76 lines
2.5 KiB
Python
76 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
import pathlib
|
|
import sys
|
|
|
|
import bpy
|
|
|
|
|
|
def sculpt_mesh():
|
|
mesh = bpy.data.meshes.new("WBV2P4003SculptMesh")
|
|
mesh.from_pydata(
|
|
[(-1, -1, 0), (1, -1, 0), (1, 1, 0), (-1, 1, 0), (0, 0, 1)],
|
|
[],
|
|
[(0, 1, 2, 3), (0, 1, 4), (1, 2, 4), (2, 3, 4), (3, 0, 4)],
|
|
)
|
|
mesh.update()
|
|
mask = mesh.attributes.new(".sculpt_mask", "FLOAT", "POINT")
|
|
for index, item in enumerate(mask.data):
|
|
item.value = 0.0 if index == 0 else 0.25 * index
|
|
face_sets = mesh.attributes.new(".sculpt_face_set", "INT", "FACE")
|
|
for index, item in enumerate(face_sets.data):
|
|
item.value = index + 1
|
|
obj = bpy.data.objects.new("WBV2P4003SculptObject", mesh)
|
|
bpy.context.scene.collection.objects.link(obj)
|
|
return obj
|
|
|
|
|
|
def curve_object():
|
|
data = bpy.data.curves.new("WBV2P4003Curve", "CURVE")
|
|
data.dimensions = "3D"
|
|
data.resolution_u = 4
|
|
spline = data.splines.new("BEZIER")
|
|
spline.bezier_points.add(2)
|
|
for point, co in zip(spline.bezier_points, ((-1.5, 2, 0), (0, 2.5, 0.75), (1.5, 2, 0))):
|
|
point.co = co
|
|
point.handle_left_type = "AUTO"
|
|
point.handle_right_type = "AUTO"
|
|
obj = bpy.data.objects.new("WBV2P4003CurveObject", data)
|
|
bpy.context.scene.collection.objects.link(obj)
|
|
return obj
|
|
|
|
|
|
def point_cloud_object():
|
|
seed = bpy.data.meshes.new("WBV2P4003PointSeed")
|
|
seed.from_pydata([(-1, -2, 0), (0, -2, 0.5), (1, -2, 0)], [], [])
|
|
obj = bpy.data.objects.new("WBV2P4003PointCloudObject", seed)
|
|
bpy.context.scene.collection.objects.link(obj)
|
|
bpy.context.view_layer.objects.active = obj
|
|
obj.select_set(True)
|
|
bpy.ops.object.convert(target="POINTCLOUD")
|
|
obj.data.name = "WBV2P4003PointCloud"
|
|
radius = obj.data.attributes.new("radius", "FLOAT", "POINT")
|
|
for index, item in enumerate(radius.data):
|
|
item.value = 0.05 + index * 0.01
|
|
return obj
|
|
|
|
|
|
def main(output):
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
scene = bpy.context.scene
|
|
scene.name = "WBV2P4003SculptNonmeshScene"
|
|
scene.frame_start = 1
|
|
scene.frame_end = 8
|
|
scene.frame_set(1)
|
|
sculpt_mesh()
|
|
curve_object()
|
|
point_cloud_object()
|
|
bpy.ops.object.select_all(action="DESELECT")
|
|
bpy.ops.wm.save_as_mainfile(filepath=str(pathlib.Path(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 --factory-startup --python WBV2-P4-003.py -- OUTPUT")
|
|
main(arguments[0])
|