Java Code Examples for com.jme3.light.DirectionalLight#setDirection()
The following examples show how to use
com.jme3.light.DirectionalLight#setDirection() .
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: TestBlendEquations.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void simpleInitApp() { cam.setLocation(new Vector3f(0f, 0.5f, 3f)); viewPort.setBackgroundColor(ColorRGBA.LightGray); // Add a light source to the scene. DirectionalLight directionalLight = new DirectionalLight(); directionalLight.setColor(ColorRGBA.Magenta); directionalLight.setDirection(Vector3f.UNIT_XYZ.negate()); rootNode.addLight(directionalLight); // Create and add a teapot to the scene graph. Spatial teapotModel = assetManager.loadModel("Models/Teapot/Teapot.obj"); rootNode.attachChild(teapotModel); // Create the two moving quads with custom blend modes. createLeftQuad(); createRightQuad(); }
Example 2
Source File: TestBlenderObjectAnim.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 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); BlenderKey blenderKey = new BlenderKey("Blender/2.4x/animtest.blend"); Spatial scene = (Spatial) assetManager.loadModel(blenderKey); rootNode.attachChild(scene); Spatial model = this.findNode(rootNode, "TestAnim"); model.center(); control = model.getControl(AnimControl.class); channel = control.createChannel(); channel.setAnim("TestAnim"); }
Example 3
Source File: TestOgreLoading.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void simpleInitApp() { // PointLight pl = new PointLight(); // pl.setPosition(new Vector3f(10, 10, -10)); // rootNode.addLight(pl); flyCam.setMoveSpeed(10f); // sunset light 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); lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f)); lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m")); rootNode.attachChild(lightMdl); lightMd2 = new Geometry("Light", new Sphere(10, 10, 0.1f)); lightMd2.setMaterial(assetManager.loadMaterial("Common/Materials/WhiteColor.j3m")); rootNode.attachChild(lightMd2); pl = new PointLight(); pl.setColor(new ColorRGBA(1, 0.9f, 0.9f, 0)); pl.setPosition(new Vector3f(0f, 0f, 4f)); rootNode.addLight(pl); p2 = new PointLight(); p2.setColor(new ColorRGBA(0.9f, 1, 0.9f, 0)); p2.setPosition(new Vector3f(0f, 0f, 3f)); rootNode.addLight(p2); // create the geometry and attach it Spatial elephant = (Spatial) assetManager.loadModel("Models/Elephant/Elephant.mesh.xml"); float scale = 0.05f; elephant.scale(scale, scale, scale); rootNode.attachChild(elephant); }
Example 4
Source File: TestModelExportingCloning.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleInitApp() { cam.setLocation(new Vector3f(10f, 3f, 40f)); cam.lookAtDirection(Vector3f.UNIT_Z.negate(), 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); AnimComposer composer; Spatial originalModel = assetManager.loadModel("Models/Oto/Oto.mesh.xml"); composer = originalModel.getControl(AnimComposer.class); composer.setCurrentAction("Walk"); composer.setGlobalSpeed(1.5f); rootNode.attachChild(originalModel); Spatial clonedModel = originalModel.clone(); clonedModel.move(10, 0, 0); composer = clonedModel.getControl(AnimComposer.class); composer.setCurrentAction("push"); System.out.println("clonedModel: globalSpeed=" + composer.getGlobalSpeed()); rootNode.attachChild(clonedModel); Spatial exportedModel = BinaryExporter.saveAndLoad(assetManager, originalModel); exportedModel.move(20, 0, 0); composer = exportedModel.getControl(AnimComposer.class); composer.setCurrentAction("pull"); System.out.println("exportedModel: globalSpeed=" + composer.getGlobalSpeed()); rootNode.attachChild(exportedModel); }
Example 5
Source File: TestSceneLoading.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleInitApp() { File file = new File("wildhouse.zip"); if (!file.exists()) { useHttp = true; } this.flyCam.setMoveSpeed(10); // load sky rootNode.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"); AmbientLight al = new AmbientLight(); scene.addLight(al); DirectionalLight sun = new DirectionalLight(); sun.setDirection(new Vector3f(0.69077975f, -0.6277887f, -0.35875428f).normalizeLocal()); sun.setColor(ColorRGBA.White.clone().multLocal(2)); scene.addLight(sun); rootNode.attachChild(scene); }
Example 6
Source File: TestHoveringTank.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleInitApp() { bulletAppState = new BulletAppState(); bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL); stateManager.attach(bulletAppState); // bulletAppState.getPhysicsSpace().enableDebug(assetManager); bulletAppState.getPhysicsSpace().setAccuracy(1f/30f); rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", EnvMapType.CubeMap)); DirectionalLightShadowRenderer dlsr = new DirectionalLightShadowRenderer(assetManager, 2048, 3); dlsr.setLambda(0.55f); dlsr.setShadowIntensity(0.6f); dlsr.setEdgeFilteringMode(EdgeFilteringMode.Bilinear); viewPort.addProcessor(dlsr); setupKeys(); createTerrain(); buildPlayer(); DirectionalLight dl = new DirectionalLight(); dlsr.setLight(dl); dl.setColor(new ColorRGBA(1.0f, 0.94f, 0.8f, 1f).multLocal(1.3f)); dl.setDirection(new Vector3f(-0.5f, -0.3f, -0.3f).normalizeLocal()); rootNode.addLight(dl); Vector3f lightDir2 = new Vector3f(0.70518064f, 0.5902297f, -0.39287305f); DirectionalLight dl2 = new DirectionalLight(); dl2.setColor(new ColorRGBA(0.7f, 0.85f, 1.0f, 1f)); dl2.setDirection(lightDir2); rootNode.addLight(dl2); }
Example 7
Source File: HelloPicking.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected Spatial makeCharacter() { // load a character from jme3test-test-data Spatial golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml"); golem.scale(0.5f); golem.setLocalTranslation(-1.0f, -1.5f, -0.6f); // We must add a light to make the model visible DirectionalLight sun = new DirectionalLight(); sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f)); golem.addLight(sun); return golem; }
Example 8
Source File: TestMotionPath.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void createScene() { Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat.setFloat("Shininess", 1f); mat.setBoolean("UseMaterialColors", true); mat.setColor("Ambient", ColorRGBA.Black); mat.setColor("Diffuse", ColorRGBA.DarkGray); mat.setColor("Specular", ColorRGBA.White.mult(0.6f)); Material matSoil = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); matSoil.setBoolean("UseMaterialColors", true); matSoil.setColor("Ambient", ColorRGBA.Black); matSoil.setColor("Diffuse", ColorRGBA.Black); matSoil.setColor("Specular", ColorRGBA.Black); teapot = assetManager.loadModel("Models/Teapot/Teapot.obj"); teapot.setName("Teapot"); teapot.setLocalScale(3); teapot.setMaterial(mat); rootNode.attachChild(teapot); Geometry soil = new Geometry("soil", new Box(50, 1, 50)); soil.setLocalTranslation(0, -1, 0); soil.setMaterial(matSoil); rootNode.attachChild(soil); DirectionalLight light = new DirectionalLight(); light.setDirection(new Vector3f(0, -1, 0).normalizeLocal()); light.setColor(ColorRGBA.White.mult(1.5f)); rootNode.addLight(light); }
Example 9
Source File: TestLightRadius.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleInitApp() { Torus torus = new Torus(10, 6, 1, 3); // Torus torus = new Torus(50, 30, 1, 3); Geometry g = new Geometry("Torus Geom", torus); g.rotate(-FastMath.HALF_PI, 0, 0); g.center(); // g.move(0, 1, 0); Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat.setFloat("Shininess", 32f); mat.setBoolean("UseMaterialColors", true); mat.setColor("Ambient", ColorRGBA.Black); mat.setColor("Diffuse", ColorRGBA.White); mat.setColor("Specular", ColorRGBA.White); // mat.setBoolean("VertexLighting", true); // mat.setBoolean("LowQuality", true); g.setMaterial(mat); rootNode.attachChild(g); lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f)); lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m")); rootNode.attachChild(lightMdl); pl = new PointLight(); pl.setColor(ColorRGBA.Green); pl.setRadius(4f); rootNode.addLight(pl); DirectionalLight dl = new DirectionalLight(); dl.setColor(ColorRGBA.Red); dl.setDirection(new Vector3f(0, 1, 0)); rootNode.addLight(dl); }
Example 10
Source File: TestHWSkinningOld.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleInitApp() { flyCam.setMoveSpeed(10f); flyCam.setDragToRotate(true); setPauseOnLostFocus(false); cam.setLocation(new Vector3f(24.746134f, 13.081396f, 32.72753f)); cam.setRotation(new Quaternion(-0.06867662f, 0.92435044f, -0.19981281f, -0.31770203f)); makeHudText(); 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); for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { Spatial model = assetManager.loadModel("Models/Oto/OtoOldAnim.j3o"); model.setLocalScale(0.1f); model.setLocalTranslation(i - SIZE / 2, 0, j - SIZE / 2); control = model.getControl(AnimControl.class); channel = control.createChannel(); channel.setAnim(animNames[(i + j) % 4]); SkeletonControl skeletonControl = model.getControl(SkeletonControl.class); skeletonControl.setHardwareSkinningPreferred(hwSkinningEnable); skControls.add(skeletonControl); rootNode.attachChild(model); } } inputManager.addListener(this, "toggleHWS"); inputManager.addMapping("toggleHWS", new KeyTrigger(KeyInput.KEY_SPACE)); }
Example 11
Source File: TestTransparentCartoonEdge.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void simpleInitApp() { renderManager.setAlphaToCoverage(true); cam.setLocation(new Vector3f(0.14914267f, 0.58147097f, 4.7686534f)); cam.setRotation(new Quaternion(-0.0044764364f, 0.9767943f, 0.21314798f, 0.020512417f)); // cam.setLocation(new Vector3f(2.0606942f, 3.20342f, 6.7860126f)); // cam.setRotation(new Quaternion(-0.017481906f, 0.98241085f, -0.12393151f, -0.13857932f)); viewPort.setBackgroundColor(ColorRGBA.DarkGray); Quad q = new Quad(20, 20); q.scaleTextureCoordinates(Vector2f.UNIT_XY.mult(5)); Geometry geom = new Geometry("floor", q); Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m"); geom.setMaterial(mat); geom.rotate(-FastMath.HALF_PI, 0, 0); geom.center(); geom.setShadowMode(ShadowMode.Receive); rootNode.attachChild(geom); // create the geometry and attach it Spatial teaGeom = assetManager.loadModel("Models/Tree/Tree2.mesh.xml"); teaGeom.setQueueBucket(Bucket.Transparent); teaGeom.setShadowMode(ShadowMode.Cast); makeToonish(teaGeom); AmbientLight al = new AmbientLight(); al.setColor(ColorRGBA.White.mult(2)); rootNode.addLight(al); DirectionalLight dl1 = new DirectionalLight(); dl1.setDirection(new Vector3f(1, -1, 1).normalizeLocal()); dl1.setColor(new ColorRGBA(0.965f, 0.949f, 0.772f, 1f).mult(0.7f)); rootNode.addLight(dl1); DirectionalLight dl = new DirectionalLight(); dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal()); dl.setColor(new ColorRGBA(0.965f, 0.949f, 0.772f, 1f).mult(0.7f)); rootNode.addLight(dl); rootNode.attachChild(teaGeom); FilterPostProcessor fpp=new FilterPostProcessor(assetManager); CartoonEdgeFilter toon=new CartoonEdgeFilter(); toon.setEdgeWidth(0.5f); toon.setEdgeIntensity(1.0f); toon.setNormalThreshold(0.8f); fpp.addFilter(toon); viewPort.addProcessor(fpp); }
Example 12
Source File: TestPostWaterLake.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); cam.setLocation(new Vector3f(-27.0f, 1.0f, 75.0f)); // cam.setRotation(new Quaternion(0.03f, 0.9f, 0f, 0.4f)); // load sky rootNode.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"); rootNode.attachChild(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); FilterPostProcessor fpp = new FilterPostProcessor(assetManager); final WaterFilter water = new WaterFilter(rootNode, lightDir); water.setWaterHeight(-20); water.setUseFoam(false); water.setUseRipples(false); water.setDeepWaterColor(ColorRGBA.Brown); water.setWaterColor(ColorRGBA.Brown.mult(2.0f)); water.setWaterTransparency(0.2f); water.setMaxAmplitude(0.3f); water.setWaveScale(0.008f); water.setSpeed(0.7f); water.setShoreHardness(1.0f); water.setRefractionConstant(0.2f); water.setShininess(0.3f); water.setSunScale(1.0f); water.setColorExtinction(new Vector3f(10.0f, 20.0f, 30.0f)); fpp.addFilter(water); viewPort.addProcessor(fpp); inputManager.addListener(new ActionListener() { @Override public void onAction(String name, boolean isPressed, float tpf) { if(isPressed){ if(water.isUseHQShoreline()){ water.setUseHQShoreline(false); }else{ water.setUseHQShoreline(true); } } } }, "HQ"); inputManager.addMapping("HQ", new KeyTrigger(keyInput.KEY_SPACE)); }
Example 13
Source File: TestRagdollCharacter.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
private void setupLight() { 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); }
Example 14
Source File: TestBatchNode.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void simpleInitApp() { timer = new NanoTimer(); batch = new BatchNode("theBatchNode"); /** * A cube with a color "bleeding" through transparent texture. Uses * Texture from jme3-test-data library! */ Box boxshape4 = new Box(Vector3f.ZERO, 1f, 1f, 1f ); cube = new Geometry("cube1", boxshape4); Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m"); cube.setMaterial(mat); // Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); // mat.setColor("Diffuse", ColorRGBA.Blue); // mat.setBoolean("UseMaterialColors", true); /** * A cube with a color "bleeding" through transparent texture. Uses * Texture from jme3-test-data library! */ Box box = new Box(Vector3f.ZERO, 1f, 1f, 1f); cube2 = new Geometry("cube2", box); cube2.setMaterial(mat); TangentBinormalGenerator.generate(cube); TangentBinormalGenerator.generate(cube2); n = new Node("aNode"); // n.attachChild(cube2); batch.attachChild(cube); batch.attachChild(cube2); // batch.setMaterial(mat); batch.batch(); rootNode.attachChild(batch); cube.setLocalTranslation(3, 0, 0); cube2.setLocalTranslation(0, 3, 0); dl=new DirectionalLight(); dl.setColor(ColorRGBA.White.mult(2)); dl.setDirection(new Vector3f(1, -1, -1)); rootNode.addLight(dl); flyCam.setMoveSpeed(10); }
Example 15
Source File: TestLightScattering.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void simpleInitApp() { // put the camera in a bad position cam.setLocation(new Vector3f(55.35316f, -0.27061665f, 27.092093f)); cam.setRotation(new Quaternion(0.010414706f, 0.9874893f, 0.13880467f, -0.07409228f)); // cam.setDirection(new Vector3f(0,-0.5f,1.0f)); // cam.setLocation(new Vector3f(0, 300, -500)); //cam.setFrustumFar(1000); flyCam.setMoveSpeed(10); Material mat = assetManager.loadMaterial("Textures/Terrain/Rocky/Rocky.j3m"); Spatial scene = assetManager.loadModel("Models/Terrain/Terrain.mesh.xml"); TangentBinormalGenerator.generate(((Geometry)((Node)scene).getChild(0)).getMesh()); scene.setMaterial(mat); scene.setShadowMode(ShadowMode.CastAndReceive); scene.setLocalScale(400); scene.setLocalTranslation(0, -10, -120); rootNode.attachChild(scene); // load sky rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/FullskiesBlueClear03.dds", false)); DirectionalLight sun = new DirectionalLight(); Vector3f lightDir = new Vector3f(-0.12f, -0.3729129f, 0.74847335f); sun.setDirection(lightDir); sun.setColor(ColorRGBA.White.clone().multLocal(2)); scene.addLight(sun); PssmShadowRenderer pssmRenderer = new PssmShadowRenderer(assetManager,1024,4); pssmRenderer.setDirection(lightDir); pssmRenderer.setShadowIntensity(0.55f); // viewPort.addProcessor(pssmRenderer); FilterPostProcessor fpp = new FilterPostProcessor(assetManager); // SSAOFilter ssaoFilter= new SSAOFilter(viewPort, new SSAOConfig(0.36f,1.8f,0.84f,0.16f,false,true)); // fpp.addFilter(ssaoFilter); // Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); // mat2.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); // // Sphere lite=new Sphere(8, 8, 10.0f); // Geometry lightSphere=new Geometry("lightsphere", lite); // lightSphere.setMaterial(mat2); Vector3f lightPos = lightDir.multLocal(-3000); // lightSphere.setLocalTranslation(lightPos); // rootNode.attachChild(lightSphere); LightScatteringFilter filter = new LightScatteringFilter(lightPos); LightScatteringUI ui = new LightScatteringUI(inputManager, filter); fpp.addFilter(filter); //fpp.setNumSamples(4); //fpp.addFilter(new RadialBlurFilter(0.3f,15.0f)); // SSAOUI ui=new SSAOUI(inputManager, ssaoFilter.getConfig()); viewPort.addProcessor(fpp); }
Example 16
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 17
Source File: TestSpatialAnim.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" 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; } TransformTrack transformTrack = new TransformTrack(geom, times, translations, rotations, scales); TransformTrack transformTrackChild = new TransformTrack(childGeom, times, translations, rotations, scales); // creating the animation AnimClip animClip = new AnimClip("anim"); animClip.setTracks(new AnimTrack[] { transformTrack, transformTrackChild }); // create spatial animation control AnimComposer animComposer = new AnimComposer(); animComposer.addAnimClip(animClip); model.addControl(animComposer); rootNode.attachChild(model); // run animation model.getControl(AnimComposer.class).setCurrentAction("anim"); }
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: TestPointDirectionalAndSpotLightShadows.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)); 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); scene.getLocalLightList().get(0).setColor(ColorRGBA.Red); plsr = new PointLightShadowRenderer(assetManager, SHADOWMAP_SIZE); plsr.setLight((PointLight) scene.getLocalLightList().get(0)); plsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4); plsf = new PointLightShadowFilter(assetManager, SHADOWMAP_SIZE); plsf.setLight((PointLight) scene.getLocalLightList().get(0)); plsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4); plsf.setEnabled(useFilter); //DIRECTIONAL LIGHT DirectionalLight directionalLight = new DirectionalLight(); rootNode.addLight(directionalLight); directionalLight.setColor(ColorRGBA.Blue); directionalLight.setDirection(new Vector3f(-1f, -.2f, 0f)); dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE*2, 4); dlsr.setLight(directionalLight); dlsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4); dlsf = new DirectionalLightShadowFilter(assetManager, SHADOWMAP_SIZE*2, 4); dlsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4); dlsf.setLight(directionalLight); dlsf.setEnabled(useFilter); //SPOT LIGHT spotLight = new SpotLight(); spotLight.setDirection(new Vector3f(1f,-1f,0f)); spotLight.setPosition(new Vector3f(-1f,3f,0f)); spotLight.setSpotOuterAngle(0.5f); spotLight.setColor(ColorRGBA.Green); Sphere sphere = new Sphere(8, 8, .1f); Geometry sphereGeometry = new Geometry("Sphere", sphere); sphereGeometry.setLocalTranslation(-1f, 3f, 0f); sphereGeometry.setMaterial(assetManager.loadMaterial("Common/Materials/WhiteColor.j3m")); rootNode.attachChild(sphereGeometry); rootNode.addLight(spotLight); slsr = new SpotLightShadowRenderer(assetManager, SHADOWMAP_SIZE); slsr.setLight(spotLight); slsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4); slsf = new SpotLightShadowFilter(assetManager, SHADOWMAP_SIZE); slsf.setLight(spotLight); slsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4); slsf.setEnabled(useFilter); if (!useFilter)viewPort.addProcessor(slsr); if (!useFilter)viewPort.addProcessor(plsr); if (!useFilter)viewPort.addProcessor(dlsr); FilterPostProcessor fpp = new FilterPostProcessor(assetManager); fpp.addFilter(plsf); fpp.addFilter(dlsf); fpp.addFilter(slsf); viewPort.addProcessor(fpp); ShadowTestUIManager uiMan = new ShadowTestUIManager(assetManager, plsr, plsf, guiNode, inputManager, viewPort); ShadowTestUIManager uiManPls = new ShadowTestUIManager(assetManager, plsr, plsf, guiNode, inputManager, viewPort); ShadowTestUIManager uiManDls = new ShadowTestUIManager(assetManager, dlsr, dlsf, guiNode, inputManager, viewPort); ShadowTestUIManager uiManSls = new ShadowTestUIManager(assetManager, slsr, slsf, guiNode, inputManager, viewPort); }
Example 20
Source File: TestMultiplesFilters.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void simpleInitApp() { this.flyCam.setMoveSpeed(10); cam.setLocation(new Vector3f(6.0344796f, 1.5054002f, 55.572033f)); cam.setRotation(new Quaternion(0.0016069f, 0.9810479f, -0.008143323f, 0.19358753f)); // load sky rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", 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(); sun.setDirection(new Vector3f(-0.4790551f, -0.39247334f, -0.7851566f)); sun.setColor(ColorRGBA.White.clone().multLocal(2)); scene.addLight(sun); fpp = new FilterPostProcessor(assetManager); // fpp.setNumSamples(4); ssaoFilter = new SSAOFilter(0.92f, 2.2f, 0.46f, 0.2f); final WaterFilter water=new WaterFilter(rootNode,new Vector3f(-0.4790551f, -0.39247334f, -0.7851566f)); water.setWaterHeight(-20); SSAOUI ui=new SSAOUI(inputManager,ssaoFilter); final BloomFilter bloom = new BloomFilter(); final ColorOverlayFilter overlay = new ColorOverlayFilter(ColorRGBA.LightGray); fpp.addFilter(ssaoFilter); fpp.addFilter(water); fpp.addFilter(bloom); fpp.addFilter(overlay); viewPort.addProcessor(fpp); rootNode.attachChild(scene); inputManager.addListener(new ActionListener() { public void onAction(String name, boolean isPressed, float tpf) { if ("toggleSSAO".equals(name) && isPressed) { if (ssaoFilter.isEnabled()) { ssaoFilter.setEnabled(false); } else { ssaoFilter.setEnabled(true); } } if ("toggleWater".equals(name) && isPressed) { if (water.isEnabled()) { water.setEnabled(false); } else { water.setEnabled(true); } } if ("toggleBloom".equals(name) && isPressed) { if (bloom.isEnabled()) { bloom.setEnabled(false); } else { bloom.setEnabled(true); } } if ("toggleOverlay".equals(name) && isPressed) { if (overlay.isEnabled()) { overlay.setEnabled(false); } else { overlay.setEnabled(true); } } } }, "toggleSSAO", "toggleBloom", "toggleWater","toggleOverlay"); inputManager.addMapping("toggleSSAO", new KeyTrigger(KeyInput.KEY_1)); inputManager.addMapping("toggleWater", new KeyTrigger(KeyInput.KEY_2)); inputManager.addMapping("toggleBloom", new KeyTrigger(KeyInput.KEY_3)); inputManager.addMapping("toggleOverlay", new KeyTrigger(KeyInput.KEY_4)); }