-
Notifications
You must be signed in to change notification settings - Fork 872
Adding uvFromPoint (clientX, clientY) #3043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
added testing (npm test doesn't test anything due to unknown reason) added entry in docs.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
uvFromPoint(pixelX: number, pixelY: number): Vector2D|null { | ||
const scene = this[$scene]; | ||
const ndcCoords = scene.getNDC(pixelX, pixelY); | ||
scene.raycaster.setFromCamera(ndcCoords, scene.getCamera()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind shifting this over next to positionAndNormalFromPoint
in annotations.ts instead? I think following that logic will also clean this up a shade (no need to access the raycaster out here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I was doing this in the beginning, but then I was not sure if it really fits under "annotations" since I couldn't see a use case relating the hotspots. Though I changed that now.
'uvFromPoint returns null when intersect fails', async () => { | ||
await loadModel(ASTRONAUT_GLB_PATH); | ||
|
||
await timePasses(1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I was following the test from "materialFromPoint()" for coherence. I removed it, and just check that the UV-coords are within 0-1 inside the positionAndNormalFromPoint() test.
|
||
export interface Vector2D { | ||
x: number | ||
y: number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be u and v instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed that now, but wouldn't it be maybe better for other use cases in the future if it stays x and y? So it can be reused without creating confusion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, but I think we'll cross that bridge when we come to it. I don't see a lot of need to return {x, y}
, so hopefully it's a non-issue.
Removed method from scene-graph and return uv from previous existing positionAndNormalfromPoint().
I made the changes you requested. Let me know if it suits your proposals. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I like that better. The method name ought to be more generic, but it's not worth a breaking change. Just a little cleanup left.
} | ||
|
||
if (hit.uv == null) { | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't want this; a model can lack UV coordinates, in which case uv = null
makes sense, and it shouldn't destroy the rest of the result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made some according changes.
return {position: hit.point, normal: hit.face.normal, uv: hit.uv}; | ||
} | ||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to delete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed
also deleted old comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Referring to discussion.
Added tests, but I couldn't sucessfully run
npm run test
yet.Added some description in the docs.json for explanation.
Own toString() Method for Vector2.
Works pretty much like the positionAndNormalFromPoint() method, but only returns a Vector2D.