Examples of MTTriangleMesh


Examples of org.mt4j.components.visibleComponents.shapes.mesh.MTTriangleMesh

    //Load the meshes with the ModelImporterFactory (A file can contain more than 1 mesh)
    //Loads 3ds model
    MTTriangleMesh[] meshes = ModelImporterFactory.loadModel(mtApplication, modelsPath + "jazz_Obj" + MTApplication.separator + "honda_jazz.obj", 180, true, false );
   
    //Get the biggest mesh in the group to use as a reference for setting the position/scale
    final MTTriangleMesh biggestMesh = this.getBiggestMesh(meshes);
   
    Vector3D translationToScreenCenter = new Vector3D(destinationPosition);
    translationToScreenCenter.subtractLocal(biggestMesh.getCenterPointGlobal());
   
    Vector3D scalingPoint = new Vector3D(biggestMesh.getCenterPointGlobal());
    float biggestWidth = biggestMesh.getWidthXY(TransformSpace.GLOBAL)
    float scale = destinationScale/biggestWidth;
   
    //Move the group the the desired position
    group1.scaleGlobal(scale, scale, scale, scalingPoint);
    group1.translateGlobal(translationToScreenCenter);
    this.getCanvas().addChild(group1);
    group1.addChild(meshGroup);
   
    //Inverts the normals, if they are calculated pointing inside of the mesh instead of outside
    boolean invertNormals = true;
   
    for (int i = 0; i < meshes.length; i++) {
      MTTriangleMesh mesh = meshes[i];
      meshGroup.addChild(mesh);
      mesh.unregisterAllInputProcessors(); //Clear previously registered input processors
      mesh.setPickable(true);

      if (invertNormals){
        Vector3D[] normals = mesh.getGeometryInfo().getNormals();
        for (int j = 0; j < normals.length; j++) {
          Vector3D vector3d = normals[j];
          vector3d.scaleLocal(-1);
        }
        mesh.getGeometryInfo().setNormals(mesh.getGeometryInfo().getNormals(), mesh.isUseDirectGL(), mesh.isUseVBOs());
      }

      //If the mesh has more than 20 vertices, use a display list for faster rendering
      if (mesh.getVertexCount() > 20)
        mesh.generateAndUseDisplayLists();
      //Set the material to the mesh  (determines the reaction to the lightning)
      if (mesh.getMaterial() == null)
        mesh.setMaterial(material);
      mesh.setDrawNormals(false);
    }
   
    //Register arcball gesture manipulation to the whole mesh-group
    meshGroup.setComposite(true); //-> Group gets picked instead of its children
    meshGroup.registerInputProcessor(new ArcballProcessor(mtApplication, biggestMesh));
View Full Code Here

Examples of org.mt4j.components.visibleComponents.shapes.mesh.MTTriangleMesh

    meshGroup.addGestureListener(RotateProcessor.class, new DefaultRotateAction());
  }

 
  public MTTriangleMesh getBiggestMesh(MTTriangleMesh[] meshes){
    MTTriangleMesh currentBiggestMesh = null;
    //Get the biggest mesh and extract its width
    float currentBiggestWidth = Float.MIN_VALUE;
    for (int i = 0; i < meshes.length; i++) {
      MTTriangleMesh triangleMesh = meshes[i];
      float width = triangleMesh.getWidthXY(TransformSpace.GLOBAL);
      if (width >= currentBiggestWidth || currentBiggestWidth == Float.MIN_VALUE){
        currentBiggestWidth = width;
        currentBiggestMesh = triangleMesh;
      }
    }
View Full Code Here

Examples of org.mt4j.components.visibleComponents.shapes.mesh.MTTriangleMesh

    List<Vertex> tris = triangulator.getTriList();
    Vertex[] verts = tris.toArray(new Vertex[tris.size()]);
    GeometryInfo geom = new GeometryInfo(pa, verts);
   
//    MTTriangleMesh mesh = new MTTriangleMesh(pa, geom);
    MTTriangleMesh mesh = new SVGMesh(pa, geom);
   
    //TODO put outline contourse in own class SVGMesh!
    //not belonging in general mesh class
    mesh.setOutlineContours(bezierContours);
   
    triangulator.deleteTess(); //Delete triangulator (C++ object)
    return mesh;
  }
View Full Code Here

Examples of org.mt4j.components.visibleComponents.shapes.mesh.MTTriangleMesh

         this.triList.clear();
         this.tesselate(contours, windingRule);
         List<Vertex> tris = this.getTriList();
         Vertex[] verts = tris.toArray(new Vertex[tris.size()]);
         GeometryInfo geom = new GeometryInfo(p, verts);
         MTTriangleMesh mesh = new MTTriangleMesh(p, geom, false);
         return mesh;
       }
View Full Code Here

Examples of org.mt4j.components.visibleComponents.shapes.mesh.MTTriangleMesh

