Three.js: Cannot clone THREE.Line which geometry is type of THREE.Geometry

Created on 13 Dec 2018  路  4Comments  路  Source: mrdoob/three.js

Right now you cannot clone a THREE.Line when it's geometry attribute is a type of THREE.Geometry.

This is because the clone method calls the constructor without parameters so that the new line's geometry attribute will be constructed as a THREE.BufferGeometry by default. Then the copy method tries to copy a THREE.Geometry object into a THREE.BufferGeometry, which doesn't work.

So shouldn't the clone method look like the one in THREE.Mesh ? meaning:

`clone: function () {

 return new this.constructor(this.geometry, this.material).copy( this );

}`

This fiddle shows the error:

I don't know but maybe this kind of problem could exist at other places too.

Three.js version
  • [x] Dev
  • [ ] r99
  • [ ] ...
Browser
  • [x] All of them
  • [ ] Chrome
  • [ ] Firefox
  • [ ] Internet Explorer
OS
  • [x] All of them
  • [ ] Windows
  • [ ] macOS
  • [ ] Linux
  • [ ] Android
  • [ ] iOS
Hardware Requirements (graphics card, VR Device, ...)
Duplicate

Most helpful comment

This is already fixed in dev, see https://jsfiddle.net/62s8gxqp/

Will be available with the next release R103.

All 4 comments

I think this is a duplicate of #15239 and #15064

@Mugen87

What is the solution? Fiddle from master branch still doesn't work: https://jsfiddle.net/dc5fb0x9/.

TypeError: index is undefined

This is already fixed in dev, see https://jsfiddle.net/62s8gxqp/

Will be available with the next release R103.

Great! Thanks.

Here is a workaround until next release.

/**
 * @returns {Line}
 */
function cloneLine() {
  return new this.constructor(this.geometry, this.material).copy(this);
}

const line = new THREE.Line(lineGeometry, lineMaterial);
line.clone = cloneLine;

line.clone();
Was this page helpful?
0 / 5 - 0 ratings

Related issues

donmccurdy picture donmccurdy  路  3Comments

akshaysrin picture akshaysrin  路  3Comments

danieljack picture danieljack  路  3Comments

seep picture seep  路  3Comments

zsitro picture zsitro  路  3Comments