/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #pragma once #include #include #include #include namespace NvCloth { //! Implementation of the ITangentSpaceHelper interface. class TangentSpaceHelper : public AZ::Interface::Registrar { public: AZ_RTTI(TangentSpaceHelper, "{2F8400BF-045A-49C3-B9D1-356011907E62}", ITangentSpaceHelper); protected: // ITangentSpace overrides ... bool CalculateNormals( const AZStd::vector& vertices, const AZStd::vector& indices, AZStd::vector& outNormals) override; bool CalculateTangentsAndBitagents( const AZStd::vector& vertices, const AZStd::vector& indices, const AZStd::vector& uvs, const AZStd::vector& normals, AZStd::vector& outTangents, AZStd::vector& outBitangents) override; bool CalculateTangentSpace( const AZStd::vector& vertices, const AZStd::vector& indices, const AZStd::vector& uvs, AZStd::vector& outTangents, AZStd::vector& outBitangents, AZStd::vector& outNormals) override; private: using TriangleIndices = AZStd::array; using TrianglePositions = AZStd::array; using TriangleUVs = AZStd::array; using TriangleEdges = AZStd::array; void GetTriangleData( size_t triangleIndex, const AZStd::vector& indices, const AZStd::vector& vertices, TriangleIndices& triangleIndices, TrianglePositions& trianglePositions, TriangleEdges& triangleEdges); void GetTriangleData( size_t triangleIndex, const AZStd::vector& indices, const AZStd::vector& vertices, const AZStd::vector& uvs, TriangleIndices& triangleIndices, TrianglePositions& trianglePositions, TriangleEdges& triangleEdges, TriangleUVs& triangleUVs); bool ComputeNormal(const TriangleEdges& triangleEdges, AZ::Vector3& normal); bool ComputeTangentAndBitangent( const TriangleUVs& triangleUVs, const TriangleEdges& triangleEdges, AZ::Vector3& tangent, AZ::Vector3& bitangent); void AdjustTangentAndBitangent( const AZ::Vector3& normal, AZ::Vector3& tangent, AZ::Vector3& bitangent); float GetVertexWeightInTriangle(AZ::u32 vertexIndexInTriangle, const TrianglePositions& trianglePositions); }; } // namespace NvCloth