Rumba C++ SDK
BrushSculptPlugin.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 "BrushPlugin.h"
18 #include "Utils.h"
19 
20 namespace maquina
21 {
22 
24 
33 {
34 public:
35 
37 
42  {
43  public:
45  const SparseBufferV3f& delta_points,
46  const BrushPlugin::GeometryData& geometry,
47  const BufferConstM33f& vertex_space,
48  const std::shared_ptr<SceneConst>& reference
49  );
50 
52 
55  virtual bool sculpt_callback(gsl::span<Imath::V3f>& /* delta */, bool /* finished */) { return false; };
56 
58  std::shared_ptr<SparseBufferV3f> delta_points;
59 
61  std::vector<Imath::V3f> delta_points_orig;
62 
64  std::vector<Imath::V4f> accum;
65 
68 
70 
72  gsl::span<const Imath::M33f> vertex_space_span;
73 
75 
77  const std::shared_ptr<SceneConst> reference;
78 
80  Imath::V3f input_to_ref(size_t i, const Imath::V3f& l);
81 
83  Imath::V3f ref_to_input(size_t i, const Imath::V3f& l);
84 
86  std::vector<bool> vertex_on_edge;
87  };
88 
89  BrushSculptPlugin(Node* node);
90 
92 
96  virtual std::shared_ptr<BrushSculptUserData> user_data(
97  const SparseBufferV3f& delta_points,
98  const BrushPlugin::GeometryData& geometry,
99  const BufferConstM33f& vertex_space,
100  const std::shared_ptr<SceneConst>& reference
101  ) { return std::make_shared<BrushSculptUserData>(delta_points, geometry, vertex_space, reference); };
102 
104  virtual SceneConst delta_points() const { return {}; }
105 
107  virtual void set_delta_points(const SceneConst& /* delta_points */) {}
108 
110  virtual SceneConst vertex_space() { return {}; };
111 
113  virtual SceneConst reference() { return {}; };
114 
116  virtual bool preserve_edges() { return false; }
117 
118  // From ToolPlugin
119  void deactivate() override;
120 
121  // From BrushPlugin
122  void stroke_begin(int modifiers) override;
123  void stroke_update(bool first, bool finished) override;
124 
125 private:
126 
127  void _stroke_init_data(GeometryData& geometry);
128  void _stroke_update(GeometryData& geometry, bool finished);
129 
130  // The edited attributes
131  Scene _delta_points;
132 };
133 
135 {
136  if(vertex_space_span.empty())
137  return l;
138 
139  return mul_dir(l, vertex_space_span[i].inverse());
140 }
141 
143 {
144  if(vertex_space_span.empty())
145  return l;
146 
147  return mul_dir(l, vertex_space_span[i]);
148 }
149 
150 }
const BrushPlugin::GeometryData & geometry
A ref on the GeometryData.
Definition: BrushSculptPlugin.h:67
std::vector< Imath::V3f > delta_points_orig
A copy of the fully expanded delta_points at the stroke start, in reference space.
Definition: BrushSculptPlugin.h:61
std::vector< Imath::V4f > accum
Accumulation buffer of the sculpt (delta*weight, weight)
Definition: BrushSculptPlugin.h:64
V mul_dir(const V &src, const M &m)
A faster alternative to multiply a direction by a 4x4 matrix, ignoring the homogeneous normalization...
Definition: Utils.h:41
Imath::V3f input_to_ref(size_t i, const Imath::V3f &l)
Convert a vertex from the local space to the reference space is ref matrices are available.
Definition: BrushSculptPlugin.h:134
Definition: ImathFrame.h:42
A mutable scene node value.
Definition: Scene.h:292
A readonly buffer for basic types like floats, integers, Imath::V3f, Imath::M44f..
Definition: Buffer.h:42
std::vector< bool > vertex_on_edge
true if the vertex is on an open edge.
Definition: BrushSculptPlugin.h:86
gsl::span< const Imath::M33f > vertex_space_span
Definition: BrushSculptPlugin.h:72
This version of the SDK is unstable, i-e, it may change with no warning.
Definition: AddCurveAction.h:20
virtual SceneConst vertex_space()
Return a scene with for every geometries, an array of vertex space rotation matrices.
Definition: BrushSculptPlugin.h:110
Base class for the sculpt brush plug-ins.
Definition: BrushSculptPlugin.h:32
virtual bool preserve_edges()
Return true if the sculpt weight on edge vertices must be 0 or false if nothing special must be done ...
Definition: BrushSculptPlugin.h:116
Definition: BrushPlugin.h:36
virtual bool sculpt_callback(gsl::span< Imath::V3f > &, bool)
The sculpt callback.
Definition: BrushSculptPlugin.h:55
const std::shared_ptr< SceneConst > reference
The scene node of the reference sculpt object.
Definition: BrushSculptPlugin.h:77
const BufferConstM33f vertex_space
The current vertex spaces.
Definition: BrushSculptPlugin.h:71
virtual SceneConst reference()
Return the reference scene (as it with no modification, no animation)
Definition: BrushSculptPlugin.h:113
Definition: BrushPlugin.h:26
MAQUINA_EXPORT Node reference(Node &root, const std::wstring &filepath, const std::string &reference_root_name="", const ProgressCallback &progress={})
Reference the content of a file into the project.
#define MAQUINA_EXPORT
Definition: Export.h:31
An immutable scene node value.
Definition: Scene.h:35
virtual std::shared_ptr< BrushSculptUserData > user_data(const SparseBufferV3f &delta_points, const BrushPlugin::GeometryData &geometry, const BufferConstM33f &vertex_space, const std::shared_ptr< SceneConst > &reference)
Create a BrushSculptUserData object for a geometry.
Definition: BrushSculptPlugin.h:96
A writable SparseBuffer.
Definition: SparseBuffer.h:55
virtual void set_delta_points(const SceneConst &)
Set delta points to the deformer.
Definition: BrushSculptPlugin.h:107
virtual SceneConst delta_points() const
Get the current delta points from the deformer.
Definition: BrushSculptPlugin.h:104
The base sculpt brush data.
Definition: BrushSculptPlugin.h:41
Definition: BrushPlugin.h:180
Imath::V3f ref_to_input(size_t i, const Imath::V3f &l)
Convert a vertex from the local space to the reference space is ref matrices are available.
Definition: BrushSculptPlugin.h:142
Base class of all Rumba nodes.
Definition: Node.h:37