var manager = new THREE.LoadingManager();
var loader = new THREE.GLTFLoader(manager); // You need to download this JS file separately
var cache = {};
// Add manager listeners
manager.onLoad = function() { /* Do something */ }
manager.onProgress = function() { /* Do something */ }
// Load all your models from your JSON file (using jQuery) and clone theme for later
$.getJSON("./json/assets.json", function(json) {
for (const [key, value] of Object.entries(json)) {
loader.load(value.url, function(gltf) {
// Define model using the loaded scene
var model = gltf.scene;
model.name = key;
model.animations = gltf.animations;
model.mixer = new THREE.AnimationMixer(model);
model.clips = [];
// Add all animations (for nested models)
for (var i = 0; i < model.animations.length; i++) {
model.clips.push(model.mixer.clipAction(model.animations[i]));
// (optional) Create animation functions for easier playback
model.animation = {
play: function() { for (var i = 0; i < model.clips.length; i++) { model.clips[i].play(); }},
reset: function() { for (var i = 0; i < model.clips.length; i++) { model.clips[i].reset(); }}
// Cache objects for later
cache[key] = model;
var clock = new THREE.Clock();
var myModel = THREE.SkeletonUtils.clone(cache['my-model-1']);
// This function would be called by your game render loop
function updateAnimation() {
var delta = clock.getDelta();
myModel.mixer.update(delta);
}