Quote: "what does it actually produce? Functions to reproduce the path or some kind of object?"
Currently, it produces a list of points. It would be possible to add the curve points once I get more efficient in benzier calculations.
Quote: ""Is there a Blender alternative? It might make it a little more accessible""
Hmm sorry I don't have skills in writing scripts for blender right now But there should be a script, that could save the points of the spline and export them to a readable format. I think I will write a blender script, when I manage to add bend points to the benzier curve library, but I still have to learn more about the process of benzier calculation.
Custom spline library with 2 tangents
// Project: Bezier Curve New
// Created: 2016-02-15
// set window properties
SetWindowTitle( "Bezier Curve New" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
#constant KEY_LEFT 37
#constant KEY_UP 38
#constant KEY_RIGHT 39
#constant KEY_DOWN 40
#constant KEY_W 87
#constant KEY_A 65
#constant KEY_S 83
#constant KEY_D 68
#constant KEY_SHIFT 16
type tVector
x# as float
y# as float
z# as float
endtype
type tSpline_Point
anchor as tVector
bend_in as tVector
bend_out as tVector
endtype
type tCurveDef
closed as integer
knots as integer
visual as integer
endtype
dim OA_Spline[] as tCurveDef // this array defines the splines
dim OA_SplineCurvePoints[0,0] as tSpline_Point // this array saves all points(knots) to a spline
dim OA_SplineVisualisationPoints[0,0] as tVector // this array is created for a visualisation of the splines
current_spline=create_spline(0) // create an open spline
add_spline_knot(current_spline,20.0,20.0,20.0, 10.0,10.0,10.0, 30.0,30.0,30.0) // add knots
add_spline_knot(current_spline,60.0,50.0,10.0, 40.0,30.0,0.0 ,70.0,60.0,50.0)
add_spline_knot(current_spline,80.0,80.0,80.0,70.0,70.0,70.0,90.0,90.0,90.0)
visualize_spline(current_spline,40) // spline number, amount of edge points(nodes)
remstart
// create a list with 100 dots between 0 and 1
for i=0 to 100
someline.length=someline.length+1
someline[someline.length].x#=find_knot_position(current_spline,0,i/100.0,0)
someline[someline.length].y#=find_knot_position(current_spline,0,i/100.0,1)
someline[someline.length].z#=find_knot_position(current_spline,0,i/100.0,2)
next i
remend
box=CreateObjectBox(2,2,2)
point=CreateObjectBox(1,1,1)
ps#=0.0
do
print("percent: "+str(ps#))
ps#=ps#+0.01
if ps#=>1.0 then ps#=0.0
x#=find_knot_position(current_spline,0,ps#,0)
y#=find_knot_position(current_spline,0,ps#,1)
z#=find_knot_position(current_spline,0,ps#,2)
SetObjectPosition(box,x#,y#,z#)
remstart
for i=0 to 100-1
sx# = GetScreenXFrom3D(someline[i].x#,someline[i].y#,someline[i].z#)
sy# = GetScreenYFrom3D(someline[i].x#,someline[i].y#,someline[i].z#)
ex# = GetScreenXFrom3D(someline[i+1].x#,someline[i+1].y#,someline[i+1].z#)
ey# = GetScreenYFrom3D(someline[i+1].x#,someline[i+1].y#,someline[i+1].z#)
// color = MakeColor(130,110,0)
color = MakeColor(130,210,0)
black = MakeColor(0,0,0)
DrawLine(sx#,sy#,ex#,ey#,color,color)
next i
remend
if GetRawKeyState(KEY_SHIFT)=1
movspd#=3
else
movspd#=1
endif
// movement
if GetRawKeyState(KEY_W)=1 then MoveCameraLocalZ(1,movspd#)
if GetRawKeyState(KEY_S)=1 then MoveCameraLocalZ(1,-movspd#)
if GetRawKeyState(KEY_A)=1 then MoveCameraLocalX(1,-movspd#)
if GetRawKeyState(KEY_D)=1 then MoveCameraLocalX(1,movspd#)
// rotation
if GetRawKeyState(KEY_UP)=1 then RotateCameraLocalX( 1,-2)
if GetRawKeyState(KEY_DOWN)=1 then RotateCameraLocalX( 1,2)
if GetRawKeyState(KEY_LEFT)=1 then RotateCameraGlobalY( 1,-2)
if GetRawKeyState(KEY_RIGHT)=1 then RotateCameraGlobalY( 1,2)
Print( ScreenFPS() )
draw_spline_bends()
// draw_spline()
draw_spline(current_spline)
Sync()
loop
function visualize_spline(spline,nodes)
dim OA_SplineVisualisationPoints[spline,nodes] as tVector
Segments=OA_Spline[spline].knots-1
NodesPerSegment = nodes/(OA_Spline[spline].knots-1)
curnode=-1
for knot=0 to Segments-1
for nps=0 to NodesPerSegment
if curnode<nodes then inc curnode
remstart
repeat
print(Segments)
print(NodesPerSegment)
print(spline)
print(knot)
print(nps)
sync()
until GetRawMouseLeftPressed()=1
remend
t#=(1.0/NodesPerSegment)*nps
OA_SplineVisualisationPoints[spline,curnode].x#=find_knot_position(spline,knot,t#,0)
OA_SplineVisualisationPoints[spline,curnode].y#=find_knot_position(spline,knot,t#,1)
OA_SplineVisualisationPoints[spline,curnode].z#=find_knot_position(spline,knot,t#,2)
test=CreateObjectBox(0.5,0.5,0.5)
SetObjectPosition(test,OA_SplineVisualisationPoints[spline,curnode].x#,OA_SplineVisualisationPoints[spline,curnode].y#,OA_SplineVisualisationPoints[spline,curnode].z#)
next nps
next knot
OA_Spline[spline].visual=nodes
endfunction
function draw_spline_bends()
for spline=0 to OA_Spline.length
if OA_Spline[spline].knots>-1
for knot=0 to OA_Spline[spline].knots-1
ax#=OA_SplineCurvePoints[spline,knot].anchor.x#
ay#=OA_SplineCurvePoints[spline,knot].anchor.y#
az#=OA_SplineCurvePoints[spline,knot].anchor.z#
bix#=OA_SplineCurvePoints[spline,knot].bend_in.x#
biy#=OA_SplineCurvePoints[spline,knot].bend_in.y#
biz#=OA_SplineCurvePoints[spline,knot].bend_in.z#
box#=OA_SplineCurvePoints[spline,knot].bend_out.x#
boy#=OA_SplineCurvePoints[spline,knot].bend_out.y#
boz#=OA_SplineCurvePoints[spline,knot].bend_out.z#
sx# = GetScreenXFrom3D(ax#,ay#,az#)
sy# = GetScreenYFrom3D(ax#,ay#,az#)
ex# = GetScreenXFrom3D(bix#,biy#,biz#)
ey# = GetScreenYFrom3D(bix#,biy#,biz#)
e2x# = GetScreenXFrom3D(box#,boy#,boz#)
e2y# = GetScreenYFrom3D(box#,boy#,boz#)
// color = MakeColor(130,110,0)
color = MakeColor(130,210,0) // in
color2 = MakeColor(230,210,0) // out
black = MakeColor(0,0,0) // first color
DrawLine(sx#,sy#,ex#,ey#,black,color) // bend in
DrawLine(sx#,sy#,e2x#,e2y#,black,color2) // bend out
next knot
endif
next spline
endfunction
function draw_spline(spline)
if OA_Spline[spline].visual>-1
for i=0 to OA_Spline[spline].visual-1
sx# = GetScreenXFrom3D(OA_SplineVisualisationPoints[spline,i].x#,OA_SplineVisualisationPoints[spline,i].y#,OA_SplineVisualisationPoints[spline,i].z#)
sy# = GetScreenYFrom3D(OA_SplineVisualisationPoints[spline,i].x#,OA_SplineVisualisationPoints[spline,i].y#,OA_SplineVisualisationPoints[spline,i].z#)
ex# = GetScreenXFrom3D(OA_SplineVisualisationPoints[spline,i+1].x#,OA_SplineVisualisationPoints[spline,i+1].y#,OA_SplineVisualisationPoints[spline,i+1].z#)
ey# = GetScreenYFrom3D(OA_SplineVisualisationPoints[spline,i+1].x#,OA_SplineVisualisationPoints[spline,i+1].y#,OA_SplineVisualisationPoints[spline,i+1].z#)
// color = MakeColor(130,110,0)
color = MakeColor(0,0,255)
black = MakeColor(0,0,100)
DrawLine(sx#,sy#,ex#,ey#,black,color)
next i
endif
endfunction
// ================================================================
// ==== Online Arts Spline Library =============================
// ================================================================
// create a spline inside the array and return the spline number
function create_spline(closed)
OA_Spline.length=OA_Spline.length+1
spline=OA_Spline.length
OA_Spline[spline].visual=-1
endfunction spline
// add a knot to the already created spline
// each knot can have one position represented by anchor and two bend vectors
// the most bend vectors are on one line
// Position: a1x#,a1y#,a1z#
// Bend1 (in): b1x#,b1y#,b1z#
// Bend2 (out): b2x#,b2y#,b2z#
function add_spline_knot(spline_id,a1x#,a1y#,a1z#, b1x#,b1y#,b1z#, b2x#,b2y#,b2z#)
OA_Spline[spline_Id].knots=OA_Spline[spline_Id].knots+1
knot=OA_Spline[spline_Id].knots-1
dim OA_SplineCurvePoints[spline_id,knot] as tSpline_Point
OA_SplineCurvePoints[spline_id,knot].anchor.x# = a1x# // Position
OA_SplineCurvePoints[spline_id,knot].anchor.y# = a1y#
OA_SplineCurvePoints[spline_id,knot].anchor.z# = a1z#
anchor=CreateObjectBox(1,1,1)
SetObjectColor(anchor,255,255,0,255)
SetObjectPosition(anchor,a1x#,a1y#,a1z#)
OA_SplineCurvePoints[spline_id,knot].bend_in.x# = b1x# // Bend 1 in
OA_SplineCurvePoints[spline_id,knot].bend_in.y# = b1y#
OA_SplineCurvePoints[spline_id,knot].bend_in.z# = b1z#
bend=CreateObjectBox(1,1,1)
SetObjectColor(bend,0,255,0,255)
SetObjectPosition(bend,b1x#,b1y#,b1z#)
OA_SplineCurvePoints[spline_id,knot].bend_out.x# = b2x# // Bend 2 out
OA_SplineCurvePoints[spline_id,knot].bend_out.y# = b2y#
OA_SplineCurvePoints[spline_id,knot].bend_out.z# = b2z#
bend=CreateObjectBox(1,1,1)
SetObjectColor(bend,0,255,0,255)
SetObjectPosition(bend,b2x#,b2y#,b2z#)
endfunction
function find_knot_position(spline,knot,t#,var)
// define the arrays
// var=0 : x#
// var=1 : y#
// var=2 : z#
// if closed and its the last knot, the next knot is the first one
if OA_Spline[spline].closed=1
sndknot=knot+1
// if knot=OA_Spline[spline].knots then sndknot=0
else
sndknot=knot+1
endif
// to calculate a point between two knots we need following information
a1x#=OA_SplineCurvePoints[spline,knot].anchor.x# // knot 1 position
a1y#=OA_SplineCurvePoints[spline,knot].anchor.y#
a1z#=OA_SplineCurvePoints[spline,knot].anchor.z#
b1x#=OA_SplineCurvePoints[spline,knot].bend_out.x# // knot 1 out bend
b1y#=OA_SplineCurvePoints[spline,knot].bend_out.y#
b1z#=OA_SplineCurvePoints[spline,knot].bend_out.z#
a2x#=OA_SplineCurvePoints[spline,sndknot].anchor.x# // knot 2 position
a2y#=OA_SplineCurvePoints[spline,sndknot].anchor.y#
a2z#=OA_SplineCurvePoints[spline,sndknot].anchor.z#
b2x#=OA_SplineCurvePoints[spline,sndknot].bend_in.x# // knot 2 in bend
b2y#=OA_SplineCurvePoints[spline,sndknot].bend_in.y#
b2z#=OA_SplineCurvePoints[spline,sndknot].bend_in.z#
// this is where the magic happens:
cx# = 3.0 * (b1x# - a1x#)
bx# = 3.0 * (b2x# - b1x#) - cx#
ax# = a2x# - a1x# - cx# - bx#
cy# = 3.0 * (b1y# - a1y#)
by# = 3.0 * (b2y# - b1y#) - cy#
ay# = a2y# - a1y# - cy# - by#
cz# = 3.0 * (b1z# - a1z#)
bz# = 3.0 * (b2z# - b1z#) - cz#
az# = a2z# - a1z# - cz# - bz#
tSquared# = t# * t#
tCubed# = tSquared# * t#
// set return to right var
select var
case 0:
SplinePoint# = (ax# * tCubed#) + (bx# * tSquared#) + (cx# * t#) + a1x# // x
endcase
case 1:
SplinePoint# = (ay# * tCubed#) + (by# * tSquared#) + (cy# * t#) + a1y# // y
endcase
case 2:
SplinePoint# = (az# * tCubed#) + (bz# * tSquared#) + (cz# * t#) + a1z# // z
endcase
endselect
endfunction SplinePoint#