Show material preview in browser

This commit is contained in:
luboslenco
2020-01-28 00:02:07 +01:00
parent 585ceedf81
commit a61cc7a588
7 changed files with 46 additions and 12 deletions
+1
View File
@@ -288,6 +288,7 @@ typedef TProjectFormat = {
public var version: String;
@:optional public var brush_nodes: Array<TNodeCanvas>;
@:optional public var material_nodes: Array<TNodeCanvas>;
@:optional public var material_icons: Array<haxe.io.Bytes>;
@:optional public var assets: Array<String>; // texture_assets
@:optional public var layer_datas: Array<TLayerData>;
@:optional public var mesh_datas: Array<TMeshData>;
+1 -1
View File
@@ -33,7 +33,7 @@ class MaterialSlot {
data = m;
var w = RenderUtil.matPreviewSize;
var wIcon = Std.int(w / 4);
var wIcon = 50;
image = Image.createRenderTarget(w, w);
imageIcon = Image.createRenderTarget(wIcon, wIcon);
+1
View File
@@ -103,6 +103,7 @@ class ExportArm {
var raw = {
version: App.version,
material_nodes: mnodes,
material_icons: [Lz4.encode(m.image.getPixels())],
assets: texture_files
};
+9 -9
View File
@@ -94,15 +94,20 @@ class ImportArm {
public static function runProject(path: String) {
Data.getBlob(path, function(b: Blob) {
var project: TProjectFormat = ArmPack.decode(b.toBytes());
path = path.replace("\\", "/");
// Import as material instead
if (project.version != null && project.layer_datas == null) {
runMaterialFromProject(project, path);
return;
}
Context.layersPreviewDirty = true;
var resetLayers = false;
Project.projectNew(resetLayers);
path = path.replace("\\", "/");
Project.filepath = path;
Project.projectNew(false);
UIFiles.filename = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
Window.get(0).title = UIFiles.filename + " - ArmorPaint";
var project: TProjectFormat = ArmPack.decode(b.toBytes());
// Import as mesh instead
if (project.version == null) {
@@ -110,11 +115,6 @@ class ImportArm {
return;
}
if (project.layer_datas == null) {
runMaterialFromProject(project, Project.filepath);
return;
}
Project.raw = project;
var base = Path.baseDir(path);
+4
View File
@@ -104,6 +104,10 @@ class Path {
return p.endsWith(".json");
}
public static function isKnown(path: String): Bool {
return isMesh(path) || isTexture(path) || isFont(path) || isProject(path) || isPlugin(path);
}
static function checkExt(p: String, exts: Array<String>): Bool {
p = p.replace("-", "_");
for (ext in exts) if (p.endsWith("_" + ext)) return true;
+29 -1
View File
@@ -1,9 +1,12 @@
package arm.ui;
import haxe.io.Bytes;
import zui.Zui;
import zui.Id;
import iron.system.Input;
import iron.system.Time;
import iron.system.ArmPack;
import arm.format.Lz4;
import arm.sys.Path;
import arm.sys.File;
using StringTools;
@@ -14,6 +17,7 @@ class UIFiles {
public static var path = "/";
static var lastPath = "";
static var files: Array<String> = null;
static var iconMap: Map<String, kha.Image> = null;
static var selected = -1;
public static function show(filters: String, isSave: Bool, filesDone: String->Void) {
@@ -85,6 +89,7 @@ class UIFiles {
var filesAll = File.readDirectory(handle.text, foldersOnly);
for (f in filesAll) {
if (f == "" || f.charAt(0) == ".") continue; // Skip hidden
if (f.indexOf(".") > 0 && !Path.isKnown(f)) continue; // Skip unknown extensions
files.push(f);
}
}
@@ -120,7 +125,30 @@ class UIFiles {
var uix = ui._x;
var uiy = ui._y;
var state = ui.image(icons, col, rect.h, rect.x, rect.y, rect.w, rect.h);
var state = Idle;
var generic = true;
if (f.endsWith(".arm")) {
if (iconMap == null) iconMap = [];
var icon = iconMap.get(handle.text + Path.sep + f);
if (icon == null) {
var bytes = Bytes.ofData(Krom.loadBlob(handle.text + Path.sep + f));
var raw = ArmPack.decode(bytes);
if (raw.material_icons != null) {
var bytesIcon = raw.material_icons[0];
icon = kha.Image.fromBytes(Lz4.decode(bytesIcon, 256 * 256 * 4), 256, 256);
iconMap.set(handle.text + Path.sep + f, icon);
}
}
if (icon != null) {
state = ui.image(icon, col, rect.h);
generic = false;
}
}
if (generic) {
state = ui.image(icons, col, rect.h, rect.x, rect.y, rect.w, rect.h);
}
if (state == Started) {
+1 -1
View File
@@ -15,7 +15,7 @@ import arm.Tool;
class RenderUtil {
public static inline var matPreviewSize = 200;
public static inline var matPreviewSize = 256;
public static inline var decalPreviewSize = 512;
public static function makeMaterialPreview() {