Files
o3de/Gems/NvCloth/Code/Source/System/TangentSpaceHelper.h
T
2021-03-08 14:30:57 -08:00

87 lines
3.5 KiB
C++

/*
* 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 <AzCore/RTTI/RTTI.h>
#include <AzCore/Interface/Interface.h>
#include <AzCore/std/containers/array.h>
#include <NvCloth/ITangentSpaceHelper.h>
namespace NvCloth
{
//! Implementation of the ITangentSpaceHelper interface.
class TangentSpaceHelper
: public AZ::Interface<ITangentSpaceHelper>::Registrar
{
public:
AZ_RTTI(TangentSpaceHelper, "{2F8400BF-045A-49C3-B9D1-356011907E62}", ITangentSpaceHelper);
protected:
// ITangentSpace overrides ...
bool CalculateNormals(
const AZStd::vector<SimParticleFormat>& vertices,
const AZStd::vector<SimIndexType>& indices,
AZStd::vector<AZ::Vector3>& outNormals) override;
bool CalculateTangentsAndBitagents(
const AZStd::vector<SimParticleFormat>& vertices,
const AZStd::vector<SimIndexType>& indices,
const AZStd::vector<SimUVType>& uvs,
const AZStd::vector<AZ::Vector3>& normals,
AZStd::vector<AZ::Vector3>& outTangents,
AZStd::vector<AZ::Vector3>& outBitangents) override;
bool CalculateTangentSpace(
const AZStd::vector<SimParticleFormat>& vertices,
const AZStd::vector<SimIndexType>& indices,
const AZStd::vector<SimUVType>& uvs,
AZStd::vector<AZ::Vector3>& outTangents,
AZStd::vector<AZ::Vector3>& outBitangents,
AZStd::vector<AZ::Vector3>& outNormals) override;
private:
using TriangleIndices = AZStd::array<SimIndexType, 3>;
using TrianglePositions = AZStd::array<AZ::Vector3, 3>;
using TriangleUVs = AZStd::array<SimUVType, 3>;
using TriangleEdges = AZStd::array<AZ::Vector3, 2>;
void GetTriangleData(
size_t triangleIndex,
const AZStd::vector<SimIndexType>& indices,
const AZStd::vector<SimParticleFormat>& vertices,
TriangleIndices& triangleIndices,
TrianglePositions& trianglePositions,
TriangleEdges& triangleEdges);
void GetTriangleData(
size_t triangleIndex,
const AZStd::vector<SimIndexType>& indices,
const AZStd::vector<SimParticleFormat>& vertices,
const AZStd::vector<SimUVType>& 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