Skip to content

Commit

Permalink
IndexedMesh: generate meshes from collision shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Feb 9, 2024
1 parent 11993bb commit e4b53ab
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
package com.jme3.bullet.collision.shapes.infos;

import com.jme3.bullet.NativePhysicsObject;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.collision.shapes.CompoundCollisionShape;
import com.jme3.math.Plane;
import com.jme3.math.Triangle;
import com.jme3.math.Vector3f;
Expand Down Expand Up @@ -200,6 +202,36 @@ public IndexedMesh(FloatBuffer positionBuffer, IntBuffer indexBuffer) {

createMesh();
}

/**
* Instantiate a IndexedMesh to visualize the specified collision shape.
*
* @param shape shape to visualize (not null, not compound, unaffected)
* @param meshResolution (0=low, 1=high)
*/
public IndexedMesh(CollisionShape shape, int meshResolution) {
Validate.require(
!(shape == null || shape instanceof CompoundCollisionShape),
"a non-null value, not a compound shape");
Validate.inRange(meshResolution, "mesh resolution", 0, 1);

long shapeId = shape.nativeId();
long meshId = createIntDebug(shapeId, meshResolution);
setNativeId(meshId);
logger.log(Level.FINE, "Created {0}", this);

this.numVertices = countVertices(meshId);
int numFloats = numVertices * numAxes;
this.vertexPositions = BufferUtils.createFloatBuffer(numFloats);
this.vertexStride = numAxes * floatBytes;

this.numTriangles = countTriangles(meshId);
int numIndices = numTriangles * vpt;
this.indices = BufferUtils.createIntBuffer(numIndices);
this.indexStride = vpt * intBytes;

fillBuffersInt(meshId, vertexPositions, indices);
}
// *************************************************************************
// new methods exposed

Expand Down

0 comments on commit e4b53ab

Please sign in to comment.