Resources
Resources are created in the core and referenced by numeric IDs in the host.
Geometry
- Primitive geometry is generated by the core.
- Custom geometry uses buffer uploads.
ts
const geoId = createGeometry(WINDOW_ID, {
type: 'primitive',
shape: 'cube',
});
For custom geometry, upload buffers with uploadBuffer() and reference them in GeometryPrimitiveEntry.
Textures
Textures can be created from solid colors or uploaded buffers.
ts
const texId = createTexture(WINDOW_ID, {
source: { type: 'color', color: [0.8, 0.2, 0.1, 1] },
srgb: true,
});
For image data, upload a buffer and use source: { type: 'buffer', bufferId }.
Materials
Materials reference textures and define shading options.
ts
const matId = createMaterial(WINDOW_ID, {
kind: 'standard',
options: {
type: 'standard',
content: {
baseColor: [1, 1, 1, 1],
baseTexId: texId,
baseSampler: 'linear-clamp',
surfaceType: 'opaque',
flags: 0,
},
},
});
Models
Models connect geometry + material and can be attached to entities.
ts
createModel(WINDOW_ID, entityId, {
geometryId: geoId,
materialId: matId,
});
Resource Lifecycle
- Use
createMaterial/createGeometry/createTextureto allocate IDs. - Use
disposeMaterial/disposeGeometry/disposeTexturewhen finished. - Resources are owned by the world they were created in.
Documentation Vulfram Core