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