本文整理汇总了C++中defvert_find_weight函数的典型用法代码示例。如果您正苦于以下问题:C++ defvert_find_weight函数的具体用法?C++ defvert_find_weight怎么用?C++ defvert_find_weight使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了defvert_find_weight函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initSystem
static void initSystem(LaplacianDeformModifierData *lmd, Object *ob, DerivedMesh *dm,
float (*vertexCos)[3], int numVerts)
{
int i;
int defgrp_index;
int total_anchors;
float wpaint;
MDeformVert *dvert = NULL;
MDeformVert *dv = NULL;
LaplacianSystem *sys;
if (isValidVertexGroup(lmd, ob, dm)) {
int *index_anchors = MEM_mallocN(sizeof(int) * numVerts, __func__); /* over-alloc */
const MLoopTri *mlooptri;
const MLoop *mloop;
STACK_DECLARE(index_anchors);
STACK_INIT(index_anchors, numVerts);
modifier_get_vgroup(ob, dm, lmd->anchor_grp_name, &dvert, &defgrp_index);
BLI_assert(dvert != NULL);
dv = dvert;
for (i = 0; i < numVerts; i++) {
wpaint = defvert_find_weight(dv, defgrp_index);
dv++;
if (wpaint > 0.0f) {
STACK_PUSH(index_anchors, i);
}
}
DM_ensure_looptri(dm);
total_anchors = STACK_SIZE(index_anchors);
lmd->cache_system = initLaplacianSystem(numVerts, dm->getNumEdges(dm), dm->getNumLoopTri(dm),
total_anchors, lmd->anchor_grp_name, lmd->repeat);
sys = (LaplacianSystem *)lmd->cache_system;
memcpy(sys->index_anchors, index_anchors, sizeof(int) * total_anchors);
memcpy(sys->co, vertexCos, sizeof(float[3]) * numVerts);
MEM_freeN(index_anchors);
lmd->vertexco = MEM_mallocN(sizeof(float[3]) * numVerts, "ModDeformCoordinates");
memcpy(lmd->vertexco, vertexCos, sizeof(float[3]) * numVerts);
lmd->total_verts = numVerts;
createFaceRingMap(
dm->getNumVerts(dm), dm->getLoopTriArray(dm), dm->getNumLoopTri(dm),
dm->getLoopArray(dm), &sys->ringf_map, &sys->ringf_indices);
createVertRingMap(
dm->getNumVerts(dm), dm->getEdgeArray(dm), dm->getNumEdges(dm),
&sys->ringv_map, &sys->ringv_indices);
mlooptri = dm->getLoopTriArray(dm);
mloop = dm->getLoopArray(dm);
for (i = 0; i < sys->total_tris; i++) {
sys->tris[i][0] = mloop[mlooptri[i].tri[0]].v;
sys->tris[i][1] = mloop[mlooptri[i].tri[1]].v;
sys->tris[i][2] = mloop[mlooptri[i].tri[2]].v;
}
}
}
示例2: defvert_array_find_weight_safe
/* take care with this the rationale is:
* - if the object has no vertex group. act like vertex group isn't set and return 1.0,
* - if the vertex group exists but the 'defgroup' isn't found on this vertex, _still_ return 0.0
*
* This is a bit confusing, just saves some checks from the caller.
*/
float defvert_array_find_weight_safe(const struct MDeformVert *dvert, const int index, const int defgroup)
{
if (defgroup == -1 || dvert == NULL)
return 1.0f;
return defvert_find_weight(dvert + index, defgroup);
}
示例3: hook_co_apply
static void hook_co_apply(struct HookData_cb *hd, const int j)
{
float *co = hd->vertexCos[j];
float fac;
if (hd->use_falloff) {
float len_sq;
if (hd->use_uniform) {
float co_uniform[3];
mul_v3_m3v3(co_uniform, hd->mat_uniform, co);
len_sq = len_squared_v3v3(hd->cent, co_uniform);
}
else {
len_sq = len_squared_v3v3(hd->cent, co);
}
fac = hook_falloff(hd, len_sq);
}
else {
fac = hd->fac_orig;
}
if (fac) {
if (hd->dvert) {
fac *= defvert_find_weight(&hd->dvert[j], hd->defgrp_index);
}
if (fac) {
float co_tmp[3];
mul_v3_m4v3(co_tmp, hd->mat, co);
interp_v3_v3v3(co, co, co_tmp, fac);
}
}
}
示例4: uv_warp_compute
static void uv_warp_compute(void *userdata, const int i)
{
const UVWarpData *data = userdata;
const MPoly *mp = &data->mpoly[i];
const MLoop *ml = &data->mloop[mp->loopstart];
MLoopUV *mluv = &data->mloopuv[mp->loopstart];
const MDeformVert *dvert = data->dvert;
const int defgrp_index = data->defgrp_index;
float (*warp_mat)[4] = data->warp_mat;
const int axis_u = data->axis_u;
const int axis_v = data->axis_v;
int l;
if (dvert) {
for (l = 0; l < mp->totloop; l++, ml++, mluv++) {
float uv[2];
const float weight = defvert_find_weight(&dvert[ml->v], defgrp_index);
uv_warp_from_mat4_pair(uv, mluv->uv, warp_mat, axis_u, axis_v);
interp_v2_v2v2(mluv->uv, mluv->uv, uv, weight);
}
}
else {
for (l = 0; l < mp->totloop; l++, ml++, mluv++) {
uv_warp_from_mat4_pair(mluv->uv, mluv->uv, warp_mat, axis_u, axis_v);
}
}
}
示例5: lattice_deform_verts
void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm,
float (*vertexCos)[3], int numVerts, const char *vgroup, float fac)
{
LatticeDeformData *lattice_deform_data;
int a;
bool use_vgroups;
if (laOb->type != OB_LATTICE)
return;
lattice_deform_data = init_latt_deform(laOb, target);
/* check whether to use vertex groups (only possible if target is a Mesh)
* we want either a Mesh with no derived data, or derived data with
* deformverts
*/
if (target && target->type == OB_MESH) {
/* if there's derived data without deformverts, don't use vgroups */
if (dm) {
use_vgroups = (dm->getVertDataArray(dm, CD_MDEFORMVERT) != NULL);
}
else {
Mesh *me = target->data;
use_vgroups = (me->dvert != NULL);
}
}
else {
use_vgroups = false;
}
if (vgroup && vgroup[0] && use_vgroups) {
Mesh *me = target->data;
const int defgrp_index = defgroup_name_index(target, vgroup);
float weight;
if (defgrp_index >= 0 && (me->dvert || dm)) {
MDeformVert *dvert = me->dvert;
for (a = 0; a < numVerts; a++, dvert++) {
if (dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT);
weight = defvert_find_weight(dvert, defgrp_index);
if (weight > 0.0f)
calc_latt_deform(lattice_deform_data, vertexCos[a], weight * fac);
}
}
}
else {
for (a = 0; a < numVerts; a++) {
calc_latt_deform(lattice_deform_data, vertexCos[a], fac);
}
}
end_latt_deform(lattice_deform_data);
}
示例6: defvert_find_shared
/**
* \return The first group index shared by both deform verts
* or -1 if none are found.
*/
int defvert_find_shared(const MDeformVert *dvert_a, const MDeformVert *dvert_b)
{
if (dvert_a->totweight && dvert_b->totweight) {
MDeformWeight *dw = dvert_a->dw;
unsigned int i;
for (i = dvert_a->totweight; i != 0; i--, dw++) {
if (dw->weight > 0.0f && defvert_find_weight(dvert_b, dw->def_nr) > 0.0f) {
return dw->def_nr;
}
}
}
return -1;
}
示例7: BKE_defvert_extract_vgroup_to_vertweights
void BKE_defvert_extract_vgroup_to_vertweights(
MDeformVert *dvert, const int defgroup, const int num_verts, float *r_weights, const bool invert_vgroup)
{
if (dvert && defgroup != -1) {
int i = num_verts;
while (i--) {
const float w = defvert_find_weight(&dvert[i], defgroup);
r_weights[i] = invert_vgroup ? (1.0f - w) : w;
}
}
else {
copy_vn_fl(r_weights, num_verts, invert_vgroup ? 1.0f : 0.0f);
}
}
示例8: dm_get_weights
/* check individual weights for changes and cache values */
static void dm_get_weights(
MDeformVert *dvert, const int defgrp_index,
const unsigned int numVerts, const bool use_invert_vgroup,
float *smooth_weights)
{
unsigned int i;
for (i = 0; i < numVerts; i++, dvert++) {
const float w = defvert_find_weight(dvert, defgrp_index);
if (use_invert_vgroup == false) {
smooth_weights[i] = w;
}
else {
smooth_weights[i] = 1.0f - w;
}
}
}
示例9: get_def_index
void RAS_MeshObject::CheckWeightCache(Object* obj)
{
KeyBlock *kb;
int kbindex, defindex;
MDeformVert *dv= NULL;
int totvert, i;
float *weights;
if (!m_mesh->key)
return;
for (kbindex = 0, kb = (KeyBlock *)m_mesh->key->block.first; kb; kb = kb->next, kbindex++)
{
// first check the cases where the weight must be cleared
if (kb->vgroup[0] == 0 ||
m_mesh->dvert == NULL ||
(defindex = get_def_index(obj, kb->vgroup)) == -1) {
if (kb->weights) {
MEM_freeN(kb->weights);
kb->weights = NULL;
}
m_cacheWeightIndex[kbindex] = -1;
} else if (m_cacheWeightIndex[kbindex] != defindex) {
// a weight array is required but the cache is not matching
if (kb->weights) {
MEM_freeN(kb->weights);
kb->weights = NULL;
}
dv= m_mesh->dvert;
totvert= m_mesh->totvert;
weights= (float*)MEM_mallocN(totvert*sizeof(float), "weights");
for (i=0; i < totvert; i++, dv++) {
weights[i] = defvert_find_weight(dv, defindex);
}
kb->weights = weights;
m_cacheWeightIndex[kbindex] = defindex;
}
}
}
示例10: isSystemDifferent
static int isSystemDifferent(LaplacianDeformModifierData *lmd, Object *ob, DerivedMesh *dm, int numVerts)
{
int i;
int defgrp_index;
int total_anchors = 0;
float wpaint;
MDeformVert *dvert = NULL;
MDeformVert *dv = NULL;
LaplacianSystem *sys = (LaplacianSystem *)lmd->cache_system;
if (sys->total_verts != numVerts) {
return LAPDEFORM_SYSTEM_CHANGE_VERTEXES;
}
if (sys->total_edges != dm->getNumEdges(dm)) {
return LAPDEFORM_SYSTEM_CHANGE_EDGES;
}
if (!STREQ(lmd->anchor_grp_name, sys->anchor_grp_name)) {
return LAPDEFORM_SYSTEM_ONLY_CHANGE_GROUP;
}
modifier_get_vgroup(ob, dm, lmd->anchor_grp_name, &dvert, &defgrp_index);
if (!dvert) {
return LAPDEFORM_SYSTEM_CHANGE_NOT_VALID_GROUP;
}
dv = dvert;
for (i = 0; i < numVerts; i++) {
wpaint = defvert_find_weight(dv, defgrp_index);
dv++;
if (wpaint > 0.0f) {
total_anchors++;
}
}
if (sys->total_anchors != total_anchors) {
return LAPDEFORM_SYSTEM_ONLY_CHANGE_ANCHORS;
}
return LAPDEFORM_SYSTEM_NOT_CHANGE;
}
示例11: displaceModifier_do
/* dm must be a CDDerivedMesh */
static void displaceModifier_do(
DisplaceModifierData *dmd, Object *ob,
DerivedMesh *dm, float (*vertexCos)[3], int numVerts)
{
int i;
MVert *mvert;
MDeformVert *dvert;
int direction = dmd->direction;
int defgrp_index;
float (*tex_co)[3];
float weight = 1.0f; /* init value unused but some compilers may complain */
const float delta_fixed = 1.0f - dmd->midlevel; /* when no texture is used, we fallback to white */
float (*vert_clnors)[3] = NULL;
if (!dmd->texture && dmd->direction == MOD_DISP_DIR_RGB_XYZ) return;
if (dmd->strength == 0.0f) return;
mvert = CDDM_get_verts(dm);
modifier_get_vgroup(ob, dm, dmd->defgrp_name, &dvert, &defgrp_index);
if (dmd->texture) {
tex_co = MEM_callocN(sizeof(*tex_co) * numVerts,
"displaceModifier_do tex_co");
get_texture_coords((MappingInfoModifierData *)dmd, ob, dm, vertexCos, tex_co, numVerts);
modifier_init_texture(dmd->modifier.scene, dmd->texture);
}
else {
tex_co = NULL;
}
if (direction == MOD_DISP_DIR_CLNOR) {
CustomData *ldata = dm->getLoopDataLayout(dm);
if (CustomData_has_layer(ldata, CD_CUSTOMLOOPNORMAL)) {
float (*clnors)[3] = NULL;
if ((dm->dirty & DM_DIRTY_NORMALS) || !CustomData_has_layer(ldata, CD_NORMAL)) {
dm->calcLoopNormals(dm, true, (float)M_PI);
}
clnors = CustomData_get_layer(ldata, CD_NORMAL);
vert_clnors = MEM_mallocN(sizeof(*vert_clnors) * (size_t)numVerts, __func__);
BKE_mesh_normals_loop_to_vertex(numVerts, dm->getLoopArray(dm), dm->getNumLoops(dm),
(const float (*)[3])clnors, vert_clnors);
}
else {
direction = MOD_DISP_DIR_NOR;
}
}
for (i = 0; i < numVerts; i++) {
TexResult texres;
float strength = dmd->strength;
float delta;
if (dvert) {
weight = defvert_find_weight(dvert + i, defgrp_index);
if (weight == 0.0f) continue;
}
if (dmd->texture) {
texres.nor = NULL;
BKE_texture_get_value(dmd->modifier.scene, dmd->texture, tex_co[i], &texres, false);
delta = texres.tin - dmd->midlevel;
}
else {
delta = delta_fixed; /* (1.0f - dmd->midlevel) */ /* never changes */
}
if (dvert) strength *= weight;
delta *= strength;
CLAMP(delta, -10000, 10000);
switch (direction) {
case MOD_DISP_DIR_X:
vertexCos[i][0] += delta;
break;
case MOD_DISP_DIR_Y:
vertexCos[i][1] += delta;
break;
case MOD_DISP_DIR_Z:
vertexCos[i][2] += delta;
break;
case MOD_DISP_DIR_RGB_XYZ:
vertexCos[i][0] += (texres.tr - dmd->midlevel) * strength;
vertexCos[i][1] += (texres.tg - dmd->midlevel) * strength;
vertexCos[i][2] += (texres.tb - dmd->midlevel) * strength;
break;
case MOD_DISP_DIR_NOR:
vertexCos[i][0] += delta * (mvert[i].no[0] / 32767.0f);
vertexCos[i][1] += delta * (mvert[i].no[1] / 32767.0f);
vertexCos[i][2] += delta * (mvert[i].no[2] / 32767.0f);
break;
case MOD_DISP_DIR_CLNOR:
madd_v3_v3fl(vertexCos[i], vert_clnors[i], delta);
break;
}
//.........这里部分代码省略.........
示例12: UNUSED
//.........这里部分代码省略.........
if (mmd->flag & MOD_MASK_INV) {
/* if this vert is in the vgroup, don't include it in vertHash */
if (found) continue;
}
else {
/* if this vert isn't in the vgroup, don't include it in vertHash */
if (!found) continue;
}
/* add to ghash for verts (numVerts acts as counter for mapping) */
BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(i), SET_INT_IN_POINTER(numVerts));
numVerts++;
}
/* free temp hashes */
MEM_freeN(bone_select_array);
}
else { /* --- Using Nominated VertexGroup only --- */
int defgrp_index = defgroup_name_index(ob, mmd->vgroup);
/* get dverts */
if (defgrp_index != -1)
dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
/* if no vgroup (i.e. dverts) found, return the initial mesh */
if ((defgrp_index == -1) || (dvert == NULL))
return dm;
/* hashes for quickly providing a mapping from old to new - use key=oldindex, value=newindex */
vertHash = BLI_ghash_int_new("mask vert2 bh");
/* add vertices which exist in vertexgroup into ghash for filtering */
for (i = 0, dv = dvert; i < maxVerts; i++, dv++) {
const int weight_set = defvert_find_weight(dv, defgrp_index) != 0.0f;
/* check if include vert in vertHash */
if (mmd->flag & MOD_MASK_INV) {
/* if this vert is in the vgroup, don't include it in vertHash */
if (weight_set) continue;
}
else {
/* if this vert isn't in the vgroup, don't include it in vertHash */
if (!weight_set) continue;
}
/* add to ghash for verts (numVerts acts as counter for mapping) */
BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(i), SET_INT_IN_POINTER(numVerts));
numVerts++;
}
}
/* hashes for quickly providing a mapping from old to new - use key=oldindex, value=newindex */
edgeHash = BLI_ghash_int_new("mask ed2 gh");
polyHash = BLI_ghash_int_new("mask fa2 gh");
mpoly = dm->getPolyArray(dm);
mloop = dm->getLoopArray(dm);
loop_mapping = MEM_callocN(sizeof(int) * maxPolys, "mask loopmap"); /* overalloc, assume all polys are seen */
/* loop over edges and faces, and do the same thing to
* ensure that they only reference existing verts
*/
for (i = 0; i < maxEdges; i++) {
MEdge me;
dm->getEdge(dm, i, &me);
示例13: curve_deform_verts
void curve_deform_verts(Scene *scene, Object *cuOb, Object *target,
DerivedMesh *dm, float (*vertexCos)[3],
int numVerts, const char *vgroup, short defaxis)
{
Curve *cu;
int a, flag;
CurveDeform cd;
int use_vgroups;
const int is_neg_axis = (defaxis > 2);
if (cuOb->type != OB_CURVE)
return;
cu = cuOb->data;
flag = cu->flag;
cu->flag |= (CU_PATH | CU_FOLLOW); // needed for path & bevlist
init_curve_deform(cuOb, target, &cd);
/* dummy bounds, keep if CU_DEFORM_BOUNDS_OFF is set */
if (is_neg_axis == FALSE) {
cd.dmin[0] = cd.dmin[1] = cd.dmin[2] = 0.0f;
cd.dmax[0] = cd.dmax[1] = cd.dmax[2] = 1.0f;
}
else {
/* negative, these bounds give a good rest position */
cd.dmin[0] = cd.dmin[1] = cd.dmin[2] = -1.0f;
cd.dmax[0] = cd.dmax[1] = cd.dmax[2] = 0.0f;
}
/* check whether to use vertex groups (only possible if target is a Mesh)
* we want either a Mesh with no derived data, or derived data with
* deformverts
*/
if (target && target->type == OB_MESH) {
/* if there's derived data without deformverts, don't use vgroups */
if (dm) {
use_vgroups = (dm->getVertData(dm, 0, CD_MDEFORMVERT) != NULL);
}
else {
Mesh *me = target->data;
use_vgroups = (me->dvert != NULL);
}
}
else {
use_vgroups = FALSE;
}
if (vgroup && vgroup[0] && use_vgroups) {
Mesh *me = target->data;
int index = defgroup_name_index(target, vgroup);
if (index != -1 && (me->dvert || dm)) {
MDeformVert *dvert = me->dvert;
float vec[3];
float weight;
if (cu->flag & CU_DEFORM_BOUNDS_OFF) {
dvert = me->dvert;
for (a = 0; a < numVerts; a++, dvert++) {
if (dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT);
weight = defvert_find_weight(dvert, index);
if (weight > 0.0f) {
mul_m4_v3(cd.curvespace, vertexCos[a]);
copy_v3_v3(vec, vertexCos[a]);
calc_curve_deform(scene, cuOb, vec, defaxis, &cd, NULL);
interp_v3_v3v3(vertexCos[a], vertexCos[a], vec, weight);
mul_m4_v3(cd.objectspace, vertexCos[a]);
}
}
}
else {
/* set mesh min/max bounds */
INIT_MINMAX(cd.dmin, cd.dmax);
for (a = 0; a < numVerts; a++, dvert++) {
if (dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT);
if (defvert_find_weight(dvert, index) > 0.0f) {
mul_m4_v3(cd.curvespace, vertexCos[a]);
minmax_v3v3_v3(cd.dmin, cd.dmax, vertexCos[a]);
}
}
dvert = me->dvert;
for (a = 0; a < numVerts; a++, dvert++) {
if (dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT);
weight = defvert_find_weight(dvert, index);
if (weight > 0.0f) {
/* already in 'cd.curvespace', prev for loop */
copy_v3_v3(vec, vertexCos[a]);
calc_curve_deform(scene, cuOb, vec, defaxis, &cd, NULL);
interp_v3_v3v3(vertexCos[a], vertexCos[a], vec, weight);
mul_m4_v3(cd.objectspace, vertexCos[a]);
}
}
//.........这里部分代码省略.........
示例14: calc_latt_deform
void calc_latt_deform(Object *ob, float co[3], float weight)
{
Lattice *lt = ob->data;
float u, v, w, tu[4], tv[4], tw[4];
float vec[3];
int idx_w, idx_v, idx_u;
int ui, vi, wi, uu, vv, ww;
/* vgroup influence */
int defgroup_nr = -1;
float co_prev[3], weight_blend = 0.0f;
MDeformVert *dvert = BKE_lattice_deform_verts_get(ob);
if (lt->editlatt) lt = lt->editlatt->latt;
if (lt->latticedata == NULL) return;
if (lt->vgroup[0] && dvert) {
defgroup_nr = defgroup_name_index(ob, lt->vgroup);
copy_v3_v3(co_prev, co);
}
/* co is in local coords, treat with latmat */
mul_v3_m4v3(vec, lt->latmat, co);
/* u v w coords */
if (lt->pntsu > 1) {
u = (vec[0] - lt->fu) / lt->du;
ui = (int)floor(u);
u -= ui;
key_curve_position_weights(u, tu, lt->typeu);
}
else {
tu[0] = tu[2] = tu[3] = 0.0; tu[1] = 1.0;
ui = 0;
}
if (lt->pntsv > 1) {
v = (vec[1] - lt->fv) / lt->dv;
vi = (int)floor(v);
v -= vi;
key_curve_position_weights(v, tv, lt->typev);
}
else {
tv[0] = tv[2] = tv[3] = 0.0; tv[1] = 1.0;
vi = 0;
}
if (lt->pntsw > 1) {
w = (vec[2] - lt->fw) / lt->dw;
wi = (int)floor(w);
w -= wi;
key_curve_position_weights(w, tw, lt->typew);
}
else {
tw[0] = tw[2] = tw[3] = 0.0; tw[1] = 1.0;
wi = 0;
}
for (ww = wi - 1; ww <= wi + 2; ww++) {
w = tw[ww - wi + 1];
if (w != 0.0f) {
if (ww > 0) {
if (ww < lt->pntsw) idx_w = ww * lt->pntsu * lt->pntsv;
else idx_w = (lt->pntsw - 1) * lt->pntsu * lt->pntsv;
}
else idx_w = 0;
for (vv = vi - 1; vv <= vi + 2; vv++) {
v = w * tv[vv - vi + 1];
if (v != 0.0f) {
if (vv > 0) {
if (vv < lt->pntsv) idx_v = idx_w + vv * lt->pntsu;
else idx_v = idx_w + (lt->pntsv - 1) * lt->pntsu;
}
else idx_v = idx_w;
for (uu = ui - 1; uu <= ui + 2; uu++) {
u = weight * v * tu[uu - ui + 1];
if (u != 0.0f) {
if (uu > 0) {
if (uu < lt->pntsu) idx_u = idx_v + uu;
else idx_u = idx_v + (lt->pntsu - 1);
}
else idx_u = idx_v;
madd_v3_v3fl(co, <->latticedata[idx_u * 3], u);
if (defgroup_nr != -1)
weight_blend += (u * defvert_find_weight(dvert + idx_u, defgroup_nr));
}
}
}
}
}
}
//.........这里部分代码省略.........
示例15: curve_deform_verts
void curve_deform_verts(
Scene *scene, Object *cuOb, Object *target, DerivedMesh *dm, float (*vertexCos)[3],
int numVerts, const char *vgroup, short defaxis)
{
Curve *cu;
int a;
CurveDeform cd;
MDeformVert *dvert = NULL;
int defgrp_index = -1;
const bool is_neg_axis = (defaxis > 2);
if (cuOb->type != OB_CURVE)
return;
cu = cuOb->data;
init_curve_deform(cuOb, target, &cd);
/* dummy bounds, keep if CU_DEFORM_BOUNDS_OFF is set */
if (is_neg_axis == false) {
cd.dmin[0] = cd.dmin[1] = cd.dmin[2] = 0.0f;
cd.dmax[0] = cd.dmax[1] = cd.dmax[2] = 1.0f;
}
else {
/* negative, these bounds give a good rest position */
cd.dmin[0] = cd.dmin[1] = cd.dmin[2] = -1.0f;
cd.dmax[0] = cd.dmax[1] = cd.dmax[2] = 0.0f;
}
/* Check whether to use vertex groups (only possible if target is a Mesh or Lattice).
* We want either a Mesh/Lattice with no derived data, or derived data with deformverts.
*/
if (vgroup && vgroup[0] && ELEM(target->type, OB_MESH, OB_LATTICE)) {
defgrp_index = defgroup_name_index(target, vgroup);
if (defgrp_index != -1) {
/* if there's derived data without deformverts, don't use vgroups */
if (dm) {
dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
}
else if (target->type == OB_LATTICE) {
dvert = ((Lattice *)target->data)->dvert;
}
else {
dvert = ((Mesh *)target->data)->dvert;
}
}
}
if (dvert) {
MDeformVert *dvert_iter;
float vec[3];
if (cu->flag & CU_DEFORM_BOUNDS_OFF) {
for (a = 0, dvert_iter = dvert; a < numVerts; a++, dvert_iter++) {
const float weight = defvert_find_weight(dvert_iter, defgrp_index);
if (weight > 0.0f) {
mul_m4_v3(cd.curvespace, vertexCos[a]);
copy_v3_v3(vec, vertexCos[a]);
calc_curve_deform(scene, cuOb, vec, defaxis, &cd, NULL);
interp_v3_v3v3(vertexCos[a], vertexCos[a], vec, weight);
mul_m4_v3(cd.objectspace, vertexCos[a]);
}
}
}
else {
/* set mesh min/max bounds */
INIT_MINMAX(cd.dmin, cd.dmax);
for (a = 0, dvert_iter = dvert; a < numVerts; a++, dvert_iter++) {
if (defvert_find_weight(dvert_iter, defgrp_index) > 0.0f) {
mul_m4_v3(cd.curvespace, vertexCos[a]);
minmax_v3v3_v3(cd.dmin, cd.dmax, vertexCos[a]);
}
}
for (a = 0, dvert_iter = dvert; a < numVerts; a++, dvert_iter++) {
const float weight = defvert_find_weight(dvert_iter, defgrp_index);
if (weight > 0.0f) {
/* already in 'cd.curvespace', prev for loop */
copy_v3_v3(vec, vertexCos[a]);
calc_curve_deform(scene, cuOb, vec, defaxis, &cd, NULL);
interp_v3_v3v3(vertexCos[a], vertexCos[a], vec, weight);
mul_m4_v3(cd.objectspace, vertexCos[a]);
}
}
}
}
else {
if (cu->flag & CU_DEFORM_BOUNDS_OFF) {
for (a = 0; a < numVerts; a++) {
mul_m4_v3(cd.curvespace, vertexCos[a]);
calc_curve_deform(scene, cuOb, vertexCos[a], defaxis, &cd, NULL);
mul_m4_v3(cd.objectspace, vertexCos[a]);
}
}
else {
/* set mesh min max bounds */
//.........这里部分代码省略.........