- simplify GeometryBatchFactory.optimize() by expecting a Node as parameter

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7214 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 14 years ago
parent 0dacbb77e1
commit dd749a699b
  1. 24
      engine/src/tools/jme3tools/optimize/GeometryBatchFactory.java

@ -24,6 +24,7 @@ import java.nio.FloatBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -254,30 +255,27 @@ public class GeometryBatchFactory {
} }
/** /**
* Optimizes a scene by combining Geometry with the same material. If the * Optimizes a scene by combining Geometry with the same material.
* given spatial has a parent it is removed from the parent and the newly * All Geometries found in the scene are detached from their parent and
* generated scene is attached instead. * a new Node containing the optimized Geometries is attached.
* @param scene The scene to optimize * @param scene The scene to optimize
* @return The newly created optimized scene * @return The newly created optimized geometries attached to a node
*/ */
public static Spatial optimize(Spatial scene){ public static Node optimize(Node scene){
ArrayList<Geometry> geoms = new ArrayList<Geometry>(); ArrayList<Geometry> geoms = new ArrayList<Geometry>();
gatherGeoms(scene, geoms); gatherGeoms(scene, geoms);
List<Geometry> batchedGeoms = makeBatches(geoms); List<Geometry> batchedGeoms = makeBatches(geoms);
Node node = new Node(scene.getName());
for (Geometry geom : batchedGeoms){ for (Geometry geom : batchedGeoms){
node.attachChild(geom); scene.attachChild(geom);
} }
Node parent = scene.getParent(); for (Iterator<Geometry> it = geoms.iterator(); it.hasNext();) {
if(parent != null){ Geometry geometry = it.next();
scene.removeFromParent(); geometry.removeFromParent();
parent.attachChild(node);
} }
return node; return scene;
} }
public static void printMesh(Mesh mesh){ public static void printMesh(Mesh mesh){

Loading…
Cancel
Save