MeshOptimizerComponent.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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/smart_ptr/unique_ptr.h>
  10. #include <AzCore/std/tuple.h>
  11. #include <AzCore/Component/Component.h>
  12. #include <AzCore/Memory/Memory.h>
  13. #include <AzCore/RTTI/RTTI.h>
  14. #include <SceneAPI/SceneCore/Components/GenerationComponent.h>
  15. #include <SceneAPI/SceneCore/Containers/SceneGraph.h>
  16. #include <SceneAPI/SceneCore/Events/ProcessingResult.h>
  17. namespace AZ { class ReflectContext; }
  18. namespace AZ::SceneAPI::DataTypes { class IBlendShapeData; }
  19. namespace AZ::SceneAPI::DataTypes { class IMeshData; }
  20. namespace AZ::SceneAPI::DataTypes { class IMeshGroup; }
  21. namespace AZ::SceneAPI::DataTypes { class IMeshVertexUVData; }
  22. namespace AZ::SceneAPI::DataTypes { class IMeshVertexTangentData; }
  23. namespace AZ::SceneAPI::DataTypes { class IMeshVertexBitangentData; }
  24. namespace AZ::SceneAPI::DataTypes { class ISkinWeightData; }
  25. namespace AZ::SceneAPI::DataTypes { class IMeshVertexColorData; }
  26. namespace AZ::SceneAPI::Events { class GenerateSimplificationEventContext; }
  27. namespace AZ::SceneData::GraphData { class BlendShapeData; }
  28. namespace AZ::SceneData::GraphData { class MeshData; }
  29. namespace AZ::SceneData::GraphData { class MeshVertexBitangentData; }
  30. namespace AZ::SceneData::GraphData { class MeshVertexColorData; }
  31. namespace AZ::SceneData::GraphData { class MeshVertexTangentData; }
  32. namespace AZ::SceneData::GraphData { class MeshVertexUVData; }
  33. namespace AZ::SceneAPI::Containers { class SceneGraph; }
  34. namespace AZ::SceneGenerationComponents
  35. {
  36. class MeshOptimizerComponent
  37. : public AZ::SceneAPI::SceneCore::GenerationComponent
  38. {
  39. public:
  40. AZ_COMPONENT(MeshOptimizerComponent, "{05791580-A464-436C-B3EA-36AD68A42BC8}", AZ::SceneAPI::SceneCore::GenerationComponent)
  41. MeshOptimizerComponent();
  42. static void Reflect(AZ::ReflectContext* context);
  43. AZ::SceneAPI::Events::ProcessingResult OptimizeMeshes(AZ::SceneAPI::Events::GenerateSimplificationEventContext& context) const;
  44. static bool HasAnyBlendShapeChild(const AZ::SceneAPI::Containers::SceneGraph& graph, const AZ::SceneAPI::Containers::SceneGraph::NodeIndex& nodeIndex);
  45. private:
  46. template<class MeshDataType>
  47. static AZStd::tuple<
  48. AZStd::unique_ptr<MeshDataType>,
  49. AZStd::vector<AZStd::unique_ptr<AZ::SceneData::GraphData::MeshVertexUVData>>,
  50. AZStd::vector<AZStd::unique_ptr<AZ::SceneData::GraphData::MeshVertexTangentData>>,
  51. AZStd::vector<AZStd::unique_ptr<AZ::SceneData::GraphData::MeshVertexBitangentData>>,
  52. AZStd::vector<AZStd::unique_ptr<AZ::SceneData::GraphData::MeshVertexColorData>>,
  53. AZStd::unique_ptr<AZ::SceneAPI::DataTypes::ISkinWeightData>
  54. > OptimizeMesh(
  55. const MeshDataType* meshData,
  56. const SceneAPI::DataTypes::IMeshData* baseMesh,
  57. const AZStd::vector<AZStd::reference_wrapper<const AZ::SceneAPI::DataTypes::IMeshVertexUVData>>& uvs,
  58. const AZStd::vector<AZStd::reference_wrapper<const AZ::SceneAPI::DataTypes::IMeshVertexTangentData>>& tangents,
  59. const AZStd::vector<AZStd::reference_wrapper<const AZ::SceneAPI::DataTypes::IMeshVertexBitangentData>>& bitangents,
  60. const AZStd::vector<AZStd::reference_wrapper<const AZ::SceneAPI::DataTypes::IMeshVertexColorData>>& vertexColors,
  61. const AZStd::vector<AZStd::reference_wrapper<const AZ::SceneAPI::DataTypes::ISkinWeightData>>& skinWeights,
  62. const AZ::SceneAPI::DataTypes::IMeshGroup& meshGroup,
  63. bool hasBlendShapes);
  64. static void AddFace(AZ::SceneData::GraphData::BlendShapeData* blendShape, unsigned int index1, unsigned int index2, unsigned int index3, unsigned int faceMaterialId);
  65. static void AddFace(AZ::SceneData::GraphData::MeshData* mesh, unsigned int index1, unsigned int index2, unsigned int index3, unsigned int faceMaterialId);
  66. };
  67. } // namespace AZ::SceneGenerationComponents