diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshContext.java b/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshContext.java index c3045195c..7e38ffe09 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshContext.java +++ b/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 geometries = new HashMap(); /** The vertex reference map. */ private Map>> vertexReferenceMap; - /** Bind buffer for vertices is stored here and applied when required. */ - private Map bindPoseBuffer = new HashMap(); - /** Bind buffer for normals is stored here and applied when required. */ - private Map bindNormalBuffer = new HashMap(); /** * Adds a geometry for the specified material index. @@ -78,46 +73,4 @@ public class MeshContext { public void setVertexReferenceMap(Map>> 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); - } } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java index 8c470275b..36c70aacd 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java +++ b/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 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(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 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(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(meshBuilder.getMeshesPartAmount()); for (Entry> 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 mFaces = pMFace.isNotNull() ? pMFace.fetchData(blenderContext.getInputStream()) : null; if (mFaces != null && mFaces.size() > 0) { diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java index 22b0a5e3d..b4590bf87 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java +++ b/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);