Skip to content

Commit 49b45bd

Browse files
haroonqcopybara-github
authored andcommitted
Merge vertex_util into math_util.
PiperOrigin-RevId: 896071837 Change-Id: Ieec0e4b4b11988805219739a84f413871ae34f1b
1 parent f7fd5fc commit 49b45bd

8 files changed

Lines changed: 56 additions & 111 deletions

File tree

src/experimental/filament/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ target_sources(${MUJOCO_FILAMENT_TARGET_NAME}
6161
filament/scene_view.h
6262
filament/texture.cc
6363
filament/texture.h
64-
filament/vertex_util.cc
65-
filament/vertex_util.h
6664
)
6765
if(MUJOCO_USE_FILAMENT_MJR_COMPAT)
6866
target_sources(${MUJOCO_FILAMENT_TARGET_NAME}

src/experimental/filament/filament/builtins.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
#include <math/vec2.h>
2828
#include <math/vec3.h>
2929
#include <math/vec4.h>
30+
#include "experimental/filament/filament/math_util.h"
3031
#include "experimental/filament/filament/mesh.h"
31-
#include "experimental/filament/filament/vertex_util.h"
3232

3333
namespace mujoco {
3434

src/experimental/filament/filament/math_util.cc

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
// limitations under the License.
1414

1515
#include "experimental/filament/filament/math_util.h"
16+
#include <limits>
1617

18+
#include <math/mat3.h>
1719
#include <math/mat4.h>
20+
#include <math/quat.h>
1821
#include <math/vec3.h>
1922
#include <math/vec4.h>
2023
#include <math/TVecHelpers.h>
@@ -23,7 +26,9 @@ namespace mujoco {
2326

2427
using filament::math::float3;
2528
using filament::math::float4;
29+
using filament::math::mat3f;
2630
using filament::math::mat4;
31+
using filament::math::quatf;
2732

2833
mat4 ToReflectionMatrix(const mat4& xform) {
2934
const float3 normal = xform[2].xyz;
@@ -81,4 +86,38 @@ mat4 CalculateObliqueProjection(const mat4& projection, const float4& plane) {
8186
return res;
8287
}
8388

89+
90+
float4 CalculateOrientation(const float3& normal) {
91+
float3 tangent;
92+
float3 bitangent;
93+
if (normal.y < -1.0f + std::numeric_limits<float>::epsilon()) {
94+
// Handle the singularity.
95+
tangent = float3{-1.0f, 0.0f, 0.0f};
96+
bitangent = float3{0.0f, 0.0f, -1.0f};
97+
} else {
98+
const float a = 1.0f / (1.0f + normal.y);
99+
const float b = -normal.z * normal.x * a;
100+
tangent = float3(b, -normal.z, 1.0f - normal.z * normal.z * a);
101+
bitangent = float3(1.0f - normal.x * normal.x * a, -normal.x, b);
102+
}
103+
quatf orientation = mat3f::packTangentFrame({tangent, bitangent, normal});
104+
return float4(orientation.xyz, orientation.w);
105+
}
106+
107+
float3 CalculateNormal(
108+
const filament::math::float3& p1,
109+
const filament::math::float3& p2,
110+
const filament::math::float3& p3) {
111+
const float3 v12 = p2 - p1;
112+
const float3 v13 = p3 - p1;
113+
return normalize(cross(v12, v13));
114+
}
115+
116+
float4 CalculateOrientation(
117+
const filament::math::float3& p1,
118+
const filament::math::float3& p2,
119+
const filament::math::float3& p3) {
120+
return CalculateOrientation(CalculateNormal(p1, p2, p3));
121+
}
122+
84123
} // namespace mujoco

src/experimental/filament/filament/math_util.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ filament::math::mat4 CalculateObliqueProjection(
6464
const filament::math::mat4& projection,
6565
const filament::math::float4& plane);
6666

67+
// Calculates the normal of a triangle given its three vertices.
68+
filament::math::float3 CalculateNormal(
69+
const filament::math::float3& p1,
70+
const filament::math::float3& p2,
71+
const filament::math::float3& p3);
72+
73+
// Calculates the orientation of a vertex given just its normal.
74+
filament::math::float4 CalculateOrientation(
75+
const filament::math::float3& normal);
76+
77+
// Calculates the orientation of a triangle given its three vertices.
78+
filament::math::float4 CalculateOrientation(
79+
const filament::math::float3& p1,
80+
const filament::math::float3& p2,
81+
const filament::math::float3& p3);
82+
6783
} // namespace mujoco
6884

6985
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_MATH_UTIL_H_

src/experimental/filament/filament/mesh.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <math/vec4.h>
3131
#include <mujoco/mujoco.h>
3232
#include "experimental/filament/filament/math_util.h"
33-
#include "experimental/filament/filament/vertex_util.h"
3433

3534
namespace mujoco {
3635

src/experimental/filament/filament/model_util.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <mujoco/mujoco.h>
2929
#include "experimental/filament/filament/math_util.h"
3030
#include "experimental/filament/filament/mesh.h"
31-
#include "experimental/filament/filament/vertex_util.h"
3231

3332
namespace mujoco {
3433

src/experimental/filament/filament/vertex_util.cc

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/experimental/filament/filament/vertex_util.h

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)