Issue 429: Blender loader doesn't specify that meshes are non-animated (fix)

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9403 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Kae..pl 13 years ago
parent 9e2f6b88ef
commit e2652851c5
  1. 41
      engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshContext.java
  2. 8
      engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java
  3. 13
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java

@ -21,6 +21,10 @@ public class MeshContext {
private Map<Integer, List<Integer>> vertexReferenceMap; private Map<Integer, List<Integer>> vertexReferenceMap;
/** The UV-coordinates for each of the geometries. */ /** The UV-coordinates for each of the geometries. */
private Map<Geometry, VertexBuffer> uvCoordinates = new HashMap<Geometry, VertexBuffer>(); private Map<Geometry, VertexBuffer> uvCoordinates = new HashMap<Geometry, VertexBuffer>();
/** Bind buffer for vertices is stored here and applied when required. */
private VertexBuffer bindPoseBuffer;
/** Bind buffer for normals is stored here and applied when required. */
private VertexBuffer bindNormalBuffer;
/** /**
* This method returns the referenced mesh. * This method returns the referenced mesh.
@ -75,8 +79,7 @@ public class MeshContext {
* @param vertexReferenceMap * @param vertexReferenceMap
* the vertex reference map * the vertex reference map
*/ */
public void setVertexReferenceMap( public void setVertexReferenceMap(Map<Integer, List<Integer>> vertexReferenceMap) {
Map<Integer, List<Integer>> vertexReferenceMap) {
this.vertexReferenceMap = vertexReferenceMap; this.vertexReferenceMap = vertexReferenceMap;
} }
@ -102,4 +105,38 @@ public class MeshContext {
public VertexBuffer getUVCoordinates(Geometry geometry) { public VertexBuffer getUVCoordinates(Geometry geometry) {
return uvCoordinates.get(geometry); return uvCoordinates.get(geometry);
} }
/**
* This method sets the bind buffer for vertices.
*
* @param bindNormalBuffer
* the bind buffer for vertices
*/
public void setBindNormalBuffer(VertexBuffer bindNormalBuffer) {
this.bindNormalBuffer = bindNormalBuffer;
}
/**
* @return the bind buffer for vertices
*/
public VertexBuffer getBindNormalBuffer() {
return bindNormalBuffer;
}
/**
* This method sets the bind buffer for normals.
*
* @param bindNormalBuffer
* the bind buffer for normals
*/
public void setBindPoseBuffer(VertexBuffer bindPoseBuffer) {
this.bindPoseBuffer = bindPoseBuffer;
}
/**
* @return the bind buffer for normals
*/
public VertexBuffer getBindPoseBuffer() {
return bindPoseBuffer;
}
} }

@ -278,7 +278,7 @@ public class MeshHelper extends AbstractBlenderHelper {
geometries = new ArrayList<Geometry>(meshesMap.size()); geometries = new ArrayList<Geometry>(meshesMap.size());
VertexBuffer verticesBuffer = new VertexBuffer(Type.Position); VertexBuffer verticesBuffer = new VertexBuffer(Type.Position);
verticesBuffer.setupData(Usage.Stream, 3, Format.Float, verticesBuffer.setupData(Usage.Static, 3, Format.Float,
BufferUtils.createFloatBuffer(vertexList.toArray(new Vector3f[vertexList.size()]))); BufferUtils.createFloatBuffer(vertexList.toArray(new Vector3f[vertexList.size()])));
// initial vertex position (used with animation) // initial vertex position (used with animation)
@ -286,7 +286,7 @@ public class MeshHelper extends AbstractBlenderHelper {
verticesBind.setupData(Usage.CpuOnly, 3, Format.Float, BufferUtils.clone(verticesBuffer.getData())); verticesBind.setupData(Usage.CpuOnly, 3, Format.Float, BufferUtils.clone(verticesBuffer.getData()));
VertexBuffer normalsBuffer = new VertexBuffer(Type.Normal); VertexBuffer normalsBuffer = new VertexBuffer(Type.Normal);
normalsBuffer.setupData(Usage.Stream, 3, Format.Float, BufferUtils.createFloatBuffer(normals)); normalsBuffer.setupData(Usage.Static, 3, Format.Float, BufferUtils.createFloatBuffer(normals));
// initial normals position (used with animation) // initial normals position (used with animation)
VertexBuffer normalsBind = new VertexBuffer(Type.BindPoseNormal); VertexBuffer normalsBind = new VertexBuffer(Type.BindPoseNormal);
@ -323,7 +323,7 @@ public class MeshHelper extends AbstractBlenderHelper {
} }
mesh.setBuffer(verticesBuffer); mesh.setBuffer(verticesBuffer);
mesh.setBuffer(verticesBind); meshContext.setBindPoseBuffer(verticesBind);//this is stored in the context and applied when needed (when animation is applied to the mesh)
// setting vertices colors // setting vertices colors
if (verticesColorsBuffer != null) { if (verticesColorsBuffer != null) {
@ -333,7 +333,7 @@ public class MeshHelper extends AbstractBlenderHelper {
// setting faces' normals // setting faces' normals
mesh.setBuffer(normalsBuffer); mesh.setBuffer(normalsBuffer);
mesh.setBuffer(normalsBind); meshContext.setBindNormalBuffer(normalsBind);//this is stored in the context and applied when needed (when animation is applied to the mesh)
// creating the result // creating the result
Geometry geometry = new Geometry(name + (geometries.size() + 1), mesh); Geometry geometry = new Geometry(name + (geometries.size() + 1), mesh);

@ -177,9 +177,20 @@ import com.jme3.util.BufferUtils;
} }
// setting weights for bones // setting weights for bones
List<Geometry> geomList = (List<Geometry>) blenderContext.getLoadedFeature(this.meshOMA, LoadedFeatureDataType.LOADED_FEATURE); List<Geometry> geomList = (List<Geometry>) blenderContext.getLoadedFeature(meshOMA, LoadedFeatureDataType.LOADED_FEATURE);
MeshContext meshContext = blenderContext.getMeshContext(meshOMA);
for (Geometry geom : geomList) { for (Geometry geom : geomList) {
Mesh mesh = geom.getMesh(); Mesh mesh = geom.getMesh();
if(meshContext.getBindNormalBuffer() != null) {
mesh.setBuffer(meshContext.getBindNormalBuffer());
}
if(meshContext.getBindPoseBuffer() != null) {
mesh.setBuffer(meshContext.getBindPoseBuffer());
}
//change the usage type of vertex and normal buffers from Static to Stream
mesh.getBuffer(Type.Position).setUsage(Usage.Stream);
mesh.getBuffer(Type.Normal).setUsage(Usage.Stream);
if (this.verticesWeights != null) { if (this.verticesWeights != null) {
mesh.setMaxNumWeights(this.boneGroups); mesh.setMaxNumWeights(this.boneGroups);
mesh.setBuffer(this.verticesWeights); mesh.setBuffer(this.verticesWeights);

Loading…
Cancel
Save