use of com.jme3.bullet.collision.shapes.infos.ChildCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class BufferedTriangleCallback method getDebugShape.
/**
* Creates a debug shape from the given collision shape. This is mostly used internally.<br>
* To attach a debug shape to a physics object, call <code>attachDebugShape(AssetManager manager);</code> on it.
* @param collisionShape
* @return
*/
public static Spatial getDebugShape(CollisionShape collisionShape) {
if (collisionShape == null) {
return null;
}
Spatial debugShape;
if (collisionShape instanceof CompoundCollisionShape) {
CompoundCollisionShape shape = (CompoundCollisionShape) collisionShape;
List<ChildCollisionShape> children = shape.getChildren();
Node node = new Node("DebugShapeNode");
for (Iterator<ChildCollisionShape> it = children.iterator(); it.hasNext(); ) {
ChildCollisionShape childCollisionShape = it.next();
CollisionShape ccollisionShape = childCollisionShape.shape;
Geometry geometry = createDebugShape(ccollisionShape);
// apply translation
geometry.setLocalTranslation(childCollisionShape.location);
// apply rotation
TempVars vars = TempVars.get();
Matrix3f tempRot = vars.tempMat3;
tempRot.set(geometry.getLocalRotation());
childCollisionShape.rotation.mult(tempRot, tempRot);
geometry.setLocalRotation(tempRot);
vars.release();
node.attachChild(geometry);
}
debugShape = node;
} else {
debugShape = createDebugShape(collisionShape);
}
if (debugShape == null) {
return null;
}
debugShape.updateGeometricState();
return debugShape;
}
use of com.jme3.bullet.collision.shapes.infos.ChildCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class CompoundCollisionShape method addChildShape.
/**
* adds a child shape at the given local translation
* @param shape the child shape to add
* @param location the local location of the child shape
*/
public void addChildShape(CollisionShape shape, Vector3f location) {
Transform transA = new Transform(Converter.convert(new Matrix3f()));
Converter.convert(location, transA.origin);
children.add(new ChildCollisionShape(location.clone(), new Matrix3f(), shape));
((CompoundShape) cShape).addChildShape(transA, shape.getCShape());
}
use of com.jme3.bullet.collision.shapes.infos.ChildCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class CompoundCollisionShape method read.
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule capsule = im.getCapsule(this);
children = capsule.readSavableArrayList("children", new ArrayList<ChildCollisionShape>());
cShape.setLocalScaling(Converter.convert(getScale()));
cShape.setMargin(margin);
loadChildren();
}
use of com.jme3.bullet.collision.shapes.infos.ChildCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class CompoundCollisionShape method loadChildren.
private void loadChildren() {
for (Iterator<ChildCollisionShape> it = children.iterator(); it.hasNext(); ) {
ChildCollisionShape child = it.next();
addChildShapeDirect(child.shape, child.location, child.rotation);
}
}
use of com.jme3.bullet.collision.shapes.infos.ChildCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class CompoundCollisionShape method addChildShape.
/**
* adds a child shape at the given local translation
* @param shape the child shape to add
* @param location the local location of the child shape
*/
public void addChildShape(CollisionShape shape, Vector3f location, Matrix3f rotation) {
if (shape instanceof CompoundCollisionShape) {
throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!");
}
Transform transA = new Transform(Converter.convert(rotation));
Converter.convert(location, transA.origin);
Converter.convert(rotation, transA.basis);
children.add(new ChildCollisionShape(location.clone(), rotation.clone(), shape));
((CompoundShape) cShape).addChildShape(transA, shape.getCShape());
}
Aggregations