use of com.jme3.asset.AssetManager in project jmonkeyengine by jMonkeyEngine.
the class TextureAtlas method makeAtlasBatch.
/**
* Creates one geometry out of the given root spatial and merges all single
* textures into one texture of the given size.
* @param spat The root spatial of the scene to batch
* @param mgr An assetmanager that can be used to create the material.
* @param atlasSize A size for the atlas texture, it has to be large enough to hold all single textures.
* @return A new geometry that uses the generated texture atlas and merges all meshes of the root spatial, null if the atlas cannot be created because not all textures fit.
*/
public static Geometry makeAtlasBatch(Spatial spat, AssetManager mgr, int atlasSize) {
List<Geometry> geometries = new ArrayList<Geometry>();
GeometryBatchFactory.gatherGeoms(spat, geometries);
TextureAtlas atlas = createAtlas(spat, atlasSize);
if (atlas == null) {
return null;
}
Geometry geom = new Geometry();
Mesh mesh = new Mesh();
GeometryBatchFactory.mergeGeometries(geometries, mesh);
applyAtlasCoords(geometries, mesh, atlas);
mesh.updateCounts();
mesh.updateBound();
geom.setMesh(mesh);
Material mat = new Material(mgr, "Common/MatDefs/Light/Lighting.j3md");
Texture diffuseMap = atlas.getAtlasTexture("DiffuseMap");
Texture normalMap = atlas.getAtlasTexture("NormalMap");
Texture specularMap = atlas.getAtlasTexture("SpecularMap");
if (diffuseMap != null) {
mat.setTexture("DiffuseMap", diffuseMap);
}
if (normalMap != null) {
mat.setTexture("NormalMap", normalMap);
}
if (specularMap != null) {
mat.setTexture("SpecularMap", specularMap);
}
mat.setFloat("Shininess", 16.0f);
geom.setMaterial(mat);
return geom;
}
use of com.jme3.asset.AssetManager in project jmonkeyengine by jMonkeyEngine.
the class MaterialMatParamTest method material.
private void material(String path) {
AssetManager assetManager = TestUtil.createAssetManager();
geometry.setMaterial(new Material(assetManager, path));
}
use of com.jme3.asset.AssetManager in project jmonkeyengine by jMonkeyEngine.
the class MaterialTest method material.
private void material(String path) {
AssetManager assetManager = TestUtil.createAssetManager();
material = new Material(assetManager, path);
geometry.setMaterial(material);
}
use of com.jme3.asset.AssetManager in project jmonkeyengine by jMonkeyEngine.
the class J3MLoaderTest method oldStyleTextureParameters_shouldBeSupported.
@Test
public void oldStyleTextureParameters_shouldBeSupported() throws Exception {
when(assetInfo.openStream()).thenReturn(J3MLoader.class.getResourceAsStream("/texture-parameters-oldstyle.j3m"));
final Texture textureOldStyle = Mockito.mock(Texture.class);
final Texture textureOldStyleUsingQuotes = Mockito.mock(Texture.class);
final TextureKey textureKeyUsingQuotes = setupMockForTexture("OldStyleUsingQuotes", "old style using quotes/texture.png", true, textureOldStyleUsingQuotes);
final TextureKey textureKeyOldStyle = setupMockForTexture("OldStyle", "old style/texture.png", true, textureOldStyle);
j3MLoader.load(assetInfo);
verify(assetManager).loadTexture(textureKeyUsingQuotes);
verify(assetManager).loadTexture(textureKeyOldStyle);
verify(textureOldStyle).setWrap(Texture.WrapMode.Repeat);
verify(textureOldStyleUsingQuotes).setWrap(Texture.WrapMode.Repeat);
}
use of com.jme3.asset.AssetManager in project jmonkeyengine by jMonkeyEngine.
the class J3MLoaderTest method newStyleTextureParameters_shouldBeSupported.
@Test
public void newStyleTextureParameters_shouldBeSupported() throws Exception {
when(assetInfo.openStream()).thenReturn(J3MLoader.class.getResourceAsStream("/texture-parameters-newstyle.j3m"));
final Texture textureNoParameters = Mockito.mock(Texture.class);
final Texture textureFlip = Mockito.mock(Texture.class);
final Texture textureRepeat = Mockito.mock(Texture.class);
final Texture textureRepeatAxis = Mockito.mock(Texture.class);
final Texture textureMin = Mockito.mock(Texture.class);
final Texture textureMag = Mockito.mock(Texture.class);
final Texture textureCombined = Mockito.mock(Texture.class);
final Texture textureLooksLikeOldStyle = Mockito.mock(Texture.class);
final TextureKey textureKeyNoParameters = setupMockForTexture("Empty", "empty.png", false, textureNoParameters);
final TextureKey textureKeyFlip = setupMockForTexture("Flip", "flip.png", true, textureFlip);
setupMockForTexture("Repeat", "repeat.png", false, textureRepeat);
setupMockForTexture("RepeatAxis", "repeat-axis.png", false, textureRepeatAxis);
setupMockForTexture("Min", "min.png", false, textureMin);
setupMockForTexture("Mag", "mag.png", false, textureMag);
setupMockForTexture("Combined", "combined.png", true, textureCombined);
setupMockForTexture("LooksLikeOldStyle", "oldstyle.png", true, textureLooksLikeOldStyle);
j3MLoader.load(assetInfo);
verify(assetManager).loadTexture(textureKeyNoParameters);
verify(assetManager).loadTexture(textureKeyFlip);
verify(textureRepeat).setWrap(Texture.WrapMode.Repeat);
verify(textureRepeatAxis).setWrap(Texture.WrapAxis.T, Texture.WrapMode.Repeat);
verify(textureMin).setMinFilter(Texture.MinFilter.Trilinear);
verify(textureMag).setMagFilter(Texture.MagFilter.Bilinear);
verify(textureCombined).setMagFilter(Texture.MagFilter.Nearest);
verify(textureCombined).setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
verify(textureCombined).setWrap(Texture.WrapMode.Repeat);
}
Aggregations