paint: skinning cleanup
This commit is contained in:
+7
-22
@@ -81,23 +81,6 @@ static void *import_svg(char *path) {
|
||||
return io_svg_parse((char *)b->buffer);
|
||||
}
|
||||
|
||||
static buffer_t *plugins_skin_blob = NULL;
|
||||
|
||||
void plugins_skin_data_clear() {
|
||||
gc_unroot(plugins_skin_blob);
|
||||
plugins_skin_blob = NULL;
|
||||
}
|
||||
|
||||
static void plugins_skin_data_set(buffer_t *b) {
|
||||
plugins_skin_data_clear();
|
||||
plugins_skin_blob = b;
|
||||
gc_root(plugins_skin_blob);
|
||||
}
|
||||
|
||||
bool plugins_skin_data_exists() {
|
||||
return plugins_skin_blob != NULL;
|
||||
}
|
||||
|
||||
static void plugins_free_raw_mesh(raw_mesh_t *raw) {
|
||||
i16_array_t *arrays[] = {raw->posa, raw->nora, raw->texa, raw->texa1, raw->cola};
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
@@ -114,12 +97,12 @@ static void plugins_free_raw_mesh(raw_mesh_t *raw) {
|
||||
free(raw);
|
||||
}
|
||||
|
||||
bool plugins_skin_data_apply(int frame, i16_array_t *posa, i16_array_t *nora, float *scale_pos) {
|
||||
if (plugins_skin_blob == NULL) {
|
||||
bool plugins_skin_data_apply(buffer_t *blob, int frame, i16_array_t *posa, i16_array_t *nora, float *scale_pos) {
|
||||
if (blob == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
raw_mesh_t *raw = io_gltf_parse_skinned((char *)plugins_skin_blob->buffer, plugins_skin_blob->length, NULL, frame);
|
||||
raw_mesh_t *raw = io_gltf_parse_skinned((char *)blob->buffer, blob->length, NULL, frame);
|
||||
if (raw == NULL) {
|
||||
return false;
|
||||
}
|
||||
@@ -139,8 +122,10 @@ static void *import_gltf_glb(char *path) {
|
||||
return io_gltf_parse((char *)b->buffer, b->length, path);
|
||||
}
|
||||
else {
|
||||
plugins_skin_data_set(b);
|
||||
return io_gltf_parse_skinned((char *)b->buffer, b->length, path, plugins_skinning_frame);
|
||||
raw_mesh_t *raw = io_gltf_parse_skinned((char *)b->buffer, b->length, path, plugins_skinning_frame);
|
||||
raw->blob = b;
|
||||
gc_root(b);
|
||||
return raw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -666,9 +666,7 @@ void import_keymap_run(char *path);
|
||||
void tab_plugins_draw(ui_handle_t *htab);
|
||||
void plugin_uv_unwrap_button();
|
||||
void plugin_uv_unwrap_per_object_button(mesh_object_t *mo);
|
||||
void plugins_skin_data_clear();
|
||||
bool plugins_skin_data_exists();
|
||||
bool plugins_skin_data_apply(int frame, i16_array_t *posa, i16_array_t *nora, float *scale_pos);
|
||||
bool plugins_skin_data_apply(buffer_t *blob, int frame, i16_array_t *posa, i16_array_t *nora, float *scale_pos);
|
||||
void make_discard_color_id(node_shader_t *kong, char *tex_coord);
|
||||
void make_discard_face(node_shader_t *kong);
|
||||
void make_discard_uv_island(node_shader_t *kong);
|
||||
|
||||
@@ -19,12 +19,6 @@ void import_mesh_run(char *path, bool _clear_layers, bool replace_existing, bool
|
||||
import_mesh_no_reset = keep_camera;
|
||||
g_context->layer_filter = 0;
|
||||
|
||||
#ifdef WITH_PLUGINS
|
||||
if (replace_existing) {
|
||||
plugins_skin_data_clear();
|
||||
}
|
||||
#endif
|
||||
|
||||
char *p = to_lower_case(path);
|
||||
if (ends_with(p, ".obj")) {
|
||||
import_obj_run(path, replace_existing);
|
||||
@@ -155,6 +149,9 @@ char *_import_mesh_number_ext(i32 i) {
|
||||
|
||||
void import_mesh_make_mesh(raw_mesh_t *mesh) {
|
||||
if (mesh == NULL || mesh->posa == NULL || mesh->nora == NULL || mesh->inda == NULL || mesh->posa->length == 0) {
|
||||
if (mesh != NULL) {
|
||||
gc_unroot(mesh->blob);
|
||||
}
|
||||
console_error(strings_failed_to_read_mesh_data());
|
||||
return;
|
||||
}
|
||||
@@ -167,7 +164,10 @@ void import_mesh_make_mesh(raw_mesh_t *mesh) {
|
||||
|
||||
mesh_data_t *raw = import_mesh_raw_mesh(mesh);
|
||||
|
||||
mesh_data_t *md = mesh_data_create(raw);
|
||||
mesh_data_t *md = mesh_data_create(raw);
|
||||
md->_->skin_blob = mesh->blob;
|
||||
gc_unroot(mesh->blob);
|
||||
|
||||
g_context->paint_object = context_main_object();
|
||||
|
||||
context_select_paint_object(context_main_object());
|
||||
@@ -236,7 +236,9 @@ void import_mesh_add_mesh(raw_mesh_t *mesh) {
|
||||
|
||||
mesh_data_t *raw = import_mesh_raw_mesh(mesh);
|
||||
// util_mesh_pack_uvs(mesh->texa);
|
||||
mesh_data_t *md = mesh_data_create(raw);
|
||||
mesh_data_t *md = mesh_data_create(raw);
|
||||
md->_->skin_blob = mesh->blob;
|
||||
gc_unroot(mesh->blob);
|
||||
|
||||
mesh_object_t *object = scene_add_mesh_object(md, g_context->paint_object->material, g_context->paint_object->base);
|
||||
object->base->name = mesh->name;
|
||||
|
||||
@@ -378,14 +378,14 @@ void project_reimport_mesh() {
|
||||
|
||||
bool project_reskin_mesh(int frame) {
|
||||
#ifdef WITH_PLUGINS
|
||||
if (!plugins_skin_data_exists()) {
|
||||
mesh_data_t *md = context_main_object()->data;
|
||||
if (md->_->skin_blob == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mesh_data_t *md = context_main_object()->data;
|
||||
vertex_array_t *pos = mesh_data_get_vertex_array(md, "pos");
|
||||
vertex_array_t *nor = mesh_data_get_vertex_array(md, "nor");
|
||||
if (!plugins_skin_data_apply(frame, pos->values, nor->values, &md->scale_pos)) {
|
||||
if (!plugins_skin_data_apply(md->_->skin_blob, frame, pos->values, nor->values, &md->scale_pos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user