Files
o3de/Gems/PhysX/Code/Source/Pipeline/MeshExporter.h
T
Aaron Ruiz Mora 9d41954d0e Added configurable physics materials per asset in PhysX group in FBX Settings. (#1186)
- Added back the' Physics Materials from Asset' tick in the collider components.
- Made physics materials names case insensitive.
- Refactored how to gather material information from fbx and used the same code for exporter and physx groups.
2021-06-10 12:22:16 +01:00

92 lines
3.2 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 <SceneAPI/SceneCore/Components/ExportingComponent.h>
namespace AZ
{
namespace SceneAPI
{
namespace Events
{
class ExportEventContext;
}
namespace Containers
{
class Scene;
class SceneGraph;
}
namespace DataTypes
{
class IMeshData;
}
}
}
namespace PhysX
{
namespace Pipeline
{
class MeshGroup;
class MeshExporter
: public AZ::SceneAPI::SceneCore::ExportingComponent
{
public:
AZ_COMPONENT(MeshExporter, "{4EA8B035-064D-456F-A9BA-0CDA40E9B84C}", AZ::SceneAPI::SceneCore::ExportingComponent);
MeshExporter();
~MeshExporter() override = default;
static void Reflect(AZ::ReflectContext* context);
AZ::SceneAPI::Events::ProcessingResult ProcessContext(AZ::SceneAPI::Events::ExportEventContext& context) const;
private:
AZ::SceneAPI::Events::ProcessingResult ExportMeshObject(AZ::SceneAPI::Events::ExportEventContext& context, const AZStd::shared_ptr<const AZ::SceneAPI::DataTypes::IMeshData>& meshToExport, const AZStd::string& nodePath, const Pipeline::MeshGroup& pxMeshGroup) const;
};
namespace Utils
{
//! A struct to store the materials of the mesh nodes selected in a mesh group.
struct AssetMaterialsData
{
//! Material names coming from FBX.
AZStd::vector<AZStd::string> m_fbxMaterialNames;
//! Look-up table for fbxMaterialNames.
AZStd::unordered_map<AZStd::string, size_t> m_materialIndexByName;
//! Map of mesh nodes to their list of material indices associated to each face.
AZStd::unordered_map<AZStd::string, AZStd::vector<AZ::u16>> m_nodesToPerFaceMaterialIndices;
};
//! Returns the list of materials assigned to the triangles
//! of the mesh nodes selected in a mesh group.
AZStd::optional<AssetMaterialsData> GatherMaterialsFromMeshGroup(
const MeshGroup& meshGroup,
const AZ::SceneAPI::Containers::SceneGraph& sceneGraph);
//! Function to update a list of materials and physics materials from a new list.
//! All those new materials not found in the previous list will fallback to default physics material.
bool UpdateAssetPhysicsMaterials(
const AZStd::vector<AZStd::string>& newMaterials,
AZStd::vector<AZStd::string>& materials,
AZStd::vector<AZStd::string>& physicsMaterials);
} // namespace Utils
} // namespace Pipeline
} // namespace PhysX