Archive 17/01/2023.

Models with multiple materials

Sean221

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.

ExporterSettings

These are the settings im using

BlenderGun

This is what its supposed to look like

InGame

This is what it looks like in game

Finally here is the code im using to create the model

	StaticModel* gunObject = gunNode->CreateComponent<StaticModel>();
	gunObject->SetModel(cache->GetResource<Model>("Models/Gun.mdl"));
	gunObject->SetMaterial(cache->GetResource<Material>("Materials/Base.xml"));
	gunObject->SetMaterial(cache->GetResource<Material>("Materials/BarrelStuff.xml"));
Dave82

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

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

Modanung

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:
    bpy.context.scene.objects.active = ob
    
    bpy.ops.object.mode_set(mode = 'EDIT')
    bpy.ops.mesh.select_all(action='SELECT')
    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.

1vanK

use material list file