From a69541da4cf156ed00de7ed10887a1fc57dcbd14 Mon Sep 17 00:00:00 2001 From: reduz Date: Wed, 20 Oct 2021 20:42:22 -0300 Subject: Implement Animation Compression Roughly based on https://github.com/godotengine/godot-proposals/issues/3375 (used format is slightly different). * Implement bitwidth based animation compression (see animation.h for format). * Can compress imported animations up to 10 times. * Compression format opens the door to streaming. * Works transparently (happens all inside animation.h) --- core/math/vector3.h | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'core/math/vector3.h') diff --git a/core/math/vector3.h b/core/math/vector3.h index e65ac31c02..dc9aa60458 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -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(); + } + _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; -- cgit v1.2.3