diff --git a/Hydrogent/CMakeLists.txt b/Hydrogent/CMakeLists.txt index a8b35d60..dd3a6e84 100644 --- a/Hydrogent/CMakeLists.txt +++ b/Hydrogent/CMakeLists.txt @@ -43,6 +43,7 @@ set(INCLUDE ) set(INTERFACE + interface/GfTypeConversions.hpp interface/HnMaterial.hpp interface/HnMaterialNetwork.hpp interface/HnMesh.hpp diff --git a/Hydrogent/interface/GfTypeConversions.hpp b/Hydrogent/interface/GfTypeConversions.hpp new file mode 100644 index 00000000..039ff346 --- /dev/null +++ b/Hydrogent/interface/GfTypeConversions.hpp @@ -0,0 +1,190 @@ +/* + * Copyright 2023 Diligent Graphics LLC + * + * 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. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "../../../DiligentCore/Common/interface/BasicMath.hpp" + +#include "pxr/base/gf/vec2f.h" +#include "pxr/base/gf/vec3f.h" +#include "pxr/base/gf/vec4f.h" +#include "pxr/base/gf/vec2d.h" +#include "pxr/base/gf/vec3d.h" +#include "pxr/base/gf/vec4d.h" +#include "pxr/base/gf/matrix4f.h" +#include "pxr/base/gf/matrix4d.h" + +namespace Diligent +{ + +namespace USD +{ + +template +pxr::GfVec2f ToGfVec2f(const Vector2& v) +{ + return pxr::GfVec2f{ + static_cast(v.x), + static_cast(v.y), + }; +} + +template +pxr::GfVec3f ToGfVec3f(const Vector3& v) +{ + return pxr::GfVec3f{ + static_cast(v.x), + static_cast(v.y), + static_cast(v.z), + }; +} + +template +pxr::GfVec4f ToGfVec4f(const Vector4& v) +{ + return pxr::GfVec4f{ + static_cast(v.x), + static_cast(v.y), + static_cast(v.z), + static_cast(v.w), + }; +} + +template +Vector2 ToVector2(const pxr::GfVec2f& v) +{ + return Vector2{ + static_cast(v[0]), + static_cast(v[1]), + }; +} + +template +Vector2 ToVector2(const pxr::GfVec2d& v) +{ + return Vector2{ + static_cast(v[0]), + static_cast(v[1]), + }; +} + +template +Vector3 ToVector3(const pxr::GfVec3f& v) +{ + return Vector3{ + static_cast(v[0]), + static_cast(v[1]), + static_cast(v[2]), + }; +} + +template +Vector3 ToVector3(const pxr::GfVec3d& v) +{ + return Vector3{ + static_cast(v[0]), + static_cast(v[1]), + static_cast(v[2]), + }; +} + +template +Vector4 ToVector4(const pxr::GfVec4f& v) +{ + return Vector4{ + static_cast(v[0]), + static_cast(v[1]), + static_cast(v[2]), + static_cast(v[3]), + }; +} + +template +Vector4 ToVector4(const pxr::GfVec4d& v) +{ + return Vector4{ + static_cast(v[0]), + static_cast(v[1]), + static_cast(v[2]), + static_cast(v[3]), + }; +} + +template +pxr::GfMatrix4f ToGfMatrix4f(const Matrix4x4& m) +{ + // clang-format off + return pxr::GfMatrix4f{ + static_cast(m._11), static_cast(m._12), static_cast(m._13), static_cast(m._14), + static_cast(m._21), static_cast(m._22), static_cast(m._23), static_cast(m._24), + static_cast(m._31), static_cast(m._32), static_cast(m._33), static_cast(m._34), + static_cast(m._41), static_cast(m._42), static_cast(m._43), static_cast(m._44), + }; + // clang-format on +} + +template +pxr::GfMatrix4d ToGfMatrix4d(const Matrix4x4& m) +{ + // clang-format off + return pxr::GfMatrix4d{ + static_cast(m._11), static_cast(m._12), static_cast(m._13), static_cast(m._14), + static_cast(m._21), static_cast(m._22), static_cast(m._23), static_cast(m._24), + static_cast(m._31), static_cast(m._32), static_cast(m._33), static_cast(m._34), + static_cast(m._41), static_cast(m._42), static_cast(m._43), static_cast(m._44), + }; + // clang-format on +} + +template +Matrix4x4 ToMatrix4x4(const pxr::GfMatrix4f& m) +{ + // clang-format off + return Matrix4x4{ + static_cast(m[0][0]), static_cast(m[0][1]), static_cast(m[0][2]), static_cast(m[0][3]), + static_cast(m[1][0]), static_cast(m[1][1]), static_cast(m[1][2]), static_cast(m[1][3]), + static_cast(m[2][0]), static_cast(m[2][1]), static_cast(m[2][2]), static_cast(m[2][3]), + static_cast(m[3][0]), static_cast(m[3][1]), static_cast(m[3][2]), static_cast(m[3][3]), + }; + // clang-format on +} + +template +Matrix4x4 ToMatrix4x4(const pxr::GfMatrix4d& m) +{ + // clang-format off + return Matrix4x4{ + static_cast(m[0][0]), static_cast(m[0][1]), static_cast(m[0][2]), static_cast(m[0][3]), + static_cast(m[1][0]), static_cast(m[1][1]), static_cast(m[1][2]), static_cast(m[1][3]), + static_cast(m[2][0]), static_cast(m[2][1]), static_cast(m[2][2]), static_cast(m[2][3]), + static_cast(m[3][0]), static_cast(m[3][1]), static_cast(m[3][2]), static_cast(m[3][3]), + }; + // clang-format on +} + +} // namespace USD + +} // namespace Diligent