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
This commit is contained in:
parent
2a00f1ccb0
commit
915638a370
@ -6,7 +6,6 @@ import java.util.Map;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import com.jme3.scene.Geometry;
|
import com.jme3.scene.Geometry;
|
||||||
import com.jme3.scene.VertexBuffer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that holds information about the mesh.
|
* Class that holds information about the mesh.
|
||||||
@ -18,10 +17,6 @@ public class MeshContext {
|
|||||||
private Map<Integer, Geometry> geometries = new HashMap<Integer, Geometry>();
|
private Map<Integer, Geometry> geometries = new HashMap<Integer, Geometry>();
|
||||||
/** The vertex reference map. */
|
/** The vertex reference map. */
|
||||||
private Map<Integer, Map<Integer, List<Integer>>> vertexReferenceMap;
|
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.
|
* 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) {
|
public void setVertexReferenceMap(Map<Integer, Map<Integer, List<Integer>>> vertexReferenceMap) {
|
||||||
this.vertexReferenceMap = 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.jme3.asset.BlenderKey.FeaturesToLoad;
|
import com.jme3.asset.BlenderKey.FeaturesToLoad;
|
||||||
@ -106,18 +107,18 @@ public class MeshHelper extends AbstractBlenderHelper {
|
|||||||
return copiedGeometries;
|
return copiedGeometries;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reading mesh data
|
|
||||||
String name = structure.getName();
|
String name = structure.getName();
|
||||||
MeshContext meshContext = new MeshContext();
|
MeshContext meshContext = new MeshContext();
|
||||||
|
LOGGER.log(Level.FINE, "Reading mesh: {0}.", name);
|
||||||
|
|
||||||
// reading materials
|
LOGGER.fine("Loading materials.");
|
||||||
MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
|
MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
|
||||||
MaterialContext[] materials = null;
|
MaterialContext[] materials = null;
|
||||||
if ((blenderContext.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.MATERIALS) != 0) {
|
if ((blenderContext.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.MATERIALS) != 0) {
|
||||||
materials = materialHelper.getMaterials(structure, blenderContext);
|
materials = materialHelper.getMaterials(structure, blenderContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
// reading vertices and their colors
|
LOGGER.fine("Reading vertices and their colors.");
|
||||||
Vector3f[][] verticesAndNormals = this.getVerticesAndNormals(structure, blenderContext);
|
Vector3f[][] verticesAndNormals = this.getVerticesAndNormals(structure, blenderContext);
|
||||||
List<byte[]> verticesColors = this.getVerticesColors(structure, blenderContext);
|
List<byte[]> verticesColors = this.getVerticesColors(structure, blenderContext);
|
||||||
|
|
||||||
@ -130,6 +131,7 @@ public class MeshHelper extends AbstractBlenderHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (meshBuilder.isEmpty()) {
|
if (meshBuilder.isEmpty()) {
|
||||||
|
LOGGER.fine("The geometry is empty.");
|
||||||
geometries = new ArrayList<Geometry>(0);
|
geometries = new ArrayList<Geometry>(0);
|
||||||
blenderContext.addLoadedFeatures(structure.getOldMemoryAddress(), structure.getName(), structure, geometries);
|
blenderContext.addLoadedFeatures(structure.getOldMemoryAddress(), structure.getName(), structure, geometries);
|
||||||
blenderContext.setMeshContext(structure.getOldMemoryAddress(), meshContext);
|
blenderContext.setMeshContext(structure.getOldMemoryAddress(), meshContext);
|
||||||
@ -138,7 +140,7 @@ public class MeshHelper extends AbstractBlenderHelper {
|
|||||||
|
|
||||||
meshContext.setVertexReferenceMap(meshBuilder.getVertexReferenceMap());
|
meshContext.setVertexReferenceMap(meshBuilder.getVertexReferenceMap());
|
||||||
|
|
||||||
// reading vertices groups (from the parent)
|
LOGGER.fine("Reading vertices groups (from the Object structure).");
|
||||||
Structure parent = blenderContext.peekParent();
|
Structure parent = blenderContext.peekParent();
|
||||||
Structure defbase = (Structure) parent.getFieldValue("defbase");
|
Structure defbase = (Structure) parent.getFieldValue("defbase");
|
||||||
List<Structure> defs = defbase.evaluateListBase(blenderContext);
|
List<Structure> defs = defbase.evaluateListBase(blenderContext);
|
||||||
@ -148,13 +150,11 @@ public class MeshHelper extends AbstractBlenderHelper {
|
|||||||
verticesGroups[defIndex++] = def.getFieldValue("name").toString();
|
verticesGroups[defIndex++] = def.getFieldValue("name").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// creating the result meshes
|
LOGGER.fine("Reading custom properties.");
|
||||||
geometries = new ArrayList<Geometry>(meshBuilder.getMeshesPartAmount());
|
|
||||||
|
|
||||||
// reading custom properties
|
|
||||||
Properties properties = this.loadProperties(structure, blenderContext);
|
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()) {
|
for (Entry<Integer, List<Integer>> meshEntry : meshBuilder.getMeshesMap().entrySet()) {
|
||||||
int materialIndex = meshEntry.getKey();
|
int materialIndex = meshEntry.getKey();
|
||||||
// key is the material index (or -1 if the material has no texture)
|
// 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);
|
mesh.setBuffer(Type.Index, 1, indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOGGER.fine("Creating vertices buffer.");
|
||||||
VertexBuffer verticesBuffer = new VertexBuffer(Type.Position);
|
VertexBuffer verticesBuffer = new VertexBuffer(Type.Position);
|
||||||
verticesBuffer.setupData(Usage.Static, 3, Format.Float, BufferUtils.createFloatBuffer(meshBuilder.getVertices(materialIndex)));
|
verticesBuffer.setupData(Usage.Static, 3, Format.Float, BufferUtils.createFloatBuffer(meshBuilder.getVertices(materialIndex)));
|
||||||
|
mesh.setBuffer(verticesBuffer);
|
||||||
|
|
||||||
// initial vertex position (used with animation)
|
LOGGER.fine("Creating normals buffer.");
|
||||||
VertexBuffer verticesBind = new VertexBuffer(Type.BindPosePosition);
|
|
||||||
verticesBind.setupData(Usage.CpuOnly, 3, Format.Float, BufferUtils.createFloatBuffer(meshBuilder.getVertices(materialIndex)));
|
|
||||||
|
|
||||||
VertexBuffer normalsBuffer = new VertexBuffer(Type.Normal);
|
VertexBuffer normalsBuffer = new VertexBuffer(Type.Normal);
|
||||||
normalsBuffer.setupData(Usage.Static, 3, Format.Float, BufferUtils.createFloatBuffer(meshBuilder.getNormals(materialIndex)));
|
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) {
|
if (verticesColors != null) {
|
||||||
|
LOGGER.fine("Setting vertices colors.");
|
||||||
mesh.setBuffer(Type.Color, 4, meshBuilder.getVertexColorsBuffer(materialIndex));
|
mesh.setBuffer(Type.Color, 4, meshBuilder.getVertexColorsBuffer(materialIndex));
|
||||||
mesh.getBuffer(Type.Color).setNormalized(true);
|
mesh.getBuffer(Type.Color).setNormalized(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// setting faces' normals
|
LOGGER.fine("Preparing the result part.");
|
||||||
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
|
|
||||||
Geometry geometry = new Geometry(name + (geometries.size() + 1), mesh);
|
Geometry geometry = new Geometry(name + (geometries.size() + 1), mesh);
|
||||||
if (properties != null && properties.getValue() != null) {
|
if (properties != null && properties.getValue() != null) {
|
||||||
this.applyProperties(geometry, properties);
|
this.applyProperties(geometry, properties);
|
||||||
@ -347,6 +336,7 @@ public class MeshHelper extends AbstractBlenderHelper {
|
|||||||
* blender file
|
* blender file
|
||||||
*/
|
*/
|
||||||
private void readBMesh(MeshBuilder meshBuilder, Structure meshStructure, BlenderContext blenderContext) throws BlenderFileException {
|
private void readBMesh(MeshBuilder meshBuilder, Structure meshStructure, BlenderContext blenderContext) throws BlenderFileException {
|
||||||
|
LOGGER.fine("Reading BMesh.");
|
||||||
Pointer pMLoop = (Pointer) meshStructure.getFieldValue("mloop");
|
Pointer pMLoop = (Pointer) meshStructure.getFieldValue("mloop");
|
||||||
Pointer pMPoly = (Pointer) meshStructure.getFieldValue("mpoly");
|
Pointer pMPoly = (Pointer) meshStructure.getFieldValue("mpoly");
|
||||||
Pointer pMEdge = (Pointer) meshStructure.getFieldValue("medge");
|
Pointer pMEdge = (Pointer) meshStructure.getFieldValue("medge");
|
||||||
@ -409,6 +399,7 @@ public class MeshHelper extends AbstractBlenderHelper {
|
|||||||
* blender file
|
* blender file
|
||||||
*/
|
*/
|
||||||
private void readTraditionalFaces(MeshBuilder meshBuilder, Structure meshStructure, BlenderContext blenderContext) throws BlenderFileException {
|
private void readTraditionalFaces(MeshBuilder meshBuilder, Structure meshStructure, BlenderContext blenderContext) throws BlenderFileException {
|
||||||
|
LOGGER.fine("Reading traditional faces.");
|
||||||
Pointer pMFace = (Pointer) meshStructure.getFieldValue("mface");
|
Pointer pMFace = (Pointer) meshStructure.getFieldValue("mface");
|
||||||
List<Structure> mFaces = pMFace.isNotNull() ? pMFace.fetchData(blenderContext.getInputStream()) : null;
|
List<Structure> mFaces = pMFace.isNotNull() ? pMFace.fetchData(blenderContext.getInputStream()) : null;
|
||||||
if (mFaces != null && mFaces.size() > 0) {
|
if (mFaces != null && mFaces.size() > 0) {
|
||||||
|
@ -46,7 +46,6 @@ import com.jme3.util.BufferUtils;
|
|||||||
/* package */class ArmatureModifier extends Modifier {
|
/* package */class ArmatureModifier extends Modifier {
|
||||||
private static final Logger LOGGER = Logger.getLogger(ArmatureModifier.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(ArmatureModifier.class.getName());
|
||||||
private static final int MAXIMUM_WEIGHTS_PER_VERTEX = 4; // JME
|
private static final int MAXIMUM_WEIGHTS_PER_VERTEX = 4; // JME
|
||||||
// limitation
|
|
||||||
|
|
||||||
private Skeleton skeleton;
|
private Skeleton skeleton;
|
||||||
private Structure objectStructure;
|
private Structure objectStructure;
|
||||||
@ -197,16 +196,9 @@ import com.jme3.util.BufferUtils;
|
|||||||
mesh.setBuffer(buffers[0]);
|
mesh.setBuffer(buffers[0]);
|
||||||
mesh.setBuffer(buffers[1]);
|
mesh.setBuffer(buffers[1]);
|
||||||
|
|
||||||
//FIXME @Kaelthas this should be replaced by a call to
|
LOGGER.fine("Generating bind pose and normal buffers.");
|
||||||
//mesh.generateBindPos(true)
|
mesh.generateBindPose(true);
|
||||||
VertexBuffer bindNormalBuffer = meshContext.getBindNormalBuffer(materialIndex);
|
|
||||||
if (bindNormalBuffer != null) {
|
|
||||||
mesh.setBuffer(bindNormalBuffer);
|
|
||||||
}
|
|
||||||
VertexBuffer bindPoseBuffer = meshContext.getBindPoseBuffer(materialIndex);
|
|
||||||
if (bindPoseBuffer != null) {
|
|
||||||
mesh.setBuffer(bindPoseBuffer);
|
|
||||||
}
|
|
||||||
// change the usage type of vertex and normal buffers from
|
// change the usage type of vertex and normal buffers from
|
||||||
// Static to Stream
|
// Static to Stream
|
||||||
mesh.getBuffer(Type.Position).setUsage(Usage.Stream);
|
mesh.getBuffer(Type.Position).setUsage(Usage.Stream);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user