Java Code Examples for com.jme3.scene.Node#attachChild()
The following examples show how to use
com.jme3.scene.Node#attachChild() .
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: MapDrawer.java From OpenRTS with MIT License | 6 votes |
private void attachNaturalCliff(Cliff c) { Node n = new Node(); tilesSpatial.get(c.getTile()).add(n); castAndReceiveNode.attachChild(n); NaturalFace face = (NaturalFace) (c.face); Geometry g = new Geometry(); g.setMesh(TranslateUtil.toJMEMesh(face.mesh)); if (face.color != null) { g.setMaterial(MaterialManager.getLightingColor(TranslateUtil.toColorRGBA(face.color))); } else { g.setMaterial(MaterialManager.getLightingTexture(face.texturePath)); } // g.setMaterial(mm.getLightingTexture("textures/road.jpg")); g.rotate(0, 0, (float) (c.angle)); g.setLocalTranslation((float)c.getTile().getCoord().x + 0.5f, (float)c.getTile().getCoord().y + 0.5f, (float) (c.level * Tile.STAGE_HEIGHT)); n.attachChild(g); }
Example 2
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 3
Source File: AdvancedAbstractEditor3DPart.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@Override @JmeThread public void initialize(@NotNull final AppStateManager stateManager, @NotNull final Application application) { super.initialize(stateManager, application); this.stateManager = stateManager; final Node rootNode = EditorUtil.getGlobalRootNode(); rootNode.attachChild(getStateNode()); final RenderFilterExtension filterExtension = RenderFilterExtension.getInstance(); filterExtension.enableFilters(); final EditorCamera editorCamera = getEditorCamera(); final InputManager inputManager = EditorUtil.getInputManager(); checkAndAddMappings(inputManager); registerActionListener(inputManager); registerAnalogListener(inputManager); if (editorCamera != null) { editorCamera.setEnabled(true); editorCamera.registerInput(inputManager); } }
Example 4
Source File: ModelEditor3DPart.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
/** * The process of changing the fast sky. */ @JmeThread private void changeFastSkyImpl(@Nullable final Spatial fastSky) { final Node stateNode = getStateNode(); final Spatial currentFastSky = getCurrentFastSky(); if (currentFastSky != null) { stateNode.detachChild(currentFastSky); } if (fastSky != null) { stateNode.attachChild(fastSky); } stateNode.detachChild(getModelNode()); stateNode.detachChild(getToolNode()); setCurrentFastSky(fastSky); frame = 0; }
Example 5
Source File: CubeField.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private Node createPlayer() { Dome b = new Dome(Vector3f.ZERO, 10, 100, 1); Geometry playerMesh = new Geometry("Box", b); playerMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); playerMaterial.setColor("Color", ColorRGBA.Red); playerMesh.setMaterial(playerMaterial); playerMesh.setName("player"); Box floor = new Box(Vector3f.ZERO.add(playerMesh.getLocalTranslation().getX(), playerMesh.getLocalTranslation().getY() - 1, 0), 100, 0, 100); Geometry floorMesh = new Geometry("Box", floor); floorMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); floorMaterial.setColor("Color", ColorRGBA.LightGray); floorMesh.setMaterial(floorMaterial); floorMesh.setName("floor"); Node playerNode = new Node(); playerNode.attachChild(playerMesh); playerNode.attachChild(floorMesh); return playerNode; }
Example 6
Source File: TestSceneStress.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected Spatial createOctSplit( String name, int size, int depth ) { if( depth == 0 ) { // Done splitting Geometry geom = new Geometry(name, BOX); totalGeometry++; geom.setMaterial(mat); if( random.nextFloat() < 0.01 ) { RotatorControl control = new RotatorControl(random.nextFloat(), random.nextFloat(), random.nextFloat()); geom.addControl(control); totalControls++; } return geom; } Node root = new Node(name); totalNodes++; int half = size / 2; float quarter = half * 0.5f; for( int i = 0; i < 2; i++ ) { float x = i * half - quarter; for( int j = 0; j < 2; j++ ) { float y = j * half - quarter; for( int k = 0; k < 2; k++ ) { float z = k * half - quarter; Spatial child = createOctSplit(name + "(" + i + ", " + j + ", " + k + ")", half, depth - 1); child.setLocalTranslation(x, y, z); root.attachChild(child); } } } return root; }
Example 7
Source File: TestSaveGame.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleInitApp() { //node that is used to store player data Node myPlayer = new Node(); myPlayer.setName("PlayerNode"); myPlayer.setUserData("name", "Mario"); myPlayer.setUserData("health", 100.0f); myPlayer.setUserData("points", 0); //the actual model would be attached to this node Spatial model = assetManager.loadModel("Models/Oto/Oto.mesh.xml"); myPlayer.attachChild(model); //before saving the game, the model should be detached so it's not saved along with the node myPlayer.detachAllChildren(); SaveGame.saveGame("mycompany/mygame", "savegame_001", myPlayer); //later the game is loaded again Node player = (Node) SaveGame.loadGame("mycompany/mygame", "savegame_001"); player.attachChild(model); rootNode.attachChild(player); //and the data is available System.out.println("Name: " + player.getUserData("name")); System.out.println("Health: " + player.getUserData("health")); System.out.println("Points: " + player.getUserData("points")); AmbientLight al = new AmbientLight(); rootNode.addLight(al); //note you can also implement your own classes that implement the Savable interface. }
Example 8
Source File: DebugShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Creates a debug shape from the given collision shape. This is mostly used internally.<br> * To attach a debug shape to a physics object, call <code>attachDebugShape(AssetManager manager);</code> on it. * @param collisionShape * @return */ public static Spatial getDebugShape(CollisionShape collisionShape) { if (collisionShape == null) { return null; } Spatial debugShape; if (collisionShape instanceof CompoundCollisionShape) { CompoundCollisionShape shape = (CompoundCollisionShape) collisionShape; List<ChildCollisionShape> children = shape.getChildren(); Node node = new Node("DebugShapeNode"); for (Iterator<ChildCollisionShape> it = children.iterator(); it.hasNext();) { ChildCollisionShape childCollisionShape = it.next(); CollisionShape ccollisionShape = childCollisionShape.shape; Geometry geometry = createDebugShape(ccollisionShape); // apply translation geometry.setLocalTranslation(childCollisionShape.location); // apply rotation TempVars vars = TempVars.get(); Matrix3f tempRot = vars.tempMat3; tempRot.set(geometry.getLocalRotation()); childCollisionShape.rotation.mult(tempRot, tempRot); geometry.setLocalRotation(tempRot); vars.release(); node.attachChild(geometry); } debugShape = node; } else { debugShape = createDebugShape(collisionShape); } if (debugShape == null) { return null; } debugShape.updateGeometricState(); return debugShape; }
Example 9
Source File: BoxLayout.java From Lemur with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void attach( GuiControl parent ) { this.parent = parent; Node self = parent.getNode(); for( Node n : children ) { self.attachChild(n); } }
Example 10
Source File: ModelEditor3DPart.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Activate the node with models. */ @JmeThread private void notifyProbeComplete() { final Node stateNode = getStateNode(); stateNode.attachChild(getModelNode()); stateNode.attachChild(getToolNode()); final Node customSkyNode = getCustomSkyNode(); customSkyNode.detachAllChildren(); final RenderFilterExtension filterExtension = RenderFilterExtension.getInstance(); filterExtension.refreshFilters(); }
Example 11
Source File: TestMousePick.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void simpleInitApp() { flyCam.setEnabled(false); initMark(); // a red sphere to mark the hit /** create four colored boxes and a floor to shoot at: */ shootables = new Node("Shootables"); rootNode.attachChild(shootables); shootables.attachChild(makeCube("a Dragon", -2f, 0f, 1f)); shootables.attachChild(makeCube("a tin can", 1f, -2f, 0f)); shootables.attachChild(makeCube("the Sheriff", 0f, 1f, -2f)); shootables.attachChild(makeCube("the Deputy", 1f, 0f, -4f)); shootables.attachChild(makeFloor()); shootables.attachChild(makeCharacter()); }
Example 12
Source File: PhysicsTestHelper.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * creates the necessary inputlistener and action to shoot balls from teh camera * @param app * @param rootNode * @param space */ public static void createBallShooter(final Application app, final Node rootNode, final PhysicsSpace space) { ActionListener actionListener = new ActionListener() { public void onAction(String name, boolean keyPressed, float tpf) { Sphere bullet = new Sphere(32, 32, 0.4f, true, false); bullet.setTextureMode(TextureMode.Projected); Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG"); key2.setGenerateMips(true); Texture tex2 = app.getAssetManager().loadTexture(key2); mat2.setTexture("ColorMap", tex2); if (name.equals("shoot") && !keyPressed) { Geometry bulletg = new Geometry("bullet", bullet); bulletg.setMaterial(mat2); bulletg.setShadowMode(ShadowMode.CastAndReceive); bulletg.setLocalTranslation(app.getCamera().getLocation()); RigidBodyControl bulletControl = new RigidBodyControl(1); bulletg.addControl(bulletControl); bulletControl.setLinearVelocity(app.getCamera().getDirection().mult(25)); bulletg.addControl(bulletControl); rootNode.attachChild(bulletg); space.add(bulletControl); } } }; app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); app.getInputManager().addListener(actionListener, "shoot"); }
Example 13
Source File: TerrainTestAdvanced.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected Node createAxisMarker(float arrowSize) { Material redMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); redMat.getAdditionalRenderState().setWireframe(true); redMat.setColor("Color", ColorRGBA.Red); Material greenMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); greenMat.getAdditionalRenderState().setWireframe(true); greenMat.setColor("Color", ColorRGBA.Green); Material blueMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); blueMat.getAdditionalRenderState().setWireframe(true); blueMat.setColor("Color", ColorRGBA.Blue); Node axis = new Node(); // create arrows Geometry arrowX = new Geometry("arrowX", new Arrow(new Vector3f(arrowSize, 0, 0))); arrowX.setMaterial(redMat); Geometry arrowY = new Geometry("arrowY", new Arrow(new Vector3f(0, arrowSize, 0))); arrowY.setMaterial(greenMat); Geometry arrowZ = new Geometry("arrowZ", new Arrow(new Vector3f(0, 0, arrowSize))); arrowZ.setMaterial(blueMat); axis.attachChild(arrowX); axis.attachChild(arrowY); axis.attachChild(arrowZ); //axis.setModelBound(new BoundingBox()); return axis; }
Example 14
Source File: TestSpatialAnim.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void simpleInitApp() { AmbientLight al = new AmbientLight(); rootNode.addLight(al); DirectionalLight dl = new DirectionalLight(); dl.setDirection(Vector3f.UNIT_XYZ.negate()); rootNode.addLight(dl); // Create model Box box = new Box(1, 1, 1); Geometry geom = new Geometry("box", box); geom.setMaterial(assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m")); Node model = new Node("model"); model.attachChild(geom); Box child = new Box(0.5f, 0.5f, 0.5f); Geometry childGeom = new Geometry("box", child); childGeom.setMaterial(assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m")); Node childModel = new Node("childmodel"); childModel.setLocalTranslation(2, 2, 2); childModel.attachChild(childGeom); model.attachChild(childModel); //animation parameters float animTime = 5; int fps = 25; float totalXLength = 10; //calculating frames int totalFrames = (int) (fps * animTime); float dT = animTime / totalFrames, t = 0; float dX = totalXLength / totalFrames, x = 0; float[] times = new float[totalFrames]; Vector3f[] translations = new Vector3f[totalFrames]; Quaternion[] rotations = new Quaternion[totalFrames]; Vector3f[] scales = new Vector3f[totalFrames]; for (int i = 0; i < totalFrames; ++i) { times[i] = t; t += dT; translations[i] = new Vector3f(x, 0, 0); x += dX; rotations[i] = Quaternion.IDENTITY; scales[i] = Vector3f.UNIT_XYZ; } SpatialTrack spatialTrack = new SpatialTrack(times, translations, rotations, scales); //creating the animation Animation spatialAnimation = new Animation("anim", animTime); spatialAnimation.setTracks(new SpatialTrack[] { spatialTrack }); //create spatial animation control AnimControl control = new AnimControl(); HashMap<String, Animation> animations = new HashMap<String, Animation>(); animations.put("anim", spatialAnimation); control.setAnimations(animations); model.addControl(control); rootNode.attachChild(model); //run animation control.createChannel().setAnim("anim"); }
Example 15
Source File: DebugShapeFactory.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Creates a debug shape from the given collision shape. This is mostly used internally.<br> * To attach a debug shape to a physics object, call <code>attachDebugShape(AssetManager manager);</code> on it. * @param collisionShape * @return a new Spatial or null */ public static Spatial getDebugShape(CollisionShape collisionShape) { if (collisionShape == null) { return null; } Spatial debugShape; if (collisionShape instanceof CompoundCollisionShape) { CompoundCollisionShape shape = (CompoundCollisionShape) collisionShape; List<ChildCollisionShape> children = shape.getChildren(); Node node = new Node("DebugShapeNode"); for (Iterator<ChildCollisionShape> it = children.iterator(); it.hasNext();) { ChildCollisionShape childCollisionShape = it.next(); CollisionShape ccollisionShape = childCollisionShape.shape; Geometry geometry = createDebugShape(ccollisionShape); // apply translation geometry.setLocalTranslation(childCollisionShape.location); // apply rotation TempVars vars = TempVars.get(); Matrix3f tempRot = vars.tempMat3; tempRot.set(geometry.getLocalRotation()); childCollisionShape.rotation.mult(tempRot, tempRot); geometry.setLocalRotation(tempRot); vars.release(); node.attachChild(geometry); } debugShape = node; } else { debugShape = createDebugShape(collisionShape); } if (debugShape == null) { return null; } debugShape.updateGeometricState(); return debugShape; }
Example 16
Source File: SceneEditTool.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Create the axis marker that is selectable */ protected Node createAxisMarker() { float size = 2; float arrowSize = size; float planeSize = size * 0.7f; Quaternion YAW090 = new Quaternion().fromAngleAxis(-FastMath.PI / 2, new Vector3f(0, 1, 0)); Quaternion PITCH090 = new Quaternion().fromAngleAxis(FastMath.PI / 2, new Vector3f(1, 0, 0)); redMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md"); redMat.getAdditionalRenderState().setWireframe(true); redMat.setColor("Color", ColorRGBA.Red); //redMat.getAdditionalRenderState().setDepthTest(false); greenMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md"); greenMat.getAdditionalRenderState().setWireframe(true); greenMat.setColor("Color", ColorRGBA.Green); //greenMat.getAdditionalRenderState().setDepthTest(false); blueMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md"); blueMat.getAdditionalRenderState().setWireframe(true); blueMat.setColor("Color", ColorRGBA.Blue); //blueMat.getAdditionalRenderState().setDepthTest(false); yellowMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md"); yellowMat.getAdditionalRenderState().setWireframe(false); yellowMat.setColor("Color", new ColorRGBA(1f, 1f, 0f, 0.25f)); yellowMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); yellowMat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off); //yellowMat.getAdditionalRenderState().setDepthTest(false); cyanMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md"); cyanMat.getAdditionalRenderState().setWireframe(false); cyanMat.setColor("Color", new ColorRGBA(0f, 1f, 1f, 0.25f)); cyanMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); cyanMat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off); //cyanMat.getAdditionalRenderState().setDepthTest(false); magentaMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md"); magentaMat.getAdditionalRenderState().setWireframe(false); magentaMat.setColor("Color", new ColorRGBA(1f, 0f, 1f, 0.25f)); magentaMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); magentaMat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off); //magentaMat.getAdditionalRenderState().setDepthTest(false); orangeMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md"); orangeMat.getAdditionalRenderState().setWireframe(false); orangeMat.setColor("Color", new ColorRGBA(251f / 255f, 130f / 255f, 0f, 0.4f)); orangeMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); orangeMat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off); Node axis = new Node(); // create arrows Geometry arrowX = new Geometry("arrowX", new Arrow(new Vector3f(arrowSize, 0, 0))); Geometry arrowY = new Geometry("arrowY", new Arrow(new Vector3f(0, arrowSize, 0))); Geometry arrowZ = new Geometry("arrowZ", new Arrow(new Vector3f(0, 0, arrowSize))); axis.attachChild(arrowX); axis.attachChild(arrowY); axis.attachChild(arrowZ); // create planes quadXY = new Geometry("quadXY", new Quad(planeSize, planeSize)); quadXZ = new Geometry("quadXZ", new Quad(planeSize, planeSize)); quadXZ.setLocalRotation(PITCH090); quadYZ = new Geometry("quadYZ", new Quad(planeSize, planeSize)); quadYZ.setLocalRotation(YAW090); // axis.attachChild(quadXY); // axis.attachChild(quadXZ); // axis.attachChild(quadYZ); axis.setModelBound(new BoundingBox()); return axis; }
Example 17
Source File: TestPointLightShadows.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void simpleInitApp () { flyCam.setMoveSpeed(10); cam.setLocation(new Vector3f(0.040581334f, 1.7745866f, 6.155161f)); cam.setRotation(new Quaternion(4.3868728E-5f, 0.9999293f, -0.011230096f, 0.0039059948f)); al = new AmbientLight(ColorRGBA.White.mult(0.02f)); rootNode.addLight(al); Node scene = (Node) assetManager.loadModel("Models/Test/CornellBox.j3o"); scene.setShadowMode(RenderQueue.ShadowMode.CastAndReceive); rootNode.attachChild(scene); rootNode.getChild("Cube").setShadowMode(RenderQueue.ShadowMode.Receive); lightNode = (Node) rootNode.getChild("Lamp"); Geometry lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f)); //Geometry lightMdl = new Geometry("Light", new Box(.1f,.1f,.1f)); lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m")); lightMdl.setShadowMode(RenderQueue.ShadowMode.Off); lightNode.attachChild(lightMdl); //lightMdl.setLocalTranslation(lightNode.getLocalTranslation()); Geometry box = new Geometry("box", new Box(0.2f, 0.2f, 0.2f)); //Geometry lightMdl = new Geometry("Light", new Box(.1f,.1f,.1f)); box.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m")); box.setShadowMode(RenderQueue.ShadowMode.CastAndReceive); rootNode.attachChild(box); box.setLocalTranslation(-1f, 0.5f, -2); plsr = new PointLightShadowRenderer(assetManager, SHADOWMAP_SIZE); plsr.setLight((PointLight) scene.getLocalLightList().get(0)); plsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4); plsr.setShadowZExtend(15); plsr.setShadowZFadeLength(5); plsr.setShadowIntensity(0.9f); // plsr.setFlushQueues(false); //plsr.displayFrustum(); plsr.displayDebug(); viewPort.addProcessor(plsr); plsf = new PointLightShadowFilter(assetManager, SHADOWMAP_SIZE); plsf.setLight((PointLight) scene.getLocalLightList().get(0)); plsf.setShadowZExtend(15); plsf.setShadowZFadeLength(5); plsf.setShadowIntensity(0.8f); plsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4); plsf.setEnabled(false); FilterPostProcessor fpp = new FilterPostProcessor(assetManager); fpp.addFilter(plsf); viewPort.addProcessor(fpp); inputManager.addListener(this,"ShadowUp","ShadowDown"); ShadowTestUIManager uiMan = new ShadowTestUIManager(assetManager, plsr, plsf, guiNode, inputManager, viewPort); }
Example 18
Source File: TestAnimBlendBug.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void simpleInitApp() { inputManager.addMapping("One", new KeyTrigger(KeyInput.KEY_1)); inputManager.addListener(this, "One"); flyCam.setMoveSpeed(100f); cam.setLocation( new Vector3f( 0f, 150f, -325f ) ); cam.lookAt( new Vector3f( 0f, 100f, 0f ), Vector3f.UNIT_Y ); DirectionalLight dl = new DirectionalLight(); dl.setDirection(new Vector3f(-0.1f, -0.7f, 1).normalizeLocal()); dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f)); rootNode.addLight(dl); Node model1 = (Node) assetManager.loadModel("Models/Ninja/Ninja.mesh.xml"); Node model2 = (Node) assetManager.loadModel("Models/Ninja/Ninja.mesh.xml"); // Node model2 = model1.clone(); model1.setLocalTranslation(-60, 0, 0); model2.setLocalTranslation(60, 0, 0); AnimControl control1 = model1.getControl(AnimControl.class); animNames = control1.getAnimationNames().toArray(new String[0]); channel1 = control1.createChannel(); AnimControl control2 = model2.getControl(AnimControl.class); channel2 = control2.createChannel(); SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton1", control1.getSkeleton()); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.getAdditionalRenderState().setWireframe(true); mat.setColor("Color", ColorRGBA.Green); mat.getAdditionalRenderState().setDepthTest(false); skeletonDebug.setMaterial(mat); model1.attachChild(skeletonDebug); skeletonDebug = new SkeletonDebugger("skeleton2", control2.getSkeleton()); skeletonDebug.setMaterial(mat); model2.attachChild(skeletonDebug); rootNode.attachChild(model1); rootNode.attachChild(model2); }
Example 19
Source File: TestOgreComplexAnim.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void simpleInitApp() { flyCam.setMoveSpeed(10f); cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f)); cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f)); DirectionalLight dl = new DirectionalLight(); dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal()); dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f)); rootNode.addLight(dl); Node model = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml"); control = model.getControl(AnimControl.class); AnimChannel feet = control.createChannel(); AnimChannel leftHand = control.createChannel(); AnimChannel rightHand = control.createChannel(); // feet will dodge feet.addFromRootBone("hip.right"); feet.addFromRootBone("hip.left"); feet.setAnim("Dodge"); feet.setSpeed(2); feet.setLoopMode(LoopMode.Cycle); // will blend over 15 seconds to stand feet.setAnim("Walk", 15); feet.setSpeed(0.25f); feet.setLoopMode(LoopMode.Cycle); // left hand will pull leftHand.addFromRootBone("uparm.right"); leftHand.setAnim("pull"); leftHand.setSpeed(.5f); // will blend over 15 seconds to stand leftHand.setAnim("stand", 15); // right hand will push rightHand.addBone("spinehigh"); rightHand.addFromRootBone("uparm.left"); rightHand.setAnim("push"); SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton", control.getSkeleton()); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.getAdditionalRenderState().setWireframe(true); mat.setColor("Color", ColorRGBA.Green); mat.getAdditionalRenderState().setDepthTest(false); skeletonDebug.setMaterial(mat); model.attachChild(skeletonDebug); rootNode.attachChild(model); }
Example 20
Source File: TestAnimMorphSerialization.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void simpleInitApp() { setTimer(new EraseTimer()); //cam.setFrustumPerspective(90f, (float) cam.getWidth() / cam.getHeight(), 0.01f, 10f); viewPort.setBackgroundColor(ColorRGBA.DarkGray); //rootNode.addLight(new DirectionalLight(new Vector3f(-1, -1, -1).normalizeLocal())); //rootNode.addLight(new AmbientLight(ColorRGBA.DarkGray)); Node probeNode = (Node) assetManager.loadModel("Scenes/defaultProbe.j3o"); rootNode.attachChild(probeNode); Spatial model = assetManager.loadModel("Models/gltf/zophrac/scene.gltf"); File storageFolder = JmeSystem.getStorageFolder(); file = new File(storageFolder.getPath() + File.separator + "zophrac.j3o"); BinaryExporter be = new BinaryExporter(); try { be.save(model, file); } catch (IOException e) { e.printStackTrace(); } assetManager.registerLocator(storageFolder.getPath(), FileLocator.class); Spatial model2 = assetManager.loadModel("zophrac.j3o"); model2.setLocalScale(0.1f); probeNode.attachChild(model2); debugAppState = new ArmatureDebugAppState(); stateManager.attach(debugAppState); setupModel(model2); flyCam.setEnabled(false); Node target = new Node("CamTarget"); //target.setLocalTransform(model.getLocalTransform()); target.move(0, 0, 0); ChaseCameraAppState chaseCam = new ChaseCameraAppState(); chaseCam.setTarget(target); getStateManager().attach(chaseCam); chaseCam.setInvertHorizontalAxis(true); chaseCam.setInvertVerticalAxis(true); chaseCam.setZoomSpeed(0.5f); chaseCam.setMinVerticalRotation(-FastMath.HALF_PI); chaseCam.setRotationSpeed(3); chaseCam.setDefaultDistance(3); chaseCam.setMinDistance(0.01f); chaseCam.setZoomSpeed(0.01f); chaseCam.setDefaultVerticalRotation(0.3f); initInputs(); }