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,262 @@
/*
* 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/Module/DynamicModuleHandle.h>
#include <AzCore/Serialization/EditContext.h>
#include <Source/SceneProcessingModule.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/IAnimationData.h>
#include <Config/SettingsObjects/NodeSoftNameSetting.h>
#include <Config/SettingsObjects/FileSoftNameSetting.h>
#include <Config/Components/SceneProcessingConfigSystemComponent.h>
#include <Config/Widgets/GraphTypeSelector.h>
namespace AZ
{
namespace SceneProcessingConfig
{
void SceneProcessingConfigSystemComponentSerializationEvents::OnWriteBegin(void* classPtr)
{
SceneProcessingConfigSystemComponent* component = reinterpret_cast<SceneProcessingConfigSystemComponent*>(classPtr);
component->Clear();
}
SceneProcessingConfigSystemComponent::SceneProcessingConfigSystemComponent()
{
using namespace AZ::SceneAPI::SceneCore;
ActivateSceneModule(SceneProcessing::s_sceneCoreModule);
ActivateSceneModule(SceneProcessing::s_sceneDataModule);
ActivateSceneModule(SceneProcessing::s_fbxSceneBuilderModule);
// Defaults in case there's no config setup in the Project Configurator.
m_softNames.push_back(aznew NodeSoftNameSetting("_lod1", PatternMatcher::MatchApproach::PostFix, "LODMesh1", true));
m_softNames.push_back(aznew NodeSoftNameSetting("_lod2", PatternMatcher::MatchApproach::PostFix, "LODMesh2", true));
m_softNames.push_back(aznew NodeSoftNameSetting("_lod3", PatternMatcher::MatchApproach::PostFix, "LODMesh3", true));
m_softNames.push_back(aznew NodeSoftNameSetting("_lod4", PatternMatcher::MatchApproach::PostFix, "LODMesh4", true));
m_softNames.push_back(aznew NodeSoftNameSetting("_lod5", PatternMatcher::MatchApproach::PostFix, "LODMesh5", true));
m_softNames.push_back(aznew NodeSoftNameSetting("_phys", PatternMatcher::MatchApproach::PostFix, "PhysicsMesh", true));
m_softNames.push_back(aznew NodeSoftNameSetting("_ignore", PatternMatcher::MatchApproach::PostFix, "Ignore", false));
// If the filename ends with "_anim" this will mark all nodes as "Ignore" unless they're derived from IAnimationData. This will
// cause only animations to be exported from the .fbx file even if there's other data available.
m_softNames.push_back(aznew FileSoftNameSetting("_anim", PatternMatcher::MatchApproach::PostFix, "Ignore", false,
{ FileSoftNameSetting::GraphType(SceneAPI::DataTypes::IAnimationData::TYPEINFO_Name()) }));
m_UseCustomNormals = true;
}
void SceneProcessingConfigSystemComponent::Activate()
{
SceneProcessingConfigRequestBus::Handler::BusConnect();
AZ::SceneAPI::Events::AssetImportRequestBus::Handler::BusConnect();
SceneProcessingConfig::GraphTypeSelector::Register();
}
void SceneProcessingConfigSystemComponent::Deactivate()
{
SceneProcessingConfig::GraphTypeSelector::Unregister();
AZ::SceneAPI::Events::AssetImportRequestBus::Handler::BusDisconnect();
SceneProcessingConfigRequestBus::Handler::BusDisconnect();
}
SceneProcessingConfigSystemComponent::~SceneProcessingConfigSystemComponent()
{
DeactivateSceneModule(SceneProcessing::s_fbxSceneBuilderModule);
DeactivateSceneModule(SceneProcessing::s_sceneDataModule);
DeactivateSceneModule(SceneProcessing::s_sceneCoreModule);
}
void SceneProcessingConfigSystemComponent::Clear()
{
m_softNames.clear();
m_softNames.shrink_to_fit();
m_UseCustomNormals = true;
}
const AZStd::vector<SoftNameSetting*>* SceneProcessingConfigSystemComponent::GetSoftNames()
{
return &m_softNames;
}
bool SceneProcessingConfigSystemComponent::AddSoftName(SoftNameSetting* newSoftname)
{
bool success = true;
Crc32 newHash = newSoftname->GetVirtualTypeHash();
for (SoftNameSetting* softName : m_softNames)
{
//First check whether an item with the same CRC value already exists.
if (newHash == softName->GetVirtualTypeHash())
{
AZ_Error("SceneProcessing", false, "newSoftname(%s) and existing softName(%s) have the same hash: 0x%X",
newSoftname->GetVirtualType().c_str(), softName->GetVirtualType().c_str(), newHash);
success = false;
break;
}
}
if (success)
{
m_softNames.push_back(newSoftname);
}
return success;
}
bool SceneProcessingConfigSystemComponent::AddNodeSoftName(const char* pattern,
SceneAPI::SceneCore::PatternMatcher::MatchApproach approach,
const char* virtualType, bool includeChildren)
{
SoftNameSetting* newSoftname = aznew NodeSoftNameSetting(pattern, approach, virtualType, includeChildren);
bool success = AddSoftName(newSoftname);
if (!success)
{
delete newSoftname;
}
return success;
}
bool SceneProcessingConfigSystemComponent::AddFileSoftName(const char* pattern,
SceneAPI::SceneCore::PatternMatcher::MatchApproach approach,
const char* virtualType, bool inclusive, const AZStd::string& graphObjectTypeName)
{
SoftNameSetting* newSoftname = aznew FileSoftNameSetting(pattern, approach, virtualType, inclusive,
{ FileSoftNameSetting::GraphType(graphObjectTypeName) });
bool success = AddSoftName(newSoftname);
if (!success)
{
delete newSoftname;
}
return success;
}
void SceneProcessingConfigSystemComponent::AreCustomNormalsUsed(bool &value)
{
value = m_UseCustomNormals;
}
void SceneProcessingConfigSystemComponent::Reflect(AZ::ReflectContext* context)
{
ReflectSceneModule(context, SceneProcessing::s_sceneCoreModule);
ReflectSceneModule(context, SceneProcessing::s_sceneDataModule);
ReflectSceneModule(context, SceneProcessing::s_fbxSceneBuilderModule);
SoftNameSetting::Reflect(context);
NodeSoftNameSetting::Reflect(context);
FileSoftNameSetting::Reflect(context);
AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
if (serialize)
{
serialize->Class<SceneProcessingConfigSystemComponent, AZ::Component>()
->Version(2)
->EventHandler<SceneProcessingConfigSystemComponentSerializationEvents>()
->Field("softNames", &SceneProcessingConfigSystemComponent::m_softNames)
->Field("useCustomNormals", &SceneProcessingConfigSystemComponent::m_UseCustomNormals);
if (AZ::EditContext* ec = serialize->GetEditContext())
{
ec->Class<SceneProcessingConfigSystemComponent>("Scene Processing Config", "Use this component to fine tune the defaults for processing of scene files like Fbx.")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Category, "Assets")
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System", 0xc94d118b))
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->DataElement(AZ::Edit::UIHandlers::Default, &SceneProcessingConfigSystemComponent::m_softNames,
"Soft naming conventions", "Update the naming conventions to suit your project.")
->Attribute(AZ::Edit::Attributes::AutoExpand, false)
->DataElement(AZ::Edit::UIHandlers::Default, &SceneProcessingConfigSystemComponent::m_UseCustomNormals,
"Use Custom Normals", "When enabled, Lumberyard will use the DCC assets custom or tangent space normals. When disabled, the normals will be averaged. This setting can be overridden on individual FBX asset settings.")
->Attribute(AZ::Edit::Attributes::AutoExpand, false);
}
}
}
void SceneProcessingConfigSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC("SceneProcessingConfigService", 0x7b333b47));
}
void SceneProcessingConfigSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
{
incompatible.push_back(AZ_CRC("SceneProcessingConfigService", 0x7b333b47));
}
void SceneProcessingConfigSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
{
AZ_UNUSED(required);
}
void SceneProcessingConfigSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
{
AZ_UNUSED(dependent);
}
void SceneProcessingConfigSystemComponent::ReflectSceneModule(AZ::ReflectContext* context,
const AZStd::unique_ptr<AZ::DynamicModuleHandle>& module)
{
using ReflectFunc = void(*)(AZ::SerializeContext*);
AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
if (serialize)
{
if (module)
{
ReflectFunc reflect = module->GetFunction<ReflectFunc>("Reflect");
if (reflect)
{
(*reflect)(serialize);
}
}
}
using ReflectBehaviorFunc = void(*)(AZ::BehaviorContext*);
AZ::BehaviorContext* behavior = azrtti_cast<AZ::BehaviorContext*>(context);
if (behavior)
{
if (module)
{
ReflectBehaviorFunc reflectBehavior = module->GetFunction<ReflectBehaviorFunc>("ReflectBehavior");
if (reflectBehavior)
{
(*reflectBehavior)(behavior);
}
}
}
}
void SceneProcessingConfigSystemComponent::ActivateSceneModule(const AZStd::unique_ptr<AZ::DynamicModuleHandle>& module)
{
using ActivateFunc = void(*)();
if (module)
{
ActivateFunc activate = module->GetFunction<ActivateFunc>("Activate");
if (activate)
{
(*activate)();
}
}
}
void SceneProcessingConfigSystemComponent::DeactivateSceneModule(const AZStd::unique_ptr<AZ::DynamicModuleHandle>& module)
{
using DeactivateFunc = void(*)();
if (module)
{
DeactivateFunc deactivate = module->GetFunction<DeactivateFunc>("Deactivate");
if (deactivate)
{
(*deactivate)();
}
}
}
} // namespace SceneProcessingConfig
} // namespace AZ
@@ -0,0 +1,85 @@
/*
* 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/Component/Component.h>
#include <AzCore/std/smart_ptr/unique_ptr.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <SceneAPI/SceneCore/Components/SceneSystemComponent.h>
#include <Config/SceneProcessingConfigBus.h>
#include <Config/SettingsObjects/SoftNameSetting.h>
#include <SceneAPI/SceneCore/Events/AssetImportRequest.h>
namespace AZ
{
class DynamicModuleHandle;
namespace SceneProcessingConfig
{
class SceneProcessingConfigSystemComponentSerializationEvents
: public SerializeContext::IEventHandler
{
public:
AZ_CLASS_ALLOCATOR(SceneProcessingConfigSystemComponentSerializationEvents, SystemAllocator, 0);
void OnWriteBegin(void* classPtr) override;
};
class SceneProcessingConfigSystemComponent
: public AZ::SceneAPI::SceneCore::SceneSystemComponent
, protected SceneProcessingConfigRequestBus::Handler
, public AZ::SceneAPI::Events::AssetImportRequestBus::Handler
{
public:
AZ_COMPONENT(SceneProcessingConfigSystemComponent, "{80FE1130-91B4-44D4-869F-859BB996161A}", AZ::SceneAPI::SceneCore::SceneSystemComponent);
SceneProcessingConfigSystemComponent();
~SceneProcessingConfigSystemComponent();
void Activate() override;
void Deactivate() override;
void Clear();
// SceneProcessingConfigRequestBus START
const AZStd::vector<SoftNameSetting*>* GetSoftNames() override;
bool AddNodeSoftName(const char* pattern,
SceneAPI::SceneCore::PatternMatcher::MatchApproach approach,
const char* virtualType, bool includeChildren) override;
bool AddFileSoftName(const char* pattern, SceneAPI::SceneCore::PatternMatcher::MatchApproach approach,
const char* virtualType, bool inclusive, const AZStd::string& graphObjectTypeName) override;
// SceneProcessingConfigRequestBus END
void AreCustomNormalsUsed(bool &value) override;
static void Reflect(AZ::ReflectContext* context);
static void GetProvidedServices(ComponentDescriptor::DependencyArrayType& provided);
static void GetIncompatibleServices(ComponentDescriptor::DependencyArrayType& incompatible);
static void GetRequiredServices(ComponentDescriptor::DependencyArrayType& required);
static void GetDependentServices(ComponentDescriptor::DependencyArrayType& dependent);
private:
/// It is the responsibility of the caller to delete newSoftname if this method returns
/// false.
bool AddSoftName(SoftNameSetting* newSoftname);
static void ReflectSceneModule(ReflectContext* context, const AZStd::unique_ptr<DynamicModuleHandle>& module);
static void ActivateSceneModule(const AZStd::unique_ptr<DynamicModuleHandle>& module);
static void DeactivateSceneModule(const AZStd::unique_ptr<DynamicModuleHandle>& module);
AZStd::vector<SoftNameSetting*> m_softNames;
bool m_UseCustomNormals;
};
} // namespace SceneProcessingConfig
} // namespace AZ
@@ -0,0 +1,82 @@
/*
* 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/Serialization/SerializeContext.h>
#include <Config/SceneProcessingConfigBus.h>
#include <Config/Components/SoftNameBehavior.h>
#include <Config/SettingsObjects/SoftNameSetting.h>
namespace AZ
{
namespace SceneProcessingConfig
{
void SoftNameBehavior::Activate()
{
SceneAPI::Events::GraphMetaInfoBus::Handler::BusConnect();
}
void SoftNameBehavior::Deactivate()
{
SceneAPI::Events::GraphMetaInfoBus::Handler::BusDisconnect();
}
void SoftNameBehavior::GetVirtualTypes(AZStd::set<Crc32>& types, const SceneAPI::Containers::Scene& scene,
SceneAPI::Containers::SceneGraph::NodeIndex node)
{
const AZStd::vector<SoftNameSetting*>* softNames = nullptr;
SceneProcessingConfigRequestBus::BroadcastResult(softNames, &SceneProcessingConfigRequestBus::Events::GetSoftNames);
if (softNames)
{
for (const SoftNameSetting* softName : *softNames)
{
if (types.find(softName->GetVirtualTypeHash()) != types.end())
{
// This type has already been added.
continue;
}
if (softName->IsVirtualType(scene, node))
{
types.insert(softName->GetVirtualTypeHash());
}
}
}
}
void SoftNameBehavior::GetVirtualTypeName(AZStd::string& name, Crc32 type)
{
if (type == AZ_CRC("Ignore", 0x0d88d6e2))
{
name = "Ignore";
}
}
void SoftNameBehavior::GetAllVirtualTypes(AZStd::set<Crc32>& types)
{
// Add types that aren't handled by one specific behavior and have a more global utility.
if (types.find(AZ_CRC("Ignore", 0x0d88d6e2)) == types.end())
{
types.insert(AZ_CRC("Ignore", 0x0d88d6e2));
}
}
void SoftNameBehavior::Reflect(ReflectContext* context)
{
SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<SoftNameBehavior, BehaviorComponent>()->Version(1);
}
}
} // namespace SceneProcessingConfig
} // namespace AZ
@@ -0,0 +1,42 @@
/*
* 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/BehaviorComponent.h>
#include <SceneAPI/SceneCore/Events/GraphMetaInfoBus.h>
namespace AZ
{
namespace SceneProcessingConfig
{
class SoftNameBehavior
: public SceneAPI::SceneCore::BehaviorComponent
, protected SceneAPI::Events::GraphMetaInfoBus::Handler
{
public:
AZ_COMPONENT(SoftNameBehavior, "{C2A9D207-485F-4752-B37B-388B0A52A956}", SceneAPI::SceneCore::BehaviorComponent);
~SoftNameBehavior() override = default;
void Activate() override;
void Deactivate() override;
void GetVirtualTypes(AZStd::set<Crc32>& types, const SceneAPI::Containers::Scene& scene,
SceneAPI::Containers::SceneGraph::NodeIndex node) override;
void GetVirtualTypeName(AZStd::string& name, Crc32 type) override;
void GetAllVirtualTypes(AZStd::set<Crc32>& types) override;
static void Reflect(ReflectContext* context);
};
} // namespace SceneProcessingConfig
} // namespace AZ