THREE.Geometry will be removed from core with r125

In a lot of cases - it actually may be. If you didn’t use any geometry merging / non-buffer vertex modifications, replacing should work just fine.

I’d say start by doing the search-and-replace and check what breaks - then fix issues one by one :sweat_smile:

1 Like

Please don’t post the same comment in multiple topics. I’ve deleted the post in How to stay up-to-date with latest editor releases/versions.

1 Like

Thank you!
I just didn’t know where the question would be best asked.

Oh, it’s beaking GSAP example: https://codepen.io/GreenSock/pen/BaarZmV

Here is an updated fiddle with latest the latest three.js version: Edit fiddle - JSFiddle - Code Playground

2 Likes

:thinking: Works for me. They use r122.

The codepen works but the code breaks if someone upgrades to the latest three.js version (because of the removal of THREE.Geometry).

1 Like

You’re right I forgot to say “the r125 update breaks the example”

Hi! in one of my applications I have the following line of code:
const totalGeom = new THREE.Geometry();

further down in my code, I have a mesh:
const cubeMesh = new THREE.Mesh()

i then merge as follow:
totalGeom.merge(cubeMesh.geometry, cubeMesh.matrix)

this works fine, however switching totalGeom to :
totalGeom = new THREE.BufferGeometry();
does not return the expected results…

is there another way of converting Geometry to BufferGeometry which I should be using?
thank you kindly

Buffer geometry doesn’t have a built in merge method. You can use BufferGeometryUtils.mergeBufferGeometries instead.

1 Like

Actually there is:

But it works differently compared to the Geometry method. Using BufferGeometryUtils.mergeBufferGeometries() is indeed the better solution.

1 Like

Thanks for replying so quickly guys! does that mean I should replace ‘THREE.BufferGeometry().merge()’ with ’ THREE.BufferGeometryUtils.mergeBufferGeometries() ?
or is `BufferGeometryUtils’ not part of the core ?

Yes, please use BufferGeometryUtils.mergeBufferGeometries(). And yes, BufferGeometryUtils is no part of the core. But you can import it from the examples directory. If you are working with the npm package, the ES6 import looks like so:

import * as BufferGeometryUtils from 'three/examples/jsm/utils/BufferGeometryUtils.js';

Thank you, i’ve made the necessary changes but I run into the error: ‘Cannot read properties of undefined (reading 'index')
which seems to originate from the BufferGeometryUtils.js file in line
28 : const isIndexed = geometries[ 0 ].index !== null;

could this be because the geometry I’m attempting to merge is not indexed?
Here’s a snippet of my code related to the issue for some context:

let cubeGeom = new THREE.BoxBufferGeometry()
let cubeMat = new THREE.MeshLambertMaterial()

let cubeMesh = new THREE.Mesh(cubeGeom, cubeMat);

BufferGeometryUtils.mergeBufferGeometries(cubeMesh.geometry, cubeMesh.matrix);

i’ve omitted the parameter values in the parenthesis to make this reply shorter

The mergeBufferGeometries method takes an array of geometries as its first argument, and the second argument is usually false. “Merging” a single geometry would be the same as calling .clone() on that geometry. Any geometries given must all have the same data layout, i.e. either all or none should be indexed.