/** * 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; }
/** * 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; }
private int addCubeGeometry() { Mesh cubeMesh = new BitCubeBox(1f, 1f, 1f); TextureAtlas atlas = new TextureAtlas(400, 1200); MatFactory matFact = getRenderRegCli().getOpticMaterialFacade(null, null); AssetManager assetMgr = matFact.getAssetManager(); Texture zeroTexture = assetMgr.loadTexture("textures/robosteps/Zero.png"); Texture oneTexture = assetMgr.loadTexture("textures/robosteps/One.png"); Texture blankTexture = assetMgr.loadTexture("textures/robosteps/BlankGray.png"); atlas.addTexture(zeroTexture, "ColorMap"); atlas.addTexture(oneTexture, "ColorMap"); atlas.addTexture(blankTexture, "ColorMap"); Material cubeMaterial = matFact.makeMatWithOptTexture("Common/MatDefs/Misc/Unshaded.j3md", "ColorMap", atlas.getAtlasTexture("ColorMap")); return addGeometry(cubeMesh, cubeMaterial, null, new Quaternion()); }