/** * Calculates smoothing groups for data formatted in TriangleMesh style * @param flatFaces An array of faces, where each triangle face is represented by 6 (vertex and uv) indices * @param flatFaceNormals An array of face normals, where each triangle face is represented by 3 normal indices * @param normals The array of normals * @return An array of smooth groups, where the length of the array is the number of faces */ public static int[] calcSmoothGroups(TriangleMesh mesh, int[] flatFaces, int[] flatFaceNormals, float[] normals) { int faceElementSize = mesh.getFaceElementSize(); int[][] faces = new int[flatFaces.length/faceElementSize][faceElementSize]; for (int f = 0; f < faces.length; f++) { for (int e = 0; e < faceElementSize; e++) { faces[f][e] = flatFaces[f * faceElementSize + e]; } } int pointElementSize = mesh.getPointElementSize(); int[][] faceNormals = new int[flatFaceNormals.length/pointElementSize][pointElementSize]; for (int f = 0; f < faceNormals.length; f++) { for (int e = 0; e < pointElementSize; e++) { faceNormals[f][e] = flatFaceNormals[f * pointElementSize + e]; } } SmoothingGroups smoothGroups = new SmoothingGroups(faces, faceNormals, normals); return smoothGroups.calcSmoothGroups(); } }
int numPoints = tMesh.getPoints().size() / tMesh.getPointElementSize(); int numTexCoords = tMesh.getTexCoords().size() / tMesh.getTexCoordElementSize(); int numFaces = tMesh.getFaces().size() / tMesh.getFaceElementSize(); if (numPoints == 0 || numPoints * tMesh.getPointElementSize() != tMesh.getPoints().size()) { throw new AssertionError("Points array size is not correct: " + tMesh.getPoints().size()); throw new AssertionError("TexCoords array size is not correct: " + tMesh.getPoints().size()); if (numFaces == 0 || numFaces * tMesh.getFaceElementSize() != tMesh.getFaces().size()) { throw new AssertionError("Faces array size is not correct: " + tMesh.getPoints().size());
triangleMesh.getTexCoords().addAll(convertToFloatArray(texturePoints)); triangleMesh.getFaces().addAll(indices); triangleMesh.getFaceSmoothingGroups().addAll(new int[indices.length / triangleMesh.getFaceElementSize()]); triangleMesh.getNormals().addAll(convertToFloatArray(normals));
triangleMesh.getTexCoords().addAll(convertToFloatArray(texturePoints)); triangleMesh.getFaces().addAll(indices); triangleMesh.getFaceSmoothingGroups().addAll(new int[indices.length / triangleMesh.getFaceElementSize()]); triangleMesh.getNormals().addAll(convertToFloatArray(normals));
"Added mesh '" + key + "' of " + mesh.getPoints().size() / mesh.getPointElementSize() + " vertexes, " + mesh.getTexCoords().size() / mesh.getTexCoordElementSize() + " uvs, " + mesh.getFaces().size() / mesh.getFaceElementSize() + " faces, " + mesh.getFaceSmoothingGroups().size() + " smoothing groups."); log("material diffuse color = " + ((PhongMaterial) material).getDiffuseColor());
newFaceSmoothingGroups.ensureCapacity(faceSmoothingGroups.size()); int pointElementSize = mesh.getPointElementSize(); int faceElementSize = mesh.getFaceElementSize(); for (int i = 0; i < faces.size(); i += faceElementSize) { total++;
final int faceElementSize = triangleMesh.getFaceElementSize(); final boolean isWireframe = getDrawMode() == DrawMode.LINE; if (DEBUG) System.out.println("UPDATE MESH -- "+(isWireframe?"WIREFRAME":"SOLID"));