Пример #1
0
/**
 * Find at most 26 cubes to start polygonization from.
 */
static void find_first_points(PROCESS *process, const unsigned int em)
{
	const MetaElem *ml;
	int center[3], lbn[3], rtf[3], it[3], dir[3], add[3];
	float tmp[3], a, b;

	ml = process->mainb[em];

	mid_v3_v3v3(tmp, ml->bb->vec[0], ml->bb->vec[6]);
	closest_latice(center, tmp, process->size);
	prev_lattice(lbn, ml->bb->vec[0], process->size);
	next_lattice(rtf, ml->bb->vec[6], process->size);

	for (dir[0] = -1; dir[0] <= 1; dir[0]++) {
		for (dir[1] = -1; dir[1] <= 1; dir[1]++) {
			for (dir[2] = -1; dir[2] <= 1; dir[2]++) {
				if (dir[0] == 0 && dir[1] == 0 && dir[2] == 0) {
					continue;
				}

				copy_v3_v3_int(it, center);

				b = setcorner(process, it[0], it[1], it[2])->value;
				do {
					it[0] += dir[0];
					it[1] += dir[1];
					it[2] += dir[2];
					a = b;
					b = setcorner(process, it[0], it[1], it[2])->value;

					if (a * b < 0.0f) {
						add[0] = it[0] - dir[0];
						add[1] = it[1] - dir[1];
						add[2] = it[2] - dir[2];
						DO_MIN(it, add);
						add_cube(process, add[0], add[1], add[2]);
						break;
					}
				} while ((it[0] > lbn[0]) && (it[1] > lbn[1]) && (it[2] > lbn[2]) &&
				         (it[0] < rtf[0]) && (it[1] < rtf[1]) && (it[2] < rtf[2]));
			}
		}
	}
}
Пример #2
0
static void init_frame_smoke(VoxelData *vd, int cfra)
{
#ifdef WITH_SMOKE
	Object *ob;
	ModifierData *md;
	
	vd->dataset = NULL;
	if (vd->object == NULL) return;
	ob = vd->object;
	
	/* draw code for smoke */
	if ((md = (ModifierData *)modifiers_findByType(ob, eModifierType_Smoke))) {
		SmokeModifierData *smd = (SmokeModifierData *)md;
		SmokeDomainSettings *sds = smd->domain;
		
		if (sds && sds->fluid) {
			BLI_rw_mutex_lock(sds->fluid_mutex, THREAD_LOCK_READ);

			if (!sds->fluid) {
				BLI_rw_mutex_unlock(sds->fluid_mutex);
				return;
			}

			if (cfra < sds->point_cache[0]->startframe)
				;  /* don't show smoke before simulation starts, this could be made an option in the future */
			else if (vd->smoked_type == TEX_VD_SMOKEHEAT) {
				size_t totRes;
				size_t i;
				float *heat;

				if (!smoke_has_heat(sds->fluid)) {
					BLI_rw_mutex_unlock(sds->fluid_mutex);
					return;
				}

				copy_v3_v3_int(vd->resol, sds->res);
				totRes = vd_resol_size(vd);
				vd->dataset = MEM_mapallocN(sizeof(float) * (totRes), "smoke data");
				/* get heat data */
				heat = smoke_get_heat(sds->fluid);

				/* scale heat values from -2.0-2.0 to 0.0-1.0 */
				for (i = 0; i < totRes; i++) {
					vd->dataset[i] = (heat[i] + 2.0f) / 4.0f;
				}
			}
			else if (vd->smoked_type == TEX_VD_SMOKEVEL) {
				size_t totRes;
				size_t i;
				float *xvel, *yvel, *zvel;

				copy_v3_v3_int(vd->resol, sds->res);
				totRes = vd_resol_size(vd);
				vd->dataset = MEM_mapallocN(sizeof(float) * (totRes), "smoke data");
				/* get velocity data */
				xvel = smoke_get_velocity_x(sds->fluid);
				yvel = smoke_get_velocity_y(sds->fluid);
				zvel = smoke_get_velocity_z(sds->fluid);

				/* map velocities between 0 and 0.3f */
				for (i = 0; i < totRes; i++) {
					vd->dataset[i] = sqrtf(xvel[i] * xvel[i] + yvel[i] * yvel[i] + zvel[i] * zvel[i]) * 3.0f;
				}

			}
			else if (vd->smoked_type == TEX_VD_SMOKEFLAME) {
				size_t totRes;
				float *flame;

				if (sds->flags & MOD_SMOKE_HIGHRES) {
					if (!smoke_turbulence_has_fuel(sds->wt)) {
						BLI_rw_mutex_unlock(sds->fluid_mutex);
						return;
					}
					smoke_turbulence_get_res(sds->wt, vd->resol);
					flame = smoke_turbulence_get_flame(sds->wt);
				}
				else {
					if (!smoke_has_fuel(sds->fluid)) {
						BLI_rw_mutex_unlock(sds->fluid_mutex);
						return;
					}
					copy_v3_v3_int(vd->resol, sds->res);
					flame = smoke_get_flame(sds->fluid);
				}

				/* always store copy, as smoke internal data can change */
				totRes = vd_resol_size(vd);
				vd->dataset = MEM_mapallocN(sizeof(float)*(totRes), "smoke data");
				memcpy(vd->dataset, flame, sizeof(float)*totRes);
			}
			else {
				size_t totCells;
				int depth = 4;
				vd->data_type = TEX_VD_RGBA_PREMUL;

				/* data resolution */
				if (sds->flags & MOD_SMOKE_HIGHRES) {
					smoke_turbulence_get_res(sds->wt, vd->resol);
				}
				else {
					copy_v3_v3_int(vd->resol, sds->res);
				}

				/* TODO: is_vd_res_ok(rvd) doesnt check this resolution */
				totCells = vd_resol_size(vd) * depth;
				/* always store copy, as smoke internal data can change */
				vd->dataset = MEM_mapallocN(sizeof(float) * totCells, "smoke data");

				if (sds->flags & MOD_SMOKE_HIGHRES) {
					if (smoke_turbulence_has_colors(sds->wt)) {
						smoke_turbulence_get_rgba(sds->wt, vd->dataset, 1);
					}
					else {
						smoke_turbulence_get_rgba_from_density(sds->wt, sds->active_color, vd->dataset, 1);
					}
				}
				else {
					if (smoke_has_colors(sds->fluid)) {
						smoke_get_rgba(sds->fluid, vd->dataset, 1);
					}
					else {
						smoke_get_rgba_from_density(sds->fluid, sds->active_color, vd->dataset, 1);
					}
				}
			}  /* end of fluid condition */

			BLI_rw_mutex_unlock(sds->fluid_mutex);
		}
	}
	
	vd->ok = 1;

#else // WITH_SMOKE
	(void)vd;
	(void)cfra;

	vd->dataset = NULL;
#endif
}