1 /* ----------------------------------------------------------------------------
\r
2 * This file was automatically generated by SWIG (http://www.swig.org).
\r
5 * Do not make changes to this file unless you know what you are doing--modify
\r
6 * the SWIG interface file instead.
\r
7 * ----------------------------------------------------------------------------- */
\r
9 package com.badlogic.gdx.physics.bullet;
\r
11 import com.badlogic.gdx.graphics.Mesh;
\r
12 import com.badlogic.gdx.graphics.VertexAttribute;
\r
13 import com.badlogic.gdx.graphics.VertexAttributes.Usage;
\r
14 import com.badlogic.gdx.graphics.g3d.model.MeshPart;
\r
15 import com.badlogic.gdx.utils.Array;
\r
16 import com.badlogic.gdx.utils.GdxRuntimeException;
\r
18 public class btIndexedMesh extends BulletBase {
\r
19 private long swigCPtr;
\r
21 protected btIndexedMesh(final String className, long cPtr, boolean cMemoryOwn) {
\r
22 super(className, cPtr, cMemoryOwn);
\r
26 protected btIndexedMesh(long cPtr, boolean cMemoryOwn) {
\r
27 this("btIndexedMesh", cPtr, cMemoryOwn);
\r
32 protected void reset(long cPtr, boolean cMemoryOwn) {
\r
35 super.reset(swigCPtr = cPtr, cMemoryOwn);
\r
38 public static long getCPtr(btIndexedMesh obj) {
\r
39 return (obj == null) ? 0 : obj.swigCPtr;
\r
43 protected void finalize() throws Throwable {
\r
49 @Override protected synchronized void delete() {
\r
50 if (swigCPtr != 0) {
\r
52 swigCMemOwn = false;
\r
53 gdxBulletJNI.delete_btIndexedMesh(swigCPtr);
\r
60 protected final static Array<btIndexedMesh> instances = new Array<btIndexedMesh>();
\r
61 protected static btIndexedMesh getInstance(final MeshPart meshPart) {
\r
62 final int n = instances.size;
\r
63 for (int i = 0; i < n; i++) {
\r
64 final btIndexedMesh mesh = instances.get(i);
\r
65 if (meshPart.equals(mesh.meshPart))
\r
71 /** Create or reuse a btIndexedMesh instance based on the specified {@link MeshPart}.
\r
72 * Use {@link #release()} to release the mesh when it's no longer needed. */
\r
73 public static btIndexedMesh obtain(final MeshPart meshPart) {
\r
74 if (meshPart == null)
\r
75 throw new GdxRuntimeException("meshPart cannot be null");
\r
77 btIndexedMesh result = getInstance(meshPart);
\r
78 if (result == null) {
\r
79 result = new btIndexedMesh(meshPart);
\r
80 instances.add(result);
\r
86 protected MeshPart meshPart;
\r
88 /** Construct a new btIndexedMesh based on the supplied {@link Mesh}
\r
89 * The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh.
\r
90 * The buffers for the vertices and indices are shared amonst both. */
\r
91 public btIndexedMesh(final Mesh mesh) {
\r
96 /** Construct a new btIndexedMesh based on the supplied {@link MeshPart}
\r
97 * The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh.
\r
98 * The buffers for the vertices and indices are shared amonst both. */
\r
99 public btIndexedMesh(final MeshPart meshPart) {
\r
104 /** Construct a new btIndexedMesh based on the supplied {@link Mesh}
\r
105 * The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh.
\r
106 * The buffers for the vertices and indices are shared amonst both. */
\r
107 public btIndexedMesh(final Mesh mesh, int offset, int count) {
\r
109 set(mesh, offset, count);
\r
112 /** @return The {@link MeshPart} used to create or set this btIndexedMesh, may be null. */
\r
113 public MeshPart getMeshPart() {
\r
117 /** Convenience method to set this btIndexedMesh to the specified {@link Mesh}
\r
118 * The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh.
\r
119 * The buffers for the vertices and indices are shared amonst both. */
\r
120 public void set(final Mesh mesh) {
\r
121 set(mesh, 0, mesh.getNumIndices());
\r
124 /** Convenience method to set this btIndexedMesh to the specified {@link MeshPart}
\r
125 * The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh.
\r
126 * The buffers for the vertices and indices are shared amonst both. */
\r
127 public void set(final MeshPart meshPart) {
\r
128 if (meshPart.primitiveType != com.badlogic.gdx.graphics.GL10.GL_TRIANGLES)
\r
129 throw new com.badlogic.gdx.utils.GdxRuntimeException("Mesh must be indexed and triangulated");
\r
130 set(meshPart.mesh, meshPart.indexOffset, meshPart.numVertices);
\r
131 this.meshPart = meshPart;
\r
134 /** Convenience method to set this btIndexedMesh to the specified {@link Mesh}
\r
135 * The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh.
\r
136 * The buffers for the vertices and indices are shared amonst both. */
\r
137 public void set(final Mesh mesh, int offset, int count) {
\r
138 if ((count <= 0) || ((count % 3) != 0))
\r
139 throw new com.badlogic.gdx.utils.GdxRuntimeException("Mesh must be indexed and triangulated");
\r
141 VertexAttribute posAttr = mesh.getVertexAttribute(Usage.Position);
\r
143 if (posAttr == null)
\r
144 throw new com.badlogic.gdx.utils.GdxRuntimeException("Mesh doesn't have a position attribute");
\r
146 setVertices(mesh.getVerticesBuffer(), mesh.getVertexSize(), mesh.getNumVertices(), posAttr.offset);
\r
147 setIndices(mesh.getIndicesBuffer(), offset, count);
\r
152 public void setNumTriangles(int value) {
\r
153 gdxBulletJNI.btIndexedMesh_numTriangles_set(swigCPtr, this, value);
\r
156 public int getNumTriangles() {
\r
157 return gdxBulletJNI.btIndexedMesh_numTriangles_get(swigCPtr, this);
\r
160 public void setTriangleIndexBase(java.nio.ByteBuffer value) {
\r
161 assert value.isDirect() : "Buffer must be allocated direct.";
\r
163 gdxBulletJNI.btIndexedMesh_triangleIndexBase_set(swigCPtr, this, value);
\r
167 public java.nio.ByteBuffer getTriangleIndexBase() {
\r
168 return gdxBulletJNI.btIndexedMesh_triangleIndexBase_get(swigCPtr, this);
\r
171 public void setTriangleIndexStride(int value) {
\r
172 gdxBulletJNI.btIndexedMesh_triangleIndexStride_set(swigCPtr, this, value);
\r
175 public int getTriangleIndexStride() {
\r
176 return gdxBulletJNI.btIndexedMesh_triangleIndexStride_get(swigCPtr, this);
\r
179 public void setNumVertices(int value) {
\r
180 gdxBulletJNI.btIndexedMesh_numVertices_set(swigCPtr, this, value);
\r
183 public int getNumVertices() {
\r
184 return gdxBulletJNI.btIndexedMesh_numVertices_get(swigCPtr, this);
\r
187 public void setVertexBase(java.nio.ByteBuffer value) {
\r
188 assert value.isDirect() : "Buffer must be allocated direct.";
\r
190 gdxBulletJNI.btIndexedMesh_vertexBase_set(swigCPtr, this, value);
\r
194 public java.nio.ByteBuffer getVertexBase() {
\r
195 return gdxBulletJNI.btIndexedMesh_vertexBase_get(swigCPtr, this);
\r
198 public void setVertexStride(int value) {
\r
199 gdxBulletJNI.btIndexedMesh_vertexStride_set(swigCPtr, this, value);
\r
202 public int getVertexStride() {
\r
203 return gdxBulletJNI.btIndexedMesh_vertexStride_get(swigCPtr, this);
\r
206 public void setIndexType(int value) {
\r
207 gdxBulletJNI.btIndexedMesh_indexType_set(swigCPtr, this, value);
\r
210 public int getIndexType() {
\r
211 return gdxBulletJNI.btIndexedMesh_indexType_get(swigCPtr, this);
\r
214 public void setVertexType(int value) {
\r
215 gdxBulletJNI.btIndexedMesh_vertexType_set(swigCPtr, this, value);
\r
218 public int getVertexType() {
\r
219 return gdxBulletJNI.btIndexedMesh_vertexType_get(swigCPtr, this);
\r
222 public btIndexedMesh() {
\r
223 this(gdxBulletJNI.new_btIndexedMesh(), true);
\r
226 public void setTriangleIndexBase(java.nio.ShortBuffer data) {
\r
227 assert data.isDirect() : "Buffer must be allocated direct.";
\r
229 gdxBulletJNI.btIndexedMesh_setTriangleIndexBase(swigCPtr, this, data);
\r
233 public void setVertexBase(java.nio.FloatBuffer data) {
\r
234 assert data.isDirect() : "Buffer must be allocated direct.";
\r
236 gdxBulletJNI.btIndexedMesh_setVertexBase(swigCPtr, this, data);
\r
240 public void setVertices(java.nio.FloatBuffer vertices, int sizeInBytesOfEachVertex, int vertexCount, int positionOffsetInBytes) {
\r
241 assert vertices.isDirect() : "Buffer must be allocated direct.";
\r
243 gdxBulletJNI.btIndexedMesh_setVertices(swigCPtr, this, vertices, sizeInBytesOfEachVertex, vertexCount, positionOffsetInBytes);
\r
247 public void setIndices(java.nio.ShortBuffer indices, int indexOffset, int indexCount) {
\r
248 assert indices.isDirect() : "Buffer must be allocated direct.";
\r
250 gdxBulletJNI.btIndexedMesh_setIndices(swigCPtr, this, indices, indexOffset, indexCount);
\r