Skip to content

Conversation

@riccardobl
Copy link
Member

In j3md you should be allowed to define default textures like this

Texture2D Texture -LINEAR: MinTrilinear MagBilinear /path/to/my/texture.dds

But the j3md loaded actually didn't set the default value for texture params.
This pr fixes that.

@riccardobl riccardobl changed the title j3md Fix for default textures J3MLoader Fix for default textures for j3md Mar 21, 2019
@stephengold
Copy link
Member

Is there a test case or example?

@riccardobl
Copy link
Member Author

riccardobl commented Mar 27, 2019

TestDefaultTex.java

package tests;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.renderer.queue.RenderQueue.Bucket;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Quad;

public class TestDefaultTex extends SimpleApplication {


    public static void main(String[] args){
        new TestDefaultTex().start();
    }

    @Override
    public void simpleInitApp() {
        Quad quadMesh = new Quad(512,512);
        Geometry quad = new Geometry("Quad", quadMesh);
        quad.setQueueBucket(Bucket.Gui);
        quad.setMaterial(new Material(assetManager, "TestMaterials/TestDefaultTexture.j3md"));  
        guiNode.attachChild(quad);

        quad = quad.clone();
        quad.setMaterial(new Material(assetManager, "TestMaterials/TestMissingTexture.j3md"));
        guiNode.attachChild(quad);
        quad.setLocalTranslation(522,0,0);
    }

    @Override
    public void simpleUpdate(float tpf){
    
    }
}

TestMaterials/TestDefaultTexture.j3md

MaterialDef TestDefaultTexture {

    MaterialParameters {
        Texture2D ColorMap: Flip Textures/ColoredTex/Monkey.png
    }

    Technique {
        VertexShader GLSL100 GLSL150:   Common/MatDefs/Misc/Unshaded.vert
        FragmentShader GLSL100 GLSL150: Common/MatDefs/Misc/Unshaded.frag

        WorldParameters {
            WorldViewProjectionMatrix
            ViewProjectionMatrix
            ViewMatrix
        }

        Defines {
            HAS_COLORMAP : ColorMap
        }
    }
}

TestMaterials/TestMissingTexture.j3md

MaterialDef TestMissingDefaultTexture {

    MaterialParameters {
        Texture2D ColorMap: Texture/that/doesnt/exist.png
    }

    Technique {
        VertexShader GLSL100 GLSL150:   Common/MatDefs/Misc/Unshaded.vert
        FragmentShader GLSL100 GLSL150: Common/MatDefs/Misc/Unshaded.frag

        WorldParameters {
            WorldViewProjectionMatrix
            ViewProjectionMatrix
            ViewMatrix
        }

        Defines {
            HAS_COLORMAP : ColorMap
        }
    }
}

Expected output
missingtex

@stephengold stephengold merged commit cf7b15b into jMonkeyEngine:master Mar 27, 2019
@stephengold stephengold added this to the v3.2.4 milestone Jul 8, 2019
stephengold pushed a commit that referenced this pull request Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants