diff options
Diffstat (limited to 'source/blender/blenkernel')
93 files changed, 2957 insertions, 3865 deletions
diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h index aae2be14f1f..e82eb0ed0c9 100644 --- a/source/blender/blenkernel/BKE_anim.h +++ b/source/blender/blenkernel/BKE_anim.h @@ -31,8 +31,6 @@ #ifndef BKE_ANIM_H #define BKE_ANIM_H -#define MAX_DUPLI_RECUR 8 - struct Path; struct Object; struct PartEff; @@ -42,8 +40,6 @@ struct bAnimVizSettings; struct bMotionPath; struct bPoseChannel; -#include "DNA_object_types.h" - /* ---------------------------------------------------- */ /* Animation Visualisation */ @@ -54,7 +50,7 @@ void animviz_free_motionpath(struct bMotionPath *mpath); struct bMotionPath *animviz_verify_motionpaths(struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan); -void animviz_get_object_motionpaths(Object *ob, ListBase *targets); +void animviz_get_object_motionpaths(struct Object *ob, ListBase *targets); void animviz_calc_motionpaths(struct Scene *scene, ListBase *targets); /* ---------------------------------------------------- */ diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h index 2c661a74573..242de4d788b 100644 --- a/source/blender/blenkernel/BKE_armature.h +++ b/source/blender/blenkernel/BKE_armature.h @@ -80,7 +80,6 @@ void free_armature(struct bArmature *arm); void make_local_armature(struct bArmature *arm); struct bArmature *copy_armature(struct bArmature *arm); -void bone_flip_name (char *name, int strip_number); int bone_autoside_name (char *name, int strip_number, short axis, float head, float tail); struct Bone *get_named_bone (struct bArmature *arm, const char *name); diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index 34e8fb420c9..8820edc3adf 100644 --- a/source/blender/blenkernel/BKE_blender.h +++ b/source/blender/blenkernel/BKE_blender.h @@ -44,8 +44,8 @@ struct ReportList; struct Scene; struct Main; -#define BLENDER_VERSION 252 -#define BLENDER_SUBVERSION 5 +#define BLENDER_VERSION 253 +#define BLENDER_SUBVERSION 1 #define BLENDER_MINVERSION 250 #define BLENDER_MINSUBVERSION 0 diff --git a/source/blender/blenkernel/BKE_bmesh.h b/source/blender/blenkernel/BKE_bmesh.h index b6c39697428..c05a940b0f5 100644 --- a/source/blender/blenkernel/BKE_bmesh.h +++ b/source/blender/blenkernel/BKE_bmesh.h @@ -59,7 +59,7 @@ struct BME_Loop; -Remove the eflags completely, they are mostly not used -Remove the selection/vis/bevel weight flag/values ect and move them to custom data -Remove EID member and move to custom data - -Add a radial cycle length, disk cycle length and loop cycle lenght attributes to custom data and have eulers maintain/use them if present. + -Add a radial cycle length, disk cycle length and loop cycle length attributes to custom data and have eulers maintain/use them if present. -Move data such as vertex coordinates/normals to custom data and leave pointers in structures to active layer data. -Remove BME_CycleNode structure? */ diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h index 6a209167f93..0e406a16d0c 100644 --- a/source/blender/blenkernel/BKE_brush.h +++ b/source/blender/blenkernel/BKE_brush.h @@ -44,11 +44,13 @@ struct Brush *copy_brush(struct Brush *brush); void make_local_brush(struct Brush *brush); void free_brush(struct Brush *brush); +void brush_reset_sculpt(struct Brush *brush); + +/* image icon function */ +struct ImBuf *get_brush_icon(struct Brush *brush); + /* brush library operations used by different paint panels */ -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, 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); int brush_clone_image_set_nr(struct Brush *brush, int nr); @@ -85,14 +87,24 @@ void brush_radial_control_invoke(struct wmOperator *op, struct Brush *br, float int brush_radial_control_exec(struct wmOperator *op, struct Brush *br, float size_weight); /* unified strength and size */ -int sculpt_get_brush_size(struct Brush *brush); -void sculpt_set_brush_size(struct Brush *brush, int size); -int sculpt_get_lock_brush_size(struct Brush *brush); -float sculpt_get_brush_unprojected_radius(struct Brush *brush); -void sculpt_set_brush_unprojected_radius(struct Brush *brush, float unprojected_radius); -float sculpt_get_brush_alpha(struct Brush *brush); -void sculpt_set_brush_alpha(struct Brush *brush, float alpha); +int brush_size(struct Brush *brush); +void brush_set_size(struct Brush *brush, int value); + +int brush_use_locked_size(struct Brush *brush); +void brush_set_use_locked_size(struct Brush *brush, int value); + +int brush_use_alpha_pressure(struct Brush *brush); +void brush_set_use_alpha_pressure(struct Brush *brush, int value); + +int brush_use_size_pressure(struct Brush *brush); +void brush_set_use_size_pressure(struct Brush *brush, int value); + +float brush_unprojected_radius(struct Brush *brush); +void brush_set_unprojected_radius(struct Brush *brush, float value); + +float brush_alpha(struct Brush *brush); +void brush_set_alpha(struct Brush *brush, float value); #endif diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h index d8b3fcfd0bb..034bedbb07d 100644 --- a/source/blender/blenkernel/BKE_cloth.h +++ b/source/blender/blenkernel/BKE_cloth.h @@ -33,24 +33,8 @@ #include <float.h> -#include "BLI_linklist.h" -#include "BKE_customdata.h" -#include "BKE_DerivedMesh.h" - -#include "BLI_blenlib.h" -#include "BLI_math.h" -#include "BLI_edgehash.h" - -#include "DNA_cloth_types.h" -#include "DNA_customdata_types.h" -#include "DNA_meshdata_types.h" -#include "DNA_modifier_types.h" -#include "DNA_object_types.h" -#include "DNA_scene_types.h" - -#include "BKE_collision.h" - struct Object; +struct ListBase; struct Scene; struct MFace; struct DerivedMesh; @@ -210,7 +194,7 @@ typedef enum //////////////////////////////////////////////// // needed for implicit.c -int cloth_bvh_objcollision (Object *ob, ClothModifierData * clmd, float step, float dt ); +int cloth_bvh_objcollision (struct Object *ob, struct ClothModifierData * clmd, float step, float dt ); //////////////////////////////////////////////// @@ -220,10 +204,10 @@ int cloth_bvh_objcollision (Object *ob, ClothModifierData * clmd, float step, fl //////////////////////////////////////////////// // needed for cloth.c -int implicit_init ( Object *ob, ClothModifierData *clmd ); -int implicit_free ( ClothModifierData *clmd ); -int implicit_solver ( Object *ob, float frame, ClothModifierData *clmd, ListBase *effectors ); -void implicit_set_positions ( ClothModifierData *clmd ); +int implicit_init ( struct Object *ob, struct ClothModifierData *clmd ); +int implicit_free ( struct ClothModifierData *clmd ); +int implicit_solver ( struct Object *ob, float frame, struct ClothModifierData *clmd, struct ListBase *effectors ); +void implicit_set_positions ( struct ClothModifierData *clmd ); // globally needed void clmdSetInterruptCallBack ( int ( *f ) ( void ) ); @@ -235,23 +219,23 @@ void clmdSetInterruptCallBack ( int ( *f ) ( void ) ); //////////////////////////////////////////////// // needed for modifier.c -void cloth_free_modifier_extern ( ClothModifierData *clmd ); -void cloth_free_modifier ( Object *ob, ClothModifierData *clmd ); -void cloth_init ( ClothModifierData *clmd ); -DerivedMesh *clothModifier_do ( ClothModifierData *clmd, struct Scene *scene, Object *ob, DerivedMesh *dm, int useRenderParams, int isFinalCalc ); +void cloth_free_modifier_extern ( struct ClothModifierData *clmd ); +void cloth_free_modifier ( struct Object *ob, struct ClothModifierData *clmd ); +void cloth_init ( struct ClothModifierData *clmd ); +struct DerivedMesh *clothModifier_do ( struct ClothModifierData *clmd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, int useRenderParams, int isFinalCalc ); -void cloth_update_normals ( ClothVertex *verts, int nVerts, MFace *face, int totface ); -int cloth_uses_vgroup(ClothModifierData *clmd); +void cloth_update_normals ( ClothVertex *verts, int nVerts, struct MFace *face, int totface ); +int cloth_uses_vgroup(struct ClothModifierData *clmd); // needed for collision.c -void bvhtree_update_from_cloth ( ClothModifierData *clmd, int moving ); -void bvhselftree_update_from_cloth ( ClothModifierData *clmd, int moving ); +void bvhtree_update_from_cloth ( struct ClothModifierData *clmd, int moving ); +void bvhselftree_update_from_cloth ( struct ClothModifierData *clmd, int moving ); // needed for button_object.c -void cloth_clear_cache ( Object *ob, ClothModifierData *clmd, float framenr ); +void cloth_clear_cache ( struct Object *ob, struct ClothModifierData *clmd, float framenr ); // needed for cloth.c -int cloth_add_spring ( ClothModifierData *clmd, unsigned int indexA, unsigned int indexB, float restlength, int spring_type); +int cloth_add_spring ( struct ClothModifierData *clmd, unsigned int indexA, unsigned int indexB, float restlength, int spring_type); //////////////////////////////////////////////// @@ -270,9 +254,9 @@ typedef struct { char *name; CM_SOLVER_ID id; - int ( *init ) ( Object *ob, ClothModifierData *clmd ); - int ( *solver ) ( Object *ob, float framenr, ClothModifierData *clmd, ListBase *effectors ); - int ( *free ) ( ClothModifierData *clmd ); + int ( *init ) ( struct Object *ob, struct ClothModifierData *clmd ); + int ( *solver ) ( struct Object *ob, float framenr, struct ClothModifierData *clmd, struct ListBase *effectors ); + int ( *free ) ( struct ClothModifierData *clmd ); } CM_SOLVER_DEF; diff --git a/source/blender/blenkernel/BKE_collision.h b/source/blender/blenkernel/BKE_collision.h index 91c5eb4afee..d7ae7df9342 100644 --- a/source/blender/blenkernel/BKE_collision.h +++ b/source/blender/blenkernel/BKE_collision.h @@ -37,25 +37,21 @@ #include <string.h> /* types */ -#include "BLI_linklist.h" #include "BKE_collision.h" -#include "BKE_customdata.h" -#include "BKE_DerivedMesh.h" #include "DNA_cloth_types.h" -#include "DNA_customdata_types.h" -#include "DNA_meshdata_types.h" -#include "DNA_modifier_types.h" -#include "DNA_object_types.h" #include "BLI_kdopbvh.h" struct Cloth; struct ClothModifierData; +struct CollisionModifierData; struct DerivedMesh; struct Group; struct MFace; +struct MVert; struct Object; struct Scene; +struct LinkNode; //////////////////////////////////////// // used for collisions in collision.c @@ -122,16 +118,16 @@ FaceCollPair; // used in modifier.c from collision.c ///////////////////////////////////////////////// -BVHTree *bvhtree_build_from_mvert ( MFace *mfaces, unsigned int numfaces, MVert *x, unsigned int numverts, float epsilon ); -void bvhtree_update_from_mvert ( BVHTree * bvhtree, MFace *faces, int numfaces, MVert *x, MVert *xnew, int numverts, int moving ); +BVHTree *bvhtree_build_from_mvert ( struct MFace *mfaces, unsigned int numfaces, struct MVert *x, unsigned int numverts, float epsilon ); +void bvhtree_update_from_mvert ( BVHTree * bvhtree, struct MFace *faces, int numfaces, struct MVert *x, struct MVert *xnew, int numverts, int moving ); ///////////////////////////////////////////////// -LinkNode *BLI_linklist_append_fast ( LinkNode **listp, void *ptr ); +struct LinkNode *BLI_linklist_append_fast ( struct LinkNode **listp, void *ptr ); // move Collision modifier object inter-frame with step = [0,1] // defined in collisions.c -void collision_move_object ( CollisionModifierData *collmd, float step, float prevstep ); +void collision_move_object ( struct CollisionModifierData *collmd, float step, float prevstep ); // interface for collision functions void collisions_compute_barycentric ( float pv[3], float p1[3], float p2[3], float p3[3], float *w1, float *w2, float *w3 ); diff --git a/source/blender/blenkernel/BKE_colortools.h b/source/blender/blenkernel/BKE_colortools.h index 1f2dee6dcfc..e0ebedb320b 100644 --- a/source/blender/blenkernel/BKE_colortools.h +++ b/source/blender/blenkernel/BKE_colortools.h @@ -53,9 +53,11 @@ void curvemapping_free(struct CurveMapping *cumap); struct CurveMapping *curvemapping_copy(struct CurveMapping *cumap); void curvemapping_set_black_white(struct CurveMapping *cumap, float *black, float *white); +#define CURVEMAP_SLOPE_NEGATIVE 0 +#define CURVEMAP_SLOPE_POSITIVE 1 +void curvemap_reset(struct CurveMap *cuma, struct rctf *clipr, int preset, int slope); void curvemap_remove(struct CurveMap *cuma, int flag); void curvemap_insert(struct CurveMap *cuma, float x, float y); -void curvemap_reset(struct CurveMap *cuma, struct rctf *clipr, int preset); void curvemap_sethandle(struct CurveMap *cuma, int type); void curvemapping_changed(struct CurveMapping *cumap, int rem_doubles); diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h index ca45c2f318c..db6d995aa74 100644 --- a/source/blender/blenkernel/BKE_curve.h +++ b/source/blender/blenkernel/BKE_curve.h @@ -40,15 +40,15 @@ struct ListBase; struct BezTriple; struct BevList; -#define KNOTSU(nu) ( (nu)->orderu+ (nu)->pntsu+ (((nu)->flagu & CU_NURB_CYCLIC) ? (nu->orderu-1) : 0) ) -#define KNOTSV(nu) ( (nu)->orderv+ (nu)->pntsv+ (((nu)->flagv & CU_NURB_CYCLIC) ? (nu->orderv-1) : 0) ) +#define KNOTSU(nu) ( (nu)->orderu+ (nu)->pntsu+ (((nu)->flagu & CU_NURB_CYCLIC) ? ((nu)->orderu-1) : 0) ) +#define KNOTSV(nu) ( (nu)->orderv+ (nu)->pntsv+ (((nu)->flagv & CU_NURB_CYCLIC) ? ((nu)->orderv-1) : 0) ) /* Non cyclic nurbs have 1 less segment */ #define SEGMENTSU(nu) ( ((nu)->flagu & CU_NURB_CYCLIC) ? (nu)->pntsu : (nu)->pntsu-1 ) #define SEGMENTSV(nu) ( ((nu)->flagv & CU_NURB_CYCLIC) ? (nu)->pntsv : (nu)->pntsv-1 ) #define CU_DO_TILT(cu, nu) (((nu->flag & CU_2D) && (cu->flag & CU_3D)==0) ? 0 : 1) -#define CU_DO_RADIUS(cu, nu) ((CU_DO_TILT(cu, nu) || cu->bevobj || cu->ext1!=0.0 || cu->ext2!=0.0) ? 1:0) +#define CU_DO_RADIUS(cu, nu) ((CU_DO_TILT(cu, nu) || ((cu)->flag & CU_PATH_RADIUS) || (cu)->bevobj || (cu)->ext1!=0.0 || (cu)->ext2!=0.0) ? 1:0) void unlink_curve( struct Curve *cu); @@ -105,5 +105,11 @@ int check_valid_nurb_v( struct Nurb *nu); int clamp_nurb_order_u( struct Nurb *nu); int clamp_nurb_order_v( struct Nurb *nu); +ListBase *BKE_curve_nurbs(struct Curve *cu); + +int minmax_curve(struct Curve *cu, float min[3], float max[3]); +int curve_center_median(struct Curve *cu, float cent[3]); +int curve_center_bounds(struct Curve *cu, float cent[3]); +void curve_translate(struct Curve *cu, float offset[3], int do_keys); #endif diff --git a/source/blender/blenkernel/BKE_deform.h b/source/blender/blenkernel/BKE_deform.h index 702cb100e18..53f474aa972 100644 --- a/source/blender/blenkernel/BKE_deform.h +++ b/source/blender/blenkernel/BKE_deform.h @@ -42,7 +42,7 @@ struct MDeformVert; void defgroup_copy_list(struct ListBase *lb1, struct ListBase *lb2); struct bDeformGroup *defgroup_duplicate(struct bDeformGroup *ingroup); -struct bDeformGroup *defgroup_find_name(struct Object *ob, char *name); +struct bDeformGroup *defgroup_find_name(struct Object *ob, const char *name); int defgroup_find_index(struct Object *ob, struct bDeformGroup *dg); int *defgroup_flip_map(struct Object *ob, int use_default); int defgroup_flip_index(struct Object *ob, int index, int use_default); diff --git a/source/blender/blenkernel/BKE_depsgraph.h b/source/blender/blenkernel/BKE_depsgraph.h index 6a44051806e..0b78a1206fe 100644 --- a/source/blender/blenkernel/BKE_depsgraph.h +++ b/source/blender/blenkernel/BKE_depsgraph.h @@ -70,7 +70,7 @@ int queue_count(struct DagNodeQueue *queue); void queue_delete(struct DagNodeQueue *queue); // queries -struct DagForest *build_dag(struct Scene *sce, short mask); +struct DagForest *build_dag(struct Main *bmain, struct Scene *sce, short mask); void free_forest(struct DagForest *Dag); // note : @@ -97,14 +97,14 @@ void draw_all_deps(void); /* Note that the DAG never executes changes in Objects, only sets flags in Objects */ /* (re)-create dependency graph for scene */ -void DAG_scene_sort(struct Scene *sce); +void DAG_scene_sort(struct Main *bmain, struct Scene *sce); /* flag all objects that need recalc because they're animated */ -void DAG_scene_update_flags(struct Scene *sce, unsigned int lay); +void DAG_scene_update_flags(struct Main *bmain, struct Scene *sce, unsigned int lay); /* flushes all recalc flags in objects down the dependency tree */ -void DAG_scene_flush_update(struct Scene *sce, unsigned int lay, int time); +void DAG_scene_flush_update(struct Main *bmain, struct Scene *sce, unsigned int lay, int time); /* tag objects for update on file load */ -void DAG_on_load_update(void); +void DAG_on_load_update(struct Main *bmain); /* flag all IDs that need recalc because they're animated, influencing this ID only. only for objects currently */ @@ -113,7 +113,7 @@ void DAG_id_update_flags(struct ID *id); but note the DAG only supports objects and object data currently */ void DAG_id_flush_update(struct ID *id, short flag); /* when setting manual RECALC flags, call this afterwards */ -void DAG_ids_flush_update(int time); +void DAG_ids_flush_update(struct Main *bmain, int time); /* (re)-create dependency graph for armature pose */ void DAG_pose_sort(struct Object *ob); diff --git a/source/blender/blenkernel/BKE_displist.h b/source/blender/blenkernel/BKE_displist.h index df0627f61ba..01d3de1b94f 100644 --- a/source/blender/blenkernel/BKE_displist.h +++ b/source/blender/blenkernel/BKE_displist.h @@ -83,7 +83,7 @@ extern void copy_displist(struct ListBase *lbn, struct ListBase *lb); extern void free_disp_elem(DispList *dl); extern DispList *find_displist_create(struct ListBase *lb, int type); extern DispList *find_displist(struct ListBase *lb, int type); -extern void addnormalsDispList(struct Object *ob, struct ListBase *lb); +extern void addnormalsDispList(struct ListBase *lb); extern void count_displist(struct ListBase *lb, int *totvert, int *totface); extern void freedisplist(struct ListBase *lb); extern int displist_has_faces(struct ListBase *lb); diff --git a/source/blender/blenkernel/BKE_effect.h b/source/blender/blenkernel/BKE_effect.h index 837fede3c8a..99f55200eac 100644 --- a/source/blender/blenkernel/BKE_effect.h +++ b/source/blender/blenkernel/BKE_effect.h @@ -31,7 +31,6 @@ #ifndef BKE_EFFECT_H #define BKE_EFFECT_H -#include "DNA_object_types.h" #include "DNA_modifier_types.h" struct Object; diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h index 835e2ed80c8..6de0c55af3b 100644 --- a/source/blender/blenkernel/BKE_fcurve.h +++ b/source/blender/blenkernel/BKE_fcurve.h @@ -143,7 +143,7 @@ typedef enum eFMI_Action_Types { typedef enum eFMI_Requirement_Flags { /* modifier requires original data-points (kindof beats the purpose of a modifier stack?) */ FMI_REQUIRES_ORIGINAL_DATA = (1<<0), - /* modifier doesn't require on any preceeding data (i.e. it will generate a curve). + /* modifier doesn't require on any preceding data (i.e. it will generate a curve). * Use in conjunction with FMI_TYPE_GENRATE_CURVE */ FMI_REQUIRES_NOTHING = (1<<1), diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index d7eb5fe8246..c842efaa3b2 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -159,7 +159,7 @@ void BKE_image_memorypack(struct Image *ima); void BKE_image_print_memlist(void); /* empty image block, of similar type and filename */ -struct Image *BKE_image_copy(struct Image *ima); +struct Image *copy_image(struct Image *ima); /* merge source into dest, and free source */ void BKE_image_merge(struct Image *dest, struct Image *source); diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index cb61a08f3ba..e25c379ded1 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -55,7 +55,7 @@ int new_id(struct ListBase *lb, struct ID *id, const char *name); struct ListBase *which_libbase(struct Main *mainlib, short type); -#define MAX_LIBARRAY 40 +#define MAX_LIBARRAY 39 int set_listbasepointers(struct Main *main, struct ListBase **lb); void free_libblock(struct ListBase *lb, void *idv); @@ -63,8 +63,9 @@ void free_libblock_us(struct ListBase *lb, void *idv); void free_main(struct Main *mainvar); void tag_main(struct Main *mainvar, int tag); -void splitIDname(char *name, char *left, int *nr); +int splitIDname(char *name, char *left, int *nr); void rename_id(struct ID *id, char *name); +void name_uiprefix_id(char *name, struct ID *id); void test_idbutton(char *name); void text_idbutton(struct ID *id, char *text); void all_local(struct Library *lib, int untagged_only); @@ -85,4 +86,3 @@ void set_free_windowmanager_cb(void (*func)(struct bContext *, struct wmWindowMa #define ID_FALLBACK_NAME "Untitled" #endif - diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h index d4d76b2e6e1..60c2d51571f 100644 --- a/source/blender/blenkernel/BKE_main.h +++ b/source/blender/blenkernel/BKE_main.h @@ -58,7 +58,6 @@ typedef struct Main { ListBase mat; ListBase tex; ListBase image; - ListBase wave; ListBase latt; ListBase lamp; ListBase camera; diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h index 07ca5a1c0ee..a220153523e 100644 --- a/source/blender/blenkernel/BKE_material.h +++ b/source/blender/blenkernel/BKE_material.h @@ -35,6 +35,7 @@ extern "C" { #endif +struct Main; struct Material; struct ID; struct Object; @@ -69,9 +70,9 @@ int object_remove_material_slot(struct Object *ob); /* rendering */ void init_render_material(struct Material *, int, float *); -void init_render_materials(int, float *); +void init_render_materials(struct Main *, int, float *); void end_render_material(struct Material *); -void end_render_materials(void); +void end_render_materials(struct Main *); int material_in_material(struct Material *parmat, struct Material *mat); diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 20291611986..c51ba36c93c 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -36,14 +36,16 @@ struct BoundBox; struct DispList; struct ListBase; -struct EditMesh; -struct MDeformVert; +struct BMEditMesh; +struct BMesh; struct Mesh; +struct MPoly; +struct MLoop; struct MFace; struct MEdge; struct MVert; +struct MDeformVert; struct MCol; -struct BMesh; struct Object; struct MTFace; struct VecNor; @@ -168,6 +170,13 @@ int mesh_layers_menu_charlen(struct CustomData *data, int type); /* use this to void mesh_layers_menu_concat(struct CustomData *data, int type, char *str); int mesh_layers_menu(struct CustomData *data, int type); +/* vertex level transformations & checks (no derived mesh) */ + +int minmax_mesh(struct Mesh *me, float min[3], float max[3]); +int mesh_center_median(struct Mesh *me, float cent[3]); +int mesh_center_bounds(struct Mesh *me, float cent[3]); +void mesh_translate(struct Mesh *me, float offset[3], int do_keys); + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 4c7dcff0cd2..4bd4cc3792f 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -36,24 +36,26 @@ /* not very important, but the stack solver likes to know a maximum */ #define MAX_SOCKET 64 -struct ID; -struct bNodeTree; +struct bContext; struct bNode; struct bNodeLink; struct bNodeSocket; struct bNodeStack; -struct uiLayout; -struct rctf; -struct ListBase; -struct RenderData; -struct Scene; -struct Main; -struct Tex; +struct bNodeTree; struct GPUMaterial; struct GPUNode; struct GPUNodeStack; +struct ID; +struct ListBase; +struct Main; +struct MTex; struct PointerRNA; -struct bContext; +struct rctf; +struct RenderData; +struct Scene; +struct Tex; +struct uiLayout; + /* ************** NODE TYPE DEFINITIONS ***** */ @@ -134,6 +136,7 @@ void ntreeMakeOwnType(struct bNodeTree *ntree); void ntreeUpdateType(struct bNodeTree *ntree, struct bNodeType *ntype); void ntreeFreeTree(struct bNodeTree *ntree); struct bNodeTree *ntreeCopyTree(struct bNodeTree *ntree, int internal_select); +void ntreeSwitchID(struct bNodeTree *ntree, struct ID *sce_from, struct ID *sce_to); void ntreeMakeLocal(struct bNodeTree *ntree); void ntreeSocketUseFlags(struct bNodeTree *ntree); diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index 07c3da48792..2a7ba4f98c9 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -83,7 +83,6 @@ struct Lamp *copy_lamp(struct Lamp *la); void make_local_lamp(struct Lamp *la); void free_camera(struct Camera *ca); void free_lamp(struct Lamp *la); -void *add_wave(void); struct Object *add_only_object(int type, char *name); struct Object *add_object(struct Scene *scene, int type); diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index 91fa664bde5..e2d48baba37 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -47,13 +47,11 @@ extern const char PAINT_CURSOR_TEXTURE_PAINT[3]; void paint_init(struct Paint *p, const char col[3]); void free_paint(struct Paint *p); -void copy_paint(struct Paint *orig, struct Paint *new); +void copy_paint(struct Paint *src, struct Paint *tar); 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 diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h index 33a41821fe2..fcef00ae9b3 100644 --- a/source/blender/blenkernel/BKE_particle.h +++ b/source/blender/blenkernel/BKE_particle.h @@ -255,11 +255,9 @@ void psys_threads_free(ParticleThread *threads); void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3], float zvec[3], float center[3]); /* particle_system.c */ -void psys_update_path_cache(struct ParticleSimulationData *sim, float cfra); struct ParticleSystem *psys_get_target_system(struct Object *ob, struct ParticleTarget *pt); void psys_count_keyed_targets(struct ParticleSimulationData *sim); void psys_update_particle_tree(struct ParticleSystem *psys, float cfra); -void psys_update_children(struct ParticleSimulationData *sim); void psys_make_temp_pointcache(struct Object *ob, struct ParticleSystem *psys); void psys_get_pointcache_start_end(struct Scene *scene, ParticleSystem *psys, int *sfra, int *efra); diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h index 03a86b6566a..52536e10e56 100644 --- a/source/blender/blenkernel/BKE_pointcache.h +++ b/source/blender/blenkernel/BKE_pointcache.h @@ -33,8 +33,6 @@ #include "DNA_object_force.h" #include "DNA_boid_types.h" -#include "MEM_guardedalloc.h" - /* Point cache clearing option, for BKE_ptcache_id_clear, before * and after are non inclusive (they wont remove the cfra) */ #define PTCACHE_CLEAR_ALL 0 @@ -70,15 +68,16 @@ #define PTCACHE_READ_OLD 3 /* Structs */ +struct ClothModifierData; +struct ListBase; +struct Main; struct Object; -struct Scene; -struct SoftBody; -struct ParticleSystem; struct ParticleKey; -struct ClothModifierData; -struct SmokeModifierData; +struct ParticleSystem; struct PointCache; -struct ListBase; +struct Scene; +struct SmokeModifierData; +struct SoftBody; /* temp structure for read/write */ typedef struct PTCacheData { @@ -143,6 +142,7 @@ typedef struct PTCacheID { } PTCacheID; typedef struct PTCacheBaker { + struct Main *main; struct Scene *scene; int bake; int render; @@ -273,7 +273,7 @@ int BKE_ptcache_read_cache(PTCacheID *pid, float cfra, float frs_sec); int BKE_ptcache_write_cache(PTCacheID *pid, int cfra); /****************** Continue physics ***************/ -void BKE_ptcache_set_continue_physics(struct Scene *scene, int enable); +void BKE_ptcache_set_continue_physics(struct Main *bmain, struct Scene *scene, int enable); int BKE_ptcache_get_continue_physics(void); /******************* Allocate & free ***************/ @@ -286,7 +286,7 @@ struct PointCache *BKE_ptcache_copy_list(struct ListBase *ptcaches_new, struct L /********************** Baking *********************/ /* Bakes cache with cache_step sized jumps in time, not accurate but very fast. */ -void BKE_ptcache_quick_cache_all(struct Scene *scene); +void BKE_ptcache_quick_cache_all(struct Main *bmain, struct Scene *scene); /* Bake cache or simulate to current frame with settings defined in the baker. */ void BKE_ptcache_make_cache(struct PTCacheBaker* baker); diff --git a/source/blender/blenkernel/BKE_sca.h b/source/blender/blenkernel/BKE_sca.h index 7adbfd9b48d..6cafb7ef104 100644 --- a/source/blender/blenkernel/BKE_sca.h +++ b/source/blender/blenkernel/BKE_sca.h @@ -70,9 +70,9 @@ void set_sca_new_poins_ob(struct Object *ob); void set_sca_new_poins(void); void sca_remove_ob_poin(struct Object *obt, struct Object *ob); -void sca_move_sensor(struct bSensor *sens_to_move, Object *ob, int move_up); -void sca_move_controller(struct bController *cont_to_move, Object *ob, int move_up); -void sca_move_actuator(struct bActuator *act_to_move, Object *ob, int move_up); +void sca_move_sensor(struct bSensor *sens_to_move, struct Object *ob, int move_up); +void sca_move_controller(struct bController *cont_to_move, struct Object *ob, int move_up); +void sca_move_actuator(struct bActuator *act_to_move, struct Object *ob, int move_up); #endif diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h index f0fb2a65673..96ef8d44cf4 100644 --- a/source/blender/blenkernel/BKE_scene.h +++ b/source/blender/blenkernel/BKE_scene.h @@ -31,16 +31,16 @@ #ifndef BKE_SCENE_H #define BKE_SCENE_H +struct AviCodecData; +struct Base; struct bglMats; -struct Scene; +struct Main; struct Object; -struct Base; -struct Text; -struct AviCodecData; struct QuicktimeCodecData; struct RenderData; +struct Scene; +struct Text; struct Text; -struct Main; #define SCE_COPY_EMPTY 0 #define SCE_COPY_LINK_OB 1 @@ -57,8 +57,8 @@ 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); -struct Scene *set_scene_name(char *name); +void set_scene_bg(struct Main *bmain, struct Scene *sce); +struct Scene *set_scene_name(struct Main *bmain, 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); @@ -78,12 +78,12 @@ void scene_deselect_all(struct Scene *sce); void scene_select_base(struct Scene *sce, struct Base *selbase); /* checks for cycle, returns 1 if it's all OK */ -int scene_check_setscene(struct Scene *sce); +int scene_check_setscene(struct Main *bmain, struct Scene *sce); float BKE_curframe(struct Scene *scene); -void scene_update_tagged(struct Scene *sce); -void scene_update_for_newframe(struct Scene *sce, unsigned int lay); +void scene_update_tagged(struct Main *bmain, struct Scene *sce); +void scene_update_for_newframe(struct Main *bmain, struct Scene *sce, unsigned int lay); void scene_add_render_layer(struct Scene *sce); diff --git a/source/blender/blenkernel/BKE_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h index 002a1958a13..a9fb45c6e14 100644 --- a/source/blender/blenkernel/BKE_sequencer.h +++ b/source/blender/blenkernel/BKE_sequencer.h @@ -31,13 +31,14 @@ #ifndef BKE_SEQUENCER_H #define BKE_SEQUENCER_H +struct bContext; struct Editing; +struct ImBuf; +struct Main; +struct Scene; struct Sequence; struct Strip; struct StripElem; -struct ImBuf; -struct Scene; -struct bContext; #define MAXSEQ 32 @@ -107,15 +108,14 @@ struct SeqEffectHandle { 0: no early out, 1: out = ibuf1, 2: out = ibuf2 */ - int (*early_out)(struct Sequence *seq, - float facf0, float facf1); + int (*early_out)(struct Sequence *seq, float facf0, float facf1); /* stores the y-range of the effect IPO */ void (*store_icu_yrange)(struct Sequence * seq, short adrcode, float *ymin, float *ymax); /* stores the default facf0 and facf1 if no IPO is present */ - void (*get_default_fac)(struct Sequence *seq, int cfra, + void (*get_default_fac)(struct Sequence *seq, float cfra, float * facf0, float * facf1); /* execute the effect @@ -123,11 +123,13 @@ struct SeqEffectHandle { float-rects or byte-rects (mixed cases are handled one layer up...) */ - void (*execute)(struct Scene *scene, struct Sequence *seq, int cfra, - float facf0, float facf1, - int x, int y, int preview_render_size, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3, struct ImBuf *out); + struct ImBuf* (*execute)( + struct Main *bmain, + struct Scene *scene, struct Sequence *seq, float cfra, + float facf0, float facf1, + int x, int y, int preview_render_size, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3); }; /* ********************* prototypes *************** */ @@ -146,15 +148,15 @@ void seq_free_editing(struct Scene *scene); void seq_free_clipboard(void); struct Editing *seq_give_editing(struct Scene *scene, int alloc); char *give_seqname(struct Sequence *seq); -struct ImBuf *give_ibuf_seq(struct Scene *scene, int rectx, int recty, int cfra, int chanshown, int render_size); -struct ImBuf *give_ibuf_seq_threaded(struct Scene *scene, int rectx, int recty, int cfra, int chanshown, int render_size); -struct ImBuf *give_ibuf_seq_direct(struct Scene *scene, int rectx, int recty, int cfra, int render_size, struct Sequence *seq); -struct ImBuf *give_ibuf_seqbase(struct Scene *scene, int rectx, int recty, int cfra, int chan_shown, int render_size, struct ListBase *seqbasep); +struct ImBuf *give_ibuf_seq(struct Main *bmain, struct Scene *scene, int rectx, int recty, int cfra, int chanshown, int render_size); +struct ImBuf *give_ibuf_seq_threaded(struct Main *bmain, struct Scene *scene, int rectx, int recty, int cfra, int chanshown, int render_size); +struct ImBuf *give_ibuf_seq_direct(struct Main *bmain, struct Scene *scene, int rectx, int recty, int cfra, int render_size, struct Sequence *seq); +struct ImBuf *give_ibuf_seqbase(struct Main *bmain, struct Scene *scene, int rectx, int recty, int cfra, int chan_shown, int render_size, struct ListBase *seqbasep); void give_ibuf_prefetch_request(int rectx, int recty, int cfra, int chanshown, int render_size); void calc_sequence(struct Scene *scene, struct Sequence *seq); void calc_sequence_disp(struct Scene *scene, struct Sequence *seq); void new_tstripdata(struct Sequence *seq); -void reload_sequence_new_file(struct Scene *scene, struct Sequence * seq, int lock_range); +void reload_sequence_new_file(struct Main *bmain, struct Scene *scene, struct Sequence * seq, int lock_range); void sort_seq(struct Scene *scene); void build_seqar_cb(struct ListBase *seqbase, struct Sequence ***seqar, int *totseq, int (*test_func)(struct Sequence * seq)); @@ -164,6 +166,32 @@ struct StripElem *give_stripelem(struct Sequence *seq, int cfra); // intern? void update_changed_seq_and_deps(struct Scene *scene, struct Sequence *changed_seq, int len_change, int ibuf_change); +int input_have_to_preprocess( + struct Scene *scene, struct Sequence * seq, + float cfra, int seqrectx, int seqrecty); + +/* seqcache.c */ + +typedef enum { + SEQ_STRIPELEM_IBUF, + SEQ_STRIPELEM_IBUF_COMP, + SEQ_STRIPELEM_IBUF_STARTSTILL, + SEQ_STRIPELEM_IBUF_ENDSTILL +} seq_stripelem_ibuf_t; + +void seq_stripelem_cache_init(); +void seq_stripelem_cache_destruct(); + +void seq_stripelem_cache_cleanup(); + +struct ImBuf * seq_stripelem_cache_get( + struct Sequence * seq, int rectx, int recty, + float cfra, seq_stripelem_ibuf_t type); +void seq_stripelem_cache_put( + struct Sequence * seq, int rectx, int recty, + float cfra, seq_stripelem_ibuf_t type, struct ImBuf * nval); + + /* seqeffects.c */ // intern? struct SeqEffectHandle get_sequence_blend(struct Sequence *seq); @@ -191,17 +219,17 @@ void seq_dupe_animdata(struct Scene *scene, char *name_from, char *name_to); int shuffle_seq(struct ListBase * seqbasep, struct Sequence *test, struct Scene *evil_scene); int shuffle_seq_time(ListBase * seqbasep, struct Scene *evil_scene); int seqbase_isolated_sel_check(struct ListBase *seqbase); -void free_imbuf_seq(struct Scene *scene, struct ListBase * seqbasep, int check_mem_usage); +void free_imbuf_seq(struct Scene *scene, struct ListBase * seqbasep, int check_mem_usage, int keep_file_handles); struct Sequence *seq_dupli_recursive(struct Scene *scene, struct Sequence * seq, int dupe_flag); int seq_swap(struct Sequence *seq_a, struct Sequence *seq_b); void seq_update_sound(struct Scene* scene, struct Sequence *seq); void seq_update_muting(struct Scene* scene, struct Editing *ed); -void seqbase_sound_reload(Scene *scene, ListBase *seqbase); +void seqbase_sound_reload(struct Scene *scene, ListBase *seqbase); void seqbase_unique_name_recursive(ListBase *seqbasep, struct Sequence *seq); void seqbase_dupli_recursive(struct Scene *scene, ListBase *nseqbase, ListBase *seqbase, int dupe_flag); -void clear_scene_in_allseqs(struct Scene *sce); +void clear_scene_in_allseqs(struct Main *bmain, struct Scene *sce); struct Sequence *get_seq_by_name(struct ListBase *seqbase, const char *name, int recursive); diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h index 50c86e80b08..190b0400aff 100644 --- a/source/blender/blenkernel/BKE_sound.h +++ b/source/blender/blenkernel/BKE_sound.h @@ -94,6 +94,6 @@ float sound_sync_scene(struct Scene *scene); int sound_scene_playing(struct Scene *scene); -int sound_read_sound_buffer(struct bSound* sound, float* buffer, int length); +int sound_read_sound_buffer(struct bSound* sound, float* buffer, int length, float start, float end); #endif diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index 244fffa06ea..bcda86fdae4 100644 --- a/source/blender/blenkernel/BKE_text.h +++ b/source/blender/blenkernel/BKE_text.h @@ -92,7 +92,7 @@ void unindent (struct Text *text); void comment (struct Text *text); void indent (struct Text *text); void uncomment (struct Text *text); -int setcurr_tab (struct Text *text); +int setcurr_tab_spaces (struct Text *text, int space); void txt_add_marker (struct Text *text, struct TextLine *line, int start, int end, char color[4], int group, int flags); short txt_clear_marker_region (struct Text *text, struct TextLine *line, int start, int end, int group, int flags); diff --git a/source/blender/blenkernel/BKE_texture.h b/source/blender/blenkernel/BKE_texture.h index 39c12a2bfd8..380672dae04 100644 --- a/source/blender/blenkernel/BKE_texture.h +++ b/source/blender/blenkernel/BKE_texture.h @@ -61,6 +61,9 @@ void init_colorband(struct ColorBand *coba, int rangetype); struct ColorBand *add_colorband(int rangetype); int do_colorband(struct ColorBand *coba, float in, float out[4]); void colorband_table_RGBA(struct ColorBand *coba, float **array, int *size); +int vergcband(const void *a1, const void *a2); +struct CBData *colorband_element_add(struct ColorBand *coba, float position); +int colorband_element_remove(struct ColorBand *coba, int index); void default_tex(struct Tex *tex); struct Tex *add_texture(const char *name); diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 09707ba5c91..b196ddc8509 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -46,21 +46,29 @@ IF(WITH_BULLET) ADD_DEFINITIONS(-DUSE_BULLET) ENDIF(WITH_BULLET) -IF(WITH_OPENEXR) +IF(WITH_IMAGE_OPENEXR) ADD_DEFINITIONS(-DWITH_OPENEXR) -ENDIF(WITH_OPENEXR) +ENDIF(WITH_IMAGE_OPENEXR) -IF(WITH_TIFF) +IF(WITH_IMAGE_TIFF) ADD_DEFINITIONS(-DWITH_TIFF) -ENDIF(WITH_TIFF) +ENDIF(WITH_IMAGE_TIFF) -IF(WITH_OPENJPEG) +IF(WITH_IMAGE_OPENJPEG) ADD_DEFINITIONS(-DWITH_OPENJPEG) -ENDIF(WITH_OPENJPEG) +ENDIF(WITH_IMAGE_OPENJPEG) -IF(WITH_DDS) +IF(WITH_IMAGE_DDS) ADD_DEFINITIONS(-DWITH_DDS) -ENDIF(WITH_DDS) +ENDIF(WITH_IMAGE_DDS) + +IF(WITH_IMAGE_CINEON) + ADD_DEFINITIONS(-DWITH_CINEON) +ENDIF(WITH_IMAGE_CINEON) + +IF(WITH_IMAGE_HDR) + ADD_DEFINITIONS(-DWITH_HDR) +ENDIF(WITH_IMAGE_HDR) IF(WITH_QUICKTIME) SET(INC ${INC} ../quicktime ${QUICKTIME_INC}) @@ -87,9 +95,9 @@ IF(WITH_OPENMP) ADD_DEFINITIONS(-DPARALLEL=1) ENDIF(WITH_OPENMP) -IF(NOT WITH_ELBEEM) +IF(NOT WITH_FLUID) ADD_DEFINITIONS(-DDISABLE_ELBEEM) -ENDIF(NOT WITH_ELBEEM) +ENDIF(NOT WITH_FLUID) IF(WITH_LZO) SET(INC ${INC} ../../../extern/lzo/minilzo) diff --git a/source/blender/blenkernel/Makefile b/source/blender/blenkernel/Makefile index f0476bbf026..dc5f0a91da6 100644 --- a/source/blender/blenkernel/Makefile +++ b/source/blender/blenkernel/Makefile @@ -15,7 +15,7 @@ # # 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. +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. # All rights reserved. diff --git a/source/blender/blenkernel/SConscript b/source/blender/blenkernel/SConscript index 88a45ee9302..51c42bf4c7d 100644 --- a/source/blender/blenkernel/SConscript +++ b/source/blender/blenkernel/SConscript @@ -48,6 +48,12 @@ if env['WITH_BF_OPENJPEG']: if env['WITH_BF_DDS']: defs.append('WITH_DDS') +if env['WITH_BF_CINEON']: + defs.append('WITH_CINEON') + +if env['WITH_BF_HDR']: + defs.append('WITH_HDR') + if env['WITH_BF_FFMPEG']: defs.append('WITH_FFMPEG') incs += ' ' + env['BF_FFMPEG_INC'] diff --git a/source/blender/blenkernel/intern/BME_Customdata.c b/source/blender/blenkernel/intern/BME_Customdata.c index 913225a2f73..139f07c3902 100644 --- a/source/blender/blenkernel/intern/BME_Customdata.c +++ b/source/blender/blenkernel/intern/BME_Customdata.c @@ -37,9 +37,9 @@ #include <string.h> +#include "MEM_guardedalloc.h" #include "BKE_bmeshCustomData.h" #include "bmesh_private.h" -#include "MEM_guardedalloc.h" /********************* Layer type information **********************/ typedef struct BME_LayerTypeInfo { diff --git a/source/blender/blenkernel/intern/BME_conversions.c b/source/blender/blenkernel/intern/BME_conversions.c index aab0c0011a0..439b77db9a6 100644 --- a/source/blender/blenkernel/intern/BME_conversions.c +++ b/source/blender/blenkernel/intern/BME_conversions.c @@ -392,9 +392,9 @@ void BME_bmesh_to_editmesh(BME_Mesh *bm, BME_TransData_Head *td, EditMesh *em) { if(e->flag & SELECT) eed->f |= SELECT; //XXX if(e->flag & ME_FGON) eed->h= EM_FGON; // 2 different defines! if(e->flag & ME_HIDE) eed->h |= 1; - if(em->selectmode==SCE_SELECT_EDGE) + if(em->selectmode==SCE_SELECT_EDGE) { ; //XXX EM_select_edge(eed, eed->f & SELECT); - + } CustomData_em_copy_data(&bm->edata, &em->edata, e->data, &eed->data); } } @@ -532,6 +532,7 @@ DerivedMesh *BME_bmesh_to_derivedmesh(BME_Mesh *bm, DerivedMesh *dm) MFace *mface, *mf; MEdge *medge, *me; MVert *mvert, *mv; + int *origindex; int totface,totedge,totvert,i,bmeshok,len, numTex, numCol; BME_Vert *v1=NULL; @@ -579,13 +580,16 @@ DerivedMesh *BME_bmesh_to_derivedmesh(BME_Mesh *bm, DerivedMesh *dm) /*Make Verts*/ mvert = CDDM_get_verts(result); + origindex = result->getVertDataArray(result, CD_ORIGINDEX); for(i=0,v1=bm->verts.first,mv=mvert;v1;v1=v1->next,i++,mv++){ VECCOPY(mv->co,v1->co); mv->flag = (unsigned char)v1->flag; mv->bweight = (char)(255.0*v1->bweight); CustomData_from_bmesh_block(&bm->vdata, &result->vertData, &v1->data, i); + origindex[i] = ORIGINDEX_NONE; } medge = CDDM_get_edges(result); + origindex = result->getEdgeDataArray(result, CD_ORIGINDEX); i=0; for(e=bm->edges.first,me=medge;e;e=e->next){ if(e->tflag2){ @@ -602,12 +606,14 @@ DerivedMesh *BME_bmesh_to_derivedmesh(BME_Mesh *bm, DerivedMesh *dm) me->bweight = (char)(255.0*e->bweight); me->flag = e->flag; CustomData_from_bmesh_block(&bm->edata, &result->edgeData, &e->data, i); + origindex[i] = ORIGINDEX_NONE; me++; i++; } } if(totface){ mface = CDDM_get_tessfaces(result); + origindex = result->getFaceDataArray(result, CD_ORIGINDEX); /*make faces*/ for(i=0,f=bm->polys.first;f;f=f->next){ mf = &mface[i]; @@ -627,6 +633,7 @@ DerivedMesh *BME_bmesh_to_derivedmesh(BME_Mesh *bm, DerivedMesh *dm) mf->flag = (unsigned char)f->flag; CustomData_from_bmesh_block(&bm->pdata, &result->faceData, &f->data, i); BME_DMloops_to_corners(bm, &result->faceData, i, f,numCol,numTex); + origindex[i] = ORIGINDEX_NONE; i++; } } diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 56b0a3bfb68..950ac6f3f4f 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -652,987 +652,6 @@ static DerivedMesh *getMeshDerivedMesh(Mesh *me, Object *ob, float (*vertCos)[3] return dm; } -/// - -typedef struct { - DerivedMesh dm; - - EditMesh *em; - float (*vertexCos)[3]; - float (*vertexNos)[3]; - float (*faceNos)[3]; -} EditMeshDerivedMesh; - -static void emDM_foreachMappedVert(void *dm, void (*func)(void *userData, int index, float *co, float *no_f, short *no_s), void *userData) -{ - EditMeshDerivedMesh *emdm= dm; - EditVert *eve; - int i; - - for (i=0,eve= emdm->em->verts.first; eve; i++,eve=eve->next) { - if (emdm->vertexCos) { - func(userData, i, emdm->vertexCos[i], emdm->vertexNos[i], NULL); - } else { - func(userData, i, eve->co, eve->no, NULL); - } - } -} -static void emDM_foreachMappedEdge(void *dm, void (*func)(void *userData, int index, float *v0co, float *v1co), void *userData) -{ - EditMeshDerivedMesh *emdm= dm; - EditEdge *eed; - int i; - - if (emdm->vertexCos) { - EditVert *eve; - - for (i=0,eve=emdm->em->verts.first; eve; eve= eve->next) - eve->tmp.l = (intptr_t) i++; - for(i=0,eed= emdm->em->edges.first; eed; i++,eed= eed->next) - func(userData, i, emdm->vertexCos[(int) eed->v1->tmp.l], emdm->vertexCos[(int) eed->v2->tmp.l]); - } else { - for(i=0,eed= emdm->em->edges.first; eed; i++,eed= eed->next) - func(userData, i, eed->v1->co, eed->v2->co); - } -} -static void emDM_drawMappedEdges(void *dm, int (*setDrawOptions)(void *userData, int index), void *userData) -{ - EditMeshDerivedMesh *emdm= dm; - EditEdge *eed; - int i; - - if (emdm->vertexCos) { - EditVert *eve; - - for (i=0,eve=emdm->em->verts.first; eve; eve= eve->next) - eve->tmp.l = (intptr_t) i++; - - glBegin(GL_LINES); - for(i=0,eed= emdm->em->edges.first; eed; i++,eed= eed->next) { - if(!setDrawOptions || setDrawOptions(userData, i)) { - glVertex3fv(emdm->vertexCos[(int) eed->v1->tmp.l]); - glVertex3fv(emdm->vertexCos[(int) eed->v2->tmp.l]); - } - } - glEnd(); - } else { - glBegin(GL_LINES); - for(i=0,eed= emdm->em->edges.first; eed; i++,eed= eed->next) { - if(!setDrawOptions || setDrawOptions(userData, i)) { - glVertex3fv(eed->v1->co); - glVertex3fv(eed->v2->co); - } - } - glEnd(); - } -} -static void emDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int drawAllEdges) -{ - emDM_drawMappedEdges(dm, NULL, NULL); -} -static void emDM_drawMappedEdgesInterp(void *dm, int (*setDrawOptions)(void *userData, int index), void (*setDrawInterpOptions)(void *userData, int index, float t), void *userData) -{ - EditMeshDerivedMesh *emdm= dm; - EditEdge *eed; - int i; - - if (emdm->vertexCos) { - EditVert *eve; - - for (i=0,eve=emdm->em->verts.first; eve; eve= eve->next) - eve->tmp.l = (intptr_t) i++; - - glBegin(GL_LINES); - for (i=0,eed= emdm->em->edges.first; eed; i++,eed= eed->next) { - if(!setDrawOptions || setDrawOptions(userData, i)) { - setDrawInterpOptions(userData, i, 0.0); - glVertex3fv(emdm->vertexCos[(int) eed->v1->tmp.l]); - setDrawInterpOptions(userData, i, 1.0); - glVertex3fv(emdm->vertexCos[(int) eed->v2->tmp.l]); - } - } - glEnd(); - } else { - glBegin(GL_LINES); - for (i=0,eed= emdm->em->edges.first; eed; i++,eed= eed->next) { - if(!setDrawOptions || setDrawOptions(userData, i)) { - setDrawInterpOptions(userData, i, 0.0); - glVertex3fv(eed->v1->co); - setDrawInterpOptions(userData, i, 1.0); - glVertex3fv(eed->v2->co); - } - } - glEnd(); - } -} - -static void emDM_drawUVEdges(void *dm) -{ - EditMeshDerivedMesh *emdm= dm; - EditFace *efa; - MTFace *tf; - - glBegin(GL_LINES); - for(efa= emdm->em->faces.first; efa; efa= efa->next) { - tf = CustomData_em_get(&emdm->em->fdata, efa->data, CD_MTFACE); - - if(tf && !(efa->h)) { - glVertex2fv(tf->uv[0]); - glVertex2fv(tf->uv[1]); - - glVertex2fv(tf->uv[1]); - glVertex2fv(tf->uv[2]); - - if (!efa->v4) { - glVertex2fv(tf->uv[2]); - glVertex2fv(tf->uv[0]); - } else { - glVertex2fv(tf->uv[2]); - glVertex2fv(tf->uv[3]); - glVertex2fv(tf->uv[3]); - glVertex2fv(tf->uv[0]); - } - } - } - glEnd(); -} - -static void emDM__calcFaceCent(EditFace *efa, float cent[3], float (*vertexCos)[3]) -{ - if (vertexCos) { - VECCOPY(cent, vertexCos[(int) efa->v1->tmp.l]); - add_v3_v3(cent, vertexCos[(int) efa->v2->tmp.l]); - add_v3_v3(cent, vertexCos[(int) efa->v3->tmp.l]); - if (efa->v4) add_v3_v3(cent, vertexCos[(int) efa->v4->tmp.l]); - } else { - VECCOPY(cent, efa->v1->co); - add_v3_v3(cent, efa->v2->co); - add_v3_v3(cent, efa->v3->co); - if (efa->v4) add_v3_v3(cent, efa->v4->co); - } - - if (efa->v4) { - mul_v3_fl(cent, 0.25f); - } else { - mul_v3_fl(cent, 0.33333333333f); - } -} -static void emDM_foreachMappedFaceCenter(void *dm, void (*func)(void *userData, int index, float *co, float *no), void *userData) -{ - EditMeshDerivedMesh *emdm= dm; - EditVert *eve; - EditFace *efa; - float cent[3]; - int i; - - if (emdm->vertexCos) { - for (i=0,eve=emdm->em->verts.first; eve; eve= eve->next) - eve->tmp.l = (intptr_t) i++; - } - - for(i=0,efa= emdm->em->faces.first; efa; i++,efa= efa->next) { - emDM__calcFaceCent(efa, cent, emdm->vertexCos); - func(userData, i, cent, emdm->vertexCos?emdm->faceNos[i]:efa->n); - } -} -static void emDM_drawMappedFaces(void *dm, int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r), void *userData, int useColors) -{ - EditMeshDerivedMesh *emdm= dm; - EditFace *efa; - int i, draw; - - if (emdm->vertexCos) { - EditVert *eve; - - for (i=0,eve=emdm->em->verts.first; eve; eve= eve->next) - eve->tmp.l = (intptr_t) i++; - - for (i=0,efa= emdm->em->faces.first; efa; i++,efa= efa->next) { - int drawSmooth = (efa->flag & ME_SMOOTH); - draw = setDrawOptions==NULL ? 1 : setDrawOptions(userData, i, &drawSmooth); - if(draw) { - if (draw==2) { /* enabled with stipple */ - glEnable(GL_POLYGON_STIPPLE); - glPolygonStipple(stipple_quarttone); - } - - glShadeModel(drawSmooth?GL_SMOOTH:GL_FLAT); - - glBegin(efa->v4?GL_QUADS:GL_TRIANGLES); - if (!drawSmooth) { - glNormal3fv(emdm->faceNos[i]); - glVertex3fv(emdm->vertexCos[(int) efa->v1->tmp.l]); - glVertex3fv(emdm->vertexCos[(int) efa->v2->tmp.l]); - glVertex3fv(emdm->vertexCos[(int) efa->v3->tmp.l]); - if(efa->v4) glVertex3fv(emdm->vertexCos[(int) efa->v4->tmp.l]); - } else { - glNormal3fv(emdm->vertexNos[(int) efa->v1->tmp.l]); - glVertex3fv(emdm->vertexCos[(int) efa->v1->tmp.l]); - glNormal3fv(emdm->vertexNos[(int) efa->v2->tmp.l]); - glVertex3fv(emdm->vertexCos[(int) efa->v2->tmp.l]); - glNormal3fv(emdm->vertexNos[(int) efa->v3->tmp.l]); - glVertex3fv(emdm->vertexCos[(int) efa->v3->tmp.l]); - if(efa->v4) { - glNormal3fv(emdm->vertexNos[(int) efa->v4->tmp.l]); - glVertex3fv(emdm->vertexCos[(int) efa->v4->tmp.l]); - } - } - glEnd(); - - if (draw==2) - glDisable(GL_POLYGON_STIPPLE); - } - } - } else { - for (i=0,efa= emdm->em->faces.first; efa; i++,efa= efa->next) { - int drawSmooth = (efa->flag & ME_SMOOTH); - draw = setDrawOptions==NULL ? 1 : setDrawOptions(userData, i, &drawSmooth); - if(draw) { - if (draw==2) { /* enabled with stipple */ - glEnable(GL_POLYGON_STIPPLE); - glPolygonStipple(stipple_quarttone); - } - glShadeModel(drawSmooth?GL_SMOOTH:GL_FLAT); - - glBegin(efa->v4?GL_QUADS:GL_TRIANGLES); - if (!drawSmooth) { - glNormal3fv(efa->n); - glVertex3fv(efa->v1->co); - glVertex3fv(efa->v2->co); - glVertex3fv(efa->v3->co); - if(efa->v4) glVertex3fv(efa->v4->co); - } else { - glNormal3fv(efa->v1->no); - glVertex3fv(efa->v1->co); - glNormal3fv(efa->v2->no); - glVertex3fv(efa->v2->co); - glNormal3fv(efa->v3->no); - glVertex3fv(efa->v3->co); - if(efa->v4) { - glNormal3fv(efa->v4->no); - glVertex3fv(efa->v4->co); - } - } - glEnd(); - - if (draw==2) - glDisable(GL_POLYGON_STIPPLE); - } - } - } -} - -static void emDM_drawFacesTex_common(void *dm, - int (*drawParams)(MTFace *tface, MCol *mcol, int matnr), - int (*drawParamsMapped)(void *userData, int index), - void *userData) -{ - EditMeshDerivedMesh *emdm= dm; - EditMesh *em= emdm->em; - float (*vertexCos)[3]= emdm->vertexCos; - float (*vertexNos)[3]= emdm->vertexNos; - EditFace *efa; - int i; - - /* always use smooth shading even for flat faces, else vertex colors wont interpolate */ - glShadeModel(GL_SMOOTH); - - if (vertexCos) { - EditVert *eve; - - for (i=0,eve=em->verts.first; eve; eve= eve->next) - eve->tmp.l = (intptr_t) i++; - - for (i=0,efa= em->faces.first; efa; i++,efa= efa->next) { - MTFace *tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); - MCol *mcol= CustomData_em_get(&em->fdata, efa->data, CD_MCOL); - unsigned char *cp= NULL; - int drawSmooth= (efa->flag & ME_SMOOTH); - int flag; - - if(drawParams) - flag= drawParams(tf, mcol, efa->mat_nr); - else if(drawParamsMapped) - flag= drawParamsMapped(userData, i); - else - flag= 1; - - if(flag != 0) { /* flag 0 == the face is hidden or invisible */ - - /* we always want smooth here since otherwise vertex colors dont interpolate */ - if (mcol) { - if (flag==1) { - cp= (unsigned char*)mcol; - } - } else { - glShadeModel(drawSmooth?GL_SMOOTH:GL_FLAT); - } - - glBegin(efa->v4?GL_QUADS:GL_TRIANGLES); - if (!drawSmooth) { - glNormal3fv(emdm->faceNos[i]); - - if(tf) glTexCoord2fv(tf->uv[0]); - if(cp) glColor3ub(cp[3], cp[2], cp[1]); - glVertex3fv(vertexCos[(int) efa->v1->tmp.l]); - - if(tf) glTexCoord2fv(tf->uv[1]); - if(cp) glColor3ub(cp[7], cp[6], cp[5]); - glVertex3fv(vertexCos[(int) efa->v2->tmp.l]); - - if(tf) glTexCoord2fv(tf->uv[2]); - if(cp) glColor3ub(cp[11], cp[10], cp[9]); - glVertex3fv(vertexCos[(int) efa->v3->tmp.l]); - - if(efa->v4) { - if(tf) glTexCoord2fv(tf->uv[3]); - if(cp) glColor3ub(cp[15], cp[14], cp[13]); - glVertex3fv(vertexCos[(int) efa->v4->tmp.l]); - } - } else { - if(tf) glTexCoord2fv(tf->uv[0]); - if(cp) glColor3ub(cp[3], cp[2], cp[1]); - glNormal3fv(vertexNos[(int) efa->v1->tmp.l]); - glVertex3fv(vertexCos[(int) efa->v1->tmp.l]); - - if(tf) glTexCoord2fv(tf->uv[1]); - if(cp) glColor3ub(cp[7], cp[6], cp[5]); - glNormal3fv(vertexNos[(int) efa->v2->tmp.l]); - glVertex3fv(vertexCos[(int) efa->v2->tmp.l]); - - if(tf) glTexCoord2fv(tf->uv[2]); - if(cp) glColor3ub(cp[11], cp[10], cp[9]); - glNormal3fv(vertexNos[(int) efa->v3->tmp.l]); - glVertex3fv(vertexCos[(int) efa->v3->tmp.l]); - - if(efa->v4) { - if(tf) glTexCoord2fv(tf->uv[3]); - if(cp) glColor3ub(cp[15], cp[14], cp[13]); - glNormal3fv(vertexNos[(int) efa->v4->tmp.l]); - glVertex3fv(vertexCos[(int) efa->v4->tmp.l]); - } - } - glEnd(); - } - } - } else { - for (i=0,efa= em->faces.first; efa; i++,efa= efa->next) { - MTFace *tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); - MCol *mcol= CustomData_em_get(&em->fdata, efa->data, CD_MCOL); - unsigned char *cp= NULL; - int drawSmooth= (efa->flag & ME_SMOOTH); - int flag; - - if(drawParams) - flag= drawParams(tf, mcol, efa->mat_nr); - else if(drawParamsMapped) - flag= drawParamsMapped(userData, i); - else - flag= 1; - - if(flag != 0) { /* flag 0 == the face is hidden or invisible */ - /* we always want smooth here since otherwise vertex colors dont interpolate */ - if (mcol) { - if (flag==1) { - cp= (unsigned char*)mcol; - } - } else { - glShadeModel(drawSmooth?GL_SMOOTH:GL_FLAT); - } - - glBegin(efa->v4?GL_QUADS:GL_TRIANGLES); - if (!drawSmooth) { - glNormal3fv(efa->n); - - if(tf) glTexCoord2fv(tf->uv[0]); - if(cp) glColor3ub(cp[3], cp[2], cp[1]); - glVertex3fv(efa->v1->co); - - if(tf) glTexCoord2fv(tf->uv[1]); - if(cp) glColor3ub(cp[7], cp[6], cp[5]); - glVertex3fv(efa->v2->co); - - if(tf) glTexCoord2fv(tf->uv[2]); - if(cp) glColor3ub(cp[11], cp[10], cp[9]); - glVertex3fv(efa->v3->co); - - if(efa->v4) { - if(tf) glTexCoord2fv(tf->uv[3]); - if(cp) glColor3ub(cp[15], cp[14], cp[13]); - glVertex3fv(efa->v4->co); - } - } else { - if(tf) glTexCoord2fv(tf->uv[0]); - if(cp) glColor3ub(cp[3], cp[2], cp[1]); - glNormal3fv(efa->v1->no); - glVertex3fv(efa->v1->co); - - if(tf) glTexCoord2fv(tf->uv[1]); - if(cp) glColor3ub(cp[7], cp[6], cp[5]); - glNormal3fv(efa->v2->no); - glVertex3fv(efa->v2->co); - - if(tf) glTexCoord2fv(tf->uv[2]); - if(cp) glColor3ub(cp[11], cp[10], cp[9]); - glNormal3fv(efa->v3->no); - glVertex3fv(efa->v3->co); - - if(efa->v4) { - if(tf) glTexCoord2fv(tf->uv[3]); - if(cp) glColor3ub(cp[15], cp[14], cp[13]); - glNormal3fv(efa->v4->no); - glVertex3fv(efa->v4->co); - } - } - glEnd(); - } - } - } -} - -static void emDM_drawFacesTex(void *dm, int (*setDrawOptions)(MTFace *tface, int has_vcol, int matnr)) -{ - emDM_drawFacesTex_common(dm, (int (*)(struct MTFace *, struct MCol *, int))setDrawOptions, NULL, NULL); -} - -static void emDM_drawMappedFacesTex(void *dm, int (*setDrawOptions)(void *userData, int index), void *userData) -{ - emDM_drawFacesTex_common(dm, NULL, setDrawOptions, userData); -} - -static void emDM_drawMappedFacesGLSL(void *dm, - int (*setMaterial)(int, void *attribs), - int (*setDrawOptions)(void *userData, int index), void *userData) -{ - EditMeshDerivedMesh *emdm= dm; - EditMesh *em= emdm->em; - float (*vertexCos)[3]= emdm->vertexCos; - float (*vertexNos)[3]= emdm->vertexNos; - EditVert *eve; - EditFace *efa; - DMVertexAttribs attribs; - GPUVertexAttribs gattribs; - MTFace *tf; - int transp, new_transp, orig_transp, tfoffset; - int i, b, matnr, new_matnr, dodraw, layer; - - dodraw = 0; - matnr = -1; - - transp = GPU_get_material_blend_mode(); - orig_transp = transp; - layer = CustomData_get_layer_index(&em->fdata, CD_MTFACE); - tfoffset = (layer == -1)? -1: em->fdata.layers[layer].offset; - - memset(&attribs, 0, sizeof(attribs)); - - /* always use smooth shading even for flat faces, else vertex colors wont interpolate */ - glShadeModel(GL_SMOOTH); - - for (i=0,eve=em->verts.first; eve; eve= eve->next) - eve->tmp.l = (intptr_t) i++; - -#define PASSATTRIB(efa, eve, vert) { \ - if(attribs.totorco) { \ - float *orco = attribs.orco.array[eve->tmp.l]; \ - glVertexAttrib3fvARB(attribs.orco.glIndex, orco); \ - } \ - for(b = 0; b < attribs.tottface; b++) { \ - MTFace *_tf = (MTFace*)((char*)efa->data + attribs.tface[b].emOffset); \ - glVertexAttrib2fvARB(attribs.tface[b].glIndex, _tf->uv[vert]); \ - } \ - for(b = 0; b < attribs.totmcol; b++) { \ - MCol *cp = (MCol*)((char*)efa->data + attribs.mcol[b].emOffset); \ - GLubyte col[4]; \ - col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; \ - glVertexAttrib4ubvARB(attribs.mcol[b].glIndex, col); \ - } \ - if(attribs.tottang) { \ - float *tang = attribs.tang.array[i*4 + vert]; \ - glVertexAttrib3fvARB(attribs.tang.glIndex, tang); \ - } \ -} - - for (i=0,efa= em->faces.first; efa; i++,efa= efa->next) { - int drawSmooth= (efa->flag & ME_SMOOTH); - - if(setDrawOptions && !setDrawOptions(userData, i)) - continue; - - new_matnr = efa->mat_nr + 1; - if(new_matnr != matnr) { - dodraw = setMaterial(matnr = new_matnr, &gattribs); - if(dodraw) - DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs); - } - - if(tfoffset != -1) { - tf = (MTFace*)((char*)efa->data)+tfoffset; - new_transp = tf->transp; - - if(new_transp != transp) { - if(new_transp == GPU_BLEND_SOLID && orig_transp != GPU_BLEND_SOLID) - GPU_set_material_blend_mode(orig_transp); - else - GPU_set_material_blend_mode(new_transp); - transp = new_transp; - } - } - - if(dodraw) { - glBegin(efa->v4?GL_QUADS:GL_TRIANGLES); - if (!drawSmooth) { - if(vertexCos) glNormal3fv(emdm->faceNos[i]); - else glNormal3fv(efa->n); - - PASSATTRIB(efa, efa->v1, 0); - if(vertexCos) glVertex3fv(vertexCos[(int) efa->v1->tmp.l]); - else glVertex3fv(efa->v1->co); - - PASSATTRIB(efa, efa->v2, 1); - if(vertexCos) glVertex3fv(vertexCos[(int) efa->v2->tmp.l]); - else glVertex3fv(efa->v2->co); - - PASSATTRIB(efa, efa->v3, 2); - if(vertexCos) glVertex3fv(vertexCos[(int) efa->v3->tmp.l]); - else glVertex3fv(efa->v3->co); - - if(efa->v4) { - PASSATTRIB(efa, efa->v4, 3); - if(vertexCos) glVertex3fv(vertexCos[(int) efa->v4->tmp.l]); - else glVertex3fv(efa->v4->co); - } - } else { - PASSATTRIB(efa, efa->v1, 0); - if(vertexCos) { - glNormal3fv(vertexNos[(int) efa->v1->tmp.l]); - glVertex3fv(vertexCos[(int) efa->v1->tmp.l]); - } - else { - glNormal3fv(efa->v1->no); - glVertex3fv(efa->v1->co); - } - - PASSATTRIB(efa, efa->v2, 1); - if(vertexCos) { - glNormal3fv(vertexNos[(int) efa->v2->tmp.l]); - glVertex3fv(vertexCos[(int) efa->v2->tmp.l]); - } - else { - glNormal3fv(efa->v2->no); - glVertex3fv(efa->v2->co); - } - - PASSATTRIB(efa, efa->v3, 2); - if(vertexCos) { - glNormal3fv(vertexNos[(int) efa->v3->tmp.l]); - glVertex3fv(vertexCos[(int) efa->v3->tmp.l]); - } - else { - glNormal3fv(efa->v3->no); - glVertex3fv(efa->v3->co); - } - - if(efa->v4) { - PASSATTRIB(efa, efa->v4, 3); - if(vertexCos) { - glNormal3fv(vertexNos[(int) efa->v4->tmp.l]); - glVertex3fv(vertexCos[(int) efa->v4->tmp.l]); - } - else { - glNormal3fv(efa->v4->no); - glVertex3fv(efa->v4->co); - } - } - } - glEnd(); - } - } -} - -static void emDM_drawFacesGLSL(void *dm, - int (*setMaterial)(int, void *attribs)) -{ - ((DerivedMesh*)dm)->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL); -} - -static void emDM_getMinMax(void *dm, float min_r[3], float max_r[3]) -{ - EditMeshDerivedMesh *emdm= dm; - EditVert *eve; - int i; - - if (emdm->em->verts.first) { - for (i=0,eve= emdm->em->verts.first; eve; i++,eve= eve->next) { - if (emdm->vertexCos) { - DO_MINMAX(emdm->vertexCos[i], min_r, max_r); - } else { - DO_MINMAX(eve->co, min_r, max_r); - } - } - } else { - min_r[0] = min_r[1] = min_r[2] = max_r[0] = max_r[1] = max_r[2] = 0.0; - } -} -static int emDM_getNumVerts(void *dm) -{ - EditMeshDerivedMesh *emdm= dm; - - return BLI_countlist(&emdm->em->verts); -} - -static int emDM_getNumEdges(void *dm) -{ - EditMeshDerivedMesh *emdm= dm; - - return BLI_countlist(&emdm->em->edges); -} - -static int emDM_getNumTessFaces(void *dm) -{ - EditMeshDerivedMesh *emdm= dm; - - return BLI_countlist(&emdm->em->faces); -} - -static void emDM_getVertCos(DerivedMesh *dm, float (*cos_r)[3]) -{ - EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm; - EditVert *eve; - int i; - - for (i=0,eve= emdm->em->verts.first; eve; i++,eve=eve->next) { - if (emdm->vertexCos) { - copy_v3_v3(cos_r[i], emdm->vertexCos[i]); - } else { - copy_v3_v3(cos_r[i], eve->co); - } - } -} - -static void emDM_getVert(DerivedMesh *dm, int index, MVert *vert_r) -{ - EditVert *ev = ((EditMeshDerivedMesh *)dm)->em->verts.first; - int i; - - for(i = 0; i < index; ++i) ev = ev->next; - - VECCOPY(vert_r->co, ev->co); - - vert_r->no[0] = ev->no[0] * 32767.0; - vert_r->no[1] = ev->no[1] * 32767.0; - vert_r->no[2] = ev->no[2] * 32767.0; - - /* TODO what to do with vert_r->flag and vert_r->mat_nr? */ - vert_r->mat_nr = 0; - vert_r->bweight = (unsigned char) (ev->bweight*255.0f); -} - -static void emDM_getEdge(void *dm, int index, MEdge *edge_r) -{ - EditMesh *em = ((EditMeshDerivedMesh *)dm)->em; - EditEdge *ee = em->edges.first; - EditVert *ev, *v1, *v2; - int i; - - for(i = 0; i < index; ++i) ee = ee->next; - - edge_r->crease = (unsigned char) (ee->crease*255.0f); - edge_r->bweight = (unsigned char) (ee->bweight*255.0f); - /* TODO what to do with edge_r->flag? */ - edge_r->flag = ME_EDGEDRAW|ME_EDGERENDER; - if (ee->seam) edge_r->flag |= ME_SEAM; - if (ee->sharp) edge_r->flag |= ME_SHARP; -#if 0 - /* this needs setup of f2 field */ - if (!ee->f2) edge_r->flag |= ME_LOOSEEDGE; -#endif - - /* goddamn, we have to search all verts to find indices */ - v1 = ee->v1; - v2 = ee->v2; - for(i = 0, ev = em->verts.first; v1 || v2; i++, ev = ev->next) { - if(ev == v1) { - edge_r->v1 = i; - v1 = NULL; - } - if(ev == v2) { - edge_r->v2 = i; - v2 = NULL; - } - } -} - -static void emDM_getFace(void *dm, int index, MFace *face_r) -{ - EditMesh *em = ((EditMeshDerivedMesh *)dm)->em; - EditFace *ef = em->faces.first; - EditVert *ev, *v1, *v2, *v3, *v4; - int i; - - for(i = 0; i < index; ++i) ef = ef->next; - - face_r->mat_nr = ef->mat_nr; - face_r->flag = ef->flag; - - /* goddamn, we have to search all verts to find indices */ - v1 = ef->v1; - v2 = ef->v2; - v3 = ef->v3; - v4 = ef->v4; - if(!v4) face_r->v4 = 0; - - for(i = 0, ev = em->verts.first; v1 || v2 || v3 || v4; - i++, ev = ev->next) { - if(ev == v1) { - face_r->v1 = i; - v1 = NULL; - } - if(ev == v2) { - face_r->v2 = i; - v2 = NULL; - } - if(ev == v3) { - face_r->v3 = i; - v3 = NULL; - } - if(ev == v4) { - face_r->v4 = i; - v4 = NULL; - } - } - - test_index_face(face_r, NULL, 0, ef->v4?4:3); -} - -static void emDM_copyVertArray(void *dm, MVert *vert_r) -{ - EditVert *ev = ((EditMeshDerivedMesh *)dm)->em->verts.first; - - for( ; ev; ev = ev->next, ++vert_r) { - VECCOPY(vert_r->co, ev->co); - - vert_r->no[0] = ev->no[0] * 32767.0; - vert_r->no[1] = ev->no[1] * 32767.0; - vert_r->no[2] = ev->no[2] * 32767.0; - - /* TODO what to do with vert_r->flag and vert_r->mat_nr? */ - vert_r->mat_nr = 0; - vert_r->flag = 0; - vert_r->bweight = (unsigned char) (ev->bweight*255.0f); - } -} - -static void emDM_copyEdgeArray(void *dm, MEdge *edge_r) -{ - EditMesh *em = ((EditMeshDerivedMesh *)dm)->em; - EditEdge *ee = em->edges.first; - EditVert *ev; - int i; - - /* store vertex indices in tmp union */ - for(ev = em->verts.first, i = 0; ev; ev = ev->next, ++i) - ev->tmp.l = (intptr_t) i; - - for( ; ee; ee = ee->next, ++edge_r) { - edge_r->crease = (unsigned char) (ee->crease*255.0f); - edge_r->bweight = (unsigned char) (ee->bweight*255.0f); - /* TODO what to do with edge_r->flag? */ - edge_r->flag = ME_EDGEDRAW|ME_EDGERENDER; - if (ee->seam) edge_r->flag |= ME_SEAM; - if (ee->sharp) edge_r->flag |= ME_SHARP; -#if 0 - /* this needs setup of f2 field */ - if (!ee->f2) edge_r->flag |= ME_LOOSEEDGE; -#endif - - edge_r->v1 = (int)ee->v1->tmp.l; - edge_r->v2 = (int)ee->v2->tmp.l; - } -} - -static void emDM_copyFaceArray(void *dm, MFace *face_r) -{ - EditMesh *em = ((EditMeshDerivedMesh *)dm)->em; - EditFace *ef = em->faces.first; - EditVert *ev; - int i; - - /* store vertexes indices in tmp union */ - for(ev = em->verts.first, i = 0; ev; ev = ev->next, ++i) - ev->tmp.l = (intptr_t) i; - - for( ; ef; ef = ef->next, ++face_r) { - face_r->mat_nr = ef->mat_nr; - face_r->flag = ef->flag; - - face_r->v1 = (int)ef->v1->tmp.l; - face_r->v2 = (int)ef->v2->tmp.l; - face_r->v3 = (int)ef->v3->tmp.l; - if(ef->v4) face_r->v4 = (int)ef->v4->tmp.l; - else face_r->v4 = 0; - - test_index_face(face_r, NULL, 0, ef->v4?4:3); - } -} - -static void *emDM_getFaceDataArray(void *dm, int type) -{ - EditMeshDerivedMesh *emdm= dm; - EditMesh *em= emdm->em; - EditFace *efa; - char *data, *emdata; - void *datalayer; - int index, offset, size; - - datalayer = DM_get_tessface_data_layer(dm, type); - if(datalayer) - return datalayer; - - /* layers are store per face for editmesh, we convert to a temporary - * data layer array in the derivedmesh when these are requested */ - if(type == CD_MTFACE || type == CD_MCOL) { - index = CustomData_get_layer_index(&em->fdata, type); - - if(index != -1) { - offset = em->fdata.layers[index].offset; - size = CustomData_sizeof(type); - - DM_add_tessface_layer(dm, type, CD_CALLOC, NULL); - index = CustomData_get_layer_index(&emdm->dm.faceData, type); - emdm->dm.faceData.layers[index].flag |= CD_FLAG_TEMPORARY; - - data = datalayer = DM_get_tessface_data_layer(dm, type); - for(efa=em->faces.first; efa; efa=efa->next, data+=size) { - emdata = CustomData_em_get(&em->fdata, efa->data, type); - memcpy(data, emdata, size); - } - } - } - - return datalayer; -} - -static void emDM_release(void *dm) -{ - EditMeshDerivedMesh *emdm= dm; - - if (DM_release(dm)) { - if (emdm->vertexCos) { - MEM_freeN(emdm->vertexCos); - MEM_freeN(emdm->vertexNos); - MEM_freeN(emdm->faceNos); - } - - MEM_freeN(emdm); - } -} - -static DerivedMesh *getEditMeshDerivedMesh(EditMesh *em, Object *ob, - float (*vertexCos)[3]) -{ -#if 0 - EditMeshDerivedMesh *emdm = MEM_callocN(sizeof(*emdm), "emdm"); - - DM_init(&emdm->dm, DM_TYPE_EDITMESH, BLI_countlist(&em->verts), - BLI_countlist(&em->edges), BLI_countlist(&em->faces), - 0, 0); - - emdm->dm.getMinMax = emDM_getMinMax; - - emdm->dm.getNumVerts = emDM_getNumVerts; - emdm->dm.getNumEdges = emDM_getNumEdges; - emdm->dm.getNumTessFaces = emDM_getNumTessFaces; - - emdm->dm.getVertCos = emDM_getVertCos; - - emdm->dm.getVert = emDM_getVert; - emdm->dm.getEdge = emDM_getEdge; - emdm->dm.getTessFace = emDM_getFace; - emdm->dm.copyVertArray = emDM_copyVertArray; - emdm->dm.copyEdgeArray = emDM_copyEdgeArray; - emdm->dm.copyTessFaceArray = emDM_copyFaceArray; - emdm->dm.getTessFaceDataArray = emDM_getFaceDataArray; - - emdm->dm.foreachMappedVert = emDM_foreachMappedVert; - emdm->dm.foreachMappedEdge = emDM_foreachMappedEdge; - emdm->dm.foreachMappedFaceCenter = emDM_foreachMappedFaceCenter; - - emdm->dm.drawEdges = emDM_drawEdges; - emdm->dm.drawMappedEdges = emDM_drawMappedEdges; - emdm->dm.drawMappedEdgesInterp = emDM_drawMappedEdgesInterp; - emdm->dm.drawMappedFaces = emDM_drawMappedFaces; - emdm->dm.drawMappedFacesTex = emDM_drawMappedFacesTex; - emdm->dm.drawMappedFacesGLSL = emDM_drawMappedFacesGLSL; - emdm->dm.drawFacesTex = emDM_drawFacesTex; - emdm->dm.drawFacesGLSL = emDM_drawFacesGLSL; - emdm->dm.drawUVEdges = emDM_drawUVEdges; - - emdm->dm.release = emDM_release; - - emdm->em = em; - emdm->vertexCos = vertexCos; - - if(CustomData_has_layer(&em->vdata, CD_MDEFORMVERT)) { - EditVert *eve; - int i; - - DM_add_vert_layer(&emdm->dm, CD_MDEFORMVERT, CD_CALLOC, NULL); - - for(eve = em->verts.first, i = 0; eve; eve = eve->next, ++i) - DM_set_vert_data(&emdm->dm, i, CD_MDEFORMVERT, - CustomData_em_get(&em->vdata, eve->data, CD_MDEFORMVERT)); - } - - if(vertexCos) { - EditVert *eve; - EditFace *efa; - int totface = BLI_countlist(&em->faces); - int i; - - for (i=0,eve=em->verts.first; eve; eve= eve->next) - eve->tmp.l = (intptr_t) i++; - - emdm->vertexNos = MEM_callocN(sizeof(*emdm->vertexNos)*i, "emdm_vno"); - emdm->faceNos = MEM_mallocN(sizeof(*emdm->faceNos)*totface, "emdm_vno"); - - for(i=0, efa= em->faces.first; efa; i++, efa=efa->next) { - float *v1 = vertexCos[(int) efa->v1->tmp.l]; - float *v2 = vertexCos[(int) efa->v2->tmp.l]; - float *v3 = vertexCos[(int) efa->v3->tmp.l]; - float *no = emdm->faceNos[i]; - - if(efa->v4) { - float *v4 = vertexCos[(int) efa->v4->tmp.l]; - - normal_quad_v3( no,v1, v2, v3, v4); - add_v3_v3(emdm->vertexNos[(int) efa->v4->tmp.l], no); - } - else { - normal_tri_v3( no,v1, v2, v3); - } - - add_v3_v3(emdm->vertexNos[(int) efa->v1->tmp.l], no); - add_v3_v3(emdm->vertexNos[(int) efa->v2->tmp.l], no); - add_v3_v3(emdm->vertexNos[(int) efa->v3->tmp.l], no); - } - - for(i=0, eve= em->verts.first; eve; i++, eve=eve->next) { - float *no = emdm->vertexNos[i]; - /* following Mesh convention; we use vertex coordinate itself - * for normal in this case */ - if (normalize_v3(no)==0.0) { - VECCOPY(no, vertexCos[i]); - normalize_v3(no); - } - } - } - - return (DerivedMesh*) emdm; -#endif - return NULL; -} - /***/ DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob, ModifierData *md) @@ -1716,7 +735,7 @@ static void *get_orco_coords_dm(Object *ob, BMEditMesh *em, int layer, int *free return NULL; } -static DerivedMesh *create_orco_dm(Object *ob, Mesh *me, EditMesh *em, int layer) +static DerivedMesh *create_orco_dm(Object *ob, Mesh *me, BMEditMesh *em, int layer) { DerivedMesh *dm; float (*orco)[3]; @@ -2832,9 +1851,7 @@ void DM_add_tangent_layer(DerivedMesh *dm) for(j=0; j<len; j++) { vtang= find_vertex_tangent(vtangents[mf_vi[j]], mtface ? tf->uv[j] : uv[j]); - - VECCOPY(tangent[j], vtang); - normalize_v3(tangent[j]); + normalize_v3_v3(tangent[j], vtang); } } @@ -2853,15 +1870,8 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, memset(attribs, 0, sizeof(DMVertexAttribs)); vdata = &dm->vertData; - fdata = &dm->faceData; - - /* ugly hack, editmesh derivedmesh doesn't copy face data, this way we - * can use offsets instead */ - if(dm->release == emDM_release) - tfdata = &((EditMeshDerivedMesh*)dm)->em->fdata; - else - tfdata = fdata; - + fdata = tfdata = dm->getTessFaceDataLayout(dm); + /* add a tangent layer if necessary */ for(b = 0; b < gattribs->totlayer; b++) if(gattribs->layer[b].type == CD_TANGENT) diff --git a/source/blender/blenkernel/intern/Makefile b/source/blender/blenkernel/intern/Makefile index 15c022592f9..53a9999758c 100644 --- a/source/blender/blenkernel/intern/Makefile +++ b/source/blender/blenkernel/intern/Makefile @@ -15,7 +15,7 @@ # # 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. +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. # All rights reserved. @@ -136,8 +136,21 @@ ifeq ($(WITH_TIFF), true) CPPFLAGS += -DWITH_TIFF endif +ifeq ($(WITH_CINEON), true) + CPPFLAGS += -DWITH_CINEON +endif + +ifeq ($(WITH_HDR), true) + CPPFLAGS += -DWITH_HDR +endif + ifeq ($(OS), darwin) ifeq ($(WITH_BF_OPENMP), true) CPPFLAGS += -DPARALLEL=1 endif endif + +ifeq ($(WITH_LCMS), true) + CPPFLAGS += -DWITH_LCMS + CPPFLAGS += -I$(BF_LCMS_INC) +endif diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 6c8e5c48745..90a3a6ce664 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -37,6 +37,7 @@ #include "DNA_armature_types.h" #include "DNA_constraint_types.h" #include "DNA_scene_types.h" +#include "DNA_object_types.h" #include "BKE_animsys.h" #include "BKE_action.h" @@ -301,7 +302,7 @@ void action_groups_add_channel (bAction *act, bActionGroup *agrp, FCurve *fcurve /* firstly, link this F-Curve to the group */ agrp->channels.first = agrp->channels.last = fcurve; - /* step through the groups preceeding this one, finding the F-Curve there to attach this one after */ + /* step through the groups preceding this one, finding the F-Curve there to attach this one after */ for (grp= agrp->prev; grp; grp= grp->prev) { /* if this group has F-Curves, we want weave the given one in right after the last channel there, * but via the Action's list not this group's list @@ -367,20 +368,12 @@ void action_groups_remove_channel (bAction *act, FCurve *fcu) /* Find a group with the given name */ bActionGroup *action_groups_find_named (bAction *act, const char name[]) { - bActionGroup *grp; - /* sanity checks */ if (ELEM3(NULL, act, act->groups.first, name) || (name[0] == 0)) return NULL; /* do string comparisons */ - for (grp= act->groups.first; grp; grp= grp->next) { - if (strcmp(grp->name, name) == 0) - return grp; - } - - /* not found */ - return NULL; + return BLI_findstring(&act->groups, name, offsetof(bActionGroup, name)); } /* *************** Pose channels *************** */ diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index 8c8567fdec9..5d8a57f46f5 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -40,7 +40,6 @@ #include "BLI_math.h" #include "BLI_rand.h" - #include "DNA_anim_types.h" #include "DNA_armature_types.h" #include "DNA_group_types.h" @@ -51,7 +50,6 @@ #include "DNA_view3d_types.h" #include "DNA_vfont_types.h" -#include "BKE_anim.h" #include "BKE_curve.h" #include "BKE_DerivedMesh.h" #include "BKE_depsgraph.h" @@ -69,6 +67,7 @@ #include "BKE_tessmesh.h" #include "BKE_depsgraph.h" + // XXX bad level call... /* --------------------- */ @@ -290,7 +289,7 @@ static void motionpaths_calc_optimise_depsgraph(Scene *scene, ListBase *targets) } /* "brew me a list that's sorted a bit faster now depsy" */ - DAG_scene_sort(scene); + DAG_scene_sort(G.main, scene); } /* update scene for current frame */ @@ -300,7 +299,7 @@ static void motionpaths_calc_update_scene(Scene *scene) Base *base, *last=NULL; /* only stuff that moves or needs display still */ - DAG_scene_update_flags(scene, scene->lay); + DAG_scene_update_flags(G.main, scene, scene->lay); /* find the last object with the tag * - all those afterwards are assumed to not be relevant for our calculations @@ -328,7 +327,7 @@ static void motionpaths_calc_update_scene(Scene *scene) * that doesn't force complete update, but for now, this is the * most accurate way! */ - scene_update_for_newframe(scene, scene->lay); // XXX this is the best way we can get anything moving + scene_update_for_newframe(G.main, scene, scene->lay); // XXX this is the best way we can get anything moving #endif } @@ -461,17 +460,17 @@ void calc_curvepath(Object *ob) float *fp, *dist, *maxdist, xyz[3]; float fac, d=0, fac1, fac2; int a, tot, cycl=0; + ListBase *nurbs; /* in a path vertices are with equal differences: path->len = number of verts */ /* NOW WITH BEVELCURVE!!! */ if(ob==NULL || ob->type != OB_CURVE) return; cu= ob->data; - if(cu->editnurb) - nu= cu->editnurb->first; - else - nu= cu->nurb.first; - + + nurbs= BKE_curve_nurbs(cu); + nu= nurbs->first; + if(cu->path) free_path(cu->path); cu->path= NULL; diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index c44406b5ed4..a482e4051d4 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -46,6 +46,7 @@ #include "DNA_meshdata_types.h" #include "DNA_nla_types.h" #include "DNA_scene_types.h" +#include "DNA_object_types.h" #include "BKE_animsys.h" #include "BKE_armature.h" @@ -246,117 +247,6 @@ Bone *get_named_bone (bArmature *arm, const char *name) return bone; } - -#define IS_SEPARATOR(a) (a=='.' || a==' ' || a=='-' || a=='_') - -/* finds the best possible flipped name. For renaming; check for unique names afterwards */ -/* if strip_number: removes number extensions */ -void bone_flip_name (char *name, int strip_number) -{ - int len; - char prefix[128]={""}; /* The part before the facing */ - char suffix[128]={""}; /* The part after the facing */ - char replace[128]={""}; /* The replacement string */ - char number[128]={""}; /* The number extension string */ - char *index=NULL; - - len= strlen(name); - if(len<3) return; // we don't do names like .R or .L - - /* We first check the case with a .### extension, let's find the last period */ - if(isdigit(name[len-1])) { - index= strrchr(name, '.'); // last occurrence - if (index && isdigit(index[1]) ) { // doesnt handle case bone.1abc2 correct..., whatever! - if(strip_number==0) - strcpy(number, index); - *index= 0; - len= strlen(name); - } - } - - strcpy (prefix, name); - - /* first case; separator . - _ with extensions r R l L */ - if( IS_SEPARATOR(name[len-2]) ) { - switch(name[len-1]) { - case 'l': - prefix[len-1]= 0; - strcpy(replace, "r"); - break; - case 'r': - prefix[len-1]= 0; - strcpy(replace, "l"); - break; - case 'L': - prefix[len-1]= 0; - strcpy(replace, "R"); - break; - case 'R': - prefix[len-1]= 0; - strcpy(replace, "L"); - break; - } - } - /* case; beginning with r R l L , with separator after it */ - else if( IS_SEPARATOR(name[1]) ) { - switch(name[0]) { - case 'l': - strcpy(replace, "r"); - strcpy(suffix, name+1); - prefix[0]= 0; - break; - case 'r': - strcpy(replace, "l"); - strcpy(suffix, name+1); - prefix[0]= 0; - break; - case 'L': - strcpy(replace, "R"); - strcpy(suffix, name+1); - prefix[0]= 0; - break; - case 'R': - strcpy(replace, "L"); - strcpy(suffix, name+1); - prefix[0]= 0; - break; - } - } - else if(len > 5) { - /* hrms, why test for a separator? lets do the rule 'ultimate left or right' */ - index = BLI_strcasestr(prefix, "right"); - if (index==prefix || index==prefix+len-5) { - if(index[0]=='r') - strcpy (replace, "left"); - else { - if(index[1]=='I') - strcpy (replace, "LEFT"); - else - strcpy (replace, "Left"); - } - *index= 0; - strcpy (suffix, index+5); - } - else { - index = BLI_strcasestr(prefix, "left"); - if (index==prefix || index==prefix+len-4) { - if(index[0]=='l') - strcpy (replace, "right"); - else { - if(index[1]=='E') - strcpy (replace, "RIGHT"); - else - strcpy (replace, "Right"); - } - *index= 0; - strcpy (suffix, index+4); - } - } - } - - sprintf (name, "%s%s%s%s", prefix, replace, suffix, number); -} - /* Finds the best possible extension to the name on a particular axis. (For renaming, check for unique names afterwards) * This assumes that bone names are at most 32 chars long! * strip_number: removes number extensions (TODO: not used) @@ -1394,9 +1284,8 @@ void vec_roll_to_mat3(float *vec, float roll, float mat[][3]) float nor[3], axis[3], target[3]={0,1,0}; float theta; float rMatrix[3][3], bMatrix[3][3]; - - VECCOPY (nor, vec); - normalize_v3(nor); + + normalize_v3_v3(nor, vec); /* Find Axis & Amount for bone matrix*/ cross_v3_v3v3(axis,target,nor); diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 590b9f7e476..95e9d419f44 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -43,6 +43,7 @@ #include <stdlib.h> #include <stdio.h> +#include <stddef.h> #include <string.h> #include <fcntl.h> // for open @@ -52,6 +53,7 @@ #include "DNA_scene_types.h" #include "DNA_screen_types.h" #include "DNA_sequence_types.h" +#include "DNA_sound_types.h" #include "BLI_blenlib.h" #include "BLI_dynstr.h" @@ -102,6 +104,7 @@ void free_blender(void) BKE_spacetypes_free(); /* after free main, it uses space callbacks */ IMB_exit(); + seq_stripelem_cache_destruct(); free_nodesystem(); } @@ -312,7 +315,7 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, char *filename) BLI_strncpy(G.main->name, filename, FILE_MAX); /* is guaranteed current file */ /* baseflags, groups, make depsgraph, etc */ - set_scene_bg(CTX_data_scene(C)); + set_scene_bg(G.main, CTX_data_scene(C)); MEM_freeN(bfd); } @@ -477,7 +480,7 @@ static int read_undosave(bContext *C, UndoElem *uel) G.fileflags= fileflags; if(success) - DAG_on_load_update(); + DAG_on_load_update(G.main); return success; } @@ -638,12 +641,8 @@ void BKE_undo_number(bContext *C, int nr) /* go back to the last occurance of name in stack */ void BKE_undo_name(bContext *C, const char *name) { - UndoElem *uel; - - for(uel= undobase.last; uel; uel= uel->prev) { - if(strcmp(name, uel->name)==0) - break; - } + UndoElem *uel= BLI_findstring(&undobase, name, offsetof(UndoElem, name)); + if(uel && uel->prev) { curundo= uel->prev; BKE_undo_step(C, 0); diff --git a/source/blender/blenkernel/intern/boids.c b/source/blender/blenkernel/intern/boids.c index 82602a6951d..7ae65d0113a 100644 --- a/source/blender/blenkernel/intern/boids.c +++ b/source/blender/blenkernel/intern/boids.c @@ -659,9 +659,9 @@ static int rule_fight(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Parti /* attack if in range */ if(closest_dist <= bbd->part->boids->range + pa->size + enemy_pa->size) { float damage = BLI_frand(); - float enemy_dir[3] = {bbd->wanted_co[0],bbd->wanted_co[1],bbd->wanted_co[2]}; + float enemy_dir[3]; - normalize_v3(enemy_dir); + normalize_v3_v3(enemy_dir, bbd->wanted_co); /* fight mode */ bbd->wanted_speed = 0.0f; @@ -786,8 +786,7 @@ static Object *boid_find_ground(BoidBrainData *bbd, ParticleData *pa, float *gro if(hit.index>=0) { t = hit.dist/col.ray_len; interp_v3_v3v3(ground_co, col.co1, col.co2, t); - VECCOPY(ground_nor, col.nor); - normalize_v3(ground_nor); + normalize_v3_v3(ground_nor, col.nor); return col.hit_ob; } else { @@ -1115,8 +1114,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) } VECCOPY(old_dir, pa->prev_state.ave); - VECCOPY(wanted_dir, bbd->wanted_co); - new_speed = normalize_v3(wanted_dir); + new_speed = normalize_v3_v3(wanted_dir, bbd->wanted_co); /* first check if we have valid direction we want to go towards */ if(new_speed == 0.0f) { @@ -1356,8 +1354,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) /* save direction to state.ave unless the boid is falling */ /* (boids can't effect their direction when falling) */ if(bpa->data.mode!=eBoidMode_Falling && len_v3(pa->state.vel) > 0.1*pa->size) { - VECCOPY(pa->state.ave, pa->state.vel); - normalize_v3(pa->state.ave); + normalize_v3_v3(pa->state.ave, pa->state.vel); } /* apply damping */ diff --git a/source/blender/blenkernel/intern/booleanops_mesh.c b/source/blender/blenkernel/intern/booleanops_mesh.c index 431e51cf149..dd595fc98b6 100644 --- a/source/blender/blenkernel/intern/booleanops_mesh.c +++ b/source/blender/blenkernel/intern/booleanops_mesh.c @@ -30,7 +30,6 @@ */ #include "CSG_BooleanOps.h" -#include "MEM_guardedalloc.h" diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index c423d426e32..71a43994363 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_scene_types.h" +#include "DNA_object_types.h" #include "DNA_windowmanager_types.h" #include "WM_types.h" @@ -61,25 +62,24 @@ #include "RE_render_ext.h" /* externtex */ #include "RE_shader_ext.h" -/* Datablock add/copy/free/make_local */ - -Brush *add_brush(const char *name) +static void brush_set_defaults(Brush *brush) { - Brush *brush; + brush->blend = 0; + brush->flag = 0; - brush= alloc_libblock(&G.main->brush, ID_BR, name); + brush->ob_mode = (OB_MODE_SCULPT|OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT); /* BRUSH SCULPT TOOL SETTINGS */ - brush->sculpt_tool = SCULPT_TOOL_DRAW; /* sculpting defaults to the draw tool for new brushes */ brush->size= 35; /* radius of the brush in pixels */ brush->alpha= 0.5f; /* brush strength/intensity probably variable should be renamed? */ brush->autosmooth_factor= 0.0f; brush->crease_pinch_factor= 0.5f; - brush->sculpt_plane = SCULPT_DISP_DIR_VIEW; + brush->sculpt_plane = SCULPT_DISP_DIR_AREA; brush->plane_offset= 0.0f; /* how far above or below the plane that is found by averaging the faces */ brush->plane_trim= 0.5f; brush->clone.alpha= 0.5f; brush->normal_weight= 0.0f; + brush->flag |= BRUSH_ALPHA_PRESSURE; /* BRUSH PAINT TOOL SETTINGS */ brush->rgb[0]= 1.0f; /* default rgb color of the brush when painting - white */ @@ -101,11 +101,10 @@ Brush *add_brush(const char *name) default_mtex(&brush->mtex); brush->texture_sample_bias= 0; /* value to added to texture samples */ + brush->texture_overlay_alpha= 33; /* brush appearance */ - brush->image_icon= NULL; - brush->add_col[0]= 1.00; /* add mode color is light red */ brush->add_col[1]= 0.39; brush->add_col[2]= 0.39; @@ -113,13 +112,25 @@ Brush *add_brush(const char *name) brush->sub_col[0]= 0.39; /* subtract mode color is light blue */ brush->sub_col[1]= 0.39; brush->sub_col[2]= 1.00; +} - /* the default alpha falloff curve */ - brush_curve_preset(brush, CURVE_PRESET_SMOOTH); +/* Datablock add/copy/free/make_local */ + +Brush *add_brush(const char *name) +{ + Brush *brush; + + brush= alloc_libblock(&G.main->brush, ID_BR, name); /* enable fake user by default */ brush->id.flag |= LIB_FAKEUSER; - brush_toggled_fake_user(brush); + + brush_set_defaults(brush); + + brush->sculpt_tool = SCULPT_TOOL_DRAW; /* sculpting defaults to the draw tool for new brushes */ + + /* the default alpha falloff curve */ + brush_curve_preset(brush, CURVE_PRESET_SMOOTH); return brush; } @@ -130,14 +141,18 @@ Brush *copy_brush(Brush *brush) brushn= copy_libblock(brush); - if(brush->mtex.tex) id_us_plus((ID*)brush->mtex.tex); - + if (brush->mtex.tex) + id_us_plus((ID*)brush->mtex.tex); + + if (brush->icon_imbuf) + brushn->icon_imbuf= IMB_dupImBuf(brush->icon_imbuf); + brushn->curve= curvemapping_copy(brush->curve); /* enable fake user by default */ if (!(brushn->id.flag & LIB_FAKEUSER)) { brushn->id.flag |= LIB_FAKEUSER; - brush_toggled_fake_user(brushn); + brushn->id.us++; } return brushn; @@ -146,7 +161,13 @@ Brush *copy_brush(Brush *brush) /* not brush itself */ void free_brush(Brush *brush) { - if(brush->mtex.tex) brush->mtex.tex->id.us--; + if (brush->mtex.tex) + brush->mtex.tex->id.us--; + + if (brush->icon_imbuf) + IMB_freeImBuf(brush->icon_imbuf); + + BKE_previewimg_free(&(brush->preview)); curvemapping_free(brush->curve); } @@ -176,7 +197,7 @@ void make_local_brush(Brush *brush) if(scene->id.lib) lib= 1; else local= 1; } - + if(local && lib==0) { brush->id.lib= 0; brush->id.flag= LIB_LOCAL; @@ -185,7 +206,7 @@ void make_local_brush(Brush *brush) /* enable fake user by default */ if (!(brush->id.flag & LIB_FAKEUSER)) { brush->id.flag |= LIB_FAKEUSER; - brush_toggled_fake_user(brush); + brush->id.us++; } } else if(local && lib) { @@ -203,55 +224,176 @@ void make_local_brush(Brush *brush) } } -/* Library Operations */ - -int brush_set_nr(Brush **current_brush, int nr, const char *name) +void brush_debug_print_state(Brush *br) { - ID *idtest, *id; + Brush def; + + /* create a fake brush and set it to the defaults */ + memset(&def, 0, sizeof(Brush)); + brush_set_defaults(&def); - id= (ID*)(*current_brush); - idtest= (ID*)BLI_findlink(&G.main->brush, nr-1); +#define BR_TEST(field, t) \ + if(br->field != def.field) \ + printf("br->" #field " = %" #t ";\n", br->field) + +#define BR_TEST_FLAG(_f) \ + if((br->flag & _f) && !(def.flag & _f)) \ + printf("br->flag |= " #_f ";\n"); \ + else if(!(br->flag & _f) && (def.flag & _f)) \ + printf("br->flag &= ~" #_f ";\n") - if(idtest==0) { /* new brush */ - if(id) idtest= (ID *)copy_brush((Brush *)id); - else idtest= (ID *)add_brush(name); - idtest->us--; - } - if(idtest!=id) { - brush_delete(current_brush); - *current_brush= (Brush *)idtest; - id_us_plus(idtest); - - return 1; - } - return 0; -} - -int brush_delete(Brush **current_brush) -{ - if (*current_brush) { - (*current_brush)->id.us--; - *current_brush= NULL; - - return 1; - } - - return 0; + /* print out any non-default brush state */ + BR_TEST(normal_weight, f); + + BR_TEST(blend, d); + BR_TEST(size, d); + + /* br->flag */ + BR_TEST_FLAG(BRUSH_AIRBRUSH); + BR_TEST_FLAG(BRUSH_TORUS); + BR_TEST_FLAG(BRUSH_ALPHA_PRESSURE); + BR_TEST_FLAG(BRUSH_SIZE_PRESSURE); + BR_TEST_FLAG(BRUSH_JITTER_PRESSURE); + BR_TEST_FLAG(BRUSH_SPACING_PRESSURE); + BR_TEST_FLAG(BRUSH_FIXED_TEX); + BR_TEST_FLAG(BRUSH_RAKE); + BR_TEST_FLAG(BRUSH_ANCHORED); + BR_TEST_FLAG(BRUSH_DIR_IN); + BR_TEST_FLAG(BRUSH_SPACE); + BR_TEST_FLAG(BRUSH_SMOOTH_STROKE); + BR_TEST_FLAG(BRUSH_PERSISTENT); + BR_TEST_FLAG(BRUSH_ACCUMULATE); + BR_TEST_FLAG(BRUSH_LOCK_ALPHA); + BR_TEST_FLAG(BRUSH_ORIGINAL_NORMAL); + BR_TEST_FLAG(BRUSH_OFFSET_PRESSURE); + BR_TEST_FLAG(BRUSH_SPACE_ATTEN); + BR_TEST_FLAG(BRUSH_ADAPTIVE_SPACE); + BR_TEST_FLAG(BRUSH_LOCK_SIZE); + BR_TEST_FLAG(BRUSH_TEXTURE_OVERLAY); + BR_TEST_FLAG(BRUSH_EDGE_TO_EDGE); + BR_TEST_FLAG(BRUSH_RESTORE_MESH); + BR_TEST_FLAG(BRUSH_INVERSE_SMOOTH_PRESSURE); + BR_TEST_FLAG(BRUSH_RANDOM_ROTATION); + BR_TEST_FLAG(BRUSH_PLANE_TRIM); + BR_TEST_FLAG(BRUSH_FRONTFACE); + BR_TEST_FLAG(BRUSH_CUSTOM_ICON); + + BR_TEST(jitter, f); + BR_TEST(spacing, d); + BR_TEST(smooth_stroke_radius, d); + BR_TEST(smooth_stroke_factor, f); + BR_TEST(rate, f); + + BR_TEST(alpha, f); + + BR_TEST(sculpt_plane, d); + + BR_TEST(plane_offset, f); + + BR_TEST(autosmooth_factor, f); + + BR_TEST(crease_pinch_factor, f); + + BR_TEST(plane_trim, f); + + BR_TEST(texture_sample_bias, f); + BR_TEST(texture_overlay_alpha, d); + + BR_TEST(add_col[0], f); + BR_TEST(add_col[1], f); + BR_TEST(add_col[2], f); + BR_TEST(sub_col[0], f); + BR_TEST(sub_col[1], f); + BR_TEST(sub_col[2], f); + + printf("\n"); + +#undef BR_TEST +#undef BR_TEST_FLAG } -void brush_toggled_fake_user(Brush *brush) +void brush_reset_sculpt(Brush *br) { - ID *id= (ID*)brush; - if(id) { - if(id->flag & LIB_FAKEUSER) { - id_us_plus(id); - } else { - id->us--; - } + /* enable this to see any non-default + settings used by a brush: + + brush_debug_print_state(br); + */ + + brush_set_defaults(br); + brush_curve_preset(br, CURVE_PRESET_SMOOTH); + + switch(br->sculpt_tool) { + case SCULPT_TOOL_CLAY: + br->flag |= BRUSH_FRONTFACE; + break; + case SCULPT_TOOL_CREASE: + br->flag |= BRUSH_DIR_IN; + br->alpha = 0.25; + break; + case SCULPT_TOOL_FILL: + br->add_col[1] = 1; + br->sub_col[0] = 0.25; + br->sub_col[1] = 1; + break; + case SCULPT_TOOL_FLATTEN: + br->add_col[1] = 1; + br->sub_col[0] = 0.25; + br->sub_col[1] = 1; + break; + case SCULPT_TOOL_INFLATE: + br->add_col[0] = 0.750000; + br->add_col[1] = 0.750000; + br->add_col[2] = 0.750000; + br->sub_col[0] = 0.250000; + br->sub_col[1] = 0.250000; + br->sub_col[2] = 0.250000; + break; + case SCULPT_TOOL_NUDGE: + br->add_col[0] = 0.250000; + br->add_col[1] = 1.000000; + br->add_col[2] = 0.250000; + break; + case SCULPT_TOOL_PINCH: + br->add_col[0] = 0.750000; + br->add_col[1] = 0.750000; + br->add_col[2] = 0.750000; + br->sub_col[0] = 0.250000; + br->sub_col[1] = 0.250000; + br->sub_col[2] = 0.250000; + break; + case SCULPT_TOOL_SCRAPE: + br->add_col[1] = 1.000000; + br->sub_col[0] = 0.250000; + br->sub_col[1] = 1.000000; + break; + case SCULPT_TOOL_ROTATE: + break; + case SCULPT_TOOL_SMOOTH: + br->flag &= ~BRUSH_SPACE_ATTEN; + br->spacing = 5; + br->add_col[0] = 0.750000; + br->add_col[1] = 0.750000; + br->add_col[2] = 0.750000; + break; + case SCULPT_TOOL_GRAB: + case SCULPT_TOOL_SNAKE_HOOK: + case SCULPT_TOOL_THUMB: + br->size = 75; + br->flag &= ~BRUSH_ALPHA_PRESSURE; + br->flag &= ~BRUSH_SPACE; + br->flag &= ~BRUSH_SPACE_ATTEN; + br->add_col[0] = 0.250000; + br->add_col[1] = 1.000000; + br->add_col[2] = 0.250000; + break; + default: + break; } } +/* Library Operations */ void brush_curve_preset(Brush *b, /*CurveMappingPreset*/int preset) { CurveMap *cm = NULL; @@ -263,7 +405,7 @@ void brush_curve_preset(Brush *b, /*CurveMappingPreset*/int preset) cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE; b->curve->preset = preset; - curvemap_reset(cm, &b->curve->clipr, b->curve->preset); + curvemap_reset(cm, &b->curve->clipr, b->curve->preset, CURVEMAP_SLOPE_NEGATIVE); curvemapping_changed(b->curve, 0); } @@ -335,12 +477,6 @@ int brush_clone_image_delete(Brush *brush) return 0; } -void brush_check_exists(Brush **brush, const char *name) -{ - if(*brush==NULL) - brush_set_nr(brush, 1, name); -} - /* Brush Sampling */ void brush_sample_tex(Brush *brush, float *xy, float *rgba) { @@ -349,9 +485,10 @@ void brush_sample_tex(Brush *brush, float *xy, float *rgba) if (mtex && mtex->tex) { float co[3], tin, tr, tg, tb, ta; int hasrgb; - - co[0]= xy[0]/(brush->size >> 1); - co[1]= xy[1]/(brush->size >> 1); + const int radius= brush_size(brush); + + co[0]= xy[0]/radius; + co[1]= xy[1]/radius; co[2]= 0.0f; hasrgb= externtex(mtex, co, &tin, &tr, &tg, &tb, &ta); @@ -374,23 +511,24 @@ void brush_sample_tex(Brush *brush, float *xy, float *rgba) } -void brush_imbuf_new(Brush *brush, short flt, short texfall, int size, ImBuf **outbuf) +void brush_imbuf_new(Brush *brush, short flt, short texfall, int bufsize, ImBuf **outbuf) { ImBuf *ibuf; float xy[2], dist, rgba[4], *dstf; int x, y, rowbytes, xoff, yoff, imbflag; - int maxsize = brush->size >> 1; + const int radius= brush_size(brush); char *dst, crgb[3]; + const float alpha= brush_alpha(brush); imbflag= (flt)? IB_rectfloat: IB_rect; - xoff = -size/2.0f + 0.5f; - yoff = -size/2.0f + 0.5f; - rowbytes= size*4; + xoff = -bufsize/2.0f + 0.5f; + yoff = -bufsize/2.0f + 0.5f; + rowbytes= bufsize*4; if (*outbuf) ibuf= *outbuf; else - ibuf= IMB_allocImBuf(size, size, 32, imbflag, 0); + ibuf= IMB_allocImBuf(bufsize, bufsize, 32, imbflag, 0); if (flt) { for (y=0; y < ibuf->y; y++) { @@ -404,7 +542,7 @@ void brush_imbuf_new(Brush *brush, short flt, short texfall, int size, ImBuf **o dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]); VECCOPY(dstf, brush->rgb); - dstf[3]= brush->alpha*brush_curve_strength_clamp(brush, dist, maxsize); + dstf[3]= alpha*brush_curve_strength_clamp(brush, dist, radius); } else if (texfall == 1) { brush_sample_tex(brush, xy, dstf); @@ -417,7 +555,7 @@ void brush_imbuf_new(Brush *brush, short flt, short texfall, int size, ImBuf **o dstf[0] = rgba[0]*brush->rgb[0]; dstf[1] = rgba[1]*brush->rgb[1]; dstf[2] = rgba[2]*brush->rgb[2]; - dstf[3] = rgba[3]*brush->alpha*brush_curve_strength_clamp(brush, dist, maxsize); + dstf[3] = rgba[3]*alpha*brush_curve_strength_clamp(brush, dist, radius); } } } @@ -440,7 +578,7 @@ void brush_imbuf_new(Brush *brush, short flt, short texfall, int size, ImBuf **o dst[0]= crgb[0]; dst[1]= crgb[1]; dst[2]= crgb[2]; - dst[3]= FTOCHAR(brush->alpha*brush_curve_strength(brush, dist, maxsize)); + dst[3]= FTOCHAR(alpha*brush_curve_strength(brush, dist, radius)); } else if (texfall == 1) { brush_sample_tex(brush, xy, rgba); @@ -456,7 +594,7 @@ void brush_imbuf_new(Brush *brush, short flt, short texfall, int size, ImBuf **o dst[0] = FTOCHAR(rgba[0]*brush->rgb[0]); dst[1] = FTOCHAR(rgba[1]*brush->rgb[1]); dst[2] = FTOCHAR(rgba[2]*brush->rgb[2]); - dst[3] = FTOCHAR(rgba[3]*brush->alpha*brush_curve_strength_clamp(brush, dist, maxsize)); + dst[3] = FTOCHAR(rgba[3]*alpha*brush_curve_strength_clamp(brush, dist, radius)); } } } @@ -470,7 +608,7 @@ void brush_imbuf_new(Brush *brush, short flt, short texfall, int size, ImBuf **o typedef struct BrushPainterCache { short enabled; - int size; /* size override, if 0 uses brush->size */ + int size; /* size override, if 0 uses 2*brush_size(brush) */ short flt; /* need float imbuf? */ short texonly; /* no alpha, color or fallof, only texture in imbuf */ @@ -515,8 +653,8 @@ BrushPainter *brush_painter_new(Brush *brush) painter->firsttouch= 1; painter->cache.lastsize= -1; /* force ibuf create in refresh */ - painter->startsize = brush->size; - painter->startalpha = brush->alpha; + painter->startsize = brush_size(brush); + painter->startalpha = brush_alpha(brush); painter->startjitter = brush->jitter; painter->startspacing = brush->spacing; @@ -549,8 +687,8 @@ void brush_painter_free(BrushPainter *painter) { Brush *brush = painter->brush; - brush->size = painter->startsize; - brush->alpha = painter->startalpha; + brush_set_size(brush, painter->startsize); + brush_set_alpha(brush, painter->startalpha); brush->jitter = painter->startjitter; brush->spacing = painter->startspacing; @@ -567,9 +705,10 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, i float *bf, *mf, *tf, *otf=NULL, xoff, yoff, xy[2], rgba[4]; char *b, *m, *t, *ot= NULL; int dotexold, origx= x, origy= y; + const int radius= brush_size(brush); - xoff = -brush->size/2.0f + 0.5f; - yoff = -brush->size/2.0f + 0.5f; + xoff = -radius + 0.5f; + yoff = -radius + 0.5f; xoff += (int)pos[0] - (int)painter->startpaintpos[0]; yoff += (int)pos[1] - (int)painter->startpaintpos[1]; @@ -651,14 +790,15 @@ static void brush_painter_fixed_tex_partial_update(BrushPainter *painter, float BrushPainterCache *cache= &painter->cache; ImBuf *oldtexibuf, *ibuf; int imbflag, destx, desty, srcx, srcy, w, h, x1, y1, x2, y2; + const int diameter= 2*brush_size(brush); imbflag= (cache->flt)? IB_rectfloat: IB_rect; if (!cache->ibuf) - cache->ibuf= IMB_allocImBuf(brush->size, brush->size, 32, imbflag, 0); + cache->ibuf= IMB_allocImBuf(diameter, diameter, 32, imbflag, 0); ibuf= cache->ibuf; oldtexibuf= cache->texibuf; - cache->texibuf= IMB_allocImBuf(brush->size, brush->size, 32, imbflag, 0); + cache->texibuf= IMB_allocImBuf(diameter, diameter, 32, imbflag, 0); if (oldtexibuf) { srcx= srcy= 0; @@ -705,9 +845,13 @@ static void brush_painter_refresh_cache(BrushPainter *painter, float *pos) MTex *mtex= &brush->mtex; int size; short flt; + const int diameter= 2*brush_size(brush); + const float alpha= brush_alpha(brush); - if ((brush->size != cache->lastsize) || (brush->alpha != cache->lastalpha) - || (brush->jitter != cache->lastjitter)) { + if (diameter != cache->lastsize || + alpha != cache->lastalpha || + brush->jitter != cache->lastjitter) + { if (cache->ibuf) { IMB_freeImBuf(cache->ibuf); cache->ibuf= NULL; @@ -718,7 +862,7 @@ static void brush_painter_refresh_cache(BrushPainter *painter, float *pos) } flt= cache->flt; - size= (cache->size)? cache->size: brush->size; + size= (cache->size)? cache->size: diameter; if (!(mtex && mtex->tex) || (mtex->tex->type==0)) { brush_imbuf_new(brush, flt, 0, size, &cache->ibuf); @@ -730,8 +874,8 @@ static void brush_painter_refresh_cache(BrushPainter *painter, float *pos) else brush_imbuf_new(brush, flt, 2, size, &cache->ibuf); - cache->lastsize= brush->size; - cache->lastalpha= brush->alpha; + cache->lastsize= diameter; + cache->lastalpha= alpha; cache->lastjitter= brush->jitter; } else if ((brush->flag & BRUSH_FIXED_TEX) && mtex && mtex->tex) { @@ -750,10 +894,10 @@ void brush_painter_break_stroke(BrushPainter *painter) static void brush_apply_pressure(BrushPainter *painter, Brush *brush, float pressure) { - if (brush->flag & BRUSH_ALPHA_PRESSURE) - brush->alpha = MAX2(0.0, painter->startalpha*pressure); - if (brush->flag & BRUSH_SIZE_PRESSURE) - brush->size = MAX2(1.0, painter->startsize*pressure); + if (brush_use_alpha_pressure(brush)) + brush_set_alpha(brush, MAX2(0.0, painter->startalpha*pressure)); + if (brush_use_size_pressure(brush)) + brush_set_size(brush, MAX2(1.0, painter->startsize*pressure)); if (brush->flag & BRUSH_JITTER_PRESSURE) brush->jitter = MAX2(0.0, painter->startjitter*pressure); if (brush->flag & BRUSH_SPACING_PRESSURE) @@ -764,6 +908,8 @@ void brush_jitter_pos(Brush *brush, float *pos, float *jitterpos) { if(brush->jitter){ float rand_pos[2]; + const int radius= brush_size(brush); + const int diameter= 2*radius; // find random position within a circle of diameter 1 do { @@ -771,8 +917,8 @@ void brush_jitter_pos(Brush *brush, float *pos, float *jitterpos) rand_pos[1] = BLI_frand()-0.5f; } while (len_v2(rand_pos) > 0.5f); - jitterpos[0] = pos[0] + 2*rand_pos[0]*brush->size*brush->jitter; - jitterpos[1] = pos[1] + 2*rand_pos[1]*brush->size*brush->jitter; + jitterpos[0] = pos[0] + 2*rand_pos[0]*diameter*brush->jitter; + jitterpos[1] = pos[1] + 2*rand_pos[1]*diameter*brush->jitter; } else { VECCOPY2D(jitterpos, pos); @@ -811,7 +957,7 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos, doubl double starttime, curtime= time; /* compute brush spacing adapted to brush size */ - spacing= brush->rate; //brush->size*brush->spacing*0.01f; + spacing= brush->rate; //radius*brush->spacing*0.01f; /* setup starting time, direction vector and accumulated time */ starttime= painter->accumtime; @@ -842,11 +988,12 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos, doubl else { float startdistance, spacing, step, paintpos[2], dmousepos[2], finalpos[2]; float t, len, press; + const int radius= brush_size(brush); - /* compute brush spacing adapted to brush size, spacing may depend + /* compute brush spacing adapted to brush radius, spacing may depend on pressure, so update it */ brush_apply_pressure(painter, brush, painter->lastpressure); - spacing= MAX2(1.0f, brush->size)*brush->spacing*0.01f; + spacing= MAX2(1.0f, radius)*brush->spacing*0.01f; /* setup starting distance, direction vector and accumulated distance */ startdistance= painter->accumdistance; @@ -863,7 +1010,7 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos, doubl t = step/len; press= (1.0f-t)*painter->lastpressure + t*pressure; brush_apply_pressure(painter, brush, press); - spacing= MAX2(1.0f, brush->size)*brush->spacing*0.01f; + spacing= MAX2(1.0f, radius)*brush->spacing*0.01f; brush_jitter_pos(brush, paintpos, finalpos); @@ -913,8 +1060,8 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos, doubl painter->lastmousepos[1]= pos[1]; painter->lastpressure= pressure; - brush->alpha = painter->startalpha; - brush->size = painter->startsize; + brush_set_alpha(brush, painter->startalpha); + brush_set_size(brush, painter->startsize); brush->jitter = painter->startjitter; brush->spacing = painter->startspacing; @@ -1033,9 +1180,9 @@ void brush_radial_control_invoke(wmOperator *op, Brush *br, float size_weight) float original_value= 0; if(mode == WM_RADIALCONTROL_SIZE) - original_value = sculpt_get_brush_size(br) * size_weight; + original_value = brush_size(br) * size_weight; else if(mode == WM_RADIALCONTROL_STRENGTH) - original_value = sculpt_get_brush_alpha(br); + original_value = brush_alpha(br); else if(mode == WM_RADIALCONTROL_ANGLE) { MTex *mtex = brush_active_texture(br); if(mtex) @@ -1053,15 +1200,15 @@ int brush_radial_control_exec(wmOperator *op, Brush *br, float size_weight) const float conv = 0.017453293; if(mode == WM_RADIALCONTROL_SIZE) - if (sculpt_get_lock_brush_size(br)) { + if (brush_use_locked_size(br)) { float initial_value = RNA_float_get(op->ptr, "initial_value"); - const float unprojected_radius = sculpt_get_brush_unprojected_radius(br); - sculpt_set_brush_unprojected_radius(br, unprojected_radius * new_value/initial_value * size_weight); + const float unprojected_radius = brush_unprojected_radius(br); + brush_set_unprojected_radius(br, unprojected_radius * new_value/initial_value * size_weight); } else - sculpt_set_brush_size(br, new_value * size_weight); + brush_set_size(br, new_value * size_weight); else if(mode == WM_RADIALCONTROL_STRENGTH) - sculpt_set_brush_alpha(br, new_value); + brush_set_alpha(br, new_value); else if(mode == WM_RADIALCONTROL_ANGLE) { MTex *mtex = brush_active_texture(br); if(mtex) @@ -1070,3 +1217,248 @@ int brush_radial_control_exec(wmOperator *op, Brush *br, float size_weight) return OPERATOR_FINISHED; } + +/* Unified Size and Strength */ + +static void set_unified_settings(Brush *brush, short flag, int value) +{ + Scene *sce; + for (sce= G.main->scene.first; sce; sce= sce->id.next) { + if (sce->toolsettings && + ELEM4(brush, + paint_brush(&(sce->toolsettings->imapaint.paint)), + paint_brush(&(sce->toolsettings->vpaint->paint)), + paint_brush(&(sce->toolsettings->wpaint->paint)), + paint_brush(&(sce->toolsettings->sculpt->paint)))) + { + if (value) + sce->toolsettings->sculpt_paint_settings |= flag; + else + sce->toolsettings->sculpt_paint_settings &= ~flag; + } + } +} + +static short unified_settings(Brush *brush) +{ + Scene *sce; + for (sce= G.main->scene.first; sce; sce= sce->id.next) { + if (sce->toolsettings && + ELEM4(brush, + paint_brush(&(sce->toolsettings->imapaint.paint)), + paint_brush(&(sce->toolsettings->vpaint->paint)), + paint_brush(&(sce->toolsettings->wpaint->paint)), + paint_brush(&(sce->toolsettings->sculpt->paint)))) + { + return sce->toolsettings->sculpt_paint_settings; + } + } + + return 0; +} + +static void set_unified_size(Brush *brush, int value) +{ + Scene *sce; + for (sce= G.main->scene.first; sce; sce= sce->id.next) { + if (sce->toolsettings && + ELEM4(brush, + paint_brush(&(sce->toolsettings->imapaint.paint)), + paint_brush(&(sce->toolsettings->vpaint->paint)), + paint_brush(&(sce->toolsettings->wpaint->paint)), + paint_brush(&(sce->toolsettings->sculpt->paint)))) + { + sce->toolsettings->sculpt_paint_unified_size= value; + } + } +} + +static int unified_size(Brush *brush) +{ + Scene *sce; + for (sce= G.main->scene.first; sce; sce= sce->id.next) { + if (sce->toolsettings && + ELEM4(brush, + paint_brush(&(sce->toolsettings->imapaint.paint)), + paint_brush(&(sce->toolsettings->vpaint->paint)), + paint_brush(&(sce->toolsettings->wpaint->paint)), + paint_brush(&(sce->toolsettings->sculpt->paint)))) + { + return sce->toolsettings->sculpt_paint_unified_size; + } + } + + return 35; // XXX magic number +} + +static void set_unified_alpha(Brush *brush, float value) +{ + Scene *sce; + for (sce= G.main->scene.first; sce; sce= sce->id.next) { + if (sce->toolsettings && + ELEM4(brush, + paint_brush(&(sce->toolsettings->imapaint.paint)), + paint_brush(&(sce->toolsettings->vpaint->paint)), + paint_brush(&(sce->toolsettings->wpaint->paint)), + paint_brush(&(sce->toolsettings->sculpt->paint)))) + { + sce->toolsettings->sculpt_paint_unified_alpha= value; + } + } +} + +static float unified_alpha(Brush *brush) +{ + Scene *sce; + for (sce= G.main->scene.first; sce; sce= sce->id.next) { + if (sce->toolsettings && + ELEM4(brush, + paint_brush(&(sce->toolsettings->imapaint.paint)), + paint_brush(&(sce->toolsettings->vpaint->paint)), + paint_brush(&(sce->toolsettings->wpaint->paint)), + paint_brush(&(sce->toolsettings->sculpt->paint)))) + { + return sce->toolsettings->sculpt_paint_unified_alpha; + } + } + + return 0.5f; // XXX magic number +} + +static void set_unified_unprojected_radius(Brush *brush, float value) +{ + Scene *sce; + for (sce= G.main->scene.first; sce; sce= sce->id.next) { + if (sce->toolsettings && + ELEM4(brush, + paint_brush(&(sce->toolsettings->imapaint.paint)), + paint_brush(&(sce->toolsettings->vpaint->paint)), + paint_brush(&(sce->toolsettings->wpaint->paint)), + paint_brush(&(sce->toolsettings->sculpt->paint)))) + { + sce->toolsettings->sculpt_paint_unified_unprojected_radius= value; + } + } +} + +static float unified_unprojected_radius(Brush *brush) +{ + Scene *sce; + for (sce= G.main->scene.first; sce; sce= sce->id.next) { + if (sce->toolsettings && + ELEM4(brush, + paint_brush(&(sce->toolsettings->imapaint.paint)), + paint_brush(&(sce->toolsettings->vpaint->paint)), + paint_brush(&(sce->toolsettings->wpaint->paint)), + paint_brush(&(sce->toolsettings->sculpt->paint)))) + { + return sce->toolsettings->sculpt_paint_unified_unprojected_radius; + } + } + + return 0.125f; // XXX magic number +} +void brush_set_size(Brush *brush, int size) +{ + if (unified_settings(brush) & SCULPT_PAINT_USE_UNIFIED_SIZE) + set_unified_size(brush, size); + else + brush->size= size; + + //WM_main_add_notifier(NC_BRUSH|NA_EDITED, brush); +} + +int brush_size(Brush *brush) +{ + return (unified_settings(brush) & SCULPT_PAINT_USE_UNIFIED_SIZE) ? unified_size(brush) : brush->size; +} + +void brush_set_use_locked_size(Brush *brush, int value) +{ + if (unified_settings(brush) & SCULPT_PAINT_USE_UNIFIED_SIZE) { + set_unified_settings(brush, SCULPT_PAINT_UNIFIED_LOCK_BRUSH_SIZE, value); + } + else { + if (value) + brush->flag |= BRUSH_LOCK_SIZE; + else + brush->flag &= ~BRUSH_LOCK_SIZE; + } + + //WM_main_add_notifier(NC_BRUSH|NA_EDITED, brush); +} + +int brush_use_locked_size(Brush *brush) +{ + return (unified_settings(brush) & SCULPT_PAINT_USE_UNIFIED_SIZE) ? (unified_settings(brush) & SCULPT_PAINT_UNIFIED_LOCK_BRUSH_SIZE) : (brush->flag & BRUSH_LOCK_SIZE); +} + +void brush_set_use_size_pressure(Brush *brush, int value) +{ + if (unified_settings(brush) & SCULPT_PAINT_USE_UNIFIED_SIZE) { + set_unified_settings(brush, SCULPT_PAINT_UNIFIED_SIZE_PRESSURE, value); + } + else { + if (value) + brush->flag |= BRUSH_SIZE_PRESSURE; + else + brush->flag &= ~BRUSH_SIZE_PRESSURE; + } + + //WM_main_add_notifier(NC_BRUSH|NA_EDITED, brush); +} + +int brush_use_size_pressure(Brush *brush) +{ + return (unified_settings(brush) & SCULPT_PAINT_USE_UNIFIED_SIZE) ? (unified_settings(brush) & SCULPT_PAINT_UNIFIED_SIZE_PRESSURE) : (brush->flag & BRUSH_SIZE_PRESSURE); +} + +void brush_set_use_alpha_pressure(Brush *brush, int value) +{ + if (unified_settings(brush) & SCULPT_PAINT_USE_UNIFIED_ALPHA) { + set_unified_settings(brush, SCULPT_PAINT_UNIFIED_ALPHA_PRESSURE, value); + } + else { + if (value) + brush->flag |= BRUSH_ALPHA_PRESSURE; + else + brush->flag &= ~BRUSH_ALPHA_PRESSURE; + } + + //WM_main_add_notifier(NC_BRUSH|NA_EDITED, brush); +} + +int brush_use_alpha_pressure(Brush *brush) +{ + return (unified_settings(brush) & SCULPT_PAINT_USE_UNIFIED_ALPHA) ? (unified_settings(brush) & SCULPT_PAINT_UNIFIED_ALPHA_PRESSURE) : (brush->flag & BRUSH_ALPHA_PRESSURE); +} + +void brush_set_unprojected_radius(Brush *brush, float unprojected_radius) +{ + if (unified_settings(brush) & SCULPT_PAINT_USE_UNIFIED_SIZE) + set_unified_unprojected_radius(brush, unprojected_radius); + else + brush->unprojected_radius= unprojected_radius; + + //WM_main_add_notifier(NC_BRUSH|NA_EDITED, brush); +} + +float brush_unprojected_radius(Brush *brush) +{ + return (unified_settings(brush) & SCULPT_PAINT_USE_UNIFIED_SIZE) ? unified_unprojected_radius(brush) : brush->unprojected_radius; +} + +void brush_set_alpha(Brush *brush, float alpha) +{ + if (unified_settings(brush) & SCULPT_PAINT_USE_UNIFIED_ALPHA) + set_unified_alpha(brush, alpha); + else + brush->alpha= alpha; + + //WM_main_add_notifier(NC_BRUSH|NA_EDITED, brush); +} + +float brush_alpha(Brush *brush) +{ + return (unified_settings(brush) & SCULPT_PAINT_USE_UNIFIED_ALPHA) ? unified_alpha(brush) : brush->alpha; +} diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 7b6da4dd811..6ad43d72177 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -254,7 +254,8 @@ static void cdDM_drawVerts(DerivedMesh *dm) else { /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */ GPU_vertex_setup(dm); if( !GPU_buffer_legacy(dm) ) { - glDrawArrays(GL_POINTS,0,dm->drawObject->nelements); + if(dm->drawObject->nelements) glDrawArrays(GL_POINTS,0, dm->drawObject->nelements); + else glDrawArrays(GL_POINTS,0, dm->drawObject->nlooseverts); } GPU_buffer_unbind(); } @@ -2082,6 +2083,11 @@ DerivedMesh *CDDM_from_template(DerivedMesh *source, CDDerivedMesh *cddm = cdDM_create("CDDM_from_template dest"); DerivedMesh *dm = &cddm->dm; + /* ensure these are created if they are made on demand */ + source->getVertDataArray(source, CD_ORIGINDEX); + source->getEdgeDataArray(source, CD_ORIGINDEX); + source->getTessFaceDataArray(source, CD_ORIGINDEX); + /* this does a copy of all non mvert/medge/mface layers */ DM_from_template(dm, source, DM_TYPE_CDDM, numVerts, numEdges, numFaces, numLoops, numPolys); @@ -2199,9 +2205,7 @@ void CDDM_calc_normals(DerivedMesh *dm) } } - mv->no[0] = (short)(no[0] * 32767.0f); - mv->no[1] = (short)(no[1] * 32767.0f); - mv->no[2] = (short)(no[2] * 32767.0f); + normal_float_to_short_v3(mv->no, no); } MEM_freeN(temp_nors); diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 44b17265807..8d4bacb977f 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -27,6 +27,14 @@ #include "MEM_guardedalloc.h" +#include "DNA_cloth_types.h" +#include "DNA_scene_types.h" +#include "DNA_object_types.h" +#include "DNA_meshdata_types.h" + +#include "BLI_math.h" +#include "BLI_edgehash.h" + #include "BKE_cdderivedmesh.h" #include "BKE_cloth.h" #include "BKE_effect.h" @@ -149,6 +157,9 @@ void cloth_init ( ClothModifierData *clmd ) if(!clmd->sim_parms->effector_weights) clmd->sim_parms->effector_weights = BKE_add_effector_weights(NULL); + + if(clmd->point_cache) + clmd->point_cache->step = 1; } static BVHTree *bvhselftree_build_from_cloth (ClothModifierData *clmd, float epsilon) diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index 9b49ac9c6ff..af12d23b2c2 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -37,6 +37,11 @@ #include "DNA_object_types.h" #include "DNA_object_force.h" #include "DNA_scene_types.h" +#include "DNA_meshdata_types.h" + +#include "BLI_blenlib.h" +#include "BLI_math.h" +#include "BLI_edgehash.h" #include "BKE_DerivedMesh.h" #include "BKE_global.h" @@ -591,7 +596,7 @@ int cloth_collision_response_static ( ClothModifierData *clmd, CollisionModifier return result; } -//Determines collisions on overlap, collisions are writen to collpair[i] and collision+number_collision_found is returned +//Determines collisions on overlap, collisions are written to collpair[i] and collision+number_collision_found is returned CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, BVHTreeOverlap *overlap, CollPair *collpair ) { ClothModifierData *clmd = ( ClothModifierData * ) md1; @@ -686,8 +691,7 @@ CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, BVHTreeOverlap if ( distance <= ( epsilon1 + epsilon2 + ALMOST_ZERO ) ) { - VECCOPY ( collpair->normal, collpair->vector ); - normalize_v3( collpair->normal ); + normalize_v3_v3( collpair->normal, collpair->vector ); collpair->distance = distance; collpair->flag = 0; diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index a07c18f42f3..90ffa39c88f 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -236,7 +236,7 @@ void curvemap_insert(CurveMap *cuma, float x, float y) cuma->curve= cmp; } -void curvemap_reset(CurveMap *cuma, rctf *clipr, int preset) +void curvemap_reset(CurveMap *cuma, rctf *clipr, int preset, int slope) { if(cuma->curve) MEM_freeN(cuma->curve); @@ -320,6 +320,20 @@ void curvemap_reset(CurveMap *cuma, rctf *clipr, int preset) break; } + /* mirror curve in x direction to have positive slope + * rather than default negative slope */ + if (slope == CURVEMAP_SLOPE_POSITIVE) { + int i, last=cuma->totpoint-1; + CurveMapPoint *newpoints= MEM_dupallocN(cuma->curve); + + for (i=0; i<cuma->totpoint; i++) { + newpoints[i].y = cuma->curve[last-i].y; + } + + MEM_freeN(cuma->curve); + cuma->curve = newpoints; + } + if(cuma->table) { MEM_freeN(cuma->table); cuma->table= NULL; @@ -768,36 +782,55 @@ void curvemapping_evaluate_premulRGBF(CurveMapping *cumap, float *vecout, const vecout[2]= curvemap_evaluateF(cumap->cm+2, fac); } + +#ifdef WITH_LCMS +/* basic error handler, if we dont do this blender will exit */ +static int ErrorReportingFunction(int ErrorCode, const char *ErrorText) +{ + fprintf(stderr, "%s:%d\n", ErrorText, ErrorCode); + return 1; +} +#endif + void colorcorrection_do_ibuf(ImBuf *ibuf, const char *profile) { +#ifdef WITH_LCMS if (ibuf->crect == NULL) { -#ifdef WITH_LCMS - cmsHPROFILE imageProfile, proofingProfile; - cmsHTRANSFORM hTransform; + cmsHPROFILE proofingProfile; - ibuf->crect = MEM_mallocN(ibuf->x*ibuf->y*sizeof(int), "imbuf crect"); - - imageProfile = cmsCreate_sRGBProfile(); - proofingProfile = cmsOpenProfileFromFile(profile, "r"); + /* TODO, move to initialization area of code */ + //cmsSetLogErrorHandler(ErrorReportingFunction); + cmsSetErrorHandler(ErrorReportingFunction); + /* will return NULL if the file isn't fount */ + proofingProfile = cmsOpenProfileFromFile(profile, "r"); + cmsErrorAction(LCMS_ERROR_SHOW); - - hTransform = cmsCreateProofingTransform(imageProfile, TYPE_RGBA_8, imageProfile, TYPE_RGBA_8, - proofingProfile, - INTENT_ABSOLUTE_COLORIMETRIC, - INTENT_ABSOLUTE_COLORIMETRIC, - cmsFLAGS_SOFTPROOFING); - - cmsDoTransform(hTransform, ibuf->rect, ibuf->crect, ibuf->x * ibuf->y); - - cmsDeleteTransform(hTransform); - cmsCloseProfile(imageProfile); - cmsCloseProfile(proofingProfile); -#else - ibuf->crect = ibuf->rect; -#endif + + if(proofingProfile) { + cmsHPROFILE imageProfile; + cmsHTRANSFORM hTransform; + + ibuf->crect = MEM_mallocN(ibuf->x*ibuf->y*sizeof(int), "imbuf crect"); + + imageProfile = cmsCreate_sRGBProfile(); + + + hTransform = cmsCreateProofingTransform(imageProfile, TYPE_RGBA_8, imageProfile, TYPE_RGBA_8, + proofingProfile, + INTENT_ABSOLUTE_COLORIMETRIC, + INTENT_ABSOLUTE_COLORIMETRIC, + cmsFLAGS_SOFTPROOFING); + + cmsDoTransform(hTransform, ibuf->rect, ibuf->crect, ibuf->x * ibuf->y); + + cmsDeleteTransform(hTransform); + cmsCloseProfile(imageProfile); + cmsCloseProfile(proofingProfile); + } } +#endif } /* only used for image editor curves */ diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 673b3c6d482..dbf32c4224f 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -260,7 +260,7 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 /* construct offs_bone the same way it is done in armature.c */ copy_m4_m3(offs_bone, pchan->bone->bone_mat); - VECCOPY(offs_bone[3], pchan->bone->head); + copy_v3_v3(offs_bone[3], pchan->bone->head); offs_bone[3][1]+= pchan->bone->parent->length; if (pchan->bone->flag & BONE_HINGE) { @@ -271,7 +271,7 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 copy_m4_m4(tmat, pchan->bone->parent->arm_mat); /* the location of actual parent transform */ - VECCOPY(tmat[3], offs_bone[3]); + copy_v3_v3(tmat[3], offs_bone[3]); offs_bone[3][0]= offs_bone[3][1]= offs_bone[3][2]= 0.0f; mul_m4_v3(pchan->parent->pose_mat, tmat[3]); @@ -313,7 +313,7 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 /* construct offs_bone the same way it is done in armature.c */ copy_m4_m3(offs_bone, pchan->bone->bone_mat); - VECCOPY(offs_bone[3], pchan->bone->head); + copy_v3_v3(offs_bone[3], pchan->bone->head); offs_bone[3][1]+= pchan->bone->parent->length; if (pchan->bone->flag & BONE_HINGE) { @@ -324,8 +324,8 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 copy_m4_m4(tmat, pchan->bone->parent->arm_mat); /* the location of actual parent transform */ - VECCOPY(tmat[3], offs_bone[3]); - offs_bone[3][0]= offs_bone[3][1]= offs_bone[3][2]= 0.0f; + copy_v3_v3(tmat[3], offs_bone[3]); + zero_v3(offs_bone[3]); mul_m4_v3(pchan->parent->pose_mat, tmat[3]); mul_m4_m4m4(diff_mat, offs_bone, tmat); @@ -404,7 +404,7 @@ static void contarget_get_mesh_mat (Scene *scene, Object *ob, char *substring, f DerivedMesh *dm = NULL; Mesh *me= ob->data; BMEditMesh *em = me->edit_btmesh; - float vec[3] = {0.0f, 0.0f, 0.0f}, tvec[3]; + float vec[3] = {0.0f, 0.0f, 0.0f}; float normal[3] = {0.0f, 0.0f, 0.0f}, plane[3]; float imat[3][3], tmat[3][3]; int dgroup; @@ -481,9 +481,9 @@ static void contarget_get_mesh_mat (Scene *scene, Object *ob, char *substring, f mul_m3_v3(tmat, normal); normalize_v3(normal); - VECCOPY(plane, tmat[1]); + copy_v3_v3(plane, tmat[1]); - VECCOPY(tmat[2], normal); + copy_v3_v3(tmat[2], normal); cross_v3_v3v3(tmat[0], normal, plane); cross_v3_v3v3(tmat[1], tmat[2], tmat[0]); @@ -492,8 +492,7 @@ static void contarget_get_mesh_mat (Scene *scene, Object *ob, char *substring, f /* apply the average coordinate as the new location */ - mul_v3_m4v3(tvec, ob->obmat, vec); - VECCOPY(mat[3], tvec); + mul_v3_m4v3(mat[3], ob->obmat, vec); } } @@ -556,7 +555,7 @@ static void contarget_get_lattice_mat (Object *ob, char *substring, float mat[][ mul_v3_m4v3(tvec, ob->obmat, vec); /* copy new location to matrix */ - VECCOPY(mat[3], tvec); + copy_v3_v3(mat[3], tvec); } /* generic function to get the appropriate matrix for most target cases */ @@ -821,11 +820,11 @@ static void childof_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta copy_m4_m4(invmat, data->invmat); /* extract components of both matrices */ - VECCOPY(loc, ct->matrix[3]); + copy_v3_v3(loc, ct->matrix[3]); mat4_to_eulO(eul, ct->rotOrder, ct->matrix); mat4_to_size(size, ct->matrix); - VECCOPY(loco, invmat[3]); + copy_v3_v3(loco, invmat[3]); mat4_to_eulO(eulo, cob->rotOrder, invmat); mat4_to_size(sizo, invmat); @@ -942,9 +941,8 @@ static void vectomat (float *vec, float *target_up, short axis, short upflag, sh float right[3]; float neg = -1; int right_index; - - copy_v3_v3(n, vec); - if (normalize_v3(n) == 0.0) { + + if (normalize_v3_v3(n, vec) == 0.0) { n[0] = 0.0; n[1] = 0.0; n[2] = 1.0; @@ -955,9 +953,7 @@ static void vectomat (float *vec, float *target_up, short axis, short upflag, sh /* n specifies the transformation of the track axis */ if (flags & TARGET_Z_UP) { /* target Z axis is the global up axis */ - u[0] = target_up[0]; - u[1] = target_up[1]; - u[2] = target_up[2]; + copy_v3_v3(u, target_up); } else { /* world Z axis is the global up axis */ @@ -990,20 +986,13 @@ static void vectomat (float *vec, float *target_up, short axis, short upflag, sh m[right_index][1] = neg * right[1]; m[right_index][2] = neg * right[2]; - m[upflag][0] = proj[0]; - m[upflag][1] = proj[1]; - m[upflag][2] = proj[2]; + copy_v3_v3(m[upflag], proj); - m[axis][0] = n[0]; - m[axis][1] = n[1]; - m[axis][2] = n[2]; + copy_v3_v3(m[axis], n); } /* identity matrix - don't do anything if the two axes are the same */ else { - m[0][0]= m[1][1]= m[2][2]= 1.0; - m[0][1]= m[0][2]= 0.0; - m[1][0]= m[1][2]= 0.0; - m[2][0]= m[2][1]= 0.0; + unit_m3(m); } } @@ -1129,10 +1118,9 @@ static void kinematic_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstra else { float vec[3]; /* move grabtarget into world space */ - VECCOPY(vec, data->grabtarget); - mul_m4_v3(ob->obmat, vec); + mul_v3_m4v3(vec, ob->obmat, data->grabtarget); copy_m4_m4(ct->matrix, ob->obmat); - VECCOPY(ct->matrix[3], vec); + copy_v3_v3(ct->matrix[3], vec); } } else @@ -1267,7 +1255,7 @@ static void followpath_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr copy_m4_m4(totmat, rmat); } - VECCOPY(totmat[3], vec); + copy_v3_v3(totmat[3], vec); mul_serie_m4(ct->matrix, ct->tar->obmat, totmat, NULL, NULL, NULL, NULL, NULL, NULL); } @@ -1386,7 +1374,7 @@ static void rotlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *t float eul[3]; float size[3]; - VECCOPY(loc, cob->matrix[3]); + copy_v3_v3(loc, cob->matrix[3]); mat4_to_size(size, cob->matrix); mat4_to_eulO(eul, cob->rotOrder, cob->matrix); @@ -1547,7 +1535,7 @@ static void loclike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta float offset[3] = {0.0f, 0.0f, 0.0f}; if (data->flag & LOCLIKE_OFFSET) - VECCOPY(offset, cob->matrix[3]); + copy_v3_v3(offset, cob->matrix[3]); if (data->flag & LOCLIKE_X) { cob->matrix[3][0] = ct->matrix[3][0]; @@ -1639,7 +1627,7 @@ static void rotlike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta float eul[3], obeul[3]; float size[3]; - VECCOPY(loc, cob->matrix[3]); + copy_v3_v3(loc, cob->matrix[3]); mat4_to_size(size, cob->matrix); /* to allow compatible rotations, must get both rotations in the order of the owner... */ @@ -2141,7 +2129,7 @@ static void actcon_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraint } else { /* extract location */ - VECCOPY(vec, tempmat[3]); + copy_v3_v3(vec, tempmat[3]); axis= data->type - 20; } @@ -2297,10 +2285,7 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * normalize_v3(totmat[1]); /* the x axis is fixed */ - totmat[0][0] = cob->matrix[0][0]; - totmat[0][1] = cob->matrix[0][1]; - totmat[0][2] = cob->matrix[0][2]; - normalize_v3(totmat[0]); + normalize_v3_v3(totmat[0], cob->matrix[0]); /* the z axis gets mapped onto a third orthogonal vector */ cross_v3_v3v3(totmat[2], totmat[0], totmat[1]); @@ -2314,10 +2299,7 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * normalize_v3(totmat[2]); /* the x axis is fixed */ - totmat[0][0] = cob->matrix[0][0]; - totmat[0][1] = cob->matrix[0][1]; - totmat[0][2] = cob->matrix[0][2]; - normalize_v3(totmat[0]); + normalize_v3_v3(totmat[0], cob->matrix[0]); /* the z axis gets mapped onto a third orthogonal vector */ cross_v3_v3v3(totmat[1], totmat[2], totmat[0]); @@ -2332,10 +2314,7 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * negate_v3(totmat[1]); /* the x axis is fixed */ - totmat[0][0] = cob->matrix[0][0]; - totmat[0][1] = cob->matrix[0][1]; - totmat[0][2] = cob->matrix[0][2]; - normalize_v3(totmat[0]); + normalize_v3_v3(totmat[0], cob->matrix[0]); /* the z axis gets mapped onto a third orthogonal vector */ cross_v3_v3v3(totmat[2], totmat[0], totmat[1]); @@ -2350,10 +2329,7 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * negate_v3(totmat[2]); /* the x axis is fixed */ - totmat[0][0] = cob->matrix[0][0]; - totmat[0][1] = cob->matrix[0][1]; - totmat[0][2] = cob->matrix[0][2]; - normalize_v3(totmat[0]); + normalize_v3_v3(totmat[0], cob->matrix[0]); /* the z axis gets mapped onto a third orthogonal vector */ cross_v3_v3v3(totmat[1], totmat[2], totmat[0]); @@ -2361,9 +2337,7 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * break; default: { - totmat[0][0] = 1;totmat[0][1] = 0;totmat[0][2] = 0; - totmat[1][0] = 0;totmat[1][1] = 1;totmat[1][2] = 0; - totmat[2][0] = 0;totmat[2][1] = 0;totmat[2][2] = 1; + unit_m3(totmat); } break; } @@ -2380,11 +2354,8 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * normalize_v3(totmat[0]); /* the y axis is fixed */ - totmat[1][0] = cob->matrix[1][0]; - totmat[1][1] = cob->matrix[1][1]; - totmat[1][2] = cob->matrix[1][2]; - normalize_v3(totmat[1]); - + normalize_v3_v3(totmat[1], cob->matrix[1]); + /* the z axis gets mapped onto a third orthogonal vector */ cross_v3_v3v3(totmat[2], totmat[0], totmat[1]); } @@ -2397,10 +2368,7 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * normalize_v3(totmat[2]); /* the y axis is fixed */ - totmat[1][0] = cob->matrix[1][0]; - totmat[1][1] = cob->matrix[1][1]; - totmat[1][2] = cob->matrix[1][2]; - normalize_v3(totmat[1]); + normalize_v3_v3(totmat[1], cob->matrix[1]); /* the z axis gets mapped onto a third orthogonal vector */ cross_v3_v3v3(totmat[0], totmat[1], totmat[2]); @@ -2415,10 +2383,7 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * negate_v3(totmat[0]); /* the y axis is fixed */ - totmat[1][0] = cob->matrix[1][0]; - totmat[1][1] = cob->matrix[1][1]; - totmat[1][2] = cob->matrix[1][2]; - normalize_v3(totmat[1]); + normalize_v3_v3(totmat[1], cob->matrix[1]); /* the z axis gets mapped onto a third orthogonal vector */ cross_v3_v3v3(totmat[2], totmat[0], totmat[1]); @@ -2433,10 +2398,7 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * negate_v3(totmat[2]); /* the y axis is fixed */ - totmat[1][0] = cob->matrix[1][0]; - totmat[1][1] = cob->matrix[1][1]; - totmat[1][2] = cob->matrix[1][2]; - normalize_v3(totmat[1]); + normalize_v3_v3(totmat[1], cob->matrix[1]); /* the z axis gets mapped onto a third orthogonal vector */ cross_v3_v3v3(totmat[0], totmat[1], totmat[2]); @@ -2444,9 +2406,7 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * break; default: { - totmat[0][0] = 1;totmat[0][1] = 0;totmat[0][2] = 0; - totmat[1][0] = 0;totmat[1][1] = 1;totmat[1][2] = 0; - totmat[2][0] = 0;totmat[2][1] = 0;totmat[2][2] = 1; + unit_m3(totmat); } break; } @@ -2463,10 +2423,7 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * normalize_v3(totmat[0]); /* the z axis is fixed */ - totmat[2][0] = cob->matrix[2][0]; - totmat[2][1] = cob->matrix[2][1]; - totmat[2][2] = cob->matrix[2][2]; - normalize_v3(totmat[2]); + normalize_v3_v3(totmat[2], cob->matrix[2]); /* the x axis gets mapped onto a third orthogonal vector */ cross_v3_v3v3(totmat[1], totmat[2], totmat[0]); @@ -2480,10 +2437,7 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * normalize_v3(totmat[1]); /* the z axis is fixed */ - totmat[2][0] = cob->matrix[2][0]; - totmat[2][1] = cob->matrix[2][1]; - totmat[2][2] = cob->matrix[2][2]; - normalize_v3(totmat[2]); + normalize_v3_v3(totmat[2], cob->matrix[2]); /* the x axis gets mapped onto a third orthogonal vector */ cross_v3_v3v3(totmat[0], totmat[1], totmat[2]); @@ -2498,10 +2452,7 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * negate_v3(totmat[0]); /* the z axis is fixed */ - totmat[2][0] = cob->matrix[2][0]; - totmat[2][1] = cob->matrix[2][1]; - totmat[2][2] = cob->matrix[2][2]; - normalize_v3(totmat[2]); + normalize_v3_v3(totmat[2], cob->matrix[2]); /* the x axis gets mapped onto a third orthogonal vector */ cross_v3_v3v3(totmat[1], totmat[2], totmat[0]); @@ -2516,10 +2467,7 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * negate_v3(totmat[1]); /* the z axis is fixed */ - totmat[2][0] = cob->matrix[2][0]; - totmat[2][1] = cob->matrix[2][1]; - totmat[2][2] = cob->matrix[2][2]; - normalize_v3(totmat[2]); + normalize_v3_v3(totmat[2], cob->matrix[2]); /* the x axis gets mapped onto a third orthogonal vector */ cross_v3_v3v3(totmat[0], totmat[1], totmat[2]); @@ -2527,9 +2475,7 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * break; default: { - totmat[0][0] = 1;totmat[0][1] = 0;totmat[0][2] = 0; - totmat[1][0] = 0;totmat[1][1] = 1;totmat[1][2] = 0; - totmat[2][0] = 0;totmat[2][1] = 0;totmat[2][2] = 1; + unit_m3(totmat); } break; } @@ -2537,19 +2483,13 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * break; default: { - totmat[0][0] = 1;totmat[0][1] = 0;totmat[0][2] = 0; - totmat[1][0] = 0;totmat[1][1] = 1;totmat[1][2] = 0; - totmat[2][0] = 0;totmat[2][1] = 0;totmat[2][2] = 1; + unit_m3(totmat); } break; } /* Block to keep matrix heading */ - tmpmat[0][0] = cob->matrix[0][0];tmpmat[0][1] = cob->matrix[0][1];tmpmat[0][2] = cob->matrix[0][2]; - tmpmat[1][0] = cob->matrix[1][0];tmpmat[1][1] = cob->matrix[1][1];tmpmat[1][2] = cob->matrix[1][2]; - tmpmat[2][0] = cob->matrix[2][0];tmpmat[2][1] = cob->matrix[2][1];tmpmat[2][2] = cob->matrix[2][2]; - normalize_v3(tmpmat[0]); - normalize_v3(tmpmat[1]); - normalize_v3(tmpmat[2]); + copy_m3_m4(tmpmat, cob->matrix); + normalize_m3(tmpmat); invert_m3_m3(invmat, tmpmat); mul_m3_m3m3(tmpmat, totmat, invmat); totmat[0][0] = tmpmat[0][0];totmat[0][1] = tmpmat[0][1];totmat[0][2] = tmpmat[0][2]; @@ -2562,9 +2502,7 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * totmat[1][0],totmat[1][1],totmat[1][2], totmat[2][0],totmat[2][1],totmat[2][2]); if (mdet==0) { - totmat[0][0] = 1;totmat[0][1] = 0;totmat[0][2] = 0; - totmat[1][0] = 0;totmat[1][1] = 1;totmat[1][2] = 0; - totmat[2][0] = 0;totmat[2][1] = 0;totmat[2][2] = 1; + unit_m3(totmat); } /* apply out transformaton to the object */ @@ -2692,7 +2630,7 @@ static void distlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * interp_v3_v3v3(dvec, ct->matrix[3], cob->matrix[3], sfac); /* copy new vector onto owner */ - VECCOPY(cob->matrix[3], dvec); + copy_v3_v3(cob->matrix[3], dvec); } } } @@ -2775,16 +2713,10 @@ static void stretchto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * mat4_to_size(size, cob->matrix); /* store X orientation before destroying obmat */ - xx[0] = cob->matrix[0][0]; - xx[1] = cob->matrix[0][1]; - xx[2] = cob->matrix[0][2]; - normalize_v3(xx); + normalize_v3_v3(xx, cob->matrix[0]); /* store Z orientation before destroying obmat */ - zz[0] = cob->matrix[2][0]; - zz[1] = cob->matrix[2][1]; - zz[2] = cob->matrix[2][2]; - normalize_v3(zz); + normalize_v3_v3(zz, cob->matrix[2]); sub_v3_v3v3(vec, cob->matrix[3], ct->matrix[3]); vec[0] /= size[0]; @@ -2839,9 +2771,7 @@ static void stretchto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * normalize_v3(vec); /* new Y aligns object target connection*/ - totmat[1][0] = -vec[0]; - totmat[1][1] = -vec[1]; - totmat[1][2] = -vec[2]; + negate_v3_v3(totmat[1], vec); switch (data->plane) { case PLANE_X: /* build new Z vector */ @@ -2850,16 +2780,11 @@ static void stretchto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * normalize_v3(orth); /* new Z*/ - totmat[2][0] = orth[0]; - totmat[2][1] = orth[1]; - totmat[2][2] = orth[2]; + copy_v3_v3(totmat[2], orth); /* we decided to keep X plane*/ cross_v3_v3v3(xx, orth, vec); - normalize_v3(xx); - totmat[0][0] = xx[0]; - totmat[0][1] = xx[1]; - totmat[0][2] = xx[2]; + normalize_v3_v3(totmat[0], xx); break; case PLANE_Z: /* build new X vector */ @@ -2868,16 +2793,11 @@ static void stretchto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * normalize_v3(orth); /* new X */ - totmat[0][0] = -orth[0]; - totmat[0][1] = -orth[1]; - totmat[0][2] = -orth[2]; + negate_v3_v3(totmat[0], orth); /* we decided to keep Z */ cross_v3_v3v3(zz, orth, vec); - normalize_v3(zz); - totmat[2][0] = zz[0]; - totmat[2][1] = zz[1]; - totmat[2][2] = zz[2]; + normalize_v3_v3(totmat[2], zz); break; } /* switch (data->plane) */ @@ -3009,10 +2929,10 @@ static void minmax_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *tar obmat[3][index] = tarmat[3][index] + data->offset; if (data->flag & MINMAX_STICKY) { if (data->flag & MINMAX_STUCK) { - VECCOPY(obmat[3], data->cache); + copy_v3_v3(obmat[3], data->cache); } else { - VECCOPY(data->cache, obmat[3]); + copy_v3_v3(data->cache, obmat[3]); data->flag |= MINMAX_STUCK; } } @@ -3022,7 +2942,7 @@ static void minmax_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *tar copy_m4_m4(cob->matrix, tmat); } else { - VECCOPY(cob->matrix[3], obmat[3]); + copy_v3_v3(cob->matrix[3], obmat[3]); } } else { @@ -3177,7 +3097,7 @@ static void clampto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta copy_m4_m4(obmat, cob->matrix); unit_m4(targetMatrix); - VECCOPY(ownLoc, obmat[3]); + copy_v3_v3(ownLoc, obmat[3]); INIT_MINMAX(curveMin, curveMax) minmax_object(ct->tar, curveMin, curveMax); @@ -3266,14 +3186,14 @@ static void clampto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta /* 3. position on curve */ if (where_on_path(ct->tar, curvetime, vec, dir, NULL, NULL, NULL) ) { unit_m4(totmat); - VECCOPY(totmat[3], vec); + copy_v3_v3(totmat[3], vec); mul_serie_m4(targetMatrix, ct->tar->obmat, totmat, NULL, NULL, NULL, NULL, NULL, NULL); } } /* obtain final object position */ - VECCOPY(cob->matrix[3], targetMatrix[3]); + copy_v3_v3(cob->matrix[3], targetMatrix[3]); } } @@ -3365,7 +3285,7 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * } /* extract components of owner's matrix */ - VECCOPY(loc, cob->matrix[3]); + copy_v3_v3(loc, cob->matrix[3]); mat4_to_eulO(eul, cob->rotOrder, cob->matrix); mat4_to_size(size, cob->matrix); @@ -3559,7 +3479,7 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr fail = TRUE; break; } - VECCOPY(co, hit.co); + copy_v3_v3(co, hit.co); break; } @@ -3575,7 +3495,7 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr /* co is in local object coordinates, change it to global and update target position */ mul_m4_v3(cob->matrix, co); - VECCOPY(ct->matrix[3], co); + copy_v3_v3(ct->matrix[3], co); } } } @@ -3587,7 +3507,7 @@ static void shrinkwrap_evaluate (bConstraint *con, bConstraintOb *cob, ListBase /* only evaluate if there is a target */ if (VALID_CONS_TARGET(ct)) { - VECCOPY(cob->matrix[3], ct->matrix[3]); + copy_v3_v3(cob->matrix[3], ct->matrix[3]); } } @@ -3671,23 +3591,23 @@ static void damptrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * * - the normalisation step at the end should take care of any unwanted scaling * left over in the 3x3 matrix we used */ - VECCOPY(obvec, track_dir_vecs[data->trackflag]); + copy_v3_v3(obvec, track_dir_vecs[data->trackflag]); mul_mat3_m4_v3(cob->matrix, obvec); if (normalize_v3(obvec) == 0.0f) { /* exceptional case - just use the track vector as appropriate */ - VECCOPY(obvec, track_dir_vecs[data->trackflag]); + copy_v3_v3(obvec, track_dir_vecs[data->trackflag]); } /* find the (unit) direction vector going from the owner to the target */ - VECCOPY(obloc, cob->matrix[3]); + copy_v3_v3(obloc, cob->matrix[3]); sub_v3_v3v3(tarvec, ct->matrix[3], obloc); if (normalize_v3(tarvec) == 0.0f) { /* the target is sitting on the owner, so just make them use the same direction vectors */ // FIXME: or would it be better to use the pure direction vector? - VECCOPY(tarvec, obvec); - //VECCOPY(tarvec, track_dir_vecs[data->trackflag]); + copy_v3_v3(tarvec, obvec); + //copy_v3_v3(tarvec, track_dir_vecs[data->trackflag]); } /* determine the axis-angle rotation, which represents the smallest possible rotation @@ -3715,7 +3635,7 @@ static void damptrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * mul_m4_m3m4(tmat, rmat, cob->matrix); // m1, m3, m2 copy_m4_m4(cob->matrix, tmat); - VECCOPY(cob->matrix[3], obloc); + copy_v3_v3(cob->matrix[3], obloc); } } @@ -3910,7 +3830,7 @@ static void pivotcon_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *t } else { /* directly use the 'offset' specified as an absolute position instead */ - VECCOPY(pivot, data->offset); + copy_v3_v3(pivot, data->offset); } } diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index 9520df71b60..24dcb4c5846 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -25,6 +25,9 @@ * ***** END GPL LICENSE BLOCK ***** */ +#include <string.h> +#include <stddef.h> + #include "MEM_guardedalloc.h" #include "DNA_scene_types.h" @@ -47,8 +50,6 @@ #include "BPY_extern.h" #endif -#include <string.h> - /* struct */ struct bContext { @@ -571,13 +572,12 @@ int CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, ListB static void data_dir_add(ListBase *lb, const char *member) { LinkData *link; - + if(strcmp(member, "scene") == 0) /* exception */ return; - for(link=lb->first; link; link=link->next) - if(strcmp(link->data, member) == 0) - return; + if(BLI_findstring(lb, member, offsetof(LinkData, data))) + return; link= MEM_callocN(sizeof(LinkData), "LinkData"); link->data= (void*)member; diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 2f0c83507f0..5f5958f8893 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -46,6 +46,7 @@ #include "DNA_scene_types.h" #include "DNA_vfont_types.h" #include "DNA_meshdata_types.h" +#include "DNA_object_types.h" #include "BKE_animsys.h" #include "BKE_anim.h" @@ -59,6 +60,8 @@ #include "BKE_object.h" #include "BKE_utildefines.h" // VECCOPY +#include "ED_curve.h" + /* globals */ /* local */ @@ -105,13 +108,8 @@ void free_curve(Curve *cu) BLI_freelistN(&cu->bev); freedisplist(&cu->disp); BKE_free_editfont(cu); - - if(cu->editnurb) { - freeNurblist(cu->editnurb); - MEM_freeN(cu->editnurb); - cu->editnurb= NULL; - } + free_curve_editNurb(cu); unlink_curve(cu); BKE_free_animdata((ID *)cu); @@ -130,7 +128,7 @@ Curve *add_curve(char *name, int type) cu= alloc_libblock(&G.main->curve, ID_CU, name); cu->size[0]= cu->size[1]= cu->size[2]= 1.0; - cu->flag= CU_FRONT|CU_BACK|CU_PATH_RADIUS; + cu->flag= CU_FRONT|CU_BACK|CU_DEFORM_BOUNDS_OFF|CU_PATH_RADIUS; cu->pathlen= 100; cu->resolu= cu->resolv= 12; cu->width= 1.0; @@ -149,7 +147,7 @@ Curve *add_curve(char *name, int type) cu->vfont->id.us+=4; cu->str= MEM_mallocN(12, "str"); strcpy(cu->str, "Text"); - cu->pos= 4; + cu->len= cu->pos= 4; cu->strinfo= MEM_callocN(12*sizeof(CharInfo), "strinfo new"); cu->totbox= cu->actbox= 1; cu->tb= MEM_callocN(MAXTEXTBOX*sizeof(TextBox), "textbox"); @@ -280,7 +278,7 @@ void tex_space_curve(Curve *cu) { DispList *dl; BoundBox *bb; - float *fp, min[3], max[3], loc[3], size[3]; + float *fp, min[3], max[3]; int tot, doit= 0; if(cu->bb==NULL) cu->bb= MEM_callocN(sizeof(BoundBox), "boundbox"); @@ -307,20 +305,15 @@ void tex_space_curve(Curve *cu) min[0] = min[1] = min[2] = -1.0f; max[0] = max[1] = max[2] = 1.0f; } - - loc[0]= (min[0]+max[0])/2.0f; - loc[1]= (min[1]+max[1])/2.0f; - loc[2]= (min[2]+max[2])/2.0f; - - size[0]= (max[0]-min[0])/2.0f; - size[1]= (max[1]-min[1])/2.0f; - size[2]= (max[2]-min[2])/2.0f; boundbox_set_from_min_max(bb, min, max); if(cu->texflag & CU_AUTOSPACE) { - VECCOPY(cu->loc, loc); - VECCOPY(cu->size, size); + mid_v3_v3v3(cu->loc, min, max); + cu->size[0]= (max[0]-min[0])/2.0f; + cu->size[1]= (max[1]-min[1])/2.0f; + cu->size[2]= (max[2]-min[2])/2.0f; + cu->rot[0]= cu->rot[1]= cu->rot[2]= 0.0; if(cu->size[0]==0.0) cu->size[0]= 1.0; @@ -1230,6 +1223,8 @@ void makebevelcurve(Scene *scene, Object *ob, ListBase *disp, int forRender) // XXX if( ob == obedit && ob->type == OB_FONT ) return; if(cu->bevobj) { + if (cu->bevobj->type!=OB_CURVE) return; + bevcu= cu->bevobj->data; if(bevcu->ext1==0.0 && bevcu->ext2==0.0) { ListBase bevdisp= {NULL, NULL}; @@ -1579,7 +1574,7 @@ static void alfa_bezpart(BezTriple *prevbezt, BezTriple *bezt, Nurb *nu, float * for(a=0; a<resolu; a++, fac+= dfac) { if (tilt_array) { - if (nu->tilt_interp==3) { /* May as well support for tilt also 2.47 ease interp */ + if (nu->tilt_interp==KEY_CU_EASE) { /* May as well support for tilt also 2.47 ease interp */ *tilt_array = prevbezt->alfa + (bezt->alfa - prevbezt->alfa)*(3.0f*fac*fac - 2.0f*fac*fac*fac); } else { key_curve_position_weights(fac, t, nu->tilt_interp); @@ -1590,7 +1585,7 @@ static void alfa_bezpart(BezTriple *prevbezt, BezTriple *bezt, Nurb *nu, float * } if (radius_array) { - if (nu->radius_interp==3) { + if (nu->radius_interp==KEY_CU_EASE) { /* Support 2.47 ease interp * Note! - this only takes the 2 points into account, * giving much more localized results to changes in radius, sometimes you want that */ @@ -2009,8 +2004,10 @@ void makeBevelList(Object *ob) /* STEP 1: MAKE POLYS */ BLI_freelistN(&(cu->bev)); - if(cu->editnurb && ob->type!=OB_FONT) nu= cu->editnurb->first; - else nu= cu->nurb.first; + if(cu->editnurb && ob->type!=OB_FONT) { + ListBase *nurbs= ED_curve_editnurbs(cu); + nu= nurbs->first; + } else nu= cu->nurb.first; while(nu) { @@ -3000,7 +2997,7 @@ float (*curve_getKeyVertexCos(Curve *cu, ListBase *lb, float *key))[3] VECCOPY(co, key); co+=3; key+=3; VECCOPY(co, key); co+=3; key+=3; VECCOPY(co, key); co+=3; key+=3; - key++; /* skip tilt */ + key+=3; /* skip tilt */ } } else { @@ -3079,7 +3076,7 @@ int clamp_nurb_order_u( struct Nurb *nu ) nu->orderu= nu->pntsu; change= 1; } - if(((nu->flag & CU_NURB_CYCLIC)==0) && (nu->flagu & CU_NURB_BEZIER)) { + if(((nu->flagu & CU_NURB_CYCLIC)==0) && (nu->flagu & CU_NURB_BEZIER)) { CLAMP(nu->orderu, 3,4); change= 1; } @@ -3093,12 +3090,117 @@ int clamp_nurb_order_v( struct Nurb *nu) nu->orderv= nu->pntsv; change= 1; } - if(((nu->flag & CU_NURB_CYCLIC)==0) && (nu->flagv & CU_NURB_BEZIER)) { + if(((nu->flagv & CU_NURB_CYCLIC)==0) && (nu->flagv & CU_NURB_BEZIER)) { CLAMP(nu->orderv, 3,4); change= 1; } return change; } +/* Get edit nurbs or normal nurbs list */ +ListBase *BKE_curve_nurbs(Curve *cu) +{ + if (cu->editnurb) { + return ED_curve_editnurbs(cu); + } + + return &cu->nurb; +} + + +/* basic vertex data functions */ +int minmax_curve(Curve *cu, float min[3], float max[3]) +{ + ListBase *nurb_lb= BKE_curve_nurbs(cu); + Nurb *nu; + + for(nu= nurb_lb->first; nu; nu= nu->next) + minmaxNurb(nu, min, max); + + return (nurb_lb->first != NULL); +} + +int curve_center_median(Curve *cu, float cent[3]) +{ + ListBase *nurb_lb= BKE_curve_nurbs(cu); + Nurb *nu; + int total= 0; + zero_v3(cent); + for(nu= nurb_lb->first; nu; nu= nu->next) { + int i; + + if(nu->type == CU_BEZIER) { + BezTriple *bezt; + i= nu->pntsu; + total += i * 3; + for(bezt= nu->bezt; i--; bezt++) { + add_v3_v3(cent, bezt->vec[0]); + add_v3_v3(cent, bezt->vec[1]); + add_v3_v3(cent, bezt->vec[2]); + } + } + else { + BPoint *bp; + i= nu->pntsu*nu->pntsv; + total += i; + for(bp= nu->bp; i--; bp++) { + add_v3_v3(cent, bp->vec); + } + } + } + + mul_v3_fl(cent, 1.0f/(float)total); + + return (total != 0); +} + +int curve_center_bounds(Curve *cu, float cent[3]) +{ + float min[3], max[3]; + INIT_MINMAX(min, max); + if(minmax_curve(cu, min, max)) { + mid_v3_v3v3(cent, min, max); + return 1; + } + + return 0; +} + +void curve_translate(Curve *cu, float offset[3], int do_keys) +{ + ListBase *nurb_lb= BKE_curve_nurbs(cu); + Nurb *nu; + int i; + + for(nu= nurb_lb->first; nu; nu= nu->next) { + BezTriple *bezt; + BPoint *bp; + + if(nu->type == CU_BEZIER) { + i= nu->pntsu; + for(bezt= nu->bezt; i--; bezt++) { + add_v3_v3(bezt->vec[0], offset); + add_v3_v3(bezt->vec[1], offset); + add_v3_v3(bezt->vec[2], offset); + } + } + else { + i= nu->pntsu*nu->pntsv; + for(bp= nu->bp; i--; bp++) { + add_v3_v3(bp->vec, offset); + } + } + } + + if (do_keys && cu->key) { + KeyBlock *kb; + for (kb=cu->key->block.first; kb; kb=kb->next) { + float *fp= kb->data; + for (i= kb->totelem; i--; fp+=3) { + add_v3_v3(fp, offset); + } + } + } +} diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index 1ab0cb8d29d..be28553f347 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -177,7 +177,7 @@ void defvert_flip (MDeformVert *dvert, int *flip_map) } -bDeformGroup *defgroup_find_name (Object *ob, char *name) +bDeformGroup *defgroup_find_name (Object *ob, const char *name) { /* return a pointer to the deform group with this name * or return NULL otherwise. diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index 142f80a350e..382c0690ae3 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -41,6 +41,8 @@ #include "DNA_screen_types.h" #include "DNA_windowmanager_types.h" +#include "MEM_guardedalloc.h" + #include "BLI_ghash.h" #include "BKE_animsys.h" @@ -59,13 +61,7 @@ #include "BKE_scene.h" #include "BKE_screen.h" -#include "MEM_guardedalloc.h" - -#ifndef DISABLE_PYTHON -#include "BPY_extern.h" -#endif - - #include "depsgraph_private.h" +#include "depsgraph_private.h" /* Queue and stack operations for dag traversal * @@ -658,7 +654,7 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O dag_add_relation(dag,scenenode,node,DAG_RL_SCENE, "Scene Relation"); } -struct DagForest *build_dag(struct Scene *sce, short mask) +struct DagForest *build_dag(Main *bmain, Scene *sce, short mask) { Base *base; Object *ob; @@ -695,7 +691,7 @@ struct DagForest *build_dag(struct Scene *sce, short mask) } /* add groups used in current scene objects */ - for(group= G.main->group.first; group; group= group->id.next) { + for(group= bmain->group.first; group; group= group->id.next) { if(group->id.flag & LIB_DOIT) { for(go= group->gobject.first; go; go= go->next) { build_dag_object(dag, scenenode, sce, go->ob, mask); @@ -1605,7 +1601,7 @@ static void dag_editors_update(Main *bmain, ID *id) } /* groups with objects in this scene need to be put in the right order as well */ -static void scene_sort_groups(Scene *sce) +static void scene_sort_groups(Main *bmain, Scene *sce) { Base *base; Group *group; @@ -1613,14 +1609,14 @@ static void scene_sort_groups(Scene *sce) Object *ob; /* test; are group objects all in this scene? */ - for(ob= G.main->object.first; ob; ob= ob->id.next) { + for(ob= bmain->object.first; ob; ob= ob->id.next) { ob->id.flag &= ~LIB_DOIT; ob->id.newid= NULL; /* newid abuse for GroupObject */ } for(base = sce->base.first; base; base= base->next) base->object->id.flag |= LIB_DOIT; - for(group= G.main->group.first; group; group= group->id.next) { + for(group= bmain->group.first; group; group= group->id.next) { for(go= group->gobject.first; go; go= go->next) { if((go->ob->id.flag & LIB_DOIT)==0) break; @@ -1649,7 +1645,7 @@ static void scene_sort_groups(Scene *sce) } /* sort the base list on dependency order */ -void DAG_scene_sort(struct Scene *sce) +void DAG_scene_sort(Main *bmain, Scene *sce) { DagNode *node; DagNodeQueue *nqueue; @@ -1661,7 +1657,7 @@ void DAG_scene_sort(struct Scene *sce) tempbase.first= tempbase.last= NULL; - build_dag(sce, DAG_RL_ALL_BUT_DATA); + build_dag(bmain, sce, DAG_RL_ALL_BUT_DATA); dag_check_cycle(sce->theDag); @@ -1731,7 +1727,7 @@ void DAG_scene_sort(struct Scene *sce) queue_delete(nqueue); /* all groups with objects in this scene gets resorted too */ - scene_sort_groups(sce); + scene_sort_groups(bmain, sce); if(G.f & G_DEBUG) { printf("\nordered\n"); @@ -1926,7 +1922,7 @@ static void dag_scene_flush_layers(Scene *sce, int lay) } /* flushes all recalc flags in objects down the dependency tree */ -void DAG_scene_flush_update(Scene *sce, unsigned int lay, int time) +void DAG_scene_flush_update(Main *bmain, Scene *sce, unsigned int lay, int time) { DagNode *firstnode; DagAdjList *itA; @@ -1935,7 +1931,7 @@ void DAG_scene_flush_update(Scene *sce, unsigned int lay, int time) if(sce->theDag==NULL) { printf("DAG zero... not allowed to happen!\n"); - DAG_scene_sort(sce); + DAG_scene_sort(bmain, sce); } firstnode= sce->theDag->DagNode.first; // always scene node @@ -2135,7 +2131,7 @@ static void dag_object_time_update_flags(Object *ob) } } /* flag all objects that need recalc, for changes in time for example */ -void DAG_scene_update_flags(Scene *scene, unsigned int lay) +void DAG_scene_update_flags(Main *bmain, Scene *scene, unsigned int lay) { Base *base; Object *ob; @@ -2157,7 +2153,7 @@ void DAG_scene_update_flags(Scene *scene, unsigned int lay) } /* we do groups each once */ - for(group= G.main->group.first; group; group= group->id.next) { + for(group= bmain->group.first; group; group= group->id.next) { if(group->id.flag & LIB_DOIT) { for(go= group->gobject.first; go; go= go->next) { dag_object_time_update_flags(go->ob); @@ -2166,7 +2162,7 @@ void DAG_scene_update_flags(Scene *scene, unsigned int lay) } for(sce= scene; sce; sce= sce->set) - DAG_scene_flush_update(sce, lay, 1); + DAG_scene_flush_update(bmain, sce, lay, 1); /* test: set time flag, to disable baked systems to update */ for(SETLOOPER(scene, base)) { @@ -2180,7 +2176,7 @@ void DAG_scene_update_flags(Scene *scene, unsigned int lay) dag_object_time_update_flags(scene->camera); /* and store the info in groupobject */ - for(group= G.main->group.first; group; group= group->id.next) { + for(group= bmain->group.first; group; group= group->id.next) { if(group->id.flag & LIB_DOIT) { for(go= group->gobject.first; go; go= go->next) { go->recalc= go->ob->recalc; @@ -2223,21 +2219,19 @@ static void dag_current_scene_layers(Main *bmain, Scene **sce, unsigned int *lay } } -void DAG_ids_flush_update(int time) +void DAG_ids_flush_update(Main *bmain, int time) { - Main *bmain= G.main; Scene *sce; unsigned int lay; dag_current_scene_layers(bmain, &sce, &lay); if(sce) - DAG_scene_flush_update(sce, lay, time); + DAG_scene_flush_update(bmain, sce, lay, time); } -void DAG_on_load_update(void) +void DAG_on_load_update(Main *bmain) { - Main *bmain= G.main; Scene *scene, *sce; Base *base; Object *ob; @@ -2268,7 +2262,7 @@ void DAG_on_load_update(void) } } - for(group= G.main->group.first; group; group= group->id.next) { + for(group= bmain->group.first; group; group= group->id.next) { if(group->id.flag & LIB_DOIT) { for(go= group->gobject.first; go; go= go->next) { if(ELEM5(go->ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL)) @@ -2282,7 +2276,7 @@ void DAG_on_load_update(void) } /* now tag update flags, to ensure deformers get calculated on redraw */ - DAG_scene_update_flags(scene, lay); + DAG_scene_update_flags(bmain, scene, lay); } } @@ -2394,7 +2388,7 @@ void DAG_id_flush_update(ID *id, short flag) } /* flush to other objects that depend on this one */ - DAG_scene_flush_update(sce, lay, 0); + DAG_scene_flush_update(bmain, sce, lay, 0); } /* recursively descends tree, each node only checked once */ @@ -2477,7 +2471,7 @@ void DAG_id_update_flags(ID *id) } /* set recalcs and flushes */ - DAG_scene_update_flags(sce, lay); + DAG_scene_update_flags(bmain, sce, lay); /* now we clear recalcs, unless color is set */ for(node = sce->theDag->DagNode.first; node; node= node->next) { diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index 15e561cfc45..666a62d96de 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -39,6 +39,7 @@ #include "DNA_curve_types.h" #include "DNA_meshdata_types.h" #include "DNA_scene_types.h" +#include "DNA_object_types.h" #include "DNA_material_types.h" #include "BLI_blenlib.h" @@ -63,6 +64,7 @@ #include "BLO_sys_types.h" // for intptr_t support +#include "ED_curve.h" /* for BKE_curve_nurbs */ static void boundbox_displist(Object *ob); @@ -152,7 +154,7 @@ void copy_displist(ListBase *lbn, ListBase *lb) } } -void addnormalsDispList(Object *ob, ListBase *lb) +void addnormalsDispList(ListBase *lb) { DispList *dl = NULL; float *vdata, *ndata, nor[3]; @@ -1127,7 +1129,7 @@ float calc_taper(Scene *scene, Object *taperobj, int cur, int tot) Curve *cu; DispList *dl; - if(taperobj==NULL) return 1.0; + if(taperobj==NULL || taperobj->type!=OB_CURVE) return 1.0; cu= taperobj->data; dl= cu->disp.first; @@ -1221,7 +1223,7 @@ static void curve_calc_modifiers_pre(Scene *scene, Object *ob, int forRender, fl ModifierData *md = modifiers_getVirtualModifierList(ob); ModifierData *preTesselatePoint; Curve *cu= ob->data; - ListBase *nurb= cu->editnurb?cu->editnurb:&cu->nurb; + ListBase *nurb= BKE_curve_nurbs(cu); int numVerts = 0; int editmode = (!forRender && cu->editnurb); float (*originalVerts)[3] = NULL; @@ -1324,8 +1326,8 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *dispba ModifierData *md = modifiers_getVirtualModifierList(ob); ModifierData *preTesselatePoint; Curve *cu= ob->data; - ListBase *nurb= cu->editnurb?cu->editnurb:&cu->nurb; - int required_mode, totvert = 0; + ListBase *nurb= BKE_curve_nurbs(cu); + int required_mode = 0, totvert = 0; int editmode = (!forRender && cu->editnurb); DerivedMesh *dm= NULL, *ndm; float (*vertCos)[3] = NULL; @@ -1590,9 +1592,9 @@ void makeDispListSurf(Scene *scene, Object *ob, ListBase *dispbase, int numVerts; float (*originalVerts)[3]; float (*deformedVerts)[3]; - + if(!forRender && cu->editnurb) - nubase= cu->editnurb; + nubase= ED_curve_editnurbs(cu); else nubase= &cu->nurb; @@ -1680,19 +1682,7 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba float (*deformedVerts)[3]; int numVerts; - /* Bevel and taper objects should always be curves */ - if (cu->bevobj && cu->bevobj->type != OB_CURVE) { - cu->bevobj = NULL; - } - - if (cu->taperobj && cu->taperobj->type != OB_CURVE) { - cu->taperobj = NULL; - } - - if(cu->editnurb) - nubase= cu->editnurb; - else - nubase= &cu->nurb; + nubase= BKE_curve_nurbs(cu); BLI_freelistN(&(cu->bev)); diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index b1182cfcec3..fba96d2fd8f 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -433,9 +433,8 @@ static float eff_calc_visibility(ListBase *colliders, EffectorCache *eff, Effect if(!colls) return visibility; - - VECCOPY(norm, efd->vec_to_point); - negate_v3(norm); + + negate_v3_v3(norm, efd->vec_to_point); len = normalize_v3(norm); // check all collision objects @@ -663,8 +662,7 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin where_is_object_time(eff->scene, ob, cfra); /* use z-axis as normal*/ - VECCOPY(efd->nor, ob->obmat[2]); - normalize_v3(efd->nor); + normalize_v3_v3(efd->nor, ob->obmat[2]); /* for vortex the shape chooses between old / new force */ if(eff->pd && eff->pd->shape == PFIELD_SHAPE_PLANE) { @@ -708,8 +706,7 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin else { /* for some effectors we need the object center every time */ sub_v3_v3v3(efd->vec_to_point2, point->loc, eff->ob->obmat[3]); - VECCOPY(efd->nor2, eff->ob->obmat[2]); - normalize_v3(efd->nor2); + normalize_v3_v3(efd->nor2, eff->ob->obmat[2]); } } diff --git a/source/blender/blenkernel/intern/fluidsim.c b/source/blender/blenkernel/intern/fluidsim.c index a0906a67be0..834fd09aac2 100644 --- a/source/blender/blenkernel/intern/fluidsim.c +++ b/source/blender/blenkernel/intern/fluidsim.c @@ -50,7 +50,6 @@ #include "BKE_global.h" #include "BKE_modifier.h" #include "BKE_mesh.h" -#include "BKE_pointcache.h" #include "BKE_utildefines.h" // headers for fluidsim bobj meshes diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c index 5829d462011..f054f2e8738 100644 --- a/source/blender/blenkernel/intern/fmodifier.c +++ b/source/blender/blenkernel/intern/fmodifier.c @@ -43,10 +43,6 @@ #include "BKE_idprop.h" #include "BKE_utildefines.h" -#ifndef DISABLE_PYTHON -#include "BPY_extern.h" /* for BPY_eval_driver() */ -#endif - #define SMALL -1.0e-10 #define SELECT 1 @@ -1193,7 +1189,7 @@ short list_has_suitable_fmodifier (ListBase *modifiers, int mtype, short acttype * - this step acts as an optimisation to prevent the F-Curve stack being evaluated * several times by modifiers requesting the time be modified, as the final result * would have required using the modified time - * - modifiers only ever recieve the unmodified time, as subsequent modifiers should be + * - modifiers only ever receive the unmodified time, as subsequent modifiers should be * working on the 'global' result of the modified curve, not some localised segment, * so nevaltime gets set to whatever the last time-modifying modifier likes... * - we start from the end of the stack, as only the last one matters for now diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index a99f2599f66..39b74be3d40 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -46,6 +46,7 @@ #include "DNA_curve_types.h" #include "DNA_vfont_types.h" #include "DNA_scene_types.h" +#include "DNA_object_types.h" #include "BKE_utildefines.h" @@ -122,8 +123,8 @@ wcsleninu8(wchar_t *src) return len; } -int -static utf8slen(char *src) +static int +utf8slen(char *src) { int size = 0, index = 0; unsigned char c; @@ -814,7 +815,7 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode) twidth = char_width(cu, che, info); // Calculate positions - if((tb->w != 0.0) && (ct->dobreak==0) && ((xof-(tb->x/cu->fsize)+twidth)*cu->fsize) > tb->w) { + if((tb->w != 0.0) && (ct->dobreak==0) && ((xof-(tb->x/cu->fsize)+twidth)*cu->fsize) > tb->w + cu->xof*cu->fsize) { // fprintf(stderr, "linewidth exceeded: %c%c%c...\n", mem[i], mem[i+1], mem[i+2]); for (j=i; j && (mem[j] != '\n') && (mem[j] != '\r') && (chartransdata[j].dobreak==0); j--) { if (mem[j]==' ' || mem[j]=='-') { @@ -855,7 +856,7 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode) linedata4[lnr]= wsnr; if ( (tb->h != 0.0) && - ((-(yof-(tb->y/cu->fsize))) > ((tb->h/cu->fsize)-(linedist*cu->fsize))) && + ((-(yof-(tb->y/cu->fsize))) > ((tb->h/cu->fsize)-(linedist*cu->fsize)) - cu->yof) && (cu->totbox > (curbox+1)) ) { maxlen= 0; tb++; @@ -1194,18 +1195,14 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode) ascii = mem[i]; info = &(custrinfo[i]); if (cu->sepchar == (i+1)) { - float vecyo[3]; + float vecyo[3]= {ct->xof, ct->yof, 0.0f}; mem[0] = ascii; mem[1] = 0; custrinfo[0]= *info; cu->pos = 1; cu->len = 1; - vecyo[0] = ct->xof; - vecyo[1] = ct->yof; - vecyo[2] = 0; - mul_m4_v3(ob->obmat, vecyo); - VECCOPY(ob->loc, vecyo); + mul_v3_m4v3(ob->loc, ob->obmat, vecyo); outta = 1; cu->sepchar = 0; } diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c index 6377a6f6ccd..bdf203119c3 100644 --- a/source/blender/blenkernel/intern/group.c +++ b/source/blender/blenkernel/intern/group.c @@ -69,21 +69,22 @@ void free_group_objects(Group *group) void unlink_group(Group *group) { + Main *bmain= G.main; Material *ma; Object *ob; Scene *sce; SceneRenderLayer *srl; ParticleSystem *psys; - for(ma= G.main->mat.first; ma; ma= ma->id.next) { + for(ma= bmain->mat.first; ma; ma= ma->id.next) { if(ma->group==group) ma->group= NULL; } - for(ma= G.main->mat.first; ma; ma= ma->id.next) { + for(ma= bmain->mat.first; ma; ma= ma->id.next) { if(ma->group==group) ma->group= NULL; } - for (sce= G.main->scene.first; sce; sce= sce->id.next) { + for (sce= bmain->scene.first; sce; sce= sce->id.next) { Base *base= sce->base.first; /* ensure objects are not in this group */ @@ -100,7 +101,7 @@ void unlink_group(Group *group) } } - for(ob= G.main->object.first; ob; ob= ob->id.next) { + for(ob= bmain->object.first; ob; ob= ob->id.next) { bActionStrip *strip; if(ob->dup_group==group) { diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c index ad2c857be75..78306705d6b 100644 --- a/source/blender/blenkernel/intern/icons.c +++ b/source/blender/blenkernel/intern/icons.c @@ -177,6 +177,9 @@ void BKE_previewimg_free_id(ID *id) } else if (GS(id->name) == ID_IM) { Image *img = (Image*)id; BKE_previewimg_free(&img->preview); + } else if (GS(id->name) == ID_BR) { + Brush *br = (Brush*)id; + BKE_previewimg_free(&br->preview); } } @@ -204,6 +207,10 @@ PreviewImage* BKE_previewimg_get(ID *id) Image *img = (Image*)id; if (!img->preview) img->preview = BKE_previewimg_create(); prv_img = img->preview; + } else if (GS(id->name) == ID_BR) { + Brush *br = (Brush*)id; + if (!br->preview) br->preview = BKE_previewimg_create(); + prv_img = br->preview; } return prv_img; diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 2ccb33b088a..a0df73d6c42 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -27,6 +27,7 @@ #include <stdio.h> #include <stdlib.h> +#include <stddef.h> #include <string.h> #include "BKE_idprop.h" @@ -491,47 +492,41 @@ void IDP_ReplaceGroupInGroup(IDProperty *dest, IDProperty *src) void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop) { IDProperty *loop; - for (loop=group->data.group.first; loop; loop=loop->next) { - if (BSTR_EQ(loop->name, prop->name)) { - BLI_insertlink(&group->data.group, loop, prop); - - BLI_remlink(&group->data.group, loop); - IDP_FreeProperty(loop); - MEM_freeN(loop); - return; - } + if((loop= IDP_GetPropertyFromGroup(group, prop->name))) { + BLI_insertlink(&group->data.group, loop, prop); + + BLI_remlink(&group->data.group, loop); + IDP_FreeProperty(loop); + MEM_freeN(loop); + } + else { + group->len++; + BLI_addtail(&group->data.group, prop); } - - group->len++; - BLI_addtail(&group->data.group, prop); } /*returns 0 if an id property with the same name exists and it failed, or 1 if it succeeded in adding to the group.*/ int IDP_AddToGroup(IDProperty *group, IDProperty *prop) { - IDProperty *loop; - for (loop=group->data.group.first; loop; loop=loop->next) { - if (BSTR_EQ(loop->name, prop->name)) return 0; + if(IDP_GetPropertyFromGroup(group, prop->name) == NULL) { + group->len++; + BLI_addtail(&group->data.group, prop); + return 1; } - group->len++; - BLI_addtail(&group->data.group, prop); - - return 1; + return 0; } int IDP_InsertToGroup(IDProperty *group, IDProperty *previous, IDProperty *pnew) { - IDProperty *loop; - for (loop=group->data.group.first; loop; loop=loop->next) { - if (BSTR_EQ(loop->name, pnew->name)) return 0; + if(IDP_GetPropertyFromGroup(group, pnew->name) == NULL) { + group->len++; + BLI_insertlink(&group->data.group, previous, pnew); + return 1; } - - group->len++; - BLI_insertlink(&group->data.group, previous, pnew); - return 1; + return 0; } void IDP_RemFromGroup(IDProperty *group, IDProperty *prop) @@ -542,11 +537,7 @@ void IDP_RemFromGroup(IDProperty *group, IDProperty *prop) IDProperty *IDP_GetPropertyFromGroup(IDProperty *prop, const char *name) { - IDProperty *loop; - for (loop=prop->data.group.first; loop; loop=loop->next) { - if (strcmp(loop->name, name)==0) return loop; - } - return NULL; + return (IDProperty *)BLI_findstring(&prop->data.group, name, offsetof(IDProperty, name)); } typedef struct IDPIter { diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index b66b5c60916..d2612e90945 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -287,17 +287,25 @@ static void image_assign_ibuf(Image *ima, ImBuf *ibuf, int index, int frame) } /* empty image block, of similar type and filename */ -Image *BKE_image_copy(Image *ima) +Image *copy_image(Image *ima) { - Image *new= image_alloc(ima->id.name+2, ima->source, ima->type); + Image *nima= image_alloc(ima->id.name+2, ima->source, ima->type); - BLI_strncpy(new->name, ima->name, sizeof(ima->name)); - - new->gen_x= ima->gen_x; - new->gen_y= ima->gen_y; - new->gen_type= ima->gen_type; + BLI_strncpy(nima->name, ima->name, sizeof(ima->name)); + + nima->flag= ima->flag; + nima->tpageflag= ima->tpageflag; - return new; + nima->gen_x= ima->gen_x; + nima->gen_y= ima->gen_y; + nima->gen_type= ima->gen_type; + + nima->animspeed= ima->animspeed; + + nima->aspx= ima->aspx; + nima->aspy= ima->aspy; + + return nima; } void BKE_image_merge(Image *dest, Image *source) @@ -652,8 +660,10 @@ int BKE_imtype_to_ftype(int imtype) return TGA; else if(imtype== R_IRIS) return IMAGIC; +#ifdef WITH_HDR else if (imtype==R_RADHDR) return RADHDR; +#endif else if (imtype==R_PNG) return PNG; #ifdef WITH_DDS @@ -662,14 +672,18 @@ int BKE_imtype_to_ftype(int imtype) #endif else if (imtype==R_BMP) return BMP; +#ifdef WITH_TIFF else if (imtype==R_TIFF) return TIF; +#endif else if (imtype==R_OPENEXR || imtype==R_MULTILAYER) return OPENEXR; +#ifdef WITH_CINEON else if (imtype==R_CINEON) return CINEON; else if (imtype==R_DPX) return DPX; +#endif else if (imtype==R_TARGA) return TGA; else if(imtype==R_RAWTGA) @@ -688,8 +702,10 @@ int BKE_ftype_to_imtype(int ftype) return TGA; else if(ftype == IMAGIC) return R_IRIS; +#ifdef WITH_HDR else if (ftype & RADHDR) return R_RADHDR; +#endif else if (ftype & PNG) return R_PNG; #ifdef WITH_DDS @@ -698,14 +714,18 @@ int BKE_ftype_to_imtype(int ftype) #endif else if (ftype & BMP) return R_BMP; +#ifdef WITH_TIFF else if (ftype & TIF) return R_TIFF; +#endif else if (ftype & OPENEXR) return R_OPENEXR; +#ifdef WITH_CINEON else if (ftype & CINEON) return R_CINEON; else if (ftype & DPX) return R_DPX; +#endif else if (ftype & TGA) return R_TARGA; else if(ftype & RAWTGA) @@ -748,10 +768,12 @@ void BKE_add_image_extension(char *string, int imtype) if(!BLI_testextensie(string, ".rgb")) extension= ".rgb"; } +#ifdef WITH_HDR else if(imtype==R_RADHDR) { if(!BLI_testextensie(string, ".hdr")) extension= ".hdr"; } +#endif else if (ELEM5(imtype, R_PNG, R_FFMPEG, R_H264, R_THEORA, R_XVID)) { if(!BLI_testextensie(string, ".png")) extension= ".png"; @@ -782,6 +804,7 @@ void BKE_add_image_extension(char *string, int imtype) extension= ".exr"; } #endif +#ifdef WITH_CINEON else if(imtype==R_CINEON){ if (!BLI_testextensie(string, ".cin")) extension= ".cin"; @@ -790,6 +813,7 @@ void BKE_add_image_extension(char *string, int imtype) if (!BLI_testextensie(string, ".dpx")) extension= ".dpx"; } +#endif else if(imtype==R_TARGA) { if(!BLI_testextensie(string, ".tga")) extension= ".tga"; @@ -1172,14 +1196,23 @@ int BKE_write_ibuf(Scene *scene, ImBuf *ibuf, char *name, int imtype, int subimt { int ok; - if(imtype==0); - else if(imtype== R_IRIS) + if(imtype==0) { + /* pass */ + } + else if(imtype== R_IRIS) { ibuf->ftype= IMAGIC; + } +#ifdef WITH_HDR else if ((imtype==R_RADHDR)) { ibuf->ftype= RADHDR; } +#endif else if (ELEM5(imtype, R_PNG, R_FFMPEG, R_H264, R_THEORA, R_XVID)) { ibuf->ftype= PNG; + + if(imtype==R_PNG) + ibuf->ftype |= quality; /* quality is actually compression 0-100 --> 0-9 */ + } #ifdef WITH_DDS else if ((imtype==R_DDS)) { @@ -1209,12 +1242,14 @@ int BKE_write_ibuf(Scene *scene, ImBuf *ibuf, char *name, int imtype, int subimt } #endif +#ifdef WITH_CINEON else if (imtype==R_CINEON) { ibuf->ftype = CINEON; } else if (imtype==R_DPX) { ibuf->ftype = DPX; } +#endif else if (imtype==R_TARGA) { ibuf->ftype= TGA; } diff --git a/source/blender/blenkernel/intern/implicit.c b/source/blender/blenkernel/intern/implicit.c index 902965bd2f6..158f964a846 100644 --- a/source/blender/blenkernel/intern/implicit.c +++ b/source/blender/blenkernel/intern/implicit.c @@ -29,16 +29,21 @@ #include "MEM_guardedalloc.h" -#include "BKE_cloth.h" - +#include "DNA_scene_types.h" +#include "DNA_object_types.h" #include "DNA_object_force.h" +#include "DNA_meshdata_types.h" +#include "BLI_threads.h" +#include "BLI_math.h" +#include "BLI_linklist.h" + +#include "BKE_cloth.h" +#include "BKE_collision.h" #include "BKE_effect.h" #include "BKE_global.h" #include "BKE_utildefines.h" -#include "BLI_threads.h" - #define CLOTH_OPENMP_LIMIT 25 #ifdef _WIN32 @@ -1621,9 +1626,8 @@ static void cloth_calc_force(ClothModifierData *clmd, float frame, lfVector *lF, CalcFloat4(lX[mfaces[i].v1],lX[mfaces[i].v2],lX[mfaces[i].v3],lX[mfaces[i].v4],triunnormal); else CalcFloat(lX[mfaces[i].v1],lX[mfaces[i].v2],lX[mfaces[i].v3],triunnormal); - - VECCOPY(trinormal, triunnormal); - normalize_v3(trinormal); + + normalize_v3_v3(trinormal, triunnormal); // add wind from v1 VECCOPY(tmp, trinormal); diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index cd8ab8290e5..a24f37bf73a 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -54,6 +54,7 @@ #include "DNA_sequence_types.h" #include "DNA_scene_types.h" #include "DNA_world_types.h" +#include "DNA_object_types.h" #include "BLI_math.h" /* windows needs for M_PI */ #include "BLI_blenlib.h" @@ -906,7 +907,7 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co *array_index= dummy_index; } - /* append preceeding bits to path */ + /* append preceding bits to path */ if ((actname && actname[0]) && (constname && constname[0])) { /* Constraint in Pose-Channel */ sprintf(buf, "pose.bones[\"%s\"].constraints[\"%s\"]", actname, constname); diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index efbc09692a9..f6f4226bf57 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -50,6 +50,7 @@ #include "BKE_animsys.h" #include "BKE_curve.h" #include "BKE_customdata.h" +#include "BKE_deform.h" #include "BKE_global.h" #include "BKE_key.h" #include "BKE_lattice.h" @@ -589,11 +590,15 @@ static void cp_key(int start, int end, int tot, char *poin, Key *key, KeyBlock * poinsize= ofs[0]; } else if( GS(key->from->name)==ID_CU ) { - if(mode==KEY_BPOINT) ofs[0]= sizeof(float)*4; - else ofs[0]= sizeof(float)*10; - + if(mode==KEY_BPOINT) { + ofs[0]= sizeof(float)*4; + poinsize= ofs[0]; + }else { + ofs[0]= sizeof(float)*12; + poinsize= ofs[0]/3; + } + ofs[1]= 0; - poinsize= ofs[0]; } if(end>tot) end= tot; @@ -659,7 +664,7 @@ static void cp_key(int start, int end, int tot, char *poin, Key *key, KeyBlock * memcpy(poin, k1, sizeof(float)*4); break; case IPO_BEZTRIPLE: - memcpy(poin, k1, sizeof(float)*10); + memcpy(poin, k1, sizeof(float)*12); break; } @@ -691,28 +696,25 @@ static void cp_key(int start, int end, int tot, char *poin, Key *key, KeyBlock * static void cp_cu_key(Curve *cu, Key *key, KeyBlock *actkb, KeyBlock *kb, int start, int end, char *out, int tot) { Nurb *nu; - char *poin; int a, step, a1, a2; for(a=0, nu=cu->nurb.first; nu; nu=nu->next, a+=step) { if(nu->bp) { step= nu->pntsu*nu->pntsv; - - /* exception because keys prefer to work with complete blocks */ - poin= out - a*sizeof(float)*4; + a1= MAX2(a, start); a2= MIN2(a+step, end); - - if(a1<a2) cp_key(a1, a2, tot, poin, key, actkb, kb, NULL, KEY_BPOINT); + + if(a1<a2) cp_key(a1, a2, tot, out, key, actkb, kb, NULL, KEY_BPOINT); } else if(nu->bezt) { step= 3*nu->pntsu; - - poin= out - a*sizeof(float)*10; + + /* exception because keys prefer to work with complete blocks */ a1= MAX2(a, start); a2= MIN2(a+step, end); - if(a1<a2) cp_key(a1, a2, tot, poin, key, actkb, kb, NULL, KEY_BEZTRIPLE); + if(a1<a2) cp_key(a1, a2, tot, out, key, actkb, kb, NULL, KEY_BEZTRIPLE); } else step= 0; @@ -726,26 +728,34 @@ void do_rel_key(int start, int end, int tot, char *basispoin, Key *key, KeyBlock int *ofsp, ofs[3], elemsize, b; char *cp, *poin, *reffrom, *from, elemstr[8]; char *freefrom, *freereffrom; - + int poinsize= 0; + if(key->from==NULL) return; - + if( GS(key->from->name)==ID_ME ) { ofs[0]= sizeof(float)*3; ofs[1]= 0; + poinsize= ofs[0]; } else if( GS(key->from->name)==ID_LT ) { ofs[0]= sizeof(float)*3; ofs[1]= 0; + poinsize= ofs[0]; } else if( GS(key->from->name)==ID_CU ) { - if(mode==KEY_BPOINT) ofs[0]= sizeof(float)*4; - else ofs[0]= sizeof(float)*10; - + if(mode==KEY_BPOINT) { + ofs[0]= sizeof(float)*4; + poinsize= ofs[0]; + } else { + ofs[0]= sizeof(float)*12; + poinsize= ofs[0] / 3; + } + ofs[1]= 0; } - + if(end>tot) end= tot; - + /* in case of beztriple */ elemstr[0]= 1; /* nr of ipofloats */ elemstr[1]= IPO_BEZTRIPLE; @@ -777,7 +787,7 @@ void do_rel_key(int start, int end, int tot, char *basispoin, Key *key, KeyBlock from= key_block_get_data(key, actkb, kb, &freefrom); reffrom= key_block_get_data(key, actkb, refb, &freereffrom); - poin+= start*ofs[0]; + poin+= start*poinsize; reffrom+= key->elemsize*start; // key elemsize yes! from+= key->elemsize*start; @@ -803,7 +813,7 @@ void do_rel_key(int start, int end, int tot, char *basispoin, Key *key, KeyBlock rel_flerp(4, (float *)poin, (float *)reffrom, (float *)from, weight); break; case IPO_BEZTRIPLE: - rel_flerp(10, (float *)poin, (float *)reffrom, (float *)from, weight); + rel_flerp(12, (float *)poin, (float *)reffrom, (float *)from, weight); break; } @@ -850,11 +860,15 @@ static void do_key(int start, int end, int tot, char *poin, Key *key, KeyBlock * poinsize= ofs[0]; } else if( GS(key->from->name)==ID_CU ) { - if(mode==KEY_BPOINT) ofs[0]= sizeof(float)*4; - else ofs[0]= sizeof(float)*10; - + if(mode==KEY_BPOINT) { + ofs[0]= sizeof(float)*4; + poinsize= ofs[0]; + } else { + ofs[0]= sizeof(float)*12; + poinsize= ofs[0] / 3; + } + ofs[1]= 0; - poinsize= ofs[0]; } if(end>tot) end= tot; @@ -976,7 +990,7 @@ static void do_key(int start, int end, int tot, char *poin, Key *key, KeyBlock * flerp(4, (float *)poin, (float *)k1, (float *)k2, (float *)k3, (float *)k4, t); break; case IPO_BEZTRIPLE: - flerp(10, (void *)poin, (void *)k1, (void *)k2, (void *)k3, (void *)k4, t); + flerp(12, (void *)poin, (void *)k1, (void *)k2, (void *)k3, (void *)k4, t); break; } @@ -1037,7 +1051,6 @@ static void do_key(int start, int end, int tot, char *poin, Key *key, KeyBlock * static float *get_weights_array(Object *ob, char *vgroup) { - bDeformGroup *curdef; MDeformVert *dvert= NULL; BMEditMesh *em= NULL; BMIter iter; @@ -1065,11 +1078,8 @@ static float *get_weights_array(Object *ob, char *vgroup) if(dvert==NULL) return NULL; /* find the group (weak loop-in-loop) */ - for (curdef = ob->defbase.first; curdef; curdef=curdef->next, index++) - if (!strcmp(curdef->name, vgroup)) - break; - - if(curdef) { + index= defgroup_name_index(ob, vgroup); + if(index >= 0) { float *weights; int i, j; @@ -1186,19 +1196,16 @@ static void do_mesh_key(Scene *scene, Object *ob, Key *key, char *out, int tot) static void do_cu_key(Curve *cu, Key *key, KeyBlock *actkb, KeyBlock **k, float *t, char *out, int tot) { Nurb *nu; - char *poin; int a, step; for(a=0, nu=cu->nurb.first; nu; nu=nu->next, a+=step) { if(nu->bp) { step= nu->pntsu*nu->pntsv; - poin= out - a*sizeof(float)*4; - do_key(a, a+step, tot, poin, key, actkb, k, t, KEY_BPOINT); + do_key(a, a+step, tot, out, key, actkb, k, t, KEY_BPOINT); } else if(nu->bezt) { step= 3*nu->pntsu; - poin= out - a*sizeof(float)*10; - do_key(a, a+step, tot, poin, key, actkb, k, t, KEY_BEZTRIPLE); + do_key(a, a+step, tot, out, key, actkb, k, t, KEY_BEZTRIPLE); } else step= 0; @@ -1208,19 +1215,16 @@ static void do_cu_key(Curve *cu, Key *key, KeyBlock *actkb, KeyBlock **k, float static void do_rel_cu_key(Curve *cu, Key *key, KeyBlock *actkb, float ctime, char *out, int tot) { Nurb *nu; - char *poin; int a, step; for(a=0, nu=cu->nurb.first; nu; nu=nu->next, a+=step) { if(nu->bp) { step= nu->pntsu*nu->pntsv; - poin= out - a*sizeof(float)*3; do_rel_key(a, a+step, tot, out, key, actkb, KEY_BPOINT); } else if(nu->bezt) { step= 3*nu->pntsu; - poin= out - a*sizeof(float)*10; - do_rel_key(a, a+step, tot, poin, key, actkb, KEY_BEZTRIPLE); + do_rel_key(a, a+step, tot, out, key, actkb, KEY_BEZTRIPLE); } else step= 0; @@ -1233,35 +1237,61 @@ static void do_curve_key(Scene *scene, Object *ob, Key *key, char *out, int tot) KeyBlock *k[4], *actkb= ob_get_keyblock(ob); float cfra, ctime, t[4], delta; int a, flag = 0, step = 0; - - if(key->slurph) { - delta= key->slurph; - delta/= tot; - + + if(key->slurph && key->type!=KEY_RELATIVE) { + Nurb *nu; + int mode, i= 0, remain= 0, estep, count; + + delta= (float)key->slurph / tot; + step= 1; if(tot>100 && slurph_opt) { step= tot/50; delta*= step; /* in do_key and cp_key the case a>tot has been handled */ } - + cfra= (float)scene->r.cfra; - - for(a=0; a<tot; a+=step, cfra+= delta) { - ctime= bsystem_time(scene, 0, cfra, 0.0f); // XXX old cruft -#if 0 // XXX old animation system - if(calc_ipo_spec(key->ipo, KEY_SPEED, &ctime)==0) { - ctime /= 100.0; - CLAMP(ctime, 0.0, 1.0); + + for(nu=cu->nurb.first; nu; nu=nu->next) { + if(nu->bp) { + mode= KEY_BPOINT; + estep= nu->pntsu*nu->pntsv; + } + else if(nu->bezt) { + mode= KEY_BEZTRIPLE; + estep= 3*nu->pntsu; } -#endif // XXX old animation system - - flag= setkeys(ctime, &key->block, k, t, 0); - - if(flag==0) - do_key(a, a+step, tot, (char *)out, key, actkb, k, t, 0); else - cp_key(a, a+step, tot, (char *)out, key, actkb, k[2], NULL, 0); + step= 0; + + a= 0; + while (a < estep) { + if (remain <= 0) { + cfra+= delta; + ctime= bsystem_time(scene, 0, cfra, 0.0f); // XXX old cruft + + ctime /= 100.0f; + CLAMP(ctime, 0.0f, 1.0f); // XXX for compat, we use this, but this clamping was confusing + flag= setkeys(ctime, &key->block, k, t, 0); + + remain= step; + } + + count= MIN2(remain, estep); + if (mode == KEY_BEZTRIPLE) { + count += 3 - count % 3; + } + + if(flag==0) + do_key(i, i+count, tot, (char *)out, key, actkb, k, t, mode); + else + cp_key(i, i+count, tot, (char *)out, key, actkb, k[2], NULL, mode); + + a += count; + i += count; + remain -= count; + } } } else { @@ -1385,11 +1415,11 @@ float *do_ob_key(Scene *scene, Object *ob) for(nu=cu->nurb.first; nu; nu=nu->next) { if(nu->bezt) { tot += 3*nu->pntsu; - size += nu->pntsu*10*sizeof(float); + size += nu->pntsu*12*sizeof(float); } else if(nu->bp) { tot += nu->pntsu*nu->pntsv; - size += nu->pntsu*nu->pntsv*10*sizeof(float); + size += nu->pntsu*nu->pntsv*12*sizeof(float); } } } @@ -1556,14 +1586,8 @@ KeyBlock *key_get_keyblock(Key *key, int index) /* get the appropriate KeyBlock given a name to search for */ KeyBlock *key_get_named_keyblock(Key *key, const char name[]) { - KeyBlock *kb; - - if (key && name) { - for (kb= key->block.first; kb; kb= kb->next) { - if (strcmp(name, kb->name)==0) - return kb; - } - } + if (key && name) + return BLI_findstring(&key->block, name, offsetof(KeyBlock, name)); return NULL; } @@ -1867,9 +1891,12 @@ void vertcos_to_key(Object *ob, KeyBlock *kb, float (*vertCos)[3]) tot= count_curveverts(&cu->nurb); } - fp= kb->data= MEM_callocN(tot*elemsize, "key_to_vertcos vertCos"); + if (tot == 0) { + kb->data= NULL; + return; + } - if (tot == 0) return; + fp= kb->data= MEM_callocN(tot*elemsize, "key_to_vertcos vertCos"); /* Copy coords to keyblock */ diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 55934c0af5c..725f9a34b25 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -45,6 +45,7 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" #include "DNA_scene_types.h" +#include "DNA_object_types.h" #include "DNA_lattice_types.h" #include "DNA_curve_types.h" #include "DNA_key_types.h" @@ -175,7 +176,7 @@ void resizelattice(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb) bp= lt->def; for (i=0; i<lt->pntsu*lt->pntsv*lt->pntsw; i++,bp++) { - VECCOPY(bp->vec, vertexCos[i]); + copy_v3_v3(bp->vec, vertexCos[i]); } MEM_freeN(vertexCos); @@ -225,8 +226,12 @@ void free_lattice(Lattice *lt) if(lt->def) MEM_freeN(lt->def); if(lt->dvert) free_dverts(lt->dvert, lt->pntsu*lt->pntsv*lt->pntsw); if(lt->editlatt) { - if(lt->editlatt->def) MEM_freeN(lt->editlatt->def); - if(lt->editlatt->dvert) free_dverts(lt->editlatt->dvert, lt->pntsu*lt->pntsv*lt->pntsw); + Lattice *editlt= lt->editlatt->latt; + + if(editlt->def) MEM_freeN(editlt->def); + if(editlt->dvert) free_dverts(editlt->dvert, lt->pntsu*lt->pntsv*lt->pntsw); + + MEM_freeN(editlt); MEM_freeN(lt->editlatt); } } @@ -295,7 +300,7 @@ void init_latt_deform(Object *oblatt, Object *ob) float fu, fv, fw; int u, v, w; - if(lt->editlatt) lt= lt->editlatt; + if(lt->editlatt) lt= lt->editlatt->latt; bp = lt->def; fp= lt->latticedata= MEM_mallocN(sizeof(float)*3*lt->pntsu*lt->pntsv*lt->pntsw, "latticedata"); @@ -350,7 +355,7 @@ void calc_latt_deform(Object *ob, float *co, float weight) MDeformVert *dvert= lattice_get_deform_verts(ob); - if(lt->editlatt) lt= lt->editlatt; + if(lt->editlatt) lt= lt->editlatt->latt; if(lt->latticedata==NULL) return; if(lt->vgroup[0] && dvert) { @@ -446,7 +451,7 @@ void end_latt_deform(Object *ob) { Lattice *lt= ob->data; - if(lt->editlatt) lt= lt->editlatt; + if(lt->editlatt) lt= lt->editlatt->latt; if(lt->latticedata) MEM_freeN(lt->latticedata); @@ -474,7 +479,9 @@ static void init_curve_deform(Object *par, Object *ob, CurveDeform *cd, int dloc invert_m4_m4(par->imat, par->obmat); mul_v3_m4v3(cd->dloc, par->imat, ob->obmat[3]); } - else cd->dloc[0]=cd->dloc[1]=cd->dloc[2]= 0.0f; + else { + cd->dloc[0]=cd->dloc[1]=cd->dloc[2]= 0.0f; + } cd->no_rot_axis= 0; } @@ -507,15 +514,15 @@ static int where_on_path_deform(Object *ob, float ctime, float *vec, float *dir, if(ctime < 0.0) { sub_v3_v3v3(dvec, path->data[1].vec, path->data[0].vec); mul_v3_fl(dvec, ctime*(float)path->len); - VECADD(vec, vec, dvec); - if(quat) QUATCOPY(quat, path->data[0].quat); + add_v3_v3(vec, dvec); + if(quat) copy_qt_qt(quat, path->data[0].quat); if(radius) *radius= path->data[0].radius; } else if(ctime > 1.0) { sub_v3_v3v3(dvec, path->data[path->len-1].vec, path->data[path->len-2].vec); mul_v3_fl(dvec, (ctime-1.0)*(float)path->len); - VECADD(vec, vec, dvec); - if(quat) QUATCOPY(quat, path->data[path->len-1].quat); + add_v3_v3(vec, dvec); + if(quat) copy_qt_qt(quat, path->data[path->len-1].quat); if(radius) *radius= path->data[path->len-1].radius; /* weight - not used but could be added */ } @@ -608,7 +615,7 @@ static int calc_curve_deform(Scene *scene, Object *par, float *co, short axis, C /* this is not exactly the same as 2.4x, since the axis is having rotation removed rather then * changing the axis before calculating the tilt but serves much the same purpose */ float dir_flat[3]={0,0,0}, q[4]; - VECCOPY(dir_flat, dir); + copy_v3_v3(dir_flat, dir); dir_flat[cd->no_rot_axis-1]= 0.0f; normalize_v3(dir); @@ -686,11 +693,11 @@ static int calc_curve_deform(Scene *scene, Object *par, float *co, short axis, C mul_qt_v3(quat, cent); /* translation */ - VECADD(co, cent, loc); + add_v3_v3v3(co, cent, loc); if(quatp) - QUATCOPY(quatp, quat); - + copy_qt_qt(quatp, quat); + return 1; } return 0; @@ -711,7 +718,18 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target, DerivedMesh cu->flag |= (CU_PATH|CU_FOLLOW); // needed for path & bevlist init_curve_deform(cuOb, target, &cd, (cu->flag & CU_STRETCH)==0); - + + /* dummy bounds, keep if CU_DEFORM_BOUNDS_OFF is set */ + if(defaxis < 3) { + cd.dmin[0]= cd.dmin[1]= cd.dmin[2]= 0.0f; + cd.dmax[0]= cd.dmax[1]= cd.dmax[2]= 1.0f; + } + else { + /* negative, these bounds give a good rest position */ + cd.dmin[0]= cd.dmin[1]= cd.dmin[2]= -1.0f; + cd.dmax[0]= cd.dmax[1]= cd.dmax[2]= 0.0f; + } + /* check whether to use vertex groups (only possible if target is a Mesh) * we want either a Mesh with no derived data, or derived data with * deformverts @@ -726,62 +744,84 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target, DerivedMesh use_vgroups = 0; if(vgroup && vgroup[0] && use_vgroups) { - bDeformGroup *curdef; Mesh *me= target->data; - int index; - - /* find the group (weak loop-in-loop) */ - for(index = 0, curdef = target->defbase.first; curdef; - curdef = curdef->next, index++) - if (!strcmp(curdef->name, vgroup)) - break; + int index= defgroup_name_index(target, vgroup); - if(curdef && (me->dvert || dm)) { + if(index != -1 && (me->dvert || dm)) { MDeformVert *dvert = me->dvert; float vec[3]; - int j; - - INIT_MINMAX(cd.dmin, cd.dmax); - - for(a = 0; a < numVerts; a++, dvert++) { - if(dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT); + float weight; + - for(j = 0; j < dvert->totweight; j++) { - if(dvert->dw[j].def_nr == index) { + if(cu->flag & CU_DEFORM_BOUNDS_OFF) { + /* dummy bounds */ + cd.dmin[0]= cd.dmin[1]= cd.dmin[2]= 0.0f; + cd.dmax[0]= cd.dmax[1]= cd.dmax[2]= 1.0f; + + dvert = me->dvert; + for(a = 0; a < numVerts; a++, dvert++) { + if(dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT); + weight= defvert_find_weight(dvert, index); + + if(weight > 0.0f) { mul_m4_v3(cd.curvespace, vertexCos[a]); - DO_MINMAX(vertexCos[a], cd.dmin, cd.dmax); - break; + copy_v3_v3(vec, vertexCos[a]); + calc_curve_deform(scene, cuOb, vec, defaxis, &cd, NULL); + interp_v3_v3v3(vertexCos[a], vertexCos[a], vec, weight); + mul_m4_v3(cd.objectspace, vertexCos[a]); } } } - - dvert = me->dvert; - for(a = 0; a < numVerts; a++, dvert++) { - if(dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT); - - for(j = 0; j < dvert->totweight; j++) { - if(dvert->dw[j].def_nr == index) { - VECCOPY(vec, vertexCos[a]); + else { + /* set mesh min/max bounds */ + INIT_MINMAX(cd.dmin, cd.dmax); + + for(a = 0; a < numVerts; a++, dvert++) { + if(dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT); + + if(defvert_find_weight(dvert, index) > 0.0f) { + mul_m4_v3(cd.curvespace, vertexCos[a]); + DO_MINMAX(vertexCos[a], cd.dmin, cd.dmax); + } + } + + dvert = me->dvert; + for(a = 0; a < numVerts; a++, dvert++) { + if(dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT); + + weight= defvert_find_weight(dvert, index); + + if(weight > 0.0f) { + copy_v3_v3(vec, vertexCos[a]); calc_curve_deform(scene, cuOb, vec, defaxis, &cd, NULL); - interp_v3_v3v3(vertexCos[a], vertexCos[a], vec, - dvert->dw[j].weight); + interp_v3_v3v3(vertexCos[a], vertexCos[a], vec, weight); mul_m4_v3(cd.objectspace, vertexCos[a]); - break; } } } } - } else { - INIT_MINMAX(cd.dmin, cd.dmax); - - for(a = 0; a < numVerts; a++) { - mul_m4_v3(cd.curvespace, vertexCos[a]); - DO_MINMAX(vertexCos[a], cd.dmin, cd.dmax); + } + else { + if(cu->flag & CU_DEFORM_BOUNDS_OFF) { + for(a = 0; a < numVerts; a++) { + mul_m4_v3(cd.curvespace, vertexCos[a]); + calc_curve_deform(scene, cuOb, vertexCos[a], defaxis, &cd, NULL); + mul_m4_v3(cd.objectspace, vertexCos[a]); + } } - - for(a = 0; a < numVerts; a++) { - calc_curve_deform(scene, cuOb, vertexCos[a], defaxis, &cd, NULL); - mul_m4_v3(cd.objectspace, vertexCos[a]); + else { + /* set mesh min max bounds */ + INIT_MINMAX(cd.dmin, cd.dmax); + + for(a = 0; a < numVerts; a++) { + mul_m4_v3(cd.curvespace, vertexCos[a]); + DO_MINMAX(vertexCos[a], cd.dmin, cd.dmax); + } + + for(a = 0; a < numVerts; a++) { + calc_curve_deform(scene, cuOb, vertexCos[a], defaxis, &cd, NULL); + mul_m4_v3(cd.objectspace, vertexCos[a]); + } } } cu->flag = flag; @@ -803,8 +843,8 @@ void curve_deform_vector(Scene *scene, Object *cuOb, Object *target, float *orco init_curve_deform(cuOb, target, &cd, 0); /* 0 no dloc */ cd.no_rot_axis= no_rot_axis; /* option to only rotate for XY, for example */ - VECCOPY(cd.dmin, orco); - VECCOPY(cd.dmax, orco); + copy_v3_v3(cd.dmin, orco); + copy_v3_v3(cd.dmax, orco); mul_m4_v3(cd.curvespace, vec); @@ -967,13 +1007,13 @@ float (*lattice_getVertexCos(struct Object *ob, int *numVerts_r))[3] int i, numVerts; float (*vertexCos)[3]; - if(lt->editlatt) lt= lt->editlatt; + if(lt->editlatt) lt= lt->editlatt->latt; numVerts = *numVerts_r = lt->pntsu*lt->pntsv*lt->pntsw; vertexCos = MEM_mallocN(sizeof(*vertexCos)*numVerts,"lt_vcos"); for (i=0; i<numVerts; i++) { - VECCOPY(vertexCos[i], lt->def[i].vec); + copy_v3_v3(vertexCos[i], lt->def[i].vec); } return vertexCos; @@ -985,7 +1025,7 @@ void lattice_applyVertexCos(struct Object *ob, float (*vertexCos)[3]) int i, numVerts = lt->pntsu*lt->pntsv*lt->pntsw; for (i=0; i<numVerts; i++) { - VECCOPY(lt->def[i].vec, vertexCos[i]); + copy_v3_v3(lt->def[i].vec, vertexCos[i]); } } @@ -1031,7 +1071,7 @@ struct MDeformVert* lattice_get_deform_verts(struct Object *oblatt) if(oblatt->type == OB_LATTICE) { Lattice *lt = (Lattice*)oblatt->data; - if(lt->editlatt) lt= lt->editlatt; + if(lt->editlatt) lt= lt->editlatt->latt; return lt->dvert; } diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index d6a3dc8d983..26be4114db0 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -43,27 +43,29 @@ #include "MEM_guardedalloc.h" /* all types are needed here, in order to do memory operations */ -#include "DNA_scene_types.h" -#include "DNA_mesh_types.h" -#include "DNA_lattice_types.h" -#include "DNA_meta_types.h" -#include "DNA_material_types.h" -#include "DNA_wave_types.h" -#include "DNA_lamp_types.h" +#include "DNA_anim_types.h" +#include "DNA_armature_types.h" +#include "DNA_brush_types.h" #include "DNA_camera_types.h" +#include "DNA_group_types.h" #include "DNA_ipo_types.h" #include "DNA_key_types.h" -#include "DNA_world_types.h" +#include "DNA_lamp_types.h" +#include "DNA_lattice_types.h" +#include "DNA_material_types.h" +#include "DNA_mesh_types.h" +#include "DNA_meta_types.h" +#include "DNA_nla_types.h" +#include "DNA_node_types.h" +#include "DNA_scene_types.h" #include "DNA_screen_types.h" -#include "DNA_vfont_types.h" -#include "DNA_text_types.h" #include "DNA_sound_types.h" -#include "DNA_group_types.h" -#include "DNA_armature_types.h" -#include "DNA_node_types.h" -#include "DNA_nla_types.h" +#include "DNA_text_types.h" +#include "DNA_vfont_types.h" #include "DNA_windowmanager_types.h" -#include "DNA_anim_types.h" +#include "DNA_world_types.h" +#include "DNA_gpencil_types.h" + #include "BLI_blenlib.h" #include "BLI_dynstr.h" @@ -174,8 +176,6 @@ int id_make_local(ID *id, int test) return 1; case ID_IM: return 0; /* not implemented */ - case ID_WV: - return 0; /* deprecated */ case ID_LT: if(!test) { make_local_lattice((Lattice*)id); @@ -262,9 +262,8 @@ int id_copy(ID *id, ID **newid, int test) if(!test) *newid= (ID*)copy_texture((Tex*)id); return 1; case ID_IM: - return 0; /* not implemented */ - case ID_WV: - return 0; /* deprecated */ + if(!test) *newid= (ID*)copy_image((Image*)id); + return 1; case ID_LT: if(!test) *newid= (ID*)copy_lattice((Lattice*)id); return 1; @@ -373,8 +372,6 @@ ListBase *which_libbase(Main *mainlib, short type) return &(mainlib->tex); case ID_IM: return &(mainlib->image); - case ID_WV: - return &(mainlib->wave); case ID_LT: return &(mainlib->latt); case ID_LA: @@ -474,7 +471,6 @@ int set_listbasepointers(Main *main, ListBase **lb) lb[a++]= &(main->curve); lb[a++]= &(main->mball); - lb[a++]= &(main->wave); lb[a++]= &(main->latt); lb[a++]= &(main->lamp); lb[a++]= &(main->camera); @@ -541,9 +537,6 @@ static ID *alloc_libblock_notest(short type) case ID_IM: id= MEM_callocN(sizeof(Image), "image"); break; - case ID_WV: - id= MEM_callocN(sizeof(Wave), "wave"); - break; case ID_LT: id= MEM_callocN(sizeof(Lattice), "latt"); break; @@ -745,9 +738,6 @@ void free_libblock(ListBase *lb, void *idv) case ID_IM: free_image((Image *)id); break; - case ID_WV: - /* free_wave(id); */ - break; case ID_LT: free_lattice((Lattice *)id); break; @@ -995,7 +985,7 @@ void IMAnames_to_pupstring(char **str, char *title, char *extraops, ListBase *lb /* used by buttons.c library.c mball.c */ -void splitIDname(char *name, char *left, int *nr) +int splitIDname(char *name, char *left, int *nr) { int a; @@ -1003,19 +993,23 @@ void splitIDname(char *name, char *left, int *nr) strncpy(left, name, 21); a= strlen(name); - if(a>1 && name[a-1]=='.') return; + if(a>1 && name[a-1]=='.') return a; while(a--) { if( name[a]=='.' ) { left[a]= 0; *nr= atol(name+a+1); - return; + return a; } if( isdigit(name[a])==0 ) break; left[a]= 0; } - strcpy(left, name); + + for(a= 0; name[a]; a++) + left[a]= name[a]; + + return a; } static void sort_alpha_id(ListBase *lb, ID *id) @@ -1077,8 +1071,7 @@ static ID *is_dupid(ListBase *lb, ID *id, char *name) static int check_for_dupid(ListBase *lb, ID *id, char *name) { ID *idtest; - int nr= 0, nrtest, a; - const int maxtest=32; + int nr= 0, nrtest, a, left_len; char left[32], leftest[32], in_use[32]; /* make sure input name is terminated properly */ @@ -1095,31 +1088,37 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name) /* we have a dup; need to make a new name */ /* quick check so we can reuse one of first 32 ids if vacant */ - memset(in_use, 0, maxtest); + memset(in_use, 0, sizeof(in_use)); /* get name portion, number portion ("name.number") */ - splitIDname( name, left, &nr); + left_len= splitIDname(name, left, &nr); /* if new name will be too long, truncate it */ - if(nr>999 && strlen(left)>16) left[16]= 0; - else if(strlen(left)>17) left[17]= 0; - - for( idtest = lb->first; idtest; idtest = idtest->next ) { - if( id != idtest && idtest->lib == NULL ) { - splitIDname(idtest->name+2, leftest, &nrtest); - /* if base names match... */ - /* optimized */ - if( *left == *leftest && strcmp(left, leftest)==0 ) { - if(nrtest < maxtest) - in_use[nrtest]= 1; /* mark as used */ - if(nr <= nrtest) - nr= nrtest+1; /* track largest unused */ - } + if(nr > 999 && left_len > 16) { + left[16]= 0; + left_len= 16; + } + else if(left_len > 17) { + left[17]= 0; + left_len= 17; + } + + for(idtest= lb->first; idtest; idtest= idtest->next) { + if( (id != idtest) && + (idtest->lib == NULL) && + (*name == *(idtest->name+2)) && + (strncmp(name, idtest->name+2, left_len)==0) && + (splitIDname(idtest->name+2, leftest, &nrtest) == left_len) + ) { + if(nrtest < sizeof(in_use)) + in_use[nrtest]= 1; /* mark as used */ + if(nr <= nrtest) + nr= nrtest+1; /* track largest unused */ } } /* decide which value of nr to use */ - for(a=0; a<maxtest; a++) { + for(a=0; a < sizeof(in_use); a++) { if(a>=nr) break; /* stop when we've check up to biggest */ if( in_use[a]==0 ) { /* found an unused value */ nr = a; @@ -1129,9 +1128,10 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name) /* If the original name has no numeric suffix, * rather than just chopping and adding numbers, - * shave off the end chars until we have a unique name */ - if (nr==0) { - int len = strlen(name)-1; + * shave off the end chars until we have a unique name. + * Check the null terminators match as well so we dont get Cube.000 -> Cube.00 */ + if (nr==0 && name[left_len]== '\0') { + int len = left_len-1; idtest= is_dupid(lb, id, name); while (idtest && len> 1) { @@ -1142,10 +1142,11 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name) /* otherwise just continue and use a number suffix */ } - if(nr > 999 && strlen(left) > 16) { + if(nr > 999 && left_len > 16) { /* this would overflow name buffer */ left[16] = 0; - strcpy( name, left ); + /* left_len = 16; */ /* for now this isnt used again */ + memcpy(name, left, sizeof(char) * 16); continue; } /* this format specifier is from hell... */ @@ -1303,7 +1304,7 @@ void all_local(Library *lib, int untagged_only) /* The check on the second line (LIB_PRE_EXISTING) is done so its * possible to tag data you dont want to be made local, used for - * appending data, so any libdata alredy linked wont become local + * appending data, so any libdata already linked wont become local * (very nasty to discover all your links are lost after appending) * */ if(id->flag & (LIB_EXTERN|LIB_INDIRECT|LIB_NEW) && @@ -1390,3 +1391,11 @@ void rename_id(ID *id, char *name) new_id(lb, id, name); } +void name_uiprefix_id(char *name, ID *id) +{ + name[0] = id->lib ? 'L':' '; + name[1] = id->flag & LIB_FAKEUSER ? 'F':' '; + name[2] = ' '; + + strcpy(name+3, id->name+2); +} diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 11c96e9a347..9774e97f69b 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -56,10 +56,6 @@ #include "BKE_node.h" #include "BKE_utildefines.h" -#ifndef DISABLE_PYTHON -#include "BPY_extern.h" -#endif - #include "GPU_material.h" /* used in UI and render */ @@ -236,6 +232,7 @@ Material *copy_material(Material *ma) void make_local_material(Material *ma) { + Main *bmain= G.main; Object *ob; Mesh *me; Curve *cu; @@ -261,7 +258,7 @@ void make_local_material(Material *ma) } /* test objects */ - ob= G.main->object.first; + ob= bmain->object.first; while(ob) { if(ob->mat) { for(a=0; a<ob->totcol; a++) { @@ -274,7 +271,7 @@ void make_local_material(Material *ma) ob= ob->id.next; } /* test meshes */ - me= G.main->mesh.first; + me= bmain->mesh.first; while(me) { if(me->mat) { for(a=0; a<me->totcol; a++) { @@ -287,7 +284,7 @@ void make_local_material(Material *ma) me= me->id.next; } /* test curves */ - cu= G.main->curve.first; + cu= bmain->curve.first; while(cu) { if(cu->mat) { for(a=0; a<cu->totcol; a++) { @@ -300,7 +297,7 @@ void make_local_material(Material *ma) cu= cu->id.next; } /* test mballs */ - mb= G.main->mball.first; + mb= bmain->mball.first; while(mb) { if(mb->mat) { for(a=0; a<mb->totcol; a++) { @@ -329,7 +326,7 @@ void make_local_material(Material *ma) man->id.us= 0; /* do objects */ - ob= G.main->object.first; + ob= bmain->object.first; while(ob) { if(ob->mat) { for(a=0; a<ob->totcol; a++) { @@ -345,7 +342,7 @@ void make_local_material(Material *ma) ob= ob->id.next; } /* do meshes */ - me= G.main->mesh.first; + me= bmain->mesh.first; while(me) { if(me->mat) { for(a=0; a<me->totcol; a++) { @@ -361,7 +358,7 @@ void make_local_material(Material *ma) me= me->id.next; } /* do curves */ - cu= G.main->curve.first; + cu= bmain->curve.first; while(cu) { if(cu->mat) { for(a=0; a<cu->totcol; a++) { @@ -377,7 +374,7 @@ void make_local_material(Material *ma) cu= cu->id.next; } /* do mballs */ - mb= G.main->mball.first; + mb= bmain->mball.first; while(mb) { if(mb->mat) { for(a=0; a<mb->totcol; a++) { @@ -783,14 +780,14 @@ void init_render_material(Material *mat, int r_mode, float *amb) } } -void init_render_materials(int r_mode, float *amb) +void init_render_materials(Main *bmain, int r_mode, float *amb) { Material *ma; /* clear these flags before going over materials, to make sure they * are cleared only once, otherwise node materials contained in other * node materials can go wrong */ - for(ma= G.main->mat.first; ma; ma= ma->id.next) { + for(ma= bmain->mat.first; ma; ma= ma->id.next) { if(ma->id.us) { ma->texco= 0; ma->mapto= 0; @@ -798,7 +795,7 @@ void init_render_materials(int r_mode, float *amb) } /* two steps, first initialize, then or the flags for layers */ - for(ma= G.main->mat.first; ma; ma= ma->id.next) { + for(ma= bmain->mat.first; ma; ma= ma->id.next) { /* is_used flag comes back in convertblender.c */ ma->flag &= ~MA_IS_USED; if(ma->id.us) @@ -815,10 +812,10 @@ void end_render_material(Material *mat) ntreeEndExecTree(mat->nodetree); /* has internal flag to detect it only does it once */ } -void end_render_materials(void) +void end_render_materials(Main *bmain) { Material *ma; - for(ma= G.main->mat.first; ma; ma= ma->id.next) + for(ma= bmain->mat.first; ma; ma= ma->id.next) if(ma->id.us) end_render_material(ma); } diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 956fe10ee4b..71abab93989 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -384,6 +384,7 @@ void make_local_tface(Mesh *me) void make_local_mesh(Mesh *me) { + Main *bmain= G.main; Object *ob; Mesh *men; int local=0, lib=0; @@ -404,7 +405,7 @@ void make_local_mesh(Mesh *me) return; } - ob= G.main->object.first; + ob= bmain->object.first; while(ob) { if( me==get_mesh(ob) ) { if(ob->id.lib) lib= 1; @@ -425,7 +426,7 @@ void make_local_mesh(Mesh *me) men= copy_mesh(me); men->id.us= 0; - ob= G.main->object.first; + ob= bmain->object.first; while(ob) { if( me==get_mesh(ob) ) { if(ob->id.lib==0) { @@ -439,33 +440,23 @@ void make_local_mesh(Mesh *me) void boundbox_mesh(Mesh *me, float *loc, float *size) { - MVert *mvert; BoundBox *bb; float min[3], max[3]; float mloc[3], msize[3]; - int a; if(me->bb==0) me->bb= MEM_callocN(sizeof(BoundBox), "boundbox"); bb= me->bb; - - INIT_MINMAX(min, max); if (!loc) loc= mloc; if (!size) size= msize; - mvert= me->mvert; - for(a=0; a<me->totvert; a++, mvert++) { - DO_MINMAX(mvert->co, min, max); - } - - if(!me->totvert) { + INIT_MINMAX(min, max); + if(!minmax_mesh(me, min, max)) { min[0] = min[1] = min[2] = -1.0f; max[0] = max[1] = max[2] = 1.0f; } - loc[0]= (min[0]+max[0])/2.0f; - loc[1]= (min[1]+max[1])/2.0f; - loc[2]= (min[2]+max[2])/2.0f; + mid_v3_v3v3(loc, min, max); size[0]= (max[0]-min[0])/2.0f; size[1]= (max[1]-min[1])/2.0f; @@ -488,9 +479,9 @@ void tex_space_mesh(Mesh *me) else if(size[a]<0.0 && size[a]> -0.00001) size[a]= -0.00001; } - VECCOPY(me->loc, loc); - VECCOPY(me->size, size); - me->rot[0]= me->rot[1]= me->rot[2]= 0.0; + copy_v3_v3(me->loc, loc); + copy_v3_v3(me->size, size); + zero_v3(me->rot); } } @@ -532,9 +523,7 @@ float *get_mesh_orco_verts(Object *ob) totvert = MIN2(tme->totvert, me->totvert); for(a=0; a<totvert; a++, mvert++) { - vcos[a][0]= mvert->co[0]; - vcos[a][1]= mvert->co[1]; - vcos[a][2]= mvert->co[2]; + copy_v3_v3(vcos[a], mvert->co); } return (float*)vcos; @@ -550,9 +539,7 @@ void transform_mesh_orco_verts(Mesh *me, float (*orco)[3], int totvert, int inve if(invert) { for(a=0; a<totvert; a++) { float *co = orco[a]; - co[0] = co[0]*size[0] + loc[0]; - co[1] = co[1]*size[1] + loc[1]; - co[2] = co[2]*size[2] + loc[2]; + madd_v3_v3v3v3(co, loc, co, size); } } else { @@ -816,7 +803,6 @@ void mball_to_mesh(ListBase *lb, Mesh *me) if(dl==0) return; if(dl->type==DL_INDEX4) { - me->flag= ME_NOPUNOFLIP; me->totvert= dl->nr; me->totface= dl->parts; @@ -1059,6 +1045,7 @@ int nurbs_to_mdata_customdb(Object *ob, ListBase *dispbase, MVert **allvert, int /* this may fail replacing ob->data, be sure to check ob->type */ void nurbs_to_mesh(Object *ob) { + Main *bmain= G.main; Object *ob1; DerivedMesh *dm= ob->derivedFinal; Mesh *me; @@ -1101,13 +1088,13 @@ void nurbs_to_mesh(Object *ob) cu->totcol= 0; if(ob->data) { - free_libblock(&G.main->curve, ob->data); + free_libblock(&bmain->curve, ob->data); } ob->data= me; ob->type= OB_MESH; /* other users */ - ob1= G.main->object.first; + ob1= bmain->object.first; while(ob1) { if(ob1->data==cu) { ob1->type= OB_MESH; @@ -1368,14 +1355,10 @@ void mesh_calc_normals(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, MVert *mv= &mverts[i]; float *no= tnorms[i]; - if (normalize_v3(no)==0.0) { - VECCOPY(no, mv->co); - normalize_v3(no); - } + if (normalize_v3(no)==0.0) + normalize_v3_v3(no, mv->co); - mv->no[0]= (short)(no[0]*32767.0); - mv->no[1]= (short)(no[1]*32767.0); - mv->no[2]= (short)(no[2]*32767.0); + normal_float_to_short_v3(mv->no, no); } MEM_freeN(tnorms); @@ -1889,3 +1872,59 @@ void mesh_calc_poly_normal(MPoly *mpoly, MLoop *loopstart, no[2] = 1.0; } } + +/* basic vertex data functions */ +int minmax_mesh(Mesh *me, float min[3], float max[3]) +{ + int i= me->totvert; + MVert *mvert; + for(mvert= me->mvert; i--; mvert++) { + DO_MINMAX(mvert->co, min, max); + } + + return (me->totvert != 0); +} + +int mesh_center_median(Mesh *me, float cent[3]) +{ + int i= me->totvert; + MVert *mvert; + zero_v3(cent); + for(mvert= me->mvert; i--; mvert++) { + add_v3_v3(cent, mvert->co); + } + mul_v3_fl(cent, 1.0f/(float)me->totvert); + + return (me->totvert != 0); +} + +int mesh_center_bounds(Mesh *me, float cent[3]) +{ + float min[3], max[3]; + INIT_MINMAX(min, max); + if(minmax_mesh(me, min, max)) { + mid_v3_v3v3(cent, min, max); + return 1; + } + + return 0; +} + +void mesh_translate(Mesh *me, float offset[3], int do_keys) +{ + int i= me->totvert; + MVert *mvert; + for(mvert= me->mvert; i--; mvert++) { + add_v3_v3(mvert->co, offset); + } + + if (do_keys && me->key) { + KeyBlock *kb; + for (kb=me->key->block.first; kb; kb=kb->next) { + float *fp= kb->data; + for (i= kb->totelem; i--; fp+=3) { + add_v3_v3(fp, offset); + } + } + } +} diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 858e9d6c6d9..63f0f1fa091 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -34,13 +34,17 @@ * */ -#include "stddef.h" -#include "string.h" -#include "stdarg.h" -#include "math.h" -#include "float.h" +#include <stddef.h> +#include <string.h> +#include <stdarg.h> +#include <math.h> +#include <float.h> #include "DNA_armature_types.h" +#include "DNA_object_types.h" +#include "DNA_meshdata_types.h" + +#include "MEM_guardedalloc.h" #include "BKE_bmesh.h" #include "BKE_cloth.h" @@ -193,7 +197,7 @@ void modifier_copyData(ModifierData *md, ModifierData *target) mti->copyData(md, target); } -int modifier_couldBeCage(Scene *scene, ModifierData *md) +int modifier_couldBeCage(struct Scene *scene, ModifierData *md) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); @@ -233,7 +237,7 @@ void modifier_setError(ModifierData *md, char *format, ...) * also used in transform_conversion.c, to detect CrazySpace [tm] (2nd arg * then is NULL) */ -int modifiers_getCageIndex(Scene *scene, Object *ob, int *lastPossibleCageIndex_r, int virtual_) +int modifiers_getCageIndex(struct Scene *scene, Object *ob, int *lastPossibleCageIndex_r, int virtual_) { ModifierData *md = (virtual_)? modifiers_getVirtualModifierList(ob): ob->modifiers.first; int i, cageIndex = -1; @@ -283,7 +287,7 @@ int modifiers_isParticleEnabled(Object *ob) return (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)); } -int modifier_isEnabled(Scene *scene, ModifierData *md, int required_mode) +int modifier_isEnabled(struct Scene *scene, ModifierData *md, int required_mode) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); @@ -298,7 +302,7 @@ int modifier_isEnabled(Scene *scene, ModifierData *md, int required_mode) return 1; } -LinkNode *modifiers_calcDataMasks(Scene *scene, Object *ob, ModifierData *md, CustomDataMask dataMask, int required_mode) +LinkNode *modifiers_calcDataMasks(struct Scene *scene, Object *ob, ModifierData *md, CustomDataMask dataMask, int required_mode) { LinkNode *dataMasks = NULL; LinkNode *curr, *prev; @@ -487,7 +491,7 @@ int modifier_isCorrectableDeformed(ModifierData *md) return 0; } -int modifiers_isCorrectableDeformed(Scene *scene, Object *ob) +int modifiers_isCorrectableDeformed(struct Scene *scene, Object *ob) { ModifierData *md = modifiers_getVirtualModifierList(ob); diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index 8d2ad49e7bf..b053d615756 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -1265,13 +1265,13 @@ void BKE_nlastrip_validate_name (AnimData *adt, NlaStrip *strip) char *dot; /* Strip off the suffix */ - dot = strchr(strip->name, '.'); + dot = strrchr(strip->name, '.'); if (dot) *dot=0; /* Try different possibilities */ for (number = 1; number <= 999; number++) { /* assemble alternative name */ - BLI_snprintf(tempname, 128, "%s%c%03d", strip->name, ".", number); + BLI_snprintf(tempname, 128, "%s.%03d", strip->name, number); /* if hash doesn't have this, set it */ if (BLI_ghash_haskey(gh, tempname) == 0) { diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 838ec24391c..eb09ecf2e6e 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -45,7 +45,6 @@ #include "PIL_time.h" -#include "MEM_guardedalloc.h" #include "CMP_node.h" #include "intern/CMP_util.h" /* stupid include path... */ @@ -735,13 +734,7 @@ void nodeGroupSocketUseFlags(bNodeTree *ngroup) /* finds a node based on its name */ bNode *nodeFindNodebyName(bNodeTree *ntree, const char *name) { - bNode *node=NULL; - - for(node= ntree->nodes.first; node; node= node->next) { - if (strcmp(name, node->name) == 0) - break; - } - return node; + return BLI_findstring(&ntree->nodes, name, offsetof(bNode, name)); } /* finds a node based on given socket */ @@ -1064,6 +1057,7 @@ bNodeTree *ntreeAddTree(int type) * - internal_select is only 1 when used for duplicating selected nodes (i.e. Shift-D duplicate operator) * - this gets called when executing compositing updates (for threaded previews) * - when the nodetree datablock needs to be copied (i.e. when users get copied) + * - for scene duplication use ntreeSwapID() after so we dont have stale pointers. */ bNodeTree *ntreeCopyTree(bNodeTree *ntree, int internal_select) { @@ -1142,6 +1136,18 @@ bNodeTree *ntreeCopyTree(bNodeTree *ntree, int internal_select) return newtree; } +/* use when duplicating scenes */ +void ntreeSwitchID(bNodeTree *ntree, ID *id_from, ID *id_to) +{ + bNode *node; + /* for scene duplication only */ + for(node= ntree->nodes.first; node; node= node->next) { + if(node->id==id_from) { + node->id= id_to; + } + } +} + /* *************** preview *********** */ /* if node->preview, then we assume the rect to exist */ @@ -1842,9 +1848,8 @@ static void node_group_execute(bNodeStack *stack, void *data, bNode *gnode, bNod /* for groups, only execute outputs for edited group */ if(node->typeinfo->nclass==NODE_CLASS_OUTPUT) { - if(gnode->flag & NODE_GROUP_EDIT) - if(node->flag & NODE_DO_OUTPUT) - node->typeinfo->execfunc(data, node, nsin, nsout); + if(node->type==CMP_NODE_OUTPUT_FILE || (gnode->flag & NODE_GROUP_EDIT)) + node->typeinfo->execfunc(data, node, nsin, nsout); } else node->typeinfo->execfunc(data, node, nsin, nsout); @@ -2565,7 +2570,7 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree) if(ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { if(node->id) { if(node->flag & NODE_DO_OUTPUT) - node->new_node->id= (ID *)BKE_image_copy((Image *)node->id); + node->new_node->id= (ID *)copy_image((Image *)node->id); else node->new_node->id= NULL; } @@ -2651,8 +2656,9 @@ void ntreeLocalMerge(bNodeTree *localtree, bNodeTree *ntree) for(lsock= lnode->outputs.first; lsock; lsock= lsock->next) { if(outsocket_exists(lnode->new_node, lsock->new_sock)) { lsock->new_sock->ns.data= lsock->ns.data; + compbuf_set_node(lsock->new_sock->ns.data, lnode->new_node); lsock->ns.data= NULL; - lsock->new_sock= NULL; + lsock->new_sock= NULL; } } } diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index a6565ade028..2649d95dd88 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -284,7 +284,7 @@ void free_object(Object *ob) ob->path= 0; if(ob->adt) BKE_free_animdata((ID *)ob); if(ob->poselib) ob->poselib->id.us--; - if(ob->gpd) ob->gpd->id.us--; + if(ob->gpd) ((ID *)ob->gpd)->us--; if(ob->defbase.first) BLI_freelistN(&ob->defbase); if(ob->pose) @@ -323,6 +323,7 @@ static void unlink_object__unlinkModifierLinks(void *userData, Object *ob, Objec void unlink_object(Scene *scene, Object *ob) { + Main *bmain= G.main; Object *obt; Material *mat; World *wrld; @@ -344,7 +345,7 @@ void unlink_object(Scene *scene, Object *ob) /* check all objects: parents en bevels and fields, also from libraries */ // FIXME: need to check all animation blocks (drivers) - obt= G.main->object.first; + obt= bmain->object.first; while(obt) { if(obt->proxy==ob) obt->proxy= NULL; @@ -518,7 +519,7 @@ void unlink_object(Scene *scene, Object *ob) } /* materials */ - mat= G.main->mat.first; + mat= bmain->mat.first; while(mat) { for(a=0; a<MAX_MTEX; a++) { @@ -532,7 +533,7 @@ void unlink_object(Scene *scene, Object *ob) } /* textures */ - tex= G.main->tex.first; + tex= bmain->tex.first; while(tex) { if(tex->env) { if(tex->env->object == ob) tex->env->object= NULL; @@ -541,7 +542,7 @@ void unlink_object(Scene *scene, Object *ob) } /* worlds */ - wrld= G.main->world.first; + wrld= bmain->world.first; while(wrld) { if(wrld->id.lib==NULL) { for(a=0; a<MAX_MTEX; a++) { @@ -554,7 +555,7 @@ void unlink_object(Scene *scene, Object *ob) } /* scenes */ - sce= G.main->scene.first; + sce= bmain->scene.first; while(sce) { if(sce->id.lib==NULL) { if(sce->camera==ob) sce->camera= NULL; @@ -586,7 +587,7 @@ void unlink_object(Scene *scene, Object *ob) #if 0 // XXX old animation system /* ipos */ - ipo= G.main->ipo.first; + ipo= bmain->ipo.first; while(ipo) { if(ipo->id.lib==NULL) { IpoCurve *icu; @@ -600,7 +601,7 @@ void unlink_object(Scene *scene, Object *ob) #endif // XXX old animation system /* screens */ - sc= G.main->screen.first; + sc= bmain->screen.first; while(sc) { ScrArea *sa= sc->areabase.first; while(sa) { @@ -665,14 +666,14 @@ void unlink_object(Scene *scene, Object *ob) } /* groups */ - group= G.main->group.first; + group= bmain->group.first; while(group) { rem_from_group(group, ob, NULL, NULL); group= group->id.next; } /* cameras */ - camera= G.main->camera.first; + camera= bmain->camera.first; while(camera) { if (camera->dof_ob==ob) { camera->dof_ob = NULL; @@ -726,6 +727,7 @@ Camera *copy_camera(Camera *cam) void make_local_camera(Camera *cam) { + Main *bmain= G.main; Object *ob; Camera *camn; int local=0, lib=0; @@ -743,7 +745,7 @@ void make_local_camera(Camera *cam) return; } - ob= G.main->object.first; + ob= bmain->object.first; while(ob) { if(ob->data==cam) { if(ob->id.lib) lib= 1; @@ -761,7 +763,7 @@ void make_local_camera(Camera *cam) camn= copy_camera(cam); camn->id.us= 0; - ob= G.main->object.first; + ob= bmain->object.first; while(ob) { if(ob->data==cam) { @@ -874,6 +876,7 @@ Lamp *copy_lamp(Lamp *la) void make_local_lamp(Lamp *la) { + Main *bmain= G.main; Object *ob; Lamp *lan; int local=0, lib=0; @@ -891,7 +894,7 @@ void make_local_lamp(Lamp *la) return; } - ob= G.main->object.first; + ob= bmain->object.first; while(ob) { if(ob->data==la) { if(ob->id.lib) lib= 1; @@ -909,7 +912,7 @@ void make_local_lamp(Lamp *la) lan= copy_lamp(la); lan->id.us= 0; - ob= G.main->object.first; + ob= bmain->object.first; while(ob) { if(ob->data==la) { @@ -949,12 +952,6 @@ void free_lamp(Lamp *la) la->id.icon_id = 0; } -void *add_wave() -{ - return 0; -} - - /* *************************************************** */ static void *add_obdata_from_type(int type) @@ -968,7 +965,6 @@ static void *add_obdata_from_type(int type) case OB_CAMERA: return add_camera("Camera"); case OB_LAMP: return add_lamp("Lamp"); case OB_LATTICE: return add_lattice("Lattice"); - case OB_WAVE: return add_wave(); case OB_ARMATURE: return add_armature("Armature"); case OB_EMPTY: return NULL; default: @@ -988,7 +984,6 @@ static char *get_obdata_defname(int type) case OB_CAMERA: return "Camera"; case OB_LAMP: return "Lamp"; case OB_LATTICE: return "Lattice"; - case OB_WAVE: return "Wave"; case OB_ARMATURE: return "Armature"; case OB_EMPTY: return "Empty"; default: @@ -1375,6 +1370,7 @@ void expand_local_object(Object *ob) void make_local_object(Object *ob) { + Main *bmain= G.main; Object *obn; Scene *sce; Base *base; @@ -1396,7 +1392,7 @@ void make_local_object(Object *ob) } else { - sce= G.main->scene.first; + sce= bmain->scene.first; while(sce) { base= sce->base.first; while(base) { @@ -1419,7 +1415,7 @@ void make_local_object(Object *ob) obn= copy_object(ob); obn->id.us= 0; - sce= G.main->scene.first; + sce= bmain->scene.first; while(sce) { if(sce->id.lib==0) { base= sce->base.first; @@ -1636,10 +1632,7 @@ float bsystem_time(struct Scene *scene, Object *ob, float cfra, float ofs) void object_scale_to_mat3(Object *ob, float mat[][3]) { float vec[3]; - - vec[0]= ob->size[0]+ob->dsize[0]; - vec[1]= ob->size[1]+ob->dsize[1]; - vec[2]= ob->size[2]+ob->dsize[2]; + add_v3_v3v3(vec, ob->size, ob->dsize); size_to_mat3( mat,vec); } @@ -1697,7 +1690,7 @@ void object_mat3_to_rot(Object *ob, float mat[][3], int use_compat) void object_apply_mat4(Object *ob, float mat[][4]) { float mat3[3][3]; - VECCOPY(ob->loc, mat[3]); + copy_v3_v3(ob->loc, mat[3]); mat4_to_size(ob->size, mat); copy_m3_m4(mat3, mat); object_mat3_to_rot(ob, mat3, 0); @@ -1805,7 +1798,7 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4]) copy_m4_m4(mat, rmat); } - VECCOPY(mat[3], vec); + copy_v3_v3(mat[3], vec); } } @@ -1832,7 +1825,7 @@ static void ob_parbone(Object *ob, Object *par, float mat[][4]) copy_m4_m4(mat, pchan->pose_mat); /* but for backwards compatibility, the child has to move to the tail */ - VECCOPY(vec, mat[1]); + copy_v3_v3(vec, mat[1]); mul_v3_fl(vec, pchan->bone->length); add_v3_v3(mat[3], vec); } @@ -1847,6 +1840,7 @@ static void give_parvert(Object *par, int nr, float *vec) if(par->type==OB_MESH) { Mesh *me= par->data; em = me->edit_btmesh; + DerivedMesh *dm; if(em) { BMVert *eve; @@ -1861,33 +1855,32 @@ static void give_parvert(Object *par, int nr, float *vec) } } } - else { - DerivedMesh *dm = par->derivedFinal; + + dm = (em)? em->derivedFinal: par->derivedFinal; - if(dm) { - MVert *mvert= dm->getVertArray(dm); - int *index = (int *)dm->getVertDataArray(dm, CD_ORIGINDEX); - int i, count = 0, vindex, numVerts = dm->getNumVerts(dm); - - /* get the average of all verts with (original index == nr) */ - for(i = 0; i < numVerts; i++) { - vindex= (index)? index[i]: i; - - if(vindex == nr) { - add_v3_v3(vec, mvert[i].co); - count++; - } - } + if(dm) { + MVert *mvert= dm->getVertArray(dm); + int *index = (int *)dm->getVertDataArray(dm, CD_ORIGINDEX); + int i, count = 0, vindex, numVerts = dm->getNumVerts(dm); + + /* get the average of all verts with (original index == nr) */ + for(i = 0; i < numVerts; i++) { + vindex= (index)? index[i]: i; - if (count==0) { - /* keep as 0,0,0 */ - } else if(count > 0) { - mul_v3_fl(vec, 1.0f / count); - } else { - /* use first index if its out of range */ - dm->getVertCo(dm, 0, vec); + if(vindex == nr) { + add_v3_v3(vec, mvert[i].co); + count++; } } + + if (count==0) { + /* keep as 0,0,0 */ + } else if(count > 0) { + mul_v3_fl(vec, 1.0f / count); + } else { + /* use first index if its out of range */ + dm->getVertCo(dm, 0, vec); + } } } else if (ELEM(par->type, OB_CURVE, OB_SURF)) { @@ -1896,13 +1889,12 @@ static void give_parvert(Object *par, int nr, float *vec) BPoint *bp; BezTriple *bezt; int found= 0; - + ListBase *nurbs; + cu= par->data; - if(cu->editnurb) - nu= cu->editnurb->first; - else - nu= cu->nurb.first; - + nurbs= BKE_curve_nurbs(cu); + nu= nurbs->first; + count= 0; while(nu && !found) { if(nu->type == CU_BEZIER) { @@ -1941,7 +1933,7 @@ static void give_parvert(Object *par, int nr, float *vec) DispList *dl = find_displist(&par->disp, DL_VERTS); float *co = dl?dl->verts:NULL; - if(latt->editlatt) latt= latt->editlatt; + if(latt->editlatt) latt= latt->editlatt->latt; a= latt->pntsu*latt->pntsv*latt->pntsw; count= 0; @@ -2336,11 +2328,9 @@ void minmax_object(Object *ob, float *min, float *max) if(ob->pose) { bPoseChannel *pchan; for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - VECCOPY(vec, pchan->pose_head); - mul_m4_v3(ob->obmat, vec); + mul_v3_m4v3(vec, ob->obmat, pchan->pose_head); DO_MINMAX(vec, min, max); - VECCOPY(vec, pchan->pose_tail); - mul_m4_v3(ob->obmat, vec); + mul_v3_m4v3(vec, ob->obmat, pchan->pose_tail); DO_MINMAX(vec, min, max); } break; @@ -2527,7 +2517,7 @@ void object_handle_update(Scene *scene, Object *ob) /* includes all keys and modifiers */ if(ob->type==OB_MESH) { - BMEditMesh *em = ((Mesh*)ob->data)->edit_btmesh; + BMEditMesh *em = (ob == scene->obedit)? ((Mesh*)ob->data)->edit_btmesh : NULL; /* evaluate drivers */ // XXX: should we push this to derivedmesh instead? @@ -2956,7 +2946,7 @@ static KeyBlock *insert_curvekey(Scene *scene, Object *ob, char *name, int from_ Curve *cu= ob->data; Key *key= cu->key; KeyBlock *kb; - ListBase *lb= (cu->editnurb)? cu->editnurb: &cu->nurb; + ListBase *lb= BKE_curve_nurbs(cu); int newkey= 0; if(key==NULL) { @@ -2968,7 +2958,11 @@ static KeyBlock *insert_curvekey(Scene *scene, Object *ob, char *name, int from_ if(newkey || from_mix==FALSE) { /* create from curve */ kb= add_keyblock(key, name); - curve_to_key(cu, kb, lb); + if (!newkey) { + KeyBlock *basekb= (KeyBlock *)key->block.first; + kb->data= MEM_dupallocN(basekb->data); + kb->totelem= basekb->totelem; + } else curve_to_key(cu, kb, lb); } else { /* copy from current values */ diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index cf5deb95258..ffb99c10c40 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -25,11 +25,11 @@ * ***** END GPL LICENSE BLOCK ***** */ -#include "MEM_guardedalloc.h" #include "DNA_object_types.h" #include "DNA_mesh_types.h" #include "DNA_scene_types.h" +#include "DNA_brush_types.h" #include "BKE_brush.h" #include "BKE_library.h" @@ -70,91 +70,13 @@ Paint *paint_get_active(Scene *sce) Brush *paint_brush(Paint *p) { - return p && p->brushes ? p->brushes[p->active_brush_index] : NULL; + return p ? p->brush : 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; - } + if(p) + p->brush= br; } int paint_facesel_test(Object *ob) @@ -168,7 +90,8 @@ void paint_init(Paint *p, const char col[3]) /* If there's no brush, create one */ brush = paint_brush(p); - brush_check_exists(&brush, "Brush"); + if(brush == NULL) + brush= add_brush("Brush"); paint_brush_set(p, brush); memcpy(p->paint_cursor_col, col, 3); @@ -179,16 +102,10 @@ void paint_init(Paint *p, const char col[3]) void free_paint(Paint *paint) { - if(paint->brushes) - MEM_freeN(paint->brushes); + /* nothing */ } -void copy_paint(Paint *orig, Paint *new) +void copy_paint(Paint *src, Paint *tar) { - 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]); - } + tar->brush= src->brush; } diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 4c68c5487c8..993eefcb6f9 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -40,13 +40,17 @@ #include "DNA_key_types.h" #include "DNA_material_types.h" #include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" #include "DNA_particle_types.h" #include "DNA_smoke_types.h" +#include "DNA_scene_types.h" +#include "BLI_blenlib.h" #include "BLI_kdtree.h" #include "BLI_rand.h" #include "BLI_threads.h" #include "BLI_cellalloc.h" +#include "BLI_math.h" #include "BKE_anim.h" #include "BKE_animsys.h" @@ -434,7 +438,7 @@ void free_keyed_keys(ParticleSystem *psys) } } } -void psys_free_child_path_cache(ParticleSystem *psys) +static void free_child_path_cache(ParticleSystem *psys) { psys_free_path_cache_buffers(psys->childcache, &psys->childcachebufs); psys->childcache = NULL; @@ -452,7 +456,7 @@ void psys_free_path_cache(ParticleSystem *psys, PTCacheEdit *edit) psys->pathcache= NULL; psys->totcached= 0; - psys_free_child_path_cache(psys); + free_child_path_cache(psys); } } void psys_free_children(ParticleSystem *psys) @@ -463,7 +467,7 @@ void psys_free_children(ParticleSystem *psys) psys->totchild=0; } - psys_free_child_path_cache(psys); + free_child_path_cache(psys); } void psys_free_particles(ParticleSystem *psys) { @@ -621,8 +625,7 @@ static float psys_render_projected_area(ParticleSystem *psys, float *center, flo mul_m4_v4(data->viewmat, co); /* compute two vectors orthogonal to view vector */ - VECCOPY(view, co); - normalize_v3(view); + normalize_v3_v3(view, co); ortho_basis_v3v3_v3( ortho1, ortho2,view); /* compute on screen minification */ @@ -1920,8 +1923,7 @@ static void do_prekink(ParticleKey *state, ParticleKey *par, float *par_rot, flo mul_qt_v3(q2,z_vec); VECSUB(vec_from_par,state->co,par->co); - VECCOPY(vec_one,vec_from_par); - radius=normalize_v3(vec_one); + radius= normalize_v3_v3(vec_one, vec_from_par); inp_y=dot_v3v3(y_vec,vec_one); inp_z=dot_v3v3(z_vec,vec_one); @@ -2722,7 +2724,7 @@ void psys_cache_child_paths(ParticleSimulationData *sim, float cfra, int editupd } else { /* clear out old and create new empty path cache */ - psys_free_child_path_cache(sim->psys); + free_child_path_cache(sim->psys); sim->psys->childcache= psys_alloc_path_cache_buffers(&sim->psys->childcachebufs, totchild, ctx->steps+1); sim->psys->totchildcache = totchild; } @@ -2788,7 +2790,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) int steps = (int)pow(2.0, (double)(psys->renderdata ? part->ren_step : part->draw_step)); int totpart = psys->totpart; float length, vec[3]; - float *vg_effector= NULL, effector=0.0f; + float *vg_effector= NULL; float *vg_length= NULL, pa_length=1.0f; int keyed, baked; @@ -2890,85 +2892,83 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) /*--modify paths and calculate rotation & velocity--*/ - sub_v3_v3v3(vec,(cache[p]+1)->co,cache[p]->co); - length = len_v3(vec); + if(!(psys->flag & PSYS_GLOBAL_HAIR)) { + /* apply effectors */ + if((psys->part->flag & PART_CHILD_EFFECT) == 0) { + float effector= 1.0f; + if(vg_effector) + effector*= psys_particle_value_from_verts(psmd->dm,psys->part->from,pa,vg_effector); - effector= 1.0f; - if(vg_effector) - effector*= psys_particle_value_from_verts(psmd->dm,psys->part->from,pa,vg_effector); + sub_v3_v3v3(vec,(cache[p]+1)->co,cache[p]->co); + length = len_v3(vec); - for(k=0, ca=cache[p]; k<=steps; k++, ca++) { - if(!(psys->flag & PSYS_GLOBAL_HAIR)) { - /* apply effectors */ - if(!(psys->part->flag & PART_CHILD_EFFECT) && k) + for(k=1, ca=cache[p]+1; k<=steps; k++, ca++) do_path_effectors(sim, p, ca, k, steps, cache[p]->co, effector, dfra, cfra, &length, vec); + } - /* apply guide curves to path data */ - if(sim->psys->effectors && (psys->part->flag & PART_CHILD_EFFECT)==0) + /* apply guide curves to path data */ + if(sim->psys->effectors && (psys->part->flag & PART_CHILD_EFFECT)==0) { + for(k=0, ca=cache[p]; k<=steps; k++, ca++) /* ca is safe to cast, since only co and vel are used */ do_guides(sim->psys->effectors, (ParticleKey*)ca, p, (float)k/(float)steps); + } - /* apply lattice */ - if(psys->lattice) + /* lattices have to be calculated separately to avoid mixups between effector calculations */ + if(psys->lattice) { + for(k=0, ca=cache[p]; k<=steps; k++, ca++) calc_latt_deform(psys->lattice, ca->co, 1.0f); + } + } - /* figure out rotation */ - - if(k) { - float cosangle, angle, tangent[3], normal[3], q[4]; - - if(k == 1) { - /* calculate initial tangent for incremental rotations */ - VECSUB(tangent, ca->co, (ca - 1)->co); - VECCOPY(prev_tangent, tangent); - normalize_v3(prev_tangent); - - /* First rotation is based on emitting face orientation. */ - /* This is way better than having flipping rotations resulting */ - /* from using a global axis as a rotation pole (vec_to_quat()). */ - /* It's not an ideal solution though since it disregards the */ - /* initial tangent, but taking that in to account will allow */ - /* the possibility of flipping again. -jahka */ - mat3_to_quat_is_ok( (ca-1)->rot,rotmat); - } - else { - VECSUB(tangent, ca->co, (ca - 1)->co); - normalize_v3(tangent); - - cosangle= dot_v3v3(tangent, prev_tangent); - - /* note we do the comparison on cosangle instead of - * angle, since floating point accuracy makes it give - * different results across platforms */ - if(cosangle > 0.999999f) { - QUATCOPY((ca - 1)->rot, (ca - 2)->rot); - } - else { - angle= saacos(cosangle); - cross_v3_v3v3(normal, prev_tangent, tangent); - axis_angle_to_quat( q,normal, angle); - mul_qt_qtqt((ca - 1)->rot, q, (ca - 2)->rot); - } + /* finally do rotation & velocity */ + for(k=1, ca=cache[p]+1; k<=steps; k++, ca++) { + /* figure out rotation */ + float cosangle, angle, tangent[3], normal[3], q[4]; + + if(k == 1) { + /* calculate initial tangent for incremental rotations */ + VECSUB(tangent, ca->co, (ca - 1)->co); + normalize_v3_v3(prev_tangent, tangent); + + /* First rotation is based on emitting face orientation. */ + /* This is way better than having flipping rotations resulting */ + /* from using a global axis as a rotation pole (vec_to_quat()). */ + /* It's not an ideal solution though since it disregards the */ + /* initial tangent, but taking that in to account will allow */ + /* the possibility of flipping again. -jahka */ + mat3_to_quat_is_ok( (ca-1)->rot,rotmat); + } + else { + VECSUB(tangent, ca->co, (ca - 1)->co); + normalize_v3(tangent); - VECCOPY(prev_tangent, tangent); - } + cosangle= dot_v3v3(tangent, prev_tangent); - if(k == steps) - QUATCOPY(ca->rot, (ca - 1)->rot); + /* note we do the comparison on cosangle instead of + * angle, since floating point accuracy makes it give + * different results across platforms */ + if(cosangle > 0.999999f) { + QUATCOPY((ca - 1)->rot, (ca - 2)->rot); + } + else { + angle= saacos(cosangle); + cross_v3_v3v3(normal, prev_tangent, tangent); + axis_angle_to_quat( q,normal, angle); + mul_qt_qtqt((ca - 1)->rot, q, (ca - 2)->rot); } + VECCOPY(prev_tangent, tangent); } - - /* set velocity */ - if(k){ - VECSUB(ca->vel, ca->co, (ca-1)->co); + if(k == steps) + QUATCOPY(ca->rot, (ca - 1)->rot); + - if(k==1) { - VECCOPY((ca-1)->vel, ca->vel); - } + /* set velocity */ + VECSUB(ca->vel, ca->co, (ca-1)->co); - } + if(k==1) + VECCOPY((ca-1)->vel, ca->vel); } } @@ -3104,8 +3104,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf if(k == 1) { /* calculate initial tangent for incremental rotations */ VECSUB(tangent, ca->co, (ca - 1)->co); - VECCOPY(prev_tangent, tangent); - normalize_v3(prev_tangent); + normalize_v3_v3(prev_tangent, tangent); /* First rotation is based on emitting face orientation. */ /* This is way better than having flipping rotations resulting */ @@ -3397,7 +3396,7 @@ ModifierData *object_add_particle_system(Scene *scene, Object *ob, char *name) psys->flag = PSYS_ENABLED|PSYS_CURRENT; psys->cfra=bsystem_time(scene,ob,scene->r.cfra+1,0.0); - DAG_scene_sort(scene); + DAG_scene_sort(G.main, scene); DAG_id_flush_update(&ob->id, OB_RECALC_DATA); return md; @@ -3434,7 +3433,7 @@ void object_remove_particle_system(Scene *scene, Object *ob) else ob->mode &= ~OB_MODE_PARTICLE_EDIT; - DAG_scene_sort(scene); + DAG_scene_sort(G.main, scene); DAG_id_flush_update(&ob->id, OB_RECALC_DATA); } static void default_particle_settings(ParticleSettings *part) @@ -4369,20 +4368,14 @@ void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3] onevec[bb->align]=1.0f; if(bb->lock && (bb->align == PART_BB_VIEW)) { - VECCOPY(xvec, bb->ob->obmat[0]); - normalize_v3(xvec); - - VECCOPY(yvec, bb->ob->obmat[1]); - normalize_v3(yvec); - - VECCOPY(zvec, bb->ob->obmat[2]); - normalize_v3(zvec); + normalize_v3_v3(xvec, bb->ob->obmat[0]); + normalize_v3_v3(yvec, bb->ob->obmat[1]); + normalize_v3_v3(zvec, bb->ob->obmat[2]); } else if(bb->align == PART_BB_VEL) { float temp[3]; - VECCOPY(temp, bb->vel); - normalize_v3(temp); + normalize_v3_v3(temp, bb->vel); VECSUB(zvec, bb->ob->obmat[3], bb->vec); diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index a128cfaedf9..2b43ce1ea36 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -62,7 +62,6 @@ #include "BLI_listbase.h" #include "BLI_threads.h" -#include "BKE_anim.h" #include "BKE_animsys.h" #include "BKE_boids.h" #include "BKE_cdderivedmesh.h" @@ -182,7 +181,7 @@ static void realloc_particles(ParticleSimulationData *sim, int new_totpart) else totpart=new_totpart; - if(totpart && totpart != psys->totpart) { + if(totpart != psys->totpart) { if(psys->edit && psys->free_edit) { psys->free_edit(psys->edit); psys->edit = NULL; @@ -727,7 +726,7 @@ static void psys_thread_distribute_particle(ParticleThread *thread, ParticleData pa->foffset=0.0; else switch(distr){ case PART_DISTR_JIT: - pa->foffset*= ctx->jit[2*(int)ctx->jitoff[i]]; + pa->foffset*= ctx->jit[p%(2*ctx->jitlevel)]; break; case PART_DISTR_RAND: pa->foffset*=BLI_frand(); @@ -1730,8 +1729,7 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime, mul_qt_v3(rot, vtan); mul_qt_v3(rot, utan); - VECCOPY(p_vel, state.vel); - speed=normalize_v3(p_vel); + speed= normalize_v3_v3(p_vel, state.vel); mul_v3_fl(p_vel, dot_v3v3(r_vel, p_vel)); VECSUB(p_vel, r_vel, p_vel); normalize_v3(p_vel); @@ -1872,18 +1870,15 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime, /* *emitter object orientation */ if(part->ob_vel[0]!=0.0) { - VECCOPY(vec, ob->obmat[0]); - normalize_v3(vec); + normalize_v3_v3(vec, ob->obmat[0]); VECADDFAC(vel, vel, vec, part->ob_vel[0]); } if(part->ob_vel[1]!=0.0) { - VECCOPY(vec, ob->obmat[1]); - normalize_v3(vec); + normalize_v3_v3(vec, ob->obmat[1]); VECADDFAC(vel, vel, vec, part->ob_vel[1]); } if(part->ob_vel[2]!=0.0) { - VECCOPY(vec, ob->obmat[2]); - normalize_v3(vec); + normalize_v3_v3(vec, ob->obmat[2]); VECADDFAC(vel, vel, vec, part->ob_vel[2]); } @@ -3075,18 +3070,66 @@ static void deflect_particle(ParticleSimulationData *sim, int p, float dfra, flo /* Hair */ /************************************************/ /* check if path cache or children need updating and do it if needed */ -void psys_update_path_cache(ParticleSimulationData *sim, float cfra) +static void psys_update_path_cache(ParticleSimulationData *sim, float cfra) { ParticleSystem *psys = sim->psys; ParticleSettings *part = psys->part; - - /* only hair, keyed and baked stuff can have paths */ - if(part->type==PART_HAIR || psys->flag&PSYS_KEYED || psys->pointcache->mem_cache.first) { + ParticleEditSettings *pset = &sim->scene->toolsettings->particle; + int distr=0, alloc=0, skip=0; + + if((psys->part->childtype && psys->totchild != get_psys_tot_child(sim->scene, psys)) || psys->recalc&PSYS_RECALC_RESET) + alloc=1; + + if(alloc || psys->recalc&PSYS_RECALC_CHILD || (psys->vgroup[PSYS_VG_DENSITY] && (sim->ob && sim->ob->mode & OB_MODE_WEIGHT_PAINT))) + distr=1; + + if(distr){ + if(alloc) + realloc_particles(sim, sim->psys->totpart); + + if(get_psys_tot_child(sim->scene, psys)) { + /* don't generate children while computing the hair keys */ + if(!(psys->part->type == PART_HAIR) || (psys->flag & PSYS_HAIR_DONE)) { + distribute_particles(sim, PART_FROM_CHILD); + + if(part->from!=PART_FROM_PARTICLE && part->childtype==PART_CHILD_FACES && part->parents!=0.0) + psys_find_parents(sim); + } + } + else + psys_free_children(psys); + } + + if((part->type==PART_HAIR || psys->flag&PSYS_KEYED || psys->pointcache->flag & PTCACHE_BAKED)==0) + skip = 1; /* only hair, keyed and baked stuff can have paths */ + else if(part->ren_as != PART_DRAW_PATH && !(part->type==PART_HAIR && ELEM(part->ren_as, PART_DRAW_OB, PART_DRAW_GR))) + skip = 1; /* particle visualization must be set as path */ + else if(!psys->renderdata) { + if(part->draw_as != PART_DRAW_REND) + skip = 1; /* draw visualization */ + else if(psys->pointcache->flag & PTCACHE_BAKING) + skip = 1; /* no need to cache paths while baking dynamics */ + else if(psys_in_edit_mode(sim->scene, psys)) { + if((pset->flag & PE_DRAW_PART)==0) + skip = 1; + else if(part->childtype==0 && (psys->flag & PSYS_HAIR_DYNAMICS && psys->pointcache->flag & PTCACHE_BAKED)==0) + skip = 1; /* in edit mode paths are needed for child particles and dynamic hair */ + } + } + + if(!skip) { psys_cache_paths(sim, cfra); /* for render, child particle paths are computed on the fly */ - if(part->childtype && psys->totchild) - psys_cache_child_paths(sim, cfra, 0); + if(part->childtype) { + if(!psys->totchild) + skip = 1; + else if(psys->part->type == PART_HAIR && (psys->flag & PSYS_HAIR_DONE)==0) + skip = 1; + + if(!skip) + psys_cache_child_paths(sim, cfra, 0); + } } else if(psys->pathcache) psys_free_path_cache(psys, NULL); @@ -3201,8 +3244,6 @@ static void do_hair_dynamics(ParticleSimulationData *sim) psys->hair_out_dm = clothModifier_do(psys->clmd, sim->scene, sim->ob, dm, 0, 0); psys->clmd->sim_parms->effector_weights = NULL; - - psys_free_path_cache(psys, NULL); } static void hair_step(ParticleSimulationData *sim, float cfra) { @@ -3454,19 +3495,14 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) } free_collider_cache(&sim->colliders); - - if(psys->pathcache) - psys_free_path_cache(psys, NULL); } -void psys_update_children(ParticleSimulationData *sim) +static void update_children(ParticleSimulationData *sim) { if((sim->psys->part->type == PART_HAIR) && (sim->psys->flag & PSYS_HAIR_DONE)==0) /* don't generate children while growing hair - waste of time */ psys_free_children(sim->psys); - else if(sim->psys->part->childtype) { - if(sim->psys->totchild != get_psys_tot_child(sim->scene, sim->psys)) - distribute_particles(sim, PART_FROM_CHILD); - } + else if(sim->psys->part->childtype && sim->psys->totchild != get_psys_tot_child(sim->scene, sim->psys)) + distribute_particles(sim, PART_FROM_CHILD); else psys_free_children(sim->psys); } @@ -3721,6 +3757,8 @@ static void system_step(ParticleSimulationData *sim, float cfra) if(ELEM(cache_result, PTCACHE_READ_EXACT, PTCACHE_READ_INTERPOLATED)) { cached_step(sim, cfra); + update_children(sim); + psys_update_path_cache(sim, cfra); BKE_ptcache_validate(cache, framenr); @@ -3784,6 +3822,9 @@ static void system_step(ParticleSimulationData *sim, float cfra) BKE_ptcache_write_cache(use_cache, framenr); } + if(init) + update_children(sim); + /* cleanup */ if(psys->lattice){ end_latt_deform(psys->lattice); @@ -3946,13 +3987,6 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys) /* execute drivers only, as animation has already been done */ BKE_animsys_evaluate_animdata(&part->id, part->adt, cfra, ADT_RECALC_DRIVERS); - /* TODO: only free child paths in case of PSYS_RECALC_CHILD */ - if(psys->recalc & PSYS_RECALC || ob->recalc & OB_RECALC_ALL) - psys_free_path_cache(psys, NULL); - - if(psys->recalc & PSYS_RECALC_CHILD) - psys_free_children(psys); - if(psys->recalc & PSYS_RECALC_TYPE) psys_changed_type(&sim); else if(psys->recalc & PSYS_RECALC_PHYS) @@ -3999,16 +4033,26 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys) case PART_PHYS_NO: case PART_PHYS_KEYED: { + PARTICLE_P; + if(emit_particles(&sim, NULL, cfra)) { free_keyed_keys(psys); distribute_particles(&sim, part->from); initialize_all_particles(&sim); } - reset_all_particles(&sim, 0.0, cfra, 0); + + LOOP_EXISTING_PARTICLES { + pa->size = part->size; + if(part->randsize > 0.0) + pa->size *= 1.0f - part->randsize * PSYS_FRAND(p + 1); + + reset_particle(&sim, pa, 0.0, cfra); + } if(part->phystype == PART_PHYS_KEYED) { psys_count_keyed_targets(&sim); set_keyed_keys(&sim); + psys_update_path_cache(&sim,(int)cfra); } break; } diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 5295a496d2b..a35e40d7cf7 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -43,6 +43,7 @@ #include "BLI_blenlib.h" #include "BLI_threads.h" +#include "BLI_math.h" #include "PIL_time.h" @@ -1041,11 +1042,13 @@ void BKE_ptcache_ids_from_object(ListBase *lb, Object *ob, Scene *scene, int dup if((lb_dupli_ob=object_duplilist(scene, ob))) { DupliObject *dob; for(dob= lb_dupli_ob->first; dob; dob= dob->next) { - ListBase lb_dupli_pid; - BKE_ptcache_ids_from_object(&lb_dupli_pid, dob->ob, scene, duplis); - addlisttolist(lb, &lb_dupli_pid); - if(lb_dupli_pid.first) - printf("Adding Dupli\n"); + if(dob->ob != ob) { /* avoids recursive loops with dupliframes: bug 22988 */ + ListBase lb_dupli_pid; + BKE_ptcache_ids_from_object(&lb_dupli_pid, dob->ob, scene, duplis); + addlisttolist(lb, &lb_dupli_pid); + if(lb_dupli_pid.first) + printf("Adding Dupli\n"); + } } free_object_duplilist(lb_dupli_ob); /* does restore */ @@ -2237,7 +2240,7 @@ void BKE_ptcache_remove(void) static int CONTINUE_PHYSICS = 0; -void BKE_ptcache_set_continue_physics(Scene *scene, int enable) +void BKE_ptcache_set_continue_physics(Main *bmain, Scene *scene, int enable) { Object *ob; @@ -2245,7 +2248,7 @@ void BKE_ptcache_set_continue_physics(Scene *scene, int enable) CONTINUE_PHYSICS = enable; if(CONTINUE_PHYSICS == 0) { - for(ob=G.main->object.first; ob; ob=ob->id.next) + for(ob=bmain->object.first; ob; ob=ob->id.next) if(BKE_ptcache_object_reset(scene, ob, PTCACHE_RESET_OUTDATED)) DAG_id_flush_update(&ob->id, OB_RECALC_DATA); } @@ -2333,7 +2336,7 @@ PointCache *BKE_ptcache_copy_list(ListBase *ptcaches_new, ListBase *ptcaches_old /* Baking */ -void BKE_ptcache_quick_cache_all(Scene *scene) +void BKE_ptcache_quick_cache_all(Main *bmain, Scene *scene) { PTCacheBaker baker; @@ -2346,6 +2349,7 @@ void BKE_ptcache_quick_cache_all(Scene *scene) baker.progresscontext=NULL; baker.render=0; baker.anim_init = 0; + baker.main=bmain; baker.scene=scene; baker.quick_step=scene->physics_settings.quick_cache_step; @@ -2360,6 +2364,7 @@ typedef struct { int endframe; int step; int *cfra_ptr; + Main *main; Scene *scene; } ptcache_make_cache_data; @@ -2367,7 +2372,7 @@ static void *ptcache_make_cache_thread(void *ptr) { ptcache_make_cache_data *data = (ptcache_make_cache_data*)ptr; for(; (*data->cfra_ptr <= data->endframe) && !data->break_operation; *data->cfra_ptr+=data->step) { - scene_update_for_newframe(data->scene, data->scene->lay); + scene_update_for_newframe(data->main, data->scene, data->scene->lay); if(G.background) { printf("bake: frame %d :: %d\n", (int)*data->cfra_ptr, data->endframe); } @@ -2380,6 +2385,7 @@ static void *ptcache_make_cache_thread(void *ptr) { /* if bake is not given run simulations to current frame */ void BKE_ptcache_make_cache(PTCacheBaker* baker) { + Main *bmain = baker->main; Scene *scene = baker->scene; Scene *sce; /* SETLOOPER macro only */ Base *base; @@ -2399,6 +2405,7 @@ void BKE_ptcache_make_cache(PTCacheBaker* baker) thread_data.step = baker->quick_step; thread_data.cfra_ptr = &CFRA; thread_data.scene = baker->scene; + thread_data.main = baker->main; G.afbreek = 0; @@ -2568,7 +2575,7 @@ void BKE_ptcache_make_cache(PTCacheBaker* baker) CFRA = cfrao; if(bake) /* already on cfra unless baking */ - scene_update_for_newframe(scene, scene->lay); + scene_update_for_newframe(bmain, scene, scene->lay); if (thread_data.break_operation) WM_cursor_wait(0); diff --git a/source/blender/blenkernel/intern/property.c b/source/blender/blenkernel/intern/property.c index a2ba7c69b93..d8001572b4f 100644 --- a/source/blender/blenkernel/intern/property.c +++ b/source/blender/blenkernel/intern/property.c @@ -32,6 +32,7 @@ #include <stdio.h> #include <stdlib.h> +#include <stddef.h> #include <string.h> #include <ctype.h> @@ -180,14 +181,7 @@ void unique_property(bProperty *first, bProperty *prop, int force) bProperty *get_ob_property(Object *ob, char *name) { - bProperty *prop; - - prop= ob->prop.first; - while(prop) { - if( strcmp(prop->name, name)==0 ) return prop; - prop= prop->next; - } - return NULL; + return BLI_findstring(&ob->prop, name, offsetof(bProperty, name)); } void set_ob_property(Object *ob, bProperty *propc) diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c index 61e98ce9d45..f5ca7ee3cef 100644 --- a/source/blender/blenkernel/intern/sca.c +++ b/source/blender/blenkernel/intern/sca.c @@ -800,7 +800,7 @@ void link_logicbricks(void **poin, void ***ppoin, short *tot, short size) (*tot) ++; *ppoin = MEM_callocN((*tot)*size, "new link"); - for (ibrick=0; ibrick < *tot - 1; ibrick++) { + for (ibrick=0; ibrick < *(tot) - 1; ibrick++) { (*ppoin)[ibrick] = old_links[ibrick]; } (*ppoin)[ibrick] = *poin; diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index fe52375617b..8793c412d7d 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -38,14 +38,16 @@ #else #include <io.h> #endif -#include "MEM_guardedalloc.h" #include "DNA_anim_types.h" #include "DNA_group_types.h" +#include "DNA_object_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" #include "DNA_sequence_types.h" +#include "MEM_guardedalloc.h" + #include "BKE_anim.h" #include "BKE_animsys.h" #include "BKE_depsgraph.h" @@ -67,10 +69,6 @@ //XXX #include "BIF_previewrender.h" //XXX #include "BIF_editseq.h" -#ifndef DISABLE_PYTHON -#include "BPY_extern.h" -#endif - #include "BLI_math.h" #include "BLI_blenlib.h" @@ -171,9 +169,12 @@ Scene *copy_scene(Main *bmain, Scene *sce, int type) 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); - + + if(sce->nodetree) { + scen->nodetree= ntreeCopyTree(sce->nodetree, 0); + ntreeSwitchID(scen->nodetree, &sce->id, &scen->id); + } + obase= sce->base.first; base= scen->base.first; while(base) { @@ -316,11 +317,12 @@ void free_scene(Scene *sce) Scene *add_scene(char *name) { + Main *bmain= G.main; Scene *sce; ParticleEditSettings *pset; int a; - sce= alloc_libblock(&G.main->scene, ID_SCE, name); + sce= alloc_libblock(&bmain->scene, ID_SCE, name); sce->lay= sce->layact= 1; sce->r.mode= R_GAMMA|R_OSA|R_SHADOW|R_SSS|R_ENVMAP|R_RAYTRACE; @@ -395,6 +397,7 @@ Scene *add_scene(char *name) sce->toolsettings->jointrilimit = 0.8f; sce->toolsettings->selectmode= SCE_SELECT_VERTEX; + sce->toolsettings->uv_selectmode= UV_SELECT_VERTEX; sce->toolsettings->normalsize= 0.1; sce->toolsettings->autokey_mode= U.autokey_mode; @@ -500,7 +503,7 @@ Base *object_in_scene(Object *ob, Scene *sce) return NULL; } -void set_scene_bg(Scene *scene) +void set_scene_bg(Main *bmain, Scene *scene) { Scene *sce; Base *base; @@ -510,14 +513,18 @@ void set_scene_bg(Scene *scene) int flag; /* check for cyclic sets, for reading old files but also for definite security (py?) */ - scene_check_setscene(scene); + scene_check_setscene(bmain, scene); + /* can happen when switching modes in other scenes */ + if(scene->obedit && !(scene->obedit->mode & OB_MODE_EDIT)) + scene->obedit= NULL; + /* deselect objects (for dataselect) */ - for(ob= G.main->object.first; ob; ob= ob->id.next) + for(ob= bmain->object.first; ob; ob= ob->id.next) ob->flag &= ~(SELECT|OB_FROMGROUP); /* group flags again */ - for(group= G.main->group.first; group; group= group->id.next) { + for(group= bmain->group.first; group; group= group->id.next) { go= group->gobject.first; while(go) { if(go->ob) go->ob->flag |= OB_FROMGROUP; @@ -526,12 +533,12 @@ void set_scene_bg(Scene *scene) } /* sort baselist */ - DAG_scene_sort(scene); + DAG_scene_sort(bmain, scene); /* ensure dags are built for sets */ for(sce= scene->set; sce; sce= sce->set) if(sce->theDag==NULL) - DAG_scene_sort(sce); + DAG_scene_sort(bmain, sce); /* copy layers and flags from bases to objects */ for(base= scene->base.first; base; base= base->next) { @@ -553,11 +560,11 @@ void set_scene_bg(Scene *scene) } /* called from creator.c */ -Scene *set_scene_name(char *name) +Scene *set_scene_name(Main *bmain, char *name) { Scene *sce= (Scene *)find_id("SC", name); if(sce) { - set_scene_bg(sce); + set_scene_bg(bmain, sce); printf("Scene switch: '%s' in file: '%s'\n", name, G.sce); return sce; } @@ -577,7 +584,7 @@ void unlink_scene(Main *bmain, Scene *sce, Scene *newsce) sce1->set= NULL; /* check all sequences */ - clear_scene_in_allseqs(sce); + clear_scene_in_allseqs(bmain, sce); /* check render layer nodes in other scenes */ clear_scene_in_nodes(bmain, sce); @@ -866,7 +873,7 @@ void scene_select_base(Scene *sce, Base *selbase) } /* checks for cycle, returns 1 if it's all OK */ -int scene_check_setscene(Scene *sce) +int scene_check_setscene(Main *bmain, Scene *sce) { Scene *scene; int a, totscene; @@ -874,7 +881,7 @@ int scene_check_setscene(Scene *sce) if(sce->set==NULL) return 1; totscene= 0; - for(scene= G.main->scene.first; scene; scene= scene->id.next) + for(scene= bmain->scene.first; scene; scene= scene->id.next) totscene++; for(a=0, scene=sce; scene->set; scene=scene->set, a++) { @@ -902,14 +909,14 @@ float BKE_curframe(Scene *scene) return ctime; } -static void scene_update_tagged_recursive(Scene *scene, Scene *scene_parent) +static void scene_update_tagged_recursive(Main *bmain, Scene *scene, Scene *scene_parent) { Base *base; /* sets first, we allow per definition current scene to have dependencies on sets, but not the other way around. */ if(scene->set) - scene_update_tagged_recursive(scene->set, scene_parent); + scene_update_tagged_recursive(bmain, scene->set, scene_parent); for(base= scene->base.first; base; base= base->next) { Object *ob= base->object; @@ -925,14 +932,14 @@ static void scene_update_tagged_recursive(Scene *scene, Scene *scene_parent) } /* this is called in main loop, doing tagged updates before redraw */ -void scene_update_tagged(Scene *scene) +void scene_update_tagged(Main *bmain, Scene *scene) { scene->physics_settings.quick_cache_step= 0; /* update all objects: drivers, matrices, displists, etc. flags set by depgraph or manual, no layer check here, gets correct flushed */ - scene_update_tagged_recursive(scene, scene); + scene_update_tagged_recursive(bmain, scene, scene); /* recalc scene animation data here (for sequencer) */ { @@ -944,14 +951,14 @@ void scene_update_tagged(Scene *scene) } if(scene->physics_settings.quick_cache_step) - BKE_ptcache_quick_cache_all(scene); + BKE_ptcache_quick_cache_all(bmain, scene); /* in the future this should handle updates for all datablocks, not only objects and scenes. - brecht */ } /* applies changes right away, does all sets too */ -void scene_update_for_newframe(Scene *sce, unsigned int lay) +void scene_update_for_newframe(Main *bmain, Scene *sce, unsigned int lay) { float ctime = BKE_curframe(sce); Scene *sce_iter; @@ -961,13 +968,13 @@ void scene_update_for_newframe(Scene *sce, unsigned int lay) for(sce_iter= sce; sce_iter; sce_iter= sce_iter->set) { if(sce_iter->theDag==NULL) - DAG_scene_sort(sce_iter); + DAG_scene_sort(bmain, sce_iter); } /* Following 2 functions are recursive * so dont call within 'scene_update_tagged_recursive' */ - DAG_scene_update_flags(sce, lay); // only stuff that moves or needs display still + DAG_scene_update_flags(bmain, sce, lay); // only stuff that moves or needs display still /* All 'standard' (i.e. without any dependencies) animation is handled here, * with an 'local' to 'macro' order of evaluation. This should ensure that @@ -975,11 +982,11 @@ void scene_update_for_newframe(Scene *sce, unsigned int lay) * can be overridden by settings from Scene, which owns the Texture through a hierarchy * such as Scene->World->MTex/Texture) can still get correctly overridden. */ - BKE_animsys_evaluate_all_animation(G.main, ctime); + BKE_animsys_evaluate_all_animation(bmain, ctime); /*...done with recusrive funcs */ /* object_handle_update() on all objects, groups and sets */ - scene_update_tagged_recursive(sce, sce); + scene_update_tagged_recursive(bmain, sce, sce); } /* return default layer, also used to patch old files */ diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index a8140cb815d..6f1d32898f9 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -42,10 +42,6 @@ #include "BKE_screen.h" -#ifndef DISABLE_PYTHON -#include "BPY_extern.h" -#endif - /* ************ Spacetype/regiontype handling ************** */ /* keep global; this has to be accessible outside of windowmanager */ diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index 73c19772c69..461cb075bb0 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -41,6 +41,7 @@ #include "DNA_anim_types.h" #include "BKE_fcurve.h" +#include "BKE_main.h" #include "BKE_plugin_types.h" #include "BKE_sequencer.h" #include "BKE_texture.h" @@ -67,6 +68,48 @@ enum { GlowA=3 }; +static struct ImBuf * prepare_effect_imbufs( + int x, int y, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) +{ + struct ImBuf * out; + + if (!ibuf1 && !ibuf2 && !ibuf3) { + /* hmmm, global float option ? */ + out = IMB_allocImBuf((short)x, (short)y, 32, IB_rect, 0); + } else if ((ibuf1 && ibuf1->rect_float) || + (ibuf2 && ibuf2->rect_float) || + (ibuf3 && ibuf3->rect_float)) { + /* if any inputs are rectfloat, output is float too */ + + out = IMB_allocImBuf((short)x, (short)y, 32, IB_rectfloat, 0); + } else { + out = IMB_allocImBuf((short)x, (short)y, 32, IB_rect, 0); + } + + if (ibuf1 && !ibuf1->rect_float && out->rect_float) { + IMB_float_from_rect_simple(ibuf1); + } + if (ibuf2 && !ibuf2->rect_float && out->rect_float) { + IMB_float_from_rect_simple(ibuf2); + } + if (ibuf3 && !ibuf3->rect_float && out->rect_float) { + IMB_float_from_rect_simple(ibuf3); + } + + if (ibuf1 && !ibuf1->rect && !out->rect_float) { + IMB_rect_from_float(ibuf1); + } + if (ibuf2 && !ibuf2->rect && !out->rect_float) { + IMB_rect_from_float(ibuf2); + } + if (ibuf3 && !ibuf3->rect && !out->rect_float) { + IMB_rect_from_float(ibuf3); + } + + return out; +} /* ********************************************************************** PLUGINS @@ -229,11 +272,12 @@ static ImBuf * IMB_cast_away_list(ImBuf * i) return (ImBuf*) (((void**) i) + 2); } -static void do_plugin_effect(Scene *scene, Sequence *seq, int cfra, - float facf0, float facf1, int x, int y, - int preview_render_size, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3, struct ImBuf *out) +static struct ImBuf * do_plugin_effect( + Main *bmain, Scene *scene, Sequence *seq, float cfra, + float facf0, float facf1, int x, int y, + int preview_render_size, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { char *cp; int float_rendering; @@ -241,6 +285,8 @@ static void do_plugin_effect(Scene *scene, Sequence *seq, int cfra, old plugins) do very bad stuff with imbuf-internals */ + struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3); + if(seq->plugin && seq->plugin->doit) { if(seq->plugin->cfra) @@ -321,6 +367,7 @@ static void do_plugin_effect(Scene *scene, Sequence *seq, int cfra, if (ibuf3) IMB_freeImBuf(ibuf3); } } + return out; } static int do_plugin_early_out(struct Sequence *seq, @@ -476,12 +523,15 @@ static void do_alphaover_effect_float(float facf0, float facf1, int x, int y, } } -static void do_alphaover_effect(Scene *scene, Sequence *seq, int cfra, - float facf0, float facf1, int x, int y, - int preview_render_size, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3, struct ImBuf *out) +static struct ImBuf * do_alphaover_effect( + Main *bmain, Scene *scene, Sequence *seq, float cfra, + float facf0, float facf1, int x, int y, + int preview_render_size, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { + struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3); + if (out->rect_float) { do_alphaover_effect_float( facf0, facf1, x, y, @@ -493,6 +543,7 @@ static void do_alphaover_effect(Scene *scene, Sequence *seq, int cfra, (char*) ibuf1->rect, (char*) ibuf2->rect, (char*) out->rect); } + return out; } @@ -644,12 +695,15 @@ static void do_alphaunder_effect_float(float facf0, float facf1, int x, int y, } } -static void do_alphaunder_effect(Scene *scene, Sequence *seq, int cfra, - float facf0, float facf1, int x, int y, - int preview_render_size, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3, struct ImBuf *out) +static struct ImBuf* do_alphaunder_effect( + Main *bmain, Scene *scene, Sequence *seq, float cfra, + float facf0, float facf1, int x, int y, + int preview_render_size, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { + struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3); + if (out->rect_float) { do_alphaunder_effect_float( facf0, facf1, x, y, @@ -661,6 +715,7 @@ static void do_alphaunder_effect(Scene *scene, Sequence *seq, int cfra, (char*) ibuf1->rect, (char*) ibuf2->rect, (char*) out->rect); } + return out; } @@ -765,12 +820,15 @@ void do_cross_effect_float(float facf0, float facf1, int x, int y, /* carefull: also used by speed effect! */ -static void do_cross_effect(Scene *scene, Sequence *seq, int cfra, - float facf0, float facf1, int x, int y, - int preview_render_size, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3, struct ImBuf *out) +static struct ImBuf* do_cross_effect( + Main *bmain, Scene *scene, Sequence *seq, float cfra, + float facf0, float facf1, int x, int y, + int preview_render_size, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { + struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3); + if (out->rect_float) { do_cross_effect_float( facf0, facf1, x, y, @@ -782,6 +840,7 @@ static void do_cross_effect(Scene *scene, Sequence *seq, int cfra, (char*) ibuf1->rect, (char*) ibuf2->rect, (char*) out->rect); } + return out; } @@ -827,7 +886,7 @@ static void makeGammaTables(float gamma) /* The end of the table should match 1.0 carefully. In order to avoid */ /* rounding errors, we just set this explicitly. The last segment may */ - /* have a different lenght than the other segments, but our */ + /* have a different length than the other segments, but our */ /* interpolation is insensitive to that. */ color_domain_table[RE_GAMMA_TABLE_SIZE] = 1.0; gamma_range_table[RE_GAMMA_TABLE_SIZE] = 1.0; @@ -1028,12 +1087,15 @@ static void do_gammacross_effect_float(float facf0, float facf1, } } -static void do_gammacross_effect(Scene *scene, Sequence *seq, int cfra, - float facf0, float facf1, int x, int y, - int preview_render_size, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3, struct ImBuf *out) +static struct ImBuf * do_gammacross_effect( + Main *bmain, Scene *scene, Sequence *seq, float cfra, + float facf0, float facf1, int x, int y, + int preview_render_size, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { + struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3); + build_gammatabs(); if (out->rect_float) { @@ -1047,6 +1109,7 @@ static void do_gammacross_effect(Scene *scene, Sequence *seq, int cfra, (unsigned char*) ibuf1->rect, (unsigned char*) ibuf2->rect, (unsigned char*) out->rect); } + return out; } @@ -1143,12 +1206,14 @@ static void do_add_effect_float(float facf0, float facf1, int x, int y, } } -static void do_add_effect(Scene *scene, Sequence *seq, int cfra, - float facf0, float facf1, int x, int y, - int preview_render_size, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3, struct ImBuf *out) +static struct ImBuf * do_add_effect(Main *bmain, Scene *scene, Sequence *seq, float cfra, + float facf0, float facf1, int x, int y, + int preview_render_size, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { + struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3); + if (out->rect_float) { do_add_effect_float( facf0, facf1, x, y, @@ -1160,6 +1225,7 @@ static void do_add_effect(Scene *scene, Sequence *seq, int cfra, (unsigned char*) ibuf1->rect, (unsigned char*) ibuf2->rect, (unsigned char*) out->rect); } + return out; } @@ -1256,12 +1322,15 @@ static void do_sub_effect_float(float facf0, float facf1, int x, int y, } } -static void do_sub_effect(Scene *scene, Sequence *seq, int cfra, - float facf0, float facf1, int x, int y, - int preview_render_size, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3, struct ImBuf *out) +static struct ImBuf * do_sub_effect( + Main *bmain, Scene *scene, Sequence *seq, float cfra, + float facf0, float facf1, int x, int y, + int preview_render_size, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { + struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3); + if (out->rect_float) { do_sub_effect_float( facf0, facf1, x, y, @@ -1273,6 +1342,7 @@ static void do_sub_effect(Scene *scene, Sequence *seq, int cfra, (char*) ibuf1->rect, (char*) ibuf2->rect, (char*) out->rect); } + return out; } /* ********************************************************************** @@ -1284,8 +1354,8 @@ static void do_sub_effect(Scene *scene, Sequence *seq, int cfra, #define YOFF 8 static void do_drop_effect_byte(float facf0, float facf1, int x, int y, - unsigned char *rect2i, unsigned char *rect1i, - unsigned char *outi) + char *rect2i, char *rect1i, + char *outi) { int height, width, temp, fac, fac1, fac2; char *rt1, *rt2, *out; @@ -1364,27 +1434,6 @@ static void do_drop_effect_float(float facf0, float facf1, int x, int y, memcpy(out, rt1, 4 * sizeof(float)*YOFF*width); } - -static void do_drop_effect(Scene *scene, Sequence *seq, int cfra, - float facf0, float facf1, int x, int y, - int preview_render_size, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf * ibuf3, - struct ImBuf *out) -{ - if (out->rect_float) { - do_drop_effect_float( - facf0, facf1, x, y, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); - } else { - do_drop_effect_byte( - facf0, facf1, x, y, - (unsigned char*) ibuf1->rect, (unsigned char*) ibuf2->rect, - (unsigned char*) out->rect); - } -} - /* ********************************************************************** MUL ********************************************************************** */ @@ -1487,12 +1536,15 @@ static void do_mul_effect_float(float facf0, float facf1, int x, int y, } } -static void do_mul_effect(Scene *scene, Sequence *seq, int cfra, - float facf0, float facf1, int x, int y, - int preview_render_size, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3, struct ImBuf *out) +static struct ImBuf * do_mul_effect( + Main *bmain, Scene *scene, Sequence *seq, float cfra, + float facf0, float facf1, int x, int y, + int preview_render_size, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { + struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3); + if (out->rect_float) { do_mul_effect_float( facf0, facf1, x, y, @@ -1504,6 +1556,8 @@ static void do_mul_effect(Scene *scene, Sequence *seq, int cfra, (unsigned char*) ibuf1->rect, (unsigned char*) ibuf2->rect, (unsigned char*) out->rect); } + + return out; } /* ********************************************************************** @@ -1938,12 +1992,15 @@ static void do_wipe_effect_float(Sequence *seq, float facf0, float facf1, } } -static void do_wipe_effect(Scene *scene, Sequence *seq, int cfra, - float facf0, float facf1, int x, int y, - int preview_render_size, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3, struct ImBuf *out) +static struct ImBuf * do_wipe_effect( + Main *bmain, Scene *scene, Sequence *seq, float cfra, + float facf0, float facf1, int x, int y, + int preview_render_size, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { + struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3); + if (out->rect_float) { do_wipe_effect_float(seq, facf0, facf1, x, y, @@ -1955,6 +2012,8 @@ static void do_wipe_effect(Scene *scene, Sequence *seq, int cfra, (unsigned char*) ibuf1->rect, (unsigned char*) ibuf2->rect, (unsigned char*) out->rect); } + + return out; } /* ********************************************************************** TRANSFORM @@ -2084,13 +2143,18 @@ static void do_transform(Scene *scene, Sequence *seq, float facf0, int x, int y, } -static void do_transform_effect(Scene *scene, Sequence *seq,int cfra, - float facf0, float facf1, int x, int y, - int preview_render_size, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3, struct ImBuf *out) +static struct ImBuf * do_transform_effect( + Main *bmain, Scene *scene, Sequence *seq,float cfra, + float facf0, float facf1, int x, int y, + int preview_render_size, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { + struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3); + do_transform(scene, seq, facf0, x, y, ibuf1, out); + + return out; } @@ -2597,12 +2661,15 @@ static void do_glow_effect_float(Sequence *seq, float facf0, float facf1, RVAddBitmaps_float (inbuf , outbuf, outbuf, x, y); } -static void do_glow_effect(Scene *scene, Sequence *seq, int cfra, - float facf0, float facf1, int x, int y, - int preview_render_size, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3, struct ImBuf *out) +static struct ImBuf * do_glow_effect( + Main *bmain, Scene *scene, Sequence *seq, float cfra, + float facf0, float facf1, int x, int y, + int preview_render_size, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { + struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3); + if (out->rect_float) { do_glow_effect_float(seq, facf0, facf1, x, y, @@ -2614,6 +2681,8 @@ static void do_glow_effect(Scene *scene, Sequence *seq, int cfra, (char*) ibuf1->rect, (char*) ibuf2->rect, (char*) out->rect); } + + return out; } /* ********************************************************************** @@ -2653,12 +2722,15 @@ static int early_out_color(struct Sequence *seq, return -1; } -static void do_solid_color(Scene *scene, Sequence *seq, int cfra, - float facf0, float facf1, int x, int y, - int preview_render_size, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3, struct ImBuf *out) +static struct ImBuf * do_solid_color( + Main *bmain, Scene *scene, Sequence *seq, float cfra, + float facf0, float facf1, int x, int y, + int preview_render_size, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { + struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3); + SolidColorVars *cv = (SolidColorVars *)seq->effectdata; unsigned char *rect; @@ -2728,6 +2800,7 @@ static void do_solid_color(Scene *scene, Sequence *seq, int cfra, } } } + return out; } /* ********************************************************************** @@ -2745,47 +2818,45 @@ static int early_out_multicam(struct Sequence *seq, float facf0, float facf1) return -1; } -static void do_multicam(Scene *scene, Sequence *seq, int cfra, - float facf0, float facf1, int x, int y, - int preview_render_size, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3, struct ImBuf *out) +static struct ImBuf * do_multicam( + Main *bmain, Scene *scene, Sequence *seq, float cfra, + float facf0, float facf1, int x, int y, + int preview_render_size, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { struct ImBuf * i; + struct ImBuf * out; Editing * ed; ListBase * seqbasep; if (seq->multicam_source == 0 || seq->multicam_source >= seq->machine) { - return; + return 0; } ed = scene->ed; if (!ed) { - return; + return 0; } seqbasep = seq_seqbase(&ed->seqbase, seq); if (!seqbasep) { - return; + return 0; } - i = give_ibuf_seqbase(scene, - out->x, out->y, cfra, seq->multicam_source, + i = give_ibuf_seqbase(bmain, scene, x, y, cfra, seq->multicam_source, preview_render_size, seqbasep); if (!i) { - return; + return 0; } - if (out->rect && i->rect) { - memcpy(out->rect, i->rect, out->x * out->y * 4); - } else if (out->rect_float && i->rect_float) { - memcpy(out->rect_float, i->rect_float, out->x * out->y *4*sizeof(float)); - } else if (out->rect && i->rect_float) { - IMB_rect_from_float(i); - memcpy(out->rect, i->rect, out->x * out->y * 4); - } else if (out->rect_float && i->rect) { - IMB_float_from_rect_simple(i); - memcpy(out->rect_float, i->rect_float, out->x * out->y *4*sizeof(float)); + if (input_have_to_preprocess(scene, seq, cfra, x, y)) { + out = IMB_dupImBuf(i); + IMB_freeImBuf(i); + } else { + out = i; } + + return out; } /* ********************************************************************** @@ -2898,22 +2969,11 @@ void sequence_effect_speed_rebuild_map(Scene *scene, Sequence * seq, int force) fallback_fac = 1.0; - /* if there is no IPO, try to make retiming easy by stretching the + /* if there is no fcurve, try to make retiming easy by stretching the strip */ - // XXX old animation system - seq if (!fcu && seq->seq1->enddisp != seq->seq1->start && seq->seq1->len != 0) { fallback_fac = (float) seq->seq1->len / (float) (seq->seq1->enddisp - seq->seq1->start); - /* FIXME: this strip stretching gets screwed by stripdata - handling one layer up. - - So it currently works by enlarging, never by shrinking! - - (IPOs still work, if used correctly) - */ - if (fallback_fac > 1.0) { - fallback_fac = 1.0; - } } if ((v->flags & SEQ_SPEED_INTEGRATE) != 0) { @@ -2936,8 +2996,8 @@ void sequence_effect_speed_rebuild_map(Scene *scene, Sequence * seq, int force) cursor += facf; - if (cursor >= v->length) { - v->frameMap[cfra] = v->length - 1; + if (cursor >= seq->seq1->len) { + v->frameMap[cfra] = seq->seq1->len - 1; } else { v->frameMap[cfra] = cursor; v->lastValidFrame = cfra; @@ -2963,8 +3023,8 @@ void sequence_effect_speed_rebuild_map(Scene *scene, Sequence * seq, int force) facf = (float) cfra * fallback_fac; } facf *= v->globalSpeed; - if (facf >= v->length) { - facf = v->length - 1; + if (facf >= seq->seq1->len) { + facf = seq->seq1->len - 1; } else { v->lastValidFrame = cfra; } @@ -3048,13 +3108,13 @@ static void store_icu_yrange_noop(struct Sequence * seq, /* defaults are fine */ } -static void get_default_fac_noop(struct Sequence *seq, int cfra, +static void get_default_fac_noop(struct Sequence *seq, float cfra, float * facf0, float * facf1) { *facf0 = *facf1 = 1.0; } -static void get_default_fac_fade(struct Sequence *seq, int cfra, +static void get_default_fac_fade(struct Sequence *seq, float cfra, float * facf0, float * facf1) { *facf0 = (float)(cfra - seq->startdisp); @@ -3063,21 +3123,38 @@ static void get_default_fac_fade(struct Sequence *seq, int cfra, *facf1 /= seq->len; } -static void do_overdrop_effect(Scene *scene, Sequence *seq, int cfra, - float fac, float facf, - int x, int y, - int preview_render_size, - struct ImBuf * ibuf1, - struct ImBuf * ibuf2, - struct ImBuf * ibuf3, - struct ImBuf * out) -{ - do_drop_effect(scene, seq, cfra, fac, facf, x, y, - preview_render_size, - ibuf1, ibuf2, ibuf3, out); - do_alphaover_effect(scene, seq, cfra, fac, facf, x, y, - preview_render_size, - ibuf1, ibuf2, ibuf3, out); +static struct ImBuf * do_overdrop_effect(Main *bmain, Scene *scene, Sequence *seq, float cfra, + float facf0, float facf1, + int x, int y, + int preview_render_size, + struct ImBuf * ibuf1, + struct ImBuf * ibuf2, + struct ImBuf * ibuf3) +{ + struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3); + + if (out->rect_float) { + do_drop_effect_float( + facf0, facf1, x, y, + ibuf1->rect_float, ibuf2->rect_float, + out->rect_float); + do_alphaover_effect_float( + facf0, facf1, x, y, + ibuf1->rect_float, ibuf2->rect_float, + out->rect_float); + } else { + do_drop_effect_byte( + facf0, facf1, x, y, + (char*) ibuf1->rect, + (char*) ibuf2->rect, + (char*) out->rect); + do_alphaover_effect_byte( + facf0, facf1, x, y, + (char*) ibuf1->rect, (char*) ibuf2->rect, + (char*) out->rect); + } + + return out; } static struct SeqEffectHandle get_sequence_effect_impl(int seq_type) diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index d97e6151a13..b20bb111cb4 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -39,6 +39,7 @@ #include "DNA_scene_types.h" #include "DNA_anim_types.h" #include "DNA_object_types.h" +#include "DNA_sound_types.h" #include "BKE_animsys.h" #include "BKE_global.h" @@ -55,6 +56,7 @@ #include "BLI_listbase.h" #include "BLI_path_util.h" #include "BLI_string.h" +#include "BLI_threads.h" #include <pthread.h> #include "IMB_imbuf.h" @@ -115,53 +117,11 @@ int seq_recursive_apply(Sequence *seq, int (*apply_func)(Sequence *, void *), vo alloc / free functions ********************************************************************** */ -static void free_tstripdata(int len, TStripElem *se) -{ - TStripElem *seo; - int a; - - seo= se; - if (!se) - return; - - for(a=0; a<len; a++, se++) { - if(se->ibuf) { - IMB_freeImBuf(se->ibuf); - se->ibuf = 0; - } - if(se->ibuf_comp) { - IMB_freeImBuf(se->ibuf_comp); - se->ibuf_comp = 0; - } - } - - MEM_freeN(seo); -} void new_tstripdata(Sequence *seq) { if(seq->strip) { - free_tstripdata(seq->strip->len, seq->strip->tstripdata); - free_tstripdata(seq->strip->endstill, - seq->strip->tstripdata_endstill); - free_tstripdata(seq->strip->startstill, - seq->strip->tstripdata_startstill); - - seq->strip->tstripdata= 0; - seq->strip->tstripdata_endstill= 0; - seq->strip->tstripdata_startstill= 0; - - if(seq->strip->ibuf_startstill) { - IMB_freeImBuf(seq->strip->ibuf_startstill); - seq->strip->ibuf_startstill = 0; - } - - if(seq->strip->ibuf_endstill) { - IMB_freeImBuf(seq->strip->ibuf_endstill); - seq->strip->ibuf_endstill = 0; - } - seq->strip->len= seq->len; } } @@ -207,20 +167,6 @@ void seq_free_strip(Strip *strip) MEM_freeN(strip->color_balance); } - free_tstripdata(strip->len, strip->tstripdata); - free_tstripdata(strip->endstill, strip->tstripdata_endstill); - free_tstripdata(strip->startstill, strip->tstripdata_startstill); - - if(strip->ibuf_startstill) { - IMB_freeImBuf(strip->ibuf_startstill); - strip->ibuf_startstill = 0; - } - - if(strip->ibuf_endstill) { - IMB_freeImBuf(strip->ibuf_endstill); - strip->ibuf_endstill = 0; - } - MEM_freeN(strip); } @@ -608,7 +554,7 @@ void calc_sequence(Scene *scene, Sequence *seq) } /* note: caller should run calc_sequence(scene, seq) after */ -void reload_sequence_new_file(Scene *scene, Sequence * seq, int lock_range) +void reload_sequence_new_file(Main *bmain, Scene *scene, Sequence * seq, int lock_range) { char str[FILE_MAXDIR+FILE_MAXFILE]; int prev_startdisp, prev_enddisp; @@ -675,7 +621,7 @@ void reload_sequence_new_file(Scene *scene, Sequence * seq, int lock_range) seq->strip->len = seq->len; } else if (seq->type == SEQ_SCENE) { /* 'seq->scenenr' should be replaced with something more reliable */ - Scene * sce = G.main->scene.first; + Scene * sce = bmain->scene.first; int nr = 1; while(sce) { @@ -764,12 +710,12 @@ static int clear_scene_in_allseqs_cb(Sequence *seq, void *arg_pt) return 1; } -void clear_scene_in_allseqs(Scene *scene) +void clear_scene_in_allseqs(Main *bmain, Scene *scene) { Scene *scene_iter; /* when a scene is deleted: test all seqs */ - for(scene_iter= G.main->scene.first; scene_iter; scene_iter= scene_iter->id.next) { + for(scene_iter= bmain->scene.first; scene_iter; scene_iter= scene_iter->id.next) { if(scene_iter != scene && scene_iter->ed) { seqbase_recursive_apply(&scene_iter->ed->seqbase, clear_scene_in_allseqs_cb, scene); } @@ -949,139 +895,10 @@ static void multibuf(ImBuf *ibuf, float fmul) } } -static void do_effect(Scene *scene, int cfra, Sequence *seq, TStripElem * se, - int render_size) -{ - TStripElem *se1, *se2, *se3; - float fac, facf; - int x, y; - int early_out; - struct SeqEffectHandle sh = get_sequence_effect(seq); - FCurve *fcu= NULL; - - if (!sh.execute) { /* effect not supported in this version... */ - make_black_ibuf(se->ibuf); - return; - } - - if ((seq->flag & SEQ_USE_EFFECT_DEFAULT_FADE) != 0) { - sh.get_default_fac(seq, cfra, &fac, &facf); - if( scene->r.mode & R_FIELDS ); else facf= fac; - } else { - fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, - "effect_fader", 0); - if (fcu) { - fac = facf = evaluate_fcurve(fcu, cfra); - if( scene->r.mode & R_FIELDS ) { - facf = evaluate_fcurve(fcu, cfra + 0.5); - } - } else { - fac = facf = seq->effect_fader; - } - } - - early_out = sh.early_out(seq, fac, facf); - - if (early_out == -1) { /* no input needed */ - sh.execute(scene, seq, cfra, fac, facf, - se->ibuf->x, se->ibuf->y, render_size, - 0, 0, 0, se->ibuf); - return; - } - - switch (early_out) { - case 0: - if (se->se1==0 || se->se2==0 || se->se3==0) { - make_black_ibuf(se->ibuf); - return; - } - - se1= se->se1; - se2= se->se2; - se3= se->se3; - - if ( (se1==0 || se2==0 || se3==0) - || (se1->ibuf==0 || se2->ibuf==0 || se3->ibuf==0)) { - make_black_ibuf(se->ibuf); - return; - } - - break; - case 1: - if (se->se1 == 0) { - make_black_ibuf(se->ibuf); - return; - } - - se1= se->se1; - - if (se1 == 0 || se1->ibuf == 0) { - make_black_ibuf(se->ibuf); - return; - } - - if (se->ibuf != se1->ibuf) { - IMB_freeImBuf(se->ibuf); - se->ibuf = se1->ibuf; - IMB_refImBuf(se->ibuf); - } - return; - case 2: - if (se->se2 == 0) { - make_black_ibuf(se->ibuf); - return; - } - - se2= se->se2; - - if (se2 == 0 || se2->ibuf == 0) { - make_black_ibuf(se->ibuf); - return; - } - if (se->ibuf != se2->ibuf) { - IMB_freeImBuf(se->ibuf); - se->ibuf = se2->ibuf; - IMB_refImBuf(se->ibuf); - } - return; - default: - make_black_ibuf(se->ibuf); - return; - } - - x= se2->ibuf->x; - y= se2->ibuf->y; - - if (!se1->ibuf->rect_float && se->ibuf->rect_float) { - IMB_float_from_rect_simple(se1->ibuf); - } - if (!se2->ibuf->rect_float && se->ibuf->rect_float) { - IMB_float_from_rect_simple(se2->ibuf); - } - if (!se3->ibuf->rect_float && se->ibuf->rect_float) { - IMB_float_from_rect_simple(se3->ibuf); - } - - if (!se1->ibuf->rect && !se->ibuf->rect_float) { - IMB_rect_from_float(se1->ibuf); - } - if (!se2->ibuf->rect && !se->ibuf->rect_float) { - IMB_rect_from_float(se2->ibuf); - } - if (!se3->ibuf->rect && !se->ibuf->rect_float) { - IMB_rect_from_float(se3->ibuf); - } - - sh.execute(scene, seq, cfra, fac, facf, x, y, render_size, - se1->ibuf, se2->ibuf, se3->ibuf, - se->ibuf); -} - -static int give_stripelem_index(Sequence *seq, int cfra) +static float give_stripelem_index(Sequence *seq, float cfra) { - int nr; + float nr; - if(seq->startdisp >cfra || seq->enddisp <= cfra) return -1; if(seq->len == 0) return -1; if(seq->flag&SEQ_REVERSE_FRAMES) { /*reverse frame in this sequence */ @@ -1095,93 +912,12 @@ static int give_stripelem_index(Sequence *seq, int cfra) } if (seq->strobe < 1.0) seq->strobe = 1.0; if (seq->strobe > 1.0) { - nr -= (int)fmod((double)nr, (double)seq->strobe); + nr -= fmod((double)nr, (double)seq->strobe); } return nr; } -static TStripElem* alloc_tstripdata(int len, const char * name) -{ - int i; - TStripElem *se = MEM_callocN(len * sizeof(TStripElem), name); - for (i = 0; i < len; i++) { - se[i].ok = STRIPELEM_OK; - } - return se; -} - -static TStripElem *give_tstripelem(Sequence *seq, int cfra) -{ - TStripElem *se; - int nr; - - se = seq->strip->tstripdata; - if (se == 0 && seq->len > 0) { - se = seq->strip->tstripdata = alloc_tstripdata(seq->len, - "tstripelems"); - } - nr = give_stripelem_index(seq, cfra); - - if (nr == -1) return 0; - if (se == 0) return 0; - - se += nr; - - /* if there are IPOs with blend modes active, one has to watch out - for startstill + endstill area: we can't use the same tstripelem - here for all ibufs, since then, blending with IPOs won't work! - - Rather common case, if you use a single image and try to fade - it in and out... or want to use your strip as a watermark in - alpha over mode... - */ - if (seq->blend_mode != SEQ_BLEND_REPLACE || - (/*seq->ipo && seq->ipo->curve.first &&*/ - (!(seq->type & SEQ_EFFECT) || !seq->seq1))) { - Strip * s = seq->strip; - if (cfra < seq->start) { - se = s->tstripdata_startstill; - if (seq->startstill > s->startstill) { - free_tstripdata(s->startstill, - s->tstripdata_startstill); - se = 0; - } - - if (se == 0) { - s->startstill = seq->startstill; - se = seq->strip->tstripdata_startstill - = alloc_tstripdata( - s->startstill, - "tstripelems_startstill"); - } - se += seq->start - cfra - 1; - - } else if (cfra > seq->start + seq->len-1) { - se = s->tstripdata_endstill; - if (seq->endstill > s->endstill) { - free_tstripdata(s->endstill, - s->tstripdata_endstill); - se = 0; - } - - if (se == 0) { - s->endstill = seq->endstill; - se = seq->strip->tstripdata_endstill - = alloc_tstripdata( - s->endstill, - "tstripelems_endstill"); - } - se += cfra - (seq->start + seq->len-1) - 1; - } - } - - - se->nr= nr; - - return se; -} - StripElem *give_stripelem(Sequence *seq, int cfra) { StripElem *se= seq->strip->stripdata; @@ -1190,7 +926,7 @@ StripElem *give_stripelem(Sequence *seq, int cfra) /* use the first */ } else { - int nr = give_stripelem_index(seq, cfra); + int nr = (int) give_stripelem_index(seq, cfra); if (nr == -1) return 0; if (se == 0) return 0; @@ -1321,17 +1057,15 @@ static int seq_proxy_get_fname(Scene *scene, Sequence * seq, int cfra, char * na dir, render_size, se->name); frameno = 1; } else if (seq->type == SEQ_MOVIE) { - TStripElem * tse = give_tstripelem(seq, cfra); - - frameno = tse->nr + seq->anim_startofs; + frameno = (int) give_stripelem_index(seq, cfra) + + seq->anim_startofs; snprintf(name, PROXY_MAXFILE, "%s/%s/%d/####", dir, seq->strip->stripdata->name, render_size); } else { - TStripElem * tse = give_tstripelem(seq, cfra); - - frameno = tse->nr + seq->anim_startofs; + frameno = (int) give_stripelem_index(seq, cfra) + + seq->anim_startofs; snprintf(name, PROXY_MAXFILE, "%s/proxy_misc/%d/####", dir, render_size); @@ -1360,10 +1094,11 @@ static struct ImBuf * seq_proxy_fetch(Scene *scene, Sequence * seq, int cfra, in } if (seq->flag & SEQ_USE_PROXY_CUSTOM_FILE) { - TStripElem * tse = give_tstripelem(seq, cfra); - int frameno = tse->nr + seq->anim_startofs; + int frameno = (int) give_stripelem_index(seq, cfra) + + seq->anim_startofs; if (!seq->strip->proxy->anim) { - if (!seq_proxy_get_fname(scene, seq, cfra, name, render_size)) { + if (!seq_proxy_get_fname( + scene, seq, cfra, name, render_size)) { return 0; } @@ -1606,12 +1341,12 @@ static void make_cb_table_float(float lift, float gain, float gamma, } } -static void color_balance_byte_byte(Sequence * seq, TStripElem* se, float mul) +static void color_balance_byte_byte(Sequence * seq, ImBuf* ibuf, float mul) { unsigned char cb_tab[3][256]; int c; - unsigned char * p = (unsigned char*) se->ibuf->rect; - unsigned char * e = p + se->ibuf->x * 4 * se->ibuf->y; + unsigned char * p = (unsigned char*) ibuf->rect; + unsigned char * e = p + ibuf->x * 4 * ibuf->y; StripColorBalance cb = calc_cb(seq->strip->color_balance); @@ -1629,24 +1364,24 @@ static void color_balance_byte_byte(Sequence * seq, TStripElem* se, float mul) } } -static void color_balance_byte_float(Sequence * seq, TStripElem* se, float mul) +static void color_balance_byte_float(Sequence * seq, ImBuf* ibuf, float mul) { float cb_tab[4][256]; int c,i; - unsigned char * p = (unsigned char*) se->ibuf->rect; - unsigned char * e = p + se->ibuf->x * 4 * se->ibuf->y; + unsigned char * p = (unsigned char*) ibuf->rect; + unsigned char * e = p + ibuf->x * 4 * ibuf->y; float * o; StripColorBalance cb; - imb_addrectfloatImBuf(se->ibuf); + imb_addrectfloatImBuf(ibuf); - o = se->ibuf->rect_float; + o = ibuf->rect_float; cb = calc_cb(seq->strip->color_balance); for (c = 0; c < 3; c++) { make_cb_table_float(cb.lift[c], cb.gain[c], cb.gamma[c], - cb_tab[c], mul); + cb_tab[c], mul); } for (i = 0; i < 256; i++) { @@ -1663,10 +1398,10 @@ static void color_balance_byte_float(Sequence * seq, TStripElem* se, float mul) } } -static void color_balance_float_float(Sequence * seq, TStripElem* se, float mul) +static void color_balance_float_float(Sequence * seq, ImBuf* ibuf, float mul) { - float * p = se->ibuf->rect_float; - float * e = se->ibuf->rect_float + se->ibuf->x * 4* se->ibuf->y; + float * p = ibuf->rect_float; + float * e = ibuf->rect_float + ibuf->x * 4* ibuf->y; StripColorBalance cb = calc_cb(seq->strip->color_balance); while (p < e) { @@ -1678,14 +1413,14 @@ static void color_balance_float_float(Sequence * seq, TStripElem* se, float mul) } } -static void color_balance(Sequence * seq, TStripElem* se, float mul) +static void color_balance(Sequence * seq, ImBuf* ibuf, float mul) { - if (se->ibuf->rect_float) { - color_balance_float_float(seq, se, mul); + if (ibuf->rect_float) { + color_balance_float_float(seq, ibuf, mul); } else if(seq->flag & SEQ_MAKE_FLOAT) { - color_balance_byte_float(seq, se, mul); + color_balance_byte_float(seq, ibuf, mul); } else { - color_balance_byte_byte(seq, se, mul); + color_balance_byte_byte(seq, ibuf, mul); } } @@ -1708,44 +1443,49 @@ static void color_balance(Sequence * seq, TStripElem* se, float mul) */ -static int input_have_to_preprocess(Scene *scene, Sequence * seq, TStripElem* se, int cfra, int seqrectx, int seqrecty) +int input_have_to_preprocess( + Scene *scene, Sequence * seq, float cfra, int seqrectx, int seqrecty) { float mul; if ((seq->flag & SEQ_FILTERY) || - (seq->flag & SEQ_USE_CROP) || - (seq->flag & SEQ_USE_TRANSFORM) || - (seq->flag & SEQ_FLIPX) || - (seq->flag & SEQ_FLIPY) || - (seq->flag & SEQ_USE_COLOR_BALANCE) || - (seq->flag & SEQ_MAKE_PREMUL) || - (se->ibuf->x != seqrectx || se->ibuf->y != seqrecty)) { + (seq->flag & SEQ_USE_CROP) || + (seq->flag & SEQ_USE_TRANSFORM) || + (seq->flag & SEQ_FLIPX) || + (seq->flag & SEQ_FLIPY) || + (seq->flag & SEQ_USE_COLOR_BALANCE) || + (seq->flag & SEQ_MAKE_PREMUL)) { return TRUE; } mul = seq->mul; - if(seq->blend_mode == SEQ_BLEND_REPLACE && - !(seq->type & SEQ_EFFECT)) { + if(seq->blend_mode == SEQ_BLEND_REPLACE) { mul *= seq->blend_opacity / 100.0; } if (mul != 1.0) { return TRUE; } + + if (seq->sat != 1.0) { + return TRUE; + } return FALSE; } -static void input_preprocess(Scene *scene, Sequence *seq, TStripElem *se, int cfra, int seqrectx, int seqrecty) +static ImBuf * input_preprocess( + Scene *scene, Sequence *seq, float cfra, int seqrectx, int seqrecty, + ImBuf * ibuf) { float mul; - seq->strip->orx= se->ibuf->x; - seq->strip->ory= se->ibuf->y; + seq->strip->orx= ibuf->x; + seq->strip->ory= ibuf->y; if((seq->flag & SEQ_FILTERY) && seq->type != SEQ_MOVIE) { - IMB_filtery(se->ibuf); + IMB_filtery(ibuf); } if(seq->flag & SEQ_USE_CROP || seq->flag & SEQ_USE_TRANSFORM) { @@ -1763,8 +1503,8 @@ static void input_preprocess(Scene *scene, Sequence *seq, TStripElem *se, int cf t = *seq->strip->transform; } - sx = se->ibuf->x - c.left - c.right; - sy = se->ibuf->y - c.top - c.bottom; + sx = ibuf->x - c.left - c.right; + sy = ibuf->y - c.top - c.bottom; dx = sx; dy = sy; @@ -1773,45 +1513,49 @@ static void input_preprocess(Scene *scene, Sequence *seq, TStripElem *se, int cf dy = scene->r.ysch; } - if (c.top + c.bottom >= se->ibuf->y || - c.left + c.right >= se->ibuf->x || + if (c.top + c.bottom >= ibuf->y || + c.left + c.right >= ibuf->x || t.xofs >= dx || t.yofs >= dy) { - make_black_ibuf(se->ibuf); + make_black_ibuf(ibuf); } else { ImBuf * i; - if (se->ibuf->rect_float) { + if (ibuf->rect_float) { i = IMB_allocImBuf(dx, dy,32, IB_rectfloat, 0); } else { i = IMB_allocImBuf(dx, dy,32, IB_rect, 0); } - IMB_rectcpy(i, se->ibuf, - t.xofs, t.yofs, - c.left, c.bottom, - sx, sy); - - IMB_freeImBuf(se->ibuf); + IMB_rectcpy(i, ibuf, + t.xofs, t.yofs, + c.left, c.bottom, + sx, sy); + + IMB_freeImBuf(ibuf); - se->ibuf = i; + ibuf = i; } } if(seq->flag & SEQ_FLIPX) { - IMB_flipx(se->ibuf); + IMB_flipx(ibuf); + } + + if(seq->flag & SEQ_FLIPY) { + IMB_flipy(ibuf); } if(seq->sat != 1.0f) { /* inline for now, could become an imbuf function */ int i; - char *rct= (char *)se->ibuf->rect; - float *rctf= se->ibuf->rect_float; + char *rct= (char *)ibuf->rect; + float *rctf= ibuf->rect_float; const float sat= seq->sat; float hsv[3]; if(rct) { float rgb[3]; - for (i = se->ibuf->x * se->ibuf->y; i > 0; i--, rct+=4) { + for (i = ibuf->x * ibuf->y; i > 0; i--, rct+=4) { rgb_byte_to_float(rct, rgb); rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2); hsv_to_rgb(hsv[0], hsv[1] * sat, hsv[2], rgb, rgb+1, rgb+2); @@ -1820,7 +1564,7 @@ static void input_preprocess(Scene *scene, Sequence *seq, TStripElem *se, int cf } if(rctf) { - for (i = se->ibuf->x * se->ibuf->y; i > 0; i--, rctf+=4) { + for (i = ibuf->x * ibuf->y; i > 0; i--, rctf+=4) { rgb_to_hsv(rctf[0], rctf[1], rctf[2], hsv, hsv+1, hsv+2); hsv_to_rgb(hsv[0], hsv[1] * sat, hsv[2], rctf, rctf+1, rctf+2); } @@ -1834,718 +1578,520 @@ static void input_preprocess(Scene *scene, Sequence *seq, TStripElem *se, int cf } if(seq->flag & SEQ_USE_COLOR_BALANCE && seq->strip->color_balance) { - color_balance(seq, se, mul); + color_balance(seq, ibuf, mul); mul = 1.0; } if(seq->flag & SEQ_MAKE_FLOAT) { - if (!se->ibuf->rect_float) - IMB_float_from_rect_simple(se->ibuf); + if (!ibuf->rect_float) + IMB_float_from_rect_simple(ibuf); - if (se->ibuf->rect) { - imb_freerectImBuf(se->ibuf); + if (ibuf->rect) { + imb_freerectImBuf(ibuf); } } if(mul != 1.0) { - multibuf(se->ibuf, mul); + multibuf(ibuf, mul); } if(seq->flag & SEQ_MAKE_PREMUL) { - if(se->ibuf->depth == 32 && se->ibuf->zbuf == 0) { - IMB_premultiply_alpha(se->ibuf); + if(ibuf->depth == 32 && ibuf->zbuf == 0) { + IMB_premultiply_alpha(ibuf); } } - if(se->ibuf->x != seqrectx || se->ibuf->y != seqrecty ) { + if(ibuf->x != seqrectx || ibuf->y != seqrecty ) { if(scene->r.mode & R_OSA) { - IMB_scaleImBuf(se->ibuf, - (short)seqrectx, (short)seqrecty); + IMB_scaleImBuf(ibuf, + (short)seqrectx, (short)seqrecty); } else { - IMB_scalefastImBuf(se->ibuf, + IMB_scalefastImBuf(ibuf, (short)seqrectx, (short)seqrecty); } } + return ibuf; } -/* test if image too small or discarded from cache: reload */ - -static void test_and_auto_discard_ibuf(TStripElem * se, - int seqrectx, int seqrecty) +static ImBuf * copy_from_ibuf_still(Sequence * seq, float nr, + int seqrectx, int seqrecty) { - if (se->ibuf) { - if(se->ibuf->x != seqrectx || se->ibuf->y != seqrecty - || !(se->ibuf->rect || se->ibuf->rect_float)) { - IMB_freeImBuf(se->ibuf); + ImBuf * rval = 0; + ImBuf * ibuf = 0; - se->ibuf= 0; - se->ok= STRIPELEM_OK; - } + if (nr == 0) { + ibuf = seq_stripelem_cache_get( + seq, seqrectx, seqrecty, seq->start, + SEQ_STRIPELEM_IBUF_STARTSTILL); + } + if (nr == seq->len - 1) { + ibuf = seq_stripelem_cache_get( + seq, seqrectx, seqrecty, seq->start, + SEQ_STRIPELEM_IBUF_ENDSTILL); } - if (se->ibuf_comp) { - if(se->ibuf_comp->x != seqrectx || se->ibuf_comp->y != seqrecty - || !(se->ibuf_comp->rect || se->ibuf_comp->rect_float)) { - IMB_freeImBuf(se->ibuf_comp); - se->ibuf_comp = 0; - } + if (ibuf) { + rval = IMB_dupImBuf(ibuf); + IMB_freeImBuf(ibuf); } + + return rval; } -static void test_and_auto_discard_ibuf_stills(Strip * strip) +static void copy_to_ibuf_still(Sequence * seq, float nr, + ImBuf * ibuf) { - if (strip->ibuf_startstill) { - if (!strip->ibuf_startstill->rect && - !strip->ibuf_startstill->rect_float) { - IMB_freeImBuf(strip->ibuf_startstill); - strip->ibuf_startstill = 0; - } + if (nr == 0) { + seq_stripelem_cache_put( + seq, 0, 0, seq->start, + SEQ_STRIPELEM_IBUF_STARTSTILL, ibuf); } - if (strip->ibuf_endstill) { - if (!strip->ibuf_endstill->rect && - !strip->ibuf_endstill->rect_float) { - IMB_freeImBuf(strip->ibuf_endstill); - strip->ibuf_endstill = 0; - } + if (nr == seq->len - 1) { + seq_stripelem_cache_put( + seq, 0, 0, seq->start, + SEQ_STRIPELEM_IBUF_ENDSTILL, ibuf); } } -static void copy_from_ibuf_still(Sequence * seq, TStripElem * se) -{ - if (!se->ibuf) { - if (se->nr == 0 && seq->strip->ibuf_startstill) { - IMB_cache_limiter_touch(seq->strip->ibuf_startstill); - - se->ibuf = IMB_dupImBuf(seq->strip->ibuf_startstill); - } - if (se->nr == seq->len - 1 - && (seq->len != 1) - && seq->strip->ibuf_endstill) { - IMB_cache_limiter_touch(seq->strip->ibuf_endstill); +/* ********************************************************************** + strip rendering functions + ********************************************************************** */ - se->ibuf = IMB_dupImBuf(seq->strip->ibuf_endstill); - } - } -} +static ImBuf* seq_render_strip_stack( + Main *bmain, Scene *scene, + ListBase *seqbasep, float cfra, int chanshown, int render_size, + int seqrectx, int seqrecty); -static void copy_to_ibuf_still(Sequence * seq, TStripElem * se) -{ - if (se->ibuf) { - if (se->nr == 0) { - seq->strip->ibuf_startstill = IMB_dupImBuf(se->ibuf); +static ImBuf * seq_render_strip(Main *bmain, Scene *scene, Sequence * seq, float cfra, + int render_size, + int seqrectx, int seqrecty); - IMB_cache_limiter_insert(seq->strip->ibuf_startstill); - IMB_cache_limiter_touch(seq->strip->ibuf_startstill); - } - if (se->nr == seq->len - 1 && seq->len != 1) { - seq->strip->ibuf_endstill = IMB_dupImBuf(se->ibuf); - IMB_cache_limiter_insert(seq->strip->ibuf_endstill); - IMB_cache_limiter_touch(seq->strip->ibuf_endstill); - } - } -} - -static void free_metastrip_imbufs(ListBase *seqbasep, int cfra, int chanshown) +static ImBuf* seq_render_effect_strip_impl( + Main *bmain, Scene *scene, float cfra, Sequence *seq, int render_size, + int seqrectx, int seqrecty) { - Sequence* seq_arr[MAXSEQ+1]; + float fac, facf; + int early_out; int i; - TStripElem* se = 0; - - evaluate_seq_frame_gen(seq_arr, seqbasep, cfra); + int must_preprocess = FALSE; - for (i = 0; i < MAXSEQ; i++) { - if (!video_seq_is_rendered(seq_arr[i])) { - continue; - } - se = give_tstripelem(seq_arr[i], cfra); - if (se) { - if (se->ibuf) { - IMB_freeImBuf(se->ibuf); - - se->ibuf= 0; - se->ok= STRIPELEM_OK; - } + struct SeqEffectHandle sh = get_sequence_effect(seq); + FCurve *fcu= NULL; + ImBuf * ibuf[3]; + ImBuf * out = 0; - if (se->ibuf_comp) { - IMB_freeImBuf(se->ibuf_comp); + ibuf[0] = ibuf[1] = ibuf[2] = 0; - se->ibuf_comp = 0; - } - } + if (!sh.execute) { /* effect not supported in this version... */ + goto finish; } - -} -static void check_limiter_refcount(const char * func, TStripElem *se) -{ - if (se && se->ibuf) { - int refcount = IMB_cache_limiter_get_refcount(se->ibuf); - if (refcount != 1) { - /* can happen on complex pipelines */ - if (refcount > 1 && (G.f & G_DEBUG) == 0) { - return; - } - - fprintf(stderr, - "sequencer: (ibuf) %s: " - "suspicious memcache " - "limiter refcount: %d\n", func, refcount); - } - } -} - -static void check_limiter_refcount_comp(const char * func, TStripElem *se) -{ - if (se && se->ibuf_comp) { - int refcount = IMB_cache_limiter_get_refcount(se->ibuf_comp); - if (refcount != 1) { - /* can happen on complex pipelines */ - if (refcount > 1 && (G.f & G_DEBUG) == 0) { - return; + if ((seq->flag & SEQ_USE_EFFECT_DEFAULT_FADE) != 0) { + sh.get_default_fac(seq, cfra, &fac, &facf); + if( scene->r.mode & R_FIELDS ); else facf= fac; + } else { + fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, + "effect_fader", 0); + if (fcu) { + fac = facf = evaluate_fcurve(fcu, cfra); + if( scene->r.mode & R_FIELDS ) { + facf = evaluate_fcurve(fcu, cfra + 0.5); } - fprintf(stderr, - "sequencer: (ibuf comp) %s: " - "suspicious memcache " - "limiter refcount: %d\n", func, refcount); + } else { + fac = facf = seq->effect_fader; } } -} - -static TStripElem* do_build_seq_array_recursively( - Scene *scene, - ListBase *seqbasep, int cfra, int chanshown, int render_size, - int seqrectx, int seqrecty); - -static void do_build_seq_ibuf(Scene *scene, Sequence * seq, TStripElem *se, int cfra, - int build_proxy_run, int render_size, int seqrectx, int seqrecty) -{ - char name[FILE_MAXDIR+FILE_MAXFILE]; - int use_limiter = TRUE; - - test_and_auto_discard_ibuf(se, seqrectx, seqrecty); - test_and_auto_discard_ibuf_stills(seq->strip); - - if(seq->type == SEQ_META) { - TStripElem * meta_se = 0; - int use_preprocess = FALSE; - use_limiter = FALSE; - - if (!build_proxy_run && se->ibuf == 0) { - se->ibuf = seq_proxy_fetch(scene, seq, cfra, render_size); - if (se->ibuf) { - use_limiter = TRUE; - use_preprocess = TRUE; - } - } - - if(!se->ibuf && seq->seqbase.first) { - meta_se = do_build_seq_array_recursively(scene, - &seq->seqbase, seq->start + se->nr, 0, - render_size, seqrectx, seqrecty); - - check_limiter_refcount("do_build_seq_ibuf: for META", meta_se); - } - se->ok = STRIPELEM_OK; - - if(!se->ibuf && meta_se) { - se->ibuf = meta_se->ibuf_comp; - if(se->ibuf && - (!input_have_to_preprocess(scene, seq, se, cfra, - seqrectx, seqrecty) || - build_proxy_run)) { - IMB_refImBuf(se->ibuf); - if (build_proxy_run) { - IMB_cache_limiter_unref(se->ibuf); - } - } else if (se->ibuf) { - struct ImBuf * i = IMB_dupImBuf(se->ibuf); + early_out = sh.early_out(seq, fac, facf); - IMB_cache_limiter_unref(se->ibuf); + if (early_out == -1) { /* no input needed */ + out = sh.execute(bmain, scene, seq, cfra, fac, facf, + seqrectx, seqrecty, render_size, + 0, 0, 0); + goto finish; + } - se->ibuf = i; - use_limiter = TRUE; - use_preprocess = TRUE; - } - } else if (se->ibuf) { - use_limiter = TRUE; - } - if (meta_se) { - free_metastrip_imbufs( - &seq->seqbase, seq->start + se->nr, 0); - } + must_preprocess = input_have_to_preprocess( + scene, seq, cfra, seqrectx, seqrecty); - if (use_preprocess) { - input_preprocess(scene, seq, se, cfra, seqrectx, - seqrecty); - } - } else if(seq->type & SEQ_EFFECT) { - int use_preprocess = FALSE; - /* should the effect be recalculated? */ - - if (!build_proxy_run && se->ibuf == 0) { - se->ibuf = seq_proxy_fetch(scene, seq, cfra, render_size); - if (se->ibuf) { - use_preprocess = TRUE; - } + switch (early_out) { + case 0: + break; + case 1: + if (seq->seq1) { + ibuf[0] = seq_render_strip(bmain, scene, seq->seq1, cfra, + render_size, + seqrectx, seqrecty); } - - if(se->ibuf == 0) { - /* if any inputs are rectfloat, output is float too */ - if((se->se1 && se->se1->ibuf && se->se1->ibuf->rect_float) || - (se->se2 && se->se2->ibuf && se->se2->ibuf->rect_float) || - (se->se3 && se->se3->ibuf && se->se3->ibuf->rect_float)) - se->ibuf= IMB_allocImBuf((short)seqrectx, (short)seqrecty, 32, IB_rectfloat, 0); - else - se->ibuf= IMB_allocImBuf((short)seqrectx, (short)seqrecty, 32, IB_rect, 0); - - do_effect(scene, cfra, seq, se, render_size); - if (input_have_to_preprocess(scene, seq, se, cfra, - seqrectx, seqrecty) && - !build_proxy_run) { - if ((se->se1 && (se->ibuf == se->se1->ibuf)) || - (se->se2 && (se->ibuf == se->se2->ibuf))) { - struct ImBuf * i - = IMB_dupImBuf(se->ibuf); - - IMB_freeImBuf(se->ibuf); - - se->ibuf = i; - } - use_preprocess = TRUE; + if (ibuf[0]) { + if (must_preprocess) { + out = IMB_dupImBuf(ibuf[0]); + } else { + out = ibuf[0]; + IMB_refImBuf(out); } } - if (use_preprocess) { - input_preprocess(scene, seq, se, cfra, seqrectx, - seqrecty); - } - } else if(seq->type == SEQ_IMAGE) { - if(se->ok == STRIPELEM_OK && se->ibuf == 0) { - StripElem * s_elem = give_stripelem(seq, cfra); - BLI_join_dirfile(name, seq->strip->dir, s_elem->name); - BLI_path_abs(name, G.sce); - if (!build_proxy_run) { - se->ibuf = seq_proxy_fetch(scene, seq, cfra, render_size); - } - copy_from_ibuf_still(seq, se); - - if (se->ibuf==NULL && (se->ibuf= IMB_loadiffname(name, IB_rect))) { - /* we don't need both (speed reasons)! */ - if (se->ibuf->rect_float && se->ibuf->rect) - imb_freerectImBuf(se->ibuf); - - /* all sequencer color is done in SRGB space, linear gives odd crossfades */ - if(se->ibuf->profile == IB_PROFILE_LINEAR_RGB) - IMB_convert_profile(se->ibuf, IB_PROFILE_NONE); - - copy_to_ibuf_still(seq, se); - } - - if(se->ibuf == 0) { - se->ok = STRIPELEM_FAILED; - } else if (!build_proxy_run) { - input_preprocess(scene, seq, se, cfra, - seqrectx, seqrecty); + goto finish; + case 2: + if (seq->seq2) { + ibuf[1] = seq_render_strip(bmain, scene, seq->seq2, cfra, + render_size, + seqrectx, seqrecty); + } + if (ibuf[1]) { + if (must_preprocess) { + out = IMB_dupImBuf(ibuf[1]); + } else { + out = ibuf[1]; + IMB_refImBuf(out); } } - } else if(seq->type == SEQ_MOVIE) { - if(se->ok == STRIPELEM_OK && se->ibuf==0) { - if(!build_proxy_run) { - se->ibuf = seq_proxy_fetch(scene, seq, cfra, render_size); - } - copy_from_ibuf_still(seq, se); + goto finish; + default: + goto finish; + } - if (se->ibuf == 0) { - if(seq->anim==0) { - BLI_join_dirfile(name, seq->strip->dir, seq->strip->stripdata->name); - BLI_path_abs(name, G.sce); - - seq->anim = openanim( - name, IB_rect | - ((seq->flag & SEQ_FILTERY) - ? IB_animdeinterlace : 0)); - } - if(seq->anim) { - IMB_anim_set_preseek(seq->anim, seq->anim_preseek); - se->ibuf = IMB_anim_absolute(seq->anim, se->nr + seq->anim_startofs); - /* we don't need both (speed reasons)! */ - if (se->ibuf - && se->ibuf->rect_float - && se->ibuf->rect) { - imb_freerectImBuf(se->ibuf); - } + if (seq->seq1) { + ibuf[0] = seq_render_strip(bmain, scene, seq->seq1, cfra, + render_size, + seqrectx, seqrecty); + } - } - copy_to_ibuf_still(seq, se); - } - - if(se->ibuf == 0) { - se->ok = STRIPELEM_FAILED; - } else if (!build_proxy_run) { - input_preprocess(scene, seq, se, cfra, - seqrectx, seqrecty); - } - } - } else if(seq->type == SEQ_SCENE) { // scene can be NULL after deletions - Scene *sce= seq->scene;// *oldsce= scene; - int have_seq= FALSE; - int sce_valid= FALSE; + if (seq->seq2) { + ibuf[1] = seq_render_strip(bmain, scene, seq->seq2, cfra, + render_size, + seqrectx, seqrecty); + } - if(sce) { - have_seq= (sce->r.scemode & R_DOSEQ) && sce->ed && sce->ed->seqbase.first; - sce_valid= (sce->camera || have_seq); - } + if (seq->seq3) { + ibuf[2] = seq_render_strip(bmain, scene, seq->seq3, cfra, + render_size, + seqrectx, seqrecty); + } - if (se->ibuf == NULL && sce_valid && !build_proxy_run) { - se->ibuf = seq_proxy_fetch(scene, seq, cfra, render_size); - if (se->ibuf) { - input_preprocess(scene, seq, se, cfra, - seqrectx, seqrecty); - } - } + if (!ibuf[0] || !ibuf[1]) { + goto finish; + } - if (se->ibuf == NULL && sce_valid) { - copy_from_ibuf_still(seq, se); - if (se->ibuf) { - input_preprocess(scene, seq, se, cfra, - seqrectx, seqrecty); - } - } - - if (!sce_valid) { - se->ok = STRIPELEM_FAILED; - } - else if (se->ibuf==NULL && sce_valid) { - int frame= seq->sfra + se->nr + seq->anim_startofs; - int oldcfra = seq->scene->r.cfra; - Object *oldcamera= seq->scene->camera; - ListBase oldmarkers; - - /* Hack! This function can be called from do_render_seq(), in that case - the seq->scene can already have a Render initialized with same name, - so we have to use a default name. (compositor uses scene name to - find render). - However, when called from within the UI (image preview in sequencer) - we do want to use scene Render, that way the render result is defined - for display in render/imagewindow - - Hmm, don't see, why we can't do that all the time, - and since G.rendering is uhm, gone... (Peter) - */ - - int rendering = G.rendering; - int doseq; - int doseq_gl= G.rendering ? /*(scene->r.seq_flag & R_SEQ_GL_REND)*/ 0 : (scene->r.seq_flag & R_SEQ_GL_PREV); - - /* prevent eternal loop */ - doseq= scene->r.scemode & R_DOSEQ; - scene->r.scemode &= ~R_DOSEQ; - - seq->scene->r.cfra= frame; - if(seq->scene_camera) seq->scene->camera= seq->scene_camera; - else scene_camera_switch_update(seq->scene); + out = sh.execute(bmain, scene, seq, cfra, fac, facf, seqrectx, seqrecty, + render_size, + ibuf[0], ibuf[1], ibuf[2]); -#ifdef DURIAN_CAMERA_SWITCH - /* stooping to new low's in hackyness :( */ - oldmarkers= seq->scene->markers; - seq->scene->markers.first= seq->scene->markers.last= NULL; -#endif +finish: + for (i = 0; i < 3; i++) { + IMB_freeImBuf(ibuf[i]); + } - if(sequencer_view3d_cb && doseq_gl && (seq->scene == scene || have_seq==0) && seq->scene->camera) { - /* opengl offscreen render */ - scene_update_for_newframe(seq->scene, seq->scene->lay); - se->ibuf= sequencer_view3d_cb(seq->scene, seqrectx, seqrecty, scene->r.seq_prev_type); - } - else { - Render *re; - RenderResult rres; + if (!out) { + out = IMB_allocImBuf( + (short)seqrectx, (short)seqrecty, 32, IB_rect, 0); + } - if(rendering) - re= RE_NewRender(" do_build_seq_ibuf"); - else - re= RE_NewRender(sce->id.name); + return out; +} - RE_BlenderFrame(re, sce, NULL, sce->lay, frame); - RE_AcquireResultImage(re, &rres); +static ImBuf * seq_render_scene_strip_impl( + Main *bmain, Scene * scene, Sequence * seq, float nr, int seqrectx, int seqrecty) +{ + ImBuf * ibuf = 0; + float frame= seq->sfra + nr + seq->anim_startofs; + float oldcfra; + Object *oldcamera; + ListBase oldmarkers; + + /* Hack! This function can be called from do_render_seq(), in that case + the seq->scene can already have a Render initialized with same name, + so we have to use a default name. (compositor uses scene name to + find render). + However, when called from within the UI (image preview in sequencer) + we do want to use scene Render, that way the render result is defined + for display in render/imagewindow + + Hmm, don't see, why we can't do that all the time, + and since G.rendering is uhm, gone... (Peter) + */ - if(rres.rectf) { - se->ibuf= IMB_allocImBuf(rres.rectx, rres.recty, 32, IB_rectfloat, 0); - memcpy(se->ibuf->rect_float, rres.rectf, 4*sizeof(float)*rres.rectx*rres.recty); - if(rres.rectz) { - addzbuffloatImBuf(se->ibuf); - memcpy(se->ibuf->zbuf_float, rres.rectz, sizeof(float)*rres.rectx*rres.recty); - } - } else if (rres.rect32) { - se->ibuf= IMB_allocImBuf(rres.rectx, rres.recty, 32, IB_rect, 0); - memcpy(se->ibuf->rect, rres.rect32, 4*rres.rectx*rres.recty); - } + int rendering = G.rendering; + int doseq; + int doseq_gl= G.rendering ? /*(scene->r.seq_flag & R_SEQ_GL_REND)*/ 0 : (scene->r.seq_flag & R_SEQ_GL_PREV); + int have_seq= FALSE; + Scene *sce= seq->scene; /* dont refer to seq->scene above this point!, it can be NULL */ + int sce_valid= FALSE; - RE_ReleaseResultImage(re); + if(sce) { + have_seq= (sce->r.scemode & R_DOSEQ) && sce->ed && sce->ed->seqbase.first; + sce_valid= (sce->camera || have_seq); + } - // BIF_end_render_callbacks(); - } - - /* restore */ - scene->r.scemode |= doseq; + if (!sce_valid) + return NULL; - seq->scene->r.cfra = oldcfra; - seq->scene->camera= oldcamera; + oldcfra= seq->scene->r.cfra; + oldcamera= seq->scene->camera; + /* prevent eternal loop */ + doseq= scene->r.scemode & R_DOSEQ; + scene->r.scemode &= ~R_DOSEQ; + + seq->scene->r.cfra= frame; + if(seq->scene_camera) + seq->scene->camera= seq->scene_camera; + else + scene_camera_switch_update(seq->scene); + #ifdef DURIAN_CAMERA_SWITCH - /* stooping to new low's in hackyness :( */ - seq->scene->markers= oldmarkers; + /* stooping to new low's in hackyness :( */ + oldmarkers= seq->scene->markers; + seq->scene->markers.first= seq->scene->markers.last= NULL; #endif - - copy_to_ibuf_still(seq, se); - - if (!build_proxy_run) { - if(se->ibuf == NULL) { - se->ok = STRIPELEM_FAILED; - } else { - input_preprocess(scene, seq, se, cfra, - seqrectx, seqrecty); - } + + if(sequencer_view3d_cb && BLI_thread_is_main() && doseq_gl && (seq->scene == scene || have_seq==0) && seq->scene->camera) { + /* opengl offscreen render */ + scene_update_for_newframe(bmain, seq->scene, seq->scene->lay); + ibuf= sequencer_view3d_cb(seq->scene, seqrectx, seqrecty, + scene->r.seq_prev_type); + } + else { + Render *re; + RenderResult rres; + + if(rendering) + re= RE_NewRender(" do_build_seq_ibuf"); + else + re= RE_NewRender(sce->id.name); + + RE_BlenderFrame(re, bmain, sce, NULL, sce->lay, frame); + + RE_AcquireResultImage(re, &rres); + + if(rres.rectf) { + ibuf= IMB_allocImBuf(rres.rectx, rres.recty, 32, IB_rectfloat, 0); + memcpy(ibuf->rect_float, rres.rectf, 4*sizeof(float)*rres.rectx*rres.recty); + if(rres.rectz) { + addzbuffloatImBuf(ibuf); + memcpy(ibuf->zbuf_float, rres.rectz, sizeof(float)*rres.rectx*rres.recty); } + /* float buffers in the sequencer are not linear */ + ibuf->profile= IB_PROFILE_LINEAR_RGB; + IMB_convert_profile(ibuf, IB_PROFILE_SRGB); } - } - if (!build_proxy_run) { - if (se->ibuf && use_limiter) { - IMB_cache_limiter_insert(se->ibuf); - IMB_cache_limiter_ref(se->ibuf); - IMB_cache_limiter_touch(se->ibuf); + else if (rres.rect32) { + ibuf= IMB_allocImBuf(rres.rectx, rres.recty, 32, IB_rect, 0); + memcpy(ibuf->rect, rres.rect32, 4*rres.rectx*rres.recty); } + + RE_ReleaseResultImage(re); + + // BIF_end_render_callbacks(); } -} + + /* restore */ + scene->r.scemode |= doseq; + + seq->scene->r.cfra = oldcfra; + seq->scene->camera= oldcamera; + +#ifdef DURIAN_CAMERA_SWITCH + /* stooping to new low's in hackyness :( */ + seq->scene->markers= oldmarkers; +#endif -static TStripElem* do_build_seq_recursively(Scene *scene, Sequence *seq, int cfra, int render_size, int seqrectx, int seqrecty); + return ibuf; +} -static void do_effect_seq_recursively(Scene *scene, Sequence *seq, TStripElem *se, int cfra, int render_size, int seqrectx, int seqrecty) +static ImBuf * seq_render_strip(Main *bmain, Scene *scene, Sequence * seq, float cfra, + int render_size, + int seqrectx, int seqrecty) { - float fac, facf; - struct SeqEffectHandle sh = get_sequence_effect(seq); - int early_out; - FCurve *fcu= NULL; + char name[FILE_MAXDIR+FILE_MAXFILE]; + int use_preprocess = input_have_to_preprocess( + scene, seq, cfra, seqrectx, seqrecty); + ImBuf * ibuf = seq_stripelem_cache_get( + seq, seqrectx, seqrecty, cfra, SEQ_STRIPELEM_IBUF); + float nr = give_stripelem_index(seq, cfra); - se->se1 = 0; - se->se2 = 0; - se->se3 = 0; + /* currently, we cache preprocessed images */ + if (ibuf) { + use_preprocess = FALSE; + } - if ((seq->flag & SEQ_USE_EFFECT_DEFAULT_FADE) != 0) { - sh.get_default_fac(seq, cfra, &fac, &facf); - if( scene->r.mode & R_FIELDS ); else facf= fac; - } else { - fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, - "effect_fader", 0); - if (fcu) { - fac = facf = evaluate_fcurve(fcu, cfra); - if( scene->r.mode & R_FIELDS ) { - facf = evaluate_fcurve(fcu, cfra + 0.5); - } - } else { - fac = facf = seq->effect_fader; + if(seq->type == SEQ_META) { + ImBuf * meta_ibuf = 0; + + if (ibuf == 0) { + ibuf = seq_proxy_fetch(scene, seq, cfra, render_size); } - } - early_out = sh.early_out(seq, fac, facf); - switch (early_out) { - case -1: - /* no input needed */ - break; - case 0: - se->se1 = do_build_seq_recursively(scene, seq->seq1, cfra, render_size, seqrectx, seqrecty); - se->se2 = do_build_seq_recursively(scene, seq->seq2, cfra, render_size, seqrectx, seqrecty); - if (seq->seq3) { - se->se3 = do_build_seq_recursively(scene, seq->seq3, cfra, render_size, seqrectx, seqrecty); + if(!ibuf && seq->seqbase.first) { + meta_ibuf = seq_render_strip_stack( + bmain, scene, + &seq->seqbase, seq->start + nr, 0, + render_size, seqrectx, seqrecty); } - break; - case 1: - se->se1 = do_build_seq_recursively(scene, seq->seq1, cfra, render_size, seqrectx, seqrecty); - break; - case 2: - se->se2 = do_build_seq_recursively(scene, seq->seq2, cfra, render_size, seqrectx, seqrecty); - break; - } + if(!ibuf && meta_ibuf) { + ibuf = meta_ibuf; + if(ibuf && use_preprocess) { + struct ImBuf * i = IMB_dupImBuf(ibuf); - do_build_seq_ibuf(scene, seq, se, cfra, FALSE, render_size, seqrectx, seqrecty); + IMB_freeImBuf(ibuf); - /* children are not needed anymore ... */ + ibuf = i; + } + } + } else if(seq->type == SEQ_SPEED) { + ImBuf * child_ibuf = 0; - if (se->se1 && se->se1->ibuf) { - IMB_cache_limiter_unref(se->se1->ibuf); - } - if (se->se2 && se->se2->ibuf) { - IMB_cache_limiter_unref(se->se2->ibuf); - } - if (se->se3 && se->se3->ibuf) { - IMB_cache_limiter_unref(se->se3->ibuf); - } - check_limiter_refcount("do_effect_seq_recursively", se); -} + if (ibuf == 0) { + ibuf = seq_proxy_fetch(scene, seq, cfra, render_size); + } -static TStripElem* do_build_seq_recursively_impl(Scene *scene, Sequence * seq, int cfra, int render_size, int seqrectx, int seqrecty) -{ - TStripElem *se; + if (ibuf == 0) { + float f_cfra; + SpeedControlVars * s + = (SpeedControlVars *)seq->effectdata; - se = give_tstripelem(seq, cfra); + sequence_effect_speed_rebuild_map(scene, seq, 0); - if(se) { - if (seq->type & SEQ_EFFECT) { - do_effect_seq_recursively(scene, seq, se, cfra, render_size, seqrectx, seqrecty); - } else { - do_build_seq_ibuf(scene, seq, se, cfra, FALSE, render_size, seqrectx, seqrecty); + /* weeek! */ + f_cfra = seq->start + s->frameMap[(int) nr]; + + child_ibuf = seq_render_strip(bmain, scene, seq->seq1, f_cfra, + render_size, + seqrectx, seqrecty); } - } - return se; -} -/* FIXME: - -If cfra was float throughout blender (especially in the render -pipeline) one could even _render_ with subframe precision -instead of faking using the blend code below... + if (!ibuf && child_ibuf) { + ibuf = child_ibuf; + if(ibuf && use_preprocess) { + struct ImBuf * i = IMB_dupImBuf(ibuf); -*/ + IMB_freeImBuf(ibuf); -static TStripElem* do_handle_speed_effect(Scene *scene, Sequence * seq, int cfra, int render_size, int seqrectx, int seqrecty) -{ - SpeedControlVars * s = (SpeedControlVars *)seq->effectdata; - int nr = cfra - seq->start; - float f_cfra; - int cfra_left; - int cfra_right; - TStripElem * se = 0; - TStripElem * se1 = 0; - TStripElem * se2 = 0; - - sequence_effect_speed_rebuild_map(scene, seq, 0); - - f_cfra = seq->start + s->frameMap[nr]; - - cfra_left = (int) floor(f_cfra); - cfra_right = (int) ceil(f_cfra); + ibuf = i; + } + } + } else if(seq->type & SEQ_EFFECT) { + /* should the effect be recalculated? */ + + if (ibuf == 0) { + ibuf = seq_proxy_fetch(scene, seq, cfra, render_size); + } - se = give_tstripelem(seq, cfra); + if(ibuf == 0) { + ibuf = seq_render_effect_strip_impl( + bmain, scene, cfra, seq, render_size, + seqrectx, seqrecty); + } + } else if(seq->type == SEQ_IMAGE) { + StripElem * s_elem = give_stripelem(seq, cfra); - if (!se) { - return se; - } + if(ibuf == 0 && s_elem) { + BLI_join_dirfile(name, seq->strip->dir, s_elem->name); + BLI_path_abs(name, G.sce); - if (cfra_left == cfra_right || - (s->flags & SEQ_SPEED_BLEND) == 0) { - test_and_auto_discard_ibuf(se, seqrectx, seqrecty); + ibuf = seq_proxy_fetch(scene, seq, cfra, render_size); + } - if (se->ibuf == NULL) { - se1 = do_build_seq_recursively(scene, seq->seq1, cfra_left, render_size, seqrectx, seqrecty); + if (ibuf == 0) { + ibuf = copy_from_ibuf_still(seq,nr,seqrectx,seqrecty); + } - if((se1 && se1->ibuf && se1->ibuf->rect_float)) - se->ibuf= IMB_allocImBuf((short)seqrectx, (short)seqrecty, 32, IB_rectfloat, 0); - else - se->ibuf= IMB_allocImBuf((short)seqrectx, (short)seqrecty, 32, IB_rect, 0); + if (ibuf == 0 && s_elem && + (ibuf = IMB_loadiffname(name, IB_rect))) { + /* we don't need both (speed reasons)! */ + if (ibuf->rect_float && ibuf->rect) + imb_freerectImBuf(ibuf); - if (se1 == 0 || se1->ibuf == 0) { - make_black_ibuf(se->ibuf); - } else { - if (se->ibuf != se1->ibuf) { - if (se->ibuf) { - IMB_freeImBuf(se->ibuf); - } + /* all sequencer color is done in SRGB space, linear gives odd crossfades */ + if(ibuf->profile == IB_PROFILE_LINEAR_RGB) + IMB_convert_profile(ibuf, IB_PROFILE_NONE); - se->ibuf = se1->ibuf; - IMB_refImBuf(se->ibuf); - } - } + copy_to_ibuf_still(seq, nr, ibuf); } - } else { - struct SeqEffectHandle sh; - - if(se->ibuf) { - if(se->ibuf->x < seqrectx || se->ibuf->y < seqrecty - || !(se->ibuf->rect || se->ibuf->rect_float)) { - IMB_freeImBuf(se->ibuf); - se->ibuf= 0; - } + } else if(seq->type == SEQ_MOVIE) { + if(ibuf == 0) { + ibuf = seq_proxy_fetch(scene, seq, cfra, render_size); + + } + + if (ibuf == 0) { + ibuf = copy_from_ibuf_still(seq, nr,seqrectx,seqrecty); } - if (se->ibuf == NULL) { - se1 = do_build_seq_recursively(scene, seq->seq1, cfra_left, render_size, seqrectx, seqrecty); - se2 = do_build_seq_recursively(scene, seq->seq1, cfra_right, render_size, seqrectx, seqrecty); + if (ibuf == 0) { + if(seq->anim==0) { + BLI_join_dirfile(name, + seq->strip->dir, + seq->strip->stripdata->name); + BLI_path_abs(name, G.sce); + + seq->anim = openanim( + name, IB_rect | + ((seq->flag & SEQ_FILTERY) + ? IB_animdeinterlace : 0)); + } + if(seq->anim) { + IMB_anim_set_preseek(seq->anim, + seq->anim_preseek); + ibuf = IMB_anim_absolute(seq->anim, + nr + + seq->anim_startofs); + /* we don't need both (speed reasons)! */ + if (ibuf && ibuf->rect_float + && ibuf->rect) { + imb_freerectImBuf(ibuf); + } - if((se1 && se1->ibuf && se1->ibuf->rect_float)) - se->ibuf= IMB_allocImBuf((short)seqrectx, (short)seqrecty, 32, IB_rectfloat, 0); - else - se->ibuf= IMB_allocImBuf((short)seqrectx, (short)seqrecty, 32, IB_rect, 0); - - if (!se1 || !se2) { - make_black_ibuf(se->ibuf); - } else { - sh = get_sequence_effect(seq); - - sh.execute(scene, seq, cfra, - f_cfra - (float) cfra_left, - f_cfra - (float) cfra_left, - se->ibuf->x, se->ibuf->y, - render_size, - se1->ibuf, se2->ibuf, 0, se->ibuf); } + copy_to_ibuf_still(seq, nr, ibuf); } + + } else if(seq->type == SEQ_SCENE) { // scene can be NULL after deletions + if (ibuf == 0) { + ibuf = seq_proxy_fetch(scene, seq, cfra, render_size); + } + if (ibuf == 0) { + ibuf = copy_from_ibuf_still(seq, nr,seqrectx,seqrecty); + } + + if (ibuf == 0) { + ibuf = seq_render_scene_strip_impl(bmain, scene, seq, nr, + seqrectx, seqrecty); + copy_to_ibuf_still(seq, nr, ibuf); + } } - /* caller expects this to be referenced, so do it! */ - if (se->ibuf) { - IMB_cache_limiter_insert(se->ibuf); - IMB_cache_limiter_ref(se->ibuf); - IMB_cache_limiter_touch(se->ibuf); + if (!ibuf) { + ibuf = IMB_allocImBuf( + (short)seqrectx, (short)seqrecty, 32, IB_rect, 0); } - /* children are no longer needed */ - if (se1 && se1->ibuf) - IMB_cache_limiter_unref(se1->ibuf); - if (se2 && se2->ibuf) - IMB_cache_limiter_unref(se2->ibuf); - - check_limiter_refcount("do_handle_speed_effect", se); - - return se; -} - -/* - * build all ibufs recursively - * - * if successfull, the returned TStripElem contains the (referenced!) imbuf - * that means: you _must_ call - * - * IMB_cache_limiter_unref(rval); - * - * if rval != 0 - * - */ - -static TStripElem* do_build_seq_recursively(Scene *scene, Sequence * seq, int cfra, int render_size, int seqrectx, int seqrecty) -{ - TStripElem *se; + if (ibuf->x != seqrectx || ibuf->y != seqrecty) { + use_preprocess = TRUE; + } - /* BAD HACK! Seperate handling for speed effects needed, since - a) you can't just fetch a different cfra within an effect strip - b) we have to blend two frames, and CFRA is not float... - */ - if (seq->type == SEQ_SPEED) { - se = do_handle_speed_effect(scene, seq, cfra, render_size, seqrectx, seqrecty); - } else { - se = do_build_seq_recursively_impl(scene, seq, cfra, render_size, seqrectx, seqrecty); + if (use_preprocess) { + ibuf = input_preprocess(scene, seq, cfra, seqrectx, + seqrecty, ibuf); } - check_limiter_refcount("do_build_seq_recursively", se); + seq_stripelem_cache_put( + seq, seqrectx, seqrecty, cfra, SEQ_STRIPELEM_IBUF, ibuf); - return se; + return ibuf; } +/* ********************************************************************** + strip stack rendering functions + ********************************************************************** */ + static int seq_must_swap_input_in_blend_mode(Sequence * seq) { int swap_input = FALSE; @@ -2582,28 +2128,22 @@ static int seq_get_early_out_for_blend_mode(Sequence * seq) return early_out; } -static TStripElem* do_build_seq_array_recursively( - Scene *scene, ListBase *seqbasep, int cfra, int chanshown, +static ImBuf* seq_render_strip_stack( + Main *bmain, Scene *scene, ListBase *seqbasep, float cfra, int chanshown, int render_size, int seqrectx, int seqrecty) { Sequence* seq_arr[MAXSEQ+1]; int count; int i; - TStripElem* se = 0; + ImBuf* out = 0; count = get_shown_sequences(seqbasep, cfra, chanshown, - (Sequence **)&seq_arr); + (Sequence **)&seq_arr); if (!count) { return 0; } - se = give_tstripelem(seq_arr[count - 1], cfra); - - if (!se) { - return 0; - } - #if 0 /* commentind since this breaks keyframing, since it resets the value on draw */ if(scene->r.cfra != cfra) { // XXX for prefetch and overlay offset!..., very bad!!! @@ -2612,25 +2152,24 @@ static TStripElem* do_build_seq_array_recursively( } #endif - test_and_auto_discard_ibuf(se, seqrectx, seqrecty); + out = seq_stripelem_cache_get( + seq_arr[count - 1], + seqrectx, seqrecty, cfra, SEQ_STRIPELEM_IBUF_COMP); - if (se->ibuf_comp != 0) { - IMB_cache_limiter_insert(se->ibuf_comp); - IMB_cache_limiter_ref(se->ibuf_comp); - IMB_cache_limiter_touch(se->ibuf_comp); - return se; + if (out) { + return out; } - if(count == 1) { - se = do_build_seq_recursively(scene, seq_arr[0], - cfra, render_size, - seqrectx, seqrecty); - if (se->ibuf) { - se->ibuf_comp = se->ibuf; - IMB_refImBuf(se->ibuf_comp); - } - return se; + out = seq_render_strip(bmain, scene, seq_arr[0], + cfra, render_size, + seqrectx, seqrecty); + seq_stripelem_cache_put( + seq_arr[0], + seqrectx, seqrecty, cfra, + SEQ_STRIPELEM_IBUF_COMP, out); + + return out; } @@ -2638,29 +2177,17 @@ static TStripElem* do_build_seq_array_recursively( int early_out; Sequence * seq = seq_arr[i]; - se = give_tstripelem(seq, cfra); - - test_and_auto_discard_ibuf(se, seqrectx, seqrecty); + out = seq_stripelem_cache_get( + seq, + seqrectx, seqrecty, cfra, SEQ_STRIPELEM_IBUF_COMP); - if (se->ibuf_comp != 0) { + if (out) { break; } if (seq->blend_mode == SEQ_BLEND_REPLACE) { - do_build_seq_recursively( - scene, seq, cfra, render_size, - seqrectx, seqrecty); - - if (se->ibuf) { - se->ibuf_comp = se->ibuf; - IMB_refImBuf(se->ibuf); - } else { - se->ibuf_comp = IMB_allocImBuf( - (short)seqrectx, (short)seqrecty, - 32, IB_rect, 0); - IMB_cache_limiter_insert(se->ibuf_comp); - IMB_cache_limiter_ref(se->ibuf_comp); - IMB_cache_limiter_touch(se->ibuf_comp); - } + out = seq_render_strip(bmain, scene, seq, cfra, + render_size, + seqrectx, seqrecty); break; } @@ -2669,154 +2196,87 @@ static TStripElem* do_build_seq_array_recursively( switch (early_out) { case -1: case 2: - do_build_seq_recursively( - scene, seq, cfra, render_size, - seqrectx, seqrecty); - - if (se->ibuf) { - se->ibuf_comp = se->ibuf; - IMB_refImBuf(se->ibuf_comp); - } else { - se->ibuf_comp = IMB_allocImBuf( - (short)seqrectx, (short)seqrecty, - 32, IB_rect, 0); - IMB_cache_limiter_insert(se->ibuf_comp); - IMB_cache_limiter_ref(se->ibuf_comp); - IMB_cache_limiter_touch(se->ibuf_comp); - } + out = seq_render_strip(bmain, scene, seq, cfra, + render_size, + seqrectx, seqrecty); break; case 1: if (i == 0) { - se->ibuf_comp = IMB_allocImBuf( + out = IMB_allocImBuf( (short)seqrectx, (short)seqrecty, 32, IB_rect, 0); - IMB_cache_limiter_insert(se->ibuf_comp); - IMB_cache_limiter_ref(se->ibuf_comp); - IMB_cache_limiter_touch(se->ibuf_comp); } break; case 0: - do_build_seq_recursively( - scene, seq, cfra, render_size, - seqrectx, seqrecty); - - if (!se->ibuf) { - se->ibuf = IMB_allocImBuf( - (short)seqrectx, (short)seqrecty, - 32, IB_rect, 0); - IMB_cache_limiter_insert(se->ibuf); - IMB_cache_limiter_ref(se->ibuf); - IMB_cache_limiter_touch(se->ibuf); - } if (i == 0) { - se->ibuf_comp = se->ibuf; - IMB_refImBuf(se->ibuf_comp); + out = seq_render_strip(bmain, scene, seq, cfra, + render_size, + seqrectx, seqrecty); } + break; } - - if (se->ibuf_comp) { + if (out) { break; } } + seq_stripelem_cache_put( + seq_arr[i], seqrectx, seqrecty, cfra, + SEQ_STRIPELEM_IBUF_COMP, out); + + i++; for (; i < count; i++) { Sequence * seq = seq_arr[i]; - struct SeqEffectHandle sh = get_sequence_blend(seq); - TStripElem* se1 = give_tstripelem(seq_arr[i-1], cfra); - TStripElem* se2 = give_tstripelem(seq_arr[i], cfra); - - float facf = seq->blend_opacity / 100.0; - int swap_input = seq_must_swap_input_in_blend_mode(seq); - int early_out = seq_get_early_out_for_blend_mode(seq); - switch (early_out) { - case 0: { - int x= se2->ibuf->x; - int y= se2->ibuf->y; - - if(se1->ibuf_comp == NULL) - continue; - - if (se1->ibuf_comp->rect_float || - se2->ibuf->rect_float) { - se2->ibuf_comp = IMB_allocImBuf( - (short)seqrectx, (short)seqrecty, - 32, IB_rectfloat, 0); - } else { - se2->ibuf_comp = IMB_allocImBuf( - (short)seqrectx, (short)seqrecty, - 32, IB_rect, 0); - } + if (seq_get_early_out_for_blend_mode(seq) == 0) { + struct SeqEffectHandle sh = get_sequence_blend(seq); + ImBuf * ibuf1 = out; + ImBuf * ibuf2 = seq_render_strip(bmain, scene, seq, cfra, + render_size, + seqrectx, seqrecty); + float facf = seq->blend_opacity / 100.0; + int swap_input + = seq_must_swap_input_in_blend_mode(seq); - if (!se1->ibuf_comp->rect_float && - se2->ibuf_comp->rect_float) { - IMB_float_from_rect_simple(se1->ibuf_comp); - } - if (!se2->ibuf->rect_float && - se2->ibuf_comp->rect_float) { - IMB_float_from_rect_simple(se2->ibuf); - } + int x= seqrectx; + int y= seqrecty; - if (!se1->ibuf_comp->rect && - !se2->ibuf_comp->rect_float) { - IMB_rect_from_float(se1->ibuf_comp); - } - if (!se2->ibuf->rect && - !se2->ibuf_comp->rect_float) { - IMB_rect_from_float(se2->ibuf); - } - if (swap_input) { - sh.execute(scene, seq, cfra, - facf, facf, x, y, render_size, - se2->ibuf, se1->ibuf_comp, 0, - se2->ibuf_comp); + out = sh.execute(bmain, scene, seq, cfra, + facf, facf, x, y, render_size, + ibuf2, ibuf1, 0); } else { - sh.execute(scene, seq, cfra, - facf, facf, x, y, render_size, - se1->ibuf_comp, se2->ibuf, 0, - se2->ibuf_comp); + out = sh.execute(bmain, scene, seq, cfra, + facf, facf, x, y, render_size, + ibuf1, ibuf2, 0); } - - IMB_cache_limiter_insert(se2->ibuf_comp); - IMB_cache_limiter_ref(se2->ibuf_comp); - IMB_cache_limiter_touch(se2->ibuf_comp); - - IMB_cache_limiter_unref(se1->ibuf_comp); - IMB_cache_limiter_unref(se2->ibuf); - - break; + + IMB_freeImBuf(ibuf1); + IMB_freeImBuf(ibuf2); } - case 1: { - se2->ibuf_comp = se1->ibuf_comp; - if(se2->ibuf_comp) - IMB_refImBuf(se2->ibuf_comp); - break; - } - } - se = se2; + seq_stripelem_cache_put( + seq_arr[i], seqrectx, seqrecty, cfra, + SEQ_STRIPELEM_IBUF_COMP, out); } - return se; + return out; } /* * returned ImBuf is refed! - * you have to unref after usage! + * you have to free after usage! */ -static ImBuf *give_ibuf_seq_impl(Scene *scene, int rectx, int recty, int cfra, int chanshown, int render_size) +ImBuf *give_ibuf_seq(Main *bmain, Scene *scene, int rectx, int recty, int cfra, int chanshown, int render_size) { Editing *ed= seq_give_editing(scene, FALSE); int count; ListBase *seqbasep; - TStripElem *se; - if(ed==NULL) return NULL; @@ -2828,64 +2288,19 @@ static ImBuf *give_ibuf_seq_impl(Scene *scene, int rectx, int recty, int cfra, i seqbasep= ed->seqbasep; } - se = do_build_seq_array_recursively(scene, seqbasep, cfra, chanshown, render_size, rectx, recty); - - if(!se) { - return 0; - } - - check_limiter_refcount_comp("give_ibuf_seq_impl", se); - - return se->ibuf_comp; + return seq_render_strip_stack( + bmain, scene, seqbasep, cfra, chanshown, render_size, rectx, recty); } -ImBuf *give_ibuf_seqbase(struct Scene *scene, int rectx, int recty, int cfra, int chanshown, int render_size, ListBase *seqbasep) +ImBuf *give_ibuf_seqbase(Main *bmain, Scene *scene, int rectx, int recty, int cfra, int chanshown, int render_size, ListBase *seqbasep) { - TStripElem *se; - - se = do_build_seq_array_recursively(scene, seqbasep, cfra, chanshown, render_size, rectx, recty); - - if(!se) { - return 0; - } - - check_limiter_refcount_comp("give_ibuf_seqbase", se); - - if (se->ibuf_comp) { - IMB_cache_limiter_unref(se->ibuf_comp); - } - - return se->ibuf_comp; + return seq_render_strip_stack(bmain, scene, seqbasep, cfra, chanshown, render_size, rectx, recty); } -ImBuf *give_ibuf_seq_direct(Scene *scene, int rectx, int recty, int cfra, int render_size, Sequence *seq) +ImBuf *give_ibuf_seq_direct(Main *bmain, Scene *scene, int rectx, int recty, int cfra, int render_size, Sequence *seq) { - TStripElem* se; - - se = do_build_seq_recursively(scene, seq, cfra, render_size, rectx, recty); - - if(!se) { - return 0; - } - - check_limiter_refcount("give_ibuf_seq_direct", se); - - if (se->ibuf) { - IMB_cache_limiter_unref(se->ibuf); - } - - return se->ibuf; -} - -ImBuf *give_ibuf_seq(Scene *scene, int rectx, int recty, int cfra, int chanshown, int render_size) -{ - ImBuf* i = give_ibuf_seq_impl(scene, rectx, recty, cfra, chanshown, render_size); - - if (i) { - IMB_cache_limiter_unref(i); - } - return i; + return seq_render_strip(bmain, scene, seq, cfra, render_size, rectx, recty); } #if 0 @@ -3151,13 +2566,13 @@ static void seq_wait_for_prefetch_ready() } #endif -ImBuf *give_ibuf_seq_threaded(Scene *scene, int rectx, int recty, int cfra, int chanshown, int render_size) +ImBuf *give_ibuf_seq_threaded(Main *bmain, Scene *scene, int rectx, int recty, int cfra, int chanshown, int render_size) { PrefetchQueueElem *e = NULL; int found_something = FALSE; if (seq_thread_shutdown) { - return give_ibuf_seq(scene, rectx, recty, cfra, chanshown, render_size); + return give_ibuf_seq(bmain, scene, rectx, recty, cfra, chanshown, render_size); } while (!e) { @@ -3234,20 +2649,6 @@ ImBuf *give_ibuf_seq_threaded(Scene *scene, int rectx, int recty, int cfra, int /* Functions to free imbuf and anim data on changes */ -static void free_imbuf_strip_elem(TStripElem *se) -{ - if(se->ibuf) { - IMB_freeImBuf(se->ibuf); - } - if(se->ibuf_comp) { - IMB_freeImBuf(se->ibuf_comp); - } - se->ibuf_comp = 0; - se->ibuf= 0; - se->ok= STRIPELEM_OK; - se->se1= se->se2= se->se3= 0; -} - static void free_anim_seq(Sequence *seq) { if(seq->anim) { @@ -3256,63 +2657,10 @@ static void free_anim_seq(Sequence *seq) } } -#if 0 -static void free_imbuf_seq_except(Scene *scene, int cfra) +void free_imbuf_seq(Scene *scene, ListBase * seqbase, int check_mem_usage, + int keep_file_handles) { - Editing *ed= seq_give_editing(scene, FALSE); Sequence *seq; - TStripElem *se; - int a; - - if(ed==NULL) return; - - SEQ_BEGIN(ed, seq) { - if(seq->strip) { - TStripElem * curelem = give_tstripelem(seq, cfra); - - for(a = 0, se = seq->strip->tstripdata; - a < seq->strip->len && se; a++, se++) { - if(se != curelem) { - free_imbuf_strip_elem(se); - } - } - for(a = 0, se = seq->strip->tstripdata_startstill; - a < seq->strip->startstill && se; a++, se++) { - if(se != curelem) { - free_imbuf_strip_elem(se); - } - } - for(a = 0, se = seq->strip->tstripdata_endstill; - a < seq->strip->endstill && se; a++, se++) { - if(se != curelem) { - free_imbuf_strip_elem(se); - } - } - if(seq->strip->ibuf_startstill) { - IMB_freeImBuf(seq->strip->ibuf_startstill); - seq->strip->ibuf_startstill = 0; - } - - if(seq->strip->ibuf_endstill) { - IMB_freeImBuf(seq->strip->ibuf_endstill); - seq->strip->ibuf_endstill = 0; - } - - if(seq->type==SEQ_MOVIE) - if(seq->startdisp > cfra || seq->enddisp < cfra) - free_anim_seq(seq); - free_proxy_seq(seq); - } - } - SEQ_END -} -#endif - -void free_imbuf_seq(Scene *scene, ListBase * seqbase, int check_mem_usage) -{ - Sequence *seq; - TStripElem *se; - int a; if (check_mem_usage) { /* Let the cache limitor take care of this (schlaile) */ @@ -3338,39 +2686,19 @@ void free_imbuf_seq(Scene *scene, ListBase * seqbase, int check_mem_usage) } } + seq_stripelem_cache_cleanup(); for(seq= seqbase->first; seq; seq= seq->next) { if(seq->strip) { - for(a = 0, se = seq->strip->tstripdata; - a < seq->strip->len && se; a++, se++) { - free_imbuf_strip_elem(se); - } - for(a = 0, se = seq->strip->tstripdata_startstill; - a < seq->strip->startstill && se; a++, se++) { - free_imbuf_strip_elem(se); - } - for(a = 0, se = seq->strip->tstripdata_endstill; - a < seq->strip->endstill && se; a++, se++) { - free_imbuf_strip_elem(se); - } - if(seq->strip->ibuf_startstill) { - IMB_freeImBuf(seq->strip->ibuf_startstill); - seq->strip->ibuf_startstill = 0; - } - - if(seq->strip->ibuf_endstill) { - IMB_freeImBuf(seq->strip->ibuf_endstill); - seq->strip->ibuf_endstill = 0; - } - - if(seq->type==SEQ_MOVIE) + if(seq->type==SEQ_MOVIE && !keep_file_handles) free_anim_seq(seq); if(seq->type==SEQ_SPEED) { sequence_effect_speed_rebuild_map(scene, seq, 1); } } if(seq->type==SEQ_META) { - free_imbuf_seq(scene, &seq->seqbase, FALSE); + free_imbuf_seq(scene, &seq->seqbase, FALSE, + keep_file_handles); } if(seq->type==SEQ_SCENE) { /* FIXME: recurs downwards, @@ -3383,8 +2711,7 @@ void free_imbuf_seq(Scene *scene, ListBase * seqbase, int check_mem_usage) static int update_changed_seq_recurs(Scene *scene, Sequence *seq, Sequence *changed_seq, int len_change, int ibuf_change) { Sequence *subseq; - int a, free_imbuf = 0; - TStripElem *se; + int free_imbuf = 0; /* recurs downwards to see if this seq depends on the changed seq */ @@ -3410,12 +2737,6 @@ static int update_changed_seq_recurs(Scene *scene, Sequence *seq, Sequence *chan if(free_imbuf) { if(ibuf_change) { - se= seq->strip->tstripdata; - if (se) { - for(a=0; a<seq->len; a++, se++) - free_imbuf_strip_elem(se); - } - if(seq->type == SEQ_MOVIE) free_anim_seq(seq); if(seq->type == SEQ_SPEED) { @@ -3441,39 +2762,6 @@ void update_changed_seq_and_deps(Scene *scene, Sequence *changed_seq, int len_ch update_changed_seq_recurs(scene, seq, changed_seq, len_change, ibuf_change); } -#if 0 // XXX from 2.4x, needs updating -void free_imbuf_seq() -{ - Scene * sce = G.main->scene.first; - while(sce) { - free_imbuf_seq_editing(sce->ed); - sce= sce->id.next; - } -} -#endif - -#if 0 // XXX old animation system -static void free_imbuf_seq_with_ipo(Scene *scene, struct Ipo *ipo) -{ - /* force update of all sequences with this ipo, on ipo changes */ - Editing *ed= seq_give_editing(scene, FALSE); - Sequence *seq; - - if(ed==NULL) return; - - SEQ_BEGIN(ed, seq) { - if(seq->ipo == ipo) { - update_changed_seq_and_deps(scene, seq, 0, 1); - if(seq->type == SEQ_SPEED) { - sequence_effect_speed_rebuild_map(seq, 1); - } - free_proxy_seq(seq); - } - } - SEQ_END -} -#endif - /* seq funcs's for transforming internally notice the difference between start/end and left/right. @@ -4252,12 +3540,6 @@ static Sequence *seq_dupli(struct Scene *scene, Sequence *seq, int dupe_flag) // XXX: add F-Curve duplication stuff? - seqn->strip->tstripdata = 0; - seqn->strip->tstripdata_startstill = 0; - seqn->strip->tstripdata_endstill = 0; - seqn->strip->ibuf_startstill = 0; - seqn->strip->ibuf_endstill = 0; - if (seq->strip->crop) { seqn->strip->crop = MEM_dupallocN(seq->strip->crop); } diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index b9c033f1809..454a82c2ad3 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -54,7 +54,6 @@ #include "BLI_math.h" #include "BLI_editVert.h" -#include "MEM_guardedalloc.h" /* Util macros */ diff --git a/source/blender/blenkernel/intern/sketch.c b/source/blender/blenkernel/intern/sketch.c index 33871f78864..7e39cdd1196 100644 --- a/source/blender/blenkernel/intern/sketch.c +++ b/source/blender/blenkernel/intern/sketch.c @@ -72,8 +72,7 @@ void sk_initPoint(SK_Point *pt, SK_DrawData *dd, float *no) { if (no) { - VECCOPY(pt->no, no); - normalize_v3(pt->no); + normalize_v3_v3(pt->no, no); } else { diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index 5fa9f3897c2..c6993e933c2 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -37,8 +37,8 @@ #include <float.h> #include <math.h> -#include "stdio.h" -#include "string.h" /* memset */ +#include <stdio.h> +#include <string.h> /* memset */ #include "BLI_linklist.h" #include "BLI_rand.h" @@ -220,7 +220,7 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive // printf("res[0]: %d, res[1]: %d, res[2]: %d\n", smd->domain->res[0], smd->domain->res[1], smd->domain->res[2]); // dt max is 0.1 - smd->domain->fluid = smoke_init(smd->domain->res, smd->domain->p0, 0.1); + smd->domain->fluid = smoke_init(smd->domain->res, smd->domain->p0); smd->time = scene->r.cfra; if(smd->domain->flags & MOD_SMOKE_HIGHRES) @@ -237,7 +237,7 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive if(!smd->domain->shadow) smd->domain->shadow = MEM_callocN(sizeof(float) * smd->domain->res[0] * smd->domain->res[1] * smd->domain->res[2], "SmokeDomainShadow"); - smoke_initBlenderRNA(smd->domain->fluid, &(smd->domain->alpha), &(smd->domain->beta)); + smoke_initBlenderRNA(smd->domain->fluid, &(smd->domain->alpha), &(smd->domain->beta), &(smd->domain->time_scale), &(smd->domain->vorticity), &(smd->domain->border_collisions)); if(smd->domain->wt) { @@ -296,7 +296,7 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive return 1; } - return 1; + return 2; } static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs) @@ -713,12 +713,16 @@ void smokeModifier_createType(struct SmokeModifierData *smd) smd->domain->omega = 1.0; smd->domain->alpha = -0.001; smd->domain->beta = 0.1; - smd->domain->flags = MOD_SMOKE_DISSOLVE_LOG; + smd->domain->time_scale = 1.0; + smd->domain->vorticity = 2.0; + smd->domain->border_collisions = 1; // vertically non-colliding + smd->domain->flags = MOD_SMOKE_DISSOLVE_LOG | MOD_SMOKE_HIGH_SMOOTH; smd->domain->strength = 2.0; smd->domain->noise = MOD_SMOKE_NOISEWAVE; smd->domain->diss_speed = 5; - // init view3d buffer - smd->domain->viewsettings = 0; + // init 3dview buffer + + smd->domain->viewsettings = MOD_SMOKE_VIEW_SHOWBIG; smd->domain->effector_weights = BKE_add_effector_weights(NULL); } else if(smd->type & MOD_SMOKE_TYPE_FLOW) @@ -733,6 +737,8 @@ void smokeModifier_createType(struct SmokeModifierData *smd) /* set some standard values */ smd->flow->density = 1.0; smd->flow->temp = 1.0; + smd->flow->flags = MOD_SMOKE_FLOW_ABSOLUTE; + smd->flow->vel_multi = 1.0; smd->flow->psys = NULL; @@ -862,7 +868,7 @@ static void smoke_calc_domain(Scene *scene, Object *ob, SmokeModifierData *smd) { ParticleSystem *psys = sfs->psys; ParticleSettings *part=psys->part; - ParticleData *pa = NULL; + ParticleData *pa = NULL; int p = 0; float *density = smoke_get_density(sds->fluid); float *bigdensity = smoke_turbulence_get_density(sds->wt); @@ -871,7 +877,27 @@ static void smoke_calc_domain(Scene *scene, Object *ob, SmokeModifierData *smd) float *velocity_y = smoke_get_velocity_y(sds->fluid); float *velocity_z = smoke_get_velocity_z(sds->fluid); unsigned char *obstacle = smoke_get_obstacle(sds->fluid); - int bigres[3]; + int bigres[3]; + short absolute_flow = (sfs->flags & MOD_SMOKE_FLOW_ABSOLUTE); + short high_emission_smoothing = bigdensity ? (smd->domain->flags & MOD_SMOKE_HIGH_SMOOTH) : 0; + + /* + * A temporary volume map used to store whole emissive + * area to be added to smoke density and interpolated + * for high resolution smoke. + */ + float *temp_emission_map = NULL; + + // initialize temp emission map + if(!(sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW)) + { + int i; + temp_emission_map = MEM_callocN(sizeof(float) * sds->res[0]*sds->res[1]*sds->res[2], "SmokeTempEmission"); + // set whole volume to 0.0f + for (i=0; i<sds->res[0]*sds->res[1]*sds->res[2]; i++) { + temp_emission_map[i] = 0.0f; + } + } // mostly copied from particle code for(p=0, pa=psys->particles; p<psys->totpart; p++, pa++) @@ -905,33 +931,17 @@ static void smoke_calc_domain(Scene *scene, Object *ob, SmokeModifierData *smd) // heat[index] += sfs->temp * 0.1; // density[index] += sfs->density * 0.1; heat[index] = sfs->temp; - density[index] = sfs->density; - + + // Add emitter density to temp emission map + temp_emission_map[index] = sfs->density; // Uses particle velocity as initial velocity for smoke - if(smd->domain->flags & MOD_SMOKE_INITVELOCITY) { - velocity_x[index] = pa->state.vel[0]; - velocity_y[index] = pa->state.vel[1]; - velocity_z[index] = pa->state.vel[2]; - } - - // obstacle[index] |= 2; - // we need different handling for the high-res feature - if(bigdensity) + if(sfs->flags & MOD_SMOKE_FLOW_INITVELOCITY && (psys->part->phystype != PART_PHYS_NO)) { - // init all surrounding cells according to amplification, too - int i, j, k; - - smoke_turbulence_get_res(smd->domain->wt, bigres); - - for(i = 0; i < smd->domain->amplify + 1; i++) - for(j = 0; j < smd->domain->amplify + 1; j++) - for(k = 0; k < smd->domain->amplify + 1; k++) - { - index = smoke_get_index((smd->domain->amplify + 1)* cell[0] + i, bigres[0], (smd->domain->amplify + 1)* cell[1] + j, bigres[1], (smd->domain->amplify + 1)* cell[2] + k); - bigdensity[index] = sfs->density; - } - } + velocity_x[index] = pa->state.vel[0]*sfs->vel_multi; + velocity_y[index] = pa->state.vel[1]*sfs->vel_multi; + velocity_z[index] = pa->state.vel[2]*sfs->vel_multi; + } } else if(sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW) // outflow { @@ -954,9 +964,136 @@ static void smoke_calc_domain(Scene *scene, Object *ob, SmokeModifierData *smd) index = smoke_get_index((smd->domain->amplify + 1)* cell[0] + i, bigres[0], (smd->domain->amplify + 1)* cell[1] + j, bigres[1], (smd->domain->amplify + 1)* cell[2] + k); bigdensity[index] = 0.f; } - } - } // particles loop - } + } + } + } // particles loop + + + // apply emission values + if(!(sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW)) { + + // initialize variables + int ii, jj, kk, x, y, z, block_size; + size_t index, index_big; + + smoke_turbulence_get_res(smd->domain->wt, bigres); + block_size = smd->domain->amplify + 1; // high res block size + + + // loop through every low res cell + for(x = 0; x < sds->res[0]; x++) + for(y = 0; y < sds->res[1]; y++) + for(z = 0; z < sds->res[2]; z++) + { + + // neighbour cell emission densities (for high resolution smoke smooth interpolation) + float c000, c001, c010, c011, c100, c101, c110, c111; + + c000 = (x>0 && y>0 && z>0) ? temp_emission_map[smoke_get_index(x-1, sds->res[0], y-1, sds->res[1], z-1)] : 0; + c001 = (x>0 && y>0) ? temp_emission_map[smoke_get_index(x-1, sds->res[0], y-1, sds->res[1], z)] : 0; + c010 = (x>0 && z>0) ? temp_emission_map[smoke_get_index(x-1, sds->res[0], y, sds->res[1], z-1)] : 0; + c011 = (x>0) ? temp_emission_map[smoke_get_index(x-1, sds->res[0], y, sds->res[1], z)] : 0; + + c100 = (y>0 && z>0) ? temp_emission_map[smoke_get_index(x, sds->res[0], y-1, sds->res[1], z-1)] : 0; + c101 = (y>0) ? temp_emission_map[smoke_get_index(x, sds->res[0], y-1, sds->res[1], z)] : 0; + c110 = (z>0) ? temp_emission_map[smoke_get_index(x, sds->res[0], y, sds->res[1], z-1)] : 0; + c111 = temp_emission_map[smoke_get_index(x, sds->res[0], y, sds->res[1], z)]; // this cell + + + + // get cell index + index = smoke_get_index(x, sds->res[0], y, sds->res[1], z); + + // add emission to low resolution density + if (absolute_flow) {if (temp_emission_map[index]>0) density[index] = temp_emission_map[index];} + else { + density[index] += temp_emission_map[index]; + if (density[index]>1) density[index]=1.0f; + } + + smoke_turbulence_get_res(smd->domain->wt, bigres); + + + + /* + loop through high res blocks if high res enabled + */ + if (bigdensity) + for(ii = 0; ii < block_size; ii++) + for(jj = 0; jj < block_size; jj++) + for(kk = 0; kk < block_size; kk++) + { + + float fx,fy,fz, interpolated_value; + int shift_x, shift_y, shift_z; + + + /* + * Do volume interpolation if emitter smoothing + * is enabled + */ + if (high_emission_smoothing) { + // convert block position to relative + // for interpolation smoothing + fx = (float)ii/block_size + 0.5f/block_size; + fy = (float)jj/block_size + 0.5f/block_size; + fz = (float)kk/block_size + 0.5f/block_size; + + // calculate trilinear interpolation + interpolated_value = c000 * (1-fx) * (1-fy) * (1-fz) + + c100 * fx * (1-fy) * (1-fz) + + c010 * (1-fx) * fy * (1-fz) + + c001 * (1-fx) * (1-fy) * fz + + c101 * fx * (1-fy) * fz + + c011 * (1-fx) * fy * fz + + c110 * fx * fy * (1-fz) + + c111 * fx * fy * fz; + + + // add some contrast / sharpness + // depending on hi-res block size + + interpolated_value = (interpolated_value-0.4f*sfs->density)*(block_size/2) + 0.4f*sfs->density; + if (interpolated_value<0.0f) interpolated_value = 0.0f; + if (interpolated_value>1.0f) interpolated_value = 1.0f; + + // shift smoke block index + // (because pixel center is actually + // in halfway of the low res block) + shift_x = (x < 1) ? 0 : block_size/2; + shift_y = (y < 1) ? 0 : block_size/2; + shift_z = (z < 1) ? 0 : block_size/2; + } + else { + // without interpolation use same low resolution + // block value for all hi-res blocks + interpolated_value = c111; + shift_x = 0; + shift_y = 0; + shift_z = 0; + } + + // get shifted index for current high resolution block + index_big = smoke_get_index(block_size * x + ii - shift_x, bigres[0], block_size * y + jj - shift_y, bigres[1], block_size * z + kk - shift_z); + + // add emission data to high resolution density + if (absolute_flow) {if (interpolated_value > 0) bigdensity[index_big] = interpolated_value;} + else { + bigdensity[index_big] += interpolated_value; + if (bigdensity[index_big]>1) bigdensity[index_big]=1.0f; + } + + } // end of hires loop + + } // end of low res loop + + // free temporary emission map + if (temp_emission_map) MEM_freeN(temp_emission_map); + + } // end emission + + + } else { @@ -970,7 +1107,7 @@ static void smoke_calc_domain(Scene *scene, Object *ob, SmokeModifierData *smd) BLI_bvhtree_find_nearest(sfs->bvh->tree, pco, &nearest, sfs->bvh->nearest_callback, sfs->bvh); }*/ - } + } } } if(sds->fluid_group) @@ -1188,6 +1325,7 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM int startframe, endframe, framenr; float timescale; int cache_result = 0, cache_result_wt = 0; + int did_init = 0; framenr = scene->r.cfra; @@ -1217,7 +1355,7 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM // printf("startframe: %d, framenr: %d\n", startframe, framenr); - if(!smokeModifier_init(smd, ob, scene, dm)) + if(!(did_init = smokeModifier_init(smd, ob, scene, dm))) { printf("bad smokeModifier_init\n"); return; @@ -1272,10 +1410,20 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM { if(sds->flags & MOD_SMOKE_DISSOLVE) smoke_dissolve(sds->fluid, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG); - smoke_step(sds->fluid, smd->time); + smoke_step(sds->fluid, smd->time, scene->r.frs_sec / scene->r.frs_sec_base); + } + else + { + /* Smoke did not load cache and was not reset but we're on startframe */ + /* So now reinit the smoke since it was not done yet */ + if(did_init == 2) + { + smokeModifier_reset(smd); + smokeModifier_init(smd, ob, scene, dm); + } } - // create shadows before writing cache so we get nice shadows for sstartframe, too + // create shadows before writing cache so we get nice shadows for startframe, too if(get_lamp(scene, light)) smoke_calc_transparency(sds->shadow, smoke_get_density(sds->fluid), sds->p0, sds->p1, sds->res, sds->dx, light, calc_voxel_transp, -7.0*sds->dx); diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 70834746027..d9cb03be37f 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -55,11 +55,12 @@ variables on the UI for now #include "MEM_guardedalloc.h" /* types */ +#include "DNA_object_types.h" +#include "DNA_scene_types.h" +#include "DNA_lattice_types.h" #include "DNA_curve_types.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" -#include "DNA_lattice_types.h" -#include "DNA_scene_types.h" #include "BLI_math.h" #include "BLI_ghash.h" @@ -252,7 +253,7 @@ static float _final_mass(Object *ob,BodyPoint *bp) /******************** for each target object/face the axis aligned bounding box (AABB) is stored -faces paralell to global axes +faces parallel to global axes so only simple "value" in [min,max] ckecks are used float operations still */ @@ -2032,8 +2033,7 @@ static int sb_detect_vertex_collisionCached(float opco[3], float facenormal[3], VECCOPY(vel,avel); if (ci) *intrusion /= ci; if (deflected){ - VECCOPY(facenormal,force); - normalize_v3(facenormal); + normalize_v3_v3(facenormal, force); } return deflected; } @@ -3227,7 +3227,7 @@ static void get_scalar_from_vertexgroup(Object *ob, int vertID, short groupindex } /* Resetting a Mesh SB object's springs */ -/* Spring lenght are caculted from'raw' mesh vertices that are NOT altered by modifier stack. */ +/* Spring length are caculted from'raw' mesh vertices that are NOT altered by modifier stack. */ static void springs_from_mesh(Object *ob) { SoftBody *sb; @@ -3363,7 +3363,7 @@ static void mesh_to_softbody(Scene *scene, Object *ob) add_2nd_order_springs(ob,sb->secondspring); /* exploits the the first run of build_bps_springlist(ob);*/ build_bps_springlist(ob); /* yes we need to do it again*/ } - springs_from_mesh(ob); /* write the 'rest'-lenght of the springs */ + springs_from_mesh(ob); /* write the 'rest'-length of the springs */ if (ob->softflag & OB_SB_SELF) {calculate_collision_balls(ob);} } diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 6402f908422..dd0135cfefc 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -16,6 +16,7 @@ #include "DNA_sequence_types.h" #include "DNA_packedFile_types.h" #include "DNA_screen_types.h" +#include "DNA_sound_types.h" #include "AUD_C-API.h" @@ -122,10 +123,15 @@ struct bSound* sound_new_file(struct Main *bmain, char* filename) bSound* sound = NULL; char str[FILE_MAX]; + char *path; + int len; strcpy(str, filename); - BLI_path_abs(str, bmain->name); + + path = /*bmain ? bmain->name :*/ G.sce; + + BLI_path_abs(str, path); len = strlen(filename); while(len > 0 && filename[len-1] != '/' && filename[len-1] != '\\') @@ -258,7 +264,7 @@ void sound_load(struct Main *bmain, struct bSound* sound) if(sound->id.lib) path = sound->id.lib->filepath; else - path = bmain ? bmain->name : G.sce; + path = /*bmain ? bmain->name :*/ G.sce; BLI_path_abs(fullpath, path); @@ -376,10 +382,8 @@ void sound_move_scene_sound(struct Scene *scene, void* handle, int startframe, i void sound_start_play_scene(struct Scene *scene) { - AUD_Sound* sound; - sound = AUD_loopSound(scene->sound_scene); - scene->sound_scene_handle = AUD_play(sound, 1); - AUD_unload(sound); + scene->sound_scene_handle = AUD_play(scene->sound_scene, 1); + AUD_setLoop(scene->sound_scene_handle, -1, 0); } void sound_play_scene(struct Scene *scene) @@ -392,8 +396,6 @@ void sound_play_scene(struct Scene *scene) if(status == AUD_STATUS_INVALID) sound_start_play_scene(scene); - AUD_setLoop(scene->sound_scene_handle, -1, -1); - if(status != AUD_STATUS_PLAYING) { AUD_seek(scene->sound_scene_handle, CFRA / FPS); @@ -431,12 +433,16 @@ void sound_seek_scene(struct bContext *C) if(scene->audio.flag & AUDIO_SCRUB && !CTX_wm_screen(C)->animtimer) { - AUD_setLoop(scene->sound_scene_handle, -1, 1 / FPS); + // AUD_XXX TODO: fix scrubbing, it currently doesn't stop playing if(scene->audio.flag & AUDIO_SYNC) AUD_seekSequencer(scene->sound_scene_handle, CFRA / FPS); else AUD_seek(scene->sound_scene_handle, CFRA / FPS); AUD_resume(scene->sound_scene_handle); + if(AUD_getStatus(scene->sound_scrub_handle) != AUD_STATUS_INVALID) + AUD_seek(scene->sound_scrub_handle, 0); + //XXX merge EEK! else + //scene->sound_scrub_handle = AUD_pauseAfter(scene->sound_scene_handle, 1 / FPS); } else { @@ -468,7 +474,9 @@ int sound_scene_playing(struct Scene *scene) return -1; } -int sound_read_sound_buffer(struct bSound* sound, float* buffer, int length) +int sound_read_sound_buffer(struct bSound* sound, float* buffer, int length, float start, float end) { - return AUD_readSound(sound->cache, buffer, length); + AUD_Sound* limiter = AUD_limitSound(sound->cache, start, end); + return AUD_readSound(limiter, buffer, length); + AUD_unload(limiter); } diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 6eaac8525bc..7e3b5691177 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -73,6 +73,8 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, int useSubsurfUv, DerivedMesh *dm); +static int ccgDM_use_grid_pbvh(CCGDerivedMesh *ccgdm); + /// static void *arena_alloc(CCGAllocatorHDL a, int numBytes) { @@ -1897,7 +1899,7 @@ void ccgDM_glNormalFast(float *a, float *b, float *c, float *d) static void ccgdm_pbvh_update(CCGDerivedMesh *ccgdm) { - if(ccgdm->pbvh && ccgdm->multires.mmd) { + if(ccgdm->pbvh && ccgDM_use_grid_pbvh(ccgdm)) { CCGFace **faces; int totface; diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index e8328d0e622..19bc853276a 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -43,6 +43,8 @@ #include "DNA_screen_types.h" #include "DNA_space_types.h" #include "DNA_text_types.h" +#include "DNA_userdef_types.h" +#include "DNA_object_types.h" #include "BKE_depsgraph.h" #include "BKE_global.h" @@ -172,10 +174,11 @@ void free_text(Text *text) Text *add_empty_text(char *name) { + Main *bmain= G.main; Text *ta; TextLine *tmp; - ta= alloc_libblock(&G.main->text, ID_TXT, name); + ta= alloc_libblock(&bmain->text, ID_TXT, name); ta->id.us= 1; ta->name= NULL; @@ -324,6 +327,7 @@ int reopen_text(Text *text) Text *add_text(char *file, const char *relpath) { + Main *bmain= G.main; FILE *fp; int i, llen, len, res; unsigned char *buffer; @@ -339,7 +343,7 @@ Text *add_text(char *file, const char *relpath) fp= fopen(str, "r"); if(fp==NULL) return NULL; - ta= alloc_libblock(&G.main->text, ID_TXT, BLI_path_basename(str)); + ta= alloc_libblock(&bmain->text, ID_TXT, BLI_path_basename(str)); ta->id.us= 1; ta->lines.first= ta->lines.last= NULL; @@ -479,7 +483,7 @@ void unlink_text(Main *bmain, Text *text) for(scene=bmain->scene.first; scene; scene=scene->id.next) if(scene->r.dometext == text) scene->r.dometext = NULL; - + for(ob=bmain->object.first; ob; ob=ob->id.next) { /* game controllers */ for(cont=ob->controllers.first; cont; cont=cont->next) { @@ -2683,19 +2687,20 @@ void uncomment(Text *text) } } -int setcurr_tab (Text *text) +int setcurr_tab_spaces (Text *text, int space) { int i = 0; int test = 0; - char *word = ":"; - char *comm = "#"; - char back_words[4][7] = {"return", "break", "pass", "yield"}; + const char *word = ":"; + const char *comm = "#"; + const char indent= (text->flags & TXT_TABSTOSPACES) ? ' ' : '\t'; + static char *back_words[]= {"return", "break", "continue", "pass", "yield", NULL}; if (!text) return 0; if (!text->curl) return 0; - - while (text->curl->line[i] == '\t') + + while (text->curl->line[i] == indent) { - //we only count thos tabs that are before any text or before the curs; + //we only count those tabs/spaces that are before any text or before the curs; if (i == text->curc) { return i; @@ -2718,18 +2723,18 @@ int setcurr_tab (Text *text) } } if (indent) { - i++; + i += space; } } - for(test=0; test < 4; test++) + for(test=0; back_words[test]; test++) { - //if there are these 4 key words then remove a tab because we are done with the block + /* if there are these key words then remove a tab because we are done with the block */ if(strstr(text->curl->line, back_words[test]) && i > 0) { if(strcspn(text->curl->line, back_words[test]) < strcspn(text->curl->line, comm)) { - i--; + i -= space; } } } diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 57816b7e470..9075c64d286 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -169,8 +169,8 @@ PluginTex *add_plugin_tex(char *str) open_plugin_tex(pit); if(pit->doit==0) { - if(pit->handle==0); //XXX error("no plugin: %s", str); - else ; //XXX error("in plugin: %s", str); + if(pit->handle==0) {;} //XXX error("no plugin: %s", str); + else {;} //XXX error("in plugin: %s", str); MEM_freeN(pit); return NULL; } @@ -403,6 +403,73 @@ void colorband_table_RGBA(ColorBand *coba, float **array, int *size) do_colorband(coba, (float)a/(float)CM_TABLE, &(*array)[a*4]); } +int vergcband(const void *a1, const void *a2) +{ + const CBData *x1=a1, *x2=a2; + + if( x1->pos > x2->pos ) return 1; + else if( x1->pos < x2->pos) return -1; + return 0; +} + +CBData *colorband_element_add(struct ColorBand *coba, float position) +{ + int a; + + if(coba->tot==MAXCOLORBAND) { + return NULL; + } + else if(coba->tot > 0) { + CBData *xnew; + float col[4]; + + do_colorband(coba, position, col); + + xnew = &coba->data[coba->tot]; + xnew->pos = position; + + xnew->r = col[0]; + xnew->g = col[1]; + xnew->b = col[2]; + xnew->a = col[3]; + } + + coba->tot++; + coba->cur = coba->tot-1; + + for(a = 0; a < coba->tot; a++) + coba->data[a].cur = a; + + qsort(coba->data, coba->tot, sizeof(CBData), vergcband); + + for(a = 0; a < coba->tot; a++) { + if(coba->data[a].cur == coba->cur) { + coba->cur = a; + break; + } + } + + return coba->data + coba->cur; +} + +int colorband_element_remove(struct ColorBand *coba, int index) +{ + int a; + + if(coba->tot < 2) + return 0; + + if(index < 0 || index >= coba->tot) + return 0; + + for(a = index; a < coba->tot; a++) { + coba->data[a] = coba->data[a + 1]; + } + if(coba->cur) coba->cur--; + coba->tot--; + return 1; +} + /* ******************* TEX ************************ */ void free_texture(Tex *tex) @@ -535,9 +602,10 @@ void tex_set_type(Tex *tex, int type) Tex *add_texture(const char *name) { + Main *bmain= G.main; Tex *tex; - tex= alloc_libblock(&G.main->tex, ID_TE, name); + tex= alloc_libblock(&bmain->tex, ID_TE, name); default_tex(tex); @@ -659,6 +727,7 @@ Tex *copy_texture(Tex *tex) void make_local_texture(Tex *tex) { + Main *bmain= G.main; Tex *texn; Material *ma; World *wrld; @@ -688,7 +757,7 @@ void make_local_texture(Tex *tex) return; } - ma= G.main->mat.first; + ma= bmain->mat.first; while(ma) { for(a=0; a<MAX_MTEX; a++) { if(ma->mtex[a] && ma->mtex[a]->tex==tex) { @@ -698,7 +767,7 @@ void make_local_texture(Tex *tex) } ma= ma->id.next; } - la= G.main->lamp.first; + la= bmain->lamp.first; while(la) { for(a=0; a<MAX_MTEX; a++) { if(la->mtex[a] && la->mtex[a]->tex==tex) { @@ -708,7 +777,7 @@ void make_local_texture(Tex *tex) } la= la->id.next; } - wrld= G.main->world.first; + wrld= bmain->world.first; while(wrld) { for(a=0; a<MAX_MTEX; a++) { if(wrld->mtex[a] && wrld->mtex[a]->tex==tex) { @@ -718,7 +787,7 @@ void make_local_texture(Tex *tex) } wrld= wrld->id.next; } - br= G.main->brush.first; + br= bmain->brush.first; while(br) { if(br->mtex.tex==tex) { if(br->id.lib) lib= 1; @@ -736,7 +805,7 @@ void make_local_texture(Tex *tex) texn= copy_texture(tex); texn->id.us= 0; - ma= G.main->mat.first; + ma= bmain->mat.first; while(ma) { for(a=0; a<MAX_MTEX; a++) { if(ma->mtex[a] && ma->mtex[a]->tex==tex) { @@ -749,7 +818,7 @@ void make_local_texture(Tex *tex) } ma= ma->id.next; } - la= G.main->lamp.first; + la= bmain->lamp.first; while(la) { for(a=0; a<MAX_MTEX; a++) { if(la->mtex[a] && la->mtex[a]->tex==tex) { @@ -762,7 +831,7 @@ void make_local_texture(Tex *tex) } la= la->id.next; } - wrld= G.main->world.first; + wrld= bmain->world.first; while(wrld) { for(a=0; a<MAX_MTEX; a++) { if(wrld->mtex[a] && wrld->mtex[a]->tex==tex) { @@ -775,7 +844,7 @@ void make_local_texture(Tex *tex) } wrld= wrld->id.next; } - br= G.main->brush.first; + br= bmain->brush.first; while(br) { if(br->mtex.tex==tex) { if(br->id.lib==0) { @@ -793,6 +862,7 @@ void make_local_texture(Tex *tex) void autotexname(Tex *tex) { + Main *bmain= G.main; char texstr[20][15]= {"None" , "Clouds" , "Wood", "Marble", "Magic" , "Blend", "Stucci", "Noise" , "Image", "Plugin", "EnvMap" , "Musgrave", "Voronoi", "DistNoise", "Point Density", "Voxel Data", "", "", "", ""}; @@ -801,7 +871,7 @@ void autotexname(Tex *tex) if(tex) { if(tex->use_nodes) { - new_id(&G.main->tex, (ID *)tex, "Noddy"); + new_id(&bmain->tex, (ID *)tex, "Noddy"); } else if(tex->type==TEX_IMAGE) { @@ -811,12 +881,12 @@ void autotexname(Tex *tex) BLI_splitdirstring(di, fi); strcpy(di, "I."); strcat(di, fi); - new_id(&G.main->tex, (ID *)tex, di); + new_id(&bmain->tex, (ID *)tex, di); } - else new_id(&G.main->tex, (ID *)tex, texstr[tex->type]); + else new_id(&bmain->tex, (ID *)tex, texstr[tex->type]); } - else if(tex->type==TEX_PLUGIN && tex->plugin) new_id(&G.main->tex, (ID *)tex, tex->plugin->pname); - else new_id(&G.main->tex, (ID *)tex, texstr[tex->type]); + else if(tex->type==TEX_PLUGIN && tex->plugin) new_id(&bmain->tex, (ID *)tex, tex->plugin->pname); + else new_id(&bmain->tex, (ID *)tex, texstr[tex->type]); } } diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index 6fb1c5ff70c..42df92443f3 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -36,6 +36,7 @@ #include "DNA_world_types.h" #include "DNA_scene_types.h" +#include "DNA_texture_types.h" #include "BKE_library.h" #include "BKE_animsys.h" @@ -43,10 +44,6 @@ #include "BKE_main.h" #include "BKE_icons.h" -#ifndef DISABLE_PYTHON -#include "BPY_extern.h" -#endif - void free_world(World *wrld) { MTex *mtex; @@ -68,9 +65,10 @@ void free_world(World *wrld) World *add_world(char *name) { + Main *bmain= G.main; World *wrld; - wrld= alloc_libblock(&G.main->world, ID_WO, name); + wrld= alloc_libblock(&bmain->world, ID_WO, name); wrld->horr= 0.05f; wrld->horg= 0.05f; @@ -128,6 +126,7 @@ World *copy_world(World *wrld) void make_local_world(World *wrld) { + Main *bmain= G.main; Scene *sce; World *wrldn; int local=0, lib=0; @@ -145,7 +144,7 @@ void make_local_world(World *wrld) return; } - sce= G.main->scene.first; + sce= bmain->scene.first; while(sce) { if(sce->world==wrld) { if(sce->id.lib) lib= 1; @@ -163,7 +162,7 @@ void make_local_world(World *wrld) wrldn= copy_world(wrld); wrldn->id.us= 0; - sce= G.main->scene.first; + sce= bmain->scene.first; while(sce) { if(sce->world==wrld) { if(sce->id.lib==0) { diff --git a/source/blender/blenkernel/intern/writeframeserver.c b/source/blender/blenkernel/intern/writeframeserver.c index 0ec8837c0e7..b0c05c31fa1 100644 --- a/source/blender/blenkernel/intern/writeframeserver.c +++ b/source/blender/blenkernel/intern/writeframeserver.c @@ -45,7 +45,6 @@ #include <stdlib.h> -#include "MEM_guardedalloc.h" #include "DNA_userdef_types.h" #include "BKE_global.h" |