Fix fbx vertex color import
This commit is contained in:
@@ -19,7 +19,7 @@ void io_fbx_parse_mesh(raw_mesh_t *raw, ufbx_mesh *mesh, ufbx_matrix *to_world,
|
||||
float *posa32 = (float *)malloc(sizeof(float) * numtri * 3 * 3);
|
||||
float *nora32 = (float *)malloc(sizeof(float) * numtri * 3 * 3);
|
||||
float *texa32 = has_tex ? (float *)malloc(sizeof(float) * numtri * 3 * 2) : NULL;
|
||||
float *cola32 = has_col ? (float *)malloc(sizeof(float) * numtri * 3 * 3) : NULL;
|
||||
float *cola32 = has_col ? (float *)malloc(sizeof(float) * numtri * 3 * 4) : NULL;
|
||||
int pi = 0;
|
||||
int ni = 0;
|
||||
int ti = 0;
|
||||
@@ -50,6 +50,7 @@ void io_fbx_parse_mesh(raw_mesh_t *raw, ufbx_mesh *mesh, ufbx_matrix *to_world,
|
||||
cola32[ci++] = ufbx_get_vertex_vec4(&mesh->vertex_color, a).x;
|
||||
cola32[ci++] = ufbx_get_vertex_vec4(&mesh->vertex_color, a).y;
|
||||
cola32[ci++] = ufbx_get_vertex_vec4(&mesh->vertex_color, a).z;
|
||||
cola32[ci++] = ufbx_get_vertex_vec4(&mesh->vertex_color, a).w;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,11 +113,12 @@ void io_fbx_parse_mesh(raw_mesh_t *raw, ufbx_mesh *mesh, ufbx_matrix *to_world,
|
||||
|
||||
short *cola = NULL;
|
||||
if (cola32 != NULL) {
|
||||
short *cola = malloc(sizeof(short) * vertex_count * 3);
|
||||
cola = malloc(sizeof(short) * vertex_count * 4);
|
||||
for (int i = 0; i < vertex_count; ++i) {
|
||||
cola[i * 3 ] = cola32[i * 3 ] * 32767;
|
||||
cola[i * 3 + 1] = cola32[i * 3 + 1] * 32767;
|
||||
cola[i * 3 + 2] = cola32[i * 3 + 2] * 32767;
|
||||
cola[i * 4 ] = cola32[i * 4 ] * 32767;
|
||||
cola[i * 4 + 1] = cola32[i * 4 + 1] * 32767;
|
||||
cola[i * 4 + 2] = cola32[i * 4 + 2] * 32767;
|
||||
cola[i * 4 + 3] = cola32[i * 4 + 3] * 32767;
|
||||
}
|
||||
free(cola32);
|
||||
}
|
||||
@@ -133,6 +135,12 @@ void io_fbx_parse_mesh(raw_mesh_t *raw, ufbx_mesh *mesh, ufbx_matrix *to_world,
|
||||
raw->texa->buffer = texa;
|
||||
raw->texa->length = raw->texa->capacity = vertex_count * 2;
|
||||
|
||||
if (cola != NULL) {
|
||||
raw->cola = (i16_array_t *)malloc(sizeof(i16_array_t));
|
||||
raw->cola->buffer = cola;
|
||||
raw->cola->length = raw->cola->capacity = vertex_count * 4;
|
||||
}
|
||||
|
||||
raw->inda = (u32_array_t *)malloc(sizeof(u32_array_t));
|
||||
raw->inda->buffer = inda;
|
||||
raw->inda->length = raw->inda->capacity = index_count;
|
||||
|
||||
@@ -84,14 +84,6 @@ function import_mesh_finish_import() {
|
||||
|
||||
function _import_mesh_make_mesh(mesh: raw_mesh_t) {
|
||||
let raw: raw_mesh_t = import_mesh_raw_mesh(mesh);
|
||||
if (mesh.cola != null) {
|
||||
let va: vertex_array_t = {
|
||||
values: mesh.cola,
|
||||
attrib: "col",
|
||||
data: "short4norm"
|
||||
};
|
||||
array_push(raw.vertex_arrays, va);
|
||||
}
|
||||
|
||||
let md: mesh_data_t = mesh_data_create(raw);
|
||||
context_raw.paint_object = context_main_object();
|
||||
@@ -150,14 +142,6 @@ function import_mesh_make_mesh(mesh: raw_mesh_t) {
|
||||
|
||||
function import_mesh_add_mesh(mesh: raw_mesh_t) {
|
||||
let raw: raw_mesh_t = import_mesh_raw_mesh(mesh);
|
||||
if (mesh.cola != null) {
|
||||
let va: vertex_array_t = {
|
||||
values: mesh.cola,
|
||||
attrib: "col",
|
||||
data: "short4norm"
|
||||
};
|
||||
array_push(raw.vertex_arrays, va);
|
||||
}
|
||||
|
||||
let md: mesh_data_t = mesh_data_create(raw);
|
||||
|
||||
|
||||
+10
-16
@@ -111,14 +111,6 @@ function import_mesh_finish_import() {
|
||||
|
||||
function _import_mesh_make_mesh(mesh: raw_mesh_t) {
|
||||
let raw: mesh_data_t = import_mesh_raw_mesh(mesh);
|
||||
if (mesh.cola != null) {
|
||||
let va: vertex_array_t = {
|
||||
values: mesh.cola,
|
||||
attrib: "col",
|
||||
data: "short4norm"
|
||||
};
|
||||
array_push(raw.vertex_arrays, va);
|
||||
}
|
||||
|
||||
let md: mesh_data_t = mesh_data_create(raw);
|
||||
context_raw.paint_object = context_main_object();
|
||||
@@ -206,14 +198,6 @@ function import_mesh_make_mesh(mesh: raw_mesh_t) {
|
||||
|
||||
function _import_mesh_add_mesh(mesh: raw_mesh_t) {
|
||||
let raw: mesh_data_t = import_mesh_raw_mesh(mesh);
|
||||
if (mesh.cola != null) {
|
||||
let va: vertex_array_t = {
|
||||
values: mesh.cola,
|
||||
attrib: "col",
|
||||
data: "short4norm"
|
||||
};
|
||||
array_push(raw.vertex_arrays, va);
|
||||
}
|
||||
|
||||
///if is_forge
|
||||
util_mesh_ext_pack_uvs(mesh.texa);
|
||||
@@ -294,5 +278,15 @@ function import_mesh_raw_mesh(mesh: raw_mesh_t): mesh_data_t {
|
||||
scale_pos: mesh.scale_pos,
|
||||
scale_tex: mesh.scale_tex
|
||||
};
|
||||
|
||||
if (mesh.cola != null) {
|
||||
let va: vertex_array_t = {
|
||||
values: mesh.cola,
|
||||
attrib: "col",
|
||||
data: "short4norm"
|
||||
};
|
||||
array_push(raw.vertex_arrays, va);
|
||||
}
|
||||
|
||||
return raw;
|
||||
}
|
||||
|
||||
+8
-10
@@ -434,16 +434,14 @@ function project_import_mesh_box(path: string, replace_existing: bool = true, cl
|
||||
}
|
||||
|
||||
///if (is_paint || is_sculpt)
|
||||
// if (ends_with(to_lower_case(path), ".fbx")) {
|
||||
// let h: ui_handle_t = ui_handle(__ID__);
|
||||
// if (h.init) {
|
||||
// h.selected = context_raw.parse_vcols;
|
||||
// }
|
||||
// context_raw.parse_vcols = ui_check(h, tr("Parse Vertex Colors"));
|
||||
// if (ui.is_hovered) {
|
||||
// ui_tooltip(tr("Import vertex color data"));
|
||||
// }
|
||||
// }
|
||||
if (ends_with(to_lower_case(path), ".fbx")) {
|
||||
let h: ui_handle_t = ui_handle(__ID__);
|
||||
h.selected = context_raw.parse_vcols;
|
||||
context_raw.parse_vcols = ui_check(h, tr("Parse Vertex Colors"));
|
||||
if (ui.is_hovered) {
|
||||
ui_tooltip(tr("Import vertex color data"));
|
||||
}
|
||||
}
|
||||
|
||||
if (ends_with(to_lower_case(path), ".blend")) {
|
||||
import_blend_mesh_ui();
|
||||
|
||||
Reference in New Issue
Block a user