Преглед изворни кода

Refactoring: vertices and normals bind poses are now generated instead of read from the file (as suggested in ArmatureModifier ;).

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10804 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
Kae..pl пре 12 година
родитељ
комит
915638a370

+ 0 - 47
engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshContext.java

@@ -6,7 +6,6 @@ import java.util.Map;
 import java.util.Map.Entry;
 
 import com.jme3.scene.Geometry;
-import com.jme3.scene.VertexBuffer;
 
 /**
  * Class that holds information about the mesh.
@@ -18,10 +17,6 @@ public class MeshContext {
     private Map<Integer, Geometry>                    geometries       = new HashMap<Integer, Geometry>();
     /** The vertex reference map. */
     private Map<Integer, Map<Integer, List<Integer>>> vertexReferenceMap;
-    /** Bind buffer for vertices is stored here and applied when required. */
-    private Map<Integer, VertexBuffer>                bindPoseBuffer   = new HashMap<Integer, VertexBuffer>();
-    /** Bind buffer for normals is stored here and applied when required. */
-    private Map<Integer, VertexBuffer>                bindNormalBuffer = new HashMap<Integer, VertexBuffer>();
 
     /**
      * Adds a geometry for the specified material index.
@@ -78,46 +73,4 @@ public class MeshContext {
     public void setVertexReferenceMap(Map<Integer, Map<Integer, List<Integer>>> vertexReferenceMap) {
         this.vertexReferenceMap = vertexReferenceMap;
     }
-
-    /**
-     * This method sets the bind buffer for vertices.
-     * 
-     * @param materialIndex
-     *            the index of the mesh's material
-     * @param bindNormalBuffer
-     *            the bind buffer for vertices
-     */
-    public void setBindNormalBuffer(int materialIndex, VertexBuffer bindNormalBuffer) {
-        this.bindNormalBuffer.put(materialIndex, bindNormalBuffer);
-    }
-
-    /**
-     * @param materialIndex
-     *            the index of the mesh's material
-     * @return the bind buffer for vertices
-     */
-    public VertexBuffer getBindNormalBuffer(int materialIndex) {
-        return bindNormalBuffer.get(materialIndex);
-    }
-
-    /**
-     * This method sets the bind buffer for normals.
-     * 
-     * @param materialIndex
-     *            the index of the mesh's material
-     * @param bindNormalBuffer
-     *            the bind buffer for normals
-     */
-    public void setBindPoseBuffer(int materialIndex, VertexBuffer bindPoseBuffer) {
-        this.bindPoseBuffer.put(materialIndex, bindPoseBuffer);
-    }
-
-    /**
-     * @param materialIndex
-     *            the index of the mesh's material
-     * @return the bind buffer for normals
-     */
-    public VertexBuffer getBindPoseBuffer(int materialIndex) {
-        return bindPoseBuffer.get(materialIndex);
-    }
 }

+ 18 - 27
engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java

@@ -37,6 +37,7 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import com.jme3.asset.BlenderKey.FeaturesToLoad;
@@ -106,18 +107,18 @@ public class MeshHelper extends AbstractBlenderHelper {
             return copiedGeometries;
         }
 
-        // reading mesh data
         String name = structure.getName();
         MeshContext meshContext = new MeshContext();
+        LOGGER.log(Level.FINE, "Reading mesh: {0}.", name);
 
-        // reading materials
+        LOGGER.fine("Loading materials.");
         MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
         MaterialContext[] materials = null;
         if ((blenderContext.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.MATERIALS) != 0) {
             materials = materialHelper.getMaterials(structure, blenderContext);
         }
 
-        // reading vertices and their colors
+        LOGGER.fine("Reading vertices and their colors.");
         Vector3f[][] verticesAndNormals = this.getVerticesAndNormals(structure, blenderContext);
         List<byte[]> verticesColors = this.getVerticesColors(structure, blenderContext);
 
