Search in sources :

Example 36 with Geometry

use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.

the class TestTessellationShader method simpleInitApp.

@Override
public void simpleInitApp() {
    tessellationMaterial = new Material(getAssetManager(), "Materials/Tess/SimpleTess.j3md");
    tessellationMaterial.setInt("TessellationFactor", tessFactor);
    tessellationMaterial.getAdditionalRenderState().setWireframe(true);
    Quad quad = new Quad(10, 10);
    quad.clearBuffer(VertexBuffer.Type.Index);
    quad.setBuffer(VertexBuffer.Type.Index, 4, BufferUtils.createIntBuffer(0, 1, 2, 3));
    quad.setMode(Mesh.Mode.Patch);
    quad.setPatchVertexCount(4);
    Geometry geometry = new Geometry("tessTest", quad);
    geometry.setMaterial(tessellationMaterial);
    rootNode.attachChild(geometry);
    getInputManager().addMapping("TessUp", new KeyTrigger(KeyInput.KEY_O));
    getInputManager().addMapping("TessDo", new KeyTrigger(KeyInput.KEY_L));
    getInputManager().addListener(new AnalogListener() {

        @Override
        public void onAnalog(String name, float value, float tpf) {
            if (name.equals("TessUp")) {
                tessFactor++;
                enqueue(new Callable<Boolean>() {

                    @Override
                    public Boolean call() throws Exception {
                        tessellationMaterial.setInt("TessellationFactor", tessFactor);
                        return true;
                    }
                });
            }
            if (name.equals("TessDo")) {
                tessFactor--;
                enqueue(new Callable<Boolean>() {

                    @Override
                    public Boolean call() throws Exception {
                        tessellationMaterial.setInt("TessellationFactor", tessFactor);
                        return true;
                    }
                });
            }
        }
    }, "TessUp", "TessDo");
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) KeyTrigger(com.jme3.input.controls.KeyTrigger) Material(com.jme3.material.Material) AnalogListener(com.jme3.input.controls.AnalogListener) Callable(java.util.concurrent.Callable)

Example 37 with Geometry

use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.

the class TestHoverTank method simpleInitApp.

@Override
public void simpleInitApp() {
    Node tank = (Node) assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");
    flyCam.setEnabled(false);
    ChaseCamera chaseCam = new ChaseCamera(cam, tank, inputManager);
    chaseCam.setSmoothMotion(true);
    chaseCam.setMaxDistance(100000);
    chaseCam.setMinVerticalRotation(-FastMath.PI / 2);
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    Geometry tankGeom = (Geometry) tank.getChild(0);
    LodControl control = new LodControl();
    tankGeom.addControl(control);
    rootNode.attachChild(tank);
    Vector3f lightDir = new Vector3f(-0.8719428f, -0.46824604f, 0.14304268f);
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(new ColorRGBA(1.0f, 0.92f, 0.75f, 1f));
    dl.setDirection(lightDir);
    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(dl);
    rootNode.addLight(dl2);
    rootNode.attachChild(tank);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    BloomFilter bf = new BloomFilter(BloomFilter.GlowMode.Objects);
    bf.setBloomIntensity(2.0f);
    bf.setExposurePower(1.3f);
    fpp.addFilter(bf);
    BloomUI bui = new BloomUI(inputManager, bf);
    viewPort.addProcessor(fpp);
}
Also used : Geometry(com.jme3.scene.Geometry) BloomUI(jme3test.post.BloomUI) LodControl(com.jme3.scene.control.LodControl) ColorRGBA(com.jme3.math.ColorRGBA) Node(com.jme3.scene.Node) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) ChaseCamera(com.jme3.input.ChaseCamera) FilterPostProcessor(com.jme3.post.FilterPostProcessor) BloomFilter(com.jme3.post.filters.BloomFilter)

Example 38 with Geometry

use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRendererVR method postFrame.

public void postFrame(FrameBuffer out) {
    if (skipPostPass) {
        return;
    }
    if (debug) {
        displayShadowMap(renderManager.getRenderer());
    }
    getReceivers(lightReceivers);
    if (lightReceivers.size() != 0) {
        //setting params to recieving geometry list
        setMatParams(lightReceivers);
        Camera cam = viewPort.getCamera();
        //some materials in the scene does not have a post shadow technique so we're using the fall back material
        if (needsfallBackMaterial) {
            renderManager.setForcedMaterial(postshadowMat);
        }
        //forcing the post shadow technique and render state
        renderManager.setForcedTechnique(postTechniqueName);
        //rendering the post shadow pass
        viewPort.getQueue().renderShadowQueue(lightReceivers, renderManager, cam, false);
        //resetting renderManager settings
        renderManager.setForcedTechnique(null);
        renderManager.setForcedMaterial(null);
        renderManager.setCamera(cam, false);
        //clearing the params in case there are some other shadow renderers
        clearMatParams();
    }
}
Also used : Camera(com.jme3.renderer.Camera)

