-
Notifications
You must be signed in to change notification settings - Fork 4
Models
The Models library is meant to ease loading, storing, and getting 3D models. The existing Three.js model loaders work well, but do not support promises or async/await. Additionally, loading many models can be cumbersome, and loading models when they're needed can be slow.
The Models library is a singleton instance, meaning you'll need to call Models.get()
to access it.
Before using your models, ERA loads and stores them in a "storage" mechanism for easier access by the user later. There are a couple of ways to load your 3D Models:
Many Models
If you want to have a set (or all) of your models loaded at once, say, before starting the render loop, you can call
await Models.get().loadAllFromFile('path/to/models.json');
Where models.json
is a file containing a manifest of all your models:
{
"example": {
"scale": 1,
"extension": "obj"
}
}
Individual Model
If you want to load a single model, you can call
const model = await Models.get().load(directory, name, options);
After your models have been loaded, you'll want to access them and load them into your scene. To do this, call
const mesh = Models.get().createModel(name);
This is a synchronous function, as ERA simply creates a clone of 3D model in memory. A clone is created in order to prevent accidentally using the same mesh instance for multiple entities.
- The ERA Models library only supports
obj
andgltf
models. New model formats can be supported easily, just send a PR.