Serializing a Line object, i lose position

I’m trying to send a Line object through a webworker. I call

myLine.toJSON()

Post it, and in the other thread i use:

const line = new ObjectLoader.parse(lineSource)

However, once parsed, my position is always 0. I tried updating the matrix in the worker, and i see the matrix in the serialized object, however, parsing it seems to ignore it?

Do i need to separate the position and then reapply it?

If you want to re-populate .position, .rotation, .scale, you can .decompose your matrix back into those fields.

object.matrix.decompose(object.position,object.quaternion,object.scale)

(I think setting the quaternion will automagically convert to the.rotation euler, but if not, follow up with object.rotation.setFromQuaternion(object.quaternion) )

https://threejs.org/docs/#api/en/math/Matrix4.decompose

1 Like