use of com.jme3.bullet.collision.shapes.MeshCollisionShape 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.bullet.collision.shapes.MeshCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class TestQ3 method simpleInitApp.
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
flyCam.setMoveSpeed(100);
setupKeys();
this.cam.setFrustumFar(2000);
DirectionalLight dl = new DirectionalLight();
dl.setColor(ColorRGBA.White.clone().multLocal(2));
dl.setDirection(new Vector3f(-1, -1, -1).normalize());
rootNode.addLight(dl);
AmbientLight am = new AmbientLight();
am.setColor(ColorRGBA.White.mult(2));
rootNode.addLight(am);
// load the level from zip or http zip
if (useHttp) {
assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/quake3level.zip", HttpZipLocator.class);
} else {
assetManager.registerLocator("quake3level.zip", ZipLocator.class);
}
// create the geometry and attach it
MaterialList matList = (MaterialList) assetManager.loadAsset("Scene.material");
OgreMeshKey key = new OgreMeshKey("main.meshxml", matList);
gameLevel = (Node) assetManager.loadAsset(key);
gameLevel.setLocalScale(0.1f);
// add a physics control, it will generate a MeshCollisionShape based on the gameLevel
gameLevel.addControl(new RigidBodyControl(0));
player = new PhysicsCharacter(new SphereCollisionShape(5), .01f);
player.setJumpSpeed(20);
player.setFallSpeed(30);
player.setGravity(30);
player.setPhysicsLocation(new Vector3f(60, 10, -60));
rootNode.attachChild(gameLevel);
getPhysicsSpace().addAll(gameLevel);
getPhysicsSpace().add(player);
}
use of com.jme3.bullet.collision.shapes.MeshCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class TestBetterCharacter method setupPlanet.
private void setupPlanet() {
Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
material.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
//immovable sphere with mesh collision shape
Sphere sphere = new Sphere(64, 64, 20);
planet = new Geometry("Sphere", sphere);
planet.setMaterial(material);
planet.setLocalTranslation(30, -15, 30);
planet.addControl(new RigidBodyControl(new MeshCollisionShape(sphere), 0));
rootNode.attachChild(planet);
getPhysicsSpace().add(planet);
}
use of com.jme3.bullet.collision.shapes.MeshCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class TestFancyCar method findGeom.
// public void setupFloor() {
// Material mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m");
// mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat);
//// mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat);
//// mat.getTextureParam("ParallaxMap").getTextureValue().setWrap(WrapMode.Repeat);
//
// Box floor = new Box(Vector3f.ZERO, 140, 1f, 140);
// floor.scaleTextureCoordinates(new Vector2f(112.0f, 112.0f));
// Geometry floorGeom = new Geometry("Floor", floor);
// floorGeom.setShadowMode(ShadowMode.Receive);
// floorGeom.setMaterial(mat);
//
// PhysicsNode tb = new PhysicsNode(floorGeom, new MeshCollisionShape(floorGeom.getMesh()), 0);
// tb.setLocalTranslation(new Vector3f(0f, -6, 0f));
//// tb.attachDebugShape(assetManager);
// rootNode.attachChild(tb);
// getPhysicsSpace().add(tb);
// }
private Geometry findGeom(Spatial spatial, String name) {
if (spatial instanceof Node) {
Node node = (Node) spatial;
for (int i = 0; i < node.getQuantity(); i++) {
Spatial child = node.getChild(i);
Geometry result = findGeom(child, name);
if (result != null) {
return result;
}
}
} else if (spatial instanceof Geometry) {
if (spatial.getName().startsWith(name)) {
return (Geometry) spatial;
}
}
return null;
}
use of com.jme3.bullet.collision.shapes.MeshCollisionShape in project jmonkeyengine by jMonkeyEngine.
the class PhysicsTestHelper method createPhysicsTestWorldSoccer.
public static void createPhysicsTestWorldSoccer(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(20, 0.25f, 20);
Geometry floorGeometry = new Geometry("Floor", floorBox);
floorGeometry.setMaterial(material);
floorGeometry.setLocalTranslation(0, -0.25f, 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 spheres
for (int i = 0; i < 5; i++) {
Sphere sphere = new Sphere(16, 16, .5f);
Geometry ballGeometry = new Geometry("Soccer ball", sphere);
ballGeometry.setMaterial(material);
ballGeometry.setLocalTranslation(i, 2, -3);
//RigidBodyControl automatically uses Sphere collision shapes when attached to single geometry with sphere mesh
ballGeometry.addControl(new RigidBodyControl(.001f));
ballGeometry.getControl(RigidBodyControl.class).setRestitution(1);
rootNode.attachChild(ballGeometry);
space.add(ballGeometry);
}
{
//immovable Box with mesh collision shape
Box box = new Box(1, 1, 1);
Geometry boxGeometry = new Geometry("Box", box);
boxGeometry.setMaterial(material);
boxGeometry.setLocalTranslation(4, 1, 2);
boxGeometry.addControl(new RigidBodyControl(new MeshCollisionShape(box), 0));
rootNode.attachChild(boxGeometry);
space.add(boxGeometry);
}
{
//immovable Box with mesh collision shape
Box box = new Box(1, 1, 1);
Geometry boxGeometry = new Geometry("Box", box);
boxGeometry.setMaterial(material);
boxGeometry.setLocalTranslation(4, 3, 4);
boxGeometry.addControl(new RigidBodyControl(new MeshCollisionShape(box), 0));
rootNode.attachChild(boxGeometry);
space.add(boxGeometry);
}
}
Aggregations