-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix divide zero issue in mat4.toSRT which causes node._lrot with NaN values. #16935
Fix divide zero issue in mat4.toSRT which causes node._lrot with NaN values. #16935
Conversation
Interface Check ReportThis pull request does not change any public interfaces ! |
if (det < 0) { | ||
s.x *= -1; | ||
} | ||
} |
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 don't understand, why inverse s.x?
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.
https://github.com/cocos/cocos-engine/blob/v3.8.3/cocos/core/math/mat4.ts#L904
It's from the original logic。
There is an explain from AI:
When the determinant is less than 0, it signifies two important physical meanings:
- Reversal of Orientation: The sign of the determinant indicates whether a transformation preserves the orientation of space. When the determinant is negative, it means that the transformation reverses the orientation of space, flipping from the positive direction to the negative direction. Geometrically, this implies that objects are oriented oppositely after the transformation compared to the original orientation.
- Volume Reversal: The absolute value of the determinant represents the scaling factor of the space volume defined by the transformation. When the determinant is negative, it implies that the transformation results in a reversal of the space volume, meaning that after the transformation, the volume of objects in space is reversed, becoming opposite.
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.
@star-e I found some reference in Ogre engine:
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 it mirrors the x-axis. As long as the conversion is consistent, it will be fine.
} | ||
|
||
m3_1.m00 = m.m00 / sx; |
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.
The original code did not check whether the sx value is 0, and divide 0 will make m3_1.m00 be a NaN value.
0a8ea73
to
71cdc92
Compare
Re: #16929
If node._lrot.x is NaN, it will be serialized to scene data with
null
value.Changelog
Continuous Integration
This pull request:
Compatibility Check
This pull request: