Java Code Examples for com.jme3.scene.Mesh#getTriangle()
The following examples show how to use
com.jme3.scene.Mesh#getTriangle() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmitterMeshFaceShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void setMeshes(List<Mesh> meshes) { this.vertices = new ArrayList<List<Vector3f>>(meshes.size()); this.normals = new ArrayList<List<Vector3f>>(meshes.size()); for (Mesh mesh : meshes) { Vector3f[] vertexTable = BufferUtils.getVector3Array(mesh.getFloatBuffer(Type.Position)); int[] indices = new int[3]; List<Vector3f> vertices = new ArrayList<Vector3f>(mesh.getTriangleCount() * 3); List<Vector3f> normals = new ArrayList<Vector3f>(mesh.getTriangleCount()); for (int i = 0; i < mesh.getTriangleCount(); ++i) { mesh.getTriangle(i, indices); vertices.add(vertexTable[indices[0]]); vertices.add(vertexTable[indices[1]]); vertices.add(vertexTable[indices[2]]); normals.add(FastMath.computeNormal(vertexTable[indices[0]], vertexTable[indices[1]], vertexTable[indices[2]])); } this.vertices.add(vertices); this.normals.add(normals); } }
Example 2
Source File: GeneratedTexture.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * This method triangulates the texture. In the result we get a set of small * flat textures for each face of the given mesh. This can be later merged * into one flat texture. * * @param mesh * the mesh we create the texture for * @param geometriesOMA * the old memory address of the geometries group that the given * mesh belongs to (required for bounding box calculations) * @param coordinatesType * the types of UV coordinates * @param blenderContext * the blender context * @return triangulated texture */ @SuppressWarnings("unchecked") public TriangulatedTexture triangulate(Mesh mesh, Long geometriesOMA, UVCoordinatesType coordinatesType, BlenderContext blenderContext) { List<Geometry> geometries = (List<Geometry>) blenderContext.getLoadedFeature(geometriesOMA, LoadedFeatureDataType.LOADED_FEATURE); int[] coordinatesSwappingIndexes = new int[] { ((Number) mTex.getFieldValue("projx")).intValue(), ((Number) mTex.getFieldValue("projy")).intValue(), ((Number) mTex.getFieldValue("projz")).intValue() }; List<Vector3f> uvs = UVCoordinatesGenerator.generateUVCoordinatesFor3DTexture(mesh, coordinatesType, coordinatesSwappingIndexes, geometries); Vector3f[] uvsArray = uvs.toArray(new Vector3f[uvs.size()]); BoundingBox boundingBox = UVCoordinatesGenerator.getBoundingBox(geometries); Set<TriangleTextureElement> triangleTextureElements = new TreeSet<TriangleTextureElement>(new Comparator<TriangleTextureElement>() { public int compare(TriangleTextureElement o1, TriangleTextureElement o2) { return o1.faceIndex - o2.faceIndex; } }); int[] indices = new int[3]; for (int i = 0; i < mesh.getTriangleCount(); ++i) { mesh.getTriangle(i, indices); triangleTextureElements.add(new TriangleTextureElement(i, boundingBox, this, uvsArray, indices, blenderContext)); } return new TriangulatedTexture(triangleTextureElements, blenderContext); }
Example 3
Source File: EmitterMeshFaceShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void setMeshes(List<Mesh> meshes) { this.vertices = new ArrayList<List<Vector3f>>(meshes.size()); this.normals = new ArrayList<List<Vector3f>>(meshes.size()); for (Mesh mesh : meshes) { Vector3f[] vertexTable = BufferUtils.getVector3Array(mesh.getFloatBuffer(Type.Position)); int[] indices = new int[3]; List<Vector3f> vertices = new ArrayList<Vector3f>(mesh.getTriangleCount() * 3); List<Vector3f> normals = new ArrayList<Vector3f>(mesh.getTriangleCount()); for (int i = 0; i < mesh.getTriangleCount(); ++i) { mesh.getTriangle(i, indices); vertices.add(vertexTable[indices[0]]); vertices.add(vertexTable[indices[1]]); vertices.add(vertexTable[indices[2]]); normals.add(FastMath.computeNormal(vertexTable[indices[0]], vertexTable[indices[1]], vertexTable[indices[2]])); } this.vertices.add(vertices); this.normals.add(normals); } }
Example 4
Source File: CollisionResult.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Triangle getTriangle(Triangle store){ if (store == null) store = new Triangle(); Mesh m = geometry.getMesh(); m.getTriangle(triangleIndex, store); store.calculateCenter(); store.calculateNormal(); return store; }
Example 5
Source File: BoundingBox.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void computeFromTris(int[] indices, Mesh mesh, int start, int end) { if (end - start <= 0) { return; } TempVars vars = TempVars.get(); Vector3f vect1 = vars.vect1; Vector3f vect2 = vars.vect2; Triangle triangle = vars.triangle; Vector3f min = vect1.set(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY); Vector3f max = vect2.set(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY); Vector3f point; for (int i = start; i < end; i++) { mesh.getTriangle(indices[i], triangle); point = triangle.get(0); checkMinMax(min, max, point); point = triangle.get(1); checkMinMax(min, max, point); point = triangle.get(2); checkMinMax(min, max, point); } center.set(min.addLocal(max)); center.multLocal(0.5f); xExtent = max.x - center.x; yExtent = max.y - center.y; zExtent = max.z - center.z; vars.release(); }
Example 6
Source File: Octree.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public Octree(Spatial scene, int minTrisPerNode){ scene.updateGeometricState(); List<Geometry> geomsList = getGeometries(scene); geoms = new Geometry[geomsList.size()]; geomsList.toArray(geoms); // generate bound box for all geom bbox = new BoundingBox(); for (Geometry geom : geoms){ BoundingVolume bv = geom.getWorldBound(); bbox.mergeLocal(bv); } // set largest extent float extent = Math.max(bbox.getXExtent(), Math.max(bbox.getYExtent(), bbox.getZExtent())); bbox.setXExtent(extent); bbox.setYExtent(extent); bbox.setZExtent(extent); this.minTrisPerNode = minTrisPerNode; Triangle t = new Triangle(); for (int g = 0; g < geoms.length; g++){ Mesh m = geoms[g].getMesh(); for (int i = 0; i < m.getTriangleCount(); i++){ m.getTriangle(i, t); OCTTriangle ot = new OCTTriangle(t.get1(), t.get2(), t.get3(), i, g); allTris.add(ot); // convert triangle to world space // geom.getWorldTransform().transformVector(t.get1(), t.get1()); // geom.getWorldTransform().transformVector(t.get2(), t.get2()); // geom.getWorldTransform().transformVector(t.get3(), t.get3()); } } }
Example 7
Source File: CollisionResult.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public Triangle getTriangle(Triangle store){ if (store == null) store = new Triangle(); Mesh m = geometry.getMesh(); m.getTriangle(triangleIndex, store); store.calculateCenter(); store.calculateNormal(); return store; }
Example 8
Source File: BoundingBox.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void computeFromTris(int[] indices, Mesh mesh, int start, int end) { if (end - start <= 0) { return; } TempVars vars = TempVars.get(); Vector3f vect1 = vars.vect1; Vector3f vect2 = vars.vect2; Triangle triangle = vars.triangle; Vector3f min = vect1.set(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY); Vector3f max = vect2.set(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY); Vector3f point; for (int i = start; i < end; i++) { mesh.getTriangle(indices[i], triangle); point = triangle.get(0); checkMinMax(min, max, point); point = triangle.get(1); checkMinMax(min, max, point); point = triangle.get(2); checkMinMax(min, max, point); } center.set(min.addLocal(max)); center.multLocal(0.5f); xExtent = max.x - center.x; yExtent = max.y - center.y; zExtent = max.z - center.z; vars.release(); }