This release introduces an experimental version of UltimateLoader that increases usability and performance.
UltimateLoader2 aims to clean up your code by using a config. By creating a config object, you can easily define your models and insert basic transform information (position, scale, and rotation) all in one place. UtlimateLoader2 will load the models, automatically apply the transform data, and add the models to the scene for you. These actions are optional, you still have control over the models once they’re loaded.
- Caching
- A single promise that accepts multiple paramaters
- Transform properties applied automatically
- Add to scene automatically
- Shared .mtl
- Easy referencing
var Models =
{
Duck: { url: 'models/Duck.glb' },
Chair: { url: 'models/chair.dae', position: '0 5 0', scale: '1 1 1', rotation: '0 0 0' },
Celeste: { url: 'models/Celeste.obj', mtl: 'models/Other.mtl', position: '0 0 5', scale: '1 1 1', rotation: '0 0 0' }
};
UltimateLoader.load(scene, Models).then(function(models)
{
console.log(Models);
});
Default: true
If a scene is passed in load() and this is set to true, the models will automatically load into the scene.
Default: true
If you specify transform properties, they'll be applied automatically.
Default: true
UltimateLoader will cache each unique model you load making subsiquent loads very quick.
Default: false
If set to true, standalone images will load onto a plane.
Default: 32
The size of standalone images when loaded onto a plan (dependant on loadImagesOnPlane)
There are multiple ways you can use the load() function.
This method gives you more options when loading. Additionally, you'll be able to access the loaded object by referencing the model name.
var Models =
{
Duck: { url: 'models/Duck.glb' },
Chair: { url: 'models/chair.dae', position: '0 5 0', scale: '1 1 1', rotation: '0 0 0' },
Celeste: { url: 'models/Celeste.obj', mtl: 'models/Other.mtl', position: '0 0 5', scale: '1 1 1', rotation: '0 0 0' }
};
UltimateLoader.load(Models).then(function(models)
{
});
Great for quick loading where you want the most control after the loading is done. You'll have to handle storing the models and automatic transformation is not available.
var array =
[
'models/Duck.glb',
'models/chair.dae',
'models/avatar_head.obj',
];
UltimateLoader.load(array).then(function(models)
{
});
The simplest load of a single model. You'll have to handle storing the model and automatic transformation is not available.
var src = 'models/avatar_head.obj';
UltimateLoader.load(src).then(function(model)
{
});
You can mix the config types in one call for whatever reason.
UltimateLoader.load(src, array, Models).then(function(models)
{
});
This is an easy way to ensure that all .obj files share a single .mtl. If an mtl property is present in a config object, that will be used instead.
UltimateLoader.load('http://example.com/mat.mtl', src, array, Models).then(function(models)
{
});
Pass in your scene so that UltimateLoader can automatically add your models to the scene.
UltimateLoader.load(scene, Models).then(function(models)
{
});
As shown in the examples above, there are a few config properties available that helps you manage the loading process.
url: 'string'
mtl: 'string'
position: {x: 0, y: 0, z: 0 } OR position: '0 0 0'
scale: {x: 1, y: 1, z: 1 } OR scale: '1 1 1'
rotation: {x: 0, y: 0, z: 0 } OR rotation: '0 0 0'
You can name your config object whatever you want. Each property inside the object is an object that specifies the information for a particular model. Each model name must be unique.
var Models =
{
Duck: { url: 'models/Duck.glb' },
Chair: { url: 'models/chair.dae', position: '0 5 0', scale: '1 1 1', rotation: '0 0 0' },
Celeste: { url: 'models/Celeste.obj', mtl: 'models/Other.mtl', position: '0 0 5', scale: '1 1 1', rotation: '0 0 0' }
};
A loader is only useful when you can access your models!
As implied in previous examples, you can access your loaded model by referencing the config object after the entire load is complete.
var Models =
{
Duck: { url: 'models/Duck.glb' },
Chair: { url: 'models/chair.dae', position: '0 5 0', scale: '1 1 1', rotation: '0 0 0' },
Celeste: { url: 'models/Celeste.obj', mtl: 'models/Other.mtl', position: '0 0 5', scale: '1 1 1', rotation: '0 0 0' }
};
UltimateLoader.load(scene, Models).then(function(models)
{
Models.Duck.position.set(0,0,0);
scene.remove(Models.Celeste);
});
Each load() call will return an array of all loaded objects in order of how they were passed into the function.
var Models =
{
Duck: { url: 'models/Duck.glb' },
};
var array =
[
'models/chair.dae'
]
UltimateLoader.load(scene, 'models/Celeste.obj', array, Models).then(function(models)
{
for (var i = 0; i < models.length; i++)
{
console.log(models[i]);
}
// Output will be:
// Celeste, chair, Duck
});
If a single model was loaded, the returned object will be readily accessible by itself.
UltimateLoader.load(scene, 'models/Celeste.obj', array, Models).then(function(model)
{
console.log(model);
// Output will be:
// Celeste
});