/** * creates an empty node with a RigidBodyControl * * @param manager for loading assets * @param shape a shape for the collision object * @param mass a mass for rigid body * @return a new Node */ public static Node createPhysicsTestNode(AssetManager manager, CollisionShape shape, float mass) { Node node = new Node("PhysicsNode"); RigidBodyControl control = new RigidBodyControl(shape, mass); node.addControl(control); return node; }
private void updateGhosts() { HashMap<PhysicsGhostObject, Spatial> oldObjects = ghosts; ghosts = new HashMap<PhysicsGhostObject, Spatial>(); Collection<PhysicsGhostObject> current = space.getGhostObjectList(); //create new map for (Iterator<PhysicsGhostObject> it = current.iterator(); it.hasNext();) { PhysicsGhostObject physicsObject = it.next(); //copy existing spatials if (oldObjects.containsKey(physicsObject)) { Spatial spat = oldObjects.get(physicsObject); ghosts.put(physicsObject, spat); oldObjects.remove(physicsObject); } else { if (filter == null || filter.displayObject(physicsObject)) { logger.log(Level.FINE, "Create new debug GhostObject"); //create new spatial Node node = new Node(physicsObject.toString()); node.addControl(new BulletGhostObjectDebugControl(this, physicsObject)); ghosts.put(physicsObject, node); physicsDebugRootNode.attachChild(node); } } } //remove leftover spatials for (Map.Entry<PhysicsGhostObject, Spatial> entry : oldObjects.entrySet()) { PhysicsGhostObject object = entry.getKey(); Spatial spatial = entry.getValue(); spatial.removeFromParent(); } }
private void updateCharacters() { HashMap<PhysicsCharacter, Spatial> oldObjects = characters; characters = new HashMap<PhysicsCharacter, Spatial>(); Collection<PhysicsCharacter> current = space.getCharacterList(); //create new map for (Iterator<PhysicsCharacter> it = current.iterator(); it.hasNext();) { PhysicsCharacter physicsObject = it.next(); //copy existing spatials if (oldObjects.containsKey(physicsObject)) { Spatial spat = oldObjects.get(physicsObject); characters.put(physicsObject, spat); oldObjects.remove(physicsObject); } else { if (filter == null || filter.displayObject(physicsObject)) { logger.log(Level.FINE, "Create new debug Character"); //create new spatial Node node = new Node(physicsObject.toString()); node.addControl(new BulletCharacterDebugControl(this, physicsObject)); characters.put(physicsObject, node); physicsDebugRootNode.attachChild(node); } } } //remove leftover spatials for (Map.Entry<PhysicsCharacter, Spatial> entry : oldObjects.entrySet()) { PhysicsCharacter object = entry.getKey(); Spatial spatial = entry.getValue(); spatial.removeFromParent(); } }
private void updateJoints() { HashMap<PhysicsJoint, Spatial> oldObjects = joints; joints = new HashMap<PhysicsJoint, Spatial>(); Collection<PhysicsJoint> current = space.getJointList(); //create new map for (Iterator<PhysicsJoint> it = current.iterator(); it.hasNext();) { PhysicsJoint physicsObject = it.next(); //copy existing spatials if (oldObjects.containsKey(physicsObject)) { Spatial spat = oldObjects.get(physicsObject); joints.put(physicsObject, spat); oldObjects.remove(physicsObject); } else { if (filter == null || filter.displayObject(physicsObject)) { logger.log(Level.FINE, "Create new debug Joint"); //create new spatial Node node = new Node(physicsObject.toString()); node.addControl(new BulletJointDebugControl(this, physicsObject)); joints.put(physicsObject, node); physicsDebugRootNode.attachChild(node); } } } //remove leftover spatials for (Map.Entry<PhysicsJoint, Spatial> entry : oldObjects.entrySet()) { PhysicsJoint object = entry.getKey(); Spatial spatial = entry.getValue(); spatial.removeFromParent(); } }
private void applySkinning() { for(FbxBindPose pose : bindMap.values()) pose.fillBindTransforms(); if(limbMap == null) return; List<Bone> bones = new ArrayList<>(); for(FbxNode limb : limbMap.values()) { if(limb.bone != null) { bones.add(limb.bone); limb.buildBindPoseBoneTransform(); } } skeleton = new Skeleton(bones.toArray(new Bone[bones.size()])); skeleton.setBindingPose(); for(FbxNode limb : limbMap.values()) limb.setSkeleton(skeleton); for(FbxSkin skin : skinMap.values()) skin.generateSkinning(); // Attach controls animControl = new AnimControl(skeleton); sceneNode.addControl(animControl); SkeletonControl control = new SkeletonControl(skeleton); sceneNode.addControl(control); }
private Node createLimb(float width, float height, Vector3f location, boolean rotate) { int axis = rotate ? PhysicsSpace.AXIS_X : PhysicsSpace.AXIS_Y; CapsuleCollisionShape shape = new CapsuleCollisionShape(width, height, axis); Node node = new Node("Limb"); RigidBodyControl rigidBodyControl = new RigidBodyControl(shape, 1); node.setLocalTranslation(location); node.addControl(rigidBodyControl); return node; }
private void createCharacter() { CapsuleCollisionShape capsule = new CapsuleCollisionShape(3f, 4f); character = new CharacterControl(capsule, 0.01f); model = (Node) assetManager.loadModel("Models/Oto/OtoOldAnim.j3o"); //model.setLocalScale(0.5f); model.addControl(character); character.setPhysicsLocation(new Vector3f(-140, 40, -10)); rootNode.attachChild(model); getPhysicsSpace().add(character); }
private void initGhostObject() { Vector3f halfExtents = new Vector3f(3, 4.2f, 1); ghostControl = new GhostControl(new BoxCollisionShape(halfExtents)); Node node=new Node("Ghost Object"); node.addControl(ghostControl); rootNode.attachChild(node); getPhysicsSpace().add(ghostControl); }
Node createTestNode(float mass, Vector3f location) { float size = 0.1f; Vector3f halfExtents = new Vector3f(size, size, size); CollisionShape shape = new BoxCollisionShape(halfExtents); RigidBodyControl control = new RigidBodyControl(shape, mass); Node node = new Node(); node.addControl(control); rootNode.attachChild(node); bulletAppState.getPhysicsSpace().add(node); control.setPhysicsLocation(location); return node; }
@Override public void simpleInitApp() { flyCam.setEnabled(false); BulletAppState bulletAppState = new BulletAppState(); bulletAppState.setDebugEnabled(true); bulletAppState.setSpeed(0f); stateManager.attach(bulletAppState); PhysicsSpace space = bulletAppState.getPhysicsSpace(); float radius = 1f; CollisionShape sphere = new SphereCollisionShape(radius); CollisionShape box = new BoxCollisionShape(Vector3f.UNIT_XYZ); RigidBodyControl rbc = new RigidBodyControl(box); rbc.setEnabled(false); rbc.setPhysicsSpace(space); rootNode.addControl(rbc); BetterCharacterControl bcc = new BetterCharacterControl(radius, 4f, 1f); bcc.setEnabled(false); bcc.setPhysicsSpace(space); rootNode.addControl(bcc); GhostControl gc = new GhostControl(sphere); gc.setEnabled(false); gc.setPhysicsSpace(space); rootNode.addControl(gc); } }
sinbad.addControl(ragdoll);
@Override public void simpleInitApp() { BulletAppState bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); String sinbadPath = "Models/Sinbad/SinbadOldAnim.j3o"; Node sinbad = (Node) assetManager.loadModel(sinbadPath); Node extender = new Node(); for (Spatial child : sinbad.getChildren()) { extender.attachChild(child); } sinbad.attachChild(extender); //Note: PhysicsRagdollControl is still a WIP, constructor will change KinematicRagdollControl ragdoll = new KinematicRagdollControl(0.5f); sinbad.addControl(ragdoll); stop(); } }
@Override public void simpleInitApp() { obstacleCollisionShape = new CapsuleCollisionShape(0.3f, 0.5f); capsuleCollisionShape = new CapsuleCollisionShape(1f, 1f); stateManager.attach(bulletAppState); capsule = new Node("capsule"); capsule.move(-2, 0, 0); capsule.addControl(new RigidBodyControl(capsuleCollisionShape, 1)); capsule.getControl(RigidBodyControl.class).setKinematic(true); bulletAppState.getPhysicsSpace().add(capsule); rootNode.attachChild(capsule); obstacle = new Node("obstacle"); obstacle.move(2, 0, 0); RigidBodyControl bodyControl = new RigidBodyControl(obstacleCollisionShape, 0); obstacle.addControl(bodyControl); bulletAppState.getPhysicsSpace().add(obstacle); rootNode.attachChild(obstacle); bulletAppState.setDebugEnabled(true); }
@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); }
/** * No ClassCastException when clear() a Cinematic with AnimationEvent */ @Test public void clearAnimationEvent() { Cinematic sut = new Cinematic(); Node model = new Node("model"); AnimControl ac = new AnimControl(); ac.addAnim(new Animation("animName", 1.0f)); model.addControl(ac); sut.enqueueCinematicEvent(new AnimationEvent(model, "animName")); sut.initialize(null, null); sut.clear(); } }
@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); }
model.addControl(ragdoll);
@Override public void simpleInitApp() { bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); bulletAppState.setDebugEnabled(true); createMaterial(); Node node = new Node("node1"); attachRandomGeometry(node, mat1); randomizeTransform(node); Node node2 = new Node("node2"); attachRandomGeometry(node2, mat2); randomizeTransform(node2); node.attachChild(node2); rootNode.attachChild(node); RigidBodyControl control = new RigidBodyControl(0); node.addControl(control); getPhysicsSpace().add(control); //test single geometry too Geometry myGeom = new Geometry("cylinder", new Cylinder(16, 16, 0.5f, 1)); myGeom.setMaterial(mat3); randomizeTransform(myGeom); rootNode.attachChild(myGeom); RigidBodyControl control3 = new RigidBodyControl(0); myGeom.addControl(control3); getPhysicsSpace().add(control3); }
@Override public void simpleInitApp() { // activate physics bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); // init a physical test scene PhysicsTestHelper.createPhysicsTestWorldSoccer(rootNode, assetManager, bulletAppState.getPhysicsSpace()); setupKeys(); // Add a physics character to the world physicsCharacter = new CharacterControl(new CapsuleCollisionShape(0.5f, 1.8f), .1f); physicsCharacter.setPhysicsLocation(new Vector3f(0, 1, 0)); characterNode = new Node("character node"); Spatial model = assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml"); model.scale(0.25f); characterNode.addControl(physicsCharacter); getPhysicsSpace().add(physicsCharacter); rootNode.attachChild(characterNode); characterNode.attachChild(model); // set forward camera node that follows the character camNode = new CameraNode("CamNode", cam); camNode.setControlDir(ControlDirection.SpatialToCamera); camNode.setLocalTranslation(new Vector3f(0, 1, -5)); camNode.lookAt(model.getLocalTranslation(), Vector3f.UNIT_Y); characterNode.attachChild(camNode); //disable the default 1st-person flyCam (don't forget this!!) flyCam.setEnabled(false); }
public void setupJoint() { Node holderNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.1f, .1f, .1f)), 0); holderNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, 0, 0f)); rootNode.attachChild(holderNode); getPhysicsSpace().add(holderNode); Node hammerNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.3f, .3f, .3f)), 1); hammerNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -1, 0f)); rootNode.attachChild(hammerNode); getPhysicsSpace().add(hammerNode); //immovable collisionNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.3f, .3f, .3f)), 0); collisionNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(1.8f, 0, 0f)); rootNode.attachChild(collisionNode); getPhysicsSpace().add(collisionNode); //ghost node ghostControl = new GhostControl(new SphereCollisionShape(0.7f)); hammerNode.addControl(ghostControl); getPhysicsSpace().add(ghostControl); joint = new HingeJoint(holderNode.getControl(RigidBodyControl.class), hammerNode.getControl(RigidBodyControl.class), Vector3f.ZERO, new Vector3f(0f, -1, 0f), Vector3f.UNIT_Z, Vector3f.UNIT_Z); getPhysicsSpace().add(joint); }