The clone()
method creates a clone of the curve. It returns a new instance of the same class with the same properties and values as the original curve.
clone(): Curve
The clone()
method creates a new instance of the same class with the same properties and values as the original curve. The cloned curve is an independent copy of the original curve, and any changes to the cloned curve do not affect the original.
The clone()
method is inherited by all curve classes that extend the Curve
base class.
None.
A new instance of the same curve class with the same properties and values as the original curve.
// Create a quadratic curve
var curve = new THREE.QuadraticBezierCurve(
new THREE.Vector2(0, 0),
new THREE.Vector2(0.5, 1),
new THREE.Vector2(1, 0)
);
// Clone the curve
var clonedCurve = curve.clone();
// Modify the cloned curve
clonedCurve.v1 = new THREE.Vector2(0.5, 0);
// Verify that the original curve is unchanged
console.log(curve);
// QuadraticBezierCurve {_v0: Vector2, v1: Vector2, v2: Vector2}
// Verify that the cloned curve has been modified
console.log(clonedCurve);
// QuadraticBezierCurve {_v0: Vector2, v1: Vector2, v2: Vector2}
In this example, we create a quadratic curve and then clone it. We then modify the cloned curve by setting its v1
property to a new value. Finally, we verify that the original curve was not modified, and that the cloned curve was modified as expected.
clone()
method is a shallow clone, meaning that if any of the curve's properties are themselves objects, those objects are not cloned. Instead, the clone of the curve will reference the same objects as the original. If you need a deep clone, you must create a custom clone method that recursively clones any child objects.