From a371edd07fa94d1c231162cc24062eb3452a95bb Mon Sep 17 00:00:00 2001 From: srikappa Date: Wed, 14 Apr 2021 17:26:14 -0700 Subject: [PATCH 01/33] Initial commit of CreatePrefab work --- .../PrefabEditorEntityOwnershipService.cpp | 25 ++- .../PrefabEditorEntityOwnershipService.h | 2 +- .../Prefab/Instance/Instance.cpp | 2 +- .../Instance/InstanceUpdateExecutor.cpp | 57 ++++- .../Prefab/Instance/InstanceUpdateExecutor.h | 14 ++ .../Prefab/PrefabPublicHandler.cpp | 211 ++++++++++++------ .../Prefab/PrefabPublicHandler.h | 5 +- .../Prefab/PrefabPublicInterface.h | 2 +- .../Prefab/PrefabSystemComponent.cpp | 33 ++- .../UI/Prefab/PrefabIntegrationManager.cpp | 16 +- .../UI/Prefab/PrefabIntegrationManager.h | 4 + 11 files changed, 281 insertions(+), 90 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp index 4b23b46ffd..2424658ecf 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp @@ -279,18 +279,29 @@ namespace AzToolsFramework AZStd::unique_ptr createdPrefabInstance = m_prefabSystemComponent->CreatePrefab(entities, AZStd::move(nestedPrefabInstances), filePath); - if (!instanceToParentUnder) - { - instanceToParentUnder = *m_rootInstance; - } - if (createdPrefabInstance) { + if (!instanceToParentUnder) + { + instanceToParentUnder = *m_rootInstance; + } + Prefab::Instance& addedInstance = instanceToParentUnder->get().AddInstance(AZStd::move(createdPrefabInstance)); - HandleEntitiesAdded({addedInstance.m_containerEntity.get()}); + AZ::Entity* containerEntity = addedInstance.m_containerEntity.get(); + containerEntity->AddComponent(aznew Prefab::EditorPrefabComponent()); + HandleEntitiesAdded({containerEntity}); + HandleEntitiesAdded(entities); + + // Update the template of the instance since we modified the entities of the instance by calling HandleEntitiesAdded. + Prefab::PrefabDom serializedInstance; + if (Prefab::PrefabDomUtils::StoreInstanceInPrefabDom(addedInstance, serializedInstance)) + { + m_prefabSystemComponent->UpdatePrefabTemplate(addedInstance.GetTemplateId(), serializedInstance); + } + return addedInstance; } - HandleEntitiesAdded(entities); + return AZStd::nullopt; } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.h index ad11547506..36a60cc501 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.h @@ -186,7 +186,7 @@ namespace AzToolsFramework PlayInEditorData m_playInEditorData; ////////////////////////////////////////////////////////////////////////// - // PrefabSystemComponentInterface interface implementation + // PrefabEditorEntityOwnershipInterface implementation Prefab::InstanceOptionalReference CreatePrefab( const AZStd::vector& entities, AZStd::vector>&& nestedPrefabInstances, AZ::IO::PathView filePath, Prefab::InstanceOptionalReference instanceToParentUnder) override; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.cpp index 0a5b43482e..bd4c343a3c 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.cpp @@ -283,7 +283,7 @@ namespace AzToolsFramework { if (!m_instanceEntityMapper->RegisterEntityToInstance(entityId, *this)) { - AZ_Assert(false, + AZ_Error("Prefab", false, "Prefab - Failed to register entity with id %s with a Prefab Instance derived from source asset %s " "This entity is likely already registered. Check for a double add.", entityId.ToString().c_str(), diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp index 65de6b713c..7df1602bff 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -117,6 +118,8 @@ namespace AzToolsFramework currentTemplateId); isUpdateSuccessful = false; + m_instancesUpdateQueue.pop(); + continue; } } @@ -139,9 +142,16 @@ namespace AzToolsFramework } m_instancesUpdateQueue.pop(); - } + for (auto entityIdIterator = selectedEntityIds.begin(); entityIdIterator != selectedEntityIds.end(); entityIdIterator++) + { + AZ::Entity* entity = GetEntityById(*entityIdIterator); + if (entity == nullptr) + { + selectedEntityIds.erase(entityIdIterator--); + } + } ToolsApplicationRequestBus::Broadcast(&ToolsApplicationRequests::SetSelectedEntities, selectedEntityIds); // Enable the Outliner @@ -163,5 +173,50 @@ namespace AzToolsFramework return isUpdateSuccessful; } + + Instance* InstanceUpdateExecutor::UniqueInstanceQueue::front() + { + return m_instancesQueue.front(); + } + + void InstanceUpdateExecutor::UniqueInstanceQueue::pop() + { + m_instancesSet.erase(m_instancesQueue.front()); + m_instancesQueue.pop(); + } + + void InstanceUpdateExecutor::UniqueInstanceQueue::emplace(Instance* instance) + { + Instance* ancestorInstance = instance; + + while (ancestorInstance != nullptr) + { + if (m_instancesSet.contains(ancestorInstance)) + { + return; + } + + auto parent = ancestorInstance->GetParentInstance(); + if (parent.has_value()) + { + ancestorInstance = &(parent->get()); + } + else + { + ancestorInstance = nullptr; + } + } + + // TODO - remove child instances too? + // Optimization. + + m_instancesQueue.emplace(instance); + m_instancesSet.emplace(instance); + } + + size_t InstanceUpdateExecutor::UniqueInstanceQueue::size() + { + return m_instancesQueue.size(); + } } } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.h index 04bd189816..a29e19dc8a 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -45,6 +46,19 @@ namespace AzToolsFramework PrefabSystemComponentInterface* m_prefabSystemComponentInterface = nullptr; TemplateInstanceMapperInterface* m_templateInstanceMapperInterface = nullptr; int m_instanceCountToUpdateInBatch = 0; + + class UniqueInstanceQueue + { + public: + Instance* front(); + void pop(); + void emplace(Instance* instance); + size_t size(); + private: + AZStd::queue m_instancesQueue; + AZStd::unordered_set m_instancesSet; + }; + //UniqueInstanceQueue m_instancesUpdateQueue; AZStd::queue m_instancesUpdateQueue; bool m_updatingTemplateInstancesInQueue { false }; }; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp index 417a524e77..292ee3c7f8 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp @@ -15,15 +15,16 @@ #include #include +#include #include #include #include #include -#include #include #include #include #include +#include #include #include #include @@ -37,12 +38,14 @@ namespace AzToolsFramework void PrefabPublicHandler::RegisterPrefabPublicHandlerInterface() { m_instanceEntityMapperInterface = AZ::Interface::Get(); - AZ_Assert( - m_instanceEntityMapperInterface, "PrefabPublicHandler - Could not retrieve instance of InstanceEntityMapperInterface"); + AZ_Assert(m_instanceEntityMapperInterface, "PrefabPublicHandler - Could not retrieve instance of InstanceEntityMapperInterface"); m_instanceToTemplateInterface = AZ::Interface::Get(); AZ_Assert(m_instanceToTemplateInterface, "PrefabPublicHandler - Could not retrieve instance of InstanceToTemplateInterface"); + m_prefabLoaderInterface = AZ::Interface::Get(); + AZ_Assert(m_prefabLoaderInterface, "Could not get PrefabLoaderInterface on PrefabPublicHandler construction."); + m_prefabSystemComponentInterface = AZ::Interface::Get(); AZ_Assert(m_prefabSystemComponentInterface, "Could not get PrefabSystemComponentInterface on PrefabPublicHandler construction."); @@ -58,7 +61,7 @@ namespace AzToolsFramework m_prefabUndoCache.Destroy(); } - PrefabOperationResult PrefabPublicHandler::CreatePrefab(const AZStd::vector& entityIds, AZStd::string_view filePath) + PrefabOperationResult PrefabPublicHandler::CreatePrefab(const AZStd::vector& entityIds, AZ::IO::PathView filePath) { // Retrieve entityList from entityIds EntityList inputEntityList; @@ -70,17 +73,14 @@ namespace AzToolsFramework EntityList topLevelEntities; AzToolsFramework::ToolsApplicationRequests::Bus::BroadcastResult( - entitiesHaveCommonRoot, - &AzToolsFramework::ToolsApplicationRequests::FindCommonRootInactive, - inputEntityList, - commonRootEntityId, - &topLevelEntities - ); + entitiesHaveCommonRoot, &AzToolsFramework::ToolsApplicationRequests::FindCommonRootInactive, inputEntityList, + commonRootEntityId, &topLevelEntities); // Bail if entities don't share a common root if (!entitiesHaveCommonRoot) { - return AZ::Failure(AZStd::string("Could not create a new prefab out of the entities provided - entities do not share a common root.")); + return AZ::Failure( + AZStd::string("Could not create a new prefab out of the entities provided - entities do not share a common root.")); } AZ::Entity* commonRootEntity = nullptr; @@ -91,58 +91,139 @@ namespace AzToolsFramework // Retrieve the owning instance of the common root entity, which will be our new instance's parent instance. InstanceOptionalReference commonRootEntityOwningInstance = GetOwnerInstanceByEntityId(commonRootEntityId); - AZ_Assert(commonRootEntityOwningInstance.has_value(), "Failed to create prefab : " + AZ_Assert( + commonRootEntityOwningInstance.has_value(), + "Failed to create prefab : " "Couldn't get a valid owning instance for the common root entity of the enities provided"); AZStd::vector entities; AZStd::vector> instances; - // Retrieve all entities affected and identify Instances - if (!RetrieveAndSortPrefabEntitiesAndInstances(inputEntityList, commonRootEntityOwningInstance->get(), entities, instances)) + InstanceOptionalReference instance; + { - return AZ::Failure(AZStd::string("Could not create a new prefab out of the entities provided - entities do not share a common root.")); + // Initialize Undo Batch object + ScopedUndoBatch undoBatch("Create Prefab"); + + TemplateId commonRootOwningTemplateId = commonRootEntityOwningInstance->get().GetTemplateId(); + + PrefabDom commonRootInstanceDomBeforeCreate; + m_instanceToTemplateInterface->GenerateDomForInstance( + commonRootInstanceDomBeforeCreate, commonRootEntityOwningInstance->get()); + + // Retrieve all entities affected and identify Instances + if (!RetrieveAndSortPrefabEntitiesAndInstances(inputEntityList, commonRootEntityOwningInstance->get(), entities, instances)) + { + return AZ::Failure( + AZStd::string("Could not create a new prefab out of the entities provided - entities do not share a common root.")); + } + + auto prefabEditorEntityOwnershipInterface = AZ::Interface::Get(); + if (!prefabEditorEntityOwnershipInterface) + { + return AZ::Failure(AZStd::string("Could not create a new prefab out of the entities provided - internal error " + "(PrefabEditorEntityOwnershipInterface unavailable).")); + } + + // When you move instances from another template, you have to remove the links and propagate changes to target template. + auto linkRemoveUndo = aznew PrefabUndoInstanceLink("Undo Link Remove Node"); + for (auto& nestedInstance : instances) + { + PrefabDom emptyLinkDom; + linkRemoveUndo->Capture( + commonRootOwningTemplateId, nestedInstance->GetTemplateId(), nestedInstance->GetInstanceAlias(), emptyLinkDom, + nestedInstance->GetLinkId()); + linkRemoveUndo->SetParent(undoBatch.GetUndoBatch()); + } + + // Create the Prefab + instance = prefabEditorEntityOwnershipInterface->CreatePrefab( + entities, AZStd::move(instances), filePath, commonRootEntityOwningInstance); + + if (!instance) + { + return AZ::Failure(AZStd::string("Could not create a new prefab out of the entities provided - internal error " + "(A null instance is returned).")); + } + + PrefabDom commonRootInstanceDomAfterCreate; + m_instanceToTemplateInterface->GenerateDomForInstance( + commonRootInstanceDomAfterCreate, commonRootEntityOwningInstance->get()); + + auto commonRootInstanceUndoNode = aznew PrefabUndoInstance("Undo Instance Node"); + commonRootInstanceUndoNode->Capture( + commonRootInstanceDomBeforeCreate, commonRootInstanceDomAfterCreate, commonRootOwningTemplateId); + commonRootInstanceUndoNode->SetParent(undoBatch.GetUndoBatch()); + commonRootInstanceUndoNode->Redo(); + + linkRemoveUndo->Redo(); + + + AZ::EntityId containerEntityId = instance->get().GetContainerEntityId(); + AZ::Entity* containerEntity = GetEntityById(containerEntityId); + + // Apply Transform changes as overrides + { + Prefab::PrefabDom containerEntityDomBefore; + m_instanceToTemplateInterface->GenerateDomForEntity(containerEntityDomBefore, *containerEntity); + + AZ::Vector3 containerEntityTranslation(AZ::Vector3::CreateZero()); + AZ::Quaternion containerEntityRotation(AZ::Quaternion::CreateZero()); + + // Set the transform (translation, rotation) of the container entity + GenerateContainerEntityTransform(topLevelEntities, containerEntityTranslation, containerEntityRotation); + + // Set container entity to be child of common root + AZ::TransformBus::Event(containerEntityId, &AZ::TransformBus::Events::SetParent, commonRootEntityId); + + AZ::TransformBus::Event(containerEntityId, &AZ::TransformBus::Events::SetLocalTranslation, containerEntityTranslation); + AZ::TransformBus::Event(containerEntityId, &AZ::TransformBus::Events::SetLocalRotationQuaternion, containerEntityRotation); + + PrefabDom containerEntityDomAfter; + m_instanceToTemplateInterface->GenerateDomForEntity(containerEntityDomAfter, *containerEntity); + + PrefabDom patch; + m_instanceToTemplateInterface->GeneratePatch(patch, containerEntityDomBefore, containerEntityDomAfter); + + m_instanceToTemplateInterface->AppendEntityAliasToPatchPaths(patch, containerEntityId); + + + auto linkAddUndo = aznew PrefabUndoInstanceLink("Undo Link Add Node"); + linkAddUndo->Capture( + commonRootEntityOwningInstance->get().GetTemplateId(), instance->get().GetTemplateId(), instance->get().GetInstanceAlias(), + patch, InvalidLinkId); + linkAddUndo->SetParent(undoBatch.GetUndoBatch()); + + linkAddUndo->Redo(); + + // Update the cache - this prevents these changes from being stored in the regular undo/redo nodes + m_prefabUndoCache.Store(containerEntityId, AZStd::move(containerEntityDomAfter)); + } + + // Change top level entities to be parented to the container entity + // Mark them as dirty so this change is correctly applied to the template + for (AZ::Entity* topLevelEntity : topLevelEntities) + { + m_prefabUndoCache.UpdateCache(topLevelEntity->GetId()); + undoBatch.MarkEntityDirty(topLevelEntity->GetId()); + AZ::TransformBus::Event(topLevelEntity->GetId(), &AZ::TransformBus::Events::SetParent, containerEntityId); + } + + /* + // Select Container Entity + { + auto selectionUndo = aznew SelectionCommand({containerEntityId}, "Select Prefab Container Entity"); + selectionUndo->SetParent(undoBatch.GetUndoBatch()); + + ToolsApplicationRequestBus::Broadcast(&ToolsApplicationRequestBus::Events::RunRedoSeparately, selectionUndo); + }*/ } - auto prefabEditorEntityOwnershipInterface = AZ::Interface::Get(); - if (!prefabEditorEntityOwnershipInterface) - { - return AZ::Failure(AZStd::string("Could not create a new prefab out of the entities provided - internal error " - "(PrefabEditorEntityOwnershipInterface unavailable).")); - } + // Save Template to file + m_prefabLoaderInterface->SaveTemplate(instance->get().GetTemplateId()); - InstanceOptionalReference instance = prefabEditorEntityOwnershipInterface->CreatePrefab( - entities, AZStd::move(instances), filePath, commonRootEntityOwningInstance); - - if (!instance) - { - return AZ::Failure(AZStd::string("Could not create a new prefab out of the entities provided - internal error " - "(A null instance is returned).")); - } - - AZ::EntityId containerEntityId = instance->get().GetContainerEntityId(); - AZ::Vector3 containerEntityTranslation(AZ::Vector3::CreateZero()); - AZ::Quaternion containerEntityRotation(AZ::Quaternion::CreateZero()); - - // Set the transform (translation, rotation) of the container entity - GenerateContainerEntityTransform(topLevelEntities, containerEntityTranslation, containerEntityRotation); - - AZ::TransformBus::Event(containerEntityId, &AZ::TransformBus::Events::SetLocalTranslation, containerEntityTranslation); - AZ::TransformBus::Event(containerEntityId, &AZ::TransformBus::Events::SetLocalRotationQuaternion, containerEntityRotation); - - // Set container entity to be child of common root - AZ::TransformBus::Event(containerEntityId, &AZ::TransformBus::Events::SetParent, commonRootEntityId); - - // Assign the EditorPrefabComponent to the instance container - EntityCompositionRequests::AddComponentsOutcome outcome; - EntityCompositionRequestBus::BroadcastResult( - outcome, &EntityCompositionRequests::AddComponentsToEntities, EntityIdList{containerEntityId}, - AZ::ComponentTypeList{azrtti_typeid()}); - - // Change top level entities to be parented to the container entity - for (AZ::Entity* topLevelEntity : topLevelEntities) - { - AZ::TransformBus::Event(topLevelEntity->GetId(), &AZ::TransformBus::Events::SetParent, containerEntityId); - } + // This function does not support undo/redo yet, so clear the undo stack to prevent issues. + //AzToolsFramework::ToolsApplicationRequestBus::Broadcast(&AzToolsFramework::ToolsApplicationRequestBus::Events::FlushUndo); return AZ::Success(); } @@ -174,14 +255,7 @@ namespace AzToolsFramework AZStd::string("SavePrefab - Path error. Path could be invalid, or the prefab may not be loaded in this level.")); } - auto prefabLoaderInterface = AZ::Interface::Get(); - if (prefabLoaderInterface == nullptr) - { - return AZ::Failure(AZStd::string( - "Could not save prefab - internal error (PrefabLoaderInterface unavailable).")); - } - - if (!prefabLoaderInterface->SaveTemplate(templateId)) + if (!m_prefabLoaderInterface->SaveTemplate(templateId)) { return AZ::Failure(AZStd::string("Could not save prefab - internal error (Json write operation failure).")); } @@ -260,15 +334,15 @@ namespace AzToolsFramework // Create Undo node on entities if they belong to an instance InstanceOptionalReference instanceOptionalReference = m_instanceEntityMapperInterface->FindOwningInstance(entityId); - if (instanceOptionalReference.has_value()) + if (instanceOptionalReference.has_value() && !IsInstanceContainerEntity(entityId)) { - PrefabDom beforeState; - m_prefabUndoCache.Retrieve(entityId, beforeState); - PrefabDom afterState; AZ::Entity* entity = GetEntityById(entityId); if (entity) { + PrefabDom beforeState; + m_prefabUndoCache.Retrieve(entityId, beforeState); + m_instanceToTemplateInterface->GenerateDomForEntity(afterState, *entity); PrefabDom patch; @@ -287,7 +361,10 @@ namespace AzToolsFramework // Update the cache m_prefabUndoCache.Store(entityId, AZStd::move(afterState)); } - + else + { + m_prefabUndoCache.PurgeCache(entityId); + } } } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h index 46a7f946ba..de892470ab 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h @@ -27,8 +27,10 @@ namespace AzToolsFramework namespace Prefab { class Instance; + class InstanceEntityMapperInterface; class InstanceToTemplateInterface; + class PrefabLoaderInterface; class PrefabSystemComponentInterface; class PrefabPublicHandler final @@ -42,7 +44,7 @@ namespace AzToolsFramework void UnregisterPrefabPublicHandlerInterface(); // PrefabPublicInterface... - PrefabOperationResult CreatePrefab(const AZStd::vector& entityIds, AZStd::string_view filePath) override; + PrefabOperationResult CreatePrefab(const AZStd::vector& entityIds, AZ::IO::PathView filePath) override; PrefabOperationResult InstantiatePrefab(AZStd::string_view filePath, AZ::EntityId parent, AZ::Vector3 position) override; PrefabOperationResult SavePrefab(AZ::IO::Path filePath) override; PrefabEntityResult CreateEntity(AZ::EntityId parentId, const AZ::Vector3& position) override; @@ -74,6 +76,7 @@ namespace AzToolsFramework InstanceEntityMapperInterface* m_instanceEntityMapperInterface = nullptr; InstanceToTemplateInterface* m_instanceToTemplateInterface = nullptr; + PrefabLoaderInterface* m_prefabLoaderInterface = nullptr; PrefabSystemComponentInterface* m_prefabSystemComponentInterface = nullptr; // Caches entity states for undo/redo purposes diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicInterface.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicInterface.h index 81a5258d91..4e59729ab2 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicInterface.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicInterface.h @@ -49,7 +49,7 @@ namespace AzToolsFramework * @param filePath The path for the new prefab file. * @return An outcome object; on failure, it comes with an error message detailing the cause of the error. */ - virtual PrefabOperationResult CreatePrefab(const AZStd::vector& entityIds, AZStd::string_view filePath) = 0; + virtual PrefabOperationResult CreatePrefab(const AZStd::vector& entityIds, AZ::IO::PathView filePath) = 0; /** * Instantiate a prefab from a prefab file. diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp index bf9fd658c6..37620ed9ec 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp @@ -104,7 +104,6 @@ namespace AzToolsFramework return nullptr; } - AZStd::unique_ptr newInstance = AZStd::make_unique(AZStd::move(containerEntity)); for (AZ::Entity* entity : entities) @@ -120,8 +119,11 @@ namespace AzToolsFramework newInstance->AddInstance(AZStd::move(instance)); } - - newInstance->SetTemplateSourcePath(relativeFilePath); + /* + AzToolsFramework::EditorEntityContextRequestBus::Broadcast( + &AzToolsFramework::EditorEntityContextRequests::HandleEntitiesAdded, EntityList{containerEntity->GetId()}); + */ + newInstance->SetTemplateSourcePath(filePath); TemplateId newTemplateId = CreateTemplateFromInstance(*newInstance); if (newTemplateId == InvalidTemplateId) @@ -157,11 +159,16 @@ namespace AzToolsFramework void PrefabSystemComponent::UpdatePrefabTemplate(TemplateId templateId, const PrefabDom& updatedDom) { - PrefabDom& templateDomToUpdate = FindTemplateDom(templateId); - if (AZ::JsonSerialization::Compare(templateDomToUpdate, updatedDom) != AZ::JsonSerializerCompareResult::Equal) + auto templateRef = FindTemplate(templateId); + if (templateRef.has_value()) { - templateDomToUpdate.CopyFrom(updatedDom, templateDomToUpdate.GetAllocator()); - PropagateTemplateChanges(templateId); + PrefabDom& templateDomToUpdate = templateRef->get().GetPrefabDom(); + if (AZ::JsonSerialization::Compare(templateDomToUpdate, updatedDom) != AZ::JsonSerializerCompareResult::Equal) + { + templateDomToUpdate.CopyFrom(updatedDom, templateDomToUpdate.GetAllocator()); + templateRef->get().MarkAsDirty(true); + PropagateTemplateChanges(templateId); + } } } @@ -615,7 +622,12 @@ namespace AzToolsFramework instancesValue = memberFound->value; } - instancesValue->get().AddMember(rapidjson::StringRef(instanceAlias.c_str()), PrefabDomValue(), targetTemplateDom.GetAllocator()); + // Only add the instance if it's not there already + if (instancesValue->get().FindMember(rapidjson::StringRef(instanceAlias.c_str())) == instancesValue->get().MemberEnd()) + { + instancesValue->get().AddMember( + rapidjson::StringRef(instanceAlias.c_str()), PrefabDomValue(), targetTemplateDom.GetAllocator()); + } Template& sourceTemplate = sourceTemplateRef->get(); @@ -628,9 +640,12 @@ namespace AzToolsFramework newLink.GetLinkDom().AddMember(rapidjson::StringRef(PrefabDomUtils::SourceName), rapidjson::StringRef(sourceTemplate.GetFilePath().c_str()), newLink.GetLinkDom().GetAllocator()); + PrefabDom linkPatchCopy; + linkPatchCopy.CopyFrom(linkPatch->get(), newLink.GetLinkDom().GetAllocator()); + if (linkPatch && linkPatch->get().IsArray() && !(linkPatch->get().Empty())) { - m_instanceToTemplatePropagator.AddPatchesToLink(linkPatch.value(), newLink); + m_instanceToTemplatePropagator.AddPatchesToLink(linkPatchCopy, newLink); } //update the target template dom to have the proper values for the source template dom diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp index 1e71b545b5..6ce3fdc755 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -39,9 +40,12 @@ namespace AzToolsFramework { namespace Prefab { + EditorEntityUiInterface* PrefabIntegrationManager::s_editorEntityUiInterface = nullptr; PrefabPublicInterface* PrefabIntegrationManager::s_prefabPublicInterface = nullptr; PrefabEditInterface* PrefabIntegrationManager::s_prefabEditInterface = nullptr; + PrefabLoaderInterface* PrefabIntegrationManager::s_prefabLoaderInterface = nullptr; + const AZStd::string PrefabIntegrationManager::s_prefabFileExtension = ".prefab"; void PrefabUserSettings::Reflect(AZ::ReflectContext* context) @@ -79,6 +83,13 @@ namespace AzToolsFramework return; } + s_prefabLoaderInterface = AZ::Interface::Get(); + if (s_prefabLoaderInterface == nullptr) + { + AZ_Assert(false, "Prefab - could not get PrefabLoaderInterface on PrefabIntegrationManager construction."); + return; + } + EditorContextMenuBus::Handler::BusConnect(); PrefabInstanceContainerNotificationBus::Handler::BusConnect(); AZ::Interface::Register(this); @@ -320,14 +331,15 @@ namespace AzToolsFramework GenerateSuggestedFilenameFromEntities(prefabRootEntities, suggestedName); - if (!QueryUserForPrefabSaveLocation(suggestedName, targetDirectory, AZ_CRC("PrefabUserSettings"), activeWindow, prefabName, prefabFilePath)) + if (!QueryUserForPrefabSaveLocation( + suggestedName, targetDirectory, AZ_CRC("PrefabUserSettings"), activeWindow, prefabName, prefabFilePath)) { // User canceled prefab creation, or error prevented continuation. return; } } - auto createPrefabOutcome = s_prefabPublicInterface->CreatePrefab(selectedEntities, prefabFilePath); + auto createPrefabOutcome = s_prefabPublicInterface->CreatePrefab(selectedEntities, s_prefabLoaderInterface->GetRelativePathToProject(prefabFilePath.data())); if (!createPrefabOutcome.IsSuccess()) { diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.h b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.h index 66a047df28..c9b846aa5b 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.h @@ -29,6 +29,9 @@ namespace AzToolsFramework { namespace Prefab { + + class PrefabLoaderInterface; + //! Structure for saving/retrieving user settings related to prefab workflows. class PrefabUserSettings : public AZ::UserSettings @@ -129,6 +132,7 @@ namespace AzToolsFramework static EditorEntityUiInterface* s_editorEntityUiInterface; static PrefabPublicInterface* s_prefabPublicInterface; static PrefabEditInterface* s_prefabEditInterface; + static PrefabLoaderInterface* s_prefabLoaderInterface; }; } } From 778d60bd0c47ad25e43b166928dfa64e54202167 Mon Sep 17 00:00:00 2001 From: srikappa Date: Thu, 15 Apr 2021 18:45:48 -0700 Subject: [PATCH 02/33] Replaced unique instance queue with checks in template to instance mapper --- .../Instance/InstanceUpdateExecutor.cpp | 54 ++++--------------- .../Prefab/Instance/InstanceUpdateExecutor.h | 14 ----- .../Prefab/PrefabPublicHandler.cpp | 2 +- .../Prefab/PrefabSystemComponent.cpp | 5 +- 4 files changed, 14 insertions(+), 61 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp index 7df1602bff..d84edd6212 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp @@ -123,6 +123,15 @@ namespace AzToolsFramework } } + auto findInstancesResult = m_templateInstanceMapperInterface->FindInstancesOwnedByTemplate(instanceTemplateId)->get(); + + if (findInstancesResult.find(instanceToUpdate) == findInstancesResult.end()) + { + isUpdateSuccessful = false; + m_instancesUpdateQueue.pop(); + continue; + } + Template& currentTemplate = currentTemplateReference->get(); Instance::EntityList newEntities; if (PrefabDomUtils::LoadInstanceFromPrefabDom(*instanceToUpdate, newEntities, currentTemplate.GetPrefabDom())) @@ -173,50 +182,5 @@ namespace AzToolsFramework return isUpdateSuccessful; } - - Instance* InstanceUpdateExecutor::UniqueInstanceQueue::front() - { - return m_instancesQueue.front(); - } - - void InstanceUpdateExecutor::UniqueInstanceQueue::pop() - { - m_instancesSet.erase(m_instancesQueue.front()); - m_instancesQueue.pop(); - } - - void InstanceUpdateExecutor::UniqueInstanceQueue::emplace(Instance* instance) - { - Instance* ancestorInstance = instance; - - while (ancestorInstance != nullptr) - { - if (m_instancesSet.contains(ancestorInstance)) - { - return; - } - - auto parent = ancestorInstance->GetParentInstance(); - if (parent.has_value()) - { - ancestorInstance = &(parent->get()); - } - else - { - ancestorInstance = nullptr; - } - } - - // TODO - remove child instances too? - // Optimization. - - m_instancesQueue.emplace(instance); - m_instancesSet.emplace(instance); - } - - size_t InstanceUpdateExecutor::UniqueInstanceQueue::size() - { - return m_instancesQueue.size(); - } } } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.h index a29e19dc8a..04bd189816 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.h @@ -15,7 +15,6 @@ #include #include #include -#include #include #include @@ -46,19 +45,6 @@ namespace AzToolsFramework PrefabSystemComponentInterface* m_prefabSystemComponentInterface = nullptr; TemplateInstanceMapperInterface* m_templateInstanceMapperInterface = nullptr; int m_instanceCountToUpdateInBatch = 0; - - class UniqueInstanceQueue - { - public: - Instance* front(); - void pop(); - void emplace(Instance* instance); - size_t size(); - private: - AZStd::queue m_instancesQueue; - AZStd::unordered_set m_instancesSet; - }; - //UniqueInstanceQueue m_instancesUpdateQueue; AZStd::queue m_instancesUpdateQueue; bool m_updatingTemplateInstancesInQueue { false }; }; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp index 292ee3c7f8..b97e9ebd98 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp @@ -334,7 +334,7 @@ namespace AzToolsFramework // Create Undo node on entities if they belong to an instance InstanceOptionalReference instanceOptionalReference = m_instanceEntityMapperInterface->FindOwningInstance(entityId); - if (instanceOptionalReference.has_value() && !IsInstanceContainerEntity(entityId)) + if (instanceOptionalReference.has_value()) { PrefabDom afterState; AZ::Entity* entity = GetEntityById(entityId); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp index 37620ed9ec..7a9ec0a62e 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp @@ -144,7 +144,6 @@ namespace AzToolsFramework void PrefabSystemComponent::PropagateTemplateChanges(TemplateId templateId) { - UpdatePrefabInstances(templateId); auto templateIdToLinkIdsIterator = m_templateToLinkIdsMap.find(templateId); if (templateIdToLinkIdsIterator != m_templateToLinkIdsMap.end()) { @@ -155,6 +154,10 @@ namespace AzToolsFramework templateIdToLinkIdsIterator->second.end())); UpdateLinkedInstances(linkIdsToUpdateQueue); } + else + { + UpdatePrefabInstances(templateId); + } } void PrefabSystemComponent::UpdatePrefabTemplate(TemplateId templateId, const PrefabDom& updatedDom) From 22d6e1ec0dfd41a49d2e8b37e4ee71566a274838 Mon Sep 17 00:00:00 2001 From: srikappa Date: Fri, 16 Apr 2021 16:18:34 -0700 Subject: [PATCH 03/33] Modularized undo instannce update undo operation and enabled setting container entity to be selected --- .../Prefab/PrefabPublicHandler.cpp | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp index b97e9ebd98..0ce929217d 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp @@ -146,15 +146,8 @@ namespace AzToolsFramework "(A null instance is returned).")); } - PrefabDom commonRootInstanceDomAfterCreate; - m_instanceToTemplateInterface->GenerateDomForInstance( - commonRootInstanceDomAfterCreate, commonRootEntityOwningInstance->get()); - - auto commonRootInstanceUndoNode = aznew PrefabUndoInstance("Undo Instance Node"); - commonRootInstanceUndoNode->Capture( - commonRootInstanceDomBeforeCreate, commonRootInstanceDomAfterCreate, commonRootOwningTemplateId); - commonRootInstanceUndoNode->SetParent(undoBatch.GetUndoBatch()); - commonRootInstanceUndoNode->Redo(); + PrefabUndoHelpers::UpdatePrefabInstance( + commonRootEntityOwningInstance->get(), "Undo detaching entity", commonRootInstanceDomBeforeCreate, undoBatch.GetUndoBatch()); linkRemoveUndo->Redo(); @@ -208,22 +201,17 @@ namespace AzToolsFramework undoBatch.MarkEntityDirty(topLevelEntity->GetId()); AZ::TransformBus::Event(topLevelEntity->GetId(), &AZ::TransformBus::Events::SetParent, containerEntityId); } - - /* + // Select Container Entity { auto selectionUndo = aznew SelectionCommand({containerEntityId}, "Select Prefab Container Entity"); selectionUndo->SetParent(undoBatch.GetUndoBatch()); - ToolsApplicationRequestBus::Broadcast(&ToolsApplicationRequestBus::Events::RunRedoSeparately, selectionUndo); - }*/ + } } // Save Template to file m_prefabLoaderInterface->SaveTemplate(instance->get().GetTemplateId()); - - // This function does not support undo/redo yet, so clear the undo stack to prevent issues. - //AzToolsFramework::ToolsApplicationRequestBus::Broadcast(&AzToolsFramework::ToolsApplicationRequestBus::Events::FlushUndo); return AZ::Success(); } From 82f6d249eb11edb3907c59d97e67b5348558f6e5 Mon Sep 17 00:00:00 2001 From: Chris Santora Date: Fri, 16 Apr 2021 23:01:27 -0700 Subject: [PATCH 04/33] ATOM-14765 Add More Texture Preset Masks Several image preset files had a full list of file masks for only one platform. I made sure that the same list was applied to every platform including the default preset. Removed the "Swizzle" command from Displacement.preset. Swizzle "aaa1" is wrong since this preset expects a single channel image. Added "_col" to Albedo.preset as an abbreviation for "_color". Added "_rough" to Roughness.preset as it's a common abbreviation. Added "_rgbmask" filter to LayerMask.preset to correspond to the "_mask" filter in Grayscale.preset. Added a warning when an image can't be processed according to the assigned preset due to dimension issues. Otherwise it's difficult to figure out why it's using the ReferenceImage preset instead of what was expected. Resized the "bark" textures to make them compatible with the image presets. Removed the "bark1disp2.jgp" image and just applied the changes to the original bark1disp.jpg". It's just blurred a bit to remove excessive noise. Renamed all the "bark" textures to include an underscore "_" after "bark1" to get the image pipeline to properly recognize the file masks. Testing: AtomSampleViewer automation. All assets in AtomTest build. Opened several levels in AtomTest. --- .../BuilderSettings/BuilderSettingManager.cpp | 4 ++ .../Code/Source/ImageBuilderComponent.cpp | 2 +- .../ImageProcessingAtom/Config/Albedo.preset | 5 ++ .../Config/AmbientOcclusion.preset | 20 ++++++-- .../Config/Displacement.preset | 49 +++++++++++++++---- .../Config/Emissive.preset | 24 +++++++-- .../Config/LayerMask.preset | 15 ++++-- .../Config/NormalsWithSmoothness.preset | 24 +++++++-- .../ImageProcessingAtom/Config/Opacity.preset | 40 ++++++++++++--- .../Config/Reflectance.preset | 15 ++++-- .../001_ManyFeatures.material | 12 ++--- .../002_ParallaxPdo.material | 8 +-- .../TestData/Textures/cc0/bark1_col.jpg | 3 ++ .../TestData/Textures/cc0/bark1_disp.jpg | 3 ++ .../TestData/Textures/cc0/bark1_norm.jpg | 3 ++ .../TestData/Textures/cc0/bark1_roughness.jpg | 3 ++ .../TestData/Textures/cc0/bark1col.jpg | 3 -- .../TestData/Textures/cc0/bark1disp.jpg | 3 -- .../TestData/Textures/cc0/bark1disp2.jpg | 3 -- .../TestData/Textures/cc0/bark1norm.jpg | 3 -- .../TestData/Textures/cc0/bark1roughness.jpg | 3 -- 21 files changed, 182 insertions(+), 63 deletions(-) create mode 100644 Gems/Atom/TestData/TestData/Textures/cc0/bark1_col.jpg create mode 100644 Gems/Atom/TestData/TestData/Textures/cc0/bark1_disp.jpg create mode 100644 Gems/Atom/TestData/TestData/Textures/cc0/bark1_norm.jpg create mode 100644 Gems/Atom/TestData/TestData/Textures/cc0/bark1_roughness.jpg delete mode 100644 Gems/Atom/TestData/TestData/Textures/cc0/bark1col.jpg delete mode 100644 Gems/Atom/TestData/TestData/Textures/cc0/bark1disp.jpg delete mode 100644 Gems/Atom/TestData/TestData/Textures/cc0/bark1disp2.jpg delete mode 100644 Gems/Atom/TestData/TestData/Textures/cc0/bark1norm.jpg delete mode 100644 Gems/Atom/TestData/TestData/Textures/cc0/bark1roughness.jpg diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/BuilderSettings/BuilderSettingManager.cpp b/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/BuilderSettings/BuilderSettingManager.cpp index e30fb9c6a2..3b6c906c10 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/BuilderSettings/BuilderSettingManager.cpp +++ b/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/BuilderSettings/BuilderSettingManager.cpp @@ -524,6 +524,10 @@ namespace ImageProcessingAtom { return outPreset; } + else + { + AZ_Warning("Image Processing", false, "Image dimensions are not compatible with preset '%s'. The default preset will be used.", presetInfo->m_name.c_str()); + } } //uncompressed one which could be used for almost everything diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageBuilderComponent.cpp b/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageBuilderComponent.cpp index 4de024c088..5d5fd21b44 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageBuilderComponent.cpp +++ b/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageBuilderComponent.cpp @@ -79,7 +79,7 @@ namespace ImageProcessingAtom builderDescriptor.m_busId = azrtti_typeid(); builderDescriptor.m_createJobFunction = AZStd::bind(&ImageBuilderWorker::CreateJobs, &m_imageBuilder, AZStd::placeholders::_1, AZStd::placeholders::_2); builderDescriptor.m_processJobFunction = AZStd::bind(&ImageBuilderWorker::ProcessJob, &m_imageBuilder, AZStd::placeholders::_1, AZStd::placeholders::_2); - builderDescriptor.m_version = 19; // [ATOM-14459] + builderDescriptor.m_version = 22; // [ATOM-14765] builderDescriptor.m_analysisFingerprint = ImageProcessingAtom::BuilderSettingManager::Instance()->GetAnalysisFingerprint(); m_imageBuilder.BusConnect(builderDescriptor.m_busId); AssetBuilderSDK::AssetBuilderBus::Broadcast(&AssetBuilderSDK::AssetBuilderBusTraits::RegisterBuilderInformation, builderDescriptor); diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Config/Albedo.preset b/Gems/Atom/Asset/ImageProcessingAtom/Config/Albedo.preset index d81fefede2..c00185e255 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Config/Albedo.preset +++ b/Gems/Atom/Asset/ImageProcessingAtom/Config/Albedo.preset @@ -11,6 +11,7 @@ "_basecolor", "_diff", "_color", + "_col", "_albedo", "_alb", "_bc", @@ -31,6 +32,7 @@ "FileMasks": [ "_diff", "_color", + "_col", "_albedo", "_alb", "_basecolor", @@ -51,6 +53,7 @@ "FileMasks": [ "_diff", "_color", + "_col", "_albedo", "_alb", "_basecolor", @@ -71,6 +74,7 @@ "FileMasks": [ "_diff", "_color", + "_col", "_albedo", "_alb", "_basecolor", @@ -91,6 +95,7 @@ "FileMasks": [ "_diff", "_color", + "_col", "_albedo", "_alb", "_basecolor", diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Config/AmbientOcclusion.preset b/Gems/Atom/Asset/ImageProcessingAtom/Config/AmbientOcclusion.preset index 222a1d4c7b..6b1197e28d 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Config/AmbientOcclusion.preset +++ b/Gems/Atom/Asset/ImageProcessingAtom/Config/AmbientOcclusion.preset @@ -9,7 +9,10 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_ao" + "_ao", + "_ambocc", + "_amb", + "_ambientocclusion" ], "PixelFormat": "BC4" }, @@ -33,7 +36,10 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_ao" + "_ao", + "_ambocc", + "_amb", + "_ambientocclusion" ], "PixelFormat": "EAC_R11" }, @@ -43,7 +49,10 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_ao" + "_ao", + "_ambocc", + "_amb", + "_ambientocclusion" ], "PixelFormat": "BC4" }, @@ -53,7 +62,10 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_ao" + "_ao", + "_ambocc", + "_amb", + "_ambientocclusion" ], "PixelFormat": "BC4" } diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Config/Displacement.preset b/Gems/Atom/Asset/ImageProcessingAtom/Config/Displacement.preset index 1cac9c1d3a..569ff6ce23 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Config/Displacement.preset +++ b/Gems/Atom/Asset/ImageProcessingAtom/Config/Displacement.preset @@ -9,12 +9,20 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_displ" + "_displ", + "_disp", + "_dsp", + "_d", + "_dm", + "_displacement", + "_height", + "_hm", + "_ht", + "_h" ], "PixelFormat": "BC4", "DiscardAlpha": true, "IsPowerOf2": true, - "Swizzle": "aaa1", "MipMapSetting": { "MipGenType": "Box" } @@ -26,13 +34,21 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_displ" + "_displ", + "_disp", + "_dsp", + "_d", + "_dm", + "_displacement", + "_height", + "_hm", + "_ht", + "_h" ], "PixelFormat": "EAC_R11", "DiscardAlpha": true, "IsPowerOf2": true, "SizeReduceLevel": 3, - "Swizzle": "aaa1", "MipMapSetting": { "MipGenType": "Box" } @@ -57,7 +73,6 @@ "PixelFormat": "EAC_R11", "DiscardAlpha": true, "IsPowerOf2": true, - "Swizzle": "aaa1", "MipMapSetting": { "MipGenType": "Box" } @@ -68,12 +83,20 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_displ" + "_displ", + "_disp", + "_dsp", + "_d", + "_dm", + "_displacement", + "_height", + "_hm", + "_ht", + "_h" ], "PixelFormat": "BC4", "DiscardAlpha": true, "IsPowerOf2": true, - "Swizzle": "aaa1", "MipMapSetting": { "MipGenType": "Box" } @@ -84,12 +107,20 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_displ" + "_displ", + "_disp", + "_dsp", + "_d", + "_dm", + "_displacement", + "_height", + "_hm", + "_ht", + "_h" ], "PixelFormat": "BC4", "DiscardAlpha": true, "IsPowerOf2": true, - "Swizzle": "aaa1", "MipMapSetting": { "MipGenType": "Box" } diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Config/Emissive.preset b/Gems/Atom/Asset/ImageProcessingAtom/Config/Emissive.preset index d3290eb469..5dc75397a0 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Config/Emissive.preset +++ b/Gems/Atom/Asset/ImageProcessingAtom/Config/Emissive.preset @@ -8,7 +8,11 @@ "Name": "Emissive", "RGB_Weight": "CIEXYZ", "FileMasks": [ - "_emissive" + "_emissive", + "_e", + "_glow", + "_em", + "_emit" ], "PixelFormat": "BC7", "DiscardAlpha": true @@ -33,7 +37,11 @@ "Name": "Emissive", "RGB_Weight": "CIEXYZ", "FileMasks": [ - "_emissive" + "_emissive", + "_e", + "_glow", + "_em", + "_emit" ], "PixelFormat": "ASTC_6x6", "DiscardAlpha": true @@ -43,7 +51,11 @@ "Name": "Emissive", "RGB_Weight": "CIEXYZ", "FileMasks": [ - "_emissive" + "_emissive", + "_e", + "_glow", + "_em", + "_emit" ], "PixelFormat": "BC7", "DiscardAlpha": true @@ -53,7 +65,11 @@ "Name": "Emissive", "RGB_Weight": "CIEXYZ", "FileMasks": [ - "_emissive" + "_emissive", + "_e", + "_glow", + "_em", + "_emit" ], "PixelFormat": "BC7", "DiscardAlpha": true diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Config/LayerMask.preset b/Gems/Atom/Asset/ImageProcessingAtom/Config/LayerMask.preset index 363a6f9f9d..66927b175c 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Config/LayerMask.preset +++ b/Gems/Atom/Asset/ImageProcessingAtom/Config/LayerMask.preset @@ -9,7 +9,8 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_layers" + "_layers", + "_rgbmask" ], "PixelFormat": "R8G8B8X8" }, @@ -20,7 +21,8 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_layers" + "_layers", + "_rgbmask" ], "PixelFormat": "R8G8B8X8" }, @@ -30,7 +32,8 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_layers" + "_layers", + "_rgbmask" ], "PixelFormat": "R8G8B8X8" }, @@ -40,7 +43,8 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_layers" + "_layers", + "_rgbmask" ], "PixelFormat": "R8G8B8X8" }, @@ -50,7 +54,8 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_layers" + "_layers", + "_rgbmask" ], "PixelFormat": "R8G8B8X8" } diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Config/NormalsWithSmoothness.preset b/Gems/Atom/Asset/ImageProcessingAtom/Config/NormalsWithSmoothness.preset index fb8b1da6a4..fdb24ecd09 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Config/NormalsWithSmoothness.preset +++ b/Gems/Atom/Asset/ImageProcessingAtom/Config/NormalsWithSmoothness.preset @@ -9,7 +9,11 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_ddna" + "_ddna", + "_normala", + "_nrma", + "_nma", + "_na" ], "PixelFormat": "BC5s", "PixelFormatAlpha": "BC4", @@ -48,7 +52,11 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_ddna" + "_ddna", + "_normala", + "_nrma", + "_nma", + "_na" ], "PixelFormat": "ASTC_4x4", "PixelFormatAlpha": "ASTC_4x4", @@ -65,7 +73,11 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_ddna" + "_ddna", + "_normala", + "_nrma", + "_nma", + "_na" ], "PixelFormat": "BC5s", "PixelFormatAlpha": "BC4", @@ -82,7 +94,11 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_ddna" + "_ddna", + "_normala", + "_nrma", + "_nma", + "_na" ], "PixelFormat": "BC5s", "PixelFormatAlpha": "BC4", diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Config/Opacity.preset b/Gems/Atom/Asset/ImageProcessingAtom/Config/Opacity.preset index bd9299d71d..6d0d9009a5 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Config/Opacity.preset +++ b/Gems/Atom/Asset/ImageProcessingAtom/Config/Opacity.preset @@ -9,9 +9,16 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_sss", - "_trans", - "_opac" + "_sss", + "_trans", + "_opac", + "_opacity", + "_o", + "_opac", + "_op", + "_mask", + "_msk", + "_blend" ], "PixelFormat": "BC4", "IsPowerOf2": true, @@ -28,7 +35,14 @@ "FileMasks": [ "_sss", "_trans", - "_opac" + "_opac", + "_opacity", + "_o", + "_opac", + "_op", + "_mask", + "_msk", + "_blend" ], "PixelFormat": "EAC_R11", "IsPowerOf2": true, @@ -67,7 +81,14 @@ "FileMasks": [ "_sss", "_trans", - "_opac" + "_opac", + "_opacity", + "_o", + "_opac", + "_op", + "_mask", + "_msk", + "_blend" ], "PixelFormat": "BC4", "IsPowerOf2": true, @@ -83,7 +104,14 @@ "FileMasks": [ "_sss", "_trans", - "_opac" + "_opac", + "_opacity", + "_o", + "_opac", + "_op", + "_mask", + "_msk", + "_blend" ], "PixelFormat": "BC4", "IsPowerOf2": true, diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Config/Reflectance.preset b/Gems/Atom/Asset/ImageProcessingAtom/Config/Reflectance.preset index ca773debbb..7a6af50728 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Config/Reflectance.preset +++ b/Gems/Atom/Asset/ImageProcessingAtom/Config/Reflectance.preset @@ -24,7 +24,8 @@ "_mt", "_metalness", "_metallic", - "_roughness" + "_roughness", + "_rough" ], "PixelFormat": "BC1", "IsPowerOf2": true, @@ -53,7 +54,8 @@ "_mt", "_metalness", "_metallic", - "_roughness" + "_roughness", + "_rough" ], "PixelFormat": "ETC2", "IsPowerOf2": true, @@ -81,7 +83,8 @@ "_mt", "_metalness", "_metallic", - "_roughness" + "_roughness", + "_rough" ], "PixelFormat": "ASTC_6x6", "IsPowerOf2": true, @@ -109,7 +112,8 @@ "_mt", "_metalness", "_metallic", - "_roughness" + "_roughness", + "_rough" ], "PixelFormat": "BC1", "IsPowerOf2": true, @@ -137,7 +141,8 @@ "_mt", "_metalness", "_metallic", - "_roughness" + "_roughness", + "_rough" ], "PixelFormat": "BC1", "IsPowerOf2": true, diff --git a/Gems/Atom/TestData/TestData/Materials/StandardMultilayerPbrTestCases/001_ManyFeatures.material b/Gems/Atom/TestData/TestData/Materials/StandardMultilayerPbrTestCases/001_ManyFeatures.material index c013eecae5..e84c6296be 100644 --- a/Gems/Atom/TestData/TestData/Materials/StandardMultilayerPbrTestCases/001_ManyFeatures.material +++ b/Gems/Atom/TestData/TestData/Materials/StandardMultilayerPbrTestCases/001_ManyFeatures.material @@ -7,7 +7,7 @@ "layer1_ambientOcclusion": { "enable": true, "factor": 1.6399999856948853, - "textureMap": "TestData/Textures/cc0/bark1disp2.jpg" + "textureMap": "TestData/Textures/cc0/bark1_disp.jpg" }, "layer1_baseColor": { "color": [ @@ -16,7 +16,7 @@ 0.12039368599653244, 1.0 ], - "textureMap": "TestData/Textures/cc0/bark1col.jpg" + "textureMap": "TestData/Textures/cc0/bark1_col.jpg" }, "layer1_emissive": { "color": [ @@ -30,16 +30,16 @@ "layer1_normal": { "factor": 0.4444443881511688, "flipY": true, - "textureMap": "TestData/Textures/cc0/bark1norm.jpg" + "textureMap": "TestData/Textures/cc0/bark1_norm.jpg" }, "layer1_parallax": { "enable": true, "factor": 0.02500000037252903, - "textureMap": "TestData/Textures/cc0/bark1disp2.jpg" + "textureMap": "TestData/Textures/cc0/bark1_disp.jpg" }, "layer1_roughness": { "lowerBound": 0.010100999847054482, - "textureMap": "TestData/Textures/cc0/bark1roughness.jpg" + "textureMap": "TestData/Textures/cc0/bark1_roughness.jpg" }, "layer1_specularF0": { "factor": 0.5099999904632568, @@ -55,7 +55,7 @@ }, "layer2_ambientOcclusion": { "factor": 1.2200000286102296, - "textureMap": "TestData/Textures/cc0/bark1disp2.jpg" + "textureMap": "TestData/Textures/cc0/bark1_disp.jpg" }, "layer2_baseColor": { "textureMap": "TestData/Textures/cc0/Lava004_1K_Color.jpg" diff --git a/Gems/Atom/TestData/TestData/Materials/StandardMultilayerPbrTestCases/002_ParallaxPdo.material b/Gems/Atom/TestData/TestData/Materials/StandardMultilayerPbrTestCases/002_ParallaxPdo.material index 471b437bd2..126e1a7fcb 100644 --- a/Gems/Atom/TestData/TestData/Materials/StandardMultilayerPbrTestCases/002_ParallaxPdo.material +++ b/Gems/Atom/TestData/TestData/Materials/StandardMultilayerPbrTestCases/002_ParallaxPdo.material @@ -5,18 +5,18 @@ "propertyLayoutVersion": 3, "properties": { "layer1_baseColor": { - "textureMap": "TestData/Textures/cc0/bark1col.jpg" + "textureMap": "TestData/Textures/cc0/bark1_col.jpg" }, "layer1_normal": { - "textureMap": "TestData/Textures/cc0/bark1norm.jpg" + "textureMap": "TestData/Textures/cc0/bark1_norm.jpg" }, "layer1_parallax": { "enable": true, "factor": 0.03999999910593033, - "textureMap": "TestData/Textures/cc0/bark1disp2.jpg" + "textureMap": "TestData/Textures/cc0/bark1_disp.jpg" }, "layer1_roughness": { - "textureMap": "TestData/Textures/cc0/bark1roughness.jpg" + "textureMap": "TestData/Textures/cc0/bark1_roughness.jpg" }, "layer2_baseColor": { "textureMap": "TestData/Textures/cc0/Rock030_2K_Color.jpg" diff --git a/Gems/Atom/TestData/TestData/Textures/cc0/bark1_col.jpg b/Gems/Atom/TestData/TestData/Textures/cc0/bark1_col.jpg new file mode 100644 index 0000000000..0a4c5f380c --- /dev/null +++ b/Gems/Atom/TestData/TestData/Textures/cc0/bark1_col.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bd44119610135ca5674de7144647df6580d7ac3e03576e9a8e87e741548e7364 +size 2105853 diff --git a/Gems/Atom/TestData/TestData/Textures/cc0/bark1_disp.jpg b/Gems/Atom/TestData/TestData/Textures/cc0/bark1_disp.jpg new file mode 100644 index 0000000000..57c74af488 --- /dev/null +++ b/Gems/Atom/TestData/TestData/Textures/cc0/bark1_disp.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4dbb74aac2450d6457bb02d36bd3d74e671c2dc7e938e090331151ecc52d545b +size 845683 diff --git a/Gems/Atom/TestData/TestData/Textures/cc0/bark1_norm.jpg b/Gems/Atom/TestData/TestData/Textures/cc0/bark1_norm.jpg new file mode 100644 index 0000000000..41b1d6d30b --- /dev/null +++ b/Gems/Atom/TestData/TestData/Textures/cc0/bark1_norm.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e69a3844c3a595245619a9dda4ed8981476a516ad3648a8b4dfb8151a68b0db5 +size 4439966 diff --git a/Gems/Atom/TestData/TestData/Textures/cc0/bark1_roughness.jpg b/Gems/Atom/TestData/TestData/Textures/cc0/bark1_roughness.jpg new file mode 100644 index 0000000000..2e7ccba4e0 --- /dev/null +++ b/Gems/Atom/TestData/TestData/Textures/cc0/bark1_roughness.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a8caa5961599624a6414d7277c389dd85b175b9587989b815ffd90aff8f62b6c +size 1747230 diff --git a/Gems/Atom/TestData/TestData/Textures/cc0/bark1col.jpg b/Gems/Atom/TestData/TestData/Textures/cc0/bark1col.jpg deleted file mode 100644 index 944a968d5b..0000000000 --- a/Gems/Atom/TestData/TestData/Textures/cc0/bark1col.jpg +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:24f5c234f11a1b29de9000b5a7ba74262f1bc5ebd2227ca1e85a12fa0e8b5237 -size 8273450 diff --git a/Gems/Atom/TestData/TestData/Textures/cc0/bark1disp.jpg b/Gems/Atom/TestData/TestData/Textures/cc0/bark1disp.jpg deleted file mode 100644 index c8a2a44e9b..0000000000 --- a/Gems/Atom/TestData/TestData/Textures/cc0/bark1disp.jpg +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:0112ac235da74c60105b0e1a2da49c1e4ab7b89a60960a60cec54ad65db0b4b6 -size 4585685 diff --git a/Gems/Atom/TestData/TestData/Textures/cc0/bark1disp2.jpg b/Gems/Atom/TestData/TestData/Textures/cc0/bark1disp2.jpg deleted file mode 100644 index f93d68141b..0000000000 --- a/Gems/Atom/TestData/TestData/Textures/cc0/bark1disp2.jpg +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:6a202449e5d787e76d959b6bee7a4b60b3821441ac918944c21358742ed1c546 -size 878112 diff --git a/Gems/Atom/TestData/TestData/Textures/cc0/bark1norm.jpg b/Gems/Atom/TestData/TestData/Textures/cc0/bark1norm.jpg deleted file mode 100644 index f68ed8b696..0000000000 --- a/Gems/Atom/TestData/TestData/Textures/cc0/bark1norm.jpg +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:b0100b3c356d76ae1cb4c42bd4cc9c58ff359155aab6b9e3c1b205fe25956738 -size 16848020 diff --git a/Gems/Atom/TestData/TestData/Textures/cc0/bark1roughness.jpg b/Gems/Atom/TestData/TestData/Textures/cc0/bark1roughness.jpg deleted file mode 100644 index f6e7acd7b6..0000000000 --- a/Gems/Atom/TestData/TestData/Textures/cc0/bark1roughness.jpg +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:11badf07e6a7d0501c915f669ff1b14c8744d427d47d06e2fdca46b8f86839c9 -size 4441528 From 593542627602015b897f4239c3e4a785bfa6c755 Mon Sep 17 00:00:00 2001 From: Chris Santora Date: Mon, 19 Apr 2021 09:33:49 -0700 Subject: [PATCH 05/33] Fixed whitespace. ATOM-14765 Add More Texture Preset Masks --- .../Config/IBLSkybox.preset | 6 +++--- .../Config/NormalsWithSmoothness.preset | 10 +++++----- .../ImageProcessingAtom/Config/Opacity.preset | 20 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Config/IBLSkybox.preset b/Gems/Atom/Asset/ImageProcessingAtom/Config/IBLSkybox.preset index 867fc73959..fef756e354 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Config/IBLSkybox.preset +++ b/Gems/Atom/Asset/ImageProcessingAtom/Config/IBLSkybox.preset @@ -27,7 +27,7 @@ }, "PlatformsPresets": { "es3": { - "UUID": "{E6441EAC-9843-484B-8EFC-C03B2935B48D}", + "UUID": "{E6441EAC-9843-484B-8EFC-C03B2935B48D}", "Name": "IBLSkybox", "FileMasks": [ "_iblskyboxcm" @@ -61,7 +61,7 @@ "MinTextureSize": 256, "IsPowerOf2": true, "CubemapSettings": { - "RequiresConvolve": false, + "RequiresConvolve": false, "GenerateIBLSpecular": true, "IBLSpecularPreset": "{908DA68C-97FB-4C4A-97BC-5A55F30F14FA}", "GenerateIBLDiffuse": true, @@ -69,7 +69,7 @@ } }, "osx_gl": { - "UUID": "{E6441EAC-9843-484B-8EFC-C03B2935B48D}", + "UUID": "{E6441EAC-9843-484B-8EFC-C03B2935B48D}", "Name": "IBLSkybox", "FileMasks": [ "_iblskyboxcm" diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Config/NormalsWithSmoothness.preset b/Gems/Atom/Asset/ImageProcessingAtom/Config/NormalsWithSmoothness.preset index fdb24ecd09..2c61d6f5a6 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Config/NormalsWithSmoothness.preset +++ b/Gems/Atom/Asset/ImageProcessingAtom/Config/NormalsWithSmoothness.preset @@ -9,11 +9,11 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_ddna", - "_normala", - "_nrma", - "_nma", - "_na" + "_ddna", + "_normala", + "_nrma", + "_nma", + "_na" ], "PixelFormat": "BC5s", "PixelFormatAlpha": "BC4", diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Config/Opacity.preset b/Gems/Atom/Asset/ImageProcessingAtom/Config/Opacity.preset index 6d0d9009a5..79fb235508 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Config/Opacity.preset +++ b/Gems/Atom/Asset/ImageProcessingAtom/Config/Opacity.preset @@ -9,16 +9,16 @@ "SourceColor": "Linear", "DestColor": "Linear", "FileMasks": [ - "_sss", - "_trans", - "_opac", - "_opacity", - "_o", - "_opac", - "_op", - "_mask", - "_msk", - "_blend" + "_sss", + "_trans", + "_opac", + "_opacity", + "_o", + "_opac", + "_op", + "_mask", + "_msk", + "_blend" ], "PixelFormat": "BC4", "IsPowerOf2": true, From 889158e3a993eb371ed358cb3ce3e92c98ae6c8d Mon Sep 17 00:00:00 2001 From: srikappa Date: Mon, 19 Apr 2021 09:53:45 -0700 Subject: [PATCH 06/33] A couple of minor fixes --- .../Prefab/Instance/Instance.cpp | 2 +- .../Prefab/PrefabSystemComponent.cpp | 18 ++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.cpp index bd4c343a3c..0a5b43482e 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.cpp @@ -283,7 +283,7 @@ namespace AzToolsFramework { if (!m_instanceEntityMapper->RegisterEntityToInstance(entityId, *this)) { - AZ_Error("Prefab", false, + AZ_Assert(false, "Prefab - Failed to register entity with id %s with a Prefab Instance derived from source asset %s " "This entity is likely already registered. Check for a double add.", entityId.ToString().c_str(), diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp index 7a9ec0a62e..b777c2bdeb 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp @@ -119,10 +119,7 @@ namespace AzToolsFramework newInstance->AddInstance(AZStd::move(instance)); } - /* - AzToolsFramework::EditorEntityContextRequestBus::Broadcast( - &AzToolsFramework::EditorEntityContextRequests::HandleEntitiesAdded, EntityList{containerEntity->GetId()}); - */ + newInstance->SetTemplateSourcePath(filePath); TemplateId newTemplateId = CreateTemplateFromInstance(*newInstance); @@ -162,14 +159,14 @@ namespace AzToolsFramework void PrefabSystemComponent::UpdatePrefabTemplate(TemplateId templateId, const PrefabDom& updatedDom) { - auto templateRef = FindTemplate(templateId); - if (templateRef.has_value()) + auto templateToUpdate = FindTemplate(templateId); + if (templateToUpdate) { - PrefabDom& templateDomToUpdate = templateRef->get().GetPrefabDom(); + PrefabDom& templateDomToUpdate = templateToUpdate->get().GetPrefabDom(); if (AZ::JsonSerialization::Compare(templateDomToUpdate, updatedDom) != AZ::JsonSerializerCompareResult::Equal) { templateDomToUpdate.CopyFrom(updatedDom, templateDomToUpdate.GetAllocator()); - templateRef->get().MarkAsDirty(true); + templateToUpdate->get().MarkAsDirty(true); PropagateTemplateChanges(templateId); } } @@ -643,12 +640,9 @@ namespace AzToolsFramework newLink.GetLinkDom().AddMember(rapidjson::StringRef(PrefabDomUtils::SourceName), rapidjson::StringRef(sourceTemplate.GetFilePath().c_str()), newLink.GetLinkDom().GetAllocator()); - PrefabDom linkPatchCopy; - linkPatchCopy.CopyFrom(linkPatch->get(), newLink.GetLinkDom().GetAllocator()); - if (linkPatch && linkPatch->get().IsArray() && !(linkPatch->get().Empty())) { - m_instanceToTemplatePropagator.AddPatchesToLink(linkPatchCopy, newLink); + m_instanceToTemplatePropagator.AddPatchesToLink(linkPatch.value(), newLink); } //update the target template dom to have the proper values for the source template dom From f3ff5ec8869e2344e17b1510bf76a9ae6b2a9b2e Mon Sep 17 00:00:00 2001 From: srikappa Date: Mon, 19 Apr 2021 11:05:28 -0700 Subject: [PATCH 07/33] Add helper method for adding link in CreatePrefab --- .../Prefab/PrefabPublicHandler.cpp | 77 +++++++++---------- .../Prefab/PrefabPublicHandler.h | 4 + .../Prefab/PrefabSystemComponent.cpp | 2 +- .../AzToolsFramework/Prefab/PrefabUndo.cpp | 2 +- .../AzToolsFramework/Prefab/PrefabUndo.h | 2 +- .../Prefab/PrefabUndoHelpers.cpp | 10 +++ .../Prefab/PrefabUndoHelpers.h | 3 + 7 files changed, 57 insertions(+), 43 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp index 0ce929217d..2fb186bcf7 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp @@ -100,7 +100,6 @@ namespace AzToolsFramework AZStd::vector> instances; InstanceOptionalReference instance; - { // Initialize Undo Batch object ScopedUndoBatch undoBatch("Create Prefab"); @@ -151,47 +150,9 @@ namespace AzToolsFramework linkRemoveUndo->Redo(); - AZ::EntityId containerEntityId = instance->get().GetContainerEntityId(); - AZ::Entity* containerEntity = GetEntityById(containerEntityId); - // Apply Transform changes as overrides - { - Prefab::PrefabDom containerEntityDomBefore; - m_instanceToTemplateInterface->GenerateDomForEntity(containerEntityDomBefore, *containerEntity); - - AZ::Vector3 containerEntityTranslation(AZ::Vector3::CreateZero()); - AZ::Quaternion containerEntityRotation(AZ::Quaternion::CreateZero()); - - // Set the transform (translation, rotation) of the container entity - GenerateContainerEntityTransform(topLevelEntities, containerEntityTranslation, containerEntityRotation); - - // Set container entity to be child of common root - AZ::TransformBus::Event(containerEntityId, &AZ::TransformBus::Events::SetParent, commonRootEntityId); - - AZ::TransformBus::Event(containerEntityId, &AZ::TransformBus::Events::SetLocalTranslation, containerEntityTranslation); - AZ::TransformBus::Event(containerEntityId, &AZ::TransformBus::Events::SetLocalRotationQuaternion, containerEntityRotation); - - PrefabDom containerEntityDomAfter; - m_instanceToTemplateInterface->GenerateDomForEntity(containerEntityDomAfter, *containerEntity); - - PrefabDom patch; - m_instanceToTemplateInterface->GeneratePatch(patch, containerEntityDomBefore, containerEntityDomAfter); - - m_instanceToTemplateInterface->AppendEntityAliasToPatchPaths(patch, containerEntityId); - - - auto linkAddUndo = aznew PrefabUndoInstanceLink("Undo Link Add Node"); - linkAddUndo->Capture( - commonRootEntityOwningInstance->get().GetTemplateId(), instance->get().GetTemplateId(), instance->get().GetInstanceAlias(), - patch, InvalidLinkId); - linkAddUndo->SetParent(undoBatch.GetUndoBatch()); - - linkAddUndo->Redo(); - - // Update the cache - this prevents these changes from being stored in the regular undo/redo nodes - m_prefabUndoCache.Store(containerEntityId, AZStd::move(containerEntityDomAfter)); - } + AddLink(topLevelEntities, instance->get(), commonRootEntityOwningInstance->get(), undoBatch.GetUndoBatch(), commonRootEntityId); // Change top level entities to be parented to the container entity // Mark them as dirty so this change is correctly applied to the template @@ -216,6 +177,42 @@ namespace AzToolsFramework return AZ::Success(); } + void PrefabPublicHandler::AddLink( + const EntityList& topLevelEntities, Instance& instanceToAdd, Instance& parentInstance, UndoSystem::URSequencePoint* undoBatch, + AZ::EntityId commonRootEntityId) + { + AZ::EntityId containerEntityId = instanceToAdd.GetContainerEntityId(); + AZ::Entity* containerEntity = GetEntityById(containerEntityId); + Prefab::PrefabDom containerEntityDomBefore; + m_instanceToTemplateInterface->GenerateDomForEntity(containerEntityDomBefore, *containerEntity); + + AZ::Vector3 containerEntityTranslation(AZ::Vector3::CreateZero()); + AZ::Quaternion containerEntityRotation(AZ::Quaternion::CreateZero()); + + // Set the transform (translation, rotation) of the container entity + GenerateContainerEntityTransform(topLevelEntities, containerEntityTranslation, containerEntityRotation); + + // Set container entity to be child of common root + AZ::TransformBus::Event(containerEntityId, &AZ::TransformBus::Events::SetParent, commonRootEntityId); + + AZ::TransformBus::Event(containerEntityId, &AZ::TransformBus::Events::SetLocalTranslation, containerEntityTranslation); + AZ::TransformBus::Event(containerEntityId, &AZ::TransformBus::Events::SetLocalRotationQuaternion, containerEntityRotation); + + PrefabDom containerEntityDomAfter; + m_instanceToTemplateInterface->GenerateDomForEntity(containerEntityDomAfter, *containerEntity); + + PrefabDom patch; + m_instanceToTemplateInterface->GeneratePatch(patch, containerEntityDomBefore, containerEntityDomAfter); + m_instanceToTemplateInterface->AppendEntityAliasToPatchPaths(patch, containerEntityId); + + PrefabUndoHelpers::AddLink( + "Add Link", instanceToAdd.GetTemplateId(), parentInstance.GetTemplateId(), patch, instanceToAdd.GetInstanceAlias(), + undoBatch); + + // Update the cache - this prevents these changes from being stored in the regular undo/redo nodes + m_prefabUndoCache.Store(containerEntityId, AZStd::move(containerEntityDomAfter)); + } + PrefabOperationResult PrefabPublicHandler::InstantiatePrefab(AZStd::string_view /*filePath*/, AZ::EntityId /*parent*/, AZ::Vector3 /*position*/) { return AZ::Failure(AZStd::string("Prefab - InstantiatePrefab is yet to be implemented.")); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h index de892470ab..7f3d05e3d3 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h @@ -69,6 +69,10 @@ namespace AzToolsFramework InstanceOptionalReference GetOwnerInstanceByEntityId(AZ::EntityId entityId) const; bool EntitiesBelongToSameInstance(const EntityIdList& entityIds) const; + void AddLink( + const EntityList& topLevelEntities, Instance& instanceToAdd, Instance& parentInstance, + UndoSystem::URSequencePoint* undoBatch, AZ::EntityId commonRootEntityId); + static Instance* GetParentInstance(Instance* instance); static Instance* GetAncestorOfInstanceThatIsChildOfRoot(const Instance* ancestor, Instance* descendant); static void GenerateContainerEntityTransform(const EntityList& topLevelEntities, AZ::Vector3& translation, AZ::Quaternion& rotation); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp index b777c2bdeb..9070630e56 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp @@ -120,7 +120,7 @@ namespace AzToolsFramework newInstance->AddInstance(AZStd::move(instance)); } - newInstance->SetTemplateSourcePath(filePath); + newInstance->SetTemplateSourcePath(relativeFilePath); TemplateId newTemplateId = CreateTemplateFromInstance(*newInstance); if (newTemplateId == InvalidTemplateId) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.cpp index 0d9f9f72a5..ea3fa5d84d 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.cpp @@ -124,7 +124,7 @@ namespace AzToolsFramework const TemplateId& targetId, const TemplateId& sourceId, const InstanceAlias& instanceAlias, - const PrefabDomReference linkDom, + PrefabDomReference linkDom, const LinkId linkId) { m_targetId = targetId; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.h index 7a765c5db7..0d15d707d2 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.h @@ -101,7 +101,7 @@ namespace AzToolsFramework const TemplateId& targetId, const TemplateId& sourceId, const InstanceAlias& instanceAlias, - const PrefabDomReference linkDom = PrefabDomReference(), + PrefabDomReference linkDom = PrefabDomReference(), const LinkId linkId = InvalidLinkId); void Undo() override; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.cpp index da41635d03..1fa9169ae2 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.cpp @@ -32,6 +32,16 @@ namespace AzToolsFramework state->SetParent(undoBatch); state->Redo(); } + + void AddLink( + AZStd::string_view undoMessage, TemplateId sourceTemplateId, TemplateId targetTemplateId, PrefabDomReference patch, + const InstanceAlias& instanceAlias, UndoSystem::URSequencePoint* undoBatch) + { + auto linkAddUndo = aznew PrefabUndoInstanceLink(undoMessage); + linkAddUndo->Capture(targetTemplateId, sourceTemplateId, instanceAlias, patch, InvalidLinkId); + linkAddUndo->SetParent(undoBatch); + linkAddUndo->Redo(); + } } } // namespace Prefab } // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.h index 81d0048e9e..279deb953c 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.h @@ -21,6 +21,9 @@ namespace AzToolsFramework void UpdatePrefabInstance( const Instance& instance, AZStd::string_view undoMessage, const PrefabDom& instanceDomBeforeUpdate, UndoSystem::URSequencePoint* undoBatch); + void AddLink( + AZStd::string_view undoMessage, TemplateId sourceTemplateId, TemplateId targetTemplateId, PrefabDomReference patch, + const InstanceAlias& instanceAlias, UndoSystem::URSequencePoint* undoBatch); } } // namespace Prefab } // namespace AzToolsFramework From 65b2d9de1bcee2cc4466e25738c285bb2f233c7d Mon Sep 17 00:00:00 2001 From: srikappa Date: Mon, 19 Apr 2021 13:43:54 -0700 Subject: [PATCH 08/33] Added couple of helper functions --- .../Prefab/PrefabPublicHandler.cpp | 120 +++++++++--------- .../Prefab/PrefabPublicHandler.h | 6 +- .../Prefab/PrefabUndoHelpers.cpp | 18 ++- .../Prefab/PrefabUndoHelpers.h | 7 +- 4 files changed, 87 insertions(+), 64 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp index 2fb186bcf7..adadc9d0ac 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp @@ -63,53 +63,28 @@ namespace AzToolsFramework PrefabOperationResult PrefabPublicHandler::CreatePrefab(const AZStd::vector& entityIds, AZ::IO::PathView filePath) { - // Retrieve entityList from entityIds - EntityList inputEntityList; - EntityIdListToEntityList(entityIds, inputEntityList); - - // Find common root and top level entities - bool entitiesHaveCommonRoot = false; + EntityList inputEntityList, topLevelEntities; AZ::EntityId commonRootEntityId; - EntityList topLevelEntities; - - AzToolsFramework::ToolsApplicationRequests::Bus::BroadcastResult( - entitiesHaveCommonRoot, &AzToolsFramework::ToolsApplicationRequests::FindCommonRootInactive, inputEntityList, - commonRootEntityId, &topLevelEntities); - - // Bail if entities don't share a common root - if (!entitiesHaveCommonRoot) + InstanceOptionalReference commonRootEntityOwningInstance; + PrefabOperationResult findCommonRootOutcome = FindCommonRootOwningInstance( + entityIds, inputEntityList, topLevelEntities, commonRootEntityId, commonRootEntityOwningInstance); + if (!findCommonRootOutcome.IsSuccess()) { - return AZ::Failure( - AZStd::string("Could not create a new prefab out of the entities provided - entities do not share a common root.")); + return findCommonRootOutcome; } - AZ::Entity* commonRootEntity = nullptr; - if (commonRootEntityId.IsValid()) - { - commonRootEntity = GetEntityById(commonRootEntityId); - } - - // Retrieve the owning instance of the common root entity, which will be our new instance's parent instance. - InstanceOptionalReference commonRootEntityOwningInstance = GetOwnerInstanceByEntityId(commonRootEntityId); - AZ_Assert( - commonRootEntityOwningInstance.has_value(), - "Failed to create prefab : " - "Couldn't get a valid owning instance for the common root entity of the enities provided"); - - AZStd::vector entities; - AZStd::vector> instances; - - InstanceOptionalReference instance; + InstanceOptionalReference instanceToCreate; { // Initialize Undo Batch object ScopedUndoBatch undoBatch("Create Prefab"); - TemplateId commonRootOwningTemplateId = commonRootEntityOwningInstance->get().GetTemplateId(); - PrefabDom commonRootInstanceDomBeforeCreate; m_instanceToTemplateInterface->GenerateDomForInstance( commonRootInstanceDomBeforeCreate, commonRootEntityOwningInstance->get()); + AZStd::vector entities; + AZStd::vector> instances; + // Retrieve all entities affected and identify Instances if (!RetrieveAndSortPrefabEntitiesAndInstances(inputEntityList, commonRootEntityOwningInstance->get(), entities, instances)) { @@ -117,6 +92,14 @@ namespace AzToolsFramework AZStd::string("Could not create a new prefab out of the entities provided - entities do not share a common root.")); } + // When you move instances from another template, you have to remove the links and propagate changes to target template. + for (auto& nestedInstance : instances) + { + PrefabUndoHelpers::RemoveLink( + nestedInstance->GetTemplateId(), commonRootEntityOwningInstance->get().GetTemplateId(), + nestedInstance->GetInstanceAlias(), nestedInstance->GetLinkId(), undoBatch.GetUndoBatch()); + } + auto prefabEditorEntityOwnershipInterface = AZ::Interface::Get(); if (!prefabEditorEntityOwnershipInterface) { @@ -124,35 +107,23 @@ namespace AzToolsFramework "(PrefabEditorEntityOwnershipInterface unavailable).")); } - // When you move instances from another template, you have to remove the links and propagate changes to target template. - auto linkRemoveUndo = aznew PrefabUndoInstanceLink("Undo Link Remove Node"); - for (auto& nestedInstance : instances) - { - PrefabDom emptyLinkDom; - linkRemoveUndo->Capture( - commonRootOwningTemplateId, nestedInstance->GetTemplateId(), nestedInstance->GetInstanceAlias(), emptyLinkDom, - nestedInstance->GetLinkId()); - linkRemoveUndo->SetParent(undoBatch.GetUndoBatch()); - } - // Create the Prefab - instance = prefabEditorEntityOwnershipInterface->CreatePrefab( + instanceToCreate = prefabEditorEntityOwnershipInterface->CreatePrefab( entities, AZStd::move(instances), filePath, commonRootEntityOwningInstance); - if (!instance) + if (!instanceToCreate) { return AZ::Failure(AZStd::string("Could not create a new prefab out of the entities provided - internal error " "(A null instance is returned).")); } PrefabUndoHelpers::UpdatePrefabInstance( - commonRootEntityOwningInstance->get(), "Undo detaching entity", commonRootInstanceDomBeforeCreate, undoBatch.GetUndoBatch()); + commonRootEntityOwningInstance->get(), "Update prefab instance", commonRootInstanceDomBeforeCreate, undoBatch.GetUndoBatch()); - linkRemoveUndo->Redo(); - - AZ::EntityId containerEntityId = instance->get().GetContainerEntityId(); - - AddLink(topLevelEntities, instance->get(), commonRootEntityOwningInstance->get(), undoBatch.GetUndoBatch(), commonRootEntityId); + CreateLink( + topLevelEntities, instanceToCreate->get(), commonRootEntityOwningInstance->get(), undoBatch.GetUndoBatch(), + commonRootEntityId); + AZ::EntityId containerEntityId = instanceToCreate->get().GetContainerEntityId(); // Change top level entities to be parented to the container entity // Mark them as dirty so this change is correctly applied to the template @@ -172,12 +143,45 @@ namespace AzToolsFramework } // Save Template to file - m_prefabLoaderInterface->SaveTemplate(instance->get().GetTemplateId()); + m_prefabLoaderInterface->SaveTemplate(instanceToCreate->get().GetTemplateId()); return AZ::Success(); } - void PrefabPublicHandler::AddLink( + PrefabOperationResult PrefabPublicHandler::FindCommonRootOwningInstance( + const AZStd::vector& entityIds, EntityList& inputEntityList, EntityList& topLevelEntities, + AZ::EntityId& commonRootEntityId, InstanceOptionalReference& commonRootEntityOwningInstance) + { + // Retrieve entityList from entityIds + EntityIdListToEntityList(entityIds, inputEntityList); + + // Find common root and top level entities + bool entitiesHaveCommonRoot = false; + + AzToolsFramework::ToolsApplicationRequests::Bus::BroadcastResult( + entitiesHaveCommonRoot, &AzToolsFramework::ToolsApplicationRequests::FindCommonRootInactive, inputEntityList, + commonRootEntityId, &topLevelEntities); + + // Bail if entities don't share a common root + if (!entitiesHaveCommonRoot) + { + return AZ::Failure(AZStd::string("Failed to create a prefab: Provided entities do not share a common root.")); + } + + // Retrieve the owning instance of the common root entity, which will be our new instance's parent instance. + commonRootEntityOwningInstance = GetOwnerInstanceByEntityId(commonRootEntityId); + if (!commonRootEntityOwningInstance) + { + AZ_Assert( + false, + "Failed to create prefab : Couldn't get a valid owning instance for the common root entity of the enities provided"); + return AZ::Failure(AZStd::string( + "Failed to create prefab : Couldn't get a valid owning instance for the common root entity of the enities provided")); + } + return AZ::Success(); + } + + void PrefabPublicHandler::CreateLink( const EntityList& topLevelEntities, Instance& instanceToAdd, Instance& parentInstance, UndoSystem::URSequencePoint* undoBatch, AZ::EntityId commonRootEntityId) { @@ -205,8 +209,8 @@ namespace AzToolsFramework m_instanceToTemplateInterface->GeneratePatch(patch, containerEntityDomBefore, containerEntityDomAfter); m_instanceToTemplateInterface->AppendEntityAliasToPatchPaths(patch, containerEntityId); - PrefabUndoHelpers::AddLink( - "Add Link", instanceToAdd.GetTemplateId(), parentInstance.GetTemplateId(), patch, instanceToAdd.GetInstanceAlias(), + PrefabUndoHelpers::CreateLink( + instanceToAdd.GetTemplateId(), parentInstance.GetTemplateId(), patch, instanceToAdd.GetInstanceAlias(), undoBatch); // Update the cache - this prevents these changes from being stored in the regular undo/redo nodes diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h index 7f3d05e3d3..d05192a3b4 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h @@ -69,10 +69,14 @@ namespace AzToolsFramework InstanceOptionalReference GetOwnerInstanceByEntityId(AZ::EntityId entityId) const; bool EntitiesBelongToSameInstance(const EntityIdList& entityIds) const; - void AddLink( + void CreateLink( const EntityList& topLevelEntities, Instance& instanceToAdd, Instance& parentInstance, UndoSystem::URSequencePoint* undoBatch, AZ::EntityId commonRootEntityId); + PrefabOperationResult FindCommonRootOwningInstance( + const AZStd::vector& entityIds, EntityList& inputEntityList, EntityList& topLevelEntities, + AZ::EntityId& commonRootEntityId, InstanceOptionalReference& commonRootEntityOwningInstance); + static Instance* GetParentInstance(Instance* instance); static Instance* GetAncestorOfInstanceThatIsChildOfRoot(const Instance* ancestor, Instance* descendant); static void GenerateContainerEntityTransform(const EntityList& topLevelEntities, AZ::Vector3& translation, AZ::Quaternion& rotation); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.cpp index 1fa9169ae2..c9b6c88a97 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.cpp @@ -33,15 +33,27 @@ namespace AzToolsFramework state->Redo(); } - void AddLink( - AZStd::string_view undoMessage, TemplateId sourceTemplateId, TemplateId targetTemplateId, PrefabDomReference patch, + void CreateLink( + TemplateId sourceTemplateId, TemplateId targetTemplateId, PrefabDomReference patch, const InstanceAlias& instanceAlias, UndoSystem::URSequencePoint* undoBatch) { - auto linkAddUndo = aznew PrefabUndoInstanceLink(undoMessage); + auto linkAddUndo = aznew PrefabUndoInstanceLink("Create Link"); linkAddUndo->Capture(targetTemplateId, sourceTemplateId, instanceAlias, patch, InvalidLinkId); linkAddUndo->SetParent(undoBatch); linkAddUndo->Redo(); } + + void RemoveLink( + TemplateId sourceTemplateId, TemplateId targetTemplateId, const InstanceAlias& instanceAlias, + LinkId linkId, UndoSystem::URSequencePoint* undoBatch) + { + auto linkRemoveUndo = aznew PrefabUndoInstanceLink("Remove Link"); + PrefabDom emptyLinkDom; + linkRemoveUndo->Capture( + targetTemplateId, sourceTemplateId, instanceAlias, emptyLinkDom, linkId); + linkRemoveUndo->SetParent(undoBatch); + linkRemoveUndo->Redo(); + } } } // namespace Prefab } // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.h index 279deb953c..5f81ef14a8 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.h @@ -21,9 +21,12 @@ namespace AzToolsFramework void UpdatePrefabInstance( const Instance& instance, AZStd::string_view undoMessage, const PrefabDom& instanceDomBeforeUpdate, UndoSystem::URSequencePoint* undoBatch); - void AddLink( - AZStd::string_view undoMessage, TemplateId sourceTemplateId, TemplateId targetTemplateId, PrefabDomReference patch, + void CreateLink( + TemplateId sourceTemplateId, TemplateId targetTemplateId, PrefabDomReference patch, const InstanceAlias& instanceAlias, UndoSystem::URSequencePoint* undoBatch); + void RemoveLink( + TemplateId sourceTemplateId, TemplateId targetTemplateId, const InstanceAlias& instanceAlias, + LinkId linkId, UndoSystem::URSequencePoint* undoBatch); } } // namespace Prefab } // namespace AzToolsFramework From 707f7cb6cefe7b43c03495a9137d829c63722710 Mon Sep 17 00:00:00 2001 From: srikappa Date: Mon, 19 Apr 2021 15:06:41 -0700 Subject: [PATCH 09/33] Added some comments --- .../Instance/InstanceUpdateExecutor.cpp | 5 +++++ .../Prefab/PrefabPublicHandler.cpp | 10 ++++----- .../Prefab/PrefabPublicHandler.h | 21 ++++++++++++++++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp index d84edd6212..b307d8290c 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp @@ -117,6 +117,7 @@ namespace AzToolsFramework "Could not find Template using Id '%llu'. Unable to update Instance.", currentTemplateId); + // Remove the instance from update queue if it's corresponding template couldn't be found isUpdateSuccessful = false; m_instancesUpdateQueue.pop(); continue; @@ -127,6 +128,8 @@ namespace AzToolsFramework if (findInstancesResult.find(instanceToUpdate) == findInstancesResult.end()) { + // Since nested instances get reconstructed during propgation, remove any nested instance that no longer + // maps to a template. isUpdateSuccessful = false; m_instancesUpdateQueue.pop(); continue; @@ -155,6 +158,8 @@ namespace AzToolsFramework for (auto entityIdIterator = selectedEntityIds.begin(); entityIdIterator != selectedEntityIds.end(); entityIdIterator++) { + // Since entities get recreated during propagation, we need to check whether the entities correspoding to the list + // of selected entity ids are present or not. AZ::Entity* entity = GetEntityById(*entityIdIterator); if (entity == nullptr) { diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp index adadc9d0ac..6ba342bf9b 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp @@ -121,7 +121,7 @@ namespace AzToolsFramework commonRootEntityOwningInstance->get(), "Update prefab instance", commonRootInstanceDomBeforeCreate, undoBatch.GetUndoBatch()); CreateLink( - topLevelEntities, instanceToCreate->get(), commonRootEntityOwningInstance->get(), undoBatch.GetUndoBatch(), + topLevelEntities, instanceToCreate->get(), commonRootEntityOwningInstance->get().GetTemplateId(), undoBatch.GetUndoBatch(), commonRootEntityId); AZ::EntityId containerEntityId = instanceToCreate->get().GetContainerEntityId(); @@ -182,10 +182,10 @@ namespace AzToolsFramework } void PrefabPublicHandler::CreateLink( - const EntityList& topLevelEntities, Instance& instanceToAdd, Instance& parentInstance, UndoSystem::URSequencePoint* undoBatch, - AZ::EntityId commonRootEntityId) + const EntityList& topLevelEntities, Instance& sourceInstance, TemplateId targetTemplateId, + UndoSystem::URSequencePoint* undoBatch, AZ::EntityId commonRootEntityId) { - AZ::EntityId containerEntityId = instanceToAdd.GetContainerEntityId(); + AZ::EntityId containerEntityId = sourceInstance.GetContainerEntityId(); AZ::Entity* containerEntity = GetEntityById(containerEntityId); Prefab::PrefabDom containerEntityDomBefore; m_instanceToTemplateInterface->GenerateDomForEntity(containerEntityDomBefore, *containerEntity); @@ -210,7 +210,7 @@ namespace AzToolsFramework m_instanceToTemplateInterface->AppendEntityAliasToPatchPaths(patch, containerEntityId); PrefabUndoHelpers::CreateLink( - instanceToAdd.GetTemplateId(), parentInstance.GetTemplateId(), patch, instanceToAdd.GetInstanceAlias(), + sourceInstance.GetTemplateId(), targetTemplateId, patch, sourceInstance.GetInstanceAlias(), undoBatch); // Update the cache - this prevents these changes from being stored in the regular undo/redo nodes diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h index d05192a3b4..f97fa46c3e 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h @@ -69,10 +69,29 @@ namespace AzToolsFramework InstanceOptionalReference GetOwnerInstanceByEntityId(AZ::EntityId entityId) const; bool EntitiesBelongToSameInstance(const EntityIdList& entityIds) const; + /** + * Creates a link between the templates of an instance and its parent. + * + * \param topLevelEntities The list of entities that are immediate children of container entity of instance. + * \param sourceInstance The instance that corresponds to the source template of the link. + * \param targetInstance The id of the target template. + * \param undoBatch The undo batch to set as parent for this create link action. + * \param commonRootEntityId The id of the entity that the source instance should be parented under. + */ void CreateLink( - const EntityList& topLevelEntities, Instance& instanceToAdd, Instance& parentInstance, + const EntityList& topLevelEntities, Instance& sourceInstance, TemplateId targetTemplateId, UndoSystem::URSequencePoint* undoBatch, AZ::EntityId commonRootEntityId); + /** + * Given a list of entityIds, finds the prefab instance that owns the common root entity of the entityIds. + * + * \param entityIds The list of entity ids. + * \param inputEntityList The list of entities corresponding to the entity ids. + * \param topLevelEntities The list of entities that are immediate children of the common root entity. + * \param commonRootEntityId The entity id of the common root entity of all the entityIds. + * \param commonRootEntityOwningInstance The owning instance of the common root entity. + * \return PrefabOperationResult indicating whether the action was successful or not. + */ PrefabOperationResult FindCommonRootOwningInstance( const AZStd::vector& entityIds, EntityList& inputEntityList, EntityList& topLevelEntities, AZ::EntityId& commonRootEntityId, InstanceOptionalReference& commonRootEntityOwningInstance); From 8fc69113c9d91a7fd64948787488e8f742962b3a Mon Sep 17 00:00:00 2001 From: nvsickle Date: Mon, 19 Apr 2021 15:08:06 -0700 Subject: [PATCH 10/33] Get the default viewport context on demand in FFont, as it may change --- .../AtomLyIntegration/AtomFont/FFont.h | 31 ++--------------- .../AtomFont/Code/Source/FFont.cpp | 33 +++++++++++++------ 2 files changed, 26 insertions(+), 38 deletions(-) diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h index 96f5e09fc3..a6066984c7 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h +++ b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h @@ -277,11 +277,11 @@ namespace AZ void ScaleCoord(const RHI::Viewport& viewport, float& x, float& y) const; - void InitDefaultWindowContext(); - void InitDefaultViewportContext(); - void OnBootstrapSceneReady(AZ::RPI::Scene* bootstrapScene) override; + RPI::WindowContextSharedPtr GetDefaultWindowContext() const; + RPI::ViewportContextPtr GetDefaultViewportContext() const; + private: static constexpr uint32_t NumBuffers = 2; static constexpr float WindowScaleWidth = 800.0f; @@ -294,9 +294,6 @@ namespace AZ size_t m_fontBufferSize = 0; unsigned char* m_fontBuffer = nullptr; - AZStd::shared_ptr m_defaultWindowContext; - AZStd::shared_ptr m_defaultViewportContext; - AZ::Data::Instance m_fontStreamingImage; AZ::RHI::Ptr m_fontImage; uint32_t m_fontImageVersion = 0; @@ -345,26 +342,4 @@ namespace AZ } } -inline void AZ::FFont::InitDefaultWindowContext() -{ - if (!m_defaultWindowContext) - { - // font is created before window & viewport in the editor so need to do late init - // TODO need to deal with multiple windows, such as the editor - AZ::Render::Bootstrap::DefaultWindowBus::BroadcastResult(m_defaultWindowContext, &AZ::Render::Bootstrap::DefaultWindowInterface::GetDefaultWindowContext); - AZ_Assert(m_defaultWindowContext, "Unable to get the main window context"); - } -} - -inline void AZ::FFont::InitDefaultViewportContext() -{ - if (!m_defaultViewportContext) - { - // font is created before window & viewport in the editor so need to do late init - auto viewContextManager = AZ::Interface::Get(); - m_defaultViewportContext = viewContextManager->GetViewportContextByName(viewContextManager->GetDefaultViewportContextName()); - AZ_Assert(m_defaultViewportContext, "Unable to get the viewport context"); - } -} - #endif diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp b/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp index d32302a07b..38024393fa 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp +++ b/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp @@ -84,6 +84,20 @@ AZ::FFont::FFont(AtomFont* atomFont, const char* fontName) AZ::Render::Bootstrap::NotificationBus::Handler::BusConnect(); } +AZ::RPI::ViewportContextPtr AZ::FFont::GetDefaultViewportContext() const +{ + auto viewContextManager = AZ::Interface::Get(); + return viewContextManager->GetDefaultViewportContext(); +} + +AZ::RPI::WindowContextSharedPtr AZ::FFont::GetDefaultWindowContext() const +{ + if (auto defaultViewportContext = GetDefaultViewportContext()) + { + return defaultViewportContext->GetWindowContext(); + } + return {}; +} bool AZ::FFont::InitFont() { @@ -92,11 +106,8 @@ bool AZ::FFont::InitFont() return true; } - InitDefaultWindowContext(); - InitDefaultViewportContext(); - // Create and initialize DynamicDrawContext for font draw - AZ::RPI::Ptr dynamicDraw = m_atomFont->GetOrCreateDynamicDrawForScene(m_defaultViewportContext->GetRenderScene().get()); + AZ::RPI::Ptr dynamicDraw = m_atomFont->GetOrCreateDynamicDrawForScene(GetDefaultViewportContext()->GetRenderScene().get()); // Save draw srg input indices for later use Data::Instance drawSrg = dynamicDraw->NewDrawSrg(); @@ -259,7 +270,7 @@ void AZ::FFont::DrawString(float x, float y, const char* str, const bool asciiMu return; } - DrawStringUInternal(m_defaultWindowContext->GetViewport(), m_defaultViewportContext.get(), x, y, 1.0f, str, asciiMultiLine, ctx); + DrawStringUInternal(GetDefaultWindowContext()->GetViewport(), GetDefaultViewportContext().get(), x, y, 1.0f, str, asciiMultiLine, ctx); } void AZ::FFont::DrawString(float x, float y, float z, const char* str, const bool asciiMultiLine, const TextDrawContext& ctx) @@ -269,7 +280,7 @@ void AZ::FFont::DrawString(float x, float y, float z, const char* str, const boo return; } - DrawStringUInternal(m_defaultWindowContext->GetViewport(), m_defaultViewportContext.get(), x, y, z, str, asciiMultiLine, ctx); + DrawStringUInternal(GetDefaultWindowContext()->GetViewport(), GetDefaultViewportContext().get(), x, y, z, str, asciiMultiLine, ctx); } void AZ::FFont::DrawStringUInternal( @@ -282,6 +293,8 @@ void AZ::FFont::DrawStringUInternal( const bool asciiMultiLine, const TextDrawContext& ctx) { + InitFont(); + if (!str || !m_vertexBuffer // vertex buffer isn't created until BootstrapScene is ready, Editor tries to render text before that. || !m_fontTexture @@ -400,7 +413,7 @@ Vec2 AZ::FFont::GetTextSize(const char* str, const bool asciiMultiLine, const Te return Vec2(0.0f, 0.0f); } - return GetTextSizeUInternal(m_defaultWindowContext->GetViewport(), str, asciiMultiLine, ctx); + return GetTextSizeUInternal(GetDefaultWindowContext()->GetViewport(), str, asciiMultiLine, ctx); } Vec2 AZ::FFont::GetTextSizeUInternal( @@ -746,7 +759,7 @@ uint32_t AZ::FFont::WriteTextQuadsToBuffers(SVF_P2F_C4B_T2F_F4B* verts, uint16_t return true; }; - CreateQuadsForText(m_defaultWindowContext->GetViewport(), x, y, z, str, asciiMultiLine, ctx, AddQuad); + CreateQuadsForText(GetDefaultWindowContext()->GetViewport(), x, y, z, str, asciiMultiLine, ctx, AddQuad); return numQuadsWritten; } @@ -1438,7 +1451,7 @@ void AZ::FFont::AddCharsToFontTexture(const char* chars, int glyphSizeX, int gly Vec2 AZ::FFont::GetKerning(uint32_t leftGlyph, uint32_t rightGlyph, const TextDrawContext& ctx) const { - return GetKerningInternal(m_defaultWindowContext->GetViewport(), leftGlyph, rightGlyph, ctx); + return GetKerningInternal(GetDefaultWindowContext()->GetViewport(), leftGlyph, rightGlyph, ctx); } Vec2 AZ::FFont::GetKerningInternal(const RHI::Viewport& viewport, uint32_t leftGlyph, uint32_t rightGlyph, const TextDrawContext& ctx) const @@ -1454,7 +1467,7 @@ float AZ::FFont::GetAscender(const TextDrawContext& ctx) const float AZ::FFont::GetBaseline(const TextDrawContext& ctx) const { - return GetBaselineInternal(m_defaultWindowContext->GetViewport(), ctx); + return GetBaselineInternal(GetDefaultWindowContext()->GetViewport(), ctx); } float AZ::FFont::GetBaselineInternal(const RHI::Viewport& viewport, const TextDrawContext& ctx) const From c05d4b44e4789eafdad6168bba28e46870d257cd Mon Sep 17 00:00:00 2001 From: nvsickle Date: Mon, 19 Apr 2021 15:08:40 -0700 Subject: [PATCH 11/33] Move supplemental EditorViewportWidget rendering to OnBeginPrepareRender to avoid sync issues --- Code/Sandbox/Editor/EditorViewportWidget.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Code/Sandbox/Editor/EditorViewportWidget.cpp b/Code/Sandbox/Editor/EditorViewportWidget.cpp index 695a0fa5f1..897b3c569d 100644 --- a/Code/Sandbox/Editor/EditorViewportWidget.cpp +++ b/Code/Sandbox/Editor/EditorViewportWidget.cpp @@ -276,9 +276,6 @@ void EditorViewportWidget::paintEvent([[maybe_unused]] QPaintEvent* event) if ((ge && ge->IsLevelLoaded()) || (GetType() != ET_ViewportCamera)) { setRenderOverlayVisible(true); - m_isOnPaint = true; - Update(); - m_isOnPaint = false; } else { @@ -809,6 +806,10 @@ void EditorViewportWidget::OnBeginPrepareRender() return; } + m_isOnPaint = true; + Update(); + m_isOnPaint = false; + float fNearZ = GetIEditor()->GetConsoleVar("cl_DefaultNearPlane"); float fFarZ = m_Camera.GetFarPlane(); From 482e423ec9294a416697a37f0f08054814963b55 Mon Sep 17 00:00:00 2001 From: nvsickle Date: Fri, 16 Apr 2021 12:00:13 -0700 Subject: [PATCH 12/33] Fix crash on default layout restore --- Code/Sandbox/Editor/LayoutWnd.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Code/Sandbox/Editor/LayoutWnd.cpp b/Code/Sandbox/Editor/LayoutWnd.cpp index 56c0bcb849..dc3ae14d90 100644 --- a/Code/Sandbox/Editor/LayoutWnd.cpp +++ b/Code/Sandbox/Editor/LayoutWnd.cpp @@ -418,8 +418,9 @@ void CLayoutWnd::CreateLayout(EViewLayout layout, bool bBindViewports, EViewport QRect rcView = rect(); rcView.setBottom(rcView.bottom() - m_infoBar->height()); + // Ensure we delete our old view immediately so it can relinquish its backing ViewportContext if (m_maximizedView) - m_maximizedView->deleteLater(); + delete m_maximizedView; m_maximizedView = new CLayoutViewPane(this); m_maximizedView->SetId(0); From d2fadcb0e37bc78b035e9b0cb3c37fa960a7b190 Mon Sep 17 00:00:00 2001 From: nvsickle Date: Fri, 16 Apr 2021 12:02:55 -0700 Subject: [PATCH 13/33] Fix context menu handling in multi-viewport scenarios (the logic bugs here were many and nuanced, but we're narrowing in on something robust). Specifically this: -Ensures key/mouse up event propagation works across multiple viewports -Ensures that mouse up events for manipulators only get delivered if there's a corresponding mouse down event -Also tidies up the "are we done processing events this tick?" logic in ViewportManipulatorController --- .../Editor/ViewportManipulatorController.cpp | 26 +++++++++++++++---- .../Source/Viewport/RenderViewportWidget.cpp | 19 +++++++++++--- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/Code/Sandbox/Editor/ViewportManipulatorController.cpp b/Code/Sandbox/Editor/ViewportManipulatorController.cpp index 910d037670..8ce2ea1cd9 100644 --- a/Code/Sandbox/Editor/ViewportManipulatorController.cpp +++ b/Code/Sandbox/Editor/ViewportManipulatorController.cpp @@ -95,6 +95,11 @@ bool ViewportManipulatorControllerInstance::HandleInputChannelEvent(const AzFram AZStd::optional overrideButton; AZStd::optional eventType; + // Because we receive events multiple times at separate priorities for manipulator events and + // viewport interaction events, we want to avoid updating our "last tick state" until we're on our last event, + // which currently is the low priority Interaction processor. + const bool finishedProcessingEvents = event.m_priority == InteractionPriority; + if (IsMouseMove(event.m_inputChannel)) { // Cache the ray trace results when doing manipulator interaction checks, no need to recalculate after @@ -120,10 +125,11 @@ bool ViewportManipulatorControllerInstance::HandleInputChannelEvent(const AzFram } else if (auto mouseButton = GetMouseButton(event.m_inputChannel); mouseButton != MouseButton::None) { + const AZ::u32 mouseButtonValue = static_cast(mouseButton); overrideButton = mouseButton; if (event.m_inputChannel.GetState() == InputChannel::State::Began) { - m_state.m_mouseButtons.m_mouseButtons |= static_cast(mouseButton); + m_state.m_mouseButtons.m_mouseButtons |= mouseButtonValue; if (IsDoubleClick(mouseButton)) { // Only remove the double click flag once we're done processing both Manipulator and Interaction events @@ -135,8 +141,8 @@ bool ViewportManipulatorControllerInstance::HandleInputChannelEvent(const AzFram } else { - // Only insert the double click timing once we're done processing both Manipulator and Interaction events, to avoid a false IsDoubleClick positive - if (event.m_priority == InteractionPriority) + // Only insert the double click timing once we're done processing events, to avoid a false IsDoubleClick positive + if (finishedProcessingEvents) { m_pendingDoubleClicks[mouseButton] = m_curTime; } @@ -145,8 +151,18 @@ bool ViewportManipulatorControllerInstance::HandleInputChannelEvent(const AzFram } else if (event.m_inputChannel.GetState() == InputChannel::State::Ended) { - m_state.m_mouseButtons.m_mouseButtons &= ~static_cast(mouseButton); - eventType = MouseEvent::Up; + // If we've actually logged a mouse down event, forward a mouse up event. + // This prevents corner cases like the context menu thinking it should be opened even though no one clicked in this viewport, + // due to RenderViewportWidget ensuring all controllers get InputChannel::State::Ended events. + if (m_state.m_mouseButtons.m_mouseButtons & mouseButtonValue) + { + // Erase the button from our state if we're done processing events. + if (event.m_priority == InteractionPriority) + { + m_state.m_mouseButtons.m_mouseButtons &= ~mouseButtonValue; + } + eventType = MouseEvent::Up; + } } } else if (auto keyboardModifier = GetKeyboardModifier(event.m_inputChannel); keyboardModifier != KeyboardModifier::None) diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp index e08a5a045c..9ea2144289 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp @@ -164,6 +164,8 @@ namespace AtomToolsFramework bool RenderViewportWidget::OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) { + bool shouldConsumeEvent = true; + // Grab keyboard focus if we've been clicked on. // Qt normally handles this for us, but we're filtering native events before they get // synthesized into QMouseEvents. @@ -175,9 +177,18 @@ namespace AtomToolsFramework // Don't consume new input events if we don't currently have focus. // We do forward Ended events, as they may be relevant to our current state // (e.g. a key gets released after we lose focus, it shouldn't remain "stuck"). - if (!hasFocus() && inputChannel.GetState() != AzFramework::InputChannel::State::Ended) + if (!hasFocus()) { - return false; + if (inputChannel.GetState() == AzFramework::InputChannel::State::Ended) + { + // Forward the input ended event to our controllers, but don't prevent other viewports from receiving it. + shouldConsumeEvent = false; + } + else + { + // Not an event we should listen to, abort + return false; + } } // If we receive a mouse button event from outside of our viewport, ignore it even if we have focus. @@ -196,7 +207,9 @@ namespace AtomToolsFramework } AzFramework::NativeWindowHandle windowId = reinterpret_cast(winId()); - return m_controllerList->HandleInputChannelEvent({GetId(), windowId, inputChannel}); + const bool eventHandled = m_controllerList->HandleInputChannelEvent({GetId(), windowId, inputChannel}); + // If our controllers handled the event and it's one we can safely consume (i.e. it's not an Ended event that other viewports might need), consume it. + return eventHandled && shouldConsumeEvent; } void RenderViewportWidget::OnTick([[maybe_unused]]float deltaTime, AZ::ScriptTimePoint time) From dd7334471f9920b6312738c5abcf9d5fc37e0b1d Mon Sep 17 00:00:00 2001 From: nvsickle Date: Fri, 16 Apr 2021 12:17:35 -0700 Subject: [PATCH 14/33] Fix comment punctuation --- .../Code/Source/Viewport/RenderViewportWidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp index 9ea2144289..bf46ece27b 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp @@ -186,7 +186,7 @@ namespace AtomToolsFramework } else { - // Not an event we should listen to, abort + // Not an event we should listen to, abort. return false; } } From ebf41d2bdf58dcc3f7899bf94cf84e380c0f8428 Mon Sep 17 00:00:00 2001 From: nvsickle Date: Fri, 16 Apr 2021 14:26:58 -0700 Subject: [PATCH 15/33] Update code style --- Code/Sandbox/Editor/LayoutWnd.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Code/Sandbox/Editor/LayoutWnd.cpp b/Code/Sandbox/Editor/LayoutWnd.cpp index dc3ae14d90..34a96bca53 100644 --- a/Code/Sandbox/Editor/LayoutWnd.cpp +++ b/Code/Sandbox/Editor/LayoutWnd.cpp @@ -420,7 +420,9 @@ void CLayoutWnd::CreateLayout(EViewLayout layout, bool bBindViewports, EViewport // Ensure we delete our old view immediately so it can relinquish its backing ViewportContext if (m_maximizedView) + { delete m_maximizedView; + } m_maximizedView = new CLayoutViewPane(this); m_maximizedView->SetId(0); From e2a76299938d5e7a2f942917e434f9f4f2f8cb3f Mon Sep 17 00:00:00 2001 From: nvsickle Date: Mon, 19 Apr 2021 15:24:08 -0700 Subject: [PATCH 16/33] Remove statistics rendering from EditorViewportWidget - it's wrong at the moment, and needs to be moved to a controller --- Code/Sandbox/Editor/EditorViewportWidget.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Code/Sandbox/Editor/EditorViewportWidget.cpp b/Code/Sandbox/Editor/EditorViewportWidget.cpp index 897b3c569d..3c714b1d4c 100644 --- a/Code/Sandbox/Editor/EditorViewportWidget.cpp +++ b/Code/Sandbox/Editor/EditorViewportWidget.cpp @@ -906,11 +906,6 @@ void EditorViewportWidget::OnBeginPrepareRender() m_debugDisplay->DepthTestOn(); PostWidgetRendering(); - - if (!m_renderer->IsStereoEnabled()) - { - GetIEditor()->GetSystem()->RenderStatistics(); - } } ////////////////////////////////////////////////////////////////////////// From 6aabf2ee3db06bc56725b7cecea2e45f4d508621 Mon Sep 17 00:00:00 2001 From: nvsickle Date: Mon, 19 Apr 2021 15:36:25 -0700 Subject: [PATCH 17/33] Don't attempt to render manipulators in game mode --- Code/Sandbox/Editor/EditorViewportWidget.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Code/Sandbox/Editor/EditorViewportWidget.cpp b/Code/Sandbox/Editor/EditorViewportWidget.cpp index 3c714b1d4c..91c70b720f 100644 --- a/Code/Sandbox/Editor/EditorViewportWidget.cpp +++ b/Code/Sandbox/Editor/EditorViewportWidget.cpp @@ -881,6 +881,11 @@ void EditorViewportWidget::OnBeginPrepareRender() GetIEditor()->GetSystem()->SetViewCamera(m_Camera); + if (GetIEditor()->IsInGameMode()) + { + return; + } + PreWidgetRendering(); RenderAll(); From dee0f8470448c5ce4d60944f0db6df091e17c3f0 Mon Sep 17 00:00:00 2001 From: nvsickle Date: Mon, 19 Apr 2021 17:00:36 -0700 Subject: [PATCH 18/33] Clarified lazy initialization and added some thread sanity logic after discussion with @rgba16f --- .../Include/AtomLyIntegration/AtomFont/FFont.h | 1 + .../AtomFont/Code/Source/FFont.cpp | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h index a6066984c7..91fc0834ec 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h +++ b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h @@ -302,6 +302,7 @@ namespace AZ bool m_fontTexDirty = false; bool m_fontInitialized = false; + AZStd::atomic_bool m_fontInitializing = false; FontEffects m_effects; diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp b/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp index 38024393fa..edbf148940 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp +++ b/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp @@ -106,6 +106,14 @@ bool AZ::FFont::InitFont() return true; } + // If we're being initialized in another thread, abort. + if (m_fontInitializing) + { + return false; + } + + m_fontInitializing = true; + // Create and initialize DynamicDrawContext for font draw AZ::RPI::Ptr dynamicDraw = m_atomFont->GetOrCreateDynamicDrawForScene(GetDefaultViewportContext()->GetRenderScene().get()); @@ -129,6 +137,7 @@ bool AZ::FFont::InitFont() m_indexCount = 0; m_fontInitialized = true; + m_fontInitializing = false; return true; } @@ -293,7 +302,11 @@ void AZ::FFont::DrawStringUInternal( const bool asciiMultiLine, const TextDrawContext& ctx) { - InitFont(); + // Lazily ensure we're initialized before attempting to render. + if (!InitFont()) + { + return; + } if (!str || !m_vertexBuffer // vertex buffer isn't created until BootstrapScene is ready, Editor tries to render text before that. From 967d182ccc9f6deb7c2f95bd9c0cef3a5ff60fe8 Mon Sep 17 00:00:00 2001 From: srikappa Date: Mon, 19 Apr 2021 17:29:03 -0700 Subject: [PATCH 19/33] Fixed a couple of typos --- .../Prefab/Instance/InstanceUpdateExecutor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp index b307d8290c..71b1e04ec8 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp @@ -117,7 +117,7 @@ namespace AzToolsFramework "Could not find Template using Id '%llu'. Unable to update Instance.", currentTemplateId); - // Remove the instance from update queue if it's corresponding template couldn't be found + // Remove the instance from update queue if its corresponding template couldn't be found isUpdateSuccessful = false; m_instancesUpdateQueue.pop(); continue; @@ -128,7 +128,7 @@ namespace AzToolsFramework if (findInstancesResult.find(instanceToUpdate) == findInstancesResult.end()) { - // Since nested instances get reconstructed during propgation, remove any nested instance that no longer + // Since nested instances get reconstructed during propagation, remove any nested instance that no longer // maps to a template. isUpdateSuccessful = false; m_instancesUpdateQueue.pop(); From 33e61ad35ba191fd8490e02fe151476256e0bb54 Mon Sep 17 00:00:00 2001 From: mbalfour Date: Wed, 14 Apr 2021 16:03:27 -0500 Subject: [PATCH 20/33] Added SetEntityName and exposed Get/SetEntityName to the behavior context for use from scripts. (cherry picked from commit 4f2e0b74727cfe99c74ed588769a540f24d7aa46) --- .../AzCore/Component/ComponentApplication.cpp | 24 +++++++++++++++++++ .../AzCore/Component/ComponentApplication.h | 1 + .../Component/ComponentApplicationBus.h | 8 ++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp index a3af2648cf..a3986f72dd 100644 --- a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp +++ b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp @@ -341,6 +341,16 @@ namespace AZ ; } } + + if (auto behaviorContext = azrtti_cast(context)) + { + behaviorContext->EBus("ComponentApplicationBus") + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) + ->Attribute(AZ::Script::Attributes::Category, "Components") + + ->Event("GetEntityName", &ComponentApplicationBus::Events::GetEntityName) + ->Event("SetEntityName", &ComponentApplicationBus::Events::SetEntityName); + } } //========================================================================= @@ -1050,6 +1060,20 @@ namespace AZ return AZStd::string(); } + //========================================================================= + // SetEntityName + //========================================================================= + bool ComponentApplication::SetEntityName(const EntityId& id, const AZStd::string& name) + { + Entity* entity = FindEntity(id); + if (entity) + { + entity->SetName(name); + return true; + } + return false; + } + //========================================================================= // EnumerateEntities //========================================================================= diff --git a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h index ef5c813573..a66409eaf3 100644 --- a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h +++ b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h @@ -209,6 +209,7 @@ namespace AZ bool DeleteEntity(const EntityId& id) override; Entity* FindEntity(const EntityId& id) override; AZStd::string GetEntityName(const EntityId& id) override; + bool SetEntityName(const EntityId& id, const AZStd::string& name) override; void EnumerateEntities(const ComponentApplicationRequests::EntityCallback& callback) override; ComponentApplication* GetApplication() override { return this; } /// Returns the serialize context that has been registered with the app, if there is one. diff --git a/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h b/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h index d0f161aa39..a3602c303e 100644 --- a/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h +++ b/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h @@ -130,7 +130,13 @@ namespace AZ //! @param entity A reference to the entity whose name you are seeking. //! @return The name of the entity with the specified entity ID. //! If no entity is found for the specified ID, it returns an empty string. - virtual AZStd::string GetEntityName(const EntityId& id) { (void)id; return AZStd::string(); }; + virtual AZStd::string GetEntityName(const EntityId& id) { (void)id; return AZStd::string(); } + + //! Sets the name of the entity that has the specified entity ID. + //! Entity names are not enforced to be unique. + //! @param entityId A reference to the entity whose name you want to change. + //! @return True if the name was changed successfully, false if it wasn't. + virtual bool SetEntityName([[maybe_unused]] const EntityId& id, [[maybe_unused]] const AZStd::string& name) { return false; } //! The type that AZ::ComponentApplicationRequests::EnumerateEntities uses to //! pass entity callbacks to the application for enumeration. From e8459898a7f887008fe2375673e3cddb39f1d40c Mon Sep 17 00:00:00 2001 From: mbalfour Date: Wed, 14 Apr 2021 16:04:44 -0500 Subject: [PATCH 21/33] Exposed Quaternion::CreateFromEulerAnglesDegrees and Transform::Transform(Vector3, Quaternion, Vector3) to the behavior context to improve usability of these classes from scripts. (cherry picked from commit 8156beb21181f9ff20972c8ea8be5e3dc61f1700) --- Code/Framework/AzCore/AzCore/Math/Quaternion.cpp | 3 ++- Code/Framework/AzCore/AzCore/Math/Transform.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Code/Framework/AzCore/AzCore/Math/Quaternion.cpp b/Code/Framework/AzCore/AzCore/Math/Quaternion.cpp index ca09f8b453..143fe59ca7 100644 --- a/Code/Framework/AzCore/AzCore/Math/Quaternion.cpp +++ b/Code/Framework/AzCore/AzCore/Math/Quaternion.cpp @@ -258,7 +258,8 @@ namespace AZ Method("CreateFromMatrix3x3", &Quaternion::CreateFromMatrix3x3)-> Method("CreateFromMatrix4x4", &Quaternion::CreateFromMatrix4x4)-> Method("CreateFromAxisAngle", &Quaternion::CreateFromAxisAngle)-> - Method("CreateShortestArc", &Quaternion::CreateShortestArc) + Method("CreateShortestArc", &Quaternion::CreateShortestArc)-> + Method("CreateFromEulerAnglesDegrees", &Quaternion::CreateFromEulerAnglesDegrees) ; } } diff --git a/Code/Framework/AzCore/AzCore/Math/Transform.cpp b/Code/Framework/AzCore/AzCore/Math/Transform.cpp index 77d8658d0f..bb3f764492 100644 --- a/Code/Framework/AzCore/AzCore/Math/Transform.cpp +++ b/Code/Framework/AzCore/AzCore/Math/Transform.cpp @@ -250,6 +250,7 @@ namespace AZ Attribute(Script::Attributes::ExcludeFrom, Script::Attributes::ExcludeFlags::All)-> Attribute(Script::Attributes::Storage, Script::Attributes::StorageType::Value)-> Attribute(Script::Attributes::GenericConstructorOverride, &Internal::TransformDefaultConstructor)-> + Constructor()-> Method("GetBasis", &Transform::GetBasis)-> Method("GetBasisX", &Transform::GetBasisX)-> Method("GetBasisY", &Transform::GetBasisY)-> From 5aa4642c12df54a6f7c53986bbe6dd5169f89d5f Mon Sep 17 00:00:00 2001 From: mbalfour Date: Wed, 14 Apr 2021 16:05:50 -0500 Subject: [PATCH 22/33] Added another implicit converter to MaterialPropertyValue so that generated images can be used with material properties more easily. (cherry picked from commit 66d7e9672ca0d6ced068dd95d8b52f88b5492c1f) --- .../Include/Atom/RPI.Reflect/Material/MaterialPropertyValue.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Material/MaterialPropertyValue.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Material/MaterialPropertyValue.h index cafd31d8a5..758afb1c66 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Material/MaterialPropertyValue.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Material/MaterialPropertyValue.h @@ -65,6 +65,7 @@ namespace AZ MaterialPropertyValue(const Vector4& value) : m_value(value) {} MaterialPropertyValue(const Color& value) : m_value(value) {} MaterialPropertyValue(const Data::Asset& value) : m_value(value) {} + MaterialPropertyValue(const Data::Instance& value) : m_value(value) {} MaterialPropertyValue(const AZStd::string& value) : m_value(value) {} //! Copy constructor From 3e8625b78b83a56ae3f9557060f3e9bf4387517b Mon Sep 17 00:00:00 2001 From: mbalfour Date: Wed, 14 Apr 2021 16:09:02 -0500 Subject: [PATCH 23/33] Added "IsReadyToSpawn" to help detect when a spawner is ready to start spawning. Also added a small optimization to SetDynamicSliceByAssetId so that it doesn't do anything when setting it to the same value as before. (cherry picked from commit ff8a93e71f3017e8555012855f3e2155ec74a405) --- .../Source/Scripting/SpawnerComponent.cpp | 25 +++++++++++-------- .../Code/Source/Scripting/SpawnerComponent.h | 3 ++- .../Scripting/SpawnerComponentBus.h | 3 +++ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Gems/LmbrCentral/Code/Source/Scripting/SpawnerComponent.cpp b/Gems/LmbrCentral/Code/Source/Scripting/SpawnerComponent.cpp index 2595fc09fd..7b76a1465c 100644 --- a/Gems/LmbrCentral/Code/Source/Scripting/SpawnerComponent.cpp +++ b/Gems/LmbrCentral/Code/Source/Scripting/SpawnerComponent.cpp @@ -148,6 +148,7 @@ namespace LmbrCentral ->Event("GetCurrentEntitiesFromSpawnedSlice", &SpawnerComponentRequestBus::Events::GetCurrentEntitiesFromSpawnedSlice) ->Event("GetAllCurrentlySpawnedEntities", &SpawnerComponentRequestBus::Events::GetAllCurrentlySpawnedEntities) ->Event("SetDynamicSlice", &SpawnerComponentRequestBus::Events::SetDynamicSliceByAssetId) + ->Event("IsReadyToSpawn", &SpawnerComponentRequestBus::Events::IsReadyToSpawn) ; behaviorContext->EBus("SpawnerComponentNotificationBus") @@ -250,17 +251,15 @@ namespace LmbrCentral //========================================================================= void SpawnerComponent::SetDynamicSliceByAssetId(AZ::Data::AssetId& assetId) { - auto sliceAsset = AZ::Data::AssetManager::Instance().GetAsset(assetId, AZ::AzTypeInfo::Uuid(), m_sliceAsset.GetAutoLoadBehavior()); + if (m_sliceAsset.GetId() == assetId) + { + return; + } - if (sliceAsset.IsReady()) - { - m_sliceAsset = sliceAsset; - } - else - { - AZ::Data::AssetBus::Handler::BusDisconnect(); - AZ::Data::AssetBus::Handler::BusConnect(assetId); - } + m_sliceAsset = AZ::Data::AssetManager::Instance().GetAsset( + assetId, AZ::AzTypeInfo::Uuid(), m_sliceAsset.GetAutoLoadBehavior()); + AZ::Data::AssetBus::Handler::BusDisconnect(); + AZ::Data::AssetBus::Handler::BusConnect(assetId); } //========================================================================= @@ -444,6 +443,12 @@ namespace LmbrCentral return entities; } + //========================================================================= + bool SpawnerComponent::IsReadyToSpawn() + { + return m_sliceAsset.IsReady(); + } + //========================================================================= void SpawnerComponent::OnSlicePreInstantiate(const AZ::Data::AssetId& /*sliceAssetId*/, [[maybe_unused]] const AZ::SliceComponent::SliceInstanceAddress& sliceAddress) { diff --git a/Gems/LmbrCentral/Code/Source/Scripting/SpawnerComponent.h b/Gems/LmbrCentral/Code/Source/Scripting/SpawnerComponent.h index 3dee332df3..75f5db8df2 100644 --- a/Gems/LmbrCentral/Code/Source/Scripting/SpawnerComponent.h +++ b/Gems/LmbrCentral/Code/Source/Scripting/SpawnerComponent.h @@ -70,7 +70,8 @@ namespace LmbrCentral AZStd::vector GetCurrentlySpawnedSlices() override; bool HasAnyCurrentlySpawnedSlices() override; AZStd::vector GetCurrentEntitiesFromSpawnedSlice(const AzFramework::SliceInstantiationTicket& ticket) override; - AZStd::vector GetAllCurrentlySpawnedEntities(); + AZStd::vector GetAllCurrentlySpawnedEntities() override; + bool IsReadyToSpawn() override; ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// diff --git a/Gems/LmbrCentral/Code/include/LmbrCentral/Scripting/SpawnerComponentBus.h b/Gems/LmbrCentral/Code/include/LmbrCentral/Scripting/SpawnerComponentBus.h index 6122a747f3..92ca003300 100644 --- a/Gems/LmbrCentral/Code/include/LmbrCentral/Scripting/SpawnerComponentBus.h +++ b/Gems/LmbrCentral/Code/include/LmbrCentral/Scripting/SpawnerComponentBus.h @@ -91,6 +91,9 @@ namespace LmbrCentral //! Note that spawning is not instant, if a slice hasn't finished spawning then none of its entities are returned. //! If an entity has been destroyed since it was spawned, its ID is not returned. virtual AZStd::vector GetAllCurrentlySpawnedEntities() = 0; + + //! Returns whether or not the spawner is in a state that's ready to spawn. + virtual bool IsReadyToSpawn() = 0; }; using SpawnerComponentRequestBus = AZ::EBus; From 83324762b58438c954a75851d3a277511e2c5628 Mon Sep 17 00:00:00 2001 From: luissemp Date: Tue, 20 Apr 2021 10:40:53 -0700 Subject: [PATCH 24/33] Brought over SC's command line fixes and add_node example script --- .../Code/Editor/View/Widgets/CommandLine.cpp | 215 ++++++++++++++---- .../Code/Editor/View/Widgets/CommandLine.h | 106 ++++++++- .../Code/Editor/View/Windows/MainWindow.cpp | 2 +- .../Code/Editor/View/Windows/mainwindow.ui | 2 +- .../AutoGen/ScriptCanvasGrammar_Header.jinja | 2 +- 5 files changed, 275 insertions(+), 52 deletions(-) diff --git a/Gems/ScriptCanvas/Code/Editor/View/Widgets/CommandLine.cpp b/Gems/ScriptCanvas/Code/Editor/View/Widgets/CommandLine.cpp index 6fa930ba34..19390de956 100644 --- a/Gems/ScriptCanvas/Code/Editor/View/Widgets/CommandLine.cpp +++ b/Gems/ScriptCanvas/Code/Editor/View/Widgets/CommandLine.cpp @@ -79,15 +79,19 @@ namespace // Create the nodes in a horizontal list at the top of the canvas. - AZ::Vector2 pos(20.0f, -100.0f); + AZ::Vector2 pos(20.0f, 20.0f); for (const auto& index : ui->commandList->selectionModel()->selectedIndexes()) { - if (index.column() != CommandListDataModel::ColumnIndex::Command) + if (index.column() != CommandListDataModel::ColumnIndex::CommandIndex) { continue; } AZ::Uuid type = dataModel->data(index, CommandListDataModel::CustomRole::Types).value(); + if (type.IsNull()) + { + continue; + } [[maybe_unused]] const AZ::SerializeContext::ClassData* classData = serializeContext->FindClassData(type); AZ_Assert(classData, "Failed to find ClassData for ID: %s", type.ToString().data()); @@ -115,6 +119,8 @@ namespace ScriptCanvasEditor ///////////////////////////////////////////////////////////////////////////////////////////// CommandListDataModel::CommandListDataModel([[maybe_unused]] QWidget* parent /*= nullptr*/) { + ScriptCanvasCommandLineRequestBus::Handler::BusConnect(); + AZ::SerializeContext* serializeContext = nullptr; AZ::ComponentApplicationBus::BroadcastResult(serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext); @@ -138,12 +144,62 @@ namespace ScriptCanvasEditor if (add) { - m_nodeTypes.push_back(classData->m_typeId); + Entry entry; + entry.m_type = classData->m_typeId; + m_entries.emplace_back(entry); } } return true; } - ); + ); + + ScriptCanvasCommandLineRequestBus::Broadcast(&ScriptCanvasCommandLineRequests::AddCommand, "add_node", "Adds the specified node to the graph", + [serializeContext](const AZStd::vector& nodes) + { + AZ::Uuid nodeTypeToAdd = AZ::Uuid::CreateNull(); + if (nodes.size() > 0) + { + const AZStd::string& nodeName = *(nodes.begin()); + + serializeContext->EnumerateDerived( + [&nodeName, &nodeTypeToAdd](const AZ::SerializeContext::ClassData* classData, [[maybe_unused]] const AZ::Uuid& classUuid) -> bool + { + if (classData && classData->m_editData) + { + if (nodeName.compare(classData->m_name) == 0) + { + nodeTypeToAdd = classData->m_typeId; + } + } + return true; + } + ); + + if (!nodeTypeToAdd.IsNull()) + { + ScriptCanvas::ScriptCanvasId scriptCanvasId; + ScriptCanvasEditor::GeneralRequestBus::BroadcastResult(scriptCanvasId, &ScriptCanvasEditor::GeneralRequests::GetActiveScriptCanvasId); + + AZ::EntityId graphCanvasGraphId; + ScriptCanvasEditor::GeneralRequestBus::BroadcastResult(graphCanvasGraphId, &ScriptCanvasEditor::GeneralRequests::GetActiveGraphCanvasGraphId); + + if (scriptCanvasId.IsValid() && graphCanvasGraphId.IsValid()) + { + ScriptCanvasEditor::Nodes::StyleConfiguration styleConfiguration; + + AZ::Vector2 pos(100.0f, 20.0f); + NodeIdPair nodePair = ScriptCanvasEditor::Nodes::CreateNode(nodeTypeToAdd, scriptCanvasId, styleConfiguration); + GraphCanvas::SceneRequestBus::Event(graphCanvasGraphId, &GraphCanvas::SceneRequests::AddNode, nodePair.m_graphCanvasId, pos, false); + } + } + } + } + ); + } + + CommandListDataModel::~CommandListDataModel() + { + ScriptCanvasCommandLineRequestBus::Handler::BusDisconnect(); } QModelIndex CommandListDataModel::index(int row, int column, const QModelIndex& parent /*= QModelIndex()*/) const @@ -162,7 +218,7 @@ namespace ScriptCanvasEditor int CommandListDataModel::rowCount([[maybe_unused]] const QModelIndex& parent /*= QModelIndex()*/) const { - return static_cast(m_nodeTypes.size()); + return static_cast(m_entries.size()); } int CommandListDataModel::columnCount([[maybe_unused]] const QModelIndex& parent /*= QModelIndex()*/) const @@ -190,19 +246,40 @@ namespace ScriptCanvasEditor } } - AZ::Uuid nodeType = m_nodeTypes[index.row()]; - const AZ::SerializeContext::ClassData* classData = serializeContext->FindClassData(nodeType); - if (index.column() == ColumnIndex::Command) + AZ::Uuid nodeType = m_entries[index.row()].m_type; + if (nodeType.IsNull()) { - return QVariant(QString(classData->m_name)); + if (index.column() == ColumnIndex::CommandIndex) + { + return QVariant(QString(m_entries[index.row()].m_command.c_str())); + } + if (index.column() == ColumnIndex::DescriptionIndex) + { + AZStd::string command = m_entries[index.row()].m_command; + const auto& entry = m_commands.find(command); + if (entry != m_commands.end()) + { + return QVariant(QString(entry->second->GetDescription().c_str())); + } + } } - if (index.column() == ColumnIndex::Description) + else { - return QVariant(QString(classData->m_editData ? classData->m_editData->m_description : tr("No description provided."))); - } - if (index.column() == ColumnIndex::Trail) - { - return QVariant(QString("")); + if (const AZ::SerializeContext::ClassData* classData = serializeContext->FindClassData(nodeType)) + { + if (index.column() == ColumnIndex::CommandIndex) + { + return QVariant(QString(classData->m_name)); + } + if (index.column() == ColumnIndex::DescriptionIndex) + { + return QVariant(QString(classData->m_editData ? classData->m_editData->m_description : tr("No description provided."))); + } + if (index.column() == ColumnIndex::TrailIndex) + { + return QVariant(QString("")); + } + } } } @@ -210,25 +287,42 @@ namespace ScriptCanvasEditor { case CustomRole::Types: { - AZ::Uuid nodeType = m_nodeTypes[index.row()]; + AZ::Uuid nodeType = m_entries[index.row()].m_type; return QVariant::fromValue(nodeType); } break; case CustomRole::Node: { - AZ::Uuid nodeType = m_nodeTypes[index.row()]; - const AZ::SerializeContext::ClassData* classData = serializeContext->FindClassData(nodeType); - if (index.column() == ColumnIndex::Command) + AZ::Uuid nodeType = m_entries[index.row()].m_type; + if (nodeType.IsNull()) { - return QVariant(QString(classData->m_name)); + return QVariant(QString(m_entries[index.row()].m_command.c_str())); } - if (index.column() == ColumnIndex::Description) + else { - return QVariant(QString(classData->m_editData ? classData->m_editData->m_description : tr("No description provided."))); + if (const AZ::SerializeContext::ClassData* classData = serializeContext->FindClassData(nodeType)) + { + if (index.column() == ColumnIndex::CommandIndex) + { + return QVariant(QString(classData->m_name)); + } + if (index.column() == ColumnIndex::DescriptionIndex) + { + return QVariant(QString(classData->m_editData ? classData->m_editData->m_description : tr("No description provided."))); + } + if (index.column() == ColumnIndex::TrailIndex) + { + return QVariant(QString("")); + } + } } - if (index.column() == ColumnIndex::Trail) + } + break; + case CustomRole::Commands: + { + if (index.column() == ColumnIndex::CommandIndex) { - return QVariant(QString("")); + return QVariant(QString(m_entries[index.row()].m_command.c_str())); } } break; @@ -250,21 +344,31 @@ namespace ScriptCanvasEditor AZ::SerializeContext* serializeContext = nullptr; AZ::ComponentApplicationBus::BroadcastResult(serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext); - for (const auto& entry : m_nodeTypes) + for (const auto& entry : m_entries) { - const AZ::SerializeContext::ClassData* classData = serializeContext->FindClassData(entry); - if (classData) + if (!entry.m_type.IsNull()) { - QString name = QString(classData->m_name); - if (name.startsWith(input.c_str(), Qt::CaseSensitivity::CaseInsensitive)) + if (const AZ::SerializeContext::ClassData* classData = serializeContext->FindClassData(entry.m_type)) { - return true; + QString name = QString(classData->m_name); + if (name.startsWith(input.c_str(), Qt::CaseSensitivity::CaseInsensitive)) + { + return true; + } } } + else + { + QString commandName = entry.m_command.c_str(); + return (commandName.startsWith(input.c_str(), Qt::CaseSensitivity::CaseInsensitive)); + } } + return false; } + ScriptCanvasEditor::Widget::CommandRegistry CommandListDataModel::m_commands; + // CommandLineEdit ///////////////////////////////////////////////////////////////////////////////////////////// @@ -335,8 +439,25 @@ namespace ScriptCanvasEditor case Qt::Key_Return: { // Invoke the command - // TODO: trigger invoke - // CommandRequestBus::Broadcast(&CommandRequest::Invoke, text().toStdString().c_str()); + AZStd::string commandText = text().toStdString().c_str(); + AZStd::vector tokens; + AZ::StringFunc::Tokenize(commandText, tokens, " "); + if (tokens.size() == 1) + { + ScriptCanvasCommandLineRequestBus::Broadcast(&ScriptCanvasCommandLineRequests::Invoke, tokens.begin()->c_str()); + } + else if (tokens.size() > 1) + { + AZStd::string command = *(tokens.begin()); + AZStd::vector args; + for (auto it = tokens.begin() + 1; it != tokens.end(); ++it) + { + args.push_back(*it); + } + ScriptCanvasCommandLineRequestBus::Broadcast(&ScriptCanvasCommandLineRequests::InvokeWithArguments, command.c_str(), args); + } + + ResetState(); qobject_cast(parent())->hide(); } @@ -376,20 +497,29 @@ namespace ScriptCanvasEditor // CommandListDataProxyModel ///////////////////////////////////////////////////////////////////////////////////////////// - CommandListDataProxyModel::CommandListDataProxyModel(QObject* parent /*= nullptr*/) + CommandListDataProxyModel::CommandListDataProxyModel(CommandListDataModel* commandListData, QObject* parent /*= nullptr*/) : QSortFilterProxyModel(parent) { - QStringList commands; + setSourceModel(commandListData); + + QStringList commandList; - CommandListDataModel* commandListData = new CommandListDataModel(); for (int i = 0; i < commandListData->rowCount(); ++i) { - QModelIndex index = commandListData->index(i, CommandListDataModel::ColumnIndex::Command); + QModelIndex index = commandListData->index(i, CommandListDataModel::ColumnIndex::CommandIndex); QString command = commandListData->data(index, CommandListDataModel::CustomRole::Node).toString(); - commands.push_back(command); + commandList.push_back(command); } - m_completer = new QCompleter(commands); + ScriptCanvasCommandLineRequests::CommandNameList commands; + ScriptCanvasCommandLineRequestBus::BroadcastResult(commands, &ScriptCanvasCommandLineRequests::GetCommands); + for (auto& command : commands) + { + QString commandName = command.first.c_str(); + commandList.push_back(commandName); + } + + m_completer = new QCompleter(commandList); m_completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion); m_completer->setCaseSensitivity(Qt::CaseInsensitive); } @@ -421,7 +551,7 @@ namespace ScriptCanvasEditor } } - QModelIndex index = dataModel->index(sourceRow, CommandListDataModel::ColumnIndex::Command); + QModelIndex index = dataModel->index(sourceRow, CommandListDataModel::ColumnIndex::CommandIndex); QString sourceStr = dataModel->data(index).toString(); if (sourceRow > 0 && sourceStr.startsWith(m_input.c_str(), Qt::CaseSensitivity::CaseInsensitive)) @@ -450,8 +580,7 @@ namespace ScriptCanvasEditor ui->setupUi(this); CommandListDataModel* commandListDataModel = new CommandListDataModel(); - CommandListDataProxyModel* commandListDataProxyModel = new CommandListDataProxyModel(); - commandListDataProxyModel->setSourceModel(commandListDataModel); + CommandListDataProxyModel* commandListDataProxyModel = new CommandListDataProxyModel(commandListDataModel); ui->commandList->setModel(commandListDataProxyModel); @@ -460,8 +589,8 @@ namespace ScriptCanvasEditor connect(ui->commandText, &CommandLineEdit::onKeyReleased, this, &CommandLine::onEditKeyReleaseEvent); connect(ui->commandList, &CommandLineList::onKeyReleased, this, &CommandLine::onListKeyReleaseEvent); - ui->commandList->setColumnWidth(CommandListDataModel::ColumnIndex::Command, 250); - ui->commandList->setColumnWidth(CommandListDataModel::ColumnIndex::Description, 1000); + ui->commandList->setColumnWidth(CommandListDataModel::ColumnIndex::CommandIndex, 250); + ui->commandList->setColumnWidth(CommandListDataModel::ColumnIndex::DescriptionIndex, 1000); } void CommandLine::onTextChanged(const QString& text) diff --git a/Gems/ScriptCanvas/Code/Editor/View/Widgets/CommandLine.h b/Gems/ScriptCanvas/Code/Editor/View/Widgets/CommandLine.h index ab9b115bde..28e3ce4671 100644 --- a/Gems/ScriptCanvas/Code/Editor/View/Widgets/CommandLine.h +++ b/Gems/ScriptCanvas/Code/Editor/View/Widgets/CommandLine.h @@ -25,6 +25,7 @@ #include #include #include +#include #endif namespace Ui @@ -36,10 +37,49 @@ namespace ScriptCanvasEditor { namespace Widget { + class Command + { + public: + using Functor = AZStd::function)>; + + Command(const AZStd::string& name, const AZStd::string& description, Functor functor) + : m_name(name) + , m_description(description) + , m_functor(functor) + {} + + void operator()(const AZStd::vector& args) + { + m_functor(args); + } + + const AZStd::string& GetName() const { return m_name; } + const AZStd::string& GetDescription() const { return m_description; } + + private: + AZStd::string m_name; + AZStd::string m_description; + Functor m_functor; + }; + + using CommandRegistry = AZStd::unordered_map>; + + struct ScriptCanvasCommandLineRequests : public AZ::EBusTraits + { + virtual void AddCommand(const AZStd::string commandName, const AZStd::string description, Command::Functor) = 0; + virtual void Invoke(const char* commandName) = 0; + virtual void InvokeWithArguments(const char* commandName, const AZStd::vector&) = 0; + + using CommandNameList = AZStd::list>; + virtual CommandNameList GetCommands() = 0; + }; + using ScriptCanvasCommandLineRequestBus = AZ::EBus; + // TODO #lsempe: this deserves its own file // CommandListDataModel ///////////////////////////////////////////////////////////////////////////////////////////// class CommandListDataModel : public QAbstractTableModel + , ScriptCanvasCommandLineRequestBus::Handler { Q_OBJECT @@ -49,9 +89,9 @@ namespace ScriptCanvasEditor enum ColumnIndex { - Command, - Description, - Trail, + CommandIndex, + DescriptionIndex, + TrailIndex, Count }; @@ -65,6 +105,8 @@ namespace ScriptCanvasEditor }; CommandListDataModel(QWidget* parent = nullptr); + ~CommandListDataModel() override; + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; QModelIndex parent(const QModelIndex &child) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; @@ -75,10 +117,62 @@ namespace ScriptCanvasEditor bool HasMatches(const AZStd::string& input); + struct Entry + { + AZ::Uuid m_type; + AZStd::string m_command; + + Entry() + { + m_type = AZ::Uuid::CreateNull(); + } + }; + protected: - AZStd::vector m_nodeTypes; + AZStd::vector m_entries; + static CommandRegistry m_commands; + + void AddCommand(const AZStd::string commandName, const AZStd::string description, Command::Functor f) override + { + if (m_commands.find(commandName) == m_commands.end()) + { + m_commands[commandName] = AZStd::make_unique(commandName, description, f); + Entry entry; + entry.m_command = commandName; + entry.m_type = AZ::Uuid::CreateNull(); + m_entries.emplace_back(entry); + } + } + + void Invoke(const char* commandName) override + { + auto command = m_commands.find(commandName); + if (command != m_commands.end()) + { + command->second->operator()({}); + } + } + + void InvokeWithArguments(const char* commandName, const AZStd::vector& args) override + { + auto command = m_commands.find(commandName); + if (command != m_commands.end()) + { + command->second->operator()(args); + } + } + + ScriptCanvasCommandLineRequests::CommandNameList GetCommands() override + { + ScriptCanvasCommandLineRequests::CommandNameList commands; + for (auto& command : m_commands) + { + commands.push_back(AZStd::make_pair(command.second->GetName(), command.second->GetDescription())); + } + return commands; + } }; class CommandListDataProxyModel : public QSortFilterProxyModel @@ -88,7 +182,7 @@ namespace ScriptCanvasEditor public: AZ_CLASS_ALLOCATOR(CommandListDataProxyModel, AZ::SystemAllocator, 0); - CommandListDataProxyModel(QObject* parent = nullptr); + CommandListDataProxyModel(CommandListDataModel* commandListData, QObject* parent = nullptr); bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; @@ -168,4 +262,4 @@ namespace ScriptCanvasEditor AZStd::unique_ptr ui; }; } -} \ No newline at end of file +} diff --git a/Gems/ScriptCanvas/Code/Editor/View/Windows/MainWindow.cpp b/Gems/ScriptCanvas/Code/Editor/View/Windows/MainWindow.cpp index 3f226e62e0..85abf68332 100644 --- a/Gems/ScriptCanvas/Code/Editor/View/Windows/MainWindow.cpp +++ b/Gems/ScriptCanvas/Code/Editor/View/Windows/MainWindow.cpp @@ -595,7 +595,7 @@ namespace ScriptCanvasEditor m_commandLine = new Widget::CommandLine(this); m_commandLine->setBaseSize(QSize(size().width(), m_commandLine->size().height())); m_commandLine->setObjectName("CommandLine"); - m_commandLine->hide(); +// m_commandLine->hide(); m_layout->addWidget(m_commandLine); m_layout->addWidget(m_emptyCanvas); diff --git a/Gems/ScriptCanvas/Code/Editor/View/Windows/mainwindow.ui b/Gems/ScriptCanvas/Code/Editor/View/Windows/mainwindow.ui index 40ba00bb31..3b3043a4a0 100644 --- a/Gems/ScriptCanvas/Code/Editor/View/Windows/mainwindow.ui +++ b/Gems/ScriptCanvas/Code/Editor/View/Windows/mainwindow.ui @@ -244,7 +244,7 @@ false - false + true diff --git a/Gems/ScriptCanvas/Code/Include/ScriptCanvas/AutoGen/ScriptCanvasGrammar_Header.jinja b/Gems/ScriptCanvas/Code/Include/ScriptCanvas/AutoGen/ScriptCanvasGrammar_Header.jinja index b7394ef212..185cf82c86 100644 --- a/Gems/ScriptCanvas/Code/Include/ScriptCanvas/AutoGen/ScriptCanvasGrammar_Header.jinja +++ b/Gems/ScriptCanvas/Code/Include/ScriptCanvas/AutoGen/ScriptCanvasGrammar_Header.jinja @@ -66,7 +66,7 @@ namespace {{attribute_Namespace}} {% set deprecationUuid = Class.attrib['DeprecationUUID'] %} -// The following will be injected directly into the source header file for which AzCodeGenerator is being run. +// The following will be injected directly into the source header file for which AZ AutoGen is being run. // You must #include the generated header into the source header #define SCRIPTCANVAS_NODE_{{ className }} \ public: \ From dc5b4ee1dd665c08a47e36cc622678bd9529fd90 Mon Sep 17 00:00:00 2001 From: shiranj Date: Tue, 20 Apr 2021 10:50:41 -0700 Subject: [PATCH 25/33] Add Android package in packaging pipeline --- .../build/Platform/Android/build_config.json | 10 ++++++++ .../package/Platform/Android/package_env.json | 25 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 scripts/build/package/Platform/Android/package_env.json diff --git a/scripts/build/Platform/Android/build_config.json b/scripts/build/Platform/Android/build_config.json index 0fa4d9ade3..097ff59e4e 100644 --- a/scripts/build/Platform/Android/build_config.json +++ b/scripts/build/Platform/Android/build_config.json @@ -40,6 +40,16 @@ "CMAKE_BUILD_ARGS":"-j!NUMBER_OF_PROCESSORS!" } }, + "android_packaging_all": { + "TAGS": [ + "packaging" + ], + "COMMAND": "python_windows.cmd", + "PARAMETERS": { + "SCRIPT_PATH": "scripts/build/package/package.py", + "SCRIPT_PARAMETERS": "--platform Android --type all" + } + }, "profile": { "TAGS":[ "weekly-build-metrics", diff --git a/scripts/build/package/Platform/Android/package_env.json b/scripts/build/package/Platform/Android/package_env.json new file mode 100644 index 0000000000..017937413a --- /dev/null +++ b/scripts/build/package/Platform/Android/package_env.json @@ -0,0 +1,25 @@ +{ + "local_env": { + "S3_PREFIX": "${BRANCH_NAME}/Android" + }, + "types":{ + "all":{ + "PACKAGE_TARGETS":[ + { + "FILE_LIST": "all.json", + "FILE_LIST_TYPE": "All", + "PACKAGE_NAME": "${PACKAGE_NAME_PATTERN}-android-all-${BUILD_NUMBER}.zip" + } + ], + "BOOTSTRAP_CFG_GAME_FOLDER":"AutomatedTesting", + "SKIP_BUILD": 0, + "BUILD_TARGETS":[ + { + "BUILD_CONFIG_FILENAME": "build_config.json", + "PLATFORM": "Android", + "TYPE": "profile" + } + ] + } + } +} From d9fe89ba56a1c7d344538951909f086386ba5947 Mon Sep 17 00:00:00 2001 From: mbalfour Date: Tue, 20 Apr 2021 13:37:10 -0500 Subject: [PATCH 26/33] Addressed feedback - made string& into a string_view. --- Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp | 2 +- Code/Framework/AzCore/AzCore/Component/ComponentApplication.h | 2 +- .../Framework/AzCore/AzCore/Component/ComponentApplicationBus.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp index a3986f72dd..c55f565615 100644 --- a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp +++ b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp @@ -1063,7 +1063,7 @@ namespace AZ //========================================================================= // SetEntityName //========================================================================= - bool ComponentApplication::SetEntityName(const EntityId& id, const AZStd::string& name) + bool ComponentApplication::SetEntityName(const EntityId& id, const AZStd::string_view name) { Entity* entity = FindEntity(id); if (entity) diff --git a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h index a66409eaf3..3ebcf39d95 100644 --- a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h +++ b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h @@ -209,7 +209,7 @@ namespace AZ bool DeleteEntity(const EntityId& id) override; Entity* FindEntity(const EntityId& id) override; AZStd::string GetEntityName(const EntityId& id) override; - bool SetEntityName(const EntityId& id, const AZStd::string& name) override; + bool SetEntityName(const EntityId& id, const AZStd::string_view name) override; void EnumerateEntities(const ComponentApplicationRequests::EntityCallback& callback) override; ComponentApplication* GetApplication() override { return this; } /// Returns the serialize context that has been registered with the app, if there is one. diff --git a/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h b/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h index a3602c303e..3582e6ebb8 100644 --- a/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h +++ b/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h @@ -136,7 +136,7 @@ namespace AZ //! Entity names are not enforced to be unique. //! @param entityId A reference to the entity whose name you want to change. //! @return True if the name was changed successfully, false if it wasn't. - virtual bool SetEntityName([[maybe_unused]] const EntityId& id, [[maybe_unused]] const AZStd::string& name) { return false; } + virtual bool SetEntityName([[maybe_unused]] const EntityId& id, [[maybe_unused]] const AZStd::string_view name) { return false; } //! The type that AZ::ComponentApplicationRequests::EnumerateEntities uses to //! pass entity callbacks to the application for enumeration. From 33b485767f584bef006049ed3beb792325190830 Mon Sep 17 00:00:00 2001 From: nvsickle Date: Tue, 20 Apr 2021 11:49:59 -0700 Subject: [PATCH 27/33] Address reviewer feedback, make FFont initialization state an atomic state machine --- .../AtomLyIntegration/AtomFont/FFont.h | 9 +++++-- .../AtomFont/Code/Source/FFont.cpp | 24 ++++++++----------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h index 91fc0834ec..8e60cc2055 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h +++ b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h @@ -301,8 +301,13 @@ namespace AZ AtomFont* m_atomFont = nullptr; bool m_fontTexDirty = false; - bool m_fontInitialized = false; - AZStd::atomic_bool m_fontInitializing = false; + enum class InitializationState : AZ::u8 + { + Uninitialized, + Initializing, + Initialized + }; + AZStd::atomic m_fontInitializationState = InitializationState::Uninitialized; FontEffects m_effects; diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp b/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp index edbf148940..20879876e7 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp +++ b/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp @@ -101,19 +101,16 @@ AZ::RPI::WindowContextSharedPtr AZ::FFont::GetDefaultWindowContext() const bool AZ::FFont::InitFont() { - if (m_fontInitialized) + auto initializationState = InitializationState::Uninitialized; + // Do an atomic transition to Initializing if we're in the Uninitialized state. + // Otherwise, check the current state. + // If we're Initialized, there's no more work to be done, return true to indicate we're good to go. + // If we're Initializing (on another thread), return false to let the consumer know it's not safe for us to be used yet. + if (!m_fontInitializationState.compare_exchange_strong(initializationState, InitializationState::Initializing)) { - return true; + return initializationState == InitializationState::Initialized; } - // If we're being initialized in another thread, abort. - if (m_fontInitializing) - { - return false; - } - - m_fontInitializing = true; - // Create and initialize DynamicDrawContext for font draw AZ::RPI::Ptr dynamicDraw = m_atomFont->GetOrCreateDynamicDrawForScene(GetDefaultViewportContext()->GetRenderScene().get()); @@ -136,8 +133,7 @@ bool AZ::FFont::InitFont() m_vertexCount = 0; m_indexCount = 0; - m_fontInitialized = true; - m_fontInitializing = false; + m_fontInitializationState = InitializationState::Initialized; return true; } @@ -1522,7 +1518,7 @@ bool AZ::FFont::UpdateTexture() { using namespace AZ; - if (!m_fontInitialized || !m_fontImage) + if (m_fontInitializationState != InitializationState::Initialized || !m_fontImage) { return false; } @@ -1590,7 +1586,7 @@ void AZ::FFont::Prepare(const char* str, bool updateTexture, const AtomFont::Gly const bool rerenderGlyphs = m_sizeBehavior == SizeBehavior::Rerender; const AtomFont::GlyphSize usedGlyphSize = rerenderGlyphs ? glyphSize : AtomFont::defaultGlyphSize; bool texUpdateNeeded = m_fontTexture->PreCacheString(str, nullptr, m_sizeRatio, usedGlyphSize, m_fontHintParams) == 1 || m_fontTexDirty; - if (m_fontInitialized && updateTexture && texUpdateNeeded && m_fontImage) + if (m_fontInitializationState == InitializationState::Initialized && updateTexture && texUpdateNeeded && m_fontImage) { UpdateTexture(); m_fontTexDirty = false; From f53c1e808411085f37ed373a674d98984fb87e68 Mon Sep 17 00:00:00 2001 From: amzn-sj Date: Tue, 20 Apr 2021 12:16:40 -0700 Subject: [PATCH 28/33] 3rd Party static libraries need to be public dependencies to work from installed engine. --- Code/Framework/AzCore/CMakeLists.txt | 7 +++---- Code/Framework/AzFramework/CMakeLists.txt | 4 ++-- Code/Framework/GridMate/CMakeLists.txt | 3 ++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Code/Framework/AzCore/CMakeLists.txt b/Code/Framework/AzCore/CMakeLists.txt index c77205a760..db2c79f0c9 100644 --- a/Code/Framework/AzCore/CMakeLists.txt +++ b/Code/Framework/AzCore/CMakeLists.txt @@ -40,14 +40,13 @@ ly_add_target( ${common_dir} ${AZ_CORE_RADTELEMETRY_INCLUDE_DIRECTORIES} BUILD_DEPENDENCIES - PRIVATE - 3rdParty::zlib - 3rdParty::zstd - 3rdParty::cityhash PUBLIC 3rdParty::Lua 3rdParty::RapidJSON 3rdParty::RapidXML + 3rdParty::zlib + 3rdParty::zstd + 3rdParty::cityhash ${AZ_CORE_RADTELEMETRY_BUILD_DEPENDENCIES} ) ly_add_source_properties( diff --git a/Code/Framework/AzFramework/CMakeLists.txt b/Code/Framework/AzFramework/CMakeLists.txt index f62f205efd..50e1fcb5a4 100644 --- a/Code/Framework/AzFramework/CMakeLists.txt +++ b/Code/Framework/AzFramework/CMakeLists.txt @@ -33,12 +33,12 @@ ly_add_target( BUILD_DEPENDENCIES PRIVATE AZ::AzCore + PUBLIC + AZ::GridMate 3rdParty::md5 3rdParty::zlib 3rdParty::zstd 3rdParty::lz4 - PUBLIC - AZ::GridMate ) if(LY_ENABLE_STATISTICAL_PROFILING) diff --git a/Code/Framework/GridMate/CMakeLists.txt b/Code/Framework/GridMate/CMakeLists.txt index f326bda179..20ce582307 100644 --- a/Code/Framework/GridMate/CMakeLists.txt +++ b/Code/Framework/GridMate/CMakeLists.txt @@ -28,8 +28,9 @@ ly_add_target( ${pal_dir} BUILD_DEPENDENCIES PRIVATE - 3rdParty::OpenSSL AZ::AzCore + PUBLIC + 3rdParty::OpenSSL ) ly_add_source_properties( From 990a40199b5567429f1d88d62edf2c6b34876987 Mon Sep 17 00:00:00 2001 From: Terry Michaels <81711813+tjmichaels@users.noreply.github.com> Date: Tue, 20 Apr 2021 15:05:45 -0500 Subject: [PATCH 29/33] Removed the last remaining connections to the Clang 3rd Party (#159) --- .../3rdParty/Platform/Linux/Clang_linux.cmake | 43 ---------------- .../Platform/Linux/cmake_linux_files.cmake | 1 - cmake/3rdParty/Platform/Mac/Clang_mac.cmake | 49 ------------------- .../Platform/Mac/cmake_mac_files.cmake | 1 - .../Platform/Windows/Clang_windows.cmake | 44 ----------------- .../Windows/cmake_windows_files.cmake | 1 - 6 files changed, 139 deletions(-) delete mode 100644 cmake/3rdParty/Platform/Linux/Clang_linux.cmake delete mode 100644 cmake/3rdParty/Platform/Mac/Clang_mac.cmake delete mode 100644 cmake/3rdParty/Platform/Windows/Clang_windows.cmake diff --git a/cmake/3rdParty/Platform/Linux/Clang_linux.cmake b/cmake/3rdParty/Platform/Linux/Clang_linux.cmake deleted file mode 100644 index 1cf269d1a2..0000000000 --- a/cmake/3rdParty/Platform/Linux/Clang_linux.cmake +++ /dev/null @@ -1,43 +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. -# - -set(CLANG_PLATFORM_LIB_PATH ${BASE_PATH}/linux_x64/release/lib) - -set(CLANG_INCLUDE_DIRECTORIES - llvm/include - linux_x64/release/include -) - -set(CLANG_LIBS - ${CLANG_PLATFORM_LIB_PATH}/libclangFrontend.a - ${CLANG_PLATFORM_LIB_PATH}/libclangSerialization.a - ${CLANG_PLATFORM_LIB_PATH}/libclangDriver.a - ${CLANG_PLATFORM_LIB_PATH}/libclangTooling.a - ${CLANG_PLATFORM_LIB_PATH}/libclangParse.a - ${CLANG_PLATFORM_LIB_PATH}/libclangSema.a - ${CLANG_PLATFORM_LIB_PATH}/libclangAnalysis.a - ${CLANG_PLATFORM_LIB_PATH}/libclangRewriteFrontend.a - ${CLANG_PLATFORM_LIB_PATH}/libclangRewrite.a - ${CLANG_PLATFORM_LIB_PATH}/libclangEdit.a - ${CLANG_PLATFORM_LIB_PATH}/libclangAST.a - ${CLANG_PLATFORM_LIB_PATH}/libclangLex.a - ${CLANG_PLATFORM_LIB_PATH}/libclangBasic.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMCore.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMBinaryFormat.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMDebugInfoDWARF.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMMC.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMOption.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMBitReader.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMMCParser.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMProfileData.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMTarget.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMSupport.a -) diff --git a/cmake/3rdParty/Platform/Linux/cmake_linux_files.cmake b/cmake/3rdParty/Platform/Linux/cmake_linux_files.cmake index 2b1ba4d0e5..83d862ee78 100644 --- a/cmake/3rdParty/Platform/Linux/cmake_linux_files.cmake +++ b/cmake/3rdParty/Platform/Linux/cmake_linux_files.cmake @@ -13,7 +13,6 @@ set(FILES AWSGameLiftServerSDK_linux.cmake BuiltInPackages_linux.cmake civetweb_linux.cmake - Clang_linux.cmake dyad_linux.cmake FbxSdk_linux.cmake OpenSSL_linux.cmake diff --git a/cmake/3rdParty/Platform/Mac/Clang_mac.cmake b/cmake/3rdParty/Platform/Mac/Clang_mac.cmake deleted file mode 100644 index 3d7fc64465..0000000000 --- a/cmake/3rdParty/Platform/Mac/Clang_mac.cmake +++ /dev/null @@ -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. -# - -set(CLANG_PLATFORM_LIB_PATH ${BASE_PATH}/xcode/$,debug,release>/lib) - -set(CLANG_INCLUDE_DIRECTORIES - llvm/include - xcode/$,debug,release>/include -) - -set(CLANG_LIBS - ${CLANG_PLATFORM_LIB_PATH}/libclangFrontend.a - ${CLANG_PLATFORM_LIB_PATH}/libclangSerialization.a - ${CLANG_PLATFORM_LIB_PATH}/libclangDriver.a - ${CLANG_PLATFORM_LIB_PATH}/libclangTooling.a - ${CLANG_PLATFORM_LIB_PATH}/libclangParse.a - ${CLANG_PLATFORM_LIB_PATH}/libclangSema.a - ${CLANG_PLATFORM_LIB_PATH}/libclangAnalysis.a - ${CLANG_PLATFORM_LIB_PATH}/libclangRewriteFrontend.a - ${CLANG_PLATFORM_LIB_PATH}/libclangRewrite.a - ${CLANG_PLATFORM_LIB_PATH}/libclangEdit.a - ${CLANG_PLATFORM_LIB_PATH}/libclangAST.a - ${CLANG_PLATFORM_LIB_PATH}/libclangASTMatchers.a - ${CLANG_PLATFORM_LIB_PATH}/libclangLex.a - ${CLANG_PLATFORM_LIB_PATH}/libclangBasic.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMCore.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMBinaryFormat.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMDebugInfoDWARF.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMMC.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMOption.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMBitReader.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMMCParser.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMProfileData.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMTarget.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMSupport.a - - ${CLANG_PLATFORM_LIB_PATH}/libLLVMDemangle.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMSupport.a - ${CLANG_PLATFORM_LIB_PATH}/libLLVMCore.a - -) diff --git a/cmake/3rdParty/Platform/Mac/cmake_mac_files.cmake b/cmake/3rdParty/Platform/Mac/cmake_mac_files.cmake index 0e3cc53262..9d0166913a 100644 --- a/cmake/3rdParty/Platform/Mac/cmake_mac_files.cmake +++ b/cmake/3rdParty/Platform/Mac/cmake_mac_files.cmake @@ -12,7 +12,6 @@ set(FILES BuiltInPackages_mac.cmake civetweb_mac.cmake - Clang_mac.cmake DirectXShaderCompiler_mac.cmake FbxSdk_mac.cmake OpenGLInterface_mac.cmake diff --git a/cmake/3rdParty/Platform/Windows/Clang_windows.cmake b/cmake/3rdParty/Platform/Windows/Clang_windows.cmake deleted file mode 100644 index 69a6b77119..0000000000 --- a/cmake/3rdParty/Platform/Windows/Clang_windows.cmake +++ /dev/null @@ -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. -# - -set(CLANG_PLATFORM_LIB_PATH ${BASE_PATH}/vs2015/$,debug,release>/lib) - -set(CLANG_INCLUDE_DIRECTORIES - llvm/include - vs2015/$,debug,release>/include -) - -set(CLANG_LIBS - ${CLANG_PLATFORM_LIB_PATH}/clangFrontend.lib - ${CLANG_PLATFORM_LIB_PATH}/clangSerialization.lib - ${CLANG_PLATFORM_LIB_PATH}/clangDriver.lib - ${CLANG_PLATFORM_LIB_PATH}/clangTooling.lib - ${CLANG_PLATFORM_LIB_PATH}/clangParse.lib - ${CLANG_PLATFORM_LIB_PATH}/clangSema.lib - ${CLANG_PLATFORM_LIB_PATH}/clangAnalysis.lib - ${CLANG_PLATFORM_LIB_PATH}/clangRewriteFrontend.lib - ${CLANG_PLATFORM_LIB_PATH}/clangRewrite.lib - ${CLANG_PLATFORM_LIB_PATH}/clangEdit.lib - ${CLANG_PLATFORM_LIB_PATH}/clangAST.lib - ${CLANG_PLATFORM_LIB_PATH}/clangLex.lib - ${CLANG_PLATFORM_LIB_PATH}/clangBasic.lib - ${CLANG_PLATFORM_LIB_PATH}/LLVMBinaryFormat.lib - ${CLANG_PLATFORM_LIB_PATH}/LLVMDebugInfoDWARF.lib - ${CLANG_PLATFORM_LIB_PATH}/LLVMMC.lib - ${CLANG_PLATFORM_LIB_PATH}/LLVMOption.lib - ${CLANG_PLATFORM_LIB_PATH}/LLVMBitReader.lib - ${CLANG_PLATFORM_LIB_PATH}/LLVMMCParser.lib - ${CLANG_PLATFORM_LIB_PATH}/LLVMProfileData.lib - ${CLANG_PLATFORM_LIB_PATH}/LLVMTarget.lib - ${CLANG_PLATFORM_LIB_PATH}/LLVMCore.lib - ${CLANG_PLATFORM_LIB_PATH}/LLVMSupport.lib - Version.lib -) diff --git a/cmake/3rdParty/Platform/Windows/cmake_windows_files.cmake b/cmake/3rdParty/Platform/Windows/cmake_windows_files.cmake index 2c7890fcc4..fe4aa6bc82 100644 --- a/cmake/3rdParty/Platform/Windows/cmake_windows_files.cmake +++ b/cmake/3rdParty/Platform/Windows/cmake_windows_files.cmake @@ -12,7 +12,6 @@ set(FILES AWSGameLiftServerSDK_windows.cmake BuiltInPackages_windows.cmake - Clang_windows.cmake Crashpad_windows.cmake DirectXShaderCompiler_windows.cmake dyad_windows.cmake From 2f9102f10a678bf6fa798b79a869610fd94f5b12 Mon Sep 17 00:00:00 2001 From: sharmajs-amzn <82233357+sharmajs-amzn@users.noreply.github.com> Date: Tue, 20 Apr 2021 13:10:25 -0700 Subject: [PATCH 30/33] AssImp asserts on Linux processing (#118) (#138) LYN-2645} Helios - AssImp asserts on Linux processing * Linux builds have asserts off, to match Windows and Mac. * Secondary UV channels support names are available now Jira: https://jira.agscollab.com/browse/LYN-2645 --- cmake/3rdParty/Platform/Linux/BuiltInPackages_linux.cmake | 2 +- cmake/3rdParty/Platform/Mac/BuiltInPackages_mac.cmake | 2 +- cmake/3rdParty/Platform/Windows/BuiltInPackages_windows.cmake | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/3rdParty/Platform/Linux/BuiltInPackages_linux.cmake b/cmake/3rdParty/Platform/Linux/BuiltInPackages_linux.cmake index 9057b5ba1b..e42e8e40ea 100644 --- a/cmake/3rdParty/Platform/Linux/BuiltInPackages_linux.cmake +++ b/cmake/3rdParty/Platform/Linux/BuiltInPackages_linux.cmake @@ -15,7 +15,7 @@ ly_associate_package(PACKAGE_NAME Lua-5.3.5-rev3-multiplatform TARG ly_associate_package(PACKAGE_NAME ilmbase-2.3.0-rev4-multiplatform TARGETS ilmbase PACKAGE_HASH 97547fdf1fbc4d81b8ccf382261f8c25514ed3b3c4f8fd493f0a4fa873bba348) ly_associate_package(PACKAGE_NAME hdf5-1.0.11-rev2-multiplatform TARGETS hdf5 PACKAGE_HASH 11d5e04df8a93f8c52a5684a4cacbf0d9003056360983ce34f8d7b601082c6bd) ly_associate_package(PACKAGE_NAME alembic-1.7.11-rev3-multiplatform TARGETS alembic PACKAGE_HASH ba7a7d4943dd752f5a662374f6c48b93493df1d8e2c5f6a8d101f3b50700dd25) -ly_associate_package(PACKAGE_NAME assimp-5.0.1-rev6-multiplatform TARGETS assimplib PACKAGE_HASH 47f1a6d05d101def036c030484c4a6e19d745aacd57037174715c7afe2b19b4c) +ly_associate_package(PACKAGE_NAME assimp-5.0.1-rev7-multiplatform TARGETS assimplib PACKAGE_HASH def855c89d8210db3040f1cb6ec837141ab9b8e74c158eae7c03d50160fcf30b) ly_associate_package(PACKAGE_NAME squish-ccr-20150601-rev3-multiplatform TARGETS squish-ccr PACKAGE_HASH c878c6c0c705e78403c397d03f5aa7bc87e5978298710e14d09c9daf951a83b3) ly_associate_package(PACKAGE_NAME ASTCEncoder-2017_11_14-rev2-multiplatform TARGETS ASTCEncoder PACKAGE_HASH c240ffc12083ee39a5ce9dc241de44d116e513e1e3e4cc1d05305e7aa3bdc326) ly_associate_package(PACKAGE_NAME md5-2.0-multiplatform TARGETS md5 PACKAGE_HASH 29e52ad22c78051551f78a40c2709594f0378762ae03b417adca3f4b700affdf) diff --git a/cmake/3rdParty/Platform/Mac/BuiltInPackages_mac.cmake b/cmake/3rdParty/Platform/Mac/BuiltInPackages_mac.cmake index ef66259e22..d6d017d1d1 100644 --- a/cmake/3rdParty/Platform/Mac/BuiltInPackages_mac.cmake +++ b/cmake/3rdParty/Platform/Mac/BuiltInPackages_mac.cmake @@ -15,7 +15,7 @@ ly_associate_package(PACKAGE_NAME Lua-5.3.5-rev3-multiplatform ly_associate_package(PACKAGE_NAME ilmbase-2.3.0-rev4-multiplatform TARGETS ilmbase PACKAGE_HASH 97547fdf1fbc4d81b8ccf382261f8c25514ed3b3c4f8fd493f0a4fa873bba348) ly_associate_package(PACKAGE_NAME hdf5-1.0.11-rev2-multiplatform TARGETS hdf5 PACKAGE_HASH 11d5e04df8a93f8c52a5684a4cacbf0d9003056360983ce34f8d7b601082c6bd) ly_associate_package(PACKAGE_NAME alembic-1.7.11-rev3-multiplatform TARGETS alembic PACKAGE_HASH ba7a7d4943dd752f5a662374f6c48b93493df1d8e2c5f6a8d101f3b50700dd25) -ly_associate_package(PACKAGE_NAME assimp-5.0.1-rev6-multiplatform TARGETS assimplib PACKAGE_HASH 47f1a6d05d101def036c030484c4a6e19d745aacd57037174715c7afe2b19b4c) +ly_associate_package(PACKAGE_NAME assimp-5.0.1-rev7-multiplatform TARGETS assimplib PACKAGE_HASH def855c89d8210db3040f1cb6ec837141ab9b8e74c158eae7c03d50160fcf30b) ly_associate_package(PACKAGE_NAME squish-ccr-20150601-rev3-multiplatform TARGETS squish-ccr PACKAGE_HASH c878c6c0c705e78403c397d03f5aa7bc87e5978298710e14d09c9daf951a83b3) ly_associate_package(PACKAGE_NAME ASTCEncoder-2017_11_14-rev2-multiplatform TARGETS ASTCEncoder PACKAGE_HASH c240ffc12083ee39a5ce9dc241de44d116e513e1e3e4cc1d05305e7aa3bdc326) ly_associate_package(PACKAGE_NAME md5-2.0-multiplatform TARGETS md5 PACKAGE_HASH 29e52ad22c78051551f78a40c2709594f0378762ae03b417adca3f4b700affdf) diff --git a/cmake/3rdParty/Platform/Windows/BuiltInPackages_windows.cmake b/cmake/3rdParty/Platform/Windows/BuiltInPackages_windows.cmake index 58050652c0..09dd543e5c 100644 --- a/cmake/3rdParty/Platform/Windows/BuiltInPackages_windows.cmake +++ b/cmake/3rdParty/Platform/Windows/BuiltInPackages_windows.cmake @@ -15,7 +15,7 @@ ly_associate_package(PACKAGE_NAME Lua-5.3.5-rev3-multiplatform ly_associate_package(PACKAGE_NAME ilmbase-2.3.0-rev4-multiplatform TARGETS ilmbase PACKAGE_HASH 97547fdf1fbc4d81b8ccf382261f8c25514ed3b3c4f8fd493f0a4fa873bba348) ly_associate_package(PACKAGE_NAME hdf5-1.0.11-rev2-multiplatform TARGETS hdf5 PACKAGE_HASH 11d5e04df8a93f8c52a5684a4cacbf0d9003056360983ce34f8d7b601082c6bd) ly_associate_package(PACKAGE_NAME alembic-1.7.11-rev3-multiplatform TARGETS alembic PACKAGE_HASH ba7a7d4943dd752f5a662374f6c48b93493df1d8e2c5f6a8d101f3b50700dd25) -ly_associate_package(PACKAGE_NAME assimp-5.0.1-rev6-multiplatform TARGETS assimplib PACKAGE_HASH 47f1a6d05d101def036c030484c4a6e19d745aacd57037174715c7afe2b19b4c) +ly_associate_package(PACKAGE_NAME assimp-5.0.1-rev7-multiplatform TARGETS assimplib PACKAGE_HASH def855c89d8210db3040f1cb6ec837141ab9b8e74c158eae7c03d50160fcf30b) ly_associate_package(PACKAGE_NAME squish-ccr-20150601-rev3-multiplatform TARGETS squish-ccr PACKAGE_HASH c878c6c0c705e78403c397d03f5aa7bc87e5978298710e14d09c9daf951a83b3) ly_associate_package(PACKAGE_NAME ASTCEncoder-2017_11_14-rev2-multiplatform TARGETS ASTCEncoder PACKAGE_HASH c240ffc12083ee39a5ce9dc241de44d116e513e1e3e4cc1d05305e7aa3bdc326) ly_associate_package(PACKAGE_NAME md5-2.0-multiplatform TARGETS md5 PACKAGE_HASH 29e52ad22c78051551f78a40c2709594f0378762ae03b417adca3f4b700affdf) From 78892c8d7eb566b43c7a4364b01163e45eb304e6 Mon Sep 17 00:00:00 2001 From: srikappa Date: Tue, 20 Apr 2021 14:30:56 -0700 Subject: [PATCH 31/33] Improved a couple of comments --- .../AzToolsFramework/Prefab/PrefabPublicHandler.cpp | 3 ++- .../AzToolsFramework/Prefab/PrefabPublicHandler.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp index 69ccf707d7..46bd924f30 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp @@ -92,7 +92,8 @@ namespace AzToolsFramework AZStd::string("Could not create a new prefab out of the entities provided - entities do not share a common root.")); } - // When you move instances from another template, you have to remove the links and propagate changes to target template. + // When we create a prefab with other prefab instances, we have to remove the existing links between the source and + // target templates of the other instances. for (auto& nestedInstance : instances) { PrefabUndoHelpers::RemoveLink( diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h index d92f33b634..19985bbf51 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h @@ -72,7 +72,7 @@ namespace AzToolsFramework /** * Creates a link between the templates of an instance and its parent. * - * \param topLevelEntities The list of entities that are immediate children of container entity of instance. + * \param topLevelEntities The list of entities that are immediate children to the container entity of the instance. * \param sourceInstance The instance that corresponds to the source template of the link. * \param targetInstance The id of the target template. * \param undoBatch The undo batch to set as parent for this create link action. From 65a1840e1dc9ff283da27d2ed08e3411b3e20d89 Mon Sep 17 00:00:00 2001 From: luissemp Date: Tue, 20 Apr 2021 14:38:03 -0700 Subject: [PATCH 32/33] Removed commented out line --- Gems/ScriptCanvas/Code/Editor/View/Windows/MainWindow.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Gems/ScriptCanvas/Code/Editor/View/Windows/MainWindow.cpp b/Gems/ScriptCanvas/Code/Editor/View/Windows/MainWindow.cpp index 85abf68332..ee4d6d9371 100644 --- a/Gems/ScriptCanvas/Code/Editor/View/Windows/MainWindow.cpp +++ b/Gems/ScriptCanvas/Code/Editor/View/Windows/MainWindow.cpp @@ -595,7 +595,6 @@ namespace ScriptCanvasEditor m_commandLine = new Widget::CommandLine(this); m_commandLine->setBaseSize(QSize(size().width(), m_commandLine->size().height())); m_commandLine->setObjectName("CommandLine"); -// m_commandLine->hide(); m_layout->addWidget(m_commandLine); m_layout->addWidget(m_emptyCanvas); From 62bc7a66bb82dfdc390dec81cdfaf2e3d72711cf Mon Sep 17 00:00:00 2001 From: AMZN-daimini <82231674+AMZN-daimini@users.noreply.github.com> Date: Tue, 20 Apr 2021 16:22:34 -0700 Subject: [PATCH 33/33] Remove the Level Inspector from Prefab mode and move behavior to Entity Inspector. (#149) * Remove Level Inspector from Prefab mode, and integrate the same behavior in the Entity Inspector * Show prefab name in level entity row of the Outliner. Allow Ui Handlers to prevent renaming. * Separate setting the prefab's template path and the container entity name. * Disable reparenting to root level * Disable the ability to rename the level entity. * Fixes as per Ram's review --- .../PrefabEditorEntityOwnershipService.cpp | 2 + .../Prefab/Instance/Instance.cpp | 8 ++- .../Prefab/Instance/Instance.h | 1 + .../Prefab/PrefabPublicHandler.cpp | 4 +- .../Prefab/PrefabSystemComponent.cpp | 1 + .../EditorEntityUiHandlerBase.cpp | 5 ++ .../EditorEntityUiHandlerBase.h | 2 + .../UI/Outliner/EntityOutlinerListModel.cpp | 44 +++++++------- .../UI/Outliner/EntityOutlinerWidget.cpp | 29 ++++++++-- .../UI/Outliner/EntityOutlinerWidget.hxx | 3 + .../UI/Prefab/LevelRootUiHandler.cpp | 20 +++++++ .../UI/Prefab/LevelRootUiHandler.h | 2 + .../PropertyEditor/EntityPropertyEditor.cpp | 57 +++++++++++++++---- .../PropertyEditor/EntityPropertyEditor.hxx | 9 +++ Code/Sandbox/Editor/QtViewPaneManager.cpp | 20 ++++++- .../ComponentEntityEditorPlugin.cpp | 17 +++--- 16 files changed, 171 insertions(+), 53 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp index 2424658ecf..cb16e0c099 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp @@ -94,6 +94,7 @@ namespace AzToolsFramework m_prefabSystemComponent->RemoveTemplate(templateId); } m_rootInstance->Reset(); + m_rootInstance->SetContainerEntityName("Level"); AzFramework::EntityOwnershipServiceNotificationBus::Event( m_entityContextId, &AzFramework::EntityOwnershipServiceNotificationBus::Events::OnEntityOwnershipServiceReset); @@ -198,6 +199,7 @@ namespace AzToolsFramework m_rootInstance->SetTemplateId(templateId); m_rootInstance->SetTemplateSourcePath(m_loaderInterface->GetRelativePathToProject(filename)); + m_rootInstance->SetContainerEntityName("Level"); m_prefabSystemComponent->PropagateTemplateChanges(templateId); return true; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.cpp index 0a5b43482e..c1eee62dbc 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.cpp @@ -123,7 +123,11 @@ namespace AzToolsFramework void Instance::SetTemplateSourcePath(AZ::IO::PathView sourcePath) { m_templateSourcePath = sourcePath; - m_containerEntity->SetName(sourcePath.Filename().Native()); + } + + void Instance::SetContainerEntityName(AZStd::string_view containerName) + { + m_containerEntity->SetName(containerName); } bool Instance::AddEntity(AZ::Entity& entity) @@ -563,7 +567,7 @@ namespace AzToolsFramework AZ::EntityId Instance::GetContainerEntityId() const { - return m_containerEntity->GetId(); + return m_containerEntity ? m_containerEntity->GetId() : AZ::EntityId(); } bool Instance::HasContainerEntity() const diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.h index d1c7a4d853..186dce0f50 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.h @@ -80,6 +80,7 @@ namespace AzToolsFramework const AZ::IO::Path& GetTemplateSourcePath() const; void SetTemplateSourcePath(AZ::IO::PathView sourcePath); + void SetContainerEntityName(AZStd::string_view containerName); bool AddEntity(AZ::Entity& entity); bool AddEntity(AZ::Entity& entity, EntityAlias entityAlias); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp index 46bd924f30..772e0ae52e 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp @@ -721,7 +721,7 @@ namespace AzToolsFramework InstanceOptionalReference owningInstance = m_instanceEntityMapperInterface->FindOwningInstance(entity->GetId()); AZ_Assert( owningInstance.has_value(), - "An error occored while retrieving entities and prefab instances : " + "An error occurred while retrieving entities and prefab instances : " "Owning instance of entity with id '%llu' couldn't be found", entity->GetId()); @@ -805,7 +805,7 @@ namespace AzToolsFramework { AZ_Assert( false, - "An error occored in function EntitiesBelongToSameInstance: " + "An error occurred in function EntitiesBelongToSameInstance: " "Owning instance of entity with id '%llu' couldn't be found", entityId); return false; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp index 9070630e56..54e99c9416 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp @@ -121,6 +121,7 @@ namespace AzToolsFramework } newInstance->SetTemplateSourcePath(relativeFilePath); + newInstance->SetContainerEntityName(relativeFilePath.Stem().Native()); TemplateId newTemplateId = CreateTemplateFromInstance(*newInstance); if (newTemplateId == InvalidTemplateId) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/EditorEntityUi/EditorEntityUiHandlerBase.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/EditorEntityUi/EditorEntityUiHandlerBase.cpp index 98edd26f88..84266d3707 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/EditorEntityUi/EditorEntityUiHandlerBase.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/EditorEntityUi/EditorEntityUiHandlerBase.cpp @@ -61,6 +61,11 @@ namespace AzToolsFramework return true; } + bool EditorEntityUiHandlerBase::CanRename(AZ::EntityId /*entityId*/) const + { + return true; + } + void EditorEntityUiHandlerBase::PaintItemBackground(QPainter* /*painter*/, const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/) const { } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/EditorEntityUi/EditorEntityUiHandlerBase.h b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/EditorEntityUi/EditorEntityUiHandlerBase.h index 7360e7ff0b..1aa5e5720f 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/EditorEntityUi/EditorEntityUiHandlerBase.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/EditorEntityUi/EditorEntityUiHandlerBase.h @@ -47,6 +47,8 @@ namespace AzToolsFramework virtual QPixmap GenerateItemIcon(AZ::EntityId entityId) const; //! Returns whether the element's lock and visibility state should be accessible in the Outliner virtual bool CanToggleLockVisibility(AZ::EntityId entityId) const; + //! Returns whether the element's name should be editable + virtual bool CanRename(AZ::EntityId entityId) const; //! Paints the background of the item in the Outliner. virtual void PaintItemBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerListModel.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerListModel.cpp index de10ae18b4..5b44594398 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerListModel.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerListModel.cpp @@ -945,6 +945,12 @@ namespace AzToolsFramework return false; } + // Disable reparenting to the root level + if (!newParentId.IsValid()) + { + return false; + } + // Ignore entities not owned by the editor context. It is assumed that all entities belong // to the same context since multiple selection doesn't span across views. for (const AZ::EntityId& entityId : selectedEntityIds) @@ -974,39 +980,33 @@ namespace AzToolsFramework } } - if (newParentId.IsValid()) + bool isLayerEntity = false; + Layers::EditorLayerComponentRequestBus::EventResult( + isLayerEntity, + entityId, + &Layers::EditorLayerComponentRequestBus::Events::HasLayer); + // Layers can only have other layers as parents, or have no parent. + if (isLayerEntity) { - bool isLayerEntity = false; + bool newParentIsLayer = false; Layers::EditorLayerComponentRequestBus::EventResult( - isLayerEntity, - entityId, + newParentIsLayer, + newParentId, &Layers::EditorLayerComponentRequestBus::Events::HasLayer); - // Layers can only have other layers as parents, or have no parent. - if (isLayerEntity) + if (!newParentIsLayer) { - bool newParentIsLayer = false; - Layers::EditorLayerComponentRequestBus::EventResult( - newParentIsLayer, - newParentId, - &Layers::EditorLayerComponentRequestBus::Events::HasLayer); - if (!newParentIsLayer) - { - return false; - } + return false; } } } //Only check the entity pointer if the entity id is valid because //we want to allow dragging items to unoccupied parts of the tree to un-parent them - if (newParentId.IsValid()) + AZ::Entity* newParentEntity = nullptr; + AZ::ComponentApplicationBus::BroadcastResult(newParentEntity, &AZ::ComponentApplicationRequests::FindEntity, newParentId); + if (!newParentEntity) { - AZ::Entity* newParentEntity = nullptr; - AZ::ComponentApplicationBus::BroadcastResult(newParentEntity, &AZ::ComponentApplicationRequests::FindEntity, newParentId); - if (!newParentEntity) - { - return false; - } + return false; } //reject dragging on to yourself or your children diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerWidget.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerWidget.cpp index 08fc764507..3ee8a14285 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerWidget.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerWidget.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -271,6 +272,12 @@ namespace AzToolsFramework m_listModel->Initialize(); + m_editorEntityUiInterface = AZ::Interface::Get(); + + AZ_Assert( + m_editorEntityUiInterface != nullptr, + "EntityOutlinerWidget requires a EditorEntityUiInterface instance on Initialize."); + EditorPickModeNotificationBus::Handler::BusConnect(GetEntityContextId()); EntityHighlightMessages::Bus::Handler::BusConnect(); EntityOutlinerModelNotificationBus::Handler::BusConnect(); @@ -562,7 +569,13 @@ namespace AzToolsFramework if (m_selectedEntityIds.size() == 1) { - contextMenu->addAction(m_actionToRenameSelection); + auto entityId = m_selectedEntityIds.front(); + auto entityUiHandler = m_editorEntityUiInterface->GetHandler(entityId); + + if (!entityUiHandler || entityUiHandler->CanRename(entityId)) + { + contextMenu->addAction(m_actionToRenameSelection); + } } if (m_selectedEntityIds.size() == 1) @@ -688,11 +701,17 @@ namespace AzToolsFramework if (m_selectedEntityIds.size() == 1) { - const QModelIndex proxyIndex = GetIndexFromEntityId(m_selectedEntityIds.front()); - if (proxyIndex.isValid()) + auto entityId = m_selectedEntityIds.front(); + auto entityUiHandler = m_editorEntityUiInterface->GetHandler(entityId); + + if (!entityUiHandler || entityUiHandler->CanRename(entityId)) { - m_gui->m_objectTree->setCurrentIndex(proxyIndex); - m_gui->m_objectTree->QTreeView::edit(proxyIndex); + const QModelIndex proxyIndex = GetIndexFromEntityId(entityId); + if (proxyIndex.isValid()) + { + m_gui->m_objectTree->setCurrentIndex(proxyIndex); + m_gui->m_objectTree->QTreeView::edit(proxyIndex); + } } } } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerWidget.hxx b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerWidget.hxx index cf8c55abd1..f225bb49b8 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerWidget.hxx +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerWidget.hxx @@ -42,6 +42,7 @@ namespace Ui namespace AzToolsFramework { + class EditorEntityUiInterface; class EntityOutlinerListModel; class EntityOutlinerSortFilterProxyModel; @@ -193,6 +194,8 @@ namespace AzToolsFramework EntityIdSet m_entitiesToSort; EntityOutliner::DisplaySortMode m_sortMode; bool m_sortContentQueued; + + EditorEntityUiInterface* m_editorEntityUiInterface = nullptr; }; } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/LevelRootUiHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/LevelRootUiHandler.cpp index 828a49ef94..7915403c0a 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/LevelRootUiHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/LevelRootUiHandler.cpp @@ -50,11 +50,31 @@ namespace AzToolsFramework return QPixmap(m_levelRootIconPath); } + QString LevelRootUiHandler::GenerateItemInfoString(AZ::EntityId entityId) const + { + QString infoString; + + AZ::IO::Path path = m_prefabPublicInterface->GetOwningInstancePrefabPath(entityId); + + if (!path.empty()) + { + infoString = + QObject::tr("(%1)").arg(path.Filename().Native().data()); + } + + return infoString; + } + bool LevelRootUiHandler::CanToggleLockVisibility(AZ::EntityId /*entityId*/) const { return false; } + bool LevelRootUiHandler::CanRename(AZ::EntityId /*entityId*/) const + { + return false; + } + void LevelRootUiHandler::PaintItemBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& /*index*/) const { if (!painter) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/LevelRootUiHandler.h b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/LevelRootUiHandler.h index a8b2e4a4f8..19c1244040 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/LevelRootUiHandler.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/LevelRootUiHandler.h @@ -34,7 +34,9 @@ namespace AzToolsFramework // EditorEntityUiHandler... QPixmap GenerateItemIcon(AZ::EntityId entityId) const override; + QString GenerateItemInfoString(AZ::EntityId entityId) const override; bool CanToggleLockVisibility(AZ::EntityId entityId) const override; + bool CanRename(AZ::EntityId entityId) const override; void PaintItemBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override; private: diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp index 55c7fb3f65..181f5b9a9d 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp @@ -310,6 +310,9 @@ namespace AzToolsFramework { initEntityPropertyEditorResources(); + m_prefabPublicInterface = AZ::Interface::Get(); + AZ_Assert(m_prefabPublicInterface != nullptr, "EntityPropertyEditor requires a PrefabPublicInterface instance on Initialize."); + setObjectName("EntityPropertyEditor"); setAcceptDrops(true); @@ -405,8 +408,6 @@ namespace AzToolsFramework CreateActions(); UpdateContents(); - m_prefabPublicInterface = AZ::Interface::Get(); - EditorEntityContextNotificationBus::Handler::BusConnect(); //forced to register global event filter with application for selection @@ -693,11 +694,38 @@ namespace AzToolsFramework m_gui->m_entityIcon->repaint(); } + EntityPropertyEditor::InspectorLayout EntityPropertyEditor::GetCurrentInspectorLayout() const + { + if (!m_prefabsAreEnabled) + { + return m_isLevelEntityEditor ? InspectorLayout::LEVEL : InspectorLayout::ENTITY; + } + + AZ::EntityId levelContainerEntityId = m_prefabPublicInterface->GetLevelInstanceContainerEntityId(); + if (AZStd::find(m_selectedEntityIds.begin(), m_selectedEntityIds.end(), levelContainerEntityId) != m_selectedEntityIds.end()) + { + if (m_selectedEntityIds.size() > 1) + { + return InspectorLayout::INVALID; + } + else + { + return InspectorLayout::LEVEL; + } + } + else + { + return InspectorLayout::ENTITY; + } + } + void EntityPropertyEditor::UpdateEntityDisplay() { UpdateStatusComboBox(); - if (m_isLevelEntityEditor) + InspectorLayout layout = GetCurrentInspectorLayout(); + + if (layout == InspectorLayout::LEVEL) { AZStd::string levelName; AzToolsFramework::EditorRequestBus::BroadcastResult(levelName, &AzToolsFramework::EditorRequests::GetLevelName); @@ -737,13 +765,20 @@ namespace AzToolsFramework AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::AzToolsFramework); SelectionEntityTypeInfo result = SelectionEntityTypeInfo::None; - if (m_isLevelEntityEditor) + InspectorLayout layout = GetCurrentInspectorLayout(); + + if (layout == InspectorLayout::LEVEL) { // The Level Inspector should only have a list of selectable components after the // level entity itself is valid (i.e. "selected"). return selection.empty() ? SelectionEntityTypeInfo::None : SelectionEntityTypeInfo::LevelEntity; } + if (layout == InspectorLayout::INVALID) + { + return SelectionEntityTypeInfo::Mixed; + } + for (AZ::EntityId selectedEntityId : selection) { bool isLayerEntity = false; @@ -909,16 +944,18 @@ namespace AzToolsFramework } } + bool isLevelLayout = GetCurrentInspectorLayout() == InspectorLayout::LEVEL; + m_gui->m_entityDetailsLabel->setText(entityDetailsLabelText); m_gui->m_entityDetailsLabel->setVisible(entityDetailsVisible); m_gui->m_entityNameEditor->setVisible(hasEntitiesDisplayed); m_gui->m_entityNameLabel->setVisible(hasEntitiesDisplayed); m_gui->m_entityIcon->setVisible(hasEntitiesDisplayed); - m_gui->m_pinButton->setVisible(m_overrideSelectedEntityIds.empty() && hasEntitiesDisplayed && !m_isSystemEntityEditor && !m_isLevelEntityEditor); - m_gui->m_statusLabel->setVisible(hasEntitiesDisplayed && !m_isSystemEntityEditor && !m_isLevelEntityEditor); - m_gui->m_statusComboBox->setVisible(hasEntitiesDisplayed && !m_isSystemEntityEditor && !m_isLevelEntityEditor); - m_gui->m_entityIdLabel->setVisible(hasEntitiesDisplayed && !m_isSystemEntityEditor && !m_isLevelEntityEditor); - m_gui->m_entityIdText->setVisible(hasEntitiesDisplayed && !m_isSystemEntityEditor && !m_isLevelEntityEditor); + m_gui->m_pinButton->setVisible(m_overrideSelectedEntityIds.empty() && hasEntitiesDisplayed && !m_isSystemEntityEditor); + m_gui->m_statusLabel->setVisible(hasEntitiesDisplayed && !m_isSystemEntityEditor && !isLevelLayout); + m_gui->m_statusComboBox->setVisible(hasEntitiesDisplayed && !m_isSystemEntityEditor && !isLevelLayout); + m_gui->m_entityIdLabel->setVisible(hasEntitiesDisplayed && !m_isSystemEntityEditor && !isLevelLayout); + m_gui->m_entityIdText->setVisible(hasEntitiesDisplayed && !m_isSystemEntityEditor && !isLevelLayout); bool displayComponentSearchBox = hasEntitiesDisplayed; if (hasEntitiesDisplayed) @@ -941,7 +978,7 @@ namespace AzToolsFramework UpdateEntityDisplay(); } - m_gui->m_darkBox->setVisible(displayComponentSearchBox && !m_isSystemEntityEditor && !m_isLevelEntityEditor); + m_gui->m_darkBox->setVisible(displayComponentSearchBox && !m_isSystemEntityEditor && !isLevelLayout); m_gui->m_entitySearchBox->setVisible(displayComponentSearchBox); bool displayAddComponentMenu = CanAddComponentsToSelection(selectionEntityTypeInfo); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx index fed9c55f15..677dc98277 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx @@ -521,6 +521,15 @@ namespace AzToolsFramework bool m_isSystemEntityEditor; bool m_isLevelEntityEditor = false; + enum class InspectorLayout + { + ENTITY = 0, // All selected entities are regular entities + LEVEL, // The selected entity is the level prefab container entity + INVALID // Other entities are selected alongside the level prefab container entity + }; + + InspectorLayout GetCurrentInspectorLayout() const; + // the spacer's job is to make sure that its always at the end of the list of components. QSpacerItem* m_spacer; bool m_isAlreadyQueuedRefresh; diff --git a/Code/Sandbox/Editor/QtViewPaneManager.cpp b/Code/Sandbox/Editor/QtViewPaneManager.cpp index ad33eecfee..b242f3d914 100644 --- a/Code/Sandbox/Editor/QtViewPaneManager.cpp +++ b/Code/Sandbox/Editor/QtViewPaneManager.cpp @@ -36,6 +36,8 @@ #include #include +#include + #include #include #include @@ -983,6 +985,11 @@ bool QtViewPaneManager::ClosePanesWithRollback(const QVector& panesToKe */ void QtViewPaneManager::RestoreDefaultLayout(bool resetSettings) { + // Get whether the prefab system is enabled + bool isPrefabSystemEnabled = false; + AzFramework::ApplicationRequests::Bus::BroadcastResult( + isPrefabSystemEnabled, &AzFramework::ApplicationRequests::IsPrefabSystemEnabled); + if (resetSettings) { // We're going to do something destructive (removing all of the viewpane settings). Better confirm with the user @@ -1022,7 +1029,11 @@ void QtViewPaneManager::RestoreDefaultLayout(bool resetSettings) state.viewPanes.push_back(LyViewPane::EntityInspector); state.viewPanes.push_back(LyViewPane::AssetBrowser); state.viewPanes.push_back(LyViewPane::Console); - state.viewPanes.push_back(LyViewPane::LevelInspector); + + if (!isPrefabSystemEnabled) + { + state.viewPanes.push_back(LyViewPane::LevelInspector); + } state.mainWindowState = m_defaultMainWindowState; @@ -1047,7 +1058,12 @@ void QtViewPaneManager::RestoreDefaultLayout(bool resetSettings) const QtViewPane* assetBrowserViewPane = OpenPane(LyViewPane::AssetBrowser, QtViewPane::OpenMode::UseDefaultState); const QtViewPane* entityInspectorViewPane = OpenPane(LyViewPane::EntityInspector, QtViewPane::OpenMode::UseDefaultState); const QtViewPane* consoleViewPane = OpenPane(LyViewPane::Console, QtViewPane::OpenMode::UseDefaultState); - const QtViewPane* levelInspectorPane = OpenPane(LyViewPane::LevelInspector, QtViewPane::OpenMode::UseDefaultState); + + const QtViewPane* levelInspectorPane = nullptr; + if (!isPrefabSystemEnabled) + { + levelInspectorPane = OpenPane(LyViewPane::LevelInspector, QtViewPane::OpenMode::UseDefaultState); + } // This class does all kinds of behind the scenes magic to make docking / restore work, especially with groups // so instead of doing our special default layout attach / docking right now, we want to make it happen diff --git a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin.cpp b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin.cpp index 17face523b..e5ad2a2872 100644 --- a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin.cpp +++ b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin.cpp @@ -143,15 +143,6 @@ ComponentEntityEditorPlugin::ComponentEntityEditorPlugin([[maybe_unused]] IEdito LyViewPane::CategoryTools, pinnedInspectorOptions); - ViewPaneOptions levelInspectorOptions; - levelInspectorOptions.canHaveMultipleInstances = false; - levelInspectorOptions.preferedDockingArea = Qt::RightDockWidgetArea; - levelInspectorOptions.paneRect = QRect(50, 50, 400, 700); - RegisterViewPane( - LyViewPane::LevelInspector, - LyViewPane::CategoryTools, - levelInspectorOptions); - bool prefabSystemEnabled = false; AzFramework::ApplicationRequests::Bus::BroadcastResult(prefabSystemEnabled, &AzFramework::ApplicationRequests::IsPrefabSystemEnabled); @@ -170,8 +161,14 @@ ComponentEntityEditorPlugin::ComponentEntityEditorPlugin([[maybe_unused]] IEdito } else { - // Add the Legacy Outliner to the Tools Menu + ViewPaneOptions levelInspectorOptions; + levelInspectorOptions.canHaveMultipleInstances = false; + levelInspectorOptions.preferedDockingArea = Qt::RightDockWidgetArea; + levelInspectorOptions.paneRect = QRect(50, 50, 400, 700); + RegisterViewPane( + LyViewPane::LevelInspector, LyViewPane::CategoryTools, levelInspectorOptions); + // Add the Legacy Outliner to the Tools Menu ViewPaneOptions outlinerOptions; outlinerOptions.canHaveMultipleInstances = true; outlinerOptions.preferedDockingArea = Qt::LeftDockWidgetArea;