Rotating Object and unable to click

Hello, I want to be able to rotate the object after clicking it, and click the object again after rotating it.

But I can’t do it now. I can’t trigger the SelectionEvent after clicking on the rotated object.

I’m not sure if it has something to do with the updatematrix of three.js

The following is my code, thanks for the answer

viewer.on(ViewerEvent.ObjectClicked, (selectionEvent: SelectionEvent) => {

    if (selectionEvent && selectionEvent.hits) {

        const firstHitGuid = selectionEvent.hits[0].guid;
        if (firstHitGuid) {
            const objects = viewer.getObjects(firstHitGuid)

            const position = { value: { x: 0, y: 0, z: 0 } }
            const rotation = { value: { x: 1, y: 0, z: 0 } }
            const scale = { value: { x: 1, y: 1, z: 1 } }

            const unionBox: any = new Box3();
            objects.forEach((obj: BatchObject) => {
                unionBox.union(obj.renderView.aabb)
            })

            const origin = new Vector3(1, 0, 0)
            objects.forEach((obj: BatchObject) => {
                obj.transformTRS(position.value, rotation.value, scale.value, origin)
                viewer!.getRenderer().markTransformsDirty(obj.renderView.batchId)
            })
        }

    }
})

Hi @benst96

From the code you shared it looks like you’re using the old viewer API. I strongly suggest using API 2.0, which is available on npm under the viewer-next tag.

The version you are using might have a bug regarding the BathObject transformation, however API 2.0 works fine. Here’s an example sandbox that shows just that: https://www.npmjs.com/package/@speckle/viewer/v/2.17.0-alpha.10

API 2.0 even comes with a temporary LegacyViewer implementation which emulates the old viewer API, for backwards compatibility and an easier transition between the two versions

Let me know if I can be of more help

Cheers

1 Like

It was indeed successful after changing to 2.0, great, thank you.

2 Likes