Files
armorpaint/Sources/arm/io/ImportTexture.hx
T
2019-06-23 14:50:41 +02:00

39 lines
1017 B
Haxe

package arm.io;
import kha.Image;
import zui.Canvas;
import iron.data.Data;
import arm.ui.UITrait;
import arm.util.Path;
using StringTools;
class ImportTexture {
public static function run(path:String) {
if (!Path.checkTextureFormat(path)) {
UITrait.inst.showError(Strings.error1);
return;
}
for (a in Project.assets) if (a.file == path) { UITrait.inst.showMessage(Strings.info0); return; }
Data.getImage(path, function(image:Image) {
var ar = path.split("/");
ar = ar[ar.length - 1].split("\\");
var name = ar[ar.length - 1];
var asset:TAsset = {name: name, file: path, id: Project.assetId++};
Project.assets.push(asset);
if (Context.texture == null) Context.texture = asset;
Project.assetNames.push(name);
Canvas.assetMap.set(asset.id, image);
UITrait.inst.hwnd2.redraws = 2;
// Set envmap
if (path.toLowerCase().endsWith(".hdr") &&
(image.width == 1024 || image.width == 2048 || image.width == 4096)) {
ImportEnvmap.run(path, image);
}
});
}
}