Skip to content

BufferGeometry.merge or BufferGeometryUtils.mergeBufferGeometries: Add support for transformation matrix #18918

@finnbear

Description

@finnbear
Summary of feature request

.addScaledVector but instead of adding a scaled vector, merging a transformed BufferGeometry

Description of feature request

For optimization purposes, I want to render a single buffer geometry instead of rendering each object in my scene separately

const geometry = THREE.BufferGeometryUtils.mergeBufferGeometries(this.children.map(child =>
    child.geometry.clone().applyMatrix4(child.matrix) // The issue
));
this.add(new THREE.Mesh(geometry, this.children[0].material));
for (const child of this.children) {
     child.visible = false;
}

(simplified code, not tested but should convey my point)

Unfortunately, the existing buffer geometry merge methods don't support transforming each merged vertex by a custom matrix. That means I have to clone each child's geometry and apply the matrix to the entire clone at once.

This is a waste of memory, and could be avoided with

  • BufferGeometry.merge(bufferGeometry, optionalMatrix)
  • BufferGeometryUtils.mergeBufferGeometries(bufferGeometries, optionalMatrices)

The 2nd option is slightly more awkward but is preferred because BufferGeometryUtils is lossless (doesn't require manual index argument)

If a matrix is passed in, each vertex being merged in should have it applied.

Note: I know I could get around this by pre-applyMatrix4-ing all my objects' geometries, but I don't want to do that...I want them to share a single, applyMatrix4'd buffer geometry instance.

Note 2: For my use case, each child's BufferGeometry is the same. A solution specific to my case is :

  • BufferGeometryUtils.stamp(bufferGeometry, matrices)

Which would take a single geometry and stamp it at multiple locations/rotations/scales defined by each matrix.

Three.js version
  • Dev
  • r114

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions