Exemplo n.º 1
0
static bool object_rand_transverts(
        TransVertStore *tvs,
        const float offset, const float uniform, const float normal_factor,
        const unsigned int seed)
{
	bool use_normal = (normal_factor != 0.0f);
	struct RNG *rng;
	TransVert *tv;
	int a;

	if (!tvs || !(tvs->transverts)) {
		return false;
	}

	rng = BLI_rng_new(seed);

	tv = tvs->transverts;
	for (a = 0; a < tvs->transverts_tot; a++, tv++) {
		const float t = max_ff(0.0f, uniform + ((1.0f - uniform) * BLI_rng_get_float(rng)));
		float vec[3];
		BLI_rng_get_float_unit_v3(rng, vec);

		if (use_normal && (tv->flag & TX_VERT_USE_NORMAL)) {
			float no[3];

			/* avoid >90d rotation to align with normal */
			if (dot_v3v3(vec, tv->normal) < 0.0f) {
				negate_v3_v3(no, tv->normal);
			}
			else {
				copy_v3_v3(no, tv->normal);
			}

			interp_v3_v3v3_slerp_safe(vec, vec, no, normal_factor);
		}

		madd_v3_v3fl(tv->loc, vec, offset * t);
	}

	BLI_rng_free(rng);

	return true;
}
Exemplo n.º 2
0
/* Note this modifies nos_new in-place. */
static void mix_normals(
        const float mix_factor, MDeformVert *dvert, const int defgrp_index, const bool use_invert_vgroup,
        const float mix_limit, const short mix_mode,
        const int num_verts, MLoop *mloop, float (*nos_old)[3], float (*nos_new)[3], const int num_loops)
{
	/* Mix with org normals... */
	float *facs = NULL, *wfac;
	float (*no_new)[3], (*no_old)[3];
	int i;

	if (dvert) {
		facs = MEM_malloc_arrayN((size_t)num_loops, sizeof(*facs), __func__);
		BKE_defvert_extract_vgroup_to_loopweights(
		            dvert, defgrp_index, num_verts, mloop, num_loops, facs, use_invert_vgroup);
	}

	for (i = num_loops, no_new = nos_new, no_old = nos_old, wfac = facs; i--; no_new++, no_old++, wfac++) {
		const float fac = facs ? *wfac * mix_factor : mix_factor;

		switch (mix_mode) {
			case MOD_NORMALEDIT_MIX_ADD:
				add_v3_v3(*no_new, *no_old);
				normalize_v3(*no_new);
				break;
			case MOD_NORMALEDIT_MIX_SUB:
				sub_v3_v3(*no_new, *no_old);
				normalize_v3(*no_new);
				break;
			case MOD_NORMALEDIT_MIX_MUL:
				mul_v3_v3(*no_new, *no_old);
				normalize_v3(*no_new);
				break;
			case MOD_NORMALEDIT_MIX_COPY:
				break;
		}

		interp_v3_v3v3_slerp_safe(
		        *no_new, *no_old, *no_new,
		        (mix_limit < (float)M_PI) ? min_ff(fac, mix_limit / angle_v3v3(*no_new, *no_old)) : fac);
	}

	MEM_SAFE_FREE(facs);
}