From dd749a699b14c0302b08b5d52c959762786e3d66 Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Thu, 7 Apr 2011 12:05:04 +0000 Subject: [PATCH] - simplify GeometryBatchFactory.optimize() by expecting a Node as parameter git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7214 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../optimize/GeometryBatchFactory.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) 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){