Archive 17/01/2023.

Multiple materials on single mesh

ChunFengTsin

I know this is pretty basic, but I can’t seem to figure out how to get it working. I created a simple room mesh in blender with different materials (each having it’s own texture) for the walls, floor, and ceiling. I’m using the Urho3D-Blender Exporter to export and generate an .mdl for the room’s mesh, and it generates materials and textures for the room.

If I only use one I can get the material/texture to work. If I use more than one, only material is visible (the ceiling) and the rest of the mesh is the blank default material. Not sure what I’m doing wrong. Or if I’m making an incorrect assumption in thinking a single .mdl can have multiple materials.

Alex-Doc

Have you set the StaticModel Material parameters?
IIRC the materials have to be set as list in the StaticModel component:

<attribute name="Material" value="Material;Materials/first.xml;Materials/second.xml" />

A more complete example/prefab:

<?xml version="1.0"?>
<node id="124">
    <attribute name="Is Enabled" value="true" />
    <attribute name="Name" value="Example" />
    <attribute name="Tags" />
    <attribute name="Position" value="0 0 0" />
    <attribute name="Rotation" value="0.935595 0 -0.353083 0" />
    <attribute name="Scale" value="1 1 1" />
    <attribute name="Variables" />
    <component type="StaticModel" id="1234">
        <attribute name="Model" value="Model;Models/MyModel.mdl" />
<!-- here we set the material list -->
        <attribute name="Material" value="Material;Materials/Pink.xml;Materials/Blue.xml" />
<!-- -->
        <attribute name="Cast Shadows" value="true" />
    </component>
</node>
rasteron

Of course you can set multiple materials and also use a material list, having a quick test with the exporter I don’t see any problems here.

I suggest doing a simple test with just a few textures so you can easily check and fix your export issues.

ChunFengTsin

yes , I have make a lowpoly model in blender ,export as obj format, then import to urho3d-eidtor, and last save scene.

ChunFengTsin

I’ve made it with urho-editor ,then I open the scene xml file ,
as you said:
<attribute name="Material" value="Material;Materials/Stone.xml;Materials/Ground.xml;Materials/Snow.xml" />
but I don’t know how the points of model find the material correctly?

1vanK

In blender enable "Export materlas > Materials text list"
In game use staticModel->ApplyMaterialList()

rasteron

Both tools (Blender/AssetImporter) does this for you automatically, but if you need to make some tweaks, this is how it should look like in your xml scene file

<component id="xxx" type="StaticModel">
 	<attribute name="Model" value="Model;Models/Ball.mdl"/>
    <attribute name="Material" value="Material;Materials/sphere.xml;Materials/suzanne.xml;Materials/cube.xml"/>
</component>

Again, if you export your multiple materials correctly even without the textures, the editor/engine will detect the model and supply you with empty fields to fill it out and set your materials/textures.

Modanung

In Blender you can sort elements by material. This option can be found in edit mode in the Mesh menu. The upshot of which is that the geometries in Urho will have the same order as the material slots in Blender.