コード例 #1
0
Image *rna_Main_images_load(Main *UNUSED(bmain), ReportList *reports, const char *filepath)
{
	Image *ima;

	errno= 0;
	ima= BKE_add_image_file(filepath);

	if(!ima)
		BKE_reportf(reports, RPT_ERROR, "Can't read: \"%s\", %s.", filepath, errno ? strerror(errno) : "Unsupported image format");

	return ima;
}
コード例 #2
0
ファイル: DocumentImporter.cpp プロジェクト: BHCLL/blendocv
/** When this method is called, the writer must write the image.
	@return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeImage( const COLLADAFW::Image* image ) 
{
	if(mImportStage!=General)
		return true;
		
	// XXX maybe it is necessary to check if the path is absolute or relative
	const std::string& filepath = image->getImageURI().toNativePath();
	const char *filename = (const char*)mFilename.c_str();
	char dir[FILE_MAX];
	char full_path[FILE_MAX];
	
	BLI_split_dirfile(filename, dir, NULL, sizeof(dir), 0);
	BLI_join_dirfile(full_path, sizeof(full_path), dir, filepath.c_str());
	Image *ima = BKE_add_image_file(full_path);
	if (!ima) {
		fprintf(stderr, "Cannot create image. \n");
		return true;
	}
	this->uid_image_map[image->getUniqueId()] = ima;
	
	return true;
}
コード例 #3
0
ファイル: mesh_data.c プロジェクト: rexbron/blender-ocio
static int drop_named_image_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
	Scene *scene= CTX_data_scene(C);
	View3D *v3d= CTX_wm_view3d(C);
	Base *base= ED_view3d_give_base_under_cursor(C, event->mval);
	Image *ima= NULL;
	Mesh *me;
	Object *obedit;
	int exitmode= 0;
	char name[32];
	
	/* Check context */
	if(base==NULL || base->object->type!=OB_MESH) {
		BKE_report(op->reports, RPT_ERROR, "Not an Object or Mesh");
		return OPERATOR_CANCELLED;
	}
	
	/* check input variables */
	if(RNA_property_is_set(op->ptr, "filepath")) {
		char path[FILE_MAX];
		
		RNA_string_get(op->ptr, "filepath", path);
		ima= BKE_add_image_file(path);
	}
	else {
		RNA_string_get(op->ptr, "name", name);
		ima= (Image *)find_id("IM", name);
	}
	
	if(!ima) {
		BKE_report(op->reports, RPT_ERROR, "Not an Image.");
		return OPERATOR_CANCELLED;
	}
	
	/* turn mesh in editmode */
	/* BKE_mesh_get/end_editmesh: ED_uvedit_assign_image also calls this */

	obedit= base->object;
	me= obedit->data;
	if(me->edit_mesh==NULL) {
		make_editMesh(scene, obedit);
		exitmode= 1;
	}
	if(me->edit_mesh==NULL)
		return OPERATOR_CANCELLED;
	
	ED_uvedit_assign_image(scene, obedit, ima, NULL);

	if(exitmode) {
		load_editMesh(scene, obedit);
		free_editMesh(me->edit_mesh);
		MEM_freeN(me->edit_mesh);
		me->edit_mesh= NULL;
	}

	/* dummie drop support; ensure view shows a result :) */
	if(v3d)
		v3d->flag2 |= V3D_SOLID_TEX;
	
	WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
	
	return OPERATOR_FINISHED;
}