Skip to content

Commit

Permalink
Implement util_encode_scene
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Sep 22, 2024
1 parent 7554eee commit aa65487
Showing 1 changed file with 48 additions and 42 deletions.
90 changes: 48 additions & 42 deletions base/sources/util_encode.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@

function util_encode_scene(raw: scene_t): buffer_t {
return null;
let size: i32 = 8 * 1024 * 1024 + util_encode_mesh_data_size(raw.mesh_datas);
let encoded: buffer_t = buffer_create(size);

// armpack_encode_start(encoded.buffer);
// armpack_encode_map(3);
// armpack_encode_string("name");
// armpack_encode_string(canvas->name);
armpack_encode_start(encoded.buffer);
util_encode_mesh_datas(raw.mesh_datas);

let ei: i32 = armpack_encode_end();
encoded.length = ei;
return encoded;
}

function util_encode_node_canvas(c: ui_node_canvas_t) {
Expand Down Expand Up @@ -38,6 +41,44 @@ function util_encode_layer_data_size(datas: layer_data_t[]): i32 {
return size;
}

function util_encode_mesh_datas(datas: mesh_data_t[]) {
armpack_encode_string("mesh_datas");
armpack_encode_array(datas.length);
for (let i: i32 = 0; i < datas.length; ++i) {
armpack_encode_map(7);
armpack_encode_string("name");
armpack_encode_string(datas[i].name);
armpack_encode_string("scale_pos");
armpack_encode_f32(datas[i].scale_pos);
armpack_encode_string("scale_tex");
armpack_encode_f32(datas[i].scale_tex);
armpack_encode_string("instancing");
armpack_encode_null(); // mesh_data_instancing_t
armpack_encode_string("skin");
armpack_encode_null(); // skin_t
armpack_encode_string("vertex_arrays");
armpack_encode_array(datas[i].vertex_arrays.length);
for (let j: i32 = 0; j < datas[i].vertex_arrays.length; ++j) {
armpack_encode_map(3);
armpack_encode_string("attrib");
armpack_encode_string(datas[i].vertex_arrays[j].attrib);
armpack_encode_string("data");
armpack_encode_string(datas[i].vertex_arrays[j].data);
armpack_encode_string("values");
armpack_encode_array_i16(datas[i].vertex_arrays[j].values);
}
armpack_encode_string("index_arrays");
armpack_encode_array(datas[i].index_arrays.length);
for (let j: i32 = 0; j < datas[i].index_arrays.length; ++j) {
armpack_encode_map(2);
armpack_encode_string("material");
armpack_encode_i32(datas[i].index_arrays[j].material);
armpack_encode_string("values");
armpack_encode_array_i32(datas[i].index_arrays[j].values);
}
}
}

function util_encode_project(raw: project_format_t): buffer_t {
let size: i32 = 32 * 1024 * 1024 + util_encode_layer_data_size(raw.layer_datas) + util_encode_mesh_data_size(raw.mesh_datas);
let encoded: buffer_t = buffer_create(size);
Expand Down Expand Up @@ -207,41 +248,7 @@ function util_encode_project(raw: project_format_t): buffer_t {
armpack_encode_bool(raw.layer_datas[i].paint_subs);
///end
}
armpack_encode_string("mesh_datas");
armpack_encode_array(raw.mesh_datas.length);
for (let i: i32 = 0; i < raw.mesh_datas.length; ++i) {
armpack_encode_map(7);
armpack_encode_string("name");
armpack_encode_string(raw.mesh_datas[i].name);
armpack_encode_string("scale_pos");
armpack_encode_f32(raw.mesh_datas[i].scale_pos);
armpack_encode_string("scale_tex");
armpack_encode_f32(raw.mesh_datas[i].scale_tex);
armpack_encode_string("instancing");
armpack_encode_null(); // mesh_data_instancing_t
armpack_encode_string("skin");
armpack_encode_null(); // skin_t
armpack_encode_string("vertex_arrays");
armpack_encode_array(raw.mesh_datas[i].vertex_arrays.length);
for (let j: i32 = 0; j < raw.mesh_datas[i].vertex_arrays.length; ++j) {
armpack_encode_map(3);
armpack_encode_string("attrib");
armpack_encode_string(raw.mesh_datas[i].vertex_arrays[j].attrib);
armpack_encode_string("data");
armpack_encode_string(raw.mesh_datas[i].vertex_arrays[j].data);
armpack_encode_string("values");
armpack_encode_array_i16(raw.mesh_datas[i].vertex_arrays[j].values);
}
armpack_encode_string("index_arrays");
armpack_encode_array(raw.mesh_datas[i].index_arrays.length);
for (let j: i32 = 0; j < raw.mesh_datas[i].index_arrays.length; ++j) {
armpack_encode_map(2);
armpack_encode_string("material");
armpack_encode_i32(raw.mesh_datas[i].index_arrays[j].material);
armpack_encode_string("values");
armpack_encode_array_i32(raw.mesh_datas[i].index_arrays[j].values);
}
}
util_encode_mesh_datas(raw.mesh_datas);
armpack_encode_string("mesh_assets");
armpack_encode_array_string(raw.mesh_assets);
armpack_encode_string("mesh_icons");
Expand Down Expand Up @@ -272,6 +279,5 @@ function util_encode_project(raw: project_format_t): buffer_t {

let ei: i32 = armpack_encode_end();
encoded.length = ei;

return encoded;
return encoded;
}

0 comments on commit aa65487

Please sign in to comment.