With a time interruption I reprogrammed the showroom.
The new approach is to do completely without groups and instead create a separate geometry and mesh for each material used. This only makes sense if the parts are immobile after creation. This is the case with the floors, ceilings, walls, frames, etc. of a showroom.
With .push arrays for the vertices and uv’s are filled.
let vt = []; // vertices
let uv = [];
for ( let i = 0; i < m.length; i ++ ) {
m[ i ].unshift( i ) // insert index at the front of the material definition, used for vt, uv index
vt.push( [] ); // vertices array for each material
uv.push( [] ); // uv's array for each material
}
When the individual components are created, they are broken down according to the material. For this purpose the material index is determined.
Example
vt[ getMatIndex( cp, i, mi, mNo ) ].push( x1,y1,z1, x2,y2,z2, x3,y3,z3, x1,y1,z1, x3,y3,z3, x4,y4,z4 );
uv[ getMatIndex( cp, i, mi, mNo ) ].push( u1, v1, u2, v2, u3, v3, u1, v1, u3, v3, u4, v4 );
The completely defined geometries and meshes are then created in a loop.
let geometries = [];
let meshes = [];
for ( let i = 0; i < m.length; i ++ ) {
if ( vt[ i ].length > 0 ) { // only for defined materials, not for material Empty
geometries[ i ] = new THREE.BufferGeometry();
geometries[ i ].setAttribute( 'position', new THREE.BufferAttribute( new Float32Array( vt[ i ] ), 3 ) );
geometries[ i ].setAttribute( 'uv', new THREE.BufferAttribute( new Float32Array( uv[ i ] ), 2 ) );
geometries[ i ].computeVertexNormals();
meshes[ i ] = new THREE.Mesh( geometries[ i ], getMaterial( m[ i ] ) );
scene.add( meshes[ i ] );
} else {
geometries[ i ] = null;
meshes[ i ] = null;
}
}
The effort was obviously worth it, it runs much better now with much more elements and more materials in the showroom.
renderer.info.render results in maximum values, if Gltf/Obj models are displayed in the mirror.
calls: 45, triangles about 42000, points: 0, lines: 84
Unfortunately, I can’t explain it because of my very limited overview of the internal workings of three.js/ WebGL, but obviously it has something to do with the grouping as I only suspected. Because I have extended the number of materials a bit, currently 21 materials. So I have 21 meshes with one material each.
At the showroom itself there are still some finer details to be done.
Translated with www.DeepL.com/Translator (free version)