47 lines
1.9 KiB
Python
47 lines
1.9 KiB
Python
"""Executed by Blender, never by Unreal. Export an evaluated, joined static mesh."""
|
|
import argparse
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
import bpy
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--output", required=True)
|
|
parser.add_argument("--collection", default="Character")
|
|
args = parser.parse_args(sys.argv[sys.argv.index("--") + 1:])
|
|
collection = bpy.data.collections.get(args.collection)
|
|
if collection is None:
|
|
raise RuntimeError(f"Brak kolekcji {args.collection!r} w zapisanym pliku blend.")
|
|
meshes = [obj for obj in collection.all_objects if obj.type == "MESH"]
|
|
if not meshes:
|
|
raise RuntimeError("Kolekcja Character nie zawiera siatek.")
|
|
bpy.ops.object.select_all(action="DESELECT")
|
|
depsgraph = bpy.context.evaluated_depsgraph_get()
|
|
copies = []
|
|
for obj in meshes:
|
|
evaluated = obj.evaluated_get(depsgraph)
|
|
data = bpy.data.meshes.new_from_object(evaluated, depsgraph=depsgraph)
|
|
duplicate = bpy.data.objects.new(obj.name + "_export", data)
|
|
bpy.context.scene.collection.objects.link(duplicate)
|
|
duplicate.matrix_world = obj.matrix_world.copy()
|
|
duplicate.select_set(True)
|
|
copies.append(duplicate)
|
|
bpy.context.view_layer.objects.active = copies[0]
|
|
bpy.ops.object.join()
|
|
joined = bpy.context.object
|
|
joined.name = "Character"
|
|
# Origin at world zero: stable pivot, independent of which body part is first.
|
|
bpy.context.scene.cursor.location = (0, 0, 0)
|
|
bpy.ops.object.origin_set(type="ORIGIN_CURSOR")
|
|
output = Path(args.output).resolve()
|
|
output.parent.mkdir(parents=True, exist_ok=True)
|
|
bpy.ops.export_scene.gltf(filepath=str(output), export_format="GLB", use_selection=True,
|
|
export_animations=False, export_materials="EXPORT", export_yup=True)
|
|
print("WORKSHOP_EXPORTED=" + str(output))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|