Created
February 25, 2023 16:46
-
-
Save RichardEllicott/7bce99c3db28fe9c6f8b46a43c04a02a to your computer and use it in GitHub Desktop.
This file contains 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
# function that takes array of Vector3, returns a spline between them (as a Curve3D) | |
static func spline_positions_to_curve(marker_positions: Array, curve_strength: float) -> Curve3D: | |
var curve3D: Curve3D = Curve3D.new() | |
for i in marker_positions.size(): | |
var pos = marker_positions[i] # curve pos | |
var _in: Vector3 = Vector3() # the in and out directions (opposite for unbroken curve) | |
var _out: Vector3 = Vector3() | |
if i > 0 and i < marker_positions.size() - 1: | |
var posA1: Vector3 = marker_positions[i-1] | |
var posA2: Vector3 = marker_positions[i+1] | |
var offset1: Vector3 = posA1 - pos | |
var offset2: Vector3 = posA2 - pos | |
offset1 = offset1.normalized() | |
offset2 = offset2.normalized() | |
var offset3: Vector3 = offset1 | |
offset3 -= offset2 # we add minus as it's opposite direction | |
offset3 = offset3.normalized() | |
offset3 *= curve_strength | |
_in = offset3 | |
_out = -offset3 | |
curve3D.add_point(pos, _in, _out) | |
return curve3D |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment