cognitedata / reveal

Cognite Reveal 3D viewer
https://cognitedata.github.io/reveal
Apache License 2.0
80 stars 20 forks source link

Ghosted Nodes don't get caught in getIntersectionFromPixel from Cognite3DViewer #4516

Closed joao-mbn closed 5 months ago

joao-mbn commented 5 months ago

I have a piece of code that creates a Cognite3DViewer instance, load a few models and get them reacting to clicks, not very different to this basic example in the docs. When I set the DefaultNodeAppearance to Ghosted, however, the result of await viewer.getIntersectionFromPixel(event.offsetX, event.offsetY) is always null. Other options behave as expected.

Is this behavior intentional? I didn't find anywhere in the docs pointing that it is.

Below is what I believe is the relevant part of the code:

const widget = document.getElementById('threeD-canvas-container')
if (!widget) return

const viewer = new Cognite3DViewer({ sdk: client, domElement: widget })

;(async () => {
    await Promise.all(Object.values(THREE_D_MODELS).map(async (model) => await viewer.addCadModel(model)))

    viewer.models.forEach((model) => {
        if (!(model instanceof CogniteCadModel)) return
        model.setDefaultNodeAppearance(DefaultNodeAppearance.Ghosted)
    })

    viewer.on('click', async (event) => {
        const intersection = (await viewer.getIntersectionFromPixel(
            event.offsetX,
            event.offsetY
        )) as CadIntersection | null
        if (intersection) {
            const {
                treeIndex,
                model: { modelId, revisionId },
            } = intersection
            const model = viewer.models.find(
                (model) => model.modelId === modelId && model.revisionId === revisionId
            )
            if (!(model instanceof CogniteCadModel)) return

            const nodeId = await model.mapTreeIndexToNodeId(treeIndex)

            const toPresent = { treeIndex, nodeId, point: intersection.point }
            alert(`Clicked object!: ${JSON.stringify(toPresent)}`)
        }
    })
})()

I'm using @cognite/sdk v8.3.0, @cognite/reveal v4.14.1 and @three v0.164.1

christjt commented 5 months ago

Hey,

This is currently intended behaviour from our side to enable clicking "through" ghosted nodes. I'll add a task for us internally to make this clear in the docs.