1 /* This file is part of Dilay 2 * Copyright © 2015-2018 Alexander Bau 3 * Use and redistribute under the terms of the GNU General Public License 4 */ 5 #include <QCheckBox> 6 #include "cache.hpp" 7 #include "dynamic/mesh-intersection.hpp" 8 #include "primitive/plane.hpp" 9 #include "state.hpp" 10 #include "tool/sculpt/util/brush.hpp" 11 #include "tool/util/movement.hpp" 12 #include "tools.hpp" 13 #include "view/double-slider.hpp" 14 #include "view/pointing-event.hpp" 15 #include "view/two-column-grid.hpp" 16 #include "view/util.hpp" 17 18 struct ToolSculptFlatten::Impl 19 { 20 ToolSculptFlatten* self; 21 ToolUtilMovement movement; 22 ImplToolSculptFlatten::Impl23 Impl (ToolSculptFlatten* s) 24 : self (s) 25 , movement (this->self->state ().camera (), glm::vec3 (0.0f)) 26 { 27 } 28 runSetupBrushToolSculptFlatten::Impl29 void runSetupBrush (SculptBrush& brush) 30 { 31 auto& params = brush.initParameters<SBFlattenParameters> (); 32 33 params.intensity (this->self->cache ().get<float> ("intensity", 0.5f)); 34 params.lockPlane (this->self->cache ().get<bool> ("lock-plane", false)); 35 36 brush.subdivide (false); 37 } 38 runSetupCursorToolSculptFlatten::Impl39 void runSetupCursor (ViewCursor&) {} 40 runSetupPropertiesToolSculptFlatten::Impl41 void runSetupProperties (ViewTwoColumnGrid& properties) 42 { 43 auto& params = this->self->brush ().parameters<SBFlattenParameters> (); 44 45 ViewDoubleSlider& intensityEdit = ViewUtil::slider (2, 0.1f, params.intensity (), 1.0f); 46 ViewUtil::connect (intensityEdit, [this, ¶ms](float i) { 47 params.intensity (i); 48 this->self->cache ().set ("intensity", i); 49 }); 50 properties.addStacked (QObject::tr ("Intensity"), intensityEdit); 51 this->self->registerSecondarySlider (intensityEdit); 52 53 QCheckBox& lockPlaneEdit = ViewUtil::checkBox (QObject::tr ("Lock plane"), params.lockPlane ()); 54 ViewUtil::connect (lockPlaneEdit, [this, ¶ms](bool v) { 55 params.lockPlane (v); 56 params.resetLockedPlane (); 57 this->self->cache ().set ("lock-plane", v); 58 }); 59 properties.add (lockPlaneEdit); 60 } 61 runSetupToolTipToolSculptFlatten::Impl62 void runSetupToolTip (ViewToolTip& toolTip) 63 { 64 this->self->addDefaultToolTip (toolTip, false, true); 65 } 66 runSculptPointingEventToolSculptFlatten::Impl67 bool runSculptPointingEvent (const ViewPointingEvent& e) 68 { 69 auto& params = this->self->brush ().parameters<SBFlattenParameters> (); 70 71 if (params.lockPlane ()) 72 { 73 if (e.pressEvent ()) 74 { 75 DynamicMeshIntersection intersection; 76 if (this->self->intersectsScene (e, intersection)) 77 { 78 params.lockedPlane (PrimPlane (intersection.position (), intersection.normal ())); 79 this->movement.onFreePlane (intersection.normal ()); 80 } 81 else 82 { 83 params.resetLockedPlane (); 84 } 85 } 86 return this->self->grablikeStroke (e, this->movement); 87 } 88 else 89 { 90 return this->self->drawlikeStroke (e, false); 91 } 92 } 93 }; 94 95 DELEGATE_TOOL_SCULPT (ToolSculptFlatten) 96