90 lines
3.4 KiB
Python
90 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
import pathlib
|
|
import sys
|
|
|
|
import bpy
|
|
|
|
|
|
def geometry_group(name, blocked=False):
|
|
group = bpy.data.node_groups.new(name, "GeometryNodeTree")
|
|
group.interface.new_socket(name="Geometry", in_out="INPUT", socket_type="NodeSocketGeometry")
|
|
group.interface.new_socket(name="Geometry", in_out="OUTPUT", socket_type="NodeSocketGeometry")
|
|
group_input = group.nodes.new("NodeGroupInput")
|
|
group_input.name = "WBV2P4002 Group Input"
|
|
group_output = group.nodes.new("NodeGroupOutput")
|
|
group_output.name = "WBV2P4002 Group Output"
|
|
if blocked:
|
|
unsupported = group.nodes.new("GeometryNodeDistributePointsOnFaces")
|
|
unsupported.name = "WBV2P4002 Unsupported Distribute"
|
|
unsupported.distribute_method = "RANDOM"
|
|
group.links.new(group_input.outputs["Geometry"], unsupported.inputs["Mesh"])
|
|
group.links.new(unsupported.outputs["Points"], group_output.inputs["Geometry"])
|
|
else:
|
|
transform = group.nodes.new("GeometryNodeTransform")
|
|
transform.name = "WBV2P4002 Transform"
|
|
transform.inputs["Translation"].default_value = (0.25, -0.5, 0.75)
|
|
group.links.new(group_input.outputs["Geometry"], transform.inputs["Geometry"])
|
|
group.links.new(transform.outputs["Geometry"], group_output.inputs["Geometry"])
|
|
return group
|
|
|
|
|
|
def mesh_object(name, group):
|
|
mesh = bpy.data.meshes.new(f"{name}Mesh")
|
|
mesh.from_pydata(
|
|
[(-1, -1, 0), (1, -1, 0), (1, 1, 0), (-1, 1, 0)],
|
|
[],
|
|
[(0, 1, 2, 3)],
|
|
)
|
|
mesh.update()
|
|
obj = bpy.data.objects.new(name, mesh)
|
|
bpy.context.scene.collection.objects.link(obj)
|
|
modifier = obj.modifiers.new("WBV2P4002 Geometry Nodes", "NODES")
|
|
modifier.node_group = group
|
|
return obj
|
|
|
|
|
|
def material():
|
|
value = bpy.data.materials.new("WBV2P4002ShaderMaterial")
|
|
value.use_nodes = True
|
|
tree = value.node_tree
|
|
nodes = tree.nodes
|
|
links = tree.links
|
|
principled = nodes.get("Principled BSDF")
|
|
output = nodes.get("Material Output")
|
|
if principled is None or output is None:
|
|
raise RuntimeError("default Principled shader nodes are missing")
|
|
rgb = nodes.new("ShaderNodeRGB")
|
|
rgb.name = "WBV2P4002 RGB"
|
|
rgb.outputs["Color"].default_value = (0.12, 0.34, 0.56, 1.0)
|
|
links.new(rgb.outputs["Color"], principled.inputs["Base Color"])
|
|
links.new(principled.outputs["BSDF"], output.inputs["Surface"])
|
|
return value
|
|
|
|
|
|
def main(output):
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
scene = bpy.context.scene
|
|
scene.name = "WBV2P4002NodesScene"
|
|
scene.frame_start = 1
|
|
scene.frame_end = 12
|
|
scene.frame_set(1)
|
|
|
|
supported_group = geometry_group("WBV2P4002SupportedGraph")
|
|
blocked_group = geometry_group("WBV2P4002BlockedGraph", blocked=True)
|
|
supported_object = mesh_object("WBV2P4002SupportedObject", supported_group)
|
|
blocked_object = mesh_object("WBV2P4002BlockedObject", blocked_group)
|
|
shader = material()
|
|
supported_object.data.materials.append(shader)
|
|
|
|
bpy.context.view_layer.objects.active = supported_object
|
|
supported_object.select_set(True)
|
|
blocked_object.select_set(False)
|
|
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-002.py -- OUTPUT")
|
|
main(arguments[0])
|