init
This commit is contained in:
67
sanctification-tcg/card-harness/scripts/export_card_mesh.py
Normal file
67
sanctification-tcg/card-harness/scripts/export_card_mesh.py
Normal file
@@ -0,0 +1,67 @@
|
||||
import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import bpy
|
||||
|
||||
|
||||
def script_args():
|
||||
separator = sys.argv.index("--") if "--" in sys.argv else len(sys.argv)
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--output", required=True)
|
||||
return parser.parse_args(sys.argv[separator + 1:])
|
||||
|
||||
|
||||
def slot_material(name, color):
|
||||
material = bpy.data.materials.get(name) or bpy.data.materials.new(name)
|
||||
material.diffuse_color = (*color, 1.0)
|
||||
return material
|
||||
|
||||
|
||||
args = script_args()
|
||||
output = Path(args.output).resolve()
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
source = bpy.data.objects.get("CARD_David_Foil")
|
||||
if source is None:
|
||||
raise RuntimeError("Expected CARD_David_Foil in the Blender prototype")
|
||||
|
||||
bpy.ops.object.select_all(action="DESELECT")
|
||||
export_object = source.copy()
|
||||
export_object.data = source.data.copy()
|
||||
export_object.name = "SanctificationCardMesh"
|
||||
export_object.data.name = "SanctificationCardMesh"
|
||||
export_object.animation_data_clear()
|
||||
export_object.location = (0, 0, 0)
|
||||
export_object.rotation_euler = (0, 0, 0)
|
||||
export_object.scale = (1, 1, 1)
|
||||
bpy.context.scene.collection.objects.link(export_object)
|
||||
|
||||
material_indices = [polygon.material_index for polygon in export_object.data.polygons]
|
||||
export_object.data.materials.clear()
|
||||
export_object.data.materials.append(slot_material("SLOT_FRONT", (0.8, 0.8, 0.8)))
|
||||
export_object.data.materials.append(slot_material("SLOT_BACK", (0.25, 0.25, 0.25)))
|
||||
export_object.data.materials.append(slot_material("SLOT_EDGE", (0.5, 0.42, 0.28)))
|
||||
for polygon, material_index in zip(export_object.data.polygons, material_indices):
|
||||
polygon.material_index = material_index
|
||||
|
||||
export_object.select_set(True)
|
||||
bpy.context.view_layer.objects.active = export_object
|
||||
|
||||
bpy.ops.export_scene.gltf(
|
||||
filepath=str(output),
|
||||
export_format="GLB",
|
||||
use_selection=True,
|
||||
export_apply=True,
|
||||
export_materials="EXPORT",
|
||||
export_texcoords=True,
|
||||
export_normals=True,
|
||||
export_yup=True,
|
||||
)
|
||||
|
||||
print({
|
||||
"output": str(output),
|
||||
"object": export_object.name,
|
||||
"mesh": export_object.data.name,
|
||||
"materials": [material.name for material in export_object.data.materials],
|
||||
})
|
||||
Reference in New Issue
Block a user