Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Oct 17, 2024
1 parent 700083f commit f1ebd16
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
35 changes: 20 additions & 15 deletions armorsculpt/sources/import_mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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();
}
19 changes: 3 additions & 16 deletions base/sources/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit f1ebd16

Please sign in to comment.