Panda Manual > Using Models in Your Program

Using Models in Your Program

There are two ways to get a Panda model into a BambooBasic program:

.bb3d fileBambooBasic code (.bam)
Howb2dLoadMesh("Media/model.bb3d")Include "Model.bam"
Files to shipthe .bb3d and its texturenone (the texture, if it has one)
Webloads after the program starts: wait for itthere straight away
Animationpose frames and clipsskeleton (and you can turn joints from code) and/or frames
Drawingyour code (copy one of the examples)your code, or the ready-made _Draw
Joint positionsnoyes (_JointPoint ...)
Big modelsfinebig source files, slower builds (use Packed)
Change the modelreplace the fileexport again and rebuild

The code export has its own page: BambooBasic Code Export. This page is about .bb3d.


How a .bb3d is drawn

BambooBasic draws 3D with its 2D commands and a depth buffer - see 3D in 2D. The runtime stores the mesh; your program reads it and draws each face. The usual shape of a program:

  1. Load it once: mesh = b2dLoadMesh("Media/crate.bb3d"). On the web this finishes later: wait until b2dMeshFaceCount(mesh) > 0 before reading it.
  2. Read the faces once into arrays - they never change: for each face, b2dMeshFaceVert(mesh, f, corner) (corners 0 to 3; a triangle repeats its last corner), b2dMeshFaceU/V(mesh, f, corner) for textured models, b2dMeshFaceR/G/B(mesh, f) for coloured ones. b2dMeshTexture(mesh) gives the texture as an image (0 if none).
  3. Every frame: get the vertices - b2dMeshCopyVertsX/Y/Z(mesh, array) fill your arrays (after b2dMeshAnimate for an animated model) - then turn and project them, and draw each face with b2dDrawImageQuadDepthUV (textured) or b2dSetColor + b2dDrawQuadDepth (coloured).
mesh = b2dLoadMesh("Media/crate.bb3d")
nv = b2dMeshVertCount(mesh)
nf = b2dMeshFaceCount(mesh)
tex = b2dMeshTexture(mesh)
For f = 0 To nf - 1
    For c = 0 To 3
        fvi[f * 4 + c] = b2dMeshFaceVert(mesh, f, c)
        fu[f * 4 + c] = b2dMeshFaceU(mesh, f, c)
        fv[f * 4 + c] = b2dMeshFaceV(mesh, f, c)
    Next
Next
; ... then every frame:
b2dMeshCopyVertsX(mesh, mvx)
b2dMeshCopyVertsY(mesh, mvy)
b2dMeshCopyVertsZ(mesh, mvz)
; turn + project mvx/mvy/mvz into screen x, y and depth, then for each face:
b2dDrawImageQuadDepthUV(tex, x0, y0, d0, u0, v0, x1, y1, d1, u1, v1, x2, y2, d2, u2, v2, x3, y3, d3, u3, v3)

Complete, working programs to copy from, in examples\BambooRuntime\26 - 3D in 2D (each with web versions):


Animation from a .bb3d

To play clip c at a time in seconds: position = seconds × FPS; the whole part (wrapped round the clip's frame count) picks frame A, the next frame (wrapping to the first) is frame B, and the fraction is t. MeshAnimate.bam does exactly this.


Getting it the right size and the right way round

< BambooBasic Code Export   |   Contents   |   Keys and Mouse >