Forráskód Böngészése

Add atlas resolution preference

luboslenco 8 hónapja
szülő
commit
dd232b8228

+ 1 - 1
armorforge/sources/base_ext.ts

@@ -22,7 +22,7 @@ function base_ext_render() {
 function base_ext_init_config(raw: config_t) {
 	raw.window_w = 1920;
 	raw.window_h = 1080;
-    raw.layer_res = texture_res_t.RES8192;
+	raw.atlas_res = texture_res_t.RES8192;
 	raw.undo_steps = 1;
 }
 

+ 3 - 3
armorforge/sources/util_mesh_ext.ts

@@ -5,9 +5,9 @@ function _util_mesh_unique_data_count(): i32 {
 
 function util_mesh_ext_pack_uvs(texa: i16_array_t) {
     // Scale tex coords into global atlas
-	let atlas_w: i32 = config_get_texture_res();
-	let item_i: i32 = _util_mesh_unique_data_count() + 1; // Add the one being imported
-	let item_w: i32 = 2048;
+	let atlas_w: i32 = config_get_atlas_res();
+	let item_i: i32 = _util_mesh_unique_data_count() - 1; // Add the one being imported
+	let item_w: i32 = config_get_layer_res();
 	let atlas_stride: i32 = atlas_w / item_w;
 	let atlas_step: i32 = 32767 / atlas_stride;
 	let item_x: i32 = (item_i % atlas_stride) * atlas_step;

+ 1 - 0
base/sources/base.ts

@@ -836,6 +836,7 @@ function base_init_config() {
 	raw.dilate_radius = 2;
 	raw.gpu_inference = true;
 	raw.blender = "";
+	raw.atlas_res = 0;
 
 	base_ext_init_config(raw);
 }

+ 18 - 4
base/sources/box_preferences.ts

@@ -389,17 +389,30 @@ function box_preferences_show() {
 			}
 
 			///if (arm_android || arm_ios)
-			let layer_res_combo: string[] = ["128", "256", "512", "1K", "2K", "4K"];
+			let res_combo: string[] = ["128", "256", "512", "1K", "2K", "4K"];
 			///else
-			let layer_res_combo: string[] = ["128", "256", "512", "1K", "2K", "4K", "8K"];
+			let res_combo: string[] = ["128", "256", "512", "1K", "2K", "4K", "8K", "16K"];
 			///end
 
-			ui_combo(layer_res_handle, layer_res_combo, tr("Default Layer Resolution"), true);
-
+			ui_combo(layer_res_handle, res_combo, tr("Default Layer Resolution"), true);
 			if (layer_res_handle.changed) {
 				config_raw.layer_res = layer_res_handle.position;
 			}
 
+			///if is_forge
+			let atlas_res_handle: ui_handle_t = ui_handle(__ID__);
+			if (atlas_res_handle.init) {
+				atlas_res_handle.position = config_raw.atlas_res;
+			}
+
+			ui_combo(atlas_res_handle, res_combo, tr("Atlas Resolution"), true);
+			if (atlas_res_handle.changed) {
+				config_raw.atlas_res = atlas_res_handle.position;
+			}
+			///end
+
+
+
 			let server_handle: ui_handle_t = ui_handle(__ID__);
 			if (server_handle.init) {
 				server_handle.text = config_raw.server;
@@ -572,6 +585,7 @@ function box_preferences_show() {
 			if (hpathtrace_mode.changed) {
 				render_path_raytrace_ready = false;
 				render_path_raytrace_first = true;
+				context_raw.ddirty = 2;
 			}
 
 			///end

+ 24 - 9
base/sources/config.ts

@@ -98,6 +98,7 @@ function config_save() {
 	json_encode_i32("dilate_radius", config_raw.dilate_radius);
 	json_encode_bool("gpu_inference", config_raw.gpu_inference);
 	json_encode_string("blender", config_raw.blender);
+	json_encode_i32("atlas_res", config_raw.atlas_res);
 	let config_json: string = json_encode_end();
 
 	let buffer: buffer_t = sys_string_to_buffer(config_json);
@@ -274,16 +275,30 @@ function config_get_super_sample_size(i: i32): f32 {
 		   i == 4 ? 2.0 : 4.0;
 }
 
+function config_texture_res_size(pos: i32): i32 {
+	return pos == texture_res_t.RES128 ? 128 :
+		   pos == texture_res_t.RES256 ? 256 :
+		   pos == texture_res_t.RES512 ? 512 :
+		   pos == texture_res_t.RES1024 ? 1024 :
+		   pos == texture_res_t.RES2048 ? 2048 :
+		   pos == texture_res_t.RES4096 ? 4096 :
+		   pos == texture_res_t.RES8192 ? 8192 :
+		   pos == texture_res_t.RES16384 ? 16384 : 0;
+}
+
 function config_get_texture_res(): i32 {
 	let res: i32 = base_res_handle.position;
-	return res == texture_res_t.RES128 ? 128 :
-		   res == texture_res_t.RES256 ? 256 :
-		   res == texture_res_t.RES512 ? 512 :
-		   res == texture_res_t.RES1024 ? 1024 :
-		   res == texture_res_t.RES2048 ? 2048 :
-		   res == texture_res_t.RES4096 ? 4096 :
-		   res == texture_res_t.RES8192 ? 8192 :
-		   res == texture_res_t.RES16384 ? 16384 : 0;
+	return config_texture_res_size(res);
+}
+
+function config_get_layer_res(): i32 {
+	let res: i32 = config_raw.layer_res;
+	return config_texture_res_size(res);
+}
+
+function config_get_atlas_res(): i32 {
+	let res: i32 = config_raw.atlas_res;
+	return config_texture_res_size(res);
 }
 
 function config_get_texture_res_x(): i32 {
@@ -426,6 +441,6 @@ type config_t = {
 	dilate_radius?: i32;
 
 	gpu_inference?: bool;
-
 	blender?: string;
+	atlas_res: i32; // Forge
 };

+ 2 - 2
base/sources/context.ts

@@ -429,8 +429,8 @@ function context_create(): context_t {
 	c.brush_opacity_handle = ui_handle_create();
 	c.brush_opacity_handle.value = 1.0;
 	///if is_forge
-	let atlas_w: i32 = 8192; // config_get_texture_res();
-	let item_w: i32 = 2048;
+	let atlas_w: i32 = config_get_atlas_res();
+	let item_w: i32 = config_get_layer_res();
 	let atlas_stride: i32 = atlas_w / item_w;
 	c.brush_scale = atlas_stride;
 	///else

+ 1 - 1
base/sources/main.ts

@@ -11,8 +11,8 @@ function main() {
 	app_on_x = base_x;
 	app_on_y = base_y;
 
-	context_init();
 	config_init();
+	context_init();
 	sys_start(config_get_options());
 	if (config_raw.layout == null) {
 		base_init_layout();