本文整理汇总了C++中zero_v3函数的典型用法代码示例。如果您正苦于以下问题:C++ zero_v3函数的具体用法?C++ zero_v3怎么用?C++ zero_v3使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zero_v3函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: apply_objects_internal
//.........这里部分代码省略.........
ED_armature_apply_transform(ob, mat);
}
else if (ob->type == OB_LATTICE) {
Lattice *lt = ob->data;
BKE_lattice_transform(lt, mat, true);
}
else if (ob->type == OB_MBALL) {
MetaBall *mb = ob->data;
BKE_mball_transform(mb, mat);
}
else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
Curve *cu = ob->data;
scale = mat3_to_scale(rsmat);
BKE_curve_transform_ex(cu, mat, true, scale);
}
else if (ob->type == OB_FONT) {
Curve *cu = ob->data;
int i;
scale = mat3_to_scale(rsmat);
for (i = 0; i < cu->totbox; i++) {
TextBox *tb = &cu->tb[i];
tb->x *= scale;
tb->y *= scale;
tb->w *= scale;
tb->h *= scale;
}
cu->fsize *= scale;
}
else if (ob->type == OB_CAMERA) {
MovieClip *clip = BKE_object_movieclip_get(scene, ob, false);
/* applying scale on camera actually scales clip's reconstruction.
* of there's clip assigned to camera nothing to do actually.
*/
if (!clip)
continue;
if (apply_scale)
BKE_tracking_reconstruction_scale(&clip->tracking, ob->size);
}
else if (ob->type == OB_EMPTY) {
/* It's possible for empties too, even though they don't
* really have obdata, since we can simply apply the maximum
* scaling to the empty's drawsize.
*
* Core Assumptions:
* 1) Most scaled empties have uniform scaling
* (i.e. for visibility reasons), AND/OR
* 2) Preserving non-uniform scaling is not that important,
* and is something that many users would be willing to
* sacrifice for having an easy way to do this.
*/
if ((apply_loc == false) &&
(apply_rot == false) &&
(apply_scale == true))
{
float max_scale = max_fff(fabsf(ob->size[0]), fabsf(ob->size[1]), fabsf(ob->size[2]));
ob->empty_drawsize *= max_scale;
}
}
else {
continue;
}
if (apply_loc)
zero_v3(ob->loc);
if (apply_scale)
ob->size[0] = ob->size[1] = ob->size[2] = 1.0f;
if (apply_rot) {
zero_v3(ob->rot);
unit_qt(ob->quat);
unit_axis_angle(ob->rotAxis, &ob->rotAngle);
}
BKE_object_where_is_calc(scene, ob);
if (ob->type == OB_ARMATURE) {
BKE_pose_where_is(scene, ob); /* needed for bone parents */
}
ignore_parent_tx(bmain, scene, ob);
DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA);
changed = true;
}
CTX_DATA_END;
if (!changed) {
BKE_report(reports, RPT_WARNING, "Objects have no data to transform");
return OPERATOR_CANCELLED;
}
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
return OPERATOR_FINISHED;
}
示例2: make_duplis_font
static void make_duplis_font(const DupliContext *ctx)
{
Object *par = ctx->object;
GHash *family_gh;
Object *ob;
Curve *cu;
struct CharTrans *ct, *chartransdata = NULL;
float vec[3], obmat[4][4], pmat[4][4], fsize, xof, yof;
int text_len, a;
size_t family_len;
const wchar_t *text = NULL;
bool text_free = false;
/* font dupliverts not supported inside groups */
if (ctx->group)
return;
copy_m4_m4(pmat, par->obmat);
/* in par the family name is stored, use this to find the other objects */
BKE_vfont_to_curve_ex(G.main, par, FO_DUPLI, NULL,
&text, &text_len, &text_free, &chartransdata);
if (text == NULL || chartransdata == NULL) {
return;
}
cu = par->data;
fsize = cu->fsize;
xof = cu->xof;
yof = cu->yof;
ct = chartransdata;
/* cache result */
family_len = strlen(cu->family);
family_gh = BLI_ghash_int_new_ex(__func__, 256);
/* advance matching BLI_strncpy_wchar_from_utf8 */
for (a = 0; a < text_len; a++, ct++) {
ob = find_family_object(cu->family, family_len, (unsigned int)text[a], family_gh);
if (ob) {
vec[0] = fsize * (ct->xof - xof);
vec[1] = fsize * (ct->yof - yof);
vec[2] = 0.0;
mul_m4_v3(pmat, vec);
copy_m4_m4(obmat, par->obmat);
if (UNLIKELY(ct->rot != 0.0f)) {
float rmat[4][4];
zero_v3(obmat[3]);
unit_m4(rmat);
rotate_m4(rmat, 'Z', -ct->rot);
mul_m4_m4m4(obmat, obmat, rmat);
}
copy_v3_v3(obmat[3], vec);
make_dupli(ctx, ob, obmat, a, false, false);
}
}
if (text_free) {
MEM_freeN((void *)text);
}
BLI_ghash_free(family_gh, NULL, NULL);
MEM_freeN(chartransdata);
}
示例3: cloth_calc_spring_force
BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s, float time)
{
Cloth *cloth = clmd->clothObject;
ClothSimSettings *parms = clmd->sim_parms;
Implicit_Data *data = cloth->implicit;
ClothVertex *verts = cloth->verts;
bool no_compress = parms->flags & CLOTH_SIMSETTINGS_FLAG_NO_SPRING_COMPRESS;
zero_v3(s->f);
zero_m3(s->dfdx);
zero_m3(s->dfdv);
s->flags &= ~CLOTH_SPRING_FLAG_NEEDED;
// calculate force of structural + shear springs
if ((s->type & CLOTH_SPRING_TYPE_STRUCTURAL) || (s->type & CLOTH_SPRING_TYPE_SHEAR) || (s->type & CLOTH_SPRING_TYPE_SEWING) ) {
#ifdef CLOTH_FORCE_SPRING_STRUCTURAL
float k, scaling;
s->flags |= CLOTH_SPRING_FLAG_NEEDED;
scaling = parms->structural + s->stiffness * fabsf(parms->max_struct - parms->structural);
k = scaling / (parms->avg_spring_len + FLT_EPSILON);
if (s->type & CLOTH_SPRING_TYPE_SEWING) {
// TODO: verify, half verified (couldn't see error)
// sewing springs usually have a large distance at first so clamp the force so we don't get tunnelling through colission objects
BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, s->restlen, k, parms->Cdis, no_compress, parms->max_sewing, s->f, s->dfdx, s->dfdv);
}
else {
BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, s->restlen, k, parms->Cdis, no_compress, 0.0f, s->f, s->dfdx, s->dfdv);
}
#endif
}
else if (s->type & CLOTH_SPRING_TYPE_GOAL) {
#ifdef CLOTH_FORCE_SPRING_GOAL
float goal_x[3], goal_v[3];
float k, scaling;
s->flags |= CLOTH_SPRING_FLAG_NEEDED;
// current_position = xold + t * (newposition - xold)
/* divide by time_scale to prevent goal vertices' delta locations from being multiplied */
interp_v3_v3v3(goal_x, verts[s->ij].xold, verts[s->ij].xconst, time / parms->time_scale);
sub_v3_v3v3(goal_v, verts[s->ij].xconst, verts[s->ij].xold); // distance covered over dt==1
scaling = parms->goalspring + s->stiffness * fabsf(parms->max_struct - parms->goalspring);
k = verts[s->ij].goal * scaling / (parms->avg_spring_len + FLT_EPSILON);
BPH_mass_spring_force_spring_goal(data, s->ij, goal_x, goal_v, k, parms->goalfrict * 0.01f, s->f, s->dfdx, s->dfdv);
#endif
}
else if (s->type & CLOTH_SPRING_TYPE_BENDING) { /* calculate force of bending springs */
#ifdef CLOTH_FORCE_SPRING_BEND
float kb, cb, scaling;
s->flags |= CLOTH_SPRING_FLAG_NEEDED;
scaling = parms->bending + s->stiffness * fabsf(parms->max_bend - parms->bending);
kb = scaling / (20.0f * (parms->avg_spring_len + FLT_EPSILON));
// Fix for [#45084] for cloth stiffness must have cb proportional to kb
cb = kb * parms->bending_damping;
BPH_mass_spring_force_spring_bending(data, s->ij, s->kl, s->restlen, kb, cb, s->f, s->dfdx, s->dfdv);
#endif
}
else if (s->type & CLOTH_SPRING_TYPE_BENDING_ANG) {
#ifdef CLOTH_FORCE_SPRING_BEND
float kb, cb, scaling;
s->flags |= CLOTH_SPRING_FLAG_NEEDED;
/* XXX WARNING: angular bending springs for hair apply stiffness factor as an overall factor, unlike cloth springs!
* this is crap, but needed due to cloth/hair mixing ...
* max_bend factor is not even used for hair, so ...
*/
scaling = s->stiffness * parms->bending;
kb = scaling / (20.0f * (parms->avg_spring_len + FLT_EPSILON));
// Fix for [#45084] for cloth stiffness must have cb proportional to kb
cb = kb * parms->bending_damping;
/* XXX assuming same restlen for ij and jk segments here, this can be done correctly for hair later */
BPH_mass_spring_force_spring_bending_angular(data, s->ij, s->kl, s->mn, s->target, kb, cb);
#if 0
{
float x_kl[3], x_mn[3], v[3], d[3];
BPH_mass_spring_get_motion_state(data, s->kl, x_kl, v);
BPH_mass_spring_get_motion_state(data, s->mn, x_mn, v);
BKE_sim_debug_data_add_dot(clmd->debug_data, x_kl, 0.9, 0.9, 0.9, "target", 7980, s->kl);
BKE_sim_debug_data_add_line(clmd->debug_data, x_kl, x_mn, 0.8, 0.8, 0.8, "target", 7981, s->kl);
copy_v3_v3(d, s->target);
BKE_sim_debug_data_add_vector(clmd->debug_data, x_kl, d, 0.8, 0.8, 0.2, "target", 7982, s->kl);
//.........这里部分代码省略.........
示例4: distribute_grid
static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys)
{
ParticleData *pa=NULL;
float min[3], max[3], delta[3], d;
MVert *mv, *mvert = dm->getVertDataArray(dm,0);
int totvert=dm->getNumVerts(dm), from=psys->part->from;
int i, j, k, p, res=psys->part->grid_res, size[3], axis;
/* find bounding box of dm */
if (totvert > 0) {
mv=mvert;
copy_v3_v3(min, mv->co);
copy_v3_v3(max, mv->co);
mv++;
for (i = 1; i < totvert; i++, mv++) {
minmax_v3v3_v3(min, max, mv->co);
}
}
else {
zero_v3(min);
zero_v3(max);
}
sub_v3_v3v3(delta, max, min);
/* determine major axis */
axis = axis_dominant_v3_single(delta);
d = delta[axis]/(float)res;
size[axis] = res;
size[(axis+1)%3] = (int)ceil(delta[(axis+1)%3]/d);
size[(axis+2)%3] = (int)ceil(delta[(axis+2)%3]/d);
/* float errors grrr.. */
size[(axis+1)%3] = MIN2(size[(axis+1)%3],res);
size[(axis+2)%3] = MIN2(size[(axis+2)%3],res);
size[0] = MAX2(size[0], 1);
size[1] = MAX2(size[1], 1);
size[2] = MAX2(size[2], 1);
/* no full offset for flat/thin objects */
min[0]+= d < delta[0] ? d/2.f : delta[0]/2.f;
min[1]+= d < delta[1] ? d/2.f : delta[1]/2.f;
min[2]+= d < delta[2] ? d/2.f : delta[2]/2.f;
for (i=0,p=0,pa=psys->particles; i<res; i++) {
for (j=0; j<res; j++) {
for (k=0; k<res; k++,p++,pa++) {
pa->fuv[0] = min[0] + (float)i*d;
pa->fuv[1] = min[1] + (float)j*d;
pa->fuv[2] = min[2] + (float)k*d;
pa->flag |= PARS_UNEXIST;
pa->hair_index = 0; /* abused in volume calculation */
}
}
}
/* enable particles near verts/edges/faces/inside surface */
if (from==PART_FROM_VERT) {
float vec[3];
pa=psys->particles;
min[0] -= d/2.0f;
min[1] -= d/2.0f;
min[2] -= d/2.0f;
for (i=0,mv=mvert; i<totvert; i++,mv++) {
sub_v3_v3v3(vec,mv->co,min);
vec[0]/=delta[0];
vec[1]/=delta[1];
vec[2]/=delta[2];
pa[((int)(vec[0] * (size[0] - 1)) * res +
(int)(vec[1] * (size[1] - 1))) * res +
(int)(vec[2] * (size[2] - 1))].flag &= ~PARS_UNEXIST;
}
}
else if (ELEM(from,PART_FROM_FACE,PART_FROM_VOLUME)) {
float co1[3], co2[3];
MFace *mface= NULL, *mface_array;
float v1[3], v2[3], v3[3], v4[4], lambda;
int a, a1, a2, a0mul, a1mul, a2mul, totface;
int amax= from==PART_FROM_FACE ? 3 : 1;
totface=dm->getNumTessFaces(dm);
mface=mface_array=dm->getTessFaceDataArray(dm,CD_MFACE);
for (a=0; a<amax; a++) {
if (a==0) { a0mul=res*res; a1mul=res; a2mul=1; }
else if (a==1) { a0mul=res; a1mul=1; a2mul=res*res; }
else { a0mul=1; a1mul=res*res; a2mul=res; }
for (a1=0; a1<size[(a+1)%3]; a1++) {
for (a2=0; a2<size[(a+2)%3]; a2++) {
mface= mface_array;
pa = psys->particles + a1*a1mul + a2*a2mul;
//.........这里部分代码省略.........
示例5: BKE_mesh_validate_arrays
int BKE_mesh_validate_arrays(Mesh *mesh,
MVert *mverts, unsigned int totvert,
MEdge *medges, unsigned int totedge,
MFace *mfaces, unsigned int totface,
MLoop *mloops, unsigned int totloop,
MPoly *mpolys, unsigned int totpoly,
MDeformVert *dverts, /* assume totvert length */
const bool do_verbose, const bool do_fixes)
{
# define REMOVE_EDGE_TAG(_me) { _me->v2 = _me->v1; do_edge_free = true; } (void)0
# define IS_REMOVED_EDGE(_me) (_me->v2 == _me->v1)
# define REMOVE_LOOP_TAG(_ml) { _ml->e = INVALID_LOOP_EDGE_MARKER; do_polyloop_free = true; } (void)0
# define REMOVE_POLY_TAG(_mp) { _mp->totloop *= -1; do_polyloop_free = true; } (void)0
MVert *mv = mverts;
MEdge *me;
MLoop *ml;
MPoly *mp;
unsigned int i, j;
int *v;
bool do_edge_free = false;
bool do_face_free = false;
bool do_polyloop_free = false; /* This regroups loops and polys! */
bool verts_fixed = false;
bool vert_weights_fixed = false;
bool msel_fixed = false;
bool do_edge_recalc = false;
EdgeHash *edge_hash = BLI_edgehash_new();
BLI_assert(!(do_fixes && mesh == NULL));
PRINT("%s: verts(%u), edges(%u), loops(%u), polygons(%u)\n",
__func__, totvert, totedge, totloop, totpoly);
if (totedge == 0 && totpoly != 0) {
PRINT("\tLogical error, %u polygons and 0 edges\n", totpoly);
do_edge_recalc = do_fixes;
}
for (i = 1; i < totvert; i++, mv++) {
int fix_normal = TRUE;
for (j = 0; j < 3; j++) {
if (!finite(mv->co[j])) {
PRINT("\tVertex %u: has invalid coordinate\n", i);
if (do_fixes) {
zero_v3(mv->co);
verts_fixed = TRUE;
}
}
if (mv->no[j] != 0)
fix_normal = FALSE;
}
if (fix_normal) {
PRINT("\tVertex %u: has zero normal, assuming Z-up normal\n", i);
if (do_fixes) {
mv->no[2] = SHRT_MAX;
verts_fixed = TRUE;
}
}
}
for (i = 0, me = medges; i < totedge; i++, me++) {
int remove = FALSE;
if (me->v1 == me->v2) {
PRINT("\tEdge %u: has matching verts, both %u\n", i, me->v1);
remove = do_fixes;
}
if (me->v1 >= totvert) {
PRINT("\tEdge %u: v1 index out of range, %u\n", i, me->v1);
remove = do_fixes;
}
if (me->v2 >= totvert) {
PRINT("\tEdge %u: v2 index out of range, %u\n", i, me->v2);
remove = do_fixes;
}
if (BLI_edgehash_haskey(edge_hash, me->v1, me->v2)) {
PRINT("\tEdge %u: is a duplicate of %d\n", i,
GET_INT_FROM_POINTER(BLI_edgehash_lookup(edge_hash, me->v1, me->v2)));
remove = do_fixes;
}
if (remove == FALSE) {
BLI_edgehash_insert(edge_hash, me->v1, me->v2, SET_INT_IN_POINTER(i));
}
else {
REMOVE_EDGE_TAG(me);
}
}
//.........这里部分代码省略.........
示例6: ED_armature_origin_set
/* 0 == do center, 1 == center new, 2 == center cursor */
void ED_armature_origin_set(Scene *scene, Object *ob, float cursor[3], int centermode, int around)
{
Object *obedit = scene->obedit; // XXX get from context
EditBone *ebone;
bArmature *arm = ob->data;
float cent[3];
/* Put the armature into editmode */
if (ob != obedit) {
ED_armature_to_edit(ob);
obedit = NULL; /* we cant use this so behave as if there is no obedit */
}
/* Find the centerpoint */
if (centermode == 2) {
copy_v3_v3(cent, cursor);
invert_m4_m4(ob->imat, ob->obmat);
mul_m4_v3(ob->imat, cent);
}
else {
if (around == V3D_CENTROID) {
int total = 0;
zero_v3(cent);
for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
total += 2;
add_v3_v3(cent, ebone->head);
add_v3_v3(cent, ebone->tail);
}
if (total) {
mul_v3_fl(cent, 1.0f / (float)total);
}
}
else {
float min[3], max[3];
INIT_MINMAX(min, max);
for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
minmax_v3v3_v3(min, max, ebone->head);
minmax_v3v3_v3(min, max, ebone->tail);
}
mid_v3_v3v3(cent, min, max);
}
}
/* Do the adjustments */
for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
sub_v3_v3(ebone->head, cent);
sub_v3_v3(ebone->tail, cent);
}
/* Turn the list into an armature */
if (obedit == NULL) {
ED_armature_from_edit(ob);
ED_armature_edit_free(ob);
}
/* Adjust object location for new centerpoint */
if (centermode && obedit == NULL) {
mul_mat3_m4_v3(ob->obmat, cent); /* ommit translation part */
add_v3_v3(ob->loc, cent);
}
}
示例7: BLI_array_alloca
//.........这里部分代码省略.........
float vec[3] = {0, 1, 0};
float cross1[3];
float cross2[3];
cross_v3_v3v3(cross1, vec, axis_vec);
mul_v3_m3v3(cross2, mtx3_tx, cross1);
{
float c1[3];
float c2[3];
float axis_tmp[3];
cross_v3_v3v3(c1, cross2, axis_vec);
cross_v3_v3v3(c2, axis_vec, c1);
angle = angle_v3v3(cross1, c2);
cross_v3_v3v3(axis_tmp, cross1, c2);
normalize_v3(axis_tmp);
if (len_v3v3(axis_tmp, axis_vec) > 1.0f)
angle = -angle;
}
}
#endif
}
else {
/* exis char is used by i_rotate*/
axis_char = (char)(axis_char + ltmd->axis); /* 'X' + axis */
/* useful to be able to use the axis vec in some cases still */
zero_v3(axis_vec);
axis_vec[ltmd->axis] = 1.0f;
}
/* apply the multiplier */
angle *= (float)ltmd->iter;
screw_ofs *= (float)ltmd->iter;
uv_u_scale = 1.0f / (float)(step_tot);
/* multiplying the steps is a bit tricky, this works best */
step_tot = ((step_tot + 1) * ltmd->iter) - (ltmd->iter - 1);
/* will the screw be closed?
* Note! smaller then FLT_EPSILON * 100 gives problems with float precision so its never closed. */
if (fabsf(screw_ofs) <= (FLT_EPSILON * 100.0f) &&
fabsf(fabsf(angle) - ((float)M_PI * 2.0f)) <= (FLT_EPSILON * 100.0f))
{
close = 1;
step_tot--;
if (step_tot < 3) step_tot = 3;
maxVerts = totvert * step_tot; /* -1 because we're joining back up */
maxEdges = (totvert * step_tot) + /* these are the edges between new verts */
(totedge * step_tot); /* -1 because vert edges join */
maxPolys = totedge * step_tot;
screw_ofs = 0.0f;
}
else {
close = 0;
if (step_tot < 3) step_tot = 3;
maxVerts = totvert * step_tot; /* -1 because we're joining back up */
示例8: UNUSED
//.........这里部分代码省略.........
float vec[3] = {0,1,0};
float cross1[3];
float cross2[3];
cross_v3_v3v3(cross1, vec, axis_vec);
mul_v3_m3v3(cross2, mtx3_tx, cross1);
{
float c1[3];
float c2[3];
float axis_tmp[3];
cross_v3_v3v3(c1, cross2, axis_vec);
cross_v3_v3v3(c2, axis_vec, c1);
angle= angle_v3v3(cross1, c2);
cross_v3_v3v3(axis_tmp, cross1, c2);
normalize_v3(axis_tmp);
if(len_v3v3(axis_tmp, axis_vec) > 1.0f)
angle= -angle;
}
}
#endif
}
else {
/* exis char is used by i_rotate*/
axis_char += ltmd->axis; /* 'X' + axis */
/* useful to be able to use the axis vec in some cases still */
zero_v3(axis_vec);
axis_vec[ltmd->axis]= 1.0f;
}
/* apply the multiplier */
angle *= ltmd->iter;
screw_ofs *= ltmd->iter;
/* multiplying the steps is a bit tricky, this works best */
step_tot = ((step_tot + 1) * ltmd->iter) - (ltmd->iter - 1);
/* will the screw be closed?
* Note! smaller then FLT_EPSILON*100 gives problems with float precision so its never closed. */
if (fabsf(screw_ofs) <= (FLT_EPSILON*100.0f) && fabsf(fabsf(angle) - ((float)M_PI * 2.0f)) <= (FLT_EPSILON*100.0f)) {
close= 1;
step_tot--;
if(step_tot < 3) step_tot= 3;
maxVerts = totvert * step_tot; /* -1 because we're joining back up */
maxEdges = (totvert * step_tot) + /* these are the edges between new verts */
(totedge * step_tot); /* -1 because vert edges join */
maxFaces = totedge * step_tot;
screw_ofs= 0.0f;
}
else {
close= 0;
if(step_tot < 3) step_tot= 3;
maxVerts = totvert * step_tot; /* -1 because we're joining back up */
maxEdges = (totvert * (step_tot-1)) + /* these are the edges between new verts */
(totedge * step_tot); /* -1 because vert edges join */
maxFaces = totedge * (step_tot-1);
示例9: rna_Object_ray_cast
static void rna_Object_ray_cast(Object *ob,
bContext *C,
ReportList *reports,
float origin[3],
float direction[3],
float distance,
PointerRNA *rnaptr_depsgraph,
bool *r_success,
float r_location[3],
float r_normal[3],
int *r_index)
{
bool success = false;
if (ob->runtime.mesh_eval == NULL &&
(ob = eval_object_ensure(ob, C, reports, rnaptr_depsgraph)) == NULL) {
return;
}
/* Test BoundBox first (efficiency) */
BoundBox *bb = BKE_object_boundbox_get(ob);
float distmin;
normalize_v3(
direction); /* Needed for valid distance check from isect_ray_aabb_v3_simple() call. */
if (!bb ||
(isect_ray_aabb_v3_simple(origin, direction, bb->vec[0], bb->vec[6], &distmin, NULL) &&
distmin <= distance)) {
BVHTreeFromMesh treeData = {NULL};
/* No need to managing allocation or freeing of the BVH data.
* This is generated and freed as needed. */
BKE_bvhtree_from_mesh_get(&treeData, ob->runtime.mesh_eval, BVHTREE_FROM_LOOPTRI, 4);
/* may fail if the mesh has no faces, in that case the ray-cast misses */
if (treeData.tree != NULL) {
BVHTreeRayHit hit;
hit.index = -1;
hit.dist = distance;
if (BLI_bvhtree_ray_cast(treeData.tree,
origin,
direction,
0.0f,
&hit,
treeData.raycast_callback,
&treeData) != -1) {
if (hit.dist <= distance) {
*r_success = success = true;
copy_v3_v3(r_location, hit.co);
copy_v3_v3(r_normal, hit.no);
*r_index = mesh_looptri_to_poly_index(ob->runtime.mesh_eval,
&treeData.looptri[hit.index]);
}
}
free_bvhtree_from_mesh(&treeData);
}
}
if (success == false) {
*r_success = false;
zero_v3(r_location);
zero_v3(r_normal);
*r_index = -1;
}
}
示例10: pointdensity_cache_psys
static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, ParticleSystem *psys)
{
DerivedMesh* dm;
ParticleKey state;
ParticleCacheKey *cache;
ParticleSimulationData sim= {NULL};
ParticleData *pa=NULL;
float cfra = BKE_scene_frame_get(re->scene);
int i /*, childexists*/ /* UNUSED */;
int total_particles, offset=0;
int data_used = point_data_used(pd);
float partco[3];
float obview[4][4];
/* init everything */
if (!psys || !ob || !pd) return;
mul_m4_m4m4(obview, ob->obmat, re->viewinv);
/* Just to create a valid rendering context for particles */
psys_render_set(ob, psys, re->viewmat, re->winmat, re->winx, re->winy, 0);
dm = mesh_create_derived_render(re->scene, ob, CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL);
if ( !psys_check_enabled(ob, psys)) {
psys_render_restore(ob, psys);
return;
}
sim.scene= re->scene;
sim.ob= ob;
sim.psys= psys;
/* in case ob->imat isn't up-to-date */
invert_m4_m4(ob->imat, ob->obmat);
total_particles = psys->totpart+psys->totchild;
psys->lattice_deform_data = psys_create_lattice_deform_data(&sim);
pd->point_tree = BLI_bvhtree_new(total_particles, 0.0, 4, 6);
alloc_point_data(pd, total_particles, data_used);
pd->totpoints = total_particles;
if (data_used & POINT_DATA_VEL) offset = pd->totpoints*3;
#if 0 /* UNUSED */
if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT))
childexists = 1;
#endif
for (i=0, pa=psys->particles; i < total_particles; i++, pa++) {
if (psys->part->type == PART_HAIR) {
/* hair particles */
if (i < psys->totpart && psys->pathcache)
cache = psys->pathcache[i];
else if (i >= psys->totpart && psys->childcache)
cache = psys->childcache[i - psys->totpart];
else
continue;
cache += cache->segments; /* use endpoint */
copy_v3_v3(state.co, cache->co);
zero_v3(state.vel);
state.time = 0.0f;
}
else {
/* emitter particles */
state.time = cfra;
if (!psys_get_particle_state(&sim, i, &state, 0))
continue;
if (data_used & POINT_DATA_LIFE) {
if (i < psys->totpart) {
state.time = (cfra - pa->time)/pa->lifetime;
}
else {
ChildParticle *cpa= (psys->child + i) - psys->totpart;
float pa_birthtime, pa_dietime;
state.time = psys_get_child_time(psys, cpa, cfra, &pa_birthtime, &pa_dietime);
}
}
}
copy_v3_v3(partco, state.co);
if (pd->psys_cache_space == TEX_PD_OBJECTSPACE)
mul_m4_v3(ob->imat, partco);
else if (pd->psys_cache_space == TEX_PD_OBJECTLOC) {
sub_v3_v3(partco, ob->loc);
}
else {
/* TEX_PD_WORLDSPACE */
}
BLI_bvhtree_insert(pd->point_tree, i, partco, 1);
if (data_used & POINT_DATA_VEL) {
//.........这里部分代码省略.........
示例11: initFlyInfo
static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent *event)
{
wmWindow *win = CTX_wm_window(C);
rctf viewborder;
float upvec[3]; /* tmp */
float mat[3][3];
fly->rv3d = CTX_wm_region_view3d(C);
fly->v3d = CTX_wm_view3d(C);
fly->ar = CTX_wm_region(C);
fly->scene = CTX_data_scene(C);
#ifdef NDOF_FLY_DEBUG
puts("\n-- fly begin --");
#endif
/* sanity check: for rare but possible case (if lib-linking the camera fails) */
if ((fly->rv3d->persp == RV3D_CAMOB) && (fly->v3d->camera == NULL)) {
fly->rv3d->persp = RV3D_PERSP;
}
if (fly->rv3d->persp == RV3D_CAMOB && ID_IS_LINKED(fly->v3d->camera)) {
BKE_report(op->reports, RPT_ERROR, "Cannot fly a camera from an external library");
return false;
}
if (ED_view3d_offset_lock_check(fly->v3d, fly->rv3d)) {
BKE_report(op->reports, RPT_ERROR, "Cannot fly when the view offset is locked");
return false;
}
if (fly->rv3d->persp == RV3D_CAMOB && fly->v3d->camera->constraints.first) {
BKE_report(op->reports, RPT_ERROR, "Cannot fly an object with constraints");
return false;
}
fly->state = FLY_RUNNING;
fly->speed = 0.0f;
fly->axis = 2;
fly->pan_view = false;
fly->xlock = FLY_AXISLOCK_STATE_OFF;
fly->zlock = FLY_AXISLOCK_STATE_OFF;
fly->xlock_momentum = 0.0f;
fly->zlock_momentum = 0.0f;
fly->grid = 1.0f;
fly->use_precision = false;
fly->use_freelook = false;
#ifdef NDOF_FLY_DRAW_TOOMUCH
fly->redraw = 1;
#endif
zero_v3(fly->dvec_prev);
fly->timer = WM_event_add_timer(CTX_wm_manager(C), win, TIMER, 0.01f);
copy_v2_v2_int(fly->mval, event->mval);
#ifdef WITH_INPUT_NDOF
fly->ndof = NULL;
#endif
fly->time_lastdraw = fly->time_lastwheel = PIL_check_seconds_timer();
fly->draw_handle_pixel = ED_region_draw_cb_activate(fly->ar->type, drawFlyPixel, fly, REGION_DRAW_POST_PIXEL);
fly->rv3d->rflag |= RV3D_NAVIGATING;
/* detect whether to start with Z locking */
copy_v3_fl3(upvec, 1.0f, 0.0f, 0.0f);
copy_m3_m4(mat, fly->rv3d->viewinv);
mul_m3_v3(mat, upvec);
if (fabsf(upvec[2]) < 0.1f) {
fly->zlock = FLY_AXISLOCK_STATE_IDLE;
}
fly->v3d_camera_control = ED_view3d_cameracontrol_acquire(
fly->scene, fly->v3d, fly->rv3d,
(U.uiflag & USER_CAM_LOCK_NO_PARENT) == 0);
/* calculate center */
if (fly->scene->camera) {
ED_view3d_calc_camera_border(fly->scene, fly->ar, fly->v3d, fly->rv3d, &viewborder, false);
fly->width = BLI_rctf_size_x(&viewborder);
fly->height = BLI_rctf_size_y(&viewborder);
fly->center_mval[0] = viewborder.xmin + fly->width / 2;
fly->center_mval[1] = viewborder.ymin + fly->height / 2;
}
else {
fly->width = fly->ar->winx;
fly->height = fly->ar->winy;
fly->center_mval[0] = fly->width / 2;
fly->center_mval[1] = fly->height / 2;
}
/* center the mouse, probably the UI mafia are against this but without its quite annoying */
WM_cursor_warp(win, fly->ar->winrct.xmin + fly->center_mval[0], fly->ar->winrct.ymin + fly->center_mval[1]);
//.........这里部分代码省略.........
示例12: recalc_face_normals_find_index
/**
* \return a face index in \a faces and set \a r_is_flip
* if the face is flipped away from the center.
*/
static int recalc_face_normals_find_index(BMesh *bm,
BMFace **faces,
const int faces_len,
bool *r_is_flip)
{
const float eps = FLT_EPSILON;
float cent_area_accum = 0.0f;
float cent[3];
const float cent_fac = 1.0f / (float)faces_len;
bool is_flip = false;
int f_start_index;
int i;
/** Search for the best loop. Members are compared in-order defined here. */
struct {
/**
* Squared distance from the center to the loops vertex 'l->v'.
* The normalized direction between the center and this vertex
* is also used for the dot-products below.
*/
float dist_sq;
/**
* Signed dot product using the normalized edge vector,
* (best of 'l->prev->v' or 'l->next->v').
*/
float edge_dot;
/**
* Unsigned dot product using the loop-normal
* (sign is used to check if we need to flip).
*/
float loop_dot;
} best, test;
UNUSED_VARS_NDEBUG(bm);
zero_v3(cent);
/* first calculate the center */
for (i = 0; i < faces_len; i++) {
float f_cent[3];
const float f_area = BM_face_calc_area(faces[i]);
BM_face_calc_center_median_weighted(faces[i], f_cent);
madd_v3_v3fl(cent, f_cent, cent_fac * f_area);
cent_area_accum += f_area;
BLI_assert(BMO_face_flag_test(bm, faces[i], FACE_TEMP) == 0);
BLI_assert(BM_face_is_normal_valid(faces[i]));
}
if (cent_area_accum != 0.0f) {
mul_v3_fl(cent, 1.0f / cent_area_accum);
}
/* Distances must start above zero,
* or we can't do meaningful calculations based on the direction to the center */
best.dist_sq = eps;
best.edge_dot = best.loop_dot = -FLT_MAX;
/* used in degenerate cases only */
f_start_index = 0;
/**
* Find the outer-most vertex, comparing distance to the center,
* then the outer-most loop attached to that vertex.
*
* Important this is correctly detected,
* where casting a ray from the center wont hit any loops past this one.
* Otherwise the result may be incorrect.
*/
for (i = 0; i < faces_len; i++) {
BMLoop *l_iter, *l_first;
l_iter = l_first = BM_FACE_FIRST_LOOP(faces[i]);
do {
bool is_best_dist_sq;
float dir[3];
sub_v3_v3v3(dir, l_iter->v->co, cent);
test.dist_sq = len_squared_v3(dir);
is_best_dist_sq = (test.dist_sq > best.dist_sq);
if (is_best_dist_sq || (test.dist_sq == best.dist_sq)) {
float edge_dir_pair[2][3];
mul_v3_fl(dir, 1.0f / sqrtf(test.dist_sq));
sub_v3_v3v3(edge_dir_pair[0], l_iter->next->v->co, l_iter->v->co);
sub_v3_v3v3(edge_dir_pair[1], l_iter->prev->v->co, l_iter->v->co);
if ((normalize_v3(edge_dir_pair[0]) > eps) && (normalize_v3(edge_dir_pair[1]) > eps)) {
bool is_best_edge_dot;
test.edge_dot = max_ff(dot_v3v3(dir, edge_dir_pair[0]), dot_v3v3(dir, edge_dir_pair[1]));
is_best_edge_dot = (test.edge_dot > best.edge_dot);
if (is_best_dist_sq || is_best_edge_dot || (test.edge_dot == best.edge_dot)) {
float loop_dir[3];
cross_v3_v3v3(loop_dir, edge_dir_pair[0], edge_dir_pair[1]);
if (normalize_v3(loop_dir) > eps) {
float loop_dir_dot;
//.........这里部分代码省略.........
示例13: boid_brain
/* determines the velocity the boid wants to have */
void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa)
{
BoidRule *rule;
BoidSettings *boids = bbd->part->boids;
BoidValues val;
BoidState *state = get_boid_state(boids, pa);
BoidParticle *bpa = pa->boid;
ParticleSystem *psys = bbd->sim->psys;
int rand;
//BoidCondition *cond;
if (bpa->data.health <= 0.0f) {
pa->alive = PARS_DYING;
pa->dietime = bbd->cfra;
return;
}
//planned for near future
//cond = state->conditions.first;
//for (; cond; cond=cond->next) {
// if (boid_condition_is_true(cond)) {
// pa->boid->state_id = cond->state_id;
// state = get_boid_state(boids, pa);
// break; /* only first true condition is used */
// }
//}
zero_v3(bbd->wanted_co);
bbd->wanted_speed = 0.0f;
/* create random seed for every particle & frame */
rand = (int)(psys_frand(psys, psys->seed + p) * 1000);
rand = (int)(psys_frand(psys, (int)bbd->cfra + rand) * 1000);
set_boid_values(&val, bbd->part->boids, pa);
/* go through rules */
switch (state->ruleset_type) {
case eBoidRulesetType_Fuzzy:
{
for (rule = state->rules.first; rule; rule = rule->next) {
if (apply_boid_rule(bbd, rule, &val, pa, state->rule_fuzziness))
break; /* only first nonzero rule that comes through fuzzy rule is applied */
}
break;
}
case eBoidRulesetType_Random:
{
/* use random rule for each particle (always same for same particle though) */
rule = BLI_findlink(&state->rules, rand % BLI_listbase_count(&state->rules));
apply_boid_rule(bbd, rule, &val, pa, -1.0);
break;
}
case eBoidRulesetType_Average:
{
float wanted_co[3] = {0.0f, 0.0f, 0.0f}, wanted_speed = 0.0f;
int n = 0;
for (rule = state->rules.first; rule; rule=rule->next) {
if (apply_boid_rule(bbd, rule, &val, pa, -1.0f)) {
add_v3_v3(wanted_co, bbd->wanted_co);
wanted_speed += bbd->wanted_speed;
n++;
zero_v3(bbd->wanted_co);
bbd->wanted_speed = 0.0f;
}
}
if (n > 1) {
mul_v3_fl(wanted_co, 1.0f/(float)n);
wanted_speed /= (float)n;
}
copy_v3_v3(bbd->wanted_co, wanted_co);
bbd->wanted_speed = wanted_speed;
break;
}
}
/* decide on jumping & liftoff */
if (bpa->data.mode == eBoidMode_OnLand) {
/* fuzziness makes boids capable of misjudgement */
float mul = 1.0f + state->rule_fuzziness;
if (boids->options & BOID_ALLOW_FLIGHT && bbd->wanted_co[2] > 0.0f) {
float cvel[3], dir[3];
copy_v3_v3(dir, pa->prev_state.ave);
normalize_v2(dir);
copy_v3_v3(cvel, bbd->wanted_co);
normalize_v2(cvel);
if (dot_v2v2(cvel, dir) > 0.95f / mul)
bpa->data.mode = eBoidMode_Liftoff;
}
else if (val.jump_speed > 0.0f) {
float jump_v[3];
//.........这里部分代码省略.........
示例14: walkApply
//.........这里部分代码省略.........
if (moffset[0]) {
float x;
/* if we're upside down invert the moffset */
copy_v3_fl3(upvec, 0.0f, 1.0f, 0.0f);
mul_m3_v3(mat, upvec);
if (upvec[2] < 0.0f)
moffset[0] = -moffset[0];
/* relative offset */
x = (float) moffset[0] / ar->winx;
/* speed factor */
x *= WALK_ROTATE_FAC;
/* user adjustement factor */
x *= walk->mouse_speed;
copy_v3_fl3(upvec, 0.0f, 0.0f, 1.0f);
/* Rotate about the relative up vec */
axis_angle_normalized_to_quat(tmp_quat, upvec, x);
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
}
}
/* WASD - 'move' translation code */
if ((walk->active_directions) &&
(walk->gravity_state == WALK_GRAVITY_STATE_OFF))
{
short direction;
zero_v3(dvec);
if ((walk->active_directions & WALK_BIT_FORWARD) ||
(walk->active_directions & WALK_BIT_BACKWARD))
{
direction = 0;
if ((walk->active_directions & WALK_BIT_FORWARD))
direction += 1;
if ((walk->active_directions & WALK_BIT_BACKWARD))
direction -= 1;
copy_v3_fl3(dvec_tmp, 0.0f, 0.0f, direction);
mul_m3_v3(mat, dvec_tmp);
if (walk->navigation_mode == WALK_MODE_GRAVITY) {
dvec_tmp[2] = 0.0f;
}
normalize_v3(dvec_tmp);
add_v3_v3(dvec, dvec_tmp);
}
if ((walk->active_directions & WALK_BIT_LEFT) ||
(walk->active_directions & WALK_BIT_RIGHT))
{
direction = 0;
if ((walk->active_directions & WALK_BIT_LEFT))
示例15: apply_objects_internal
//.........这里部分代码省略.........
}
/* apply to object data */
if (ob->type == OB_MESH) {
Mesh *me = ob->data;
MVert *mvert;
multiresModifier_scale_disp(scene, ob);
/* adjust data */
mvert = me->mvert;
for (a = 0; a < me->totvert; a++, mvert++)
mul_m4_v3(mat, mvert->co);
if (me->key) {
KeyBlock *kb;
for (kb = me->key->block.first; kb; kb = kb->next) {
float *fp = kb->data;
for (a = 0; a < kb->totelem; a++, fp += 3)
mul_m4_v3(mat, fp);
}
}
/* update normals */
BKE_mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
}
else if (ob->type == OB_ARMATURE) {
ED_armature_apply_transform(ob, mat);
}
else if (ob->type == OB_LATTICE) {
Lattice *lt = ob->data;
BPoint *bp = lt->def;
int a = lt->pntsu * lt->pntsv * lt->pntsw;
while (a--) {
mul_m4_v3(mat, bp->vec);
bp++;
}
}
else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
Curve *cu = ob->data;
Nurb *nu;
BPoint *bp;
BezTriple *bezt;
scale = mat3_to_scale(rsmat);
for (nu = cu->nurb.first; nu; nu = nu->next) {
if (nu->type == CU_BEZIER) {
a = nu->pntsu;
for (bezt = nu->bezt; a--; bezt++) {
mul_m4_v3(mat, bezt->vec[0]);
mul_m4_v3(mat, bezt->vec[1]);
mul_m4_v3(mat, bezt->vec[2]);
bezt->radius *= scale;
}
BKE_nurb_handles_calc(nu);
}
else {
a = nu->pntsu * nu->pntsv;
for (bp = nu->bp; a--; bp++)
mul_m4_v3(mat, bp->vec);
}
}
}
else
continue;
if (apply_loc)
zero_v3(ob->loc);
if (apply_scale)
ob->size[0] = ob->size[1] = ob->size[2] = 1.0f;
if (apply_rot) {
zero_v3(ob->rot);
unit_qt(ob->quat);
unit_axis_angle(ob->rotAxis, &ob->rotAngle);
}
BKE_object_where_is_calc(scene, ob);
if (ob->type == OB_ARMATURE) {
BKE_pose_where_is(scene, ob); /* needed for bone parents */
}
ignore_parent_tx(bmain, scene, ob);
DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA);
change = 1;
}
CTX_DATA_END;
if (!change)
return OPERATOR_CANCELLED;
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
return OPERATOR_FINISHED;
}