diff --git a/Sources/arm/Project.hx b/Sources/arm/Project.hx index e91e48c2..3bd6071e 100644 --- a/Sources/arm/Project.hx +++ b/Sources/arm/Project.hx @@ -349,13 +349,13 @@ class Project { }); } - public static function importMesh() { + public static function importMesh(replaceExisting = true) { UIFiles.show(Path.meshFormats.join(","), false, function(path: String) { - importMeshBox(path); + importMeshBox(path, replaceExisting); }); } - public static function importMeshBox(path: String) { + public static function importMeshBox(path: String, replaceExisting = true) { #if krom_ios // Import immediately while access to resource is unlocked @@ -392,7 +392,7 @@ class Project { if (ui.button(tr("Import")) || ui.isReturnDown) { UIBox.show = false; App.redrawUI(); - ImportMesh.run(path, true, true); + ImportMesh.run(path, true, replaceExisting); } if (ui.button(tr("?"))) { File.explorer("https://github.com/armory3d/armorpaint_docs/blob/master/faq.md"); diff --git a/Sources/arm/io/ImportMesh.hx b/Sources/arm/io/ImportMesh.hx index ac940ed0..8d30aab5 100644 --- a/Sources/arm/io/ImportMesh.hx +++ b/Sources/arm/io/ImportMesh.hx @@ -18,10 +18,9 @@ import arm.Enums; class ImportMesh { - public static var clearLayers = true; - public static var replaceExisting = true; + static var clearLayers = true; - public static function run(path: String, _clearLayers = true, _replaceExisting = true) { + public static function run(path: String, _clearLayers = true, replaceExisting = true) { if (!Path.isMesh(path)) { if (!Context.enableImportPlugin(path)) { Log.error(Strings.error1()); @@ -30,7 +29,6 @@ class ImportMesh { } clearLayers = _clearLayers; - replaceExisting = _replaceExisting; Context.layerFilter = 0; #if arm_debug @@ -45,7 +43,7 @@ class ImportMesh { var ext = path.substr(path.lastIndexOf(".") + 1); var importer = Path.meshImporters.get(ext); importer(path, function(mesh: Dynamic) { - ImportMesh.makeMesh(mesh, path); + replaceExisting ? ImportMesh.makeMesh(mesh, path) : ImportMesh.addMesh(mesh); }); } @@ -72,9 +70,7 @@ class ImportMesh { } Project.meshAssets = [path]; - if (replaceExisting) { - ViewportUtil.scaleToBounds(); - } + ViewportUtil.scaleToBounds(); if (Context.paintObject.name == "") Context.paintObject.name = "Object"; arm.node.MakeMaterial.parsePaintMaterial(); @@ -103,42 +99,31 @@ class ImportMesh { if (mesh.cola != null) raw.vertex_arrays.push({ values: mesh.cola, attrib: "col", data: "short4norm", padding: 1 }); new MeshData(raw, function(md: MeshData) { - if (replaceExisting) { - Context.paintObject = Context.mainObject(); + 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 > 0) { var l = Project.layers.pop(); l.unload(); } - Layers.newLayer(false); - iron.App.notifyOnInit(Layers.initLayers); - History.reset(); - } - - Context.paintObject.setData(md); - Context.paintObject.name = mesh.name; - Project.paintObjects = [Context.paintObject]; + 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(); } - else { // Append - // var mats = new haxe.ds.Vector(1); - // mats[0] = Context.materialScene.data; - // var object = Scene.active.addMeshObject(md, mats, Scene.active.getChild("Scene")); - // var ar = path.split(Path.sep); - // var s = ar[ar.length - 1]; - // object.name = s.substring(0, s.length - 4); - // Context.selectObject(object); + var handle = Context.paintObject.data.handle; + if (handle != "SceneSphere" && handle != "ScenePlane") { + Data.deleteMesh(handle); } + if (clearLayers) { + while (Project.layers.length > 0) { var l = Project.layers.pop(); l.unload(); } + Layers.newLayer(false); + iron.App.notifyOnInit(Layers.initLayers); + History.reset(); + } + + Context.paintObject.setData(md); + Context.paintObject.name = mesh.name; + Project.paintObjects = [Context.paintObject]; + md.handle = raw.name; Data.cachedMeshes.set(md.handle, md); diff --git a/Sources/arm/ui/TabMeshes.hx b/Sources/arm/ui/TabMeshes.hx index f7e5937e..5bd08707 100644 --- a/Sources/arm/ui/TabMeshes.hx +++ b/Sources/arm/ui/TabMeshes.hx @@ -14,7 +14,17 @@ class TabMeshes { ui.beginSticky(); ui.row([1 / 4, 1 / 4]); - if (ui.button(tr("Import"))) Project.importMesh(); + if (ui.button(tr("Import"))) { + UIMenu.draw(function(ui: Zui) { + ui.text(tr("Import"), Right, ui.t.HIGHLIGHT_COL); + if (ui.button(tr("Replace Existing"), Left)) { + Project.importMesh(true); + } + if (ui.button(tr("Append"), Left)) { + Project.importMesh(false); + } + }, 3); + } if (ui.isHovered) ui.tooltip(tr("Import mesh file") + ' (${Config.keymap.file_import_assets})'); if (ui.button(tr("Tools..."))) {