CreateSpline ( [closed][,smooth] )

Parameters

closed (optional) - True joins the last point back to the first to make a loop; False (default)

smooth (optional) - True passes a smooth curve through the points (default); False joins them with straight lines

Description

Creates an empty spline - a path through 3D points - and returns its handle.

A spline is a path through points you add with AddSplinePoint. Use it to lay out a water slide, a road, a cable, a rail or a train's route, then build a mesh along it with CreatePipe, CreateRod, CreateRibbon or CreateSweep, and move things along it with PositionOnSpline.

A smooth spline passes through every point, the first and last included, and does not overshoot into loops or cusps between closely spaced points (it uses centripetal Catmull-Rom curves). An open spline starts heading towards its second point and ends heading away from its second-to-last, so its ends have no hooks. A closed spline joins smoothly back to its start, and distances along it wrap round, so a train on a loop can just keep adding to its distance.

A spline is a plain handle, like a brush, not an entity: it has no position of its own and is never drawn. Its coordinates are just numbers. A mesh made from it puts them in its parent's space, and PositionOnSpline reads them in the entity's parent space, as PositionEntity does. Free it with FreeSpline when you have finished; meshes already made from it are not affected.

A spline needs at least two distinct points before it can be measured or built along; points closer than 0.001 apart are merged. SplineUpright and SplineDetail change how meshes follow it.

See also: AddSplinePoint, CreatePipe, PositionOnSpline, SplineLength, SplineUpright, FreeSpline.

Example

; CreateSpline Example
; --------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,2,-6
RotateEntity camera,15,0,0

light=CreateLight()
RotateEntity light,45,45,0

; Five points for the path, each marked with a small red ball
Dim px#(4),py#(4),pz#(4)
For index=0 To 4
    Read px(index),py(index),pz(index)
    marker=CreateSphere(8)
    ScaleEntity marker,0.12,0.12,0.12
    PositionEntity marker,px(index),py(index),pz(index)
    EntityColor marker,255,60,60
Next
Data -3,0,0
Data -1.5,1.5,1.5
Data 0,0.2,2.5
Data 1.5,1.5,1
Data 3,0,-0.5

; A bead that travels along the path
bead=CreateSphere(12)
ScaleEntity bead,0.2,0.2,0.2
EntityColor bead,255,220,80

closed=False
smooth=True
rebuild=True
distance#=0

While Not KeyDown(1)

    ; C makes a loop, S switches between curves and straight lines
    If KeyHit(46) Then
        closed=Not closed
        rebuild=True
    EndIf
    If KeyHit(31) Then
        smooth=Not smooth
        rebuild=True
    EndIf

    If rebuild Then
        If route Then
            FreeEntity rod
            FreeSpline route
        EndIf
        ; A new spline, then its points in order
        route=CreateSpline(closed,smooth)
        For index=0 To 4
            AddSplinePoint route,px(index),py(index),pz(index)
        Next
        ; A thin rod shows where the path goes
        rod=CreateRod(route,0.04)
        EntityColor rod,120,200,255
        rebuild=False
    EndIf

    ; Move the bead 3 m a second, starting again at the end of an open path
    distance=distance+0.05
    If distance>SplineLength(route) Then distance=0
    PositionOnSpline bead,route,distance

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"Arrow keys: move camera   C: closed   S: smooth   Esc: exit"
    Text 0,20,"route=CreateSpline("+closed+","+smooth+")"
    Text 0,40,"The path passes through every point; closed joins the last back to the first"

    Flip

Wend

End

Index