Search in sources :

Example 31 with TextureKey

use of com.jme3.asset.TextureKey in project jmonkeyengine by jMonkeyEngine.

the class TextureProcessor method postProcess.

@Override
public Object postProcess(AssetKey key, Object obj) {
    TextureKey texKey = (TextureKey) key;
    Image img = (Image) obj;
    if (img == null) {
        return null;
    }
    Texture tex;
    if (texKey.getTextureTypeHint() == Texture.Type.CubeMap) {
        if (texKey.isFlipY()) {
            // also flip -y and +y image in cubemap
            ByteBuffer pos_y = img.getData(2);
            img.setData(2, img.getData(3));
            img.setData(3, pos_y);
        }
        tex = new TextureCubeMap();
    } else if (texKey.getTextureTypeHint() == Texture.Type.ThreeDimensional) {
        tex = new Texture3D();
    } else {
        tex = new Texture2D();
    }
    // or generate them if requested by user
    if (img.hasMipmaps() || texKey.isGenerateMips()) {
        tex.setMinFilter(Texture.MinFilter.Trilinear);
    }
    tex.setAnisotropicFilter(texKey.getAnisotropy());
    tex.setName(texKey.getName());
    tex.setImage(img);
    return tex;
}
Also used : TextureKey(com.jme3.asset.TextureKey) ByteBuffer(java.nio.ByteBuffer)

Example 32 with TextureKey

use of com.jme3.asset.TextureKey in project jmonkeyengine by jMonkeyEngine.

the class Picture method setImage.

/**
     * Set the image to put on the picture.
     * 
     * @param assetManager The {@link AssetManager} to use to load the image.
     * @param imgName The image name.
     * @param useAlpha If true, the picture will appear transparent and allow
     * objects behind it to appear through. If false, the transparent
     * portions will be the image's color at that pixel.
     */
public void setImage(AssetManager assetManager, String imgName, boolean useAlpha) {
    TextureKey key = new TextureKey(imgName, true);
    Texture2D tex = (Texture2D) assetManager.loadTexture(key);
    setTexture(assetManager, tex, useAlpha);
}
Also used : TextureKey(com.jme3.asset.TextureKey) Texture2D(com.jme3.texture.Texture2D)

Example 33 with TextureKey

use of com.jme3.asset.TextureKey in project jmonkeyengine by jMonkeyEngine.

the class HelloPhysics method initMaterials.

/** Initialize the materials used in this scene. */
public void initMaterials() {
    wall_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    wall_mat.setTexture("ColorMap", tex);
    stone_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
    key2.setGenerateMips(true);
    Texture tex2 = assetManager.loadTexture(key2);
    stone_mat.setTexture("ColorMap", tex2);
    floor_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg");
    key3.setGenerateMips(true);
    Texture tex3 = assetManager.loadTexture(key3);
    tex3.setWrap(WrapMode.Repeat);
    floor_mat.setTexture("ColorMap", tex3);
}
Also used : TextureKey(com.jme3.asset.TextureKey) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture)

Example 34 with TextureKey

use of com.jme3.asset.TextureKey in project jmonkeyengine by jMonkeyEngine.

the class TestMaterialCompare method main.

public static void main(String[] args) {
    AssetManager assetManager = JmeSystem.newAssetManager(TestMaterialCompare.class.getResource("/com/jme3/asset/Desktop.cfg"));
    // Cloned materials
    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setName("mat1");
    mat1.setColor("Color", ColorRGBA.Blue);
    Material mat2 = mat1.clone();
    mat2.setName("mat2");
    testEquality(mat1, mat2, true);
    // Cloned material with different render states
    Material mat3 = mat1.clone();
    mat3.setName("mat3");
    mat3.getAdditionalRenderState().setBlendMode(BlendMode.ModulateX2);
    testEquality(mat1, mat3, false);
    // Two separately loaded materials
    Material mat4 = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
    mat4.setName("mat4");
    Material mat5 = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
    mat5.setName("mat5");
    testEquality(mat4, mat5, true);
    // Comparing same textures
    TextureKey originalKey = (TextureKey) mat4.getTextureParam("DiffuseMap").getTextureValue().getKey();
    TextureKey tex1key = new TextureKey("Models/Sign Post/Sign Post.jpg", false);
    tex1key.setGenerateMips(true);
    // and thus materials are not identical!
    if (!originalKey.equals(tex1key)) {
        System.out.println("TEXTURE KEYS ARE NOT EQUAL");
    }
    Texture tex1 = assetManager.loadTexture(tex1key);
    mat4.setTexture("DiffuseMap", tex1);
    testEquality(mat4, mat5, true);
    // Change some stuff on the texture and compare, materials no longer equal
    tex1.setWrap(Texture.WrapMode.MirroredRepeat);
    testEquality(mat4, mat5, false);
    // Comparing different textures
    Texture tex2 = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
    mat4.setTexture("DiffuseMap", tex2);
    testEquality(mat4, mat5, false);
    // Two materials created the same way
    Material mat6 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat6.setName("mat6");
    mat6.setColor("Color", ColorRGBA.Blue);
    testEquality(mat1, mat6, true);
    // Changing a material param
    mat6.setColor("Color", ColorRGBA.Green);
    testEquality(mat1, mat6, false);
}
Also used : TextureKey(com.jme3.asset.TextureKey) AssetManager(com.jme3.asset.AssetManager) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture)

