Search in sources :

Example 1 with MatParamTexture

use of com.jme3.material.MatParamTexture in project jmonkeyengine by jMonkeyEngine.

the class J3MLoaderTest method setupMockForTexture.

private TextureKey setupMockForTexture(final String paramName, final String path, final boolean flipY, final Texture texture) {
    when(materialDef.getMaterialParam(paramName)).thenReturn(new MatParamTexture(VarType.Texture2D, paramName, texture, null));
    final TextureKey textureKey = new TextureKey(path, flipY);
    textureKey.setGenerateMips(true);
    when(assetManager.loadTexture(textureKey)).thenReturn(texture);
    return textureKey;
}
Also used : TextureKey(com.jme3.asset.TextureKey) MatParamTexture(com.jme3.material.MatParamTexture)

Example 2 with MatParamTexture

use of com.jme3.material.MatParamTexture in project jmonkeyengine by jMonkeyEngine.

the class Material method read.

public void read(JmeImporter im) throws IOException {
    InputCapsule ic = im.getCapsule(this);
    name = ic.readString("name", null);
    additionalState = (RenderState) ic.readSavable("render_state", null);
    transparent = ic.readBoolean("is_transparent", false);
    // Load the material def
    String defName = ic.readString("material_def", null);
    HashMap<String, MatParam> params = (HashMap<String, MatParam>) ic.readStringSavableMap("parameters", null);
    boolean enableVcolor = false;
    boolean separateTexCoord = false;
    boolean applyDefaultValues = false;
    boolean guessRenderStateApply = false;
    int ver = ic.getSavableVersion(Material.class);
    if (ver < 1) {
        applyDefaultValues = true;
    }
    if (ver < 2) {
        guessRenderStateApply = true;
    }
    if (im.getFormatVersion() == 0) {
        // Enable compatibility with old models
        if (defName.equalsIgnoreCase("Common/MatDefs/Misc/VertexColor.j3md")) {
            // Using VertexColor, switch to Unshaded and set VertexColor=true
            enableVcolor = true;
            defName = "Common/MatDefs/Misc/Unshaded.j3md";
        } else if (defName.equalsIgnoreCase("Common/MatDefs/Misc/SimpleTextured.j3md") || defName.equalsIgnoreCase("Common/MatDefs/Misc/SolidColor.j3md")) {
            // Using SimpleTextured/SolidColor, just switch to Unshaded
            defName = "Common/MatDefs/Misc/Unshaded.j3md";
        } else if (defName.equalsIgnoreCase("Common/MatDefs/Misc/WireColor.j3md")) {
            // Using WireColor, set wireframe renderstate = true and use Unshaded
            getAdditionalRenderState().setWireframe(true);
            defName = "Common/MatDefs/Misc/Unshaded.j3md";
        } else if (defName.equalsIgnoreCase("Common/MatDefs/Misc/Unshaded.j3md")) {
            // Uses unshaded, ensure that the proper param is set
            MatParam value = params.get("SeperateTexCoord");
            if (value != null && ((Boolean) value.getValue()) == true) {
                params.remove("SeperateTexCoord");
                separateTexCoord = true;
            }
        }
        assert applyDefaultValues && guessRenderStateApply;
    }
    def = (MaterialDef) im.getAssetManager().loadAsset(new AssetKey(defName));
    paramValues = new ListMap<String, MatParam>();
    // load the textures and update nextTexUnit
    for (Map.Entry<String, MatParam> entry : params.entrySet()) {
        MatParam param = entry.getValue();
        if (param instanceof MatParamTexture) {
            MatParamTexture texVal = (MatParamTexture) param;
            // do not add to param values
            if (texVal.getTextureValue() == null || texVal.getTextureValue().getImage() == null) {
                continue;
            }
        }
        if (im.getFormatVersion() == 0 && param.getName().startsWith("m_")) {
            // Ancient version of jME3 ...
            param.setName(param.getName().substring(2));
        }
        if (def.getMaterialParam(param.getName()) == null) {
            logger.log(Level.WARNING, "The material parameter is not defined: {0}. Ignoring..", param.getName());
        } else {
            checkSetParam(param.getVarType(), param.getName());
            paramValues.put(param.getName(), param);
        }
    }
    if (applyDefaultValues) {
        // not available
        for (MatParam param : def.getMaterialParams()) {
            if (param.getValue() != null && paramValues.get(param.getName()) == null) {
                setParam(param.getName(), param.getVarType(), param.getValue());
            }
        }
    }
    if (guessRenderStateApply && additionalState != null) {
        // Try to guess values of "apply" render state based on defaults
        // if value != default then set apply to true
        additionalState.applyPolyOffset = additionalState.offsetEnabled;
        additionalState.applyBlendMode = additionalState.blendMode != BlendMode.Off;
        additionalState.applyColorWrite = !additionalState.colorWrite;
        additionalState.applyCullMode = additionalState.cullMode != FaceCullMode.Back;
        additionalState.applyDepthTest = !additionalState.depthTest;
        additionalState.applyDepthWrite = !additionalState.depthWrite;
        additionalState.applyStencilTest = additionalState.stencilTest;
        additionalState.applyWireFrame = additionalState.wireframe;
    }
    if (enableVcolor) {
        setBoolean("VertexColor", true);
    }
    if (separateTexCoord) {
        setBoolean("SeparateTexCoord", true);
    }
}
Also used : AssetKey(com.jme3.asset.AssetKey) ListMap(com.jme3.util.ListMap)

