Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/object_dupli.cc
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| bool use_scale; | bool use_scale; | ||||
| }; | }; | ||||
| 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 int *corner_verts; | ||||
| Span<float3> vert_positions; | Span<float3> vert_positions; | ||||
| const float (*orco)[3]; | const float (*orco)[3]; | ||||
| const float2 *mloopuv; | const float2 *mloopuv; | ||||
| }; | }; | ||||
| struct FaceDupliData_EditMesh { | struct FaceDupliData_EditMesh { | ||||
| FaceDupliData_Params params; | FaceDupliData_Params params; | ||||
| ▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | |||||
| Object *inst_ob, | Object *inst_ob, | ||||
| const float child_imat[4][4], | const float child_imat[4][4], | ||||
| const int index, | const int index, | ||||
| const bool use_scale, | const bool use_scale, | ||||
| const float scale_fac, | const float scale_fac, | ||||
| /* Mesh variables. */ | /* Mesh variables. */ | ||||
| const MPoly *mpoly, | const MPoly *mpoly, | ||||
| const MLoop *mloopstart, | const int *poly_verts, | ||||
| const Span<float3> vert_positions) | const Span<float3> vert_positions) | ||||
| { | { | ||||
| const int coords_len = mpoly->totloop; | const int coords_len = mpoly->totloop; | ||||
| Array<float3, 64> coords(coords_len); | Array<float3, 64> coords(coords_len); | ||||
| const MLoop *ml = mloopstart; | for (int i = 0; i < coords_len; i++) { | ||||
| for (int i = 0; i < coords_len; i++, ml++) { | coords[i] = vert_positions[poly_verts[i]]; | ||||
| coords[i] = vert_positions[ml->v]; | |||||
| } | } | ||||
| return face_dupli(ctx, inst_ob, child_imat, index, use_scale, scale_fac, coords); | return face_dupli(ctx, inst_ob, child_imat, index, use_scale, scale_fac, coords); | ||||
| } | } | ||||
| static DupliObject *face_dupli_from_editmesh(const DupliContext *ctx, | static DupliObject *face_dupli_from_editmesh(const DupliContext *ctx, | ||||
| Object *inst_ob, | Object *inst_ob, | ||||
| const float child_imat[4][4], | const float child_imat[4][4], | ||||
| Show All 26 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 int *corner_verts = fdd->corner_verts; | ||||
| const float(*orco)[3] = fdd->orco; | const float(*orco)[3] = fdd->orco; | ||||
| const float2 *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. */ | ||||
| mul_m4_m4m4(child_imat, inst_ob->world_to_object, ctx->object->object_to_world); | mul_m4_m4m4(child_imat, inst_ob->world_to_object, ctx->object->object_to_world); | ||||
| const float scale_fac = ctx->object->instance_faces_scale; | const float scale_fac = ctx->object->instance_faces_scale; | ||||
| for (a = 0, mp = mpoly; a < totface; a++, mp++) { | for (a = 0, mp = mpoly; a < totface; a++, mp++) { | ||||
| const MLoop *loopstart = mloop + mp->loopstart; | const int *poly_verts = &corner_verts[mp->loopstart]; | ||||
| DupliObject *dob = face_dupli_from_mesh(fdd->params.ctx, | DupliObject *dob = face_dupli_from_mesh(fdd->params.ctx, | ||||
| inst_ob, | inst_ob, | ||||
| child_imat, | child_imat, | ||||
| a, | a, | ||||
| use_scale, | use_scale, | ||||
| scale_fac, | scale_fac, | ||||
| mp, | mp, | ||||
| loopstart, | poly_verts, | ||||
| fdd->vert_positions); | fdd->vert_positions); | ||||
| 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[poly_verts[j]], 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], w); | madd_v2_v2fl(dob->uv, mloopuv[mp->loopstart + j], w); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | |||||
| 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_PROP_FLOAT2); | 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.corner_verts = me_eval->corner_verts().data(); | ||||
| fdd.vert_positions = me_eval->vert_positions(); | fdd.vert_positions = me_eval->vert_positions(); | ||||
| fdd.mloopuv = (uv_idx != -1) ? (const float2 *)CustomData_get_layer_n( | fdd.mloopuv = (uv_idx != -1) ? (const float2 *)CustomData_get_layer_n( | ||||
| &me_eval->ldata, CD_PROP_FLOAT2, 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); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||