Merge vertex_util into math_util.
PiperOrigin-RevId: 896071837 Change-Id: Ieec0e4b4b11988805219739a84f413871ae34f1b
This commit is contained in:
committed by
Copybara-Service
parent
f7fd5fc58b
commit
49b45bd993
@@ -61,8 +61,6 @@ target_sources(${MUJOCO_FILAMENT_TARGET_NAME}
|
||||
filament/scene_view.h
|
||||
filament/texture.cc
|
||||
filament/texture.h
|
||||
filament/vertex_util.cc
|
||||
filament/vertex_util.h
|
||||
)
|
||||
if(MUJOCO_USE_FILAMENT_MJR_COMPAT)
|
||||
target_sources(${MUJOCO_FILAMENT_TARGET_NAME}
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
#include <math/vec2.h>
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
#include "experimental/filament/filament/math_util.h"
|
||||
#include "experimental/filament/filament/mesh.h"
|
||||
#include "experimental/filament/filament/vertex_util.h"
|
||||
|
||||
namespace mujoco {
|
||||
|
||||
|
||||
@@ -13,8 +13,11 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include "experimental/filament/filament/math_util.h"
|
||||
#include <limits>
|
||||
|
||||
#include <math/mat3.h>
|
||||
#include <math/mat4.h>
|
||||
#include <math/quat.h>
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
#include <math/TVecHelpers.h>
|
||||
@@ -23,7 +26,9 @@ namespace mujoco {
|
||||
|
||||
using filament::math::float3;
|
||||
using filament::math::float4;
|
||||
using filament::math::mat3f;
|
||||
using filament::math::mat4;
|
||||
using filament::math::quatf;
|
||||
|
||||
mat4 ToReflectionMatrix(const mat4& xform) {
|
||||
const float3 normal = xform[2].xyz;
|
||||
@@ -81,4 +86,38 @@ mat4 CalculateObliqueProjection(const mat4& projection, const float4& plane) {
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
float4 CalculateOrientation(const float3& normal) {
|
||||
float3 tangent;
|
||||
float3 bitangent;
|
||||
if (normal.y < -1.0f + std::numeric_limits<float>::epsilon()) {
|
||||
// Handle the singularity.
|
||||
tangent = float3{-1.0f, 0.0f, 0.0f};
|
||||
bitangent = float3{0.0f, 0.0f, -1.0f};
|
||||
} else {
|
||||
const float a = 1.0f / (1.0f + normal.y);
|
||||
const float b = -normal.z * normal.x * a;
|
||||
tangent = float3(b, -normal.z, 1.0f - normal.z * normal.z * a);
|
||||
bitangent = float3(1.0f - normal.x * normal.x * a, -normal.x, b);
|
||||
}
|
||||
quatf orientation = mat3f::packTangentFrame({tangent, bitangent, normal});
|
||||
return float4(orientation.xyz, orientation.w);
|
||||
}
|
||||
|
||||
float3 CalculateNormal(
|
||||
const filament::math::float3& p1,
|
||||
const filament::math::float3& p2,
|
||||
const filament::math::float3& p3) {
|
||||
const float3 v12 = p2 - p1;
|
||||
const float3 v13 = p3 - p1;
|
||||
return normalize(cross(v12, v13));
|
||||
}
|
||||
|
||||
float4 CalculateOrientation(
|
||||
const filament::math::float3& p1,
|
||||
const filament::math::float3& p2,
|
||||
const filament::math::float3& p3) {
|
||||
return CalculateOrientation(CalculateNormal(p1, p2, p3));
|
||||
}
|
||||
|
||||
} // namespace mujoco
|
||||
|
||||
@@ -64,6 +64,22 @@ filament::math::mat4 CalculateObliqueProjection(
|
||||
const filament::math::mat4& projection,
|
||||
const filament::math::float4& plane);
|
||||
|
||||
// Calculates the normal of a triangle given its three vertices.
|
||||
filament::math::float3 CalculateNormal(
|
||||
const filament::math::float3& p1,
|
||||
const filament::math::float3& p2,
|
||||
const filament::math::float3& p3);
|
||||
|
||||
// Calculates the orientation of a vertex given just its normal.
|
||||
filament::math::float4 CalculateOrientation(
|
||||
const filament::math::float3& normal);
|
||||
|
||||
// Calculates the orientation of a triangle given its three vertices.
|
||||
filament::math::float4 CalculateOrientation(
|
||||
const filament::math::float3& p1,
|
||||
const filament::math::float3& p2,
|
||||
const filament::math::float3& p3);
|
||||
|
||||
} // namespace mujoco
|
||||
|
||||
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_MATH_UTIL_H_
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <math/vec4.h>
|
||||
#include <mujoco/mujoco.h>
|
||||
#include "experimental/filament/filament/math_util.h"
|
||||
#include "experimental/filament/filament/vertex_util.h"
|
||||
|
||||
namespace mujoco {
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <mujoco/mujoco.h>
|
||||
#include "experimental/filament/filament/math_util.h"
|
||||
#include "experimental/filament/filament/mesh.h"
|
||||
#include "experimental/filament/filament/vertex_util.h"
|
||||
|
||||
namespace mujoco {
|
||||
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
// Copyright 2025 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "experimental/filament/filament/vertex_util.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <math/TVecHelpers.h>
|
||||
#include <math/mat3.h>
|
||||
#include <math/quat.h>
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
|
||||
namespace mujoco {
|
||||
|
||||
using filament::math::float3;
|
||||
using filament::math::float4;
|
||||
using filament::math::mat3f;
|
||||
using filament::math::quatf;
|
||||
|
||||
float4 CalculateOrientation(const float3& normal) {
|
||||
float3 tangent;
|
||||
float3 bitangent;
|
||||
if (normal.y < -1.0f + std::numeric_limits<float>::epsilon()) {
|
||||
// Handle the singularity.
|
||||
tangent = float3{-1.0f, 0.0f, 0.0f};
|
||||
bitangent = float3{0.0f, 0.0f, -1.0f};
|
||||
} else {
|
||||
const float a = 1.0f / (1.0f + normal.y);
|
||||
const float b = -normal.z * normal.x * a;
|
||||
tangent = float3(b, -normal.z, 1.0f - normal.z * normal.z * a);
|
||||
bitangent = float3(1.0f - normal.x * normal.x * a, -normal.x, b);
|
||||
}
|
||||
quatf orientation = mat3f::packTangentFrame({tangent, bitangent, normal});
|
||||
return float4(orientation.xyz, orientation.w);
|
||||
}
|
||||
|
||||
float3 CalculateNormal(
|
||||
const filament::math::float3& p1,
|
||||
const filament::math::float3& p2,
|
||||
const filament::math::float3& p3) {
|
||||
const float3 v12 = p2 - p1;
|
||||
const float3 v13 = p3 - p1;
|
||||
return normalize(cross(v12, v13));
|
||||
}
|
||||
|
||||
float4 CalculateOrientation(
|
||||
const filament::math::float3& p1,
|
||||
const filament::math::float3& p2,
|
||||
const filament::math::float3& p3) {
|
||||
return CalculateOrientation(CalculateNormal(p1, p2, p3));
|
||||
}
|
||||
|
||||
} // namespace mujoco
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright 2025 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_VERTEX_UTIL_H_
|
||||
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_VERTEX_UTIL_H_
|
||||
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
|
||||
namespace mujoco {
|
||||
|
||||
// Calculates the normal of a triangle given its three vertices.
|
||||
filament::math::float3 CalculateNormal(
|
||||
const filament::math::float3& p1,
|
||||
const filament::math::float3& p2,
|
||||
const filament::math::float3& p3);
|
||||
|
||||
// Calculates the orientation of a vertex given just its normal.
|
||||
filament::math::float4 CalculateOrientation(
|
||||
const filament::math::float3& normal);
|
||||
|
||||
// Calculates the orientation of a triangle given its three vertices.
|
||||
filament::math::float4 CalculateOrientation(
|
||||
const filament::math::float3& p1,
|
||||
const filament::math::float3& p2,
|
||||
const filament::math::float3& p3);
|
||||
|
||||
} // namespace mujoco
|
||||
|
||||
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_VERTEX_UTIL_H_
|
||||
Reference in New Issue
Block a user