* Lines can now be imported from ogre3d meshes

* Better error messages for ogre3d meshes when strips or fans are used

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8868 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Sha..rd 13 years ago
parent ed6dedb409
commit 538b6edd35
  1. 65
      engine/src/ogre/com/jme3/scene/plugins/ogre/MeshLoader.java

@ -144,16 +144,29 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
public void endDocument() {
}
private void pushFace(String v1, String v2, String v3) throws SAXException {
int i1 = parseInt(v1);
// TODO: fan/strip support
int i2 = parseInt(v2);
int i3 = parseInt(v3);
private void pushIndex(int index){
if (ib != null){
ib.put(i1).put(i2).put(i3);
ib.put(index);
}else{
sb.put((short) i1).put((short) i2).put((short) i3);
sb.put((short)index);
}
}
private void pushFace(String v1, String v2, String v3) throws SAXException {
// TODO: fan/strip support
switch (mesh.getMode()){
case Triangles:
pushIndex(parseInt(v1));
pushIndex(parseInt(v2));
pushIndex(parseInt(v3));
break;
case Lines:
pushIndex(parseInt(v1));
pushIndex(parseInt(v2));
break;
case Points:
pushIndex(parseInt(v1));
break;
}
}
@ -163,23 +176,33 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
private void startFaces(String count) throws SAXException {
int numFaces = parseInt(count);
int numIndices;
int indicesPerFace = 0;
if (mesh.getMode() == Mesh.Mode.Triangles) {
numIndices = numFaces * 3;
} else {
throw new SAXException("Triangle strip or fan not supported!");
switch (mesh.getMode()){
case Triangles:
indicesPerFace = 3;
break;
case Lines:
indicesPerFace = 2;
break;
case Points:
indicesPerFace = 1;
break;
default:
throw new SAXException("Strips or fans not supported!");
}
int numIndices = indicesPerFace * numFaces;
vb = new VertexBuffer(VertexBuffer.Type.Index);
if (!usesBigIndices) {
sb = BufferUtils.createShortBuffer(numIndices);
ib = null;
vb.setupData(Usage.Static, 3, Format.UnsignedShort, sb);
vb.setupData(Usage.Static, indicesPerFace, Format.UnsignedShort, sb);
} else {
ib = BufferUtils.createIntBuffer(numIndices);
sb = null;
vb.setupData(Usage.Static, 3, Format.UnsignedInt, ib);
vb.setupData(Usage.Static, indicesPerFace, Format.UnsignedInt, ib);
}
mesh.setBuffer(vb);
}
@ -215,10 +238,14 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
mesh = new Mesh();
if (opType == null || opType.equals("triangle_list")) {
mesh.setMode(Mesh.Mode.Triangles);
} else if (opType.equals("triangle_strip")) {
mesh.setMode(Mesh.Mode.TriangleStrip);
} else if (opType.equals("triangle_fan")) {
mesh.setMode(Mesh.Mode.TriangleFan);
//} else if (opType.equals("triangle_strip")) {
// mesh.setMode(Mesh.Mode.TriangleStrip);
//} else if (opType.equals("triangle_fan")) {
// mesh.setMode(Mesh.Mode.TriangleFan);
} else if (opType.equals("line_list")) {
mesh.setMode(Mesh.Mode.Lines);
} else {
throw new SAXException("Unsupported operation type: " + opType);
}
usesBigIndices = parseBool(use32bitIndices, false);

Loading…
Cancel
Save