Search in sources :

Example 1 with AssetNotFoundException

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

the class J3MLoader method parseTextureType.

private Texture parseTextureType(final VarType type, final String value) {
    final List<String> textureValues = tokenizeTextureValue(value);
    final List<TextureOptionValue> textureOptionValues = parseTextureOptions(textureValues);
    TextureKey textureKey = null;
    // If there is only one token on the value, it must be the path to the texture.
    if (textureValues.size() == 1) {
        textureKey = new TextureKey(textureValues.get(0), false);
    } else {
        String texturePath = value.trim();
        // If there are no valid "new" texture options specified but the path is split into several parts, lets parse the old way.
        if (isTexturePathDeclaredTheTraditionalWay(textureOptionValues, texturePath)) {
            boolean flipY = false;
            if (texturePath.startsWith("Flip Repeat ") || texturePath.startsWith("Repeat Flip ")) {
                texturePath = texturePath.substring(12).trim();
                flipY = true;
            } else if (texturePath.startsWith("Flip ")) {
                texturePath = texturePath.substring(5).trim();
                flipY = true;
            } else if (texturePath.startsWith("Repeat ")) {
                texturePath = texturePath.substring(7).trim();
            }
            // Support path starting with quotes (double and single)
            if (texturePath.startsWith("\"") || texturePath.startsWith("'")) {
                texturePath = texturePath.substring(1);
            }
            // Support path ending with quotes (double and single)
            if (texturePath.endsWith("\"") || texturePath.endsWith("'")) {
                texturePath = texturePath.substring(0, texturePath.length() - 1);
            }
            textureKey = new TextureKey(texturePath, flipY);
        }
        if (textureKey == null) {
            textureKey = new TextureKey(textureValues.get(textureValues.size() - 1), false);
        }
        // Apply texture options to the texture key
        if (!textureOptionValues.isEmpty()) {
            for (final TextureOptionValue textureOptionValue : textureOptionValues) {
                textureOptionValue.applyToTextureKey(textureKey);
            }
        }
    }
    switch(type) {
        case Texture3D:
            textureKey.setTextureTypeHint(Texture.Type.ThreeDimensional);
            break;
        case TextureArray:
            textureKey.setTextureTypeHint(Texture.Type.TwoDimensionalArray);
            break;
        case TextureCubeMap:
            textureKey.setTextureTypeHint(Texture.Type.CubeMap);
            break;
    }
    textureKey.setGenerateMips(true);
    Texture texture;
    try {
        texture = assetManager.loadTexture(textureKey);
    } catch (AssetNotFoundException ex) {
        logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[] { textureKey, key });
        texture = null;
    }
    if (texture == null) {
        texture = new Texture2D(PlaceholderAssets.getPlaceholderImage(assetManager));
        texture.setKey(textureKey);
        texture.setName(textureKey.getName());
    }
    // Apply texture options to the texture
    if (!textureOptionValues.isEmpty()) {
        for (final TextureOptionValue textureOptionValue : textureOptionValues) {
            textureOptionValue.applyToTexture(texture);
        }
    }
    return texture;
}
Also used : Texture2D(com.jme3.texture.Texture2D) Texture(com.jme3.texture.Texture)

Example 2 with AssetNotFoundException

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

the class MTLLoader method loadTexture.

protected Texture loadTexture(String path) {
    String[] split = path.trim().split("\\p{javaWhitespace}+");
    // will crash if path is an empty string
    path = split[split.length - 1];
    String name = new File(path).getName();
    TextureKey texKey = new TextureKey(folderName + name);
    texKey.setGenerateMips(true);
    Texture texture;
    try {
        texture = assetManager.loadTexture(texKey);
        texture.setWrap(WrapMode.Repeat);
    } catch (AssetNotFoundException ex) {
        logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[] { texKey, key });
        texture = new Texture2D(PlaceholderAssets.getPlaceholderImage(assetManager));
        texture.setWrap(WrapMode.Repeat);
        texture.setKey(key);
    }
    return texture;
}
Also used : Texture2D(com.jme3.texture.Texture2D) File(java.io.File) Texture(com.jme3.texture.Texture)

Example 3 with AssetNotFoundException

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

the class ImageTileLoader method getHeightMapAt.

/**
     * Lets you specify the type of images that are being loaded. All images
     * must be the same type.
     * @param imageType eg. BufferedImage.TYPE_USHORT_GRAY
     */
/*public void setImageType(int imageType) {
        this.imageType = imageType;
    }*/
/**
     * The ImageHeightmap that will parse the image type that you 
     * specify with setImageType().
     * @param customImageHeightmap must extend AbstractHeightmap
     */
/*public void setCustomImageHeightmap(ImageHeightmap customImageHeightmap) {
        if (!(customImageHeightmap instanceof AbstractHeightMap)) {
            throw new IllegalArgumentException("customImageHeightmap must be an AbstractHeightMap!");
        }
        this.customImageHeightmap = customImageHeightmap;
    }*/
