public void displayNonDeformingJoint(boolean display) { joints.getChild(0).setCullHint(display ? CullHint.Dynamic : CullHint.Always); outlines.getChild(0).setCullHint(display ? CullHint.Dynamic : CullHint.Always); wires.getChild(0).setCullHint(display ? CullHint.Dynamic : CullHint.Always); ((Node) outlines.getChild(1)).getChild(0).setCullHint(display ? CullHint.Dynamic : CullHint.Always); ((Node) wires.getChild(1)).getChild(0).setCullHint(display ? CullHint.Dynamic : CullHint.Always); }
public void run() { try { Thread.sleep(1000); } catch (InterruptedException ex) { } // begin randomly changing textures after 1 sec. while (true) { for (Spatial child : rootNode.getChildren()) { Geometry g = (Geometry) (((Node)child).getChild(0)); Material m = g.getMaterial(); Texture curTex = m.getTextureParam("ColorMap").getTextureValue(); if (curTex == t1) { m.setTexture("ColorMap", t2); } else { m.setTexture("ColorMap", t1); } } } } });
/** * This method finds a node of a given name. * @param rootNode the root node to search * @param name the name of the searched node * @return the found node or null */ private Spatial findNode(Node rootNode, String name) { if (name.equals(rootNode.getName())) { return rootNode; } return rootNode.getChild(name); } }
/** * This method finds a node of a given name. * @param rootNode the root node to search * @param name the name of the searched node * @return the found node or null */ private Spatial findNode(Node rootNode, String name) { if (name.equals(rootNode.getName())) { return rootNode; } return rootNode.getChild(name); } }
public void simpleInitApp() { Node scene = (Node) assetManager.loadModel("Scenes/DotScene/DotScene.scene"); System.out.println("Scene: " + scene); Spatial testNode = scene.getChild("TestNode"); System.out.println("TestNode: "+ testNode); for (String key : testNode.getUserDataKeys()){ System.out.println("Property " + key + " = " + testNode.getUserData(key)); } } }
private void attach(Node parent, boolean deforms, Geometry geom) { if (deforms) { parent.attachChild(geom); } else { ((Node) parent.getChild(0)).attachChild(geom); } }
@Override public void done(LightProbe result) { System.err.println("Done rendering env maps"); tex = EnvMapUtils.getCubeMapCrossDebugViewWithMipMaps(result.getPrefilteredEnvMap(), assetManager); rootNode.getChild(0).setCullHint(Spatial.CullHint.Dynamic); } });
/** * <code>getChild</code> returns the first child found with exactly the * given name (case sensitive.) This method does a depth first recursive * search of all descendants of this node, it will return the first spatial * found with a matching name. * * @param name * the name of the child to retrieve. If null, we'll return null. * @return the child if found, or null. */ public Spatial getChild(String name) { if (name == null) return null; for (Spatial child : children.getArray()) { if (name.equals(child.getName())) { return child; } else if(child instanceof Node) { Spatial out = ((Node)child).getChild(name); if(out != null) { return out; } } } return null; } /**
private Geometry findGeom(Spatial spatial, String name) { if (spatial instanceof Node) { Node node = (Node) spatial; for (int i = 0; i < node.getQuantity(); i++) { Spatial child = node.getChild(i); Geometry result = findGeom(child, name); if (result != null) { return result; } } } else if (spatial instanceof Geometry) { if (spatial.getName().startsWith(name)) { return (Geometry) spatial; } } return null; }
/** * Computes this Spatial's world bounding volume in the most efficient * manner possible. */ void checkDoBoundUpdate() { if ((refreshFlags & RF_BOUND) == 0) { return; } checkDoTransformUpdate(); // Go to children recursively and update their bound if (this instanceof Node) { Node node = (Node) this; int len = node.getQuantity(); for (int i = 0; i < len; i++) { Spatial child = node.getChild(i); child.checkDoBoundUpdate(); } } // All children's bounds have been updated. Update my own now. updateWorldBound(); }
@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");
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); }
@Test public void testOverrides_CloningScene_DoesntCloneMPO() { Node originalScene = createDummyScene(); originalScene.getChild("A").addMatParamOverride(mpoInt("int", 5)); originalScene.getChild("A").addMatParamOverride(mpoBool("bool", true)); originalScene.getChild("A").addMatParamOverride(mpoFloat("float", 3.12f)); Node clonedScene = originalScene.clone(false); validateScene(clonedScene); validateScene(originalScene); List<MatParamOverride> clonedOverrides = clonedScene.getChild("A").getLocalMatParamOverrides(); List<MatParamOverride> originalOverrides = originalScene.getChild("A").getLocalMatParamOverrides(); assertNotSame(clonedOverrides, originalOverrides); assertEquals(clonedOverrides, originalOverrides); for (int i = 0; i < clonedOverrides.size(); i++) { assertNotSame(clonedOverrides.get(i), originalOverrides.get(i)); assertEquals(clonedOverrides.get(i), originalOverrides.get(i)); } }
@Test public void testOverrides_RemoveAfterAttach() { Node scene = createDummyScene(); scene.updateGeometricState(); Node root = new Node("Root Node"); root.updateGeometricState(); scene.getChild("A").addMatParamOverride(mpoInt("val", 5)); root.attachChild(scene); validateScene(root); scene.getChild("A").clearMatParamOverrides(); validateScene(root); }
@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)); }
@Test public void testOverrides_RemoveBeforeAttach() { Node scene = createDummyScene(); scene.updateGeometricState(); Node root = new Node("Root Node"); root.updateGeometricState(); scene.getChild("A").addMatParamOverride(mpoInt("val", 5)); validateScene(scene); scene.getChild("A").clearMatParamOverrides(); validateScene(scene); root.attachChild(scene); validateScene(root); }
public void initialize(AssetManager assetManager, Camera camera) { armatureNode.setCamera(camera); Material matJoints = new Material(assetManager, "Common/MatDefs/Misc/Billboard.j3md"); Texture t = assetManager.loadTexture("Common/Textures/dot.png"); matJoints.setTexture("Texture", t); matJoints.getAdditionalRenderState().setDepthTest(false); matJoints.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha); joints.setQueueBucket(RenderQueue.Bucket.Translucent); joints.setMaterial(matJoints); Material matWires = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); matWires.setBoolean("VertexColor", true); matWires.getAdditionalRenderState().setLineWidth(3); wires.setMaterial(matWires); Material matOutline = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); matOutline.setBoolean("VertexColor", true); matOutline.getAdditionalRenderState().setLineWidth(5); outlines.setMaterial(matOutline); Material matOutline2 = new Material(assetManager, "Common/MatDefs/Misc/DashedLine.j3md"); matOutline2.getAdditionalRenderState().setLineWidth(1); outlines.getChild(1).setMaterial(matOutline2); Material matWires2 = new Material(assetManager, "Common/MatDefs/Misc/DashedLine.j3md"); matWires2.getAdditionalRenderState().setLineWidth(1); wires.getChild(1).setMaterial(matWires2); }
@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); }
@Test public void testOverrides_AddBeforeAttach() { Node scene = createDummyScene(); scene.getChild("A").addMatParamOverride(mpoInt("val", 5)); scene.updateGeometricState(); Node root = new Node("Root Node"); root.updateGeometricState(); root.attachChild(scene); validateScene(root); }