THREE.Geometry will be removed from core with r125

Maybe a ridiculous follow up question.
I had started my project a while ago so I was just going to pick it back up now but my last build is at r124 .

I see a lot of discussion on changing, THREE.Geometry to THREE.BufferGeometry. Is it not as simple as search and replace? Or does the complexity really apply if you have a lot of new code using the old function?

Where should I start? The structure of my folders is a bit different so it seems I just have to go one-by-one with the latest update and check for conflicts?

Thank you for any guidance!

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.