Package com.jme.scene

Examples of com.jme.scene.TriMesh


            rootNode.attachChild(iNode);
            for (int j = 10; j <= 50; j +=10) {
                Node jNode = new Node(String.valueOf(i+j));
                iNode.attachChild(jNode);
                for (int k = 1; k <= 5; k++) {
                    TriMesh kMesh = new TriMesh(String.valueOf(i+j+k));
                    jNode.attachChild(kMesh);
                }
            }
        }
        return rootNode;
View Full Code Here


     * <code>setNormalData</code> sets the normals of each of the box's
     * planes. Normals are only initialized once.
     *
     */
    private void setNormalData() {
        TriMesh triMesh;

  // Back
  triMesh = faces[Face.BACK.ordinal()];
  if (triMesh.getNormalBuffer() != null) {
      return;
  }
  triMesh.setNormalBuffer(BufferUtils.createVector3Buffer(4));
  for (int i = 0; i < 4; i++) {
      triMesh.getNormalBuffer().put(0).put(0).put(-1);
  }
 
  // Right
  triMesh = faces[Face.RIGHT.ordinal()];
  triMesh.setNormalBuffer(BufferUtils.createVector3Buffer(4));
  for (int i = 0; i < 4; i++) {
      triMesh.getNormalBuffer().put(1).put(0).put(0);
  }
 
  // Front
  triMesh = faces[Face.FRONT.ordinal()];
  triMesh.setNormalBuffer(BufferUtils.createVector3Buffer(4));
  for (int i = 0; i < 4; i++) {
      triMesh.getNormalBuffer().put(0).put(0).put(1);
  }
 
  // Left
  triMesh = faces[Face.LEFT.ordinal()];
  triMesh.setNormalBuffer(BufferUtils.createVector3Buffer(4));
  for (int i = 0; i < 4; i++) {
      triMesh.getNormalBuffer().put(-1).put(0).put(0);
  }
 
  // Top
  triMesh = faces[Face.TOP.ordinal()];
  triMesh.setNormalBuffer(BufferUtils.createVector3Buffer(4));
  for (int i = 0; i < 4; i++) {
      triMesh.getNormalBuffer().put(0).put(1).put(0);
  }
 
  // Bottom
  triMesh = faces[Face.BOTTOM.ordinal()];
  triMesh.setNormalBuffer(BufferUtils.createVector3Buffer(4));
  for (int i = 0; i < 4; i++) {
      triMesh.getNormalBuffer().put(0).put(-1).put(0);
  }
    }
View Full Code Here

     * Sets the points that define the layer 0 texture coordinates of the box. It's a one-to-one ratio, where each
     * plane of the box has it's own copy of the texture coordinates. That is, the texture coordinates are repeated for
     * each six faces.
     */
    private void setTextureData() {
        TriMesh triMesh;
  FloatBuffer tex;
  int mask = 0x1;

  for (int i = 0; i < 6; i++, mask <<= 1) {
            triMesh = faces[i];
      if ((texturedFaces & mask) != 0) {
    FloatBuffer tbuf = BufferUtils.createVector2Buffer(4);
    triMesh.setTextureCoords(new TexCoords(tbuf));
    tbuf.put(1).put(0);
    tbuf.put(0).put(0);
    tbuf.put(0).put(1);
    tbuf.put(1).put(1);
      } else {
    triMesh.setTextureCoords(new TexCoords(null));
      }
  }
    }
View Full Code Here

     * Sets the indices into the list of vertices, defining all triangles that constitute the faces of box.
     * indices are only initialized once.
     */
    private void setIndexData() {
  int[] indices = { 2, 1, 0, 3, 2, 0 };      
        TriMesh triMesh;

  triMesh = faces[0];
  if (triMesh.getIndexBuffer() != null) {
      return;
  }

  for (int i = 0; i < 6; i++) {
      triMesh = faces[i];
      triMesh.setIndexBuffer(BufferUtils.createIntBuffer(indices));
  }
    }
