Godot 4.3
I have figured out how to create a dynamically modeled shape in the editor using this tool script:
func csg_generate():
if csg != null:
csg.queue_free()
csg = CSGCombiner3D.new()
add_child(csg)
csg.owner = get_tree().edited_scene_root
if path_mode == "Path":
var path_csg = CSGPolygon3D.new()
csg.add_child(path_csg)
path_csg.owner = get_tree().edited_scene_root
var packed_array : PackedVector2Array
var rad_per = deg_to_rad(360.0 / sides)
var node_pos := Vector2(radius, 0)
for i in sides:#
node_pos = node_pos.rotated(rad_per)
packed_array.append(node_pos)
path_csg.mode = CSGPolygon3D.MODE_PATH
path_csg.path_node = get_path()
path_csg.path_rotation = CSGPolygon3D.PATH_ROTATION_PATH_FOLLOW
path_csg.polygon = packed_array
path_csg.path_local = true
if path_rounded:
var begin_cap = CSGPolygon3D.new()
csg.add_child(begin_cap)
begin_cap.owner = get_tree().edited_scene_root
var position = curve.sample_baked()
begin_cap.transform.basis = curve.sample_baked_with_rotation(0.35).basis
begin_cap.polygon = packed_array
begin_cap.mode = CSGPolygon3D.MODE_SPIN
begin_cap.spin_sides = sides
begin_cap.polygon = packed_array
generate_csg = false
need_update = false
(This code is temporary as I figure out core systems, I know it’s not well optimized yet) This accomplishes the core goal of what I set out to do: create uniformly divided “round” surface around a path. But I cannot seem to figure out a way to “cap” the path.
The jist of what the code is doing vs what I want it to do:
The wants are pretty simple (in theory); I want to be able to cap the shape the path generates with rounded edges (even a pyramid coming to a point is fine, just something to taper the edges). I need these edges rounded because the path is how I determine which point to apply gravity in the direction of, and it would obviously act weird on the flat sides otherwise. (This is a toggle because I intend to make some hollow and flat-ended)
What it does currently: The CSG boxes do not line up well enough to create smooth sides.
I’ve hit a point where I am grasping at straws. I can’t seem to identify a way to take the very first set of points the polygon is drawing at. The closest I’ve managed is to get pretty close but still have the issue of clipping on the sides.
Really any input is helpful, I’m still rather novice with godot and GDScript