Java Code Examples for com.jme3.scene.Geometry#setLocalRotation()
The following examples show how to use
com.jme3.scene.Geometry#setLocalRotation() .
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: MaterialPreviewWidget.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private void initWidget() { SceneApplication.getApplication().addSceneListener(this); Sphere sphMesh = new Sphere(32, 32, 2.5f); sphMesh.setTextureMode(Sphere.TextureMode.Projected); sphMesh.updateGeometry(32, 32, 2.5f, false, false); TangentBinormalGenerator.generate(sphMesh); sphere = new Geometry("previewSphere", sphMesh); sphere.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.QUARTER_PI, Vector3f.UNIT_X)); Box boxMesh = new Box(new Vector3f(0, 0, 0), 1.75f, 1.75f, 1.75f); TangentBinormalGenerator.generate(boxMesh); box = new Geometry("previewBox", boxMesh); box.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.DEG_TO_RAD * 30, Vector3f.UNIT_X).multLocal(new Quaternion().fromAngleAxis(FastMath.QUARTER_PI, Vector3f.UNIT_Y))); Quad quadMesh = new Quad(4.5f, 4.5f); TangentBinormalGenerator.generate(quadMesh); quad = new Geometry("previewQuad", quadMesh); quad.setLocalTranslation(new Vector3f(-2.25f, -2.25f, 0)); currentGeom = sphere; sphereButton.setSelected(true); init=true; }
Example 2
Source File: TestCollisionShapeFactory.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void attachRandomGeometry(Node node, Material mat) { Box box = new Box(0.25f, 0.25f, 0.25f); Torus torus = new Torus(16, 16, 0.2f, 0.8f); Geometry[] boxes = new Geometry[]{ new Geometry("box1", box), new Geometry("box2", box), new Geometry("box3", box), new Geometry("torus1", torus), new Geometry("torus2", torus), new Geometry("torus3", torus) }; for (int i = 0; i < boxes.length; i++) { Geometry geometry = boxes[i]; geometry.setLocalTranslation((float) Math.random() * 10 -10, (float) Math.random() * 10 -10, (float) Math.random() * 10 -10); geometry.setLocalRotation(new Quaternion().fromAngles((float) Math.random() * FastMath.PI, (float) Math.random() * FastMath.PI, (float) Math.random() * FastMath.PI)); geometry.setLocalScale((float) Math.random() * 10 -10, (float) Math.random() * 10 -10, (float) Math.random() * 10 -10); geometry.setMaterial(mat); node.attachChild(geometry); } }
Example 3
Source File: TestParallax.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
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); }
Example 4
Source File: TestParallaxPBR.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void setupFloor() { mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWallPBR.j3m"); //mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWallPBR2.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); }
Example 5
Source File: TestCollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private void attachRandomGeometry(Node node, Material mat) { Box box = new Box(0.25f, 0.25f, 0.25f); Torus torus = new Torus(16, 16, 0.2f, 0.8f); Geometry[] boxes = new Geometry[]{ new Geometry("box1", box), new Geometry("box2", box), new Geometry("box3", box), new Geometry("torus1", torus), new Geometry("torus2", torus), new Geometry("torus3", torus) }; for (int i = 0; i < boxes.length; i++) { Geometry geometry = boxes[i]; geometry.setLocalTranslation((float) Math.random() * 10 -10, (float) Math.random() * 10 -10, (float) Math.random() * 10 -10); geometry.setLocalRotation(new Quaternion().fromAngles((float) Math.random() * FastMath.PI, (float) Math.random() * FastMath.PI, (float) Math.random() * FastMath.PI)); geometry.setLocalScale((float) Math.random() * 10 -10, (float) Math.random() * 10 -10, (float) Math.random() * 10 -10); geometry.setMaterial(mat); node.attachChild(geometry); } }
Example 6
Source File: EditorPresentableNode.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
/** * Update position and rotation of a model. */ @JmeThread public void updateModel() { final ScenePresentable object = getObject(); final Geometry model = getModel(); if (model == null || object == null) return; // TODO implement getting parent /*final Node parent = object.getParent(); if (parent != null) { setLocalTranslation(parent.getWorldTranslation()); setLocalRotation(parent.getWorldRotation()); setLocalScale(parent.getWorldScale()); }*/ final Node editedNode = getEditedNode(); model.setLocalTranslation(editedNode.getWorldTranslation()); model.setLocalRotation(editedNode.getWorldRotation()); model.setLocalScale(editedNode.getWorldScale()); }
Example 7
Source File: SelectionIndicator.java From Lemur with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected void copyTransforms( Geometry copy, Geometry original ) { // For now we will assume the root is the actual // world root so that the math is easier. copy.setLocalTranslation(original.getWorldTranslation()); copy.setLocalRotation(original.getWorldRotation()); copy.setLocalScale(original.getWorldScale()); }
Example 8
Source File: SimpleWaterProcessor.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Creates a quad with the water material applied to it. * @param width * @param height * @return */ public Geometry createWaterGeometry(float width, float height) { Quad quad = new Quad(width, height); Geometry geom = new Geometry("WaterGeometry", quad); geom.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); geom.setMaterial(material); return geom; }
Example 9
Source File: SimpleWaterProcessor.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Creates a quad with the water material applied to it. * @param width * @param height * @return a new Geometry */ public Geometry createWaterGeometry(float width, float height) { Quad quad = new Quad(width, height); Geometry geom = new Geometry("WaterGeometry", quad); geom.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); geom.setMaterial(material); return geom; }
Example 10
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 11
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 12
Source File: TestChaseCamera.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void simpleInitApp() { // Load a teapot model teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj"); Material mat_tea = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md"); teaGeom.setMaterial(mat_tea); rootNode.attachChild(teaGeom); // Load a floor model Material mat_ground = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat_ground.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); Geometry ground = new Geometry("ground", new Quad(50, 50)); ground.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); ground.setLocalTranslation(-25, -1, 25); ground.setMaterial(mat_ground); rootNode.attachChild(ground); // Disable the default first-person cam! flyCam.setEnabled(false); // Enable a chase cam chaseCam = new ChaseCamera(cam, teaGeom, inputManager); //Uncomment this to invert the camera's vertical rotation Axis //chaseCam.setInvertVerticalAxis(true); //Uncomment this to invert the camera's horizontal rotation Axis //chaseCam.setInvertHorizontalAxis(true); //Comment this to disable smooth camera motion chaseCam.setSmoothMotion(true); //Uncomment this to disable trailing of the camera //WARNING, trailing only works with smooth motion enabled. It is true by default. //chaseCam.setTrailingEnabled(false); //Uncomment this to look 3 world units above the target //chaseCam.setLookAtOffset(Vector3f.UNIT_Y.mult(3)); //Uncomment this to enable rotation when the middle mouse button is pressed (like Blender) //WARNING : setting this trigger disable the rotation on right and left mouse button click //chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE)); //Uncomment this to set mutiple triggers to enable rotation of the cam //Here spade bar and middle mouse button //chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE),new KeyTrigger(KeyInput.KEY_SPACE)); //registering inputs for target's movement registerInput(); }
Example 13
Source File: TestSceneWater.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void simpleInitApp() { this.flyCam.setMoveSpeed(10); Node mainScene=new Node(); cam.setLocation(new Vector3f(-27.0f, 1.0f, 75.0f)); cam.setRotation(new Quaternion(0.03f, 0.9f, 0f, 0.4f)); // load sky mainScene.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false)); File file = new File("wildhouse.zip"); if (file.exists()) { useHttp = false; } // create the geometry and attach it // load the level from zip or http zip if (useHttp) { assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/wildhouse.zip", HttpZipLocator.class.getName()); } else { assetManager.registerLocator("wildhouse.zip", ZipLocator.class.getName()); } Spatial scene = assetManager.loadModel("main.scene"); DirectionalLight sun = new DirectionalLight(); Vector3f lightDir=new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f); sun.setDirection(lightDir); sun.setColor(ColorRGBA.White.clone().multLocal(2)); scene.addLight(sun); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); //add lightPos Geometry Sphere lite=new Sphere(8, 8, 3.0f); Geometry lightSphere=new Geometry("lightsphere", lite); lightSphere.setMaterial(mat); Vector3f lightPos=lightDir.multLocal(-400); lightSphere.setLocalTranslation(lightPos); rootNode.attachChild(lightSphere); SimpleWaterProcessor waterProcessor = new SimpleWaterProcessor(assetManager); waterProcessor.setReflectionScene(mainScene); waterProcessor.setDebug(false); waterProcessor.setLightPosition(lightPos); waterProcessor.setRefractionClippingOffset(1.0f); //setting the water plane Vector3f waterLocation=new Vector3f(0,-20,0); waterProcessor.setPlane(new Plane(Vector3f.UNIT_Y, waterLocation.dot(Vector3f.UNIT_Y))); WaterUI waterUi=new WaterUI(inputManager, waterProcessor); waterProcessor.setWaterColor(ColorRGBA.Brown); waterProcessor.setDebug(true); //lower render size for higher performance // waterProcessor.setRenderSize(128,128); //raise depth to see through water // waterProcessor.setWaterDepth(20); //lower the distortion scale if the waves appear too strong // waterProcessor.setDistortionScale(0.1f); //lower the speed of the waves if they are too fast // waterProcessor.setWaveSpeed(0.01f); Quad quad = new Quad(400,400); //the texture coordinates define the general size of the waves quad.scaleTextureCoordinates(new Vector2f(6f,6f)); Geometry water=new Geometry("water", quad); water.setShadowMode(ShadowMode.Receive); water.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); water.setMaterial(waterProcessor.getMaterial()); water.setLocalTranslation(-200, -20, 250); rootNode.attachChild(water); viewPort.addProcessor(waterProcessor); mainScene.attachChild(scene); rootNode.attachChild(mainScene); }
Example 14
Source File: DebugShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" 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 */ 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 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: TestChaseCameraAppState.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void simpleInitApp() { // Load a teapot model teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj"); Material mat_tea = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md"); teaGeom.setMaterial(mat_tea); rootNode.attachChild(teaGeom); // Load a floor model Material mat_ground = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat_ground.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); Geometry ground = new Geometry("ground", new Quad(50, 50)); ground.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); ground.setLocalTranslation(-25, -1, 25); ground.setMaterial(mat_ground); rootNode.attachChild(ground); //disable the flyCam stateManager.detach(stateManager.getState(FlyCamAppState.class)); // Enable a chase cam ChaseCameraAppState chaseCamAS = new ChaseCameraAppState(); chaseCamAS.setTarget(teaGeom); stateManager.attach(chaseCamAS); //Uncomment this to invert the camera's vertical rotation Axis //chaseCamAS.setInvertVerticalAxis(true); //Uncomment this to invert the camera's horizontal rotation Axis //chaseCamAS.setInvertHorizontalAxis(true); //Uncomment this to enable rotation when the middle mouse button is pressed (like Blender) //WARNING : setting this trigger disable the rotation on right and left mouse button click //chaseCamAS.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE)); //Uncomment this to set multiple triggers to enable rotation of the cam //Here space bar and middle mouse button //chaseCamAS.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE),new KeyTrigger(KeyInput.KEY_SPACE)); //registering inputs for target's movement registerInput(); }
Example 17
Source File: TestChaseCamera.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void simpleInitApp() { // Load a teapot model teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj"); Material mat_tea = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md"); teaGeom.setMaterial(mat_tea); rootNode.attachChild(teaGeom); // Load a floor model Material mat_ground = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat_ground.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); Geometry ground = new Geometry("ground", new Quad(50, 50)); ground.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); ground.setLocalTranslation(-25, -1, 25); ground.setMaterial(mat_ground); rootNode.attachChild(ground); // Disable the default first-person cam! flyCam.setEnabled(false); // Enable a chase cam chaseCam = new ChaseCamera(cam, teaGeom, inputManager); //Uncomment this to invert the camera's vertical rotation Axis //chaseCam.setInvertVerticalAxis(true); //Uncomment this to invert the camera's horizontal rotation Axis //chaseCam.setInvertHorizontalAxis(true); //Comment this to disable smooth camera motion chaseCam.setSmoothMotion(true); //Uncomment this to disable trailing of the camera //WARNING, trailing only works with smooth motion enabled. It is true by default. //chaseCam.setTrailingEnabled(false); //Uncomment this to look 3 world units above the target //chaseCam.setLookAtOffset(Vector3f.UNIT_Y.mult(3)); //Uncomment this to enable rotation when the middle mouse button is pressed (like Blender) //WARNING : setting this trigger disable the rotation on right and left mouse button click //chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE)); //Uncomment this to set multiple triggers to enable rotation of the cam //Here spade bar and middle mouse button //chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE),new KeyTrigger(KeyInput.KEY_SPACE)); //registering inputs for target's movement registerInput(); }
Example 18
Source File: TestSceneWater.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void simpleInitApp() { File file = new File("wildhouse.zip"); if (!file.exists()) { useHttp = true; } this.flyCam.setMoveSpeed(10); Node mainScene=new Node(); cam.setLocation(new Vector3f(-27.0f, 1.0f, 75.0f)); cam.setRotation(new Quaternion(0.03f, 0.9f, 0f, 0.4f)); // load sky mainScene.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", SkyFactory.EnvMapType.CubeMap)); // create the geometry and attach it // load the level from zip or http zip if (useHttp) { assetManager.registerLocator("https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmonkeyengine/wildhouse.zip", HttpZipLocator.class); } else { assetManager.registerLocator("wildhouse.zip", ZipLocator.class); } Spatial scene = assetManager.loadModel("main.scene"); DirectionalLight sun = new DirectionalLight(); Vector3f lightDir=new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f); sun.setDirection(lightDir); sun.setColor(ColorRGBA.White.clone().multLocal(2)); scene.addLight(sun); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); //add lightPos Geometry Sphere lite=new Sphere(8, 8, 3.0f); Geometry lightSphere=new Geometry("lightsphere", lite); lightSphere.setMaterial(mat); Vector3f lightPos=lightDir.multLocal(-400); lightSphere.setLocalTranslation(lightPos); rootNode.attachChild(lightSphere); SimpleWaterProcessor waterProcessor = new SimpleWaterProcessor(assetManager); waterProcessor.setReflectionScene(mainScene); waterProcessor.setDebug(false); waterProcessor.setLightPosition(lightPos); waterProcessor.setRefractionClippingOffset(1.0f); //setting the water plane Vector3f waterLocation=new Vector3f(0,-20,0); waterProcessor.setPlane(new Plane(Vector3f.UNIT_Y, waterLocation.dot(Vector3f.UNIT_Y))); WaterUI waterUi=new WaterUI(inputManager, waterProcessor); waterProcessor.setWaterColor(ColorRGBA.Brown); waterProcessor.setDebug(true); //lower render size for higher performance // waterProcessor.setRenderSize(128,128); //raise depth to see through water // waterProcessor.setWaterDepth(20); //lower the distortion scale if the waves appear too strong // waterProcessor.setDistortionScale(0.1f); //lower the speed of the waves if they are too fast // waterProcessor.setWaveSpeed(0.01f); Quad quad = new Quad(400,400); //the texture coordinates define the general size of the waves quad.scaleTextureCoordinates(new Vector2f(6f,6f)); Geometry water=new Geometry("water", quad); water.setShadowMode(ShadowMode.Receive); water.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); water.setMaterial(waterProcessor.getMaterial()); water.setLocalTranslation(-200, -20, 250); rootNode.attachChild(water); viewPort.addProcessor(waterProcessor); mainScene.attachChild(scene); rootNode.attachChild(mainScene); }
Example 19
Source File: TestColorApp.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void simpleInitApp() { // Lights DirectionalLight sun = new DirectionalLight(); Vector3f sunPosition = new Vector3f(1, -1, 1); sun.setDirection(sunPosition); sun.setColor(new ColorRGBA(1f,1f,1f,1f)); rootNode.addLight(sun); //DirectionalLightShadowFilter sun_renderer = new DirectionalLightShadowFilter(assetManager, 2048, 4); DirectionalLightShadowRenderer sun_renderer = new DirectionalLightShadowRenderer(assetManager, 2048, 1); sun_renderer.setLight(sun); viewPort.addProcessor(sun_renderer); // FilterPostProcessor fpp = new FilterPostProcessor(assetManager); // fpp.addFilter(sun_renderer); // viewPort.addProcessor(fpp); rootNode.setShadowMode(RenderQueue.ShadowMode.CastAndReceive); // Camera viewPort.setBackgroundColor(new ColorRGBA(.6f, .6f, .6f, 1f)); ChaseCamera chaseCam = new ChaseCamera(cam, inputManager); // Objects // Ground Object final Geometry groundBoxWhite = new Geometry("Box", new Box(7.5f, 7.5f, .25f)); float[] f = {-FastMath.PI / 2, 3 * FastMath.PI / 2, 0f}; groundBoxWhite.setLocalRotation(new Quaternion(f)); groundBoxWhite.move(7.5f, -.75f, 7.5f); final Material groundMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); groundMaterial.setColor("Diffuse", new ColorRGBA(.9f, .9f, .9f, .9f)); groundBoxWhite.setMaterial(groundMaterial); groundBoxWhite.addControl(chaseCam); rootNode.attachChild(groundBoxWhite); // Planter Geometry planterBox = new Geometry("Box", new Box(.5f, .5f, .5f)); final Material planterMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); planterMaterial.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg")); planterBox.setMaterial(groundMaterial); planterBox.setLocalTranslation(10, 0, 9); rootNode.attachChild(planterBox); // Action! inputManager.addMapping("on", new KeyTrigger(KeyInput.KEY_Z)); inputManager.addMapping("off", new KeyTrigger(KeyInput.KEY_X)); inputManager.addListener(new AnalogListener() { @Override public void onAnalog(String s, float v, float v1) { if (s.equals("on")) { groundBoxWhite.setMaterial(planterMaterial); } if (s.equals("off")) { groundBoxWhite.setMaterial(groundMaterial); } } }, "on", "off"); inputEnabled = true; }
Example 20
Source File: DebugShapeFactory.java From jmonkeybuilder with Apache License 2.0 | 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 */ 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); geometry.setLocalScale(ccollisionShape.getScale()); vars.release(); node.attachChild(geometry); } debugShape = node; } else { debugShape = createDebugShape(collisionShape); } if (debugShape == null) { return null; } debugShape.updateGeometricState(); return debugShape; }