Search in sources :

Example 56 with Sphere

use of com.jme3.scene.shape.Sphere in project jmonkeyengine by jMonkeyEngine.

the class TestPssmShadow method loadScene.

public void loadScene() {
    obj = new Spatial[2];
    mat = new Material[2];
    mat[0] = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
    mat[1] = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    mat[1].setBoolean("UseMaterialColors", true);
    mat[1].setColor("Ambient", ColorRGBA.White.mult(0.5f));
    mat[1].setColor("Diffuse", ColorRGBA.White.clone());
    obj[0] = new Geometry("sphere", new Sphere(30, 30, 2));
    obj[0].setShadowMode(ShadowMode.CastAndReceive);
    obj[1] = new Geometry("cube", new Box(1.0f, 1.0f, 1.0f));
    obj[1].setShadowMode(ShadowMode.CastAndReceive);
    TangentBinormalGenerator.generate(obj[1]);
    TangentBinormalGenerator.generate(obj[0]);
    for (int i = 0; i < 60; i++) {
        Spatial t = obj[FastMath.nextRandomInt(0, obj.length - 1)].clone(false);
        t.setLocalScale(FastMath.nextRandomFloat() * 10f);
        t.setMaterial(mat[FastMath.nextRandomInt(0, mat.length - 1)]);
        rootNode.attachChild(t);
        t.setLocalTranslation(FastMath.nextRandomFloat() * 200f, FastMath.nextRandomFloat() * 30f + 20, 30f * (i + 2f));
    }
    Box b = new Box(1000, 2, 1000);
    b.scaleTextureCoordinates(new Vector2f(10, 10));
    ground = new Geometry("soil", b);
    ground.setLocalTranslation(0, 10, 550);
    matGroundU = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matGroundU.setColor("Color", ColorRGBA.Green);
    matGroundL = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matGroundL.setTexture("DiffuseMap", grass);
    ground.setMaterial(matGroundL);
    ground.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(ground);
    l = new DirectionalLight();
    l.setDirection(new Vector3f(-1, -1, -1));
    rootNode.addLight(l);
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.5f));
    rootNode.addLight(al);
    Spatial sky = SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false);
    sky.setLocalScale(350);
    rootNode.attachChild(sky);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) Spatial(com.jme3.scene.Spatial) Vector2f(com.jme3.math.Vector2f) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture) AmbientLight(com.jme3.light.AmbientLight)

Example 57 with Sphere

use of com.jme3.scene.shape.Sphere in project jmonkeyengine by jMonkeyEngine.

the class TestShadow method simpleInitApp.

@Override
public void simpleInitApp() {
    // put the camera in a bad position
    cam.setLocation(new Vector3f(0.7804813f, 1.7502685f, -2.1556435f));
    cam.setRotation(new Quaternion(0.1961598f, -0.7213164f, 0.2266092f, 0.6243975f));
    cam.setFrustumFar(10);
    Material mat = assetManager.loadMaterial("Common/Materials/WhiteColor.j3m");
    rootNode.setShadowMode(ShadowMode.Off);
    Box floor = new Box(3, 0.1f, 3);
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(mat);
    floorGeom.setLocalTranslation(0, -0.2f, 0);
    floorGeom.setShadowMode(ShadowMode.Receive);
    rootNode.attachChild(floorGeom);
    teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.setLocalScale(2f);
    teapot.setMaterial(mat);
    teapot.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(teapot);
    //        lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    //        lightMdl.setMaterial(mat);
    //        // disable shadowing for light representation
    //        lightMdl.setShadowMode(ShadowMode.Off);
    //        rootNode.attachChild(lightMdl);
    bsr = new BasicShadowRenderer(assetManager, 512);
    bsr.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    viewPort.addProcessor(bsr);
    frustum = new WireFrustum(bsr.getPoints());
    frustumMdl = new Geometry("f", frustum);
    frustumMdl.setCullHint(Spatial.CullHint.Never);
    frustumMdl.setShadowMode(ShadowMode.Off);
    frustumMdl.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
    frustumMdl.getMaterial().getAdditionalRenderState().setWireframe(true);
    frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
    rootNode.attachChild(frustumMdl);
}
Also used : Geometry(com.jme3.scene.Geometry) Quaternion(com.jme3.math.Quaternion) WireFrustum(com.jme3.scene.debug.WireFrustum) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) BasicShadowRenderer(com.jme3.shadow.BasicShadowRenderer)