Example 3 with MatParamTexture

use of com.jme3.material.MatParamTexture in project jmonkeyengine by jMonkeyEngine.

the class J3MOutputCapsule method formatMatParamTexture.

protected static String formatMatParamTexture(MatParamTexture param) {
    StringBuilder ret = new StringBuilder();
    Texture tex = (Texture) param.getValue();
    TextureKey key;
    if (tex != null) {
        key = (TextureKey) tex.getKey();
        if (key != null && key.isFlipY()) {
            ret.append("Flip ");
        }
        ret.append(formatWrapMode(tex, Texture.WrapAxis.S));
        ret.append(formatWrapMode(tex, Texture.WrapAxis.T));
        ret.append(formatWrapMode(tex, Texture.WrapAxis.R));
        //Min and Mag filter
        Texture.MinFilter def = Texture.MinFilter.BilinearNoMipMaps;
        if (tex.getImage().hasMipmaps() || (key != null && key.isGenerateMips())) {
            def = Texture.MinFilter.Trilinear;
        }
        if (tex.getMinFilter() != def) {
            ret.append("Min").append(tex.getMinFilter().name()).append(" ");
        }
        if (tex.getMagFilter() != Texture.MagFilter.Bilinear) {
            ret.append("Mag").append(tex.getMagFilter().name()).append(" ");
        }
        ret.append("\"").append(key.getName()).append("\"");
    }
    return ret.toString();
}
Also used : TextureKey(com.jme3.asset.TextureKey) MatParamTexture(com.jme3.material.MatParamTexture) Texture(com.jme3.texture.Texture)

Example 4 with MatParamTexture

use of com.jme3.material.MatParamTexture in project jmonkeyengine by jMonkeyEngine.

the class TextureAtlas method getMaterialTexture.

private static Texture getMaterialTexture(Geometry geometry, String mapName) {
    Material mat = geometry.getMaterial();
    if (mat == null || mat.getParam(mapName) == null || !(mat.getParam(mapName) instanceof MatParamTexture)) {
        return null;
    }
    MatParamTexture param = (MatParamTexture) mat.getParam(mapName);
    Texture texture = param.getTextureValue();
    if (texture == null) {
        return null;
    }
    return texture;
}
Also used : MatParamTexture(com.jme3.material.MatParamTexture) Material(com.jme3.material.Material) MatParamTexture(com.jme3.material.MatParamTexture) Texture(com.jme3.texture.Texture)

Aggregations

MatParamTexture (com.jme3.material.MatParamTexture)3 TextureKey (com.jme3.asset.TextureKey)2 Texture (com.jme3.texture.Texture)2 AssetKey (com.jme3.asset.AssetKey)1 Material (com.jme3.material.Material)1 ListMap (com.jme3.util.ListMap)1