Created
June 7, 2022 09:44
-
-
Save Gorgious56/5a94d900e3d8688ddd0780c3d9463b6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
from math import pi | |
from random import random | |
from mathutils import Vector | |
bpy.ops.mesh.primitive_monkey_add() | |
instance_obj = bpy.context.active_object | |
bpy.ops.mesh.primitive_cube_add() | |
instancer_obj = bpy.context.active_object | |
instancer_mesh = instancer_obj.data | |
instancer_mesh.clear_geometry() | |
verts_amount = 10000 | |
verts = [Vector((random(), random(), random())) * 50 for v in range(verts_amount)] | |
instancer_mesh.from_pydata(verts, [], []) | |
attributes = instancer_mesh.attributes | |
rotation = attributes.new(name="rotation", type="FLOAT_VECTOR", domain="POINT") | |
random_rots = [2 * pi * random() for v in range(verts_amount * 3)] | |
rotation.data.foreach_set("vector", random_rots) | |
scale = attributes.new(name="scale", type="FLOAT", domain="POINT") | |
random_scales = [(random() + 0.25) for v in range(verts_amount)] | |
scale.data.foreach_set("value", random_scales) | |
mod = instancer_obj.modifiers.new(type="NODES", name="") | |
bpy.ops.node.new_geometry_node_group_assign() | |
node_tree = mod.node_group | |
nodes = node_tree.nodes | |
instance_on_points = nodes.new(type="GeometryNodeInstanceOnPoints") | |
object_info = nodes.new(type="GeometryNodeObjectInfo") | |
object_info.inputs[0].default_value = instance_obj | |
object_info.location[0] -= 200 | |
input = next(n for n in nodes if n.name == "Group Input") | |
output = next(n for n in nodes if n.name == "Group Output") | |
links = node_tree.links | |
links.new(input.outputs["Geometry"], instance_on_points.inputs["Points"]) | |
links.new(input.outputs[-1], instance_on_points.inputs["Rotation"]) | |
links.new(input.outputs[-1], instance_on_points.inputs["Scale"]) | |
links.new(object_info.outputs["Geometry"], instance_on_points.inputs["Instance"]) | |
links.new(instance_on_points.outputs["Instances"], output.inputs["Geometry"]) | |
mod["Input_2_use_attribute"] = True | |
mod["Input_2_attribute_name"] = "rotation" | |
mod["Input_3_use_attribute"] = True | |
mod["Input_3_attribute_name"] = "scale" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment