I am using blender models for the meshes only: I would like to apply my own materials and textures in code. The problem I am having is that the material and texture seems to be ignored unless I define a material in blender.
Here is some sample code from a simpleInitApp:
assetManager.registerLoader(BlenderLoader.class, "blend"); Node features = (Node) assetManager.loadModel("Models/room-features.blend"); Node table = (Node) features.getChild("Table"); Geometry geom = (Geometry) table.getChild(0); Material material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); material.setTexture("DiffuseMap", assetManager.loadTexture("Textures/roof-diffuse.jpg")); geom.setMaterial(material); rootNode.attachChild(geom);
This works correctly only if the blender model has a material added within blender. Even though I am setting a new material in code, it needs to exist in the model to work. That doesn’t make any sense to me given I’m ignoring the imported material - any other attributes of the imported material would be overwritten.
I’ve used a debugger to break after the model has loaded to check what is different in the geometry with and without a material in the blender model. I can’t spot the difference.
Any ideas of what I’m doing wrong?