int nbGeoms = 0; gatherGeometries(matMap, this, needsFullRebatch); if (needsFullRebatch) { for (Batch batch : batches.getArray()) { Batch batch; if (!needsFullRebatch) { batch = findBatchByMaterial(material); if (batch != null) { list.add(0, batch.geometry); batch = new Batch(); mergeGeometries(m, list); m.setDynamic(); this.attachChild(batch.geometry);
@Override public void simpleUpdate(float tpf) { if (!done) { done = true; batch.attachChild(cube2); batch.batch(); } updateBoindPoints(points); frustum.update(points); time += tpf; dl.setDirection(cam.getDirection()); cube2.setLocalTranslation(FastMath.sin(-time) * 3, FastMath.cos(time) * 3, 0); cube2.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z)); cube2.setLocalScale(Math.max(FastMath.sin(time), 0.5f)); // batch.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z)); } //
/** * Batch this batchNode * every geometry of the sub scene graph of this node will be batched into a single mesh that will be rendered in one call */ public void batch() { doBatch(); //we set the batch geometries to ignore transforms to avoid transforms of parent nodes to be applied twice for (Batch batch : batches.getArray()) { batch.geometry.setIgnoreTransform(true); batch.geometry.setUserData(UserData.JME_PHYSICSIGNORE, true); } }
protected void updateSubBatch(Geometry bg) { Batch batch = batchesByGeom.get(bg); if (batch != null) { Mesh mesh = batch.geometry.getMesh(); Mesh origMesh = bg.getMesh(); VertexBuffer pvb = mesh.getBuffer(VertexBuffer.Type.Position); VertexBuffer nvb = mesh.getBuffer(VertexBuffer.Type.Normal); VertexBuffer tvb = mesh.getBuffer(VertexBuffer.Type.Tangent); VertexBuffer opvb = origMesh.getBuffer(VertexBuffer.Type.Position); VertexBuffer onvb = origMesh.getBuffer(VertexBuffer.Type.Normal); VertexBuffer otvb = origMesh.getBuffer(VertexBuffer.Type.Tangent); FloatBuffer posBuf = getFloatBuffer(pvb); FloatBuffer normBuf = getFloatBuffer(nvb); FloatBuffer tanBuf = getFloatBuffer(tvb); FloatBuffer oposBuf = getFloatBuffer(opvb); FloatBuffer onormBuf = getFloatBuffer(onvb); FloatBuffer otanBuf = getFloatBuffer(otvb); Matrix4f transformMat = getTransformMatrix(bg); doTransforms(oposBuf, onormBuf, otanBuf, posBuf, normBuf, tanBuf, bg.startIndex, bg.startIndex + bg.getVertexCount(), transformMat); pvb.updateData(posBuf); if (nvb != null) { nvb.updateData(normBuf); } if (tvb != null) { tvb.updateData(tanBuf); } batch.geometry.updateModelBound(); } }
if (!isBatch(n) && n.getBatchHint() != BatchHint.Never) { Geometry g = (Geometry) n; if (!g.isGrouped() || rebatch) { continue; gatherGeometries(map, child, rebatch);
@Override protected BatchNode constructFloor() { BatchNode root = new BatchNode(); // 3 by 3, a simple case int i = 0; Point start = roomInstance.getCoordinates().get(0); for (Point p : roomInstance.getCoordinates()) { Spatial tile = (Spatial) AssetUtils.loadModel(assetManager, roomInstance.getRoom().getCompleteResource().getName() + i, false, true); moveSpatial(tile, start, p); root.attachChild(tile); i++; } // Set the transform and scale to our scale and 0 the transform //AssetUtils.scale(root); AssetUtils.translateToTile(root, start); return root; }
@Override public void simpleInitApp() { timer = new NanoTimer(); batch = new BatchNode("theBatchNode"); batch.attachChild(cube); batch.batch(); rootNode.attachChild(batch); cube.setLocalTranslation(3, 0, 0);
@Override public int attachChild(Spatial child) { if (!(child instanceof Geometry)) { throw new UnsupportedOperationException("BatchNode is BatchMode.Simple only support child of type Geometry, use BatchMode.Complex to use a complex structure"); } return super.attachChild(child); }
staticbatchgeo.attachChild(tmpNode); Spatial delete = staticbatchgeo.getChild(id); staticbatchgeo.detachChild(delete); delete.removeFromParent(); staticbatchgeo.batch();
int nbGeoms = 0; gatherGeomerties(matMap, this, needsFullRebatch); if (needsFullRebatch) { for (Batch batch : batches.getArray()) { Batch batch; if (!needsFullRebatch) { batch = findBatchByMaterial(material); if (batch != null) { list.add(0, batch.geometry); batch = new Batch(); mergeGeometries(m, list); m.setDynamic(); this.attachChild(batch.geometry);
if (!isBatch(geom)) { geom.associateWithGroupNode(this, globalVertIndex); FloatBuffer inPos = (FloatBuffer) inBuf.getData(); FloatBuffer outPos = (FloatBuffer) outBuf.getData(); doCopyBuffer(inPos, globalVertIndex, outPos, 3); } else if (VertexBuffer.Type.Normal.ordinal() == bufType || VertexBuffer.Type.Tangent.ordinal() == bufType) { FloatBuffer inPos = (FloatBuffer) inBuf.getData(); FloatBuffer outPos = (FloatBuffer) outBuf.getData(); doCopyBuffer(inPos, globalVertIndex, outPos, compsForBuf[bufType]); if (VertexBuffer.Type.Tangent.ordinal() == bufType) { useTangents = true;
@Override public Spatial construct() { super.construct(); // Pillars if (hasPillars()) { BatchNode pillarsNode = new BatchNode("Pillars"); contructPillars(pillarsNode); if (!pillarsNode.getChildren().isEmpty()) { pillarsNode.setShadowMode(RenderQueue.ShadowMode.CastAndReceive); pillarsNode.batch(); getRootNode().attachChild(pillarsNode); } } return getRootNode(); }
rootNode.setShadowMode(ShadowMode.Off); batchNode.batch(); batchNode.setShadowMode(ShadowMode.CastAndReceive); rootNode.attachChild(batchNode);
@Override protected BatchNode constructFloor() { BatchNode root = new BatchNode(); root.attachChild(tile); tile = loadModel(resource + 4); moveSpatial(tile, start, p); root.attachChild(tile); root.attachChild(tile); tile.move(0, -MapLoader.FLOOR_HEIGHT, 0); moveSpatial(tile, start, p); root.attachChild(tile); tile.move(0, -MapLoader.FLOOR_HEIGHT, 0); moveSpatial(tile, start, p); root.attachChild(tile); moveSpatial(tile, start, p); tile.rotate(0, -FastMath.TWO_PI / 3, 0); root.attachChild(tile); moveSpatial(tile, start, p); tile.rotate(0, FastMath.TWO_PI / 3, 0); root.attachChild(tile); root.attachChild(tile.move(0, MapLoader.TILE_HEIGHT / 4, 0));
@Override public Node clone(boolean cloneMaterials) { BatchNode clone = (BatchNode) super.clone(cloneMaterials); if (batches.size() > 0) { for (Batch b : batches) { for (int i = 0; i < clone.children.size(); i++) { if (clone.children.get(i).getName().equals(b.geometry.getName())) { clone.children.remove(i); break; } } } clone.needsFullRebatch = true; clone.batches = new SafeArrayList<Batch>(Batch.class); clone.batchesByGeom = new HashMap<Geometry, Batch>(); clone.batch(); } return clone; }
batchNode.batch(); rootNode.attachChild(terrain); Vector3f pos = new Vector3f(-40, 0, -40); batchNode.setLocalTranslation(pos);
Spatial sp = batch.getChild("Box"+x+y+z); batch.detachChild(sp); sp.removeFromParent(); batch.batch();
public Spatial construct() { setupCoordinates(); // Add the floor getRootNode().detachAllChildren(); BatchNode floorNode = constructFloor(); if (floorNode != null) { floorNode.setName("Floor"); floorNode.setShadowMode(getFloorShadowMode()); floorNode.batch(); getRootNode().attachChild(floorNode); } // Custom wall BatchNode wallNode = constructWall(); if (wallNode != null) { wallNode.setName("Wall"); wallNode.setShadowMode(getWallShadowMode()); wallNode.batch(); getRootNode().attachChild(wallNode); } // The objects on the floor Node objectsNode = constructObjects(); if (objectsNode != null) { objectsNode.setName("Objects"); objectsNode.setShadowMode(RenderQueue.ShadowMode.CastAndReceive); getRootNode().attachChild(objectsNode); } return getRootNode(); }
VertexBuffer onvb = origMesh.getBuffer(VertexBuffer.Type.Normal); FloatBuffer onormBuf = (FloatBuffer) onvb.getData(); Matrix4f transformMat = getTransformMatrix(bg); VertexBuffer otvb = origMesh.getBuffer(VertexBuffer.Type.Tangent); FloatBuffer otanBuf = (FloatBuffer) otvb.getData(); doTransformsTangents(oposBuf, onormBuf, otanBuf, posBuf, normBuf, tanBuf, bg.startIndex, bg.startIndex + bg.getVertexCount(), transformMat); tvb.updateData(tanBuf); } else { doTransforms(oposBuf, onormBuf, posBuf, normBuf, bg.startIndex, bg.startIndex + bg.getVertexCount(), transformMat);
if (!tileNode.getChildren().isEmpty()) { tileNode.removeFromParent(); ((BatchNode) pageNode.getChild(FLOOR_INDEX)).attachChildAt(new Node(tileNode.getName()), getTileNodeIndex(point)); nodesNeedBatching.add((BatchNode) pageNode.getChild(FLOOR_INDEX)); if (!tileNode.getChildren().isEmpty()) { tileNode.removeFromParent(); ((BatchNode) pageNode.getChild(WALL_INDEX)).attachChildAt(new Node(tileNode.getName()), getTileNodeIndex(point)); nodesNeedBatching.add((BatchNode) pageNode.getChild(WALL_INDEX)); if (!tileNode.getChildren().isEmpty()) { tileNode.removeFromParent(); ((BatchNode) pageNode.getChild(TOP_INDEX)).attachChildAt(new Node(tileNode.getName()), getTileNodeIndex(point)); nodesNeedBatching.add((BatchNode) pageNode.getChild(TOP_INDEX)); batchNode.batch();