/** * Optimizes a scene by combining Geometry with the same material. * All Geometries found in the scene are detached from their parent and * a new Node containing the optimized Geometries is attached. * @param scene The scene to optimize * @return The newly created optimized geometries attached to a node */ public static Spatial optimize(Node scene) { return optimize(scene, false); }
GeometryBatchFactory.optimize(rootNode, true); LodControl control = new LodControl(); rootNode.getChild(0).addControl(control);
/** * Optimizes a scene by combining Geometry with the same material. * All Geometries found in the scene are detached from their parent and * a new Node containing the optimized Geometries is attached. * @param scene The scene to optimize * @return The newly created optimized geometries attached to a node */ public static Spatial optimize(Node scene) { return optimize(scene, false); }
/** * Optimizes a scene by combining Geometry with the same material. * All Geometries found in the scene are detached from their parent and * a new Node containing the optimized Geometries is attached. * @param scene The scene to optimize * @return The newly created optimized geometries attached to a node */ public static Spatial optimize(Node scene) { return optimize(scene, false); }
public monkeyApp_Grid(final float areaSize, final float spaceSize, final AssetManager assetManager, final boolean isGrid) { _assetManager = assetManager; _areaSize = areaSize; _spaceSize = spaceSize; _gridNode = new Node("gridNode"); _isGrid = isGrid; _gridNumber = Math.max((int)_spaceSize, 10); _gridGaps = (float)_areaSize / _gridNumber; createGrid(); if(_isGrid) shiftGrid(); GeometryBatchFactory.optimize(_gridNode); }
public JMEGraphicsObject(Application application, JMEAssetLocator jmeAssetLocator, Graphics3DObject graphics3dObject) { this.application = application; this.jmeAssetLocator = jmeAssetLocator; immutable = !graphics3dObject.isChangeable(); currentNode = this.rootNode; setUpGraphicsFromDefinition(graphics3dObject.getGraphics3DInstructions()); // Optimize geometries. Cannot change geometries on an optimized node. if (optimizeGraphicsObject && immutable) { rootNode = (Node) GeometryBatchFactory.optimize(rootNode); } }
public JMEGraphicsObject(Application application, AssetManager jmeAssetLocator, Graphics3DObject graphics3dObject) { this.application = application; this.assetManager = jmeAssetLocator; immutable = !graphics3dObject.isChangeable(); currentNode = this.rootNode; setUpGraphicsFromDefinition(graphics3dObject.getGraphics3DInstructions()); // Optimize geometries. Cannot change geometries on an optimized node. if (optimizeGraphicsObject && immutable) { rootNode = (Node) GeometryBatchFactory.optimize(rootNode); } }
public static Node createSelectionCircle(Material mat, float scale, int points) { Node circle = new Node(); for (int i = 0; i < points; i++) { float x0 = scale * FastMath.cos(i * 2 * FastMath.PI / points); float y0 = scale * FastMath.sin(i * 2 * FastMath.PI / points); float x1 = scale * FastMath.cos((i + 1) * 2 * FastMath.PI / points); float y1 = scale * FastMath.sin((i + 1) * 2 * FastMath.PI / points); circle.attachChild(createLine("Circle's Line", mat, new Vector3f(x0, 0, y0), new Vector3f(x1, 0, y1))); } GeometryBatchFactory.optimize(circle); return circle; }
public static Node createSelectionCircle(Material mat, float scale, int points) { Node circle = new Node(); for (int i = 0; i < points; i++) { float x0 = scale * FastMath.cos(i * 2 * FastMath.PI / points); float y0 = scale * FastMath.sin(i * 2 * FastMath.PI / points); float x1 = scale * FastMath.cos((i + 1) * 2 * FastMath.PI / points); float y1 = scale * FastMath.sin((i + 1) * 2 * FastMath.PI / points); circle.attachChild(createLine("Circle's Line", mat, new Vector3f(x0, 0, y0), new Vector3f(x1, 0, y1))); } GeometryBatchFactory.optimize(circle); return circle; }
public static Node createDebugNormals(Mesh mesh, Material mat, float scale) { Node debugNormals = new Node(); VertexBuffer vertex = mesh.getBuffer(Type.Position); float[] vertexArray = BufferUtils.getFloatArray((FloatBuffer) vertex.getData()); VertexBuffer normals = mesh.getBuffer(Type.Normal); if (normals == null) return debugNormals; float[] normalArray = BufferUtils.getFloatArray((FloatBuffer) normals.getData()); for (int i = 0; i < vertexArray.length; i += 3) { Vector3f p1 = new Vector3f(vertexArray[i], vertexArray[i + 1], vertexArray[i + 2]); Vector3f n1 = new Vector3f(normalArray[i], normalArray[i + 1], normalArray[i + 2]); debugNormals.attachChild(createLine("DebugShowNormalsLine", mat, p1, p1.add(n1.mult(scale)))); } GeometryBatchFactory.optimize(debugNormals); return debugNormals; }
public void setStaticGeometry(Node staticNode) { this.staticNode = staticNode; // Add SKY direct to Root Spatial sky = staticNode.getChild("Skymap"); if(sky != null) { sky.removeFromParent(); this.rootNode.attachChild(sky); } // Add TERRAIN direct to Root Spatial terra = staticNode.getChild("Terrain"); if(terra != null) { terra.removeFromParent(); // ShadowMode mode = terra.getShadowMode(); terrain = (TerrainQuad)terra; terrain.setLocalTranslation(appScaled / 2, 0, appScaled / 2); this.rootNode.attachChild(terrain); /** 5. The LOD (level of detail) depends on were the camera is: */ TerrainLodControl control = new TerrainLodControl(terrain, cam); terrain.addControl(control); terrain.setShadowMode(ShadowMode.Receive); } GeometryBatchFactory.optimize(this.staticNode, true); this.rootNode.attachChild(this.staticNode); }
public static Node createDebugNormals(Mesh mesh, Material mat, float scale) { Node debugNormals = new Node(); VertexBuffer vertex = mesh.getBuffer(Type.Position); float[] vertexArray = BufferUtils.getFloatArray((FloatBuffer) vertex.getData()); VertexBuffer normals = mesh.getBuffer(Type.Normal); if (normals == null) return debugNormals; float[] normalArray = BufferUtils.getFloatArray((FloatBuffer) normals.getData()); for (int i = 0; i < vertexArray.length; i += 3) { Vector3f p1 = new Vector3f(vertexArray[i], vertexArray[i + 1], vertexArray[i + 2]); Vector3f n1 = new Vector3f(normalArray[i], normalArray[i + 1], normalArray[i + 2]); debugNormals.attachChild(createLine("DebugShowNormalsLine", mat, p1, p1.add(n1.mult(scale)))); } GeometryBatchFactory.optimize(debugNormals); return debugNormals; }
/**Debug Lines*/ public static Node createWorldGrid(Material mat, Material axisMat, int xi, int yi, boolean centered) { Node worldGrid = new Node(); Material materialToUse; //Horizontial Lines for (int i = 0; i <= yi; i++) { if (i == yi / 2) materialToUse = axisMat; else materialToUse = mat; if (!centered) worldGrid.attachChild(createLine("GridLineX" + i, materialToUse, new Vector3f(0, 0, i), new Vector3f(xi, 0, i))); else worldGrid.attachChild(createLine("GridLineX" + i, materialToUse, new Vector3f(-xi / 2f, 0, -yi / 2f + i), new Vector3f(xi / 2f, 0, -yi / 2f + i))); } //Vertical Lines for (int i = 0; i <= xi; i++) { if (i == xi / 2) materialToUse = axisMat; else materialToUse = mat; if (!centered) worldGrid.attachChild(createLine("GridLineY" + i, materialToUse, new Vector3f(i, 0, 0), new Vector3f(i, 0, yi))); else worldGrid.attachChild(createLine("GridLineY" + i, materialToUse, new Vector3f(-xi / 2f + i, 0, -yi / 2f), new Vector3f(-xi / 2f + i, 0, yi / 2f))); } GeometryBatchFactory.optimize(worldGrid); return worldGrid; }
/**Debug Lines*/ public static Node createWorldGrid(Material mat, Material axisMat, int xi, int yi, boolean centered) { Node worldGrid = new Node(); Material materialToUse; //Horizontial Lines for (int i = 0; i <= yi; i++) { if (i == yi / 2) materialToUse = axisMat; else materialToUse = mat; if (!centered) worldGrid.attachChild(createLine("GridLineX" + i, materialToUse, new Vector3f(0, 0, i), new Vector3f(xi, 0, i))); else worldGrid.attachChild(createLine("GridLineX" + i, materialToUse, new Vector3f(-xi / 2f, 0, -yi / 2f + i), new Vector3f(xi / 2f, 0, -yi / 2f + i))); } //Vertical Lines for (int i = 0; i <= xi; i++) { if (i == xi / 2) materialToUse = axisMat; else materialToUse = mat; if (!centered) worldGrid.attachChild(createLine("GridLineY" + i, materialToUse, new Vector3f(i, 0, 0), new Vector3f(i, 0, yi))); else worldGrid.attachChild(createLine("GridLineY" + i, materialToUse, new Vector3f(-xi / 2f + i, 0, -yi / 2f), new Vector3f(-xi / 2f + i, 0, yi / 2f))); } GeometryBatchFactory.optimize(worldGrid); return worldGrid; }