diff --git a/armorsculpt/sources/import_mesh.ts b/armorsculpt/sources/import_mesh.ts index a1ee72d11..bb4bfa2c5 100644 --- a/armorsculpt/sources/import_mesh.ts +++ b/armorsculpt/sources/import_mesh.ts @@ -135,21 +135,7 @@ function _import_mesh_make_mesh(mesh: raw_mesh_t) { app_notify_on_init(import_mesh_finish_import); app_notify_on_next_frame(function (mesh: raw_mesh_t) { - let b: buffer_t = buffer_create(config_get_texture_res_x() * config_get_texture_res_y() * 4 * 4); - for (let i: i32 = 0; i < math_floor(mesh.inda.length); ++i) { - let index: i32 = mesh.inda[i]; - buffer_set_f32(b, 4 * i * 4, mesh.posa[index * 4] / 32767); - buffer_set_f32(b, 4 * i * 4 + 1 * 4, mesh.posa[index * 4 + 1] / 32767); - buffer_set_f32(b, 4 * i * 4 + 2 * 4, mesh.posa[index * 4 + 2] / 32767); - buffer_set_f32(b, 4 * i * 4 + 3 * 4, 1.0); - } - let imgmesh: image_t = image_from_bytes(b, config_get_texture_res_x(), config_get_texture_res_y(), tex_format_t.RGBA128); - let texpaint: image_t = project_layers[0].texpaint; - g2_begin(texpaint); - g2_set_pipeline(base_pipe_copy128); - g2_draw_scaled_image(imgmesh, 0, 0, config_get_texture_res_x(), config_get_texture_res_y()); - g2_set_pipeline(null); - g2_end(); + import_mesh_pack_to_texture(mesh); }, mesh); } @@ -230,3 +216,22 @@ function import_mesh_raw_mesh(mesh: raw_mesh_t): mesh_data_t { }; return raw; } + +function import_mesh_pack_to_texture(mesh: raw_mesh_t) { + let b: buffer_t = buffer_create(config_get_texture_res_x() * config_get_texture_res_y() * 4 * 4); + for (let i: i32 = 0; i < math_floor(mesh.inda.length); ++i) { + let index: i32 = mesh.inda[i]; + buffer_set_f32(b, 4 * i * 4, mesh.posa[index * 4] / 32767); + buffer_set_f32(b, 4 * i * 4 + 1 * 4, mesh.posa[index * 4 + 1] / 32767); + buffer_set_f32(b, 4 * i * 4 + 2 * 4, mesh.posa[index * 4 + 2] / 32767); + buffer_set_f32(b, 4 * i * 4 + 3 * 4, 1.0); + } + + let imgmesh: image_t = image_from_bytes(b, config_get_texture_res_x(), config_get_texture_res_y(), tex_format_t.RGBA128); + let texpaint: image_t = project_layers[0].texpaint; + g2_begin(texpaint); + g2_set_pipeline(base_pipe_copy128); + g2_draw_scaled_image(imgmesh, 0, 0, config_get_texture_res_x(), config_get_texture_res_y()); + g2_set_pipeline(null); + g2_end(); +} diff --git a/base/sources/project.ts b/base/sources/project.ts index d02bc74a0..51bd3325d 100644 --- a/base/sources/project.ts +++ b/base/sources/project.ts @@ -194,22 +194,9 @@ function project_new(reset_layers: bool = true) { ///if is_sculpt app_notify_on_next_frame(function (mesh: raw_mesh_t) { - let b: buffer_t = buffer_create(config_get_texture_res_x() * config_get_texture_res_y() * 4 * 4); - for (let i: i32 = 0; i < math_floor(mesh.inda.length); ++i) { - let index: i32 = mesh.inda[i]; - buffer_set_f32(b, 4 * i * 4, mesh.posa[index * 4] / 32767); - buffer_set_f32(b, 4 * i * 4 + 1 * 4, mesh.posa[index * 4 + 1] / 32767); - buffer_set_f32(b, 4 * i * 4 + 2 * 4, mesh.posa[index * 4 + 2] / 32767); - buffer_set_f32(b, 4 * i * 4 + 3 * 4, 1.0); - } - - let imgmesh: image_t = image_from_bytes(b, config_get_texture_res_x(), config_get_texture_res_y(), tex_format_t.RGBA128); - let texpaint: image_t = project_layers[0].texpaint; - g2_begin(texpaint); - g2_set_pipeline(base_pipe_copy128); - g2_draw_scaled_image(imgmesh, 0, 0, config_get_texture_res_x(), config_get_texture_res_y()); - g2_set_pipeline(null); - g2_end(); + app_notify_on_init(function (mesh: raw_mesh_t) { + import_mesh_pack_to_texture(mesh); + }, mesh); }, mesh); ///end }