Models with multiple materials

I have create a model in Blender and it has two materials attached to it. Ive exported it using reattiva exporter.
The problem is that i cannot assign both of the materials to the object when i create it.


These are the settings im using


This is what its supposed to look like


This is what it looks like in game

Finally here is the code im using to create the model

	StaticModel* gunObject = gunNode->CreateComponent<StaticModel>();

Use the overloaded method which takes both the index and the texture.

gunObject->SetMaterial(0 , cache->GetResource(“Materials/Base.xml”));
gunObject->SetMaterial(1 ,cache->GetResource(“Materials/BarrelStuff.xml”));

1 Like

And if the geometry id’s don’t match up with the material slots in Blender, sort the elements by material before export.

Python script for sorting elements of all selected objects by material
import bpy
for ob in bpy.context.selected_objects: = ob
    bpy.ops.object.mode_set(mode = 'EDIT')
    bpy.ops.mesh.sort_elements(type='MATERIAL', elements={'FACE'})
    bpy.ops.object.mode_set(mode = 'OBJECT')

For a single object you can find the menu option under Mesh -> Sort Elements -> Material in Edit Mode.

1 Like

use material list file