diff --git a/Sources/arm/App.hx b/Sources/arm/App.hx index af9a11ea..8d7b5e3a 100644 --- a/Sources/arm/App.hx +++ b/Sources/arm/App.hx @@ -154,7 +154,7 @@ class App { Project.projectNew(); // Spawn terrain plane #end if (fileArg != "") { - Importer.importFile(fileArg); + Importer.run(fileArg); // if (Path.isMesh(fileArg)) { // UITrait.inst.toggleDistractFree(); // } @@ -361,7 +361,7 @@ class App { if (!wait) { dropX = mouse.x; dropY = mouse.y; - Importer.importFile(dropPath, dropX, dropY); + Importer.run(dropPath, dropX, dropY); dropPath = ""; } } diff --git a/Sources/arm/Plugin.hx b/Sources/arm/Plugin.hx index afc7b225..74045833 100644 --- a/Sources/arm/Plugin.hx +++ b/Sources/arm/Plugin.hx @@ -73,6 +73,7 @@ class ArmBridge { public static var Plugin = arm.Plugin; public static var Project = arm.Project; public static var Res = arm.Res; + public static var Path = arm.util.Path; public static var NodesMaterial = arm.nodes.NodesMaterial; public static var Material = arm.nodes.Material; public static var Exporter = arm.io.Exporter; diff --git a/Sources/arm/Project.hx b/Sources/arm/Project.hx index 16262baa..9fc2b898 100644 --- a/Sources/arm/Project.hx +++ b/Sources/arm/Project.hx @@ -11,6 +11,7 @@ import iron.object.MeshObject; import iron.Scene; import arm.util.RenderUtil; import arm.util.ViewportUtil; +import arm.util.Path; import arm.ui.UITrait; import arm.ui.UINodes; import arm.ui.UIFiles; @@ -22,6 +23,7 @@ import arm.nodes.MaterialParser; import arm.io.Importer; import arm.io.ImportArm; import arm.io.ImportBlend; +import arm.io.ImportMesh; using StringTools; class Project { @@ -266,9 +268,9 @@ class Project { App.redrawUI(); UIFiles.show = true; UIFiles.isSave = false; - UIFiles.filters = "obj,fbx,stl,blend,arm"; + UIFiles.filters = Path.meshFormats.join(","); UIFiles.filesDone = function(path:String) { - Importer.importFile(path); + Importer.run(path); } } } @@ -277,18 +279,19 @@ class Project { public static function reimportMesh() { if (Project.meshAssets != null && Project.meshAssets.length > 0) { - Importer.importMesh(Project.meshAssets[0], false); + ImportMesh.run(Project.meshAssets[0], false); Log.showMessage("Mesh reimported."); } else importAsset(); } - public static function importAsset(filters = "jpg,png,tga,bmp,psd,gif,hdr,obj,fbx,stl,blend,arm") { + public static function importAsset(filters:String = null) { + if (filters == null) filters = Path.textureFormats.join(",") + "," + Path.meshFormats.join(","); UIFiles.show = true; UIFiles.isSave = false; UIFiles.filters = filters; UIFiles.filesDone = function(path:String) { - Importer.importFile(path); + Importer.run(path); } } } diff --git a/Sources/arm/io/ImportBlend.hx b/Sources/arm/io/ImportBlend.hx index d95ca076..d579f340 100644 --- a/Sources/arm/io/ImportBlend.hx +++ b/Sources/arm/io/ImportBlend.hx @@ -34,7 +34,7 @@ class ImportBlend { // trace(ob.get("type")); // 1 var m = bl.get("Mesh")[0]; - if (m == null) { Importer.makeMesh(null, path); return; } + if (m == null) { ImportMesh.makeMesh(null, path); return; } var totpoly = m.get("totpoly"); var numtri = 0; @@ -170,7 +170,7 @@ class ImportBlend { var name:String = m.get("id").get("name"); name = name.substring(2, name.length); var obj = {posa: posa, nora: nora, texa: texa, inda: inda, name: name, scalePos: scalePos, scaleTes: 1.0}; - Importer.makeMesh(obj, path); + ImportMesh.makeMesh(obj, path); Data.deleteBlob(path); }); } diff --git a/Sources/arm/io/ImportFbx.hx b/Sources/arm/io/ImportFbx.hx index 499da85b..6ee5acf8 100644 --- a/Sources/arm/io/ImportFbx.hx +++ b/Sources/arm/io/ImportFbx.hx @@ -11,9 +11,9 @@ class ImportFbx { Data.getBlob(path, function(b:Blob) { FbxParser.parseTransform = UITrait.inst.parseTransform; var obj = new FbxParser(b); - Importer.makeMesh(obj, path); + ImportMesh.makeMesh(obj, path); while (obj.next()) { - Importer.addMesh(obj); + ImportMesh.addMesh(obj); } Data.deleteBlob(path); }); diff --git a/Sources/arm/io/ImportGltf.hx b/Sources/arm/io/ImportGltf.hx index 65c66760..7340d264 100644 --- a/Sources/arm/io/ImportGltf.hx +++ b/Sources/arm/io/ImportGltf.hx @@ -9,7 +9,7 @@ class ImportGltf { public static function run(path:String) { Data.getBlob(path, function(b:Blob) { var obj = new GltfParser(b); - Importer.makeMesh(obj, path); + ImportMesh.makeMesh(obj, path); Data.deleteBlob(path); }); } diff --git a/Sources/arm/io/ImportMesh.hx b/Sources/arm/io/ImportMesh.hx new file mode 100644 index 00000000..72f07432 --- /dev/null +++ b/Sources/arm/io/ImportMesh.hx @@ -0,0 +1,262 @@ +package arm.io; + +import kha.Font; +import kha.arrays.Int16Array; +import iron.data.SceneFormat; +import iron.data.MeshData; +import iron.data.Data; +import iron.math.Vec4; +import iron.Scene; +import arm.util.MeshUtil; +import arm.util.UVUtil; +import arm.util.ViewportUtil; +import arm.util.Path; +import arm.ui.UITrait; +import arm.ui.UIView2D; +import arm.ui.UINodes; +import arm.Project; +import arm.Tool; +using StringTools; + +class ImportMesh { + + public static function run(path:String, _clearLayers = true) { + if (!Path.isMesh(path)) { + Log.showError(Strings.error1); + return; + } + + Importer.clearLayers = _clearLayers; + + #if arm_debug + var timer = iron.system.Time.realTime(); + #end + + var p = path.toLowerCase(); + if (p.endsWith(".obj")) ImportObj.run(path); + else if (p.endsWith(".fbx")) ImportFbx.run(path); + else if (p.endsWith(".stl")) ImportStl.run(path); + else if (p.endsWith(".blend")) ImportBlend.run(path); + else { + var ext = path.substr(path.lastIndexOf(".") + 1); + var importer = Path.meshImporters.get(ext); + importer(path, function() {}); + } + + if (Context.mergedObject != null) { + Context.mergedObject.remove(); + Data.deleteMesh(Context.mergedObject.data.handle); + Context.mergedObject = null; + } + + Context.selectPaintObject(Context.mainObject()); + + if (Project.paintObjects.length > 1) { + // Sort by name + Project.paintObjects.sort(function(a, b):Int { + if (a.name < b.name) return -1; + else if (a.name > b.name) return 1; + return 0; + }); + + // No mask by default + if (Context.mergedObject == null) MeshUtil.mergeMesh(); + Context.paintObject.skip_context = "paint"; + Context.mergedObject.visible = true; + } + Project.meshAssets = [path]; + + if (UITrait.inst.worktab.position == SpacePaint) { + ViewportUtil.scaleToBounds(); + } + + if (Context.paintObject.name == "") Context.paintObject.name = "Object"; + arm.nodes.MaterialParser.parseMeshMaterial(); + + UIView2D.inst.hwnd.redraws = 2; + + #if arm_debug + trace("Mesh imported in " + (iron.system.Time.realTime() - timer)); + #end + + #if kha_direct3d12 + arm.render.RenderPathRaytrace.ready = false; + #end + } + + public static function makeMesh(mesh:Dynamic, path:String) { + if (mesh == null || mesh.posa == null || mesh.nora == null || mesh.inda == null) { + Log.showError(Strings.error3); + return; + } + + var raw:TMeshData = null; + if (UITrait.inst.worktab.position == SpaceScene) { + raw = { + name: mesh.name, + vertex_arrays: [ + { values: mesh.posa, attrib: "pos" }, + { values: mesh.nora, attrib: "nor" } + ], + index_arrays: [ + { values: mesh.inda, material: 0 } + ], + scale_pos: mesh.scalePos, + scale_tex: mesh.scaleTex + }; + if (mesh.texa != null) raw.vertex_arrays.push({ values: mesh.texa, attrib: "tex" }); + } + else { + + if (mesh.texa == null) { + Log.showError(Strings.error4); + var verts = Std.int(mesh.posa.length / 4); + mesh.texa = new Int16Array(verts * 2); + var n = new Vec4(); + for (i in 0...verts) { + n.set(mesh.posa[i * 4] / 32767, mesh.posa[i * 4 + 1] / 32767, mesh.posa[i * 4 + 2] / 32767).normalize(); + // Sphere projection + // mesh.texa[i * 2 ] = Math.atan2(n.x, n.y) / (Math.PI * 2) + 0.5; + // mesh.texa[i * 2 + 1] = n.z * 0.5 + 0.5; + // Equirect + mesh.texa[i * 2 ] = Std.int(((Math.atan2(-n.z, n.x) + Math.PI) / (Math.PI * 2)) * 32767); + mesh.texa[i * 2 + 1] = Std.int((Math.acos(n.y) / Math.PI) * 32767); + } + } + raw = { + name: mesh.name, + vertex_arrays: [ + { values: mesh.posa, attrib: "pos" }, + { values: mesh.nora, attrib: "nor" }, + { values: mesh.texa, attrib: "tex" } + ], + index_arrays: [ + { values: mesh.inda, material: 0 } + ], + scale_pos: mesh.scalePos, + scale_tex: mesh.scaleTex + }; + } + + new MeshData(raw, function(md:MeshData) { + + // Append + if (UITrait.inst.worktab.position == SpaceScene) { + var mats = new haxe.ds.Vector(1); + mats[0] = Context.materialScene.data; + var object = Scene.active.addMeshObject(md, mats, Scene.active.getChild("Scene")); + path = path.replace("\\", "/"); + var ar = path.split("/"); + var s = ar[ar.length - 1]; + object.name = s.substring(0, s.length - 4); + + // md.geom.calculateAABB(); + // var aabb = md.geom.aabb; + // var dim = new TFloat32Array(3); + // dim[0] = aabb.x; + // dim[1] = aabb.y; + // dim[2] = aabb.z; + // object.raw.dimensions = dim; + #if arm_physics + object.addTrait(new armory.trait.physics.RigidBody(0.0)); + #end + + Context.selectObject(object); + } + // Replace + else { + Context.paintObject = Context.mainObject(); + + Context.selectPaintObject(Context.mainObject()); + for (i in 0...Project.paintObjects.length) { + var p = Project.paintObjects[i]; + if (p == Context.paintObject) continue; + Data.deleteMesh(p.data.handle); + p.remove(); + } + var handle = Context.paintObject.data.handle; + if (handle != "SceneSphere" && handle != "ScenePlane") { + Data.deleteMesh(handle); + } + + if (Importer.clearLayers) { + while (Project.layers.length > 1) { var l = Project.layers.pop(); l.unload(); } + Context.setLayer(Project.layers[0]); + iron.App.notifyOnRender(Layers.initLayers); + History.reset(); + } + + Context.paintObject.setData(md); + Context.paintObject.name = mesh.name; + + var g = Context.paintObject.data.geom; + var posbuf = g.vertexBufferMap.get("pos"); + if (posbuf != null) { // Remove cache + posbuf.delete(); + g.vertexBufferMap.remove("pos"); + } + + Project.paintObjects = [Context.paintObject]; + } + + md.handle = raw.name; + Data.cachedMeshes.set(md.handle, md); + + Context.ddirty = 4; + UITrait.inst.hwnd.redraws = 2; + UITrait.inst.hwnd1.redraws = 2; + UITrait.inst.hwnd2.redraws = 2; + UVUtil.uvmapCached = false; + UVUtil.trianglemapCached = false; + }); + } + + public static function addMesh(mesh:Dynamic) { + + if (mesh.texa == null) { + Log.showError(Strings.error4); + var verts = Std.int(mesh.posa.length / 4); + mesh.texa = new Int16Array(verts * 2); + var n = new Vec4(); + for (i in 0...verts) { + n.set(mesh.posa[i * 4] / 32767, mesh.posa[i * 4 + 1] / 32767, mesh.posa[i * 4 + 2] / 32767).normalize(); + // Sphere projection + // mesh.texa[i * 2 ] = Math.atan2(n.x, n.y) / (Math.PI * 2) + 0.5; + // mesh.texa[i * 2 + 1] = n.z * 0.5 + 0.5; + // Equirect + mesh.texa[i * 2 ] = Std.int(((Math.atan2(-n.z, n.x) + Math.PI) / (Math.PI * 2)) * 32767); + mesh.texa[i * 2 + 1] = Std.int((Math.acos(n.y) / Math.PI) * 32767); + } + } + var raw:TMeshData = { + name: mesh.name, + vertex_arrays: [ + { values: mesh.posa, attrib: "pos" }, + { values: mesh.nora, attrib: "nor" }, + { values: mesh.texa, attrib: "tex" } + ], + index_arrays: [ + { values: mesh.inda, material: 0 } + ], + scale_pos: mesh.scalePos, + scale_tex: mesh.scaleTex + }; + + new MeshData(raw, function(md:MeshData) { + + var object = Scene.active.addMeshObject(md, Context.paintObject.materials, Context.paintObject); + object.name = mesh.name; + object.skip_context = "paint"; + + Project.paintObjects.push(object); + + md.handle = raw.name; + Data.cachedMeshes.set(md.handle, md); + + Context.ddirty = 4; + UITrait.inst.hwnd.redraws = 2; + UVUtil.uvmapCached = false; + UVUtil.trianglemapCached = false; + }); + } +} diff --git a/Sources/arm/io/ImportObj.hx b/Sources/arm/io/ImportObj.hx index dca06b5b..4ac3743c 100644 --- a/Sources/arm/io/ImportObj.hx +++ b/Sources/arm/io/ImportObj.hx @@ -19,15 +19,15 @@ class ImportObj { var v = Std.int(i / obj.udimsU); obj.name = name + "." + (1000 + v * 10 + u + 1); obj.inda = obj.udims[i]; - i == 0 ? Importer.makeMesh(obj, path) : Importer.addMesh(obj); + i == 0 ? ImportMesh.makeMesh(obj, path) : ImportMesh.addMesh(obj); } } else { var obj = new ObjParser(b); - Importer.makeMesh(obj, path); + ImportMesh.makeMesh(obj, path); while (obj.hasNext) { obj = new ObjParser(b, obj.pos); - Importer.addMesh(obj); + ImportMesh.addMesh(obj); } } Data.deleteBlob(path); diff --git a/Sources/arm/io/ImportStl.hx b/Sources/arm/io/ImportStl.hx index f6b392c8..c69b0496 100644 --- a/Sources/arm/io/ImportStl.hx +++ b/Sources/arm/io/ImportStl.hx @@ -14,7 +14,7 @@ class ImportStl { var p = path.replace("\\", "/"); var index = p.lastIndexOf("/"); obj.name = p.substring(index >= 0 ? index + 1 : 0, p.length - 4); - Importer.makeMesh(obj, path); + ImportMesh.makeMesh(obj, path); Data.deleteBlob(path); }); } diff --git a/Sources/arm/io/ImportTexture.hx b/Sources/arm/io/ImportTexture.hx index 0cf6462b..86409695 100644 --- a/Sources/arm/io/ImportTexture.hx +++ b/Sources/arm/io/ImportTexture.hx @@ -17,7 +17,12 @@ class ImportTexture { for (a in Project.assets) if (a.file == path) { Log.showMessage(Strings.info0); return; } - Data.getImage(path, function(image:Image) { + var ext = path.substr(path.lastIndexOf(".") + 1); + var importer = Path.textureImporters.get(ext); + if (importer == null) importer = defaultImporter; + + importer(path, function(image:Image) { + Data.cachedImages.set(path, image); var ar = path.split("/"); ar = ar[ar.length - 1].split("\\"); var name = ar[ar.length - 1]; @@ -35,4 +40,8 @@ class ImportTexture { } }); } + + static function defaultImporter(path:String, done:Image->Void) { + Data.getImage(path, done); + } } diff --git a/Sources/arm/io/Importer.hx b/Sources/arm/io/Importer.hx index 51163703..bc88d37c 100644 --- a/Sources/arm/io/Importer.hx +++ b/Sources/arm/io/Importer.hx @@ -24,10 +24,10 @@ class Importer { public static var fontMap = new Map(); public static var clearLayers = true; - public static function importFile(path:String, dropX = -1.0, dropY = -1.0) { + public static function run(path:String, dropX = -1.0, dropY = -1.0) { // Mesh if (Path.isMesh(path)) { - importMesh(path); + ImportMesh.run(path); } // Image else if (Path.isTexture(path)) { @@ -61,239 +61,4 @@ class Importer { Log.showError(Strings.error1); } } - - public static function importMesh(path:String, _clearLayers = true) { - if (!Path.isMesh(path)) { - Log.showError(Strings.error1); - return; - } - - clearLayers = _clearLayers; - - #if arm_debug - var timer = iron.system.Time.realTime(); - #end - - var p = path.toLowerCase(); - if (p.endsWith(".obj")) ImportObj.run(path); - else if (p.endsWith(".fbx")) ImportFbx.run(path); - else if (p.endsWith(".stl")) ImportStl.run(path); - else if (p.endsWith(".blend")) ImportBlend.run(path); - - if (Context.mergedObject != null) { - Context.mergedObject.remove(); - Data.deleteMesh(Context.mergedObject.data.handle); - Context.mergedObject = null; - } - - Context.selectPaintObject(Context.mainObject()); - - if (Project.paintObjects.length > 1) { - // Sort by name - Project.paintObjects.sort(function(a, b):Int { - if (a.name < b.name) return -1; - else if (a.name > b.name) return 1; - return 0; - }); - - // No mask by default - if (Context.mergedObject == null) MeshUtil.mergeMesh(); - Context.paintObject.skip_context = "paint"; - Context.mergedObject.visible = true; - } - Project.meshAssets = [path]; - - if (UITrait.inst.worktab.position == SpacePaint) { - ViewportUtil.scaleToBounds(); - } - - if (Context.paintObject.name == "") Context.paintObject.name = "Object"; - arm.nodes.MaterialParser.parseMeshMaterial(); - - UIView2D.inst.hwnd.redraws = 2; - - #if arm_debug - trace("Mesh imported in " + (iron.system.Time.realTime() - timer)); - #end - - #if kha_direct3d12 - arm.render.RenderPathRaytrace.ready = false; - #end - } - - public static function makeMesh(mesh:Dynamic, path:String) { - if (mesh == null || mesh.posa == null || mesh.nora == null || mesh.inda == null) { - Log.showError(Strings.error3); - return; - } - - var raw:TMeshData = null; - if (UITrait.inst.worktab.position == SpaceScene) { - raw = { - name: mesh.name, - vertex_arrays: [ - { values: mesh.posa, attrib: "pos" }, - { values: mesh.nora, attrib: "nor" } - ], - index_arrays: [ - { values: mesh.inda, material: 0 } - ], - scale_pos: mesh.scalePos, - scale_tex: mesh.scaleTex - }; - if (mesh.texa != null) raw.vertex_arrays.push({ values: mesh.texa, attrib: "tex" }); - } - else { - - if (mesh.texa == null) { - Log.showError(Strings.error4); - var verts = Std.int(mesh.posa.length / 4); - mesh.texa = new Int16Array(verts * 2); - var n = new Vec4(); - for (i in 0...verts) { - n.set(mesh.posa[i * 4] / 32767, mesh.posa[i * 4 + 1] / 32767, mesh.posa[i * 4 + 2] / 32767).normalize(); - // Sphere projection - // mesh.texa[i * 2 ] = Math.atan2(n.x, n.y) / (Math.PI * 2) + 0.5; - // mesh.texa[i * 2 + 1] = n.z * 0.5 + 0.5; - // Equirect - mesh.texa[i * 2 ] = Std.int(((Math.atan2(-n.z, n.x) + Math.PI) / (Math.PI * 2)) * 32767); - mesh.texa[i * 2 + 1] = Std.int((Math.acos(n.y) / Math.PI) * 32767); - } - } - raw = { - name: mesh.name, - vertex_arrays: [ - { values: mesh.posa, attrib: "pos" }, - { values: mesh.nora, attrib: "nor" }, - { values: mesh.texa, attrib: "tex" } - ], - index_arrays: [ - { values: mesh.inda, material: 0 } - ], - scale_pos: mesh.scalePos, - scale_tex: mesh.scaleTex - }; - } - - new MeshData(raw, function(md:MeshData) { - - // Append - if (UITrait.inst.worktab.position == SpaceScene) { - var mats = new haxe.ds.Vector(1); - mats[0] = Context.materialScene.data; - var object = Scene.active.addMeshObject(md, mats, Scene.active.getChild("Scene")); - path = path.replace("\\", "/"); - var ar = path.split("/"); - var s = ar[ar.length - 1]; - object.name = s.substring(0, s.length - 4); - - // md.geom.calculateAABB(); - // var aabb = md.geom.aabb; - // var dim = new TFloat32Array(3); - // dim[0] = aabb.x; - // dim[1] = aabb.y; - // dim[2] = aabb.z; - // object.raw.dimensions = dim; - #if arm_physics - object.addTrait(new armory.trait.physics.RigidBody(0.0)); - #end - - Context.selectObject(object); - } - // Replace - else { - Context.paintObject = Context.mainObject(); - - Context.selectPaintObject(Context.mainObject()); - for (i in 0...Project.paintObjects.length) { - var p = Project.paintObjects[i]; - if (p == Context.paintObject) continue; - Data.deleteMesh(p.data.handle); - p.remove(); - } - var handle = Context.paintObject.data.handle; - if (handle != "SceneSphere" && handle != "ScenePlane") { - Data.deleteMesh(handle); - } - - if (clearLayers) { - while (Project.layers.length > 1) { var l = Project.layers.pop(); l.unload(); } - Context.setLayer(Project.layers[0]); - iron.App.notifyOnRender(Layers.initLayers); - History.reset(); - } - - Context.paintObject.setData(md); - Context.paintObject.name = mesh.name; - - var g = Context.paintObject.data.geom; - var posbuf = g.vertexBufferMap.get("pos"); - if (posbuf != null) { // Remove cache - posbuf.delete(); - g.vertexBufferMap.remove("pos"); - } - - Project.paintObjects = [Context.paintObject]; - } - - md.handle = raw.name; - Data.cachedMeshes.set(md.handle, md); - - Context.ddirty = 4; - UITrait.inst.hwnd.redraws = 2; - UITrait.inst.hwnd1.redraws = 2; - UITrait.inst.hwnd2.redraws = 2; - UVUtil.uvmapCached = false; - UVUtil.trianglemapCached = false; - }); - } - - public static function addMesh(mesh:Dynamic) { - - if (mesh.texa == null) { - Log.showError(Strings.error4); - var verts = Std.int(mesh.posa.length / 4); - mesh.texa = new Int16Array(verts * 2); - var n = new Vec4(); - for (i in 0...verts) { - n.set(mesh.posa[i * 4] / 32767, mesh.posa[i * 4 + 1] / 32767, mesh.posa[i * 4 + 2] / 32767).normalize(); - // Sphere projection - // mesh.texa[i * 2 ] = Math.atan2(n.x, n.y) / (Math.PI * 2) + 0.5; - // mesh.texa[i * 2 + 1] = n.z * 0.5 + 0.5; - // Equirect - mesh.texa[i * 2 ] = Std.int(((Math.atan2(-n.z, n.x) + Math.PI) / (Math.PI * 2)) * 32767); - mesh.texa[i * 2 + 1] = Std.int((Math.acos(n.y) / Math.PI) * 32767); - } - } - var raw:TMeshData = { - name: mesh.name, - vertex_arrays: [ - { values: mesh.posa, attrib: "pos" }, - { values: mesh.nora, attrib: "nor" }, - { values: mesh.texa, attrib: "tex" } - ], - index_arrays: [ - { values: mesh.inda, material: 0 } - ], - scale_pos: mesh.scalePos, - scale_tex: mesh.scaleTex - }; - - new MeshData(raw, function(md:MeshData) { - - var object = Scene.active.addMeshObject(md, Context.paintObject.materials, Context.paintObject); - object.name = mesh.name; - object.skip_context = "paint"; - - Project.paintObjects.push(object); - - md.handle = raw.name; - Data.cachedMeshes.set(md.handle, md); - - Context.ddirty = 4; - UITrait.inst.hwnd.redraws = 2; - UVUtil.uvmapCached = false; - UVUtil.trianglemapCached = false; - }); - } } diff --git a/Sources/arm/ui/TabTextures.hx b/Sources/arm/ui/TabTextures.hx index cde90d25..b1a92b7a 100644 --- a/Sources/arm/ui/TabTextures.hx +++ b/Sources/arm/ui/TabTextures.hx @@ -5,6 +5,7 @@ import iron.data.Data; import iron.system.Time; import iron.system.Input; import arm.io.Importer; +import arm.util.Path; using StringTools; class TabTextures { @@ -18,9 +19,9 @@ class TabTextures { if (ui.button("Import")) { UIFiles.show = true; UIFiles.isSave = false; - UIFiles.filters = "jpg,png,tga,bmp,psd,gif,hdr"; + UIFiles.filters = Path.textureFormats.join(","); UIFiles.filesDone = function(path:String) { - Importer.importFile(path); + Importer.run(path); } } if (ui.isHovered) ui.tooltip("Import texture file (" + Config.keymap.file_import_assets + ")"); diff --git a/Sources/arm/ui/TabViewport.hx b/Sources/arm/ui/TabViewport.hx index 580ee623..5437a0ff 100644 --- a/Sources/arm/ui/TabViewport.hx +++ b/Sources/arm/ui/TabViewport.hx @@ -25,7 +25,7 @@ class TabViewport { Log.showError("Error: .hdr file expected"); return; } - Importer.importFile(path); + Importer.run(path); } } diff --git a/Sources/arm/ui/UIMenu.hx b/Sources/arm/ui/UIMenu.hx index 60267633..47cc1253 100644 --- a/Sources/arm/ui/UIMenu.hx +++ b/Sources/arm/ui/UIMenu.hx @@ -8,6 +8,7 @@ import iron.system.Input; import iron.data.Data; import arm.util.ViewportUtil; import arm.util.BuildMacros; +import arm.util.Path; using StringTools; class UIMenu { @@ -68,7 +69,7 @@ class UIMenu { if (ui.button("Save", Left, Config.keymap.file_save)) Project.projectSave(); if (ui.button("Save As...", Left, Config.keymap.file_save_as)) Project.projectSaveAs(); ui.fill(0, 0, sepw, 1, ui.t.ACCENT_SELECT_COL); - if (ui.button("Import Texture...", Left, Config.keymap.file_import_assets)) Project.importAsset("jpg,png,tga,bmp,psd,gif,hdr"); + if (ui.button("Import Texture...", Left, Config.keymap.file_import_assets)) Project.importAsset(Path.textureFormats.join(",")); if (ui.button("Import Font...", Left)) Project.importAsset("ttf"); if (ui.button("Import Material...", Left)) Project.importMaterial(); if (ui.button("Import Mesh...", Left)) Project.importMesh(); diff --git a/Sources/arm/util/Path.hx b/Sources/arm/util/Path.hx index 3fbcf36d..1f6399f4 100644 --- a/Sources/arm/util/Path.hx +++ b/Sources/arm/util/Path.hx @@ -4,6 +4,12 @@ using StringTools; class Path { + public static var meshFormats = ["obj", "fbx", "stl", "blend"]; + public static var textureFormats = ["jpg", "jpeg", "png", "tga", "bmp", "psd", "gif", "hdr"]; + + public static var meshImporters = new Map(Void->Void)->Void>(); + public static var textureImporters = new Map(kha.Image->Void)->Void>(); + public static function toRelative(from:String, to:String):String { from = haxe.io.Path.normalize(from); to = haxe.io.Path.normalize(to); @@ -31,22 +37,14 @@ class Path { public static function isMesh(path:String):Bool { var p = path.toLowerCase(); - return p.endsWith(".obj") || - p.endsWith(".fbx") || - p.endsWith(".stl") || - p.endsWith(".blend"); + for (s in meshFormats) if (p.endsWith("." + s)) return true; + return false; } public static function isTexture(path:String):Bool { var p = path.toLowerCase(); - return p.endsWith(".jpg") || - p.endsWith(".jpeg") || - p.endsWith(".png") || - p.endsWith(".tga") || - p.endsWith(".bmp") || - p.endsWith(".psd") || - p.endsWith(".gif") || - p.endsWith(".hdr"); + for (s in textureFormats) if (p.endsWith("." + s)) return true; + return false; } public static function isFont(path:String):Bool {