MeshLib
 
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:
138 ChangeTextureAction( const std::string& name, const std::shared_ptr<ObjectMeshHolder>& obj ) :
139 obj_{ obj },
140 name_{ name }
141 {
142 if ( obj )
143 textures_ = obj->getTextures();
144 }
145
146 virtual std::string name() const override
147 {
148 return name_;
149 }
150
151 virtual void action( HistoryAction::Type ) override
152 {
153 if ( !obj_ )
154 return;
155 obj_->updateTextures( textures_ );
156 }
157
158 static void setObjectDirty( const std::shared_ptr<ObjectMeshHolder>& obj )
159 {
160 if ( obj )
161 obj->setDirtyFlags( DIRTY_TEXTURE );
162 }
163
164 [[nodiscard]] virtual size_t heapBytes() const override
165 {
166 return name_.capacity() + MR::heapBytes( textures_ );
167 }
168
169private:
170 std::shared_ptr<ObjectMeshHolder> obj_;
172 std::string name_;
173};
174
177{
178public:
180
182 ChangeMeshPointsAction( std::string name, const std::shared_ptr<ObjectMesh>& obj ) :
183 objMesh_{ obj },
184 name_{ std::move( name ) }
185 {
186 if ( !objMesh_ )
187 return;
188 if ( auto m = objMesh_->mesh() )
189 clonePoints_ = m->points;
190 }
191
192 virtual std::string name() const override
193 {
194 return name_;
195 }
196
197 virtual void action( HistoryAction::Type ) override
198 {
199 if ( !objMesh_ )
200 return;
201
202 if ( auto m = objMesh_->varMesh() )
203 {
204 std::swap( m->points, clonePoints_ );
205 objMesh_->setDirtyFlags( DIRTY_POSITION );
206 }
207 }
208
209 static void setObjectDirty( const std::shared_ptr<ObjectMesh>& obj )
210 {
211 if ( obj )
212 obj->setDirtyFlags( DIRTY_POSITION );
213 }
214
215 [[nodiscard]] virtual size_t heapBytes() const override
216 {
217 return name_.capacity() + clonePoints_.heapBytes();
218 }
219
220private:
221 std::shared_ptr<ObjectMesh> objMesh_;
222 VertCoords clonePoints_;
223
224 std::string name_;
225};
226
229{
230public:
232
234 ChangeMeshTopologyAction( std::string name, const std::shared_ptr<ObjectMesh>& obj ) :
235 objMesh_{ obj },
236 name_{ std::move( name ) }
237 {
238 if ( !objMesh_ )
239 return;
240 if ( auto m = objMesh_->mesh() )
241 cloneTopology_ = m->topology;
242 }
243
244 virtual std::string name() const override
245 {
246 return name_;
247 }
248
249 virtual void action( HistoryAction::Type ) override
250 {
251 if ( !objMesh_ )
252 return;
253
254 if ( auto m = objMesh_->varMesh() )
255 {
256 std::swap( m->topology, cloneTopology_ );
257 objMesh_->setDirtyFlags( DIRTY_FACE );
258 }
259 }
260
261 static void setObjectDirty( const std::shared_ptr<ObjectMesh>& obj )
262 {
263 if ( obj )
264 obj->setDirtyFlags( DIRTY_FACE );
265 }
266
267 [[nodiscard]] virtual size_t heapBytes() const override
268 {
269 return name_.capacity() + cloneTopology_.heapBytes();
270 }
271
272private:
273 std::shared_ptr<ObjectMesh> objMesh_;
274 MeshTopology cloneTopology_;
275
276 std::string name_;
277};
278
281{
282public:
284
286 ChangeMeshTexturePerFaceAction( std::string name, const std::shared_ptr<ObjectMeshHolder>& obj ) :
287 objMesh_{ obj },
288 name_{ std::move( name ) }
289 {
290 if ( obj )
291 {
292 texturePerFace_ = obj->getTexturePerFace();
293 }
294 }
295
297 ChangeMeshTexturePerFaceAction( std::string name, const std::shared_ptr<ObjectMeshHolder>& obj, Vector<TextureId, FaceId>&& newTexturePerFace ) :
298 objMesh_{ obj },
299 name_{ std::move( name ) }
300 {
301 if ( obj )
302 {
303 texturePerFace_ = std::move( newTexturePerFace );
304 obj->updateTexturePerFace( texturePerFace_ );
305 }
306 }
307
308 virtual std::string name() const override
309 {
310 return name_;
311 }
312
313 virtual void action( HistoryAction::Type ) override
314 {
315 if ( !objMesh_ )
316 return;
317
318 objMesh_->updateTexturePerFace( texturePerFace_ );
319 }
320
321 static void setObjectDirty( const std::shared_ptr<ObjectMeshHolder>& obj )
322 {
323 if ( obj )
324 obj->setDirtyFlags( DIRTY_TEXTURE_PER_FACE );
325 }
326
327 [[nodiscard]] virtual size_t heapBytes() const override
328 {
329 return name_.capacity() + texturePerFace_.heapBytes();
330 }
331
332private:
333 Vector<TextureId, FaceId> texturePerFace_;
334 std::shared_ptr<ObjectMeshHolder> objMesh_;
335 std::string name_;
336};
337
339
340} // namespace MR
List< Vector3f^> VertCoords
Definition MRDotNet/MRMeshFwd.h:95
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:177
static void setObjectDirty(const std::shared_ptr< ObjectMesh > &obj)
Definition MRChangeMeshAction.h:209
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:182
virtual std::string name() const override
Definition MRChangeMeshAction.h:192
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeMeshAction.h:197
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeMeshAction.h:215
Undo action for ObjectMeshHolder texturePerFace change.
Definition MRChangeMeshAction.h:281
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeMeshAction.h:327
virtual std::string name() const override
Definition MRChangeMeshAction.h:308
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeMeshAction.h:313
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:286
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:297
static void setObjectDirty(const std::shared_ptr< ObjectMeshHolder > &obj)
Definition MRChangeMeshAction.h:321
Undo action for ObjectMesh topology only (not points) change.
Definition MRChangeMeshAction.h:229
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeMeshAction.h:249
static void setObjectDirty(const std::shared_ptr< ObjectMesh > &obj)
Definition MRChangeMeshAction.h:261
virtual std::string name() const override
Definition MRChangeMeshAction.h:244
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:234
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeMeshAction.h:267
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:158
ChangeTextureAction(const std::string &name, const std::shared_ptr< ObjectMeshHolder > &obj)
Constructed from original obj.
Definition MRChangeMeshAction.h:138
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeMeshAction.h:151
virtual std::string name() const override
Definition MRChangeMeshAction.h:146
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeMeshAction.h:164
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:19
size_t heapBytes() const
returns the amount of memory this object occupies on heap
Definition MRMesh/MRVector.h:133
MRMESH_API size_t heapBytes(const FloatGrid &grid)
returns the amount of heap memory occupied by grid
@ 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
Definition MRCameraOrientationPlugin.h:7