コード例 #1
0
ファイル: font.c プロジェクト: JasonWilkins/blender-wayland
static VFontData *vfont_get_data(Main *bmain, VFont *vfont)
{
	if (vfont == NULL) {
		return NULL;
	}

	/* And then set the data */
	if (!vfont->data) {
		PackedFile *pf;

		if (BKE_vfont_is_builtin(vfont)) {
			pf = get_builtin_packedfile();
		}
		else {
			if (vfont->packedfile) {
				pf = vfont->packedfile;

				/* We need to copy a tmp font to memory unless it is already there */
				if (vfont->temp_pf == NULL) {
					vfont->temp_pf = dupPackedFile(pf);
				}
			}
			else {
				pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));

				if (vfont->temp_pf == NULL) {
					vfont->temp_pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));
				}
			}
			if (!pf) {
				printf("Font file doesn't exist: %s\n", vfont->name);

				/* DON'T DO THIS
				 * missing file shouldn't modifty path! - campbell */
#if 0
				strcpy(vfont->name, FO_BUILTIN_NAME);
#endif
				pf = get_builtin_packedfile();
			}
		}
		
		if (pf) {
			vfont->data = BLI_vfontdata_from_freetypefont(pf);
			if (pf != vfont->packedfile) {
				freePackedFile(pf);
			}
		}
	}
	
	return vfont->data;
}
コード例 #2
0
void packAll(Main *bmain, ReportList *reports)
{
	Image *ima;
	VFont *vf;
	bSound *sound;
	
	for (ima=bmain->image.first; ima; ima=ima->id.next) {
		if (ima->packedfile == NULL && ima->id.lib==NULL) { 
			if (ima->source==IMA_SRC_FILE) {
				ima->packedfile = newPackedFile(reports, ima->name, ID_BLEND_PATH(bmain, &ima->id));
			}
			else if (ELEM(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
				BKE_reportf(reports, RPT_WARNING, "Image '%s' skipped, movies and image sequences not supported.", ima->id.name+2);
			}
		}
	}

	for (vf=bmain->vfont.first; vf; vf=vf->id.next)
		if (vf->packedfile == NULL && vf->id.lib==NULL && strcmp(vf->name, FO_BUILTIN_NAME) != 0)
			vf->packedfile = newPackedFile(reports, vf->name, bmain->name);

	for (sound=bmain->sound.first; sound; sound=sound->id.next)
		if (sound->packedfile == NULL && sound->id.lib==NULL)
			sound->packedfile = newPackedFile(reports, sound->name, bmain->name);
}
コード例 #3
0
ファイル: sound.c プロジェクト: flair2005/mechanical-blender
bSound *BKE_sound_new_file_exists_ex(struct Main *bmain, const char *filepath, bool *r_exists)
{
	bSound *sound;
	char str[FILE_MAX], strtest[FILE_MAX];

	BLI_strncpy(str, filepath, sizeof(str));
	BLI_path_abs(str, bmain->name);

	/* first search an identical filepath */
	for (sound = bmain->sound.first; sound; sound = sound->id.next) {
		BLI_strncpy(strtest, sound->name, sizeof(sound->name));
		BLI_path_abs(strtest, ID_BLEND_PATH(bmain, &sound->id));

		if (BLI_path_cmp(strtest, str) == 0) {
			sound->id.us++;  /* officially should not, it doesn't link here! */
			if (r_exists)
				*r_exists = true;
			return sound;
		}
	}

	if (r_exists)
		*r_exists = false;
	return BKE_sound_new_file(bmain, filepath);
}
コード例 #4
0
ファイル: rna_image_api.c プロジェクト: bitfusionio/blender
static void rna_Image_pack(
        Image *image, Main *bmain, bContext *C, ReportList *reports,
        int as_png, const char *data, int data_len)
{
	ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);

	if (!as_png && (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))) {
		BKE_report(reports, RPT_ERROR, "Cannot pack edited image from disk, only as internal PNG");
	}
	else {
		BKE_image_free_packedfiles(image);
		if (as_png) {
			BKE_image_memorypack(image);
		}
		else if (data) {
			char *data_dup = MEM_mallocN(sizeof(*data_dup) * (size_t)data_len, __func__);
			memcpy(data_dup, data, (size_t)data_len);
			BKE_image_packfiles_from_mem(reports, image, data_dup, (size_t)data_len);
		}
		else {
			BKE_image_packfiles(reports, image, ID_BLEND_PATH(bmain, &image->id));
		}
	}

	BKE_image_release_ibuf(image, ibuf, NULL);
	WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, image);
}
コード例 #5
0
ファイル: rna_image_api.c プロジェクト: pawkoz/dyplom
static void rna_Image_save(Image *image, Main *bmain, bContext *C, ReportList *reports)
{
	ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
	if (ibuf) {
		char filename[FILE_MAX];
		BLI_strncpy(filename, image->name, sizeof(filename));
		BLI_path_abs(filename, ID_BLEND_PATH(bmain, &image->id));

		/* note, we purposefully ignore packed files here,
		 * developers need to explicitly write them via 'packed_files' */

		if (IMB_saveiff(ibuf, filename, ibuf->flags)) {
			image->type = IMA_TYPE_IMAGE;

			if (image->source == IMA_SRC_GENERATED)
				image->source = IMA_SRC_FILE;

			IMB_colormanagment_colorspace_from_ibuf_ftype(&image->colorspace_settings, ibuf);

			ibuf->userflags &= ~IB_BITMAPDIRTY;
		}
		else {
			BKE_reportf(reports, RPT_ERROR, "Image '%s' could not be saved to '%s'", image->id.name + 2, image->name);
		}
	}
	else {
		BKE_reportf(reports, RPT_ERROR, "Image '%s' does not have any image data", image->id.name + 2);
	}

	BKE_image_release_ibuf(image, ibuf, NULL);
	WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, image);
}
コード例 #6
0
ファイル: buttons_ops.c プロジェクト: Eibriel/kiriblender
static int file_browse_exec(bContext *C, wmOperator *op)
{
	FileBrowseOp *fbo = op->customdata;
	ID *id;
	char *str, path[FILE_MAX];
	const char *path_prop = RNA_struct_find_property(op->ptr, "directory") ? "directory" : "filepath";
	
	if (RNA_struct_property_is_set(op->ptr, path_prop) == 0 || fbo == NULL)
		return OPERATOR_CANCELLED;
	
	str = RNA_string_get_alloc(op->ptr, path_prop, NULL, 0);

	/* add slash for directories, important for some properties */
	if (RNA_property_subtype(fbo->prop) == PROP_DIRPATH) {
		int is_relative = RNA_boolean_get(op->ptr, "relative_path");
		id = fbo->ptr.id.data;

		BLI_strncpy(path, str, FILE_MAX);
		BLI_path_abs(path, id ? ID_BLEND_PATH(G.main, id) : G.main->name);
		
		if (BLI_is_dir(path)) {
			/* do this first so '//' isnt converted to '//\' on windows */
			BLI_add_slash(path);
			if (is_relative) {
				BLI_strncpy(path, str, FILE_MAX);
				BLI_path_rel(path, G.main->name);
				str = MEM_reallocN(str, strlen(path) + 2);
				BLI_strncpy(str, path, FILE_MAX);
			}
			else {
				str = MEM_reallocN(str, strlen(str) + 2);
			}
		}
		else {
			char * const lslash = (char *)BLI_last_slash(str);
			if (lslash) lslash[1] = '\0';
		}
	}

	RNA_property_string_set(&fbo->ptr, fbo->prop, str);
	RNA_property_update(C, &fbo->ptr, fbo->prop);
	MEM_freeN(str);


	/* special, annoying exception, filesel on redo panel [#26618] */
	{
		wmOperator *redo_op = WM_operator_last_redo(C);
		if (redo_op) {
			if (fbo->ptr.data == redo_op->ptr->data) {
				ED_undo_operator_repeat(C, redo_op);
			}
		}
	}

	MEM_freeN(op->customdata);

	return OPERATOR_FINISHED;
}
コード例 #7
0
ファイル: modifier.c プロジェクト: nttputus/blensor
/* campbell: logic behind this...
 *
 * - if the ID is from a library, return library path
 * - else if the file has been saved return the blend file path.
 * - else if the file isn't saved and the ID isn't from a library, return the temp dir.
 */
