com.jme3.scene.Node Java Examples
The following examples show how to use
com.jme3.scene.Node.
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: TerrainGridAlphaMapTest.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void createMarkerPoints(float count) { Node center = createAxisMarker(10); markers.attachChild(center); float xS = (count-1)*terrain.getTerrainSize() - (terrain.getTerrainSize()/2); float zS = (count-1)*terrain.getTerrainSize() - (terrain.getTerrainSize()/2); float xSi = xS; float zSi = zS; for (int x=0; x<count*2; x++) { for (int z=0; z<count*2; z++) { Node m = createAxisMarker(5); m.setLocalTranslation(xSi, 0, zSi); markers.attachChild(m); zSi += terrain.getTerrainSize(); } zSi = zS; xSi += terrain.getTerrainSize(); } }
Example #2
Source File: WelcomeScreen.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private void setupSkyBox() { Mesh sphere = new Sphere(32, 32, 10f); sphere.setStatic(); skyBox = new Geometry("SkyBox", sphere); skyBox.setQueueBucket(Bucket.Sky); skyBox.setShadowMode(ShadowMode.Off); Image cube = SceneApplication.getApplication().getAssetManager().loadTexture("Textures/blue-glow-1024.dds").getImage(); TextureCubeMap cubemap = new TextureCubeMap(cube); Material mat = new Material(SceneApplication.getApplication().getAssetManager(), "Common/MatDefs/Misc/Sky.j3md"); mat.setBoolean("SphereMap", false); mat.setTexture("Texture", cubemap); mat.setVector3("NormalScale", new Vector3f(1, 1, 1)); skyBox.setMaterial(mat); ((Node) SceneApplication.getApplication().getViewPort().getScenes().get(0)).attachChild(skyBox); }
Example #3
Source File: SceneEditorController.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public void linkModel(final AssetManager manager, final String assetName, final Vector3f location) { if (selectedSpat == null) { return; } final Node selected = selectedSpat.getLookup().lookup(Node.class); if (selected != null) { setNeedsSave(true); SceneApplication.getApplication().enqueue(new Callable<Object>() { public Object call() throws Exception { doLinkModel(manager, assetName, selected, location); return null; } }); } else { displayInfo("Please select a Node to attach to\nin the SceneExplorer."); } }
Example #4
Source File: SlopeTerrainToolControl.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@Override @JmeThread protected void onAttached(@NotNull Node node) { super.onAttached(node); var editedModel = notNull(getPaintedModel()); var baseMarker = getBaseMarker(); var targetMarker = getTargetMarker(); var line = getLine(); var markersNode = component.getMarkersNode(); markersNode.attachChild(baseMarker); markersNode.attachChild(targetMarker); markersNode.attachChild(line); baseMarker.setLocalTranslation(editedModel.getWorldTranslation()); targetMarker.setLocalTranslation(editedModel.getWorldTranslation()); }
Example #5
Source File: BulletGhostObjectDebugControl.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Update this control. Invoked once per frame during the logical-state * update, provided the control is enabled and added to a scene. Should be * invoked only by a subclass or by AbstractControl. * * @param tpf the time interval between frames (in seconds, ≥0) */ @Override protected void controlUpdate(float tpf) { CollisionShape newShape = body.getCollisionShape(); Vector3f newScale = newShape.getScale(); if (myShape != newShape || !oldScale.equals(newScale)) { myShape = newShape; oldScale.set(newScale); Node node = (Node) spatial; node.detachChild(geom); geom = DebugShapeFactory.getDebugShape(myShape); geom.setName(body.toString()); node.attachChild(geom); } geom.setMaterial(debugAppState.DEBUG_YELLOW); body.getPhysicsLocation(location); body.getPhysicsRotation(rotation); applyPhysicsTransform(location, rotation); }
Example #6
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 #7
Source File: BillboardControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Rotate the billboard so it points directly opposite the direction the * camera's facing * * @param camera * Camera */ private void rotateScreenAligned(Camera camera) { // coopt diff for our in direction: look.set(camera.getDirection()).negateLocal(); // coopt loc for our left direction: left.set(camera.getLeft()).negateLocal(); orient.fromAxes(left, camera.getUp(), look); Node parent = spatial.getParent(); Quaternion rot=new Quaternion().fromRotationMatrix(orient); if ( parent != null ) { rot = parent.getWorldRotation().inverse().multLocal(rot); rot.normalizeLocal(); } spatial.setLocalRotation(rot); fixRefreshFlags(); }
Example #8
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 #9
Source File: TestSimpleWater.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private void initScene() { //init cam location cam.setLocation(new Vector3f(0, 10, 10)); cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y); //init scene sceneNode = new Node("Scene"); mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); Box b = new Box(1, 1, 1); Geometry geom = new Geometry("Box", b); geom.setMaterial(mat); sceneNode.attachChild(geom); // load sky sceneNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false)); rootNode.attachChild(sceneNode); //add lightPos Geometry Sphere lite=new Sphere(8, 8, 3.0f); lightSphere=new Geometry("lightsphere", lite); lightSphere.setMaterial(mat); lightSphere.setLocalTranslation(lightPos); rootNode.attachChild(lightSphere); }
Example #10
Source File: TestParallax.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public void setupFloor() { mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall2.j3m"); mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat); mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat); mat.setFloat("Shininess", 0); Node floorGeom = (Node) assetManager.loadAsset("Models/WaterTest/WaterTest.mesh.xml"); Geometry g = ((Geometry) floorGeom.getChild(0)); g.getMesh().scaleTextureCoordinates(new Vector2f(10, 10)); TangentBinormalGenerator.generate(floorGeom); floorGeom.setLocalTranslation(0, 22, 0); floorGeom.setLocalScale(100); floorGeom.setMaterial(mat); rootNode.attachChild(floorGeom); }
Example #11
Source File: ResetParticleEmittersAction.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@Override @FxThread protected void process() { super.process(); final TreeNode<?> treeNode = getNode(); final Node node = (Node) treeNode.getElement(); EXECUTOR_MANAGER.addJmeTask(() -> visitSpatial(node, ParticleEmitter.class, ParticleEmitter::killAllParticles)); ADDITIONAL_ACTIONS.forEach(node, (factory, toCheck) -> { final Runnable action = factory.apply(toCheck); if (action != null) { EXECUTOR_MANAGER.addJmeTask(action); } }); }
Example #12
Source File: GridPanel.java From Lemur with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected void refreshGrid() { if( model == null ) { getControl(GuiControl.class).getLayout().clearChildren(); return; } for( int r = row; r < row + visibleRows; r++ ) { for( int c = column; c < column + visibleColumns; c++ ) { Node existing = layout.getChild(r-row, c-column); if( r < 0 || r >= model.getRowCount() || c < 0 || c >= model.getColumnCount() ) { // Out of bounds layout.addChild(null, r-row, c-column); } else { Panel child = model.getCell(r, c, (Panel)existing); if( child != existing ) { // Make sure new children pick up the alpha of the container if( alpha != null && alpha != 1 ) { child.setAlpha(alpha); } layout.addChild(child, r-row, c-column); } } } } }
Example #13
Source File: PhysicsSpace.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Removes all physics controls and joints in the given spatial from the physics space * (e.g. before saving to disk) - recursive if node * @param spatial the rootnode containing the physics objects */ public void removeAll(Spatial spatial) { if (spatial.getControl(RigidBodyControl.class) != null) { RigidBodyControl physicsNode = spatial.getControl(RigidBodyControl.class); //remove joints with physicsNode as BodyA List<PhysicsJoint> joints = physicsNode.getJoints(); for (Iterator<PhysicsJoint> it1 = joints.iterator(); it1.hasNext();) { PhysicsJoint physicsJoint = it1.next(); if (physicsNode.equals(physicsJoint.getBodyA())) { removeJoint(physicsJoint); //remove(physicsJoint.getBodyB()); } } } remove(spatial); //recursion if (spatial instanceof Node) { List<Spatial> children = ((Node) spatial).getChildren(); for (Iterator<Spatial> it = children.iterator(); it.hasNext();) { Spatial spat = it.next(); removeAll(spat); } } }
Example #14
Source File: TestIssue877.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
Node createTestNode(float mass, Vector3f location) { float size = 0.1f; Vector3f halfExtents = new Vector3f(size, size, size); CollisionShape shape = new BoxCollisionShape(halfExtents); RigidBodyControl control = new RigidBodyControl(shape, mass); Node node = new Node(); node.addControl(control); rootNode.attachChild(node); bulletAppState.getPhysicsSpace().add(node); control.setPhysicsLocation(location); return node; }
Example #15
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 #16
Source File: TerrainUtils.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Re-attach the camera to the LOD control. * Called when the scene is opened and will only * update the control if there is already a terrain present in * the scene. */ public static void enableLodControl(Camera camera, Node rootNode) { Terrain terrain = (Terrain) findTerrain(rootNode); if (terrain == null) return; TerrainLodControl control = ((Spatial)terrain).getControl(TerrainLodControl.class); if (control != null) { control.setCamera(camera); } }
Example #17
Source File: PointUtil.java From OpenRTS with MIT License | 5 votes |
private static CollisionResult getCollision(Node n, Ray r) { CollisionResults results = new CollisionResults(); n.collideWith(r, results); if (results.size() == 0) { return null; } return results.getClosestCollision(); }
Example #18
Source File: ActorDrawer.java From OpenRTS with MIT License | 5 votes |
public void setEmmitersEnable(Spatial s, boolean val) { if (s instanceof ParticleEmitter) { ((ParticleEmitter) s).setEnabled(!val); } if (s instanceof Node) { for (Spatial child : ((Node) s).getChildren()) { setEmmitersEnable(child, val); } } }
Example #19
Source File: TerrainQuad.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * used by attachBoundChildren() */ private void attachBoundingBox(BoundingBox bb, Node parent) { WireBox wb = new WireBox(bb.getXExtent(), bb.getYExtent(), bb.getZExtent()); Geometry g = new Geometry(); g.setMesh(wb); g.setLocalTranslation(bb.getCenter()); parent.attachChild(g); }
Example #20
Source File: AdvancedAbstractEditor3DPart.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Move a camera to direction. * * @param value the value to move. */ @JmeThread private void moveDirectionCamera(final float value, final boolean isAction, final boolean isPressed, final int key) { if (!canCameraMove()) { return; } else if (isAction && isPressed) { startCameraMoving(key); } else if (isAction) { finishCameraMoving(key, false); } if (!isCameraMoving() || isAction) { return; } final EditorCamera editorCamera = getEditorCamera(); if (editorCamera == null) { return; } final Camera camera = EditorUtil.getGlobalCamera(); final Node nodeForCamera = getNodeForCamera(); final LocalObjects local = LocalObjects.get(); final Vector3f direction = camera.getDirection(local.nextVector()); direction.multLocal(value * cameraSpeed); direction.addLocal(nodeForCamera.getLocalTranslation()); nodeForCamera.setLocalTranslation(direction); }
Example #21
Source File: SceneEditTool.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
protected Vector3f pickWorldLocation(Camera cam, Vector2f mouseLoc, Node rootNode) { CollisionResult cr = pick(cam, mouseLoc, rootNode); if (cr != null) { return cr.getContactPoint(); } else { return null; } }
Example #22
Source File: BasicProfilerState.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void onEnable() { // Set the number of visible frames to the current width of the screen setFrameCount(getApplication().getCamera().getWidth()); getApplication().setAppProfiler(profiler); Node gui = ((SimpleApplication)getApplication()).getGuiNode(); gui.attachChild(graph); gui.attachChild(background); }
Example #23
Source File: BulletDebugAppState.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void updateRigidBodies() { HashMap<PhysicsRigidBody, Spatial> oldObjects = bodies; bodies = new HashMap<PhysicsRigidBody, Spatial>(); Collection<PhysicsRigidBody> current = space.getRigidBodyList(); //create new map for (Iterator<PhysicsRigidBody> it = current.iterator(); it.hasNext();) { PhysicsRigidBody physicsObject = it.next(); //copy existing spatials if (oldObjects.containsKey(physicsObject)) { Spatial spat = oldObjects.get(physicsObject); bodies.put(physicsObject, spat); oldObjects.remove(physicsObject); } else { if (filter == null || filter.displayObject(physicsObject)) { logger.log(Level.FINE, "Create new debug RigidBody"); //create new spatial Node node = new Node(physicsObject.toString()); node.addControl(new BulletRigidBodyDebugControl(this, physicsObject)); bodies.put(physicsObject, node); physicsDebugRootNode.attachChild(node); } } } //remove leftover spatials for (Map.Entry<PhysicsRigidBody, Spatial> entry : oldObjects.entrySet()) { PhysicsRigidBody object = entry.getKey(); Spatial spatial = entry.getValue(); spatial.removeFromParent(); } }
Example #24
Source File: TestGhostObject.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
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); }
Example #25
Source File: AdvancedPbrWithStudioSky3DEditorPart.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
public AdvancedPbrWithStudioSky3DEditorPart(@NotNull final T fileEditor) { super(fileEditor); final AssetManager assetManager = EditorUtil.getAssetManager(); final Geometry sky = (Geometry) SkyFactory.createSky(assetManager, "graphics/textures/sky/studio.hdr", SkyFactory.EnvMapType.EquirectMap); final Node stateNode = getStateNode(); stateNode.attachChild(sky); }
Example #26
Source File: TestRagDoll.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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; }
Example #27
Source File: TerrainQuad.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void setParent(Node parent) { super.setParent(parent); if (parent == null) { // if the terrain is being detached clearCaches(); } }
Example #28
Source File: TestOgreConvert.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void simpleInitApp() { Spatial ogreModel = assetManager.loadModel("Models/Oto/Oto.mesh.xml"); DirectionalLight dl = new DirectionalLight(); dl.setColor(ColorRGBA.White); dl.setDirection(new Vector3f(0,-1,-1).normalizeLocal()); rootNode.addLight(dl); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BinaryExporter exp = new BinaryExporter(); exp.save(ogreModel, baos); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); BinaryImporter imp = new BinaryImporter(); imp.setAssetManager(assetManager); Node ogreModelReloaded = (Node) imp.load(bais, null, null); AnimControl control = ogreModelReloaded.getControl(AnimControl.class); AnimChannel chan = control.createChannel(); chan.setAnim("Walk"); rootNode.attachChild(ogreModelReloaded); } catch (IOException ex){ ex.printStackTrace(); } }
Example #29
Source File: JmeFilePreviewManager.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Prepare a transfer processor to transfer preview result to a image view. * * @return the transfer processor. */ @JmeThread private @NotNull FrameTransferSceneProcessor prepareScene() { var jmeApplication = JmeApplication.getInstance(); var assetManager = jmeApplication.getAssetManager(); var sky = SkyFactory.createSky(assetManager, "graphics/textures/sky/studio.hdr", SkyFactory.EnvMapType.EquirectMap); var light = new DirectionalLight(); light.setDirection(LIGHT_DIRECTION); var cameraNode = new Node("Camera node"); var rootNode = jmeApplication.getPreviewNode(); rootNode.addControl(this); rootNode.attachChild(sky); rootNode.addLight(light); rootNode.attachChild(cameraNode); rootNode.attachChild(modelNode); var camera = jmeApplication.getPreviewCamera(); var editorCamera = new EditorCamera(camera, cameraNode); editorCamera.setMaxDistance(10000); editorCamera.setMinDistance(0.01F); editorCamera.setSmoothMotion(false); editorCamera.setRotationSensitivity(1); editorCamera.setZoomSensitivity(0.2F); //TODO added supporting moving the camera processor = bind(jmeApplication, imageView, imageView, jmeApplication.getPreviewViewPort(), false); processor.setTransferMode(ON_CHANGES); processor.setEnabled(false); return processor; }
Example #30
Source File: TestPhysicsCharacter.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void simpleInitApp() { // activate physics bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); // init a physical test scene PhysicsTestHelper.createPhysicsTestWorldSoccer(rootNode, assetManager, bulletAppState.getPhysicsSpace()); setupKeys(); // Add a physics character to the world physicsCharacter = new CharacterControl(new CapsuleCollisionShape(0.5f, 1.8f), .1f); physicsCharacter.setPhysicsLocation(new Vector3f(0, 1, 0)); characterNode = new Node("character node"); Spatial model = assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml"); model.scale(0.25f); characterNode.addControl(physicsCharacter); getPhysicsSpace().add(physicsCharacter); rootNode.attachChild(characterNode); characterNode.attachChild(model); // set forward camera node that follows the character camNode = new CameraNode("CamNode", cam); camNode.setControlDir(ControlDirection.SpatialToCamera); camNode.setLocalTranslation(new Vector3f(0, 1, -5)); camNode.lookAt(model.getLocalTranslation(), Vector3f.UNIT_Y); characterNode.attachChild(camNode); //disable the default 1st-person flyCam (don't forget this!!) flyCam.setEnabled(false); }