Search in sources :

Example 1 with WireFrustum

use of com.jme3.scene.debug.WireFrustum in project jmonkeyengine by jMonkeyEngine.

the class TestConeVSFrustum method simpleInitApp.

@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    frustumCam = cam.clone();
    frustumCam.setFrustumFar(25);
    Vector3f[] points = new Vector3f[8];
    for (int i = 0; i < 8; i++) {
        points[i] = new Vector3f();
    }
    ShadowUtil.updateFrustumPoints2(frustumCam, points);
    WireFrustum frustumShape = new WireFrustum(points);
    Geometry frustum = new Geometry("frustum", frustumShape);
    frustum.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
    rootNode.attachChild(frustum);
    rootNode.addLight(new DirectionalLight());
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.2f));
    rootNode.addLight(al);
    Grid grid = new Grid(50, 50, 5);
    Geometry gridGeom = new Geometry("grid", grid);
    gridGeom.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
    gridGeom.getMaterial().setColor("Color", ColorRGBA.Gray);
    rootNode.attachChild(gridGeom);
    gridGeom.setLocalTranslation(-125, -25, -125);
    //        flyCam.setMoveSpeed(30);
    //        flyCam.setDragToRotate(true);
    //        cam.setLocation(new Vector3f(56.182674f, 19.037334f, 7.093905f));
    //        cam.setRotation(new Quaternion(0.0816657f, -0.82228005f, 0.12213967f, 0.5497892f));
    spotLight = new SpotLight();
    spotLight.setSpotRange(25);
    spotLight.setSpotOuterAngle(10 * FastMath.DEG_TO_RAD);
    float radius = FastMath.tan(spotLight.getSpotOuterAngle()) * spotLight.getSpotRange();
    Cylinder cylinder = new Cylinder(5, 16, 0, radius, spotLight.getSpotRange(), true, false);
    geom = new Geometry("light", cylinder);
    geom.setMaterial(new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"));
    geom.getMaterial().setColor("Diffuse", ColorRGBA.White);
    geom.getMaterial().setColor("Ambient", ColorRGBA.DarkGray);
    geom.getMaterial().setBoolean("UseMaterialColors", true);
    final LightNode ln = new LightNode("lb", spotLight);
    ln.attachChild(geom);
    geom.setLocalTranslation(0, -spotLight.getSpotRange() / 2f, 0);
    geom.rotate(-FastMath.HALF_PI, 0, 0);
    rootNode.attachChild(ln);
    //        ln.rotate(FastMath.QUARTER_PI, 0, 0);
    //      ln.setLocalTranslation(0, 0, -16);
    inputManager.addMapping("click", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
    inputManager.addMapping("shift", new KeyTrigger(KeyInput.KEY_LSHIFT), new KeyTrigger(KeyInput.KEY_RSHIFT));
    inputManager.addMapping("middleClick", new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
    inputManager.addMapping("up", new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    inputManager.addMapping("down", new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    inputManager.addMapping("left", new MouseAxisTrigger(MouseInput.AXIS_X, true));
    inputManager.addMapping("right", new MouseAxisTrigger(MouseInput.AXIS_X, false));
    final Node camTarget = new Node("CamTarget");
    rootNode.attachChild(camTarget);
    ChaseCameraAppState chaser = new ChaseCameraAppState();
    chaser.setTarget(camTarget);
    chaser.setMaxDistance(150);
    chaser.setDefaultDistance(70);
    chaser.setDefaultHorizontalRotation(FastMath.HALF_PI);
    chaser.setMinVerticalRotation(-FastMath.PI);
    chaser.setMaxVerticalRotation(FastMath.PI * 2);
    chaser.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    stateManager.attach(chaser);
    flyCam.setEnabled(false);
    inputManager.addListener(new AnalogListener() {

        public void onAnalog(String name, float value, float tpf) {
            Spatial s = null;
            float mult = 1;
            if (moving) {
                s = ln;
            }
            if (panning) {
                s = camTarget;
                mult = -1;
            }
            if ((moving || panning) && s != null) {
                if (shift) {
                    if (name.equals("left")) {
                        tmp.set(cam.getDirection());
                        s.rotate(tmpQuat.fromAngleAxis(value, tmp));
                    }
                    if (name.equals("right")) {
                        tmp.set(cam.getDirection());
                        s.rotate(tmpQuat.fromAngleAxis(-value, tmp));
                    }
                } else {
                    value *= MOVE_SPEED * mult;
                    if (name.equals("up")) {
                        tmp.set(cam.getUp()).multLocal(value);
                        s.move(tmp);
                    }
                    if (name.equals("down")) {
                        tmp.set(cam.getUp()).multLocal(-value);
                        s.move(tmp);
                    }
                    if (name.equals("left")) {
                        tmp.set(cam.getLeft()).multLocal(value);
                        s.move(tmp);
                    }
                    if (name.equals("right")) {
                        tmp.set(cam.getLeft()).multLocal(-value);
                        s.move(tmp);
                    }
                }
            }
        }
    }, "up", "down", "left", "right");
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("click")) {
                if (isPressed) {
                    moving = true;
                } else {
                    moving = false;
                }
            }
            if (name.equals("middleClick")) {
                if (isPressed) {
                    panning = true;
                } else {
                    panning = false;
                }
            }
            if (name.equals("shift")) {
                if (isPressed) {
                    shift = true;
                } else {
                    shift = false;
                }
            }
        }
    }, "click", "middleClick", "shift");
    /**
         * An unshaded textured cube. // * Uses texture from jme3-test-data
         * library!
         */
    Box boxMesh = new Box(1f, 1f, 1f);
    boxGeo = new Geometry("A Textured Box", boxMesh);
    Material boxMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    Texture monkeyTex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
    boxMat.setTexture("ColorMap", monkeyTex);
    boxGeo.setMaterial(boxMat);
    //        rootNode.attachChild(boxGeo);
    //
    //boxGeo2 = boxGeo.clone();
    //rootNode.attachChild(boxGeo2); 
    System.err.println("light " + spotLight.getPosition());
}
Also used : Grid(com.jme3.scene.debug.Grid) KeyTrigger(com.jme3.input.controls.KeyTrigger) MouseAxisTrigger(com.jme3.input.controls.MouseAxisTrigger) LightNode(com.jme3.scene.LightNode) Node(com.jme3.scene.Node) SpotLight(com.jme3.light.SpotLight) Texture(com.jme3.texture.Texture) LightNode(com.jme3.scene.LightNode) DirectionalLight(com.jme3.light.DirectionalLight) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) ChaseCameraAppState(com.jme3.app.ChaseCameraAppState) Geometry(com.jme3.scene.Geometry) Cylinder(com.jme3.scene.shape.Cylinder) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) WireFrustum(com.jme3.scene.debug.WireFrustum) AnalogListener(com.jme3.input.controls.AnalogListener) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) AmbientLight(com.jme3.light.AmbientLight)

