Skip to content

Commit

Permalink
Merge pull request #1754 from xeokit/XCD-212-fix-measurement-line
Browse files Browse the repository at this point in the history
XCD-212 Fix toClipSpace to transform its argument after view/proj matrices stabilize
  • Loading branch information
xeolabs authored Dec 5, 2024
2 parents 3c889d1 + 9aec514 commit 2dc8183
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/plugins/lib/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const tmpVec4a = math.vec4();
const tmpVec4b = math.vec4();
const tmpVec4c = math.vec4();
const tmpVec4d = math.vec4();
const tmpMat4 = math.mat4();

const nop = () => { };

Expand All @@ -25,6 +26,15 @@ export function transformToNode(from, to, vec) {
};

const toClipSpace = (camera, worldPos, p) => {
// The reason the projMatrix is explicitely fetched as below is a complex callback chain
// leading from a boundary update to a viewMatrix and projMatrix updates, which change their values
// in the mid of the toClipSpace, leading to incorrect values.
// The fetch ensures that matrix values are stabilized before used to transform worldPos to p.
// Better solution would be to ensure that no mutually-triggered callbacks
// (like boundary => view/projMatrix in this situation) ever happen, so user code can rely
// on a callback running in a stable context.
tmpMat4.set(camera.viewMatrix);
tmpMat4.set(camera.projMatrix);
// to homogeneous coords
p.set(worldPos);
p[3] = 1;
Expand Down

0 comments on commit 2dc8183

Please sign in to comment.