Example 58 with Sphere

use of com.jme3.scene.shape.Sphere in project jmonkeyengine by jMonkeyEngine.

the class TestSpotLight method setupLighting.

public void setupLighting() {
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.02f));
    rootNode.addLight(al);
    spot = new SpotLight();
    spot.setSpotRange(1000);
    spot.setSpotInnerAngle(5 * FastMath.DEG_TO_RAD);
    spot.setSpotOuterAngle(10 * FastMath.DEG_TO_RAD);
    spot.setPosition(new Vector3f(77.70334f, 34.013165f, 27.1017f));
    spot.setDirection(lightTarget.subtract(spot.getPosition()));
    spot.setColor(ColorRGBA.White.mult(2));
    rootNode.addLight(spot);
    //        PointLight pl=new PointLight();
    //      pl.setPosition(new Vector3f(77.70334f, 34.013165f, 27.1017f));
    //      pl.setRadius(1000);     
    //      pl.setColor(ColorRGBA.White.mult(2));
    //      rootNode.addLight(pl);
    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    lightMdl.setLocalTranslation(new Vector3f(77.70334f, 34.013165f, 27.1017f));
    lightMdl.setLocalScale(5);
    rootNode.attachChild(lightMdl);
//        DirectionalLight dl = new DirectionalLight();
//        dl.setDirection(lightTarget.subtract(new Vector3f(77.70334f, 34.013165f, 27.1017f)));
//        dl.setColor(ColorRGBA.White.mult(2));
//        rootNode.addLight(dl);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) SpotLight(com.jme3.light.SpotLight) AmbientLight(com.jme3.light.AmbientLight)

Example 59 with Sphere

use of com.jme3.scene.shape.Sphere in project jmonkeyengine by jMonkeyEngine.

the class TestSpotLightShadows method setupLighting.

