Expo config plugin#
{
"expo": {
"plugins": ["@apricotjs/react-native"]
}
}The plugin:
- adds the
react-native-webgpuconfig plugin; - sets Android
minSdkVersionto at least 26 (Android 8.0) and keeps a higher value; - sets iOS
CADisableMinimumFrameDurationOnPhone, so the frame loop can run at 120 Hz on ProMotion iPhones.
Run npx expo prebuild (or make a new dev build) after adding it.
Metro: withApricot#
const { getDefaultConfig } = require("expo/metro-config");
const { withApricot } = require("@apricotjs/metro");
module.exports = withApricot(getDefaultConfig(__dirname));withApricot:
- adds
glbandgltfto the asset extensions, sorequire("./car.glb")works (the list is exported asASSET_EXTENSIONS); - resolves every
threeandthree/webgpuimport to the same build, so the bundle holds one copy of three.
If your config has its own resolver, keep it. withApricot calls it for every other import.
A .gltf must be self-contained, with its buffers and images embedded. A separate .bin file is not found at runtime. Convert the model to .glb with apricot-models.
apricot-models CLI#
The CLI comes with @apricotjs/metro. Before the first run, install its model tools as dev dependencies. The CLI tells you if they are missing.
npm install --save-dev @gltf-transform/core @gltf-transform/extensions @gltf-transform/functions draco3dgltf meshoptimizerThen run it with npx. withApricot does not need them.
Optimise#
npx apricot-models <file-or-folder>... [-o <out-folder>]Each .glb or .gltf input becomes <name>.glb in the output folder. For a folder, every model inside is converted.
The command:
- removes duplicate and unused data and welds vertices;
- quantises meshes (
KHR_mesh_quantization) for smaller files that need no decoder at runtime; - decodes Draco and meshopt input, which the app can't load;
- rejects KTX2 and Basis textures with an error (use PNG or JPEG);
- converts a
.gltfwith a separate.bininto one.glb; - prints the size before and after, and budget warnings.
Inspect#
npx apricot-models inspect <file> [--json]Prints a model's contents and budget warnings:
- triangles;
- parts, heaviest first, with their names, triangles and materials;
- materials, with how many parts use each;
- textures, with size, type and bytes;
- animation clip names.
<Model materials>, joints, animations and model kits select by these names. --json prints a ModelSummary plus warnings.
Budgets#
For one hero model on a mid-range phone:
| Budget | Value |
|---|---|
| Triangles | 150,000 |
| Texture side | 2048 px |
| Texture memory | 8 MB total |
Beyond these, the CLI warns. The model still works but may cost frame rate or memory.
Each separate mesh also costs about 80 µs per frame on a mid-range phone. Merge parts in Blender where you can, and use <Instances> for repeats.
Node API: @apricotjs/metro/models#
import { BUDGET, budgetWarnings, createModelIO, optimizeModel, summarize } from "@apricotjs/metro/models";| Export | Description |
|---|---|
optimizeModel(input, { quantize? }) |
Promise<{ bytes, report: { before, after, byteLength, warnings } }>. input is .glb bytes or a gltf-transform Document |
summarize(document) |
A ModelSummary: meshes, materials, textures, vertices, triangles, parts, material names, texture list, animations, extensions |
createModelIO() |
Promise<NodeIO>: a gltf-transform NodeIO with every extension and the Draco and meshopt decoders. Await it |
BUDGET |
{ triangles: 150000, textureSide: 2048, textureBytes: 8388608 } |
budgetWarnings(summary) |
Warning strings for a summary over budget |