Can't apply mergeVertices() to TubeGeometry

I am trying to merge TubeGeometry’s vertices by applying BufferGeometryUtils.mergeVertices()
to avoid this effect:


but getting following error:

As I can see, the reason is the lack of path in constructor while clone() is called.
Could you suggest the best walkaround for this issue, or maybe I am doing something wrong ?

Live demo is here, just click “Granny knot” icon
image
to reproduce it.

To allow cloning, the constructor has to be able to handle being called with no parameters, and then having all its properties copied over after construction, via you overriding the .copy() method..
So perhaps just putting a null check in your constructor?
Like:

constructor( path, segments = 64, radius = 1, segmentsRadius = 8, closed = false ) {
    if (!path){
        super();
        return;
    } 

And rely on threejs to then call your .copy() method to transfer all the properties from the original..

Here’s what the threejs clone method does:

	clone() {
		return new this.constructor().copy( this );
	}

and then your .copy() method will simply copy those generated attributes over to the new geometry.

So your copy method might look something like:

copy(from){
   super.copy(from);
   this.tangents = from.tangents;
this.normals = from.normals;
this.binormals = from.binormals;
this.path = from.path;
this.segments = from.segments;
this.radius = from.radius;
this.segmentsRadius = from.segmentsRadius;
this.closed = from.closed;
}
2 Likes

Many-many thanks !
That was enough:

    if (!path){ // Fix clone issue
        super();
        return;
    }

You saved me from a huge head pain and now I have absolutely smooth beauty :slight_smile: :

1 Like

Looks gorgeous.

1 Like