Skip to content

Commit

Permalink
Fix arm mesh import export
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Sep 26, 2024
1 parent 50c4033 commit 4cc0b38
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
23 changes: 16 additions & 7 deletions base/sources/import_arm.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@

let scene_raw_gc: scene_t;

function import_arm_run_project(path: string) {
let b: buffer_t = data_get_blob(path);
let project: project_format_t;
let import_as_mesh: bool = false;

if (import_arm_is_legacy(b)) {
project = import_arm_from_legacy(b);
}
else if (!import_arm_has_version(b)) {
import_as_mesh = true;
scene_raw_gc = armpack_decode(b);
project = {
mesh_datas: scene_raw_gc.mesh_datas
};
}
else {
project = armpack_decode(b);
}
Expand All @@ -26,16 +36,10 @@ function import_arm_run_project(path: string) {
}
return;
}

let import_as_mesh: bool = b[10] != 118; // 'v', no version
context_raw.layers_preview_dirty = true;
context_raw.layer_filter = 0;
///end

///if is_lab
let import_as_mesh: bool = true;
///end

project_new(import_as_mesh);
project_filepath = path;
ui_files_filename = substring(path, string_last_index_of(path, path_sep) + 1, string_last_index_of(path, "."));
Expand Down Expand Up @@ -402,7 +406,7 @@ function import_arm_run_project(path: string) {
}

///if (is_paint || is_sculpt)
function import_arm_run_mesh(raw: scene_t) {
function import_arm_run_mesh(raw: project_format_t) {
project_paint_objects = [];
for (let i: i32 = 0; i < raw.mesh_datas.length; ++i) {
let md: mesh_data_t = mesh_data_create(raw.mesh_datas[i]);
Expand Down Expand Up @@ -827,6 +831,11 @@ function _import_arm_get_node_canvas_array(map: map_t<string, any>, key: string)
return ar;
}

function import_arm_has_version(b: buffer_t): bool {
let has_version: bool = b[10] == 118; // 'v';
return has_version;
}

function import_arm_is_legacy(b: buffer_t): bool {
// Cloud materials are at version 0.8 / 0.9
let has_version: bool = b[10] == 118; // 'v'
Expand Down
25 changes: 25 additions & 0 deletions base/sources/util_encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,32 @@ function util_encode_scene(raw: scene_t): buffer_t {
let encoded: buffer_t = buffer_create(size);

armpack_encode_start(encoded.buffer);
armpack_encode_map(13);
armpack_encode_string("name");
armpack_encode_null();
armpack_encode_string("objects");
armpack_encode_null();
util_encode_mesh_datas(raw.mesh_datas);
armpack_encode_string("light_datas");
armpack_encode_null();
armpack_encode_string("camera_datas");
armpack_encode_null();
armpack_encode_string("camera_ref");
armpack_encode_null();
armpack_encode_string("material_datas");
armpack_encode_null();
armpack_encode_string("shader_datas");
armpack_encode_null();
armpack_encode_string("world_datas");
armpack_encode_null();
armpack_encode_string("world_ref");
armpack_encode_null();
armpack_encode_string("particle_datas");
armpack_encode_null();
armpack_encode_string("speaker_datas");
armpack_encode_null();
armpack_encode_string("embedded_datas");
armpack_encode_null();

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

0 comments on commit 4cc0b38

Please sign in to comment.