Forge test

This commit is contained in:
luboslenco
2024-12-07 13:54:03 +01:00
parent d84a70c6c2
commit 73c1fb2ec9
7 changed files with 68 additions and 19 deletions
+2 -2
View File
@@ -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() {
+21 -3
View File
@@ -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();
@@ -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;
+24
View File
@@ -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);
}
}
}
+2 -1
View File
@@ -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 };
+15
View File
@@ -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;
}
}