Home | History | Annotate | Download | only in collision
      1 /**
      2  * Maintain a copy of the data
      3  */
      4 %module btBvhTriangleMeshShape
      5 
      6 %{
      7 #include <BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h>
      8 %}
      9 
     10 %ignore btBvhTriangleMeshShape::btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true);
     11 %ignore btBvhTriangleMeshShape::btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression,const btVector3& bvhAabbMin,const btVector3& bvhAabbMax, bool buildBvh = true);
     12 %javamethodmodifiers btBvhTriangleMeshShape::btBvhTriangleMeshShape "private";
     13 
     14 %extend btBvhTriangleMeshShape {
     15 	btBvhTriangleMeshShape(bool dummy, btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true) {
     16 		return new btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, buildBvh);
     17 	}
     18 	btBvhTriangleMeshShape(bool dummy, btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression,const btVector3& bvhAabbMin,const btVector3& bvhAabbMax, bool buildBvh = true) {
     19 		return new btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, bvhAabbMin, bvhAabbMax, buildBvh);
     20 	}
     21 };
     22 
     23 %typemap(javaimports) btBvhTriangleMeshShape %{
     24 import com.badlogic.gdx.physics.bullet.BulletBase;
     25 import com.badlogic.gdx.physics.bullet.linearmath.*;
     26 import com.badlogic.gdx.math.Vector3;
     27 import com.badlogic.gdx.math.Quaternion;
     28 import com.badlogic.gdx.math.Matrix3;
     29 import com.badlogic.gdx.math.Matrix4;
     30 import com.badlogic.gdx.graphics.Mesh;
     31 import com.badlogic.gdx.graphics.g3d.Model;
     32 import com.badlogic.gdx.graphics.g3d.model.MeshPart;
     33 import com.badlogic.gdx.graphics.g3d.model.NodePart;
     34 import com.badlogic.gdx.utils.Array;
     35 %}
     36 
     37 %typemap(javacode) btBvhTriangleMeshShape %{
     38 	protected final static Array<btBvhTriangleMeshShape> instances = new Array<btBvhTriangleMeshShape>();
     39 
     40 	protected static <T extends MeshPart> btBvhTriangleMeshShape getInstance(final Array<T> meshParts) {
     41 		for (final btBvhTriangleMeshShape instance : instances) {
     42 			if (instance.meshInterface instanceof btTriangleIndexVertexArray &&
     43 					btTriangleIndexVertexArray.compare((btTriangleIndexVertexArray)(instance.meshInterface), meshParts))
     44 				return instance;
     45 		}
     46 		return null;
     47 	}
     48 
     49 	/** Obtain an instance of btBvhTriangleMeshShape, made up of the specified {@link MeshPart} instances.
     50 	 * Where possible previously obtained objects are reused. You must call {@link #release()},
     51 	 * when you no longer need the shape. */
     52 	public static <T extends MeshPart> btBvhTriangleMeshShape obtain(final Array<T> meshParts) {
     53 		btBvhTriangleMeshShape result = getInstance(meshParts);
     54 		if (result == null) {
     55 			result = new btBvhTriangleMeshShape(btTriangleIndexVertexArray.obtain(meshParts), true);
     56 			instances.add(result);
     57 		}
     58 		result.obtain();
     59 		return result;
     60 	}
     61 
     62 	private btStridingMeshInterface meshInterface = null;
     63 
     64 	/** @return The {@link btStridingMeshInterface} this shape encapsulates. */
     65 	public btStridingMeshInterface getMeshInterface() {
     66 		return meshInterface;
     67 	}
     68 
     69 	public <T extends MeshPart> btBvhTriangleMeshShape(final Array<T> meshParts) {
     70 		this(meshParts, true);
     71 	}
     72 
     73 	public <T extends MeshPart> btBvhTriangleMeshShape(final Array<T> meshParts, boolean useQuantizedAabbCompression) {
     74 		this(1, btTriangleIndexVertexArray.obtain(meshParts), useQuantizedAabbCompression);
     75 	}
     76 
     77 	public <T extends MeshPart> btBvhTriangleMeshShape(final Array<T> meshParts, boolean useQuantizedAabbCompression, boolean buildBvh) {
     78 		this(1, btTriangleIndexVertexArray.obtain(meshParts), useQuantizedAabbCompression, buildBvh);
     79 	}
     80 
     81 	public <T extends MeshPart> btBvhTriangleMeshShape(final Array<T> meshParts, boolean useQuantizedAabbCompression, Vector3 bvhAabbMin, Vector3 bvhAabbMax) {
     82 		this(1, btTriangleIndexVertexArray.obtain(meshParts), useQuantizedAabbCompression, bvhAabbMin, bvhAabbMax);
     83 	}
     84 
     85 	public <T extends MeshPart> btBvhTriangleMeshShape(final Array<T> meshParts, boolean useQuantizedAabbCompression, Vector3 bvhAabbMin, Vector3 bvhAabbMax, boolean buildBvh) {
     86 		this(1, btTriangleIndexVertexArray.obtain(meshParts), useQuantizedAabbCompression, bvhAabbMin, bvhAabbMax, buildBvh);
     87 	}
     88 
     89 	public btBvhTriangleMeshShape(btStridingMeshInterface meshInterface, boolean useQuantizedAabbCompression) {
     90 		this(0, meshInterface, useQuantizedAabbCompression);
     91 	}
     92 
     93 	public btBvhTriangleMeshShape(btStridingMeshInterface meshInterface, boolean useQuantizedAabbCompression, boolean buildBvh) {
     94 		this(0, meshInterface, useQuantizedAabbCompression, buildBvh);
     95 	}
     96 
     97 	public btBvhTriangleMeshShape(btStridingMeshInterface meshInterface, boolean useQuantizedAabbCompression, Vector3 bvhAabbMin, Vector3 bvhAabbMax, boolean buildBvh) {
     98 		this(0, meshInterface, useQuantizedAabbCompression, bvhAabbMin, bvhAabbMax, buildBvh);
     99 	}
    100 
    101 	public btBvhTriangleMeshShape(btStridingMeshInterface meshInterface, boolean useQuantizedAabbCompression, Vector3 bvhAabbMin, Vector3 bvhAabbMax) {
    102 		this(0, meshInterface, useQuantizedAabbCompression, bvhAabbMin, bvhAabbMax);
    103 	}
    104 
    105 	private btBvhTriangleMeshShape(int obtained, btStridingMeshInterface meshInterface, boolean useQuantizedAabbCompression) {
    106 		this(true, meshInterface, useQuantizedAabbCompression);
    107 		this.meshInterface = meshInterface;
    108 		if (obtained == 0)
    109 			meshInterface.obtain();
    110 	}
    111 
    112 	private btBvhTriangleMeshShape(int obtained, btStridingMeshInterface meshInterface, boolean useQuantizedAabbCompression, boolean buildBvh) {
    113 		this(true, meshInterface, useQuantizedAabbCompression, buildBvh);
    114 		this.meshInterface = meshInterface;
    115 		if (obtained == 0)
    116 			meshInterface.obtain();
    117 	}
    118 
    119 	private btBvhTriangleMeshShape(int obtained, btStridingMeshInterface meshInterface, boolean useQuantizedAabbCompression, Vector3 bvhAabbMin, Vector3 bvhAabbMax, boolean buildBvh) {
    120 		this(true, meshInterface, useQuantizedAabbCompression, bvhAabbMin, bvhAabbMax, buildBvh);
    121 		this.meshInterface = meshInterface;
    122 		if (obtained == 0)
    123 			meshInterface.obtain();
    124 	}
    125 
    126 	private btBvhTriangleMeshShape(int obtained, btStridingMeshInterface meshInterface, boolean useQuantizedAabbCompression, Vector3 bvhAabbMin, Vector3 bvhAabbMax) {
    127 		this(true, meshInterface, useQuantizedAabbCompression, bvhAabbMin, bvhAabbMax);
    128 		this.meshInterface = meshInterface;
    129 		if (obtained == 0)
    130 			meshInterface.obtain();
    131 	}
    132 
    133 
    134 	public void dispose() {
    135 		if (meshInterface != null)
    136 			meshInterface.release();
    137 		meshInterface = null;
    138 		super.dispose();
    139 	}
    140 %}
    141 
    142 %include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"