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
31 public static long getCPtr(btIndexedMesh obj) {
\r
32 return (obj == null) ? 0 : obj.swigCPtr;
\r
36 protected void finalize() throws Throwable {
\r
42 @Override protected synchronized void delete() {
\r
43 if (swigCPtr != 0) {
\r
45 swigCMemOwn = false;
\r
46 gdxBulletJNI.delete_btIndexedMesh(swigCPtr);
\r
53 protected final static Array<btIndexedMesh> instances = new Array<btIndexedMesh>();
\r
54 protected static btIndexedMesh getInstance(final MeshPart meshPart) {
\r
55 final int n = instances.size;
\r
56 for (int i = 0; i < n; i++) {
\r
57 final btIndexedMesh mesh = instances.get(i);
\r
58 if (meshPart.equals(mesh.meshPart))
\r
64 /** Create or reuse a btIndexedMesh instance based on the specified {@link MeshPart}.
\r
65 * Use {@link #release()} to release the mesh when it's no longer needed. */
\r
66 public static btIndexedMesh obtain(final MeshPart meshPart) {
\r
67 if (meshPart == null)
\r
68 throw new GdxRuntimeException("meshPart cannot be null");
\r
70 btIndexedMesh result = getInstance(meshPart);
\r
71 if (result == null) {
\r
72 result = new btIndexedMesh(meshPart);
\r
73 instances.add(result);
\r
79 protected MeshPart meshPart;
\r
81 /** Construct a new btIndexedMesh based on the supplied {@link Mesh}
\r
82 * The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh.
\r
83 * The buffers for the vertices and indices are shared amonst both. */
\r
84 public btIndexedMesh(final Mesh mesh) {
\r
89 /** Construct a new btIndexedMesh based on the supplied {@link MeshPart}
\r
90 * The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh.
\r
91 * The buffers for the vertices and indices are shared amonst both. */
\r
92 public btIndexedMesh(final MeshPart meshPart) {
\r
97 /** Construct a new btIndexedMesh based on the supplied {@link Mesh}
\r
98 * The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh.
\r
99 * The buffers for the vertices and indices are shared amonst both. */
\r
100 public btIndexedMesh(final Mesh mesh, int offset, int count) {
\r
102 set(mesh, offset, count);
\r
105 /** @return The {@link MeshPart} used to create or set this btIndexedMesh, may be null. */
\r
106 public MeshPart getMeshPart() {
\r
110 /** Convenience method to set this btIndexedMesh to the specified {@link Mesh}
\r
111 * The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh.
\r
112 * The buffers for the vertices and indices are shared amonst both. */
\r
113 public void set(final Mesh mesh) {
\r
114 set(mesh, 0, mesh.getNumIndices());
\r
117 /** Convenience method to set this btIndexedMesh to the specified {@link MeshPart}
\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 MeshPart meshPart) {
\r
121 if (meshPart.primitiveType != com.badlogic.gdx.graphics.GL10.GL_TRIANGLES)
\r
122 throw new com.badlogic.gdx.utils.GdxRuntimeException("Mesh must be indexed and triangulated");
\r
123 set(meshPart.mesh, meshPart.indexOffset, meshPart.numVertices);
\r
124 this.meshPart = meshPart;
\r
127 /** Convenience method to set this btIndexedMesh to the specified {@link Mesh}
\r
128 * The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh.
\r
129 * The buffers for the vertices and indices are shared amonst both. */
\r
130 public void set(final Mesh mesh, int offset, int count) {
\r
131 if ((count <= 0) || ((count % 3) != 0))
\r
132 throw new com.badlogic.gdx.utils.GdxRuntimeException("Mesh must be indexed and triangulated");
\r
134 VertexAttribute posAttr = mesh.getVertexAttribute(Usage.Position);
\r
136 if (posAttr == null)
\r
137 throw new com.badlogic.gdx.utils.GdxRuntimeException("Mesh doesn't have a position attribute");
\r
139 setVertices(mesh.getVerticesBuffer(), mesh.getVertexSize(), mesh.getNumVertices(), posAttr.offset);
\r
140 setIndices(mesh.getIndicesBuffer(), offset, count);
\r
145 public void setNumTriangles(int value) {
\r
146 gdxBulletJNI.btIndexedMesh_numTriangles_set(swigCPtr, this, value);
\r
149 public int getNumTriangles() {
\r
150 return gdxBulletJNI.btIndexedMesh_numTriangles_get(swigCPtr, this);
\r
153 public void setTriangleIndexBase(java.nio.ByteBuffer value) {
\r
154 assert value.isDirect() : "Buffer must be allocated direct.";
\r
156 gdxBulletJNI.btIndexedMesh_triangleIndexBase_set(swigCPtr, this, value);
\r
160 public java.nio.ByteBuffer getTriangleIndexBase() {
\r
161 return gdxBulletJNI.btIndexedMesh_triangleIndexBase_get(swigCPtr, this);
\r
164 public void setTriangleIndexStride(int value) {
\r
165 gdxBulletJNI.btIndexedMesh_triangleIndexStride_set(swigCPtr, this, value);
\r
168 public int getTriangleIndexStride() {
\r
169 return gdxBulletJNI.btIndexedMesh_triangleIndexStride_get(swigCPtr, this);
\r
172 public void setNumVertices(int value) {
\r
173 gdxBulletJNI.btIndexedMesh_numVertices_set(swigCPtr, this, value);
\r
176 public int getNumVertices() {
\r
177 return gdxBulletJNI.btIndexedMesh_numVertices_get(swigCPtr, this);
\r
180 public void setVertexBase(java.nio.ByteBuffer value) {
\r
181 assert value.isDirect() : "Buffer must be allocated direct.";
\r
183 gdxBulletJNI.btIndexedMesh_vertexBase_set(swigCPtr, this, value);
\r
187 public java.nio.ByteBuffer getVertexBase() {
\r
188 return gdxBulletJNI.btIndexedMesh_vertexBase_get(swigCPtr, this);
\r
191 public void setVertexStride(int value) {
\r
192 gdxBulletJNI.btIndexedMesh_vertexStride_set(swigCPtr, this, value);
\r
195 public int getVertexStride() {
\r
196 return gdxBulletJNI.btIndexedMesh_vertexStride_get(swigCPtr, this);
\r
199 public void setIndexType(int value) {
\r
200 gdxBulletJNI.btIndexedMesh_indexType_set(swigCPtr, this, value);
\r
203 public int getIndexType() {
\r
204 return gdxBulletJNI.btIndexedMesh_indexType_get(swigCPtr, this);
\r
207 public void setVertexType(int value) {
\r
208 gdxBulletJNI.btIndexedMesh_vertexType_set(swigCPtr, this, value);
\r
211 public int getVertexType() {
\r
212 return gdxBulletJNI.btIndexedMesh_vertexType_get(swigCPtr, this);
\r
215 public btIndexedMesh() {
\r
216 this(gdxBulletJNI.new_btIndexedMesh(), true);
\r
219 public void setTriangleIndexBase(java.nio.ShortBuffer data) {
\r
220 assert data.isDirect() : "Buffer must be allocated direct.";
\r
222 gdxBulletJNI.btIndexedMesh_setTriangleIndexBase(swigCPtr, this, data);
\r
226 public void setVertexBase(java.nio.FloatBuffer data) {
\r
227 assert data.isDirect() : "Buffer must be allocated direct.";
\r
229 gdxBulletJNI.btIndexedMesh_setVertexBase(swigCPtr, this, data);
\r
233 public void setVertices(java.nio.FloatBuffer vertices, int sizeInBytesOfEachVertex, int vertexCount, int positionOffsetInBytes) {
\r
234 assert vertices.isDirect() : "Buffer must be allocated direct.";
\r
236 gdxBulletJNI.btIndexedMesh_setVertices(swigCPtr, this, vertices, sizeInBytesOfEachVertex, vertexCount, positionOffsetInBytes);
\r
240 public void setIndices(java.nio.ShortBuffer indices, int indexOffset, int indexCount) {
\r
241 assert indices.isDirect() : "Buffer must be allocated direct.";
\r
243 gdxBulletJNI.btIndexedMesh_setIndices(swigCPtr, this, indices, indexOffset, indexCount);
\r