Cogs.Core
ResourceCommands.h
1#pragma once
2
3#include "EditorCommand.h"
4
5#include "Resources/Resources.h"
6#include "Resources/MaterialInstance.h"
7#include "Resources/Mesh.h"
8
9namespace Cogs::Core
10{
11 template<typename T>
13 {
16 StringView key,
17 T value) : EditorCommand(state, state->context), material(material), key(key.to_string()), value(value) {}
18
19 void apply() override
20 {
21 material->getProperty(key, &previousValue, sizeof(T));
22 material->setProperty(key, &value, sizeof(T));
23 }
24
25 void undo() override
26 {
27 material->setProperty(key, &previousValue, sizeof(T));
28 }
29
30 bool mergeWith(const EditorCommand * command) override
31 {
32 auto setPropertyCommand = dynamic_cast<const SetMaterialPropertyCommand *>(command);
33
34 if (!setPropertyCommand) return false;
35 if (material != setPropertyCommand->material) return false;
36
37 value = setPropertyCommand->value;
38
39 return true;
40 }
41
42 private:
44 std::string key;
45 T value;
46 T previousValue;
47 };
48
50 {
52 EditorCommand(state, state->context), material(material), key(key.to_string()), texture(texture) {}
53
54 void apply() override;
55 void undo() override;
56
57 private:
59 std::string key;
60 TextureHandle texture;
61
62 TextureHandle previousTexture;
63 };
64
66 {
67 RemapMaterialCommand(EditorState * state, EntityId entityId) : EditorCommand(state, state->context), entityId(entityId) {}
68
69 void apply() override;
70 void undo() override;
71
72 private:
73 EntityId entityId;
74
75 std::unordered_map<EntityId, MaterialInstanceHandle> materials;
76 };
77
79 {
80 MergeMaterialCommand(EditorState * state, EntityId entityId) : EditorCommand(state, state->context), entityId(entityId) {}
81
82 void apply() override;
83 void undo() override;
84
85 private:
86 EntityId entityId;
87
88 std::unordered_map<EntityId, MaterialInstanceHandle> materials;
89 };
90
92 {
93 GenerateTangentsCommand(EditorState * state, EntityId entityId) : EditorCommand(state, state->context), entityId(entityId) {}
94
95 void apply() override;
96 void undo() override;
97
98 private:
99 EntityId entityId;
100
101 std::unordered_map<EntityId, MeshHandle> meshes;
102 };
103
105 {
106 GenNormalsCommand(EditorState * state, EntityId entityId) : EditorCommand(state, state->context), entityId(entityId) {}
107
108 void apply() override;
109 void undo() override;
110
111 private:
112 EntityId entityId;
113
114 std::unordered_map<EntityId, MeshHandle> meshes;
115 };
116}
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
std::string to_string() const
String conversion method.
Definition: StringView.cpp:9
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
Base class for Cogs Editor commands.
Definition: EditorCommand.h:19
void apply() override
Run the command.
void apply() override
Run the command.
Material * material
Material resource this MaterialInstance is created from.
void apply() override
Run the command.
void apply() override
Run the command.
bool mergeWith(const EditorCommand *command) override
void apply() override
Run the command.
void apply() override
Run the command.