Reconstruct NurbsSurface from verb-nurbs

Hi there. I’m working on some 3d visualizations of NurbsSurfaces and started using verb.

In the repo of verb there are some example functions to convert a surface to a Three.js geometry, but as Geometry and Face3 are deprecated, could anyone point me in the right direction to convert this function using BufferGeometry?

function tessellateSurface(srf) {

        var tess = srf.tessellate();

        var geometry = new THREE.Geometry();

        geometry.vertices = asVector3( tess.points );

        geometry.faces = tess.faces.map(function(faceIndices){
            var normals = faceIndices.map(function(x){
                var vn = tess.normals[x];
                return new THREE.Vector3( vn[0], vn[1], vn[2] );
            });

            return new THREE.Face3(faceIndices[0],faceIndices[1],faceIndices[2], normals);
        });

        return geometry;
    }

Ok, so if anyone else is wondering how to reconstruct a NurbsSurface from the verb-nurbs library and render it in Three.js using BufferGeometry:

      const tess = verbCurve.tessellate();

      const geometry = new THREE.BufferGeometry();

      geometry.setIndex(tess.faces.flat());

      geometry.setAttribute(
        "position",
        new THREE.Float32BufferAttribute(tess.points.flat(), 3)
      );
      geometry.setAttribute(
        "normal",
        new THREE.Float32BufferAttribute(tess.normals.flat(), 3)
      );

      return new THREE.Mesh(geometry, meshMaterial);
1 Like