public static void gatherGeoms(Spatial scene, List<Geometry> geoms) { if (scene instanceof Node) { Node node = (Node) scene; for (Spatial child : node.getChildren()) { gatherGeoms(child, geoms); } } else if (scene instanceof Geometry) { geoms.add((Geometry) scene); } }
/** * Create a texture atlas for the given root node, containing DiffuseMap, NormalMap and SpecularMap. * @param root The rootNode to create the atlas for. * @param atlasSize The size of the atlas (width and height). * @return Null if the atlas cannot be created because not all textures fit. */ public static TextureAtlas createAtlas(Spatial root, int atlasSize) { List<Geometry> geometries = new ArrayList<Geometry>(); GeometryBatchFactory.gatherGeoms(root, geometries); TextureAtlas atlas = new TextureAtlas(atlasSize, atlasSize); for (Geometry geometry : geometries) { if (!atlas.addGeometry(geometry)) { logger.log(Level.WARNING, "Texture atlas size too small, cannot add all textures"); return null; } } return atlas; }
/** * 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 * @param useLods true if you want the resulting geometry to keep lod information * @return The newly created optimized geometries attached to a node */ public static Node optimize(Node scene, boolean useLods) { ArrayList<Geometry> geoms = new ArrayList<Geometry>(); gatherGeoms(scene, geoms); List<Geometry> batchedGeoms = makeBatches(geoms, useLods); for (Geometry geom : batchedGeoms) { scene.attachChild(geom); } for (Iterator<Geometry> it = geoms.iterator(); it.hasNext();) { Geometry geometry = it.next(); geometry.removeFromParent(); } // Since the scene is returned unaltered the transform must be reset scene.setLocalTransform(Transform.IDENTITY); return scene; }
GeometryBatchFactory.gatherGeoms(spat, geometries); TextureAtlas atlas = createAtlas(spat, atlasSize); if (atlas == null) {
private static void gatherGeoms(Spatial scene, List<Geometry> geoms) { if (scene instanceof Node) { Node node = (Node) scene; for (Spatial child : node.getChildren()) { gatherGeoms(child, geoms); } } else if (scene instanceof Geometry) { geoms.add((Geometry) scene); } }
public static void gatherGeoms(Spatial scene, List<Geometry> geoms) { if (scene instanceof Node) { Node node = (Node) scene; for (Spatial child : node.getChildren()) { gatherGeoms(child, geoms); } } else if (scene instanceof Geometry) { geoms.add((Geometry) scene); } }
/** * Create a texture atlas for the given root node, containing DiffuseMap, NormalMap and SpecularMap. * @param root The rootNode to create the atlas for. * @param atlasSize The size of the atlas (width and height). * @return Null if the atlas cannot be created because not all textures fit. */ public static TextureAtlas createAtlas(Spatial root, int atlasSize) { List<Geometry> geometries = new ArrayList<Geometry>(); GeometryBatchFactory.gatherGeoms(root, geometries); TextureAtlas atlas = new TextureAtlas(atlasSize, atlasSize); for (Geometry geometry : geometries) { if (!atlas.addGeometry(geometry)) { logger.log(Level.WARNING, "Texture atlas size too small, cannot add all textures"); return null; } } return atlas; }
/** * 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 * @param useLods true if you want the resulting geometry to keep lod information * @return The newly created optimized geometries attached to a node */ public static Node optimize(Node scene, boolean useLods) { ArrayList<Geometry> geoms = new ArrayList<Geometry>(); gatherGeoms(scene, geoms); List<Geometry> batchedGeoms = makeBatches(geoms, useLods); for (Geometry geom : batchedGeoms) { scene.attachChild(geom); } for (Iterator<Geometry> it = geoms.iterator(); it.hasNext();) { Geometry geometry = it.next(); geometry.removeFromParent(); } // Since the scene is returned unaltered the transform must be reset scene.setLocalTransform(Transform.IDENTITY); return scene; }
/** * 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 * @param useLods true if you want the resulting geometry to keep lod information * @return The newly created optimized geometries attached to a node */ public static Node optimize(Node scene, boolean useLods) { ArrayList<Geometry> geoms = new ArrayList<Geometry>(); gatherGeoms(scene, geoms); List<Geometry> batchedGeoms = makeBatches(geoms, useLods); for (Geometry geom : batchedGeoms) { scene.attachChild(geom); } for (Iterator<Geometry> it = geoms.iterator(); it.hasNext();) { Geometry geometry = it.next(); geometry.removeFromParent(); } // Since the scene is returned unaltered the transform must be reset scene.setLocalTransform(Transform.IDENTITY); return scene; }
GeometryBatchFactory.gatherGeoms(spatial, geometries); Mesh outMesh = new Mesh(); GeometryBatchFactory.mergeGeometries(geometries, outMesh);
GeometryBatchFactory.gatherGeoms(spatial, geometries); Mesh outMesh = new Mesh(); GeometryBatchFactory.mergeGeometries(geometries, outMesh);
GeometryBatchFactory.gatherGeoms(spat, geometries); TextureAtlas atlas = createAtlas(spat, atlasSize); if (atlas == null) {