/** * Alter which spatial is controlled. Invoked when the control is added to * or removed from a spatial. Should be invoked only by a subclass or from * Spatial. Do not invoke directly from user code. * * @param spatial the spatial to control (or null) */ @Override public void setSpatial(Spatial spatial) { if (spatial != null && spatial instanceof Node) { Node node = (Node) spatial; node.attachChild(geom); } else if (spatial == null && this.spatial != null) { Node node = (Node) this.spatial; node.detachChild(geom); } super.setSpatial(spatial); }
@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(); } }
public void setupRobotGuy(){ Node model = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml"); Material mat = assetManager.loadMaterial("Models/Oto/Oto.j3m"); model.getChild(0).setMaterial(mat); // model.setAnimation("Walk"); model.setLocalTranslation(30, 10.5f, 30); model.setLocalScale(2); model.setShadowMode(ShadowMode.CastAndReceive); rootNode.attachChild(model); }
private void attach(Node parent, boolean deforms, Geometry geom) { if (deforms) { parent.attachChild(geom); } else { ((Node) parent.getChild(0)).attachChild(geom); } }
@Override public void update(float tpf) { if (clickDelay > -1) { clickDelay += tpf; } debugNode.updateLogicalState(tpf); debugNode.updateGeometricState(); }
public Node getRootNode() { if (rootNode == null) { rootNode = new Node("ZoomLevel"); if (parent != null) { rootNode.setLocalScale(1.0f / poiRadius); } } return rootNode; }
@Test public void testOverrides_AddAfterAttach() { Node scene = createDummyScene(); scene.updateGeometricState(); Node root = new Node("Root Node"); root.updateGeometricState(); root.attachChild(scene); scene.getChild("A").addMatParamOverride(mpoInt("val", 5)); validateScene(root); }
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); }
@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); }
public void setupFloor() { mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m"); Node floorGeom = new Node("floorGeom"); Quad q = new Quad(100, 100); q.scaleTextureCoordinates(new Vector2f(10, 10)); Geometry g = new Geometry("geom", q); g.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); floorGeom.attachChild(g); TangentBinormalGenerator.generate(floorGeom); floorGeom.setLocalTranslation(-50, 22, 60); //floorGeom.setLocalScale(100); floorGeom.setMaterial(mat); rootNode.attachChild(floorGeom); }
@Override public void onAction(String name, boolean isPressed, float tpf) { if (name.equals("tex") && isPressed) { if (tex == null) { tex = EnvMapUtils.getCubeMapCrossDebugViewWithMipMaps(stateManager.getState(EnvironmentCamera.class).debugEnv, assetManager); } if (tex.getParent() == null) { guiNode.attachChild(tex); } else { tex.removeFromParent(); } } if (name.equals("switch") && isPressed) { switchMat(rootNode.getChild("Scene")); } if (name.equals("ref") && isPressed) { if (ref.getParent() == null) { guiNode.attachChild(ref); } else { ref.removeFromParent(); } } } }, "tex", "switch", "ref");
model.lookAt(new Vector3f(0,0,-1), Vector3f.UNIT_Y); model.setLocalTranslation(4, 0, -7f); model.addControl(ragdoll); rootNode.attachChild(model); AnimControl control = model.getControl(AnimControl.class); animChannel = control.createChannel(); animChannel.setAnim("IdleTop");
/** * For debuging porpose only * Will return a Node meant to be added to a GUI presenting the 2 cube maps in a cross pattern with all the mip maps. * * @param manager the asset manager * @return a debug node */ public static Node getDebugGui(AssetManager manager, LightProbe probe) { if (!probe.isReady()) { throw new UnsupportedOperationException("This EnvProbe is not ready yet, try to test isReady()"); } Node debugNode = new Node("debug gui probe"); Node debugPfemCm = EnvMapUtils.getCubeMapCrossDebugViewWithMipMaps(probe.getPrefilteredEnvMap(), manager); debugNode.attachChild(debugPfemCm); debugPfemCm.setLocalTranslation(520, 0, 0); return debugNode; }
/** * Fetches the world matrix transformation of the given node. * @param node * the node * @return the node's world transformation matrix */ private Matrix4f getWorldMatrix(Node node) { Matrix4f result = new Matrix4f(); result.setTranslation(node.getWorldTranslation()); result.setRotationQuaternion(node.getWorldRotation()); result.setScale(node.getWorldScale()); return result; }
@Override public void simpleUpdate(float tpf) { frame++; if (frame == 2) { modelNode.removeFromParent(); final LightProbe probe = LightProbeFactory.makeProbe(stateManager.getState(EnvironmentCamera.class), rootNode, new JobProgressAdapter<LightProbe>() { @Override public void done(LightProbe result) { System.err.println("Done rendering env maps"); tex = EnvMapUtils.getCubeMapCrossDebugViewWithMipMaps(result.getPrefilteredEnvMap(), assetManager); } }); ((SphereProbeArea) probe.getArea()).setRadius(100); rootNode.addLight(probe); //getStateManager().getState(EnvironmentManager.class).addEnvProbe(probe); } if (frame > 10 && modelNode.getParent() == null) { rootNode.attachChild(modelNode); } }
@Override public void update(float tpf) { if (spatial == null) { throw new IllegalArgumentException("The spatial to follow is null, please use the setTarget method"); } target.setLocalTranslation(spatial.getWorldTranslation()); camNode.lookAt(target.getWorldTranslation(), upVector); target.updateLogicalState(tpf); target.updateGeometricState(); }
protected TemporalMesh getTemporalMesh(Node node) { List<Spatial> children = node.getChildren(); if (children != null && children.size() == 1 && children.get(0) instanceof TemporalMesh) { return (TemporalMesh) children.get(0); } return null; } }
@Test public void testOverrides_SaveAndLoad_KeepsMPOs() { MatParamOverride override = mpoInt("val", 5); Node scene = createDummyScene(); scene.getChild("A").addMatParamOverride(override); AssetManager assetManager = TestUtil.createAssetManager(); Node loadedScene = BinaryExporter.saveAndLoad(assetManager, scene); Node root = new Node("Root Node"); root.attachChild(loadedScene); validateScene(root); validateScene(scene); assertNotSame(override, loadedScene.getChild("A").getLocalMatParamOverrides().get(0)); assertEquals(override, loadedScene.getChild("A").getLocalMatParamOverrides().get(0)); }
private void parseNode(Attributes attribs) throws SAXException { String name = attribs.getValue("name"); if (name == null) { name = "OgreNode-" + (++nodeIdx); } com.jme3.scene.Node newNode = new com.jme3.scene.Node(name); if (node != null) { node.attachChild(newNode); } node = newNode; }
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; }