com.jme3.bullet.collision.shapes.CompoundCollisionShape Java Examples
The following examples show how to use
com.jme3.bullet.collision.shapes.CompoundCollisionShape.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ComputedCollisionShapeTreeNode.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
@Override @FxThread public @NotNull Array<TreeNode<?>> getChildren(@NotNull final NodeTree<?> nodeTree) { final CompoundCollisionShape element = getElement(); final List<ChildCollisionShape> children = element.getChildren(); final Array<TreeNode<?>> result = ArrayFactory.newArray(TreeNode.class); children.forEach(childCollisionShape -> result.add(FACTORY_REGISTRY.createFor(childCollisionShape))); return result; }
Example #2
Source File: CollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * This method moves each child shape of a compound shape by the given vector * @param vector */ public static void shiftCompoundShapeContents(CompoundCollisionShape compoundShape, Vector3f vector) { for (Iterator<ChildCollisionShape> it = new LinkedList(compoundShape.getChildren()).iterator(); it.hasNext();) { ChildCollisionShape childCollisionShape = it.next(); CollisionShape child = childCollisionShape.shape; Vector3f location = childCollisionShape.location; Matrix3f rotation = childCollisionShape.rotation; compoundShape.removeChildShape(child); compoundShape.addChildShape(child, location.add(vector), rotation); } }
Example #3
Source File: DebugShapeFactory.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create a debug spatial from the specified collision shape. * <p> * This is mostly used internally. To attach a debug shape to a physics * object, call <code>attachDebugShape(AssetManager manager);</code> on it. * * @param collisionShape the shape to visualize (may be null, unaffected) * @return a new tree of geometries, or null */ 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; }
Example #4
Source File: BetterCharacterControl.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create a collision shape based on the scale parameter. The new shape is a * compound shape containing an offset capsule. * * @return a new compound shape (not null) */ protected CollisionShape getShape() { //TODO: cleanup size mess.. CapsuleCollisionShape capsuleCollisionShape = new CapsuleCollisionShape(getFinalRadius(), (getFinalHeight() - (2 * getFinalRadius()))); CompoundCollisionShape compoundCollisionShape = new CompoundCollisionShape(); Vector3f addLocation = new Vector3f(0, (getFinalHeight() / 2.0f), 0); compoundCollisionShape.addChildShape(capsuleCollisionShape, addLocation); return compoundCollisionShape; }
Example #5
Source File: CollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * This method creates a hull shape for the given Spatial.<br> * If you want to have mesh-accurate dynamic shapes (CPU intense!!!) use GImpact shapes, its probably best to do so with a low-poly version of your model. * @return A HullCollisionShape or a CompoundCollisionShape with HullCollisionShapes as children if the supplied 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!"); } }
Example #6
Source File: CollisionTester.java From OpenRTS with MIT License | 5 votes |
private static CompoundCollisionShape getCollisionShape(Asset asset){ Spatial s = models.get(asset.modelPath); // if(!shapes.containsKey(asset.modelPath)){ CompoundCollisionShape res = new CompoundCollisionShape(); if(s instanceof Node){ for(Spatial child : ((Node)s).getChildren()) if(child instanceof Geometry){ HullCollisionShape hull = new HullCollisionShape(((Geometry)child).getMesh()); float scale = (float)asset.scale; Vector3f vScale = new Vector3f(scale, scale, scale) ; hull.setScale(vScale); res.addChildShape(hull, Vector3f.ZERO); } } else { logger.info("houston on a un probleme"); } shapes.put(asset.modelPath, res); // } // CompoundCollisionShape res = shapes.get(asset.modelPath); // float scale = (float)asset.scale; // Vector3f vScale = new Vector3f(scale, scale, scale) ; // for(ChildCollisionShape hull : res.getChildren()) // hull.shape.setScale(vScale); return res; }
Example #7
Source File: DebugShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * 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; }
Example #8
Source File: CollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * This method moves each child shape of a compound shape by the given vector * @param vector */ public static void shiftCompoundShapeContents(CompoundCollisionShape compoundShape, Vector3f vector) { for (Iterator<ChildCollisionShape> it = new LinkedList(compoundShape.getChildren()).iterator(); it.hasNext();) { ChildCollisionShape childCollisionShape = it.next(); CollisionShape child = childCollisionShape.shape; Vector3f location = childCollisionShape.location; Matrix3f rotation = childCollisionShape.rotation; compoundShape.removeChildShape(child); compoundShape.addChildShape(child, location.add(vector), rotation); } }
Example #9
Source File: CollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * This method creates a hull shape for the given Spatial.<br> * If you want to have mesh-accurate dynamic shapes (CPU intense!!!) use GImpact shapes, its probably best to do so with a low-poly version of your model. * @return A HullCollisionShape or a CompoundCollisionShape with HullCollisionShapes as children if the supplied 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!"); } }
Example #10
Source File: TestPhysicsCar.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
private void buildPlayer() { Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); mat.getAdditionalRenderState().setWireframe(true); mat.setColor("Color", ColorRGBA.Red); //create a compound shape and attach the BoxCollisionShape for the car body at 0,1,0 //this shifts the effective center of mass of the BoxCollisionShape to 0,-1,0 CompoundCollisionShape compoundShape = new CompoundCollisionShape(); BoxCollisionShape box = new BoxCollisionShape(new Vector3f(1.2f, 0.5f, 2.4f)); compoundShape.addChildShape(box, new Vector3f(0, 1, 0)); //create vehicle node Node vehicleNode=new Node("vehicleNode"); vehicle = new VehicleControl(compoundShape, 400); vehicleNode.addControl(vehicle); //setting suspension values for wheels, this can be a bit tricky //see also https://docs.google.com/Doc?docid=0AXVUZ5xw6XpKZGNuZG56a3FfMzU0Z2NyZnF4Zmo&hl=en float stiffness = 60.0f;//200=f1 car float compValue = .3f; //(should be lower than damp) float dampValue = .4f; vehicle.setSuspensionCompression(compValue * 2.0f * FastMath.sqrt(stiffness)); vehicle.setSuspensionDamping(dampValue * 2.0f * FastMath.sqrt(stiffness)); vehicle.setSuspensionStiffness(stiffness); vehicle.setMaxSuspensionForce(10000.0f); //Create four wheels and add them at their locations Vector3f wheelDirection = new Vector3f(0, -1, 0); // was 0, -1, 0 Vector3f wheelAxle = new Vector3f(-1, 0, 0); // was -1, 0, 0 float radius = 0.5f; float restLength = 0.3f; float yOff = 0.5f; float xOff = 1f; float zOff = 2f; Cylinder wheelMesh = new Cylinder(16, 16, radius, radius * 0.6f, true); Node node1 = new Node("wheel 1 node"); Geometry wheels1 = new Geometry("wheel 1", wheelMesh); node1.attachChild(wheels1); wheels1.rotate(0, FastMath.HALF_PI, 0); wheels1.setMaterial(mat); vehicle.addWheel(node1, new Vector3f(-xOff, yOff, zOff), wheelDirection, wheelAxle, restLength, radius, true); Node node2 = new Node("wheel 2 node"); Geometry wheels2 = new Geometry("wheel 2", wheelMesh); node2.attachChild(wheels2); wheels2.rotate(0, FastMath.HALF_PI, 0); wheels2.setMaterial(mat); vehicle.addWheel(node2, new Vector3f(xOff, yOff, zOff), wheelDirection, wheelAxle, restLength, radius, true); Node node3 = new Node("wheel 3 node"); Geometry wheels3 = new Geometry("wheel 3", wheelMesh); node3.attachChild(wheels3); wheels3.rotate(0, FastMath.HALF_PI, 0); wheels3.setMaterial(mat); vehicle.addWheel(node3, new Vector3f(-xOff, yOff, -zOff), wheelDirection, wheelAxle, restLength, radius, false); Node node4 = new Node("wheel 4 node"); Geometry wheels4 = new Geometry("wheel 4", wheelMesh); node4.attachChild(wheels4); wheels4.rotate(0, FastMath.HALF_PI, 0); wheels4.setMaterial(mat); vehicle.addWheel(node4, new Vector3f(xOff, yOff, -zOff), wheelDirection, wheelAxle, restLength, radius, false); vehicleNode.attachChild(node1); vehicleNode.attachChild(node2); vehicleNode.attachChild(node3); vehicleNode.attachChild(node4); rootNode.attachChild(vehicleNode); getPhysicsSpace().add(vehicle); }
Example #11
Source File: ComputedCollisionShapeTreeNode.java From jmonkeybuilder with Apache License 2.0 | 4 votes |
public ComputedCollisionShapeTreeNode(@NotNull final CompoundCollisionShape element, final long objectId) { super(element, objectId); }
Example #12
Source File: CollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
private static CompoundCollisionShape createCompoundShape( Node rootNode, CompoundCollisionShape shape, boolean meshAccurate) { return createCompoundShape(rootNode, rootNode, shape, meshAccurate, false); }
Example #13
Source File: DebugShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * 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; }
Example #14
Source File: CollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
private static CompoundCollisionShape createCompoundShape( Node rootNode, CompoundCollisionShape shape, boolean meshAccurate) { return createCompoundShape(rootNode, rootNode, shape, meshAccurate, false); }
Example #15
Source File: DebugShapeFactory.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * 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 a new Spatial or null */ 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; }
Example #16
Source File: TestPhysicsCar.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void buildPlayer() { Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); mat.getAdditionalRenderState().setWireframe(true); mat.setColor("Color", ColorRGBA.Red); //create a compound shape and attach the BoxCollisionShape for the car body at 0,1,0 //this shifts the effective center of mass of the BoxCollisionShape to 0,-1,0 CompoundCollisionShape compoundShape = new CompoundCollisionShape(); BoxCollisionShape box = new BoxCollisionShape(new Vector3f(1.2f, 0.5f, 2.4f)); compoundShape.addChildShape(box, new Vector3f(0, 1, 0)); //create vehicle node Node vehicleNode=new Node("vehicleNode"); vehicle = new VehicleControl(compoundShape, 400); vehicleNode.addControl(vehicle); //setting suspension values for wheels, this can be a bit tricky //see also https://docs.google.com/Doc?docid=0AXVUZ5xw6XpKZGNuZG56a3FfMzU0Z2NyZnF4Zmo&hl=en float stiffness = 60.0f;//200=f1 car float compValue = .3f; //(should be lower than damp) float dampValue = .4f; vehicle.setSuspensionCompression(compValue * 2.0f * FastMath.sqrt(stiffness)); vehicle.setSuspensionDamping(dampValue * 2.0f * FastMath.sqrt(stiffness)); vehicle.setSuspensionStiffness(stiffness); vehicle.setMaxSuspensionForce(10000.0f); //Create four wheels and add them at their locations Vector3f wheelDirection = new Vector3f(0, -1, 0); // was 0, -1, 0 Vector3f wheelAxle = new Vector3f(-1, 0, 0); // was -1, 0, 0 float radius = 0.5f; float restLength = 0.3f; float yOff = 0.5f; float xOff = 1f; float zOff = 2f; Cylinder wheelMesh = new Cylinder(16, 16, radius, radius * 0.6f, true); Node node1 = new Node("wheel 1 node"); Geometry wheels1 = new Geometry("wheel 1", wheelMesh); node1.attachChild(wheels1); wheels1.rotate(0, FastMath.HALF_PI, 0); wheels1.setMaterial(mat); vehicle.addWheel(node1, new Vector3f(-xOff, yOff, zOff), wheelDirection, wheelAxle, restLength, radius, true); Node node2 = new Node("wheel 2 node"); Geometry wheels2 = new Geometry("wheel 2", wheelMesh); node2.attachChild(wheels2); wheels2.rotate(0, FastMath.HALF_PI, 0); wheels2.setMaterial(mat); vehicle.addWheel(node2, new Vector3f(xOff, yOff, zOff), wheelDirection, wheelAxle, restLength, radius, true); Node node3 = new Node("wheel 3 node"); Geometry wheels3 = new Geometry("wheel 3", wheelMesh); node3.attachChild(wheels3); wheels3.rotate(0, FastMath.HALF_PI, 0); wheels3.setMaterial(mat); vehicle.addWheel(node3, new Vector3f(-xOff, yOff, -zOff), wheelDirection, wheelAxle, restLength, radius, false); Node node4 = new Node("wheel 4 node"); Geometry wheels4 = new Geometry("wheel 4", wheelMesh); node4.attachChild(wheels4); wheels4.rotate(0, FastMath.HALF_PI, 0); wheels4.setMaterial(mat); vehicle.addWheel(node4, new Vector3f(xOff, yOff, -zOff), wheelDirection, wheelAxle, restLength, radius, false); vehicleNode.attachChild(node1); vehicleNode.attachChild(node2); vehicleNode.attachChild(node3); vehicleNode.attachChild(node4); rootNode.attachChild(vehicleNode); getPhysicsSpace().add(vehicle); }
Example #17
Source File: DebugShapeFactory.java From jmonkeybuilder with Apache License 2.0 | 4 votes |
/** * 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); geometry.setLocalScale(ccollisionShape.getScale()); vars.release(); node.attachChild(geometry); } debugShape = node; } else { debugShape = createDebugShape(collisionShape); } if (debugShape == null) { return null; } debugShape.updateGeometricState(); return debugShape; }
Example #18
Source File: CollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 2 votes |
/** * This type of collision shape creates a CompoundShape made out of boxes that * are based on the bounds of the Geometries in the tree. * @param rootNode * @return */ private static CompoundCollisionShape createBoxCompoundShape(Node rootNode) { return createCompoundShape(rootNode, new CompoundCollisionShape(), false); }
Example #19
Source File: CollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 2 votes |
/** * 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 CompoundCollisionShape createMeshCompoundShape(Node rootNode) { return createCompoundShape(rootNode, new CompoundCollisionShape(), true); }
Example #20
Source File: CollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 2 votes |
/** * 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 CompoundCollisionShape createMeshCompoundShape(Node rootNode) { return createCompoundShape(rootNode, new CompoundCollisionShape(), true); }
Example #21
Source File: CollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 2 votes |
/** * This type of collision shape creates a CompoundShape made out of boxes that * are based on the bounds of the Geometries in the tree. * @param rootNode * @return */ private static CompoundCollisionShape createBoxCompoundShape(Node rootNode) { return createCompoundShape(rootNode, new CompoundCollisionShape(), false); }