From a4f634edcb2603a2d42eca5efa68b1bd8f3a1733 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Mon, 2 Dec 2024 18:58:23 +0100 Subject: [PATCH] Forge test --- armorforge/sources/context_ext.ts | 6 ++++++ armorforge/sources/sim.ts | 20 ++++++++++++++++++++ armorforge/sources/tab_scene.ts | 17 +++++++++++++---- base/sources/import_mesh.ts | 16 ++++++++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/armorforge/sources/context_ext.ts b/armorforge/sources/context_ext.ts index 02d6179b7..c18ca3602 100644 --- a/armorforge/sources/context_ext.ts +++ b/armorforge/sources/context_ext.ts @@ -4,4 +4,10 @@ function context_ext_init(c: context_t) { } function context_ext_select_paint_object(o: mesh_object_t) { + for (let i: i32 = 0; i < project_paint_objects.length; ++i) { + let p: mesh_object_t = project_paint_objects[i]; + p.skip_context = "paint"; + } + context_raw.paint_object.skip_context = ""; + context_raw.paint_object = o; } diff --git a/armorforge/sources/sim.ts b/armorforge/sources/sim.ts index 09590974e..5f2b6c366 100644 --- a/armorforge/sources/sim.ts +++ b/armorforge/sources/sim.ts @@ -1,5 +1,6 @@ let sim_running: bool = false; +let sim_transforms: mat4_box_t[]; function sim_init() { physics_world_create(); @@ -35,11 +36,30 @@ function sim_play() { sim_running = true; let rt: render_target_t = map_get(render_path_render_targets, "taa"); iron_mp4_begin("/home/lubos/Desktop/test.mp4", rt._image.width, rt._image.height); + + // Save transforms + sim_transforms = []; + let pos: mesh_object_t[] = project_paint_objects; + for (let i: i32 = 0; i < pos.length; ++i) { + let m: mat4_box_t = { v: pos[i].base.transform.local }; + array_push(sim_transforms, m); + } } function sim_stop() { sim_running = false; iron_mp4_end(); + + // Restore transforms + let pos: mesh_object_t[] = project_paint_objects; + for (let i: i32 = 0; i < pos.length; ++i) { + transform_set_matrix(pos[i].base.transform, sim_transforms[i].v); + + let pb: physics_body_t = map_get(physics_body_object_map, pos[i].base.uid); + if (pb != null) { + physics_body_sync_transform(pb); + } + } } function sim_add(o: object_t, shape: physics_shape_t, mass: f32) { diff --git a/armorforge/sources/tab_scene.ts b/armorforge/sources/tab_scene.ts index 0795f76e5..ca5455990 100644 --- a/armorforge/sources/tab_scene.ts +++ b/armorforge/sources/tab_scene.ts @@ -1,10 +1,19 @@ let tab_scene_line_counter: i32 = 0; +function tab_scene_select_object(mo: mesh_object_t) { + context_raw.selected_object = mo.base; + context_raw.paint_object = mo; + if (context_raw.merged_object != null) { + context_raw.merged_object.base.visible = false; + } + context_select_paint_object(mo); +} + function tab_scene_import_mesh_done() { let mo: mesh_object_t = project_paint_objects[project_paint_objects.length - 1]; object_set_parent(mo.base, null); - context_raw.selected_object = mo.base; + tab_scene_select_object(mo); } function tab_scene_draw_list(ui: ui_t, list_handle: ui_handle_t, current_object: object_t) { @@ -54,7 +63,7 @@ function tab_scene_draw_list(ui: ui_t, list_handle: ui_handle_t, current_object: ui._y -= ui_ELEMENT_OFFSET(ui); if (ui.is_released) { - context_raw.selected_object = current_object; + tab_scene_select_object(current_object.ext); } if (b) { @@ -103,13 +112,13 @@ function tab_scene_draw(htab: ui_handle_t) { if (ui.is_key_pressed && ui.key_code == key_code_t.DOWN) { let i: i32 = array_index_of(project_paint_objects, context_raw.selected_object.ext); if (i < project_paint_objects.length - 1) { - context_raw.selected_object = project_paint_objects[i + 1].base; + tab_scene_select_object(project_paint_objects[i + 1]); } } if (ui.is_key_pressed && ui.key_code == key_code_t.UP) { let i: i32 = array_index_of(project_paint_objects, context_raw.selected_object.ext); if (i > 1) { - context_raw.selected_object = project_paint_objects[i - 1].base; + tab_scene_select_object(project_paint_objects[i - 1]); } } } diff --git a/base/sources/import_mesh.ts b/base/sources/import_mesh.ts index 6c91829e9..31ac6f293 100644 --- a/base/sources/import_mesh.ts +++ b/base/sources/import_mesh.ts @@ -215,6 +215,22 @@ function _import_mesh_add_mesh(mesh: raw_mesh_t) { array_push(raw.vertex_arrays, va); } + ///if is_forge + // Scale tex coords into global atlas + let atlas_w: i32 = config_get_texture_res(); + let item_i: i32 = project_paint_objects.length; + let item_w: i32 = 4096; + 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; + let item_y: i32 = math_floor(item_i / atlas_stride) * atlas_step; + let texa: i16_array_t = mesh.texa; + for (let i: i32 = 0; i < texa.length / 2; ++i) { + texa[i * 2] = texa[i * 2] / atlas_stride + item_x; + texa[i * 2 + 1] = texa[i * 2 + 1] / atlas_stride + item_y; + } + ///end + let md: mesh_data_t = mesh_data_create(raw); let object: mesh_object_t = scene_add_mesh_object(md, context_raw.paint_object.materials, context_raw.paint_object.base);