dxf-viewer icon indicating copy to clipboard operation
dxf-viewer copied to clipboard

How to get clientX and clientY on pointerdown event?

Open sdsoldi opened this issue 2 years ago • 3 comments

I need to get the mouse click positions to find and select nearlest object. Searching in google threejs clientX and clientY are only in mouse (click, mousedown, mouseup) events.

My event has not clientX but has a

event {
    detail {
        "domEvent": {
            "isTrusted": true
        },
        "canvasCoord": {
            "x": 1061,
            "y": 104
        },
        "position": {
            "x": 6.269714285714287,
            "y": 9.19257142857143
        }
    }
}

Is event.detail.position.x the real click coordinates?

sdsoldi avatar Oct 24 '23 08:10 sdsoldi

Is event.detail.position.x the real click coordinates?

This is scene coordinate, i.e. Three.js objects coordinate space. It can be converted to DXF model space by adding scene origin, which can be obtained by viewer.GetOrigin() method.

vagran avatar Oct 24 '23 08:10 vagran

Using viewer.GetOrigin() response is always

{
    "x": 0,
    "y": 0
}

I think I need the coordinates of the scene because I need to get the nearest mesh or line segments to select and hide if action required

sdsoldi avatar Oct 24 '23 08:10 sdsoldi

Origin at [0;0] might happen if your DXF has some point at this position and is selected as origin. It may differ with other files. It will be quite difficult to determine DXF primitive from Three.js scene object since they are compiled rendering batches. In general, this feature was not really designed in current viewer version. There are plans to support such use cases in a future version, but currently the development is a bit stuck due to my busyness, so you will probably need a deep modification of the library to implement it. Some additional info can be found in this issue.

vagran avatar Oct 24 '23 08:10 vagran