Skip to content

Commit 3cec8cb

Browse files
committed
DebugShapeFactory: add a getDebugMesh(CollisionShape) method
1 parent 489c090 commit 3cec8cb

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

MinieLibrary/src/main/java/com/jme3/bullet/util/DebugShapeFactory.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.jme3.scene.Node;
4646
import com.jme3.scene.Spatial;
4747
import com.jme3.scene.VertexBuffer.Type;
48+
import java.nio.FloatBuffer;
4849
import java.util.HashMap;
4950
import java.util.Map;
5051
import java.util.logging.Logger;
@@ -121,6 +122,24 @@ public static Vector3f[] footprint(CollisionShape shape,
121122
return cornerLocations;
122123
}
123124

125+
/**
126+
* For compatibility with the jme3-bullet library.
127+
*
128+
* @param shape (not null, unaffected)
129+
* @return a new Mesh (not null)
130+
*/
131+
public static Mesh getDebugMesh(CollisionShape shape) {
132+
long shapeId = shape.getObjectId();
133+
DebugMeshCallback callback = new DebugMeshCallback();
134+
getVertices2(shapeId, lowResolution, callback);
135+
FloatBuffer floatBuffer = callback.getVertices();
136+
137+
Mesh result = new Mesh();
138+
result.setBuffer(Type.Position, 3, floatBuffer);
139+
140+
return result;
141+
}
142+
124143
/**
125144
* For compatibility with the jme3-bullet library.
126145
*
@@ -220,7 +239,7 @@ public static float volumeConvex(CollisionShape shape, int meshResolution) {
220239
* @param shape (not null, unaffected)
221240
* @param normals which normals to generate (not null)
222241
* @param resolution how much detail for convex shapes (0=low, 1=high)
223-
* @return a new geometry (not null)
242+
* @return a new Geometry (not null)
224243
*/
225244
private static Geometry createGeometry(CollisionShape shape,
226245
DebugMeshInitListener listener, DebugMeshNormals normals,
@@ -254,13 +273,13 @@ private static Geometry createGeometry(CollisionShape shape,
254273
* @param shape (not null, unaffected)
255274
* @param normals which normals to generate (not null)
256275
* @param resolution how much detail for convex shapes (0=low, 1=high)
257-
* @return a new mesh (not null)
276+
* @return a new Mesh (not null)
258277
*/
259278
private static Mesh createMesh(CollisionShape shape,
260279
DebugMeshNormals normals, int resolution) {
261-
long id = shape.getObjectId();
280+
long shapeId = shape.getObjectId();
262281
DebugMeshCallback callback = new DebugMeshCallback();
263-
getVertices2(id, resolution, callback);
282+
getVertices2(shapeId, resolution, callback);
264283

265284
Mesh mesh = new Mesh();
266285
mesh.setBuffer(Type.Position, 3, callback.getVertices());

0 commit comments

Comments
 (0)