Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,48 @@
/*
* 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)
{
}
}
}
@@ -0,0 +1,59 @@
#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;
};
}
}
@@ -0,0 +1,58 @@
/*
* 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
@@ -0,0 +1,46 @@
/*
* 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
@@ -0,0 +1,131 @@
/*
* 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
@@ -0,0 +1,47 @@
/*
* 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