/** * Build a map of mesh vertices in a subtree of the scene graph. * * @param model the root of the subtree (may be null) * @return a new map (not null) */ public static Map<Integer, List<Float>> buildPointMap(Spatial model) { Map<Integer, List<Float>> map = new HashMap<>(); SkeletonControl skeletonCtrl = model.getControl(SkeletonControl.class); Mesh[] targetMeshes = skeletonCtrl.getTargets(); for (Mesh mesh : targetMeshes) { buildPointMapForMesh(mesh, map); } return map; }
/** * Build a map of mesh vertices in a subtree of the scene graph. * * @param model the root of the subtree (may be null) * @return a new map (not null) */ public static Map<Integer, List<Float>> buildPointMap(Spatial model) { Map<Integer, List<Float>> map = new HashMap<>(); SkeletonControl skeletonCtrl = model.getControl(SkeletonControl.class); Mesh[] targetMeshes = skeletonCtrl.getTargets(); for (Mesh mesh : targetMeshes) { buildPointMapForMesh(mesh, map); } return map; }
/** * creates an animation event * * @param model the model on which the animation will be played * @param animationName the name of the animation to play */ public AnimationEvent(Spatial model, String animationName) { this.model = model; this.modelName = model.getName(); this.animationName = animationName; initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); }
private Spatial loadModel(int i) { Spatial model = assetManager.loadModel("Models/Oto/Oto.mesh.xml"); model.setLocalScale(0.1f); AnimComposer composer = model.getControl(AnimComposer.class); composer.setCurrentAction(animNames[i]); SkinningControl skinningControl = model.getControl(SkinningControl.class); skinningControl.setHardwareSkinningPreferred(hwSkinningEnable); skControls.add(skinningControl); rootNode.attachChild(model); return model; }
/** * creates an animation event * * @param model the model on which the animation will be played * @param animationName the name of the animation to play * @param loopMode the loopMode * @see LoopMode */ public AnimationEvent(Spatial model, String animationName, LoopMode loopMode) { super(loopMode); initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); this.model = model; this.modelName = model.getName(); this.animationName = animationName; }
/** * creates an animation event * * @param model the model on which the animation will be played * @param animationName the name of the animation to play * @param channelIndex the index of the channel default is 0. Events on the * same channelIndex will use the same channel. */ public AnimationEvent(Spatial model, String animationName, int channelIndex) { this.model = model; this.modelName = model.getName(); this.animationName = animationName; initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); this.channelIndex = channelIndex; }
private <T extends Control> T findControl(Spatial s, Class<T> controlClass) { T ctrl = s.getControl(controlClass); if (ctrl != null) { return ctrl; } if (s instanceof Node) { Node n = (Node) s; for (Spatial spatial : n.getChildren()) { ctrl = findControl(spatial, controlClass); if (ctrl != null) { return ctrl; } } } return null; }
/** * creates an animation event * * @param model the model on which the animation will be played * @param animationName the name of the animation to play * @param loopMode the loopMode * @see LoopMode * @param blendTime the time during the animation are gonna be blended * @see AnimChannel#setAnim(java.lang.String, float) */ public AnimationEvent(Spatial model, String animationName, LoopMode loopMode, float blendTime) { super(loopMode); initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); this.model = model; this.modelName = model.getName(); this.animationName = animationName; this.blendTime = blendTime; }
/** * creates an animation event * * @param model the model on which the animation will be played * @param animationName the name of the animation to play * @param loopMode the loopMode * @see LoopMode * @param channelIndex the index of the channel default is 0. Events on the * same channelIndex will use the same channel. */ public AnimationEvent(Spatial model, String animationName, LoopMode loopMode, int channelIndex) { super(loopMode); initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); this.model = model; this.modelName = model.getName(); this.animationName = animationName; this.channelIndex = channelIndex; }
/** * creates an animation event * * @param model the model on which the animation will be played * @param animationName the name of the animation to play * @param channelIndex the index of the channel default is 0. Events on the * @param blendTime the time during the animation are gonna be blended * same channelIndex will use the same channel. */ public AnimationEvent(Spatial model, String animationName, LoopMode loopMode, int channelIndex, float blendTime) { this.model = model; this.modelName = model.getName(); this.animationName = animationName; this.loopMode = loopMode; initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); this.channelIndex = channelIndex; this.blendTime = blendTime; }
private void playFirstAnim(Spatial s) { AnimComposer control = s.getControl(AnimComposer.class); if (control != null) { anims.clear(); for (String name : control.getAnimClipsNames()) { anims.add(name); } if (anims.isEmpty()) { return; } String anim = anims.poll(); anims.add(anim); control.setCurrentAction(anim); composer = control; } if (s instanceof Node) { Node n = (Node) s; for (Spatial spatial : n.getChildren()) { playFirstAnim(spatial); } } }
private void stopAnim(Spatial s) { AnimComposer control = s.getControl(AnimComposer.class); if (control != null) { control.reset(); } if (s instanceof Node) { Node n = (Node) s; for (Spatial spatial : n.getChildren()) { stopAnim(spatial); } } }
/** * adds an object to the physics space * @param obj the PhysicsControl or Spatial with PhysicsControl to add */ public void add(Object obj) { if (obj == null) return; if (obj instanceof PhysicsControl) { ((PhysicsControl) obj).setPhysicsSpace(this); } else if (obj instanceof Spatial) { Spatial node = (Spatial) obj; for (int i = 0; i < node.getNumControls(); i++) { if (node.getControl(i) instanceof PhysicsControl) { add(((PhysicsControl) node.getControl(i))); } } } else if (obj instanceof PhysicsCollisionObject) { addCollisionObject((PhysicsCollisionObject) obj); } else if (obj instanceof PhysicsJoint) { addJoint((PhysicsJoint) obj); } else { throw (new UnsupportedOperationException("Cannot add this kind of object to the physics space.")); } }
/** * removes an object from the physics space * * @param obj the PhysicsControl or Spatial with PhysicsControl to remove */ public void remove(Object obj) { if (obj == null) return; if (obj instanceof PhysicsControl) { ((PhysicsControl) obj).setPhysicsSpace(null); } else if (obj instanceof Spatial) { Spatial node = (Spatial) obj; for (int i = 0; i < node.getNumControls(); i++) { if (node.getControl(i) instanceof PhysicsControl) { remove(((PhysicsControl) node.getControl(i))); } } } else if (obj instanceof PhysicsCollisionObject) { removeCollisionObject((PhysicsCollisionObject) obj); } else if (obj instanceof PhysicsJoint) { removeJoint((PhysicsJoint) obj); } else { throw (new UnsupportedOperationException("Cannot remove this kind of object from the physics space.")); } }
/** * Remove the specified object from this space. * * @param obj the PhysicsCollisionObject to add, or null (modified) */ public void remove(Object obj) { if (obj == null) return; if (obj instanceof PhysicsControl) { ((PhysicsControl) obj).setPhysicsSpace(null); } else if (obj instanceof Spatial) { Spatial node = (Spatial) obj; for (int i = 0; i < node.getNumControls(); i++) { if (node.getControl(i) instanceof PhysicsControl) { remove(((PhysicsControl) node.getControl(i))); } } } else if (obj instanceof PhysicsCollisionObject) { removeCollisionObject((PhysicsCollisionObject) obj); } else if (obj instanceof PhysicsJoint) { removeJoint((PhysicsJoint) obj); } else { throw (new UnsupportedOperationException("Cannot remove this kind of object from the physics space.")); } }
/** * Generate physics shapes and bone links for the skeleton. * * @param model the spatial with the model's SkeletonControl (not null) */ protected void scanSpatial(Spatial model) { AnimControl animControl = model.getControl(AnimControl.class); Map<Integer, List<Float>> pointsMap = null; if (weightThreshold == -1.0f) { pointsMap = RagdollUtils.buildPointMap(model); } skeleton = animControl.getSkeleton(); skeleton.resetAndUpdate(); for (int i = 0; i < skeleton.getRoots().length; i++) { Bone childBone = skeleton.getRoots()[i]; if (childBone.getParent() == null) { logger.log(Level.FINE, "Found root bone in skeleton {0}", skeleton); boneRecursion(model, childBone, baseRigidBody, 1, pointsMap); } } }
/** * Generate physics shapes and bone links for the skeleton. * * @param model the spatial with the model's SkeletonControl (not null) */ protected void scanSpatial(Spatial model) { AnimControl animControl = model.getControl(AnimControl.class); Map<Integer, List<Float>> pointsMap = null; if (weightThreshold == -1.0f) { pointsMap = RagdollUtils.buildPointMap(model); } skeleton = animControl.getSkeleton(); skeleton.resetAndUpdate(); for (int i = 0; i < skeleton.getRoots().length; i++) { Bone childBone = skeleton.getRoots()[i]; if (childBone.getParent() == null) { logger.log(Level.FINE, "Found root bone in skeleton {0}", skeleton); boneRecursion(model, childBone, baseRigidBody, 1, pointsMap); } } }
private void reset() { // Reset the pickups for(Spatial pickUp : pickUps.getChildren()) { GhostControl pickUpControl = pickUp.getControl(GhostControl.class); if(pickUpControl != null) { pickUpControl.setEnabled(true); } pickUp.setLocalScale(1.0f); } // Reset the player player.setPhysicsLocation(PLAYER_START.clone()); player.setAngularVelocity(Vector3f.ZERO.clone()); player.setLinearVelocity(Vector3f.ZERO.clone()); // Reset the score score = 0; // Reset the message messageText.setLocalScale(0.0f); }
@Override public void simpleInitApp() { flyCam.setMoveSpeed(10f); cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f)); cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f)); DirectionalLight dl = new DirectionalLight(); dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal()); dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f)); rootNode.addLight(dl); BlenderKey blenderKey = new BlenderKey("Blender/2.4x/BaseMesh_249.blend"); Spatial scene = (Spatial) assetManager.loadModel(blenderKey); rootNode.attachChild(scene); Spatial model = this.findNode(rootNode, "BaseMesh_01"); model.center(); control = model.getControl(AnimControl.class); channel = control.createChannel(); channel.setAnim("run_01"); }
@Override public void simpleInitApp() { flyCam.setMoveSpeed(10f); cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f)); cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f)); DirectionalLight dl = new DirectionalLight(); dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal()); dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f)); rootNode.addLight(dl); BlenderKey blenderKey = new BlenderKey("Blender/2.4x/animtest.blend"); Spatial scene = (Spatial) assetManager.loadModel(blenderKey); rootNode.attachChild(scene); Spatial model = this.findNode(rootNode, "Cube"); model.center(); control = model.getControl(AnimControl.class); channel = control.createChannel(); channel.setAnim("Action"); }