View Full Code Here

        creator.clearInstances();
    }

    public void batch() {
        // Create a TriMesh
        mesh = new TriMesh();
        mesh.setModelBound(new BoundingBox());

        // Create the batch's buffers
        mesh.setIndexBuffer(BufferUtils.createIntBuffer(creator.getNumIndices()));
        mesh.setVertexBuffer(BufferUtils.createVector3Buffer(creator.getNumVertices()));
View Full Code Here

     */
    public void setData(Vector3f center, float xExtent, float yExtent, float zExtent) {

        for (int i = 0; i < 6; i++) {
      if (faces[i] == null) {
    TriMesh mesh = new TriMesh();
    TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
    ts.setTexture(texture);
    mesh.setRenderState(ts);
    mesh.setModelBound(new BoundingBox());
    mesh.updateModelBound();
    faces[i] = mesh;
    attachChild(mesh);
      }
  }

View Full Code Here

    
     */
    private void setVertexData() {
  Vector3f[] vert = computeVertices(); // returns 8 vertices

        TriMesh triMesh;

  // Back
  triMesh = faces[Face.BACK.ordinal()];
        triMesh.setVertexBuffer(BufferUtils.createVector3Buffer(triMesh.getVertexBuffer(), 4));
  triMesh.setVertexCount(4);
  triMesh.getVertexBuffer().put(vert[0].x).put(vert[0].y).put(vert[0].z);
  triMesh.getVertexBuffer().put(vert[1].x).put(vert[1].y).put(vert[1].z);
  triMesh.getVertexBuffer().put(vert[2].x).put(vert[2].y).put(vert[2].z);
  triMesh.getVertexBuffer().put(vert[3].x).put(vert[3].y).put(vert[3].z);

  // Right
  triMesh = faces[Face.RIGHT.ordinal()];
        triMesh.setVertexBuffer(BufferUtils.createVector3Buffer(triMesh.getVertexBuffer(), 4));
  triMesh.setVertexCount(4);
  triMesh.getVertexBuffer().put(vert[1].x).put(vert[1].y).put(vert[1].z);
  triMesh.getVertexBuffer().put(vert[4].x).put(vert[4].y).put(vert[4].z);
  triMesh.getVertexBuffer().put(vert[6].x).put(vert[6].y).put(vert[6].z);
  triMesh.getVertexBuffer().put(vert[2].x).put(vert[2].y).put(vert[2].z);

  // Front
  triMesh = faces[Face.FRONT.ordinal()];
        triMesh.setVertexBuffer(BufferUtils.createVector3Buffer(triMesh.getVertexBuffer(), 4));
  triMesh.setVertexCount(4);
  triMesh.getVertexBuffer().put(vert[4].x).put(vert[4].y).put(vert[4].z);
  triMesh.getVertexBuffer().put(vert[5].x).put(vert[5].y).put(vert[5].z);
  triMesh.getVertexBuffer().put(vert[7].x).put(vert[7].y).put(vert[7].z);
  triMesh.getVertexBuffer().put(vert[6].x).put(vert[6].y).put(vert[6].z);

  // Left
  triMesh = faces[Face.LEFT.ordinal()];
        triMesh.setVertexBuffer(BufferUtils.createVector3Buffer(triMesh.getVertexBuffer(), 4));
  triMesh.setVertexCount(4);
  triMesh.getVertexBuffer().put(vert[5].x).put(vert[5].y).put(vert[5].z);
  triMesh.getVertexBuffer().put(vert[0].x).put(vert[0].y).put(vert[0].z);
  triMesh.getVertexBuffer().put(vert[3].x).put(vert[3].y).put(vert[3].z);
  triMesh.getVertexBuffer().put(vert[7].x).put(vert[7].y).put(vert[7].z);

  // Top
  triMesh = faces[Face.TOP.ordinal()];
        triMesh.setVertexBuffer(BufferUtils.createVector3Buffer(triMesh.getVertexBuffer(), 4));
  triMesh.setVertexCount(4);
  triMesh.getVertexBuffer().put(vert[2].x).put(vert[2].y).put(vert[2].z);
  triMesh.getVertexBuffer().put(vert[6].x).put(vert[6].y).put(vert[6].z);
  triMesh.getVertexBuffer().put(vert[7].x).put(vert[7].y).put(vert[7].z);
  triMesh.getVertexBuffer().put(vert[3].x).put(vert[3].y).put(vert[3].z);

  // Bottom
  triMesh = faces[Face.BOTTOM.ordinal()];
        triMesh.setVertexBuffer(BufferUtils.createVector3Buffer(triMesh.getVertexBuffer(), 4));
  triMesh.setVertexCount(4);
  triMesh.getVertexBuffer().put(vert[0].x).put(vert[0].y).put(vert[0].z);
  triMesh.getVertexBuffer().put(vert[5].x).put(vert[5].y).put(vert[5].z);
  triMesh.getVertexBuffer().put(vert[4].x).put(vert[4].y).put(vert[4].z);
  triMesh.getVertexBuffer().put(vert[1].x).put(vert[1].y).put(vert[1].z);
    }
View Full Code Here

    private float agl = 0.0f;
    protected void simpleInitGame()
    {
     
        //Sphere dome = new Sphere("TankDome", new Vector3f(-1.0f,1.0f,0.5f),16,16,.5f);
      TriMesh dome = new Dome("TankDome", new Vector3f(0, 0, 0), 16, 16, .5f);
      dome.setLocalTranslation(new Vector3f(-1.0f,1.0f,0.5f));
        //Cylinder canon = new Cylinder("Canon", 16, 16, 0.25f, 3.0f,true);
      TriMesh mesh = new TriMesh("TankMesh");
     
      Vector3f[] vertexes = {
          new Vector3f(1.0f,.5f,0.0f),
          new Vector3f(0.0f,0.0f,0.0f),
          new Vector3f(0.0f,1.0f,0.0f),
          new Vector3f(-2.0f,0.0f,0.0f),
          new Vector3f(-2.0f,1.0f,0.0f),
         
          new Vector3f(-3.0f,0.5f,0.0f),
          new Vector3f(1.0f,.5f,1.0f),
          new Vector3f(0.0f,0.0f,1.0f),
          new Vector3f(0.0f,1.0f,1.0f),
          new Vector3f(-2.0f,0.0f,1.0f),
          new Vector3f(-2.0f,1.0f,1.0f),
          new Vector3f(-3.0f,0.5f,1.0f)};
     
     
      Vector3f[] normals={
                new Vector3f(0,0,-1),
                new Vector3f(0,0,-1),
                new Vector3f(0,0,-1),
                new Vector3f(0,0,-1),
                new Vector3f(0,0,-1),
                new Vector3f(0,0,-1),
                new Vector3f(0,0,1),
                new Vector3f(0,0,1),
                new Vector3f(0,0,1),
                new Vector3f(0,0,1),
                new Vector3f(0,0,1),
                new Vector3f(0,0,1)};
     
     
     
     
      int[] indexes = {0,1,2,2,3,1,2,4,3,4,5,3,6,7,8,8,9,7,
              8,10,9,10,11,9,1,7,9,1,3,9,9,3,11,3,11,5,
              6,0,8,8,2,0,8,10,2,10,4,2,4,11,5,10,4,11,1,7,6,0,6,1};
     
      mesh.reconstruct(BufferUtils.createFloatBuffer(vertexes),
              BufferUtils.createFloatBuffer(normals),
              null, null,BufferUtils.createIntBuffer(indexes));
     
     
     
      mesh.setModelBound(new BoundingBox());
      mesh.updateModelBound();
     
      tankNode = new Node("TankNode");
      tankTurret = new Node("tankTurret");
        tankTurretBarrel = new Cylinder("tankTurretBarrel", 16, 16, .1f, BARREL_LENGTH );
        tankTurretBarrel.setModelBound(new BoundingBox());
View Full Code Here

    private float agl = 0.0f;
    protected void simpleInitGame()
    {
     
        //Sphere dome = new Sphere("TankDome", new Vector3f(-1.0f,1.0f,0.5f),16,16,.5f);
      TriMesh dome = new Dome("TankDome", new Vector3f(0, 0, 0), 16, 16, .5f);
      dome.setLocalTranslation(new Vector3f(-1.0f,1.0f,0.5f));
        //Cylinder canon = new Cylinder("Canon", 16, 16, 0.25f, 3.0f,true);
      TriMesh mesh = new TriMesh("TankMesh");
     
      Vector3f[] vertexes = {
          new Vector3f(1.0f,.5f,0.0f),
          new Vector3f(0.0f,0.0f,0.0f),
          new Vector3f(0.0f,1.0f,0.0f),
          new Vector3f(-2.0f,0.0f,0.0f),
          new Vector3f(-2.0f,1.0f,0.0f),
         
          new Vector3f(-3.0f,0.5f,0.0f),
          new Vector3f(1.0f,.5f,1.0f),
          new Vector3f(0.0f,0.0f,1.0f),
          new Vector3f(0.0f,1.0f,1.0f),
          new Vector3f(-2.0f,0.0f,1.0f),
          new Vector3f(-2.0f,1.0f,1.0f),
          new Vector3f(-3.0f,0.5f,1.0f)};
     
     
      Vector3f[] normals={
                new Vector3f(0,0,-1),
                new Vector3f(0,0,-1),
                new Vector3f(0,0,-1),
                new Vector3f(0,0,-1),
                new Vector3f(0,0,-1),
                new Vector3f(0,0,-1),
                new Vector3f(0,0,1),
                new Vector3f(0,0,1),
                new Vector3f(0,0,1),
                new Vector3f(0,0,1),
                new Vector3f(0,0,1),
                new Vector3f(0,0,1)};
     
     
     
     
      int[] indexes = {0,1,2,2,3,1,2,4,3,4,5,3,6,7,8,8,9,7,
              8,10,9,10,11,9,1,7,9,1,3,9,9,3,11,3,11,5,
              6,0,8,8,2,0,8,10,2,10,4,2,4,11,5,10,4,11,1,7,6,0,6,1};
     
      mesh.reconstruct(BufferUtils.createFloatBuffer(vertexes),
              BufferUtils.createFloatBuffer(normals),
              null, null,BufferUtils.createIntBuffer(indexes));
     
     
     
      mesh.setModelBound(new BoundingBox());
      mesh.updateModelBound();
     
      tankNode = new Node("TankNode");
      tankTurret = new Node("tankTurret");
        tankTurretBarrel = new Cylinder("tankTurretBarrel", 16, 16, .1f, BARREL_LENGTH );
        tankTurretBarrel.setModelBound(new BoundingBox());
View Full Code Here

TOP

Related Classes of com.jme.scene.TriMesh

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.