示例#1
0
static void build_image_lookup(Main *bmain, Object *ob, BakeImages *bake_images)
{
	const int tot_mat = ob->totcol;
	int i, j;
	int tot_images = 0;

	/* error handling and tag (in case multiple materials share the same image) */
	BKE_main_id_tag_idcode(bmain, ID_IM, false);

	for (i = 0; i < tot_mat; i++) {
		Image *image;
		ED_object_get_active_image(ob, i + 1, &image, NULL, NULL, NULL);

		if ((image->id.tag & LIB_TAG_DOIT)) {
			for (j = 0; j < i; j++) {
				if (bake_images->data[j].image == image) {
					bake_images->lookup[i] = j;
					break;
				}
			}
		}
		else {
			bake_images->lookup[i] = tot_images;
			bake_images->data[tot_images].image = image;
			image->id.tag |= LIB_TAG_DOIT;
			tot_images++;
		}
	}

	bake_images->size = tot_images;
}
示例#2
0
static bool build_image_lookup(Main *bmain, Object *ob, BakeImages *bake_images, ReportList *reports)
{
	const int tot_mat = ob->totcol;
	int i, j;
	int tot_images = 0;

	/* error handling and tag (in case multiple materials share the same image) */
	BKE_main_id_tag_idcode(bmain, ID_IM, false);

	for (i = 0; i < tot_mat; i++) {
		Image *image;
		ED_object_get_active_image(ob, i + 1, &image, NULL, NULL);

		if (!image) {
			if (ob->mat[i]) {
				BKE_reportf(reports, RPT_ERROR,
				            "No active image found in material %d (%s)", i, ob->mat[i]->id.name + 2);
			}
			else if (((Mesh *) ob->data)->mat[i]) {
				BKE_reportf(reports, RPT_ERROR,
				            "No active image found in material %d (%s)", i, ((Mesh *) ob->data)->mat[i]->id.name + 2);
			}
			else {
				BKE_reportf(reports, RPT_ERROR,
				            "No active image found in material %d", i);
			}
			return false;
		}

		if ((image->id.flag & LIB_DOIT)) {
			for (j = 0; j < i; j++) {
				if (bake_images->data[j].image == image) {
					bake_images->lookup[i] = j;
					break;
				}
			}
		}
		else {
			bake_images->lookup[i] = tot_images;
			bake_images->data[tot_images].image = image;
			image->id.flag |= LIB_DOIT;
			tot_images++;
		}
	}

	bake_images->size = tot_images;
	return true;
}
示例#3
0
/* before even getting in the bake function we check for some basic errors */
static bool bake_objects_check(Main *bmain, Object *ob, ListBase *selected_objects,
                               ReportList *reports, const bool is_selected_to_active)
{
	CollectionPointerLink *link;

	/* error handling and tag (in case multiple materials share the same image) */
	BKE_main_id_tag_idcode(bmain, ID_IM, false);

	if (is_selected_to_active) {
		int tot_objects = 0;

		if (!bake_object_check(ob, reports))
			return false;

		for (link = selected_objects->first; link; link = link->next) {
			Object *ob_iter = (Object *)link->ptr.data;

			if (ob_iter == ob)
				continue;

			if (ELEM(ob_iter->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL) == false) {
				BKE_reportf(reports, RPT_ERROR, "Object \"%s\" is not a mesh or can't be converted to a mesh (Curve, Text, Surface or Metaball)", ob_iter->id.name + 2);
				return false;
			}
			tot_objects += 1;
		}

		if (tot_objects == 0) {
			BKE_report(reports, RPT_ERROR, "No valid selected objects");
			return false;
		}
	}
	else {
		if (BLI_listbase_is_empty(selected_objects)) {
			BKE_report(reports, RPT_ERROR, "No valid selected objects");
			return false;
		}

		for (link = selected_objects->first; link; link = link->next) {
			if (!bake_object_check(link->ptr.data, reports))
				return false;
		}
	}
	return true;
}