use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.
the class RigidBodyControl method createCollisionShape.
protected void createCollisionShape() {
if (spatial == null) {
return;
}
if (spatial instanceof Geometry) {
Geometry geom = (Geometry) spatial;
Mesh mesh = geom.getMesh();
if (mesh instanceof Sphere) {
collisionShape = new SphereCollisionShape(((Sphere) mesh).getRadius());
return;
} else if (mesh instanceof Box) {
collisionShape = new BoxCollisionShape(new Vector3f(((Box) mesh).getXExtent(), ((Box) mesh).getYExtent(), ((Box) mesh).getZExtent()));
return;
}
}
if (mass > 0) {
collisionShape = CollisionShapeFactory.createDynamicMeshShape(spatial);
} else {
collisionShape = CollisionShapeFactory.createMeshShape(spatial);
}
}
use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.
the class RagdollUtils method buildPointMap.
public static Map<Integer, List<Float>> buildPointMap(Spatial model) {
Map<Integer, List<Float>> map = new HashMap<Integer, List<Float>>();
if (model instanceof Geometry) {
Geometry g = (Geometry) model;
buildPointMapForMesh(g.getMesh(), map);
} else if (model instanceof Node) {
Node node = (Node) model;
for (Spatial s : node.getChildren()) {
if (s instanceof Geometry) {
Geometry g = (Geometry) s;
buildPointMapForMesh(g.getMesh(), map);
}
}
}
return map;
}
use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.
the class BulletVehicleDebugControl method createVehicle.
private void createVehicle() {
suspensionNode.detachAllChildren();
for (int i = 0; i < body.getNumWheels(); i++) {
VehicleWheel physicsVehicleWheel = body.getWheel(i);
Vector3f location = physicsVehicleWheel.getLocation().clone();
Vector3f direction = physicsVehicleWheel.getDirection().clone();
Vector3f axle = physicsVehicleWheel.getAxle().clone();
float restLength = physicsVehicleWheel.getRestLength();
float radius = physicsVehicleWheel.getRadius();
Arrow locArrow = new Arrow(location);
Arrow axleArrow = new Arrow(axle.normalizeLocal().multLocal(0.3f));
Arrow wheelArrow = new Arrow(direction.normalizeLocal().multLocal(radius));
Arrow dirArrow = new Arrow(direction.normalizeLocal().multLocal(restLength));
Geometry locGeom = new Geometry("WheelLocationDebugShape" + i, locArrow);
Geometry dirGeom = new Geometry("WheelDirectionDebugShape" + i, dirArrow);
Geometry axleGeom = new Geometry("WheelAxleDebugShape" + i, axleArrow);
Geometry wheelGeom = new Geometry("WheelRadiusDebugShape" + i, wheelArrow);
dirGeom.setLocalTranslation(location);
axleGeom.setLocalTranslation(location.add(direction));
wheelGeom.setLocalTranslation(location.add(direction));
locGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
dirGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
axleGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
wheelGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
suspensionNode.attachChild(locGeom);
suspensionNode.attachChild(dirGeom);
suspensionNode.attachChild(axleGeom);
suspensionNode.attachChild(wheelGeom);
}
}
use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.
the class CollisionShapeFactory method createSingleMeshShape.
/**
* This type of collision shape is mesh-accurate and meant for immovable "world objects".
* Examples include terrain, houses or whole shooter levels.<br>
* Objects with "mesh" type collision shape will not collide with each other.
*/
private static MeshCollisionShape createSingleMeshShape(Geometry geom, Spatial parent) {
Mesh mesh = geom.getMesh();
Transform trans = getTransform(geom, parent);
if (mesh != null && mesh.getMode() == Mesh.Mode.Triangles) {
MeshCollisionShape mColl = new MeshCollisionShape(mesh);
mColl.setScale(trans.getScale());
return mColl;
} else {
return null;
}
}
use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.
the class CollisionShapeFactory method createSingleDynamicMeshShape.
/**
* This method creates a hull collision shape for the given mesh.<br>
*/
private static HullCollisionShape createSingleDynamicMeshShape(Geometry geom, Spatial parent) {
Mesh mesh = geom.getMesh();
Transform trans = getTransform(geom, parent);
if (mesh != null) {
HullCollisionShape dynamicShape = new HullCollisionShape(mesh);
dynamicShape.setScale(trans.getScale());
return dynamicShape;
} else {
return null;
}
}
Aggregations