diff options
author | Alexander Romanov <a.romanov@blend4web.com> | 2017-07-03 19:49:35 +0300 |
---|---|---|
committer | Alexander Romanov <a.romanov@blend4web.com> | 2017-07-03 19:53:00 +0300 |
commit | e1482841dd5dd55cb453d37d115ec80f44c02316 (patch) | |
tree | 63cee90e2ab7b4316b4e36ffeb181700e99d6aab /source/blender/blenkernel/intern | |
parent | 1ad0cc6bde4746949eee7a9babb97178a05816c3 (diff) | |
parent | 1fb30758034c2f83862bb7fc5f30a1a4d7b4510b (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 17 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/cachefile.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/editmesh_tangent.c | 47 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh_tangent.c | 60 |
4 files changed, 73 insertions, 53 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 55d5f6f89a1..aea2ad0cd9e 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -3054,14 +3054,23 @@ void DM_calc_tangents_names_from_gpu( *r_tangent_names_count = count; } +void DM_add_named_tangent_layer_for_uv( + CustomData *uv_data, CustomData *tan_data, int numLoopData, + const char *layer_name) +{ + if (CustomData_get_named_layer_index(tan_data, CD_TANGENT, layer_name) == -1 && + CustomData_get_named_layer_index(uv_data, CD_MLOOPUV, layer_name) != -1) + { + CustomData_add_layer_named( + tan_data, CD_TANGENT, CD_CALLOC, NULL, + numLoopData, layer_name); + } +} + void DM_calc_loop_tangents( DerivedMesh *dm, bool calc_active_tangent, const char (*tangent_names)[MAX_NAME], int tangent_names_len) { - if (CustomData_number_of_layers(&dm->loopData, CD_MLOOPUV) == 0) { - return; - } - BKE_mesh_calc_loop_tangent_ex( dm->getVertArray(dm), dm->getPolyArray(dm), dm->getNumPolys(dm), diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c index 43dcde302b3..fe0cad7afa2 100644 --- a/source/blender/blenkernel/intern/cachefile.c +++ b/source/blender/blenkernel/intern/cachefile.c @@ -166,10 +166,12 @@ void BKE_cachefile_update_frame(Main *bmain, Scene *scene, const float ctime, co const float time = BKE_cachefile_time_offset(cache_file, ctime, fps); if (BKE_cachefile_filepath_get(bmain, cache_file, time, filename)) { + BKE_cachefile_clean(scene, cache_file); #ifdef WITH_ALEMBIC ABC_free_handle(cache_file->handle); cache_file->handle = ABC_create_handle(filename, NULL); #endif + break; } } } diff --git a/source/blender/blenkernel/intern/editmesh_tangent.c b/source/blender/blenkernel/intern/editmesh_tangent.c index ee13a887a5f..314c50d42c6 100644 --- a/source/blender/blenkernel/intern/editmesh_tangent.c +++ b/source/blender/blenkernel/intern/editmesh_tangent.c @@ -283,7 +283,7 @@ void BKE_editmesh_loop_tangent_calc( /* result */ CustomData *loopdata_out, const uint loopdata_out_len, - char *tangent_mask_curr_p) + short *tangent_mask_curr_p) { BMesh *bm = em->bm; @@ -295,8 +295,8 @@ void BKE_editmesh_loop_tangent_calc( bool calc_ren = false; char act_uv_name[MAX_NAME]; char ren_uv_name[MAX_NAME]; - char tangent_mask = 0; - char tangent_mask_curr = *tangent_mask_curr_p; + short tangent_mask = 0; + short tangent_mask_curr = *tangent_mask_curr_p; BKE_mesh_calc_loop_tangent_step_0( &bm->ldata, calc_active_tangent, tangent_names, tangent_names_len, @@ -305,11 +305,13 @@ void BKE_editmesh_loop_tangent_calc( if ((tangent_mask_curr | tangent_mask) != tangent_mask_curr) { for (int i = 0; i < tangent_names_len; i++) if (tangent_names[i][0]) - BKE_mesh_add_loop_tangent_named_layer_for_uv(&bm->ldata, loopdata_out, loopdata_out_len, tangent_names[i]); + BKE_mesh_add_loop_tangent_named_layer_for_uv(&bm->ldata, loopdata_out, (int)loopdata_out_len, tangent_names[i]); + if ((tangent_mask & DM_TANGENT_MASK_ORCO) && CustomData_get_named_layer_index(loopdata_out, CD_TANGENT, "") == -1) + CustomData_add_layer_named(loopdata_out, CD_TANGENT, CD_CALLOC, NULL, (int)loopdata_out_len, ""); if (calc_act && act_uv_name[0]) - BKE_mesh_add_loop_tangent_named_layer_for_uv(&bm->ldata, loopdata_out, loopdata_out_len, act_uv_name); + BKE_mesh_add_loop_tangent_named_layer_for_uv(&bm->ldata, loopdata_out, (int)loopdata_out_len, act_uv_name); if (calc_ren && ren_uv_name[0]) - BKE_mesh_add_loop_tangent_named_layer_for_uv(&bm->ldata, loopdata_out, loopdata_out_len, ren_uv_name); + BKE_mesh_add_loop_tangent_named_layer_for_uv(&bm->ldata, loopdata_out, (int)loopdata_out_len, ren_uv_name); int totface = em->tottri; #ifdef USE_LOOPTRI_DETECT_QUADS int num_face_as_quad_map; @@ -372,6 +374,15 @@ void BKE_editmesh_loop_tangent_calc( continue; /* needed for orco lookups */ htype_index |= BM_VERT; + *tangent_mask_curr_p |= DM_TANGENT_MASK_ORCO; + } + else { + /* Fill the resulting tangent_mask */ + int uv_ind = CustomData_get_named_layer_index(&bm->ldata, CD_MLOOPUV, loopdata_out->layers[index].name); + int uv_start = CustomData_get_layer_index(&bm->ldata, CD_MLOOPUV); + BLI_assert(uv_ind != -1 && uv_start != -1); + BLI_assert(uv_ind - uv_start < MAX_MTFACE); + *tangent_mask_curr_p |= 1 << (uv_ind - uv_start); } if (mesh2tangent->precomputedFaceNormals) { /* needed for face normal lookups */ @@ -382,13 +393,6 @@ void BKE_editmesh_loop_tangent_calc( mesh2tangent->looptris = (const BMLoop *(*)[3])em->looptris; mesh2tangent->tangent = loopdata_out->layers[index].data; - /* Fill the resulting tangent_mask */ - int uv_ind = CustomData_get_named_layer_index( - &bm->ldata, CD_MLOOPUV, loopdata_out->layers[index].name); - int uv_start = CustomData_get_layer_index(&bm->ldata, CD_MLOOPUV); - BLI_assert(uv_ind != -1 && uv_start != -1); - BLI_assert(uv_ind - uv_start < MAX_MTFACE); - tangent_mask_curr |= 1 << (uv_ind - uv_start); BLI_task_pool_push(task_pool, emDM_calc_loop_tangents_thread, mesh2tangent, false, TASK_PRIORITY_LOW); } @@ -409,15 +413,18 @@ void BKE_editmesh_loop_tangent_calc( *tangent_mask_curr_p = tangent_mask_curr; - /* Update active layer index */ - int uv_index = CustomData_get_layer_index_n(&bm->ldata, CD_MLOOPUV, act_uv_n); - int tan_index = CustomData_get_named_layer_index(loopdata_out, CD_TANGENT, bm->ldata.layers[uv_index].name); - CustomData_set_layer_active_index(loopdata_out, CD_TANGENT, tan_index); + int act_uv_index = CustomData_get_layer_index_n(&bm->ldata, CD_MLOOPUV, act_uv_n); + if (act_uv_index >= 0) { + int tan_index = CustomData_get_named_layer_index(loopdata_out, CD_TANGENT, bm->ldata.layers[act_uv_index].name); + CustomData_set_layer_active_index(loopdata_out, CD_TANGENT, tan_index); + } /* else tangent has been built from orco */ /* Update render layer index */ - uv_index = CustomData_get_layer_index_n(&bm->ldata, CD_MLOOPUV, ren_uv_n); - tan_index = CustomData_get_named_layer_index(loopdata_out, CD_TANGENT, bm->ldata.layers[uv_index].name); - CustomData_set_layer_render_index(loopdata_out, CD_TANGENT, tan_index); + int ren_uv_index = CustomData_get_layer_index_n(&bm->ldata, CD_MLOOPUV, ren_uv_n); + if (ren_uv_index >= 0) { + int tan_index = CustomData_get_named_layer_index(loopdata_out, CD_TANGENT, bm->ldata.layers[ren_uv_index].name); + CustomData_set_layer_render_index(loopdata_out, CD_TANGENT, tan_index); + } /* else tangent has been built from orco */ } /** \} */
\ No newline at end of file diff --git a/source/blender/blenkernel/intern/mesh_tangent.c b/source/blender/blenkernel/intern/mesh_tangent.c index 34104932e38..5a25767d3ef 100644 --- a/source/blender/blenkernel/intern/mesh_tangent.c +++ b/source/blender/blenkernel/intern/mesh_tangent.c @@ -474,7 +474,7 @@ void BKE_mesh_calc_loop_tangent_step_0( const CustomData *loopData, bool calc_active_tangent, const char (*tangent_names)[MAX_NAME], int tangent_names_count, bool *rcalc_act, bool *rcalc_ren, int *ract_uv_n, int *rren_uv_n, - char *ract_uv_name, char *rren_uv_name, char *rtangent_mask) { + char *ract_uv_name, char *rren_uv_name, short *rtangent_mask) { /* Active uv in viewport */ int layer_index = CustomData_get_layer_index(loopData, CD_MLOOPUV); *ract_uv_n = CustomData_get_active_layer(loopData, CD_MLOOPUV); @@ -549,18 +549,16 @@ void BKE_mesh_calc_loop_tangent_ex( /* result */ CustomData *loopdata_out, const uint loopdata_out_len, - char *tangent_mask_curr_p) + short *tangent_mask_curr_p) { - BLI_assert(CustomData_number_of_layers(loopdata, CD_MLOOPUV) != 0); - int act_uv_n = -1; int ren_uv_n = -1; bool calc_act = false; bool calc_ren = false; char act_uv_name[MAX_NAME]; char ren_uv_name[MAX_NAME]; - char tangent_mask = 0; - char tangent_mask_curr = *tangent_mask_curr_p; + short tangent_mask = 0; + short tangent_mask_curr = *tangent_mask_curr_p; BKE_mesh_calc_loop_tangent_step_0( loopdata, calc_active_tangent, tangent_names, tangent_names_len, @@ -571,6 +569,8 @@ void BKE_mesh_calc_loop_tangent_ex( for (int i = 0; i < tangent_names_len; i++) if (tangent_names[i][0]) BKE_mesh_add_loop_tangent_named_layer_for_uv(loopdata, loopdata_out, (int)loopdata_out_len, tangent_names[i]); + if ((tangent_mask & DM_TANGENT_MASK_ORCO) && CustomData_get_named_layer_index(loopdata, CD_TANGENT, "") == -1) + CustomData_add_layer_named(loopdata, CD_TANGENT, CD_CALLOC, NULL, (int)loopdata_out_len, ""); if (calc_act && act_uv_name[0]) BKE_mesh_add_loop_tangent_named_layer_for_uv(loopdata, loopdata_out, (int)loopdata_out_len, act_uv_name); if (calc_ren && ren_uv_name[0]) @@ -632,20 +632,24 @@ void BKE_mesh_calc_loop_tangent_ex( mesh2tangent->orco = NULL; mesh2tangent->mloopuv = CustomData_get_layer_named(loopdata, CD_MLOOPUV, loopdata_out->layers[index].name); + + /* Fill the resulting tangent_mask */ if (!mesh2tangent->mloopuv) { - mesh2tangent->orco = vert_orco; - if (!mesh2tangent->orco) - continue; + mesh2tangent->orco = vert_orco; + if (!mesh2tangent->orco) + continue; + + *tangent_mask_curr_p |= DM_TANGENT_MASK_ORCO; + } + else { + int uv_ind = CustomData_get_named_layer_index(loopdata, CD_MLOOPUV, loopdata->layers[index].name); + int uv_start = CustomData_get_layer_index(loopdata, CD_MLOOPUV); + BLI_assert(uv_ind != -1 && uv_start != -1); + BLI_assert(uv_ind - uv_start < MAX_MTFACE); + *tangent_mask_curr_p |= 1 << (uv_ind - uv_start); } - mesh2tangent->tangent = loopdata_out->layers[index].data; - /* Fill the resulting tangent_mask */ - int uv_ind = CustomData_get_named_layer_index( - loopdata, CD_MLOOPUV, loopdata_out->layers[index].name); - int uv_start = CustomData_get_layer_index(loopdata, CD_MLOOPUV); - BLI_assert(uv_ind != -1 && uv_start != -1); - BLI_assert(uv_ind - uv_start < MAX_MTFACE); - tangent_mask_curr |= (char)(1 << (uv_ind - uv_start)); + mesh2tangent->tangent = loopdata_out->layers[index].data; BLI_task_pool_push(task_pool, DM_calc_loop_tangents_thread, mesh2tangent, false, TASK_PRIORITY_LOW); } @@ -666,21 +670,19 @@ void BKE_mesh_calc_loop_tangent_ex( *tangent_mask_curr_p = tangent_mask_curr; - int uv_index, tan_index; - /* Update active layer index */ - uv_index = CustomData_get_layer_index_n(loopdata, CD_MLOOPUV, act_uv_n); - if (uv_index != -1) { - tan_index = CustomData_get_named_layer_index(loopdata_out, CD_TANGENT, loopdata->layers[uv_index].name); - CustomData_set_layer_active_index(loopdata_out, CD_TANGENT, tan_index); - } + int act_uv_index = CustomData_get_layer_index_n(loopdata, CD_MLOOPUV, act_uv_n); + if (act_uv_index != -1) { + int tan_index = CustomData_get_named_layer_index(loopdata, CD_TANGENT, loopdata->layers[act_uv_index].name); + CustomData_set_layer_active_index(loopdata, CD_TANGENT, tan_index); + }/* else tangent has been built from orco */ /* Update render layer index */ - uv_index = CustomData_get_layer_index_n(loopdata, CD_MLOOPUV, ren_uv_n); - if (uv_index != -1) { - tan_index = CustomData_get_named_layer_index(loopdata_out, CD_TANGENT, loopdata->layers[uv_index].name); - CustomData_set_layer_render_index(loopdata_out, CD_TANGENT, tan_index); - } + int ren_uv_index = CustomData_get_layer_index_n(loopdata, CD_MLOOPUV, ren_uv_n); + if (ren_uv_index != -1) { + int tan_index = CustomData_get_named_layer_index(loopdata, CD_TANGENT, loopdata->layers[ren_uv_index].name); + CustomData_set_layer_render_index(loopdata, CD_TANGENT, tan_index); + }/* else tangent has been built from orco */ } } |