diff --git a/AutomatedTesting/Gem/PythonTests/EditorPythonBindings/CryMaterialsCommands_test.py b/AutomatedTesting/Gem/PythonTests/EditorPythonBindings/CryMaterialsCommands_test.py deleted file mode 100755 index 41ae0608a4..0000000000 --- a/AutomatedTesting/Gem/PythonTests/EditorPythonBindings/CryMaterialsCommands_test.py +++ /dev/null @@ -1,75 +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. -""" - -# -# This is a pytest module to test the in-Editor Python API from ViewPane.h -# -import pytest -pytest.importorskip('ly_test_tools') - -import sys -import os -sys.path.append(os.path.dirname(__file__)) -from hydra_utils import launch_test_case - - -@pytest.mark.SUITE_sandbox -@pytest.mark.parametrize('launcher_platform', ['windows_editor']) -@pytest.mark.parametrize('project', ['AutomatedTesting']) -@pytest.mark.parametrize('level', ['auto_test']) -class TestLegacyCryMaterialsCommandsAutomation(object): - - def test_Legacy_CryMaterials(self, request, editor, level, launcher_platform): - - unexpected_lines=[] - expected_lines = [ - # "Material Settings/Shader updated correctly", # Disabled, SPEC-3590 - # "Material Settings/Surface Type updated correctly", # Disabled, SPEC-3590 - "Texture Maps/Diffuse/Tiling/IsTileU updated correctly", - "Texture Maps/Diffuse/Tiling/TileU updated correctly", - "Texture Maps/Diffuse/Rotator/Type updated correctly", - "Texture Maps/Diffuse/Rotator/Amplitude updated correctly", - "Texture Maps/Diffuse/Oscillator/AmplitudeU updated correctly", - "Opacity Settings/Opacity updated correctly", - "Opacity Settings/AlphaTest updated correctly", - "Opacity Settings/Additive updated correctly", - "Lighting Settings/Diffuse Color updated correctly", - "Lighting Settings/Specular Color updated correctly", - "Lighting Settings/Emissive Intensity updated correctly", - "Lighting Settings/Emissive Color updated correctly", - "Advanced/Allow layer activation updated correctly", - "Advanced/2 Sided updated correctly", - "Advanced/No Shadow updated correctly", - "Advanced/Use Scattering updated correctly", - "Advanced/Hide After Breaking updated correctly", - "Advanced/Fog Volume Shading Quality High updated correctly", - "Advanced/Blend Terrain Color updated correctly", - "Advanced/Voxel Coverage updated correctly", - "Advanced/Propagate Opacity Settings updated correctly", - "Advanced/Propagate Lighting Settings updated correctly", - "Advanced/Propagate Advanced Settings updated correctly", - "Advanced/Propagate Texture Maps updated correctly", - "Advanced/Propagate Shader Params updated correctly", - "Advanced/Propagate Shader Generation updated correctly", - "Advanced/Propagate Vertex Deformation updated correctly", - # "Shader Params/Blend Factor updated correctly", # Disabled, SPEC-3590 - # "Shader Params/Indirect bounce color updated correctly", # Disabled, SPEC-3590 - "Vertex Deformation/Type updated correctly", - "Vertex Deformation/Wave Length X updated correctly", - "Vertex Deformation/Wave X/Level updated correctly", - "Vertex Deformation/Wave X/Amplitude updated correctly", - "Vertex Deformation/Wave X/Phase updated correctly", - "Vertex Deformation/Wave X/Frequency updated correctly" - ] - - test_case_file = os.path.join(os.path.dirname(__file__), 'CryMaterialsCommands_test_case.py') - launch_test_case(editor, test_case_file, expected_lines, unexpected_lines) - diff --git a/AutomatedTesting/Gem/PythonTests/EditorPythonBindings/CryMaterialsCommands_test_case.py b/AutomatedTesting/Gem/PythonTests/EditorPythonBindings/CryMaterialsCommands_test_case.py deleted file mode 100755 index 913b1ace24..0000000000 --- a/AutomatedTesting/Gem/PythonTests/EditorPythonBindings/CryMaterialsCommands_test_case.py +++ /dev/null @@ -1,116 +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. -""" - -# Tests the legacy Python API for CryMaterials while the Editor is running - -import azlmbr.bus as bus -import azlmbr.editor as editor -import azlmbr.legacy.material as material -import azlmbr.math as math - -materialName = 'materials/ter_layer_green' -print(f'Starting CryMaterial test case using material {materialName}') - - -def MaterialPropertyTest(property, value, doReset=True): - try: - # get old value and attempt to set new value - oldValue = material.get_property(materialName, property) - if oldValue == value: - print(f'>>> `{property}` already set to {oldValue}') - return - material.set_property(materialName, property, value) - - # test that the set new value worked - newValue = material.get_property(materialName, property) - if oldValue != newValue: - print(f"{property} updated correctly") - - # reset back to old value - if doReset: - material.set_property(materialName, property, oldValue) - except: - print(f'!!! hit an exception when setting `{property}` to {value}') - - -color = math.Color() -color.r = 255.0 -color.g = 128.0 -color.b = 64.0 -color.a = 0.0 - -# Material Settings -# MaterialPropertyTest("Material Settings/Shader", "Geometrybeam") # Disabled, SPEC-3590 -# MaterialPropertyTest("Material Settings/Surface Type", "grass") # Disabled, SPEC-3590 - -# Texture Maps -MaterialPropertyTest("Texture Maps/Diffuse/Tiling/IsTileU", False) -MaterialPropertyTest("Texture Maps/Diffuse/Tiling/IsTileV", False) -MaterialPropertyTest("Texture Maps/Diffuse/Tiling/TileU", 0.42) -MaterialPropertyTest("Texture Maps/Diffuse/Rotator/Type", 'Oscillated Rotation') -MaterialPropertyTest("Texture Maps/Diffuse/Rotator/Amplitude", 42.0) -MaterialPropertyTest("Texture Maps/Diffuse/Oscillator/TypeU", 'Fixed Moving') -MaterialPropertyTest("Texture Maps/Diffuse/Oscillator/AmplitudeU", 42.0) - -# Vertex Deformation -MaterialPropertyTest("Vertex Deformation/Type", 'Sin Wave') -MaterialPropertyTest("Vertex Deformation/Wave Length X", 42.0) -MaterialPropertyTest("Vertex Deformation/Type", 'Perlin 3D') -MaterialPropertyTest("Vertex Deformation/Noise Scale", math.Vector3(1.1, 2.2, 3.3)) - -# Opacity Settings -MaterialPropertyTest("Opacity Settings/Opacity", 42) -MaterialPropertyTest("Opacity Settings/AlphaTest", 2) -MaterialPropertyTest("Opacity Settings/Additive", True) - -# Lighting Settings -MaterialPropertyTest("Lighting Settings/Diffuse Color", color) -MaterialPropertyTest("Lighting Settings/Specular Color", color) -MaterialPropertyTest("Lighting Settings/Emissive Intensity", 42.0) -MaterialPropertyTest("Lighting Settings/Emissive Color", color) -MaterialPropertyTest("Lighting Settings/Specular Level", 2.0) - -# Advanced -MaterialPropertyTest("Advanced/Allow layer activation", False) -MaterialPropertyTest("Advanced/2 Sided", True) -MaterialPropertyTest("Advanced/No Shadow", True) -MaterialPropertyTest("Advanced/Use Scattering", True) -MaterialPropertyTest("Advanced/Hide After Breaking", True) -MaterialPropertyTest("Advanced/Fog Volume Shading Quality High", True) -MaterialPropertyTest("Advanced/Blend Terrain Color", True) -MaterialPropertyTest("Advanced/Voxel Coverage", 0.42) -# --- MaterialPropertyTest("Advanced/Link to Material", "materials/ter_layer_blue") # Works, but clears on UI refresh -MaterialPropertyTest("Advanced/Propagate Opacity Settings", True) -MaterialPropertyTest("Advanced/Propagate Lighting Settings", True) -MaterialPropertyTest("Advanced/Propagate Advanced Settings", True) -MaterialPropertyTest("Advanced/Propagate Texture Maps", True) -MaterialPropertyTest("Advanced/Propagate Shader Params", True) -MaterialPropertyTest("Advanced/Propagate Shader Generation", True) -MaterialPropertyTest("Advanced/Propagate Vertex Deformation", True) - -# Shader parameters vary with each Shader, just testing a couple of them... -# MaterialPropertyTest("Shader Params/Blend Factor", 7.0, False) # Disabled, SPEC-3590 -# MaterialPropertyTest("Shader Params/Indirect bounce color", color, False) # Disabled, SPEC-3590 - -### These values are reset to False when set. Left them here commented for reference. -# MaterialPropertyTest("Shader Generation Params/Dust & Turbulence", True) -# MaterialPropertyTest("Shader Generation Params/Receive Shadows", True) -# MaterialPropertyTest("Shader Generation Params/UV Vignetting", True) - -# Vertex Deformation -MaterialPropertyTest("Vertex Deformation/Type", "Sin Wave") -MaterialPropertyTest("Vertex Deformation/Wave Length X", 42.0) -MaterialPropertyTest("Vertex Deformation/Wave X/Level", 42.0) -MaterialPropertyTest("Vertex Deformation/Wave X/Amplitude", 42.0) -MaterialPropertyTest("Vertex Deformation/Wave X/Phase", 42.0) -MaterialPropertyTest("Vertex Deformation/Wave X/Frequency", 42.0) - -editor.EditorToolsApplicationRequestBus(bus.Broadcast, 'ExitNoPrompt') diff --git a/Code/CryEngine/CryCommon/IShader.h b/Code/CryEngine/CryCommon/IShader.h index 1e8553ac57..7fcbdefebb 100644 --- a/Code/CryEngine/CryCommon/IShader.h +++ b/Code/CryEngine/CryCommon/IShader.h @@ -52,7 +52,6 @@ struct SShaderItem; class ITexture; struct IMaterial; struct SParam; -class CMaterial; struct SShaderSerializeContext; struct IAnimNode; struct SSkinningData; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFrameworkModule.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFrameworkModule.cpp index e7037c8936..373787e7dd 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFrameworkModule.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFrameworkModule.cpp @@ -53,7 +53,6 @@ #include #include #include -#include #include namespace AzToolsFramework @@ -93,7 +92,6 @@ namespace AzToolsFramework AzToolsFramework::SliceDependencyBrowserComponent::CreateDescriptor(), AzToolsFramework::Thumbnailer::ThumbnailerComponent::CreateDescriptor(), AzToolsFramework::AssetBrowser::AssetBrowserComponent::CreateDescriptor(), - AzToolsFramework::MaterialBrowser::MaterialBrowserComponent::CreateDescriptor(), AzToolsFramework::EditorInteractionSystemComponent::CreateDescriptor(), AzToolsFramework::Components::EditorComponentAPIComponent::CreateDescriptor(), AzToolsFramework::Components::EditorLevelComponentAPIComponent::CreateDescriptor(), diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialBrowserBus.h b/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialBrowserBus.h deleted file mode 100644 index b0d625b6e4..0000000000 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialBrowserBus.h +++ /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. -* -*/ - -#pragma once - -#include - -namespace AZ -{ - namespace Data - { - struct AssetId; - } -} - -namespace AzToolsFramework -{ - namespace MaterialBrowser - { - class MaterialBrowserRequests - : public AZ::EBusTraits - { - public: - - // Only a single handler is allowed - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - - virtual bool HasRecord(const AZ::Data::AssetId& assetId) = 0; - virtual bool IsMultiMaterial(const AZ::Data::AssetId& assetId) = 0; - }; - - using MaterialBrowserRequestBus = AZ::EBus; - } // namespace MaterialBrowser -} // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialBrowserComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialBrowserComponent.cpp deleted file mode 100644 index f64d4af23d..0000000000 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialBrowserComponent.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#include - -#include -#include -#include -#include -#include -#include - -#include -AZ_PUSH_DISABLE_WARNING(4251, "-Wunknown-warning-option") // 4251: 'QBrush::d': class 'QScopedPointer' needs to have dll-interface to be used by clients of class 'QBrush' -#include -AZ_POP_DISABLE_WARNING - -namespace AzToolsFramework -{ - namespace MaterialBrowser - { - MaterialBrowserComponent::MaterialBrowserComponent() - { - } - - void MaterialBrowserComponent::Activate() - { - using namespace Thumbnailer; - using namespace AssetBrowser; - const char* contextName = "MaterialBrowser"; - ThumbnailerRequestsBus::Broadcast(&ThumbnailerRequests::RegisterContext, contextName); - ThumbnailerRequestsBus::Broadcast(&ThumbnailerRequests::RegisterThumbnailProvider, MAKE_TCACHE(FolderThumbnailCache), contextName); - ThumbnailerRequestsBus::Broadcast(&ThumbnailerRequests::RegisterThumbnailProvider, MAKE_TCACHE(SourceThumbnailCache), contextName); - ThumbnailerRequestsBus::Broadcast(&ThumbnailerRequests::RegisterThumbnailProvider, MAKE_TCACHE(MaterialThumbnailCache), contextName); - ThumbnailerRequestsBus::Broadcast(&ThumbnailerRequests::RegisterThumbnailProvider, MAKE_TCACHE(SourceControlThumbnailCache), contextName); - } - - void MaterialBrowserComponent::Deactivate() - { - } - - void MaterialBrowserComponent::Reflect(AZ::ReflectContext* context) - { - AZ::SerializeContext* serialize = azrtti_cast(context); - if (serialize) - { - serialize->Class(); - } - } - - void MaterialBrowserComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) - { - required.push_back(AZ_CRC("ThumbnailerService", 0x65422b97)); - } - } // namespace MaterialBrowser -} // namespace AzToolsFramework - diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialBrowserComponent.h b/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialBrowserComponent.h deleted file mode 100644 index 93a48cf22c..0000000000 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialBrowserComponent.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once - -#include -#include - -namespace AzToolsFramework -{ - namespace MaterialBrowser - { - //! MaterialBrowserComponent allows initialization of MaterialBrowser systems, such as thumbnails - class MaterialBrowserComponent - : public AZ::Component - { - public: - AZ_COMPONENT(MaterialBrowserComponent, "{121F3F3B-2412-490D-9E3E-C205C677F476}") - - MaterialBrowserComponent(); - virtual ~MaterialBrowserComponent() = default; - - ////////////////////////////////////////////////////////////////////////// - // AZ::Component - ////////////////////////////////////////////////////////////////////////// - void Activate() override; - void Deactivate() override; - static void Reflect(AZ::ReflectContext* context); - - static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required); - }; - } // namespace MaterialBrowser -} // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialThumbnail.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialThumbnail.cpp deleted file mode 100644 index e04df8937c..0000000000 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialThumbnail.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include - -#include - -namespace AzToolsFramework -{ - namespace MaterialBrowser - { - static constexpr const char* SimpleMaterialIconPath = ":/MaterialBrowser/images/material_04.png"; - static constexpr const char* MultiMaterialIconPath = ":/MaterialBrowser/images/material_06.png"; - - ////////////////////////////////////////////////////////////////////////// - // MaterialThumbnail - ////////////////////////////////////////////////////////////////////////// - MaterialThumbnail::MaterialThumbnail(Thumbnailer::SharedThumbnailKey key) - : Thumbnail(key) - { - auto productKey = azrtti_cast(m_key.data()); - AZ_Assert(productKey, "Incorrect key type, excpected ProductThumbnailKey"); - - bool multiMat = false; - MaterialBrowserRequestBus::BroadcastResult(multiMat, &MaterialBrowserRequests::IsMultiMaterial, productKey->GetAssetId()); - - QString iconPath = multiMat ? MultiMaterialIconPath : SimpleMaterialIconPath; - m_pixmap.load(iconPath); - m_state = m_pixmap.isNull() ? State::Failed : State::Ready; - } - - ////////////////////////////////////////////////////////////////////////// - // MaterialThumbnailCache - ////////////////////////////////////////////////////////////////////////// - MaterialThumbnailCache::MaterialThumbnailCache() - : ThumbnailCache() {} - - MaterialThumbnailCache::~MaterialThumbnailCache() = default; - - int MaterialThumbnailCache::GetPriority() const - { - return 1; - } - - const char* MaterialThumbnailCache::GetProviderName() const - { - return ProviderName; - } - - bool MaterialThumbnailCache::IsSupportedThumbnail(Thumbnailer::SharedThumbnailKey key) const - { - return azrtti_istypeof(key.data()); - } - - } // namespace MaterialBrowser -} // namespace AzToolsFramework - -#include "MaterialBrowser/moc_MaterialThumbnail.cpp" diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialThumbnail.h b/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialThumbnail.h deleted file mode 100644 index 60a2bb11e5..0000000000 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialThumbnail.h +++ /dev/null @@ -1,86 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#if !defined(Q_MOC_RUN) -#include -#include -#include -#endif - -namespace AzToolsFramework -{ - namespace MaterialBrowser - { - //! Material Browser uses only 2 thumbnails: simple and multimaterial - class MaterialThumbnail - : public Thumbnailer::Thumbnail - { - Q_OBJECT - public: - MaterialThumbnail(Thumbnailer::SharedThumbnailKey key); - }; - - namespace - { - class MaterialKeyHash - { - public: - size_t operator()(const Thumbnailer::SharedThumbnailKey& /*val*/) const - { - return 0; // there is only 2 thumbnails in this cache - } - }; - - class MaterialKeyEqual - { - public: - bool operator()(const Thumbnailer::SharedThumbnailKey& val1, const Thumbnailer::SharedThumbnailKey& val2) const - { - auto productThumbnailKey1 = azrtti_cast(val1.data()); - auto productThumbnailKey2 = azrtti_cast(val2.data()); - if (!productThumbnailKey1 || !productThumbnailKey2) - { - return false; - } - - // check whether keys point to single or multimaterial asset type - bool multiMat1 = false; - bool multiMat2 = false; - MaterialBrowserRequestBus::BroadcastResult(multiMat1, &MaterialBrowserRequests::IsMultiMaterial, productThumbnailKey1->GetAssetId()); - MaterialBrowserRequestBus::BroadcastResult(multiMat2, &MaterialBrowserRequests::IsMultiMaterial, productThumbnailKey2->GetAssetId()); - return multiMat1 == multiMat2; - } - }; - } - - //! MaterialBrowserEntry thumbnails - class MaterialThumbnailCache - : public Thumbnailer::ThumbnailCache - { - public: - MaterialThumbnailCache(); - ~MaterialThumbnailCache() override; - - int GetPriority() const override; - const char* GetProviderName() const override; - - static constexpr const char* ProviderName = "CryMaterial Thumbnails"; - - protected: - bool IsSupportedThumbnail(Thumbnailer::SharedThumbnailKey key) const override; - }; - } // namespace MaterialBrowser -} // namespace AzToolsFramework - - diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/aztoolsframework_files.cmake b/Code/Framework/AzToolsFramework/AzToolsFramework/aztoolsframework_files.cmake index 4cf121c517..a7fcf2e711 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/aztoolsframework_files.cmake +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/aztoolsframework_files.cmake @@ -70,11 +70,6 @@ set(FILES AssetCatalog/PlatformAddressedAssetCatalog.cpp AssetCatalog/PlatformAddressedAssetCatalogManager.h AssetCatalog/PlatformAddressedAssetCatalogManager.cpp - MaterialBrowser/MaterialBrowserBus.h - MaterialBrowser/MaterialBrowserComponent.cpp - MaterialBrowser/MaterialBrowserComponent.h - MaterialBrowser/MaterialThumbnail.cpp - MaterialBrowser/MaterialThumbnail.h Thumbnails/ThumbnailerComponent.cpp Thumbnails/ThumbnailerComponent.h Thumbnails/LoadingThumbnail.cpp diff --git a/Code/Sandbox/Editor/Controls/PreviewModelCtrl.cpp b/Code/Sandbox/Editor/Controls/PreviewModelCtrl.cpp index 5746e9db2f..9b07f59e6a 100644 --- a/Code/Sandbox/Editor/Controls/PreviewModelCtrl.cpp +++ b/Code/Sandbox/Editor/Controls/PreviewModelCtrl.cpp @@ -365,10 +365,6 @@ bool CPreviewModelCtrl::Render() } _smart_ptr pMaterial; - if (m_pCurrentMaterial) - { - pMaterial = m_pCurrentMaterial->GetMatInfo(); - } if (m_bPrecacheMaterial) { @@ -430,11 +426,6 @@ bool CPreviewModelCtrl::Render() m_pRenderer->EF_ADDDlight(&m_lights[i], passInfo); } - if (m_pCurrentMaterial) - { - m_pCurrentMaterial->DisableHighlightForFrame(); - } - if (m_bShowObject) { RenderObject(pMaterial, passInfo); @@ -778,32 +769,6 @@ void CPreviewModelCtrl::SetRotation(bool bEnable) m_bRotate = bEnable; } -void CPreviewModelCtrl::SetMaterial(CMaterial* pMaterial) -{ - if (pMaterial) - { - if ((pMaterial->GetFlags() & MTL_FLAG_NOPREVIEW)) - { - m_pCurrentMaterial = 0; - if (isVisible()) - { - update(); - } - return; - } - } - m_pCurrentMaterial = pMaterial; - if (isVisible()) - { - update(); - } -} - -CMaterial* CPreviewModelCtrl::GetMaterial() -{ - return m_pCurrentMaterial; -} - void CPreviewModelCtrl::OnEditorNotifyEvent(EEditorNotifyEvent event) { switch (event) diff --git a/Code/Sandbox/Editor/Controls/PreviewModelCtrl.h b/Code/Sandbox/Editor/Controls/PreviewModelCtrl.h index 73839612af..6388be9fd5 100644 --- a/Code/Sandbox/Editor/Controls/PreviewModelCtrl.h +++ b/Code/Sandbox/Editor/Controls/PreviewModelCtrl.h @@ -22,8 +22,6 @@ #include -#include - #endif struct IRenderNode; @@ -71,9 +69,6 @@ public: int heightForWidth(int w) const override; bool hasHeightForWidth() const override; - void SetMaterial(CMaterial* pMaterial); - CMaterial* GetMaterial(); - void GetImageOffscreen(CImageEx& image, const QSize& customSize = QSize(0, 0)); void GetCameraTM(Matrix34& cameraTM); @@ -192,7 +187,6 @@ protected: float m_tileY; float m_tileSizeX; float m_tileSizeY; - _smart_ptr m_pCurrentMaterial; CameraChangeCallback m_cameraChangeCallback; void* m_pCameraChangeUserData; diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyCtrl.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyCtrl.cpp index c21aff046e..f0367ffdc1 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyCtrl.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyCtrl.cpp @@ -29,7 +29,6 @@ void RegisterReflectedVarHandlers() EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew AnimationPropertyWidgetHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew FileResourceSelectorWidgetHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew ShaderPropertyHandler()); - EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew MaterialPropertyHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew ReverbPresetPropertyHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew SequencePropertyHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew SequenceIdPropertyHandler()); diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.cpp index 3d17e77bb0..75344b2172 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.cpp @@ -27,7 +27,6 @@ // Editor #include "ShadersDialog.h" -#include "Material/MaterialManager.h" #include "SelectLightAnimationDialog.h" #include "SelectSequenceDialog.h" #include "SelectEAXPresetDlg.h" @@ -88,25 +87,6 @@ void ShaderPropertyEditor::onEditClicked() } } -void MaterialPropertyEditor::onEditClicked() -{ -} - -void MaterialPropertyEditor::onButton2Clicked() -{ - // Open material browser dialog. - IDataBaseItem *pItem = GetIEditor()->GetMaterialManager()->GetSelectedItem(); - if (pItem) - { - QString value = pItem->GetName(); - value.replace('\\', '/'); - if (value.length() >= MAX_PATH) - value = value.left(MAX_PATH); - SetValue(value); - } - else - SetValue(QString()); -} void ReverbPresetPropertyEditor::onEditClicked() { diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.h b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.h index d5ec0045c4..cdbb18ae12 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.h +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.h @@ -109,16 +109,6 @@ public: void onEditClicked() override; }; -class MaterialPropertyEditor - : public GenericPopupPropertyEditor -{ -public: - MaterialPropertyEditor(QWidget* pParent = nullptr) - : GenericPopupPropertyEditor(pParent, true){} - void onEditClicked() override; - void onButton2Clicked() override; -}; - class ReverbPresetPropertyEditor : public GenericPopupPropertyEditor { @@ -179,7 +169,6 @@ public: #define CONST_AZ_CRC(name, value) AZ::u32(value) using ShaderPropertyHandler = GenericPopupWidgetHandler; -using MaterialPropertyHandler = GenericPopupWidgetHandler; using ReverbPresetPropertyHandler = GenericPopupWidgetHandler; using MissionObjPropertyHandler = GenericPopupWidgetHandler; using SequencePropertyHandler = GenericPopupWidgetHandler; diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyResourceCtrl.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyResourceCtrl.cpp index a66a73eaa4..e698b86341 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyResourceCtrl.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyResourceCtrl.cpp @@ -111,14 +111,12 @@ private: { case ePropertyTexture: case ePropertyModel: - case ePropertyMaterial: newPath.replace("\\\\", "/"); } switch (m_propertyType) { case ePropertyTexture: case ePropertyModel: - case ePropertyMaterial: case ePropertyFile: if (newPath.size() > MAX_PATH) { diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.cpp index 92610021b9..a188ee117b 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.cpp @@ -361,16 +361,6 @@ void ReflectedPropertyControl::CreateItems(XmlNodeRef node, CVarBlockPtr& outBlo textureVar->Set(textureName); } } - else if (!azstricmp(type, "material")) - { - CSmartVariable materialVar; - AddVariable(group, materialVar, child->getTag(), humanReadableName.toUtf8().data(), strDescription.toUtf8().data(), func, pUserData, IVariable::DT_MATERIAL); - const char* materialName; - if (child->getAttr("value", &materialName)) - { - materialVar->Set(materialName); - } - } else if (!azstricmp(type, "color")) { CSmartVariable colorVar; diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp index 055fc26a15..13584d9b82 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp @@ -269,7 +269,6 @@ void ReflectedPropertyItem::SetVariable(IVariable *var) m_reflectedVarAdapter = new ReflectedVarUserAdapter; break; case ePropertyShader: - case ePropertyMaterial: case ePropertyEquip: case ePropertyReverbPreset: case ePropertyGameToken: @@ -576,7 +575,6 @@ void ReflectedPropertyItem::SetValue(const QString& sValue, bool bRecordUndo, bo case ePropertyTexture: case ePropertyModel: - case ePropertyMaterial: value.replace('\\', '/'); break; } @@ -586,7 +584,6 @@ void ReflectedPropertyItem::SetValue(const QString& sValue, bool bRecordUndo, bo { case ePropertyTexture: case ePropertyModel: - case ePropertyMaterial: case ePropertyFile: if (value.length() >= MAX_PATH) { diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVar.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVar.cpp index a805c07a2f..12165d2be8 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVar.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVar.cpp @@ -286,8 +286,6 @@ AZ::u32 CReflectedVarGenericProperty::handler() { case ePropertyShader: return AZ_CRC("ePropertyShader", 0xc40932f1); - case ePropertyMaterial: - return AZ_CRC("ePropertyMaterial", 0xf324dffa); case ePropertyEquip: return AZ_CRC("ePropertyEquip", 0x66ffd290); case ePropertyReverbPreset: diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVarWrapper.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVarWrapper.cpp index 84a7f8c26f..b2fc07073f 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVarWrapper.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVarWrapper.cpp @@ -455,8 +455,6 @@ void ReflectedVarGenericPropertyAdapter::SyncReflectedVarToIVar(IVariable *pVari { QString value; pVariable->Get(value); - if (m_reflectedVar->m_propertyType == ePropertyMaterial) - value.replace('\\', '/'); m_reflectedVar->m_value = value.toUtf8().data(); } diff --git a/Code/Sandbox/Editor/CryEdit.cpp b/Code/Sandbox/Editor/CryEdit.cpp index e118104687..44f328b309 100644 --- a/Code/Sandbox/Editor/CryEdit.cpp +++ b/Code/Sandbox/Editor/CryEdit.cpp @@ -102,7 +102,6 @@ AZ_POP_DISABLE_WARNING #include "ModelViewport.h" #include "FileTypeUtils.h" #include "PluginManager.h" -#include "Material/MaterialManager.h" #include "IEditorImpl.h" #include "StartupLogoDialog.h" @@ -459,9 +458,6 @@ void CCryEditApp::RegisterActionHandlers() ON_COMMAND(ID_CHANGEMOVESPEED_INCREASE, OnChangemovespeedIncrease) ON_COMMAND(ID_CHANGEMOVESPEED_DECREASE, OnChangemovespeedDecrease) ON_COMMAND(ID_CHANGEMOVESPEED_CHANGESTEP, OnChangemovespeedChangestep) - ON_COMMAND(ID_MATERIAL_ASSIGNCURRENT, OnMaterialAssigncurrent) - ON_COMMAND(ID_MATERIAL_RESETTODEFAULT, OnMaterialResettodefault) - ON_COMMAND(ID_MATERIAL_GETMATERIAL, OnMaterialGetmaterial) ON_COMMAND(ID_FILE_SAVELEVELRESOURCES, OnFileSavelevelresources) ON_COMMAND(ID_CLEAR_REGISTRY, OnClearRegistryData) ON_COMMAND(ID_VALIDATELEVEL, OnValidatelevel) @@ -4180,25 +4176,6 @@ void CCryEditApp::OnSwitchcameraNext() } } -////////////////////////////////////////////////////////////////////////// -void CCryEditApp::OnMaterialAssigncurrent() -{ - CUndo undo("Assign Material To Selection"); - GetIEditor()->GetMaterialManager()->Command_AssignToSelection(); -} - -////////////////////////////////////////////////////////////////////////// -void CCryEditApp::OnMaterialResettodefault() -{ - GetIEditor()->GetMaterialManager()->Command_ResetSelection(); -} - -////////////////////////////////////////////////////////////////////////// -void CCryEditApp::OnMaterialGetmaterial() -{ - GetIEditor()->GetMaterialManager()->Command_SelectFromObject(); -} - ////////////////////////////////////////////////////////////////////////// void CCryEditApp::OnOpenAssetBrowserView() { diff --git a/Code/Sandbox/Editor/CryEdit.h b/Code/Sandbox/Editor/CryEdit.h index 8c0c4bd59b..bce7f0c90d 100644 --- a/Code/Sandbox/Editor/CryEdit.h +++ b/Code/Sandbox/Editor/CryEdit.h @@ -417,9 +417,6 @@ private: void OnChangemovespeedIncrease(); void OnChangemovespeedDecrease(); void OnChangemovespeedChangestep(); - void OnMaterialAssigncurrent(); - void OnMaterialResettodefault(); - void OnMaterialGetmaterial(); void OnFileSavelevelresources(); void OnClearRegistryData(); void OnValidatelevel(); diff --git a/Code/Sandbox/Editor/CryEditDoc.cpp b/Code/Sandbox/Editor/CryEditDoc.cpp index 41c49ab026..c144d93c46 100644 --- a/Code/Sandbox/Editor/CryEditDoc.cpp +++ b/Code/Sandbox/Editor/CryEditDoc.cpp @@ -51,7 +51,6 @@ #include "CryEdit.h" #include "ActionManager.h" #include "Include/IObjectManager.h" -#include "Material/MaterialManager.h" #include "ErrorReportDialog.h" #include "SurfaceTypeValidator.h" #include "ShaderCache.h" @@ -357,8 +356,6 @@ void CCryEditDoc::Save(TDocMultiArchive& arrXmlAr) SerializeFogSettings((*arrXmlAr[DMAS_GENERAL])); // Serialize Missions ////////////////////////////////////////////////// SerializeMissions(arrXmlAr, currentMissionName, false); - //! Serialize material manager. - GetIEditor()->GetMaterialManager()->Serialize((*arrXmlAr[DMAS_GENERAL]).root, (*arrXmlAr[DMAS_GENERAL]).bLoading); SerializeShaderCache((*arrXmlAr[DMAS_GENERAL_NAMED_DATA])); SerializeNameSelection((*arrXmlAr[DMAS_GENERAL])); @@ -513,14 +510,6 @@ void CCryEditDoc::Load(TDocMultiArchive& arrXmlAr, const QString& szFilename) ////////////////////////////////////////////////////////////////////////// (*arrXmlAr[DMAS_GENERAL]).root->getAttr("WaterColor", m_waterColor); - ////////////////////////////////////////////////////////////////////////// - // Load materials. - ////////////////////////////////////////////////////////////////////////// - { - CAutoLogTime logtime("Load MaterialManager"); - GetIEditor()->GetMaterialManager()->Serialize((*arrXmlAr[DMAS_GENERAL]).root, (*arrXmlAr[DMAS_GENERAL]).bLoading); - } - ////////////////////////////////////////////////////////////////////////// // Load View Settings ////////////////////////////////////////////////////////////////////////// diff --git a/Code/Sandbox/Editor/DisplaySettings.cpp b/Code/Sandbox/Editor/DisplaySettings.cpp index bd4372ae70..75e5c54ae9 100644 --- a/Code/Sandbox/Editor/DisplaySettings.cpp +++ b/Code/Sandbox/Editor/DisplaySettings.cpp @@ -22,7 +22,6 @@ // Editor #include "Settings.h" -#include "Material/MaterialManager.h" @@ -112,30 +111,6 @@ void CDisplaySettings::SetDebugFlags(int flags) //SetCVarInt( "sys_enable_budgetmonitoring",(m_debugFlags&DBG_BUDGET_MONITORING) ? 4:0 ); //SetCVarInt( "Profile",(m_debugFlags&DBG_FRAMEPROFILE) ? 1:0 ); - - if (CMaterialManager* pMaterialManager = GetIEditor()->GetMaterialManager()) - { - int mask = pMaterialManager->GetHighlightMask(); - if (m_debugFlags & DBG_HIGHLIGHT_BREAKABLE) - { - mask |= eHighlight_Breakable; - } - else - { - mask &= ~eHighlight_Breakable; - } - - if (m_debugFlags & DBG_HIGHLIGHT_MISSING_SURFACE_TYPE) - { - mask |= eHighlight_NoSurfaceType; - } - else - { - mask &= ~eHighlight_NoSurfaceType; - } - - pMaterialManager->SetHighlightMask(mask); - } } ////////////////////////////////////////////////////////////////////////// diff --git a/Code/Sandbox/Editor/EditorToolsApplication.cpp b/Code/Sandbox/Editor/EditorToolsApplication.cpp index 97caaf612a..2e3d70795a 100644 --- a/Code/Sandbox/Editor/EditorToolsApplication.cpp +++ b/Code/Sandbox/Editor/EditorToolsApplication.cpp @@ -21,14 +21,12 @@ #include #include #include -#include // Editor #include "MainWindow.h" #include "CryEdit.h" #include "DisplaySettingsPythonFuncs.h" #include "GameEngine.h" -#include "Material/MaterialPythonFuncs.h" #include "PythonEditorFuncs.h" #include "TrackView/TrackViewPythonFuncs.h" #include "Include/IObjectManager.h" @@ -65,7 +63,6 @@ namespace EditorInternal RegisterComponentDescriptor(AzToolsFramework::DisplaySettingsPythonFuncsHandler::CreateDescriptor()); RegisterComponentDescriptor(AzToolsFramework::MainWindowEditorFuncsHandler::CreateDescriptor()); RegisterComponentDescriptor(AzToolsFramework::ObjectManagerFuncsHandler::CreateDescriptor()); - RegisterComponentDescriptor(AzToolsFramework::MaterialPythonFuncsHandler::CreateDescriptor()); RegisterComponentDescriptor(AzToolsFramework::PythonEditorComponent::CreateDescriptor()); RegisterComponentDescriptor(AzToolsFramework::PythonEditorFuncsHandler::CreateDescriptor()); RegisterComponentDescriptor(AzToolsFramework::DisplaySettingsComponent::CreateDescriptor()); @@ -81,7 +78,6 @@ namespace EditorInternal components.emplace_back(azrtti_typeid()); components.emplace_back(azrtti_typeid()); - components.emplace_back(azrtti_typeid()); // Add new Bus-based Python Bindings components.emplace_back(azrtti_typeid()); diff --git a/Code/Sandbox/Editor/ErrorReport.h b/Code/Sandbox/Editor/ErrorReport.h index f78410be62..b13f8ae120 100644 --- a/Code/Sandbox/Editor/ErrorReport.h +++ b/Code/Sandbox/Editor/ErrorReport.h @@ -19,7 +19,6 @@ #pragma once // forward declarations. -class CMaterial; class CParticleItem; #include "BaseLibraryItem.h" diff --git a/Code/Sandbox/Editor/Export/ExportManager.cpp b/Code/Sandbox/Editor/Export/ExportManager.cpp index b41872595a..638977b191 100644 --- a/Code/Sandbox/Editor/Export/ExportManager.cpp +++ b/Code/Sandbox/Editor/Export/ExportManager.cpp @@ -23,7 +23,6 @@ // Editor #include "Geometry/EdGeometry.h" -#include "Material/Material.h" #include "ViewManager.h" #include "OBJExporter.h" #include "OCMExporter.h" @@ -79,47 +78,6 @@ Export::CMesh::CMesh() } -void Export::CMesh::SetMaterial(CMaterial* pMtl, CBaseObject* pBaseObj) -{ - if (!pMtl) - { - cry_strcpy(material.name, pBaseObj->GetName().toUtf8().data()); - return; - } - - cry_strcpy(material.name, pMtl->GetFullName().toUtf8().data()); - - _smart_ptr matInfo = pMtl->GetMatInfo(); - IRenderShaderResources* pRes = matInfo->GetShaderItem().m_pShaderResources; - if (!pRes) - { - return; - } - - ColorF difColor = pRes->GetColorValue(EFTT_DIFFUSE); - material.diffuse.r = difColor.r; - material.diffuse.g = difColor.g; - material.diffuse.b = difColor.b; - material.diffuse.a = difColor.a; - - ColorF specColor = pRes->GetColorValue(EFTT_SPECULAR); - material.specular.r = specColor.r; - material.specular.g = specColor.g; - material.specular.b = specColor.b; - material.specular.a = specColor.a; - - material.opacity = pRes->GetStrengthValue(EFTT_OPACITY); - material.smoothness = pRes->GetStrengthValue(EFTT_SMOOTHNESS); - - SetTexture(material.mapDiffuse, pRes, EFTT_DIFFUSE); - SetTexture(material.mapSpecular, pRes, EFTT_SPECULAR); - SetTexture(material.mapOpacity, pRes, EFTT_OPACITY); - SetTexture(material.mapNormals, pRes, EFTT_NORMALS); - SetTexture(material.mapDecal, pRes, EFTT_DECAL_OVERLAY); - SetTexture(material.mapDisplacement, pRes, EFTT_HEIGHT); -} - - ////////////////////////////////////////////////////////// // CObject Export::CObject::CObject(const char* pName) @@ -416,18 +374,6 @@ void CExportManager::AddMesh(Export::CObject* pObj, const IIndexedMesh* pIndMesh pObj->m_texCoords.push_back(tc); } - CMaterial* pMtl = 0; - - if (m_pBaseObj) - { - pMtl = m_pBaseObj->GetRenderMaterial(); - } - - if (pMtl) - { - pObj->SetMaterialName(pMtl->GetFullName().toUtf8().data()); - } - if (pIndMesh->GetSubSetCount() && !(pIndMesh->GetSubSetCount() == 1 && pIndMesh->GetSubSet(0).nNumIndices == 0)) { for (int i = 0; i < pIndMesh->GetSubSetCount(); ++i) @@ -447,23 +393,6 @@ void CExportManager::AddMesh(Export::CObject* pObj, const IIndexedMesh* pIndMesh pMesh->m_faces.push_back(face); } - if (pMtl) - { - if (pMtl->IsMultiSubMaterial()) - { - CMaterial* pSubMtl = 0; - if (sms.nMatID < pMtl->GetSubMaterialCount()) - { - pSubMtl = pMtl->GetSubMaterial(sms.nMatID); - } - pMesh->SetMaterial(pSubMtl, m_pBaseObj); - } - else - { - pMesh->SetMaterial(pMtl, m_pBaseObj); - } - } - pObj->m_meshes.push_back(pMesh); } } @@ -497,10 +426,6 @@ void CExportManager::AddMesh(Export::CObject* pObj, const IIndexedMesh* pIndMesh } } - if (m_pBaseObj && pMtl) - { - pMesh->SetMaterial(pMtl, m_pBaseObj); - } pObj->m_meshes.push_back(pMesh); } } diff --git a/Code/Sandbox/Editor/Export/ExportManager.h b/Code/Sandbox/Editor/Export/ExportManager.h index 8904ef08ed..a27e54b085 100644 --- a/Code/Sandbox/Editor/Export/ExportManager.h +++ b/Code/Sandbox/Editor/Export/ExportManager.h @@ -43,8 +43,6 @@ namespace Export virtual int GetFaceCount() const { return m_faces.size(); } virtual const Face* GetFaceBuffer() const { return m_faces.size() ? &m_faces[0] : 0; } - void SetMaterial(CMaterial* pMtl, CBaseObject* pBaseObj); - private: std::vector m_faces; diff --git a/Code/Sandbox/Editor/GameExporter.cpp b/Code/Sandbox/Editor/GameExporter.cpp index 8f0b6f6d0f..64e1fc6514 100644 --- a/Code/Sandbox/Editor/GameExporter.cpp +++ b/Code/Sandbox/Editor/GameExporter.cpp @@ -27,8 +27,6 @@ #include "Mission.h" #include "ShaderCache.h" #include "UsedResources.h" -#include "Material/MaterialManager.h" -#include "Material/MaterialLibrary.h" #include "WaitProgress.h" #include "Util/CryMemFile.h" #include "Objects/ObjectManager.h" @@ -336,11 +334,6 @@ void CGameExporter::ExportLevelData(const QString& path, bool bExportMission) ExportMapInfo(root); - ////////////////////////////////////////////////////////////////////////// - // Export materials. - ExportMaterials(root, path); - ////////////////////////////////////////////////////////////////////////// - CCryEditDoc* pDocument = pEditor->GetDocument(); CMission* pCurrentMission = 0; @@ -508,48 +501,6 @@ void CGameExporter::ExportMapInfo(XmlNodeRef& node) xmlAr.root = node; } -////////////////////////////////////////////////////////////////////////// -void CGameExporter::ExportMaterials(XmlNodeRef& levelDataNode, const QString& path) -{ - ////////////////////////////////////////////////////////////////////////// - // Export materials manager. - CMaterialManager* pManager = GetIEditor()->GetMaterialManager(); - pManager->Export(levelDataNode); - - QString filename = Path::Make(path, MATERIAL_LEVEL_LIBRARY_FILE); - - bool bHaveItems = true; - - int numMtls = 0; - - XmlNodeRef nodeMaterials = XmlHelpers::CreateXmlNode("MaterialsLibrary"); - // Export Materials local level library. - for (int i = 0; i < pManager->GetLibraryCount(); i++) - { - XmlNodeRef nodeLib = nodeMaterials->newChild("Library"); - CMaterialLibrary* pLib = (CMaterialLibrary*)pManager->GetLibrary(i); - if (pLib->GetItemCount() > 0) - { - bHaveItems = false; - // Export this library. - numMtls += pManager->ExportLib(pLib, nodeLib); - } - } - if (!bHaveItems) - { - XmlString xmlData = nodeMaterials->getXML(); - - CCryMemFile file; - file.Write(xmlData.c_str(), xmlData.length()); - m_levelPak.m_pakFile.UpdateFile(filename.toUtf8().data(), file); - } - else - { - m_levelPak.m_pakFile.RemoveFile(filename.toUtf8().data()); - } - m_numExportedMaterials = numMtls; -} - ////////////////////////////////////////////////////////////////////////// void CGameExporter::ExportLevelResourceList(const QString& path) { diff --git a/Code/Sandbox/Editor/GameExporter.h b/Code/Sandbox/Editor/GameExporter.h index 52731a7000..a428046f0a 100644 --- a/Code/Sandbox/Editor/GameExporter.h +++ b/Code/Sandbox/Editor/GameExporter.h @@ -98,7 +98,6 @@ private: void ExportLevelResourceList(const QString& path); void ExportLevelUsedResourceList(const QString& path); void ExportLevelShaderCache(const QString& path); - void ExportMaterials(XmlNodeRef& levelDataNode, const QString& path); void ExportGameData(const QString& path); void ExportFileList(const QString& path, const QString& levelName); diff --git a/Code/Sandbox/Editor/GameResourcesExporter.cpp b/Code/Sandbox/Editor/GameResourcesExporter.cpp index 564396d090..8a6c547dca 100644 --- a/Code/Sandbox/Editor/GameResourcesExporter.cpp +++ b/Code/Sandbox/Editor/GameResourcesExporter.cpp @@ -21,7 +21,6 @@ // Editor #include "UsedResources.h" #include "GameEngine.h" -#include "Material/MaterialManager.h" #include "Include/IObjectManager.h" #include "WaitProgress.h" @@ -51,7 +50,7 @@ void CGameResourcesExporter::ChooseDirectory() void CGameResourcesExporter::GatherAllLoadedResources() { m_files.clear(); - m_files.reserve(100000); // count from GetResourceList, GetFilesFromObjects, GetFilesFromMaterials ... is unknown + m_files.reserve(100000); // count from GetResourceList, GetFilesFromObjects ... is unknown auto pResList = gEnv->pCryPak->GetResourceList(AZ::IO::IArchive::RFOM_Level); { @@ -62,7 +61,6 @@ void CGameResourcesExporter::GatherAllLoadedResources() } GetFilesFromObjects(); - GetFilesFromMaterials(); } ////////////////////////////////////////////////////////////////////////// @@ -158,12 +156,3 @@ void CGameResourcesExporter::GetFilesFromObjects() Append(m_files, rs.files); } - -////////////////////////////////////////////////////////////////////////// -void CGameResourcesExporter::GetFilesFromMaterials() -{ - CUsedResources rs; - GetIEditor()->GetMaterialManager()->GatherUsedResources(rs); - Append(m_files, rs.files); -} - diff --git a/Code/Sandbox/Editor/GameResourcesExporter.h b/Code/Sandbox/Editor/GameResourcesExporter.h index b408cbb42f..8236458cb3 100644 --- a/Code/Sandbox/Editor/GameResourcesExporter.h +++ b/Code/Sandbox/Editor/GameResourcesExporter.h @@ -44,7 +44,6 @@ private: void GetFilesFromObjects(); void GetFilesFromVarBlock(CVarBlock* pVB); void GetFilesFromVariable(IVariable* pVar); - void GetFilesFromMaterials(); }; #endif // CRYINCLUDE_EDITOR_GAMERESOURCESEXPORTER_H diff --git a/Code/Sandbox/Editor/IEditor.h b/Code/Sandbox/Editor/IEditor.h index 838f48573d..c03b99e128 100644 --- a/Code/Sandbox/Editor/IEditor.h +++ b/Code/Sandbox/Editor/IEditor.h @@ -46,9 +46,7 @@ class CGameEngine; struct IIconManager; class CToolBoxManager; class CClassFactory; -class CMaterialManager; class CMusicManager; -class CMaterail; struct IEditorParticleManager; class CEAXPresetManager; class CErrorReport; @@ -544,8 +542,6 @@ struct IEditor virtual CSettingsManager* GetSettingsManager() = 0; //! Get DB manager that own items of specified type. virtual IDataBaseManager* GetDBItemManager(EDataBaseItemType itemType) = 0; - //! Get Manager of Materials. - virtual CMaterialManager* GetMaterialManager() = 0; virtual IBaseLibraryManager* GetMaterialManagerLibrary() = 0; // Vladimir@conffx virtual IEditorMaterialManager* GetIEditorMaterialManager() = 0; // Vladimir@Conffx //! Returns IconManager. diff --git a/Code/Sandbox/Editor/IEditorImpl.cpp b/Code/Sandbox/Editor/IEditorImpl.cpp index 060bf41189..61d24db90c 100644 --- a/Code/Sandbox/Editor/IEditorImpl.cpp +++ b/Code/Sandbox/Editor/IEditorImpl.cpp @@ -53,7 +53,6 @@ AZ_POP_DISABLE_WARNING #include "KeyboardCustomizationSettings.h" #include "Export/ExportManager.h" #include "LevelIndependentFileMan.h" -#include "Material/MaterialManager.h" #include "TrackView/TrackViewSequenceManager.h" #include "AnimationContext.h" #include "GameEngine.h" @@ -167,7 +166,6 @@ CEditorImpl::CEditorImpl() , m_pAnimationContext(nullptr) , m_pSequenceManager(nullptr) , m_pToolBoxManager(nullptr) - , m_pMaterialManager(nullptr) , m_pMusicManager(nullptr) , m_pErrorReport(nullptr) , m_pLasLoadedLevelErrorReport(nullptr) @@ -222,7 +220,6 @@ CEditorImpl::CEditorImpl() m_pIconManager = new CIconManager; m_pUndoManager = new CUndoManager; m_pToolBoxManager = new CToolBoxManager; - m_pMaterialManager = new CMaterialManager(regCtx); m_pAlembicCompiler = new CAlembicCompiler(); m_pSequenceManager = new CTrackViewSequenceManager; m_pAnimationContext = new CAnimationContext; @@ -342,7 +339,6 @@ CEditorImpl::~CEditorImpl() m_bExiting = true; // Can't save level after this point (while Crash) SAFE_RELEASE(m_pSourceControl); - SAFE_DELETE(m_pMaterialManager) SAFE_DELETE(m_pAlembicCompiler) SAFE_DELETE(m_pIconManager) SAFE_DELETE(m_pViewManager) @@ -412,7 +408,6 @@ void CEditorImpl::SetGameEngine(CGameEngine* ge) m_pObjectManager->LoadClassTemplates("Editor"); m_pObjectManager->RegisterCVars(); - m_pMaterialManager->Set3DEngine(); m_pAnimationContext->Init(); } @@ -1000,13 +995,8 @@ void CEditorImpl::CloseView(const GUID& classId) } } -IDataBaseManager* CEditorImpl::GetDBItemManager(EDataBaseItemType itemType) +IDataBaseManager* CEditorImpl::GetDBItemManager([[maybe_unused]] EDataBaseItemType itemType) { - switch (itemType) - { - case EDB_TYPE_MATERIAL: - return m_pMaterialManager; - } return 0; } @@ -1772,13 +1762,13 @@ SEditorSettings* CEditorImpl::GetEditorSettings() // Vladimir@Conffx IBaseLibraryManager* CEditorImpl::GetMaterialManagerLibrary() { - return m_pMaterialManager; + return nullptr; } // Vladimir@Conffx IEditorMaterialManager* CEditorImpl::GetIEditorMaterialManager() { - return m_pMaterialManager; + return nullptr; } IImageUtil* CEditorImpl::GetImageUtil() diff --git a/Code/Sandbox/Editor/IEditorImpl.h b/Code/Sandbox/Editor/IEditorImpl.h index 3c440dd5fc..d17a94807f 100644 --- a/Code/Sandbox/Editor/IEditorImpl.h +++ b/Code/Sandbox/Editor/IEditorImpl.h @@ -180,7 +180,6 @@ public: bool IsSelectionLocked(); IDataBaseManager* GetDBItemManager(EDataBaseItemType itemType); - CMaterialManager* GetMaterialManager() { return m_pMaterialManager; } CMusicManager* GetMusicManager() { return m_pMusicManager; }; IBackgroundTaskManager* GetBackgroundTaskManager() override; @@ -379,7 +378,6 @@ protected: CAnimationContext* m_pAnimationContext; CTrackViewSequenceManager* m_pSequenceManager; CToolBoxManager* m_pToolBoxManager; - CMaterialManager* m_pMaterialManager; CAlembicCompiler* m_pAlembicCompiler; CMusicManager* m_pMusicManager; CErrorReport* m_pErrorReport; diff --git a/Code/Sandbox/Editor/Include/IErrorReport.h b/Code/Sandbox/Editor/Include/IErrorReport.h index 8afe269324..f25a1163a3 100644 --- a/Code/Sandbox/Editor/Include/IErrorReport.h +++ b/Code/Sandbox/Editor/Include/IErrorReport.h @@ -21,7 +21,6 @@ #include // forward declarations. -class CMaterial; class CParticleItem; class CBaseObject; class CBaseLibraryItem; diff --git a/Code/Sandbox/Editor/LevelInfo.cpp b/Code/Sandbox/Editor/LevelInfo.cpp index 4b8a6d5cac..81441a3797 100644 --- a/Code/Sandbox/Editor/LevelInfo.cpp +++ b/Code/Sandbox/Editor/LevelInfo.cpp @@ -20,7 +20,6 @@ // Editor #include "Util/fastlib.h" -#include "Material/MaterialManager.h" // for CMaterialManager #include @@ -67,7 +66,6 @@ void CLevelInfo::Validate() // Validate level. ValidateObjects(); - ValidateMaterials(); if (m_pReport->GetErrorCount() == 0) { @@ -186,11 +184,3 @@ void CLevelInfo::ValidateObjects() } } } - -////////////////////////////////////////////////////////////////////////// -void CLevelInfo::ValidateMaterials() -{ - // Validate all objects - CBaseObjectsArray objects; - GetIEditor()->GetMaterialManager()->Validate(); -} diff --git a/Code/Sandbox/Editor/LevelInfo.h b/Code/Sandbox/Editor/LevelInfo.h index 0611ad652e..515a21886e 100644 --- a/Code/Sandbox/Editor/LevelInfo.h +++ b/Code/Sandbox/Editor/LevelInfo.h @@ -27,7 +27,6 @@ public: private: void ValidateObjects(); - void ValidateMaterials(); IErrorReport* m_pReport; }; diff --git a/Code/Sandbox/Editor/Lib/Tests/IEditorMock.h b/Code/Sandbox/Editor/Lib/Tests/IEditorMock.h index 45810da2cf..6659e41122 100644 --- a/Code/Sandbox/Editor/Lib/Tests/IEditorMock.h +++ b/Code/Sandbox/Editor/Lib/Tests/IEditorMock.h @@ -91,7 +91,6 @@ public: MOCK_METHOD0(GetObjectManager, struct IObjectManager* ()); MOCK_METHOD0(GetSettingsManager, CSettingsManager* ()); MOCK_METHOD1(GetDBItemManager, IDataBaseManager* (EDataBaseItemType)); - MOCK_METHOD0(GetMaterialManager, CMaterialManager* ()); MOCK_METHOD0(GetMaterialManagerLibrary, IBaseLibraryManager* ()); MOCK_METHOD0(GetIEditorMaterialManager, IEditorMaterialManager* ()); MOCK_METHOD0(GetIconManager, IIconManager* ()); diff --git a/Code/Sandbox/Editor/Lib/Tests/test_MaterialPythonFuncs.cpp b/Code/Sandbox/Editor/Lib/Tests/test_MaterialPythonFuncs.cpp deleted file mode 100644 index c27608b695..0000000000 --- a/Code/Sandbox/Editor/Lib/Tests/test_MaterialPythonFuncs.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#include "EditorDefs.h" -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -namespace MaterialPythonFuncsUnitTests -{ - - class MaterialPythonBindingsFixture - : public testing::Test - { - public: - AzToolsFramework::ToolsApplication m_app; - - void SetUp() override - { - AzFramework::Application::Descriptor appDesc; - appDesc.m_enableDrilling = false; - - m_app.Start(appDesc); - // Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is - // shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash - // in the unit tests. - AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize); - m_app.RegisterComponentDescriptor(AzToolsFramework::MaterialPythonFuncsHandler::CreateDescriptor()); - } - - void TearDown() override - { - m_app.Stop(); - } - }; - - TEST_F(MaterialPythonBindingsFixture, MaterialEditorCommands_ApiExists) - { - AZ::BehaviorContext* behaviorContext = m_app.GetBehaviorContext(); - ASSERT_TRUE(behaviorContext); - - EXPECT_TRUE(behaviorContext->m_methods.find("create") != behaviorContext->m_methods.end()); - EXPECT_TRUE(behaviorContext->m_methods.find("create_multi") != behaviorContext->m_methods.end()); - EXPECT_TRUE(behaviorContext->m_methods.find("convert_to_multi") != behaviorContext->m_methods.end()); - EXPECT_TRUE(behaviorContext->m_methods.find("duplicate_current") != behaviorContext->m_methods.end()); - EXPECT_TRUE(behaviorContext->m_methods.find("merge_selection") != behaviorContext->m_methods.end()); - EXPECT_TRUE(behaviorContext->m_methods.find("delete_current") != behaviorContext->m_methods.end()); - EXPECT_TRUE(behaviorContext->m_methods.find("get_submaterial") != behaviorContext->m_methods.end()); - EXPECT_TRUE(behaviorContext->m_methods.find("get_property") != behaviorContext->m_methods.end()); - EXPECT_TRUE(behaviorContext->m_methods.find("set_property") != behaviorContext->m_methods.end()); - } -} diff --git a/Code/Sandbox/Editor/MainWindow.cpp b/Code/Sandbox/Editor/MainWindow.cpp index 96f4da7312..44d65af8cd 100644 --- a/Code/Sandbox/Editor/MainWindow.cpp +++ b/Code/Sandbox/Editor/MainWindow.cpp @@ -94,13 +94,11 @@ AZ_POP_DISABLE_WARNING #include "TimeOfDayDialog.h" #include "Dialogs/PythonScriptsDialog.h" -#include "Material/MaterialManager.h" #include "EngineSettingsManager.h" #include "AzAssetBrowser/AzAssetBrowserWindow.h" #include "AssetEditor/AssetEditorWindow.h" #include "GridSettingsDialog.h" -#include "MaterialSender.h" #include "ActionManager.h" // uncomment this to show thumbnail demo widget diff --git a/Code/Sandbox/Editor/MatEditPreviewDlg.cpp b/Code/Sandbox/Editor/MatEditPreviewDlg.cpp deleted file mode 100644 index 4bac9b5e76..0000000000 --- a/Code/Sandbox/Editor/MatEditPreviewDlg.cpp +++ /dev/null @@ -1,149 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "MatEditPreviewDlg.h" - -// Qt -#include -#include -#include - -// Editor -#include "Material/MaterialManager.h" -#include "Material/MaterialPreviewModelView.h" - - -///////////////////////////////////////////////////////////////////////////// -// CMatEditPreviewDlg dialog - - -CMatEditPreviewDlg::CMatEditPreviewDlg(QWidget* parent) - : QDialog(parent) -{ - setAttribute(Qt::WA_DeleteOnClose); - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); - - setWindowTitle(tr("Material Preview")); - - /* create sub controls */ - m_previewCtrl.reset(new MaterialPreviewModelView(this)); - m_menubar.reset(new QMenuBar); - - /* configure layout */ - QVBoxLayout* layout = new QVBoxLayout(); - layout->setContentsMargins(0, 0, 0, 0); - layout->addWidget(m_menubar.data()); - layout->addWidget(m_previewCtrl.data()); - layout->setStretchFactor(m_previewCtrl.data(), 1); - setLayout(layout); - - GetIEditor()->GetMaterialManager()->AddListener(this); - - SetupMenuBar(); - - OnPreviewPlane(); - m_previewCtrl->SetMaterial(GetIEditor()->GetMaterialManager()->GetCurrentMaterial() ? GetIEditor()->GetMaterialManager()->GetCurrentMaterial()->GetMatInfo() : nullptr); - m_previewCtrl->Update(); -} - -CMatEditPreviewDlg::~CMatEditPreviewDlg() -{ - GetIEditor()->GetMaterialManager()->RemoveListener(this); -} - -QSize CMatEditPreviewDlg::sizeHint() const -{ - return QSize(450, 400); -} - -void CMatEditPreviewDlg::showEvent(QShowEvent* e) -{ - QDialog::showEvent(e); - resize(sizeHint()); // Because WindowDecorationWrapper resizes it to the minimum for some reason. -} - -////////////////////////////////////////////////////////////////////////// -void CMatEditPreviewDlg::SetupMenuBar() -{ - QMenu* menu; - QAction* action; - - menu = m_menubar->addMenu(tr("Preview")); - action = menu->addAction(tr("&Plane")); - connect(action, &QAction::triggered, this, &CMatEditPreviewDlg::OnPreviewPlane); - action = menu->addAction(tr("&Sphere")); - connect(action, &QAction::triggered, this, &CMatEditPreviewDlg::OnPreviewSphere); - action = menu->addAction(tr("&Box")); - connect(action, &QAction::triggered, this, &CMatEditPreviewDlg::OnPreviewBox); - action = menu->addAction(tr("&Teapot")); - connect(action, &QAction::triggered, this, &CMatEditPreviewDlg::OnPreviewTeapot); - action = menu->addAction(tr("&Custom")); - connect(action, &QAction::triggered, this, &CMatEditPreviewDlg::OnPreviewCustom); -} - -////////////////////////////////////////////////////////////////////////// -void CMatEditPreviewDlg::OnPreviewSphere() -{ - m_previewCtrl->LoadModelFile("Objects/MtlSphere.cgf"); -} - -////////////////////////////////////////////////////////////////////////// -void CMatEditPreviewDlg::OnPreviewBox() -{ - m_previewCtrl->LoadModelFile("Objects/MtlBox.cgf"); -} - -////////////////////////////////////////////////////////////////////////// -void CMatEditPreviewDlg::OnPreviewTeapot() -{ - m_previewCtrl->LoadModelFile("Objects/MtlTeapot.cgf"); -} - -////////////////////////////////////////////////////////////////////////// -void CMatEditPreviewDlg::OnPreviewPlane() -{ - m_previewCtrl->LoadModelFile("Objects/MtlPlane.cgf"); -} - -////////////////////////////////////////////////////////////////////////// -void CMatEditPreviewDlg::OnPreviewCustom() -{ - const QString fullFileName = - QFileDialog::getOpenFileName(this, tr("Custom Model"), QString(), tr("Objects (*.cgf);;All files (*.*)")); - if (!fullFileName.isNull()) - { - m_previewCtrl->LoadModelFile(fullFileName); - } -} - -///////////////////////////////////////////////////////////////////////////// -// CMatEditPreviewDlg message handlers - -void CMatEditPreviewDlg::OnDataBaseItemEvent([[maybe_unused]] IDataBaseItem* pItem, EDataBaseItemEvent event) -{ - switch (event) - { - case EDB_ITEM_EVENT_SELECTED: - case EDB_ITEM_EVENT_ADD: - case EDB_ITEM_EVENT_CHANGED: - m_previewCtrl->SetMaterial(GetIEditor()->GetMaterialManager()->GetCurrentMaterial() ? GetIEditor()->GetMaterialManager()->GetCurrentMaterial()->GetMatInfo() : nullptr); - break; - case EDB_ITEM_EVENT_DELETE: - m_previewCtrl->SetMaterial(nullptr); - break; - } -} - -#include diff --git a/Code/Sandbox/Editor/MatEditPreviewDlg.h b/Code/Sandbox/Editor/MatEditPreviewDlg.h deleted file mode 100644 index 870d1b901e..0000000000 --- a/Code/Sandbox/Editor/MatEditPreviewDlg.h +++ /dev/null @@ -1,66 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_MATEDITPREVIEWDLG_H -#define CRYINCLUDE_EDITOR_MATEDITPREVIEWDLG_H - -#pragma once - -#if !defined(Q_MOC_RUN) -#include -#include - -#include "IDataBaseManager.h" -#endif - -class MaterialPreviewModelView; -class QMenuBar; - -// MatEditPreviewDlg.h : header file -// - -///////////////////////////////////////////////////////////////////////////// -// CMatEditPreviewDlg dialog -class CMatEditPreviewDlg - : public QDialog - , public IDataBaseManagerListener -{ - Q_OBJECT - // Construction -public: - CMatEditPreviewDlg(QWidget* parent); // standard constructor - ~CMatEditPreviewDlg(); - - QSize sizeHint() const override; - void showEvent(QShowEvent*) override; - - //Functions - - virtual void OnDataBaseItemEvent(IDataBaseItem* pItem, EDataBaseItemEvent event); - -protected: - void SetupMenuBar(); - -private slots: - void OnPreviewSphere(); - void OnPreviewPlane(); - void OnPreviewBox(); - void OnPreviewTeapot(); - void OnPreviewCustom(); - -private: - QScopedPointer m_previewCtrl; - QScopedPointer m_menubar; -}; - -#endif // CRYINCLUDE_EDITOR_MATEDITPREVIEWDLG_H diff --git a/Code/Sandbox/Editor/Material/Material.cpp b/Code/Sandbox/Editor/Material/Material.cpp deleted file mode 100644 index 3d642a53dd..0000000000 --- a/Code/Sandbox/Editor/Material/Material.cpp +++ /dev/null @@ -1,1982 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "Material.h" - -// Editor -#include "MaterialHelpers.h" -#include "MaterialManager.h" -#include "UsedResources.h" -#include "ErrorReport.h" -#include "Include/ISourceControl.h" -#include "Undo/IUndoObject.h" - - -static SInputShaderResources defaultShaderResource; - -////////////////////////////////////////////////////////////////////////// -CMaterial::CMaterial(const QString& name, int nFlags) - : m_highlightFlags(0) - , m_dccMaterialHash(0) -{ - m_scFileAttributes = SCC_FILE_ATTRIBUTE_NORMAL; - - m_pParent = 0; - - m_shaderResources = defaultShaderResource; - m_shaderResources.m_LMaterial.m_Opacity = 1; - m_shaderResources.m_LMaterial.m_Diffuse.Set(1.0f, 1.0f, 1.0f, 1.0f); - m_shaderResources.m_LMaterial.m_Specular.Set(0.045f, 0.045f, 0.045f, 1.0f); // default 59 spec + div by Gamma exponent -> lin - m_shaderResources.m_LMaterial.m_Smoothness = 10.0f; - - m_mtlFlags = nFlags; - ZeroStruct(m_shaderItem); - - // Default shader. - m_shaderName = "Illum"; - m_nShaderGenMask = 0; - - m_name = name; - m_bRegetPublicParams = true; - m_bKeepPublicParamsValues = false; - m_bIgnoreNotifyChange = false; - m_bDummyMaterial = false; - - m_pMatInfo = NULL; - m_propagationFlags = 0; - - m_allowLayerActivation = true; -} - -CMaterial::CMaterial(const CMaterial& rhs) - : m_scFileAttributes{rhs.m_scFileAttributes} - , m_pParent{nullptr} - , m_shaderResources{rhs.m_shaderResources} - , m_mtlFlags{rhs.m_mtlFlags} - , m_shaderName{rhs.m_shaderName} - , m_nShaderGenMask{rhs.m_nShaderGenMask} - , m_bRegetPublicParams{rhs.m_bRegetPublicParams} - , m_bKeepPublicParamsValues{rhs.m_bKeepPublicParamsValues} - , m_bDummyMaterial{rhs.m_bDummyMaterial} - , m_pMatInfo{nullptr} - , m_propagationFlags{rhs.m_propagationFlags} - , m_allowLayerActivation{rhs.m_allowLayerActivation} - , m_dccMaterialHash(rhs.m_dccMaterialHash) -{ - ZeroStruct(m_shaderItem); - m_name = rhs.m_name; -} - -////////////////////////////////////////////////////////////////////////// -CMaterial::~CMaterial() -{ - if (IsModified()) - { - Save(false); - } - - // Release used shader. - SAFE_RELEASE(m_shaderItem.m_pShader); - SAFE_RELEASE(m_shaderItem.m_pShaderResources); - - if (m_pMatInfo) - { - m_pMatInfo->SetUserData(0); - m_pMatInfo = 0; - } - - if (!m_subMaterials.empty()) - { - for (int i = 0; i < m_subMaterials.size(); i++) - { - if (m_subMaterials[i]) - { - m_subMaterials[i]->m_pParent = NULL; - } - } - - m_subMaterials.clear(); - } - - if (!IsPureChild() && !(GetFlags() & MTL_FLAG_UIMATERIAL)) - { - // Unregister this material from manager. - // Don't use here local variable m_pManager. Manager can be destroyed. - if (GetIEditor()->GetMaterialManager()) - { - GetIEditor()->GetMaterialManager()->DeleteItem(this); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetName(const QString& name) -{ - if (name != m_name) - { - QString oldName = GetFullName(); - m_name = name; - - if (!IsPureChild()) - { - if (GetIEditor()->GetMaterialManager()) - { - GetIEditor()->GetMaterialManager()->OnRenameItem(this, oldName); - } - - if (m_pMatInfo) - { - GetIEditor()->Get3DEngine()->GetMaterialManager()->RenameMaterial(m_pMatInfo, GetName().toUtf8().data()); - } - } - else - { - if (m_pMatInfo) - { - m_pMatInfo->SetName(m_name.toUtf8().data()); - } - } - - NotifyChanged(); - } - - if (m_shaderItem.m_pShaderResources) - { - // Only for correct warning message purposes. - m_shaderItem.m_pShaderResources->SetMaterialName(m_name.toUtf8().data()); - } -} - - -////////////////////////////////////////////////////////////////////////// -QString CMaterial::GetFilename() const -{ - return GetIEditor()->GetMaterialManager()->MaterialToFilename(IsPureChild() && m_pParent ? m_pParent->m_name : m_name); -} - -////////////////////////////////////////////////////////////////////////// -int CMaterial::GetTextureFilenames(QStringList& outFilenames) const -{ - for (auto& iter : m_shaderResources.m_TexturesResourcesMap ) - { - const SEfResTexture* pTexture = (const SEfResTexture*) &(iter.second); - QString name = QtUtil::ToQString(pTexture->m_Name); - if (name.isEmpty()) - { - AZ_Warning("Shaders System", false, "Error: CMaterial::GetTextureFilenames - texture slot name does not exist for slot %d", iter.first ); - continue; - } - - // Collect image filenames - if (IResourceCompilerHelper::IsSourceImageFormatSupported(name.toUtf8().data())) - { - stl::push_back_unique(outFilenames, Path::GamePathToFullPath(name)); - } - - // collect source files used in DCC tools - QString dccFilename; - if (CFileUtil::CalculateDccFilename(name, dccFilename)) - { - stl::push_back_unique(outFilenames, Path::GamePathToFullPath(dccFilename)); - } - } - - if (IsMultiSubMaterial()) - { - for (int i = 0; i < GetSubMaterialCount(); ++i) - { - CMaterial* pSubMtl = GetSubMaterial(i); - if (pSubMtl) - { - pSubMtl->GetTextureFilenames(outFilenames); - } - } - } - - return outFilenames.size(); -} - -////////////////////////////////////////////////////////////////////////// -int CMaterial::GetAnyTextureFilenames(QStringList& outFilenames) const -{ - for ( auto& iter : m_shaderResources.m_TexturesResourcesMap ) - { - QString name = QtUtil::ToQString( iter.second.m_Name); - if (name.isEmpty()) - { - continue; - } - - // Collect any filenames - stl::push_back_unique(outFilenames, Path::GamePathToFullPath(name)); - } - - if (IsMultiSubMaterial()) - { - for (int i = 0; i < GetSubMaterialCount(); ++i) - { - CMaterial* pSubMtl = GetSubMaterial(i); - if (pSubMtl) - { - pSubMtl->GetAnyTextureFilenames(outFilenames); - } - } - } - - return outFilenames.size(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::UpdateFileAttributes(bool useSourceControl) -{ - QString filename = GetFilename(); - if (filename.isEmpty()) - { - return; - } - - m_scFileAttributes = CFileUtil::GetAttributes(filename.toUtf8().data(), useSourceControl); -} - -////////////////////////////////////////////////////////////////////////// -uint32 CMaterial::GetFileAttributes() -{ - if (IsDummy()) - { - return m_scFileAttributes; - } - - if (IsPureChild() && m_pParent) - { - return m_pParent->GetFileAttributes(); - } - - UpdateFileAttributes(); - return m_scFileAttributes; -}; - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetShaderName(const QString& shaderName) -{ - if (m_shaderName != shaderName) - { - m_bRegetPublicParams = true; - m_bKeepPublicParamsValues = false; - - RecordUndo("Change Shader"); - } - - m_shaderName = shaderName; - if (QString::compare(m_shaderName, "nodraw", Qt::CaseInsensitive) == 0) - { - m_mtlFlags |= MTL_FLAG_NODRAW; - } - else - { - m_mtlFlags &= ~MTL_FLAG_NODRAW; - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::CheckSpecialConditions() -{ - if (QString::compare(m_shaderName, "nodraw", Qt::CaseInsensitive) == 0) - { - m_mtlFlags |= MTL_FLAG_NODRAW; - } - else - { - m_mtlFlags &= ~MTL_FLAG_NODRAW; - } - - // If environment texture name have auto/nearest cubemap in it, force material to use auto cube-map for it. - SEfResTexture* pTextureRes = m_shaderResources.GetTextureResource(EFTT_ENV); - if (!pTextureRes) - return; - - if (!pTextureRes->m_Name.empty()) - { - const char* sAtPos; - sAtPos = strstr(pTextureRes->m_Name.c_str(), "auto_2d"); - if (sAtPos) - { - pTextureRes->m_Sampler.m_eTexType = eTT_Auto2D; // Force Auto-2D - } - sAtPos = strstr(pTextureRes->m_Name.c_str(), "nearest_cubemap"); - if (sAtPos) - { - pTextureRes->m_Sampler.m_eTexType = eTT_NearestCube; // Force Nearest Cubemap - } - } - - // Force auto 2D map if user sets texture type - if (pTextureRes->m_Sampler.m_eTexType == eTT_Auto2D) - { - pTextureRes->m_Name = "auto_2d"; - } - - // Force nearest cube map if user sets texture type - if (pTextureRes->m_Sampler.m_eTexType == eTT_NearestCube) - { - pTextureRes->m_Name = "nearest_cubemap"; - m_mtlFlags |= MTL_FLAG_REQUIRE_NEAREST_CUBEMAP; - } -} - -////////////////////////////////////////////////////////////////////////// -bool CMaterial::LoadShader() -{ - if (m_bDummyMaterial) - { - return true; - } - - CheckSpecialConditions(); - - GetIEditor()->GetErrorReport()->SetCurrentValidatorItem(this); - - m_shaderResources.m_ResFlags = m_mtlFlags; - - QString sShader = m_shaderName; - if (sShader.isEmpty()) - { - sShader = ""; - } - - QByteArray n = m_name.toUtf8(); - m_shaderResources.m_szMaterialName = n.data(); - SShaderItem newShaderItem = GetIEditor()->GetRenderer()->EF_LoadShaderItem(sShader.toUtf8().data(), false, 0, &m_shaderResources, m_nShaderGenMask); - - // Shader not found - if (newShaderItem.m_pShader && (newShaderItem.m_pShader->GetFlags() & EF_NOTFOUND) != 0) - { - CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_WARNING, "Failed to load shader \"%s\" in material \"%s\"", newShaderItem.m_pShader->GetName(), m_name.toUtf8().constData()); - } - - // Release previously used shader (Must be After new shader is loaded, for speed). - SAFE_RELEASE(m_shaderItem.m_pShader); - SAFE_RELEASE(m_shaderItem.m_pShaderResources); - - m_shaderItem = newShaderItem; - if (!m_shaderItem.m_pShader) - { - CErrorRecord err; - - err.error = QObject::tr("Failed to Load Shader %1").arg(m_shaderName); - err.pItem = this; - - GetIEditor()->GetErrorReport()->ReportError(err); - GetIEditor()->GetErrorReport()->SetCurrentValidatorItem(NULL); - return false; - } - - IShader* pShader = m_shaderItem.m_pShader; - m_nShaderGenMask = pShader->GetGenerationMask(); - if (pShader->GetFlags() & EF_NOPREVIEW) - { - m_mtlFlags |= MTL_FLAG_NOPREVIEW; - } - else - { - m_mtlFlags &= ~MTL_FLAG_NOPREVIEW; - } - - ////////////////////////////////////////////////////////////////////////// - // Reget shader parms. - ////////////////////////////////////////////////////////////////////////// - if (m_bRegetPublicParams) - { - if (m_bKeepPublicParamsValues) - { - m_bKeepPublicParamsValues = false; - m_publicVarsCache = XmlHelpers::CreateXmlNode("PublicParams"); - - MaterialHelpers::SetXmlFromShaderParams(m_shaderResources, m_publicVarsCache); - } - - m_shaderResources.m_ShaderParams = pShader->GetPublicParams(); - m_bRegetPublicParams = false; - } - - ////////////////////////////////////////////////////////////////////////// - // If we have XML node with public parameters loaded, apply it on shader parms. - ////////////////////////////////////////////////////////////////////////// - if (m_publicVarsCache) - { - MaterialHelpers::SetShaderParamsFromXml(m_shaderResources, m_publicVarsCache); - GetIEditor()->GetMaterialManager()->OnUpdateProperties(this, false); - m_publicVarsCache = 0; - } - - ////////////////////////////////////////////////////////////////////////// - // Set shader parms. - if (m_shaderItem.m_pShaderResources) - { - m_shaderItem.m_pShaderResources->SetShaderParams(&m_shaderResources, m_shaderItem.m_pShader); - } - ////////////////////////////////////////////////////////////////////////// - - gEnv->pRenderer->UpdateShaderItem(&m_shaderItem, nullptr); - - ////////////////////////////////////////////////////////////////////////// - // Set Shader Params for material layers - ////////////////////////////////////////////////////////////////////////// - if (m_pMatInfo) - { - UpdateMatInfo(); - } - - GetIEditor()->GetMaterialManager()->OnLoadShader(this); - GetIEditor()->GetErrorReport()->SetCurrentValidatorItem(NULL); - - return true; -} - -bool CMaterial::LoadMaterialLayers() -{ - if (!m_pMatInfo) - { - return false; - } - - if (m_shaderItem.m_pShader && m_shaderItem.m_pShaderResources) - { - // mask generation for base material shader - uint32 nMaskGenBase = m_shaderItem.m_pShader->GetGenerationMask(); - SShaderGen* pShaderGenBase = m_shaderItem.m_pShader->GetGenerationParams(); - - for (uint32 l(0); l < MTL_LAYER_MAX_SLOTS; ++l) - { - SMaterialLayerResources* pCurrLayer = &m_pMtlLayerResources[l]; - pCurrLayer->m_nFlags |= MTL_FLAG_NODRAW; - if (!pCurrLayer->m_shaderName.isEmpty()) - { - if (QString::compare(pCurrLayer->m_shaderName, "nodraw", Qt::CaseInsensitive) == 0) - { - // no shader = skip layer - pCurrLayer->m_shaderName.clear(); - continue; - } - - IShader* pNewShader = GetIEditor()->GetRenderer()->EF_LoadShader(pCurrLayer->m_shaderName.toUtf8().data(), 0); - - // Check if shader loaded - if (!pNewShader || (pNewShader->GetFlags() & EF_NOTFOUND) != 0) - { - CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_WARNING, "Failed to load material layer shader \"%s\" in material \"%s\"", pCurrLayer->m_shaderName.toUtf8().constData(), m_pMatInfo->GetName()); - if (!pNewShader) - { - continue; - } - } - - if (!pCurrLayer->m_pMatLayer) - { - pCurrLayer->m_pMatLayer = m_pMatInfo->CreateLayer(); - } - - // mask generation for base material shader - uint64 nMaskGenLayer = 0; - SShaderGen* pShaderGenLayer = pNewShader->GetGenerationParams(); - if (pShaderGenBase && pShaderGenLayer) - { - for (int nLayerBit(0); nLayerBit < pShaderGenLayer->m_BitMask.size(); ++nLayerBit) - { - SShaderGenBit* pLayerBit = pShaderGenLayer->m_BitMask[nLayerBit]; - - for (int nBaseBit(0); nBaseBit < pShaderGenBase->m_BitMask.size(); ++nBaseBit) - { - SShaderGenBit* pBaseBit = pShaderGenBase->m_BitMask[nBaseBit]; - - // Need to check if flag name is common to both shaders (since flags values can be different), if so activate it on this layer - if (nMaskGenBase & pBaseBit->m_Mask) - { - if (!pLayerBit->m_ParamName.empty() && !pBaseBit->m_ParamName.empty()) - { - if (pLayerBit->m_ParamName == pBaseBit->m_ParamName) - { - nMaskGenLayer |= pLayerBit->m_Mask; - break; - } - } - } - } - } - } - - // Reload with proper flags - SShaderItem newShaderItem = GetIEditor()->GetRenderer()->EF_LoadShaderItem(pCurrLayer->m_shaderName.toUtf8().data(), false, 0, &pCurrLayer->m_shaderResources, nMaskGenLayer); - if (!newShaderItem.m_pShader || (newShaderItem.m_pShader->GetFlags() & EF_NOTFOUND) != 0) - { - CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_WARNING, "Failed to load material layer shader \"%s\" in material \"%s\"", pCurrLayer->m_shaderName.toUtf8().data(), m_pMatInfo->GetName()); - if (!newShaderItem.m_pShader) - { - continue; - } - } - - SShaderItem& pCurrShaderItem = pCurrLayer->m_pMatLayer->GetShaderItem(); - - if (newShaderItem.m_pShader) - { - newShaderItem.m_pShader->AddRef(); - } - - // Release previously used shader (Must be After new shader is loaded, for speed). - SAFE_RELEASE(pCurrShaderItem.m_pShader); - SAFE_RELEASE(pCurrShaderItem.m_pShaderResources); - SAFE_RELEASE(newShaderItem.m_pShaderResources); - - pCurrShaderItem.m_pShader = newShaderItem.m_pShader; - // Copy resources from base material - pCurrShaderItem.m_pShaderResources = m_shaderItem.m_pShaderResources->Clone(); - pCurrShaderItem.m_nTechnique = newShaderItem.m_nTechnique; - pCurrShaderItem.m_nPreprocessFlags = newShaderItem.m_nPreprocessFlags; - - // set default params - if (pCurrLayer->m_bRegetPublicParams) - { - pCurrLayer->m_shaderResources.m_ShaderParams = pCurrShaderItem.m_pShader->GetPublicParams(); - } - - pCurrLayer->m_bRegetPublicParams = false; - - if (pCurrLayer->m_publicVarsCache) - { - MaterialHelpers::SetShaderParamsFromXml(pCurrLayer->m_shaderResources, pCurrLayer->m_publicVarsCache); - pCurrLayer->m_publicVarsCache = 0; - } - - if (pCurrShaderItem.m_pShaderResources) - { - pCurrShaderItem.m_pShaderResources->SetShaderParams(&pCurrLayer->m_shaderResources, pCurrShaderItem.m_pShader); - } - - // Activate layer - pCurrLayer->m_nFlags &= ~MTL_FLAG_NODRAW; - } - } - - return true; - } - - return false; -} - -////////////////////////////////////////////////////////////////////////// - -void CMaterial::UpdateMaterialLayers() -{ - if (m_pMatInfo && m_shaderItem.m_pShaderResources) - { - m_pMatInfo->SetLayerCount(MTL_LAYER_MAX_SLOTS); - - uint8 nMaterialLayerFlags = 0; - - for (int l(0); l < MTL_LAYER_MAX_SLOTS; ++l) - { - SMaterialLayerResources* pCurrLayer = &m_pMtlLayerResources[l]; - if (pCurrLayer && !pCurrLayer->m_shaderName.isEmpty() && pCurrLayer->m_pMatLayer) - { - pCurrLayer->m_pMatLayer->SetFlags(pCurrLayer->m_nFlags); - m_pMatInfo->SetLayer(l, pCurrLayer->m_pMatLayer); - - if ((pCurrLayer->m_nFlags & MTL_LAYER_USAGE_NODRAW)) - { - if (!QString::compare(pCurrLayer->m_shaderName, "frozenlayerwip", Qt::CaseInsensitive)) - { - nMaterialLayerFlags |= MTL_LAYER_FROZEN; - } - } - } - } - - if (m_shaderItem.m_pShaderResources) - { - m_shaderItem.m_pShaderResources->SetMtlLayerNoDrawFlags(nMaterialLayerFlags); - } - } -} - -void CMaterial::UpdateMatInfo() -{ - if (m_pMatInfo) - { - // Mark material invalid. - m_pMatInfo->SetFlags(m_mtlFlags); - m_pMatInfo->SetShaderItem(m_shaderItem); - m_pMatInfo->SetShaderName(m_shaderName.toUtf8().constData()); - m_pMatInfo->SetSurfaceType(m_surfaceType.toUtf8().constData()); - - LoadMaterialLayers(); - UpdateMaterialLayers(); - - m_pMatInfo->SetMaterialLinkName(m_linkedMaterial.toUtf8().data()); - - if (IsMultiSubMaterial()) - { - m_pMatInfo->SetSubMtlCount(m_subMaterials.size()); - for (unsigned int i = 0; i < m_subMaterials.size(); i++) - { - if (m_subMaterials[i]) - { - m_pMatInfo->SetSubMtl(i, m_subMaterials[i]->GetMatInfo()); - } - else - { - m_pMatInfo->SetSubMtl(i, NULL); - } - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -CVarBlock* CMaterial::GetPublicVars(SInputShaderResources& pShaderResources) -{ - return MaterialHelpers::GetPublicVars(pShaderResources); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetShaderParamPublicScript() -{ - IShader* pShader = m_shaderItem.m_pShader; - - if (!pShader) - { - return; - } - - if (m_shaderResources.m_ShaderParams.size() == 0 || pShader->GetPublicParams().size() == 0) - { - return; - } - - // We want to inspect public shader param and paste the m_script into our shader resource param script - for (int i = 0; i < m_shaderResources.m_ShaderParams.size(); ++i) - { - SShaderParam ¤tShaderParam = m_shaderResources.m_ShaderParams.at(i); - for (int j = 0; j < pShader->GetPublicParams().size(); ++j) - { - const SShaderParam &publicShaderParam = pShader->GetPublicParams().at(j); - if ((currentShaderParam.m_Name == publicShaderParam.m_Name) && (currentShaderParam.m_Type == publicShaderParam.m_Type)) - { - currentShaderParam.m_Script = publicShaderParam.m_Script; - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetPublicVars(CVarBlock* pPublicVars, CMaterial* pMtl) -{ - if (!pMtl->GetShaderResources().m_ShaderParams.empty()) - { - RecordUndo("Set Public Vars"); - } - - MaterialHelpers::SetPublicVars(pPublicVars, pMtl->GetShaderResources(), pMtl->GetShaderItem().m_pShaderResources, pMtl->GetShaderItem().m_pShader); - - GetIEditor()->GetMaterialManager()->OnUpdateProperties(this, false); -} - -////////////////////////////////////////////////////////////////////////// -CVarBlock* CMaterial::GetShaderGenParamsVars() -{ - return MaterialHelpers::GetShaderGenParamsVars(GetShaderItem().m_pShader, m_nShaderGenMask); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetShaderGenParamsVars(CVarBlock* pBlock) -{ - RecordUndo("Change Shader GenMask"); - - uint64 nGenMask = MaterialHelpers::SetShaderGenParamsVars(GetShaderItem().m_pShader, pBlock); - if (m_nShaderGenMask != nGenMask) - { - m_bRegetPublicParams = true; - m_bKeepPublicParamsValues = true; - m_nShaderGenMask = nGenMask; - } -} - -////////////////////////////////////////////////////////////////////////// -unsigned int CMaterial::GetTexmapUsageMask() const -{ - int mask = 0; - if (m_shaderItem.m_pShader) - { - IShader* pTempl = m_shaderItem.m_pShader; - if (pTempl) - { - mask = pTempl->GetUsedTextureTypes(); - } - } - return mask; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::Update() -{ - // Reload shader item with new resources and shader. - LoadShader(); - - // Mark library as modified. - SetModified(); - - GetIEditor()->SetModifiedFlag(); - - // When modifying pure child, mark his parent as modified. - if (IsPureChild() && m_pParent) - { - m_pParent->SetModified(); - } -} - -////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////// -void CMaterial::Serialize(SerializeContext& ctx) -{ - //CBaseLibraryItem::Serialize( ctx ); - - XmlNodeRef node = ctx.node; - if (ctx.bLoading) - { - m_bIgnoreNotifyChange = true; - m_bRegetPublicParams = true; - - SInputShaderResources& sr = m_shaderResources; - m_shaderResources = defaultShaderResource; - - // Loading - int flags = m_mtlFlags; - if (node->getAttr("MtlFlags", flags)) - { - m_mtlFlags &= ~(MTL_FLAGS_SAVE_MASK); - m_mtlFlags |= (flags & (MTL_FLAGS_SAVE_MASK)); - } - - uint32 dccMaterialHash = 0; - node->getAttr("DccMaterialHash", dccMaterialHash); - SetDccMaterialHash(dccMaterialHash); - - if (!IsMultiSubMaterial()) - { - node->getAttr("Shader", m_shaderName); - node->getAttr("GenMask", m_nShaderGenMask); - - if (!(m_mtlFlags & MTL_64BIT_SHADERGENMASK)) - { - uint32 nShaderGenMask = 0; - node->getAttr("GenMask", nShaderGenMask); - m_nShaderGenMask = nShaderGenMask; - } - else - { - node->getAttr("GenMask", m_nShaderGenMask); - } - - // Remap flags if needed - if (!(m_mtlFlags & MTL_64BIT_SHADERGENMASK)) - { - m_nShaderGenMask = GetIEditor()->GetRenderer()->EF_GetRemapedShaderMaskGen(m_shaderName.toUtf8().data(), m_nShaderGenMask); - m_mtlFlags |= MTL_64BIT_SHADERGENMASK; - } - - if (node->getAttr("StringGenMask", m_pszShaderGenMask)) - { - m_nShaderGenMask = GetIEditor()->GetRenderer()->EF_GetShaderGlobalMaskGenFromString(m_shaderName.toUtf8().data(), m_pszShaderGenMask.toUtf8().data(), m_nShaderGenMask); // get common mask gen - } - else - { - // version doens't has string gen mask yet ? Remap flags if needed - m_nShaderGenMask = GetIEditor()->GetRenderer()->EF_GetRemapedShaderMaskGen(m_shaderName.toUtf8().data(), m_nShaderGenMask, ((m_mtlFlags & MTL_64BIT_SHADERGENMASK) != 0)); - } - m_mtlFlags |= MTL_64BIT_SHADERGENMASK; - - node->getAttr("SurfaceType", m_surfaceType); - node->getAttr("LayerAct", m_allowLayerActivation); - - MaterialHelpers::SetLightingFromXml(sr, node); - - MaterialHelpers::SetTexturesFromXml(sr, node); - MaterialHelpers::MigrateXmlLegacyData(sr, node); - } - - ////////////////////////////////////////////////////////////////////////// - // Check if we have a link name and if any propagation settings were - // present - ////////////////////////////////////////////////////////////////////////// - XmlNodeRef pLinkName = node->findChild("MaterialLinkName"); - if (pLinkName) - { - m_linkedMaterial = pLinkName->getAttr("name"); - } - else - { - m_linkedMaterial = QString(); - } - - XmlNodeRef pPropagationFlags = node->findChild("MaterialPropagationFlags"); - if (pPropagationFlags) - { - pPropagationFlags->getAttr("flags", m_propagationFlags); - } - else - { - m_propagationFlags = 0; - } - - ////////////////////////////////////////////////////////////////////////// - // Check if we have vertex deform. - ////////////////////////////////////////////////////////////////////////// - MaterialHelpers::SetVertexDeformFromXml(m_shaderResources, node); - - // Serialize sub materials. - - const auto ResizeSubMaterials = [this](size_t count) - { - for (size_t i = count; i < m_subMaterials.size(); ++i) - { - if (auto& pSubMtl = m_subMaterials[i]) - { - pSubMtl->m_pParent = nullptr; - } - } - m_subMaterials.resize(count); - }; - - XmlNodeRef childsNode = node->findChild("SubMaterials"); - if (childsNode && !ctx.bIgnoreChilds) - { - QString name; - int nSubMtls = childsNode->getChildCount(); - ResizeSubMaterials(nSubMtls); - for (int i = 0; i < nSubMtls; i++) - { - auto& pSubMtl = m_subMaterials[i]; - XmlNodeRef mtlNode = childsNode->getChild(i); - if (mtlNode->isTag("Material")) - { - mtlNode->getAttr("Name", name); - if (pSubMtl && pSubMtl->IsPureChild()) - { - pSubMtl->SetName(name); - } - else - { - if (pSubMtl) - { - pSubMtl->m_pParent = nullptr; - } - - pSubMtl = new CMaterial(name, MTL_FLAG_PURE_CHILD); - pSubMtl->m_pParent = this; - } - - SerializeContext childCtx(ctx); - childCtx.node = mtlNode; - pSubMtl->Serialize(childCtx); - - pSubMtl->m_shaderResources.m_SortPrio = nSubMtls - i - 1; - } - else - { - if (pSubMtl) - { - pSubMtl->m_pParent = nullptr; - pSubMtl = nullptr; - } - - if (mtlNode->getAttr("Name", name)) - { - CMaterial* pMtl = GetIEditor()->GetMaterialManager()->LoadMaterial(name); - if (pMtl && !pMtl->IsMultiSubMaterial()) - { - pSubMtl = pMtl; - } - } - } - } - - m_subMaterials.erase(std::remove(m_subMaterials.begin(), m_subMaterials.end(), nullptr), m_subMaterials.end()); - } - else - { - ResizeSubMaterials(0); - } - - UpdateMatInfo(); - - ////////////////////////////////////////////////////////////////////////// - // Load public parameters. - ////////////////////////////////////////////////////////////////////////// - m_publicVarsCache = node->findChild("PublicParams"); - - ////////////////////////////////////////////////////////////////////////// - // Load material layers data - ////////////////////////////////////////////////////////////////////////// - XmlNodeRef mtlLayersNode = node->findChild("MaterialLayers"); - if (mtlLayersNode) - { - int nChildCount = min((int) MTL_LAYER_MAX_SLOTS, (int) mtlLayersNode->getChildCount()); - for (int l = 0; l < nChildCount; ++l) - { - XmlNodeRef layerNode = mtlLayersNode->getChild(l); - if (layerNode) - { - if (layerNode->getAttr("Name", m_pMtlLayerResources[l].m_shaderName)) - { - m_pMtlLayerResources[l].m_bRegetPublicParams = true; - - bool bNoDraw = false; - layerNode->getAttr("NoDraw", bNoDraw); - - m_pMtlLayerResources[l].m_publicVarsCache = layerNode->findChild("PublicParams"); - - if (bNoDraw) - { - m_pMtlLayerResources[l].m_nFlags |= MTL_LAYER_USAGE_NODRAW; - } - else - { - m_pMtlLayerResources[l].m_nFlags &= ~MTL_LAYER_USAGE_NODRAW; - } - - - bool bFadeOut = false; - layerNode->getAttr("FadeOut", bFadeOut); - if (bFadeOut) - { - m_pMtlLayerResources[l].m_nFlags |= MTL_LAYER_USAGE_FADEOUT; - } - else - { - m_pMtlLayerResources[l].m_nFlags &= ~MTL_LAYER_USAGE_FADEOUT; - } - } - } - } - } - - if (ctx.bUndo) - { - LoadShader(); - UpdateMatInfo(); - } - - m_bIgnoreNotifyChange = false; - - // If copy pasting or undo send update event. - if (ctx.bCopyPaste || ctx.bUndo) - { - NotifyChanged(); - } - - // NotifyChanged calls SetModified but since we just loaded it, its not actually changed. - SetModified(false); - } - else // If !ctx.bLoading - { - int extFlags = MTL_64BIT_SHADERGENMASK; - { - const QString& name = GetName(); - const size_t len = name.length(); - if (len > 4 && strstri(name.toUtf8().data() + (len - 4), "_con")) - { - extFlags |= MTL_FLAG_CONSOLE_MAT; - } - } - - // Saving. - node->setAttr("MtlFlags", m_mtlFlags | extFlags); - node->setAttr("DccMaterialHash", GetDccMaterialHash()); - - if (!IsMultiSubMaterial()) - { - // store shader gen bit mask string - m_pszShaderGenMask = GetIEditor()->GetRenderer()->EF_GetStringFromShaderGlobalMaskGen(m_shaderName.toUtf8().data(), m_nShaderGenMask).c_str(); - - node->setAttr("Shader", m_shaderName.toUtf8().data()); - node->setAttr("GenMask", m_nShaderGenMask); - node->setAttr("StringGenMask", m_pszShaderGenMask.toUtf8().data()); - node->setAttr("SurfaceType", m_surfaceType.toUtf8().data()); - - //if (!m_shaderName.IsEmpty() && (stricmp(m_shaderName,"nodraw") != 0)) - { - MaterialHelpers::SetXmlFromLighting(m_shaderResources, node); - MaterialHelpers::SetXmlFromTextures(m_shaderResources, node); - } - } - - ////////////////////////////////////////////////////////////////////////// - // Save out the link name if present and the propagation flags - ////////////////////////////////////////////////////////////////////////// - if (!m_linkedMaterial.isEmpty()) - { - XmlNodeRef pLinkName = node->newChild("MaterialLinkName"); - pLinkName->setAttr("name", m_linkedMaterial.toUtf8().data()); - } - - if (m_propagationFlags) - { - XmlNodeRef pPropagationFlags = node->newChild("MaterialPropagationFlags"); - pPropagationFlags->setAttr("flags", m_propagationFlags); - } - - ////////////////////////////////////////////////////////////////////////// - // Check if we have vertex deform. - ////////////////////////////////////////////////////////////////////////// - MaterialHelpers::SetXmlFromVertexDeform(m_shaderResources, node); - - if (GetSubMaterialCount() > 0) - { - // Serialize sub materials. - - // Let's not serialize empty submaterials at the end of the list. - // Note that IDs of the remaining submaterials stay intact. - int count = GetSubMaterialCount(); - while (count > 0 && !GetSubMaterial(count - 1)) - { - --count; - } - - XmlNodeRef childsNode = node->newChild("SubMaterials"); - - for (int i = 0; i < count; ++i) - { - CMaterial* const pSubMtl = GetSubMaterial(i); - if (pSubMtl && pSubMtl->IsPureChild()) - { - XmlNodeRef mtlNode = childsNode->newChild("Material"); - mtlNode->setAttr("Name", pSubMtl->GetName().toUtf8().data()); - SerializeContext childCtx(ctx); - childCtx.node = mtlNode; - pSubMtl->Serialize(childCtx); - } - else - { - XmlNodeRef mtlNode = childsNode->newChild("MaterialRef"); - if (pSubMtl) - { - mtlNode->setAttr("Name", pSubMtl->GetName().toUtf8().data()); - } - } - } - } - - ////////////////////////////////////////////////////////////////////////// - // Save public parameters. - ////////////////////////////////////////////////////////////////////////// - if (m_publicVarsCache) - { - node->addChild(m_publicVarsCache); - } - else if (!m_shaderResources.m_ShaderParams.empty()) - { - XmlNodeRef publicsNode = node->newChild("PublicParams"); - MaterialHelpers::SetXmlFromShaderParams(m_shaderResources, publicsNode); - } - - ////////////////////////////////////////////////////////////////////////// - // Save material layers data - ////////////////////////////////////////////////////////////////////////// - - bool bMaterialLayers = false; - for (int l(0); l < MTL_LAYER_MAX_SLOTS; ++l) - { - if (!m_pMtlLayerResources[l].m_shaderName.isEmpty()) - { - bMaterialLayers = true; - break; - } - } - - if (bMaterialLayers) - { - XmlNodeRef mtlLayersNode = node->newChild("MaterialLayers"); - for (int l(0); l < MTL_LAYER_MAX_SLOTS; ++l) - { - XmlNodeRef layerNode = mtlLayersNode->newChild("Layer"); - if (!m_pMtlLayerResources[l].m_shaderName.isEmpty()) - { - layerNode->setAttr("Name", m_pMtlLayerResources[l].m_shaderName.toUtf8().data()); - layerNode->setAttr("NoDraw", m_pMtlLayerResources[l].m_nFlags & MTL_LAYER_USAGE_NODRAW); - layerNode->setAttr("FadeOut", m_pMtlLayerResources[l].m_nFlags & MTL_LAYER_USAGE_FADEOUT); - - if (m_pMtlLayerResources[l].m_publicVarsCache) - { - layerNode->addChild(m_pMtlLayerResources[l].m_publicVarsCache); - } - else if (!m_pMtlLayerResources[l].m_shaderResources.m_ShaderParams.empty()) - { - XmlNodeRef publicsNode = layerNode->newChild("PublicParams"); - MaterialHelpers::SetXmlFromShaderParams(m_pMtlLayerResources[l].m_shaderResources, publicsNode); - } - } - } - } - - if (GetSubMaterialCount() == 0 || GetParent()) - { - node->setAttr("LayerAct", m_allowLayerActivation); - } - } -} - -/* -////////////////////////////////////////////////////////////////////////// -void CMaterial::SerializePublics( XmlNodeRef &node,bool bLoading ) -{ -if (bLoading) -{ -} -else -{ -if (m_shaderParams.empty()) -return; -XmlNodeRef publicsNode = node->newChild( "PublicParams" ); - -for (int i = 0; i < m_shaderParams.size(); i++) -{ -XmlNodeRef paramNode = node->newChild( "Param" ); -SShaderParam *pParam = &m_shaderParams[i]; -paramNode->setAttr( "Name",pParam->m_Name ); -switch (pParam->m_Type) -{ -case eType_BYTE: -paramNode->setAttr( "Value",(int)pParam->m_Value.m_Byte ); -paramNode->setAttr( "Type",(int)pParam->m_Value.m_Byte ); -break; -case eType_SHORT: -paramNode->setAttr( "Value",(int)pParam->m_Value.m_Short ); -break; -case eType_INT: -paramNode->setAttr( "Value",(int)pParam->m_Value.m_Int ); -break; -case eType_FLOAT: -paramNode->setAttr( "Value",pParam->m_Value.m_Float ); -break; -case eType_STRING: -paramNode->setAttr( "Value",pParam->m_Value.m_String ); -break; -case eType_FCOLOR: -paramNode->setAttr( "Value",Vec3(pParam->m_Value.m_Color[0],pParam->m_Value.m_Color[1],pParam->m_Value.m_Color[2]) ); -break; -case eType_VECTOR: -paramNode->setAttr( "Value",Vec3(pParam->m_Value.m_Vector[0],pParam->m_Value.m_Vector[1],pParam->m_Value.m_Vector[2]) ); -break; -} -} -} -} -*/ - -////////////////////////////////////////////////////////////////////////// -void CMaterial::AssignToEntity(IRenderNode* pEntity) -{ - assert(pEntity); - pEntity->SetMaterial(GetMatInfo()); -} - -////////////////////////////////////////////////////////////////////////// -bool CMaterial::IsBreakable2D() const -{ - if ((GetFlags() & MTL_FLAG_NODRAW) != 0) - { - return false; - } - - const QString& surfaceTypeName = GetSurfaceTypeName(); - if (ISurfaceTypeManager* pSurfaceManager = GetIEditor()->Get3DEngine()->GetMaterialManager()->GetSurfaceTypeManager()) - { - ISurfaceType* pSurfaceType = pSurfaceManager->GetSurfaceTypeByName(surfaceTypeName.toUtf8().data()); - if (pSurfaceType && pSurfaceType->GetBreakable2DParams() != 0) - { - return true; - } - } - - int count = GetSubMaterialCount(); - for (int i = 0; i < count; ++i) - { - const CMaterial* pSub = GetSubMaterial(i); - if (!pSub) - { - continue; - } - if (pSub->IsBreakable2D()) - { - return true; - } - } - return false; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetFromMatInfo(_smart_ptr pMatInfo) -{ - assert(pMatInfo); - - m_shaderName = ""; - - ClearMatInfo(); - SetModified(true); - - m_mtlFlags = pMatInfo->GetFlags(); - if (m_mtlFlags & MTL_FLAG_MULTI_SUBMTL) - { - // Create sub materials. - SetSubMaterialCount(pMatInfo->GetSubMtlCount()); - for (int i = 0; i < GetSubMaterialCount(); i++) - { - _smart_ptr pChildMatInfo = pMatInfo->GetSubMtl(i); - if (!pChildMatInfo) - { - continue; - } - - if (pChildMatInfo->GetFlags() & MTL_FLAG_PURE_CHILD) - { - CMaterial* existingChild = GetSubMaterial(i); - if (existingChild) - { - existingChild->SetFromMatInfo(pChildMatInfo); - } - else - { - CMaterial* pChild = new CMaterial(pChildMatInfo->GetName(), pChildMatInfo->GetFlags()); - pChild->SetFromMatInfo(pChildMatInfo); - SetSubMaterial(i, pChild); - } - } - else - { - CMaterial* pChild = GetIEditor()->GetMaterialManager()->LoadMaterial(pChildMatInfo->GetName()); - pChild->SetFromMatInfo(pChildMatInfo); - SetSubMaterial(i, pChild); - } - } - } - else - { - SetShaderItem(pMatInfo->GetShaderItem()); - - if (m_shaderItem.m_pShaderResources) - { - m_shaderResources = SInputShaderResources(m_shaderItem.m_pShaderResources); - } - if (m_shaderItem.m_pShader) - { - // Get name of template. - IShader* pTemplShader = m_shaderItem.m_pShader; - if (pTemplShader) - { - m_nShaderGenMask = pTemplShader->GetGenerationMask(); - } - } - m_shaderName = pMatInfo->GetShaderName(); - ISurfaceType* pSurfaceType = pMatInfo->GetSurfaceType(); - if (pSurfaceType) - { - m_surfaceType = pSurfaceType->GetName(); - } - else - { - m_surfaceType = ""; - } - } - - // Mark as not modified. - SetModified(false); - - // Material link names - if (const char* szLinkName = pMatInfo->GetMaterialLinkName()) - { - m_linkedMaterial = szLinkName; - } - - ////////////////////////////////////////////////////////////////////////// - // Assign mat info. - m_pMatInfo = pMatInfo; - m_pMatInfo->SetUserData(this); - AddRef(); // Let IMaterial keep a reference to us. -} - -////////////////////////////////////////////////////////////////////////// -int CMaterial::GetSubMaterialCount() const -{ - return m_subMaterials.size(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetSubMaterialCount(int nSubMtlsCount) -{ - RecordUndo("Multi Material Change"); - m_subMaterials.resize(nSubMtlsCount); - UpdateMatInfo(); - NotifyChanged(); -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterial::GetSubMaterial(int index) const -{ - const int nSubMats = m_subMaterials.size(); - assert(index >= 0 && index < nSubMats); - - if (index < 0 || index >= nSubMats) - { - return NULL; - } - - return m_subMaterials[index]; -} - -////////////////////////////////////////////////////////////////////////// -int CMaterial::FindMaterialIndex(const QString& name) -{ - for (int i = 0; i < m_subMaterials.size(); ++i) - { - if (m_subMaterials[i]->GetName().compare(name) == 0) - { - return i; - } - } - - return -1; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetSubMaterial(int nSlot, CMaterial* mtl) -{ - RecordUndo("Multi Material Change"); - assert(nSlot >= 0 && nSlot < m_subMaterials.size()); - if (mtl) - { - if (mtl->IsMultiSubMaterial()) - { - return; - } - if (mtl->IsPureChild()) - { - mtl->m_pParent = this; - } - } - - if (m_subMaterials[nSlot]) - { - m_subMaterials[nSlot]->m_pParent = NULL; - } - m_subMaterials[nSlot] = mtl; - - if (!m_subMaterials[nSlot]) - { - m_subMaterials.erase(m_subMaterials.begin() + nSlot); - } - - UpdateMatInfo(); - NotifyChanged(); -} - -////////////////////////////////////////////////////////////////////////// -// This method will populate for the material editor the name and tool tip of the -// different textures of the current material -//CVarBlock* CMaterial::UpdateTextureNames(AZStd::unordered_map& textureVarsMap) -CVarBlock* CMaterial::UpdateTextureNames(CSmartVariableArray textureVars[EFTT_MAX]) -{ - CVarBlock* pTextureSlots = new CVarBlock; - IShader* pTemplShader = m_shaderItem.m_pShader; - int nTech = max(0, m_shaderItem.m_nTechnique); - SShaderTexSlots* pShaderSlots = pTemplShader ? pTemplShader->GetUsedTextureSlots(nTech) : nullptr; - - for (EEfResTextures nTexSlot = EEfResTextures(0); nTexSlot < EFTT_MAX; nTexSlot = EEfResTextures(nTexSlot + 1)) - { - if (!MaterialHelpers::IsAdjustableTexSlot((EEfResTextures)nTexSlot)) - { // do not take into account virtual slots (such as smoothness - normal's alpha) - // in theory this case should not happen as it is filtered from the source list. - continue; - } - - IVariable* pVar = textureVars[nTexSlot].GetVar(); - SShaderTextureSlot* pSlot = pShaderSlots ? pShaderSlots->m_UsedTextureSlots[nTexSlot] : nullptr; - - // If slot is NULL, fall back to default name - name here is the context name (i.e. diffuse, normal..) - // and not the actual texture file name - pVar->SetName(pSlot && pSlot->m_Name.length() ? pSlot->m_Name.c_str() : MaterialHelpers::LookupTexName((EEfResTextures) nTexSlot)); - pVar->SetDescription(pSlot && pSlot->m_Description.length() ? pSlot->m_Description.c_str() : MaterialHelpers::LookupTexDesc((EEfResTextures)nTexSlot)); - - int flags = pVar->GetFlags(); - - // TODO: slot->m_TexType gives expected sampler type (2D vs Cube etc). Could check/extract this here. - - // Not sure why this needs COLLAPSED added again, but without this all the slots expand - flags |= IVariable::UI_COLLAPSED; - - //clear the auto-expand flag if there is no texture assigned. - SEfResTexture* pTextureRes = m_shaderResources.GetTextureResource(nTexSlot); - bool noTextureName = (!pTextureRes ? true : pTextureRes->m_Name.empty()); - - if (noTextureName) - { - flags &= ~IVariable::UI_AUTO_EXPAND; - } - - // if slot is NULL, but we have reflection information, this slot isn't used - make the variable invisible - // unless there's a texture in the slot - if (pShaderSlots && !pSlot && noTextureName) - { - flags |= IVariable::UI_INVISIBLE; - } - else - { - flags &= ~IVariable::UI_INVISIBLE; - } - - pVar->SetFlags(flags); - - pTextureSlots->AddVariable(pVar); - } - - return pTextureSlots; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::ClearAllSubMaterials() -{ - RecordUndo("Multi Material Change"); - for (int i = 0; i < m_subMaterials.size(); i++) - { - if (m_subMaterials[i]) - { - m_subMaterials[i]->m_pParent = NULL; - m_subMaterials[i] = NULL; - } - } - UpdateMatInfo(); - NotifyChanged(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::Validate() -{ - if (IsDummy()) - { - CErrorRecord err; - err.error = QObject::tr("Material %1 file not found").arg(GetName()); - err.pItem = this; - GetIEditor()->GetErrorReport()->ReportError(err); - } - // Reload shader. - LoadShader(); - - // Validate sub materials. - for (int i = 0; i < m_subMaterials.size(); i++) - { - if (m_subMaterials[i]) - { - m_subMaterials[i]->Validate(); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::GatherUsedResources(CUsedResources& resources) -{ - if (!IsUsed()) - { - return; - } - - SInputShaderResources& sr = GetShaderResources(); - for (auto iter = sr.m_TexturesResourcesMap.begin(); iter != sr.m_TexturesResourcesMap.end(); ++iter) - { - SEfResTexture* pTexture = &iter->second; - if (!pTexture->m_Name.empty()) - { - resources.Add(pTexture->m_Name.c_str()); - } - } -} - -////////////////////////////////////////////////////////////////////////// -bool CMaterial::CanModify(bool bSkipReadOnly) -{ - if (m_bDummyMaterial) - { - return false; - } - - if (IsPureChild() && GetParent()) - { - return GetParent()->CanModify(bSkipReadOnly); - } - - if (bSkipReadOnly) - { - // If read only or in pack, do not save. - if (m_scFileAttributes & (SCC_FILE_ATTRIBUTE_READONLY | SCC_FILE_ATTRIBUTE_INPAK)) - { - return false; - } - - // Managed file must be checked out. - if ((m_scFileAttributes & SCC_FILE_ATTRIBUTE_MANAGED) && !(m_scFileAttributes & SCC_FILE_ATTRIBUTE_CHECKEDOUT)) - { - return false; - } - } - else - { - // Only if in pack. - if (m_scFileAttributes & (SCC_FILE_ATTRIBUTE_INPAK)) - { - return false; - } - } - return true; -} - -////////////////////////////////////////////////////////////////////////// -bool CMaterial::Save(bool bSkipReadOnly, const QString& fullPath) -{ - // Save our parent - if (IsPureChild()) - { - if (m_pParent) - { - return m_pParent->Save(bSkipReadOnly); - } - return false; - } - - if (m_mtlFlags & MTL_FLAG_UIMATERIAL) - { - return false; - } - - GetFileAttributes(); - - if (bSkipReadOnly && IsModified()) - { - // If read only or in pack, do not save. - if (m_scFileAttributes & (SCC_FILE_ATTRIBUTE_READONLY | SCC_FILE_ATTRIBUTE_INPAK)) - { - gEnv->pLog->LogError("Can't save material %s (read-only)", GetName().toUtf8().constData()); - } - - // Managed file must be checked out. - if ((m_scFileAttributes & SCC_FILE_ATTRIBUTE_MANAGED) && !(m_scFileAttributes & SCC_FILE_ATTRIBUTE_CHECKEDOUT)) - { - gEnv->pLog->LogError("Can't save material %s (need to check out)", GetName().toUtf8().constData()); - } - } - - if (!CanModify(bSkipReadOnly)) - { - return false; - } - - - // If filename is empty do not not save. - if (GetFilename().isEmpty()) - { - return false; - } - - // Save material XML to a file that corresponds to the material name with extension .mtl. - XmlNodeRef mtlNode = XmlHelpers::CreateXmlNode("Material"); - CBaseLibraryItem::SerializeContext ctx(mtlNode, false); - Serialize(ctx); - - bool saveSucceeded = false; - if (fullPath.isEmpty()) - { - // If no filepath was specified, get the filename using the relative path/unique identifier of this material - saveSucceeded = XmlHelpers::SaveXmlNode(GetIEditor()->GetFileUtil(), mtlNode, GetFilename().toUtf8().data()); - } - else - { - // If a filepath was specified, save to the specified location - saveSucceeded = XmlHelpers::SaveXmlNode(GetIEditor()->GetFileUtil(), mtlNode, fullPath.toUtf8().data()); - } - - if (saveSucceeded) - { - // If material successfully saved, clear modified flag. - SetModified(false); - for (int i = 0; i < GetSubMaterialCount(); ++i) - { - CMaterial* pSubMaterial = GetSubMaterial(i); - if (pSubMaterial) - { - pSubMaterial->SetModified(false); - } - } - } - else - { - AZ_Warning("Material Editor", false, "Material '%s' failed to save successfully. Check that the file is writable and has been successfully checked out in source control.", m_name.toUtf8().data()); - } - - return saveSucceeded; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::ClearMatInfo() -{ - m_pMatInfo = nullptr; -} - -////////////////////////////////////////////////////////////////////////// -_smart_ptr CMaterial::GetMatInfo(bool bUseExistingEngineMaterial) -{ - if (!m_pMatInfo) - { - if (m_bDummyMaterial) - { - m_pMatInfo = GetIEditor()->Get3DEngine()->GetMaterialManager()->GetDefaultMaterial(); - AddRef(); // Always keep dummy materials. - return m_pMatInfo; - } - - if (!IsMultiSubMaterial() && !m_shaderItem.m_pShader) - { - LoadShader(); - } - - if (!IsPureChild()) - { - if (bUseExistingEngineMaterial) - { - m_pMatInfo = GetIEditor()->Get3DEngine()->GetMaterialManager()->FindMaterial(GetName().toUtf8().data()); - } - - if (!m_pMatInfo) - { - m_pMatInfo = GetIEditor()->Get3DEngine()->GetMaterialManager()->CreateMaterial(GetName().toUtf8().data(), m_mtlFlags); - } - } - else - { - // Pure child should not be registered with the name. - m_pMatInfo = GetIEditor()->Get3DEngine()->GetMaterialManager()->CreateMaterial("", m_mtlFlags); - m_pMatInfo->SetName(GetName().toUtf8().data()); - } - m_mtlFlags = m_pMatInfo->GetFlags(); - UpdateMatInfo(); - - if (m_pMatInfo->GetUserData() != this) - { - m_pMatInfo->SetUserData(this); - AddRef(); // Let IMaterial keep a reference to us. - } - } - - return m_pMatInfo; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::NotifyChanged() -{ - if (m_bIgnoreNotifyChange) - { - return; - } - - if (!CanModify() && !IsModified() && CUndo::IsRecording()) - { - // Display Warning message. - Warning("Modifying read only material %s\r\nChanges will not be saved!", GetName().toUtf8().data()); - } - - SetModified(); - - GetIEditor()->GetMaterialManager()->OnItemChanged(this); -} - -////////////////////////////////////////////////////////////////////////// -class CUndoMaterial - : public IUndoObject -{ -public: - CUndoMaterial(CMaterial* pMaterial, const char* undoDescription, bool bForceUpdate) - { - assert(pMaterial); - - // Stores the current state of this object. - m_undoDescription = undoDescription; - - m_bIsSubMaterial = pMaterial->IsPureChild(); - - if (m_bIsSubMaterial) - { - CMaterial* pParentMaterial = pMaterial->GetParent(); - assert(pParentMaterial && !pParentMaterial->IsPureChild()); - if (pParentMaterial && !pParentMaterial->IsPureChild()) - { - bool bFound = false; - const int subMaterialCount = pParentMaterial->GetSubMaterialCount(); - for (int i = 0; i < subMaterialCount; ++i) - { - CMaterial* pSubMaterial = pParentMaterial->GetSubMaterial(i); - if (pSubMaterial == pMaterial) - { - bFound = true; - m_subMaterialName = pSubMaterial->GetName(); - break; - } - } - assert(bFound); - m_mtlName = pParentMaterial->GetName(); - } - } - else - { - m_mtlName = pMaterial->GetName(); - } - - // Save material XML to a file that corresponds to the material name with extension .mtl. - m_undo = XmlHelpers::CreateXmlNode("Material"); - CBaseLibraryItem::SerializeContext ctx(m_undo, false); - pMaterial->Serialize(ctx); - m_bForceUpdate = bForceUpdate; - } - -protected: - virtual void Release() { delete this; }; - - virtual int GetSize() - { - return sizeof(*this) + m_undoDescription.length() + m_mtlName.length(); - } - - virtual QString GetDescription() { return m_undoDescription; }; - - virtual void Undo(bool bUndo) - { - CMaterial* pMaterial = GetMaterial(); - - assert(pMaterial); - if (!pMaterial) - { - return; - } - - if (bUndo) - { - // Save current object state. - m_redo = XmlHelpers::CreateXmlNode("Material"); - CBaseLibraryItem::SerializeContext ctx(m_redo, false); - pMaterial->Serialize(ctx); - } - - CBaseLibraryItem::SerializeContext ctx(m_undo, true); - ctx.bUndo = bUndo; - pMaterial->Serialize(ctx); - - if (m_bForceUpdate && bUndo) - { - GetIEditor()->GetMaterialManager()->OnUpdateProperties(pMaterial, true); - } - } - - virtual void Redo() - { - CMaterial* pMaterial = GetMaterial(); - - if (!pMaterial) - { - return; - } - - CBaseLibraryItem::SerializeContext ctx(m_redo, true); - ctx.bUndo = true; - pMaterial->Serialize(ctx); - - if (m_bForceUpdate) - { - GetIEditor()->GetMaterialManager()->OnUpdateProperties(pMaterial, true); - } - } - -private: - CMaterial* GetMaterial() - { - CMaterial* pMaterial = (CMaterial*)GetIEditor()->GetMaterialManager()->FindItemByName(m_mtlName); - assert(pMaterial); - - if (pMaterial && m_bIsSubMaterial) - { - bool bFound = false; - const int subMaterialCount = pMaterial->GetSubMaterialCount(); - for (int i = 0; i < subMaterialCount; ++i) - { - CMaterial* pSubMaterial = pMaterial->GetSubMaterial(i); - if (pSubMaterial && (pSubMaterial->GetName() == m_subMaterialName)) - { - bFound = true; - pMaterial = pSubMaterial; - break; - } - } - assert(bFound && pMaterial); - } - - return pMaterial; - } - - QString m_undoDescription; - QString m_mtlName; - bool m_bIsSubMaterial; - QString m_subMaterialName; - XmlNodeRef m_undo; - XmlNodeRef m_redo; - bool m_bForceUpdate; -}; - -////////////////////////////////////////////////////////////////////////// -void CMaterial::RecordUndo(const char* sText, bool bForceUpdate) -{ - if (CUndo::IsRecording()) - { - CUndo::Record(new CUndoMaterial(this, sText, bForceUpdate)); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::OnMakeCurrent() -{ - UpdateFileAttributes(false); - - // If Shader not yet loaded, load it now. - if (!m_shaderItem.m_pShader) - { - LoadShader(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetSurfaceTypeName(const QString& surfaceType) -{ - m_surfaceType = surfaceType; - UpdateMatInfo(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::Reload() -{ - if (IsPureChild()) - { - if (m_pParent) - { - m_pParent->Reload(); - } - return; - } - if (IsDummy()) - { - return; - } - - XmlNodeRef mtlNode = GetISystem()->LoadXmlFromFile(GetFilename().toUtf8().data()); - if (!mtlNode) - { - return; - } - CBaseLibraryItem::SerializeContext serCtx(mtlNode, true); - serCtx.bUndo = true; // Simulate undo. - Serialize(serCtx); - - // was called by Simulate undo. - //UpdateMatInfo(); - //NotifyChanged(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::LinkToMaterial(const QString& name) -{ - m_linkedMaterial = name; - UpdateMatInfo(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::DisableHighlightForFrame() -{ - SetHighlightFlags(0); -} - -static ColorF Interpolate(const ColorF& a, const ColorF& b, float phase) -{ - const float oneMinusPhase = 1.0f - phase; - return ColorF(b.r * phase + a.r * oneMinusPhase, - b.g * phase + a.g * oneMinusPhase, - b.b * phase + a.b * oneMinusPhase, - b.a * phase + a.a * oneMinusPhase); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::UpdateHighlighting() -{ - if (!(GetFlags() & MTL_FLAG_NODRAW)) - { - const CInputLightMaterial& original = m_shaderResources.m_LMaterial; - CInputLightMaterial lm = original; - - ColorF highlightColor(0.0f, 0.0f, 0.0f, 1.0f); - float highlightIntensity = 0.0f; - - MAKE_SURE(GetIEditor()->GetMaterialManager(), return ); - GetIEditor()->GetMaterialManager()->GetHighlightColor(&highlightColor, &highlightIntensity, m_highlightFlags); - - if (m_shaderItem.m_pShaderResources) - { - ColorF diffuseColor = Interpolate(original.m_Diffuse, highlightColor, highlightIntensity); - ColorF emissiveColor = Interpolate(original.m_Emittance, highlightColor, highlightIntensity); - ColorF specularColor = Interpolate(original.m_Specular, highlightColor, highlightIntensity); - - // [Shader System TO DO] remove this hard coded association! - m_shaderItem.m_pShaderResources->SetColorValue(EFTT_DIFFUSE, diffuseColor); - m_shaderItem.m_pShaderResources->SetColorValue(EFTT_SPECULAR, specularColor); - m_shaderItem.m_pShaderResources->SetColorValue(EFTT_EMITTANCE, emissiveColor); - - m_shaderItem.m_pShaderResources->UpdateConstants(m_shaderItem.m_pShader); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetHighlightFlags(int highlightFlags) -{ - m_highlightFlags = highlightFlags; - - UpdateHighlighting(); -} - - -void CMaterial::SetShaderItem(const SShaderItem& shaderItem) -{ - SAFE_RELEASE(m_shaderItem.m_pShader); - SAFE_RELEASE(m_shaderItem.m_pShaderResources); - - m_shaderItem = shaderItem; - if (m_shaderItem.m_pShader) - { - m_shaderItem.m_pShader->AddRef(); - } - if (m_shaderItem.m_pShaderResources) - { - m_shaderItem.m_pShaderResources->AddRef(); - } -} diff --git a/Code/Sandbox/Editor/Material/Material.h b/Code/Sandbox/Editor/Material/Material.h deleted file mode 100644 index b311744e14..0000000000 --- a/Code/Sandbox/Editor/Material/Material.h +++ /dev/null @@ -1,315 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_MATERIAL_MATERIAL_H -#define CRYINCLUDE_EDITOR_MATERIAL_MATERIAL_H -#pragma once - -#include -#include -#include "BaseLibraryItem.h" -#include "Include/IEditorMaterial.h" -#include "Util/Variable.h" -#include - -// forward declarations, -class CMaterialManager; -class CVarBlock; - -enum eMTL_PROPAGATION -{ - MTL_PROPAGATE_OPACITY = 1 << 0, - MTL_PROPAGATE_LIGHTING = 1 << 1, - MTL_PROPAGATE_ADVANCED = 1 << 2, - MTL_PROPAGATE_TEXTURES = 1 << 3, - MTL_PROPAGATE_SHADER_PARAMS = 1 << 4, - MTL_PROPAGATE_SHADER_GEN = 1 << 5, - MTL_PROPAGATE_VERTEX_DEF = 1 << 6, - MTL_PROPAGATE_LAYER_PRESETS = 1 << 7, - MTL_PROPAGATE_MATERIAL_SETTINGS = 1 << 8, - MTL_PROPAGATE_ALL = ( - MTL_PROPAGATE_OPACITY | - MTL_PROPAGATE_LIGHTING | - MTL_PROPAGATE_ADVANCED | - MTL_PROPAGATE_TEXTURES | - MTL_PROPAGATE_SHADER_PARAMS | - MTL_PROPAGATE_SHADER_GEN | - MTL_PROPAGATE_VERTEX_DEF | - MTL_PROPAGATE_LAYER_PRESETS | - MTL_PROPAGATE_MATERIAL_SETTINGS), - MTL_PROPAGATE_RESERVED = 1 << 9 -}; - -/** CMaterial class - Every Material is a member of material library. - Materials can have child sub materials, - Sub materials are applied to the same geometry of the parent material in the other material slots. -*/ - -struct SMaterialLayerResources -{ - SMaterialLayerResources() - : m_nFlags(MTL_LAYER_USAGE_REPLACEBASE) - , m_bRegetPublicParams(true) - , m_pMatLayer(0) - { - } - - uint8 m_nFlags; - bool m_bRegetPublicParams; - QString m_shaderName; - - _smart_ptr< IMaterialLayer > m_pMatLayer; - SInputShaderResources m_shaderResources; - XmlNodeRef m_publicVarsCache; -}; - -AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING -class CRYEDIT_API CMaterial - : public IEditorMaterial -{ -AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING -public: - ////////////////////////////////////////////////////////////////////////// - CMaterial(const QString& name, int nFlags = 0); - CMaterial(const CMaterial& rhs); - ~CMaterial(); - - virtual EDataBaseItemType GetType() const { return EDB_TYPE_MATERIAL; }; - - void SetName(const QString& name); - - ////////////////////////////////////////////////////////////////////////// - QString GetFullName() const { return m_name; }; - - ////////////////////////////////////////////////////////////////////////// - // File properties of the material. - ////////////////////////////////////////////////////////////////////////// - QString GetFilename() const; - - //! Collect filenames of texture sources used in material - //! Return number of filenames - int GetTextureFilenames(QStringList& outFilenames) const; - int GetAnyTextureFilenames(QStringList& outFilenames) const; - - void UpdateFileAttributes(bool useSourceControl = true); - uint32 GetFileAttributes(); - ////////////////////////////////////////////////////////////////////////// - - //! Sets one or more material flags from EMaterialFlags enum. - void SetFlags(int flags) { m_mtlFlags = flags; }; - //! Query this material flags. - virtual int GetFlags() const { return m_mtlFlags; } - bool IsMultiSubMaterial() const { return (m_mtlFlags & MTL_FLAG_MULTI_SUBMTL) != 0; }; - bool IsPureChild() const { return (m_mtlFlags & MTL_FLAG_PURE_CHILD) != 0; } - - // Check if material is used. - bool IsUsed() const { /*return m_nUseCount > 0 || (m_mtlFlags & MTL_FLAG_ALWAYS_USED);*/ return true; }; - - virtual void GatherUsedResources(CUsedResources& resources); - - //! Set name of shader used by this material. - void SetShaderName(const QString& shaderName); - //! Get name of shader used by this material. - QString GetShaderName() const { return m_shaderName; }; - - virtual SInputShaderResources& GetShaderResources() { return m_shaderResources; }; - - //! Get public parameters of material in variable block. - CVarBlock* GetPublicVars(SInputShaderResources& pShaderResources); - - //! Set the shader public param m_script variable into our own m_script, script contains min/max for a given shader param value - void SetShaderParamPublicScript(); - - //! Sets variable block of public shader parameters. - //! VarBlock must be in same format as returned by GetPublicVars(). - void SetPublicVars(CVarBlock* pPublicVars, CMaterial* pMtl); - - //! Update names/descriptions in this variable array, return a variable block for replacing - CVarBlock* UpdateTextureNames(CSmartVariableArray textureVars[EFTT_MAX]); -// [Shader System] - Do To: add back with map usage: CVarBlock* UpdateTextureNames(AZStd::unordered_map& textureVarsMap); - - ////////////////////////////////////////////////////////////////////////// - CVarBlock* GetShaderGenParamsVars(); - void SetShaderGenParamsVars(CVarBlock* pBlock); - uint64 GetShaderGenMask() { return m_nShaderGenMask; } - void SetShaderGenMask(uint64 mask) { m_nShaderGenMask = mask; } - - //! Return variable block of shader params. - SShaderItem& GetShaderItem() { return m_shaderItem; }; - - //! Return material layers resources - SMaterialLayerResources* GetMtlLayerResources() { return m_pMtlLayerResources; }; - - //! Get texture map usage mask for shader in this material. - unsigned int GetTexmapUsageMask() const; - - //! Load new shader. - bool LoadShader(); - - //! Reload shader, update all shader parameters. - virtual void Update(); - - // Reload material settings from file. - // NOTICE: The function will remove all the sub-materials and recreate them! - void Reload(); - - //! Serialize material settings to xml. - virtual void Serialize(SerializeContext& ctx); - - //! Assign this material to static geometry. - void AssignToEntity(IRenderNode* pEntity); - - ////////////////////////////////////////////////////////////////////////// - // Surface types. - ////////////////////////////////////////////////////////////////////////// - virtual void SetSurfaceTypeName(const QString& surfaceType); - virtual const QString& GetSurfaceTypeName() const { return m_surfaceType; }; - bool IsBreakable2D() const; - - ////////////////////////////////////////////////////////////////////////// - // Child Sub materials. - ////////////////////////////////////////////////////////////////////////// - //! Get number of sub materials childs. - int GetSubMaterialCount() const; - //! Set number of sub materials childs. - void SetSubMaterialCount(int nSubMtlsCount); - //! Get sub material child by index. - CMaterial* GetSubMaterial(int index) const; - //! Find sub material index by name - int FindMaterialIndex(const QString& name); - // Set a material to the sub materials slot. - // Use NULL material pointer to clear slot. - void SetSubMaterial(int nSlot, CMaterial* mtl); - //! Remove all sub materials, does not change number of sub material slots. - void ClearAllSubMaterials(); - - //! Return pointer to engine material. - virtual _smart_ptr GetMatInfo(bool bUseExistingEngineMaterial = true); - // Clear stored pointer to engine material. - void ClearMatInfo(); - - //! Validate materials for errors. - void Validate(); - - // Check if material file can be modified. - // Will check file attributes if it is not read only. - bool CanModify(bool bSkipReadOnly = true); - - // Save material to file. - virtual bool Save(bool bSkipReadOnly = true, const QString& fullPath = ""); - - // Dummy material is just a placeholder item for materials that have not been found on disk. - void SetDummy(bool bDummy) { m_bDummyMaterial = bDummy; } - bool IsDummy() const { return m_bDummyMaterial != 0; } - - // Called by material manager when material selected as a current material. - void OnMakeCurrent(); - - void SetFromMatInfo(_smart_ptr pMatInfo); - - // Link a submaterial by name (used for value propagation in CMaterialUI) - void LinkToMaterial(const QString& name); - const QString& GetLinkedMaterialName() { return m_linkedMaterial; } - - // Return parent material for submaterial - CMaterial* GetParent() const {return m_pParent; } - - //! Loads material layers - bool LoadMaterialLayers(); - //! Updates material layers - void UpdateMaterialLayers(); - - void SetHighlightFlags(int highlightFlags); - void UpdateHighlighting(); - virtual void DisableHighlightForFrame(); - void RecordUndo(const char* sText, bool bForceUpdate = false); - - int GetPropagationFlags() const { return m_propagationFlags; } - void SetPropagationFlags(const int flags) { m_propagationFlags = flags; } - - bool LayerActivationAllowed() const { return m_allowLayerActivation; } - void SetLayerActivation(bool allowed) { m_allowLayerActivation = allowed; } - - uint32 GetDccMaterialHash() const { return m_dccMaterialHash; } - void SetDccMaterialHash(AZ::u32 hash) { m_dccMaterialHash = hash; } - void SetShaderItem(const SShaderItem& shaderItem); - -private: - void UpdateMatInfo(); - void CheckSpecialConditions(); - - void NotifyChanged(); - -private: - ////////////////////////////////////////////////////////////////////////// - // Variables. - ////////////////////////////////////////////////////////////////////////// - QString m_shaderName; - QString m_surfaceType; - QString m_linkedMaterial; - - //! Material flags. - int m_mtlFlags; - - // Hash for DCC material attributes, used to check if .dccmtl has changed - // If so, the source .mtl file will need to be rebuilt - uint32 m_dccMaterialHash; - - // Parent material, Only valid for Pure Childs. - CMaterial* m_pParent; - - ////////////////////////////////////////////////////////////////////////// - // Shader resources. - ////////////////////////////////////////////////////////////////////////// - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - SShaderItem m_shaderItem; - SInputShaderResources m_shaderResources; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - - //CVarBlockPtr m_shaderParamsVar; - //! Common shader flags. - uint64 m_nShaderGenMask; - QString m_pszShaderGenMask; - - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - SMaterialLayerResources m_pMtlLayerResources[MTL_LAYER_MAX_SLOTS]; - - _smart_ptr m_pMatInfo; - - XmlNodeRef m_publicVarsCache; - - //! Array of sub materials. - std::vector<_smart_ptr > m_subMaterials; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - - int m_nUseCount; - uint32 m_scFileAttributes; - - unsigned char m_highlightFlags; - - // The propagation flags are a bit combination of the MTL_PROPAGATION enum above - // and determine which properties get propagated to an optional linked material - // during ui editing - int m_propagationFlags; - - //! Material Used in level. - unsigned int m_bDummyMaterial : 1; // Dummy material, name specified but material file not found. - unsigned int m_bIgnoreNotifyChange : 1; // Do not send notifications about changes. - unsigned int m_bRegetPublicParams : 1; - unsigned int m_bKeepPublicParamsValues : 1; - - bool m_allowLayerActivation; -}; - -#endif // CRYINCLUDE_EDITOR_MATERIAL_MATERIAL_H diff --git a/Code/Sandbox/Editor/Material/MaterialBrowser.cpp b/Code/Sandbox/Editor/Material/MaterialBrowser.cpp deleted file mode 100644 index e39a29a47d..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialBrowser.cpp +++ /dev/null @@ -1,1792 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "MaterialBrowser.h" - -// Qt -#include - -// AzQtComponents -#include - -// AzToolsFramework -#include - -// Editor -#include "MaterialManager.h" -#include "Clipboard.h" -#include "MaterialImageListCtrl.h" -#include "StringDlg.h" - -AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING -#include -AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - - -enum -{ - MENU_UNDEFINED = CMaterialImageListCtrl::MaterialBrowserWidgetActionsStart, - MENU_CUT, - MENU_COPY, - MENU_COPY_NAME, - MENU_PASTE, - MENU_EXPLORE, - MENU_DUPLICATE, - MENU_EXTRACT, - MENU_RENAME, - MENU_DELETE, - MENU_RESET, - MENU_ASSIGNTOSELECTION, - MENU_SELECTASSIGNEDOBJECTS, - MENU_NUM_SUBMTL, - MENU_ADDNEW, - MENU_ADDNEW_MULTI, - MENU_CONVERT_TO_MULTI, - MENU_SUBMTL_MAKE, - MENU_SUBMTL_CLEAR, - MENU_SAVE_TO_FILE, - MENU_SAVE_TO_FILE_MULTI, - MENU_MERGE, - - MENU_SCM_ADD, - MENU_SCM_CHECK_OUT, - MENU_SCM_UNDO_CHECK_OUT, - MENU_SCM_GET_LATEST, - MENU_SCM_GET_LATEST_TEXTURES, -}; - -static QAction* CreateTreeViewAction(const char* text, const QKeySequence& shortcut, QWidget* shortcutContext, MaterialBrowserWidget* widget, void (MaterialBrowserWidget::*slot)()) -{ - QAction* action = new QAction(text, shortcutContext); - action->setShortcut(shortcut); - QObject::connect(action, &QAction::triggered, widget, slot); - widget->addAction(action); - return action; -} - -////////////////////////////////////////////////////////////////////////// -MaterialBrowserWidget::MaterialBrowserWidget(QWidget* parent) - : QWidget(parent) - , m_ui(new Ui::MaterialBrowser) - , m_filterModel(new MaterialBrowserFilterModel(this)) -{ - using namespace AzToolsFramework::AssetBrowser; - - m_ui->setupUi(this); - - // create some permanent (for the life of this widget) actions for shortcut handling - m_cutAction = CreateTreeViewAction("Cut", QKeySequence::Cut, m_ui->treeView, this, &MaterialBrowserWidget::OnCut); - m_copyAction = CreateTreeViewAction("Copy", QKeySequence::Copy, m_ui->treeView, this, &MaterialBrowserWidget::OnCopy); - m_pasteAction = CreateTreeViewAction("Paste", QKeySequence::Paste, m_ui->treeView, this, &MaterialBrowserWidget::OnPaste); - m_duplicateAction = CreateTreeViewAction("Duplicate", QKeySequence(Qt::CTRL + Qt::Key_D), m_ui->treeView, this, &MaterialBrowserWidget::OnDuplicate); - m_deleteAction = CreateTreeViewAction("Delete", QKeySequence::Delete, m_ui->treeView, this, &MaterialBrowserWidget::DeleteItem); - m_renameItemAction = CreateTreeViewAction("Rename", Qt::Key_F2, m_ui->treeView, this, &MaterialBrowserWidget::OnRenameItem); - m_addNewMaterialAction = CreateTreeViewAction("Add New Material", Qt::Key_Insert, m_ui->treeView, this, &MaterialBrowserWidget::OnAddNewMaterial); - - MaterialBrowserWidgetBus::Handler::BusConnect(); - - // Get the asset browser model - AssetBrowserComponentRequestBus::BroadcastResult(m_assetBrowserModel, &AssetBrowserComponentRequests::GetAssetBrowserModel); - AZ_Assert(m_assetBrowserModel, "Failed to get filebrowser model"); - - // Set up the filter model - m_filterModel->setSourceModel(m_assetBrowserModel); - m_ui->treeView->setModel(m_filterModel.data()); - m_ui->treeView->SetThumbnailContext("MaterialBrowser"); - m_ui->treeView->SetShowSourceControlIcons(true); - - m_ui->m_searchWidget->Setup(true, false); - m_filterModel->SetSearchFilter(m_ui->m_searchWidget); - connect(m_ui->m_searchWidget->GetFilter().data(), &AssetBrowserEntryFilter::updatedSignal, m_filterModel.data(), &MaterialBrowserFilterModel::SearchFilterUpdated); - - // Call LoadState to initialize the AssetBrowserTreeView's QTreeViewStateSaver - // This must be done BEFORE StartRecordUpdateJobs(). A race condition from the update jobs was causing a 5-10% crash/hang when opening the Material Editor. - m_ui->treeView->SetName("MaterialBrowserTreeView"); - - // Override the AssetBrowserTreeView's custom context menu - disconnect(m_ui->treeView, &QWidget::customContextMenuRequested, 0, 0); - connect(m_ui->treeView, &QWidget::customContextMenuRequested, this, [=](const QPoint& point) - { - CMaterialBrowserRecord record; - TryGetSelectedRecord(record); - ShowContextMenu(record, point); - }); - - connect(m_ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &MaterialBrowserWidget::OnSelectionChanged); - //Wait for the signal emitted on record update jobs finished, then we can restore the selection for the previous selected item - connect(this, SIGNAL(refreshSelection()), this, SLOT(OnRefreshSelection())); - - connect(this, SIGNAL(materialAdded()), this, SLOT(OnMaterialAdded())); - - m_bIgnoreSelectionChange = false; - m_bItemsValid = true; - - m_pMatMan = GetIEditor()->GetMaterialManager(); - m_pMatMan->AddListener(this); - m_pListener = NULL; - - m_viewType = VIEW_LEVEL; - m_pMaterialImageListCtrl = NULL; - m_pLastActiveMultiMaterial = 0; - - m_bNeedReload = false; - - m_bHighlightMaterial = false; - m_timeOfHighlight = 0; - - m_bShowOnlyCheckedOut = false; - - GetIEditor()->RegisterNotifyListener(this); -} - -////////////////////////////////////////////////////////////////////////// -MaterialBrowserWidget::~MaterialBrowserWidget() -{ - m_filterModel->CancelRecordUpdateJobs(); - m_filterModel->deleteLater(); - m_ui->treeView->SaveState(); - GetIEditor()->UnregisterNotifyListener(this); - - m_pMaterialImageListCtrl = NULL; - m_pMatMan->RemoveListener(this); - ClearItems(); - - if (m_bHighlightMaterial) - { - m_pMatMan->SetHighlightedMaterial(0); - } - - MaterialBrowserWidgetBus::Handler::BusDisconnect(); -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::ClearItems() -{ - m_bIgnoreSelectionChange = true; - - if (m_pMaterialImageListCtrl) - { - QMaterialImageListModel* materialModel = - qobject_cast(m_pMaterialImageListCtrl->model()); - Q_ASSERT(materialModel); - materialModel->DeleteAllItems(); - } - - m_pLastActiveMultiMaterial = nullptr; - m_delayedSelection = nullptr; - - m_bIgnoreSelectionChange = false; -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::TryLoadRecordMaterial(CMaterialBrowserRecord& record) -{ - // If material already loaded ignore. - if (record.m_material) - { - return; - } - - m_bIgnoreSelectionChange = true; - // Try to load material for it. - record.m_material = m_pMatMan->LoadMaterial(record.GetRelativeFilePath().c_str(), false); - - m_filterModel->SetRecord(record); - m_bIgnoreSelectionChange = false; -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::TickRefreshMaterials() -{ - if (m_bHighlightMaterial) - { - uint32 t = GetTickCount(); - if ((t - m_timeOfHighlight) > 300) - { - m_bHighlightMaterial = false; - m_pMatMan->SetHighlightedMaterial(0); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnEditorNotifyEvent(EEditorNotifyEvent event) -{ - switch (event) - { - case eNotify_OnIdleUpdate: - { - TickRefreshMaterials(); - } - break; - case eNotify_OnBeginLoad: - { - //Need to make sure the selection is cleared before clearing the record map - SetSelectedItem(nullptr, nullptr, true); - m_filterModel->ClearRecordMap(); - } - break; - case eNotify_OnCloseScene: - { - m_filterModel->ShowOnlyLevelMaterials(false, true); - ClearItems(); - m_ui->treeView->SaveState(); - //Need to make sure the selection is cleared before clearing the record map - SetSelectedItem(nullptr, nullptr, true); - m_filterModel->ClearRecordMap(); - } - break; - case eNotify_OnEndNewScene: - case eNotify_OnEndSceneOpen: - { - m_filterModel->ShowOnlyLevelMaterials(false, true); - m_filterModel->StartRecordUpdateJobs(); - if (m_ui->treeView->IsTreeViewSavingReady()) - { - m_ui->treeView->ApplyTreeViewSnapshot(); - } - } - break; - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::SetSelectedItem(_smart_ptr material, const TMaterialBrowserRecords* pMarkedRecords, bool selectInTreeView) -{ - if (m_bIgnoreSelectionChange) - { - return; - } - - m_bIgnoreSelectionChange = true; - if (pMarkedRecords) - { - m_markedRecords = *pMarkedRecords; - } - else - { - m_markedRecords.clear(); - } - - m_pMatMan->SetCurrentFolder(""); - - _smart_ptr selectedMaterial = material; - if (material && material->IsPureChild()) - { - selectedMaterial = material->GetParent(); - } - - // Clear the delayed selection whenever a new material is selected - m_delayedSelection = nullptr; - - // In some cases, such as when SetSelectedItem is called from the material picker or the rollup bar, - // the material has not yet been selected in the tree-view, so that item must be selected here - bool validSelection = false; - if (selectInTreeView) - { - if (!selectedMaterial) - { - // Clear the current selection so that the upcoming call to RefreshSelected() - // doesn't try to refresh the previously selected material which may be invalid - m_ui->treeView->clearSelection(); - m_ui->treeView->setCurrentIndex(QModelIndex()); - } - else if (m_markedRecords.size() > 0) - { - QItemSelection selection; - for (CMaterialBrowserRecord record : m_markedRecords) - { - QModelIndex currentIndex = m_filterModel->GetIndexFromMaterial(record.m_material); - if (currentIndex.isValid()) - { - selection.push_back(QItemSelectionRange(currentIndex)); - validSelection = true; - } - } - m_ui->treeView->selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect); - } - else - { - QModelIndex currentIndex = m_filterModel->GetIndexFromMaterial(selectedMaterial); - if (currentIndex.isValid()) - { - m_ui->treeView->selectionModel()->setCurrentIndex(currentIndex, QItemSelectionModel::ClearAndSelect); - validSelection = true; - - // Now that the parent material is selected in the browser, - // select the appropriate sub-material in the material preview window - if (selectedMaterial == material->GetParent()) - { - for (int i = 0; i < selectedMaterial->GetSubMaterialCount(); ++i) - { - if (material == selectedMaterial->GetSubMaterial(i)) - { - m_selectedSubMaterialIndex = i; - break; - } - } - } - } - else - { - // Hold on to a pointer to this material, listen for the MaterialFinishedProcessing event, - // and attempt to re-select this material if it finishes processing in the background - m_delayedSelection = selectedMaterial; - } - } - } - - RefreshSelected(); - - if (!selectedMaterial) - { - QModelIndex current = m_ui->treeView->currentIndex(); - QString path; - while (current.isValid()) - { - path = '/' + current.data().toString() + path; - current = current.parent(); - } - m_pMatMan->SetCurrentFolder((Path::GetEditingGameDataFolder() + path.toUtf8().data()).c_str()); - } - else - { - if (selectedMaterial->IsMultiSubMaterial() && m_selectedSubMaterialIndex >= 0) - { - selectedMaterial = selectedMaterial->GetSubMaterial(m_selectedSubMaterialIndex); - } - } - - if (m_pListener) - { - // Don't call the listener event if we attempted to select an item in the tree view and failed - // to prevent the material parameter editor from switching to a new material if it wasn't actually selected - if (!selectInTreeView || validSelection) - { - m_pListener->OnBrowserSelectItem(selectedMaterial, false); - } - //Update the selected item if no material is selected in tree view - else if (!selectedMaterial && selectInTreeView) - { - m_pListener->OnBrowserSelectItem(nullptr, false); - } - } - - m_timeOfHighlight = GetTickCount(); - m_pMatMan->SetHighlightedMaterial(selectedMaterial); - if (selectedMaterial) - { - m_bHighlightMaterial = true; - } - - std::vector<_smart_ptr > markedMaterials; - if (pMarkedRecords) - { - for (size_t i = 0; i < pMarkedRecords->size(); ++i) - { - markedMaterials.push_back((*pMarkedRecords)[i].m_material); - } - } - m_pMatMan->SetMarkedMaterials(markedMaterials); - - m_bIgnoreSelectionChange = false; -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::SelectItem(IDataBaseItem* pItem, [[maybe_unused]] IDataBaseItem* pParentItem) -{ - if (m_bIgnoreSelectionChange) - { - return; - } - - if (!pItem) - { - return; - } - - _smart_ptr material = static_cast(pItem); - SetSelectedItem(material, 0, true); -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnDuplicate() -{ - GetIEditor()->GetMaterialManager()->Command_Merge(); -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnCut() -{ - CMaterialBrowserRecord record; - bool found = TryGetSelectedRecord(record); - if (found) - { - OnCopy(); - DeleteItem(record); - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnCopyName() -{ - _smart_ptr pMtl = GetCurrentMaterial(); - if (pMtl) - { - CClipboard clipboard(this); - clipboard.PutString(pMtl->GetName(), "Material Name"); - } -} - -void MaterialBrowserWidget::ShowOnlyLevelMaterials(bool levelOnly) -{ - m_filterModel->ShowOnlyLevelMaterials(levelOnly); -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnCopy() -{ - _smart_ptr pMtl = GetCurrentMaterial(); - if (pMtl) - { - CClipboard clipboard(this); - XmlNodeRef node = XmlHelpers::CreateXmlNode("Material"); - node->setAttr("Name", pMtl->GetName().toUtf8().data()); - CBaseLibraryItem::SerializeContext ctx(node, false); - ctx.bCopyPaste = true; - pMtl->Serialize(ctx); - clipboard.Put(node); - } -} - -////////////////////////////////////////////////////////////////////////// -bool MaterialBrowserWidget::CanPaste() const -{ - CClipboard clipboard(nullptr); - if (clipboard.IsEmpty()) - { - return false; - } - XmlNodeRef node = clipboard.Get(); - if (!node) - { - return false; - } - - if (strcmp(node->getTag(), "Material") == 0) - { - return true; - } - return false; -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnPaste() -{ - CClipboard clipboard(this); - if (clipboard.IsEmpty()) - { - return; - } - XmlNodeRef node = clipboard.Get(); - if (!node) - { - return; - } - - if (strcmp(node->getTag(), "Material") == 0) - { - if (!m_pMatMan->GetCurrentMaterial()) - { - GetIEditor()->GetMaterialManager()->Command_Create(); - } - - _smart_ptr pMtl = m_pMatMan->GetCurrentMaterial(); - if (pMtl) - { - // This is material node. - CBaseLibraryItem::SerializeContext serCtx(node, true); - serCtx.bCopyPaste = true; - serCtx.bUniqName = true; - pMtl->Serialize(serCtx); - - SelectItem(pMtl, NULL); - pMtl->Save(); - pMtl->Reload(); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnAddNewMaterial() -{ - GetIEditor()->GetMaterialManager()->Command_Create(); -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnAddNewMultiMaterial() -{ - GetIEditor()->GetMaterialManager()->Command_CreateMulti(); -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnMergeMaterials() -{ - GetIEditor()->GetMaterialManager()->Command_Merge(); -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnConvertToMulti() -{ - GetIEditor()->GetMaterialManager()->Command_ConvertToMulti(); -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::DeleteItem() -{ - CMaterialBrowserRecord record; - bool found = TryGetSelectedRecord(record); - if (found) - { - DeleteItem(record); - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnResetItem() -{ - if (QMessageBox::question(this, tr("Reset Material"), tr("Reset Material to default?")) == QMessageBox::Yes) - { - _smart_ptr pMtl = GetCurrentMaterial(); - int index; - - pMtl->GetSubMaterialCount() > 0 ? index = pMtl->GetSubMaterialCount() : index = 1; - - if (pMtl) - { - for (int i = 0; i < index; i++) - { - pMtl->GetSubMaterialCount() > 0 ? pMtl->GetSubMaterial(i)->Reload() : pMtl->Reload(); - TickRefreshMaterials(); - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::DeleteItem(const CMaterialBrowserRecord& record) -{ - _smart_ptr pMtl = record.m_material; - if (pMtl) - { - if (m_selectedSubMaterialIndex >= 0) - { - pMtl = pMtl->GetSubMaterial(m_selectedSubMaterialIndex); - OnClearSubMtlSlot(pMtl); - } - else - { - GetIEditor()->GetMaterialManager()->Command_Delete(); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnRenameItem() -{ - _smart_ptr pMtl = GetCurrentMaterial(); - if (!pMtl) - { - return; - } - - if (pMtl->IsPureChild()) - { - StringDlg dlg(tr("Enter New Sub-Material Name"), this); - dlg.SetString(pMtl->GetName()); - dlg.SetCheckCallback([this](QString name) -> bool - { - static const int MAX_REASONABLE_MATERIAL_NAME = 128; - if (name.length() >= MAX_REASONABLE_MATERIAL_NAME) - { - QMessageBox::warning(this, tr("Name too long"), tr("Please enter a name less than %1 characters").arg(MAX_REASONABLE_MATERIAL_NAME)); - return false; - } - return true; - }); - - if (dlg.exec() == QDialog::Accepted) - { - pMtl->SetName(dlg.GetString()); - pMtl->Save(); - pMtl->Reload(); - } - } - else - { - if ((pMtl->GetFileAttributes() & SCC_FILE_ATTRIBUTE_MANAGED) && - !(pMtl->GetFileAttributes() & SCC_FILE_ATTRIBUTE_CHECKEDOUT)) - { - if (QMessageBox::Cancel == QMessageBox::information(this, tr("Confirm"), tr("Only checked-out files can be renamed. Check out and mark for delete before rename it?"), QMessageBox::Ok | QMessageBox::Cancel)) - { - return; - } - } - - QFileInfo info(pMtl->GetFilename()); - QString filename = info.fileName(); - if (!CFileUtil::SelectSaveFile("Material Files (*.mtl)", "mtl", info.path(), filename)) - { - return; - } - - QString itemName = m_pMatMan->FilenameToMaterial(Path::GetRelativePath(filename)); - if (itemName.isEmpty()) - { - return; - } - - if (m_pMatMan->FindItemByName(itemName)) - { - Warning("Material with name %s already exist", itemName.toUtf8().data()); - return; - } - - if (pMtl->GetFileAttributes() & SCC_FILE_ATTRIBUTE_MANAGED) - { - if (pMtl->GetFileAttributes() & SCC_FILE_ATTRIBUTE_CHECKEDOUT) - { - if (QMessageBox::Cancel == QMessageBox::information(this, tr("Confirm"), tr("The original file will be marked for delete and the new named file will be marked for integration."), QMessageBox::Ok | QMessageBox::Cancel)) - { - return; - } - } - else - { - CFileUtil::CheckoutFile(pMtl->GetFilename().toUtf8().data(), this); - } - - if (!CFileUtil::RenameFile(pMtl->GetFilename().toUtf8().data(), filename.toUtf8().data())) - { - QMessageBox::critical(this, tr("Error"), tr("Could not rename file in Source Control.")); - } - } - - - // Delete file on disk. - if (!pMtl->GetFilename().isEmpty()) - { - QFile::remove(pMtl->GetFilename()); - } - pMtl->SetName(itemName); - pMtl->Save(); - SetSelectedItem(pMtl, 0, true); - } -} - - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnSetSubMtlCount(const CMaterialBrowserRecord& record) -{ - _smart_ptr pMtl = record.m_material; - if (!pMtl) - { - return; - } - - if (!pMtl->IsMultiSubMaterial()) - { - return; - } - - int num = pMtl->GetSubMaterialCount(); - bool ok = false; - num = QInputDialog::getInt(this, tr("Number of Sub Materials"), QStringLiteral(""), num, 0, MAX_SUB_MATERIALS, 1, &ok); - if (ok) - { - if (num != pMtl->GetSubMaterialCount()) - { - if (m_selectedSubMaterialIndex >= num) - { - m_selectedSubMaterialIndex = num - 1; - } - - CUndo undo("Set SubMtl Count"); - pMtl->SetSubMaterialCount(num); - - for (int i = 0; i < num; i++) - { - if (pMtl->GetSubMaterial(i) == 0) - { - // Allocate pure childs for all empty slots. - QString name; - name = QStringLiteral("SubMtl%1").arg(i + 1); - _smart_ptr pChild = new CMaterial(name, MTL_FLAG_PURE_CHILD); - pMtl->SetSubMaterial(i, pChild); - } - } - } - } -} - - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::DoSourceControlOp(CMaterialBrowserRecord& record, ESourceControlOp scmOp) -{ - if (!GetIEditor()->IsSourceControlAvailable()) - { - return; - } - - _smart_ptr pMtl = record.m_material; - - if (pMtl && pMtl->IsPureChild()) - { - pMtl = pMtl->GetParent(); - } - - if (scmOp == ESCM_IMPORT) // don't save unless you're doing an operation which writes. - { - if (pMtl && pMtl->IsModified()) - { - pMtl->Save(); - } - } - - QString path = pMtl ? pMtl->GetFilename() : QString(); - - if (path.isEmpty()) - { - return; - } - - bool bRes = true; - switch (scmOp) - { - case ESCM_IMPORT: - if (pMtl) - { - QStringList filenames; - int nTextures = pMtl->GetTextureFilenames(filenames); - for (int i = 0; i < nTextures; ++i) - { - CFileUtil::CheckoutFile(filenames[i].toUtf8().data(), this); - } - - bRes = CFileUtil::CheckoutFile(path.toUtf8().data(), this); - } - break; - case ESCM_CHECKOUT: - { - if (pMtl && (pMtl->GetFileAttributes() & SCC_FILE_ATTRIBUTE_BYANOTHER)) - { - AZStd::string otherUser("another user"); - AzToolsFramework::SourceControlFileInfo fileInfo; - if (CFileUtil::GetFileInfoFromSourceControl(pMtl->GetFilename().toUtf8().data(), fileInfo, this)) - { - // Sanity check the source control api reports the file is checked out by another - AZ_Assert(fileInfo.HasFlag(AzToolsFramework::SCF_OtherOpen), "File attributes reporting incorrectly"); - otherUser = fileInfo.m_StatusUser; - } - - if (QMessageBox::question(this, QString(), tr("This file is checked out by %1. Try to continue?").arg(otherUser.c_str())) != QMessageBox::Yes) - { - return; - } - } - bRes = CFileUtil::GetLatestFromSourceControl(path.toUtf8().data(), this); - if (bRes) - { - bRes = CFileUtil::CheckoutFile(path.toUtf8().data(), this); - } - } - break; - case ESCM_UNDO_CHECKOUT: - bRes = CFileUtil::RevertFile(path.toUtf8().data(), this); - break; - case ESCM_GETLATEST: - bRes = CFileUtil::GetLatestFromSourceControl(path.toUtf8().data(), this); - break; - case ESCM_GETLATESTTEXTURES: - if (pMtl) - { - QString message; - QStringList filenames; - int nTextures = pMtl->GetTextureFilenames(filenames); - for (int i = 0; i < nTextures; ++i) - { - bRes = CFileUtil::GetLatestFromSourceControl(filenames[i].toUtf8().data(), this); - message += Path::GetRelativePath(filenames[i], true) + (bRes ? " [OK]" : " [Fail]") + "\n"; - } - QMessageBox::information(this, QString(), message.isEmpty() ? tr("No files are affected") : message); - } - return; - } - - if (!bRes) - { - QMessageBox::critical(this, tr("Error"), tr("Source Control Operation Failed.\r\nCheck if Source Control Provider correctly setup and working directory is correct.")); - return; - } - - // force the cache to be rebuilt next time we repaint - record.InitializeSourceControlAttributes(); - m_filterModel->SetRecord(record); - - if (pMtl) - { - pMtl->Reload(); - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnMakeSubMtlSlot(const CMaterialBrowserRecord& record) -{ - if (m_selectedSubMaterialIndex >= 0) - { - _smart_ptr parentMaterial = record.m_material; - if (parentMaterial && parentMaterial->IsMultiSubMaterial()) - { - const QString str = tr("Making new material will override material currently assigned to the slot %1 of %2\r\nMake new sub material?") - .arg(m_selectedSubMaterialIndex).arg(parentMaterial->GetName()); - if (QMessageBox::question(this, tr("Confirm Override"), str) == QMessageBox::Yes) - { - QString name = tr("SubMtl%1") - .arg(m_selectedSubMaterialIndex + 1); - _smart_ptr pMtl = new CMaterial(name, MTL_FLAG_PURE_CHILD); - parentMaterial->SetSubMaterial(m_selectedSubMaterialIndex, pMtl); - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnClearSubMtlSlot(_smart_ptr subMaterial) -{ - if (subMaterial && m_selectedSubMaterialIndex >= 0) - { - _smart_ptr parentMaterial = subMaterial->GetParent(); - if (parentMaterial && parentMaterial->IsMultiSubMaterial()) - { - const QString str = tr("Clear Sub-Material Slot %1 of %2?").arg(m_selectedSubMaterialIndex).arg(parentMaterial->GetName()); - if (QMessageBox::question(this, tr("Clear Sub-Material"), str) == QMessageBox::Yes) - { - CUndo undo("Material Change"); - SetSubMaterial(parentMaterial, m_selectedSubMaterialIndex, 0); - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::SetSubMaterial(_smart_ptr parentMaterial, int slot, _smart_ptr subMaterial) -{ - if (parentMaterial && parentMaterial->IsMultiSubMaterial()) - { - // If the last sub-material is being removed, select the 2nd to last sub-material - if (!subMaterial && slot == parentMaterial->GetSubMaterialCount() - 1) - { - m_selectedSubMaterialIndex = slot - 1; - } - parentMaterial->SetSubMaterial(slot, subMaterial); - } -} - - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnDataBaseItemEvent(IDataBaseItem* pItem, EDataBaseItemEvent event) -{ - if (m_bIgnoreSelectionChange) - { - return; - } - - if (!pItem) - { - return; - } - - - switch (event) - { - case EDB_ITEM_EVENT_ADD: - break; - case EDB_ITEM_EVENT_DELETE: - { - if (pItem) - { - //If the deleted item is selected, remove selection - CMaterial* pMtl = static_cast(pItem); - CMaterial* selectedMaterial = GetCurrentMaterial(); - if (selectedMaterial && selectedMaterial->IsPureChild()) - { - selectedMaterial = selectedMaterial->GetParent(); - } - if (pMtl == selectedMaterial) - { - SetSelectedItem(nullptr, nullptr, true); - } - } - } - break; - case EDB_ITEM_EVENT_CHANGED: - { - CMaterial* pMtl = static_cast(pItem); - CMaterial* selectedMaterial = GetCurrentMaterial(); - if (selectedMaterial && selectedMaterial->IsPureChild()) - { - selectedMaterial = selectedMaterial->GetParent(); - } - // If this is a sub material, refresh parent - if (pMtl->IsPureChild()) - { - pMtl = pMtl->GetParent(); - } - - if (pMtl == selectedMaterial) - { - if (pMtl->IsMultiSubMaterial()) - { - m_pLastActiveMultiMaterial = NULL; - } - RefreshSelected(); - } - m_bItemsValid = false; - } - break; - case EDB_ITEM_EVENT_SELECTED: - { - SelectItem(pItem, NULL); - } - break; - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::SetImageListCtrl(CMaterialImageListCtrl* pCtrl) -{ - m_pMaterialImageListCtrl = pCtrl; - if (m_pMaterialImageListCtrl) - { - connect(m_pMaterialImageListCtrl->selectionModel(), &QItemSelectionModel::currentChanged, - this, &MaterialBrowserWidget::OnSubMaterialSelectedInPreviewPane); - - connect(m_pMaterialImageListCtrl, &QAbstractItemView::clicked, - this, &MaterialBrowserWidget::OnSubMaterialSelectedInPreviewPane); - - m_pMaterialImageListCtrl->SetMaterialBrowserWidget(this); - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnSaveToFile(bool bMulti) -{ - _smart_ptr pCurrentMaterial = GetCurrentMaterial(); - if (pCurrentMaterial) - { - QString startPath = GetIEditor()->GetSearchPath(EDITOR_PATH_MATERIALS); - QString filename; - if (!CFileUtil::SelectSaveFile("Material Files (*.mtl)", "mtl", startPath, filename)) - { - return; - } - QFileInfo info(filename); - QString itemName = info.baseName(); - itemName = Path::MakeGamePath(itemName); - - if (m_pMatMan->FindItemByName(itemName)) - { - Warning("Material with name %s already exist", itemName.toUtf8().data()); - return; - } - int flags = pCurrentMaterial->GetFlags(); - if (bMulti) - { - flags |= MTL_FLAG_MULTI_SUBMTL; - } - - pCurrentMaterial->SetFlags(flags); - - if (pCurrentMaterial->IsDummy()) - { - pCurrentMaterial->ClearMatInfo(); - pCurrentMaterial->SetDummy(false); - } - pCurrentMaterial->SetModified(true); - pCurrentMaterial->Save(); - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::RefreshSelected() -{ - CMaterialBrowserRecord record; - bool found = TryGetSelectedRecord(record); - _smart_ptr pMtl = nullptr; - if (!found) - { - ClearImageListControlSelection(); - return; - } - else - { - pMtl = record.m_material; - } - - if (m_pMaterialImageListCtrl) - { - QMaterialImageListModel* materialModel = - qobject_cast(m_pMaterialImageListCtrl->model()); - Q_ASSERT(materialModel); - - materialModel->InvalidateMaterial(pMtl); - if (pMtl) - { - _smart_ptr pMultiMtl = nullptr; - if (pMtl->IsMultiSubMaterial()) - { - // It's possible that the currently selected sub-material index is beyond the range of the current multi-material if, for example, - // the last sub-material was selected but then the source .mtl file was changed to have fewer total sub-materials - if (m_selectedSubMaterialIndex >= pMtl->GetSubMaterialCount()) - { - // If that's the case, select the last sub-material - // If the sub-material count has dropped to 0, setting m_selectedSubMaterialIndex to -1 will cause the parent material to be selected - m_selectedSubMaterialIndex = pMtl->GetSubMaterialCount() - 1; - } - - pMultiMtl = pMtl; - if (m_selectedSubMaterialIndex >= 0) - { - pMtl = pMtl->GetSubMaterial(m_selectedSubMaterialIndex); - } - } - - if (m_pLastActiveMultiMaterial != pMultiMtl || pMultiMtl == nullptr) - { - // A new material was selected, so the previewer needs to be cleared - materialModel->DeleteAllItems(); - // If the new material was not a multi-material, add it to the previewer - if (pMultiMtl == nullptr) - { - materialModel->AddMaterial(pMtl); - } - } - - // If a new multi-material was selected - if (m_pLastActiveMultiMaterial != pMultiMtl && pMultiMtl != nullptr) - { - // Add all of its submaterials to the previewer - for (size_t i = 0; i < pMultiMtl->GetSubMaterialCount(); i++) - { - if (pMultiMtl->GetSubMaterial(i)) - { - materialModel->AddMaterial(pMultiMtl->GetSubMaterial(i), reinterpret_cast(i)); - } - } - m_pMaterialImageListCtrl->selectionModel()->clear(); - - // If a sub-material was selected in the material browser, select it in the previewer - QModelIndex modelIndex; - if (m_selectedSubMaterialIndex >= 0) - { - modelIndex = materialModel->index(m_selectedSubMaterialIndex, 0); - } - m_pMaterialImageListCtrl->selectionModel()->select(modelIndex, QItemSelectionModel::SelectCurrent); - } - - m_pMaterialImageListCtrl->SelectMaterial(pMtl); - m_pLastActiveMultiMaterial = pMultiMtl; - } - else - { - ClearSelection(materialModel); - } - } -} - -void MaterialBrowserWidget::ClearImageListControlSelection() -{ - QMaterialImageListModel* materialModel = - qobject_cast(m_pMaterialImageListCtrl->model()); - Q_ASSERT(materialModel); - - ClearSelection(materialModel); -} - -void MaterialBrowserWidget::ClearSelection(QMaterialImageListModel* materialModel) -{ - materialModel->DeleteAllItems(); - m_pLastActiveMultiMaterial = nullptr; -} - -////////////////////////////////////////////////////////////////////////// - -void MaterialBrowserWidget::AddContextMenuActionsMultiSelect(QMenu& menu) const -{ - int numMaterialsSelected = 0; - for (int i = 0; i < m_markedRecords.size(); ++i) - { - if (m_markedRecords[i].m_material) - { - ++numMaterialsSelected; - } - } - const QString itemsSelected = tr(" (%1 Materials Selected)").arg(numMaterialsSelected); - menu.addAction(itemsSelected)->setEnabled(false); - menu.addSeparator(); - - if (numMaterialsSelected >= 2) // ... and at least two materials - { - menu.addAction(tr("Merge"))->setData(MENU_MERGE); - } - else - { - menu.addAction(tr("Merge (Select two or more)"))->setEnabled(false); - } -} - -void MaterialBrowserWidget::AddContextMenuActionsNoSelection(QMenu& menu) const -{ - QAction* action = menu.addAction(tr("Paste")); - action->setShortcut(QKeySequence::Paste); - action->setData(MENU_PASTE); - action->setEnabled(CanPaste()); - - menu.addSeparator(); - menu.addAction(tr("Add New Material"))->setData(MENU_ADDNEW); - menu.addAction(tr("Add New Multi Material"))->setData(MENU_ADDNEW_MULTI); - if (GetIEditor()->IsSourceControlAvailable()) - { - menu.addSeparator(); - menu.addAction(tr("Source Control"))->setEnabled(false); - menu.addAction(tr("Check Out"))->setData(MENU_SCM_CHECK_OUT); - menu.addAction(tr("Undo Check Out"))->setData(MENU_SCM_UNDO_CHECK_OUT); - menu.addAction(tr("Get Latest Version"))->setData(MENU_SCM_GET_LATEST); - } -} - -void MaterialBrowserWidget::AddContextMenuActionsSingleSelection(QMenu& menu, _smart_ptr material) const -{ - if (material) - { - if (material->IsMultiSubMaterial()) - { - if (m_selectedSubMaterialIndex >= 0) - { - AddContextMenuActionsSubMaterial(menu, material, material->GetSubMaterial(m_selectedSubMaterialIndex)); - } - else - { - AddContextMenuActionsMultiMaterial(menu); - AddContextMenuActionsCommon(menu, material); - } - } - else if (material->IsPureChild()) - { - AddContextMenuActionsSubMaterial(menu, material->GetParent(), material); - } - else - { - AddContextMenuActionsSingleMaterial(menu); - AddContextMenuActionsCommon(menu, material); - } - } -} - -void MaterialBrowserWidget::AddContextMenuActionsSubMaterial(QMenu& menu, _smart_ptr parentMaterial, _smart_ptr subMaterial) const -{ - bool enabled = true; - - if (parentMaterial) - { - uint32 nFileAttr = parentMaterial->GetFileAttributes(); - if (nFileAttr & SCC_FILE_ATTRIBUTE_READONLY) - { - enabled = false; - } - } - - QAction* action = menu.addAction(tr("Reset sub-material to default")); - action->setData(MENU_SUBMTL_MAKE); - action->setEnabled(enabled); - - menu.addSeparator(); - - action = menu.addAction(tr("Cut")); - action->setShortcut(QKeySequence::Cut); - action->setData(MENU_CUT); - action->setEnabled(enabled); - - action = menu.addAction(tr("Copy")); - action->setShortcut(QKeySequence::Copy); - action->setData(MENU_COPY); - - action = menu.addAction(tr("Paste")); - action->setShortcut(QKeySequence::Paste); - action->setData(MENU_PASTE); - action->setEnabled(CanPaste() && enabled); - - action = menu.addAction(tr("Rename\tF2")); - action->setData(MENU_RENAME); - action->setEnabled(enabled); - - action = menu.addAction(tr("Delete")); - action->setData(MENU_SUBMTL_CLEAR); - action->setEnabled(enabled); -} - -void MaterialBrowserWidget::AddContextMenuActionsMultiMaterial(QMenu& menu) const -{ - menu.addAction(tr("Set Number of Sub-Materials"))->setData(MENU_NUM_SUBMTL); - menu.addSeparator(); -} - -void MaterialBrowserWidget::AddContextMenuActionsSingleMaterial(QMenu& menu) const -{ - menu.addAction(tr("Convert To Multi Material"))->setData(MENU_CONVERT_TO_MULTI); - menu.addSeparator(); -} - -void MaterialBrowserWidget::AddContextMenuActionsCommon(QMenu& menu, _smart_ptr material) const -{ - uint32 fileAttributes = material->GetFileAttributes(); - - bool modificationsEnabled = true; - if (fileAttributes & SCC_FILE_ATTRIBUTE_READONLY) - { - modificationsEnabled = false; - } - - QAction* action = menu.addAction(tr("Cut")); - action->setShortcut(QKeySequence::Cut); - action->setData(MENU_CUT); - action = menu.addAction(tr("Copy")); - action->setShortcut(QKeySequence::Copy); - action->setData(MENU_COPY); - action = menu.addAction(tr("Paste")); - action->setShortcut(QKeySequence::Paste); - action->setData(MENU_PASTE); - action->setEnabled(CanPaste() && modificationsEnabled); - menu.addAction(tr("Copy Path to Clipboard"))->setData(MENU_COPY_NAME); - if (fileAttributes & SCC_FILE_ATTRIBUTE_INPAK) - { - menu.addAction(tr("Extract"))->setData(MENU_EXTRACT); - } - else - { - menu.addAction(tr("Explore"))->setData(MENU_EXPLORE); - } - menu.addSeparator(); - action = menu.addAction(tr("Duplicate")); - action->setShortcut(tr("Ctrl+D")); - action->setData(MENU_DUPLICATE); - menu.addAction(tr("Rename\tF2"))->setData(MENU_RENAME); - action = menu.addAction(tr("Delete")); - action->setShortcut(QKeySequence::Delete); - action->setData(MENU_DELETE); - menu.addSeparator(); - menu.addAction(tr("Assign to Selected Objects"))->setData(MENU_ASSIGNTOSELECTION); - menu.addAction(tr("Select Assigned Objects"))->setData(MENU_SELECTASSIGNEDOBJECTS); - menu.addSeparator(); - - menu.addAction(tr("Add New Material"))->setData(MENU_ADDNEW); - menu.addAction(tr("Add New Multi Material"))->setData(MENU_ADDNEW_MULTI); - menu.addAction(tr("Merge (Select two or more)"))->setEnabled(false); - - AddContextMenuActionsSourceControl(menu, material, fileAttributes); -} - -void MaterialBrowserWidget::AddContextMenuActionsSourceControl(QMenu& menu, _smart_ptr material, uint32 fileAttributes) const -{ - if (GetIEditor()->IsSourceControlAvailable()) - { - menu.addSeparator(); - - if (fileAttributes & SCC_FILE_ATTRIBUTE_INPAK) - { - menu.addAction(tr(" Material In Pak (Read Only)"))->setEnabled(false); - } - else - { - menu.addAction(tr(" Source Control"))->setEnabled(false); - if (!(fileAttributes & SCC_FILE_ATTRIBUTE_MANAGED)) - { - menu.addAction(tr("Add To Source Control"))->setData(MENU_SCM_ADD); - } - } - QAction* action = nullptr; - if (fileAttributes & SCC_FILE_ATTRIBUTE_MANAGED) - { - action = menu.addAction(tr("Check Out")); - action->setData(MENU_SCM_CHECK_OUT); - action->setEnabled(fileAttributes & SCC_FILE_ATTRIBUTE_READONLY || fileAttributes & SCC_FILE_ATTRIBUTE_INPAK); - action = menu.addAction(tr("Undo Check Out")); - action->setData(MENU_SCM_UNDO_CHECK_OUT); - action->setEnabled(fileAttributes & SCC_FILE_ATTRIBUTE_CHECKEDOUT); - menu.addAction(tr("Get Latest Version"))->setData(MENU_SCM_GET_LATEST); - } - - if (material) - { - QStringList filenames; - int nTextures = material->GetTextureFilenames(filenames); - action = menu.addAction(tr("Get Textures")); - action->setData(MENU_SCM_GET_LATEST_TEXTURES); - action->setEnabled(nTextures > 0); - } - } -} - -void MaterialBrowserWidget::ShowContextMenu(const CMaterialBrowserRecord& record, const QPoint& point) -{ - _smart_ptr material = record.m_material; - - // Create pop up menu. - QMenu menu; - if (m_markedRecords.size() >= 2) // it makes sense when we have at least two items selected - { - AddContextMenuActionsMultiSelect(menu); - } - else if (!material) // click on root, background or folder - { - AddContextMenuActionsNoSelection(menu); - } - else - { - // When right-clicking a single item in the material browser, select the parent material that was clicked, rather than the currently selected sub-material - // The context menu for sub-materials will be handled by the image list control rather than the material browser widget - m_selectedSubMaterialIndex = -1; - SetSelectedItem(material, nullptr, true); - AddContextMenuActionsSingleSelection(menu, material); - } - QAction* action = menu.exec(m_ui->treeView->mapToGlobal(point)); - const int cmd = action ? action->data().toInt() : 0; - - OnContextMenuAction(cmd, material); -} - -void MaterialBrowserWidget::OnContextMenuAction(int command, _smart_ptr material) -{ - CMaterialBrowserRecord record; - TryGetSelectedRecord(record); - switch (command) - { - case MENU_UNDEFINED: - return; // do nothing - case MENU_CUT: - OnCut(); - break; - case MENU_COPY: - OnCopy(); - break; - case MENU_COPY_NAME: - OnCopyName(); - break; - case MENU_PASTE: - OnPaste(); - break; - case MENU_EXPLORE: - { - if (material && material->IsPureChild()) - { - material = material->GetParent(); - } - - if (material) - { - QString fullPath = material->GetFilename(); - AzQtComponents::ShowFileOnDesktop(fullPath); - } - } - break; - case MENU_EXTRACT: - { - if (material && material->IsPureChild()) - { - material = material->GetParent(); - } - - if (material) - { - QString fullPath = material->GetFilename(); - if (CFileUtil::ExtractFile(fullPath, true, fullPath.toUtf8().data())) - { - AzQtComponents::ShowFileOnDesktop(fullPath); - } - } - } - break; - case MENU_DUPLICATE: - OnDuplicate(); - break; - case MENU_RENAME: - OnRenameItem(); - break; - case MENU_DELETE: - DeleteItem(record); - break; - case MENU_RESET: - OnResetItem(); - break; - case MENU_ASSIGNTOSELECTION: - { - CUndo undo("Assign Material To Selection"); - GetIEditor()->GetMaterialManager()->Command_AssignToSelection(); - break; - } - case MENU_SELECTASSIGNEDOBJECTS: - { - CUndo undo("Select Objects With Current Material"); - GetIEditor()->GetMaterialManager()->Command_SelectAssignedObjects(); - break; - } - case MENU_NUM_SUBMTL: - OnSetSubMtlCount(record); - break; - case MENU_ADDNEW: - OnAddNewMaterial(); - break; - case MENU_ADDNEW_MULTI: - OnAddNewMultiMaterial(); - break; - case MENU_CONVERT_TO_MULTI: - OnConvertToMulti(); - break; - case MENU_MERGE: - OnMergeMaterials(); - break; - - case MENU_SUBMTL_MAKE: - OnMakeSubMtlSlot(record); - break; - case MENU_SUBMTL_CLEAR: - OnClearSubMtlSlot(material); - break; - - case MENU_SCM_ADD: - DoSourceControlOp(record, ESCM_IMPORT); - break; - case MENU_SCM_CHECK_OUT: - DoSourceControlOp(record, ESCM_CHECKOUT); - break; - case MENU_SCM_UNDO_CHECK_OUT: - DoSourceControlOp(record, ESCM_UNDO_CHECKOUT); - break; - case MENU_SCM_GET_LATEST: - DoSourceControlOp(record, ESCM_GETLATEST); - break; - case MENU_SCM_GET_LATEST_TEXTURES: - DoSourceControlOp(record, ESCM_GETLATESTTEXTURES); - break; - - case MENU_SAVE_TO_FILE: - OnSaveToFile(false); - break; - case MENU_SAVE_TO_FILE_MULTI: - OnSaveToFile(true); - break; - //case MENU_MAKE_SUBMTL: OnAddNewMultiMaterial(); break; - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::PopulateItems() -{ - if (m_bIgnoreSelectionChange) - { - return; - } - - if (m_bItemsValid) - { - return; - } - - m_bItemsValid = true; - m_bIgnoreSelectionChange = true; - - IDataBaseItem* pSelection = m_pMatMan->GetSelectedItem(); - IDataBaseItem* pSelectionParent = m_pMatMan->GetSelectedParentItem(); - - m_bIgnoreSelectionChange = false; - - if (pSelection) - { - SelectItem(pSelection, pSelectionParent); - if (m_bHighlightMaterial) - { - m_bHighlightMaterial = false; - m_pMatMan->SetHighlightedMaterial(0); - } - } -} - -void MaterialBrowserWidget::StartRecordUpdateJobs() -{ - m_filterModel->StartRecordUpdateJobs(); -} - -////////////////////////////////////////////////////////////////////////// -uint32 MaterialBrowserWidget::MaterialNameToCrc32(const QString& str) -{ - return CCrc32::ComputeLowercase(str.toUtf8()); -} - -////////////////////////////////////////////////////////////////////////// -bool MaterialBrowserWidget::TryGetSelectedRecord(CMaterialBrowserRecord& record) -{ - QVariant variant = m_filterModel->data(m_ui->treeView->currentIndex(), Qt::UserRole); - if (variant.isValid()) - { - record = variant.value(); - return true; - } - - return false; -} - -////////////////////////////////////////////////////////////////////////// -_smart_ptr MaterialBrowserWidget::GetCurrentMaterial() -{ - CMaterialBrowserRecord record; - bool found = TryGetSelectedRecord(record); - if (found && record.m_material) - { - if (record.m_material->IsMultiSubMaterial() && m_selectedSubMaterialIndex >= 0) - { - return record.m_material->GetSubMaterial(m_selectedSubMaterialIndex); - } - else - { - return record.m_material; - } - } - - return m_pMatMan->GetCurrentMaterial(); -} - -////////////////////////////////////////////////////////////////////////// -AZStd::string MaterialBrowserWidget::GetSelectedMaterialID() -{ - CMaterialBrowserRecord record; - bool found = TryGetSelectedRecord(record); - if (found) - { - return record.GetRelativeFilePath(); - } - return AZStd::string(); -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnSelectionChanged() -{ - m_selectedSubMaterialIndex = -1; - TMaterialBrowserRecords markedRecords; - - CMaterialBrowserRecord record; - bool found = TryGetSelectedRecord(record); - for (const QModelIndex& row : m_ui->treeView->selectionModel()->selectedRows()) - { - QVariant userRole = row.data(Qt::UserRole); - if (userRole.isValid()) - { - CMaterialBrowserRecord currentRecord = userRole.value(); - markedRecords.push_back(currentRecord); - } - } - - if (!found && !markedRecords.empty()) - { - record = markedRecords.front(); - found = true; - } - if (found) - { - // Since the call to SetSelectedItem is coming from an OnSelectionChanged event, the appropriate - // element of the tree view has already been selected. Pass in false for the selectInTreeView argument - // to prevent SetSelectedItem from trying to re-select the material in the browser - SetSelectedItem(record.m_material, &markedRecords, false); - } -} - -void MaterialBrowserWidget::OnRefreshSelection() -{ - // force RefreshSelected to repopulate by setting m_pLastActiveMultiMaterial to null - // so it thinks we selected a new material. - m_pLastActiveMultiMaterial = nullptr; - - //If no material is selected, clear preview. - if (!GetCurrentMaterial()) - { - if (m_pMaterialImageListCtrl) - { - QMaterialImageListModel* materialModel = - qobject_cast(m_pMaterialImageListCtrl->model()); - Q_ASSERT(materialModel); - materialModel->DeleteAllItems(); - } - } - - RefreshSelected(); - - // Force update the material dialog - if (m_pListener) - { - m_pListener->OnBrowserSelectItem(GetCurrentMaterial(), true); - } -} - -void MaterialBrowserWidget::OnMaterialAdded() -{ - if (m_delayedSelection) - { - SetSelectedItem(m_delayedSelection, nullptr, true); - - // Force update the material dialog - if (m_pListener) - { - m_pListener->OnBrowserSelectItem(GetCurrentMaterial(), true); - } - } -} - -void MaterialBrowserWidget::OnSubMaterialSelectedInPreviewPane(const QModelIndex& current) -{ - if (!m_pMaterialImageListCtrl) - { - return; - } - - QMaterialImageListModel* materialModel = - qobject_cast(m_pMaterialImageListCtrl->model()); - Q_ASSERT(materialModel); - - int nSlot = (INT_PTR)materialModel->UserDataFromIndex(current); - if (nSlot < 0) - { - return; - } - - CMaterialBrowserRecord record; - bool found = TryGetSelectedRecord(record); - if (!found || !record.m_material) - { - return; - } - - if (!record.m_material->IsMultiSubMaterial()) - { - return; // must be multi sub material. - } - if (nSlot >= record.m_material->GetSubMaterialCount()) - { - return; - } - - if (nSlot == m_selectedSubMaterialIndex) - { - return; - } - - m_selectedSubMaterialIndex = nSlot; - - SetSelectedItem(record.m_material, nullptr, false); -} - -void MaterialBrowserWidget::SaveCurrentMaterial() -{ - // Saving might open a modal dialog asking to overwrite, therefore don't run this from DTOR, might crash - - _smart_ptr pCurrentMtl = GetCurrentMaterial(); - if (pCurrentMtl && pCurrentMtl->IsModified()) - { - pCurrentMtl->Save(); - } -} - -void MaterialBrowserWidget::expandAllNotMatchingIndexes(const QModelIndex& parent) -{ - if (!parent.isValid()) - { - m_ui->treeView->collapseAll(); - } - - const int rowCount = m_ui->treeView->model()->rowCount(parent); - for (int row = 0; row < rowCount; ++row) - { - const QModelIndex index = m_ui->treeView->model()->index(row, 0, parent); - const QString text = index.data().toString(); - bool contains = true; - m_ui->treeView->setExpanded(index, !contains); - if (!contains) - { - expandAllNotMatchingIndexes(index); - } - } -} - -void MaterialBrowserWidget::MaterialAddFinished() -{ - emit materialAdded(); -} - -void MaterialBrowserWidget::MaterialFinishedProcessing(_smart_ptr material, const QPersistentModelIndex& filterModelIndex) -{ - // If the currently selected material finished processing - if (filterModelIndex.isValid() && filterModelIndex == m_ui->treeView->currentIndex()) - { - // Stash the delayed selection so that it is not cleared just because the currently selected material finished processing - _smart_ptr tempDelayedSelection = m_delayedSelection; - - // Re-select the material to update the material dialogue - // but ignore the tree-view selection since the current index is already the correct one for this material - SetSelectedItem(material, nullptr, false); - - // Force update the material dialog - if (m_pListener) - { - m_pListener->OnBrowserSelectItem(GetCurrentMaterial(), true); - } - - if (material != m_delayedSelection) - { - // If the current selection that just finished processing was not the delayed selection, restore the delayed selection - m_delayedSelection = tempDelayedSelection; - } - } - // If there was a failed attempt to select the material before it finished processing - else if (m_delayedSelection && m_delayedSelection == material) - { - // Re-select the material to update the material dialogue - // and also select the material in the tree-view - SetSelectedItem(material, nullptr, true); - - // Force update the material dialog - if (m_pListener) - { - m_pListener->OnBrowserSelectItem(GetCurrentMaterial(), true); - } - } -} - -void MaterialBrowserWidget::MaterialRecordUpdateFinished() -{ - //The event is sent by a AZJob working thread, need to emit a signal here for qt to catch later. - //It can make sure all the qt functions need to be called at this point are only executed in the qt thread. - emit refreshSelection(); -} - - -#include diff --git a/Code/Sandbox/Editor/Material/MaterialBrowser.h b/Code/Sandbox/Editor/Material/MaterialBrowser.h deleted file mode 100644 index d02045bacd..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialBrowser.h +++ /dev/null @@ -1,248 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_MATERIAL_MATERIALBROWSER_H -#define CRYINCLUDE_EDITOR_MATERIAL_MATERIALBROWSER_H -#pragma once - - -#if !defined(Q_MOC_RUN) -#include "Include/IDataBaseManager.h" -#include "Material/Material.h" -#include "Material/MaterialBrowserFilterModel.h" - -#include -#include -#include -#include - -#include -#endif - -class CMaterial; - -class MaterialBrowserWidget; -class CMaterialImageListCtrl; -class QMaterialImageListModel; - -class QTreeView; -class QAction; - -struct IDataBaseItem; -class CMaterialBrowserRecord; -typedef std::vector TMaterialBrowserRecords; - -namespace AzToolsFramework -{ - namespace AssetBrowser - { - class AssetBrowserModel; - class AssetBrowserFilterModel; - class AssetTypeFilter; - } -} - -enum ESccFileAttributes; - -namespace Ui -{ - class MaterialBrowser; -} - - -////////////////////////////////////////////////////////////////////////// -struct IMaterialBrowserListener -{ - virtual void OnBrowserSelectItem(IDataBaseItem* pItem, bool bForce) = 0; -}; - -////////////////////////////////////////////////////////////////////////// -// MaterialBrowserWidget -////////////////////////////////////////////////////////////////////////// -class MaterialBrowserFilterModel; - -class MaterialBrowserWidget - : public QWidget - , public IDataBaseManagerListener - , public IEditorNotifyListener - , public MaterialBrowserWidgetBus::Handler -{ - Q_OBJECT - -public: - enum EViewType - { - VIEW_LEVEL = 0, - VIEW_ALL = 1, - }; - - enum EFilter - { - eFilter_Materials = 0x01, - eFilter_Textures = 0x02, - eFilter_Materials_And_Textures = 0x03, - eFilter_Submaterials = 0x04 - }; - - MaterialBrowserWidget(QWidget* parent); - ~MaterialBrowserWidget(); - - void SetListener(IMaterialBrowserListener* pListener) { m_pListener = pListener; } - - EViewType GetViewType() const { return m_viewType; }; - - void ClearItems(); - - void SelectItem(IDataBaseItem* pItem, IDataBaseItem* pParentItem); - void DeleteItem(); - - void PopulateItems(); - void StartRecordUpdateJobs(); - - bool ShowCheckedOutRecursive(TMaterialBrowserRecords* pRecords); - - void ShowOnlyLevelMaterials(bool levelOnly); - - void OnCopy(); - void OnCopyName(); - void OnPaste(); - void OnCut(); - void OnDuplicate(); - void OnAddNewMaterial(); - void OnAddNewMultiMaterial(); - void OnConvertToMulti(); - void OnMergeMaterials(); - -public slots: - void OnSelectionChanged(); - void OnSubMaterialSelectedInPreviewPane(const QModelIndex& current); - void SaveCurrentMaterial(); - void OnRefreshSelection(); - void OnMaterialAdded(); - -signals: - void refreshSelection(); - void materialAdded(); - -public: - void OnUpdateShowCheckedOut(); - bool CanPaste() const; - - void SetImageListCtrl(CMaterialImageListCtrl* pCtrl); - - ////////////////////////////////////////////////////////////////////////// - // IDataBaseManagerListener implementation. - ////////////////////////////////////////////////////////////////////////// - virtual void OnDataBaseItemEvent(IDataBaseItem* pItem, EDataBaseItemEvent event); - ////////////////////////////////////////////////////////////////////////// - - virtual void OnEditorNotifyEvent(EEditorNotifyEvent event); - void AddContextMenuActionsSingleSelection(QMenu &menu, _smart_ptr material) const; - void OnContextMenuAction(int command, _smart_ptr material); - - // MaterialBrowserWidgetBus event handlers - void MaterialAddFinished() override; - void MaterialFinishedProcessing(_smart_ptr material, const QPersistentModelIndex &filterModelIndex) override; - void MaterialRecordUpdateFinished() override; - -protected: - // Item definition. - enum ESourceControlOp - { - ESCM_IMPORT, - ESCM_CHECKOUT, - ESCM_UNDO_CHECKOUT, - ESCM_GETLATEST, - ESCM_GETLATESTTEXTURES, - }; - - void DeleteItem(const CMaterialBrowserRecord &record); - void SetSelectedItem(_smart_ptr material, const TMaterialBrowserRecords* pMarkedRecords, bool selectInTreeView); - void OnAddSubMtl(); - void OnSelectAssignedObjects(); - void OnAssignMaterialToSelection(); - void OnRenameItem(); - void OnResetItem(); - void OnSetSubMtlCount(const CMaterialBrowserRecord &record); - - void DoSourceControlOp(CMaterialBrowserRecord &record, ESourceControlOp); - - void OnMakeSubMtlSlot(const CMaterialBrowserRecord &record); - void OnClearSubMtlSlot(_smart_ptr subMaterial); - void SetSubMaterial(_smart_ptr parentMaterial, int slot, _smart_ptr subMaterial); - - void OnSaveToFile(bool bMulti); - - void RefreshSelected(); - - void TickRefreshMaterials(); - void TryLoadRecordMaterial(CMaterialBrowserRecord &record); - - void ShowContextMenu(const CMaterialBrowserRecord &record, const QPoint& point); - _smart_ptr GetCurrentMaterial(); - - uint32 MaterialNameToCrc32(const QString& str); - - bool TryGetSelectedRecord(CMaterialBrowserRecord &record); - AZStd::string GetSelectedMaterialID(); - -private: - void expandAllNotMatchingIndexes(const QModelIndex& parent = QModelIndex()); - void ClearImageListControlSelection(); - void ClearSelection(QMaterialImageListModel* materialModel); - QMenu *InitializeSearchMenu(); - - void AddContextMenuActionsMultiSelect(QMenu &menu) const; - void AddContextMenuActionsNoSelection(QMenu &menu) const; - void AddContextMenuActionsSubMaterial(QMenu &menu, _smart_ptr parentMaterial, _smart_ptr subMaterial) const; - void AddContextMenuActionsMultiMaterial(QMenu &menu) const; - void AddContextMenuActionsSingleMaterial(QMenu &menu) const; - void AddContextMenuActionsCommon(QMenu &menu, _smart_ptr material) const; - void AddContextMenuActionsSourceControl(QMenu &menu, _smart_ptr material, uint32 fileAttributes) const; - - QScopedPointer m_ui; - - AzToolsFramework::AssetBrowser::AssetBrowserModel* m_assetBrowserModel; - QSharedPointer m_filterModel; - int m_selectedSubMaterialIndex = -1; - - bool m_bIgnoreSelectionChange; - bool m_bItemsValid; - - CMaterialManager* m_pMatMan; - IMaterialBrowserListener* m_pListener; - CMaterialImageListCtrl* m_pMaterialImageListCtrl; - - EViewType m_viewType; - bool m_bNeedReload; - - bool m_bHighlightMaterial; - uint32 m_timeOfHighlight; - - TMaterialBrowserRecords m_markedRecords; - - _smart_ptr m_pLastActiveMultiMaterial; - _smart_ptr m_delayedSelection; - - bool m_bShowOnlyCheckedOut; - - QAction* m_cutAction; - QAction* m_copyAction; - QAction* m_pasteAction; - QAction* m_duplicateAction; - QAction* m_deleteAction; - QAction* m_renameItemAction; - QAction* m_addNewMaterialAction; -}; - -#endif // CRYINCLUDE_EDITOR_MATERIAL_MATERIALBROWSER_H diff --git a/Code/Sandbox/Editor/Material/MaterialBrowser.ui b/Code/Sandbox/Editor/Material/MaterialBrowser.ui deleted file mode 100644 index 44e4e135ef..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialBrowser.ui +++ /dev/null @@ -1,87 +0,0 @@ - - - MaterialBrowser - - - - 0 - 0 - 250 - 400 - - - - Form - - - - 0 - - - 2 - - - 0 - - - 0 - - - - - - - - 0 - 0 - - - - - 147 - 22 - - - - - - - - - - - 0 - 0 - - - - Qt::CustomContextMenu - - - QAbstractItemView::ExtendedSelection - - - false - - - - - - - - AzToolsFramework::AssetBrowser::SearchWidget - QWidget -
AzToolsFramework/AssetBrowser/Search/SearchWidget.h
- 1 -
- - AzToolsFramework::AssetBrowser::AssetBrowserTreeView - QTreeView -
AzToolsFramework/AssetBrowser/Views/AssetBrowserTreeView.h
-
-
- - - - -
diff --git a/Code/Sandbox/Editor/Material/MaterialBrowserFilterModel.cpp b/Code/Sandbox/Editor/Material/MaterialBrowserFilterModel.cpp deleted file mode 100644 index 9f145c4daf..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialBrowserFilterModel.cpp +++ /dev/null @@ -1,652 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include "EditorDefs.h" - -#include "MaterialBrowserFilterModel.h" - -// AzFramework -#include - -// AzToolsFramework -#include -#include -#include -#include - -// Editor -#include "MaterialBrowserSearchFilters.h" -#include "MaterialManager.h" - - -namespace -{ - // how often to re-query source control status of an item after querying it, in seconds. - // note that using a source control operation on an item invalidates the cache and will immediately - // refresh its status regardless of this value, so it can be pretty high. - qint64 g_timeRefreshSCCStatus = 60; -} - -#define IDC_MATERIAL_TREECTRL 3 - -////////////////////////////////////////////////////////////////////////// -#define ITEM_IMAGE_SHARED_MATERIAL 0 -#define ITEM_IMAGE_SHARED_MATERIAL_SELECTED 1 -#define ITEM_IMAGE_FOLDER 2 -#define ITEM_IMAGE_FOLDER_OPEN 3 -#define ITEM_IMAGE_MATERIAL 4 -#define ITEM_IMAGE_MATERIAL_SELECTED 5 -#define ITEM_IMAGE_MULTI_MATERIAL 6 -#define ITEM_IMAGE_MULTI_MATERIAL_SELECTED 7 - - -#define ITEM_IMAGE_OVERLAY_CGF 8 -#define ITEM_IMAGE_OVERLAY_INPAK 9 -#define ITEM_IMAGE_OVERLAY_READONLY 10 -#define ITEM_IMAGE_OVERLAY_ONDISK 11 -#define ITEM_IMAGE_OVERLAY_LOCKED 12 -#define ITEM_IMAGE_OVERLAY_CHECKEDOUT 13 -#define ITEM_IMAGE_OVERLAY_NO_CHECKOUT 14 -////////////////////////////////////////////////////////////////////////// - -AZ::Data::AssetId GetMaterialProductAssetIdFromAssetBrowserEntry(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* assetEntry) -{ - using namespace AzToolsFramework::AssetBrowser; - - if (assetEntry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Source || - assetEntry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Product) - { - AZStd::vector products; - assetEntry->GetChildrenRecursively(products); - - // Cache the material asset type because this function is called for every submaterial when searching. - // AssetType is a POD struct so it should be fine to leave it as a static that gets destroyed during library unload/program termination. - static AZ::Data::AssetType materialAssetType = AZ::Data::AssetType::CreateNull(); - if (materialAssetType.IsNull()) - { - EBusFindAssetTypeByName materialAssetTypeResult("Material"); - AZ::AssetTypeInfoBus::BroadcastResult(materialAssetTypeResult, &AZ::AssetTypeInfo::GetAssetType); - AZ_Assert(materialAssetTypeResult.Found(), "Could not find asset type for material asset"); - materialAssetType = materialAssetTypeResult.GetAssetType(); - } - - for (const auto* product : products) - { - if (product->GetAssetType() == materialAssetType) - { - return product->GetAssetId(); - } - } - } - return AZ::Data::AssetId(); -} - -MaterialBrowserFilterModel::MaterialBrowserFilterModel(QObject* parent) - : AzToolsFramework::AssetBrowser::AssetBrowserFilterModel(parent) -{ - using namespace AzToolsFramework::AssetBrowser; - using namespace AzToolsFramework::MaterialBrowser; - - MaterialBrowserSourceControlBus::Handler::BusConnect(); - AssetBrowserModelNotificationBus::Handler::BusConnect(); - MaterialBrowserRequestBus::Handler::BusConnect(); - AzFramework::AssetCatalogEventBus::Handler::BusConnect(); - - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/material_00.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/material_01.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/material_02.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/material_03.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/material_04.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/material_05.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/material_06.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/material_07.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/filestatus_00.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/filestatus_01.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/filestatus_02.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/filestatus_03.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/filestatus_04.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/filestatus_05.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/filestatus_06.png")); - - - // Create an asset type filter for materials - AssetTypeFilter* assetTypeFilter = new AssetTypeFilter(); - assetTypeFilter->SetAssetType("Material"); - assetTypeFilter->SetFilterPropagation(AssetBrowserEntryFilter::PropagateDirection::Down); //this will make sure folders that contain materials are displayed - m_assetTypeFilter = FilterConstType(assetTypeFilter); - - // Create search filters. SetSearchFilter stores these filters so that they are deleted when this object is deleted. - m_subMaterialSearchFilter = new SubMaterialSearchFilter(this); - m_levelMaterialSearchFilter = new LevelMaterialSearchFilter(this); - - InitializeRecordUpdateJob(); -} - -MaterialBrowserFilterModel::~MaterialBrowserFilterModel() -{ - SAFE_DELETE(m_jobCancelGroup); - SAFE_DELETE(m_jobContext); - SAFE_DELETE(m_jobManager); - - AzToolsFramework::AssetBrowser::AssetBrowserModelNotificationBus::Handler::BusDisconnect(); - MaterialBrowserSourceControlBus::Handler::BusDisconnect(); - AzToolsFramework::MaterialBrowser::MaterialBrowserRequestBus::Handler::BusDisconnect(); - AzFramework::AssetCatalogEventBus::Handler::BusDisconnect(); -} - -void MaterialBrowserFilterModel::UpdateRecord(const QModelIndex& filterModelIndex) -{ - using namespace AzToolsFramework::AssetBrowser; - - if (filterModelIndex.isValid()) - { - QModelIndex modelIndex = mapToSource(filterModelIndex); - - AssetBrowserEntry* assetEntry = static_cast(modelIndex.internalPointer()); - - if (assetEntry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Source || - assetEntry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Product) - { - AZStd::vector products; - assetEntry->GetChildrenRecursively(products); - - for (const auto* product : products) - { - if (!m_assetTypeFilter->Match(product)) - { - continue; - } - MaterialBrowserRecordAssetBrowserData assetBrowserData; - assetBrowserData.assetId = product->GetAssetId(); - assetBrowserData.relativeFilePath = product->GetRelativePath(); - assetBrowserData.fullSourcePath = product->GetFullPath(); - assetBrowserData.modelIndex = modelIndex; - assetBrowserData.filterModelIndex = filterModelIndex; - UpdateRecord(assetBrowserData); - } - } - } -} - -void MaterialBrowserFilterModel::UpdateRecord(const MaterialBrowserRecordAssetBrowserData& assetBrowserData) -{ - CMaterialBrowserRecord record; - record.SetAssetBrowserData(assetBrowserData); - record.m_material = GetIEditor()->GetMaterialManager()->LoadMaterial(record.GetRelativeFilePath().c_str()); - SetRecord(record); -} - -void MaterialBrowserFilterModel::UpdateSourceControlFileInfoCallback(const AZ::Data::AssetId& assetId, const AzToolsFramework::SourceControlFileInfo& info) -{ - CMaterialBrowserRecord record; - bool found = m_materialRecordMap.find(assetId, &record); - if (found) - { - // Update the cached source control attributes for the record - record.m_lastCachedSCCAttributes = info; - record.m_lastCachedFileAttributes = static_cast(CFileUtil::GetAttributes(record.GetFullSourcePath().c_str(), false)); - record.m_lastCheckedSCCAttributes = QDateTime::currentDateTime(); - - // Update the record - m_materialRecordMap.erase(assetId); - m_materialRecordMap.insert(AZStd::pair(record.GetAssetId(), record)); - - QueueDataChangedEvent(record.GetFilterModelIndex()); - } -} - -void MaterialBrowserFilterModel::UpdateSourceControlLastCheckedTime(const AZ::Data::AssetId& assetId, const QDateTime& dateTime) -{ - CMaterialBrowserRecord record; - bool found = m_materialRecordMap.find(assetId, &record); - if (found) - { - // Update the record - record.m_lastCheckedSCCAttributes = dateTime; - m_materialRecordMap.erase(assetId); - m_materialRecordMap.insert(AZStd::pair(record.GetAssetId(), record)); - } -} - -QVariant MaterialBrowserFilterModel::data(const QModelIndex& index, int role /* = Qt::DisplayRole*/) const -{ - // Should return data from an AssetBrowserEntry, or get material specific info from that data - if (index.isValid()) - { - // Use the base AssetBrowserFilterModel::data function for display role - if (role != AzToolsFramework::AssetBrowser::AssetBrowserModel::Roles::EntryRole) - { - QModelIndex modelIndex = mapToSource(index); - AzToolsFramework::AssetBrowser::AssetBrowserEntry* assetEntry = static_cast(modelIndex.internalPointer()); - - AZ::Data::AssetId assetId = GetMaterialProductAssetIdFromAssetBrowserEntry(assetEntry); - if (assetId.IsValid()) - { - CMaterialBrowserRecord record; - bool found = m_materialRecordMap.find(assetId, &record); - - if (role == Qt::UserRole) - { - if (found) - { - return QVariant::fromValue(record); - } - else - { - return QVariant(); - } - } - } - } - } - // If the role is Qt::DisplayRole, the item a folder, or the material has not been parsed yet, fall back on the default data result from the underlying AssetBrowserModel - return AzToolsFramework::AssetBrowser::AssetBrowserFilterModel::data(index, role); -} - -void MaterialBrowserFilterModel::GetRelativeFilePaths(AZStd::vector& files) const -{ - GetRelativeFilePathsRecursive(files, this); -} - -void MaterialBrowserFilterModel::GetRelativeFilePathsRecursive(AZStd::vector& files, - const MaterialBrowserFilterModel* model, const QModelIndex& parent) const -{ - using namespace AzToolsFramework::AssetBrowser; - - for (int r = 0; r < model->rowCount(parent); ++r) - { - QModelIndex index = model->index(r, 0, parent); - QModelIndex modelIndex = model->mapToSource(index); - - if (model->hasChildren(index)) - { - GetRelativeFilePathsRecursive(files, model, index); - } - else - { - AssetBrowserEntry* assetEntry = static_cast(modelIndex.internalPointer()); - - AZStd::vector products; - assetEntry->GetChildrenRecursively(products); - - for (const auto* product : products) - { - if (!m_assetTypeFilter->Match(product)) - { - continue; - } - MaterialBrowserRecordAssetBrowserData item; - item.assetId = product->GetAssetId(); - item.fullSourcePath = product->GetFullPath(); - item.relativeFilePath = product->GetRelativePath(); - item.modelIndex = modelIndex; - item.filterModelIndex = index; - files.push_back(item); - } - } - } -} - -QModelIndex MaterialBrowserFilterModel::GetIndexFromMaterial(_smart_ptr material) const -{ - CMaterialBrowserRecord record; - bool found = TryGetRecordFromMaterial(material, record); - if (found) - { - return record.GetFilterModelIndex(); - } - return QModelIndex(); -} - -QModelIndex MaterialBrowserFilterModel::GetFilterModelIndex(const AZ::Data::AssetId& assetId) const -{ - QModelIndex filterModelIndex; - if (TryGetFilterModelIndexRecursive(filterModelIndex, assetId, this)) - { - return filterModelIndex; - } - - return QModelIndex(); -} - -bool MaterialBrowserFilterModel::TryGetFilterModelIndexRecursive(QModelIndex& filterModelIndex, - const AZ::Data::AssetId& assetId, const MaterialBrowserFilterModel* model, const QModelIndex& parent) const -{ - using namespace AzToolsFramework::AssetBrowser; - - // Walk through the filter model to find the product entry with the corresponding assetId - for (int r = 0; r < model->rowCount(parent); ++r) - { - QModelIndex index = model->index(r, 0, parent); - QModelIndex modelIndex = model->mapToSource(index); - - if (model->hasChildren(index)) - { - if (TryGetFilterModelIndexRecursive(filterModelIndex, assetId, model, index)) - { - return true; - } - } - else - { - // Check to see if the current entry is the one we're looking for - AssetBrowserEntry* assetEntry = static_cast(modelIndex.internalPointer()); - - AZStd::vector products; - assetEntry->GetChildrenRecursively(products); - - for (const auto* product : products) - { - if (assetId == product->GetAssetId()) - { - filterModelIndex = index; - return true; - } - } - } - } - - return false; -} - -void MaterialBrowserFilterModel::EntryAdded(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) -{ - // If the entry is a product material - if (entry->GetEntryType() == AzToolsFramework::AssetBrowser::AssetBrowserEntry::AssetEntryType::Product && m_assetTypeFilter->Match(entry)) - { - // capture the data here, so that entry cannot disappear before we actually get to the job. - MaterialBrowserRecordAssetBrowserData assetBrowserData; - assetBrowserData.assetId = GetMaterialProductAssetIdFromAssetBrowserEntry(entry); - assetBrowserData.relativeFilePath = entry->GetRelativePath(); - assetBrowserData.fullSourcePath = entry->GetFullPath(); - assetBrowserData.filterModelIndex = GetFilterModelIndex(assetBrowserData.assetId); - - // Create a job to add/update the entry in the underlying map - AZ::Job* updateEntryJob = AZ::CreateJobFunction([this, assetBrowserData]() - { - CMaterialBrowserRecord record; - record.SetAssetBrowserData(assetBrowserData); - record.m_material = GetIEditor()->GetMaterialManager()->LoadMaterialWithFullSourcePath(record.GetRelativeFilePath().c_str(), record.GetFullSourcePath().c_str()); - SetRecord(record); - MaterialBrowserWidgetBus::Broadcast(&MaterialBrowserWidgetEvents::MaterialAddFinished); - }, true, m_jobContext); - - // Start the job immediately - AZ::Job* currentJob = m_jobContext->GetJobManager().GetCurrentJob(); - if (currentJob) - { - // Suspend the current job until the new job completes so that - // if a new material is created by the user it's ready to use sooner - currentJob->StartAsChild(updateEntryJob); - currentJob->WaitForChildren(); - } - else - { - updateEntryJob->Start(); - } - } -} - - -void MaterialBrowserFilterModel::OnCatalogAssetChanged(const AZ::Data::AssetId& assetId) -{ - CMaterialBrowserRecord record; - bool found = m_materialRecordMap.find(assetId, &record); - if (found) - { - record.m_material->Reload(); - //Send out event to notify UI update if it's currently selected - MaterialBrowserWidgetBus::Broadcast(&MaterialBrowserWidgetEvents::MaterialFinishedProcessing, record.m_material, record.GetFilterModelIndex()); - } -} - -bool MaterialBrowserFilterModel::HasRecord(const AZ::Data::AssetId& assetId) -{ - return m_materialRecordMap.find(assetId); -} - -bool MaterialBrowserFilterModel::IsMultiMaterial(const AZ::Data::AssetId& assetId) -{ - CMaterialBrowserRecord record; - bool found = m_materialRecordMap.find(assetId, &record); - if (found) - { - if (record.m_material && record.m_material->IsMultiSubMaterial()) - { - return true; - } - } - return false; -} - -bool MaterialBrowserFilterModel::TryGetRecordFromMaterial(_smart_ptr material, CMaterialBrowserRecord& record) const -{ - if (material) - { - // Get the relative path for the material - bool pathFound = false; - AZStd::string relativePath; - AzToolsFramework::AssetSystemRequestBus::BroadcastResult(pathFound, &AzToolsFramework::AssetSystem::AssetSystemRequest::GetRelativeProductPathFromFullSourceOrProductPath, material->GetFilename().toUtf8().data(), relativePath); - AZ_Assert(pathFound, "Failed to get engine relative path from %s", material->GetFilename().toUtf8().data()); - - // Get the assetId from the relative path - AZ::Data::AssetId assetId; - - AZ::Data::AssetCatalogRequestBus::BroadcastResult(assetId, &AZ::Data::AssetCatalogRequests::GetAssetIdByPath, relativePath.c_str(), GetIEditor()->GetMaterialManager()->GetMaterialAssetType(), false); - - return TryGetRecordFromAssetId(assetId, record); - } - - return false; -} - -bool MaterialBrowserFilterModel::TryGetRecordFromAssetId(const AZ::Data::AssetId& assetId, CMaterialBrowserRecord& record) const -{ - bool recordFound = m_materialRecordMap.find(assetId, &record); - return recordFound; -} - -void MaterialBrowserFilterModel::SetRecord(const CMaterialBrowserRecord& record) -{ - m_materialRecordMap.erase(record.GetAssetId()); - m_materialRecordMap.insert({ record.GetAssetId(), record }); - - QueueDataChangedEvent(record.GetFilterModelIndex()); -} - -void MaterialBrowserFilterModel::SetSearchFilter(const AzToolsFramework::AssetBrowser::SearchWidget* searchWidget) -{ - /* - * The filter matches the following rule: - * A. If the entry is a material - * 1. The material's name matches the search text - * 2. The sub material's name matches the search text - * B. If the entry is a folder: - * 1. The folder's name matches the search text - * 2. The folder contains a material matching A - * 3. The folder contains a folder matching B.1 & B.2 - */ - - using namespace AzToolsFramework::AssetBrowser; - - m_searchWidget = searchWidget; - - // Create a search filter where a search text either matches entry/entry parent's name or sub material name - CompositeFilter* nameFilter = new CompositeFilter(CompositeFilter::LogicOperatorType::OR); - QSharedPointer searchWidgetFilter = m_searchWidget->GetFilter(); - // The default setting for search widget filter is Down - // Since now we only need to match for the entry itself in this filter, set back to None - searchWidgetFilter->SetFilterPropagation(AssetBrowserEntryFilter::PropagateDirection::None); - nameFilter->AddFilter(FilterConstType(m_subMaterialSearchFilter)); - nameFilter->AddFilter(FilterConstType(searchWidgetFilter)); - - EntryTypeFilter* productsFilter = new EntryTypeFilter(); - productsFilter->SetEntryType(AssetBrowserEntry::AssetEntryType::Product); - InverseFilter* noProductsFilter = new InverseFilter(); - noProductsFilter->SetFilter(FilterConstType(productsFilter)); - - // Create a filter where the entry needs to match the previous name filter and it needs to be material itself or it contains material. - CompositeFilter* isMaterialAndMatchesSearchFilter = new CompositeFilter(CompositeFilter::LogicOperatorType::AND); - isMaterialAndMatchesSearchFilter->AddFilter(FilterConstType(nameFilter)); - isMaterialAndMatchesSearchFilter->AddFilter(FilterConstType(m_assetTypeFilter)); - isMaterialAndMatchesSearchFilter->AddFilter(FilterConstType(noProductsFilter)); - isMaterialAndMatchesSearchFilter->AddFilter(FilterConstType(m_levelMaterialSearchFilter)); - // Make sure any folder contains the matching result is included - isMaterialAndMatchesSearchFilter->SetFilterPropagation(AssetBrowserEntryFilter::PropagateDirection::Down); - - // Set the filter for the MaterialBrowserFilterModel - SetFilter(FilterConstType(isMaterialAndMatchesSearchFilter)); -} - -void MaterialBrowserFilterModel::ShowOnlyLevelMaterials(bool levelOnly, bool invalidateFilterNow) -{ - m_levelMaterialSearchFilter->ShowOnlyLevelMaterials(levelOnly); - if (levelOnly) - { - m_levelMaterialSearchFilter->CacheLoadedMaterials(); - } - - if (invalidateFilterNow) - { - // we need to invalid the filter immediately, for example this is used when we are changing level, otherwise - // the current filter is used when getting file paths for all of the materials as part of StartRecordUpdateJobs. - invalidateFilter(); - } - else - { - filterUpdatedSlot(); - } -} - -void MaterialBrowserFilterModel::SearchFilterUpdated() -{ - m_subMaterialSearchFilter->SetFilterString(m_searchWidget->textFilter()); - filterUpdatedSlot(); -} - -void MaterialBrowserFilterModel::QueueDataChangedEvent(const QPersistentModelIndex& filterModelIndex) -{ - // Queue a data changed event to be executed on the main thread - AZStd::function emitDataChanged = - [this, filterModelIndex]() - { - if (filterModelIndex.isValid()) - { - Q_EMIT dataChanged(filterModelIndex, filterModelIndex); - } - }; - - AZ::TickBus::QueueFunction(emitDataChanged); -} - -void MaterialBrowserFilterModel::InitializeRecordUpdateJob() -{ - AZ::JobManagerDesc desc; - AZ::JobManagerThreadDesc threadDesc; - for (size_t i = 0; i < AZStd::thread::hardware_concurrency(); ++i) - { - desc.m_workerThreads.push_back(threadDesc); - } - - // Check to ensure these have not already been initialized. - AZ_Error("Material Browser", !m_jobManager && !m_jobCancelGroup && !m_jobContext, "MaterialBrowserFilterModel::InitializeRecordUpdateJob is being called again after it has already been initialized"); - m_jobManager = aznew AZ::JobManager(desc); - m_jobCancelGroup = aznew AZ::JobCancelGroup(); - m_jobContext = aznew AZ::JobContext(*m_jobManager, *m_jobCancelGroup); -} - -void MaterialBrowserFilterModel::StartRecordUpdateJobs() -{ - // Generate a list of file paths, assetId's, and asset browser model indices - // This must be done on the main thread, otherwise it can lead to a crash when the tree view UI is being initialized - AZStd::vector files; - GetRelativeFilePaths(files); - - // Kick off the background process that will iterate over the list of file paths and update the material record map - m_mainUpdateRecordJob = aznew MaterialBrowserUpdateJobCreator(this, files, m_jobContext); - m_mainUpdateRecordJob->Start(); -} - -void MaterialBrowserFilterModel::CancelRecordUpdateJobs() -{ - m_jobContext->GetCancelGroup()->Cancel(); - m_jobContext->GetCancelGroup()->Reset(); -} - -void MaterialBrowserFilterModel::ClearRecordMap() -{ - CancelRecordUpdateJobs(); - m_materialRecordMap.clear(); -} - -MaterialBrowserUpdateJobCreator::MaterialBrowserUpdateJobCreator(MaterialBrowserFilterModel* model, AZStd::vector& files, AZ::JobContext* context /*= NULL*/) - : Job(true, context) - , m_files(files) - , m_filterModel(model) -{ -} - -void MaterialBrowserUpdateJobCreator::Process() -{ - // Split the files to be processed evenly among threads - int numJobs = GetContext()->GetJobManager().GetNumWorkerThreads(); - int materialsPerJob = (m_files.size() / numJobs) + 1; - - for (auto it = m_files.begin(); it <= m_files.end(); it += materialsPerJob) - { - // Create a subset of the list of material files to be processed by another job - auto start = it; - auto end = it + materialsPerJob; - if (end > m_files.end()) - { - end = m_files.end(); - } - AZStd::vector subset(start, end); - - if (subset.size() > 0) - { - AZ::Job* materialBrowserUpdateJob = aznew MaterialBrowserUpdateJob(m_filterModel, subset, GetContext()); - StartAsChild(materialBrowserUpdateJob); - } - } - - WaitForChildren(); - - MaterialBrowserWidgetBus::Broadcast(&MaterialBrowserWidgetEvents::MaterialRecordUpdateFinished); -} - -MaterialBrowserUpdateJob::MaterialBrowserUpdateJob(MaterialBrowserFilterModel* model, AZStd::vector& files, AZ::JobContext* context /*= NULL*/) - : Job(true, context) - , m_filterModel(model) - , m_files(files) -{ -} - -void MaterialBrowserUpdateJob::Process() -{ - for (size_t i = 0; i < m_files.size(); ++i) - { - // Early out when the job is cancelled - if (IsCancelled()) - { - return; - } - CMaterialBrowserRecord record; - record.SetAssetBrowserData(m_files[i]); - - // Get the writable status of the file, but don't update source control status until it is actually needed - record.m_lastCachedFileAttributes = static_cast(CFileUtil::GetAttributes(record.GetFullSourcePath().c_str(), false)); - - record.m_material = GetIEditor()->GetMaterialManager()->LoadMaterialWithFullSourcePath(record.GetRelativeFilePath().c_str(), record.GetFullSourcePath().c_str()); - m_filterModel->SetRecord(record); - } -} diff --git a/Code/Sandbox/Editor/Material/MaterialBrowserFilterModel.h b/Code/Sandbox/Editor/Material/MaterialBrowserFilterModel.h deleted file mode 100644 index afb7f8a7ce..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialBrowserFilterModel.h +++ /dev/null @@ -1,240 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include - -#include -#include -#include -#include -#include - - -#include -#include - -namespace AZ -{ - class Job; - class JobManager; - class JobCancelGroup; - class JobContext; -} - -class SubMaterialSearchFilter; -class LevelMaterialSearchFilter; - -////////////////////////////////////////////////////////////////////////// -// Item class for browser. -////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////// -struct MaterialBrowserRecordAssetBrowserData -{ - AZ::Data::AssetId assetId; - AZStd::string relativeFilePath; - AZStd::string fullSourcePath; - QPersistentModelIndex modelIndex; - QPersistentModelIndex filterModelIndex; -}; - -class CMaterialBrowserRecord -{ -public: - CMaterialBrowserRecord() - { - InitializeSourceControlAttributes(); - } - - CMaterialBrowserRecord(const CMaterialBrowserRecord &rhs) - : m_material(rhs.m_material) - , m_lastCachedSCCAttributes(rhs.m_lastCachedSCCAttributes) - , m_lastCachedFileAttributes(rhs.m_lastCachedFileAttributes) - , m_lastCheckedSCCAttributes(rhs.m_lastCheckedSCCAttributes) - , m_assetBrowserData(rhs.m_assetBrowserData) - { - } - - AZ::Data::AssetId GetAssetId() const { return m_assetBrowserData.assetId; } - AZStd::string GetRelativeFilePath() const { return m_assetBrowserData.relativeFilePath; } - AZStd::string GetFullSourcePath() const { return m_assetBrowserData.fullSourcePath; } - QPersistentModelIndex GetModelIndex() const { return m_assetBrowserData.modelIndex; } - QPersistentModelIndex GetFilterModelIndex() const { return m_assetBrowserData.filterModelIndex; } - void SetAssetBrowserData(const MaterialBrowserRecordAssetBrowserData &assetBrowserData) { m_assetBrowserData = assetBrowserData; } - void InitializeSourceControlAttributes() - { - // Force an update by setting the last update time to 1 / 1 / 1 - m_lastCachedSCCAttributes = AzToolsFramework::SourceControlFileInfo(); - m_lastCachedFileAttributes = SCC_FILE_ATTRIBUTE_INVALID; - m_lastCheckedSCCAttributes = QDate(1, 1, 1).startOfDay(); - } -public: - _smart_ptr m_material = nullptr; - AzToolsFramework::SourceControlFileInfo m_lastCachedSCCAttributes; - ESccFileAttributes m_lastCachedFileAttributes; - QDateTime m_lastCheckedSCCAttributes; - -private: - MaterialBrowserRecordAssetBrowserData m_assetBrowserData; -}; -Q_DECLARE_METATYPE(CMaterialBrowserRecord) - - -//! MaterialBrowserSourceControlEvents -//! This bus informs the material browser filter model -//! when an ASYNC source control command has completed -class MaterialBrowserSourceControlEvents - : public AZ::EBusTraits -{ -public: - typedef AZStd::recursive_mutex MutexType; - - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; // there's only one listener - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; // theres only one listener - virtual ~MaterialBrowserSourceControlEvents() {} - - //! Signals the callback for the GetFileInfo source control op - virtual void UpdateSourceControlFileInfoCallback(const AZ::Data::AssetId &assetId, const AzToolsFramework::SourceControlFileInfo& fileInfo) = 0; - //! Updates the timestamp for when the source control status was last checked - virtual void UpdateSourceControlLastCheckedTime(const AZ::Data::AssetId &assetId, const QDateTime &dateTime) = 0; -}; - -using MaterialBrowserSourceControlBus = AZ::EBus; - -//! MaterialBrowserWidgetEvents -//! This bus is used to send events to the material browser widget -class MaterialBrowserWidgetEvents - : public AZ::EBusTraits -{ -public: - typedef AZStd::recursive_mutex MutexType; - - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; // there's only one listener - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; // theres only one listener - virtual ~MaterialBrowserWidgetEvents() {} - - //! Indicates that a material has finished being processed by the asset processor - virtual void MaterialFinishedProcessing(_smart_ptr material, const QPersistentModelIndex &filterModelIndex) = 0; - - //! Indicates that a material has finished being added to the material browser - virtual void MaterialAddFinished() = 0; - - //! Indicates that the material record update for initially populating the material browser has finished - virtual void MaterialRecordUpdateFinished() = 0; -}; - -using MaterialBrowserWidgetBus = AZ::EBus; - -/** -* Get the product material assetId for a given AssetBrowserEntry -* If there is no valid product material, the material has not been processed, or there are multiple product materials -* and thus there is not an individual material that can be assumed based on the source, an invalid assetId is returned -* @param assetEntry An asset entry that may be a source or a product -* @return The assetId of the product material. -*/ -AZ::Data::AssetId GetMaterialProductAssetIdFromAssetBrowserEntry(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* assetEntry); - -class MaterialBrowserFilterModel - : public AzToolsFramework::AssetBrowser::AssetBrowserFilterModel - , public MaterialBrowserSourceControlBus::Handler - , public AzToolsFramework::AssetBrowser::AssetBrowserModelNotificationBus::Handler - , public AzToolsFramework::MaterialBrowser::MaterialBrowserRequestBus::Handler - , private AzFramework::AssetCatalogEventBus::Handler -{ -public: - AZ_CLASS_ALLOCATOR(MaterialBrowserFilterModel, AZ::SystemAllocator, 0); - MaterialBrowserFilterModel(QObject* parent); - ~MaterialBrowserFilterModel(); - void UpdateRecord(const QModelIndex& filterModelIndex); - void UpdateRecord(const MaterialBrowserRecordAssetBrowserData &assetBrowserData); - void UpdateSourceControlFileInfoCallback(const AZ::Data::AssetId &assetId, const AzToolsFramework::SourceControlFileInfo& info) override; - void UpdateSourceControlLastCheckedTime(const AZ::Data::AssetId &assetId, const QDateTime &dateTime) override; - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; - bool TryGetRecordFromMaterial(_smart_ptr material, CMaterialBrowserRecord& record) const; - bool TryGetRecordFromAssetId(const AZ::Data::AssetId &assetId, CMaterialBrowserRecord& record) const; - void SetRecord(const CMaterialBrowserRecord& record); - void SetSearchFilter(const AzToolsFramework::AssetBrowser::SearchWidget* searchWidget); - void StartRecordUpdateJobs(); - void CancelRecordUpdateJobs(); - void ClearRecordMap(); - void GetRelativeFilePaths(AZStd::vector &files) const; - QModelIndex GetIndexFromMaterial(_smart_ptr material) const; - QModelIndex GetFilterModelIndex(const AZ::Data::AssetId &assetId) const; - - // AssetBrowserModelNotificationBus event handlers - void EntryAdded(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) override; - - void OnCatalogAssetChanged(const AZ::Data::AssetId& assetId) override; - // MaterialBrowserRequestBus - bool HasRecord(const AZ::Data::AssetId& assetId) override; - bool IsMultiMaterial(const AZ::Data::AssetId& assetId) override; - - void ShowOnlyLevelMaterials(bool levelOnly, bool invalidateFilterNow = false); - - public Q_SLOTS: - void SearchFilterUpdated(); - -private: - void GetRelativeFilePathsRecursive(AZStd::vector &files, const MaterialBrowserFilterModel* model, const QModelIndex &parent = QModelIndex()) const; - bool TryGetFilterModelIndexRecursive(QModelIndex &filterModelIndex, const AZ::Data::AssetId &assetId, const MaterialBrowserFilterModel* model, const QModelIndex &parent = QModelIndex()) const; - void QueueDataChangedEvent(const QPersistentModelIndex &filterModelIndex); - AZStd::concurrent_unordered_map m_materialRecordMap; - QVector m_imageList; - AzToolsFramework::AssetBrowser::FilterConstType m_assetTypeFilter; - SubMaterialSearchFilter* m_subMaterialSearchFilter; - LevelMaterialSearchFilter* m_levelMaterialSearchFilter; - const AzToolsFramework::AssetBrowser::SearchWidget* m_searchWidget; - - void InitializeRecordUpdateJob(); - AZ::JobManager* m_jobManager = nullptr; - AZ::JobCancelGroup* m_jobCancelGroup = nullptr; - AZ::JobContext* m_jobContext = nullptr; - AZ::Job* m_mainUpdateRecordJob = nullptr; -}; - -/** -* Job that walks through a MaterialBrowserFilterModel to generate a list of files, -* then divides the list amongst child jobs for processing -*/ -class MaterialBrowserUpdateJobCreator - : public AZ::Job -{ -public: - AZ_CLASS_ALLOCATOR(MaterialBrowserUpdateJobCreator, AZ::ThreadPoolAllocator, 0); - - MaterialBrowserUpdateJobCreator(MaterialBrowserFilterModel* model, AZStd::vector& files, AZ::JobContext* context = nullptr); - void Process() override; -private: - MaterialBrowserFilterModel* m_filterModel; - AZStd::vector m_files; -}; - -/** -* Job that walks through a list of material files, loads them, and then populates -* the MaterialBrowserFilterModel's map of material data -*/ -class MaterialBrowserUpdateJob - : public AZ::Job -{ -public: - AZ_CLASS_ALLOCATOR(MaterialBrowserUpdateJob, AZ::ThreadPoolAllocator, 0); - - MaterialBrowserUpdateJob(MaterialBrowserFilterModel* model, AZStd::vector &files, AZ::JobContext* context = nullptr); - void Process() override; -private: - MaterialBrowserFilterModel* m_filterModel; - AZStd::vector m_files; -}; - diff --git a/Code/Sandbox/Editor/Material/MaterialBrowserSearchFilters.cpp b/Code/Sandbox/Editor/Material/MaterialBrowserSearchFilters.cpp deleted file mode 100644 index cf2d3449d1..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialBrowserSearchFilters.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include "EditorDefs.h" - -#include "MaterialBrowserSearchFilters.h" - -// Editor -#include "MaterialBrowserFilterModel.h" -#include "Material.h" - - -SubMaterialSearchFilter::SubMaterialSearchFilter(const MaterialBrowserFilterModel* filterModel) - : m_filterModel(filterModel) -{ - AzToolsFramework::AssetBrowser::AssetBrowserEntryFilter::SetFilterPropagation(AzToolsFramework::AssetBrowser::AssetBrowserEntryFilter::PropagateDirection::Down); -} - -void SubMaterialSearchFilter::SetFilterString(const QString& filterString) -{ - m_filterString = filterString; -} - -QString SubMaterialSearchFilter::GetNameInternal() const -{ - return "SubMaterialSearchFilter"; -} - -bool SubMaterialSearchFilter::MatchInternal(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) const -{ - // All entries match if there is no search string - if (m_filterString.isEmpty()) - { - return true; - } - - if (m_filterModel) - { - // Get the product material for the given asset browser entry - AZ::Data::AssetId assetId = GetMaterialProductAssetIdFromAssetBrowserEntry(entry); - if (assetId.IsValid()) - { - CMaterialBrowserRecord record; - bool found = m_filterModel->TryGetRecordFromAssetId(assetId, record); - if (found) - { - // If there is a valid product material, check to see if any of its sub-materials match the search string - if (record.m_material) - { - for (int i = 0; i < record.m_material->GetSubMaterialCount(); ++i) - { - CMaterial* subMaterial = record.m_material->GetSubMaterial(i); - if (subMaterial) - { - // If any of the product sub-materials matches the string, return true for this entry - if (subMaterial->GetName().contains(m_filterString, Qt::CaseInsensitive)) - { - return true; - } - } - } - } - } - } - } - return false; -} - -LevelMaterialSearchFilter::LevelMaterialSearchFilter(const MaterialBrowserFilterModel* filterModel) - : m_filterModel(filterModel) -{ - AzToolsFramework::AssetBrowser::AssetBrowserEntryFilter::SetFilterPropagation(AzToolsFramework::AssetBrowser::AssetBrowserEntryFilter::PropagateDirection::Down); -} - -QString LevelMaterialSearchFilter::GetNameInternal() const -{ - return "LoadedMaterialSearchFilter"; -} - -void LevelMaterialSearchFilter::CacheLoadedMaterials() -{ - m_localMap.clear(); - - AZStd::vector foundRenderNodes; - unsigned int numFoundObjects = 0; - - numFoundObjects = GetIEditor()->Get3DEngine()->GetObjectsByFlags(0); - foundRenderNodes.resize(numFoundObjects, nullptr); - GetIEditor()->Get3DEngine()->GetObjectsByFlags(0, foundRenderNodes.data()); - - AZStd::vector<_smart_ptr> materials; - materials.reserve(foundRenderNodes.size()); - for (IRenderNode* renderNode : foundRenderNodes) - { - renderNode->GetMaterials(materials); - } - - for (size_t i = 0; i < materials.size(); ++i) - { - if (materials[i]) - { - m_localMap[materials[i]->GetName()] = materials[i]; - } - } -} - -bool LevelMaterialSearchFilter::MatchInternal(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) const -{ - // All entries match if show level materials isn't selected - if (!m_onlyShowLevelMaterials) - { - return true; - } - - // Get the product material for the given asset browser entry - AZ::Data::AssetId assetId = GetMaterialProductAssetIdFromAssetBrowserEntry(entry); - if (assetId.IsValid() && m_filterModel) - { - CMaterialBrowserRecord record; - bool found = m_filterModel->TryGetRecordFromAssetId(assetId, record); - if (found && record.m_material) - { - // If there is a valid product material, check to see if it is used by the level - return m_localMap.find(record.m_material->GetName()) != m_localMap.end(); - } - } - - return false; -} - -#include diff --git a/Code/Sandbox/Editor/Material/MaterialBrowserSearchFilters.h b/Code/Sandbox/Editor/Material/MaterialBrowserSearchFilters.h deleted file mode 100644 index 4326e66218..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialBrowserSearchFilters.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#if !defined(Q_MOC_RUN) -#include -#include -#endif - -class MaterialBrowserFilterModel; - -//! Filter that checks the name of each sub-material in a material to see if it contains the filter string -class SubMaterialSearchFilter - : public AzToolsFramework::AssetBrowser::AssetBrowserEntryFilter -{ - Q_OBJECT -public: - SubMaterialSearchFilter(const MaterialBrowserFilterModel* filterModel); - ~SubMaterialSearchFilter() override = default; - - void SetFilterString(const QString& filterString); - -protected: - QString GetNameInternal() const override; - bool MatchInternal(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) const override; - -private: - bool TextMatchesFilter(const QString &text) const; - QString m_filterString = ""; - const MaterialBrowserFilterModel* m_filterModel = nullptr; -}; - -class LevelMaterialSearchFilter - : public AzToolsFramework::AssetBrowser::AssetBrowserEntryFilter -{ - Q_OBJECT -public: - LevelMaterialSearchFilter(const MaterialBrowserFilterModel* filterModel); - ~LevelMaterialSearchFilter() override = default; - - void ShowOnlyLevelMaterials(bool onlyLevel) { m_onlyShowLevelMaterials = onlyLevel; } - - void CacheLoadedMaterials(); - -protected: - QString GetNameInternal() const override; - bool MatchInternal(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) const override; - -private: - bool m_onlyShowLevelMaterials = false; - const MaterialBrowserFilterModel* m_filterModel = nullptr; - using MaterialMap = QHash >; - MaterialMap m_localMap; -}; diff --git a/Code/Sandbox/Editor/Material/MaterialDialog.qrc b/Code/Sandbox/Editor/Material/MaterialDialog.qrc deleted file mode 100644 index c99e5b052a..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialDialog.qrc +++ /dev/null @@ -1,23 +0,0 @@ - - - images/material_browser_00.png - images/material_browser_01.png - images/material_browser_02.png - images/material_browser_03.png - images/material_00.png - images/material_01.png - images/material_02.png - images/material_03.png - images/material_04.png - images/material_05.png - images/material_06.png - images/material_07.png - images/filestatus_00.png - images/filestatus_01.png - images/filestatus_02.png - images/filestatus_03.png - images/filestatus_04.png - images/filestatus_05.png - images/filestatus_06.png - - diff --git a/Code/Sandbox/Editor/Material/MaterialHelpers.cpp b/Code/Sandbox/Editor/Material/MaterialHelpers.cpp deleted file mode 100644 index 8f9311a27a..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialHelpers.cpp +++ /dev/null @@ -1,372 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "MaterialHelpers.h" - -namespace MaterialHelpers -{ - ////////////////////////////////////////////////////////////////////////// - static void ParsePublicParamsScript(const char* sUIScript, IVariable* pVar) - { - string uiscript = sUIScript; - string element[3]; - int p1 = 0; - string itemToken = uiscript.Tokenize(";", p1); - while (!itemToken.empty()) - { - int nElements = 0; - int p2 = 0; - string token = itemToken.Tokenize(" \t\r\n=", p2); - while (!token.empty()) - { - element[nElements++] = token; - if (nElements == 2) - { - element[nElements] = itemToken.substr(p2); - element[nElements].Trim(" =\t\""); - break; - } - token = itemToken.Tokenize(" \t\r\n=", p2); - } - - float minLimit, maxLimit; - pVar->GetLimits(minLimit, maxLimit); - - if (azstricmp(element[1], "UIWidget") == 0) - { - if (azstricmp(element[2], "Color") == 0) - { - pVar->SetDataType(IVariable::DT_COLOR); - } - } - else if (azstricmp(element[1], "UIHelp") == 0) - { - string help = element[2]; - help.replace("\\n", "\n"); - pVar->SetDescription(help); - } - else if (azstricmp(element[1], "UIName") == 0) - { - pVar->SetHumanName(element[2].c_str()); - } - else if (azstricmp(element[1], "UIMin") == 0) - { - pVar->SetLimits(atof(element[2]), maxLimit); - } - else if (azstricmp(element[1], "UIMax") == 0) - { - pVar->SetLimits(minLimit, atof(element[2])); - } - else if (azstricmp(element[1], "UIStep") == 0) - { - } - - itemToken = uiscript.Tokenize(";", p1); - } - } - - ////////////////////////////////////////////////////////////////////////// - static void AddRealNameToDescription(IVariable* pIVar, const SShaderParam* pParam) - { - // In order to help the user discover the true names of parameters, info they need using certain script functions, - // we embed the real parameter name in the description. - QString description = pIVar->GetDescription(); - if (!description.isEmpty()) - { - description += "\n"; - } - description += "(Script Param Name = "; - description += pParam->m_Name.c_str(); - description += ")"; - pIVar->SetDescription(description); - } - - ////////////////////////////////////////////////////////////////////////// - CVarBlock* GetPublicVars(SInputShaderResources& pShaderResources) - { - if (pShaderResources.m_ShaderParams.empty()) - { - return 0; - } - - CVarBlock* pPublicVars = new CVarBlock; - for (int i = 0; i < pShaderResources.m_ShaderParams.size(); i++) - { - IVariable* pIVar = NULL; - SShaderParam* pParam = &pShaderResources.m_ShaderParams[i]; - - switch (pParam->m_Type) - { - case eType_BYTE: - pIVar = new CVariable(pParam->m_Value.m_Byte); - break; - case eType_SHORT: - pIVar = new CVariable(pParam->m_Value.m_Short); - break; - case eType_INT: - pIVar = new CVariable(pParam->m_Value.m_Int); - break; - case eType_FLOAT: - pIVar = new CVariable(pParam->m_Value.m_Float); - break; - /* case eType_STRING: - pIVar = new CVariable(pParam->m_Value.m_String); - break; */ - case eType_FCOLOR: - pIVar = new CVariable(Vec3(pParam->m_Value.m_Color[0], pParam->m_Value.m_Color[1], pParam->m_Value.m_Color[2])); - pIVar->SetDataType(IVariable::DT_COLOR); - break; - case eType_FCOLORA: - pIVar = new CVariable(Vec4(pParam->m_Value.m_Color[0], pParam->m_Value.m_Color[1], pParam->m_Value.m_Color[2], pParam->m_Value.m_Color[3])); - pIVar->SetDataType(IVariable::DT_COLORA); - break; - case eType_VECTOR: - pIVar = new CVariable(Vec3(pParam->m_Value.m_Vector[0], pParam->m_Value.m_Vector[1], pParam->m_Value.m_Vector[2])); - break; - default: - break; - } - - if (pIVar) - { - pIVar->SetName(pParam->m_Name.c_str()); - pPublicVars->AddVariable(pIVar); - - if (pParam->m_Script.size()) - { - ParsePublicParamsScript(pParam->m_Script.c_str(), pIVar); - } - - AddRealNameToDescription(pIVar, pParam); - } - } - - return pPublicVars; - } - - void SetPublicVars(CVarBlock* pPublicVars, SInputShaderResources& pInputShaderResources) - { - assert(pPublicVars); - - if (pInputShaderResources.m_ShaderParams.empty()) - { - return; - } - - int numVars = pPublicVars->GetNumVariables(); - - for (int i = 0; i < numVars; i++) - { - if (i >= numVars) - { - break; - } - - IVariable* pVar = pPublicVars->GetVariable(i); - SShaderParam* pParam = NULL; - for (int j = 0; j < pInputShaderResources.m_ShaderParams.size(); j++) - { - if (QString::compare(pVar->GetName(), pInputShaderResources.m_ShaderParams[j].m_Name.c_str()) == 0) - { - pParam = &pInputShaderResources.m_ShaderParams[j]; - break; - } - } - if (!pParam) - { - continue; - } - - switch (pParam->m_Type) - { - case eType_BYTE: - if (pVar->GetType() == IVariable::INT) - { - int val = 0; - pVar->Get(val); - pParam->m_Value.m_Byte = val; - } - break; - case eType_SHORT: - if (pVar->GetType() == IVariable::INT) - { - int val = 0; - pVar->Get(val); - pParam->m_Value.m_Short = val; - } - break; - case eType_INT: - if (pVar->GetType() == IVariable::INT) - { - int val = 0; - pVar->Get(val); - pParam->m_Value.m_Int = val; - } - break; - case eType_FLOAT: - if (pVar->GetType() == IVariable::FLOAT) - { - float val = 0; - pVar->Get(val); - pParam->m_Value.m_Float = val; - } - break; - /* - case eType_STRING: - if (pVar->GetType() == IVariable::STRING) - { - CString str; - int val = 0; - pVar->Get(val); - pParam->m_Value.m_Byte = val; - } - break; - */ - case eType_FCOLOR: - case eType_FCOLORA: - if (pVar->GetType() == IVariable::VECTOR4 && (pVar->GetDataType() == IVariable::DT_COLOR || pVar->GetDataType() == IVariable::DT_COLORA)) - { - Vec4 val(0, 0, 0, 0); - pVar->Get(val); - pParam->m_Value.m_Color[0] = val.x; - pParam->m_Value.m_Color[1] = val.y; - pParam->m_Value.m_Color[2] = val.z; - pParam->m_Value.m_Color[3] = val.w; - } - else if (pVar->GetType() == IVariable::VECTOR && (pVar->GetDataType() == IVariable::DT_COLOR || pVar->GetDataType() == IVariable::DT_COLORA)) - { - Vec3 val(0, 0, 0); - pVar->Get(val); - pParam->m_Value.m_Color[0] = val.x; - pParam->m_Value.m_Color[1] = val.y; - pParam->m_Value.m_Color[2] = val.z; - } - break; - case eType_VECTOR: - if (pVar->GetType() == IVariable::VECTOR) - { - Vec3 val(0, 0, 0); - pVar->Get(val); - pParam->m_Value.m_Vector[0] = val.x; - pParam->m_Value.m_Vector[1] = val.y; - pParam->m_Value.m_Vector[2] = val.z; - } - break; - default: - break; - } - } - } - - void SetPublicVars(CVarBlock* pPublicVars, SInputShaderResources& pInputShaderResources, IRenderShaderResources* pRenderShaderResources, IShader* pShader) - { - SetPublicVars(pPublicVars, pInputShaderResources); - - // Set shader params. - if (pRenderShaderResources) - { - pRenderShaderResources->SetShaderParams(&pInputShaderResources, pShader); - } - } - - ////////////////////////////////////////////////////////////////////////// - CVarBlock* GetShaderGenParamsVars(IShader* pShader, uint64 nShaderGenMask) - { - IShader* pTemplShader = pShader; - if (!pTemplShader) - { - return 0; - } - - SShaderGen* pShaderGen = pTemplShader->GetGenerationParams(); - if (!pShaderGen) - { - return 0; - } - - CVarBlock* pBlock = new CVarBlock; - for (int i = 0; i < pShaderGen->m_BitMask.size(); i++) - { - SShaderGenBit* pGenBit = pShaderGen->m_BitMask[i]; - if (pGenBit->m_Flags & SHGF_HIDDEN) - { - continue; - } - if (!pGenBit->m_ParamProp.empty()) - { - CVariable* pVar = new CVariable; - pBlock->AddVariable(pVar); - pVar->SetName(pGenBit->m_ParamProp.c_str()); - *pVar = (pGenBit->m_Mask & nShaderGenMask) != 0; - pVar->SetDescription(pGenBit->m_ParamDesc.c_str()); - } - } - - /* - // make sure if no valid generation parameters to not create new tab - if (!pBlock->GetVarsCount()) - { - SAFE_DELETE(pBlock); - return 0; - } - */ - - return pBlock; - } - - ////////////////////////////////////////////////////////////////////////// - uint64 SetShaderGenParamsVars(IShader* pShader, CVarBlock* pBlock) - { - IShader* pTemplShader = pShader; - if (!pTemplShader) - { - return 0; - } - - SShaderGen* pShaderGen = pTemplShader->GetGenerationParams(); - if (!pShaderGen) - { - return 0; - } - - uint64 nGenMask = 0; - - for (int i = 0; i < pShaderGen->m_BitMask.size(); i++) - { - SShaderGenBit* pGenBit = pShaderGen->m_BitMask[i]; - if (pGenBit->m_Flags & SHGF_HIDDEN) - { - continue; - } - - if (!pGenBit->m_ParamProp.empty()) - { - IVariable* pVar = pBlock->FindVariable(pGenBit->m_ParamProp.c_str()); - if (!pVar) - { - continue; - } - bool bFlagOn = false; - pVar->Get(bFlagOn); - if (bFlagOn) - { - nGenMask |= pGenBit->m_Mask; - } - } - } - - return nGenMask; - } -} diff --git a/Code/Sandbox/Editor/Material/MaterialHelpers.h b/Code/Sandbox/Editor/Material/MaterialHelpers.h deleted file mode 100644 index 0f0228db7a..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialHelpers.h +++ /dev/null @@ -1,67 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#pragma once - -#include "Material.h" - -namespace MaterialHelpers -{ - ////////////////////////////////////////////////////////////////////////// - //! Get public parameters of material in variable block. - CVarBlock* GetPublicVars(SInputShaderResources& pShaderResources); - - //! Sets variable block of public shader parameters. - //! VarBlock must be in same format as returned by GetPublicVars(). - void SetPublicVars(CVarBlock* pPublicVars, SInputShaderResources& pInputShaderResources); - void SetPublicVars(CVarBlock* pPublicVars, SInputShaderResources& pInputShaderResources, IRenderShaderResources* pRenderShaderResources, IShader* pShader); - - ////////////////////////////////////////////////////////////////////////// - CVarBlock* GetShaderGenParamsVars(IShader* pShader, uint64 nShaderGenMask); - uint64 SetShaderGenParamsVars(IShader* pShader, CVarBlock* pBlock); - - ////////////////////////////////////////////////////////////////////////// - // [Shader System TO DO] change the usage of these functions to retrieve by slot name - inline EEfResTextures FindTexSlot(const char* texName) { return GetIEditor()->Get3DEngine()->GetMaterialHelpers().FindTexSlot(texName); } - inline const char* FindTexName(EEfResTextures texSlot) { return GetIEditor()->Get3DEngine()->GetMaterialHelpers().FindTexName(texSlot); } - inline const char* LookupTexName(EEfResTextures texSlot) { return GetIEditor()->Get3DEngine()->GetMaterialHelpers().LookupTexName(texSlot); } - inline const char* LookupTexDesc(EEfResTextures texSlot) { return GetIEditor()->Get3DEngine()->GetMaterialHelpers().LookupTexDesc(texSlot); } - - //-------------------------------------------------------------------------- - // Adjustable means that the slot is not virtual, i.e. using a sub-channel from another - // slot (for example - smoothness that uses the normal's alpha) - inline bool IsAdjustableTexSlot(EEfResTextures texSlot) { return GetIEditor()->Get3DEngine()->GetMaterialHelpers().IsAdjustableTexSlot(texSlot); } - - ////////////////////////////////////////////////////////////////////////// - inline void SetTexModFromXml(SEfTexModificator& pShaderResources, const XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetTexModFromXml(pShaderResources, node); } - inline void SetXmlFromTexMod(const SEfTexModificator& pShaderResources, XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetXmlFromTexMod(pShaderResources, node); } - - ////////////////////////////////////////////////////////////////////////// - inline void SetTexturesFromXml(SInputShaderResources& pShaderResources, const XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetTexturesFromXml(pShaderResources, node); } - inline void SetXmlFromTextures( SInputShaderResources& pShaderResources, XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetXmlFromTextures(pShaderResources, node); } - - ////////////////////////////////////////////////////////////////////////// - inline void SetVertexDeformFromXml(SInputShaderResources& pShaderResources, const XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetVertexDeformFromXml(pShaderResources, node); } - inline void SetXmlFromVertexDeform(const SInputShaderResources& pShaderResources, XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetXmlFromVertexDeform(pShaderResources, node); } - - ////////////////////////////////////////////////////////////////////////// - inline void SetLightingFromXml(SInputShaderResources& pShaderResources, const XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetLightingFromXml(pShaderResources, node); } - inline void SetXmlFromLighting(const SInputShaderResources& pShaderResources, XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetXmlFromLighting(pShaderResources, node); } - - ////////////////////////////////////////////////////////////////////////// - inline void SetShaderParamsFromXml(SInputShaderResources& pShaderResources, const XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetShaderParamsFromXml(pShaderResources, node); } - inline void SetXmlFromShaderParams(const SInputShaderResources& pShaderResources, XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetXmlFromShaderParams(pShaderResources, node); } - - ////////////////////////////////////////////////////////////////////////// - inline void MigrateXmlLegacyData(SInputShaderResources& pShaderResources, const XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().MigrateXmlLegacyData(pShaderResources, node); } -} diff --git a/Code/Sandbox/Editor/Material/MaterialImageListCtrl.cpp b/Code/Sandbox/Editor/Material/MaterialImageListCtrl.cpp deleted file mode 100644 index 6ebc85c1bc..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialImageListCtrl.cpp +++ /dev/null @@ -1,834 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "MaterialImageListCtrl.h" - -// Qt -#include - -// Editor -#include "Material.h" -#include "MaterialManager.h" -#include "MaterialPreviewModelView.h" -#include "MaterialBrowser.h" -#include "Util/Image.h" - -#define ME_BG_TEXTURE "Materials/Stripes.dds" - - -#define MATERIAL_EDITOR_SPHERE_MODEL_FILE "Objects/MtlSphere.cgf" -#define MATERIAL_EDITOR_SPHERE_CAMERA_RADIUS 1.6f -#define MATERIAL_EDITOR_SPHERE_CAMERA_FROM_DIRECTION Vec3(0.1f, -1.0f, -0.1f) - -#define MATERIAL_EDITOR_BOX_MODEL_FILE "Objects/MtlBox.cgf" -#define MATERIAL_EDITOR_BOX_CAMERA_RADIUS 2.0f -#define MATERIAL_EDITOR_BOX_CAMERA_FROM_DIRECTION Vec3(0.75f, -0.75f, -0.5f) - -#define MATERIAL_EDITOR_TEAPOT_MODEL_FILE "Objects/MtlTeapot.cgf" -#define MATERIAL_EDITOR_TEAPOT_CAMERA_RADIUS 1.6f -#define MATERIAL_EDITOR_TEAPOT_CAMERA_FROM_DIRECTION Vec3(0.1f, -0.75f, -0.25f) - -#define MATERIAL_EDITOR_PLANE_MODEL_FILE "Objects/MtlPlane.cgf" -#define MATERIAL_EDITOR_PLANE_CAMERA_RADIUS 1.6f -#define MATERIAL_EDITOR_PLANE_CAMERA_FROM_DIRECTION Vec3(-0.5f, 0.5f, -0.5f) - -#define MATERIAL_EDITOR_SWATCH_MODEL_FILE "Objects/MtlSwatch.cgf" -#define MATERIAL_EDITOR_SWATCH_CAMERA_RADIUS 1.0f -#define MATERIAL_EDITOR_SWATCH_CAMERA_FROM_DIRECTION Vec3(0.0f, 0.0f, -1.0f) - - -_smart_ptr ResolveTerrainLayerPreviewMaterial(_smart_ptr material, _smart_ptr pMatPreview) -{ - if (!QString::compare(material->GetShaderName(), "Terrain.Layer")) - { - XmlNodeRef node = XmlHelpers::CreateXmlNode("Material"); - CBaseLibraryItem::SerializeContext ctx(node, false); - material->Serialize(ctx); - - if (!pMatPreview) - { - int flags = 0; - if (node->getAttr("MtlFlags", flags)) - { - flags |= MTL_FLAG_UIMATERIAL; - node->setAttr("MtlFlags", flags); - } - pMatPreview = GetIEditor()->GetMaterialManager()->CreateMaterial("_NewPreview_", node); - } - else - { - CBaseLibraryItem::SerializeContext ctx2(node, true); - pMatPreview->Serialize(ctx2); - } - pMatPreview->SetShaderName("Illum"); - pMatPreview->Update(); - return pMatPreview; - } - else - { - return material; - } -} - -struct QMaterialImageListModel::Item -{ - QImage image; - void* pUserData; - QPoint position; - QSize size; - _smart_ptr pMaterial; - QStringList vVisibleTextures; -}; - -////////////////////////////////////////////////////////////////////////// -void CMaterialImageListCtrl::OnCreate() -{ - // m_largePreviewCtrl is used to draw the 3D preview for the selected material - m_largePreviewCtrl.reset(new MaterialPreviewModelView(this)); - m_largePreviewCtrl->hide(); - // m_renderCtrl is used to draw all the sub-materials - m_renderCtrl.reset(new MaterialPreviewModelView(this, false /* disable idle updates since this is only used to create the preview list images */)); - m_renderCtrl->UnSetFlag(CPreviewModelView::PreviewModelViewFlag::SHOW_GRID); - m_renderCtrl->UnSetFlag(CPreviewModelView::PreviewModelViewFlag::SHOW_GRID_AXIS); - - if (gEnv->pSystem) - { - gEnv->pSystem->GetISystemEventDispatcher()->RegisterListener(this); - } - - // m_resizeTimer is used to stall updateGeometries being called via resizeEvents until RESIZE_TIMEOUT ms after resizing - // This prevents an Editor freeze caused by constant resizing of the Material Editor when viewing - // a high sub-material count material (LY-58389) - m_resizeTimer = new QTimer(this); - connect(m_resizeTimer, &QTimer::timeout, this, &CMaterialImageListCtrl::ResizeTimeout); -} - -void CMaterialImageListCtrl::resizeEvent([[maybe_unused]] QResizeEvent* event) -{ - m_resizeTimer->stop(); - m_resizeTimer->start(RESIZE_TIMEOUT); -} - -void CMaterialImageListCtrl::ResizeTimeout() -{ - m_resizeTimer->stop(); - updateGeometries(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialImageListCtrl::OnDestroy() -{ - if (gEnv->pSystem) - { - gEnv->pSystem->GetISystemEventDispatcher()->RemoveListener(this); - } -} - -////////////////////////////////////////////////////////////////////////// -CMaterialImageListCtrl::CMaterialImageListCtrl(QWidget* parent) - : CImageListCtrl(parent) -{ - OnCreate(); -} - -////////////////////////////////////////////////////////////////////////// -CMaterialImageListCtrl::~CMaterialImageListCtrl() -{ - OnDestroy(); -} - -////////////////////////////////////////////////////////////////////////// -QModelIndex QMaterialImageListModel::AddMaterial(CMaterial* pMaterial, void* pUserData) -{ - Item* pItem = new Item; - pItem->pMaterial = pMaterial; - pItem->pUserData = pUserData; - pMaterial->GetAnyTextureFilenames(pItem->vVisibleTextures); - - const int row = m_items.count(); - beginInsertRows(QModelIndex(), row, row); - m_items.insert(row, pItem); - endInsertRows(); - - return index(row, 0); -} - -////////////////////////////////////////////////////////////////////////// -void QMaterialImageListModel::SetMaterial(int nItemIndex, CMaterial* pMaterial, void* pUserData) -{ - assert(nItemIndex <= (int)m_items.size()); - Item* pItem = m_items.at(nItemIndex); - - pItem->vVisibleTextures.clear(); - pItem->pMaterial = pMaterial; - pItem->pUserData = pUserData; - pMaterial->GetAnyTextureFilenames(pItem->vVisibleTextures); - pItem->image = QImage(); - - QModelIndex idx = index(nItemIndex, 0); - emit dataChanged(idx, idx, QVector() << Qt::DisplayRole << Qt::DecorationRole); -} - -////////////////////////////////////////////////////////////////////////// -QModelIndex QMaterialImageListModel::FindMaterial(CMaterial* const pMaterial) -{ - for (int i = 0; i < m_items.count(); i++) - { - Item* item = m_items[i]; - if (pMaterial == item->pMaterial) - { - return index(i, 0); - } - } - return QModelIndex(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialImageListCtrl::SelectMaterial(CMaterial* pMaterial) -{ - // Force the material to load the highest resolution textures - pMaterial->GetMatInfo()->DisableTextureStreaming(); - - selectionModel()->clearSelection(); - - QMaterialImageListModel* materialModel = qobject_cast(model()); - Q_ASSERT(materialModel); - - QModelIndex index = materialModel->FindMaterial(pMaterial); - if (index.isValid()) - { - selectionModel()->select(index, QItemSelectionModel::SelectCurrent); - m_largePreviewMaterial = pMaterial; - } - else - { - // If the parent material was selected, set the first sub-material as the large preview's material so it has something to render - if (pMaterial->GetSubMaterialCount() > 0) - { - m_largePreviewMaterial = pMaterial->GetSubMaterial(0); - } - } - - GenerateAllImages(); -} - -////////////////////////////////////////////////////////////////////////// -void QMaterialImageListModel::InvalidateMaterial(CMaterial* pMaterial) -{ - QModelIndex idx = FindMaterial(pMaterial); - Item* pItem = ItemFromIndex(idx); - if ((pItem) && (m_renderCtrl)) - { - if (pMaterial) - { - // Ensure the full resolution textures are loaded for the material editor - pMaterial->GetMatInfo()->DisableTextureStreaming(); - } - - pItem->vVisibleTextures.clear(); - pMaterial->GetAnyTextureFilenames(pItem->vVisibleTextures); - pItem->image = QImage(); - GenerateImage(pItem); - - emit dataChanged(idx, idx, QVector() << Qt::DecorationRole); - } -} - -////////////////////////////////////////////////////////////////////////// -void QMaterialImageListModel::DeleteAllItems() -{ - if (m_renderCtrl) - { - m_renderCtrl->SetMaterial(nullptr); - } - beginResetModel(); - qDeleteAll(m_items); - m_items.clear(); - endResetModel(); -} - -////////////////////////////////////////////////////////////////////////// -void QMaterialImageListModel::GenerateImage(Item* pItem) -{ - // Make a bitmap from image. - Q_ASSERT(pItem); - if (!m_renderCtrl || !pItem->size.isValid()) - { - return; - } - if (pItem->image.size() == pItem->size) - { - return; - } - - Item* pMtlItem = pItem; - - CImageEx image; - - bool bPreview = false; - if (pMtlItem->pMaterial) - { - if (!(pMtlItem->pMaterial->GetFlags() & MTL_FLAG_NOPREVIEW)) - { - if (!m_renderCtrl->GetStaticModel()) - { - AZ_Warning("Material Editor", false, "Preview renderer has no object loaded!"); - return; - } - - // keep m_renderCtrl off screen, but visible - m_renderCtrl->setGeometry(QRect(-QPoint(pItem->size.width(), pItem->size.height()), pItem->size)); - - _smart_ptr matPreview = ResolveTerrainLayerPreviewMaterial(pItem->pMaterial, m_pMatPreview); - - m_renderCtrl->SetMaterial(matPreview->GetMatInfo()); - m_renderCtrl->GetImageOffscreen(image, pMtlItem->size); - } - bPreview = true; - } - - if (!bPreview) - { - image.Allocate(pItem->size.width(), pItem->size.height()); - image.Clear(); - } - - pItem->image = QImage(image.GetWidth(), image.GetHeight(), QImage::Format_RGB32); - memcpy(pItem->image.bits(), image.GetData(), image.GetSize()); -} - - -#define MENU_USE_DEFAULT 1 -#define MENU_USE_BOX 2 -#define MENU_USE_PLANE 3 -#define MENU_USE_SPHERE 4 -#define MENU_USE_TEAPOT 5 -#define MENU_BG_BLACK 6 -#define MENU_BG_GRAY 7 -#define MENU_BG_WHITE 8 -#define MENU_BG_TEXTURE 9 -#define MENU_USE_BACKLIGHT 10 - - - -////////////////////////////////////////////////////////////////////////// -void CMaterialImageListCtrl::contextMenuEvent(QContextMenuEvent* event) -{ - QAction* action; - QMenu menu; - - action = menu.addAction(tr("Use Default Object")); - action->setData(ModelDefault); - action->setCheckable(true); - action->setChecked(m_modelType == ModelType::Default); - - action = menu.addAction(tr("Use Plane")); - action->setData(ModelPlane); - action->setCheckable(true); - action->setChecked(m_modelType == ModelType::Plane); - - action = menu.addAction(tr("Use Box")); - action->setData(ModelBox); - action->setCheckable(true); - action->setChecked(m_modelType == ModelType::Box); - - action = menu.addAction(tr("Use Sphere")); - action->setData(ModelSphere); - action->setCheckable(true); - action->setChecked(m_modelType == ModelType::Sphere); - - action = menu.addAction(tr("Use Teapot")); - action->setData(ModelTeapot); - action->setCheckable(true); - action->setChecked(m_modelType == ModelType::Teapot); - - menu.addSeparator(); - - // If there is a currently selected material - if (m_materialBrowserWidget && m_largePreviewMaterial) - { - // Add context menu actions that are common to both the material browser and the preview swatches - m_materialBrowserWidget->AddContextMenuActionsSingleSelection(menu, m_largePreviewMaterial); - } - - action = menu.exec(mapToGlobal(event->pos())); - if (!action) - { - return; - } - - int cmd = action->data().toInt(); - switch (cmd) - { - case ModelDefault: - m_modelType = ModelType::Default; - LoadModel(); - break; - case ModelPlane: - m_modelType = ModelType::Plane; - LoadModel(); - break; - case ModelBox: - m_modelType = ModelType::Box; - LoadModel(); - break; - case ModelSphere: - m_modelType = ModelType::Sphere; - LoadModel(); - break; - case ModelTeapot: - m_modelType = ModelType::Teapot; - LoadModel(); - break; - default: - // If there is a currently selected material - if (m_materialBrowserWidget && m_largePreviewMaterial) - { - // Handle context menu actions that are common to both the material browser and the preview swatches - m_materialBrowserWidget->OnContextMenuAction(cmd, m_largePreviewMaterial); - } - break; - } - - QMaterialImageListModel* materialModel = - qobject_cast(model()); - Q_ASSERT(materialModel); - - materialModel->GenerateImages(); - update(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialImageListCtrl::LoadModel() -{ - switch (m_modelType) - { - case ModelType::Default: - case ModelType::Sphere: - m_largePreviewCtrl->LoadModelFile(MATERIAL_EDITOR_SPHERE_MODEL_FILE); - m_largePreviewCtrl->SetCameraLookAt(MATERIAL_EDITOR_SPHERE_CAMERA_RADIUS, MATERIAL_EDITOR_SPHERE_CAMERA_FROM_DIRECTION); - break; - case ModelType::Box: - m_largePreviewCtrl->LoadModelFile(MATERIAL_EDITOR_BOX_MODEL_FILE); - m_largePreviewCtrl->SetCameraLookAt(MATERIAL_EDITOR_BOX_CAMERA_RADIUS, MATERIAL_EDITOR_BOX_CAMERA_FROM_DIRECTION); - break; - case ModelType::Teapot: - m_largePreviewCtrl->LoadModelFile(MATERIAL_EDITOR_TEAPOT_MODEL_FILE); - m_largePreviewCtrl->SetCameraLookAt(MATERIAL_EDITOR_TEAPOT_CAMERA_RADIUS, MATERIAL_EDITOR_TEAPOT_CAMERA_FROM_DIRECTION); - break; - case ModelType::Plane: - m_largePreviewCtrl->LoadModelFile(MATERIAL_EDITOR_PLANE_MODEL_FILE); - m_largePreviewCtrl->SetCameraLookAt(MATERIAL_EDITOR_PLANE_CAMERA_RADIUS, MATERIAL_EDITOR_PLANE_CAMERA_FROM_DIRECTION); - break; - } - - GenerateAllImages(); -} - - -////////////////////////////////////////////////////////////////////////// -void CMaterialImageListCtrl::updateGeometries() -{ - ClearItemGeometries(); - m_updatingGeometries = true; - - if (!model()) - { - return; - } - - const int rowCount = model()->rowCount(); - if (!rowCount) - { - m_largePreviewCtrl->hide(); - m_largePreviewMaterial = nullptr; - return; - } - m_largePreviewCtrl->setParent(nullptr); - m_largePreviewCtrl->setParent(this); - m_largePreviewCtrl->show(); - - const int bwidth = BorderSize().width(); - const int bheight = BorderSize().height(); - m_largePreviewCtrl->move(bwidth, bheight); - - QRect rc = viewport()->contentsRect() - .adjusted(bwidth, bheight, -bwidth, -bheight); - - int cy = rc.height(); - - // Preview item is big. - if (model()->rowCount() > 0) - { - QSize size(cy, rc.height()); - m_largePreviewCtrl->SetSize(size); - m_largePreviewCtrl->resize(size); - rc.setLeft(rc.left() + cy + bwidth * 2); - m_largePreviewCtrl->show(); - } - - int cx = rc.width() - bwidth; - - int itemSize = cy; - - // Adjust all other bitmaps as tight as possible. - int numItems = model()->rowCount(); - int div = 0; - for (div = 1; div < 1000 && itemSize > 0; div++) - { - int nX = cx / (itemSize + 2); - if (nX >= numItems) - { - break; - } - if (nX > 0) - { - int nY = numItems / nX + 1; - if (nY * (itemSize + 2) < cy) - { - //itemSize = itemSize -= 2; - break; - } - } - itemSize = itemSize -= 2; - } - if (itemSize < 0) - { - itemSize = 0; - } - - QPoint pos(rc.topLeft()); - const QSize size(itemSize, itemSize); - m_renderCtrl->SetSize(size); - for (int row = 0; row < numItems; ++row) - { - QModelIndex index = model()->index(row, 0); - SetItemGeometry(index, QRect(pos, size)); - model()->setData(index, pos, QMaterialImageListModel::PositionRole); - model()->setData(index, size, Qt::SizeHintRole); - pos.rx() += itemSize + 2; - if (pos.rx() + itemSize >= rc.right()) - { - pos.rx() = rc.left(); - pos.ry() += itemSize + 2; - } - } - - m_updatingGeometries = false; - update(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialImageListCtrl::setModel(QAbstractItemModel* model) -{ - QMaterialImageListModel* materialModel = qobject_cast(model); - if (materialModel) - { - materialModel->SetPreviewModelCtrl(m_renderCtrl.data()); - } - - CImageListCtrl::setModel(model); - - auto delegate = qobject_cast(itemDelegate()); - // in case the delegate misses a pixmap we can generate it (done only once not at every painting) - connect(delegate, SIGNAL(invalidPixmapGenerated(const QModelIndex&)), materialModel, SLOT(GenerateImage(const QModelIndex&))); - connect(model, &QAbstractItemModel::dataChanged, this, &CMaterialImageListCtrl::ModelDataChanged); -} - -void CMaterialImageListCtrl::ModelDataChanged(const QModelIndex& index) -{ - // Prevent the hundreads of resize calls done in a row - // to trigger a new image computation that we already have - if (m_updatingGeometries) - { - return; - } - - GenerateImage(index); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialImageListCtrl::showEvent(QShowEvent* event) -{ - CImageListCtrl::showEvent(event); - - if (!m_largePreviewCtrl->GetStaticModel()) - { - LoadModel(); - } - if (!m_renderCtrl->GetStaticModel()) - { - m_renderCtrl->LoadModelFile(MATERIAL_EDITOR_SWATCH_MODEL_FILE); - m_renderCtrl->SetCameraLookAt(MATERIAL_EDITOR_SWATCH_CAMERA_RADIUS, MATERIAL_EDITOR_SWATCH_CAMERA_FROM_DIRECTION); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialImageListCtrl::OnSystemEvent(ESystemEvent event, UINT_PTR wparam, [[maybe_unused]] UINT_PTR lparam) -{ - switch (event) - { - // Toggle visibility of this control whenever the main editor window has a change of focus. - case ESYSTEM_EVENT_CHANGE_FOCUS: - { - setAttribute(Qt::WA_WState_Visible, (wparam != 0)); - break; - } - } - ; -} - -void CMaterialImageListCtrl::UpdateLargePreview() -{ - if (m_largePreviewMaterial) - { - m_largePreviewCtrl->SetMaterial(ResolveTerrainLayerPreviewMaterial(m_largePreviewMaterial, m_tempTerrainMaterial)->GetMatInfo()); - m_largePreviewCtrl->show(); - m_largePreviewCtrl->update(); - } -} - -void CMaterialImageListCtrl::GenerateImage(const QModelIndex& index) -{ - QMaterialImageListModel* materialModel = - qobject_cast(model()); - Q_ASSERT(materialModel); - if (m_largePreviewMaterial == materialModel->MaterialFromIndex(index)) - { - UpdateLargePreview(); - } - - materialModel->SetPreviewModelCtrl(m_renderCtrl.data()); - materialModel->GenerateImage(index); - update(); -} - -void CMaterialImageListCtrl::GenerateAllImages() -{ - QMaterialImageListModel* materialModel = - qobject_cast(model()); - Q_ASSERT(materialModel); - - UpdateLargePreview(); - - materialModel->SetPreviewModelCtrl(m_renderCtrl.data()); - materialModel->GenerateImages(); - update(); -} - -////////////////////////////////////////////////////////////////////////// -QMaterialImageListModel::QMaterialImageListModel(QObject* parent) - : QAbstractListModel(parent) - , m_renderCtrl(nullptr) -{ - BusConnect(AZ_CRC("dds", 0x780234cb)); -} - -////////////////////////////////////////////////////////////////////////// -QMaterialImageListModel::~QMaterialImageListModel() -{ - BusDisconnect(); - - qDeleteAll(m_items); -} - -////////////////////////////////////////////////////////////////////////// -MaterialPreviewModelView* QMaterialImageListModel::PreviewModelCtrl() const -{ - return m_renderCtrl; -} - -////////////////////////////////////////////////////////////////////////// -void QMaterialImageListModel::SetPreviewModelCtrl(MaterialPreviewModelView* ctrl) -{ - if (m_renderCtrl) - { - disconnect(m_renderCtrl, &MaterialPreviewModelView::destroyed, - this, &QMaterialImageListModel::ClearPreviewModelCtrl); - } - - m_renderCtrl = ctrl; - - if (m_renderCtrl) - { - connect(m_renderCtrl, &MaterialPreviewModelView::destroyed, - this, &QMaterialImageListModel::ClearPreviewModelCtrl); - } -} - -////////////////////////////////////////////////////////////////////////// -void QMaterialImageListModel::ClearPreviewModelCtrl() -{ - m_renderCtrl = nullptr; -} - -////////////////////////////////////////////////////////////////////////// -int QMaterialImageListModel::rowCount(const QModelIndex& parent) const -{ - if (parent.isValid()) - { - return 0; - } - - return m_items.count(); -} - -////////////////////////////////////////////////////////////////////////// -QVariant QMaterialImageListModel::data(const QModelIndex& index, int role) const -{ - if (!index.isValid()) - { - return QVariant(); - } - - Item* pItem = m_items.at(index.row()); - Q_ASSERT(pItem); - - switch (role) - { - case Qt::DisplayRole: - return pItem->pMaterial->GetShortName(); - - case Qt::DecorationRole: - return QPixmap::fromImage(pItem->image); - - case PositionRole: - return pItem->position; - - case Qt::SizeHintRole: - return pItem->size; - - default: - break; - } - - return QVariant(); -} - -////////////////////////////////////////////////////////////////////////// -bool QMaterialImageListModel::setData(const QModelIndex& index, const QVariant& value, int role) -{ - if (!index.isValid()) - { - return false; - } - - Item* pItem = ItemFromIndex(index); - if (!pItem) - { - return false; - } - - if (Qt::SizeHintRole == role) - { - pItem->size = value.toSize(); - emit dataChanged(index, index, QVector() << Qt::DecorationRole << Qt::SizeHintRole); - return true; - } - - if (PositionRole == role) - { - pItem->position = value.toPoint(); - } - - return false; -} - -////////////////////////////////////////////////////////////////////////// -Qt::ItemFlags QMaterialImageListModel::flags(const QModelIndex& index) const -{ - return QAbstractListModel::flags(index); -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* QMaterialImageListModel::MaterialFromIndex(QModelIndex index) const -{ - Item* pItem = ItemFromIndex(index); - if (!pItem) - { - return nullptr; - } - - return pItem->pMaterial; -} - -////////////////////////////////////////////////////////////////////////// -void* QMaterialImageListModel::UserDataFromIndex(QModelIndex index) const -{ - Item* pItem = ItemFromIndex(index); - if (!pItem) - { - return nullptr; - } - - return pItem->pUserData; -} - -////////////////////////////////////////////////////////////////////////// -void QMaterialImageListModel::GenerateImages() -{ - if ((!m_renderCtrl) || (m_items.isEmpty())) - { - return; - } - - for (Item* materialImageListItem : m_items) - { - GenerateImage(materialImageListItem); - } -} - -void QMaterialImageListModel::GenerateImage(const QModelIndex& index) -{ - if ((!m_renderCtrl) || (m_items.isEmpty())) - { - return; - } - - GenerateImage(ItemFromIndex(index)); -} - -////////////////////////////////////////////////////////////////////////// -QMaterialImageListModel::Item* QMaterialImageListModel::ItemFromIndex(QModelIndex index) const -{ - if (!index.isValid()) - { - return nullptr; - } - - return m_items.at(index.row()); -} - -////////////////////////////////////////////////////////////////////////// -void QMaterialImageListModel::OnFileChanged(AZStd::string assetPath) -{ - const int rowCount = m_items.count(); - - // update all previews who's texture(s) changed - for (int row = 0; row < rowCount; ++row) - { - Item* pItem = m_items.at(row); - - QStringList::const_iterator textureIt = std::find(pItem->vVisibleTextures.begin(), pItem->vVisibleTextures.end(), assetPath.c_str()); - if (textureIt != pItem->vVisibleTextures.end()) - { - pItem->image = QImage(); - QModelIndex idx = index(row, 0); - emit dataChanged(idx, idx, QVector() << Qt::DecorationRole); - } - } -} - -#include diff --git a/Code/Sandbox/Editor/Material/MaterialImageListCtrl.h b/Code/Sandbox/Editor/Material/MaterialImageListCtrl.h deleted file mode 100644 index fe9742fb53..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialImageListCtrl.h +++ /dev/null @@ -1,164 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_MATERIAL_MATERIALIMAGELISTCTRL_H -#define CRYINCLUDE_EDITOR_MATERIAL_MATERIALIMAGELISTCTRL_H -#pragma once - -#if !defined(Q_MOC_RUN) -#include "Controls/ImageListCtrl.h" -#include -#include "Material.h" -#include "IRenderer.h" // IAsyncTextureCompileListener -#include "IResourceCompilerHelper.h" -#include - -#include -#include -#endif - -class MaterialPreviewModelView; -class MaterialBrowserWidget; - -////////////////////////////////////////////////////////////////////////// -class CMaterialImageListCtrl - : public CImageListCtrl - , public ISystemEventListener -{ - Q_OBJECT -public: - - enum class ModelType - { - Default, - Box, - Sphere, - Teapot, - Plane - }; - - enum MenuAction - { - ModelDefault = 0, - ModelPlane, - ModelBox, - ModelSphere, - ModelTeapot, - // Context menu actions that are common to both the material browser and the preview swatches - // are handled by the same switch statement, so they need to be unique. This sets the starting point for the common actions - MaterialBrowserWidgetActionsStart - }; - - CMaterialImageListCtrl(QWidget* parent = nullptr); - ~CMaterialImageListCtrl(); - - void setModel(QAbstractItemModel* model) override; - - void EnableAutoRefresh(bool autoRefreshState, unsigned int refreshInterval); - void SelectMaterial(CMaterial* pMaterial); - void LoadModel(); - void SetMaterialBrowserWidget(MaterialBrowserWidget* materialBrowserWidget){ m_materialBrowserWidget = materialBrowserWidget; } - // ISystemEventListener - // Due to the material editor working on a ProcessEvents -> Timer based system, rather than the OnIdle update event loops - // that the other editor windows use, make sure that when the editor loses focus that the Material Editor itself loses focus. - // This will pause updates/renderings in the material editor when it does not have focus. - // This prevents certain materials from re-creating themselves and eventually overflowing a few resource buffers. - // The main window cleans up those resources during its main update, which is bypassed when the window does not have focus. - virtual void OnSystemEvent(ESystemEvent event, UINT_PTR wparam, UINT_PTR lparam); - // ~ISystemEventListener - - // Override resizeEvent and use this const to rate limit it such that it only fires RESIZE_TIMEOUT ms after resizing stops - static const int RESIZE_TIMEOUT = 100; - void resizeEvent(QResizeEvent* event) override; - -public slots: - void ModelDataChanged(const QModelIndex& index); - void ResizeTimeout(); -protected: - void OnCreate(); - void OnDestroy(); - - void contextMenuEvent(QContextMenuEvent* event) override; - void showEvent(QShowEvent* event) override; - void updateGeometries() override; - -private: - void GenerateImage(const QModelIndex& index); - void GenerateAllImages(); - void UpdateLargePreview(); - - QScopedPointer m_largePreviewCtrl; // Used to draw the main 3D preview viewport for the selected sub-material - _smart_ptr m_largePreviewMaterial; - _smart_ptr m_tempTerrainMaterial; - QScopedPointer m_renderCtrl; // Used to draw the swatches for all the sub-materials - int m_nColor; - bool m_updatingGeometries = false; - ModelType m_modelType = ModelType::Default; - MaterialBrowserWidget* m_materialBrowserWidget; - QTimer* m_resizeTimer; // Used to stall a resizeEvent from firing until RESIZE_TIMEOUT ms have passed since resizing stopped -}; - -class QMaterialImageListModel - : public QAbstractListModel - , public AzFramework::LegacyAssetEventBus::Handler -{ - struct Item; - Q_OBJECT - -public: - enum CustomRoles - { - PositionRole = Qt::UserRole - }; - - QMaterialImageListModel(QObject* parent = nullptr); - ~QMaterialImageListModel(); - - int rowCount(const QModelIndex& parent = QModelIndex()) const override; - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; - bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; - Qt::ItemFlags flags(const QModelIndex& index) const override; - - QModelIndex AddMaterial(CMaterial* pMaterial, void* pUserData = nullptr); - void SetMaterial(int nItemIndex, CMaterial* pMaterial, void* pUserData = nullptr); - QModelIndex FindMaterial(CMaterial* pMaterial); - void InvalidateMaterial(CMaterial* pMaterial); - void DeleteAllItems(); - - MaterialPreviewModelView* PreviewModelCtrl() const; - void SetPreviewModelCtrl(MaterialPreviewModelView* ctrl); - - CMaterial* MaterialFromIndex(QModelIndex index) const; - void* UserDataFromIndex(QModelIndex index) const; - -public slots: - void GenerateImages(); - void GenerateImage(const QModelIndex& index); - -protected: - void GenerateImage(Item* pItem); - Item* ItemFromIndex(QModelIndex index) const; - -private slots: - void ClearPreviewModelCtrl(); - -private: - void OnFileChanged(AZStd::string assetPath) override; - -private: - _smart_ptr m_pMatPreview; - QPointer m_renderCtrl; - QVector m_items; -}; - -#endif // CRYINCLUDE_EDITOR_MATERIAL_MATERIALIMAGELISTCTRL_H diff --git a/Code/Sandbox/Editor/Material/MaterialLibrary.cpp b/Code/Sandbox/Editor/Material/MaterialLibrary.cpp deleted file mode 100644 index 351eee5c63..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialLibrary.cpp +++ /dev/null @@ -1,151 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "MaterialLibrary.h" - -// Editor -#include "BaseLibraryItem.h" - - -////////////////////////////////////////////////////////////////////////// -// CMaterialLibrary implementation. -////////////////////////////////////////////////////////////////////////// -bool CMaterialLibrary::Save() -{ - return SaveLibrary("MaterialLibrary"); -} - -////////////////////////////////////////////////////////////////////////// -bool CMaterialLibrary::Load(const QString& filename) -{ - if (filename.isEmpty()) - { - return false; - } - SetFilename(filename); - XmlNodeRef root = XmlHelpers::LoadXmlFromFile(filename.toUtf8().data()); - if (!root) - { - return false; - } - - Serialize(root, true); - return true; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialLibrary::Serialize([[maybe_unused]] XmlNodeRef& root, [[maybe_unused]] bool bLoading) -{ - /* - if (bLoading) - { - // Loading. - CString name = GetName(); - root->getAttr( "Name",name ); - SetName( name ); - for (int i = 0; i < root->getChildCount(); i++) - { - XmlNodeRef itemNode = root->getChild(i); - CMaterial *material = new CMaterial(itemNode->getAttr("Name")); - AddItem( material ); - CBaseLibraryItem::SerializeContext ctx( itemNode,bLoading ); - material->Serialize( ctx ); - } - SetModified(false); - } - else - { - // Saving. - root->setAttr( "Name",GetName() ); - root->setAttr( "SandboxVersion",(const char*)GetIEditor()->GetFileVersion().ToFullString() ); - // Serialize prototypes. - for (int i = 0; i < GetItemCount(); i++) - { - CMaterial *pMtl = (CMaterial*)GetItem(i); - // Save materials with parents under thier parent xml node. - if (pMtl->GetParent()) - continue; - - XmlNodeRef itemNode = root->newChild( "Material" ); - CBaseLibraryItem::SerializeContext ctx( itemNode,bLoading ); - GetItem(i)->Serialize( ctx ); - } - } - */ -} - -////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////// -void CMaterialLibrary::AddItem(IDataBaseItem* item, bool bRegister) -{ - CBaseLibraryItem* pLibItem = (CBaseLibraryItem*)item; - // Check if item is already assigned to this library. - if (pLibItem->GetLibrary() != this) - { - pLibItem->SetLibrary(this); - if (bRegister) - { - m_pManager->RegisterItem(pLibItem); - } - m_items.push_back(pLibItem); - } -} - -////////////////////////////////////////////////////////////////////////// -IDataBaseItem* CMaterialLibrary::GetItem(int index) -{ - assert(index >= 0 && index < m_items.size()); - return m_items[index]; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialLibrary::RemoveItem(IDataBaseItem* item) -{ - for (int i = 0; i < m_items.size(); i++) - { - if (m_items[i] == item) - { - m_items.erase(m_items.begin() + i); - SetModified(); - break; - } - } -} - -////////////////////////////////////////////////////////////////////////// -IDataBaseItem* CMaterialLibrary::FindItem(const QString& name) -{ - for (int i = 0; i < m_items.size(); i++) - { - if (QString::compare(m_items[i]->GetName(), name, Qt::CaseInsensitive) == 0) - { - return m_items[i]; - } - } - return NULL; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialLibrary::RemoveAllItems() -{ - AddRef(); - for (int i = 0; i < m_items.size(); i++) - { - // Clear library item. - m_items[i]->SetLibrary(NULL); - } - m_items.clear(); - Release(); -} diff --git a/Code/Sandbox/Editor/Material/MaterialLibrary.h b/Code/Sandbox/Editor/Material/MaterialLibrary.h deleted file mode 100644 index 5a80500e94..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialLibrary.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_MATERIAL_MATERIALLIBRARY_H -#define CRYINCLUDE_EDITOR_MATERIAL_MATERIALLIBRARY_H -#pragma once - -#include "BaseLibrary.h" - -/** Library of prototypes. -*/ -class CRYEDIT_API CMaterialLibrary - : public CBaseLibrary -{ -public: - CMaterialLibrary(IBaseLibraryManager* pManager) - : CBaseLibrary(pManager) {}; - virtual bool Save(); - virtual bool Load(const QString& filename); - virtual void Serialize(XmlNodeRef& node, bool bLoading); - - ////////////////////////////////////////////////////////////////////////// - // CBaseLibrary override. - ////////////////////////////////////////////////////////////////////////// - void AddItem(IDataBaseItem* item, bool bRegister = true); - int GetItemCount() const { return m_items.size(); } - IDataBaseItem* GetItem(int index); - void RemoveItem(IDataBaseItem* item); - void RemoveAllItems(); - IDataBaseItem* FindItem(const QString& name); -private: - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - std::vector m_items; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING -}; - -#endif // CRYINCLUDE_EDITOR_MATERIAL_MATERIALLIBRARY_H diff --git a/Code/Sandbox/Editor/Material/MaterialManager.cpp b/Code/Sandbox/Editor/Material/MaterialManager.cpp deleted file mode 100644 index 51460ff34a..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialManager.cpp +++ /dev/null @@ -1,2095 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "MaterialManager.h" - -// Qt -#include - -// AzCore -#include - -// AzFramework -#include - -// AzToolsFramework -#include -#include -#include - -// Editor -#include "MainWindow.h" -#include "MaterialLibrary.h" -#include "MaterialSender.h" -#include "MaterialUtils.h" -#include "ModelViewport.h" -#include "ISourceControl.h" -#include "UsedResources.h" -#include "Viewport.h" -#include "Commands/CommandManager.h" -#include "Include/IObjectManager.h" -#include "Objects/BaseObject.h" -#include "Objects/SelectionGroup.h" - - -static const char* MATERIALS_LIBS_PATH = "Materials/"; -static unsigned int s_highlightUpdateCounter = 0; - -// Convert a material name into a material identifier (no extension, no gamename, etc) so that it can be compared -// in the hash. -static QString UnifyMaterialName(const QString& source) -{ - char tempBuffer[AZ_MAX_PATH_LEN]; - azstrncpy(tempBuffer, AZ_ARRAY_SIZE(tempBuffer), source.toUtf8().data(), AZ_ARRAY_SIZE(tempBuffer) - 1); - MaterialUtils::UnifyMaterialName(tempBuffer); - return QString(tempBuffer); -} - -struct SHighlightMode -{ - float m_colorHue; - float m_period; - bool m_continuous; -}; - -static SHighlightMode g_highlightModes[] = { - { 0.70f, 0.8f, true }, // purple - { 0.25f, 0.75f, false }, // green - { 0.0, 0.75f, true } // red -}; - -class CMaterialHighlighter -{ -public: - void Start(CMaterial* pMaterial, int modeFlag); - void Stop(CMaterial* pMaterial, int modeFlag); - void GetHighlightColor(ColorF* color, float* intensity, int flags); - - void ClearMaterials() { m_materials.clear(); }; - void RestoreMaterials(); - void Update(); -private: - struct SHighlightOptions - { - int m_modeFlags; - }; - - typedef std::map Materials; - Materials m_materials; -}; - -AZStd::string DccMaterialToSourcePath(const AZStd::string& relativeDccMaterialPath) -{ - AZStd::string fullSourcePath; - bool sourcePathFound = false; - - // Get source path using relative .dccmtl path - AzToolsFramework::AssetSystemRequestBus::BroadcastResult(sourcePathFound, &AzToolsFramework::AssetSystemRequestBus::Events::GetFullSourcePathFromRelativeProductPath, relativeDccMaterialPath, fullSourcePath); - - if (sourcePathFound) - { - // Set source path extension to ".mtl" - AzFramework::StringFunc::Path::ReplaceExtension(fullSourcePath, MATERIAL_FILE_EXT); - } - return fullSourcePath; -} - - -void CMaterialHighlighter::Start(CMaterial* pMaterial, int modeFlag) -{ - Materials::iterator it = m_materials.find(pMaterial); - if (it == m_materials.end()) - { - SHighlightOptions& options = m_materials[pMaterial]; - options.m_modeFlags = modeFlag; - } - else - { - SHighlightOptions& options = it->second; - options.m_modeFlags |= modeFlag; - } -} - -void CMaterialHighlighter::Stop(CMaterial* pMaterial, int modeFlag) -{ - if (pMaterial) - { - pMaterial->SetHighlightFlags(0); - } - - Materials::iterator it = m_materials.find(pMaterial); - if (it == m_materials.end()) - { - return; - } - - SHighlightOptions& options = it->second; - MAKE_SURE((options.m_modeFlags & modeFlag) != 0, return ); - - options.m_modeFlags &= ~modeFlag; - if (options.m_modeFlags == 0) - { - m_materials.erase(it); - } -} - -void CMaterialHighlighter::RestoreMaterials() -{ - for (Materials::iterator it = m_materials.begin(); it != m_materials.end(); ++it) - { - if (it->first) - { - it->first->SetHighlightFlags(0); - } - } -} - -void CMaterialHighlighter::Update() -{ - unsigned int counter = s_highlightUpdateCounter; - - Materials::iterator it; - for (it = m_materials.begin(); it != m_materials.end(); ++it) - { - // Only update each material every 4 frames - if (counter++ % 4 == 0) - { - it->first->SetHighlightFlags(it->second.m_modeFlags); - } - } - - s_highlightUpdateCounter = (s_highlightUpdateCounter + 1) % 4; -} - -void CMaterialHighlighter::GetHighlightColor(ColorF* color, float* intensity, int flags) -{ - MAKE_SURE(color != 0, return ); - MAKE_SURE(intensity != 0, return ); - - *intensity = 0.0f; - - if (flags == 0) - { - return; - } - - int flagIndex = 0; - while (flags) - { - if ((flags & 1) != 0) - { - break; - } - flags = flags >> 1; - ++flagIndex; - } - - MAKE_SURE(flagIndex < sizeof(g_highlightModes) / sizeof(g_highlightModes[0]), return ); - - const SHighlightMode& mode = g_highlightModes[flagIndex]; - float t = GetTickCount() / 1000.0f; - float h = mode.m_colorHue; - float s = 1.0f; - float v = 1.0f; - - color->fromHSV(h + sinf(t * g_PI2 * 5.0f) * 0.025f, s, v); - color->a = 1.0f; - - if (mode.m_continuous) - { - *intensity = fabsf(sinf(t * g_PI2 / mode.m_period)); - } - else - { - *intensity = max(0.0f, sinf(t * g_PI2 / mode.m_period)); - } -} - - -////////////////////////////////////////////////////////////////////////// -// CMaterialManager implementation. -////////////////////////////////////////////////////////////////////////// -CMaterialManager::CMaterialManager(CRegistrationContext& regCtx) - : m_pHighlighter(new CMaterialHighlighter) - , m_highlightMask(eHighlight_All) - , m_currentFolder("") - , m_joinThreads(false) -{ - m_bUniqGuidMap = false; - m_bUniqNameMap = true; - - m_bEditorUiReady = false; - m_bSourceControlErrorReported = false; - m_sourceControlFunctionQueued = false; - m_pLevelLibrary = (CBaseLibrary*)AddLibrary("Level", true); - - m_MatSender = new CMaterialSender(true); - - EBusFindAssetTypeByName materialResult("Material"); //from MaterialAssetTypeInfo.cpp, case insensitive - AZ::AssetTypeInfoBus::BroadcastResult(materialResult, &AZ::AssetTypeInfo::GetAssetType); - m_materialAssetType = materialResult.GetAssetType(); - - EBusFindAssetTypeByName dccMaterialResult("DccMaterial"); //from MaterialAssetTypeInfo.cpp, case insensitive - AZ::AssetTypeInfoBus::BroadcastResult(dccMaterialResult, &AZ::AssetTypeInfo::GetAssetType); - m_dccMaterialAssetType = dccMaterialResult.GetAssetType(); - - RegisterCommands(regCtx); - AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler::BusConnect(); - AzToolsFramework::AssetBrowser::AssetBrowserModelNotificationBus::Handler::BusConnect(); - AzFramework::AssetCatalogEventBus::Handler::BusConnect(); - AzToolsFramework::EditorEvents::Bus::Handler::BusConnect(); -} - -////////////////////////////////////////////////////////////////////////// -CMaterialManager::~CMaterialManager() -{ - AzToolsFramework::AssetBrowser::AssetBrowserModelNotificationBus::Handler::BusDisconnect(); - AzFramework::AssetCatalogEventBus::Handler::BusDisconnect(); - AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect(); - - delete m_pHighlighter; - m_pHighlighter = 0; - - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->GetMaterialManager()->SetListener(NULL); - } - - if (m_MatSender) - { - delete m_MatSender; - m_MatSender = 0; - } - - // Terminate thread that saves dcc materials. - m_joinThreads = true; - if (m_bEditorUiReady) - { - m_dccMaterialSaveSemaphore.release(); - m_dccMaterialSaveThread.join(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Set3DEngine() -{ - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->GetMaterialManager()->SetListener(this); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::ClearAll() -{ - SetCurrentMaterial(NULL); - CBaseLibraryManager::ClearAll(); - - m_pLevelLibrary = (CBaseLibrary*)AddLibrary("Level", true); -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::CreateMaterial(const QString& sMaterialName,const XmlNodeRef& node, int nMtlFlags, [[maybe_unused]] unsigned long nLoadingFlags) -{ - CMaterial* pMaterial = new CMaterial(sMaterialName, nMtlFlags); - - if (node) - { - CBaseLibraryItem::SerializeContext serCtx(node, true); - serCtx.bUniqName = true; - pMaterial->Serialize(serCtx); - } - if (!pMaterial->IsPureChild() && !(pMaterial->GetFlags() & MTL_FLAG_UIMATERIAL)) - { - RegisterItem(pMaterial); - } - - return pMaterial; -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::CreateMaterial(const char* sMaterialName,const XmlNodeRef& node, int nMtlFlags, unsigned long nLoadingFlags) -{ - return CreateMaterial(QString(sMaterialName), node, nMtlFlags, nLoadingFlags); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Export(XmlNodeRef& node) -{ - XmlNodeRef libs = node->newChild("MaterialsLibrary"); - for (int i = 0; i < GetLibraryCount(); i++) - { - IDataBaseLibrary* pLib = GetLibrary(i); - // Level libraries are saved in in level. - XmlNodeRef libNode = libs->newChild("Library"); - - // Export library. - libNode->setAttr("Name", pLib->GetName().toUtf8().data()); - } -} - -////////////////////////////////////////////////////////////////////////// -int CMaterialManager::ExportLib(CMaterialLibrary* pLib, XmlNodeRef& libNode) -{ - int num = 0; - // Export library. - libNode->setAttr("Name", pLib->GetName().toUtf8().data()); - libNode->setAttr("File", pLib->GetFilename().toUtf8().data()); - char version[50]; - GetIEditor()->GetFileVersion().ToString(version, AZ_ARRAY_SIZE(version)); - libNode->setAttr("SandboxVersion", version); - - // Serialize prototypes. - for (int j = 0; j < pLib->GetItemCount(); j++) - { - CMaterial* pMtl = (CMaterial*)pLib->GetItem(j); - - // Only export real used materials. - if (pMtl->IsDummy() || !pMtl->IsUsed() || pMtl->IsPureChild()) - { - continue; - } - - XmlNodeRef itemNode = libNode->newChild("Material"); - itemNode->setAttr("Name", pMtl->GetName().toUtf8().data()); - num++; - } - return num; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::SetSelectedItem(IDataBaseItem* pItem) -{ - m_pSelectedItem = (CBaseLibraryItem*)pItem; - SetCurrentMaterial((CMaterial*)pItem); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::SetCurrentMaterial(CMaterial* pMtl) -{ - if (m_pCurrentMaterial) - { - // Changing current material. save old one. - if (m_pCurrentMaterial->IsModified()) - { - m_pCurrentMaterial->Save(); - } - } - - m_pCurrentMaterial = pMtl; - if (m_pCurrentMaterial) - { - m_pCurrentMaterial->OnMakeCurrent(); - m_pCurrentEngineMaterial = m_pCurrentMaterial->GetMatInfo(); - } - else - { - m_pCurrentEngineMaterial = 0; - } - - m_pSelectedItem = pMtl; - m_pSelectedParent = pMtl ? pMtl->GetParent() : NULL; - - NotifyItemEvent(m_pCurrentMaterial, EDB_ITEM_EVENT_SELECTED); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::SetCurrentFolder(const QString& folder) -{ - m_currentFolder = folder; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::SetMarkedMaterials(const std::vector<_smart_ptr >& markedMaterials) -{ - m_markedMaterials = markedMaterials; -} - -void CMaterialManager::OnLoadShader(CMaterial* pMaterial) -{ - RemoveFromHighlighting(pMaterial, eHighlight_All); - AddForHighlighting(pMaterial); -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::GetCurrentMaterial() const -{ - return m_pCurrentMaterial; -} - -////////////////////////////////////////////////////////////////////////// -CBaseLibraryItem* CMaterialManager::MakeNewItem() -{ - CMaterial* pMaterial = new CMaterial("", 0); - return pMaterial; -} -////////////////////////////////////////////////////////////////////////// -CBaseLibrary* CMaterialManager::MakeNewLibrary() -{ - return new CMaterialLibrary(this); -} -////////////////////////////////////////////////////////////////////////// -QString CMaterialManager::GetRootNodeName() -{ - return "MaterialsLibs"; -} -////////////////////////////////////////////////////////////////////////// -QString CMaterialManager::GetLibsPath() -{ - if (m_libsPath.isEmpty()) - { - m_libsPath = MATERIALS_LIBS_PATH; - } - return m_libsPath; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::ReportDuplicateItem(CBaseLibraryItem* pItem, CBaseLibraryItem* pOldItem) -{ - QString sLibName; - if (pOldItem->GetLibrary()) - { - sLibName = pOldItem->GetLibrary()->GetName(); - } - CErrorRecord err; - err.pItem = (CMaterial*)pOldItem; - err.error = QObject::tr("Material %1 with the duplicate name to the loaded material %2 ignored").arg(pItem->GetName(), pOldItem->GetName()); - GetIEditor()->GetErrorReport()->ReportError(err); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Serialize([[maybe_unused]] XmlNodeRef& node, bool bLoading) -{ - //CBaseLibraryManager::Serialize( node,bLoading ); - if (bLoading) - { - } - else - { - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::OnEditorNotifyEvent(EEditorNotifyEvent event) -{ - CBaseLibraryManager::OnEditorNotifyEvent(event); - switch (event) - { - case eNotify_OnInit: - InitMatSender(); - break; - case eNotify_OnIdleUpdate: - m_pHighlighter->Update(); - break; - case eNotify_OnBeginGameMode: - m_pHighlighter->RestoreMaterials(); - break; - case eNotify_OnEndGameMode: - ReloadDirtyMaterials(); - break; - case eNotify_OnBeginNewScene: - SetCurrentMaterial(0); - break; - case eNotify_OnBeginSceneOpen: - SetCurrentMaterial(0); - break; - case eNotify_OnMissionChange: - SetCurrentMaterial(0); - break; - case eNotify_OnCloseScene: - SetCurrentMaterial(0); - m_pHighlighter->ClearMaterials(); - break; - case eNotify_OnQuit: - SetCurrentMaterial(0); - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->GetMaterialManager()->SetListener(NULL); - } - break; - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::ReloadDirtyMaterials() -{ - if (!GetIEditor()->Get3DEngine()) - { - return; - } - - IMaterialManager* runtimeMaterialManager = GetIEditor()->Get3DEngine()->GetMaterialManager(); - - uint32 mtlCount = 0; - - runtimeMaterialManager->GetLoadedMaterials(NULL, mtlCount); - - if (mtlCount > 0) - { - AZStd::vector<_smart_ptr> allMaterials; - - allMaterials.reserve(mtlCount); - - [[maybe_unused]] uint32 mtlCountPrev = mtlCount; - runtimeMaterialManager->GetLoadedMaterials(&allMaterials, mtlCount); - AZ_Assert(mtlCountPrev == mtlCount && mtlCount == allMaterials.size(), "It appears GetLoadedMaterials was not used correctly."); - - for (size_t i = 0; i < mtlCount; ++i) - { - _smart_ptr pMtl = allMaterials[i]; - if (pMtl && pMtl->IsDirty()) - { - runtimeMaterialManager->ReloadMaterial(pMtl); - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::LoadMaterial(const QString& sMaterialName, bool bMakeIfNotFound) -{ - LOADING_TIME_PROFILE_SECTION(GetISystem()); - - QString sMaterialNameClear = UnifyMaterialName(sMaterialName); - QString fullSourcePath = MaterialToFilename(sMaterialNameClear); - QString relativePath = PathUtil::ReplaceExtension(sMaterialNameClear.toUtf8().data(), MATERIAL_FILE_EXT).c_str(); - - return LoadMaterialInternal(sMaterialNameClear, fullSourcePath, relativePath, bMakeIfNotFound); -} - -////////////////////////////////////////////////////////////////////////// -XmlNodeRef CMaterialManager::LoadXmlNode(const QString &fullSourcePath, const QString &relativeFilePath) -{ - XmlNodeRef materialNode = GetISystem()->LoadXmlFromFile(fullSourcePath.toUtf8().data()); - if (!materialNode) - { - // try again with the product file in case its present - materialNode = GetISystem()->LoadXmlFromFile(relativeFilePath.toUtf8().data()); - } - return materialNode; -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::LoadMaterialWithFullSourcePath(const QString& relativeFilePath, const QString& fullSourcePath, bool makeIfNotFound /*= true*/) -{ - QString materialNameClear = UnifyMaterialName(relativeFilePath); - return LoadMaterialInternal(materialNameClear, fullSourcePath, relativeFilePath, makeIfNotFound); -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::LoadMaterialInternal(const QString &materialNameClear, const QString &fullSourcePath, const QString &relativeFilePath, bool makeIfNotFound) -{ - // Note: We are loading from source files here, not from compiled assets, so there is no need to query the asset system for compilation status, etc. - - // Load material with this name if not yet loaded. - CMaterial* pMaterial = (CMaterial*)FindItemByName(materialNameClear); - if (pMaterial) - { - // If this is a dummy material that was created before for not found mtl file - // try reload the mtl file again to get valid material data. - if (pMaterial->IsDummy()) - { - XmlNodeRef mtlNode = GetISystem()->LoadXmlFromFile(fullSourcePath.toUtf8().data()); - if (mtlNode) - { - DeleteMaterial(pMaterial); - pMaterial = CreateMaterial(materialNameClear, mtlNode); - } - } - return pMaterial; - } - - XmlNodeRef mtlNode = LoadXmlNode(fullSourcePath, relativeFilePath); - - if (mtlNode) - { - pMaterial = CreateMaterial(materialNameClear, mtlNode); - } - else - { - if (makeIfNotFound) - { - pMaterial = new CMaterial(materialNameClear); - pMaterial->SetDummy(true); - RegisterItem(pMaterial); - - CErrorRecord err; - err.error = QObject::tr("Material %1 not found").arg(materialNameClear); - GetIEditor()->GetErrorReport()->ReportError(err); - } - } - - return pMaterial; -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::LoadMaterial(const char* sMaterialName, bool bMakeIfNotFound) -{ - return LoadMaterial(QString(sMaterialName), bMakeIfNotFound); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::AddSourceFileOpeners(const char* fullSourceFileName, [[maybe_unused]] const AZ::Uuid& sourceUUID, AzToolsFramework::AssetBrowser::SourceFileOpenerList& openers) -{ - using namespace AzToolsFramework; - using namespace AzToolsFramework::AssetBrowser; - - // disable if other project is active - if (AzFramework::Render::RenderSystemRequestBus::HasHandlers()) - { - return; - } - - if (AZStd::wildcard_match("*.mtl", fullSourceFileName)) - { - // we can handle these! - auto materialCallback = [this](const char* fullSourceFileNameInCall, const AZ::Uuid& sourceUUIDInCall) - { - const SourceAssetBrowserEntry* fullDetails = SourceAssetBrowserEntry::GetSourceByUuid(sourceUUIDInCall); - if (fullDetails) - { - CMaterial* materialFile = LoadMaterialWithFullSourcePath(QString::fromUtf8(fullDetails->GetRelativePath().c_str()), QString::fromUtf8(fullSourceFileNameInCall), false); - if (materialFile) - { - OpenViewPane("Material Editor"); - SetCurrentMaterial(materialFile); // the material browser pane should be able to deal with this. - } - } - }; - - openers.push_back({ "O3DE_MaterialEditor", "Open In Material Editor...", QIcon(), materialCallback }); - } -} - -////////////////////////////////////////////////////////////////////////// -static bool MaterialRequiresSurfaceType(CMaterial* pMaterial) -{ - // Do not enforce Surface Type... - - // ...over editor UI materials - if ((pMaterial->GetFlags() & MTL_FLAG_UIMATERIAL) != 0) - { - return false; - } - - // ...over SKY - if (pMaterial->GetShaderName() == "DistanceCloud" || - pMaterial->GetShaderName() == "Sky" || - pMaterial->GetShaderName() == "SkyHDR") - { - return false; - } - // ...over terrain materials - if (pMaterial->GetShaderName() == "Terrain.Layer") - { - return false; - } - // ...over vegetation - if (pMaterial->GetShaderName() == "Vegetation") - { - return false; - } - - // ...over decals - bool requiresSurfaceType = true; - CVarBlock* pShaderGenParams = pMaterial->GetShaderGenParamsVars(); - if (pShaderGenParams) - { - if (IVariable* pVar = pShaderGenParams->FindVariable("Decal")) - { - int value = 0; - pVar->Get(value); - if (value) - { - requiresSurfaceType = false; - } - } - // The function GetShaderGenParamsVars allocates a new CVarBlock object, so let's clean it up here - delete pShaderGenParams; - } - return requiresSurfaceType; -} - -////////////////////////////////////////////////////////////////////////// -int CMaterialManager::GetHighlightFlags(CMaterial* pMaterial) const -{ - if (pMaterial == NULL) - { - return 0; - } - - if ((pMaterial->GetFlags() & MTL_FLAG_NODRAW) != 0) - { - return 0; - } - - int result = 0; - - if (pMaterial == m_pHighlightMaterial) - { - result |= eHighlight_Pick; - } - - const QString& surfaceTypeName = pMaterial->GetSurfaceTypeName(); - if (surfaceTypeName.isEmpty() && MaterialRequiresSurfaceType(pMaterial)) - { - result |= eHighlight_NoSurfaceType; - } - - if (GetIEditor()->Get3DEngine()) - { - if (ISurfaceTypeManager* pSurfaceManager = GetIEditor()->Get3DEngine()->GetMaterialManager()->GetSurfaceTypeManager()) - { - const ISurfaceType* pSurfaceType = pSurfaceManager->GetSurfaceTypeByName(surfaceTypeName.toUtf8().data()); - if (pSurfaceType && pSurfaceType->GetBreakability() != 0) - { - result |= eHighlight_Breakable; - } - } - } - - return result; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::AddForHighlighting(CMaterial* pMaterial) -{ - if (pMaterial == NULL) - { - return; - } - - int highlightFlags = (GetHighlightFlags(pMaterial) & m_highlightMask); - if (highlightFlags != 0) - { - m_pHighlighter->Start(pMaterial, highlightFlags); - } - - int count = pMaterial->GetSubMaterialCount(); - for (int i = 0; i < count; ++i) - { - CMaterial* pChild = pMaterial->GetSubMaterial(i); - if (!pChild) - { - continue; - } - - AddForHighlighting(pChild); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::RemoveFromHighlighting(CMaterial* pMaterial, int mask) -{ - if (pMaterial == NULL) - { - return; - } - - m_pHighlighter->Stop(pMaterial, mask); - - int count = pMaterial->GetSubMaterialCount(); - for (int i = 0; i < count; ++i) - { - CMaterial* pChild = pMaterial->GetSubMaterial(i); - if (!pChild) - { - continue; - } - - RemoveFromHighlighting(pChild, mask); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::UpdateHighlightedMaterials() -{ - IDataBaseItemEnumerator* pEnum = CBaseLibraryManager::GetItemEnumerator(); - if (!pEnum) - { - return; - } - - CMaterial* pMaterial = (CMaterial*)pEnum->GetFirst(); - while (pMaterial) - { - RemoveFromHighlighting(pMaterial, eHighlight_All); - AddForHighlighting(pMaterial); - pMaterial = (CMaterial*)pEnum->GetNext(); - } - - pEnum->Release(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::OnRequestMaterial(_smart_ptr pMatInfo) -{ - const char* pcName = pMatInfo->GetName(); - CMaterial* pMaterial = (CMaterial*) pMatInfo->GetUserData(); - - if (!pMaterial && pcName && *pcName) - { - pMaterial = LoadMaterial(pcName, false); - } - - if (pMaterial) - { - _smart_ptr pNewMatInfo = pMaterial->GetMatInfo(true); - assert(pNewMatInfo == pMatInfo); - //Only register if the material is not registered - if (!pMaterial->IsRegistered()) - { - RegisterItem(pMaterial); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::OnCreateMaterial(_smart_ptr pMatInfo) -{ - CMaterial* existingMaterial = static_cast(FindItemByName(UnifyMaterialName(pMatInfo->GetName()))); - bool materialAlreadyExists = existingMaterial != nullptr; - - // If its not a sub-material or a UI material - if (!(pMatInfo->GetFlags() & MTL_FLAG_PURE_CHILD) && !(pMatInfo->GetFlags() & MTL_FLAG_UIMATERIAL)) - { - // Create a new editor material if it doesn't exist - if (!materialAlreadyExists) - { - CMaterial* pMaterial = new CMaterial(pMatInfo->GetName()); - pMaterial->SetFromMatInfo(pMatInfo); - RegisterItem(pMaterial); - - AddForHighlighting(pMaterial); - } - else - { - // If the material already exists, re-set its values from the engine material that was just re-loaded - existingMaterial->SetFromMatInfo(pMatInfo); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::OnDeleteMaterial(_smart_ptr pMaterial) -{ - CMaterial* pMtl = (CMaterial*)pMaterial->GetUserData(); - if (pMtl) - { - RemoveFromHighlighting(pMtl, eHighlight_All); - DeleteMaterial(pMtl); - } -} - -////////////////////////////////////////////////////////////////////////// -bool CMaterialManager::IsCurrentMaterial(_smart_ptr pMaterial) const -{ - if (!pMaterial) - { - return false; - } - - CMaterial* pMtl = static_cast(pMaterial->GetUserData()); - bool currentMaterial = (pMtl == m_pCurrentMaterial); - - if (pMtl->GetParent()) - { - currentMaterial |= (pMtl->GetParent() == m_pCurrentMaterial); - } - - for (size_t subMatIdx = 0; subMatIdx < pMtl->GetMatInfo()->GetSubMtlCount(); ++subMatIdx) - { - if (static_cast(pMtl->GetMatInfo()->GetSubMtl(subMatIdx)->GetUserData()) == m_pCurrentMaterial) - { - currentMaterial = true; - break; - } - } - - return currentMaterial; -} - - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::FromIMaterial(_smart_ptr engineMaterial) -{ - if (!engineMaterial) - { - return nullptr; - } - CMaterial* editorMaterial = (CMaterial*)engineMaterial->GetUserData(); - if (!editorMaterial) - { - // If the user data isn't set, check for an existing material with the same name - editorMaterial = static_cast(FindItemByName(UnifyMaterialName(engineMaterial->GetName()))); - } - return editorMaterial; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::SaveAllLibs() -{ -} - -////////////////////////////////////////////////////////////////////////// -QString CMaterialManager::FilenameToMaterial(const QString& filename) -{ - // Convert a full or relative path to a normalized name that can be used in a hash (so lowercase, relative path, correct slashes, remove extension) - // note that it may already be an asset path, if so, don't add the overhead of calling into the AP and convert it. - // if it starts with an alias (@) or if its an absolute file path, we need to convert it. Otherwise we really don't... - QString name = filename; - if (name.startsWith(QChar('@')) || AZ::IO::PathView(name.toUtf8().data()).IsAbsolute()) - { - name = Path::FullPathToGamePath(filename); // convert any full path to a relative path instead. - } - QByteArray n = name.toUtf8(); - MaterialUtils::UnifyMaterialName(n.data()); // Utility function used by all other parts of the code to unify slashes, lowercase, and remove extension - - return QString::fromUtf8(n); -} - -////////////////////////////////////////////////////////////////////////// -QString CMaterialManager::MaterialToFilename(const QString& sMaterialName) -{ - QString materialWithExtension = Path::ReplaceExtension(sMaterialName, MATERIAL_FILE_EXT); - QString fileName = Path::GamePathToFullPath(materialWithExtension); - const int mtlExtensionLength = strlen(MATERIAL_FILE_EXT); - if (fileName.right(mtlExtensionLength).toLower() != MATERIAL_FILE_EXT) - { - // we got something back which is not a mtl, fall back heuristic: - AZStd::string pathName(fileName.toUtf8().data()); - AZStd::string fileNameOfMaterial; - AzFramework::StringFunc::Path::StripFullName(pathName); // remove the filename of the path to the FBX file so now it just contains the folder of the fbx file. - AzFramework::StringFunc::Path::GetFullFileName(materialWithExtension.toUtf8().data(), fileNameOfMaterial); // remove the path part of the material so it only contains the file name - AZStd::string finalName; - AzFramework::StringFunc::Path::Join(pathName.c_str(), fileNameOfMaterial.c_str(), finalName); - fileName = finalName.c_str(); - } - return fileName; -} - -////////////////////////////////////////////////////////////////////////// -const AZ::Data::AssetType& CMaterialManager::GetMaterialAssetType() -{ - return m_materialAssetType; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::DeleteMaterial(CMaterial* pMtl) -{ - assert(pMtl); - _smart_ptr _ref(pMtl); - if (pMtl == GetCurrentMaterial()) - { - SetCurrentMaterial(NULL); - } - - DeleteItem(pMtl); - - // Delete it from all sub materials. - for (int i = 0; i < m_pLevelLibrary->GetItemCount(); i++) - { - CMaterial* pMultiMtl = (CMaterial*)m_pLevelLibrary->GetItem(i); - if (pMultiMtl->IsMultiSubMaterial()) - { - for (int slot = 0; slot < pMultiMtl->GetSubMaterialCount(); slot++) - { - if (pMultiMtl->GetSubMaterial(slot) == pMultiMtl) - { - // Clear this sub material slot. - pMultiMtl->SetSubMaterial(slot, 0); - } - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::RemoveMaterialFromDisk(const char * fileName) -{ - using namespace AzToolsFramework; - if (fileName) - { - SourceControlCommandBus::Broadcast(&SourceControlCommandBus::Events::RequestDelete, fileName, - [](bool success, const SourceControlFileInfo& info) - { - //If the file is not managed by source control, delete it locally - if (!success && !info.IsManaged()) - { - QFile::remove(info.m_filePath.c_str()); - } - } - ); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::RegisterCommands(CRegistrationContext& regCtx) -{ - CommandManagerHelper::RegisterCommand(regCtx.pCommandManager, "material", "duplicate", "", "", AZStd::bind(&CMaterialManager::Command_Duplicate, this)); - CommandManagerHelper::RegisterCommand(regCtx.pCommandManager, "material", "merge", "", "", AZStd::bind(&CMaterialManager::Command_Merge, this)); - CommandManagerHelper::RegisterCommand(regCtx.pCommandManager, "material", "delete", "", "", AZStd::bind(&CMaterialManager::Command_Delete, this)); - CommandManagerHelper::RegisterCommand(regCtx.pCommandManager, "material", "assign_to_selection", "", "", AZStd::bind(&CMaterialManager::Command_AssignToSelection, this)); - CommandManagerHelper::RegisterCommand(regCtx.pCommandManager, "material", "select_assigned_objects", "", "", AZStd::bind(&CMaterialManager::Command_SelectAssignedObjects, this)); - CommandManagerHelper::RegisterCommand(regCtx.pCommandManager, "material", "select_from_object", "", "", AZStd::bind(&CMaterialManager::Command_SelectFromObject, this)); -} - -////////////////////////////////////////////////////////////////////////// -bool CMaterialManager::SelectSaveMaterial(QString& itemName, QString& fullSourcePath, const char* defaultStartPath) -{ - QString startPath; - if (defaultStartPath && defaultStartPath[0] != '\0') - { - startPath = defaultStartPath; - } - else - { - startPath = GetIEditor()->GetSearchPath(EDITOR_PATH_MATERIALS); - } - - if (!CFileUtil::SelectSaveFile("Material Files (*.mtl)", "mtl", startPath, fullSourcePath)) - { - return false; - } - - itemName = FilenameToMaterial(fullSourcePath); - if (itemName.isEmpty()) - { - return false; - } - - return true; -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::SelectNewMaterial(int nMtlFlags, [[maybe_unused]] const char* sStartPath) -{ - QString path = m_pCurrentMaterial ? Path::GetPath(m_pCurrentMaterial->GetFilename()) : m_currentFolder; - QString itemName; - QString fullPath; - if (!SelectSaveMaterial(itemName, fullPath, path.toUtf8().data())) - { - return 0; - } - - if (FindItemByName(itemName)) - { - Warning("Material with name %s already exist", itemName.toUtf8().data()); - return 0; - } - - _smart_ptr mtl = CreateMaterial(itemName, XmlNodeRef(), nMtlFlags); - mtl->Update(); - bool skipReadOnly = true; - mtl->Save(skipReadOnly, fullPath); - SetCurrentMaterial(mtl); - return mtl; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_Create() -{ - SelectNewMaterial(0); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_CreateMulti() -{ - SelectNewMaterial(MTL_FLAG_MULTI_SUBMTL); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_ConvertToMulti() -{ - CMaterial* pMaterial = GetCurrentMaterial(); - - if (pMaterial && pMaterial->GetSubMaterialCount() == 0) - { - CMaterial* pSubMat = new CMaterial(*pMaterial); - pSubMat->SetName(pSubMat->GetShortName()); - pSubMat->SetFlags(pSubMat->GetFlags() | MTL_FLAG_PURE_CHILD); - - pMaterial->SetFlags(MTL_FLAG_MULTI_SUBMTL); - pMaterial->SetSubMaterialCount(1); - pMaterial->SetSubMaterial(0, pSubMat); - - pMaterial->Save(); - pMaterial->Reload(); - SetSelectedItem(pSubMat); - } - else - { - Warning(pMaterial ? "azlmbr.legacy.material.convert_to_multi called on invalid material setup" : "azlmbr.legacy.material.convert_to_multi called while no material selected"); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_Duplicate() -{ - CMaterial* pSrcMtl = GetCurrentMaterial(); - - if (!pSrcMtl) - { - CErrorRecord err; - err.error = "azlmbr.legacy.material.duplicate called while no materials selected"; - GetIEditor()->GetErrorReport()->ReportError(err); - return; - } - - if (GetIEditor()->IsSourceControlAvailable()) - { - uint32 attrib = pSrcMtl->GetFileAttributes(); - - if ((attrib & SCC_FILE_ATTRIBUTE_INPAK) && (attrib & SCC_FILE_ATTRIBUTE_MANAGED) && !(attrib & SCC_FILE_ATTRIBUTE_NORMAL)) - { - // Get latest for making folders with right case - CFileUtil::GetLatestFromSourceControl(pSrcMtl->GetFilename().toUtf8().data()); - } - } - - if (pSrcMtl != 0 && !pSrcMtl->IsPureChild()) - { - QString newUniqueRelativePath = MakeUniqueItemName(pSrcMtl->GetName()); - - // Create a new material. - _smart_ptr pMtl = DuplicateMaterial(newUniqueRelativePath.toUtf8().data(), pSrcMtl); - if (pMtl) - { - // Get the new filename from the relative path - AZStd::string newFileName; - AzFramework::StringFunc::Path::GetFileName(newUniqueRelativePath.toUtf8().data(), newFileName); - - // Get the full path to the original material, so we know which folder to put the new material in - AZStd::string newFullFilePath = pSrcMtl->GetFilename().toUtf8().data(); - - // Replace the original material filename with the filename from the new relative path + the material file extension to get the new full file path - AzFramework::StringFunc::Path::ReplaceFullName(newFullFilePath, newFileName.c_str(), MATERIAL_FILE_EXT); - - AzFramework::StringFunc::Path::Normalize(newFullFilePath); - - const bool skipReadOnly = true; - pMtl->Save(skipReadOnly, newFullFilePath.c_str()); - SetSelectedItem(pMtl); - } - } -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::DuplicateMaterial(const char* newName, CMaterial* pOriginal) -{ - if (!newName) - { - assert(0 && "NULL newName passed into CMaterialManager::DuplicateMaterial"); - return 0; - } - if (!pOriginal) - { - assert(0 && "NULL pOriginal passed into CMaterialManager::DuplicateMaterial"); - return 0; - } - - - XmlNodeRef node = GetISystem()->CreateXmlNode("Material"); - CBaseLibraryItem::SerializeContext ctx(node, false); - ctx.bCopyPaste = true; - pOriginal->Serialize(ctx); - - return CreateMaterial(newName, node, pOriginal->GetFlags()); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::GenerateUniqueSubmaterialName(const CMaterial* pSourceMaterial, const CMaterial* pTargetMaterial, QString& uniqueSubmaterialName) const -{ - QString sourceMaterialName = pSourceMaterial->GetName(); - - // We don't need the whole path to the material, just the base name - QFileInfo filename(sourceMaterialName); - sourceMaterialName = filename.baseName(); - - uniqueSubmaterialName = sourceMaterialName; - size_t nameIndex = 0; - - bool nameUpdated = true; - while (nameUpdated) - { - nameUpdated = false; - for (size_t k = 0; k < pTargetMaterial->GetSubMaterialCount(); ++k) - { - CMaterial* pSubMaterial = pTargetMaterial->GetSubMaterial(k); - if (pSubMaterial && pSubMaterial->GetName() == uniqueSubmaterialName) - { - ++nameIndex; - uniqueSubmaterialName = QStringLiteral("%1%2").arg(sourceMaterialName).arg(nameIndex, 2, 10, QLatin1Char('0')); - nameUpdated = true; - break; - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -bool CMaterialManager::DuplicateAsSubMaterialAtIndex(CMaterial* pSourceMaterial, CMaterial* pTargetMaterial, int subMaterialIndex) -{ - if (pSourceMaterial && pTargetMaterial && pTargetMaterial->GetSubMaterialCount() > subMaterialIndex) - { - // Resolve name collisions between the source material and the submaterials in the target material - QString newSubMaterialName; - GenerateUniqueSubmaterialName(pSourceMaterial, pTargetMaterial, newSubMaterialName); - - // Mark the material to be duplicated as a PURE_CHILD since it is being duplicated as a submaterial - int sourceMaterialFlags = pSourceMaterial->GetFlags(); - pSourceMaterial->SetFlags(sourceMaterialFlags | MTL_FLAG_PURE_CHILD); - - CMaterial* pNewSubMaterial = DuplicateMaterial(newSubMaterialName.toUtf8().data(), pSourceMaterial); - pTargetMaterial->SetSubMaterial(subMaterialIndex, pNewSubMaterial); - - // Reset the flags of the source material to their original values - pSourceMaterial->SetFlags(sourceMaterialFlags); - return true; - } - - return false; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_Merge() -{ - QString itemName; - QString fullPath; - QString defaultMaterialPath; - if (m_pCurrentMaterial) - { - defaultMaterialPath = Path::GetPath(m_pCurrentMaterial->GetFilename()); - } - if (!SelectSaveMaterial(itemName, fullPath, defaultMaterialPath.toUtf8().data())) - { - return; - } - - _smart_ptr pNewMaterial = CreateMaterial(itemName, XmlNodeRef(), MTL_FLAG_MULTI_SUBMTL); - - size_t totalSubMaterialCount = 0; - for (_smart_ptr pMaterial : m_markedMaterials) - { - if (pMaterial->IsMultiSubMaterial()) - { - totalSubMaterialCount += pMaterial->GetSubMaterialCount(); - } - else - { - totalSubMaterialCount++; - } - } - pNewMaterial->SetSubMaterialCount(totalSubMaterialCount); - - size_t subMaterialIndex = 0; - for (_smart_ptr pMaterial : m_markedMaterials) - { - if (pMaterial->IsMultiSubMaterial()) - { - // Loop through each submaterial and duplicate it as a submaterial in the new material - for (size_t j = 0; j < pMaterial->GetSubMaterialCount(); ++j) - { - CMaterial* pSubMaterial = pMaterial->GetSubMaterial(j); - if (DuplicateAsSubMaterialAtIndex(pSubMaterial, pNewMaterial, subMaterialIndex)) - { - ++subMaterialIndex; - } - } - } - else - { - // Duplicate the material as a submaterial in the new material - if (DuplicateAsSubMaterialAtIndex(pMaterial, pNewMaterial, subMaterialIndex)) - { - ++subMaterialIndex; - } - } - } - - pNewMaterial->Update(); - const bool skipReadOnly = true; - pNewMaterial->Save(skipReadOnly, fullPath); - SetCurrentMaterial(pNewMaterial); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_Delete() -{ - CMaterial* pMtl = GetCurrentMaterial(); - if (pMtl) - { - CUndo undo("Delete Material"); - QString str = QObject::tr("Delete Material %1?\r\nNote: Material file %2 will also be deleted.") - .arg(pMtl->GetName(), pMtl->GetFilename()); - if (QMessageBox::question(QApplication::activeWindow(), QObject::tr("Delete Confirmation"), str) == QMessageBox::Yes) - { - AZStd::string matName = pMtl->GetFilename().toUtf8().data(); - DeleteMaterial(pMtl); - RemoveMaterialFromDisk(matName.c_str()); - SetCurrentMaterial(0); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_AssignToSelection() -{ - CMaterial* pMtl = GetCurrentMaterial(); - if (pMtl) - { - CUndo undo("Assign Material"); - CSelectionGroup* pSel = GetIEditor()->GetSelection(); - if (pMtl->IsPureChild()) - { - const QString title = QObject::tr("Assign Submaterial"); - const QString message = QObject::tr("You can assign submaterials to objects only for preview purpose. This assignment will not be saved with the level and will not be exported to the game."); - if (QMessageBox::information(QApplication::activeWindow(), title, message, QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel) - { - return; - } - } - if (!pSel->IsEmpty()) - { - for (int i = 0; i < pSel->GetCount(); i++) - { - pSel->GetObject(i)->SetMaterial(pMtl); - } - } - } - CViewport* pViewport = GetIEditor()->GetActiveView(); - if (pViewport) - { - pViewport->Drop(QPoint(-1, -1), pMtl); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_ResetSelection() -{ - CSelectionGroup* pSel = GetIEditor()->GetSelection(); - if (!pSel->IsEmpty()) - { - CUndo undo("Reset Material"); - for (int i = 0; i < pSel->GetCount(); i++) - { - pSel->GetObject(i)->SetMaterial(0); - } - } - CViewport* pViewport = GetIEditor()->GetActiveView(); - if (pViewport) - { - pViewport->Drop(QPoint(-1, -1), 0); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_SelectAssignedObjects() -{ - CMaterial* pMtl = GetCurrentMaterial(); - if (pMtl) - { - CUndo undo("Select Object(s)"); - CBaseObjectsArray objects; - GetIEditor()->GetObjectManager()->GetObjects(objects); - for (int i = 0; i < objects.size(); i++) - { - CBaseObject* pObject = objects[i]; - if (pObject->GetMaterial() == pMtl || pObject->GetRenderMaterial() == pMtl) - { - if (pObject->IsHidden() || pObject->IsFrozen()) - { - continue; - } - GetIEditor()->GetObjectManager()->SelectObject(pObject); - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_SelectFromObject() -{ - if (GetIEditor()->IsInPreviewMode()) - { - CViewport* pViewport = GetIEditor()->GetActiveView(); - if (CModelViewport* p = viewport_cast(pViewport)) - { - CMaterial* pMtl = p->GetMaterial(); - SetCurrentMaterial(pMtl); - } - return; - } - - CSelectionGroup* pSel = GetIEditor()->GetSelection(); - if (pSel->IsEmpty()) - { - return; - } - - for (int i = 0; i < pSel->GetCount(); i++) - { - CMaterial* pMtl = pSel->GetObject(i)->GetRenderMaterial(); - if (pMtl) - { - SetCurrentMaterial(pMtl); - return; - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::PickPreviewMaterial() -{ - XmlNodeRef data = XmlHelpers::CreateXmlNode("ExportMaterial"); - CMaterial* pMtl = GetCurrentMaterial(); - if (!pMtl) - { - return; - } - - if (pMtl->IsPureChild() && pMtl->GetParent()) - { - pMtl = pMtl->GetParent(); - } - - if (pMtl->GetFlags() & MTL_FLAG_WIRE) - { - data->setAttr("Flag_Wire", 1); - } - if (pMtl->GetFlags() & MTL_FLAG_2SIDED) - { - data->setAttr("Flag_2Sided", 1); - } - - data->setAttr("Name", pMtl->GetName().toUtf8().data()); - data->setAttr("FileName", pMtl->GetFilename().toUtf8().data()); - - XmlNodeRef node = data->newChild("Material"); - - CBaseLibraryItem::SerializeContext serCtx(node, false); - pMtl->Serialize(serCtx); - - - if (!pMtl->IsMultiSubMaterial()) - { - XmlNodeRef texturesNode = node->findChild("Textures"); - if (texturesNode) - { - for (int i = 0; i < texturesNode->getChildCount(); i++) - { - XmlNodeRef texNode = texturesNode->getChild(i); - QString file; - if (texNode->getAttr("File", file)) - { - texNode->setAttr("File", Path::GamePathToFullPath(file).toUtf8().data()); - } - } - } - } - else - { - XmlNodeRef childsNode = node->findChild("SubMaterials"); - if (childsNode) - { - int nSubMtls = childsNode->getChildCount(); - for (int i = 0; i < nSubMtls; i++) - { - XmlNodeRef node2 = childsNode->getChild(i); - XmlNodeRef texturesNode = node2->findChild("Textures"); - if (texturesNode) - { - for (int ii = 0; ii < texturesNode->getChildCount(); ii++) - { - XmlNodeRef texNode = texturesNode->getChild(ii); - QString file; - if (texNode->getAttr("File", file)) - { - texNode->setAttr("File", Path::GamePathToFullPath(file).toUtf8().data()); - } - } - } - } - } - } - - - m_MatSender->SendMessage(eMSM_GetSelectedMaterial, data); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::SyncMaterialEditor() -{ -#if defined(AZ_PLATFORM_WINDOWS) - if (!m_MatSender) - { - return; - } - - if (!m_MatSender->GetMessage()) - { - return; - } - - if (m_MatSender->m_h.msg == eMSM_Create) - { - XmlNodeRef node = m_MatSender->m_node->findChild("Material"); - if (!node) - { - return; - } - - QString sMtlName; - QString sMaxFile; - - XmlNodeRef root = m_MatSender->m_node; - root->getAttr("Name", sMtlName); - root->getAttr("MaxFile", sMaxFile); - - int IsMulti = 0; - root->getAttr("IsMulti", IsMulti); - - int nMtlFlags = 0; - if (IsMulti) - { - nMtlFlags |= MTL_FLAG_MULTI_SUBMTL; - } - - if (root->haveAttr("Flag_Wire")) - { - nMtlFlags |= MTL_FLAG_WIRE; - } - if (root->haveAttr("Flag_2Sided")) - { - nMtlFlags |= MTL_FLAG_2SIDED; - } - - _smart_ptr pMtl = SelectNewMaterial(nMtlFlags, Path::GetPath(sMaxFile).toUtf8().data()); - - if (!pMtl) - { - return; - } - - if (!IsMulti) - { - node->delAttr("Shader"); // Remove shader attribute. - XmlNodeRef texturesNode = node->findChild("Textures"); - if (texturesNode) - { - for (int i = 0; i < texturesNode->getChildCount(); i++) - { - XmlNodeRef texNode = texturesNode->getChild(i); - QString file; - if (texNode->getAttr("File", file)) - { - //make path relative to the project specific game folder - QString newfile = Path::MakeGamePath(file); - if (!newfile.isEmpty()) - { - file = newfile; - } - texNode->setAttr("File", file.toUtf8().data()); - } - } - } - } - else - { - XmlNodeRef childsNode = node->findChild("SubMaterials"); - if (childsNode) - { - int nSubMtls = childsNode->getChildCount(); - for (int i = 0; i < nSubMtls; i++) - { - XmlNodeRef node2 = childsNode->getChild(i); - node2->delAttr("Shader"); // Remove shader attribute. - XmlNodeRef texturesNode = node2->findChild("Textures"); - if (texturesNode) - { - for (int ii = 0; ii < texturesNode->getChildCount(); ii++) - { - XmlNodeRef texNode = texturesNode->getChild(ii); - QString file; - if (texNode->getAttr("File", file)) - { - //make path relative to the project specific game folder - QString newfile = Path::MakeGamePath(file); - if (!newfile.isEmpty()) - { - file = newfile; - } - texNode->setAttr("File", file.toUtf8().data()); - } - } - } - } - } - } - - CBaseLibraryItem::SerializeContext ctx(node, true); - ctx.bUndo = true; - pMtl->Serialize(ctx); - - pMtl->Update(); - - SetCurrentMaterial(0); - SetCurrentMaterial(pMtl); - } - - if (m_MatSender->m_h.msg == eMSM_GetSelectedMaterial) - { - PickPreviewMaterial(); - } -#endif -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::InitMatSender() -{ - //MatSend(true); - m_MatSender->Create(); - QWidget* mainWindow = MainWindow::instance(); - m_MatSender->SetupWindows(mainWindow, mainWindow); - XmlNodeRef node = XmlHelpers::CreateXmlNode("Temp"); - m_MatSender->SendMessage(eMSM_Init, node); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::GotoMaterial([[maybe_unused]] CMaterial* pMaterial) -{ -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::GotoMaterial([[maybe_unused]] _smart_ptr pMtl) -{ -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::SetHighlightedMaterial(CMaterial* pMtl) -{ - if (m_pHighlightMaterial) - { - RemoveFromHighlighting(m_pHighlightMaterial, eHighlight_Pick); - } - - m_pHighlightMaterial = pMtl; - if (m_pHighlightMaterial) - { - AddForHighlighting(m_pHighlightMaterial); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::HighlightedMaterialChanged(CMaterial* pMtl) -{ - if (!pMtl) - { - return; - } - - RemoveFromHighlighting(pMtl, eHighlight_All); - AddForHighlighting(pMtl); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::SetHighlightMask(int highlightMask) -{ - if (m_highlightMask != highlightMask) - { - m_highlightMask = highlightMask; - - UpdateHighlightedMaterials(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::GatherResources(_smart_ptr pMaterial, CUsedResources& resources) -{ - if (!pMaterial) - { - return; - } - - int nSubMtlCount = pMaterial->GetSubMtlCount(); - if (nSubMtlCount > 0) - { - for (int i = 0; i < nSubMtlCount; i++) - { - GatherResources(pMaterial->GetSubMtl(i), resources); - } - } - else - { - SShaderItem& shItem = pMaterial->GetShaderItem(); - if (shItem.m_pShaderResources) - { - SInputShaderResources res; - shItem.m_pShaderResources->ConvertToInputResource(&res); - - for (auto& iter : res.m_TexturesResourcesMap ) - { - SEfResTexture* pTexture = &(iter.second); - if (!pTexture->m_Name.empty()) - { - resources.Add(pTexture->m_Name.c_str()); - } - } - gEnv->pRenderer->EF_ReleaseInputShaderResource(&res); - } - } -} - -/////////////////////////////////////////////////////////////////////////// -void CMaterialManager::GetHighlightColor(ColorF* color, float* intensity, int flags) -{ - MAKE_SURE(m_pHighlighter, return ); - m_pHighlighter->GetHighlightColor(color, intensity, flags); -} - -/////////////////////////////////////////////////////////////////////////// -// This will be called when the editor welcome screen is displayed. -// At this point the editor is ready for UI events, which means we can -// process .dccmtl paths and display error to the user if necessary -bool CMaterialManager::SkipEditorStartupUI() -{ - // Editor started - m_bEditorUiReady = true; - - // If we have any file paths buffered - if (m_sourceControlBuffer.size() > 0) - { - // Start queuing - QueueSourceControlTick(); - } - - // Launch thread responsible for saving cached - // .dccmtl files as source .mtl files - StartDccMaterialSaveThread(); - - // Never want to skip Startup UI - return false; -} - -/////////////////////////////////////////////////////////////////////////// -// Queues the function TickSourceControl() to be exectued next frame -void CMaterialManager::QueueSourceControlTick() -{ - // If TickSourceControl is not currently queued - if (!m_sourceControlFunctionQueued) - { - // Queue it - AZStd::function tickFunction = [this]() - { - TickSourceControl(); - }; - AZ::SystemTickBus::QueueFunction(tickFunction); - - // Stop further queues as TickSourceControl will queue itself - // until there are no more paths in the buffer to process - m_sourceControlFunctionQueued = true; - } -} - -/////////////////////////////////////////////////////////////////////////// -// Takes a single path from m_sourceControlBuffer and passes it to -// DccMaterialSourceControlCheck(). Then if there are more paths -// remaining in the buffer, it will queue itself for execution next -// frame. The reason for doing only one material every tick is to avoid -// flooding source control with too many requests and stalling the editor -void CMaterialManager::TickSourceControl() -{ - m_sourceControlFunctionQueued = false; - AZStd::string filePath; - bool moreRemaining = false; - - { - AZStd::lock_guard lock(m_sourceControlBufferMutex); - - if (m_sourceControlBuffer.size() < 1) - { - return; - } - - filePath = m_sourceControlBuffer.back(); - m_sourceControlBuffer.pop_back(); - moreRemaining = !m_sourceControlBuffer.empty(); - } - - // Process it - DccMaterialSourceControlCheck(filePath); - - // If there are more paths to check - if (moreRemaining) - { - // Queue again - QueueSourceControlTick(); - } -} - -/////////////////////////////////////////////////////////////////////////// -// Launches new thread running the DccMaterialSaveThreadFunc() function -void CMaterialManager::StartDccMaterialSaveThread() -{ - AZStd::thread_desc threadDesc; - threadDesc.m_name = "Dcc Material Save Thread"; - - m_dccMaterialSaveThread = AZStd::thread( - [this]() - { - DccMaterialSaveThreadFunc(); - }, - &threadDesc); -} - -/////////////////////////////////////////////////////////////////////////// -// Will save all the .dccmtl file paths in the buffer to source .mtl -// Runs on a separate thread so as not to stall the main thread -void CMaterialManager::DccMaterialSaveThreadFunc() -{ - while (true) - { - m_dccMaterialSaveSemaphore.acquire(); - - // Exit condition, set to true in destructor - if (m_joinThreads) - { - return; - } - - AZStd::vector dccMaterialPaths; - - // Lock the buffer and copy file paths locally - { - AZStd::lock_guard lock(m_dccMaterialSaveMutex); - dccMaterialPaths.reserve(m_dccMaterialSaveBuffer.size()); - for (AZStd::string& fileName : m_dccMaterialSaveBuffer) - { - dccMaterialPaths.push_back(fileName); - } - m_dccMaterialSaveBuffer.clear(); - } - - // Save all the buffered .dccmtl files - for (AZStd::string& fileName : dccMaterialPaths) - { - SaveDccMaterial(fileName); - } - - // Clear local strings - dccMaterialPaths.clear(); - } -} - -/////////////////////////////////////////////////////////////////////////// -// Async source control request. If successful, the callback will add the -// file name to the buffer for processing by the Dcc Material Save Thread -void CMaterialManager::DccMaterialSourceControlCheck(const AZStd::string& relativeDccMaterialPath) -{ - AZStd::string fullSourcePath = DccMaterialToSourcePath(relativeDccMaterialPath); - - if (!DccMaterialRequiresSave(relativeDccMaterialPath, fullSourcePath)) - { - // Source .mtl update not required, early out - return; - } - - // Create callback for source control operation (see SCCommandBus::Broadcast below) - AzToolsFramework::SourceControlResponseCallback callback = - [this, relativeDccMaterialPath, fullSourcePath](bool success, const AzToolsFramework::SourceControlFileInfo& info) - { - if (success || !info.IsReadOnly()) - { - // File needs saving, add it to the buffer for processing by the dcc material thread - - // Lock access to the buffer - AZStd::lock_guard lock(m_dccMaterialSaveMutex); - - // Add file path - m_dccMaterialSaveBuffer.push_back(relativeDccMaterialPath); - - // Notify thread there's work to do - m_dccMaterialSaveSemaphore.release(); - } - else - { - QString errorMessage = QObject::tr("Could not check out read-only file %1 in source control. Either check your source control configuration or disable source control.").arg(QString::fromUtf8(fullSourcePath.c_str())); - - // Alter error message slightly if source control is disabled - bool isSourceControlActive = false; - AzToolsFramework::SourceControlConnectionRequestBus::BroadcastResult(isSourceControlActive, &AzToolsFramework::SourceControlConnectionRequestBus::Events::IsActive); - - if (!isSourceControlActive) - { - errorMessage = QObject::tr("Could not check out read-only file %1 because source control is disabled. Either enable source control or check out the file manually to make it writable.").arg(QString::fromUtf8(fullSourcePath.c_str())); - } - - // Pop open an error message box if this is the first error we encounter - if (!m_bSourceControlErrorReported) - { - // Report warning in message box - QString errorTitle = QStringLiteral("Dcc Material Error"); - QMessageBox::warning(QApplication::activeWindow(), errorTitle, errorMessage, QMessageBox::Cancel); - - // Only report source control error box to the user once, - // no need to spam them for every material - m_bSourceControlErrorReported = true; - } - - AZ_Error("Rendering", false, errorMessage.toUtf8().data()); - } - }; - - // Request edit from source control (happens asynchronously) - using SCCommandBus = AzToolsFramework::SourceControlCommandBus; - SCCommandBus::Broadcast(&SCCommandBus::Events::RequestEdit, fullSourcePath.c_str(), true, callback); -} - -/////////////////////////////////////////////////////////////////////////// -// Handles when .dccmtl is created -void CMaterialManager::EntryAdded(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* assetEntry) -{ - if (assetEntry->GetEntryType() != AzToolsFramework::AssetBrowser::AssetBrowserEntry::AssetEntryType::Product) - { - // Ignore non-product entries - return; - } - const AzToolsFramework::AssetBrowser::ProductAssetBrowserEntry* productAssetEntry = azrtti_cast(assetEntry); - if (productAssetEntry && productAssetEntry->GetAssetType() != m_dccMaterialAssetType) - { - // Ignore types that aren't .dccmtl - return; - } - - AddDccMaterialPath(productAssetEntry->GetRelativePath()); -} - -/////////////////////////////////////////////////////////////////////////// -// Handles when .dccmtl is edited -void CMaterialManager::OnCatalogAssetChanged(const AZ::Data::AssetId& assetId) -{ - AZ::Data::AssetInfo assetInfo; - EBUS_EVENT_RESULT(assetInfo, AZ::Data::AssetCatalogRequestBus, GetAssetInfoById, assetId); - - if (assetInfo.m_assetType != m_dccMaterialAssetType) - { - // Ignore types that aren't .dccmtl - return; - } - - AddDccMaterialPath(assetInfo.m_relativePath); -} - -/////////////////////////////////////////////////////////////////////////// -void CMaterialManager::AddDccMaterialPath(const AZStd::string relativeDccMaterialPath) -{ - if (relativeDccMaterialPath.empty()) - { - return; - } - - // Lock access to the buffer - AZStd::lock_guard lock(m_sourceControlBufferMutex); - - // Add file path - m_sourceControlBuffer.push_back(relativeDccMaterialPath); - - if (m_bEditorUiReady) - { - QueueSourceControlTick(); - } -} - -/////////////////////////////////////////////////////////////////////////// -// Given the path of a .dccmtl in cache, save it as a source .mtl -void CMaterialManager::SaveDccMaterial(const AZStd::string& relativeDccMaterialPath) -{ - // __________________________________________________ - // Load .dccmtl - - XmlNodeRef dccNode = GetISystem()->LoadXmlFromFile(relativeDccMaterialPath.c_str()); - - if (!dccNode) - { - AZ_Error("MaterialManager", false, "CMaterialManager::SaveDccMaterial: Failed to load XML node from .dccmtl file: %s", relativeDccMaterialPath.c_str()); - return; - } - - // __________________________________________________ - // Save as source .mtl file - - AZStd::string fullSourcePath = DccMaterialToSourcePath(relativeDccMaterialPath); - bool saveSuccessful = dccNode->saveToFile(fullSourcePath.c_str()); - - if (!saveSuccessful) - { - AZ_Error("MaterialManager", false, "CMaterialManager::SaveDccMaterial: Failed to save source .mtl from .dccmtl file: %s", relativeDccMaterialPath.c_str()); - } -} - -/////////////////////////////////////////////////////////////////////////// -// Compares the hash values from .dccmtl and source .mtl to determine if -// .dccmtl has changed and needs to be saved. -bool CMaterialManager::DccMaterialRequiresSave(const AZStd::string& relativeDccMaterialPath, const AZStd::string& fullSourcePath) -{ - // __________________________________________________ - // Get Source Hash - - AZ::u32 sourceHash = 0; - - // Check if material is already loaded - QString unifiedName = UnifyMaterialName(QString(relativeDccMaterialPath.c_str())); - CMaterial* sourceMaterial = (CMaterial*)FindItemByName(unifiedName); - - if (sourceMaterial && !sourceMaterial->IsDummy()) - { - sourceHash = sourceMaterial->GetDccMaterialHash(); - } - else - { - XmlNodeRef sourceNode = GetISystem()->LoadXmlFromFile(fullSourcePath.c_str()); - if (sourceNode) - { - sourceNode->getAttr("DccMaterialHash", sourceHash); - } - else - { - // Couldn't find source node or material, so we need to save the dcc material as a source material - // No need to check the dcc material hash, just return true - return true; - } - } - - // __________________________________________________ - // Get DCC material Hash - - AZ::u32 dccHash = 0; - XmlNodeRef dccNode = GetISystem()->LoadXmlFromFile(relativeDccMaterialPath.c_str()); - - if (!dccNode) - { - AZ_Error("MaterialManager", false, "CMaterialManager::DccMaterialRequiresSave: Failed to load XML node from .dccmtl file: %s", relativeDccMaterialPath.c_str()); - return false; - } - - dccNode->getAttr("DccMaterialHash", dccHash); - - // __________________________________________________ - // Compare hash values - - // Only update if .dccmtl hash is different from the source hash - return (dccHash != sourceHash); -} - diff --git a/Code/Sandbox/Editor/Material/MaterialManager.h b/Code/Sandbox/Editor/Material/MaterialManager.h deleted file mode 100644 index a9dcabfa40..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialManager.h +++ /dev/null @@ -1,300 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_MATERIAL_MATERIALMANAGER_H -#define CRYINCLUDE_EDITOR_MATERIAL_MATERIALMANAGER_H -#pragma once - -#include "BaseLibraryManager.h" -#include "Material.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -class CMaterial; -class CMaterialLibrary; -class CMaterialHighlighter; - -namespace AZ -{ - struct Uuid; -} - -namespace AzToolsFramework -{ - namespace AssetBrowser - { - struct SourceFileOpenerDetails; - typedef AZStd::vector SourceFileOpenerList; - } -} - -enum EHighlightMode -{ - eHighlight_Pick = BIT(0), - eHighlight_Breakable = BIT(1), - eHighlight_NoSurfaceType = BIT(2), - eHighlight_All = 0xFFFFFFFF -}; - -AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING -AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING -/** Manages all entity prototypes and material libraries. -*/ -class CRYEDIT_API CMaterialManager - : public IEditorMaterialManager - , public CBaseLibraryManager - , public IMaterialManagerListener - , protected AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler - , public AzToolsFramework::AssetBrowser::AssetBrowserModelNotificationBus::Handler - , public AzFramework::AssetCatalogEventBus::Handler - , public AzToolsFramework::EditorEvents::Bus::Handler -{ -AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING -AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING -public: - - //! Notification callback. - typedef AZStd::function NotifyCallback; - - CMaterialManager(CRegistrationContext& regCtx); - ~CMaterialManager(); - - void Set3DEngine(); - - // Clear all prototypes and material libraries. - void ClearAll(); - - ////////////////////////////////////////////////////////////////////////// - // Materials. - ////////////////////////////////////////////////////////////////////////// - - // Loads material. - CMaterial* LoadMaterial(const QString& sMaterialName, bool bMakeIfNotFound = true); - XmlNodeRef LoadXmlNode(const QString &fullSourcePath, const QString &relativeFilePath); - //! Loads a material, avoiding a call to CMaterialManager::MaterialToFilename if the full path is already known - CMaterial* LoadMaterialWithFullSourcePath(const QString& relativeFilePath, const QString& fullSourcePath, bool makeIfNotFound = true); - virtual CMaterial* LoadMaterial(const char* sMaterialName, bool bMakeIfNotFound = true); - virtual void OnRequestMaterial(_smart_ptr pMaterial); - // Creates a new material from a xml node. - CMaterial* CreateMaterial(const QString& sMaterialName, const XmlNodeRef& node = XmlNodeRef(), int nMtlFlags = 0, unsigned long nLoadingFlags = 0); - virtual CMaterial* CreateMaterial(const char* sMaterialName, const XmlNodeRef& node = XmlNodeRef(), int nMtlFlags = 0, unsigned long nLoadingFlags = 0); - - // Duplicate material and do nothing more. - CMaterial* DuplicateMaterial(const char* newName, CMaterial* pOriginal); - - // Delete specified material, erases material file, and unassigns from all objects. - virtual void DeleteMaterial(CMaterial* pMtl); - virtual void RemoveMaterialFromDisk(const char* fileName); - - - //! Export property manager to game. - void Export(XmlNodeRef& node); - int ExportLib(CMaterialLibrary* pLib, XmlNodeRef& libNode); - - virtual void SetSelectedItem(IDataBaseItem* pItem); - void SetCurrentMaterial(CMaterial* pMtl); - //! Get currently active material. - CMaterial* GetCurrentMaterial() const; - - void SetCurrentFolder(const QString& folder); - - // This material will be highlighted - void SetHighlightedMaterial(CMaterial* pMtl); - void GetHighlightColor(ColorF* color, float* intensity, int flags); - void HighlightedMaterialChanged(CMaterial* pMtl); - // highlightMask is a combination of EHighlightMode flags - void SetHighlightMask(int highlightMask); - int GetHighlightMask() const{ return m_highlightMask; } - void SetMarkedMaterials(const std::vector<_smart_ptr >& markedMaterials); - void OnLoadShader(CMaterial* pMaterial); - - //! Serialize property manager. - virtual void Serialize(XmlNodeRef& node, bool bLoading); - - virtual void SaveAllLibs(); - - ////////////////////////////////////////////////////////////////////////// - // IMaterialManagerListener implementation - ////////////////////////////////////////////////////////////////////////// - // Called when material manager tries to load a material. - virtual void OnCreateMaterial(_smart_ptr pMaterial); - virtual void OnDeleteMaterial(_smart_ptr pMaterial); - virtual bool IsCurrentMaterial(_smart_ptr pMaterial) const; - ////////////////////////////////////////////////////////////////////////// - - // Convert filename of material file into the name of the material. - QString FilenameToMaterial(const QString& filename); - - // Convert name of the material to the filename. - QString MaterialToFilename(const QString& sMaterialName); - - //! Get the full file path of the source material - const AZ::Data::AssetType& GetMaterialAssetType(); - - ////////////////////////////////////////////////////////////////////////// - // Convert 3DEngine IMaterial to Editor's CMaterial pointer. - CMaterial* FromIMaterial(_smart_ptr pMaterial); - - // Open File selection dialog to create a new material. - CMaterial* SelectNewMaterial(int nMtlFlags, const char* sStartPath = NULL); - - // Synchronize material between 3dsMax and editor. - void SyncMaterialEditor(); - - ////////////////////////////////////////////////////////////////////////// - void GotoMaterial(CMaterial* pMaterial); - void GotoMaterial(_smart_ptr pMaterial); - - // Gather resources from the game material. - static void GatherResources(_smart_ptr pMaterial, CUsedResources& resources); - - void Command_Create(); - void Command_CreateMulti(); - void Command_ConvertToMulti(); - void Command_Duplicate(); - void Command_Merge(); - void Command_Delete(); - void Command_AssignToSelection(); - void Command_ResetSelection(); - void Command_SelectAssignedObjects(); - void Command_SelectFromObject(); - -protected: - ////////////////////////////////////////////////////////////////////////////////////////////////////// - // protected AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler - void AddSourceFileOpeners(const char* fullSourceFileName, const AZ::Uuid& sourceUUID, AzToolsFramework::AssetBrowser::SourceFileOpenerList& openers) override; - ////////////////////////////////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////////////////////////////////// - // public AzToolsFramework::AssetBrowser::AssetBrowserModelNotificationsBus::Handler - void EntryAdded(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry); - ////////////////////////////////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////////////////////////////////// - // AssetCatalogEventBus Functions - void OnCatalogAssetChanged(const AZ::Data::AssetId& assetId) override; - ////////////////////////////////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////////////////////////////////// - // EditorEventsBus Functions - bool SkipEditorStartupUI() override; - ////////////////////////////////////////////////////////////////////////////////////////////////////// - - void SaveDccMaterial(const AZStd::string& relativeDccMaterialPath); - bool DccMaterialRequiresSave(const AZStd::string& relativeDccMaterialPath, const AZStd::string& fullSourcePath); - void DccMaterialSourceControlCheck(const AZStd::string& relativeDccMaterialPath); - void AddDccMaterialPath(const AZStd::string relativeDccMaterialPath); - void TickSourceControl(); - void QueueSourceControlTick(); - - // Duplicate the source material and set it as a submaterial of the target material at subMaterialIndex. Returns true if successful. - bool DuplicateAsSubMaterialAtIndex(CMaterial* pSourceMaterial, CMaterial* pTargetMaterial, int subMaterialIndex); - // Generates a unique variant of the name of the source material to resolve name collisions with the names of the submaterials in the target material. - void GenerateUniqueSubmaterialName(const CMaterial* pSourceMaterial, const CMaterial* pTargetMaterial, QString& uniqueSubmaterialName) const; - - // Open save as dialog for saving materials. - bool SelectSaveMaterial(QString& itemName, QString& fullPath, const char* defaultStartPath); - - void OnEditorNotifyEvent(EEditorNotifyEvent event); - - virtual CBaseLibraryItem* MakeNewItem(); - virtual CBaseLibrary* MakeNewLibrary(); - //! Root node where this library will be saved. - virtual QString GetRootNodeName(); - //! Path to libraries in this manager. - virtual QString GetLibsPath(); - virtual void ReportDuplicateItem(CBaseLibraryItem* pItem, CBaseLibraryItem* pOldItem); - - void RegisterCommands(CRegistrationContext& regCtx); - - void UpdateHighlightedMaterials(); - void AddForHighlighting(CMaterial* pMaterial); - void RemoveFromHighlighting(CMaterial* pMaterial, int mask); - int GetHighlightFlags(CMaterial* pMaterial) const; - - // For material syncing with 3dsMax. - void PickPreviewMaterial(); - void InitMatSender(); - - //! Reloads any registered materials that have been modified by the runtime. - void ReloadDirtyMaterials(); - -protected: - QString m_libsPath; - - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - // Currently selected (focused) material, in material browser. - _smart_ptr m_pCurrentMaterial; - // current selected folder - QString m_currentFolder; - // List of materials selected in material browser tree. - std::vector<_smart_ptr > m_markedMaterials; - // IMaterial is needed to not let 3Dengine release selected IMaterial - _smart_ptr m_pCurrentEngineMaterial; - - // Paths of .dccmtl that might require saving. They will be fed to - // DccMaterialSourceControlCheck() and if saving is required, they - // will be added to m_dccMaterialSaveBuffer - AZStd::vector m_sourceControlBuffer; - AZStd::mutex m_sourceControlBufferMutex; - AZStd::atomic_bool m_sourceControlFunctionQueued; - - // Paths of .dccmtl that require saving. These paths have - // gone through DccMaterialSourceControlCheck() and will - // be saved by the dcc material save thread - AZStd::vector m_dccMaterialSaveBuffer; - AZStd::mutex m_dccMaterialSaveMutex; - - // Material highlighting - _smart_ptr m_pHighlightMaterial; - CMaterialHighlighter* m_pHighlighter; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - int m_highlightMask; - - bool m_bHighlightingMaterial; - - // Only begin processing .dccmtl filepaths once editor is ready - // and we can display appropriate error messages - bool m_bEditorUiReady; - - // Only report source control error to the user once, - // no need to spam them for every material - bool m_bSourceControlErrorReported; - - class CMaterialSender* m_MatSender; - -private: - CMaterial* LoadMaterialInternal(const QString &materialNameClear, const QString &fullSourcePath, const QString &relativeFilePath, bool bMakeIfNotFound); - - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - AZ::Data::AssetType m_materialAssetType; - AZ::Data::AssetType m_dccMaterialAssetType; - - void StartDccMaterialSaveThread(); - void DccMaterialSaveThreadFunc(); - AZStd::thread m_dccMaterialSaveThread; - AZStd::atomic_bool m_joinThreads; - AZStd::binary_semaphore m_dccMaterialSaveSemaphore; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING -}; - -#endif // CRYINCLUDE_EDITOR_MATERIAL_MATERIALMANAGER_H diff --git a/Code/Sandbox/Editor/Material/MaterialPreviewModelView.cpp b/Code/Sandbox/Editor/Material/MaterialPreviewModelView.cpp deleted file mode 100644 index 3e1bc37c6a..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialPreviewModelView.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include "EditorDefs.h" - -#include "MaterialPreviewModelView.h" - - - -MaterialPreviewModelView::MaterialPreviewModelView(QWidget* parent, bool enableIdleUpdate) - : CPreviewModelView(parent) - , m_enableIdleUpdate(enableIdleUpdate) -{} - -MaterialPreviewModelView::~MaterialPreviewModelView() -{} - -void MaterialPreviewModelView::SetCameraLookAt(float fRadiusScale, const Vec3& fromDir) -{ - IStatObj* target = GetStaticModel(); - if (target) - { - Vec3 dir = fromDir.GetNormalized(); - - // Calculate the camera matrix - Matrix34 tm = Matrix33::CreateRotationVDir(dir, 0); - Vec3 translation = target->GetAABB().GetCenter() - dir * target->GetAABB().GetRadius() * fRadiusScale; - tm.SetTranslation(translation); - - // Convert it to a quaternion and move the viewport's camera - QuatT quat(tm); - CameraMoved(quat, true); - } -} - -void MaterialPreviewModelView::SetMaterial(_smart_ptr material) -{ - IStatObj* staticModel = GetStaticModel(); - if (staticModel) - { - staticModel->SetMaterial(material); - } -} - -void MaterialPreviewModelView::resizeEvent(QResizeEvent* event) -{ - if (m_enableIdleUpdate) - { - CPreviewModelView::resizeEvent(event); - } -} - -void MaterialPreviewModelView::OnEditorNotifyEvent(EEditorNotifyEvent event) -{ - switch (event) - { - case eNotify_OnIdleUpdate: - { - if (m_enableIdleUpdate) - { - Update(); - } - break; - } - default: - break; - } -} diff --git a/Code/Sandbox/Editor/Material/MaterialPreviewModelView.h b/Code/Sandbox/Editor/Material/MaterialPreviewModelView.h deleted file mode 100644 index 0df7c1767f..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialPreviewModelView.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once - -#include "PreviewModelView.h" - -class MaterialPreviewModelView - : public CPreviewModelView -{ -public: - // set enableIdleUpdate to false if you don't want the view to update itself during - // application idle notification (and resize events). That makes sense when this view - // is only used to render into memory bitmaps. Note that the view has to been visible - // for that, but can be somewhere of-screen. - MaterialPreviewModelView(QWidget* parent, bool enableIdleUpdate = true); - virtual ~MaterialPreviewModelView(); - void SetCameraLookAt(float fRadiusScale, const Vec3& fromDir); - void SetMaterial(_smart_ptr material); - void OnEditorNotifyEvent(EEditorNotifyEvent event) override; - -protected: - void resizeEvent(QResizeEvent* event) override; - -private: - bool m_enableIdleUpdate; -}; diff --git a/Code/Sandbox/Editor/Material/MaterialPythonFuncs.cpp b/Code/Sandbox/Editor/Material/MaterialPythonFuncs.cpp deleted file mode 100644 index 5de75a7c39..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialPythonFuncs.cpp +++ /dev/null @@ -1,2208 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Material support for Python - -#include "EditorDefs.h" - -#include "MaterialPythonFuncs.h" - -// Editor -#include "MaterialManager.h" -#include "ShaderEnum.h" - - -namespace -{ - void PyMaterialCreate() - { - GetIEditor()->GetMaterialManager()->Command_Create(); - } - - void PyMaterialCreateMulti() - { - GetIEditor()->GetMaterialManager()->Command_CreateMulti(); - } - - void PyMaterialConvertToMulti() - { - GetIEditor()->GetMaterialManager()->Command_ConvertToMulti(); - } - - void PyMaterialDuplicateCurrent() - { - GetIEditor()->GetMaterialManager()->Command_Duplicate(); - } - - void PyMaterialMergeSelection() - { - GetIEditor()->GetMaterialManager()->Command_Merge(); - } - - void PyMaterialDeleteCurrent() - { - GetIEditor()->GetMaterialManager()->Command_Delete(); - } - - void PyMaterialAssignCurrentToSelection() - { - CUndo undo("Assign Material To Selection"); - GetIEditor()->GetMaterialManager()->Command_AssignToSelection(); - } - - void PyMaterialResetSelection() - { - GetIEditor()->GetMaterialManager()->Command_ResetSelection(); - } - - void PyMaterialSelectObjectsWithCurrent() - { - CUndo undo("Select Objects With Current Material"); - GetIEditor()->GetMaterialManager()->Command_SelectAssignedObjects(); - } - - void PyMaterialSetCurrentFromObject() - { - GetIEditor()->GetMaterialManager()->Command_SelectFromObject(); - } - - AZStd::vector PyGetSubMaterial(const char* pMaterialPath) - { - QString materialPath = pMaterialPath; - CMaterial* pMaterial = GetIEditor()->GetMaterialManager()->LoadMaterial(pMaterialPath, false); - if (!pMaterial) - { - throw std::runtime_error("Invalid multi material."); - } - - AZStd::vector result; - for (int i = 0; i < pMaterial->GetSubMaterialCount(); i++) - { - if (pMaterial->GetSubMaterial(i)) - { - result.push_back((materialPath + "\\" + pMaterial->GetSubMaterial(i)->GetName()).toUtf8().data()); - } - } - return result; - } - - CMaterial* TryLoadingMaterial(const char* pPathAndMaterialName) - { - QString varMaterialPath = pPathAndMaterialName; - std::deque splittedMaterialPath; - for (auto token : varMaterialPath.split(QRegularExpression(R"([\\/])"), Qt::SkipEmptyParts)) - { - splittedMaterialPath.push_back(token); - } - - CMaterial* pMaterial = GetIEditor()->GetMaterialManager()->LoadMaterial(varMaterialPath, false); - if (!pMaterial) - { - QString subMaterialName = splittedMaterialPath.back(); - bool isSubMaterialExist(false); - - varMaterialPath.remove((varMaterialPath.length() - subMaterialName.length() - 1), varMaterialPath.length()); - QString test = varMaterialPath; - pMaterial = GetIEditor()->GetMaterialManager()->LoadMaterial(varMaterialPath, false); - - if (!pMaterial) - { - throw std::runtime_error("Invalid multi material."); - } - - for (int i = 0; i < pMaterial->GetSubMaterialCount(); i++) - { - if (pMaterial->GetSubMaterial(i)->GetName() == subMaterialName) - { - pMaterial = pMaterial->GetSubMaterial(i); - isSubMaterialExist = true; - } - } - - if (!pMaterial || !isSubMaterialExist) - { - throw std::runtime_error((QString("\"") + subMaterialName + "\" is an invalid sub material.").toUtf8().data()); - } - } - GetIEditor()->GetMaterialManager()->SetCurrentMaterial(pMaterial); - return pMaterial; - } - - std::deque PreparePropertyPath(const char* pPathAndPropertyName) - { - QString varPathProperty = pPathAndPropertyName; - std::deque splittedPropertyPath; - for (auto token : varPathProperty.split(QRegularExpression(R"([\\/])"), Qt::SkipEmptyParts)) - { - splittedPropertyPath.push_back(token); - } - - return splittedPropertyPath; - } - - ////////////////////////////////////////////////////////////////////////// - // Converter: Enum -> CString (human readable) - ////////////////////////////////////////////////////////////////////////// - - QString TryConvertingSEFResTextureToCString(SEfResTexture* pResTexture) - { - if (pResTexture) - { - return pResTexture->m_Name.c_str(); - } - return ""; - } - - QString TryConvertingETEX_TypeToCString(const uint8& texTypeName) - { - switch (texTypeName) - { - case eTT_2D: - return "2D"; - case eTT_Cube: - return "Cube-Map"; - case eTT_NearestCube: - return "Nearest Cube-Map probe for alpha blended"; - case eTT_Auto2D: - return "Auto 2D-Map"; - case eTT_Dyn2D: - return "Dynamic 2D-Map"; - case eTT_User: - return "From User Params"; - default: - throw std::runtime_error("Invalid tex type."); - } - } - - QString TryConvertingTexFilterToCString(const int& iFilterName) - { - switch (iFilterName) - { - case FILTER_NONE: - return "Default"; - case FILTER_POINT: - return "Point"; - case FILTER_LINEAR: - return "Linear"; - case FILTER_BILINEAR: - return "Bilinear"; - case FILTER_TRILINEAR: - return "Trilinear"; - case FILTER_ANISO2X: - return "Anisotropic 2x"; - case FILTER_ANISO4X: - return "Anisotropic 4x"; - case FILTER_ANISO8X: - return "Anisotropic 8x"; - case FILTER_ANISO16X: - return "Anisotropic 16x"; - default: - throw std::runtime_error("Invalid tex filter."); - } - } - - QString TryConvertingETexGenTypeToCString(const uint8& texGenType) - { - switch (texGenType) - { - case ETG_Stream: - return "Stream"; - case ETG_World: - return "World"; - case ETG_Camera: - return "Camera"; - default: - throw std::runtime_error("Invalid tex gen type."); - } - } - - QString TryConvertingETexModRotateTypeToCString(const uint8& rotateType) - { - switch (rotateType) - { - case ETMR_NoChange: - return "No Change"; - case ETMR_Fixed: - return "Fixed Rotation"; - case ETMR_Constant: - return "Constant Rotation"; - case ETMR_Oscillated: - return "Oscillated Rotation"; - default: - throw std::runtime_error("Invalid rotate type."); - } - } - - QString TryConvertingETexModMoveTypeToCString(const uint8& oscillatorType) - { - switch (oscillatorType) - { - case ETMM_NoChange: - return "No Change"; - case ETMM_Fixed: - return "Fixed Moving"; - case ETMM_Constant: - return "Constant Moving"; - case ETMM_Jitter: - return "Jitter Moving"; - case ETMM_Pan: - return "Pan Moving"; - case ETMM_Stretch: - return "Stretch Moving"; - case ETMM_StretchRepeat: - return "Stretch-Repeat Moving"; - default: - throw std::runtime_error("Invalid oscillator type."); - } - } - - QString TryConvertingEDeformTypeToCString(const EDeformType& deformType) - { - switch (deformType) - { - case eDT_Unknown: - return "None"; - case eDT_SinWave: - return "Sin Wave"; - case eDT_SinWaveUsingVtxColor: - return "Sin Wave using vertex color"; - case eDT_Bulge: - return "Bulge"; - case eDT_Squeeze: - return "Squeeze"; - case eDT_Perlin2D: - return "Perlin 2D"; - case eDT_Perlin3D: - return "Perlin 3D"; - case eDT_FromCenter: - return "From Center"; - case eDT_Bending: - return "Bending"; - case eDT_ProcFlare: - return "Proc. Flare"; - case eDT_AutoSprite: - return "Auto sprite"; - case eDT_Beam: - return "Beam"; - case eDT_FixedOffset: - return "FixedOffset"; - default: - throw std::runtime_error("Invalid deform type."); - } - } - - QString TryConvertingEWaveFormToCString(const EWaveForm& waveForm) - { - switch (waveForm) - { - case eWF_None: - return "None"; - case eWF_Sin: - return "Sin"; - case eWF_HalfSin: - return "Half Sin"; - case eWF_Square: - return "Square"; - case eWF_Triangle: - return "Triangle"; - case eWF_SawTooth: - return "Saw Tooth"; - case eWF_InvSawTooth: - return "Inverse Saw Tooth"; - case eWF_Hill: - return "Hill"; - case eWF_InvHill: - return "Inverse Hill"; - default: - throw std::runtime_error("Invalid wave form."); - } - } - - ////////////////////////////////////////////////////////////////////////// - // Converter: CString -> Enum - ////////////////////////////////////////////////////////////////////////// - - template - // [Shader System TO DO] remove once dynamic slots assingment is in place - EEfResTextures TryConvertingCStringToEEfResTextures(const STRING& resTextureName) - { - if (resTextureName == "Diffuse") - { - return EFTT_DIFFUSE; - } - else if (resTextureName == "Specular") - { - return EFTT_SPECULAR; - } - else if (resTextureName == "Bumpmap") - { - return EFTT_NORMALS; - } - else if (resTextureName == "Heightmap") - { - return EFTT_HEIGHT; - } - else if (resTextureName == "Environment") - { - return EFTT_ENV; - } - else if (resTextureName == "Detail") - { - return EFTT_DETAIL_OVERLAY; - } - else if (resTextureName == "Opacity") - { - return EFTT_OPACITY; - } - else if (resTextureName == "Decal") - { - return EFTT_DECAL_OVERLAY; - } - else if (resTextureName == "SubSurface") - { - return EFTT_SUBSURFACE; - } - else if (resTextureName == "Custom") - { - return EFTT_CUSTOM; - } - else if (resTextureName == "[1] Custom") - { - return EFTT_DIFFUSE; - } - else if (resTextureName == "Emittance") - { - return EFTT_EMITTANCE; - } - else if (resTextureName == "Occlusion") - { - return EFTT_OCCLUSION; - } - else if (resTextureName == "Specular2") - { - return EFTT_SPECULAR_2; - } - throw std::runtime_error("Invalid texture name."); - } - - template - ETEX_Type TryConvertingCStringToETEX_Type(const STRING& texTypeName) - { - if (texTypeName == "2D") - { - return eTT_2D; - } - else if (texTypeName == "Cube-Map") - { - return eTT_Cube; - } - else if (texTypeName == "Nearest Cube-Map probe for alpha blended") - { - return eTT_NearestCube; - } - else if (texTypeName == "Auto 2D-Map") - { - return eTT_Auto2D; - } - else if (texTypeName == "Dynamic 2D-Map") - { - return eTT_Dyn2D; - } - else if (texTypeName == "From User Params") - { - return eTT_User; - } - throw std::runtime_error("Invalid tex type name."); - } - - template - signed char TryConvertingCStringToTexFilter(const STRING& filterName) - { - if (filterName == "Default") - { - return FILTER_NONE; - } - else if (filterName == "Point") - { - return FILTER_POINT; - } - else if (filterName == "Linear") - { - return FILTER_LINEAR; - } - else if (filterName == "Bilinear") - { - return FILTER_BILINEAR; - } - else if (filterName == "Trilinear") - { - return FILTER_TRILINEAR; - } - else if (filterName == "Anisotropic 2x") - { - return FILTER_ANISO2X; - } - else if (filterName == "Anisotropic 4x") - { - return FILTER_ANISO4X; - } - else if (filterName == "Anisotropic 8x") - { - return FILTER_ANISO8X; - } - else if (filterName == "Anisotropic 16x") - { - return FILTER_ANISO16X; - } - throw std::runtime_error("Invalid filter name."); - } - - template - ETexGenType TryConvertingCStringToETexGenType(const STRING& texGenType) - { - if (texGenType == "Stream") - { - return ETG_Stream; - } - else if (texGenType == "World") - { - return ETG_World; - } - else if (texGenType == "Camera") - { - return ETG_Camera; - } - throw std::runtime_error("Invalid tex gen type name."); - } - - template - ETexModRotateType TryConvertingCStringToETexModRotateType(const STRING& rotateType) - { - if (rotateType == "No Change") - { - return ETMR_NoChange; - } - else if (rotateType == "Fixed Rotation") - { - return ETMR_Fixed; - } - else if (rotateType == "Constant Rotation") - { - return ETMR_Constant; - } - else if (rotateType == "Oscillated Rotation") - { - return ETMR_Oscillated; - } - throw std::runtime_error("Invalid rotate type name."); - } - - template - ETexModMoveType TryConvertingCStringToETexModMoveType(const STRING& oscillatorType) - { - if (oscillatorType == "No Change") - { - return ETMM_NoChange; - } - else if (oscillatorType == "Fixed Moving") - { - return ETMM_Fixed; - } - else if (oscillatorType == "Constant Moving") - { - return ETMM_Constant; - } - else if (oscillatorType == "Jitter Moving") - { - return ETMM_Jitter; - } - else if (oscillatorType == "Pan Moving") - { - return ETMM_Pan; - } - else if (oscillatorType == "Stretch Moving") - { - return ETMM_Stretch; - } - else if (oscillatorType == "Stretch-Repeat Moving") - { - return ETMM_StretchRepeat; - } - throw std::runtime_error("Invalid oscillator type."); - } - - template - EDeformType TryConvertingCStringToEDeformType(const STRING& deformType) - { - if (deformType == "None") - { - return eDT_Unknown; - } - else if (deformType == "Sin Wave") - { - return eDT_SinWave; - } - else if (deformType == "Sin Wave using vertex color") - { - return eDT_SinWaveUsingVtxColor; - } - else if (deformType == "Bulge") - { - return eDT_Bulge; - } - else if (deformType == "Squeeze") - { - return eDT_Squeeze; - } - else if (deformType == "Perlin 2D") - { - return eDT_Perlin2D; - } - else if (deformType == "Perlin 3D") - { - return eDT_Perlin3D; - } - else if (deformType == "From Center") - { - return eDT_FromCenter; - } - else if (deformType == "Bending") - { - return eDT_Bending; - } - else if (deformType == "Proc. Flare") - { - return eDT_ProcFlare; - } - else if (deformType == "Auto sprite") - { - return eDT_AutoSprite; - } - else if (deformType == "Beam") - { - return eDT_Beam; - } - else if (deformType == "FixedOffset") - { - return eDT_FixedOffset; - } - throw std::runtime_error("Invalid deform type."); - } - - template - EWaveForm TryConvertingCStringToEWaveForm(const STRING& waveForm) - { - if (waveForm == "None") - { - return eWF_None; - } - else if (waveForm == "Sin") - { - return eWF_Sin; - } - else if (waveForm == "Half Sin") - { - return eWF_HalfSin; - } - else if (waveForm == "Square") - { - return eWF_Square; - } - else if (waveForm == "Triangle") - { - return eWF_Triangle; - } - else if (waveForm == "Saw Tooth") - { - return eWF_SawTooth; - } - else if (waveForm == "Inverse Saw Tooth") - { - return eWF_InvSawTooth; - } - else if (waveForm == "Hill") - { - return eWF_Hill; - } - else if (waveForm == "Inverse Hill") - { - return eWF_InvHill; - } - throw std::runtime_error("Invalid wave form."); - } - - ////////////////////////////////////////////////////////////////////////// - // Script parser - ////////////////////////////////////////////////////////////////////////// - - QString ParseUINameFromPublicParamsScript(const char* sUIScript) - { - string uiscript = sUIScript; - string element[3]; - int p1 = 0; - string itemToken = uiscript.Tokenize(";", p1); - while (!itemToken.empty()) - { - int nElements = 0; - int p2 = 0; - string token = itemToken.Tokenize(" \t\r\n=", p2); - while (!token.empty()) - { - element[nElements++] = token; - if (nElements == 2) - { - element[nElements] = itemToken.substr(p2); - element[nElements].Trim(" =\t\""); - break; - } - token = itemToken.Tokenize(" \t\r\n=", p2); - } - - if (_stricmp(element[1], "UIName") == 0) - { - return element[2].c_str(); - } - itemToken = uiscript.Tokenize(";", p1); - } - return ""; - } - - std::map ParseValidRangeFromPublicParamsScript(const char* sUIScript) - { - string uiscript = sUIScript; - std::map result; - bool isUIMinExist(false); - bool isUIMaxExist(false); - string element[3]; - int p1 = 0; - string itemToken = uiscript.Tokenize(";", p1); - while (!itemToken.empty()) - { - int nElements = 0; - int p2 = 0; - string token = itemToken.Tokenize(" \t\r\n=", p2); - while (!token.empty()) - { - element[nElements++] = token; - if (nElements == 2) - { - element[nElements] = itemToken.substr(p2); - element[nElements].Trim(" =\t\""); - break; - } - token = itemToken.Tokenize(" \t\r\n=", p2); - } - - if (_stricmp(element[1], "UIMin") == 0) - { - result["UIMin"] = atof(element[2]); - isUIMinExist = true; - } - if (_stricmp(element[1], "UIMax") == 0) - { - result["UIMax"] = atof(element[2]); - isUIMaxExist = true; - } - itemToken = uiscript.Tokenize(";", p1); - } - if (!isUIMinExist || !isUIMaxExist) - { - throw std::runtime_error("Invalid range for shader param."); - } - return result; - } - - ////////////////////////////////////////////////////////////////////////// - // Set Flags - ////////////////////////////////////////////////////////////////////////// - - void SetMaterialFlag(CMaterial* pMaterial, const EMaterialFlags& eFlag, const bool& bFlag) - { - if (pMaterial->GetFlags() & eFlag && bFlag == false) - { - pMaterial->SetFlags(pMaterial->GetFlags() - eFlag); - } - else if (!(pMaterial->GetFlags() & eFlag) && bFlag == true) - { - pMaterial->SetFlags(pMaterial->GetFlags() | eFlag); - } - } - - void SetPropagationFlag(CMaterial* pMaterial, const eMTL_PROPAGATION& eFlag, const bool& bFlag) - { - if (pMaterial->GetPropagationFlags() & eFlag && bFlag == false) - { - pMaterial->SetPropagationFlags(pMaterial->GetPropagationFlags() - eFlag); - } - else if (!(pMaterial->GetPropagationFlags() & eFlag) && bFlag == true) - { - pMaterial->SetPropagationFlags(pMaterial->GetPropagationFlags() | eFlag); - } - } - - ////////////////////////////////////////////////////////////////////////// - template - bool IsAnyValidRange(const AZStd::any& value, const T& low, const T& high, const QString& invalidTypeMessage, const QString& invalidValueMessage) - { - static_assert(AZStd::is_arithmetic::value, "This function only works with numbers."); - - if (!value.is()) - { - throw std::runtime_error(invalidTypeMessage.toUtf8().data()); - } - - T valueData; - AZStd::any_numeric_cast(&value, valueData); - if (valueData < low || valueData > high) - { - throw std::runtime_error(invalidValueMessage.toUtf8().data()); - } - return true; - } - - template <> - bool IsAnyValidRange(const AZStd::any& value, const AZ::Color& low, const AZ::Color& high, const QString& invalidTypeMessage, const QString& invalidValueMessage) - { - if (!value.is()) - { - throw std::runtime_error(invalidTypeMessage.toUtf8().data()); - } - - const AZ::Color* valueData = AZStd::any_cast(&value); - if (!valueData) - { - throw std::runtime_error(invalidValueMessage.toUtf8().data()); - } - - if (valueData->IsLessThan(low) || valueData->IsGreaterThan(high)) - { - throw std::runtime_error(invalidValueMessage.toUtf8().data()); - } - return true; - } - - bool ValidateProperty(CMaterial* pMaterial, const std::deque& splittedPropertyPathParam, const AZStd::any& value) - { - std::deque splittedPropertyPath = splittedPropertyPathParam; - std::deque splittedPropertyPathSubCategory = splittedPropertyPathParam; - QString categoryName = splittedPropertyPath.front(); - QString subCategoryName = ""; - QString subSubCategoryName = ""; - QString currentPath = ""; - QString propertyName = splittedPropertyPath.back(); - - QString errorMsgInvalidValue = QString("Invalid value for property \"") + propertyName + "\""; - QString errorMsgInvalidDataType = QString("Invalid data type for property \"") + propertyName + "\""; - QString errorMsgInvalidPropertyPath = QString("Invalid property path"); - - const int iMinColorValue = 0; - const int iMaxColorValue = 255; - - if (splittedPropertyPathSubCategory.size() == 3) - { - splittedPropertyPathSubCategory.pop_back(); - subCategoryName = splittedPropertyPathSubCategory.back(); - currentPath = QString("") + categoryName + "/" + subCategoryName; - - if ( - subCategoryName != "TexType" && - subCategoryName != "Filter" && - subCategoryName != "IsProjectedTexGen" && - subCategoryName != "TexGenType" && - subCategoryName != "Wave X" && - subCategoryName != "Wave Y" && - subCategoryName != "Wave Z" && - subCategoryName != "Wave W" && - subCategoryName != "Shader1" && - subCategoryName != "Shader2" && - subCategoryName != "Shader3" && - subCategoryName != "Tiling" && - subCategoryName != "Rotator" && - subCategoryName != "Oscillator" && - subCategoryName != "Diffuse" && - subCategoryName != "Specular" && - subCategoryName != "Bumpmap" && - subCategoryName != "Heightmap" && - subCategoryName != "Environment" && - subCategoryName != "Detail" && - subCategoryName != "Opacity" && - subCategoryName != "Decal" && - subCategoryName != "SubSurface" && - subCategoryName != "Custom" && - subCategoryName != "[1] Custom" - ) - { - throw std::runtime_error((errorMsgInvalidPropertyPath + " (" + currentPath + ")").toUtf8().data()); - } - } - else if (splittedPropertyPathSubCategory.size() == 4) - { - splittedPropertyPathSubCategory.pop_back(); - subCategoryName = splittedPropertyPathSubCategory.back(); - splittedPropertyPathSubCategory.pop_back(); - subSubCategoryName = splittedPropertyPathSubCategory.back(); - currentPath = categoryName + "/" + subSubCategoryName + "/" + subCategoryName; - - if ( - subSubCategoryName != "Diffuse" && - subSubCategoryName != "Specular" && - subSubCategoryName != "Bumpmap" && - subSubCategoryName != "Heightmap" && - subSubCategoryName != "Environment" && - subSubCategoryName != "Detail" && - subSubCategoryName != "Opacity" && - subSubCategoryName != "Decal" && - subSubCategoryName != "SubSurface" && - subSubCategoryName != "Custom" && - subSubCategoryName != "[1] Custom" - ) - { - throw std::runtime_error((errorMsgInvalidPropertyPath + " (" + currentPath + ")").toUtf8().data()); - } - else if (subCategoryName != "Tiling" && subCategoryName != "Rotator" && subCategoryName != "Oscillator") - { - throw std::runtime_error((errorMsgInvalidPropertyPath + " (" + currentPath + ")").toUtf8().data()); - } - } - else - { - currentPath = categoryName; - } - - if ( - categoryName == "Material Settings" || - categoryName == "Opacity Settings" || - categoryName == "Lighting Settings" || - categoryName == "Advanced" || - categoryName == "Texture Maps" || - categoryName == "Vertex Deformation" || - categoryName == "Layer Presets") - { - if (propertyName == "Opacity" || propertyName == "AlphaTest" || propertyName == "Glow Amount") - { - // int: 0 < x < 100 - if (!value.is()) - { - throw std::runtime_error(errorMsgInvalidDataType.toUtf8().data()); - } - - AZ::s64 valueData; - AZStd::any_numeric_cast(&value, valueData); - if (valueData < 0 || valueData > 100) - { - throw std::runtime_error(errorMsgInvalidValue.toUtf8().data()); - } - return true; - } - else if (propertyName == "Smoothness" || propertyName == "Glossiness") - { - // int: 0 < x < 255 - return IsAnyValidRange(value, 0, 255, errorMsgInvalidDataType, errorMsgInvalidValue); - } - else if (propertyName == "Specular Level") - { - // float: 0.0 < x < 4.0 - return IsAnyValidRange(value, 0.0, 4.0, errorMsgInvalidDataType, errorMsgInvalidValue); - } - else if ( - propertyName == "TileU" || - propertyName == "TileV" || - propertyName == "OffsetU" || - propertyName == "OffsetV" || - propertyName == "RotateU" || - propertyName == "RotateV" || - propertyName == "RotateW" || - propertyName == "Rate" || - propertyName == "Phase" || - propertyName == "Amplitude" || - propertyName == "CenterU" || - propertyName == "CenterV" || - propertyName == "RateU" || - propertyName == "RateV" || - propertyName == "PhaseU" || - propertyName == "PhaseV" || - propertyName == "AmplitudeU" || - propertyName == "AmplitudeV" || - propertyName == "Wave Length X" || - propertyName == "Wave Length Y" || - propertyName == "Wave Length Z" || - propertyName == "Wave Length W" || - propertyName == "Level" || - propertyName == "Amplitude" || - propertyName == "Phase" || - propertyName == "Frequency") - { - // float: 0.0 < x < 100.0 - return IsAnyValidRange(value, 0.0, 100.0, errorMsgInvalidDataType, errorMsgInvalidValue); - } - else if (propertyName == "Voxel Coverage") - { - // float: 0.0 < x < 1.0 - return IsAnyValidRange(value, 0.0, 1.0, errorMsgInvalidDataType, errorMsgInvalidValue); - } - else if (propertyName == "Emissive Intensity") - { - // float: 0.0 < x < 200.0 - return IsAnyValidRange(value, 0.0, 200.0, errorMsgInvalidDataType, errorMsgInvalidValue); - } - else if (propertyName == "Diffuse Color" || propertyName == "Specular Color" || propertyName == "Emissive Color") - { - // intVector(RGB): 0 < x < 255 - return IsAnyValidRange(value, AZ::Color::CreateZero(), AZ::Color::CreateOne(), errorMsgInvalidDataType, errorMsgInvalidValue); - } - else if ( - propertyName == "Link to Material" || - propertyName == "Surface Type" || - propertyName == "Diffuse" || - propertyName == "Specular" || - propertyName == "Bumpmap" || - propertyName == "Heightmap" || - propertyName == "Environment" || - propertyName == "Detail" || - propertyName == "Opacity" || - propertyName == "Decal" || - propertyName == "SubSurface" || - propertyName == "Custom" || - propertyName == "[1] Custom" || - propertyName == "TexType" || - propertyName == "Filter" || - propertyName == "TexGenType" || - propertyName == "Type" || - propertyName == "TypeU" || - propertyName == "TypeV") - { - // string - if (!value.is()) - { - throw std::runtime_error(errorMsgInvalidDataType.toUtf8().data()); - } - return true; - } - else if ( - propertyName == "Additive" || - propertyName == "Allow layer activation" || - propertyName == "2 Sided" || - propertyName == "No Shadow" || - propertyName == "Use Scattering" || - propertyName == "Hide After Breaking" || - propertyName == "Fog Volume Shading Quality High" || - propertyName == "Blend Terrain Color" || - propertyName == "Propagate Material Settings" || - propertyName == "Propagate Opacity Settings" || - propertyName == "Propagate Lighting Settings" || - propertyName == "Propagate Advanced Settings" || - propertyName == "Propagate Texture Maps" || - propertyName == "Propagate Shader Params" || - propertyName == "Propagate Shader Generation" || - propertyName == "Propagate Vertex Deformation" || - propertyName == "Propagate Layer Presets" || - propertyName == "IsProjectedTexGen" || - propertyName == "IsTileU" || - propertyName == "IsTileV" || - propertyName == "No Draw") - { - // bool - if (!value.is()) - { - throw std::runtime_error(errorMsgInvalidDataType.toUtf8().data()); - } - return true; - } - else if (propertyName == "Shader" || propertyName == "Shader1" || propertyName == "Shader2" || propertyName == "Shader3") - { - // string && valid shader - if (!value.is()) - { - throw std::runtime_error(errorMsgInvalidDataType.toUtf8().data()); - } - - CShaderEnum* pShaderEnum = GetIEditor()->GetShaderEnum(); - if (!pShaderEnum) - { - throw std::runtime_error("Shader enumerator corrupted."); - } - pShaderEnum->EnumShaders(); - for (int i = 0; i < pShaderEnum->GetShaderCount(); i++) - { - if (pShaderEnum->GetShader(i) == AZStd::any_cast(value).data()) - { - return true; - } - } - } - else if (propertyName == "Noise Scale") - { - // FloatVec: undefined < x < undefined - if (!value.is()) - { - throw std::runtime_error(errorMsgInvalidDataType.toUtf8().data()); - } - return true; - } - } - else if (categoryName == "Shader Params") - { - auto& shaderParams = pMaterial->GetShaderResources().m_ShaderParams; - for (int i = 0; i < shaderParams.size(); i++) - { - if (propertyName == ParseUINameFromPublicParamsScript(shaderParams[i].m_Script.c_str())) - { - if (shaderParams[i].m_Type == eType_FLOAT) - { - // float: valid range (from script) - float floatValue; - if (!AZStd::any_numeric_cast(&value, floatValue)) - { - throw std::runtime_error(errorMsgInvalidDataType.toUtf8().data()); - } - std::map range = ParseValidRangeFromPublicParamsScript(shaderParams[i].m_Script.c_str()); - if (floatValue < range["UIMin"] || floatValue > range["UIMax"]) - { - QString errorMsg; - errorMsg = QStringLiteral("Invalid value for shader param \"%1\" (min: %2, max: %3)").arg(propertyName).arg(range["UIMin"]).arg(range["UIMax"]); - throw std::runtime_error(errorMsg.toUtf8().data()); - } - return true; - } - else if (shaderParams[i].m_Type == eType_FCOLOR) - { - return IsAnyValidRange(value, AZ::Color::CreateZero(), AZ::Color::CreateOne(), errorMsgInvalidDataType, errorMsgInvalidValue); - } - } - } - } - else if (categoryName == "Shader Generation Params") - { - for (int i = 0; i < pMaterial->GetShaderGenParamsVars()->GetNumVariables(); i++) - { - if (propertyName == pMaterial->GetShaderGenParamsVars()->GetVariable(i)->GetHumanName()) - { - if (!value.is()) - { - throw std::runtime_error(errorMsgInvalidDataType.toUtf8().data()); - } - return true; - } - } - } - else - { - throw std::runtime_error((errorMsgInvalidPropertyPath + " (" + currentPath + ")").toUtf8().data()); - } - return false; - } - - ////////////////////////////////////////////////////////////////////////// - template - T PyFetchNumericType(const AZStd::any& value) - { - T numericValue; - AZStd::any_numeric_cast(&value, numericValue); - return numericValue; - } - - AZStd::any PyGetProperty(const char* pPathAndMaterialName, const char* pPathAndPropertyName) - { - CMaterial* pMaterial = TryLoadingMaterial(pPathAndMaterialName); - std::deque splittedPropertyPath = PreparePropertyPath(pPathAndPropertyName); - std::deque splittedPropertyPathCategory = splittedPropertyPath; - QString categoryName = splittedPropertyPath.front(); - QString subCategoryName = "None"; - QString subSubCategoryName = "None"; - QString propertyName = splittedPropertyPath.back(); - QString errorMsgInvalidPropertyPath = "Invalid property path."; - - if (splittedPropertyPathCategory.size() == 3) - { - splittedPropertyPathCategory.pop_back(); - subCategoryName = splittedPropertyPathCategory.back(); - } - else if (splittedPropertyPathCategory.size() == 4) - { - splittedPropertyPathCategory.pop_back(); - subCategoryName = splittedPropertyPathCategory.back(); - splittedPropertyPathCategory.pop_back(); - subSubCategoryName = splittedPropertyPathCategory.back(); - } - - // ########## Material Settings ########## - if (categoryName == "Material Settings") - { - if (propertyName == "Shader") - { - return AZStd::make_any(pMaterial->GetShaderName().toUtf8().data()); - } - else if (propertyName == "Surface Type") - { - QString stringValue = pMaterial->GetSurfaceTypeName(); - if (stringValue.startsWith("mat_")) - { - stringValue.remove(0, 4); - } - return AZStd::make_any(stringValue.toLatin1().data()); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid material setting.").toUtf8().data()); - } - } - // ########## Opacity Settings ########## - else if (categoryName == "Opacity Settings") - { - if (propertyName == "Opacity") - { - AZ::s64 intValue = aznumeric_cast(pMaterial->GetShaderResources().m_LMaterial.m_Opacity * 100.0f); - return AZStd::make_any(intValue); - } - else if (propertyName == "AlphaTest") - { - AZ::s64 intValue = aznumeric_cast(pMaterial->GetShaderResources().m_AlphaRef * 100.0f); - return AZStd::make_any(intValue); - } - else if (propertyName == "Additive") - { - return AZStd::make_any(pMaterial->GetFlags() & MTL_FLAG_ADDITIVE); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid opacity setting.").toUtf8().data()); - } - } - // ########## Lighting Settings ########## - else if (categoryName == "Lighting Settings") - { - if (propertyName == "Diffuse Color") - { - QColor col = ColorLinearToGamma(ColorF( - pMaterial->GetShaderResources().m_LMaterial.m_Diffuse.r, - pMaterial->GetShaderResources().m_LMaterial.m_Diffuse.g, - pMaterial->GetShaderResources().m_LMaterial.m_Diffuse.b)); - return AZStd::make_any(col.red(), col.green(), col.blue(), 1.0f); - } - else if (propertyName == "Specular Color") - { - QColor col = ColorLinearToGamma(ColorF( - pMaterial->GetShaderResources().m_LMaterial.m_Specular.r / pMaterial->GetShaderResources().m_LMaterial.m_Specular.a, - pMaterial->GetShaderResources().m_LMaterial.m_Specular.g / pMaterial->GetShaderResources().m_LMaterial.m_Specular.a, - pMaterial->GetShaderResources().m_LMaterial.m_Specular.b / pMaterial->GetShaderResources().m_LMaterial.m_Specular.a)); - return AZStd::make_any(col.red(), col.green(), col.blue(), 1.0f); - } - else if (propertyName == "Glossiness") - { - return AZStd::make_any(pMaterial->GetShaderResources().m_LMaterial.m_Smoothness); - } - else if (propertyName == "Specular Level") - { - return AZStd::make_any(pMaterial->GetShaderResources().m_LMaterial.m_Specular.a); - } - else if (propertyName == "Emissive Color") - { - QColor col = ColorLinearToGamma(ColorF( - pMaterial->GetShaderResources().m_LMaterial.m_Emittance.r, - pMaterial->GetShaderResources().m_LMaterial.m_Emittance.g, - pMaterial->GetShaderResources().m_LMaterial.m_Emittance.b)); - return AZStd::make_any(col.red(), col.green(), col.blue(), 1.0f); - } - else if (propertyName == "Emissive Intensity") - { - return AZStd::make_any(pMaterial->GetShaderResources().m_LMaterial.m_Emittance.a); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid lighting setting.").toUtf8().data()); - } - } - // ########## Advanced ########## - else if (categoryName == "Advanced") - { - if (propertyName == "Allow layer activation") - { - return AZStd::make_any(pMaterial->LayerActivationAllowed()); - } - else if (propertyName == "2 Sided") - { - return AZStd::make_any(pMaterial->GetFlags() & MTL_FLAG_2SIDED); - } - else if (propertyName == "No Shadow") - { - return AZStd::make_any(pMaterial->GetFlags() & MTL_FLAG_NOSHADOW); - } - else if (propertyName == "Use Scattering") - { - return AZStd::make_any(pMaterial->GetFlags() & MTL_FLAG_SCATTER); - } - else if (propertyName == "Hide After Breaking") - { - return AZStd::make_any(pMaterial->GetFlags() & MTL_FLAG_HIDEONBREAK); - } - else if (propertyName == "Fog Volume Shading Quality High") - { - return AZStd::make_any(pMaterial->GetFlags() & MTL_FLAG_FOG_VOLUME_SHADING_QUALITY_HIGH); - } - else if (propertyName == "Blend Terrain Color") - { - return AZStd::make_any(pMaterial->GetFlags() & MTL_FLAG_BLEND_TERRAIN); - } - else if (propertyName == "Voxel Coverage") - { - return AZStd::make_any(aznumeric_cast(pMaterial->GetShaderResources().m_VoxelCoverage) / 255.0f); - } - else if (propertyName == "Link to Material") - { - return AZStd::make_any(pMaterial->GetMatInfo()->GetMaterialLinkName()); - } - else if (propertyName == "Propagate Material Settings") - { - return AZStd::make_any(pMaterial->GetPropagationFlags() & MTL_PROPAGATE_MATERIAL_SETTINGS); - } - else if (propertyName == "Propagate Opacity Settings") - { - return AZStd::make_any(pMaterial->GetPropagationFlags() & MTL_PROPAGATE_OPACITY); - } - else if (propertyName == "Propagate Lighting Settings") - { - return AZStd::make_any(pMaterial->GetPropagationFlags() & MTL_PROPAGATE_LIGHTING); - } - else if (propertyName == "Propagate Advanced Settings") - { - return AZStd::make_any(pMaterial->GetPropagationFlags() & MTL_PROPAGATE_ADVANCED); - } - else if (propertyName == "Propagate Texture Maps") - { - return AZStd::make_any(pMaterial->GetPropagationFlags() & MTL_PROPAGATE_TEXTURES); - } - else if (propertyName == "Propagate Shader Params") - { - return AZStd::make_any(pMaterial->GetPropagationFlags() & MTL_PROPAGATE_SHADER_PARAMS); - } - else if (propertyName == "Propagate Shader Generation") - { - return AZStd::make_any(pMaterial->GetPropagationFlags() & MTL_PROPAGATE_SHADER_GEN); - } - else if (propertyName == "Propagate Vertex Deformation") - { - return AZStd::make_any(pMaterial->GetPropagationFlags() & MTL_PROPAGATE_VERTEX_DEF); - } - else if (propertyName == "Propagate Layer Presets") - { - return AZStd::make_any(pMaterial->GetPropagationFlags() & MTL_PROPAGATE_LAYER_PRESETS); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid advanced setting.").toUtf8().data()); - } - } - // ########## Texture Maps ########## - else if (categoryName == "Texture Maps") - { - SInputShaderResources& shaderResources = pMaterial->GetShaderResources(); - // ########## Texture Maps / [name] ########## - if (splittedPropertyPath.size() == 2) - { - uint16 nSlot = aznumeric_cast(TryConvertingCStringToEEfResTextures(propertyName)); - SEfResTexture* pTextureRes = shaderResources.GetTextureResource(nSlot); - if (!pTextureRes || pTextureRes->m_Name.empty()) - { - AZ_Warning("ShadersSystem", false, "PyGetProperty - Error: empty texture slot [%d] (or missing name) for material %s", - nSlot, pMaterial->GetName().toStdString().c_str()); - return AZStd::any(); - } - else - { - return AZStd::make_any(pTextureRes->m_Name); - } - } - // ########## Texture Maps / [TexType | Filter | IsProjectedTexGen | TexGenType ] ########## - else if (splittedPropertyPath.size() == 3) - { - SEfResTexture* pTextureRes = shaderResources.GetTextureResource(TryConvertingCStringToEEfResTextures(subCategoryName)); - if (pTextureRes) - { - if (propertyName == "TexType") - { - return AZStd::make_any(TryConvertingETEX_TypeToCString(pTextureRes->m_Sampler.m_eTexType).toLatin1().data()); - } - else if (propertyName == "Filter") - { - return AZStd::make_any(TryConvertingTexFilterToCString(pTextureRes->m_Filter).toLatin1().data()); - } - else if (propertyName == "IsProjectedTexGen") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_bTexGenProjected); - } - else if (propertyName == "TexGenType") - { - return AZStd::make_any(TryConvertingETexGenTypeToCString(pTextureRes->AddModificator()->m_eTGType).toLatin1().data()); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid property.").toUtf8().data()); - } - } - else - { - AZ_Warning("ShadersSystem", false, "PyGetProperty - Error: empty 'subCategoryName' texture slot [%d] for material %s", - aznumeric_cast(TryConvertingCStringToEEfResTextures(subCategoryName)), - pMaterial->GetName().toStdString().c_str()); - } - } - // ########## Texture Maps / [Tiling | Rotator | Oscillator] ########## - else if (splittedPropertyPath.size() == 4) - { - SEfResTexture* pTextureRes = shaderResources.GetTextureResource(TryConvertingCStringToEEfResTextures(subSubCategoryName)); - if (pTextureRes) - { - if (subCategoryName == "Tiling") - { - if (propertyName == "IsTileU") - { - return AZStd::make_any(pTextureRes->m_bUTile); - } - else if (propertyName == "IsTileV") - { - return AZStd::make_any(pTextureRes->m_bVTile); - } - else if (propertyName == "TileU") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_Tiling[0]); - } - else if (propertyName == "TileV") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_Tiling[1]); - } - else if (propertyName == "OffsetU") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_Offs[0]); - } - else if (propertyName == "OffsetV") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_Offs[1]); - } - else if (propertyName == "RotateU") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_Rot[0]); - } - else if (propertyName == "RotateV") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_Rot[1]); - } - else if (propertyName == "RotateW") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_Rot[2]); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid property.").toUtf8().data()); - } - } - else if (subCategoryName == "Rotator") - { - if (propertyName == "Type") - { - return AZStd::make_any(TryConvertingETexModRotateTypeToCString(pTextureRes->AddModificator()->m_eRotType).toLatin1().data()); - } - else if (propertyName == "Rate") - { - return AZStd::make_any(Word2Degr(pTextureRes->AddModificator()->m_RotOscRate[2])); - } - else if (propertyName == "Phase") - { - return AZStd::make_any(Word2Degr(pTextureRes->AddModificator()->m_RotOscPhase[2])); - } - else if (propertyName == "Amplitude") - { - return AZStd::make_any(Word2Degr(pTextureRes->AddModificator()->m_RotOscAmplitude[2])); - } - else if (propertyName == "CenterU") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_RotOscCenter[0]); - } - else if (propertyName == "CenterV") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_RotOscCenter[1]); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid property.").toUtf8().data()); - } - } - else if (subCategoryName == "Oscillator") - { - if (propertyName == "TypeU") - { - return AZStd::make_any(TryConvertingETexModMoveTypeToCString(pTextureRes->AddModificator()->m_eMoveType[0]).toLatin1().data()); - } - else if (propertyName == "TypeV") - { - return AZStd::make_any(TryConvertingETexModMoveTypeToCString(pTextureRes->AddModificator()->m_eMoveType[1]).toLatin1().data()); - } - else if (propertyName == "RateU") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_OscRate[0]); - - } - else if (propertyName == "RateV") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_OscRate[1]); - } - else if (propertyName == "PhaseU") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_OscPhase[0]); - } - else if (propertyName == "PhaseV") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_OscPhase[1]); - } - else if (propertyName == "AmplitudeU") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_OscAmplitude[0]); - } - else if (propertyName == "AmplitudeV") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_OscAmplitude[1]); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid property.").toUtf8().data()); - } - } - else - { - throw std::runtime_error((QString("\"") + subCategoryName + "\" is an invalid sub category.").toUtf8().data()); - } - } - else - { - AZ_Warning("ShadersSystem", false, "PyGetProperty - Error: empty 'subSubCategoryName' texture slot [%d] for material %s", - aznumeric_cast(TryConvertingCStringToEEfResTextures(subSubCategoryName)), - pMaterial->GetName().toStdString().c_str()); - } - } - else - { - throw std::runtime_error(errorMsgInvalidPropertyPath.toUtf8().data()); - } - } - // ########## Shader Params ########## - else if (categoryName == "Shader Params") - { - auto& shaderParams = pMaterial->GetShaderResources().m_ShaderParams; - - for (int i = 0; i < shaderParams.size(); i++) - { - if (propertyName == ParseUINameFromPublicParamsScript(shaderParams[i].m_Script.c_str())) - { - if (shaderParams[i].m_Type == eType_FLOAT) - { - return AZStd::make_any(shaderParams[i].m_Value.m_Float); - } - else if (shaderParams[i].m_Type == eType_FCOLOR) - { - QColor col = ColorLinearToGamma(ColorF( - shaderParams[i].m_Value.m_Vector[0], - shaderParams[i].m_Value.m_Vector[1], - shaderParams[i].m_Value.m_Vector[2])); - return AZStd::make_any(col.red(), col.green(), col.blue(), 1.0f); - } - } - } - - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid shader param.").toUtf8().data()); - } - // ########## Shader Generation Params ########## - else if (categoryName == "Shader Generation Params") - { - for (int i = 0; i < pMaterial->GetShaderGenParamsVars()->GetNumVariables(); i++) - { - if (propertyName == pMaterial->GetShaderGenParamsVars()->GetVariable(i)->GetHumanName()) - { - // get the current Boolean value for this shader variable and return so that the std::runtime_error() will not throw to indicate failure - bool boolValue = false; - pMaterial->GetShaderGenParamsVars()->GetVariable(i)->Get(boolValue); - return AZStd::make_any(boolValue); - } - } - - // not matching property was found, so throw a std::runtime_error() to indcate an error - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid shader generation param.").toUtf8().data()); - } - // ########## Vertex Deformation ########## - else if (categoryName == "Vertex Deformation") - { - // ########## Vertex Deformation / [ Type | Wave Length X | Wave Length Y | Wave Length Z | Wave Length W | Noise Scale ] ########## - if (splittedPropertyPath.size() == 2) - { - if (propertyName == "Type") - { - return AZStd::make_any(TryConvertingEDeformTypeToCString(pMaterial->GetShaderResources().m_DeformInfo.m_eType).toLatin1().data()); - } - else if (propertyName == "Wave Length X") - { - return AZStd::make_any(pMaterial->GetShaderResources().m_DeformInfo.m_fDividerX); - } - else if (propertyName == "Noise Scale") - { - return AZStd::make_any( - pMaterial->GetShaderResources().m_DeformInfo.m_vNoiseScale[0], - pMaterial->GetShaderResources().m_DeformInfo.m_vNoiseScale[1], - pMaterial->GetShaderResources().m_DeformInfo.m_vNoiseScale[2]); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid property.").toUtf8().data()); - } - } - // ########## Vertex Deformation / [ Wave X ] ########## - else if (splittedPropertyPath.size() == 3) - { - if (subCategoryName == "Wave X") - { - SWaveForm2 currentWaveForm; - if (subCategoryName == "Wave X") - { - currentWaveForm = pMaterial->GetShaderResources().m_DeformInfo.m_WaveX; - } - - if (propertyName == "Type") - { - return AZStd::make_any(TryConvertingEWaveFormToCString(currentWaveForm.m_eWFType).toLatin1().data()); - } - else if (propertyName == "Level") - { - return AZStd::make_any(currentWaveForm.m_Level); - } - else if (propertyName == "Amplitude") - { - return AZStd::make_any(currentWaveForm.m_Amp); - } - else if (propertyName == "Phase") - { - return AZStd::make_any(currentWaveForm.m_Phase); - } - else if (propertyName == "Frequency") - { - return AZStd::make_any(currentWaveForm.m_Freq); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid property.").toUtf8().data()); - } - } - else - { - throw std::runtime_error((QString("\"") + categoryName + "\" is an invalid category.").toUtf8().data()); - } - } - else - { - throw std::runtime_error(errorMsgInvalidPropertyPath.toUtf8().data()); - } - } - // ########## Layer Presets ########## - else if (categoryName == "Layer Presets") - { - // names are "Shader1", "Shader2" and "Shader3", because all have the name "Shader" in material editor - if (splittedPropertyPath.size() == 2) - { - int shaderNumber = -1; - if (propertyName == "Shader1") - { - shaderNumber = 0; - } - else if (propertyName == "Shader2") - { - shaderNumber = 1; - } - else if (propertyName == "Shader3") - { - shaderNumber = 2; - } - else - { - throw std::runtime_error("Invalid shader."); - } - - return AZStd::make_any(pMaterial->GetMtlLayerResources()[shaderNumber].m_shaderName.toLatin1().data()); - } - else if (splittedPropertyPath.size() == 3) - { - if (propertyName == "No Draw") - { - int shaderNumber = -1; - if (subCategoryName == "Shader1") - { - shaderNumber = 0; - } - else if (subCategoryName == "Shader2") - { - shaderNumber = 1; - } - else if (subCategoryName == "Shader3") - { - shaderNumber = 2; - } - else - { - throw std::runtime_error("Invalid shader."); - } - return AZStd::make_any(pMaterial->GetMtlLayerResources()[shaderNumber].m_nFlags & MTL_LAYER_USAGE_NODRAW); - } - } - } - - throw std::runtime_error(errorMsgInvalidPropertyPath.toUtf8().data()); - return AZStd::any(); - } - - void PySetProperty(const char* pPathAndMaterialName, const char* pPathAndPropertyName, const AZStd::any& value) - { - CMaterial* pMaterial = TryLoadingMaterial(pPathAndMaterialName); - std::deque splittedPropertyPath = PreparePropertyPath(pPathAndPropertyName); - std::deque splittedPropertyPathCategory = splittedPropertyPath; - QString categoryName = splittedPropertyPath.front(); - QString subCategoryName = "None"; - QString subSubCategoryName = "None"; - QString propertyName = splittedPropertyPath.back(); - QString errorMsgInvalidPropertyPath = "Invalid property path."; - - if (!ValidateProperty(pMaterial, splittedPropertyPath, value)) - { - throw std::runtime_error("Invalid property."); - } - - QString undoMsg = "Set Material Property"; - CUndo undo(undoMsg.toUtf8().data()); - pMaterial->RecordUndo(undoMsg.toUtf8().data(), true); - - if (splittedPropertyPathCategory.size() == 3) - { - splittedPropertyPathCategory.pop_back(); - subCategoryName = splittedPropertyPathCategory.back(); - } - else if (splittedPropertyPathCategory.size() == 4) - { - splittedPropertyPathCategory.pop_back(); - subCategoryName = splittedPropertyPathCategory.back(); - splittedPropertyPathCategory.pop_back(); - subSubCategoryName = splittedPropertyPathCategory.back(); - } - - // ########## Material Settings ########## - if (categoryName == "Material Settings") - { - if (propertyName == "Shader") - { - pMaterial->SetShaderName(AZStd::any_cast(value).data()); - } - else if (propertyName == "Surface Type") - { - bool isSurfaceExist(false); - QString realSurfacename = ""; - ISurfaceTypeEnumerator* pSurfaceTypeEnum = gEnv->p3DEngine->GetMaterialManager()->GetSurfaceTypeManager()->GetEnumerator(); - if (pSurfaceTypeEnum) - { - for (ISurfaceType* pSurfaceType = pSurfaceTypeEnum->GetFirst(); pSurfaceType; pSurfaceType = pSurfaceTypeEnum->GetNext()) - { - QString surfaceName = pSurfaceType->GetName(); - realSurfacename = surfaceName; - if (surfaceName.left(4) == "mat_") - { - surfaceName.remove(0, 4); - } - if (surfaceName == AZStd::any_cast(value).data()) - { - isSurfaceExist = true; - pMaterial->SetSurfaceTypeName(realSurfacename); - } - } - - if (!isSurfaceExist) - { - throw std::runtime_error("Invalid surface type name."); - } - } - else - { - throw std::runtime_error("Surface Type Enumerator corrupted."); - } - } - } - // ########## Opacity Settings ########## - else if (categoryName == "Opacity Settings") - { - if (propertyName == "Opacity") - { - pMaterial->GetShaderResources().m_LMaterial.m_Opacity = PyFetchNumericType(value) / 100.0f; - } - else if (propertyName == "AlphaTest") - { - pMaterial->GetShaderResources().m_AlphaRef = PyFetchNumericType(value) / 100.0f; - } - else if (propertyName == "Additive") - { - SetMaterialFlag(pMaterial, MTL_FLAG_ADDITIVE, PyFetchNumericType(value)); - } - } - // ########## Lighting Settings ########## - else if (categoryName == "Lighting Settings") - { - if (propertyName == "Diffuse Color") - { - const AZ::Color* color = AZStd::any_cast(&value); - pMaterial->GetShaderResources().m_LMaterial.m_Diffuse = ColorGammaToLinear(QColor(color->GetR8(), color->GetG8(), color->GetB8())); - } - else if (propertyName == "Specular Color") - { - const AZ::Color* color = AZStd::any_cast(&value); - ColorF colorFloat = ColorGammaToLinear(QColor(color->GetR8(), color->GetG8(), color->GetB8())); - colorFloat.a = pMaterial->GetShaderResources().m_LMaterial.m_Specular.a; - colorFloat.r *= colorFloat.a; - colorFloat.g *= colorFloat.a; - colorFloat.b *= colorFloat.a; - pMaterial->GetShaderResources().m_LMaterial.m_Specular = colorFloat; - } - else if (propertyName == "Glossiness" || propertyName == "Smoothness") - { - pMaterial->GetShaderResources().m_LMaterial.m_Smoothness = PyFetchNumericType(value); - } - else if (propertyName == "Specular Level") - { - const float localVariableAlpha = PyFetchNumericType(value); - ColorF colorFloat = pMaterial->GetShaderResources().m_LMaterial.m_Specular; - colorFloat.r *= localVariableAlpha; - colorFloat.g *= localVariableAlpha; - colorFloat.b *= localVariableAlpha; - colorFloat.a = 1.0f; - pMaterial->GetShaderResources().m_LMaterial.m_Specular = colorFloat; - } - else if (propertyName == "Emissive Color") - { - const AZ::Color* color = AZStd::any_cast(&value); - float emissiveIntensity = pMaterial->GetShaderResources().m_LMaterial.m_Emittance.a; - pMaterial->GetShaderResources().m_LMaterial.m_Emittance = ColorGammaToLinear(QColor(color->GetR8(), color->GetG8(), color->GetB8())); - pMaterial->GetShaderResources().m_LMaterial.m_Emittance.a = emissiveIntensity; - } - else if (propertyName == "Emissive Intensity") - { - pMaterial->GetShaderResources().m_LMaterial.m_Emittance.a = PyFetchNumericType(value); - } - } - // ########## Advanced ########## - else if (categoryName == "Advanced") - { - if (propertyName == "Allow layer activation") - { - pMaterial->SetLayerActivation(PyFetchNumericType(value)); - } - else if (propertyName == "2 Sided") - { - SetMaterialFlag(pMaterial, MTL_FLAG_2SIDED, PyFetchNumericType(value)); - } - else if (propertyName == "No Shadow") - { - SetMaterialFlag(pMaterial, MTL_FLAG_NOSHADOW, PyFetchNumericType(value)); - } - else if (propertyName == "Use Scattering") - { - SetMaterialFlag(pMaterial, MTL_FLAG_SCATTER, PyFetchNumericType(value)); - } - else if (propertyName == "Hide After Breaking") - { - SetMaterialFlag(pMaterial, MTL_FLAG_HIDEONBREAK, PyFetchNumericType(value)); - } - else if (propertyName == "Fog Volume Shading Quality High") - { - SetMaterialFlag(pMaterial, MTL_FLAG_FOG_VOLUME_SHADING_QUALITY_HIGH, PyFetchNumericType(value)); - } - else if (propertyName == "Blend Terrain Color") - { - SetMaterialFlag(pMaterial, MTL_FLAG_BLEND_TERRAIN, PyFetchNumericType(value)); - } - else if (propertyName == "Voxel Coverage") - { - pMaterial->GetShaderResources().m_VoxelCoverage = aznumeric_cast(PyFetchNumericType(value) * 255.0f); - } - else if (propertyName == "Link to Material") - { - pMaterial->GetMatInfo()->SetMaterialLinkName(AZStd::any_cast(value).data()); - } - else if (propertyName == "Propagate Material Settings") - { - SetPropagationFlag(pMaterial, MTL_PROPAGATE_MATERIAL_SETTINGS, PyFetchNumericType(value)); - } - else if (propertyName == "Propagate Opacity Settings") - { - SetPropagationFlag(pMaterial, MTL_PROPAGATE_OPACITY, PyFetchNumericType(value)); - } - else if (propertyName == "Propagate Lighting Settings") - { - SetPropagationFlag(pMaterial, MTL_PROPAGATE_LIGHTING, PyFetchNumericType(value)); - } - else if (propertyName == "Propagate Advanced Settings") - { - SetPropagationFlag(pMaterial, MTL_PROPAGATE_ADVANCED, PyFetchNumericType(value)); - } - else if (propertyName == "Propagate Texture Maps") - { - SetPropagationFlag(pMaterial, MTL_PROPAGATE_TEXTURES, PyFetchNumericType(value)); - } - else if (propertyName == "Propagate Shader Params") - { - if (PyFetchNumericType(value)) - { - SetPropagationFlag(pMaterial, MTL_PROPAGATE_MATERIAL_SETTINGS, true); - } - SetPropagationFlag(pMaterial, MTL_PROPAGATE_SHADER_PARAMS, PyFetchNumericType(value)); - } - else if (propertyName == "Propagate Shader Generation") - { - if (PyFetchNumericType(value)) - { - SetPropagationFlag(pMaterial, MTL_PROPAGATE_MATERIAL_SETTINGS, true); - } - SetPropagationFlag(pMaterial, MTL_PROPAGATE_SHADER_GEN, PyFetchNumericType(value)); - } - else if (propertyName == "Propagate Vertex Deformation") - { - SetPropagationFlag(pMaterial, MTL_PROPAGATE_VERTEX_DEF, PyFetchNumericType(value)); - } - else if (propertyName == "Propagate Layer Presets") - { - SetPropagationFlag(pMaterial, MTL_PROPAGATE_LAYER_PRESETS, PyFetchNumericType(value)); - } - } - // ########## Texture Maps ########## - else if (categoryName == "Texture Maps") - { - // ########## Texture Maps / [name] ########## - SInputShaderResources& shaderResources = pMaterial->GetShaderResources(); - if (splittedPropertyPath.size() == 2) - { - uint16 nSlot = aznumeric_cast(TryConvertingCStringToEEfResTextures(propertyName)); - auto stringValue = AZStd::any_cast(value); - if (stringValue.empty()) - { - AZ_Warning("ShadersSystem", false, "PySetProperty - Error: empty texture [%d] name for material %s", - nSlot, pMaterial->GetName().toStdString().c_str()); - } - // notice that the following is an insertion operation if the index did not exist in the map - shaderResources.m_TexturesResourcesMap[nSlot].m_Name = stringValue.data(); - } - // ########## Texture Maps / [TexType | Filter | IsProjectedTexGen | TexGenType ] ########## - else if (splittedPropertyPath.size() == 3) - { - uint16 nSlot = aznumeric_cast(TryConvertingCStringToEEfResTextures(subCategoryName)); - // notice that each of the following will add the texture slot if did not exist yet - if (propertyName == "TexType") - { - shaderResources.m_TexturesResourcesMap[nSlot].m_Sampler.m_eTexType = TryConvertingCStringToETEX_Type(AZStd::any_cast(value)); - } - else if (propertyName == "Filter") - { - shaderResources.m_TexturesResourcesMap[nSlot].m_Filter = TryConvertingCStringToTexFilter(AZStd::any_cast(value)); - } - else if (propertyName == "IsProjectedTexGen") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_bTexGenProjected = PyFetchNumericType(value); - } - else if (propertyName == "TexGenType") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_eTGType = TryConvertingCStringToETexGenType(AZStd::any_cast(value)); - } - } - // ########## Texture Maps / [Tiling | Rotator | Oscillator] ########## - else if (splittedPropertyPath.size() == 4) - { - uint16 nSlot = aznumeric_cast(TryConvertingCStringToEEfResTextures(subSubCategoryName)); - if (subCategoryName == "Tiling") - { - if (propertyName == "IsTileU") - { - shaderResources.m_TexturesResourcesMap[nSlot].m_bUTile = PyFetchNumericType(value); - } - else if (propertyName == "IsTileV") - { - shaderResources.m_TexturesResourcesMap[nSlot].m_bVTile = PyFetchNumericType(value); - } - else if (propertyName == "TileU") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_Tiling[0] = PyFetchNumericType(value); - } - else if (propertyName == "TileV") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_Tiling[1] = PyFetchNumericType(value); - } - else if (propertyName == "OffsetU") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_Offs[0] = PyFetchNumericType(value); - } - else if (propertyName == "OffsetV") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_Offs[1] = PyFetchNumericType(value); - } - else if (propertyName == "RotateU") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_Rot[0] = Degr2Word(PyFetchNumericType(value)); - } - else if (propertyName == "RotateV") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_Rot[1] = Degr2Word(PyFetchNumericType(value)); - } - else if (propertyName == "RotateW") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_Rot[2] = Degr2Word(PyFetchNumericType(value)); - } - } - else if (subCategoryName == "Rotator") - { - if (propertyName == "Type") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_eRotType = TryConvertingCStringToETexModRotateType(AZStd::any_cast(value)); - } - else if (propertyName == "Rate") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_RotOscRate[2] = Degr2Word(PyFetchNumericType(value)); - } - else if (propertyName == "Phase") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_RotOscPhase[2] = Degr2Word(PyFetchNumericType(value)); - } - else if (propertyName == "Amplitude") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_RotOscAmplitude[2] = Degr2Word(PyFetchNumericType(value)); - } - else if (propertyName == "CenterU") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_RotOscCenter[0] = PyFetchNumericType(value); - } - else if (propertyName == "CenterV") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_RotOscCenter[1] = PyFetchNumericType(value); - } - } - else if (subCategoryName == "Oscillator") - { - if (propertyName == "TypeU") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_eMoveType[0] = TryConvertingCStringToETexModMoveType(AZStd::any_cast(value)); - } - else if (propertyName == "TypeV") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_eMoveType[1] = TryConvertingCStringToETexModMoveType(AZStd::any_cast(value)); - } - else if (propertyName == "RateU") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_OscRate[0] = PyFetchNumericType(value); - } - else if (propertyName == "RateV") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_OscRate[1] = PyFetchNumericType(value); - } - else if (propertyName == "PhaseU") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_OscPhase[0] = PyFetchNumericType(value); - } - else if (propertyName == "PhaseV") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_OscPhase[1] = PyFetchNumericType(value); - } - else if (propertyName == "AmplitudeU") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_OscAmplitude[0] = PyFetchNumericType(value); - } - else if (propertyName == "AmplitudeV") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_OscAmplitude[1] = PyFetchNumericType(value); - } - } - } - } - // ########## Shader Params ########## - else if (categoryName == "Shader Params") - { - auto& shaderParams = pMaterial->GetShaderResources().m_ShaderParams; - - for (int i = 0; i < shaderParams.size(); i++) - { - if (propertyName == ParseUINameFromPublicParamsScript(shaderParams[i].m_Script.c_str())) - { - if (shaderParams[i].m_Type == eType_FLOAT) - { - shaderParams[i].m_Value.m_Float = PyFetchNumericType(value); - break; - } - else if (shaderParams[i].m_Type == eType_FCOLOR) - { - const AZ::Color* color = AZStd::any_cast(&value); - ColorF colorLinear = ColorGammaToLinear(QColor(color->GetR8(), color->GetG8(), color->GetB8())); - shaderParams[i].m_Value.m_Vector[0] = colorLinear.r; - shaderParams[i].m_Value.m_Vector[1] = colorLinear.g; - shaderParams[i].m_Value.m_Vector[2] = colorLinear.b; - break; - } - else - { - throw std::runtime_error("Invalid data type (Shader Params)"); - } - } - } - } - // ########## Shader Generation Params ########## - else if (categoryName == "Shader Generation Params") - { - for (int i = 0; i < pMaterial->GetShaderGenParamsVars()->GetNumVariables(); i++) - { - if (propertyName == pMaterial->GetShaderGenParamsVars()->GetVariable(i)->GetHumanName()) - { - CVarBlock* shaderGenBlock = pMaterial->GetShaderGenParamsVars(); - shaderGenBlock->GetVariable(i)->Set(PyFetchNumericType(value)); - pMaterial->SetShaderGenParamsVars(shaderGenBlock); - break; - } - } - } - // ########## Vertex Deformation ########## - else if (categoryName == "Vertex Deformation") - { - // ########## Vertex Deformation / [ Type | Wave Length X | Noise Scale ] ########## - if (splittedPropertyPath.size() == 2) - { - if (propertyName == "Type") - { - pMaterial->GetShaderResources().m_DeformInfo.m_eType = TryConvertingCStringToEDeformType(AZStd::any_cast(value)); - } - else if (propertyName == "Wave Length X") - { - pMaterial->GetShaderResources().m_DeformInfo.m_fDividerX = PyFetchNumericType(value); - } - else if (propertyName == "Noise Scale") - { - const AZ::Vector3* vecValue = AZStd::any_cast(&value); - pMaterial->GetShaderResources().m_DeformInfo.m_vNoiseScale[0] = vecValue->GetX(); - pMaterial->GetShaderResources().m_DeformInfo.m_vNoiseScale[1] = vecValue->GetY(); - pMaterial->GetShaderResources().m_DeformInfo.m_vNoiseScale[2] = vecValue->GetZ(); - } - } - // ########## Vertex Deformation / [ Wave X ] ########## - else if (splittedPropertyPath.size() == 3) - { - if (subCategoryName == "Wave X") - { - SWaveForm2& currentWaveForm = pMaterial->GetShaderResources().m_DeformInfo.m_WaveX; - - if (propertyName == "Type") - { - currentWaveForm.m_eWFType = TryConvertingCStringToEWaveForm(AZStd::any_cast(value)); - } - else if (propertyName == "Level") - { - currentWaveForm.m_Level = PyFetchNumericType(value); - } - else if (propertyName == "Amplitude") - { - currentWaveForm.m_Amp = PyFetchNumericType(value); - } - else if (propertyName == "Phase") - { - currentWaveForm.m_Phase = PyFetchNumericType(value); - } - else if (propertyName == "Frequency") - { - currentWaveForm.m_Freq = PyFetchNumericType(value); - } - } - } - } - // ########## Layer Presets ########## - else if (categoryName == "Layer Presets") - { - // names are "Shader1", "Shader2" and "Shader3", because all have the name "Shader" in material editor - if (splittedPropertyPath.size() == 2) - { - int shaderNumber = -1; - if (propertyName == "Shader1") - { - shaderNumber = 0; - } - else if (propertyName == "Shader2") - { - shaderNumber = 1; - } - else if (propertyName == "Shader3") - { - shaderNumber = 2; - } - - pMaterial->GetMtlLayerResources()[shaderNumber].m_shaderName = AZStd::any_cast(value).data(); - } - else if (splittedPropertyPath.size() == 3) - { - if (propertyName == "No Draw") - { - int shaderNumber = -1; - if (subCategoryName == "Shader1") - { - shaderNumber = 0; - } - else if (subCategoryName == "Shader2") - { - shaderNumber = 1; - } - else if (subCategoryName == "Shader3") - { - shaderNumber = 2; - } - - if (pMaterial->GetMtlLayerResources()[shaderNumber].m_nFlags & MTL_LAYER_USAGE_NODRAW && PyFetchNumericType(value) == false) - { - pMaterial->GetMtlLayerResources()[shaderNumber].m_nFlags = pMaterial->GetMtlLayerResources()[shaderNumber].m_nFlags - MTL_LAYER_USAGE_NODRAW; - } - else if (!(pMaterial->GetMtlLayerResources()[shaderNumber].m_nFlags & MTL_LAYER_USAGE_NODRAW) && PyFetchNumericType(value) == true) - { - pMaterial->GetMtlLayerResources()[shaderNumber].m_nFlags = pMaterial->GetMtlLayerResources()[shaderNumber].m_nFlags | MTL_LAYER_USAGE_NODRAW; - } - } - } - } - - pMaterial->Update(); - pMaterial->Save(); - GetIEditor()->GetMaterialManager()->OnUpdateProperties(pMaterial, true); - } -} - -namespace AzToolsFramework -{ - void MaterialPythonFuncsHandler::Reflect(AZ::ReflectContext* context) - { - if (auto behaviorContext = azrtti_cast(context)) - { - // this will put these methods into the 'azlmbr.legacy.material' module - auto addLegacyMaterial = [](AZ::BehaviorContext::GlobalMethodBuilder methodBuilder) - { - methodBuilder->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation) - ->Attribute(AZ::Script::Attributes::Category, "Legacy/Material") - ->Attribute(AZ::Script::Attributes::Module, "legacy.material"); - }; - addLegacyMaterial(behaviorContext->Method("create", PyMaterialCreate, nullptr, "Creates a material.")); - addLegacyMaterial(behaviorContext->Method("create_multi", PyMaterialCreateMulti, nullptr, "Creates a multi-material.")); - addLegacyMaterial(behaviorContext->Method("convert_to_multi", PyMaterialConvertToMulti, nullptr, "Converts the selected material to a multi-material.")); - addLegacyMaterial(behaviorContext->Method("duplicate_current", PyMaterialDuplicateCurrent, nullptr, "Duplicates the current material.")); - addLegacyMaterial(behaviorContext->Method("merge_selection", PyMaterialMergeSelection, nullptr, "Merges the selected materials.")); - addLegacyMaterial(behaviorContext->Method("delete_current", PyMaterialDeleteCurrent, nullptr, "Deletes the current material.")); - addLegacyMaterial(behaviorContext->Method("get_submaterial", PyGetSubMaterial, nullptr, "Gets sub materials of a material.")); - addLegacyMaterial(behaviorContext->Method("get_property", PyGetProperty, nullptr, "Gets a property of a material.")); - addLegacyMaterial(behaviorContext->Method("set_property", PySetProperty, nullptr, "Sets a property of a material.")); - } - } -} diff --git a/Code/Sandbox/Editor/Material/MaterialPythonFuncs.h b/Code/Sandbox/Editor/Material/MaterialPythonFuncs.h deleted file mode 100644 index f04542f466..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialPythonFuncs.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -namespace AzToolsFramework -{ - //! A component to reflect scriptable commands for materials in the Editor - class MaterialPythonFuncsHandler - : public AZ::Component - { - public: - AZ_COMPONENT(MaterialPythonFuncsHandler, "{E437BCF2-DE71-43E1-A7EC-DD243EB41F0B}") - - SANDBOX_API static void Reflect(AZ::ReflectContext* context); - - // AZ::Component ... - void Activate() override {} - void Deactivate() override {} - }; - -} // namespace AzToolsFramework diff --git a/Code/Sandbox/Editor/Material/PreviewModelView.cpp b/Code/Sandbox/Editor/Material/PreviewModelView.cpp deleted file mode 100644 index 41a50436d1..0000000000 --- a/Code/Sandbox/Editor/Material/PreviewModelView.cpp +++ /dev/null @@ -1,416 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include "EditorDefs.h" - -//AZCore -#include - -//CRY -#include -#include - -//Editor -#include -#include -#include -#include -#include -#include -#include -#include - -//EditorCommon -#include - -//Local -#include "PreviewModelView.h" - -//QT -#include - - - -CPreviewModelView::CPreviewModelView(QWidget* parent) - : QViewport(parent, QViewport::StartupMode_Manual) // Manual since we need to set WA_DontCreateNativeAncestors before QViewport::Startup() creates the internal native window and propagates - , m_Flags(0) - , m_GridColor(150, 150, 150, 40) - , m_BackgroundColor(0.5f, 0.5f, 0.5f) - , m_TimeScale(1.0f) - , m_PlayState(PlayState::NONE) - , m_pStaticModel(nullptr) - , m_PostUpdateCallback(nullptr) - , m_ContextMenuCallback(nullptr) -{ -#ifdef Q_OS_MACOS - // Don't propagate the nativeness up, as dockwidgets on macOS don't like it - setAttribute(Qt::WA_DontCreateNativeAncestors); -#endif - Startup(); - - ////////////////////////////////////////////////////////// - //QViewport - AddConsumer(this); - ////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////// - //IEditorNotifyListener - GetIEditor()->RegisterNotifyListener(this); - ////////////////////////////////////////////////////////// - - FocusOnScreen();//update the camera ... - SetDefaultFlags(); - UpdateSettings(); -} - -CPreviewModelView::~CPreviewModelView() -{ - CRY_ASSERT(GetIEditor()); - - ////////////////////////////////////////////////////////// - //IEditorNotifyListener - GetIEditor()->UnregisterNotifyListener(this); - ////////////////////////////////////////////////////////// - - ReleaseModel(); -} - - -bool CPreviewModelView::IsFlagSet(PreviewModelViewFlag flag) const -{ - CRY_ASSERT(flag < PreviewModelViewFlag::END_POSSIBLE_ITEMS); - return (m_Flags & (1 << static_cast(flag))); -} - -void CPreviewModelView::ToggleFlag(PreviewModelViewFlag flag) -{ - CRY_ASSERT(flag < PreviewModelViewFlag::END_POSSIBLE_ITEMS); - if (IsFlagSet(flag)) - { - UnSetFlag(flag); - } - else - { - SetFlag(flag); - } -} - -void CPreviewModelView::SetFlag(PreviewModelViewFlag flag) -{ - CRY_ASSERT(flag < PreviewModelViewFlag::END_POSSIBLE_ITEMS); - m_Flags |= (1 << static_cast(flag)); -} - -void CPreviewModelView::UnSetFlag(PreviewModelViewFlag flag) -{ - CRY_ASSERT(flag < PreviewModelViewFlag::END_POSSIBLE_ITEMS); - m_Flags &= ~(1 << static_cast(flag)); -} - -void CPreviewModelView::ResetPlaybackControls() -{ - UnSetFlag(CPreviewModelView::PreviewModelViewFlag::LOOPING_PLAY); - m_TimeScale = 1.0f; -} - -void CPreviewModelView::ResetBackgroundColor() -{ - SetBackgroundColor(ColorF(0.5f, 0.5f, 0.5f)); -} - -void CPreviewModelView::ResetGridColor() -{ - SetGridColor(ColorF(150, 150, 150, 40)); -} - -void CPreviewModelView::ResetCamera() -{ - FocusOnScreen(); -} - -void CPreviewModelView::ResetAll() -{ - ResetPlaybackControls(); - ResetGridColor(); - ResetBackgroundColor(); - ReleaseModel(); - SetDefaultFlags(); -} - -void CPreviewModelView::SetGridColor(ColorF color) -{ - m_GridColor = color; -} - -void CPreviewModelView::SetBackgroundColor(ColorF color) -{ - m_BackgroundColor = color; -} - -void CPreviewModelView::SetPlayState(PlayState state) -{ - m_PlayState = state; -} - -void CPreviewModelView::SetTimeScale(float scale) -{ - m_TimeScale = scale; -} - -CPreviewModelView::PlayState CPreviewModelView::GetPlayState() const -{ - return m_PlayState; -} - -float CPreviewModelView::GetTimeScale() const -{ - return m_TimeScale; -} - - -ColorF CPreviewModelView::GetGridColor() const -{ - return m_GridColor; -} - -ColorF CPreviewModelView::GetBackgroundColor() const -{ - return m_BackgroundColor; -} - -void CPreviewModelView::ImportModel() -{ - SResourceSelectorContext x; - x.typeName = Prop::GetPropertyTypeToResourceType(ePropertyModel); - - QString currPath = m_ModelFilename.toLower(); - QString selected = GetIEditor()->GetResourceSelectorHost()->SelectResource(x, currPath); - LoadModelFile(selected); -} - -void CPreviewModelView::SetPostUpdateCallback(PostUpdateCallback callback) -{ - m_PostUpdateCallback = callback; -} - -void CPreviewModelView::SetContextMenuCallback(ContextMenuCallback callback) -{ - m_ContextMenuCallback = callback; -} - -//////////////////////////////////////////////////////// -//QViewportConsumer -void CPreviewModelView::OnViewportRender(const SRenderContext& rc) -{ - ///UPDATE - UpdateSettings();//Some changes may take effect next frame ... - - //External updating ... - if (m_PostUpdateCallback) - { - m_PostUpdateCallback(); - } - - //RENDER - CRY_ASSERT(rc.renderParams); - CRY_ASSERT(rc.passInfo); - RenderModels(*rc.renderParams, *rc.passInfo); -} - -void CPreviewModelView::OnViewportKey([[maybe_unused]] const SKeyEvent& ev) -{ -} - -void CPreviewModelView::OnViewportMouse([[maybe_unused]] const SMouseEvent& ev) -{ -} -//////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////// -//IEditorNotifyListener -void CPreviewModelView::OnEditorNotifyEvent(EEditorNotifyEvent event) -{ - switch (event) - { - case eNotify_OnCloseScene: - { - ResetAll(); - break; - } - case eNotify_OnIdleUpdate: - { - Update(); - } - break; - default: - break; - } -} -/////////////////////////////////////////////////////// - - -void CPreviewModelView::UpdateSettings() -{ - //Update the settings - SViewportSettings allsettings; - - allsettings.background.topColor = m_BackgroundColor; - allsettings.background.useGradient = false; - - allsettings.grid.showGrid = IsFlagSet(PreviewModelViewFlag::SHOW_GRID); - allsettings.grid.middleColor = m_BackgroundColor; - allsettings.grid.mainColor = m_GridColor; - - allsettings.rendering.wireframe = IsFlagSet(PreviewModelViewFlag::DRAW_WIREFRAME); - allsettings.rendering.sunlight = IsFlagSet(PreviewModelViewFlag::ENABLE_TIME_OF_DAY); - allsettings.rendering.fps = false; - - - // Set zoom speed to 1.0f for better UI workflow, instead of the default 0.1f - allsettings.camera.zoomSpeed = 1.0f; - allsettings.camera.moveSpeed = GetIEditor()->GetEditorSettings()->cameraMoveSpeed; - allsettings.camera.fastMoveMultiplier = GetIEditor()->GetEditorSettings()->cameraFastMoveSpeed; - allsettings.camera.rotationSpeed = GetIEditor()->GetEditorSettings()->cameraRotateSpeed; - allsettings.camera.showViewportOrientation = IsFlagSet(PreviewModelViewFlag::SHOW_GRID_AXIS); - - //Set them ... - SetSettings(allsettings); -} - - - -void CPreviewModelView::RenderModels(SRendParams& rendParams, SRenderingPassInfo& passInfo) -{ - if (m_pStaticModel) - { - if (IsFlagSet(PreviewModelViewFlag::PRECACHE_MATERIAL)) - { - _smart_ptr pCurMat = m_pStaticModel->GetMaterial(); - if (pCurMat) - { - pCurMat->PrecacheMaterial(0.0f, nullptr, true, true); - } - } - m_pStaticModel->Render(rendParams, passInfo); - } -} - -void CPreviewModelView::ReleaseModel() -{ - m_ModelFilename = ""; - SAFE_RELEASE(m_pStaticModel); -} - -void CPreviewModelView::SetDefaultFlags() -{ - UnSetFlag(PreviewModelViewFlag::SHOW_OVERDRAW); - - m_Flags = 0; - - SetFlag(PreviewModelViewFlag::SHOW_GRID); - SetFlag(PreviewModelViewFlag::SHOW_GRID_AXIS); -} - -void CPreviewModelView::LoadModelFile(const QString& modelFile) -{ - //Something to load - if (!modelFile.isEmpty()) - { - //Make sure we are not loading the same thing ... - if (m_ModelFilename != modelFile) - { - ReleaseModel();//release any old mesh - - QString strFileExt = Path::GetExt(modelFile); - bool isCGF = (QString::compare(strFileExt, CRY_GEOMETRY_FILE_EXT, Qt::CaseInsensitive) == 0); - - // NOTE: have to create a local buffer and evaluate the full message here due to calling into another address space to evaluate va_args - // this prevents passing of random data to the log system ... any plugin that does not do it this way is rolling the dice each time. - char buffer[2046]; - CRY_ASSERT(GetIEditor()); - if (isCGF) - { - CRY_ASSERT(GetIEditor()->Get3DEngine()); - // Load object. - m_pStaticModel = GetIEditor()->Get3DEngine()->LoadStatObjUnsafeManualRef(modelFile.toUtf8().data(), nullptr, nullptr, false); - if (m_pStaticModel) - { - m_pStaticModel->AddRef(); - } - else - { - CRY_ASSERT(GetIEditor()->GetLogFile()); - azsprintf(buffer, "Loading of geometry object %s failed.", modelFile.toUtf8().data()); - GetIEditor()->GetLogFile()->Warning(buffer); - } - } - else - { - CRY_ASSERT(GetIEditor()->GetLogFile()); - azsprintf(buffer, "Unknown model file (%s) attempting to be loaded.", modelFile.toUtf8().data()); - GetIEditor()->GetLogFile()->Warning(buffer); - } - - //if something was loaded then we store off the model path for the future - if (m_pStaticModel) - { - m_ModelFilename = modelFile; - } - } - } -} - -IStatObj* CPreviewModelView::GetStaticModel() -{ - return m_pStaticModel; -} - -void CPreviewModelView::FocusOnScreen() -{ - CCamera* camera = Camera(); - if (camera) - { - AABB accumulated(2); - - if (m_pStaticModel) - { - AABB temp; - temp.min = m_pStaticModel->GetBoxMin(); - temp.max = m_pStaticModel->GetBoxMax(); - accumulated.Add(temp); - } - - Vec3 fromDir(1.0f, 1.0f, -0.5f); - Vec3 target = accumulated.GetCenter(); - float bbRadius = accumulated.GetRadius(); - - Vec3 dir = fromDir.GetNormalized(); - Matrix34 tm = Matrix33::CreateRotationVDir(dir, 0); - tm.SetTranslation(target - dir * bbRadius); - CameraMoved(QuatT(tm), true); - } -} - -float CPreviewModelView::GetSpeedScale() const -{ - CRY_ASSERT(GetIEditor()); - CRY_ASSERT(GetIEditor()->GetSystem()); - CRY_ASSERT(GetIEditor()->GetSystem()->GetITimer()); - //Taken from CRenderViewport to mirror controls from there ... - float speedScale = 60.0f * GetIEditor()->GetSystem()->GetITimer()->GetFrameTime(); - if (speedScale > 20.0f) - { - speedScale = 20.0f; - } - return speedScale; -} - diff --git a/Code/Sandbox/Editor/Material/PreviewModelView.h b/Code/Sandbox/Editor/Material/PreviewModelView.h deleted file mode 100644 index 3d27983be1..0000000000 --- a/Code/Sandbox/Editor/Material/PreviewModelView.h +++ /dev/null @@ -1,173 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -//Editor -#if !defined(Q_MOC_RUN) -#include "IEditor.h" -#include "../EditorCommon/QViewport.h" -#include "../EditorCommon/QViewportConsumer.h" - -#endif - -struct IStatObj; -struct SRenderingPassInfo; -struct SRendParams; -class CParticleItem; -class CAxisHelper; -struct HitContext; -struct IGizmoMouseDragHandler; -struct SLodInfo; - -namespace RotationDrawHelper -{ - class Axis; -} - -AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING -class CPreviewModelView - : public QViewport - , public QViewportConsumer - , public IEditorNotifyListener -{ -AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING -public: - enum class PlayState - { - NONE, - PLAY, - PAUSE, - STEP, - RESET - }; - enum class SplineMode - { - NONE, - LINE, - SINEWAVE, - COIL - }; - - //NOTE: these need to be limited to 32 as these are being used for bit wise operations. - enum class PreviewModelViewFlag - { - DRAW_WIREFRAME = 0, - - SHOW_BOUNDINGBOX, - SHOW_GIZMO, - SHOW_GRID, - SHOW_GRID_AXIS, - SHOW_EMITTER_SHAPE, - SHOW_OVERDRAW, - SHOW_FIRST_CONTAINER, - - LOOPING_PLAY, - - //Spline - SPLINE_LOOPING, - SPLINE_PINGPONG, - - PRECACHE_MATERIAL, - - ENABLE_TIME_OF_DAY, - - END_POSSIBLE_ITEMS = 32, - }; - - explicit CPreviewModelView(QWidget* parent); - virtual ~CPreviewModelView(); - - //Flags - bool IsFlagSet(PreviewModelViewFlag flag) const; - void ToggleFlag(PreviewModelViewFlag flag); - virtual void SetFlag(PreviewModelViewFlag flag); - virtual void UnSetFlag(PreviewModelViewFlag flag); - - //Resets - void ResetPlaybackControls(); - void ResetBackgroundColor(); - void ResetGridColor(); - virtual void ResetCamera(); - virtual void ResetAll(); - - void SetGridColor(ColorF color); - void SetBackgroundColor(ColorF color); - void SetPlayState(PlayState state); - void SetTimeScale(float scale); - - PlayState GetPlayState() const; - float GetTimeScale() const; - ColorF GetGridColor() const; - ColorF GetBackgroundColor() const; - - void ImportModel(); - - void LoadModelFile(const QString& modelFile); - IStatObj* GetStaticModel(); - - typedef std::function PostUpdateCallback; - void SetPostUpdateCallback(PostUpdateCallback callback); - - typedef std::function ContextMenuCallback; - void SetContextMenuCallback(ContextMenuCallback callback); - - //////////////////////////////////////////////////////// - //QViewportConsumer - virtual void OnViewportRender(const SRenderContext& rc) override; - virtual void OnViewportKey(const SKeyEvent& ev) override; - virtual void OnViewportMouse(const SMouseEvent& ev) override; - //////////////////////////////////////////////////////// - - //////////////////////////////////////////////////////// - //IEditorNotifyListener - virtual void OnEditorNotifyEvent(EEditorNotifyEvent event) override; - //////////////////////////////////////////////////////// - -private: - - //Update - void UpdateSettings(); -protected: -private: - //Render - void RenderModels(SRendParams& rendParams, SRenderingPassInfo& passInfo); - - //Misc - void ReleaseModel(); - void SetDefaultFlags(); -protected: - void FocusOnScreen(); -private: - float GetSpeedScale() const; - -private: - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - ColorF m_GridColor; - ColorF m_BackgroundColor; - - QString m_ModelFilename; - - - IStatObj* m_pStaticModel; - -protected: - PostUpdateCallback m_PostUpdateCallback; - ContextMenuCallback m_ContextMenuCallback; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - -protected: - PlayState m_PlayState; - float m_TimeScale; -private: - unsigned int m_Flags; -}; diff --git a/Code/Sandbox/Editor/Material/images/filestatus_00.png b/Code/Sandbox/Editor/Material/images/filestatus_00.png deleted file mode 100644 index 414609f486..0000000000 --- a/Code/Sandbox/Editor/Material/images/filestatus_00.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:3e5d226d043630028a1fe88af240b627a08966066b605294cc79ff8273588166 -size 194 diff --git a/Code/Sandbox/Editor/Material/images/filestatus_01.png b/Code/Sandbox/Editor/Material/images/filestatus_01.png deleted file mode 100644 index d644fcfe12..0000000000 --- a/Code/Sandbox/Editor/Material/images/filestatus_01.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f80544a0537398979dd423ffdc8e99c08e47dbe814cd4225646761cbe281eecc -size 206 diff --git a/Code/Sandbox/Editor/Material/images/filestatus_02.png b/Code/Sandbox/Editor/Material/images/filestatus_02.png deleted file mode 100644 index da155a1d2a..0000000000 --- a/Code/Sandbox/Editor/Material/images/filestatus_02.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:bee8a3d1d5571e5afe0bd02edf0fc58d8297f96494a7c074fd2a37ecda7ae4dc -size 208 diff --git a/Code/Sandbox/Editor/Material/images/filestatus_03.png b/Code/Sandbox/Editor/Material/images/filestatus_03.png deleted file mode 100644 index a047cb4599..0000000000 --- a/Code/Sandbox/Editor/Material/images/filestatus_03.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d3d0fc234e3154c06abd4e3b8d3d7e52a75f80d527b1d05541f55221cba199d7 -size 183 diff --git a/Code/Sandbox/Editor/Material/images/filestatus_04.png b/Code/Sandbox/Editor/Material/images/filestatus_04.png deleted file mode 100644 index 519b68d500..0000000000 --- a/Code/Sandbox/Editor/Material/images/filestatus_04.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:ffb3586ef4309d8bfa93a581c38fe970e8b0411f170955921054522b0bf52bd3 -size 182 diff --git a/Code/Sandbox/Editor/Material/images/filestatus_05.png b/Code/Sandbox/Editor/Material/images/filestatus_05.png deleted file mode 100644 index f4f548cdc9..0000000000 --- a/Code/Sandbox/Editor/Material/images/filestatus_05.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f258e9617a1d4c7be16fcab12533a4f0bfe4072151f2140ca41364ef1a3cea62 -size 196 diff --git a/Code/Sandbox/Editor/Material/images/filestatus_06.png b/Code/Sandbox/Editor/Material/images/filestatus_06.png deleted file mode 100644 index 7b7412b19d..0000000000 --- a/Code/Sandbox/Editor/Material/images/filestatus_06.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:68c609d7bde1796f281690148c19694afddcc2cf4ea306116b546327cb50aad2 -size 249 diff --git a/Code/Sandbox/Editor/Material/images/material_00.png b/Code/Sandbox/Editor/Material/images/material_00.png deleted file mode 100644 index a7f48148f1..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_00.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:bd5106eebb6cf264fdac5f3568977fc8f944df4a4d4de6b0e9f35b3a001a3001 -size 206 diff --git a/Code/Sandbox/Editor/Material/images/material_01.png b/Code/Sandbox/Editor/Material/images/material_01.png deleted file mode 100644 index e6c26f748a..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_01.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:2b08a8d94c64aed944901b76afcb921c3df2c122c9eac6d52140552c2eb4e5cc -size 227 diff --git a/Code/Sandbox/Editor/Material/images/material_02.png b/Code/Sandbox/Editor/Material/images/material_02.png deleted file mode 100644 index a116e84295..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_02.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:623a937f09f1de3ebb889d7ac9e042f91bf67bef34695801b3603f4517166c8e -size 223 diff --git a/Code/Sandbox/Editor/Material/images/material_03.png b/Code/Sandbox/Editor/Material/images/material_03.png deleted file mode 100644 index a116e84295..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_03.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:623a937f09f1de3ebb889d7ac9e042f91bf67bef34695801b3603f4517166c8e -size 223 diff --git a/Code/Sandbox/Editor/Material/images/material_04.png b/Code/Sandbox/Editor/Material/images/material_04.png deleted file mode 100644 index 1d83e3526a..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_04.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:0ad56ab7be0a5a40b644045ac01c90fed6e70433a693e80c5b4b88d63801d75f -size 14604 diff --git a/Code/Sandbox/Editor/Material/images/material_05.png b/Code/Sandbox/Editor/Material/images/material_05.png deleted file mode 100644 index 8d953a6ae4..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_05.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:9cc845c4eb0ed6fb772064d73f1c679e3b28288411a02f0cafaf248b83b44ca2 -size 221 diff --git a/Code/Sandbox/Editor/Material/images/material_06.png b/Code/Sandbox/Editor/Material/images/material_06.png deleted file mode 100644 index 7e5159a2fc..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_06.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:966fd5ef5c1e0fe6e920511952d7aea98ad0f165f9ce0197f000f9f48ccd338b -size 14628 diff --git a/Code/Sandbox/Editor/Material/images/material_07.png b/Code/Sandbox/Editor/Material/images/material_07.png deleted file mode 100644 index 7e5159a2fc..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_07.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:966fd5ef5c1e0fe6e920511952d7aea98ad0f165f9ce0197f000f9f48ccd338b -size 14628 diff --git a/Code/Sandbox/Editor/Material/images/material_browser_00.png b/Code/Sandbox/Editor/Material/images/material_browser_00.png deleted file mode 100644 index f1e7a2ffce..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_browser_00.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:c4a8dc85c9928faacd184148aaf0f17ef7b68c185b04b0b5f16e942fb11c528e -size 209 diff --git a/Code/Sandbox/Editor/Material/images/material_browser_01.png b/Code/Sandbox/Editor/Material/images/material_browser_01.png deleted file mode 100644 index 1ff2ea213f..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_browser_01.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d9047378404e0893b79bafaad9e6b312d467033daab2191a8c8839e4ff494bd8 -size 321 diff --git a/Code/Sandbox/Editor/Material/images/material_browser_02.png b/Code/Sandbox/Editor/Material/images/material_browser_02.png deleted file mode 100644 index edd5148133..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_browser_02.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:2e79122edef52c3f9a31fd662f9f5cfd08b06e44e861c7379d8869635fd1d245 -size 168 diff --git a/Code/Sandbox/Editor/Material/images/material_browser_03.png b/Code/Sandbox/Editor/Material/images/material_browser_03.png deleted file mode 100644 index bfbcc6ce98..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_browser_03.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:8cc16bbb4c4c0c1bea14c94d0609f4b11a7cd0ead4af3d236d329a404e8223a8 -size 200 diff --git a/Code/Sandbox/Editor/MaterialSender.cpp b/Code/Sandbox/Editor/MaterialSender.cpp deleted file mode 100644 index 2123eadb31..0000000000 --- a/Code/Sandbox/Editor/MaterialSender.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#include "EditorDefs.h" - -#include "MaterialSender.h" - -bool CMaterialSender::SendMessage(int msg, const XmlNodeRef& node) -{ - bool bRet = false; - -#if defined(AZ_PLATFORM_WINDOWS) - if (!CheckWindows()) - { - return false; - } - - m_h.msg = msg; - - int nDataSize = sizeof(SMaterialMapFileHeader) + strlen(node->getXML().c_str()) + 1; - - //hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, nDataSize, "EditMatMappingObject"); - - HANDLE mapFileHandle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, "EditMatMappingObject"); - if (mapFileHandle) - { - void* pMes = MapViewOfFile(mapFileHandle, FILE_MAP_ALL_ACCESS, 0, 0, nDataSize); - if (pMes) - { - memcpy(pMes, &m_h, sizeof(SMaterialMapFileHeader)); - azstrcpy(((char*)pMes) + sizeof(SMaterialMapFileHeader), nDataSize - sizeof(SMaterialMapFileHeader), node->getXML().c_str()); - UnmapViewOfFile(pMes); - if (m_bIsMatEditor) - { - ::SendMessage(m_h.GetMaxHWND(), WM_MATEDITSEND, msg, 0); - } - else - { - ::SendMessage(m_h.GetEditorHWND(), WM_MATEDITSEND, msg, 0); - } - bRet = true; - } - CloseHandle(mapFileHandle); - } - else - { - CryLog("No File Map"); - } -#endif - - return bRet; -} diff --git a/Code/Sandbox/Editor/MaterialSender.h b/Code/Sandbox/Editor/MaterialSender.h deleted file mode 100644 index 0123223821..0000000000 --- a/Code/Sandbox/Editor/MaterialSender.h +++ /dev/null @@ -1,175 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_MATERIALSENDER_H -#define CRYINCLUDE_EDITOR_MATERIALSENDER_H -#pragma once - -#ifndef WM_MATEDITSEND -// Value copied from Code/Tools/MaxCryExport/CryShader/MaterialSender.h -# define WM_MATEDITSEND (WM_USER + 315) -#endif - -enum EMaterialSenderMessage -{ - eMSM_Create = 1, - eMSM_GetSelectedMaterial = 2, - eMSM_Init = 3, -}; - -#if defined(AZ_PLATFORM_WINDOWS) -struct SMaterialMapFileHeader -{ - // max - void SetMaxHWND(HWND hWnd) - { - hwndMax = (int64)hWnd; - } - HWND GetMaxHWND() const - { - return (HWND)hwndMax; - } - // editor - void SetEditorHWND(HWND hWnd) - { - hwndMatEdit = (int64)hWnd; - } - HWND GetEditorHWND() const - { - return (HWND)hwndMatEdit; - } - int64 msg;// 64bits for both 32 and 64 - int64 Reserved;// 64bits for both 32 and 64 -protected: - uint64 hwndMax;// HWND for 32 and 64 is different - uint64 hwndMatEdit;// HWND for 32 and 64 is different -}; -#endif // AZ_PLATFORM_WINDOWS - - -class CMaterialSender -{ -public: - - CMaterialSender(bool bIsMatEditor) - : m_bIsMatEditor(bIsMatEditor) - { -#if defined(AZ_PLATFORM_WINDOWS) - m_h.SetEditorHWND(0); - m_h.SetMaxHWND(0); - m_h.msg = 0; - hMapFile = 0; -#endif - } - - ~CMaterialSender() - { -#if defined(AZ_PLATFORM_WINDOWS) - if (hMapFile) - { - CloseHandle(hMapFile); - } - hMapFile = 0; -#endif - } - - bool GetMessage() - { - LoadMapFile(); - return true; - } - - bool CheckWindows() - { -#if defined(AZ_PLATFORM_WINDOWS) - if (!m_h.GetMaxHWND() || !m_h.GetEditorHWND() || !::IsWindow(m_h.GetMaxHWND()) || !::IsWindow(m_h.GetEditorHWND())) - { - LoadMapFile(); - } - if (!m_h.GetMaxHWND() || !m_h.GetEditorHWND() || !::IsWindow(m_h.GetMaxHWND()) || !::IsWindow(m_h.GetEditorHWND())) - { - return false; - } -#endif - return true; - } - - bool Create() - { -#if defined(AZ_PLATFORM_WINDOWS) - hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 1024 * 1024, "EditMatMappingObject"); - if (hMapFile) - { - return true; - } - CryLog("Can't create File Map"); - - return false; -#else - return true; -#endif - } - - bool SendMessage(int msg, const XmlNodeRef& node); - - void SetupWindows(QWidget* hwndMax, QWidget* hwndMatEdit) - { -#if defined(AZ_PLATFORM_WINDOWS) - m_h.SetMaxHWND(reinterpret_cast(hwndMax->winId())); - m_h.SetEditorHWND(reinterpret_cast(hwndMatEdit->winId())); -#endif - } - -private: - - bool LoadMapFile() - { -#if defined(AZ_PLATFORM_WINDOWS) - bool bRet = false; - const HANDLE mapFileHandle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, "EditMatMappingObject"); - if (mapFileHandle) - { - void* const pMes = MapViewOfFile(mapFileHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0); - - if (pMes) - { - memcpy(&m_h, pMes, sizeof(SMaterialMapFileHeader)); - const char* const pXml = ((const char*)pMes) + sizeof(SMaterialMapFileHeader); - m_node = XmlHelpers::LoadXmlFromBuffer(pXml, strlen(pXml)); - UnmapViewOfFile(pMes); - bRet = true; - } - - CloseHandle(mapFileHandle); - } - - return bRet; -#else - return false; -#endif - } - -public: -#if defined(AZ_PLATFORM_WINDOWS) - SMaterialMapFileHeader m_h; -#endif - XmlNodeRef m_node; -private: - bool m_bIsMatEditor; -#if defined(AZ_PLATFORM_WINDOWS) - HANDLE hMapFile; -#endif -}; - - -#endif // CRYINCLUDE_EDITOR_MATERIALSENDER_H diff --git a/Code/Sandbox/Editor/ModelViewport.cpp b/Code/Sandbox/Editor/ModelViewport.cpp index bf15f2fbaf..2e00adb4fc 100644 --- a/Code/Sandbox/Editor/ModelViewport.cpp +++ b/Code/Sandbox/Editor/ModelViewport.cpp @@ -29,7 +29,6 @@ // Editor #include "ThumbnailGenerator.h" // for CThumbnailGenerator #include "FileTypeUtils.h" // for IsPreviewableFileType -#include "Material/MaterialManager.h" // for CMaterialManager #include "ErrorRecorder.h" @@ -652,32 +651,6 @@ void CModelViewport::DrawInfo() const } } -////////////////////////////////////////////////////////////////////////// -void CModelViewport::SetCustomMaterial(CMaterial* pMaterial) -{ - m_pCurrentMaterial = pMaterial; -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CModelViewport::GetMaterial() -{ - if (m_pCurrentMaterial) - { - return m_pCurrentMaterial; - } - else - { - _smart_ptr pMtl = 0; - if (m_object) - { - pMtl = m_object->GetMaterial(); - } - - CMaterial* pCMaterial = GetIEditor()->GetMaterialManager()->FromIMaterial(pMtl); - return pCMaterial; - } -} - ////////////////////////////////////////////////////////////////////////// bool CModelViewport::CanDrop([[maybe_unused]] const QPoint& point, IDataBaseItem* pItem) { @@ -686,26 +659,12 @@ bool CModelViewport::CanDrop([[maybe_unused]] const QPoint& point, IDataBaseItem return false; } - if (pItem->GetType() == EDB_TYPE_MATERIAL) - { - SetCustomMaterial((CMaterial*)pItem); - } return true; } ////////////////////////////////////////////////////////////////////////// -void CModelViewport::Drop([[maybe_unused]] const QPoint& point, IDataBaseItem* pItem) +void CModelViewport::Drop([[maybe_unused]] const QPoint& point, [[maybe_unused]] IDataBaseItem* pItem) { - if (!pItem) - { - SetCustomMaterial(NULL); - return; - } - - if (pItem->GetType() == EDB_TYPE_MATERIAL) - { - SetCustomMaterial((CMaterial*)pItem); - } } ////////////////////////////////////////////////////////////////////////// @@ -788,10 +747,6 @@ void CModelViewport::DrawModel(const SRenderingPassInfo& passInfo) } rp.dwFObjFlags = 0; - if (m_pCurrentMaterial) - { - rp.pMaterial = m_pCurrentMaterial->GetMatInfo(); - } //----------------------------------------------------------------------------- //----- Render Static Object (handled by 3DEngine) ---- diff --git a/Code/Sandbox/Editor/ModelViewport.h b/Code/Sandbox/Editor/ModelViewport.h index d9b119c5d5..a5d1ac2a26 100644 --- a/Code/Sandbox/Editor/ModelViewport.h +++ b/Code/Sandbox/Editor/ModelViewport.h @@ -31,7 +31,6 @@ #if !defined(Q_MOC_RUN) #include "RenderViewport.h" -#include "Material/Material.h" #include "Util/Variable.h" #endif @@ -90,14 +89,6 @@ public: void UseWeaponIK([[maybe_unused]] bool val) { m_weaponIK = true; } - // Set current material to render object. - void SetCustomMaterial(CMaterial* pMaterial); - // Get custom material that object is rendered with. - CMaterial* GetCustomMaterial() { return m_pCurrentMaterial; }; - - // Get material the object is actually rendered with. - CMaterial* GetMaterial(); - void ReleaseObject(); void RePhysicalize(); @@ -182,7 +173,6 @@ protected: class CRESky* m_pRESky; struct ICVar* m_pSkyboxName; IShader* m_pSkyBoxShader; - _smart_ptr m_pCurrentMaterial; //--------------------------------------------------- //--- debug options --- diff --git a/Code/Sandbox/Editor/Objects/AxisGizmo.cpp b/Code/Sandbox/Editor/Objects/AxisGizmo.cpp index 40970838c1..ef2b91685a 100644 --- a/Code/Sandbox/Editor/Objects/AxisGizmo.cpp +++ b/Code/Sandbox/Editor/Objects/AxisGizmo.cpp @@ -22,7 +22,6 @@ #include "ViewManager.h" #include "Settings.h" #include "RenderHelpers/AxisHelper.h" -#include "RenderHelpers/AxisHelperExtended.h" #include "IObjectManager.h" ////////////////////////////////////////////////////////////////////////// @@ -36,7 +35,6 @@ CAxisGizmo::CAxisGizmo(CBaseObject* object) assert(object != 0); m_object = object; m_pAxisHelper.reset(new CAxisHelper); - m_pAxisHelperExtended.reset(new CAxisHelperExtended); // Set selectable flag. SetFlags(EGIZMO_SELECTABLE | EGIZMO_TRANSFORM_MANIPULATOR); @@ -60,7 +58,6 @@ CAxisGizmo::CAxisGizmo() SetFlags(EGIZMO_SELECTABLE); m_axisGizmoCount++; m_pAxisHelper.reset(new CAxisHelper); - m_pAxisHelperExtended.reset(new CAxisHelperExtended); m_bDragging = false; m_bAlwaysUseLocal = false; m_coordSysBackUp = COORDS_VIEW; diff --git a/Code/Sandbox/Editor/Objects/AxisGizmo.h b/Code/Sandbox/Editor/Objects/AxisGizmo.h index 55506ed6b5..689b011972 100644 --- a/Code/Sandbox/Editor/Objects/AxisGizmo.h +++ b/Code/Sandbox/Editor/Objects/AxisGizmo.h @@ -22,7 +22,6 @@ // forward declarations. struct DisplayContext; class CAxisHelper; -class CAxisHelperExtended; /** Gizmo of Objects animation track. */ @@ -75,7 +74,6 @@ private: CBaseObjectPtr m_object; AABB m_bbox; std::unique_ptr m_pAxisHelper; - std::unique_ptr m_pAxisHelperExtended; bool m_bDragging; QPoint m_cMouseDownPos; diff --git a/Code/Sandbox/Editor/Objects/BaseObject.cpp b/Code/Sandbox/Editor/Objects/BaseObject.cpp index a579f303a9..109b28798f 100644 --- a/Code/Sandbox/Editor/Objects/BaseObject.cpp +++ b/Code/Sandbox/Editor/Objects/BaseObject.cpp @@ -30,8 +30,6 @@ #include "DisplaySettings.h" #include "Undo/Undo.h" #include "UsedResources.h" -#include "Material/Material.h" -#include "Material/MaterialManager.h" #include "GizmoManager.h" #include "Include/IIconManager.h" #include "Objects/SelectionGroup.h" @@ -398,7 +396,6 @@ CBaseObject::CBaseObject() , m_classDesc(nullptr) , m_numRefs(0) , m_parent(nullptr) - , m_pMaterial(nullptr) , m_bInSelectionBox(false) , m_pTransformDelegate(nullptr) , m_bMatrixInWorldSpace(false) @@ -438,7 +435,6 @@ bool CBaseObject::Init([[maybe_unused]] IEditor* ie, CBaseObject* prev, [[maybe_ SetArea(prev->GetArea()); SetColor(prev->GetColor()); m_nMaterialLayersMask = prev->m_nMaterialLayersMask; - SetMaterial(prev->GetMaterial()); SetMinSpec(prev->GetMinSpec(), false); // Copy all basic variables. @@ -485,12 +481,6 @@ void CBaseObject::Done() NotifyListeners(CBaseObject::ON_DELETE); m_eventListeners.clear(); - - if (m_pMaterial) - { - m_pMaterial->Release(); - m_pMaterial = NULL; - } } ////////////////////////////////////////////////////////////////////////// @@ -1838,11 +1828,6 @@ void CBaseObject::Serialize(CObjectArchive& ar) SetFrozen(bFrozen); SetHidden(bHidden); - ////////////////////////////////////////////////////////////////////////// - // Load material. - ////////////////////////////////////////////////////////////////////////// - SetMaterial(mtlName); - ar.SetResolveCallback(this, parentId, AZStd::bind(&CBaseObject::ResolveParent, this, AZStd::placeholders::_1 )); ar.SetResolveCallback(this, lookatId, AZStd::bind(&CBaseObject::SetLookAt, this, AZStd::placeholders::_1)); @@ -1912,11 +1897,6 @@ void CBaseObject::Serialize(CObjectArchive& ar) xmlNode->setAttr("Flags", flags); } - if (m_pMaterial) - { - xmlNode->setAttr("Material", GetMaterialName().toUtf8().data()); - } - if (m_nMinSpec != 0) { xmlNode->setAttr("MinSpec", (uint32)m_nMinSpec); @@ -1937,11 +1917,6 @@ XmlNodeRef CBaseObject::Export([[maybe_unused]] const QString& levelPath, XmlNod objNode->setAttr("Type", GetTypeName().toUtf8().data()); objNode->setAttr("Name", GetName().toUtf8().data()); - if (m_pMaterial) - { - objNode->setAttr("Material", m_pMaterial->GetName().toUtf8().data()); - } - Vec3 pos, scale; Quat rotate; if (m_parent) @@ -2926,7 +2901,6 @@ bool CBaseObject::ConvertFromObject(CBaseObject* object) { object->GetParent()->AttachChild(this); } - SetMaterial(object->GetMaterial()); return true; } @@ -2981,14 +2955,6 @@ void CBaseObject::Validate(IErrorReport* report) report->ReportError(err); } ////////////////////////////////////////////////////////////////////////// - - if (GetMaterial() != NULL && GetMaterial()->IsDummy()) - { - CErrorRecord err; - err.error = QStringLiteral("Material: %1 for object: %2 not found,").arg(GetMaterial()->GetName(), GetName()); - err.pObject = this; - report->ReportError(err); - } }; ////////////////////////////////////////////////////////////////////////// @@ -3055,10 +3021,6 @@ void CBaseObject::GatherUsedResources(CUsedResources& resources) { GetVarBlock()->GatherUsedResources(resources); } - if (m_pMaterial) - { - m_pMaterial->GatherUsedResources(resources); - } } ////////////////////////////////////////////////////////////////////////// @@ -3071,50 +3033,6 @@ bool CBaseObject::IsSimilarObject(CBaseObject* pObject) return false; } -////////////////////////////////////////////////////////////////////////// -void CBaseObject::SetMaterial(CMaterial* mtl) -{ - if (m_pMaterial == mtl) - { - return; - } - - StoreUndo("Assign Material"); - if (m_pMaterial) - { - m_pMaterial->Release(); - } - m_pMaterial = mtl; - if (m_pMaterial) - { - m_pMaterial->AddRef(); - } - - OnMaterialChanged(MATERIALCHANGE_ALL); -} - -////////////////////////////////////////////////////////////////////////// -QString CBaseObject::GetMaterialName() const -{ - if (m_pMaterial) - { - return m_pMaterial->GetName(); - } - return ""; -} - -////////////////////////////////////////////////////////////////////////// -void CBaseObject::SetMaterial(const QString& materialName) -{ - CMaterial* pMaterial = NULL; - CMaterialManager* pManager = GetIEditor()->GetMaterialManager(); - if (!materialName.isEmpty() && pManager != NULL) - { - pMaterial = pManager->LoadMaterial(materialName); - } - SetMaterial(pMaterial); -} - ////////////////////////////////////////////////////////////////////////// void CBaseObject::SetMinSpec(uint32 nSpec, bool bSetChildren) { diff --git a/Code/Sandbox/Editor/Objects/BaseObject.h b/Code/Sandbox/Editor/Objects/BaseObject.h index d62e0bed5f..44df1e5757 100644 --- a/Code/Sandbox/Editor/Objects/BaseObject.h +++ b/Code/Sandbox/Editor/Objects/BaseObject.h @@ -35,7 +35,6 @@ class CUndoBaseObject; class CObjectManager; class CGizmo; class CObjectArchive; -class CMaterial; class CEdGeometry; struct SSubObjSelectionModifyContext; struct SRayHitInfo; @@ -135,13 +134,6 @@ enum ObjectEditFlags OBJECT_COLLAPSE_OBJECTPANEL = 0x004 }; -/////////////////////////////////////////////////////////////////////////// -enum MaterialChangeFlags -{ - MATERIALCHANGE_SURFACETYPE = 0x001, - MATERIALCHANGE_ALL = 0xFFFFFFFF, -}; - ////////////////////////////////////////////////////////////////////////// //! Return values from CBaseObject::MouseCreateCallback method. enum MouseCreateResult @@ -554,22 +546,6 @@ public: //! Remove event listener callback. void RemoveEventListener(EventListener* listener); - ////////////////////////////////////////////////////////////////////////// - //! Material handling for this base object. - //! Override in derived classes. - ////////////////////////////////////////////////////////////////////////// - //! Assign new material to this object. - virtual void SetMaterial(CMaterial* mtl); - //! Assign new material to this object as a material name. - virtual void SetMaterial(const QString& materialName); - //! Get assigned material for this object. - virtual CMaterial* GetMaterial() const { return m_pMaterial; }; - // Get actual rendering material for this object. - virtual CMaterial* GetRenderMaterial() const { return m_pMaterial; }; - // Get the material name. Even though the material pointer is null, the material name can exist separately. - virtual QString GetMaterialName() const; - virtual void OnMaterialChanged([[maybe_unused]] MaterialChangeFlags change) {} - ////////////////////////////////////////////////////////////////////////// //! Analyze errors for this object. virtual void Validate(IErrorReport* report); @@ -861,9 +837,6 @@ private: //! Pointer to parent node. mutable CBaseObject* m_parent; - //! Material of this object. - CMaterial* m_pMaterial; - AABB m_worldBounds; // The transform delegate diff --git a/Code/Sandbox/Editor/Objects/EntityObject.cpp b/Code/Sandbox/Editor/Objects/EntityObject.cpp index 82d45f8ae5..0b2627091c 100644 --- a/Code/Sandbox/Editor/Objects/EntityObject.cpp +++ b/Code/Sandbox/Editor/Objects/EntityObject.cpp @@ -25,7 +25,6 @@ #include "Settings.h" #include "Viewport.h" #include "LineGizmo.h" -#include "Material/MaterialManager.h" #include "Include/IObjectManager.h" #include "Objects/ObjectManager.h" #include "ViewManager.h" @@ -1077,11 +1076,6 @@ XmlNodeRef CEntityObject::Export([[maybe_unused]] const QString& levelPath, XmlN objNode->setAttr("Name", GetName().toUtf8().data()); - if (GetMaterial()) - { - objNode->setAttr("Material", GetMaterial()->GetName().toUtf8().data()); - } - Vec3 pos = GetPos(), scale = GetScale(); Quat rotate = GetRotation(); @@ -1860,17 +1854,6 @@ void CEntityObject::OnLoadFailed() GetIEditor()->GetErrorReport()->ReportError(err); } -////////////////////////////////////////////////////////////////////////// -CMaterial* CEntityObject::GetRenderMaterial() const -{ - if (GetMaterial()) - { - return GetMaterial(); - } - - return NULL; -} - ////////////////////////////////////////////////////////////////////////// void CEntityObject::SetHelperScale(float scale) { @@ -1943,21 +1926,6 @@ void CEntityObject::OnContextMenu(QMenu* pMenu) CBaseObject::OnContextMenu(pMenu); } -////////////////////////////////////////////////////////////////////////// -void CEntityObject::OnMaterialChanged(MaterialChangeFlags change) -{ - if (change & MATERIALCHANGE_SURFACETYPE) - { - m_statObjValidator.Validate(0, GetRenderMaterial()); - } -} - -////////////////////////////////////////////////////////////////////////// -QString CEntityObject::GetTooltip() const -{ - return m_statObjValidator.GetDescription(); -} - ////////////////////////////////////////////////////////////////////////// IOpticsElementBasePtr CEntityObject::GetOpticsElement() { @@ -1979,7 +1947,6 @@ void CEntityObject::SetOpticsName(const QString& opticsFullName) { pLight->SetLensOpticsElement(NULL); } - SetMaterial(NULL); } } diff --git a/Code/Sandbox/Editor/Objects/EntityObject.h b/Code/Sandbox/Editor/Objects/EntityObject.h index 941094c755..a287cd8828 100644 --- a/Code/Sandbox/Editor/Objects/EntityObject.h +++ b/Code/Sandbox/Editor/Objects/EntityObject.h @@ -21,7 +21,6 @@ #include "IMovieSystem.h" #include "IEntityObjectListener.h" -#include "StatObjValidator.h" #include "Gizmo.h" #include "CryListenerSet.h" #include "StatObjBus.h" @@ -108,8 +107,6 @@ public: void SetEntityPropertyFloat(const char* name, float value); void SetEntityPropertyString(const char* name, const QString& value); - virtual QString GetTooltip() const; - virtual int MouseCreateCallback(CViewport* view, EMouseEvent event, QPoint& point, int flags); virtual void OnContextMenu(QMenu* menu); @@ -134,9 +131,6 @@ public: virtual void SetTransformDelegate(ITransformDelegate* pTransformDelegate) override; - virtual CMaterial* GetRenderMaterial() const; - virtual void OnMaterialChanged(MaterialChangeFlags change); - // Set attach flags and target enum EAttachmentType { @@ -405,8 +399,6 @@ protected: static float m_helperScale; - CStatObjValidator m_statObjValidator; - EAttachmentType m_attachmentType; bool m_bEnableReload; diff --git a/Code/Sandbox/Editor/Objects/ObjectLoader.cpp b/Code/Sandbox/Editor/Objects/ObjectLoader.cpp index 746b9e8c73..41f543a5a3 100644 --- a/Code/Sandbox/Editor/Objects/ObjectLoader.cpp +++ b/Code/Sandbox/Editor/Objects/ObjectLoader.cpp @@ -17,7 +17,6 @@ // Editor #include "Util/PakFile.h" -#include "Material/MaterialManager.h" #include "WaitProgress.h" #include "Include/IObjectManager.h" @@ -239,14 +238,6 @@ void CObjectArchive::ResolveObjects() obj.pObject->CreateGameObject(); - CMaterial* pMaterial = obj.pObject->GetRenderMaterial(); - CMaterialManager* pManager = GetIEditor()->GetMaterialManager(); - - if (pMaterial && pMaterial->GetMatInfo() && pManager) - { - pManager->OnRequestMaterial(pMaterial->GetMatInfo()); - } - // unset the current validator object because the wait Step // might generate unrelated errors m_pCurrentErrorReport->SetCurrentValidatorObject(nullptr); diff --git a/Code/Sandbox/Editor/Objects/SelectionGroup.cpp b/Code/Sandbox/Editor/Objects/SelectionGroup.cpp index b883b78e49..08abf8f763 100644 --- a/Code/Sandbox/Editor/Objects/SelectionGroup.cpp +++ b/Code/Sandbox/Editor/Objects/SelectionGroup.cpp @@ -20,7 +20,7 @@ // Editor #include "ViewManager.h" -#include "SurfaceInfoPicker.h" +#include "Include/IObjectManager.h" ////////////////////////////////////////////////////////////////////////// @@ -238,16 +238,6 @@ void CSelectionGroup::Move(const Vec3& offset, EMoveSelectionFlag moveFlag, [[ma } SRayHitInfo pickedInfo; - if (moveFlag == eMS_FollowGeometryPosNorm && bValidFollowGeometryMode) - { - CSurfaceInfoPicker::CExcludedObjects excludeObjects; - for (int i = 0; i < GetFilteredCount(); ++i) - { - excludeObjects.Add(GetFilteredObject(i)); - } - CSurfaceInfoPicker surfacePicker; - bValidFollowGeometryMode = surfacePicker.Pick(point, pickedInfo, &excludeObjects); - } if (moveFlag == eMS_FollowGeometryPosNorm) { diff --git a/Code/Sandbox/Editor/Objects/StatObjValidator.cpp b/Code/Sandbox/Editor/Objects/StatObjValidator.cpp deleted file mode 100644 index 85226fb236..0000000000 --- a/Code/Sandbox/Editor/Objects/StatObjValidator.cpp +++ /dev/null @@ -1,200 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "StatObjValidator.h" - -// Editor -#include "Material/Material.h" - - -CStatObjValidator::CStatObjValidator() - : m_isValid(true) -{ -} - -template -bool HasPrefix(const char* name, const char (&prefix)[size]) -{ - return _strnicmp(name, prefix, size - 1) == 0; -} - -struct SMeshMaterialIssue -{ - AZStd::string nodeName; - AZStd::string description; - int subMaterialIndex; - - SMeshMaterialIssue() - : subMaterialIndex(-1) - { - } - - SMeshMaterialIssue(const AZStd::string& name, const AZStd::string& description) - : nodeName(name) - , description(description) - , subMaterialIndex(-1) - { - } -}; - -static void ValidateMeshMaterials(std::vector* issues, IStatObj* pStatObj, CMaterial* pMaterial) -{ - _smart_ptr pIMaterial = 0; - if (pMaterial) - { - if (pMaterial->GetParent()) - { - pIMaterial = pMaterial->GetParent()->GetMatInfo(); - } - else - { - pIMaterial = pMaterial->GetMatInfo(); - } - } - - IIndexedMesh* pIndexedMesh = pStatObj->GetIndexedMesh(true); - if (pIndexedMesh) - { - int breakableSubmeshes = 0; - int nonbreakableSubmeshes = 0; - - int subsetCount = pIndexedMesh->GetSubSetCount(); - for (int i = 0; i < subsetCount; ++i) - { - const SMeshSubset& subset = pIndexedMesh->GetSubSet(i); - if (subset.nNumVerts == 0) - { - continue; - } - - // Check to see if the material uses multiple uv sets and if the vertex format has the same number of texCoord attributes - SShaderItem shaderItem = pIMaterial->GetShaderItem(i); - if (shaderItem.m_pShader) - { - size_t materialUVs = shaderItem.m_pShader->GetNumberOfUVSets(); - size_t meshUVs = subset.vertexFormat.GetAttributeUsageCount(AZ::Vertex::AttributeUsage::TexCoord); - if (materialUVs != meshUVs) - { - const char* meshName = pStatObj->GetRenderMesh() ? pStatObj->GetRenderMesh()->GetSourceName() : "unknown"; - AZStd::string errorMessage; - errorMessage = AZStd::string::format("Material '%s' sub-material %d with %zu uv set(s) was assigned to mesh '%s' with %zu uv set(s). ", pIMaterial->GetName(), i + 1, materialUVs, meshName, meshUVs); - - AZStd::string recommendedAction; - if (materialUVs < meshUVs) - { - recommendedAction = AZStd::string::format("If you do not intend to use %zu uv sets, remove the extra uv set(s) from the source mesh during the import process. Otherwise, consider checking the desired 'Use uv set 2 for...' shader gen params in the material editor.", meshUVs); - } - else - { - recommendedAction = AZStd::string::format("If you intend to use %zu uv sets, include the additional uv set(s) in the source mesh during the import process. Otherwise, consider unchecking the 'Use uv set 2 for...' shader gen params in the material editor.", materialUVs); - } - errorMessage += recommendedAction; - AZ_Warning("Material Editor", false, errorMessage.c_str()); - SMeshMaterialIssue issue(meshName, errorMessage); - issues->push_back(issue); - } - } - - _smart_ptr pSubMaterial = pIMaterial->GetSubMtl(subset.nMatID); - if (!pSubMaterial) - { - continue; - } - - if (size_t(subset.nMatID) > size_t(pMaterial->GetSubMaterialCount())) - { - continue; - } - - if (pSubMaterial->GetSurfaceType()->GetBreakable2DParams()) - { - ++breakableSubmeshes; - } - else - { - ++nonbreakableSubmeshes; - } - } - } - - - int subobjectCount = pStatObj->GetSubObjectCount(); - for (int i = 0; i < subobjectCount; ++i) - { - const IStatObj::SSubObject* subobject = pStatObj->GetSubObject(i); - if (subobject->pStatObj) - { - ValidateMeshMaterials(issues, subobject->pStatObj, pMaterial); - } - } -} - -void CStatObjValidator::Validate(IStatObj* statObj, CMaterial* editorMaterial) -{ - m_description = QString(); - m_isValid = true; - - _smart_ptr pIMaterial = 0; - if (editorMaterial) - { - if (editorMaterial->GetParent()) - { - pIMaterial = editorMaterial->GetParent()->GetMatInfo(); - } - else - { - pIMaterial = editorMaterial->GetMatInfo(); - } - } - - if (statObj && editorMaterial) - { - std::vector issues; - ValidateMeshMaterials(&issues, statObj, editorMaterial); - - if (!issues.empty()) - { - m_isValid = false; - } - - for (size_t i = 0; i < issues.size(); ++i) - { - const SMeshMaterialIssue& issue = issues[i]; - if (!m_description.isEmpty()) - { - m_description += "\n"; - } - if (!issue.nodeName.empty()) - { - m_description += "Node "; - m_description += issue.nodeName.c_str(); - m_description += ":"; - } - if (issue.subMaterialIndex >= 0) - { - m_description += QStringLiteral("SubMaterial %1:").arg(issue.subMaterialIndex + 1); - } - if (!issue.nodeName.empty() || issue.subMaterialIndex >= 0) - { - m_description += "\n "; - } - if (!issue.description.empty()) - { - m_description += issue.description.c_str(); - } - } - } -} - diff --git a/Code/Sandbox/Editor/Objects/StatObjValidator.h b/Code/Sandbox/Editor/Objects/StatObjValidator.h deleted file mode 100644 index 40145e90c5..0000000000 --- a/Code/Sandbox/Editor/Objects/StatObjValidator.h +++ /dev/null @@ -1,32 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// This class is supposed to validate CGF with assigned material. -// Some of the asset issues may be diagnosed only when SurfaceType is known. - -#pragma once - -class CRYEDIT_API CStatObjValidator -{ -public: - CStatObjValidator(); - - void Validate(IStatObj* statObj, CMaterial* editorMaterial); - bool IsValid() const { return m_isValid; } - - QString GetDescription() const { return m_description; } -private: - bool m_isValid; - QString m_description; -}; - diff --git a/Code/Sandbox/Editor/RenderHelpers/AxisHelperExtended.cpp b/Code/Sandbox/Editor/RenderHelpers/AxisHelperExtended.cpp deleted file mode 100644 index cee7f0f716..0000000000 --- a/Code/Sandbox/Editor/RenderHelpers/AxisHelperExtended.cpp +++ /dev/null @@ -1,213 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "AxisHelperExtended.h" - -#include "CryPhysicsDeprecation.h" - -// Editor -#include "Include/IDisplayViewport.h" -#include "SurfaceInfoPicker.h" -#include "Objects/DisplayContext.h" -#include "Objects/SelectionGroup.h" -#include "Util/fastlib.h" - - -////////////////////////////////////////////////////////////////////////// -// Helper Extended Axis object. -////////////////////////////////////////////////////////////////////////// -CAxisHelperExtended::CAxisHelperExtended() - : m_matrix(IDENTITY) - , m_vPos(ZERO) - , m_pCurObject(0) - , m_dwLastUpdateTime(0) - , m_fMaxDist(100.0f) -{ -} - -////////////////////////////////////////////////////////////////////////// -void CAxisHelperExtended::DrawAxes(DisplayContext& dc, const Matrix34& matrix, bool bUsePhysicalProxy) -{ - const DWORD dwUpdateTime = 2000; // 2 sec - CSelectionGroup* pSel = GetIEditor()->GetSelection(); - int numSels = pSel->GetCount(); - - if (numSels == 0) - { - return; - } - - CBaseObject* pCurObject = pSel->GetObject(numSels - 1); // get just last object for simple check - - // Add current selection to the elements to be skipped - CRY_PHYSICS_REPLACEMENT_ASSERT(); - - Vec3 x = Vec3(1, 0, 0); - Vec3 y = Vec3(0, 1, 0); - Vec3 z = Vec3(0, 0, 1); - - Vec3 colR = Vec3(1, 0, 0); - Vec3 colG = Vec3(0, 1, 0); - Vec3 colB = Vec3(0, 0.8f, 1); - - m_vPos = matrix.GetTranslation(); - - Vec3 vDirX = (matrix * x - m_vPos); - Vec3 vDirY = (matrix * y - m_vPos); - Vec3 vDirZ = (matrix * z - m_vPos); - vDirX.Normalize(); - vDirY.Normalize(); - vDirZ.Normalize(); - - if ( - m_pCurObject != pCurObject || - GetTickCount() - m_dwLastUpdateTime > dwUpdateTime || - !Matrix34::IsEquivalent(m_matrix, matrix) - ) - { - Vec3 outTmp; - AABB aabb(m_vPos, m_fMaxDist); - m_objects.clear(); - CBaseObjectsArray allObjects; - GetIEditor()->GetObjectManager()->GetObjects(allObjects); - - for (size_t i = 0, n = allObjects.size(); i < n; ++i) - { - CBaseObject* pObject = allObjects[i]; - if (pObject->IsSelected() || !pObject->GetEngineNode()) - { - continue; - } - - AABB aabbObj; - pObject->GetBoundBox(aabbObj); - - if (!Intersect::Ray_AABB(m_vPos, vDirX, aabbObj, outTmp) - && !Intersect::Ray_AABB(m_vPos, vDirY, aabbObj, outTmp) - && !Intersect::Ray_AABB(m_vPos, vDirZ, aabbObj, outTmp) - && !Intersect::Ray_AABB(m_vPos, -vDirX, aabbObj, outTmp) - && !Intersect::Ray_AABB(m_vPos, -vDirY, aabbObj, outTmp) - && !Intersect::Ray_AABB(m_vPos, -vDirZ, aabbObj, outTmp)) - { - continue; - } - - if (aabb.IsIntersectBox(aabbObj)) - { - m_objects.push_back(pObject); - } - } - m_dwLastUpdateTime = GetTickCount(); - } - m_pCurObject = pCurObject; - m_matrix = matrix; - - DrawAxis(dc, vDirX, z, colR, bUsePhysicalProxy); - DrawAxis(dc, vDirY, z, colG, bUsePhysicalProxy); - DrawAxis(dc, vDirZ, x, colB, bUsePhysicalProxy); - DrawAxis(dc, -vDirX, z, colR, bUsePhysicalProxy); - DrawAxis(dc, -vDirY, z, colG, bUsePhysicalProxy); - DrawAxis(dc, -vDirZ, x, colB, bUsePhysicalProxy); -} - - -////////////////////////////////////////////////////////////////////////// -void CAxisHelperExtended::DrawAxis(DisplayContext& dc, const Vec3& vDir, const Vec3& vUpAxis, const Vec3& col, bool bUsePhysicalProxy) -{ - AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Editor); - - const float fBallSize = 0.005f; - const float fTextSize = 1.4f; - - float fDist = m_fMaxDist + 1.0f; - size_t objectsSize = m_objects.size(); - for (size_t i = 0; i < objectsSize; ++i) - { - CBaseObject* pObject = m_objects[i]; - if (pObject->CheckFlags(OBJFLAG_DELETED)) - { - continue; - } - - SRayHitInfo hitInfo; - if (pObject->IntersectRayMesh(m_vPos, vDir, hitInfo)) - { - Vec3 newP = pObject->GetWorldTM().TransformPoint(hitInfo.vHitPos); - float fNewDist = (newP - m_vPos).GetLength(); - if (fDist > fNewDist) - { - fDist = fNewDist; - } - } - } - - if (bUsePhysicalProxy) - { - CRY_PHYSICS_REPLACEMENT_ASSERT(); - } - else - { - CSurfaceInfoPicker picker; - m_objectsForPicker.assign(m_objects.begin(), m_objects.end()); - picker.SetObjects(&m_objectsForPicker); - SRayHitInfo hitInfo; - if (picker.Pick(m_vPos, fDist * vDir, hitInfo, NULL, CSurfaceInfoPicker::ePOG_All)) - { - fDist = hitInfo.fDistance; - } - picker.SetObjects(0); - } - - if (fDist < m_fMaxDist) - { - Vec3 p = m_vPos + vDir * fDist; - - dc.SetColor(col); - dc.DrawLine(m_vPos, p); - float fScreenScale = dc.view->GetScreenScaleFactor(p); - dc.DrawBall(p, fBallSize * fScreenScale); - QString label; - label = QString::number(fDist, 'f', 2); - dc.DrawTextOn2DBox((p + m_vPos) * 0.5f, label.toUtf8().data(), fTextSize, col, ColorF(0.0f, 0.0f, 0.0f, 0.7f)); - - Vec3 vUp = (m_matrix * vUpAxis - m_vPos); - vUp.Normalize(); - - Vec3 u = vUp; - Vec3 v = vDir ^ vUp; - float fPlaneSize = fDist / 4.0f; - float alphaMax = 1.0f, alphaMin = 0.0f; - ColorF colAlphaMin = ColorF(col.x, col.y, col.z, alphaMin); - - float fStepSize = dc.view->GetGridStep(); - const int MIN_STEP_COUNT = 5; - const int MAX_STEP_COUNT = 20; - int nSteps = std::min(std::max(FloatToIntRet(fPlaneSize / fStepSize), MIN_STEP_COUNT), MAX_STEP_COUNT); - float fGridSize = nSteps * fStepSize; - - for (int i = -nSteps; i <= nSteps; ++i) - { - Vec3 stepV = v * (fStepSize * i); - Vec3 stepU = u * (fStepSize * i); - ColorF colCurAlpha = ColorF(col.x, col.y, col.z, alphaMax - fabsf(float(i) / float(nSteps)) * (alphaMax - alphaMin)); - // Draw u lines. - dc.DrawLine(p + stepV, p + u * fGridSize + stepV, colCurAlpha, colAlphaMin); - dc.DrawLine(p + stepV, p - u * fGridSize + stepV, colCurAlpha, colAlphaMin); - // Draw v lines. - dc.DrawLine(p + stepU, p + v * fGridSize + stepU, colCurAlpha, colAlphaMin); - dc.DrawLine(p + stepU, p - v * fGridSize + stepU, colCurAlpha, colAlphaMin); - } - } -} diff --git a/Code/Sandbox/Editor/RenderHelpers/AxisHelperExtended.h b/Code/Sandbox/Editor/RenderHelpers/AxisHelperExtended.h deleted file mode 100644 index 42a1c66b9c..0000000000 --- a/Code/Sandbox/Editor/RenderHelpers/AxisHelperExtended.h +++ /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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_RENDERHELPERS_AXISHELPEREXTENDED_H -#define CRYINCLUDE_EDITOR_RENDERHELPERS_AXISHELPEREXTENDED_H -#pragma once - -#include "Objects/BaseObject.h" -#include "Include/IObjectManager.h" - -struct DisplayContext; -struct HitContext; - -class CAxisHelperExtended -{ -public: - CAxisHelperExtended(); - void DrawAxes(DisplayContext& dc, const Matrix34& matrix, bool bUsePhysicalProxy); - -private: - void DrawAxis(DisplayContext& dc, const Vec3& vDirAxis, const Vec3& vUpAxis, const Vec3& col, bool bUsePhysicalProxy); - -private: - Matrix34 m_matrix; - Vec3 m_vPos; - std::vector m_objects; - CBaseObjectsArray m_objectsForPicker; - CBaseObject* m_pCurObject; - DWORD m_dwLastUpdateTime; - - float m_fMaxDist; -}; - -#endif // CRYINCLUDE_EDITOR_RENDERHELPERS_AXISHELPEREXTENDED_H diff --git a/Code/Sandbox/Editor/Resource.h b/Code/Sandbox/Editor/Resource.h index 78a9855d71..51f9b1f3e9 100644 --- a/Code/Sandbox/Editor/Resource.h +++ b/Code/Sandbox/Editor/Resource.h @@ -95,9 +95,6 @@ #define ID_CHANGEMOVESPEED_INCREASE 32928 #define ID_CHANGEMOVESPEED_DECREASE 32929 #define ID_CHANGEMOVESPEED_CHANGESTEP 32930 -#define ID_MATERIAL_ASSIGNCURRENT 32933 -#define ID_MATERIAL_RESETTODEFAULT 32934 -#define ID_MATERIAL_GETMATERIAL 32935 #define ID_PHYSICS_GETPHYSICSSTATE 32937 #define ID_PHYSICS_RESETPHYSICSSTATE 32938 #define ID_GAME_SYNCPLAYER 32941 diff --git a/Code/Sandbox/Editor/SurfaceInfoPicker.cpp b/Code/Sandbox/Editor/SurfaceInfoPicker.cpp deleted file mode 100644 index 5ef20dcec0..0000000000 --- a/Code/Sandbox/Editor/SurfaceInfoPicker.cpp +++ /dev/null @@ -1,535 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "SurfaceInfoPicker.h" - -// AzToolsFramework -#include - -// Editor -#include "Material/MaterialManager.h" -#include "Objects/EntityObject.h" -#include "Viewport.h" -#include "QtViewPane.h" - -// ComponentEntityEditorPlugin -#include "Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.h" - -static const float kEnoughFarDistance(5000.0f); - -CSurfaceInfoPicker::CSurfaceInfoPicker() - : m_pObjects(NULL) - , m_pSetObjects(NULL) - , m_PickOption(0) -{ - m_pActiveView = GetIEditor()->GetActiveView(); -} - -bool CSurfaceInfoPicker::PickByAABB(const QPoint& point, [[maybe_unused]] int nFlag, IDisplayViewport* pView, CExcludedObjects* pExcludedObjects, std::vector* pOutObjects) -{ - GetIEditor()->GetObjectManager()->GetObjects(m_objects); - - Vec3 vWorldRaySrc, vWorldRayDir; - m_pActiveView->ViewToWorldRay(point, vWorldRaySrc, vWorldRayDir); - vWorldRaySrc = vWorldRaySrc + vWorldRayDir * 0.1f; - vWorldRayDir = vWorldRayDir * kEnoughFarDistance; - - bool bPicked = false; - - for (int i = 0, iCount(m_objects.size()); i < iCount; ++i) - { - if (pExcludedObjects && pExcludedObjects->Contains(m_objects[i])) - { - continue; - } - - AABB worldObjAABB; - m_objects[i]->GetBoundBox(worldObjAABB); - - if (pView) - { - float fScreenFactor = pView->GetScreenScaleFactor(m_objects[i]->GetPos()); - worldObjAABB.Expand(0.01f * Vec3(fScreenFactor, fScreenFactor, fScreenFactor)); - } - - Vec3 vHitPos; - if (Intersect::Ray_AABB(vWorldRaySrc, vWorldRayDir, worldObjAABB, vHitPos)) - { - if ((vHitPos - vWorldRaySrc).GetNormalized().Dot(vWorldRayDir) > 0 || worldObjAABB.IsContainPoint(vHitPos)) - { - if (pOutObjects) - { - pOutObjects->push_back(m_objects[i]); - } - bPicked = true; - } - } - } - - return bPicked; -} - -bool CSurfaceInfoPicker::PickImpl(const QPoint& point, - _smart_ptr* ppOutLastMaterial, - SRayHitInfo& outHitInfo, - CExcludedObjects* pExcludedObjects, - int nFlag) -{ - Vec3 vWorldRaySrc; - Vec3 vWorldRayDir; - if (!m_pActiveView) - { - m_pActiveView = GetIEditor()->GetActiveView(); - } - m_pActiveView->ViewToWorldRay(point, vWorldRaySrc, vWorldRayDir); - vWorldRaySrc = vWorldRaySrc + vWorldRayDir * 0.1f; - vWorldRayDir = vWorldRayDir * kEnoughFarDistance; - - return PickImpl(vWorldRaySrc, vWorldRayDir, ppOutLastMaterial, outHitInfo, pExcludedObjects, nFlag); -} - -bool CSurfaceInfoPicker::PickImpl(const Vec3& vWorldRaySrc, const Vec3& vWorldRayDir, - _smart_ptr* ppOutLastMaterial, - SRayHitInfo& outHitInfo, - CExcludedObjects* pExcludedObjects, - int nFlag) -{ - memset(&outHitInfo, 0, sizeof(outHitInfo)); - outHitInfo.fDistance = kEnoughFarDistance; - - if (m_pSetObjects) - { - m_pObjects = m_pSetObjects; - } - else - { - GetIEditor()->GetObjectManager()->GetObjects(m_objects); - m_pObjects = &m_objects; - } - - if (pExcludedObjects) - { - m_ExcludedObjects = *pExcludedObjects; - } - else - { - m_ExcludedObjects.Clear(); - } - - m_pPickedObject = NULL; - - if (nFlag & ePOG_Entity) - { - FindNearestInfoFromEntities(vWorldRaySrc, vWorldRayDir, ppOutLastMaterial, outHitInfo); - } - - if (!m_pSetObjects) - { - m_objects.clear(); - } - - m_ExcludedObjects.Clear(); - - return outHitInfo.fDistance < kEnoughFarDistance; -} - -void CSurfaceInfoPicker::FindNearestInfoFromEntities( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - _smart_ptr* pOutLastMaterial, - SRayHitInfo& outHitInfo) const -{ - for (size_t i = 0; i < m_pObjects->size(); ++i) - { - CBaseObject* object((*m_pObjects)[i]); - - if (object == nullptr - || !qobject_cast(object) - || object->IsHidden() - || IsFrozen(object) - || m_ExcludedObjects.Contains(object) - ) - { - continue; - } - - CEntityObject* entityObject = static_cast(object); - - // If a legacy entity doesn't have a material override, we'll get the default material for that statObj - _smart_ptr statObjDefaultMaterial = nullptr; - // And in some cases the material we want does comes from RayIntersection(), and we will skip AssignObjectMaterial(). - _smart_ptr pickedMaterial = nullptr; - - bool hit = false; - - // entityObject is a component entity... - if (entityObject->GetType() == OBJTYPE_AZENTITY) - { - AZ::EntityId id; - AzToolsFramework::ComponentEntityObjectRequestBus::EventResult(id, entityObject, &AzToolsFramework::ComponentEntityObjectRequestBus::Events::GetAssociatedEntityId); - - // If the entity has an ActorComponent or another component that overrides RenderNodeRequestBus, it will hit here - if (!hit) - { - // There might be multiple components with render nodes on the same entity - // This will get the highest priority one, as determined by RenderNodeRequests::GetRenderNodeRequestBusOrder - IRenderNode* renderNode = entityObject->GetEngineNode(); - - // If the renderNode exists and is physicalized, it will hit here - hit = RayIntersection_IRenderNode(vWorldRaySrc, vWorldRayDir, renderNode, &pickedMaterial, object->GetWorldTM(), outHitInfo); - if (!hit) - { - // If the renderNode is not physicalized, such as an actor component, but still exists and has a valid material we might want to pick - if (renderNode && renderNode->GetMaterial()) - { - // Do a hit test with anything in this entity that has overridden EditorComponentSelectionRequestsBus - CComponentEntityObject* componentEntityObject = static_cast(entityObject); - HitContext hc; - hc.raySrc = vWorldRaySrc; - hc.rayDir = vWorldRayDir; - bool intersects = componentEntityObject->HitTest(hc); - - if (intersects) - { - // If the distance is closer than the nearest distance so far - if (hc.dist < outHitInfo.fDistance) - { - hit = true; - outHitInfo.vHitPos = hc.raySrc + hc.rayDir * hc.dist; - outHitInfo.fDistance = hc.dist; - // We don't get material/sub-material information back from HitTest, so just use the material from the render node - pickedMaterial = renderNode->GetMaterial(); - outHitInfo.nHitMatID = 0; - // We don't get normal information back from HitTest, so just orient the selection disk towards the camera - outHitInfo.vHitNormal = vWorldRayDir.normalized(); - } - } - } - } - } - } - - if (hit) - { - if(pickedMaterial) - { - AssignMaterial(pickedMaterial, outHitInfo, pOutLastMaterial); - } - else - { - if (object->GetMaterial()) - { - // If the entity has a material override, assign the object material - AssignObjectMaterial(object, outHitInfo, pOutLastMaterial); - } - else - { - // Otherwise assign the default material for that object - AssignMaterial(statObjDefaultMaterial, outHitInfo, pOutLastMaterial); - } - } - - m_pPickedObject = object; - } - } -} - -bool CSurfaceInfoPicker::RayIntersection_CBaseObject( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - CBaseObject* pBaseObject, - _smart_ptr* pOutLastMaterial, - SRayHitInfo& outHitInfo) -{ - if (pBaseObject == NULL) - { - return false; - } - IRenderNode* pRenderNode(pBaseObject->GetEngineNode()); - if (pRenderNode == NULL) - { - return false; - } - IStatObj* pStatObj(pRenderNode->GetEntityStatObj()); - if (pStatObj == NULL) - { - return false; - } - return RayIntersection(vWorldRaySrc, vWorldRayDir, pRenderNode, pStatObj, pBaseObject->GetWorldTM(), outHitInfo, pOutLastMaterial); -} - -bool CSurfaceInfoPicker::RayIntersection( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - IRenderNode* pRenderNode, - IStatObj* pStatObj, - const Matrix34A& WorldTM, - SRayHitInfo& outHitInfo, - _smart_ptr* ppOutLastMaterial) -{ - SRayHitInfo hitInfo; - bool bRayIntersection = false; - _smart_ptr pMaterial(NULL); - - bRayIntersection = RayIntersection_IStatObj(vWorldRaySrc, vWorldRayDir, pStatObj, &pMaterial, WorldTM, hitInfo); - if (!bRayIntersection) - { - bRayIntersection = RayIntersection_IRenderNode(vWorldRaySrc, vWorldRayDir, pRenderNode, &pMaterial, WorldTM, hitInfo); - } - - if (bRayIntersection) - { - hitInfo.fDistance = vWorldRaySrc.GetDistance(hitInfo.vHitPos); - if (hitInfo.fDistance < outHitInfo.fDistance) - { - if (ppOutLastMaterial) - { - *ppOutLastMaterial = pMaterial; - } - memcpy(&outHitInfo, &hitInfo, sizeof(SRayHitInfo)); - outHitInfo.vHitNormal.Normalize(); - return true; - } - } - return false; -} - -bool CSurfaceInfoPicker::RayIntersection_IStatObj( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - IStatObj* pStatObj, - _smart_ptr* ppOutLastMaterial, - const Matrix34A& worldTM, - SRayHitInfo& outHitInfo) -{ - if (pStatObj == NULL) - { - return false; - } - - Vec3 localRaySrc; - Vec3 localRayDir; - if (!RayWorldToLocal(worldTM, vWorldRaySrc, vWorldRayDir, localRaySrc, localRayDir)) - { - return false; - } - - // the outHitInfo contains information about the previous closest hit and should not be cleared / replaced unless you have a better hit! - // all of the intersection functions called (such as statobj's RayIntersection) only modify the hit info if it actually hits it closer than the current distance of the last hit. - - outHitInfo.inReferencePoint = localRaySrc; - outHitInfo.inRay = Ray(localRaySrc, localRayDir); - outHitInfo.bInFirstHit = false; - outHitInfo.bUseCache = false; - - _smart_ptr hitMaterial = nullptr; - - Vec3 hitPosOnAABB; - if (Intersect::Ray_AABB(outHitInfo.inRay, pStatObj->GetAABB(), hitPosOnAABB) == 0x00) - { - return false; - } - - if (pStatObj->RayIntersection(outHitInfo)) - { - if (outHitInfo.fDistance < 0) - { - return false; - } - outHitInfo.vHitPos = worldTM.TransformPoint(outHitInfo.vHitPos); - outHitInfo.vHitNormal = worldTM.GetTransposed().GetInverted().TransformVector(outHitInfo.vHitNormal); - - // we need to set nHitSurfaceID anyway - so we need to do this regardless of whether the caller - // has asked for detailed material info by passing in a non-null ppOutLastMaterial - hitMaterial = pStatObj->GetMaterial(); - - if (hitMaterial) - { - if (outHitInfo.nHitMatID >= 0) - { - if (hitMaterial->GetSubMtlCount() > 0 && outHitInfo.nHitMatID < hitMaterial->GetSubMtlCount()) - { - _smart_ptr subMaterial = hitMaterial->GetSubMtl(outHitInfo.nHitMatID); - if (subMaterial) - { - hitMaterial = subMaterial; - } - } - } - outHitInfo.nHitSurfaceID = hitMaterial->GetSurfaceTypeId(); - } - - if ((ppOutLastMaterial) && (hitMaterial)) - { - *ppOutLastMaterial = hitMaterial; - } - - return true; - } - - return outHitInfo.fDistance < kEnoughFarDistance; -} - -#if defined(USE_GEOM_CACHES) -bool CSurfaceInfoPicker::RayIntersection_IGeomCacheRenderNode( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - IGeomCacheRenderNode* pGeomCacheRenderNode, - _smart_ptr* ppOutLastMaterial, - [[maybe_unused]] const Matrix34A& worldTM, - SRayHitInfo& outHitInfo) -{ - if (!pGeomCacheRenderNode) - { - return false; - } - - SRayHitInfo newHitInfo = outHitInfo; - newHitInfo.inReferencePoint = vWorldRaySrc; - newHitInfo.inRay = Ray(vWorldRaySrc, vWorldRayDir); - newHitInfo.bInFirstHit = false; - newHitInfo.bUseCache = false; - - if (pGeomCacheRenderNode->RayIntersection(newHitInfo)) - { - if (newHitInfo.fDistance < 0 || newHitInfo.fDistance > kEnoughFarDistance || (outHitInfo.fDistance != 0 && newHitInfo.fDistance > outHitInfo.fDistance)) - { - return false; - } - - // Only override outHitInfo if the new hit is closer than the original hit - outHitInfo = newHitInfo; - if (ppOutLastMaterial) - { - _smart_ptr pMaterial = pGeomCacheRenderNode->GetMaterial(); - if (pMaterial) - { - *ppOutLastMaterial = pMaterial; - if (outHitInfo.nHitMatID >= 0) - { - if (pMaterial->GetSubMtlCount() > 0 && outHitInfo.nHitMatID < pMaterial->GetSubMtlCount()) - { - *ppOutLastMaterial = pMaterial->GetSubMtl(outHitInfo.nHitMatID); - } - } - } - } - return true; - } - - return false; -} -#endif - -bool CSurfaceInfoPicker::RayIntersection_IRenderNode( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - IRenderNode* pRenderNode, - _smart_ptr* pOutLastMaterial, - [[maybe_unused]] const Matrix34A& WorldTM, - SRayHitInfo& outHitInfo) -{ - if (pRenderNode == NULL) - { - return false; - } - - AZ_UNUSED(vWorldRaySrc) - AZ_UNUSED(vWorldRayDir) - AZ_UNUSED(pRenderNode) - AZ_UNUSED(pOutLastMaterial) - AZ_UNUSED(WorldTM) - AZ_UNUSED(outHitInfo) - return false; -} - -bool CSurfaceInfoPicker::RayWorldToLocal( - const Matrix34A& WorldTM, - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - Vec3& outRaySrc, - Vec3& outRayDir) -{ - if (!WorldTM.IsValid()) - { - return false; - } - Matrix34A invertedM(WorldTM.GetInverted()); - if (!invertedM.IsValid()) - { - return false; - } - outRaySrc = invertedM.TransformPoint(vWorldRaySrc); - outRayDir = invertedM.TransformVector(vWorldRayDir).GetNormalized(); - return true; -} - -bool CSurfaceInfoPicker::IsMaterialValid(CMaterial* pMaterial) -{ - if (pMaterial == NULL) - { - return false; - } - return !(pMaterial->GetMatInfo()->GetFlags() & MTL_FLAG_NODRAW); -} - -void CSurfaceInfoPicker::AssignObjectMaterial(CBaseObject* pObject, const SRayHitInfo& outHitInfo, _smart_ptr* pOutMaterial) -{ - CMaterial* material = pObject->GetMaterial(); - if (material) - { - if (material->GetMatInfo()) - { - if (pOutMaterial) - { - *pOutMaterial = material->GetMatInfo(); - if (*pOutMaterial) - { - if (outHitInfo.nHitMatID >= 0 && (*pOutMaterial)->GetSubMtlCount() > 0 && outHitInfo.nHitMatID < (*pOutMaterial)->GetSubMtlCount()) - { - *pOutMaterial = (*pOutMaterial)->GetSubMtl(outHitInfo.nHitMatID); - } - } - } - } - } -} - -void CSurfaceInfoPicker::AssignMaterial(_smart_ptr pMaterial, const SRayHitInfo& outHitInfo, _smart_ptr* pOutMaterial) -{ - if (pOutMaterial) - { - *pOutMaterial = pMaterial; - if (*pOutMaterial) - { - if (outHitInfo.nHitMatID >= 0 && (*pOutMaterial)->GetSubMtlCount() > 0 && outHitInfo.nHitMatID < (*pOutMaterial)->GetSubMtlCount()) - { - *pOutMaterial = (*pOutMaterial)->GetSubMtl(outHitInfo.nHitMatID); - } - } - } -} - -void CSurfaceInfoPicker::SetActiveView(IDisplayViewport* view) -{ - if (view) - { - m_pActiveView = view; - } - else - { - m_pActiveView = GetIEditor()->GetActiveView(); - } -} diff --git a/Code/Sandbox/Editor/SurfaceInfoPicker.h b/Code/Sandbox/Editor/SurfaceInfoPicker.h deleted file mode 100644 index 110408d558..0000000000 --- a/Code/Sandbox/Editor/SurfaceInfoPicker.h +++ /dev/null @@ -1,220 +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. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_SURFACEINFOPICKER_H -#define CRYINCLUDE_EDITOR_SURFACEINFOPICKER_H - -#pragma once - -#include "Include/IObjectManager.h" -#include "Objects/BaseObject.h" - -class CKDTree; -struct IDisplayViewport; - -////////////////////////////////////////////////////////////////////////// -class SANDBOX_API CSurfaceInfoPicker -{ -public: - - CSurfaceInfoPicker(); - - class CExcludedObjects - { - public: - - CExcludedObjects(){} - ~CExcludedObjects(){} - CExcludedObjects(const CExcludedObjects& excluded) - { - objects = excluded.objects; - } - - void Add(CBaseObject* pObject) - { - objects.insert(pObject); - } - - void Clear() - { - objects.clear(); - } - - bool Contains(CBaseObject* pObject) const - { - return objects.find(pObject) != objects.end(); - } - - private: - std::set objects; - }; - - enum EPickedObjectGroup - { - ePOG_Entity = BIT(1), - ePOG_All = ePOG_Entity, - }; - - enum EPickOption - { - ePickOption_IncludeFrozenObject = BIT(0), - }; - - void SetPickOptionFlag(int nFlag) { m_PickOption = nFlag; } - -public: - - bool Pick(const Vec3& vWorldRaySrc, const Vec3& vWorldRayDir, - _smart_ptr& ppOutLastMaterial, - SRayHitInfo& outHitInfo, - CExcludedObjects* pExcludedObjects = NULL, - int nFlag = ePOG_All) - { - return PickImpl(vWorldRaySrc, vWorldRayDir, &ppOutLastMaterial, outHitInfo, pExcludedObjects, nFlag); - } - - bool Pick(const Vec3& vWorldRaySrc, const Vec3& vWorldRayDir, - SRayHitInfo& outHitInfo, - CExcludedObjects* pExcludedObjects = NULL, - int nFlag = ePOG_All) - { - return PickImpl(vWorldRaySrc, vWorldRayDir, NULL, outHitInfo, pExcludedObjects, nFlag); - } - - bool Pick(const QPoint& point, - SRayHitInfo& outHitInfo, - CExcludedObjects* pExcludedObjects = NULL, - int nFlag = ePOG_All) - { - return PickImpl(point, NULL, outHitInfo, pExcludedObjects, nFlag); - } - - bool Pick(const QPoint& point, - _smart_ptr& ppOutLastMaterial, - SRayHitInfo& outHitInfo, - CExcludedObjects* pExcludedObjects = NULL, - int nFlag = ePOG_All) - { - return PickImpl(point, &ppOutLastMaterial, outHitInfo, pExcludedObjects, nFlag); - } - - bool PickByAABB(const QPoint& point, int nFlag = ePOG_All, IDisplayViewport* pView = NULL, CExcludedObjects* pExcludedObjects = NULL, std::vector* pOutObjects = NULL); - - void SetObjects(CBaseObjectsArray* pSetObjects) { m_pSetObjects = pSetObjects; } - - CBaseObjectPtr GetPickedObject() - { - return m_pPickedObject; - } - - void SetActiveView(IDisplayViewport* view); - -public: - - static bool RayWorldToLocal( - const Matrix34A& WorldTM, - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - Vec3& outRaySrc, - Vec3& outRayDir); - -private: - - bool IsFrozen(CBaseObject* pBaseObject) const - { - return !(m_PickOption & ePickOption_IncludeFrozenObject) && pBaseObject->IsFrozen(); - } - - bool PickImpl(const QPoint& point, - _smart_ptr* ppOutLastMaterial, - SRayHitInfo& outHitInfo, - CExcludedObjects* pExcludedObjects = NULL, - int nFlag = ePOG_All); - - bool PickImpl(const Vec3& vWorldRaySrc, const Vec3& vWorldRayDir, - _smart_ptr* ppOutLastMaterial, - SRayHitInfo& outHitInfo, - CExcludedObjects* pExcludedObjects = NULL, - int nFlag = ePOG_All); - - void FindNearestInfoFromEntities( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - _smart_ptr* ppOutLastMaterial, - SRayHitInfo& outHitInfo) const; - - /// Detect ray intersection with a IRenderNode or IStatObj. - /// But only if the intersection is closer than the one already in outHitInfo. - static bool RayIntersection( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - IRenderNode* pRenderNode, - IStatObj* pStatObj, - const Matrix34A& WorldTM, - SRayHitInfo& outHitInfo, - _smart_ptr* ppOutLastMaterial); - - /// Detect ray intersection with a IStatObj - static bool RayIntersection_IStatObj( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - IStatObj* pStatObj, - _smart_ptr* ppOutLastMaterial, - const Matrix34A& WorldTM, - SRayHitInfo& outHitInfo); - - /// Detect ray intersection with a IGeomCacheRenderNode - static bool RayIntersection_IGeomCacheRenderNode( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - IGeomCacheRenderNode* pGeomCacheRenderNode, - _smart_ptr* ppOutLastMaterial, - const Matrix34A& worldTM, - SRayHitInfo& outHitInfo); - - /// Detect ray intersection with a IRenderNode - static bool RayIntersection_IRenderNode( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - IRenderNode* pRenderNode, - _smart_ptr* ppOutLastMaterial, - const Matrix34A& WorldTM, - SRayHitInfo& outHitInfo); - - /// Detect ray intersection with a CBaseObject - static bool RayIntersection_CBaseObject( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - CBaseObject* pBaseObject, - _smart_ptr* ppOutLastMaterial, - SRayHitInfo& outHitInfo); - - static void AssignObjectMaterial(CBaseObject* pObject, const SRayHitInfo& outHitInfo, _smart_ptr* pOutMaterial); - static void AssignMaterial(_smart_ptr pObject, const SRayHitInfo& outHitInfo, _smart_ptr* pOutMaterial); - static bool IsMaterialValid(CMaterial* pMaterial); - -private: - - int m_PickOption; - - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - CBaseObjectsArray* m_pObjects; - CBaseObjectsArray* m_pSetObjects; - CBaseObjectsArray m_objects; - IDisplayViewport* m_pActiveView; - CExcludedObjects m_ExcludedObjects; - mutable CBaseObjectPtr m_pPickedObject; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING -}; - -#endif // CRYINCLUDE_EDITOR_SURFACEINFOPICKER_H diff --git a/Code/Sandbox/Editor/SurfaceTypeValidator.cpp b/Code/Sandbox/Editor/SurfaceTypeValidator.cpp index 68bbdcf3bb..9aec070912 100644 --- a/Code/Sandbox/Editor/SurfaceTypeValidator.cpp +++ b/Code/Sandbox/Editor/SurfaceTypeValidator.cpp @@ -16,7 +16,6 @@ #include "SurfaceTypeValidator.h" // Editor -#include "Material/Material.h" #include "Include/IObjectManager.h" #include "Objects/BaseObject.h" #include "ErrorReport.h" diff --git a/Code/Sandbox/Editor/TrackView/TrackViewSequenceManager.cpp b/Code/Sandbox/Editor/TrackView/TrackViewSequenceManager.cpp index 12f38c920a..0ba7c5b325 100644 --- a/Code/Sandbox/Editor/TrackView/TrackViewSequenceManager.cpp +++ b/Code/Sandbox/Editor/TrackView/TrackViewSequenceManager.cpp @@ -27,7 +27,6 @@ #include "AnimationContext.h" #include "GameEngine.h" #include "Include/IObjectManager.h" -#include "Material/MaterialManager.h" #include "Objects/ObjectManager.h" @@ -35,7 +34,6 @@ CTrackViewSequenceManager::CTrackViewSequenceManager() { GetIEditor()->RegisterNotifyListener(this); - GetIEditor()->GetMaterialManager()->AddListener(this); AZ::EntitySystemBus::Handler::BusConnect(); } @@ -45,7 +43,6 @@ CTrackViewSequenceManager::~CTrackViewSequenceManager() { AZ::EntitySystemBus::Handler::BusDisconnect(); - GetIEditor()->GetMaterialManager()->RemoveListener(this); GetIEditor()->UnregisterNotifyListener(this); } diff --git a/Code/Sandbox/Editor/Util/Variable.h b/Code/Sandbox/Editor/Util/Variable.h index 20c18d4409..d00ef6103a 100644 --- a/Code/Sandbox/Editor/Util/Variable.h +++ b/Code/Sandbox/Editor/Util/Variable.h @@ -152,7 +152,7 @@ struct IVariable DT_LOCAL_STRING, DT_EQUIP, DT_REVERBPRESET, - DT_MATERIAL, + DT_DEPRECATED0, // formerly DT_MATERIAL DT_MATERIALLOOKUP, DT_EXTARRAY, // Extendable Array DT_SEQUENCE, // Movie Sequence (DEPRECATED, use DT_SEQUENCE_ID, instead.) diff --git a/Code/Sandbox/Editor/Util/VariablePropertyType.cpp b/Code/Sandbox/Editor/Util/VariablePropertyType.cpp index c80461182d..c7fd3d9de2 100644 --- a/Code/Sandbox/Editor/Util/VariablePropertyType.cpp +++ b/Code/Sandbox/Editor/Util/VariablePropertyType.cpp @@ -49,7 +49,7 @@ namespace Prop { IVariable::DT_SIMPLE, "Selection", ePropertySelection, -1 }, { IVariable::DT_SIMPLE, "List", ePropertyList, -1 }, { IVariable::DT_SHADER, "Shader", ePropertyShader, 9 }, - { IVariable::DT_MATERIAL, "Material", ePropertyMaterial, 14 }, + { IVariable::DT_DEPRECATED0, "DEPRECATED", ePropertyDeprecated2, -1 }, { IVariable::DT_EQUIP, "Equip", ePropertyEquip, 11 }, { IVariable::DT_REVERBPRESET, "ReverbPreset", ePropertyReverbPreset, 11 }, { IVariable::DT_LOCAL_STRING, "LocalString", ePropertyLocalString, 3 }, diff --git a/Code/Sandbox/Editor/Util/VariablePropertyType.h b/Code/Sandbox/Editor/Util/VariablePropertyType.h index 76379c1bc0..130148c903 100644 --- a/Code/Sandbox/Editor/Util/VariablePropertyType.h +++ b/Code/Sandbox/Editor/Util/VariablePropertyType.h @@ -39,7 +39,7 @@ enum PropertyType ePropertySelection, ePropertyList, ePropertyShader, - ePropertyMaterial, + ePropertyDeprecated2, // formerly ePropertyMaterial ePropertyEquip, ePropertyReverbPreset, ePropertyLocalString, diff --git a/Code/Sandbox/Editor/Util/VariableTypeInfo.cpp b/Code/Sandbox/Editor/Util/VariableTypeInfo.cpp index 61cdac53c6..206131e5a9 100644 --- a/Code/Sandbox/Editor/Util/VariableTypeInfo.cpp +++ b/Code/Sandbox/Editor/Util/VariableTypeInfo.cpp @@ -112,10 +112,6 @@ void CVariableTypeInfo::SetTypes(CTypeInfo const& TypeInfo, EType eType) { SetDataType(DT_TEXTURE); } - else if (m_name == "Material") - { - SetDataType(DT_MATERIAL); - } else if (m_name == "Geometry") { SetDataType(DT_OBJECT); diff --git a/Code/Sandbox/Editor/editor_lib_files.cmake b/Code/Sandbox/Editor/editor_lib_files.cmake index e6337796d6..a0c22c9a14 100644 --- a/Code/Sandbox/Editor/editor_lib_files.cmake +++ b/Code/Sandbox/Editor/editor_lib_files.cmake @@ -309,15 +309,6 @@ set(FILES Util/AffineParts.cpp Objects/BaseObject.cpp Objects/BaseObject.h - Material/Material.cpp - Material/Material.h - Material/MaterialHelpers.cpp - Material/MaterialHelpers.h - Material/MaterialDialog.qrc - Material/MaterialPreviewModelView.cpp - Material/MaterialPreviewModelView.h - Material/PreviewModelView.cpp - Material/PreviewModelView.h Alembic/AlembicCompileDialog.cpp Alembic/AlembicCompileDialog.h Alembic/AlembicCompileDialog.ui @@ -553,7 +544,6 @@ set(FILES IObservable.h IPostRenderer.h LightmapCompiler/SimpleTriangleRasterizer.h - SurfaceInfoPicker.h ToolBox.h TrackViewNewSequenceDialog.h UndoConfigSpec.h @@ -570,25 +560,6 @@ set(FILES LevelIndependentFileMan.h LogFileImpl.cpp LogFileImpl.h - MatEditPreviewDlg.cpp - MatEditPreviewDlg.h - Material/MaterialBrowser.cpp - Material/MaterialBrowser.h - Material/MaterialBrowser.ui - Material/MaterialBrowserSearchFilters.cpp - Material/MaterialBrowserSearchFilters.h - Material/MaterialBrowserFilterModel.cpp - Material/MaterialBrowserFilterModel.h - Material/MaterialImageListCtrl.cpp - Material/MaterialImageListCtrl.h - Material/MaterialLibrary.cpp - Material/MaterialLibrary.h - Material/MaterialManager.cpp - Material/MaterialManager.h - MaterialSender.h - MaterialSender.cpp - Material/MaterialPythonFuncs.h - Material/MaterialPythonFuncs.cpp Mission.cpp Mission.h Objects/ClassDesc.cpp @@ -596,8 +567,6 @@ set(FILES Objects/IEntityObjectListener.h Objects/SelectionGroup.cpp Objects/SelectionGroup.h - Objects/StatObjValidator.cpp - Objects/StatObjValidator.h Objects/SubObjSelection.cpp Objects/SubObjSelection.h Objects/ObjectLoader.cpp @@ -631,9 +600,7 @@ set(FILES QtUI/WaitCursor.h QtUI/WaitCursor.cpp RenderHelpers/AxisHelper.cpp - RenderHelpers/AxisHelperExtended.cpp RenderHelpers/AxisHelper.h - RenderHelpers/AxisHelperExtended.h Serialization.h Serialization/VariableOArchive.cpp Serialization/VariableOArchive.h @@ -687,7 +654,6 @@ set(FILES LightmapCompiler/SimpleTriangleRasterizer.cpp ResourceSelectorHost.cpp ResourceSelectorHost.h - SurfaceInfoPicker.cpp ThumbnailGenerator.cpp ThumbnailGenerator.h ToolBox.cpp diff --git a/Code/Sandbox/Editor/editor_lib_test_files.cmake b/Code/Sandbox/Editor/editor_lib_test_files.cmake index f537169136..9eca3c56ae 100644 --- a/Code/Sandbox/Editor/editor_lib_test_files.cmake +++ b/Code/Sandbox/Editor/editor_lib_test_files.cmake @@ -18,7 +18,6 @@ set(FILES Lib/Tests/test_EditorUtils.cpp Lib/Tests/test_Main.cpp Lib/Tests/test_MainWindowPythonBindings.cpp - Lib/Tests/test_MaterialPythonFuncs.cpp Lib/Tests/test_ObjectManagerPythonBindings.cpp Lib/Tests/test_TrackViewPythonBindings.cpp Lib/Tests/test_ViewPanePythonBindings.cpp diff --git a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.cpp b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.cpp index 8f695c39ab..692bb92bf7 100644 --- a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.cpp +++ b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.cpp @@ -46,9 +46,7 @@ #include #include -#include #include -#include #include #include #include @@ -1096,56 +1094,3 @@ void CComponentEntityObject::DrawAccent(DisplayContext& dc) dc.DrawWireBox(box.min, box.max); } } - -void CComponentEntityObject::SetMaterial(CMaterial* material) -{ - AZ::Entity* entity = nullptr; - EBUS_EVENT_RESULT(entity, AZ::ComponentApplicationBus, FindEntity, m_entityId); - if (entity) - { - if (material) - { - EBUS_EVENT_ID(m_entityId, LmbrCentral::MaterialOwnerRequestBus, SetMaterial, material->GetMatInfo()); - } - else - { - EBUS_EVENT_ID(m_entityId, LmbrCentral::MaterialOwnerRequestBus, SetMaterial, nullptr); - } - } - - ValidateMeshStatObject(); -} - -CMaterial* CComponentEntityObject::GetMaterial() const -{ - _smart_ptr material = nullptr; - EBUS_EVENT_ID_RESULT(material, m_entityId, LmbrCentral::MaterialOwnerRequestBus, GetMaterial); - return GetIEditor()->GetMaterialManager()->FromIMaterial(material); -} - -CMaterial* CComponentEntityObject::GetRenderMaterial() const -{ - AZ::Entity* entity = nullptr; - EBUS_EVENT_RESULT(entity, AZ::ComponentApplicationBus, FindEntity, m_entityId); - if (entity) - { - _smart_ptr material = nullptr; - EBUS_EVENT_ID_RESULT(material, m_entityId, LmbrCentral::MaterialOwnerRequestBus, GetMaterial); - - if (material) - { - return GetIEditor()->GetMaterialManager()->LoadMaterial(material->GetName(), false); - } - } - - return nullptr; -} - -void CComponentEntityObject::ValidateMeshStatObject() -{ - IStatObj* statObj = GetIStatObj(); - CMaterial* editorMaterial = GetMaterial(); - CStatObjValidator statValidator; - statValidator.Validate(statObj, editorMaterial); -} - diff --git a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.h b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.h index 41619d75c5..b64bd6b3e1 100644 --- a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.h +++ b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.h @@ -79,9 +79,6 @@ public: CBaseObject* GetLinkParent() const override; XmlNodeRef Export(const QString& levelPath, XmlNodeRef& xmlNode) override; void DeleteEntity() override; - void SetMaterial(CMaterial* mtl) override; - CMaterial* GetMaterial() const override; - CMaterial* GetRenderMaterial() const override; void DrawDefault(DisplayContext& dc, const QColor& labelColor = QColor(255, 255, 255)) override; IStatObj* GetIStatObj() override; bool IsIsolated() const override; @@ -184,8 +181,6 @@ protected: void DrawAccent(DisplayContext& dc); - void ValidateMeshStatObject(); - class EditorActionGuard { public: diff --git a/Gems/LyShine/Code/Editor/Animation/UiAnimViewSequenceManager.cpp b/Gems/LyShine/Code/Editor/Animation/UiAnimViewSequenceManager.cpp index a65e220cbd..225f4e0b1a 100644 --- a/Gems/LyShine/Code/Editor/Animation/UiAnimViewSequenceManager.cpp +++ b/Gems/LyShine/Code/Editor/Animation/UiAnimViewSequenceManager.cpp @@ -16,7 +16,6 @@ #include "UiEditorDLLBus.h" #include "UiAnimViewSequenceManager.h" #include "UiAnimViewUndo.h" -#include "Material/MaterialManager.h" #include "AnimationContext.h" #include "GameEngine.h" #include