changeset 4279:b5a930c2fd82

Subdivided meshes were missing smoothing groups; faces of the subdivided meshes have the smoothing group of the parent face.
author Alex X. Lee
date Thu, 11 Jul 2013 18:24:36 -0700
parents c6a7452039b6
children 448737b47996
files apps/experiments/3DViewer/src/main/java/com/javafx/experiments/shape3d/SubdivisionMesh.java apps/experiments/3DViewer/src/main/java/com/javafx/experiments/shape3d/symbolic/SymbolicPolygonMesh.java apps/experiments/3DViewer/src/main/java/com/javafx/experiments/shape3d/symbolic/SymbolicSubdivisionBuilder.java
diffstat 3 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/apps/experiments/3DViewer/src/main/java/com/javafx/experiments/shape3d/SubdivisionMesh.java	Thu Jul 11 18:23:34 2013 -0700
+++ b/apps/experiments/3DViewer/src/main/java/com/javafx/experiments/shape3d/SubdivisionMesh.java	Thu Jul 11 18:24:36 2013 -0700
@@ -105,15 +105,14 @@
         }
         
         if (pointValuesDirty || subdivisionLevelDirty) {
-            float[] points = symbolicMeshes.get(subdivisionLevel).points.data;
-            getPoints().setAll(points, 0, points.length);
+            getPoints().setAll(symbolicMeshes.get(subdivisionLevel).points.data);
         }
         
         if (subdivisionLevelDirty) {
             faces = symbolicMeshes.get(subdivisionLevel).faces;
             numEdgesInFaces = -1;
-            float[] texCoords = symbolicMeshes.get(subdivisionLevel).texCoords;
-            getTexCoords().setAll(texCoords, 0, texCoords.length);
+            getFaceSmoothingGroups().setAll(symbolicMeshes.get(subdivisionLevel).faceSmoothingGroups);
+            getTexCoords().setAll(symbolicMeshes.get(subdivisionLevel).texCoords);
         }
         
         meshDirty = false;
--- a/apps/experiments/3DViewer/src/main/java/com/javafx/experiments/shape3d/symbolic/SymbolicPolygonMesh.java	Thu Jul 11 18:23:34 2013 -0700
+++ b/apps/experiments/3DViewer/src/main/java/com/javafx/experiments/shape3d/symbolic/SymbolicPolygonMesh.java	Thu Jul 11 18:24:36 2013 -0700
@@ -10,20 +10,21 @@
     public SymbolicPointArray points;
     public float[] texCoords;
     public int[][] faces;
+    public int[] faceSmoothingGroups;
     private int numEdgesInFaces = -1;
 
-    public SymbolicPolygonMesh() { }
-    
-    public SymbolicPolygonMesh(SymbolicPointArray points, float[] texCoords, int[][] faces) {
+    public SymbolicPolygonMesh(SymbolicPointArray points, float[] texCoords, int[][] faces, int[] faceSmoothingGroups) {
         this.points = points;
         this.texCoords = texCoords;
         this.faces = faces;
+        this.faceSmoothingGroups = faceSmoothingGroups;
     }
     
     public SymbolicPolygonMesh(PolygonMesh mesh) {
         this.points = new OriginalPointArray(mesh);
         this.texCoords = mesh.getTexCoords().toArray(this.texCoords);
         this.faces = mesh.faces;
+        this.faceSmoothingGroups = mesh.getFaceSmoothingGroups().toArray(null);
     }
     
     public int getNumEdgesInFaces() {
--- a/apps/experiments/3DViewer/src/main/java/com/javafx/experiments/shape3d/symbolic/SymbolicSubdivisionBuilder.java	Thu Jul 11 18:23:34 2013 -0700
+++ b/apps/experiments/3DViewer/src/main/java/com/javafx/experiments/shape3d/symbolic/SymbolicSubdivisionBuilder.java	Thu Jul 11 18:24:36 2013 -0700
@@ -38,6 +38,7 @@
         
         texCoords = new float[(oldMesh.getNumEdgesInFaces() * 3 + oldMesh.faces.length) * 2];
         int[][] faces = new int[oldMesh.getNumEdgesInFaces()][8];
+        int[] faceSmoothingGroups = new int[oldMesh.getNumEdgesInFaces()];
         newTexCoordIndex = 0;
         reindex = new int[oldMesh.points.numPoints]; // indexes incremented by 1, 0 reserved for empty
         
@@ -49,6 +50,7 @@
             for (int p = 0; p < oldFaces.length; p += 2) {
                 faces[newFacesInd][4] = getPointNewIndex(faceInfo);
                 faces[newFacesInd][5] = getTexCoordNewIndex(faceInfo);
+                faceSmoothingGroups[newFacesInd] = oldMesh.faceSmoothingGroups[f];
                 newFacesInd++;
             }
         }
@@ -77,7 +79,7 @@
             }
         }
         
-        SymbolicPolygonMesh newMesh = new SymbolicPolygonMesh(points, texCoords, faces);
+        SymbolicPolygonMesh newMesh = new SymbolicPolygonMesh(points, texCoords, faces, faceSmoothingGroups);
         return newMesh;
     }