diff --git a/engine/src/tools/jme3tools/optimize/GeometryBatchFactory.java b/engine/src/tools/jme3tools/optimize/GeometryBatchFactory.java index 33203c493..c7817c167 100644 --- a/engine/src/tools/jme3tools/optimize/GeometryBatchFactory.java +++ b/engine/src/tools/jme3tools/optimize/GeometryBatchFactory.java @@ -24,6 +24,7 @@ import java.nio.FloatBuffer; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -254,30 +255,27 @@ public class GeometryBatchFactory { } /** - * Optimizes a scene by combining Geometry with the same material. If the - * given spatial has a parent it is removed from the parent and the newly - * generated scene is attached instead. + * 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 scene + * @return The newly created optimized geometries attached to a node */ - public static Spatial optimize(Spatial scene){ + public static Node optimize(Node scene){ ArrayList geoms = new ArrayList(); gatherGeoms(scene, geoms); List batchedGeoms = makeBatches(geoms); - - Node node = new Node(scene.getName()); for (Geometry geom : batchedGeoms){ - node.attachChild(geom); + scene.attachChild(geom); } - Node parent = scene.getParent(); - if(parent != null){ - scene.removeFromParent(); - parent.attachChild(node); + for (Iterator it = geoms.iterator(); it.hasNext();) { + Geometry geometry = it.next(); + geometry.removeFromParent(); } - return node; + return scene; } public static void printMesh(Mesh mesh){