Integrating up through commit 90f050496

This commit is contained in:
alexpete
2021-04-07 14:03:29 -07:00
parent 8f2ed080a9
commit c2cbd430fe
2694 changed files with 285622 additions and 176874 deletions
@@ -1,48 +0,0 @@
/*
* 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.
*
*/
#include <RC/ResourceCompilerScene/Chr/ChrExportContexts.h>
namespace AZ
{
namespace RC
{
ChrGroupExportContext::ChrGroupExportContext(SceneAPI::Events::ExportEventContext& parent,
const SceneAPI::DataTypes::ISkeletonGroup& group, Phase phase)
: m_products(parent.GetProductList())
, m_scene(parent.GetScene())
, m_outputDirectory(parent.GetOutputDirectory())
, m_group(group)
, m_phase(phase)
{
}
ChrGroupExportContext::ChrGroupExportContext(SceneAPI::Events::ExportProductList& products, const SceneAPI::Containers::Scene& scene,
const AZStd::string& outputDirectory, const SceneAPI::DataTypes::ISkeletonGroup& group, Phase phase)
: m_products(products)
, m_scene(scene)
, m_outputDirectory(outputDirectory)
, m_group(group)
, m_phase(phase)
{
}
ChrGroupExportContext::ChrGroupExportContext(const ChrGroupExportContext& copyContext, Phase phase)
: m_products(copyContext.m_products)
, m_scene(copyContext.m_scene)
, m_outputDirectory(copyContext.m_outputDirectory)
, m_group(copyContext.m_group)
, m_phase(phase)
{
}
}
}
@@ -1,59 +0,0 @@
#pragma once
/*
* 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.
*
*/
#include <AzCore/RTTI/RTTI.h>
#include <SceneAPI/SceneCore/Events/CallProcessorBus.h>
#include <SceneAPI/SceneCore/Events/ExportEventContext.h>
#include <RC/ResourceCompilerScene/Common/ExportContextGlobal.h>
namespace AZ
{
namespace SceneAPI
{
namespace DataTypes
{
class ISkeletonGroup;
}
namespace Events
{
class ExportProductList;
}
}
namespace RC
{
// Called to export a specific Skeleton (Chr) Group
struct ChrGroupExportContext
: public SceneAPI::Events::ICallContext
{
AZ_RTTI(ChrGroupExportContext, "{294BB98B-DE9D-4B03-B219-A8A94657E81E}", SceneAPI::Events::ICallContext);
ChrGroupExportContext(SceneAPI::Events::ExportEventContext& parent,
const SceneAPI::DataTypes::ISkeletonGroup& group, Phase phase);
ChrGroupExportContext(SceneAPI::Events::ExportProductList& products, const SceneAPI::Containers::Scene& scene,
const AZStd::string& outputDirectory, const SceneAPI::DataTypes::ISkeletonGroup& group, Phase phase);
ChrGroupExportContext(const ChrGroupExportContext& copyContent, Phase phase);
ChrGroupExportContext(const ChrGroupExportContext& copyContent) = delete;
~ChrGroupExportContext() override = default;
ChrGroupExportContext& operator=(const ChrGroupExportContext& other) = delete;
SceneAPI::Events::ExportProductList& m_products;
const SceneAPI::Containers::Scene& m_scene;
const AZStd::string& m_outputDirectory;
const SceneAPI::DataTypes::ISkeletonGroup& m_group;
const Phase m_phase;
};
}
}
@@ -1,58 +0,0 @@
/*
* 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.
*
*/
#include <RC/ResourceCompilerScene/Chr/ChrExporter.h>
#include <Cry_Geo.h>
#include <ConvertContext.h>
#include <CGFContent.h>
#include <AzToolsFramework/Debug/TraceContext.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Containers/SceneManifest.h>
#include <SceneAPI/SceneCore/Containers/Utilities/Filters.h>
#include <SceneAPI/SceneCore/DataTypes/Groups/ISkeletonGroup.h>
#include <SceneAPI/SceneCore/Events/ExportEventContext.h>
#include <RC/ResourceCompilerScene/Chr/ChrExportContexts.h>
namespace AZ
{
namespace RC
{
namespace SceneContainers = AZ::SceneAPI::Containers;
namespace SceneDataTypes = AZ::SceneAPI::DataTypes;
ChrExporter::ChrExporter(IConvertContext* convertContext)
: m_convertContext(convertContext)
{
BindToCall(&ChrExporter::ProcessContext);
ActivateBindings();
}
SceneEvents::ProcessingResult ChrExporter::ProcessContext(SceneEvents::ExportEventContext& context)
{
const SceneContainers::SceneManifest& manifest = context.GetScene().GetManifest();
auto valueStorage = manifest.GetValueStorage();
auto view = SceneContainers::MakeDerivedFilterView<SceneDataTypes::ISkeletonGroup>(valueStorage);
SceneEvents::ProcessingResultCombiner result;
for (const SceneDataTypes::ISkeletonGroup& skeletonGroup : view)
{
AZ_TraceContext("Skeleton Group", skeletonGroup.GetName());
result += SceneEvents::Process<ChrGroupExportContext>(context, skeletonGroup, Phase::Construction);
result += SceneEvents::Process<ChrGroupExportContext>(context, skeletonGroup, Phase::Filling);
result += SceneEvents::Process<ChrGroupExportContext>(context, skeletonGroup, Phase::Finalizing);
}
return result.GetResult();
}
} // namespace RC
} // namespace AZ
@@ -1,46 +0,0 @@
/*
* 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/Events/CallProcessorBinder.h>
struct IConvertContext;
namespace AZ
{
namespace SceneAPI
{
namespace Events
{
class ExportEventContext;
}
}
namespace RC
{
namespace SceneEvents = AZ::SceneAPI::Events;
class ChrExporter
: public SceneEvents::CallProcessorBinder
{
public:
ChrExporter(IConvertContext* convertContext);
~ChrExporter() override = default;
SceneEvents::ProcessingResult ProcessContext(SceneEvents::ExportEventContext& context);
private:
IConvertContext* m_convertContext;
};
} // namespace RC
} // namespace AZ
@@ -1,131 +0,0 @@
/*
* 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.
*
*/
#include <Cry_Geo.h> // Needed for CGFContent.h
#include <CGFContent.h>
#include <AzFramework/StringFunc/StringFunc.h>
#include <RC/ResourceCompilerScene/Common/CommonExportContexts.h>
#include <RC/ResourceCompilerScene/Chr/ChrExportContexts.h>
#include <RC/ResourceCompilerScene/Chr/ChrGroupExporter.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/DataTypes/Groups/ISkeletonGroup.h>
#include <SceneAPI/SceneCore/Events/ExportProductList.h>
#include <SceneAPI/SceneCore/Utilities/FileUtilities.h>
#include <SceneAPI/SceneCore/Utilities/Reporting.h>
namespace AZ
{
namespace RC
{
namespace SceneUtil = AZ::SceneAPI::Utilities;
namespace SceneContainer = AZ::SceneAPI::Containers;
namespace SceneDataTypes = AZ::SceneAPI::DataTypes;
const AZStd::string ChrGroupExporter::fileExtension = "chr";
ChrGroupExporter::ChrGroupExporter(IAssetWriter* writer, IConvertContext* convertContext)
: m_assetWriter(writer)
, m_convertContext(convertContext)
{
BindToCall(&ChrGroupExporter::ProcessContext);
ActivateBindings();
}
SceneEvents::ProcessingResult ChrGroupExporter::ProcessContext(ChrGroupExportContext& context) const
{
if (context.m_phase != Phase::Filling)
{
return SceneEvents::ProcessingResult::Ignored;
}
AZStd::string filename = SceneUtil::FileUtilities::CreateOutputFileName(context.m_group.GetName(), context.m_outputDirectory, fileExtension);
if (filename.empty())
{
AZ_TracePrintf(SceneUtil::ErrorWindow, "Invalid filename, can not be an empty value.\n");
return SceneEvents::ProcessingResult::Failure;
}
if (!SceneUtil::FileUtilities::EnsureTargetFolderExists(filename))
{
AZ_TracePrintf(SceneUtil::ErrorWindow, "Invalid filename, target folder does not exist. ('%s')\n", filename.c_str());
return SceneEvents::ProcessingResult::Failure;
}
SceneEvents::ProcessingResultCombiner result;
CContentCGF cgfContent(filename.c_str());
AZStd::unordered_map<AZStd::string, int> boneNameIdMap;
SkeletonExportContext skeletonContextConstruction(context.m_scene, context.m_group.GetSelectedRootBone(), *cgfContent.GetSkinningInfo(), boneNameIdMap, Phase::Construction);
ConfigureChrContent(cgfContent);
result += SceneEvents::Process(skeletonContextConstruction);
result += SceneEvents::Process<SkeletonExportContext>(context.m_scene, context.m_group.GetSelectedRootBone(), *cgfContent.GetSkinningInfo(), boneNameIdMap, Phase::Filling);
result += SceneEvents::Process<SkeletonExportContext>(context.m_scene, context.m_group.GetSelectedRootBone(), *cgfContent.GetSkinningInfo(), boneNameIdMap, Phase::Finalizing);
AZ_Assert(m_assetWriter != nullptr, "Unable to write CHR due to invalid asset writer.");
if (m_assetWriter)
{
if (m_assetWriter->WriteCHR(&cgfContent, m_convertContext))
{
static const AZ::Data::AssetType skeletonAssetType("{60161B46-21F0-4396-A4F0-F2CCF0664CDE}");
auto& list = context.m_products.GetProducts();
bool isFirst = AZStd::find_if(list.begin(), list.end(),
[](const SceneAPI::Events::ExportProduct& it) -> bool
{
return it.m_assetType == skeletonAssetType;
}) == list.end();
SceneAPI::Events::ExportProduct& product = context.m_products.AddProduct(AZStd::move(filename), context.m_group.GetId(), skeletonAssetType,
AZStd::nullopt, AZStd::nullopt);
// Previously only a single skeleton would be exported that was named after the source file. This was changed to exporting all
// skeletons now named after the root node. This means that the first skeleton would previously have been known under
// another name.
if (isFirst)
{
AZStd::string legacyName = product.m_filename;
AzFramework::StringFunc::Path::ReplaceFullName(legacyName, context.m_scene.GetName().c_str(), fileExtension.c_str());
product.m_legacyFileNames.emplace_back(AZStd::move(legacyName));
}
}
else
{
AZ_TracePrintf(SceneUtil::ErrorWindow, "Failed writing CHR file ('%s')\n", filename.c_str());
result += SceneEvents::ProcessingResult::Failure;
}
}
else
{
AZ_TracePrintf(SceneUtil::ErrorWindow, "Failed writing CHR file ('%s')\n", filename.c_str());
result += SceneEvents::ProcessingResult::Failure;
}
return result.GetResult();
}
void ChrGroupExporter::ConfigureChrContent(CContentCGF& content) const
{
CExportInfoCGF* exportInfo = content.GetExportInfo();
AZ_Assert(exportInfo != nullptr, "Invalid export info from %s.", content.GetFilename());
exportInfo->bMergeAllNodes = true;
exportInfo->bUseCustomNormals = false;
exportInfo->bCompiledCGF = false;
exportInfo->bHavePhysicsProxy = false;
exportInfo->bHaveAutoLods = false;
exportInfo->bNoMesh = true;
exportInfo->b8WeightsPerVertex = false;
exportInfo->bWantF32Vertices = false;
exportInfo->authorToolVersion = 1;
}
} // namespace RC
} // namespace AZ
@@ -1,47 +0,0 @@
/*
* 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/std/string/string.h>
#include <SceneAPI/SceneCore/Events/CallProcessorBinder.h>
struct IConvertContext;
class CContentCGF;
namespace AZ
{
namespace RC
{
struct ChrGroupExportContext;
namespace SceneEvents = AZ::SceneAPI::Events;
class ChrGroupExporter
: public SceneEvents::CallProcessorBinder
{
public:
ChrGroupExporter(IAssetWriter* writer, IConvertContext* convertContext);
~ChrGroupExporter() override = default;
SceneEvents::ProcessingResult ProcessContext(ChrGroupExportContext& context) const;
static const AZStd::string fileExtension;
protected:
void ConfigureChrContent(CContentCGF& content) const;
IAssetWriter* m_assetWriter;
IConvertContext* m_convertContext;
};
} // namespace RC
} // namespace AZ
@@ -1,48 +0,0 @@
/*
* 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.
*
*/
#include <RC/ResourceCompilerScene/Skin/SkinExportContexts.h>
namespace AZ
{
namespace RC
{
SkinGroupExportContext::SkinGroupExportContext(SceneAPI::Events::ExportEventContext& parent,
const SceneAPI::DataTypes::ISkinGroup& group, Phase phase)
: m_products(parent.GetProductList())
, m_scene(parent.GetScene())
, m_outputDirectory(parent.GetOutputDirectory())
, m_group(group)
, m_phase(phase)
{
}
SkinGroupExportContext::SkinGroupExportContext(SceneAPI::Events::ExportProductList& products, const SceneAPI::Containers::Scene& scene,
const AZStd::string& outputDirectory, const SceneAPI::DataTypes::ISkinGroup& group, Phase phase)
: m_products(products)
, m_scene(scene)
, m_outputDirectory(outputDirectory)
, m_group(group)
, m_phase(phase)
{
}
SkinGroupExportContext::SkinGroupExportContext(const SkinGroupExportContext& copyContext, Phase phase)
: m_products(copyContext.m_products)
, m_scene(copyContext.m_scene)
, m_outputDirectory(copyContext.m_outputDirectory)
, m_group(copyContext.m_group)
, m_phase(phase)
{
}
}
}
@@ -1,57 +0,0 @@
#pragma once
/*
* 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.
*
*/
#include <AzCore/RTTI/RTTI.h>
#include <SceneAPI/SceneCore/Events/CallProcessorBus.h>
#include <SceneAPI/SceneCore/Events/ExportEventContext.h>
#include <RC/ResourceCompilerScene/Common/ExportContextGlobal.h>
struct CSkinningInfo;
namespace AZ
{
namespace SceneAPI
{
namespace DataTypes
{
class ISkinGroup;
}
}
namespace RC
{
// Called to export a specific Skin Group
struct SkinGroupExportContext
: public SceneAPI::Events::ICallContext
{
AZ_RTTI(SkinGroupExportContext, "{F2C0DF6D-84F7-4692-9626-C981FA599755}", SceneAPI::Events::ICallContext);
SkinGroupExportContext(SceneAPI::Events::ExportEventContext& parent,
const SceneAPI::DataTypes::ISkinGroup& group, Phase phase);
SkinGroupExportContext(SceneAPI::Events::ExportProductList& products, const SceneAPI::Containers::Scene& scene,
const AZStd::string& outputDirectory, const SceneAPI::DataTypes::ISkinGroup& group, Phase phase);
SkinGroupExportContext(const SkinGroupExportContext& copyContent, Phase phase);
SkinGroupExportContext(const SkinGroupExportContext& copyContent) = delete;
~SkinGroupExportContext() override = default;
SkinGroupExportContext& operator=(const SkinGroupExportContext& other) = delete;
SceneAPI::Events::ExportProductList& m_products;
const SceneAPI::Containers::Scene& m_scene;
const AZStd::string& m_outputDirectory;
const SceneAPI::DataTypes::ISkinGroup& m_group;
const Phase m_phase;
};
}
}
@@ -1,59 +0,0 @@
/*
* 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.
*
*/
#include <RC/ResourceCompilerScene/Skin/SkinExporter.h>
#include <Cry_Geo.h>
#include <ConvertContext.h>
#include <CGFContent.h>
#include <AzToolsFramework/Debug/TraceContext.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Containers/SceneManifest.h>
#include <SceneAPI/SceneCore/Containers/Utilities/Filters.h>
#include <SceneAPI/SceneCore/DataTypes/Groups/ISkinGroup.h>
#include <SceneAPI/SceneCore/Events/ExportEventContext.h>
#include <RC/ResourceCompilerScene/Skin/SkinExportContexts.h>
namespace AZ
{
namespace RC
{
namespace SceneContainers = AZ::SceneAPI::Containers;
namespace SceneDataTypes = AZ::SceneAPI::DataTypes;
SkinExporter::SkinExporter(IConvertContext* convertContext)
: m_convertContext(convertContext)
{
BindToCall(&SkinExporter::ProcessContext);
ActivateBindings();
}
SceneEvents::ProcessingResult SkinExporter::ProcessContext(SceneEvents::ExportEventContext& context)
{
const SceneContainers::SceneManifest& manifest = context.GetScene().GetManifest();
auto valueStorage = manifest.GetValueStorage();
auto view = SceneContainers::MakeDerivedFilterView<SceneDataTypes::ISkinGroup>(valueStorage);
SceneEvents::ProcessingResultCombiner result;
for (const SceneDataTypes::ISkinGroup& skinGroup : view)
{
AZ_TraceContext("Skin Group", skinGroup.GetName());
result += SceneEvents::Process<SkinGroupExportContext>(context, skinGroup, Phase::Construction);
result += SceneEvents::Process<SkinGroupExportContext>(context, skinGroup, Phase::Filling);
result += SceneEvents::Process<SkinGroupExportContext>(context, skinGroup, Phase::Finalizing);
}
return result.GetResult();
}
} // namespace RC
} // namespace AZ
@@ -1,49 +0,0 @@
/*
* 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/Events/CallProcessorBinder.h>
namespace AZ
{
namespace SceneAPI
{
namespace Events
{
class ExportEventContext;
}
}
}
struct IConvertContext;
namespace AZ
{
namespace RC
{
namespace SceneEvents = AZ::SceneAPI::Events;
class SkinExporter
: public SceneEvents::CallProcessorBinder
{
public:
SkinExporter(IConvertContext* convertContext);
~SkinExporter() override = default;
SceneEvents::ProcessingResult ProcessContext(SceneEvents::ExportEventContext& context);
private:
IConvertContext* m_convertContext;
};
} // namespace RC
} // namespace AZ
@@ -1,93 +0,0 @@
/*
* 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.
*
*/
#include <Cry_Geo.h> // Needed for CGFContent.h
#include <CGFContent.h>
#include <AzCore/std/containers/map.h>
#include <AzToolsFramework/Debug/TraceContext.h>
#include <RC/ResourceCompilerScene/Common/CommonExportContexts.h>
#include <RC/ResourceCompilerScene/Skin/SkinExportContexts.h>
#include <RC/ResourceCompilerScene/Skin/SkinGroupExporter.h>
#include <RC/ResourceCompilerScene/Skin/SkinUtils.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Utilities/SceneGraphSelector.h>
#include <SceneAPI/SceneCore/DataTypes/ManifestBase/ISceneNodeSelectionList.h>
#include <SceneAPI/SceneCore/DataTypes/Groups/ISkinGroup.h>
#include <SceneAPI/SceneCore/Events/ExportProductList.h>
#include <SceneAPI/SceneCore/Utilities/FileUtilities.h>
#include <SceneAPI/SceneCore/Utilities/Reporting.h>
namespace AZ
{
namespace RC
{
namespace SceneUtil = AZ::SceneAPI::Utilities;
namespace SceneContainer = AZ::SceneAPI::Containers;
const AZStd::string SkinGroupExporter::s_fileExtension = "skin";
SkinGroupExporter::SkinGroupExporter(IAssetWriter* writer, IConvertContext* convertContext)
: m_assetWriter(writer)
, m_convertContext(convertContext)
{
BindToCall(&SkinGroupExporter::ProcessContext);
ActivateBindings();
}
SceneEvents::ProcessingResult SkinGroupExporter::ProcessContext(SkinGroupExportContext& context) const
{
if (context.m_phase != Phase::Filling)
{
return SceneEvents::ProcessingResult::Ignored;
}
AZStd::string filename = SceneUtil::FileUtilities::CreateOutputFileName(context.m_group.GetName(), context.m_outputDirectory, s_fileExtension);
AZ_TraceContext("Skin filename", filename);
if (filename.empty() || !SceneUtil::FileUtilities::EnsureTargetFolderExists(filename))
{
AZ_TracePrintf(AZ::SceneAPI::Utilities::ErrorWindow, "Invalid file name for skin");
return SceneEvents::ProcessingResult::Failure;
}
SceneEvents::ProcessingResultCombiner result;
CContentCGF cgfContent(filename.c_str());
ConfigureSkinContent(cgfContent);
// Process mesh
// For each selected mesh, find its skinned skeleton's root bone. Make sure the root bone is consistent through all selected skin meshes.
const SceneContainer::SceneGraph& graph = context.m_scene.GetGraph();
AZStd::vector<AZStd::string> targetNodes = SceneUtil::SceneGraphSelector::GenerateTargetNodes(graph,
context.m_group.GetSceneNodeSelectionList(), SceneUtil::SceneGraphSelector::IsMesh);
result += ProcessSkins(context, cgfContent, targetNodes);
if (m_assetWriter)
{
if (m_assetWriter->WriteSKIN(&cgfContent, m_convertContext, true))
{
static const AZ::Data::AssetType skinnedMeshAssetType("{C5D443E1-41FF-4263-8654-9438BC888CB7}"); // from MeshAsset.h
context.m_products.AddProduct(AZStd::move(filename), context.m_group.GetId(), skinnedMeshAssetType, 0, AZStd::nullopt);
}
else
{
AZ_TracePrintf(AZ::SceneAPI::Utilities::ErrorWindow, "Writing Skin has failed.");
result += SceneEvents::ProcessingResult::Failure;
}
}
else
{
AZ_TracePrintf(AZ::SceneAPI::Utilities::ErrorWindow, "No asset writer found. Unable to write skin to disk");
result += SceneEvents::ProcessingResult::Failure;
}
return result.GetResult();
}
} // namespace RC
} // namespace AZ
@@ -1,44 +0,0 @@
/*
* 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/std/string/string.h>
#include <SceneAPI/SceneCore/Events/CallProcessorBinder.h>
struct IConvertContext;
namespace AZ
{
namespace RC
{
struct SkinGroupExportContext;
namespace SceneEvents = AZ::SceneAPI::Events;
class SkinGroupExporter
: public SceneEvents::CallProcessorBinder
{
public:
SkinGroupExporter(IAssetWriter* writer, IConvertContext* convertContext);
~SkinGroupExporter() override = default;
SceneEvents::ProcessingResult ProcessContext(SkinGroupExportContext& context) const;
static const AZStd::string s_fileExtension;
protected:
IAssetWriter* m_assetWriter;
IConvertContext* m_convertContext;
};
} // namespace RC
} // namespace AZ
@@ -1,117 +0,0 @@
/*
* 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.
*
*/
#include <Cry_Geo.h> // Needed for CGFContent.h
#include <CGFContent.h>
#include <AzCore/std/containers/map.h>
#include <AzCore/std/string/conversions.h>
#include <AzToolsFramework/Debug/TraceContext.h>
#include <RC/ResourceCompilerScene/Common/CommonExportContexts.h>
#include <RC/ResourceCompilerScene/Cgf/CgfUtils.h>
#include <RC/ResourceCompilerScene/Skin/SkinExportContexts.h>
#include <RC/ResourceCompilerScene/Skin/SkinLodExporter.h>
#include <RC/ResourceCompilerScene/Skin/SkinUtils.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Utilities/SceneGraphSelector.h>
#include <SceneAPI/SceneCore/DataTypes/DataTypeUtilities.h>
#include <SceneAPI/SceneCore/DataTypes/ManifestBase/ISceneNodeSelectionList.h>
#include <SceneAPI/SceneCore/DataTypes/Groups/ISkinGroup.h>
#include <SceneAPI/SceneCore/DataTypes/Rules/ILodRule.h>
#include <SceneAPI/SceneCore/Events/ExportProductList.h>
#include <SceneAPI/SceneCore/Utilities/FileUtilities.h>
#include <SceneAPI/SceneCore/Utilities/Reporting.h>
namespace AZ
{
namespace RC
{
namespace SceneUtil = AZ::SceneAPI::Utilities;
namespace SceneContainer = AZ::SceneAPI::Containers;
namespace SceneDataTypes = AZ::SceneAPI::DataTypes;
const AZStd::string SkinLodExporter::s_fileExtension = "skin";
SkinLodExporter::SkinLodExporter(IAssetWriter* writer, IConvertContext* convertContext)
: m_assetWriter(writer)
, m_convertContext(convertContext)
{
BindToCall(&SkinLodExporter::ProcessContext);
ActivateBindings();
}
SceneEvents::ProcessingResult SkinLodExporter::ProcessContext(SkinGroupExportContext& context) const
{
if (context.m_phase != Phase::Filling)
{
return SceneEvents::ProcessingResult::Ignored;
}
AZStd::shared_ptr<const SceneDataTypes::ILodRule> lodRule = context.m_group.GetRuleContainerConst().FindFirstByType<SceneDataTypes::ILodRule>();
if (!lodRule)
{
return SceneEvents::ProcessingResult::Ignored;
}
SceneEvents::ProcessingResultCombiner result;
for (size_t index = 0; index < lodRule->GetLodCount(); ++index)
{
AZ_TraceContext("Skin lod level", static_cast<uint64_t>(index));
AZStd::string filename = SceneUtil::FileUtilities::CreateOutputFileName(
context.m_group.GetName() + "_LOD" + AZStd::to_string(static_cast<int>(index + 1)), context.m_outputDirectory, s_fileExtension);
AZ_TraceContext("Skin lod filename", filename);
if (filename.empty() || !SceneUtil::FileUtilities::EnsureTargetFolderExists(filename))
{
AZ_TracePrintf(AZ::SceneAPI::Utilities::ErrorWindow, "Invalid file name for skin");
result += SceneEvents::ProcessingResult::Failure;
break;
}
CContentCGF cgfContent(filename.c_str());
ConfigureSkinContent(cgfContent);
// Process mesh
// For each selected mesh, find its skinned skeleton's root bone. Make sure the root bone is consistent through all selected skin meshes.
const SceneContainer::SceneGraph& graph = context.m_scene.GetGraph();
AZStd::vector<AZStd::string> targetNodes = SceneUtil::SceneGraphSelector::GenerateTargetNodes(graph,
lodRule->GetSceneNodeSelectionList(index), SceneUtil::SceneGraphSelector::IsMesh);
result += ProcessSkins(context, cgfContent, targetNodes);
if (m_assetWriter)
{
if (m_assetWriter->WriteSKIN(&cgfContent, m_convertContext, false))
{
static const AZ::Data::AssetType skinnedMeshLodsAssetType("{58E5824F-C27B-46FD-AD48-865BA41B7A51}");
// Using the same guid as the parent group/cgf as this needs to be a lod of that cgf.
// Setting the lod to index+1 as 0 means the base mesh and 1-6 are lod levels 0-5.
context.m_products.AddProduct(AZStd::move(filename), context.m_group.GetId(), skinnedMeshLodsAssetType, index + 1, AZStd::nullopt);
}
else
{
AZ_TracePrintf(AZ::SceneAPI::Utilities::ErrorWindow, "Writing Skin has failed.");
result += SceneEvents::ProcessingResult::Failure;
break;
}
}
else
{
AZ_TracePrintf(AZ::SceneAPI::Utilities::ErrorWindow, "No asset writer found. Unable to write skin to disk");
result += SceneEvents::ProcessingResult::Failure;
break;
}
}
return result.GetResult();
}
} // namespace RC
} // namespace AZ
@@ -1,45 +0,0 @@
/*
* 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/std/string/string.h>
#include <SceneAPI/SceneCore/Events/CallProcessorBinder.h>
struct IConvertContext;
class CContentCGF;
namespace AZ
{
namespace RC
{
struct SkinGroupExportContext;
namespace SceneEvents = AZ::SceneAPI::Events;
class SkinLodExporter
: public SceneEvents::CallProcessorBinder
{
public:
SkinLodExporter(IAssetWriter* writer, IConvertContext* convertContext);
~SkinLodExporter() override = default;
SceneEvents::ProcessingResult ProcessContext(SkinGroupExportContext& context) const;
static const AZStd::string s_fileExtension;
protected:
IAssetWriter* m_assetWriter;
IConvertContext* m_convertContext;
};
} // namespace RC
} // namespace AZ
@@ -1,194 +0,0 @@
/*
* 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.
*
*/
#include <Cry_Geo.h> // Needed for CGFContent.h
#include <CGFContent.h>
#include <AzCore/std/containers/map.h>
#include <AzToolsFramework/Debug/TraceContext.h>
#include <RC/ResourceCompilerScene/Common/CommonExportContexts.h>
#include <RC/ResourceCompilerScene/Skin/SkinExportContexts.h>
#include <RC/ResourceCompilerScene/Skin/SkinGroupExporter.h>
#include <RC/ResourceCompilerScene/Cgf/CgfUtils.h>
#include <RC/ResourceCompilerScene/Skin/SkinUtils.h>
#include <RC/ResourceCompilerScene/Skin/SkinExportContexts.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/DataTypes/Groups/ISkinGroup.h>
#include <SceneAPI/SceneCore/Utilities/FileUtilities.h>
#include <SceneAPI/SceneCore/Utilities/Reporting.h>
namespace AZ
{
namespace RC
{
void ConfigureSkinContent(CContentCGF& content)
{
CExportInfoCGF* exportInfo = content.GetExportInfo();
exportInfo->bMergeAllNodes = true;
exportInfo->bUseCustomNormals = false;
exportInfo->bCompiledCGF = false;
exportInfo->bHavePhysicsProxy = false;
exportInfo->bHaveAutoLods = false;
exportInfo->bNoMesh = true;
exportInfo->b8WeightsPerVertex = false;
exportInfo->bWantF32Vertices = false;
exportInfo->authorToolVersion = 1;
}
void MergeToFirstNodeMesh(CContentCGF& content)
{
AZ_Assert(content.GetNodeCount() > 0, "Skin Mesh has no node to merge");
if (content.GetNodeCount() == 0)
{
return;
}
CMesh* mergedMesh = content.GetNode(0)->pMesh;
AZ_Assert(mergedMesh, "Failed to retrieve merged mesh for content root node");
if (!mergedMesh)
{
return;
}
for (size_t nodeIndex = 0; nodeIndex < content.GetNodeCount(); ++nodeIndex)
{
CNodeCGF* node = content.GetNode(nodeIndex);
AZ_Assert(node, "Failed to retrieve node at index %i", nodeIndex);
if (!node)
{
continue;
}
if (!node->bIdentityMatrix)
{
AZ_Assert(node->pMesh, "No mesh node set on CGF node at index %i", nodeIndex);
if (!node->pMesh)
{
continue;
}
for (size_t vertexIndex = 0; vertexIndex < node->pMesh->GetVertexCount(); ++vertexIndex)
{
node->pMesh->m_pPositions[vertexIndex] = node->worldTM.TransformPoint(node->pMesh->m_pPositions[vertexIndex]);
node->pMesh->m_pNorms[vertexIndex].RotateSafelyBy(node->worldTM);
}
}
if (nodeIndex > 0)
{
mergedMesh->Append(*node->pMesh);
// Keep color stream in sync size with vertex/normals stream. Reference to CGFNodeMerger::MergeNodes
if (mergedMesh->m_streamSize[CMesh::COLORS][0] > 0 && mergedMesh->m_streamSize[CMesh::COLORS][0] < mergedMesh->GetVertexCount())
{
int colorCount = mergedMesh->m_streamSize[CMesh::COLORS][0];
mergedMesh->ReallocStream(CMesh::COLORS, 0, mergedMesh->GetVertexCount());
memset(mergedMesh->m_pColor0 + colorCount, 255, (mergedMesh->GetVertexCount() - colorCount) * sizeof(SMeshColor));
}
}
}
// We already used the transform during merge, so clear it out
content.GetNode(0)->worldTM.SetIdentity();
}
void RemoveRedundantNodes(CContentCGF& content)
{
while (content.GetNodeCount() > 1)
{
CNodeCGF* deleteNode = content.GetNode(content.GetNodeCount() - 1);
content.RemoveNode(deleteNode);
}
}
SceneAPI::Events::ProcessingResult ProcessSkins(SkinGroupExportContext& context, CContentCGF& content, AZStd::vector<AZStd::string>& targetNodes)
{
namespace SceneEvents = SceneAPI::Events;
if (targetNodes.empty())
{
AZ_TracePrintf(SceneAPI::Utilities::WarningWindow, "No nodes selected for mesh exporting.");
return SceneEvents::ProcessingResult::Ignored;
}
SceneEvents::ProcessingResultCombiner result;
ContainerExportContext containerContext(context.m_scene, context.m_outputDirectory, context.m_group, content, Phase::Construction);
result += SceneEvents::Process(containerContext);
result += SceneEvents::Process<ContainerExportContext>(containerContext, Phase::Filling);
const EPhysicsGeomType physicalizeType = PHYS_GEOM_TYPE_NONE;
AZStd::string rootBoneName;
const SceneAPI::Containers::SceneGraph& graph = context.m_scene.GetGraph();
AZStd::string currentRootBoneName;
for (const AZStd::string& nodeName : targetNodes)
{
AZ_TraceContext("Skin mesh", nodeName);
SceneAPI::Containers::SceneGraph::NodeIndex index = graph.Find(nodeName.c_str());
if (index.IsValid())
{
// Pick the target skeleton from the first node, then make sure all the remaining meshes are referencing the same skeleton
// as the skins need to merged to a single mesh at the end.
SceneEvents::ProcessingResult rootNameResult = SceneEvents::Process<ResolveRootBoneFromNodeContext>(currentRootBoneName, context.m_scene, index);
if (rootNameResult != SceneEvents::ProcessingResult::Success || currentRootBoneName.empty())
{
AZ_TracePrintf(SceneAPI::Utilities::WarningWindow, "Selected skin has no weight data.");
continue;
}
if (rootBoneName.empty())
{
rootBoneName = currentRootBoneName;
// The skeleton has been established so fill up the skinning information for it as there's still
// a strong link between skin and skeleton.
SceneEvents::ProcessingResult skinInfoResult = SceneEvents::Process<AddBonesToSkinningInfoContext>(
*content.GetSkinningInfo(), context.m_scene, rootBoneName);
if (skinInfoResult != SceneEvents::ProcessingResult::Success)
{
// Without the skinning info further processing will cause a crash so early out here.
AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Unable to link bones to skin.");
return SceneEvents::ProcessingResult::Failure;
}
}
else if (rootBoneName != currentRootBoneName)
{
AZ_TracePrintf(SceneAPI::Utilities::WarningWindow, "Skin doesn't belong to the same skeleton as the rest of the meshes in the group.");
continue;
}
CNodeCGF* node = new CNodeCGF(); // will be auto deleted by CContentCGF cgf
SetNodeName(nodeName, *node);
result += SceneAPI::Events::Process<NodeExportContext>(containerContext, *node, nodeName, index, physicalizeType, rootBoneName, Phase::Construction);
result += SceneAPI::Events::Process<NodeExportContext>(containerContext, *node, nodeName, index, physicalizeType, rootBoneName, Phase::Filling);
content.AddNode(node);
result += SceneAPI::Events::Process<NodeExportContext>(containerContext, *node, nodeName, index, physicalizeType, rootBoneName, Phase::Finalizing);
currentRootBoneName.clear();
}
}
if (content.GetNodeCount() > 0)
{
// CharacterCompiler expects all skin sub-meshes to be merged and stored in a single CNodeCGF
MergeToFirstNodeMesh(content);
result += SceneAPI::Events::Process<ContainerExportContext>(containerContext, Phase::Finalizing);
RemoveRedundantNodes(content);
}
else
{
AZ_TracePrintf(SceneAPI::Utilities::WarningWindow, "No valid skin information found that could be added to this container.");
result += SceneAPI::Events::Process<ContainerExportContext>(containerContext, Phase::Finalizing);
}
return result.GetResult();
}
}
}
@@ -1,31 +0,0 @@
/*
* 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/std/string/string.h>
#include <SceneAPI/SceneCore/Events/ProcessingResult.h>
class CContentCGF;
struct CNodeCGF;
namespace AZ
{
namespace RC
{
struct SkinGroupExportContext;
void ConfigureSkinContent(CContentCGF& content);
void MergeToFirstNodeMesh(CContentCGF& content);
void RemoveRedundantNodes(CContentCGF& content);
AZ::SceneAPI::Events::ProcessingResult ProcessSkins(SkinGroupExportContext& context, CContentCGF& content, AZStd::vector<AZStd::string>& targetNodes);
} // namespace RC
} // namespace AZ
@@ -52,20 +52,4 @@ set(FILES
Cgf/CgfExporter.cpp
Cgf/CgfUtils.h
Cgf/CgfUtils.cpp
Chr/ChrExportContexts.h
Chr/ChrExportContexts.cpp
Chr/ChrGroupExporter.h
Chr/ChrGroupExporter.cpp
Chr/ChrExporter.h
Chr/ChrExporter.cpp
Skin/SkinExportContexts.h
Skin/SkinExportContexts.cpp
Skin/SkinGroupExporter.h
Skin/SkinGroupExporter.cpp
Skin/SkinLodExporter.h
Skin/SkinLodExporter.cpp
Skin/SkinExporter.h
Skin/SkinExporter.cpp
Skin/SkinUtils.h
Skin/SkinUtils.cpp
)