Example 2 with WireFrustum

use of com.jme3.scene.debug.WireFrustum in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRenderer method createFrustum.

/**
     * debug function to create a visible frustum
     */
protected Geometry createFrustum(Vector3f[] pts, int i) {
    WireFrustum frustum = new WireFrustum(pts);
    Geometry frustumMdl = new Geometry("f", frustum);
    frustumMdl.setCullHint(Spatial.CullHint.Never);
    frustumMdl.setShadowMode(ShadowMode.Off);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    frustumMdl.setMaterial(mat);
    switch(i) {
        case 0:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Pink);
            break;
        case 1:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
            break;
        case 2:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Green);
            break;
        case 3:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Blue);
            break;
        default:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.White);
            break;
    }
    frustumMdl.updateGeometricState();
    return frustumMdl;
}
Also used : Geometry(com.jme3.scene.Geometry) WireFrustum(com.jme3.scene.debug.WireFrustum) Material(com.jme3.material.Material)

Example 3 with WireFrustum

use of com.jme3.scene.debug.WireFrustum in project jmonkeyengine by jMonkeyEngine.

the class PssmShadowRenderer method createFrustum.

//debug function that create a displayable frustrum
private Geometry createFrustum(Vector3f[] pts, int i) {
    WireFrustum frustum = new WireFrustum(pts);
    Geometry frustumMdl = new Geometry("f", frustum);
    frustumMdl.setCullHint(Spatial.CullHint.Never);
    frustumMdl.setShadowMode(ShadowMode.Off);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    frustumMdl.setMaterial(mat);
    switch(i) {
        case 0:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Pink);
            break;
        case 1:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
            break;
        case 2:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Green);
            break;
        case 3:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Blue);
            break;
        default:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.White);
            break;
    }
    frustumMdl.updateGeometricState();
    return frustumMdl;
}
Also used : Geometry(com.jme3.scene.Geometry) WireFrustum(com.jme3.scene.debug.WireFrustum) Material(com.jme3.material.Material)

Example 4 with WireFrustum

use of com.jme3.scene.debug.WireFrustum in project jmonkeyengine by jMonkeyEngine.

the class TestBatchNode method simpleInitApp.

@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(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(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, 20, 0);
    updateBoindPoints(points);
    frustum = new WireFrustum(points);
    frustumMdl = new Geometry("f", frustum);
    frustumMdl.setCullHint(Spatial.CullHint.Never);
    frustumMdl.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
    frustumMdl.getMaterial().getAdditionalRenderState().setWireframe(true);
    frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
    rootNode.attachChild(frustumMdl);
    dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White.mult(2));
    dl.setDirection(new Vector3f(1, -1, -1));
    rootNode.addLight(dl);
    flyCam.setMoveSpeed(10);
}
Also used : Geometry(com.jme3.scene.Geometry) NanoTimer(com.jme3.system.NanoTimer) WireFrustum(com.jme3.scene.debug.WireFrustum) Node(com.jme3.scene.Node) BatchNode(com.jme3.scene.BatchNode) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) BoundingBox(com.jme3.bounding.BoundingBox) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) BatchNode(com.jme3.scene.BatchNode)

Example 5 with WireFrustum

use of com.jme3.scene.debug.WireFrustum 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)

Aggregations

Material (com.jme3.material.Material)6 Geometry (com.jme3.scene.Geometry)6 WireFrustum (com.jme3.scene.debug.WireFrustum)6 Box (com.jme3.scene.shape.Box)3 DirectionalLight (com.jme3.light.DirectionalLight)2 Vector3f (com.jme3.math.Vector3f)2 Node (com.jme3.scene.Node)2 ChaseCameraAppState (com.jme3.app.ChaseCameraAppState)1 BoundingBox (com.jme3.bounding.BoundingBox)1 ActionListener (com.jme3.input.controls.ActionListener)1 AnalogListener (com.jme3.input.controls.AnalogListener)1 KeyTrigger (com.jme3.input.controls.KeyTrigger)1 MouseAxisTrigger (com.jme3.input.controls.MouseAxisTrigger)1 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)1 AmbientLight (com.jme3.light.AmbientLight)1 SpotLight (com.jme3.light.SpotLight)1 Quaternion (com.jme3.math.Quaternion)1 BatchNode (com.jme3.scene.BatchNode)1 LightNode (com.jme3.scene.LightNode)1 Spatial (com.jme3.scene.Spatial)1