use of com.jme3.bullet.collision.shapes.MeshCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class PhysicsTestHelper method createPhysicsTestWorld.
/**
* creates a simple physics test world with a floor, an obstacle and some test boxes
* @param rootNode
* @param assetManager
* @param space
*/
public static void createPhysicsTestWorld(Node rootNode, AssetManager assetManager, PhysicsSpace space) {
AmbientLight light = new AmbientLight();
light.setColor(ColorRGBA.LightGray);
rootNode.addLight(light);
Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
material.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
Box floorBox = new Box(140, 0.25f, 140);
Geometry floorGeometry = new Geometry("Floor", floorBox);
floorGeometry.setMaterial(material);
floorGeometry.setLocalTranslation(0, -5, 0);
// Plane plane = new Plane();
// plane.setOriginNormal(new Vector3f(0, 0.25f, 0), Vector3f.UNIT_Y);
// floorGeometry.addControl(new RigidBodyControl(new PlaneCollisionShape(plane), 0));
floorGeometry.addControl(new RigidBodyControl(0));
rootNode.attachChild(floorGeometry);
space.add(floorGeometry);
//movable boxes
for (int i = 0; i < 12; i++) {
Box box = new Box(0.25f, 0.25f, 0.25f);
Geometry boxGeometry = new Geometry("Box", box);
boxGeometry.setMaterial(material);
boxGeometry.setLocalTranslation(i, 5, -3);
//RigidBodyControl automatically uses box collision shapes when attached to single geometry with box mesh
boxGeometry.addControl(new RigidBodyControl(2));
rootNode.attachChild(boxGeometry);
space.add(boxGeometry);
}
//immovable sphere with mesh collision shape
Sphere sphere = new Sphere(8, 8, 1);
Geometry sphereGeometry = new Geometry("Sphere", sphere);
sphereGeometry.setMaterial(material);
sphereGeometry.setLocalTranslation(4, -4, 2);
sphereGeometry.addControl(new RigidBodyControl(new MeshCollisionShape(sphere), 0));
rootNode.attachChild(sphereGeometry);
space.add(sphereGeometry);
}
use of com.jme3.bullet.collision.shapes.MeshCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class TestAttachDriver method setupFloor.
public void setupFloor() {
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true);
key.setGenerateMips(true);
Texture tex = assetManager.loadTexture(key);
tex.setMinFilter(Texture.MinFilter.Trilinear);
mat.setTexture("ColorMap", tex);
Box floor = new Box(100, 1f, 100);
Geometry floorGeom = new Geometry("Floor", floor);
floorGeom.setMaterial(mat);
floorGeom.setLocalTranslation(new Vector3f(0f, -3, 0f));
floorGeom.addControl(new RigidBodyControl(new MeshCollisionShape(floorGeom.getMesh()), 0));
rootNode.attachChild(floorGeom);
getPhysicsSpace().add(floorGeom);
}
use of com.jme3.bullet.collision.shapes.MeshCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class TestCcd method simpleInitApp.
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
bullet = new Sphere(32, 32, 0.4f, true, false);
bullet.setTextureMode(TextureMode.Projected);
bulletCollisionShape = new SphereCollisionShape(0.1f);
setupKeys();
mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
mat.getAdditionalRenderState().setWireframe(true);
mat.setColor("Color", ColorRGBA.Green);
mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
mat2.getAdditionalRenderState().setWireframe(true);
mat2.setColor("Color", ColorRGBA.Red);
// An obstacle mesh, does not move (mass=0)
Node node2 = new Node();
node2.setName("mesh");
node2.setLocalTranslation(new Vector3f(2.5f, 0, 0f));
node2.addControl(new RigidBodyControl(new MeshCollisionShape(new Box(4, 4, 0.1f)), 0));
rootNode.attachChild(node2);
getPhysicsSpace().add(node2);
// The floor, does not move (mass=0)
Node node3 = new Node();
node3.setLocalTranslation(new Vector3f(0f, -6, 0f));
node3.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(100, 1, 100)), 0));
rootNode.attachChild(node3);
getPhysicsSpace().add(node3);
}
use of com.jme3.bullet.collision.shapes.MeshCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class TestKinematicAddToPhysicsSpaceIssue method simpleInitApp.
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
// Add a physics sphere to the world
Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
rootNode.attachChild(physicsSphere);
//Setting the rigidBody to kinematic before adding it to the physic space
physicsSphere.getControl(RigidBodyControl.class).setKinematic(true);
//adding it to the physic space
getPhysicsSpace().add(physicsSphere);
//Making it not kinematic again, it should fall under gravity, it doesn't
physicsSphere.getControl(RigidBodyControl.class).setKinematic(false);
// Add a physics sphere to the world using the collision shape from sphere one
Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(5, 6, 0));
rootNode.attachChild(physicsSphere2);
//Adding the rigid body to physic space
getPhysicsSpace().add(physicsSphere2);
//making it kinematic
physicsSphere2.getControl(RigidBodyControl.class).setKinematic(false);
//Making it not kinematic again, it works properly, the rigidbody is affected by grvity.
physicsSphere2.getControl(RigidBodyControl.class).setKinematic(false);
// an obstacle mesh, does not move (mass=0)
Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);
node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f));
rootNode.attachChild(node2);
getPhysicsSpace().add(node2);
// the floor mesh, does not move (mass=0)
Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new PlaneCollisionShape(new Plane(new Vector3f(0, 1, 0), 0)), 0);
node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
rootNode.attachChild(node3);
getPhysicsSpace().add(node3);
}
use of com.jme3.bullet.collision.shapes.MeshCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class TestLocalPhysics method simpleInitApp.
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
// Add a physics sphere to the world
Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
physicsSphere.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
rootNode.attachChild(physicsSphere);
getPhysicsSpace().add(physicsSphere);
// Add a physics sphere to the world using the collision shape from sphere one
Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, physicsSphere.getControl(RigidBodyControl.class).getCollisionShape(), 1);
physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0));
physicsSphere2.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
rootNode.attachChild(physicsSphere2);
getPhysicsSpace().add(physicsSphere2);
// Add a physics box to the world
Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1);
physicsBox.getControl(RigidBodyControl.class).setFriction(0.1f);
physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f));
physicsBox.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
rootNode.attachChild(physicsBox);
getPhysicsSpace().add(physicsBox);
// Add a physics cylinder to the world
Node physicsCylinder = PhysicsTestHelper.createPhysicsTestNode(assetManager, new CylinderCollisionShape(new Vector3f(1f, 1f, 1.5f)), 1);
physicsCylinder.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2, 2, 0));
physicsCylinder.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
rootNode.attachChild(physicsCylinder);
getPhysicsSpace().add(physicsCylinder);
// an obstacle mesh, does not move (mass=0)
Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);
node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f));
node2.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
rootNode.attachChild(node2);
getPhysicsSpace().add(node2);
// the floor mesh, does not move (mass=0)
Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new PlaneCollisionShape(new Plane(new Vector3f(0, 1, 0), 0)), 0);
node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
node3.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
rootNode.attachChild(node3);
getPhysicsSpace().add(node3);
// Join the physics objects with a Point2Point joint
// PhysicsPoint2PointJoint joint=new PhysicsPoint2PointJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0));
// PhysicsHingeJoint joint=new PhysicsHingeJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0), Vector3f.UNIT_Z,Vector3f.UNIT_Z);
// getPhysicsSpace().add(joint);
}
Aggregations