Improve envmap handling
This commit is contained in:
@@ -415,10 +415,10 @@ class Project {
|
||||
else importAsset();
|
||||
}
|
||||
|
||||
public static function importAsset(filters: String = null) {
|
||||
public static function importAsset(filters: String = null, hdrAsEnvmap = true) {
|
||||
if (filters == null) filters = Path.textureFormats.join(",") + "," + Path.meshFormats.join(",");
|
||||
UIFiles.show(filters, false, function(path: String) {
|
||||
ImportAsset.run(path);
|
||||
ImportAsset.run(path, -1.0, -1.0, true, hdrAsEnvmap);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ typedef TProjectFormat = {
|
||||
@:optional public var swatches: Array<TSwatchColor>;
|
||||
@:optional public var is_bgra: Null<Bool>; // Swapped red and blue channels for layer textures
|
||||
@:optional public var packed_assets: Array<TPackedAsset>;
|
||||
@:optional public var envmap: String; // Asset name
|
||||
}
|
||||
|
||||
typedef TLayerData = {
|
||||
|
||||
@@ -90,6 +90,7 @@ class ExportArm {
|
||||
}
|
||||
|
||||
var packed_assets = Project.raw.packed_assets == null || Project.raw.packed_assets.length == 0 ? null : Project.raw.packed_assets;
|
||||
var sameDrive = Project.filepath.charAt(0) == Project.raw.envmap.charAt(0);
|
||||
|
||||
Project.raw = {
|
||||
version: Main.version,
|
||||
@@ -105,6 +106,7 @@ class ExportArm {
|
||||
atlas_names: Project.atlasNames,
|
||||
swatches: Project.raw.swatches,
|
||||
packed_assets: packed_assets,
|
||||
envmap: sameDrive ? Path.toRelative(Project.filepath, Project.raw.envmap) : Project.raw.envmap,
|
||||
#if (kha_metal || kha_vulkan)
|
||||
is_bgra: true
|
||||
#else
|
||||
|
||||
@@ -111,6 +111,7 @@ class ImportArm {
|
||||
var format = l0.bpp == 8 ? TextureFormat.RGBA32 : l0.bpp == 16 ? TextureFormat.RGBA64 : TextureFormat.RGBA128;
|
||||
|
||||
var base = Path.baseDir(path);
|
||||
Project.raw.envmap = Data.isAbsolute(Project.raw.envmap) ? Project.raw.envmap : base + Project.raw.envmap;
|
||||
|
||||
for (file in project.assets) {
|
||||
#if krom_windows
|
||||
@@ -126,7 +127,8 @@ class ImportArm {
|
||||
if (Data.cachedImages.get(abs) == null && !File.exists(abs)) {
|
||||
makePink(abs);
|
||||
}
|
||||
ImportTexture.run(abs);
|
||||
var hdrAsEnvmap = abs.endsWith(".hdr") && Project.raw.envmap == abs;
|
||||
ImportTexture.run(abs, hdrAsEnvmap);
|
||||
}
|
||||
|
||||
if (project.font_assets != null) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import arm.Project;
|
||||
|
||||
class ImportAsset {
|
||||
|
||||
public static function run(path: String, dropX = -1.0, dropY = -1.0, showBox = true) {
|
||||
public static function run(path: String, dropX = -1.0, dropY = -1.0, showBox = true, hdrAsEnvmap = true) {
|
||||
|
||||
if (path.startsWith("cloud")) {
|
||||
var abs = File.cacheCloud(path);
|
||||
@@ -21,7 +21,7 @@ class ImportAsset {
|
||||
if (dropX > 0) UIBox.clickToHide = false; // Prevent closing when going back to window after drag and drop
|
||||
}
|
||||
else if (Path.isTexture(path)) {
|
||||
ImportTexture.run(path);
|
||||
ImportTexture.run(path, hdrAsEnvmap);
|
||||
// Place image node
|
||||
var x0 = UINodes.inst.wx;
|
||||
var x1 = UINodes.inst.wx + UINodes.inst.ww;
|
||||
|
||||
@@ -94,6 +94,7 @@ class ImportEnvmap {
|
||||
Scene.active.world.envmap = Scene.active.world.probe.radianceMipmaps[0];
|
||||
}
|
||||
Context.ddirty = 2;
|
||||
Project.raw.envmap = path;
|
||||
}
|
||||
|
||||
static function getRadianceMip(mip: kha.Image, level: Int, radiance: kha.Image) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import arm.ProjectFormat;
|
||||
|
||||
class ImportTexture {
|
||||
|
||||
public static function run(path: String) {
|
||||
public static function run(path: String, hdrAsEnvmap = true) {
|
||||
if (!Path.isTexture(path)) {
|
||||
if (!Context.enableImportPlugin(path)) {
|
||||
Log.error(Strings.error1());
|
||||
@@ -17,9 +17,10 @@ class ImportTexture {
|
||||
}
|
||||
|
||||
for (a in Project.assets) {
|
||||
// Already imported
|
||||
if (a.file == path) {
|
||||
// Set envmap
|
||||
if (path.toLowerCase().endsWith(".hdr")) {
|
||||
// Set as envmap
|
||||
if (hdrAsEnvmap && path.toLowerCase().endsWith(".hdr")) {
|
||||
Data.getImage(path, function(image: kha.Image) {
|
||||
App.notifyOnNextFrame(function() { // Make sure file browser process did finish
|
||||
ImportEnvmap.run(path, image);
|
||||
@@ -31,6 +32,7 @@ class ImportTexture {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var ext = path.substr(path.lastIndexOf(".") + 1);
|
||||
var importer = Path.textureImporters.get(ext);
|
||||
var cached = Data.cachedImages.get(path) != null; // Already loaded or pink texture for missing file
|
||||
@@ -47,8 +49,8 @@ class ImportTexture {
|
||||
Project.assetMap.set(asset.id, image);
|
||||
UISidebar.inst.hwnd2.redraws = 2;
|
||||
|
||||
// Set envmap
|
||||
if (path.toLowerCase().endsWith(".hdr")) {
|
||||
// Set as envmap
|
||||
if (hdrAsEnvmap && path.toLowerCase().endsWith(".hdr")) {
|
||||
App.notifyOnNextFrame(function() { // Make sure file browser process did finish
|
||||
ImportEnvmap.run(path, image);
|
||||
});
|
||||
|
||||
@@ -22,7 +22,7 @@ class TabTextures {
|
||||
|
||||
if (ui.button(tr("Import"))) {
|
||||
UIFiles.show(Path.textureFormats.join(","), false, function(path: String) {
|
||||
ImportAsset.run(path);
|
||||
ImportAsset.run(path, -1.0, -1.0, true, false);
|
||||
});
|
||||
}
|
||||
if (ui.isHovered) ui.tooltip(tr("Import texture file") + ' (${Config.keymap.file_import_assets})');
|
||||
|
||||
+12
-13
@@ -54,9 +54,9 @@ class UIMenu {
|
||||
}
|
||||
else {
|
||||
var menuItems = [
|
||||
18, // MenuFile
|
||||
19, // MenuFile
|
||||
4, // MenuEdit
|
||||
14, // MenuViewport
|
||||
13, // MenuViewport
|
||||
#if (kha_direct3d12 || kha_vulkan) 14 #else 13 #end, // MenuMode
|
||||
17, // MenuCamera
|
||||
7 // MenuHelp
|
||||
@@ -72,7 +72,16 @@ class UIMenu {
|
||||
if (ui.button(" " + tr("Save"), Left, Config.keymap.file_save)) Project.projectSave();
|
||||
if (ui.button(" " + tr("Save As..."), Left, Config.keymap.file_save_as)) Project.projectSaveAs();
|
||||
ui.fill(0, 0, sepw, 1, ui.t.ACCENT_SELECT_COL);
|
||||
if (ui.button(" " + tr("Import Texture..."), Left, Config.keymap.file_import_assets)) Project.importAsset(Path.textureFormats.join(","));
|
||||
if (ui.button(" " + tr("Import Texture..."), Left, Config.keymap.file_import_assets)) Project.importAsset(Path.textureFormats.join(","), false);
|
||||
if (ui.button(" " + tr("Import Envmap..."), Left)) {
|
||||
UIFiles.show("hdr", false, function(path: String) {
|
||||
if (!path.endsWith(".hdr")) {
|
||||
Log.error("Error: .hdr file expected");
|
||||
return;
|
||||
}
|
||||
ImportAsset.run(path);
|
||||
});
|
||||
}
|
||||
if (ui.button(" " + tr("Import Font..."), Left)) Project.importAsset("ttf,ttc,otf");
|
||||
if (ui.button(" " + tr("Import Material..."), Left)) Project.importMaterial();
|
||||
if (ui.button(" " + tr("Import Brush..."), Left)) Project.importBrush();
|
||||
@@ -110,16 +119,6 @@ class UIMenu {
|
||||
if (ui.button(" " + tr("Preferences..."), Left, Config.keymap.edit_prefs)) BoxPreferences.show();
|
||||
}
|
||||
else if (menuCategory == MenuViewport) {
|
||||
if (ui.button(" " + tr("Import Envmap..."), Left)) {
|
||||
UIFiles.show("hdr", false, function(path: String) {
|
||||
if (!path.endsWith(".hdr")) {
|
||||
Log.error("Error: .hdr file expected");
|
||||
return;
|
||||
}
|
||||
ImportAsset.run(path);
|
||||
});
|
||||
}
|
||||
|
||||
if (ui.button(" " + tr("Distract Free"), Left, Config.keymap.view_distract_free)) {
|
||||
UISidebar.inst.toggleDistractFree();
|
||||
UISidebar.inst.ui.isHovered = false;
|
||||
|
||||
Reference in New Issue
Block a user