Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/data_transfer.cc
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| /* Compute custom normals into regular loop normals, which will be used for the transfer. */ | /* Compute custom normals into regular loop normals, which will be used for the transfer. */ | ||||
| const float(*positions_dst)[3] = BKE_mesh_vert_positions(me_dst); | const float(*positions_dst)[3] = BKE_mesh_vert_positions(me_dst); | ||||
| const int num_verts_dst = me_dst->totvert; | const int num_verts_dst = me_dst->totvert; | ||||
| const MEdge *edges_dst = BKE_mesh_edges(me_dst); | const MEdge *edges_dst = BKE_mesh_edges(me_dst); | ||||
| const int num_edges_dst = me_dst->totedge; | const int num_edges_dst = me_dst->totedge; | ||||
| const MPoly *polys_dst = BKE_mesh_polys(me_dst); | const MPoly *polys_dst = BKE_mesh_polys(me_dst); | ||||
| const int num_polys_dst = me_dst->totpoly; | const int num_polys_dst = me_dst->totpoly; | ||||
| const MLoop *loops_dst = BKE_mesh_loops(me_dst); | |||||
| const int num_loops_dst = me_dst->totloop; | const int num_loops_dst = me_dst->totloop; | ||||
| CustomData *ldata_dst = &me_dst->ldata; | CustomData *ldata_dst = &me_dst->ldata; | ||||
| const bool use_split_nors_dst = (me_dst->flag & ME_AUTOSMOOTH) != 0; | const bool use_split_nors_dst = (me_dst->flag & ME_AUTOSMOOTH) != 0; | ||||
| const float split_angle_dst = me_dst->smoothresh; | const float split_angle_dst = me_dst->smoothresh; | ||||
| /* This should be ensured by cddata_masks we pass to code generating/giving us me_src now. */ | /* This should be ensured by cddata_masks we pass to code generating/giving us me_src now. */ | ||||
| BLI_assert(CustomData_get_layer(&me_src->ldata, CD_NORMAL) != nullptr); | BLI_assert(CustomData_get_layer(&me_src->ldata, CD_NORMAL) != nullptr); | ||||
| Show All 15 Lines | |||||
| if (dirty_nors_dst || do_loop_nors_dst) { | if (dirty_nors_dst || do_loop_nors_dst) { | ||||
| const bool *sharp_edges = static_cast<const bool *>( | const bool *sharp_edges = static_cast<const bool *>( | ||||
| CustomData_get_layer_named(&me_dst->edata, CD_PROP_BOOL, "sharp_edge")); | CustomData_get_layer_named(&me_dst->edata, CD_PROP_BOOL, "sharp_edge")); | ||||
| BKE_mesh_normals_loop_split(positions_dst, | BKE_mesh_normals_loop_split(positions_dst, | ||||
| BKE_mesh_vertex_normals_ensure(me_dst), | BKE_mesh_vertex_normals_ensure(me_dst), | ||||
| num_verts_dst, | num_verts_dst, | ||||
| edges_dst, | edges_dst, | ||||
| num_edges_dst, | num_edges_dst, | ||||
| loops_dst, | me_dst->corner_verts().data(), | ||||
| me_dst->corner_edges().data(), | |||||
| loop_nors_dst, | loop_nors_dst, | ||||
| num_loops_dst, | num_loops_dst, | ||||
| polys_dst, | polys_dst, | ||||
| BKE_mesh_poly_normals_ensure(me_dst), | BKE_mesh_poly_normals_ensure(me_dst), | ||||
| num_polys_dst, | num_polys_dst, | ||||
| use_split_nors_dst, | use_split_nors_dst, | ||||
| split_angle_dst, | split_angle_dst, | ||||
| sharp_edges, | sharp_edges, | ||||
| Show All 19 Lines | |||||
| /* Bake edited destination loop normals into custom normals again. */ | /* Bake edited destination loop normals into custom normals again. */ | ||||
| const float(*positions_dst)[3] = BKE_mesh_vert_positions(me_dst); | const float(*positions_dst)[3] = BKE_mesh_vert_positions(me_dst); | ||||
| const int num_verts_dst = me_dst->totvert; | const int num_verts_dst = me_dst->totvert; | ||||
| MEdge *edges_dst = BKE_mesh_edges_for_write(me_dst); | MEdge *edges_dst = BKE_mesh_edges_for_write(me_dst); | ||||
| const int num_edges_dst = me_dst->totedge; | const int num_edges_dst = me_dst->totedge; | ||||
| MPoly *polys_dst = BKE_mesh_polys_for_write(me_dst); | MPoly *polys_dst = BKE_mesh_polys_for_write(me_dst); | ||||
| const int num_polys_dst = me_dst->totpoly; | const int num_polys_dst = me_dst->totpoly; | ||||
| MLoop *loops_dst = BKE_mesh_loops_for_write(me_dst); | |||||
| const int num_loops_dst = me_dst->totloop; | const int num_loops_dst = me_dst->totloop; | ||||
| CustomData *ldata_dst = &me_dst->ldata; | CustomData *ldata_dst = &me_dst->ldata; | ||||
| const float(*poly_nors_dst)[3] = BKE_mesh_poly_normals_ensure(me_dst); | const float(*poly_nors_dst)[3] = BKE_mesh_poly_normals_ensure(me_dst); | ||||
| float(*loop_nors_dst)[3] = static_cast<float(*)[3]>( | float(*loop_nors_dst)[3] = static_cast<float(*)[3]>( | ||||
| CustomData_get_layer_for_write(ldata_dst, CD_NORMAL, me_dst->totloop)); | CustomData_get_layer_for_write(ldata_dst, CD_NORMAL, me_dst->totloop)); | ||||
| short(*custom_nors_dst)[2] = static_cast<short(*)[2]>( | short(*custom_nors_dst)[2] = static_cast<short(*)[2]>( | ||||
| CustomData_get_layer_for_write(ldata_dst, CD_CUSTOMLOOPNORMAL, me_dst->totloop)); | CustomData_get_layer_for_write(ldata_dst, CD_CUSTOMLOOPNORMAL, me_dst->totloop)); | ||||
| if (!custom_nors_dst) { | if (!custom_nors_dst) { | ||||
| custom_nors_dst = static_cast<short(*)[2]>(CustomData_add_layer( | custom_nors_dst = static_cast<short(*)[2]>(CustomData_add_layer( | ||||
| ldata_dst, CD_CUSTOMLOOPNORMAL, CD_SET_DEFAULT, nullptr, num_loops_dst)); | ldata_dst, CD_CUSTOMLOOPNORMAL, CD_SET_DEFAULT, nullptr, num_loops_dst)); | ||||
| } | } | ||||
| bke::MutableAttributeAccessor attributes = me_dst->attributes_for_write(); | bke::MutableAttributeAccessor attributes = me_dst->attributes_for_write(); | ||||
| bke::SpanAttributeWriter<bool> sharp_edges = attributes.lookup_or_add_for_write_span<bool>( | bke::SpanAttributeWriter<bool> sharp_edges = attributes.lookup_or_add_for_write_span<bool>( | ||||
| "sharp_edge", ATTR_DOMAIN_EDGE); | "sharp_edge", ATTR_DOMAIN_EDGE); | ||||
| /* Note loop_nors_dst contains our custom normals as transferred from source... */ | /* Note loop_nors_dst contains our custom normals as transferred from source... */ | ||||
| BKE_mesh_normals_loop_custom_set(positions_dst, | BKE_mesh_normals_loop_custom_set(positions_dst, | ||||
| BKE_mesh_vertex_normals_ensure(me_dst), | BKE_mesh_vertex_normals_ensure(me_dst), | ||||
| num_verts_dst, | num_verts_dst, | ||||
| edges_dst, | edges_dst, | ||||
| num_edges_dst, | num_edges_dst, | ||||
| loops_dst, | me_dst->corner_verts().data(), | ||||
| me_dst->corner_edges().data(), | |||||
| loop_nors_dst, | loop_nors_dst, | ||||
| num_loops_dst, | num_loops_dst, | ||||
| polys_dst, | polys_dst, | ||||
| poly_nors_dst, | poly_nors_dst, | ||||
| num_polys_dst, | num_polys_dst, | ||||
| sharp_edges.span.data(), | sharp_edges.span.data(), | ||||
| custom_nors_dst); | custom_nors_dst); | ||||
| sharp_edges.finish(); | sharp_edges.finish(); | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| if (DT_DATATYPE_IS_LOOP(dtdata_type)) { | if (DT_DATATYPE_IS_LOOP(dtdata_type)) { | ||||
| const float(*positions_dst)[3] = BKE_mesh_vert_positions(me_dst); | const float(*positions_dst)[3] = BKE_mesh_vert_positions(me_dst); | ||||
| const int num_verts_dst = me_dst->totvert; | const int num_verts_dst = me_dst->totvert; | ||||
| const MEdge *edges_dst = BKE_mesh_edges(me_dst); | const MEdge *edges_dst = BKE_mesh_edges(me_dst); | ||||
| const int num_edges_dst = me_dst->totedge; | const int num_edges_dst = me_dst->totedge; | ||||
| const MPoly *polys_dst = BKE_mesh_polys(me_dst); | const MPoly *polys_dst = BKE_mesh_polys(me_dst); | ||||
| const int num_polys_dst = me_dst->totpoly; | const int num_polys_dst = me_dst->totpoly; | ||||
| const MLoop *loops_dst = BKE_mesh_loops(me_dst); | const int *corner_verts_dst = me_dst->corner_verts().data(); | ||||
| const int *corner_edges_dst = me_dst->corner_edges().data(); | |||||
| const int num_loops_dst = me_dst->totloop; | const int num_loops_dst = me_dst->totloop; | ||||
| CustomData *ldata_dst = &me_dst->ldata; | CustomData *ldata_dst = &me_dst->ldata; | ||||
| MeshRemapIslandsCalc island_callback = data_transfer_get_loop_islands_generator(cddata_type); | MeshRemapIslandsCalc island_callback = data_transfer_get_loop_islands_generator(cddata_type); | ||||
| if (!geom_map_init[LDATA]) { | if (!geom_map_init[LDATA]) { | ||||
| const int num_loops_src = me_src->totloop; | const int num_loops_src = me_src->totloop; | ||||
| Show All 23 Lines | |||||
| space_transform, | space_transform, | ||||
| max_distance, | max_distance, | ||||
| ray_radius, | ray_radius, | ||||
| me_dst, | me_dst, | ||||
| positions_dst, | positions_dst, | ||||
| num_verts_dst, | num_verts_dst, | ||||
| edges_dst, | edges_dst, | ||||
| num_edges_dst, | num_edges_dst, | ||||
| loops_dst, | corner_verts_dst, | ||||
| corner_edges_dst, | |||||
| num_loops_dst, | num_loops_dst, | ||||
| polys_dst, | polys_dst, | ||||
| num_polys_dst, | num_polys_dst, | ||||
| ldata_dst, | ldata_dst, | ||||
| (me_dst->flag & ME_AUTOSMOOTH) != 0, | (me_dst->flag & ME_AUTOSMOOTH) != 0, | ||||
| me_dst->smoothresh, | me_dst->smoothresh, | ||||
| dirty_nors_dst, | dirty_nors_dst, | ||||
| me_src, | me_src, | ||||
| island_callback, | island_callback, | ||||
| islands_handling_precision, | islands_handling_precision, | ||||
| &geom_map[LDATA]); | &geom_map[LDATA]); | ||||
| geom_map_init[LDATA] = true; | geom_map_init[LDATA] = true; | ||||
| } | } | ||||
| if (mdef && vg_idx != -1 && !weights[LDATA]) { | if (mdef && vg_idx != -1 && !weights[LDATA]) { | ||||
| weights[LDATA] = static_cast<float *>( | weights[LDATA] = static_cast<float *>( | ||||
| MEM_mallocN(sizeof(*weights[LDATA]) * size_t(num_loops_dst), __func__)); | MEM_mallocN(sizeof(*weights[LDATA]) * size_t(num_loops_dst), __func__)); | ||||
| BKE_defvert_extract_vgroup_to_loopweights( | BKE_defvert_extract_vgroup_to_loopweights(mdef, | ||||
| mdef, vg_idx, num_verts_dst, loops_dst, num_loops_dst, invert_vgroup, weights[LDATA]); | vg_idx, | ||||
| num_verts_dst, | |||||
| corner_verts_dst, | |||||
| num_loops_dst, | |||||
| invert_vgroup, | |||||
| weights[LDATA]); | |||||
| } | } | ||||
| if (data_transfer_layersmapping_generate(&lay_map, | if (data_transfer_layersmapping_generate(&lay_map, | ||||
| ob_src, | ob_src, | ||||
| ob_dst, | ob_dst, | ||||
| me_src, | me_src, | ||||
| me_dst, | me_dst, | ||||
| ME_LOOP, | ME_LOOP, | ||||
| Show All 19 Lines | |||||
| BLI_freelistN(&lay_map); | BLI_freelistN(&lay_map); | ||||
| } | } | ||||
| } | } | ||||
| if (DT_DATATYPE_IS_POLY(dtdata_type)) { | if (DT_DATATYPE_IS_POLY(dtdata_type)) { | ||||
| const float(*positions_dst)[3] = BKE_mesh_vert_positions(me_dst); | const float(*positions_dst)[3] = BKE_mesh_vert_positions(me_dst); | ||||
| const int num_verts_dst = me_dst->totvert; | const int num_verts_dst = me_dst->totvert; | ||||
| const MPoly *polys_dst = BKE_mesh_polys(me_dst); | const MPoly *polys_dst = BKE_mesh_polys(me_dst); | ||||
| const int num_polys_dst = me_dst->totpoly; | const int num_polys_dst = me_dst->totpoly; | ||||
| const MLoop *loops_dst = BKE_mesh_loops(me_dst); | const int *corner_verts_dst = me_dst->corner_verts().data(); | ||||
| const int num_loops_dst = me_dst->totloop; | const int num_loops_dst = me_dst->totloop; | ||||
| if (!geom_map_init[PDATA]) { | if (!geom_map_init[PDATA]) { | ||||
| const int num_polys_src = me_src->totpoly; | const int num_polys_src = me_src->totpoly; | ||||
| if ((map_poly_mode == MREMAP_MODE_TOPOLOGY) && (num_polys_dst != num_polys_src)) { | if ((map_poly_mode == MREMAP_MODE_TOPOLOGY) && (num_polys_dst != num_polys_src)) { | ||||
| BKE_report(reports, | BKE_report(reports, | ||||
| RPT_ERROR, | RPT_ERROR, | ||||
| Show All 17 Lines | |||||
| } | } | ||||
| BKE_mesh_remap_calc_polys_from_mesh(map_poly_mode, | BKE_mesh_remap_calc_polys_from_mesh(map_poly_mode, | ||||
| space_transform, | space_transform, | ||||
| max_distance, | max_distance, | ||||
| ray_radius, | ray_radius, | ||||
| me_dst, | me_dst, | ||||
| positions_dst, | positions_dst, | ||||
| loops_dst, | corner_verts_dst, | ||||
| polys_dst, | polys_dst, | ||||
| num_polys_dst, | num_polys_dst, | ||||
| me_src, | me_src, | ||||
| &geom_map[PDATA]); | &geom_map[PDATA]); | ||||
| geom_map_init[PDATA] = true; | geom_map_init[PDATA] = true; | ||||
| } | } | ||||
| if (mdef && vg_idx != -1 && !weights[PDATA]) { | if (mdef && vg_idx != -1 && !weights[PDATA]) { | ||||
| weights[PDATA] = static_cast<float *>( | weights[PDATA] = static_cast<float *>( | ||||
| MEM_mallocN(sizeof(*weights[PDATA]) * size_t(num_polys_dst), __func__)); | MEM_mallocN(sizeof(*weights[PDATA]) * size_t(num_polys_dst), __func__)); | ||||
| BKE_defvert_extract_vgroup_to_polyweights(mdef, | BKE_defvert_extract_vgroup_to_polyweights(mdef, | ||||
| vg_idx, | vg_idx, | ||||
| num_verts_dst, | num_verts_dst, | ||||
| loops_dst, | corner_verts_dst, | ||||
| num_loops_dst, | num_loops_dst, | ||||
| polys_dst, | polys_dst, | ||||
| num_polys_dst, | num_polys_dst, | ||||
| invert_vgroup, | invert_vgroup, | ||||
| weights[PDATA]); | weights[PDATA]); | ||||
| } | } | ||||
| if (data_transfer_layersmapping_generate(&lay_map, | if (data_transfer_layersmapping_generate(&lay_map, | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||