Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Susano Pinto <andresusanopinto@gmail.com>2009-09-15 19:15:43 +0400
committerAndre Susano Pinto <andresusanopinto@gmail.com>2009-09-15 19:15:43 +0400
commitf7c686d0ae68842feddd4f37deadab12e1fa4991 (patch)
tree52773e6d6236aec9a3a80bf6c5c1ea5f7e943224 /source/blender/blenkernel
parentf8657be654f89c6a4826ef8dd3e2275dfe2d4a5a (diff)
parent0338b05a64184ce1a439a418ebc4e315185c1eec (diff)
svn merge -r 22571:22800 https://svn.blender.org/svnroot/bf-blender/trunk/blender
svn merge -r 22800:23207 https://svn.blender.org/svnroot/bf-blender/trunk/blender Merged volumetric with new raytrace code (it compiles and rendered volume-cube.blend withouth problems) Part1: source/blender
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_action.h2
-rw-r--r--source/blender/blenkernel/BKE_anim.h2
-rw-r--r--source/blender/blenkernel/BKE_animsys.h3
-rw-r--r--source/blender/blenkernel/BKE_armature.h1
-rw-r--r--source/blender/blenkernel/BKE_blender.h2
-rw-r--r--source/blender/blenkernel/BKE_brush.h1
-rw-r--r--source/blender/blenkernel/BKE_cloth.h3
-rw-r--r--source/blender/blenkernel/BKE_constraint.h1
-rw-r--r--source/blender/blenkernel/BKE_context.h1
-rw-r--r--source/blender/blenkernel/BKE_curve.h4
-rw-r--r--source/blender/blenkernel/BKE_depsgraph.h7
-rw-r--r--source/blender/blenkernel/BKE_global.h33
-rw-r--r--source/blender/blenkernel/BKE_group.h1
-rw-r--r--source/blender/blenkernel/BKE_key.h5
-rw-r--r--source/blender/blenkernel/BKE_library.h4
-rw-r--r--source/blender/blenkernel/BKE_modifier.h5
-rw-r--r--source/blender/blenkernel/BKE_multires.h8
-rw-r--r--source/blender/blenkernel/BKE_node.h12
-rw-r--r--source/blender/blenkernel/BKE_object.h5
-rw-r--r--source/blender/blenkernel/BKE_paint.h46
-rw-r--r--source/blender/blenkernel/BKE_particle.h56
-rw-r--r--source/blender/blenkernel/BKE_pointcache.h86
-rw-r--r--source/blender/blenkernel/BKE_sca.h1
-rw-r--r--source/blender/blenkernel/BKE_scene.h2
-rw-r--r--source/blender/blenkernel/BKE_sculpt.h72
-rw-r--r--source/blender/blenkernel/BKE_shrinkwrap.h4
-rw-r--r--source/blender/blenkernel/BKE_smoke.h15
-rw-r--r--source/blender/blenkernel/BKE_sound.h4
-rw-r--r--source/blender/blenkernel/BKE_text.h2
-rw-r--r--source/blender/blenkernel/BKE_texture.h12
-rw-r--r--source/blender/blenkernel/BKE_utildefines.h50
-rw-r--r--source/blender/blenkernel/CMakeLists.txt46
-rw-r--r--source/blender/blenkernel/SConscript8
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.c2
-rw-r--r--source/blender/blenkernel/intern/Makefile6
-rw-r--r--source/blender/blenkernel/intern/action.c55
-rw-r--r--source/blender/blenkernel/intern/anim.c98
-rw-r--r--source/blender/blenkernel/intern/anim_sys.c72
-rw-r--r--source/blender/blenkernel/intern/armature.c21
-rw-r--r--source/blender/blenkernel/intern/blender.c3
-rw-r--r--source/blender/blenkernel/intern/boids.c202
-rw-r--r--source/blender/blenkernel/intern/booleanops.c2
-rw-r--r--source/blender/blenkernel/intern/brush.c19
-rw-r--r--source/blender/blenkernel/intern/cdderivedmesh.c41
-rw-r--r--source/blender/blenkernel/intern/cloth.c66
-rw-r--r--source/blender/blenkernel/intern/collision.c4
-rw-r--r--source/blender/blenkernel/intern/colortools.c4
-rw-r--r--source/blender/blenkernel/intern/constraint.c104
-rw-r--r--source/blender/blenkernel/intern/context.c7
-rw-r--r--source/blender/blenkernel/intern/curve.c765
-rw-r--r--source/blender/blenkernel/intern/depsgraph.c93
-rw-r--r--source/blender/blenkernel/intern/displist.c48
-rw-r--r--source/blender/blenkernel/intern/fcurve.c6
-rw-r--r--source/blender/blenkernel/intern/font.c7
-rw-r--r--source/blender/blenkernel/intern/gpencil.c7
-rw-r--r--source/blender/blenkernel/intern/group.c10
-rw-r--r--source/blender/blenkernel/intern/idprop.c2
-rw-r--r--source/blender/blenkernel/intern/image.c227
-rw-r--r--source/blender/blenkernel/intern/implicit.c88
-rw-r--r--source/blender/blenkernel/intern/key.c115
-rw-r--r--source/blender/blenkernel/intern/lattice.c31
-rw-r--r--source/blender/blenkernel/intern/library.c239
-rw-r--r--source/blender/blenkernel/intern/material.c68
-rw-r--r--source/blender/blenkernel/intern/mesh.c4
-rw-r--r--source/blender/blenkernel/intern/modifier.c98
-rw-r--r--source/blender/blenkernel/intern/multires.c25
-rw-r--r--source/blender/blenkernel/intern/nla.c2
-rw-r--r--source/blender/blenkernel/intern/node.c15
-rw-r--r--source/blender/blenkernel/intern/object.c135
-rw-r--r--source/blender/blenkernel/intern/packedFile.c10
-rw-r--r--source/blender/blenkernel/intern/paint.c12
-rw-r--r--source/blender/blenkernel/intern/particle.c755
-rw-r--r--source/blender/blenkernel/intern/particle_system.c717
-rw-r--r--source/blender/blenkernel/intern/pointcache.c458
-rw-r--r--source/blender/blenkernel/intern/sca.c26
-rw-r--r--source/blender/blenkernel/intern/scene.c27
-rw-r--r--source/blender/blenkernel/intern/seqeffects.c6
-rw-r--r--source/blender/blenkernel/intern/sequence.c2
-rw-r--r--source/blender/blenkernel/intern/shrinkwrap.c2
-rw-r--r--source/blender/blenkernel/intern/smoke.c1130
-rw-r--r--source/blender/blenkernel/intern/softbody.c324
-rw-r--r--source/blender/blenkernel/intern/sound.c113
-rw-r--r--source/blender/blenkernel/intern/text.c93
-rw-r--r--source/blender/blenkernel/intern/texture.c123
-rw-r--r--source/blender/blenkernel/intern/unit.c3
85 files changed, 4184 insertions, 2812 deletions
diff --git a/source/blender/blenkernel/BKE_action.h b/source/blender/blenkernel/BKE_action.h
index d35acb5447a..4724ee19aaa 100644
--- a/source/blender/blenkernel/BKE_action.h
+++ b/source/blender/blenkernel/BKE_action.h
@@ -66,7 +66,7 @@ void free_action(struct bAction *act);
void make_local_action(struct bAction *act);
/* Some kind of bounding box operation on the action */
-void calc_action_range(const struct bAction *act, float *start, float *end, int incl_hidden);
+void calc_action_range(const struct bAction *act, float *start, float *end, short incl_modifiers);
/* Does action have any motion data at all? */
short action_has_motion(const struct bAction *act);
diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h
index 5ea511738ad..4b1e758da54 100644
--- a/source/blender/blenkernel/BKE_anim.h
+++ b/source/blender/blenkernel/BKE_anim.h
@@ -51,7 +51,7 @@ typedef struct DupliObject {
void free_path(struct Path *path);
void calc_curvepath(struct Object *ob);
int interval_test(int min, int max, int p1, int cycl);
-int where_on_path(struct Object *ob, float ctime, float *vec, float *dir);
+int where_on_path(struct Object *ob, float ctime, float *vec, float *dir, float *quat, float *radius);
struct ListBase *object_duplilist(struct Scene *sce, struct Object *ob);
void free_object_duplilist(struct ListBase *lb);
diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h
index cabbaa7aa0f..cc5b4dfdcaf 100644
--- a/source/blender/blenkernel/BKE_animsys.h
+++ b/source/blender/blenkernel/BKE_animsys.h
@@ -55,6 +55,9 @@ void BKE_free_animdata(struct ID *id);
/* Copy AnimData */
struct AnimData *BKE_copy_animdata(struct AnimData *adt);
+/* Make Local */
+void BKE_animdata_make_local(struct AnimData *adt);
+
/* ************************************* */
/* KeyingSets API */
diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h
index 0595134f5c9..1cbb2331782 100644
--- a/source/blender/blenkernel/BKE_armature.h
+++ b/source/blender/blenkernel/BKE_armature.h
@@ -74,7 +74,6 @@ struct bArmature *add_armature(char *name);
struct bArmature *get_armature(struct Object *ob);
void free_boneChildren(struct Bone *bone);
void free_bones (struct bArmature *arm);
-void unlink_armature(struct bArmature *arm);
void free_armature(struct bArmature *arm);
void make_local_armature(struct bArmature *arm);
struct bArmature *copy_armature(struct bArmature *arm);
diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h
index 4fe1eec55c0..d60737d62fe 100644
--- a/source/blender/blenkernel/BKE_blender.h
+++ b/source/blender/blenkernel/BKE_blender.h
@@ -43,7 +43,7 @@ struct bContext;
struct ReportList;
#define BLENDER_VERSION 250
-#define BLENDER_SUBVERSION 1
+#define BLENDER_SUBVERSION 3
#define BLENDER_MINVERSION 250
#define BLENDER_MINSUBVERSION 0
diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h
index 6ec988e111e..4d24a2433b3 100644
--- a/source/blender/blenkernel/BKE_brush.h
+++ b/source/blender/blenkernel/BKE_brush.h
@@ -64,7 +64,6 @@ float brush_curve_strength(struct Brush *br, float p, const float len);
/* sampling */
float brush_sample_falloff(struct Brush *brush, float dist);
-float brush_sample_falloff_noalpha(struct Brush *brush, float dist);
void brush_sample_tex(struct Brush *brush, float *xy, float *rgba);
void brush_imbuf_new(struct Brush *brush, short flt, short texfalloff, int size,
struct ImBuf **imbuf);
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index bc4585106e6..e5b3adbd0c0 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -176,7 +176,8 @@ typedef enum
CLOTH_SIMSETTINGS_FLAG_GOAL = ( 1 << 3 ), // we have goals enabled
CLOTH_SIMSETTINGS_FLAG_TEARING = ( 1 << 4 ),// true if tearing is enabled
CLOTH_SIMSETTINGS_FLAG_SCALING = ( 1 << 8 ), /* is advanced scaling active? */
- CLOTH_SIMSETTINGS_FLAG_CCACHE_EDIT = (1 << 12) /* edit cache in editmode */
+ CLOTH_SIMSETTINGS_FLAG_CCACHE_EDIT = (1 << 12), /* edit cache in editmode */
+ CLOTH_SIMSETTINGS_FLAG_NO_SPRING_COMPRESS = (1 << 13) /* don't allow spring compression */
} CLOTH_SIMSETTINGS_FLAGS;
/* COLLISION FLAGS */
diff --git a/source/blender/blenkernel/BKE_constraint.h b/source/blender/blenkernel/BKE_constraint.h
index 6e69906b71d..a0061173438 100644
--- a/source/blender/blenkernel/BKE_constraint.h
+++ b/source/blender/blenkernel/BKE_constraint.h
@@ -49,6 +49,7 @@ typedef struct bConstraintOb {
float startmat[4][4]; /* original matrix (before constraint solving) */
short type; /* type of owner */
+ short rotOrder; /* rotation order for constraint owner (as defined in eEulerRotationOrders in BLI_arithb.h) */
} bConstraintOb;
/* ---------------------------------------------------------------------------- */
diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h
index 035b7e2e5b9..09e13c2930e 100644
--- a/source/blender/blenkernel/BKE_context.h
+++ b/source/blender/blenkernel/BKE_context.h
@@ -152,6 +152,7 @@ struct SpaceLogic *CTX_wm_space_logic(const bContext *C);
struct SpaceIpo *CTX_wm_space_graph(const bContext *C);
struct SpaceAction *CTX_wm_space_action(const bContext *C);
struct SpaceInfo *CTX_wm_space_info(const bContext *C);
+struct SpaceUserPref *CTX_wm_space_userpref(const bContext *C);
void CTX_wm_manager_set(bContext *C, struct wmWindowManager *wm);
void CTX_wm_window_set(bContext *C, struct wmWindow *win);
diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h
index e5a8df1a932..78a2f13a7cc 100644
--- a/source/blender/blenkernel/BKE_curve.h
+++ b/source/blender/blenkernel/BKE_curve.h
@@ -47,7 +47,7 @@ struct BevList;
#define SEGMENTSU(nu) ( ((nu)->flagu & CU_CYCLIC) ? (nu)->pntsu : (nu)->pntsu-1 )
#define SEGMENTSV(nu) ( ((nu)->flagv & CU_CYCLIC) ? (nu)->pntsv : (nu)->pntsv-1 )
-#define CU_DO_TILT(cu, nu) (((nu->type & CU_2D) && (cu->flag & CU_3D)==0) ? 0 : 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)
@@ -72,7 +72,7 @@ void minmaxNurb( struct Nurb *nu, float *min, float *max);
void makeknots( struct Nurb *nu, short uv);
void makeNurbfaces(struct Nurb *nu, float *coord_array, int rowstride);
-void makeNurbcurve(struct Nurb *nu, float *coord_array, float *tilt_array, float *radius_array, int resolu);
+void makeNurbcurve(struct Nurb *nu, float *coord_array, float *tilt_array, float *radius_array, int resolu, int stride);
void forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride);
float *make_orco_curve(struct Scene *scene, struct Object *ob);
float *make_orco_surf( struct Object *ob);
diff --git a/source/blender/blenkernel/BKE_depsgraph.h b/source/blender/blenkernel/BKE_depsgraph.h
index 70b6c1d13f4..e242ead3b87 100644
--- a/source/blender/blenkernel/BKE_depsgraph.h
+++ b/source/blender/blenkernel/BKE_depsgraph.h
@@ -32,6 +32,8 @@
#define DEPS_DEBUG
*/
+struct ID;
+struct Main;
struct Scene;
struct DagNodeQueue;
struct DagForest;
@@ -103,8 +105,9 @@ void DAG_object_update_flags(struct Scene *sce, struct Object *ob, unsigned int
/* flushes all recalc flags in objects down the dependency tree */
void DAG_scene_flush_update(struct Scene *sce, unsigned int lay, int time);
- /* flushes all recalc flags for this object down the dependency tree */
-void DAG_object_flush_update(struct Scene *sce, struct Object *ob, short flag);
+ /* flushes all recalc flags for this object down the dependency tree,
+ but not the DAG only supports objects and object data currently */
+void DAG_id_flush_update(struct ID *id, short flag);
void DAG_pose_sort(struct Object *ob);
diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h
index 7ce616c37c9..5d0b89220d5 100644
--- a/source/blender/blenkernel/BKE_global.h
+++ b/source/blender/blenkernel/BKE_global.h
@@ -119,33 +119,32 @@ typedef struct Global {
#define G_GREASEPENCIL (1 << 17)
/* #define G_AUTOMATKEYS (1 << 30) also removed */
-#define G_HIDDENHANDLES (1 << 31) /* used for curves only */
/* G.fileflags */
#define G_AUTOPACK (1 << 0)
#define G_FILE_COMPRESS (1 << 1)
#define G_FILE_AUTOPLAY (1 << 2)
-#define G_FILE_ENABLE_ALL_FRAMES (1 << 3)
-#define G_FILE_SHOW_DEBUG_PROPS (1 << 4)
-#define G_FILE_SHOW_FRAMERATE (1 << 5)
-#define G_FILE_SHOW_PROFILE (1 << 6)
+#define G_FILE_ENABLE_ALL_FRAMES (1 << 3) /* deprecated */
+#define G_FILE_SHOW_DEBUG_PROPS (1 << 4) /* deprecated */
+#define G_FILE_SHOW_FRAMERATE (1 << 5) /* deprecated */
+#define G_FILE_SHOW_PROFILE (1 << 6) /* deprecated */
#define G_FILE_LOCK (1 << 7)
#define G_FILE_SIGN (1 << 8)
#define G_FIle_PUBLISH (1 << 9)
#define G_FILE_NO_UI (1 << 10)
-#define G_FILE_GAME_TO_IPO (1 << 11)
-#define G_FILE_GAME_MAT (1 << 12)
-#define G_FILE_DISPLAY_LISTS (1 << 13)
-#define G_FILE_SHOW_PHYSICS (1 << 14)
-#define G_FILE_GAME_MAT_GLSL (1 << 15)
-#define G_FILE_GLSL_NO_LIGHTS (1 << 16)
-#define G_FILE_GLSL_NO_SHADERS (1 << 17)
-#define G_FILE_GLSL_NO_SHADOWS (1 << 18)
-#define G_FILE_GLSL_NO_RAMPS (1 << 19)
-#define G_FILE_GLSL_NO_NODES (1 << 20)
-#define G_FILE_GLSL_NO_EXTRA_TEX (1 << 21)
-#define G_FILE_IGNORE_DEPRECATION_WARNINGS (1 << 22)
+#define G_FILE_GAME_TO_IPO (1 << 11) /* deprecated */
+#define G_FILE_GAME_MAT (1 << 12) /* deprecated */
+#define G_FILE_DISPLAY_LISTS (1 << 13) /* deprecated */
+#define G_FILE_SHOW_PHYSICS (1 << 14) /* deprecated */
+#define G_FILE_GAME_MAT_GLSL (1 << 15) /* deprecated */
+#define G_FILE_GLSL_NO_LIGHTS (1 << 16) /* deprecated */
+#define G_FILE_GLSL_NO_SHADERS (1 << 17) /* deprecated */
+#define G_FILE_GLSL_NO_SHADOWS (1 << 18) /* deprecated */
+#define G_FILE_GLSL_NO_RAMPS (1 << 19) /* deprecated */
+#define G_FILE_GLSL_NO_NODES (1 << 20) /* deprecated */
+#define G_FILE_GLSL_NO_EXTRA_TEX (1 << 21) /* deprecated */
+#define G_FILE_IGNORE_DEPRECATION_WARNINGS (1 << 22) /* deprecated */
/* G.windowstate */
#define G_WINDOWSTATE_USERDEF 0
diff --git a/source/blender/blenkernel/BKE_group.h b/source/blender/blenkernel/BKE_group.h
index 35084aabadf..b66ddf13527 100644
--- a/source/blender/blenkernel/BKE_group.h
+++ b/source/blender/blenkernel/BKE_group.h
@@ -41,6 +41,7 @@ void free_group_object(struct GroupObject *go);
void free_group(struct Group *group);
void unlink_group(struct Group *group);
struct Group *add_group(char *name);
+struct Group *copy_group(struct Group *group);
void add_to_group(struct Group *group, struct Object *ob);
int rem_from_group(struct Group *group, struct Object *ob);
struct Group *find_group(struct Object *ob, struct Group *group);
diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h
index e2f9dff6226..4bfa6a41099 100644
--- a/source/blender/blenkernel/BKE_key.h
+++ b/source/blender/blenkernel/BKE_key.h
@@ -52,8 +52,9 @@ struct Key *copy_key(struct Key *key);
void make_local_key(struct Key *key);
void sort_keys(struct Key *key);
-void set_four_ipo(float d, float *data, int type);
-void set_afgeleide_four_ipo(float d, float *data, int type);
+void key_curve_position_weights(float t, float *data, int type);
+void key_curve_tangent_weights(float t, float *data, int type);
+void key_curve_normal_weights(float t, float *data, int type);
/* only exported to curve.c! */
void cp_cu_key(struct Curve *cu, struct KeyBlock *kb, int start, int end);
diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index 4e7db115168..0e978128cf6 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -46,6 +46,9 @@ void *copy_libblock(void *rt);
void id_lib_extern(struct ID *id);
void id_us_plus(struct ID *id);
void id_us_min(struct ID *id);
+int id_make_local(struct ID *id, int test);
+int id_copy(struct ID *id, struct ID **newid, int test);
+int id_unlink(struct ID *id, int test);
int check_for_dupid(struct ListBase *lb, struct ID *id, char *name);
int new_id(struct ListBase *lb, struct ID *id, const char *name);
@@ -74,6 +77,7 @@ void IPOnames_to_pupstring(char **str, char *title, char *extraops, struct ListB
void flag_listbase_ids(ListBase *lb, short flag, short value);
void flag_all_listbases_ids(short flag, short value);
+void recalc_all_library_objects(struct Main *main);
void set_free_windowmanager_cb(void (*func)(struct bContext *, struct wmWindowManager *) );
diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h
index b65d77751e2..27c75126026 100644
--- a/source/blender/blenkernel/BKE_modifier.h
+++ b/source/blender/blenkernel/BKE_modifier.h
@@ -90,7 +90,10 @@ typedef enum {
eModifierTypeFlag_UsesPointCache = (1<<6),
/* For physics modifiers, max one per type */
- eModifierTypeFlag_Single = (1<<7)
+ eModifierTypeFlag_Single = (1<<7),
+
+ /* Some modifier can't be added manually by user */
+ eModifierTypeFlag_NoUserAdd = (1<<8)
} ModifierTypeFlag;
typedef void (*ObjectWalkFunc)(void *userData, struct Object *ob, struct Object **obpoin);
diff --git a/source/blender/blenkernel/BKE_multires.h b/source/blender/blenkernel/BKE_multires.h
index 6558212519f..a331479cad1 100644
--- a/source/blender/blenkernel/BKE_multires.h
+++ b/source/blender/blenkernel/BKE_multires.h
@@ -35,10 +35,12 @@ struct Object;
typedef struct MultiresSubsurf {
struct MultiresModifierData *mmd;
- struct Mesh *me;
+ struct Object *ob;
+ int local_mmd;
} MultiresSubsurf;
/* MultiresDM */
+struct Object *MultiresDM_get_object(struct DerivedMesh *dm);
struct Mesh *MultiresDM_get_mesh(struct DerivedMesh *dm);
struct DerivedMesh *MultiresDM_new(struct MultiresSubsurf *, struct DerivedMesh*, int, int, int);
void *MultiresDM_get_vertnorm(struct DerivedMesh *);
@@ -58,8 +60,8 @@ void multires_mark_as_modified(struct Object *ob);
void multires_force_update(struct Object *ob);
-struct DerivedMesh *multires_dm_create_from_derived(struct MultiresModifierData*, struct DerivedMesh*,
- struct Mesh *, int, int);
+struct DerivedMesh *multires_dm_create_from_derived(struct MultiresModifierData*, int local_mmd, struct DerivedMesh*,
+ struct Object *, int, int);
struct MultiresModifierData *find_multires_modifier(struct Object *ob);
int multiresModifier_switch_level(struct Object *, const int);
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 183cdaff0e6..cbb37918d04 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -25,7 +25,7 @@
*
* The Original Code is: all of this file.
*
- * Contributor(s): none yet.
+ * Contributor(s): Bob Holcomb.
*
* ***** END GPL LICENSE BLOCK *****
*/
@@ -325,7 +325,7 @@ void ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMaterial *mat);
#define CMP_NODE_COMBYUVA 234
#define CMP_NODE_DIFF_MATTE 235
#define CMP_NODE_COLOR_SPILL 236
-#define CMP_NODE_CHROMA 237
+#define CMP_NODE_CHROMA_MATTE 237
#define CMP_NODE_CHANNEL_MATTE 238
#define CMP_NODE_FLIP 239
#define CMP_NODE_SPLITVIEWER 240
@@ -345,6 +345,9 @@ void ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMaterial *mat);
#define CMP_NODE_DBLUR 254
#define CMP_NODE_BILATERALBLUR 255
#define CMP_NODE_PREMULKEY 256
+#define CMP_NODE_DIST_MATTE 257
+#define CMP_NODE_VIEW_LEVELS 258
+#define CMP_NODE_COLOR_MATTE 259
#define CMP_NODE_GLARE 301
#define CMP_NODE_TONEMAP 302
@@ -421,10 +424,9 @@ extern struct ListBase node_all_textures;
/* API */
int ntreeTexTagAnimated(struct bNodeTree *ntree);
-void ntreeTexUpdatePreviews( struct bNodeTree* nodetree );
-void ntreeTexExecTree(struct bNodeTree *ntree, struct TexResult *target, float *coord, char do_preview, short thread, struct Tex *tex, short which_output, int cfra);
+void ntreeTexSetPreviewFlag(int);
+void ntreeTexExecTree(struct bNodeTree *ntree, struct TexResult *target, float *coord, float *dxt, float *dyt, short thread, struct Tex *tex, short which_output, int cfra);
void ntreeTexCheckCyclics(struct bNodeTree *ntree);
-void ntreeTexAssignIndex(struct bNodeTree *ntree, struct bNode *node);
char* ntreeTexOutputMenu(struct bNodeTree *ntree);
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index a57529ccf75..1cb6efeb838 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -115,6 +115,11 @@ void object_handle_update(struct Scene *scene, struct Object *ob);
float give_timeoffset(struct Object *ob);
int give_obdata_texspace(struct Object *ob, int **texflag, float **loc, float **size, float **rot);
+
+int object_insert_ptcache(struct Object *ob);
+// void object_delete_ptcache(struct Object *ob, int index);
+
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 67b260b2348..7dc9e4499c6 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -29,11 +29,20 @@
#define BKE_PAINT_H
struct Brush;
+struct MFace;
+struct MultireModifierData;
+struct MVert;
struct Object;
struct Paint;
struct Scene;
+struct StrokeCache;
-void paint_init(struct Paint *p, const char *brush_name);
+extern const char PAINT_CURSOR_SCULPT[3];
+extern const char PAINT_CURSOR_VERTEX_PAINT[3];
+extern const char PAINT_CURSOR_WEIGHT_PAINT[3];
+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);
@@ -48,4 +57,39 @@ void paint_brush_slot_remove(struct Paint *p);
* however hiding faces is useful */
int paint_facesel_test(struct Object *ob);
+/* Session data (mode-specific) */
+
+typedef struct SculptSession {
+ struct ProjVert *projverts;
+
+ /* Mesh data (not copied) can come either directly from a Mesh, or from a MultiresDM */
+ struct MultiresModifierData *multires; /* Special handling for multires meshes */
+ struct MVert *mvert;
+ struct MFace *mface;
+ int totvert, totface;
+ float *face_normals;
+
+ /* Mesh connectivity */
+ struct ListBase *fmap;
+ struct IndexNode *fmap_mem;
+ int fmap_size;
+
+ /* Used temporarily per-stroke */
+ float *vertexcosnos;
+ ListBase damaged_rects;
+ ListBase damaged_verts;
+
+ /* Used to cache the render of the active texture */
+ unsigned int texcache_side, *texcache, texcache_actual;
+
+ /* Layer brush persistence between strokes */
+ float (*mesh_co_orig)[3]; /* Copy of the mesh vertices' locations */
+ float *layer_disps; /* Displacements for each vertex */
+
+ struct SculptStroke *stroke;
+ struct StrokeCache *cache;
+} SculptSession;
+
+void free_sculptsession(SculptSession **);
+
#endif
diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index cf02efc34ac..c22778f5a30 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -59,6 +59,9 @@ struct SurfaceModifierData;
struct BVHTreeRay;
struct BVHTreeRayHit;
+#define PARTICLE_P ParticleData *pa; int p
+#define LOOP_PARTICLES for(p=0, pa=psys->particles; p<psys->totpart; p++, pa++)
+
typedef struct ParticleEffectorCache {
struct ParticleEffectorCache *next, *prev;
struct Object *ob;
@@ -109,46 +112,10 @@ typedef struct ParticleCacheKey{
float vel[3];
float rot[4];
float col[3];
+ float time;
int steps;
} ParticleCacheKey;
-typedef struct ParticleEditKey{
- float *co;
- float *vel;
- float *rot;
- float *time;
-
- float world_co[3];
- float length;
- short flag;
-} ParticleEditKey;
-
-typedef struct ParticleUndo {
- struct ParticleUndo *next, *prev;
- struct ParticleEditKey **keys;
- struct KDTree *emitter_field;
- struct ParticleData *particles;
- float *emitter_cosnos;
- int totpart, totkeys;
- char name[64];
-} ParticleUndo;
-
-typedef struct ParticleEdit {
- ListBase undo;
- struct ParticleUndo *curundo;
-
- ParticleEditKey **keys;
- int totkeys;
-
- int *mirror_cache;
-
- struct KDTree *emitter_field;
- float *emitter_cosnos;
-
- char sel_col[3];
- char nosel_col[3];
-} ParticleEdit;
-
typedef struct ParticleThreadContext {
/* shared */
struct Scene *scene;
@@ -240,9 +207,10 @@ int psys_check_enabled(struct Object *ob, struct ParticleSystem *psys);
void psys_free_boid_rules(struct ListBase *list);
void psys_free_settings(struct ParticleSettings *part);
void free_child_path_cache(struct ParticleSystem *psys);
-void psys_free_path_cache(struct ParticleSystem *psys);
-void free_hair(struct ParticleSystem *psys, int softbody);
+void psys_free_path_cache(struct ParticleSystem *psys, struct PTCacheEdit *edit);
+void free_hair(struct Object *ob, struct ParticleSystem *psys, int dynamics);
void free_keyed_keys(struct ParticleSystem *psys);
+void psys_free_particles(struct ParticleSystem *psys);
void psys_free(struct Object * ob, struct ParticleSystem * psys);
void psys_free_children(struct ParticleSystem *psys);
@@ -271,9 +239,9 @@ void psys_reset(struct ParticleSystem *psys, int mode);
void psys_find_parents(struct Object *ob, struct ParticleSystemModifierData *psmd, struct ParticleSystem *psys);
-void psys_cache_paths(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys, float cfra, int editupdate);
+void psys_cache_paths(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys, float cfra);
+void psys_cache_edit_paths(struct Scene *scene, struct Object *ob, struct PTCacheEdit *edit, float cfra);
void psys_cache_child_paths(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys, float cfra, int editupdate);
-void psys_update_world_cos(struct Object *ob, struct ParticleSystem *psys);
int do_guide(struct Scene *scene, struct ParticleKey *state, int pa_num, float time, struct ListBase *lb);
float psys_get_size(struct Object *ob, struct Material *ma, struct ParticleSystemModifierData *psmd, struct IpoCurve *icu_size, struct ParticleSystem *psys, struct ParticleSettings *part, struct ParticleData *pa, float *vg_size);
float psys_get_timestep(struct ParticleSettings *part);
@@ -359,12 +327,6 @@ void reset_particle(struct Scene *scene, struct ParticleData *pa, struct Particl
#define PSYS_EC_PARTICLE 4
#define PSYS_EC_REACTOR 8
-/* ParticleEditKey->flag */
-#define PEK_SELECT 1
-#define PEK_TO_SELECT 2
-#define PEK_TAG 4
-#define PEK_HIDE 8
-
/* index_dmcache */
#define DMCACHE_NOTFOUND -1
#define DMCACHE_ISCHILD -2
diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h
index 5d9dddfe30d..5ae10d736fd 100644
--- a/source/blender/blenkernel/BKE_pointcache.h
+++ b/source/blender/blenkernel/BKE_pointcache.h
@@ -60,8 +60,8 @@
#define PTCACHE_TYPE_SOFTBODY 0
#define PTCACHE_TYPE_PARTICLES 1
#define PTCACHE_TYPE_CLOTH 2
-#define PTCACHE_TYPE_SMOKE_DOMAIN_LOW 3
-#define PTCACHE_TYPE_SMOKE_DOMAIN_HIGH 4
+#define PTCACHE_TYPE_SMOKE_DOMAIN 3
+#define PTCACHE_TYPE_SMOKE_HIGHRES 4
/* PTCache read return code */
#define PTCACHE_READ_EXACT 1
@@ -101,6 +101,8 @@ typedef struct PTCacheFile {
void *cur[BPHYS_TOT_DATA];
} PTCacheFile;
+#define PTCACHE_VEL_PER_SEC 1
+
typedef struct PTCacheID {
struct PTCacheID *next, *prev;
@@ -109,6 +111,7 @@ typedef struct PTCacheID {
void *calldata;
int type;
int stack_index;
+ int flag;
/* flags defined in DNA_object_force.h */
unsigned int data_types, info_types;
@@ -151,6 +154,76 @@ typedef struct PTCacheBaker {
void *progresscontext;
} PTCacheBaker;
+/* PTCacheEditKey->flag */
+#define PEK_SELECT 1
+#define PEK_TAG 2
+#define PEK_HIDE 4
+#define PEK_USE_WCO 8
+
+typedef struct PTCacheEditKey{
+ float *co;
+ float *vel;
+ float *rot;
+ float *time;
+
+ float world_co[3];
+ float ftime;
+ float length;
+ short flag;
+} PTCacheEditKey;
+
+/* PTCacheEditPoint->flag */
+#define PEP_TAG 1
+#define PEP_EDIT_RECALC 2
+#define PEP_TRANSFORM 4
+#define PEP_HIDE 8
+
+typedef struct PTCacheEditPoint {
+ struct PTCacheEditKey *keys;
+ int totkey;
+ short flag;
+} PTCacheEditPoint;
+
+typedef struct PTCacheUndo {
+ struct PTCacheUndo *next, *prev;
+ struct PTCacheEditPoint *points;
+
+ /* particles stuff */
+ struct ParticleData *particles;
+ struct KDTree *emitter_field;
+ float *emitter_cosnos;
+ int psys_flag;
+
+ /* cache stuff */
+ struct ListBase mem_cache;
+
+ int totpoint;
+ char name[64];
+} PTCacheUndo;
+
+typedef struct PTCacheEdit {
+ ListBase undo;
+ struct PTCacheUndo *curundo;
+ PTCacheEditPoint *points;
+
+ struct PTCacheID pid;
+
+ /* particles stuff */
+ struct ParticleSystem *psys;
+ struct ParticleData *particles;
+ struct KDTree *emitter_field;
+ float *emitter_cosnos;
+ int *mirror_cache;
+
+ struct ParticleCacheKey **pathcache; /* path cache (runtime) */
+ ListBase pathcachebufs;
+
+ int totpoint, totframes, totcached, edited;
+
+ char sel_col[3];
+ char nosel_col[3];
+} PTCacheEdit;
+
/* Particle functions */
void BKE_ptcache_make_particle_key(struct ParticleKey *key, int index, void **data, float time);
@@ -158,7 +231,8 @@ void BKE_ptcache_make_particle_key(struct ParticleKey *key, int index, void **da
void BKE_ptcache_id_from_softbody(PTCacheID *pid, struct Object *ob, struct SoftBody *sb);
void BKE_ptcache_id_from_particles(PTCacheID *pid, struct Object *ob, struct ParticleSystem *psys);
void BKE_ptcache_id_from_cloth(PTCacheID *pid, struct Object *ob, struct ClothModifierData *clmd);
-void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd, int num);
+void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd);
+void BKE_ptcache_id_from_smoke_turbulence(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd);
void BKE_ptcache_ids_from_object(struct ListBase *lb, struct Object *ob);
@@ -179,6 +253,10 @@ void BKE_ptcache_update_info(PTCacheID *pid);
/* Size of cache data type. */
int BKE_ptcache_data_size(int data_type);
+/* Memory cache read/write helpers. */
+void BKE_ptcache_mem_init_pointers(struct PTCacheMem *pm);
+void BKE_ptcache_mem_incr_pointers(struct PTCacheMem *pm);
+
/* Copy a specific data type from cache data to point data. */
void BKE_ptcache_data_get(void **data, int type, int index, void *to);
@@ -197,7 +275,7 @@ int BKE_ptcache_get_continue_physics(void);
/******************* Allocate & free ***************/
struct PointCache *BKE_ptcache_add(struct ListBase *ptcaches);
-void BKE_ptache_free_mem(struct PointCache *cache);
+void BKE_ptcache_free_mem(struct ListBase *mem_cache);
void BKE_ptcache_free(struct PointCache *cache);
void BKE_ptcache_free_list(struct ListBase *ptcaches);
struct PointCache *BKE_ptcache_copy_list(struct ListBase *ptcaches_new, struct ListBase *ptcaches_old);
diff --git a/source/blender/blenkernel/BKE_sca.h b/source/blender/blenkernel/BKE_sca.h
index 22c4f39148a..1b8e61f136f 100644
--- a/source/blender/blenkernel/BKE_sca.h
+++ b/source/blender/blenkernel/BKE_sca.h
@@ -47,7 +47,6 @@ void unlink_actuators(struct ListBase *lb);
void free_actuator(struct bActuator *act);
void free_actuators(struct ListBase *lb);
-void free_text_controllers(struct Text *txt);
void free_sensor(struct bSensor *sens);
void free_sensors(struct ListBase *lb);
struct bSensor *copy_sensor(struct bSensor *sens);
diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h
index 12a13a2b50c..686fc265de0 100644
--- a/source/blender/blenkernel/BKE_scene.h
+++ b/source/blender/blenkernel/BKE_scene.h
@@ -84,7 +84,5 @@ int get_render_child_particle_number(struct RenderData *r, int num);
int get_render_shadow_samples(struct RenderData *r, int samples);
float get_render_aosss_error(struct RenderData *r, float error);
-void free_dome_warp_text(struct Text *txt);
-
#endif
diff --git a/source/blender/blenkernel/BKE_sculpt.h b/source/blender/blenkernel/BKE_sculpt.h
deleted file mode 100644
index 9e5647a8775..00000000000
--- a/source/blender/blenkernel/BKE_sculpt.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * The Original Code is Copyright (C) 2007 by Nicholas Bishop
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef BKE_SCULPT_H
-#define BKE_SCULPT_H
-
-struct MFace;
-struct MultireModifierData;
-struct MVert;
-struct Object;
-struct StrokeCache;
-
-typedef struct SculptSession {
- struct ProjVert *projverts;
-
- /* Mesh data (not copied) can come either directly from a Mesh, or from a MultiresDM */
- struct MultiresModifierData *multires; /* Special handling for multires meshes */
- struct MVert *mvert;
- struct MFace *mface;
- int totvert, totface;
- float *face_normals;
-
- /* Mesh connectivity */
- struct ListBase *fmap;
- struct IndexNode *fmap_mem;
- int fmap_size;
-
- /* Used temporarily per-stroke */
- float *vertexcosnos;
- ListBase damaged_rects;
- ListBase damaged_verts;
-
- /* Used to cache the render of the active texture */
- unsigned int texcache_side, *texcache, texcache_actual;
-
- /* Layer brush persistence between strokes */
- float (*mesh_co_orig)[3]; /* Copy of the mesh vertices' locations */
- float *layer_disps; /* Displacements for each vertex */
-
- struct SculptStroke *stroke;
- struct StrokeCache *cache;
-} SculptSession;
-
-void free_sculptsession(SculptSession **);
-
-#endif
diff --git a/source/blender/blenkernel/BKE_shrinkwrap.h b/source/blender/blenkernel/BKE_shrinkwrap.h
index eb0e3c4ef00..5b413ae4e44 100644
--- a/source/blender/blenkernel/BKE_shrinkwrap.h
+++ b/source/blender/blenkernel/BKE_shrinkwrap.h
@@ -115,9 +115,9 @@ typedef struct ShrinkwrapCalcData
int vgroup; //Vertex group num
struct DerivedMesh *target; //mesh we are shrinking to
- SpaceTransform local2target; //transform to move bettwem local and target space
+ SpaceTransform local2target; //transform to move between local and target space
- float keepDist; //Distance to kept from target (units are in local space)
+ float keepDist; //Distance to keep above target surface (units are in local space)
} ShrinkwrapCalcData;
diff --git a/source/blender/blenkernel/BKE_smoke.h b/source/blender/blenkernel/BKE_smoke.h
index 8dc38640e9a..0f8e9c5edf5 100644
--- a/source/blender/blenkernel/BKE_smoke.h
+++ b/source/blender/blenkernel/BKE_smoke.h
@@ -32,24 +32,15 @@
#ifndef BKE_SMOKE_H_
#define BKE_SMOKE_H_
+typedef float (*bresenham_callback) (float *result, float *input, int res[3], int *pixel, float *tRay, float correct);
+
void smokeModifier_do(struct SmokeModifierData *smd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, int useRenderParams, int isFinalCalc);
void smokeModifier_free (struct SmokeModifierData *smd);
void smokeModifier_reset(struct SmokeModifierData *smd);
+void smokeModifier_reset_turbulence(struct SmokeModifierData *smd);
void smokeModifier_createType(struct SmokeModifierData *smd);
-void smoke_set_tray(struct SmokeModifierData *smd, size_t index, float transparency);
-float smoke_get_tray(struct SmokeModifierData *smd, size_t index);
-float smoke_get_tvox(struct SmokeModifierData *smd, size_t index);
-void smoke_set_tvox(struct SmokeModifierData *smd, size_t index, float tvox);
-
-void smoke_set_bigtray(struct SmokeModifierData *smd, size_t index, float transparency);
-float smoke_get_bigtray(struct SmokeModifierData *smd, size_t index);
-float smoke_get_bigtvox(struct SmokeModifierData *smd, size_t index);
-void smoke_set_bigtvox(struct SmokeModifierData *smd, size_t index, float tvox);
-
long long smoke_get_mem_req(int xres, int yres, int zres, int amplify);
-void smoke_prepare_View(struct SmokeModifierData *smd, float *light);
-void smoke_prepare_bigView(struct SmokeModifierData *smd, float *light);
#endif /* BKE_SMOKE_H_ */
diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h
index 1dd90b4dbda..e9f6eb21e36 100644
--- a/source/blender/blenkernel/BKE_sound.h
+++ b/source/blender/blenkernel/BKE_sound.h
@@ -54,7 +54,9 @@ void sound_delete(struct bContext *C, struct bSound* sound);
void sound_cache(struct bSound* sound, int ignore);
-void sound_load(struct bSound* sound);
+void sound_delete_cache(struct bSound* sound);
+
+void sound_load(struct Main *main, struct bSound* sound);
void sound_free(struct bSound* sound);
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h
index d288c0b6516..bd14053d121 100644
--- a/source/blender/blenkernel/BKE_text.h
+++ b/source/blender/blenkernel/BKE_text.h
@@ -35,6 +35,7 @@
extern "C" {
#endif
+struct Main;
struct Text;
struct TextLine;
struct SpaceText;
@@ -46,6 +47,7 @@ struct Text* add_empty_text (char *name);
int reopen_text (struct Text *text);
struct Text* add_text (char *file, const char *relpath);
struct Text* copy_text (struct Text *ta);
+void unlink_text (struct Main *bmain, struct Text *text);
char* txt_to_buf (struct Text *text);
void txt_clean_text (struct Text *text);
diff --git a/source/blender/blenkernel/BKE_texture.h b/source/blender/blenkernel/BKE_texture.h
index a1600ce5473..a9862ba586b 100644
--- a/source/blender/blenkernel/BKE_texture.h
+++ b/source/blender/blenkernel/BKE_texture.h
@@ -40,6 +40,8 @@ struct ColorBand;
struct HaloRen;
struct TexMapping;
struct EnvMap;
+struct PointDensity;
+struct VoxelData;
/* in ColorBand struct */
#define MAXCOLORBAND 32
@@ -75,6 +77,16 @@ void BKE_free_envmap(struct EnvMap *env);
struct EnvMap *BKE_add_envmap(void);
struct EnvMap *BKE_copy_envmap(struct EnvMap *env);
+void BKE_free_pointdensitydata(struct PointDensity *pd);
+void BKE_free_pointdensity(struct PointDensity *pd);
+struct PointDensity *BKE_add_pointdensity(void);
+struct PointDensity *BKE_copy_pointdensity(struct PointDensity *pd);
+
+void BKE_free_voxeldatadata(struct VoxelData *vd);
+void BKE_free_voxeldata(struct VoxelData *vd);
+struct VoxelData *BKE_add_voxeldata(void);
+struct VoxelData *BKE_copy_voxeldata(struct VoxelData *vd);
+
int BKE_texture_dependsOnTime(const struct Tex *texture);
#endif
diff --git a/source/blender/blenkernel/BKE_utildefines.h b/source/blender/blenkernel/BKE_utildefines.h
index eba5032997d..c0ed8430177 100644
--- a/source/blender/blenkernel/BKE_utildefines.h
+++ b/source/blender/blenkernel/BKE_utildefines.h
@@ -115,6 +115,7 @@
#define VECSUB(v1,v2,v3) {*(v1)= *(v2) - *(v3); *(v1+1)= *(v2+1) - *(v3+1); *(v1+2)= *(v2+2) - *(v3+2);}
#define VECSUB2D(v1,v2,v3) {*(v1)= *(v2) - *(v3); *(v1+1)= *(v2+1) - *(v3+1);}
#define VECADDFAC(v1,v2,v3,fac) {*(v1)= *(v2) + *(v3)*(fac); *(v1+1)= *(v2+1) + *(v3+1)*(fac); *(v1+2)= *(v2+2) + *(v3+2)*(fac);}
+#define VECSUBFAC(v1,v2,v3,fac) {*(v1)= *(v2) - *(v3)*(fac); *(v1+1)= *(v2+1) - *(v3+1)*(fac); *(v1+2)= *(v2+2) - *(v3+2)*(fac);}
#define QUATADDFAC(v1,v2,v3,fac) {*(v1)= *(v2) + *(v3)*(fac); *(v1+1)= *(v2+1) + *(v3+1)*(fac); *(v1+2)= *(v2+2) + *(v3+2)*(fac); *(v1+3)= *(v2+3) + *(v3+3)*(fac);}
#define INPR(v1, v2) ( (v1)[0]*(v2)[0] + (v1)[1]*(v2)[1] + (v1)[2]*(v2)[2] )
@@ -200,5 +201,54 @@
#define SET_INT_IN_POINTER(i) ((void*)(intptr_t)(i))
#define GET_INT_FROM_POINTER(i) ((int)(intptr_t)(i))
+/*little array macro library. example of usage:
+
+int *arr = NULL;
+V_DECLARE(arr);
+int i;
+
+for (i=0; i<10; i++) {
+ V_GROW(arr);
+ arr[i] = something;
+}
+V_FREE(arr);
+
+arrays are buffered, using double-buffering (so on each reallocation,
+the array size is doubled). supposedly this should give good Big Oh
+behaviour, though it may not be the best in practice.
+*/
+
+#define V_DECLARE(vec) int _##vec##_count=0; void *_##vec##_tmp
+
+/*in the future, I plan on having V_DECLARE allocate stack memory it'll
+ use at first, and switch over to heap when it needs more. that'll mess
+ up cases where you'd want to use this API to build a dynamic list for
+ non-local use, so all such cases should use this macro.*/
+#define V_DYNDECLARE(vec) V_DECLARE(vec)
+
+/*this returns the entire size of the array, including any buffering.*/
+#define V_SIZE(vec) ((signed int)((vec)==NULL ? 0 : MEM_allocN_len(vec) / sizeof(*vec)))
+
+/*this returns the logical size of the array, not including buffering.*/
+#define V_COUNT(vec) _##vec##_count
+
+/*grow the array by one. zeroes the new elements.*/
+#define V_GROW(vec) \
+ V_SIZE(vec) > _##vec##_count ? _##vec##_count++ : \
+ ((_##vec##_tmp = MEM_callocN(sizeof(*vec)*(_##vec##_count*2+2), #vec " " __FILE__ " ")),\
+ (vec && memcpy(_##vec##_tmp, vec, sizeof(*vec) * _##vec##_count)),\
+ (vec && (MEM_freeN(vec),1)),\
+ (vec = _##vec##_tmp),\
+ _##vec##_count++)
+
+#define V_FREE(vec) if (vec) MEM_freeN(vec);
+
+/*resets the logical size of an array to zero, but doesn't
+ free the memory.*/
+#define V_RESET(vec) _##vec##_count=0
+
+/*set the count of the array*/
+#define V_SETCOUNT(vec, count) _##vec##_count = (count)
+
#endif
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index c1dfc2cf639..68aed2b0184 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -27,51 +27,57 @@
FILE(GLOB SRC intern/*.c)
SET(INC
- . ../../../intern/guardedalloc ../../../intern/memutil ../editors/include ../blenlib ../makesdna
- ../render/extern/include ../../../intern/decimation/extern
- ../imbuf ../avi ../../../intern/elbeem/extern ../../../intern/opennl/extern
- ../../../intern/iksolver/extern ../blenloader ../quicktime
- ../../../extern/bullet2/src
- ../nodes ../../../extern/glew/include ../gpu ../makesrna ../../../intern/smoke/extern
- ../../../intern/bsp/extern
- ../../../intern/audaspace/intern
- ${ZLIB_INC}
+ . ../../../intern/guardedalloc ../../../intern/memutil ../editors/include ../blenlib ../makesdna
+ ../render/extern/include ../../../intern/decimation/extern
+ ../imbuf ../avi ../../../intern/elbeem/extern ../../../intern/opennl/extern
+ ../../../intern/iksolver/extern ../blenloader
+ ../nodes ../../../extern/glew/include ../gpu ../makesrna ../../../intern/smoke/extern
+ ../../../intern/bsp/extern ../blenfont
+ ../../../intern/audaspace/intern
+ ../../../extern/lzo/minilzo
+ ../../../extern/lzma
+ ${ZLIB_INC}
)
+IF(WITH_BULLET)
+ SET(INC ${INC} ../../../extern/bullet2/src)
+ ADD_DEFINITIONS(-DUSE_BULLET)
+ENDIF(WITH_BULLET)
+
IF(WITH_OPENEXR)
- ADD_DEFINITIONS(-DWITH_OPENEXR)
+ ADD_DEFINITIONS(-DWITH_OPENEXR)
ENDIF(WITH_OPENEXR)
IF(WITH_OPENJPEG)
- ADD_DEFINITIONS(-DWITH_OPENJPEG)
+ ADD_DEFINITIONS(-DWITH_OPENJPEG)
ENDIF(WITH_OPENJPEG)
IF(WITH_DDS)
- ADD_DEFINITIONS(-DWITH_DDS)
+ ADD_DEFINITIONS(-DWITH_DDS)
ENDIF(WITH_DDS)
IF(WITH_QUICKTIME)
- SET(INC ${INC} ${QUICKTIME_INC})
- ADD_DEFINITIONS(-DWITH_QUICKTIME)
+ SET(INC ${INC} ../quicktime ${QUICKTIME_INC})
+ ADD_DEFINITIONS(-DWITH_QUICKTIME)
ENDIF(WITH_QUICKTIME)
IF(WITH_FFMPEG)
- SET(INC ${INC} ${FFMPEG_INC})
- ADD_DEFINITIONS(-DWITH_FFMPEG)
+ SET(INC ${INC} ${FFMPEG_INC})
+ ADD_DEFINITIONS(-DWITH_FFMPEG)
ENDIF(WITH_FFMPEG)
IF(WITH_PYTHON)
- SET(INC ${INC} ../python ${PYTHON_INC})
+ SET(INC ${INC} ../python ${PYTHON_INC})
ELSE(WITH_PYTHON)
- ADD_DEFINITIONS(-DDISABLE_PYTHON)
+ ADD_DEFINITIONS(-DDISABLE_PYTHON)
ENDIF(WITH_PYTHON)
IF(NOT WITH_ELBEEM)
- ADD_DEFINITIONS(-DDISABLE_ELBEEM)
+ ADD_DEFINITIONS(-DDISABLE_ELBEEM)
ENDIF(NOT WITH_ELBEEM)
IF(WIN32)
- SET(INC ${INC} ${PTHREADS_INC})
+ SET(INC ${INC} ${PTHREADS_INC})
ENDIF(WIN32)
BLENDERLIB(bf_blenkernel "${SRC}" "${INC}")
diff --git a/source/blender/blenkernel/SConscript b/source/blender/blenkernel/SConscript
index 6772cccbda6..1f42390504d 100644
--- a/source/blender/blenkernel/SConscript
+++ b/source/blender/blenkernel/SConscript
@@ -3,7 +3,7 @@ Import ('env')
sources = env.Glob('intern/*.c')
-incs = '. #/intern/guardedalloc #/intern/memutil ../editors/include ../blenlib ../makesdna'
+incs = '. #/intern/guardedalloc #/intern/memutil ../editors/include ../blenlib ../blenfont ../makesdna'
incs += ' ../render/extern/include #/intern/decimation/extern ../makesrna'
incs += ' ../imbuf ../avi #/intern/elbeem/extern ../nodes'
incs += ' #/intern/iksolver/extern ../blenloader'
@@ -11,6 +11,8 @@ incs += ' #/extern/bullet2/src'
incs += ' #/intern/opennl/extern #/intern/bsp/extern'
incs += ' ../gpu #/extern/glew/include'
incs += ' #/intern/smoke/extern'
+incs += ' #/extern/lzo/minilzo'
+incs += ' #/extern/lzma'
incs += ' #/intern/audaspace/intern'
incs += ' ' + env['BF_OPENGL_INC']
@@ -52,7 +54,7 @@ if env['WITH_BF_QUICKTIME']:
incs += ' ' + env['BF_QUICKTIME_INC']
if env['WITH_BF_BULLET']:
- defs.append('WITH_BULLET')
+ defs.append('USE_BULLET')
if env['BF_NO_ELBEEM']:
defs.append('DISABLE_ELBEEM')
@@ -63,4 +65,4 @@ if env['WITH_BF_LCMS']:
if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
incs += ' ' + env['BF_PTHREADS_INC']
-env.BlenderLib ( libname = 'bf_blenkernel', sources = sources, includes = Split(incs), defines = defs, libtype=['core'], priority = [165] )
+env.BlenderLib ( libname = 'bf_blenkernel', sources = sources, includes = Split(incs), defines = defs, libtype=['core','player'], priority = [166,25] )
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 84cccd8b939..43b9a63a2c1 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -2077,7 +2077,7 @@ static void clear_mesh_caches(Object *ob)
static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask)
{
Object *obact = scene->basact?scene->basact->object:NULL;
- int editing = paint_facesel_test(ob)|(ob && ob->mode & OB_MODE_PARTICLE_EDIT);
+ int editing = paint_facesel_test(ob);
int needMapping = editing && (ob==obact);
float min[3], max[3];
diff --git a/source/blender/blenkernel/intern/Makefile b/source/blender/blenkernel/intern/Makefile
index 60ffdc78726..6c2edc9e25f 100644
--- a/source/blender/blenkernel/intern/Makefile
+++ b/source/blender/blenkernel/intern/Makefile
@@ -51,6 +51,7 @@ CPPFLAGS += -I../../imbuf
CPPFLAGS += -I../../blenlib
CPPFLAGS += -I../../blenloader
CPPFLAGS += -I../../python
+CPPFLAGS += -I../../blenfont
# also avi is used
CPPFLAGS += -I../../avi
CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
@@ -89,6 +90,10 @@ CPPFLAGS += -I$(NAN_BULLET2)/include
CPPFLAGS += -I$(NAN_FREETYPE)/include
CPPFLAGS += -I$(NAN_FREETYPE)/include/freetype2
+# lzo and lzma, for pointcache
+CPPFLAGS += -I$(NAN_LZO)/minilzo
+CPPFLAGS += -I$(NAN_LZMA)
+
ifeq ($(WITH_FFMPEG),true)
CPPFLAGS += -DWITH_FFMPEG
CPPFLAGS += $(NAN_FFMPEGCFLAGS)
@@ -110,3 +115,4 @@ ifeq ($(WITH_QUICKTIME), true)
CPPFLAGS += -I../../quicktime
CPPFLAGS += -DWITH_QUICKTIME
endif
+
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index f4d4eb1cc9c..47de044ea25 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -410,8 +410,9 @@ bActionGroup *action_groups_find_named (bAction *act, const char name[])
bPoseChannel *get_pose_channel(const bPose *pose, const char *name)
{
bPoseChannel *chan;
-
- if (pose==NULL) return NULL;
+
+ if (ELEM(NULL, pose, name) || (name[0] == 0))
+ return NULL;
for (chan=pose->chanbase.first; chan; chan=chan->next) {
if (chan->name[0] == name[0]) {
@@ -837,14 +838,15 @@ short action_has_motion(const bAction *act)
}
/* Calculate the extents of given action */
-void calc_action_range(const bAction *act, float *start, float *end, int incl_hidden)
+void calc_action_range(const bAction *act, float *start, float *end, short incl_modifiers)
{
FCurve *fcu;
float min=999999999.0f, max=-999999999.0f;
- short foundvert=0;
+ short foundvert=0, foundmod=0;
if (act) {
for (fcu= act->curves.first; fcu; fcu= fcu->next) {
+ /* if curve has keyframes, consider them first */
if (fcu->totvert) {
float nmin, nmax;
@@ -857,10 +859,53 @@ void calc_action_range(const bAction *act, float *start, float *end, int incl_hi
foundvert= 1;
}
+
+ /* if incl_modifiers is enabled, need to consider modifiers too
+ * - only really care about the last modifier
+ */
+ if ((incl_modifiers) && (fcu->modifiers.last)) {
+ FModifier *fcm= fcu->modifiers.last;
+
+ /* only use the maximum sensible limits of the modifiers if they are more extreme */
+ switch (fcm->type) {
+ case FMODIFIER_TYPE_LIMITS: /* Limits F-Modifier */
+ {
+ FMod_Limits *fmd= (FMod_Limits *)fcm->data;
+
+ if (fmd->flag & FCM_LIMIT_XMIN) {
+ min= MIN2(min, fmd->rect.xmin);
+ }
+ if (fmd->flag & FCM_LIMIT_XMAX) {
+ max= MAX2(max, fmd->rect.xmax);
+ }
+ }
+ break;
+
+ case FMODIFIER_TYPE_CYCLES: /* Cycles F-Modifier */
+ {
+ FMod_Cycles *fmd= (FMod_Cycles *)fcm->data;
+
+ if (fmd->before_mode != FCM_EXTRAPOLATE_NONE)
+ min= MINAFRAMEF;
+ if (fmd->after_mode != FCM_EXTRAPOLATE_NONE)
+ max= MAXFRAMEF;
+ }
+ break;
+
+ // TODO: function modifier may need some special limits
+
+ default: /* all other standard modifiers are on the infinite range... */
+ min= MINAFRAMEF;
+ max= MAXFRAMEF;
+ break;
+ }
+
+ foundmod= 1;
+ }
}
}
- if (foundvert) {
+ if (foundvert || foundmod) {
if(min==max) max+= 1.0f;
*start= min;
*end= max;
diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c
index 6c1b8eb9000..8cb88cdb786 100644
--- a/source/blender/blenkernel/intern/anim.c
+++ b/source/blender/blenkernel/intern/anim.c
@@ -87,15 +87,16 @@ void free_path(Path *path)
void calc_curvepath(Object *ob)
{
BevList *bl;
- BevPoint *bevp, *bevpn, *bevpfirst, *bevplast, *tempbevp;
+ BevPoint *bevp, *bevpn, *bevpfirst, *bevplast;
+ PathPoint *pp;
Curve *cu;
Nurb *nu;
Path *path;
- float *fp, *dist, *maxdist, x, y, z;
+ float *fp, *dist, *maxdist, xyz[3];
float fac, d=0, fac1, fac2;
int a, tot, cycl=0;
- float *ft;
+
/* in a path vertices are with equal differences: path->len = number of verts */
/* NOW WITH BEVELCURVE!!! */
@@ -132,19 +133,12 @@ void calc_curvepath(Object *ob)
*fp= 0;
for(a=0; a<tot; a++) {
fp++;
- if(cycl && a==tot-1) {
- x= bevpfirst->x - bevp->x;
- y= bevpfirst->y - bevp->y;
- z= bevpfirst->z - bevp->z;
- }
- else {
- tempbevp = bevp+1;
- x= (tempbevp)->x - bevp->x;
- y= (tempbevp)->y - bevp->y;
- z= (tempbevp)->z - bevp->z;
- }
- *fp= *(fp-1)+ (float)sqrt(x*x+y*y+z*z);
+ if(cycl && a==tot-1)
+ VecSubf(xyz, bevpfirst->vec, bevp->vec);
+ else
+ VecSubf(xyz, (bevp+1)->vec, bevp->vec);
+ *fp= *(fp-1)+VecLength(xyz);
bevp++;
}
@@ -152,7 +146,7 @@ void calc_curvepath(Object *ob)
/* the path verts in path->data */
/* now also with TILT value */
- ft= path->data = (float *)MEM_callocN(16*path->len, "pathdata");
+ pp= path->data = (PathPoint *)MEM_callocN(sizeof(PathPoint)*4*path->len, "pathdata"); // XXX - why *4? - in 2.4x each element was 4 and the size was 16, so better leave for now - Campbell
bevp= bevpfirst;
bevpn= bevp+1;
@@ -182,13 +176,13 @@ void calc_curvepath(Object *ob)
fac1= fac2/fac1;
fac2= 1.0f-fac1;
- ft[0]= fac1*bevp->x+ fac2*(bevpn)->x;
- ft[1]= fac1*bevp->y+ fac2*(bevpn)->y;
- ft[2]= fac1*bevp->z+ fac2*(bevpn)->z;
- ft[3]= fac1*bevp->alfa+ fac2*(bevpn)->alfa;
+ VecLerpf(pp->vec, bevp->vec, bevpn->vec, fac2);
+ pp->vec[3]= fac1*bevp->alfa + fac2*bevpn->alfa;
+ pp->radius= fac1*bevp->radius + fac2*bevpn->radius;
+ QuatInterpol(pp->quat, bevp->quat, bevpn->quat, fac2);
+ NormalQuat(pp->quat);
- ft+= 4;
-
+ pp++;
}
MEM_freeN(dist);
@@ -212,13 +206,14 @@ int interval_test(int min, int max, int p1, int cycl)
/* warning, *vec needs FOUR items! */
/* ctime is normalized range <0-1> */
-int where_on_path(Object *ob, float ctime, float *vec, float *dir) /* returns OK */
+int where_on_path(Object *ob, float ctime, float *vec, float *dir, float *quat, float *radius) /* returns OK */
{
Curve *cu;
Nurb *nu;
BevList *bl;
Path *path;
- float *fp, *p0, *p1, *p2, *p3, fac;
+ PathPoint *pp, *p0, *p1, *p2, *p3;
+ float fac;
float data[4];
int cycl=0, s0, s1, s2, s3;
@@ -229,7 +224,7 @@ int where_on_path(Object *ob, float ctime, float *vec, float *dir) /* returns OK
return 0;
}
path= cu->path;
- fp= path->data;
+ pp= path->data;
/* test for cyclic */
bl= cu->bev.first;
@@ -248,19 +243,19 @@ int where_on_path(Object *ob, float ctime, float *vec, float *dir) /* returns OK
s2= interval_test(0, path->len-1-cycl, s1+1, cycl);
s3= interval_test(0, path->len-1-cycl, s1+2, cycl);
- p0= fp + 4*s0;
- p1= fp + 4*s1;
- p2= fp + 4*s2;
- p3= fp + 4*s3;
+ p0= pp + s0;
+ p1= pp + s1;
+ p2= pp + s2;
+ p3= pp + s3;
/* note, commented out for follow constraint */
//if(cu->flag & CU_FOLLOW) {
- set_afgeleide_four_ipo(1.0f-fac, data, KEY_BSPLINE);
+ key_curve_tangent_weights(1.0f-fac, data, KEY_BSPLINE);
- dir[0]= data[0]*p0[0] + data[1]*p1[0] + data[2]*p2[0] + data[3]*p3[0] ;
- dir[1]= data[0]*p0[1] + data[1]*p1[1] + data[2]*p2[1] + data[3]*p3[1] ;
- dir[2]= data[0]*p0[2] + data[1]*p1[2] + data[2]*p2[2] + data[3]*p3[2] ;
+ dir[0]= data[0]*p0->vec[0] + data[1]*p1->vec[0] + data[2]*p2->vec[0] + data[3]*p3->vec[0] ;
+ dir[1]= data[0]*p0->vec[1] + data[1]*p1->vec[1] + data[2]*p2->vec[1] + data[3]*p3->vec[1] ;
+ dir[2]= data[0]*p0->vec[2] + data[1]*p1->vec[2] + data[2]*p2->vec[2] + data[3]*p3->vec[2] ;
/* make compatible with vectoquat */
dir[0]= -dir[0];
@@ -271,16 +266,35 @@ int where_on_path(Object *ob, float ctime, float *vec, float *dir) /* returns OK
nu= cu->nurb.first;
/* make sure that first and last frame are included in the vectors here */
- if((nu->type & 7)==CU_POLY) set_four_ipo(1.0f-fac, data, KEY_LINEAR);
- else if((nu->type & 7)==CU_BEZIER) set_four_ipo(1.0f-fac, data, KEY_LINEAR);
- else if(s0==s1 || p2==p3) set_four_ipo(1.0f-fac, data, KEY_CARDINAL);
- else set_four_ipo(1.0f-fac, data, KEY_BSPLINE);
-
- vec[0]= data[0]*p0[0] + data[1]*p1[0] + data[2]*p2[0] + data[3]*p3[0] ;
- vec[1]= data[0]*p0[1] + data[1]*p1[1] + data[2]*p2[1] + data[3]*p3[1] ;
- vec[2]= data[0]*p0[2] + data[1]*p1[2] + data[2]*p2[2] + data[3]*p3[2] ;
+ if(nu->type == CU_POLY) key_curve_position_weights(1.0f-fac, data, KEY_LINEAR);
+ else if(nu->type == CU_BEZIER) key_curve_position_weights(1.0f-fac, data, KEY_LINEAR);
+ else if(s0==s1 || p2==p3) key_curve_position_weights(1.0f-fac, data, KEY_CARDINAL);
+ else key_curve_position_weights(1.0f-fac, data, KEY_BSPLINE);
+
+ vec[0]= data[0]*p0->vec[0] + data[1]*p1->vec[0] + data[2]*p2->vec[0] + data[3]*p3->vec[0] ; /* X */
+ vec[1]= data[0]*p0->vec[1] + data[1]*p1->vec[1] + data[2]*p2->vec[1] + data[3]*p3->vec[1] ; /* Y */
+ vec[2]= data[0]*p0->vec[2] + data[1]*p1->vec[2] + data[2]*p2->vec[2] + data[3]*p3->vec[2] ; /* Z */
+ vec[3]= data[0]*p0->vec[3] + data[1]*p1->vec[3] + data[2]*p2->vec[3] + data[3]*p3->vec[3] ; /* Tilt, should not be needed since we have quat still used */
+ /* Need to verify the quat interpolation is correct - XXX */
+
+ if (quat) {
+ float totfac, q1[4], q2[4];
+
+ totfac= data[0]+data[1];
+ QuatInterpol(q1, p0->quat, p1->quat, data[0] / totfac);
+ NormalQuat(q1);
+
+ totfac= data[2]+data[3];
+ QuatInterpol(q2, p2->quat, p3->quat, data[2] / totfac);
+ NormalQuat(q2);
+
+ totfac = data[0]+data[1]+data[2]+data[3];
+ QuatInterpol(quat, q1, q2, (data[0]+data[1]) / totfac);
+ NormalQuat(quat);
+ }
- vec[3]= data[0]*p0[3] + data[1]*p1[3] + data[2]*p2[3] + data[3]*p3[3] ;
+ if(radius)
+ *radius= data[0]*p0->radius + data[1]*p1->radius + data[2]*p2->radius + data[3]*p3->radius;
return 1;
}
diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c
index 204935cc38d..2d6a97c48ae 100644
--- a/source/blender/blenkernel/intern/anim_sys.c
+++ b/source/blender/blenkernel/intern/anim_sys.c
@@ -204,15 +204,35 @@ AnimData *BKE_copy_animdata (AnimData *adt)
return dadt;
}
+/* Make Local -------------------------------------------- */
+
+static void make_local_strips(ListBase *strips)
+{
+ NlaStrip *strip;
+
+ for(strip=strips->first; strip; strip=strip->next) {
+ if(strip->act) make_local_action(strip->act);
+ if(strip->remap && strip->remap->target) make_local_action(strip->remap->target);
+
+ make_local_strips(&strip->strips);
+ }
+}
+
+void BKE_animdata_make_local(AnimData *adt)
+{
+ NlaTrack *nlt;
+
+ if(adt->action) make_local_action(adt->action);
+ if(adt->tmpact) make_local_action(adt->tmpact);
+ if(adt->remap && adt->remap->target) make_local_action(adt->remap->target);
+
+ for(nlt=adt->nla_tracks.first; nlt; nlt=nlt->next)
+ make_local_strips(&nlt->strips);
+}
+
/* *********************************** */
/* KeyingSet API */
-/* NOTES:
- * It is very likely that there will be two copies of the api - one for internal use,
- * and one 'operator' based wrapper of the internal API, which should allow for access
- * from Python/scripts so that riggers can automate the creation of KeyingSets for their rigs.
- */
-
/* Finding Tools --------------------------- */
/* Find the first path that matches the given criteria */
@@ -245,7 +265,7 @@ KS_Path *BKE_keyingset_find_destination (KeyingSet *ks, ID *id, const char group
if ((ksp->rna_path==0) || strcmp(rna_path, ksp->rna_path))
eq_path= 0;
- /* index */
+ /* index - need to compare whole-array setting too... */
if (ksp->array_index != array_index)
eq_index= 0;
@@ -276,7 +296,7 @@ KeyingSet *BKE_keyingset_add (ListBase *list, const char name[], short flag, sho
if (name)
BLI_snprintf(ks->name, 64, name);
else
- strcpy(ks->name, "Keying Set");
+ strcpy(ks->name, "KeyingSet");
ks->flag= flag;
ks->keyingflag= keyingflag;
@@ -285,7 +305,7 @@ KeyingSet *BKE_keyingset_add (ListBase *list, const char name[], short flag, sho
BLI_addtail(list, ks);
/* make sure KeyingSet has a unique name (this helps with identification) */
- BLI_uniquename(list, ks, "Keying Set", ' ', offsetof(KeyingSet, name), 64);
+ BLI_uniquename(list, ks, "KeyingSet", '.', offsetof(KeyingSet, name), 64);
/* return new KeyingSet for further editing */
return ks;
@@ -299,18 +319,25 @@ void BKE_keyingset_add_destination (KeyingSet *ks, ID *id, const char group_name
KS_Path *ksp;
/* sanity checks */
- if ELEM(NULL, ks, rna_path)
+ if ELEM(NULL, ks, rna_path) {
+ printf("ERROR: no Keying Set and/or RNA Path to add destination with \n");
return;
+ }
/* ID is optional for relative KeyingSets, but is necessary for absolute KeyingSets */
if (id == NULL) {
- if (ks->flag & KEYINGSET_ABSOLUTE)
+ if (ks->flag & KEYINGSET_ABSOLUTE) {
+ printf("ERROR: No ID provided for absolute destination. \n");
return;
+ }
}
/* don't add if there is already a matching KS_Path in the KeyingSet */
- if (BKE_keyingset_find_destination(ks, id, group_name, rna_path, array_index, groupmode))
+ if (BKE_keyingset_find_destination(ks, id, group_name, rna_path, array_index, groupmode)) {
+ if (G.f & G_DEBUG)
+ printf("ERROR: destination already exists in Keying Set \n");
return;
+ }
/* allocate a new KeyingSet Path */
ksp= MEM_callocN(sizeof(KS_Path), "KeyingSet Path");
@@ -440,19 +467,19 @@ static short animsys_write_rna_setting (PointerRNA *ptr, char *path, int array_i
switch (RNA_property_type(prop))
{
case PROP_BOOLEAN:
- if (RNA_property_array_length(prop))
+ if (RNA_property_array_length(&new_ptr, prop))
RNA_property_boolean_set_index(&new_ptr, prop, array_index, (int)value);
else
RNA_property_boolean_set(&new_ptr, prop, (int)value);
break;
case PROP_INT:
- if (RNA_property_array_length(prop))
+ if (RNA_property_array_length(&new_ptr, prop))
RNA_property_int_set_index(&new_ptr, prop, array_index, (int)value);
else
RNA_property_int_set(&new_ptr, prop, (int)value);
break;
case PROP_FLOAT:
- if (RNA_property_array_length(prop))
+ if (RNA_property_array_length(&new_ptr, prop))
RNA_property_float_set_index(&new_ptr, prop, array_index, value);
else
RNA_property_float_set(&new_ptr, prop, value);
@@ -1177,19 +1204,19 @@ void nladata_flush_channels (ListBase *channels)
switch (RNA_property_type(prop))
{
case PROP_BOOLEAN:
- if (RNA_property_array_length(prop))
+ if (RNA_property_array_length(ptr, prop))
RNA_property_boolean_set_index(ptr, prop, array_index, (int)value);
else
RNA_property_boolean_set(ptr, prop, (int)value);
break;
case PROP_INT:
- if (RNA_property_array_length(prop))
+ if (RNA_property_array_length(ptr, prop))
RNA_property_int_set_index(ptr, prop, array_index, (int)value);
else
RNA_property_int_set(ptr, prop, (int)value);
break;
case PROP_FLOAT:
- if (RNA_property_array_length(prop))
+ if (RNA_property_array_length(ptr, prop))
RNA_property_float_set_index(ptr, prop, array_index, value);
else
RNA_property_float_set(ptr, prop, value);
@@ -1263,7 +1290,7 @@ static void animsys_evaluate_nla (PointerRNA *ptr, AnimData *adt, float ctime)
dummy_strip.act= adt->action;
dummy_strip.remap= adt->remap;
- // FIXME: what happens when we want to included F-Modifier access?
+ /* action range is calculated taking F-Modifiers into account (which making new strips doesn't do due to the troublesome nature of that) */
calc_action_range(dummy_strip.act, &dummy_strip.actstart, &dummy_strip.actend, 1);
dummy_strip.start = dummy_strip.actstart;
dummy_strip.end = (IS_EQ(dummy_strip.actstart, dummy_strip.actend)) ? (dummy_strip.actstart + 1.0f): (dummy_strip.actend);
@@ -1423,7 +1450,6 @@ void BKE_animsys_evaluate_animdata (ID *id, AnimData *adt, float ctime, short re
* 'local' (i.e. belonging in the nearest ID-block that setting is related to, not a
* standard 'root') block are overridden by a larger 'user'
*/
-// FIXME?: we currently go over entire 'main' database...
void BKE_animsys_evaluate_all_animation (Main *main, float ctime)
{
ID *id;
@@ -1447,8 +1473,11 @@ void BKE_animsys_evaluate_all_animation (Main *main, float ctime)
* when there are no actions, don't go over database and loop over heaps of datablocks,
* which should ultimately be empty, since it is not possible for now to have any animation
* without some actions, and drivers wouldn't get affected by any state changes
+ *
+ * however, if there are some curves, we will need to make sure that their 'ctime' property gets
+ * set correctly, so this optimisation must be skipped in that case...
*/
- if (main->action.first == NULL) {
+ if ((main->action.first == NULL) && (main->curve.first == NULL)) {
if (G.f & G_DEBUG)
printf("\tNo Actions, so no animation needs to be evaluated...\n");
@@ -1482,6 +1511,7 @@ void BKE_animsys_evaluate_all_animation (Main *main, float ctime)
* value of the curve gets set in case there's no animation for that
* - it needs to be set before animation is evaluated just so that
* animation can successfully override...
+ * - it shouldn't get set when calculating drivers...
*/
for (id= main->curve.first; id; id= id->next) {
AnimData *adt= BKE_animdata_from_id(id);
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 7b894d79b45..c880925aa94 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -130,7 +130,6 @@ void free_bones (bArmature *arm)
void free_armature(bArmature *arm)
{
if (arm) {
- /* unlink_armature(arm);*/
free_bones(arm);
/* free editmode data */
@@ -667,10 +666,10 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest)
if(bone->segments > MAX_BBONE_SUBDIV)
bone->segments= MAX_BBONE_SUBDIV;
- forward_diff_bezier(0.0, h1[0], h2[0], 0.0, data[0], MAX_BBONE_SUBDIV, 4);
- forward_diff_bezier(0.0, h1[1], length + h2[1], length, data[0]+1, MAX_BBONE_SUBDIV, 4);
- forward_diff_bezier(0.0, h1[2], h2[2], 0.0, data[0]+2, MAX_BBONE_SUBDIV, 4);
- forward_diff_bezier(roll1, roll1 + 0.390464f*(roll2-roll1), roll2 - 0.390464f*(roll2-roll1), roll2, data[0]+3, MAX_BBONE_SUBDIV, 4);
+ forward_diff_bezier(0.0, h1[0], h2[0], 0.0, data[0], MAX_BBONE_SUBDIV, 4*sizeof(float));
+ forward_diff_bezier(0.0, h1[1], length + h2[1], length, data[0]+1, MAX_BBONE_SUBDIV, 4*sizeof(float));
+ forward_diff_bezier(0.0, h1[2], h2[2], 0.0, data[0]+2, MAX_BBONE_SUBDIV, 4*sizeof(float));
+ forward_diff_bezier(roll1, roll1 + 0.390464f*(roll2-roll1), roll2 - 0.390464f*(roll2-roll1), roll2, data[0]+3, MAX_BBONE_SUBDIV, 4*sizeof(float));
equalize_bezier(data[0], bone->segments); // note: does stride 4!
@@ -1987,10 +1986,14 @@ void chan_calc_mat(bPoseChannel *chan)
/* get scaling matrix */
SizeToMat3(chan->size, smat);
- /* rotations may either be quats or eulers (no rotation modes for now...) */
- if (chan->rotmode) {
- /* euler rotations (will cause gimble lock... no rotation order to solve that yet) */
- EulToMat3(chan->eul, rmat);
+ /* rotations may either be quats, eulers (with various rotation orders), or axis-angle */
+ if (chan->rotmode > 0) {
+ /* euler rotations (will cause gimble lock, but this can be alleviated a bit with rotation orders) */
+ EulOToMat3(chan->eul, chan->rotmode, rmat);
+ }
+ else if (chan->rotmode == PCHAN_ROT_AXISANGLE) {
+ /* axis-angle - stored in quaternion data, but not really that great for 3D-changing orientations */
+ AxisAngleToMat3(&chan->quat[1], chan->quat[0], rmat);
}
else {
/* quats are normalised before use to eliminate scaling issues */
diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index 746dc6c59cc..f261b020717 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -626,8 +626,7 @@ void BKE_write_undo(bContext *C, char *name)
}
}
-/* 1= an undo, -1 is a redo. we have to make sure 'curundo' remains at current situation
- * Note, ALWAYS call sound_initialize_sounds after BKE_undo_step() */
+/* 1= an undo, -1 is a redo. we have to make sure 'curundo' remains at current situation */
void BKE_undo_step(bContext *C, int step)
{
diff --git a/source/blender/blenkernel/intern/boids.c b/source/blender/blenkernel/intern/boids.c
index d8926fc5753..18f065b59d9 100644
--- a/source/blender/blenkernel/intern/boids.c
+++ b/source/blender/blenkernel/intern/boids.c
@@ -74,14 +74,15 @@ static int rule_goal_avoid(BoidRule *rule, BoidBrainData *bbd, BoidValues *val,
BoidSettings *boids = bbd->part->boids;
ParticleEffectorCache *ec;
Object *priority_ob = NULL;
+ BoidParticle *bpa = pa->boid;
float vec[3] = {0.0f, 0.0f, 0.0f}, loc[3] = {0.0f, 0.0f, 0.0f};
float mul = (rule->type == eBoidRuleType_Avoid ? 1.0 : -1.0);
- float priority = 0.0f, len;
+ float priority = 0.0f, len = 0.0f;
int ret = 0;
/* first find out goal/predator with highest priority */
/* if rule->ob specified use it */
- if(gabr->ob && (rule->type != eBoidRuleType_Goal || gabr->ob != pa->stick_ob)) {
+ if(gabr->ob && (rule->type != eBoidRuleType_Goal || gabr->ob != bpa->ground)) {
PartDeflect *pd = gabr->ob->pd;
float vec_to_part[3];
@@ -104,7 +105,7 @@ static int rule_goal_avoid(BoidRule *rule, BoidBrainData *bbd, BoidValues *val,
PartDeflect *pd = eob->pd;
/* skip current object */
- if(rule->type == eBoidRuleType_Goal && eob == pa->stick_ob)
+ if(rule->type == eBoidRuleType_Goal && eob == bpa->ground)
continue;
if(pd->forcefield == PFIELD_BOID && mul * pd->f_strength > 0.0f) {
@@ -169,10 +170,10 @@ static int rule_goal_avoid(BoidRule *rule, BoidBrainData *bbd, BoidValues *val,
VECCOPY(bbd->goal_nor, nor);
}
}
- else if(rule->type == eBoidRuleType_Avoid && pa->boid->mode == eBoidMode_Climbing &&
+ else if(rule->type == eBoidRuleType_Avoid && bpa->data.mode == eBoidMode_Climbing &&
priority > 2.0f * gabr->fear_factor) {
/* detach from surface and try to fly away from danger */
- VECCOPY(vec_to_part, pa->r_ve);
+ VECCOPY(vec_to_part, bpa->gravity);
VecMulf(vec_to_part, -1.0f);
}
@@ -205,6 +206,7 @@ static int rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues *
KDTreeNearest *ptn = NULL;
ParticleEffectorCache *ec;
ParticleTarget *pt;
+ BoidParticle *bpa = pa->boid;
float vec[3] = {0.0f, 0.0f, 0.0f}, loc[3] = {0.0f, 0.0f, 0.0f};
float co1[3], vel1[3], co2[3], vel2[3];
float len, t, inp, t_min = 2.0f;
@@ -231,7 +233,7 @@ static int rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues *
Object *eob = ec->ob;
/* don't check with current ground object */
- if(eob == pa->stick_ob)
+ if(eob == bpa->ground)
continue;
col.md = ( CollisionModifierData * ) ( modifiers_findByType ( eob, eModifierType_Collision ) );
@@ -558,18 +560,19 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va
}
static int rule_average_speed(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, ParticleData *pa)
{
+ BoidParticle *bpa = pa->boid;
BoidRuleAverageSpeed *asbr = (BoidRuleAverageSpeed*)rule;
float vec[3] = {0.0f, 0.0f, 0.0f};
if(asbr->wander > 0.0f) {
/* abuse pa->r_ave for wandering */
- pa->r_ave[0] += asbr->wander * (-1.0f + 2.0f * BLI_frand());
- pa->r_ave[1] += asbr->wander * (-1.0f + 2.0f * BLI_frand());
- pa->r_ave[2] += asbr->wander * (-1.0f + 2.0f * BLI_frand());
+ bpa->wander[0] += asbr->wander * (-1.0f + 2.0f * BLI_frand());
+ bpa->wander[1] += asbr->wander * (-1.0f + 2.0f * BLI_frand());
+ bpa->wander[2] += asbr->wander * (-1.0f + 2.0f * BLI_frand());
- Normalize(pa->r_ave);
+ Normalize(bpa->wander);
- VECCOPY(vec, pa->r_ave);
+ VECCOPY(vec, bpa->wander);
QuatMulVecf(pa->prev_state.rot, vec);
@@ -614,7 +617,8 @@ static int rule_fight(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Parti
KDTreeNearest *ptn = NULL;
ParticleTarget *pt;
ParticleData *epars;
- ParticleData *enemy_pa;
+ ParticleData *enemy_pa = NULL;
+ BoidParticle *bpa;
/* friends & enemies */
float closest_enemy[3] = {0.0f,0.0f,0.0f};
float closest_dist = fbr->distance + 1.0f;
@@ -624,8 +628,10 @@ static int rule_fight(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Parti
/* calculate own group strength */
int neighbors = BLI_kdtree_range_search(bbd->psys->tree, fbr->distance, pa->prev_state.co, NULL, &ptn);
- for(n=0; n<neighbors; n++)
- health += bbd->psys->particles[ptn[n].index].boid->health;
+ for(n=0; n<neighbors; n++) {
+ bpa = bbd->psys->particles[ptn[n].index].boid;
+ health += bpa->data.health;
+ }
f_strength += bbd->part->boids->strength * health;
@@ -642,7 +648,8 @@ static int rule_fight(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Parti
health = 0.0f;
for(n=0; n<neighbors; n++) {
- health += epars[ptn[n].index].boid->health;
+ bpa = epars[ptn[n].index].boid;
+ health += bpa->data.health;
if(n==0 && pt->mode==PTARGET_MODE_ENEMY && ptn[n].dist < closest_dist) {
VECCOPY(closest_enemy, ptn[n].co);
@@ -674,7 +681,8 @@ static int rule_fight(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Parti
/* must face enemy to fight */
if(Inpf(pa->prev_state.ave, enemy_dir)>0.5f) {
- enemy_pa->boid->health -= bbd->part->boids->strength * bbd->timestep * ((1.0f-bbd->part->boids->accuracy)*damage + bbd->part->boids->accuracy);
+ bpa = enemy_pa->boid;
+ bpa->data.health -= bbd->part->boids->strength * bbd->timestep * ((1.0f-bbd->part->boids->accuracy)*damage + bbd->part->boids->accuracy);
}
}
else {
@@ -683,7 +691,8 @@ static int rule_fight(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Parti
}
/* check if boid doesn't want to fight */
- if(pa->boid->health/bbd->part->boids->health * bbd->part->boids->aggression < e_strength / f_strength) {
+ bpa = pa->boid;
+ if(bpa->data.health/bbd->part->boids->health * bbd->part->boids->aggression < e_strength / f_strength) {
/* decide to flee */
if(closest_dist < fbr->flee_distance * fbr->distance) {
VecMulf(bbd->wanted_co, -1.0f);
@@ -721,18 +730,20 @@ static boid_rule_cb boid_rules[] = {
static void set_boid_values(BoidValues *val, BoidSettings *boids, ParticleData *pa)
{
- if(ELEM(pa->boid->mode, eBoidMode_OnLand, eBoidMode_Climbing)) {
- val->max_speed = boids->land_max_speed * pa->boid->health/boids->health;
+ BoidParticle *bpa = pa->boid;
+
+ if(ELEM(bpa->data.mode, eBoidMode_OnLand, eBoidMode_Climbing)) {
+ val->max_speed = boids->land_max_speed * bpa->data.health/boids->health;
val->max_acc = boids->land_max_acc * val->max_speed;
- val->max_ave = boids->land_max_ave * M_PI * pa->boid->health/boids->health;
+ val->max_ave = boids->land_max_ave * M_PI * bpa->data.health/boids->health;
val->min_speed = 0.0f; /* no minimum speed on land */
val->personal_space = boids->land_personal_space;
- val->jump_speed = boids->land_jump_speed * pa->boid->health/boids->health;
+ val->jump_speed = boids->land_jump_speed * bpa->data.health/boids->health;
}
else {
- val->max_speed = boids->air_max_speed * pa->boid->health/boids->health;
+ val->max_speed = boids->air_max_speed * bpa->data.health/boids->health;
val->max_acc = boids->air_max_acc * val->max_speed;
- val->max_ave = boids->air_max_ave * M_PI * pa->boid->health/boids->health;
+ val->max_ave = boids->air_max_ave * M_PI * bpa->data.health/boids->health;
val->min_speed = boids->air_min_speed * boids->air_max_speed;
val->personal_space = boids->air_personal_space;
val->jump_speed = 0.0f; /* no jumping in air */
@@ -740,11 +751,13 @@ static void set_boid_values(BoidValues *val, BoidSettings *boids, ParticleData *
}
static Object *boid_find_ground(BoidBrainData *bbd, ParticleData *pa, float *ground_co, float *ground_nor)
{
- if(pa->boid->mode == eBoidMode_Climbing) {
+ BoidParticle *bpa = pa->boid;
+
+ if(bpa->data.mode == eBoidMode_Climbing) {
SurfaceModifierData *surmd = NULL;
float x[3], v[3];
- surmd = (SurfaceModifierData *)modifiers_findByType ( pa->stick_ob, eModifierType_Surface );
+ surmd = (SurfaceModifierData *)modifiers_findByType ( bpa->ground, eModifierType_Surface );
/* take surface velocity into account */
effector_find_co(bbd->scene, pa->state.co, surmd, NULL, NULL, x, NULL, v, NULL);
@@ -753,7 +766,7 @@ static Object *boid_find_ground(BoidBrainData *bbd, ParticleData *pa, float *gro
/* get actual position on surface */
effector_find_co(bbd->scene, x, surmd, NULL, NULL, ground_co, ground_nor, NULL, NULL);
- return pa->stick_ob;
+ return bpa->ground;
}
else {
float zvec[3] = {0.0f, 0.0f, 2000.0f};
@@ -803,13 +816,15 @@ static Object *boid_find_ground(BoidBrainData *bbd, ParticleData *pa, float *gro
}
static int boid_rule_applies(ParticleData *pa, BoidSettings *boids, BoidRule *rule)
{
+ BoidParticle *bpa = pa->boid;
+
if(rule==NULL)
return 0;
- if(ELEM(pa->boid->mode, eBoidMode_OnLand, eBoidMode_Climbing) && rule->flag & BOIDRULE_ON_LAND)
+ if(ELEM(bpa->data.mode, eBoidMode_OnLand, eBoidMode_Climbing) && rule->flag & BOIDRULE_ON_LAND)
return 1;
- if(pa->boid->mode==eBoidMode_InAir && rule->flag & BOIDRULE_IN_AIR)
+ if(bpa->data.mode==eBoidMode_InAir && rule->flag & BOIDRULE_IN_AIR)
return 1;
return 0;
@@ -835,12 +850,13 @@ void boids_precalc_rules(ParticleSettings *part, float cfra)
}
static void boid_climb(BoidSettings *boids, ParticleData *pa, float *surface_co, float *surface_nor)
{
+ BoidParticle *bpa = pa->boid;
float nor[3], vel[3];
VECCOPY(nor, surface_nor);
- /* gather apparent gravity to r_ve */
- VECADDFAC(pa->r_ve, pa->r_ve, surface_nor, -1.0);
- Normalize(pa->r_ve);
+ /* gather apparent gravity */
+ VECADDFAC(bpa->gravity, bpa->gravity, surface_nor, -1.0);
+ Normalize(bpa->gravity);
/* raise boid it's size from surface */
VecMulf(nor, pa->size * boids->height);
@@ -877,16 +893,17 @@ static int apply_boid_rule(BoidBrainData *bbd, BoidRule *rule, BoidValues *val,
}
static BoidState *get_boid_state(BoidSettings *boids, ParticleData *pa) {
BoidState *state = boids->states.first;
+ BoidParticle *bpa = pa->boid;
for(; state; state=state->next) {
- if(state->id==pa->boid->state_id)
+ if(state->id==bpa->data.state_id)
return state;
}
/* for some reason particle isn't at a valid state */
state = boids->states.first;
if(state)
- pa->boid->state_id = state->id;
+ bpa->data.state_id = state->id;
return state;
}
@@ -902,9 +919,11 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa)
BoidSettings *boids = bbd->part->boids;
BoidValues val;
BoidState *state = get_boid_state(boids, pa);
+ BoidParticle *bpa = pa->boid;
+ int rand;
//BoidCondition *cond;
- if(pa->boid->health <= 0.0f) {
+ if(bpa->data.health <= 0.0f) {
pa->alive = PARS_DYING;
return;
}
@@ -922,7 +941,9 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa)
bbd->wanted_co[0]=bbd->wanted_co[1]=bbd->wanted_co[2]=bbd->wanted_speed=0.0f;
/* create random seed for every particle & frame */
- BLI_srandom(bbd->psys->seed + p + (int)bbd->cfra + (int)(1000*pa->r_rot[0]));
+ BLI_srandom(bbd->psys->seed + p);
+ rand = BLI_rand();
+ BLI_srandom((int)bbd->cfra + rand);
set_boid_values(&val, bbd->part->boids, pa);
@@ -939,7 +960,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa)
case eBoidRulesetType_Random:
{
/* use random rule for each particle (allways same for same particle though) */
- rule = BLI_findlink(&state->rules, (int)(1000.0f * pa->r_rot[1]) % BLI_countlist(&state->rules));
+ rule = BLI_findlink(&state->rules, rand % BLI_countlist(&state->rules));
apply_boid_rule(bbd, rule, &val, pa, -1.0);
}
@@ -969,7 +990,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa)
}
/* decide on jumping & liftoff */
- if(pa->boid->mode == eBoidMode_OnLand) {
+ if(bpa->data.mode == eBoidMode_OnLand) {
/* fuzziness makes boids capable of misjudgement */
float mul = 1.0 + state->rule_fuzziness;
@@ -983,7 +1004,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa)
Normalize2(cvel);
if(Inp2f(cvel, dir) > 0.95 / mul)
- pa->boid->mode = eBoidMode_Liftoff;
+ bpa->data.mode = eBoidMode_Liftoff;
}
else if(val.jump_speed > 0.0f) {
float jump_v[3];
@@ -1036,7 +1057,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa)
if(jump) {
VECCOPY(pa->prev_state.vel, jump_v);
- pa->boid->mode = eBoidMode_Falling;
+ bpa->data.mode = eBoidMode_Falling;
}
}
}
@@ -1045,6 +1066,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa)
void boid_body(BoidBrainData *bbd, ParticleData *pa)
{
BoidSettings *boids = bbd->part->boids;
+ BoidParticle *bpa = pa->boid;
BoidValues val;
float acc[3] = {0.0f, 0.0f, 0.0f}, tan_acc[3], nor_acc[3];
float dvec[3], bvec[3];
@@ -1066,10 +1088,10 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
pa_mass*=pa->size;
/* if boids can't fly they fall to the ground */
- if((boids->options & BOID_ALLOW_FLIGHT)==0 && ELEM(pa->boid->mode, eBoidMode_OnLand, eBoidMode_Climbing)==0 && bbd->part->acc[2] != 0.0f)
- pa->boid->mode = eBoidMode_Falling;
+ if((boids->options & BOID_ALLOW_FLIGHT)==0 && ELEM(bpa->data.mode, eBoidMode_OnLand, eBoidMode_Climbing)==0 && bbd->part->acc[2] != 0.0f)
+ bpa->data.mode = eBoidMode_Falling;
- if(pa->boid->mode == eBoidMode_Falling) {
+ if(bpa->data.mode == eBoidMode_Falling) {
/* Falling boids are only effected by gravity. */
acc[2] = bbd->part->acc[2];
}
@@ -1079,14 +1101,14 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
float level = landing_level + 1.0f;
float new_vel[3];
- if(pa->boid->mode == eBoidMode_Liftoff) {
- pa->boid->mode = eBoidMode_InAir;
- pa->stick_ob = boid_find_ground(bbd, pa, ground_co, ground_nor);
+ if(bpa->data.mode == eBoidMode_Liftoff) {
+ bpa->data.mode = eBoidMode_InAir;
+ bpa->ground = boid_find_ground(bbd, pa, ground_co, ground_nor);
}
- else if(pa->boid->mode == eBoidMode_InAir && boids->options & BOID_ALLOW_LAND) {
+ else if(bpa->data.mode == eBoidMode_InAir && boids->options & BOID_ALLOW_LAND) {
/* auto-leveling & landing if close to ground */
- pa->stick_ob = boid_find_ground(bbd, pa, ground_co, ground_nor);
+ bpa->ground = boid_find_ground(bbd, pa, ground_co, ground_nor);
/* level = how many particle sizes above ground */
level = (pa->prev_state.co[2] - ground_co[2])/(2.0f * pa->size) - 0.5;
@@ -1097,7 +1119,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
if(level < 1.0f) {
bbd->wanted_co[0] = bbd->wanted_co[1] = bbd->wanted_co[2] = 0.0f;
bbd->wanted_speed = 0.0f;
- pa->boid->mode = eBoidMode_Falling;
+ bpa->data.mode = eBoidMode_Falling;
}
else if(level < landing_level) {
bbd->wanted_speed *= (level - 1.0f)/landing_level;
@@ -1188,7 +1210,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
/* account for effectors */
do_effectors(p, pa, &pa->state, bbd->scene, bbd->ob, bbd->psys, pa->state.co, force, tvel, bbd->dfra, bbd->cfra);
- if(ELEM(pa->boid->mode, eBoidMode_OnLand, eBoidMode_Climbing)) {
+ if(ELEM(bpa->data.mode, eBoidMode_OnLand, eBoidMode_Climbing)) {
float length = Normalize(force);
length = MAX2(0.0f, length - boids->land_stick_force);
@@ -1199,8 +1221,8 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
VecAddf(acc, acc, force);
/* store smoothed acceleration for nice banking etc. */
- VECADDFAC(pa->boid->acc, pa->boid->acc, acc, dtime);
- VecMulf(pa->boid->acc, 1.0f / (1.0f + dtime));
+ VECADDFAC(bpa->data.acc, bpa->data.acc, acc, dtime);
+ VecMulf(bpa->data.acc, 1.0f / (1.0f + dtime));
/* integrate new location & velocity */
@@ -1218,32 +1240,32 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
VECADDFAC(pa->state.vel, pa->state.vel, acc, dtime);
- if(pa->boid->mode != eBoidMode_InAir)
- pa->stick_ob = boid_find_ground(bbd, pa, ground_co, ground_nor);
+ if(bpa->data.mode != eBoidMode_InAir)
+ bpa->ground = boid_find_ground(bbd, pa, ground_co, ground_nor);
/* change modes, constrain movement & keep track of down vector */
- switch(pa->boid->mode) {
+ switch(bpa->data.mode) {
case eBoidMode_InAir:
{
float grav[3] = {0.0f, 0.0f, bbd->part->acc[2] < 0.0f ? -1.0f : 0.0f};
/* don't take forward acceleration into account (better banking) */
- if(Inpf(pa->boid->acc, pa->state.vel) > 0.0f) {
- Projf(dvec, pa->boid->acc, pa->state.vel);
- VecSubf(dvec, pa->boid->acc, dvec);
+ if(Inpf(bpa->data.acc, pa->state.vel) > 0.0f) {
+ Projf(dvec, bpa->data.acc, pa->state.vel);
+ VecSubf(dvec, bpa->data.acc, dvec);
}
else {
- VECCOPY(dvec, pa->boid->acc);
+ VECCOPY(dvec, bpa->data.acc);
}
- /* gather apparent gravity to r_ve */
- VECADDFAC(pa->r_ve, grav, dvec, -boids->banking);
- Normalize(pa->r_ve);
+ /* gather apparent gravity */
+ VECADDFAC(bpa->gravity, grav, dvec, -boids->banking);
+ Normalize(bpa->gravity);
/* stick boid on goal when close enough */
if(bbd->goal_ob && boid_goal_signed_dist(pa->state.co, bbd->goal_co, bbd->goal_nor) <= pa->size * boids->height) {
- pa->boid->mode = eBoidMode_Climbing;
- pa->stick_ob = bbd->goal_ob;
+ bpa->data.mode = eBoidMode_Climbing;
+ bpa->ground = bbd->goal_ob;
boid_find_ground(bbd, pa, ground_co, ground_nor);
boid_climb(boids, pa, ground_co, ground_nor);
}
@@ -1251,7 +1273,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
else if(boids->options & BOID_ALLOW_LAND && pa->state.co[2] <= ground_co[2] + pa->size * boids->height) {
pa->state.co[2] = ground_co[2] + pa->size * boids->height;
pa->state.vel[2] = 0.0f;
- pa->boid->mode = eBoidMode_OnLand;
+ bpa->data.mode = eBoidMode_OnLand;
}
break;
}
@@ -1259,15 +1281,15 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
{
float grav[3] = {0.0f, 0.0f, bbd->part->acc[2] < 0.0f ? -1.0f : 0.0f};
- /* gather apparent gravity to r_ve */
- VECADDFAC(pa->r_ve, pa->r_ve, grav, dtime);
- Normalize(pa->r_ve);
+ /* gather apparent gravity */
+ VECADDFAC(bpa->gravity, bpa->gravity, grav, dtime);
+ Normalize(bpa->gravity);
if(boids->options & BOID_ALLOW_LAND) {
/* stick boid on goal when close enough */
if(bbd->goal_ob && boid_goal_signed_dist(pa->state.co, bbd->goal_co, bbd->goal_nor) <= pa->size * boids->height) {
- pa->boid->mode = eBoidMode_Climbing;
- pa->stick_ob = bbd->goal_ob;
+ bpa->data.mode = eBoidMode_Climbing;
+ bpa->ground = bbd->goal_ob;
boid_find_ground(bbd, pa, ground_co, ground_nor);
boid_climb(boids, pa, ground_co, ground_nor);
}
@@ -1275,14 +1297,14 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
else if(pa->state.co[2] <= ground_co[2] + 1.01 * pa->size * boids->height){
pa->state.co[2] = ground_co[2] + pa->size * boids->height;
pa->state.vel[2] = 0.0f;
- pa->boid->mode = eBoidMode_OnLand;
+ bpa->data.mode = eBoidMode_OnLand;
}
/* if we're falling, can fly and want to go upwards lets fly */
else if(boids->options & BOID_ALLOW_FLIGHT && bbd->wanted_co[2] > 0.0f)
- pa->boid->mode = eBoidMode_InAir;
+ bpa->data.mode = eBoidMode_InAir;
}
else
- pa->boid->mode = eBoidMode_InAir;
+ bpa->data.mode = eBoidMode_InAir;
break;
}
case eBoidMode_Climbing:
@@ -1308,14 +1330,14 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
{
/* stick boid on goal when close enough */
if(bbd->goal_ob && boid_goal_signed_dist(pa->state.co, bbd->goal_co, bbd->goal_nor) <= pa->size * boids->height) {
- pa->boid->mode = eBoidMode_Climbing;
- pa->stick_ob = bbd->goal_ob;
+ bpa->data.mode = eBoidMode_Climbing;
+ bpa->ground = bbd->goal_ob;
boid_find_ground(bbd, pa, ground_co, ground_nor);
boid_climb(boids, pa, ground_co, ground_nor);
}
/* ground is too far away so boid falls */
else if(pa->state.co[2]-ground_co[2] > 1.1 * pa->size * boids->height)
- pa->boid->mode = eBoidMode_Falling;
+ bpa->data.mode = eBoidMode_Falling;
else {
/* constrain to surface */
pa->state.co[2] = ground_co[2] + pa->size * boids->height;
@@ -1329,17 +1351,17 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
VECCOPY(grav, ground_nor);
VecMulf(grav, -1.0f);
- Projf(dvec, pa->boid->acc, pa->state.vel);
- VecSubf(dvec, pa->boid->acc, dvec);
+ Projf(dvec, bpa->data.acc, pa->state.vel);
+ VecSubf(dvec, bpa->data.acc, dvec);
- /* gather apparent gravity to r_ve */
- VECADDFAC(pa->r_ve, grav, dvec, -boids->banking);
- Normalize(pa->r_ve);
+ /* gather apparent gravity */
+ VECADDFAC(bpa->gravity, grav, dvec, -boids->banking);
+ Normalize(bpa->gravity);
}
else {
- /* gather negative surface normal to r_ve */
- VECADDFAC(pa->r_ve, pa->r_ve, ground_nor, -1.0f);
- Normalize(pa->r_ve);
+ /* gather negative surface normal */
+ VECADDFAC(bpa->gravity, bpa->gravity, ground_nor, -1.0f);
+ Normalize(bpa->gravity);
}
break;
}
@@ -1347,29 +1369,29 @@ 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(pa->boid->mode!=eBoidMode_Falling && VecLength(pa->state.vel) > 0.1*pa->size) {
+ if(bpa->data.mode!=eBoidMode_Falling && VecLength(pa->state.vel) > 0.1*pa->size) {
VECCOPY(pa->state.ave, pa->state.vel);
Normalize(pa->state.ave);
}
/* apply damping */
- if(ELEM(pa->boid->mode, eBoidMode_OnLand, eBoidMode_Climbing))
+ if(ELEM(bpa->data.mode, eBoidMode_OnLand, eBoidMode_Climbing))
VecMulf(pa->state.vel, 1.0f - 0.2f*bbd->part->dampfac);
/* calculate rotation matrix based on forward & down vectors */
- if(pa->boid->mode == eBoidMode_InAir) {
+ if(bpa->data.mode == eBoidMode_InAir) {
VECCOPY(mat[0], pa->state.ave);
- Projf(dvec, pa->r_ve, pa->state.ave);
- VecSubf(mat[2], pa->r_ve, dvec);
+ Projf(dvec, bpa->gravity, pa->state.ave);
+ VecSubf(mat[2], bpa->gravity, dvec);
Normalize(mat[2]);
}
else {
- Projf(dvec, pa->state.ave, pa->r_ve);
+ Projf(dvec, pa->state.ave, bpa->gravity);
VecSubf(mat[0], pa->state.ave, dvec);
Normalize(mat[0]);
- VECCOPY(mat[2], pa->r_ve);
+ VECCOPY(mat[2], bpa->gravity);
}
VecMulf(mat[2], -1.0f);
Crossf(mat[1], mat[2], mat[0]);
diff --git a/source/blender/blenkernel/intern/booleanops.c b/source/blender/blenkernel/intern/booleanops.c
index eb3aefe7ee6..5f0697f06ce 100644
--- a/source/blender/blenkernel/intern/booleanops.c
+++ b/source/blender/blenkernel/intern/booleanops.c
@@ -589,7 +589,7 @@ int NewBooleanMesh(Scene *scene, Base *base, Base *base_select, int int_op_type)
MEM_freeN(mat);
/* update dag */
- DAG_object_flush_update(scene, ob_new, OB_RECALC_DATA);
+ DAG_id_flush_update(&ob_new->id, OB_RECALC_DATA);
return 1;
}
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 612f6d2051d..bce4e1120be 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -75,6 +75,8 @@ Brush *add_brush(const char *name)
brush->alpha= 0.2f;
brush->size= 25;
brush->spacing= 10.0f;
+ brush->smooth_stroke_radius= 75;
+ brush->smooth_stroke_factor= 0.9;
brush->rate= 0.1f;
brush->innerradius= 0.5f;
brush->clone.alpha= 0.5;
@@ -407,23 +409,6 @@ float brush_sample_falloff(Brush *brush, float dist)
return 0.0f;
}
-float brush_sample_falloff_noalpha(Brush *brush, float dist)
-{
- float outer, inner;
-
- outer = brush->size >> 1;
- inner = outer*brush->innerradius;
-
- if (dist <= inner) {
- return 1.0f;
- }
- else if ((dist < outer) && (inner < outer)) {
- return 1.0f - sqrt((dist - inner)/(outer - inner));
- }
- else
- return 0.0f;
-}
-
void brush_sample_tex(Brush *brush, float *xy, float *rgba)
{
MTex *mtex= brush->mtex[brush->texact];
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 706eece108c..b20da0962a7 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -1288,6 +1288,7 @@ typedef struct MultiresDM {
CDDerivedMesh cddm;
MultiresModifierData *mmd;
+ int local_mmd;
int lvl, totlvl;
float (*orco)[3];
@@ -1297,7 +1298,7 @@ typedef struct MultiresDM {
IndexNode *vert_face_map_mem, *vert_edge_map_mem;
int *face_offsets;
- Mesh *me;
+ Object *ob;
int modified;
void (*update)(DerivedMesh*);
@@ -1309,14 +1310,19 @@ static void MultiresDM_release(DerivedMesh *dm)
int mvert_layer;
/* Before freeing, need to update the displacement map */
- if(dm->needsFree && mrdm->modified)
- mrdm->update(dm);
+ if(dm->needsFree && mrdm->modified) {
+ /* Check that mmd still exists */
+ if(!mrdm->local_mmd && BLI_findindex(&mrdm->ob->modifiers, mrdm->mmd) < 0)
+ mrdm->mmd = NULL;
+ if(mrdm->mmd)
+ mrdm->update(dm);
+ }
/* If the MVert data is being used as the sculpt undo store, don't free it */
mvert_layer = CustomData_get_layer_index(&dm->vertData, CD_MVERT);
if(mvert_layer != -1) {
CustomDataLayer *cd = &dm->vertData.layers[mvert_layer];
- if(cd->data == mrdm->mmd->undo_verts)
+ if(mrdm->mmd && cd->data == mrdm->mmd->undo_verts)
cd->flag |= CD_FLAG_NOFREE;
}
@@ -1348,7 +1354,8 @@ DerivedMesh *MultiresDM_new(MultiresSubsurf *ms, DerivedMesh *orig, int numVerts
dm = &mrdm->cddm.dm;
mrdm->mmd = ms->mmd;
- mrdm->me = ms->me;
+ mrdm->ob = ms->ob;
+ mrdm->local_mmd = ms->local_mmd;
if(dm) {
MDisps *disps;
@@ -1391,7 +1398,12 @@ DerivedMesh *MultiresDM_new(MultiresSubsurf *ms, DerivedMesh *orig, int numVerts
Mesh *MultiresDM_get_mesh(DerivedMesh *dm)
{
- return ((MultiresDM*)dm)->me;
+ return get_mesh(((MultiresDM*)dm)->ob);
+}
+
+Object *MultiresDM_get_object(DerivedMesh *dm)
+{
+ return ((MultiresDM*)dm)->ob;
}
void *MultiresDM_get_orco(DerivedMesh *dm)
@@ -1428,10 +1440,11 @@ void MultiresDM_set_update(DerivedMesh *dm, void (*update)(DerivedMesh*))
ListBase *MultiresDM_get_vert_face_map(DerivedMesh *dm)
{
MultiresDM *mrdm = (MultiresDM*)dm;
+ Mesh *me = mrdm->ob->data;
if(!mrdm->vert_face_map)
- create_vert_face_map(&mrdm->vert_face_map, &mrdm->vert_face_map_mem, mrdm->me->mface,
- mrdm->me->totvert, mrdm->me->totface);
+ create_vert_face_map(&mrdm->vert_face_map, &mrdm->vert_face_map_mem, me->mface,
+ me->totvert, me->totface);
return mrdm->vert_face_map;
}
@@ -1439,10 +1452,11 @@ ListBase *MultiresDM_get_vert_face_map(DerivedMesh *dm)
ListBase *MultiresDM_get_vert_edge_map(DerivedMesh *dm)
{
MultiresDM *mrdm = (MultiresDM*)dm;
+ Mesh *me = mrdm->ob->data;
if(!mrdm->vert_edge_map)
- create_vert_edge_map(&mrdm->vert_edge_map, &mrdm->vert_edge_map_mem, mrdm->me->medge,
- mrdm->me->totvert, mrdm->me->totedge);
+ create_vert_edge_map(&mrdm->vert_edge_map, &mrdm->vert_edge_map_mem, me->medge,
+ me->totvert, me->totedge);
return mrdm->vert_edge_map;
}
@@ -1450,6 +1464,7 @@ ListBase *MultiresDM_get_vert_edge_map(DerivedMesh *dm)
int *MultiresDM_get_face_offsets(DerivedMesh *dm)
{
MultiresDM *mrdm = (MultiresDM*)dm;
+ Mesh *me = mrdm->ob->data;
int i, accum = 0;
if(!mrdm->face_offsets) {
@@ -1457,11 +1472,11 @@ int *MultiresDM_get_face_offsets(DerivedMesh *dm)
int area = len * len;
int t = 1 + len * 3 + area * 3, q = t + len + area;
- mrdm->face_offsets = MEM_callocN(sizeof(int) * mrdm->me->totface, "mrdm face offsets");
- for(i = 0; i < mrdm->me->totface; ++i) {
+ mrdm->face_offsets = MEM_callocN(sizeof(int) * me->totface, "mrdm face offsets");
+ for(i = 0; i < me->totface; ++i) {
mrdm->face_offsets[i] = accum;
- accum += (mrdm->me->mface[i].v4 ? q : t);
+ accum += (me->mface[i].v4 ? q : t);
}
}
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 3acaaecb1e8..d25c329f49f 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -347,7 +347,7 @@ void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr)
BKE_ptcache_id_from_cloth(&pid, ob, clmd);
// don't do anything as long as we're in editmode!
- if(pid.cache->flag & PTCACHE_BAKE_EDIT_ACTIVE)
+ if(pid.cache->edit && ob->mode & OB_MODE_PARTICLE_EDIT)
return;
BKE_ptcache_id_clear(&pid, PTCACHE_CLEAR_AFTER, framenr);
@@ -496,23 +496,32 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
if(!do_init_cloth(ob, clmd, result, framenr))
return result;
+ if(framenr == startframe) {
+ BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
+ do_init_cloth(ob, clmd, result, framenr);
+ cache->simframe= framenr;
+ cache->flag |= PTCACHE_SIMULATION_VALID;
+ cache->flag &= ~PTCACHE_REDO_NEEDED;
+ return result;
+ }
+
/* try to read from cache */
cache_result = BKE_ptcache_read_cache(&pid, (float)framenr, scene->r.frs_sec);
if(cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED) {
- cache->flag |= PTCACHE_SIMULATION_VALID;
- cache->simframe= framenr;
-
implicit_set_positions(clmd);
cloth_to_object (ob, clmd, result);
+ cache->simframe= framenr;
+ cache->flag |= PTCACHE_SIMULATION_VALID;
+
+ if(cache_result == PTCACHE_READ_INTERPOLATED && cache->flag & PTCACHE_REDO_NEEDED)
+ BKE_ptcache_write_cache(&pid, framenr);
+
return result;
}
else if(cache_result==PTCACHE_READ_OLD) {
- BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_FREE);
-
implicit_set_positions(clmd);
-
cache->flag |= PTCACHE_SIMULATION_VALID;
}
else if(ob->id.lib || (cache->flag & PTCACHE_BAKED)) {
@@ -523,38 +532,25 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
return result;
}
- if(framenr == startframe) {
- if(cache->flag & PTCACHE_REDO_NEEDED) {
- BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
- do_init_cloth(ob, clmd, result, framenr);
- }
- cache->flag |= PTCACHE_SIMULATION_VALID;
- cache->simframe= framenr;
-
- /* don't write cache on first frame, but on second frame write
- * cache for frame 1 and 2 */
- }
- else {
- /* if on second frame, write cache for first frame */
- if(cache->simframe == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact==0))
- BKE_ptcache_write_cache(&pid, startframe);
-
- clmd->sim_parms->timescale *= framenr - cache->simframe;
+ /* if on second frame, write cache for first frame */
+ if(cache->simframe == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact==0))
+ BKE_ptcache_write_cache(&pid, startframe);
- /* do simulation */
- cache->flag |= PTCACHE_SIMULATION_VALID;
- cache->simframe= framenr;
+ clmd->sim_parms->timescale *= framenr - cache->simframe;
- if(!do_step_cloth(ob, clmd, result, framenr)) {
- cache->flag &= ~PTCACHE_SIMULATION_VALID;
- cache->simframe= 0;
- cache->last_exact= 0;
- }
- else
- BKE_ptcache_write_cache(&pid, framenr);
+ /* do simulation */
+ cache->flag |= PTCACHE_SIMULATION_VALID;
+ cache->simframe= framenr;
- cloth_to_object (ob, clmd, result);
+ if(!do_step_cloth(ob, clmd, result, framenr)) {
+ cache->flag &= ~PTCACHE_SIMULATION_VALID;
+ cache->simframe= 0;
+ cache->last_exact= 0;
}
+ else
+ BKE_ptcache_write_cache(&pid, framenr);
+
+ cloth_to_object (ob, clmd, result);
return result;
}
diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c
index c122145c98f..37e9c93a108 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -591,7 +591,7 @@ CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, BVHTreeOverlap
ClothModifierData *clmd = ( ClothModifierData * ) md1;
CollisionModifierData *collmd = ( CollisionModifierData * ) md2;
MFace *face1=NULL, *face2 = NULL;
-#ifdef WITH_BULLET
+#ifdef USE_BULLET
ClothVertex *verts1 = clmd->clothObject->verts;
#endif
double distance = 0;
@@ -669,7 +669,7 @@ CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, BVHTreeOverlap
break;
}
-#ifdef WITH_BULLET
+#ifdef USE_BULLET
// calc distance + normal
distance = plNearestPoints (
verts1[collpair->ap1].txold, verts1[collpair->ap2].txold, verts1[collpair->ap3].txold, collmd->current_x[collpair->bp1].co, collmd->current_x[collpair->bp2].co, collmd->current_x[collpair->bp3].co, collpair->pa,collpair->pb,collpair->vector );
diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c
index 26f9245abc7..8cd64ae2ece 100644
--- a/source/blender/blenkernel/intern/colortools.c
+++ b/source/blender/blenkernel/intern/colortools.c
@@ -502,8 +502,8 @@ static void curvemap_make_table(CurveMap *cuma, rctf *clipr)
for(a=0; a<cuma->totpoint-1; a++, fp += 2*CM_RESOL) {
correct_bezpart(bezt[a].vec[1], bezt[a].vec[2], bezt[a+1].vec[0], bezt[a+1].vec[1]);
- forward_diff_bezier(bezt[a].vec[1][0], bezt[a].vec[2][0], bezt[a+1].vec[0][0], bezt[a+1].vec[1][0], fp, CM_RESOL-1, 2);
- forward_diff_bezier(bezt[a].vec[1][1], bezt[a].vec[2][1], bezt[a+1].vec[0][1], bezt[a+1].vec[1][1], fp+1, CM_RESOL-1, 2);
+ forward_diff_bezier(bezt[a].vec[1][0], bezt[a].vec[2][0], bezt[a+1].vec[0][0], bezt[a+1].vec[1][0], fp, CM_RESOL-1, 2*sizeof(float));
+ forward_diff_bezier(bezt[a].vec[1][1], bezt[a].vec[2][1], bezt[a+1].vec[0][1], bezt[a+1].vec[1][1], fp+1, CM_RESOL-1, 2*sizeof(float));
}
/* store first and last handle for extrapolation, unit length */
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 88e73a00ba7..e5c0b3947de 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -121,6 +121,7 @@ bConstraintOb *constraints_make_evalob (Scene *scene, Object *ob, void *subdata,
if (ob) {
cob->ob = ob;
cob->type = datatype;
+ cob->rotOrder = EULER_ORDER_DEFAULT; // TODO: when objects have rotation order too, use that
Mat4CpyMat4(cob->matrix, ob->obmat);
}
else
@@ -137,6 +138,15 @@ bConstraintOb *constraints_make_evalob (Scene *scene, Object *ob, void *subdata,
cob->pchan = (bPoseChannel *)subdata;
cob->type = datatype;
+ if (cob->pchan->rotmode > 0) {
+ /* should be some type of Euler order */
+ cob->rotOrder= cob->pchan->rotmode;
+ }
+ else {
+ /* Quats, so eulers should just use default order */
+ cob->rotOrder= EULER_ORDER_DEFAULT;
+ }
+
/* matrix in world-space */
Mat4MulMat4(cob->matrix, cob->pchan->pose_mat, ob->obmat);
}
@@ -664,6 +674,7 @@ static void default_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstrain
* (Hopefully all compilers will be happy with the lines with just a space on them. Those are
* really just to help this code easier to read)
*/
+// TODO: cope with getting rotation order...
#define SINGLETARGET_GET_TARS(con, datatar, datasubtarget, ct, list) \
{ \
ct= MEM_callocN(sizeof(bConstraintTarget), "tempConstraintTarget"); \
@@ -687,6 +698,7 @@ static void default_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstrain
* (Hopefully all compilers will be happy with the lines with just a space on them. Those are
* really just to help this code easier to read)
*/
+// TODO: cope with getting rotation order...
#define SINGLETARGETNS_GET_TARS(con, datatar, ct, list) \
{ \
ct= MEM_callocN(sizeof(bConstraintTarget), "tempConstraintTarget"); \
@@ -795,11 +807,11 @@ static void childof_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta
/* extract components of both matrices */
VECCOPY(loc, ct->matrix[3]);
- Mat4ToEul(ct->matrix, eul);
+ Mat4ToEulO(ct->matrix, eul, ct->rotOrder);
Mat4ToSize(ct->matrix, size);
VECCOPY(loco, invmat[3]);
- Mat4ToEul(invmat, eulo);
+ Mat4ToEulO(invmat, eulo, cob->rotOrder);
Mat4ToSize(invmat, sizo);
/* disable channels not enabled */
@@ -814,8 +826,8 @@ static void childof_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta
if (!(data->flag & CHILDOF_SIZEZ)) size[2]= sizo[2]= 1.0f;
/* make new target mat and offset mat */
- LocEulSizeToMat4(ct->matrix, loc, eul, size);
- LocEulSizeToMat4(invmat, loco, eulo, sizo);
+ LocEulOSizeToMat4(ct->matrix, loc, eul, size, ct->rotOrder);
+ LocEulOSizeToMat4(invmat, loco, eulo, sizo, cob->rotOrder);
/* multiply target (parent matrix) by offset (parent inverse) to get
* the effect of the parent that will be exherted on the owner
@@ -1150,7 +1162,7 @@ static void followpath_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr
if (VALID_CONS_TARGET(ct)) {
Curve *cu= ct->tar->data;
- float q[4], vec[4], dir[3], quat[4], x1;
+ float q[4], vec[4], dir[3], quat[4], radius, x1;
float totmat[4][4];
float curvetime;
@@ -1162,21 +1174,30 @@ static void followpath_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr
*/
/* only happens on reload file, but violates depsgraph still... fix! */
- if (cu->path==NULL || cu->path->data==NULL)
+ if (cu->path==NULL || cu->path->data==NULL)
makeDispListCurveTypes(cob->scene, ct->tar, 0);
if (cu->path && cu->path->data) {
- curvetime= bsystem_time(cob->scene, ct->tar, (float)ctime, 0.0) - data->offset;
-
-#if 0 // XXX old animation system
- if (calc_ipo_spec(cu->ipo, CU_SPEED, &curvetime)==0) {
- curvetime /= cu->pathlen;
+ if ((data->followflag & FOLLOWPATH_STATIC) == 0) {
+ /* animated position along curve depending on time */
+ curvetime= bsystem_time(cob->scene, ct->tar, ctime, 0.0) - data->offset;
+
+ /* ctime is now a proper var setting of Curve which gets set by Animato like any other var that's animated,
+ * but this will only work if it actually is animated...
+ *
+ * we firstly calculate the modulus of cu->ctime/cu->pathlen to clamp ctime within the 0.0 to 1.0 times pathlen
+ * range, then divide this (the modulus) by pathlen to get a value between 0.0 and 1.0
+ */
+ curvetime= fmod(cu->ctime, cu->pathlen) / cu->pathlen;
CLAMP(curvetime, 0.0, 1.0);
}
-#endif // XXX old animation system
+ else {
+ /* fixed position along curve */
+ curvetime= data->offset; // XXX might need a more sensible value
+ }
- if ( where_on_path(ct->tar, curvetime, vec, dir) ) {
- if (data->followflag) {
+ if ( where_on_path(ct->tar, curvetime, vec, dir, NULL, &radius) ) {
+ if (data->followflag & FOLLOWPATH_FOLLOW) {
vectoquat(dir, (short) data->trackflag, (short) data->upflag, quat);
Normalize(dir);
@@ -1189,6 +1210,14 @@ static void followpath_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr
QuatToMat4(quat, totmat);
}
+
+ if (data->followflag & FOLLOWPATH_RADIUS) {
+ float tmat[4][4], rmat[4][4];
+ Mat4Scale(tmat, radius);
+ Mat4MulMat4(rmat, totmat, tmat);
+ Mat4CpyMat4(totmat, rmat);
+ }
+
VECCOPY(totmat[3], vec);
Mat4MulSerie(ct->matrix, ct->tar->obmat, totmat, NULL, NULL, NULL, NULL, NULL, NULL);
@@ -1206,7 +1235,8 @@ static void followpath_evaluate (bConstraint *con, bConstraintOb *cob, ListBase
/* only evaluate if there is a target */
if (VALID_CONS_TARGET(ct)) {
float obmat[4][4];
- float size[3], obsize[3];
+ float size[3];
+ bFollowPathConstraint *data= con->data;
/* get Object local transform (loc/rot/size) to determine transformation from path */
//object_to_mat4(ob, obmat);
@@ -1219,13 +1249,17 @@ static void followpath_evaluate (bConstraint *con, bConstraintOb *cob, ListBase
Mat4MulSerie(cob->matrix, ct->matrix, obmat, NULL, NULL, NULL, NULL, NULL, NULL);
/* un-apply scaling caused by path */
- Mat4ToSize(cob->matrix, obsize);
- if (obsize[0])
- VecMulf(cob->matrix[0], size[0] / obsize[0]);
- if (obsize[1])
- VecMulf(cob->matrix[1], size[1] / obsize[1]);
- if (obsize[2])
- VecMulf(cob->matrix[2], size[2] / obsize[2]);
+ if ((data->followflag & FOLLOWPATH_RADIUS)==0) { /* XXX - assume that scale correction means that radius will have some scale error in it - Campbell */
+ float obsize[3];
+
+ Mat4ToSize(cob->matrix, obsize);
+ if (obsize[0])
+ VecMulf(cob->matrix[0], size[0] / obsize[0]);
+ if (obsize[1])
+ VecMulf(cob->matrix[1], size[1] / obsize[1]);
+ if (obsize[2])
+ VecMulf(cob->matrix[2], size[2] / obsize[2]);
+ }
}
}
@@ -1304,7 +1338,7 @@ static void rotlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *t
VECCOPY(loc, cob->matrix[3]);
Mat4ToSize(cob->matrix, size);
- Mat4ToEul(cob->matrix, eul);
+ Mat4ToEulO(cob->matrix, eul, cob->rotOrder);
/* eulers: radians to degrees! */
eul[0] = (float)(eul[0] / M_PI * 180);
@@ -1339,7 +1373,7 @@ static void rotlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *t
eul[1] = (float)(eul[1] / 180 * M_PI);
eul[2] = (float)(eul[2] / 180 * M_PI);
- LocEulSizeToMat4(cob->matrix, loc, eul, size);
+ LocEulOSizeToMat4(cob->matrix, loc, eul, size, cob->rotOrder);
}
static bConstraintTypeInfo CTI_ROTLIMIT = {
@@ -1546,14 +1580,14 @@ static void rotlike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta
VECCOPY(loc, cob->matrix[3]);
Mat4ToSize(cob->matrix, size);
- Mat4ToEul(ct->matrix, eul);
- Mat4ToEul(cob->matrix, obeul);
+ Mat4ToEulO(ct->matrix, eul, ct->rotOrder);
+ Mat4ToEulO(cob->matrix, obeul, cob->rotOrder);
if ((data->flag & ROTLIKE_X)==0)
eul[0] = obeul[0];
else {
if (data->flag & ROTLIKE_OFFSET)
- euler_rot(eul, obeul[0], 'x');
+ eulerO_rot(eul, obeul[0], 'x', cob->rotOrder);
if (data->flag & ROTLIKE_X_INVERT)
eul[0] *= -1;
@@ -1563,7 +1597,7 @@ static void rotlike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta
eul[1] = obeul[1];
else {
if (data->flag & ROTLIKE_OFFSET)
- euler_rot(eul, obeul[1], 'y');
+ eulerO_rot(eul, obeul[1], 'y', cob->rotOrder);
if (data->flag & ROTLIKE_Y_INVERT)
eul[1] *= -1;
@@ -1573,14 +1607,14 @@ static void rotlike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta
eul[2] = obeul[2];
else {
if (data->flag & ROTLIKE_OFFSET)
- euler_rot(eul, obeul[2], 'z');
+ eulerO_rot(eul, obeul[2], 'z', cob->rotOrder);
if (data->flag & ROTLIKE_Z_INVERT)
eul[2] *= -1;
}
compatible_eul(eul, obeul);
- LocEulSizeToMat4(cob->matrix, loc, eul, size);
+ LocEulOSizeToMat4(cob->matrix, loc, eul, size, cob->rotOrder);
}
}
@@ -2843,7 +2877,7 @@ static void clampto_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstrain
*/
/* only happens on reload file, but violates depsgraph still... fix! */
- if (cu->path==NULL || cu->path->data==NULL)
+ if (cu->path==NULL || cu->path->data==NULL)
makeDispListCurveTypes(cob->scene, ct->tar, 0);
}
@@ -2954,7 +2988,7 @@ static void clampto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta
}
/* 3. position on curve */
- if (where_on_path(ct->tar, curvetime, vec, dir) ) {
+ if (where_on_path(ct->tar, curvetime, vec, dir, NULL, NULL) ) {
Mat4One(totmat);
VECCOPY(totmat[3], vec);
@@ -3036,7 +3070,7 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
Mat4ToSize(ct->matrix, dvec);
break;
case 1: /* rotation (convert to degrees first) */
- Mat4ToEul(ct->matrix, dvec);
+ Mat4ToEulO(ct->matrix, dvec, cob->rotOrder);
for (i=0; i<3; i++)
dvec[i] = (float)(dvec[i] / M_PI * 180);
break;
@@ -3047,7 +3081,7 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
/* extract components of owner's matrix */
VECCOPY(loc, cob->matrix[3]);
- Mat4ToEul(cob->matrix, eul);
+ Mat4ToEulO(cob->matrix, eul, cob->rotOrder);
Mat4ToSize(cob->matrix, size);
/* determine where in range current transforms lie */
@@ -3102,7 +3136,7 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
}
/* apply to matrix */
- LocEulSizeToMat4(cob->matrix, loc, eul, size);
+ LocEulOSizeToMat4(cob->matrix, loc, eul, size, cob->rotOrder);
}
}
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index c38b994849a..bbfe077c15e 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -338,6 +338,13 @@ struct SpaceInfo *CTX_wm_space_info(const bContext *C)
return NULL;
}
+struct SpaceUserPref *CTX_wm_space_userpref(const bContext *C)
+{
+ if(C->wm.area && C->wm.area->spacetype==SPACE_USERPREF)
+ return C->wm.area->spacedata.first;
+ return NULL;
+}
+
void CTX_wm_manager_set(bContext *C, wmWindowManager *wm)
{
C->wm.manager= wm;
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 7dd868278f4..eec3cb73d8a 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -65,7 +65,6 @@
#include "BKE_object.h"
#include "BKE_utildefines.h" // VECCOPY
-
/* globals */
/* local */
@@ -137,7 +136,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->flag= CU_FRONT|CU_BACK|CU_PATH_RADIUS;
cu->pathlen= 100;
cu->resolu= cu->resolv= 12;
cu->width= 1.0;
@@ -470,8 +469,11 @@ void test2DNurb(Nurb *nu)
BezTriple *bezt;
BPoint *bp;
int a;
+
+ if((nu->flag & CU_2D)==0)
+ return;
- if( nu->type== CU_BEZIER+CU_2D ) {
+ if(nu->type == CU_BEZIER) {
a= nu->pntsu;
bezt= nu->bezt;
while(a--) {
@@ -481,7 +483,7 @@ void test2DNurb(Nurb *nu)
bezt++;
}
}
- else if(nu->type & CU_2D) {
+ else {
a= nu->pntsu*nu->pntsv;
bp= nu->bp;
while(a--) {
@@ -497,7 +499,7 @@ void minmaxNurb(Nurb *nu, float *min, float *max)
BPoint *bp;
int a;
- if( (nu->type & 7)==CU_BEZIER ) {
+ if(nu->type == CU_BEZIER) {
a= nu->pntsu;
bezt= nu->bezt;
while(a--) {
@@ -594,7 +596,7 @@ static void makecyclicknots(float *knots, short pnts, short order)
void makeknots(Nurb *nu, short uv)
{
- if( (nu->type & 7)==CU_NURBS ) {
+ if(nu->type == CU_NURBS) {
if(uv == 1) {
if(nu->knotsu) MEM_freeN(nu->knotsu);
if(check_valid_nurb_u(nu)) {
@@ -850,7 +852,7 @@ void makeNurbfaces(Nurb *nu, float *coord_array, int rowstride)
MEM_freeN(jend);
}
-void makeNurbcurve(Nurb *nu, float *coord_array, float *tilt_array, float *radius_array, int resolu)
+void makeNurbcurve(Nurb *nu, float *coord_array, float *tilt_array, float *radius_array, int resolu, int stride)
/* coord_array has to be 3*4*pntsu*resolu in size and zero-ed
* tilt_array and radius_array will be written to if valid */
{
@@ -934,10 +936,10 @@ void makeNurbcurve(Nurb *nu, float *coord_array, float *tilt_array, float *radiu
}
}
- coord_fp+= 3;
+ coord_fp = (float *)(((char *)coord_fp) + stride);
- if (tilt_fp) tilt_fp++;
- if (radius_fp) radius_fp++;
+ if (tilt_fp) tilt_fp = (float *)(((char *)tilt_fp) + stride);
+ if (radius_fp) radius_fp = (float *)(((char *)radius_fp) + stride);
u+= ustep;
}
@@ -968,12 +970,31 @@ void forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int i
for(a=0; a<=it; a++) {
*p= q0;
- p+= stride;
+ p = (float *)(((char *)p)+stride);
q0+= q1;
q1+= q2;
q2+= q3;
}
-}
+}
+
+void forward_diff_bezier_cotangent(float *p0, float *p1, float *p2, float *p3, float *p, int it, int stride)
+{
+ /* note that these are not purpendicular to the curve
+ * they need to be rotated for this,
+ *
+ * This could also be optimized like forward_diff_bezier */
+ int a;
+ for(a=0; a<=it; a++) {
+ float t = (float)a / (float)it;
+
+ int i;
+ for(i=0; i<3; i++) {
+ p[i]= (-6*t + 6)*p0[i] + (18*t - 12)*p1[i] + (-18*t + 6)*p2[i] + (6*t)*p3[i];
+ }
+ Normalize(p);
+ p = (float *)(((char *)p)+stride);
+ }
+}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
@@ -1387,8 +1408,8 @@ static short bevelinside(BevList *bl1,BevList *bl2)
/* take first vertex of possible hole */
bevp= (BevPoint *)(bl2+1);
- hvec1[0]= bevp->x;
- hvec1[1]= bevp->y;
+ hvec1[0]= bevp->vec[0];
+ hvec1[1]= bevp->vec[1];
hvec1[2]= 0.0;
VECCOPY(hvec2,hvec1);
hvec2[0]+=1000;
@@ -1401,16 +1422,16 @@ static short bevelinside(BevList *bl1,BevList *bl2)
prevbevp= bevp+(nr-1);
while(nr--) {
- min= prevbevp->y;
- max= bevp->y;
+ min= prevbevp->vec[0];
+ max= bevp->vec[1];
if(max<min) {
min= max;
- max= prevbevp->y;
+ max= prevbevp->vec[1];
}
if(min!=max) {
if(min<=hvec1[1] && max>=hvec1[1]) {
/* there's a transition, calc intersection point */
- mode= cu_isectLL(&(prevbevp->x),&(bevp->x),hvec1,hvec2,0,1,&lab,&mu,vec);
+ mode= cu_isectLL(prevbevp->vec, bevp->vec, hvec1, hvec2, 0, 1, &lab, &mu, vec);
/* if lab==0.0 or lab==1.0 then the edge intersects exactly a transition
only allow for one situation: we choose lab= 1.0
*/
@@ -1483,12 +1504,15 @@ static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2, float *si
}
-static void alfa_bezpart(BezTriple *prevbezt, BezTriple *bezt, Nurb *nu, float *tilt_array, float *radius_array, int resolu)
+static void alfa_bezpart(BezTriple *prevbezt, BezTriple *bezt, Nurb *nu, float *tilt_array, float *radius_array, int resolu, int stride)
{
BezTriple *pprev, *next, *last;
float fac, dfac, t[4];
int a;
+ if(tilt_array==NULL && radius_array==NULL)
+ return;
+
last= nu->bezt+(nu->pntsu-1);
/* returns a point */
@@ -1511,11 +1535,13 @@ 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 */
- tilt_array[a] = prevbezt->alfa + (bezt->alfa - prevbezt->alfa)*(3.0f*fac*fac - 2.0f*fac*fac*fac);
+ *tilt_array = prevbezt->alfa + (bezt->alfa - prevbezt->alfa)*(3.0f*fac*fac - 2.0f*fac*fac*fac);
} else {
- set_four_ipo(fac, t, nu->tilt_interp);
- tilt_array[a]= t[0]*pprev->alfa + t[1]*prevbezt->alfa + t[2]*bezt->alfa + t[3]*next->alfa;
+ key_curve_position_weights(fac, t, nu->tilt_interp);
+ *tilt_array= t[0]*pprev->alfa + t[1]*prevbezt->alfa + t[2]*bezt->alfa + t[3]*next->alfa;
}
+
+ tilt_array = (float *)(((char *)tilt_array) + stride);
}
if (radius_array) {
@@ -1523,19 +1549,363 @@ static void alfa_bezpart(BezTriple *prevbezt, BezTriple *bezt, Nurb *nu, float *
/* 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 */
- radius_array[a] = prevbezt->radius + (bezt->radius - prevbezt->radius)*(3.0f*fac*fac - 2.0f*fac*fac*fac);
+ *radius_array = prevbezt->radius + (bezt->radius - prevbezt->radius)*(3.0f*fac*fac - 2.0f*fac*fac*fac);
} else {
/* reuse interpolation from tilt if we can */
if (tilt_array==NULL || nu->tilt_interp != nu->radius_interp) {
- set_four_ipo(fac, t, nu->radius_interp);
+ key_curve_position_weights(fac, t, nu->radius_interp);
}
- radius_array[a]= t[0]*pprev->radius + t[1]*prevbezt->radius + t[2]*bezt->radius + t[3]*next->radius;
+ *radius_array= t[0]*pprev->radius + t[1]*prevbezt->radius + t[2]*bezt->radius + t[3]*next->radius;
+ }
+
+ radius_array = (float *)(((char *)radius_array) + stride);
+ }
+ }
+}
+
+/* make_bevel_list_3D_* funcs, at a minimum these must
+ * fill in the bezp->quat and bezp->dir values */
+
+/* correct non-cyclic cases by copying direction and rotation
+ * values onto the first & last end-points */
+static void bevel_list_cyclic_fix(BevList *bl)
+{
+ BevPoint *bevp, *bevp1;
+
+ bevp= (BevPoint *)(bl+1);
+ bevp1= bevp+1;
+ QUATCOPY(bevp->quat, bevp1->quat);
+ VECCOPY(bevp->dir, bevp1->dir);
+ VECCOPY(bevp->tan, bevp1->tan);
+ bevp= (BevPoint *)(bl+1);
+ bevp+= (bl->nr-1);
+ bevp1= bevp-1;
+ QUATCOPY(bevp->quat, bevp1->quat);
+ VECCOPY(bevp->dir, bevp1->dir);
+ VECCOPY(bevp->tan, bevp1->tan);
+}
+/* utility for make_bevel_list_3D_* funcs */
+static void bevel_list_calc_bisect(BevList *bl)
+{
+ BevPoint *bevp2, *bevp1, *bevp0;
+ int nr;
+
+ bevp2= (BevPoint *)(bl+1);
+ bevp1= bevp2+(bl->nr-1);
+ bevp0= bevp1-1;
+
+ nr= bl->nr;
+ while(nr--) {
+ /* totally simple */
+ VecBisect3(bevp1->dir, bevp0->vec, bevp1->vec, bevp2->vec);
+
+ bevp0= bevp1;
+ bevp1= bevp2;
+ bevp2++;
+ }
+}
+static void bevel_list_flip_tangents(BevList *bl)
+{
+ BevPoint *bevp2, *bevp1, *bevp0;
+ int nr;
+
+ bevp2= (BevPoint *)(bl+1);
+ bevp1= bevp2+(bl->nr-1);
+ bevp0= bevp1-1;
+
+ nr= bl->nr;
+ while(nr--) {
+ if(VecAngle2(bevp0->tan, bevp1->tan) > 90)
+ VecNegf(bevp1->tan);
+
+ bevp0= bevp1;
+ bevp1= bevp2;
+ bevp2++;
+ }
+}
+/* apply user tilt */
+static void bevel_list_apply_tilt(BevList *bl)
+{
+ BevPoint *bevp2, *bevp1, *bevp0;
+ int nr;
+ float q[4];
+
+ bevp2= (BevPoint *)(bl+1);
+ bevp1= bevp2+(bl->nr-1);
+ bevp0= bevp1-1;
+
+ nr= bl->nr;
+ while(nr--) {
+ AxisAngleToQuat(q, bevp1->dir, bevp1->alfa);
+ QuatMul(bevp1->quat, q, bevp1->quat);
+ NormalQuat(bevp1->quat);
+
+ bevp0= bevp1;
+ bevp1= bevp2;
+ bevp2++;
+ }
+}
+/* smooth quats, this function should be optimized, it can get slow with many iterations. */
+static void bevel_list_smooth(BevList *bl, int smooth_iter)
+{
+ BevPoint *bevp2, *bevp1, *bevp0;
+ int nr;
+
+ float q[4];
+ float bevp0_quat[4];
+ int a;
+
+ for(a=0; a < smooth_iter; a++) {
+
+ bevp2= (BevPoint *)(bl+1);
+ bevp1= bevp2+(bl->nr-1);
+ bevp0= bevp1-1;
+
+ nr= bl->nr;
+
+ if(bl->poly== -1) { /* check its not cyclic */
+ /* skip the first point */
+ bevp0= bevp1;
+ bevp1= bevp2;
+ bevp2++;
+ nr--;
+
+ bevp0= bevp1;
+ bevp1= bevp2;
+ bevp2++;
+ nr--;
+
+ }
+
+ QUATCOPY(bevp0_quat, bevp0->quat);
+
+ while(nr--) {
+ /* interpolate quats */
+ float zaxis[3] = {0,0,1}, cross[3], q2[4];
+ QuatInterpol(q, bevp0_quat, bevp2->quat, 0.5);
+ NormalQuat(q);
+
+ QuatMulVecf(q, zaxis);
+ Crossf(cross, zaxis, bevp1->dir);
+ AxisAngleToQuat(q2, cross, NormalizedVecAngle2(zaxis, bevp1->dir));
+ NormalQuat(q2);
+
+ QUATCOPY(bevp0_quat, bevp1->quat);
+ QuatMul(q, q2, q);
+ QuatInterpol(bevp1->quat, bevp1->quat, q, 0.5);
+ NormalQuat(bevp1->quat);
+
+
+ bevp0= bevp1;
+ bevp1= bevp2;
+ bevp2++;
+ }
+ }
+}
+
+static void make_bevel_list_3D_zup(BevList *bl)
+{
+ BevPoint *bevp2, *bevp1, *bevp0; /* standard for all make_bevel_list_3D_* funcs */
+ int nr;
+
+ bevp2= (BevPoint *)(bl+1);
+ bevp1= bevp2+(bl->nr-1);
+ bevp0= bevp1-1;
+
+ nr= bl->nr;
+ while(nr--) {
+ /* totally simple */
+ VecBisect3(bevp1->dir, bevp0->vec, bevp1->vec, bevp2->vec);
+ vectoquat(bevp1->dir, 5, 1, bevp1->quat);
+
+ bevp0= bevp1;
+ bevp1= bevp2;
+ bevp2++;
+ }
+}
+
+static void make_bevel_list_3D_minimum_twist(BevList *bl)
+{
+ BevPoint *bevp2, *bevp1, *bevp0; /* standard for all make_bevel_list_3D_* funcs */
+ int nr;
+ float q[4];
+
+ float cross_tmp[3];
+
+ bevel_list_calc_bisect(bl);
+
+ bevp2= (BevPoint *)(bl+1);
+ bevp1= bevp2+(bl->nr-1);
+ bevp0= bevp1-1;
+
+ nr= bl->nr;
+ while(nr--) {
+
+ if(nr+4 > bl->nr) { /* first time and second time, otherwise first point adjusts last */
+ vectoquat(bevp1->dir, 5, 1, bevp1->quat);
+ }
+ else {
+ float angle= NormalizedVecAngle2(bevp0->dir, bevp1->dir);
+
+ if(angle > 0.0f) { /* otherwise we can keep as is */
+ Crossf(cross_tmp, bevp0->dir, bevp1->dir);
+ AxisAngleToQuat(q, cross_tmp, angle);
+ QuatMul(bevp1->quat, q, bevp0->quat);
}
+ else {
+ QUATCOPY(bevp1->quat, bevp0->quat);
+ }
+ }
+
+ bevp0= bevp1;
+ bevp1= bevp2;
+ bevp2++;
+ }
+
+ if(bl->poly != -1) { /* check for cyclic */
+
+ /* Need to correct for the start/end points not matching
+ * do this by calculating the tilt angle difference, then apply
+ * the rotation gradually over the entire curve
+ *
+ * note that the split is between last and second last, rather then first/last as youd expect.
+ *
+ * real order is like this
+ * 0,1,2,3,4 --> 1,2,3,4,0
+ *
+ * this is why we compare last with second last
+ * */
+ float vec_1[3]= {0,1,0}, vec_2[3]= {0,1,0}, angle, ang_fac, cross_tmp[3];
+
+ BevPoint *bevp_first;
+ BevPoint *bevp_last;
+
+
+ bevp_first= (BevPoint *)(bl+1);
+ bevp_first+= bl->nr-1;
+ bevp_last = bevp_first;
+ bevp_last--;
+
+ /* quats and vec's are normalized, should not need to re-normalize */
+ QuatMulVecf(bevp_first->quat, vec_1);
+ QuatMulVecf(bevp_last->quat, vec_2);
+ Normalize(vec_1);
+ Normalize(vec_2);
+
+ /* align the vector, can avoid this and it looks 98% OK but
+ * better to align the angle quat roll's before comparing */
+ {
+ Crossf(cross_tmp, bevp_last->dir, bevp_first->dir);
+ angle = NormalizedVecAngle2(bevp_first->dir, bevp_last->dir);
+ AxisAngleToQuat(q, cross_tmp, angle);
+ QuatMulVecf(q, vec_2);
}
+
+ angle= NormalizedVecAngle2(vec_1, vec_2);
+
+ /* flip rotation if needs be */
+ Crossf(cross_tmp, vec_1, vec_2);
+ Normalize(cross_tmp);
+ if(NormalizedVecAngle2(bevp_first->dir, cross_tmp) < 90/(180.0/M_PI))
+ angle = -angle;
+
+ bevp2= (BevPoint *)(bl+1);
+ bevp1= bevp2+(bl->nr-1);
+ bevp0= bevp1-1;
+
+ nr= bl->nr;
+ while(nr--) {
+ ang_fac= angle * (1.0f-((float)nr/bl->nr)); /* also works */
+
+ AxisAngleToQuat(q, bevp1->dir, ang_fac);
+ QuatMul(bevp1->quat, q, bevp1->quat);
+
+ bevp0= bevp1;
+ bevp1= bevp2;
+ bevp2++;
+ }
+ }
+}
+
+static void make_bevel_list_3D_tangent(BevList *bl)
+{
+ BevPoint *bevp2, *bevp1, *bevp0; /* standard for all make_bevel_list_3D_* funcs */
+ int nr;
+
+ float bevp0_tan[3], cross_tmp[3];
+
+ bevel_list_calc_bisect(bl);
+ if(bl->poly== -1) /* check its not cyclic */
+ bevel_list_cyclic_fix(bl); // XXX - run this now so tangents will be right before doing the flipping
+ bevel_list_flip_tangents(bl);
+
+ /* correct the tangents */
+ bevp2= (BevPoint *)(bl+1);
+ bevp1= bevp2+(bl->nr-1);
+ bevp0= bevp1-1;
+
+ nr= bl->nr;
+ while(nr--) {
+
+ Crossf(cross_tmp, bevp1->tan, bevp1->dir);
+ Crossf(bevp1->tan, cross_tmp, bevp1->dir);
+ Normalize(bevp1->tan);
+
+ bevp0= bevp1;
+ bevp1= bevp2;
+ bevp2++;
+ }
+
+
+ /* now for the real twist calc */
+ bevp2= (BevPoint *)(bl+1);
+ bevp1= bevp2+(bl->nr-1);
+ bevp0= bevp1-1;
+
+ VECCOPY(bevp0_tan, bevp0->tan);
+
+ nr= bl->nr;
+ while(nr--) {
+
+ /* make perpendicular, modify tan in place, is ok */
+ float cross_tmp[3];
+ float zero[3] = {0,0,0};
+
+ Crossf(cross_tmp, bevp1->tan, bevp1->dir);
+ Normalize(cross_tmp);
+ triatoquat(zero, cross_tmp, bevp1->tan, bevp1->quat); /* XXX - could be faster */
+
+ bevp0= bevp1;
+ bevp1= bevp2;
+ bevp2++;
}
}
+void make_bevel_list_3D(BevList *bl, int smooth_iter, int twist_mode)
+{
+ switch(twist_mode) {
+ case CU_TWIST_TANGENT:
+ make_bevel_list_3D_tangent(bl);
+ break;
+ case CU_TWIST_MINIMUM:
+ make_bevel_list_3D_minimum_twist(bl);
+ break;
+ default: /* CU_TWIST_Z_UP default, pre 2.49c */
+ make_bevel_list_3D_zup(bl);
+ }
+
+ if(bl->poly== -1) /* check its not cyclic */
+ bevel_list_cyclic_fix(bl);
+
+ if(smooth_iter)
+ bevel_list_smooth(bl, smooth_iter);
+
+ bevel_list_apply_tilt(bl);
+}
+
+
+
void makeBevelList(Object *ob)
{
/*
@@ -1550,9 +1920,7 @@ void makeBevelList(Object *ob)
BPoint *bp;
BevList *bl, *blnew, *blnext;
BevPoint *bevp, *bevp2, *bevp1 = NULL, *bevp0;
- float min, inp, x1, x2, y1, y2, vec[3];
- float *coord_array, *tilt_array=NULL, *radius_array=NULL, *coord_fp, *tilt_fp=NULL, *radius_fp=NULL;
- float *v1, *v2;
+ float min, inp, x1, x2, y1, y2;
struct bevelsort *sortdata, *sd, *sd1;
int a, b, nr, poly, resolu, len=0;
int do_tilt, do_radius;
@@ -1587,7 +1955,7 @@ void makeBevelList(Object *ob)
else
resolu= nu->resolu;
- if((nu->type & 7)==CU_POLY) {
+ if(nu->type == CU_POLY) {
len= nu->pntsu;
bl= MEM_callocN(sizeof(BevList)+len*sizeof(BevPoint), "makeBevelList2");
BLI_addtail(&(cu->bev), bl);
@@ -1595,22 +1963,20 @@ void makeBevelList(Object *ob)
if(nu->flagu & CU_CYCLIC) bl->poly= 0;
else bl->poly= -1;
bl->nr= len;
- bl->flag= 0;
+ bl->dupe_nr= 0;
bevp= (BevPoint *)(bl+1);
bp= nu->bp;
while(len--) {
- bevp->x= bp->vec[0];
- bevp->y= bp->vec[1];
- bevp->z= bp->vec[2];
+ VECCOPY(bevp->vec, bp->vec);
bevp->alfa= bp->alfa;
bevp->radius= bp->radius;
- bevp->f1= SELECT;
+ bevp->split_tag= TRUE;
bevp++;
bp++;
}
}
- else if((nu->type & 7)==CU_BEZIER) {
+ else if(nu->type == CU_BEZIER) {
len= resolu*(nu->pntsu+ (nu->flagu & CU_CYCLIC) -1)+1; /* in case last point is not cyclic */
bl= MEM_callocN(sizeof(BevList)+len*sizeof(BevPoint), "makeBevelBPoints");
@@ -1631,139 +1997,81 @@ void makeBevelList(Object *ob)
bezt++;
}
- coord_array= coord_fp= MEM_mallocN(3*sizeof(float)*(resolu+1), "makeBevelCoords");
-
- if(do_tilt)
- tilt_array= tilt_fp= MEM_callocN(sizeof(float)*(resolu+1), "makeBevelTilt");
-
- if (do_radius)
- radius_array= radius_fp= MEM_callocN(sizeof(float)*(resolu+1), "nakeBevelRadius");
-
while(a--) {
if(prevbezt->h2==HD_VECT && bezt->h1==HD_VECT) {
-
- bevp->x= prevbezt->vec[1][0];
- bevp->y= prevbezt->vec[1][1];
- bevp->z= prevbezt->vec[1][2];
+
+ VECCOPY(bevp->vec, prevbezt->vec[1]);
bevp->alfa= prevbezt->alfa;
bevp->radius= prevbezt->radius;
- bevp->f1= SELECT;
- bevp->f2= 0;
+ bevp->split_tag= TRUE;
+ bevp->dupe_tag= FALSE;
bevp++;
bl->nr++;
- bl->flag= 1;
+ bl->dupe_nr= 1;
}
else {
- v1= prevbezt->vec[1];
- v2= bezt->vec[0];
-
/* always do all three, to prevent data hanging around */
- forward_diff_bezier(v1[0], v1[3], v2[0], v2[3], coord_array, resolu, 3);
- forward_diff_bezier(v1[1], v1[4], v2[1], v2[4], coord_array+1, resolu, 3);
- forward_diff_bezier(v1[2], v1[5], v2[2], v2[5], coord_array+2, resolu, 3);
+ int j;
- if (do_tilt || do_radius)
- alfa_bezpart(prevbezt, bezt, nu, tilt_array, radius_array, resolu);
+ /* BevPoint must stay aligned to 4 so sizeof(BevPoint)/sizeof(float) works */
+ for(j=0; j<3; j++) {
+ forward_diff_bezier( prevbezt->vec[1][j], prevbezt->vec[2][j],
+ bezt->vec[0][j], bezt->vec[1][j],
+ &(bevp->vec[j]), resolu, sizeof(BevPoint));
+ }
+
+ /* if both arrays are NULL do nothiong */
+ alfa_bezpart( prevbezt, bezt, nu,
+ do_tilt ? &bevp->alfa : NULL,
+ do_radius ? &bevp->radius : NULL,
+ resolu, sizeof(BevPoint));
+
+ if(cu->twist_mode==CU_TWIST_TANGENT) {
+ forward_diff_bezier_cotangent(
+ prevbezt->vec[1], prevbezt->vec[2],
+ bezt->vec[0], bezt->vec[1],
+ bevp->tan, resolu, sizeof(BevPoint));
+ }
+
/* indicate with handlecodes double points */
if(prevbezt->h1==prevbezt->h2) {
- if(prevbezt->h1==0 || prevbezt->h1==HD_VECT) bevp->f1= SELECT;
+ if(prevbezt->h1==0 || prevbezt->h1==HD_VECT) bevp->split_tag= TRUE;
}
else {
- if(prevbezt->h1==0 || prevbezt->h1==HD_VECT) bevp->f1= SELECT;
- else if(prevbezt->h2==0 || prevbezt->h2==HD_VECT) bevp->f1= SELECT;
- }
-
- nr= resolu;
-
- coord_fp = coord_array;
- tilt_fp = tilt_array;
- radius_fp = radius_array;
-
- while(nr--) {
- bevp->x= coord_fp[0];
- bevp->y= coord_fp[1];
- bevp->z= coord_fp[2];
- coord_fp+=3;
-
- if (do_tilt) {
- bevp->alfa= *tilt_fp;
- tilt_fp++;
- }
-
- if (do_radius) {
- bevp->radius= *radius_fp;
- radius_fp++;
- }
- bevp++;
+ if(prevbezt->h1==0 || prevbezt->h1==HD_VECT) bevp->split_tag= TRUE;
+ else if(prevbezt->h2==0 || prevbezt->h2==HD_VECT) bevp->split_tag= TRUE;
}
bl->nr+= resolu;
-
+ bevp+= resolu;
}
prevbezt= bezt;
bezt++;
}
- MEM_freeN(coord_array);
- if (do_tilt) MEM_freeN(tilt_array);
- if (do_radius) MEM_freeN(radius_array);
- coord_array = tilt_array = radius_array = NULL;
-
if((nu->flagu & CU_CYCLIC)==0) { /* not cyclic: endpoint */
- bevp->x= prevbezt->vec[1][0];
- bevp->y= prevbezt->vec[1][1];
- bevp->z= prevbezt->vec[1][2];
+ VECCOPY(bevp->vec, prevbezt->vec[1]);
bevp->alfa= prevbezt->alfa;
bevp->radius= prevbezt->radius;
bl->nr++;
}
}
- else if((nu->type & 7)==CU_NURBS) {
+ else if(nu->type == CU_NURBS) {
if(nu->pntsv==1) {
len= (resolu*SEGMENTSU(nu));
bl= MEM_callocN(sizeof(BevList)+len*sizeof(BevPoint), "makeBevelList3");
BLI_addtail(&(cu->bev), bl);
bl->nr= len;
- bl->flag= 0;
+ bl->dupe_nr= 0;
if(nu->flagu & CU_CYCLIC) bl->poly= 0;
else bl->poly= -1;
bevp= (BevPoint *)(bl+1);
-
- coord_array= coord_fp= MEM_callocN(3*sizeof(float)*len, "makeBevelCoords"); /* has to be zero-ed */
-
- if(do_tilt)
- tilt_array= tilt_fp= MEM_callocN(sizeof(float)*len, "makeBevelTilt");
- if (do_radius)
- radius_array= radius_fp= MEM_callocN(sizeof(float)*len, "nakeBevelRadius");
-
- makeNurbcurve(nu, coord_array, tilt_array, radius_array, resolu);
-
- while(len--) {
- bevp->x= coord_fp[0];
- bevp->y= coord_fp[1];
- bevp->z= coord_fp[2];
- coord_fp+=3;
-
- if (do_tilt) {
- bevp->alfa= *tilt_fp;
- tilt_fp++;
- }
-
- if (do_radius) {
- bevp->radius= *radius_fp;
- radius_fp++;
- }
-
-
- bevp->f1= bevp->f2= 0;
- bevp++;
- }
- MEM_freeN(coord_array);
- if (do_tilt) MEM_freeN(tilt_array);
- if (do_radius) MEM_freeN(radius_array);
- coord_array = tilt_array = radius_array = NULL;
+ makeNurbcurve( nu, &bevp->vec[0],
+ do_tilt ? &bevp->alfa : NULL,
+ do_radius ? &bevp->radius : NULL,
+ resolu, sizeof(BevPoint));
}
}
}
@@ -1779,11 +2087,11 @@ void makeBevelList(Object *ob)
bevp0= bevp1+(nr-1);
nr--;
while(nr--) {
- if( fabs(bevp0->x-bevp1->x)<0.00001 ) {
- if( fabs(bevp0->y-bevp1->y)<0.00001 ) {
- if( fabs(bevp0->z-bevp1->z)<0.00001 ) {
- bevp0->f2= SELECT;
- bl->flag++;
+ if( fabs(bevp0->vec[0]-bevp1->vec[0])<0.00001 ) {
+ if( fabs(bevp0->vec[1]-bevp1->vec[1])<0.00001 ) {
+ if( fabs(bevp0->vec[2]-bevp1->vec[2])<0.00001 ) {
+ bevp0->dupe_tag= TRUE;
+ bl->dupe_nr++;
}
}
}
@@ -1796,8 +2104,8 @@ void makeBevelList(Object *ob)
bl= cu->bev.first;
while(bl) {
blnext= bl->next;
- if(bl->nr && bl->flag) {
- nr= bl->nr- bl->flag+1; /* +1 because vectorbezier sets flag too */
+ if(bl->nr && bl->dupe_nr) {
+ nr= bl->nr- bl->dupe_nr+1; /* +1 because vectorbezier sets flag too */
blnew= MEM_mallocN(sizeof(BevList)+nr*sizeof(BevPoint), "makeBevelList4");
memcpy(blnew, bl, sizeof(BevList));
blnew->nr= 0;
@@ -1807,7 +2115,7 @@ void makeBevelList(Object *ob)
bevp1= (BevPoint *)(blnew+1);
nr= bl->nr;
while(nr--) {
- if(bevp0->f2==0) {
+ if(bevp0->dupe_tag==0) {
memcpy(bevp1, bevp0, sizeof(BevPoint));
bevp1++;
blnew->nr++;
@@ -1815,19 +2123,19 @@ void makeBevelList(Object *ob)
bevp0++;
}
MEM_freeN(bl);
- blnew->flag= 0;
+ blnew->dupe_nr= 0;
}
bl= blnext;
}
- /* STEP 3: COUNT POLYS TELLEN AND AUTOHOLE */
+ /* STEP 3: POLYS COUNT AND AUTOHOLE */
bl= cu->bev.first;
poly= 0;
while(bl) {
if(bl->nr && bl->poly>=0) {
poly++;
bl->poly= poly;
- bl->gat= 0; /* 'gat' is dutch for hole */
+ bl->hole= 0;
}
bl= bl->next;
}
@@ -1844,8 +2152,8 @@ void makeBevelList(Object *ob)
bevp= (BevPoint *)(bl+1);
nr= bl->nr;
while(nr--) {
- if(min>bevp->x) {
- min= bevp->x;
+ if(min>bevp->vec[0]) {
+ min= bevp->vec[0];
bevp1= bevp;
}
bevp++;
@@ -1860,8 +2168,7 @@ void makeBevelList(Object *ob)
if(bevp1== bevp) bevp2= (BevPoint *)(bl+1);
else bevp2= bevp1+1;
- inp= (bevp1->x- bevp0->x)*(bevp0->y- bevp2->y)
- +(bevp0->y- bevp1->y)*(bevp0->x- bevp2->x);
+ inp= (bevp1->vec[0]- bevp0->vec[0]) * (bevp0->vec[1]- bevp2->vec[1]) + (bevp0->vec[1]- bevp1->vec[1]) * (bevp0->vec[0]- bevp2->vec[0]);
if(inp>0.0) sd->dir= 1;
else sd->dir= 0;
@@ -1879,7 +2186,7 @@ void makeBevelList(Object *ob)
sd1= sortdata+ (a-1);
for(b=a-1; b>=0; b--, sd1--) { /* all polys to the left */
if(bevelinside(sd1->bl, bl)) {
- bl->gat= 1- sd1->bl->gat;
+ bl->hole= 1- sd1->bl->hole;
break;
}
}
@@ -1889,7 +2196,7 @@ void makeBevelList(Object *ob)
if((cu->flag & CU_3D)==0) {
sd= sortdata;
for(a=0; a<poly; a++, sd++) {
- if(sd->bl->gat==sd->dir) {
+ if(sd->bl->hole==sd->dir) {
bl= sd->bl;
bevp1= (BevPoint *)(bl+1);
bevp2= bevp1+ (bl->nr-1);
@@ -1905,104 +2212,90 @@ void makeBevelList(Object *ob)
MEM_freeN(sortdata);
}
- /* STEP 4: COSINES */
- bl= cu->bev.first;
- while(bl) {
-
- if(bl->nr==2) { /* 2 pnt, treat separate */
- bevp2= (BevPoint *)(bl+1);
- bevp1= bevp2+1;
+ /* STEP 4: 2D-COSINES or 3D ORIENTATION */
+ if((cu->flag & CU_3D)==0) { /* 3D */
+ bl= cu->bev.first;
+ while(bl) {
- x1= bevp1->x- bevp2->x;
- y1= bevp1->y- bevp2->y;
+ if(bl->nr < 2) {
+ /* do nothing */
+ }
+ else if(bl->nr==2) { /* 2 pnt, treat separate */
+ bevp2= (BevPoint *)(bl+1);
+ bevp1= bevp2+1;
- calc_bevel_sin_cos(x1, y1, -x1, -y1, &(bevp1->sina), &(bevp1->cosa));
- bevp2->sina= bevp1->sina;
- bevp2->cosa= bevp1->cosa;
+ x1= bevp1->vec[0]- bevp2->vec[0];
+ y1= bevp1->vec[1]- bevp2->vec[1];
- if(cu->flag & CU_3D) { /* 3D */
- float quat[4], q[4];
-
- vec[0]= bevp1->x - bevp2->x;
- vec[1]= bevp1->y - bevp2->y;
- vec[2]= bevp1->z - bevp2->z;
-
- vectoquat(vec, 5, 1, quat);
-
- Normalize(vec);
- q[0]= (float)cos(0.5*bevp1->alfa);
- x1= (float)sin(0.5*bevp1->alfa);
- q[1]= x1*vec[0];
- q[2]= x1*vec[1];
- q[3]= x1*vec[2];
- QuatMul(quat, q, quat);
-
- QuatToMat3(quat, bevp1->mat);
- Mat3CpyMat3(bevp2->mat, bevp1->mat);
+ calc_bevel_sin_cos(x1, y1, -x1, -y1, &(bevp1->sina), &(bevp1->cosa));
+ bevp2->sina= bevp1->sina;
+ bevp2->cosa= bevp1->cosa;
}
+ else {
+ bevp2= (BevPoint *)(bl+1);
+ bevp1= bevp2+(bl->nr-1);
+ bevp0= bevp1-1;
- }
- else if(bl->nr>2) {
- bevp2= (BevPoint *)(bl+1);
- bevp1= bevp2+(bl->nr-1);
- bevp0= bevp1-1;
+ nr= bl->nr;
+ while(nr--) {
+ x1= bevp1->vec[0]- bevp0->vec[0];
+ x2= bevp1->vec[0]- bevp2->vec[0];
+ y1= bevp1->vec[1]- bevp0->vec[1];
+ y2= bevp1->vec[1]- bevp2->vec[1];
-
- nr= bl->nr;
-
- while(nr--) {
-
- if(cu->flag & CU_3D) { /* 3D */
- float quat[4], q[4];
-
- vec[0]= bevp2->x - bevp0->x;
- vec[1]= bevp2->y - bevp0->y;
- vec[2]= bevp2->z - bevp0->z;
-
- Normalize(vec);
+ calc_bevel_sin_cos(x1, y1, x2, y2, &(bevp1->sina), &(bevp1->cosa));
- vectoquat(vec, 5, 1, quat);
-
- q[0]= (float)cos(0.5*bevp1->alfa);
- x1= (float)sin(0.5*bevp1->alfa);
- q[1]= x1*vec[0];
- q[2]= x1*vec[1];
- q[3]= x1*vec[2];
- QuatMul(quat, q, quat);
-
- QuatToMat3(quat, bevp1->mat);
+ bevp0= bevp1;
+ bevp1= bevp2;
+ bevp2++;
}
-
- x1= bevp1->x- bevp0->x;
- x2= bevp1->x- bevp2->x;
- y1= bevp1->y- bevp0->y;
- y2= bevp1->y- bevp2->y;
-
- calc_bevel_sin_cos(x1, y1, x2, y2, &(bevp1->sina), &(bevp1->cosa));
-
-
- bevp0= bevp1;
- bevp1= bevp2;
- bevp2++;
- }
- /* correct non-cyclic cases */
- if(bl->poly== -1) {
- if(bl->nr>2) {
+
+ /* correct non-cyclic cases */
+ if(bl->poly== -1) {
bevp= (BevPoint *)(bl+1);
bevp1= bevp+1;
bevp->sina= bevp1->sina;
bevp->cosa= bevp1->cosa;
- Mat3CpyMat3(bevp->mat, bevp1->mat);
bevp= (BevPoint *)(bl+1);
bevp+= (bl->nr-1);
bevp1= bevp-1;
bevp->sina= bevp1->sina;
bevp->cosa= bevp1->cosa;
- Mat3CpyMat3(bevp->mat, bevp1->mat);
}
}
+ bl= bl->next;
+ }
+ }
+ else { /* 3D Curves */
+ bl= cu->bev.first;
+ while(bl) {
+
+ if(bl->nr < 2) {
+ /* do nothing */
+ }
+ else if(bl->nr==2) { /* 2 pnt, treat separate */
+ float q[4];
+
+ bevp2= (BevPoint *)(bl+1);
+ bevp1= bevp2+1;
+
+ /* simple quat/dir */
+ VecSubf(bevp1->dir, bevp1->vec, bevp2->vec);
+ Normalize(bevp1->dir);
+
+ vectoquat(bevp1->dir, 5, 1, bevp1->quat);
+
+ AxisAngleToQuat(q, bevp1->dir, bevp1->alfa);
+ QuatMul(bevp1->quat, q, bevp1->quat);
+ NormalQuat(bevp1->quat);
+ VECCOPY(bevp2->dir, bevp1->dir);
+ QUATCOPY(bevp2->quat, bevp1->quat);
+ }
+ else {
+ make_bevel_list_3D(bl, (int)(resolu*cu->twist_smooth), cu->twist_mode);
+ }
+ bl= bl->next;
}
- bl= bl->next;
}
}
@@ -2207,7 +2500,7 @@ void calchandlesNurb(Nurb *nu) /* first, if needed, set handle flags */
BezTriple *bezt, *prev, *next;
short a;
- if((nu->type & 7)!=CU_BEZIER) return;
+ if(nu->type != CU_BEZIER) return;
if(nu->pntsu<2) return;
a= nu->pntsu;
@@ -2242,7 +2535,7 @@ void testhandlesNurb(Nurb *nu)
BezTriple *bezt;
short flag, a;
- if((nu->type & 7)!=CU_BEZIER) return;
+ if(nu->type != CU_BEZIER) return;
bezt= nu->bezt;
a= nu->pntsu;
@@ -2370,7 +2663,7 @@ void sethandlesNurb(ListBase *editnurb, short code)
if(code==1 || code==2) {
nu= editnurb->first;
while(nu) {
- if( (nu->type & 7)==CU_BEZIER) {
+ if(nu->type == CU_BEZIER) {
bezt= nu->bezt;
a= nu->pntsu;
while(a--) {
@@ -2400,7 +2693,7 @@ void sethandlesNurb(ListBase *editnurb, short code)
} else {
/* Toggle */
while(nu) {
- if( (nu->type & 7)==CU_BEZIER) {
+ if(nu->type == CU_BEZIER) {
bezt= nu->bezt;
a= nu->pntsu;
while(a--) {
@@ -2417,7 +2710,7 @@ void sethandlesNurb(ListBase *editnurb, short code)
}
nu= editnurb->first;
while(nu) {
- if( (nu->type & 7)==CU_BEZIER) {
+ if(nu->type == CU_BEZIER) {
bezt= nu->bezt;
a= nu->pntsu;
while(a--) {
@@ -2465,7 +2758,7 @@ void switchdirectionNurb(Nurb *nu)
if(nu->pntsu==1 && nu->pntsv==1) return;
- if((nu->type & 7)==CU_BEZIER) {
+ if(nu->type == CU_BEZIER) {
a= nu->pntsu;
bezt1= nu->bezt;
bezt2= bezt1+(a-1);
@@ -2504,7 +2797,7 @@ void switchdirectionNurb(Nurb *nu)
bp1++;
bp2--;
}
- if((nu->type & 7)==CU_NURBS) {
+ if(nu->type == CU_NURBS) {
/* inverse knots */
a= KNOTSU(nu);
fp1= nu->knotsu;
@@ -2567,7 +2860,7 @@ float (*curve_getVertexCos(Curve *cu, ListBase *lb, int *numVerts_r))[3]
co = cos[0];
for (nu=lb->first; nu; nu=nu->next) {
- if ((nu->type & 7)==CU_BEZIER) {
+ if (nu->type == CU_BEZIER) {
BezTriple *bezt = nu->bezt;
for (i=0; i<nu->pntsu; i++,bezt++) {
@@ -2594,7 +2887,7 @@ void curve_applyVertexCos(Curve *cu, ListBase *lb, float (*vertexCos)[3])
int i;
for (nu=lb->first; nu; nu=nu->next) {
- if ((nu->type & 7)==CU_BEZIER) {
+ if (nu->type == CU_BEZIER) {
BezTriple *bezt = nu->bezt;
for (i=0; i<nu->pntsu; i++,bezt++) {
@@ -2616,7 +2909,7 @@ int check_valid_nurb_u( struct Nurb *nu )
{
if (nu==NULL) return 0;
if (nu->pntsu <= 1) return 0;
- if ((nu->type & 7)!=CU_NURBS) return 1; /* not a nurb, lets assume its valid */
+ if (nu->type != CU_NURBS) return 1; /* not a nurb, lets assume its valid */
if (nu->pntsu < nu->orderu) return 0;
if (((nu->flag & CU_CYCLIC)==0) && ((nu->flagu>>1) & 2)) { /* Bezier U Endpoints */
@@ -2630,7 +2923,7 @@ int check_valid_nurb_v( struct Nurb *nu)
{
if (nu==NULL) return 0;
if (nu->pntsv <= 1) return 0;
- if ((nu->type & 7)!=CU_NURBS) return 1; /* not a nurb, lets assume its valid */
+ if (nu->type != CU_NURBS) return 1; /* not a nurb, lets assume its valid */
if (nu->pntsv < nu->orderv) return 0;
if (((nu->flag & CU_CYCLIC)==0) && ((nu->flagv>>1) & 2)) { /* Bezier V Endpoints */
diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c
index 6c765b02e5d..6a14762e0ed 100644
--- a/source/blender/blenkernel/intern/depsgraph.c
+++ b/source/blender/blenkernel/intern/depsgraph.c
@@ -61,6 +61,7 @@
#include "DNA_space_types.h"
#include "DNA_view2d_types.h"
#include "DNA_view3d_types.h"
+#include "DNA_windowmanager_types.h"
#include "BLI_ghash.h"
@@ -2141,39 +2142,77 @@ void DAG_scene_update_flags(Scene *scene, unsigned int lay)
}
-
-/* flag this object and all its relations to recalc */
-/* if you need to do more objects, tag object yourself and
- use DAG_scene_flush_update() in end */
-void DAG_object_flush_update(Scene *sce, Object *ob, short flag)
+void DAG_id_flush_update(ID *id, short flag)
{
-
- if(ob==NULL || sce->theDag==NULL) return;
+ Main *bmain= G.main;
+ wmWindowManager *wm;
+ wmWindow *win;
+ Scene *sce;
+ Object *obt, *ob= NULL;
+ short idtype;
- ob->recalc |= flag;
- BKE_ptcache_object_reset(sce, ob, PTCACHE_RESET_DEPSGRAPH);
-
- /* all users of this ob->data should be checked */
- /* BUT! displists for curves are still only on cu */
- if(flag & OB_RECALC_DATA) {
- if(ob->type!=OB_CURVE && ob->type!=OB_SURF) {
- ID *id= ob->data;
- if(id && id->us>1) {
- /* except when there's a key and shapes are locked */
- if(ob_get_key(ob) && (ob->shapeflag & (OB_SHAPE_LOCK|OB_SHAPE_TEMPLOCK)));
- else {
- Object *obt;
- for (obt=G.main->object.first; obt; obt= obt->id.next) {
- if (obt != ob && obt->data==ob->data) {
- obt->recalc |= OB_RECALC_DATA;
- BKE_ptcache_object_reset(sce, obt, PTCACHE_RESET_DEPSGRAPH);
- }
- }
+ /* only one scene supported currently, making more scenes work
+ correctly requires changes beyond just the dependency graph */
+
+ if((wm= bmain->wm.first)) {
+ /* if we have a windowmanager, use sce from first window */
+ for(win=wm->windows.first; win; win=win->next) {
+ sce= (win->screen)? win->screen->scene: NULL;
+
+ if(sce)
+ break;
+ }
+ }
+ else
+ /* if not, use the first sce */
+ sce= bmain->scene.first;
+
+ if(!id || !sce || !sce->theDag)
+ return;
+
+ /* set flags & pointcache for object */
+ if(GS(id->name) == ID_OB) {
+ ob= (Object*)id;
+ ob->recalc |= flag;
+ BKE_ptcache_object_reset(sce, ob, PTCACHE_RESET_DEPSGRAPH);
+
+ if(flag & OB_RECALC_DATA) {
+ /* all users of this ob->data should be checked */
+ id= ob->data;
+
+ /* no point in trying in this cases */
+ if(!id || id->us <= 1)
+ id= NULL;
+ /* curves and surfaces only need to mark one object, since
+ otherwise cu->displist would be computed multiple times */
+ else if(ob->type==OB_CURVE || ob->type==OB_SURF)
+ id= NULL;
+ /* also for locked shape keys we make an exception */
+ else if(ob_get_key(ob) && (ob->shapeflag & (OB_SHAPE_LOCK|OB_SHAPE_TEMPLOCK)))
+ id= NULL;
+ }
+ }
+
+ /* set flags & pointcache for object data */
+ if(id) {
+ idtype= GS(id->name);
+
+ if(ELEM7(idtype, ID_ME, ID_CU, ID_MB, ID_LA, ID_LT, ID_CA, ID_AR)) {
+ for(obt=bmain->object.first; obt; obt= obt->id.next) {
+ if(!(ob && obt == ob) && obt->data == id) {
+ obt->recalc |= OB_RECALC_DATA;
+ BKE_ptcache_object_reset(sce, obt, PTCACHE_RESET_DEPSGRAPH);
+
+ /* for these we only flag one object, otherwise cu->displist
+ would be computed multiple times */
+ if(obt->type==OB_CURVE || obt->type==OB_SURF)
+ break;
}
}
}
}
-
+
+ /* flush to other objects that depend on this one */
// XXX if(G.curscreen)
// DAG_scene_flush_update(sce, dag_screen_view3d_layers(), 0);
// else
diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c
index 069129c15da..d87dbc833c5 100644
--- a/source/blender/blenkernel/intern/displist.c
+++ b/source/blender/blenkernel/intern/displist.c
@@ -821,7 +821,7 @@ static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase)
DispList *dl;
BezTriple *bezt, *prevbezt;
BPoint *bp;
- float *data, *v1, *v2;
+ float *data;
int a, len, resolu;
nu= nubase->first;
@@ -834,7 +834,7 @@ static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase)
resolu= nu->resolu;
if(!check_valid_nurb_u(nu));
- else if((nu->type & 7)==CU_BEZIER) {
+ else if(nu->type == CU_BEZIER) {
/* count */
len= 0;
@@ -886,11 +886,15 @@ static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase)
data+= 3;
}
else {
- v1= prevbezt->vec[1];
- v2= bezt->vec[0];
- forward_diff_bezier(v1[0], v1[3], v2[0], v2[3], data, resolu, 3);
- forward_diff_bezier(v1[1], v1[4], v2[1], v2[4], data+1, resolu, 3);
- forward_diff_bezier(v1[2], v1[5], v2[2], v2[5], data+2, resolu, 3);
+ int j;
+ for(j=0; j<3; j++) {
+ forward_diff_bezier( prevbezt->vec[1][j],
+ prevbezt->vec[2][j],
+ bezt->vec[0][j],
+ bezt->vec[1][j],
+ data+j, resolu, 3*sizeof(float));
+ }
+
data+= 3*resolu;
}
@@ -902,7 +906,7 @@ static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase)
bezt++;
}
}
- else if((nu->type & 7)==CU_NURBS) {
+ else if(nu->type == CU_NURBS) {
len= (resolu*SEGMENTSU(nu));
dl= MEM_callocN(sizeof(DispList), "makeDispListsurf");
@@ -917,9 +921,9 @@ static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase)
data= dl->verts;
if(nu->flagu & CU_CYCLIC) dl->type= DL_POLY;
else dl->type= DL_SEGM;
- makeNurbcurve(nu, data, NULL, NULL, resolu);
+ makeNurbcurve(nu, data, NULL, NULL, resolu, 3*sizeof(float));
}
- else if((nu->type & 7)==CU_POLY) {
+ else if(nu->type == CU_POLY) {
len= nu->pntsu;
dl= MEM_callocN(sizeof(DispList), "makeDispListpoly");
dl->verts= MEM_callocN(len*3*sizeof(float), "dlverts");
@@ -1424,7 +1428,7 @@ void makeDispListSurf(Scene *scene, Object *ob, ListBase *dispbase, int forRende
if(nu->flagu & CU_CYCLIC) dl->type= DL_POLY;
else dl->type= DL_SEGM;
- makeNurbcurve(nu, data, NULL, NULL, nu->resolu);
+ makeNurbcurve(nu, data, NULL, NULL, nu->resolu, 3*sizeof(float));
}
else {
len= (nu->pntsu*nu->resolu) * (nu->pntsv*nu->resolv);
@@ -1539,9 +1543,9 @@ void makeDispListCurveTypes(Scene *scene, Object *ob, int forOrco)
bevp= (BevPoint *)(bl+1);
data= dl->verts;
while(a--) {
- data[0]= bevp->x+widfac*bevp->sina;
- data[1]= bevp->y+widfac*bevp->cosa;
- data[2]= bevp->z;
+ data[0]= bevp->vec[0]+widfac*bevp->sina;
+ data[1]= bevp->vec[1]+widfac*bevp->cosa;
+ data[2]= bevp->vec[2];
bevp++;
data+=3;
}
@@ -1581,7 +1585,7 @@ void makeDispListCurveTypes(Scene *scene, Object *ob, int forOrco)
fac = calc_taper(scene, cu->taperobj, a, bl->nr);
}
- if (bevp->f1) {
+ if (bevp->split_tag) {
dl->bevelSplitFlag[a>>5] |= 1<<(a&0x1F);
}
@@ -1595,16 +1599,16 @@ void makeDispListCurveTypes(Scene *scene, Object *ob, int forOrco)
vec[1]= fp1[2];
vec[2]= 0.0;
- Mat3MulVecfl(bevp->mat, vec);
+ QuatMulVecf(bevp->quat, vec);
- data[0]= bevp->x+ fac*vec[0];
- data[1]= bevp->y+ fac*vec[1];
- data[2]= bevp->z+ fac*vec[2];
+ data[0]= bevp->vec[0] + fac*vec[0];
+ data[1]= bevp->vec[1] + fac*vec[1];
+ data[2]= bevp->vec[2] + fac*vec[2];
}
else {
- data[0]= bevp->x+ fac*(widfac+fp1[1])*bevp->sina;
- data[1]= bevp->y+ fac*(widfac+fp1[1])*bevp->cosa;
- data[2]= bevp->z+ fac*fp1[2];
+ data[0]= bevp->vec[0] + fac*(widfac+fp1[1])*bevp->sina;
+ data[1]= bevp->vec[1] + fac*(widfac+fp1[1])*bevp->cosa;
+ data[2]= bevp->vec[2] + fac*fp1[2];
}
}
}
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index 90bf08059d7..31f6e2c6067 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -698,19 +698,19 @@ float driver_get_target_value (ChannelDriver *driver, DriverTarget *dtar)
if (RNA_path_resolve(&id_ptr, path, &ptr, &prop)) {
switch (RNA_property_type(prop)) {
case PROP_BOOLEAN:
- if (RNA_property_array_length(prop))
+ if (RNA_property_array_length(&ptr, prop))
value= (float)RNA_property_boolean_get_index(&ptr, prop, index);
else
value= (float)RNA_property_boolean_get(&ptr, prop);
break;
case PROP_INT:
- if (RNA_property_array_length(prop))
+ if (RNA_property_array_length(&ptr, prop))
value= (float)RNA_property_int_get_index(&ptr, prop, index);
else
value= (float)RNA_property_int_get(&ptr, prop);
break;
case PROP_FLOAT:
- if (RNA_property_array_length(prop))
+ if (RNA_property_array_length(&ptr, prop))
value= RNA_property_float_get_index(&ptr, prop, index);
else
value= RNA_property_float_get(&ptr, prop);
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index 70901778585..411b2448dea 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -462,7 +462,7 @@ static void build_underline(Curve *cu, float x1, float y1, float x2, float y2, i
nu2->resolu= cu->resolu;
nu2->bezt = NULL;
nu2->knotsu = nu2->knotsv = NULL;
- nu2->flag= 0;
+ nu2->flag= CU_2D;
nu2->charidx = charidx+1000;
if (mat_nr > 0) nu2->mat_nr= mat_nr-1;
nu2->pntsu = 4;
@@ -495,7 +495,6 @@ static void build_underline(Curve *cu, float x1, float y1, float x2, float y2, i
nu2->bp[3].vec[2] = 0;
nu2->bp[3].vec[3] = 1.0;
- nu2->type = CU_2D;
BLI_addtail(&(cu->nurb), nu2);
}
@@ -1040,8 +1039,8 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
/* calc the right loc AND the right rot separately */
/* vec, tvec need 4 items */
- where_on_path(cu->textoncurve, ctime, vec, tvec);
- where_on_path(cu->textoncurve, ctime+dtime, tvec, rotvec);
+ where_on_path(cu->textoncurve, ctime, vec, tvec, NULL, NULL);
+ where_on_path(cu->textoncurve, ctime+dtime, tvec, rotvec, NULL, NULL);
VecMulf(vec, sizefac);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index dd8f44c71d5..43c4137e73e 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -214,6 +214,11 @@ bGPdata *gpencil_data_addnew (char name[])
/* initial settings */
gpd->flag = (GP_DATA_DISPINFO|GP_DATA_EXPAND);
+ /* for now, stick to view is also enabled by default
+ * since this is more useful...
+ */
+ gpd->flag |= GP_DATA_VIEWALIGN;
+
return gpd;
}
@@ -308,7 +313,7 @@ bGPdata *gpencil_data_duplicate (bGPdata *src)
void gpencil_frame_delete_laststroke (bGPDlayer *gpl, bGPDframe *gpf)
{
bGPDstroke *gps= (gpf) ? gpf->strokes.last : NULL;
- int cfra = 1; // XXX FIXME!!!
+ int cfra = (gpf) ? gpf->framenum : 0; /* assume that the current frame was not locked */
/* error checking */
if (ELEM(NULL, gpf, gps))
diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c
index 6fffbd794ef..6bb47bc0f0f 100644
--- a/source/blender/blenkernel/intern/group.c
+++ b/source/blender/blenkernel/intern/group.c
@@ -142,6 +142,16 @@ Group *add_group(char *name)
return group;
}
+Group *copy_group(Group *group)
+{
+ Group *groupn;
+
+ groupn= MEM_dupallocN(group);
+ BLI_duplicatelist(&groupn->gobject, &group->gobject);
+
+ return groupn;
+}
+
/* external */
void add_to_group(Group *group, Object *ob)
{
diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c
index 54366aadd92..3cff82f522a 100644
--- a/source/blender/blenkernel/intern/idprop.c
+++ b/source/blender/blenkernel/intern/idprop.c
@@ -167,7 +167,7 @@ void IDP_ResizeIDPArray(IDProperty *prop, int newlen)
for (i=newlen; i<prop->len; i++) {
IDP_FreeProperty(GETPROP(prop, i));
}
- memcpy(newarr, prop->data.pointer, newlen*prop->len*sizeof(IDProperty));
+ memcpy(newarr, prop->data.pointer, newlen*sizeof(IDProperty));
}
if(prop->data.pointer)
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 62af05fbc9a..cdb175ed661 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -38,6 +38,11 @@
#include <time.h>
+#ifdef _WIN32
+#define open _open
+#define close _close
+#endif
+
#include "MEM_guardedalloc.h"
#include "IMB_imbuf_types.h"
@@ -73,6 +78,8 @@
//XXX #include "BIF_editseq.h"
+#include "BLF_api.h"
+
#include "PIL_time.h"
#include "RE_pipeline.h"
@@ -978,7 +985,6 @@ static void stampdata(Scene *scene, StampData *stamp_data, int do_prefix)
if (do_prefix) strcpy(stamp_data->file, "File <untitled>");
else strcpy(stamp_data->file, "<untitled>");
}
- stamp_data->note[0] = '\0';
} else {
stamp_data->file[0] = '\0';
}
@@ -1046,8 +1052,8 @@ static void stampdata(Scene *scene, StampData *stamp_data, int do_prefix)
if (scene->r.stamp & R_STAMP_FRAME) {
char format[32];
- if (do_prefix) sprintf(format, "Frame %%0%di\n", 1 + (int) log10(scene->r.efra));
- else sprintf(format, "%%0%di\n", 1 + (int) log10(scene->r.efra));
+ if (do_prefix) sprintf(format, "Frame %%0%di", 1 + (int) log10(scene->r.efra));
+ else sprintf(format, "%%0%di", 1 + (int) log10(scene->r.efra));
sprintf (stamp_data->frame, format, scene->r.cfra);
} else {
stamp_data->frame[0] = '\0';
@@ -1083,131 +1089,172 @@ static void stampdata(Scene *scene, StampData *stamp_data, int do_prefix)
}
}
+// XXX - Bad level call.
+extern int datatoc_bmonofont_ttf_size;
+extern char datatoc_bmonofont_ttf[];
+
+// XXX - copied from text_font_begin
+static void stamp_font_begin(int size)
+{
+ static int mono= -1;
+
+ if (mono == -1)
+ mono= BLF_load_mem("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);
+
+ BLF_set(mono);
+ BLF_aspect(1.0);
+ BLF_size(size, 72);
+}
+
void BKE_stamp_buf(Scene *scene, unsigned char *rect, float *rectf, int width, int height, int channels)
{
-#if 0
-// XXX
-// This go back when BLF_draw_buffer is implemented - Diego
struct StampData stamp_data;
-
- int x=1,y=1;
- int font_height;
- int text_width;
- int text_pad;
- struct BMF_Font *font;
+ float w, h, pad;
+ int x, y;
if (!rect && !rectf)
return;
stampdata(scene, &stamp_data, 1);
-
- switch (scene->r.stamp_font_id) {
- case 1: /* tiny */
- font = BMF_GetFont(BMF_kHelveticaBold8);
- break;
- case 2: /* small */
- font = BMF_GetFont(BMF_kHelveticaBold10);
- break;
- case 3: /* medium */
- font = BMF_GetFont(BMF_kScreen12);
- break;
- case 0: /* large - default */
- font = BMF_GetFont(BMF_kScreen15);
- break;
- case 4: /* huge */
- font = BMF_GetFont(BMF_kHelveticaBold14);
- break;
- default:
- font = NULL;
- break;
- }
-
- font_height = BMF_GetFontHeight(font);
- /* All texts get halfspace+1 pixel on each side and 1 pix
- above and below as padding against their backing rectangles */
- text_pad = BMF_GetStringWidth(font, " ");
-
- x = 1; /* Inits for everyone, text position, so 1 for padding, not 0 */
- y = height - font_height - 1; /* Also inits for everyone, notice padding pixel */
-
+ stamp_font_begin(12);
+
+ BLF_buffer(rectf, rect, width, height, channels);
+ BLF_buffer_col(scene->r.fg_stamp[0], scene->r.fg_stamp[1], scene->r.fg_stamp[2], 1.0);
+ pad= BLF_width("--");
+
+ x= 0;
+ y= height;
+
if (stamp_data.file[0]) {
/* Top left corner */
- text_width = BMF_GetStringWidth(font, stamp_data.file);
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
- BMF_DrawStringBuf(font, stamp_data.file, x+(text_pad/2), y, scene->r.fg_stamp, rect, rectf, width, height, channels);
- y -= font_height+2; /* Top and bottom 1 pix padding each */
+ BLF_width_and_height(stamp_data.file, &w, &h);
+ y -= h;
+
+ /* also a little of space to the background. */
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y-3, w+3, y+h+3);
+
+ /* and draw the text. */
+ BLF_position(x, y, 0.0);
+ BLF_draw_buffer(stamp_data.file);
+
+ /* the extra pixel for background. */
+ y -= 4;
}
/* Top left corner, below File */
if (stamp_data.note[0]) {
- text_width = BMF_GetStringWidth(font, stamp_data.note);
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
- BMF_DrawStringBuf(font, stamp_data.note, x+(text_pad/2), y, scene->r.fg_stamp, rect, rectf, width, height, channels);
- y -= font_height+2; /* Top and bottom 1 pix padding each */
+ BLF_width_and_height(stamp_data.note, &w, &h);
+ y -= h;
+
+ /* and space for background. */
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-2, w+3, y+h+2);
+
+ BLF_position(x, y+1, 0.0);
+ BLF_draw_buffer(stamp_data.note);
+
+ /* the extra pixel for background. */
+ y -= 4;
}
/* Top left corner, below File (or Note) */
if (stamp_data.date[0]) {
- text_width = BMF_GetStringWidth(font, stamp_data.date);
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
- BMF_DrawStringBuf(font, stamp_data.date, x+(text_pad/2), y, scene->r.fg_stamp, rect, rectf, width, height, channels);
+ BLF_width_and_height(stamp_data.date, &w, &h);
+ y -= h;
+
+ /* and space for background. */
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-3, w+3, y+h+3);
+
+ BLF_position(x, y, 0.0);
+ BLF_draw_buffer(stamp_data.date);
}
+ x= 0;
+ y= 0;
+
/* Bottom left corner, leaving space for timing */
if (stamp_data.marker[0]) {
- x = 1;
- y = font_height+2+1; /* 2 for padding in TIME|FRAME fields below and 1 for padding in this one */
- text_width = BMF_GetStringWidth(font, stamp_data.marker);
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
- BMF_DrawStringBuf(font, stamp_data.marker, x+(text_pad/2), y, scene->r.fg_stamp, rect, rectf, width, height, channels);
+ BLF_width_and_height(stamp_data.marker, &w, &h);
+
+ /* extra space for background. */
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, w+2, y+h+3);
+
+ /* and pad the text. */
+ BLF_position(x, y+3, 0.0);
+ BLF_draw_buffer(stamp_data.marker);
+
+ /* space width. */
+ x += w + pad;
}
/* Left bottom corner */
if (stamp_data.time[0]) {
- x = 1;
- y = 1;
- text_width = BMF_GetStringWidth(font, stamp_data.time);
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
- BMF_DrawStringBuf(font, stamp_data.time, x+(text_pad/2), y, scene->r.fg_stamp, rect, rectf, width, height, channels);
- x += text_width+text_pad+2; /* Both sides have 1 pix additional padding each */
+ BLF_width_and_height(stamp_data.time, &w, &h);
+
+ /* extra space for background */
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, x+w+2, y+h+3);
+
+ /* and pad the text. */
+ BLF_position(x, y+3, 0.0);
+ BLF_draw_buffer(stamp_data.time);
+
+ /* space width. */
+ x += w + pad;
}
if (stamp_data.frame[0]) {
- text_width = BMF_GetStringWidth(font, stamp_data.frame);
- /* Left bottom corner (after SMPTE if exists) */
- if (!stamp_data.time[0]) x = 1;
- y = 1;
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
- BMF_DrawStringBuf(font, stamp_data.frame, x+(text_pad/2), y, scene->r.fg_stamp, rect, rectf, width, height, channels);
+ BLF_width_and_height(stamp_data.frame, &w, &h);
+
+ /* extra space for background. */
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, x+w+2, y+h+3);
+
+ /* and pad the text. */
+ BLF_position(x, y+3, 0.0);
+
+ BLF_draw_buffer(stamp_data.frame);
+
+ /* space width. */
+ x += w + pad;
}
if (stamp_data.camera[0]) {
- text_width = BMF_GetStringWidth(font, stamp_data.camera);
- /* Center of bottom edge */
- x = (width/2) - (BMF_GetStringWidth(font, stamp_data.camera)/2);
- y = 1;
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
- BMF_DrawStringBuf(font, stamp_data.camera, x+(text_pad/2), y, scene->r.fg_stamp, rect, rectf, width, height, channels);
+ BLF_width_and_height(stamp_data.camera, &w, &h);
+
+ /* extra space for background. */
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, x+w+2, y+h+3);
+ BLF_position(x, y+3, 0.0);
+ BLF_draw_buffer(stamp_data.camera);
}
if (stamp_data.scene[0]) {
- text_width = BMF_GetStringWidth(font, stamp_data.scene);
- /* Bottom right corner */
- x = width - (text_width+1+text_pad);
- y = 1;
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
- BMF_DrawStringBuf(font, stamp_data.scene, x+(text_pad/2), y, scene->r.fg_stamp, rect, rectf, width, height, channels);
+ BLF_width_and_height(stamp_data.scene, &w, &h);
+
+ /* Bottom right corner, with an extra space because blenfont is too strict! */
+ x= width - w - 2;
+
+ /* extra space for background. */
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, x+w+3, y+h+3);
+
+ /* and pad the text. */
+ BLF_position(x, y+3, 0.0);
+ BLF_draw_buffer(stamp_data.scene);
}
if (stamp_data.strip[0]) {
- text_width = BMF_GetStringWidth(font, stamp_data.strip);
- /* Top right corner */
- x = width - (text_width+1+text_pad);
- y = height - font_height - 1;
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
- BMF_DrawStringBuf(font, stamp_data.strip, x+(text_pad/2), y, scene->r.fg_stamp, rect, rectf, width, height, channels);
- }
-#endif // 0 XXX
+ BLF_width_and_height(stamp_data.scene, &w, &h);
+
+ /* Top right corner, with an extra space because blenfont is too strict! */
+ x= width - w - pad;
+ y= height - h;
+
+ /* extra space for background. */
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y-3, x+w+pad, y+h+3);
+
+ BLF_position(x, y, 0.0);
+ BLF_draw_buffer(stamp_data.strip);
+ }
+
+ /* cleanup the buffer. */
+ BLF_buffer(NULL, NULL, 0, 0, 0);
}
void BKE_stamp_info(Scene *scene, struct ImBuf *ibuf)
diff --git a/source/blender/blenkernel/intern/implicit.c b/source/blender/blenkernel/intern/implicit.c
index fc5213d5532..0bce71b57eb 100644
--- a/source/blender/blenkernel/intern/implicit.c
+++ b/source/blender/blenkernel/intern/implicit.c
@@ -1183,7 +1183,8 @@ DO_INLINE void dfdx_spring(float to[3][3], float dir[3],float length,float L,fl
//return ( (I-outerprod(dir,dir))*Min(1.0f,rest/length) - I) * -k;
mul_fvectorT_fvector(to, dir, dir);
sub_fmatrix_fmatrix(to, I, to);
- mul_fmatrix_S(to, (((L/length)> 1.0f) ? (1.0f): (L/length)));
+
+ mul_fmatrix_S(to, (L/length));
sub_fmatrix_fmatrix(to, to, I);
mul_fmatrix_S(to, -k);
}
@@ -1218,6 +1219,8 @@ DO_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
float nulldfdx[3][3]={ {0,0,0}, {0,0,0}, {0,0,0}};
float scaling = 0.0;
+
+ int no_compress = clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_NO_SPRING_COMPRESS;
VECCOPY(s->f, nullf);
cp_fmatrix(s->dfdx, nulldfdx);
@@ -1254,7 +1257,7 @@ DO_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
// calculate force of structural + shear springs
if((s->type & CLOTH_SPRING_TYPE_STRUCTURAL) || (s->type & CLOTH_SPRING_TYPE_SHEAR))
{
- if(length > L) // only on elonglation
+ if(length > L || no_compress)
{
s->flags |= CLOTH_SPRING_FLAG_NEEDED;
@@ -1393,6 +1396,84 @@ float calculateVertexWindForce(float wind[3], float vertexnormal[3])
return (INPR(wind, vertexnormal));
}
+typedef struct HairGridVert {
+ float velocity[3];
+ float density;
+} HairGridVert;
+/* Smoothing of hair velocities:
+ * adapted from
+ Volumetric Methods for Simulation and Rendering of Hair
+ by Lena Petrovic, Mark Henne and John Anderson
+ * Pixar Technical Memo #06-08, Pixar Animation Studios
+ */
+static void hair_velocity_smoothing(float smoothfac, lfVector *lF, lfVector *lX, lfVector *lV, int numverts)
+{
+ /* TODO: this is an initial implementation and should be made much better in due time */
+
+ /* 10x10x10 grid gives nice initial results */
+ HairGridVert grid[10][10][10];
+ float gmin[3], gmax[3], density;
+ int v = 0;
+ int i = 0;
+ int j = 0;
+ int k = 0;
+ lfVector temp;
+
+ INIT_MINMAX(gmin, gmax);
+
+ for(i = 0; i < numverts; i++)
+ DO_MINMAX(lX[i], gmin, gmax);
+
+ /* initialize grid */
+ for(i = 0; i < 10; i++) {
+ for(j = 0; j < 10; j++) {
+ for(k = 0; k < 10; k++) {
+ grid[i][j][k].velocity[0] = 0.0f;
+ grid[i][j][k].velocity[1] = 0.0f;
+ grid[i][j][k].velocity[2] = 0.0f;
+ grid[i][j][k].density = 0.0f;
+ }
+ }
+ }
+
+ /* gather velocities & density */
+ for(v = 0; v < numverts; v++) {
+ i = (int)( (lX[v][0] - gmin[0]) / (gmax[0] - gmin[0]) * 9.99f );
+ j = (int)( (lX[v][1] - gmin[1]) / (gmax[1] - gmin[1]) * 9.99f );
+ k = (int)( (lX[v][2] - gmin[2]) / (gmax[2] - gmin[2]) * 9.99f );
+
+ grid[i][j][k].velocity[0] += lV[v][0];
+ grid[i][j][k].velocity[1] += lV[v][1];
+ grid[i][j][k].velocity[2] += lV[v][2];
+ grid[i][j][k].density += 1.0f;
+ }
+
+ /* divide velocity with density */
+ for(i = 0; i < 10; i++) {
+ for(j = 0; j < 10; j++) {
+ for(k = 0; k < 10; k++) {
+ density = grid[i][j][k].density;
+ if(density > 0.0f) {
+ grid[i][j][k].velocity[0] /= density;
+ grid[i][j][k].velocity[1] /= density;
+ grid[i][j][k].velocity[2] /= density;
+ }
+ }
+ }
+ }
+
+ /* calculate forces */
+ for(v = 0; v < numverts; v++) {
+ i = (int)( (lX[v][0] - gmin[0]) / (gmax[0] - gmin[0]) * 9.99f );
+ j = (int)( (lX[v][1] - gmin[1]) / (gmax[1] - gmin[1]) * 9.99f );
+ k = (int)( (lX[v][2] - gmin[2]) / (gmax[2] - gmin[2]) * 9.99f );
+
+ /* 2.0f is an experimental value that seems to give good results */
+ lF[v][0] += 2.0f * smoothfac * (grid[i][j][k].velocity[0] - lV[v][0]);
+ lF[v][1] += 2.0f * smoothfac * (grid[i][j][k].velocity[1] - lV[v][1]);
+ lF[v][2] += 2.0f * smoothfac * (grid[i][j][k].velocity[2] - lV[v][2]);
+ }
+}
static void cloth_calc_force(ClothModifierData *clmd, float frame, lfVector *lF, lfVector *lX, lfVector *lV, fmatrix3x3 *dFdV, fmatrix3x3 *dFdX, ListBase *effectors, float time, fmatrix3x3 *M)
{
/* Collect forces and derivatives: F,dFdX,dFdV */
@@ -1416,6 +1497,9 @@ static void cloth_calc_force(ClothModifierData *clmd, float frame, lfVector *lF,
init_lfvector(lF, gravity, numverts);
+ if(clmd->sim_parms->velocity_smooth > 0.0f)
+ hair_velocity_smoothing(clmd->sim_parms->velocity_smooth, lF, lX, lV, numverts);
+
/* multiply lF with mass matrix
// force = mass * acceleration (in this case: gravity)
*/
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index a2fa97cabc9..39f9ed808fd 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -266,66 +266,91 @@ void sort_keys(Key *key)
/**************** do the key ****************/
+void key_curve_position_weights(float t, float *data, int type)
+{
+ float t2, t3, fc;
+
+ if(type==KEY_LINEAR) {
+ data[0]= 0.0f;
+ data[1]= -t + 1.0f;
+ data[2]= t;
+ data[3]= 0.0f;
+ }
+ else if(type==KEY_CARDINAL) {
+ t2= t*t;
+ t3= t2*t;
+ fc= 0.71f;
+
+ data[0]= -fc*t3 + 2.0f*fc*t2 - fc*t;
+ data[1]= (2.0f-fc)*t3 + (fc-3.0f)*t2 + 1.0f;
+ data[2]= (fc-2.0f)*t3 + (3.0f-2.0f*fc)*t2 + fc*t;
+ data[3]= fc*t3 - fc*t2;
+ }
+ else if(type==KEY_BSPLINE) {
+ t2= t*t;
+ t3= t2*t;
+
+ data[0]= -0.16666666f*t3 + 0.5f*t2 - 0.5f*t + 0.16666666f;
+ data[1]= 0.5f*t3 - t2 + 0.6666666f;
+ data[2]= -0.5f*t3 + 0.5f*t2 + 0.5f*t + 0.16666666f;
+ data[3]= 0.16666666f*t3;
+ }
+}
-void set_four_ipo(float d, float *data, int type)
+/* first derivative */
+void key_curve_tangent_weights(float t, float *data, int type)
{
- float d2, d3, fc;
+ float t2, fc;
if(type==KEY_LINEAR) {
data[0]= 0.0f;
- data[1]= 1.0f-d;
- data[2]= d;
+ data[1]= -1.0f;
+ data[2]= 1.0f;
data[3]= 0.0f;
}
- else {
- d2= d*d;
- d3= d2*d;
+ else if(type==KEY_CARDINAL) {
+ t2= t*t;
+ fc= 0.71f;
- if(type==KEY_CARDINAL) {
-
- fc= 0.71f;
-
- data[0]= -fc*d3 +2.0f*fc*d2 -fc*d;
- data[1]= (2.0f-fc)*d3 +(fc-3.0f)*d2 +1.0f;
- data[2]= (fc-2.0f)*d3 +(3.0f-2.0f*fc)*d2 +fc*d;
- data[3]= fc*d3 -fc*d2;
- }
- else if(type==KEY_BSPLINE) {
+ data[0]= -3.0f*fc*t2 +4.0f*fc*t - fc;
+ data[1]= 3.0f*(2.0f-fc)*t2 +2.0f*(fc-3.0f)*t;
+ data[2]= 3.0f*(fc-2.0f)*t2 +2.0f*(3.0f-2.0f*fc)*t + fc;
+ data[3]= 3.0f*fc*t2 -2.0f*fc*t;
+ }
+ else if(type==KEY_BSPLINE) {
+ t2= t*t;
- data[0]= -0.16666666f*d3 +0.5f*d2 -0.5f*d +0.16666666f;
- data[1]= 0.5f*d3 -d2 +0.6666666f;
- data[2]= -0.5f*d3 +0.5f*d2 +0.5f*d +0.16666666f;
- data[3]= 0.16666666f*d3 ;
- }
+ data[0]= -0.5f*t2 + t - 0.5f;
+ data[1]= 1.5f*t2 - 2.0f*t;
+ data[2]= -1.5f*t2 + t + 0.5f;
+ data[3]= 0.5f*t2;
}
}
-void set_afgeleide_four_ipo(float d, float *data, int type)
+/* second derivative */
+void key_curve_normal_weights(float t, float *data, int type)
{
- float d2, fc;
+ float fc;
if(type==KEY_LINEAR) {
-
+ data[0]= 0.0f;
+ data[1]= 0.0f;
+ data[2]= 0.0f;
+ data[3]= 0.0f;
}
- else {
- d2= d*d;
+ else if(type==KEY_CARDINAL) {
+ fc= 0.71f;
- if(type==KEY_CARDINAL) {
-
- fc= 0.71f;
-
- data[0]= -3.0f*fc*d2 +4.0f*fc*d -fc;
- data[1]= 3.0f*(2.0f-fc)*d2 +2.0f*(fc-3.0f)*d;
- data[2]= 3.0f*(fc-2.0f)*d2 +2.0f*(3.0f-2.0f*fc)*d +fc;
- data[3]= 3.0f*fc*d2 -2.0f*fc*d;
- }
- else if(type==KEY_BSPLINE) {
-
- data[0]= -0.16666666f*3.0f*d2 +d -0.5f;
- data[1]= 1.5f*d2 -2.0f*d;
- data[2]= -1.5f*d2 +d +0.5f;
- data[3]= 0.16666666f*3.0f*d2 ;
- }
+ data[0]= -6.0f*fc*t + 4.0f*fc;
+ data[1]= 6.0f*(2.0f-fc)*t + 2.0f*(fc-3.0f);
+ data[2]= 6.0f*(fc-2.0f)*t + 2.0f*(3.0f-2.0f*fc);
+ data[3]= 6.0f*fc*t - 2.0f*fc;
+ }
+ else if(type==KEY_BSPLINE) {
+ data[0]= -1.0f*t + 1.0f;
+ data[1]= 3.0f*t - 2.0f;
+ data[2]= -3.0f*t + 1.0f;
+ data[3]= 1.0f*t;
}
}
@@ -436,10 +461,10 @@ static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float *t, int cycl)
/* interpolation */
- set_four_ipo(d, t, k[1]->type);
+ key_curve_position_weights(d, t, k[1]->type);
if(k[1]->type != k[2]->type) {
- set_four_ipo(d, fval, k[2]->type);
+ key_curve_position_weights(d, fval, k[2]->type);
temp= 1.0f-d;
t[0]= temp*t[0]+ d*fval[0];
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index 67d63d527cb..730a12bea09 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -364,7 +364,7 @@ void calc_latt_deform(Object *ob, float *co, float weight)
u= (vec[0]-lt->fu)/lt->du;
ui= (int)floor(u);
u -= ui;
- set_four_ipo(u, tu, lt->typeu);
+ key_curve_position_weights(u, tu, lt->typeu);
}
else {
tu[0]= tu[2]= tu[3]= 0.0; tu[1]= 1.0;
@@ -375,7 +375,7 @@ void calc_latt_deform(Object *ob, float *co, float weight)
v= (vec[1]-lt->fv)/lt->dv;
vi= (int)floor(v);
v -= vi;
- set_four_ipo(v, tv, lt->typev);
+ key_curve_position_weights(v, tv, lt->typev);
}
else {
tv[0]= tv[2]= tv[3]= 0.0; tv[1]= 1.0;
@@ -386,7 +386,7 @@ void calc_latt_deform(Object *ob, float *co, float weight)
w= (vec[2]-lt->fw)/lt->dw;
wi= (int)floor(w);
w -= wi;
- set_four_ipo(w, tw, lt->typew);
+ key_curve_position_weights(w, tw, lt->typew);
}
else {
tw[0]= tw[2]= tw[3]= 0.0; tw[1]= 1.0;
@@ -472,7 +472,7 @@ static void init_curve_deform(Object *par, Object *ob, CurveDeform *cd, int dloc
}
/* this makes sure we can extend for non-cyclic. *vec needs 4 items! */
-static int where_on_path_deform(Object *ob, float ctime, float *vec, float *dir) /* returns OK */
+static int where_on_path_deform(Object *ob, float ctime, float *vec, float *dir, float *quat, float *radius) /* returns OK */
{
Curve *cu= ob->data;
BevList *bl;
@@ -490,21 +490,25 @@ static int where_on_path_deform(Object *ob, float ctime, float *vec, float *dir)
else ctime1= ctime;
/* vec needs 4 items */
- if(where_on_path(ob, ctime1, vec, dir)) {
+ if(where_on_path(ob, ctime1, vec, dir, quat, radius)) {
if(cycl==0) {
Path *path= cu->path;
float dvec[3];
if(ctime < 0.0) {
- VecSubf(dvec, path->data+4, path->data);
+ VecSubf(dvec, path->data[1].vec, path->data[0].vec);
VecMulf(dvec, ctime*(float)path->len);
VECADD(vec, vec, dvec);
+ if(quat) QUATCOPY(quat, path->data[0].quat);
+ if(radius) *radius= path->data[0].radius;
}
else if(ctime > 1.0) {
- VecSubf(dvec, path->data+4*path->len-4, path->data+4*path->len-8);
+ VecSubf(dvec, path->data[path->len-1].vec, path->data[path->len-2].vec);
VecMulf(dvec, (ctime-1.0)*(float)path->len);
VECADD(vec, vec, dvec);
+ if(quat) QUATCOPY(quat, path->data[path->len-1].quat);
+ if(radius) *radius= path->data[path->len-1].radius;
}
}
return 1;
@@ -520,7 +524,7 @@ static int where_on_path_deform(Object *ob, float ctime, float *vec, float *dir)
static int calc_curve_deform(Scene *scene, Object *par, float *co, short axis, CurveDeform *cd, float *quatp)
{
Curve *cu= par->data;
- float fac, loc[4], dir[3], cent[3];
+ float fac, loc[4], dir[3], cent[3], radius;
short upflag, index;
if(axis==MOD_CURVE_POSX || axis==MOD_CURVE_NEGX) {
@@ -575,7 +579,7 @@ static int calc_curve_deform(Scene *scene, Object *par, float *co, short axis, C
}
#endif // XXX old animation system
- if( where_on_path_deform(par, fac, loc, dir)) { /* returns OK */
+ if( where_on_path_deform(par, fac, loc, dir, NULL, &radius)) { /* returns OK */
float q[4], mat[3][3], quat[4];
if(cd->no_rot_axis) /* set by caller */
@@ -595,7 +599,14 @@ static int calc_curve_deform(Scene *scene, Object *par, float *co, short axis, C
QuatMul(quat, q, quat);
}
QuatToMat3(quat, mat);
-
+
+ if(cu->flag & CU_PATH_RADIUS) {
+ float tmat[3][3], rmat[3][3];
+ Mat3Scale(tmat, radius);
+ Mat3MulMat3(rmat, mat, tmat);
+ Mat3CpyMat3(mat, rmat);
+ }
+
/* local rotation */
Mat3MulVecfl(mat, cent);
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 3c8bf9200f8..da7692d0cdb 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -119,6 +119,13 @@
#define MAX_IDPUP 60 /* was 24 */
+/* GS reads the memory pointed at in a specific ordering.
+ only use this definition, makes little and big endian systems
+ work fine, in conjunction with MAKE_ID */
+
+/* from blendef: */
+#define GS(a) (*((short *)(a)))
+
/* ************* general ************************ */
void id_lib_extern(ID *id)
@@ -148,6 +155,220 @@ void id_us_min(ID *id)
id->us--;
}
+int id_make_local(ID *id, int test)
+{
+ if(id->flag & LIB_INDIRECT)
+ return 0;
+
+ switch(GS(id->name)) {
+ case ID_SCE:
+ return 0; /* not implemented */
+ case ID_LI:
+ return 0; /* can't be linked */
+ case ID_OB:
+ if(!test) make_local_object((Object*)id);
+ return 1;
+ case ID_ME:
+ if(!test) {
+ make_local_mesh((Mesh*)id);
+ make_local_key(((Mesh*)id)->key);
+ }
+ return 1;
+ case ID_CU:
+ if(!test) {
+ make_local_curve((Curve*)id);
+ make_local_key(((Curve*)id)->key);
+ }
+ return 1;
+ case ID_MB:
+ if(!test) make_local_mball((MetaBall*)id);
+ return 1;
+ case ID_MA:
+ if(!test) make_local_material((Material*)id);
+ return 1;
+ case ID_TE:
+ if(!test) make_local_texture((Tex*)id);
+ 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);
+ make_local_key(((Lattice*)id)->key);
+ }
+ return 1;
+ case ID_LA:
+ if(!test) make_local_lamp((Lamp*)id);
+ return 1;
+ case ID_CA:
+ if(!test) make_local_camera((Camera*)id);
+ return 1;
+ case ID_IP:
+ return 0; /* deprecated */
+ case ID_KE:
+ if(!test) make_local_key((Key*)id);
+ return 1;
+ case ID_WO:
+ if(!test) make_local_world((World*)id);
+ return 1;
+ case ID_SCR:
+ return 0; /* can't be linked */
+ case ID_VF:
+ return 0; /* not implemented */
+ case ID_TXT:
+ return 0; /* not implemented */
+ case ID_SCRIPT:
+ return 0; /* deprecated */
+ case ID_SO:
+ return 0; /* not implemented */
+ case ID_GR:
+ return 0; /* not implemented */
+ case ID_AR:
+ if(!test) make_local_armature((bArmature*)id);
+ return 1;
+ case ID_AC:
+ if(!test) make_local_action((bAction*)id);
+ return 1;
+ case ID_NT:
+ return 0; /* not implemented */
+ case ID_BR:
+ if(!test) make_local_brush((Brush*)id);
+ return 1;
+ case ID_PA:
+ if(!test) make_local_particlesettings((ParticleSettings*)id);
+ return 1;
+ case ID_WM:
+ return 0; /* can't be linked */
+ case ID_GD:
+ return 0; /* not implemented */
+ }
+
+ return 0;
+}
+
+int id_copy(ID *id, ID **newid, int test)
+{
+ if(!test) *newid= NULL;
+
+ /* conventions:
+ * - make shallow copy, only this ID block
+ * - id.us of the new ID is set to 1 */
+ switch(GS(id->name)) {
+ case ID_SCE:
+ return 0; /* can't be copied from here */
+ case ID_LI:
+ return 0; /* can't be copied from here */
+ case ID_OB:
+ if(!test) *newid= (ID*)copy_object((Object*)id);
+ return 1;
+ case ID_ME:
+ if(!test) *newid= (ID*)copy_mesh((Mesh*)id);
+ return 1;
+ case ID_CU:
+ if(!test) *newid= (ID*)copy_curve((Curve*)id);
+ return 1;
+ case ID_MB:
+ if(!test) *newid= (ID*)copy_mball((MetaBall*)id);
+ return 1;
+ case ID_MA:
+ if(!test) *newid= (ID*)copy_material((Material*)id);
+ return 1;
+ case ID_TE:
+ if(!test) *newid= (ID*)copy_texture((Tex*)id);
+ return 1;
+ case ID_IM:
+ return 0; /* not implemented */
+ case ID_WV:
+ return 0; /* deprecated */
+ case ID_LT:
+ if(!test) *newid= (ID*)copy_lattice((Lattice*)id);
+ return 1;
+ case ID_LA:
+ if(!test) *newid= (ID*)copy_lamp((Lamp*)id);
+ return 1;
+ case ID_CA:
+ if(!test) *newid= (ID*)copy_camera((Camera*)id);
+ return 1;
+ case ID_IP:
+ return 0; /* deprecated */
+ case ID_KE:
+ if(!test) *newid= (ID*)copy_key((Key*)id);
+ return 1;
+ case ID_WO:
+ if(!test) *newid= (ID*)copy_world((World*)id);
+ return 1;
+ case ID_SCR:
+ return 0; /* can't be copied from here */
+ case ID_VF:
+ return 0; /* not implemented */
+ case ID_TXT:
+ if(!test) *newid= (ID*)copy_text((Text*)id);
+ return 1;
+ case ID_SCRIPT:
+ return 0; /* deprecated */
+ case ID_SO:
+ return 0; /* not implemented */
+ case ID_GR:
+ if(!test) *newid= (ID*)copy_group((Group*)id);
+ return 1;
+ case ID_AR:
+ if(!test) *newid= (ID*)copy_armature((bArmature*)id);
+ return 1;
+ case ID_AC:
+ if(!test) *newid= (ID*)copy_action((bAction*)id);
+ return 1;
+ case ID_NT:
+ if(!test) *newid= (ID*)ntreeCopyTree((bNodeTree*)id, 0);
+ return 1;
+ case ID_BR:
+ if(!test) *newid= (ID*)copy_brush((Brush*)id);
+ return 1;
+ case ID_PA:
+ if(!test) *newid= (ID*)psys_copy_settings((ParticleSettings*)id);
+ return 1;
+ case ID_WM:
+ return 0; /* can't be copied from here */
+ case ID_GD:
+ return 0; /* not implemented */
+ }
+
+ return 0;
+}
+
+int id_unlink(ID *id, int test)
+{
+ Main *mainlib= G.main;
+ ListBase *lb;
+
+ switch(GS(id->name)) {
+ case ID_TXT:
+ if(test) return 1;
+ unlink_text(mainlib, (Text*)id);
+ break;
+ case ID_GR:
+ if(test) return 1;
+ unlink_group((Group*)id);
+ break;
+ case ID_OB:
+ if(test) return 1;
+ unlink_object(NULL, (Object*)id);
+ break;
+ }
+
+ if(id->us == 0) {
+ if(test) return 1;
+
+ lb= wich_libbase(mainlib, GS(id->name));
+ free_libblock(lb, id);
+
+ return 1;
+ }
+
+ return 0;
+}
+
ListBase *wich_libbase(Main *mainlib, short type)
{
switch( type ) {
@@ -234,6 +455,17 @@ void flag_all_listbases_ids(short flag, short value)
while(a--) flag_listbase_ids(lbarray[a], flag, value);
}
+void recalc_all_library_objects(struct Main *main)
+{
+ /* DISPLISTS? */
+ Object *ob= main->object.first;
+ while(ob) {
+ if(ob->id.lib) {
+ ob->recalc |= OB_RECALC;
+ }
+ ob= ob->id.next;
+ }
+}
/* note: MAX_LIBARRAY define should match this code */
int set_listbasepointers(Main *main, ListBase **lb)
@@ -409,13 +641,6 @@ void *alloc_libblock(ListBase *lb, short type, const char *name)
return id;
}
-/* GS reads the memory pointed at in a specific ordering.
- only use this definition, makes little and big endian systems
- work fine, in conjunction with MAKE_ID */
-
-/* from blendef: */
-#define GS(a) (*((short *)(a)))
-
/* by spec, animdata is first item after ID */
/* we still read ->adt itself, to ensure compiler warns when it doesnt exist */
static void id_copy_animdata(ID *id)
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 50db2bfe706..e6f9ac2f404 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -170,7 +170,22 @@ void init_material(Material *ma)
ma->sss_front= 1.0f;
ma->sss_back= 1.0f;
- ma->mode= MA_TRACEBLE|MA_SHADBUF|MA_SHADOW|MA_RAYBIAS|MA_TANGENT_STR;
+ ma->vol.density = 1.0f;
+ ma->vol.emission = 0.0f;
+ ma->vol.absorption = 1.0f;
+ ma->vol.scattering = 1.0f;
+ ma->vol.emission_col[0] = ma->vol.emission_col[1] = ma->vol.emission_col[2] = 1.0f;
+ ma->vol.absorption_col[0] = ma->vol.absorption_col[1] = ma->vol.absorption_col[2] = 0.0f;
+ ma->vol.density_scale = 1.0f;
+ ma->vol.depth_cutoff = 0.01f;
+ ma->vol.stepsize_type = MA_VOL_STEP_RANDOMIZED;
+ ma->vol.stepsize = 0.2f;
+ ma->vol.shade_stepsize = 0.2f;
+ ma->vol.shade_type = MA_VOL_SHADE_SINGLE;
+ ma->vol.shadeflag |= MA_VOL_PRECACHESHADING;
+ ma->vol.precache_resolution = 50;
+
+ ma->mode= MA_TRACEBLE|MA_SHADBUF|MA_SHADOW|MA_RAYBIAS|MA_TANGENT_STR|MA_ZTRANSP;
ma->preview = NULL;
}
@@ -1016,15 +1031,15 @@ void ramp_blend(int type, float *r, float *g, float *b, float fac, float *col)
}
break;
case MA_RAMP_DARK:
- tmp= fac*col[0];
- if(tmp < *r) *r= tmp;
- if(g) {
- tmp= fac*col[1];
- if(tmp < *g) *g= tmp;
- tmp= fac*col[2];
- if(tmp < *b) *b= tmp;
- }
- break;
+ tmp=col[0]+((1-col[0])*facm);
+ if(tmp < *r) *r= tmp;
+ if(g) {
+ tmp=col[1]+((1-col[1])*facm);
+ if(tmp < *g) *g= tmp;
+ tmp=col[2]+((1-col[2])*facm);
+ if(tmp < *b) *b= tmp;
+ }
+ break;
case MA_RAMP_LIGHT:
tmp= fac*col[0];
if(tmp > *r) *r= tmp;
@@ -1154,8 +1169,37 @@ void ramp_blend(int type, float *r, float *g, float *b, float fac, float *col)
}
}
break;
- }
-
+ case MA_RAMP_SOFT:
+ if (g){
+ float scr, scg, scb;
+
+ /* first calculate non-fac based Screen mix */
+ scr = 1.0 - ((1.0 - col[0])) * (1.0 - *r);
+ scg = 1.0 - ((1.0 - col[1])) * (1.0 - *g);
+ scb = 1.0 - ((1.0 - col[2])) * (1.0 - *b);
+
+ *r = facm*(*r) + fac*(((1.0 - *r) * col[0] * (*r)) + (*r * scr));
+ *g = facm*(*g) + fac*(((1.0 - *g) * col[1] * (*g)) + (*g * scg));
+ *b = facm*(*b) + fac*(((1.0 - *b) * col[2] * (*b)) + (*b * scb));
+ }
+ break;
+ case MA_RAMP_LINEAR:
+ if (col[0] > 0.5)
+ *r = *r + fac*(2*(col[0]-0.5));
+ else
+ *r = *r + fac*(2*(col[0]) - 1);
+ if (g){
+ if (col[1] > 0.5)
+ *g = *g + fac*(2*(col[1]-0.5));
+ else
+ *g = *g + fac*(2*(col[1]) -1);
+ if (col[2] > 0.5)
+ *b = *b + fac*(2*(col[2]-0.5));
+ else
+ *b = *b + fac*(2*(col[2]) - 1);
+ }
+ break;
+ }
}
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index c7454d3b832..c92eda6d169 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -977,7 +977,7 @@ void mesh_set_smooth_flag(Object *meshOb, int enableSmooth)
}
}
-// XXX do this in caller DAG_object_flush_update(scene, meshOb, OB_RECALC_DATA);
+// XXX do this in caller DAG_id_flush_update(&me->id, OB_RECALC_DATA);
}
void mesh_calc_normals(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float **faceNors_r)
@@ -1265,7 +1265,7 @@ void mesh_pmv_revert(Object *ob, Mesh *me)
MEM_freeN(me->pv->vert_map);
me->pv->vert_map= NULL;
-// XXX do this in caller DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+// XXX do this in caller DAG_id_flush_update(&me->id, OB_RECALC_DATA);
}
}
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c
index 53d1baa5c9c..f06173264ee 100644
--- a/source/blender/blenkernel/intern/modifier.c
+++ b/source/blender/blenkernel/intern/modifier.c
@@ -73,11 +73,12 @@
#include "BLI_editVert.h"
-#include "MTC_matrixops.h"
-#include "MTC_vectorops.h"
+
+
#include "BKE_main.h"
#include "BKE_anim.h"
+#include "BKE_action.h"
#include "BKE_bmesh.h"
// XXX #include "BKE_booleanops.h"
#include "BKE_cloth.h"
@@ -1189,7 +1190,7 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
if(amd->end_cap && amd->end_cap != ob)
end_cap = mesh_get_derived_final(scene, amd->end_cap, CD_MASK_MESH);
- MTC_Mat4One(offset);
+ Mat4One(offset);
indexMap = MEM_callocN(sizeof(*indexMap) * dm->getNumVerts(dm),
"indexmap");
@@ -1211,14 +1212,14 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
float result_mat[4][4];
if(ob)
- MTC_Mat4Invert(obinv, ob->obmat);
+ Mat4Invert(obinv, ob->obmat);
else
- MTC_Mat4One(obinv);
+ Mat4One(obinv);
- MTC_Mat4MulSerie(result_mat, offset,
+ Mat4MulSerie(result_mat, offset,
obinv, amd->offset_ob->obmat,
NULL, NULL, NULL, NULL, NULL);
- MTC_Mat4CpyMat4(offset, result_mat);
+ Mat4CpyMat4(offset, result_mat);
}
if(amd->fit_type == MOD_ARR_FITCURVE && amd->curve_ob) {
@@ -1243,7 +1244,7 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
prescribed length */
if(amd->fit_type == MOD_ARR_FITLENGTH
|| amd->fit_type == MOD_ARR_FITCURVE) {
- float dist = sqrt(MTC_dot3Float(offset[3], offset[3]));
+ float dist = sqrt(Inpf(offset[3], offset[3]));
if(dist > 1e-6f)
/* this gives length = first copy start to last copy end
@@ -1276,11 +1277,11 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
result = CDDM_from_template(dm, finalVerts, finalEdges, finalFaces);
/* calculate the offset matrix of the final copy (for merging) */
- MTC_Mat4One(final_offset);
+ Mat4One(final_offset);
for(j=0; j < count - 1; j++) {
- MTC_Mat4MulMat4(tmp_mat, final_offset, offset);
- MTC_Mat4CpyMat4(final_offset, tmp_mat);
+ Mat4MulMat4(tmp_mat, final_offset, offset);
+ Mat4CpyMat4(final_offset, tmp_mat);
}
numVerts = numEdges = numFaces = 0;
@@ -1316,7 +1317,7 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
if((count > 1) && (amd->flags & MOD_ARR_MERGE)) {
float tmp_co[3];
VECCOPY(tmp_co, mv->co);
- MTC_Mat4MulVecfl(offset, tmp_co);
+ Mat4MulVecfl(offset, tmp_co);
for(j = 0; j < maxVerts; j++) {
/* if vertex already merged, don't use it */
@@ -1331,7 +1332,7 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
if(amd->flags & MOD_ARR_MERGEFINAL) {
VECCOPY(tmp_co, inMV->co);
inMV = &src_mvert[i];
- MTC_Mat4MulVecfl(final_offset, tmp_co);
+ Mat4MulVecfl(final_offset, tmp_co);
if(VecLenCompare(tmp_co, inMV->co, amd->merge_dist))
indexMap[i].merge_final = 1;
}
@@ -1349,7 +1350,7 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
*mv2 = *mv;
numVerts++;
- MTC_Mat4MulVecfl(offset, co);
+ Mat4MulVecfl(offset, co);
VECCOPY(mv2->co, co);
}
} else if(indexMap[i].merge != i && indexMap[i].merge_final) {
@@ -3181,7 +3182,7 @@ static void tag_and_count_extra_edges(SmoothMesh *mesh, float split_angle,
/* we know the edge has 2 faces, so check the angle */
SmoothFace *face1 = edge->faces->link;
SmoothFace *face2 = edge->faces->next->link;
- float edge_angle_cos = MTC_dot3Float(face1->normal,
+ float edge_angle_cos = Inpf(face1->normal,
face2->normal);
if(edge_angle_cos < threshold) {
@@ -4050,11 +4051,11 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
/* find the projector which the face points at most directly
* (projector normal with largest dot product is best)
*/
- best_dot = MTC_dot3Float(projectors[0].normal, face_no);
+ best_dot = Inpf(projectors[0].normal, face_no);
best_projector = &projectors[0];
for(j = 1; j < num_projectors; ++j) {
- float tmp_dot = MTC_dot3Float(projectors[j].normal,
+ float tmp_dot = Inpf(projectors[j].normal,
face_no);
if(tmp_dot > best_dot) {
best_dot = tmp_dot;
@@ -5598,6 +5599,7 @@ static void hookModifier_copyData(ModifierData *md, ModifierData *target)
thmd->indexar = MEM_dupallocN(hmd->indexar);
memcpy(thmd->parentinv, hmd->parentinv, sizeof(hmd->parentinv));
strncpy(thmd->name, hmd->name, 32);
+ strncpy(thmd->subtarget, hmd->subtarget, 32);
}
CustomDataMask hookModifier_requiredDataMask(Object *ob, ModifierData *md)
@@ -5642,9 +5644,11 @@ static void hookModifier_updateDepgraph(ModifierData *md, DagForest *forest, Sce
if (hmd->object) {
DagNode *curNode = dag_get_node(forest, hmd->object);
-
- dag_add_relation(forest, curNode, obNode, DAG_RL_OB_DATA,
- "Hook Modifier");
+
+ if (hmd->subtarget[0])
+ dag_add_relation(forest, curNode, obNode, DAG_RL_OB_DATA|DAG_RL_DATA_DATA, "Hook Modifier");
+ else
+ dag_add_relation(forest, curNode, obNode, DAG_RL_OB_DATA, "Hook Modifier");
}
}
@@ -5653,12 +5657,22 @@ static void hookModifier_deformVerts(
float (*vertexCos)[3], int numVerts, int useRenderParams, int isFinalCalc)
{
HookModifierData *hmd = (HookModifierData*) md;
- float vec[3], mat[4][4];
+ bPoseChannel *pchan= get_pose_channel(hmd->object->pose, hmd->subtarget);
+ float vec[3], mat[4][4], dmat[4][4];
int i;
DerivedMesh *dm = derivedData;
-
+
+ /* get world-space matrix of target, corrected for the space the verts are in */
+ if (hmd->subtarget[0] && pchan) {
+ /* bone target if there's a matching pose-channel */
+ Mat4MulMat4(dmat, pchan->pose_mat, hmd->object->obmat);
+ }
+ else {
+ /* just object target */
+ Mat4CpyMat4(dmat, hmd->object->obmat);
+ }
Mat4Invert(ob->imat, ob->obmat);
- Mat4MulSerie(mat, ob->imat, hmd->object->obmat, hmd->parentinv,
+ Mat4MulSerie(mat, ob->imat, dmat, hmd->parentinv,
NULL, NULL, NULL, NULL, NULL);
/* vertex indices? */
@@ -5715,7 +5729,8 @@ static void hookModifier_deformVerts(
}
}
}
- } else { /* vertex group hook */
+ }
+ else if(hmd->name[0]) { /* vertex group hook */
bDeformGroup *curdef;
Mesh *me = ob->data;
int index = 0;
@@ -5801,26 +5816,6 @@ static void smokeModifier_initData(ModifierData *md)
smd->coll = NULL;
smd->type = 0;
smd->time = -1;
-
- /*
- smd->fluid = NULL;
- smd->maxres = 48;
- smd->amplify = 4;
- smd->omega = 0.5;
- smd->time = 0;
- smd->flags = 0;
- smd->noise = MOD_SMOKE_NOISEWAVE;
- smd->visibility = 1;
-
- // init 3dview buffer
- smd->tvox = NULL;
- smd->tray = NULL;
- smd->tvoxbig = NULL;
- smd->traybig = NULL;
- smd->viewsettings = 0;
- smd->bind = NULL;
- smd->max_textures = 0;
- */
}
static void smokeModifier_freeData(ModifierData *md)
@@ -6701,10 +6696,8 @@ static DerivedMesh * particleInstanceModifier_applyModifier(
if((psys->flag & (PSYS_HAIR_DONE|PSYS_KEYED) || psys->pointcache->flag & PTCACHE_BAKED) && pimd->flag & eParticleInstanceFlag_Path){
float ran = 0.0f;
if(pimd->random_position != 0.0f) {
- /* just use some static collection of random numbers */
- /* TODO: use something else that's unique to each instanced object */
- pa = psys->particles + (i/totvert)%totpart;
- ran = pimd->random_position * 0.5 * (1.0f + pa->r_ave[0]);
+ BLI_srandom(psys->seed + (i/totvert)%totpart);
+ ran = pimd->random_position * BLI_frand();
}
if(pimd->flag & eParticleInstanceFlag_KeepShape) {
@@ -8078,14 +8071,13 @@ static DerivedMesh *multiresModifier_applyModifier(ModifierData *md, Object *ob,
int useRenderParams, int isFinalCalc)
{
MultiresModifierData *mmd = (MultiresModifierData*)md;
- Mesh *me = get_mesh(ob);
DerivedMesh *final;
/* TODO: for now just skip a level1 mesh */
if(mmd->lvl == 1)
return dm;
- final = multires_dm_create_from_derived(mmd, dm, me, useRenderParams, isFinalCalc);
+ final = multires_dm_create_from_derived(mmd, 0, dm, ob, useRenderParams, isFinalCalc);
if(mmd->undo_signal && mmd->undo_verts && mmd->undo_verts_tot == final->getNumVerts(final)) {
int i;
MVert *dst = CDDM_get_verts(final);
@@ -8580,7 +8572,9 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type)
mti->type = eModifierTypeType_OnlyDeform;
mti->initData = smokeModifier_initData;
mti->freeData = smokeModifier_freeData;
- mti->flags = eModifierTypeFlag_AcceptsMesh;
+ mti->flags = eModifierTypeFlag_AcceptsMesh
+ | eModifierTypeFlag_UsesPointCache
+ | eModifierTypeFlag_Single;
mti->deformVerts = smokeModifier_deformVerts;
mti->dependsOnTime = smokeModifier_dependsOnTime;
mti->updateDepgraph = smokeModifier_updateDepgraph;
@@ -8611,7 +8605,7 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type)
mti = INIT_TYPE(Surface);
mti->type = eModifierTypeType_OnlyDeform;
mti->initData = surfaceModifier_initData;
- mti->flags = eModifierTypeFlag_AcceptsMesh;
+ mti->flags = eModifierTypeFlag_AcceptsMesh|eModifierTypeFlag_NoUserAdd;
mti->dependsOnTime = surfaceModifier_dependsOnTime;
mti->freeData = surfaceModifier_freeData;
mti->deformVerts = surfaceModifier_deformVerts;
diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c
index e91f318adad..37e7e55050a 100644
--- a/source/blender/blenkernel/intern/multires.c
+++ b/source/blender/blenkernel/intern/multires.c
@@ -83,7 +83,7 @@ int multiresModifier_switch_level(Object *ob, const int distance)
mmd->lvl += distance;
if(mmd->lvl < 1) mmd->lvl = 1;
else if(mmd->lvl > mmd->totlvl) mmd->lvl = mmd->totlvl;
- /* XXX: DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
+ /* XXX: DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
object_handle_update(ob);*/
return 1;
}
@@ -204,10 +204,11 @@ static void VecAddUf(float a[3], float b[3])
a[2] += b[2];
}
-static void multires_subdisp(DerivedMesh *orig, Mesh *me, DerivedMesh *final, int lvl, int totlvl,
+static void multires_subdisp(DerivedMesh *orig, Object *ob, DerivedMesh *final, int lvl, int totlvl,
int totsubvert, int totsubedge, int totsubface, int addverts)
{
DerivedMesh *mrdm;
+ Mesh *me = ob->data;
MultiresModifierData mmd_sub;
MVert *mvs = CDDM_get_verts(final);
MVert *mvd, *mvd_f1, *mvs_f1, *mvd_f3, *mvd_f4;
@@ -222,7 +223,7 @@ static void multires_subdisp(DerivedMesh *orig, Mesh *me, DerivedMesh *final, in
memset(&mmd_sub, 0, sizeof(MultiresModifierData));
mmd_sub.lvl = mmd_sub.totlvl = totlvl;
- mrdm = multires_dm_create_from_derived(&mmd_sub, orig, me, 0, 0);
+ mrdm = multires_dm_create_from_derived(&mmd_sub, 1, orig, ob, 0, 0);
mvd = CDDM_get_verts(mrdm);
/* Need to map from ccg to mrdm */
@@ -395,7 +396,7 @@ static void multires_subdisp(DerivedMesh *orig, Mesh *me, DerivedMesh *final, in
}
}
- final->needsFree = 1;
+ final->needsFree = 1;
final->release(final);
mrdm->needsFree = 1;
MultiresDM_mark_as_modified(mrdm);
@@ -468,7 +469,8 @@ void multiresModifier_subdivide(MultiresModifierData *mmd, Object *ob, int dista
orig = CDDM_from_mesh(me, NULL);
memset(&mmd_sub, 0, sizeof(MultiresModifierData));
mmd_sub.lvl = mmd_sub.totlvl = mmd->lvl;
- mrdm = multires_dm_create_from_derived(&mmd_sub, orig, me, 0, 0);
+ mmd_sub.simple = simple;
+ mrdm = multires_dm_create_from_derived(&mmd_sub, 1, orig, ob, 0, 0);
totsubvert = mrdm->getNumVerts(mrdm);
totsubedge = mrdm->getNumEdges(mrdm);
totsubface = mrdm->getNumFaces(mrdm);
@@ -497,7 +499,7 @@ void multiresModifier_subdivide(MultiresModifierData *mmd, Object *ob, int dista
orig = CDDM_from_mesh(me, NULL);
- multires_subdisp(orig, me, final, mmd->lvl, mmd->totlvl, totsubvert, totsubedge, totsubface, 0);
+ multires_subdisp(orig, ob, final, mmd->lvl, mmd->totlvl, totsubvert, totsubedge, totsubface, 0);
orig->needsFree = 1;
orig->release(orig);
@@ -1166,9 +1168,11 @@ static void multiresModifier_disp_run(DerivedMesh *dm, MVert *subco, int invert)
static void multiresModifier_update(DerivedMesh *dm)
{
+ Object *ob;
Mesh *me;
MDisps *mdisps;
+ ob = MultiresDM_get_object(dm);
me = MultiresDM_get_mesh(dm);
mdisps = CustomData_get_layer(&me->fdata, CD_MDISPS);
@@ -1189,7 +1193,7 @@ static void multiresModifier_update(DerivedMesh *dm)
(includes older displacements but not new sculpts) */
mmd.totlvl = totlvl;
mmd.lvl = lvl;
- subco_dm = multires_dm_create_from_derived(&mmd, orig, me, 0, 0);
+ subco_dm = multires_dm_create_from_derived(&mmd, 1, orig, ob, 0, 0);
cur_lvl_orig_verts = CDDM_get_verts(subco_dm);
/* Subtract the original vertex cos from the new vertex cos */
@@ -1199,7 +1203,7 @@ static void multiresModifier_update(DerivedMesh *dm)
final = multires_subdisp_pre(dm, totlvl - lvl, 0);
- multires_subdisp(orig, me, final, lvl, totlvl, dm->getNumVerts(dm), dm->getNumEdges(dm),
+ multires_subdisp(orig, ob, final, lvl, totlvl, dm->getNumVerts(dm), dm->getNumEdges(dm),
dm->getNumFaces(dm), 1);
subco_dm->release(subco_dm);
@@ -1226,7 +1230,7 @@ void multires_force_update(Object *ob)
}
}
-struct DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, DerivedMesh *dm, Mesh *me,
+struct DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, int local_mmd, DerivedMesh *dm, Object *ob,
int useRenderParams, int isFinalCalc)
{
SubsurfModifierData smd;
@@ -1235,7 +1239,8 @@ struct DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, D
int i;
ms.mmd = mmd;
- ms.me = me;
+ ms.ob = ob;
+ ms.local_mmd = local_mmd;
memset(&smd, 0, sizeof(SubsurfModifierData));
smd.levels = smd.renderLevels = mmd->lvl - 1;
diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c
index c41c4ae78e4..480c79fbc1a 100644
--- a/source/blender/blenkernel/intern/nla.c
+++ b/source/blender/blenkernel/intern/nla.c
@@ -291,7 +291,7 @@ NlaStrip *add_nlastrip (bAction *act)
/* determine initial range
* - strip length cannot be 0... ever...
*/
- calc_action_range(strip->act, &strip->actstart, &strip->actend, 1);
+ calc_action_range(strip->act, &strip->actstart, &strip->actend, 0);
strip->start = strip->actstart;
strip->end = (IS_EQ(strip->actstart, strip->actend)) ? (strip->actstart + 1.0f): (strip->actend);
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index 836f4281eb9..90ea53d4364 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -22,7 +22,7 @@
*
* The Original Code is: all of this file.
*
- * Contributor(s): none yet.
+ * Contributor(s): Bob Holcomb.
*
* ***** END GPL LICENSE BLOCK *****
*/
@@ -950,9 +950,6 @@ bNode *nodeAddNodeType(bNodeTree *ntree, int type, bNodeTree *ngroup, ID *id)
if(ntype->initfunc!=NULL)
ntype->initfunc(node);
- if(type==TEX_NODE_OUTPUT)
- ntreeTexAssignIndex(ntree, node);
-
nodeAddSockets(node, ntype);
return node;
@@ -1021,9 +1018,6 @@ bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node, int internal)
nnode->new_node= NULL;
nnode->preview= NULL;
- if(node->type==TEX_NODE_OUTPUT)
- ntreeTexAssignIndex(ntree, node);
-
return nnode;
}
@@ -2603,7 +2597,7 @@ void ntreeLocalMerge(bNodeTree *localtree, bNodeTree *ntree)
if(outsocket_exists(lnode->new_node, lsock->new_sock)) {
lsock->new_sock->ns.data= lsock->ns.data;
lsock->ns.data= NULL;
- lsock->new_sock= NULL;
+ lsock->new_sock= NULL;
}
}
}
@@ -2938,6 +2932,7 @@ static void registerCompositNodes(ListBase *ntypelist)
nodeRegisterType(ntypelist, &cmp_node_viewer);
nodeRegisterType(ntypelist, &cmp_node_splitviewer);
nodeRegisterType(ntypelist, &cmp_node_output_file);
+ nodeRegisterType(ntypelist, &cmp_node_view_levels);
nodeRegisterType(ntypelist, &cmp_node_curve_rgb);
nodeRegisterType(ntypelist, &cmp_node_mix_rgb);
@@ -2977,7 +2972,9 @@ static void registerCompositNodes(ListBase *ntypelist)
nodeRegisterType(ntypelist, &cmp_node_premulkey);
nodeRegisterType(ntypelist, &cmp_node_diff_matte);
- nodeRegisterType(ntypelist, &cmp_node_chroma);
+ nodeRegisterType(ntypelist, &cmp_node_distance_matte);
+ nodeRegisterType(ntypelist, &cmp_node_chroma_matte);
+ nodeRegisterType(ntypelist, &cmp_node_color_matte);
nodeRegisterType(ntypelist, &cmp_node_channel_matte);
nodeRegisterType(ntypelist, &cmp_node_color_spill);
nodeRegisterType(ntypelist, &cmp_node_luma_matte);
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 0e45aedc3ed..8fe7beeb247 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -101,13 +101,13 @@
#include "BKE_mball.h"
#include "BKE_modifier.h"
#include "BKE_object.h"
+#include "BKE_paint.h"
#include "BKE_particle.h"
#include "BKE_pointcache.h"
#include "BKE_property.h"
#include "BKE_sca.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
-#include "BKE_sculpt.h"
#include "BKE_softbody.h"
#include "LBM_fluidsim.h"
@@ -284,6 +284,7 @@ void free_object(Object *ob)
if(ob->adt) BKE_free_animdata((ID *)ob);
if(ob->poselib) ob->poselib->id.us--;
if(ob->dup_group) ob->dup_group->id.us--;
+ if(ob->gpd) ob->gpd->id.us--;
if(ob->defbase.first)
BLI_freelistN(&ob->defbase);
if(ob->pose)
@@ -307,6 +308,8 @@ void free_object(Object *ob)
if(ob->gpulamp.first) GPU_lamp_free(ob);
free_sculptsession(&ob->sculpt);
+
+ if(ob->pc_ids.first) BLI_freelistN(&ob->pc_ids);
}
static void unlink_object__unlinkModifierLinks(void *userData, Object *ob, Object **obpoin)
@@ -478,15 +481,15 @@ void unlink_object(Scene *scene, Object *ob)
if(tpsys->part->dup_ob==ob)
tpsys->part->dup_ob= NULL;
- if(tpsys->part->flag&PART_STICKY) {
+ if(tpsys->part->phystype==PART_PHYS_BOIDS) {
ParticleData *pa;
+ BoidParticle *bpa;
int p;
for(p=0,pa=tpsys->particles; p<tpsys->totpart; p++,pa++) {
- if(pa->stick_ob==ob) {
- pa->stick_ob= 0;
- pa->flag &= ~PARS_STICKY;
- }
+ bpa = pa->boid;
+ if(bpa->ground == ob)
+ bpa->ground = NULL;
}
}
if(tpsys->part->boids) {
@@ -1016,6 +1019,8 @@ Object *add_only_object(int type, char *name)
ob->fluidsimFlag = 0;
ob->fluidsimSettings = NULL;
+ ob->pc_ids.first = ob->pc_ids.last = NULL;
+
return ob;
}
@@ -1077,34 +1082,44 @@ ParticleSystem *copy_particlesystem(ParticleSystem *psys)
{
ParticleSystem *psysn;
ParticleData *pa;
- int a;
+ int p;
psysn= MEM_dupallocN(psys);
psysn->particles= MEM_dupallocN(psys->particles);
psysn->child= MEM_dupallocN(psys->child);
- if(psysn->particles->keys)
- psysn->particles->keys = MEM_dupallocN(psys->particles->keys);
- for(a=0, pa=psysn->particles; a<psysn->totpart; a++, pa++) {
- if(pa->hair)
- pa->hair= MEM_dupallocN(pa->hair);
- if(a)
- pa->keys= (pa-1)->keys + (pa-1)->totkey;
+ if(psys->part->type == PART_HAIR) {
+ for(p=0, pa=psysn->particles; p<psysn->totpart; p++, pa++)
+ pa->hair = MEM_dupallocN(pa->hair);
}
- if(psys->soft) {
- psysn->soft= copy_softbody(psys->soft);
- psysn->soft->particles = psysn;
+ if(psysn->particles->keys || psysn->particles->boid) {
+ ParticleKey *key = psysn->particles->keys;
+ BoidParticle *boid = psysn->particles->boid;
+
+ if(key)
+ key = MEM_dupallocN(key);
+
+ if(boid)
+ boid = MEM_dupallocN(boid);
+
+ for(p=0, pa=psysn->particles; p<psysn->totpart; p++, pa++) {
+ if(boid)
+ pa->boid = boid++;
+ if(key) {
+ pa->keys = key;
+ key += pa->totkey;
+ }
+ }
}
- if(psys->particles->boid) {
- psysn->particles->boid = MEM_dupallocN(psys->particles->boid);
- for(a=1, pa=psysn->particles+1; a<psysn->totpart; a++, pa++)
- pa->boid = (pa-1)->boid + 1;
+ if(psys->clmd) {
+ ClothModifierData *nclmd = (ClothModifierData *)modifier_new(eModifierType_Cloth);
+ modifier_copyData((ModifierData*)psys->clmd, (ModifierData*)nclmd);
+ psys->hair_in_dm = psys->hair_out_dm = NULL;
}
- if(psys->targets.first)
- BLI_duplicatelist(&psysn->targets, &psys->targets);
+ BLI_duplicatelist(&psysn->targets, &psys->targets);
psysn->pathcache= NULL;
psysn->childcache= NULL;
@@ -1268,7 +1283,8 @@ Object *copy_object(Object *ob)
obn->derivedFinal = NULL;
obn->gpulamp.first = obn->gpulamp.last = NULL;
-
+ obn->pc_ids.first = obn->pc_ids.last = NULL;
+
return obn;
}
@@ -1630,7 +1646,7 @@ int enable_cu_speed= 1;
static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4])
{
Curve *cu;
- float q[4], vec[4], dir[3], quat[4], x1, ctime;
+ float q[4], vec[4], dir[3], quat[4], radius, x1, ctime;
float timeoffs = 0.0, sf_orig = 0.0;
Mat4One(mat);
@@ -1678,7 +1694,7 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4])
/* vec: 4 items! */
- if( where_on_path(par, ctime, vec, dir) ) {
+ if( where_on_path(par, ctime, vec, dir, NULL, &radius) ) {
if(cu->flag & CU_FOLLOW) {
vectoquat(dir, ob->trackflag, ob->upflag, quat);
@@ -1695,6 +1711,13 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4])
QuatToMat4(quat, mat);
}
+ if(cu->flag & CU_PATH_RADIUS) {
+ float tmat[4][4], rmat[4][4];
+ Mat4Scale(tmat, radius);
+ Mat4MulMat4(rmat, mat, tmat);
+ Mat4CpyMat4(mat, rmat);
+ }
+
VECCOPY(mat[3], vec);
}
@@ -1792,7 +1815,7 @@ static void give_parvert(Object *par, int nr, float *vec)
count= 0;
while(nu && !found) {
- if((nu->type & 7)==CU_BEZIER) {
+ if(nu->type == CU_BEZIER) {
bezt= nu->bezt;
a= nu->pntsu;
while(a--) {
@@ -2535,3 +2558,61 @@ int ray_hit_boundbox(struct BoundBox *bb, float ray_start[3], float ray_normal[3
return result;
}
+
+static int pc_cmp(void *a, void *b)
+{
+ LinkData *ad = a, *bd = b;
+ if((int)ad->data > (int)bd->data)
+ return 1;
+ else return 0;
+}
+
+int object_insert_ptcache(Object *ob)
+{
+ LinkData *link = NULL;
+ int i = 0;
+
+ BLI_sortlist(&ob->pc_ids, pc_cmp);
+
+ for(link=ob->pc_ids.first, i = 0; link; link=link->next, i++)
+ {
+ int index =(int)link->data;
+
+ if(i < index)
+ break;
+ }
+
+ link = MEM_callocN(sizeof(LinkData), "PCLink");
+ link->data = (void *)i;
+ BLI_addtail(&ob->pc_ids, link);
+
+ return i;
+}
+
+#if 0
+static int pc_findindex(ListBase *listbase, int index)
+{
+ LinkData *link= NULL;
+ int number= 0;
+
+ if (listbase == NULL) return -1;
+
+ link= listbase->first;
+ while (link) {
+ if ((int)link->data == index)
+ return number;
+
+ number++;
+ link= link->next;
+ }
+
+ return -1;
+}
+
+void object_delete_ptcache(Object *ob, int index)
+{
+ int list_index = pc_findindex(&ob->pc_ids, index);
+ LinkData *link = BLI_findlink(&ob->pc_ids, list_index);
+ BLI_freelinkN(&ob->pc_ids, link);
+}
+#endif
diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c
index 8c77ed92aa1..bd0b1a5e36e 100644
--- a/source/blender/blenkernel/intern/packedFile.c
+++ b/source/blender/blenkernel/intern/packedFile.c
@@ -63,6 +63,14 @@
#include "BKE_packedFile.h"
#include "BKE_report.h"
+#ifdef _WIN32
+#define open _open
+#define close _close
+#define read _read
+#define write _write
+#endif
+
+
int seekPackedFile(PackedFile *pf, int offset, int whence)
{
int oldseek = -1, seek = 0;
@@ -473,7 +481,7 @@ int unpackSound(ReportList *reports, bSound *sound, int how)
freePackedFile(sound->packedfile);
sound->packedfile = 0;
- sound_load(sound);
+ sound_load(NULL, sound);
ret_value = RET_OK;
}
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 80016f23d7c..7c5b2b82b4b 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -39,6 +39,11 @@
#include <stdlib.h>
#include <string.h>
+const char PAINT_CURSOR_SCULPT[3] = {255, 100, 100};
+const char PAINT_CURSOR_VERTEX_PAINT[3] = {255, 255, 255};
+const char PAINT_CURSOR_WEIGHT_PAINT[3] = {200, 200, 255};
+const char PAINT_CURSOR_TEXTURE_PAINT[3] = {255, 255, 255};
+
Paint *paint_get_active(Scene *sce)
{
if(sce && sce->basact && sce->basact->object) {
@@ -154,14 +159,17 @@ int paint_facesel_test(Object *ob)
}
-void paint_init(Paint *p, const char *name)
+void paint_init(Paint *p, const char col[3])
{
Brush *brush;
/* If there's no brush, create one */
brush = paint_brush(p);
- brush_check_exists(&brush, name);
+ brush_check_exists(&brush, "Brush");
paint_brush_set(p, brush);
+
+ memcpy(p->paint_cursor_col, col, 3);
+ p->paint_cursor_col[3] = 128;
}
void free_paint(Paint *paint)
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index e1987d34a6c..2d3e3210afc 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -60,6 +60,7 @@
#include "BKE_anim.h"
#include "BKE_boids.h"
+#include "BKE_cloth.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_lattice.h"
@@ -92,10 +93,10 @@ static void do_child_modifiers(Scene *scene, Object *ob, ParticleSystem *psys, P
/* few helpers for countall etc. */
int count_particles(ParticleSystem *psys){
ParticleSettings *part=psys->part;
- ParticleData *pa;
- int tot=0,p;
+ PARTICLE_P;
+ int tot=0;
- for(p=0,pa=psys->particles; p<psys->totpart; p++,pa++){
+ LOOP_PARTICLES {
if(pa->alive == PARS_KILLED);
else if(pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN)==0);
else if(pa->alive == PARS_DEAD && (part->flag & PART_DIED)==0);
@@ -106,10 +107,10 @@ int count_particles(ParticleSystem *psys){
}
int count_particles_mod(ParticleSystem *psys, int totgr, int cur){
ParticleSettings *part=psys->part;
- ParticleData *pa;
- int tot=0,p;
+ PARTICLE_P;
+ int tot=0;
- for(p=0,pa=psys->particles; p<psys->totpart; p++,pa++){
+ LOOP_PARTICLES {
if(pa->alive == PARS_KILLED);
else if(pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN)==0);
else if(pa->alive == PARS_DEAD && (part->flag & PART_DIED)==0);
@@ -120,10 +121,10 @@ int count_particles_mod(ParticleSystem *psys, int totgr, int cur){
}
int psys_count_keys(ParticleSystem *psys)
{
- ParticleData *pa;
- int i, totpart=psys->totpart, totkey=0;
+ PARTICLE_P;
+ int totkey=0;
- for(i=0, pa=psys->particles; i<totpart; i++, pa++)
+ LOOP_PARTICLES
totkey += pa->totkey;
return totkey;
@@ -321,7 +322,7 @@ int psys_ob_has_hair(Object *ob)
}
int psys_in_edit_mode(Scene *scene, ParticleSystem *psys)
{
- return ((scene->basact->object->mode & OB_MODE_PARTICLE_EDIT) && psys==psys_get_current((scene->basact)->object) && psys->edit);
+ return (scene->basact && (scene->basact->object->mode & OB_MODE_PARTICLE_EDIT) && psys==psys_get_current((scene->basact)->object) && (psys->edit || psys->pointcache->edit));
}
int psys_check_enabled(Object *ob, ParticleSystem *psys)
{
@@ -366,33 +367,56 @@ void psys_free_settings(ParticleSettings *part)
boid_free_settings(part->boids);
}
-void free_hair(ParticleSystem *psys, int softbody)
+void free_hair(Object *ob, ParticleSystem *psys, int dynamics)
{
- ParticleData *pa;
- int i, totpart=psys->totpart;
+ PARTICLE_P;
- for(i=0, pa=psys->particles; i<totpart; i++, pa++) {
+ if(psys->part->type != PART_HAIR)
+ return;
+
+ LOOP_PARTICLES {
if(pa->hair)
MEM_freeN(pa->hair);
pa->hair = NULL;
+ pa->totkey = 0;
}
psys->flag &= ~PSYS_HAIR_DONE;
- if(softbody && psys->soft) {
- sbFree(psys->soft);
- psys->soft = NULL;
+ if(psys->clmd) {
+ if(dynamics) {
+ BKE_ptcache_free_list(&psys->ptcaches);
+ psys->clmd->point_cache = psys->pointcache = NULL;
+ psys->clmd->ptcaches.first = psys->clmd->ptcaches.first = NULL;
+
+ modifier_free((ModifierData*)psys->clmd);
+
+ psys->clmd = NULL;
+ }
+ else {
+ cloth_free_modifier(ob, psys->clmd);
+ }
}
+
+ if(psys->hair_in_dm)
+ psys->hair_in_dm->release(psys->hair_in_dm);
+ psys->hair_in_dm = NULL;
+
+ if(psys->hair_out_dm)
+ psys->hair_out_dm->release(psys->hair_out_dm);
+ psys->hair_out_dm = NULL;
}
void free_keyed_keys(ParticleSystem *psys)
{
- ParticleData *pa;
- int i;
+ PARTICLE_P;
+
+ if(psys->part->type == PART_HAIR)
+ return;
if(psys->particles && psys->particles->keys) {
MEM_freeN(psys->particles->keys);
- for(i=0, pa=psys->particles; i<psys->totpart; i++, pa++) {
+ LOOP_PARTICLES {
if(pa->keys) {
pa->keys= NULL;
pa->totkey= 0;
@@ -406,13 +430,20 @@ void free_child_path_cache(ParticleSystem *psys)
psys->childcache = NULL;
psys->totchildcache = 0;
}
-void psys_free_path_cache(ParticleSystem *psys)
+void psys_free_path_cache(ParticleSystem *psys, PTCacheEdit *edit)
{
- psys_free_path_cache_buffers(psys->pathcache, &psys->pathcachebufs);
- psys->pathcache= NULL;
- psys->totcached= 0;
+ if(edit) {
+ psys_free_path_cache_buffers(edit->pathcache, &edit->pathcachebufs);
+ edit->pathcache= NULL;
+ edit->totcached= 0;
+ }
+ if(psys) {
+ psys_free_path_cache_buffers(psys->pathcache, &psys->pathcachebufs);
+ psys->pathcache= NULL;
+ psys->totcached= 0;
- free_child_path_cache(psys);
+ free_child_path_cache(psys);
+ }
}
void psys_free_children(ParticleSystem *psys)
{
@@ -424,6 +455,29 @@ void psys_free_children(ParticleSystem *psys)
free_child_path_cache(psys);
}
+void psys_free_particles(ParticleSystem *psys)
+{
+ PARTICLE_P;
+
+ if(psys->particles) {
+ if(psys->part->type==PART_HAIR) {
+ LOOP_PARTICLES {
+ if(pa->hair)
+ MEM_freeN(pa->hair);
+ }
+ }
+
+ if(psys->particles->keys)
+ MEM_freeN(psys->particles->keys);
+
+ if(psys->particles->boid)
+ MEM_freeN(psys->particles->boid);
+
+ MEM_freeN(psys->particles);
+ psys->particles= NULL;
+ psys->totpart= 0;
+ }
+}
/* free everything */
void psys_free(Object *ob, ParticleSystem * psys)
{
@@ -431,23 +485,14 @@ void psys_free(Object *ob, ParticleSystem * psys)
int nr = 0;
ParticleSystem * tpsys;
- psys_free_path_cache(psys);
+ psys_free_path_cache(psys, NULL);
- free_hair(psys, 1);
+ free_hair(ob, psys, 1);
- free_keyed_keys(psys);
+ psys_free_particles(psys);
if(psys->edit && psys->free_edit)
- psys->free_edit(psys);
-
- if(psys->particles){
- if(psys->particles->boid)
- MEM_freeN(psys->particles->boid);
-
- MEM_freeN(psys->particles);
- psys->particles = 0;
- psys->totpart = 0;
- }
+ psys->free_edit(psys->edit);
if(psys->child){
MEM_freeN(psys->child);
@@ -478,14 +523,11 @@ void psys_free(Object *ob, ParticleSystem * psys)
psys->part=0;
}
- if(psys->reactevents.first)
- BLI_freelistN(&psys->reactevents);
-
BKE_ptcache_free_list(&psys->ptcaches);
psys->pointcache = NULL;
- if(psys->targets.first)
- BLI_freelistN(&psys->targets);
+ BLI_freelistN(&psys->targets);
+ BLI_freelistN(&psys->reactevents);
BLI_kdtree_free(psys->tree);
@@ -645,7 +687,7 @@ void psys_render_restore(Object *ob, ParticleSystem *psys)
psmd->dm->release(psmd->dm);
}
- psys_free_path_cache(psys);
+ psys_free_path_cache(psys, NULL);
if(psys->child){
MEM_freeN(psys->child);
@@ -929,7 +971,7 @@ void psys_interpolate_particle(short type, ParticleKey keys[4], float dt, Partic
VecfCubicInterpol(keys[1].co, keys[1].vel, keys[2].co, keys[2].vel, dt, result->co, result->vel);
}
else {
- set_four_ipo(dt, t, type);
+ key_curve_position_weights(dt, t, type);
weighted_particle_vector(keys[0].co, keys[1].co, keys[2].co, keys[3].co, t, result->co);
@@ -937,12 +979,12 @@ void psys_interpolate_particle(short type, ParticleKey keys[4], float dt, Partic
float temp[3];
if(dt>0.999f){
- set_four_ipo(dt-0.001f, t, type);
+ key_curve_position_weights(dt-0.001f, t, type);
weighted_particle_vector(keys[0].co, keys[1].co, keys[2].co, keys[3].co, t, temp);
VECSUB(result->vel, result->co, temp);
}
else{
- set_four_ipo(dt+0.001f, t, type);
+ key_curve_position_weights(dt+0.001f, t, type);
weighted_particle_vector(keys[0].co, keys[1].co, keys[2].co, keys[3].co, t, temp);
VECSUB(result->vel, temp, result->co);
}
@@ -953,17 +995,25 @@ void psys_interpolate_particle(short type, ParticleKey keys[4], float dt, Partic
typedef struct ParticleInterpolationData {
- ParticleKey *kkey[2];
HairKey *hkey[2];
- BodyPoint *bp[2];
- SoftBody *soft;
- int keyed, cached;
+
+ DerivedMesh *dm;
+ MVert *mvert[2];
+
+ int keyed;
+ ParticleKey *kkey[2];
+
+ PointCache *cache;
+
+ PTCacheEditPoint *epoint;
+ PTCacheEditKey *ekey[2];
+
float birthtime, dietime;
+ int bspline;
} ParticleInterpolationData;
/* Assumes pointcache->mem_cache exists, so for disk cached particles call psys_make_temp_pointcache() before use */
-static void get_pointcache_keys_for_time(Object *ob, ParticleSystem *psys, int index, float t, ParticleKey *key1, ParticleKey *key2)
+static void get_pointcache_keys_for_time(Object *ob, PointCache *cache, int index, float t, ParticleKey *key1, ParticleKey *key2)
{
- PointCache *cache = psys->pointcache;
static PTCacheMem *pm = NULL; /* not thread safe */
if(index < 0) { /* initialize */
@@ -990,54 +1040,83 @@ static void get_pointcache_keys_for_time(Object *ob, ParticleSystem *psys, int i
static void init_particle_interpolation(Object *ob, ParticleSystem *psys, ParticleData *pa, ParticleInterpolationData *pind)
{
- if(pind->keyed) {
- pind->kkey[0] = pa->keys;
+ if(pind->epoint) {
+ PTCacheEditPoint *point = pind->epoint;
- if(pa->totkey > 1)
- pind->kkey[1] = pa->keys + 1;
- else
- pind->kkey[1] = NULL;
+ pind->ekey[0] = point->keys;
+ pind->ekey[1] = point->totkey > 1 ? point->keys + 1 : NULL;
- pind->birthtime = pa->keys->time;
- pind->dietime = (pa->keys + pa->totkey - 1)->time;
+ pind->birthtime = *(point->keys->time);
+ pind->dietime = *((point->keys + point->totkey - 1)->time);
}
- else if(pind->cached) {
- get_pointcache_keys_for_time(ob, psys, -1, 0.0f, NULL, NULL);
+ else if(pind->keyed) {
+ ParticleKey *key = pa->keys;
+ pind->kkey[0] = key;
+ pind->kkey[1] = pa->totkey > 1 ? key + 1 : NULL;
- pind->birthtime = pa->time;
- pind->dietime = pa->dietime;
+ pind->birthtime = key->time;
+ pind->dietime = (key + pa->totkey - 1)->time;
}
- else {
- pind->hkey[0] = pa->hair;
- pind->hkey[1] = pa->hair + 1;
+ else if(pind->cache) {
+ get_pointcache_keys_for_time(ob, pind->cache, -1, 0.0f, NULL, NULL);
- pind->birthtime = pa->hair->time;
- pind->dietime = (pa->hair + pa->totkey - 1)->time;
+ pind->birthtime = pa ? pa->time : pind->cache->startframe;
+ pind->dietime = pa ? pa->dietime : pind->cache->endframe;
}
+ else {
+ HairKey *key = pa->hair;
+ pind->hkey[0] = key;
+ pind->hkey[1] = key + 1;
- if(pind->soft) {
- pind->bp[0] = pind->soft->bpoint + pa->bpi;
- pind->bp[1] = pind->soft->bpoint + pa->bpi + 1;
+ pind->birthtime = key->time;
+ pind->dietime = (key + pa->totkey - 1)->time;
+
+ if(pind->dm) {
+ pind->mvert[0] = CDDM_get_vert(pind->dm, pa->hair_index);
+ pind->mvert[1] = pind->mvert[0] + 1;
+ }
+ }
+}
+static void edit_to_particle(ParticleKey *key, PTCacheEditKey *ekey)
+{
+ VECCOPY(key->co, ekey->co);
+ if(ekey->vel) {
+ VECCOPY(key->vel, ekey->vel);
}
+ key->time = *(ekey->time);
}
static void hair_to_particle(ParticleKey *key, HairKey *hkey)
{
VECCOPY(key->co, hkey->co);
key->time = hkey->time;
}
-static void bp_to_particle(ParticleKey *key, BodyPoint *bp, HairKey *hkey)
+
+static void mvert_to_particle(ParticleKey *key, MVert *mvert, HairKey *hkey)
{
- VECCOPY(key->co, bp->pos);
+ VECCOPY(key->co, mvert->co);
key->time = hkey->time;
}
static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData *pa, float t, float frs_sec, ParticleInterpolationData *pind, ParticleKey *result)
{
+ PTCacheEditPoint *point = pind->epoint;
ParticleKey keys[4];
+ int point_vel = (point && point->keys->vel);
float real_t, dfra, keytime;
/* interpret timing and find keys */
- if(pind->keyed) {
+ if(point) {
+ if(result->time < 0.0f)
+ real_t = -result->time;
+ else
+ real_t = *(pind->ekey[0]->time) + t * (*(pind->ekey[0][point->totkey-1].time) - *(pind->ekey[0]->time));
+
+ while(*(pind->ekey[1]->time) < real_t)
+ pind->ekey[1]++;
+
+ pind->ekey[0] = pind->ekey[1] - 1;
+ }
+ else if(pind->keyed) {
/* we have only one key, so let's use that */
if(pind->kkey[1]==NULL) {
copy_particle_key(result, pind->kkey[0], 1);
@@ -1074,7 +1153,7 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData
pind->kkey[0] = pind->kkey[1] - 1;
}
- else if(pind->cached) {
+ else if(pind->cache) {
if(result->time < 0.0f) /* flag for time in frames */
real_t = -result->time;
else
@@ -1088,24 +1167,28 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData
while(pind->hkey[1]->time < real_t) {
pind->hkey[1]++;
- pind->bp[1]++;
+ pind->mvert[1]++;
}
pind->hkey[0] = pind->hkey[1] - 1;
}
/* set actual interpolation keys */
- if(pind->soft) {
- pind->bp[0] = pind->bp[1] - 1;
- bp_to_particle(keys + 1, pind->bp[0], pind->hkey[0]);
- bp_to_particle(keys + 2, pind->bp[1], pind->hkey[1]);
+ if(point) {
+ edit_to_particle(keys + 1, pind->ekey[0]);
+ edit_to_particle(keys + 2, pind->ekey[1]);
+ }
+ else if(pind->dm) {
+ pind->mvert[0] = pind->mvert[1] - 1;
+ mvert_to_particle(keys + 1, pind->mvert[0], pind->hkey[0]);
+ mvert_to_particle(keys + 2, pind->mvert[1], pind->hkey[1]);
}
else if(pind->keyed) {
memcpy(keys + 1, pind->kkey[0], sizeof(ParticleKey));
memcpy(keys + 2, pind->kkey[1], sizeof(ParticleKey));
}
- else if(pind->cached) {
- get_pointcache_keys_for_time(NULL, psys, p, real_t, keys+1, keys+2);
+ else if(pind->cache) {
+ get_pointcache_keys_for_time(NULL, pind->cache, p, real_t, keys+1, keys+2);
}
else {
hair_to_particle(keys + 1, pind->hkey[0]);
@@ -1113,12 +1196,18 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData
}
/* set secondary interpolation keys for hair */
- if(!pind->keyed && !pind->cached) {
- if(pind->soft) {
+ if(!pind->keyed && !pind->cache && !point_vel) {
+ if(point) {
+ if(pind->ekey[0] != point->keys)
+ edit_to_particle(keys, pind->ekey[0] - 1);
+ else
+ edit_to_particle(keys, pind->ekey[0]);
+ }
+ else if(pind->dm) {
if(pind->hkey[0] != pa->hair)
- bp_to_particle(keys, pind->bp[0] - 1, pind->hkey[0] - 1);
+ mvert_to_particle(keys, pind->mvert[0] - 1, pind->hkey[0] - 1);
else
- bp_to_particle(keys, pind->bp[0], pind->hkey[0]);
+ mvert_to_particle(keys, pind->mvert[0], pind->hkey[0]);
}
else {
if(pind->hkey[0] != pa->hair)
@@ -1127,11 +1216,17 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData
hair_to_particle(keys, pind->hkey[0]);
}
- if(pind->soft) {
+ if(point) {
+ if(pind->ekey[1] != point->keys + point->totkey - 1)
+ edit_to_particle(keys + 3, pind->ekey[1] + 1);
+ else
+ edit_to_particle(keys + 3, pind->ekey[1]);
+ }
+ else if(pind->dm) {
if(pind->hkey[1] != pa->hair + pa->totkey - 1)
- bp_to_particle(keys + 3, pind->bp[1] + 1, pind->hkey[1] + 1);
+ mvert_to_particle(keys + 3, pind->mvert[1] + 1, pind->hkey[1] + 1);
else
- bp_to_particle(keys + 3, pind->bp[1], pind->hkey[1]);
+ mvert_to_particle(keys + 3, pind->mvert[1], pind->hkey[1]);
}
else {
if(pind->hkey[1] != pa->hair + pa->totkey - 1)
@@ -1145,19 +1240,19 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData
keytime = (real_t - keys[1].time) / dfra;
/* convert velocity to timestep size */
- if(pind->keyed || pind->cached){
+ if(pind->keyed || pind->cache || point_vel){
VecMulf(keys[1].vel, dfra / frs_sec);
VecMulf(keys[2].vel, dfra / frs_sec);
QuatInterpol(result->rot,keys[1].rot,keys[2].rot,keytime);
}
/* now we should have in chronologiacl order k1<=k2<=t<=k3<=k4 with keytime between [0,1]->[k2,k3] (k1 & k4 used for cardinal & bspline interpolation)*/
- psys_interpolate_particle((pind->keyed || pind->cached) ? -1 /* signal for cubic interpolation */
- : ((psys->part->flag & PART_HAIR_BSPLINE) ? KEY_BSPLINE : KEY_CARDINAL)
+ psys_interpolate_particle((pind->keyed || pind->cache || point_vel) ? -1 /* signal for cubic interpolation */
+ : (pind->bspline ? KEY_BSPLINE : KEY_CARDINAL)
,keys, keytime, result, 1);
/* the velocity needs to be converted back from cubic interpolation */
- if(pind->keyed || pind->cached)
+ if(pind->keyed || pind->cache || point_vel)
VecMulf(result->vel, frs_sec / dfra);
}
/************************************************/
@@ -1610,7 +1705,7 @@ ParticleSystemModifierData *psys_get_modifier(Object *ob, ParticleSystem *psys)
}
}
}
- return 0;
+ return NULL;
}
/************************************************/
/* Particles on a shape */
@@ -1837,7 +1932,7 @@ int do_guide(Scene *scene, ParticleKey *state, int pa_num, float time, ListBase
ParticleKey key, par;
float effect[3]={0.0,0.0,0.0}, distance, f_force, mindist, totforce=0.0;
- float guidevec[4], guidedir[3], rot2[4], temp[3], angle, pa_loc[3], pa_zero[3]={0.0f,0.0f,0.0f};
+ float guidevec[4], guidedir[3], rot2[4], radius, temp[3], angle, pa_loc[3], pa_zero[3]={0.0f,0.0f,0.0f};
float veffect[3]={0.0,0.0,0.0}, guidetime;
effect[0]=effect[1]=effect[2]=0.0;
@@ -1880,9 +1975,9 @@ int do_guide(Scene *scene, ParticleKey *state, int pa_num, float time, ListBase
}
if(pd->flag & PFIELD_GUIDE_PATH_ADD)
- where_on_path(eob, f_force*guidetime, guidevec, guidedir);
+ where_on_path(eob, f_force*guidetime, guidevec, guidedir, NULL, &radius);
else
- where_on_path(eob, guidetime, guidevec, guidedir);
+ where_on_path(eob, guidetime, guidevec, guidedir, NULL, &radius);
Mat4MulVecfl(ec->ob->obmat,guidevec);
Mat4Mul3Vecfl(ec->ob->obmat,guidedir);
@@ -1912,10 +2007,12 @@ int do_guide(Scene *scene, ParticleKey *state, int pa_num, float time, ListBase
/* curve taper */
if(cu->taperobj)
VecMulf(pa_loc, calc_taper(scene, cu->taperobj, (int)(f_force*guidetime*100.0), 100));
- /* TODO */
- //else{
- ///* curve size*/
- //}
+
+ else{ /* curve size*/
+ if(cu->flag & CU_PATH_RADIUS) {
+ VecMulf(pa_loc, radius);
+ }
+ }
par.co[0]=par.co[1]=par.co[2]=0.0f;
VECCOPY(key.co,pa_loc);
do_prekink(&key, &par, 0, guidetime, pd->kink_freq, pd->kink_shape, pd->kink_amp, pd->kink, pd->kink_axis, 0);
@@ -2037,7 +2134,11 @@ float *psys_cache_vgroup(DerivedMesh *dm, ParticleSystem *psys, int vgroup)
{
float *vg=0;
- if(psys->vgroup[vgroup]){
+ if(vgroup < 0) {
+ /* hair dynamics pinning vgroup */
+
+ }
+ else if(psys->vgroup[vgroup]){
MDeformVert *dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
if(dvert){
int totvert=dm->getNumVerts(dm), i;
@@ -2129,7 +2230,7 @@ int psys_threads_init_path(ParticleThread *threads, Scene *scene, float cfra, in
/*---start figuring out what is actually wanted---*/
if(psys_in_edit_mode(scene, psys))
- if(psys->renderdata==0 && (psys->edit==NULL || pset->flag & PE_SHOW_CHILD)==0)
+ if(psys->renderdata==0 && (psys->edit==NULL || pset->flag & PE_DRAW_PART)==0)
totchild=0;
if(totchild && part->from!=PART_FROM_PARTICLE && part->childtype==PART_CHILD_FACES){
@@ -2245,7 +2346,7 @@ void psys_thread_create_path(ParticleThread *thread, struct ChildParticle *cpa,
needupdate= 0;
w= 0;
while(w<4 && cpa->pa[w]>=0) {
- if(psys->particles[cpa->pa[w]].flag & PARS_EDIT_RECALC) {
+ if(psys->edit->points[cpa->pa[w]].flag & PEP_EDIT_RECALC) {
needupdate= 1;
break;
}
@@ -2288,7 +2389,7 @@ void psys_thread_create_path(ParticleThread *thread, struct ChildParticle *cpa,
}
else{
if(ctx->editupdate && !(part->flag & PART_BRANCHING)) {
- if(!(psys->particles[cpa->parent].flag & PARS_EDIT_RECALC))
+ if(!(psys->edit->points[cpa->parent].flag & PEP_EDIT_RECALC))
return;
memset(keys, 0, sizeof(*keys)*(ctx->steps+1));
@@ -2501,6 +2602,9 @@ void psys_cache_child_paths(Scene *scene, Object *ob, ParticleSystem *psys, floa
ListBase threads;
int i, totchild, totparent, totthread;
+ if(psys->flag & PSYS_GLOBAL_HAIR)
+ return;
+
pthreads= psys_threads_create(scene, ob, psys);
if(!psys_threads_init_path(pthreads, scene, cfra, editupdate)) {
@@ -2557,158 +2661,111 @@ void psys_cache_child_paths(Scene *scene, Object *ob, ParticleSystem *psys, floa
/* -Usefull for making use of opengl vertex arrays for super fast strand drawing. */
/* -Makes child strands possible and creates them too into the cache. */
/* -Cached path data is also used to determine cut position for the editmode tool. */
-void psys_cache_paths(Scene *scene, Object *ob, ParticleSystem *psys, float cfra, int editupdate)
+void psys_cache_paths(Scene *scene, Object *ob, ParticleSystem *psys, float cfra)
{
- ParticleCacheKey *ca, **cache=psys->pathcache;
+ ParticleCacheKey *ca, **cache= psys->pathcache;
ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys);
- ParticleEditSettings *pset = &scene->toolsettings->particle;
ParticleSettings *part = psys->part;
+ ParticleEditSettings *pset = &scene->toolsettings->particle;
+
+ DerivedMesh *hair_dm = psys->hair_out_dm;
- ParticleData *pa;
+ ParticleData *pa = psys->particles;
ParticleKey result;
-
- ParticleEdit *edit = 0;
- ParticleEditKey *ekey = 0;
-
- SoftBody *soft = 0;
- BodyPoint *bp[2] = {NULL, NULL};
Material *ma;
-
ParticleInterpolationData pind;
float birthtime = 0.0, dietime = 0.0;
- float t, time = 0.0, keytime = 0.0, dfra = 1.0, frs_sec = scene->r.frs_sec;
+ float t, time = 0.0, dfra = 1.0, frs_sec = scene->r.frs_sec;
float col[4] = {0.5f, 0.5f, 0.5f, 1.0f};
float prev_tangent[3], hairmat[4][4];
float rotmat[3][3];
int k,i;
- int steps = (int)pow(2.0, (double)psys->part->draw_step);
+ int steps = (int)pow(2.0, (double)(psys->renderdata ? part->ren_step : part->draw_step));
int totpart = psys->totpart;
- float sel_col[3];
- float nosel_col[3];
float length, vec[3];
float *vg_effector= NULL, effector=0.0f;
float *vg_length= NULL, pa_length=1.0f;
int keyed, baked;
/* we don't have anything valid to create paths from so let's quit here */
- if((psys->flag & PSYS_HAIR_DONE)==0 && (psys->flag & PSYS_KEYED)==0 && (psys->pointcache->flag & PTCACHE_BAKED)==0)
+ if((psys->flag & PSYS_HAIR_DONE || psys->flag & PSYS_KEYED || psys->pointcache->flag & PTCACHE_BAKED)==0)
return;
+ if(psys_in_edit_mode(scene, psys))
+ if(psys->renderdata==0 && (psys->edit==NULL || pset->flag & PE_DRAW_PART)==0)
+ return;
+
BLI_srandom(psys->seed);
keyed = psys->flag & PSYS_KEYED;
- baked = psys->pointcache->flag & PTCACHE_BAKED;
+ baked = !hair_dm && psys->pointcache->flag & PTCACHE_BAKED;
- if(psys->renderdata) {
- steps = (int)pow(2.0, (double)psys->part->ren_step);
- }
- else if(psys_in_edit_mode(scene, psys)) {
- edit=psys->edit;
-
- //timed = edit->draw_timed;
-
- if(pset->brushtype == PE_BRUSH_WEIGHT) {
- sel_col[0] = sel_col[1] = sel_col[2] = 1.0f;
- nosel_col[0] = nosel_col[1] = nosel_col[2] = 0.0f;
- }
- else{
- sel_col[0] = (float)edit->sel_col[0] / 255.0f;
- sel_col[1] = (float)edit->sel_col[1] / 255.0f;
- sel_col[2] = (float)edit->sel_col[2] / 255.0f;
- nosel_col[0] = (float)edit->nosel_col[0] / 255.0f;
- nosel_col[1] = (float)edit->nosel_col[1] / 255.0f;
- nosel_col[2] = (float)edit->nosel_col[2] / 255.0f;
- }
- }
+ /* clear out old and create new empty path cache */
+ psys_free_path_cache(psys, psys->edit);
+ cache= psys->pathcache= psys_alloc_path_cache_buffers(&psys->pathcachebufs, totpart, steps+1);
- if(editupdate && psys->pathcache && totpart == psys->totcached) {
- cache = psys->pathcache;
- }
- else {
- /* clear out old and create new empty path cache */
- psys_free_path_cache(psys);
- cache= psys_alloc_path_cache_buffers(&psys->pathcachebufs, totpart, steps+1);
- psys->pathcache= cache;
- }
-
- if(edit==NULL && psys->soft && psys->softflag & OB_SB_ENABLE) {
- soft = psys->soft;
- if(!soft->bpoint)
- soft= NULL;
- }
-
psys->lattice = psys_get_lattice(scene, ob, psys);
ma= give_current_material(ob, psys->part->omat);
if(ma && (psys->part->draw & PART_DRAW_MAT_COL))
VECCOPY(col, &ma->r)
-
- if(psys->part->from!=PART_FROM_PARTICLE) {
+
+ if(psys->part->from!=PART_FROM_PARTICLE && !(psys->flag & PSYS_GLOBAL_HAIR)) {
if(!(psys->part->flag & PART_CHILD_EFFECT))
vg_effector = psys_cache_vgroup(psmd->dm, psys, PSYS_VG_EFFECTOR);
- if(!edit && !psys->totchild)
+ if(!psys->totchild)
vg_length = psys_cache_vgroup(psmd->dm, psys, PSYS_VG_LENGTH);
}
/*---first main loop: create all actual particles' paths---*/
- for(i=0,pa=psys->particles; i<totpart; i++, pa++){
- if(psys && edit==NULL && (pa->flag & PARS_NO_DISP || pa->flag & PARS_UNEXIST)) {
- if(soft)
- bp[0] += pa->totkey; /* TODO use of initialized value? */
+ for(i=0; i<totpart; i++, pa++){
+ if(pa->flag & PARS_NO_DISP || pa->flag & PARS_UNEXIST)
continue;
- }
- if(editupdate && !(pa->flag & PARS_EDIT_RECALC)) continue;
- else memset(cache[i], 0, sizeof(*cache[i])*(steps+1));
-
- if(!edit && !psys->totchild) {
- pa_length = 1.0f - part->randlength * 0.5 * (1.0f + pa->r_ave[0]);
+ if(!psys->totchild) {
+ BLI_srandom(psys->seed + i);
+ pa_length = 1.0f - part->randlength * BLI_frand();
if(vg_length)
pa_length *= psys_particle_value_from_verts(psmd->dm,part->from,pa,vg_length);
}
- cache[i]->steps = steps;
+ pind.keyed = keyed;
+ pind.cache = baked ? psys->pointcache : NULL;
+ pind.epoint = NULL;
+ pind.bspline = (psys->part->flag & PART_HAIR_BSPLINE);
+ pind.dm = hair_dm;
+
+ memset(cache[i], 0, sizeof(*cache[i])*(steps+1));
- if(edit)
- ekey = edit->keys[i];
+ cache[i]->steps = steps;
/*--get the first data points--*/
- pind.keyed = keyed;
- pind.cached = baked;
- pind.soft = soft;
init_particle_interpolation(ob, psys, pa, &pind);
-
/* hairmat is needed for for non-hair particle too so we get proper rotations */
psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, hairmat);
VECCOPY(rotmat[0], hairmat[2]);
VECCOPY(rotmat[1], hairmat[1]);
VECCOPY(rotmat[2], hairmat[0]);
- if(!edit) {
- if(part->draw & PART_ABS_PATH_TIME) {
- birthtime = MAX2(pind.birthtime, part->path_start);
- dietime = MIN2(pind.dietime, part->path_end);
- }
- else {
- float tb = pind.birthtime;
- birthtime = tb + part->path_start * (pind.dietime - tb);
- dietime = tb + part->path_end * (pind.dietime - tb);
- }
-
- if(birthtime >= dietime) {
- cache[i]->steps = -1;
- continue;
- }
+ if(part->draw & PART_ABS_PATH_TIME) {
+ birthtime = MAX2(pind.birthtime, part->path_start);
+ dietime = MIN2(pind.dietime, part->path_end);
+ }
+ else {
+ float tb = pind.birthtime;
+ birthtime = tb + part->path_start * (pind.dietime - tb);
+ dietime = tb + part->path_end * (pind.dietime - tb);
+ }
- dietime = birthtime + pa_length * (dietime - birthtime);
+ if(birthtime >= dietime) {
+ cache[i]->steps = -1;
+ continue;
}
- else
- /* XXX brecht: don't know if this code from 2.4 is correct
- * still, but makes hair appear again in particle mode */
- dietime= pind.hkey[0][pa->totkey-1].time;
+
+ dietime = birthtime + pa_length * (dietime - birthtime);
/*--interpolate actual path from data points--*/
for(k=0, ca=cache[i]; k<=steps; k++, ca++){
@@ -2720,46 +2777,16 @@ void psys_cache_paths(Scene *scene, Object *ob, ParticleSystem *psys, float cfra
do_particle_interpolation(psys, i, pa, t, frs_sec, &pind, &result);
- /* keyed, baked and softbody are allready in global space */
- if(!keyed && !baked && !soft) {
+ /* dynamic hair is in object space */
+ /* keyed and baked are allready in global space */
+ if(hair_dm)
+ Mat4MulVecfl(ob->obmat, result.co);
+ else if(!keyed && !baked && !(psys->flag & PSYS_GLOBAL_HAIR))
Mat4MulVecfl(hairmat, result.co);
- }
VECCOPY(ca->co, result.co);
-
- /* selection coloring in edit mode */
- if(edit){
- if(pset->brushtype==PE_BRUSH_WEIGHT){
- if(k==steps)
- VecLerpf(ca->col, nosel_col, sel_col, pind.hkey[0]->weight);
- else
- VecLerpf(ca->col, nosel_col, sel_col,
- (1.0f - keytime) * pind.hkey[0]->weight + keytime * pind.hkey[1]->weight);
- }
- else{
- if((ekey + (pind.hkey[0] - pa->hair))->flag & PEK_SELECT){
- if((ekey + (pind.hkey[1] - pa->hair))->flag & PEK_SELECT){
- VECCOPY(ca->col, sel_col);
- }
- else{
- VecLerpf(ca->col, sel_col, nosel_col, keytime);
- }
- }
- else{
- if((ekey + (pind.hkey[1] - pa->hair))->flag & PEK_SELECT){
- VecLerpf(ca->col, nosel_col, sel_col, keytime);
- }
- else{
- VECCOPY(ca->col, nosel_col);
- }
- }
- }
- }
- else{
- VECCOPY(ca->col, col);
- }
+ VECCOPY(ca->col, col);
}
-
/*--modify paths and calculate rotation & velocity--*/
@@ -2771,64 +2798,66 @@ void psys_cache_paths(Scene *scene, Object *ob, ParticleSystem *psys, float cfra
effector*= psys_particle_value_from_verts(psmd->dm,psys->part->from,pa,vg_effector);
for(k=0, ca=cache[i]; k<=steps; k++, ca++) {
+ if(!(psys->flag & PSYS_GLOBAL_HAIR)) {
/* apply effectors */
- if(!(psys->part->flag & PART_CHILD_EFFECT) && edit==0 && k)
- do_path_effectors(scene, ob, psys, i, ca, k, steps, cache[i]->co, effector, dfra, cfra, &length, vec);
+ if(!(psys->part->flag & PART_CHILD_EFFECT) && k)
+ do_path_effectors(scene, ob, psys, i, ca, k, steps, cache[i]->co, effector, dfra, cfra, &length, vec);
- /* apply guide curves to path data */
- if(edit==0 && psys->effectors.first && (psys->part->flag & PART_CHILD_EFFECT)==0)
- /* ca is safe to cast, since only co and vel are used */
- do_guide(scene, (ParticleKey*)ca, i, (float)k/(float)steps, &psys->effectors);
+ /* apply guide curves to path data */
+ if(psys->effectors.first && (psys->part->flag & PART_CHILD_EFFECT)==0)
+ /* ca is safe to cast, since only co and vel are used */
+ do_guide(scene, (ParticleKey*)ca, i, (float)k/(float)steps, &psys->effectors);
- /* apply lattice */
- if(psys->lattice && edit==0)
- calc_latt_deform(psys->lattice, ca->co, 1.0f);
+ /* apply lattice */
+ if(psys->lattice)
+ 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(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 */
- Mat3ToQuat_is_ok(rotmat, (ca-1)->rot);
- }
- else {
- VECSUB(tangent, ca->co, (ca - 1)->co);
- Normalize(tangent);
-
- cosangle= Inpf(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);
+ /* 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(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 */
+ Mat3ToQuat_is_ok(rotmat, (ca-1)->rot);
}
else {
- angle= saacos(cosangle);
- Crossf(normal, prev_tangent, tangent);
- VecRotToQuat(normal, angle, q);
- QuatMul((ca - 1)->rot, q, (ca - 2)->rot);
+ VECSUB(tangent, ca->co, (ca - 1)->co);
+ Normalize(tangent);
+
+ cosangle= Inpf(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);
+ Crossf(normal, prev_tangent, tangent);
+ VecRotToQuat(normal, angle, q);
+ QuatMul((ca - 1)->rot, q, (ca - 2)->rot);
+ }
+
+ VECCOPY(prev_tangent, tangent);
}
- VECCOPY(prev_tangent, tangent);
+ if(k == steps)
+ QUATCOPY(ca->rot, (ca - 1)->rot);
}
- if(k == steps)
- QUATCOPY(ca->rot, (ca - 1)->rot);
}
-
/* set velocity */
@@ -2856,6 +2885,123 @@ void psys_cache_paths(Scene *scene, Object *ob, ParticleSystem *psys, float cfra
if(vg_length)
MEM_freeN(vg_length);
}
+void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cfra)
+{
+ ParticleCacheKey *ca, **cache= edit->pathcache;
+ ParticleEditSettings *pset = &scene->toolsettings->particle;
+
+ PTCacheEditPoint *point = edit->points;
+ PTCacheEditKey *ekey = NULL;
+
+ ParticleSystem *psys = edit->psys;
+ ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys);
+ ParticleData *pa = psys ? psys->particles : NULL;
+
+ ParticleInterpolationData pind;
+ ParticleKey result;
+
+ float birthtime = 0.0, dietime = 0.0;
+ float t, time = 0.0, keytime = 0.0, frs_sec;
+ float hairmat[4][4];
+ int k,i;
+ int steps = (int)pow(2.0, (double)pset->draw_step);
+ int totpart = edit->totpoint;
+ float sel_col[3];
+ float nosel_col[3];
+
+ steps = MAX2(steps, 4);
+
+ if(!cache || edit->totpoint != edit->totcached) {
+ /* clear out old and create new empty path cache */
+ psys_free_path_cache(edit->psys, edit);
+ cache= edit->pathcache= psys_alloc_path_cache_buffers(&edit->pathcachebufs, totpart, steps+1);
+ }
+
+ frs_sec = (psys || edit->pid.flag & PTCACHE_VEL_PER_SEC) ? 25.0f : 1.0f;
+
+ sel_col[0] = (float)edit->sel_col[0] / 255.0f;
+ sel_col[1] = (float)edit->sel_col[1] / 255.0f;
+ sel_col[2] = (float)edit->sel_col[2] / 255.0f;
+ nosel_col[0] = (float)edit->nosel_col[0] / 255.0f;
+ nosel_col[1] = (float)edit->nosel_col[1] / 255.0f;
+ nosel_col[2] = (float)edit->nosel_col[2] / 255.0f;
+
+ /*---first main loop: create all actual particles' paths---*/
+ for(i=0; i<totpart; i++, pa+=pa?1:0, point++){
+ if(edit->totcached && !(point->flag & PEP_EDIT_RECALC))
+ continue;
+
+ ekey = point->keys;
+
+ pind.keyed = 0;
+ pind.cache = NULL;
+ pind.epoint = point;
+ pind.bspline = psys ? (psys->part->flag & PART_HAIR_BSPLINE) : 0;
+ pind.dm = NULL;
+
+ memset(cache[i], 0, sizeof(*cache[i])*(steps+1));
+
+ cache[i]->steps = steps;
+
+ /*--get the first data points--*/
+ init_particle_interpolation(ob, psys, pa, &pind);
+
+ if(psys)
+ psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, hairmat);
+
+ birthtime = pind.birthtime;
+ dietime = pind.dietime;
+
+ if(birthtime >= dietime) {
+ cache[i]->steps = -1;
+ continue;
+ }
+
+ /*--interpolate actual path from data points--*/
+ for(k=0, ca=cache[i]; k<=steps; k++, ca++){
+ time = (float)k / (float)steps;
+
+ t = birthtime + time * (dietime - birthtime);
+
+ result.time = -t;
+
+ do_particle_interpolation(psys, i, pa, t, frs_sec, &pind, &result);
+
+ /* non-hair points are allready in global space */
+ if(psys && !(psys->flag & PSYS_GLOBAL_HAIR))
+ Mat4MulVecfl(hairmat, result.co);
+
+ VECCOPY(ca->co, result.co);
+
+ ca->vel[0] = ca->vel[1] = 0.0f;
+ ca->vel[1] = 1.0f;
+
+ /* selection coloring in edit mode */
+ if((ekey + (pind.ekey[0] - point->keys))->flag & PEK_SELECT){
+ if((ekey + (pind.ekey[1] - point->keys))->flag & PEK_SELECT){
+ VECCOPY(ca->col, sel_col);
+ }
+ else{
+ keytime = (t - (*pind.ekey[0]->time))/((*pind.ekey[1]->time) - (*pind.ekey[0]->time));
+ VecLerpf(ca->col, sel_col, nosel_col, keytime);
+ }
+ }
+ else{
+ if((ekey + (pind.ekey[1] - point->keys))->flag & PEK_SELECT){
+ keytime = (t - (*pind.ekey[0]->time))/((*pind.ekey[1]->time) - (*pind.ekey[0]->time));
+ VecLerpf(ca->col, nosel_col, sel_col, keytime);
+ }
+ else{
+ VECCOPY(ca->col, nosel_col);
+ }
+ }
+
+ ca->time = t;
+ }
+ }
+
+ edit->totcached = totpart;
+}
/************************************************/
/* Particle Key handling */
/************************************************/
@@ -3056,7 +3202,7 @@ void object_add_particle_system(Scene *scene, Object *ob)
psys->cfra=bsystem_time(scene,ob,scene->r.cfra+1,0.0);
DAG_scene_sort(scene);
- DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+ DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
}
void object_remove_particle_system(Scene *scene, Object *ob)
{
@@ -3079,7 +3225,7 @@ void object_remove_particle_system(Scene *scene, Object *ob)
((ParticleSystem *) ob->particlesystem.first)->flag |= PSYS_CURRENT;
DAG_scene_sort(scene);
- DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+ DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
}
static void default_particle_settings(ParticleSettings *part)
{
@@ -3259,7 +3405,7 @@ void psys_flush_particle_settings(Scene *scene, ParticleSettings *part, int reca
}
}
if(flush)
- DAG_object_flush_update(scene, base->object, OB_RECALC_DATA);
+ DAG_id_flush_update(&base->object->id, OB_RECALC_DATA);
}
}
@@ -3291,7 +3437,7 @@ LinkNode *psys_using_settings(struct Scene *scene, ParticleSettings *part, int f
}
if(flush_update && found)
- DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+ DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
}
return node;
@@ -3470,6 +3616,8 @@ float psys_get_size(Object *ob, Material *ma, ParticleSystemModifierData *psmd,
{
ParticleTexture ptex;
float size=1.0f;
+
+ BLI_srandom(psys->seed + (pa - psys->particles) + 100);
if(ma && part->from!=PART_FROM_PARTICLE){
ptex.size=size;
@@ -3488,7 +3636,7 @@ float psys_get_size(Object *ob, Material *ma, ParticleSystemModifierData *psmd,
size*=psys_particle_value_from_verts(psmd->dm,part->from,pa,vg_size);
if(part->randsize!=0.0)
- size*= 1.0f - part->randsize*pa->sizemul;
+ size*= 1.0f - part->randsize * BLI_frand();
return size*part->size;
}
@@ -3655,16 +3803,10 @@ void psys_get_particle_on_path(Scene *scene, Object *ob, ParticleSystem *psys, i
if(p<totpart){
pa = psys->particles + p;
-
- if(pa->alive==PARS_DEAD && part->flag & PART_STICKY && pa->flag & PARS_STICKY && pa->stick_ob){
- copy_particle_key(state,&pa->state,0);
- key_from_object(pa->stick_ob,state);
- return;
- }
-
pind.keyed = keyed;
- pind.cached = cached;
- pind.soft = NULL;
+ pind.cache = cached ? psys->pointcache : NULL;
+ pind.epoint = NULL;
+ pind.dm = psys->hair_out_dm;
init_particle_interpolation(ob, psys, pa, &pind);
do_particle_interpolation(psys, p, pa, t, frs_sec, &pind, state);
@@ -3876,20 +4018,11 @@ int psys_get_particle_state(struct Scene *scene, Object *ob, ParticleSystem *psy
return 0; /* currently not supported */
else if(psys->totchild && p>=psys->totpart){
ChildParticle *cpa=psys->child+p-psys->totpart;
- ParticleKey *key1, skey;
+ ParticleKey *key1;
float t = (cfra - pa->time + pa->loop * pa->lifetime) / pa->lifetime;
pa = psys->particles + cpa->parent;
-
- if(pa->alive==PARS_DEAD && part->flag&PART_STICKY && pa->flag&PARS_STICKY && pa->stick_ob) {
- key1 = &skey;
- copy_particle_key(key1,&pa->state,0);
- key_from_object(pa->stick_ob,key1);
- }
- else {
- key1=&pa->state;
- }
-
+ key1=&pa->state;
offset_child(cpa, key1, state, part->childflat, part->childrad);
CLAMP(t,0.0,1.0);
@@ -3946,10 +4079,6 @@ int psys_get_particle_state(struct Scene *scene, Object *ob, ParticleSystem *psy
}
}
- if(pa->alive==PARS_DEAD && part->flag&PART_STICKY && pa->flag&PARS_STICKY && pa->stick_ob){
- key_from_object(pa->stick_ob,state);
- }
-
if(psys->lattice)
calc_latt_deform(psys->lattice, state->co,1.0f);
}
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index dcd3fcd2f89..fb12cfe3147 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -73,7 +73,7 @@
#include "BKE_DerivedMesh.h"
#include "BKE_object.h"
#include "BKE_material.h"
-#include "BKE_softbody.h"
+#include "BKE_cloth.h"
#include "BKE_depsgraph.h"
#include "BKE_lattice.h"
#include "BKE_pointcache.h"
@@ -123,21 +123,11 @@ static int get_current_display_percentage(ParticleSystem *psys)
void psys_reset(ParticleSystem *psys, int mode)
{
ParticleSettings *part= psys->part;
- ParticleData *pa;
- int i;
+ PARTICLE_P;
if(ELEM(mode, PSYS_RESET_ALL, PSYS_RESET_DEPSGRAPH)) {
- if(mode == PSYS_RESET_ALL || !(part->type == PART_HAIR && (psys->flag & PSYS_EDITED))) {
- if(psys->particles) {
- if(psys->particles->keys)
- MEM_freeN(psys->particles->keys);
-
- for(i=0, pa=psys->particles; i<psys->totpart; i++, pa++)
- if(pa->hair) MEM_freeN(pa->hair);
-
- MEM_freeN(psys->particles);
- psys->particles= NULL;
- }
+ if(mode == PSYS_RESET_ALL || !(psys->flag & PSYS_EDITED)) {
+ psys_free_particles(psys);
psys->totpart= 0;
psys->totkeyed= 0;
@@ -145,14 +135,17 @@ void psys_reset(ParticleSystem *psys, int mode)
if(psys->reactevents.first)
BLI_freelistN(&psys->reactevents);
+
+ if(psys->edit && psys->free_edit) {
+ psys->free_edit(psys->edit);
+ psys->edit = NULL;
+ psys->free_edit = NULL;
+ }
}
}
else if(mode == PSYS_RESET_CACHE_MISS) {
/* set all particles to be skipped */
- ParticleData *pa = psys->particles;
- int p=0;
-
- for(; p<psys->totpart; p++, pa++)
+ LOOP_PARTICLES
pa->flag |= PARS_NO_DISP;
}
@@ -165,7 +158,7 @@ void psys_reset(ParticleSystem *psys, int mode)
psys->totchild= 0;
/* reset path cache */
- psys_free_path_cache(psys);
+ psys_free_path_cache(psys, psys->edit);
/* reset point cache */
psys->pointcache->flag &= ~PTCACHE_SIMULATION_VALID;
@@ -174,9 +167,10 @@ void psys_reset(ParticleSystem *psys, int mode)
static void realloc_particles(Object *ob, ParticleSystem *psys, int new_totpart)
{
- ParticleData *newpars = 0, *pa;
- BoidData *newboids = 0;
- int i, totpart, totsaved = 0;
+ ParticleData *newpars = NULL;
+ BoidParticle *newboids = NULL;
+ PARTICLE_P;
+ int totpart, totsaved = 0;
if(new_totpart<0) {
if(psys->part->distr==PART_DISTR_GRID && psys->part->from != PART_FROM_VERT) {
@@ -189,47 +183,46 @@ static void realloc_particles(Object *ob, ParticleSystem *psys, int new_totpart)
else
totpart=new_totpart;
- if(totpart) {
+ if(totpart && totpart != psys->totpart) {
newpars= MEM_callocN(totpart*sizeof(ParticleData), "particles");
+
+ if(psys->particles) {
+ totsaved=MIN2(psys->totpart,totpart);
+ /*save old pars*/
+ if(totsaved) {
+ memcpy(newpars,psys->particles,totsaved*sizeof(ParticleData));
+
+ if(psys->particles->boid)
+ memcpy(newboids, psys->particles->boid, totsaved*sizeof(BoidParticle));
+ }
- if(psys->part->phystype == PART_PHYS_BOIDS)
- newboids = MEM_callocN(totpart*sizeof(BoidData), "Boid Data");
- }
- if(psys->particles) {
- totsaved=MIN2(psys->totpart,totpart);
- /*save old pars*/
- if(totsaved) {
- memcpy(newpars,psys->particles,totsaved*sizeof(ParticleData));
-
- if(newboids)
- memcpy(newboids, psys->particles->boid, totsaved*sizeof(BoidData));
- }
-
- if(psys->particles->keys)
- MEM_freeN(psys->particles->keys);
+ if(psys->particles->keys)
+ MEM_freeN(psys->particles->keys);
- if(psys->particles->boid)
- MEM_freeN(psys->particles->boid);
+ if(psys->particles->boid)
+ MEM_freeN(psys->particles->boid);
- for(i=0, pa=newpars; i<totsaved; i++, pa++) {
- if(pa->keys) {
- pa->keys= NULL;
- pa->totkey= 0;
+ for(p=0, pa=newpars; p<totsaved; p++, pa++) {
+ if(pa->keys) {
+ pa->keys= NULL;
+ pa->totkey= 0;
+ }
}
- }
- for(i=totsaved, pa=psys->particles+totsaved; i<psys->totpart; i++, pa++)
- if(pa->hair) MEM_freeN(pa->hair);
+ for(p=totsaved, pa=psys->particles+totsaved; p<psys->totpart; p++, pa++)
+ if(pa->hair) MEM_freeN(pa->hair);
- MEM_freeN(psys->particles);
- }
- psys->particles=newpars;
+ MEM_freeN(psys->particles);
+ }
+
+ psys->particles=newpars;
- if(newboids) {
- pa = psys->particles;
- pa->boid = newboids;
- for(i=1, pa++; i<totpart; i++,pa++)
- pa->boid = (pa-1)->boid + 1;
+ if(newboids) {
+ LOOP_PARTICLES
+ pa->boid = newboids++;
+ }
+
+ psys->totpart=totpart;
}
if(psys->child) {
@@ -237,8 +230,6 @@ static void realloc_particles(Object *ob, ParticleSystem *psys, int new_totpart)
psys->child=0;
psys->totchild=0;
}
-
- psys->totpart=totpart;
}
static int get_psys_child_number(struct Scene *scene, ParticleSystem *psys)
@@ -285,8 +276,7 @@ void psys_calc_dmcache(Object *ob, DerivedMesh *dm, ParticleSystem *psys)
each original elements can reference its derived elements
*/
Mesh *me= (Mesh*)ob->data;
- ParticleData *pa= 0;
- int p;
+ PARTICLE_P;
/* CACHE LOCATIONS */
if(!dm->deformedOnly) {
@@ -323,7 +313,7 @@ void psys_calc_dmcache(Object *ob, DerivedMesh *dm, ParticleSystem *psys)
}
/* cache the verts/faces! */
- for(p=0,pa=psys->particles; p<psys->totpart; p++,pa++) {
+ LOOP_PARTICLES {
if(psys->part->from == PART_FROM_VERT) {
if(nodearray[pa->num])
pa->num_dmcache= GET_INT_FROM_POINTER(nodearray[pa->num]->link);
@@ -343,7 +333,7 @@ void psys_calc_dmcache(Object *ob, DerivedMesh *dm, ParticleSystem *psys)
* should know to use the num or num_dmcache, set the num_dmcache to
* an invalid value, just incase */
- for(p=0,pa=psys->particles; p<psys->totpart; p++,pa++)
+ LOOP_PARTICLES
pa->num_dmcache = -1;
}
}
@@ -1443,12 +1433,11 @@ static void distribute_particles_on_dm(DerivedMesh *finaldm, Scene *scene, Objec
/* ready for future use, to emit particles without geometry */
static void distribute_particles_on_shape(Object *ob, ParticleSystem *psys, int from)
{
- ParticleData *pa;
- int totpart=psys->totpart, p;
+ PARTICLE_P;
fprintf(stderr,"Shape emission not yet possible!\n");
- for(p=0,pa=psys->particles; p<totpart; p++,pa++){
+ LOOP_PARTICLES {
pa->fuv[0]=pa->fuv[1]=pa->fuv[2]=pa->fuv[3]= 0.0;
pa->foffset= 0.0f;
pa->num= -1;
@@ -1470,12 +1459,11 @@ static void distribute_particles(Scene *scene, Object *ob, ParticleSystem *psys,
distribute_particles_on_shape(ob,psys,from);
if(distr_error){
- ParticleData *pa;
- int totpart=psys->totpart, p;
+ PARTICLE_P;
fprintf(stderr,"Particle distribution error!\n");
- for(p=0,pa=psys->particles; p<totpart; p++,pa++){
+ LOOP_PARTICLES {
pa->fuv[0]=pa->fuv[1]=pa->fuv[2]=pa->fuv[3]= 0.0;
pa->foffset= 0.0f;
pa->num= -1;
@@ -1570,7 +1558,7 @@ void initialize_particle(ParticleData *pa, int p, Object *ob, ParticleSystem *ps
Material *ma=0;
//IpoCurve *icu=0; // XXX old animation system
int totpart;
- float rand,length;
+ float rand;
part=psys->part;
@@ -1625,40 +1613,8 @@ void initialize_particle(ParticleData *pa, int p, Object *ob, ParticleSystem *ps
pa->dietime= pa->time+pa->lifetime;
- pa->sizemul= BLI_frand();
-
- rand= BLI_frand();
-
- /* while loops are to have a spherical distribution (avoid cubic distribution) */
- if(part->phystype != PART_PHYS_BOIDS) {
- /* boids store gravity in r_ve, so skip here */
- length=2.0f;
- while(length>1.0){
- pa->r_ve[0]=2.0f*(BLI_frand()-0.5f);
- pa->r_ve[1]=2.0f*(BLI_frand()-0.5f);
- pa->r_ve[2]=2.0f*(BLI_frand()-0.5f);
- length=VecLength(pa->r_ve);
- }
- }
-
- length=2.0f;
- while(length>1.0){
- pa->r_ave[0]=2.0f*(BLI_frand()-0.5f);
- pa->r_ave[1]=2.0f*(BLI_frand()-0.5f);
- pa->r_ave[2]=2.0f*(BLI_frand()-0.5f);
- length=VecLength(pa->r_ave);
- }
-
- pa->r_rot[0]=2.0f*(BLI_frand()-0.5f);
- pa->r_rot[1]=2.0f*(BLI_frand()-0.5f);
- pa->r_rot[2]=2.0f*(BLI_frand()-0.5f);
- pa->r_rot[3]=2.0f*(BLI_frand()-0.5f);
-
- NormalQuat(pa->r_rot);
-
if(part->type!=PART_HAIR && part->distr!=PART_DISTR_GRID && part->from != PART_FROM_VERT){
- /* any unique random number will do (r_ave[0]) */
- if(ptex.exist < 0.5*(1.0+pa->r_ave[0]))
+ if(ptex.exist < BLI_frand())
pa->flag |= PARS_UNEXIST;
else
pa->flag &= ~PARS_UNEXIST;
@@ -1672,10 +1628,9 @@ void initialize_particle(ParticleData *pa, int p, Object *ob, ParticleSystem *ps
static void initialize_all_particles(Object *ob, ParticleSystem *psys, ParticleSystemModifierData *psmd)
{
//IpoCurve *icu=0; // XXX old animation system
- ParticleData *pa;
- int p, totpart=psys->totpart;
+ PARTICLE_P;
- for(p=0, pa=psys->particles; p<totpart; p++, pa++)
+ LOOP_PARTICLES
initialize_particle(pa,p,ob,psys,psmd);
if(psys->part->type != PART_FLUID) {
@@ -1743,10 +1698,39 @@ void reset_particle(Scene *scene, ParticleData *pa, ParticleSystem *psys, Partic
float fac, phasefac, nor[3]={0,0,0},loc[3],tloc[3],vel[3]={0.0,0.0,0.0},rot[4],q2[4];
float r_vel[3],r_ave[3],r_rot[4],p_vel[3]={0.0,0.0,0.0};
float x_vec[3]={1.0,0.0,0.0}, utan[3]={0.0,1.0,0.0}, vtan[3]={0.0,0.0,1.0}, rot_vec[3]={0.0,0.0,0.0};
- float q_phase[4];
+ float q_phase[4], length, r_phase;
part=psys->part;
ptex.ivel=1.0;
+
+ BLI_srandom(psys->seed + (pa - psys->particles));
+
+ /* we need to get every random even if they're not used so that they don't effect eachother */
+ /* while loops are to have a spherical distribution (avoid cubic distribution) */
+ length=2.0f;
+ while(length>1.0){
+ r_vel[0]=2.0f*(BLI_frand()-0.5f);
+ r_vel[1]=2.0f*(BLI_frand()-0.5f);
+ r_vel[2]=2.0f*(BLI_frand()-0.5f);
+ length=VecLength(r_vel);
+ }
+
+ length=2.0f;
+ while(length>1.0){
+ r_ave[0]=2.0f*(BLI_frand()-0.5f);
+ r_ave[1]=2.0f*(BLI_frand()-0.5f);
+ r_ave[2]=2.0f*(BLI_frand()-0.5f);
+ length=VecLength(r_ave);
+ }
+
+ r_rot[0]=2.0f*(BLI_frand()-0.5f);
+ r_rot[1]=2.0f*(BLI_frand()-0.5f);
+ r_rot[2]=2.0f*(BLI_frand()-0.5f);
+ r_rot[3]=2.0f*(BLI_frand()-0.5f);
+
+ NormalQuat(r_rot);
+
+ r_phase = BLI_frand();
if(part->from==PART_FROM_PARTICLE){
Object *tob;
@@ -1757,29 +1741,26 @@ void reset_particle(Scene *scene, ParticleData *pa, ParticleSystem *psys, Partic
if(tob==0)
tob=ob;
- tpsys=BLI_findlink(&tob->particlesystem,psys->target_psys-1);
+ tpsys=BLI_findlink(&tob->particlesystem, psys->target_psys-1);
state.time = pa->time;
if(pa->num == -1)
memset(&state, 0, sizeof(state));
else
psys_get_particle_state(scene, tob,tpsys,pa->num,&state,1);
- psys_get_from_key(&state,loc,nor,rot,0);
+ psys_get_from_key(&state, loc, nor, rot, 0);
- QuatMulVecf(rot,vtan);
- QuatMulVecf(rot,utan);
- VECCOPY(r_vel,pa->r_ve);
- VECCOPY(r_rot,pa->r_rot);
- VECCOPY(r_ave,pa->r_ave);
+ QuatMulVecf(rot, vtan);
+ QuatMulVecf(rot, utan);
- VECCOPY(p_vel,state.vel);
+ VECCOPY(p_vel, state.vel);
speed=Normalize(p_vel);
- VecMulf(p_vel,Inpf(pa->r_ve,p_vel));
- VECSUB(p_vel,pa->r_ve,p_vel);
+ VecMulf(p_vel, Inpf(r_vel, p_vel));
+ VECSUB(p_vel, r_vel, p_vel);
Normalize(p_vel);
- VecMulf(p_vel,speed);
+ VecMulf(p_vel, speed);
- VECCOPY(pa->fuv,loc); /* abusing pa->fuv (not used for "from particle") for storing emit location */
+ VECCOPY(pa->fuv, loc); /* abusing pa->fuv (not used for "from particle") for storing emit location */
}
else{
/* get precise emitter matrix if particle is born */
@@ -1833,29 +1814,25 @@ void reset_particle(Scene *scene, ParticleData *pa, ParticleSystem *psys, Partic
/* -velocity */
if(part->randfac!=0.0){
- VECADD(r_vel,tloc,pa->r_ve);
- Mat4MulVecfl(ob->obmat,r_vel);
- VECSUB(r_vel,r_vel,loc);
+ Mat4Mul3Vecfl(ob->obmat,r_vel);
Normalize(r_vel);
}
/* -angular velocity */
if(part->avemode==PART_AVE_RAND){
- VECADD(r_ave,tloc,pa->r_ave);
- Mat4MulVecfl(ob->obmat,r_ave);
- VECSUB(r_ave,r_ave,loc);
+ Mat4Mul3Vecfl(ob->obmat,r_ave);
Normalize(r_ave);
}
/* -rotation */
if(part->randrotfac != 0.0f){
- QUATCOPY(r_rot,pa->r_rot);
Mat4ToQuat(ob->obmat,rot);
QuatMul(r_rot,r_rot,rot);
}
}
if(part->phystype==PART_PHYS_BOIDS) {
+ BoidParticle *bpa = pa->boid;
float dvec[3], q[4], mat[3][3];
VECCOPY(pa->state.co,loc);
@@ -1872,16 +1849,21 @@ void reset_particle(Scene *scene, ParticleData *pa, ParticleSystem *psys, Partic
VECCOPY(pa->state.ave, nor);
}
/* and gravity in r_ve */
- pa->r_ve[0] = pa->r_ve[1] = 0.0f;
- pa->r_ve[2] = -1.0f;
+ bpa->gravity[0] = bpa->gravity[1] = 0.0f;
+ bpa->gravity[2] = -1.0f;
if(part->acc[2]!=0.0f)
- pa->r_ve[2] = part->acc[2];
+ bpa->gravity[2] = part->acc[2];
+
+ //pa->r_ve[0] = pa->r_ve[1] = 0.0f;
+ //pa->r_ve[2] = -1.0f;
+ //if(part->acc[2]!=0.0f)
+ // pa->r_ve[2] = part->acc[2];
/* calculate rotation matrix */
- Projf(dvec, pa->r_ve, pa->state.ave);
+ Projf(dvec, r_vel, pa->state.ave);
VecSubf(mat[0], pa->state.ave, dvec);
Normalize(mat[0]);
- VECCOPY(mat[2], pa->r_ve);
+ VECCOPY(mat[2], r_vel);
VecMulf(mat[2], -1.0f);
Normalize(mat[2]);
Crossf(mat[1], mat[2], mat[0]);
@@ -1890,10 +1872,10 @@ void reset_particle(Scene *scene, ParticleData *pa, ParticleSystem *psys, Partic
Mat3ToQuat_is_ok(mat, q);
QuatCopy(pa->state.rot, q);
- pa->boid->health = part->boids->health;
- pa->boid->mode = eBoidMode_InAir;
- pa->boid->state_id = ((BoidState*)part->boids->states.first)->id;
- pa->boid->acc[0]=pa->boid->acc[1]=pa->boid->acc[2]=0.0f;
+ bpa->data.health = part->boids->health;
+ bpa->data.mode = eBoidMode_InAir;
+ bpa->data.state_id = ((BoidState*)part->boids->states.first)->id;
+ bpa->data.acc[0]=bpa->data.acc[1]=bpa->data.acc[2]=0.0f;
}
else {
/* conversion done so now we apply new: */
@@ -1982,8 +1964,8 @@ void reset_particle(Scene *scene, ParticleData *pa, ParticleSystem *psys, Partic
/* rotation phase */
phasefac = part->phasefac;
- if(part->randphasefac != 0.0f) /* abuse r_ave[0] as a random number */
- phasefac += part->randphasefac * pa->r_ave[0];
+ if(part->randphasefac != 0.0f)
+ phasefac += part->randphasefac * r_phase;
VecRotToQuat(x_vec, phasefac*(float)M_PI, q_phase);
/* combine base rotation & phase */
@@ -2021,8 +2003,7 @@ void reset_particle(Scene *scene, ParticleData *pa, ParticleSystem *psys, Partic
pa->state.time = cfra;
- pa->stick_ob = 0;
- pa->flag &= ~PARS_STICKY;
+// pa->flag &= ~PARS_STICKY;
}
static void reset_all_particles(Scene *scene, Object *ob, ParticleSystem *psys, ParticleSystemModifierData *psmd, float dtime, float cfra, int from)
{
@@ -2088,8 +2069,9 @@ static void set_keyed_keys(Scene *scene, Object *ob, ParticleSystem *psys)
{
ParticleSystem *kpsys = psys;
ParticleTarget *pt;
- ParticleData *pa;
- int totpart = psys->totpart, i, k, totkeys = psys->totkeyed;
+ PARTICLE_P;
+ ParticleKey *key;
+ int totpart = psys->totpart, k, totkeys = psys->totkeyed;
/* no proper targets so let's clear and bail out */
if(psys->totkeyed==0) {
@@ -2101,12 +2083,12 @@ static void set_keyed_keys(Scene *scene, Object *ob, ParticleSystem *psys)
if(totpart && psys->particles->totkey != totkeys) {
free_keyed_keys(psys);
- psys->particles->keys = MEM_callocN(totpart*totkeys*sizeof(ParticleKey), "Keyed keys");
- psys->particles->totkey = totkeys;
+ key = MEM_callocN(totpart*totkeys*sizeof(ParticleKey), "Keyed keys");
- for(i=1, pa=psys->particles+1; i<totpart; i++,pa++){
- pa->keys = (pa-1)->keys + totkeys;
+ LOOP_PARTICLES {
+ pa->keys = key;
pa->totkey = totkeys;
+ key += totkeys;
}
}
@@ -2120,22 +2102,23 @@ static void set_keyed_keys(Scene *scene, Object *ob, ParticleSystem *psys)
else
kpsys = BLI_findlink(&ob->particlesystem, pt->psys - 1);
- for(i=0,pa=psys->particles; i<totpart; i++, pa++) {
- (pa->keys + k)->time = -1.0; /* use current time */
+ LOOP_PARTICLES {
+ key = pa->keys + k;
+ key->time = -1.0; /* use current time */
- psys_get_particle_state(scene, pt->ob, kpsys, i%kpsys->totpart, pa->keys + k, 1);
+ psys_get_particle_state(scene, pt->ob, kpsys, p%kpsys->totpart, key, 1);
if(psys->flag & PSYS_KEYED_TIMING){
- (pa->keys+k)->time = pa->time + pt->time;
+ key->time = pa->time + pt->time;
if(pt->duration != 0.0f && k+1 < totkeys) {
- copy_particle_key(pa->keys+k+1, pa->keys+k, 1);
- (pa->keys+k+1)->time = pa->time + pt->time + pt->duration;
+ copy_particle_key(key+1, key, 1);
+ (key+1)->time = pa->time + pt->time + pt->duration;
}
}
else if(totkeys > 1)
- (pa->keys+k)->time = pa->time + (float)k / (float)(totkeys - 1) * pa->lifetime;
+ key->time = pa->time + (float)k / (float)(totkeys - 1) * pa->lifetime;
else
- pa->keys->time = pa->time;
+ key->time = pa->time;
}
if(psys->flag & PSYS_KEYED_TIMING && pt->duration!=0.0f)
@@ -2274,7 +2257,7 @@ void psys_clear_temp_pointcache(ParticleSystem *psys)
if((psys->pointcache->flag & PTCACHE_DISK_CACHE)==0)
return;
- BKE_ptache_free_mem(psys->pointcache);
+ BKE_ptcache_free_mem(&psys->pointcache->mem_cache);
}
void psys_get_pointcache_start_end(Scene *scene, ParticleSystem *psys, int *sfra, int *efra)
{
@@ -2290,16 +2273,15 @@ void psys_get_pointcache_start_end(Scene *scene, ParticleSystem *psys, int *sfra
static void update_particle_tree(ParticleSystem *psys)
{
if(psys) {
- ParticleData *pa = psys->particles;
- int p, totpart = psys->totpart;
+ PARTICLE_P;
if(!psys->tree || psys->tree_frame != psys->cfra) {
BLI_kdtree_free(psys->tree);
- psys->tree = BLI_kdtree_new(totpart);
+ psys->tree = BLI_kdtree_new(psys->totpart);
- for(p=0, pa=psys->particles; p<totpart; p++,pa++){
+ LOOP_PARTICLES {
if(pa->flag & (PARS_NO_DISP+PARS_UNEXIST) || pa->alive != PARS_ALIVE)
continue;
@@ -2542,9 +2524,9 @@ static void precalc_effectors(Scene *scene, Object *ob, ParticleSystem *psys, Pa
ListBase *lb=&psys->effectors;
ParticleEffectorCache *ec;
ParticleSettings *part=psys->part;
- ParticleData *pa;
- float vec2[3],loc[3],*co=0;
- int p,totpart;
+ PARTICLE_P;
+ int totpart;
+ float vec2[3],loc[3],radius,*co=0;
for(ec= lb->first; ec; ec= ec->next) {
PartDeflect *pd= ec->ob->pd;
@@ -2554,7 +2536,7 @@ static void precalc_effectors(Scene *scene, Object *ob, ParticleSystem *psys, Pa
&& part->phystype!=PART_PHYS_BOIDS) {
float vec[4];
- where_on_path(ec->ob, 0.0, vec, vec2);
+ where_on_path(ec->ob, 0.0, vec, vec2, NULL, &radius);
Mat4MulVecfl(ec->ob->obmat,vec);
Mat4Mul3Vecfl(ec->ob->obmat,vec2);
@@ -2562,13 +2544,15 @@ static void precalc_effectors(Scene *scene, Object *ob, ParticleSystem *psys, Pa
QUATCOPY(ec->firstloc,vec);
VECCOPY(ec->firstdir,vec2);
+ /* TODO - use 'radius' to adjust the effector */
+
totpart=psys->totpart;
if(totpart){
ec->distances=MEM_callocN(totpart*sizeof(float),"particle distances");
ec->locations=MEM_callocN(totpart*3*sizeof(float),"particle locations");
- for(p=0,pa=psys->particles; p<totpart; p++, pa++){
+ LOOP_PARTICLES {
if(part->from == PART_FROM_PARTICLE) {
VECCOPY(loc, pa->fuv);
}
@@ -3238,7 +3222,7 @@ static void deflect_particle(Scene *scene, Object *pob, ParticleSystemModifierDa
ParticleCollision col;
BVHTreeRayHit hit;
float ray_dir[3], zerovec[3]={0.0,0.0,0.0};
- float radius = ((part->flag & PART_SIZE_DEFL)?pa->size:0.0f), boid_z;
+ float radius = ((part->flag & PART_SIZE_DEFL)?pa->size:0.0f), boid_z = 0.0f;
int deflections=0, max_deflections=10;
VECCOPY(col.co1, pa->prev_state.co);
@@ -3247,9 +3231,10 @@ static void deflect_particle(Scene *scene, Object *pob, ParticleSystemModifierDa
/* override for boids */
if(part->phystype == PART_PHYS_BOIDS) {
+ BoidParticle *bpa = pa->boid;
radius = pa->size;
boid_z = pa->state.co[2];
- skip_ob = pa->stick_ob;
+ skip_ob = bpa->ground;
}
/* 10 iterations to catch multiple deflections */
@@ -3319,12 +3304,7 @@ static void deflect_particle(Scene *scene, Object *pob, ParticleSystemModifierDa
deflections=max_deflections;
/* store for reactors */
- copy_particle_key(&reaction_state,&pa->state,0);
-
- if(part->flag & PART_STICKY){
- pa->stick_ob=ob;
- pa->flag |= PARS_STICKY;
- }
+ copy_particle_key(&reaction_state, &pa->state, 0);
}
else {
float nor_vec[3], tan_vec[3], tan_vel[3], vel[3];
@@ -3412,7 +3392,8 @@ static void deflect_particle(Scene *scene, Object *pob, ParticleSystemModifierDa
VECADDFAC(co, co, col.nor, (through ? -0.0001f : 0.0001f));
if(part->phystype == PART_PHYS_BOIDS && part->boids->options & BOID_ALLOW_LAND) {
- if(pa->boid->mode == eBoidMode_OnLand || co[2] <= boid_z) {
+ BoidParticle *bpa = pa->boid;
+ if(bpa->data.mode == eBoidMode_OnLand || co[2] <= boid_z) {
co[2] = boid_z;
vel[2] = 0.0f;
}
@@ -3453,11 +3434,194 @@ static void deflect_particle(Scene *scene, Object *pob, ParticleSystemModifierDa
/************************************************/
/* Hair */
/************************************************/
-static void save_hair(Scene *scene, Object *ob, ParticleSystem *psys, ParticleSystemModifierData *psmd, float cfra){
- ParticleData *pa;
+/* check if path cache or children need updating and do it if needed */
+static void psys_update_path_cache(Scene *scene, Object *ob, ParticleSystemModifierData *psmd, ParticleSystem *psys, float cfra)
+{
+ ParticleSettings *part=psys->part;
+ ParticleEditSettings *pset=&scene->toolsettings->particle;
+ int distr=0,alloc=0,skip=0;
+
+ if((psys->part->childtype && psys->totchild != get_psys_tot_child(scene, psys)) || psys->recalc&PSYS_RECALC_RESET)
+ alloc=1;
+
+ if(alloc || psys->recalc&PSYS_RECALC_CHILD || (psys->vgroup[PSYS_VG_DENSITY] && (ob && ob->mode & OB_MODE_WEIGHT_PAINT)))
+ distr=1;
+
+ if(distr){
+ if(alloc)
+ realloc_particles(ob,psys,psys->totpart);
+
+ if(get_psys_tot_child(scene, psys)) {
+ /* don't generate children while computing the hair keys */
+ if(!(psys->part->type == PART_HAIR) || (psys->flag & PSYS_HAIR_DONE)) {
+ distribute_particles(scene, ob, psys, PART_FROM_CHILD);
+
+ if(part->from!=PART_FROM_PARTICLE && part->childtype==PART_CHILD_FACES && part->parents!=0.0)
+ psys_find_parents(ob,psmd,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)
+ 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(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(scene, ob, psys, cfra);
+
+ /* for render, child particle paths are computed on the fly */
+ 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(scene, ob, psys, cfra, 0);
+ }
+ }
+ else if(psys->pathcache)
+ psys_free_path_cache(psys, NULL);
+}
+
+static void do_hair_dynamics(Scene *scene, Object *ob, ParticleSystem *psys, ParticleSystemModifierData *psmd)
+{
+ DerivedMesh *dm = psys->hair_in_dm;
+ MVert *mvert = NULL;
+ MEdge *medge = NULL;
+ MDeformVert *dvert = NULL;
HairKey *key;
+ PARTICLE_P;
+ int totpoint = 0;
+ int totedge;
+ int k;
+ float hairmat[4][4];
+
+ if(!psys->clmd) {
+ psys->clmd = (ClothModifierData*)modifier_new(eModifierType_Cloth);
+ psys->clmd->sim_parms->goalspring = 0.0f;
+ psys->clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_GOAL|CLOTH_SIMSETTINGS_FLAG_NO_SPRING_COMPRESS;
+ psys->clmd->coll_parms->flags &= ~CLOTH_COLLSETTINGS_FLAG_SELF;
+ }
+
+ /* create a dm from hair vertices */
+ LOOP_PARTICLES
+ totpoint += pa->totkey;
+
+ totedge = totpoint - psys->totpart;
+
+ if(dm && (totpoint != dm->getNumVerts(dm) || totedge != dm->getNumEdges(dm))) {
+ dm->release(dm);
+ dm = psys->hair_in_dm = NULL;
+ }
+
+ if(!dm) {
+ dm = psys->hair_in_dm = CDDM_new(totpoint, totedge, 0);
+ DM_add_vert_layer(dm, CD_MDEFORMVERT, CD_CALLOC, NULL);
+ }
+
+ mvert = CDDM_get_verts(dm);
+ medge = CDDM_get_edges(dm);
+ dvert = DM_get_vert_data_layer(dm, CD_MDEFORMVERT);
+
+ psys->clmd->sim_parms->vgroup_mass = 1;
+
+ /* make vgroup for pin roots etc.. */
+ psys->particles->hair_index = 0;
+ LOOP_PARTICLES {
+ if(p)
+ pa->hair_index = (pa-1)->hair_index + (pa-1)->totkey;
+
+ psys_mat_hair_to_object(ob, psmd->dm, psys->part->from, pa, hairmat);
+
+ for(k=0, key=pa->hair; k<pa->totkey; k++,key++) {
+ VECCOPY(mvert->co, key->co);
+ Mat4MulVecfl(hairmat, mvert->co);
+ mvert++;
+
+ if(k) {
+ medge->v1 = pa->hair_index + k - 1;
+ medge->v2 = pa->hair_index + k;
+ medge++;
+ }
+
+ if(dvert) {
+ if(!dvert->totweight) {
+ dvert->dw = MEM_callocN (sizeof(MDeformWeight), "deformWeight");
+ dvert->totweight = 1;
+ }
+
+ /* no special reason for the 0.5 */
+ /* just seems like a nice value from experiments */
+ dvert->dw->weight = k ? 0.5f : 1.0f;
+ dvert++;
+ }
+ }
+ }
+
+ if(psys->hair_out_dm)
+ psys->hair_out_dm->release(psys->hair_out_dm);
+
+ psys->clmd->point_cache = psys->pointcache;
+
+ psys->hair_out_dm = clothModifier_do(psys->clmd, scene, ob, dm, 0, 0);
+}
+static void hair_step(Scene *scene, Object *ob, ParticleSystemModifierData *psmd, ParticleSystem *psys, float cfra)
+{
+ ParticleSettings *part = psys->part;
+ PARTICLE_P;
+ float disp = (float)get_current_display_percentage(psys)/100.0f;
+
+ BLI_srandom(psys->seed);
+
+ LOOP_PARTICLES {
+ if(BLI_frand() > disp)
+ pa->flag |= PARS_NO_DISP;
+ else
+ pa->flag &= ~PARS_NO_DISP;
+ }
+
+ if(psys->recalc & PSYS_RECALC_RESET) {
+ /* need this for changing subsurf levels */
+ psys_calc_dmcache(ob, psmd->dm, psys);
+
+ if(psys->clmd)
+ cloth_free_modifier(ob, psys->clmd);
+ }
+
+ if(psys->effectors.first)
+ psys_end_effectors(psys);
+
+ /* dynamics with cloth simulation */
+ if(psys->part->type==PART_HAIR && psys->flag & PSYS_HAIR_DYNAMICS)
+ do_hair_dynamics(scene, ob, psys, psmd);
+
+ psys_init_effectors(scene, ob, part->eff_group, psys);
+ if(psys->effectors.first)
+ precalc_effectors(scene, ob,psys,psmd,cfra);
+
+ psys_update_path_cache(scene, ob,psmd,psys,cfra);
+
+ psys->flag |= PSYS_HAIR_UPDATED;
+}
+
+static void save_hair(Scene *scene, Object *ob, ParticleSystem *psys, ParticleSystemModifierData *psmd, float cfra){
+ HairKey *key, *root;
+ PARTICLE_P;
int totpart;
- int i;
Mat4Invert(ob->imat,ob->obmat);
@@ -3468,21 +3632,22 @@ static void save_hair(Scene *scene, Object *ob, ParticleSystem *psys, ParticleSy
totpart=psys->totpart;
/* save new keys for elements if needed */
- for(i=0,pa=psys->particles; i<totpart; i++,pa++) {
+ LOOP_PARTICLES {
/* first time alloc */
if(pa->totkey==0 || pa->hair==NULL) {
pa->hair = MEM_callocN((psys->part->hair_step + 1) * sizeof(HairKey), "HairKeys");
pa->totkey = 0;
}
- key = pa->hair + pa->totkey;
+ key = root = pa->hair;
+ key += pa->totkey;
/* convert from global to geometry space */
VecCopyf(key->co, pa->state.co);
Mat4MulVecfl(ob->imat, key->co);
if(pa->totkey) {
- VECSUB(key->co, key->co, pa->hair->co);
+ VECSUB(key->co, key->co, root->co);
psys_vec_rot_to_face(psmd->dm, pa, key->co);
}
@@ -3494,7 +3659,7 @@ static void save_hair(Scene *scene, Object *ob, ParticleSystem *psys, ParticleSy
/* root is always in the origin of hair space so we set it to be so after the last key is saved*/
if(pa->totkey == psys->part->hair_step + 1)
- pa->hair->co[0] = pa->hair->co[1] = pa->hair->co[2] = 0.0f;
+ root->co[0] = root->co[1] = root->co[2] = 0.0f;
}
}
/************************************************/
@@ -3504,14 +3669,14 @@ static void save_hair(Scene *scene, Object *ob, ParticleSystem *psys, ParticleSy
static void dynamics_step(Scene *scene, Object *ob, ParticleSystem *psys, ParticleSystemModifierData *psmd, float cfra,
float *vg_vel, float *vg_tan, float *vg_rot, float *vg_size)
{
- ParticleData *pa;
ParticleSettings *part=psys->part;
KDTree *tree=0;
IpoCurve *icu_esize= NULL; //=find_ipocurve(part->ipo,PART_EMIT_SIZE); // XXX old animation system
Material *ma=give_current_material(ob,part->omat);
BoidBrainData bbd;
+ PARTICLE_P;
float timestep;
- int p, totpart;
+ int totpart;
/* current time */
float ctime, ipotime; // XXX old animation system
/* frame & time changes */
@@ -3540,7 +3705,7 @@ static void dynamics_step(Scene *scene, Object *ob, ParticleSystem *psys, Partic
if(part->type==PART_REACTOR)
vg_size=psys_cache_vgroup(psmd->dm,psys,PSYS_VG_SIZE);
- for(p=0, pa=psys->particles; p<totpart; p++,pa++){
+ LOOP_PARTICLES {
if(pa->flag & PARS_UNEXIST) continue;
/* set correct ipo timing */
@@ -3609,7 +3774,7 @@ static void dynamics_step(Scene *scene, Object *ob, ParticleSystem *psys, Partic
}
/* main loop: calculate physics for all particles */
- for(p=0, pa=psys->particles; p<totpart; p++,pa++){
+ LOOP_PARTICLES {
if(pa->flag & (PARS_UNEXIST+PARS_NO_DISP)) continue;
copy_particle_key(&pa->prev_state,&pa->state,1);
@@ -3697,9 +3862,6 @@ static void dynamics_step(Scene *scene, Object *ob, ParticleSystem *psys, Partic
else{
pa->alive=PARS_DEAD;
pa->state.time=pa->dietime;
-
- if(pa->flag&PARS_STICKY)
- psys_key_to_object(pa->stick_ob,&pa->state,0);
}
}
else
@@ -3716,116 +3878,18 @@ static void dynamics_step(Scene *scene, Object *ob, ParticleSystem *psys, Partic
BLI_kdtree_free(tree);
}
-/* check if path cache or children need updating and do it if needed */
-static void psys_update_path_cache(Scene *scene, Object *ob, ParticleSystemModifierData *psmd, ParticleSystem *psys, float cfra)
-{
- ParticleSettings *part=psys->part;
- ParticleEditSettings *pset=&scene->toolsettings->particle;
- int distr=0,alloc=0;
-
- if((psys->part->childtype && psys->totchild != get_psys_tot_child(scene, psys)) || psys->recalc&PSYS_RECALC_RESET)
- alloc=1;
-
- if(alloc || psys->recalc&PSYS_RECALC_CHILD || (psys->vgroup[PSYS_VG_DENSITY] && (ob && ob->mode & OB_MODE_WEIGHT_PAINT)))
- distr=1;
-
- if(distr){
- if(alloc)
- realloc_particles(ob,psys,psys->totpart);
-
- if(get_psys_tot_child(scene, psys)) {
- /* don't generate children while computing the hair keys */
- if(!(psys->part->type == PART_HAIR) || (psys->flag & PSYS_HAIR_DONE)) {
- distribute_particles(scene, ob, psys, PART_FROM_CHILD);
-
- if(part->from!=PART_FROM_PARTICLE && part->childtype==PART_CHILD_FACES && part->parents!=0.0)
- psys_find_parents(ob,psmd,psys);
- }
- }
- }
-
- if((part->type==PART_HAIR || psys->flag&PSYS_KEYED || psys->pointcache->flag & PTCACHE_BAKED) && ( psys_in_edit_mode(scene, psys) || (part->type==PART_HAIR
- || (part->ren_as == PART_DRAW_PATH && (part->draw_as == PART_DRAW_REND || psys->renderdata))))){
-
- psys_cache_paths(scene, ob, psys, cfra, 0);
-
- /* for render, child particle paths are computed on the fly */
- if(part->childtype) {
- if(((psys->totchild!=0)) || (psys_in_edit_mode(scene, psys) && (pset->flag&PE_SHOW_CHILD)))
- if(!(psys->part->type == PART_HAIR) || (psys->flag & PSYS_HAIR_DONE))
- psys_cache_child_paths(scene, ob, psys, cfra, 0);
- }
- }
- else if(psys->pathcache)
- psys_free_path_cache(psys);
-}
-
-/* calculate and store key locations in world coordinates */
-void psys_update_world_cos(Object *ob, ParticleSystem *psys)
-{
- ParticleSystemModifierData *psmd= psys_get_modifier(ob, psys);
- ParticleData *pa;
- ParticleEditKey *key;
- int i, k, totpart;
- float hairmat[4][4];
-
- if(psys==0 || psys->edit==0)
- return;
-
- totpart= psys->totpart;
-
- for(i=0, pa=psys->particles; i<totpart; i++, pa++) {
- psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, hairmat);
-
- for(k=0, key=psys->edit->keys[i]; k<pa->totkey; k++, key++) {
- VECCOPY(key->world_co,key->co);
- Mat4MulVecfl(hairmat, key->world_co);
- }
- }
-}
-
-static void hair_step(Scene *scene, Object *ob, ParticleSystemModifierData *psmd, ParticleSystem *psys, float cfra)
-{
- ParticleSettings *part = psys->part;
- ParticleData *pa;
- int p;
- float disp = (float)get_current_display_percentage(psys)/50.0f-1.0f;
-
- for(p=0, pa=psys->particles; p<psys->totpart; p++,pa++){
- if(pa->r_rot[0] > disp)
- pa->flag |= PARS_NO_DISP;
- else
- pa->flag &= ~PARS_NO_DISP;
- }
-
- if(psys->recalc & PSYS_RECALC_RESET)
- /* need this for changing subsurf levels */
- psys_calc_dmcache(ob, psmd->dm, psys);
-
- if(psys->effectors.first)
- psys_end_effectors(psys);
-
- psys_init_effectors(scene, ob, part->eff_group, psys);
- if(psys->effectors.first)
- precalc_effectors(scene, ob,psys,psmd,cfra);
-
- if(psys_in_edit_mode(scene, psys))
- psys_update_world_cos(ob, psys);
-
- psys_update_path_cache(scene, ob,psmd,psys,cfra);
-}
-
/* updates cached particles' alive & other flags etc..*/
static void cached_step(Scene *scene, Object *ob, ParticleSystemModifierData *psmd, ParticleSystem *psys, float cfra)
{
ParticleSettings *part=psys->part;
- ParticleData *pa;
ParticleKey state;
IpoCurve *icu_esize= NULL; //=find_ipocurve(part->ipo,PART_EMIT_SIZE); // XXX old animation system
Material *ma=give_current_material(ob,part->omat);
- int p;
+ PARTICLE_P;
float disp, birthtime, dietime, *vg_size= NULL; // XXX ipotime=cfra
+ BLI_srandom(psys->seed);
+
if(part->from!=PART_FROM_PARTICLE)
vg_size= psys_cache_vgroup(psmd->dm,psys,PSYS_VG_SIZE);
@@ -3838,9 +3902,9 @@ static void cached_step(Scene *scene, Object *ob, ParticleSystemModifierData *ps
precalc_effectors(scene, ob,psys,psmd,cfra);
//}
- disp= (float)get_current_display_percentage(psys)/50.0f-1.0f;
+ disp= (float)get_current_display_percentage(psys)/100.0f;
- for(p=0, pa=psys->particles; p<psys->totpart; p++,pa++){
+ LOOP_PARTICLES {
#if 0 // XXX old animation system
if((part->flag&PART_ABS_TIME)==0 && part->ipo){
ipotime=100.0f*(cfra-pa->time)/pa->lifetime;
@@ -3887,7 +3951,7 @@ static void cached_step(Scene *scene, Object *ob, ParticleSystemModifierData *ps
psys->lattice= NULL;
}
- if(pa->r_rot[0] > disp)
+ if(BLI_frand() > disp)
pa->flag |= PARS_NO_DISP;
else
pa->flag &= ~PARS_NO_DISP;
@@ -3938,35 +4002,35 @@ static void psys_changed_type(Object *ob, ParticleSystem *psys)
BKE_ptcache_id_clear(&pid, PTCACHE_CLEAR_ALL, 0);
}
else {
- free_hair(psys, 1);
+ free_hair(ob, psys, 1);
- CLAMP(part->path_start, part->sta, part->end + part->lifetime);
- CLAMP(part->path_end, part->sta, part->end + part->lifetime);
+ CLAMP(part->path_start, 0.0f, MAX2(100.0f, part->end + part->lifetime));
+ CLAMP(part->path_end, 0.0f, MAX2(100.0f, part->end + part->lifetime));
}
- psys->softflag= 0;
-
psys_reset(psys, PSYS_RESET_ALL);
}
void psys_check_boid_data(ParticleSystem *psys)
{
- ParticleData *pa = psys->particles;
- int p = 1;
+ BoidParticle *bpa;
+ PARTICLE_P;
+
+ pa = psys->particles;
if(!pa)
return;
if(psys->part && psys->part->phystype==PART_PHYS_BOIDS) {
if(!pa->boid) {
- pa->boid = MEM_callocN(psys->totpart * sizeof(BoidData), "Boid Data");
+ bpa = MEM_callocN(psys->totpart * sizeof(BoidParticle), "Boid Data");
- for(pa++; p<psys->totpart; p++, pa++)
- pa->boid = (pa-1)->boid + 1;
+ LOOP_PARTICLES
+ pa->boid = bpa++;
}
}
else if(pa->boid){
MEM_freeN(pa->boid);
- for(; p<psys->totpart; p++, pa++)
+ LOOP_PARTICLES
pa->boid = NULL;
}
}
@@ -4114,10 +4178,10 @@ static void particles_fluid_step(Scene *scene, Object *ob, ParticleSystem *psys,
static void system_step(Scene *scene, Object *ob, ParticleSystem *psys, ParticleSystemModifierData *psmd, float cfra)
{
ParticleSettings *part;
- ParticleData *pa;
PointCache *cache;
PTCacheID pid;
- int totpart, oldtotpart, totchild, oldtotchild, p;
+ PARTICLE_P;
+ int totpart, oldtotpart, totchild, oldtotchild;
float disp, *vg_vel= 0, *vg_tan= 0, *vg_rot= 0, *vg_size= 0;
int init= 0, distr= 0, alloc= 0, usecache= 0, only_children_changed= 0;
int framenr, framedelta, startframe, endframe;
@@ -4129,7 +4193,7 @@ static void system_step(Scene *scene, Object *ob, ParticleSystem *psys, Particle
framedelta= framenr - cache->simframe;
/* set suitable cache range automatically */
- if((cache->flag & (PTCACHE_BAKING|PTCACHE_BAKED))==0)
+ if((cache->flag & (PTCACHE_BAKING|PTCACHE_BAKED))==0 && !(psys->flag & PSYS_HAIR_DYNAMICS))
psys_get_pointcache_start_end(scene, psys, &cache->startframe, &cache->endframe);
BKE_ptcache_id_from_particles(&pid, ob, psys);
@@ -4260,7 +4324,7 @@ static void system_step(Scene *scene, Object *ob, ParticleSystem *psys, Particle
}
else if(result==PTCACHE_READ_OLD) {
psys->cfra = (float)cache->simframe;
- for(p=0, pa=psys->particles; p<totpart; p++, pa++) {
+ LOOP_PARTICLES {
/* update alive status */
if(pa->time > psys->cfra)
pa->alive = PARS_UNBORN;
@@ -4299,10 +4363,11 @@ static void system_step(Scene *scene, Object *ob, ParticleSystem *psys, Particle
}
/* set particles to be not calculated TODO: can't work with pointcache */
- disp= (float)get_current_display_percentage(psys)/50.0f-1.0f;
+ disp= (float)get_current_display_percentage(psys)/100.0f;
- for(p=0, pa=psys->particles; p<totpart; p++,pa++){
- if(pa->r_rot[0] > disp)
+ BLI_srandom(psys->seed);
+ LOOP_PARTICLES {
+ if(BLI_frand() > disp)
pa->flag |= PARS_NO_DISP;
else
pa->flag &= ~PARS_NO_DISP;
@@ -4339,7 +4404,7 @@ static void system_step(Scene *scene, Object *ob, ParticleSystem *psys, Particle
psys_update_path_cache(scene, ob, psmd, psys,(int)cfra);
}
else if(psys->pathcache)
- psys_free_path_cache(psys);
+ psys_free_path_cache(psys, NULL);
/* cleanup */
if(vg_vel) MEM_freeN(vg_vel);
@@ -4353,39 +4418,9 @@ static void system_step(Scene *scene, Object *ob, ParticleSystem *psys, Particle
}
}
-static void psys_to_softbody(Scene *scene, Object *ob, ParticleSystem *psys)
-{
- SoftBody *sb;
- short softflag;
-
- if(!(psys->softflag & OB_SB_ENABLE))
- return;
-
- /* let's replace the object's own softbody with the particle softbody */
- /* a temporary solution before cloth simulation is implemented, jahka */
-
- /* save these */
- sb= ob->soft;
- softflag= ob->softflag;
-
- /* swich to new ones */
- ob->soft= psys->soft;
- ob->softflag= psys->softflag;
-
- /* do softbody */
- sbObjectStep(scene, ob, (float)scene->r.cfra, NULL, psys_count_keys(psys));
-
- /* return things back to normal */
- psys->soft= ob->soft;
- psys->softflag= ob->softflag;
-
- ob->soft= sb;
- ob->softflag= softflag;
-}
-
static int hair_needs_recalc(ParticleSystem *psys)
{
- if((psys->flag & PSYS_EDITED)==0 &&
+ if(!(psys->flag & PSYS_EDITED) && (!psys->edit || !psys->edit->edited) &&
((psys->flag & PSYS_HAIR_DONE)==0 || psys->recalc & PSYS_RECALC_RESET)) {
return 1;
}
@@ -4426,7 +4461,7 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys)
float hcfra=0.0f;
int i;
- free_hair(psys, 0);
+ free_hair(ob, psys, 0);
/* first step is negative so particles get killed and reset */
psys->cfra= 1.0f;
@@ -4440,10 +4475,6 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys)
psys->flag |= PSYS_HAIR_DONE;
}
- /* handle softbody hair */
- if(psys->part->type==PART_HAIR && psys->soft)
- psys_to_softbody(scene, ob, psys);
-
/* the main particle system step */
system_step(scene, ob, psys, psmd, cfra);
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 09170d92866..f351f8a4335 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -59,26 +59,21 @@
#include "BLI_blenlib.h"
+/* both in intern */
#include "smoke_API.h"
+#include "minilzo.h"
+
+#include "LzmaLib.h"
+
/* needed for directory lookup */
+/* untitled blend's need getpid for a unique name */
#ifndef WIN32
#include <dirent.h>
+#include <unistd.h>
#else
- #include "BLI_winstuff.h"
-#endif
-
-/* untitled blend's need getpid for a unique name */
-#ifdef WIN32
#include <process.h>
-#else
-#include <unistd.h>
-#endif
-
-#ifdef _WIN32
-#ifndef snprintf
-#define snprintf _snprintf
-#endif
+ #include "BLI_winstuff.h"
#endif
static void ptcache_data_to(void **data, int type, int index, void *to);
@@ -176,6 +171,7 @@ static int ptcache_write_particle(int index, void *psys_v, void **data)
{
ParticleSystem *psys= psys_v;
ParticleData *pa = psys->particles + index;
+ BoidParticle *boid = (psys->part->phystype == PART_PHYS_BOIDS) ? pa->boid : NULL;
float times[3] = {pa->time, pa->dietime, pa->lifetime};
if(data[BPHYS_DATA_INDEX]) {
@@ -193,8 +189,8 @@ static int ptcache_write_particle(int index, void *psys_v, void **data)
ptcache_data_from(data, BPHYS_DATA_SIZE, &pa->size);
ptcache_data_from(data, BPHYS_DATA_TIMES, times);
- if(pa->boid)
- ptcache_data_from(data, BPHYS_DATA_TIMES, &pa->boid);
+ if(boid)
+ ptcache_data_from(data, BPHYS_DATA_BOIDS, &boid->data);
return 1;
}
@@ -210,6 +206,7 @@ static void ptcache_read_particle(int index, void *psys_v, void **data, float fr
{
ParticleSystem *psys= psys_v;
ParticleData *pa = psys->particles + index;
+ BoidParticle *boid = (psys->part->phystype == PART_PHYS_BOIDS) ? pa->boid : NULL;
if(cfra > pa->state.time)
memcpy(&pa->prev_state, &pa->state, sizeof(ParticleKey));
@@ -233,8 +230,8 @@ static void ptcache_read_particle(int index, void *psys_v, void **data, float fr
pa->lifetime = times[2];
}
- if(pa->boid)
- ptcache_data_to(data, BPHYS_DATA_BOIDS, 0, &pa->boid);
+ if(boid)
+ ptcache_data_to(data, BPHYS_DATA_BOIDS, 0, &boid->data);
/* determine velocity from previous location */
if(data[BPHYS_DATA_LOCATION] && !data[BPHYS_DATA_VELOCITY]) {
@@ -385,10 +382,6 @@ static int ptcache_totpoint_cloth(void *cloth_v)
/* Creating ID's */
void BKE_ptcache_id_from_softbody(PTCacheID *pid, Object *ob, SoftBody *sb)
{
- ParticleSystemModifierData *psmd;
- ModifierData *md;
- int a;
-
memset(pid, 0, sizeof(PTCacheID));
pid->ob= ob;
@@ -411,34 +404,24 @@ void BKE_ptcache_id_from_softbody(PTCacheID *pid, Object *ob, SoftBody *sb)
pid->data_types= (1<<BPHYS_DATA_LOCATION) | (1<<BPHYS_DATA_VELOCITY);
pid->info_types= 0;
- if(sb->particles) {
- psmd= psys_get_modifier(ob, sb->particles);
- pid->stack_index= modifiers_indexInObject(ob, (ModifierData*)psmd);
- }
- else {
- for(a=0, md=ob->modifiers.first; md; md=md->next, a++) {
- if(md->type == eModifierType_Softbody) {
- pid->stack_index = a;
- break;
- }
- }
- }
+ pid->stack_index = pid->cache->index;
}
void BKE_ptcache_id_from_particles(PTCacheID *pid, Object *ob, ParticleSystem *psys)
{
- ParticleSystemModifierData *psmd= psys_get_modifier(ob, psys);
-
memset(pid, 0, sizeof(PTCacheID));
pid->ob= ob;
pid->calldata= psys;
pid->type= PTCACHE_TYPE_PARTICLES;
- pid->stack_index= modifiers_indexInObject(ob, (ModifierData *)psmd);
+ pid->stack_index= psys->pointcache->index;
pid->cache= psys->pointcache;
pid->cache_ptr= &psys->pointcache;
pid->ptcaches= &psys->ptcaches;
+ if(psys->part->type != PART_HAIR)
+ pid->flag |= PTCACHE_VEL_PER_SEC;
+
pid->write_elem= ptcache_write_particle;
pid->write_stream = NULL;
pid->read_stream = NULL;
@@ -469,76 +452,254 @@ void BKE_ptcache_id_from_particles(PTCacheID *pid, Object *ob, ParticleSystem *p
pid->info_types= (1<<BPHYS_DATA_TIMES);
}
-#if 0 // XXX smoke pointcache stuff breaks compiling now
/* Smoke functions */
static int ptcache_totpoint_smoke(void *smoke_v)
{
SmokeModifierData *smd= (SmokeModifierData *)smoke_v;
SmokeDomainSettings *sds = smd->domain;
- if(sds->fluid)
- {
+ if(sds->fluid) {
return sds->res[0]*sds->res[1]*sds->res[2];
}
else
return 0;
}
+/* Smoke functions */
+static int ptcache_totpoint_smoke_turbulence(void *smoke_v)
+{
+ SmokeModifierData *smd= (SmokeModifierData *)smoke_v;
+ SmokeDomainSettings *sds = smd->domain;
+
+ if(sds->wt) {
+ return sds->res_wt[0]*sds->res_wt[1]*sds->res_wt[2];
+ }
+ else
+ return 0;
+}
+
// forward decleration
static int ptcache_file_write(PTCacheFile *pf, void *f, size_t tot, int size);
-static int ptcache_write_smoke(PTCacheFile *pf, void *smoke_v)
+static int ptcache_compress_write(PTCacheFile *pf, unsigned char *in, unsigned int in_len, unsigned char *out, int mode)
{
+ int r = 0;
+ unsigned char compressed;
+ LZO_HEAP_ALLOC(wrkmem, LZO1X_MEM_COMPRESS);
+ unsigned int out_len = LZO_OUT_LEN(in_len);
+ unsigned char *props = MEM_callocN(16*sizeof(char), "tmp");
+ size_t sizeOfIt = 5;
+
+ if(mode == 1) {
+ r = lzo1x_1_compress(in, (lzo_uint)in_len, out, (lzo_uint *)&out_len, wrkmem);
+ if (!(r == LZO_E_OK) || (out_len >= in_len))
+ compressed = 0;
+ else
+ compressed = 1;
+ }
+ else if(mode == 2) {
+
+ r = LzmaCompress(out, (size_t *)&out_len, in, in_len,//assume sizeof(char)==1....
+ props, &sizeOfIt, 5, 1 << 24, 3, 0, 2, 32, 2);
+
+ if(!(r == SZ_OK) || (out_len >= in_len))
+ compressed = 0;
+ else
+ compressed = 2;
+ }
+
+ ptcache_file_write(pf, &compressed, 1, sizeof(unsigned char));
+ if(compressed) {
+ ptcache_file_write(pf, &out_len, 1, sizeof(unsigned int));
+ ptcache_file_write(pf, out, out_len, sizeof(unsigned char));
+ }
+ else
+ ptcache_file_write(pf, in, in_len, sizeof(unsigned char));
+
+ if(compressed == 2)
+ {
+ ptcache_file_write(pf, &sizeOfIt, 1, sizeof(unsigned int));
+ ptcache_file_write(pf, props, sizeOfIt, sizeof(unsigned char));
+ }
+
+ MEM_freeN(props);
+
+ return r;
+}
+
+static int ptcache_write_smoke(PTCacheFile *pf, void *smoke_v)
+{
SmokeModifierData *smd= (SmokeModifierData *)smoke_v;
SmokeDomainSettings *sds = smd->domain;
- if(sds->fluid)
- {
+ if(sds->fluid) {
size_t res = sds->res[0]*sds->res[1]*sds->res[2];
- float *dens, *densold, *heat, *heatold, *vx, *vy, *vz;
-
- smoke_export(sds->fluid, &dens, &densold, &heat, &heatold, &vx, &vy, &vz);
-
- ptcache_file_write(pf, dens, res, sizeof(float));
- ptcache_file_write(pf, densold, res, sizeof(float));
- ptcache_file_write(pf, heat, res, sizeof(float));
- ptcache_file_write(pf, heatold, res, sizeof(float));
- ptcache_file_write(pf, vx, res, sizeof(float));
- ptcache_file_write(pf, vy, res, sizeof(float));
- ptcache_file_write(pf, vz, res, sizeof(float));
+ float dt, dx, *dens, *densold, *heat, *heatold, *vx, *vy, *vz, *vxold, *vyold, *vzold;
+ unsigned char *obstacles;
+ unsigned int in_len = sizeof(float)*(unsigned int)res;
+ unsigned char *out = (unsigned char *)MEM_callocN(LZO_OUT_LEN(in_len)*4, "pointcache_lzo_buffer");
+ int mode = res >= 1000000 ? 2 : 1;
+
+ smoke_export(sds->fluid, &dt, &dx, &dens, &densold, &heat, &heatold, &vx, &vy, &vz, &vxold, &vyold, &vzold, &obstacles);
+
+ ptcache_compress_write(pf, (unsigned char *)sds->shadow, in_len, out, mode);
+ ptcache_compress_write(pf, (unsigned char *)dens, in_len, out, mode);
+ ptcache_compress_write(pf, (unsigned char *)densold, in_len, out, mode);
+ ptcache_compress_write(pf, (unsigned char *)heat, in_len, out, mode);
+ ptcache_compress_write(pf, (unsigned char *)heatold, in_len, out, mode);
+ ptcache_compress_write(pf, (unsigned char *)vx, in_len, out, mode);
+ ptcache_compress_write(pf, (unsigned char *)vy, in_len, out, mode);
+ ptcache_compress_write(pf, (unsigned char *)vz, in_len, out, mode);
+ ptcache_compress_write(pf, (unsigned char *)vxold, in_len, out, mode);
+ ptcache_compress_write(pf, (unsigned char *)vyold, in_len, out, mode);
+ ptcache_compress_write(pf, (unsigned char *)vzold, in_len, out, mode);
+ ptcache_compress_write(pf, (unsigned char *)obstacles, (unsigned int)res, out, mode);
+ ptcache_file_write(pf, &dt, 1, sizeof(float));
+ ptcache_file_write(pf, &dx, 1, sizeof(float));
+
+ MEM_freeN(out);
return 1;
}
+ return 0;
+}
+static int ptcache_write_smoke_turbulence(PTCacheFile *pf, void *smoke_v)
+{
+ SmokeModifierData *smd= (SmokeModifierData *)smoke_v;
+ SmokeDomainSettings *sds = smd->domain;
+
+ if(sds->wt) {
+ unsigned int res_big_array[3];
+ unsigned int res_big;
+ unsigned int res = sds->res[0]*sds->res[1]*sds->res[2];
+ float *dens, *densold, *tcu, *tcv, *tcw;
+ unsigned int in_len = sizeof(float)*(unsigned int)res;
+ unsigned int in_len_big;
+ unsigned char *out;
+ int mode;
+
+ smoke_turbulence_get_res(sds->wt, res_big_array);
+ res_big = res_big_array[0]*res_big_array[1]*res_big_array[2];
+ mode = res_big >= 1000000 ? 2 : 1;
+ in_len_big = sizeof(float) * (unsigned int)res_big;
+
+ smoke_turbulence_export(sds->wt, &dens, &densold, &tcu, &tcv, &tcw);
+
+ out = (unsigned char *)MEM_callocN(LZO_OUT_LEN(in_len_big), "pointcache_lzo_buffer");
+ ptcache_compress_write(pf, (unsigned char *)dens, in_len_big, out, mode);
+ ptcache_compress_write(pf, (unsigned char *)densold, in_len_big, out, mode);
+ MEM_freeN(out);
+
+ out = (unsigned char *)MEM_callocN(LZO_OUT_LEN(in_len), "pointcache_lzo_buffer");
+ ptcache_compress_write(pf, (unsigned char *)tcu, in_len, out, mode);
+ ptcache_compress_write(pf, (unsigned char *)tcv, in_len, out, mode);
+ ptcache_compress_write(pf, (unsigned char *)tcw, in_len, out, mode);
+ MEM_freeN(out);
+
+ return 1;
+ }
return 0;
}
// forward decleration
static int ptcache_file_read(PTCacheFile *pf, void *f, size_t tot, int size);
+static int ptcache_compress_read(PTCacheFile *pf, unsigned char *result, unsigned int len)
+{
+ int r = 0;
+ unsigned char compressed = 0;
+ unsigned int in_len;
+ unsigned int out_len = len;
+ unsigned char *in;
+ unsigned char *props = MEM_callocN(16*sizeof(char), "tmp");
+ size_t sizeOfIt = 5;
+
+ ptcache_file_read(pf, &compressed, 1, sizeof(unsigned char));
+ if(compressed) {
+ ptcache_file_read(pf, &in_len, 1, sizeof(unsigned int));
+ in = (unsigned char *)MEM_callocN(sizeof(unsigned char)*in_len, "pointcache_compressed_buffer");
+ ptcache_file_read(pf, in, in_len, sizeof(unsigned char));
+
+ if(compressed == 1)
+ r = lzo1x_decompress(in, (lzo_uint)in_len, result, (lzo_uint *)&out_len, NULL);
+ else if(compressed == 2)
+ {
+ size_t leni = in_len, leno = out_len;
+ ptcache_file_read(pf, &sizeOfIt, 1, sizeof(unsigned int));
+ ptcache_file_read(pf, props, sizeOfIt, sizeof(unsigned char));
+ r = LzmaUncompress(result, &leno, in, &leni, props, sizeOfIt);
+ }
+
+ MEM_freeN(in);
+ }
+ else {
+ ptcache_file_read(pf, result, len, sizeof(unsigned char));
+ }
+
+ MEM_freeN(props);
+
+ return r;
+}
+
static void ptcache_read_smoke(PTCacheFile *pf, void *smoke_v)
{
SmokeModifierData *smd= (SmokeModifierData *)smoke_v;
SmokeDomainSettings *sds = smd->domain;
- if(sds->fluid)
- {
+ if(sds->fluid) {
size_t res = sds->res[0]*sds->res[1]*sds->res[2];
- float *dens, *densold, *heat, *heatold, *vx, *vy, *vz;
-
- smoke_export(sds->fluid, &dens, &densold, &heat, &heatold, &vx, &vy, &vz);
-
- ptcache_file_read(pf, dens, res, sizeof(float));
- ptcache_file_read(pf, densold, res, sizeof(float));
- ptcache_file_read(pf, heat, res, sizeof(float));
- ptcache_file_read(pf, heatold, res, sizeof(float));
- ptcache_file_read(pf, vx, res, sizeof(float));
- ptcache_file_read(pf, vy, res, sizeof(float));
- ptcache_file_read(pf, vz, res, sizeof(float));
+ float dt, dx, *dens, *densold, *heat, *heatold, *vx, *vy, *vz, *vxold, *vyold, *vzold;
+ unsigned char *obstacles;
+ unsigned int out_len = (unsigned int)res * sizeof(float);
+ smoke_export(sds->fluid, &dt, &dx, &dens, &densold, &heat, &heatold, &vx, &vy, &vz, &vxold, &vyold, &vzold, &obstacles);
+
+ ptcache_compress_read(pf, (unsigned char *)sds->shadow, out_len);
+ ptcache_compress_read(pf, (unsigned char*)dens, out_len);
+ ptcache_compress_read(pf, (unsigned char*)densold, out_len);
+ ptcache_compress_read(pf, (unsigned char*)heat, out_len);
+ ptcache_compress_read(pf, (unsigned char*)heatold, out_len);
+ ptcache_compress_read(pf, (unsigned char*)vx, out_len);
+ ptcache_compress_read(pf, (unsigned char*)vy, out_len);
+ ptcache_compress_read(pf, (unsigned char*)vz, out_len);
+ ptcache_compress_read(pf, (unsigned char*)vxold, out_len);
+ ptcache_compress_read(pf, (unsigned char*)vyold, out_len);
+ ptcache_compress_read(pf, (unsigned char*)vzold, out_len);
+ ptcache_compress_read(pf, (unsigned char*)obstacles, (unsigned int)res);
+ ptcache_file_read(pf, &dt, 1, sizeof(float));
+ ptcache_file_read(pf, &dx, 1, sizeof(float));
}
}
-void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd, int num)
+
+static void ptcache_read_smoke_turbulence(PTCacheFile *pf, void *smoke_v)
+{
+ SmokeModifierData *smd= (SmokeModifierData *)smoke_v;
+ SmokeDomainSettings *sds = smd->domain;
+
+ if(sds->fluid) {
+ unsigned int res = sds->res[0]*sds->res[1]*sds->res[2];
+ unsigned int res_big, res_big_array[3];
+ float *dens, *densold, *tcu, *tcv, *tcw;
+ unsigned int out_len = sizeof(float)*(unsigned int)res;
+ unsigned int out_len_big;
+
+ smoke_turbulence_get_res(sds->wt, res_big_array);
+ res_big = res_big_array[0]*res_big_array[1]*res_big_array[2];
+ out_len_big = sizeof(float) * (unsigned int)res_big;
+
+ smoke_turbulence_export(sds->wt, &dens, &densold, &tcu, &tcv, &tcw);
+
+ ptcache_compress_read(pf, (unsigned char*)dens, out_len_big);
+ ptcache_compress_read(pf, (unsigned char*)densold, out_len_big);
+
+ ptcache_compress_read(pf, (unsigned char*)tcu, out_len);
+ ptcache_compress_read(pf, (unsigned char*)tcv, out_len);
+ ptcache_compress_read(pf, (unsigned char*)tcw, out_len);
+ }
+}
+
+void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd)
{
SmokeDomainSettings *sds = smd->domain;
@@ -547,24 +708,54 @@ void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeMo
pid->ob= ob;
pid->calldata= smd;
- // if(num == 0)
- pid->type= PTCACHE_TYPE_SMOKE_DOMAIN_LOW;
- // else if(num == 1)
- // pid->type= PTCACHE_TYPE_SMOKE_DOMAIN_HIGH;
-
- pid->stack_index= modifiers_indexInObject(ob, (ModifierData *)smd);
+ pid->type= PTCACHE_TYPE_SMOKE_DOMAIN;
+ pid->stack_index= sds->point_cache[0]->index;
- pid->cache= sds->point_cache;
- pid->cache_ptr= &sds->point_cache;
- pid->ptcaches= &sds->ptcaches;
+ pid->cache= sds->point_cache[0];
+ pid->cache_ptr= &(sds->point_cache[0]);
+ pid->ptcaches= &(sds->ptcaches[0]);
-
pid->totpoint= pid->totwrite= ptcache_totpoint_smoke;
pid->write_elem= NULL;
pid->read_elem= NULL;
+
pid->read_stream = ptcache_read_smoke;
pid->write_stream = ptcache_write_smoke;
+
+ pid->interpolate_elem= NULL;
+
+ pid->write_header= ptcache_write_basic_header;
+ pid->read_header= ptcache_read_basic_header;
+
+ pid->data_types= (1<<BPHYS_DATA_LOCATION); // bogus values to make pointcache happy
+ pid->info_types= 0;
+}
+
+void BKE_ptcache_id_from_smoke_turbulence(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd)
+{
+ SmokeDomainSettings *sds = smd->domain;
+
+ memset(pid, 0, sizeof(PTCacheID));
+
+ pid->ob= ob;
+ pid->calldata= smd;
+
+ pid->type= PTCACHE_TYPE_SMOKE_HIGHRES;
+ pid->stack_index= sds->point_cache[1]->index;
+
+ pid->cache= sds->point_cache[1];
+ pid->cache_ptr= &sds->point_cache[1];
+ pid->ptcaches= &sds->ptcaches[1];
+
+ pid->totpoint= pid->totwrite= ptcache_totpoint_smoke_turbulence;
+
+ pid->write_elem= NULL;
+ pid->read_elem= NULL;
+
+ pid->read_stream = ptcache_read_smoke_turbulence;
+ pid->write_stream = ptcache_write_smoke_turbulence;
+
pid->interpolate_elem= NULL;
pid->write_header= ptcache_write_basic_header;
@@ -573,7 +764,6 @@ void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeMo
pid->data_types= (1<<BPHYS_DATA_LOCATION); // bogus values tot make pointcache happy
pid->info_types= 0;
}
-#endif // XXX smoke poitcache stuff breaks compiling
void BKE_ptcache_id_from_cloth(PTCacheID *pid, Object *ob, ClothModifierData *clmd)
{
@@ -582,7 +772,7 @@ void BKE_ptcache_id_from_cloth(PTCacheID *pid, Object *ob, ClothModifierData *cl
pid->ob= ob;
pid->calldata= clmd;
pid->type= PTCACHE_TYPE_CLOTH;
- pid->stack_index= modifiers_indexInObject(ob, (ModifierData *)clmd);
+ pid->stack_index= clmd->point_cache->index;
pid->cache= clmd->point_cache;
pid->cache_ptr= &clmd->point_cache;
pid->ptcaches= &clmd->ptcaches;
@@ -616,13 +806,9 @@ void BKE_ptcache_ids_from_object(ListBase *lb, Object *ob)
}
for(psys=ob->particlesystem.first; psys; psys=psys->next) {
- pid= MEM_callocN(sizeof(PTCacheID), "PTCacheID");
- BKE_ptcache_id_from_particles(pid, ob, psys);
- BLI_addtail(lb, pid);
-
- if(psys->soft) {
+ if(psys->part) {
pid= MEM_callocN(sizeof(PTCacheID), "PTCacheID");
- BKE_ptcache_id_from_softbody(pid, ob, psys->soft);
+ BKE_ptcache_id_from_particles(pid, ob, psys);
BLI_addtail(lb, pid);
}
}
@@ -633,18 +819,19 @@ void BKE_ptcache_ids_from_object(ListBase *lb, Object *ob)
BKE_ptcache_id_from_cloth(pid, ob, (ClothModifierData*)md);
BLI_addtail(lb, pid);
}
- /*
- // enabled on next commit
if(md->type == eModifierType_Smoke) {
SmokeModifierData *smd = (SmokeModifierData *)md;
if(smd->type & MOD_SMOKE_TYPE_DOMAIN)
{
pid= MEM_callocN(sizeof(PTCacheID), "PTCacheID");
- BKE_ptcache_id_from_smoke(pid, ob, (SmokeModifierData*)md, 0);
+ BKE_ptcache_id_from_smoke(pid, ob, (SmokeModifierData*)md);
+ BLI_addtail(lb, pid);
+
+ pid= MEM_callocN(sizeof(PTCacheID), "PTCacheID");
+ BKE_ptcache_id_from_smoke_turbulence(pid, ob, (SmokeModifierData*)md);
BLI_addtail(lb, pid);
}
}
- */
}
}
@@ -728,6 +915,10 @@ static int BKE_ptcache_id_filename(PTCacheID *pid, char *filename, int cfra, sho
}
if (do_ext) {
+
+ if(pid->cache->index < 0)
+ pid->cache->index = pid->stack_index = object_insert_ptcache(pid->ob);
+
if(pid->cache->flag & PTCACHE_EXTERNAL) {
if(pid->cache->index >= 0)
snprintf(newname, MAX_PTCACHE_FILE, "_%06d_%02d"PTCACHE_EXT, cfra, pid->stack_index); /* always 6 chars */
@@ -902,7 +1093,7 @@ static void ptcache_file_init_pointers(PTCacheFile *pf)
pf->cur[BPHYS_DATA_BOIDS] = data_types & (1<<BPHYS_DATA_BOIDS) ? &pf->data.boids : NULL;
}
-static void ptcache_mem_init_pointers(PTCacheMem *pm)
+void BKE_ptcache_mem_init_pointers(PTCacheMem *pm)
{
int data_types = pm->data_types;
int i;
@@ -911,7 +1102,7 @@ static void ptcache_mem_init_pointers(PTCacheMem *pm)
pm->cur[i] = data_types & (1<<i) ? pm->data[i] : NULL;
}
-static void ptcache_mem_incr_pointers(PTCacheMem *pm)
+void BKE_ptcache_mem_incr_pointers(PTCacheMem *pm)
{
int i;
@@ -977,7 +1168,7 @@ int BKE_ptcache_read_cache(PTCacheID *pid, float cfra, float frs_sec)
int cfra1 = 0, cfra2 = 0;
int totpoint = 0, totpoint2 = 0;
int *index = &i, *index2 = &i;
- int use_old = 0, old_frame;
+ int use_old = 0, old_frame = 0;
int ret = 0, error = 0;
@@ -1064,12 +1255,12 @@ int BKE_ptcache_read_cache(PTCacheID *pid, float cfra, float frs_sec)
return 0;
if(pm) {
- ptcache_mem_init_pointers(pm);
+ BKE_ptcache_mem_init_pointers(pm);
totpoint = pm->totpoint;
index = pm->data_types & (1<<BPHYS_DATA_INDEX) ? pm->cur[BPHYS_DATA_INDEX] : &i;
}
if(pm2) {
- ptcache_mem_init_pointers(pm2);
+ BKE_ptcache_mem_init_pointers(pm2);
totpoint2 = pm2->totpoint;
index2 = pm2->data_types & (1<<BPHYS_DATA_INDEX) ? pm2->cur[BPHYS_DATA_INDEX] : &i;
}
@@ -1140,18 +1331,18 @@ int BKE_ptcache_read_cache(PTCacheID *pid, float cfra, float frs_sec)
if(use_old) {
if(pid->read_elem && ptcache_file_read(pf, (void*)old_data1, 1, old_elemsize))
pid->read_elem(i, pid->calldata, NULL, frs_sec, cfra, old_data1);
- else
+ else if(pid->read_elem)
{ error = 1; break; }
}
else {
if(pid->read_elem && (pm || ptcache_file_read_data(pf)))
pid->read_elem(*index, pid->calldata, pm ? pm->cur : pf->cur, frs_sec, cfra1 ? (float)cfra1 : (float)cfrai, NULL);
- else
+ else if(pid->read_elem)
{ error = 1; break; }
}
if(pm) {
- ptcache_mem_incr_pointers(pm);
+ BKE_ptcache_mem_incr_pointers(pm);
index = pm->data_types & (1<<BPHYS_DATA_INDEX) ? pm->cur[BPHYS_DATA_INDEX] : &i;
}
}
@@ -1185,7 +1376,7 @@ int BKE_ptcache_read_cache(PTCacheID *pid, float cfra, float frs_sec)
else
{ error = 1; break; }
}
- else
+ else if(pid->read_elem)
{ error = 1; break; }
}
else {
@@ -1197,12 +1388,12 @@ int BKE_ptcache_read_cache(PTCacheID *pid, float cfra, float frs_sec)
else
{ error = 1; break; }
}
- else
+ else if(pid->read_elem)
{ error = 1; break; }
}
if(pm2) {
- ptcache_mem_incr_pointers(pm2);
+ BKE_ptcache_mem_incr_pointers(pm2);
index2 = pm2->data_types & (1<<BPHYS_DATA_INDEX) ? pm2->cur[BPHYS_DATA_INDEX] : &i;
}
}
@@ -1374,11 +1565,11 @@ int BKE_ptcache_write_cache(PTCacheID *pid, int cfra)
pm->data_types = cfra ? pid->data_types : pid->info_types;
ptcache_alloc_data(pm);
- ptcache_mem_init_pointers(pm);
+ BKE_ptcache_mem_init_pointers(pm);
for(i=0; i<totpoint; i++) {
if(pid->write_elem && pid->write_elem(i, pid->calldata, pm->cur))
- ptcache_mem_incr_pointers(pm);
+ BKE_ptcache_mem_incr_pointers(pm);
}
//ptcache_make_index_array(pm, pid->totpoint(pid->calldata));
@@ -1479,6 +1670,8 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, int cfra)
PTCacheMem *pm= pid->cache->mem_cache.first;
PTCacheMem *link= NULL;
+ pm= pid->cache->mem_cache.first;
+
if(mode == PTCACHE_CLEAR_ALL) {
pid->cache->last_exact = 0;
for(; pm; pm=pm->next)
@@ -1623,9 +1816,10 @@ int BKE_ptcache_id_reset(Scene *scene, PTCacheID *pid, int mode)
else if(mode == PTCACHE_RESET_OUTDATED) {
reset = 1;
- if(cache->flag & PTCACHE_OUTDATED)
- if(!(cache->flag & PTCACHE_BAKED))
- clear= 1;
+ if(cache->flag & PTCACHE_OUTDATED && !(cache->flag & PTCACHE_BAKED)) {
+ clear= 1;
+ cache->flag &= ~PTCACHE_OUTDATED;
+ }
}
if(reset) {
@@ -1639,8 +1833,10 @@ int BKE_ptcache_id_reset(Scene *scene, PTCacheID *pid, int mode)
sbFreeSimulation(pid->calldata);
else if(pid->type == PTCACHE_TYPE_PARTICLES)
psys_reset(pid->calldata, PSYS_RESET_DEPSGRAPH);
- else if(pid->type == PTCACHE_TYPE_SMOKE_DOMAIN_LOW)
+ else if(pid->type == PTCACHE_TYPE_SMOKE_DOMAIN)
smokeModifier_reset(pid->calldata);
+ else if(pid->type == PTCACHE_TYPE_SMOKE_HIGHRES)
+ smokeModifier_reset_turbulence(pid->calldata);
}
if(clear)
BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_ALL, 0);
@@ -1666,10 +1862,10 @@ int BKE_ptcache_object_reset(Scene *scene, Object *ob, int mode)
}
for(psys=ob->particlesystem.first; psys; psys=psys->next) {
- /* Baked softbody hair has to be checked first, because we don't want to reset */
- /* particles or softbody in that case -jahka */
- if(psys->soft) {
- BKE_ptcache_id_from_softbody(&pid, ob, psys->soft);
+ /* Baked cloth hair has to be checked first, because we don't want to reset */
+ /* particles or cloth in that case -jahka */
+ if(psys->clmd) {
+ BKE_ptcache_id_from_cloth(&pid, ob, psys->clmd);
if(mode == PSYS_RESET_ALL || !(psys->part->type == PART_HAIR && (pid.cache->flag & PTCACHE_BAKED)))
reset |= BKE_ptcache_id_reset(scene, &pid, mode);
else
@@ -1678,7 +1874,7 @@ int BKE_ptcache_object_reset(Scene *scene, Object *ob, int mode)
else if(psys->recalc & PSYS_RECALC_REDO || psys->recalc & PSYS_RECALC_CHILD)
skip = 1;
- if(skip == 0) {
+ if(skip == 0 && psys->part) {
BKE_ptcache_id_from_particles(&pid, ob, psys);
reset |= BKE_ptcache_id_reset(scene, &pid, mode);
}
@@ -1689,17 +1885,17 @@ int BKE_ptcache_object_reset(Scene *scene, Object *ob, int mode)
BKE_ptcache_id_from_cloth(&pid, ob, (ClothModifierData*)md);
reset |= BKE_ptcache_id_reset(scene, &pid, mode);
}
- /*
- // enabled on next commit
if(md->type == eModifierType_Smoke) {
SmokeModifierData *smd = (SmokeModifierData *)md;
if(smd->type & MOD_SMOKE_TYPE_DOMAIN)
{
- BKE_ptcache_id_from_smoke(&pid, ob, (SmokeModifierData*)md, 0);
+ BKE_ptcache_id_from_smoke(&pid, ob, (SmokeModifierData*)md);
+ reset |= BKE_ptcache_id_reset(scene, &pid, mode);
+
+ BKE_ptcache_id_from_smoke_turbulence(&pid, ob, (SmokeModifierData*)md);
reset |= BKE_ptcache_id_reset(scene, &pid, mode);
}
}
- */
}
return reset;
@@ -1759,7 +1955,7 @@ void BKE_ptcache_set_continue_physics(Scene *scene, int enable)
if(CONTINUE_PHYSICS == 0) {
for(ob=G.main->object.first; ob; ob=ob->id.next)
if(BKE_ptcache_object_reset(scene, ob, PTCACHE_RESET_OUTDATED))
- DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+ DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
}
}
}
@@ -1779,15 +1975,16 @@ PointCache *BKE_ptcache_add(ListBase *ptcaches)
cache->startframe= 1;
cache->endframe= 250;
cache->step= 10;
+ cache->index = -1;
BLI_addtail(ptcaches, cache);
return cache;
}
-void BKE_ptache_free_mem(PointCache *cache)
+void BKE_ptcache_free_mem(ListBase *mem_cache)
{
- PTCacheMem *pm = cache->mem_cache.first;
+ PTCacheMem *pm = mem_cache->first;
if(pm) {
for(; pm; pm=pm->next) {
@@ -1796,22 +1993,25 @@ void BKE_ptache_free_mem(PointCache *cache)
MEM_freeN(pm->index_array);
}
- BLI_freelistN(&cache->mem_cache);
+ BLI_freelistN(mem_cache);
}
}
void BKE_ptcache_free(PointCache *cache)
{
- BKE_ptache_free_mem(cache);
+ BKE_ptcache_free_mem(&cache->mem_cache);
+ if(cache->edit && cache->free_edit)
+ cache->free_edit(cache->edit);
MEM_freeN(cache);
}
void BKE_ptcache_free_list(ListBase *ptcaches)
{
PointCache *cache = ptcaches->first;
- for(; cache; cache=cache->next)
- BKE_ptache_free_mem(cache);
-
- BLI_freelistN(ptcaches);
+ while(cache) {
+ BLI_remlink(ptcaches, cache);
+ BKE_ptcache_free(cache);
+ cache = ptcaches->first;
+ }
}
static PointCache *ptcache_copy(PointCache *cache)
@@ -1901,7 +2101,7 @@ void BKE_ptcache_make_cache(PTCacheBaker* baker)
Base *base;
ListBase pidlist;
PTCacheID *pid = baker->pid;
- PointCache *cache;
+ PointCache *cache = NULL;
float frameleno = scene->r.framelen;
int cfrao = CFRA;
int startframe = MAXFRAME;
@@ -2075,7 +2275,7 @@ void BKE_ptcache_disk_to_mem(PTCacheID *pid)
pm->frame = cfra;
ptcache_alloc_data(pm);
- ptcache_mem_init_pointers(pm);
+ BKE_ptcache_mem_init_pointers(pm);
ptcache_file_init_pointers(pf);
for(i=0; i<pm->totpoint; i++) {
@@ -2091,7 +2291,7 @@ void BKE_ptcache_disk_to_mem(PTCacheID *pid)
return;
}
ptcache_copy_data(pf->cur, pm->cur);
- ptcache_mem_incr_pointers(pm);
+ BKE_ptcache_mem_incr_pointers(pm);
}
//ptcache_make_index_array(pm, pid->totpoint(pid->calldata));
@@ -2122,7 +2322,7 @@ void BKE_ptcache_mem_to_disk(PTCacheID *pid)
pf->totpoint = pm->totpoint;
pf->type = pid->type;
- ptcache_mem_init_pointers(pm);
+ BKE_ptcache_mem_init_pointers(pm);
ptcache_file_init_pointers(pf);
if(!ptcache_file_write_header_begin(pf) || !pid->write_header(pf)) {
@@ -2142,7 +2342,7 @@ void BKE_ptcache_mem_to_disk(PTCacheID *pid)
ptcache_file_close(pf);
return;
}
- ptcache_mem_incr_pointers(pm);
+ BKE_ptcache_mem_incr_pointers(pm);
}
ptcache_file_close(pf);
diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c
index 139895bbdaf..de2118af202 100644
--- a/source/blender/blenkernel/intern/sca.c
+++ b/source/blender/blenkernel/intern/sca.c
@@ -52,30 +52,6 @@
#include "BKE_blender.h"
#include "BKE_sca.h"
-//#include "wm_event_types.h"
-
-void free_text_controllers(Text *txt)
-{
- Object *ob;
- bController *cont;
-
- ob= G.main->object.first;
- while(ob) {
- cont= ob->controllers.first;
- while(cont) {
- if(cont->type==CONT_PYTHON) {
- bPythonCont *pc;
-
- pc= cont->data;
- if(pc->text==txt) pc->text= NULL;
- }
- cont= cont->next;
- }
- ob= ob->id.next;
- }
-}
-
-
/* ******************* SENSORS ************************ */
void free_sensor(bSensor *sens)
@@ -418,12 +394,10 @@ void init_actuator(bActuator *act)
act->data= 0;
switch(act->type) {
-#ifdef __NLA
case ACT_ACTION:
case ACT_SHAPEACTION:
act->data= MEM_callocN(sizeof(bActionActuator), "actionact");
break;
-#endif
case ACT_SOUND:
sa = act->data= MEM_callocN(sizeof(bSoundActuator), "soundact");
sa->volume = 1.0f;
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 8488d7ab247..6f9ed3e0978 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -155,6 +155,7 @@ Scene *copy_scene(Main *bmain, Scene *sce, int type)
scen->theDag= NULL;
scen->obedit= NULL;
scen->toolsettings= MEM_dupallocN(sce->toolsettings);
+ scen->stats= NULL;
ts= scen->toolsettings;
if(ts) {
@@ -244,6 +245,11 @@ void free_scene(Scene *sce)
base= base->next;
}
/* do not free objects! */
+
+ if(sce->gpd) {
+ sce->gpd->id.us--;
+ sce->gpd= NULL;
+ }
BLI_freelistN(&sce->base);
seq_free_editing(sce);
@@ -299,6 +305,9 @@ void free_scene(Scene *sce)
ntreeFreeTree(sce->nodetree);
MEM_freeN(sce->nodetree);
}
+
+ if(sce->stats)
+ MEM_freeN(sce->stats);
}
Scene *add_scene(char *name)
@@ -395,11 +404,13 @@ Scene *add_scene(char *name)
sce->unit.scale_length = 1.0f;
pset= &sce->toolsettings->particle;
- pset->flag= PE_KEEP_LENGTHS|PE_LOCK_FIRST|PE_DEFLECT_EMITTER;
+ pset->flag= PE_KEEP_LENGTHS|PE_LOCK_FIRST|PE_DEFLECT_EMITTER|PE_AUTO_VELOCITY;
pset->emitterdist= 0.25f;
pset->totrekey= 5;
pset->totaddkey= 5;
pset->brushtype= PE_BRUSH_NONE;
+ pset->draw_step= 2;
+ pset->fade_frames= 2;
for(a=0; a<PE_TOT_BRUSH; a++) {
pset->brush[a].strength= 50;
pset->brush[a].size= 50;
@@ -442,6 +453,9 @@ Scene *add_scene(char *name)
sce->gm.physubstep = 1;
sce->gm.maxphystep = 5;
+ sce->gm.flag = GAME_DISPLAY_LISTS;
+ sce->gm.matmode = GAME_MAT_MULTITEX;
+
return sce;
}
@@ -846,14 +860,3 @@ float get_render_aosss_error(RenderData *r, float error)
return error;
}
-void free_dome_warp_text(struct Text *txt)
-{
- Scene *scene;
-
- scene = G.main->scene.first;
- while(scene) {
- if (scene->r.dometext == txt)
- scene->r.dometext = NULL;
- scene = scene->id.next;
- }
-}
diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c
index 2ee95ed928e..078258092f7 100644
--- a/source/blender/blenkernel/intern/seqeffects.c
+++ b/source/blender/blenkernel/intern/seqeffects.c
@@ -2792,6 +2792,10 @@ void sequence_effect_speed_rebuild_map(Sequence * seq, int force)
if (!(force || seq->len != v->length || !v->frameMap)) {
return;
}
+ if (!seq->seq1) { /* make coverity happy and check for (CID 598)
+ input strip ... */
+ return;
+ }
if (!v->frameMap || v->length != seq->len) {
if (v->frameMap) MEM_freeN(v->frameMap);
@@ -2807,7 +2811,7 @@ void sequence_effect_speed_rebuild_map(Sequence * seq, int force)
/* if there is no IPO, try to make retiming easy by stretching the
strip */
// XXX old animation system - seq
- if (/*!seq->ipo &&*/ seq->seq1 && seq->seq1->enddisp != seq->seq1->start
+ if (/*!seq->ipo &&*/ seq->seq1->enddisp != seq->seq1->start
&& seq->seq1->len != 0) {
fallback_fac = (float) seq->seq1->len /
(float) (seq->seq1->enddisp - seq->seq1->start);
diff --git a/source/blender/blenkernel/intern/sequence.c b/source/blender/blenkernel/intern/sequence.c
index 159a60ad3af..c6b714c3125 100644
--- a/source/blender/blenkernel/intern/sequence.c
+++ b/source/blender/blenkernel/intern/sequence.c
@@ -570,7 +570,7 @@ void reload_sequence_new_file(Scene *scene, Sequence * seq)
}
seq->strip->len = seq->len;
} else if (seq->type == SEQ_SOUND) {
- seq->len = AUD_getInfo(seq->sound->snd_sound).length * FPS;
+ seq->len = AUD_getInfo(seq->sound->handle).length * FPS;
seq->len -= seq->anim_startofs;
seq->len -= seq->anim_endofs;
if (seq->len < 0) {
diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c
index 27357d92aae..efb7db04029 100644
--- a/source/blender/blenkernel/intern/shrinkwrap.c
+++ b/source/blender/blenkernel/intern/shrinkwrap.c
@@ -574,7 +574,7 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Scene *scene, Object
}
}
- //Just to make sure we are not letting any memory behind
+ //Just to make sure we are not leaving any memory behind
assert(ssmd.emCache == NULL);
assert(ssmd.mCache == NULL);
}
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index 22ea41276ff..67744ab56a2 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -38,6 +38,7 @@
#include <float.h>
#include <math.h>
#include "stdio.h"
+#include "string.h" /* memset */
#include "BLI_linklist.h"
#include "BLI_rand.h"
@@ -54,10 +55,13 @@
#include "BKE_DerivedMesh.h"
#include "BKE_modifier.h"
#include "BKE_particle.h"
+#include "BKE_pointcache.h"
+#include "BKE_smoke.h"
#include "BKE_utildefines.h"
#include "DNA_customdata_types.h"
#include "DNA_group_types.h"
+#include "DNA_lamp_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_modifier_types.h"
@@ -120,8 +124,7 @@ struct DerivedMesh;
struct SmokeModifierData;
// forward declerations
-static void get_cell(struct SmokeModifierData *smd, float *pos, int *cell, int correct);
-static void get_bigcell(struct SmokeModifierData *smd, float *pos, int *cell, int correct);
+static void get_cell(float *p0, int res[3], float dx, float *pos, int *cell, int correct);
void calcTriangleDivs(Object *ob, MVert *verts, int numverts, MFace *tris, int numfaces, int numtris, int **tridivs, float cell_len);
#define TRI_UVOFFSET (1./4.)
@@ -163,6 +166,13 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive
// calc other res with max_res provided
VECSUB(size, max, min);
+
+ printf("size: %f, %f, %f\n", size[0], size[1], size[2]);
+
+ // prevent crash when initializing a plane as domain
+ if((size[0] < FLT_EPSILON) || (size[1] < FLT_EPSILON) || (size[2] < FLT_EPSILON))
+ return 0;
+
if(size[0] > size[1])
{
if(size[0] > size[1])
@@ -202,21 +212,36 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive
}
}
+ printf("smd->domain->dx: %f\n", smd->domain->dx);
+
// TODO: put in failsafe if res<=0 - dg
// 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->wt = smoke_turbulence_init(smd->domain->res, (smd->domain->flags & MOD_SMOKE_HIGHRES) ? (smd->domain->amplify + 1) : 0, smd->domain->noise);
smd->time = scene->r.cfra;
- smd->domain->firstframe = smd->time;
-
+
+ if(smd->domain->flags & MOD_SMOKE_HIGHRES)
+ {
+ smd->domain->wt = smoke_turbulence_init(smd->domain->res, smd->domain->amplify + 1, smd->domain->noise);
+ smd->domain->res_wt[0] = smd->domain->res[0] * (smd->domain->amplify + 1);
+ smd->domain->res_wt[1] = smd->domain->res[1] * (smd->domain->amplify + 1);
+ smd->domain->res_wt[2] = smd->domain->res[2] * (smd->domain->amplify + 1);
+ smd->domain->dx_wt = smd->domain->dx / (smd->domain->amplify + 1);
+ printf("smd->domain->amplify: %d\n", smd->domain->amplify);
+ printf("(smd->domain->flags & MOD_SMOKE_HIGHRES)\n");
+ }
+
+ 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));
- if(smd->domain->wt)
+ if(smd->domain->wt)
+ {
smoke_initWaveletBlenderRNA(smd->domain->wt, &(smd->domain->strength));
-
+ printf("smoke_initWaveletBlenderRNA\n");
+ }
return 1;
}
else if((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow)
@@ -256,12 +281,11 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive
SmokeCollSettings *scs = smd->coll;
MVert *mvert = dm->getVertArray(dm);
MFace *mface = dm->getFaceArray(dm);
- size_t i = 0, divs = 0;
+ int i = 0, divs = 0;
int *tridivs = NULL;
float cell_len = 1.0 / 50.0; // for res = 50
- size_t newdivs = 0;
- //size_t max_points = 0;
- size_t quads = 0, facecounter = 0;
+ int newdivs = 0;
+ int quads = 0, facecounter = 0;
// copy obmat
Mat4CpyMat4(scs->mat, ob->obmat);
@@ -299,7 +323,7 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive
int again = 0;
do
{
- size_t j, k;
+ int j, k;
int divs1 = tridivs[3 * facecounter + 0];
int divs2 = tridivs[3 * facecounter + 1];
//int divs3 = tridivs[3 * facecounter + 2];
@@ -396,10 +420,10 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive
{
smd->coll->bvhtree = NULL; // bvhtree_build_from_smoke ( ob->obmat, dm->getFaceArray(dm), dm->getNumFaces(dm), dm->getVertArray(dm), dm->getNumVerts(dm), 0.0 );
}
-
+ return 1;
}
- return 0;
+ return 1;
}
/*! init triangle divisions */
@@ -506,22 +530,9 @@ void smokeModifier_freeDomain(SmokeModifierData *smd)
{
if(smd->domain)
{
- // free visualisation buffers
- if(smd->domain->bind)
- {
- glDeleteTextures(smd->domain->max_textures, (GLuint *)smd->domain->bind);
- MEM_freeN(smd->domain->bind);
- }
- smd->domain->max_textures = 0; // unnecessary but let's be sure
-
- if(smd->domain->tray)
- MEM_freeN(smd->domain->tray);
- if(smd->domain->tvox)
- MEM_freeN(smd->domain->tvox);
- if(smd->domain->traybig)
- MEM_freeN(smd->domain->traybig);
- if(smd->domain->tvoxbig)
- MEM_freeN(smd->domain->tvoxbig);
+ if(smd->domain->shadow)
+ MEM_freeN(smd->domain->shadow);
+ smd->domain->shadow = NULL;
if(smd->domain->fluid)
smoke_free(smd->domain->fluid);
@@ -529,6 +540,11 @@ void smokeModifier_freeDomain(SmokeModifierData *smd)
if(smd->domain->wt)
smoke_turbulence_free(smd->domain->wt);
+ BKE_ptcache_free_list(&(smd->domain->ptcaches[0]));
+ smd->domain->point_cache[0] = NULL;
+ BKE_ptcache_free_list(&(smd->domain->ptcaches[1]));
+ smd->domain->point_cache[1] = NULL;
+
MEM_freeN(smd->domain);
smd->domain = NULL;
}
@@ -576,50 +592,39 @@ void smokeModifier_freeCollision(SmokeModifierData *smd)
}
}
+void smokeModifier_reset_turbulence(struct SmokeModifierData *smd)
+{
+ if(smd && smd->domain && smd->domain->wt)
+ {
+ smoke_turbulence_free(smd->domain->wt);
+ smd->domain->wt = NULL;
+ }
+}
+
void smokeModifier_reset(struct SmokeModifierData *smd)
{
if(smd)
{
if(smd->domain)
{
- // free visualisation buffers
- if(smd->domain->bind)
- {
- glDeleteTextures(smd->domain->max_textures, (GLuint *)smd->domain->bind);
- MEM_freeN(smd->domain->bind);
- smd->domain->bind = NULL;
- }
- smd->domain->max_textures = 0;
- if(smd->domain->viewsettings < MOD_SMOKE_VIEW_USEBIG)
- smd->domain->viewsettings = 0;
- else
- smd->domain->viewsettings = MOD_SMOKE_VIEW_USEBIG;
-
- if(smd->domain->tray)
- MEM_freeN(smd->domain->tray);
- if(smd->domain->tvox)
- MEM_freeN(smd->domain->tvox);
- if(smd->domain->traybig)
- MEM_freeN(smd->domain->traybig);
- if(smd->domain->tvoxbig)
- MEM_freeN(smd->domain->tvoxbig);
-
- smd->domain->tvox = NULL;
- smd->domain->tray = NULL;
- smd->domain->tvoxbig = NULL;
- smd->domain->traybig = NULL;
+ if(smd->domain->shadow)
+ MEM_freeN(smd->domain->shadow);
+ smd->domain->shadow = NULL;
if(smd->domain->fluid)
{
smoke_free(smd->domain->fluid);
smd->domain->fluid = NULL;
}
-
- if(smd->domain->wt)
- {
- smoke_turbulence_free(smd->domain->wt);
- smd->domain->wt = NULL;
- }
+
+ smd->domain->point_cache[0]->flag |= PTCACHE_OUTDATED;
+ smd->domain->point_cache[1]->flag |= PTCACHE_OUTDATED;
+
+ smokeModifier_reset_turbulence(smd);
+
+ smd->time = -1;
+
+ printf("reset domain end\n");
}
else if(smd->flow)
{
@@ -677,31 +682,31 @@ void smokeModifier_createType(struct SmokeModifierData *smd)
smd->domain->smd = smd;
+ smd->domain->point_cache[0] = BKE_ptcache_add(&(smd->domain->ptcaches[0]));
+ smd->domain->point_cache[0]->flag |= PTCACHE_DISK_CACHE;
+ smd->domain->point_cache[0]->step = 1;
+
+ smd->domain->point_cache[1] = BKE_ptcache_add(&(smd->domain->ptcaches[1]));
+ smd->domain->point_cache[1]->flag |= PTCACHE_DISK_CACHE;
+ smd->domain->point_cache[1]->step = 1;
+
/* set some standard values */
smd->domain->fluid = NULL;
- smd->domain->wt = NULL;
+ smd->domain->wt = NULL;
smd->domain->eff_group = NULL;
smd->domain->fluid_group = NULL;
smd->domain->coll_group = NULL;
smd->domain->maxres = 32;
- smd->domain->amplify = 1;
- smd->domain->omega = 1.0;
+ smd->domain->amplify = 1;
+ smd->domain->omega = 1.0;
smd->domain->alpha = -0.001;
smd->domain->beta = 0.1;
smd->domain->flags = MOD_SMOKE_DISSOLVE_LOG;
smd->domain->strength = 2.0;
smd->domain->noise = MOD_SMOKE_NOISEWAVE;
- smd->domain->visibility = 1;
smd->domain->diss_speed = 5;
-
// init 3dview buffer
- smd->domain->tvox = NULL;
- smd->domain->tray = NULL;
- smd->domain->tvoxbig = NULL;
- smd->domain->traybig = NULL;
smd->domain->viewsettings = 0;
- smd->domain->bind = NULL;
- smd->domain->max_textures = 0;
}
else if(smd->type & MOD_SMOKE_TYPE_FLOW)
{
@@ -735,16 +740,321 @@ void smokeModifier_createType(struct SmokeModifierData *smd)
}
}
-// forward declaration
-void smoke_calc_transparency(struct SmokeModifierData *smd, float *light, int big);
+// forward decleration
+void smoke_calc_transparency(float *result, float *input, float *p0, float *p1, int res[3], float dx, float *light, bresenham_callback cb, float correct);
+static float calc_voxel_transp(float *result, float *input, int res[3], int *pixel, float *tRay, float correct);
+static int get_lamp(Scene *scene, float *light)
+{
+ Base *base_tmp = NULL;
+ for(base_tmp = scene->base.first; base_tmp; base_tmp= base_tmp->next)
+ {
+ if(base_tmp->object->type == OB_LAMP)
+ {
+ Lamp *la = (Lamp *)base_tmp->object->data;
+
+ if(la->type == LA_LOCAL)
+ {
+ VECCOPY(light, base_tmp->object->obmat[3]);
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
+
+static void smoke_calc_domain(Scene *scene, Object *ob, SmokeModifierData *smd)
+{
+ SmokeDomainSettings *sds = smd->domain;
+ GroupObject *go = NULL;
+ Base *base = NULL;
+
+ // do flows and fluids
+ if(1)
+ {
+ Object *otherobj = NULL;
+ ModifierData *md = NULL;
+ if(sds->fluid_group) // we use groups since we have 2 domains
+ go = sds->fluid_group->gobject.first;
+ else
+ base = scene->base.first;
+ while(base || go)
+ {
+ otherobj = NULL;
+ if(sds->fluid_group)
+ {
+ if(go->ob)
+ otherobj = go->ob;
+ }
+ else
+ otherobj = base->object;
+ if(!otherobj)
+ {
+ if(sds->fluid_group)
+ go = go->next;
+ else
+ base= base->next;
+
+ continue;
+ }
+
+ md = modifiers_findByType(otherobj, eModifierType_Smoke);
+
+ // check for active smoke modifier
+ if(md && md->mode & (eModifierMode_Realtime | eModifierMode_Render))
+ {
+ SmokeModifierData *smd2 = (SmokeModifierData *)md;
+
+ // check for initialized smoke object
+ if((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow)
+ {
+ // we got nice flow object
+ SmokeFlowSettings *sfs = smd2->flow;
+
+ if(sfs->psys && sfs->psys->part && sfs->psys->part->type==PART_EMITTER) // is particle system selected
+ {
+ ParticleSystem *psys = sfs->psys;
+ ParticleSettings *part=psys->part;
+ ParticleData *pa = NULL;
+ int p = 0;
+ float *density = smoke_get_density(sds->fluid);
+ float *bigdensity = smoke_turbulence_get_density(sds->wt);
+ float *heat = smoke_get_heat(sds->fluid);
+ float *velocity_x = smoke_get_velocity_x(sds->fluid);
+ 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];
+
+ // mostly copied from particle code
+ for(p=0, pa=psys->particles; p<psys->totpart; p++, pa++)
+ {
+ int cell[3];
+ size_t i = 0;
+ size_t index = 0;
+ int badcell = 0;
+ if(pa->alive == PARS_KILLED) continue;
+ else if(pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN)==0) continue;
+ else if(pa->alive == PARS_DEAD && (part->flag & PART_DIED)==0) continue;
+ else if(pa->flag & (PARS_UNEXIST+PARS_NO_DISP)) continue;
+ // VECCOPY(pos, pa->state.co);
+ // Mat4MulVecfl (ob->imat, pos);
+ // 1. get corresponding cell
+ get_cell(smd->domain->p0, smd->domain->res, smd->domain->dx, pa->state.co, cell, 0);
+ // check if cell is valid (in the domain boundary)
+ for(i = 0; i < 3; i++)
+ {
+ if((cell[i] > sds->res[i] - 1) || (cell[i] < 0))
+ {
+ badcell = 1;
+ break;
+ }
+ }
+ if(badcell)
+ continue;
+ // 2. set cell values (heat, density and velocity)
+ index = smoke_get_index(cell[0], sds->res[0], cell[1], sds->res[1], cell[2]);
+ if(!(sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW) && !(obstacle[index] & 2)) // this is inflow
+ {
+ // heat[index] += sfs->temp * 0.1;
+ // density[index] += sfs->density * 0.1;
+ heat[index] = sfs->temp;
+ density[index] = sfs->density;
+
+ /*
+ 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)
+ {
+ // 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;
+ }
+ }
+ }
+ else if(sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW) // outflow
+ {
+ heat[index] = 0.f;
+ density[index] = 0.f;
+ velocity_x[index] = 0.f;
+ velocity_y[index] = 0.f;
+ velocity_z[index] = 0.f;
+ // we need different handling for the high-res feature
+ if(bigdensity)
+ {
+ // 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] = 0.f;
+ }
+ }
+ } // particles loop
+ }
+ }
+ else
+ {
+ /*
+ for()
+ {
+ // no psys
+ BVHTreeNearest nearest;
+ nearest.index = -1;
+ nearest.dist = FLT_MAX;
+
+ BLI_bvhtree_find_nearest(sfs->bvh->tree, pco, &nearest, sfs->bvh->nearest_callback, sfs->bvh);
+ }*/
+ }
+ }
+ }
+ if(sds->fluid_group)
+ go = go->next;
+ else
+ base= base->next;
+ }
+ }
+ // do effectors
+ /*
+ if(sds->eff_group)
+ {
+ for(go = sds->eff_group->gobject.first; go; go = go->next)
+ {
+ if(go->ob)
+ {
+ if(ob->pd)
+ {
+
+ }
+ }
+ }
+ }
+ */
+
+ // do collisions
+ if(1)
+ {
+ Object *otherobj = NULL;
+ ModifierData *md = NULL;
+
+ if(sds->coll_group) // we use groups since we have 2 domains
+ go = sds->coll_group->gobject.first;
+ else
+ base = scene->base.first;
+
+ while(base || go)
+ {
+ otherobj = NULL;
+ if(sds->coll_group)
+ {
+ if(go->ob)
+ otherobj = go->ob;
+ }
+ else
+ otherobj = base->object;
+ if(!otherobj)
+ {
+ if(sds->coll_group)
+ go = go->next;
+ else
+ base= base->next;
+ continue;
+ }
+ md = modifiers_findByType(otherobj, eModifierType_Smoke);
+
+ // check for active smoke modifier
+ if(md && md->mode & (eModifierMode_Realtime | eModifierMode_Render))
+ {
+ SmokeModifierData *smd2 = (SmokeModifierData *)md;
+
+ if((smd2->type & MOD_SMOKE_TYPE_COLL) && smd2->coll)
+ {
+ // we got nice collision object
+ SmokeCollSettings *scs = smd2->coll;
+ size_t i, j;
+ unsigned char *obstacles = smoke_get_obstacle(smd->domain->fluid);
+
+ for(i = 0; i < scs->numpoints; i++)
+ {
+ int badcell = 0;
+ size_t index = 0;
+ int cell[3];
+
+ // 1. get corresponding cell
+ get_cell(smd->domain->p0, smd->domain->res, smd->domain->dx, &scs->points[3 * i], cell, 0);
+
+ // check if cell is valid (in the domain boundary)
+ for(j = 0; j < 3; j++)
+ if((cell[j] > sds->res[j] - 1) || (cell[j] < 0))
+ {
+ badcell = 1;
+ break;
+ }
+
+ if(badcell)
+ continue;
+ // 2. set cell values (heat, density and velocity)
+ index = smoke_get_index(cell[0], sds->res[0], cell[1], sds->res[1], cell[2]);
+
+ // printf("cell[0]: %d, cell[1]: %d, cell[2]: %d\n", cell[0], cell[1], cell[2]);
+ // printf("res[0]: %d, res[1]: %d, res[2]: %d, index: %d\n\n", sds->res[0], sds->res[1], sds->res[2], index);
+ obstacles[index] = 1;
+ // for moving gobstacles
+ /*
+ const LbmFloat maxVelVal = 0.1666;
+ const LbmFloat maxusqr = maxVelVal*maxVelVal*3. *1.5;
+
+ LbmVec objvel = vec2L((mMOIVertices[n]-mMOIVerticesOld[n]) /dvec);
+ {
+ const LbmFloat usqr = (objvel[0]*objvel[0]+objvel[1]*objvel[1]+objvel[2]*objvel[2])*1.5;
+ USQRMAXCHECK(usqr, objvel[0],objvel[1],objvel[2], mMaxVlen, mMxvx,mMxvy,mMxvz);
+ if(usqr>maxusqr) {
+ // cutoff at maxVelVal
+ for(int jj=0; jj<3; jj++) {
+ if(objvel[jj]>0.) objvel[jj] = maxVelVal;
+ if(objvel[jj]<0.) objvel[jj] = -maxVelVal;
+ }
+ }
+ }
+ const LbmFloat dp=dot(objvel, vec2L((*pNormals)[n]) );
+ const LbmVec oldov=objvel; // debug
+ objvel = vec2L((*pNormals)[n]) *dp;
+ */
+ }
+ }
+ }
+
+ if(sds->coll_group)
+ go = go->next;
+ else
+ base= base->next;
+ }
+ }
+}
void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedMesh *dm, int useRenderParams, int isFinalCalc)
{
- if(scene->r.cfra >= smd->time)
- smokeModifier_init(smd, ob, scene, dm);
-
if((smd->type & MOD_SMOKE_TYPE_FLOW))
{
+ if(scene->r.cfra >= smd->time)
+ smokeModifier_init(smd, ob, scene, dm);
+
if(scene->r.cfra > smd->time)
{
// XXX TODO
@@ -764,6 +1074,9 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM
}
else if(smd->type & MOD_SMOKE_TYPE_COLL)
{
+ if(scene->r.cfra >= smd->time)
+ smokeModifier_init(smd, ob, scene, dm);
+
if(scene->r.cfra > smd->time)
{
// XXX TODO
@@ -787,458 +1100,119 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM
else if(smd->type & MOD_SMOKE_TYPE_DOMAIN)
{
SmokeDomainSettings *sds = smd->domain;
-
- if(scene->r.cfra > smd->time)
- {
- GroupObject *go = NULL;
- Base *base = NULL;
-
- tstart();
-
- if(sds->flags & MOD_SMOKE_DISSOLVE)
- {
- smoke_dissolve(sds->fluid, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG);
-
- if(sds->wt)
- smoke_dissolve_wavelet(sds->wt, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG);
- }
+ float light[3];
+ PointCache *cache = NULL;
+ PTCacheID pid;
+ PointCache *cache_wt = NULL;
+ PTCacheID pid_wt;
+ int startframe, endframe, framenr;
+ float timescale;
+ int cache_result = 0, cache_result_wt = 0;
- /* reset view for new frame */
- if(sds->viewsettings < MOD_SMOKE_VIEW_USEBIG)
- sds->viewsettings = 0;
- else
- sds->viewsettings = MOD_SMOKE_VIEW_USEBIG;
+ framenr = scene->r.cfra;
- // do flows and fluids
- if(1)
- {
- Object *otherobj = NULL;
- ModifierData *md = NULL;
+ printf("time: %d\n", scene->r.cfra);
- if(sds->fluid_group) // we use groups since we have 2 domains
- go = sds->fluid_group->gobject.first;
- else
- base = scene->base.first;
+ if(framenr == smd->time)
+ return;
- while(base || go)
- {
- otherobj = NULL;
+ cache = sds->point_cache[0];
+ BKE_ptcache_id_from_smoke(&pid, ob, smd);
+ BKE_ptcache_id_time(&pid, scene, framenr, &startframe, &endframe, &timescale);
- if(sds->fluid_group)
- {
- if(go->ob)
- otherobj = go->ob;
- }
- else
- otherobj = base->object;
+ cache_wt = sds->point_cache[1];
+ BKE_ptcache_id_from_smoke_turbulence(&pid_wt, ob, smd);
- if(!otherobj)
- {
- if(sds->fluid_group)
- go = go->next;
- else
- base= base->next;
+ if(framenr < startframe)
+ return;
- continue;
- }
+ if(framenr > endframe)
+ return;
- md = modifiers_findByType(otherobj, eModifierType_Smoke);
-
- // check for active smoke modifier
- if(md && md->mode & (eModifierMode_Realtime | eModifierMode_Render))
- {
- SmokeModifierData *smd2 = (SmokeModifierData *)md;
-
- // check for initialized smoke object
- if((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow)
- {
- // we got nice flow object
- SmokeFlowSettings *sfs = smd2->flow;
-
- if(sfs->psys && sfs->psys->part && sfs->psys->part->type==PART_EMITTER) // is particle system selected
- {
- ParticleSystem *psys = sfs->psys;
- ParticleSettings *part=psys->part;
- ParticleData *pa = NULL;
- int p = 0;
- float *density = smoke_get_density(sds->fluid);
- float *bigdensity = smoke_turbulence_get_density(sds->wt);
- float *heat = smoke_get_heat(sds->fluid);
- float *velocity_x = smoke_get_velocity_x(sds->fluid);
- 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];
-
- printf("found flow psys\n");
-
- // mostly copied from particle code
- for(p=0, pa=psys->particles; p<psys->totpart; p++, pa++)
- {
- int cell[3];
- size_t i = 0;
- size_t index = 0;
- int badcell = 0;
-
- if(pa->alive == PARS_KILLED) continue;
- else if(pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN)==0) continue;
- else if(pa->alive == PARS_DEAD && (part->flag & PART_DIED)==0) continue;
- else if(pa->flag & (PARS_UNEXIST+PARS_NO_DISP)) continue;
-
- // VECCOPY(pos, pa->state.co);
- // Mat4MulVecfl (ob->imat, pos);
-
- // 1. get corresponding cell
- get_cell(smd, pa->state.co, cell, 0);
-
- // check if cell is valid (in the domain boundary)
- for(i = 0; i < 3; i++)
- {
- if((cell[i] > sds->res[i] - 1) || (cell[i] < 0))
- {
- badcell = 1;
- break;
- }
- }
-
- if(badcell)
- continue;
-
- // 2. set cell values (heat, density and velocity)
- index = smoke_get_index(cell[0], sds->res[0], cell[1], sds->res[1], cell[2]);
-
- if(!(sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW) && !(obstacle[index] & 2)) // this is inflow
- {
- // heat[index] += sfs->temp * 0.1;
- // density[index] += sfs->density * 0.1;
-
- heat[index] = sfs->temp;
- density[index] = sfs->density;
-
- /*
- 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)
- {
- // 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;
- }
- }
- }
- else if(sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW) // outflow
- {
- heat[index] = 0.f;
- density[index] = 0.f;
- velocity_x[index] = 0.f;
- velocity_y[index] = 0.f;
- velocity_z[index] = 0.f;
-
- // we need different handling for the high-res feature
- if(bigdensity)
- {
- // 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] = 0.f;
- }
- }
- }
- }
- }
- else
- {
- /*
- for()
- {
- // no psys
- BVHTreeNearest nearest;
+ if(!smd->domain->fluid)
+ {
+ BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
+ BKE_ptcache_id_reset(scene, &pid_wt, PTCACHE_RESET_OUTDATED);
+ }
- nearest.index = -1;
- nearest.dist = FLT_MAX;
+ if(!smokeModifier_init(smd, ob, scene, dm))
+ {
+ printf("bad smokeModifier_init\n");
+ return;
+ }
- BLI_bvhtree_find_nearest(sfs->bvh->tree, pco, &nearest, sfs->bvh->nearest_callback, sfs->bvh);
- }*/
- }
- }
- }
+ /* try to read from cache */
+ cache_result = BKE_ptcache_read_cache(&pid, (float)framenr, scene->r.frs_sec);
+ printf("cache_result: %d\n", cache_result);
- if(sds->fluid_group)
- go = go->next;
- else
- base= base->next;
- }
- }
+ if(cache_result == PTCACHE_READ_EXACT)
+ {
+ cache->flag |= PTCACHE_SIMULATION_VALID;
+ cache->simframe= framenr;
- // do effectors
- /*
- if(sds->eff_group)
+ if(sds->wt)
{
- for(go = sds->eff_group->gobject.first; go; go = go->next)
+ cache_result_wt = BKE_ptcache_read_cache(&pid_wt, (float)framenr, scene->r.frs_sec);
+
+ if(cache_result_wt == PTCACHE_READ_EXACT)
{
- if(go->ob)
- {
- if(ob->pd)
- {
-
- }
- }
+ cache_wt->flag |= PTCACHE_SIMULATION_VALID;
+ cache_wt->simframe= framenr;
}
}
- */
-
- // do collisions
- if(1)
- {
- Object *otherobj = NULL;
- ModifierData *md = NULL;
-
- if(sds->coll_group) // we use groups since we have 2 domains
- go = sds->coll_group->gobject.first;
- else
- base = scene->base.first;
-
- while(base || go)
- {
- otherobj = NULL;
-
- if(sds->coll_group)
- {
- if(go->ob)
- otherobj = go->ob;
- }
- else
- otherobj = base->object;
-
- if(!otherobj)
- {
- if(sds->coll_group)
- go = go->next;
- else
- base= base->next;
-
- continue;
- }
-
- md = modifiers_findByType(otherobj, eModifierType_Smoke);
-
- // check for active smoke modifier
- if(md && md->mode & (eModifierMode_Realtime | eModifierMode_Render))
- {
- SmokeModifierData *smd2 = (SmokeModifierData *)md;
-
- if((smd2->type & MOD_SMOKE_TYPE_COLL) && smd2->coll)
- {
- // we got nice collision object
- SmokeCollSettings *scs = smd2->coll;
- size_t i, j;
- unsigned char *obstacles = smoke_get_obstacle(smd->domain->fluid);
+ return;
+ }
- for(i = 0; i < scs->numpoints; i++)
- {
- int badcell = 0;
- size_t index = 0;
- int cell[3];
+ tstart();
- // 1. get corresponding cell
- get_cell(smd, &scs->points[3 * i], cell, 0);
-
- // check if cell is valid (in the domain boundary)
- for(j = 0; j < 3; j++)
- if((cell[j] > sds->res[j] - 1) || (cell[j] < 0))
- {
- badcell = 1;
- break;
- }
-
- if(badcell)
- continue;
-
- // 2. set cell values (heat, density and velocity)
- index = smoke_get_index(cell[0], sds->res[0], cell[1], sds->res[1], cell[2]);
-
- // printf("cell[0]: %d, cell[1]: %d, cell[2]: %d\n", cell[0], cell[1], cell[2]);
- // printf("res[0]: %d, res[1]: %d, res[2]: %d, index: %d\n\n", sds->res[0], sds->res[1], sds->res[2], index);
-
- obstacles[index] = 1;
+ smoke_calc_domain(scene, ob, smd);
+
+ // set new time
+ smd->time = scene->r.cfra;
- // for moving gobstacles
- /*
- const LbmFloat maxVelVal = 0.1666;
- const LbmFloat maxusqr = maxVelVal*maxVelVal*3. *1.5;
-
- LbmVec objvel = vec2L((mMOIVertices[n]-mMOIVerticesOld[n]) /dvec); {
- const LbmFloat usqr = (objvel[0]*objvel[0]+objvel[1]*objvel[1]+objvel[2]*objvel[2])*1.5;
- USQRMAXCHECK(usqr, objvel[0],objvel[1],objvel[2], mMaxVlen, mMxvx,mMxvy,mMxvz);
- if(usqr>maxusqr) {
- // cutoff at maxVelVal
- for(int jj=0; jj<3; jj++) {
- if(objvel[jj]>0.) objvel[jj] = maxVelVal;
- if(objvel[jj]<0.) objvel[jj] = -maxVelVal;
- }
- } }
-
- const LbmFloat dp=dot(objvel, vec2L((*pNormals)[n]) );
- const LbmVec oldov=objvel; // debug
- objvel = vec2L((*pNormals)[n]) *dp;
- */
- }
- }
- }
+ /* do simulation */
- if(sds->coll_group)
- go = go->next;
- else
- base= base->next;
- }
- }
-
- // set new time
- smd->time = scene->r.cfra;
+ // low res
+ cache->flag |= PTCACHE_SIMULATION_VALID;
+ cache->simframe= framenr;
- // simulate the actual smoke (c++ code in intern/smoke)
+ // simulate the actual smoke (c++ code in intern/smoke)
+ if(framenr!=startframe)
smoke_step(sds->fluid, smd->time);
- if(sds->wt)
- smoke_turbulence_step(sds->wt, sds->fluid);
+ BKE_ptcache_write_cache(&pid, framenr);
- tend();
- printf ( "Frame: %d, Time: %f\n", (int)smd->time, ( float ) tval() );
- }
- else if(scene->r.cfra < smd->time)
+ if(sds->wt)
{
- // we got back in time, reset smoke in this case (TODO: use cache later)
- smd->time = scene->r.cfra;
- smokeModifier_reset(smd);
- }
- }
-}
-
-// update necessary information for 3dview
-void smoke_prepare_View(SmokeModifierData *smd, float *light)
-{
- float *density = NULL;
- int x, y, z;
+ if(framenr!=startframe)
+ smoke_turbulence_step(sds->wt, sds->fluid);
- if(!smd->domain->tray)
- {
- // TRay is for self shadowing
- smd->domain->tray = MEM_callocN(sizeof(float)*smd->domain->res[0]*smd->domain->res[1]*smd->domain->res[2], "Smoke_tRay");
- }
- if(!smd->domain->tvox)
- {
- // TVox is for tranaparency
- smd->domain->tvox = MEM_callocN(sizeof(float)*smd->domain->res[0]*smd->domain->res[1]*smd->domain->res[2], "Smoke_tVox");
- }
+ cache_wt->flag |= PTCACHE_SIMULATION_VALID;
+ cache_wt->simframe= framenr;
+ BKE_ptcache_write_cache(&pid_wt, framenr);
+ }
- // update 3dview
- density = smoke_get_density(smd->domain->fluid);
- for(x = 0; x < smd->domain->res[0]; x++)
- for(y = 0; y < smd->domain->res[1]; y++)
- for(z = 0; z < smd->domain->res[2]; z++)
- {
- size_t index;
-
- index = smoke_get_index(x, smd->domain->res[0], y, smd->domain->res[1], z);
- // Transparency computation
- // formula taken from "Visual Simulation of Smoke" / Fedkiw et al. pg. 4
- // T_vox = exp(-C_ext * h)
- // C_ext/sigma_t = density * C_ext
- smoke_set_tvox(smd, index, exp(-density[index] * 7.0 * smd->domain->dx));
+ 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);
+
+ tend();
+ printf ( "Frame: %d, Time: %f\n", (int)smd->time, ( float ) tval() );
}
- smoke_calc_transparency(smd, light, 0);
}
-// update necessary information for 3dview ("high res" option)
-void smoke_prepare_bigView(SmokeModifierData *smd, float *light)
+static float calc_voxel_transp(float *result, float *input, int res[3], int *pixel, float *tRay, float correct)
{
- float *density = NULL;
- size_t i = 0;
- int bigres[3];
-
- smoke_turbulence_get_res(smd->domain->wt, bigres);
+ const size_t index = smoke_get_index(pixel[0], res[0], pixel[1], res[1], pixel[2]);
- if(!smd->domain->traybig)
- {
- // TRay is for self shadowing
- smd->domain->traybig = MEM_callocN(sizeof(float)*bigres[0]*bigres[1]*bigres[2], "Smoke_tRayBig");
- }
- if(!smd->domain->tvoxbig)
+ // T_ray *= T_vox
+ *tRay *= exp(input[index]*correct);
+
+ if(result[index] < 0.0f)
{
- // TVox is for tranaparency
- smd->domain->tvoxbig = MEM_callocN(sizeof(float)*bigres[0]*bigres[1]*bigres[2], "Smoke_tVoxBig");
- }
+#pragma omp critical
+ result[index] = *tRay;
+ }
- density = smoke_turbulence_get_density(smd->domain->wt);
- for (i = 0; i < bigres[0] * bigres[1] * bigres[2]; i++)
- {
- // Transparency computation
- // formula taken from "Visual Simulation of Smoke" / Fedkiw et al. pg. 4
- // T_vox = exp(-C_ext * h)
- // C_ext/sigma_t = density * C_ext
- smoke_set_bigtvox(smd, i, exp(-density[i] * 7.0 * smd->domain->dx / (smd->domain->amplify + 1)) );
- }
- smoke_calc_transparency(smd, light, 1);
-}
-
-
-float smoke_get_tvox(SmokeModifierData *smd, size_t index)
-{
- return smd->domain->tvox[index];
-}
-
-void smoke_set_tvox(SmokeModifierData *smd, size_t index, float tvox)
-{
- smd->domain->tvox[index] = tvox;
-}
-
-float smoke_get_tray(SmokeModifierData *smd, size_t index)
-{
- return smd->domain->tray[index];
-}
-
-void smoke_set_tray(SmokeModifierData *smd, size_t index, float transparency)
-{
- smd->domain->tray[index] = transparency;
-}
-
-float smoke_get_bigtvox(SmokeModifierData *smd, size_t index)
-{
- return smd->domain->tvoxbig[index];
-}
-
-void smoke_set_bigtvox(SmokeModifierData *smd, size_t index, float tvox)
-{
- smd->domain->tvoxbig[index] = tvox;
-}
-
-float smoke_get_bigtray(SmokeModifierData *smd, size_t index)
-{
- return smd->domain->traybig[index];
-}
-
-void smoke_set_bigtray(SmokeModifierData *smd, size_t index, float transparency)
-{
- smd->domain->traybig[index] = transparency;
+ return *tRay;
}
long long smoke_get_mem_req(int xres, int yres, int zres, int amplify)
@@ -1259,34 +1233,7 @@ long long smoke_get_mem_req(int xres, int yres, int zres, int amplify)
return totalMB;
}
-
-static void calc_voxel_transp(SmokeModifierData *smd, int *pixel, float *tRay)
-{
- // printf("Pixel(%d, %d, %d)\n", pixel[0], pixel[1], pixel[2]);
- const size_t index = smoke_get_index(pixel[0], smd->domain->res[0], pixel[1], smd->domain->res[1], pixel[2]);
-
- // T_ray *= T_vox
- *tRay *= smoke_get_tvox(smd, index);
-}
-
-static void calc_voxel_transp_big(SmokeModifierData *smd, int *pixel, float *tRay)
-{
- int bigres[3];
- size_t index;
-
- smoke_turbulence_get_res(smd->domain->wt, bigres);
- index = smoke_get_index(pixel[0], bigres[0], pixel[1], bigres[1], pixel[2]);
-
- /*
- if(index > bigres[0]*bigres[1]*bigres[2])
- printf("pixel[0]: %d, [1]: %d, [2]: %d\n", pixel[0], pixel[1], pixel[2]);
- */
-
- // T_ray *= T_vox
- *tRay *= smoke_get_bigtvox(smd, index);
-}
-
-static void bresenham_linie_3D(SmokeModifierData *smd, int x1, int y1, int z1, int x2, int y2, int z2, float *tRay, int big)
+static void bresenham_linie_3D(int x1, int y1, int z1, int x2, int y2, int z2, float *tRay, bresenham_callback cb, float *result, float *input, int res[3], float correct)
{
int dx, dy, dz, i, l, m, n, x_inc, y_inc, z_inc, err_1, err_2, dx2, dy2, dz2;
int pixel[3];
@@ -1313,12 +1260,8 @@ static void bresenham_linie_3D(SmokeModifierData *smd, int x1, int y1, int z1, i
err_1 = dy2 - l;
err_2 = dz2 - l;
for (i = 0; i < l; i++) {
- if(!big)
- calc_voxel_transp(smd, pixel, tRay);
- else
- calc_voxel_transp_big(smd, pixel, tRay);
- if(*tRay < 0.0f)
- return;
+ if(cb(result, input, res, pixel, tRay, correct) <= FLT_EPSILON)
+ break;
if (err_1 > 0) {
pixel[1] += y_inc;
err_1 -= dx2;
@@ -1335,12 +1278,8 @@ static void bresenham_linie_3D(SmokeModifierData *smd, int x1, int y1, int z1, i
err_1 = dx2 - m;
err_2 = dz2 - m;
for (i = 0; i < m; i++) {
- if(!big)
- calc_voxel_transp(smd, pixel, tRay);
- else
- calc_voxel_transp_big(smd, pixel, tRay);
- if(*tRay < 0.0f)
- return;
+ if(cb(result, input, res, pixel, tRay, correct) <= FLT_EPSILON)
+ break;
if (err_1 > 0) {
pixel[0] += x_inc;
err_1 -= dy2;
@@ -1357,12 +1296,8 @@ static void bresenham_linie_3D(SmokeModifierData *smd, int x1, int y1, int z1, i
err_1 = dy2 - n;
err_2 = dx2 - n;
for (i = 0; i < n; i++) {
- if(!big)
- calc_voxel_transp(smd, pixel, tRay);
- else
- calc_voxel_transp_big(smd, pixel, tRay);
- if(*tRay < 0.0f)
- return;
+ if(cb(result, input, res, pixel, tRay, correct) <= FLT_EPSILON)
+ break;
if (err_1 > 0) {
pixel[1] += y_inc;
err_1 -= dz2;
@@ -1376,41 +1311,15 @@ static void bresenham_linie_3D(SmokeModifierData *smd, int x1, int y1, int z1, i
pixel[2] += z_inc;
}
}
- if(!big)
- calc_voxel_transp(smd, pixel, tRay);
- else
- calc_voxel_transp_big(smd, pixel, tRay);
+ cb(result, input, res, pixel, tRay, correct);
}
-static void get_cell(struct SmokeModifierData *smd, float *pos, int *cell, int correct)
+static void get_cell(float *p0, int res[3], float dx, float *pos, int *cell, int correct)
{
float tmp[3];
- VECSUB(tmp, pos, smd->domain->p0);
- VecMulf(tmp, 1.0 / smd->domain->dx);
-
- if(correct)
- {
- cell[0] = MIN2(smd->domain->res[0] - 1, MAX2(0, (int)floor(tmp[0])));
- cell[1] = MIN2(smd->domain->res[1] - 1, MAX2(0, (int)floor(tmp[1])));
- cell[2] = MIN2(smd->domain->res[2] - 1, MAX2(0, (int)floor(tmp[2])));
- }
- else
- {
- cell[0] = (int)floor(tmp[0]);
- cell[1] = (int)floor(tmp[1]);
- cell[2] = (int)floor(tmp[2]);
- }
-}
-static void get_bigcell(struct SmokeModifierData *smd, float *pos, int *cell, int correct)
-{
- float tmp[3];
- int res[3];
- smoke_turbulence_get_res(smd->domain->wt, res);
-
- VECSUB(tmp, pos, smd->domain->p0);
-
- VecMulf(tmp, (smd->domain->amplify + 1)/ smd->domain->dx );
+ VECSUB(tmp, pos, p0);
+ VecMulf(tmp, 1.0 / dx);
if(correct)
{
@@ -1426,43 +1335,22 @@ static void get_bigcell(struct SmokeModifierData *smd, float *pos, int *cell, in
}
}
-
-void smoke_calc_transparency(struct SmokeModifierData *smd, float *light, int big)
+void smoke_calc_transparency(float *result, float *input, float *p0, float *p1, int res[3], float dx, float *light, bresenham_callback cb, float correct)
{
int x, y, z;
float bv[6];
- int res[3];
- float bigfactor = 1.0;
- // x
- bv[0] = smd->domain->p0[0];
- bv[1] = smd->domain->p1[0];
+ memset(result, -1, sizeof(float)*res[0]*res[1]*res[2]); // x
+ bv[0] = p0[0];
+ bv[1] = p1[0];
// y
- bv[2] = smd->domain->p0[1];
- bv[3] = smd->domain->p1[1];
+ bv[2] = p0[1];
+ bv[3] = p1[1];
// z
- bv[4] = smd->domain->p0[2];
- bv[5] = smd->domain->p1[2];
-/*
- printf("bv[0]: %f, [1]: %f, [2]: %f, [3]: %f, [4]: %f, [5]: %f\n", bv[0], bv[1], bv[2], bv[3], bv[4], bv[5]);
+ bv[4] = p0[2];
+ bv[5] = p1[2];
- printf("p0[0]: %f, p0[1]: %f, p0[2]: %f\n", smd->domain->p0[0], smd->domain->p0[1], smd->domain->p0[2]);
- printf("p1[0]: %f, p1[1]: %f, p1[2]: %f\n", smd->domain->p1[0], smd->domain->p1[1], smd->domain->p1[2]);
- printf("dx: %f, amp: %d\n", smd->domain->dx, smd->domain->amplify);
-*/
- if(!big)
- {
- res[0] = smd->domain->res[0];
- res[1] = smd->domain->res[1];
- res[2] = smd->domain->res[2];
- }
- else
- {
- smoke_turbulence_get_res(smd->domain->wt, res);
- bigfactor = 1.0 / (smd->domain->amplify + 1);
- }
-
-#pragma omp parallel for schedule(static) private(y, z) shared(big, smd, light, res, bigfactor)
+#pragma omp parallel for schedule(static) private(y, z)
for(x = 0; x < res[0]; x++)
for(y = 0; y < res[1]; y++)
for(z = 0; z < res[2]; z++)
@@ -1475,41 +1363,29 @@ void smoke_calc_transparency(struct SmokeModifierData *smd, float *light, int bi
index = smoke_get_index(x, res[0], y, res[1], z);
- // voxelCenter = m_voxelarray[i].GetCenter();
- voxelCenter[0] = smd->domain->p0[0] + smd->domain->dx * bigfactor * x + smd->domain->dx * bigfactor * 0.5;
- voxelCenter[1] = smd->domain->p0[1] + smd->domain->dx * bigfactor * y + smd->domain->dx * bigfactor * 0.5;
- voxelCenter[2] = smd->domain->p0[2] + smd->domain->dx * bigfactor * z + smd->domain->dx * bigfactor * 0.5;
-
- // printf("vc[0]: %f, vc[1]: %f, vc[2]: %f\n", voxelCenter[0], voxelCenter[1], voxelCenter[2]);
- // printf("light[0]: %f, light[1]: %f, light[2]: %f\n", light[0], light[1], light[2]);
+ if(result[index] >= 0.0f)
+ continue;
+ voxelCenter[0] = p0[0] + dx * x + dx * 0.5;
+ voxelCenter[1] = p0[1] + dx * y + dx * 0.5;
+ voxelCenter[2] = p0[2] + dx * z + dx * 0.5;
// get starting position (in voxel coords)
if(BLI_bvhtree_bb_raycast(bv, light, voxelCenter, pos) > FLT_EPSILON)
{
// we're ouside
- // printf("out: pos[0]: %f, pos[1]: %f, pos[2]: %f\n", pos[0], pos[1], pos[2]);
- if(!big)
- get_cell(smd, pos, cell, 1);
- else
- get_bigcell(smd, pos, cell, 1);
+ get_cell(p0, res, dx, pos, cell, 1);
}
else
{
- // printf("in: pos[0]: %f, pos[1]: %f, pos[2]: %f\n", light[0], light[1], light[2]);
// we're inside
- if(!big)
- get_cell(smd, light, cell, 1);
- else
- get_bigcell(smd, light, cell, 1);
+ get_cell(p0, res, dx, light, cell, 1);
}
- // printf("cell - [0]: %d, [1]: %d, [2]: %d\n", cell[0], cell[1], cell[2]);
- bresenham_linie_3D(smd, cell[0], cell[1], cell[2], x, y, z, &tRay, big);
+ bresenham_linie_3D(cell[0], cell[1], cell[2], x, y, z, &tRay, cb, result, input, res, correct);
- if(!big)
- smoke_set_tray(smd, index, tRay);
- else
- smoke_set_bigtray(smd, index, tRay);
+ // convention -> from a RGBA float array, use G value for tRay
+// #pragma omp critical
+ result[index] = tRay;
}
}
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c
index 68f918b0c68..450a64d72eb 100644
--- a/source/blender/blenkernel/intern/softbody.c
+++ b/source/blender/blenkernel/intern/softbody.c
@@ -58,7 +58,6 @@ variables on the UI for now
#include "DNA_curve_types.h"
#include "DNA_object_types.h"
#include "DNA_object_force.h" /* here is the softbody struct */
-#include "DNA_particle_types.h"
#include "DNA_key_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
@@ -76,7 +75,6 @@ variables on the UI for now
#include "BKE_global.h"
#include "BKE_key.h"
#include "BKE_object.h"
-#include "BKE_particle.h"
#include "BKE_softbody.h"
#include "BKE_utildefines.h"
#include "BKE_DerivedMesh.h"
@@ -494,32 +492,21 @@ static void ccd_build_deflector_hash(Scene *scene, Object *vertexowner, GHash *h
while (base) {
/*Only proceed for mesh object in same layer */
if(base->object->type==OB_MESH && (base->lay & vertexowner->lay)) {
- int particles=0;
ob= base->object;
if((vertexowner) && (ob == vertexowner)) {
- if(vertexowner->soft->particles){
- particles=1;
- }
- else {
- /* if vertexowner is given we don't want to check collision with owner object */
- base = base->next;
- continue;
- }
+ /* if vertexowner is given we don't want to check collision with owner object */
+ base = base->next;
+ continue;
}
/*+++ only with deflecting set */
if(ob->pd && ob->pd->deflect && BLI_ghash_lookup(hash, ob) == 0) {
DerivedMesh *dm= NULL;
- if(particles) {
- dm = psys_get_modifier(ob,psys_get_current(ob))->dm;
- }
- else {
- if(ob->softflag & OB_SB_COLLFINAL) /* so maybe someone wants overkill to collide with subsurfed */
- dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
- else
- dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH);
- }
+ if(ob->softflag & OB_SB_COLLFINAL) /* so maybe someone wants overkill to collide with subsurfed */
+ dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
+ else
+ dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH);
if(dm){
ccd_Mesh *ccdmesh = ccd_mesh_make(ob, dm);
@@ -866,7 +853,8 @@ static void renew_softbody(Scene *scene, Object *ob, int totpoint, int totspring
bp->frozen = 1.0f;
bp->colball = 0.0f;
bp->flag = 0;
-
+ bp->springweight = 1.0f;
+ bp->mass = sb->nodemass;
}
}
}
@@ -3570,107 +3558,6 @@ static void curve_surf_to_softbody(Scene *scene, Object *ob)
}
}
-
-static void springs_from_particles(Object *ob)
-{
- ParticleSystem *psys;
- ParticleSystemModifierData *psmd=0;
- ParticleData *pa=0;
- HairKey *key=0;
- SoftBody *sb;
- BodyPoint *bp;
- BodySpring *bs;
- int a,k;
- float hairmat[4][4];
-
- if(ob && ob->soft && ob->soft->particles) {
- psys= ob->soft->particles;
- sb= ob->soft;
- psmd = psys_get_modifier(ob, psys);
-
- bp= sb->bpoint;
- for(a=0, pa=psys->particles; a<psys->totpart; a++, pa++) {
- for(k=0, key=pa->hair; k<pa->totkey; k++, bp++, key++) {
- VECCOPY(bp->origS, key->co);
-
- psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, hairmat);
-
- Mat4MulVecfl(hairmat, bp->origS);
- }
- }
-
- for(a=0, bs=sb->bspring; a<sb->totspring; a++, bs++)
- bs->len= VecLenf(sb->bpoint[bs->v1].origS, sb->bpoint[bs->v2].origS);
- }
-}
-
-static void particles_to_softbody(Scene *scene, Object *ob)
-{
- SoftBody *sb;
- BodyPoint *bp;
- BodySpring *bs;
- ParticleData *pa;
- HairKey *key;
- ParticleSystem *psys= ob->soft->particles;
- float goalfac;
- int a, k, curpoint;
- int totpoint= psys_count_keys(psys);
- int totedge= totpoint-psys->totpart;
-
- /* renew ends with ob->soft with points and edges, also checks & makes ob->soft */
- renew_softbody(scene, ob, totpoint, totedge);
-
- /* find first BodyPoint index for each particle */
- if(psys->totpart > 0) {
- psys->particles->bpi = 0;
- for(a=1, pa=psys->particles+1; a<psys->totpart; a++, pa++)
- pa->bpi = (pa-1)->bpi + (pa-1)->totkey;
- }
-
- /* we always make body points */
- sb= ob->soft;
- bp= sb->bpoint;
- bs= sb->bspring;
- goalfac= ABS(sb->maxgoal - sb->mingoal);
-
- if((ob->softflag & OB_SB_GOAL)) {
- for(a=0, pa=psys->particles; a<psys->totpart; a++, pa++) {
- for(k=0, key=pa->hair; k<pa->totkey; k++,bp++,key++) {
- if(k) {
- bp->goal= key->weight;
- bp->goal= sb->mingoal + bp->goal*goalfac;
- bp->goal= (float)pow(bp->goal, 4.0f);
- }
- else{
- /* hair roots are allways fixed fully to goal */
- bp->goal= 1.0f;
- }
- }
- }
- }
-
- bp= sb->bpoint;
- curpoint=0;
- for(a=0, pa=psys->particles; a<psys->totpart; a++, curpoint++, pa++) {
- for(k=0; k<pa->totkey-1; k++,bs++,curpoint++) {
- bs->v1=curpoint;
- bs->v2=curpoint+1;
- bs->strength= 1.0;
- bs->order=1;
- }
- }
-
- build_bps_springlist(ob); /* scan for springs attached to bodypoints ONCE */
- /* insert *other second order* springs if desired */
- if(sb->secondspring > 0.0000001f) {
- add_2nd_order_springs(ob,sb->secondspring*10.0); /* exploits the the first run of build_bps_springlist(ob);*/
- build_bps_springlist(ob); /* yes we need to do it again*/
- }
- springs_from_particles(ob); /* write the 'rest'-lenght of the springs */
- if(ob->softflag & OB_SB_SELF)
- calculate_collision_balls(ob);
-}
-
/* copies softbody result back in object */
static void softbody_to_object(Object *ob, float (*vertexCos)[3], int numVerts, int local)
{
@@ -3794,44 +3681,16 @@ void sbSetInterruptCallBack(int (*f)(void))
static void softbody_update_positions(Object *ob, SoftBody *sb, float (*vertexCos)[3], int numVerts)
{
- ParticleSystemModifierData *psmd= NULL;
- ParticleData *pa= NULL;
- HairKey *key= NULL;
BodyPoint *bp;
- float hairmat[4][4];
int a;
- /* update the vertex locations */
- if(sb->particles && sb->particles->totpart>0) {
- psmd= psys_get_modifier(ob,sb->particles);
-
- pa= sb->particles->particles;
- key= pa->hair;
-
- psys_mat_hair_to_global(ob, psmd->dm, sb->particles->part->from, pa, hairmat);
- }
-
for(a=0,bp=sb->bpoint; a<numVerts; a++, bp++) {
/* store where goals are now */
VECCOPY(bp->origS, bp->origE);
/* copy the position of the goals at desired end time */
- if(sb->particles) {
- if(key == pa->hair + pa->totkey) {
- pa++;
- key = pa->hair;
-
- psys_mat_hair_to_global(ob, psmd->dm, sb->particles->part->from, pa, hairmat);
- }
- VECCOPY(bp->origE, key->co);
- Mat4MulVecfl(hairmat,bp->origE);
-
- key++;
- }
- else{
- VECCOPY(bp->origE, vertexCos[a]);
- /* vertexCos came from local world, go global */
- Mat4MulVecfl(ob->obmat, bp->origE);
- }
+ VECCOPY(bp->origE, vertexCos[a]);
+ /* vertexCos came from local world, go global */
+ Mat4MulVecfl(ob->obmat, bp->origE);
/* just to be save give bp->origT a defined value
will be calulated in interpolate_exciter()*/
VECCOPY(bp->origT, bp->origE);
@@ -3840,37 +3699,12 @@ static void softbody_update_positions(Object *ob, SoftBody *sb, float (*vertexCo
static void softbody_reset(Object *ob, SoftBody *sb, float (*vertexCos)[3], int numVerts)
{
- ParticleSystemModifierData *psmd= NULL;
- HairKey *key= NULL;
- ParticleData *pa= NULL;
BodyPoint *bp;
- float hairmat[4][4];
int a;
- if(sb->particles && sb->particles->totpart>0) {
- psmd= psys_get_modifier(ob, sb->particles);
- pa= sb->particles->particles;
- key= pa->hair;
-
- psys_mat_hair_to_global(ob, psmd->dm, sb->particles->part->from, pa, hairmat);
- }
-
for(a=0,bp=sb->bpoint; a<numVerts; a++, bp++) {
- if(sb->particles) {
- if(key == pa->hair + pa->totkey) {
- pa++;
- key = pa->hair;
-
- psys_mat_hair_to_global(ob, psmd->dm, sb->particles->part->from, pa, hairmat);
- }
- VECCOPY(bp->pos, key->co);
- Mat4MulVecfl(hairmat, bp->pos);
- key++;
- }
- else {
- VECCOPY(bp->pos, vertexCos[a]);
- Mat4MulVecfl(ob->obmat, bp->pos); /* yep, sofbody is global coords*/
- }
+ VECCOPY(bp->pos, vertexCos[a]);
+ Mat4MulVecfl(ob->obmat, bp->pos); /* yep, sofbody is global coords*/
VECCOPY(bp->origS, bp->pos);
VECCOPY(bp->origE, bp->pos);
VECCOPY(bp->origT, bp->pos);
@@ -3899,20 +3733,18 @@ static void softbody_reset(Object *ob, SoftBody *sb, float (*vertexCos)[3], int
sb_new_scratch(sb); /* make a new */
sb->scratch->needstobuildcollider=1;
- if((sb->particles)==0) {
- /* copy some info to scratch */
- switch(ob->type) {
- case OB_MESH:
- if (ob->softflag & OB_SB_FACECOLL) mesh_faces_to_scratch(ob);
- break;
- case OB_LATTICE:
- break;
- case OB_CURVE:
- case OB_SURF:
- break;
- default:
- break;
- }
+ /* copy some info to scratch */
+ switch(ob->type) {
+ case OB_MESH:
+ if (ob->softflag & OB_SB_FACECOLL) mesh_faces_to_scratch(ob);
+ break;
+ case OB_LATTICE:
+ break;
+ case OB_CURVE:
+ case OB_SURF:
+ break;
+ default:
+ break;
}
}
@@ -4048,8 +3880,6 @@ static void softbody_step(Scene *scene, Object *ob, SoftBody *sb, float dtime)
/* simulates one step. framenr is in frames */
void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], int numVerts)
{
- ParticleSystemModifierData *psmd=0;
- ParticleData *pa=0;
SoftBody *sb= ob->soft;
PointCache *cache;
PTCacheID pid;
@@ -4078,7 +3908,7 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i
if(framenr < startframe) {
cache->flag &= ~PTCACHE_SIMULATION_VALID;
cache->simframe= 0;
- cache->last_exact= 0;
+ //cache->last_exact= 0;
return;
}
@@ -4090,25 +3920,20 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i
if(sb->bpoint == NULL ||
((ob->softflag & OB_SB_EDGES) && !ob->soft->bspring && object_has_edges(ob))) {
- if(sb->particles){
- particles_to_softbody(scene, ob);
- }
- else {
- switch(ob->type) {
- case OB_MESH:
- mesh_to_softbody(scene, ob);
- break;
- case OB_LATTICE:
- lattice_to_softbody(scene, ob);
- break;
- case OB_CURVE:
- case OB_SURF:
- curve_surf_to_softbody(scene, ob);
- break;
- default:
- renew_softbody(scene, ob, numVerts, 0);
- break;
- }
+ switch(ob->type) {
+ case OB_MESH:
+ mesh_to_softbody(scene, ob);
+ break;
+ case OB_LATTICE:
+ lattice_to_softbody(scene, ob);
+ break;
+ case OB_CURVE:
+ case OB_SURF:
+ curve_surf_to_softbody(scene, ob);
+ break;
+ default:
+ renew_softbody(scene, ob, numVerts, 0);
+ break;
}
softbody_update_positions(ob, sb, vertexCos, numVerts);
@@ -4126,8 +3951,7 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i
softbody_update_positions(ob, sb, vertexCos, numVerts);
softbody_step(scene, ob, sb, dtime);
- if(sb->particles==0)
- softbody_to_object(ob, vertexCos, numVerts, 0);
+ softbody_to_object(ob, vertexCos, numVerts, 0);
return;
}
@@ -4135,25 +3959,33 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i
/* still no points? go away */
if(sb->totpoint==0) return;
- if(sb->particles){
- psmd= psys_get_modifier(ob, sb->particles);
- pa= sb->particles->particles;
+ if(framenr == startframe) {
+ BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
+
+ /* first frame, no simulation to do, just set the positions */
+ softbody_update_positions(ob, sb, vertexCos, numVerts);
+
+ cache->simframe= framenr;
+ cache->flag |= PTCACHE_SIMULATION_VALID;
+ cache->flag &= ~PTCACHE_REDO_NEEDED;
+ return;
}
/* try to read from cache */
cache_result = BKE_ptcache_read_cache(&pid, framenr, scene->r.frs_sec);
if(cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED) {
- cache->flag |= PTCACHE_SIMULATION_VALID;
+ softbody_to_object(ob, vertexCos, numVerts, sb->local);
+
cache->simframe= framenr;
+ cache->flag |= PTCACHE_SIMULATION_VALID;
- if(sb->particles==0)
- softbody_to_object(ob, vertexCos, numVerts, sb->local);
+ if(cache_result == PTCACHE_READ_INTERPOLATED && cache->flag & PTCACHE_REDO_NEEDED)
+ BKE_ptcache_write_cache(&pid, framenr);
return;
}
else if(cache_result==PTCACHE_READ_OLD) {
- BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_FREE);
cache->flag |= PTCACHE_SIMULATION_VALID;
}
else if(ob->id.lib || (cache->flag & PTCACHE_BAKED)) {
@@ -4164,41 +3996,23 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i
return;
}
- if(framenr == startframe) {
- if(cache->flag & PTCACHE_REDO_NEEDED) {
- softbody_update_positions(ob, sb, vertexCos, numVerts);
- softbody_reset(ob, sb, vertexCos, numVerts);
- cache->flag &= ~PTCACHE_REDO_NEEDED;
- }
- /* first frame, no simulation to do, just set the positions */
- softbody_update_positions(ob, sb, vertexCos, numVerts);
-
- cache->flag |= PTCACHE_SIMULATION_VALID;
- cache->simframe= framenr;
-
- /* don't write cache on first frame, but on second frame write
- * cache for frame 1 and 2 */
- }
- else {
- /* if on second frame, write cache for first frame */
- if(cache->simframe == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact==0))
- BKE_ptcache_write_cache(&pid, startframe);
+ /* if on second frame, write cache for first frame */
+ if(cache->simframe == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact==0))
+ BKE_ptcache_write_cache(&pid, startframe);
- softbody_update_positions(ob, sb, vertexCos, numVerts);
+ softbody_update_positions(ob, sb, vertexCos, numVerts);
- /* do simulation */
- cache->flag |= PTCACHE_SIMULATION_VALID;
- cache->simframe= framenr;
+ /* checking time: */
+ dtime = framedelta*timescale;
- /* checking time: */
- dtime = framedelta*timescale;
+ softbody_step(scene, ob, sb, dtime);
- softbody_step(scene, ob, sb, dtime);
+ softbody_to_object(ob, vertexCos, numVerts, 0);
- if(sb->particles==0)
- softbody_to_object(ob, vertexCos, numVerts, 0);
+ /* do simulation */
+ cache->simframe= framenr;
+ cache->flag |= PTCACHE_SIMULATION_VALID;
- BKE_ptcache_write_cache(&pid, framenr);
- }
+ BKE_ptcache_write_cache(&pid, framenr);
}
diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c
index a3275792a85..2d5d8dad7a8 100644
--- a/source/blender/blenkernel/intern/sound.c
+++ b/source/blender/blenkernel/intern/sound.c
@@ -34,7 +34,7 @@
void sound_init()
{
AUD_Specs specs;
- int device, buffersize, success;
+ int device, buffersize;
device = U.audiodevice;
buffersize = U.mixbufsize;
@@ -54,15 +54,8 @@ void sound_init()
if(specs.channels <= AUD_CHANNELS_INVALID)
specs.channels = AUD_CHANNELS_STEREO;
- if(!AUD_init(device, specs, buffersize)) {
- if(device == AUD_SDL_DEVICE)
- success= AUD_init(AUD_OPENAL_DEVICE, specs, AUD_DEFAULT_BUFFER_SIZE*4);
- else
- success= AUD_init(AUD_SDL_DEVICE, specs, AUD_DEFAULT_BUFFER_SIZE*4);
-
- if(!success)
- AUD_init(AUD_NULL_DEVICE, specs, buffersize);
- }
+ if(!AUD_init(device, specs, buffersize))
+ AUD_init(AUD_NULL_DEVICE, specs, buffersize);
}
void sound_exit()
@@ -78,7 +71,7 @@ struct bSound* sound_new_file(struct Main *main, char* filename)
int len;
strcpy(str, filename);
- BLI_convertstringcode(str, G.sce);
+ BLI_convertstringcode(str, main->name);
len = strlen(filename);
while(len > 0 && filename[len-1] != '/' && filename[len-1] != '\\')
@@ -86,11 +79,11 @@ struct bSound* sound_new_file(struct Main *main, char* filename)
sound = alloc_libblock(&main->sound, ID_SO, filename+len);
strcpy(sound->name, filename);
- sound->type = SOUND_TYPE_FILE;
+// XXX unused currently sound->type = SOUND_TYPE_FILE;
- sound_load(sound);
+ sound_load(main, sound);
- if(!sound->snd_sound)
+ if(!sound->handle)
{
free_libblock(&main->sound, sound);
sound = NULL;
@@ -114,9 +107,9 @@ struct bSound* sound_new_buffer(struct bContext *C, struct bSound *source)
sound->child_sound = source;
sound->type = SOUND_TYPE_BUFFER;
- sound_load(sound);
+ sound_load(CTX_data_main(C), sound);
- if(!sound->snd_sound)
+ if(!sound->handle)
{
free_libblock(&CTX_data_main(C)->sound, sound);
sound = NULL;
@@ -140,9 +133,9 @@ struct bSound* sound_new_limiter(struct bContext *C, struct bSound *source, floa
sound->end = end;
sound->type = SOUND_TYPE_LIMITER;
- sound_load(sound);
+ sound_load(CTX_data_main(C), sound);
- if(!sound->snd_sound)
+ if(!sound->handle)
{
free_libblock(&CTX_data_main(C)->sound, sound);
sound = NULL;
@@ -169,22 +162,35 @@ void sound_cache(struct bSound* sound, int ignore)
if(sound->cache && !ignore)
AUD_unload(sound->cache);
- sound->cache = AUD_bufferSound(sound->snd_sound);
+ sound->cache = AUD_bufferSound(sound->handle);
+ sound->changed++;
}
-void sound_load(struct bSound* sound)
+void sound_delete_cache(struct bSound* sound)
+{
+ if(sound->cache)
+ {
+ AUD_unload(sound->cache);
+ sound->cache = NULL;
+ }
+}
+
+void sound_load(struct Main *main, struct bSound* sound)
{
if(sound)
{
- if(sound->snd_sound)
+ if(sound->handle)
{
- AUD_unload(sound->snd_sound);
- sound->snd_sound = NULL;
+ AUD_unload(sound->handle);
+ sound->handle = NULL;
}
+// XXX unused currently
+#if 0
switch(sound->type)
{
case SOUND_TYPE_FILE:
+#endif
{
char fullpath[FILE_MAX];
char *path;
@@ -198,32 +204,32 @@ void sound_load(struct bSound* sound)
if(sound->id.lib)
path = sound->id.lib->filename;
else
- path = G.sce;
+ path = main ? main->name : G.sce;
BLI_convertstringcode(fullpath, path);
/* but we need a packed file then */
if (pf)
- sound->snd_sound = AUD_loadBuffer((unsigned char*) pf->data, pf->size);
+ sound->handle = AUD_loadBuffer((unsigned char*) pf->data, pf->size);
/* or else load it from disk */
else
- sound->snd_sound = AUD_load(fullpath);
+ sound->handle = AUD_load(fullpath);
+ } // XXX
+// XXX unused currently
+#if 0
break;
}
case SOUND_TYPE_BUFFER:
- if(sound->child_sound && sound->child_sound->snd_sound)
- sound->snd_sound = AUD_bufferSound(sound->child_sound->snd_sound);
+ if(sound->child_sound && sound->child_sound->handle)
+ sound->handle = AUD_bufferSound(sound->child_sound->handle);
break;
case SOUND_TYPE_LIMITER:
- if(sound->child_sound && sound->child_sound->snd_sound)
- sound->snd_sound = AUD_limitSound(sound->child_sound, sound->start, sound->end);
+ if(sound->child_sound && sound->child_sound->handle)
+ sound->handle = AUD_limitSound(sound->child_sound, sound->start, sound->end);
break;
}
-
- if(sound->cache)
- {
-
- }
+#endif
+ sound->changed++;
}
}
@@ -235,33 +241,36 @@ void sound_free(struct bSound* sound)
sound->packedfile = NULL;
}
- if(sound->snd_sound)
+ if(sound->handle)
{
- AUD_unload(sound->snd_sound);
- sound->snd_sound = NULL;
+ AUD_unload(sound->handle);
+ sound->handle = NULL;
}
}
void sound_unlink(struct bContext *C, struct bSound* sound)
{
- bSound *snd;
Scene *scene;
SoundHandle *handle;
+// XXX unused currently
+#if 0
+ bSound *snd;
for(snd = CTX_data_main(C)->sound.first; snd; snd = snd->id.next)
{
if(snd->child_sound == sound)
{
snd->child_sound = NULL;
- if(snd->snd_sound)
+ if(snd->handle)
{
- AUD_unload(sound->snd_sound);
- snd->snd_sound = NULL;
+ AUD_unload(sound->handle);
+ snd->handle = NULL;
}
sound_unlink(C, snd);
}
}
+#endif
for(scene = CTX_data_main(C)->scene.first; scene; scene = scene->id.next)
{
@@ -319,8 +328,6 @@ void sound_stop_all(struct bContext *C)
}
}
-#define SOUND_PLAYBACK_LAMBDA 1.0
-
void sound_update_playing(struct bContext *C)
{
SoundHandle *handle;
@@ -366,12 +373,10 @@ void sound_update_playing(struct bContext *C)
action = 3;
else
{
- float diff = AUD_getPosition(handle->handle) - (cfra - handle->startframe) / fps;
-// AUD_XXX float diff = AUD_getPosition(handle->handle) * fps - cfra + handle->startframe
+ float diff = AUD_getPosition(handle->handle) * fps - cfra + handle->startframe;
if(diff < 0.0)
diff = -diff;
- if(diff > SOUND_PLAYBACK_LAMBDA)
-// AUD_XXX if(diff > 5.0f)
+ if(diff > FPS/2.0)
{
action = 2;
}
@@ -383,9 +388,9 @@ void sound_update_playing(struct bContext *C)
{
if(handle->state == AUD_STATUS_INVALID)
{
- if(handle->source && handle->source->snd_sound)
+ if(handle->source && handle->source->handle)
{
- AUD_Sound* limiter = AUD_limitSound(handle->source->cache ? handle->source->cache : handle->source->snd_sound, handle->frameskip / fps, (handle->frameskip + handle->endframe - handle->startframe)/fps);
+ AUD_Sound* limiter = AUD_limitSound(handle->source->cache ? handle->source->cache : handle->source->handle, handle->frameskip / fps, (handle->frameskip + handle->endframe - handle->startframe)/fps);
handle->handle = AUD_play(limiter, 1);
AUD_unload(limiter);
if(handle->handle)
@@ -424,10 +429,10 @@ void sound_scrub(struct bContext *C)
{
if(cfra >= handle->startframe && cfra < handle->endframe && !handle->mute)
{
- if(handle->source && handle->source->snd_sound)
+ if(handle->source && handle->source->handle)
{
int frameskip = handle->frameskip + cfra - handle->startframe;
- AUD_Sound* limiter = AUD_limitSound(handle->source->cache ? handle->source->cache : handle->source->snd_sound, frameskip / fps, (frameskip + 1)/fps);
+ AUD_Sound* limiter = AUD_limitSound(handle->source->cache ? handle->source->cache : handle->source->handle, frameskip / fps, (frameskip + 1)/fps);
AUD_play(limiter, 0);
AUD_unload(limiter);
}
@@ -450,7 +455,7 @@ AUD_Device* sound_mixdown(struct Scene *scene, AUD_Specs specs, int start, int e
for(handle = scene->sound_handles.first; handle; handle = handle->next)
{
- if(start < handle->endframe && end > handle->startframe && !handle->mute && handle->source && handle->source->snd_sound)
+ if(start < handle->endframe && end > handle->startframe && !handle->mute && handle->source && handle->source->handle)
{
frameskip = handle->frameskip;
s = handle->startframe - start;
@@ -462,7 +467,7 @@ AUD_Device* sound_mixdown(struct Scene *scene, AUD_Specs specs, int start, int e
s = 0;
}
- limiter = AUD_limitSound(handle->source->snd_sound, frameskip / fps, e / fps);
+ limiter = AUD_limitSound(handle->source->handle, frameskip / fps, e / fps);
delayer = AUD_delaySound(limiter, s / fps);
AUD_playDevice(mixdown, delayer);
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index 8e3d59bbc58..dac426de4eb 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -37,14 +37,22 @@
#include "BLI_blenlib.h"
+#include "DNA_action_types.h"
+#include "DNA_armature_types.h"
+#include "DNA_constraint_types.h"
+#include "DNA_controller_types.h"
#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
#include "DNA_text_types.h"
-#include "BKE_utildefines.h"
-#include "BKE_text.h"
-#include "BKE_library.h"
+#include "BKE_depsgraph.h"
#include "BKE_global.h"
+#include "BKE_library.h"
#include "BKE_main.h"
+#include "BKE_node.h"
+#include "BKE_text.h"
+#include "BKE_utildefines.h"
#ifndef DISABLE_PYTHON
#include "BPY_extern.h"
@@ -451,6 +459,85 @@ Text *copy_text(Text *ta)
return tan;
}
+void unlink_text(Main *bmain, Text *text)
+{
+ bScreen *scr;
+ ScrArea *area;
+ SpaceLink *sl;
+ Scene *scene;
+ Object *ob;
+ bController *cont;
+ bConstraint *con;
+ short update;
+
+ /* dome */
+ 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) {
+ if(cont->type==CONT_PYTHON) {
+ bPythonCont *pc;
+
+ pc= cont->data;
+ if(pc->text==text) pc->text= NULL;
+ }
+ }
+
+ /* pyconstraints */
+ update = 0;
+
+ if(ob->type==OB_ARMATURE && ob->pose) {
+ bPoseChannel *pchan;
+ for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
+ for(con = pchan->constraints.first; con; con=con->next) {
+ if(con->type==CONSTRAINT_TYPE_PYTHON) {
+ bPythonConstraint *data = con->data;
+ if (data->text==text) data->text = NULL;
+ update = 1;
+
+ }
+ }
+ }
+ }
+
+ for(con = ob->constraints.first; con; con=con->next) {
+ if(con->type==CONSTRAINT_TYPE_PYTHON) {
+ bPythonConstraint *data = con->data;
+ if (data->text==text) data->text = NULL;
+ update = 1;
+ }
+ }
+
+ if(update)
+ DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
+ }
+
+ /* pynodes */
+ // XXX nodeDynamicUnlinkText(&text->id);
+
+ /* text space */
+ for(scr= bmain->screen.first; scr; scr= scr->id.next) {
+ for(area= scr->areabase.first; area; area= area->next) {
+ for(sl= area->spacedata.first; sl; sl= sl->next) {
+ if(sl->spacetype==SPACE_TEXT) {
+ SpaceText *st= (SpaceText*) sl;
+
+ if(st->text==text) {
+ st->text= NULL;
+ st->top= 0;
+ }
+ }
+ }
+ }
+ }
+
+ text->id.us= 0;
+}
+
+
/*****************************/
/* Editing utility functions */
/*****************************/
diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c
index eeffbfe5ef6..d7616ec8a9a 100644
--- a/source/blender/blenkernel/intern/texture.c
+++ b/source/blender/blenkernel/intern/texture.c
@@ -38,11 +38,12 @@
#include "PIL_dynlib.h"
-#include "MTC_matrixops.h"
+
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
#include "BLI_rand.h"
+#include "BLI_kdopbvh.h"
#include "DNA_texture_types.h"
#include "DNA_key_types.h"
@@ -367,9 +368,9 @@ int do_colorband(ColorBand *coba, float in, float out[4])
CLAMP(fac, 0.0f, 1.0f);
if(coba->ipotype==3)
- set_four_ipo(fac, t, KEY_CARDINAL);
+ key_curve_position_weights(fac, t, KEY_CARDINAL);
else
- set_four_ipo(fac, t, KEY_BSPLINE);
+ key_curve_position_weights(fac, t, KEY_BSPLINE);
out[0]= t[3]*cbd3->r +t[2]*cbd2->r +t[1]*cbd1->r +t[0]*cbd0->r;
out[1]= t[3]*cbd3->g +t[2]*cbd2->g +t[1]*cbd1->g +t[0]*cbd0->g;
@@ -417,6 +418,8 @@ void free_texture(Tex *tex)
free_plugin_tex(tex->plugin);
if(tex->coba) MEM_freeN(tex->coba);
if(tex->env) BKE_free_envmap(tex->env);
+ if(tex->pd) BKE_free_pointdensity(tex->pd);
+ if(tex->vd) BKE_free_voxeldata(tex->vd);
BKE_previewimg_free(&tex->preview);
BKE_icon_delete((struct ID*)tex);
tex->id.icon_id = 0;
@@ -486,6 +489,16 @@ void default_tex(Tex *tex)
tex->env->depth=0;
}
+ if (tex->pd) {
+ tex->pd->radius = 0.3f;
+ tex->pd->falloff_type = TEX_PD_FALLOFF_STD;
+ }
+
+ if (tex->vd) {
+ tex->vd->resol[0] = tex->vd->resol[1] = tex->vd->resol[2] = 0;
+ tex->vd->interp_type=TEX_VD_LINEAR;
+ tex->vd->file_format=TEX_VD_SMOKE;
+ }
pit = tex->plugin;
if (pit) {
varstr= pit->varstr;
@@ -737,9 +750,9 @@ void make_local_texture(Tex *tex)
void autotexname(Tex *tex)
{
- char texstr[20][12]= {"None" , "Clouds" , "Wood", "Marble", "Magic" , "Blend",
+ char texstr[20][15]= {"None" , "Clouds" , "Wood", "Marble", "Magic" , "Blend",
"Stucci", "Noise" , "Image", "Plugin", "EnvMap" , "Musgrave",
- "Voronoi", "DistNoise", "", "", "", "", "", ""};
+ "Voronoi", "DistNoise", "Point Density", "Voxel Data", "", "", "", ""};
Image *ima;
char di[FILE_MAXDIR], fi[FILE_MAXFILE];
@@ -888,6 +901,106 @@ void BKE_free_envmap(EnvMap *env)
}
/* ------------------------------------------------------------------------- */
+
+PointDensity *BKE_add_pointdensity(void)
+{
+ PointDensity *pd;
+
+ pd= MEM_callocN(sizeof(PointDensity), "pointdensity");
+ pd->flag = 0;
+ pd->radius = 0.3f;
+ pd->falloff_type = TEX_PD_FALLOFF_STD;
+ pd->falloff_softness = 2.0;
+ pd->source = TEX_PD_PSYS;
+ pd->point_tree = NULL;
+ pd->point_data = NULL;
+ pd->noise_size = 0.5f;
+ pd->noise_depth = 1;
+ pd->noise_fac = 1.0f;
+ pd->noise_influence = TEX_PD_NOISE_STATIC;
+ pd->coba = add_colorband(1);
+ pd->speed_scale = 1.0f;
+ pd->totpoints = 0;
+ pd->coba = add_colorband(1);
+ pd->object = NULL;
+ pd->psys = NULL;
+ return pd;
+}
+
+PointDensity *BKE_copy_pointdensity(PointDensity *pd)
+{
+ PointDensity *pdn;
+
+ pdn= MEM_dupallocN(pd);
+ pdn->point_tree = NULL;
+ pdn->point_data = NULL;
+ if(pdn->coba) pdn->coba= MEM_dupallocN(pdn->coba);
+
+ return pdn;
+}
+
+void BKE_free_pointdensitydata(PointDensity *pd)
+{
+ if (pd->point_tree) {
+ BLI_bvhtree_free(pd->point_tree);
+ pd->point_tree = NULL;
+ }
+ if (pd->point_data) {
+ MEM_freeN(pd->point_data);
+ pd->point_data = NULL;
+ }
+ if(pd->coba) MEM_freeN(pd->coba);
+}
+
+void BKE_free_pointdensity(PointDensity *pd)
+{
+ BKE_free_pointdensitydata(pd);
+ MEM_freeN(pd);
+}
+
+
+void BKE_free_voxeldatadata(struct VoxelData *vd)
+{
+ if (vd->dataset) {
+ MEM_freeN(vd->dataset);
+ vd->dataset = NULL;
+ }
+
+}
+
+void BKE_free_voxeldata(struct VoxelData *vd)
+{
+ BKE_free_voxeldatadata(vd);
+ MEM_freeN(vd);
+}
+
+struct VoxelData *BKE_add_voxeldata(void)
+{
+ VoxelData *vd;
+
+ vd= MEM_callocN(sizeof(struct VoxelData), "voxeldata");
+ vd->dataset = NULL;
+ vd->resol[0] = vd->resol[1] = vd->resol[2] = 1;
+ vd->interp_type= TEX_VD_LINEAR;
+ vd->file_format= TEX_VD_SMOKE;
+ vd->int_multiplier = 1.0;
+ vd->object = NULL;
+
+ return vd;
+ }
+
+struct VoxelData *BKE_copy_voxeldata(struct VoxelData *vd)
+{
+ VoxelData *vdn;
+
+ vdn= MEM_dupallocN(vd);
+ vdn->dataset = NULL;
+
+ return vdn;
+}
+
+
+/* ------------------------------------------------------------------------- */
int BKE_texture_dependsOnTime(const struct Tex *texture)
{
if(texture->plugin) {
diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c
index e56d8f173e5..f8e3b3c5ad2 100644
--- a/source/blender/blenkernel/intern/unit.c
+++ b/source/blender/blenkernel/intern/unit.c
@@ -317,11 +317,14 @@ static int ch_is_op(char op)
case '*':
case '/':
case '|':
+ case '&':
+ case '~':
case '<':
case '>':
case '^':
case '!':
case '=':
+ case '%':
return 1;
default:
return 0;