Finish local geometry node sample corpus
This commit is contained in:
parent
9bc09bb7c2
commit
182b2f17c6
14 changed files with 1387 additions and 41 deletions
|
|
@ -12,6 +12,19 @@ except ModuleNotFoundError:
|
|||
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 Auto Smooth")
|
||||
|
|
@ -42,14 +55,328 @@ def vg_auto_smooth(geometry: Geometry, angle: Float = 0.0):
|
|||
return {"Geometry": face_pass}
|
||||
|
||||
|
||||
@tree("VG Curve To Mesh UV")
|
||||
def vg_curve_to_mesh_uv(
|
||||
curve: Geometry,
|
||||
profile_curve: Geometry,
|
||||
fill_caps: Bool = False,
|
||||
lock_caps_uv_scaling: Bool = False,
|
||||
hole_tolerant: Bool = False,
|
||||
smooth_angle: Float = 3.1415927410125732,
|
||||
free_u_space: Bool = False,
|
||||
lock_u_scaling: Bool = False,
|
||||
free_v_space: Bool = False,
|
||||
lock_v_scaling: Bool = False,
|
||||
sides_uv_scale: Vector = (1.0, 1.0, 0.0),
|
||||
sides_uv_offset: Vector = (0.0, 0.0, 0.0),
|
||||
sides_uv_z_rotation: Float = 0.0,
|
||||
caps_uv_scale: Vector = (1.0, 1.0, 0.0),
|
||||
caps_uv_offset: Vector = (0.0, 0.0, 0.0),
|
||||
caps_uv_z_rotation: Float = 0.0,
|
||||
store_attributes: Bool = False,
|
||||
):
|
||||
del lock_caps_uv_scaling
|
||||
del hole_tolerant
|
||||
del smooth_angle
|
||||
del free_u_space
|
||||
del lock_u_scaling
|
||||
del free_v_space
|
||||
del lock_v_scaling
|
||||
del sides_uv_scale
|
||||
del sides_uv_offset
|
||||
del sides_uv_z_rotation
|
||||
del caps_uv_scale
|
||||
del caps_uv_offset
|
||||
del caps_uv_z_rotation
|
||||
del store_attributes
|
||||
|
||||
resampled_curve = resample_curve(
|
||||
curve=curve,
|
||||
mode="Evaluated",
|
||||
keep_last_segment=False,
|
||||
)
|
||||
cyclic_start = boolean_math(
|
||||
operation=BooleanMath.Operation.AND,
|
||||
boolean=(endpoint_selection(start_size=1, end_size=0), is_spline_cyclic()),
|
||||
)
|
||||
curve_parameter = spline_parameter()
|
||||
curve_length = spline_length()
|
||||
curve_point_index = switch(
|
||||
input_type=Switch.InputType.INT,
|
||||
switch=cyclic_start,
|
||||
false=curve_parameter.index,
|
||||
true=curve_length.point_count,
|
||||
)
|
||||
curve_point_triplet = combine_xyz(x=curve_point_index, y=curve_parameter.index, z=curve_length.point_count)
|
||||
curve_points = _capture_attribute_item("VECTOR", "POINT", resampled_curve, curve_point_triplet, "curve point triplet")
|
||||
curve_indices = _capture_attribute_item("INT", "CURVE", curve_points.geometry, index(), "curve index")
|
||||
|
||||
resampled_profile = resample_curve(
|
||||
curve=profile_curve,
|
||||
mode="Evaluated",
|
||||
keep_last_segment=False,
|
||||
)
|
||||
profile_points = _capture_attribute_item("VECTOR", "POINT", resampled_profile, curve_point_triplet, "profile point triplet")
|
||||
profile_curve_indices = _capture_attribute_item("INT", "CURVE", profile_points.geometry, index(), "profile curve index")
|
||||
profile_point_indices = _capture_attribute_item("INT", "POINT", profile_curve_indices.geometry, index(), "profile point index")
|
||||
|
||||
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=curve_indices.geometry,
|
||||
profile_curve=profile_point_indices.geometry,
|
||||
scale=radius_scale,
|
||||
fill_caps=fill_caps,
|
||||
)
|
||||
|
||||
profile_curve_count = domain_size(component="CURVE", geometry=profile_curve_indices.geometry)
|
||||
corner_group = math(
|
||||
operation=Math.Operation.ADD,
|
||||
value=(
|
||||
math(operation=Math.Operation.MULTIPLY, value=(curve_indices.curve_index, profile_curve_count.spline_count)),
|
||||
profile_curve_indices.profile_curve_index,
|
||||
),
|
||||
)
|
||||
corner_counter = accumulate_field(
|
||||
data_type=AccumulateField.DataType.INT,
|
||||
domain=AccumulateField.Domain.CORNER,
|
||||
value=1,
|
||||
group_id=corner_group,
|
||||
).trailing
|
||||
|
||||
curve_cyclic = sample_index(
|
||||
data_type=SampleIndex.DataType.BOOLEAN,
|
||||
domain=SampleIndex.Domain.CURVE,
|
||||
clamp=True,
|
||||
geometry=curve_indices.geometry,
|
||||
value=is_spline_cyclic(),
|
||||
index=curve_indices.curve_index,
|
||||
)
|
||||
source_curve_length = spline_length()
|
||||
source_curve_point_count = switch(
|
||||
input_type=Switch.InputType.INT,
|
||||
switch=curve_cyclic,
|
||||
false=math(operation=Math.Operation.SUBTRACT, value=(source_curve_length.point_count, 1.0)),
|
||||
true=source_curve_length.point_count,
|
||||
)
|
||||
source_curve_points = sample_index(
|
||||
data_type=SampleIndex.DataType.INT,
|
||||
domain=SampleIndex.Domain.CURVE,
|
||||
clamp=True,
|
||||
geometry=curve_indices.geometry,
|
||||
value=source_curve_point_count,
|
||||
index=curve_indices.curve_index,
|
||||
)
|
||||
|
||||
profile_cyclic = sample_index(
|
||||
data_type=SampleIndex.DataType.BOOLEAN,
|
||||
domain=SampleIndex.Domain.CURVE,
|
||||
clamp=True,
|
||||
geometry=profile_curve_indices.geometry,
|
||||
value=is_spline_cyclic(),
|
||||
index=profile_curve_indices.profile_curve_index,
|
||||
)
|
||||
source_profile_length = spline_length()
|
||||
source_profile_point_count = switch(
|
||||
input_type=Switch.InputType.INT,
|
||||
switch=profile_cyclic,
|
||||
false=math(operation=Math.Operation.SUBTRACT, value=(source_profile_length.point_count, 1.0)),
|
||||
true=source_profile_length.point_count,
|
||||
)
|
||||
source_profile_points = sample_index(
|
||||
data_type=SampleIndex.DataType.INT,
|
||||
domain=SampleIndex.Domain.CURVE,
|
||||
clamp=True,
|
||||
geometry=profile_curve_indices.geometry,
|
||||
value=source_profile_point_count,
|
||||
index=profile_curve_indices.profile_curve_index,
|
||||
)
|
||||
cap_start = math(
|
||||
operation=Math.Operation.MULTIPLY,
|
||||
value=(source_curve_points, math(operation=Math.Operation.MULTIPLY, value=(source_profile_points, 4.0))),
|
||||
)
|
||||
caps_mask = compare(
|
||||
operation=Compare.Operation.GREATER_EQUAL,
|
||||
data_type=Compare.DataType.FLOAT,
|
||||
mode=Compare.Mode.ELEMENT,
|
||||
a=corner_counter,
|
||||
b=cap_start,
|
||||
)
|
||||
|
||||
corner_mod = math(operation=Math.Operation.MODULO, value=(index(), 4.0))
|
||||
use_curve_y = compare(
|
||||
operation=Compare.Operation.LESS_EQUAL,
|
||||
data_type=Compare.DataType.INT,
|
||||
mode=Compare.Mode.ELEMENT,
|
||||
a=corner_mod,
|
||||
b=1,
|
||||
)
|
||||
curve_triplet = separate_xyz(vector=curve_points.curve_point_triplet)
|
||||
side_u = switch(input_type=Switch.InputType.FLOAT, switch=use_curve_y, false=curve_triplet.x, true=curve_triplet.y)
|
||||
|
||||
profile_mod = math(operation=Math.Operation.MODULO, value=(index(), 4.0))
|
||||
use_profile_y = compare(
|
||||
operation=Compare.Operation.NOT_EQUAL,
|
||||
data_type=Compare.DataType.FLOAT,
|
||||
mode=Compare.Mode.ELEMENT,
|
||||
a=profile_mod,
|
||||
b=1.5,
|
||||
epsilon=0.5,
|
||||
)
|
||||
profile_triplet = separate_xyz(vector=profile_points.profile_point_triplet)
|
||||
side_v = switch(input_type=Switch.InputType.FLOAT, switch=use_profile_y, false=profile_triplet.x, true=profile_triplet.y)
|
||||
side_uv = combine_xyz(x=side_u, y=side_v, z=0.0)
|
||||
|
||||
source_position = sample_index(
|
||||
data_type=SampleIndex.DataType.FLOAT_VECTOR,
|
||||
domain=SampleIndex.Domain.POINT,
|
||||
clamp=False,
|
||||
geometry=profile_point_indices.geometry,
|
||||
value=position(),
|
||||
index=profile_point_indices.profile_point_index,
|
||||
)
|
||||
profile_bounds = bounding_box(geometry=profile_point_indices.geometry, use_radius=True)
|
||||
cap_uv = map_range(
|
||||
clamp=False,
|
||||
interpolation_type="LINEAR",
|
||||
data_type="FLOAT_VECTOR",
|
||||
vector=source_position,
|
||||
from_min=profile_bounds.min,
|
||||
from_max=profile_bounds.max,
|
||||
to_min=(0.0, 0.0, 0.0),
|
||||
to_max=(1.0, 1.0, 1.0),
|
||||
)
|
||||
uv_map = switch(input_type=Switch.InputType.VECTOR, switch=caps_mask, false=side_uv, true=switch(input_type=Switch.InputType.VECTOR, switch=fill_caps, false=(0.0, 0.0, 0.0), true=cap_uv))
|
||||
return {"Mesh": mesh, "UV Map": uv_map, "Caps Mask": caps_mask}
|
||||
|
||||
|
||||
@tree("VG Curve To Mesh UV Demo")
|
||||
def vg_curve_to_mesh_uv_demo():
|
||||
curve = transform_geometry(
|
||||
geometry=curve_circle(mode=CurveCircle.Mode.RADIUS, resolution=32, radius=1.899999976158142),
|
||||
translation=(0.0, 0.0, 0.0),
|
||||
)
|
||||
profile = curve_circle(mode=CurveCircle.Mode.RADIUS, resolution=16, radius=0.6269999742507935)
|
||||
mesh, uv_map, caps_mask = vg_curve_to_mesh_uv(
|
||||
curve=curve,
|
||||
profile_curve=profile,
|
||||
fill_caps=False,
|
||||
lock_caps_uv_scaling=True,
|
||||
hole_tolerant=True,
|
||||
smooth_angle=3.1415927410125732,
|
||||
free_u_space=True,
|
||||
lock_u_scaling=True,
|
||||
free_v_space=True,
|
||||
lock_v_scaling=True,
|
||||
sides_uv_scale=(1.0, 1.0, 0.0),
|
||||
sides_uv_offset=(0.0, 0.0, 0.0),
|
||||
sides_uv_z_rotation=0.0,
|
||||
caps_uv_scale=(1.0, 1.0, 0.0),
|
||||
caps_uv_offset=(0.0, 0.0, 0.0),
|
||||
caps_uv_z_rotation=0.0,
|
||||
store_attributes=True,
|
||||
)
|
||||
transformed = transform_geometry(
|
||||
geometry=mesh,
|
||||
translation=(2.4099998474121094, 0.0, 3.3399999141693115),
|
||||
rotation=(0.9615018963813782, 0.0, -0.5942845940589905),
|
||||
).set_material(material=None)
|
||||
return {"Geometry": transformed, "UV Map": uv_map, "Caps Mask": caps_mask}
|
||||
|
||||
|
||||
@tree("VG Curve To Mesh UV Title")
|
||||
def vg_curve_to_mesh_uv_title():
|
||||
title = string_to_curves(
|
||||
string=string(string="Curve to Mesh UV"),
|
||||
size=0.6000000238418579,
|
||||
align_x="Center",
|
||||
align_y="Top",
|
||||
pivot_point="Midpoint",
|
||||
).curve_instances
|
||||
subtitle_text = join_strings(
|
||||
delimiter=special_characters().line_break,
|
||||
strings=[
|
||||
string(string="v1.7.02.230210"),
|
||||
string(string="for Blender 3.4+"),
|
||||
string(string="[ Free|Github Edition]"),
|
||||
],
|
||||
)
|
||||
subtitle = transform_geometry(
|
||||
geometry=string_to_curves(
|
||||
string=subtitle_text,
|
||||
size=0.4000000059604645,
|
||||
align_x="Center",
|
||||
align_y="Top",
|
||||
pivot_point="Bottom Left",
|
||||
).curve_instances,
|
||||
translation=(0.0, -0.699999988079071, 0.0),
|
||||
)
|
||||
text = transform_geometry(
|
||||
geometry=join_geometry(geometry=[title, subtitle]),
|
||||
translation=(0.0, 0.0, -1.6699999570846558),
|
||||
rotation=(1.5707963705062866, 0.0, 0.0),
|
||||
)
|
||||
text_face = fill_curve(curve=text, mode="N-gons", fill_rule="Even-Odd").set_material(material=None)
|
||||
|
||||
plinth = cube(size=(4.400000095367432, 0.20000000298023224, 10.0), vertices_x=2, vertices_y=2, vertices_z=2)
|
||||
plinth_uv = store_named_attribute(
|
||||
data_type=StoreNamedAttribute.DataType.FLOAT_VECTOR,
|
||||
domain=StoreNamedAttribute.Domain.CORNER,
|
||||
geometry=plinth.mesh,
|
||||
name="uv_map",
|
||||
value=plinth.uv_map,
|
||||
)
|
||||
plinth_geo = transform_geometry(geometry=plinth_uv, translation=(0.0, 0.17000000178813934, 0.0)).set_material(material=None)
|
||||
|
||||
backdrop = grid(size_x=2.0, size_y=2.0, vertices_x=2, vertices_y=2)
|
||||
backdrop_uv = store_named_attribute(
|
||||
data_type=StoreNamedAttribute.DataType.FLOAT_VECTOR,
|
||||
domain=StoreNamedAttribute.Domain.CORNER,
|
||||
geometry=backdrop.mesh,
|
||||
name="uv_map",
|
||||
value=backdrop.uv_map,
|
||||
)
|
||||
backdrop_plane = transform_geometry(
|
||||
geometry=backdrop_uv,
|
||||
translation=(0.0, -0.019999999552965164, 0.0),
|
||||
rotation=(-1.5707963705062866, 0.0, 0.0),
|
||||
)
|
||||
bounds = bounding_box(geometry=backdrop_plane, use_radius=True)
|
||||
uv = map_range(
|
||||
clamp=False,
|
||||
interpolation_type="LINEAR",
|
||||
data_type="FLOAT_VECTOR",
|
||||
vector=position(),
|
||||
from_min=bounds.min,
|
||||
from_max=bounds.max,
|
||||
to_min=(-1.0, -1.0, -1.0),
|
||||
to_max=(1.0, 1.0, 1.0),
|
||||
)
|
||||
backdrop_geo = store_named_attribute(
|
||||
data_type=StoreNamedAttribute.DataType.FLOAT_VECTOR,
|
||||
domain=StoreNamedAttribute.Domain.CORNER,
|
||||
geometry=backdrop_plane,
|
||||
name="UV",
|
||||
value=uv,
|
||||
).set_material(material=None)
|
||||
return {"Geometry": join_geometry(geometry=[text_face, plinth_geo, flip_faces(mesh=backdrop_geo)])}
|
||||
|
||||
|
||||
def _finalize_groups():
|
||||
import bpy
|
||||
|
||||
group = bpy.data.node_groups.get("VG Auto Smooth")
|
||||
if group:
|
||||
group.use_fake_user = True
|
||||
return [group]
|
||||
return []
|
||||
groups = []
|
||||
for name in (
|
||||
"VG Auto Smooth",
|
||||
"VG Curve To Mesh UV",
|
||||
"VG Curve To Mesh UV Demo",
|
||||
"VG Curve To Mesh UV Title",
|
||||
):
|
||||
group = bpy.data.node_groups.get(name)
|
||||
if group:
|
||||
group.use_fake_user = True
|
||||
groups.append(group)
|
||||
return groups
|
||||
|
||||
|
||||
_finalize_groups()
|
||||
|
|
|
|||
|
|
@ -29,6 +29,90 @@ def _accumulated_parameter(resolution, max_value):
|
|||
).trailing
|
||||
|
||||
|
||||
def _choose_float(curve_type, val0, val1, val2, val3, val4, val5=0.0):
|
||||
selected = switch(
|
||||
input_type=Switch.InputType.FLOAT,
|
||||
switch=compare(
|
||||
operation=Compare.Operation.EQUAL,
|
||||
data_type=Compare.DataType.INT,
|
||||
mode=Compare.Mode.ELEMENT,
|
||||
a=curve_type,
|
||||
b=4,
|
||||
),
|
||||
false=val5,
|
||||
true=val4,
|
||||
)
|
||||
for index, value in reversed(list(enumerate([val0, val1, val2, val3]))):
|
||||
selected = switch(
|
||||
input_type=Switch.InputType.FLOAT,
|
||||
switch=compare(
|
||||
operation=Compare.Operation.EQUAL,
|
||||
data_type=Compare.DataType.INT,
|
||||
mode=Compare.Mode.ELEMENT,
|
||||
a=curve_type,
|
||||
b=index,
|
||||
),
|
||||
false=selected,
|
||||
true=value,
|
||||
)
|
||||
return selected
|
||||
|
||||
|
||||
def _choose_string(curve_type, val0, val1, val2, val3, val4, val5=""):
|
||||
selected = switch(
|
||||
input_type=Switch.InputType.STRING,
|
||||
switch=compare(
|
||||
operation=Compare.Operation.EQUAL,
|
||||
data_type=Compare.DataType.INT,
|
||||
mode=Compare.Mode.ELEMENT,
|
||||
a=curve_type,
|
||||
b=4,
|
||||
),
|
||||
false=val5,
|
||||
true=val4,
|
||||
)
|
||||
for index, value in reversed(list(enumerate([val0, val1, val2, val3]))):
|
||||
selected = switch(
|
||||
input_type=Switch.InputType.STRING,
|
||||
switch=compare(
|
||||
operation=Compare.Operation.EQUAL,
|
||||
data_type=Compare.DataType.INT,
|
||||
mode=Compare.Mode.ELEMENT,
|
||||
a=curve_type,
|
||||
b=index,
|
||||
),
|
||||
false=selected,
|
||||
true=value,
|
||||
)
|
||||
return selected
|
||||
|
||||
|
||||
@tree("VG Choose Float Val")
|
||||
def vg_choose_float_val(
|
||||
curve_type: Int = 0,
|
||||
val0: Float = 0.0,
|
||||
val1: Float = 0.0,
|
||||
val2: Float = 0.0,
|
||||
val3: Float = 0.0,
|
||||
val4: Float = 0.0,
|
||||
val5: Float = 0.0,
|
||||
):
|
||||
return {"val": _choose_float(curve_type, val0, val1, val2, val3, val4, val5)}
|
||||
|
||||
|
||||
@tree("VG Choose Str Val")
|
||||
def vg_choose_str_val(
|
||||
curve_type: Int = 0,
|
||||
val0: String = "",
|
||||
val1: String = "",
|
||||
val2: String = "",
|
||||
val3: String = "",
|
||||
val4: String = "",
|
||||
val5: String = "",
|
||||
):
|
||||
return {"val": _choose_string(curve_type, val0, val1, val2, val3, val4, val5)}
|
||||
|
||||
|
||||
@tree("VG Param Epicycloid X")
|
||||
def vg_param_epicycloid_x(a: Float = 0.5, b: Float = 0.5, t: Float = 1.0):
|
||||
ratio_plus_one = math(
|
||||
|
|
@ -75,6 +159,184 @@ def vg_polar_spiral_y(a: Float = 0.5, b: Float = 0.5, theta: Float = 1.0):
|
|||
return {"y": math(operation=Math.Operation.MULTIPLY, value=(math(operation=Math.Operation.SINE, value=theta), radius))}
|
||||
|
||||
|
||||
@tree("VG Param XY")
|
||||
def vg_param_xy(a: Float = 0.0, b: Float = 0.0, c: Float = 0.0, t: Float = 0.0, curve_type: Int = 0):
|
||||
normalized_curve_type = math(
|
||||
operation=Math.Operation.MODULO,
|
||||
value=(math(operation=Math.Operation.ABSOLUTE, value=curve_type), 5.0),
|
||||
)
|
||||
|
||||
epi_x = vg_param_epicycloid_x(a=a, b=b, t=t)
|
||||
epi_y = vg_param_epicycloid_y(a=a, b=b, t=t)
|
||||
epitrochoid_x = math(
|
||||
operation=Math.Operation.SUBTRACT,
|
||||
value=(
|
||||
math(operation=Math.Operation.MULTIPLY, value=(math(operation=Math.Operation.ADD, value=(a, b)), math(operation=Math.Operation.COSINE, value=t))),
|
||||
math(
|
||||
operation=Math.Operation.MULTIPLY,
|
||||
value=(
|
||||
c,
|
||||
math(
|
||||
operation=Math.Operation.COSINE,
|
||||
value=math(
|
||||
operation=Math.Operation.MULTIPLY,
|
||||
value=(math(operation=Math.Operation.ADD, value=(math(operation=Math.Operation.DIVIDE, value=(a, b)), 1.0)), t),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
epitrochoid_y = math(
|
||||
operation=Math.Operation.SUBTRACT,
|
||||
value=(
|
||||
math(operation=Math.Operation.MULTIPLY, value=(math(operation=Math.Operation.ADD, value=(a, b)), math(operation=Math.Operation.SINE, value=t))),
|
||||
math(
|
||||
operation=Math.Operation.MULTIPLY,
|
||||
value=(
|
||||
c,
|
||||
math(
|
||||
operation=Math.Operation.SINE,
|
||||
value=math(
|
||||
operation=Math.Operation.MULTIPLY,
|
||||
value=(math(operation=Math.Operation.ADD, value=(math(operation=Math.Operation.DIVIDE, value=(a, b)), 1.0)), t),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
hypo_x = math(
|
||||
operation=Math.Operation.ADD,
|
||||
value=(
|
||||
math(operation=Math.Operation.MULTIPLY, value=(math(operation=Math.Operation.SUBTRACT, value=(a, b)), math(operation=Math.Operation.COSINE, value=t))),
|
||||
math(
|
||||
operation=Math.Operation.MULTIPLY,
|
||||
value=(
|
||||
b,
|
||||
math(
|
||||
operation=Math.Operation.COSINE,
|
||||
value=math(
|
||||
operation=Math.Operation.MULTIPLY,
|
||||
value=(math(operation=Math.Operation.SUBTRACT, value=(math(operation=Math.Operation.DIVIDE, value=(a, b)), 1.0)), t),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
hypo_y = math(
|
||||
operation=Math.Operation.SUBTRACT,
|
||||
value=(
|
||||
math(operation=Math.Operation.MULTIPLY, value=(math(operation=Math.Operation.SUBTRACT, value=(a, b)), math(operation=Math.Operation.SINE, value=t))),
|
||||
math(
|
||||
operation=Math.Operation.MULTIPLY,
|
||||
value=(
|
||||
b,
|
||||
math(
|
||||
operation=Math.Operation.SINE,
|
||||
value=math(
|
||||
operation=Math.Operation.MULTIPLY,
|
||||
value=(math(operation=Math.Operation.SUBTRACT, value=(math(operation=Math.Operation.DIVIDE, value=(a, b)), 1.0)), t),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
hypotrochoid_x = math(
|
||||
operation=Math.Operation.ADD,
|
||||
value=(
|
||||
math(operation=Math.Operation.MULTIPLY, value=(math(operation=Math.Operation.SUBTRACT, value=(a, b)), math(operation=Math.Operation.COSINE, value=t))),
|
||||
math(
|
||||
operation=Math.Operation.MULTIPLY,
|
||||
value=(
|
||||
c,
|
||||
math(
|
||||
operation=Math.Operation.COSINE,
|
||||
value=math(
|
||||
operation=Math.Operation.MULTIPLY,
|
||||
value=(math(operation=Math.Operation.SUBTRACT, value=(math(operation=Math.Operation.DIVIDE, value=(a, b)), 1.0)), t),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
hypotrochoid_y = math(
|
||||
operation=Math.Operation.SUBTRACT,
|
||||
value=(
|
||||
math(operation=Math.Operation.MULTIPLY, value=(math(operation=Math.Operation.SUBTRACT, value=(a, b)), math(operation=Math.Operation.SINE, value=t))),
|
||||
math(
|
||||
operation=Math.Operation.MULTIPLY,
|
||||
value=(
|
||||
c,
|
||||
math(
|
||||
operation=Math.Operation.SINE,
|
||||
value=math(
|
||||
operation=Math.Operation.MULTIPLY,
|
||||
value=(math(operation=Math.Operation.SUBTRACT, value=(math(operation=Math.Operation.DIVIDE, value=(a, b)), 1.0)), t),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
arch_radius = math(operation=Math.Operation.ADD, value=(a, math(operation=Math.Operation.MULTIPLY, value=(b, t))))
|
||||
arch_x = math(operation=Math.Operation.MULTIPLY, value=(arch_radius, math(operation=Math.Operation.COSINE, value=t)))
|
||||
arch_y = math(operation=Math.Operation.MULTIPLY, value=(arch_radius, math(operation=Math.Operation.SINE, value=t)))
|
||||
|
||||
linebreak = special_characters().line_break
|
||||
eq = _choose_string(
|
||||
normalized_curve_type,
|
||||
join_strings(
|
||||
delimiter=linebreak,
|
||||
strings=[
|
||||
string(string="y = ((a + b) * sin(t)) - (b * sin((a/b + 1) * t))"),
|
||||
string(string="x = ((a + b) * cos(t)) - (b * cos((a/b + 1) * t))"),
|
||||
string(string="Epicycloid"),
|
||||
],
|
||||
),
|
||||
join_strings(
|
||||
delimiter=linebreak,
|
||||
strings=[
|
||||
string(string="y = ((a + b) * sin(t)) - (c * sin((a/b + 1) * t))"),
|
||||
string(string="x = ((a + b) * cos(t)) - (c * cos((a/b + 1) * t))"),
|
||||
string(string="Epitrochoid"),
|
||||
],
|
||||
),
|
||||
join_strings(
|
||||
delimiter=linebreak,
|
||||
strings=[
|
||||
string(string="y = ((a - b) * sin(t)) + (b * sin((a/b - 1) * t))"),
|
||||
string(string="x = ((a - b) * cos(t)) + (b * cos((a/b - 1) * t))"),
|
||||
string(string="Hypocycloid"),
|
||||
],
|
||||
),
|
||||
join_strings(
|
||||
delimiter=linebreak,
|
||||
strings=[
|
||||
string(string="y = ((a - b) * sin(t)) + (c * sin((a/b - 1) * t))"),
|
||||
string(string="x = ((a - b) * cos(t)) + (c * cos((a/b - 1) * t))"),
|
||||
string(string="Hypotrochoid"),
|
||||
],
|
||||
),
|
||||
join_strings(
|
||||
delimiter=linebreak,
|
||||
strings=[
|
||||
string(string="r = a + b theta"),
|
||||
string(string="Archimedes Spiral"),
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
return {
|
||||
"x": _choose_float(normalized_curve_type, epi_x, epitrochoid_x, hypo_x, hypotrochoid_x, arch_x),
|
||||
"y": _choose_float(normalized_curve_type, epi_y, epitrochoid_y, hypo_y, hypotrochoid_y, arch_y),
|
||||
"eq": eq,
|
||||
}
|
||||
|
||||
|
||||
@tree("VG Archimedes Spiral")
|
||||
def vg_archimedes_spiral(
|
||||
resolution: Int = 10,
|
||||
|
|
@ -155,6 +417,60 @@ def vg_mirrored_root_spiral(a: Float = 0.30000001192092896, round_count: Float =
|
|||
return {"Geometry": join_geometry(geometry=[mirrored, forward])}
|
||||
|
||||
|
||||
def _empty_curve_geometry():
|
||||
return mesh_line(
|
||||
mode=MeshLine.Mode.OFFSET,
|
||||
count_mode=MeshLine.CountMode.TOTAL,
|
||||
count=0,
|
||||
offset=(0.0, 0.0, 1.0),
|
||||
)
|
||||
|
||||
|
||||
@tree("VG Param Curve")
|
||||
def vg_param_curve(
|
||||
curve_type: Int = 0,
|
||||
a: Float = 0.800000011920929,
|
||||
b: Float = 0.5,
|
||||
c: Float = 1.0,
|
||||
z: Float = 0.0,
|
||||
max_t: Float = 32.5,
|
||||
resolution: Float = 500.0,
|
||||
showlabel: Bool = True,
|
||||
thickness: Float = 0.009999999776482582,
|
||||
curve_material: Material = None,
|
||||
text_material: Material = None,
|
||||
):
|
||||
t = _accumulated_parameter(resolution=resolution, max_value=max_t)
|
||||
x, y, equation = vg_param_xy(a=a, b=b, c=c, t=t, curve_type=curve_type)
|
||||
|
||||
text_curve = string_to_curves(
|
||||
string=equation,
|
||||
size=2.0,
|
||||
align_x="Center",
|
||||
align_y="Middle",
|
||||
pivot_point="Bottom Left",
|
||||
).curve_instances
|
||||
label = transform_geometry(
|
||||
geometry=fill_curve(curve=text_curve, mode="Triangles", fill_rule="Even-Odd").set_material(material=text_material),
|
||||
translation=(0.0, 0.0, 0.30000001192092896),
|
||||
)
|
||||
label_or_empty = switch(input_type=Switch.InputType.GEOMETRY, switch=showlabel, false=_empty_curve_geometry(), true=label)
|
||||
|
||||
rail_seed = mesh_line(
|
||||
mode=MeshLine.Mode.OFFSET,
|
||||
count_mode=MeshLine.CountMode.TOTAL,
|
||||
count=resolution,
|
||||
start_location=(0.0, 0.0, 0.0),
|
||||
offset=(0.0, 0.0, 1.0),
|
||||
)
|
||||
rail = mesh_to_curve(mode=MeshToCurve.Mode.EDGES, mesh=rail_seed).set_position(position=combine_xyz(x=x, y=y, z=z))
|
||||
profile = curve_circle(mode=CurveCircle.Mode.RADIUS, resolution=32, 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)
|
||||
curve_mesh = rail.curve_to_mesh(profile_curve=profile, scale=radius_scale, fill_caps=False).set_material(material=curve_material)
|
||||
return {"Geometry": join_geometry(geometry=[label_or_empty, curve_mesh])}
|
||||
|
||||
|
||||
def _finalize_groups():
|
||||
import bpy
|
||||
|
||||
|
|
@ -164,9 +480,13 @@ def _finalize_groups():
|
|||
"VG Param Epicycloid Y",
|
||||
"VG Polar Spiral X",
|
||||
"VG Polar Spiral Y",
|
||||
"VG Choose Float Val",
|
||||
"VG Choose Str Val",
|
||||
"VG Param XY",
|
||||
"VG Archimedes Spiral",
|
||||
"VG Epicycloid",
|
||||
"VG Mirrored Root Spiral",
|
||||
"VG Param Curve",
|
||||
):
|
||||
group = bpy.data.node_groups.get(name)
|
||||
if group:
|
||||
|
|
|
|||
|
|
@ -112,11 +112,256 @@ def vg_pie_chart(
|
|||
return join_geometry(geometry=[a_geometry, b_geometry, c_geometry])
|
||||
|
||||
|
||||
def _empty_geometry():
|
||||
return mesh_line(
|
||||
mode=MeshLine.Mode.OFFSET,
|
||||
count_mode=MeshLine.CountMode.TOTAL,
|
||||
count=0,
|
||||
offset=(0.0, 0.0, 1.0),
|
||||
)
|
||||
|
||||
|
||||
@tree("VG Extended Pie Segment")
|
||||
def vg_extended_pie_segment(
|
||||
radius: Float = 0.0,
|
||||
pie_height: Float = 0.0,
|
||||
text_height: Float = 0.0,
|
||||
text_size: Float = 0.0,
|
||||
text_material: Material = None,
|
||||
text_offset: Float = 0.0,
|
||||
pie_material: Material = None,
|
||||
include_percentage: Bool = True,
|
||||
value: Float = 0.0,
|
||||
total: Float = 0.0,
|
||||
start_angle: Float = 0.0,
|
||||
shift: Float = 0.0,
|
||||
text: String = "",
|
||||
):
|
||||
fraction = math(operation=Math.Operation.DIVIDE, value=(value, total))
|
||||
sweep = math(operation=Math.Operation.MULTIPLY, value=(fraction, TAU))
|
||||
end_angle = math(operation=Math.Operation.ADD, value=(start_angle, sweep))
|
||||
mid_angle = math(operation=Math.Operation.ADD, value=(start_angle, math(operation=Math.Operation.DIVIDE, value=(sweep, 2.0))))
|
||||
|
||||
percentage = value_to_string(
|
||||
data_type=ValueToString.DataType.FLOAT,
|
||||
value=math(operation=Math.Operation.MULTIPLY, value=(fraction, 100.0)),
|
||||
decimals=2,
|
||||
)
|
||||
percentage_line = join_strings(delimiter="", strings=[string(string="%"), percentage])
|
||||
label_with_percentage = join_strings(delimiter=special_characters().line_break, strings=[percentage_line, text])
|
||||
label = switch(input_type=Switch.InputType.STRING, switch=include_percentage, false=text, true=label_with_percentage)
|
||||
|
||||
shift_vector = combine_xyz(
|
||||
x=math(operation=Math.Operation.MULTIPLY, value=(shift, math(operation=Math.Operation.COSINE, value=mid_angle))),
|
||||
y=math(operation=Math.Operation.MULTIPLY, value=(shift, math(operation=Math.Operation.SINE, value=mid_angle))),
|
||||
z=0.0,
|
||||
)
|
||||
label_radius = math(operation=Math.Operation.MULTIPLY, value=(text_offset, radius))
|
||||
label_offset = vector_math(
|
||||
operation=VectorMath.Operation.ADD,
|
||||
vector=(
|
||||
shift_vector,
|
||||
combine_xyz(
|
||||
x=math(operation=Math.Operation.MULTIPLY, value=(label_radius, math(operation=Math.Operation.COSINE, value=mid_angle))),
|
||||
y=math(operation=Math.Operation.MULTIPLY, value=(label_radius, math(operation=Math.Operation.SINE, value=mid_angle))),
|
||||
z=0.0,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
text_curves = string_to_curves(
|
||||
string=label,
|
||||
size=text_size,
|
||||
align_x="Center",
|
||||
align_y="Middle",
|
||||
pivot_point="Bottom Left",
|
||||
).curve_instances
|
||||
text_face = fill_curve(curve=text_curves, mode="Triangles", fill_rule="Even-Odd")
|
||||
placed_text = set_position(geometry=text_face.set_material(material=text_material), offset=label_offset)
|
||||
extruded_text = extrude_mesh(
|
||||
mode=ExtrudeMesh.Mode.FACES,
|
||||
mesh=placed_text,
|
||||
offset=combine_xyz(x=0.0, y=0.0, z=math(operation=Math.Operation.ADD, value=(text_height, pie_height))),
|
||||
offset_scale=1.0,
|
||||
individual=True,
|
||||
).mesh.set_material(material=text_material)
|
||||
|
||||
arc_curve = arc(
|
||||
mode=Arc.Mode.RADIUS,
|
||||
resolution=64,
|
||||
radius=radius,
|
||||
start_angle=start_angle,
|
||||
sweep_angle=sweep,
|
||||
connect_center=True,
|
||||
)
|
||||
shifted_arc = transform_geometry(geometry=arc_curve, translation=shift_vector)
|
||||
pie_face = fill_curve(curve=shifted_arc, mode="Triangles", fill_rule="Even-Odd").set_material(
|
||||
material=pie_material
|
||||
)
|
||||
extruded_pie = extrude_mesh(
|
||||
mode=ExtrudeMesh.Mode.FACES,
|
||||
mesh=pie_face,
|
||||
offset=combine_xyz(x=0.0, y=0.0, z=pie_height),
|
||||
offset_scale=1.0,
|
||||
individual=True,
|
||||
).mesh.set_material(material=pie_material)
|
||||
|
||||
return {"End Angle": end_angle, "Pie": join_geometry(geometry=[extruded_text, extruded_pie, placed_text, pie_face])}
|
||||
|
||||
|
||||
@tree("VG Extended Pie Chart")
|
||||
def vg_extended_pie_chart(
|
||||
title: String = "Extended Pie Chart",
|
||||
title_size: Float = 0.20000000298023224,
|
||||
title_material: Material = None,
|
||||
title_offset: Float = 0.18000000715255737,
|
||||
segment_count: Int = 10,
|
||||
radius: Float = 1.0,
|
||||
pie_height: Float = 0.10000000149011612,
|
||||
text_height: Float = 0.004999999888241291,
|
||||
text_size: Float = 0.07999999821186066,
|
||||
text_material: Material = None,
|
||||
text_offset: Float = 0.699999988079071,
|
||||
include_percentage: Bool = True,
|
||||
value_1: Float = 20.0,
|
||||
label_1: String = "Lorem",
|
||||
shift_1: Float = 0.20000000298023224,
|
||||
material_1: Material = None,
|
||||
value_2: Float = 30.0,
|
||||
label_2: String = "Ipsum",
|
||||
shift_2: Float = 0.0,
|
||||
material_2: Material = None,
|
||||
value_3: Float = 27.0,
|
||||
label_3: String = "Dolor",
|
||||
shift_3: Float = 0.0,
|
||||
material_3: Material = None,
|
||||
value_4: Float = 25.0,
|
||||
label_4: String = "Sit",
|
||||
shift_4: Float = 0.0,
|
||||
material_4: Material = None,
|
||||
value_5: Float = 55.0,
|
||||
label_5: String = "Amet",
|
||||
shift_5: Float = 0.0,
|
||||
material_5: Material = None,
|
||||
value_6: Float = 45.0,
|
||||
label_6: String = "Consectetur",
|
||||
shift_6: Float = 0.0,
|
||||
material_6: Material = None,
|
||||
value_7: Float = 25.0,
|
||||
label_7: String = "Adipiscing",
|
||||
shift_7: Float = 0.0,
|
||||
material_7: Material = None,
|
||||
value_8: Float = 35.0,
|
||||
label_8: String = "Elit",
|
||||
shift_8: Float = 0.0,
|
||||
material_8: Material = None,
|
||||
value_9: Float = 58.0,
|
||||
label_9: String = "Sed",
|
||||
shift_9: Float = 0.0,
|
||||
material_9: Material = None,
|
||||
value_10: Float = 32.0,
|
||||
label_10: String = "Do",
|
||||
shift_10: Float = 0.0,
|
||||
material_10: Material = None,
|
||||
):
|
||||
values = [value_1, value_2, value_3, value_4, value_5, value_6, value_7, value_8, value_9, value_10]
|
||||
labels = [label_1, label_2, label_3, label_4, label_5, label_6, label_7, label_8, label_9, label_10]
|
||||
shifts = [shift_1, shift_2, shift_3, shift_4, shift_5, shift_6, shift_7, shift_8, shift_9, shift_10]
|
||||
materials = [
|
||||
material_1,
|
||||
material_2,
|
||||
material_3,
|
||||
material_4,
|
||||
material_5,
|
||||
material_6,
|
||||
material_7,
|
||||
material_8,
|
||||
material_9,
|
||||
material_10,
|
||||
]
|
||||
|
||||
total = value_1
|
||||
for index, segment_value in enumerate(values[1:], start=2):
|
||||
total = math(
|
||||
operation=Math.Operation.ADD,
|
||||
value=(
|
||||
total,
|
||||
switch(
|
||||
input_type=Switch.InputType.FLOAT,
|
||||
switch=math(operation=Math.Operation.GREATER_THAN, value=(segment_count, index - 1.0)),
|
||||
false=0.0,
|
||||
true=segment_value,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
empty = _empty_geometry()
|
||||
start_angle = 0.0
|
||||
segments = []
|
||||
for index, (segment_value, label, segment_shift, segment_material) in enumerate(
|
||||
zip(values, labels, shifts, materials),
|
||||
start=1,
|
||||
):
|
||||
end_angle, segment_geometry = vg_extended_pie_segment(
|
||||
radius=radius,
|
||||
pie_height=pie_height,
|
||||
text_height=text_height,
|
||||
text_size=text_size,
|
||||
text_material=text_material,
|
||||
text_offset=text_offset,
|
||||
pie_material=segment_material,
|
||||
include_percentage=include_percentage,
|
||||
value=segment_value,
|
||||
total=total,
|
||||
start_angle=start_angle,
|
||||
shift=segment_shift,
|
||||
text=label,
|
||||
)
|
||||
if index == 1:
|
||||
segments.append(segment_geometry)
|
||||
else:
|
||||
segments.append(
|
||||
switch(
|
||||
input_type=Switch.InputType.GEOMETRY,
|
||||
switch=math(operation=Math.Operation.GREATER_THAN, value=(segment_count, index - 1.0)),
|
||||
false=empty,
|
||||
true=segment_geometry,
|
||||
)
|
||||
)
|
||||
start_angle = end_angle
|
||||
|
||||
title_curves = string_to_curves(
|
||||
string=title,
|
||||
size=title_size,
|
||||
align_x="Center",
|
||||
align_y="Middle",
|
||||
pivot_point="Bottom Left",
|
||||
).curve_instances
|
||||
title_face = fill_curve(curve=title_curves, mode="Triangles", fill_rule="Even-Odd")
|
||||
title_position = combine_xyz(
|
||||
x=0.0,
|
||||
y=math(
|
||||
operation=Math.Operation.SUBTRACT,
|
||||
value=(math(operation=Math.Operation.MULTIPLY, value=(-1.0, math(operation=Math.Operation.ADD, value=(radius, title_size)))), title_offset),
|
||||
),
|
||||
z=0.0,
|
||||
)
|
||||
placed_title = transform_geometry(geometry=title_face, translation=title_position).set_material(material=title_material)
|
||||
extruded_title = extrude_mesh(
|
||||
mode=ExtrudeMesh.Mode.FACES,
|
||||
mesh=placed_title,
|
||||
offset=combine_xyz(x=0.0, y=0.0, z=text_height),
|
||||
offset_scale=1.0,
|
||||
individual=True,
|
||||
).mesh.set_material(material=title_material)
|
||||
return {"Geometry": join_geometry(geometry=[*segments, placed_title, extruded_title])}
|
||||
|
||||
|
||||
def _finalize_groups():
|
||||
import bpy
|
||||
|
||||
groups = []
|
||||
for name in ("VG Pie Segment", "VG Pie Chart"):
|
||||
for name in ("VG Pie Segment", "VG Pie Chart", "VG Extended Pie Segment", "VG Extended Pie Chart"):
|
||||
group = bpy.data.node_groups.get(name)
|
||||
if not group:
|
||||
continue
|
||||
|
|
|
|||
Loading…
Reference in a new issue