CreateExtrusion ( profile[,depth#][,upward][,parent] )

Parameters

profile - the outline to extrude

depth# (optional) - how far to push it, greater than 0; 2 (default)

upward (optional) - True reads the outline as a plan seen from above and raises it from the ground; False pushes it back along Z (default)

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

Description

Creates a solid by pushing a profile straight back, or up from the ground, and returns its handle.

By default the outline stands in X and Y as you drew it and is pushed back along Z by depth#, centred on Z 0, with its front facing -Z towards a default camera. Use it for signs, lettering, window frames, gable walls, gears and anything cut out like a biscuit.

With upward True the outline is a plan seen from above: its x runs along +X and its y along +Z, and it rises from the ground (Y 0) to a height of depth#. Use it for houses, rooms, platforms, pillars and raised beds. The plan is not mirrored when seen from above.

Corners stay crisp, walls tile textures in world units, and the caps are filled round any holes, so an L-shaped house, a courtyard or a window frame works as well as a rectangle. The walls build the surfaces chosen with ProfileSurface and the caps the surface after the highest one used. An open outline makes walls with no caps.

A closed outline gives a closed solid that works with the CSG commands. Automatic EntityPhysics makes a static extrusion 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. A window frame, for example, moves as four bars.

A depth that is not greater than 0, a profile with no outline that has any area or length, or a handle that does not exist stops the program with a runtime error.

See also: CreateProfile, AddProfileRect, CreateLathe, CreateSweep, CreateBox.

Example

; CreateExtrusion Example
; -----------------------

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

camera=CreateCamera()
PositionEntity camera,0,9,-16
RotateEntity camera,25,0,0

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

ground=CreatePlane()
EntityColor ground,70,110,70

; An L-shaped plan in metres: 10 wide and 9 deep
plan=CreateProfile()
AddProfilePoint plan,-5,0
AddProfilePoint plan,5,0
AddProfilePoint plan,5,6
AddProfilePoint plan,-1,6
AddProfilePoint plan,-1,9
AddProfilePoint plan,-5,9

; A turntable, so the building can be seen from every side
turntable=CreatePivot()

upward=True
depth_steps=3
house=0

While Not KeyDown(1)

    ; U switches between a plan raised from the ground and a shape pushed back along Z
    If KeyHit(22) Then
        upward=Not upward
        If house Then FreeEntity house
        house=0
    EndIf
    ; [ / ] change the depth in 1 m steps
    If KeyHit(26) And depth_steps>1 Then
        depth_steps=depth_steps-1
        If house Then FreeEntity house
        house=0
    EndIf
    If KeyHit(27) And depth_steps<8 Then
        depth_steps=depth_steps+1
        If house Then FreeEntity house
        house=0
    EndIf

    If house=0 Then
        house=CreateExtrusion(plan,depth_steps,upward,turntable)
        EntityColor house,230,210,170
    EndIf

    TurnEntity turntable,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   U: upward   [ / ] : depth   Esc: exit"
    Text 0,20,"CreateExtrusion(plan,"+depth_steps+","+upward+",turntable)"
    If upward Then
        Text 0,40,"Upward: the outline is a plan seen from above, rising from the ground"
    Else
        Text 0,40,"Not upward: the outline stands up, pushed back along Z and centred"
    EndIf

    Flip

Wend

End

Index