set(mesh);\r
}\r
\r
+ /** Construct a new btIndexedMesh based on the supplied {@link Mesh}\r
+ * The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh.\r
+ * The buffers for the vertices and indices are shared amonst both. */\r
+ public btIndexedMesh(final Mesh mesh, int offset, int count) {\r
+ this();\r
+ set(mesh, offset, count);\r
+ }\r
+ \r
/** Convenience method to set this btIndexedMesh to the specified {@link Mesh} \r
* The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh.\r
* The buffers for the vertices and indices are shared amonst both. */\r
public void set(final Mesh mesh) {\r
- final int numIndices = mesh.getNumIndices();\r
- if ((numIndices <= 0) || ((numIndices % 3) != 0))\r
+ set(mesh, 0, mesh.getNumIndices());\r
+ }\r
+\r
+ /** Convenience method to set this btIndexedMesh to the specified {@link Mesh} \r
+ * The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh.\r
+ * The buffers for the vertices and indices are shared amonst both. */\r
+ public void set(final Mesh mesh, int offset, int count) {\r
+ if ((count <= 0) || ((count % 3) != 0))\r
throw new com.badlogic.gdx.utils.GdxRuntimeException("Mesh must be indexed and triangulated");\r
java.nio.FloatBuffer buf = mesh.getVerticesBuffer();\r
+ java.nio.ShortBuffer ind = mesh.getIndicesBuffer();\r
VertexAttribute posAttr = mesh.getVertexAttribute(Usage.Position);\r
if (posAttr == null)\r
throw new com.badlogic.gdx.utils.GdxRuntimeException("Mesh doesn't have a position attribute");\r
final int pos = buf.position();\r
buf.position(posAttr.offset);\r
setM_indexType(PHY_ScalarType.PHY_SHORT);\r
- setM_numTriangles(numIndices/3);\r
+ setM_numTriangles(count/3);\r
setM_numVertices(mesh.getNumVertices());\r
setM_triangleIndexStride(6);\r
setM_vertexStride(mesh.getVertexSize());\r
setM_vertexType(PHY_ScalarType.PHY_FLOAT);\r
- setTriangleIndexBase(mesh.getIndicesBuffer());\r
+ final int ipos = ind.position();\r
+ ind.position(offset);\r
+ setTriangleIndexBase(ind);\r
setVertexBase(buf);\r
+ ind.position(ipos);\r
buf.position(pos);\r
}\r
\r
* The buffers for the vertices and indices are shared amongst both. */\r
public void addModel(final com.badlogic.gdx.graphics.g3d.model.Model... models) {\r
for (int i = 0; i < models.length; i++) {\r
- final com.badlogic.gdx.graphics.g3d.model.SubMesh[] subMeshes = models[i].getSubMeshes();\r
- for (int j = 0; j < subMeshes.length; j++)\r
- if (subMeshes[j].primitiveType == com.badlogic.gdx.graphics.GL10.GL_TRIANGLES)\r
- addIndexedMesh(new btIndexedMesh(subMeshes[j].getMesh()), PHY_ScalarType.PHY_SHORT, true);\r
+ for (int j = 0; j < models[i].meshParts.size; j++) {\r
+ com.badlogic.gdx.graphics.g3d.model.MeshPart mp = models[i].meshParts.get(j);\r
+ if (mp.primitiveType == com.badlogic.gdx.graphics.GL10.GL_TRIANGLES)\r
+ addIndexedMesh(new btIndexedMesh(mp.mesh, mp.indexOffset, mp.numVertices), PHY_ScalarType.PHY_SHORT, true);\r
+ }\r
}\r
}\r
\r
set(mesh);
}
+ /** Construct a new btIndexedMesh based on the supplied {@link Mesh}
+ * The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh.
+ * The buffers for the vertices and indices are shared amonst both. */
+ public btIndexedMesh(final Mesh mesh, int offset, int count) {
+ this();
+ set(mesh, offset, count);
+ }
+
/** Convenience method to set this btIndexedMesh to the specified {@link Mesh}
* The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh.
* The buffers for the vertices and indices are shared amonst both. */
public void set(final Mesh mesh) {
- final int numIndices = mesh.getNumIndices();
- if ((numIndices <= 0) || ((numIndices % 3) != 0))
+ set(mesh, 0, mesh.getNumIndices());
+ }
+
+ /** Convenience method to set this btIndexedMesh to the specified {@link Mesh}
+ * The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh.
+ * The buffers for the vertices and indices are shared amonst both. */
+ public void set(final Mesh mesh, int offset, int count) {
+ if ((count <= 0) || ((count % 3) != 0))
throw new com.badlogic.gdx.utils.GdxRuntimeException("Mesh must be indexed and triangulated");
java.nio.FloatBuffer buf = mesh.getVerticesBuffer();
+ java.nio.ShortBuffer ind = mesh.getIndicesBuffer();
VertexAttribute posAttr = mesh.getVertexAttribute(Usage.Position);
if (posAttr == null)
throw new com.badlogic.gdx.utils.GdxRuntimeException("Mesh doesn't have a position attribute");
final int pos = buf.position();
buf.position(posAttr.offset);
setM_indexType(PHY_ScalarType.PHY_SHORT);
- setM_numTriangles(numIndices/3);
+ setM_numTriangles(count/3);
setM_numVertices(mesh.getNumVertices());
setM_triangleIndexStride(6);
setM_vertexStride(mesh.getVertexSize());
setM_vertexType(PHY_ScalarType.PHY_FLOAT);
- setTriangleIndexBase(mesh.getIndicesBuffer());
+ final int ipos = ind.position();
+ ind.position(offset);
+ setTriangleIndexBase(ind);
setVertexBase(buf);
+ ind.position(ipos);
buf.position(pos);
}
%}
* The buffers for the vertices and indices are shared amongst both. */
public void addModel(final com.badlogic.gdx.graphics.g3d.model.Model... models) {
for (int i = 0; i < models.length; i++) {
- final com.badlogic.gdx.graphics.g3d.model.SubMesh[] subMeshes = models[i].getSubMeshes();
- for (int j = 0; j < subMeshes.length; j++)
- if (subMeshes[j].primitiveType == com.badlogic.gdx.graphics.GL10.GL_TRIANGLES)
- addIndexedMesh(new btIndexedMesh(subMeshes[j].getMesh()), PHY_ScalarType.PHY_SHORT, true);
+ for (int j = 0; j < models[i].meshParts.size; j++) {
+ com.badlogic.gdx.graphics.g3d.model.MeshPart mp = models[i].meshParts.get(j);
+ if (mp.primitiveType == com.badlogic.gdx.graphics.GL10.GL_TRIANGLES)
+ addIndexedMesh(new btIndexedMesh(mp.mesh, mp.indexOffset, mp.numVertices), PHY_ScalarType.PHY_SHORT, true);
+ }
}
}
sphereConstructor.bodyInfo.setM_restitution(1f);
world.addConstructor("sphere", sphereConstructor);
- final StillModel sceneModel = ModelLoaderRegistry.loadStillModel(Gdx.files.internal("data/scene.obj"));
- final BulletConstructor sceneConstructor = new BulletConstructor(sceneModel, 0f, new btBvhTriangleMeshShape(true, sceneModel));
- sceneConstructor.bodyInfo.setM_restitution(0.25f);
- world.addConstructor("scene", sceneConstructor);
+ // final StillModel sceneModel = ModelLoaderRegistry.loadStillModel(Gdx.files.internal("data/scene.obj"));
+ // final BulletConstructor sceneConstructor = new BulletConstructor(sceneModel, 0f, new btBvhTriangleMeshShape(true, sceneModel));
+ // sceneConstructor.bodyInfo.setM_restitution(0.25f);
+ // world.addConstructor("scene", sceneConstructor);
- world.add("scene", (new Matrix4()).setToTranslation(0f, 2f, 0f).rotate(Vector3.Y, -90))
- .color.set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
+ // world.add("scene", (new Matrix4()).setToTranslation(0f, 2f, 0f).rotate(Vector3.Y, -90))
+ // .color.set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
world.add("ground", 0f, 0f, 0f)
.color.set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);