Java Code Examples for com.jme3.scene.Node#setLocalScale()
The following examples show how to use
com.jme3.scene.Node#setLocalScale() .
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: HelloAnimation.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void simpleInitApp() { viewPort.setBackgroundColor(ColorRGBA.LightGray); initKeys(); /** Add a light source so we can see the model */ DirectionalLight dl = new DirectionalLight(); dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal()); rootNode.addLight(dl); /** Load a model that contains animation */ player = (Node) assetManager.loadModel("Models/Oto/OtoOldAnim.j3o"); player.setLocalScale(0.5f); rootNode.attachChild(player); /** Create a controller and channels. */ control = player.getControl(AnimControl.class); control.addListener(this); channel = control.createChannel(); channel.setAnim("stand"); }
Example 2
Source File: HelloAnimation.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void simpleInitApp() { viewPort.setBackgroundColor(ColorRGBA.LightGray); initKeys(); /** Add a light source so we can see the model */ DirectionalLight dl = new DirectionalLight(); dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal()); rootNode.addLight(dl); /** Load a model that contains animation */ player = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml"); player.setLocalScale(0.5f); rootNode.attachChild(player); /** Create a controller and channels. */ control = player.getControl(AnimControl.class); control.addListener(this); channel = control.createChannel(); channel.setAnim("stand"); }
Example 3
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 4
Source File: EditorPresentableNode.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Synchronize this node with presented object. */ @JmeThread public void sync() { final ScenePresentable object = getObject(); final Node editedNode = getEditedNode(); editedNode.setLocalRotation(object.getRotation()); editedNode.setLocalTranslation(object.getLocation()); editedNode.setLocalScale(object.getScale()); }
Example 5
Source File: TestEverything.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void setupRobotGuy(){ Node model = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml"); Material mat = assetManager.loadMaterial("Models/Oto/Oto.j3m"); model.getChild(0).setMaterial(mat); // model.setAnimation("Walk"); model.setLocalTranslation(30, 10.5f, 30); model.setLocalScale(2); model.setShadowMode(ShadowMode.CastAndReceive); rootNode.attachChild(model); }
Example 6
Source File: HelloAnimation.java From chuidiang-ejemplos with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void simpleInitApp() { viewPort.setBackgroundColor(ColorRGBA.LightGray); initKeys(); DirectionalLight dl = new DirectionalLight(); dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal()); rootNode.addLight(dl); player = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml"); player.setLocalScale(0.5f); rootNode.attachChild(player); control = player.getControl(AnimControl.class); control.addListener(this); channel = control.createChannel(); channel.setAnim("stand"); }
Example 7
Source File: TestEverything.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void setupRobotGuy(){ Node model = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml"); Material mat = assetManager.loadMaterial("Models/Oto/Oto.j3m"); model.getChild(0).setMaterial(mat); // model.setAnimation("Walk"); model.setLocalTranslation(30, 10.5f, 30); model.setLocalScale(2); model.setShadowMode(ShadowMode.CastAndReceive); rootNode.attachChild(model); }
Example 8
Source File: ScaleToolControl.java From jmonkeybuilder with Apache License 2.0 | 4 votes |
@JmeThread @Override public void processTransform() { final EditorTransformSupport editorControl = getEditorControl(); final LocalObjects local = LocalObjects.get(); final Camera camera = editorControl.getCamera(); final InputManager inputManager = EditorUtil.getInputManager(); final Transform transform = notNull(editorControl.getTransformCenter()); // cursor position and selected position vectors final Vector2f cursorPos = inputManager.getCursorPosition(); final Vector3f transformOnScreen = camera.getScreenCoordinates(transform.getTranslation(), local.nextVector()); final Vector2f selectedCoords = local.nextVector(transformOnScreen.getX(), transformOnScreen.getY()); // set new deltaVector if it's not set (scale tool stores position of a cursor) if (Float.isNaN(editorControl.getTransformDeltaX())) { editorControl.setTransformDeltaX(cursorPos.getX()); editorControl.setTransformDeltaY(cursorPos.getY()); } final Node parentNode = getParentNode(); final Node childNode = getChildNode(); // Picked vector final Spatial toTransform = notNull(editorControl.getToTransform()); final TransformationMode transformationMode = editorControl.getTransformationMode(); transformationMode.prepareToScale(parentNode, childNode, transform, camera); // scale according to distance final Vector3f deltaVector = local.nextVector(editorControl.getTransformDeltaX(), editorControl.getTransformDeltaY(), 0F); final Vector2f delta2d = local.nextVector(deltaVector.getX(), deltaVector.getY()); final Vector3f baseScale = local.nextVector(transform.getScale()); // default scale final Vector3f pickedVector = local.nextVector(transformationMode.getScaleAxis(transform, editorControl.getPickedAxis(), camera)); pickedVector.setX(abs(pickedVector.getX())); pickedVector.setY(abs(pickedVector.getY())); pickedVector.setZ(abs(pickedVector.getZ())); if (Config.DEV_TRANSFORMS_DEBUG) { System.out.println("Base scale " + baseScale + ", pickedVector " + pickedVector); } // scale object float disCursor = cursorPos.distance(selectedCoords); float disDelta = delta2d.distance(selectedCoords); float scaleValue = (float) (cursorPos.distance(delta2d) * 0.01f * Math.sqrt(baseScale.length())); if (disCursor > disDelta) { baseScale.addLocal(pickedVector.mult(scaleValue, local.nextVector())); } else { scaleValue = Math.min(scaleValue, 0.999f); // remove negateve values baseScale.subtractLocal(pickedVector.mult(scaleValue, local.nextVector())); } parentNode.setLocalScale(baseScale); if (Config.DEV_TRANSFORMS_DEBUG) { System.out.println("New scale " + baseScale + ", result world " + childNode.getWorldScale()); } parentNode.setLocalScale(baseScale); toTransform.setLocalScale(childNode.getWorldScale()); editorControl.notifyTransformed(toTransform); }
Example 9
Source File: TestBetterCharacter.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void simpleInitApp() { //setup keyboard mapping setupKeys(); // activate physics bulletAppState = new BulletAppState() { @Override public void prePhysicsTick(PhysicsSpace space, float tpf) { // Apply radial gravity near the planet, downward gravity elsewhere. checkPlanetGravity(); } }; stateManager.attach(bulletAppState); bulletAppState.setDebugEnabled(true); // init a physics test scene PhysicsTestHelper.createPhysicsTestWorldSoccer(rootNode, assetManager, bulletAppState.getPhysicsSpace()); PhysicsTestHelper.createBallShooter(this, rootNode, bulletAppState.getPhysicsSpace()); setupPlanet(); // Create a node for the character model characterNode = new Node("character node"); characterNode.setLocalTranslation(new Vector3f(4, 5, 2)); // Add a character control to the node so we can add other things and // control the model rotation physicsCharacter = new BetterCharacterControl(0.3f, 2.5f, 8f); characterNode.addControl(physicsCharacter); getPhysicsSpace().add(physicsCharacter); // Load model, attach to character node Node model = (Node) assetManager.loadModel("Models/Jaime/Jaime.j3o"); model.setLocalScale(1.50f); characterNode.attachChild(model); // Add character node to the rootNode rootNode.attachChild(characterNode); // Set forward camera node that follows the character, only used when // view is "locked" camNode = new CameraNode("CamNode", cam); camNode.setControlDir(ControlDirection.SpatialToCamera); camNode.setLocalTranslation(new Vector3f(0, 2, -6)); Quaternion quat = new Quaternion(); // These coordinates are local, the camNode is attached to the character node! quat.lookAt(Vector3f.UNIT_Z, Vector3f.UNIT_Y); camNode.setLocalRotation(quat); characterNode.attachChild(camNode); // Disable by default, can be enabled via keyboard shortcut camNode.setEnabled(false); }
Example 10
Source File: TestQ3.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void simpleInitApp() { File file = new File("quake3level.zip"); if (!file.exists()) { useHttp = true; } bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); flyCam.setMoveSpeed(100); setupKeys(); this.cam.setFrustumFar(2000); DirectionalLight dl = new DirectionalLight(); dl.setColor(ColorRGBA.White.clone().multLocal(2)); dl.setDirection(new Vector3f(-1, -1, -1).normalize()); rootNode.addLight(dl); AmbientLight am = new AmbientLight(); am.setColor(ColorRGBA.White.mult(2)); rootNode.addLight(am); // 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/quake3level.zip", HttpZipLocator.class); } else { assetManager.registerLocator("quake3level.zip", ZipLocator.class); } // create the geometry and attach it MaterialList matList = (MaterialList) assetManager.loadAsset("Scene.material"); OgreMeshKey key = new OgreMeshKey("main.meshxml", matList); gameLevel = (Node) assetManager.loadAsset(key); gameLevel.setLocalScale(0.1f); // add a physics control, it will generate a MeshCollisionShape based on the gameLevel gameLevel.addControl(new RigidBodyControl(0)); player = new PhysicsCharacter(new SphereCollisionShape(5), .01f); player.setJumpSpeed(20); player.setFallSpeed(30); player.setGravity(30); player.setPhysicsLocation(new Vector3f(60, 10, -60)); rootNode.attachChild(gameLevel); getPhysicsSpace().addAll(gameLevel); getPhysicsSpace().add(player); }
Example 11
Source File: EnvMapUtils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Creates a debug Node of the given cube map to attach to the gui node * * the cube map is layered this way : * <pre> * _____ * | | * | +Y | * _____|_____|_____ _____ * | | | | | * | -X | +Z | +X | -Z | * |_____|_____|_____|_____| * | | * | -Y | * |_____| * *</pre> * * @param cubeMap the cube map * @param assetManager the asset Manager * @return a new Node */ public static Node getCubeMapCrossDebugView(TextureCubeMap cubeMap, AssetManager assetManager) { Node n = new Node("CubeMapDebug" + cubeMap.getName()); int size = cubeMap.getImage().getWidth(); Picture[] pics = new Picture[6]; float ratio = 128f / size; for (int i = 0; i < 6; i++) { pics[i] = new Picture("bla"); Texture2D tex = new Texture2D(new Image(cubeMap.getImage().getFormat(), size, size, cubeMap.getImage().getData(i), cubeMap.getImage().getColorSpace())); pics[i].setTexture(assetManager, tex, true); pics[i].setWidth(size); pics[i].setHeight(size); n.attachChild(pics[i]); } pics[0].setLocalTranslation(size, size * 2, 1); pics[0].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z)); pics[1].setLocalTranslation(size * 3, size * 2, 1); pics[1].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z)); pics[2].setLocalTranslation(size * 2, size * 3, 1); pics[2].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z)); pics[3].setLocalTranslation(size * 2, size, 1); pics[3].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z)); pics[4].setLocalTranslation(size * 2, size * 2, 1); pics[4].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z)); pics[5].setLocalTranslation(size * 4, size * 2, 1); pics[5].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z)); Quad q = new Quad(size * 4, size * 3); Geometry g = new Geometry("bg", q); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.Black); g.setMaterial(mat); g.setLocalTranslation(0, 0, 0); n.attachChild(g); n.setLocalScale(ratio); return n; }
Example 12
Source File: EnvMapUtils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static Node getCubeMapCrossDebugViewWithMipMaps(TextureCubeMap cubeMap, AssetManager assetManager) { Node n = new Node("CubeMapDebug" + cubeMap.getName()); int size = cubeMap.getImage().getWidth(); int nbMips = cubeMap.getImage().getMipMapSizes().length; Picture[] pics = new Picture[6*nbMips]; float ratio = 1f;// 128f / (float) size; int offset = 0; int guiOffset = 0; for (int mipLevel = 0; mipLevel < nbMips; mipLevel++) { size = Math.max(1, cubeMap.getImage().getWidth() >> mipLevel); int dataSize = cubeMap.getImage().getMipMapSizes()[mipLevel]; byte[] dataArray = new byte[dataSize]; for (int i = 0; i < 6; i++) { ByteBuffer bb = cubeMap.getImage().getData(i); bb.rewind(); bb.position(offset); bb.get(dataArray, 0, dataSize); ByteBuffer data = BufferUtils.createByteBuffer(dataArray); pics[i] = new Picture("bla"); Texture2D tex = new Texture2D(new Image(cubeMap.getImage().getFormat(), size, size, data, cubeMap.getImage().getColorSpace())); pics[i].setTexture(assetManager, tex, true); pics[i].setWidth(size); pics[i].setHeight(size); n.attachChild(pics[i]); } pics[0].setLocalTranslation(guiOffset + size, guiOffset + size * 2, 1); pics[0].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z)); pics[1].setLocalTranslation(guiOffset + size * 3, guiOffset + size * 2, 1); pics[1].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z)); pics[2].setLocalTranslation(guiOffset + size * 2, guiOffset + size * 3, 1); pics[2].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z)); pics[3].setLocalTranslation(guiOffset + size * 2, guiOffset + size, 1); pics[3].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z)); pics[4].setLocalTranslation(guiOffset + size * 2, guiOffset + size * 2, 1); pics[4].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z)); pics[5].setLocalTranslation(guiOffset + size * 4, guiOffset + size * 2, 1); pics[5].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z)); guiOffset+=size *2+1; offset += dataSize; } Quad q = new Quad(cubeMap.getImage().getWidth() * 4 + nbMips, guiOffset + size); Geometry g = new Geometry("bg", q); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.Black); g.setMaterial(mat); g.setLocalTranslation(0, 0, 0); n.attachChild(g); n.setLocalScale(ratio); return n; }
Example 13
Source File: TestQ3.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void simpleInitApp() { bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); flyCam.setMoveSpeed(100); setupKeys(); this.cam.setFrustumFar(2000); DirectionalLight dl = new DirectionalLight(); dl.setColor(ColorRGBA.White.clone().multLocal(2)); dl.setDirection(new Vector3f(-1, -1, -1).normalize()); rootNode.addLight(dl); AmbientLight am = new AmbientLight(); am.setColor(ColorRGBA.White.mult(2)); rootNode.addLight(am); // load the level from zip or http zip if (useHttp) { assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/quake3level.zip", HttpZipLocator.class.getName()); } else { assetManager.registerLocator("quake3level.zip", ZipLocator.class.getName()); } // create the geometry and attach it MaterialList matList = (MaterialList) assetManager.loadAsset("Scene.material"); OgreMeshKey key = new OgreMeshKey("main.meshxml", matList); gameLevel = (Node) assetManager.loadAsset(key); gameLevel.setLocalScale(0.1f); // add a physics control, it will generate a MeshCollisionShape based on the gameLevel gameLevel.addControl(new RigidBodyControl(0)); player = new PhysicsCharacter(new SphereCollisionShape(5), .01f); player.setJumpSpeed(20); player.setFallSpeed(30); player.setGravity(30); player.setPhysicsLocation(new Vector3f(60, 10, -60)); rootNode.attachChild(gameLevel); getPhysicsSpace().addAll(gameLevel); getPhysicsSpace().add(player); }
Example 14
Source File: EditorTransformSupport.java From jmonkeybuilder with Apache License 2.0 | 3 votes |
/** * Prepare nodes to scale. * * @param parent the parent node. * @param child the child node. * @param transform the base transform. * @param camera the camera. */ @JmeThread public void prepareToScale(@NotNull final Node parent, @NotNull final Node child, @NotNull final Transform transform, @NotNull final Camera camera) { parent.setLocalScale(transform.getScale()); child.setLocalScale(Vector3f.UNIT_XYZ); }