Skip to content

Commit

Permalink
Forge test
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Dec 2, 2024
1 parent 1a47510 commit a4f634e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
6 changes: 6 additions & 0 deletions armorforge/sources/context_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
20 changes: 20 additions & 0 deletions armorforge/sources/sim.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

let sim_running: bool = false;
let sim_transforms: mat4_box_t[];

function sim_init() {
physics_world_create();
Expand Down Expand Up @@ -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) {
Expand Down
17 changes: 13 additions & 4 deletions armorforge/sources/tab_scene.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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]);
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions base/sources/import_mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a4f634e

Please sign in to comment.