Java Code Examples for com.jme3.renderer.Camera#setPlaneState()

The following examples show how to use com.jme3.renderer.Camera#setPlaneState() . 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: ShadowUtil.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Helper function used to recursively populate the outputGeometryList 
 * with geometry children of scene node
 * 
 * @param camera
 * @param scene
 * @param outputGeometryList 
 */
private static void addGeometriesInCamFrustumFromNode(Camera camera, Node scene, RenderQueue.ShadowMode mode, GeometryList outputGeometryList) {
    if (scene.getCullHint() == Spatial.CullHint.Always) return;
    camera.setPlaneState(0);
    if (camera.contains(scene.getWorldBound()) != Camera.FrustumIntersect.Outside) {
        for (Spatial child: scene.getChildren()) {
            if (child instanceof Node) addGeometriesInCamFrustumFromNode(camera, (Node)child, mode, outputGeometryList);
            else if (child instanceof Geometry && child.getCullHint() != Spatial.CullHint.Always) {
                camera.setPlaneState(0);
                if (checkShadowMode(child.getShadowMode(), mode) &&
                        !((Geometry)child).isGrouped() &&
                        camera.contains(child.getWorldBound()) != Camera.FrustumIntersect.Outside) {
                  outputGeometryList.add((Geometry)child);
                }
            }
        }
    }
}
 
Example 2
Source File: ShadowUtil.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Populates the outputGeometryList with the geometry of the
 * inputGeometryList that are in the radius of a light.
 * The array of camera must be an array of 6 cameras initialized so they represent the light viewspace of a pointlight
 *
 * @param inputGeometryList The list containing all geometries to check
 * against the camera frustum
 * @param cameras the camera array to check geometries against
 * @param outputGeometryList the list of all geometries that are in the
 * camera frustum
 */
public static void getGeometriesInLightRadius(GeometryList inputGeometryList,
        Camera[] cameras,
        GeometryList outputGeometryList) {
    for (int i = 0; i < inputGeometryList.size(); i++) {
        Geometry g = inputGeometryList.get(i);
        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(g.getWorldBound()) != Camera.FrustumIntersect.Outside;
            camera.setPlaneState(planeState);
        }
        if (inFrustum) {
            outputGeometryList.add(g);
        }
    }

}
 
Example 3
Source File: Octnode.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void generateRenderSet(Set<Geometry> renderSet, Camera cam){
//        generateRenderSetNoCheck(renderSet, cam);

        bbox.setCheckPlane(0);
        cam.setPlaneState(0);
        Camera.FrustumIntersect result = cam.contains(bbox);
        if (result != Camera.FrustumIntersect.Outside){
            if (geoms != null){
                renderSet.addAll(Arrays.asList(geoms));
            }
            for (int i = 0; i < 8; i++){
                if (children[i] != null){
                    if (result == Camera.FrustumIntersect.Inside){
                        children[i].generateRenderSetNoCheck(renderSet, cam);
                    }else{
                        children[i].generateRenderSet(renderSet, cam);
                    }
                }
            }
        }
    }
 
Example 4
Source File: ShadowUtil.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Populates the outputGeometryList with the geometry of the
 * inputGeometryList that are in the frustum of the given camera
 *
 * @param inputGeometryList The list containing all geometries 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);
    }

}
 
Example 5
Source File: ShadowUtil.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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);
            }
        }
    }
}
 
Example 6
Source File: FastOctnode.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void generateRenderSet(Geometry[] globalGeomList, Set<Geometry> renderSet, Camera cam, BoundingBox parentBox, boolean isRoot){
    tempBox.setCenter(parentBox.getCenter());
    tempBox.setXExtent(parentBox.getXExtent());
    tempBox.setYExtent(parentBox.getYExtent());
    tempBox.setZExtent(parentBox.getZExtent());

    if (!isRoot){
        findChildBound(tempBox, getSide());
    }
    
    tempBox.setCheckPlane(0);
    cam.setPlaneState(0);
    Camera.FrustumIntersect result = cam.contains(tempBox);
    if (result != Camera.FrustumIntersect.Outside){
        if (length != 0){
            int start = getOffset();
            int end   = start + length;
            for (int i = start; i < end; i++){
                renderSet.add(globalGeomList[i]);
            }
        }

        if (child == null)
            return;

        FastOctnode node = child;

        float x = tempBox.getCenter().x;
        float y = tempBox.getCenter().y;
        float z = tempBox.getCenter().z;
        float ext = tempBox.getXExtent();

        while (node != null){
            if (result == Camera.FrustumIntersect.Inside){
                node.generateRenderSetNoCheck(globalGeomList, renderSet, cam);
            }else{
                node.generateRenderSet(globalGeomList, renderSet, cam, tempBox, false);
            }

            tempBox.getCenter().set(x,y,z);
            tempBox.setXExtent(ext);
            tempBox.setYExtent(ext);
            tempBox.setZExtent(ext);

            node = node.next;
        }
    }
}
 
Example 7
Source File: ShadowUtil.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Populates the outputGeometryList with the rootScene children geometries
 * that are in the frustum of the given camera
 *
 * @param rootScene the rootNode of the scene to traverse
 * @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(Spatial rootScene, Camera camera, RenderQueue.ShadowMode mode, GeometryList outputGeometryList) {
    if (rootScene != null && rootScene instanceof Node) {
        int planeState = camera.getPlaneState();
        addGeometriesInCamFrustumFromNode(camera, (Node)rootScene, mode, outputGeometryList);
        camera.setPlaneState(planeState);
    }
}