MeshLib C++ Docs
Loading...
Searching...
No Matches
MRChangeMeshAction.h
Go to the documentation of this file.
1#pragma once
2#include "MRHistoryAction.h"
3#include "MRObjectMesh.h"
4#include "MRMesh.h"
5#include "MRHeapBytes.h"
6#include <memory>
7
8namespace MR
9{
10
13
16{
17public:
18 using Obj = ObjectMesh;
19
21 ChangeMeshAction( std::string name, const std::shared_ptr<ObjectMesh>& obj ) :
22 objMesh_{ obj },
23 name_{ std::move( name ) }
24 {
25 if ( obj )
26 {
27 if ( auto m = obj->mesh() )
28 cloneMesh_ = std::make_shared<Mesh>( *m );
29 }
30 }
31
33 ChangeMeshAction( std::string name, const std::shared_ptr<ObjectMesh>& obj, std::shared_ptr<Mesh> newMesh ) :
34 objMesh_{ obj },
35 name_{ std::move( name ) }
36 {
37 if ( obj )
38 cloneMesh_ = objMesh_->updateMesh( std::move( newMesh ) );
39 }
40
41 virtual std::string name() const override
42 {
43 return name_;
44 }
45
46 virtual void action( HistoryAction::Type ) override
47 {
48 if ( !objMesh_ )
49 return;
50
51 cloneMesh_ = objMesh_->updateMesh( cloneMesh_ );
52 }
53
54 static void setObjectDirty( const std::shared_ptr<ObjectMesh>& obj )
55 {
56 if ( obj )
57 obj->setDirtyFlags( DIRTY_ALL );
58 }
59
60 [[nodiscard]] virtual size_t heapBytes() const override
61 {
62 return name_.capacity() + MR::heapBytes( cloneMesh_ );
63 }
64
65private:
66 std::shared_ptr<ObjectMesh> objMesh_;
67 std::shared_ptr<Mesh> cloneMesh_;
68
69 std::string name_;
70};
71
74{
75public:
77
79 ChangeMeshUVCoordsAction( std::string name, const std::shared_ptr<ObjectMeshHolder>& obj ) :
80 objMesh_{ obj },
81 name_{ std::move( name ) }
82 {
83 if ( obj )
84 {
85 uvCoords_ = obj->getUVCoords();
86 }
87 }
88
90 ChangeMeshUVCoordsAction( std::string name, const std::shared_ptr<ObjectMeshHolder>& obj, VertUVCoords&& newUvCoords ) :
91 objMesh_{ obj },
92 name_{ std::move( name ) }
93 {
94 if ( obj )
95 {
96 uvCoords_ = std::move( newUvCoords );
97 obj->updateUVCoords( uvCoords_ );
98 }
99 }
100
101 virtual std::string name() const override
102 {
103 return name_;
104 }
105
106 virtual void action( HistoryAction::Type ) override
107 {
108 if ( !objMesh_ )
109 return;
110
111 objMesh_->updateUVCoords( uvCoords_ );
112 }
113
114 static void setObjectDirty( const std::shared_ptr<ObjectMeshHolder>& obj )
115 {
116 if ( obj )
117 obj->setDirtyFlags( DIRTY_UV );
118 }
119
120 [[nodiscard]] virtual size_t heapBytes() const override
121 {
122 return name_.capacity() + uvCoords_.heapBytes();
123 }
124
125private:
126 VertUVCoords uvCoords_;
127 std::shared_ptr<ObjectMeshHolder> objMesh_;
128 std::string name_;
129};
130
134{
135public:
137
139 ChangeTextureAction( std::string name, const std::shared_ptr<ObjectMeshHolder>& obj ) :
140 obj_{ obj },
141 name_{ std::move( name ) }
142 {
143 if ( obj )
144 textures_ = obj->getTextures();
145 }
146
148 ChangeTextureAction( std::string name, const std::shared_ptr<ObjectMeshHolder>& obj, Vector<MeshTexture, TextureId>&& newTextures ) :
149 obj_{ obj },
150 name_{ std::move( name ) }
151 {
152 if ( obj )
153 {
154 textures_ = std::move( newTextures );
155 obj->updateTextures( textures_ );
156 }
157 }
158
159 virtual std::string name() const override
160 {
161 return name_;
162 }
163
164 virtual void action( HistoryAction::Type ) override
165 {
166 if ( !obj_ )
167 return;
168 obj_->updateTextures( textures_ );
169 }
170
171 static void setObjectDirty( const std::shared_ptr<ObjectMeshHolder>& obj )
172 {
173 if ( obj )
174 obj->setDirtyFlags( DIRTY_TEXTURE );
175 }
176
177 [[nodiscard]] virtual size_t heapBytes() const override
178 {
179 return name_.capacity() + MR::heapBytes( textures_ );
180 }
181
182private:
183 std::shared_ptr<ObjectMeshHolder> obj_;
185 std::string name_;
186};
187
190{
191public:
193
195 ChangeMeshPointsAction( std::string name, const std::shared_ptr<ObjectMesh>& obj ) :
196 objMesh_{ obj },
197 name_{ std::move( name ) }
198 {
199 if ( !objMesh_ )
200 return;
201 if ( auto m = objMesh_->mesh() )
202 clonePoints_ = m->points;
203 }
204
206 ChangeMeshPointsAction( std::string name, const std::shared_ptr<ObjectMesh>& obj, VertCoords && newCoords ) :
207 objMesh_{ obj },
208 name_{ std::move( name ) }
209 {
210 clonePoints_ = std::move( newCoords );
212 }
213
214 virtual std::string name() const override
215 {
216 return name_;
217 }
218
219 virtual void action( HistoryAction::Type ) override
220 {
221 if ( !objMesh_ )
222 return;
223
224 if ( auto m = objMesh_->varMesh() )
225 {
226 std::swap( m->points, clonePoints_ );
227 objMesh_->setDirtyFlags( DIRTY_POSITION );
228 }
229 }
230
231 static void setObjectDirty( const std::shared_ptr<ObjectMesh>& obj )
232 {
233 if ( obj )
234 obj->setDirtyFlags( DIRTY_POSITION );
235 }
236
237 [[nodiscard]] virtual size_t heapBytes() const override
238 {
239 return name_.capacity() + clonePoints_.heapBytes();
240 }
241
242 const std::shared_ptr<ObjectMesh> & obj() const { return objMesh_; }
243 const VertCoords & clonePoints() const { return clonePoints_; }
244
245private:
246 std::shared_ptr<ObjectMesh> objMesh_;
247 VertCoords clonePoints_;
248
249 std::string name_;
250};
251
254{
255public:
257
259 ChangeMeshTopologyAction( std::string name, const std::shared_ptr<ObjectMesh>& obj ) :
260 objMesh_{ obj },
261 name_{ std::move( name ) }
262 {
263 if ( !objMesh_ )
264 return;
265 if ( auto m = objMesh_->mesh() )
266 cloneTopology_ = m->topology;
267 }
268
270 ChangeMeshTopologyAction( std::string name, const std::shared_ptr<ObjectMesh>& obj, MeshTopology && newTopology ) :
271 objMesh_{ obj },
272 name_{ std::move( name ) }
273 {
274 cloneTopology_ = std::move( newTopology );
276 }
277
278 virtual std::string name() const override
279 {
280 return name_;
281 }
282
283 virtual void action( HistoryAction::Type ) override
284 {
285 if ( !objMesh_ )
286 return;
287
288 if ( auto m = objMesh_->varMesh() )
289 {
290 std::swap( m->topology, cloneTopology_ );
291 objMesh_->setDirtyFlags( DIRTY_FACE );
292 }
293 }
294
295 static void setObjectDirty( const std::shared_ptr<ObjectMesh>& obj )
296 {
297 if ( obj )
298 obj->setDirtyFlags( DIRTY_FACE );
299 }
300
301 [[nodiscard]] virtual size_t heapBytes() const override
302 {
303 return name_.capacity() + cloneTopology_.heapBytes();
304 }
305
306private:
307 std::shared_ptr<ObjectMesh> objMesh_;
308 MeshTopology cloneTopology_;
309
310 std::string name_;
311};
312
315{
316public:
318
320 ChangeMeshTexturePerFaceAction( std::string name, const std::shared_ptr<ObjectMeshHolder>& obj ) :
321 objMesh_{ obj },
322 name_{ std::move( name ) }
323 {
324 if ( obj )
325 {
326 texturePerFace_ = obj->getTexturePerFace();
327 }
328 }
329
331 ChangeMeshTexturePerFaceAction( std::string name, const std::shared_ptr<ObjectMeshHolder>& obj, Vector<TextureId, FaceId>&& newTexturePerFace ) :
332 objMesh_{ obj },
333 name_{ std::move( name ) }
334 {
335 if ( obj )
336 {
337 texturePerFace_ = std::move( newTexturePerFace );
338 obj->updateTexturePerFace( texturePerFace_ );
339 }
340 }
341
342 virtual std::string name() const override
343 {
344 return name_;
345 }
346
347 virtual void action( HistoryAction::Type ) override
348 {
349 if ( !objMesh_ )
350 return;
351
352 objMesh_->updateTexturePerFace( texturePerFace_ );
353 }
354
355 static void setObjectDirty( const std::shared_ptr<ObjectMeshHolder>& obj )
356 {
357 if ( obj )
358 obj->setDirtyFlags( DIRTY_TEXTURE_PER_FACE );
359 }
360
361 [[nodiscard]] virtual size_t heapBytes() const override
362 {
363 return name_.capacity() + texturePerFace_.heapBytes();
364 }
365
366private:
367 Vector<TextureId, FaceId> texturePerFace_;
368 std::shared_ptr<ObjectMeshHolder> objMesh_;
369 std::string name_;
370};
371
373
374} // namespace MR
Undo action for ObjectMesh mesh change.
Definition MRChangeMeshAction.h:16
virtual std::string name() const override
Definition MRChangeMeshAction.h:41
ChangeMeshAction(std::string name, const std::shared_ptr< ObjectMesh > &obj, std::shared_ptr< Mesh > newMesh)
use this constructor to remember object's mesh and immediately set new mesh
Definition MRChangeMeshAction.h:33
ChangeMeshAction(std::string name, const std::shared_ptr< ObjectMesh > &obj)
use this constructor to remember object's mesh before making any changes in it
Definition MRChangeMeshAction.h:21
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeMeshAction.h:46
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeMeshAction.h:60
static void setObjectDirty(const std::shared_ptr< ObjectMesh > &obj)
Definition MRChangeMeshAction.h:54
Undo action for ObjectMesh points only (not topology) change.
Definition MRChangeMeshAction.h:190
static void setObjectDirty(const std::shared_ptr< ObjectMesh > &obj)
Definition MRChangeMeshAction.h:231
ChangeMeshPointsAction(std::string name, const std::shared_ptr< ObjectMesh > &obj)
use this constructor to remember object's mesh points before making any changes in it
Definition MRChangeMeshAction.h:195
ChangeMeshPointsAction(std::string name, const std::shared_ptr< ObjectMesh > &obj, VertCoords &&newCoords)
use this constructor to remember object's mesh points and immediate set new value
Definition MRChangeMeshAction.h:206
virtual std::string name() const override
Definition MRChangeMeshAction.h:214
const std::shared_ptr< ObjectMesh > & obj() const
Definition MRChangeMeshAction.h:242
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeMeshAction.h:219
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeMeshAction.h:237
const VertCoords & clonePoints() const
Definition MRChangeMeshAction.h:243
Undo action for ObjectMeshHolder texturePerFace change.
Definition MRChangeMeshAction.h:315
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeMeshAction.h:361
virtual std::string name() const override
Definition MRChangeMeshAction.h:342
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeMeshAction.h:347
ChangeMeshTexturePerFaceAction(std::string name, const std::shared_ptr< ObjectMeshHolder > &obj)
use this constructor to remember object's texturePerFace data before making any changes in them
Definition MRChangeMeshAction.h:320
ChangeMeshTexturePerFaceAction(std::string name, const std::shared_ptr< ObjectMeshHolder > &obj, Vector< TextureId, FaceId > &&newTexturePerFace)
use this constructor to remember object's texturePerFace data and immediate set new value
Definition MRChangeMeshAction.h:331
static void setObjectDirty(const std::shared_ptr< ObjectMeshHolder > &obj)
Definition MRChangeMeshAction.h:355
Undo action for ObjectMesh topology only (not points) change.
Definition MRChangeMeshAction.h:254
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeMeshAction.h:283
static void setObjectDirty(const std::shared_ptr< ObjectMesh > &obj)
Definition MRChangeMeshAction.h:295
virtual std::string name() const override
Definition MRChangeMeshAction.h:278
ChangeMeshTopologyAction(std::string name, const std::shared_ptr< ObjectMesh > &obj, MeshTopology &&newTopology)
use this constructor to remember object's mesh topology and immediate set new value
Definition MRChangeMeshAction.h:270
ChangeMeshTopologyAction(std::string name, const std::shared_ptr< ObjectMesh > &obj)
use this constructor to remember object's mesh points before making any changes in it
Definition MRChangeMeshAction.h:259
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeMeshAction.h:301
Undo action for ObjectMeshHolder uvCoords change.
Definition MRChangeMeshAction.h:74
ChangeMeshUVCoordsAction(std::string name, const std::shared_ptr< ObjectMeshHolder > &obj, VertUVCoords &&newUvCoords)
use this constructor to remember object's uv-coordinates and immediate set new value
Definition MRChangeMeshAction.h:90
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeMeshAction.h:106
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeMeshAction.h:120
virtual std::string name() const override
Definition MRChangeMeshAction.h:101
static void setObjectDirty(const std::shared_ptr< ObjectMeshHolder > &obj)
Definition MRChangeMeshAction.h:114
ChangeMeshUVCoordsAction(std::string name, const std::shared_ptr< ObjectMeshHolder > &obj)
use this constructor to remember object's uv-coordinates before making any changes in them
Definition MRChangeMeshAction.h:79
Definition MRChangeMeshAction.h:134
static void setObjectDirty(const std::shared_ptr< ObjectMeshHolder > &obj)
Definition MRChangeMeshAction.h:171
ChangeTextureAction(std::string name, const std::shared_ptr< ObjectMeshHolder > &obj, Vector< MeshTexture, TextureId > &&newTextures)
use this constructor to remember object's textures and immediate set new value
Definition MRChangeMeshAction.h:148
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeMeshAction.h:164
ChangeTextureAction(std::string name, const std::shared_ptr< ObjectMeshHolder > &obj)
use this constructor to remember object's textures before making any changes in them
Definition MRChangeMeshAction.h:139
virtual std::string name() const override
Definition MRChangeMeshAction.h:159
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeMeshAction.h:177
Definition MRHistoryAction.h:12
Type
Definition MRHistoryAction.h:19
Definition MRMesh/MRMeshTopology.h:18
MRMESH_API size_t heapBytes() const
returns the amount of memory this object occupies on heap
Definition MRObjectMeshHolder.h:30
Definition MRObjectMesh.h:11
std::vector<T>-like container that requires specific indexing type,
Definition MRMesh/MRVector.h:20
size_t heapBytes() const
returns the amount of memory this object occupies on heap
Definition MRMesh/MRVector.h:142
size_t heapBytes(const std::vector< T > &vec)
returns the amount of memory given vector occupies on heap
Definition MRHeapBytes.h:15
@ DIRTY_POSITION
Definition MRVisualObject.h:90
@ DIRTY_TEXTURE
Definition MRVisualObject.h:97
@ DIRTY_TEXTURE_PER_FACE
Definition MRVisualObject.h:103
@ DIRTY_FACE
Definition MRVisualObject.h:99
@ DIRTY_ALL
Definition MRVisualObject.h:109
@ DIRTY_UV
Definition MRVisualObject.h:91