Fixing a bug that caused the loader to crash when the mesh (traditional one and not BMesh) had no faces and only edges or points instead (without support for loading edges and points yet).

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9692 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Kae..pl 12 years ago
parent 4fb6ba58c7
commit 49c47f8174
  1. 23
      engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshBuilder.java
  2. 37
      engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java

@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import com.jme3.math.FastMath;
import com.jme3.math.Vector2f;
@ -12,6 +13,8 @@ import com.jme3.math.Vector3f;
import com.jme3.util.BufferUtils;
/*package*/ class MeshBuilder {
private static final Logger LOGGER = Logger.getLogger(MeshBuilder.class.getName());
/** An array of reference vertices. */
private Vector3f[][] verticesAndNormals;
/** An list of vertices colors. */
@ -50,6 +53,26 @@ import com.jme3.util.BufferUtils;
globalVertexReferenceMap = new HashMap<Integer, Map<Integer, List<Integer>>>(verticesAndNormals.length);
}
/**
* This method adds a point to the mesh.
* @param coordinates the coordinates of the point
* @param normal the point's normal vector
* @param materialNumber the material number for this point
*/
public void appendPoint(Vector3f coordinates, Vector3f normal, int materialNumber) {
LOGGER.warning("Appending single point not yet supported!");//TODO
}
/**
* This method adds a line to the mesh.
* @param v1 index of the 1'st vertex from the reference vertex table
* @param v2 index of the 2'nd vertex from the reference vertex table
* @param smooth indicates if this face should have smooth shading or flat shading
*/
public void appendEdge(int v1, int v2, boolean smooth) {
LOGGER.warning("Appending single line not yet supported!");//TODO
}
/**
* This method adds a face to the mesh.
* @param v1 index of the 1'st vertex from the reference vertex table

@ -111,12 +111,12 @@ public class MeshHelper extends AbstractBlenderHelper {
MeshBuilder meshBuilder = new MeshBuilder(verticesAndNormals, verticesColors, this.areGeneratedTexturesPresent(materials));
Pointer pMFace = (Pointer) structure.getFieldValue("mface");
if(pMFace.isNotNull()) {
this.readTraditionalFaces(meshBuilder, structure, blenderContext);
} else {
if(this.isBMeshCompatible(structure)) {
this.readBMesh(meshBuilder, structure, blenderContext);
} else {
this.readTraditionalFaces(meshBuilder, structure, blenderContext);
}
if(meshBuilder.isEmpty()) {
geometries = new ArrayList<Geometry>(0);
blenderContext.addLoadedFeatures(structure.getOldMemoryAddress(), structure.getName(), structure, geometries);
@ -235,6 +235,19 @@ public class MeshHelper extends AbstractBlenderHelper {
return geometries;
}
/**
* Tells if the given mesh structure supports BMesh.
*
* @param meshStructure
* the mesh structure
* @return <b>true</b> if BMesh is supported and <b>false</b> otherwise
*/
private boolean isBMeshCompatible(Structure meshStructure) {
Pointer pMLoop = (Pointer) meshStructure.getFieldValue("mloop");
Pointer pMPoly = (Pointer) meshStructure.getFieldValue("mpoly");
return pMLoop != null && pMPoly != null;
}
/**
* This method reads the mesh from the new BMesh system.
*
@ -316,7 +329,7 @@ public class MeshHelper extends AbstractBlenderHelper {
@SuppressWarnings("unchecked")
private void readTraditionalFaces(MeshBuilder meshBuilder, Structure meshStructure, BlenderContext blenderContext) throws BlenderFileException {
Pointer pMFace = (Pointer) meshStructure.getFieldValue("mface");
List<Structure> mFaces = pMFace.fetchData(blenderContext.getInputStream());
List<Structure> mFaces = pMFace.isNotNull() ? pMFace.fetchData(blenderContext.getInputStream()) : null;
if (mFaces != null && mFaces.size() > 0) {
Pointer pMTFace = (Pointer) meshStructure.getFieldValue("mtface");
List<Structure> mtFaces = null;
@ -362,6 +375,20 @@ public class MeshHelper extends AbstractBlenderHelper {
meshBuilder.appendFace(v1, v3, v4, smooth, materialNumber, uvs == null ? null : uvCoordinatesForFace, true, i);
}
}
} else {
Pointer pMEdge = (Pointer) meshStructure.getFieldValue("medge");
List<Structure> mEdges = pMEdge.isNotNull() ? pMEdge.fetchData(blenderContext.getInputStream()) : null;
if (mEdges != null && mEdges.size() > 0) {
for (int i = 0; i < mEdges.size(); ++i) {
Structure mEdge = mEdges.get(i);
boolean smooth = (((Number) mEdge.getFieldValue("flag")).byteValue() & 0x01) != 0x00;
int v1 = ((Number) mEdge.getFieldValue("v1")).intValue();
int v2 = ((Number) mEdge.getFieldValue("v2")).intValue();
meshBuilder.appendEdge(v1, v2, smooth);
}
}
}
}

Loading…
Cancel
Save