CreatePipe ( spline[,radius#][,thickness#][,segments][,arc#][,parent] )

Parameters

spline - spline to follow

radius# (optional) - outer radius; 0.1 (default)

thickness# (optional) - thickness of the wall, measured in from the outside, up to the radius; 0.01 (default)

segments (optional) - segments round the pipe for a full turn, from 3 to 256; 12 (default)

arc# (optional) - how much of the circle to build, in degrees, more than 0 and up to 360; under 360 opens it into a trough; 360 (default)

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

Description

Creates a hollow pipe, or an open trough, along a spline and returns its handle.

Use it for pipes, tunnels and tubes you can look into and, with an arc# under 360, for water slide flumes, gutters, half-pipes and channels. The part kept is centred on the bottom of the cross-section, so a trough always opens upwards and a rider placed with PositionOnSpline sits in the middle of it. Roll on the spline's points banks it into bends.

The surfaces follow CreateTube: 1 is the outside, 2 the inside, and 3 the ends, including the rims along a trough's edges, so the inside and outside of a slide can be painted differently. A texture wraps once round the pipe, with U from 0 to 1, and V runs along it in world units, so a 40 m slide repeats its texture rather than stretching one copy along its length.

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 pipe 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 pipe 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: CreateRod, CreateRibbon, CreateTube, PositionOnSpline, SplineDetail, SplineFollowGround.

Example

; CreatePipe Example
; ------------------

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

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

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

; A water slide spiralling down round a tower
route=CreateSpline()
For index=0 To 8
    angle#=index*60
    AddSplinePoint route,4*Cos(angle),7-index*0.8,4*Sin(angle),-15
Next

tower=CreateCylinder(16)
ScaleEntity tower,1,4,1
PositionEntity tower,0,4,0
EntityColor tower,200,190,170

; Surfaces: 1 outside, 2 inside, 3 ends and trough rims
Dim brushes(3)
brushes(1)=CreateBrush(250,130,40)
brushes(2)=CreateBrush(200,235,255)
brushes(3)=CreateBrush(255,255,255)

; A rider sliding down the inside
rider=CreateSphere(12)
ScaleEntity rider,0.25,0.25,0.25
EntityColor rider,240,60,60

arc_steps=7
slide=0
distance#=0

While Not KeyDown(1)

    ; [ / ] open or close the trough
    If KeyHit(26) And arc_steps>4 Then
        arc_steps=arc_steps-1
        If slide Then FreeEntity slide
        slide=0
    EndIf
    If KeyHit(27) And arc_steps<12 Then
        arc_steps=arc_steps+1
        If slide Then FreeEntity slide
        slide=0
    EndIf

    If slide=0 Then
        ; Outer radius 0.6 m with an 8 cm wall; under 360 degrees it opens at the top
        arc#=arc_steps*30
        slide=CreatePipe(route,0.6,0.08,24,arc)
        For s=1 To CountSurfaces(slide)
            PaintSurface GetSurface(slide,s),brushes(s)
        Next
    EndIf

    ; Slide down, then start again at the top
    distance=distance+0.1
    If distance>SplineLength(route) Then distance=0
    PositionOnSpline rider,route,distance
    ; Drop to the bottom of the inside wall
    MoveEntity rider,0,-0.27,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   [ / ] : open or close the trough   Esc: exit"
    Text 0,20,"CreatePipe(route,0.6,0.08,24,"+arc+")"
    If arc<360 Then
        Text 0,40,"An open flume: the "+arc+" degrees kept are centred on the bottom"
    Else
        Text 0,40,"A closed tube: the rider is hidden inside"
    EndIf

    Flip

Wend

End

Index