I became aware of InstancedBufferGeometry while doing my research yesterday afternoon. At the moment I create a new bufferGeometry and a new mesh for each child in my quadtree. The material is always a clone because each child needs the same material structure but with its own data. Roughly comparable to a class but several objects of this with different data. And then I also address each child in the update function in order to use uniforms, e.g. updating the time etc. If I generate many children and create a mesh for each child, this results in a corresponding number of drawcalls.
Since the basic structure of the geometry, meshes, materials is the same for each child, only the data, e.g. positions are different, because each child has its own vertices (always the same number) but with different values, I wonder whether InstancedBufferGeometry would be suitable for reducing drawCalls. After all, I don’t want to use up valuable reserves and then later only have a little leeway for other objects in the scene.
For the creation of each new child I call this. The material from the params is a clone in each case. And the group is just that, a “group = new THREE.Group();” in the main to which every mesh of every child is passed here with every call. And the group is then passed to the scene in the main.
Init(params) {
this.geometry_ = new THREE.BufferGeometry();
this.mesh_ = new THREE.Mesh(this.geometry_, params.material);
this.params_.group.add(this.mesh_);
}
RebuildMeshFromData(data) {
this.geometry_.setAttribute('position', new THREE.Float32BufferAttribute(data.positions, 3));
this.geometry_.setAttribute('vindex', new THREE.Int32BufferAttribute(data.vindices, 1));
this.geometry_.setIndex(new THREE.BufferAttribute(data.indices, 1));
this.geometry_.attributes.position.needsUpdate = true;
this.geometry_.attributes.vindex.needsUpdate = true;
this.mesh_.material.uniforms.wMatrix.value = data.worldMatrix;
this.mesh_.material.uniforms.resolution.value = data.resolution;
this.mesh_.material.uniforms.offset.value = data.offset;
this.mesh_.material.uniforms.width.value = data.width;
this.mesh_.material.uniforms.lod.value = this.params_.lod;
this.mesh_.material.uniformsNeedUpdate = true;
}
Are my thoughts in the right direction if I imagine the use of InstancedBufferGeometry or InstancedMesh because of the same structure of each child, only with different data for the uniforms of each child?