Question about fromDirectGeometry function of BufferGeometry

I’m reading the source code of Three.js, and I cannot understand the fromDirectGeometry function in core/BufferGeometry.js .
The following code from here:

if ( geometry.indices.length > 0 ) {

   var TypeArray = arrayMax( geometry.indices ) > 65535 ? Uint32Array : Uint16Array;
   var indices = new TypeArray( geometry.indices.length * 3 );
   this.setIndex( new BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );


So what’s the type for DirectGeometry.indices? arrayMax implies indices should be an array of number, however the copyIndicesArray function of class BufferAttribute (source)requires argument to be Face3 or Triangle liked data (with property a, b, c).

It is an array of Face3 objects. Since DirectGeometry.fromGeometry() creates a non-indexed geometry, the indices array is always empty. You can easily check this with the following demo. Just set a break point at the start of BufferGeometry.fromDirectGeometry().

BufferAttribute.copyIndicesArray() is only used in BufferGeometry.fromDirectGeometry(). I guess it is currently somewhat obsolete since it is not actually executed by the code base.

Well, I’m keeping on reading source code. and I found the ShadowMaterial extends from Material without own copy function won’t copy the color property. Is this the expected behavior for copying a ShadowMaterial instance?

The doc page doesn’t list the ShadowMaterial.color property either.

Perhaps this was added later and not fully implemented?

In any case, I would open an issue on GitHub and note these omissions.

1 Like

Also to mention that in comment of MeshBasicMaterial, MeshLambertMaterial and MeshPhongMaterial files for envMap type is THREE.TextureCube which should be THREE.CubeTexture. But it doesn’t seem to have much to do with it.

Well, the first issue is solved :grin:


BTW: You can directly create PRs if you find an error/inconsistency and know the solution :+1:

1 Like