Changeset View
Changeset View
Standalone View
Standalone View
source/blender/modifiers/intern/MOD_meshdeform.c
| Show First 20 Lines • Show All 347 Lines • ▼ Show 20 Lines | static void meshdeformModifier_do(ModifierData *md, | ||||
| int numVerts) | int numVerts) | ||||
| { | { | ||||
| MeshDeformModifierData *mmd = (MeshDeformModifierData *)md; | MeshDeformModifierData *mmd = (MeshDeformModifierData *)md; | ||||
| Object *ob = ctx->object; | Object *ob = ctx->object; | ||||
| Mesh *cagemesh; | Mesh *cagemesh; | ||||
| MDeformVert *dvert = NULL; | MDeformVert *dvert = NULL; | ||||
| float imat[4][4], cagemat[4][4], iobmat[4][4], icagemat[3][3], cmat[4][4]; | float imat[4][4], cagemat[4][4], iobmat[4][4], icagemat[3][3], cmat[4][4]; | ||||
| float co[3], (*dco)[3] = NULL, (*bindcagecos)[3]; | float(*dco)[3] = NULL, (*bindcagecos)[3]; | ||||
| int a, totvert, totcagevert, defgrp_index; | int a, totvert, totcagevert, defgrp_index; | ||||
| float(*cagecos)[3] = NULL; | float(*cagecos)[3] = NULL; | ||||
zeddb: `cagecos` is now unused, remove it. | |||||
| MeshdeformUserdata data; | MeshdeformUserdata data; | ||||
| static int recursive_bind_sentinel = 0; | static int recursive_bind_sentinel = 0; | ||||
| if (mmd->object == NULL || (mmd->bindcagecos == NULL && mmd->bindfunc == NULL)) { | if (mmd->object == NULL || (mmd->bindcagecos == NULL && mmd->bindfunc == NULL)) { | ||||
| return; | return; | ||||
| } | } | ||||
| Show All 34 Lines | if (!recursive_bind_sentinel) { | ||||
| recursive_bind_sentinel = 0; | recursive_bind_sentinel = 0; | ||||
| } | } | ||||
| goto finally; | goto finally; | ||||
| } | } | ||||
| /* verify we have compatible weights */ | /* verify we have compatible weights */ | ||||
| totvert = numVerts; | totvert = numVerts; | ||||
| totcagevert = cagemesh->totvert; | totcagevert = BKE_mesh_wrapper_vert_len(cagemesh); | ||||
| if (mmd->totvert != totvert) { | if (mmd->totvert != totvert) { | ||||
| BKE_modifier_set_error(md, "Vertices changed from %d to %d", mmd->totvert, totvert); | BKE_modifier_set_error(md, "Vertices changed from %d to %d", mmd->totvert, totvert); | ||||
| goto finally; | goto finally; | ||||
| } | } | ||||
| else if (mmd->totcagevert != totcagevert) { | else if (mmd->totcagevert != totcagevert) { | ||||
| BKE_modifier_set_error( | BKE_modifier_set_error( | ||||
| md, "Cage vertices changed from %d to %d", mmd->totcagevert, totcagevert); | md, "Cage vertices changed from %d to %d", mmd->totcagevert, totcagevert); | ||||
| goto finally; | goto finally; | ||||
| } | } | ||||
| else if (mmd->bindcagecos == NULL) { | else if (mmd->bindcagecos == NULL) { | ||||
| BKE_modifier_set_error(md, "Bind data missing"); | BKE_modifier_set_error(md, "Bind data missing"); | ||||
| goto finally; | goto finally; | ||||
| } | } | ||||
| /* setup deformation data */ | |||||
| cagecos = BKE_mesh_vert_coords_alloc(cagemesh, NULL); | |||||
| bindcagecos = (float(*)[3])mmd->bindcagecos; | |||||
| /* We allocate 1 element extra to make it possible to | /* We allocate 1 element extra to make it possible to | ||||
| * load the values to SSE registers, which are float4. | * load the values to SSE registers, which are float4. | ||||
| */ | */ | ||||
| dco = MEM_calloc_arrayN((totcagevert + 1), sizeof(*dco), "MDefDco"); | dco = MEM_calloc_arrayN((totcagevert + 1), sizeof(*dco), "MDefDco"); | ||||
| zero_v3(dco[totcagevert]); | zero_v3(dco[totcagevert]); | ||||
| for (a = 0; a < totcagevert; a++) { | |||||
| /* get cage vertex in world space with binding transform */ | /* setup deformation data */ | ||||
| copy_v3_v3(co, cagecos[a]); | BKE_mesh_wrapper_vert_coords_copy(cagemesh, dco, totcagevert); | ||||
| bindcagecos = (float(*)[3])mmd->bindcagecos; | |||||
| if (G.debug_value != 527) { | if (G.debug_value != 527) { | ||||
| mul_m4_v3(mmd->bindmat, co); | for (a = 0; a < totcagevert; a++) { | ||||
| /* get cage vertex in world space with binding transform */ | |||||
| float co[3]; | |||||
| mul_v3_m4v3(co, mmd->bindmat, dco[a]); | |||||
| /* compute difference with world space bind coord */ | /* compute difference with world space bind coord */ | ||||
| sub_v3_v3v3(dco[a], co, bindcagecos[a]); | sub_v3_v3v3(dco[a], co, bindcagecos[a]); | ||||
| } | } | ||||
| else { | |||||
| copy_v3_v3(dco[a], co); | |||||
| } | |||||
| } | } | ||||
| MOD_get_vgroup(ob, mesh, mmd->defgrp_name, &dvert, &defgrp_index); | MOD_get_vgroup(ob, mesh, mmd->defgrp_name, &dvert, &defgrp_index); | ||||
| /* Initialize data to be pass to the for body function. */ | /* Initialize data to be pass to the for body function. */ | ||||
| data.mmd = mmd; | data.mmd = mmd; | ||||
| data.dvert = dvert; | data.dvert = dvert; | ||||
| data.dco = dco; | data.dco = dco; | ||||
| data.defgrp_index = defgrp_index; | data.defgrp_index = defgrp_index; | ||||
| data.vertexCos = vertexCos; | data.vertexCos = vertexCos; | ||||
| data.cagemat = cagemat; | data.cagemat = cagemat; | ||||
| data.icagemat = icagemat; | data.icagemat = icagemat; | ||||
| /* Do deformation. */ | /* Do deformation. */ | ||||
| TaskParallelSettings settings; | TaskParallelSettings settings; | ||||
| BLI_parallel_range_settings_defaults(&settings); | BLI_parallel_range_settings_defaults(&settings); | ||||
| settings.min_iter_per_thread = 16; | settings.min_iter_per_thread = 16; | ||||
| BLI_task_parallel_range(0, totvert, &data, meshdeform_vert_task, &settings); | BLI_task_parallel_range(0, totvert, &data, meshdeform_vert_task, &settings); | ||||
| finally: | finally: | ||||
| MEM_SAFE_FREE(dco); | MEM_SAFE_FREE(dco); | ||||
| MEM_SAFE_FREE(cagecos); | |||||
| } | } | ||||
| static void deformVerts(ModifierData *md, | static void deformVerts(ModifierData *md, | ||||
| const ModifierEvalContext *ctx, | const ModifierEvalContext *ctx, | ||||
| Mesh *mesh, | Mesh *mesh, | ||||
| float (*vertexCos)[3], | float (*vertexCos)[3], | ||||
| int numVerts) | int numVerts) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 200 Lines • Show Last 20 Lines | |||||
cagecos is now unused, remove it.