Java Code Examples for com.jme3.scene.Node#getChildren()
The following examples show how to use
com.jme3.scene.Node#getChildren() .
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: Octree.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private static List<Geometry> getGeometries(Spatial scene){ if (scene instanceof Geometry){ List<Geometry> geomList = new ArrayList<Geometry>(1); geomList.add((Geometry) scene); return geomList; }else if (scene instanceof Node){ Node n = (Node) scene; List<Geometry> geoms = new ArrayList<Geometry>(); for (Spatial child : n.getChildren()){ geoms.addAll(getGeometries(child)); } return geoms; }else{ throw new UnsupportedOperationException("Unsupported scene element class"); } }
Example 2
Source File: TestCartoonEdge.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void makeToonish(Spatial spatial){ if (spatial instanceof Node){ Node n = (Node) spatial; for (Spatial child : n.getChildren()) makeToonish(child); }else if (spatial instanceof Geometry){ Geometry g = (Geometry) spatial; Material m = g.getMaterial(); if (m.getMaterialDef().getMaterialParam("UseMaterialColors") != null) { Texture t = assetManager.loadTexture("Textures/ColorRamp/toon.png"); // t.setMinFilter(Texture.MinFilter.NearestNoMipMaps); // t.setMagFilter(Texture.MagFilter.Nearest); m.setTexture("ColorRamp", t); m.setBoolean("UseMaterialColors", true); m.setColor("Specular", ColorRGBA.Black); m.setColor("Diffuse", ColorRGBA.White); m.setBoolean("VertexLighting", true); } } }
Example 3
Source File: SilentTangentBinormalGenerator.java From OpenRTS with MIT License | 6 votes |
public static void generate(Spatial scene, boolean splitMirrored) { if (scene instanceof Node) { Node node = (Node) scene; for (Spatial child : node.getChildren()) { generate(child, splitMirrored); } } else { Geometry geom = (Geometry) scene; Mesh mesh = geom.getMesh(); // Check to ensure mesh has texcoords and normals before generating if (mesh.getBuffer(Type.TexCoord) != null && mesh.getBuffer(Type.Normal) != null) { generate(geom.getMesh(), true, splitMirrored); } } }
Example 4
Source File: AbstractTerrainToolAction.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
protected Terrain getTerrain(Spatial root) { // is this the terrain? if (root instanceof Terrain && root instanceof Node) { return (Terrain)root; } if (root instanceof Node) { Node n = (Node) root; for (Spatial c : n.getChildren()) { if (c instanceof Node){ Terrain res = getTerrain(c); if (res != null) return res; } } } return null; }
Example 5
Source File: TerrainUtils.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
protected static Node findTerrain(Spatial root) { // is this the terrain? if (root instanceof Terrain && root instanceof Node) { return (Node)root; } if (root instanceof Node) { Node n = (Node) root; for (Spatial c : n.getChildren()) { if (c instanceof Node){ Node res = findTerrain(c); if (res != null) return res; } } } return null; }
Example 6
Source File: TestIssue931.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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(); }
Example 7
Source File: TestCartoonEdge.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public void makeToonish(Spatial spatial){ if (spatial instanceof Node){ Node n = (Node) spatial; for (Spatial child : n.getChildren()) makeToonish(child); }else if (spatial instanceof Geometry){ Geometry g = (Geometry) spatial; Material m = g.getMaterial(); if (m.getMaterialDef().getName().equals("Phong Lighting")){ Texture t = assetManager.loadTexture("Textures/ColorRamp/toon.png"); // t.setMinFilter(Texture.MinFilter.NearestNoMipMaps); // t.setMagFilter(Texture.MagFilter.Nearest); m.setTexture("ColorRamp", t); m.setBoolean("UseMaterialColors", true); m.setColor("Specular", ColorRGBA.Black); m.setColor("Diffuse", ColorRGBA.White); m.setBoolean("VertexLighting", true); } } }
Example 8
Source File: RenderManager.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * If a spatial is not inside the eye frustum, it * is still rendered in the shadow frustum (shadow casting queue) * through this recursive method. */ private void renderShadow(Spatial s, RenderQueue rq) { if (s instanceof Node) { Node n = (Node) s; List<Spatial> children = n.getChildren(); for (int i = 0; i < children.size(); i++) { renderShadow(children.get(i), rq); } } else if (s instanceof Geometry) { Geometry gm = (Geometry) s; RenderQueue.ShadowMode shadowMode = s.getShadowMode(); if (shadowMode != RenderQueue.ShadowMode.Off && shadowMode != RenderQueue.ShadowMode.Receive) { //forcing adding to shadow cast mode, culled objects doesn't have to be in the receiver queue rq.addToShadowQueue(gm, RenderQueue.ShadowMode.Cast); } } }
Example 9
Source File: GeometryBatchFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private static void gatherGeoms(Spatial scene, List<Geometry> geoms) { if (scene instanceof Node) { Node node = (Node) scene; for (Spatial child : node.getChildren()) { gatherGeoms(child, geoms); } } else if (scene instanceof Geometry) { geoms.add((Geometry) scene); } }
Example 10
Source File: TranslucentBucketFilter.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private void makeSoftParticleEmitter(Spatial scene, boolean enabled) { if (scene instanceof Node) { Node n = (Node) scene; for (Spatial child : n.getChildren()) { makeSoftParticleEmitter(child, enabled); } } if (scene instanceof ParticleEmitter) { ParticleEmitter emitter = (ParticleEmitter) scene; if (enabled) { enabledSoftParticles = enabled; if( processor.getNumSamples()>1){ emitter.getMaterial().selectTechnique("SoftParticles15", renderManager); emitter.getMaterial().setInt("NumSamplesDepth", processor.getNumSamples()); }else{ emitter.getMaterial().selectTechnique("SoftParticles", renderManager); } emitter.getMaterial().setTexture("DepthTexture", processor.getDepthTexture()); emitter.setQueueBucket(RenderQueue.Bucket.Translucent); logger.log(Level.FINE, "Made particle Emitter {0} soft.", emitter.getName()); } else { emitter.getMaterial().clearParam("DepthTexture"); emitter.getMaterial().selectTechnique("Default", renderManager); // emitter.setQueueBucket(RenderQueue.Bucket.Transparent); logger.log(Level.FINE, "Particle Emitter {0} is not soft anymore.", emitter.getName()); } } }
Example 11
Source File: WaterFilter.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private DirectionalLight findLight(Node node) { for (Light light : node.getWorldLightList()) { if (light instanceof DirectionalLight) { return (DirectionalLight) light; } } for (Spatial child : node.getChildren()) { if (child instanceof Node) { return findLight((Node) child); } } return null; }
Example 12
Source File: GltfLoaderTest.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void dumpScene(Spatial s, int indent) { System.err.println(indentString.substring(0, indent) + s.getName() + " (" + s.getClass().getSimpleName() + ") / " + s.getLocalTransform().getTranslation().toString() + ", " + s.getLocalTransform().getRotation().toString() + ", " + s.getLocalTransform().getScale().toString()); if (s instanceof Node) { Node n = (Node) s; for (Spatial spatial : n.getChildren()) { dumpScene(spatial, indent + 1); } } }
Example 13
Source File: RagUtils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Enumerate all animated meshes in the specified subtree of a scene graph. * Note: recursive! * * @param subtree which subtree (aliases created) * @param storeResult (added to if not null) * @return an expanded list (either storeResult or a new instance) */ static List<Mesh> listAnimatedMeshes(Spatial subtree, List<Mesh> storeResult) { if (storeResult == null) { storeResult = new ArrayList<>(10); } if (subtree instanceof Geometry) { Geometry geometry = (Geometry) subtree; Mesh mesh = geometry.getMesh(); VertexBuffer indices = mesh.getBuffer(VertexBuffer.Type.BoneIndex); boolean hasIndices = indices != null; VertexBuffer weights = mesh.getBuffer(VertexBuffer.Type.BoneWeight); boolean hasWeights = weights != null; if (hasIndices && hasWeights && !storeResult.contains(mesh)) { storeResult.add(mesh); } } else if (subtree instanceof Node) { Node node = (Node) subtree; List<Spatial> children = node.getChildren(); for (Spatial child : children) { listAnimatedMeshes(child, storeResult); } } return storeResult; }
Example 14
Source File: RagUtils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Find an animated geometry in the specified subtree of the scene graph. * Note: recursive! * * @param subtree where to search (not null, unaffected) * @return a pre-existing instance, or null if none */ static Geometry findAnimatedGeometry(Spatial subtree) { Geometry result = null; if (subtree instanceof Geometry) { Geometry geometry = (Geometry) subtree; Mesh mesh = geometry.getMesh(); VertexBuffer indices = mesh.getBuffer(VertexBuffer.Type.BoneIndex); boolean hasIndices = indices != null; VertexBuffer weights = mesh.getBuffer(VertexBuffer.Type.BoneWeight); boolean hasWeights = weights != null; if (hasIndices && hasWeights) { result = geometry; } } else if (subtree instanceof Node) { Node node = (Node) subtree; List<Spatial> children = node.getChildren(); for (Spatial child : children) { result = findAnimatedGeometry(child); if (result != null) { break; } } } return result; }
Example 15
Source File: TestAnimSerialization.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void setupModel(Spatial model) { if (composer != null) { return; } composer = model.getControl(AnimComposer.class); if (composer != null) { SkinningControl sc = model.getControl(SkinningControl.class); debugAppState.addArmatureFrom(sc); anims.clear(); for (String name : composer.getAnimClipsNames()) { anims.add(name); } if (anims.isEmpty()) { return; } if (playAnim) { String anim = anims.poll(); anims.add(anim); composer.setCurrentAction(anim); System.err.println(anim); } } else { if (model instanceof Node) { Node n = (Node) model; for (Spatial child : n.getChildren()) { setupModel(child); } } } }
Example 16
Source File: TestEnvironmentMapping.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleInitApp() { final Node buggy = (Node) assetManager.loadModel("Models/Buggy/Buggy.j3o"); TextureKey key = new TextureKey("Textures/Sky/Bright/BrightSky.dds", true); key.setGenerateMips(true); key.setTextureTypeHint(Texture.Type.CubeMap); final Texture tex = assetManager.loadTexture(key); for (Spatial geom : buggy.getChildren()) { if (geom instanceof Geometry) { Material m = ((Geometry) geom).getMaterial(); m.setTexture("EnvMap", tex); m.setVector3("FresnelParams", new Vector3f(0.05f, 0.18f, 0.11f)); } } flyCam.setEnabled(false); ChaseCamera chaseCam = new ChaseCamera(cam, inputManager); chaseCam.setLookAtOffset(new Vector3f(0,0.5f,-1.0f)); buggy.addControl(chaseCam); rootNode.attachChild(buggy); rootNode.attachChild(SkyFactory.createSky(assetManager, tex, SkyFactory.EnvMapType.CubeMap)); FilterPostProcessor fpp = new FilterPostProcessor(assetManager); BloomFilter bf = new BloomFilter(BloomFilter.GlowMode.Objects); bf.setBloomIntensity(2.3f); bf.setExposurePower(0.6f); fpp.addFilter(bf); DirectionalLight l = new DirectionalLight(); l.setDirection(new Vector3f(0, -1, -1)); rootNode.addLight(l); viewPort.addProcessor(fpp); }
Example 17
Source File: TangentBinormalGenerator.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public static void generate(Spatial scene){ if (scene instanceof Node){ Node node = (Node) scene; for (Spatial child : node.getChildren()){ generate(child); } }else{ Geometry geom = (Geometry) scene; generate(geom.getMesh()); } }
Example 18
Source File: TestAnimMigration.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void setupModel(Spatial model) { if (composer != null) { return; } composer = model.getControl(AnimComposer.class); if (composer != null) { SkinningControl sc = model.getControl(SkinningControl.class); debugAppState.addArmatureFrom(sc); anims.clear(); for (String name : composer.getAnimClipsNames()) { anims.add(name); } composer.actionSequence("Sequence1", composer.makeAction("Walk"), composer.makeAction("Run"), composer.makeAction("Jumping")).setSpeed(1); composer.actionSequence("Sequence2", composer.makeAction("Walk"), composer.makeAction("Run"), composer.makeAction("Jumping")).setSpeed(-1); action = composer.actionBlended("Blend", new LinearBlendSpace(1, 4), "Walk", "Run"); action.getBlendSpace().setValue(1); composer.action("Walk").setSpeed(-1); composer.makeLayer("LeftArm", ArmatureMask.createMask(sc.getArmature(), "shoulder.L")); anims.addFirst("Blend"); anims.addFirst("Sequence2"); anims.addFirst("Sequence1"); if (anims.isEmpty()) { return; } if (playAnim) { String anim = anims.poll(); anims.add(anim); composer.setCurrentAction(anim); System.err.println(anim); } } else { if (model instanceof Node) { Node n = (Node) model; for (Spatial child : n.getChildren()) { setupModel(child); } } } }
Example 19
Source File: RenderManager.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Flattens the given scene graph into the ViewPort's RenderQueue, * checking for culling as the call goes down the graph recursively. * <p> * First, the scene is checked for culling based on the <code>Spatial</code>s * {@link Spatial#setCullHint(com.jme3.scene.Spatial.CullHint) cull hint}, * if the camera frustum contains the scene, then this method is recursively * called on its children. * <p> * When the scene's leaves or {@link Geometry geometries} are reached, * they are each enqueued into the * {@link ViewPort#getQueue() ViewPort's render queue}. * <p> * In addition to enqueuing the visible geometries, this method * also scenes which cast or receive shadows, by putting them into the * RenderQueue's * {@link RenderQueue#addToShadowQueue(com.jme3.scene.Geometry, com.jme3.renderer.queue.RenderQueue.ShadowMode) * shadow queue}. Each Spatial which has its * {@link Spatial#setShadowMode(com.jme3.renderer.queue.RenderQueue.ShadowMode) shadow mode} * set to not off, will be put into the appropriate shadow queue, note that * this process does not check for frustum culling on any * {@link ShadowMode#Cast shadow casters}, as they don't have to be * in the eye camera frustum to cast shadows on objects that are inside it. * * @param scene The scene to flatten into the queue * @param vp The ViewPort provides the {@link ViewPort#getCamera() camera} * used for culling and the {@link ViewPort#getQueue() queue} used to * contain the flattened scene graph. */ public void renderScene(Spatial scene, ViewPort vp) { if (scene.getParent() == null) { vp.getCamera().setPlaneState(0); } // check culling first. if (!scene.checkCulling(vp.getCamera())) { // move on to shadow-only render if ((scene.getShadowMode() != RenderQueue.ShadowMode.Off || scene instanceof Node) && scene.getCullHint()!=Spatial.CullHint.Always) { renderShadow(scene, vp.getQueue()); } return; } scene.runControlRender(this, vp); if (scene instanceof Node) { // recurse for all children Node n = (Node) scene; List<Spatial> children = n.getChildren(); //saving cam state for culling int camState = vp.getCamera().getPlaneState(); for (int i = 0; i < children.size(); i++) { //restoring cam state before proceeding children recusively vp.getCamera().setPlaneState(camState); renderScene(children.get(i), vp); } } else if (scene instanceof Geometry) { // add to the render queue Geometry gm = (Geometry) scene; if (gm.getMaterial() == null) { throw new IllegalStateException("No material is set for Geometry: " + gm.getName()); } vp.getQueue().addToQueue(gm, scene.getQueueBucket()); // add to shadow queue if needed RenderQueue.ShadowMode shadowMode = scene.getShadowMode(); if (shadowMode != RenderQueue.ShadowMode.Off) { vp.getQueue().addToShadowQueue(gm, shadowMode); } } }
Example 20
Source File: NodeTreeNode.java From jmonkeybuilder with Apache License 2.0 | 4 votes |
/** * Get the children spatial. * * @return the children spatial. */ @FxThread protected @NotNull List<Spatial> getSpatialChildren() { final Node element = getElement(); return element.getChildren(); }