Example 35 with TextureKey

use of com.jme3.asset.TextureKey in project jmonkeyengine by jMonkeyEngine.

the class TestSkeletonControlRefresh method simpleInitApp.

@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.White);
    flyCam.setMoveSpeed(10f);
    cam.setLocation(new Vector3f(3.8664846f, 6.2704787f, 9.664585f));
    cam.setRotation(new Quaternion(-0.054774776f, 0.94064945f, -0.27974048f, -0.18418397f));
    makeHudText();
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);
    Material m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey k = new TextureKey("Models/Oto/Oto.jpg", false);
    m.setTexture("ColorMap", assetManager.loadTexture(k));
    for (int i = 0; i < SIZE; i++) {
        for (int j = 0; j < SIZE; j++) {
            Spatial model = (Spatial) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
            //setting a different material
            model.setMaterial(m.clone());
            model.setLocalScale(0.1f);
            model.setLocalTranslation(i - SIZE / 2, 0, j - SIZE / 2);
            control = model.getControl(AnimControl.class);
            channel = control.createChannel();
            channel.setAnim(animNames[(i + j) % 4]);
            channel.setLoopMode(LoopMode.DontLoop);
            SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);
            //This is a workaround the issue. this call will make the SkeletonControl gather the targets again.
            //skeletonControl.setSpatial(model);
            skeletonControl.setHardwareSkinningPreferred(hwSkinningEnable);
            skControls.add(skeletonControl);
            rootNode.attachChild(model);
        }
    }
    rootNode.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
    setupFloor();
    inputManager.addListener(this, "toggleHWS");
    inputManager.addMapping("toggleHWS", new KeyTrigger(KeyInput.KEY_SPACE));
    //        DirectionalLightShadowRenderer pssm = new DirectionalLightShadowRenderer(assetManager, 1024, 2);
    //        pssm.setLight(dl);
    //        viewPort.addProcessor(pssm);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    DirectionalLightShadowFilter sf = new DirectionalLightShadowFilter(assetManager, 1024, 2);
    sf.setLight(dl);
    fpp.addFilter(sf);
    fpp.addFilter(new SSAOFilter());
    viewPort.addProcessor(fpp);
}
Also used : SSAOFilter(com.jme3.post.ssao.SSAOFilter) Quaternion(com.jme3.math.Quaternion) KeyTrigger(com.jme3.input.controls.KeyTrigger) Material(com.jme3.material.Material) FilterPostProcessor(com.jme3.post.FilterPostProcessor) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter) TextureKey(com.jme3.asset.TextureKey) ColorRGBA(com.jme3.math.ColorRGBA) Spatial(com.jme3.scene.Spatial) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight)

Aggregations

TextureKey (com.jme3.asset.TextureKey)37 Texture (com.jme3.texture.Texture)26 Material (com.jme3.material.Material)16 Image (com.jme3.texture.Image)9 InputStream (java.io.InputStream)9 Geometry (com.jme3.scene.Geometry)7 Vector3f (com.jme3.math.Vector3f)6 Texture2D (com.jme3.texture.Texture2D)6 MatParamTexture (com.jme3.material.MatParamTexture)4 AssetLoadException (com.jme3.asset.AssetLoadException)3 AssetNotFoundException (com.jme3.asset.AssetNotFoundException)3 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)3 DirectionalLight (com.jme3.light.DirectionalLight)3 ByteBuffer (java.nio.ByteBuffer)3 AssetManager (com.jme3.asset.AssetManager)2 Vector2f (com.jme3.math.Vector2f)2 FilterPostProcessor (com.jme3.post.FilterPostProcessor)2 Spatial (com.jme3.scene.Spatial)2 Box (com.jme3.scene.shape.Box)2 Quad (com.jme3.scene.shape.Quad)2