Skip to content

Commit

Permalink
Refactored annotation creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Savokr committed Jul 12, 2023
1 parent bc8ef9f commit 5aee57e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
30 changes: 1 addition & 29 deletions examples/src/pages/Viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -475,35 +475,7 @@ export function Viewer() {
sphere.position.copy(point);
viewer.addObject3D(sphere);

if (pointCloudObjectsUi.createAnnotationsOnClick) {
const cdfPosition = point.clone().applyMatrix4(model.getCdfToDefaultModelTransformation().invert());

const annotation = await client.annotations.create([
{
annotatedResourceId: model.modelId,
annotatedResourceType: 'threedmodel',
annotationType: 'pointcloud.BoundingVolume',
status: 'suggested',
creatingApp: 'reveal-examples',
creatingUser: 'reveal-user',
creatingAppVersion: '0.0.1',
data: {
label: 'Dummy annotation',
region: [
{
box: {
matrix: new THREE.Matrix4()
.makeTranslation(cdfPosition.x, cdfPosition.y, cdfPosition.z)
.transpose().elements
}
}
]
}
}
]);

console.log('Annotation successfully created', annotation);
}
pointCloudObjectsUi.createModelAnnotation(point, model);
}
}
break;
Expand Down
31 changes: 29 additions & 2 deletions examples/src/utils/PointCloudObjectStylingUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,35 @@ export class PointCloudObjectStylingUI {
.onChange((value: boolean) => (this._createAnnotationsOnClick = value));
}

get createAnnotationsOnClick() {
return this._createAnnotationsOnClick;
async createModelAnnotation(position: THREE.Vector3, model: CognitePointCloudModel) {
if (!this._createAnnotationsOnClick) return;

const cdfPosition = position.clone().applyMatrix4(model.getCdfToDefaultModelTransformation().invert());

const annotation = await this._client.annotations.create([
{
annotatedResourceId: model.modelId,
annotatedResourceType: 'threedmodel',
annotationType: 'pointcloud.BoundingVolume',
status: 'suggested',
creatingApp: 'reveal-examples',
creatingUser: 'reveal-user',
creatingAppVersion: '0.0.1',
data: {
label: 'Dummy annotation',
region: [
{
box: {
matrix: new THREE.Matrix4().makeTranslation(cdfPosition.x, cdfPosition.y, cdfPosition.z).transpose()
.elements
}
}
]
}
}
]);

console.log('Annotation successfully created', annotation);
}

async updateSelectedAnnotation(annotationId: number | undefined) {
Expand Down

0 comments on commit 5aee57e

Please sign in to comment.