本文整理汇总了C++中defvert_find_weight函数的典型用法代码示例。如果您正苦于以下问题:C++ defvert_find_weight函数的具体用法?C++ defvert_find_weight怎么用?C++ defvert_find_weight使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了defvert_find_weight函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
}
}
开发者ID:flair2005,项目名称:mechanical-blender,代码行数:60,代码来源:MOD_laplaciandeform.c
示例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);
}
开发者ID:Brachi,项目名称:blender,代码行数:13,代码来源:deform.c
示例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);
}
}
}
开发者ID:Andrewson3D,项目名称:blender-for-vray,代码行数:35,代码来源:MOD_hook.c
示例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);
}
}
}
开发者ID:wisaac407,项目名称:blender,代码行数:32,代码来源:MOD_uvwarp.c
示例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);
}
开发者ID:JasonWilkins,项目名称:blender-viewport_fx,代码行数:55,代码来源:lattice.c
示例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;
}
开发者ID:Brachi,项目名称:blender,代码行数:19,代码来源:deform.c
示例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);
}
}
开发者ID:Brachi,项目名称:blender,代码行数:15,代码来源:deform.c
示例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;
}
}
}
开发者ID:DarkDefender,项目名称:blender-npr-tess2,代码行数:19,代码来源:MOD_correctivesmooth.c
示例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;
}
}
}
开发者ID:244xiao,项目名称:blender,代码行数:43,代码来源:RAS_MeshObject.cpp
示例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;
}
开发者ID:YasirArafath,项目名称:blender-git,代码行数:37,代码来源:MOD_laplaciandeform.c
示例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;
}
//.........这里部分代码省略.........
开发者ID:DarkDefender,项目名称:blender-npr-tess2,代码行数:101,代码来源:MOD_displace.c
示例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);
开发者ID:danielmarg,项目名称:blender-main,代码行数:67,代码来源:MOD_mask.c
示例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]);
}
}
//.........这里部分代码省略.........
开发者ID:vanangamudi,项目名称:blender-main,代码行数:101,代码来源:lattice.c
示例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));
}
}
}
}
}
}
//.........这里部分代码省略.........
开发者ID:vanangamudi,项目名称:blender-main,代码行数:101,代码来源:lattice.c
示例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 */
//.........这里部分代码省略.........
开发者ID:JasonWilkins,项目名称:blender-viewport_fx,代码行数:101,代码来源:lattice.c
示例16: laplaciansmoothModifier_do
static void laplaciansmoothModifier_do(
LaplacianSmoothModifierData *smd, Object *ob, DerivedMesh *dm,
float (*vertexCos)[3], int numVerts)
{
LaplacianSystem *sys;
MDeformVert *dvert = NULL;
MDeformVert *dv = NULL;
float w, wpaint;
int i, iter;
int defgrp_index;
DM_ensure_tessface(dm);
sys = init_laplacian_system(dm->getNumEdges(dm), dm->getNumTessFaces(dm), numVerts);
if (!sys) {
return;
}
sys->mfaces = dm->getTessFaceArray(dm);
sys->medges = dm->getEdgeArray(dm);
sys->vertexCos = vertexCos;
sys->min_area = 0.00001f;
modifier_get_vgroup(ob, dm, smd->defgrp_name, &dvert, &defgrp_index);
sys->vert_centroid[0] = 0.0f;
sys->vert_centroid[1] = 0.0f;
sys->vert_centroid[2] = 0.0f;
memset_laplacian_system(sys, 0);
#ifdef OPENNL_THREADING_HACK
modifier_opennl_lock();
#endif
nlNewContext();
sys->context = nlGetCurrent();
nlSolverParameteri(NL_NB_VARIABLES, numVerts);
nlSolverParameteri(NL_LEAST_SQUARES, NL_TRUE);
nlSolverParameteri(NL_NB_ROWS, numVerts);
nlSolverParameteri(NL_NB_RIGHT_HAND_SIDES, 3);
init_laplacian_matrix(sys);
for (iter = 0; iter < smd->repeat; iter++) {
nlBegin(NL_SYSTEM);
for (i = 0; i < numVerts; i++) {
nlSetVariable(0, i, vertexCos[i][0]);
nlSetVariable(1, i, vertexCos[i][1]);
nlSetVariable(2, i, vertexCos[i][2]);
if (iter == 0) {
add_v3_v3(sys->vert_centroid, vertexCos[i]);
}
}
if (iter == 0 && numVerts > 0) {
mul_v3_fl(sys->vert_centroid, 1.0f / (float)numVerts);
}
nlBegin(NL_MATRIX);
dv = dvert;
for (i = 0; i < numVerts; i++) {
nlRightHandSideSet(0, i, vertexCos[i][0]);
nlRightHandSideSet(1, i, vertexCos[i][1]);
nlRightHandSideSet(2, i, vertexCos[i][2]);
if (iter == 0) {
if (dv) {
wpaint = defvert_find_weight(dv, defgrp_index);
dv++;
}
else {
wpaint = 1.0f;
}
if (sys->zerola[i] == 0) {
if (smd->flag & MOD_LAPLACIANSMOOTH_NORMALIZED) {
w = sys->vweights[i];
sys->vweights[i] = (w == 0.0f) ? 0.0f : -fabsf(smd->lambda) * wpaint / w;
w = sys->vlengths[i];
sys->vlengths[i] = (w == 0.0f) ? 0.0f : -fabsf(smd->lambda_border) * wpaint * 2.0f / w;
if (sys->numNeEd[i] == sys->numNeFa[i]) {
nlMatrixAdd(i, i, 1.0f + fabsf(smd->lambda) * wpaint);
}
else {
nlMatrixAdd(i, i, 1.0f + fabsf(smd->lambda_border) * wpaint * 2.0f);
}
}
else {
w = sys->vweights[i] * sys->ring_areas[i];
sys->vweights[i] = (w == 0.0f) ? 0.0f : -fabsf(smd->lambda) * wpaint / (4.0f * w);
w = sys->vlengths[i];
sys->vlengths[i] = (w == 0.0f) ? 0.0f : -fabsf(smd->lambda_border) * wpaint * 2.0f / w;
if (sys->numNeEd[i] == sys->numNeFa[i]) {
nlMatrixAdd(i, i, 1.0f + fabsf(smd->lambda) * wpaint / (4.0f * sys->ring_areas[i]));
}
else {
nlMatrixAdd(i, i, 1.0f + fabsf(smd->lambda_border) * wpaint * 2.0f);
}
}
}
else {
nlMatrixAdd(i, i, 1.0f);
//.........这里部分代码省略.........
开发者ID:Walid-Shouman,项目名称:Blender,代码行数:101,代码来源:MOD_laplaciansmooth.c
示例17: smoothModifier_do
static void smoothModifier_do(
SmoothModifierData *smd, Object *ob, DerivedMesh *dm,
float (*vertexCos)[3], int numVerts)
{
MDeformVert *dvert = NULL;
MEdge *medges = NULL;
int i, j, numDMEdges, defgrp_index;
unsigned char *uctmp;
float *ftmp, fac, facm;
ftmp = (float *)MEM_callocN(3 * sizeof(float) * numVerts,
"smoothmodifier_f");
if (!ftmp) return;
uctmp = (unsigned char *)MEM_callocN(sizeof(unsigned char) * numVerts,
"smoothmodifier_uc");
if (!uctmp) {
if (ftmp) MEM_freeN(ftmp);
return;
}
fac = smd->fac;
facm = 1 - fac;
if (dm->getNumVerts(dm) == numVerts) {
medges = dm->getEdgeArray(dm);
numDMEdges = dm->getNumEdges(dm);
}
else {
medges = NULL;
numDMEdges = 0;
}
modifier_get_vgroup(ob, dm, smd->defgrp_name, &dvert, &defgrp_index);
/* NOTICE: this can be optimized a little bit by moving the
* if (dvert) out of the loop, if needed */
for (j = 0; j < smd->repeat; j++) {
for (i = 0; i < numDMEdges; i++) {
float fvec[3];
float *v1, *v2;
unsigned int idx1, idx2;
idx1 = medges[i].v1;
idx2 = medges[i].v2;
v1 = vertexCos[idx1];
v2 = vertexCos[idx2];
mid_v3_v3v3(fvec, v1, v2);
v1 = &ftmp[idx1 * 3];
v2 = &ftmp[idx2 * 3];
if (uctmp[idx1] < 255) {
uctmp[idx1]++;
add_v3_v3(v1, fvec);
}
if (uctmp[idx2] < 255) {
uctmp[idx2]++;
add_v3_v3(v2, fvec);
}
}
if (dvert) {
MDeformVert *dv = dvert;
for (i = 0; i < numVerts; i++, dv++) {
float f, fm, facw, *fp, *v;
short flag = smd->flag;
v = vertexCos[i];
fp = &ftmp[i * 3];
f = defvert_find_weight(dv, defgrp_index);
if (f <= 0.0f) continue;
f *= fac;
fm = 1.0f - f;
/* fp is the sum of uctmp[i] verts, so must be averaged */
facw = 0.0f;
if (uctmp[i])
facw = f / (float)uctmp[i];
if (flag & MOD_SMOOTH_X)
v[0] = fm * v[0] + facw * fp[0];
if (flag & MOD_SMOOTH_Y)
v[1] = fm * v[1] + facw * fp[1];
if (flag & MOD_SMOOTH_Z)
v[2] = fm * v[2] + facw * fp[2];
}
}
else { /* no vertex group */
for (i = 0; i < numVerts; i++) {
float facw, *fp, *v;
short flag = smd->flag;
v = vertexCos[i];
fp = &ftmp[i * 3];
//.........这里部分代码省略.........
开发者ID:244xiao,项目名称:blender,代码行数:101,代码来源:MOD_smooth.c
示例18: cuboid_do
//.........这里部分代码省略.........
bb[0][0] = bb[2][0] = bb[4][0] = bb[6][0] = min[0];
bb[1][0] = bb[3][0] = bb[5][0] = bb[7][0] = max[0];
bb[0][1] = bb[1][1] = bb[4][1] = bb[5][1] = min[1];
bb[2][1] = bb[3][1] = bb[6][1] = bb[7][1] = max[1];
bb[0][2] = bb[1][2] = bb[2][2] = bb[3][2] = min[2];
bb[4][2] = bb[5][2] = bb[6][2] = bb[7][2] = max[2];
/* ready to apply the effect, one vertex at a time */
for (i = 0; i < numVerts; i++) {
int octant, coord;
float d[3], dmax, apex[3], fbb;
float tmp_co[3];
copy_v3_v3(tmp_co, vertexCos[i]);
if (ctrl_ob) {
if (flag & MOD_CAST_USE_OB_TRANSFORM) {
mul_m4_v3(mat, tmp_co);
}
else {
sub_v3_v3(tmp_co, center);
}
}
if (has_radius) {
if (fabsf(tmp_co[0]) > cmd->radius ||
fabsf(tmp_co[1]) > cmd->radius ||
fabsf(tmp_co[2]) > cmd->radius)
{
continue;
}
}
if (dvert) {
const float weight = defvert_find_weight(&dvert[i], defgrp_index);
if (weight == 0.0f) {
continue;
}
fac = fac_orig * weight;
facm = 1.0f - fac;
}
/* The algo used to project the vertices to their
* bounding box (bb) is pretty simple:
* for each vertex v:
* 1) find in which octant v is in;
* 2) find which outer "wall" of that octant is closer to v;
* 3) calculate factor (var fbb) to project v to that wall;
* 4) project. */
/* find in which octant this vertex is in */
octant = 0;
if (tmp_co[0] > 0.0f) octant += 1;
if (tmp_co[1] > 0.0f) octant += 2;
if (tmp_co[2] > 0.0f) octant += 4;
/* apex is the bb's vertex at the chosen octant */
copy_v3_v3(apex, bb[octant]);
/* find which bb plane is closest to this vertex ... */
d[0] = tmp_co[0] / apex[0];
d[1] = tmp_co[1] / apex[1];
d[2] = tmp_co[2] / apex[2];
/* ... (the closest has the higher (closer to 1) d value) */
dmax = d[0];
开发者ID:mgschwan,项目名称:blensor,代码行数:67,代码来源:MOD_cast.c
示例19: sphere_do
static void sphere_do(
CastModifierData *cmd, Object *ob, DerivedMesh *dm,
float (*vertexCos)[3], int numVerts)
{
MDeformVert *dvert = NULL;
Object *ctrl_ob = NULL;
int i, defgrp_index;
bool has_radius = false;
short flag, type;
float len = 0.0f;
float fac = cmd->fac;
float facm = 1.0f - fac;
const float fac_orig = fac;
float vec[3], center[3] = {0.0f, 0.0f, 0.0f};
float mat[4][4], imat[4][4];
flag = cmd->flag;
type = cmd->type; /* projection type: sphere or cylinder */
if (type == MOD_CAST_TYPE_CYLINDER)
flag &= ~MOD_CAST_Z;
ctrl_ob = cmd->object;
/* spherify's center is {0, 0, 0} (the ob's own center in its local
* space), by default, but if the user defined a control object,
* we use its location, transformed to ob's local space */
if (ctrl_ob) {
if (flag & MOD_CAST_USE_OB_TRANSFORM) {
invert_m4_m4(imat, ctrl_ob->obmat);
mul_m4_m4m4(mat, imat, ob->obmat);
invert_m4_m4(imat, mat);
}
invert_m4_m4(ob->imat, ob->obmat);
mul_v3_m4v3(center, ob->imat, ctrl_ob->obmat[3]);
}
/* now we check which options the user wants */
/* 1) (flag was checked in the "if (ctrl_ob)" block above) */
/* 2) cmd->radius > 0.0f: only the vertices within this radius from
* the center of the effect should be deformed */
if (cmd->radius > FLT_EPSILON) has_radius = 1;
/* 3) if we were given a vertex group name,
* only those vertices should be affected */
modifier_get_vgroup(ob, dm, cmd->defgrp_name, &dvert, &defgrp_index);
if (flag & MOD_CAST_SIZE_FROM_RADIUS) {
len = cmd->radius;
}
else {
len = cmd->size;
}
if (len <= 0) {
for (i = 0; i < numVerts; i++) {
len += len_v3v3(center, vertexCos[i]);
}
len /= numVerts;
if (len == 0.0f) len = 10.0f;
}
for (i = 0; i < numVerts; i++) {
float tmp_co[3];
copy_v3_v3(tmp_co, vertexCos[i]);
if (ctrl_ob) {
if (flag & MOD_CAST_USE_OB_TRANSFORM) {
mul_m4_v3(mat, tmp_co);
}
else {
sub_v3_v3(tmp_co, center);
}
}
copy_v3_v3(vec, tmp_co);
if (type == MOD_CAST_TYPE_CYLINDER)
vec[2] = 0.0f;
if (has_radius) {
if (len_v3(vec) > cmd->radius) continue;
}
if (dvert) {
const float weight = defvert_find_weight(&dvert[i], defgrp_index);
if (weight == 0.0f) {
continue;
}
fac = fac_orig * weight;
facm = 1.0f - fac;
}
normalize_v3(vec);
//.........这里部分代码省略.........
开发者ID:mgschwan,项目名称:blensor,代码行数:101,代码来源:MOD_cast.c
示例20: createFacepa
static void createFacepa(ExplodeModifierData *emd,
ParticleSystemModifierData *psmd,
DerivedMesh *dm)
{
ParticleSystem *psys = psmd->psys;
MFace *fa = NULL, *mface = NULL;
MVert *mvert = NULL;
ParticleData *pa;
KDTree *tree;
RNG *rng;
float center[3], co[3];
int *facepa = NULL, *vertpa = NULL, totvert = 0, totface = 0, totpart = 0;
int i, p, v1, v2, v3, v4 = 0;
mvert = dm->getVertArray(dm);
mface = dm->getTessFaceArray(dm);
totface = dm->getNumTessFaces(dm);
totvert = dm->getNumVerts(dm);
totpart = psmd->psys->totpart;
rng = BLI_rng_new_srandom(psys->seed);
if (emd->facepa)
MEM_freeN(emd->facepa);
facepa = emd->facepa = MEM_callocN(sizeof(int) * totface, "explode_facepa");
vertpa = MEM_callocN(sizeof(int) * totvert, "explode_vertpa");
/* initialize all faces & verts to no particle */
for (i = 0; i < totface; i++)
facepa[i] = totpart;
for (i = 0; i < totvert; i++)
vertpa[i] = totpart;
/* set protected verts */
if (emd->vgroup) {
MDeformVert *dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
if (dvert) {
const int defgrp_index = emd->vgroup - 1;
for (i = 0; i < totvert; i++, dvert++) {
float val = BLI_rng_get_float(rng);
val = (1.0f - emd->protect) * val + emd->protect * 0.5f;
if (val < defvert_find_weight(dvert, defgrp_index))
vertpa[i] = -1;
}
}
}
/* make tree of emitter locations */
tree = BLI_kdtree_new(totpart);
for (p = 0, pa = psys->particles; p < totpart; p++, pa++) {
psys_particle_on_emitter(psmd, psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co, NULL, NULL, NULL, NULL, NULL);
BLI_kdtree_insert(tree, p, co);
}
BLI_kdtree_balance(tree);
/* set face-particle-indexes to nearest particle to face center */
for (i = 0, fa = mface; i < totface; i++, fa++) {
add_v3_v3v3(center, mvert[fa->v1].co, mvert[fa->v2].co);
add_v3_v3(center, mvert[fa->v3].co);
if (fa->v4) {
add_v3_v3(center, mvert[fa->v4].co);
mul_v3_fl(center, 0.25);
}
else
mul_v3_fl(center, 1.0f / 3.0f);
p = BLI_kdtree_find_nearest(tree, center, NULL);
v1 = vertpa[fa->v1];
v2 = vertpa[fa->v2];
v3 = vertpa[fa->v3];
if (fa->v4)
v4 = vertpa[fa->v4];
if (v1 >= 0 && v2 >= 0 && v3 >= 0 && (fa->v4 == 0 || v4 >= 0))
facepa[i] = p;
if (v1 >= 0) vertpa[fa->v1] = p;
if (v2 >= 0) vertpa[fa->v2] = p;
if (v3 >= 0) vertpa[fa->v3] = p;
if (fa->v4 && v4 >= 0) vertpa[fa->v4] = p;
}
if (vertpa) MEM_freeN(vertpa);
BLI_kdtree_free(tree);
BLI_rng_free(rng);
}
开发者ID:flair2005,项目名称:mechanical-blender,代码行数:91,代码来源:MOD_explode.c
注:本文中的defvert_find_weight函数示例由纯净天空整理自Github/MSDocs等源码及文档 |
请发表评论