Java Code Examples for com.jme3.scene.Spatial#addControl()
The following examples show how to use
com.jme3.scene.Spatial#addControl() .
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: MotionEvent.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Creates a MotionPath for the given spatial on the given motion path. * @param spatial * @param path */ public MotionEvent(Spatial spatial, MotionPath path, LoopMode loopMode) { super(); spatial.addControl(this); this.path = path; this.loopMode = loopMode; }
Example 2
Source File: MotionTrack.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Creates a MotionPath for the given spatial on the given motion path * @param spatial * @param path */ public MotionTrack(Spatial spatial, MotionPath path, float initialDuration) { super(initialDuration); this.spatial = spatial; spatial.addControl(this); this.path = path; }
Example 3
Source File: MotionTrack.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Creates a MotionPath for the given spatial on the given motion path * @param spatial * @param path */ public MotionTrack(Spatial spatial, MotionPath path, LoopMode loopMode) { super(); this.spatial = spatial; spatial.addControl(this); this.path = path; this.loopMode = loopMode; }
Example 4
Source File: AnimControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Internal use only. */ @Override public void setSpatial(Spatial spatial) { if (spatial == null && skeletonControl != null) { this.spatial.removeControl(skeletonControl); } super.setSpatial(spatial); //Backward compatibility. if (spatial != null && skeletonControl != null) { spatial.addControl(skeletonControl); } }
Example 5
Source File: TestHoveringTank.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void makeMissile() { Vector3f pos = spaceCraft.getWorldTranslation().clone(); Quaternion rot = spaceCraft.getWorldRotation(); Vector3f dir = rot.getRotationColumn(2); Spatial missile = assetManager.loadModel("Models/SpaceCraft/Rocket.mesh.xml"); missile.scale(0.5f); missile.rotate(0, FastMath.PI, 0); missile.updateGeometricState(); BoundingBox box = (BoundingBox) missile.getWorldBound(); final Vector3f extent = box.getExtent(null); BoxCollisionShape boxShape = new BoxCollisionShape(extent); missile.setName("Missile"); missile.rotate(rot); missile.setLocalTranslation(pos.addLocal(0, extent.y * 4.5f, 0)); missile.setLocalRotation(hoverControl.getPhysicsRotation()); missile.setShadowMode(ShadowMode.Cast); RigidBodyControl control = new BombControl(assetManager, boxShape, 20); control.setLinearVelocity(dir.mult(100)); control.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_03); missile.addControl(control); rootNode.attachChild(missile); getPhysicsSpace().add(missile); }
Example 6
Source File: MotionTrack.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Creates a MotionPath for the given spatial on the given motion path * @param spatial * @param path */ public MotionTrack(Spatial spatial, MotionPath path, float initialDuration, LoopMode loopMode) { super(initialDuration); this.spatial = spatial; spatial.addControl(this); this.path = path; this.loopMode = loopMode; }
Example 7
Source File: AnimControl.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Internal use only. */ @Override public void setSpatial(Spatial spatial) { if (spatial == null && skeletonControl != null) { this.spatial.removeControl(skeletonControl); } super.setSpatial(spatial); //Backward compatibility. if (spatial != null && skeletonControl != null) { spatial.addControl(skeletonControl); } }
Example 8
Source File: TestHoveringTank.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void makeMissile() { Vector3f pos = spaceCraft.getWorldTranslation().clone(); Quaternion rot = spaceCraft.getWorldRotation(); Vector3f dir = rot.getRotationColumn(2); Spatial missile = assetManager.loadModel("Models/SpaceCraft/Rocket.mesh.xml"); missile.scale(0.5f); missile.rotate(0, FastMath.PI, 0); missile.updateGeometricState(); BoundingBox box = (BoundingBox) missile.getWorldBound(); final Vector3f extent = box.getExtent(null); BoxCollisionShape boxShape = new BoxCollisionShape(extent); missile.setName("Missile"); missile.rotate(rot); missile.setLocalTranslation(pos.addLocal(0, extent.y * 4.5f, 0)); missile.setLocalRotation(hoverControl.getPhysicsRotation()); missile.setShadowMode(ShadowMode.Cast); RigidBodyControl control = new BombControl(assetManager, boxShape, 20); control.setLinearVelocity(dir.mult(100)); control.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_03); missile.addControl(control); rootNode.attachChild(missile); getPhysicsSpace().add(missile); }
Example 9
Source File: MouseEventControl.java From Lemur with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Convenience method that will add a MouseEventControl if it * doesn't exist, while adding the specified listeners. */ public static void addListenersToSpatial( Spatial s, MouseListener... listeners ) { if( s == null ) { return; } MouseEventControl mec = s.getControl(MouseEventControl.class); if( mec == null ) { s.addControl(new MouseEventControl(listeners)); } else { mec.listeners.addAll(Arrays.asList(listeners)); } }
Example 10
Source File: CursorEventControl.java From Lemur with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Convenience method that will add a CursorEventControl if it * doesn't exist, while adding the specified listeners. */ public static void addListenersToSpatial( Spatial s, CursorListener... listeners ) { if( s == null ) { return; } CursorEventControl cec = s.getControl(CursorEventControl.class); if( cec == null ) { s.addControl(new CursorEventControl(listeners)); } else { cec.listeners.addAll(Arrays.asList(listeners)); } }
Example 11
Source File: FbxNode.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static Spatial createScene(FbxNode fbxNode) { Spatial jmeSpatial = fbxNode.getJmeObject(); if (jmeSpatial instanceof Node) { // Attach children to Node Node jmeNode = (Node) jmeSpatial; for (FbxNode fbxChild : fbxNode.children) { if (!(fbxChild instanceof FbxLimbNode)) { createScene(fbxChild); FbxNode preferredParent = fbxChild.getPreferredParent(); Spatial jmeChild = fbxChild.getJmeObject(); if (preferredParent != null) { System.out.println("Preferred parent for " + fbxChild + " is " + preferredParent); Node jmePreferredParent = (Node) preferredParent.getJmeObject(); relocateSpatial(jmeChild, fbxChild.jmeWorldNodeTransform, preferredParent.jmeWorldNodeTransform); jmePreferredParent.attachChild(jmeChild); } else { jmeNode.attachChild(jmeChild); } } } } if (fbxNode.skeleton != null) { jmeSpatial.addControl(new AnimControl(fbxNode.skeleton)); jmeSpatial.addControl(new SkeletonControl(fbxNode.skeleton)); SkeletonDebugger sd = new SkeletonDebugger("debug", fbxNode.skeleton); Material mat = new Material(fbxNode.assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.getAdditionalRenderState().setWireframe(true); mat.getAdditionalRenderState().setDepthTest(false); mat.setColor("Color", ColorRGBA.Green); sd.setMaterial(mat); ((Node)jmeSpatial).attachChild(sd); } return jmeSpatial; }
Example 12
Source File: MotionEvent.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Creates a MotionPath for the given spatial on the given motion path. * @param spatial * @param path */ public MotionEvent(Spatial spatial, MotionPath path, float initialDuration) { super(initialDuration); spatial.addControl(this); this.path = path; }
Example 13
Source File: RemoveElementsOperation.java From jmonkeybuilder with Apache License 2.0 | 4 votes |
@JmeThread private void restoreControl(@NotNull final Element element, @NotNull final Control toRestore) { final Spatial parent = (Spatial) element.getParent(); parent.addControl(toRestore); }
Example 14
Source File: KinematicRagdollControl.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Create spatial-dependent data. Invoked when this control is added to a * scene. * * @param model the controlled spatial (not null) */ @Override protected void createSpatialData(Spatial model) { targetModel = model; Node parent = model.getParent(); Vector3f initPosition = model.getLocalTranslation().clone(); Quaternion initRotation = model.getLocalRotation().clone(); initScale = model.getLocalScale().clone(); model.removeFromParent(); model.setLocalTranslation(Vector3f.ZERO); model.setLocalRotation(Quaternion.IDENTITY); model.setLocalScale(1); //HACK ALERT change this //I remove the skeletonControl and readd it to the spatial to make sure it's after the ragdollControl in the stack //Find a proper way to order the controls. SkeletonControl sc = model.getControl(SkeletonControl.class); if(sc == null){ throw new IllegalArgumentException("The root node of the model should have a SkeletonControl. Make sure the control is there and that it's not on a sub node."); } model.removeControl(sc); model.addControl(sc); if (boneList.isEmpty()) { // add all bones to the list skeleton = sc.getSkeleton(); for (int boneI = 0; boneI < skeleton.getBoneCount(); boneI++) { String boneName = skeleton.getBone(boneI).getName(); boneList.add(boneName); } } // filter out bones without vertices filterBoneList(sc); if (boneList.isEmpty()) { throw new IllegalArgumentException( "No suitable bones were found in the model's skeleton."); } // put into bind pose and compute bone transforms in model space // maybe don't reset to ragdoll out of animations? scanSpatial(model); if (parent != null) { parent.attachChild(model); } model.setLocalTranslation(initPosition); model.setLocalRotation(initRotation); model.setLocalScale(initScale); if (added) { addPhysics(space); } logger.log(Level.FINE, "Created physics ragdoll for skeleton {0}", skeleton); }
Example 15
Source File: CollisionTester.java From OpenRTS with MIT License | 4 votes |
public static boolean areColliding(Asset asset1, Asset asset2, boolean debug){ Spatial s1 = getSpatialFromAsset(asset1); Spatial s2 = getSpatialFromAsset(asset2); PhysicsSpace space = new PhysicsSpace(); RigidBodyControl ghost1 = new RigidBodyControl(getCollisionShape(asset1)); s1.addControl(ghost1); space.add(ghost1); RigidBodyControl ghost2 = new RigidBodyControl(getCollisionShape(asset2)); s2.addControl(ghost2); // ghost2.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02); // space.add(ghost2); space.update(1); // int numCollision = ghost1.getOverlappingCount(); // boolean collision = numCollision > 0; Transform t = new Transform(); t.setRotation(s2.getLocalRotation()); t.setTranslation(s2.getLocalTranslation()); boolean collision = false; for(ChildCollisionShape hull : getCollisionShape(asset2).getChildren()) if(!space.sweepTest(hull.shape, Transform.IDENTITY, t).isEmpty()){ collision = true; break; } space.remove(ghost1); // space.remove(ghost2); // if(!collision){ // Spatial debugS2 = DebugShapeFactory.getDebugShape(ghost2.getCollisionShape()); // debugS2.setLocalRotation(ghost2.getPhysicsRotation()); //// Spatial debugS2 = s2; // Material m = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"); // m.getAdditionalRenderState().setWireframe(true); // m.setColor("Color", ColorRGBA.Red); // debugS2.setMaterial(m); // debugS2.setLocalTranslation(ghost2.getPhysicsLocation()); // asset2.s = debugS2; // //EventManager.post(new GenericEvent(debugS2)); // } if(!collision){// && debug){ Material m = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"); m.getAdditionalRenderState().setWireframe(true); m.setColor("Color", ColorRGBA.Red); Spatial debugS2 = DebugShapeFactory.getDebugShape(getCollisionShape(asset2)); debugS2.setLocalTransform(t); // debugS2.setLocalRotation(ghost2.getPhysicsRotation()); // debugS2.setLocalTranslation(ghost2.getPhysicsLocation()); debugS2.setMaterial(m); Material m2 = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"); m2.getAdditionalRenderState().setWireframe(true); m2.setColor("Color", ColorRGBA.Blue); Geometry linegeom = new Geometry(); Line l = new Line(debugS2.getLocalTranslation().add(0, 0, 1), ghost1.getPhysicsLocation().add(0, 0, 1)); linegeom.setMesh(l); linegeom.setMaterial(m2); asset2.s = debugS2; if(l.getStart().distance(l.getEnd())<2) asset2.links.add(linegeom); // EventManager.post(new GenericEvent(debugS2)); // EventManager.post(new GenericEvent(linegeom)); } return collision; }
Example 16
Source File: KinematicRagdollControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void setSpatial(Spatial model) { if (model == null) { removeFromPhysicsSpace(); clearData(); return; } targetModel = model; Node parent = model.getParent(); Vector3f initPosition = model.getLocalTranslation().clone(); Quaternion initRotation = model.getLocalRotation().clone(); initScale = model.getLocalScale().clone(); model.removeFromParent(); model.setLocalTranslation(Vector3f.ZERO); model.setLocalRotation(Quaternion.IDENTITY); model.setLocalScale(1); //HACK ALERT change this //I remove the skeletonControl and readd it to the spatial to make sure it's after the ragdollControl in the stack //Find a proper way to order the controls. SkeletonControl sc = model.getControl(SkeletonControl.class); model.removeControl(sc); model.addControl(sc); //---- removeFromPhysicsSpace(); clearData(); // put into bind pose and compute bone transforms in model space // maybe dont reset to ragdoll out of animations? scanSpatial(model); if (parent != null) { parent.attachChild(model); } model.setLocalTranslation(initPosition); model.setLocalRotation(initRotation); model.setLocalScale(initScale); logger.log(Level.INFO, "Created physics ragdoll for skeleton {0}", skeleton); }
Example 17
Source File: KinematicRagdollControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void setSpatial(Spatial model) { if (model == null) { removeFromPhysicsSpace(); clearData(); return; } targetModel = model; Node parent = model.getParent(); Vector3f initPosition = model.getLocalTranslation().clone(); Quaternion initRotation = model.getLocalRotation().clone(); initScale = model.getLocalScale().clone(); model.removeFromParent(); model.setLocalTranslation(Vector3f.ZERO); model.setLocalRotation(Quaternion.IDENTITY); model.setLocalScale(1); //HACK ALERT change this //I remove the skeletonControl and readd it to the spatial to make sure it's after the ragdollControl in the stack //Find a proper way to order the controls. SkeletonControl sc = model.getControl(SkeletonControl.class); model.removeControl(sc); model.addControl(sc); //---- removeFromPhysicsSpace(); clearData(); // put into bind pose and compute bone transforms in model space // maybe dont reset to ragdoll out of animations? scanSpatial(model); if (parent != null) { parent.attachChild(model); } model.setLocalTranslation(initPosition); model.setLocalRotation(initRotation); model.setLocalScale(initScale); logger.log(Level.INFO, "Created physics ragdoll for skeleton {0}", skeleton); }
Example 18
Source File: ChaseCamera.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 2 votes |
/** * Constructs the chase camera * @param cam the application camera * @param target the spatial to follow */ public ChaseCamera(Camera cam, final Spatial target) { this(cam); target.addControl(this); }
Example 19
Source File: ChaseCamera.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Constructs the chase camera * @param cam the application camera * @param target the spatial to follow */ public ChaseCamera(Camera cam, final Spatial target) { this(cam); target.addControl(this); }
Example 20
Source File: EditorCamera.java From jmonkeybuilder with Apache License 2.0 | 2 votes |
/** * Constructs the chase camera * * @param camera the application camera * @param target the spatial to follow */ public EditorCamera(@NotNull final Camera camera, @NotNull final Spatial target) { this(camera); target.addControl(this); }