Render delays on multiple BoxBufferGeometries with 6 materials

In my application I have 70 THREE.BoxBufferGeometries created, and as each BBG has different size, each side has a different texture, in the sense that the image used is the same but map.rotation, map.repeat and map.offset varies.

Basically, the ‘draw’ function below is executed 70 times…

loadingManager performs apparently well, and fires when the images are loaded (caching enabled).

But there is a delay of, im my specific case, 2.5 sec between loadingManager finishes and the scene is rendered.

How can I debug or find the source of this delay.
Alternatively, is there a ‘three.scene.onLoad’ event?

----- code excerpt ----

var loadingManager = new THREE.LoadingManager();

loadingManager.onStart = function ( url, itemsLoaded, itemsTotal ) {

loadingManager.onLoad = function ( ) {

function draw(x,y,z) {
var geometry = new THREE.BoxBufferGeometry( x, y, z)
for (var i=0;i<6;i+=1) {
new THREE.MeshBasicMaterial({
name: _materialcodes[i],
map: new THREE.TextureLoader(loadingManager).load(’/image/e/512x512/’+_materialcodes[i]+’.png’)})

materials.forEach(function(mat) { = THREE.sRGBEncoding; = 16; = = THREE.MirroredRepeatWrapping 50Math.random(), 50Math.random() );


var mesh= new THREE.Mesh(geometry , materials );
var edges = new THREE.EdgesGeometry( geometry )
var line = new THREE.LineSegments( edges, new THREE.LineBasicMaterial( {color: 0x000000,linewidth: .1} ) );
var _g=new THREE.Group
_g.add(mesh, line)
return _g

Without doing a performance analysis its hard to specific the root cause but I feel the number of texture uploads is responsible for the performance problems.

In general, you should load the textures only ones and not per invocation of draw() and then just clone the textures for your each material. Besides, you only need a single instance of TextureLoader.

Unfortunately, even with those changes the performance won’t be much better because the engine has currently a design limitation that prevents a more efficient texture upload when using shared images. We hope to resolve this issue with the following PR: WebGLTextures: Avoid unnecessary texture uploads. by Mugen87 · Pull Request #17949 · mrdoob/three.js · GitHub

In any event, you can also try to work with ImageBitmapLoader instead which will mitigate the decode overhead.

Thanks for your prompt reply! Much apprecited.
I’ll apply your suggestions in my code.

Is there a possibility to have some kind of a loading screen while rendering is in progress?


Loading screens are possible, but three.js does not provide them. You will probably want to use normal HTML/CSS made with whatever web development tools you prefer.