55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
import pathlib
|
|
import sys
|
|
|
|
import bpy
|
|
|
|
|
|
def mesh_object(name: str, vertices, faces):
|
|
mesh = bpy.data.meshes.new(name + "Mesh")
|
|
mesh.from_pydata(vertices, [], faces)
|
|
mesh.update()
|
|
obj = bpy.data.objects.new(name, mesh)
|
|
bpy.context.collection.objects.link(obj)
|
|
return obj
|
|
|
|
|
|
def main(output: pathlib.Path) -> None:
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
source = mesh_object(
|
|
"WebGapArrayObject",
|
|
[(-0.5, -0.5, 0.0), (0.5, -0.5, 0.0), (0.5, 0.5, 0.0), (-0.5, 0.5, 0.0)],
|
|
[(0, 1, 2, 3)],
|
|
)
|
|
start_cap = mesh_object(
|
|
"WebGapArrayStartCap",
|
|
[(-0.4, -0.4, 0.0), (0.4, -0.4, 0.0), (0.0, 0.4, 0.0)],
|
|
[(0, 1, 2)],
|
|
)
|
|
end_cap = mesh_object(
|
|
"WebGapArrayEndCap",
|
|
[(-0.4, -0.4, 0.0), (0.4, -0.4, 0.0), (0.0, 0.4, 0.0)],
|
|
[(0, 1, 2)],
|
|
)
|
|
start_cap.location.x = -2.0
|
|
end_cap.location.x = 5.0
|
|
modifier = source.modifiers.new(name="WebGapArray", type="ARRAY")
|
|
modifier.count = 4
|
|
modifier.relative_offset_displace = (1.25, 0.0, 0.0)
|
|
modifier.start_cap = start_cap
|
|
modifier.end_cap = end_cap
|
|
modifier.show_viewport = True
|
|
modifier.show_render = False
|
|
modifier.show_in_editmode = True
|
|
modifier.show_on_cage = False
|
|
bpy.context.view_layer.objects.active = source
|
|
source.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-00031.py -- OUTPUT")
|
|
main(pathlib.Path(arguments[0]))
|