diff options
author | Matt Ebb <matt@mke3.net> | 2009-08-19 15:18:52 +0400 |
---|---|---|
committer | Matt Ebb <matt@mke3.net> | 2009-08-19 15:18:52 +0400 |
commit | 132277f0989b0b7d99d883d22a2bade6534ae44c (patch) | |
tree | 6d26c46f62749470130375061381353fd54c2364 /source/blender/blenkernel | |
parent | 8480ea2b0abacae00c90d37e7d99fa5e0c89eebe (diff) | |
parent | e611c4756fa17c57855123dc2b5c2c2408b0d790 (diff) |
svn merge -r 22450:22627 https://svn.blender.org/svnroot/bf-blender/branches/blender2.5/blender
Diffstat (limited to 'source/blender/blenkernel')
39 files changed, 1196 insertions, 371 deletions
diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h index 2447d1823af..cabbaa7aa0f 100644 --- a/source/blender/blenkernel/BKE_animsys.h +++ b/source/blender/blenkernel/BKE_animsys.h @@ -66,6 +66,9 @@ void BKE_keyingset_add_destination(struct KeyingSet *ks, struct ID *id, const ch struct KS_Path *BKE_keyingset_find_destination(struct KeyingSet *ks, struct ID *id, const char group_name[], const char rna_path[], int array_index, int group_mode); +/* Copy all KeyingSets in the given list */ +void BKE_keyingsets_copy(struct ListBase *newlist, struct ListBase *list); + /* Free data for KeyingSet but not set itself */ void BKE_keyingset_free(struct KeyingSet *ks); diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index 19b9c315939..42ee11587a7 100644 --- a/source/blender/blenkernel/BKE_blender.h +++ b/source/blender/blenkernel/BKE_blender.h @@ -43,7 +43,7 @@ struct bContext; struct ReportList; #define BLENDER_VERSION 250 -#define BLENDER_SUBVERSION 0 +#define BLENDER_SUBVERSION 2 #define BLENDER_MINVERSION 250 #define BLENDER_MINSUBVERSION 0 diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h index 9eb0b15aed4..6ec988e111e 100644 --- a/source/blender/blenkernel/BKE_brush.h +++ b/source/blender/blenkernel/BKE_brush.h @@ -38,16 +38,15 @@ struct Scene; struct wmOperator; /* datablock functions */ -struct Brush *add_brush(char *name); +struct Brush *add_brush(const char *name); struct Brush *copy_brush(struct Brush *brush); void make_local_brush(struct Brush *brush); void free_brush(struct Brush *brush); /* brush library operations used by different paint panels */ -struct Brush **current_brush_source(struct Scene *sce); -int brush_set_nr(struct Brush **current_brush, int nr); +int brush_set_nr(struct Brush **current_brush, int nr, const char *name); int brush_delete(struct Brush **current_brush); -void brush_check_exists(struct Brush **brush); +void brush_check_exists(struct Brush **brush, const char *name); void brush_toggled_fake_user(struct Brush *brush); int brush_texture_set_nr(struct Brush *brush, int nr); int brush_texture_delete(struct Brush *brush); diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h index e47ad969b91..09e13c2930e 100644 --- a/source/blender/blenkernel/BKE_context.h +++ b/source/blender/blenkernel/BKE_context.h @@ -86,6 +86,25 @@ typedef struct bContextStore { int used; } bContextStore; +/* for the conrtext's rna mode enum + * keep aligned with data_mode_strings in context.c */ +enum { + CTX_MODE_EDIT_MESH = 0, + CTX_MODE_EDIT_CURVE, + CTX_MODE_EDIT_SURFACE, + CTX_MODE_EDIT_TEXT, + CTX_MODE_EDIT_ARMATURE, + CTX_MODE_EDIT_METABALL, + CTX_MODE_EDIT_LATTICE, + CTX_MODE_POSE, + CTX_MODE_SCULPT, + CTX_MODE_PAINT_WEIGHT, + CTX_MODE_PAINT_VERTEX, + CTX_MODE_PAINT_TEXTURE, + CTX_MODE_PARTICLE, + CTX_MODE_OBJECT +}; + /* Context */ bContext *CTX_create(void); @@ -133,6 +152,7 @@ struct SpaceLogic *CTX_wm_space_logic(const bContext *C); struct SpaceIpo *CTX_wm_space_graph(const bContext *C); struct SpaceAction *CTX_wm_space_action(const bContext *C); struct SpaceInfo *CTX_wm_space_info(const bContext *C); +struct SpaceUserPref *CTX_wm_space_userpref(const bContext *C); void CTX_wm_manager_set(bContext *C, struct wmWindowManager *wm); void CTX_wm_window_set(bContext *C, struct wmWindow *win); @@ -191,6 +211,9 @@ struct Main *CTX_data_main(const bContext *C); struct Scene *CTX_data_scene(const bContext *C); struct ToolSettings *CTX_data_tool_settings(const bContext *C); +char *CTX_data_mode_string(const bContext *C); +int CTX_data_mode_enum(const bContext *C); + void CTX_data_main_set(bContext *C, struct Main *bmain); void CTX_data_scene_set(bContext *C, struct Scene *bmain); diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h index 315fe2a39cb..6323258ff43 100644 --- a/source/blender/blenkernel/BKE_global.h +++ b/source/blender/blenkernel/BKE_global.h @@ -112,52 +112,40 @@ typedef struct Global { #define G_FACESELECT (1 << 8) -#define G_VERTEXPAINT (1 << 10) - #define G_DEBUG (1 << 12) #define G_DOSCRIPTLINKS (1 << 13) -#define G_WEIGHTPAINT (1 << 15) -#define G_TEXTUREPAINT (1 << 16) /* #define G_NOFROZEN (1 << 17) also removed */ #define G_GREASEPENCIL (1 << 17) -#define G_SCULPTMODE (1 << 29) -#define G_PARTICLEEDIT (1 << 30) - /* #define G_AUTOMATKEYS (1 << 30) also removed */ #define G_HIDDENHANDLES (1 << 31) /* used for curves only */ -/* macro for testing face select mode - * Texture paint could be removed since selected faces are not used - * however hiding faces is useful */ -#define FACESEL_PAINT_TEST ((G.f&G_FACESELECT) && (G.f & (G_VERTEXPAINT|G_WEIGHTPAINT|G_TEXTUREPAINT))) - /* G.fileflags */ #define G_AUTOPACK (1 << 0) #define G_FILE_COMPRESS (1 << 1) #define G_FILE_AUTOPLAY (1 << 2) -#define G_FILE_ENABLE_ALL_FRAMES (1 << 3) -#define G_FILE_SHOW_DEBUG_PROPS (1 << 4) -#define G_FILE_SHOW_FRAMERATE (1 << 5) -#define G_FILE_SHOW_PROFILE (1 << 6) +#define G_FILE_ENABLE_ALL_FRAMES (1 << 3) /* deprecated */ +#define G_FILE_SHOW_DEBUG_PROPS (1 << 4) /* deprecated */ +#define G_FILE_SHOW_FRAMERATE (1 << 5) /* deprecated */ +#define G_FILE_SHOW_PROFILE (1 << 6) /* deprecated */ #define G_FILE_LOCK (1 << 7) #define G_FILE_SIGN (1 << 8) #define G_FIle_PUBLISH (1 << 9) #define G_FILE_NO_UI (1 << 10) -#define G_FILE_GAME_TO_IPO (1 << 11) -#define G_FILE_GAME_MAT (1 << 12) -#define G_FILE_DISPLAY_LISTS (1 << 13) -#define G_FILE_SHOW_PHYSICS (1 << 14) -#define G_FILE_GAME_MAT_GLSL (1 << 15) -#define G_FILE_GLSL_NO_LIGHTS (1 << 16) -#define G_FILE_GLSL_NO_SHADERS (1 << 17) -#define G_FILE_GLSL_NO_SHADOWS (1 << 18) -#define G_FILE_GLSL_NO_RAMPS (1 << 19) -#define G_FILE_GLSL_NO_NODES (1 << 20) -#define G_FILE_GLSL_NO_EXTRA_TEX (1 << 21) -#define G_FILE_IGNORE_DEPRECATION_WARNINGS (1 << 22) +#define G_FILE_GAME_TO_IPO (1 << 11) /* deprecated */ +#define G_FILE_GAME_MAT (1 << 12) /* deprecated */ +#define G_FILE_DISPLAY_LISTS (1 << 13) /* deprecated */ +#define G_FILE_SHOW_PHYSICS (1 << 14) /* deprecated */ +#define G_FILE_GAME_MAT_GLSL (1 << 15) /* deprecated */ +#define G_FILE_GLSL_NO_LIGHTS (1 << 16) /* deprecated */ +#define G_FILE_GLSL_NO_SHADERS (1 << 17) /* deprecated */ +#define G_FILE_GLSL_NO_SHADOWS (1 << 18) /* deprecated */ +#define G_FILE_GLSL_NO_RAMPS (1 << 19) /* deprecated */ +#define G_FILE_GLSL_NO_NODES (1 << 20) /* deprecated */ +#define G_FILE_GLSL_NO_EXTRA_TEX (1 << 21) /* deprecated */ +#define G_FILE_IGNORE_DEPRECATION_WARNINGS (1 << 22) /* deprecated */ /* G.windowstate */ #define G_WINDOWSTATE_USERDEF 0 diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 87ee8f9cab3..4ac95b61a5e 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -47,6 +47,7 @@ struct rctf; struct ListBase; struct RenderData; struct Scene; +struct Main; struct Tex; struct GPUMaterial; struct GPUNode; @@ -421,7 +422,7 @@ extern struct ListBase node_all_textures; /* API */ int ntreeTexTagAnimated(struct bNodeTree *ntree); void ntreeTexUpdatePreviews( struct bNodeTree* nodetree ); -void ntreeTexExecTree(struct bNodeTree *ntree, struct TexResult *target, float *coord, char do_preview, short thread, struct Tex *tex, short which_output, int cfra); +void ntreeTexExecTree(struct bNodeTree *ntree, struct TexResult *target, float *coord, float *dxt, float *dyt, char do_preview, short thread, struct Tex *tex, short which_output, int cfra); void ntreeTexCheckCyclics(struct bNodeTree *ntree); void ntreeTexAssignIndex(struct bNodeTree *ntree, struct bNode *node); char* ntreeTexOutputMenu(struct bNodeTree *ntree); @@ -432,4 +433,8 @@ char* ntreeTexOutputMenu(struct bNodeTree *ntree); void init_nodesystem(void); void free_nodesystem(void); +/**/ + +void clear_scene_in_nodes(struct Main *bmain, struct Scene *sce); + #endif diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h new file mode 100644 index 00000000000..67b260b2348 --- /dev/null +++ b/source/blender/blenkernel/BKE_paint.h @@ -0,0 +1,51 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009 by Nicholas Bishop + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef BKE_PAINT_H +#define BKE_PAINT_H + +struct Brush; +struct Object; +struct Paint; +struct Scene; + +void paint_init(struct Paint *p, const char *brush_name); +void free_paint(struct Paint *p); +void copy_paint(struct Paint *orig, struct Paint *new); + +struct Paint *paint_get_active(struct Scene *sce); +struct Brush *paint_brush(struct Paint *paint); +void paint_brush_set(struct Paint *paint, struct Brush *br); +void paint_brush_slot_add(struct Paint *p); +void paint_brush_slot_remove(struct Paint *p); + +/* testing face select mode + * Texture paint could be removed since selected faces are not used + * however hiding faces is useful */ +int paint_facesel_test(struct Object *ob); + +#endif diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h index b83afb6b28f..5d9dddfe30d 100644 --- a/source/blender/blenkernel/BKE_pointcache.h +++ b/source/blender/blenkernel/BKE_pointcache.h @@ -57,9 +57,11 @@ #define PTCACHE_FILE_WRITE 1 /* PTCacheID types */ -#define PTCACHE_TYPE_SOFTBODY 0 -#define PTCACHE_TYPE_PARTICLES 1 -#define PTCACHE_TYPE_CLOTH 2 +#define PTCACHE_TYPE_SOFTBODY 0 +#define PTCACHE_TYPE_PARTICLES 1 +#define PTCACHE_TYPE_CLOTH 2 +#define PTCACHE_TYPE_SMOKE_DOMAIN_LOW 3 +#define PTCACHE_TYPE_SMOKE_DOMAIN_HIGH 4 /* PTCache read return code */ #define PTCACHE_READ_EXACT 1 @@ -73,6 +75,7 @@ struct SoftBody; struct ParticleSystem; struct ParticleKey; struct ClothModifierData; +struct SmokeModifierData; struct PointCache; struct ListBase; @@ -112,8 +115,12 @@ typedef struct PTCacheID { /* copies point data to cache data */ int (*write_elem)(int index, void *calldata, void **data); + /* copies point data to cache data */ + int (*write_stream)(PTCacheFile *pf, void *calldata); /* copies cache cata to point data */ void (*read_elem)(int index, void *calldata, void **data, float frs_sec, float cfra, float *old_data); + /* copies cache cata to point data */ + void (*read_stream)(PTCacheFile *pf, void *calldata); /* interpolated between previously read point data and cache data */ void (*interpolate_elem)(int index, void *calldata, void **data, float frs_sec, float cfra, float cfra1, float cfra2, float *old_data); @@ -151,6 +158,7 @@ void BKE_ptcache_make_particle_key(struct ParticleKey *key, int index, void **da void BKE_ptcache_id_from_softbody(PTCacheID *pid, struct Object *ob, struct SoftBody *sb); void BKE_ptcache_id_from_particles(PTCacheID *pid, struct Object *ob, struct ParticleSystem *psys); void BKE_ptcache_id_from_cloth(PTCacheID *pid, struct Object *ob, struct ClothModifierData *clmd); +void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd, int num); void BKE_ptcache_ids_from_object(struct ListBase *lb, struct Object *ob); @@ -192,7 +200,7 @@ struct PointCache *BKE_ptcache_add(struct ListBase *ptcaches); void BKE_ptache_free_mem(struct PointCache *cache); void BKE_ptcache_free(struct PointCache *cache); void BKE_ptcache_free_list(struct ListBase *ptcaches); -struct PointCache *BKE_ptcache_copy(struct PointCache *cache); +struct PointCache *BKE_ptcache_copy_list(struct ListBase *ptcaches_new, struct ListBase *ptcaches_old); /********************** Baking *********************/ diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h index 9bb246f88cc..12a13a2b50c 100644 --- a/source/blender/blenkernel/BKE_scene.h +++ b/source/blender/blenkernel/BKE_scene.h @@ -40,6 +40,12 @@ struct AviCodecData; struct QuicktimeCodecData; struct RenderData; struct Text; +struct Main; + +#define SCE_COPY_EMPTY 0 +#define SCE_COPY_LINK_OB 1 +#define SCE_COPY_LINK_DATA 2 +#define SCE_COPY_FULL 3 /* note; doesn't work when scene is empty */ #define SETLOOPER(s, b) sce= s, b= (Base*)sce->base.first; b; b= (Base*)(b->next?b->next:sce->set?(sce=sce->set)->base.first:NULL) @@ -48,13 +54,16 @@ struct Text; void free_avicodecdata(struct AviCodecData *acd); void free_qtcodecdata(struct QuicktimeCodecData *acd); -void free_scene(struct Scene *me); +void free_scene(struct Scene *sce); struct Scene *add_scene(char *name); struct Base *object_in_scene(struct Object *ob, struct Scene *sce); void set_scene_bg(struct Scene *sce); void set_scene_name(char *name); +struct Scene *copy_scene(struct Main *bmain, struct Scene *sce, int type); +void unlink_scene(struct Main *bmain, struct Scene *sce, struct Scene *newsce); + int next_object(struct Scene *scene, int val, struct Base **base, struct Object **ob); struct Object *scene_find_camera(struct Scene *sc); diff --git a/source/blender/blenkernel/BKE_sculpt.h b/source/blender/blenkernel/BKE_sculpt.h index 54cafc984a6..9e5647a8775 100644 --- a/source/blender/blenkernel/BKE_sculpt.h +++ b/source/blender/blenkernel/BKE_sculpt.h @@ -33,7 +33,7 @@ struct MFace; struct MultireModifierData; struct MVert; -struct Sculpt; +struct Object; struct StrokeCache; typedef struct SculptSession { @@ -63,13 +63,10 @@ typedef struct SculptSession { float (*mesh_co_orig)[3]; /* Copy of the mesh vertices' locations */ float *layer_disps; /* Displacements for each vertex */ - void *cursor; /* wm handle */ - struct SculptStroke *stroke; - struct StrokeCache *cache; } SculptSession; -void sculptsession_free(struct Sculpt *sculpt); +void free_sculptsession(SculptSession **); #endif diff --git a/source/blender/blenkernel/BKE_sequence.h b/source/blender/blenkernel/BKE_sequence.h index 35cff5c9422..f72617c8312 100644 --- a/source/blender/blenkernel/BKE_sequence.h +++ b/source/blender/blenkernel/BKE_sequence.h @@ -184,3 +184,7 @@ int shuffle_seq(struct ListBase * seqbasep, struct Sequence *test); void free_imbuf_seq(struct ListBase * seqbasep, int check_mem_usage); void seq_update_sound(struct Sequence *seq); + +void clear_scene_in_allseqs(struct Scene *sce); + + diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h index ef66b29f112..1dd90b4dbda 100644 --- a/source/blender/blenkernel/BKE_sound.h +++ b/source/blender/blenkernel/BKE_sound.h @@ -39,8 +39,6 @@ struct Main; void sound_init(); -void sound_reinit(struct bContext *C); - void sound_exit(); struct bSound* sound_new_file(struct Main *main, char* filename); diff --git a/source/blender/blenkernel/BKE_unit.h b/source/blender/blenkernel/BKE_unit.h index 54d5bba057a..5d5f8cddf47 100644 --- a/source/blender/blenkernel/BKE_unit.h +++ b/source/blender/blenkernel/BKE_unit.h @@ -47,7 +47,7 @@ double bUnit_BaseScalar(int system, int type); void bUnit_GetSystem(void **usys_pt, int *len, int system, int type); char* bUnit_GetName(void *usys_pt, int index); -char* bUnit_GetNamePlural(void *usys_pt, int index); +char* bUnit_GetNameDisplay(void *usys_pt, int index); double bUnit_GetScaler(void *usys_pt, int index); /* aligned with PropertyUnit */ diff --git a/source/blender/blenkernel/BKE_utildefines.h b/source/blender/blenkernel/BKE_utildefines.h index f6c305b202d..76e0da98f69 100644 --- a/source/blender/blenkernel/BKE_utildefines.h +++ b/source/blender/blenkernel/BKE_utildefines.h @@ -62,11 +62,6 @@ #define SHIFT3(type, a, b, c) { type tmp; tmp = a; a = c; c = b; b = tmp; } #define SHIFT4(type, a, b, c, d) { type tmp; tmp = a; a = d; d = c; c = b; b = tmp; } -/* string compare */ -#define STREQ(str, a) ( strcmp((str), (a))==0 ) -#define STREQ2(str, a, b) ( STREQ(str, a) || STREQ(str, b) ) -#define STREQ3(str, a, b, c) ( STREQ2(str, a, b) || STREQ(str, c) ) - /* min/max */ #define MIN2(x,y) ( (x)<(y) ? (x) : (y) ) #define MIN3(x,y,z) MIN2( MIN2((x),(y)) , (z) ) @@ -92,8 +87,6 @@ if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \ if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1]; } -#define MINSIZE(val, size) ( ((val)>=0.0) ? (((val)<(size)) ? (size): (val)) : ( ((val)>(-size)) ? (-size) : (val))) - /* some math and copy defines */ #define SWAP(type, a, b) { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; } diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 950947f0d24..8d1df98c5b4 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -30,14 +30,18 @@ SET(INC . ../../../intern/guardedalloc ../../../intern/memutil ../editors/include ../blenlib ../makesdna ../render/extern/include ../../../intern/decimation/extern ../imbuf ../avi ../../../intern/elbeem/extern ../../../intern/opennl/extern - ../../../intern/iksolver/extern ../blenloader ../quicktime - ../../../extern/bullet2/src + ../../../intern/iksolver/extern ../blenloader ../nodes ../../../extern/glew/include ../gpu ../makesrna ../../../intern/smoke/extern - ../../../intern/bsp/extern + ../../../intern/bsp/extern ../blenfont ../../../intern/audaspace/intern ${ZLIB_INC} ) +IF(WITH_BULLET) + SET(INC ${INC} ../../../extern/bullet2/src) + ADD_DEFINITIONS(-DUSE_BULLET) +ENDIF(WITH_BULLET) + IF(WITH_OPENEXR) ADD_DEFINITIONS(-DWITH_OPENEXR) ENDIF(WITH_OPENEXR) @@ -51,16 +55,10 @@ IF(WITH_DDS) ENDIF(WITH_DDS) IF(WITH_QUICKTIME) - SET(INC ${INC} ${QUICKTIME_INC}) + SET(INC ${INC} ../quicktime ${QUICKTIME_INC}) ADD_DEFINITIONS(-DWITH_QUICKTIME) ENDIF(WITH_QUICKTIME) -IF(WITH_SDL) - SET(INC ${INC} ${SDL_INC}) -ELSE(WITH_SDL) - ADD_DEFINITIONS(-DDISABLE_SDL) -ENDIF(WITH_SDL) - IF(WITH_FFMPEG) SET(INC ${INC} ${FFMPEG_INC}) ADD_DEFINITIONS(-DWITH_FFMPEG) diff --git a/source/blender/blenkernel/SConscript b/source/blender/blenkernel/SConscript index 6772cccbda6..fdc7782a0b1 100644 --- a/source/blender/blenkernel/SConscript +++ b/source/blender/blenkernel/SConscript @@ -3,7 +3,7 @@ Import ('env') sources = env.Glob('intern/*.c') -incs = '. #/intern/guardedalloc #/intern/memutil ../editors/include ../blenlib ../makesdna' +incs = '. #/intern/guardedalloc #/intern/memutil ../editors/include ../blenlib ../blenfont ../makesdna' incs += ' ../render/extern/include #/intern/decimation/extern ../makesrna' incs += ' ../imbuf ../avi #/intern/elbeem/extern ../nodes' incs += ' #/intern/iksolver/extern ../blenloader' @@ -52,7 +52,7 @@ if env['WITH_BF_QUICKTIME']: incs += ' ' + env['BF_QUICKTIME_INC'] if env['WITH_BF_BULLET']: - defs.append('WITH_BULLET') + defs.append('USE_BULLET') if env['BF_NO_ELBEEM']: defs.append('DISABLE_ELBEEM') diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 090f256ab9f..84cccd8b939 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -72,6 +72,7 @@ #include "BKE_modifier.h" #include "BKE_mesh.h" #include "BKE_object.h" +#include "BKE_paint.h" #include "BKE_subsurf.h" #include "BKE_texture.h" #include "BKE_utildefines.h" @@ -2076,7 +2077,7 @@ static void clear_mesh_caches(Object *ob) static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask) { Object *obact = scene->basact?scene->basact->object:NULL; - int editing = (FACESEL_PAINT_TEST)|(G.f & G_PARTICLEEDIT); + int editing = paint_facesel_test(ob)|(ob && ob->mode & OB_MODE_PARTICLE_EDIT); int needMapping = editing && (ob==obact); float min[3], max[3]; diff --git a/source/blender/blenkernel/intern/Makefile b/source/blender/blenkernel/intern/Makefile index 60ffdc78726..d6d41d6579e 100644 --- a/source/blender/blenkernel/intern/Makefile +++ b/source/blender/blenkernel/intern/Makefile @@ -51,6 +51,7 @@ CPPFLAGS += -I../../imbuf CPPFLAGS += -I../../blenlib CPPFLAGS += -I../../blenloader CPPFLAGS += -I../../python +CPPFLAGS += -I../../blenfont # also avi is used CPPFLAGS += -I../../avi CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 983f1ecc31c..5eaf2133515 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -276,7 +276,7 @@ KeyingSet *BKE_keyingset_add (ListBase *list, const char name[], short flag, sho if (name) BLI_snprintf(ks->name, 64, name); else - strcpy(ks->name, "Keying Set"); + strcpy(ks->name, "KeyingSet"); ks->flag= flag; ks->keyingflag= keyingflag; @@ -285,7 +285,7 @@ KeyingSet *BKE_keyingset_add (ListBase *list, const char name[], short flag, sho BLI_addtail(list, ks); /* make sure KeyingSet has a unique name (this helps with identification) */ - BLI_uniquename(list, ks, "Keying Set", ' ', offsetof(KeyingSet, name), 64); + BLI_uniquename(list, ks, "KeyingSet", '.', offsetof(KeyingSet, name), 64); /* return new KeyingSet for further editing */ return ks; @@ -342,6 +342,21 @@ void BKE_keyingset_add_destination (KeyingSet *ks, ID *id, const char group_name BLI_addtail(&ks->paths, ksp); } +/* Copy all KeyingSets in the given list */ +void BKE_keyingsets_copy(ListBase *newlist, ListBase *list) +{ + KeyingSet *ksn; + KS_Path *kspn; + + BLI_duplicatelist(newlist, list); + + for(ksn=newlist->first; ksn; ksn=ksn->next) { + BLI_duplicatelist(&ksn->paths, &ksn->paths); + + for(kspn=ksn->paths.first; kspn; kspn=kspn->next) + kspn->rna_path= MEM_dupallocN(kspn->rna_path); + } +} /* Freeing Tools --------------------------- */ diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 2e4e5596450..746dc6c59cc 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -226,7 +226,7 @@ static void clear_global(void) G.main= NULL; - G.f &= ~(G_WEIGHTPAINT + G_VERTEXPAINT + G_FACESELECT + G_PARTICLEEDIT); + G.f &= ~(G_FACESELECT); } /* make sure path names are correct for OS */ diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 5dbef017f9d..a7b5a16d924 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -35,6 +35,7 @@ #include "DNA_brush_types.h" #include "DNA_color_types.h" #include "DNA_image_types.h" +#include "DNA_object_types.h" #include "DNA_texture_types.h" #include "DNA_scene_types.h" #include "DNA_windowmanager_types.h" @@ -50,6 +51,7 @@ #include "BKE_image.h" #include "BKE_library.h" #include "BKE_main.h" +#include "BKE_paint.h" #include "BKE_texture.h" #include "BKE_utildefines.h" @@ -61,7 +63,7 @@ /* Datablock add/copy/free/make_local */ -Brush *add_brush(char *name) +Brush *add_brush(const char *name) { Brush *brush; @@ -73,6 +75,8 @@ Brush *add_brush(char *name) brush->alpha= 0.2f; brush->size= 25; brush->spacing= 10.0f; + brush->smooth_stroke_radius= 75; + brush->smooth_stroke_factor= 0.9; brush->rate= 0.1f; brush->innerradius= 0.5f; brush->clone.alpha= 0.5; @@ -152,7 +156,7 @@ void make_local_brush(Brush *brush) } for(scene= G.main->scene.first; scene; scene=scene->id.next) - if(scene->toolsettings->imapaint.brush==brush) { + if(paint_brush(&scene->toolsettings->imapaint.paint)==brush) { if(scene->id.lib) lib= 1; else local= 1; } @@ -174,9 +178,9 @@ void make_local_brush(Brush *brush) brushn->id.flag |= LIB_FAKEUSER; for(scene= G.main->scene.first; scene; scene=scene->id.next) - if(scene->toolsettings->imapaint.brush==brush) + if(paint_brush(&scene->toolsettings->imapaint.paint)==brush) if(scene->id.lib==0) { - scene->toolsettings->imapaint.brush= brushn; + paint_brush_set(&scene->toolsettings->imapaint.paint, brushn); brushn->id.us++; brush->id.us--; } @@ -185,20 +189,7 @@ void make_local_brush(Brush *brush) /* Library Operations */ -Brush **current_brush_source(Scene *sce) -{ - if(G.f & G_SCULPTMODE) - return &sce->toolsettings->sculpt->brush; - else if(G.f & G_VERTEXPAINT) - return &sce->toolsettings->vpaint->brush; - else if(G.f & G_WEIGHTPAINT) - return &sce->toolsettings->wpaint->brush; - else if(G.f & G_TEXTUREPAINT) - return &sce->toolsettings->imapaint.brush; - return NULL; -} - -int brush_set_nr(Brush **current_brush, int nr) +int brush_set_nr(Brush **current_brush, int nr, const char *name) { ID *idtest, *id; @@ -207,7 +198,7 @@ int brush_set_nr(Brush **current_brush, int nr) if(idtest==0) { /* new brush */ if(id) idtest= (ID *)copy_brush((Brush *)id); - else idtest= (ID *)add_brush("Brush"); + else idtest= (ID *)add_brush(name); idtest->us--; } if(idtest!=id) { @@ -381,10 +372,10 @@ int brush_clone_image_delete(Brush *brush) return 0; } -void brush_check_exists(Brush **brush) +void brush_check_exists(Brush **brush, const char *name) { if(*brush==NULL) - brush_set_nr(brush, 1); + brush_set_nr(brush, 1, name); } /* Brush Sampling */ diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index c122145c98f..37e9c93a108 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -591,7 +591,7 @@ CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, BVHTreeOverlap ClothModifierData *clmd = ( ClothModifierData * ) md1; CollisionModifierData *collmd = ( CollisionModifierData * ) md2; MFace *face1=NULL, *face2 = NULL; -#ifdef WITH_BULLET +#ifdef USE_BULLET ClothVertex *verts1 = clmd->clothObject->verts; #endif double distance = 0; @@ -669,7 +669,7 @@ CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, BVHTreeOverlap break; } -#ifdef WITH_BULLET +#ifdef USE_BULLET // calc distance + normal distance = plNearestPoints ( verts1[collpair->ap1].txold, verts1[collpair->ap2].txold, verts1[collpair->ap3].txold, collmd->current_x[collpair->bp1].co, collmd->current_x[collpair->bp2].co, collmd->current_x[collpair->bp3].co, collpair->pa,collpair->pb,collpair->vector ); diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index 78c29a96bff..bbfe077c15e 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -34,6 +34,7 @@ #include "DNA_space_types.h" #include "DNA_view3d_types.h" #include "DNA_windowmanager_types.h" +#include "DNA_object_types.h" #include "RNA_access.h" @@ -43,6 +44,7 @@ #include "BKE_context.h" #include "BKE_main.h" #include "BKE_screen.h" +#include "BKE_global.h" #include <string.h> @@ -217,7 +219,10 @@ struct ARegion *CTX_wm_menu(const bContext *C) struct ReportList *CTX_wm_reports(const bContext *C) { - return &(C->wm.manager->reports); + if (C->wm.manager) + return &(C->wm.manager->reports); + + return NULL; } View3D *CTX_wm_view3d(const bContext *C) @@ -333,6 +338,13 @@ struct SpaceInfo *CTX_wm_space_info(const bContext *C) return NULL; } +struct SpaceUserPref *CTX_wm_space_userpref(const bContext *C) +{ + if(C->wm.area && C->wm.area->spacetype==SPACE_USERPREF) + return C->wm.area->spacedata.first; + return NULL; +} + void CTX_wm_manager_set(bContext *C, wmWindowManager *wm) { C->wm.manager= wm; @@ -656,6 +668,69 @@ Scene *CTX_data_scene(const bContext *C) return C->data.scene; } +int CTX_data_mode_enum(const bContext *C) +{ + Object *obedit= CTX_data_edit_object(C); + + if(obedit) { + switch(obedit->type) { + case OB_MESH: + return CTX_MODE_EDIT_MESH; + case OB_CURVE: + return CTX_MODE_EDIT_CURVE; + case OB_SURF: + return CTX_MODE_EDIT_SURFACE; + case OB_FONT: + return CTX_MODE_EDIT_TEXT; + case OB_ARMATURE: + return CTX_MODE_EDIT_ARMATURE; + case OB_MBALL: + return CTX_MODE_EDIT_METABALL; + case OB_LATTICE: + return CTX_MODE_EDIT_LATTICE; + } + } + else { + Object *ob = CTX_data_active_object(C); + + if(ob) { + if(ob->mode & OB_MODE_POSE) return CTX_MODE_POSE; + else if(ob->mode & OB_MODE_SCULPT) return CTX_MODE_SCULPT; + else if(ob->mode & OB_MODE_WEIGHT_PAINT) return CTX_MODE_PAINT_WEIGHT; + else if(ob->mode & OB_MODE_VERTEX_PAINT) return CTX_MODE_PAINT_VERTEX; + else if(ob->mode & OB_MODE_TEXTURE_PAINT) return CTX_MODE_PAINT_TEXTURE; + else if(ob->mode & OB_MODE_PARTICLE_EDIT) return CTX_MODE_PARTICLE; + } + } + + return CTX_MODE_OBJECT; +} + + +/* would prefer if we can use the enum version below over this one - Campbell */ +/* must be aligned with above enum */ +static char *data_mode_strings[] = { + "mesh_edit", + "curve_edit", + "surface_edit", + "text_edit", + "armature_edit", + "mball_edit", + "lattice_edit", + "posemode", + "sculpt_mode", + "weightpaint", + "vertexpaint", + "texturepaint", + "particlemode", + "objectmode", + 0 +}; +char *CTX_data_mode_string(const bContext *C) +{ + return data_mode_strings[CTX_data_mode_enum(C)]; +} + void CTX_data_scene_set(bContext *C, Scene *scene) { C->data.scene= scene; diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 54366aadd92..3cff82f522a 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -167,7 +167,7 @@ void IDP_ResizeIDPArray(IDProperty *prop, int newlen) for (i=newlen; i<prop->len; i++) { IDP_FreeProperty(GETPROP(prop, i)); } - memcpy(newarr, prop->data.pointer, newlen*prop->len*sizeof(IDProperty)); + memcpy(newarr, prop->data.pointer, newlen*sizeof(IDProperty)); } if(prop->data.pointer) diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 62af05fbc9a..eb8872c43a5 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -73,6 +73,8 @@ //XXX #include "BIF_editseq.h" +#include "BLF_api.h" + #include "PIL_time.h" #include "RE_pipeline.h" @@ -978,7 +980,6 @@ static void stampdata(Scene *scene, StampData *stamp_data, int do_prefix) if (do_prefix) strcpy(stamp_data->file, "File <untitled>"); else strcpy(stamp_data->file, "<untitled>"); } - stamp_data->note[0] = '\0'; } else { stamp_data->file[0] = '\0'; } @@ -1046,8 +1047,8 @@ static void stampdata(Scene *scene, StampData *stamp_data, int do_prefix) if (scene->r.stamp & R_STAMP_FRAME) { char format[32]; - if (do_prefix) sprintf(format, "Frame %%0%di\n", 1 + (int) log10(scene->r.efra)); - else sprintf(format, "%%0%di\n", 1 + (int) log10(scene->r.efra)); + if (do_prefix) sprintf(format, "Frame %%0%di", 1 + (int) log10(scene->r.efra)); + else sprintf(format, "%%0%di", 1 + (int) log10(scene->r.efra)); sprintf (stamp_data->frame, format, scene->r.cfra); } else { stamp_data->frame[0] = '\0'; @@ -1083,131 +1084,172 @@ static void stampdata(Scene *scene, StampData *stamp_data, int do_prefix) } } +// XXX - Bad level call. +extern int datatoc_bmonofont_ttf_size; +extern char datatoc_bmonofont_ttf[]; + +// XXX - copied from text_font_begin +static void stamp_font_begin(int size) +{ + static int mono= -1; + + if (mono == -1) + mono= BLF_load_mem("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size); + + BLF_set(mono); + BLF_aspect(1.0); + BLF_size(size, 72); +} + void BKE_stamp_buf(Scene *scene, unsigned char *rect, float *rectf, int width, int height, int channels) { -#if 0 -// XXX -// This go back when BLF_draw_buffer is implemented - Diego struct StampData stamp_data; - - int x=1,y=1; - int font_height; - int text_width; - int text_pad; - struct BMF_Font *font; + float w, h, pad; + int x, y; if (!rect && !rectf) return; stampdata(scene, &stamp_data, 1); - - switch (scene->r.stamp_font_id) { - case 1: /* tiny */ - font = BMF_GetFont(BMF_kHelveticaBold8); - break; - case 2: /* small */ - font = BMF_GetFont(BMF_kHelveticaBold10); - break; - case 3: /* medium */ - font = BMF_GetFont(BMF_kScreen12); - break; - case 0: /* large - default */ - font = BMF_GetFont(BMF_kScreen15); - break; - case 4: /* huge */ - font = BMF_GetFont(BMF_kHelveticaBold14); - break; - default: - font = NULL; - break; - } - - font_height = BMF_GetFontHeight(font); - /* All texts get halfspace+1 pixel on each side and 1 pix - above and below as padding against their backing rectangles */ - text_pad = BMF_GetStringWidth(font, " "); - - x = 1; /* Inits for everyone, text position, so 1 for padding, not 0 */ - y = height - font_height - 1; /* Also inits for everyone, notice padding pixel */ - + stamp_font_begin(12); + + BLF_buffer(rectf, rect, width, height, channels); + BLF_buffer_col(scene->r.fg_stamp[0], scene->r.fg_stamp[1], scene->r.fg_stamp[2], 1.0); + pad= BLF_width("--"); + + x= 0; + y= height; + if (stamp_data.file[0]) { /* Top left corner */ - text_width = BMF_GetStringWidth(font, stamp_data.file); - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1); - BMF_DrawStringBuf(font, stamp_data.file, x+(text_pad/2), y, scene->r.fg_stamp, rect, rectf, width, height, channels); - y -= font_height+2; /* Top and bottom 1 pix padding each */ + BLF_width_and_height(stamp_data.file, &w, &h); + y -= h; + + /* also a little of space to the background. */ + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y-3, w+3, y+h+3); + + /* and draw the text. */ + BLF_position(x, y, 0.0); + BLF_draw_buffer(stamp_data.file); + + /* the extra pixel for background. */ + y -= 4; } /* Top left corner, below File */ if (stamp_data.note[0]) { - text_width = BMF_GetStringWidth(font, stamp_data.note); - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1); - BMF_DrawStringBuf(font, stamp_data.note, x+(text_pad/2), y, scene->r.fg_stamp, rect, rectf, width, height, channels); - y -= font_height+2; /* Top and bottom 1 pix padding each */ + BLF_width_and_height(stamp_data.note, &w, &h); + y -= h; + + /* and space for background. */ + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-2, w+3, y+h+2); + + BLF_position(x, y+1, 0.0); + BLF_draw_buffer(stamp_data.note); + + /* the extra pixel for background. */ + y -= 4; } /* Top left corner, below File (or Note) */ if (stamp_data.date[0]) { - text_width = BMF_GetStringWidth(font, stamp_data.date); - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1); - BMF_DrawStringBuf(font, stamp_data.date, x+(text_pad/2), y, scene->r.fg_stamp, rect, rectf, width, height, channels); + BLF_width_and_height(stamp_data.date, &w, &h); + y -= h; + + /* and space for background. */ + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-3, w+3, y+h+3); + + BLF_position(x, y, 0.0); + BLF_draw_buffer(stamp_data.date); } + x= 0; + y= 0; + /* Bottom left corner, leaving space for timing */ if (stamp_data.marker[0]) { - x = 1; - y = font_height+2+1; /* 2 for padding in TIME|FRAME fields below and 1 for padding in this one */ - text_width = BMF_GetStringWidth(font, stamp_data.marker); - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1); - BMF_DrawStringBuf(font, stamp_data.marker, x+(text_pad/2), y, scene->r.fg_stamp, rect, rectf, width, height, channels); + BLF_width_and_height(stamp_data.marker, &w, &h); + + /* extra space for background. */ + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, w+2, y+h+3); + + /* and pad the text. */ + BLF_position(x, y+3, 0.0); + BLF_draw_buffer(stamp_data.marker); + + /* space width. */ + x += w + pad; } /* Left bottom corner */ if (stamp_data.time[0]) { - x = 1; - y = 1; - text_width = BMF_GetStringWidth(font, stamp_data.time); - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1); - BMF_DrawStringBuf(font, stamp_data.time, x+(text_pad/2), y, scene->r.fg_stamp, rect, rectf, width, height, channels); - x += text_width+text_pad+2; /* Both sides have 1 pix additional padding each */ + BLF_width_and_height(stamp_data.time, &w, &h); + + /* extra space for background */ + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, x+w+2, y+h+3); + + /* and pad the text. */ + BLF_position(x, y+3, 0.0); + BLF_draw_buffer(stamp_data.time); + + /* space width. */ + x += w + pad; } if (stamp_data.frame[0]) { - text_width = BMF_GetStringWidth(font, stamp_data.frame); - /* Left bottom corner (after SMPTE if exists) */ - if (!stamp_data.time[0]) x = 1; - y = 1; - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1); - BMF_DrawStringBuf(font, stamp_data.frame, x+(text_pad/2), y, scene->r.fg_stamp, rect, rectf, width, height, channels); + BLF_width_and_height(stamp_data.frame, &w, &h); + + /* extra space for background. */ + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, x+w+2, y+h+3); + + /* and pad the text. */ + BLF_position(x, y+3, 0.0); + + BLF_draw_buffer(stamp_data.frame); + + /* space width. */ + x += w + pad; } if (stamp_data.camera[0]) { - text_width = BMF_GetStringWidth(font, stamp_data.camera); - /* Center of bottom edge */ - x = (width/2) - (BMF_GetStringWidth(font, stamp_data.camera)/2); - y = 1; - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1); - BMF_DrawStringBuf(font, stamp_data.camera, x+(text_pad/2), y, scene->r.fg_stamp, rect, rectf, width, height, channels); + BLF_width_and_height(stamp_data.camera, &w, &h); + + /* extra space for background. */ + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, x+w+2, y+h+3); + BLF_position(x, y+3, 0.0); + BLF_draw_buffer(stamp_data.camera); } if (stamp_data.scene[0]) { - text_width = BMF_GetStringWidth(font, stamp_data.scene); - /* Bottom right corner */ - x = width - (text_width+1+text_pad); - y = 1; - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1); - BMF_DrawStringBuf(font, stamp_data.scene, x+(text_pad/2), y, scene->r.fg_stamp, rect, rectf, width, height, channels); + BLF_width_and_height(stamp_data.scene, &w, &h); + + /* Bottom right corner, with an extra space because blenfont is too strict! */ + x= width - w - 2; + + /* extra space for background. */ + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, x+w+3, y+h+3); + + /* and pad the text. */ + BLF_position(x, y+3, 0.0); + BLF_draw_buffer(stamp_data.scene); } if (stamp_data.strip[0]) { - text_width = BMF_GetStringWidth(font, stamp_data.strip); - /* Top right corner */ - x = width - (text_width+1+text_pad); - y = height - font_height - 1; - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1); - BMF_DrawStringBuf(font, stamp_data.strip, x+(text_pad/2), y, scene->r.fg_stamp, rect, rectf, width, height, channels); - } -#endif // 0 XXX + BLF_width_and_height(stamp_data.scene, &w, &h); + + /* Top right corner, with an extra space because blenfont is too strict! */ + x= width - w - pad; + y= height - h; + + /* extra space for background. */ + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y-3, x+w+pad, y+h+3); + + BLF_position(x, y, 0.0); + BLF_draw_buffer(stamp_data.strip); + } + + /* cleanup the buffer. */ + BLF_buffer(NULL, NULL, 0, 0, 0); } void BKE_stamp_info(Scene *scene, struct ImBuf *ibuf) diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index a72f26f6157..2f0e0931588 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -160,7 +160,7 @@ static AdrBit2Path ma_mode_bits[]= { // {MA_SHADOW, "shadow", 0}, // {MA_SHLESS, "shadeless", 0}, // ... - {MA_RAYTRANSP, "raytrace_transparency.enabled", 0}, + {MA_RAYTRANSP, "transparency", 0}, {MA_RAYMIRROR, "raytrace_mirror.enabled", 0}, // {MA_HALO, "type", MA_TYPE_HALO} }; diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 51748443c97..0e26564df74 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -185,7 +185,7 @@ void init_material(Material *ma) ma->vol.shadeflag |= MA_VOL_PRECACHESHADING; ma->vol.precache_resolution = 50; - ma->mode= MA_TRACEBLE|MA_SHADBUF|MA_SHADOW|MA_RADIO|MA_RAYBIAS|MA_TANGENT_STR; + ma->mode= MA_TRACEBLE|MA_SHADBUF|MA_SHADOW|MA_RAYBIAS|MA_TANGENT_STR; ma->preview = NULL; } @@ -693,9 +693,6 @@ static void do_init_render_material(Material *ma, int r_mode, float *amb) if(needtang) ma->mode |= MA_NORMAP_TANG; else ma->mode &= ~MA_NORMAP_TANG; - if(r_mode & R_RADIO) - if(ma->mode & MA_RADIO) needuv= 1; - if(ma->mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE)) { needuv= 1; if(r_mode & R_OSA) ma->texco |= TEXCO_OSA; /* for texfaces */ @@ -704,7 +701,7 @@ static void do_init_render_material(Material *ma, int r_mode, float *amb) /* since the raytracer doesnt recalc O structs for each ray, we have to preset them all */ if(r_mode & R_RAYTRACE) { - if(ma->mode & (MA_RAYMIRROR|MA_RAYTRANSP|MA_SHADOW_TRA)) { + if((ma->mode & (MA_RAYMIRROR|MA_SHADOW_TRA)) || ((ma->mode && MA_TRANSP) && (ma->mode & MA_RAYTRANSP))) { ma->texco |= NEED_UV|TEXCO_ORCO|TEXCO_REFL|TEXCO_NORM; if(r_mode & R_OSA) ma->texco |= TEXCO_OSA; } diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 0c975a10c0a..53d1baa5c9c 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -5858,8 +5858,7 @@ static void smokeModifier_updateDepgraph( ModifierData *md, DagForest *forest, Scene *scene, Object *ob, DagNode *obNode) { - SmokeModifierData *smd = (SmokeModifierData *) md; - /* + /*SmokeModifierData *smd = (SmokeModifierData *) md; if(smd && (smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) { if(smd->domain->fluid_group) @@ -5978,7 +5977,7 @@ static void clothModifier_copyData(ModifierData *md, ModifierData *target) tclmd->sim_parms = MEM_dupallocN(clmd->sim_parms); tclmd->coll_parms = MEM_dupallocN(clmd->coll_parms); - tclmd->point_cache = BKE_ptcache_copy(clmd->point_cache); + tclmd->point_cache = BKE_ptcache_copy_list(&tclmd->ptcaches, &clmd->ptcaches); tclmd->clothObject = NULL; } diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 0f42ba0d2e2..bd6919dc115 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -950,9 +950,6 @@ bNode *nodeAddNodeType(bNodeTree *ntree, int type, bNodeTree *ngroup, ID *id) if(ntype->initfunc!=NULL) ntype->initfunc(node); - if(type==TEX_NODE_OUTPUT) - ntreeTexAssignIndex(ntree, node); - nodeAddSockets(node, ntype); return node; @@ -1021,9 +1018,6 @@ bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node, int internal) nnode->new_node= NULL; nnode->preview= NULL; - if(node->type==TEX_NODE_OUTPUT) - ntreeTexAssignIndex(ntree, node); - return nnode; } @@ -3112,3 +3106,29 @@ void free_nodesystem(void) BLI_freelistN(&node_all_shaders); BLI_freelistN(&node_all_textures); } + +/* called from unlink_scene, when deleting a scene goes over all scenes + * other than the input, checks if they have render layer nodes referencing + * the to-be-deleted scene, and resets them to NULL. */ + +/* XXX needs to get current scene then! */ +void clear_scene_in_nodes(Main *bmain, Scene *sce) +{ + Scene *sce1; + bNode *node; + + for(sce1= bmain->scene.first; sce1; sce1=sce1->id.next) { + if(sce1!=sce) { + if(sce1->nodetree) { + for(node= sce1->nodetree->nodes.first; node; node= node->next) { + if(node->type==CMP_NODE_R_LAYERS) { + Scene *nodesce= (Scene *)node->id; + + if (nodesce==sce) node->id = NULL; + } + } + } + } + } +} + diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 150a5aa97aa..0e45aedc3ed 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -107,6 +107,7 @@ #include "BKE_sca.h" #include "BKE_scene.h" #include "BKE_screen.h" +#include "BKE_sculpt.h" #include "BKE_softbody.h" #include "LBM_fluidsim.h" @@ -222,6 +223,34 @@ void object_free_display(Object *ob) freedisplist(&ob->disp); } +void free_sculptsession(SculptSession **ssp) +{ + if(ssp && *ssp) { + SculptSession *ss = *ssp; + if(ss->projverts) + MEM_freeN(ss->projverts); + + if(ss->fmap) + MEM_freeN(ss->fmap); + + if(ss->fmap_mem) + MEM_freeN(ss->fmap_mem); + + if(ss->texcache) + MEM_freeN(ss->texcache); + + if(ss->layer_disps) + MEM_freeN(ss->layer_disps); + + if(ss->mesh_co_orig) + MEM_freeN(ss->mesh_co_orig); + + MEM_freeN(ss); + + *ssp = NULL; + } +} + /* do not free object itself */ void free_object(Object *ob) { @@ -276,6 +305,8 @@ void free_object(Object *ob) if(ob->soft) sbFree(ob->soft); if(ob->bsoft) bsbFree(ob->bsoft); if(ob->gpulamp.first) GPU_lamp_free(ob); + + free_sculptsession(&ob->sculpt); } static void unlink_object__unlinkModifierLinks(void *userData, Object *ob, Object **obpoin) @@ -1026,7 +1057,7 @@ SoftBody *copy_softbody(SoftBody *sb) sbn->scratch= NULL; - sbn->pointcache= BKE_ptcache_copy(sb->pointcache); + sbn->pointcache= BKE_ptcache_copy_list(&sbn->ptcaches, &sb->ptcaches); return sbn; } @@ -1085,7 +1116,7 @@ ParticleSystem *copy_particlesystem(ParticleSystem *psys) psysn->reactevents.first = psysn->reactevents.last = NULL; psysn->renderdata = NULL; - psysn->pointcache= BKE_ptcache_copy(psys->pointcache); + psysn->pointcache= BKE_ptcache_copy_list(&psysn->ptcaches, &psys->ptcaches); id_us_plus((ID *)psysn->part); @@ -1211,6 +1242,9 @@ Object *copy_object(Object *ob) copy_defgroups(&obn->defbase, &ob->defbase); copy_constraints(&obn->constraints, &ob->constraints); + obn->mode = 0; + obn->sculpt = NULL; + /* increase user numbers */ id_us_plus((ID *)obn->data); id_us_plus((ID *)obn->dup_group); diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c new file mode 100644 index 00000000000..80016f23d7c --- /dev/null +++ b/source/blender/blenkernel/intern/paint.c @@ -0,0 +1,181 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009 by Nicholas Bishop + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "MEM_guardedalloc.h" + +#include "DNA_brush_types.h" +#include "DNA_object_types.h" +#include "DNA_scene_types.h" + +#include "BKE_brush.h" +#include "BKE_global.h" +#include "BKE_library.h" +#include "BKE_paint.h" + +#include <stdlib.h> +#include <string.h> + +Paint *paint_get_active(Scene *sce) +{ + if(sce && sce->basact && sce->basact->object) { + ToolSettings *ts = sce->toolsettings; + + switch(sce->basact->object->mode) { + case OB_MODE_SCULPT: + return &ts->sculpt->paint; + case OB_MODE_VERTEX_PAINT: + return &ts->vpaint->paint; + case OB_MODE_WEIGHT_PAINT: + return &ts->wpaint->paint; + case OB_MODE_TEXTURE_PAINT: + return &ts->imapaint.paint; + } + } + + return NULL; +} + +Brush *paint_brush(Paint *p) +{ + return p && p->brushes ? p->brushes[p->active_brush_index] : NULL; +} + +void paint_brush_set(Paint *p, Brush *br) +{ + if(p && !br) { + /* Setting to NULL removes the current slot */ + paint_brush_slot_remove(p); + } + else if(p) { + int found = 0; + + if(p->brushes) { + int i; + + /* See if there's already a slot with the brush */ + for(i = 0; i < p->brush_count; ++i) { + if(p->brushes[i] == br) { + p->active_brush_index = i; + found = 1; + break; + } + } + + } + + if(!found) { + paint_brush_slot_add(p); + id_us_plus(&br->id); + } + + /* Make sure the current slot is the new brush */ + p->brushes[p->active_brush_index] = br; + } +} + +static void paint_brush_slots_alloc(Paint *p, const int count) +{ + p->brush_count = count; + if(count == 0) + p->brushes = NULL; + else + p->brushes = MEM_callocN(sizeof(Brush*) * count, "Brush slots"); +} + +void paint_brush_slot_add(Paint *p) +{ + if(p) { + Brush **orig = p->brushes; + int orig_count = p->brushes ? p->brush_count : 0; + + /* Increase size of brush slot array */ + paint_brush_slots_alloc(p, orig_count + 1); + if(orig) { + memcpy(p->brushes, orig, sizeof(Brush*) * orig_count); + MEM_freeN(orig); + } + + p->active_brush_index = orig_count; + } +} + +void paint_brush_slot_remove(Paint *p) +{ + if(p && p->brushes) { + Brush **orig = p->brushes; + int src, dst; + + /* Decrease size of brush slot array */ + paint_brush_slots_alloc(p, p->brush_count - 1); + if(p->brushes) { + for(src = 0, dst = 0; dst < p->brush_count; ++src) { + if(src != p->active_brush_index) { + p->brushes[dst] = orig[src]; + ++dst; + } + } + } + MEM_freeN(orig); + + if(p->active_brush_index >= p->brush_count) + p->active_brush_index = p->brush_count - 1; + if(p->active_brush_index < 0) + p->active_brush_index = 0; + } +} + +int paint_facesel_test(Object *ob) +{ + return (G.f&G_FACESELECT) && (ob && (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT))); + +} + +void paint_init(Paint *p, const char *name) +{ + Brush *brush; + + /* If there's no brush, create one */ + brush = paint_brush(p); + brush_check_exists(&brush, name); + paint_brush_set(p, brush); +} + +void free_paint(Paint *paint) +{ + if(paint->brushes) + MEM_freeN(paint->brushes); +} + +void copy_paint(Paint *orig, Paint *new) +{ + if(orig->brushes) { + int i; + new->brushes = MEM_dupallocN(orig->brushes); + for(i = 0; i < orig->brush_count; ++i) + id_us_plus((ID *)new->brushes[i]); + } +} diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index c8aa440e2da..e1987d34a6c 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -321,7 +321,7 @@ int psys_ob_has_hair(Object *ob) } int psys_in_edit_mode(Scene *scene, ParticleSystem *psys) { - return ((G.f & G_PARTICLEEDIT) && psys==psys_get_current((scene->basact)->object) && psys->edit); + return ((scene->basact->object->mode & OB_MODE_PARTICLE_EDIT) && psys==psys_get_current((scene->basact)->object) && psys->edit); } int psys_check_enabled(Object *ob, ParticleSystem *psys) { @@ -431,9 +431,6 @@ void psys_free(Object *ob, ParticleSystem * psys) int nr = 0; ParticleSystem * tpsys; - if(ob->particlesystem.first == NULL && G.f & G_PARTICLEEDIT) - G.f &= ~G_PARTICLEEDIT; - psys_free_path_cache(psys); free_hair(psys, 1); diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index 2f4a5c28385..dcd3fcd2f89 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -2271,8 +2271,6 @@ void psys_make_temp_pointcache(Object *ob, ParticleSystem *psys) } void psys_clear_temp_pointcache(ParticleSystem *psys) { - PTCacheMem *pm = psys->pointcache->mem_cache.first; - if((psys->pointcache->flag & PTCACHE_DISK_CACHE)==0) return; @@ -3728,7 +3726,7 @@ static void psys_update_path_cache(Scene *scene, Object *ob, ParticleSystemModif if((psys->part->childtype && psys->totchild != get_psys_tot_child(scene, psys)) || psys->recalc&PSYS_RECALC_RESET) alloc=1; - if(alloc || psys->recalc&PSYS_RECALC_CHILD || (psys->vgroup[PSYS_VG_DENSITY] && (G.f & G_WEIGHTPAINT))) + if(alloc || psys->recalc&PSYS_RECALC_CHILD || (psys->vgroup[PSYS_VG_DENSITY] && (ob && ob->mode & OB_MODE_WEIGHT_PAINT))) distr=1; if(distr){ diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 7aa01de71d0..09170d92866 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -39,6 +39,7 @@ #include "DNA_object_force.h" #include "DNA_particle_types.h" #include "DNA_scene_types.h" +#include "DNA_smoke_types.h" #include "BLI_blenlib.h" @@ -52,11 +53,14 @@ #include "BKE_particle.h" #include "BKE_pointcache.h" #include "BKE_scene.h" +#include "BKE_smoke.h" #include "BKE_softbody.h" #include "BKE_utildefines.h" #include "BLI_blenlib.h" +#include "smoke_API.h" + /* needed for directory lookup */ #ifndef WIN32 #include <dirent.h> @@ -305,6 +309,7 @@ static int ptcache_totwrite_particle(void *psys_v) return totwrite; } + /* Cloth functions */ static int ptcache_write_cloth(int index, void *cloth_v, void **data) { @@ -376,6 +381,7 @@ static int ptcache_totpoint_cloth(void *cloth_v) ClothModifierData *clmd= cloth_v; return clmd->clothObject->numverts; } + /* Creating ID's */ void BKE_ptcache_id_from_softbody(PTCacheID *pid, Object *ob, SoftBody *sb) { @@ -394,6 +400,8 @@ void BKE_ptcache_id_from_softbody(PTCacheID *pid, Object *ob, SoftBody *sb) pid->totpoint= pid->totwrite= ptcache_totpoint_softbody; pid->write_elem= ptcache_write_softbody; + pid->write_stream = NULL; + pid->read_stream = NULL; pid->read_elem= ptcache_read_softbody; pid->interpolate_elem= ptcache_interpolate_softbody; @@ -432,6 +440,8 @@ void BKE_ptcache_id_from_particles(PTCacheID *pid, Object *ob, ParticleSystem *p pid->ptcaches= &psys->ptcaches; pid->write_elem= ptcache_write_particle; + pid->write_stream = NULL; + pid->read_stream = NULL; pid->read_elem= ptcache_read_particle; pid->interpolate_elem= ptcache_interpolate_particle; @@ -459,6 +469,112 @@ void BKE_ptcache_id_from_particles(PTCacheID *pid, Object *ob, ParticleSystem *p pid->info_types= (1<<BPHYS_DATA_TIMES); } +#if 0 // XXX smoke pointcache stuff breaks compiling now +/* Smoke functions */ +static int ptcache_totpoint_smoke(void *smoke_v) +{ + SmokeModifierData *smd= (SmokeModifierData *)smoke_v; + SmokeDomainSettings *sds = smd->domain; + + if(sds->fluid) + { + return sds->res[0]*sds->res[1]*sds->res[2]; + } + else + return 0; +} + +// forward decleration +static int ptcache_file_write(PTCacheFile *pf, void *f, size_t tot, int size); + +static int ptcache_write_smoke(PTCacheFile *pf, void *smoke_v) +{ + SmokeModifierData *smd= (SmokeModifierData *)smoke_v; + SmokeDomainSettings *sds = smd->domain; + + if(sds->fluid) + { + size_t res = sds->res[0]*sds->res[1]*sds->res[2]; + float *dens, *densold, *heat, *heatold, *vx, *vy, *vz; + + smoke_export(sds->fluid, &dens, &densold, &heat, &heatold, &vx, &vy, &vz); + + ptcache_file_write(pf, dens, res, sizeof(float)); + ptcache_file_write(pf, densold, res, sizeof(float)); + ptcache_file_write(pf, heat, res, sizeof(float)); + ptcache_file_write(pf, heatold, res, sizeof(float)); + ptcache_file_write(pf, vx, res, sizeof(float)); + ptcache_file_write(pf, vy, res, sizeof(float)); + ptcache_file_write(pf, vz, res, sizeof(float)); + + return 1; + } + + return 0; +} + +// forward decleration +static int ptcache_file_read(PTCacheFile *pf, void *f, size_t tot, int size); + +static void ptcache_read_smoke(PTCacheFile *pf, void *smoke_v) +{ + SmokeModifierData *smd= (SmokeModifierData *)smoke_v; + SmokeDomainSettings *sds = smd->domain; + + if(sds->fluid) + { + size_t res = sds->res[0]*sds->res[1]*sds->res[2]; + float *dens, *densold, *heat, *heatold, *vx, *vy, *vz; + + smoke_export(sds->fluid, &dens, &densold, &heat, &heatold, &vx, &vy, &vz); + + ptcache_file_read(pf, dens, res, sizeof(float)); + ptcache_file_read(pf, densold, res, sizeof(float)); + ptcache_file_read(pf, heat, res, sizeof(float)); + ptcache_file_read(pf, heatold, res, sizeof(float)); + ptcache_file_read(pf, vx, res, sizeof(float)); + ptcache_file_read(pf, vy, res, sizeof(float)); + ptcache_file_read(pf, vz, res, sizeof(float)); + + } +} +void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd, int num) +{ + SmokeDomainSettings *sds = smd->domain; + + memset(pid, 0, sizeof(PTCacheID)); + + pid->ob= ob; + pid->calldata= smd; + + // if(num == 0) + pid->type= PTCACHE_TYPE_SMOKE_DOMAIN_LOW; + // else if(num == 1) + // pid->type= PTCACHE_TYPE_SMOKE_DOMAIN_HIGH; + + pid->stack_index= modifiers_indexInObject(ob, (ModifierData *)smd); + + pid->cache= sds->point_cache; + pid->cache_ptr= &sds->point_cache; + pid->ptcaches= &sds->ptcaches; + + + pid->totpoint= pid->totwrite= ptcache_totpoint_smoke; + + pid->write_elem= NULL; + pid->read_elem= NULL; + pid->read_stream = ptcache_read_smoke; + pid->write_stream = ptcache_write_smoke; + pid->interpolate_elem= NULL; + + pid->write_header= ptcache_write_basic_header; + pid->read_header= ptcache_read_basic_header; + + pid->data_types= (1<<BPHYS_DATA_LOCATION); // bogus values tot make pointcache happy + pid->info_types= 0; +} +#endif // XXX smoke poitcache stuff breaks compiling + void BKE_ptcache_id_from_cloth(PTCacheID *pid, Object *ob, ClothModifierData *clmd) { memset(pid, 0, sizeof(PTCacheID)); @@ -473,6 +589,8 @@ void BKE_ptcache_id_from_cloth(PTCacheID *pid, Object *ob, ClothModifierData *cl pid->totpoint= pid->totwrite= ptcache_totpoint_cloth; pid->write_elem= ptcache_write_cloth; + pid->write_stream = NULL; + pid->read_stream = NULL; pid->read_elem= ptcache_read_cloth; pid->interpolate_elem= ptcache_interpolate_cloth; @@ -515,6 +633,18 @@ void BKE_ptcache_ids_from_object(ListBase *lb, Object *ob) BKE_ptcache_id_from_cloth(pid, ob, (ClothModifierData*)md); BLI_addtail(lb, pid); } + /* + // enabled on next commit + if(md->type == eModifierType_Smoke) { + SmokeModifierData *smd = (SmokeModifierData *)md; + if(smd->type & MOD_SMOKE_TYPE_DOMAIN) + { + pid= MEM_callocN(sizeof(PTCacheID), "PTCacheID"); + BKE_ptcache_id_from_smoke(pid, ob, (SmokeModifierData*)md, 0); + BLI_addtail(lb, pid); + } + } + */ } } @@ -533,7 +663,7 @@ void BKE_ptcache_ids_from_object(ListBase *lb, Object *ob) static int ptcache_path(PTCacheID *pid, char *filename) { Library *lib; - int i; + size_t i; lib= (pid)? pid->ob->id.lib: NULL; @@ -591,7 +721,7 @@ static int BKE_ptcache_id_filename(PTCacheID *pid, char *filename, int cfra, sho } } else { - int temp = strlen(pid->cache->name); + int temp = (int)strlen(pid->cache->name); strcpy(newname, pid->cache->name); newname+=temp; len += temp; @@ -653,11 +783,11 @@ static void ptcache_file_close(PTCacheFile *pf) MEM_freeN(pf); } -static int ptcache_file_read(PTCacheFile *pf, void *f, int tot, int size) +static int ptcache_file_read(PTCacheFile *pf, void *f, size_t tot, int size) { return (fread(f, size, tot, pf->fp) == tot); } -static int ptcache_file_write(PTCacheFile *pf, void *f, int tot, int size) +static int ptcache_file_write(PTCacheFile *pf, void *f, size_t tot, int size) { return (fwrite(f, size, tot, pf->fp) == tot); } @@ -842,7 +972,7 @@ int BKE_ptcache_read_cache(PTCacheID *pid, float cfra, float frs_sec) float old_data1[14], old_data2[14]; int cfrai = (int)cfra; int old_elemsize = ptcache_pid_old_elemsize(pid); - int i, incr = old_elemsize / sizeof(float); + int i; int cfra1 = 0, cfra2 = 0; int totpoint = 0, totpoint2 = 0; @@ -988,56 +1118,93 @@ int BKE_ptcache_read_cache(PTCacheID *pid, float cfra, float frs_sec) if(cfra1 && cfra1==cfra2) error = 1; - totpoint = MIN2(totpoint, pid->totpoint(pid->calldata)); - totpoint2 = MIN2(totpoint2, pid->totpoint(pid->calldata)); - - if(!error) for(i=0; i<totpoint; i++) { - /* read old cache file format */ - if(use_old) { - if(ptcache_file_read(pf, (void*)old_data1, 1, old_elemsize)) - pid->read_elem(i, pid->calldata, NULL, frs_sec, cfra, old_data1); + if(!error) + { + if(pf && pid->read_stream) { + if(totpoint != pid->totpoint(pid->calldata)) + error = 1; else - { error = 1; break; } + { + // we have stream writing here + pid->read_stream(pf, pid->calldata); + } } - else { - if(pm || ptcache_file_read_data(pf)) - pid->read_elem(*index, pid->calldata, pm ? pm->cur : pf->cur, frs_sec, cfra1 ? (float)cfra1 : (float)cfrai, NULL); - else - { error = 1; break; } + } + + totpoint = MIN2(totpoint, pid->totpoint(pid->calldata)); + + if(!error) + { + for(i=0; i<totpoint; i++) { + /* read old cache file format */ + if(use_old) { + if(pid->read_elem && ptcache_file_read(pf, (void*)old_data1, 1, old_elemsize)) + pid->read_elem(i, pid->calldata, NULL, frs_sec, cfra, old_data1); + else + { error = 1; break; } + } + else { + if(pid->read_elem && (pm || ptcache_file_read_data(pf))) + pid->read_elem(*index, pid->calldata, pm ? pm->cur : pf->cur, frs_sec, cfra1 ? (float)cfra1 : (float)cfrai, NULL); + else + { error = 1; break; } + } + + if(pm) { + ptcache_mem_incr_pointers(pm); + index = pm->data_types & (1<<BPHYS_DATA_INDEX) ? pm->cur[BPHYS_DATA_INDEX] : &i; + } } + } - if(pm) { - ptcache_mem_incr_pointers(pm); - index = pm->data_types & (1<<BPHYS_DATA_INDEX) ? pm->cur[BPHYS_DATA_INDEX] : &i; + if(!error) + { + if(pf2 && pid->read_stream) { + if(totpoint2 != pid->totpoint(pid->calldata)) + error = 1; + else + { + // we have stream writing here + pid->read_stream(pf2, pid->calldata); + } } } - if(!error) for(i=0; i<totpoint2; i++) { - /* read old cache file format */ - if(use_old) { - if(ptcache_file_read(pf2, (void*)old_data2, 1, old_elemsize)) { - if(!pf && pf2) - pid->read_elem(i, pid->calldata, NULL, frs_sec, (float)cfra2, old_data2); + totpoint2 = MIN2(totpoint2, pid->totpoint(pid->calldata)); + + if(!error) + { + for(i=0; i<totpoint2; i++) { + /* read old cache file format */ + if(use_old) { + if(pid->read_elem && ptcache_file_read(pf2, (void*)old_data2, 1, old_elemsize)) { + if(!pf && pf2) + pid->read_elem(i, pid->calldata, NULL, frs_sec, (float)cfra2, old_data2); + else if(pid->interpolate_elem) + pid->interpolate_elem(i, pid->calldata, NULL, frs_sec, cfra, (float)cfra1, (float)cfra2, old_data2); + else + { error = 1; break; } + } else - pid->interpolate_elem(i, pid->calldata, NULL, frs_sec, cfra, (float)cfra1, (float)cfra2, old_data2); + { error = 1; break; } } - else - { error = 1; break; } - } - else { - if(pm2 || ptcache_file_read_data(pf2)) { - if((!pf && pf2) || (!pm && pm2)) - pid->read_elem(*index2, pid->calldata, pm2 ? pm2->cur : pf2->cur, frs_sec, (float)cfra2, NULL); + else { + if(pid->read_elem && (pm2 || ptcache_file_read_data(pf2))) { + if((!pf && pf2) || (!pm && pm2)) + pid->read_elem(*index2, pid->calldata, pm2 ? pm2->cur : pf2->cur, frs_sec, (float)cfra2, NULL); + else if(pid->interpolate_elem) + pid->interpolate_elem(*index2, pid->calldata, pm2 ? pm2->cur : pf2->cur, frs_sec, cfra, (float)cfra1, (float)cfra2, NULL); + else + { error = 1; break; } + } else - pid->interpolate_elem(*index2, pid->calldata, pm2 ? pm2->cur : pf2->cur, frs_sec, cfra, (float)cfra1, (float)cfra2, NULL); + { error = 1; break; } } - else - { error = 1; break; } - } - if(pm2) { - ptcache_mem_incr_pointers(pm2); - index2 = pm2->data_types & (1<<BPHYS_DATA_INDEX) ? pm2->cur[BPHYS_DATA_INDEX] : &i; + if(pm2) { + ptcache_mem_incr_pointers(pm2); + index2 = pm2->data_types & (1<<BPHYS_DATA_INDEX) ? pm2->cur[BPHYS_DATA_INDEX] : &i; + } } } @@ -1098,8 +1265,7 @@ int BKE_ptcache_write_cache(PTCacheID *pid, int cfra) { PointCache *cache = pid->cache; PTCacheFile *pf= NULL; - int elemsize = ptcache_pid_old_elemsize(pid); - int i, incr = elemsize / sizeof(float); + int i; int totpoint = pid->totpoint(pid->calldata); int add = 0, overwrite = 0; @@ -1156,13 +1322,18 @@ int BKE_ptcache_write_cache(PTCacheID *pid, int cfra) ptcache_file_init_pointers(pf); - for(i=0; i<totpoint; i++) { - if(pid->write_elem(i, pid->calldata, pf->cur)) - if(!ptcache_file_write_data(pf)) { - ptcache_file_close(pf); - return 0; - } + if(pf && pid->write_stream) { + // we have stream writing here + pid->write_stream(pf, pid->calldata); } + else + for(i=0; i<totpoint; i++) { + if(pid->write_elem && pid->write_elem(i, pid->calldata, pf->cur)) + if(!ptcache_file_write_data(pf)) { + ptcache_file_close(pf); + return 0; + } + } } } else { @@ -1206,7 +1377,7 @@ int BKE_ptcache_write_cache(PTCacheID *pid, int cfra) ptcache_mem_init_pointers(pm); for(i=0; i<totpoint; i++) { - if(pid->write_elem(i, pid->calldata, pm->cur)) + if(pid->write_elem && pid->write_elem(i, pid->calldata, pm->cur)) ptcache_mem_incr_pointers(pm); } //ptcache_make_index_array(pm, pid->totpoint(pid->calldata)); @@ -1284,7 +1455,7 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, int cfra) BLI_delete(path_full, 0, 0); } else { /* read the number of the file */ - int frame, len2 = strlen(de->d_name); + int frame, len2 = (int)strlen(de->d_name); char num[7]; if (len2 > 15) { /* could crash if trying to copy a string out of this range*/ @@ -1468,6 +1639,8 @@ int BKE_ptcache_id_reset(Scene *scene, PTCacheID *pid, int mode) sbFreeSimulation(pid->calldata); else if(pid->type == PTCACHE_TYPE_PARTICLES) psys_reset(pid->calldata, PSYS_RESET_DEPSGRAPH); + else if(pid->type == PTCACHE_TYPE_SMOKE_DOMAIN_LOW) + smokeModifier_reset(pid->calldata); } if(clear) BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_ALL, 0); @@ -1516,6 +1689,17 @@ int BKE_ptcache_object_reset(Scene *scene, Object *ob, int mode) BKE_ptcache_id_from_cloth(&pid, ob, (ClothModifierData*)md); reset |= BKE_ptcache_id_reset(scene, &pid, mode); } + /* + // enabled on next commit + if(md->type == eModifierType_Smoke) { + SmokeModifierData *smd = (SmokeModifierData *)md; + if(smd->type & MOD_SMOKE_TYPE_DOMAIN) + { + BKE_ptcache_id_from_smoke(&pid, ob, (SmokeModifierData*)md, 0); + reset |= BKE_ptcache_id_reset(scene, &pid, mode); + } + } + */ } return reset; @@ -1630,7 +1814,7 @@ void BKE_ptcache_free_list(ListBase *ptcaches) BLI_freelistN(ptcaches); } -PointCache *BKE_ptcache_copy(PointCache *cache) +static PointCache *ptcache_copy(PointCache *cache) { PointCache *ncache; @@ -1645,7 +1829,18 @@ PointCache *BKE_ptcache_copy(PointCache *cache) return ncache; } +/* returns first point cache */ +PointCache *BKE_ptcache_copy_list(ListBase *ptcaches_new, ListBase *ptcaches_old) +{ + PointCache *cache = ptcaches_old->first; + + ptcaches_new->first = ptcaches_new->last = NULL; + + for(; cache; cache=cache->next) + BLI_addtail(ptcaches_new, ptcache_copy(cache)); + return ptcaches_new->first; +} /* Baking */ @@ -2023,7 +2218,7 @@ void BKE_ptcache_load_external(PTCacheID *pid) if (strstr(de->d_name, ext)) { /* do we have the right extension?*/ if (strncmp(filename, de->d_name, len ) == 0) { /* do we have the right prefix */ /* read the number of the file */ - int frame, len2 = strlen(de->d_name); + int frame, len2 = (int)strlen(de->d_name); char num[7]; if (len2 > 15) { /* could crash if trying to copy a string out of this range*/ @@ -2142,4 +2337,4 @@ void BKE_ptcache_update_info(PTCacheID *pid) } else sprintf(cache->info, "%s.", mem_info); -}
\ No newline at end of file +} diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 0e987850acd..2a8fd765386 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -54,6 +54,7 @@ #include "DNA_meta_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" +#include "DNA_screen_types.h" #include "DNA_texture_types.h" #include "DNA_userdef_types.h" @@ -75,8 +76,8 @@ #include "BKE_main.h" #include "BKE_node.h" #include "BKE_object.h" +#include "BKE_paint.h" #include "BKE_scene.h" -#include "BKE_sculpt.h" #include "BKE_sequence.h" #include "BKE_world.h" #include "BKE_utildefines.h" @@ -125,7 +126,112 @@ void free_qtcodecdata(QuicktimeCodecData *qcd) } } -/* copy_scene moved to src/header_info.c... should be back */ +Scene *copy_scene(Main *bmain, Scene *sce, int type) +{ + Scene *scen; + ToolSettings *ts; + Base *base, *obase; + + if(type == SCE_COPY_EMPTY) { + ListBase lb; + scen= add_scene(sce->id.name+2); + + lb= scen->r.layers; + scen->r= sce->r; + scen->r.layers= lb; + } + else { + scen= copy_libblock(sce); + BLI_duplicatelist(&(scen->base), &(sce->base)); + + clear_id_newpoins(); + + id_us_plus((ID *)scen->world); + id_us_plus((ID *)scen->set); + id_us_plus((ID *)scen->ima); + id_us_plus((ID *)scen->gm.dome.warptext); + + scen->ed= NULL; + scen->theDag= NULL; + scen->obedit= NULL; + scen->toolsettings= MEM_dupallocN(sce->toolsettings); + + ts= scen->toolsettings; + if(ts) { + if(ts->vpaint) { + ts->vpaint= MEM_dupallocN(ts->vpaint); + ts->vpaint->paintcursor= NULL; + ts->vpaint->vpaint_prev= NULL; + ts->vpaint->wpaint_prev= NULL; + copy_paint(&ts->vpaint->paint, &ts->vpaint->paint); + } + if(ts->wpaint) { + ts->wpaint= MEM_dupallocN(ts->wpaint); + ts->wpaint->paintcursor= NULL; + ts->wpaint->vpaint_prev= NULL; + ts->wpaint->wpaint_prev= NULL; + copy_paint(&ts->wpaint->paint, &ts->wpaint->paint); + } + if(ts->sculpt) { + ts->sculpt= MEM_dupallocN(ts->sculpt); + copy_paint(&ts->sculpt->paint, &ts->sculpt->paint); + } + + copy_paint(&ts->imapaint.paint, &ts->imapaint.paint); + ts->imapaint.paintcursor= NULL; + + ts->particle.paintcursor= NULL; + } + + BLI_duplicatelist(&(scen->markers), &(sce->markers)); + BLI_duplicatelist(&(scen->transform_spaces), &(sce->transform_spaces)); + BLI_duplicatelist(&(scen->r.layers), &(sce->r.layers)); + BKE_keyingsets_copy(&(scen->keyingsets), &(sce->keyingsets)); + + scen->nodetree= ntreeCopyTree(sce->nodetree, 0); + + obase= sce->base.first; + base= scen->base.first; + while(base) { + id_us_plus(&base->object->id); + if(obase==sce->basact) scen->basact= base; + + obase= obase->next; + base= base->next; + } + } + + /* make a private copy of the avicodecdata */ + if(sce->r.avicodecdata) { + scen->r.avicodecdata = MEM_dupallocN(sce->r.avicodecdata); + scen->r.avicodecdata->lpFormat = MEM_dupallocN(scen->r.avicodecdata->lpFormat); + scen->r.avicodecdata->lpParms = MEM_dupallocN(scen->r.avicodecdata->lpParms); + } + + /* make a private copy of the qtcodecdata */ + if(sce->r.qtcodecdata) { + scen->r.qtcodecdata = MEM_dupallocN(sce->r.qtcodecdata); + scen->r.qtcodecdata->cdParms = MEM_dupallocN(scen->r.qtcodecdata->cdParms); + } + + /* NOTE: part of SCE_COPY_LINK_DATA and SCE_COPY_FULL operations + * are done outside of blenkernel with ED_objects_single_users! */ + + /* camera */ + if(type == SCE_COPY_LINK_DATA || type == SCE_COPY_FULL) { + ID_NEW(scen->camera); + } + + /* world */ + if(type == SCE_COPY_FULL) { + if(scen->world) { + id_us_plus((ID *)scen->world); + scen->world= copy_world(scen->world); + } + } + + return scen; +} /* do not free scene itself */ void free_scene(Scene *sce) @@ -166,15 +272,20 @@ void free_scene(Scene *sce) BLI_freelistN(&sce->r.layers); if(sce->toolsettings) { - if(sce->toolsettings->vpaint) + if(sce->toolsettings->vpaint) { + free_paint(&sce->toolsettings->vpaint->paint); MEM_freeN(sce->toolsettings->vpaint); - if(sce->toolsettings->wpaint) + } + if(sce->toolsettings->wpaint) { + free_paint(&sce->toolsettings->wpaint->paint); MEM_freeN(sce->toolsettings->wpaint); + } if(sce->toolsettings->sculpt) { - sculptsession_free(sce->toolsettings->sculpt); + free_paint(&sce->toolsettings->sculpt->paint); MEM_freeN(sce->toolsettings->sculpt); } - + free_paint(&sce->toolsettings->imapaint.paint); + MEM_freeN(sce->toolsettings); sce->toolsettings = NULL; } @@ -297,7 +408,7 @@ Scene *add_scene(char *name) pset->brush[PE_BRUSH_CUT].strength= 100; sce->jumpframe = 10; - sce->audio.mixrate = 44100; + sce->r.audio.mixrate = 44100; strcpy(sce->r.backbuf, "//backbuf"); strcpy(sce->r.pic, U.renderdir); @@ -331,6 +442,9 @@ Scene *add_scene(char *name) sce->gm.physubstep = 1; sce->gm.maxphystep = 5; + sce->gm.flag = GAME_DISPLAY_LISTS; + sce->gm.matmode = GAME_MAT_MULTITEX; + return sce; } @@ -390,7 +504,7 @@ void set_scene_bg(Scene *scene) base->flag |= flag; /* not too nice... for recovering objects with lost data */ - if(ob->pose==NULL) base->flag &= ~OB_POSEMODE; + //if(ob->pose==NULL) base->flag &= ~OB_POSEMODE; ob->flag= base->flag; ob->ctime= -1234567.0; /* force ipo to be calculated later */ @@ -413,6 +527,30 @@ void set_scene_name(char *name) //XXX error("Can't find scene: %s", name); } +void unlink_scene(Main *bmain, Scene *sce, Scene *newsce) +{ + Scene *sce1; + bScreen *sc; + + /* check all sets */ + for(sce1= bmain->scene.first; sce1; sce1= sce1->id.next) + if(sce1->set == sce) + sce1->set= NULL; + + /* check all sequences */ + clear_scene_in_allseqs(sce); + + /* check render layer nodes in other scenes */ + clear_scene_in_nodes(bmain, sce); + + /* al screens */ + for(sc= bmain->screen.first; sc; sc= sc->id.next) + if(sc->scene == sce) + sc->scene= newsce; + + free_libblock(&bmain->scene, sce); +} + /* used by metaballs * doesnt return the original duplicated object, only dupli's */ @@ -677,33 +815,6 @@ void scene_add_render_layer(Scene *sce) srl->passflag= SCE_PASS_COMBINED|SCE_PASS_Z; } -void sculptsession_free(Sculpt *sculpt) -{ - SculptSession *ss= sculpt->session; - if(ss) { - if(ss->projverts) - MEM_freeN(ss->projverts); - - if(ss->fmap) - MEM_freeN(ss->fmap); - - if(ss->fmap_mem) - MEM_freeN(ss->fmap_mem); - - if(ss->texcache) - MEM_freeN(ss->texcache); - - if(ss->layer_disps) - MEM_freeN(ss->layer_disps); - - if(ss->mesh_co_orig) - MEM_freeN(ss->mesh_co_orig); - - MEM_freeN(ss); - sculpt->session= NULL; - } -} - /* render simplification */ int get_render_subsurf_level(RenderData *r, int lvl) diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index 2ee95ed928e..078258092f7 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -2792,6 +2792,10 @@ void sequence_effect_speed_rebuild_map(Sequence * seq, int force) if (!(force || seq->len != v->length || !v->frameMap)) { return; } + if (!seq->seq1) { /* make coverity happy and check for (CID 598) + input strip ... */ + return; + } if (!v->frameMap || v->length != seq->len) { if (v->frameMap) MEM_freeN(v->frameMap); @@ -2807,7 +2811,7 @@ void sequence_effect_speed_rebuild_map(Sequence * seq, int force) /* if there is no IPO, try to make retiming easy by stretching the strip */ // XXX old animation system - seq - if (/*!seq->ipo &&*/ seq->seq1 && seq->seq1->enddisp != seq->seq1->start + if (/*!seq->ipo &&*/ seq->seq1->enddisp != seq->seq1->start && seq->seq1->len != 0) { fallback_fac = (float) seq->seq1->len / (float) (seq->seq1->enddisp - seq->seq1->start); diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index 9d4c75245cf..22ea41276ff 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -260,7 +260,7 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive int *tridivs = NULL; float cell_len = 1.0 / 50.0; // for res = 50 size_t newdivs = 0; - size_t max_points = 0; + //size_t max_points = 0; size_t quads = 0, facecounter = 0; // copy obmat @@ -302,7 +302,7 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive size_t j, k; int divs1 = tridivs[3 * facecounter + 0]; int divs2 = tridivs[3 * facecounter + 1]; - int divs3 = tridivs[3 * facecounter + 2]; + //int divs3 = tridivs[3 * facecounter + 2]; float side1[3], side2[3], trinormorg[3], trinorm[3]; if(again == 1 && mface[i].v4) diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 347837d1dd0..a3275792a85 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -34,19 +34,7 @@ void sound_init() { AUD_Specs specs; - specs.channels = AUD_CHANNELS_STEREO; - specs.format = AUD_FORMAT_S16; - specs.rate = AUD_RATE_44100; - - if(!AUD_init(AUD_SDL_DEVICE, specs, AUD_DEFAULT_BUFFER_SIZE)) - if(!AUD_init(AUD_OPENAL_DEVICE, specs, AUD_DEFAULT_BUFFER_SIZE*4)) - AUD_init(AUD_NULL_DEVICE, specs, AUD_DEFAULT_BUFFER_SIZE); -} - -void sound_reinit(struct bContext *C) -{ - AUD_Specs specs; - int device, buffersize; + int device, buffersize, success; device = U.audiodevice; buffersize = U.mixbufsize; @@ -66,8 +54,15 @@ void sound_reinit(struct bContext *C) if(specs.channels <= AUD_CHANNELS_INVALID) specs.channels = AUD_CHANNELS_STEREO; - if(!AUD_init(device, specs, buffersize)) - AUD_init(AUD_NULL_DEVICE, specs, buffersize); + if(!AUD_init(device, specs, buffersize)) { + if(device == AUD_SDL_DEVICE) + success= AUD_init(AUD_OPENAL_DEVICE, specs, AUD_DEFAULT_BUFFER_SIZE*4); + else + success= AUD_init(AUD_SDL_DEVICE, specs, AUD_DEFAULT_BUFFER_SIZE*4); + + if(!success) + AUD_init(AUD_NULL_DEVICE, specs, buffersize); + } } void sound_exit() @@ -421,7 +416,7 @@ void sound_scrub(struct bContext *C) int cfra = CFRA; float fps = FPS; - if(scene->audio.flag & AUDIO_SCRUB && !CTX_wm_screen(C)->animtimer) + if(scene->r.audio.flag & AUDIO_SCRUB && !CTX_wm_screen(C)->animtimer) { AUD_lock(); diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c index ba609fc5611..f8e3b3c5ad2 100644 --- a/source/blender/blenkernel/intern/unit.c +++ b/source/blender/blenkernel/intern/unit.c @@ -33,6 +33,12 @@ #define TEMP_STR_SIZE 256 +#define SEP_CHR '#' +#define SEP_STR "#" + +#define EUL 0.000001 + + /* define a single unit */ typedef struct bUnitDef { char *name; @@ -40,6 +46,8 @@ typedef struct bUnitDef { char *name_short; /* this is used for display*/ char *name_alt; /* can be NULL */ + char *name_display; /* can be NULL */ + double scalar; double bias; /* not used yet, needed for converting temperature */ int flag; @@ -58,22 +66,22 @@ typedef struct bUnitCollection { /* Dummy */ static struct bUnitDef buDummyDef[] = { - {"", NULL, "", NULL, 1.0, 0.0}, - {NULL, NULL, NULL, NULL, 0.0, 0.0} + {"", NULL, "", NULL, NULL, 1.0, 0.0}, + {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; static struct bUnitCollection buDummyCollecton = {buDummyDef, 0, 0, sizeof(buDummyDef)}; /* Lengths */ static struct bUnitDef buMetricLenDef[] = { - {"kilometer", "Kilometers", "km", NULL, 1000.0, 0.0, B_UNIT_DEF_NONE}, - {"hectometer", "100 Meters", "hm", NULL, 100.0, 0.0, B_UNIT_DEF_SUPPRESS}, - {"dekameter", "10 Meters", "dkm",NULL, 10.0, 0.0, B_UNIT_DEF_SUPPRESS}, - {"meter", "Meters", "m", NULL, 1.0, 0.0, B_UNIT_DEF_NONE}, /* base unit */ - {"decimetre", "10 Centimeters", "dm", NULL, 0.1, 0.0, B_UNIT_DEF_SUPPRESS}, - {"centimeter", "Centimeters", "cm", NULL, 0.01, 0.0, B_UNIT_DEF_NONE}, - {"millimeter", "Millimeters", "mm", NULL, 0.001, 0.0, B_UNIT_DEF_NONE}, - {"micrometer", "Micrometers", "um", "µm", 0.000001, 0.0, B_UNIT_DEF_NONE}, // micron too? + {"kilometer", "kilometers", "km", NULL, "Kilometers", 1000.0, 0.0, B_UNIT_DEF_NONE}, + {"hectometer", "hectometers", "hm", NULL, "10 Meters", 100.0, 0.0, B_UNIT_DEF_SUPPRESS}, + {"dekameter", "dekameters", "dkm",NULL, "10 Meters", 10.0, 0.0, B_UNIT_DEF_SUPPRESS}, + {"meter", "meters", "m", NULL, "Meters", 1.0, 0.0, B_UNIT_DEF_NONE}, /* base unit */ + {"decimetre", "decimetres", "dm", NULL, "10 Centimeters", 0.1, 0.0, B_UNIT_DEF_SUPPRESS}, + {"centimeter", "centimeters", "cm", NULL, "Centimeters", 0.01, 0.0, B_UNIT_DEF_NONE}, + {"millimeter", "millimeters", "mm", NULL, "Millimeters", 0.001, 0.0, B_UNIT_DEF_NONE}, + {"micrometer", "micrometers", "um", "µm", "Micrometers", 0.000001, 0.0, B_UNIT_DEF_NONE}, // micron too? /* These get displayed because of float precision problems in the transform header, * could work around, but for now probably people wont use these */ @@ -81,19 +89,19 @@ static struct bUnitDef buMetricLenDef[] = { {"nanometer", "Nanometers", "nm", NULL, 0.000000001, 0.0, B_UNIT_DEF_NONE}, {"picometer", "Picometers", "pm", NULL, 0.000000000001, 0.0,B_UNIT_DEF_NONE}, */ - {NULL, NULL, NULL, NULL, 0.0, 0.0} + {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; static struct bUnitCollection buMetricLenCollecton = {buMetricLenDef, 3, 0, sizeof(buMetricLenDef)/sizeof(bUnitDef)}; static struct bUnitDef buImperialLenDef[] = { - {"mile", "Miles", "mi", "m", 1609.344, 0.0, B_UNIT_DEF_NONE}, - {"furlong", "Furlongs", "fur", NULL,201.168, 0.0, B_UNIT_DEF_SUPPRESS}, - {"chain", "Chains", "ch", NULL, 0.9144*22.0, 0.0, B_UNIT_DEF_SUPPRESS}, - {"yard", "Yards", "yd", NULL, 0.9144, 0.0, B_UNIT_DEF_NONE}, - {"foot", "Feet", "'", "ft", 0.3048, 0.0, B_UNIT_DEF_NONE}, - {"inch", "Inches", "\"", "in", 0.0254, 0.0, B_UNIT_DEF_NONE}, /* base unit */ - {"thou", "Thous", "mil", NULL,0.0000254, 0.0, B_UNIT_DEF_NONE}, - {NULL, NULL, NULL, NULL, 0.0, 0.0} + {"mile", "miles", "mi", "m", "Miles", 1609.344, 0.0, B_UNIT_DEF_NONE}, + {"furlong", "furlongs", "fur", NULL, "Furlongs",201.168, 0.0, B_UNIT_DEF_SUPPRESS}, + {"chain", "chains", "ch", NULL, "Chains", 0.9144*22.0, 0.0, B_UNIT_DEF_SUPPRESS}, + {"yard", "yards", "yd", NULL, "Yards", 0.9144, 0.0, B_UNIT_DEF_NONE}, + {"foot", "feet", "'", "ft", "Feet", 0.3048, 0.0, B_UNIT_DEF_NONE}, + {"inch", "inches", "\"", "in", "Inches", 0.0254, 0.0, B_UNIT_DEF_NONE}, /* base unit */ + {"thou", "thous", "mil", NULL, "Thous", 0.0000254, 0.0, B_UNIT_DEF_NONE}, + {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; static struct bUnitCollection buImperialLenCollecton = {buImperialLenDef, 4, 0, sizeof(buImperialLenDef)/sizeof(bUnitDef)}; @@ -101,13 +109,13 @@ static struct bUnitCollection buImperialLenCollecton = {buImperialLenDef, 4, 0, /* Time */ static struct bUnitDef buNaturalTimeDef[] = { /* weeks? - probably not needed for blender */ - {"day", "Days", "d", NULL, 90000.0, 0.0, B_UNIT_DEF_NONE}, - {"hour", "Hours", "hr", "h", 3600.0, 0.0, B_UNIT_DEF_NONE}, - {"minute", "Minutes", "min", "m", 60.0, 0.0, B_UNIT_DEF_NONE}, - {"second", "Seconds", "sec", "s", 1.0, 0.0, B_UNIT_DEF_NONE}, /* base unit */ - {"millisecond", "Milliseconds", "ms", NULL, 0.001, 0.0 , B_UNIT_DEF_NONE}, - {"microsecond", "Microseconds", "us", NULL, 0.000001, 0.0, B_UNIT_DEF_NONE}, - {NULL, NULL, NULL, NULL, 0.0, 0.0} + {"day", "days", "d", NULL, "Days", 90000.0, 0.0, B_UNIT_DEF_NONE}, + {"hour", "hours", "hr", "h", "Hours", 3600.0, 0.0, B_UNIT_DEF_NONE}, + {"minute", "minutes", "min", "m", "Minutes", 60.0, 0.0, B_UNIT_DEF_NONE}, + {"second", "seconds", "sec", "s", "Seconds", 1.0, 0.0, B_UNIT_DEF_NONE}, /* base unit */ + {"millisecond", "milliseconds", "ms", NULL, "Milliseconds", 0.001, 0.0 , B_UNIT_DEF_NONE}, + {"microsecond", "microseconds", "us", NULL, "Microseconds", 0.000001, 0.0, B_UNIT_DEF_NONE}, + {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; static struct bUnitCollection buNaturalTimeCollecton = {buNaturalTimeDef, 3, 0, sizeof(buNaturalTimeDef)/sizeof(bUnitDef)}; @@ -140,7 +148,7 @@ static bUnitDef *unit_best_fit(double value, bUnitCollection *usys, bUnitDef *un if(suppress && (unit->flag & B_UNIT_DEF_SUPPRESS)) continue; - if (value_abs >= unit->scalar*0.9999) /* scale down scalar so 1cm doesnt convert to 10mm because of float error */ + if (value_abs >= unit->scalar*(1.0-EUL)) /* scale down scalar so 1cm doesnt convert to 10mm because of float error */ return unit; } @@ -254,8 +262,7 @@ void bUnit_AsString(char *str, int len_max, double value, int prec, int system, i= unit_as_string(str, len_max, value_a, prec, usys, unit_a, '\0'); /* is there enough space for at least 1 char of the next unit? */ - if(i+3 < len_max) { - str[i++]= ','; + if(i+2 < len_max) { str[i++]= ' '; /* use low precision since this is a smaller unit */ @@ -292,11 +299,43 @@ static char *unit_find_str(char *str, char *substr) } +/* Note that numbers are added within brackets + * ") " - is used to detect numbers we added so we can detect if commas need to be added + * + * "1m1cm+2mm" - Original value + * "1*1#1*0.01#+2*0.001#" - Replace numbers + * "1*1,1*0.01 +2*0.001 " - Add comma's if ( - + * / % ^ < > ) not found in between + * + */ + +/* not too strict, (- = * /) are most common */ +static int ch_is_op(char op) +{ + switch(op) { + case '+': + case '-': + case '*': + case '/': + case '|': + case '&': + case '~': + case '<': + case '>': + case '^': + case '!': + case '=': + case '%': + return 1; + default: + return 0; + } +} + static int unit_scale_str(char *str, int len_max, char *str_tmp, double scale_pref, bUnitDef *unit, char *replace_str) { - char *str_found= unit_find_str(str, replace_str); + char *str_found; - if(str_found) { /* XXX - investigate, does not respect len_max properly */ + if((len_max>0) && (str_found= unit_find_str(str, replace_str))) { /* XXX - investigate, does not respect len_max properly */ int len, len_num, len_name, len_move, found_ofs; found_ofs = (int)(str_found-str); @@ -305,7 +344,7 @@ static int unit_scale_str(char *str, int len_max, char *str_tmp, double scale_pr len_name = strlen(replace_str); len_move= (len - (found_ofs+len_name)) + 1; /* 1+ to copy the string terminator */ - len_num= snprintf(str_tmp, TEMP_STR_SIZE, "*%lg", unit->scalar/scale_pref); + len_num= snprintf(str_tmp, TEMP_STR_SIZE, "*%lg"SEP_STR, unit->scalar/scale_pref); /* # removed later */ if(len_num > len_max) len_num= len_max; @@ -330,20 +369,22 @@ static int unit_scale_str(char *str, int len_max, char *str_tmp, double scale_pr memcpy(str_found, str_tmp, len_num); /* without the string terminator */ } - str[len_max-1]= '\0'; /* since the null terminator wont be moved */ - return 1; + /* since the null terminator wont be moved if the stringlen_max + * was not long enough to fit everything in it */ + str[len_max-1]= '\0'; + return found_ofs + len_num; } return 0; } static int unit_replace(char *str, int len_max, char *str_tmp, double scale_pref, bUnitDef *unit) { - int change= 0; - change |= unit_scale_str(str, len_max, str_tmp, scale_pref, unit, unit->name_short); - change |= unit_scale_str(str, len_max, str_tmp, scale_pref, unit, unit->name_plural); - change |= unit_scale_str(str, len_max, str_tmp, scale_pref, unit, unit->name_alt); - change |= unit_scale_str(str, len_max, str_tmp, scale_pref, unit, unit->name); - return change; + int ofs= 0; + ofs += unit_scale_str(str+ofs, len_max-ofs, str_tmp, scale_pref, unit, unit->name_short); + ofs += unit_scale_str(str+ofs, len_max-ofs, str_tmp, scale_pref, unit, unit->name_plural); + ofs += unit_scale_str(str+ofs, len_max-ofs, str_tmp, scale_pref, unit, unit->name_alt); + ofs += unit_scale_str(str+ofs, len_max-ofs, str_tmp, scale_pref, unit, unit->name); + return ofs; } static int unit_find(char *str, bUnitDef *unit) @@ -364,6 +405,9 @@ static int unit_find(char *str, bUnitDef *unit) * 10.1km -> 10.1*1000.0 * ...will be resolved by python. * + * values will be split by a comma's + * 5'2" -> 5'0.0254, 2*0.3048 + * * str_prev is optional, when valid it is used to get a base unit when none is set. * * return true of a change was made. @@ -380,6 +424,17 @@ int bUnit_ReplaceString(char *str, int len_max, char *str_prev, double scale_pre return 0; } + + { /* make lowercase */ + int i; + char *ch= str; + + for(i=0; (i>=len_max || *ch=='\0'); i++, ch++) + if((*ch>='A') && (*ch<='Z')) + *ch += ('a'-'A'); + } + + for(unit= usys->units; unit->name; unit++) { if(unit->flag & B_UNIT_DEF_SUPPRESS) @@ -401,12 +456,12 @@ int bUnit_ReplaceString(char *str, int len_max, char *str_prev, double scale_pre usys_iter= unit_get_system(system_iter, type); for(unit= usys_iter->units; unit->name; unit++) { - if(unit->flag & B_UNIT_DEF_SUPPRESS) - continue; - - /* incase there are multiple instances */ - while(unit_replace(str, len_max, str_tmp, scale_pref, unit)) - change= 1; + if((unit->flag & B_UNIT_DEF_SUPPRESS) == 0) { + int ofs = 0; + /* incase there are multiple instances */ + while((ofs=unit_replace(str+ofs, len_max-ofs, str_tmp, scale_pref, unit))) + change= 1; + } } } } @@ -430,11 +485,49 @@ int bUnit_ReplaceString(char *str, int len_max, char *str_prev, double scale_pre if(unit==NULL) unit= unit_default(usys); - /* add the unit prefic and re-run */ - snprintf(str_tmp, sizeof(str_tmp), "%s %s", str, unit->name); - strncpy(str, str_tmp, len_max); + /* add the unit prefic and re-run, use brackets incase there was an expression given */ + if(snprintf(str_tmp, sizeof(str_tmp), "(%s)%s", str, unit->name) < sizeof(str_tmp)) { + strncpy(str, str_tmp, len_max); + return bUnit_ReplaceString(str, len_max, NULL, scale_pref, system, type); + } + else { + /* snprintf would not fit into str_tmp, cant do much in this case + * check for this because otherwise bUnit_ReplaceString could call its self forever */ + return 0; + } + + } + + /* replace # with commas when there is no operator between it and the next number + * + * "1*1# 3*100# * 3" -> "1 *1, 3 *100 * 3" + * + * */ + { + char *str_found= str; + char *ch= str; - return bUnit_ReplaceString(str, len_max, NULL, scale_pref, system, type); + while((str_found= strchr(str_found, SEP_CHR))) { + + int op_found= 0; + /* any operators after this?*/ + for(ch= str_found+1; *ch!='\0'; ch++) { + + if(*ch==' ' || *ch=='\t') { + /* do nothing */ + } + else if (ch_is_op(*ch) || *ch==',') { /* found an op, no need to insert a ,*/ + op_found= 1; + break; + } + else { /* found a non-op character */ + op_found= 0; + break; + } + } + + *str_found++ = op_found ? ' ':','; + } } // printf("replace %s\n", str); @@ -481,9 +574,9 @@ char *bUnit_GetName(void *usys_pt, int index) { return ((bUnitCollection *)usys_pt)->units[index].name; } -char *bUnit_GetNamePlural(void *usys_pt, int index) +char *bUnit_GetNameDisplay(void *usys_pt, int index) { - return ((bUnitCollection *)usys_pt)->units[index].name_plural; + return ((bUnitCollection *)usys_pt)->units[index].name_display; } double bUnit_GetScaler(void *usys_pt, int index) |