This commit is contained in:
luboslenco
2019-06-20 12:30:31 +02:00
parent 54c4b35492
commit 53a6f8c7bb
15 changed files with 96 additions and 80 deletions
+3 -2
View File
@@ -24,6 +24,7 @@ import arm.data.MaterialSlot;
import arm.data.ConstData;
import arm.Config;
import arm.Tool;
using StringTools;
class App {
@@ -75,9 +76,9 @@ class App {
System.notifyOnDropFiles(function(filePath:String) {
if (!checkAscii(filePath)) return;
dropPath = filePath;
dropPath = StringTools.replace(dropPath, "%20", " "); // Linux can pass %20 on drop
dropPath = dropPath.replace("%20", " "); // Linux can pass %20 on drop
dropPath = dropPath.split("file://")[0]; // Multiple files dropped on Linux, take first
dropPath = StringTools.rtrim(dropPath);
dropPath = dropPath.rtrim();
});
#if krom_windows
+3 -2
View File
@@ -20,6 +20,7 @@ import arm.data.MaterialSlot;
import arm.nodes.MaterialParser;
import arm.io.ImportArm;
import arm.App;
using StringTools;
class Project {
public static function projectOpen() {
@@ -29,7 +30,7 @@ class Project {
App.showFilename = false;
UIFiles.filters = "arm";
App.filesDone = function(path:String) {
if (!StringTools.endsWith(path, ".arm")) {
if (!path.endsWith(".arm")) {
UITrait.inst.showError(Strings.error5);
return;
}
@@ -62,7 +63,7 @@ class Project {
var f = App.filenameHandle.text;
if (f == "") f = "untitled";
UITrait.inst.projectPath = path + "/" + f;
if (!StringTools.endsWith(UITrait.inst.projectPath, ".arm")) UITrait.inst.projectPath += ".arm";
if (!UITrait.inst.projectPath.endsWith(".arm")) UITrait.inst.projectPath += ".arm";
projectSave();
};
}
+2 -1
View File
@@ -10,13 +10,14 @@ import arm.util.Lz4;
import arm.util.Path;
import arm.Project;
import arm.App;
using StringTools;
class ExportArm {
public static function run(path:String) {
var raw:TSceneFormat = { mesh_datas: [ UITrait.inst.paintObject.data.raw ] };
var b = ArmPack.encode(raw);
if (!StringTools.endsWith(path, ".arm")) path += ".arm";
if (!path.endsWith(".arm")) path += ".arm";
#if kha_krom
Krom.fileSaveBytes(path, b.getData());
#end
+2 -1
View File
@@ -2,6 +2,7 @@ package arm.io;
import haxe.io.Bytes;
import arm.ui.UITrait;
using StringTools;
class ExportObj {
@@ -41,7 +42,7 @@ class ExportObj {
}
off += inda.length;
}
if (!StringTools.endsWith(path, ".obj")) path += ".obj";
if (!path.endsWith(".obj")) path += ".obj";
#if kha_krom
Krom.fileSaveBytes(path, Bytes.ofString(s).getData());
#end
+2 -1
View File
@@ -11,6 +11,7 @@ import iron.format.PngTools;
import arm.ui.UITrait;
import arm.ui.UIBox;
import arm.App;
using StringTools;
class Exporter {
@@ -56,7 +57,7 @@ class Exporter {
var formatType = UITrait.inst.formatType;
var bits = UITrait.inst.bitsHandle.position == 0 ? 8 : 16;
var ext = bits == 16 ? ".exr" : formatType == 0 ? ".png" : ".jpg";
if (StringTools.endsWith(f, ext)) f = f.substr(0, f.length - 4);
if (f.endsWith(ext)) f = f.substr(0, f.length - 4);
var texpaint:Image = null;
var texpaint_nor:Image = null;
var texpaint_pack:Image = null;
+10 -9
View File
@@ -16,6 +16,7 @@ import arm.nodes.MaterialParser;
import arm.util.Path;
import arm.util.RenderUtil;
import arm.data.MaterialSlot;
using StringTools;
class ImportBlend {
@@ -232,7 +233,7 @@ class ImportBlend {
for (list in NodesMaterial.list) {
var found = false;
for (n in list) {
var s = StringTools.replace(n.type, "_", "").toLowerCase();
var s = n.type.replace("_", "").toLowerCase();
if (search == s) {
base = n;
found = true;
@@ -265,8 +266,8 @@ class ImportBlend {
// Fill output socket values
if (search == "teximage") {
var img = node.get("id", 0, "Image");
var file = img.get("name").substr(2); // '//desktop\logo.png'
file = StringTools.replace(file, "\\", "/");
var file:String = img.get("name").substr(2); // '//desktop\logo.png'
file = file.replace("\\", "/");
file = Path.baseDir(path) + file;
ImportTexture.run(file);
n.buttons[0].default_value = App.getAssetIndex(file);
@@ -366,22 +367,22 @@ class ImportBlend {
static function readBlendSocket(sock:Dynamic):Dynamic {
var idname = sock.get("idname");
if (StringTools.startsWith(idname, "NodeSocketVector")) {
if (idname.startsWith("NodeSocketVector")) {
return sock.get("default_value", 0, "bNodeSocketValueVector").get("value");
}
else if (StringTools.startsWith(idname, "NodeSocketColor")) {
else if (idname.startsWith("NodeSocketColor")) {
return sock.get("default_value", 0, "bNodeSocketValueRGBA").get("value");
}
else if (StringTools.startsWith(idname, "NodeSocketFloat")) {
else if (idname.startsWith("NodeSocketFloat")) {
return sock.get("default_value", 0, "bNodeSocketValueFloat").get("value");
}
else if (StringTools.startsWith(idname, "NodeSocketInt")) {
else if (idname.startsWith("NodeSocketInt")) {
return sock.get("default_value", 0, "bNodeSocketValueInt").get("value");
}
else if (StringTools.startsWith(idname, "NodeSocketBoolean")) {
else if (idname.startsWith("NodeSocketBoolean")) {
return sock.get("default_value", 0, "bNodeSocketValueBoolean").get("value");
}
else if (StringTools.startsWith(idname, "NodeSocketString")) {
else if (idname.startsWith("NodeSocketString")) {
return sock.get("default_value", 0, "bNodeSocketValueString").get("value");
}
return null;
+3 -2
View File
@@ -7,6 +7,7 @@ import kha.arrays.Float32Array;
import iron.data.Data;
import iron.Scene;
import arm.ui.UITrait;
using StringTools;
class ImportEnvmap {
@@ -71,8 +72,8 @@ class ImportEnvmap {
band1 = band1.substring(band1.indexOf("{"), band1.length);
band2 = band2.substring(band2.indexOf("{"), band2.length);
var band = band0 + band1 + band2;
band = StringTools.replace(band, "{", "");
band = StringTools.replace(band, "}", "");
band = band.replace("{", "");
band = band.replace("}", "");
var ar = band.split(",");
var buf = new Float32Array(27);
for (i in 0...ar.length) buf[i] = Std.parseFloat(ar[i]);
+4 -3
View File
@@ -13,6 +13,7 @@ import arm.nodes.MaterialParser;
import arm.data.MaterialSlot;
import arm.Tool;
import arm.App;
using StringTools;
class ImportFolder {
@@ -44,12 +45,12 @@ class ImportFolder {
// Import maps
for (f in files) {
if (f.length == 0) continue;
f = StringTools.rtrim(f);
f = f.rtrim();
if (!Path.checkTextureFormat(f)) continue;
f = path + sep + f;
#if krom_windows
f = StringTools.replace(f, "/", "\\");
f = f.replace("/", "\\");
#end
// TODO: handle -albedo
@@ -103,7 +104,7 @@ class ImportFolder {
UINodes.inst.updateCanvasMap();
var nodes = UINodes.inst.nodes;
var canvas = UINodes.inst.canvas;
var dirs = StringTools.replace(path, "\\", "/").split("/");
var dirs = path.replace("\\", "/").split("/");
canvas.name = dirs[dirs.length - 1];
var nout:TNode = null;
for (n in canvas.nodes) if (n.type == "OUTPUT_MATERIAL_PBR") { nout = n; break; }
+2 -1
View File
@@ -5,6 +5,7 @@ import zui.Canvas;
import iron.data.Data;
import arm.ui.UITrait;
import arm.util.Path;
using StringTools;
class ImportTexture {
@@ -28,7 +29,7 @@ class ImportTexture {
UITrait.inst.hwnd2.redraws = 2;
// Set envmap
if (StringTools.endsWith(path.toLowerCase(), ".hdr") &&
if (path.toLowerCase().endsWith(".hdr") &&
(image.width == 1024 || image.width == 2048 || image.width == 4096)) {
ImportEnvmap.run(path, image);
}
+6 -5
View File
@@ -16,6 +16,7 @@ import arm.ui.UIView2D;
import arm.ui.UINodes;
import arm.Project;
import arm.Tool;
using StringTools;
class Importer {
@@ -67,10 +68,10 @@ class Importer {
#end
var p = path.toLowerCase();
if (StringTools.endsWith(p, ".obj")) ImportObj.run(path);
else if (StringTools.endsWith(p, ".gltf")) ImportGltf.run(path);
else if (StringTools.endsWith(p, ".fbx")) ImportFbx.run(path);
else if (StringTools.endsWith(p, ".blend")) ImportBlend.run(path);
if (p.endsWith(".obj")) ImportObj.run(path);
else if (p.endsWith(".gltf")) ImportGltf.run(path);
else if (p.endsWith(".fbx")) ImportFbx.run(path);
else if (p.endsWith(".blend")) ImportBlend.run(path);
if (UITrait.inst.mergedObject != null) {
UITrait.inst.mergedObject.remove();
@@ -166,7 +167,7 @@ class Importer {
var mats = new haxe.ds.Vector(1);
mats[0] = UITrait.inst.selectedMaterialScene.data;
var object = Scene.active.addMeshObject(md, mats, Scene.active.getChild("Scene"));
path = StringTools.replace(path, "\\", "/");
path = path.replace("\\", "/");
var ar = path.split("/");
var s = ar[ar.length - 1];
object.name = s.substring(0, s.length - 4);
+2 -1
View File
@@ -7,6 +7,7 @@ import iron.RenderPath;
import arm.ui.UITrait;
import arm.util.UVUtil;
import arm.Tool;
using StringTools;
class Uniforms {
public static function init() {
@@ -129,7 +130,7 @@ class Uniforms {
var i = UITrait.inst.undoI - 1 < 0 ? App.C.undo_steps - 1 : UITrait.inst.undoI - 1;
return RenderPath.active.renderTargets.get("texpaint_pack_undo" + i).image;
}
else if (StringTools.startsWith(link, "_texpaint_pack_vert")) {
else if (link.startsWith("_texpaint_pack_vert")) {
var tid = link.substr(19);
return RenderPath.active.renderTargets.get("texpaint_pack" + tid).image;
}
+3 -2
View File
@@ -3,6 +3,7 @@ package arm.ui;
import zui.Id;
import iron.system.Input;
import arm.App;
using StringTools;
class UIFiles {
@@ -18,8 +19,8 @@ class UIFiles {
App.path = untyped App.foldersOnly ? Krom.saveDialog(filters, "") : Krom.openDialog(filters, "");
if (App.path != null) {
if (!App.checkAscii(App.path)) return;
App.path = StringTools.replace(App.path, "\\\\", "\\");
App.path = StringTools.replace(App.path, "\r", "");
App.path = App.path.replace("\\\\", "\\");
App.path = App.path.replace("\r", "");
#if krom_windows
var sep = "\\";
#else
+2 -1
View File
@@ -8,6 +8,7 @@ import iron.system.Input;
import iron.data.Data;
import arm.App;
import arm.util.ViewportUtil;
using StringTools;
class UIMenu {
@@ -138,7 +139,7 @@ class UIMenu {
var updateVersion = Std.int(update.version);
if (updateVersion > 0) {
var date = Macro.buildDate().split(" ")[0].substr(2); // 2019 -> 19
var dateInt = Std.parseInt(StringTools.replace(date, "-", ""));
var dateInt = Std.parseInt(date.replace("-", ""));
if (updateVersion > dateInt) {
UIBox.showMessage("Update is available!\nPlease visit armorpaint.org to download.");
}
+3 -2
View File
@@ -32,6 +32,7 @@ import arm.io.ExportArm;
import arm.Project;
import arm.Tool;
import arm.App;
using StringTools;
@:access(zui.Zui)
class UITrait {
@@ -1901,7 +1902,7 @@ class UITrait {
App.showFilename = false;
UIFiles.filters = "arm,blend";
App.filesDone = function(path:String) {
StringTools.endsWith(path, ".blend") ?
path.endsWith(".blend") ?
ImportBlend.runMaterial(path) :
ImportArm.runMaterial(path);
}
@@ -2305,7 +2306,7 @@ class UITrait {
App.showFilename = false;
UIFiles.filters = "hdr";
App.filesDone = function(path:String) {
if (!StringTools.endsWith(path, ".hdr")) {
if (!path.endsWith(".hdr")) {
UITrait.inst.showError("Error: .hdr file expected");
return;
}
+49 -47
View File
@@ -1,5 +1,7 @@
package arm.util;
using StringTools;
class Path {
public static function toRelative(from:String, to:String):String {
@@ -29,85 +31,85 @@ class Path {
public static function checkMeshFormat(path:String):Bool {
var p = path.toLowerCase();
return StringTools.endsWith(p, ".obj") ||
StringTools.endsWith(p, ".fbx") ||
StringTools.endsWith(p, ".blend") ||
StringTools.endsWith(p, ".gltf");
return p.endsWith(".obj") ||
p.endsWith(".fbx") ||
p.endsWith(".blend") ||
p.endsWith(".gltf");
}
public static function checkTextureFormat(path:String):Bool {
var p = path.toLowerCase();
return StringTools.endsWith(p, ".jpg") ||
StringTools.endsWith(p, ".png") ||
StringTools.endsWith(p, ".tga") ||
StringTools.endsWith(p, ".hdr");
return p.endsWith(".jpg") ||
p.endsWith(".png") ||
p.endsWith(".tga") ||
p.endsWith(".hdr");
}
public static function checkFontFormat(path:String):Bool {
var p = path.toLowerCase();
return StringTools.endsWith(p, ".ttf");
return p.endsWith(".ttf");
}
public static function checkProjectFormat(path:String):Bool {
var p = path.toLowerCase();
return StringTools.endsWith(p, ".arm");
return p.endsWith(".arm");
}
public static function checkBaseTex(p:String):Bool {
return StringTools.endsWith(p, "_albedo") ||
StringTools.endsWith(p, "_alb") ||
StringTools.endsWith(p, "_basecol") ||
StringTools.endsWith(p, "_basecolor") ||
StringTools.endsWith(p, "_diffuse") ||
StringTools.endsWith(p, "_diff") ||
StringTools.endsWith(p, "_base") ||
StringTools.endsWith(p, "_bc") ||
StringTools.endsWith(p, "_d") ||
StringTools.endsWith(p, "_color") ||
StringTools.endsWith(p, "_col");
return p.endsWith("_albedo") ||
p.endsWith("_alb") ||
p.endsWith("_basecol") ||
p.endsWith("_basecolor") ||
p.endsWith("_diffuse") ||
p.endsWith("_diff") ||
p.endsWith("_base") ||
p.endsWith("_bc") ||
p.endsWith("_d") ||
p.endsWith("_color") ||
p.endsWith("_col");
}
public static function checkOpacTex(p:String):Bool {
return StringTools.endsWith(p, "_opac") ||
StringTools.endsWith(p, "_alpha") ||
StringTools.endsWith(p, "_opacity") ||
StringTools.endsWith(p, "_mask");
return p.endsWith("_opac") ||
p.endsWith("_alpha") ||
p.endsWith("_opacity") ||
p.endsWith("_mask");
}
public static function checkNorTex(p:String):Bool {
return StringTools.endsWith(p, "_normal") ||
StringTools.endsWith(p, "_nor") ||
StringTools.endsWith(p, "_n") ||
StringTools.endsWith(p, "_nrm");
return p.endsWith("_normal") ||
p.endsWith("_nor") ||
p.endsWith("_n") ||
p.endsWith("_nrm");
}
public static function checkOccTex(p:String):Bool {
return StringTools.endsWith(p, "_ao") ||
StringTools.endsWith(p, "_occlusion") ||
StringTools.endsWith(p, "_o") ||
StringTools.endsWith(p, "_occ");
return p.endsWith("_ao") ||
p.endsWith("_occlusion") ||
p.endsWith("_o") ||
p.endsWith("_occ");
}
public static function checkRoughTex(p:String):Bool {
return StringTools.endsWith(p, "_roughness") ||
StringTools.endsWith(p, "_roug") ||
StringTools.endsWith(p, "_r") ||
StringTools.endsWith(p, "_rough") ||
StringTools.endsWith(p, "_rgh");
return p.endsWith("_roughness") ||
p.endsWith("_roug") ||
p.endsWith("_r") ||
p.endsWith("_rough") ||
p.endsWith("_rgh");
}
public static function checkMetTex(p:String):Bool {
return StringTools.endsWith(p, "_metallic") ||
StringTools.endsWith(p, "_metal") ||
StringTools.endsWith(p, "_metalness") ||
StringTools.endsWith(p, "_m") ||
StringTools.endsWith(p, "_met");
return p.endsWith("_metallic") ||
p.endsWith("_metal") ||
p.endsWith("_metalness") ||
p.endsWith("_m") ||
p.endsWith("_met");
}
public static function checkDispTex(p:String):Bool {
return StringTools.endsWith(p, "_displacement") ||
StringTools.endsWith(p, "_height") ||
StringTools.endsWith(p, "_h") ||
StringTools.endsWith(p, "_disp");
return p.endsWith("_displacement") ||
p.endsWith("_height") ||
p.endsWith("_h") ||
p.endsWith("_disp");
}
}