jme3 getMaterial

Is it possible to get the material of a loaded model?

I’m loading a model from blender as .obj. It works all fine and it is correctly textured and colored. And i can set the material to for example another SolidColor with setMatrial and the definition. But how can i reverse it back to its original texture/color? Must i somehow export the texture from blender and load it as a material? Or is there a reset method that i didn’t discover yet?

Every Geometry object has a getMaterial method. You can get the current material like that before you apply another one and save it in memory or export it to a file. You can even modify the material like that. Its converted to a jme3 material on import.



Indeed, the Geometry class has this method. But what about a spatial? Like for example in the “Hello Assets” tutorial?

Spatial test = assetManager.loadModel(“test.obj”);

A cast doesn’t work here. Must i somehow convert the Spatial into a geometry?

Uh, try opening a model in jMP and you will understand… :slight_smile: The “Spatial” you load is in most cases a Node containing children or a whole tree of children. The leafs of the tree are in most cases “Geometry” spatials and you can modify these the way I suggested.



Ah, thank you normen. Now it’s making more sense why there isn’t a getMaterial method, because there could be more than one in the tree structure.

So i would have to get all the materials from all the geometrys and than set it later manually with setMaterial method for all the geometrys?

Isn’t there a more convenient way? I mean i can still setMaterial the spatial and all the geometrys in the spatial will get one material.

How could there be if theres more than one Material. Should their colors etc. be combined to the average value? :wink:

K, so there isn’t an übermaterial class that i never heard of that stores the different materials of the geoms ;).