Example 39 with Geometry

use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.

the class ShadowUtil method getGeometriesInCamFrustum.

/**
     * Populates the outputGeometryList with the geometry of the
     * inputGeomtryList that are in the frustum of the given camera
     *
     * @param inputGeometryList The list containing all geometry to check
     * against the camera frustum
     * @param camera the camera to check geometries against
     * @param outputGeometryList the list of all geometries that are in the
     * camera frustum
     */
public static void getGeometriesInCamFrustum(GeometryList inputGeometryList, Camera camera, GeometryList outputGeometryList) {
    for (int i = 0; i < inputGeometryList.size(); i++) {
        Geometry g = inputGeometryList.get(i);
        int planeState = camera.getPlaneState();
        camera.setPlaneState(0);
        if (camera.contains(g.getWorldBound()) != Camera.FrustumIntersect.Outside) {
            outputGeometryList.add(g);
        }
        camera.setPlaneState(planeState);
    }
}
Also used : Geometry(com.jme3.scene.Geometry)

Example 40 with Geometry

use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.

the class ShadowUtil method addGeometriesInCamFrustumAndViewPortFromNode.

/**
     * Helper function to recursively collect the geometries for getLitGeometriesInViewPort function.
     * 
     * @param vpCamera the viewPort camera 
     * @param cameras the camera array to check geometries against, representing the light viewspace
     * @param scene the Node to traverse or geometry to possibly add
     * @param outputGeometryList the output list of all geometries that are in the camera frustum
     */
private static void addGeometriesInCamFrustumAndViewPortFromNode(Camera vpCamera, Camera[] cameras, Spatial scene, RenderQueue.ShadowMode mode, GeometryList outputGeometryList) {
    if (scene.getCullHint() == Spatial.CullHint.Always)
        return;
    boolean inFrustum = false;
    for (int j = 0; j < cameras.length && inFrustum == false; j++) {
        Camera camera = cameras[j];
        int planeState = camera.getPlaneState();
        camera.setPlaneState(0);
        inFrustum = camera.contains(scene.getWorldBound()) != Camera.FrustumIntersect.Outside && scene.checkCulling(vpCamera);
        camera.setPlaneState(planeState);
    }
    if (inFrustum) {
        if (scene instanceof Node) {
            Node node = (Node) scene;
            for (Spatial child : node.getChildren()) {
                addGeometriesInCamFrustumAndViewPortFromNode(vpCamera, cameras, child, mode, outputGeometryList);
            }
        } else if (scene instanceof Geometry) {
            if (checkShadowMode(scene.getShadowMode(), mode) && !((Geometry) scene).isGrouped()) {
                outputGeometryList.add((Geometry) scene);
            }
        }
    }
}
Also used : Geometry(com.jme3.scene.Geometry) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) Camera(com.jme3.renderer.Camera)

Aggregations

Geometry (com.jme3.scene.Geometry)246 Material (com.jme3.material.Material)175 Vector3f (com.jme3.math.Vector3f)116 Box (com.jme3.scene.shape.Box)92 DirectionalLight (com.jme3.light.DirectionalLight)56 Node (com.jme3.scene.Node)54 Sphere (com.jme3.scene.shape.Sphere)49 Spatial (com.jme3.scene.Spatial)41 Quaternion (com.jme3.math.Quaternion)39 Quad (com.jme3.scene.shape.Quad)33 Texture (com.jme3.texture.Texture)30 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)26 Mesh (com.jme3.scene.Mesh)25 KeyTrigger (com.jme3.input.controls.KeyTrigger)24 AmbientLight (com.jme3.light.AmbientLight)24 ColorRGBA (com.jme3.math.ColorRGBA)21 FilterPostProcessor (com.jme3.post.FilterPostProcessor)21 PointLight (com.jme3.light.PointLight)20 Vector2f (com.jme3.math.Vector2f)17 FloatBuffer (java.nio.FloatBuffer)17