formatting of MeshLoader before an upcomming change

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10538 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 12 years ago
parent eb5525e581
commit 1e2dc1486b
  1. 95
      engine/src/ogre/com/jme3/scene/plugins/ogre/MeshLoader.java

@ -148,17 +148,17 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
public void endDocument() { public void endDocument() {
} }
private void pushIndex(int index){ private void pushIndex(int index) {
if (ib != null){ if (ib != null) {
ib.put(index); ib.put(index);
}else{ } else {
sb.put((short)index); sb.put((short) index);
} }
} }
private void pushFace(String v1, String v2, String v3) throws SAXException { private void pushFace(String v1, String v2, String v3) throws SAXException {
// TODO: fan/strip support // TODO: fan/strip support
switch (mesh.getMode()){ switch (mesh.getMode()) {
case Triangles: case Triangles:
pushIndex(parseInt(v1)); pushIndex(parseInt(v1));
pushIndex(parseInt(v2)); pushIndex(parseInt(v2));
@ -175,15 +175,14 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
} }
// private boolean isUsingSharedVerts(Geometry geom) { // private boolean isUsingSharedVerts(Geometry geom) {
// Old code for buffer sharer // Old code for buffer sharer
//return geom.getUserData(UserData.JME_SHAREDMESH) != null; //return geom.getUserData(UserData.JME_SHAREDMESH) != null;
// } // }
private void startFaces(String count) throws SAXException { private void startFaces(String count) throws SAXException {
int numFaces = parseInt(count); int numFaces = parseInt(count);
int indicesPerFace = 0; int indicesPerFace = 0;
switch (mesh.getMode()){ switch (mesh.getMode()) {
case Triangles: case Triangles:
indicesPerFace = 3; indicesPerFace = 3;
break; break;
@ -198,7 +197,7 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
} }
int numIndices = indicesPerFace * numFaces; int numIndices = indicesPerFace * numFaces;
vb = new VertexBuffer(VertexBuffer.Type.Index); vb = new VertexBuffer(VertexBuffer.Type.Index);
if (!usesBigIndices) { if (!usesBigIndices) {
sb = BufferUtils.createShortBuffer(numIndices); sb = BufferUtils.createShortBuffer(numIndices);
@ -218,9 +217,9 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
// load as native jme3 material instance // load as native jme3 material instance
try { try {
mat = assetManager.loadMaterial(matName); mat = assetManager.loadMaterial(matName);
} catch (AssetNotFoundException ex){ } catch (AssetNotFoundException ex) {
// Warning will be raised (see below) // Warning will be raised (see below)
if (!ex.getMessage().equals(matName)){ if (!ex.getMessage().equals(matName)) {
throw ex; throw ex;
} }
} }
@ -229,10 +228,10 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
mat = materialList.get(matName); mat = materialList.get(matName);
} }
} }
if (mat == null) { if (mat == null) {
logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[]{matName, key}); logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[]{matName, key});
mat = PlaceholderAssets.getPlaceholderMaterial(assetManager); mat = PlaceholderAssets.getPlaceholderMaterial(assetManager);
//mat.setKey(new MaterialKey(matName)); //mat.setKey(new MaterialKey(matName));
} }
@ -247,10 +246,10 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
mesh = new Mesh(); mesh = new Mesh();
if (opType == null || opType.equals("triangle_list")) { if (opType == null || opType.equals("triangle_list")) {
mesh.setMode(Mesh.Mode.Triangles); mesh.setMode(Mesh.Mode.Triangles);
//} else if (opType.equals("triangle_strip")) { //} else if (opType.equals("triangle_strip")) {
// mesh.setMode(Mesh.Mode.TriangleStrip); // mesh.setMode(Mesh.Mode.TriangleStrip);
//} else if (opType.equals("triangle_fan")) { //} else if (opType.equals("triangle_fan")) {
// mesh.setMode(Mesh.Mode.TriangleFan); // mesh.setMode(Mesh.Mode.TriangleFan);
} else if (opType.equals("line_list")) { } else if (opType.equals("line_list")) {
mesh.setMode(Mesh.Mode.Lines); mesh.setMode(Mesh.Mode.Lines);
} else { } else {
@ -261,14 +260,14 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
usesSharedVerts = parseBool(usesharedvertices, false); usesSharedVerts = parseBool(usesharedvertices, false);
if (usesSharedVerts) { if (usesSharedVerts) {
usesSharedMesh.add(true); usesSharedMesh.add(true);
// Old code for buffer sharer // Old code for buffer sharer
// import vertexbuffers from shared geom // import vertexbuffers from shared geom
// IntMap<VertexBuffer> sharedBufs = sharedMesh.getBuffers(); // IntMap<VertexBuffer> sharedBufs = sharedMesh.getBuffers();
// for (Entry<VertexBuffer> entry : sharedBufs) { // for (Entry<VertexBuffer> entry : sharedBufs) {
// mesh.setBuffer(entry.getValue()); // mesh.setBuffer(entry.getValue());
// } // }
}else{ } else {
usesSharedMesh.add(false); usesSharedMesh.add(false);
} }
@ -302,26 +301,26 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
} }
/** /**
* Normalizes weights if needed and finds largest amount of weights used * Normalizes weights if needed and finds largest amount of weights used for
* for all vertices in the buffer. * all vertices in the buffer.
*/ */
private void endBoneAssigns() { private void endBoneAssigns() {
// if (mesh != sharedMesh && isUsingSharedVerts(geom)) { // if (mesh != sharedMesh && isUsingSharedVerts(geom)) {
// return; // return;
// } // }
if (!actuallyHasWeights){ if (!actuallyHasWeights) {
// No weights were actually written (the tag didn't have any entries) // No weights were actually written (the tag didn't have any entries)
// remove those buffers // remove those buffers
mesh.clearBuffer(Type.BoneIndex); mesh.clearBuffer(Type.BoneIndex);
mesh.clearBuffer(Type.BoneWeight); mesh.clearBuffer(Type.BoneWeight);
weightsFloatData = null; weightsFloatData = null;
indicesData = null; indicesData = null;
return; return;
} }
//int vertCount = mesh.getVertexCount(); //int vertCount = mesh.getVertexCount();
int maxWeightsPerVert = 0; int maxWeightsPerVert = 0;
weightsFloatData.rewind(); weightsFloatData.rewind();
@ -518,15 +517,15 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
int index = Integer.parseInt(submeshindex); int index = Integer.parseInt(submeshindex);
mesh = geoms.get(index).getMesh(); mesh = geoms.get(index).getMesh();
int faceCount = Integer.parseInt(numfaces); int faceCount = Integer.parseInt(numfaces);
VertexBuffer originalIndexBuffer = mesh.getBuffer(Type.Index); VertexBuffer originalIndexBuffer = mesh.getBuffer(Type.Index);
vb = new VertexBuffer(VertexBuffer.Type.Index); vb = new VertexBuffer(VertexBuffer.Type.Index);
if (originalIndexBuffer.getFormat() == Format.UnsignedInt){ if (originalIndexBuffer.getFormat() == Format.UnsignedInt) {
// LOD buffer should also be integer // LOD buffer should also be integer
ib = BufferUtils.createIntBuffer(faceCount * 3); ib = BufferUtils.createIntBuffer(faceCount * 3);
sb = null; sb = null;
vb.setupData(Usage.Static, 3, Format.UnsignedInt, ib); vb.setupData(Usage.Static, 3, Format.UnsignedInt, ib);
}else{ } else {
sb = BufferUtils.createShortBuffer(faceCount * 3); sb = BufferUtils.createShortBuffer(faceCount * 3);
ib = null; ib = null;
vb.setupData(Usage.Static, 3, Format.UnsignedShort, sb); vb.setupData(Usage.Static, 3, Format.UnsignedShort, sb);
@ -536,7 +535,7 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
if (levels == null) { if (levels == null) {
// Create the LOD levels list // Create the LOD levels list
levels = new ArrayList<VertexBuffer>(); levels = new ArrayList<VertexBuffer>();
// Add the first LOD level (always the original index buffer) // Add the first LOD level (always the original index buffer)
levels.add(originalIndexBuffer); levels.add(originalIndexBuffer);
lodLevels.put(index, levels); lodLevels.put(index, levels);
@ -593,7 +592,7 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
AssetKey assetKey = new AssetKey(folderName + name + ".xml"); AssetKey assetKey = new AssetKey(folderName + name + ".xml");
try { try {
animData = (AnimData) assetManager.loadAsset(assetKey); animData = (AnimData) assetManager.loadAsset(assetKey);
} catch (AssetNotFoundException ex){ } catch (AssetNotFoundException ex) {
logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[]{assetKey, key}); logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[]{assetKey, key});
animData = null; animData = null;
} }
@ -698,7 +697,7 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
return; return;
} }
// If submesh hack is enabled, ignore any submesh/submeshes // If submesh hack is enabled, ignore any submesh/submeshes
// end tags. // end tags.
if (qName.equals("submesh") && !submeshNamesHack) { if (qName.equals("submesh") && !submeshNamesHack) {
@ -763,12 +762,12 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
for (int i = 0; i < geoms.size(); i++) { for (int i = 0; i < geoms.size(); i++) {
Geometry g = geoms.get(i); Geometry g = geoms.get(i);
Mesh m = g.getMesh(); Mesh m = g.getMesh();
// New code for buffer extract // New code for buffer extract
if (sharedMesh != null && usesSharedMesh.get(i)) { if (sharedMesh != null && usesSharedMesh.get(i)) {
m.extractVertexData(sharedMesh); m.extractVertexData(sharedMesh);
} }
// Old code for buffer sharer // Old code for buffer sharer
//if (sharedMesh != null && isUsingSharedVerts(g)) { //if (sharedMesh != null && isUsingSharedVerts(g)) {
// m.setBound(sharedMesh.getBound().clone()); // m.setBound(sharedMesh.getBound().clone());
@ -792,14 +791,14 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
for (int i = 0; i < geoms.size(); i++) { for (int i = 0; i < geoms.size(); i++) {
Geometry g = geoms.get(i); Geometry g = geoms.get(i);
Mesh m = geoms.get(i).getMesh(); Mesh m = geoms.get(i).getMesh();
m.generateBindPose(!HARDWARE_SKINNING); m.generateBindPose(!HARDWARE_SKINNING);
// Old code for buffer sharer // Old code for buffer sharer
//boolean useShared = isUsingSharedVerts(g); //boolean useShared = isUsingSharedVerts(g);
//if (!useShared) { //if (!useShared) {
// create bind pose // create bind pose
//m.generateBindPose(!HARDWARE_SKINNING); //m.generateBindPose(!HARDWARE_SKINNING);
//} //}
} }
@ -843,7 +842,7 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
OgreMeshKey meshKey = (OgreMeshKey) key; OgreMeshKey meshKey = (OgreMeshKey) key;
materialList = meshKey.getMaterialList(); materialList = meshKey.getMaterialList();
String materialName = meshKey.getMaterialName(); String materialName = meshKey.getMaterialName();
// Material list not set but material name is available // Material list not set but material name is available
if (materialList == null && materialName != null) { if (materialList == null && materialName != null) {
OgreMaterialKey materialKey = new OgreMaterialKey(folderName + materialName + ".material"); OgreMaterialKey materialKey = new OgreMaterialKey(folderName + materialName + ".material");
@ -853,7 +852,7 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[]{materialKey, key}); logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[]{materialKey, key});
} }
} }
}else{ } else {
// Make sure to reset it to null so that previous state // Make sure to reset it to null so that previous state
// doesn't leak onto this one // doesn't leak onto this one
materialList = null; materialList = null;
@ -862,15 +861,15 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
// If for some reason material list could not be found through // If for some reason material list could not be found through
// OgreMeshKey, or if regular ModelKey specified, load using // OgreMeshKey, or if regular ModelKey specified, load using
// default method. // default method.
if (materialList == null){ if (materialList == null) {
OgreMaterialKey materialKey = new OgreMaterialKey(folderName + meshName + ".material"); OgreMaterialKey materialKey = new OgreMaterialKey(folderName + meshName + ".material");
try { try {
materialList = (MaterialList) assetManager.loadAsset(materialKey); materialList = (MaterialList) assetManager.loadAsset(materialKey);
} catch (AssetNotFoundException e) { } catch (AssetNotFoundException e) {
logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[]{ materialKey, key }); logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[]{materialKey, key});
} }
} }
// Added by larynx 25.06.2011 // Added by larynx 25.06.2011
// Android needs the namespace aware flag set to true // Android needs the namespace aware flag set to true
// Kirill 30.06.2011 // Kirill 30.06.2011
@ -878,21 +877,21 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
// checking with JmeSystem. // checking with JmeSystem.
SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true); factory.setNamespaceAware(true);
XMLReader xr = factory.newSAXParser().getXMLReader(); XMLReader xr = factory.newSAXParser().getXMLReader();
xr.setContentHandler(this); xr.setContentHandler(this);
xr.setErrorHandler(this); xr.setErrorHandler(this);
InputStreamReader r = null; InputStreamReader r = null;
try { try {
r = new InputStreamReader(info.openStream()); r = new InputStreamReader(info.openStream());
xr.parse(new InputSource(r)); xr.parse(new InputSource(r));
} finally { } finally {
if (r != null){ if (r != null) {
r.close(); r.close();
} }
} }
return compileModel(); return compileModel();
} catch (SAXException ex) { } catch (SAXException ex) {
IOException ioEx = new IOException("Error while parsing Ogre3D mesh.xml"); IOException ioEx = new IOException("Error while parsing Ogre3D mesh.xml");

Loading…
Cancel
Save