const char *modifier_path_relbase(Object *ob)
{
    if (G.relbase_valid || ob->id.lib) {
        return ID_BLEND_PATH(G.main, &ob->id);
    }
    else {
        /* last resort, better then using "" which resolves to the current
         * working directory */
        return BLI_temporary_dir();
    }
}
コード例 #8
0
ファイル: cachefile.c プロジェクト: mgschwan/blensor
void BKE_cachefile_reload(const Main *bmain, CacheFile *cache_file)
{
	char filepath[FILE_MAX];

	BLI_strncpy(filepath, cache_file->filepath, sizeof(filepath));
	BLI_path_abs(filepath, ID_BLEND_PATH(bmain, &cache_file->id));

#ifdef WITH_ALEMBIC
	if (cache_file->handle) {
		ABC_free_handle(cache_file->handle);
	}

	cache_file->handle = ABC_create_handle(filepath, &cache_file->object_paths);
#endif
}
コード例 #9
0
ファイル: rna_image_api.c プロジェクト: Walid-Shouman/Blender
static void rna_Image_pack(Image *image, ReportList *reports, int as_png)
{
	ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);

	if (!as_png && (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))) {
		BKE_report(reports, RPT_ERROR, "Cannot pack edited image from disk, only as internal PNG");
	}
	else {
		if (as_png) {
			BKE_image_memorypack(image);
		}
		else {
			image->packedfile = newPackedFile(reports, image->name, ID_BLEND_PATH(G.main, &image->id));
		}
	}

	BKE_image_release_ibuf(image, ibuf, NULL);
}
コード例 #10
0
ファイル: movieclip.c プロジェクト: nttputus/blensor
static void get_sequence_fname(MovieClip *clip, int framenr, char *name)
{
    unsigned short numlen;
    char head[FILE_MAX], tail[FILE_MAX];
    int offset;

    BLI_strncpy(name, clip->name, sizeof(clip->name));
    BLI_stringdec(name, head, tail, &numlen);

    /* movieclips always points to first image from sequence,
     * autoguess offset for now. could be something smarter in the future */
    offset = sequence_guess_offset(clip->name, strlen(head), numlen);

    if (numlen)
        BLI_stringenc(name, head, tail, numlen, offset + framenr - 1);
    else
        BLI_strncpy(name, clip->name, sizeof(clip->name));

    BLI_path_abs(name, ID_BLEND_PATH(G.main, &clip->id));
}
コード例 #11
0
ファイル: packedFile.c プロジェクト: Bforartists/Bforartists
/* no libraries for now */
void packAll(Main *bmain, ReportList *reports, bool verbose)
{
	Image *ima;
	VFont *vfont;
	bSound *sound;
	int tot = 0;
	
	for (ima = bmain->image.first; ima; ima = ima->id.next) {
		if (BKE_image_has_packedfile(ima) == false && ima->id.lib == NULL) {
			if (ima->source == IMA_SRC_FILE) {
				BKE_image_packfiles(reports, ima, ID_BLEND_PATH(bmain, &ima->id));
				tot ++;
			}
			else if (BKE_image_is_animated(ima) && verbose) {
				BKE_reportf(reports, RPT_WARNING, "Image '%s' skipped, movies and image sequences not supported",
				            ima->id.name + 2);
			}
		}
	}

	for (vfont = bmain->vfont.first; vfont; vfont = vfont->id.next) {
		if (vfont->packedfile == NULL && vfont->id.lib == NULL && BKE_vfont_is_builtin(vfont) == false) {
			vfont->packedfile = newPackedFile(reports, vfont->name, bmain->name);
			tot ++;
		}
	}

	for (sound = bmain->sound.first; sound; sound = sound->id.next) {
		if (sound->packedfile == NULL && sound->id.lib == NULL) {
			sound->packedfile = newPackedFile(reports, sound->name, bmain->name);
			tot++;
		}
	}
	
	if (tot > 0)
		BKE_reportf(reports, RPT_INFO, "Packed %d files", tot);
	else if (verbose)
		BKE_report(reports, RPT_INFO, "No new files have been packed");


}
コード例 #12
0
ファイル: movieclip.c プロジェクト: Walid-Shouman/Blender
static void movieclip_open_anim_file(MovieClip *clip)
{
	char str[FILE_MAX];

	if (!clip->anim) {
		BLI_strncpy(str, clip->name, FILE_MAX);
		BLI_path_abs(str, ID_BLEND_PATH(G.main, &clip->id));

		/* FIXME: make several stream accessible in image editor, too */
		clip->anim = openanim(str, IB_rect, 0, clip->colorspace_settings.name);

		if (clip->anim) {
			if (clip->flag & MCLIP_USE_PROXY_CUSTOM_DIR) {
				char dir[FILE_MAX];
				BLI_strncpy(dir, clip->proxy.dir, sizeof(dir));
				BLI_path_abs(dir, G.main->name);
				IMB_anim_set_index_dir(clip->anim, dir);
			}
		}
	}
}
コード例 #13
0
ファイル: rna_image_api.c プロジェクト: bitfusionio/blender
static void rna_Image_save(Image *image, Main *bmain, bContext *C, ReportList *reports)
{
	ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
	if (ibuf) {
		char filename[FILE_MAX];
		BLI_strncpy(filename, image->name, sizeof(filename));
		BLI_path_abs(filename, ID_BLEND_PATH(bmain, &image->id));

		if (BKE_image_has_packedfile(image)) {
			ImagePackedFile *imapf;

			for (imapf = image->packedfiles.first; imapf; imapf = imapf->next) {
				if (writePackedFile(reports, imapf->filepath, imapf->packedfile, 0) != RET_OK) {
					BKE_reportf(reports, RPT_ERROR, "Image '%s' could not save packed file to '%s'",
					            image->id.name + 2, imapf->filepath);
				}
			}
		}
		else if (IMB_saveiff(ibuf, filename, ibuf->flags)) {
			image->type = IMA_TYPE_IMAGE;

			if (image->source == IMA_SRC_GENERATED)
				image->source = IMA_SRC_FILE;

			IMB_colormanagment_colorspace_from_ibuf_ftype(&image->colorspace_settings, ibuf);

			ibuf->userflags &= ~IB_BITMAPDIRTY;
		}
		else {
			BKE_reportf(reports, RPT_ERROR, "Image '%s' could not be saved to '%s'", image->id.name + 2, image->name);
		}
	}
	else {
		BKE_reportf(reports, RPT_ERROR, "Image '%s' does not have any image data", image->id.name + 2);
	}

	BKE_image_release_ibuf(image, ibuf, NULL);
	WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, image);
}
コード例 #14
0
ファイル: cachefile.c プロジェクト: mgschwan/blensor
bool BKE_cachefile_filepath_get(
        const Main *bmain, const CacheFile *cache_file, float frame,
        char r_filepath[FILE_MAX])
{
	BLI_strncpy(r_filepath, cache_file->filepath, FILE_MAX);
	BLI_path_abs(r_filepath, ID_BLEND_PATH(bmain, &cache_file->id));

	int fframe;
	int frame_len;

	if (cache_file->is_sequence && BLI_path_frame_get(r_filepath, &fframe, &frame_len)) {
		char ext[32];
		BLI_path_frame_strip(r_filepath, true, ext);
		BLI_path_frame(r_filepath, frame, frame_len);
		BLI_ensure_extension(r_filepath, FILE_MAX, ext);

		/* TODO(kevin): store sequence range? */
		return BLI_exists(r_filepath);
	}

	return true;
}
コード例 #15
0
ファイル: sound.c プロジェクト: flair2005/mechanical-blender
void BKE_sound_load(struct Main *bmain, bSound *sound)
{
	if (sound) {
		if (sound->cache) {
			AUD_Sound_free(sound->cache);
			sound->cache = NULL;
		}

		if (sound->handle) {
			AUD_Sound_free(sound->handle);
			sound->handle = NULL;
			sound->playback_handle = NULL;
		}

		BKE_sound_free_waveform(sound);

/* XXX unused currently */
#if 0
		switch (sound->type)
		{
			case SOUND_TYPE_FILE:
#endif
		{
			char fullpath[FILE_MAX];

			/* load sound */
			PackedFile *pf = sound->packedfile;

			/* don't modify soundact->sound->name, only change a copy */
			BLI_strncpy(fullpath, sound->name, sizeof(fullpath));
			BLI_path_abs(fullpath, ID_BLEND_PATH(bmain, &sound->id));

			/* but we need a packed file then */
			if (pf)
				sound->handle = AUD_Sound_bufferFile((unsigned char *) pf->data, pf->size);
			/* or else load it from disk */
			else
				sound->handle = AUD_Sound_file(fullpath);
		}
/* XXX unused currently */
#if 0
			break;
		}
		case SOUND_TYPE_BUFFER:
			if (sound->child_sound && sound->child_sound->handle)
				sound->handle = AUD_bufferSound(sound->child_sound->handle);
			break;
		case SOUND_TYPE_LIMITER:
			if (sound->child_sound && sound->child_sound->handle)
				sound->handle = AUD_limitSound(sound->child_sound, sound->start, sound->end);
			break;
	}
#endif
		if (sound->flags & SOUND_FLAGS_MONO) {
			void *handle = AUD_Sound_rechannel(sound->handle, AUD_CHANNELS_MONO);
			AUD_Sound_free(sound->handle);
			sound->handle = handle;
		}

		if (sound->flags & SOUND_FLAGS_CACHING) {
			sound->cache = AUD_Sound_cache(sound->handle);
		}

		if (sound->cache)
			sound->playback_handle = sound->cache;
		else
			sound->playback_handle = sound->handle;

		BKE_sound_update_sequencer(bmain, sound);
	}
