-
-
Notifications
You must be signed in to change notification settings - Fork 21.7k
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
Implement animation compression #54050
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,9 +32,9 @@ | |
#define VECTOR3_H | ||
|
||
#include "core/math/math_funcs.h" | ||
#include "core/math/vector2.h" | ||
#include "core/math/vector3i.h" | ||
#include "core/string/ustring.h" | ||
|
||
class Basis; | ||
|
||
struct Vector3 { | ||
|
@@ -103,6 +103,31 @@ struct Vector3 { | |
Vector3 cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, const real_t p_weight) const; | ||
Vector3 move_toward(const Vector3 &p_to, const real_t p_delta) const; | ||
|
||
_FORCE_INLINE_ Vector2 octahedron_encode() const { | ||
Vector3 n = *this; | ||
n /= Math::abs(n.x) + Math::abs(n.y) + Math::abs(n.z); | ||
Vector2 o; | ||
if (n.z >= 0.0) { | ||
o.x = n.x; | ||
o.y = n.y; | ||
} else { | ||
o.x = (1.0 - Math::abs(n.y)) * (n.x >= 0.0 ? 1.0 : -1.0); | ||
o.y = (1.0 - Math::abs(n.x)) * (n.y >= 0.0 ? 1.0 : -1.0); | ||
} | ||
o.x = o.x * 0.5 + 0.5; | ||
o.y = o.y * 0.5 + 0.5; | ||
return o; | ||
} | ||
|
||
static _FORCE_INLINE_ Vector3 octahedron_decode(const Vector2 &p_oct) { | ||
Vector2 f(p_oct.x * 2.0 - 1.0, p_oct.y * 2.0 - 1.0); | ||
Vector3 n(f.x, f.y, 1.0f - Math::abs(f.x) - Math::abs(f.y)); | ||
float t = CLAMP(-n.z, 0.0, 1.0); | ||
n.x += n.x >= 0 ? -t : t; | ||
n.y += n.y >= 0 ? -t : t; | ||
return n.normalized(); | ||
} | ||
Comment on lines
+106
to
+129
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
reduz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_FORCE_INLINE_ Vector3 cross(const Vector3 &p_b) const; | ||
_FORCE_INLINE_ real_t dot(const Vector3 &p_b) const; | ||
Basis outer(const Vector3 &p_b) const; | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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.
Does this return NaN for the identity quaternion? Should it return 0,0,0 or an arbitrary axis 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 think w should never be negative, but it may be possible this is the case due to numerical precision, so a MAX(1-w*w,0.0) might be in order for a separate PR.
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.
even if w is exactly +1.0 or -1.0, the issue is that (1-w*w) may become 0.0 which would cause a division by zero if
Math::sqrt(1 - w * w)==0
.that is to say,
r
may become NaNperhaps
real_t r = MAX(0.0, ....);
would avoid both issues.(I'm a bit curious how identity quaternion is currently handled in this code / why this encoding doesn't cause trouble when converting such a NaN axis to octahedral compression)
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 the problem is that, if w is 1.0 (or -1.0), then whatever axis is does not really matter because upon rebuilding of axis/angle axis is multiplied by 0. I am not sure if we should add a special check to these functions for this case.