private HeightMap getHeightMapAt(Vector3f location) {
    // HEIGHTMAP image (for the terrain heightmap)
    int x = (int) location.x;
    int z = (int) location.z;
    AbstractHeightMap heightmap = null;
    //BufferedImage im = null;
    String name = null;
    try {
        name = namer.getName(x, z);
        logger.log(Level.FINE, "Loading heightmap from file: {0}", name);
        final Texture texture = assetManager.loadTexture(new TextureKey(name));
        heightmap = new ImageBasedHeightMap(texture.getImage());
        /*if (assetInfo != null){
                InputStream in = assetInfo.openStream();
                im = ImageIO.read(in);
            } else {
                im = new BufferedImage(patchSize, patchSize, imageType);
                logger.log(Level.WARNING, "File: {0} not found, loading zero heightmap instead", name);
            }*/
        // CREATE HEIGHTMAP
        /*if (imageType == BufferedImage.TYPE_USHORT_GRAY) {
                heightmap = new Grayscale16BitHeightMap(im);
            } else if (imageType == BufferedImage.TYPE_3BYTE_BGR) {
                heightmap = new ImageBasedHeightMap(im);
            } else if (customImageHeightmap != null && customImageHeightmap instanceof AbstractHeightMap) {
                // If it gets here, it means you have specified a different image type, and you must
                // then also supply a custom image heightmap class that can parse that image into
                // a heightmap.
                customImageHeightmap.setImage(im);
                heightmap = (AbstractHeightMap) customImageHeightmap;
            } else {
                // error, no supported image format and no custom image heightmap specified
                if (customImageHeightmap == null)
                    logger.log(Level.SEVERE, "Custom image type specified [{0}] but no customImageHeightmap declared! Use setCustomImageHeightmap()",imageType);
                if (!(customImageHeightmap instanceof AbstractHeightMap))
                    logger.severe("customImageHeightmap must be an AbstractHeightMap!");
                return null;
            }*/
        heightmap.setHeightScale(1);
        heightmap.load();
    //} catch (IOException e) {
    //    e.printStackTrace();
    } catch (AssetNotFoundException e) {
        logger.log(Level.WARNING, "Asset {0} not found, loading zero heightmap instead", name);
    }
    return heightmap;
}
Also used : TextureKey(com.jme3.asset.TextureKey) AssetNotFoundException(com.jme3.asset.AssetNotFoundException) Texture(com.jme3.texture.Texture)

Example 4 with AssetNotFoundException

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

the class MeshLoader method applyMaterial.

private void applyMaterial(Geometry geom, String matName) {
    Material mat = null;
    if (matName == null) {
        // no material specified. use placeholder.
        mat = null;
    } else if (matName.endsWith(".j3m")) {
        // load as native jme3 material instance
        try {
            mat = assetManager.loadMaterial(matName);
        } catch (AssetNotFoundException ex) {
            // Warning will be raised (see below)
            if (!ex.getMessage().equals(matName)) {
                throw ex;
            }
        }
    } else {
        if (materialList != null) {
            mat = materialList.get(matName);
        }
    }
    if (mat == null) {
        logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[] { matName, key });
        mat = PlaceholderAssets.getPlaceholderMaterial(assetManager);
    //mat.setKey(new MaterialKey(matName));
    }
    if (mat.isTransparent()) {
        geom.setQueueBucket(Bucket.Transparent);
    }
    geom.setMaterial(mat);
}
Also used : Material(com.jme3.material.Material)

Example 5 with AssetNotFoundException

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

the class SceneMaterialLoader method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attribs) throws SAXException {
    if (qName.equals("externals")) {
        checkTopNode("scene");
        // Has an externals block, create material list.
        materialList = new MaterialList();
    } else if (qName.equals("item")) {
        checkTopNode("externals");
        if (!attribs.getValue("type").equals("material")) {
            // This is not a material external. Ignore it.
            ignoreItem = true;
        }
    } else if (qName.equals("file")) {
        checkTopNode("item");
        if (!ignoreItem) {
            String materialPath = attribs.getValue("name");
            String materialName = new File(materialPath).getName();
            String matFile = folderName + materialName;
            try {
                MaterialList loadedMaterialList = (MaterialList) assetManager.loadAsset(new OgreMaterialKey(matFile));
                materialList.putAll(loadedMaterialList);
            } catch (AssetNotFoundException ex) {
                logger.log(Level.WARNING, "Cannot locate material file: {0}", matFile);
            }
        }
    }
    elementStack.push(qName);
}
Also used : MaterialList(com.jme3.material.MaterialList) OgreMaterialKey(com.jme3.scene.plugins.ogre.matext.OgreMaterialKey) AssetNotFoundException(com.jme3.asset.AssetNotFoundException) File(java.io.File)

Aggregations

AssetNotFoundException (com.jme3.asset.AssetNotFoundException)12 Texture (com.jme3.texture.Texture)6 IOException (java.io.IOException)5 InputStreamReader (java.io.InputStreamReader)4 AssetInfo (com.jme3.asset.AssetInfo)3 TextureKey (com.jme3.asset.TextureKey)3 OgreMaterialKey (com.jme3.scene.plugins.ogre.matext.OgreMaterialKey)3 Texture2D (com.jme3.texture.Texture2D)3 BufferedReader (java.io.BufferedReader)3 SAXException (org.xml.sax.SAXException)3 BlenderKey (com.jme3.asset.BlenderKey)2 InputCapsule (com.jme3.export.InputCapsule)2 Spatial (com.jme3.scene.Spatial)2 File (java.io.File)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXParserFactory (javax.xml.parsers.SAXParserFactory)2 InputSource (org.xml.sax.InputSource)2 XMLReader (org.xml.sax.XMLReader)2 SettingsDialog (com.jme3.app.SettingsDialog)1 SelectionListener (com.jme3.app.SettingsDialog.SelectionListener)1