Skip to content

Commit

Permalink
Forge test
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Dec 7, 2024
1 parent d84a70c commit 73c1fb2
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 19 deletions.
4 changes: 2 additions & 2 deletions armorforge/sources/base_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
24 changes: 21 additions & 3 deletions armorforge/sources/sim.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

let sim_running: bool = false;
let sim_transforms: mat4_box_t[];
let sim_object_script_map: map_t<object_t, string> = map_create();

function sim_init() {
physics_world_create();
Expand All @@ -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);

Expand All @@ -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 = [];
Expand All @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions armorforge/sources/tab_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
3 changes: 2 additions & 1 deletion armorforge/sources/tab_scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
15 changes: 15 additions & 0 deletions armorforge/sources/util_mesh_ext.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
14 changes: 1 addition & 13 deletions base/sources/import_mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions base/sources/layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 73c1fb2

Please sign in to comment.