Skip to content

Video as code: canvas scenes rendered with WebCodecs in headless Chrome, a review viewer, and agent skills that build the video from your references.

7.3 KB
Raw Blame

3D assets: objects, characters, textures

Offer the two paths first (the table in SKILL.md), then build. Both start the same way: get the shape right against the references before any material or render, as the motlab skill's references/blender.md describes (real model if there is one, otherwise distance functions, check shots next to the reference from several angles).

All numbers below are from the test laptop (RTX 3060 Laptop, Blender 5.2, Chrome with ANGLE on Direct3D 11), on a test mug of two parts with 194,646 vertices.

Light path: Python and Chrome

  1. Write the shape as distance functions with the motlab skill's mesh_from_sdf.py (copy the pattern of its example_scene.py mesh): one .npz per part that has its own colour.
  2. Export: python scripts/mesh_export.py <asset dir> <asset> body.npz:#E8743B:0.3 base.npz:#8C735F:0.8 writes <asset>.glb and <asset>.obj + .mtl. Each part is file:#colour[:roughness[:metalness]]. --smooth 20 (the default) relaxes the surface like the Blender path's smooth modifier; use 0 for small sharp parts. 2.9 s for the mug, 9.3 MB GLB.
  3. PNGs: copy templates/model.html next to the GLB, set MODEL, and run motlab stills model.html turntable 0 1 2 3 4 5 6 7 --scale 2. View i is at t = i, eight views round the object, lit from the upper left of the camera in every view. Four 1024 px views took 2.6 s.

Limits: no textures, no FBX, no rig, one flat material per part. Anything more is the main path.

Main path: Blender

A build.py per asset, run with no window: blender -b -P build.py -- <asset dir>. It puts the motlab skill's scripts/blender and this skill's scripts/blender on sys.path, builds the objects with kit.py, and calls asset3d.py:

import sys, os
HERE = os.path.dirname(os.path.abspath(__file__)); SKILLS = r'<engine>/skills'   # from `motlab --help`
sys.path[:0] = [HERE, os.path.join(SKILLS, 'motlab', 'scripts', 'blender'), os.path.join(SKILLS, 'motlab-assets', 'scripts', 'blender')]
import bpy, math, kit, asset3d as A
from mathutils import Euler
OUT = os.path.abspath(sys.argv[sys.argv.index('--') + 1])
kit.fresh()
glaze = kit.mat('glaze', (0.9, 0.35, 0.15), 0.25, coat=0.5)       # any node tree works: noise, bump, layered paint
root = kit.empty('mug'); root.rotation_quaternion = Euler((math.pi / 2, 0, 0)).to_quaternion()   # SDF meshes are y-up
body = kit.load_npz(os.path.join(HERE, 'mesh', 'body.npz'), glaze, root)
A.bake(body, os.path.join(OUT, 'textures'), size=2048)            # body_basecolor.png, body_roughness.png, body_normal.png
A.export([root], OUT, 'mug')                                      # mug.glb, mug.fbx, mug.obj + mug.mtl
A.turntable([body], os.path.join(OUT, 'turntable'), views=8, width=2048, samples=64)
  • bake(obj, out, size, maps) applies the modifiers, unwraps with Smart UV Project if the mesh has no UVs, bakes each map from all of the object's materials, saves <object>_<map>.png, and gives the object one new material that uses the maps. Maps: basecolor, roughness, normal, ao, emission. Cycles cannot bake metalness, so the highest metalness of the old materials is kept as one value. Two objects, three 1024 px maps each: 7.5 s. A normal map only carries detail the material adds (bump, noise); a smooth mesh bakes a flat normal map.

  • export(objs, out, name) writes GLB and FBX with the textures inside, and OBJ + MTL pointing at the texture files where they are. Children of the given objects come along. 1.2 to 2.3 s over two runs; the mug was 11.6 MB GLB, 7.5 MB FBX and 26.1 MB OBJ.

  • turntable(objs, out, views, width, samples, lens, elevation, light, world): square, transparent PNGs from the front round the object; the key light turns with the camera. Use the kit's light and camera tokens. Four 1024 px views at 32 samples: 16.5 s.

  • Check the exports in a clean Blender, then through three.js:

    blender -b --factory-startup -P scripts/blender/asset3d.py -- check mug.glb mug.fbx mug.obj
    motlab stills model.html check 0 2 --scale 1      (MODEL = 'mug.glb')
    

    check prints meshes, vertices, materials, images and size per file; all three should agree (the GLB counts a few more vertices because glTF splits vertices at UV seams). On the mug, all three came back with 2 meshes, 2 materials and 6 images.

Size and detail

Distance-function meshes are dense. For a GLB that loads fast in a scene, add a Decimate modifier (ratio 0.2 to 0.5) before bake and compare the turntable before and after. If the user wants smaller files still, glTF Transform (npx @gltf-transform/cli optimize in.glb out.glb, MIT) compresses geometry and textures; it downloads from npm, so ask first, and check the result in model.html, as a compressed GLB needs the matching decoder.

Characters

  • Stylised characters (a mascot, a toy-like figure): distance functions per body part, joined smoothly where they should read as one surface and kept separate where they move. Start from the 2D character's turnaround.svg so both versions match.
  • Human characters: MPFB 2 (the MakeHuman plugin for Blender; code GPL, its assets CC0) if check_blender.py finds it. It builds a human with a skeleton. Not tested in this skill yet; read its documentation and render check poses before promising a result.
  • Rigs: an armature parented to the mesh exports to FBX and GLB. Rigify ships with Blender but is off by default (check_blender.py shows it). Turn it on inside build.py with addon_utils.enable('rigify', default_set=True) and run Blender with --factory-startup, so the user's saved preferences stay as they were; without default_set=True its generate step fails on missing parameters. Export only the deform bones: export_scene.gltf(..., export_def_bones=True, export_animations=True) and export_scene.fbx(..., use_armature_deform_only=True, bake_anim=True, add_leaf_bones=False). On a test figure (the human metarig, 706 bones of which 160 deform, a mesh bound with automatic weights, a 48-frame wave): 13 s, a 1.8 MB GLB and a 2.4 MB FBX. Re-imported in a clean Blender, both played the animation and followed a posed upper arm, and the GLB played through mixer.setTime(t) in template-three.html with the same stills both ways. Re-import and pose a bone like this before handing a rig over.

Textures on their own

A material for the kit (a brand plastic, a paper, a fabric) is a build.py that makes the node tree on a plane or a sphere, bakes it with bake(..., maps=('basecolor', 'roughness', 'normal')) at 2048 or 4096 px, and renders one turntable view as the preview. For a tileable texture, bake on a plane with a 0 to 1 UV square and check the edges by tiling the base colour 3x3 on sheet.py. HDRIs for lighting can come from Poly Haven (CC0); credit them in kit.json.

Formats

  • GLB: the one to use in motlab (template-three.html) and on the web. Metres, y-up, PBR materials and textures inside one file.
  • FBX: for other 3D programs and game engines. Textures embedded. Scale written with FBX_SCALE_ALL, so it opens at the right size in Blender; check another program's import scale if the user names one.
  • OBJ + MTL: the widest support, but no rig or animation, and PBR only through the Pr/Pm extension that Blender writes and reads. Keep the texture files next to it when copying.