What is the best workflow to load a lot of objects in a scene?

I’m new in this field but in my work the need to load a lot of objects (more than 40) and most of then have an animation (walking, talking, scrolling their cellphones, …), but at the moment that I load all the objects (in this case 10 for testing), the render freezes and gets slower at the moment that I add more objects.

Yes, I know that I may have a lot of mistakes but that’s why I’m here haha. Sorry for my misspelling, I’m still working on that.

I’m new in this field but in my work the need to load a lot of objects (more than 40) and most of then have an animation (walking, talking, scrolling their cellphones, …), but at the moment that I load all the objects (in this case 10 for testing), the render freezes and gets slower at the moment that I add more objects.

Yes, I know that I may have a lot of mistakes but that’s why I’m here haha. I added all objects in a JSON to load them and mesh them, but I don’t know how to optimize this to not feeze my render.

all models here, I just wrote one for this example.
obj -> url, txt -> textures, action -> true (has animation), false (it’s a static object).

    var models = 
    { scSubj01:
            { obj: man_nodding_obj, txt: man_walking_txt, mesh: null, name: "scSubj01", mixer: null, anims: null, x: -91.67, y: 0, z: -1132.19, rot: leftV, scale: 1.7, action: true, promise: null}
    }

This is the method that it’s called from the main js file, and returns the json variable with their mesh, mixer and anims loaded, the reason that I used promises here it was to preload the objects but I didn’t know the right way to use them for this example

addNewSubject()
    {
		let self = this;
		let models = Models.getModels();
		
		for( var model in models)
		{
			var txt = null;
			(function (key) 
			{
				let promise_obj = new Promise( resolve => 
					{
						self.loader.load(models[key].obj, function (object)
						{
							if (models[key].txt != null) { txt = new THREE.TextureLoader().load(models[key].txt); } 
							
							object.traverse( function (child) {
								if (child.isMesh)
								{
									child.castShadow = true;
									child.receiveShadow = true;
									if (txt != null) { child.material.map = txt; }
								}
							});
							

							if (models[key].action && object.animations[0] != null)
							{
								models[key].mixer = new THREE.AnimationMixer(object);
								models[key].mixer.timeScale = 4;
								models[key].anims = object.animations[0]; 
								const act = models[key].mixer.clipAction(models[key].anims);
								act.play();
							}
							
							models[key].mesh = object;
							object.position.set(models[key].x, models[key].y, models[key].z);
							const size = models[key].scale;
							object.scale.set(size, size, size);
							object.rotation.set(0, models[key].rot, 0);
							self.scene.add(object);
						});  //, resolve
					});
				models[key].promise = promise_obj;
				
			})(model);
		}
		
		return models; //return models to updated them in animate function
	}

I would recommend using your browser’s developer tools to profile this: try to identify what functions are responsible for the freeze that you see. https://developers.google.com/web/updates/2016/12/devtools-javascript-cpu-profile-migration

It could be the loading itself (some formats, like OBJ, are very slow to parse), or could be the first frame of rendering after the objects are loaded. The first time an object is rendered, its materials are compiled and texture and vertex data uploaded to the GPU. That takes time, and uploading all objects at once will take even longer.

Thant you, I’ll check that, I’m loading the objects with FBXLoader.
So, as it takes time to upload all objects, is there a way to load all objects in an optimize way or I just need to uses promises to preload them and then add them in the scene?

You’ll need to find out whether the slow thing is parsing or GPU upload. Those two things would be optimized in different ways. If you can share a live demo others can help you figure that out.

I’ll check that, and here is a demo
https://6ea0b8268d0f.ngrok.io
In html directory