I found a simple solution, but I'm intrigued. I'm not totally clear on the inner workings of .clone()
.
To standardize vectors, I created this class:
class Vector {
constructor(x,y){
this.x = x
this.y = y
}
normalize() {
let length = Math.sqrt(this.x * this.x + this.y * this.y)
this.x = this.x / length
this.y = this.y / length
}
}
After importing a GLTF model (excerpt from code):
const loader = new GLTFLoader();
loader.load( './assets/models/ROCKS.glb', function ( glb ) {
glb.scene.userData.mouseDirVector = new Vector(0,0)
obj = glb.scene
obj2 = obj.clone()
}
Upon trying to use the .normalize()
method on the Vector object in later code, an error arises (specifically with the cloned object):
Uncaught TypeError: obj2.userData.mouseDirVector.normalize is not a function
What could be causing this issue?