Rumba C++ SDK
BrushPlugin.h
Go to the documentation of this file.
1 /*
2 
3  *
4  ***
5  *****
6  ********************* Mercenaries Engineering SARL
7  ***************** Copyright (C) 2019
8  *************
9  ********* http://www.mercenaries-engineering.com
10  ***********
11  **** ****
12  ** **
13 
14 */
15 #pragma once
16 
17 #include "Maquina/Maquina.h"
18 
19 namespace maquina
20 {
21 
22 /* Base class to create brush plug-ins.
23  By deriving this class, create tools such as vertex color brushes or sculpt brushes.
24  The class has an API to compute and inspect the geometries which could be hit by the brush.
25 */
27 {
28 public:
29 
31  enum class BrushType
32  {
33  surface = 0,
34  geodesic,
35  volume
36  };
37 
38  BrushPlugin(Node* node);
39  BrushPlugin operator=(const BrushPlugin& ) = delete;
40 
42  void activate() override;
43  void deactivate() override;
44  void on_mouse_press( const CameraContext& camera, const InteractionContext& interaction ) override;
45  void on_mouse_move( const CameraContext& camera, const InteractionContext& interaction ) override;
46  void on_mouse_release( const CameraContext& camera, const InteractionContext& interaction ) override;
47  bool override_selection() override;
48  bool track_mouse() override;
49  bool manipulates() override;
50 
52 
54  virtual void stroke_begin(int modifiers);
55 
57 
61  virtual void stroke_update(
62  bool first,
63  bool finished
64  );
65 
67 
71  virtual void update_weights(
72  bool first,
73  const Imath::M44f& previous_brush_matrix
74  );
75 
77 
83  virtual bool do_update_weights() { return true; }
84 
86 
92  virtual float weight(float /* distance */) { return 1.f; }
93 
95 
103  virtual void update_brush_matrix(const CameraContext& camera, const InteractionContext& interaction, bool& visible, Imath::M44f& brush_matrix, bool on_press);
104 
106 
112  virtual float radius();
113 
115  void set_radius(float radius);
116 
118 
128  virtual float flow();
129 
131 
137  virtual bool multi_objects();
138 
140 
146  virtual bool fast_geodesic();
147 
149 
155  virtual SceneConst scene();
156 
158 
164  virtual BrushType brush_type();
165 
166  /* The brush object creates and hold one GeometryData object per "paintable" geometry.
167  * It also hold the current vertex weight and the accumulation buffer of the brush on the geometry.
168  */
170  {
171  public:
172  GeometryData(const std::string& path, const Mesh& displayed_mesh, const Imath::M44f& matrix, const Mesh& input_mesh);
173 
175  bool dirty;
176 
178  const std::string path;
179 
182 
187 
190 
193 
194  using Vertex = std::pair<int, float>;
195 
197 
199  std::vector<Vertex> weights;
200 
202  std::vector<float> accum_weights;
203 
205  std::shared_ptr<UserData> user_data;
206  };
207 
209 
210  gsl::span<GeometryData> geometry_data();
211 
213  Imath::V3f hit_pos_world() const;
214 
216  const Imath::V3f& hit_normal_world() const;
217 
219  Imath::V3f hit_pos_world_orig() const;
220 
222  const Imath::V3f& hit_normal_world_orig() const;
223 
225  const Imath::M44f& brush_matrix() const;
226 
228  const Imath::M44f& brush_matrix_orig() const;
229 
231  bool is_brush_visible() const;
232 
234  bool is_pressed() const;
235 
236 private:
237  std::vector<GeometryData> _geometry_data;
238 
239  // Once the mouse is pressed, initialize all the geometries which MAY by painted
240  void _init_geometries(const CameraContext& camera, const InteractionContext& interaction);
241 
242  void _update_displayed_geometry(const CameraContext& camera);
243 
244  bool _pressed;
245  Imath::M44f _brush_matrix;
246  Imath::M44f _brush_matrix_orig;
247  Imath::V3f _hit_normal;
248  Imath::V3f _hit_normal_orig;
249  bool _brush_visible;
250 
251  const GeometryData* _first_geometry = nullptr; // The first object hit by the stroke
252  bool _first_geometry_front_face = false; // Was the first hit front face ?
253 };
254 
255 inline gsl::span<BrushPlugin::GeometryData> BrushPlugin::geometry_data()
256 {
257  return _geometry_data;
258 }
259 
261 {
262  return _brush_matrix.translation();
263 }
264 
266 {
267  return _hit_normal;
268 }
269 
271 {
272  return _brush_matrix_orig.translation();
273 }
274 
276 {
277  return _hit_normal_orig;
278 }
279 
281 {
282  return _brush_matrix;
283 }
284 
286 {
287  return _brush_matrix_orig;
288 }
289 
290 inline bool BrushPlugin::is_brush_visible() const
291 {
292  return _brush_visible;
293 }
294 
295 inline bool BrushPlugin::is_pressed() const
296 {
297  return _pressed;
298 }
299 
300 }
const Imath::M44f & brush_matrix() const
Return the brush matrix which transforms from the brush local space to the world space.
Definition: BrushPlugin.h:280
const Mesh input_mesh
The input mesh of the deformer node.
Definition: BrushPlugin.h:192
A Tool node plug-in.
Definition: ToolPlugin.h:31
const Vec3< T > translation() const
Definition: ImathMatrix.h:2996
Definition: ImathFrame.h:42
Imath::V3f hit_pos_world() const
Return the brush position in world space.
Definition: BrushPlugin.h:260
Definition: ImathFrame.h:43
A mesh value.
Definition: Mesh.h:33
std::vector< Vertex > weights
The vertex weights computed since the last stroke update.
Definition: BrushPlugin.h:199
This class provides viewport space conversion services.
Definition: CameraContext.h:23
std::pair< int, float > Vertex
Definition: BrushPlugin.h:194
This version of the SDK is unstable, i-e, it may change with no warning.
Definition: AddCurveAction.h:20
const Imath::M44f displayed_inversed_transposed_matrix
The mesh matrix to transform the normals from local to world.
Definition: BrushPlugin.h:186
virtual float weight(float)
Convert a distance in weight.
Definition: BrushPlugin.h:92
Definition: BrushPlugin.h:26
std::shared_ptr< UserData > user_data
Optional user provided data. The data set in that field will be passed at the next stroke_update call...
Definition: BrushPlugin.h:205
BufferV3f displayed_normals
The displayed mesh normals.
Definition: BrushPlugin.h:189
bool dirty
Set this flag to update its geometry.
Definition: BrushPlugin.h:175
const Imath::M44f displayed_inversed_matrix
The world to local mesh matrix.
Definition: BrushPlugin.h:185
#define MAQUINA_EXPORT
Definition: Export.h:31
An immutable scene node value.
Definition: Scene.h:35
Mesh displayed_mesh
The displayed mesh in the viewport, may not be the same than the output mesh of the deformer node if ...
Definition: BrushPlugin.h:181
BrushType
The different brush types.
Definition: BrushPlugin.h:31
const Imath::V3f & hit_normal_world_orig() const
Return the brush normal in world space at the beginning of the stroke.
Definition: BrushPlugin.h:275
std::vector< float > accum_weights
The accumulated weights since the beginning of the stroke.
Definition: BrushPlugin.h:202
This interface is passed to the events and is implemented by the application. */. ...
Definition: InteractionContext.h:22
bool is_brush_visible() const
Returns true is the brush is visible.
Definition: BrushPlugin.h:290
const Imath::M44f & brush_matrix_orig() const
Return the brush matrix which transforms from the brush local space to the world space at the beginni...
Definition: BrushPlugin.h:285
bool is_pressed() const
Returns true is the brush is pressed by the user.
Definition: BrushPlugin.h:295
Imath::V3f hit_pos_world_orig() const
Returns the world space brush position at the beginning of the stroke.
Definition: BrushPlugin.h:270
const Imath::M44f displayed_matrix
The displayed mesh precomputed matrices.
Definition: BrushPlugin.h:184
const std::string path
The mesh&#39;s path in the edited scene.
Definition: BrushPlugin.h:178
virtual bool do_update_weights()
Does the weights have to be updated at every stroke_update() ?
Definition: BrushPlugin.h:83
Definition: BrushPlugin.h:169
const Imath::V3f & hit_normal_world() const
Return the brush normal in world space.
Definition: BrushPlugin.h:265
Base class of all Rumba nodes.
Definition: Node.h:36
gsl::span< GeometryData > geometry_data()
Return the brush&#39;s geometry data.
Definition: BrushPlugin.h:255