Skip to content

Commit

Permalink
fix change callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
micheal-parks committed Mar 6, 2024
1 parent dccb80a commit a835239
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@viamrobotics/three",
"version": "0.0.8",
"version": "0.0.9",
"license": "Apache-2.0",
"type": "module",
"files": [
Expand Down
32 changes: 21 additions & 11 deletions src/object-3d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,40 @@ export class ViamObject3D extends Object3D {
super();

const ov = new OrientationVector();
const ovChangeCallback = () => ov.setFromQuaternion(this.quaternion, false);

const ovChangeCallback = () => {
ov.setFromQuaternion(this.quaternion, false);
};

const onChange = () => {
this.quaternion._onChangeCallback = noop;
this.rotation._onChangeCallback = noop;

ov.toQuaternion(this.quaternion);
ov.toEuler(this.rotation);

this.quaternion._onChangeCallback = quatChangeCallback;
this.rotation._onChangeCallback = eulerChangeCallback;
};

const eulerOldChangeCallback = this.rotation._onChangeCallback;
const quatOldChangeCallback = this.quaternion._onChangeCallback;

const quatChangeCallback = () => {
ov._onChange(noop);
quatOldChangeCallback();
ovChangeCallback();
ov._onChange(onChange);
};

const eulerChangeCallback = () => {
ov._onChange(noop);
eulerOldChangeCallback();
ovChangeCallback();
ov._onChange(onChange);
};

ov._onChange(() => {
this.quaternion._onChangeCallback = noop;
this.rotation._onChangeCallback = noop;

ov.toQuaternion(this.quaternion);
ov.toEuler(this.rotation);

this.quaternion._onChangeCallback = quatChangeCallback;
this.rotation._onChangeCallback = eulerChangeCallback;
});
ov._onChange(onChange);

this.quaternion._onChange(quatChangeCallback);
this.rotation._onChange(eulerChangeCallback);
Expand Down

0 comments on commit a835239

Please sign in to comment.