Expand official geometry node corpus
This commit is contained in:
parent
182b2f17c6
commit
3c4ad988c3
17 changed files with 1883 additions and 6 deletions
150
examples/geometry_script/blender_index_of_nearest.py
Normal file
150
examples/geometry_script/blender_index_of_nearest.py
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
"""Geometry Script footholds from Blender's index_of_nearest demo."""
|
||||
|
||||
try:
|
||||
from tools.geometry_script_loader import load_repo_geometry_script
|
||||
except ModuleNotFoundError:
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
|
||||
from tools.geometry_script_loader import load_repo_geometry_script
|
||||
|
||||
load_repo_geometry_script()
|
||||
|
||||
from geometry_script import * # noqa: F403 - Geometry Script exposes node functions as DSL globals.
|
||||
|
||||
|
||||
@tree("VG Boundary Step")
|
||||
def vg_boundary_step(
|
||||
geometry: Geometry,
|
||||
vector: Vector = (0.0, 0.0, 0.0),
|
||||
b: Float = 0.05000000074505806,
|
||||
):
|
||||
from_center = vector_math(operation=VectorMath.Operation.SUBTRACT, vector=(position(), vector))
|
||||
distance = vector_math(operation=VectorMath.Operation.LENGTH, vector=from_center)
|
||||
outside = compare(
|
||||
operation=Compare.Operation.GREATER_THAN,
|
||||
data_type=Compare.DataType.FLOAT,
|
||||
mode=Compare.Mode.ELEMENT,
|
||||
a=distance,
|
||||
b=b,
|
||||
)
|
||||
clamped_xy = vector_math(
|
||||
operation=VectorMath.Operation.MULTIPLY,
|
||||
vector=(vector_math(operation=VectorMath.Operation.SCALE, vector=vector_math(operation=VectorMath.Operation.NORMALIZE, vector=from_center), scale=b), (1.0, 1.0, 0.0)),
|
||||
)
|
||||
return {"Geometry": set_position(geometry=geometry, selection=outside, position=clamped_xy, offset=(0.0, 0.0, 0.0))}
|
||||
|
||||
|
||||
@tree("VG Update Velocity")
|
||||
def vg_update_velocity(
|
||||
current_velocity: Vector = (0.0, 0.0, 0.0),
|
||||
last_position: Vector = (0.0, 0.0, 0.0),
|
||||
):
|
||||
movement = vector_math(operation=VectorMath.Operation.SUBTRACT, vector=(position(), last_position))
|
||||
damped_movement = vector_math(operation=VectorMath.Operation.SCALE, vector=movement, scale=0.9599999785423279)
|
||||
planar_movement = vector_math(operation=VectorMath.Operation.MULTIPLY, vector=(damped_movement, (1.0, 1.0, 0.0)))
|
||||
fast_enough = compare(
|
||||
operation=Compare.Operation.GREATER_THAN,
|
||||
data_type=Compare.DataType.FLOAT,
|
||||
mode=Compare.Mode.ELEMENT,
|
||||
a=vector_math(operation=VectorMath.Operation.LENGTH, vector=planar_movement),
|
||||
b=0.009999999776482582,
|
||||
)
|
||||
blended = vector_math(
|
||||
operation=VectorMath.Operation.ADD,
|
||||
vector=(
|
||||
vector_math(operation=VectorMath.Operation.SCALE, vector=current_velocity, scale=0.75),
|
||||
vector_math(operation=VectorMath.Operation.SCALE, vector=planar_movement, scale=0.25),
|
||||
),
|
||||
)
|
||||
capped = vector_math(
|
||||
operation=VectorMath.Operation.SCALE,
|
||||
vector=vector_math(operation=VectorMath.Operation.NORMALIZE, vector=damped_movement),
|
||||
scale=0.009999999776482582,
|
||||
)
|
||||
return {"velocity": switch(input_type=Switch.InputType.VECTOR, switch=fast_enough, false=blended, true=capped)}
|
||||
|
||||
|
||||
@tree("VG Collision Step")
|
||||
def vg_collision_step(geometry: Geometry):
|
||||
current_position = position()
|
||||
neighbor = index_of_nearest(position=position())
|
||||
neighbor_position = evaluate_at_index(
|
||||
domain="POINT",
|
||||
data_type="FLOAT_VECTOR",
|
||||
value=position(),
|
||||
index=neighbor.index,
|
||||
)
|
||||
from_neighbor = vector_math(operation=VectorMath.Operation.SUBTRACT, vector=(current_position, neighbor_position))
|
||||
too_close = compare(
|
||||
operation=Compare.Operation.LESS_THAN,
|
||||
data_type=Compare.DataType.FLOAT,
|
||||
mode=Compare.Mode.ELEMENT,
|
||||
a=vector_math(operation=VectorMath.Operation.LENGTH, vector=from_neighbor),
|
||||
b=radius(),
|
||||
)
|
||||
push_strength = math(operation=Math.Operation.MULTIPLY, value=(too_close, 0.02500000037252903))
|
||||
push = vector_math(
|
||||
operation=VectorMath.Operation.MULTIPLY,
|
||||
vector=(vector_math(operation=VectorMath.Operation.SCALE, vector=from_neighbor, scale=push_strength), (1.0, 1.0, 0.0)),
|
||||
)
|
||||
return {"Geometry": set_position(geometry=geometry, offset=push)}
|
||||
|
||||
|
||||
@tree("VG Collider Step")
|
||||
def vg_collider_step(geometry: Geometry, collider: Object = None):
|
||||
collider_info = object_info(transform_space="ORIGINAL", object=collider, as_instance=False)
|
||||
from_collider = vector_math(operation=VectorMath.Operation.SUBTRACT, vector=(position(), collider_info.location))
|
||||
collider_radius = vector_math(operation=VectorMath.Operation.ABSOLUTE, vector=collider_info.scale)
|
||||
inside = compare(
|
||||
operation=Compare.Operation.LESS_THAN,
|
||||
data_type=Compare.DataType.FLOAT,
|
||||
mode=Compare.Mode.ELEMENT,
|
||||
a=vector_math(operation=VectorMath.Operation.LENGTH, vector=from_collider),
|
||||
b=collider_radius,
|
||||
)
|
||||
clamped = vector_math(
|
||||
operation=VectorMath.Operation.ADD,
|
||||
vector=(
|
||||
vector_math(
|
||||
operation=VectorMath.Operation.SCALE,
|
||||
vector=vector_math(operation=VectorMath.Operation.NORMALIZE, vector=from_collider),
|
||||
scale=collider_radius,
|
||||
),
|
||||
collider_info.location,
|
||||
),
|
||||
)
|
||||
planar_clamped = vector_math(operation=VectorMath.Operation.MULTIPLY, vector=(clamped, (1.0, 1.0, 0.0)))
|
||||
return {"Geometry": set_position(geometry=geometry, selection=inside, position=planar_clamped, offset=(0.0, 0.0, 0.0))}
|
||||
|
||||
|
||||
def _finalize_groups():
|
||||
import bpy
|
||||
|
||||
groups = []
|
||||
for name in (
|
||||
"VG Boundary Step",
|
||||
"VG Update Velocity",
|
||||
"VG Collision Step",
|
||||
"VG Collider Step",
|
||||
):
|
||||
group = bpy.data.node_groups.get(name)
|
||||
if group:
|
||||
group.use_fake_user = True
|
||||
groups.append(group)
|
||||
return groups
|
||||
|
||||
|
||||
_finalize_groups()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
for group in _finalize_groups():
|
||||
print(
|
||||
"VG_INDEX_OF_NEAREST_GROUP",
|
||||
group.name,
|
||||
len(group.nodes),
|
||||
len(group.links),
|
||||
sorted(set(node.bl_idname for node in group.nodes)),
|
||||
)
|
||||
164
examples/geometry_script/blender_instance_attributes.py
Normal file
164
examples/geometry_script/blender_instance_attributes.py
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
"""Geometry Script recreation of Blender's instance_attribtues.blend demo graph."""
|
||||
|
||||
try:
|
||||
from tools.geometry_script_loader import load_repo_geometry_script
|
||||
except ModuleNotFoundError:
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
|
||||
from tools.geometry_script_loader import load_repo_geometry_script
|
||||
|
||||
load_repo_geometry_script()
|
||||
|
||||
from geometry_script import * # noqa: F403 - Geometry Script exposes node functions as DSL globals.
|
||||
from geometry_script.api.node_mapper import OutputsList, set_or_create_link
|
||||
from geometry_script.api.state import State
|
||||
from geometry_script.api.types import Type
|
||||
|
||||
|
||||
def _capture_attribute_item(data_type: str, domain: str, geometry, value, name: str):
|
||||
node = State.current_node_tree.nodes.new("GeometryNodeCaptureAttribute")
|
||||
node.capture_items.new(data_type, name)
|
||||
node.active_index = 0
|
||||
node.domain = domain
|
||||
set_or_create_link(geometry, node.inputs[0])
|
||||
set_or_create_link(value, node.inputs[1])
|
||||
return OutputsList({"geometry": Type(node.outputs[0]), name.lower().replace(" ", "_"): Type(node.outputs[1])})
|
||||
|
||||
|
||||
@tree("VG Grass Tuft Generator")
|
||||
def vg_grass_tuft_generator(
|
||||
geometry: Geometry,
|
||||
height: Float = 0.20000000298023224,
|
||||
radius: Float = 0.05000000074505806,
|
||||
density: Float = 1.0,
|
||||
thickness: Float = 0.009999999776482582,
|
||||
curl: Float = 0.5,
|
||||
seed: Int = 0,
|
||||
):
|
||||
del geometry
|
||||
|
||||
base_disc = mesh_circle(fill_type=MeshCircle.FillType.TRIANGLE_FAN, vertices=12, radius=radius)
|
||||
scattered_surface = subdivide_mesh(mesh=base_disc, level=3)
|
||||
radial_distance = vector_math(operation=VectorMath.Operation.LENGTH, vector=position())
|
||||
radial_falloff = map_range(
|
||||
clamp=True,
|
||||
interpolation_type="SMOOTHSTEP",
|
||||
data_type="FLOAT",
|
||||
value=radial_distance,
|
||||
from_min=0.0,
|
||||
from_max=radius,
|
||||
to_min=1.0,
|
||||
to_max=0.38999998569488525,
|
||||
)
|
||||
points = distribute_points_on_faces(
|
||||
distribute_method="POISSON",
|
||||
use_legacy_normal=True,
|
||||
mesh=scattered_surface,
|
||||
distance_min=math(
|
||||
operation=Math.Operation.DIVIDE,
|
||||
value=(math(operation=Math.Operation.MULTIPLY, value=(thickness, 2.0)), density),
|
||||
),
|
||||
density_max=math(operation=Math.Operation.MULTIPLY, value=(density, 5000.0)),
|
||||
density_factor=radial_falloff,
|
||||
seed=seed,
|
||||
)
|
||||
|
||||
blade_spine = mesh_line(
|
||||
mode=MeshLine.Mode.END_POINTS,
|
||||
count_mode=MeshLine.CountMode.TOTAL,
|
||||
count=5,
|
||||
start_location=(0.0, 0.0, 0.0),
|
||||
offset=combine_xyz(x=0.0, y=0.0, z=height),
|
||||
)
|
||||
blade_curve = mesh_to_curve(mode="EDGES", mesh=blade_spine)
|
||||
taper = math(operation=Math.Operation.SUBTRACT, value=(1.0, spline_parameter().factor))
|
||||
tapered_blade = set_curve_radius(curve=blade_curve, radius=taper)
|
||||
|
||||
instances = instance_on_points(
|
||||
points=points.points,
|
||||
instance=tapered_blade,
|
||||
pick_instance=False,
|
||||
rotation=(0.0, 0.0, 0.0),
|
||||
scale=(1.0, 1.0, 1.0),
|
||||
)
|
||||
scaled_instances = scale_instances(
|
||||
instances=instances,
|
||||
scale=radial_falloff,
|
||||
center=(0.0, 0.0, 0.0),
|
||||
local_space=True,
|
||||
)
|
||||
roots = _capture_attribute_item("VECTOR", "INSTANCE", scaled_instances, position(), "Value")
|
||||
realized_blades = realize_instances(
|
||||
realize_to_point_domain=True,
|
||||
geometry=roots.geometry,
|
||||
realize_all=True,
|
||||
depth=0,
|
||||
)
|
||||
|
||||
root_position = roots.value
|
||||
tangent_axis = vector_rotate(
|
||||
rotation_type="Z_AXIS",
|
||||
invert=False,
|
||||
vector=vector_math(operation=VectorMath.Operation.NORMALIZE, vector=root_position),
|
||||
center=(0.0, 0.0, 0.0),
|
||||
angle=1.5707963705062866,
|
||||
)
|
||||
root_distance = vector_math(operation=VectorMath.Operation.LENGTH, vector=root_position)
|
||||
curl_falloff = map_range(
|
||||
clamp=True,
|
||||
interpolation_type="SMOOTHSTEP",
|
||||
data_type="FLOAT",
|
||||
value=root_distance,
|
||||
from_min=0.0,
|
||||
from_max=radius,
|
||||
to_min=0.20000000298023224,
|
||||
to_max=2.0,
|
||||
)
|
||||
curl_angle = math(
|
||||
operation=Math.Operation.MULTIPLY,
|
||||
value=(math(operation=Math.Operation.MULTIPLY, value=(spline_parameter().factor, curl)), curl_falloff),
|
||||
)
|
||||
curled_position = vector_rotate(
|
||||
rotation_type="AXIS_ANGLE",
|
||||
invert=False,
|
||||
vector=position(),
|
||||
center=root_position,
|
||||
axis=tangent_axis,
|
||||
angle=curl_angle,
|
||||
)
|
||||
curled_blades = set_position(geometry=realized_blades, position=curled_position, offset=(0.0, 0.0, 0.0))
|
||||
|
||||
profile = curve_circle(mode=CurveCircle.Mode.RADIUS, resolution=3, radius=thickness)
|
||||
radius_attribute = named_attribute(data_type=NamedAttribute.DataType.FLOAT, name="radius")
|
||||
radius_scale = switch(input_type=Switch.InputType.FLOAT, switch=radius_attribute.exists, false=1.0, true=radius_attribute.attribute)
|
||||
mesh = curve_to_mesh(curve=curled_blades, profile_curve=profile, scale=radius_scale, fill_caps=False)
|
||||
smooth_mesh = set_shade_smooth(domain=SetShadeSmooth.Domain.FACE, mesh=mesh, shade_smooth=False)
|
||||
return {"Geometry": set_material(geometry=smooth_mesh, material=None)}
|
||||
|
||||
|
||||
def _finalize_groups():
|
||||
import bpy
|
||||
|
||||
groups = []
|
||||
for name in ("VG Grass Tuft Generator",):
|
||||
group = bpy.data.node_groups.get(name)
|
||||
if group:
|
||||
group.use_fake_user = True
|
||||
groups.append(group)
|
||||
return groups
|
||||
|
||||
|
||||
_finalize_groups()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
for group in _finalize_groups():
|
||||
print(
|
||||
"VG_INSTANCE_ATTRIBUTES_GROUP",
|
||||
group.name,
|
||||
len(group.nodes),
|
||||
len(group.links),
|
||||
sorted(set(node.bl_idname for node in group.nodes)),
|
||||
)
|
||||
191
examples/geometry_script/blender_labyrinth_shortest_path.py
Normal file
191
examples/geometry_script/blender_labyrinth_shortest_path.py
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
"""Geometry Script recreation of Blender's shortest-path labyrinth demo."""
|
||||
|
||||
try:
|
||||
from tools.geometry_script_loader import load_repo_geometry_script
|
||||
except ModuleNotFoundError:
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
|
||||
from tools.geometry_script_loader import load_repo_geometry_script
|
||||
|
||||
load_repo_geometry_script()
|
||||
|
||||
from geometry_script import * # noqa: F403 - Geometry Script exposes node functions as DSL globals.
|
||||
from geometry_script.api.node_mapper import OutputsList, set_or_create_link
|
||||
from geometry_script.api.state import State
|
||||
from geometry_script.api.types import Type
|
||||
|
||||
|
||||
def _capture_attribute_item(data_type: str, domain: str, geometry, value, name: str):
|
||||
node = State.current_node_tree.nodes.new("GeometryNodeCaptureAttribute")
|
||||
node.capture_items.new(data_type, name)
|
||||
node.active_index = 0
|
||||
node.domain = domain
|
||||
set_or_create_link(geometry, node.inputs[0])
|
||||
set_or_create_link(value, node.inputs[1])
|
||||
return OutputsList({"geometry": Type(node.outputs[0]), name.lower().replace(" ", "_").replace("/", "_"): Type(node.outputs[1])})
|
||||
|
||||
|
||||
@tree("VG Solvable Labyrinth Generator")
|
||||
def vg_solvable_labyrinth_generator(
|
||||
geometry: Geometry,
|
||||
size: Int = 20,
|
||||
seed: Int = 247,
|
||||
solve: Float = 1.0,
|
||||
):
|
||||
del geometry
|
||||
|
||||
base = grid(size_x=1.0, size_y=1.0, vertices_x=size, vertices_y=size)
|
||||
base_with_uv = store_named_attribute(
|
||||
data_type=StoreNamedAttribute.DataType.FLOAT_VECTOR,
|
||||
domain=StoreNamedAttribute.Domain.CORNER,
|
||||
geometry=base.mesh,
|
||||
name="uv_map",
|
||||
value=base.uv_map,
|
||||
)
|
||||
|
||||
start_vertex = compare(
|
||||
operation=Compare.Operation.EQUAL,
|
||||
data_type=Compare.DataType.INT,
|
||||
mode=Compare.Mode.ELEMENT,
|
||||
a=index(),
|
||||
b=0,
|
||||
)
|
||||
sparse_edges = compare(
|
||||
operation=Compare.Operation.LESS_THAN,
|
||||
data_type=Compare.DataType.INT,
|
||||
mode=Compare.Mode.ELEMENT,
|
||||
a=edge_neighbors(),
|
||||
b=2,
|
||||
)
|
||||
random_cost = random_value(data_type=RandomValue.DataType.BOOLEAN, probability=0.5, seed=seed)
|
||||
edge_cost = switch(input_type=Switch.InputType.FLOAT, switch=sparse_edges, false=random_cost, true=0.0)
|
||||
random_paths = shortest_edge_paths(end_vertex=start_vertex, edge_cost=edge_cost)
|
||||
random_path_selection = edge_paths_to_selection(next_vertex_index=random_paths.next_vertex_index)
|
||||
captured_maze_edges = _capture_attribute_item("BOOLEAN", "EDGE", base_with_uv, random_path_selection, "Path")
|
||||
|
||||
subdivided = subdivide_mesh(mesh=captured_maze_edges.geometry, level=1)
|
||||
carved_walkable = delete_geometry(
|
||||
mode=DeleteGeometry.Mode.ALL,
|
||||
domain=DeleteGeometry.Domain.POINT,
|
||||
geometry=subdivided,
|
||||
selection=captured_maze_edges.path,
|
||||
)
|
||||
|
||||
parts = separate_xyz(vector=position())
|
||||
direct_paths = shortest_edge_paths(end_vertex=start_vertex)
|
||||
direct_selection = edge_paths_to_selection(next_vertex_index=direct_paths.next_vertex_index)
|
||||
x_stats_on_path = attribute_statistic(
|
||||
data_type=AttributeStatistic.DataType.FLOAT,
|
||||
domain=AttributeStatistic.Domain.POINT,
|
||||
geometry=carved_walkable,
|
||||
selection=direct_selection,
|
||||
attribute=parts.x,
|
||||
)
|
||||
far_x_vertices = compare(
|
||||
operation=Compare.Operation.EQUAL,
|
||||
data_type=Compare.DataType.FLOAT,
|
||||
mode=Compare.Mode.ELEMENT,
|
||||
a=parts.x,
|
||||
b=x_stats_on_path.max,
|
||||
epsilon=0.0010000000474974513,
|
||||
)
|
||||
solution_curves = edge_paths_to_curves(
|
||||
mesh=carved_walkable,
|
||||
start_vertices=far_x_vertices,
|
||||
next_vertex_index=direct_paths.next_vertex_index,
|
||||
)
|
||||
|
||||
marker_radius = math(operation=Math.Operation.DIVIDE, value=(0.10000000149011612, size))
|
||||
marker_mesh = ico_sphere(radius=marker_radius, subdivisions=3)
|
||||
marker_with_uv = store_named_attribute(
|
||||
data_type=StoreNamedAttribute.DataType.FLOAT_VECTOR,
|
||||
domain=StoreNamedAttribute.Domain.CORNER,
|
||||
geometry=marker_mesh.mesh,
|
||||
name="UVMap",
|
||||
value=marker_mesh.uv_map,
|
||||
)
|
||||
endpoint_markers = instance_on_points(
|
||||
points=solution_curves,
|
||||
selection=endpoint_selection(start_size=1, end_size=1),
|
||||
instance=marker_with_uv,
|
||||
pick_instance=False,
|
||||
rotation=(0.0, 0.0, 0.0),
|
||||
scale=3.0,
|
||||
)
|
||||
marker_indices = _capture_attribute_item("INT", "INSTANCE", endpoint_markers, index(), "Start End")
|
||||
realized_markers = realize_instances(
|
||||
realize_to_point_domain=True,
|
||||
geometry=marker_indices.geometry,
|
||||
realize_all=True,
|
||||
depth=0,
|
||||
)
|
||||
marker_geometry = set_material(geometry=realized_markers, material=None)
|
||||
|
||||
trimmed_solution = trim_curve(mode=TrimCurve.Mode.FACTOR, curve=solution_curves, start=0.0, end=solve)
|
||||
captured_solution = _capture_attribute_item("BOOLEAN", "CURVE", trimmed_solution, True, "Path")
|
||||
maze_walls_source = delete_geometry(
|
||||
mode=DeleteGeometry.Mode.ALL,
|
||||
domain=DeleteGeometry.Domain.POINT,
|
||||
geometry=subdivided,
|
||||
selection=boolean_math(operation=BooleanMath.Operation.NOT, boolean=captured_maze_edges.path),
|
||||
)
|
||||
wall_curves = mesh_to_curve(mode="EDGES", mesh=maze_walls_source)
|
||||
all_curves = join_geometry(geometry=[captured_solution.geometry, wall_curves])
|
||||
filleted = fillet_curve(curve=all_curves, radius=0.004999999888241291, limit_radius=True, mode="Poly", count=6)
|
||||
curve_radius = switch(input_type=Switch.InputType.FLOAT, switch=captured_solution.path, false=2.0, true=1.0)
|
||||
radius_curves = set_curve_radius(curve=filleted, radius=curve_radius)
|
||||
|
||||
smoothed_marker = set_shade_smooth(domain=SetShadeSmooth.Domain.FACE, mesh=marker_with_uv, shade_smooth=True)
|
||||
curve_endpoint_markers = instance_on_points(
|
||||
points=radius_curves,
|
||||
selection=endpoint_selection(start_size=1, end_size=1),
|
||||
instance=smoothed_marker,
|
||||
pick_instance=False,
|
||||
rotation=(0.0, 0.0, 0.0),
|
||||
scale=radius(),
|
||||
)
|
||||
realized_curve_markers = realize_instances(
|
||||
realize_to_point_domain=True,
|
||||
geometry=curve_endpoint_markers,
|
||||
realize_all=True,
|
||||
depth=0,
|
||||
)
|
||||
profile = curve_circle(mode=CurveCircle.Mode.RADIUS, resolution=16, radius=marker_radius)
|
||||
radius_attribute = named_attribute(data_type=NamedAttribute.DataType.FLOAT, name="radius")
|
||||
profile_scale = switch(input_type=Switch.InputType.FLOAT, switch=radius_attribute.exists, false=1.0, true=radius_attribute.attribute)
|
||||
path_mesh = curve_to_mesh(curve=radius_curves, profile_curve=profile, scale=profile_scale, fill_caps=False)
|
||||
curve_geometry = set_material(geometry=join_geometry(geometry=[realized_curve_markers, path_mesh]), material=None)
|
||||
base_geometry = set_material(geometry=base_with_uv, material=None)
|
||||
return {
|
||||
"Geometry": join_geometry(geometry=[marker_geometry, curve_geometry, base_geometry]),
|
||||
"Path": captured_solution.path,
|
||||
"Start/End": marker_indices.start_end,
|
||||
}
|
||||
|
||||
|
||||
def _finalize_groups():
|
||||
import bpy
|
||||
|
||||
groups = []
|
||||
for name in ("VG Solvable Labyrinth Generator",):
|
||||
group = bpy.data.node_groups.get(name)
|
||||
if group:
|
||||
group.use_fake_user = True
|
||||
groups.append(group)
|
||||
return groups
|
||||
|
||||
|
||||
_finalize_groups()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
for group in _finalize_groups():
|
||||
print(
|
||||
"VG_LABYRINTH_GROUP",
|
||||
group.name,
|
||||
len(group.nodes),
|
||||
len(group.links),
|
||||
sorted(set(node.bl_idname for node in group.nodes)),
|
||||
)
|
||||
115
examples/geometry_script/blender_raycast_minigame.py
Normal file
115
examples/geometry_script/blender_raycast_minigame.py
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
"""Geometry Script footholds from Blender's raycast minigame demo."""
|
||||
|
||||
try:
|
||||
from tools.geometry_script_loader import load_repo_geometry_script
|
||||
except ModuleNotFoundError:
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
|
||||
from tools.geometry_script_loader import load_repo_geometry_script
|
||||
|
||||
load_repo_geometry_script()
|
||||
|
||||
from geometry_script import * # noqa: F403 - Geometry Script exposes node functions as DSL globals.
|
||||
|
||||
|
||||
@tree("VG Initial Direction")
|
||||
def vg_initial_direction(rotation: Vector = (0.0, 0.0, 0.0)):
|
||||
forward = combine_xyz(x=1.0, y=0.0, z=0.0)
|
||||
return {
|
||||
"Vector": vector_rotate(
|
||||
rotation_type="EULER_XYZ",
|
||||
invert=False,
|
||||
vector=forward,
|
||||
center=(0.0, 0.0, 0.0),
|
||||
rotation=rotation,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@tree("VG Line To Be Casted")
|
||||
def vg_line_to_be_casted(
|
||||
start_pos: Vector = (0.0, 0.0, 0.0),
|
||||
line_size: Int = 3,
|
||||
):
|
||||
seed_line = curve_line(mode=CurveLine.Mode.POINTS, start=(0.0, 0.0, 0.0), end=(0.0, 0.0, 0.0))
|
||||
placed = set_position(geometry=seed_line, position=start_pos, offset=(0.0, 0.0, 0.0))
|
||||
return {
|
||||
"Line": resample_curve(
|
||||
keep_last_segment=False,
|
||||
curve=placed,
|
||||
mode="Count",
|
||||
count=line_size,
|
||||
length=0.10000000149011612,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@tree("VG Cast Rays")
|
||||
def vg_cast_rays(
|
||||
line: Geometry,
|
||||
ray_direction: Vector = (0.0, 0.0, 0.0),
|
||||
traveled_distance: Float = 0.0,
|
||||
hit_index: Int = 1,
|
||||
target: Object = None,
|
||||
):
|
||||
active_point = compare(
|
||||
operation=Compare.Operation.EQUAL,
|
||||
data_type=Compare.DataType.INT,
|
||||
mode=Compare.Mode.ELEMENT,
|
||||
a=index(),
|
||||
b=hit_index,
|
||||
)
|
||||
target_info = object_info(transform_space="RELATIVE", object=target, as_instance=False)
|
||||
previous_index = math(operation=Math.Operation.SUBTRACT, value=(hit_index, integer(integer=1)))
|
||||
previous_position = sample_index(
|
||||
data_type=SampleIndex.DataType.FLOAT_VECTOR,
|
||||
domain=SampleIndex.Domain.POINT,
|
||||
clamp=True,
|
||||
geometry=line,
|
||||
value=position(),
|
||||
index=previous_index,
|
||||
)
|
||||
hit = raycast(
|
||||
data_type="FLOAT_VECTOR",
|
||||
target_geometry=target_info.geometry,
|
||||
interpolation="Nearest",
|
||||
source_position=previous_position,
|
||||
ray_direction=ray_direction,
|
||||
ray_length=20.0,
|
||||
)
|
||||
hit_position = vector_math(operation=VectorMath.Operation.SCALE, vector=hit.hit_position, scale=0.9990000128746033)
|
||||
updated_line = set_position(geometry=line, selection=active_point, position=hit_position, offset=(0.0, 0.0, 0.0))
|
||||
return {
|
||||
"Line": updated_line,
|
||||
"Reflected Direction": vector_math(operation=VectorMath.Operation.REFLECT, vector=(ray_direction, hit.hit_normal)),
|
||||
"Traveled Distance": math(operation=Math.Operation.ADD, value=(hit.hit_distance, traveled_distance)),
|
||||
"Next Hit Index": math(operation=Math.Operation.ADD, value=(hit_index, integer(integer=1))),
|
||||
}
|
||||
|
||||
|
||||
def _finalize_groups():
|
||||
import bpy
|
||||
|
||||
groups = []
|
||||
for name in ("VG Initial Direction", "VG Line To Be Casted", "VG Cast Rays"):
|
||||
group = bpy.data.node_groups.get(name)
|
||||
if group:
|
||||
group.use_fake_user = True
|
||||
groups.append(group)
|
||||
return groups
|
||||
|
||||
|
||||
_finalize_groups()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
for group in _finalize_groups():
|
||||
print(
|
||||
"VG_RAYCAST_GROUP",
|
||||
group.name,
|
||||
len(group.nodes),
|
||||
len(group.links),
|
||||
sorted(set(node.bl_idname for node in group.nodes)),
|
||||
)
|
||||
Loading…
Reference in a new issue