Search in sources :

Example 6 with AssetManager

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;
}
Also used : Geometry(com.jme3.scene.Geometry) ArrayList(java.util.ArrayList) Mesh(com.jme3.scene.Mesh) Material(com.jme3.material.Material) MatParamTexture(com.jme3.material.MatParamTexture) Texture(com.jme3.texture.Texture)

Example 7 with AssetManager

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));
}
Also used : AssetManager(com.jme3.asset.AssetManager)

Example 8 with AssetManager

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);
}
Also used : AssetManager(com.jme3.asset.AssetManager)

Example 9 with AssetManager

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);
}
Also used : TextureKey(com.jme3.asset.TextureKey) MatParamTexture(com.jme3.material.MatParamTexture) Texture(com.jme3.texture.Texture) Test(org.junit.Test)

Example 10 with AssetManager

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);
}
Also used : TextureKey(com.jme3.asset.TextureKey) MatParamTexture(com.jme3.material.MatParamTexture) Texture(com.jme3.texture.Texture) Test(org.junit.Test)

Aggregations

Material (com.jme3.material.Material)213 Geometry (com.jme3.scene.Geometry)138 Vector3f (com.jme3.math.Vector3f)137 Box (com.jme3.scene.shape.Box)73 Texture (com.jme3.texture.Texture)73 DirectionalLight (com.jme3.light.DirectionalLight)66 Node (com.jme3.scene.Node)52 Sphere (com.jme3.scene.shape.Sphere)47 Quaternion (com.jme3.math.Quaternion)46 Spatial (com.jme3.scene.Spatial)43 FilterPostProcessor (com.jme3.post.FilterPostProcessor)38 ColorRGBA (com.jme3.math.ColorRGBA)37 KeyTrigger (com.jme3.input.controls.KeyTrigger)31 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)27 BulletAppState (com.jme3.bullet.BulletAppState)26 Quad (com.jme3.scene.shape.Quad)23 TextureKey (com.jme3.asset.TextureKey)22 ActionListener (com.jme3.input.controls.ActionListener)21 AmbientLight (com.jme3.light.AmbientLight)20 Texture2D (com.jme3.texture.Texture2D)20