{lyn9135} Adding a default prefab during scene processing (#6851)

* {lyn8865} Adding DataTypes::ScriptProcessorFallbackLogic

- Give the user an option how to handle fallback logic for script rules

Signed-off-by: Allen Jackson <23512001+jackalbe@users.noreply.github.com>

* the new code found an error in a Python script... it seems to work!

Signed-off-by: Allen Jackson <23512001+jackalbe@users.noreply.github.com>

* fixing up the regression test

Signed-off-by: Jackson <23512001+jackalbe@users.noreply.github.com>

* dump version number

Signed-off-by: Allen Jackson <23512001+jackalbe@users.noreply.github.com>

* Adding first pass of logic plus test file

Signed-off-by: Allen Jackson <23512001+jackalbe@users.noreply.github.com>

* Applying scene graph transform to entity transform
Excluding other mesh names in the mesh groups


Signed-off-by: Allen Jackson <23512001+jackalbe@users.noreply.github.com>

* test: parent top stack


Signed-off-by: Allen Jackson <23512001+jackalbe@users.noreply.github.com>

* cleaned up the code and parent tops FBX file

Signed-off-by: Allen Jackson <23512001+jackalbe@users.noreply.github.com>

* adding tests for the proc prefab constructor logic

Signed-off-by: Allen Jackson <23512001+jackalbe@users.noreply.github.com>

* Linux/Clang fixes

Signed-off-by: Allen Jackson <23512001+jackalbe@users.noreply.github.com>

* assigning matrix data to pass the tests in Linux (and others...)

Signed-off-by: Allen Jackson <23512001+jackalbe@users.noreply.github.com>

* Addressed some concerns based on PR feedback

Signed-off-by: Allen Jackson <23512001+jackalbe@users.noreply.github.com>

* encapsulating the logic into readable sections

Signed-off-by: Allen Jackson <23512001+jackalbe@users.noreply.github.com>

* added comment to watch folder to asset path info

Signed-off-by: Allen Jackson <23512001+jackalbe@users.noreply.github.com>
This commit is contained in:
Allen Jackson
2022-01-25 10:02:56 -06:00
committed by GitHub
parent f3e6e57cc4
commit c8cf613cf6
4 changed files with 562 additions and 7 deletions
@@ -18,13 +18,57 @@
#include <AzToolsFramework/Asset/AssetSystemComponent.h>
#include <AzToolsFramework/Prefab/Procedural/ProceduralPrefabAsset.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/IMeshData.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/ITransform.h>
#include <SceneAPI/SceneCore/DataTypes/Groups/IMeshGroup.h>
#include <SceneAPI/SceneCore/Events/AssetImportRequest.h>
#include <SceneAPI/SceneCore/Events/CallProcessorBus.h>
#include <SceneAPI/SceneCore/Events/ExportEventContext.h>
#include <SceneAPI/SceneCore/Events/ExportProductList.h>
#include <SceneAPI/SceneCore/Mocks/DataTypes/MockIGraphObject.h>
#include <SceneAPI/SceneCore/SceneCoreStandaloneAllocator.h>
#include <SceneAPI/SceneData/GraphData/MeshData.h>
#include <SceneAPI/SceneData/SceneDataStandaloneAllocator.h>
#include <PrefabGroup/PrefabBehaviorTests.inl>
// a mock AZ::Render::EditorMeshComponent
namespace AZ::Render
{
struct EditorMeshComponent
: public AZ::Component
{
AZ_COMPONENT(EditorMeshComponent, "{DCE68F6E-2E16-4CB4-A834-B6C2F900A7E9}");
void Activate() override {}
void Deactivate() override {}
static void Reflect(AZ::ReflectContext* context)
{
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<AZ::Render::EditorMeshComponent>();
}
if (BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->Class<EditorMeshComponent>("AZ::Render::EditorMeshComponent");
}
}
};
struct EditorMeshComponentHelper
: public AZ::ComponentDescriptorHelper<EditorMeshComponent>
{
AZ_CLASS_ALLOCATOR(EditorMeshComponentHelper, AZ::SystemAllocator, 0);
void Reflect(AZ::ReflectContext* reflection) const override
{
AZ::Render::EditorMeshComponent::Reflect(reflection);
}
};
}
namespace UnitTest
{
class PrefabBehaviorTests
@@ -39,10 +83,12 @@ namespace UnitTest
AZ::AllocatorInstance<AZ::SystemAllocator>().Create();
}
AZ::SceneAPI::SceneCoreStandaloneAllocator::Initialize(AZ::Environment::GetInstance());
AZ::SceneAPI::SceneDataStandaloneAllocator::Initialize(AZ::Environment::GetInstance());
}
static void TearDownTestCase()
{
AZ::SceneAPI::SceneDataStandaloneAllocator::TearDown();
AZ::SceneAPI::SceneCoreStandaloneAllocator::TearDown();
AZ::AllocatorInstance<AZ::SystemAllocator>().Destroy();
}
@@ -62,10 +108,16 @@ namespace UnitTest
return PrefabBehaviorTests::OnGetSourceInfoBySourcePath(path, info);
});
m_assetSystemRequestMock.BusConnect();
m_componentDescriptorHelperEditorMeshComponent = AZStd::make_unique<AZ::Render::EditorMeshComponentHelper>();
m_componentDescriptorHelperEditorMeshComponent->Reflect(m_app.GetSerializeContext());
m_componentDescriptorHelperEditorMeshComponent->Reflect(m_app.GetBehaviorContext());
}
void TearDown() override
{
m_componentDescriptorHelperEditorMeshComponent.reset();
m_assetSystemRequestMock.BusDisconnect();
m_prefabGroupBehavior->Deactivate();
@@ -86,6 +138,72 @@ namespace UnitTest
return true;
}
AZStd::shared_ptr<AZ::SceneAPI::Containers::Scene> CreateMockScene()
{
using namespace AZ::SceneAPI;
auto scene = AZStd::make_shared<Containers::Scene>("mock_scene");
scene->SetManifestFilename("ManifestFilename");
scene->SetSource("Source", AZ::Uuid::CreateRandom());
scene->SetWatchFolder("WatchFolder");
/*---------------------------------------\
Root
|
1
|
2
/ \
------3m 7
/ / / \
6 5 4t 8m-------
\ \ \
9t 10 11
\---------------------------------------*/
// Build up the graph
auto root = scene->GetGraph().GetRoot();
scene->GetGraph().SetContent(root, AZStd::make_shared<DataTypes::MockIGraphObject>(0));
auto index1 = scene->GetGraph().AddChild(root, "1", AZStd::make_shared<DataTypes::MockIGraphObject>(1));
auto index2 = scene->GetGraph().AddChild(index1, "2", AZStd::make_shared<DataTypes::MockIGraphObject>(2));
auto index3 = scene->GetGraph().AddChild(index2, "3", AZStd::make_shared<AZ::SceneData::GraphData::MeshData>());
auto index4 = scene->GetGraph().AddChild(index3, "4", AZStd::make_shared<MockTransform>());
auto index5 = scene->GetGraph().AddChild(index3, "5", AZStd::make_shared<DataTypes::MockIGraphObject>(5));
auto index6 = scene->GetGraph().AddChild(index3, "6", AZStd::make_shared<DataTypes::MockIGraphObject>(6));
auto index7 = scene->GetGraph().AddChild(index2, "7", AZStd::make_shared<DataTypes::MockIGraphObject>(7));
auto index8 = scene->GetGraph().AddChild(index7, "8", AZStd::make_shared<AZ::SceneData::GraphData::MeshData>());
auto index9 = scene->GetGraph().AddChild(index8, "9", AZStd::make_shared<MockTransform>());
auto index10 = scene->GetGraph().AddChild(index8, "10", AZStd::make_shared<DataTypes::MockIGraphObject>(10));
auto index11 = scene->GetGraph().AddChild(index8, "11", AZStd::make_shared<DataTypes::MockIGraphObject>(11));
scene->GetGraph().MakeEndPoint(index4);
scene->GetGraph().MakeEndPoint(index5);
scene->GetGraph().MakeEndPoint(index6);
scene->GetGraph().MakeEndPoint(index9);
scene->GetGraph().MakeEndPoint(index10);
scene->GetGraph().MakeEndPoint(index11);
return scene;
}
// mock classes and structures
struct MockTransform
: public AZ::SceneAPI::DataTypes::ITransform
{
AZ::Matrix3x4 m_matrix = AZ::Matrix3x4::CreateIdentity();
AZ::Matrix3x4& GetMatrix() override
{
return m_matrix;
}
const AZ::Matrix3x4& GetMatrix() const
{
return m_matrix;
}
};
struct TestPreExportEventContext
{
TestPreExportEventContext()
@@ -110,6 +228,7 @@ namespace UnitTest
AZStd::unique_ptr<AZ::SceneAPI::Behaviors::PrefabGroupBehavior> m_prefabGroupBehavior;
testing::NiceMock<UnitTests::MockAssetSystemRequest> m_assetSystemRequestMock;
AZStd::unique_ptr<AZ::Render::EditorMeshComponentHelper> m_componentDescriptorHelperEditorMeshComponent;
};
TEST_F(PrefabBehaviorTests, PrefabBehavior_EmptyContextIgnored_Works)
@@ -164,4 +283,72 @@ namespace UnitTest
AZ_Warning("testing", false, "The product asset (%s) is missing", pathStr.c_str());
}
}
TEST_F(PrefabBehaviorTests, PrefabBehavior_UpdateManifestWithEmptyScene_DoesNotFail)
{
using namespace AZ::SceneAPI;
using namespace AZ::SceneAPI::Events;
Containers::Scene scene("empty_scene");
AssetImportRequest::ManifestAction action = AssetImportRequest::ManifestAction::ConstructDefault;
AssetImportRequest::RequestingApplication requester = {};
Behaviors::PrefabGroupBehavior prefabGroupBehavior;
ProcessingResult result = ProcessingResult::Failure;
AssetImportRequestBus::BroadcastResult(result, &AssetImportRequestBus::Events::UpdateManifest, scene, action, requester);
EXPECT_NE(result, ProcessingResult::Failure);
}
TEST_F(PrefabBehaviorTests, PrefabBehavior_UpdateManifestWithEmptyScene_Ignored)
{
using namespace AZ::SceneAPI;
using namespace AZ::SceneAPI::Events;
Containers::Scene scene("empty_scene");
AssetImportRequest::ManifestAction action = AssetImportRequest::ManifestAction::Update;
AssetImportRequest::RequestingApplication requester = {};
Behaviors::PrefabGroupBehavior prefabGroupBehavior;
ProcessingResult result = ProcessingResult::Failure;
AssetImportRequestBus::BroadcastResult(result, &AssetImportRequestBus::Events::UpdateManifest, scene, action, requester);
EXPECT_EQ(result, ProcessingResult::Ignored);
}
TEST_F(PrefabBehaviorTests, PrefabBehavior_UpdateManifestMockScene_CreatesPrefab)
{
using namespace AZ::SceneAPI;
using namespace AZ::SceneAPI::Events;
auto scene = CreateMockScene();
AssetImportRequest::ManifestAction action = AssetImportRequest::ManifestAction::ConstructDefault;
AssetImportRequest::RequestingApplication requester = {};
Behaviors::PrefabGroupBehavior prefabGroupBehavior;
ProcessingResult result = ProcessingResult::Failure;
AssetImportRequestBus::BroadcastResult(result, &AssetImportRequestBus::Events::UpdateManifest, *scene, action, requester);
EXPECT_EQ(result, ProcessingResult::Success);
EXPECT_EQ(scene->GetManifest().GetEntryCount(), 3);
EXPECT_TRUE(azrtti_istypeof<AZ::SceneAPI::DataTypes::IMeshGroup>(scene->GetManifest().GetValue(0).get()));
EXPECT_TRUE(azrtti_istypeof<AZ::SceneAPI::DataTypes::IMeshGroup>(scene->GetManifest().GetValue(1).get()));
EXPECT_TRUE(azrtti_istypeof<AZ::SceneAPI::DataTypes::IPrefabGroup>(scene->GetManifest().GetValue(2).get()));
}
TEST_F(PrefabBehaviorTests, PrefabBehavior_UpdateManifest_ToggleWorks)
{
using namespace AZ::SceneAPI;
using namespace AZ::SceneAPI::Events;
ASSERT_TRUE(AZ::SettingsRegistry::Get());
AZ::SettingsRegistry::Get()->Set("/O3DE/Preferences/Prefabs/CreateDefaults", false);
auto scene = CreateMockScene();
AssetImportRequest::ManifestAction action = AssetImportRequest::ManifestAction::ConstructDefault;
AssetImportRequest::RequestingApplication requester = {};
Behaviors::PrefabGroupBehavior prefabGroupBehavior;
ProcessingResult result = ProcessingResult::Failure;
AssetImportRequestBus::BroadcastResult(result, &AssetImportRequestBus::Events::UpdateManifest, *scene, action, requester);
EXPECT_EQ(result, ProcessingResult::Ignored);
EXPECT_EQ(scene->GetManifest().GetEntryCount(), 0);
}
}