Skip to content

Commit db3d064

Browse files
authored
Fixes picking issue in low DPR (#128)
* Update scale calculation in getEntityAtPointerEvent to use PlayCanvas's DPR for improved accuracy * Remove redundant return statement in getEntityAtPointerEvent function to streamline code execution.
1 parent 6ed3fc9 commit db3d064

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

packages/lib/src/utils/picker.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ const getEntityAtPointerEvent = async (app : AppBase, picker: Picker, rect: DOMR
5353
const x = e.clientX - rect.left;
5454
const y = e.clientY - rect.top;
5555

56-
// Account for canvas scaling
57-
const scaleX = canvas.width / rect.width;
58-
const scaleY = canvas.height / rect.height;
56+
// Scale calculation using PlayCanvas's DPR
57+
const scaleX = canvas.width / (rect.width * app.graphicsDevice.maxPixelRatio);
58+
const scaleY = canvas.height / (rect.height * app.graphicsDevice.maxPixelRatio);
5959

6060
// prepare the picker and perform picking
6161
try {
@@ -67,7 +67,6 @@ const getEntityAtPointerEvent = async (app : AppBase, picker: Picker, rect: DOMR
6767
if (!meshInstance) return null
6868

6969
return meshInstance?.node as Entity;
70-
return null
7170
} catch {
7271
// The picker can fail if the camera is not active or the canvas is not visible
7372
return null;

0 commit comments

Comments
 (0)