@@ -130,6 +131,7 @@ public class MeshHelper extends AbstractBlenderHelper {
         }
 
         if (meshBuilder.isEmpty()) {
+            LOGGER.fine("The geometry is empty.");
             geometries = new ArrayList<Geometry>(0);
             blenderContext.addLoadedFeatures(structure.getOldMemoryAddress(), structure.getName(), structure, geometries);
             blenderContext.setMeshContext(structure.getOldMemoryAddress(), meshContext);
@@ -138,7 +140,7 @@ public class MeshHelper extends AbstractBlenderHelper {
 
         meshContext.setVertexReferenceMap(meshBuilder.getVertexReferenceMap());
 
-        // reading vertices groups (from the parent)
+        LOGGER.fine("Reading vertices groups (from the Object structure).");
         Structure parent = blenderContext.peekParent();
         Structure defbase = (Structure) parent.getFieldValue("defbase");
         List<Structure> defs = defbase.evaluateListBase(blenderContext);
@@ -148,13 +150,11 @@ public class MeshHelper extends AbstractBlenderHelper {
             verticesGroups[defIndex++] = def.getFieldValue("name").toString();
         }
 
-        // creating the result meshes
-        geometries = new ArrayList<Geometry>(meshBuilder.getMeshesPartAmount());
-
-        // reading custom properties
+        LOGGER.fine("Reading custom properties.");
         Properties properties = this.loadProperties(structure, blenderContext);
 
-        // generating meshes
+        LOGGER.fine("Generating meshes.");
+        geometries = new ArrayList<Geometry>(meshBuilder.getMeshesPartAmount());
         for (Entry<Integer, List<Integer>> meshEntry : meshBuilder.getMeshesMap().entrySet()) {
             int materialIndex = meshEntry.getKey();
             // key is the material index (or -1 if the material has no texture)
@@ -177,34 +177,23 @@ public class MeshHelper extends AbstractBlenderHelper {
                 mesh.setBuffer(Type.Index, 1, indices);
             }
 
+            LOGGER.fine("Creating vertices buffer.");
             VertexBuffer verticesBuffer = new VertexBuffer(Type.Position);
             verticesBuffer.setupData(Usage.Static, 3, Format.Float, BufferUtils.createFloatBuffer(meshBuilder.getVertices(materialIndex)));
-
-            // initial vertex position (used with animation)
-            VertexBuffer verticesBind = new VertexBuffer(Type.BindPosePosition);
-            verticesBind.setupData(Usage.CpuOnly, 3, Format.Float, BufferUtils.createFloatBuffer(meshBuilder.getVertices(materialIndex)));
-
+            mesh.setBuffer(verticesBuffer);
+            
+            LOGGER.fine("Creating normals buffer.");
             VertexBuffer normalsBuffer = new VertexBuffer(Type.Normal);
             normalsBuffer.setupData(Usage.Static, 3, Format.Float, BufferUtils.createFloatBuffer(meshBuilder.getNormals(materialIndex)));
+            mesh.setBuffer(normalsBuffer);
 
-            // initial normals position (used with animation)
-            VertexBuffer normalsBind = new VertexBuffer(Type.BindPoseNormal);
-            normalsBind.setupData(Usage.CpuOnly, 3, Format.Float, BufferUtils.createFloatBuffer(meshBuilder.getNormals(materialIndex)));
-
-            mesh.setBuffer(verticesBuffer);
-            meshContext.setBindPoseBuffer(materialIndex, verticesBind);// this is stored in the context and applied when needed (when animation is applied to the mesh)
-
-            // setting vertices colors
             if (verticesColors != null) {
+                LOGGER.fine("Setting vertices colors.");
                 mesh.setBuffer(Type.Color, 4, meshBuilder.getVertexColorsBuffer(materialIndex));
                 mesh.getBuffer(Type.Color).setNormalized(true);
             }
 
-            // setting faces' normals
-            mesh.setBuffer(normalsBuffer);
-            meshContext.setBindNormalBuffer(materialIndex, normalsBind);// this is stored in the context and applied when needed (when animation is applied to the mesh)
-
-            // creating the result
+            LOGGER.fine("Preparing the result part.");
             Geometry geometry = new Geometry(name + (geometries.size() + 1), mesh);
             if (properties != null && properties.getValue() != null) {
                 this.applyProperties(geometry, properties);
@@ -347,6 +336,7 @@ public class MeshHelper extends AbstractBlenderHelper {
      *             blender file
      */
     private void readBMesh(MeshBuilder meshBuilder, Structure meshStructure, BlenderContext blenderContext) throws BlenderFileException {
+        LOGGER.fine("Reading BMesh.");
         Pointer pMLoop = (Pointer) meshStructure.getFieldValue("mloop");
         Pointer pMPoly = (Pointer) meshStructure.getFieldValue("mpoly");
         Pointer pMEdge = (Pointer) meshStructure.getFieldValue("medge");
@@ -409,6 +399,7 @@ public class MeshHelper extends AbstractBlenderHelper {
      *             blender file
      */
     private void readTraditionalFaces(MeshBuilder meshBuilder, Structure meshStructure, BlenderContext blenderContext) throws BlenderFileException {
+        LOGGER.fine("Reading traditional faces.");
         Pointer pMFace = (Pointer) meshStructure.getFieldValue("mface");
         List<Structure> mFaces = pMFace.isNotNull() ? pMFace.fetchData(blenderContext.getInputStream()) : null;
         if (mFaces != null && mFaces.size() > 0) {

+ 3 - 11
engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java

@@ -46,7 +46,6 @@ import com.jme3.util.BufferUtils;
 /* package */class ArmatureModifier extends Modifier {
     private static final Logger LOGGER                     = Logger.getLogger(ArmatureModifier.class.getName());
     private static final int    MAXIMUM_WEIGHTS_PER_VERTEX = 4;                                                 // JME
-                                                                                                                 // limitation
 
     private Skeleton            skeleton;
     private Structure           objectStructure;
@@ -197,16 +196,9 @@ import com.jme3.util.BufferUtils;
                         mesh.setBuffer(buffers[0]);
                         mesh.setBuffer(buffers[1]);
     
-                        //FIXME @Kaelthas this should be replaced by a call to 
-                        //mesh.generateBindPos(true)
-                        VertexBuffer bindNormalBuffer = meshContext.getBindNormalBuffer(materialIndex);
-                        if (bindNormalBuffer != null) {
-                            mesh.setBuffer(bindNormalBuffer);
-                        }
-                        VertexBuffer bindPoseBuffer = meshContext.getBindPoseBuffer(materialIndex);
-                        if (bindPoseBuffer != null) {
-                            mesh.setBuffer(bindPoseBuffer);
-                        }
+                        LOGGER.fine("Generating bind pose and normal buffers.");
+                        mesh.generateBindPose(true);
+                        
                         // change the usage type of vertex and normal buffers from
                         // Static to Stream
                         mesh.getBuffer(Type.Position).setUsage(Usage.Stream);