#!/usr/bin/env python3 import pathlib import sys import bpy def main(output: pathlib.Path) -> None: bpy.ops.wm.read_factory_settings(use_empty=True) mesh = bpy.data.meshes.new("WebGapArmatureMesh") mesh.from_pydata( [(-1.0, -1.0, 0.0), (1.0, -1.0, 0.0), (1.0, 1.0, 0.0), (-1.0, 1.0, 0.0)], [], [(0, 1, 2), (0, 2, 3)], ) mesh.update() mesh_object = bpy.data.objects.new("WebGapArmatureMeshObject", mesh) bpy.context.collection.objects.link(mesh_object) armature = bpy.data.armatures.new("WebGapArmature") armature_object = bpy.data.objects.new("WebGapArmatureObject", armature) bpy.context.collection.objects.link(armature_object) bpy.context.view_layer.objects.active = armature_object armature_object.select_set(True) bpy.ops.object.mode_set(mode="EDIT") root = armature.edit_bones.new("Root") root.head = (0.0, 0.0, 0.0) root.tail = (0.0, 0.0, 1.0) bpy.ops.object.mode_set(mode="OBJECT") armature_object.select_set(False) vertex_group = mesh_object.vertex_groups.new(name="Root") vertex_group.add([0, 1, 2, 3], 1.0, "REPLACE") modifier = mesh_object.modifiers.new(name="WebGapArmature", type="ARMATURE") modifier.object = armature_object modifier.vertex_group = "Root" modifier.show_viewport = True modifier.show_render = True modifier.show_in_editmode = True modifier.show_on_cage = False bpy.context.view_layer.objects.active = mesh_object mesh_object.select_set(True) bpy.ops.wm.save_as_mainfile(filepath=str(output.resolve()), check_existing=False, compress=True) if __name__ == "__main__": arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 1: raise SystemExit("usage: blender -b --python M16-GAP-00030.py -- OUTPUT") main(pathlib.Path(arguments[0]))