Plasma Engine  2.0
Loading...
Searching...
No Matches
MaterialAsset.h
1#pragma once
2
3#include <EditorFramework/Assets/SimpleAssetDocument.h>
4#include <EditorPluginAssets/VisualShader/VisualShaderNodeManager.h>
5
9
11{
12 using StorageType = plUInt8;
13
14 enum Enum
15 {
16 BaseMaterial,
17 File,
18 Custom,
19
20 Default = BaseMaterial
21 };
22};
23
25{
26 enum Type
27 {
28 TransformFailed,
29 TransformSucceeded,
30 VisualShaderNotUsed,
31 };
32
33 Type m_Type;
34 plString m_sTransformError;
35};
36
37PL_DECLARE_REFLECTABLE_TYPE(PL_NO_LINKAGE, plMaterialShaderMode);
38
40{
41 using StorageType = plUInt8;
42
43 enum Enum
44 {
45 Ball,
46 Sphere,
47 Box,
48 Plane,
49
50 Default = Sphere
51 };
52};
53PL_DECLARE_REFLECTABLE_TYPE(PL_NO_LINKAGE, plMaterialAssetPreview);
54
56{
57 PL_ADD_DYNAMIC_REFLECTION(plMaterialAssetProperties, plReflectedClass);
58
59public:
61
62 = default;
63
64 void SetBaseMaterial(const char* szBaseMaterial);
65 const char* GetBaseMaterial() const;
66
67 void SetSurface(const char* szSurface) { m_sSurface = szSurface; }
68 const char* GetSurface() const { return m_sSurface; }
69
70 void SetShader(const char* szShader);
71 const char* GetShader() const;
72 void SetShaderProperties(plReflectedClass* pProperties);
73 plReflectedClass* GetShaderProperties() const;
74 void SetShaderMode(plEnum<plMaterialShaderMode> mode);
75 plEnum<plMaterialShaderMode> GetShaderMode() const { return m_ShaderMode; }
76
77 void SetDocument(plMaterialAssetDocument* pDocument);
78 void UpdateShader(bool bForce = false);
79
80 void DeleteProperties();
81 void CreateProperties(const char* szShaderPath);
82
83 void SaveOldValues();
84 void LoadOldValues();
85
86 plString ResolveRelativeShaderPath() const;
87 plString GetAutoGenShaderPathAbs() const;
88
89 static void PropertyMetaStateEventHandler(plPropertyMetaStateEvent& e);
90
91public:
92 plString m_sBaseMaterial;
93 plString m_sSurface;
94 plString m_sShader;
95
96 plMap<plString, plVariant> m_CachedProperties;
97 plMaterialAssetDocument* m_pDocument = nullptr;
99};
100
101class plMaterialAssetDocument : public plSimpleAssetDocument<plMaterialAssetProperties>
102{
104
105public:
108
109 plDocumentObject* GetShaderPropertyObject();
110 const plDocumentObject* GetShaderPropertyObject() const;
111
112 void SetBaseMaterial(const char* szBaseMaterial);
113
114 plStatus WriteMaterialAsset(plStreamWriter& inout_stream, const plPlatformProfile* pAssetProfile, bool bEmbedLowResData) const;
115
119
122 void TagVisualShaderFileInvalid(const plPlatformProfile* pAssetProfile, const char* szError);
123
126
127 static plUuid GetLitBaseMaterial();
128 static plUuid GetLitAlphaTestBaseMaterial();
129 static plUuid GetNeutralNormalMap();
130
131 virtual void GetSupportedMimeTypesForPasting(plHybridArray<plString, 4>& out_mimeTypes) const override;
132 virtual bool CopySelectedObjects(plAbstractObjectGraph& out_objectGraph, plStringBuilder& out_sMimeType) const override;
133 virtual bool Paste(const plArrayPtr<PasteInfo>& info, const plAbstractObjectGraph& objectGraph, bool bAllowPickedPosition, plStringView sMimeType) override;
134
136 plEnum<plMaterialAssetPreview> m_PreviewModel;
137
138protected:
139 plUuid GetSeedFromBaseMaterial(const plAbstractObjectGraph* pBaseGraph);
140 static plUuid GetMaterialNodeGuid(const plAbstractObjectGraph& graph);
141 virtual void UpdatePrefabObject(plDocumentObject* pObject, const plUuid& PrefabAsset, const plUuid& PrefabSeed, plStringView sBasePrefab) override;
142 virtual void InitializeAfterLoading(bool bFirstTimeCreation) override;
143
144 virtual plTransformStatus InternalTransformAsset(const char* szTargetFile, plStringView sOutputTag, const plPlatformProfile* pAssetProfile, const plAssetFileHeader& AssetHeader, plBitflags<plTransformFlags> transformFlags) override;
145 virtual plTransformStatus InternalTransformAsset(plStreamWriter& stream, plStringView sOutputTag, const plPlatformProfile* pAssetProfile, const plAssetFileHeader& AssetHeader, plBitflags<plTransformFlags> transformFlags) override;
147
148 virtual void InternalGetMetaDataHash(const plDocumentObject* pObject, plUInt64& inout_uiHash) const override;
149 virtual void AttachMetaDataBeforeSaving(plAbstractObjectGraph& graph) const override;
150 virtual void RestoreMetaDataAfterLoading(const plAbstractObjectGraph& graph, bool bUndoable) override;
151
152 virtual void UpdateAssetDocumentInfo(plAssetDocumentInfo* pInfo) const override;
153
154 void InvalidateCachedShader();
155 void EditorEventHandler(const plEditorAppEvent& e);
156
157private:
158 plStringBuilder m_sCheckPermutations;
159 static plUuid s_LitBaseMaterial;
160 static plUuid s_LitAlphaTextBaseMaterial;
161 static plUuid s_NeutralNormalMap;
162};
163
Definition AbstractObjectGraph.h:115
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
The thumbnail info containing the hash of the file is appended to assets. The serialized size of this...
Definition AssetDocument.h:49
Definition AssetDocumentInfo.h:7
Simple class to handle asset file headers (the very first bytes in all transformed asset files)
Definition AssetFileHeader.h:8
Definition DocumentObjectBase.h:11
Definition Event.h:177
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Definition Map.h:408
Definition MaterialAsset.h:102
virtual void GetSupportedMimeTypesForPasting(plHybridArray< plString, 4 > &out_mimeTypes) const override
Whether this document supports pasting the given mime format into it.
Definition MaterialAsset.cpp:1394
void RemoveDisconnectedNodes()
Deletes all Visual Shader nodes that are not connected to the output.
Definition MaterialAsset.cpp:1299
virtual void InternalGetMetaDataHash(const plDocumentObject *pObject, plUInt64 &inout_uiHash) const override
Computes the hash for transform relevant meta data of the given document object and combines it with ...
Definition MaterialAsset.cpp:896
virtual bool CopySelectedObjects(plAbstractObjectGraph &out_objectGraph, plStringBuilder &out_sMimeType) const override
Creates the abstract graph of data to be copied and returns the mime type for the clipboard to identi...
Definition MaterialAsset.cpp:1399
virtual void UpdateAssetDocumentInfo(plAssetDocumentInfo *pInfo) const override
Override this to add custom data (e.g. additional file dependencies) to the info struct.
Definition MaterialAsset.cpp:916
plStatus RecreateVisualShaderFile(const plAssetFileHeader &assetHeader)
Will make sure that the visual shader is rebuilt. Typically called during asset transformation,...
Definition MaterialAsset.cpp:1216
void TagVisualShaderFileInvalid(const plPlatformProfile *pAssetProfile, const char *szError)
If shader compilation failed this will modify the output shader file such that transforming it again,...
Definition MaterialAsset.cpp:1185
virtual plTransformStatus InternalTransformAsset(const char *szTargetFile, plStringView sOutputTag, const plPlatformProfile *pAssetProfile, const plAssetFileHeader &AssetHeader, plBitflags< plTransformFlags > transformFlags) override
Only override this function, if the transformed file for the given szOutputTag must be written from a...
Definition MaterialAsset.cpp:793
virtual plTransformStatus InternalCreateThumbnail(const ThumbnailInfo &ThumbnailInfo) override
Override this function to generate a thumbnail. Only called if GetAssetFlags returns plAssetDocumentF...
Definition MaterialAsset.cpp:891
Definition MaterialAsset.h:56
Definition MaterialAsset.h:165
Definition PlatformProfile.h:25
All classes that should be dynamically reflectable, need to be derived from this base class.
Definition DynamicRTTI.h:86
Definition SimpleAssetDocument.h:23
Interface for binary out (write) streams.
Definition Stream.h:107
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
This data type is the abstraction for 128-bit Uuid (also known as GUID) instances.
Definition Uuid.h:11
Definition VisualShaderNodeManager.h:24
The plBitflags class allows you to work with type-safe bitflags.
Definition Bitflags.h:82
Definition EditorApp.moc.h:35
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
Definition MaterialAsset.h:40
Definition MaterialAsset.h:11
Definition MaterialAsset.h:25
Event that is broadcast whenever information about how to present properties is required.
Definition PropertyMetaState.h:35
An plResult with an additional message for the reason of failure.
Definition Status.h:12
Definition Declarations.h:114