Skip to content

Commit

Permalink
Reimplemtation of annotation fix to be more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
gjcope committed Jun 29, 2023
1 parent d5e4d1f commit a727bbb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
7 changes: 5 additions & 2 deletions source/client/components/CVAnnotationView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,12 @@ export default class CVAnnotationView extends CObject3D
this.changed = true;
}

updateAnnotation(annotation: Annotation)
updateAnnotation(annotation: Annotation, forceSprite?: boolean)
{
//this.updateSprite(annotation);
if(forceSprite) {
this.updateSprite(annotation);
}

this.changed = true;
}

Expand Down
33 changes: 33 additions & 0 deletions source/client/components/CVModel2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ import CVSetup from "./CVSetup";
const _vec3a = new Vector3();
const _vec3b = new Vector3();
const _quat = new Quaternion();
const _quat1 = new Quaternion();
const _box = new Box3();
const _mat4 = new Matrix4();

export interface ITagUpdateEvent extends ITypedEvent<"tag-update">
{
Expand Down Expand Up @@ -135,6 +137,8 @@ export default class CVModel2 extends CObject3D
private _visible: boolean = true;
private _boxFrame: Mesh = null;
private _localBoundingBox = new Box3();
private _prevPosition: Vector3 = new Vector3(0.0,0.0,0.0);
private _prevRotation: Vector3 = new Vector3(0.0,0.0,0.0);

constructor(node: Node, id: string)
{
Expand Down Expand Up @@ -360,11 +364,13 @@ export default class CVModel2 extends CObject3D

if (data.translation) {
ins.position.copyValue(data.translation);
this._prevPosition.fromArray(data.translation);
}

if (data.rotation) {
_quat.fromArray(data.rotation);
helpers.quaternionToDegrees(_quat, CVModel2.rotationOrder, ins.rotation.value);
this._prevRotation.fromArray(ins.rotation.value);
ins.rotation.set();
}

Expand Down Expand Up @@ -574,6 +580,33 @@ export default class CVModel2 extends CObject3D
object3D.matrix.compose(_vec3a, _quat, _vec3b);
object3D.matrixWorldNeedsUpdate = true;

//TODO: Cleanup & optimize annotation update
helpers.degreesToQuaternion([this._prevRotation.x, this._prevRotation.y, this._prevRotation.z], CVModel2.rotationOrder, _quat1);
_quat1.invert();
_vec3b.setScalar(1);
_mat4.compose(_vec3a.fromArray(ins.position.value), _quat, _vec3b);

const annotations = this.getComponent(CVAnnotationView);
annotations.getAnnotations().forEach(anno => {
_vec3a.fromArray(anno.data.position);
_vec3a.sub(this._prevPosition);
_vec3a.applyQuaternion(_quat1);
_vec3a.applyMatrix4(_mat4);

anno.data.position = _vec3a.toArray();

_vec3a.fromArray(anno.data.direction);
_vec3a.applyQuaternion(_quat1);
_vec3a.applyQuaternion(_quat);

anno.data.direction = _vec3a.toArray();

anno.update();
annotations.updateAnnotation(anno, true);
});
this._prevPosition.copy(_vec3a.fromArray(ins.position.value));
this._prevRotation.copy(_vec3a.fromArray(ins.rotation.value));

this.outs.updated.set();
}

Expand Down
7 changes: 0 additions & 7 deletions source/client/components/CVPoseTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,6 @@ export default class CVPoseTask extends CVTask
_mat4.identity().setPosition(_axis);
}

// Update annotation matrix
const annotations = this.activeModel.getComponent(CVAnnotationView);
const anno_mat = _mat4.clone();
anno_mat.multiply(annotations.object3D.matrix);
annotations.object3D.matrix.copy(anno_mat);
annotations.object3D.matrixWorldNeedsUpdate = true;

// multiply delta transform with current model pose transform
_mat4.multiply(this.activeModel.object3D.matrix);
this.activeModel.setFromMatrix(_mat4);
Expand Down

0 comments on commit a727bbb

Please sign in to comment.