Empty attributes after merge with BufferGeometry

Hi,

i find a lot of old tutorials using Geometry and merging other Shapes into it. I am mostly able to upgrade them to current three.js versions by using BufferGeometry and change the code a little, like use position.setX(index, value) to manipulate vertextes directly. Also it seems easier now to merge geometries, with the merge method, there is just one simple problem: when i merge a geometry, for example a box, into BufferGeometry, the BufferGeometrys attributes is empty: Edit fiddle - JSFiddle - Code Playground

What am i getting wrong? If i merge a BoxGeometry into an empty BufferGeometry, i would expect the buffer to contain all atributes from the box. it stays empty.

Regards

BufferGeometry cannot be resized, so merging just overwrites up to the original vertex or face count. Instead, use BufferGeometryUtils.mergeBufferGeometries to create a new BufferGeometry from an array of inputs.

That results in

THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index 1. All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.

which is weird because its all boxes, that are just randomly stuffed together to create random building shapes.

Maybe you can use for the boxes the function I used for connecting my geometries?
MultiFormGeometry
See function link( geoms )
https://hofk.de/main/discourse.threejs/2022/MultiFormGeometry/link.js there.

It cant work with mergeBufferGeometries because an empty BufferGeometry has no attributes.position and fails here:

The old merge seemed to really just merge the arrays of vertices, normals and uvs:

@hofk i think what you do is similar, but i dont fully understand it. Why link it?

The old script i try to understand is here:
view-source:http://colordodge.com/ProceduralCity/js/Building.js

merge is on lines 164, 172, 178, 184

I thought it is just about achieving this with the new all in one array indexing, but maybe the whole handling of mash merging changed?

Ah, i think they just merge their boxes into empty geometries to get a deep copy of it, but why not just clone it? The old Geometry had that method already.

From the linked Geometry, I can create a single connected mesh. With different materials. In this example I started from, this was especially important.
Pino

In the MultiformGeometry example, you can see that you can easily move/rotate the composite mesh using the move/rotate keys.

if you’re merging an array of geometries, there’s no reason to include an empty geometry in the list I think? the geometries do need to be ‘compatible’, having the same types of attributes and indices.

1 Like