Search in sources :

Example 1 with ContentTextureKey

use of com.jme3.scene.plugins.fbx.ContentTextureKey in project jmonkeyengine by jMonkeyEngine.

the class FbxImage method createImage.

private Image createImage() {
    AssetManager assetManager = scene.assetManager;
    Image image = null;
    if (filename != null) {
        // Try load by absolute path
        File file = new File(filename);
        if (file.exists() && file.isFile()) {
            File dir = new File(file.getParent());
            String locatorPath = dir.getAbsolutePath();
            Texture tex = null;
            try {
                assetManager.registerLocator(locatorPath, com.jme3.asset.plugins.FileLocator.class);
                tex = assetManager.loadTexture(file.getName());
            } catch (Exception e) {
            } finally {
                assetManager.unregisterLocator(locatorPath, com.jme3.asset.plugins.FileLocator.class);
            }
            if (tex != null)
                image = tex.getImage();
        }
    }
    if (image == null && relativeFilename != null) {
        // Try load by relative path
        File dir = new File(scene.sceneFolderName);
        String locatorPath = dir.getAbsolutePath();
        Texture tex = null;
        try {
            assetManager.registerLocator(locatorPath, com.jme3.asset.plugins.FileLocator.class);
            tex = assetManager.loadTexture(relativeFilename);
        } catch (Exception e) {
        } finally {
            assetManager.unregisterLocator(locatorPath, com.jme3.asset.plugins.FileLocator.class);
        }
        if (tex != null)
            image = tex.getImage();
    }
    if (image == null && content != null) {
        // Try load from content
        String filename = null;
        if (this.filename != null)
            filename = new File(this.filename).getName();
        if (filename != null && this.relativeFilename != null)
            filename = this.relativeFilename;
        // Filename is required to aquire asset loader by extension
        if (filename != null) {
            String locatorPath = scene.sceneFilename;
            // Unique path
            filename = scene.sceneFilename + File.separatorChar + filename;
            Texture tex = null;
            try {
                assetManager.registerLocator(locatorPath, ContentTextureLocator.class);
                tex = assetManager.loadTexture(new ContentTextureKey(filename, content));
            } catch (Exception e) {
            } finally {
                assetManager.unregisterLocator(locatorPath, ContentTextureLocator.class);
            }
            if (tex != null)
                image = tex.getImage();
        }
    }
    if (image == null) {
        // Try to load from files near
        if (relativeFilename != null) {
            String[] split = relativeFilename.split("[\\\\/]");
            String filename = split[split.length - 1];
            Texture tex = null;
            try {
                tex = assetManager.loadTexture(new ContentTextureKey(scene.currentAssetInfo.getKey().getFolder() + filename, content));
            } catch (Exception e) {
            }
            if (tex != null)
                image = tex.getImage();
        }
    }
    if (image == null)
        return new Image(Image.Format.RGB8, 1, 1, BufferUtils.createByteBuffer((int) ((long) 1 * (long) 1 * (long) Image.Format.RGB8.getBitsPerPixel() / 8L)), ColorSpace.Linear);
    return image;
}
Also used : AssetManager(com.jme3.asset.AssetManager) ContentTextureKey(com.jme3.scene.plugins.fbx.ContentTextureKey) Image(com.jme3.texture.Image) File(java.io.File) Texture(com.jme3.texture.Texture)

Aggregations

AssetManager (com.jme3.asset.AssetManager)1 ContentTextureKey (com.jme3.scene.plugins.fbx.ContentTextureKey)1 Image (com.jme3.texture.Image)1 Texture (com.jme3.texture.Texture)1 File (java.io.File)1