b3d-biped
Animated humanoid character controller. Loads a GLB model with skeletal animations
and drives it via ControlInput.
Demo
import { b3d, b3dBiped, b3dLight, b3dSkybox, b3dGround, label3d, select3d, slider3d } from 'tosijs-3d'
import { elements, tosi } from 'tosijs'
const animations = [
'idle', 'walk', 'run', 'sneak', 'climb', 'walkBackwards',
'jump', 'running-jump', 'salute', 'wave',
'tread-water', 'swim', 'talk', 'look', 'dance', 'pickup', 'pilot',
]
const { bipedDemo } = tosi({
bipedDemo: {
animation: 'idle',
speed: 1,
}
})
const biped = b3dBiped({
url: '/omnidude.glb',
animation: bipedDemo.animation,
animationSpeed: bipedDemo.speed,
})
preview.append(
b3d(
{
scenePanel: () => [
label3d({ text: 'Biped' }),
select3d({ label: 'animation', value: bipedDemo.animation, options: animations }),
slider3d({ label: 'speed', value: bipedDemo.speed, min: 0, max: 2, step: 0.1 }),
],
sceneCreated(el, BABYLON) {
const camera = new BABYLON.ArcRotateCamera(
'cam', -Math.PI / 2, Math.PI / 3.5, 2,
new BABYLON.Vector3(0, 0.5, 0), el.scene
)
camera.lowerRadiusLimit = 1.5
camera.upperRadiusLimit = 10
camera.attachControl(el.querySelector('canvas'), true)
el.setActiveCamera(camera)
},
},
b3dLight({ y: 1, intensity: 0.7 }),
b3dSkybox({ timeOfDay: 10 }),
b3dGround({ width: 10, height: 10 }),
biped,
),
)
tosi-b3d { width: 100%; height: 100%; }
Attributes
| Attribute | Default | Description |
|---|---|---|
url |
'' |
GLB model URL |
animation |
'' |
Current animation state name |
animationSpeed |
1 |
Playback speed multiplier (0–2) |
player |
false |
Whether this biped receives input |
cameraType |
'none' |
'follow', 'xr', or 'none' |
turnSpeed |
180 |
Degrees per second |
forwardSpeed |
2 |
Walk speed |
runSpeed |
5 |
Sprint speed |
backwardSpeed |
1 |
Backward speed |
cameraHeightOffset |
1 |
Camera height above target |
cameraTargetHeight |
0.75 |
Height of the point the camera looks at |
cameraMinFollowDistance |
2 |
Closest follow distance |
cameraMaxFollowDistance |
5 |
Furthest follow distance |
Animations
The biped automatically transitions between animation states based on input:
idle, walk, run, walkBackwards, sneak, jump, swim, dance, pilot, etc.
Animation names in the GLB must match these names.
Usage
import { b3d, b3dBiped, gameController, inputFocus } from 'tosijs-3d'
document.body.append(
b3d({},
inputFocus(
gameController(),
b3dBiped({
url: '/character.glb',
player: true,
cameraType: 'follow',
initialState: 'idle',
})
)
)
)