Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/lattice.c
| Show All 26 Lines | |||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_bitmap.h" | #include "BLI_bitmap.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_task.h" | |||||
| #include "DNA_mesh_types.h" | #include "DNA_mesh_types.h" | ||||
| #include "DNA_meshdata_types.h" | #include "DNA_meshdata_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_lattice_types.h" | #include "DNA_lattice_types.h" | ||||
| #include "DNA_curve_types.h" | #include "DNA_curve_types.h" | ||||
| #include "DNA_key_types.h" | #include "DNA_key_types.h" | ||||
| ▲ Show 20 Lines • Show All 830 Lines • ▼ Show 20 Lines | void curve_deform_vector( | ||||
| } | } | ||||
| else { | else { | ||||
| unit_m3(mat); | unit_m3(mat); | ||||
| } | } | ||||
| mul_m4_v3(cd.objectspace, vec); | mul_m4_v3(cd.objectspace, vec); | ||||
| } | } | ||||
| typedef struct LatticeDeformUserdata { | |||||
| LatticeDeformData *lattice_deform_data; | |||||
| float (*vertexCos)[3]; | |||||
| MDeformVert *dvert; | |||||
| int defgrp_index; | |||||
| float fac; | |||||
| } LatticeDeformUserdata; | |||||
| static void lattice_deform_vert_task(void *__restrict userdata, | |||||
| const int index, | |||||
| const ParallelRangeTLS *__restrict UNUSED(tls)) | |||||
| { | |||||
| const LatticeDeformUserdata *data = userdata; | |||||
| if (data->dvert != NULL) { | |||||
| const float weight = defvert_find_weight(data->dvert + index, data->defgrp_index); | |||||
| if (weight > 0.0f) { | |||||
| calc_latt_deform(data->lattice_deform_data, data->vertexCos[index], weight * data->fac); | |||||
| } | |||||
| } | |||||
| else { | |||||
| calc_latt_deform(data->lattice_deform_data, data->vertexCos[index], data->fac); | |||||
| } | |||||
| } | |||||
| void lattice_deform_verts(Object *laOb, | void lattice_deform_verts(Object *laOb, | ||||
| Object *target, | Object *target, | ||||
| Mesh *mesh, | Mesh *mesh, | ||||
| float (*vertexCos)[3], | float (*vertexCos)[3], | ||||
| int numVerts, | int numVerts, | ||||
| const char *vgroup, | const char *vgroup, | ||||
| float fac) | float fac) | ||||
| { | { | ||||
| LatticeDeformData *lattice_deform_data; | LatticeDeformData *lattice_deform_data; | ||||
| MDeformVert *dvert = NULL; | MDeformVert *dvert = NULL; | ||||
| int defgrp_index = -1; | int defgrp_index = -1; | ||||
| int a; | |||||
| if (laOb->type != OB_LATTICE) { | if (laOb->type != OB_LATTICE) { | ||||
| return; | return; | ||||
| } | } | ||||
| lattice_deform_data = init_latt_deform(laOb, target); | lattice_deform_data = init_latt_deform(laOb, target); | ||||
| /* Check whether to use vertex groups (only possible if target is a Mesh or Lattice). | /* Check whether to use vertex groups (only possible if target is a Mesh or Lattice). | ||||
| Show All 10 Lines | if (defgrp_index != -1) { | ||||
| else if (target->type == OB_LATTICE) { | else if (target->type == OB_LATTICE) { | ||||
| dvert = ((Lattice *)target->data)->dvert; | dvert = ((Lattice *)target->data)->dvert; | ||||
| } | } | ||||
| else { | else { | ||||
| dvert = ((Mesh *)target->data)->dvert; | dvert = ((Mesh *)target->data)->dvert; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (dvert) { | |||||
| MDeformVert *dvert_iter; | LatticeDeformUserdata data = {.lattice_deform_data = lattice_deform_data, | ||||
| for (a = 0, dvert_iter = dvert; a < numVerts; a++, dvert_iter++) { | .vertexCos = vertexCos, | ||||
| const float weight = defvert_find_weight(dvert_iter, defgrp_index); | .dvert = dvert, | ||||
| if (weight > 0.0f) { | .defgrp_index = defgrp_index, | ||||
| calc_latt_deform(lattice_deform_data, vertexCos[a], weight * fac); | .fac = fac}; | ||||
| } | |||||
| } | ParallelRangeSettings settings; | ||||
| } | BLI_parallel_range_settings_defaults(&settings); | ||||
| else { | settings.min_iter_per_thread = 32; | ||||
| for (a = 0; a < numVerts; a++) { | BLI_task_parallel_range(0, numVerts, &data, lattice_deform_vert_task, &settings); | ||||
| calc_latt_deform(lattice_deform_data, vertexCos[a], fac); | |||||
| } | |||||
| } | |||||
| end_latt_deform(lattice_deform_data); | end_latt_deform(lattice_deform_data); | ||||
| } | } | ||||
| bool object_deform_mball(Object *ob, ListBase *dispbase) | bool object_deform_mball(Object *ob, ListBase *dispbase) | ||||
| { | { | ||||
| if (ob->parent && ob->parent->type == OB_LATTICE && ob->partype == PARSKEL) { | if (ob->parent && ob->parent->type == OB_LATTICE && ob->partype == PARSKEL) { | ||||
| DispList *dl; | DispList *dl; | ||||
| ▲ Show 20 Lines • Show All 400 Lines • Show Last 20 Lines | |||||