|
profile - the cross-section spline - the path to draw it along caps (optional) - True closes the ends of closed outlines on an open spline (default); False leaves them open parent (optional) - parent entity for the new mesh; 0 for none (default) |
|
Creates a mesh by drawing a profile along a spline and returns its handle. Any cross-section can follow any path: kerbs round a pavement, skirting boards and mouldings round a room, shaped rails, crash barriers, ducts and gutters. CreatePipe, CreateRod and CreateRibbon are ready-made sweeps of common cross-sections. The profile's x and y become the path's right and up, as seen by a rider facing along it, and the profile's 0,0 lies on the path. Roll and scale on the spline's points bank and size the cross-section. Corner points mitre it, so a moulding keeps its thickness round a room's corners. Walls build the surfaces chosen with ProfileSurface. caps closes the ends of closed outlines on an open spline, on the surface after the highest one used; a closed spline has no ends. V runs along the path in world units, and U round the cross-section follows its perimeter in world units. A sweep is a closed solid when its outlines are closed, its ends are capped or its spline is a loop, and it neither folds nor crosses itself. 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 sweep 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 profile's lowest point rests on the ground, sunk slightly into it, and the sweep is rebuilt as the ground changes. The spline must have at least two distinct points, and the profile must have an outline with some area or length. These and handles that do not exist stop the program with a runtime error. See also: CreateProfile, CreateSpline, CreatePipe, CreateExtrusion, ProfileSurface, SplineFollowGround. |
; CreateSweep Example
; -------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
camera=CreateCamera()
PositionEntity camera,0,2.5,-8
RotateEntity camera,15,0,0
light=CreateLight()
RotateEntity light,45,45,0
ground=CreatePlane()
EntityColor ground,70,110,70
; A crash barrier's cross-section: an I-beam 30 cm wide and 60 cm tall
beam=CreateProfile()
For index=0 To 11
Read x#,y#
AddProfilePoint beam,x,y
Next
Data -0.15,0
Data 0.15,0
Data 0.15,0.08
Data 0.04,0.08
Data 0.04,0.52
Data 0.15,0.52
Data 0.15,0.6
Data -0.15,0.6
Data -0.15,0.52
Data -0.04,0.52
Data -0.04,0.08
Data -0.15,0.08
closed=True
caps=True
barrier=0
While Not KeyDown(1)
; C opens or closes the loop, P switches the end caps of an open barrier
If KeyHit(46) Then
closed=Not closed
If barrier Then FreeEntity barrier
barrier=0
EndIf
If KeyHit(25) Then
caps=Not caps
If barrier Then FreeEntity barrier
barrier=0
EndIf
If barrier=0 Then
; A rectangle of corner points, so each corner is mitred sharply
route=CreateSpline(closed)
AddSplinePoint route,-4,0,-2.5,0,1,True
AddSplinePoint route,4,0,-2.5,0,1,True
AddSplinePoint route,4,0,2.5,0,1,True
AddSplinePoint route,-4,0,2.5,0,1,True
; The profile's x and y become the path's right and up
barrier=CreateSweep(beam,route,caps)
FreeSpline route
EntityColor barrier,200,200,210
EndIf
TurnEntity barrier,0,0.2,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 C: closed loop P: end caps Esc: exit"
Text 0,20,"CreateSweep(beam,route,"+caps+") closed spline: "+closed
If closed Then
Text 0,40,"A closed loop has no ends, so caps make no difference"
Else
Text 0,40,"An open barrier: look at its ends with and without caps"
EndIf
Flip
Wend
End