public void setupLighting() {
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.02f));
    rootNode.addLight(al);
    rootNode.setShadowMode(ShadowMode.CastAndReceive);
    spot = new SpotLight();
    spot.setSpotRange(1000);
    spot.setSpotInnerAngle(5f * FastMath.DEG_TO_RAD);
    spot.setSpotOuterAngle(10 * FastMath.DEG_TO_RAD);
    spot.setPosition(new Vector3f(70.70334f, 34.013165f, 27.1017f));
    spot.setDirection(lightTarget.subtract(spot.getPosition()).normalizeLocal());
    spot.setColor(ColorRGBA.White.mult(2));
    rootNode.addLight(spot);
    //        PointLight pl=new PointLight();
    //      pl.setPosition(new Vector3f(77.70334f, 34.013165f, 27.1017f));
    //      pl.setRadius(1000);     
    //      pl.setColor(ColorRGBA.White.mult(2));
    //      rootNode.addLight(pl);
    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    lightMdl.setLocalTranslation(new Vector3f(77.70334f, 34.013165f, 27.1017f));
    lightMdl.setLocalScale(5);
    rootNode.attachChild(lightMdl);
    //        DirectionalLight dl = new DirectionalLight();
    //        dl.setDirection(lightTarget.subtract(new Vector3f(77.70334f, 34.013165f, 27.1017f)));
    //        dl.setColor(ColorRGBA.White.mult(0.7f));
    //        rootNode.addLight(dl);
    final SpotLightShadowRenderer slsr = new SpotLightShadowRenderer(assetManager, 512);
    slsr.setLight(spot);
    slsr.setShadowIntensity(0.5f);
    slsr.setShadowZExtend(100);
    slsr.setShadowZFadeLength(5);
    slsr.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
    viewPort.addProcessor(slsr);
    SpotLightShadowFilter slsf = new SpotLightShadowFilter(assetManager, 512);
    slsf.setLight(spot);
    slsf.setShadowIntensity(0.5f);
    slsf.setShadowZExtend(100);
    slsf.setShadowZFadeLength(5);
    slsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
    slsf.setEnabled(false);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(slsf);
    viewPort.addProcessor(fpp);
    ShadowTestUIManager uiMan = new ShadowTestUIManager(assetManager, slsr, slsf, guiNode, inputManager, viewPort);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("stop") && isPressed) {
                stop = !stop;
                //   slsr.displayFrustum();
                System.out.println("pos : " + spot.getPosition());
                System.out.println("dir : " + spot.getDirection());
            }
        }
    }, "stop");
    inputManager.addMapping("stop", new KeyTrigger(KeyInput.KEY_1));
    flyCam.setDragToRotate(true);
}
Also used : SpotLightShadowFilter(com.jme3.shadow.SpotLightShadowFilter) KeyTrigger(com.jme3.input.controls.KeyTrigger) FilterPostProcessor(com.jme3.post.FilterPostProcessor) SpotLightShadowRenderer(com.jme3.shadow.SpotLightShadowRenderer) SpotLight(com.jme3.light.SpotLight) Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) ActionListener(com.jme3.input.controls.ActionListener) AmbientLight(com.jme3.light.AmbientLight)

Example 60 with Sphere

use of com.jme3.scene.shape.Sphere in project jmonkeyengine by jMonkeyEngine.

the class TestTangentGen method simpleInitApp.

@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(20);
    Sphere sphereMesh = new Sphere(32, 32, 1);
    sphereMesh.setTextureMode(Sphere.TextureMode.Projected);
    sphereMesh.updateGeometry(32, 32, 1, false, false);
    addMesh("Sphere", sphereMesh, new Vector3f(-1, 0, 0));
    Quad quadMesh = new Quad(1, 1);
    quadMesh.updateGeometry(1, 1);
    addMesh("Quad", quadMesh, new Vector3f(1, 0, 0));
    Mesh strip = createTriangleStripMesh();
    addMesh("strip", strip, new Vector3f(0, -3, 0));
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(1, -1, -1).normalizeLocal());
    dl.setColor(ColorRGBA.White);
    rootNode.addLight(dl);
}
Also used : Sphere(com.jme3.scene.shape.Sphere) Quad(com.jme3.scene.shape.Quad) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) Mesh(com.jme3.scene.Mesh)

Aggregations

Sphere (com.jme3.scene.shape.Sphere)63 Geometry (com.jme3.scene.Geometry)58 Vector3f (com.jme3.math.Vector3f)57 Material (com.jme3.material.Material)46 DirectionalLight (com.jme3.light.DirectionalLight)23 Box (com.jme3.scene.shape.Box)22 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)17 Node (com.jme3.scene.Node)17 PointLight (com.jme3.light.PointLight)15 BulletAppState (com.jme3.bullet.BulletAppState)13 SphereCollisionShape (com.jme3.bullet.collision.shapes.SphereCollisionShape)13 BoundingSphere (com.jme3.bounding.BoundingSphere)12 AmbientLight (com.jme3.light.AmbientLight)12 Quaternion (com.jme3.math.Quaternion)11 ColorRGBA (com.jme3.math.ColorRGBA)10 Spatial (com.jme3.scene.Spatial)9 TempVars (com.jme3.util.TempVars)9 KeyTrigger (com.jme3.input.controls.KeyTrigger)8 Vector2f (com.jme3.math.Vector2f)8 MeshCollisionShape (com.jme3.bullet.collision.shapes.MeshCollisionShape)7