1 /* 2 Copyright © 2020, Inochi2D Project 3 Distributed under the 2-Clause BSD License, see LICENSE file. 4 5 Authors: Luna Nielsen 6 */ 7 module creator.viewport.vertex; 8 import i18n; 9 import creator.viewport; 10 import creator.viewport.common.mesh; 11 import creator.viewport.common.mesheditor; 12 import creator.core.input; 13 import creator.widgets; 14 import creator; 15 import inochi2d; 16 import bindbc.imgui; 17 import std.stdio; 18 import bindbc.opengl; 19 20 private { 21 IncMeshEditor editor; 22 } 23 24 void incViewportVertexInspector(Drawable node) { 25 26 igBeginGroup(); 27 if (igButton("")) editor.mesh.flipHorz(); 28 incTooltip(_("Flip Horizontally")); 29 30 igSameLine(0, 4); 31 32 if (igButton("")) editor.mesh.flipVert(); 33 incTooltip(_("Flip Vertically")); 34 igEndGroup(); 35 36 igBeginGroup(); 37 if (incButtonColored("", ImVec2(0, 0), editor.mirrorHoriz ? ImVec4.init : ImVec4(0.6, 0.6, 0.6, 1))) { 38 editor.mirrorHoriz = !editor.mirrorHoriz; 39 editor.refreshMesh(); 40 } 41 incTooltip(_("Mirror Horizontally")); 42 43 igSameLine(0, 4); 44 if (incButtonColored("", ImVec2(0, 0), editor.mirrorVert ? ImVec4.init : ImVec4(0.6, 0.6, 0.6, 1))) { 45 editor.mirrorVert = !editor.mirrorVert; 46 editor.refreshMesh(); 47 } 48 incTooltip(_("Mirror Vertically")); 49 igEndGroup(); 50 51 igBeginGroup(); 52 if (incButtonColored("", ImVec2(0, 0), 53 editor.previewTriangulate ? ImVec4(1, 1, 0, 1) : ImVec4.init)) { 54 editor.previewTriangulate = !editor.previewTriangulate; 55 editor.refreshMesh(); 56 } 57 igSameLine(0, 4); 58 if (incButtonColored("", ImVec2(0, 0), 59 editor.previewingTriangulation() ? ImVec4.init : ImVec4(0.6, 0.6, 0.6, 1))) { 60 if (editor.previewingTriangulation()) { 61 editor.applyPreview(); 62 editor.refreshMesh(); 63 } 64 } 65 incTooltip(_("Automatically connects vertices")); 66 igEndGroup(); 67 68 } 69 70 void incViewportVertexOverlay() { 71 editor.viewportOverlay(); 72 } 73 74 void incViewportVertexUpdate(ImGuiIO* io, Camera camera) { 75 editor.update(io, camera); 76 } 77 78 void incViewportVertexDraw(Camera camera) { 79 // Draw the part that is currently being edited 80 auto target = editor.getTarget(); 81 if (target !is null) { 82 if (Part part = cast(Part)target) { 83 84 // Draw albedo texture at 0, 0 85 inDrawTextureAtPosition(part.textures[0], vec2(0, 0)); 86 } 87 } 88 89 editor.draw(camera); 90 } 91 92 void incViewportVertexToolbar() { } 93 94 void incViewportVertexToolSettings() { } 95 96 void incViewportVertexPresent() { 97 editor = new IncMeshEditor(false); 98 } 99 100 void incViewportVertexWithdraw() { 101 editor = null; 102 } 103 104 Drawable incVertexEditGetTarget() { 105 return editor.getTarget(); 106 } 107 108 void incVertexEditSetTarget(Drawable target) { 109 editor.setTarget(target); 110 } 111 112 void incVertexEditCopyMeshDataToTarget(MeshData data) { 113 editor.importMesh(data); 114 } 115 116 /** 117 Applies the mesh edits 118 */ 119 void incMeshEditApply() { 120 editor.applyToTarget(); 121 } 122 123 /** 124 Resets the mesh edits 125 */ 126 void incMeshEditClear() { 127 editor.mesh.clear(); 128 } 129 130 131 /** 132 Resets the mesh edits 133 */ 134 void incMeshEditReset() { 135 editor.mesh.reset(); 136 }