Unload an OBJ model's texture

I have a textured mesh (OBJ + MTL file combo) that I load like so:

Spatial spatial = assetManager.loadModel("path/to/some/model.obj");
rootNode.attachChild(spatial);

I’d like to present this model in two formats: textured & untextured. By “untextured”, perhaps I mean unshaded, but what I’m looking for is a way to render the model as just a “mesh skeleton” (essentially just as vertices and connected edges). Is this possible to do?

mat.getAdditionalRenderState().setWireframe(true);

You need to get the material for this. So I think you’ll need to cast it to a geometry which has a getMaterial() method, which may require some searching on the forum but it’s pretty well documented :stuck_out_tongue:

Thanks @JESTERRRRRR, but isn’t Geometry a Spatial subclass? If so, why couldn’t I just do:

Geometry geo = (Geometry)spatial;

Or am I missing something? Thanks again!

I remember having done this once and finding it didn’t work but try it first by all means.

This is why. I think for me I just ended up doing spatial.getChild(0) and casting that to Geometry, not sure if yours will be the same case.

Or rather than casting randomly about your section of the scene graph, you can hit all of the geometry under that Spatial (or the spatial itself) pretty easily:
http://javadoc.jmonkeyengine.org/com/jme3/scene/SceneGraphVisitorAdapter.html
http://javadoc.jmonkeyengine.org/com/jme3/scene/Spatial.html#depthFirstTraversal-com.jme3.scene.SceneGraphVisitor-

Never seen that before… what a spoilsport

Thanks @pspeed and @JESTERRRRRR but I guess I’m not seeing the forest through the trees here. I’m loading a single model (OBJ) via assetManager.loadModel(String)

Wouldn’t that mean the resulting spatial will always be a Geometry?!? How could I load a model and have that be a Node with children?

Quite often. For example, if your model has more than one texture then it is probably two geometries under a node. If it has more than one mesh then it is two geometries under a node.

The case where loading a model results in a single Geometry is the rarer case.