1 /* 2 Copyright © 2022, Inochi2D Project 3 Distributed under the 2-Clause BSD License, see LICENSE file. 4 5 Authors: Luna Nielsen 6 */ 7 module creator.viewport.model.deform; 8 import creator.viewport.model.deform.mesh; 9 import creator.viewport.common.mesh; 10 import creator.viewport.common.mesheditor; 11 import creator.widgets.tooltip; 12 import creator.core.input; 13 import inochi2d.core.dbg; 14 import creator.core; 15 import creator; 16 import inochi2d; 17 import bindbc.imgui; 18 import i18n; 19 import std.stdio; 20 21 private { 22 IncMeshEditor editor; 23 Drawable selected = null; 24 } 25 26 void incViewportNodeDeformNotifyParamValueChanged() { 27 if (Parameter param = incArmedParameter()) { 28 if (!editor) { 29 if (Drawable selectedDraw = cast(Drawable)incSelectedNode()) { 30 editor = new IncMeshEditor(true); 31 editor.setTarget(selectedDraw); 32 } else { 33 return; 34 } 35 } else { 36 editor.resetMesh(); 37 } 38 39 DeformationParameterBinding deform = cast(DeformationParameterBinding)param.getBinding(editor.getTarget(), "deform"); 40 if (deform) { 41 editor.applyOffsets(deform.getValue(param.findClosestKeypoint()).vertexOffsets); 42 } 43 } else { 44 editor = null; 45 } 46 } 47 48 void incViewportModelDeformNodeSelectionChanged() { 49 editor = null; 50 incViewportNodeDeformNotifyParamValueChanged(); 51 } 52 53 void incViewportModelDeformUpdate(ImGuiIO* io, Camera camera, Parameter param) { 54 if (!editor) return; 55 56 if (editor.update(io, camera)) { 57 auto deform = cast(DeformationParameterBinding)param.getOrAddBinding(editor.getTarget(), "deform"); 58 deform.update(param.findClosestKeypoint(), editor.getOffsets()); 59 } 60 } 61 62 void incViewportModelDeformDraw(Camera camera, Parameter param) { 63 if (editor) 64 editor.draw(camera); 65 } 66 void incViewportModelDeformToolSettings() { 67 68 }