Search in sources :

Example 11 with TextureKey

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

the class TestRagdollCharacter method initWall.

public void initWall(float bLength, float bWidth, float bHeight) {
    Box brick = new Box(bLength, bHeight, bWidth);
    brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
    Material mat2 = 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);
    mat2.setTexture("ColorMap", tex);
    float startpt = bLength / 4;
    float height = -5;
    for (int j = 0; j < 15; j++) {
        for (int i = 0; i < 4; i++) {
            Vector3f ori = new Vector3f(i * bLength * 2 + startpt, bHeight + height, -10);
            Geometry reBoxg = new Geometry("brick", brick);
            reBoxg.setMaterial(mat2);
            reBoxg.setLocalTranslation(ori);
            //for geometry with sphere mesh the physics system automatically uses a sphere collision shape
            reBoxg.addControl(new RigidBodyControl(1.5f));
            reBoxg.setShadowMode(ShadowMode.CastAndReceive);
            reBoxg.getControl(RigidBodyControl.class).setFriction(0.6f);
            this.rootNode.attachChild(reBoxg);
            this.getPhysicsSpace().add(reBoxg);
        }
        startpt = -startpt;
        height += 2 * bHeight;
    }
}
Also used : Geometry(com.jme3.scene.Geometry) TextureKey(com.jme3.asset.TextureKey) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 12 with TextureKey

use of com.jme3.asset.TextureKey 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 13 with TextureKey

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

the class FbxImage method toJmeObject.

@Override
protected Object toJmeObject() {
    Image image = null;
    String fileName = null;
    String relativeFilePathJme;
    if (filePath != null) {
        fileName = getFileName(filePath);
    } else if (relativeFilePath != null) {
        fileName = getFileName(relativeFilePath);
    }
    if (fileName != null) {
        try {
            // Try to load filename relative to FBX folder
            key = new TextureKey(sceneFolderName + fileName);
            key.setGenerateMips(true);
            image = loadImageSafe(assetManager, key);
            // Try to load relative filepath relative to FBX folder
            if (image == null && relativeFilePath != null) {
                // Convert Windows paths to jME3 paths
                relativeFilePathJme = relativeFilePath.replace('\\', '/');
                key = new TextureKey(sceneFolderName + relativeFilePathJme);
                key.setGenerateMips(true);
                image = loadImageSafe(assetManager, key);
            }
            // Try to load embedded image
            if (image == null && content != null && content.length > 0) {
                key = new TextureKey(fileName);
                key.setGenerateMips(true);
                InputStream is = new ByteArrayInputStream(content);
                image = assetManager.loadAssetFromStream(key, is).getImage();
                // NOTE: embedded texture doesn't exist in the asset manager,
                //       so the texture key must not be saved.
                key = null;
            }
        } catch (AssetLoadException ex) {
            logger.log(Level.WARNING, "Error while attempting to load texture {0}:\n{1}", new Object[] { name, ex.toString() });
        }
    }
    if (image == null) {
        logger.log(Level.WARNING, "Cannot locate {0} for texture {1}", new Object[] { fileName, name });
        image = PlaceholderAssets.getPlaceholderImage(assetManager);
    }
    return image;
}
Also used : TextureKey(com.jme3.asset.TextureKey) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FbxObject(com.jme3.scene.plugins.fbx.obj.FbxObject) Image(com.jme3.texture.Image) AssetLoadException(com.jme3.asset.AssetLoadException)

Example 14 with TextureKey

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

the class FbxTexture method toJmeObject.

@Override
protected Texture toJmeObject() {
    Image image = null;
    TextureKey key = null;
    if (media != null) {
        image = (Image) media.getJmeObject();
        key = media.getTextureKey();
    }
    if (image == null) {
        image = PlaceholderAssets.getPlaceholderImage(assetManager);
    }
    Texture2D tex = new Texture2D(image);
    if (key != null) {
        tex.setKey(key);
        tex.setName(key.getName());
        tex.setAnisotropicFilter(key.getAnisotropy());
    }
    tex.setMinFilter(MinFilter.Trilinear);
    tex.setMagFilter(MagFilter.Bilinear);
    if (wrapModeU == 0) {
        tex.setWrap(WrapAxis.S, WrapMode.Repeat);
    }
    if (wrapModeV == 0) {
        tex.setWrap(WrapAxis.T, WrapMode.Repeat);
    }
    return tex;
}
Also used : TextureKey(com.jme3.asset.TextureKey) Texture2D(com.jme3.texture.Texture2D) Image(com.jme3.texture.Image)

Example 15 with TextureKey

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

the class MaterialExtensionLoader method readExtendingMaterialStatement.

private void readExtendingMaterialStatement(Statement statement) throws IOException {
    if (statement.getLine().startsWith("set_texture_alias")) {
        String[] split = statement.getLine().split(" ", 3);
        String aliasName = split[1];
        String texturePath = split[2];
        String jmeParamName = matExt.getTextureMapping(aliasName);
        TextureKey texKey = new TextureKey(texturePath, false);
        texKey.setGenerateMips(true);
        Texture tex;
        try {
            tex = assetManager.loadTexture(texKey);
            tex.setWrap(WrapMode.Repeat);
        } catch (AssetNotFoundException ex) {
            logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[] { texKey, key });
            tex = new Texture2D(PlaceholderAssets.getPlaceholderImage(assetManager));
            tex.setWrap(WrapMode.Repeat);
            tex.setKey(texKey);
        }
        material.setTexture(jmeParamName, tex);
    }
}
Also used : TextureKey(com.jme3.asset.TextureKey) Texture2D(com.jme3.texture.Texture2D) AssetNotFoundException(com.jme3.asset.AssetNotFoundException) Texture(com.jme3.texture.Texture)

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