"""Build tests/fixtures/multi_material.glb: one cube with two materials."""

import os

import bpy

OUT = os.path.join(
    os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
    "tests/fixtures/multi_material.glb",
)

bpy.ops.wm.read_factory_settings(use_empty=True)

bpy.ops.mesh.primitive_cube_add(size=2)
cube = bpy.context.active_object
cube.name = "MultiMaterialCube"

material_a = bpy.data.materials.new("MaterialA")
material_b = bpy.data.materials.new("MaterialB")
cube.data.materials.append(material_a)
cube.data.materials.append(material_b)

for index, polygon in enumerate(cube.data.polygons):
    polygon.material_index = 0 if index < 3 else 1

os.makedirs(os.path.dirname(OUT), exist_ok=True)
bpy.ops.export_scene.gltf(
    filepath=OUT, export_format="GLB", export_apply=True, export_extras=True
)
print(f"Exported {OUT}")
