Repository navigation
Keep Mat4.setLookAt valid when looking along the up vector - #10147
Open
SwastikTripathi wants to merge 1 commit into
Open
SwastikTripathi wants to merge 1 commit into
SwastikTripathi wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Mat4#setLookAtbuilds its x-axis ascross(up, z). When the line of sight is parallel toup, that cross product is the zero vector,normalize()leaves it at zero, and the matrix gets zero x and y rows.GraphNode#lookAtpassesVec3.UPby default, so the most common top-down setup silently does nothing:The rotation extracted from the zero rows comes out as identity, so the node keeps looking along -z. The same applies to a light aimed at something directly below it (noted in #9244, which left the guard for a separate change) and to
XrLightEstimation, which callssetLookAt(..., Vec3.UP)with the estimated light direction.When the cross product is exactly zero,
setLookAtnow builds the x-axis from the positive z-axis instead (or the positive x-axis whenupitself is along z). That is the limit of a target a tiny step off the vertical, so looking straight down gives the same matrix as looking down at(0, 0, -1e-6): x stays[1, 0, 0]and the view's up becomes-z. Inputs that already worked take the same path as before. The doc comment now describes the fallback instead of forbidding parallel up vectors.Tests: new cases in
test/core/math/mat4.test.mjs(orthonormal basis that still points at the target for four parallel and antiparallel cases, and a match with the nearly vertical look at) andtest/scene/graph-node.test.mjs(lookAtstraight down and straight up). All four fail on main and pass with the fix. Fullnpm test: 59 failures both before and after, the same list (asset, font and container loading in node); nothing new.npx eslinton the changed files passes.Checklist