CreateRod ( spline[,radius#][,segments][,parent] )

Parameters

spline - spline to follow

radius# (optional) - radius of the rod; 0.05 (default)

segments (optional) - segments round the rod, from 3 to 256; 8 (default)

parent (optional) - parent entity for the new mesh; 0 for none (default)

Description

Creates a solid round rod along a spline and returns its handle.

Use it for cables, ropes, rails, hoses, handrails, branches and tentacles. The scale of each spline point thickens or thins it, so a branch can taper towards its tip.

Surface 1 is the length of the rod and surface 2 its end caps; a rod along a closed spline has no ends. A texture wraps once round the rod, with U from 0 to 1, and V runs along it in world units.

Like every sweep, it places rings of vertices where the path bends or banks and few along straights (see SplineDetail), keeps its cross-section level or lets it turn as SplineUpright says, and mitres corner points so the cross-section keeps its thickness. The vertices are written ring by ring along the path, in the same order round every ring, so a program can still colour or adjust them afterwards.

The spline's coordinates become the mesh's vertices, in the parent's space when you give a parent. An entity placed with PositionOnSpline under the same parent therefore lines up with the mesh.

A bend tighter than the cross-section reaches folds its inner side through itself, and a path that passes through itself makes the mesh cross itself. Neither stops the program, because the mesh may look perfectly good, but the mesh is flagged as not solid: MeshUnion, MeshSubtract, MeshIntersect and automatic moving physics then refuse it with a message giving the distance along the path where the problem starts.

Automatic EntityPhysics makes a static rod a triangle mesh, so things can slide inside it or along it. A moving one is built from convex pieces that keep its openings open, at most 64 of them; if the shape cannot be covered that way, EntityPhysics stops with a runtime error suggesting static mode or an explicit collider, rather than quietly filling it in.

On a spline that follows a terrain (SplineFollowGround), the rod rests on the ground, lifted by its radius and sunk slightly into it, and is rebuilt as the ground changes.

The spline must have at least two distinct points. That, a spline handle that does not exist, and arguments out of range stop the program with a runtime error naming the problem, in release builds as well as debug ones.

See also: CreatePipe, CreateRibbon, CreateSweep, CreateSpline, AddSplinePoint, SplineFollowGround.

Example

; CreateRod Example
; -----------------

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

camera=CreateCamera()
PositionEntity camera,0,2,-7
; A blue sky, so the dark cable stands out
CameraClsColor camera,40,70,110

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

; Two poles to hang a power cable between
For side=-1 To 1 Step 2
    pole=CreateCylinder(8)
    ScaleEntity pole,0.1,1.6,0.1
    PositionEntity pole,side*4,1.6,0
    EntityColor pole,120,90,60
Next

; A swinging frame level with the pole tops, so the cable sways in the wind
swing=CreatePivot()
PositionEntity swing,0,3.2,0

; The cable sags between the poles; its points are in the swing's space
route=CreateSpline()
AddSplinePoint route,-3.8,0,0
AddSplinePoint route,-2,-0.8,0
AddSplinePoint route,0,-1.1,0
AddSplinePoint route,2,-0.8,0
AddSplinePoint route,3.8,0,0

; Surface 1 is the length of the rod, surface 2 its end caps
black=CreateBrush(40,40,45)
copper=CreateBrush(230,140,60)

radius_steps=4
segments=8
wire=False
cable=0

While Not KeyDown(1)

    ; [ / ] change the radius, - / + the number of sides, W shows the wireframe
    If KeyHit(26) And radius_steps>1 Then
        radius_steps=radius_steps-1
        If cable Then FreeEntity cable
        cable=0
    EndIf
    If KeyHit(27) And radius_steps<10 Then
        radius_steps=radius_steps+1
        If cable Then FreeEntity cable
        cable=0
    EndIf
    If KeyHit(12) And segments>3 Then
        segments=segments-1
        If cable Then FreeEntity cable
        cable=0
    EndIf
    If KeyHit(13) And segments<24 Then
        segments=segments+1
        If cable Then FreeEntity cable
        cable=0
    EndIf
    If KeyHit(17) Then wire=Not wire
    WireFrame wire

    If cable=0 Then
        radius#=radius_steps*0.02
        cable=CreateRod(route,radius,segments,swing)
        PaintSurface GetSurface(cable,1),black
        PaintSurface GetSurface(cable,2),copper
    EndIf

    RotateEntity swing,Sin(MilliSecs()*0.1)*10,0,0

    ; 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   [ / ] : radius   - / + : sides   W: wireframe   Esc: exit"
    Text 0,20,"CreateRod(route,"+radius+","+segments+",swing)"
    Text 0,40,"Black along its length (surface 1), copper end caps (surface 2)"

    Flip

Wend

End

Index