MorphTargetExporter.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/std/optional.h>
  10. #include <Atom/RPI.Reflect/Model/MorphTargetMetaAssetCreator.h>
  11. #include <Model/ModelAssetBuilderComponent.h>
  12. #include <SceneAPI/SceneCore/DataTypes/GraphData/IBlendShapeData.h>
  13. #include <SceneAPI/SceneCore/Utilities/CoordinateSystemConverter.h>
  14. #include <SceneAPI/SceneData/ManifestBase/SceneNodeSelectionList.h>
  15. namespace AZ
  16. {
  17. namespace RPI
  18. {
  19. class MorphTargetExporter
  20. {
  21. public:
  22. AZ_RTTI(MorphTargetExporter, "{A684EBE7-03A2-4877-B6F7-83FC0029CC38}");
  23. void ProduceMorphTargets(
  24. uint32_t productMeshIndex,
  25. uint32_t startVertex,
  26. const AZStd::map<uint32_t, uint32_t>& oldToNewIndicesMap,
  27. const AZ::SceneAPI::Containers::Scene& scene,
  28. const ModelAssetBuilderComponent::SourceMeshContent& sourceMesh,
  29. ModelAssetBuilderComponent::ProductMeshContent& productMesh,
  30. MorphTargetMetaAssetCreator& metaAssetCreator,
  31. const AZ::SceneAPI::CoordinateSystemConverter& coordSysConverter);
  32. private:
  33. struct SourceBlendShapeInfo
  34. {
  35. AZStd::vector<AZ::SceneAPI::Containers::SceneGraph::NodeIndex> m_sceneNodeIndices;
  36. };
  37. //! Retrieve all scene graph nodes per blend shape for all available blend shapes.
  38. AZStd::unordered_map<AZStd::string, SourceBlendShapeInfo> GetBlendShapeInfos(const AZ::SceneAPI::Containers::Scene& scene, const MeshData* meshData) const;
  39. //! Calculate position delta tolerance that is used to indicate whether a given vertex is part of the sparse set of morphed vertices
  40. //! or if it will be skipped and optimized out due to a hardly visible or no movement at all.
  41. float CalcPositionDeltaTolerance(const ModelAssetBuilderComponent::SourceMeshContent& mesh) const;
  42. static constexpr inline float s_positionDeltaTolerance = 0.0025f;
  43. //! Compress float value by using the full range of the storage type as a normalized value within range [minValue, maxValue].
  44. template <class StorageType>
  45. static StorageType Compress(float value, float minValue, float maxValue);
  46. // Extract the morph target vertex and meta data and save it into the product mesh content.
  47. void BuildMorphTargetMesh(
  48. uint32_t productMeshIndex,
  49. uint32_t startVertex,
  50. const AZStd::map<uint32_t, uint32_t>& oldToNewIndicesMap,
  51. const ModelAssetBuilderComponent::SourceMeshContent& sourceMesh,
  52. ModelAssetBuilderComponent::ProductMeshContent& productMesh,
  53. MorphTargetMetaAssetCreator& metaAssetCreator,
  54. const AZStd::string& blendShapeName,
  55. const AZStd::shared_ptr<const AZ::SceneAPI::DataTypes::IBlendShapeData>& blendShapeData,
  56. const AZ::SceneAPI::DataTypes::MatrixType& globalTransform,
  57. const AZ::SceneAPI::CoordinateSystemConverter& coordSysConverter,
  58. const AZStd::string& sourceSceneFilename);
  59. // Find a wrinkle mask for this morph target, if it exists
  60. Data::Asset<RPI::StreamingImageAsset> GetWrinkleMask(const AZStd::string& sourceSceneFullFilePath, const AZStd::string& blendShapeName) const;
  61. };
  62. } // namespace RPI
  63. } // namespace AZ