Panda Manual > Using Models in Your Program
Using Models in Your ProgramThere are two ways to get a Panda model into a BambooBasic program:
| .bb3d file | BambooBasic code (.bam) | |
| How | b2dLoadMesh("Media/model.bb3d") | Include "Model.bam" |
| Files to ship | the .bb3d and its texture | none (the texture, if it has one) |
| Web | loads after the program starts: wait for it | there straight away |
| Animation | pose frames and clips | skeleton (and you can turn joints from code) and/or frames |
| Drawing | your code (copy one of the examples) | your code, or the ready-made _Draw |
| Joint positions | no | yes (_JointPoint ...) |
| Big models | fine | big source files, slower builds (use Packed) |
| Change the model | replace the file | export again and rebuild |
The code export has its own page: BambooBasic Code Export. This
page is about .bb3d.
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:
mesh = b2dLoadMesh("Media/crate.bb3d"). On the web this
finishes later: wait until b2dMeshFaceCount(mesh) > 0 before reading it.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).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):
MeshLoad.bam - load and spin a textured model.MeshAnimate.bam - play an animated model's clip.MeshGLB.bam - a bigger animated model (converted from a .glb).MeshColour_web.bam - a model drawn in its face colours, with simple lighting.b2dMeshFrameCount(mesh) - how many frames.b2dMeshClipCount(mesh), and for each clip b2dMeshClipName,
b2dMeshClipStart, b2dMeshClipFrames and b2dMeshClipFPS - the
clips you made in Panda.b2dMeshAnimate(mesh, frameA, frameB, t) - blends two frames (t from 0
to 1); then b2dMeshCopyVertsX/Y/Z give you the blended vertices.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.
.bb3d and its texture into your program's Media folder (or
wherever you load from). On the web, the Media folder is copied into the web output for
you.