Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/editmesh_tangent.cc
| Show First 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | static void emDM_calc_loop_tangents_thread(TaskPool *__restrict /*pool*/, void *taskdata) | ||||
| SGLSLEditMeshToTangent *mesh_data = static_cast<SGLSLEditMeshToTangent *>(taskdata); | SGLSLEditMeshToTangent *mesh_data = static_cast<SGLSLEditMeshToTangent *>(taskdata); | ||||
| mikk::Mikktspace<SGLSLEditMeshToTangent> mikk(*mesh_data); | mikk::Mikktspace<SGLSLEditMeshToTangent> mikk(*mesh_data); | ||||
| mikk.genTangSpace(); | mikk.genTangSpace(); | ||||
| } | } | ||||
| void BKE_editmesh_loop_tangent_calc(BMEditMesh *em, | void BKE_editmesh_loop_tangent_calc(BMEditMesh *em, | ||||
| bool calc_active_tangent, | bool calc_active_tangent, | ||||
| const char (*tangent_names)[MAX_NAME], | const char (*tangent_names)[MAX_CUSTOMDATA_LAYER_NAME], | ||||
| int tangent_names_len, | int tangent_names_len, | ||||
| const float (*poly_normals)[3], | const float (*poly_normals)[3], | ||||
| const float (*loop_normals)[3], | const float (*loop_normals)[3], | ||||
| const float (*vert_orco)[3], | const float (*vert_orco)[3], | ||||
| /* result */ | /* result */ | ||||
| CustomData *loopdata_out, | CustomData *loopdata_out, | ||||
| const uint loopdata_out_len, | const uint loopdata_out_len, | ||||
| short *tangent_mask_curr_p) | short *tangent_mask_curr_p) | ||||
| ▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | |||||
| #ifdef USE_LOOPTRI_DETECT_QUADS | #ifdef USE_LOOPTRI_DETECT_QUADS | ||||
| mesh2tangent->face_as_quad_map = face_as_quad_map; | mesh2tangent->face_as_quad_map = face_as_quad_map; | ||||
| mesh2tangent->num_face_as_quad_map = num_face_as_quad_map; | mesh2tangent->num_face_as_quad_map = num_face_as_quad_map; | ||||
| #endif | #endif | ||||
| mesh2tangent->precomputedFaceNormals = poly_normals; | mesh2tangent->precomputedFaceNormals = poly_normals; | ||||
| /* NOTE: we assume we do have tessellated loop normals at this point | /* NOTE: we assume we do have tessellated loop normals at this point | ||||
| * (in case it is object-enabled), have to check this is valid. */ | * (in case it is object-enabled), have to check this is valid. */ | ||||
| mesh2tangent->precomputedLoopNormals = loop_normals; | mesh2tangent->precomputedLoopNormals = loop_normals; | ||||
| mesh2tangent->cd_loop_uv_offset = CustomData_get_n_offset(&bm->ldata, CD_MLOOPUV, n); | mesh2tangent->cd_loop_uv_offset = CustomData_get_n_offset(&bm->ldata, CD_PROP_FLOAT2, n); | ||||
| /* needed for indexing loop-tangents */ | /* needed for indexing loop-tangents */ | ||||
| int htype_index = BM_LOOP; | int htype_index = BM_LOOP; | ||||
| if (mesh2tangent->cd_loop_uv_offset == -1) { | if (mesh2tangent->cd_loop_uv_offset == -1) { | ||||
| mesh2tangent->orco = vert_orco; | mesh2tangent->orco = vert_orco; | ||||
| if (!mesh2tangent->orco) { | if (!mesh2tangent->orco) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* needed for orco lookups */ | /* needed for orco lookups */ | ||||
| htype_index |= BM_VERT; | htype_index |= BM_VERT; | ||||
| tangent_mask_curr |= DM_TANGENT_MASK_ORCO; | tangent_mask_curr |= DM_TANGENT_MASK_ORCO; | ||||
| } | } | ||||
| else { | else { | ||||
| /* Fill the resulting tangent_mask */ | /* Fill the resulting tangent_mask */ | ||||
| int uv_ind = CustomData_get_named_layer_index( | int uv_ind = CustomData_get_named_layer_index( | ||||
| &bm->ldata, CD_MLOOPUV, loopdata_out->layers[index].name); | &bm->ldata, CD_PROP_FLOAT2, loopdata_out->layers[index].name); | ||||
| int uv_start = CustomData_get_layer_index(&bm->ldata, CD_MLOOPUV); | int uv_start = CustomData_get_layer_index(&bm->ldata, CD_PROP_FLOAT2); | ||||
| BLI_assert(uv_ind != -1 && uv_start != -1); | BLI_assert(uv_ind != -1 && uv_start != -1); | ||||
| BLI_assert(uv_ind - uv_start < MAX_MTFACE); | BLI_assert(uv_ind - uv_start < MAX_MTFACE); | ||||
| tangent_mask_curr |= 1 << (uv_ind - uv_start); | tangent_mask_curr |= 1 << (uv_ind - uv_start); | ||||
| } | } | ||||
| if (mesh2tangent->precomputedFaceNormals) { | if (mesh2tangent->precomputedFaceNormals) { | ||||
| /* needed for face normal lookups */ | /* needed for face normal lookups */ | ||||
| htype_index |= BM_FACE; | htype_index |= BM_FACE; | ||||
| } | } | ||||
| Show All 18 Lines | if (face_as_quad_map) { | ||||
| MEM_freeN(face_as_quad_map); | MEM_freeN(face_as_quad_map); | ||||
| } | } | ||||
| # undef USE_LOOPTRI_DETECT_QUADS | # undef USE_LOOPTRI_DETECT_QUADS | ||||
| #endif | #endif | ||||
| } | } | ||||
| *tangent_mask_curr_p = tangent_mask_curr; | *tangent_mask_curr_p = tangent_mask_curr; | ||||
| int act_uv_index = CustomData_get_layer_index_n(&bm->ldata, CD_MLOOPUV, act_uv_n); | int act_uv_index = CustomData_get_layer_index_n(&bm->ldata, CD_PROP_FLOAT2, act_uv_n); | ||||
| if (act_uv_index >= 0) { | if (act_uv_index >= 0) { | ||||
| int tan_index = CustomData_get_named_layer_index( | int tan_index = CustomData_get_named_layer_index( | ||||
| loopdata_out, CD_TANGENT, bm->ldata.layers[act_uv_index].name); | loopdata_out, CD_TANGENT, bm->ldata.layers[act_uv_index].name); | ||||
| CustomData_set_layer_active_index(loopdata_out, CD_TANGENT, tan_index); | CustomData_set_layer_active_index(loopdata_out, CD_TANGENT, tan_index); | ||||
| } /* else tangent has been built from orco */ | } /* else tangent has been built from orco */ | ||||
| /* Update render layer index */ | /* Update render layer index */ | ||||
| int ren_uv_index = CustomData_get_layer_index_n(&bm->ldata, CD_MLOOPUV, ren_uv_n); | int ren_uv_index = CustomData_get_layer_index_n(&bm->ldata, CD_PROP_FLOAT2, ren_uv_n); | ||||
| if (ren_uv_index >= 0) { | if (ren_uv_index >= 0) { | ||||
| int tan_index = CustomData_get_named_layer_index( | int tan_index = CustomData_get_named_layer_index( | ||||
| loopdata_out, CD_TANGENT, bm->ldata.layers[ren_uv_index].name); | loopdata_out, CD_TANGENT, bm->ldata.layers[ren_uv_index].name); | ||||
| CustomData_set_layer_render_index(loopdata_out, CD_TANGENT, tan_index); | CustomData_set_layer_render_index(loopdata_out, CD_TANGENT, tan_index); | ||||
| } /* else tangent has been built from orco */ | } /* else tangent has been built from orco */ | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||