question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ClassCastException if MTL loader can not find material texture

See original GitHub issue

JME 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:open
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
deventcommented, Apr 3, 2020

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

0reactions
pspeed42commented, Dec 5, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found