Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three.js r125 BufferGeometry `vertices` does not exist

Tags:

three.js

I'm working on updating Three.js and I find that when I upgrade to r125, attempts to set vertices on BufferGeometry fail due to the method missing. It also appears to have removed verticesNeedUpdate. The migration guide does not appear to warn about this and the changelog doesn't seem to address it from what I can see.

I unfortunately didn't write the original code so I'm unsure of how to resolve it. The code looks like this:

this.geometry.vertices[0].x = this.geometry.vertices[2].x = -this.canvas.width / 2;
this.geometry.vertices[1].x = this.geometry.vertices[3].x = this.canvas.width / 2;
this.geometry.vertices[0].y = this.geometry.vertices[1].y = this.canvas.height / 2;
this.geometry.vertices[2].y = this.geometry.vertices[3].y = -this.canvas.height / 2;
this.geometry.verticesNeedUpdate = true;

Update using Don's Answer Below

After applying Don's suggested change, we wind up with this:

    const negativeWidth = -this.canvas.width / 2;
    const positiveWidth = this.canvas.width / 2;
    const positiveHeight = this.canvas.height / 2;
    const negativeHeight = -this.canvas.height / 2;

    this.geometry.attributes.position.setXY(0, negativeWidth, positiveHeight);
    this.geometry.attributes.position.setXY(1, positiveWidth, positiveHeight);
    this.geometry.attributes.position.setXY(2, negativeWidth, negativeHeight);
    this.geometry.attributes.position.setXY(3, positiveWidth, negativeHeight);
    this.geometry.attributes.position.needsUpdate = true;
like image 324
subvertallchris Avatar asked Oct 20 '25 14:10

subvertallchris


1 Answers

The first changelog entry for three.js r125 is the relevant one:

Geometry has been removed from the core. It is now located in examples/jsm/deprecated/Geometry.js.

The THREE.Geometry class has been been deprecated for a while, but some older code and examples outside of the project repository still refer to it. The recommended replacement is THREE.BufferGeometry, which is more performant. The BufferGeometry class does not have a .vertices property, so that's probably the cause of the particular error you're seeing. Instead, you can update vertices like this:

geometry.attributes.position.setXYZ( index, x, y, z );
geometry.attributes.position.needsUpdate = true;
like image 147
Don McCurdy Avatar answered Oct 23 '25 08:10

Don McCurdy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!