Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/object_dupli.cc
| Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | |||||
| #include "NOD_geometry_nodes_log.hh" | #include "NOD_geometry_nodes_log.hh" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "RNA_path.h" | #include "RNA_path.h" | ||||
| #include "RNA_prototypes.h" | #include "RNA_prototypes.h" | ||||
| #include "RNA_types.h" | #include "RNA_types.h" | ||||
| using blender::Array; | using blender::Array; | ||||
| using blender::float2; | |||||
| using blender::float3; | using blender::float3; | ||||
| using blender::float4x4; | using blender::float4x4; | ||||
| using blender::Span; | using blender::Span; | ||||
| using blender::Vector; | using blender::Vector; | ||||
| using blender::bke::InstanceReference; | using blender::bke::InstanceReference; | ||||
| using blender::bke::Instances; | using blender::bke::Instances; | ||||
| namespace geo_log = blender::nodes::geo_eval_log; | namespace geo_log = blender::nodes::geo_eval_log; | ||||
| ▲ Show 20 Lines • Show All 979 Lines • ▼ Show 20 Lines | |||||
| struct FaceDupliData_Mesh { | struct FaceDupliData_Mesh { | ||||
| FaceDupliData_Params params; | FaceDupliData_Params params; | ||||
| int totface; | int totface; | ||||
| const MPoly *mpoly; | const MPoly *mpoly; | ||||
| const MLoop *mloop; | const MLoop *mloop; | ||||
| Span<float3> vert_positions; | Span<float3> vert_positions; | ||||
| const float (*orco)[3]; | const float (*orco)[3]; | ||||
| const MLoopUV *mloopuv; | const float2 *mloopuv; | ||||
| }; | }; | ||||
| struct FaceDupliData_EditMesh { | struct FaceDupliData_EditMesh { | ||||
| FaceDupliData_Params params; | FaceDupliData_Params params; | ||||
| BMEditMesh *em; | BMEditMesh *em; | ||||
| bool has_orco, has_uvs; | bool has_orco, has_uvs; | ||||
| ▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | |||||
| static void make_child_duplis_faces_from_mesh(const DupliContext *ctx, | static void make_child_duplis_faces_from_mesh(const DupliContext *ctx, | ||||
| void *userdata, | void *userdata, | ||||
| Object *inst_ob) | Object *inst_ob) | ||||
| { | { | ||||
| FaceDupliData_Mesh *fdd = (FaceDupliData_Mesh *)userdata; | FaceDupliData_Mesh *fdd = (FaceDupliData_Mesh *)userdata; | ||||
| const MPoly *mpoly = fdd->mpoly, *mp; | const MPoly *mpoly = fdd->mpoly, *mp; | ||||
| const MLoop *mloop = fdd->mloop; | const MLoop *mloop = fdd->mloop; | ||||
| const float(*orco)[3] = fdd->orco; | const float(*orco)[3] = fdd->orco; | ||||
| const MLoopUV *mloopuv = fdd->mloopuv; | const float2 *mloopuv = fdd->mloopuv; | ||||
| const int totface = fdd->totface; | const int totface = fdd->totface; | ||||
| const bool use_scale = fdd->params.use_scale; | const bool use_scale = fdd->params.use_scale; | ||||
| int a; | int a; | ||||
| float child_imat[4][4]; | float child_imat[4][4]; | ||||
| invert_m4_m4(inst_ob->world_to_object, inst_ob->object_to_world); | invert_m4_m4(inst_ob->world_to_object, inst_ob->object_to_world); | ||||
| /* Relative transform from parent to child space. */ | /* Relative transform from parent to child space. */ | ||||
| Show All 15 Lines | for (a = 0, mp = mpoly; a < totface; a++, mp++) { | ||||
| const float w = 1.0f / float(mp->totloop); | const float w = 1.0f / float(mp->totloop); | ||||
| if (orco) { | if (orco) { | ||||
| for (int j = 0; j < mp->totloop; j++) { | for (int j = 0; j < mp->totloop; j++) { | ||||
| madd_v3_v3fl(dob->orco, orco[loopstart[j].v], w); | madd_v3_v3fl(dob->orco, orco[loopstart[j].v], w); | ||||
| } | } | ||||
| } | } | ||||
| if (mloopuv) { | if (mloopuv) { | ||||
| for (int j = 0; j < mp->totloop; j++) { | for (int j = 0; j < mp->totloop; j++) { | ||||
| madd_v2_v2fl(dob->uv, mloopuv[mp->loopstart + j].uv, w); | madd_v2_v2fl(dob->uv, mloopuv[mp->loopstart + j], w); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void make_child_duplis_faces_from_editmesh(const DupliContext *ctx, | static void make_child_duplis_faces_from_editmesh(const DupliContext *ctx, | ||||
| void *userdata, | void *userdata, | ||||
| Object *inst_ob) | Object *inst_ob) | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | const Mesh *me_eval = mesh_data_from_duplicator_object( | ||||
| parent, &em, &vert_positions_deform, nullptr); | parent, &em, &vert_positions_deform, nullptr); | ||||
| if (em == nullptr && me_eval == nullptr) { | if (em == nullptr && me_eval == nullptr) { | ||||
| return; | return; | ||||
| } | } | ||||
| FaceDupliData_Params fdd_params = {ctx, (parent->transflag & OB_DUPLIFACES_SCALE) != 0}; | FaceDupliData_Params fdd_params = {ctx, (parent->transflag & OB_DUPLIFACES_SCALE) != 0}; | ||||
| if (em != nullptr) { | if (em != nullptr) { | ||||
| const int uv_idx = CustomData_get_render_layer(&em->bm->ldata, CD_MLOOPUV); | const int uv_idx = CustomData_get_render_layer(&em->bm->ldata, CD_PROP_FLOAT2); | ||||
| FaceDupliData_EditMesh fdd{}; | FaceDupliData_EditMesh fdd{}; | ||||
| fdd.params = fdd_params; | fdd.params = fdd_params; | ||||
| fdd.em = em; | fdd.em = em; | ||||
| fdd.vert_positions_deform = vert_positions_deform; | fdd.vert_positions_deform = vert_positions_deform; | ||||
| fdd.has_orco = (vert_positions_deform != nullptr); | fdd.has_orco = (vert_positions_deform != nullptr); | ||||
| fdd.has_uvs = (uv_idx != -1); | fdd.has_uvs = (uv_idx != -1); | ||||
| fdd.cd_loop_uv_offset = (uv_idx != -1) ? | fdd.cd_loop_uv_offset = (uv_idx != -1) ? | ||||
| CustomData_get_n_offset(&em->bm->ldata, CD_MLOOPUV, uv_idx) : | CustomData_get_n_offset(&em->bm->ldata, CD_PROP_FLOAT2, uv_idx) : | ||||
| -1; | -1; | ||||
| make_child_duplis(ctx, &fdd, make_child_duplis_faces_from_editmesh); | make_child_duplis(ctx, &fdd, make_child_duplis_faces_from_editmesh); | ||||
| } | } | ||||
| else { | else { | ||||
| const int uv_idx = CustomData_get_render_layer(&me_eval->ldata, CD_MLOOPUV); | const int uv_idx = CustomData_get_render_layer(&me_eval->ldata, CD_PROP_FLOAT2); | ||||
| FaceDupliData_Mesh fdd{}; | FaceDupliData_Mesh fdd{}; | ||||
| fdd.params = fdd_params; | fdd.params = fdd_params; | ||||
| fdd.totface = me_eval->totpoly; | fdd.totface = me_eval->totpoly; | ||||
| fdd.mpoly = me_eval->polys().data(); | fdd.mpoly = me_eval->polys().data(); | ||||
| fdd.mloop = me_eval->loops().data(); | fdd.mloop = me_eval->loops().data(); | ||||
| fdd.vert_positions = me_eval->vert_positions(); | fdd.vert_positions = me_eval->vert_positions(); | ||||
| fdd.mloopuv = (uv_idx != -1) ? (const MLoopUV *)CustomData_get_layer_n( | fdd.mloopuv = (uv_idx != -1) ? (const float2 *)CustomData_get_layer_n( | ||||
| &me_eval->ldata, CD_MLOOPUV, uv_idx) : | &me_eval->ldata, CD_PROP_FLOAT2, uv_idx) : | ||||
| nullptr; | nullptr; | ||||
| fdd.orco = (const float(*)[3])CustomData_get_layer(&me_eval->vdata, CD_ORCO); | fdd.orco = (const float(*)[3])CustomData_get_layer(&me_eval->vdata, CD_ORCO); | ||||
| make_child_duplis(ctx, &fdd, make_child_duplis_faces_from_mesh); | make_child_duplis(ctx, &fdd, make_child_duplis_faces_from_mesh); | ||||
| } | } | ||||
| } | } | ||||
| static const DupliGenerator gen_dupli_faces = { | static const DupliGenerator gen_dupli_faces = { | ||||
| ▲ Show 20 Lines • Show All 661 Lines • Show Last 20 Lines | |||||