Java Code Examples for com.jme3.scene.Spatial#getCullHint()
The following examples show how to use
com.jme3.scene.Spatial#getCullHint() .
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 |
/** * 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 | 5 votes |
/** * 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 3
Source File: RenderManager.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Flattens the given scene graph into the ViewPort's RenderQueue, * checking for culling as the call goes down the graph recursively. * <p> * First, the scene is checked for culling based on the <code>Spatial</code>s * {@link Spatial#setCullHint(com.jme3.scene.Spatial.CullHint) cull hint}, * if the camera frustum contains the scene, then this method is recursively * called on its children. * <p> * When the scene's leaves or {@link Geometry geometries} are reached, * they are each enqueued into the * {@link ViewPort#getQueue() ViewPort's render queue}. * <p> * In addition to enqueuing the visible geometries, this method * also scenes which cast or receive shadows, by putting them into the * RenderQueue's * {@link RenderQueue#addToShadowQueue(com.jme3.scene.Geometry, com.jme3.renderer.queue.RenderQueue.ShadowMode) * shadow queue}. Each Spatial which has its * {@link Spatial#setShadowMode(com.jme3.renderer.queue.RenderQueue.ShadowMode) shadow mode} * set to not off, will be put into the appropriate shadow queue, note that * this process does not check for frustum culling on any * {@link ShadowMode#Cast shadow casters}, as they don't have to be * in the eye camera frustum to cast shadows on objects that are inside it. * * @param scene The scene to flatten into the queue * @param vp The ViewPort provides the {@link ViewPort#getCamera() camera} * used for culling and the {@link ViewPort#getQueue() queue} used to * contain the flattened scene graph. */ public void renderScene(Spatial scene, ViewPort vp) { if (scene.getParent() == null) { vp.getCamera().setPlaneState(0); } // check culling first. if (!scene.checkCulling(vp.getCamera())) { // move on to shadow-only render if ((scene.getShadowMode() != RenderQueue.ShadowMode.Off || scene instanceof Node) && scene.getCullHint()!=Spatial.CullHint.Always) { renderShadow(scene, vp.getQueue()); } return; } scene.runControlRender(this, vp); if (scene instanceof Node) { // recurse for all children Node n = (Node) scene; List<Spatial> children = n.getChildren(); //saving cam state for culling int camState = vp.getCamera().getPlaneState(); for (int i = 0; i < children.size(); i++) { //restoring cam state before proceeding children recusively vp.getCamera().setPlaneState(camState); renderScene(children.get(i), vp); } } else if (scene instanceof Geometry) { // add to the render queue Geometry gm = (Geometry) scene; if (gm.getMaterial() == null) { throw new IllegalStateException("No material is set for Geometry: " + gm.getName()); } vp.getQueue().addToQueue(gm, scene.getQueueBucket()); // add to shadow queue if needed RenderQueue.ShadowMode shadowMode = scene.getShadowMode(); if (shadowMode != RenderQueue.ShadowMode.Off) { vp.getQueue().addToShadowQueue(gm, shadowMode); } } }