11. 3D Static Meshes
Importing 3D static meshes (trees, buildings, etc), setting up collisions and interactions is very easy to understand and rewarding. Whether you build them yourself or get free ones off the internet, it really spices up a 3D level. Blitz3D allows for .X, .3DS or .B3D files (usually created in advance by one of a number of 3D model creation apps). Most meshes come with an accompanying texture file that must be placed in the same location with the mesh.

Many FREE meshes can be found within the Blitz3D example folders or online (HERE and HERE).

If you haven't already downloaded the tutorial files do so now, unzip to your desktop and OPEN up lesson11.bb, functions11.bb, and loadworld11.bb (below) and RUN / LAUNCH the lesson11.bb program by pressing the ROCKET ICON

and you should see this...


Here's the CODE (NEW CODE is BOLD) with commented explanations!

lesson11.bb

; Nothing new here :)


functions11.bb

...
Function LoadRandomMeshes(mesh$, total, x1, x2, z1, z2)
   temp_mesh = LoadMesh( mesh$ )
   EntityAutoFade temp_mesh,100,110
   
; makes the objects fade into the distance
   EntityType temp_mesh, coll_objects
   
; add to collisions

   For s=1 To total
      sx#=Rnd(x1,x2) : sz#=Rnd(z1,z2)
      copied_mesh=CopyEntity( temp_mesh )
      PositionEntity copied_mesh, sx, TerrainY( land, sx, 0, sz), sz
     
 ; place randomly on Terrain
      ScaleEntity copied_mesh, Rnd(.01,.05), Rnd(.01,.05), Rnd(.01,.05)
      RotateEntity copied_mesh, 0, Rand(1,360),0
      EntityColor copied_mesh, Rand(1,200),Rand(1,200),Rand(1,200)
     
 ; randomize scaling, rotation and coloring for variety
   Next
   FreeEntity temp_mesh
End Function

...


loadworld11.bb

...
; Load SHOP Mesh
shop = LoadMesh("shop.3ds")
ScaleEntity shop, .25, .25, .25
PositionEntity shop, 0, TerrainY( land, 0, 0, 30 ), 30
; choose x, Terrain Y, and z position
EntityType shop, coll_objects

; add to collisions

; NEW Random LoadMeshes - replaces 2D tree sprites
LoadRandomMeshes("tree.b3d", 500, -250, 250, -250, 250)
...


THE CHALLENGE!!!
Create or add or replace with new meshes! Alter scaling ranges?

NEXT : Lesson 12 - Animated Meshes