ClassCastException if MTL loader can not find material texture
See original GitHub issueJME throws a ClassCastException if the MTL loader can not find the material texture key. Code:
this.box = assetManager.loadModel("assets/models/tiles/box-1.obj");
Material mat1 = assetManager.loadMaterial("assets/materials/tiles/loam/loam-1-1.mtl")
mat1.setTexture("textures/loam/loam-1-1.png", assetManager.loadTexture("assets/textures/tiles/loam/loam-1-1.png"));
box.setMaterial(mat1);
return box
See the code in https://github.com/jMonkeyEngine/jmonkeyengine/blob/v3.2.4-stable/jme3-core/src/plugins/java/com/jme3/scene/plugins/MTLLoader.java#L186
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);
You set the MaterialKey to a texture object. It will throw a CCEx on https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-core/src/main/java/com/jme3/texture/Texture.java#L427
public void setKey(AssetKey key){
this.key = (TextureKey) key;
}
Error:
java.lang.ClassCastException: class com.jme3.asset.MaterialKey cannot be cast to class com.jme3.asset.TextureKey (com.jme3.asset.MaterialKey and com.jme3.asset.TextureKey are in unnamed module of loader 'app')
at com.jme3.texture.Texture.setKey(Texture.java:427)
at com.jme3.scene.plugins.MTLLoader.loadTexture(MTLLoader.java:186)
at com.jme3.scene.plugins.MTLLoader.readLine(MTLLoader.java:232)
at com.jme3.scene.plugins.MTLLoader.load(MTLLoader.java:304)
Version: 3.2.4-stable
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
MTLLoader doesn't show texture on the object I load
Tried loading the globe in Blender and the texture looks good in there, but in browser things aren't the same. var mtlLoader =...
Read more >Problem loading textured model (probably solved)
It worked just fine until I attempted to texture my model in Blender and got this runtime error: ClassCastException: com.jme3.asset.ModelKey cannot be …...
Read more >MTLLoader – three.js docs
OBJ that describes surface shading (material) properties of objects within one or more .OBJ files. Constructor. MTLLoader( loadingManager : LoadingManager ).
Read more >Processing Discourse - objimport library issue in ... - Processing 1.0
When trying to run the simple example I get several errors and the obj file does not get drawn in the sketch window:...
Read more >MTL Loader - Three.js Tutorials - sbcode.net
MTL Loader. Video Lecture ... MTL is the material information used by an OBJ file. ... If you create your OBJ and MTL...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Actually, I’m using now the JMonkeyEngine IDE to import models and I’m using the GITF file format to export from Blender. The steps are: 1. Export model from Blender in GITF. 2. Import GITF file in JMonkeyEngine IDE. 3. Use the generated 3jo file in your game. I think it’s better to just deprecate all the other import formats from JMonkeyEngine. https://wiki.jmonkeyengine.org/jme3/external/blender/blender_gltf.html
The real problem: WARNING: Cannot locate Worlds/tray/Wallpaper_Dog_Bone.jpg (Flipped) (Mipmapped)
It cannot locate your texture.
The subsequent error is caused by the code that is attempting to load a stand-in texture for you… so even if that bug is fixed your model will still not be loading correctly.