THREE.Geometry will be removed from core with r125

SubdivisionModifier has been removed from the repository with r125. So there is no support for it with newer three.js versions anymore.

1 Like

I had to use SubdivisionModifier recently. If you don’t need any of the newest features, but need subdivisions, you could just install r124.

2 Likes

I use this modifier as a solution to make my 3D models weight very little to reduce Network bandwidth. I send to my client low-poly 3Ds and make them smoother with SubdivisionModifier. I can’t believe SubdivisionModifier being removed completely from 3D solutions, as it is very used in this area. I believe someone would come with a solution for it with the new repo.

I have relied on Geometry only to extract Face normal data to generate STLs from 3D objects. How do I now compute face normals from a BufferGeometry?

thanks!

1 Like

You extract the vertices from the position buffer attribute, configure an instance of Triangle with these data and then use Triangle.getNormal().

3 Likes

@cabada As a workaround, you can copy the source code of SubdivisionModifier into your own repo and import the deprecated Geometry class from examples/jsm/deprecated/Geometry.js.

SubdivisionModifier was not only removed because it depends on Geometry. It actually never worked properly. Since the maintenance and development effort for this class was just too high, we have decided to no longer support such a modifier. Read the respective PR for more information and alternative workflows.

2 Likes

Hi guys, I am having problems migrating to 125

This is my code

  this.geometry = new THREE.ParametricGeometry(
    (u: number, v: number, result: THREE.Vector3) =>
      this.parametricGeometry.bind(this)(u, v, result, this.getMinX(), this.getMaxX(), this.getMinY(), this.getMaxY()),
    this.getMaxX() - this.getMinX(),
    this.getMaxY() - this.getMinY()
  );

  this.geometry.faces.forEach(
    (face: THREE.Face3) =>
      [face.a, face.b, face.c].forEach(index =>
        face.vertexColors.push(
          new THREE.Color().setHSL(NgxVt.mod(0.68 - (0.83 * ((this.geometry.vertices[index].z - this.getMinZ()) / (this.getMaxZ() - this.getMinZ()))), 1), 1, 0.5)
        )
      )
  );

  this.material = new THREE.MeshBasicMaterial({
    vertexColors: true,
    side: THREE.DoubleSide,
    wireframe: true
  });

  this.material.needsUpdate = true;

  this.mesh = new THREE.Mesh(this.geometry, [this.material]);

Now thanks to the snippet provided from @Mugen87 I am doing this :

  const positionAttribute = this.geometry.getAttribute('position');

  const colors = [];
  const color = new THREE.Color();
  const localVertex = new THREE.Vector3();

  for (let vertexIndex = 0; vertexIndex < positionAttribute.count; vertexIndex++) {
    localVertex.fromBufferAttribute(positionAttribute, vertexIndex);
    color.setHSL(NgxVt.mod(0.68 - (0.83 * ((localVertex.z - this.getMinZ()) / (this.getMaxZ() - this.getMinZ()))), 1), 1, 0.5);
    colors.push(color.r, color.g, color.b);
  }

  this.geometry.setAttribute('color', new THREE.Float32BufferAttribute(colors, 3));

But my Mesh stay black. I can’t see any color. What’s the equivalent code of what I was doing before ? THREE.Face hasn’t vertexColors attribyte anymore and I can’t find nothing about this in the documentation.

Please help.

Do you mind demonstrating the issue with a complete live example? https://jsfiddle.net/3oL4xmdh/

BTW: When you create a new material, there is no need to set needsUpdate to true.

Sorry, my fault. I recompiled and it worked.
Thank you.

I used to use Geometry for the improved raycaster performance. Is there an alternative to Geometry for this use case?

I’m not aware of any advantage in Geometry over BufferGeometry for raycasting – if you’d be able to share an example showing the effect, in a new thread or GitHub issue, I think we could investigate that.

EDIT: It’s worth noting that a naive conversion from Geometry → BufferGeometry could increase vertex count, but doesn’t have to. If the raycasting performance issue you mentioned boils down to a difference in vertex count, that’s helpful to know.

1 Like

i don’t mind the change to geometry, even if it does break some complicated code i’ve been working on, a suggestion though:

get vertices()
{
    const positionAttribute = MovingCube.geometry.getAttribute( 'position' );
    var retArr=[];
    for ( let vertexIndex = 0; vertexIndex < positionAttribute.count; vertexIndex ++ ) 
    {
        var localVector=new THREE.Vector3();
        if(positionAttribute.size==2)
        {
            localVector=new THREE.Vector2();
        }
    retArr.push(localVector.fromBufferAttribute( positionAttribute, vertexIndex );
    }
    return retArr;
}

or something to that effect, a similar setter can be made too, this has obvious drawbacks (it’s slower for starters, each time getting a vertex makes a whole new array, a function “getVertex(index)” could probably get around that instead of a getter) and the array is read only, but there is no way to convey that information that i’m aware of, so someone might think changing an element in the resulting array will have some kind of effect on the geometry, a setter for this would have to accept the entire array, or a function “setVertex(value,index)”

but it would go a ways to dealing with the user unfriendliness of bufferGeometry, and getting and setting vertices is the main thing i use three js for, then i send the data over to unity for rendering.

Hi guys,

I was trying to remove some vertices from BufferGeometry:

const positionAttribute = this.mesh.geometry.getAttribute('position');

            const positions = (this.mesh.geometry as THREE.BufferGeometry).attributes.position.array as Array<number>

            for (let i = 0; i < positions.length; i += 3) {

                if(positions[i +2] < 0) {
                    positions.splice(i, 1);
                    positions.splice(i +1, 1);
                    positions.splice(i +2, 1);
                }

            }

  (this.mesh.geometry as THREE.BufferGeometry).attributes.position.needsUpdate = true

But the Type Float32Array does not has the method to splice, any other Idea to “crop the geometry”?

Thanks!

A more efficient option supported on BufferGeometry would be to move the vertex to the end of the array, and then shorten the draw range (geometry.setDrawRange). You could also use an buffer.index (a list of which vertices to draw as triangle triplets), and similarly rearrange or shorten the index to avoid messing with the individual vertex attributes.

1 Like

Ok nice, I’ll try it.

And when I apply a rotation on the mesh, and I try to clone the object and I add it again to the scene, the new object is added but without the rotation applied, how I can copy with the rotation? I understand it copies the bufferGeometry right? And the rotation isn’t applied

Thanks!

maybe I am mis-reading, but I expect this to work:

sorry I did mis-read.

@Sebas could you start a new thread for this topic?

1 Like

Ready :wink:

https://discourse.threejs.org/t/align-geometry-to-plane-selecting-3-intersected-points/25531

Hi @donmccurdy can you make me a short example to how I can move the vertex to the end of the array and then change the draw range please?

Really thanks for the help

Please create a new thread for your other questions, thanks.