1 module creator.medit; 2 import creator.core; 3 import inochi2d; 4 import std.exception; 5 import bindbc.opengl; 6 public import creator.medit.mesh; 7 8 private { 9 Drawable target; 10 MeshData editingData; 11 bool hasEdited; 12 13 GLuint vboPoints; 14 GLuint vboSegments; 15 16 IncMesh editingMesh; 17 } 18 19 void incMeshEditSetTarget(Drawable target_) { 20 target = target_; 21 editingMesh = new IncMesh(target_.getMesh()); 22 } 23 24 void incMeshEditReset() { 25 editingData = target.getMesh.copy(); 26 } 27 28 /** 29 Maps UV coordinates from world-space to texture space 30 */ 31 void incMeshEditMapUV(ref vec2 uv) { 32 uv -= vec2(incMeshEditWorldPos()); 33 if (Part part = cast(Part)target) { 34 35 // Texture 0 is always albedo texture 36 auto tex = part.textures[0]; 37 38 // By dividing by width and height we should get the values in UV coordinate space. 39 uv.x /= cast(float)tex.width; 40 uv.y /= cast(float)tex.height; 41 } 42 } 43 44 void incMeshEditBarrier() { 45 //if () 46 } 47 48 void incMeshEditDbg() { 49 editingData.dbg(); 50 } 51 52 bool incMeshEditCanTriangulate() { 53 return false; 54 } 55 56 bool incMeshEditCanApply() { 57 return editingData.isReady(); 58 } 59 60 void incMeshEditApply() { 61 enforce(editingData.isReady(), "Mesh is incomplete and cannot be applied."); 62 hasEdited = false; 63 64 // Fix winding order 65 editingData.fixWinding(); 66 target.getMesh() = editingData; 67 } 68 69 bool incMeshEditIsEdited() { 70 return hasEdited; 71 } 72 73 vec3 incMeshEditWorldPos() { 74 return vec3(target.transform.matrix() * vec4(1, 1, 1, 1)); 75 }