/** * Create a box shape for the given Spatial. * * @param spatial the spatial on which to base the shape (not null) * @return a BoxCollisionShape (if spatial is a Geometry) or a * CompoundCollisionShape with BoxCollisionShapes as children (if spatial is * a Node) */ public static CollisionShape createBoxShape(Spatial spatial) { if (spatial instanceof Geometry) { return createSingleBoxShape((Geometry) spatial, spatial); } else if (spatial instanceof Node) { return createBoxCompoundShape((Node) spatial); } else { throw new IllegalArgumentException("Supplied spatial must either be Node or Geometry!"); } }
/** * Create a hull shape for the given Spatial. * <p> * For mesh-accurate animated meshes (CPU intense!) use GImpact shapes. * * @param spatial the spatial on which to base the shape (not null) * @return a HullCollisionShape (if spatial is a Geometry) or a * CompoundCollisionShape with HullCollisionShapes as children (if spatial * is a Node) */ public static CollisionShape createDynamicMeshShape(Spatial spatial) { if (spatial instanceof Geometry) { return createSingleDynamicMeshShape((Geometry) spatial, spatial); } else if (spatial instanceof Node) { return createCompoundShape((Node) spatial, (Node) spatial, new CompoundCollisionShape(), true, true); } else { throw new IllegalArgumentException("Supplied spatial must either be Node or Geometry!"); } }
return new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()); } else if (spatial instanceof Geometry) { return createSingleMeshShape((Geometry) spatial, spatial); } else if (spatial instanceof Node) { return createMeshCompoundShape((Node) spatial); } else { throw new IllegalArgumentException("Supplied spatial must either be Node or Geometry!");
Transform trans = getTransform(spatial, realRootNode); shape.addChildShape(new HeightfieldCollisionShape(terrain.getHeightMap(), trans.getScale()), trans.getTranslation(), trans.getRotation().toRotationMatrix()); } else if (spatial instanceof Node) { createCompoundShape(realRootNode, (Node) spatial, shape, meshAccurate, dynamic); } else if (spatial instanceof TerrainPatch) { Boolean bool = spatial.getUserData(UserData.JME_PHYSICSIGNORE); Transform trans = getTransform(spatial, realRootNode); shape.addChildShape(new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()), trans.getTranslation(), ? createSingleDynamicMeshShape((Geometry) spatial, realRootNode) : createSingleMeshShape((Geometry) spatial, realRootNode); if (childShape != null) { Transform trans = getTransform(spatial, realRootNode); shape.addChildShape(childShape, trans.getTranslation(), Transform trans = getTransform(spatial, realRootNode); shape.addChildShape(createSingleBoxShape(spatial, realRootNode), trans.getTranslation(), trans.getRotation().toRotationMatrix());
/** * Set the collision shape based on the controlled spatial and its * descendents. */ 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); } }
@Override public void simpleInitApp() { stateManager.attach(bulletAppState); initCrossHair(); Spatial s = assetManager.loadModel("Models/Elephant/Elephant.mesh.xml"); s.setLocalScale(0.1f); CollisionShape collisionShape = CollisionShapeFactory.createMeshShape(s); Node n = new Node("elephant"); n.addControl(new RigidBodyControl(collisionShape, 1)); n.getControl(RigidBodyControl.class).setKinematic(true); bulletAppState.getPhysicsSpace().add(n); rootNode.attachChild(n); bulletAppState.setDebugEnabled(true); }
private static CompoundCollisionShape createCompoundShape( Node rootNode, CompoundCollisionShape shape, boolean meshAccurate) { return createCompoundShape(rootNode, rootNode, shape, meshAccurate, false); }
/** * Create a hull collision shape for the specified geometry. * * @param geom the geometry on which to base the shape (not null) * @param parent */ 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; } }
player.setCollisionShape(CollisionShapeFactory.createDynamicMeshShape(findGeom(carNode, "Car"))); } else if (binding.equals("Downs")) { if (value) {
Transform trans = getTransform(spatial, realRootNode); shape.addChildShape(new HeightfieldCollisionShape(terrain.getHeightMap(), trans.getScale()), trans.getTranslation(), trans.getRotation().toRotationMatrix()); } else if (spatial instanceof Node) { createCompoundShape(realRootNode, (Node) spatial, shape, meshAccurate, dynamic); } else if (spatial instanceof TerrainPatch) { Boolean bool = spatial.getUserData(UserData.JME_PHYSICSIGNORE); Transform trans = getTransform(spatial, realRootNode); shape.addChildShape(new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()), trans.getTranslation(), ? createSingleDynamicMeshShape((Geometry) spatial, realRootNode) : createSingleMeshShape((Geometry) spatial, realRootNode); if (childShape != null) { Transform trans = getTransform(spatial, realRootNode); shape.addChildShape(childShape, trans.getTranslation(), Transform trans = getTransform(spatial, realRootNode); shape.addChildShape(createSingleBoxShape(spatial, realRootNode), trans.getTranslation(), trans.getRotation().toRotationMatrix());
/** * Set the collision shape based on the controlled spatial and its * descendents. */ 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); } }
terrain.setLocalScale(new Vector3f(2, 2, 2)); terrainPhysicsNode = new RigidBodyControl(CollisionShapeFactory.createMeshShape(terrain), 0); terrain.addControl(terrainPhysicsNode); rootNode.attachChild(terrain);
private static CompoundCollisionShape createCompoundShape( Node rootNode, CompoundCollisionShape shape, boolean meshAccurate) { return createCompoundShape(rootNode, rootNode, shape, meshAccurate, false); }
/** * Create a hull collision shape for the specified geometry. * * @param geom the geometry on which to base the shape (not null) * @param parent */ 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; } }
private void buildPlayer() { spaceCraft = assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml"); CollisionShape colShape = CollisionShapeFactory.createDynamicMeshShape(spaceCraft); spaceCraft.setShadowMode(ShadowMode.CastAndReceive); spaceCraft.setLocalTranslation(new Vector3f(-140, 50, -23)); spaceCraft.setLocalRotation(new Quaternion(new float[]{0, 0.01f, 0})); hoverControl = new PhysicsHoverControl(colShape, 500); spaceCraft.addControl(hoverControl); rootNode.attachChild(spaceCraft); getPhysicsSpace().add(hoverControl); hoverControl.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02); ChaseCamera chaseCam = new ChaseCamera(cam, inputManager); spaceCraft.addControl(chaseCam); flyCam.setEnabled(false); }
Transform trans = getTransform(spatial, realRootNode); shape.addChildShape(new HeightfieldCollisionShape(terrain.getHeightMap(), trans.getScale()), trans.getTranslation(), trans.getRotation().toRotationMatrix()); } else if (spatial instanceof Node) { createCompoundShape(realRootNode, (Node) spatial, shape, meshAccurate, dynamic); } else if (spatial instanceof TerrainPatch) { Boolean bool = spatial.getUserData(UserData.JME_PHYSICSIGNORE); Transform trans = getTransform(spatial, realRootNode); shape.addChildShape(new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()), trans.getTranslation(), ? createSingleDynamicMeshShape((Geometry) spatial, realRootNode) : createSingleMeshShape((Geometry) spatial, realRootNode); if (childShape != null) { Transform trans = getTransform(spatial, realRootNode); shape.addChildShape(childShape, trans.getTranslation(), Transform trans = getTransform(spatial, realRootNode); shape.addChildShape(createSingleBoxShape(spatial, realRootNode), trans.getTranslation(), trans.getRotation().toRotationMatrix());
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); } }
/** * Create a box shape for the given Spatial. * * @param spatial the spatial on which to base the shape (not null) * @return a BoxCollisionShape (if spatial is a Geometry) or a * CompoundCollisionShape with BoxCollisionShapes as children (if spatial is * a Node) */ public static CollisionShape createBoxShape(Spatial spatial) { if (spatial instanceof Geometry) { return createSingleBoxShape((Geometry) spatial, spatial); } else if (spatial instanceof Node) { return createBoxCompoundShape((Node) spatial); } else { throw new IllegalArgumentException("Supplied spatial must either be Node or Geometry!"); } }
/** * Create a hull shape for the given Spatial. * <p> * For mesh-accurate animated meshes (CPU intense!) use GImpact shapes. * * @param spatial the spatial on which to base the shape (not null) * @return a HullCollisionShape (if spatial is a Geometry) or a * CompoundCollisionShape with HullCollisionShapes as children (if spatial * is a Node) */ public static CollisionShape createDynamicMeshShape(Spatial spatial) { if (spatial instanceof Geometry) { return createSingleDynamicMeshShape((Geometry) spatial, spatial); } else if (spatial instanceof Node) { return createCompoundShape((Node) spatial, (Node) spatial, new CompoundCollisionShape(), true, true); } else { throw new IllegalArgumentException("Supplied spatial must either be Node or Geometry!"); } }
return new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()); } else if (spatial instanceof Geometry) { return createSingleMeshShape((Geometry) spatial, spatial); } else if (spatial instanceof Node) { return createMeshCompoundShape((Node) spatial); } else { throw new IllegalArgumentException("Supplied spatial must either be Node or Geometry!");