//        this.computeFromVertices(peerComponent.getGeometryInfo().getVertices());
//        this.computeFromPoints(peerComponent.getGeometryInfo().getVertBuff());
//        this.computeFromPoints(Vector3D.getDeepVertexArrayCopy(peerComponent.getGeometryInfo().getVertices()));
       
        if (peerComponent instanceof MTTriangleMesh){
          MTTriangleMesh mesh = (MTTriangleMesh)peerComponent;
          Triangle[] tris = mesh.getTriangles();
          this.computeFromTris(tris, 0, tris.length);
        }else{
          this.computeFromPoints(Vector3D.getDeepVertexArrayCopy(peerComponent.getGeometryInfo().getVertices())); //FIXME can we avoid the copy??
//          this.computeFromPoints(peerComponent.getGeometryInfo().getVertBuff()); //FIXME can we avoid the copy??
        }
View Full Code Here

Examples of org.mt4j.components.visibleComponents.shapes.mesh.MTTriangleMesh

                geometry = normalGenerator.generateSmoothNormals(pa, newVertices , newIndices, newTextureCoords, newTexIndices, creaseAngle, flipTextureY, flipTextureX);
              }else{
                geometry = normalGenerator.generateCreaseAngleNormals(pa, newVertices, newIndices, newTextureCoords, newTexIndices, creaseAngle, flipTextureY, flipTextureX);
              }

              MTTriangleMesh mesh = new MTTriangleMesh(pa, geometry);

              if (mesh != null){
                mesh.setName(m.name() + " material: " + new Integer(currentGroupName).toString());
                //Assign texture
                this.assignMaterial(pathToModel, file, scene, m, currentGroupName, mesh);

                if (mesh.getTexture() != null){
                  mesh.setTextureEnabled(true);
                }else{
                  logger.debug("No texture could be assigned to mesh.");
                }
                returnMeshList.add(mesh);
              }
            }
          }
        }else{
          //If there are no materials for this mesh dont split mesh into
          //groups by material
          //Fill indices array and texcoords array (Here: vertex index = texcoord index)
          for( int faceIndex = 0; faceIndex < m.faces(); faceIndex++ ){
            Face3ds f = m.face( faceIndex );

            indices[faceIndex*3]   = f.P0;
            indices[faceIndex*3+1]   = f.P1;
            indices[faceIndex*3+2]   = f.P2;

            texCoordIndices[faceIndex*3]   = f.P0;
            texCoordIndices[faceIndex*3+1]   = f.P1;
            texCoordIndices[faceIndex*3+2]   = f.P2;
          }//for faces

          //Create the Mesh and set a texture
          if (vertices.length > 2){
            //Create normals for the mesh and duplicate vertices for faces that share the same
            //Vertex, but with different texture coordinates or different normals
            GeometryInfo geometry = null;
            //Generate normals and denormalize vertices with more than 1 texture coordinate
            if (creaseAngle == 180){
              geometry = normalGenerator.generateSmoothNormals(pa, vertices, indices, textureCoords, texCoordIndices, creaseAngle, flipTextureY, flipTextureX);
            }else{
              geometry = normalGenerator.generateCreaseAngleNormals(pa, vertices, indices, textureCoords, texCoordIndices, creaseAngle, flipTextureY, flipTextureX);
            }
            MTTriangleMesh mesh = new MTTriangleMesh(pa, geometry);
            mesh.setName(m.name());
//            this.assignMaterial(file, scene, m, sceneMaterialID, mesh);
            returnMeshList.add(mesh);
          }//end if vertices.lentgh > 2
        }
      }//for meshes
View Full Code Here

Examples of org.mt4j.components.visibleComponents.shapes.mesh.MTTriangleMesh

          geometry = normalGenerator.generateSmoothNormals(pa, vertices , indices, textureCoords, texIndices, creaseAngle, flipTextureY, flipTextureX);
        }else{
          geometry = normalGenerator.generateCreaseAngleNormals(pa, vertices, indices, textureCoords, texIndices, creaseAngle, flipTextureY, flipTextureX);
        }

        MTTriangleMesh mesh = new MTTriangleMesh(pa, geometry);

        if (mesh != null){
          mesh.setName(currentGroupName);
          //Assign texture and material
          String matName = (String)groupMaterials.get(currentGroupName);
          materials.assignMaterial(((PGraphicsOpenGL)pa.g).gl, matName, mesh);
         
          if (mesh.getTexture() != null){
            mesh.setTextureEnabled(true);
          }else{
            System.out.println("No texture could be assigned to mesh.");
          }
          meshList.add(mesh);
        }else{
View Full Code Here

Examples of org.mt4j.components.visibleComponents.shapes.mesh.MTTriangleMesh

        getCanvas().addChild(cube);
       
        MTSphere sphere = new MTSphere(getMTApplication(), "sphere", 30,30, 130);
        getCanvas().addChild(sphere);
       
        MTTriangleMesh mesh = new MTTriangleMesh(getMTApplication(), new GeometryInfo(getMTApplication(), new Vertex[]{
          new Vertex(0,0,0),
          new Vertex(100,0,0),
          new Vertex(50,50,0),
        }));
        getCanvas().addChild(mesh);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.