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 "MRMeshTexture.h"
7#include <memory>
8
9namespace MR
10{
11
14
17{
18public:
19 using Obj = ObjectMesh;
20
22 ChangeMeshAction( std::string name, const std::shared_ptr<ObjectMesh>& obj ) :
23 objMesh_{ obj },
24 name_{ std::move( name ) }
25 {
26 if ( obj )
27 {
28 if ( auto m = obj->meshPtr() )
29 cloneMesh_ = std::make_shared<Mesh>( *m );
30 }
31 }
32
34 ChangeMeshAction( std::string name, const std::shared_ptr<ObjectMesh>& obj, std::shared_ptr<Mesh> newMesh ) :
35 objMesh_{ obj },
36 name_{ std::move( name ) }
37 {
38 if ( obj )
39 cloneMesh_ = objMesh_->updateMesh( std::move( newMesh ) );
40 }
41
42 virtual std::string name() const override
43 {
44 return name_;
45 }
46
47 virtual void action( HistoryAction::Type ) override
48 {
49 if ( !objMesh_ )
50 return;
51
52 cloneMesh_ = objMesh_->updateMesh( cloneMesh_ );
53 }
54
55 static void setObjectDirty( const std::shared_ptr<ObjectMesh>& obj )
56 {
57 if ( obj )
58 obj->setDirtyFlags( DIRTY_ALL );
59 }
60
61 [[nodiscard]] virtual size_t heapBytes() const override
62 {
63 return name_.capacity() + MR::heapBytes( cloneMesh_ );
64 }
65
66private:
67 std::shared_ptr<ObjectMesh> objMesh_;
68 std::shared_ptr<Mesh> cloneMesh_;
69
70 std::string name_;
71};
72
75{
76public:
78
80 ChangeMeshUVCoordsAction( std::string name, const std::shared_ptr<ObjectMeshHolder>& obj ) :
81 objMesh_{ obj },
82 name_{ std::move( name ) }
83 {
84 if ( obj )
85 {
86 uvCoords_ = obj->getUVCoords();
87 }
88 }
89
91 ChangeMeshUVCoordsAction( std::string name, const std::shared_ptr<ObjectMeshHolder>& obj, VertUVCoords&& newUvCoords ) :
92 objMesh_{ obj },
93 name_{ std::move( name ) }
94 {
95 if ( obj )
96 {
97 uvCoords_ = std::move( newUvCoords );
98 obj->updateUVCoords( uvCoords_ );
99 }
100 }
101
102 virtual std::string name() const override
103 {
104 return name_;
105 }
106
107 virtual void action( HistoryAction::Type ) override
108 {
109 if ( !objMesh_ )
110 return;
111
112 objMesh_->updateUVCoords( uvCoords_ );
113 }
114
115 static void setObjectDirty( const std::shared_ptr<ObjectMeshHolder>& obj )
116 {
117 if ( obj )
118 obj->setDirtyFlags( DIRTY_UV );
119 }
120
121 [[nodiscard]] virtual size_t heapBytes() const override
122 {
123 return name_.capacity() + uvCoords_.heapBytes();
124 }
125
126private:
127 VertUVCoords uvCoords_;
128 std::shared_ptr<ObjectMeshHolder> objMesh_;
129 std::string name_;
130};
131
135{
136public:
138
140 ChangeTextureAction( std::string name, const std::shared_ptr<ObjectMeshHolder>& obj ) :
141 obj_{ obj },
142 name_{ std::move( name ) }
143 {
144 if ( obj )
145 textures_ = obj->getTextures();
146 }
147
149 ChangeTextureAction( std::string name, const std::shared_ptr<ObjectMeshHolder>& obj, Vector<MeshTexture, TextureId>&& newTextures ) :
150 obj_{ obj },
151 name_{ std::move( name ) }
152 {
153 if ( obj )
154 {
155 textures_ = std::move( newTextures );
156 obj->updateTextures( textures_ );
157 }
158 }
159
160 virtual std::string name() const override
161 {
162 return name_;
163 }
164
165 virtual void action( HistoryAction::Type ) override
166 {
167 if ( !obj_ )
168 return;
169 obj_->updateTextures( textures_ );
170 }
171
172 static void setObjectDirty( const std::shared_ptr<ObjectMeshHolder>& obj )
173 {
174 if ( obj )
175 obj->setDirtyFlags( DIRTY_TEXTURE );
176 }
177
178 [[nodiscard]] virtual size_t heapBytes() const override
179 {
180 return name_.capacity() + MR::heapBytes( textures_ );
181 }
182
183private:
184 std::shared_ptr<ObjectMeshHolder> obj_;
186 std::string name_;
187};
188
191{
192public:
194
196 ChangeMeshPointsAction( std::string name, const std::shared_ptr<ObjectMesh>& obj ) :
197 objMesh_{ obj },
198 name_{ std::move( name ) }
199 {
200 if ( !objMesh_ )
201 return;
202 if ( auto m = objMesh_->meshPtr() )
203 clonePoints_ = m->points;
204 }
205
207 ChangeMeshPointsAction( std::string name, const std::shared_ptr<ObjectMesh>& obj, VertCoords && newCoords ) :
208 objMesh_{ obj },
209 name_{ std::move( name ) }
210 {
211 clonePoints_ = std::move( newCoords );
213 }
214
215 virtual std::string name() const override
216 {
217 return name_;
218 }
219
220 virtual void action( HistoryAction::Type ) override
221 {
222 if ( !objMesh_ )
223 return;
224
225 if ( auto m = objMesh_->varMesh() )
226 {
227 std::swap( m->points, clonePoints_ );
228 objMesh_->setDirtyFlags( DIRTY_POSITION );
229 }
230 }
231
232 static void setObjectDirty( const std::shared_ptr<ObjectMesh>& obj )
233 {
234 if ( obj )
235 obj->setDirtyFlags( DIRTY_POSITION );
236 }
237
238 [[nodiscard]] virtual size_t heapBytes() const override
239 {
240 return name_.capacity() + clonePoints_.heapBytes();
241 }
242
243 const std::shared_ptr<ObjectMesh> & obj() const { return objMesh_; }
244 const VertCoords & clonePoints() const { return clonePoints_; }
245
246private:
247 std::shared_ptr<ObjectMesh> objMesh_;
248 VertCoords clonePoints_;
249
250 std::string name_;
251};
252
255{
256public:
258
260 ChangeMeshTopologyAction( std::string name, const std::shared_ptr<ObjectMesh>& obj ) :
261 objMesh_{ obj },
262 name_{ std::move( name ) }
263 {
264 if ( !objMesh_ )
265 return;
266 if ( auto m = objMesh_->meshPtr() )
267 cloneTopology_ = m->topology;
268 }
269
271 ChangeMeshTopologyAction( std::string name, const std::shared_ptr<ObjectMesh>& obj, MeshTopology && newTopology ) :
272 objMesh_{ obj },
273 name_{ std::move( name ) }
274 {
275 cloneTopology_ = std::move( newTopology );
277 }
278
279 virtual std::string name() const override
280 {
281 return name_;
282 }
283
284 virtual void action( HistoryAction::Type ) override
285 {
286 if ( !objMesh_ )
287 return;
288
289 if ( auto m = objMesh_->varMesh() )
290 {
291 std::swap( m->topology, cloneTopology_ );
292 objMesh_->setDirtyFlags( DIRTY_FACE );
293 }
294 }
295
296 static void setObjectDirty( const std::shared_ptr<ObjectMesh>& obj )
297 {
298 if ( obj )
299 obj->setDirtyFlags( DIRTY_FACE );
300 }
301
302 [[nodiscard]] virtual size_t heapBytes() const override
303 {
304 return name_.capacity() + cloneTopology_.heapBytes();
305 }
306
307private:
308 std::shared_ptr<ObjectMesh> objMesh_;
309 MeshTopology cloneTopology_;
310
311 std::string name_;
312};
313
316{
317public:
319
321 ChangeMeshTexturePerFaceAction( std::string name, const std::shared_ptr<ObjectMeshHolder>& obj ) :
322 objMesh_{ obj },
323 name_{ std::move( name ) }
324 {
325 if ( obj )
326 {
327 texturePerFace_ = obj->getTexturePerFace();
328 }
329 }
330
332 ChangeMeshTexturePerFaceAction( std::string name, const std::shared_ptr<ObjectMeshHolder>& obj, Vector<TextureId, FaceId>&& newTexturePerFace ) :
333 objMesh_{ obj },
334 name_{ std::move( name ) }
335 {
336 if ( obj )
337 {
338 texturePerFace_ = std::move( newTexturePerFace );
339 obj->updateTexturePerFace( texturePerFace_ );
340 }
341 }
342
343 virtual std::string name() const override
344 {
345 return name_;
346 }
347
348 virtual void action( HistoryAction::Type ) override
349 {
350 if ( !objMesh_ )
351 return;
352
353 objMesh_->updateTexturePerFace( texturePerFace_ );
354 }
355
356 static void setObjectDirty( const std::shared_ptr<ObjectMeshHolder>& obj )
357 {
358 if ( obj )
359 obj->setDirtyFlags( DIRTY_TEXTURE_PER_FACE );
360 }
361
362 [[nodiscard]] virtual size_t heapBytes() const override
363 {
364 return name_.capacity() + texturePerFace_.heapBytes();
365 }
366
367private:
368 Vector<TextureId, FaceId> texturePerFace_;
369 std::shared_ptr<ObjectMeshHolder> objMesh_;
370 std::string name_;
371};
372
374
375}
virtual std::string name() const override
Definition MRChangeMeshAction.h:42
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:34
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:22
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeMeshAction.h:47
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeMeshAction.h:61
static void setObjectDirty(const std::shared_ptr< ObjectMesh > &obj)
Definition MRChangeMeshAction.h:55
ObjectMesh Obj
Definition MRChangeMeshAction.h:19
static void setObjectDirty(const std::shared_ptr< ObjectMesh > &obj)
Definition MRChangeMeshAction.h:232
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:196
ObjectMesh Obj
Definition MRChangeMeshAction.h:193
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:207
virtual std::string name() const override
Definition MRChangeMeshAction.h:215
const std::shared_ptr< ObjectMesh > & obj() const
Definition MRChangeMeshAction.h:243
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeMeshAction.h:220
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeMeshAction.h:238
const VertCoords & clonePoints() const
Definition MRChangeMeshAction.h:244
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeMeshAction.h:362
virtual std::string name() const override
Definition MRChangeMeshAction.h:343
ObjectMeshHolder Obj
Definition MRChangeMeshAction.h:318
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeMeshAction.h:348
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:321
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:332
static void setObjectDirty(const std::shared_ptr< ObjectMeshHolder > &obj)
Definition MRChangeMeshAction.h:356
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeMeshAction.h:284
static void setObjectDirty(const std::shared_ptr< ObjectMesh > &obj)
Definition MRChangeMeshAction.h:296
virtual std::string name() const override
Definition MRChangeMeshAction.h:279
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:271
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:260
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeMeshAction.h:302
ObjectMesh Obj
Definition MRChangeMeshAction.h:257
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:91
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeMeshAction.h:107
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeMeshAction.h:121
ObjectMeshHolder Obj
Definition MRChangeMeshAction.h:77
virtual std::string name() const override
Definition MRChangeMeshAction.h:102
static void setObjectDirty(const std::shared_ptr< ObjectMeshHolder > &obj)
Definition MRChangeMeshAction.h:115
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:80
static void setObjectDirty(const std::shared_ptr< ObjectMeshHolder > &obj)
Definition MRChangeMeshAction.h:172
ObjectMeshHolder Obj
Definition MRChangeMeshAction.h:137
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:149
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeMeshAction.h:165
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:140
virtual std::string name() const override
Definition MRChangeMeshAction.h:160
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeMeshAction.h:178
Definition MRMeshTopology.h:30
Definition MRObjectMeshHolder.h:37
Definition MRObjectMesh.h:14
std::vector<T>-like container that requires specific indexing type,
Definition MRVector.h:23
size_t heapBytes(const BitSet &bs)
returns the amount of memory given BitSet occupies on heap
Definition MRBitSet.h:377
Type
Definition MRHistoryAction.h:27
HistoryAction()=default
explicitly define ctors to avoid warning C5267: definition of implicit copy constructor is deprecated...
@ Redo
Definition MRHistoryAction.h:29
@ DIRTY_POSITION
Definition MRVisualObject.h:77
@ DIRTY_TEXTURE
Definition MRVisualObject.h:83
@ DIRTY_TEXTURE_PER_FACE
Definition MRVisualObject.h:89
@ DIRTY_FACE
Definition MRVisualObject.h:85
@ DIRTY_ALL
Definition MRVisualObject.h:94
@ DIRTY_UV
Definition MRVisualObject.h:78
only for bindings generation
Definition MRCameraOrientationPlugin.h:8