diff --git a/armorforge/sources/base_ext.ts b/armorforge/sources/base_ext.ts index 4969353e0..cbeea2371 100644 --- a/armorforge/sources/base_ext.ts +++ b/armorforge/sources/base_ext.ts @@ -4,8 +4,8 @@ function base_ext_init() { object_remove(scene_lights[0].base); - // project_paint_objects[0].base.visible = false; - // tab_scene_new_object("box.arm"); + // project_paint_objects[0].base.visible = false; + // tab_scene_new_object("box.arm"); } function base_ext_render() { diff --git a/armorforge/sources/sim.ts b/armorforge/sources/sim.ts index 9637d609e..38afd8541 100644 --- a/armorforge/sources/sim.ts +++ b/armorforge/sources/sim.ts @@ -1,6 +1,7 @@ let sim_running: bool = false; let sim_transforms: mat4_box_t[]; +let sim_object_script_map: map_t = map_create(); function sim_init() { physics_world_create(); @@ -15,6 +16,15 @@ function sim_update() { // return; // } + let objects: object_t[] = map_keys(sim_object_script_map); + for (let i: i32 = 0; i < objects.length; ++i) { + let o: object_t = objects[i]; + let s: string = map_get(sim_object_script_map, o); + let addr: string = i64_to_string((i64)(o.transform)); + s = "{let transform=" + addr + ";" + s + "}"; + js_eval(s); + } + let world: physics_world_t = physics_world_active; physics_world_update(world); @@ -35,8 +45,12 @@ function sim_update() { 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); + + let record: bool = false; + if (record) { + 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 = []; @@ -49,7 +63,11 @@ function sim_play() { function sim_stop() { sim_running = false; - iron_mp4_end(); + + let record: bool = false; + if (record) { + iron_mp4_end(); + } // Restore transforms let pos: mesh_object_t[] = project_paint_objects; diff --git a/armorforge/sources/tab_object.ts b/armorforge/sources/tab_object.ts index d3d9f77cc..bf63f0467 100644 --- a/armorforge/sources/tab_object.ts +++ b/armorforge/sources/tab_object.ts @@ -162,6 +162,30 @@ function tab_object_draw(htab: ui_handle_t) { sim_add(context_raw.selected_object, hshape.position - 1, hdynamic.selected ? 1.0 : 0.0); } } + + ui_text("Script", ui_align_t.LEFT, ui.ops.theme.SEPARATOR_COL); + + let script: string = map_get(sim_object_script_map, context_raw.selected_object); + if (script == null) { + script = ""; + } + + let hscript: ui_handle_t = ui_handle(__ID__); + hscript.text = script; + + let _font: g2_font_t = ui.ops.font; + let _font_size: i32 = ui.font_size; + let fmono: g2_font_t = data_get_font("font_mono.ttf"); + ui_set_font(ui, fmono); + ui.font_size = math_floor(15 * ui_SCALE(ui)); + ui_text_area_coloring = tab_script_get_text_coloring(); + ui_text_area(hscript); + ui_text_area_coloring = null; + ui_set_font(ui, _font); + ui.font_size = _font_size; + + script = hscript.text; + map_set(sim_object_script_map, context_raw.selected_object, script); } } } diff --git a/armorforge/sources/tab_scene.ts b/armorforge/sources/tab_scene.ts index 4f07bc512..658e8b13e 100644 --- a/armorforge/sources/tab_scene.ts +++ b/armorforge/sources/tab_scene.ts @@ -110,9 +110,10 @@ function tab_scene_draw_list(ui: ui_t, list_handle: ui_handle_t, current_object: function tab_scene_new_object(mesh_name: string) { let blob: buffer_t = iron_load_blob(data_path() + "meshes/" + mesh_name); let raw: scene_t = armpack_decode(blob); + util_mesh_ext_pack_uvs(raw.mesh_datas[0].vertex_arrays[2].values); let md: mesh_data_t = mesh_data_create(raw.mesh_datas[0]); md._.handle = md.name; - let mo: mesh_object_t = scene_add_mesh_object(md, scene_meshes[0].materials); + let mo: mesh_object_t = scene_add_mesh_object(md, project_paint_objects[0].materials); mo.base.name = md.name; let o: obj_t = {}; o._ = { _gc: raw }; diff --git a/armorforge/sources/util_mesh_ext.ts b/armorforge/sources/util_mesh_ext.ts new file mode 100644 index 000000000..d069bc58b --- /dev/null +++ b/armorforge/sources/util_mesh_ext.ts @@ -0,0 +1,15 @@ + +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 = project_paint_objects.length; + let item_w: i32 = 2048; + 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; + 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; + } +} diff --git a/base/sources/import_mesh.ts b/base/sources/import_mesh.ts index e949411c4..ff42f279b 100644 --- a/base/sources/import_mesh.ts +++ b/base/sources/import_mesh.ts @@ -216,19 +216,7 @@ function _import_mesh_add_mesh(mesh: raw_mesh_t) { } ///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 = 2048; - 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; - } + util_mesh_ext_pack_uvs(mesh.texa); ///end let md: mesh_data_t = mesh_data_create(raw); diff --git a/base/sources/layers.ts b/base/sources/layers.ts index 2ab07f946..a7a9d1514 100644 --- a/base/sources/layers.ts +++ b/base/sources/layers.ts @@ -531,6 +531,9 @@ function layers_new_group(): slot_layer_t { } function layers_create_fill_layer(uv_type: uv_type_t = uv_type_t.UVMAP, decal_mat: mat4_t = mat4nan, position: i32 = -1) { + ///if is_forge + return; + ///end _layers_uv_type = uv_type; _layers_decal_mat = decal_mat; _layers_position = position;