コード例 #1
0
void free_pointdensities(Render *re)
{
	Tex *tex;
	
	if(re->scene->r.scemode & R_PREVIEWBUTS)
		return;
	
	for (tex= re->main->tex.first; tex; tex= tex->id.next) {
		if(tex->id.us && tex->type==TEX_POINTDENSITY) {
			free_pointdensity(re, tex);
		}
	}
}
コード例 #2
0
ファイル: pointdensity.c プロジェクト: GeniaPenksik/blender
void RE_sample_point_density(Scene *scene, PointDensity *pd,
                             int resolution, float *values)
{
	const size_t resolution2 = resolution * resolution;
	Object *object = pd->object;
	size_t x, y, z;
	float min[3], max[3], dim[3], mat[4][4];

	if (object == NULL) {
		sample_dummy_point_density(resolution, values);
		return;
	}

	if (pd->source == TEX_PD_PSYS) {
		ParticleSystem *psys;
		if (pd->psys == 0) {
			sample_dummy_point_density(resolution, values);
			return;
		}
		psys = BLI_findlink(&object->particlesystem, pd->psys - 1);
		if (psys == NULL) {
			sample_dummy_point_density(resolution, values);
			return;
		}
		particle_system_minmax(scene, object, psys, pd->radius, min, max);
	}
	else {
		float radius[3] = {pd->radius, pd->radius, pd->radius};
		float *loc, *size;
		BKE_object_obdata_texspace_get(pd->object, NULL, &loc, &size, NULL);
		sub_v3_v3v3(min, loc, size);
		add_v3_v3v3(max, loc, size);
		/* Adjust texture space to include density points on the boundaries. */
		sub_v3_v3(min, radius);
		add_v3_v3(max, radius);
	}

	sub_v3_v3v3(dim, max, min);
	if (dim[0] <= 0.0f || dim[1] <= 0.0f || dim[2] <= 0.0f) {
		sample_dummy_point_density(resolution, values);
		return;
	}

	/* Same matricies/resolution as dupli_render_particle_set(). */
	unit_m4(mat);

	BLI_mutex_lock(&sample_mutex);
	cache_pointdensity_ex(scene, pd, mat, mat, 1, 1);
	for (z = 0; z < resolution; ++z) {
		for (y = 0; y < resolution; ++y) {
			for (x = 0; x < resolution; ++x) {
				size_t index = z * resolution2 + y * resolution + x;
				float texvec[3];
				float age, vec[3];
				TexResult texres;

				copy_v3_v3(texvec, min);
				texvec[0] += dim[0] * (float)x / (float)resolution;
				texvec[1] += dim[1] * (float)y / (float)resolution;
				texvec[2] += dim[2] * (float)z / (float)resolution;

				pointdensity(pd, texvec, &texres, &age, vec);
				pointdensity_color(pd, &texres, age, vec);

				copy_v3_v3(&values[index*4 + 0], &texres.tr);
				values[index*4 + 3] = texres.tin;
			}
		}
	}
	free_pointdensity(pd);
	BLI_mutex_unlock(&sample_mutex);
}