コード例 #16
0
static VFontData *vfont_get_data(Main *bmain, VFont *vfont)
{
	struct TmpFont *tmpfnt = NULL;
	PackedFile *tpf;
	
	if (vfont==NULL) return NULL;
	
	// Try finding the font from font list
	tmpfnt = vfont_find_tmpfont(vfont);
	
	// And then set the data	
	if (!vfont->data) {
		PackedFile *pf;
		
		if (strcmp(vfont->name, FO_BUILTIN_NAME)==0) {
			pf= get_builtin_packedfile();
		}
		else {
			if (vfont->packedfile) {
				pf= vfont->packedfile;
				
				// We need to copy a tmp font to memory unless it is already there
				if (!tmpfnt) {
					tpf= MEM_callocN(sizeof(*tpf), "PackedFile");
					tpf->data= MEM_mallocN(pf->size, "packFile");
					tpf->size= pf->size;
					memcpy(tpf->data, pf->data, pf->size);
					
					// Add temporary packed file to globals
					tmpfnt= (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font");
					tmpfnt->pf= tpf;
					tmpfnt->vfont= vfont;
					BLI_addtail(&ttfdata, tmpfnt);
				}
			}
			else {
				pf= newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));

				if (!tmpfnt) {
					tpf= newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));
					
					// Add temporary packed file to globals
					tmpfnt= (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font");
					tmpfnt->pf= tpf;
					tmpfnt->vfont= vfont;
					BLI_addtail(&ttfdata, tmpfnt);
				}
			}
			if (!pf) {
				printf("Font file doesn't exist: %s\n", vfont->name);

				strcpy(vfont->name, FO_BUILTIN_NAME);
				pf= get_builtin_packedfile();
			}
		}
		
		if (pf) {
			vfont->data= BLI_vfontdata_from_freetypefont(pf);
			if (pf != vfont->packedfile) {
				freePackedFile(pf);
			}
		}
	}
	
	return vfont->data;	
}
コード例 #17
0
ファイル: bpy_internal_import.c プロジェクト: 244xiao/blender
/* returns a dummy filename for a textblock so we can tell what file a text block comes from */
void bpy_text_filename_get(char *fn, size_t fn_len, Text *text)
{
	BLI_snprintf(fn, fn_len, "%s%c%s", ID_BLEND_PATH(bpy_import_main, &text->id), SEP, text->id.name + 2);
}
コード例 #18
0
static void meshcache_do(
        MeshCacheModifierData *mcmd, Object *ob, DerivedMesh *UNUSED(dm),
        float (*vertexCos_Real)[3], int numVerts)
{
	const bool use_factor = mcmd->factor < 1.0f;
	float (*vertexCos_Store)[3] = (use_factor || (mcmd->deform_mode == MOD_MESHCACHE_DEFORM_INTEGRATE)) ?
	                              MEM_mallocN(sizeof(*vertexCos_Store) * numVerts, __func__) : NULL;
	float (*vertexCos)[3] = vertexCos_Store ? vertexCos_Store : vertexCos_Real;

	Scene *scene = mcmd->modifier.scene;
	const float fps = FPS;

	char filepath[FILE_MAX];
	const char *err_str = NULL;
	bool ok;

	float time;


	/* -------------------------------------------------------------------- */
	/* Interpret Time (the reading functions also do some of this ) */
	if (mcmd->play_mode == MOD_MESHCACHE_PLAY_CFEA) {
		const float cfra = BKE_scene_frame_get(scene);

		switch (mcmd->time_mode) {
			case MOD_MESHCACHE_TIME_FRAME:
			{
				time = cfra;
				break;
			}
			case MOD_MESHCACHE_TIME_SECONDS:
			{
				time = cfra / fps;
				break;
			}
			case MOD_MESHCACHE_TIME_FACTOR:
			default:
			{
				time = cfra / fps;
				break;
			}
		}

		/* apply offset and scale */
		time = (mcmd->frame_scale * time) - mcmd->frame_start;
	}
	else {  /*  if (mcmd->play_mode == MOD_MESHCACHE_PLAY_EVAL) { */
		switch (mcmd->time_mode) {
			case MOD_MESHCACHE_TIME_FRAME:
			{
				time = mcmd->eval_frame;
				break;
			}
			case MOD_MESHCACHE_TIME_SECONDS:
			{
				time = mcmd->eval_time;
				break;
			}
			case MOD_MESHCACHE_TIME_FACTOR:
			default:
			{
				time = mcmd->eval_factor;
				break;
			}
		}
	}


	/* -------------------------------------------------------------------- */
	/* Read the File (or error out when the file is bad) */

	/* would be nice if we could avoid doing this _every_ frame */
	BLI_strncpy(filepath, mcmd->filepath, sizeof(filepath));
	BLI_path_abs(filepath, ID_BLEND_PATH(G.main, (ID *)ob));

	switch (mcmd->type) {
		case MOD_MESHCACHE_TYPE_MDD:
			ok = MOD_meshcache_read_mdd_times(filepath, vertexCos, numVerts,
			                                  mcmd->interp, time, fps, mcmd->time_mode, &err_str);
			break;
		case MOD_MESHCACHE_TYPE_PC2:
			ok = MOD_meshcache_read_pc2_times(filepath, vertexCos, numVerts,
			                                  mcmd->interp, time, fps, mcmd->time_mode, &err_str);
			break;
		default:
			ok = false;
			break;
	}


	/* -------------------------------------------------------------------- */
	/* tricky shape key integration (slow!) */
	if (mcmd->deform_mode == MOD_MESHCACHE_DEFORM_INTEGRATE) {
		Mesh *me = ob->data;

		/* we could support any object type */
		if (UNLIKELY(ob->type != OB_MESH)) {
			modifier_setError(&mcmd->modifier, "'Integrate' only valid for Mesh objects");
		}
		else if (UNLIKELY(me->totvert != numVerts)) {
			modifier_setError(&mcmd->modifier, "'Integrate' original mesh vertex mismatch");
		}
		else if (UNLIKELY(me->totpoly == 0)) {
			modifier_setError(&mcmd->modifier, "'Integrate' requires faces");
		}
		else {
			/* the moons align! */
			int i;

			float (*vertexCos_Source)[3] = MEM_mallocN(sizeof(*vertexCos_Source) * numVerts, __func__);
			float (*vertexCos_New)[3]    = MEM_mallocN(sizeof(*vertexCos_New) * numVerts, __func__);
			MVert *mv = me->mvert;

			for (i = 0; i < numVerts; i++, mv++) {
				copy_v3_v3(vertexCos_Source[i], mv->co);
			}

			BKE_mesh_calc_relative_deform(
			        me->mpoly, me->totpoly,
			        me->mloop, me->totvert,

			        (const float (*)[3])vertexCos_Source,   /* from the original Mesh*/
			        (const float (*)[3])vertexCos_Real,     /* the input we've been given (shape keys!) */

			        (const float (*)[3])vertexCos,          /* the result of this modifier */
			        vertexCos_New                           /* the result of this function */
			        );

			/* write the corrected locations back into the result */
			memcpy(vertexCos, vertexCos_New, sizeof(*vertexCos) * numVerts);

			MEM_freeN(vertexCos_Source);
			MEM_freeN(vertexCos_New);
		}
	}


	/* -------------------------------------------------------------------- */
	/* Apply the transformation matrix (if needed) */
	if (UNLIKELY(err_str)) {
		modifier_setError(&mcmd->modifier, "%s", err_str);
	}
	else if (ok) {
		bool use_matrix = false;
		float mat[3][3];
		unit_m3(mat);

		if (mat3_from_axis_conversion(mcmd->forward_axis, mcmd->up_axis, 1, 2, mat)) {
			use_matrix = true;
		}

		if (mcmd->flip_axis) {
			float tmat[3][3];
			unit_m3(tmat);
			if (mcmd->flip_axis & (1 << 0)) tmat[0][0] = -1.0f;
			if (mcmd->flip_axis & (1 << 1)) tmat[1][1] = -1.0f;
			if (mcmd->flip_axis & (1 << 2)) tmat[2][2] = -1.0f;
			mul_m3_m3m3(mat, tmat, mat);

			use_matrix = true;
		}

		if (use_matrix) {
			int i;
			for (i = 0; i < numVerts; i++) {
				mul_m3_v3(mat, vertexCos[i]);
			}
		}
	}

	if (vertexCos_Store) {
		if (ok) {
			if (use_factor) {
				interp_vn_vn(*vertexCos_Real, *vertexCos_Store, mcmd->factor, numVerts * 3);
			}
			else {
				memcpy(vertexCos_Real, vertexCos_Store, sizeof(*vertexCos_Store) * numVerts);
			}
		}

		MEM_freeN(vertexCos_Store);
	}
}
コード例 #19
0
ファイル: font.c プロジェクト: Eibriel/kiriblender
static VFontData *vfont_get_data(Main *bmain, VFont *vfont)
{
	if (vfont == NULL) {
		return NULL;
	}

	/* And then set the data */
	if (!vfont->data) {
		PackedFile *pf;

		BLI_mutex_lock(&vfont_mutex);

		if (vfont->data) {
			/* Check data again, since it might have been already
			 * initialized from other thread (previous check is
			 * not accurate or threading, just prevents unneeded
			 * lock if all the data is here for sure).
			 */
			BLI_mutex_unlock(&vfont_mutex);
			return vfont->data;
		}

		if (BKE_vfont_is_builtin(vfont)) {
			pf = get_builtin_packedfile();
		}
		else {
			if (vfont->packedfile) {
				pf = vfont->packedfile;

				/* We need to copy a tmp font to memory unless it is already there */
				if (vfont->temp_pf == NULL) {
					vfont->temp_pf = dupPackedFile(pf);
				}
			}
			else {
				pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));

				if (vfont->temp_pf == NULL) {
					vfont->temp_pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));
				}
			}
			if (!pf) {
				printf("Font file doesn't exist: %s\n", vfont->name);

				/* DON'T DO THIS
				 * missing file shouldn't modifty path! - campbell */
#if 0
				strcpy(vfont->name, FO_BUILTIN_NAME);
#endif
				pf = get_builtin_packedfile();
			}
		}
		
		if (pf) {
			vfont->data = BLI_vfontdata_from_freetypefont(pf);
			if (pf != vfont->packedfile) {
				freePackedFile(pf);
			}
		}

		BLI_mutex_unlock(&vfont_mutex);
	}

	return vfont->data;
}