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:
authorJoseph Eagar <joeedh@gmail.com>2011-04-15 05:19:13 +0400
committerJoseph Eagar <joeedh@gmail.com>2011-04-15 05:19:13 +0400
commitc98148a963d37fc2f25e125afeb4cf21df6fbf14 (patch)
tree691a051e27f08e35bf09d35b6fb9c88e4c37b8d2 /source/blender/blenkernel
parent0bba684d08952d0be822f3906ffb2a03b2674cc2 (diff)
parentfa63c297753636c149fbb1a3877d9b3d93601357 (diff)
=bmesh= merge from trunk at r36153
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_DerivedMesh.h2
-rw-r--r--source/blender/blenkernel/BKE_action.h8
-rw-r--r--source/blender/blenkernel/BKE_animsys.h3
-rw-r--r--source/blender/blenkernel/BKE_blender.h10
-rw-r--r--source/blender/blenkernel/BKE_curve.h2
-rw-r--r--source/blender/blenkernel/BKE_customdata_file.h4
-rw-r--r--source/blender/blenkernel/BKE_depsgraph.h2
-rw-r--r--source/blender/blenkernel/BKE_fcurve.h4
-rw-r--r--source/blender/blenkernel/BKE_global.h1
-rwxr-xr-xsource/blender/blenkernel/BKE_idcode.h8
-rw-r--r--source/blender/blenkernel/BKE_idprop.h30
-rw-r--r--source/blender/blenkernel/BKE_mesh.h21
-rw-r--r--source/blender/blenkernel/BKE_modifier.h2
-rw-r--r--source/blender/blenkernel/BKE_node.h2
-rw-r--r--source/blender/blenkernel/BKE_object.h4
-rw-r--r--source/blender/blenkernel/BKE_paint.h9
-rw-r--r--source/blender/blenkernel/BKE_particle.h63
-rw-r--r--source/blender/blenkernel/BKE_report.h2
-rw-r--r--source/blender/blenkernel/BKE_scene.h12
-rw-r--r--source/blender/blenkernel/BKE_screen.h5
-rw-r--r--source/blender/blenkernel/BKE_sequencer.h3
-rw-r--r--source/blender/blenkernel/BKE_sound.h2
-rw-r--r--source/blender/blenkernel/BKE_texture.h1
-rw-r--r--source/blender/blenkernel/CMakeLists.txt2
-rw-r--r--source/blender/blenkernel/depsgraph_private.h5
-rw-r--r--source/blender/blenkernel/intern/BME_Customdata.c5
-rw-r--r--source/blender/blenkernel/intern/BME_conversions.c5
-rw-r--r--source/blender/blenkernel/intern/BME_eulers.c5
-rw-r--r--source/blender/blenkernel/intern/BME_mesh.c5
-rw-r--r--source/blender/blenkernel/intern/BME_structure.c5
-rw-r--r--source/blender/blenkernel/intern/BME_tools.c5
-rw-r--r--source/blender/blenkernel/intern/CCGSubSurf.c72
-rw-r--r--source/blender/blenkernel/intern/CCGSubSurf.h3
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.c17
-rw-r--r--source/blender/blenkernel/intern/action.c39
-rw-r--r--source/blender/blenkernel/intern/anim.c13
-rw-r--r--source/blender/blenkernel/intern/anim_sys.c86
-rw-r--r--source/blender/blenkernel/intern/armature.c23
-rw-r--r--source/blender/blenkernel/intern/blender.c26
-rw-r--r--source/blender/blenkernel/intern/bmesh_private.h5
-rw-r--r--source/blender/blenkernel/intern/bmfont.c5
-rw-r--r--source/blender/blenkernel/intern/boids.c74
-rw-r--r--source/blender/blenkernel/intern/booleanops_mesh.c7
-rw-r--r--source/blender/blenkernel/intern/brush.c97
-rw-r--r--source/blender/blenkernel/intern/bullet.c5
-rw-r--r--source/blender/blenkernel/intern/bvhutils.c25
-rw-r--r--source/blender/blenkernel/intern/cdderivedmesh.c107
-rw-r--r--source/blender/blenkernel/intern/cloth.c5
-rw-r--r--source/blender/blenkernel/intern/collision.c5
-rw-r--r--source/blender/blenkernel/intern/colortools.c25
-rw-r--r--source/blender/blenkernel/intern/constraint.c62
-rw-r--r--source/blender/blenkernel/intern/context.c9
-rw-r--r--source/blender/blenkernel/intern/curve.c135
-rw-r--r--source/blender/blenkernel/intern/customdata.c112
-rw-r--r--source/blender/blenkernel/intern/customdata_file.c13
-rw-r--r--source/blender/blenkernel/intern/deform.c5
-rw-r--r--source/blender/blenkernel/intern/depsgraph.c13
-rw-r--r--source/blender/blenkernel/intern/displist.c21
-rw-r--r--source/blender/blenkernel/intern/editderivedbmesh.c15
-rw-r--r--source/blender/blenkernel/intern/effect.c36
-rw-r--r--source/blender/blenkernel/intern/exotic.c13
-rw-r--r--source/blender/blenkernel/intern/fcurve.c120
-rw-r--r--source/blender/blenkernel/intern/fluidsim.c5
-rw-r--r--source/blender/blenkernel/intern/fmodifier.c11
-rw-r--r--source/blender/blenkernel/intern/font.c51
-rw-r--r--source/blender/blenkernel/intern/gpencil.c5
-rw-r--r--source/blender/blenkernel/intern/group.c5
-rw-r--r--source/blender/blenkernel/intern/icons.c5
-rwxr-xr-xsource/blender/blenkernel/intern/idcode.c10
-rw-r--r--source/blender/blenkernel/intern/idprop.c7
-rw-r--r--source/blender/blenkernel/intern/image.c21
-rw-r--r--source/blender/blenkernel/intern/image_gen.c9
-rw-r--r--source/blender/blenkernel/intern/implicit.c5
-rw-r--r--source/blender/blenkernel/intern/ipo.c7
-rw-r--r--source/blender/blenkernel/intern/key.c31
-rw-r--r--source/blender/blenkernel/intern/lattice.c32
-rw-r--r--source/blender/blenkernel/intern/library.c15
-rw-r--r--source/blender/blenkernel/intern/material.c37
-rw-r--r--source/blender/blenkernel/intern/mball.c57
-rw-r--r--source/blender/blenkernel/intern/mesh.c358
-rw-r--r--source/blender/blenkernel/intern/mesh_validate.c11
-rw-r--r--source/blender/blenkernel/intern/modifier.c5
-rw-r--r--source/blender/blenkernel/intern/multires.c29
-rw-r--r--source/blender/blenkernel/intern/nla.c50
-rw-r--r--source/blender/blenkernel/intern/node.c65
-rw-r--r--source/blender/blenkernel/intern/object.c105
-rw-r--r--source/blender/blenkernel/intern/packedFile.c5
-rw-r--r--source/blender/blenkernel/intern/paint.c5
-rw-r--r--source/blender/blenkernel/intern/particle.c193
-rw-r--r--source/blender/blenkernel/intern/particle_system.c2475
-rw-r--r--source/blender/blenkernel/intern/pointcache.c50
-rw-r--r--source/blender/blenkernel/intern/property.c5
-rw-r--r--source/blender/blenkernel/intern/report.c5
-rw-r--r--source/blender/blenkernel/intern/sca.c5
-rw-r--r--source/blender/blenkernel/intern/scene.c53
-rw-r--r--source/blender/blenkernel/intern/screen.c26
-rw-r--r--source/blender/blenkernel/intern/script.c5
-rwxr-xr-xsource/blender/blenkernel/intern/seqcache.c5
-rw-r--r--source/blender/blenkernel/intern/seqeffects.c138
-rw-r--r--source/blender/blenkernel/intern/sequencer.c83
-rw-r--r--source/blender/blenkernel/intern/shrinkwrap.c7
-rw-r--r--source/blender/blenkernel/intern/sketch.c5
-rw-r--r--source/blender/blenkernel/intern/smoke.c5
-rw-r--r--source/blender/blenkernel/intern/softbody.c5
-rw-r--r--source/blender/blenkernel/intern/sound.c13
-rw-r--r--source/blender/blenkernel/intern/subsurf_ccg.c58
-rw-r--r--source/blender/blenkernel/intern/suggestions.c5
-rw-r--r--source/blender/blenkernel/intern/text.c6
-rw-r--r--source/blender/blenkernel/intern/texture.c83
-rw-r--r--source/blender/blenkernel/intern/unit.c9
-rw-r--r--source/blender/blenkernel/intern/world.c7
-rw-r--r--source/blender/blenkernel/intern/writeavi.c5
-rw-r--r--source/blender/blenkernel/intern/writeffmpeg.c3
-rw-r--r--source/blender/blenkernel/intern/writeframeserver.c3
-rw-r--r--source/blender/blenkernel/nla_private.h5
115 files changed, 3366 insertions, 2272 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h
index ea5b9e8367f..ecf62d49da6 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -295,7 +295,7 @@ struct DerivedMesh {
/* Fill the array (of length .getNumVerts()) with all vertex locations */
void (*getVertCos)(DerivedMesh *dm, float (*cos_r)[3]);
- /* Get vertex normal, undefined if index is not valid */
+ /* Get smooth vertex normal, undefined if index is not valid */
void (*getVertNo)(DerivedMesh *dm, int index, float no_r[3]);
/* Get a map of vertices to faces
diff --git a/source/blender/blenkernel/BKE_action.h b/source/blender/blenkernel/BKE_action.h
index 59da97d8b09..698f0f0fecf 100644
--- a/source/blender/blenkernel/BKE_action.h
+++ b/source/blender/blenkernel/BKE_action.h
@@ -82,9 +82,15 @@ typedef enum eAction_TransformFlags {
ACT_TRANS_ROT = (1<<1),
/* scaling */
ACT_TRANS_SCALE = (1<<2),
+
+ /* strictly not a transform, but custom properties are also
+ * quite often used in modern rigs
+ */
+ ACT_TRANS_PROP = (1<<3),
/* all flags */
- ACT_TRANS_ALL = (ACT_TRANS_LOC|ACT_TRANS_ROT|ACT_TRANS_SCALE),
+ ACT_TRANS_ONLY = (ACT_TRANS_LOC|ACT_TRANS_ROT|ACT_TRANS_SCALE),
+ ACT_TRANS_ALL = (ACT_TRANS_ONLY|ACT_TRANS_PROP)
} eAction_TransformFlags;
/* Return flags indicating which transforms the given object/posechannel has
diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h
index a469d05ee26..348b967f9c4 100644
--- a/source/blender/blenkernel/BKE_animsys.h
+++ b/source/blender/blenkernel/BKE_animsys.h
@@ -72,6 +72,9 @@ void BKE_copy_animdata_id_action(struct ID *id);
/* Make Local */
void BKE_animdata_make_local(struct AnimData *adt);
+/* Re-Assign ID's */
+void BKE_relink_animdata(struct AnimData *adt);
+
/* ************************************* */
/* KeyingSets API */
diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h
index 44ce6060f1b..eae75d58a0a 100644
--- a/source/blender/blenkernel/BKE_blender.h
+++ b/source/blender/blenkernel/BKE_blender.h
@@ -43,17 +43,17 @@ extern "C" {
/* these lines are grep'd, watch out for our not-so-awesome regex
* and keep comment above the defines.
* Use STRINGIFY() rather then defining with quotes */
-#define BLENDER_VERSION 256
-#define BLENDER_SUBVERSION 2
+#define BLENDER_VERSION 257
+#define BLENDER_SUBVERSION 0
#define BLENDER_MINVERSION 250
#define BLENDER_MINSUBVERSION 0
/* used by packaging tools */
/* can be left blank, otherwise a,b,c... etc with no quotes */
-#define BLENDER_VERSION_CHAR a
- /* alpha/beta/rc/releases */
-#define BLENDER_VERSION_CYCLE beta
+#define BLENDER_VERSION_CHAR
+ /* alpha/beta/rc/release, docs use this */
+#define BLENDER_VERSION_CYCLE release
struct ListBase;
struct MemFile;
diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h
index f0c58e0a511..0491116d199 100644
--- a/source/blender/blenkernel/BKE_curve.h
+++ b/source/blender/blenkernel/BKE_curve.h
@@ -51,7 +51,7 @@ struct BevList;
#define SEGMENTSV(nu) ( ((nu)->flagv & CU_NURB_CYCLIC) ? (nu)->pntsv : (nu)->pntsv-1 )
#define CU_DO_TILT(cu, nu) (((nu->flag & CU_2D) && (cu->flag & CU_3D)==0) ? 0 : 1)
-#define CU_DO_RADIUS(cu, nu) ((CU_DO_TILT(cu, nu) || ((cu)->flag & CU_PATH_RADIUS) || (cu)->bevobj || (cu)->ext1!=0.0 || (cu)->ext2!=0.0) ? 1:0)
+#define CU_DO_RADIUS(cu, nu) ((CU_DO_TILT(cu, nu) || ((cu)->flag & CU_PATH_RADIUS) || (cu)->bevobj || (cu)->ext1!=0.0f || (cu)->ext2!=0.0f) ? 1:0)
void unlink_curve( struct Curve *cu);
diff --git a/source/blender/blenkernel/BKE_customdata_file.h b/source/blender/blenkernel/BKE_customdata_file.h
index f97565f23a1..030d46fc1a6 100644
--- a/source/blender/blenkernel/BKE_customdata_file.h
+++ b/source/blender/blenkernel/BKE_customdata_file.h
@@ -44,12 +44,12 @@ void cdf_free(CDataFile *cdf);
int cdf_read_open(CDataFile *cdf, char *filename);
int cdf_read_layer(CDataFile *cdf, CDataFileLayer *blay);
-int cdf_read_data(CDataFile *cdf, int size, void *data);
+int cdf_read_data(CDataFile *cdf, unsigned int size, void *data);
void cdf_read_close(CDataFile *cdf);
int cdf_write_open(CDataFile *cdf, char *filename);
int cdf_write_layer(CDataFile *cdf, CDataFileLayer *blay);
-int cdf_write_data(CDataFile *cdf, int size, void *data);
+int cdf_write_data(CDataFile *cdf, unsigned int size, void *data);
void cdf_write_close(CDataFile *cdf);
void cdf_remove(char *filename);
diff --git a/source/blender/blenkernel/BKE_depsgraph.h b/source/blender/blenkernel/BKE_depsgraph.h
index f78a957cbab..14251fb1762 100644
--- a/source/blender/blenkernel/BKE_depsgraph.h
+++ b/source/blender/blenkernel/BKE_depsgraph.h
@@ -112,7 +112,7 @@ void DAG_scene_update_flags(struct Main *bmain, struct Scene *sce, unsigned int
/* flushes all recalc flags in objects down the dependency tree */
void DAG_scene_flush_update(struct Main *bmain, struct Scene *sce, unsigned int lay, const short do_time);
/* tag objects for update on file load */
-void DAG_on_load_update(struct Main *bmain, const short do_time);
+void DAG_on_visible_update(struct Main *bmain, const short do_time);
/* when setting manual RECALC flags, call this afterwards */
void DAG_ids_flush_update(struct Main *bmain, int time);
diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h
index f81acf4b11e..b791e29a38e 100644
--- a/source/blender/blenkernel/BKE_fcurve.h
+++ b/source/blender/blenkernel/BKE_fcurve.h
@@ -215,10 +215,10 @@ struct FCurve *rna_get_fcurve(struct PointerRNA *ptr, struct PropertyRNA *prop,
int binarysearch_bezt_index(struct BezTriple array[], float frame, int arraylen, short *replace);
/* get the time extents for F-Curve */
-void calc_fcurve_range(struct FCurve *fcu, float *min, float *max);
+void calc_fcurve_range(struct FCurve *fcu, float *min, float *max, const short selOnly);
/* get the bounding-box extents for F-Curve */
-void calc_fcurve_bounds(struct FCurve *fcu, float *xmin, float *xmax, float *ymin, float *ymax);
+void calc_fcurve_bounds(struct FCurve *fcu, float *xmin, float *xmax, float *ymin, float *ymax, const short selOnly);
/* .............. */
diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h
index d83e0e5bc4c..0360acbea32 100644
--- a/source/blender/blenkernel/BKE_global.h
+++ b/source/blender/blenkernel/BKE_global.h
@@ -111,6 +111,7 @@ typedef struct Global {
#define G_DEBUG (1 << 12)
#define G_SCRIPT_AUTOEXEC (1 << 13)
+#define G_SCRIPT_OVERRIDE_PREF (1 << 14) /* when this flag is set ignore the userprefs */
/* #define G_NOFROZEN (1 << 17) also removed */
#define G_GREASEPENCIL (1 << 17)
diff --git a/source/blender/blenkernel/BKE_idcode.h b/source/blender/blenkernel/BKE_idcode.h
index 1b2b3d2ee95..e46ad450c31 100755
--- a/source/blender/blenkernel/BKE_idcode.h
+++ b/source/blender/blenkernel/BKE_idcode.h
@@ -76,4 +76,12 @@ int BKE_idcode_is_linkable(int code);
*/
int BKE_idcode_is_valid(int code);
+/**
+ * Return an ID code and steps the index forward 1.
+ *
+ * @param index, start as 0.
+ * @return the code, 0 when all codes have been returned.
+ */
+int BKE_idcode_iter_step(int *index);
+
#endif
diff --git a/source/blender/blenkernel/BKE_idprop.h b/source/blender/blenkernel/BKE_idprop.h
index e71ad5c8a24..2ba23d4a944 100644
--- a/source/blender/blenkernel/BKE_idprop.h
+++ b/source/blender/blenkernel/BKE_idprop.h
@@ -88,19 +88,19 @@ void IDP_UnlinkID(struct IDProperty *prop);
/*-------- Group Functions -------*/
-/* Sync values from one group to another, only where they match */
+/** Sync values from one group to another, only where they match */
void IDP_SyncGroupValues(struct IDProperty *dest, struct IDProperty *src);
-/*
+/**
replaces all properties with the same name in a destination group from a source group.
*/
void IDP_ReplaceGroupInGroup(struct IDProperty *dest, struct IDProperty *src);
-/*checks if a property with the same name as prop exists, and if so replaces it.
+/** checks if a property with the same name as prop exists, and if so replaces it.
Use this to preserve order!*/
void IDP_ReplaceInGroup(struct IDProperty *group, struct IDProperty *prop);
-/*
+/**
This function has a sanity check to make sure ID properties with the same name don't
get added to the group.
@@ -117,12 +117,12 @@ be reorganized to work properly.
*/
int IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop);
-/*this is the same as IDP_AddToGroup, only you pass an item
+/** this is the same as IDP_AddToGroup, only you pass an item
in the group list to be inserted after.*/
int IDP_InsertToGroup(struct IDProperty *group, struct IDProperty *previous,
struct IDProperty *pnew);
-/*NOTE: this does not free the property!!
+/** \note this does not free the property!!
To free the property, you have to do:
IDP_FreeProperty(prop); //free all subdata
@@ -132,27 +132,27 @@ int IDP_InsertToGroup(struct IDProperty *group, struct IDProperty *previous,
void IDP_RemFromGroup(struct IDProperty *group, struct IDProperty *prop);
IDProperty *IDP_GetPropertyFromGroup(struct IDProperty *prop, const char *name);
-/* same as above but ensure type match */
+/** same as above but ensure type match */
IDProperty *IDP_GetPropertyTypeFromGroup(struct IDProperty *prop, const char *name, const char type);
-/*Get an iterator to iterate over the members of an id property group.
+/** Get an iterator to iterate over the members of an id property group.
Note that this will automatically free the iterator once iteration is complete;
if you stop the iteration before hitting the end, make sure to call
IDP_FreeIterBeforeEnd().*/
void *IDP_GetGroupIterator(struct IDProperty *prop);
-/*Returns the next item in the iteration. To use, simple for a loop like the following:
+/** Returns the next item in the iteration. To use, simple for a loop like the following:
while (IDP_GroupIterNext(iter) != NULL) {
. . .
}*/
IDProperty *IDP_GroupIterNext(void *vself);
-/*Frees the iterator pointed to at vself, only use this if iteration is stopped early;
+/** Frees the iterator pointed to at vself, only use this if iteration is stopped early;
when the iterator hits the end of the list it'll automatially free itself.*/
void IDP_FreeIterBeforeEnd(void *vself);
/*-------- Main Functions --------*/
-/*Get the Group property that contains the id properties for ID id. Set create_if_needed
+/** Get the Group property that contains the id properties for ID id. Set create_if_needed
to create the Group property and attach it to id if it doesn't exist; otherwise
the function will return NULL if there's no Group property attached to the ID.*/
struct IDProperty *IDP_GetProperties(struct ID *id, int create_if_needed);
@@ -160,7 +160,7 @@ struct IDProperty *IDP_CopyProperty(struct IDProperty *prop);
int IDP_EqualsProperties(struct IDProperty *prop1, struct IDProperty *prop2);
-/*
+/**
Allocate a new ID.
This function takes three arguments: the ID property type, a union which defines
@@ -186,13 +186,13 @@ IDP_AddToGroup or MEM_freeN the property, doing anything else might result in
a memory leak.
*/
struct IDProperty *IDP_New(int type, IDPropertyTemplate val, const char *name);
-\
-/*NOTE: this will free all child properties of list arrays and groups!
+
+/** \note this will free all child properties of list arrays and groups!
Also, note that this does NOT unlink anything! Plus it doesn't free
the actual struct IDProperty struct either.*/
void IDP_FreeProperty(struct IDProperty *prop);
-/*Unlinks any struct IDProperty<->ID linkage that might be going on.*/
+/** Unlinks any struct IDProperty<->ID linkage that might be going on.*/
void IDP_UnlinkProperty(struct IDProperty *prop);
#define IDP_Int(prop) ((prop)->data.val)
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 151bb45f663..42c4cb47388 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -61,8 +61,6 @@ struct Scene;
extern "C" {
#endif
-struct EditMesh *BKE_mesh_get_editmesh(struct Mesh *me);
-void BKE_mesh_end_editmesh(struct Mesh *me, struct EditMesh *em);
struct BMesh *BKE_mesh_to_bmesh(struct Mesh *me, struct Object *ob);
/*
@@ -106,17 +104,20 @@ int test_index_face(struct MFace *mface, struct CustomData *mfdata, int mfindex,
struct Mesh *get_mesh(struct Object *ob);
void set_mesh(struct Object *ob, struct Mesh *me);
void mball_to_mesh(struct ListBase *lb, struct Mesh *me);
-int nurbs_to_mdata(struct Object *ob, struct MVert **allvert, int *_totvert,
- struct MEdge **alledge, int *_totedge, struct MFace **allface, int *_totface);
-int nurbs_to_mdata_customdb(struct Object *ob, struct ListBase *dispbase,
- struct MVert **allvert, int *_totvert, struct MEdge **alledge, int *_totedge,
- struct MFace **allface, int *_totface);
+int nurbs_to_mdata(struct Object *ob, struct MVert **allvert, int *totvert,
+ struct MEdge **alledge, int *totedge, struct MFace **allface, struct MLoop **allloop, struct MPoly **allpoly,
+ int *totface, int *totloop, int *totpoly);
+int nurbs_to_mdata_customdb(struct Object *ob, struct ListBase *dispbase, struct MVert **allvert, int *_totvert,
+ struct MEdge **alledge, int *_totedge, struct MFace **allface, struct MLoop **allloop, struct MPoly **allpoly,
+ int *_totface, int *_totloop, int *_totpoly);
void nurbs_to_mesh(struct Object *ob);
void mesh_to_curve(struct Scene *scene, struct Object *ob);
void free_dverts(struct MDeformVert *dvert, int totvert);
void copy_dverts(struct MDeformVert *dst, struct MDeformVert *src, int totvert); /* __NLA */
void mesh_delete_material_index(struct Mesh *me, int index);
void mesh_set_smooth_flag(struct Object *meshOb, int enableSmooth);
+void convert_mfaces_to_mpolys(struct Mesh *mesh);
+void mesh_calc_tessface_normals(struct MVert *mverts, int numVerts,struct MFace *mfaces, int numFaces, float (*faceNors_r)[3]);
/*used for unit testing; compares two meshes, checking only
differences we care about. should be usable with leaf's
@@ -136,7 +137,9 @@ void mesh_strip_loose_edges(struct Mesh *me);
/* Calculate vertex and face normals, face normals are returned in *faceNors_r if non-NULL
* and vertex normals are stored in actual mverts.
*/
-void mesh_calc_normals(struct MVert *mverts, int numVerts, struct MFace *mfaces, int numFaces, float **faceNors_r);
+void mesh_calc_normals(struct MVert *mverts, int numVerts, struct MLoop *mloop,
+ struct MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3],
+ struct MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3]);
/* Return a newly MEM_malloc'd array of all the mesh vertex locations
* (_numVerts_r_ may be NULL) */
@@ -192,7 +195,7 @@ int mesh_center_bounds(struct Mesh *me, float cent[3]);
void mesh_translate(struct Mesh *me, float offset[3], int do_keys);
/* mesh_validate.c */
-int BKE_mesh_validate_arrays(struct Mesh *me, struct MVert *mverts, int totvert, struct MEdge *medges, int totedge, struct MFace *mfaces, int totface, const short do_verbose, const short do_fixes);
+int BKE_mesh_validate_arrays(struct Mesh *me, struct MVert *mverts, unsigned int totvert, struct MEdge *medges, unsigned int totedge, struct MFace *mfaces, unsigned int totface, const short do_verbose, const short do_fixes);
int BKE_mesh_validate(struct Mesh *me, int do_verbose);
int BKE_mesh_validate_dm(struct DerivedMesh *dm);
diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h
index 5f6120509f0..513ee68a101 100644
--- a/source/blender/blenkernel/BKE_modifier.h
+++ b/source/blender/blenkernel/BKE_modifier.h
@@ -306,7 +306,7 @@ int modifier_sameTopology(ModifierData *md);
int modifier_isEnabled(struct Scene *scene, struct ModifierData *md, int required_mode);
void modifier_setError(struct ModifierData *md, const char *format, ...)
#ifdef __GNUC__
-__attribute__ ((format (printf, 2, 3)));
+__attribute__ ((format (printf, 2, 3)))
#endif
;
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 41e41eab78f..a126f405d09 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -168,7 +168,7 @@ void ntreeLocalMerge(struct bNodeTree *localtree, struct bNodeTree *ntree);
void nodeVerifyType(struct bNodeTree *ntree, struct bNode *node);
-void nodeAddToPreview(struct bNode *, float *, int, int);
+void nodeAddToPreview(struct bNode *, float *, int, int, int);
void nodeUnlinkNode(struct bNodeTree *ntree, struct bNode *node);
void nodeUniqueName(struct bNodeTree *ntree, struct bNode *node);
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 3d32ba5a30a..cacfa702f7f 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -136,11 +136,15 @@ int object_insert_ptcache(struct Object *ob);
// void object_delete_ptcache(struct Object *ob, int index);
struct KeyBlock *object_insert_shape_key(struct Scene *scene, struct Object *ob, const char *name, int from_mix);
+int object_is_modified(struct Scene *scene, struct Object *ob);
+
void object_camera_matrix(
struct RenderData *rd, struct Object *camera, int winx, int winy, short field_second,
float winmat[][4], struct rctf *viewplane, float *clipsta, float *clipend, float *lens, float *ycor,
float *viewdx, float *viewdy);
+void object_relink(struct Object *ob);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index e6caae7a954..76f89b5e890 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -32,8 +32,6 @@
* \ingroup bke
*/
-#include "DNA_vec_types.h"
-
struct Brush;
struct MFace;
struct MultireModifierData;
@@ -65,15 +63,12 @@ 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;
- struct Object *ob;
struct KeyBlock *kb;
/* Mesh connectivity */
@@ -99,10 +94,6 @@ typedef struct SculptSession {
struct SculptStroke *stroke;
struct StrokeCache *cache;
-
- struct GPUDrawObject *drawobject;
-
- rcti previous_r;
} SculptSession;
void free_sculptsession(struct Object *ob);
diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index 507adcc5f2d..4dfc53e1734 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -155,19 +155,58 @@ typedef struct ParticleBillboardData
short align, uv_split, anim, split_offset;
} ParticleBillboardData;
+typedef struct ParticleCollisionElement
+{
+ /* pointers to original data */
+ float *x[4], *v[4];
+
+ /* values interpolated from original data*/
+ float x0[3], x1[3], x2[3], p[3];
+
+ /* results for found intersection point */
+ float nor[3], vel[3], uv[2];
+
+ /* count of original data (1-4) */
+ int tot;
+
+ /* index of the collision face */
+ int index;
+
+ /* flags for inversed normal / particle already inside element at start */
+ short inv_nor, inside;
+} ParticleCollisionElement;
+
/* container for moving data between deflet_particle and particle_intersect_face */
typedef struct ParticleCollision
{
- struct Object *ob, *hit_ob; // collided and current objects
- struct CollisionModifierData *md, *hit_md; // collision modifiers for current and hit object;
- float nor[3]; // normal at collision point
- float vel[3]; // velocity of collision point
- float co1[3], co2[3]; // ray start and end points
- float ve1[3], ve2[3]; // particle velocities
- float ray_len; // original length of co2-co1, needed for collision time evaluation
+ struct Object *current;
+ struct Object *hit;
+ struct Object *prev;
+ struct Object *skip;
+ struct Object *emitter;
+
+ struct CollisionModifierData *md; // collision modifier for current object;
+
float f; // time factor of previous collision, needed for substracting face velocity
- float cfra; // start of the timestep (during frame change, since previous integer frame)
- float dfra; // duration of timestep in frames
+ float fac1, fac2;
+
+ float cfra, old_cfra;
+
+ float original_ray_length; //original length of co2-co1, needed for collision time evaluation
+
+ int prev_index;
+
+ ParticleCollisionElement pce;
+
+ float total_time, inv_timestep;
+
+ float radius;
+ float co1[3], co2[3];
+ float ve1[3], ve2[3];
+
+ float acc[3], boid_z;
+
+ int boid;
} ParticleCollision;
typedef struct ParticleDrawData {
@@ -242,7 +281,7 @@ void psys_get_particle_on_path(struct ParticleSimulationData *sim, int pa_num, s
int psys_get_particle_state(struct ParticleSimulationData *sim, int p, struct ParticleKey *state, int always);
/* for anim.c */
-void psys_get_dupli_texture(struct Object *ob, struct ParticleSettings *part, struct ParticleSystemModifierData *psmd, struct ParticleData *pa, struct ChildParticle *cpa, float *uv, float *orco);
+void psys_get_dupli_texture(struct ParticleSystem *psys, struct ParticleSettings *part, struct ParticleSystemModifierData *psmd, struct ParticleData *pa, struct ChildParticle *cpa, float *uv, float *orco);
void psys_get_dupli_path_transform(struct ParticleSimulationData *sim, struct ParticleData *pa, struct ChildParticle *cpa, struct ParticleCacheKey *cache, float mat[][4], float *scale);
ParticleThread *psys_threads_create(struct ParticleSimulationData *sim);
@@ -289,10 +328,8 @@ void psys_interpolate_face(struct MVert *mvert, struct MFace *mface, struct MTFa
float psys_particle_value_from_verts(struct DerivedMesh *dm, short from, struct ParticleData *pa, float *values);
void psys_get_from_key(struct ParticleKey *key, float *loc, float *vel, float *rot, float *time);
-/* only in edisparticle.c*/
-int psys_intersect_dm(struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, float *vert_cos, float *co1, float* co2, float *min_d, int *min_face, float *min_uv, float *face_minmax, float *pa_minmax, float radius, float *ipoint);
/* BLI_bvhtree_ray_cast callback */
-void particle_intersect_face(void *userdata, int index, const struct BVHTreeRay *ray, struct BVHTreeRayHit *hit);
+void BKE_psys_collision_neartest_cb(void *userdata, int index, const struct BVHTreeRay *ray, struct BVHTreeRayHit *hit);
void psys_particle_on_dm(struct DerivedMesh *dm, int from, int index, int index_dmcache, float *fw, float foffset, float *vec, float *nor, float *utan, float *vtan, float *orco, float *ornor);
/* particle_system.c */
diff --git a/source/blender/blenkernel/BKE_report.h b/source/blender/blenkernel/BKE_report.h
index 397c96422a5..253f3ea9ac1 100644
--- a/source/blender/blenkernel/BKE_report.h
+++ b/source/blender/blenkernel/BKE_report.h
@@ -51,7 +51,7 @@ void BKE_reports_clear(ReportList *reports);
void BKE_report(ReportList *reports, ReportType type, const char *message);
void BKE_reportf(ReportList *reports, ReportType type, const char *format, ...)
#ifdef __GNUC__
-__attribute__ ((format (printf, 3, 4)));
+__attribute__ ((format (printf, 3, 4)))
#endif
;
diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h
index ac85f91bf46..943712167c6 100644
--- a/source/blender/blenkernel/BKE_scene.h
+++ b/source/blender/blenkernel/BKE_scene.h
@@ -50,10 +50,11 @@ struct Scene;
struct Text;
struct Text;
-#define SCE_COPY_EMPTY 0
-#define SCE_COPY_LINK_OB 1
-#define SCE_COPY_LINK_DATA 2
-#define SCE_COPY_FULL 3
+#define SCE_COPY_NEW 0
+#define SCE_COPY_EMPTY 1
+#define SCE_COPY_LINK_OB 2
+#define SCE_COPY_LINK_DATA 3
+#define SCE_COPY_FULL 4
#define SETLOOPER(_sce_basis, _sce_iter, _base) _sce_iter= _sce_basis, _base= _setlooper_base_step(&_sce_iter, NULL); _base; _base= _setlooper_base_step(&_sce_iter, _base)
struct Base *_setlooper_base_step(struct Scene **sce_iter, struct Base *base);
@@ -78,9 +79,6 @@ int scene_camera_switch_update(struct Scene *scene);
char *scene_find_marker_name(struct Scene *scene, int frame);
char *scene_find_last_marker_name(struct Scene *scene, int frame);
-int scene_marker_tfm_translate(struct Scene *scene, int delta, int flag);
-int scene_marker_tfm_extend(struct Scene *scene, int delta, int flag, int frame, char side);
-int scene_marker_tfm_scale(struct Scene *scene, float value, int flag);
struct Base *scene_add_base(struct Scene *sce, struct Object *ob);
void scene_deselect_all(struct Scene *sce);
diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index 0a7d9780a6b..56b0cd63e01 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -112,7 +112,7 @@ typedef struct SpaceType {
typedef struct ARegionType {
struct ARegionType *next, *prev;
- int regionid; /* unique identifier within this space */
+ int regionid; /* unique identifier within this space, defines RGN_TYPE_xxxx */
/* add handlers, stuff you only do once or on area/region type/size changes */
void (*init)(struct wmWindowManager *, struct ARegion *);
@@ -152,6 +152,8 @@ typedef struct ARegionType {
int prefsizex, prefsizey;
/* default keymaps to add */
int keymapflag;
+ /* return without drawing. lock is set by region definition, and copied to do_lock by render. can become flag */
+ short do_lock, lock;
} ARegionType;
/* panel types */
@@ -231,6 +233,7 @@ void BKE_spacetypes_free(void); /* only for quitting blender */
/* spacedata */
void BKE_spacedata_freelist(ListBase *lb);
void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2);
+void BKE_spacedata_draw_locks(int set);
/* area/regions */
struct ARegion *BKE_area_region_copy(struct SpaceType *st, struct ARegion *ar);
diff --git a/source/blender/blenkernel/BKE_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h
index cc1d8537cbd..33bff1cd6a7 100644
--- a/source/blender/blenkernel/BKE_sequencer.h
+++ b/source/blender/blenkernel/BKE_sequencer.h
@@ -258,6 +258,7 @@ int seq_single_check(struct Sequence *seq);
void seq_single_fix(struct Sequence *seq);
int seq_test_overlap(struct ListBase * seqbasep, struct Sequence *test);
void seq_translate(struct Scene *scene, struct Sequence *seq, int delta);
+void seq_sound_init(struct Scene *scene, struct Sequence *seq);
struct Sequence *seq_foreground_frame_get(struct Scene *scene, int frame);
struct ListBase *seq_seqbase(struct ListBase *seqbase, struct Sequence *seq);
void seq_offset_animdata(struct Scene *scene, struct Sequence *seq, int ofs);
@@ -322,7 +323,7 @@ struct Sequence *sequencer_add_sound_strip(struct bContext *C, ListBase *seqbase
struct Sequence *sequencer_add_movie_strip(struct bContext *C, ListBase *seqbasep, struct SeqLoadInfo *seq_load);
/* view3d draw callback, run when not in background view */
-typedef struct ImBuf *(*SequencerDrawView)(struct Scene *, int, int, unsigned int, int);
+typedef struct ImBuf *(*SequencerDrawView)(struct Scene *, int, int, unsigned int, int, char[256]);
extern SequencerDrawView sequencer_view3d_cb;
/* copy/paste */
diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h
index acd4718a65a..04597fd666e 100644
--- a/source/blender/blenkernel/BKE_sound.h
+++ b/source/blender/blenkernel/BKE_sound.h
@@ -78,6 +78,8 @@ void sound_create_scene(struct Scene *scene);
void sound_destroy_scene(struct Scene *scene);
+void sound_mute_scene(struct Scene *scene, int muted);
+
void* sound_scene_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip);
void* sound_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip);
diff --git a/source/blender/blenkernel/BKE_texture.h b/source/blender/blenkernel/BKE_texture.h
index e6a21ec3966..c8fa7a5e81f 100644
--- a/source/blender/blenkernel/BKE_texture.h
+++ b/source/blender/blenkernel/BKE_texture.h
@@ -81,6 +81,7 @@ void default_mtex(struct MTex *mtex);
struct MTex *add_mtex(void);
struct MTex *add_mtex_id(struct ID *id, int slot);
struct Tex *copy_texture(struct Tex *tex);
+struct Tex *localize_texture(struct Tex *tex);
void make_local_texture(struct Tex *tex);
void autotexname(struct Tex *tex);
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index dc485f5dc5f..a5a4f72523c 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -39,7 +39,6 @@ set(INC
../nodes
../editors/include
../render/extern/include
- ../../../extern/glew/include
../../../intern/audaspace/intern
../../../intern/bsp/extern ../blenfont
../../../intern/decimation/extern
@@ -51,6 +50,7 @@ set(INC
../../../intern/smoke/extern
../../../intern/mikktspace
../../../source/blender/windowmanager # XXX - BAD LEVEL CALL WM_api.h
+ ${GLEW_INCLUDE_PATH}
${ZLIB_INCLUDE_DIRS}
)
diff --git a/source/blender/blenkernel/depsgraph_private.h b/source/blender/blenkernel/depsgraph_private.h
index 4f99dacbc08..1fed115893c 100644
--- a/source/blender/blenkernel/depsgraph_private.h
+++ b/source/blender/blenkernel/depsgraph_private.h
@@ -24,6 +24,11 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
+
+/** \file blender/blenkernel/depsgraph_private.h
+ * \ingroup bke
+ */
+
#ifndef DEPSGRAPH_PRIVATE
#define DEPSGRAPH_PRIVATE
diff --git a/source/blender/blenkernel/intern/BME_Customdata.c b/source/blender/blenkernel/intern/BME_Customdata.c
index f8b432ed384..503470bb89a 100644
--- a/source/blender/blenkernel/intern/BME_Customdata.c
+++ b/source/blender/blenkernel/intern/BME_Customdata.c
@@ -36,6 +36,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/BME_Customdata.c
+ * \ingroup bke
+ */
+
+
#include <string.h>
#include "MEM_guardedalloc.h"
diff --git a/source/blender/blenkernel/intern/BME_conversions.c b/source/blender/blenkernel/intern/BME_conversions.c
index 8c399e88d67..65b0c3797d9 100644
--- a/source/blender/blenkernel/intern/BME_conversions.c
+++ b/source/blender/blenkernel/intern/BME_conversions.c
@@ -34,6 +34,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/BME_conversions.c
+ * \ingroup bke
+ */
+
+
#include "MEM_guardedalloc.h"
#include "DNA_meshdata_types.h"
diff --git a/source/blender/blenkernel/intern/BME_eulers.c b/source/blender/blenkernel/intern/BME_eulers.c
index 6897b0c8990..85007889e0a 100644
--- a/source/blender/blenkernel/intern/BME_eulers.c
+++ b/source/blender/blenkernel/intern/BME_eulers.c
@@ -34,6 +34,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/BME_eulers.c
+ * \ingroup bke
+ */
+
+
#include "MEM_guardedalloc.h"
#include "BLI_utildefines.h"
diff --git a/source/blender/blenkernel/intern/BME_mesh.c b/source/blender/blenkernel/intern/BME_mesh.c
index 1097b9da2bc..171b818ec49 100644
--- a/source/blender/blenkernel/intern/BME_mesh.c
+++ b/source/blender/blenkernel/intern/BME_mesh.c
@@ -34,6 +34,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/BME_mesh.c
+ * \ingroup bke
+ */
+
+
#include "MEM_guardedalloc.h"
#include "BKE_bmesh.h"
diff --git a/source/blender/blenkernel/intern/BME_structure.c b/source/blender/blenkernel/intern/BME_structure.c
index f79b8edc866..de6ee53f048 100644
--- a/source/blender/blenkernel/intern/BME_structure.c
+++ b/source/blender/blenkernel/intern/BME_structure.c
@@ -34,6 +34,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
#if 0
+/** \file blender/blenkernel/intern/BME_structure.c
+ * \ingroup bke
+ */
+
+
#include <limits.h>
#include "MEM_guardedalloc.h"
diff --git a/source/blender/blenkernel/intern/BME_tools.c b/source/blender/blenkernel/intern/BME_tools.c
index 8efc2d0e955..653330d03f4 100644
--- a/source/blender/blenkernel/intern/BME_tools.c
+++ b/source/blender/blenkernel/intern/BME_tools.c
@@ -33,6 +33,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/BME_tools.c
+ * \ingroup bke
+ */
+
+
#include <math.h>
#include "MEM_guardedalloc.h"
diff --git a/source/blender/blenkernel/intern/CCGSubSurf.c b/source/blender/blenkernel/intern/CCGSubSurf.c
index 3564c93681a..a311ca15e5e 100644
--- a/source/blender/blenkernel/intern/CCGSubSurf.c
+++ b/source/blender/blenkernel/intern/CCGSubSurf.c
@@ -1,3 +1,6 @@
+/** \file blender/blenkernel/intern/CCGSubSurf.c
+ * \ingroup bke
+ */
/* $Id$ */
#include <stdlib.h>
@@ -226,9 +229,9 @@ static int VertDataEqual(float *a, float *b) {
#define VertDataAvg4(tv, av, bv, cv, dv) \
{ \
float *_t = (float*) tv, *_a = (float*) av, *_b = (float*) bv, *_c = (float*) cv, *_d = (float*) dv; \
- _t[0] = (_a[0]+_b[0]+_c[0]+_d[0])*.25; \
- _t[1] = (_a[1]+_b[1]+_c[1]+_d[1])*.25; \
- _t[2] = (_a[2]+_b[2]+_c[2]+_d[2])*.25; \
+ _t[0] = (_a[0]+_b[0]+_c[0]+_d[0])*.25f; \
+ _t[1] = (_a[1]+_b[1]+_c[1]+_d[1])*.25f; \
+ _t[2] = (_a[2]+_b[2]+_c[2]+_d[2])*.25f; \
}
#define NormZero(av) { float *_a = (float*) av; _a[0] = _a[1] = _a[2] = 0.0f; }
#define NormCopy(av, bv) { float *_a = (float*) av, *_b = (float*) bv; _a[0] =_b[0]; _a[1] =_b[1]; _a[2] =_b[2]; }
@@ -504,9 +507,9 @@ static float EDGE_getSharpness(CCGEdge *e, int lvl) {
if (!lvl)
return e->crease;
else if (!e->crease)
- return 0.0;
- else if (e->crease - lvl < 0.0)
- return 0.0;
+ return 0.0f;
+ else if (e->crease - lvl < 0.0f)
+ return 0.0f;
else
return e->crease - lvl;
}
@@ -1339,6 +1342,17 @@ static void ccgSubSurf__calcVertNormals(CCGSubSurf *ss,
NormCopy(EDGE_getNo(e, lvl, x),
_face_getIFNoEdge(f, e, lvl, x, 0, subdivLevels, vertDataSize, normalDataOffset));
}
+ else {
+ /* set to zero here otherwise the normals are uninitialized memory
+ * render: tests/animation/knight.blend with valgrind.
+ * we could be more clever and interpolate vertex normals but these are
+ * most likely not used so just zero out. */
+ int x;
+
+ for (x=0; x<edgeSize; x++) {
+ NormZero(EDGE_getNo(e, lvl, x));
+ }
+ }
}
}
#undef FACE_getIFNo
@@ -1444,7 +1458,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
float sharpness = EDGE_getSharpness(e, curLvl);
int x, j;
- if (_edge_isBoundary(e) || sharpness>1.0) {
+ if (_edge_isBoundary(e) || sharpness > 1.0f) {
for (x=0; x<edgeSize-1; x++) {
int fx = x*2 + 1;
void *co0 = EDGE_getCo(e, curLvl, x+0);
@@ -1453,7 +1467,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
VertDataCopy(co, co0);
VertDataAdd(co, co1);
- VertDataMulN(co, 0.5);
+ VertDataMulN(co, 0.5f);
}
} else {
for (x=0; x<edgeSize-1; x++) {
@@ -1476,7 +1490,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
VertDataCopy(r, co0);
VertDataAdd(r, co1);
- VertDataMulN(r, 0.5);
+ VertDataMulN(r, 0.5f);
VertDataCopy(co, q);
VertDataSub(r, q);
@@ -1516,8 +1530,8 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
if(sharpCount) {
avgSharpness /= sharpCount;
- if (avgSharpness>1.0) {
- avgSharpness = 1.0;
+ if (avgSharpness > 1.0f) {
+ avgSharpness = 1.0f;
}
}
@@ -1539,7 +1553,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
}
VertDataCopy(nCo, co);
- VertDataMulN(nCo, 0.75);
+ VertDataMulN(nCo, 0.75f);
VertDataMulN(r, 0.25f/numBoundary);
VertDataAdd(nCo, r);
} else {
@@ -1584,7 +1598,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
if (seam) {
if (_edge_isBoundary(e))
VertDataAdd(q, _edge_getCoVert(e, v, curLvl, 1, vertDataSize));
- } else if (sharpness != 0.0) {
+ } else if (sharpness != 0.0f) {
VertDataAdd(q, _edge_getCoVert(e, v, curLvl, 1, vertDataSize));
}
}
@@ -1601,8 +1615,8 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
// r = co*.75 + q*.25
VertDataCopy(r, co);
- VertDataMulN(r, .75);
- VertDataMulN(q, .25);
+ VertDataMulN(r, .75f);
+ VertDataMulN(q, .25f);
VertDataAdd(r, q);
// nCo = nCo + (r-nCo)*avgSharpness
@@ -1628,8 +1642,8 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
sharpCount = 2;
avgSharpness += sharpness;
- if (avgSharpness>1.0) {
- avgSharpness = 1.0;
+ if (avgSharpness > 1.0f) {
+ avgSharpness = 1.0f;
}
} else {
sharpCount = 0;
@@ -1643,10 +1657,10 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
void *nCo = EDGE_getCo(e, nextLvl, fx);
VertDataCopy(r, EDGE_getCo(e, curLvl, x-1));
VertDataAdd(r, EDGE_getCo(e, curLvl, x+1));
- VertDataMulN(r, 0.5);
+ VertDataMulN(r, 0.5f);
VertDataCopy(nCo, co);
- VertDataMulN(nCo, 0.75);
- VertDataMulN(r, 0.25);
+ VertDataMulN(nCo, 0.75f);
+ VertDataMulN(r, 0.25f);
VertDataAdd(nCo, r);
}
} else {
@@ -1668,8 +1682,8 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
VertDataAdd(r, _face_getIFCoEdge(f, e, curLvl, x, 1, subdivLevels, vertDataSize));
numFaces++;
}
- VertDataMulN(q, 1.0/(numFaces*2.0f));
- VertDataMulN(r, 1.0/(2.0f + numFaces));
+ VertDataMulN(q, 1.0f/(numFaces*2.0f));
+ VertDataMulN(r, 1.0f/(2.0f + numFaces));
VertDataCopy(nCo, co);
VertDataMulN(nCo, (float) numFaces);
@@ -1892,7 +1906,7 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
void *co = EDGE_getCo(e, nextLvl, 1);
float sharpness = EDGE_getSharpness(e, curLvl);
- if (_edge_isBoundary(e) || sharpness>=1.0) {
+ if (_edge_isBoundary(e) || sharpness >= 1.0f) {
VertDataCopy(co, VERT_getCo(e->v0, curLvl));
VertDataAdd(co, VERT_getCo(e->v1, curLvl));
VertDataMulN(co, 0.5f);
@@ -1944,8 +1958,8 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
if(sharpCount) {
avgSharpness /= sharpCount;
- if (avgSharpness>1.0) {
- avgSharpness = 1.0;
+ if (avgSharpness > 1.0f) {
+ avgSharpness = 1.0f;
}
}
@@ -1966,7 +1980,7 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
}
}
VertDataCopy(nCo, co);
- VertDataMulN(nCo, 0.75);
+ VertDataMulN(nCo, 0.75f);
VertDataMulN(r, 0.25f/numBoundary);
VertDataAdd(nCo, r);
} else {
@@ -2012,7 +2026,7 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
CCGVert *oV = _edge_getOtherVert(e, v);
VertDataAdd(q, VERT_getCo(oV, curLvl));
}
- } else if (sharpness != 0.0) {
+ } else if (sharpness != 0.0f) {
CCGVert *oV = _edge_getOtherVert(e, v);
VertDataAdd(q, VERT_getCo(oV, curLvl));
}
@@ -2030,8 +2044,8 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
// r = co*.75 + q*.25
VertDataCopy(r, co);
- VertDataMulN(r, .75);
- VertDataMulN(q, .25);
+ VertDataMulN(r, 0.75f);
+ VertDataMulN(q, 0.25f);
VertDataAdd(r, q);
// nCo = nCo + (r-nCo)*avgSharpness
diff --git a/source/blender/blenkernel/intern/CCGSubSurf.h b/source/blender/blenkernel/intern/CCGSubSurf.h
index 34d684221b0..363d1e01f98 100644
--- a/source/blender/blenkernel/intern/CCGSubSurf.h
+++ b/source/blender/blenkernel/intern/CCGSubSurf.h
@@ -1,3 +1,6 @@
+/** \file blender/blenkernel/intern/CCGSubSurf.h
+ * \ingroup bke
+ */
/* $Id$ */
typedef void* CCGMeshHDL;
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 3ed8c0f091a..6a6a56baff6 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/DerivedMesh.c
+ * \ingroup bke
+ */
+
+
#include <string.h>
@@ -827,12 +832,12 @@ void weight_to_rgb(float input, float *fr, float *fg, float *fb)
*fg= blend;
*fb= blend*(1.0f-((input-0.25f)*4.0f));
}
- else if (input<=0.75){ // green->yellow
+ else if (input <= 0.75f){ // green->yellow
*fr= blend * ((input-0.50f)*4.0f);
*fg= blend;
*fb= 0.0f;
}
- else if (input<=1.0){ // yellow->red
+ else if (input <= 1.0f){ // yellow->red
*fr= blend;
*fg= blend * (1.0f-((input-0.75f)*4.0f));
*fb= 0.0f;
@@ -1840,11 +1845,9 @@ static void GetNormal(const SMikkTSpaceContext * pContext, float fNorm[], const
}
else
{
- int i=0;
- short * no = pMesh->mvert[indices[vert_index]].no;
- for(i=0; i<3; i++)
- fNorm[i]=no[i]/32767.0f;
- normalize_v3(fNorm);
+ short *no = pMesh->mvert[indices[vert_index]].no;
+ normal_short_to_float_v3(fNorm, no);
+ normalize_v3(fNorm); /* XXX, is this needed */
}
}
static void SetTSpace(const SMikkTSpaceContext * pContext, const float fvTangent[], const float fSign, const int face_num, const int iVert)
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index 14a0f71f824..5b42948072f 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -26,6 +26,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/action.c
+ * \ingroup bke
+ */
+
+
#include <string.h>
#include <math.h>
#include <stdlib.h>
@@ -862,7 +867,8 @@ void calc_action_range(const bAction *act, float *start, float *end, short incl_
float nmin, nmax;
/* get extents for this curve */
- calc_fcurve_range(fcu, &nmin, &nmax);
+ // TODO: allow enabling/disabling this?
+ calc_fcurve_range(fcu, &nmin, &nmax, FALSE);
/* compare to the running tally */
min= MIN2(min, nmin);
@@ -968,6 +974,11 @@ short action_get_item_transforms (bAction *act, Object *ob, bPoseChannel *pchan,
bPtr= strstr(fcu->rna_path, basePath);
if (bPtr) {
+ /* we must add len(basePath) bytes to the match so that we are at the end of the
+ * base path so that we don't get false positives with these strings in the names
+ */
+ bPtr += strlen(basePath);
+
/* step 2: check for some property with transforms
* - to speed things up, only check for the ones not yet found
* unless we're getting the curves too
@@ -976,8 +987,8 @@ short action_get_item_transforms (bAction *act, Object *ob, bPoseChannel *pchan,
* - once a match has been found, the curve cannot possibly be any other one
*/
if ((curves) || (flags & ACT_TRANS_LOC) == 0) {
- pPtr= strstr(fcu->rna_path, "location");
- if ((pPtr) && (pPtr >= bPtr)) {
+ pPtr= strstr(bPtr, "location");
+ if (pPtr) {
flags |= ACT_TRANS_LOC;
if (curves)
@@ -987,8 +998,8 @@ short action_get_item_transforms (bAction *act, Object *ob, bPoseChannel *pchan,
}
if ((curves) || (flags & ACT_TRANS_SCALE) == 0) {
- pPtr= strstr(fcu->rna_path, "scale");
- if ((pPtr) && (pPtr >= bPtr)) {
+ pPtr= strstr(bPtr, "scale");
+ if (pPtr) {
flags |= ACT_TRANS_SCALE;
if (curves)
@@ -998,8 +1009,8 @@ short action_get_item_transforms (bAction *act, Object *ob, bPoseChannel *pchan,
}
if ((curves) || (flags & ACT_TRANS_ROT) == 0) {
- pPtr= strstr(fcu->rna_path, "rotation");
- if ((pPtr) && (pPtr >= bPtr)) {
+ pPtr= strstr(bPtr, "rotation");
+ if (pPtr) {
flags |= ACT_TRANS_ROT;
if (curves)
@@ -1007,6 +1018,18 @@ short action_get_item_transforms (bAction *act, Object *ob, bPoseChannel *pchan,
continue;
}
}
+
+ if ((curves) || (flags & ACT_TRANS_PROP) == 0) {
+ /* custom properties only */
+ pPtr= strstr(bPtr, "[\""); /* extra '"' comment here to keep my texteditor functionlist working :) */
+ if (pPtr) {
+ flags |= ACT_TRANS_PROP;
+
+ if (curves)
+ BLI_addtail(curves, BLI_genericNodeN(fcu));
+ continue;
+ }
+ }
}
}
@@ -1066,7 +1089,7 @@ void copy_pose_result(bPose *to, bPose *from)
bPoseChannel *pchanto, *pchanfrom;
if(to==NULL || from==NULL) {
- printf("pose result copy error to:%p from:%p\n", to, from); // debug temp
+ printf("pose result copy error to:%p from:%p\n", (void *)to, (void *)from); // debug temp
return;
}
diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c
index 5842197da48..ec74391533b 100644
--- a/source/blender/blenkernel/intern/anim.c
+++ b/source/blender/blenkernel/intern/anim.c
@@ -29,6 +29,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/anim.c
+ * \ingroup bke
+ */
+
+
#include <stdio.h>
#include <math.h>
#include <string.h>
@@ -1119,7 +1124,7 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
/* scale */
if(par->transflag & OB_DUPLIFACES_SCALE) {
float size= v4? area_quad_v3(v1, v2, v3, v4): area_tri_v3(v1, v2, v3);
- size= sqrt(size) * par->dupfacesca;
+ size= sqrtf(size) * par->dupfacesca;
mul_m3_fl(mat, size);
}
@@ -1340,8 +1345,6 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
/* for groups, pick the object based on settings */
if(part->draw&PART_DRAW_RAND_GR)
b= BLI_rand() % totgroup;
- else if(part->from==PART_FROM_PARTICLE)
- b= pa_num % totgroup;
else
b= a % totgroup;
@@ -1396,7 +1399,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
dob= new_dupli_object(lb, go->ob, mat, par->lay, counter, OB_DUPLIPARTS, animated);
copy_m4_m4(dob->omat, obcopylist[b].obmat);
if(G.rendering)
- psys_get_dupli_texture(par, part, sim.psmd, pa, cpa, dob->uv, dob->orco);
+ psys_get_dupli_texture(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco);
}
}
else {
@@ -1428,7 +1431,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
dob= new_dupli_object(lb, ob, mat, ob->lay, counter, GS(id->name) == ID_GR ? OB_DUPLIGROUP : OB_DUPLIPARTS, animated);
copy_m4_m4(dob->omat, oldobmat);
if(G.rendering)
- psys_get_dupli_texture(par, part, sim.psmd, pa, cpa, dob->uv, dob->orco);
+ psys_get_dupli_texture(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco);
}
}
diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c
index 77d0f008c2b..2708239a4c3 100644
--- a/source/blender/blenkernel/intern/anim_sys.c
+++ b/source/blender/blenkernel/intern/anim_sys.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/anim_sys.c
+ * \ingroup bke
+ */
+
+
#include <stdio.h>
#include <string.h>
#include <stddef.h>
@@ -277,6 +282,40 @@ void BKE_animdata_make_local(AnimData *adt)
make_local_strips(&nlt->strips);
}
+
+/* When duplicating data (i.e. objects), drivers referring to the original data will
+ * get updated to point to the duplicated data (if drivers belong to the new data)
+ */
+void BKE_relink_animdata (AnimData *adt)
+{
+ /* sanity check */
+ if (adt == NULL)
+ return;
+
+ /* drivers */
+ if (adt->drivers.first) {
+ FCurve *fcu;
+
+ /* check each driver against all the base paths to see if any should go */
+ for (fcu= adt->drivers.first; fcu; fcu=fcu->next) {
+ ChannelDriver *driver= fcu->driver;
+ DriverVar *dvar;
+
+ /* driver variables */
+ for (dvar= driver->variables.first; dvar; dvar=dvar->next) {
+ /* only change the used targets, since the others will need fixing manually anyway */
+ DRIVER_TARGETS_USED_LOOPER(dvar)
+ {
+ if (dtar->id && dtar->id->newid) {
+ dtar->id= dtar->id->newid;
+ }
+ }
+ DRIVER_TARGETS_LOOPER_END
+ }
+ }
+ }
+}
+
/* Sub-ID Regrouping ------------------------------------------- */
/* helper heuristic for determining if a path is compatible with the basepath
@@ -304,7 +343,7 @@ void action_move_fcurves_by_basepath (bAction *srcAct, bAction *dstAct, const ch
if ELEM3(NULL, srcAct, dstAct, basepath) {
if (G.f & G_DEBUG) {
printf("ERROR: action_partition_fcurves_by_basepath(%p, %p, %p) has insufficient info to work with\n",
- srcAct, dstAct, basepath);
+ (void *)srcAct, (void *)dstAct, (void *)basepath);
}
return;
}
@@ -557,7 +596,7 @@ static void drivers_path_rename_fix (ID *owner_id, const char *prefix, char *old
DRIVER_TARGETS_USED_LOOPER(dvar)
{
/* rename RNA path */
- if (dtar->rna_path)
+ if (dtar->rna_path && dtar->id)
dtar->rna_path= rna_path_rename_fix(dtar->id, prefix, oldKey, newKey, dtar->rna_path, verify_paths);
/* also fix the bone-name (if applicable) */
@@ -1808,23 +1847,19 @@ void nladata_flush_channels (ListBase *channels)
/* ---------------------- */
-/* NLA Evaluation function (mostly for use through do_animdata)
- * - All channels that will be affected are not cleared anymore. Instead, we just evaluate into
- * some temp channels, where values can be accumulated in one go.
+/* NLA Evaluation function - values are calculated and stored in temporary "NlaEvalChannels"
+ * ! This is exported so that keyframing code can use this for make use of it for anim layers support
+ * > echannels: (list<NlaEvalChannels>) evaluation channels with calculated values
*/
-static void animsys_evaluate_nla (PointerRNA *ptr, AnimData *adt, float ctime)
+static void animsys_evaluate_nla (ListBase *echannels, PointerRNA *ptr, AnimData *adt, float ctime)
{
NlaTrack *nlt;
short track_index=0;
short has_strips = 0;
ListBase estrips= {NULL, NULL};
- ListBase echannels= {NULL, NULL};
NlaEvalStrip *nes;
- // TODO: need to zero out all channels used, otherwise we have problems with threadsafety
- // and also when the user jumps between different times instead of moving sequentially...
-
/* 1. get the stack of strips to evaluate at current time (influence calculated here) */
for (nlt=adt->nla_tracks.first; nlt; nlt=nlt->next, track_index++) {
/* stop here if tweaking is on and this strip is the tweaking track (it will be the first one that's 'disabled')... */
@@ -1874,7 +1909,7 @@ static void animsys_evaluate_nla (PointerRNA *ptr, AnimData *adt, float ctime)
/* 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);
+ dummy_strip.end = (IS_EQF(dummy_strip.actstart, dummy_strip.actend)) ? (dummy_strip.actstart + 1.0f): (dummy_strip.actend);
dummy_strip.blendmode= adt->act_blendmode;
dummy_strip.extendmode= adt->act_extendmode;
@@ -1899,13 +1934,30 @@ static void animsys_evaluate_nla (PointerRNA *ptr, AnimData *adt, float ctime)
/* 2. for each strip, evaluate then accumulate on top of existing channels, but don't set values yet */
for (nes= estrips.first; nes; nes= nes->next)
- nlastrip_evaluate(ptr, &echannels, NULL, nes);
+ nlastrip_evaluate(ptr, echannels, NULL, nes);
+
+ /* 3. free temporary evaluation data that's not used elsewhere */
+ BLI_freelistN(&estrips);
+}
+
+/* NLA Evaluation function (mostly for use through do_animdata)
+ * - All channels that will be affected are not cleared anymore. Instead, we just evaluate into
+ * some temp channels, where values can be accumulated in one go.
+ */
+static void animsys_calculate_nla (PointerRNA *ptr, AnimData *adt, float ctime)
+{
+ ListBase echannels= {NULL, NULL};
- /* 3. flush effects of accumulating channels in NLA to the actual data they affect */
+ // TODO: need to zero out all channels used, otherwise we have problems with threadsafety
+ // and also when the user jumps between different times instead of moving sequentially...
+
+ /* evaluate the NLA stack, obtaining a set of values to flush */
+ animsys_evaluate_nla(&echannels, ptr, adt, ctime);
+
+ /* flush effects of accumulating channels in NLA to the actual data they affect */
nladata_flush_channels(&echannels);
- /* 4. free temporary evaluation data */
- BLI_freelistN(&estrips);
+ /* free temp data */
BLI_freelistN(&echannels);
}
@@ -1999,7 +2051,7 @@ void BKE_animsys_evaluate_animdata (ID *id, AnimData *adt, float ctime, short re
/* evaluate NLA-stack
* - active action is evaluated as part of the NLA stack as the last item
*/
- animsys_evaluate_nla(&id_ptr, adt, ctime);
+ animsys_calculate_nla(&id_ptr, adt, ctime);
}
/* evaluate Active Action only */
else if (adt->action)
@@ -2041,7 +2093,7 @@ void BKE_animsys_evaluate_animdata (ID *id, AnimData *adt, float ctime, short re
void BKE_animsys_evaluate_all_animation (Main *main, float ctime)
{
ID *id;
-
+
if (G.f & G_DEBUG)
printf("Evaluate all animation - %f \n", ctime);
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index b9ff4c2a30b..6a5cc53ef23 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -25,6 +25,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/armature.c
+ * \ingroup bke
+ */
+
+
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
@@ -434,7 +439,7 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest)
scale[1]= len_v3(pchan->pose_mat[1]);
scale[2]= len_v3(pchan->pose_mat[2]);
- if(fabs(scale[0] - scale[1]) > 1e-6f || fabs(scale[1] - scale[2]) > 1e-6f) {
+ if(fabsf(scale[0] - scale[1]) > 1e-6f || fabsf(scale[1] - scale[2]) > 1e-6f) {
unit_m4(scalemat);
scalemat[0][0]= scale[0];
scalemat[1][1]= scale[1];
@@ -730,11 +735,11 @@ static float dist_bone_deform(bPoseChannel *pchan, bPoseChanDeform *pdef_info, f
fac= distfactor_to_bone(cop, bone->arm_head, bone->arm_tail, bone->rad_head, bone->rad_tail, bone->dist);
- if (fac>0.0) {
+ if (fac > 0.0f) {
fac*=bone->weight;
contrib= fac;
- if(contrib>0.0) {
+ if(contrib > 0.0f) {
if(vec) {
if(bone->segments>1)
// applies on cop and bbonemat
@@ -1273,7 +1278,7 @@ void BKE_rotMode_change_values (float quat[4], float eul[3], float axis[3], floa
}
/* when converting to axis-angle, we need a special exception for the case when there is no axis */
- if (IS_EQ(axis[0], axis[1]) && IS_EQ(axis[1], axis[2])) {
+ if (IS_EQF(axis[0], axis[1]) && IS_EQF(axis[1], axis[2])) {
/* for now, rotate around y-axis then (so that it simply becomes the roll) */
axis[1]= 1.0f;
}
@@ -1332,7 +1337,7 @@ void vec_roll_to_mat3(float *vec, float roll, float mat[][3])
/* was 0.0000000000001, caused bug [#23954], smaller values give unstable
* roll when toggling editmode */
- if (dot_v3v3(axis,axis) > 0.00001) {
+ if (dot_v3v3(axis,axis) > 0.00001f) {
/* if nor is *not* a multiple of target ... */
normalize_v3(axis);
@@ -1375,7 +1380,7 @@ void where_is_armature_bone(Bone *bone, Bone *prevbone)
bone->length= len_v3v3(bone->head, bone->tail);
/* this is called on old file reading too... */
- if(bone->xwidth==0.0) {
+ if(bone->xwidth==0.0f) {
bone->xwidth= 0.1f;
bone->zwidth= 0.1f;
bone->segments= 1;
@@ -1966,12 +1971,12 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o
/* calculate volume preservation factor which is
* basically the inverse of the y-scaling factor
*/
- if (fabs(scaleFac) != 0.0f) {
- scale= 1.0 / fabs(scaleFac);
+ if (fabsf(scaleFac) != 0.0f) {
+ scale= 1.0f / fabsf(scaleFac);
/* we need to clamp this within sensible values */
// NOTE: these should be fine for now, but should get sanitised in future
- scale= MIN2(MAX2(scale, 0.0001) , 100000);
+ CLAMP(scale, 0.0001f, 100000.0f);
}
else
scale= 1.0f;
diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index 0556acbdece..c314d476535 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -30,6 +30,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/blender.c
+ * \ingroup bke
+ */
+
+
#ifndef _WIN32
#include <unistd.h> // for read close
#else
@@ -266,12 +271,11 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filename
}
/* special cases, override loaded flags: */
- if (G.f & G_DEBUG) bfd->globalf |= G_DEBUG;
- else bfd->globalf &= ~G_DEBUG;
- if (G.f & G_SWAP_EXCHANGE) bfd->globalf |= G_SWAP_EXCHANGE;
- else bfd->globalf &= ~G_SWAP_EXCHANGE;
- if (G.f & G_SCRIPT_AUTOEXEC) bfd->globalf |= G_SCRIPT_AUTOEXEC;
- else bfd->globalf &= ~G_SCRIPT_AUTOEXEC;
+ if(G.f != bfd->globalf) {
+ const int flags_keep= (G_DEBUG | G_SWAP_EXCHANGE | G_SCRIPT_AUTOEXEC | G_SCRIPT_OVERRIDE_PREF);
+ bfd->globalf= (bfd->globalf & ~flags_keep) | (G.f & flags_keep);
+ }
+
G.f= bfd->globalf;
@@ -348,20 +352,20 @@ void BKE_userdef_free(void)
int BKE_read_file(bContext *C, const char *dir, ReportList *reports)
{
BlendFileData *bfd;
- int retval= 1;
+ int retval= BKE_READ_FILE_OK;
if(strstr(dir, BLENDER_STARTUP_FILE)==NULL) /* dont print user-pref loading */
printf("read blend: %s\n", dir);
bfd= BLO_read_from_file(dir, reports);
if (bfd) {
- if(bfd->user) retval= 2;
+ if(bfd->user) retval= BKE_READ_FILE_OK_USERPREFS;
if(0==handle_subversion_warning(bfd->main)) {
free_main(bfd->main);
MEM_freeN(bfd);
bfd= NULL;
- retval= 0;
+ retval= BKE_READ_FILE_FAIL;
}
else
setup_app_data(C, bfd, dir); // frees BFD
@@ -369,7 +373,7 @@ int BKE_read_file(bContext *C, const char *dir, ReportList *reports)
else
BKE_reports_prependf(reports, "Loading %s failed: ", dir);
- return (bfd?retval:0);
+ return (bfd?retval:BKE_READ_FILE_FAIL);
}
int BKE_read_file_from_memory(bContext *C, char* filebuf, int filelength, ReportList *reports)
@@ -464,7 +468,7 @@ static int read_undosave(bContext *C, UndoElem *uel)
if(success) {
/* important not to update time here, else non keyed tranforms are lost */
- DAG_on_load_update(G.main, FALSE);
+ DAG_on_visible_update(G.main, FALSE);
}
return success;
diff --git a/source/blender/blenkernel/intern/bmesh_private.h b/source/blender/blenkernel/intern/bmesh_private.h
index b14383378ab..d2b1d9fd566 100644
--- a/source/blender/blenkernel/intern/bmesh_private.h
+++ b/source/blender/blenkernel/intern/bmesh_private.h
@@ -34,6 +34,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/bmesh_private.h
+ * \ingroup bke
+ */
+
+
#ifndef BMESH_PRIVATE
#define BMESH_PRIVATE
diff --git a/source/blender/blenkernel/intern/bmfont.c b/source/blender/blenkernel/intern/bmfont.c
index 1d4bdf8bf44..6b1f313d88d 100644
--- a/source/blender/blenkernel/intern/bmfont.c
+++ b/source/blender/blenkernel/intern/bmfont.c
@@ -32,6 +32,11 @@
*
*/
+/** \file blender/blenkernel/intern/bmfont.c
+ * \ingroup bke
+ */
+
+
/**
* Two external functions:
*
diff --git a/source/blender/blenkernel/intern/boids.c b/source/blender/blenkernel/intern/boids.c
index ae4882b0eca..11ea3384c96 100644
--- a/source/blender/blenkernel/intern/boids.c
+++ b/source/blender/blenkernel/intern/boids.c
@@ -29,6 +29,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/boids.c
+ * \ingroup bke
+ */
+
+
#include <string.h>
#include <math.h>
@@ -208,10 +213,8 @@ static int rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues *
sub_v3_v3v3(ray_dir, col.co2, col.co1);
mul_v3_fl(ray_dir, acbr->look_ahead);
col.f = 0.0f;
- col.cfra = fmod(bbd->cfra-bbd->dfra, 1.0f);
- col.dfra = bbd->dfra;
hit.index = -1;
- hit.dist = col.ray_len = len_v3(ray_dir);
+ hit.dist = col.original_ray_length = len_v3(ray_dir);
/* find out closest deflector object */
for(coll = bbd->sim->colliders->first; coll; coll=coll->next) {
@@ -219,18 +222,18 @@ static int rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues *
if(coll->ob == bpa->ground)
continue;
- col.ob = coll->ob;
+ col.current = coll->ob;
col.md = coll->collmd;
if(col.md && col.md->bvhtree)
- BLI_bvhtree_ray_cast(col.md->bvhtree, col.co1, ray_dir, radius, &hit, particle_intersect_face, &col);
+ BLI_bvhtree_ray_cast(col.md->bvhtree, col.co1, ray_dir, radius, &hit, BKE_psys_collision_neartest_cb, &col);
}
/* then avoid that object */
if(hit.index>=0) {
- t = hit.dist/col.ray_len;
+ t = hit.dist/col.original_ray_length;
/* avoid head-on collision */
- if(dot_v3v3(col.nor, pa->prev_state.ave) < -0.99) {
+ if(dot_v3v3(col.pce.nor, pa->prev_state.ave) < -0.99f) {
/* don't know why, but uneven range [0.0,1.0] */
/* works much better than even [-1.0,1.0] */
bbd->wanted_co[0] = BLI_frand();
@@ -238,7 +241,7 @@ static int rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues *
bbd->wanted_co[2] = BLI_frand();
}
else {
- VECCOPY(bbd->wanted_co, col.nor);
+ copy_v3_v3(bbd->wanted_co, col.pce.nor);
}
mul_v3_fl(bbd->wanted_co, (1.0f - t) * val->personal_space * pa->size);
@@ -436,7 +439,7 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va
mul = dot_v3v3(vec, vec);
/* leader is not moving */
- if(mul < 0.01) {
+ if(mul < 0.01f) {
len = len_v3(loc);
/* too close to leader */
if(len < 2.0f * val->personal_space * pa->size) {
@@ -473,7 +476,7 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va
else {
VECCOPY(loc, flbr->oloc);
sub_v3_v3v3(vec, flbr->loc, flbr->oloc);
- mul_v3_fl(vec, 1.0/bbd->timestep);
+ mul_v3_fl(vec, 1.0f/bbd->timestep);
}
/* fac is seconds behind leader */
@@ -496,7 +499,7 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va
mul = dot_v3v3(vec, vec);
/* leader is not moving */
- if(mul < 0.01) {
+ if(mul < 0.01f) {
len = len_v3(loc);
/* too close to leader */
if(len < 2.0f * val->personal_space * pa->size) {
@@ -727,7 +730,7 @@ static void set_boid_values(BoidValues *val, BoidSettings *boids, ParticleData *
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 * bpa->data.health/boids->health;
+ val->max_ave = boids->land_max_ave * (float)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 * bpa->data.health/boids->health;
@@ -735,7 +738,7 @@ static void set_boid_values(BoidValues *val, BoidSettings *boids, ParticleData *
else {
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 * bpa->data.health/boids->health;
+ val->max_ave = boids->air_max_ave * (float)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 */
@@ -774,27 +777,26 @@ static Object *boid_find_ground(BoidBrainData *bbd, ParticleData *pa, float *gro
/* first try to find below boid */
copy_v3_v3(col.co1, pa->state.co);
sub_v3_v3v3(col.co2, pa->state.co, zvec);
- sub_v3_v3(col.co2, zvec);
sub_v3_v3v3(ray_dir, col.co2, col.co1);
col.f = 0.0f;
- col.cfra = fmod(bbd->cfra-bbd->dfra, 1.0f);
- col.dfra = bbd->dfra;
hit.index = -1;
- hit.dist = col.ray_len = len_v3(ray_dir);
+ hit.dist = col.original_ray_length = len_v3(ray_dir);
+ col.pce.inside = 0;
for(coll = bbd->sim->colliders->first; coll; coll = coll->next){
- col.ob = coll->ob;
+ col.current = coll->ob;
col.md = coll->collmd;
+ col.fac1 = col.fac2 = 0.f;
if(col.md && col.md->bvhtree)
- BLI_bvhtree_ray_cast(col.md->bvhtree, col.co1, ray_dir, radius, &hit, particle_intersect_face, &col);
+ BLI_bvhtree_ray_cast(col.md->bvhtree, col.co1, ray_dir, radius, &hit, BKE_psys_collision_neartest_cb, &col);
}
/* then use that object */
if(hit.index>=0) {
- t = hit.dist/col.ray_len;
+ t = hit.dist/col.original_ray_length;
interp_v3_v3v3(ground_co, col.co1, col.co2, t);
- normalize_v3_v3(ground_nor, col.nor);
- return col.hit_ob;
+ normalize_v3_v3(ground_nor, col.pce.nor);
+ return col.hit;
}
/* couldn't find below, so find upmost deflector object */
@@ -803,24 +805,22 @@ static Object *boid_find_ground(BoidBrainData *bbd, ParticleData *pa, float *gro
sub_v3_v3(col.co2, zvec);
sub_v3_v3v3(ray_dir, col.co2, col.co1);
col.f = 0.0f;
- col.cfra = fmod(bbd->cfra-bbd->dfra, 1.0f);
- col.dfra = bbd->dfra;
hit.index = -1;
- hit.dist = col.ray_len = len_v3(ray_dir);
+ hit.dist = col.original_ray_length = len_v3(ray_dir);
for(coll = bbd->sim->colliders->first; coll; coll = coll->next){
- col.ob = coll->ob;
+ col.current = coll->ob;
col.md = coll->collmd;
if(col.md && col.md->bvhtree)
- BLI_bvhtree_ray_cast(col.md->bvhtree, col.co1, ray_dir, radius, &hit, particle_intersect_face, &col);
+ BLI_bvhtree_ray_cast(col.md->bvhtree, col.co1, ray_dir, radius, &hit, BKE_psys_collision_neartest_cb, &col);
}
/* then use that object */
if(hit.index>=0) {
- t = hit.dist/col.ray_len;
+ t = hit.dist/col.original_ray_length;
interp_v3_v3v3(ground_co, col.co1, col.co2, t);
- normalize_v3_v3(ground_nor, col.nor);
- return col.hit_ob;
+ normalize_v3_v3(ground_nor, col.pce.nor);
+ return col.hit;
}
/* default to z=0 */
@@ -872,7 +872,7 @@ static void boid_climb(BoidSettings *boids, ParticleData *pa, float *surface_co,
VECCOPY(nor, surface_nor);
/* gather apparent gravity */
- VECADDFAC(bpa->gravity, bpa->gravity, surface_nor, -1.0);
+ VECADDFAC(bpa->gravity, bpa->gravity, surface_nor, -1.0f);
normalize_v3(bpa->gravity);
/* raise boid it's size from surface */
@@ -1010,7 +1010,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa)
/* decide on jumping & liftoff */
if(bpa->data.mode == eBoidMode_OnLand) {
/* fuzziness makes boids capable of misjudgement */
- float mul = 1.0 + state->rule_fuzziness;
+ float mul = 1.0f + state->rule_fuzziness;
if(boids->options & BOID_ALLOW_FLIGHT && bbd->wanted_co[2] > 0.0f) {
float cvel[3], dir[3];
@@ -1021,7 +1021,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa)
VECCOPY(cvel, bbd->wanted_co);
normalize_v2(cvel);
- if(dot_v2v2(cvel, dir) > 0.95 / mul)
+ if(dot_v2v2(cvel, dir) > 0.95f / mul)
bpa->data.mode = eBoidMode_Liftoff;
}
else if(val.jump_speed > 0.0f) {
@@ -1129,7 +1129,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
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;
+ level = (pa->prev_state.co[2] - ground_co[2])/(2.0f * pa->size) - 0.5f;
landing_level = - boids->landing_smoothness * pa->prev_state.vel[2] * pa_mass;
@@ -1328,7 +1328,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
boid_climb(boids, pa, ground_co, ground_nor);
}
/* land boid when really near ground */
- else if(pa->state.co[2] <= ground_co[2] + 1.01 * pa->size * boids->height){
+ else if(pa->state.co[2] <= ground_co[2] + 1.01f * pa->size * boids->height){
pa->state.co[2] = ground_co[2] + pa->size * boids->height;
pa->state.vel[2] = 0.0f;
bpa->data.mode = eBoidMode_OnLand;
@@ -1370,7 +1370,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
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)
+ else if(pa->state.co[2]-ground_co[2] > 1.1f * pa->size * boids->height)
bpa->data.mode = eBoidMode_Falling;
else {
/* constrain to surface */
@@ -1402,7 +1402,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
/* save direction to state.ave unless the boid is falling */
/* (boids can't effect their direction when falling) */
- if(bpa->data.mode!=eBoidMode_Falling && len_v3(pa->state.vel) > 0.1*pa->size) {
+ if(bpa->data.mode!=eBoidMode_Falling && len_v3(pa->state.vel) > 0.1f*pa->size) {
copy_v3_v3(pa->state.ave, pa->state.vel);
pa->state.ave[2] *= bbd->part->boids->pitch;
normalize_v3(pa->state.ave);
diff --git a/source/blender/blenkernel/intern/booleanops_mesh.c b/source/blender/blenkernel/intern/booleanops_mesh.c
index dd595fc98b6..4e8a3b33827 100644
--- a/source/blender/blenkernel/intern/booleanops_mesh.c
+++ b/source/blender/blenkernel/intern/booleanops_mesh.c
@@ -1,6 +1,6 @@
#if 0
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -28,6 +28,11 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
+
+/** \file blender/blenkernel/intern/booleanops_mesh.c
+ * \ingroup bke
+ */
+
#include "CSG_BooleanOps.h"
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 15404acc105..96b6ec357f9 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/brush.c
+ * \ingroup bke
+ */
+
+
#include <math.h>
#include <string.h>
@@ -588,7 +593,7 @@ void brush_imbuf_new(Brush *brush, short flt, short texfall, int bufsize, ImBuf
dst[2]= FTOCHAR(rgba[2]);
dst[3]= FTOCHAR(rgba[3]);
}
- else {
+ else if (texfall == 2) {
dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
brush_sample_tex(brush, xy, rgba, 0);
@@ -596,6 +601,14 @@ void brush_imbuf_new(Brush *brush, short flt, short texfall, int bufsize, ImBuf
dst[1] = FTOCHAR(rgba[1]*brush->rgb[1]);
dst[2] = FTOCHAR(rgba[2]*brush->rgb[2]);
dst[3] = FTOCHAR(rgba[3]*alpha*brush_curve_strength_clamp(brush, dist, radius));
+ } else {
+ dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
+
+ brush_sample_tex(brush, xy, rgba, 0);
+ dst[0]= crgb[0];
+ dst[1]= crgb[1];
+ dst[2]= crgb[2];
+ dst[3] = FTOCHAR(rgba[3]*alpha*brush_curve_strength_clamp(brush, dist, radius));
}
}
}
@@ -719,6 +732,12 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, i
dotexold = (oldtexibuf != NULL);
+ /* not sure if it's actually needed or it's a mistake in coords/sizes
+ calculation in brush_painter_fixed_tex_partial_update(), but without this
+ limitation memory gets corrupted at fast strokes with quite big spacing (sergey) */
+ w = MIN2(w, ibuf->x);
+ h = MIN2(h, ibuf->y);
+
if (painter->cache.flt) {
for (; y < h; y++) {
bf = ibuf->rect_float + (y*ibuf->x + origx)*4;
@@ -865,11 +884,8 @@ static void brush_painter_refresh_cache(BrushPainter *painter, float *pos)
flt= cache->flt;
size= (cache->size)? cache->size: diameter;
- if (!(mtex && mtex->tex) || (mtex->tex->type==0)) {
- brush_imbuf_new(brush, flt, 0, size, &cache->ibuf);
- }
- else if (brush->flag & BRUSH_FIXED_TEX) {
- brush_imbuf_new(brush, flt, 0, size, &cache->maskibuf);
+ if (brush->flag & BRUSH_FIXED_TEX) {
+ brush_imbuf_new(brush, flt, 3, size, &cache->maskibuf);
brush_painter_fixed_tex_partial_update(painter, pos);
}
else
@@ -896,13 +912,13 @@ void brush_painter_break_stroke(BrushPainter *painter)
static void brush_apply_pressure(BrushPainter *painter, Brush *brush, float pressure)
{
if (brush_use_alpha_pressure(brush))
- brush_set_alpha(brush, MAX2(0.0, painter->startalpha*pressure));
+ brush_set_alpha(brush, MAX2(0.0f, painter->startalpha*pressure));
if (brush_use_size_pressure(brush))
- brush_set_size(brush, MAX2(1.0, painter->startsize*pressure));
+ brush_set_size(brush, MAX2(1.0f, painter->startsize*pressure));
if (brush->flag & BRUSH_JITTER_PRESSURE)
- brush->jitter = MAX2(0.0, painter->startjitter*pressure);
+ brush->jitter = MAX2(0.0f, painter->startjitter*pressure);
if (brush->flag & BRUSH_SPACING_PRESSURE)
- brush->spacing = MAX2(1.0, painter->startspacing*(1.5f-pressure));
+ brush->spacing = MAX2(1.0f, painter->startspacing*(1.5f-pressure));
}
void brush_jitter_pos(Brush *brush, float *pos, float *jitterpos)
@@ -1008,29 +1024,42 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos, doubl
len= normalize_v2(dmousepos);
painter->accumdistance += len;
- /* do paint op over unpainted distance */
- while ((len > 0.0f) && (painter->accumdistance >= spacing)) {
- step= spacing - startdistance;
- paintpos[0]= painter->lastmousepos[0] + dmousepos[0]*step;
- paintpos[1]= painter->lastmousepos[1] + dmousepos[1]*step;
+ if (brush->flag & BRUSH_SPACE) {
+ /* do paint op over unpainted distance */
+ while ((len > 0.0f) && (painter->accumdistance >= spacing)) {
+ step= spacing - startdistance;
+ paintpos[0]= painter->lastmousepos[0] + dmousepos[0]*step;
+ paintpos[1]= painter->lastmousepos[1] + dmousepos[1]*step;
+
+ t = step/len;
+ press= (1.0f-t)*painter->lastpressure + t*pressure;
+ brush_apply_pressure(painter, brush, press);
+ spacing= MAX2(1.0f, radius)*brush->spacing*0.01f;
+
+ brush_jitter_pos(brush, paintpos, finalpos);
+
+ if (painter->cache.enabled)
+ brush_painter_refresh_cache(painter, finalpos);
- t = step/len;
- press= (1.0f-t)*painter->lastpressure + t*pressure;
- brush_apply_pressure(painter, brush, press);
- spacing= MAX2(1.0f, radius)*brush->spacing*0.01f;
+ totpaintops +=
+ func(user, painter->cache.ibuf, painter->lastpaintpos, finalpos);
- brush_jitter_pos(brush, paintpos, finalpos);
+ painter->lastpaintpos[0]= paintpos[0];
+ painter->lastpaintpos[1]= paintpos[1];
+ painter->accumdistance -= spacing;
+ startdistance -= spacing;
+ }
+ } else {
+ brush_jitter_pos(brush, pos, finalpos);
if (painter->cache.enabled)
brush_painter_refresh_cache(painter, finalpos);
- totpaintops +=
- func(user, painter->cache.ibuf, painter->lastpaintpos, finalpos);
+ totpaintops += func(user, painter->cache.ibuf, pos, finalpos);
- painter->lastpaintpos[0]= paintpos[0];
- painter->lastpaintpos[1]= paintpos[1];
- painter->accumdistance -= spacing;
- startdistance -= spacing;
+ painter->lastpaintpos[0]= pos[0];
+ painter->lastpaintpos[1]= pos[1];
+ painter->accumdistance= 0;
}
/* do airbrush paint ops, based on the number of paint ops left over
@@ -1046,7 +1075,7 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos, doubl
else
painter->accumtime -= painttime;
- while (painter->accumtime >= brush->rate) {
+ while (painter->accumtime >= (double)brush->rate) {
brush_apply_pressure(painter, brush, pressure);
brush_jitter_pos(brush, pos, finalpos);
@@ -1056,7 +1085,7 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos, doubl
totpaintops +=
func(user, painter->cache.ibuf, painter->lastmousepos, finalpos);
- painter->accumtime -= brush->rate;
+ painter->accumtime -= (double)brush->rate;
}
painter->lasttime= curtime;
@@ -1082,7 +1111,7 @@ float brush_curve_strength_clamp(Brush *br, float p, const float len)
else p= p/len;
p= curvemapping_evaluateF(br->curve, 0, p);
- if(p < 0.0) p= 0.0f;
+ if(p < 0.0f) p= 0.0f;
else if(p > 1.0f) p= 1.0f;
return p;
}
@@ -1129,10 +1158,10 @@ unsigned int *brush_gen_texture_cache(Brush *br, int half_side)
* if the texture didn't give an RGB value, copy the intensity across
*/
if(hasrgb & TEX_RGB)
- texres.tin = (0.35 * texres.tr + 0.45 *
- texres.tg + 0.2 * texres.tb);
+ texres.tin = (0.35f * texres.tr + 0.45f *
+ texres.tg + 0.2f * texres.tb);
- texres.tin = texres.tin * 255.0;
+ texres.tin = texres.tin * 255.0f;
((char*)texcache)[(iy*side+ix)*4] = (char)texres.tin;
((char*)texcache)[(iy*side+ix)*4+1] = (char)texres.tin;
((char*)texcache)[(iy*side+ix)*4+2] = (char)texres.tin;
@@ -1181,7 +1210,7 @@ static struct ImBuf *brush_gen_radial_control_imbuf(Brush *br)
void brush_radial_control_invoke(wmOperator *op, Brush *br, float size_weight)
{
- int mode = RNA_int_get(op->ptr, "mode");
+ int mode = RNA_enum_get(op->ptr, "mode");
float original_value= 0;
if(mode == WM_RADIALCONTROL_SIZE)
@@ -1200,7 +1229,7 @@ void brush_radial_control_invoke(wmOperator *op, Brush *br, float size_weight)
int brush_radial_control_exec(wmOperator *op, Brush *br, float size_weight)
{
- int mode = RNA_int_get(op->ptr, "mode");
+ int mode = RNA_enum_get(op->ptr, "mode");
float new_value = RNA_float_get(op->ptr, "new_value");
const float conv = 0.017453293;
diff --git a/source/blender/blenkernel/intern/bullet.c b/source/blender/blenkernel/intern/bullet.c
index 238d3e7f682..72f5e907800 100644
--- a/source/blender/blenkernel/intern/bullet.c
+++ b/source/blender/blenkernel/intern/bullet.c
@@ -28,6 +28,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/bullet.c
+ * \ingroup bke
+ */
+
+
#include "MEM_guardedalloc.h"
/* types */
diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c
index 1a5458323d8..941f377ab42 100644
--- a/source/blender/blenkernel/intern/bvhutils.c
+++ b/source/blender/blenkernel/intern/bvhutils.c
@@ -27,6 +27,11 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
+
+/** \file blender/blenkernel/intern/bvhutils.c
+ * \ingroup bke
+ */
+
#include <stdio.h>
#include <string.h>
#include <math.h>
@@ -126,7 +131,7 @@ static float nearest_point_in_tri_surface(const float *v0,const float *v1,const
}
else
{
- if(fabs(A00) > FLT_EPSILON)
+ if(fabsf(A00) > FLT_EPSILON)
S = -B0/A00;
else
S = 0.0f;
@@ -151,7 +156,7 @@ static float nearest_point_in_tri_surface(const float *v0,const float *v1,const
}
else
{
- if(fabs(A11) > FLT_EPSILON)
+ if(fabsf(A11) > FLT_EPSILON)
T = -B1 / A11;
else
T = 0.0f;
@@ -177,7 +182,7 @@ static float nearest_point_in_tri_surface(const float *v0,const float *v1,const
}
else
{
- if(fabs(A11) > FLT_EPSILON)
+ if(fabsf(A11) > FLT_EPSILON)
T = -B1 / A11;
else
T = 0.0;
@@ -203,7 +208,7 @@ static float nearest_point_in_tri_surface(const float *v0,const float *v1,const
}
else
{
- if(fabs(A00) > FLT_EPSILON)
+ if(fabsf(A00) > FLT_EPSILON)
S = -B0 / A00;
else
S = 0.0f;
@@ -215,7 +220,7 @@ static float nearest_point_in_tri_surface(const float *v0,const float *v1,const
{
// Minimum at interior lv
float invDet;
- if(fabs(Det) > FLT_EPSILON)
+ if(fabsf(Det) > FLT_EPSILON)
invDet = 1.0f / Det;
else
invDet = 0.0f;
@@ -246,7 +251,7 @@ static float nearest_point_in_tri_surface(const float *v0,const float *v1,const
}
else
{
- if(fabs(denom) > FLT_EPSILON)
+ if(fabsf(denom) > FLT_EPSILON)
S = numer / denom;
else
S = 0.0f;
@@ -273,7 +278,7 @@ static float nearest_point_in_tri_surface(const float *v0,const float *v1,const
}
else
{
- if(fabs(A11) > FLT_EPSILON)
+ if(fabsf(A11) > FLT_EPSILON)
T = -B1 / A11;
else
T = 0.0f;
@@ -299,7 +304,7 @@ static float nearest_point_in_tri_surface(const float *v0,const float *v1,const
}
else
{
- if(fabs(denom) > FLT_EPSILON)
+ if(fabsf(denom) > FLT_EPSILON)
T = numer / denom;
else
T = 0.0f;
@@ -326,7 +331,7 @@ static float nearest_point_in_tri_surface(const float *v0,const float *v1,const
}
else
{
- if(fabs(A00) > FLT_EPSILON)
+ if(fabsf(A00) > FLT_EPSILON)
S = -B0 / A00;
else
S = 0.0f;
@@ -357,7 +362,7 @@ static float nearest_point_in_tri_surface(const float *v0,const float *v1,const
}
else
{
- if(fabs(denom) > FLT_EPSILON)
+ if(fabsf(denom) > FLT_EPSILON)
S = numer / denom;
else
S = 0.0f;
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 8c22ea02ce6..cba4053ad3a 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -30,7 +30,12 @@
*
* BKE_cdderivedmesh.h contains the function prototypes for this file.
*
-*/
+*/
+
+/** \file blender/blenkernel/intern/cdderivedmesh.c
+ * \ingroup bke
+ */
+
/* TODO maybe BIF_gl.h should include string.h? */
#include <string.h>
@@ -1684,9 +1689,7 @@ DerivedMesh *disabled__CDDM_from_editmesh(EditMesh *em, Mesh *UNUSED(me))
VECCOPY(mv->co, eve->co);
- mv->no[0] = eve->no[0] * 32767.0;
- mv->no[1] = eve->no[1] * 32767.0;
- mv->no[2] = eve->no[2] * 32767.0;
+ normal_float_to_short_v3(mv->no, eve->no);
mv->bweight = (unsigned char) (eve->bweight * 255.0f);
mv->flag = 0;
@@ -1749,15 +1752,17 @@ DerivedMesh *CDDM_from_curve_customDB(Object *ob, ListBase *dispbase)
MVert *allvert;
MEdge *alledge;
MFace *allface;
- int totvert, totedge, totface;
+ MLoop *allloop;
+ MPoly *allpoly;
+ int totvert, totedge, totface, totloop, totpoly;
if (nurbs_to_mdata_customdb(ob, dispbase, &allvert, &totvert, &alledge,
- &totedge, &allface, &totface) != 0) {
+ &totedge, &allface, &allloop, &allpoly, &totface, &totloop, &totpoly) != 0) {
/* Error initializing mdata. This often happens when curve is empty */
return CDDM_new(0, 0, 0, 0, 0);
}
- dm = CDDM_new(totvert, totedge, totface, totface*4, totface);
+ dm = CDDM_new(totvert, totedge, totface, totloop, totpoly);
dm->deformedOnly = 1;
cddm = (CDDerivedMesh*)dm;
@@ -1765,10 +1770,14 @@ DerivedMesh *CDDM_from_curve_customDB(Object *ob, ListBase *dispbase)
memcpy(cddm->mvert, allvert, totvert*sizeof(MVert));
memcpy(cddm->medge, alledge, totedge*sizeof(MEdge));
memcpy(cddm->mface, allface, totface*sizeof(MFace));
+ memcpy(cddm->mloop, allloop, totloop*sizeof(MLoop));
+ memcpy(cddm->mpoly, allpoly, totpoly*sizeof(MPoly));
MEM_freeN(allvert);
MEM_freeN(alledge);
MEM_freeN(allface);
+ MEM_freeN(allloop);
+ MEM_freeN(allpoly);
return dm;
}
@@ -2227,73 +2236,27 @@ void CDDM_apply_vert_normals(DerivedMesh *dm, short (*vertNormals)[3])
void CDDM_calc_normals(DerivedMesh *dm)
{
CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
- float (*temp_nors)[3];
- float (*face_nors)[3];
- float (*vert_nors)[3];
- int i, j, *origIndex;
- int numVerts = dm->numVertData;
- int numFaces = dm->numFaceData;
- MFace *mf;
- MPoly *mp;
- MVert *mv;
- MLoop *ml;
-
- if(numVerts == 0) return;
-
- if (CustomData_has_layer(&dm->faceData, CD_NORMAL))
- CustomData_free_layer(&dm->faceData, CD_NORMAL, dm->numFaceData, 0);
+ float (*face_nors)[3] = NULL;
+
+ if(dm->numVertData == 0) return;
- /*recalc tesselation to ensure we have valid origindex values
- for mface->mpoly lookups.*/
+ /* we don't want to overwrite any referenced layers */
+ cddm->mvert = CustomData_duplicate_referenced_layer(&dm->vertData, CD_MVERT);
+
+ /*set tesselation origindex values to map to poly indices, rather then poly
+ poly origindex values*/
cdDM_recalcTesselation2(dm);
-
- numFaces = dm->numFaceData;
-
- /*first go through and calculate normals for all the polys*/
- temp_nors = MEM_callocN(sizeof(float)*3*dm->numPolyData, "temp_nors cdderivedmesh.c");
- vert_nors = MEM_callocN(sizeof(float)*3*dm->numVertData, "vert_nors cdderivedmesh.c");
- mp = cddm->mpoly;
- for (i=0; i<dm->numPolyData; i++, mp++) {
- mesh_calc_poly_normal(mp, cddm->mloop+mp->loopstart, cddm->mvert, temp_nors[i]);
-
- ml = cddm->mloop + mp->loopstart;
- for (j=0; j<mp->totloop; j++, ml++) {
- VECADD(vert_nors[ml->v], vert_nors[ml->v], temp_nors[i]);
- }
- }
-
- face_nors = MEM_callocN(sizeof(float)*3*dm->numFaceData, "face_nors cdderivedmesh.c");
- origIndex = CustomData_get_layer(&dm->faceData, CD_ORIGINDEX);
-
- mf = cddm->mface;
- for (i=0; i<dm->numFaceData; i++, mf++, origIndex++) {
- VECCOPY(face_nors[i], temp_nors[*origIndex]);
- }
-
- mv = cddm->mvert;
- for (i=0; i<dm->numVertData; i++, mv++) {
- float *no = vert_nors[i];
-
- if (normalize_v3(no) == 0.0) {
- VECCOPY(no, mv->co);
- if (normalize_v3(no) == 0.0) {
- no[0] = 0.0f;
- no[1] = 0.0f;
- no[2] = 1.0f;
- }
- }
-
- normal_float_to_short_v3(mv->no, no);
- }
-
- MEM_freeN(temp_nors);
- MEM_freeN(vert_nors);
-
- /*this restores original poly origindex -> tessface origindex mapping,
- instead of the poly index -> tessface origindex one we generated
- with cdDM_recalcTesselation2*/
+ face_nors = MEM_mallocN(sizeof(float)*3*dm->numFaceData, "face_nors");
+
+ /* calculate face normals */
+ mesh_calc_normals(cddm->mvert, dm->numVertData, CDDM_get_loops(dm), CDDM_get_polys(dm),
+ dm->numLoopData, dm->numPolyData, NULL, cddm->mface, dm->numFaceData,
+ CustomData_get_layer(&dm->faceData, CD_ORIGINDEX), face_nors);
+
+ /*restore tesselation origindex indices to poly origindex indices*/
cdDM_recalcTesselation(dm);
+
CustomData_add_layer(&dm->faceData, CD_NORMAL, CD_ASSIGN,
face_nors, dm->numFaceData);
}
@@ -2433,7 +2396,7 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, int *vtargetmap)
}
/*create new cddm*/
- cddm2 = (CDDerivedMesh*) CDDM_from_template(cddm, BLI_array_count(mvert), BLI_array_count(medge), 0, BLI_array_count(mloop), BLI_array_count(mpoly));
+ cddm2 = (CDDerivedMesh*) CDDM_from_template((DerivedMesh*)cddm, BLI_array_count(mvert), BLI_array_count(medge), 0, BLI_array_count(mloop), BLI_array_count(mpoly));
/*update edge indices and copy customdata*/
me = medge;
@@ -2476,7 +2439,7 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, int *vtargetmap)
memcpy(cddm2->mpoly, mpoly, sizeof(MPoly)*BLI_array_count(mpoly));
BLI_array_free(mvert); BLI_array_free(medge); BLI_array_free(mloop); BLI_array_free(mpoly);
- CDDM_recalc_tesselation(cddm2, 1);
+ CDDM_recalc_tesselation((DerivedMesh*)cddm2, 1);
if (newv)
MEM_freeN(newv);
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index c115f6aa470..9fabf1d52cf 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -25,6 +25,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/cloth.c
+ * \ingroup bke
+ */
+
+
#include "MEM_guardedalloc.h"
#include "DNA_cloth_types.h"
diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c
index 623ba26e86d..88b6ca296c7 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/collision.c
+ * \ingroup bke
+ */
+
+
#include "MEM_guardedalloc.h"
#include "BKE_cloth.h"
diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c
index 7cf6b21e2f1..46f3e124bcc 100644
--- a/source/blender/blenkernel/intern/colortools.c
+++ b/source/blender/blenkernel/intern/colortools.c
@@ -27,6 +27,11 @@
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/colortools.c
+ * \ingroup bke
+ */
+
+
#include <string.h>
#include <math.h>
#include <stdlib.h>
@@ -416,14 +421,14 @@ static void calchandle_curvemap(BezTriple *bezt, BezTriple *prev, BezTriple *nex
}
if(bezt->h1==HD_VECT) { /* vector */
- dx/=3.0;
- dy/=3.0;
+ dx/=3.0f;
+ dy/=3.0f;
*(p2-3)= *p2-dx;
*(p2-2)= *(p2+1)-dy;
}
if(bezt->h2==HD_VECT) {
- dx1/=3.0;
- dy1/=3.0;
+ dx1/=3.0f;
+ dy1/=3.0f;
*(p2+3)= *p2+dx1;
*(p2+4)= *(p2+1)+dy1;
}
@@ -695,7 +700,7 @@ void curvemapping_changed(CurveMapping *cumap, int rem_doubles)
for(a=0; a<cuma->totpoint-1; a++) {
dx= cmp[a].x - cmp[a+1].x;
dy= cmp[a].y - cmp[a+1].y;
- if( sqrt(dx*dx + dy*dy) < thresh ) {
+ if( sqrtf(dx*dx + dy*dy) < thresh ) {
if(a==0) {
cmp[a+1].flag|= 2;
if(cmp[a+1].flag & CUMA_SELECT)
@@ -957,7 +962,7 @@ void curvemapping_table_RGBA(CurveMapping *cumap, float **array, int *size)
DO_INLINE int get_bin_float(float f)
{
- int bin= (int)((f*255) + 0.5); /* 0.5 to prevent quantisation differences */
+ int bin= (int)((f*255.0f) + 0.5f); /* 0.5 to prevent quantisation differences */
/* note: clamp integer instead of float to avoid problems with NaN */
CLAMP(bin, 0, 255);
@@ -1049,7 +1054,7 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management)
bin_lum = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
/* convert to number of lines with logarithmic scale */
- scopes->sample_lines = (scopes->accuracy*0.01) * (scopes->accuracy*0.01) * ibuf->y;
+ scopes->sample_lines = (scopes->accuracy*0.01f) * (scopes->accuracy*0.01f) * ibuf->y;
if (scopes->sample_full)
scopes->sample_lines = ibuf->y;
@@ -1100,7 +1105,7 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management)
}
/* we still need luma for histogram */
- luma = 0.299*rgb[0] + 0.587*rgb[1] + 0.114 * rgb[2];
+ luma = 0.299f * rgb[0] + 0.587f * rgb[1] + 0.114f * rgb[2];
/* check for min max */
if(ycc_mode == -1 ) {
@@ -1150,8 +1155,8 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management)
if (bin_lum[x] > nl)
nl = bin_lum[x];
}
- div = 1.f/(double)n;
- divl = 1.f/(double)nl;
+ div = 1.0/(double)n;
+ divl = 1.0/(double)nl;
for (x=0; x<256; x++) {
scopes->hist.data_r[x] = bin_r[x] * div;
scopes->hist.data_g[x] = bin_g[x] * div;
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 2527831319e..7956da5da80 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/constraint.c
+ * \ingroup bke
+ */
+
+
#include <stdio.h>
#include <stddef.h>
#include <string.h>
@@ -618,7 +623,7 @@ static void constraint_target_to_mat4 (Scene *scene, Object *ob, const char *sub
* PoseChannel by the Armature Object's Matrix to get a worldspace
* matrix.
*/
- if (headtail < 0.000001) {
+ if (headtail < 0.000001f) {
/* skip length interpolation if set to head */
mul_m4_m4m4(mat, pchan->pose_mat, ob->obmat);
}
@@ -991,10 +996,10 @@ static void vectomat (float *vec, float *target_up, short axis, short upflag, sh
float neg = -1;
int right_index;
- if (normalize_v3_v3(n, vec) == 0.0) {
- n[0] = 0.0;
- n[1] = 0.0;
- n[2] = 1.0;
+ if (normalize_v3_v3(n, vec) == 0.0f) {
+ n[0] = 0.0f;
+ n[1] = 0.0f;
+ n[2] = 1.0f;
}
if (axis > 2) axis -= 3;
else negate_v3(n);
@@ -1016,10 +1021,10 @@ static void vectomat (float *vec, float *target_up, short axis, short upflag, sh
sub_v3_v3v3(proj, u, proj); /* then onto the plane */
/* proj specifies the transformation of the up axis */
- if (normalize_v3(proj) == 0.0) { /* degenerate projection */
- proj[0] = 0.0;
- proj[1] = 1.0;
- proj[2] = 0.0;
+ if (normalize_v3(proj) == 0.0f) { /* degenerate projection */
+ proj[0] = 0.0f;
+ proj[1] = 1.0f;
+ proj[2] = 0.0f;
}
/* Normalized cross product of n and proj specifies transformation of the right axis */
@@ -1275,7 +1280,7 @@ static void followpath_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr
* factor, which then gets clamped to lie within 0.0 - 1.0 range
*/
curvetime /= cu->pathlen;
- CLAMP(curvetime, 0.0, 1.0);
+ CLAMP(curvetime, 0.0f, 1.0f);
}
else {
/* fixed position along curve */
@@ -1922,7 +1927,7 @@ static void samevolume_evaluate (bConstraint *con, bConstraintOb *cob, ListBase
/* calculate normalising scale factor for non-essential values */
if (obsize[data->flag] != 0)
- fac = sqrt(volume / obsize[data->flag]) / obsize[data->flag];
+ fac = sqrtf(volume / obsize[data->flag]) / obsize[data->flag];
/* apply scaling factor to the channels not being kept */
switch (data->flag) {
@@ -2173,9 +2178,7 @@ static void actcon_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraint
if (data->type < 10) {
/* extract rotation (is in whatever space target should be in) */
mat4_to_eul(vec, tempmat);
- vec[0] *= (float)(180.0/M_PI);
- vec[1] *= (float)(180.0/M_PI);
- vec[2] *= (float)(180.0/M_PI);
+ mul_v3_fl(vec, (float)(180.0/M_PI)); /* rad -> deg */
axis= data->type;
}
else if (data->type < 20) {
@@ -2666,7 +2669,7 @@ static void distlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
else if (data->flag & LIMITDIST_USESOFT) {
// FIXME: there's a problem with "jumping" when this kicks in
if (dist >= (data->dist - data->soft)) {
- sfac = (float)( data->soft*(1.0 - exp(-(dist - data->dist)/data->soft)) + data->dist );
+ sfac = (float)( data->soft*(1.0f - expf(-(dist - data->dist)/data->soft)) + data->dist );
sfac /= dist;
clamp_surf= 1;
@@ -2674,7 +2677,7 @@ static void distlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
}
}
else {
- if (IS_EQ(dist, data->dist)==0) {
+ if (IS_EQF(dist, data->dist)==0) {
clamp_surf= 1;
sfac= data->dist / dist;
}
@@ -3071,7 +3074,7 @@ static void rbj_flush_tars (bConstraint *con, ListBase *list, short nocopy)
static bConstraintTypeInfo CTI_RIGIDBODYJOINT = {
CONSTRAINT_TYPE_RIGIDBODYJOINT, /* type */
sizeof(bRigidBodyJointConstraint), /* size */
- "RigidBody Joint", /* name */
+ "Rigid Body Joint", /* name */
"bRigidBodyJointConstraint", /* struct name */
NULL, /* free data */
NULL, /* relink data */
@@ -3333,8 +3336,7 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
break;
case 1: /* rotation (convert to degrees first) */
mat4_to_eulO(dvec, cob->rotOrder, ct->matrix);
- for (i=0; i<3; i++)
- dvec[i] = (float)(dvec[i] / M_PI * 180);
+ mul_v3_fl(dvec, (float)(180.0/M_PI)); /* rad -> deg */
break;
default: /* location */
copy_v3_v3(dvec, ct->matrix[3]);
@@ -3384,7 +3386,7 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
eul[i]= tmin + (sval[(int)data->map[i]] * (tmax - tmin));
/* now convert final value back to radians */
- eul[i] = (float)(eul[i] / 180 * M_PI);
+ eul[i] = DEG2RADF(eul[i]);
}
break;
default: /* location */
@@ -4462,9 +4464,11 @@ void solve_constraints (ListBase *conlist, bConstraintOb *cob, float ctime)
*/
enf = con->enforce;
+ /* make copy of worldspace matrix pre-constraint for use with blending later */
+ copy_m4_m4(oldmat, cob->matrix);
+
/* move owner matrix into right space */
constraint_mat_convertspace(cob->ob, cob->pchan, cob->matrix, CONSTRAINT_SPACE_WORLD, con->ownspace);
- copy_m4_m4(oldmat, cob->matrix);
/* prepare targets for constraint solving */
if (cti->get_constraint_targets) {
@@ -4500,16 +4504,20 @@ void solve_constraints (ListBase *conlist, bConstraintOb *cob, float ctime)
cti->flush_constraint_targets(con, &targets, 1);
}
- /* Interpolate the enforcement, to blend result of constraint into final owner transform */
+ /* move owner back into worldspace for next constraint/other business */
+ if ((con->flag & CONSTRAINT_SPACEONCE) == 0)
+ constraint_mat_convertspace(cob->ob, cob->pchan, cob->matrix, con->ownspace, CONSTRAINT_SPACE_WORLD);
+
+ /* Interpolate the enforcement, to blend result of constraint into final owner transform
+ * - all this happens in worldspace to prevent any weirdness creeping in ([#26014] and [#25725]),
+ * since some constraints may not convert the solution back to the input space before blending
+ * but all are guaranteed to end up in good "worldspace" result
+ */
/* Note: all kind of stuff here before (caused trouble), much easier to just interpolate, or did I miss something? -jahka */
- if (enf < 1.0) {
+ if (enf < 1.0f) {
float solution[4][4];
copy_m4_m4(solution, cob->matrix);
blend_m4_m4m4(cob->matrix, oldmat, solution, enf);
}
-
- /* move owner back into worldspace for next constraint/other business */
- if ((con->flag & CONSTRAINT_SPACEONCE) == 0)
- constraint_mat_convertspace(cob->ob, cob->pchan, cob->matrix, con->ownspace, CONSTRAINT_SPACE_WORLD);
}
}
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index 6f7188115e0..2a44c942865 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -25,6 +25,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/context.c
+ * \ingroup bke
+ */
+
+
#include <string.h>
#include <stddef.h>
@@ -114,7 +119,7 @@ bContext *CTX_copy(const bContext *C)
return newC;
}
-#ifdef EVENT_RECORDER
+#if defined(EVENT_RECORDER) && !defined(BUILDING_GAMEPLAYER)
extern GHOST_SystemHandle g_system;
int CTX_rec_events(bContext *C)
@@ -854,7 +859,7 @@ static const char *data_mode_strings[] = {
"sculpt_mode",
"weightpaint",
"vertexpaint",
- "texturepaint",
+ "imagepaint",
"particlemode",
"objectmode",
NULL
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 67e988249f5..b374727b87c 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -30,6 +30,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/curve.c
+ * \ingroup bke
+ */
+
+
#include <math.h> // floor
#include <string.h>
#include <stdlib.h>
@@ -329,19 +334,19 @@ void tex_space_curve(Curve *cu)
cu->size[1]= (max[1]-min[1])/2.0f;
cu->size[2]= (max[2]-min[2])/2.0f;
- cu->rot[0]= cu->rot[1]= cu->rot[2]= 0.0;
+ cu->rot[0]= cu->rot[1]= cu->rot[2]= 0.0f;
- if(cu->size[0]==0.0) cu->size[0]= 1.0;
- else if(cu->size[0]>0.0 && cu->size[0]<0.00001) cu->size[0]= 0.00001;
- else if(cu->size[0]<0.0 && cu->size[0]> -0.00001) cu->size[0]= -0.00001;
+ if(cu->size[0]==0.0f) cu->size[0]= 1.0f;
+ else if(cu->size[0]>0.0f && cu->size[0]<0.00001f) cu->size[0]= 0.00001f;
+ else if(cu->size[0]<0.0f && cu->size[0]> -0.00001f) cu->size[0]= -0.00001f;
- if(cu->size[1]==0.0) cu->size[1]= 1.0;
- else if(cu->size[1]>0.0 && cu->size[1]<0.00001) cu->size[1]= 0.00001;
- else if(cu->size[1]<0.0 && cu->size[1]> -0.00001) cu->size[1]= -0.00001;
+ if(cu->size[1]==0.0f) cu->size[1]= 1.0f;
+ else if(cu->size[1]>0.0f && cu->size[1]<0.00001f) cu->size[1]= 0.00001f;
+ else if(cu->size[1]<0.0f && cu->size[1]> -0.00001f) cu->size[1]= -0.00001f;
- if(cu->size[2]==0.0) cu->size[2]= 1.0;
- else if(cu->size[2]>0.0 && cu->size[2]<0.00001) cu->size[2]= 0.00001;
- else if(cu->size[2]<0.0 && cu->size[2]> -0.00001) cu->size[2]= -0.00001;
+ if(cu->size[2]==0.0f) cu->size[2]= 1.0f;
+ else if(cu->size[2]>0.0f && cu->size[2]<0.00001f) cu->size[2]= 0.00001f;
+ else if(cu->size[2]<0.0f && cu->size[2]> -0.00001f) cu->size[2]= -0.00001f;
}
}
@@ -586,7 +591,7 @@ static void calcknots(float *knots, short aantal, short order, short type)
k= 0.0;
for(a=1;a<=t;a++) {
knots[a-1]= k;
- if(a>=order && a<=aantal) k+= 1.0;
+ if(a>=order && a<=aantal) k+= 1.0f;
}
}
else if(type==2) {
@@ -594,15 +599,15 @@ static void calcknots(float *knots, short aantal, short order, short type)
if(order==4) {
k= 0.34;
for(a=0;a<t;a++) {
- knots[a]= (float)floor(k);
- k+= (1.0/3.0);
+ knots[a]= floorf(k);
+ k+= (1.0f/3.0f);
}
}
else if(order==3) {
- k= 0.6;
+ k= 0.6f;
for(a=0;a<t;a++) {
- if(a>=order && a<=aantal) k+= (0.5);
- knots[a]= (float)floor(k);
+ if(a>=order && a<=aantal) k+= 0.5f;
+ knots[a]= floorf(k);
}
}
else {
@@ -626,7 +631,7 @@ static void makecyclicknots(float *knots, short pnts, short order)
for(a=1; a<order2; a++) {
if(knots[b]!= knots[b-a]) break;
}
- if(a==order2) knots[pnts+order-2]+= 1.0;
+ if(a==order2) knots[pnts+order-2]+= 1.0f;
}
b= order;
@@ -718,12 +723,12 @@ static void basisNurb(float t, short order, short pnts, float *knots, float *bas
if(i2+j>= orderpluspnts) i2= opp2-j;
for(i= i1; i<=i2; i++) {
- if(basis[i]!=0.0)
+ if(basis[i]!=0.0f)
d= ((t-knots[i])*basis[i]) / (knots[i+j-1]-knots[i]);
else
- d= 0.0;
+ d= 0.0f;
- if(basis[i+1]!=0.0)
+ if(basis[i+1] != 0.0f)
e= ((knots[i+j]-t)*basis[i+1]) / (knots[i+j]-knots[i+1]);
else
e= 0.0;
@@ -736,7 +741,7 @@ static void basisNurb(float t, short order, short pnts, float *knots, float *bas
*end= 0;
for(i=i1; i<=i2; i++) {
- if(basis[i]>0.0) {
+ if(basis[i] > 0.0f) {
*end= i;
if(*start==1000) *start= i;
}
@@ -778,7 +783,7 @@ void makeNurbfaces(Nurb *nu, float *coord_array, int rowstride, int resolu, int
i= nu->pntsu*nu->pntsv;
ratcomp=0;
while(i--) {
- if(bp->vec[3]!=1.0) {
+ if(bp->vec[3] != 1.0f) {
ratcomp= 1;
break;
}
@@ -884,7 +889,7 @@ void makeNurbfaces(Nurb *nu, float *coord_array, int rowstride, int resolu, int
}
else bp++;
- if(*fp!=0.0) {
+ if(*fp != 0.0f) {
in[0]+= (*fp) * bp->vec[0];
in[1]+= (*fp) * bp->vec[1];
in[2]+= (*fp) * bp->vec[2];
@@ -960,7 +965,7 @@ void makeNurbcurve(Nurb *nu, float *coord_array, float *tilt_array, float *radiu
*fp= basisu[i]*bp->vec[3];
sumdiv+= *fp;
}
- if(sumdiv!=0.0) if(sumdiv<0.999 || sumdiv>1.001) {
+ if(sumdiv != 0.0f) if(sumdiv < 0.999f || sumdiv > 1.001f) {
/* is normalizing needed? */
fp= sum;
for(i= istart; i<=iend; i++, fp++) {
@@ -976,7 +981,7 @@ void makeNurbcurve(Nurb *nu, float *coord_array, float *tilt_array, float *radiu
if(i>=nu->pntsu) bp= nu->bp+(i - nu->pntsu);
else bp++;
- if(*fp!=0.0) {
+ if(*fp != 0.0f) {
coord_fp[0]+= (*fp) * bp->vec[0];
coord_fp[1]+= (*fp) * bp->vec[1];
@@ -1260,7 +1265,7 @@ void makebevelcurve(Scene *scene, Object *ob, ListBase *disp, int forRender)
if (cu->bevobj->type!=OB_CURVE) return;
bevcu= cu->bevobj->data;
- if(bevcu->ext1==0.0 && bevcu->ext2==0.0) {
+ if(bevcu->ext1==0.0f && bevcu->ext2==0.0f) {
ListBase bevdisp= {NULL, NULL};
facx= cu->bevobj->size[0];
facy= cu->bevobj->size[1];
@@ -1301,10 +1306,10 @@ void makebevelcurve(Scene *scene, Object *ob, ListBase *disp, int forRender)
freedisplist(&bevdisp);
}
}
- else if(cu->ext1==0.0 && cu->ext2==0.0) {
+ else if(cu->ext1==0.0f && cu->ext2==0.0f) {
;
}
- else if(cu->ext2==0.0) {
+ else if(cu->ext2==0.0f) {
dl= MEM_callocN(sizeof(DispList), "makebevelcurve2");
dl->verts= MEM_mallocN(2*3*sizeof(float), "makebevelcurve2");
BLI_addtail(disp, dl);
@@ -1333,13 +1338,13 @@ void makebevelcurve(Scene *scene, Object *ob, ListBase *disp, int forRender)
/* a circle */
fp= dl->verts;
- dangle= (2.0f*M_PI/(nr));
+ dangle= (2.0f*(float)M_PI/(nr));
angle= -(nr-1)*dangle;
for(a=0; a<nr; a++) {
fp[0]= 0.0;
- fp[1]= (float)(cos(angle)*(cu->ext2));
- fp[2]= (float)(sin(angle)*(cu->ext2)) - cu->ext1;
+ fp[1]= (cosf(angle)*(cu->ext2));
+ fp[2]= (sinf(angle)*(cu->ext2)) - cu->ext1;
angle+= dangle;
fp+= 3;
}
@@ -1370,15 +1375,15 @@ void makebevelcurve(Scene *scene, Object *ob, ListBase *disp, int forRender)
for(a=0; a<nr; a++) {
fp[0]= 0.0;
- fp[1]= (float)(cos(angle)*(cu->ext2));
- fp[2]= (float)(sin(angle)*(cu->ext2)) - cu->ext1;
+ fp[1]= (float)(cosf(angle)*(cu->ext2));
+ fp[2]= (float)(sinf(angle)*(cu->ext2)) - cu->ext1;
angle+= dangle;
fp+= 3;
}
}
/* part 2, sidefaces */
- if(cu->ext1!=0.0) {
+ if(cu->ext1!=0.0f) {
nr= 2;
dl= MEM_callocN(sizeof(DispList), "makebevelcurve p2");
@@ -1428,8 +1433,8 @@ void makebevelcurve(Scene *scene, Object *ob, ListBase *disp, int forRender)
for(a=0; a<nr; a++) {
fp[0]= 0.0;
- fp[1]= (float)(cos(angle)*(cu->ext2));
- fp[2]= (float)(sin(angle)*(cu->ext2)) + cu->ext1;
+ fp[1]= (float)(cosf(angle)*(cu->ext2));
+ fp[2]= (float)(sinf(angle)*(cu->ext2)) + cu->ext1;
angle+= dangle;
fp+= 3;
}
@@ -1448,7 +1453,7 @@ static int cu_isectLL(float *v1, float *v2, float *v3, float *v4, short cox, sho
float deler;
deler= (v1[cox]-v2[cox])*(v3[coy]-v4[coy])-(v3[cox]-v4[cox])*(v1[coy]-v2[coy]);
- if(deler==0.0) return -1;
+ if(deler==0.0f) return -1;
*labda= (v1[coy]-v3[coy])*(v3[cox]-v4[cox])-(v1[cox]-v3[cox])*(v3[coy]-v4[coy]);
*labda= -(*labda/deler);
@@ -1463,8 +1468,8 @@ static int cu_isectLL(float *v1, float *v2, float *v3, float *v4, short cox, sho
vec[cox]= *labda*(v2[cox]-v1[cox])+v1[cox];
vec[coy]= *labda*(v2[coy]-v1[coy])+v1[coy];
- if(*labda>=0.0 && *labda<=1.0 && *mu>=0.0 && *mu<=1.0) {
- if(*labda==0.0 || *labda==1.0 || *mu==0.0 || *mu==1.0) return 1;
+ if(*labda>=0.0f && *labda<=1.0f && *mu>=0.0f && *mu<=1.0f) {
+ if(*labda==0.0f || *labda==1.0f || *mu==0.0f || *mu==1.0f) return 1;
return 2;
}
return 0;
@@ -1509,7 +1514,7 @@ static short bevelinside(BevList *bl1,BevList *bl2)
/* 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
*/
- if(mode>=0 && lab!=0.0) {
+ if(mode >= 0 && lab != 0.0f) {
if(vec[0]<hvec1[0]) links++;
else rechts++;
}
@@ -1547,8 +1552,8 @@ static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2, float *si
t01= (float)sqrt(x1*x1+y1*y1);
t02= (float)sqrt(x2*x2+y2*y2);
- if(t01==0.0) t01= 1.0;
- if(t02==0.0) t02= 1.0;
+ if(t01==0.0f) t01= 1.0f;
+ if(t02==0.0f) t02= 1.0f;
x1/=t01;
y1/=t01;
@@ -1560,7 +1565,7 @@ static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2, float *si
else t02= (saacos(t02))/2.0f;
t02= (float)sin(t02);
- if(t02==0.0) t02= 1.0;
+ if(t02==0.0f) t02= 1.0f;
x3= x1-x2;
y3= y1-y2;
@@ -1697,7 +1702,7 @@ static void bevel_list_flip_tangents(BevList *bl)
nr= bl->nr;
while(nr--) {
- if(RAD2DEG(angle_v2v2(bevp0->tan, bevp1->tan)) > 90)
+ if(RAD2DEGF(angle_v2v2(bevp0->tan, bevp1->tan)) > 90.0f)
negate_v3(bevp1->tan);
bevp0= bevp1;
@@ -1708,13 +1713,12 @@ static void bevel_list_flip_tangents(BevList *bl)
/* apply user tilt */
static void bevel_list_apply_tilt(BevList *bl)
{
- BevPoint *bevp2, *bevp1, *bevp0;
+ BevPoint *bevp2, *bevp1;
int nr;
float q[4];
bevp2= (BevPoint *)(bl+1);
bevp1= bevp2+(bl->nr-1);
- bevp0= bevp1-1;
nr= bl->nr;
while(nr--) {
@@ -1722,7 +1726,6 @@ static void bevel_list_apply_tilt(BevList *bl)
mul_qt_qtqt(bevp1->quat, q, bevp1->quat);
normalize_qt(bevp1->quat);
- bevp0= bevp1;
bevp1= bevp2;
bevp2++;
}
@@ -1887,7 +1890,7 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl)
/* flip rotation if needs be */
cross_v3_v3v3(cross_tmp, vec_1, vec_2);
normalize_v3(cross_tmp);
- if(angle_normalized_v3v3(bevp_first->dir, cross_tmp) < 90/(180.0/M_PI))
+ if(angle_normalized_v3v3(bevp_first->dir, cross_tmp) < 90.0f/(float)(180.0/M_PI))
angle = -angle;
bevp2= (BevPoint *)(bl+1);
@@ -2281,7 +2284,7 @@ void makeBevelList(Object *ob)
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;
+ if(inp > 0.0f) sd->dir= 1;
else sd->dir= 0;
sd++;
@@ -2481,11 +2484,11 @@ void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode)
if(mode==2 && next && prev) { // keep horizontal if extrema
float ydiff1= prev->vec[1][1] - bezt->vec[1][1];
float ydiff2= next->vec[1][1] - bezt->vec[1][1];
- if( (ydiff1<=0.0 && ydiff2<=0.0) || (ydiff1>=0.0 && ydiff2>=0.0) ) {
+ if( (ydiff1 <= 0.0f && ydiff2 <= 0.0f) || (ydiff1 >= 0.0f && ydiff2 >= 0.0f) ) {
bezt->vec[0][1]= bezt->vec[1][1];
}
else { // handles should not be beyond y coord of two others
- if(ydiff1<=0.0) {
+ if(ydiff1 <= 0.0f) {
if(prev->vec[1][1] > bezt->vec[0][1]) {
bezt->vec[0][1]= prev->vec[1][1];
leftviolate= 1;
@@ -2509,11 +2512,11 @@ void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode)
if(mode==2 && next && prev) { // keep horizontal if extrema
float ydiff1= prev->vec[1][1] - bezt->vec[1][1];
float ydiff2= next->vec[1][1] - bezt->vec[1][1];
- if( (ydiff1<=0.0 && ydiff2<=0.0) || (ydiff1>=0.0 && ydiff2>=0.0) ) {
+ if( (ydiff1 <= 0.0f && ydiff2 <= 0.0f) || (ydiff1 >= 0.0f && ydiff2 >= 0.0f) ) {
bezt->vec[2][1]= bezt->vec[1][1];
}
else { // handles should not be beyond y coord of two others
- if(ydiff1<=0.0) {
+ if(ydiff1 <= 0.0f) {
if(next->vec[1][1] < bezt->vec[2][1]) {
bezt->vec[2][1]= next->vec[1][1];
rightviolate= 1;
@@ -2554,17 +2557,17 @@ void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode)
}
if(bezt->h1==HD_VECT) { /* vector */
- dx/=3.0;
- dy/=3.0;
- dz/=3.0;
+ dx/=3.0f;
+ dy/=3.0f;
+ dz/=3.0f;
*(p2-3)= *p2-dx;
*(p2-2)= *(p2+1)-dy;
*(p2-1)= *(p2+2)-dz;
}
if(bezt->h2==HD_VECT) {
- dx1/=3.0;
- dy1/=3.0;
- dz1/=3.0;
+ dx1/=3.0f;
+ dy1/=3.0f;
+ dz1/=3.0f;
*(p2+3)= *p2+dx1;
*(p2+4)= *(p2+1)+dy1;
*(p2+5)= *(p2+2)+dz1;
@@ -2572,8 +2575,8 @@ void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode)
len2= len_v3v3(p2, p2+3);
len1= len_v3v3(p2, p2-3);
- if(len1==0.0) len1=1.0;
- if(len2==0.0) len2=1.0;
+ if(len1==0.0f) len1= 1.0f;
+ if(len2==0.0f) len2= 1.0f;
if(bezt->f1 & SELECT) { /* order of calculation */
if(bezt->h2==HD_ALIGN) { /* aligned */
@@ -2698,18 +2701,18 @@ void autocalchandlesNurb(Nurb *nu, int flag)
if(flag==0 || (bezt1->f1 & flag) ) {
bezt1->h1= 0;
/* distance too short: vectorhandle */
- if( len_v3v3( bezt1->vec[1], bezt0->vec[1] ) < 0.0001) {
+ if( len_v3v3( bezt1->vec[1], bezt0->vec[1] ) < 0.0001f) {
bezt1->h1= HD_VECT;
leftsmall= 1;
}
else {
/* aligned handle? */
- if(dist_to_line_v2(bezt1->vec[1], bezt1->vec[0], bezt1->vec[2]) < 0.0001) {
+ if(dist_to_line_v2(bezt1->vec[1], bezt1->vec[0], bezt1->vec[2]) < 0.0001f) {
align= 1;
bezt1->h1= HD_ALIGN;
}
/* or vector handle? */
- if(dist_to_line_v2(bezt1->vec[0], bezt1->vec[1], bezt0->vec[1]) < 0.0001)
+ if(dist_to_line_v2(bezt1->vec[0], bezt1->vec[1], bezt0->vec[1]) < 0.0001f)
bezt1->h1= HD_VECT;
}
@@ -2718,7 +2721,7 @@ void autocalchandlesNurb(Nurb *nu, int flag)
if(flag==0 || (bezt1->f3 & flag) ) {
bezt1->h2= 0;
/* distance too short: vectorhandle */
- if( len_v3v3( bezt1->vec[1], bezt2->vec[1] ) < 0.0001) {
+ if( len_v3v3( bezt1->vec[1], bezt2->vec[1] ) < 0.0001f) {
bezt1->h2= HD_VECT;
rightsmall= 1;
}
@@ -2727,7 +2730,7 @@ void autocalchandlesNurb(Nurb *nu, int flag)
if(align) bezt1->h2= HD_ALIGN;
/* or vector handle? */
- if(dist_to_line_v2(bezt1->vec[2], bezt1->vec[1], bezt2->vec[1]) < 0.0001)
+ if(dist_to_line_v2(bezt1->vec[2], bezt1->vec[1], bezt2->vec[1]) < 0.0001f)
bezt1->h2= HD_VECT;
}
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 98d33e208bc..b29a669ed05 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -30,7 +30,12 @@
*
* BKE_customdata.h contains the function prototypes for this file.
*
-*/
+*/
+
+/** \file blender/blenkernel/intern/customdata.c
+ * \ingroup bke
+ */
+
#include <math.h>
#include <string.h>
@@ -453,13 +458,6 @@ static void layerInterp_mdisps(void **sources, float *UNUSED(weights),
float *sub_weights, int count, void *dest)
{
MDisps *d = dest;
- MDisps *s = NULL;
- int st, stl;
- int i, x, y;
- int side, S, dst_corners, src_corners;
- float crn_weight[4][2];
- float (*sw)[4] = (void*)sub_weights;
- float (*disps)[3], (*out)[3];
/* happens when flipping normals of newly created mesh */
if(!d->totdisp) {
@@ -468,104 +466,6 @@ static void layerInterp_mdisps(void **sources, float *UNUSED(weights),
if (!d->disps && d->totdisp)
d->disps = BLI_cellalloc_calloc(sizeof(float)*3*d->totdisp, "blank mdisps in layerInterp_mdisps");
-#if 0
- s = sources[0];
- dst_corners = multires_mdisp_corners(d);
- src_corners = multires_mdisp_corners(s);
-
- if(sub_weights && count == 2 && src_corners == 3) {
- src_corners = multires_mdisp_corners(sources[1]);
-
- /* special case -- converting two triangles to quad */
- if(src_corners == 3 && dst_corners == 4) {
- MDisps tris[2];
- int vindex[4] = {0};
-
- S = 0;
- for(i = 0; i < 2; i++)
- for(y = 0; y < 4; y++)
- for(x = 0; x < 4; x++)
- if(sw[x+i*4][y])
- vindex[x] = y;
-
- for(i = 0; i < 2; i++) {
- float sw_m4[4][4] = {{0}};
- int a = 7 & ~(1 << vindex[i*2] | 1 << vindex[i*2+1]);
-
- sw_m4[0][vindex[i*2+1]] = 1;
- sw_m4[1][vindex[i*2]] = 1;
-
- for(x = 0; x < 3; x++)
- if(a & (1 << x))
- sw_m4[2][x] = 1;
-
- tris[i] = *((MDisps*)sources[i]);
- tris[i].disps = BLI_cellalloc_dupalloc(tris[i].disps);
- layerInterp_mdisps(&sources[i], NULL, (float*)sw_m4, 1, &tris[i]);
- }
-
- mdisp_join_tris(d, &tris[0], &tris[1]);
-
- for(i = 0; i < 2; i++)
- BLI_cellalloc_free(tris[i].disps);
-
- return;
- }
- }
-
- /* For now, some restrictions on the input */
- if(count != 1 || !sub_weights) {
- for(i = 0; i < d->totdisp; ++i)
- zero_v3(d->disps[i]);
-
- return;
- }
-
- /* Initialize the destination */
- out = disps = BLI_cellalloc_calloc(3*d->totdisp*sizeof(float), "iterp disps");
-
- side = sqrt(d->totdisp / dst_corners);
- st = (side<<1)-1;
- stl = st - 1;
-
- sw= (void*)sub_weights;
- for(i = 0; i < 4; ++i) {
- crn_weight[i][0] = 0 * sw[i][0] + stl * sw[i][1] + stl * sw[i][2] + 0 * sw[i][3];
- crn_weight[i][1] = 0 * sw[i][0] + 0 * sw[i][1] + stl * sw[i][2] + stl * sw[i][3];
- }
-
- multires_mdisp_smooth_bounds(s);
-
- out = disps;
- for(S = 0; S < dst_corners; S++) {
- float base[2], axis_x[2], axis_y[2];
-
- mdisp_apply_weight(S, dst_corners, 0, 0, st, crn_weight, &base[0], &base[1]);
- mdisp_apply_weight(S, dst_corners, side-1, 0, st, crn_weight, &axis_x[0], &axis_x[1]);
- mdisp_apply_weight(S, dst_corners, 0, side-1, st, crn_weight, &axis_y[0], &axis_y[1]);
-
- sub_v2_v2(axis_x, base);
- sub_v2_v2(axis_y, base);
- normalize_v2(axis_x);
- normalize_v2(axis_y);
-
- for(y = 0; y < side; ++y) {
- for(x = 0; x < side; ++x, ++out) {
- int crn;
- float face_u, face_v, crn_u, crn_v;
-
- mdisp_apply_weight(S, dst_corners, x, y, st, crn_weight, &face_u, &face_v);
- crn = mdisp_rot_face_to_crn(src_corners, st, face_u, face_v, &crn_u, &crn_v);
-
- old_mdisps_bilinear((*out), &s->disps[crn*side*side], side, crn_u, crn_v);
- mdisp_flip_disp(crn, dst_corners, axis_x, axis_y, *out);
- }
- }
- }
-
- BLI_cellalloc_free(d->disps);
- d->disps = disps;
-#endif
}
static void layerCopy_mdisps(const void *source, void *dest, int count)
diff --git a/source/blender/blenkernel/intern/customdata_file.c b/source/blender/blenkernel/intern/customdata_file.c
index 6fb79a0df28..ab639897866 100644
--- a/source/blender/blenkernel/intern/customdata_file.c
+++ b/source/blender/blenkernel/intern/customdata_file.c
@@ -20,6 +20,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/customdata_file.c
+ * \ingroup bke
+ */
+
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -310,11 +315,11 @@ int cdf_read_layer(CDataFile *cdf, CDataFileLayer *blay)
return (fseek(cdf->readf, offset, SEEK_SET) == 0);
}
-int cdf_read_data(CDataFile *cdf, int size, void *data)
+int cdf_read_data(CDataFile *cdf, unsigned int size, void *data)
{
float *fdata;
- int a;
-
+ unsigned int a;
+
/* read data */
if(!fread(data, size, 1, cdf->readf))
return 0;
@@ -385,7 +390,7 @@ int cdf_write_layer(CDataFile *UNUSED(cdf), CDataFileLayer *UNUSED(blay))
return 1;
}
-int cdf_write_data(CDataFile *cdf, int size, void *data)
+int cdf_write_data(CDataFile *cdf, unsigned int size, void *data)
{
/* write data */
if(!fwrite(data, size, 1, cdf->writef))
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c
index 616bcb17f90..a0f8a0f13ee 100644
--- a/source/blender/blenkernel/intern/deform.c
+++ b/source/blender/blenkernel/intern/deform.c
@@ -32,6 +32,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/deform.c
+ * \ingroup bke
+ */
+
+
#include <string.h>
#include <math.h>
#include "ctype.h"
diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c
index c437c4fe61f..ff49c64ebf4 100644
--- a/source/blender/blenkernel/intern/depsgraph.c
+++ b/source/blender/blenkernel/intern/depsgraph.c
@@ -24,6 +24,11 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
+
+/** \file blender/blenkernel/intern/depsgraph.c
+ * \ingroup bke
+ */
+
#include <stdio.h>
#include <string.h>
@@ -1551,10 +1556,9 @@ void graph_print_queue(DagNodeQueue *nqueue)
void graph_print_queue_dist(DagNodeQueue *nqueue)
{
DagNodeQueueElem *queueElem;
- int max, count;
+ int count;
queueElem = nqueue->first;
- max = queueElem->node->DFS_fntm;
count = 0;
while(queueElem) {
fprintf(stderr,"** %25s %2.2i-%2.2i ",((ID *) queueElem->node->ob)->name,queueElem->node->DFS_dvtm,queueElem->node->DFS_fntm);
@@ -2266,7 +2270,7 @@ void DAG_ids_flush_update(Main *bmain, int time)
DAG_scene_flush_update(bmain, sce, lay, time);
}
-void DAG_on_load_update(Main *bmain, const short do_time)
+void DAG_on_visible_update(Main *bmain, const short do_time)
{
Scene *scene;
Base *base;
@@ -2291,7 +2295,7 @@ void DAG_on_load_update(Main *bmain, const short do_time)
node= (sce_iter->theDag)? dag_get_node(sce_iter->theDag, ob): NULL;
oblay= (node)? node->lay: ob->lay;
- if(oblay & lay) {
+ if((oblay & lay) & ~scene->lay_updated) {
if(ELEM6(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_LATTICE))
ob->recalc |= OB_RECALC_DATA;
if(ob->dup_group)
@@ -2314,6 +2318,7 @@ void DAG_on_load_update(Main *bmain, const short do_time)
/* now tag update flags, to ensure deformers get calculated on redraw */
DAG_scene_update_flags(bmain, scene, lay, do_time);
+ scene->lay_updated |= lay;
}
}
diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c
index 59e5aa7ade6..1610b510dac 100644
--- a/source/blender/blenkernel/intern/displist.c
+++ b/source/blender/blenkernel/intern/displist.c
@@ -29,6 +29,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/displist.c
+ * \ingroup bke
+ */
+
+
#include <math.h>
#include <stdio.h>
#include <string.h>
@@ -173,8 +178,8 @@ void addnormalsDispList(ListBase *lb)
if(dl->type==DL_INDEX3) {
if(dl->nors==NULL) {
dl->nors= MEM_callocN(sizeof(float)*3, "dlnors");
- if(dl->verts[2]<0.0) dl->nors[2]= -1.0;
- else dl->nors[2]= 1.0;
+ if(dl->verts[2] < 0.0f) dl->nors[2]= -1.0f;
+ else dl->nors[2]= 1.0f;
}
}
else if(dl->type==DL_SURF) {
@@ -408,10 +413,10 @@ static void fastshade(float *co, float *nor, float *orco, Material *ma, char *co
VECCOPY(shi.orn, shi.vn);
}
if(ma->texco & TEXCO_REFL) {
- float inp= 2.0*(shi.vn[2]);
+ float inp= 2.0f * (shi.vn[2]);
shi.ref[0]= (inp*shi.vn[0]);
shi.ref[1]= (inp*shi.vn[1]);
- shi.ref[2]= (-1.0+inp*shi.vn[2]);
+ shi.ref[2]= (-1.0f + inp*shi.vn[2]);
}
}
@@ -584,9 +589,7 @@ static void mesh_create_shadedColors(Render *re, Object *ob, int onlyForMesh, un
mul_v3_m4v3(vec, mat, mv->co);
- vec[0]+= 0.001*vn[0];
- vec[1]+= 0.001*vn[1];
- vec[2]+= 0.001*vn[2];
+ mul_v3_v3fl(vec, vn, 0.001f);
fastshade_customdata(&dm->faceData, i, j, ma);
fastshade(vec, vn, orco?&orco[vidx[j]*3]:mv->co, ma, col1, col2);
@@ -1155,7 +1158,7 @@ float calc_taper(Scene *scene, Object *taperobj, int cur, int tot)
/* horizontal size */
minx= dl->verts[0];
dx= dl->verts[3*(dl->nr-1)] - minx;
- if(dx>0.0) {
+ if(dx > 0.0f) {
fp= dl->verts;
for(a=0; a<dl->nr; a++, fp+=3) {
@@ -1736,7 +1739,7 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
if (!dlbev.first && cu->width==1.0f) {
curve_to_displist(cu, nubase, dispbase, forRender);
} else {
- float widfac= cu->width-1.0;
+ float widfac= cu->width - 1.0f;
BevList *bl= cu->bev.first;
Nurb *nu= nubase->first;
diff --git a/source/blender/blenkernel/intern/editderivedbmesh.c b/source/blender/blenkernel/intern/editderivedbmesh.c
index 1479cb20a05..e60179101de 100644
--- a/source/blender/blenkernel/intern/editderivedbmesh.c
+++ b/source/blender/blenkernel/intern/editderivedbmesh.c
@@ -488,7 +488,7 @@ static void bmDM_drawMappedEdges(DerivedMesh *dm, int (*setDrawOptions)(void *us
}
}
-static void bmDM_drawEdges(DerivedMesh *dm, int drawLooseEdges)
+static void bmDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int drawAllEdges)
{
bmDM_drawMappedEdges(dm, NULL, NULL);
}
@@ -622,7 +622,10 @@ static void bmDM_foreachMappedFaceCenter(DerivedMesh *dm, void (*func)(void *use
}
}
-static void bmDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r), void *userData, int useColors)
+static void bmDM_drawMappedFaces(DerivedMesh *dm,
+ int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r),
+ void *userData, int useColors,
+ int (*setMaterial)(int, void *attribs))
{
EditDerivedBMesh *bmdm= (EditDerivedBMesh*) dm;
BMFace *efa;
@@ -1492,9 +1495,9 @@ DMLoopIter *bmDM_newLoopsIter(void *faceiter)
return (DMLoopIter*) iter;
}
-static DMFaceIter *bmDM_getFaceIter(void *dm)
+static DMFaceIter *bmDM_getFaceIter(DerivedMesh *dm)
{
- EditDerivedBMesh *bmdm= dm;
+ EditDerivedBMesh *bmdm= (EditDerivedBMesh*)dm;
bmDM_faceIter *iter = MEM_callocN(sizeof(bmDM_faceIter), "bmDM_faceIter");
BMIter biter;
BMVert *v;
@@ -1528,9 +1531,9 @@ static DMFaceIter *bmDM_getFaceIter(void *dm)
return (DMFaceIter*) iter;
}
-static void bmDM_release(void *dm)
+static void bmDM_release(DerivedMesh *dm)
{
- EditDerivedBMesh *bmdm= dm;
+ EditDerivedBMesh *bmdm= (EditDerivedBMesh *)dm;
if (DM_release(dm)) {
if (bmdm->vertexCos) {
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c
index 5d8401d7a43..ab69196e8b6 100644
--- a/source/blender/blenkernel/intern/effect.c
+++ b/source/blender/blenkernel/intern/effect.c
@@ -29,6 +29,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/effect.c
+ * \ingroup bke
+ */
+
+
#include <stddef.h>
#include "BLI_storage.h" /* _LARGEFILE_SOURCE */
@@ -356,12 +361,18 @@ void pdEndEffectors(ListBase **effectors)
void pd_point_from_particle(ParticleSimulationData *sim, ParticleData *pa, ParticleKey *state, EffectedPoint *point)
{
+ ParticleSettings *part = sim->psys->part;
point->loc = state->co;
point->vel = state->vel;
point->index = pa - sim->psys->particles;
point->size = pa->size;
- /* TODO: point->charge */
- point->charge = 1.0f;
+ point->charge = 0.0f;
+
+ if(part->pd && part->pd->forcefield == PFIELD_CHARGE)
+ point->charge += part->pd->f_strength;
+
+ if(part->pd2 && part->pd2->forcefield == PFIELD_CHARGE)
+ point->charge += part->pd2->f_strength;
point->vel_to_sec = 1.0f;
point->vel_to_frame = psys_get_timestep(sim);
@@ -484,7 +495,7 @@ static float wind_func(struct RNG *rng, float strength)
float ret;
float sign = 0;
- sign = ((float)random > 64.0) ? 1.0: -1.0; // dividing by 2 is not giving equal sign distribution
+ sign = ((float)random > 64.0f) ? 1.0f: -1.0f; // dividing by 2 is not giving equal sign distribution
ret = sign*((float)random / force)*strength/128.0f;
@@ -506,7 +517,7 @@ static float falloff_func(float fac, int usemin, float mindist, int usemax, floa
if(!usemin)
mindist = 0.0;
- return pow((double)1.0+fac-mindist, (double)-power);
+ return pow((double)(1.0f+fac-mindist), (double)(-power));
}
static float falloff_func_dist(PartDeflect *pd, float fac)
@@ -642,7 +653,7 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin
sim.psys= eff->psys;
/* TODO: time from actual previous calculated frame (step might not be 1) */
- state.time = cfra - 1.0;
+ state.time = cfra - 1.0f;
ret = psys_get_particle_state(&sim, *efd->index, &state, 0);
/* TODO */
@@ -676,13 +687,16 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin
/* use z-axis as normal*/
normalize_v3_v3(efd->nor, ob->obmat[2]);
- /* for vortex the shape chooses between old / new force */
if(eff->pd && eff->pd->shape == PFIELD_SHAPE_PLANE) {
- /* efd->loc is closes point on effector xy-plane */
float temp[3], translate[3];
sub_v3_v3v3(temp, point->loc, ob->obmat[3]);
project_v3_v3v3(translate, temp, efd->nor);
- add_v3_v3v3(efd->loc, ob->obmat[3], translate);
+
+ /* for vortex the shape chooses between old / new force */
+ if(eff->pd->forcefield == PFIELD_VORTEX)
+ add_v3_v3v3(efd->loc, ob->obmat[3], translate);
+ else /* normally efd->loc is closest point on effector xy-plane */
+ sub_v3_v3v3(efd->loc, point->loc, translate);
}
else {
VECCOPY(efd->loc, ob->obmat[3]);
@@ -691,7 +705,7 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin
if(real_velocity) {
VECCOPY(efd->vel, ob->obmat[3]);
- where_is_object_time(eff->scene, ob, cfra - 1.0);
+ where_is_object_time(eff->scene, ob, cfra - 1.0f);
sub_v3_v3v3(efd->vel, efd->vel, ob->obmat[3]);
}
@@ -917,10 +931,10 @@ static void do_physical_effector(EffectorCache *eff, EffectorData *efd, Effected
case PFIELD_LENNARDJ:
fac = pow((efd->size + point->size) / efd->distance, 6.0);
- fac = - fac * (1.0 - fac) / efd->distance;
+ fac = - fac * (1.0f - fac) / efd->distance;
/* limit the repulsive term drastically to avoid huge forces */
- fac = ((fac>2.0) ? 2.0 : fac);
+ fac = ((fac>2.0f) ? 2.0f : fac);
mul_v3_fl(force, strength * fac);
break;
diff --git a/source/blender/blenkernel/intern/exotic.c b/source/blender/blenkernel/intern/exotic.c
index 4afce1e56c4..53384d790e0 100644
--- a/source/blender/blenkernel/intern/exotic.c
+++ b/source/blender/blenkernel/intern/exotic.c
@@ -31,6 +31,11 @@
* ***** END GPL LICENSE BLOCK ****
*/
+/** \file blender/blenkernel/intern/exotic.c
+ * \ingroup bke
+ */
+
+
#include <stddef.h>
#include "BLI_storage.h"
@@ -177,12 +182,10 @@ static void mesh_add_normals_flags(Mesh *me)
v2= me->mvert+mface->v2;
v3= me->mvert+mface->v3;
v4= me->mvert+mface->v4;
-
+
normal_tri_v3( nor,v1->co, v2->co, v3->co);
- sno[0]= 32767.0*nor[0];
- sno[1]= 32767.0*nor[1];
- sno[2]= 32767.0*nor[2];
-
+ normal_float_to_short_v3(sno, nor);
+
simple_vertex_normal_blend(v1->no, sno);
simple_vertex_normal_blend(v2->no, sno);
simple_vertex_normal_blend(v3->no, sno);
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index b50943ba9f1..b1272ee2d53 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -26,6 +26,11 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
+
+/** \file blender/blenkernel/intern/fcurve.c
+ * \ingroup bke
+ */
+
#include <math.h>
@@ -421,8 +426,52 @@ int binarysearch_bezt_index (BezTriple array[], float frame, int arraylen, short
return start;
}
+/* ...................................... */
+
+/* helper for calc_fcurve_* functions -> find first and last BezTriple to be used */
+static void get_fcurve_end_keyframes (FCurve *fcu, BezTriple **first, BezTriple **last, const short selOnly)
+{
+ /* init outputs */
+ *first = NULL;
+ *last = NULL;
+
+ /* sanity checks */
+ if (fcu->bezt == NULL)
+ return;
+
+ /* only include selected items? */
+ if (selOnly) {
+ BezTriple *bezt;
+ unsigned int i;
+
+ /* find first selected */
+ bezt = fcu->bezt;
+ for (i=0; i < fcu->totvert; bezt++, i++) {
+ if (BEZSELECTED(bezt)) {
+ *first= bezt;
+ break;
+ }
+ }
+
+ /* find last selected */
+ bezt = ARRAY_LAST_ITEM(fcu->bezt, BezTriple, sizeof(BezTriple), fcu->totvert);
+ for (i=0; i < fcu->totvert; bezt--, i++) {
+ if (BEZSELECTED(bezt)) {
+ *last= bezt;
+ break;
+ }
+ }
+ }
+ else {
+ /* just full array */
+ *first = fcu->bezt;
+ *last = ARRAY_LAST_ITEM(fcu->bezt, BezTriple, sizeof(BezTriple), fcu->totvert);
+ }
+}
+
+
/* Calculate the extents of F-Curve's data */
-void calc_fcurve_bounds (FCurve *fcu, float *xmin, float *xmax, float *ymin, float *ymax)
+void calc_fcurve_bounds (FCurve *fcu, float *xmin, float *xmax, float *ymin, float *ymax, const short selOnly)
{
float xminv=999999999.0f, xmaxv=-999999999.0f;
float yminv=999999999.0f, ymaxv=-999999999.0f;
@@ -431,21 +480,31 @@ void calc_fcurve_bounds (FCurve *fcu, float *xmin, float *xmax, float *ymin, flo
if (fcu->totvert) {
if (fcu->bezt) {
- /* frame range can be directly calculated from end verts */
+ BezTriple *bezt_first= NULL, *bezt_last= NULL;
+
if (xmin || xmax) {
- xminv= MIN2(xminv, fcu->bezt[0].vec[1][0]);
- xmaxv= MAX2(xmaxv, fcu->bezt[fcu->totvert-1].vec[1][0]);
+ /* get endpoint keyframes */
+ get_fcurve_end_keyframes(fcu, &bezt_first, &bezt_last, selOnly);
+
+ if (bezt_first) {
+ BLI_assert(bezt_last != NULL);
+
+ xminv= MIN2(xminv, bezt_first->vec[1][0]);
+ xmaxv= MAX2(xmaxv, bezt_last->vec[1][0]);
+ }
}
/* only loop over keyframes to find extents for values if needed */
- if (ymin || ymax) {
+ if (ymin || ymax) {
BezTriple *bezt;
for (bezt=fcu->bezt, i=0; i < fcu->totvert; bezt++, i++) {
- if (bezt->vec[1][1] < yminv)
- yminv= bezt->vec[1][1];
- if (bezt->vec[1][1] > ymaxv)
- ymaxv= bezt->vec[1][1];
+ if ((selOnly == 0) || BEZSELECTED(bezt)) {
+ if (bezt->vec[1][1] < yminv)
+ yminv= bezt->vec[1][1];
+ if (bezt->vec[1][1] > ymaxv)
+ ymaxv= bezt->vec[1][1];
+ }
}
}
}
@@ -492,15 +551,24 @@ void calc_fcurve_bounds (FCurve *fcu, float *xmin, float *xmax, float *ymin, flo
}
/* Calculate the extents of F-Curve's keyframes */
-void calc_fcurve_range (FCurve *fcu, float *start, float *end)
+void calc_fcurve_range (FCurve *fcu, float *start, float *end, const short selOnly)
{
float min=999999999.0f, max=-999999999.0f;
short foundvert=0;
if (fcu->totvert) {
if (fcu->bezt) {
- min= MIN2(min, fcu->bezt[0].vec[1][0]);
- max= MAX2(max, fcu->bezt[fcu->totvert-1].vec[1][0]);
+ BezTriple *bezt_first= NULL, *bezt_last= NULL;
+
+ /* get endpoint keyframes */
+ get_fcurve_end_keyframes(fcu, &bezt_first, &bezt_last, selOnly);
+
+ if (bezt_first) {
+ BLI_assert(bezt_last != NULL);
+
+ min= MIN2(min, bezt_first->vec[1][0]);
+ max= MAX2(max, bezt_last->vec[1][0]);
+ }
}
else if (fcu->fpt) {
min= MIN2(min, fcu->fpt[0].vec[0]);
@@ -1051,7 +1119,7 @@ static float dvar_eval_rotDiff (ChannelDriver *driver, DriverVar *dvar)
angle = 2.0f * (saacos(quat[0]));
angle= ABS(angle);
- return (angle > M_PI) ? (float)((2.0f * M_PI) - angle) : (float)(angle);
+ return (angle > (float)M_PI) ? (float)((2.0f * (float)M_PI) - angle) : (float)(angle);
}
/* evaluate 'location difference' driver variable */
@@ -1584,9 +1652,9 @@ static int findzero (float x, float q0, float q1, float q2, float q3, float *o)
int nr= 0;
c0= q0 - x;
- c1= 3.0 * (q1 - q0);
- c2= 3.0 * (q0 - 2.0*q1 + q2);
- c3= q3 - q0 + 3.0 * (q1 - q2);
+ c1= 3.0f * (q1 - q0);
+ c2= 3.0f * (q0 - 2.0f*q1 + q2);
+ c3= q3 - q0 + 3.0f * (q1 - q2);
if (c3 != 0.0) {
a= c2/c3;
@@ -1602,17 +1670,17 @@ static int findzero (float x, float q0, float q1, float q2, float q3, float *o)
t= sqrt(d);
o[0]= (float)(sqrt3d(-q+t) + sqrt3d(-q-t) - a);
- if ((o[0] >= SMALL) && (o[0] <= 1.000001)) return 1;
+ if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) return 1;
else return 0;
}
else if (d == 0.0) {
t= sqrt3d(-q);
o[0]= (float)(2*t - a);
- if ((o[0] >= SMALL) && (o[0] <= 1.000001)) nr++;
+ if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) nr++;
o[nr]= (float)(-t-a);
- if ((o[nr] >= SMALL) && (o[nr] <= 1.000001)) return nr+1;
+ if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) return nr+1;
else return nr;
}
else {
@@ -1622,13 +1690,13 @@ static int findzero (float x, float q0, float q1, float q2, float q3, float *o)
q= sqrt(3 - 3*p*p);
o[0]= (float)(2*t*p - a);
- if ((o[0] >= SMALL) && (o[0] <= 1.000001)) nr++;
+ if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) nr++;
o[nr]= (float)(-t * (p + q) - a);
- if ((o[nr] >= SMALL) && (o[nr] <= 1.000001)) nr++;
+ if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) nr++;
o[nr]= (float)(-t * (p - q) - a);
- if ((o[nr] >= SMALL) && (o[nr] <= 1.000001)) return nr+1;
+ if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) return nr+1;
else return nr;
}
}
@@ -1645,22 +1713,22 @@ static int findzero (float x, float q0, float q1, float q2, float q3, float *o)
p= sqrt(p);
o[0]= (float)((-b-p) / (2 * a));
- if ((o[0] >= SMALL) && (o[0] <= 1.000001)) nr++;
+ if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) nr++;
o[nr]= (float)((-b+p)/(2*a));
- if ((o[nr] >= SMALL) && (o[nr] <= 1.000001)) return nr+1;
+ if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) return nr+1;
else return nr;
}
else if (p == 0) {
o[0]= (float)(-b / (2 * a));
- if ((o[0] >= SMALL) && (o[0] <= 1.000001)) return 1;
+ if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) return 1;
else return 0;
}
}
else if (b != 0.0) {
o[0]= (float)(-c/b);
- if ((o[0] >= SMALL) && (o[0] <= 1.000001)) return 1;
+ if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) return 1;
else return 0;
}
else if (c == 0.0) {
diff --git a/source/blender/blenkernel/intern/fluidsim.c b/source/blender/blenkernel/intern/fluidsim.c
index 810c56dbe5d..fb15f0bffdb 100644
--- a/source/blender/blenkernel/intern/fluidsim.c
+++ b/source/blender/blenkernel/intern/fluidsim.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/fluidsim.c
+ * \ingroup bke
+ */
+
+
#include <stddef.h>
#include "BLI_storage.h" /* _LARGEFILE_SOURCE */
diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c
index 804c26295bd..b5a877a7261 100644
--- a/source/blender/blenkernel/intern/fmodifier.c
+++ b/source/blender/blenkernel/intern/fmodifier.c
@@ -25,6 +25,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/fmodifier.c
+ * \ingroup bke
+ */
+
+
#include <math.h>
#include <stdio.h>
@@ -341,7 +346,7 @@ static void fcm_fn_generator_evaluate (FCurve *UNUSED(fcu), FModifier *fcm, floa
case FCM_GENERATOR_FN_LN: /* natural log */
{
/* check that value is greater than 1? */
- if (arg > 1.0f) {
+ if (arg > 1.0) {
fn= log;
}
else {
@@ -353,7 +358,7 @@ static void fcm_fn_generator_evaluate (FCurve *UNUSED(fcu), FModifier *fcm, floa
case FCM_GENERATOR_FN_SQRT: /* square root */
{
/* no negative numbers */
- if (arg > 0.0f) {
+ if (arg > 0.0) {
fn= sqrt;
}
else {
@@ -369,7 +374,7 @@ static void fcm_fn_generator_evaluate (FCurve *UNUSED(fcu), FModifier *fcm, floa
/* execute function callback to set value if appropriate */
if (fn) {
- float value= (float)(data->amplitude*fn(arg) + data->value_offset);
+ float value= (float)(data->amplitude*(float)fn(arg) + data->value_offset);
if (data->flag & FCM_GENERATOR_ADDITIVE)
*cvalue += value;
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index 05988605b4c..f8003c656bf 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -29,6 +29,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/font.c
+ * \ingroup bke
+ */
+
+
#include <stdio.h>
#include <string.h>
#include <math.h>
@@ -485,19 +490,19 @@ static void build_underline(Curve *cu, float x1, float y1, float x2, float y2, i
nu2->bp[0].vec[0] = x1;
nu2->bp[0].vec[1] = y1;
nu2->bp[0].vec[2] = 0;
- nu2->bp[0].vec[3] = 1.0;
+ nu2->bp[0].vec[3] = 1.0f;
nu2->bp[1].vec[0] = x2;
nu2->bp[1].vec[1] = y1;
nu2->bp[1].vec[2] = 0;
- nu2->bp[1].vec[3] = 1.0;
+ nu2->bp[1].vec[3] = 1.0f;
nu2->bp[2].vec[0] = x2;
nu2->bp[2].vec[1] = y2;
nu2->bp[2].vec[2] = 0;
- nu2->bp[2].vec[3] = 1.0;
+ nu2->bp[2].vec[3] = 1.0f;
nu2->bp[3].vec[0] = x1;
nu2->bp[3].vec[1] = y2;
nu2->bp[3].vec[2] = 0;
- nu2->bp[3].vec[3] = 1.0;
+ nu2->bp[3].vec[3] = 1.0f;
BLI_addtail(&(cu->nurb), nu2);
@@ -569,7 +574,7 @@ static void buildchar(Curve *cu, unsigned long character, CharInfo *info, float
memcpy(bezt2, bezt1, i * sizeof(struct BezTriple));
nu2->bezt = bezt2;
- if (shear != 0.0) {
+ if (shear != 0.0f) {
bezt2 = nu2->bezt;
for (i= nu2->pntsu; i > 0; i--) {
@@ -579,7 +584,7 @@ static void buildchar(Curve *cu, unsigned long character, CharInfo *info, float
bezt2++;
}
}
- if(rot!=0.0) {
+ if(rot != 0.0f) {
bezt2= nu2->bezt;
for (i=nu2->pntsu; i > 0; i--) {
fp= bezt2->vec[0];
@@ -704,8 +709,8 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
// Count the wchar_t string length
slen = wcslen(mem);
- if (cu->ulheight == 0.0)
- cu->ulheight = 0.05;
+ if (cu->ulheight == 0.0f)
+ cu->ulheight = 0.05f;
if (cu->strinfo==NULL) /* old file */
cu->strinfo = MEM_callocN((slen+4) * sizeof(CharInfo), "strinfo compat");
@@ -810,7 +815,7 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
twidth = char_width(cu, che, info);
// Calculate positions
- if((tb->w != 0.0) && (ct->dobreak==0) && ((xof-(tb->x/cu->fsize)+twidth)*cu->fsize) > tb->w + cu->xof*cu->fsize) {
+ if((tb->w != 0.0f) && (ct->dobreak==0) && ((xof-(tb->x/cu->fsize)+twidth)*cu->fsize) > tb->w + cu->xof*cu->fsize) {
// fprintf(stderr, "linewidth exceeded: %c%c%c...\n", mem[i], mem[i+1], mem[i+2]);
for (j=i; j && (mem[j] != '\n') && (mem[j] != '\r') && (chartransdata[j].dobreak==0); j--) {
if (mem[j]==' ' || mem[j]=='-') {
@@ -850,7 +855,7 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
linedata3[lnr]= tb->w/cu->fsize;
linedata4[lnr]= wsnr;
- if ( (tb->h != 0.0) &&
+ if ( (tb->h != 0.0f) &&
((-(yof-(tb->y/cu->fsize))) > ((tb->h/cu->fsize)-(linedist*cu->fsize)) - cu->yof) &&
(cu->totbox > (curbox+1)) ) {
maxlen= 0;
@@ -881,7 +886,7 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
ct->charnr= cnr++;
tabfac= (xof-cu->xof+0.01f);
- tabfac= (float)(2.0*ceil(tabfac/2.0));
+ tabfac= 2.0f*ceilf(tabfac/2.0f);
xof= cu->xof+tabfac;
}
else {
@@ -895,7 +900,7 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
if (cu->selboxes && (i>=selstart) && (i<=selend)) {
sb = &(cu->selboxes[i-selstart]);
- sb->y = yof*cu->fsize-linedist*cu->fsize*0.1;
+ sb->y = yof*cu->fsize-linedist*cu->fsize*0.1f;
sb->h = linedist*cu->fsize;
sb->w = xof*cu->fsize;
}
@@ -904,12 +909,12 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
wsfac = cu->wordspace;
wsnr++;
}
- else wsfac = 1.0;
+ else wsfac = 1.0f;
// Set the width of the character
twidth = char_width(cu, che, info);
- xof += (twidth*wsfac*(1.0+(info->kern/40.0)) ) + xtrax;
+ xof += (twidth*wsfac*(1.0f+(info->kern/40.0f)) ) + xtrax;
if (sb)
sb->w = (xof*cu->fsize) - sb->w;
@@ -946,7 +951,7 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
ct++;
}
} else if((cu->spacemode==CU_FLUSH) &&
- (cu->tb[0].w != 0.0)) {
+ (cu->tb[0].w != 0.0f)) {
for(i=0;i<lnr;i++)
if(linedata2[i]>1)
linedata[i]= (linedata3[i]-linedata[i])/(linedata2[i]-1);
@@ -959,7 +964,7 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
ct++;
}
}
- else if((cu->spacemode==CU_JUSTIFY) && (cu->tb[0].w != 0.0)) {
+ else if((cu->spacemode==CU_JUSTIFY) && (cu->tb[0].w != 0.0f)) {
float curofs= 0.0f;
for (i=0; i<=slen; i++) {
for (j=i; (mem[j]) && (mem[j]!='\n') &&
@@ -1010,9 +1015,9 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
/* length correction */
distfac= sizefac*cucu->path->totdist/(maxx-minx);
- timeofs= 0.0;
+ timeofs= 0.0f;
- if(distfac > 1.0) {
+ if(distfac > 1.0f) {
/* path longer than text: spacemode involves */
distfac= 1.0f/distfac;
@@ -1046,7 +1051,7 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
dtime= distfac*0.5f*twidth;
ctime= timeofs + distfac*( ct->xof - minx);
- CLAMP(ctime, 0.0, 1.0);
+ CLAMP(ctime, 0.0f, 1.0f);
/* calc the right loc AND the right rot separately */
/* vec, tvec need 4 items */
@@ -1168,17 +1173,17 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
if ( (i<(slen-1)) && (mem[i+1] != '\n') && (mem[i+1] != '\r') &&
((mem[i+1] != ' ') || (custrinfo[i+1].flag & CU_CHINFO_UNDERLINE)) && ((custrinfo[i+1].flag & CU_CHINFO_WRAP)==0)
) {
- uloverlap = xtrax + 0.1;
+ uloverlap = xtrax + 0.1f;
}
// Find the character, the characters has to be in the memory already
// since character checking has been done earlier already.
che= find_vfont_char(vfd, cha);
twidth = char_width(cu, che, info);
- ulwidth = cu->fsize * ((twidth* (1.0+(info->kern/40.0)))+uloverlap);
- build_underline(cu, ct->xof*cu->fsize, ct->yof*cu->fsize + (cu->ulpos-0.05)*cu->fsize,
+ ulwidth = cu->fsize * ((twidth* (1.0f+(info->kern/40.0f)))+uloverlap);
+ build_underline(cu, ct->xof*cu->fsize, ct->yof*cu->fsize + (cu->ulpos-0.05f)*cu->fsize,
ct->xof*cu->fsize + ulwidth,
- ct->yof*cu->fsize + (cu->ulpos-0.05)*cu->fsize - cu->ulheight*cu->fsize,
+ ct->yof*cu->fsize + (cu->ulpos-0.05f)*cu->fsize - cu->ulheight*cu->fsize,
i, info->mat_nr);
}
ct++;
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index abd7c12ff70..db0c9d2735f 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -24,6 +24,11 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
+
+/** \file blender/blenkernel/intern/gpencil.c
+ * \ingroup bke
+ */
+
#include <stdio.h>
#include <string.h>
diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c
index e48ec8ac288..d96b00f7990 100644
--- a/source/blender/blenkernel/intern/group.c
+++ b/source/blender/blenkernel/intern/group.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/group.c
+ * \ingroup bke
+ */
+
+
#include <stdio.h>
#include <string.h>
#include <math.h>
diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c
index 8ce3847bf08..09c189a8847 100644
--- a/source/blender/blenkernel/intern/icons.c
+++ b/source/blender/blenkernel/intern/icons.c
@@ -28,6 +28,11 @@
*
*/
+/** \file blender/blenkernel/intern/icons.c
+ * \ingroup bke
+ */
+
+
#include <math.h>
#include <stdlib.h>
#include <string.h>
diff --git a/source/blender/blenkernel/intern/idcode.c b/source/blender/blenkernel/intern/idcode.c
index 6c8b5329711..8c8a693e6e7 100755
--- a/source/blender/blenkernel/intern/idcode.c
+++ b/source/blender/blenkernel/intern/idcode.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
* return info about ID types
*/
+
+/** \file blender/blenkernel/intern/idcode.c
+ * \ingroup bke
+ */
+
#include <stdlib.h>
#include <string.h>
@@ -128,3 +133,8 @@ const char *BKE_idcode_to_name_plural(int code)
return idt?idt->plural:NULL;
}
+
+int BKE_idcode_iter_step(int *index)
+{
+ return (*index < nidtypes) ? idtypes[(*index)++].code : 0;
+}
diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c
index b3119f317a5..67be3e71101 100644
--- a/source/blender/blenkernel/intern/idprop.c
+++ b/source/blender/blenkernel/intern/idprop.c
@@ -24,6 +24,11 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
+
+/** \file blender/blenkernel/intern/idprop.c
+ * \ingroup bke
+ */
+
#include <stdio.h>
#include <stdlib.h>
@@ -235,7 +240,7 @@ void IDP_ResizeArray(IDProperty *prop, int newlen)
else {
/* newlen is smaller*/
idp_resize_group_array(prop, newlen, newarr);
- memcpy(newarr, prop->data.pointer, newlen*prop->len*idp_size_table[(int)prop->subtype]);
+ memcpy(newarr, prop->data.pointer, newlen*idp_size_table[(int)prop->subtype]);
}
MEM_freeN(prop->data.pointer);
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 8a15f63243c..c44634fed34 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -26,6 +26,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/image.c
+ * \ingroup bke
+ */
+
+
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
@@ -845,9 +850,15 @@ int BKE_add_image_extension(char *string, int imtype)
if(extension) {
/* prefer this in many cases to avoid .png.tga, but in certain cases it breaks */
- /* return BLI_replace_extension(string, FILE_MAX, extension); */
- strcat(string, extension);
- return TRUE;
+ /* remove any other known image extension */
+ if(BLI_testextensie_array(string, imb_ext_image)
+ || (G.have_quicktime && BLI_testextensie_array(string, imb_ext_image_qt))) {
+ return BLI_replace_extension(string, FILE_MAX, extension);
+ } else {
+ strcat(string, extension);
+ return TRUE;
+ }
+
}
else {
return FALSE;
@@ -1238,8 +1249,8 @@ int BKE_write_ibuf(Scene *scene, ImBuf *ibuf, const char *name, int imtype, int
int ok;
(void)subimtype; /* quies unused warnings */
- if(imtype==0) {
- /* pass */
+ if(imtype == -1) {
+ /* use whatever existing image type is set by 'ibuf' */
}
else if(imtype== R_IRIS) {
ibuf->ftype= IMAGIC;
diff --git a/source/blender/blenkernel/intern/image_gen.c b/source/blender/blenkernel/intern/image_gen.c
index c21e347d6d8..8f6408f1939 100644
--- a/source/blender/blenkernel/intern/image_gen.c
+++ b/source/blender/blenkernel/intern/image_gen.c
@@ -23,6 +23,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/image_gen.c
+ * \ingroup bke
+ */
+
+
#include <math.h>
#include <stdlib.h>
@@ -156,8 +161,8 @@ void BKE_image_buf_fill_checker(unsigned char *rect, float *rect_float, int widt
/* Utility functions for BKE_image_buf_fill_checker_color */
-#define BLEND_FLOAT(real, add) (real+add <= 1.0) ? (real+add) : 1.0
-#define BLEND_CHAR(real, add) ((real + (char)(add * 255.0)) <= 255) ? (real + (char)(add * 255.0)) : 255
+#define BLEND_FLOAT(real, add) (real+add <= 1.0f) ? (real+add) : 1.0f
+#define BLEND_CHAR(real, add) ((real + (char)(add * 255.0f)) <= 255) ? (real + (char)(add * 255.0f)) : 255
static int is_pow2(int n)
{
diff --git a/source/blender/blenkernel/intern/implicit.c b/source/blender/blenkernel/intern/implicit.c
index 207c667f335..7f0292b2f22 100644
--- a/source/blender/blenkernel/intern/implicit.c
+++ b/source/blender/blenkernel/intern/implicit.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/implicit.c
+ * \ingroup bke
+ */
+
+
#include "MEM_guardedalloc.h"
#include "DNA_scene_types.h"
diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c
index 329058b3115..08e0ad4f3ff 100644
--- a/source/blender/blenkernel/intern/ipo.c
+++ b/source/blender/blenkernel/intern/ipo.c
@@ -28,6 +28,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/ipo.c
+ * \ingroup bke
+ */
+
+
/* NOTE:
*
* This file is no longer used to provide tools for the depreceated IPO system. Instead, it
@@ -326,7 +331,7 @@ static char *shapekey_adrcodes_to_paths (int adrcode, int *UNUSED(array_index))
if (adrcode == 0)
sprintf(buf, "speed");
else
- sprintf(buf, "keys[%d].value", adrcode);
+ sprintf(buf, "key_blocks[%d].value", adrcode);
return buf;
}
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index 5c10c14c4e2..06145f09488 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -30,6 +30,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/key.c
+ * \ingroup bke
+ */
+
+
#include <math.h>
#include <string.h>
#include <stddef.h>
@@ -461,7 +466,7 @@ static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float *t, int cycl)
t[3]= k1->pos+ofs;
k[3]= k1;
- if(ofs>2.1+lastpos) break;
+ if(ofs > 2.1f + lastpos) break;
}
bsplinetype= 0;
@@ -487,7 +492,7 @@ static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float *t, int cycl)
}
d= t[2]-t[1];
- if(d==0.0) {
+ if(d == 0.0f) {
if(bsplinetype==0) {
return 1; /* both keys equal */
}
@@ -691,8 +696,8 @@ static void cp_key(const int start, int end, const int tot, char *poin, Key *key
/* are we going to be nasty? */
if(flagflo) {
ktot+= kd;
- while(ktot>=1.0) {
- ktot-= 1.0;
+ while(ktot >= 1.0f) {
+ ktot -= 1.0f;
k1+= elemsize;
kref+= elemsize;
}
@@ -995,8 +1000,8 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key
if(flagdo & 1) {
if(flagflo & 1) {
k1tot+= k1d;
- while(k1tot>=1.0) {
- k1tot-= 1.0;
+ while(k1tot >= 1.0f) {
+ k1tot -= 1.0f;
k1+= elemsize;
}
}
@@ -1005,8 +1010,8 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key
if(flagdo & 2) {
if(flagflo & 2) {
k2tot+= k2d;
- while(k2tot>=1.0) {
- k2tot-= 1.0;
+ while(k2tot >= 1.0f) {
+ k2tot -= 1.0f;
k2+= elemsize;
}
}
@@ -1015,8 +1020,8 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key
if(flagdo & 4) {
if(flagflo & 4) {
k3tot+= k3d;
- while(k3tot>=1.0) {
- k3tot-= 1.0;
+ while(k3tot >= 1.0f) {
+ k3tot -= 1.0f;
k3+= elemsize;
}
}
@@ -1025,8 +1030,8 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key
if(flagdo & 8) {
if(flagflo & 8) {
k4tot+= k4d;
- while(k4tot>=1.0) {
- k4tot-= 1.0;
+ while(k4tot >= 1.0f) {
+ k4tot -= 1.0f;
k4+= elemsize;
}
}
@@ -1518,7 +1523,7 @@ KeyBlock *add_keyblock(Key *key, const char *name)
// XXX kb->pos is the confusing old horizontal-line RVK crap in old IPO Editor...
if(key->type == KEY_RELATIVE)
- kb->pos= curpos+0.1;
+ kb->pos= curpos + 0.1f;
else {
#if 0 // XXX old animation system
curpos= bsystem_time(scene, 0, (float)CFRA, 0.0);
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index 70eba3903d0..a32ae68efdd 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -30,6 +30,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/lattice.c
+ * \ingroup bke
+ */
+
+
#include <stdio.h>
#include <string.h>
@@ -408,7 +413,7 @@ void calc_latt_deform(Object *ob, float *co, float weight)
for(ww= wi-1; ww<=wi+2; ww++) {
w= tw[ww-wi+1];
- if(w!=0.0) {
+ if(w != 0.0f) {
if(ww>0) {
if(ww<lt->pntsw) idx_w= ww*lt->pntsu*lt->pntsv;
else idx_w= (lt->pntsw-1)*lt->pntsu*lt->pntsv;
@@ -418,7 +423,7 @@ void calc_latt_deform(Object *ob, float *co, float weight)
for(vv= vi-1; vv<=vi+2; vv++) {
v= w*tv[vv-vi+1];
- if(v!=0.0) {
+ if(v != 0.0f) {
if(vv>0) {
if(vv<lt->pntsv) idx_v= idx_w + vv*lt->pntsu;
else idx_v= idx_w + (lt->pntsv-1)*lt->pntsu;
@@ -428,7 +433,7 @@ void calc_latt_deform(Object *ob, float *co, float weight)
for(uu= ui-1; uu<=ui+2; uu++) {
u= weight*v*tu[uu-ui+1];
- if(u!=0.0) {
+ if(u != 0.0f) {
if(uu>0) {
if(uu<lt->pntsu) idx_u= idx_v + uu;
else idx_u= idx_v + (lt->pntsu-1);
@@ -504,7 +509,7 @@ static int where_on_path_deform(Object *ob, float ctime, float *vec, float *dir,
if(bl && bl->poly> -1) cycl= 1;
if(cycl==0) {
- ctime1= CLAMPIS(ctime, 0.0, 1.0);
+ ctime1= CLAMPIS(ctime, 0.0f, 1.0f);
}
else ctime1= ctime;
@@ -515,16 +520,16 @@ static int where_on_path_deform(Object *ob, float ctime, float *vec, float *dir,
Path *path= cu->path;
float dvec[3];
- if(ctime < 0.0) {
+ if(ctime < 0.0f) {
sub_v3_v3v3(dvec, path->data[1].vec, path->data[0].vec);
mul_v3_fl(dvec, ctime*(float)path->len);
add_v3_v3(vec, dvec);
if(quat) copy_qt_qt(quat, path->data[0].quat);
if(radius) *radius= path->data[0].radius;
}
- else if(ctime > 1.0) {
+ else if(ctime > 1.0f) {
sub_v3_v3v3(dvec, path->data[path->len-1].vec, path->data[path->len-2].vec);
- mul_v3_fl(dvec, (ctime-1.0)*(float)path->len);
+ mul_v3_fl(dvec, (ctime-1.0f)*(float)path->len);
add_v3_v3(vec, dvec);
if(quat) copy_qt_qt(quat, path->data[path->len-1].quat);
if(radius) *radius= path->data[path->len-1].radius;
@@ -1027,13 +1032,8 @@ void lattice_calc_modifiers(Scene *scene, Object *ob)
struct MDeformVert* lattice_get_deform_verts(struct Object *oblatt)
{
- if(oblatt->type == OB_LATTICE)
- {
- Lattice *lt = (Lattice*)oblatt->data;
- if(lt->editlatt) lt= lt->editlatt->latt;
- return lt->dvert;
- }
-
- return NULL;
+ Lattice *lt = (Lattice*)oblatt->data;
+ BLI_assert(oblatt->type == OB_LATTICE);
+ if(lt->editlatt) lt= lt->editlatt->latt;
+ return lt->dvert;
}
-
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index cb96f549829..e3b0a342b3a 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/library.c
+ * \ingroup bke
+ */
+
+
/*
* Contains management of ID's and libraries
* allocate and free of all library data
@@ -104,6 +109,10 @@
#include "BKE_gpencil.h"
#include "BKE_fcurve.h"
+#ifdef WITH_PYTHON
+#include "BPY_extern.h"
+#endif
+
#define MAX_IDPUP 60 /* was 24 */
/* GS reads the memory pointed at in a specific ordering.
@@ -716,7 +725,11 @@ static void animdata_dtar_clear_cb(ID *UNUSED(id), AnimData *adt, void *userdata
void free_libblock(ListBase *lb, void *idv)
{
ID *id= idv;
-
+
+#ifdef WITH_PYTHON
+ BPY_id_release(id);
+#endif
+
switch( GS(id->name) ) { /* GetShort from util.h */
case ID_SCE:
free_scene((Scene *)id);
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 0b1cbd60432..fa7709e3b33 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -30,6 +30,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/material.c
+ * \ingroup bke
+ */
+
+
#include <string.h>
#include <math.h>
@@ -240,12 +245,11 @@ Material *localize_material(Material *ma)
man= copy_libblock(ma);
BLI_remlink(&G.main->mat, man);
+ /* no increment for texture ID users, in previewrender.c it prevents decrement */
for(a=0; a<MAX_MTEX; a++) {
if(ma->mtex[a]) {
man->mtex[a]= MEM_mallocN(sizeof(MTex), "copymaterial");
memcpy(man->mtex[a], ma->mtex[a], sizeof(MTex));
- /* free_material decrements! */
- id_us_plus((ID *)man->mtex[a]->tex);
}
}
@@ -683,6 +687,10 @@ void assign_material(Object *ob, Material *ma, int act)
if(act>MAXMAT) return;
if(act<1) act= 1;
+ /* prevent crashing when using accidentally */
+ BLI_assert(ob->id.lib == NULL);
+ if(ob->id.lib) return;
+
/* test arraylens */
totcolp= give_totcolp(ob);
@@ -780,21 +788,10 @@ int find_material_index(Object *ob, Material *ma)
int object_add_material_slot(Object *ob)
{
- Material *ma;
-
if(ob==NULL) return FALSE;
if(ob->totcol>=MAXMAT) return FALSE;
- ma= give_current_material(ob, ob->actcol);
-
- if(ma == NULL)
- ma= add_material("Material");
- else
- ma= copy_material(ma);
-
- id_us_min(&ma->id);
-
- assign_material(ob, ma, ob->totcol+1);
+ assign_material(ob, NULL, ob->totcol+1);
ob->actcol= ob->totcol;
return TRUE;
}
@@ -1001,9 +998,9 @@ void automatname(Material *ma)
if(ma->mode & MA_SHLESS) ref= 1.0;
else ref= ma->ref;
- r= (int)(4.99*(ref*ma->r));
- g= (int)(4.99*(ref*ma->g));
- b= (int)(4.99*(ref*ma->b));
+ r= (int)(4.99f*(ref*ma->r));
+ g= (int)(4.99f*(ref*ma->g));
+ b= (int)(4.99f*(ref*ma->b));
nr= r + 5*g + 25*b;
if(nr>124) nr= 124;
new_id(&G.main->mat, (ID *)ma, colname_array[nr]);
@@ -1169,10 +1166,10 @@ void ramp_blend(int type, float *r, float *g, float *b, float fac, float *col)
}
break;
case MA_RAMP_DIFF:
- *r = facm*(*r) + fac*fabs(*r-col[0]);
+ *r = facm*(*r) + fac*fabsf(*r-col[0]);
if(g) {
- *g = facm*(*g) + fac*fabs(*g-col[1]);
- *b = facm*(*b) + fac*fabs(*b-col[2]);
+ *g = facm*(*g) + fac*fabsf(*g-col[1]);
+ *b = facm*(*b) + fac*fabsf(*b-col[2]);
}
break;
case MA_RAMP_DARK:
diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c
index 4f44875b7ea..e6e32be9634 100644
--- a/source/blender/blenkernel/intern/mball.c
+++ b/source/blender/blenkernel/intern/mball.c
@@ -32,6 +32,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/mball.c
+ * \ingroup bke
+ */
+
+
#include <stdio.h>
#include <string.h>
#include <math.h>
@@ -582,13 +587,13 @@ float densfunc(MetaElem *ball, float x, float y, float z)
if(ball->flag & MB_NEGATIVE) {
dist2= 1.0f-(dist2/ball->rad2);
- if(dist2 < 0.0) return 0.5f;
+ if(dist2 < 0.0f) return 0.5f;
return 0.5f-ball->s*dist2*dist2*dist2;
}
else {
dist2= 1.0f-(dist2/ball->rad2);
- if(dist2 < 0.0) return -0.5f;
+ if(dist2 < 0.0f) return -0.5f;
return ball->s*dist2*dist2*dist2 -0.5f;
}
@@ -680,8 +685,8 @@ float metaball(float x, float y, float z)
ml_p= ml_p->next;
}
- dens+= -0.5*(metaball_tree->pos - node->pos);
- dens+= 0.5*(metaball_tree->neg - node->neg);
+ dens+= -0.5f*(metaball_tree->pos - node->pos);
+ dens+= 0.5f*(metaball_tree->neg - node->neg);
}
else{
for(a=0; a<totelem; a++) {
@@ -827,7 +832,7 @@ void docube(CUBE *cube, PROCESS *p, MetaBall *mb)
CORNER *c1, *c2;
int i, index = 0, count, indexar[8];
- for (i = 0; i < 8; i++) if (cube->corners[i]->value > 0.0) index += (1<<i);
+ for (i = 0; i < 8; i++) if (cube->corners[i]->value > 0.0f) index += (1<<i);
for (polys = cubetable[index]; polys; polys = polys->next) {
INTLIST *edges;
@@ -901,7 +906,7 @@ void testface(int i, int j, int k, CUBE* old, int bit, int c1, int c2, int c3, i
corn3= old->corners[c3];
corn4= old->corners[c4];
- pos = corn1->value > 0.0 ? 1 : 0;
+ pos = corn1->value > 0.0f ? 1 : 0;
/* test if no surface crossing */
if( (corn2->value > 0) == pos && (corn3->value > 0) == pos && (corn4->value > 0) == pos) return;
@@ -1214,9 +1219,9 @@ void vnormal (MB_POINT *point, PROCESS *p, MB_POINT *v)
v->x = p->function(point->x+delta, point->y, point->z)-f;
v->y = p->function(point->x, point->y+delta, point->z)-f;
v->z = p->function(point->x, point->y, point->z+delta)-f;
- f = (float)sqrt(v->x*v->x + v->y*v->y + v->z*v->z);
+ f = sqrtf(v->x*v->x + v->y*v->y + v->z*v->z);
- if (f != 0.0) {
+ if (f != 0.0f) {
v->x /= f;
v->y /= f;
v->z /= f;
@@ -1225,16 +1230,16 @@ void vnormal (MB_POINT *point, PROCESS *p, MB_POINT *v)
if(FALSE) {
MB_POINT temp;
- delta*= 2.0;
+ delta *= 2.0f;
f = p->function(point->x, point->y, point->z);
temp.x = p->function(point->x+delta, point->y, point->z)-f;
temp.y = p->function(point->x, point->y+delta, point->z)-f;
temp.z = p->function(point->x, point->y, point->z+delta)-f;
- f = (float)sqrt(temp.x*temp.x + temp.y*temp.y + temp.z*temp.z);
+ f = sqrtf(temp.x*temp.x + temp.y*temp.y + temp.z*temp.z);
- if (f != 0.0) {
+ if (f != 0.0f) {
temp.x /= f;
temp.y /= f;
temp.z /= f;
@@ -1243,9 +1248,9 @@ void vnormal (MB_POINT *point, PROCESS *p, MB_POINT *v)
v->y+= temp.y;
v->z+= temp.z;
- f = (float)sqrt(v->x*v->x + v->y*v->y + v->z*v->z);
+ f = sqrtf(v->x*v->x + v->y*v->y + v->z*v->z);
- if (f != 0.0) {
+ if (f != 0.0f) {
v->x /= f;
v->y /= f;
v->z /= f;
@@ -1312,7 +1317,7 @@ void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2,
/* Aproximation by linear interpolation is faster then binary subdivision,
* but it results sometimes (mb->thresh < 0.2) into the strange results */
- if((mb->thresh >0.2) && (f==1)){
+ if((mb->thresh > 0.2f) && (f==1)){
if((dy == 0.0f) && (dz == 0.0f)){
p->x = neg.x - negative*dx/(positive-negative);
p->y = neg.y;
@@ -1339,7 +1344,7 @@ void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2,
while (1) {
if (i++ == RES) return;
p->x = 0.5f*(pos.x + neg.x);
- if ((function(p->x,p->y,p->z)) > 0.0) pos.x = p->x; else neg.x = p->x;
+ if ((function(p->x,p->y,p->z)) > 0.0f) pos.x = p->x; else neg.x = p->x;
}
}
@@ -1349,7 +1354,7 @@ void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2,
while (1) {
if (i++ == RES) return;
p->y = 0.5f*(pos.y + neg.y);
- if ((function(p->x,p->y,p->z)) > 0.0) pos.y = p->y; else neg.y = p->y;
+ if ((function(p->x,p->y,p->z)) > 0.0f) pos.y = p->y; else neg.y = p->y;
}
}
@@ -1359,7 +1364,7 @@ void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2,
while (1) {
if (i++ == RES) return;
p->z = 0.5f*(pos.z + neg.z);
- if ((function(p->x,p->y,p->z)) > 0.0) pos.z = p->z; else neg.z = p->z;
+ if ((function(p->x,p->y,p->z)) > 0.0f) pos.z = p->z; else neg.z = p->z;
}
}
@@ -1371,7 +1376,7 @@ void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2,
if (i++ == RES) return;
- if ((function(p->x, p->y, p->z)) > 0.0){
+ if ((function(p->x, p->y, p->z)) > 0.0f){
pos.x = p->x;
pos.y = p->y;
pos.z = p->z;
@@ -1432,7 +1437,7 @@ void find_first_points(PROCESS *mbproc, MetaBall *mb, int a)
/* Skip, when Stiffness of MetaElement is too small ... MetaElement can't be
* visible alone ... but still can influence others MetaElements :-) */
- if(f > 0.0) {
+ if(f > 0.0f) {
OUT.x = IN.x = in.x= 0.0;
OUT.y = IN.y = in.y= 0.0;
OUT.z = IN.z = in.z= 0.0;
@@ -1490,7 +1495,7 @@ void find_first_points(PROCESS *mbproc, MetaBall *mb, int a)
workp.y = in.y;
workp.z = in.z;
workp_v = in_v;
- max_len = sqrt((out.x-in.x)*(out.x-in.x) + (out.y-in.y)*(out.y-in.y) + (out.z-in.z)*(out.z-in.z));
+ max_len = sqrtf((out.x-in.x)*(out.x-in.x) + (out.y-in.y)*(out.y-in.y) + (out.z-in.z)*(out.z-in.z));
nx = abs((out.x - in.x)/mbproc->size);
ny = abs((out.y - in.y)/mbproc->size);
@@ -1510,7 +1515,7 @@ void find_first_points(PROCESS *mbproc, MetaBall *mb, int a)
/* compute value of implicite function */
tmp_v = mbproc->function(workp.x, workp.y, workp.z);
/* add cube to the stack, when value of implicite function crosses zero value */
- if((tmp_v<0.0 && workp_v>=0.0)||(tmp_v>0.0 && workp_v<=0.0)) {
+ if((tmp_v<0.0f && workp_v>=0.0f)||(tmp_v>0.0f && workp_v<=0.0f)) {
/* indexes of CUBE, which includes "first point" */
c_i= (int)floor(workp.x/mbproc->size);
@@ -1524,7 +1529,7 @@ void find_first_points(PROCESS *mbproc, MetaBall *mb, int a)
else
add_cube(mbproc, c_i, c_j, c_k, 1);
}
- len = sqrt((workp.x-in.x)*(workp.x-in.x) + (workp.y-in.y)*(workp.y-in.y) + (workp.z-in.z)*(workp.z-in.z));
+ len = sqrtf((workp.x-in.x)*(workp.x-in.x) + (workp.y-in.y)*(workp.y-in.y) + (workp.z-in.z)*(workp.z-in.z));
workp_v = tmp_v;
}
@@ -1622,13 +1627,13 @@ float init_meta(Scene *scene, Object *ob) /* return totsize */
/* when metaball object hase zero scale, then MetaElem ot this MetaBall
* will not be put to mainb array */
- if(bob->size[0]==0.0 || bob->size[1]==0.0 || bob->size[2]==0.0) {
+ if(bob->size[0]==0.0f || bob->size[1]==0.0f || bob->size[2]==0.0f) {
zero_size= 1;
}
else if(bob->parent) {
struct Object *pob=bob->parent;
while(pob) {
- if(pob->size[0]==0.0 || pob->size[1]==0.0 || pob->size[2]==0.0) {
+ if(pob->size[0]==0.0f || pob->size[1]==0.0f || pob->size[2]==0.0f) {
zero_size= 1;
break;
}
@@ -1657,7 +1662,7 @@ float init_meta(Scene *scene, Object *ob) /* return totsize */
/* too big stiffness seems only ugly due to linear interpolation
* no need to have possibility for too big stiffness */
- if(ml->s > 10.0) ml->s = 10.0;
+ if(ml->s > 10.0f) ml->s = 10.0f;
/* Rotation of MetaElem is stored in quat */
quat_to_mat4( temp3,ml->quat);
@@ -2223,7 +2228,7 @@ void metaball_polygonize(Scene *scene, Object *ob, ListBase *dispbase)
if(G.moving && mb->flag==MB_UPDATE_HALFRES) width*= 2;
}
/* nr_cubes is just for safety, minimum is totsize */
- nr_cubes= (int)(0.5+totsize/width);
+ nr_cubes= (int)(0.5f+totsize/width);
/* init process */
mbproc.function = metaball;
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index ced9a3d9e7d..3cc1f58f6d6 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -29,6 +29,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/mesh.c
+ * \ingroup bke
+ */
+
+
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -711,9 +716,9 @@ void tex_space_mesh(Mesh *me)
if(me->texflag & AUTOSPACE) {
for (a=0; a<3; a++) {
- if(size[a]==0.0) size[a]= 1.0;
- else if(size[a]>0.0 && size[a]<0.00001) size[a]= 0.00001;
- else if(size[a]<0.0 && size[a]> -0.00001) size[a]= -0.00001;
+ if(size[a]==0.0f) size[a]= 1.0f;
+ else if(size[a]>0.0f && size[a]<0.00001f) size[a]= 0.00001f;
+ else if(size[a]<0.0f && size[a]> -0.00001f) size[a]= -0.00001f;
}
copy_v3_v3(me->loc, loc);
@@ -941,13 +946,17 @@ static void mfaces_strip_loose(MFace *mface, int *totface)
}
/* Create edges based on known verts and faces */
-static void make_edges_mdata(MVert *UNUSED(allvert), MFace *allface, int UNUSED(totvert), int totface,
+static void make_edges_mdata(MVert *UNUSED(allvert), MFace *allface, MLoop *allloop,
+ MPoly *allpoly, int UNUSED(totvert), int totface, int totloop, int totpoly,
int old, MEdge **alledge, int *_totedge)
{
+ MPoly *mpoly;
+ MLoop *mloop;
MFace *mface;
MEdge *medge;
+ EdgeHash *hash = BLI_edgehash_new();
struct edgesort *edsort, *ed;
- int a, totedge=0, final=0;
+ int a, b, totedge=0, final=0;
/* we put all edges in array, sort them, and detect doubles that way */
@@ -1019,6 +1028,26 @@ static void make_edges_mdata(MVert *UNUSED(allvert), MFace *allface, int UNUSED(
medge->flag |= ME_EDGERENDER;
MEM_freeN(edsort);
+
+ /*set edge members of mloops*/
+ medge= *alledge;
+ for (a=0; a<*_totedge; a++, medge++) {
+ BLI_edgehash_insert(hash, medge->v1, medge->v2, SET_INT_IN_POINTER(a));
+ }
+
+ mpoly = allpoly;
+ for (a=0; a<totpoly; a++, mpoly++) {
+ mloop = allloop + mpoly->loopstart;
+ for (b=0; b<mpoly->totloop; b++) {
+ int v1, v2;
+
+ v1 = mloop[b].v;
+ v2 = mloop[(b+1)%mpoly->loopstart].v;
+ mloop[b].e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(hash, v1, v2));
+ }
+ }
+
+ BLI_edgehash_free(hash, NULL);
}
void make_edges(Mesh *me, int old)
@@ -1026,7 +1055,7 @@ void make_edges(Mesh *me, int old)
MEdge *medge;
int totedge=0;
- make_edges_mdata(me->mvert, me->mface, me->totvert, me->totface, old, &medge, &totedge);
+ make_edges_mdata(me->mvert, me->mface, me->mloop, me->mpoly, me->totvert, me->totface, me->totloop, me->totpoly, old, &medge, &totedge);
if(totedge==0) {
/* flag that mesh has edges */
me->medge = medge;
@@ -1100,9 +1129,7 @@ void mball_to_mesh(ListBase *lb, Mesh *me)
verts= dl->verts;
while(a--) {
VECCOPY(mvert->co, verts);
- mvert->no[0]= (short int)(nors[0]*32767.0);
- mvert->no[1]= (short int)(nors[1]*32767.0);
- mvert->no[2]= (short int)(nors[2]*32767.0);
+ normal_float_to_short_v3(mvert->no, nors);
mvert++;
nors+= 3;
verts+= 3;
@@ -1124,31 +1151,37 @@ void mball_to_mesh(ListBase *lb, Mesh *me)
}
make_edges(me, 0); // all edges
- }
+ convert_mfaces_to_mpolys(me);
+ }
}
/* Initialize mverts, medges and, faces for converting nurbs to mesh and derived mesh */
/* return non-zero on error */
int nurbs_to_mdata(Object *ob, MVert **allvert, int *totvert,
- MEdge **alledge, int *totedge, MFace **allface, int *totface)
+ MEdge **alledge, int *totedge, MFace **allface, MLoop **allloop, MPoly **allpoly,
+ int *totface, int *totloop, int *totpoly)
{
return nurbs_to_mdata_customdb(ob, &ob->disp,
- allvert, totvert, alledge, totedge, allface, totface);
+ allvert, totvert, alledge, totedge, allface, allloop, allpoly, totface, totloop, totpoly);
}
/* Initialize mverts, medges and, faces for converting nurbs to mesh and derived mesh */
/* use specified dispbase */
int nurbs_to_mdata_customdb(Object *ob, ListBase *dispbase, MVert **allvert, int *_totvert,
- MEdge **alledge, int *_totedge, MFace **allface, int *_totface)
+ MEdge **alledge, int *_totedge, MFace **allface, MLoop **allloop, MPoly **allpoly,
+ int *_totface, int *_totloop, int *_totpoly)
{
DispList *dl;
Curve *cu;
MVert *mvert;
MFace *mface;
+ MPoly *mpoly;
+ MLoop *mloop;
float *data;
int a, b, ofs, vertcount, startvert, totvert=0, totvlak=0;
int p1, p2, p3, p4, *index;
int conv_polys= 0;
+ int i, j;
cu= ob->data;
@@ -1186,8 +1219,10 @@ int nurbs_to_mdata_customdb(Object *ob, ListBase *dispbase, MVert **allvert, int
}
*allvert= mvert= MEM_callocN(sizeof (MVert) * totvert, "nurbs_init mvert");
- *allface= mface= MEM_callocN(sizeof (MVert) * totvlak, "nurbs_init mface");
-
+ *allface= mface= MEM_callocN(sizeof (MFace) * totvlak, "nurbs_init mface");
+ *allloop = mloop = MEM_callocN(sizeof(MLoop) * totvlak * 4, "nurbs_init mloop");
+ *allpoly = mpoly = MEM_callocN(sizeof(MPoly) * totvlak * 4, "nurbs_init mloop");
+
/* verts and faces */
vertcount= 0;
@@ -1325,11 +1360,34 @@ int nurbs_to_mdata_customdb(Object *ob, ListBase *dispbase, MVert **allvert, int
dl= dl->next;
}
-
+
+ mface= *allface;
+ j = 0;
+ for (i=0; i<totvert; i++, mpoly++, mface++) {
+ int k;
+
+ if (!mface->v3) {
+ mpoly--;
+ i--;
+ continue;
+ }
+
+ if (mface >= *allface + totvlak)
+ break;
+
+ mpoly->loopstart= j;
+ mpoly->totloop= mface->v4 ? 4 : 3;
+ for (k=0; k<mpoly->totloop; k++, mloop++) {
+ mloop->v = (&mface->v1)[k];
+ }
+ }
+
+ *_totpoly= i;
+ *_totloop= j;
*_totvert= totvert;
*_totface= totvlak;
- make_edges_mdata(*allvert, *allface, totvert, totvlak, 0, alledge, _totedge);
+ make_edges_mdata(*allvert, *allface, *allloop, *allpoly, totvert, totvlak, *_totloop, *_totpoly, 0, alledge, _totedge);
mfaces_strip_loose(*allface, _totface);
return 0;
@@ -1346,12 +1404,14 @@ void nurbs_to_mesh(Object *ob)
MVert *allvert= NULL;
MEdge *alledge= NULL;
MFace *allface= NULL;
- int totvert, totedge, totface;
+ MLoop *allloop = NULL;
+ MPoly *allpoly = NULL;
+ int totvert, totedge, totface, totloop, totpoly;
cu= ob->data;
if (dm == NULL) {
- if (nurbs_to_mdata (ob, &allvert, &totvert, &alledge, &totedge, &allface, &totface) != 0) {
+ if (nurbs_to_mdata (ob, &allvert, &totvert, &alledge, &totedge, &allface, &allloop, &allpoly, &totface, &totloop, &totpoly) != 0) {
/* Error initializing */
return;
}
@@ -1361,12 +1421,16 @@ void nurbs_to_mesh(Object *ob)
me->totvert= totvert;
me->totface= totface;
me->totedge= totedge;
+ me->totloop = totloop;
+ me->totpoly = totpoly;
me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, allvert, me->totvert);
- me->mface= CustomData_add_layer(&me->fdata, CD_MFACE, CD_ASSIGN, allface, me->totface);
me->medge= CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, alledge, me->totedge);
+ me->mface= CustomData_add_layer(&me->fdata, CD_MFACE, CD_ASSIGN, allface, me->totface);
+ me->mloop= CustomData_add_layer(&me->ldata, CD_MLOOP, CD_ASSIGN, allloop, me->totloop);
+ me->mpoly= CustomData_add_layer(&me->pdata, CD_MPOLY, CD_ASSIGN, allpoly, me->totpoly);
- mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
+ mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
} else {
me= add_mesh("Mesh");
DM_to_mesh(dm, me);
@@ -1619,34 +1683,112 @@ void mesh_set_smooth_flag(Object *meshOb, int enableSmooth)
mf->flag &= ~ME_SMOOTH;
}
}
+
+ mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop,
+ me->totpoly, NULL, NULL, 0, NULL, NULL);
}
-void mesh_calc_normals(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float **faceNors_r)
+void mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys,
+ int UNUSED(numLoops), int numPolys, float (*polyNors_r)[3], MFace *mfaces, int numFaces,
+ int *origIndexFace, float (*faceNors_r)[3])
+{
+ float (*pnors)[3] = polyNors_r, (*fnors)[3] = faceNors_r;
+ float (*tnorms)[3] = NULL;
+ int i, j, *origIndex;
+ MFace *mf;
+ MPoly *mp;
+ MLoop *ml;
+
+ if(numPolys == 0) return;
+
+ /*first go through and calculate normals for all the polys*/
+ tnorms = MEM_callocN(sizeof(float)*3*numVerts, "tnorms cdderivedmesh.c");
+ if (!pnors)
+ pnors = MEM_callocN(sizeof(float)*3*numPolys, "poly_nors cdderivedmesh.c");
+ if (!fnors)
+ fnors = MEM_callocN(sizeof(float)*3*numFaces, "face nors cdderivedmesh.c");
+
+ mp = mpolys;
+ for (i=0; i<numPolys; i++, mp++) {
+ mesh_calc_poly_normal(mp, mloop+mp->loopstart, mverts, pnors[i]);
+
+ ml = mloop + mp->loopstart;
+ /*this is kindof hackish, probably need to calculate quads around face center for
+ ngons, not this weird quad-fitting thing I've got going here*/
+ for (j=0; j<mp->totloop; j += 4, ml++) {
+ int v1, v2, v3, v4;
+
+ v1 = ml->v;
+ v2 = mloop[mp->loopstart+(j+1)%mp->totloop].v;
+ v3 = mloop[mp->loopstart+(j+2)%mp->totloop].v;
+ v4 = mloop[mp->loopstart+(j+3)%mp->totloop].v;
+
+ accumulate_vertex_normals(tnorms[v1], tnorms[v2], tnorms[v3], v4 != v1 ? tnorms[v4] : NULL,
+ pnors[i], mverts[v1].co, mverts[v2].co, mverts[v3].co, v4!=v1 ? mverts[v4].co : NULL);
+
+ }
+ }
+
+ /* following Mesh convention; we use vertex coordinate itself for normal in this case */
+ for(i=0; i<numVerts; i++) {
+ MVert *mv= &mverts[i];
+ float *no= tnorms[i];
+
+ if(normalize_v3(no) == 0.0f)
+ normalize_v3_v3(no, mv->co);
+
+ normal_float_to_short_v3(mv->no, no);
+ }
+
+ if (origIndexFace && fnors==faceNors_r && numFaces) {
+ mf = mfaces;
+ for (i=0; i<numFaces; i++, mf++, origIndexFace++) {
+ if (origIndex < numPolys) {
+ VECCOPY(fnors[i], tnorms[*origIndexFace]);
+ } else {
+ /*eek, we're not corrusponding to polys*/
+ printf("error in mesh_calc_normals; tesselation face indices are incorrect. normals may look bad.\n");
+ }
+ }
+ }
+
+ MEM_freeN(tnorms);
+ if (fnors != faceNors_r)
+ MEM_freeN(fnors);
+ if (pnors != polyNors_r)
+ MEM_freeN(pnors);
+
+ fnors = pnors = NULL;
+
+}
+
+void mesh_calc_tessface_normals(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float (*faceNors_r)[3])
{
float (*tnorms)[3]= MEM_callocN(numVerts*sizeof(*tnorms), "tnorms");
- float *fnors= MEM_callocN(sizeof(*fnors)*3*numFaces, "meshnormals");
+ float (*fnors)[3]= (faceNors_r)? faceNors_r: MEM_callocN(sizeof(*fnors)*numFaces, "meshnormals");
int i;
- for (i=0; i<numFaces; i++) {
+ for(i=0; i<numFaces; i++) {
MFace *mf= &mfaces[i];
- float *f_no= &fnors[i*3];
+ float *f_no= fnors[i];
+ float *n4 = (mf->v4)? tnorms[mf->v4]: NULL;
+ float *c4 = (mf->v4)? mverts[mf->v4].co: NULL;
- if (mf->v4)
- normal_quad_v3( f_no,mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, mverts[mf->v4].co);
+ if(mf->v4)
+ normal_quad_v3(f_no, mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, mverts[mf->v4].co);
else
- normal_tri_v3( f_no,mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co);
-
- add_v3_v3(tnorms[mf->v1], f_no);
- add_v3_v3(tnorms[mf->v2], f_no);
- add_v3_v3(tnorms[mf->v3], f_no);
- if (mf->v4)
- add_v3_v3(tnorms[mf->v4], f_no);
+ normal_tri_v3(f_no, mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co);
+
+ accumulate_vertex_normals(tnorms[mf->v1], tnorms[mf->v2], tnorms[mf->v3], n4,
+ f_no, mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, c4);
}
- for (i=0; i<numVerts; i++) {
+
+ /* following Mesh convention; we use vertex coordinate itself for normal in this case */
+ for(i=0; i<numVerts; i++) {
MVert *mv= &mverts[i];
float *no= tnorms[i];
- if (normalize_v3(no)==0.0)
+ if(normalize_v3(no) == 0.0f)
normalize_v3_v3(no, mv->co);
normal_float_to_short_v3(mv->no, no);
@@ -1654,11 +1796,147 @@ void mesh_calc_normals(MVert *mverts, int numVerts, MFace *mfaces, int numFaces,
MEM_freeN(tnorms);
- if (faceNors_r) {
- *faceNors_r = fnors;
- } else {
+ if(fnors != faceNors_r)
MEM_freeN(fnors);
+}
+
+
+void bmesh_corners_to_loops(Mesh *me, int findex, int loopstart, int numTex, int numCol)
+{
+ MTFace *texface;
+ MTexPoly *texpoly;
+ MCol *mcol;
+ MLoopCol *mloopcol;
+ MLoopUV *mloopuv;
+ MFace *mf;
+ int i;
+
+ for(i=0; i < numTex; i++){
+ texface = CustomData_get_n(&me->fdata, CD_MTFACE, findex, i);
+ texpoly = CustomData_get_n(&me->pdata, CD_MTEXPOLY, findex, i);
+ mf = me->mface + findex;
+
+ texpoly->tpage = texface->tpage;
+ texpoly->flag = texface->flag;
+ texpoly->transp = texface->transp;
+ texpoly->mode = texface->mode;
+ texpoly->tile = texface->tile;
+ texpoly->unwrap = texface->unwrap;
+
+ mloopuv = CustomData_get_n(&me->ldata, CD_MLOOPUV, loopstart, i);
+ mloopuv->uv[0] = texface->uv[0][0]; mloopuv->uv[1] = texface->uv[0][1]; mloopuv++;
+ mloopuv->uv[0] = texface->uv[1][0]; mloopuv->uv[1] = texface->uv[1][1]; mloopuv++;
+ mloopuv->uv[0] = texface->uv[2][0]; mloopuv->uv[1] = texface->uv[2][1]; mloopuv++;
+
+ if (mf->v4) {
+ mloopuv->uv[0] = texface->uv[3][0]; mloopuv->uv[1] = texface->uv[3][1]; mloopuv++;
+ }
}
+
+ for(i=0; i < numCol; i++){
+ mf = me->mface + findex;
+ mloopcol = CustomData_get_n(&me->ldata, CD_MLOOPCOL, loopstart, i);
+ mcol = CustomData_get_n(&me->fdata, CD_MCOL, findex, i);
+
+ mloopcol->r = mcol[0].r; mloopcol->g = mcol[0].g; mloopcol->b = mcol[0].b; mloopcol->a = mcol[0].a; mloopcol++;
+ mloopcol->r = mcol[1].r; mloopcol->g = mcol[1].g; mloopcol->b = mcol[1].b; mloopcol->a = mcol[1].a; mloopcol++;
+ mloopcol->r = mcol[2].r; mloopcol->g = mcol[2].g; mloopcol->b = mcol[2].b; mloopcol->a = mcol[2].a; mloopcol++;
+ if (mf->v4) {
+ mloopcol->r = mcol[3].r; mloopcol->g = mcol[3].g; mloopcol->b = mcol[3].b; mloopcol->a = mcol[3].a; mloopcol++;
+ }
+ }
+
+ if (CustomData_has_layer(&me->fdata, CD_MDISPS)) {
+ MDisps *ld = CustomData_get(&me->ldata, loopstart, CD_MDISPS);
+ MDisps *fd = CustomData_get(&me->fdata, findex, CD_MDISPS);
+ float (*disps)[3] = fd->disps;
+ int i, tot = mf->v4 ? 4 : 3;
+ int side, corners;
+
+ corners = multires_mdisp_corners(fd);
+ side = sqrt(fd->totdisp / corners);
+
+ for (i=0; i<tot; i++, disps += side*side, ld++) {
+ ld->totdisp = side*side;
+
+ if (ld->disps)
+ BLI_cellalloc_free(ld->disps);
+
+ ld->disps = BLI_cellalloc_malloc(sizeof(float)*3*side*side, "converted loop mdisps");
+ memcpy(ld->disps, disps, sizeof(float)*3*side*side);
+ }
+ }
+}
+
+void convert_mfaces_to_mpolys(Mesh *mesh)
+{
+ MFace *mf;
+ MLoop *ml;
+ MPoly *mp;
+ MEdge *me;
+ EdgeHash *eh;
+ int numTex, numCol;
+ int i, j, totloop;
+
+ mesh->totpoly = mesh->totface;
+ mesh->mpoly = MEM_callocN(sizeof(MPoly)*mesh->totpoly, "mpoly converted");
+ CustomData_add_layer(&mesh->pdata, CD_MPOLY, CD_ASSIGN, mesh->mpoly, mesh->totpoly);
+
+ numTex = CustomData_number_of_layers(&mesh->fdata, CD_MTFACE);
+ numCol = CustomData_number_of_layers(&mesh->fdata, CD_MCOL);
+
+ totloop = 0;
+ mf = mesh->mface;
+ for (i=0; i<mesh->totface; i++, mf++) {
+ totloop += mf->v4 ? 4 : 3;
+ }
+
+ mesh->totloop = totloop;
+ mesh->mloop = MEM_callocN(sizeof(MLoop)*mesh->totloop, "mloop converted");
+
+ CustomData_add_layer(&mesh->ldata, CD_MLOOP, CD_ASSIGN, mesh->mloop, totloop);
+ CustomData_to_bmeshpoly(&mesh->fdata, &mesh->pdata, &mesh->ldata,
+ mesh->totloop, mesh->totpoly);
+
+ eh = BLI_edgehash_new();
+
+ /*build edge hash*/
+ me = mesh->medge;
+ for (i=0; i<mesh->totedge; i++, me++) {
+ BLI_edgehash_insert(eh, me->v1, me->v2, SET_INT_IN_POINTER(i));
+ }
+
+ j = 0; /*current loop index*/
+ ml = mesh->mloop;
+ mf = mesh->mface;
+ mp = mesh->mpoly;
+ for (i=0; i<mesh->totface; i++, mf++, mp++) {
+ mp->loopstart = j;
+
+ mp->totloop = mf->v4 ? 4 : 3;
+
+ mp->mat_nr = mf->mat_nr;
+ mp->flag = mf->flag;
+
+ #define ML(v1, v2) {ml->v = mf->v1; ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v1, mf->v2)); ml++; j++;}
+
+ ML(v1, v2);
+ ML(v2, v3);
+ if (mf->v4) {
+ ML(v3, v4);
+ ML(v4, v1);
+ } else {
+ ML(v3, v1);
+ }
+
+ #undef ML
+
+ bmesh_corners_to_loops(mesh, i, mp->loopstart, numTex, numCol);
+ }
+
+ /*BMESH_TODO now to deal with fgons*/
+
+ BLI_edgehash_free(eh, NULL);
}
float (*mesh_getVertexCos(Mesh *me, int *numVerts_r))[3]
@@ -1747,7 +2025,7 @@ UvVertMap *make_uv_vert_map(struct MFace *mface, struct MTFace *tface, unsigned
sub_v2_v2v2(uvdiff, uv2, uv);
- if(fabs(uv[0]-uv2[0]) < limit[0] && fabs(uv[1]-uv2[1]) < limit[1]) {
+ if(fabsf(uv[0]-uv2[0]) < limit[0] && fabsf(uv[1]-uv2[1]) < limit[1]) {
if(lastv) lastv->next= next;
else vlist= next;
iterv->next= newvlist;
diff --git a/source/blender/blenkernel/intern/mesh_validate.c b/source/blender/blenkernel/intern/mesh_validate.c
index 0821b4188fe..70928ab7bbb 100644
--- a/source/blender/blenkernel/intern/mesh_validate.c
+++ b/source/blender/blenkernel/intern/mesh_validate.c
@@ -23,6 +23,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/mesh_validate.c
+ * \ingroup bke
+ */
+
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -112,7 +117,7 @@ static int search_face_cmp(const void *v1, const void *v2)
}
-int BKE_mesh_validate_arrays(Mesh *me, MVert *UNUSED(mverts), int totvert, MEdge *medges, int totedge, MFace *mfaces, int totface, const short do_verbose, const short do_fixes)
+int BKE_mesh_validate_arrays(Mesh *me, MVert *UNUSED(mverts), unsigned int totvert, MEdge *medges, unsigned int totedge, MFace *mfaces, unsigned int totface, const short do_verbose, const short do_fixes)
{
# define PRINT if(do_verbose) printf
# define REMOVE_EDGE_TAG(_med) { _med->v2= _med->v1; do_edge_free= 1; }
@@ -122,7 +127,7 @@ int BKE_mesh_validate_arrays(Mesh *me, MVert *UNUSED(mverts), int totvert, MEdge
MEdge *med;
MFace *mf;
MFace *mf_prev;
- int i;
+ unsigned int i;
int do_face_free= FALSE;
int do_edge_free= FALSE;
@@ -134,7 +139,7 @@ int BKE_mesh_validate_arrays(Mesh *me, MVert *UNUSED(mverts), int totvert, MEdge
SortFace *sort_faces= MEM_callocN(sizeof(SortFace) * totface, "search faces");
SortFace *sf;
SortFace *sf_prev;
- int totsortface= 0;
+ unsigned int totsortface= 0;
BLI_assert(!(do_fixes && me == NULL));
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c
index 631e5fe2cb3..372eb1fe6f1 100644
--- a/source/blender/blenkernel/intern/modifier.c
+++ b/source/blender/blenkernel/intern/modifier.c
@@ -34,6 +34,11 @@
*
*/
+/** \file blender/blenkernel/intern/modifier.c
+ * \ingroup bke
+ */
+
+
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c
index fc1b43e882e..14af46ff927 100644
--- a/source/blender/blenkernel/intern/multires.c
+++ b/source/blender/blenkernel/intern/multires.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/multires.c
+ * \ingroup bke
+ */
+
+
#include "MEM_guardedalloc.h"
#include "DNA_mesh_types.h"
@@ -916,7 +921,7 @@ static void multiresModifier_update(DerivedMesh *dm)
void multires_set_space(DerivedMesh *dm, Object *ob, int from, int to)
{
- CCGDerivedMesh *ccgdm, *subsurf=NULL;
+ DerivedMesh *ccgdm, *subsurf=NULL;
DMGridData **gridData, **subGridData=NULL;
MPoly *mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY);
MDisps *mdisps;
@@ -934,14 +939,14 @@ void multires_set_space(DerivedMesh *dm, Object *ob, int from, int to)
}
totlvl = mmd->totlvl;
- ccgdm = (CCGDerivedMesh*)multires_dm_create_local(ob, dm, totlvl, totlvl, mmd->simple);
+ ccgdm = multires_dm_create_local(ob, dm, totlvl, totlvl, mmd->simple);
subsurf = subsurf_dm_create_local(ob, dm, totlvl,
mmd->simple, mmd->flags & eMultiresModifierFlag_ControlEdges);
- numGrids = subsurf->dm.getNumGrids(subsurf);
- gridSize = subsurf->dm.getGridSize(subsurf);
- gridData = subsurf->dm.getGridData(subsurf);
+ numGrids = subsurf->getNumGrids(subsurf);
+ gridSize = subsurf->getGridSize(subsurf);
+ gridData = subsurf->getGridData(subsurf);
subGridData = MEM_callocN(sizeof(DMGridData*)*numGrids, "subGridData*");
@@ -951,9 +956,9 @@ void multires_set_space(DerivedMesh *dm, Object *ob, int from, int to)
}
/*numGrids = ccgdm->dm->getNumGrids((DerivedMesh*)ccgdm);*/ /*UNUSED*/
- gridSize = ccgdm->dm.getGridSize((DerivedMesh*)ccgdm);
- gridData = ccgdm->dm.getGridData((DerivedMesh*)ccgdm);
- gridOffset = ccgdm->dm.getGridOffset((DerivedMesh*)ccgdm);
+ gridSize = ccgdm->getGridSize((DerivedMesh*)ccgdm);
+ gridData = ccgdm->getGridData((DerivedMesh*)ccgdm);
+ gridOffset = ccgdm->getGridOffset((DerivedMesh*)ccgdm);
dGridSize = multires_side_tot[totlvl];
dSkip = (dGridSize-1)/(gridSize-1);
@@ -1026,12 +1031,12 @@ void multires_set_space(DerivedMesh *dm, Object *ob, int from, int to)
cleanup:
if (subsurf) {
- subsurf->dm.needsFree = 1;
- subsurf->dm.release(subsurf);
+ subsurf->needsFree = 1;
+ subsurf->release(subsurf);
}
- ccgdm->dm.needsFree = 1;
- ccgdm->dm.release((DerivedMesh*)ccgdm);
+ ccgdm->needsFree = 1;
+ ccgdm->release(ccgdm);
}
void multires_stitch_grids(Object *ob)
diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c
index df012c47f66..c02b5dda9ce 100644
--- a/source/blender/blenkernel/intern/nla.c
+++ b/source/blender/blenkernel/intern/nla.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/nla.c
+ * \ingroup bke
+ */
+
+
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
@@ -291,7 +296,7 @@ NlaStrip *add_nlastrip (bAction *act)
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);
+ strip->end = (IS_EQF(strip->actstart, strip->actend)) ? (strip->actstart + 1.0f): (strip->actend);
/* strip should be referenced as-is */
strip->scale= 1.0f;
@@ -342,19 +347,20 @@ NlaStrip *add_nlastrip_to_stack (AnimData *adt, bAction *act)
*/
static float nlastrip_get_frame_actionclip (NlaStrip *strip, float cframe, short mode)
{
- float actlength, repeat, scale;
+ float actlength, scale;
+ // float repeat; // UNUSED
/* get number of repeats */
- if (IS_EQ(strip->repeat, 0.0f)) strip->repeat = 1.0f;
- repeat = strip->repeat;
+ if (IS_EQF(strip->repeat, 0.0f)) strip->repeat = 1.0f;
+ // repeat = strip->repeat; // UNUSED
/* scaling */
- if (IS_EQ(strip->scale, 0.0f)) strip->scale= 1.0f;
+ if (IS_EQF(strip->scale, 0.0f)) strip->scale= 1.0f;
scale = (float)fabs(strip->scale); /* scale must be positive - we've got a special flag for reversing */
/* length of referenced action */
actlength = strip->actend - strip->actstart;
- if (IS_EQ(actlength, 0.0f)) actlength = 1.0f;
+ if (IS_EQF(actlength, 0.0f)) actlength = 1.0f;
/* reversed = play strip backwards */
if (strip->flag & NLASTRIP_FLAG_REVERSE) {
@@ -366,7 +372,7 @@ static float nlastrip_get_frame_actionclip (NlaStrip *strip, float cframe, short
return (strip->end + (strip->actstart * scale - cframe)) / scale;
}
else /* if (mode == NLATIME_CONVERT_EVAL) */{
- if (IS_EQ(cframe, strip->end) && IS_EQ(strip->repeat, ((int)strip->repeat))) {
+ if (IS_EQF(cframe, strip->end) && IS_EQF(strip->repeat, ((int)strip->repeat))) {
/* this case prevents the motion snapping back to the first frame at the end of the strip
* by catching the case where repeats is a whole number, which means that the end of the strip
* could also be interpreted as the end of the start of a repeat
@@ -377,7 +383,7 @@ static float nlastrip_get_frame_actionclip (NlaStrip *strip, float cframe, short
/* - the 'fmod(..., actlength*scale)' is needed to get the repeats working
* - the '/ scale' is needed to ensure that scaling influences the timing within the repeat
*/
- return strip->actend - fmod(cframe - strip->start, actlength*scale) / scale;
+ return strip->actend - fmodf(cframe - strip->start, actlength*scale) / scale;
}
}
}
@@ -389,7 +395,7 @@ static float nlastrip_get_frame_actionclip (NlaStrip *strip, float cframe, short
return strip->actstart + (cframe - strip->start) / scale;
}
else /* if (mode == NLATIME_CONVERT_EVAL) */{
- if (IS_EQ(cframe, strip->end) && IS_EQ(strip->repeat, ((int)strip->repeat))) {
+ if (IS_EQF(cframe, strip->end) && IS_EQF(strip->repeat, ((int)strip->repeat))) {
/* this case prevents the motion snapping back to the first frame at the end of the strip
* by catching the case where repeats is a whole number, which means that the end of the strip
* could also be interpreted as the end of the start of a repeat
@@ -400,7 +406,7 @@ static float nlastrip_get_frame_actionclip (NlaStrip *strip, float cframe, short
/* - the 'fmod(..., actlength*scale)' is needed to get the repeats working
* - the '/ scale' is needed to ensure that scaling influences the timing within the repeat
*/
- return strip->actstart + fmod(cframe - strip->start, actlength*scale) / scale;
+ return strip->actstart + fmodf(cframe - strip->start, actlength*scale) / scale;
}
}
}
@@ -502,7 +508,7 @@ short BKE_nlastrips_has_space (ListBase *strips, float start, float end)
NlaStrip *strip;
/* sanity checks */
- if ((strips == NULL) || IS_EQ(start, end))
+ if ((strips == NULL) || IS_EQF(start, end))
return 0;
if (start > end) {
puts("BKE_nlastrips_has_space() error... start and end arguments swapped");
@@ -795,13 +801,13 @@ void BKE_nlameta_flush_transforms (NlaStrip *mstrip)
* don't flush if nothing changed yet
* TODO: maybe we need a flag to say always flush?
*/
- if (IS_EQ(oStart, mstrip->start) && IS_EQ(oEnd, mstrip->end))
+ if (IS_EQF(oStart, mstrip->start) && IS_EQF(oEnd, mstrip->end))
return;
/* check if scale changed */
oLen = oEnd - oStart;
nLen = mstrip->end - mstrip->start;
- if (IS_EQ(nLen, oLen) == 0)
+ if (IS_EQF(nLen, oLen) == 0)
scaleChanged= 1;
/* for each child-strip, calculate new start/end points based on this new info */
@@ -922,7 +928,7 @@ short BKE_nlatrack_has_space (NlaTrack *nlt, float start, float end)
* - track must be editable
* - bounds cannot be equal (0-length is nasty)
*/
- if ((nlt == NULL) || (nlt->flag & NLATRACK_PROTECTED) || IS_EQ(start, end))
+ if ((nlt == NULL) || (nlt->flag & NLATRACK_PROTECTED) || IS_EQF(start, end))
return 0;
if (start > end) {
@@ -1039,7 +1045,7 @@ short BKE_nlastrip_within_bounds (NlaStrip *strip, float min, float max)
const float boundsLen= (float)fabs(max - min);
/* sanity checks */
- if ((strip == NULL) || IS_EQ(stripLen, 0.0f) || IS_EQ(boundsLen, 0.0f))
+ if ((strip == NULL) || IS_EQF(stripLen, 0.0f) || IS_EQF(boundsLen, 0.0f))
return 0;
/* only ok if at least part of the strip is within the bounding window
@@ -1079,12 +1085,12 @@ void BKE_nlastrip_recalculate_bounds (NlaStrip *strip)
/* calculate new length factors */
actlen= strip->actend - strip->actstart;
- if (IS_EQ(actlen, 0.0f)) actlen= 1.0f;
+ if (IS_EQF(actlen, 0.0f)) actlen= 1.0f;
mapping= strip->scale * strip->repeat;
/* adjust endpoint of strip in response to this */
- if (IS_EQ(mapping, 0.0f) == 0)
+ if (IS_EQF(mapping, 0.0f) == 0)
strip->end = (actlen * mapping) + strip->start;
}
@@ -1308,11 +1314,11 @@ static void nlastrip_get_endpoint_overlaps (NlaStrip *strip, NlaTrack *track, fl
/* if this strip is not part of an island of continuous strips, it can be used
* - this check needs to be done for each end of the strip we try and use...
*/
- if ((nls->next == NULL) || IS_EQ(nls->next->start, nls->end)==0) {
+ if ((nls->next == NULL) || IS_EQF(nls->next->start, nls->end)==0) {
if ((nls->end > strip->start) && (nls->end < strip->end))
*start= &nls->end;
}
- if ((nls->prev == NULL) || IS_EQ(nls->prev->end, nls->start)==0) {
+ if ((nls->prev == NULL) || IS_EQF(nls->prev->end, nls->start)==0) {
if ((nls->start < strip->end) && (nls->start > strip->start))
*end= &nls->start;
}
@@ -1344,7 +1350,7 @@ static void BKE_nlastrip_validate_autoblends (NlaTrack *nlt, NlaStrip *nls)
* is directly followed/preceeded by another strip, forming an
* 'island' of continuous strips
*/
- if ( (ps || ns) && ((nls->prev == NULL) || IS_EQ(nls->prev->end, nls->start)==0) )
+ if ( (ps || ns) && ((nls->prev == NULL) || IS_EQF(nls->prev->end, nls->start)==0) )
{
/* start overlaps - pick the largest overlap */
if ( ((ps && ns) && (*ps > *ns)) || (ps) )
@@ -1355,7 +1361,7 @@ static void BKE_nlastrip_validate_autoblends (NlaTrack *nlt, NlaStrip *nls)
else /* no overlap allowed/needed */
nls->blendin= 0.0f;
- if ( (pe || ne) && ((nls->next == NULL) || IS_EQ(nls->next->start, nls->end)==0) )
+ if ( (pe || ne) && ((nls->next == NULL) || IS_EQF(nls->next->start, nls->end)==0) )
{
/* end overlaps - pick the largest overlap */
if ( ((pe && ne) && (*pe > *ne)) || (pe) )
@@ -1494,7 +1500,7 @@ short BKE_nla_tweakmode_enter (AnimData *adt)
if ELEM3(NULL, activeTrack, activeStrip, activeStrip->act) {
if (G.f & G_DEBUG) {
printf("NLA tweakmode enter - neither active requirement found \n");
- printf("\tactiveTrack = %p, activeStrip = %p \n", activeTrack, activeStrip);
+ printf("\tactiveTrack = %p, activeStrip = %p \n", (void *)activeTrack, (void *)activeStrip);
}
return 0;
}
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index 53bac9171ae..03fdcdd0c91 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/node.c
+ * \ingroup bke
+ */
+
+
#ifdef WITH_PYTHON
#include <Python.h>
#endif
@@ -897,6 +902,7 @@ void nodeGroupRemoveSocket(bNodeTree *ngroup, bNodeSocket *gsock, int in_out)
case SOCK_IN: BLI_remlink(&ngroup->inputs, gsock); break;
case SOCK_OUT: BLI_remlink(&ngroup->outputs, gsock); break;
}
+ MEM_freeN(gsock);
}
/* ************** Add stuff ********** */
@@ -1183,6 +1189,12 @@ bNodeTree *ntreeCopyTree(bNodeTree *ntree)
newtree= MEM_dupallocN(ntree);
copy_libblock_data(&newtree->id, &ntree->id, TRUE); /* copy animdata and ID props */
}
+
+ /* in case a running nodetree is copied */
+ newtree->init &= ~(NTREE_EXEC_INIT);
+ newtree->threadstack= NULL;
+ newtree->stack= NULL;
+
newtree->nodes.first= newtree->nodes.last= NULL;
newtree->links.first= newtree->links.last= NULL;
@@ -1314,7 +1326,7 @@ void ntreeClearPreview(bNodeTree *ntree)
/* hack warning! this function is only used for shader previews, and
since it gets called multiple times per pixel for Ztransp we only
add the color once. Preview gets cleared before it starts render though */
-void nodeAddToPreview(bNode *node, float *col, int x, int y)
+void nodeAddToPreview(bNode *node, float *col, int x, int y, int do_manage)
{
bNodePreview *preview= node->preview;
if(preview) {
@@ -1322,7 +1334,7 @@ void nodeAddToPreview(bNode *node, float *col, int x, int y)
if(x<preview->xsize && y<preview->ysize) {
unsigned char *tar= preview->rect+ 4*((preview->xsize*y) + x);
- if(TRUE) {
+ if(do_manage) {
tar[0]= FTOCHAR(linearrgb_to_srgb(col[0]));
tar[1]= FTOCHAR(linearrgb_to_srgb(col[1]));
tar[2]= FTOCHAR(linearrgb_to_srgb(col[2]));
@@ -1748,32 +1760,29 @@ void ntreeSocketUseFlags(bNodeTree *ntree)
/* ************** dependency stuff *********** */
/* node is guaranteed to be not checked before */
-static int node_recurs_check(bNode *node, bNode ***nsort, int level)
+static int node_recurs_check(bNode *node, bNode ***nsort)
{
bNode *fromnode;
bNodeSocket *sock;
- int has_inputlinks= 0;
+ int level = 0xFFF;
node->done= 1;
- level++;
for(sock= node->inputs.first; sock; sock= sock->next) {
if(sock->link) {
- has_inputlinks= 1;
fromnode= sock->link->fromnode;
- if(fromnode && fromnode->done==0) {
- fromnode->level= node_recurs_check(fromnode, nsort, level);
+ if(fromnode) {
+ if (fromnode->done==0)
+ fromnode->level= node_recurs_check(fromnode, nsort);
+ if (fromnode->level <= level)
+ level = fromnode->level - 1;
}
}
}
-// printf("node sort %s level %d\n", node->name, level);
**nsort= node;
(*nsort)++;
- if(has_inputlinks)
- return level;
- else
- return 0xFFF;
+ return level;
}
@@ -1862,7 +1871,7 @@ void ntreeSolveOrder(bNodeTree *ntree)
/* recursive check */
for(node= ntree->nodes.first; node; node= node->next) {
if(node->done==0) {
- node->level= node_recurs_check(node, &nsort, 0);
+ node->level= node_recurs_check(node, &nsort);
}
}
@@ -2318,8 +2327,15 @@ void ntreeBeginExecTree(bNodeTree *ntree)
for(sock= node->inputs.first; sock; sock= sock->next) {
ns = get_socket_stack(ntree->stack, sock, NULL);
- if (ns)
+ if (ns) {
ns->hasoutput = 1;
+
+ /* sock type is needed to detect rgba or value or vector types */
+ if(sock->link && sock->link->fromsock)
+ ns->sockettype= sock->link->fromsock->type;
+ else
+ sock->ns.sockettype= sock->type;
+ }
if(sock->link) {
bNodeLink *link= sock->link;
@@ -2450,7 +2466,7 @@ static int node_only_value(bNode *node)
if(node->inputs.first && node->type==CMP_NODE_MAP_VALUE) {
int retval= 1;
for(sock= node->inputs.first; sock; sock= sock->next) {
- if(sock->link)
+ if(sock->link && sock->link->fromnode)
retval &= node_only_value(sock->link->fromnode);
}
return retval;
@@ -2608,7 +2624,7 @@ static void freeExecutableNode(bNodeTree *ntree)
for(node= ntree->nodes.first; node; node= node->next) {
if((node->exec & NODE_FINISHED)==0) {
for(sock= node->inputs.first; sock; sock= sock->next)
- if(sock->link)
+ if(sock->link && sock->link->fromnode)
sock->link->fromnode->exec &= ~NODE_FREEBUFS;
}
}
@@ -2709,7 +2725,7 @@ void ntreeCompositExecTree(bNodeTree *ntree, RenderData *rd, int do_preview)
node= getExecutableNode(ntree);
if(node) {
if(ntree->progress && totnode)
- ntree->progress(ntree->prh, (1.0 - curnode/(float)totnode));
+ ntree->progress(ntree->prh, (1.0f - curnode/(float)totnode));
if(ntree->stats_draw) {
char str[64];
sprintf(str, "Compositing %d %s", curnode, node->name);
@@ -2759,8 +2775,8 @@ void ntreeCompositExecTree(bNodeTree *ntree, RenderData *rd, int do_preview)
/* ********** copy composite tree entirely, to allow threaded exec ******************* */
/* ***************** do NOT execute this in a thread! ****************** */
-/* returns localized composite tree for execution in threads */
-/* local tree then owns all compbufs */
+/* returns localized tree for execution in threads */
+/* local tree then owns all compbufs (for composite) */
bNodeTree *ntreeLocalize(bNodeTree *ntree)
{
bNodeTree *ltree;
@@ -2797,16 +2813,17 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree)
/* end animdata uglyness */
/* ensures only a single output node is enabled */
- ntreeSetOutput(ntree);
+ ntreeSetOutput(ltree);
for(node= ntree->nodes.first; node; node= node->next) {
/* store new_node pointer to original */
node->new_node->new_node= node;
- /* ensure new user input gets handled ok */
- node->need_exec= 0;
if(ntree->type==NTREE_COMPOSIT) {
+ /* ensure new user input gets handled ok, only composites (texture nodes will break, for painting since it uses no tags) */
+ node->need_exec= 0;
+
/* move over the compbufs */
/* right after ntreeCopyTree() oldsock pointers are valid */
@@ -2874,7 +2891,7 @@ void ntreeLocalSync(bNodeTree *localtree, bNodeTree *ntree)
}
}
}
- else if(ntree->type==NTREE_SHADER) {
+ else if(ELEM(ntree->type, NTREE_SHADER, NTREE_TEXTURE)) {
/* copy over contents of previews */
for(lnode= localtree->nodes.first; lnode; lnode= lnode->next) {
if(node_exists(ntree, lnode->new_node)) {
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 9910392e2d0..fae65a366d1 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -29,6 +29,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/object.c
+ * \ingroup bke
+ */
+
+
#include <string.h>
#include <math.h>
#include <stdio.h>
@@ -1407,7 +1412,7 @@ void make_local_object(Object *ob)
if(ob->id.us==1) {
ob->id.lib= NULL;
ob->id.flag= LIB_LOCAL;
- new_id(0, (ID *)ob, 0);
+ new_id(NULL, (ID *)ob, NULL);
}
else {
@@ -1426,9 +1431,9 @@ void make_local_object(Object *ob)
}
if(local && lib==0) {
- ob->id.lib= 0;
+ ob->id.lib= NULL;
ob->id.flag= LIB_LOCAL;
- new_id(0, (ID *)ob, 0);
+ new_id(NULL, (ID *)ob, NULL);
}
else if(local && lib) {
obn= copy_object(ob);
@@ -1436,7 +1441,7 @@ void make_local_object(Object *ob)
sce= bmain->scene.first;
while(sce) {
- if(sce->id.lib==0) {
+ if(sce->id.lib==NULL) {
base= sce->base.first;
while(base) {
if(base->object==ob) {
@@ -1559,6 +1564,9 @@ void object_make_proxy(Object *ob, Object *target, Object *gob)
if(gob) {
ob->rotmode= target->rotmode;
mul_m4_m4m4(ob->obmat, target->obmat, gob->obmat);
+ if(gob->dup_group) { /* should always be true */
+ sub_v3_v3(ob->obmat[3], gob->dup_group->dupli_ofs);
+ }
object_apply_mat4(ob, ob->obmat, FALSE, TRUE);
}
else {
@@ -1810,19 +1818,19 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4])
* we divide the curvetime calculated in the previous step by the length of the path, to get a time
* factor, which then gets clamped to lie within 0.0 - 1.0 range
*/
- if (IS_EQ(cu->pathlen, 0.0f) == 0)
+ if (IS_EQF(cu->pathlen, 0.0f) == 0)
ctime= cu->ctime / cu->pathlen;
else
ctime= cu->ctime;
-
- CLAMP(ctime, 0.0, 1.0);
+
+ CLAMP(ctime, 0.0f, 1.0f);
}
else {
ctime= scene->r.cfra - give_timeoffset(ob);
- if (IS_EQ(cu->pathlen, 0.0f) == 0)
+ if (IS_EQF(cu->pathlen, 0.0f) == 0)
ctime /= cu->pathlen;
- CLAMP(ctime, 0.0, 1.0);
+ CLAMP(ctime, 0.0f, 1.0f);
}
/* time calculus is correct, now apply distance offset */
@@ -2340,9 +2348,9 @@ void object_get_dimensions(Object *ob, float *value)
mat4_to_size( scale,ob->obmat);
- value[0] = fabs(scale[0]) * (bb->vec[4][0] - bb->vec[0][0]);
- value[1] = fabs(scale[1]) * (bb->vec[2][1] - bb->vec[0][1]);
- value[2] = fabs(scale[2]) * (bb->vec[1][2] - bb->vec[0][2]);
+ value[0] = fabsf(scale[0]) * (bb->vec[4][0] - bb->vec[0][0]);
+ value[1] = fabsf(scale[1]) * (bb->vec[2][1] - bb->vec[0][1]);
+ value[2] = fabsf(scale[2]) * (bb->vec[1][2] - bb->vec[0][2]);
} else {
value[0] = value[1] = value[2] = 0.f;
}
@@ -2564,6 +2572,9 @@ void object_handle_update(Scene *scene, Object *ob)
Object *obg= ob->proxy_from->proxy_group;
invert_m4_m4(obg->imat, obg->obmat);
mul_m4_m4m4(ob->obmat, ob->proxy_from->obmat, obg->imat);
+ if(obg->dup_group) { /* should always be true */
+ add_v3_v3(ob->obmat[3], obg->dup_group->dupli_ofs);
+ }
}
else
copy_m4_m4(ob->obmat, ob->proxy_from->obmat);
@@ -2862,18 +2873,18 @@ void object_camera_matrix(
}
else if(camera->type==OB_LAMP) {
Lamp *la= camera->data;
- float fac= cos( M_PI*la->spotsize/360.0 );
+ float fac= cosf((float)M_PI*la->spotsize/360.0f);
float phi= acos(fac);
- (*lens)= 16.0*fac/sin(phi);
+ (*lens)= 16.0f*fac/sinf(phi);
if((*lens)==0.0f)
- (*lens)= 35.0;
+ (*lens)= 35.0f;
(*clipsta)= la->clipsta;
(*clipend)= la->clipend;
}
else { /* envmap exception... */;
if((*lens)==0.0f)
- (*lens)= 16.0;
+ (*lens)= 16.0f;
if((*clipsta)==0.0f || (*clipend)==0.0f) {
(*clipsta)= 0.1f;
@@ -2893,8 +2904,8 @@ void object_camera_matrix(
pixsize= cam->ortho_scale/viewfac;
}
else {
- if(rd->xasp*winx >= rd->yasp*winy) viewfac= ((*lens) * winx)/32.0;
- else viewfac= (*ycor) * ((*lens) * winy)/32.0;
+ if(rd->xasp*winx >= rd->yasp*winy) viewfac= ((*lens) * winx)/32.0f;
+ else viewfac= (*ycor) * ((*lens) * winy)/32.0f;
pixsize= (*clipsta) / viewfac;
}
@@ -2907,12 +2918,12 @@ void object_camera_matrix(
if(field_second) {
if(rd->mode & R_ODDFIELD) {
- viewplane->ymin-= 0.5 * (*ycor);
- viewplane->ymax-= 0.5 * (*ycor);
+ viewplane->ymin-= 0.5f * (*ycor);
+ viewplane->ymax-= 0.5f * (*ycor);
}
else {
- viewplane->ymin+= 0.5 * (*ycor);
- viewplane->ymax+= 0.5 * (*ycor);
+ viewplane->ymin+= 0.5f * (*ycor);
+ viewplane->ymax+= 0.5f * (*ycor);
}
}
/* the window matrix is used for clipping, and not changed during OSA steps */
@@ -3070,3 +3081,53 @@ KeyBlock *object_insert_shape_key(Scene *scene, Object *ob, const char *name, in
else return NULL;
}
+/* most important if this is modified it should _always_ return True, in certain
+ * cases false positives are hard to avoid (shape keys for eg)
+ */
+int object_is_modified(Scene *scene, Object *ob)
+{
+ int flag= 0;
+
+ if(ob_get_key(ob)) {
+ flag |= eModifierMode_Render | eModifierMode_Render;
+ }
+ else {
+ ModifierData *md;
+ /* cloth */
+ for(md=modifiers_getVirtualModifierList(ob); md && (flag != (eModifierMode_Render | eModifierMode_Realtime)); md=md->next) {
+ if((flag & eModifierMode_Render) == 0 && modifier_isEnabled(scene, md, eModifierMode_Render)) flag |= eModifierMode_Render;
+ if((flag & eModifierMode_Realtime) == 0 && modifier_isEnabled(scene, md, eModifierMode_Realtime)) flag |= eModifierMode_Realtime;
+ }
+ }
+
+ return flag;
+}
+
+static void copy_object__forwardModifierLinks(void *UNUSED(userData), Object *UNUSED(ob), ID **idpoin)
+{
+ /* this is copied from ID_NEW; it might be better to have a macro */
+ if(*idpoin && (*idpoin)->newid) *idpoin = (*idpoin)->newid;
+}
+
+void object_relink(Object *ob)
+{
+ if(ob->id.lib)
+ return;
+
+ relink_constraints(&ob->constraints);
+ if (ob->pose){
+ bPoseChannel *chan;
+ for (chan = ob->pose->chanbase.first; chan; chan=chan->next){
+ relink_constraints(&chan->constraints);
+ }
+ }
+ modifiers_foreachIDLink(ob, copy_object__forwardModifierLinks, NULL);
+
+ if(ob->adt)
+ BKE_relink_animdata(ob->adt);
+
+ ID_NEW(ob->parent);
+
+ ID_NEW(ob->proxy);
+ ID_NEW(ob->proxy_group);
+}
diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c
index 981b3b31e71..ed729d819b7 100644
--- a/source/blender/blenkernel/intern/packedFile.c
+++ b/source/blender/blenkernel/intern/packedFile.c
@@ -29,6 +29,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/packedFile.c
+ * \ingroup bke
+ */
+
+
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index e53888127f2..5be492d1108 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/paint.c
+ * \ingroup bke
+ */
+
+
#include "DNA_object_types.h"
#include "DNA_mesh_types.h"
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 4b3b30e6cd2..e5d77355d5d 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -29,6 +29,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/particle.c
+ * \ingroup bke
+ */
+
+
#include <stdlib.h>
#include <math.h>
#include <string.h>
@@ -568,6 +573,7 @@ void psys_free(Object *ob, ParticleSystem * psys)
BLI_freelistN(&psys->targets);
+ BLI_bvhtree_free(psys->bvhtree);
BLI_kdtree_free(psys->tree);
if(psys->fluid_springs)
@@ -656,7 +662,7 @@ static float psys_render_projected_area(ParticleSystem *psys, float *center, flo
}
/* screen space radius */
- radius= sqrt(area/M_PI);
+ radius= sqrt(area/(float)M_PI);
/* make smaller using fallof once over screen edge */
*viewport= 1.0f;
@@ -865,7 +871,7 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot)
powrate= log(0.5f)/log(part->simplify_rate*0.5f);
if(part->simplify_flag & PART_SIMPLIFY_VIEWPORT)
- vprate= pow(1.0 - part->simplify_viewport, 5.0);
+ vprate= pow(1.0f - part->simplify_viewport, 5.0);
else
vprate= 1.0;
@@ -876,7 +882,7 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot)
if((arearatio < 1.0f || viewport < 1.0f) && elem->totchild) {
/* lambda is percentage of elements to keep */
- lambda= (arearatio < 1.0f)? pow(arearatio, powrate): 1.0f;
+ lambda= (arearatio < 1.0f)? powf(arearatio, powrate): 1.0f;
lambda *= viewport;
lambda= MAX2(lambda, 1.0f/elem->totchild);
@@ -1207,7 +1213,7 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData
PTCacheEditPoint *point = pind->epoint;
ParticleKey keys[4];
int point_vel = (point && point->keys->vel);
- float real_t, dfra, keytime, invdt;
+ float real_t, dfra, keytime, invdt = 1.f;
/* billboards wont fill in all of these, so start cleared */
memset(keys, 0, sizeof(keys));
@@ -1346,10 +1352,10 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData
dfra = keys[2].time - keys[1].time;
keytime = (real_t - keys[1].time) / dfra;
- invdt = dfra * 0.04f * psys->part->timetweak;
/* convert velocity to timestep size */
if(pind->keyed || pind->cache || point_vel){
+ invdt = dfra * 0.04f * (psys ? psys->part->timetweak : 1.f);
mul_v3_fl(keys[1].vel, invdt);
mul_v3_fl(keys[2].vel, invdt);
interp_qt_qtqt(result->rot,keys[1].rot,keys[2].rot,keytime);
@@ -1986,25 +1992,25 @@ static void do_kink(ParticleKey *state, ParticleKey *par, float *par_rot, float
inp_y=dot_v3v3(y_vec, vec_one);
inp_z=dot_v3v3(z_vec, vec_one);
- if(inp_y>0.5){
+ if(inp_y > 0.5f){
copy_v3_v3(state_co, y_vec);
mul_v3_fl(y_vec, amplitude*(float)cos(t));
mul_v3_fl(z_vec, amplitude/2.f*(float)sin(2.f*t));
}
- else if(inp_z>0.0){
- mul_v3_v3fl(state_co, z_vec, (float)sin(M_PI/3.f));
+ else if(inp_z > 0.0f){
+ mul_v3_v3fl(state_co, z_vec, (float)sin((float)M_PI/3.f));
VECADDFAC(state_co,state_co,y_vec,-0.5f);
- mul_v3_fl(y_vec, -amplitude * (float)cos(t + M_PI/3.f));
- mul_v3_fl(z_vec, amplitude/2.f * (float)cos(2.f*t + M_PI/6.f));
+ mul_v3_fl(y_vec, -amplitude * (float)cos(t + (float)M_PI/3.f));
+ mul_v3_fl(z_vec, amplitude/2.f * (float)cos(2.f*t + (float)M_PI/6.f));
}
else{
- mul_v3_v3fl(state_co, z_vec, -(float)sin(M_PI/3.f));
+ mul_v3_v3fl(state_co, z_vec, -(float)sin((float)M_PI/3.f));
madd_v3_v3fl(state_co, y_vec, -0.5f);
- mul_v3_fl(y_vec, amplitude * (float)-sin(t + M_PI/6.f));
- mul_v3_fl(z_vec, amplitude/2.f * (float)-sin(2.f*t + M_PI/3.f));
+ mul_v3_fl(y_vec, amplitude * (float)-sin(t + (float)M_PI/6.f));
+ mul_v3_fl(z_vec, amplitude/2.f * (float)-sin(2.f*t + (float)M_PI/3.f));
}
mul_v3_fl(state_co, amplitude);
@@ -2043,15 +2049,15 @@ static float do_clump(ParticleKey *state, ParticleKey *par, float time, float cl
{
float clump = 0.f;
- if(par && clumpfac!=0.0){
+ if(par && clumpfac!=0.0f){
float cpow;
- if(clumppow<0.0)
+ if(clumppow < 0.0f)
cpow=1.0f+clumppow;
else
cpow=1.0f+9.0f*clumppow;
- if(clumpfac<0.0) /* clump roots instead of tips */
+ if(clumpfac < 0.0f) /* clump roots instead of tips */
clump = -clumpfac*pa_clump*(float)pow(1.0-(double)time,(double)cpow);
else
clump = clumpfac*pa_clump*(float)pow((double)time,(double)cpow);
@@ -2125,7 +2131,7 @@ int do_guides(ListBase *effectors, ParticleKey *state, int index, float time)
if(data->strength <= 0.0f)
continue;
- guidetime = time / (1.0 - pd->free_end);
+ guidetime = time / (1.0f - pd->free_end);
if(guidetime>1.0f)
continue;
@@ -2148,7 +2154,7 @@ int do_guides(ListBase *effectors, ParticleKey *state, int index, float time)
VECCOPY(vec_to_point, data->vec_to_point);
- if(guidetime != 0.0){
+ if(guidetime != 0.0f) {
/* curve direction */
cross_v3_v3v3(temp, eff->guide_dir, guidedir);
angle = dot_v3v3(eff->guide_dir, guidedir)/(len_v3(eff->guide_dir));
@@ -2163,7 +2169,7 @@ int do_guides(ListBase *effectors, ParticleKey *state, int index, float time)
/* curve taper */
if(cu->taperobj)
- mul_v3_fl(vec_to_point, calc_taper(eff->scene, cu->taperobj, (int)(data->strength*guidetime*100.0), 100));
+ mul_v3_fl(vec_to_point, calc_taper(eff->scene, cu->taperobj, (int)(data->strength*guidetime*100.0f), 100));
else{ /* curve size*/
if(cu->flag & CU_PATH_RADIUS) {
@@ -2187,10 +2193,10 @@ int do_guides(ListBase *effectors, ParticleKey *state, int index, float time)
totstrength *= weight;
}
- if(totstrength != 0.0){
- if(totstrength > 1.0)
+ if(totstrength != 0.0f){
+ if(totstrength > 1.0f)
mul_v3_fl(effect, 1.0f / totstrength);
- CLAMP(totstrength, 0.0, 1.0);
+ CLAMP(totstrength, 0.0f, 1.0f);
//VECADD(effect,effect,pa_zero);
interp_v3_v3v3(state->co, state->co, effect, totstrength);
@@ -2206,8 +2212,8 @@ static void do_rough(float *loc, float mat[4][4], float t, float fac, float size
float rough[3];
float rco[3];
- if(thres!=0.0)
- if((float)fabs((float)(-1.5+loc[0]+loc[1]+loc[2]))<1.5f*thres) return;
+ if(thres != 0.0f)
+ if((float)fabs((float)(-1.5f+loc[0]+loc[1]+loc[2]))<1.5f*thres) return;
VECCOPY(rco,loc);
mul_v3_fl(rco,t);
@@ -2250,7 +2256,7 @@ static void do_path_effectors(ParticleSimulationData *sim, int i, ParticleCacheK
pd_point_from_particle(sim, sim->psys->particles+i, &eff_key, &epoint);
pdDoEffectors(sim->psys->effectors, sim->colliders, sim->psys->part->effector_weights, &epoint, force, NULL);
- mul_v3_fl(force, effector*pow((float)k / (float)steps, 100.0f * sim->psys->part->eff_hair) / (float)steps);
+ mul_v3_fl(force, effector*powf((float)k / (float)steps, 100.0f * sim->psys->part->eff_hair) / (float)steps);
add_v3_v3(force, vec);
@@ -2329,7 +2335,7 @@ void psys_find_parents(ParticleSimulationData *sim)
int p, totparent,totchild=sim->psys->totchild;
float co[3], orco[3];
int from=PART_FROM_FACE;
- totparent=(int)(totchild*part->parents*0.3);
+ totparent=(int)(totchild*part->parents*0.3f);
if(G.rendering && part->child_nbr && part->ren_child_nbr)
totparent*=(float)part->child_nbr/(float)part->ren_child_nbr;
@@ -2404,8 +2410,8 @@ static int psys_threads_init_path(ParticleThread *threads, Scene *scene, float c
steps = (int)pow(2.0, (double)pset->draw_step);
}
- if(totchild && part->from!=PART_FROM_PARTICLE && part->childtype==PART_CHILD_FACES){
- totparent=(int)(totchild*part->parents*0.3);
+ if(totchild && part->childtype==PART_CHILD_FACES){
+ totparent=(int)(totchild*part->parents*0.3f);
if(G.rendering && part->child_nbr && part->ren_child_nbr)
totparent*=(float)part->child_nbr/(float)part->ren_child_nbr;
@@ -2446,16 +2452,14 @@ static int psys_threads_init_path(ParticleThread *threads, Scene *scene, float c
psys->lattice = psys_get_lattice(&ctx->sim);
/* cache all relevant vertex groups if they exist */
- if(part->from!=PART_FROM_PARTICLE){
- ctx->vg_length = psys_cache_vgroup(ctx->dm,psys,PSYS_VG_LENGTH);
- ctx->vg_clump = psys_cache_vgroup(ctx->dm,psys,PSYS_VG_CLUMP);
- ctx->vg_kink = psys_cache_vgroup(ctx->dm,psys,PSYS_VG_KINK);
- ctx->vg_rough1 = psys_cache_vgroup(ctx->dm,psys,PSYS_VG_ROUGH1);
- ctx->vg_rough2 = psys_cache_vgroup(ctx->dm,psys,PSYS_VG_ROUGH2);
- ctx->vg_roughe = psys_cache_vgroup(ctx->dm,psys,PSYS_VG_ROUGHE);
- if(psys->part->flag & PART_CHILD_EFFECT)
- ctx->vg_effector = psys_cache_vgroup(ctx->dm,psys,PSYS_VG_EFFECTOR);
- }
+ ctx->vg_length = psys_cache_vgroup(ctx->dm,psys,PSYS_VG_LENGTH);
+ ctx->vg_clump = psys_cache_vgroup(ctx->dm,psys,PSYS_VG_CLUMP);
+ ctx->vg_kink = psys_cache_vgroup(ctx->dm,psys,PSYS_VG_KINK);
+ ctx->vg_rough1 = psys_cache_vgroup(ctx->dm,psys,PSYS_VG_ROUGH1);
+ ctx->vg_rough2 = psys_cache_vgroup(ctx->dm,psys,PSYS_VG_ROUGH2);
+ ctx->vg_roughe = psys_cache_vgroup(ctx->dm,psys,PSYS_VG_ROUGHE);
+ if(psys->part->flag & PART_CHILD_EFFECT)
+ ctx->vg_effector = psys_cache_vgroup(ctx->dm,psys,PSYS_VG_EFFECTOR);
/* set correct ipo timing */
#if 0 // XXX old animation system
@@ -2547,7 +2551,7 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle
normalize_v3(v1);
normalize_v3(v2);
- d = saacos(dot_v3v3(v1, v2)) * 180.f / M_PI;
+ d = saacos(dot_v3v3(v1, v2)) * 180.0f/(float)M_PI;
}
if(p_max > p_min)
@@ -2702,7 +2706,7 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle
sub_v3_v3v3((child-1)->vel, child->co, (child-2)->co);
mul_v3_fl((child-1)->vel, 0.5);
- if(ctx->ma && (part->draw & PART_DRAW_MAT_COL))
+ if(ctx->ma && (part->draw_col == PART_DRAW_COL_MAT))
get_strand_normal(ctx->ma, ornor, cur_length, (child-1)->vel);
}
@@ -2721,7 +2725,7 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle
cur_length = 0.0f;
}
- if(ctx->ma && (part->draw & PART_DRAW_MAT_COL)) {
+ if(ctx->ma && (part->draw_col == PART_DRAW_COL_MAT)) {
VECCOPY(child->col, &ctx->ma->r)
get_strand_normal(ctx->ma, ornor, cur_length, child->vel);
}
@@ -2906,11 +2910,11 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra)
psys->lattice = psys_get_lattice(sim);
ma= give_current_material(sim->ob, psys->part->omat);
- if(ma && (psys->part->draw & PART_DRAW_MAT_COL))
+ if(ma && (psys->part->draw_col == PART_DRAW_COL_MAT))
VECCOPY(col, &ma->r)
- if(psys->part->from!=PART_FROM_PARTICLE && !(psys->flag & PSYS_GLOBAL_HAIR)) {
- if(!(psys->part->flag & PART_CHILD_EFFECT))
+ if((psys->flag & PSYS_GLOBAL_HAIR)==0) {
+ if((psys->part->flag & PART_CHILD_EFFECT)==0)
vg_effector = psys_cache_vgroup(psmd->dm, psys, PSYS_VG_EFFECTOR);
if(!psys->totchild)
@@ -3061,8 +3065,8 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf
ParticleInterpolationData pind;
ParticleKey result;
- float birthtime = 0.0, dietime = 0.0;
- float t, time = 0.0, keytime = 0.0, frs_sec;
+ float birthtime = 0.0f, dietime = 0.0f;
+ float t, time = 0.0f, keytime = 0.0f, frs_sec;
float hairmat[4][4], rotmat[3][3], prev_tangent[3] = {0.0f, 0.0f, 0.0f};
int k, i;
int steps = (int)pow(2.0, (double)pset->draw_step);
@@ -3344,7 +3348,8 @@ static void psys_face_mat(Object *ob, DerivedMesh *dm, ParticleData *pa, float m
/* ugly hack to use non-transformed orcos, since only those
* give symmetric results for mirroring in particle mode */
- transform_mesh_orco_verts(ob->data, v, 3, 1);
+ if(DM_get_vert_data_layer(dm, CD_ORIGINDEX))
+ transform_mesh_orco_verts(ob->data, v, 3, 1);
}
else {
dm->getVertCo(dm,mface->v1,v[0]);
@@ -3372,7 +3377,8 @@ void psys_mat_hair_to_orco(Object *ob, DerivedMesh *dm, short from, ParticleData
psys_particle_on_dm(dm, from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, vec, 0, 0, 0, orco, 0);
/* see psys_face_mat for why this function is called */
- transform_mesh_orco_verts(ob->data, &orco, 1, 1);
+ if(DM_get_vert_data_layer(dm, CD_ORIGINDEX))
+ transform_mesh_orco_verts(ob->data, &orco, 1, 1);
VECCOPY(hairmat[3],orco);
}
@@ -3532,16 +3538,15 @@ static void default_particle_settings(ParticleSettings *part)
part->clength=1.0f;
part->clength_thres=0.0f;
- part->draw= PART_DRAW_EMITTER|PART_DRAW_MAT_COL;
+ part->draw= PART_DRAW_EMITTER;
part->draw_line[0]=0.5;
part->path_start = 0.0f;
part->path_end = 1.0f;
part->keyed_loops = 1;
-#if 0 // XXX old animation system
- part->ipo = NULL;
-#endif // XXX old animation system
+ part->color_vec_max = 1.f;
+ part->draw_col = PART_DRAW_COL_MAT;
part->simplify_refsize= 1920;
part->simplify_rate= 1.0f;
@@ -3587,6 +3592,8 @@ ParticleSettings *psys_copy_settings(ParticleSettings *part)
id_us_plus((ID *)partn->mtex[a]->tex);
}
}
+
+ BLI_duplicatelist(&partn->dupliweights, &part->dupliweights);
return partn;
}
@@ -3694,8 +3701,8 @@ static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, fl
}
#define SET_PARTICLE_TEXTURE(type, pvalue, texfac) if((event & mtex->mapto) & type) {pvalue = texture_value_blend(def, pvalue, value, texfac, blend);}
-#define CLAMP_PARTICLE_TEXTURE_POS(type, pvalue) if(event & type) { if(pvalue < 0.f) pvalue = 1.f+pvalue; CLAMP(pvalue, 0.0, 1.0); }
-#define CLAMP_PARTICLE_TEXTURE_POSNEG(type, pvalue) if(event & type) { CLAMP(pvalue, -1.0, 1.0); }
+#define CLAMP_PARTICLE_TEXTURE_POS(type, pvalue) if(event & type) { if(pvalue < 0.f) pvalue = 1.f+pvalue; CLAMP(pvalue, 0.0f, 1.0f); }
+#define CLAMP_PARTICLE_TEXTURE_POSNEG(type, pvalue) if(event & type) { CLAMP(pvalue, -1.0f, 1.0f); }
static void get_cpa_texture(DerivedMesh *dm, ParticleSystem *psys, ParticleSettings *part, ParticleData *par, int child_index, int face_index, float *fw, float *orco, ParticleTexture *ptex, int event, float cfra)
{
@@ -3895,7 +3902,7 @@ float psys_get_child_size(ParticleSystem *psys, ChildParticle *cpa, float UNUSED
size*=part->childsize;
- if(part->childrandsize!=0.0)
+ if(part->childrandsize != 0.0f)
size *= 1.0f - part->childrandsize * PSYS_FRAND(cpa - psys->child + 26);
return size;
@@ -3999,7 +4006,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey *
memset(keys, 0, 4*sizeof(ParticleKey));
t=state->time;
- CLAMP(t, 0.0, 1.0);
+ CLAMP(t, 0.0f, 1.0f);
if(p<totpart){
pa = psys->particles + p;
@@ -4037,7 +4044,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey *
if(state->time < 0.0f)
t = psys_get_child_time(psys, cpa, -state->time, NULL, NULL);
- if(totchild && part->from!=PART_FROM_PARTICLE && part->childtype==PART_CHILD_FACES){
+ if(totchild && part->childtype==PART_CHILD_FACES){
/* part->parents could still be 0 so we can't test with totparent */
between=1;
}
@@ -4187,7 +4194,7 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta
if(!psys->totchild)
return 0;
- if(part->from != PART_FROM_PARTICLE && part->childtype == PART_CHILD_FACES){
+ if(part->childtype == PART_CHILD_FACES){
if(!(psys->flag & PSYS_KEYED))
return 0;
@@ -4196,8 +4203,8 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta
state->time = psys_get_child_time(psys, cpa, cfra, NULL, NULL);
if(!always)
- if((state->time < 0.0 && !(part->flag & PART_UNBORN))
- || (state->time > 1.0 && !(part->flag & PART_DIED)))
+ if((state->time < 0.0f && !(part->flag & PART_UNBORN))
+ || (state->time > 1.0f && !(part->flag & PART_DIED)))
return 0;
state->time= (cfra - (part->sta + (part->end - part->sta) * PSYS_FRAND(p + 23))) / (part->lifetime * PSYS_FRAND(p + 24));
@@ -4237,7 +4244,7 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta
key1=&pa->state;
offset_child(cpa, key1, key1->rot, state, part->childflat, part->childrad);
- CLAMP(t,0.0,1.0);
+ CLAMP(t, 0.0f, 1.0f);
unit_m4(mat);
do_child_modifiers(sim, NULL, key1, key1->rot, cpa, cpa->fuv, mat, state, t);
@@ -4309,13 +4316,15 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta
}
}
-void psys_get_dupli_texture(Object *UNUSED(ob), ParticleSettings *part, ParticleSystemModifierData *psmd, ParticleData *pa, ChildParticle *cpa, float *uv, float *orco)
+void psys_get_dupli_texture(ParticleSystem *psys, ParticleSettings *part, ParticleSystemModifierData *psmd, ParticleData *pa, ChildParticle *cpa, float *uv, float *orco)
{
MFace *mface;
MTFace *mtface;
float loc[3];
int num;
+ uv[0] = uv[1] = 0.f;
+
if(cpa) {
if(part->childtype == PART_CHILD_FACES) {
mtface= CustomData_get_layer(&psmd->dm->faceData, CD_MTFACE);
@@ -4324,43 +4333,36 @@ void psys_get_dupli_texture(Object *UNUSED(ob), ParticleSettings *part, Particle
mtface += cpa->num;
psys_interpolate_uvs(mtface, mface->v4, cpa->fuv, uv);
}
- else
- uv[0]= uv[1]= 0.0f;
+
+ psys_particle_on_emitter(psmd,PART_FROM_FACE,cpa->num,DMCACHE_ISCHILD,cpa->fuv,cpa->foffset,loc,0,0,0,orco,0);
+ return;
+ }
+ else {
+ pa = psys->particles + cpa->pa[0];
}
- else
- uv[0]= uv[1]= 0.0f;
-
- psys_particle_on_emitter(psmd,
- (part->childtype == PART_CHILD_FACES)? PART_FROM_FACE: PART_FROM_PARTICLE,
- cpa->num,DMCACHE_ISCHILD,cpa->fuv,cpa->foffset,loc,0,0,0,orco,0);
}
- else {
- if(part->from == PART_FROM_FACE) {
- mtface= CustomData_get_layer(&psmd->dm->faceData, CD_MTFACE);
- num= pa->num_dmcache;
- if(num == DMCACHE_NOTFOUND)
- num= pa->num;
+ if(part->from == PART_FROM_FACE) {
+ mtface= CustomData_get_layer(&psmd->dm->faceData, CD_MTFACE);
+ num= pa->num_dmcache;
- if (num >= psmd->dm->getNumTessFaces(psmd->dm)) {
- /* happens when simplify is enabled
- * gives invalid coords but would crash otherwise */
- num= DMCACHE_NOTFOUND;
- }
+ if(num == DMCACHE_NOTFOUND)
+ num= pa->num;
- if(mtface && num != DMCACHE_NOTFOUND) {
- mface= psmd->dm->getTessFaceData(psmd->dm, num, CD_MFACE);
- mtface += num;
- psys_interpolate_uvs(mtface, mface->v4, pa->fuv, uv);
- }
- else
- uv[0]= uv[1]= 0.0f;
+ if (num >= psmd->dm->getNumTessFaces(psmd->dm)) {
+ /* happens when simplify is enabled
+ * gives invalid coords but would crash otherwise */
+ num= DMCACHE_NOTFOUND;
}
- else
- uv[0]= uv[1]= 0.0f;
- psys_particle_on_emitter(psmd,part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,loc,0,0,0,orco,0);
+ if(mtface && num != DMCACHE_NOTFOUND) {
+ mface= psmd->dm->getTessFaceData(psmd->dm, num, CD_MFACE);
+ mtface += num;
+ psys_interpolate_uvs(mtface, mface->v4, pa->fuv, uv);
+ }
}
+
+ psys_particle_on_emitter(psmd,part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,loc,0,0,0,orco,0);
}
void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa, ChildParticle *cpa, ParticleCacheKey *cache, float mat[][4], float *scale)
@@ -4375,7 +4377,7 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa
len= normalize_v3(vec);
if(psys->part->rotmode) {
- if(!pa)
+ if(pa == NULL)
pa= psys->particles+cpa->pa[0];
vec_to_quat( q,xvec, ob->trackflag, ob->upflag);
@@ -4386,12 +4388,13 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa
mul_m4_m4m4(mat, obrotmat, qmat);
}
else {
+ if(pa == NULL && psys->part->childflat != PART_CHILD_FACES)
+ pa = psys->particles + cpa->pa[0];
+
if(pa)
psys_particle_on_emitter(psmd,sim->psys->part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,loc,nor,0,0,0,0);
else
- psys_particle_on_emitter(psmd,
- (psys->part->childtype == PART_CHILD_FACES)? PART_FROM_FACE: PART_FROM_PARTICLE,
- cpa->num,DMCACHE_ISCHILD,cpa->fuv,cpa->foffset,loc,nor,0,0,0,0);
+ psys_particle_on_emitter(psmd,PART_FROM_FACE,cpa->num,DMCACHE_ISCHILD,cpa->fuv,cpa->foffset,loc,nor,0,0,0,0);
copy_m3_m4(nmat, ob->imat);
transpose_m3(nmat);
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index b4900553814..dbf2803ec18 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -29,6 +29,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/particle_system.c
+ * \ingroup bke
+ */
+
+
#include <stddef.h>
#include "BLI_storage.h" /* _LARGEFILE_SOURCE */
@@ -324,6 +329,10 @@ static void alloc_child_particles(ParticleSystem *psys, int tot)
}
}
+/************************************************/
+/* Distribution */
+/************************************************/
+
void psys_calc_dmcache(Object *ob, DerivedMesh *dm, ParticleSystem *psys)
{
/* use for building derived mesh mapping info:
@@ -400,7 +409,36 @@ void psys_calc_dmcache(Object *ob, DerivedMesh *dm, ParticleSystem *psys)
}
}
-static void distribute_particles_in_grid(DerivedMesh *dm, ParticleSystem *psys)
+static void distribute_simple_children(Scene *scene, Object *ob, DerivedMesh *finaldm, ParticleSystem *psys)
+{
+ ChildParticle *cpa = NULL;
+ int i, p;
+ int child_nbr= get_psys_child_number(scene, psys);
+ int totpart= get_psys_tot_child(scene, psys);
+
+ alloc_child_particles(psys, totpart);
+
+ cpa = psys->child;
+ for(i=0; i<child_nbr; i++){
+ for(p=0; p<psys->totpart; p++,cpa++){
+ float length=2.0;
+ cpa->parent=p;
+
+ /* create even spherical distribution inside unit sphere */
+ while(length>=1.0f){
+ cpa->fuv[0]=2.0f*BLI_frand()-1.0f;
+ cpa->fuv[1]=2.0f*BLI_frand()-1.0f;
+ cpa->fuv[2]=2.0f*BLI_frand()-1.0f;
+ length=len_v3(cpa->fuv);
+ }
+
+ cpa->num=-1;
+ }
+ }
+ /* dmcache must be updated for parent particles if children from faces is used */
+ psys_calc_dmcache(ob, finaldm, psys);
+}
+static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys)
{
ParticleData *pa=NULL;
float min[3], max[3], delta[3], d;
@@ -597,8 +635,8 @@ static void hammersley_create(float *out, int n, int seed, float amount)
int k, kk;
rng = rng_new(31415926 + n + seed);
- offs[0]= rng_getDouble(rng) + amount;
- offs[1]= rng_getDouble(rng) + amount;
+ offs[0]= rng_getDouble(rng) + (double)amount;
+ offs[1]= rng_getDouble(rng) + (double)amount;
rng_free(rng);
for (k = 0; k < n; k++) {
@@ -621,8 +659,8 @@ static void init_mv_jit(float *jit, int num, int seed2, float amount)
if(num==0) return;
- rad1= (float)(1.0/sqrt((float)num));
- rad2= (float)(1.0/((float)num));
+ rad1= (float)(1.0f/sqrtf((float)num));
+ rad2= (float)(1.0f/((float)num));
rad3= (float)sqrt((float)num)/((float)num);
rng = rng_new(31415926 + num + seed2);
@@ -681,7 +719,7 @@ static void psys_uv_to_w(float u, float v, int quad, float *w)
}
/* Find the index in "sum" array before "value" is crossed. */
-static int binary_search_distribution(float *sum, int n, float value)
+static int distribute_binary_search(float *sum, int n, float value)
{
int mid, low=0, high=n;
@@ -711,13 +749,11 @@ static int binary_search_distribution(float *sum, int n, float value)
/* note: this function must be thread safe, for from == PART_FROM_CHILD */
#define ONLY_WORKING_WITH_PA_VERTS 0
-static void psys_thread_distribute_particle(ParticleThread *thread, ParticleData *pa, ChildParticle *cpa, int p)
+static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, ChildParticle *cpa, int p)
{
ParticleThreadContext *ctx= thread->ctx;
Object *ob= ctx->sim.ob;
DerivedMesh *dm= ctx->dm;
- ParticleData *tpa;
-/* ParticleSettings *part= ctx->sim.psys->part; */
float *v1, *v2, *v3, *v4, nor[3], orco1[3], co1[3], co2[3], nor1[3];
float cur_d, min_d, randu, randv;
int from= ctx->from;
@@ -755,9 +791,17 @@ static void psys_thread_distribute_particle(ParticleThread *thread, ParticleData
switch(distr){
case PART_DISTR_JIT:
- ctx->jitoff[i] = fmod(ctx->jitoff[i],(float)ctx->jitlevel);
- psys_uv_to_w(ctx->jit[2*(int)ctx->jitoff[i]], ctx->jit[2*(int)ctx->jitoff[i]+1], mface->v4, pa->fuv);
- ctx->jitoff[i]++;
+ if(ctx->jitlevel == 1) {
+ if(mface->v4)
+ psys_uv_to_w(0.5f, 0.5f, mface->v4, pa->fuv);
+ else
+ psys_uv_to_w(0.33333f, 0.33333f, mface->v4, pa->fuv);
+ }
+ else {
+ ctx->jitoff[i] = fmod(ctx->jitoff[i],(float)ctx->jitlevel);
+ psys_uv_to_w(ctx->jit[2*(int)ctx->jitoff[i]], ctx->jit[2*(int)ctx->jitoff[i]+1], mface->v4, pa->fuv);
+ ctx->jitoff[i]++;
+ }
break;
case PART_DISTR_RAND:
randu= rng_getFloat(thread->rng);
@@ -823,15 +867,6 @@ static void psys_thread_distribute_particle(ParticleThread *thread, ParticleData
}
}
}
- else if(from == PART_FROM_PARTICLE) {
- tpa=ctx->tpars+ctx->index[p];
- pa->num=ctx->index[p];
- pa->fuv[0]=tpa->fuv[0];
- pa->fuv[1]=tpa->fuv[1];
- /* abusing foffset a little for timing in near reaction */
- pa->foffset=ctx->weight[ctx->index[p]];
- ctx->weight[ctx->index[p]]+=ctx->maxweight;
- }
else if(from == PART_FROM_CHILD) {
MFace *mf;
@@ -855,7 +890,7 @@ static void psys_thread_distribute_particle(ParticleThread *thread, ParticleData
if(ctx->tree){
KDTreeNearest ptn[10];
int w,maxw;//, do_seams;
- float maxd,mind,/*dd,*/totw=0.0;
+ float maxd,mind,/*dd,*/totw= 0.0f;
int parent[10];
float pweight[10];
@@ -865,7 +900,6 @@ static void psys_thread_distribute_particle(ParticleThread *thread, ParticleData
maxd=ptn[maxw-1].dist;
mind=ptn[0].dist;
- /*dd=maxd-mind;*/ /*UNUSED*/
/* the weights here could be done better */
for(w=0; w<maxw; w++){
@@ -901,7 +935,7 @@ static void psys_thread_distribute_particle(ParticleThread *thread, ParticleData
rng_skip(thread->rng, rng_skip_tot);
}
-static void *exec_distribution(void *data)
+static void *distribute_threads_exec_cb(void *data)
{
ParticleThread *thread= (ParticleThread*)data;
ParticleSystem *psys= thread->ctx->sim.psys;
@@ -918,7 +952,7 @@ static void *exec_distribution(void *data)
rng_skip(thread->rng, PSYS_RND_DIST_SKIP * thread->ctx->skip[p]);
if((p+thread->num) % thread->tot == 0)
- psys_thread_distribute_particle(thread, NULL, cpa, p);
+ distribute_threads_exec(thread, NULL, cpa, p);
else /* thread skip */
rng_skip(thread->rng, PSYS_RND_DIST_SKIP);
}
@@ -927,7 +961,7 @@ static void *exec_distribution(void *data)
totpart= psys->totpart;
pa= psys->particles + thread->num;
for(p=thread->num; p<totpart; p+=thread->tot, pa+=thread->tot)
- psys_thread_distribute_particle(thread, pa, NULL, p);
+ distribute_threads_exec(thread, pa, NULL, p);
}
return 0;
@@ -935,7 +969,7 @@ static void *exec_distribution(void *data)
/* not thread safe, but qsort doesn't take userdata argument */
static int *COMPARE_ORIG_INDEX = NULL;
-static int compare_orig_index(const void *p1, const void *p2)
+static int distribute_compare_orig_index(const void *p1, const void *p2)
{
int index1 = COMPARE_ORIG_INDEX[*(const int*)p1];
int index2 = COMPARE_ORIG_INDEX[*(const int*)p2];
@@ -956,44 +990,53 @@ static int compare_orig_index(const void *p1, const void *p2)
return 1;
}
-/* creates a distribution of coordinates on a DerivedMesh */
-/* */
-/* 1. lets check from what we are emitting */
-/* 2. now we know that we have something to emit from so */
-/* let's calculate some weights */
-/* 2.1 from even distribution */
-/* 2.2 and from vertex groups */
-/* 3. next we determine the indexes of emitting thing that */
-/* the particles will have */
-/* 4. let's do jitter if we need it */
-/* 5. now we're ready to set the indexes & distributions to */
-/* the particles */
-/* 6. and we're done! */
+static void distribute_invalid(Scene *scene, ParticleSystem *psys, int from)
+{
+ if(from == PART_FROM_CHILD) {
+ ChildParticle *cpa;
+ int p, totchild = get_psys_tot_child(scene, psys);
+
+ if(psys->child && totchild) {
+ for(p=0,cpa=psys->child; p<totchild; p++,cpa++){
+ cpa->fuv[0]=cpa->fuv[1]=cpa->fuv[2]=cpa->fuv[3]= 0.0;
+ cpa->foffset= 0.0f;
+ cpa->parent=0;
+ cpa->pa[0]=cpa->pa[1]=cpa->pa[2]=cpa->pa[3]=0;
+ cpa->num= -1;
+ }
+ }
+ }
+ else {
+ PARTICLE_P;
+ LOOP_PARTICLES {
+ pa->fuv[0]=pa->fuv[1]=pa->fuv[2]= pa->fuv[3]= 0.0;
+ pa->foffset= 0.0f;
+ pa->num= -1;
+ }
+ }
+}
+/* Creates a distribution of coordinates on a DerivedMesh */
/* This is to denote functionality that does not yet work with mesh - only derived mesh */
-static int psys_threads_init_distribution(ParticleThread *threads, Scene *scene, DerivedMesh *finaldm, int from)
+static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, DerivedMesh *finaldm, int from)
{
ParticleThreadContext *ctx= threads[0].ctx;
Object *ob= ctx->sim.ob;
ParticleSystem *psys= ctx->sim.psys;
- Object *tob;
ParticleData *pa=0, *tpars= 0;
ParticleSettings *part;
- ParticleSystem *tpsys;
ParticleSeam *seams= 0;
- ChildParticle *cpa=0;
KDTree *tree=0;
DerivedMesh *dm= NULL;
float *jit= NULL;
int i, seed, p=0, totthread= threads[0].tot;
- int /*no_distr=0,*/ cfrom=0;
- int tot=0, totpart, *index=0, children=0, totseam=0;
- //int *vertpart=0;
+ int cfrom=0;
+ int totelem=0, totpart, *particle_element=0, children=0, totseam=0;
int jitlevel= 1, distr;
- float *weight=0,*sum=0,*jitoff=0;
- float cur, maxweight=0.0, tweight, totweight, co[3], nor[3], orco[3], ornor[3];
+ float *element_weight=NULL,*element_sum=NULL,*jitter_offset=NULL, *vweight=NULL;
+ float cur, maxweight=0.0, tweight, totweight, inv_totweight, co[3], nor[3], orco[3], ornor[3];
- if(ob==0 || psys==0 || psys->part==0)
+ if(ELEM3(NULL, ob, psys, psys->part))
return 0;
part=psys->part;
@@ -1007,81 +1050,63 @@ static int psys_threads_init_distribution(ParticleThread *threads, Scene *scene,
return 0;
}
- BLI_srandom(31415926 + psys->seed);
+ /* First handle special cases */
+ if(from == PART_FROM_CHILD) {
+ /* Simple children */
+ if(part->childtype != PART_CHILD_FACES) {
+ BLI_srandom(31415926 + psys->seed + psys->child_seed);
+ distribute_simple_children(scene, ob, finaldm, psys);
+ return 0;
+ }
+ }
+ else {
+ /* Grid distribution */
+ if(part->distr==PART_DISTR_GRID && from != PART_FROM_VERT){
+ BLI_srandom(31415926 + psys->seed);
+ dm= CDDM_from_mesh((Mesh*)ob->data, ob);
+ distribute_grid(dm,psys);
+ dm->release(dm);
+ return 0;
+ }
+ }
- if(from==PART_FROM_CHILD){
+ /* Create trees and original coordinates if needed */
+ if(from == PART_FROM_CHILD) {
distr=PART_DISTR_RAND;
BLI_srandom(31415926 + psys->seed + psys->child_seed);
+ dm= finaldm;
+ children=1;
- if(part->from!=PART_FROM_PARTICLE && part->childtype==PART_CHILD_FACES){
- dm= finaldm;
- children=1;
-
- tree=BLI_kdtree_new(totpart);
+ tree=BLI_kdtree_new(totpart);
- for(p=0,pa=psys->particles; p<totpart; p++,pa++){
- psys_particle_on_dm(dm,part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co,nor,0,0,orco,ornor);
- transform_mesh_orco_verts((Mesh*)ob->data, &orco, 1, 1);
- BLI_kdtree_insert(tree, p, orco, ornor);
- }
-
- BLI_kdtree_balance(tree);
-
- totpart=get_psys_tot_child(scene, psys);
- cfrom=from=PART_FROM_FACE;
+ for(p=0,pa=psys->particles; p<totpart; p++,pa++){
+ psys_particle_on_dm(dm,part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co,nor,0,0,orco,ornor);
+ transform_mesh_orco_verts((Mesh*)ob->data, &orco, 1, 1);
+ BLI_kdtree_insert(tree, p, orco, ornor);
}
- else{
- /* no need to figure out distribution */
- int child_nbr= get_psys_child_number(scene, psys);
-
- totpart= get_psys_tot_child(scene, psys);
- alloc_child_particles(psys, totpart);
- cpa=psys->child;
- for(i=0; i<child_nbr; i++){
- for(p=0; p<psys->totpart; p++,cpa++){
- float length=2.0;
- cpa->parent=p;
-
- /* create even spherical distribution inside unit sphere */
- while(length>=1.0f){
- cpa->fuv[0]=2.0f*BLI_frand()-1.0f;
- cpa->fuv[1]=2.0f*BLI_frand()-1.0f;
- cpa->fuv[2]=2.0f*BLI_frand()-1.0f;
- length=len_v3(cpa->fuv);
- }
- cpa->num=-1;
- }
- }
- /* dmcache must be updated for parent particles if children from faces is used */
- psys_calc_dmcache(ob, finaldm, psys);
+ BLI_kdtree_balance(tree);
- return 0;
- }
+ totpart = get_psys_tot_child(scene, psys);
+ cfrom = from = PART_FROM_FACE;
}
- else{
+ else {
+ distr = part->distr;
+ BLI_srandom(31415926 + psys->seed);
+
dm= CDDM_from_mesh((Mesh*)ob->data, ob);
- /* special handling of grid distribution */
- if(part->distr==PART_DISTR_GRID && from != PART_FROM_VERT){
- distribute_particles_in_grid(dm,psys);
- dm->release(dm);
- return 0;
- }
-
/* we need orco for consistent distributions */
DM_add_vert_layer(dm, CD_ORCO, CD_ASSIGN, get_mesh_orco_verts(ob));
- distr=part->distr;
-
- if(from==PART_FROM_VERT){
+ if(from == PART_FROM_VERT) {
MVert *mv= dm->getVertDataArray(dm, CD_MVERT);
float (*orcodata)[3]= dm->getVertDataArray(dm, CD_ORCO);
int totvert = dm->getNumVerts(dm);
tree=BLI_kdtree_new(totvert);
- for(p=0; p<totvert; p++){
+ for(p=0; p<totvert; p++) {
if(orcodata) {
VECCOPY(co,orcodata[p])
transform_mesh_orco_verts((Mesh*)ob->data, &co, 1, 1);
@@ -1095,73 +1120,33 @@ static int psys_threads_init_distribution(ParticleThread *threads, Scene *scene,
}
}
- /* 1. */
- switch(from){
- case PART_FROM_VERT:
- tot = dm->getNumVerts(dm);
- break;
- case PART_FROM_VOLUME:
- case PART_FROM_FACE:
- tot = dm->getNumTessFaces(dm);
- break;
- case PART_FROM_PARTICLE:
- if(psys->target_ob)
- tob=psys->target_ob;
- else
- tob=ob;
+ /* Get total number of emission elements and allocate needed arrays */
+ totelem = (from == PART_FROM_VERT) ? dm->getNumVerts(dm) : dm->getNumTessFaces(dm);
- if((tpsys=BLI_findlink(&tob->particlesystem,psys->target_psys-1))){
- tpars=tpsys->particles;
- tot=tpsys->totpart;
- }
- break;
- }
+ if(totelem == 0){
+ distribute_invalid(scene, psys, children ? PART_FROM_CHILD : 0);
- if(tot==0){
- /*no_distr=1;*/ /*UNUSED*/
- if(children){
- if(G.f & G_DEBUG)
- fprintf(stderr,"Particle child distribution error: Nothing to emit from!\n");
- if(psys->child) {
- for(p=0,cpa=psys->child; p<totpart; p++,cpa++){
- cpa->fuv[0]=cpa->fuv[1]=cpa->fuv[2]=cpa->fuv[3]= 0.0;
- cpa->foffset= 0.0f;
- cpa->parent=0;
- cpa->pa[0]=cpa->pa[1]=cpa->pa[2]=cpa->pa[3]=0;
- cpa->num= -1;
- }
- }
- }
- else {
- if(G.f & G_DEBUG)
- fprintf(stderr,"Particle distribution error: Nothing to emit from!\n");
- for(p=0,pa=psys->particles; p<totpart; p++,pa++){
- pa->fuv[0]=pa->fuv[1]=pa->fuv[2]= pa->fuv[3]= 0.0;
- pa->foffset= 0.0f;
- pa->num= -1;
- }
- }
+ if(G.f & G_DEBUG)
+ fprintf(stderr,"Particle distribution error: Nothing to emit from!\n");
if(dm != finaldm) dm->release(dm);
return 0;
}
- /* 2. */
-
- weight=MEM_callocN(sizeof(float)*tot, "particle_distribution_weights");
- index=MEM_callocN(sizeof(int)*totpart, "particle_distribution_indexes");
- sum=MEM_callocN(sizeof(float)*(tot+1), "particle_distribution_sum");
- jitoff=MEM_callocN(sizeof(float)*tot, "particle_distribution_jitoff");
+ element_weight = MEM_callocN(sizeof(float)*totelem, "particle_distribution_weights");
+ particle_element= MEM_callocN(sizeof(int)*totpart, "particle_distribution_indexes");
+ element_sum = MEM_callocN(sizeof(float)*(totelem+1), "particle_distribution_sum");
+ jitter_offset = MEM_callocN(sizeof(float)*totelem, "particle_distribution_jitoff");
- /* 2.1 */
- if((part->flag&PART_EDISTR || children) && ELEM(from,PART_FROM_PARTICLE,PART_FROM_VERT)==0){
+ /* Calculate weights from face areas */
+ if((part->flag&PART_EDISTR || children) && from != PART_FROM_VERT){
MVert *v1, *v2, *v3, *v4;
- float totarea=0.0, co1[3], co2[3], co3[3], co4[3];
+ float totarea=0.f, co1[3], co2[3], co3[3], co4[3];
float (*orcodata)[3];
orcodata= dm->getVertDataArray(dm, CD_ORCO);
- for(i=0; i<tot; i++){
+ for(i=0; i<totelem; i++){
MFace *mf=dm->getTessFaceData(dm,i,CD_MFACE);
if(orcodata) {
@@ -1171,6 +1156,10 @@ static int psys_threads_init_distribution(ParticleThread *threads, Scene *scene,
transform_mesh_orco_verts((Mesh*)ob->data, &co1, 1, 1);
transform_mesh_orco_verts((Mesh*)ob->data, &co2, 1, 1);
transform_mesh_orco_verts((Mesh*)ob->data, &co3, 1, 1);
+ if(mf->v4) {
+ VECCOPY(co4, orcodata[mf->v4]);
+ transform_mesh_orco_verts((Mesh*)ob->data, &co4, 1, 1);
+ }
}
else {
v1= (MVert*)dm->getVertData(dm,mf->v1,CD_MVERT);
@@ -1179,156 +1168,133 @@ static int psys_threads_init_distribution(ParticleThread *threads, Scene *scene,
VECCOPY(co1, v1->co);
VECCOPY(co2, v2->co);
VECCOPY(co3, v3->co);
- }
-
- if (mf->v4){
- if(orcodata) {
- VECCOPY(co4, orcodata[mf->v4]);
- transform_mesh_orco_verts((Mesh*)ob->data, &co4, 1, 1);
- }
- else {
+ if(mf->v4) {
v4= (MVert*)dm->getVertData(dm,mf->v4,CD_MVERT);
VECCOPY(co4, v4->co);
}
- cur= area_quad_v3(co1, co2, co3, co4);
}
- else
- cur= area_tri_v3(co1, co2, co3);
+
+ cur = mf->v4 ? area_quad_v3(co1, co2, co3, co4) : area_tri_v3(co1, co2, co3);
- if(cur>maxweight)
- maxweight=cur;
+ if(cur > maxweight)
+ maxweight = cur;
- weight[i]= cur;
- totarea+=cur;
+ element_weight[i] = cur;
+ totarea += cur;
}
- for(i=0; i<tot; i++)
- weight[i] /= totarea;
+ for(i=0; i<totelem; i++)
+ element_weight[i] /= totarea;
maxweight /= totarea;
}
- else if(from==PART_FROM_PARTICLE){
- float val=(float)tot/(float)totpart;
- for(i=0; i<tot; i++)
- weight[i]=val;
- maxweight=val;
- }
else{
- float min=1.0f/(float)(MIN2(tot,totpart));
- for(i=0; i<tot; i++)
- weight[i]=min;
+ float min=1.0f/(float)(MIN2(totelem,totpart));
+ for(i=0; i<totelem; i++)
+ element_weight[i]=min;
maxweight=min;
}
- /* 2.2 */
- if(ELEM3(from,PART_FROM_VERT,PART_FROM_FACE,PART_FROM_VOLUME)){
- float *vweight= psys_cache_vgroup(dm,psys,PSYS_VG_DENSITY);
+ /* Calculate weights from vgroup */
+ vweight = psys_cache_vgroup(dm,psys,PSYS_VG_DENSITY);
- if(vweight){
- if(from==PART_FROM_VERT) {
- for(i=0;i<tot; i++)
- weight[i]*=vweight[i];
- }
- else { /* PART_FROM_FACE / PART_FROM_VOLUME */
- for(i=0;i<tot; i++){
- MFace *mf=dm->getTessFaceData(dm,i,CD_MFACE);
- tweight = vweight[mf->v1] + vweight[mf->v2] + vweight[mf->v3];
+ if(vweight){
+ if(from==PART_FROM_VERT) {
+ for(i=0;i<totelem; i++)
+ element_weight[i]*=vweight[i];
+ }
+ else { /* PART_FROM_FACE / PART_FROM_VOLUME */
+ for(i=0;i<totelem; i++){
+ MFace *mf=dm->getTessFaceData(dm,i,CD_MFACE);
+ tweight = vweight[mf->v1] + vweight[mf->v2] + vweight[mf->v3];
- if(mf->v4) {
- tweight += vweight[mf->v4];
- tweight /= 4.0;
- }
- else {
- tweight /= 3.0;
- }
-
- weight[i]*=tweight;
+ if(mf->v4) {
+ tweight += vweight[mf->v4];
+ tweight /= 4.0f;
+ }
+ else {
+ tweight /= 3.0f;
}
+
+ element_weight[i]*=tweight;
}
- MEM_freeN(vweight);
}
+ MEM_freeN(vweight);
}
- /* 3. */
+ /* Calculate total weight of all elements */
totweight= 0.0f;
- for(i=0;i<tot; i++)
- totweight += weight[i];
+ for(i=0;i<totelem; i++)
+ totweight += element_weight[i];
- if(totweight > 0.0f)
- totweight= 1.0f/totweight;
+ inv_totweight = (totweight > 0.f ? 1.f/totweight : 0.f);
- sum[0]= 0.0f;
- for(i=0;i<tot; i++)
- sum[i+1]= sum[i]+weight[i]*totweight;
+ /* Calculate cumulative weights */
+ element_sum[0]= 0.0f;
+ for(i=0; i<totelem; i++)
+ element_sum[i+1]= element_sum[i] + element_weight[i] * inv_totweight;
+ /* Finally assign elements to particles */
if((part->flag&PART_TRAND) || (part->simplify_flag&PART_SIMPLIFY_ENABLE)) {
float pos;
for(p=0; p<totpart; p++) {
- /* In theory sys[tot] should be 1.0, but due to float errors this is not necessarily always true, so scale pos accordingly. */
- pos= BLI_frand() * sum[tot];
- index[p]= binary_search_distribution(sum, tot, pos);
- index[p]= MIN2(tot-1, index[p]);
- jitoff[index[p]]= pos;
+ /* In theory element_sum[totelem] should be 1.0, but due to float errors this is not necessarily always true, so scale pos accordingly. */
+ pos= BLI_frand() * element_sum[totelem];
+ particle_element[p]= distribute_binary_search(element_sum, totelem, pos);
+ particle_element[p]= MIN2(totelem-1, particle_element[p]);
+ jitter_offset[particle_element[p]]= pos;
}
}
else {
double step, pos;
- step= (totpart <= 1)? 0.5: 1.0/(totpart-1);
- pos= 1e-16f; /* tiny offset to avoid zero weight face */
+ step= (totpart < 2) ? 0.5 : 1.0/(double)totpart;
+ pos= 1e-16; /* tiny offset to avoid zero weight face */
i= 0;
for(p=0; p<totpart; p++, pos+=step) {
- while((i < tot) && (pos > sum[i+1]))
+ while((i < totelem) && (pos > element_sum[i+1]))
i++;
- index[p]= MIN2(tot-1, i);
+ particle_element[p]= MIN2(totelem-1, i);
/* avoid zero weight face */
- if(p == totpart-1 && weight[index[p]] == 0.0f)
- index[p]= index[p-1];
+ if(p == totpart-1 && element_weight[particle_element[p]] == 0.0f)
+ particle_element[p]= particle_element[p-1];
- jitoff[index[p]]= pos;
+ jitter_offset[particle_element[p]]= pos;
}
}
- MEM_freeN(sum);
-
- /* for hair, sort by origindex, allows optimizations in rendering */
- /* however with virtual parents the children need to be in random order */
- if(part->type == PART_HAIR && !(part->childtype==PART_CHILD_FACES && part->parents!=0.0)) {
- if(from != PART_FROM_PARTICLE) {
- COMPARE_ORIG_INDEX = NULL;
+ MEM_freeN(element_sum);
- if(from == PART_FROM_VERT) {
- if(dm->numVertData)
- COMPARE_ORIG_INDEX= dm->getVertDataArray(dm, CD_ORIGINDEX);
- }
- else {
- if(dm->numFaceData)
- COMPARE_ORIG_INDEX= dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
- }
+ /* For hair, sort by origindex (allows optimizations in rendering), */
+ /* however with virtual parents the children need to be in random order. */
+ if(part->type == PART_HAIR && !(part->childtype==PART_CHILD_FACES && part->parents!=0.0f)) {
+ COMPARE_ORIG_INDEX = NULL;
- if(COMPARE_ORIG_INDEX) {
- qsort(index, totpart, sizeof(int), compare_orig_index);
- COMPARE_ORIG_INDEX = NULL;
- }
+ if(from == PART_FROM_VERT) {
+ if(dm->numVertData)
+ COMPARE_ORIG_INDEX= dm->getVertDataArray(dm, CD_ORIGINDEX);
+ }
+ else {
+ if(dm->numFaceData)
+ COMPARE_ORIG_INDEX= dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
}
- }
- /* weights are no longer used except for FROM_PARTICLE, which needs them zeroed for indexing */
- if(from==PART_FROM_PARTICLE){
- for(i=0; i<tot; i++)
- weight[i]=0.0f;
+ if(COMPARE_ORIG_INDEX) {
+ qsort(particle_element, totpart, sizeof(int), distribute_compare_orig_index);
+ COMPARE_ORIG_INDEX = NULL;
+ }
}
- /* 4. */
+ /* Create jittering if needed */
if(distr==PART_DISTR_JIT && ELEM(from,PART_FROM_FACE,PART_FROM_VOLUME)) {
jitlevel= part->userjit;
if(jitlevel == 0) {
- jitlevel= totpart/tot;
+ jitlevel= totpart/totelem;
if(part->flag & PART_EDISTR) jitlevel*= 2; /* looks better in general, not very scietific */
if(jitlevel<3) jitlevel= 3;
}
@@ -1345,16 +1311,16 @@ static int psys_threads_init_distribution(ParticleThread *threads, Scene *scene,
BLI_array_randomize(jit, 2*sizeof(float), jitlevel, psys->seed); /* for custom jit or even distribution */
}
- /* 5. */
+ /* Setup things for threaded distribution */
ctx->tree= tree;
ctx->seams= seams;
ctx->totseam= totseam;
ctx->sim.psys= psys;
- ctx->index= index;
+ ctx->index= particle_element;
ctx->jit= jit;
ctx->jitlevel= jitlevel;
- ctx->jitoff= jitoff;
- ctx->weight= weight;
+ ctx->jitoff= jitter_offset;
+ ctx->weight= element_weight;
ctx->maxweight= maxweight;
ctx->from= (children)? PART_FROM_CHILD: from;
ctx->cfrom= cfrom;
@@ -1389,14 +1355,14 @@ static void distribute_particles_on_dm(ParticleSimulationData *sim, int from)
pthreads= psys_threads_create(sim);
- if(!psys_threads_init_distribution(pthreads, sim->scene, finaldm, from)) {
+ if(!distribute_threads_init_data(pthreads, sim->scene, finaldm, from)) {
psys_threads_free(pthreads);
return;
}
totthread= pthreads[0].tot;
if(totthread > 1) {
- BLI_init_threads(&threads, exec_distribution, totthread);
+ BLI_init_threads(&threads, distribute_threads_exec_cb, totthread);
for(i=0; i<totthread; i++)
BLI_insert_thread(&threads, &pthreads[i]);
@@ -1404,7 +1370,7 @@ static void distribute_particles_on_dm(ParticleSimulationData *sim, int from)
BLI_end_threads(&threads);
}
else
- exec_distribution(&pthreads[0]);
+ distribute_threads_exec_cb(&pthreads[0]);
psys_calc_dmcache(sim->ob, finaldm, sim->psys);
@@ -1418,17 +1384,11 @@ static void distribute_particles_on_dm(ParticleSimulationData *sim, int from)
/* ready for future use, to emit particles without geometry */
static void distribute_particles_on_shape(ParticleSimulationData *sim, int UNUSED(from))
{
- ParticleSystem *psys = sim->psys;
- PARTICLE_P;
+ distribute_invalid(sim->scene, sim->psys, 0);
fprintf(stderr,"Shape emission not yet possible!\n");
-
- LOOP_PARTICLES {
- pa->fuv[0]=pa->fuv[1]=pa->fuv[2]=pa->fuv[3]= 0.0;
- pa->foffset= 0.0f;
- pa->num= -1;
- }
}
+
static void distribute_particles(ParticleSimulationData *sim, int from)
{
PARTICLE_PSMD;
@@ -1444,16 +1404,9 @@ static void distribute_particles(ParticleSimulationData *sim, int from)
distribute_particles_on_shape(sim, from);
if(distr_error){
- ParticleSystem *psys = sim->psys;
- PARTICLE_P;
+ distribute_invalid(sim->scene, sim->psys, from);
fprintf(stderr,"Particle distribution error!\n");
-
- LOOP_PARTICLES {
- pa->fuv[0]=pa->fuv[1]=pa->fuv[2]=pa->fuv[3]= 0.0;
- pa->foffset= 0.0f;
- pa->num= -1;
- }
}
}
@@ -1542,7 +1495,7 @@ void initialize_particle(ParticleSimulationData *sim, ParticleData *pa, int p)
pa->flag &= ~PARS_UNEXIST;
- if(part->from != PART_FROM_PARTICLE && part->type != PART_FLUID) {
+ if(part->type != PART_FLUID) {
psys_get_texture(sim, pa, &ptex, PAMAP_INIT, 0.f);
if(ptex.exist < PSYS_FRAND(p+125))
@@ -1623,39 +1576,15 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime,
int p = pa - psys->particles;
part=psys->part;
-#if 0 /* deprecated code */
- if(part->from==PART_FROM_PARTICLE){
- float speed;
- ParticleSimulationData tsim= {0};
- tsim.scene= sim->scene;
- tsim.ob= psys->target_ob ? psys->target_ob : ob;
- tsim.psys = BLI_findlink(&tsim.ob->particlesystem, sim->psys->target_psys-1);
-
- state.time = pa->time;
- if(pa->num == -1)
- memset(&state, 0, sizeof(state));
- else
- psys_get_particle_state(&tsim, pa->num, &state, 1);
- psys_get_from_key(&state, loc, nor, rot, 0);
-
- mul_qt_v3(rot, vtan);
- mul_qt_v3(rot, utan);
-
- speed= normalize_v3_v3(p_vel, state.vel);
- mul_v3_fl(p_vel, dot_v3v3(r_vel, p_vel));
- VECSUB(p_vel, r_vel, p_vel);
- normalize_v3(p_vel);
- mul_v3_fl(p_vel, speed);
-
- VECCOPY(pa->fuv, loc); /* abusing pa->fuv (not used for "from particle") for storing emit location */
- }
- else{
-#endif
/* get precise emitter matrix if particle is born */
- if(part->type!=PART_HAIR && pa->time < cfra && pa->time >= sim->psys->cfra) {
+ if(part->type!=PART_HAIR && dtime > 0.f && pa->time < cfra && pa->time >= sim->psys->cfra) {
/* we have to force RECALC_ANIM here since where_is_objec_time only does drivers */
- BKE_animsys_evaluate_animdata(&sim->ob->id, sim->ob->adt, pa->time, ADT_RECALC_ANIM);
- where_is_object_time(sim->scene, sim->ob, pa->time);
+ while(ob) {
+ BKE_animsys_evaluate_animdata(&ob->id, ob->adt, pa->time, ADT_RECALC_ANIM);
+ ob = ob->parent;
+ }
+ ob = sim->ob;
+ where_is_object_time(sim->scene, ob, pa->time);
}
/* get birth location from object */
@@ -1677,11 +1606,11 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime,
normalize_v3(nor);
/* -tangent */
- if(part->tanfac!=0.0){
+ if(part->tanfac!=0.0f){
//float phase=vg_rot?2.0f*(psys_particle_value_from_verts(sim->psmd->dm,part->from,pa,vg_rot)-0.5f):0.0f;
float phase=0.0f;
- mul_v3_fl(vtan,-(float)cos(M_PI*(part->tanphase+phase)));
- fac=-(float)sin(M_PI*(part->tanphase+phase));
+ mul_v3_fl(vtan,-(float)cos((float)M_PI*(part->tanphase+phase)));
+ fac=-(float)sin((float)M_PI*(part->tanphase+phase));
VECADDFAC(vtan,vtan,utan,fac);
mul_mat3_m4_v3(ob->obmat,vtan);
@@ -1695,7 +1624,7 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime,
/* -velocity */
- if(part->randfac!=0.0){
+ if(part->randfac != 0.0f){
r_vel[0] = 2.0f * (PSYS_FRAND(p + 10) - 0.5f);
r_vel[1] = 2.0f * (PSYS_FRAND(p + 11) - 0.5f);
r_vel[2] = 2.0f * (PSYS_FRAND(p + 12) - 0.5f);
@@ -1739,7 +1668,7 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime,
zero_v3(pa->state.vel);
/* boids store direction in ave */
- if(fabs(nor[2])==1.0f) {
+ if(fabsf(nor[2])==1.0f) {
sub_v3_v3v3(pa->state.ave, loc, ob->obmat[3]);
normalize_v3(pa->state.ave);
}
@@ -1891,7 +1820,7 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime,
else{
pa->lifetime = part->lifetime * ptex.life;
- if(part->randlife != 0.0)
+ if(part->randlife != 0.0f)
pa->lifetime *= 1.0f - part->randlife * PSYS_FRAND(p + 21);
}
@@ -2031,112 +1960,7 @@ static void set_keyed_keys(ParticleSimulationData *sim)
psys->flag |= PSYS_KEYED;
}
-/************************************************/
-/* Reactors */
-/************************************************/
-//static void push_reaction(ParticleSimulationData *sim, int pa_num, int event, ParticleKey *state)
-//{
-// Object *rob;
-// ParticleSystem *rpsys;
-// ParticleSettings *rpart;
-// ParticleData *pa;
-// ListBase *lb=&sim->psys->effectors;
-// ParticleEffectorCache *ec;
-// ParticleReactEvent *re;
-//
-// if(lb->first) for(ec = lb->first; ec; ec= ec->next){
-// if(ec->type & PSYS_EC_REACTOR){
-// /* all validity checks already done in add_to_effectors */
-// rob=ec->ob;
-// rpsys=BLI_findlink(&rob->particlesystem,ec->psys_nbr);
-// rpart=rpsys->part;
-// if(rpsys->part->reactevent==event){
-// pa=sim->psys->particles+pa_num;
-// re= MEM_callocN(sizeof(ParticleReactEvent), "react event");
-// re->event=event;
-// re->pa_num = pa_num;
-// re->ob = sim->ob;
-// re->psys = sim->psys;
-// re->size = pa->size;
-// copy_particle_key(&re->state,state,1);
-//
-// switch(event){
-// case PART_EVENT_DEATH:
-// re->time=pa->dietime;
-// break;
-// case PART_EVENT_COLLIDE:
-// re->time=state->time;
-// break;
-// case PART_EVENT_NEAR:
-// re->time=state->time;
-// break;
-// }
-//
-// BLI_addtail(&rpsys->reactevents, re);
-// }
-// }
-// }
-//}
-//static void react_to_events(ParticleSystem *psys, int pa_num)
-//{
-// ParticleSettings *part=psys->part;
-// ParticleData *pa=psys->particles+pa_num;
-// ParticleReactEvent *re=psys->reactevents.first;
-// int birth=0;
-// float dist=0.0f;
-//
-// for(re=psys->reactevents.first; re; re=re->next){
-// birth=0;
-// if(part->from==PART_FROM_PARTICLE){
-// if(pa->num==re->pa_num && pa->alive==PARS_UNBORN){
-// if(re->event==PART_EVENT_NEAR){
-// ParticleData *tpa = re->psys->particles+re->pa_num;
-// float pa_time=tpa->time + pa->foffset*tpa->lifetime;
-// if(re->time >= pa_time){
-// pa->time=pa_time;
-// pa->dietime=pa->time+pa->lifetime;
-// }
-// }
-// else{
-// pa->time=re->time;
-// pa->dietime=pa->time+pa->lifetime;
-// }
-// }
-// }
-// else{
-// dist=len_v3v3(pa->state.co, re->state.co);
-// if(dist <= re->size){
-// if(pa->alive==PARS_UNBORN){
-// pa->time=re->time;
-// pa->dietime=pa->time+pa->lifetime;
-// birth=1;
-// }
-// if(birth || part->flag&PART_REACT_MULTIPLE){
-// float vec[3];
-// VECSUB(vec,pa->state.co, re->state.co);
-// if(birth==0)
-// mul_v3_fl(vec,(float)pow(1.0f-dist/re->size,part->reactshape));
-// VECADDFAC(pa->state.vel,pa->state.vel,vec,part->reactfac);
-// VECADDFAC(pa->state.vel,pa->state.vel,re->state.vel,part->partfac);
-// }
-// if(birth)
-// mul_v3_fl(pa->state.vel,(float)pow(1.0f-dist/re->size,part->reactshape));
-// }
-// }
-// }
-//}
-//void psys_get_reactor_target(ParticleSimulationData *sim, Object **target_ob, ParticleSystem **target_psys)
-//{
-// Object *tob;
-//
-// tob = sim->psys->target_ob ? sim->psys->target_ob : sim->ob;
-//
-// *target_psys = BLI_findlink(&tob->particlesystem, sim->psys->target_psys-1);
-// if(*target_psys)
-// *target_ob=tob;
-// else
-// *target_ob=0;
-//}
+
/************************************************/
/* Point Cache */
/************************************************/
@@ -2162,23 +1986,54 @@ void psys_get_pointcache_start_end(Scene *scene, ParticleSystem *psys, int *sfra
ParticleSettings *part = psys->part;
*sfra = MAX2(1, (int)part->sta);
- *efra = MIN2((int)(part->end + part->lifetime + 1.0), scene->r.efra);
+ *efra = MIN2((int)(part->end + part->lifetime + 1.0f), scene->r.efra);
}
/************************************************/
/* Effectors */
/************************************************/
+static void psys_update_particle_bvhtree(ParticleSystem *psys, float cfra)
+{
+ if(psys) {
+ PARTICLE_P;
+ int totpart = 0;
+
+ if(!psys->bvhtree || psys->bvhtree_frame != cfra) {
+ LOOP_SHOWN_PARTICLES {
+ totpart++;
+ }
+
+ BLI_bvhtree_free(psys->bvhtree);
+ psys->bvhtree = BLI_bvhtree_new(totpart, 0.0, 4, 6);
+
+ LOOP_SHOWN_PARTICLES {
+ if(pa->alive == PARS_ALIVE) {
+ if(pa->state.time == cfra)
+ BLI_bvhtree_insert(psys->bvhtree, p, pa->prev_state.co, 1);
+ else
+ BLI_bvhtree_insert(psys->bvhtree, p, pa->state.co, 1);
+ }
+ }
+ BLI_bvhtree_balance(psys->bvhtree);
+
+ psys->bvhtree_frame = cfra;
+ }
+ }
+}
void psys_update_particle_tree(ParticleSystem *psys, float cfra)
{
if(psys) {
PARTICLE_P;
+ int totpart = 0;
if(!psys->tree || psys->tree_frame != cfra) {
-
- BLI_kdtree_free(psys->tree);
+ LOOP_SHOWN_PARTICLES {
+ totpart++;
+ }
+ BLI_kdtree_free(psys->tree);
psys->tree = BLI_kdtree_new(psys->totpart);
-
+
LOOP_SHOWN_PARTICLES {
if(pa->alive == PARS_ALIVE) {
if(pa->state.time == cfra)
@@ -2189,7 +2044,7 @@ void psys_update_particle_tree(ParticleSystem *psys, float cfra)
}
BLI_kdtree_balance(psys->tree);
- psys->tree_frame = psys->cfra;
+ psys->tree_frame = cfra;
}
}
}
@@ -2201,6 +2056,133 @@ static void psys_update_effectors(ParticleSimulationData *sim)
precalc_guides(sim, sim->psys->effectors);
}
+static void integrate_particle(ParticleSettings *part, ParticleData *pa, float dtime, float *external_acceleration, void (*force_func)(void *forcedata, ParticleKey *state, float *force, float *impulse), void *forcedata)
+{
+ ParticleKey states[5];
+ float force[3],acceleration[3],impulse[3],dx[4][3],dv[4][3],oldpos[3];
+ float pa_mass= (part->flag & PART_SIZEMASS ? part->mass * pa->size : part->mass);
+ int i, steps=1;
+ int integrator = part->integrator;
+
+ copy_v3_v3(oldpos, pa->state.co);
+
+ /* Verlet integration behaves strangely with moving emitters, so do first step with euler. */
+ if(pa->prev_state.time < 0.f && integrator == PART_INT_VERLET)
+ integrator = PART_INT_EULER;
+
+ switch(integrator){
+ case PART_INT_EULER:
+ steps=1;
+ break;
+ case PART_INT_MIDPOINT:
+ steps=2;
+ break;
+ case PART_INT_RK4:
+ steps=4;
+ break;
+ case PART_INT_VERLET:
+ steps=1;
+ break;
+ }
+
+ copy_particle_key(states, &pa->state, 1);
+
+ states->time = 0.f;
+
+ for(i=0; i<steps; i++){
+ zero_v3(force);
+ zero_v3(impulse);
+
+ force_func(forcedata, states+i, force, impulse);
+
+ /* force to acceleration*/
+ mul_v3_v3fl(acceleration, force, 1.0f/pa_mass);
+
+ if(external_acceleration)
+ add_v3_v3(acceleration, external_acceleration);
+
+ /* calculate next state */
+ add_v3_v3(states[i].vel, impulse);
+
+ switch(integrator){
+ case PART_INT_EULER:
+ madd_v3_v3v3fl(pa->state.co, states->co, states->vel, dtime);
+ madd_v3_v3v3fl(pa->state.vel, states->vel, acceleration, dtime);
+ break;
+ case PART_INT_MIDPOINT:
+ if(i==0){
+ madd_v3_v3v3fl(states[1].co, states->co, states->vel, dtime*0.5f);
+ madd_v3_v3v3fl(states[1].vel, states->vel, acceleration, dtime*0.5f);
+ states[1].time = dtime*0.5f;
+ /*fra=sim->psys->cfra+0.5f*dfra;*/
+ }
+ else{
+ madd_v3_v3v3fl(pa->state.co, states->co, states[1].vel, dtime);
+ madd_v3_v3v3fl(pa->state.vel, states->vel, acceleration, dtime);
+ }
+ break;
+ case PART_INT_RK4:
+ switch(i){
+ case 0:
+ copy_v3_v3(dx[0], states->vel);
+ mul_v3_fl(dx[0], dtime);
+ copy_v3_v3(dv[0], acceleration);
+ mul_v3_fl(dv[0], dtime);
+
+ madd_v3_v3v3fl(states[1].co, states->co, dx[0], 0.5f);
+ madd_v3_v3v3fl(states[1].vel, states->vel, dv[0], 0.5f);
+ states[1].time = dtime*0.5f;
+ /*fra=sim->psys->cfra+0.5f*dfra;*/
+ break;
+ case 1:
+ madd_v3_v3v3fl(dx[1], states->vel, dv[0], 0.5f);
+ mul_v3_fl(dx[1], dtime);
+ copy_v3_v3(dv[1], acceleration);
+ mul_v3_fl(dv[1], dtime);
+
+ madd_v3_v3v3fl(states[2].co, states->co, dx[1], 0.5f);
+ madd_v3_v3v3fl(states[2].vel, states->vel, dv[1], 0.5f);
+ states[2].time = dtime*0.5f;
+ break;
+ case 2:
+ madd_v3_v3v3fl(dx[2], states->vel, dv[1], 0.5f);
+ mul_v3_fl(dx[2], dtime);
+ copy_v3_v3(dv[2], acceleration);
+ mul_v3_fl(dv[2], dtime);
+
+ add_v3_v3v3(states[3].co, states->co, dx[2]);
+ add_v3_v3v3(states[3].vel, states->vel, dv[2]);
+ states[3].time = dtime;
+ /*fra=cfra;*/
+ break;
+ case 3:
+ add_v3_v3v3(dx[3], states->vel, dv[2]);
+ mul_v3_fl(dx[3], dtime);
+ copy_v3_v3(dv[3], acceleration);
+ mul_v3_fl(dv[3], dtime);
+
+ madd_v3_v3v3fl(pa->state.co, states->co, dx[0], 1.0f/6.0f);
+ madd_v3_v3fl(pa->state.co, dx[1], 1.0f/3.0f);
+ madd_v3_v3fl(pa->state.co, dx[2], 1.0f/3.0f);
+ madd_v3_v3fl(pa->state.co, dx[3], 1.0f/6.0f);
+
+ madd_v3_v3v3fl(pa->state.vel, states->vel, dv[0], 1.0f/6.0f);
+ madd_v3_v3fl(pa->state.vel, dv[1], 1.0f/3.0f);
+ madd_v3_v3fl(pa->state.vel, dv[2], 1.0f/3.0f);
+ madd_v3_v3fl(pa->state.vel, dv[3], 1.0f/6.0f);
+ }
+ break;
+ case PART_INT_VERLET: /* Verlet integration */
+ madd_v3_v3v3fl(pa->state.vel, pa->prev_state.vel, acceleration, dtime);
+ madd_v3_v3v3fl(pa->state.co, pa->prev_state.co, pa->state.vel, dtime);
+
+ sub_v3_v3v3(pa->state.vel, pa->state.co, oldpos);
+ mul_v3_fl(pa->state.vel, 1.0f/dtime);
+ break;
+ }
+ }
+}
+
/*********************************************************************************************************
SPH fluid physics
@@ -2216,7 +2198,7 @@ static void psys_update_effectors(ParticleSimulationData *sim)
***********************************************************************************************************/
#define PSYS_FLUID_SPRINGS_INITIAL_SIZE 256
-static ParticleSpring *add_fluid_spring(ParticleSystem *psys, ParticleSpring *spring)
+static ParticleSpring *sph_spring_add(ParticleSystem *psys, ParticleSpring *spring)
{
/* Are more refs required? */
if(psys->alloc_fluidsprings == 0 || psys->fluid_springs == NULL) {
@@ -2234,8 +2216,7 @@ static ParticleSpring *add_fluid_spring(ParticleSystem *psys, ParticleSpring *sp
return psys->fluid_springs + psys->tot_fluidsprings - 1;
}
-
-static void delete_fluid_spring(ParticleSystem *psys, int j)
+static void sph_spring_delete(ParticleSystem *psys, int j)
{
if (j != psys->tot_fluidsprings - 1)
psys->fluid_springs[j] = psys->fluid_springs[psys->tot_fluidsprings - 1];
@@ -2247,8 +2228,52 @@ static void delete_fluid_spring(ParticleSystem *psys, int j)
psys->fluid_springs = (ParticleSpring*)MEM_reallocN(psys->fluid_springs, psys->alloc_fluidsprings * sizeof(ParticleSpring));
}
}
+static void sph_springs_modify(ParticleSystem *psys, float dtime){
+ SPHFluidSettings *fluid = psys->part->fluid;
+ ParticleData *pa1, *pa2;
+ ParticleSpring *spring = psys->fluid_springs;
+
+ float h, d, Rij[3], rij, Lij;
+ int i;
+
+ float yield_ratio = fluid->yield_ratio;
+ float plasticity = fluid->plasticity_constant;
+ /* scale things according to dtime */
+ float timefix = 25.f * dtime;
+
+ if((fluid->flag & SPH_VISCOELASTIC_SPRINGS)==0 || fluid->spring_k == 0.f)
+ return;
-static EdgeHash *build_fluid_springhash(ParticleSystem *psys)
+ /* Loop through the springs */
+ for(i=0; i<psys->tot_fluidsprings; i++, spring++) {
+ pa1 = psys->particles + spring->particle_index[0];
+ pa2 = psys->particles + spring->particle_index[1];
+
+ sub_v3_v3v3(Rij, pa2->prev_state.co, pa1->prev_state.co);
+ rij = normalize_v3(Rij);
+
+ /* adjust rest length */
+ Lij = spring->rest_length;
+ d = yield_ratio * timefix * Lij;
+
+ if (rij > Lij + d) // Stretch
+ spring->rest_length += plasticity * (rij - Lij - d) * timefix;
+ else if(rij < Lij - d) // Compress
+ spring->rest_length -= plasticity * (Lij - d - rij) * timefix;
+
+ h = 4.f*pa1->size;
+
+ if(spring->rest_length > h)
+ spring->delete_flag = 1;
+ }
+
+ /* Loop through springs backwaqrds - for efficient delete function */
+ for (i=psys->tot_fluidsprings-1; i >= 0; i--) {
+ if(psys->fluid_springs[i].delete_flag)
+ sph_spring_delete(psys, i);
+ }
+}
+static EdgeHash *sph_springhash_build(ParticleSystem *psys)
{
EdgeHash *springhash = NULL;
ParticleSpring *spring;
@@ -2261,351 +2286,279 @@ static EdgeHash *build_fluid_springhash(ParticleSystem *psys)
return springhash;
}
-static void particle_fluidsim(ParticleSystem *psys, int own_psys, ParticleData *pa, float dtime, float mass, float *gravity, EdgeHash *springhash)
+
+typedef struct SPHNeighbor
{
- SPHFluidSettings *fluid = psys->part->fluid;
- KDTreeNearest *ptn = NULL;
- ParticleData *npa;
- ParticleSpring *spring = NULL;
+ ParticleSystem *psys;
+ int index;
+} SPHNeighbor;
+typedef struct SPHRangeData
+{
+ SPHNeighbor neighbors[128];
+ int tot_neighbors;
- float temp[3];
- float q, q1, u, I, D, rij, d, Lij;
- float pressure_near, pressure;
- float p=0, pnear=0;
-
- float omega = fluid->viscosity_omega;
- float beta = fluid->viscosity_beta;
- float massfactor = 1.0f/mass;
- float spring_k = fluid->spring_k;
- float h = fluid->radius;
- float L = fluid->rest_length * fluid->radius;
-
- int n, neighbours = BLI_kdtree_range_search(psys->tree, h, pa->prev_state.co, NULL, &ptn);
- int spring_index = 0, index = own_psys ? pa - psys->particles : -1;
-
- /* pressure and near pressure */
- for(n=own_psys?1:0; n<neighbours; n++) {
- /* disregard particles at the exact same location */
- if(ptn[n].dist < FLT_EPSILON)
- continue;
+ float density, near_density;
+ float h;
- sub_v3_v3(ptn[n].co, pa->prev_state.co);
- mul_v3_fl(ptn[n].co, 1.f/ptn[n].dist);
- q = ptn[n].dist/h;
+ ParticleSystem *npsys;
+ ParticleData *pa;
- if(q < 1.f) {
- q1 = 1.f - q;
+ float massfac;
+ int use_size;
+} SPHRangeData;
+typedef struct SPHData {
+ ParticleSystem *psys[10];
+ ParticleData *pa;
+ float mass;
+ EdgeHash *eh;
+ float *gravity;
+}SPHData;
+static void sph_density_accum_cb(void *userdata, int index, float squared_dist)
+{
+ SPHRangeData *pfr = (SPHRangeData *)userdata;
+ ParticleData *npa = pfr->npsys->particles + index;
+ float q;
- p += q1*q1;
- pnear += q1*q1*q1;
- }
- }
+ if(npa == pfr->pa || squared_dist < FLT_EPSILON)
+ return;
- p *= mass;
- pnear *= mass;
- pressure = fluid->stiffness_k * (p - fluid->rest_density);
- pressure_near = fluid->stiffness_knear * pnear;
+ /* Ugh! One particle has over 128 neighbors! Really shouldn't happen,
+ * but even if it does it shouldn't do any terrible harm if all are
+ * not taken into account - jahka
+ */
+ if(pfr->tot_neighbors >= 128)
+ return;
+
+ pfr->neighbors[pfr->tot_neighbors].index = index;
+ pfr->neighbors[pfr->tot_neighbors].psys = pfr->npsys;
+ pfr->tot_neighbors++;
- /* main calculations */
- for(n=own_psys?1:0; n<neighbours; n++) {
- /* disregard particles at the exact same location */
- if(ptn[n].dist < FLT_EPSILON)
- continue;
+ q = (1.f - sqrtf(squared_dist)/pfr->h) * pfr->massfac;
- npa = psys->particles + ptn[n].index;
+ if(pfr->use_size)
+ q *= npa->size;
- rij = ptn[n].dist;
- q = rij/h;
- q1 = 1.f-q;
+ pfr->density += q*q;
+ pfr->near_density += q*q*q;
+}
+static void sph_force_cb(void *sphdata_v, ParticleKey *state, float *force, float *UNUSED(impulse))
+{
+ SPHData *sphdata = (SPHData *)sphdata_v;
+ ParticleSystem **psys = sphdata->psys;
+ ParticleData *pa = sphdata->pa;
+ SPHFluidSettings *fluid = psys[0]->part->fluid;
+ ParticleSpring *spring = NULL;
+ SPHRangeData pfr;
+ SPHNeighbor *pfn;
+ float mass = sphdata->mass;
+ float *gravity = sphdata->gravity;
+ EdgeHash *springhash = sphdata->eh;
- /* Double Density Relaxation - Algorithm 2 (can't be thread safe!)*/
- D = dtime * dtime * (pressure + pressure_near*q1)*q1 * 0.5f;
- madd_v3_v3fl(pa->state.co, ptn[n].co, -D * massfactor);
- if(own_psys)
- madd_v3_v3fl(npa->state.co, ptn[n].co, D * massfactor);
+ float q, u, rij, dv[3];
+ float pressure, near_pressure;
- if(index < ptn[n].index) {
- /* Viscosity - Algorithm 5 */
- if(omega > 0.f || beta > 0.f) {
- sub_v3_v3v3(temp, pa->state.vel, npa->state.vel);
- u = dot_v3v3(ptn[n].co, temp);
+ float visc = fluid->viscosity_omega;
+ float stiff_visc = fluid->viscosity_beta * (fluid->flag & SPH_FAC_VISCOSITY ? fluid->viscosity_omega : 1.f);
- if (u > 0){
- I = dtime * (q1 * (omega * u + beta * u*u)) * 0.5f;
- madd_v3_v3fl(pa->state.vel, ptn[n].co, -I * massfactor);
+ float inv_mass = 1.0f/mass;
+ float spring_constant = fluid->spring_k;
+
+ float h = fluid->radius * (fluid->flag & SPH_FAC_RADIUS ? 4.f*pa->size : 1.f); /* 4.0 seems to be a pretty good value */
+ float rest_density = fluid->rest_density * (fluid->flag & SPH_FAC_DENSITY ? 4.77f : 1.f); /* 4.77 is an experimentally determined density factor */
+ float rest_length = fluid->rest_length * (fluid->flag & SPH_FAC_REST_LENGTH ? 2.588f * pa->size : 1.f);
- if(own_psys)
- madd_v3_v3fl(npa->state.vel, ptn[n].co, I * massfactor);
- }
- }
+ float stiffness = fluid->stiffness_k;
+ float stiffness_near_fac = fluid->stiffness_knear * (fluid->flag & SPH_FAC_REPULSION ? fluid->stiffness_k : 1.f);
- if(spring_k > 0.f) {
- /* Viscoelastic spring force - Algorithm 4*/
- if (fluid->flag & SPH_VISCOELASTIC_SPRINGS && springhash){
- spring_index = GET_INT_FROM_POINTER(BLI_edgehash_lookup(springhash, index, ptn[n].index));
+ ParticleData *npa;
+ float vec[3];
+ float vel[3];
+ float co[3];
- if(spring_index) {
- spring = psys->fluid_springs + spring_index - 1;
- }
- else {
- ParticleSpring temp_spring;
- temp_spring.particle_index[0] = index;
- temp_spring.particle_index[1] = ptn[n].index;
- temp_spring.rest_length = (fluid->flag & SPH_CURRENT_REST_LENGTH) ? rij : L;
- temp_spring.delete_flag = 0;
-
- spring = add_fluid_spring(psys, &temp_spring);
- }
+ int i, spring_index, index = pa - psys[0]->particles;
- Lij = spring->rest_length;
- d = fluid->yield_ratio * Lij;
+ pfr.tot_neighbors = 0;
+ pfr.density = pfr.near_density = 0.f;
+ pfr.h = h;
+ pfr.pa = pa;
- if (rij > Lij + d) // Stretch, 25 is just a multiplier for plasticity_constant value to counter default dtime of 1/25
- spring->rest_length += dtime * 25.f * fluid->plasticity_constant * (rij - Lij - d);
- else if(rij < Lij - d) // Compress
- spring->rest_length -= dtime * 25.f * fluid->plasticity_constant * (Lij - d - rij);
- }
- else { /* PART_SPRING_HOOKES - Hooke's spring force */
- /* L is a factor of radius */
- D = 0.5 * dtime * dtime * 10.f * fluid->spring_k * (1.f - L/h) * (L - rij);
-
- madd_v3_v3fl(pa->state.co, ptn[n].co, -D * massfactor);
- if(own_psys)
- madd_v3_v3fl(npa->state.co, ptn[n].co, D * massfactor);
- }
- }
- }
- }
+ for(i=0; i<10 && psys[i]; i++) {
+ pfr.npsys = psys[i];
+ pfr.massfac = psys[i]->part->mass*inv_mass;
+ pfr.use_size = psys[i]->part->flag & PART_SIZEMASS;
- /* Artificial buoyancy force in negative gravity direction */
- if (fluid->buoyancy >= 0.f && gravity) {
- float B = -dtime * dtime * fluid->buoyancy * (p - fluid->rest_density) * 0.5f;
- madd_v3_v3fl(pa->state.co, gravity, -B * massfactor);
+ BLI_bvhtree_range_query(psys[i]->bvhtree, state->co, h, sph_density_accum_cb, &pfr);
}
- if(ptn)
- MEM_freeN(ptn);
-}
+ pressure = stiffness * (pfr.density - rest_density);
+ near_pressure = stiffness_near_fac * pfr.near_density;
-static void apply_particle_fluidsim(Object *ob, ParticleSystem *psys, ParticleData *pa, float dtime, float *gravity, EdgeHash *springhash){
- ParticleTarget *pt;
+ pfn = pfr.neighbors;
+ for(i=0; i<pfr.tot_neighbors; i++, pfn++) {
+ npa = pfn->psys->particles + pfn->index;
- particle_fluidsim(psys, 1, pa, dtime, psys->part->mass, gravity, springhash);
-
- /*----check other SPH systems (Multifluids) , each fluid has its own parameters---*/
- for(pt=psys->targets.first; pt; pt=pt->next) {
- ParticleSystem *epsys = psys_get_target_system(ob, pt);
+ madd_v3_v3v3fl(co, npa->prev_state.co, npa->prev_state.vel, state->time);
- if(epsys)
- particle_fluidsim(epsys, 0, pa, dtime, psys->part->mass, gravity, NULL);
- }
- /*----------------------------------------------------------------*/
-}
+ sub_v3_v3v3(vec, co, state->co);
+ rij = normalize_v3(vec);
-static void apply_fluid_springs(ParticleSystem *psys, float timestep){
- SPHFluidSettings *fluid = psys->part->fluid;
- ParticleData *pa1, *pa2;
- ParticleSpring *spring = psys->fluid_springs;
-
- float h = fluid->radius;
- float massfactor = 1.0f/psys->part->mass;
- float D, Rij[3], rij, Lij;
- int i;
+ q = (1.f - rij/h) * pfn->psys->part->mass * inv_mass;
- if((fluid->flag & SPH_VISCOELASTIC_SPRINGS)==0 || fluid->spring_k == 0.f)
- return;
+ if(pfn->psys->part->flag & PART_SIZEMASS)
+ q *= npa->size;
- /* Loop through the springs */
- for(i=0; i<psys->tot_fluidsprings; i++, spring++) {
- Lij = spring->rest_length;
+ copy_v3_v3(vel, npa->prev_state.vel);
- if (Lij > h) {
- spring->delete_flag = 1;
- }
- else {
- pa1 = psys->particles + spring->particle_index[0];
- pa2 = psys->particles + spring->particle_index[1];
+ /* Double Density Relaxation */
+ madd_v3_v3fl(force, vec, -(pressure + near_pressure*q)*q);
- sub_v3_v3v3(Rij, pa2->prev_state.co, pa1->prev_state.co);
- rij = normalize_v3(Rij);
+ /* Viscosity */
+ if(visc > 0.f || stiff_visc > 0.f) {
+ sub_v3_v3v3(dv, vel, state->vel);
+ u = dot_v3v3(vec, dv);
- /* Calculate displacement and apply value */
- D = 0.5f * timestep * timestep * 10.f * fluid->spring_k * (1.f - Lij/h) * (Lij - rij);
+ if(u < 0.f && visc > 0.f)
+ madd_v3_v3fl(force, vec, 0.5f * q * visc * u );
- madd_v3_v3fl(pa1->state.co, Rij, -D * pa1->state.time * pa1->state.time * massfactor);
- madd_v3_v3fl(pa2->state.co, Rij, D * pa2->state.time * pa2->state.time * massfactor);
+ if(u > 0.f && stiff_visc > 0.f)
+ madd_v3_v3fl(force, vec, 0.5f * q * stiff_visc * u );
}
- }
- /* Loop through springs backwaqrds - for efficient delete function */
- for (i=psys->tot_fluidsprings-1; i >= 0; i--) {
- if(psys->fluid_springs[i].delete_flag)
- delete_fluid_spring(psys, i);
+ if(spring_constant > 0.f) {
+ /* Viscoelastic spring force */
+ if (pfn->psys == psys[0] && fluid->flag & SPH_VISCOELASTIC_SPRINGS && springhash) {
+ spring_index = GET_INT_FROM_POINTER(BLI_edgehash_lookup(springhash, index, pfn->index));
+
+ if(spring_index) {
+ spring = psys[0]->fluid_springs + spring_index - 1;
+
+ madd_v3_v3fl(force, vec, -10.f * spring_constant * (1.f - rij/h) * (spring->rest_length - rij));
+ }
+ else if(fluid->spring_frames == 0 || (pa->prev_state.time-pa->time) <= fluid->spring_frames){
+ ParticleSpring temp_spring;
+ temp_spring.particle_index[0] = index;
+ temp_spring.particle_index[1] = pfn->index;
+ temp_spring.rest_length = (fluid->flag & SPH_CURRENT_REST_LENGTH) ? rij : rest_length;
+ temp_spring.delete_flag = 0;
+
+ sph_spring_add(psys[0], &temp_spring);
+ }
+ }
+ else {/* PART_SPRING_HOOKES - Hooke's spring force */
+ madd_v3_v3fl(force, vec, -10.f * spring_constant * (1.f - rij/h) * (rest_length - rij));
+ }
+ }
}
+
+ /* Artificial buoyancy force in negative gravity direction */
+ if (fluid->buoyancy > 0.f && gravity)
+ madd_v3_v3fl(force, gravity, fluid->buoyancy * (pfr.density-rest_density));
}
-/************************************************/
-/* Newtonian physics */
-/************************************************/
-/* gathers all forces that effect particles and calculates a new state for the particle */
-static void apply_particle_forces(ParticleSimulationData *sim, int p, float dfra, float cfra)
-{
+static void sph_integrate(ParticleSimulationData *sim, ParticleData *pa, float dfra, float *gravity, EdgeHash *springhash){
+ ParticleTarget *pt;
+ int i;
+
ParticleSettings *part = sim->psys->part;
- ParticleData *pa = sim->psys->particles + p;
- EffectedPoint epoint;
- ParticleKey states[5], tkey;
- float timestep = psys_get_timestep(sim);
- float force[3],impulse[3],dx[4][3],dv[4][3],oldpos[3];
- float dtime=dfra*timestep, time, pa_mass=part->mass, fac /*, fra=sim->psys->cfra*/;
- int i, steps=1;
- ParticleTexture ptex;
+ // float timestep = psys_get_timestep(sim); // UNUSED
+ float pa_mass = part->mass * (part->flag & PART_SIZEMASS ? pa->size : 1.f);
+ float dtime = dfra*psys_get_timestep(sim);
+ // int steps = 1; // UNUSED
+ float effector_acceleration[3];
+ SPHData sphdata;
- psys_get_texture(sim, pa, &ptex, PAMAP_PHYSICS, cfra);
-
- /* maintain angular velocity */
- VECCOPY(pa->state.ave,pa->prev_state.ave);
- VECCOPY(oldpos,pa->state.co);
+ sphdata.psys[0] = sim->psys;
+ for(i=1, pt=sim->psys->targets.first; i<10; i++, pt=(pt?pt->next:NULL))
+ sphdata.psys[i] = pt ? psys_get_target_system(sim->ob, pt) : NULL;
- if(part->flag & PART_SIZEMASS)
- pa_mass*=pa->size;
+ sphdata.pa = pa;
+ sphdata.gravity = gravity;
+ sphdata.mass = pa_mass;
+ sphdata.eh = springhash;
- switch(part->integrator){
- case PART_INT_EULER:
- steps=1;
- break;
- case PART_INT_MIDPOINT:
- steps=2;
- break;
- case PART_INT_RK4:
- steps=4;
- break;
- case PART_INT_VERLET:
- steps=1;
- break;
- }
+ /* restore previous state and treat gravity & effectors as external acceleration*/
+ sub_v3_v3v3(effector_acceleration, pa->state.vel, pa->prev_state.vel);
+ mul_v3_fl(effector_acceleration, 1.f/dtime);
- copy_particle_key(states,&pa->state,1);
+ copy_particle_key(&pa->state, &pa->prev_state, 0);
- for(i=0; i<steps; i++){
- force[0]=force[1]=force[2]=0.0;
- impulse[0]=impulse[1]=impulse[2]=0.0;
- /* add effectors */
- pd_point_from_particle(sim, pa, states+i, &epoint);
- if(part->type != PART_HAIR || part->effector_weights->flag & EFF_WEIGHT_DO_HAIR)
- pdDoEffectors(sim->psys->effectors, sim->colliders, part->effector_weights, &epoint, force, impulse);
-
- mul_v3_fl(force, ptex.field);
- mul_v3_fl(impulse, ptex.field);
-
- /* calculate air-particle interaction */
- if(part->dragfac!=0.0f){
- fac=-part->dragfac*pa->size*pa->size*len_v3(states[i].vel);
- VECADDFAC(force,force,states[i].vel,fac);
- }
+ integrate_particle(part, pa, dtime, effector_acceleration, sph_force_cb, &sphdata);
+}
- /* brownian force */
- if(part->brownfac!=0.0){
- force[0]+=(BLI_frand()-0.5f)*part->brownfac;
- force[1]+=(BLI_frand()-0.5f)*part->brownfac;
- force[2]+=(BLI_frand()-0.5f)*part->brownfac;
- }
+/************************************************/
+/* Basic physics */
+/************************************************/
+typedef struct EfData
+{
+ ParticleTexture ptex;
+ ParticleSimulationData *sim;
+ ParticleData *pa;
+} EfData;
+static void basic_force_cb(void *efdata_v, ParticleKey *state, float *force, float *impulse)
+{
+ EfData *efdata = (EfData *)efdata_v;
+ ParticleSimulationData *sim = efdata->sim;
+ ParticleSettings *part = sim->psys->part;
+ ParticleData *pa = efdata->pa;
+ EffectedPoint epoint;
- /* force to acceleration*/
- mul_v3_fl(force,1.0f/pa_mass);
+ /* add effectors */
+ pd_point_from_particle(efdata->sim, efdata->pa, state, &epoint);
+ if(part->type != PART_HAIR || part->effector_weights->flag & EFF_WEIGHT_DO_HAIR)
+ pdDoEffectors(sim->psys->effectors, sim->colliders, part->effector_weights, &epoint, force, impulse);
- /* add global acceleration (gravitation) */
- if(psys_uses_gravity(sim)
- /* normal gravity is too strong for hair so it's disabled by default */
- && (part->type != PART_HAIR || part->effector_weights->flag & EFF_WEIGHT_DO_HAIR)) {
- madd_v3_v3fl(force, sim->scene->physics_settings.gravity, part->effector_weights->global_gravity * ptex.gravity);
- }
-
- /* calculate next state */
- VECADD(states[i].vel,states[i].vel,impulse);
+ mul_v3_fl(force, efdata->ptex.field);
+ mul_v3_fl(impulse, efdata->ptex.field);
- switch(part->integrator){
- case PART_INT_EULER:
- VECADDFAC(pa->state.co,states->co,states->vel,dtime);
- VECADDFAC(pa->state.vel,states->vel,force,dtime);
- break;
- case PART_INT_MIDPOINT:
- if(i==0){
- VECADDFAC(states[1].co,states->co,states->vel,dtime*0.5f);
- VECADDFAC(states[1].vel,states->vel,force,dtime*0.5f);
- /*fra=sim->psys->cfra+0.5f*dfra;*/
- }
- else{
- VECADDFAC(pa->state.co,states->co,states[1].vel,dtime);
- VECADDFAC(pa->state.vel,states->vel,force,dtime);
- }
- break;
- case PART_INT_RK4:
- switch(i){
- case 0:
- VECCOPY(dx[0],states->vel);
- mul_v3_fl(dx[0],dtime);
- VECCOPY(dv[0],force);
- mul_v3_fl(dv[0],dtime);
+ /* calculate air-particle interaction */
+ if(part->dragfac != 0.0f)
+ madd_v3_v3fl(force, state->vel, -part->dragfac * pa->size * pa->size * len_v3(state->vel));
- VECADDFAC(states[1].co,states->co,dx[0],0.5f);
- VECADDFAC(states[1].vel,states->vel,dv[0],0.5f);
- /*fra=sim->psys->cfra+0.5f*dfra;*/
- break;
- case 1:
- VECADDFAC(dx[1],states->vel,dv[0],0.5f);
- mul_v3_fl(dx[1],dtime);
- VECCOPY(dv[1],force);
- mul_v3_fl(dv[1],dtime);
+ /* brownian force */
+ if(part->brownfac != 0.0f){
+ force[0] += (BLI_frand()-0.5f) * part->brownfac;
+ force[1] += (BLI_frand()-0.5f) * part->brownfac;
+ force[2] += (BLI_frand()-0.5f) * part->brownfac;
+ }
+}
+/* gathers all forces that effect particles and calculates a new state for the particle */
+static void basic_integrate(ParticleSimulationData *sim, int p, float dfra, float cfra)
+{
+ ParticleSettings *part = sim->psys->part;
+ ParticleData *pa = sim->psys->particles + p;
+ ParticleKey tkey;
+ float dtime=dfra*psys_get_timestep(sim), time;
+ float *gravity = NULL, gr[3];
+ EfData efdata;
- VECADDFAC(states[2].co,states->co,dx[1],0.5f);
- VECADDFAC(states[2].vel,states->vel,dv[1],0.5f);
- break;
- case 2:
- VECADDFAC(dx[2],states->vel,dv[1],0.5f);
- mul_v3_fl(dx[2],dtime);
- VECCOPY(dv[2],force);
- mul_v3_fl(dv[2],dtime);
+ psys_get_texture(sim, pa, &efdata.ptex, PAMAP_PHYSICS, cfra);
- VECADD(states[3].co,states->co,dx[2]);
- VECADD(states[3].vel,states->vel,dv[2]);
- /*fra=cfra;*/
- break;
- case 3:
- VECADD(dx[3],states->vel,dv[2]);
- mul_v3_fl(dx[3],dtime);
- VECCOPY(dv[3],force);
- mul_v3_fl(dv[3],dtime);
-
- VECADDFAC(pa->state.co,states->co,dx[0],1.0f/6.0f);
- VECADDFAC(pa->state.co,pa->state.co,dx[1],1.0f/3.0f);
- VECADDFAC(pa->state.co,pa->state.co,dx[2],1.0f/3.0f);
- VECADDFAC(pa->state.co,pa->state.co,dx[3],1.0f/6.0f);
-
- VECADDFAC(pa->state.vel,states->vel,dv[0],1.0f/6.0f);
- VECADDFAC(pa->state.vel,pa->state.vel,dv[1],1.0f/3.0f);
- VECADDFAC(pa->state.vel,pa->state.vel,dv[2],1.0f/3.0f);
- VECADDFAC(pa->state.vel,pa->state.vel,dv[3],1.0f/6.0f);
- }
- break;
- case PART_INT_VERLET: /* Verlet integration */
- VECADDFAC(pa->state.vel,pa->state.vel,force,dtime);
- VECADDFAC(pa->state.co,pa->state.co,pa->state.vel,dtime);
+ efdata.pa = pa;
+ efdata.sim = sim;
- VECSUB(pa->state.vel,pa->state.co,oldpos);
- mul_v3_fl(pa->state.vel,1.0f/dtime);
- break;
- }
+ /* add global acceleration (gravitation) */
+ if(psys_uses_gravity(sim)
+ /* normal gravity is too strong for hair so it's disabled by default */
+ && (part->type != PART_HAIR || part->effector_weights->flag & EFF_WEIGHT_DO_HAIR)) {
+ zero_v3(gr);
+ madd_v3_v3fl(gr, sim->scene->physics_settings.gravity, part->effector_weights->global_gravity * efdata.ptex.gravity);
+ gravity = gr;
}
+ /* maintain angular velocity */
+ copy_v3_v3(pa->state.ave, pa->prev_state.ave);
+
+ integrate_particle(part, pa, dtime, gravity, basic_force_cb, &efdata);
+
/* damp affects final velocity */
if(part->dampfac != 0.f)
- mul_v3_fl(pa->state.vel, 1.f - part->dampfac * ptex.damp);
+ mul_v3_fl(pa->state.vel, 1.f - part->dampfac * efdata.ptex.damp);
- VECCOPY(pa->state.ave, states->ave);
+ //VECCOPY(pa->state.ave, states->ave);
/* finally we do guides */
time=(cfra-pa->time)/pa->lifetime;
- CLAMP(time,0.0,1.0);
+ CLAMP(time, 0.0f, 1.0f);
VECCOPY(tkey.co,pa->state.co);
VECCOPY(tkey.vel,pa->state.vel);
@@ -2621,7 +2574,7 @@ static void apply_particle_forces(ParticleSimulationData *sim, int p, float dfra
}
}
}
-static void rotate_particle(ParticleSettings *part, ParticleData *pa, float dfra, float timestep)
+static void basic_rotate(ParticleSettings *part, ParticleData *pa, float dfra, float timestep)
{
float rotfac, rot1[4], rot2[4]={1.0,0.0,0.0,0.0}, dtime=dfra*timestep;
@@ -2645,8 +2598,8 @@ static void rotate_particle(ParticleSettings *part, ParticleData *pa, float dfra
}
rotfac=len_v3(pa->state.ave);
- if(rotfac==0.0){ /* unit_qt(in VecRotToQuat) doesn't give unit quat [1,0,0,0]?? */
- rot1[0]=1.0;
+ if(rotfac == 0.0f){ /* unit_qt(in VecRotToQuat) doesn't give unit quat [1,0,0,0]?? */
+ rot1[0]=1.0f;
rot1[1]=rot1[2]=rot1[3]=0;
}
else{
@@ -2659,466 +2612,696 @@ static void rotate_particle(ParticleSettings *part, ParticleData *pa, float dfra
normalize_qt(pa->state.rot);
}
-/* convert from triangle barycentric weights to quad mean value weights */
-static void intersect_dm_quad_weights(float *v1, float *v2, float *v3, float *v4, float *w)
+/************************************************/
+/* Collisions */
+/************************************************/
+#define COLLISION_MAX_COLLISIONS 10
+#define COLLISION_MIN_RADIUS 0.001f
+#define COLLISION_MIN_DISTANCE 0.0001f
+#define COLLISION_ZERO 0.00001f
+typedef float (*NRDistanceFunc)(float *p, float radius, ParticleCollisionElement *pce, float *nor);
+static float nr_signed_distance_to_plane(float *p, float radius, ParticleCollisionElement *pce, float *nor)
{
- float co[3], vert[4][3];
+ float p0[3], e1[3], e2[3], d;
- VECCOPY(vert[0], v1);
- VECCOPY(vert[1], v2);
- VECCOPY(vert[2], v3);
- VECCOPY(vert[3], v4);
+ sub_v3_v3v3(e1, pce->x1, pce->x0);
+ sub_v3_v3v3(e2, pce->x2, pce->x0);
+ sub_v3_v3v3(p0, p, pce->x0);
- co[0]= v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2] + v4[0]*w[3];
- co[1]= v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2] + v4[1]*w[3];
- co[2]= v1[2]*w[0] + v2[2]*w[1] + v3[2]*w[2] + v4[2]*w[3];
+ cross_v3_v3v3(nor, e1, e2);
+ normalize_v3(nor);
- interp_weights_poly_v3( w,vert, 4, co);
-}
+ d = dot_v3v3(p0, nor);
+
+ if(pce->inv_nor == -1) {
+ if(d < 0.f)
+ pce->inv_nor = 1;
+ else
+ pce->inv_nor = 0;
+ }
-/* check intersection with a derivedmesh */
-int psys_intersect_dm(Scene *scene, Object *ob, DerivedMesh *dm, float *vert_cos, float *co1, float* co2, float *min_d, int *min_face, float *min_w,
- float *face_minmax, float *pa_minmax, float radius, float *ipoint)
+ if(pce->inv_nor == 1) {
+ mul_v3_fl(nor, -1.f);
+ d = -d;
+ }
+
+ return d - radius;
+}
+static float nr_distance_to_edge(float *p, float radius, ParticleCollisionElement *pce, float *UNUSED(nor))
{
- MFace *mface=0;
- MVert *mvert=0;
- int i, totface, intersect=0;
- float cur_d, cur_uv[2], v1[3], v2[3], v3[3], v4[3], min[3], max[3], p_min[3],p_max[3];
- float cur_ipoint[3];
-
- if(dm==0){
- psys_disable_all(ob);
+ float v0[3], v1[3], v2[3], c[3];
- dm=mesh_get_derived_final(scene, ob, 0);
- if(dm==0)
- dm=mesh_get_derived_deform(scene, ob, 0);
+ sub_v3_v3v3(v0, pce->x1, pce->x0);
+ sub_v3_v3v3(v1, p, pce->x0);
+ sub_v3_v3v3(v2, p, pce->x1);
- psys_enable_all(ob);
+ cross_v3_v3v3(c, v1, v2);
- if(dm==0)
- return 0;
+ return fabsf(len_v3(c)/len_v3(v0)) - radius;
+}
+static float nr_distance_to_vert(float *p, float radius, ParticleCollisionElement *pce, float *UNUSED(nor))
+{
+ return len_v3v3(p, pce->x0) - radius;
+}
+static void collision_interpolate_element(ParticleCollisionElement *pce, float t, float fac, ParticleCollision *col)
+{
+ /* t is the current time for newton rhapson */
+ /* fac is the starting factor for current collision iteration */
+ /* the col->fac's are factors for the particle subframe step start and end during collision modifier step */
+ float f = fac + t*(1.f-fac);
+ float mul = col->fac1 + f * (col->fac2-col->fac1);
+ if(pce->tot > 0) {
+ madd_v3_v3v3fl(pce->x0, pce->x[0], pce->v[0], mul);
+
+ if(pce->tot > 1) {
+ madd_v3_v3v3fl(pce->x1, pce->x[1], pce->v[1], mul);
+
+ if(pce->tot > 2)
+ madd_v3_v3v3fl(pce->x2, pce->x[2], pce->v[2], mul);
+ }
}
+}
+static void collision_point_velocity(ParticleCollisionElement *pce)
+{
+ float v[3];
-
+ copy_v3_v3(pce->vel, pce->v[0]);
+
+ if(pce->tot > 1) {
+ sub_v3_v3v3(v, pce->v[1], pce->v[0]);
+ madd_v3_v3fl(pce->vel, v, pce->uv[0]);
- if(pa_minmax==0){
- INIT_MINMAX(p_min,p_max);
- DO_MINMAX(co1,p_min,p_max);
- DO_MINMAX(co2,p_min,p_max);
+ if(pce->tot > 2) {
+ sub_v3_v3v3(v, pce->v[2], pce->v[0]);
+ madd_v3_v3fl(pce->vel, v, pce->uv[1]);
+ }
}
- else{
- VECCOPY(p_min,pa_minmax);
- VECCOPY(p_max,pa_minmax+3);
+}
+static float collision_point_distance_with_normal(float p[3], ParticleCollisionElement *pce, float fac, ParticleCollision *col, float *nor)
+{
+ if(fac >= 0.f)
+ collision_interpolate_element(pce, 0.f, fac, col);
+
+ switch(pce->tot) {
+ case 1:
+ {
+ sub_v3_v3v3(nor, p, pce->x0);
+ return normalize_v3(nor);
+ }
+ case 2:
+ {
+ float u, e[3], vec[3];
+ sub_v3_v3v3(e, pce->x1, pce->x0);
+ sub_v3_v3v3(vec, p, pce->x0);
+ u = dot_v3v3(vec, e) / dot_v3v3(e, e);
+
+ madd_v3_v3v3fl(nor, vec, e, -u);
+ return normalize_v3(nor);
+ }
+ case 3:
+ return nr_signed_distance_to_plane(p, 0.f, pce, nor);
}
+ return 0;
+}
+static void collision_point_on_surface(float p[3], ParticleCollisionElement *pce, float fac, ParticleCollision *col, float *co)
+{
+ collision_interpolate_element(pce, 0.f, fac, col);
- totface=dm->getNumTessFaces(dm);
- mface=dm->getTessFaceDataArray(dm,CD_MFACE);
- mvert=dm->getVertDataArray(dm,CD_MVERT);
-
- /* lets intersect the faces */
- for(i=0; i<totface; i++,mface++){
- if(vert_cos){
- VECCOPY(v1,vert_cos+3*mface->v1);
- VECCOPY(v2,vert_cos+3*mface->v2);
- VECCOPY(v3,vert_cos+3*mface->v3);
- if(mface->v4)
- VECCOPY(v4,vert_cos+3*mface->v4)
+ switch(pce->tot) {
+ case 1:
+ {
+ sub_v3_v3v3(co, p, pce->x0);
+ normalize_v3(co);
+ madd_v3_v3v3fl(co, pce->x0, co, col->radius);
+ break;
}
- else{
- VECCOPY(v1,mvert[mface->v1].co);
- VECCOPY(v2,mvert[mface->v2].co);
- VECCOPY(v3,mvert[mface->v3].co);
- if(mface->v4)
- VECCOPY(v4,mvert[mface->v4].co)
+ case 2:
+ {
+ float u, e[3], vec[3], nor[3];
+ sub_v3_v3v3(e, pce->x1, pce->x0);
+ sub_v3_v3v3(vec, p, pce->x0);
+ u = dot_v3v3(vec, e) / dot_v3v3(e, e);
+
+ madd_v3_v3v3fl(nor, vec, e, -u);
+ normalize_v3(nor);
+
+ madd_v3_v3v3fl(co, pce->x0, e, pce->uv[0]);
+ madd_v3_v3fl(co, nor, col->radius);
+ break;
}
+ case 3:
+ {
+ float p0[3], e1[3], e2[3], nor[3];
- if(face_minmax==0){
- INIT_MINMAX(min,max);
- DO_MINMAX(v1,min,max);
- DO_MINMAX(v2,min,max);
- DO_MINMAX(v3,min,max);
- if(mface->v4)
- DO_MINMAX(v4,min,max)
- if(isect_aabb_aabb_v3(min,max,p_min,p_max)==0)
- continue;
+ sub_v3_v3v3(e1, pce->x1, pce->x0);
+ sub_v3_v3v3(e2, pce->x2, pce->x0);
+ sub_v3_v3v3(p0, p, pce->x0);
+
+ cross_v3_v3v3(nor, e1, e2);
+ normalize_v3(nor);
+
+ if(pce->inv_nor == 1)
+ mul_v3_fl(nor, -1.f);
+
+ madd_v3_v3v3fl(co, pce->x0, nor, col->radius);
+ madd_v3_v3fl(co, e1, pce->uv[0]);
+ madd_v3_v3fl(co, e2, pce->uv[1]);
+ break;
}
- else{
- VECCOPY(min, face_minmax+6*i);
- VECCOPY(max, face_minmax+6*i+3);
- if(isect_aabb_aabb_v3(min,max,p_min,p_max)==0)
- continue;
+ }
+}
+/* find first root in range [0-1] starting from 0 */
+static float collision_newton_rhapson(ParticleCollision *col, float radius, ParticleCollisionElement *pce, NRDistanceFunc distance_func)
+{
+ float t0, t1, d0, d1, dd, n[3];
+ int iter;
+
+ pce->inv_nor = -1;
+
+ /* start from the beginning */
+ t0 = 0.f;
+ collision_interpolate_element(pce, t0, col->f, col);
+ d0 = distance_func(col->co1, radius, pce, n);
+ t1 = 0.001f;
+ d1 = 0.f;
+
+ for(iter=0; iter<10; iter++) {//, itersum++) {
+ /* get current location */
+ collision_interpolate_element(pce, t1, col->f, col);
+ interp_v3_v3v3(pce->p, col->co1, col->co2, t1);
+
+ d1 = distance_func(pce->p, radius, pce, n);
+
+ /* no movement, so no collision */
+ if(d1 == d0) {
+ return -1.f;
}
- if(radius>0.0f){
- if(isect_sweeping_sphere_tri_v3(co1, co2, radius, v2, v3, v1, &cur_d, cur_ipoint)){
- if(cur_d<*min_d){
- *min_d=cur_d;
- VECCOPY(ipoint,cur_ipoint);
- *min_face=i;
- intersect=1;
- }
- }
- if(mface->v4){
- if(isect_sweeping_sphere_tri_v3(co1, co2, radius, v4, v1, v3, &cur_d, cur_ipoint)){
- if(cur_d<*min_d){
- *min_d=cur_d;
- VECCOPY(ipoint,cur_ipoint);
- *min_face=i;
- intersect=1;
- }
- }
- }
+ /* particle already inside face, so report collision */
+ if(iter == 0 && d0 < 0.f && d0 > -radius) {
+ copy_v3_v3(pce->p, col->co1);
+ copy_v3_v3(pce->nor, n);
+ pce->inside = 1;
+ return 0.f;
}
- else{
- if(isect_line_tri_v3(co1, co2, v1, v2, v3, &cur_d, cur_uv)){
- if(cur_d<*min_d){
- *min_d=cur_d;
- min_w[0]= 1.0 - cur_uv[0] - cur_uv[1];
- min_w[1]= cur_uv[0];
- min_w[2]= cur_uv[1];
- min_w[3]= 0.0f;
- if(mface->v4)
- intersect_dm_quad_weights(v1, v2, v3, v4, min_w);
- *min_face=i;
- intersect=1;
- }
- }
- if(mface->v4){
- if(isect_line_tri_v3(co1, co2, v1, v3, v4, &cur_d, cur_uv)){
- if(cur_d<*min_d){
- *min_d=cur_d;
- min_w[0]= 1.0 - cur_uv[0] - cur_uv[1];
- min_w[1]= 0.0f;
- min_w[2]= cur_uv[0];
- min_w[3]= cur_uv[1];
- intersect_dm_quad_weights(v1, v2, v3, v4, min_w);
- *min_face=i;
- intersect=1;
- }
- }
+
+ dd = (t1-t0)/(d1-d0);
+
+ t0 = t1;
+ d0 = d1;
+
+ t1 -= d1*dd;
+
+ /* particle movin away from plane could also mean a strangely rotating face, so check from end */
+ if(iter == 0 && t1 < 0.f) {
+ t0 = 1.f;
+ collision_interpolate_element(pce, t0, col->f, col);
+ d0 = distance_func(col->co2, radius, pce, n);
+ t1 = 0.999f;
+ d1 = 0.f;
+
+ continue;
+ }
+ else if(iter == 1 && (t1 < -COLLISION_ZERO || t1 > 1.f))
+ return -1.f;
+
+ if(d1 <= COLLISION_ZERO && d1 >= -COLLISION_ZERO) {
+ if(t1 >= -COLLISION_ZERO && t1 <= 1.f) {
+ if(distance_func == nr_signed_distance_to_plane)
+ copy_v3_v3(pce->nor, n);
+
+ CLAMP(t1, 0.f, 1.f);
+
+ return t1;
}
+ else
+ return -1.f;
+ }
+ }
+ return -1.0;
+}
+static int collision_sphere_to_tri(ParticleCollision *col, float radius, ParticleCollisionElement *pce, float *t)
+{
+ ParticleCollisionElement *result = &col->pce;
+ float ct, u, v;
+
+ pce->inv_nor = -1;
+ pce->inside = 0;
+
+ ct = collision_newton_rhapson(col, radius, pce, nr_signed_distance_to_plane);
+
+ if(ct >= 0.f && ct < *t && (result->inside==0 || pce->inside==1) ) {
+ float e1[3], e2[3], p0[3];
+ float e1e1, e1e2, e1p0, e2e2, e2p0, inv;
+
+ sub_v3_v3v3(e1, pce->x1, pce->x0);
+ sub_v3_v3v3(e2, pce->x2, pce->x0);
+ /* XXX: add radius correction here? */
+ sub_v3_v3v3(p0, pce->p, pce->x0);
+
+ e1e1 = dot_v3v3(e1, e1);
+ e1e2 = dot_v3v3(e1, e2);
+ e1p0 = dot_v3v3(e1, p0);
+ e2e2 = dot_v3v3(e2, e2);
+ e2p0 = dot_v3v3(e2, p0);
+
+ inv = 1.f/(e1e1 * e2e2 - e1e2 * e1e2);
+ u = (e2e2 * e1p0 - e1e2 * e2p0) * inv;
+ v = (e1e1 * e2p0 - e1e2 * e1p0) * inv;
+
+ if(u>=0.f && u<=1.f && v>=0.f && u+v<=1.f) {
+ *result = *pce;
+
+ /* normal already calculated in pce */
+
+ result->uv[0] = u;
+ result->uv[1] = v;
+
+ *t = ct;
+ return 1;
}
}
- return intersect;
+ return 0;
}
+static int collision_sphere_to_edges(ParticleCollision *col, float radius, ParticleCollisionElement *pce, float *t)
+{
+ ParticleCollisionElement edge[3], *cur = NULL, *hit = NULL;
+ ParticleCollisionElement *result = &col->pce;
+
+ float ct;
+ int i;
+
+ for(i=0; i<3; i++) {
+ /* in case of a quad, no need to check "edge" that goes through face twice */
+ if((pce->x[3] && i==2))
+ continue;
+
+ cur = edge+i;
+ cur->x[0] = pce->x[i]; cur->x[1] = pce->x[(i+1)%3];
+ cur->v[0] = pce->v[i]; cur->v[1] = pce->v[(i+1)%3];
+ cur->tot = 2;
+ cur->inside = 0;
+
+ ct = collision_newton_rhapson(col, radius, cur, nr_distance_to_edge);
+
+ if(ct >= 0.f && ct < *t) {
+ float u, e[3], vec[3];
+
+ sub_v3_v3v3(e, cur->x1, cur->x0);
+ sub_v3_v3v3(vec, cur->p, cur->x0);
+ u = dot_v3v3(vec, e) / dot_v3v3(e, e);
+
+ if(u < 0.f || u > 1.f)
+ break;
+
+ *result = *cur;
+
+ madd_v3_v3v3fl(result->nor, vec, e, -u);
+ normalize_v3(result->nor);
+
+ result->uv[0] = u;
+
+
+ hit = cur;
+ *t = ct;
+ }
+
+ }
-void particle_intersect_face(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
+ return hit != NULL;
+}
+static int collision_sphere_to_verts(ParticleCollision *col, float radius, ParticleCollisionElement *pce, float *t)
+{
+ ParticleCollisionElement vert[3], *cur = NULL, *hit = NULL;
+ ParticleCollisionElement *result = &col->pce;
+
+ float ct;
+ int i;
+
+ for(i=0; i<3; i++) {
+ /* in case of quad, only check one vert the first time */
+ if(pce->x[3] && i != 1)
+ continue;
+
+ cur = vert+i;
+ cur->x[0] = pce->x[i];
+ cur->v[0] = pce->v[i];
+ cur->tot = 1;
+ cur->inside = 0;
+
+ ct = collision_newton_rhapson(col, radius, cur, nr_distance_to_vert);
+
+ if(ct >= 0.f && ct < *t) {
+ *result = *cur;
+
+ sub_v3_v3v3(result->nor, cur->p, cur->x0);
+ normalize_v3(result->nor);
+
+ hit = cur;
+ *t = ct;
+ }
+
+ }
+
+ return hit != NULL;
+}
+/* Callback for BVHTree near test */
+void BKE_psys_collision_neartest_cb(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
{
ParticleCollision *col = (ParticleCollision *) userdata;
+ ParticleCollisionElement pce;
MFace *face = col->md->mfaces + index;
MVert *x = col->md->x;
MVert *v = col->md->current_v;
- float vel[3], co1[3], co2[3], uv[2], ipoint[3], temp[3], t;
- float x0[3], x1[3], x2[3], x3[3];
- float *t0=x0, *t1=x1, *t2=x2, *t3=(face->v4 ? x3 : NULL);
-
- /* move collision face to start of timestep */
- madd_v3_v3v3fl(t0, x[face->v1].co, v[face->v1].co, col->cfra);
- madd_v3_v3v3fl(t1, x[face->v2].co, v[face->v2].co, col->cfra);
- madd_v3_v3v3fl(t2, x[face->v3].co, v[face->v3].co, col->cfra);
- if(t3)
- madd_v3_v3v3fl(t3, x[face->v4].co, v[face->v4].co, col->cfra);
-
- /* calculate average velocity of face */
- copy_v3_v3(vel, v[ face->v1 ].co);
- add_v3_v3(vel, v[ face->v2 ].co);
- add_v3_v3(vel, v[ face->v3 ].co);
- mul_v3_fl(vel, 0.33334f*col->dfra);
-
- /* substract face velocity, in other words convert to
- a coordinate system where only the particle moves */
- madd_v3_v3v3fl(co1, col->co1, vel, -col->f);
- sub_v3_v3v3(co2, col->co2, vel);
+ float t = hit->dist/col->original_ray_length;
+ int collision = 0;
+
+ pce.x[0] = x[face->v1].co;
+ pce.x[1] = x[face->v2].co;
+ pce.x[2] = x[face->v3].co;
+ pce.x[3] = face->v4 ? x[face->v4].co : NULL;
+
+ pce.v[0] = v[face->v1].co;
+ pce.v[1] = v[face->v2].co;
+ pce.v[2] = v[face->v3].co;
+ pce.v[3] = face->v4 ? v[face->v4].co : NULL;
+
+ pce.tot = 3;
+ pce.inside = 0;
+ pce.index = index;
+
+ /* don't collide with same face again */
+ if(col->hit == col->current && col->pce.index == index && col->pce.tot == 3)
+ return;
do
{
- if(ray->radius == 0.0f) {
- if(isect_line_tri_v3(co1, co2, t0, t1, t2, &t, uv)) {
- if(t >= 0.0f && t < hit->dist/col->ray_len) {
- hit->dist = col->ray_len * t;
- hit->index = index;
-
- /* calculate normal that's facing the particle */
- normal_tri_v3( col->nor,t0, t1, t2);
- VECSUB(temp, co2, co1);
- if(dot_v3v3(col->nor, temp) > 0.0f)
- negate_v3(col->nor);
-
- VECCOPY(col->vel,vel);
-
- col->hit_ob = col->ob;
- col->hit_md = col->md;
- }
- }
+ collision = collision_sphere_to_tri(col, ray->radius, &pce, &t);
+ if(col->pce.inside == 0) {
+ collision += collision_sphere_to_edges(col, ray->radius, &pce, &t);
+ collision += collision_sphere_to_verts(col, ray->radius, &pce, &t);
}
- else {
- if(isect_sweeping_sphere_tri_v3(co1, co2, ray->radius, t0, t1, t2, &t, ipoint)) {
- if(t >=0.0f && t < hit->dist/col->ray_len) {
- hit->dist = col->ray_len * t;
- hit->index = index;
- interp_v3_v3v3(temp, co1, co2, t);
-
- VECSUB(col->nor, temp, ipoint);
- normalize_v3(col->nor);
-
- VECCOPY(col->vel,vel);
+ if(collision) {
+ hit->dist = col->original_ray_length * t;
+ hit->index = index;
+
+ collision_point_velocity(&col->pce);
- col->hit_ob = col->ob;
- col->hit_md = col->md;
- }
- }
+ col->hit = col->current;
}
- t1 = t2;
- t2 = t3;
- t3 = NULL;
+ pce.x[1] = pce.x[2];
+ pce.x[2] = pce.x[3];
+ pce.x[3] = NULL;
- } while(t2);
+ pce.v[1] = pce.v[2];
+ pce.v[2] = pce.v[3];
+ pce.v[3] = NULL;
+
+ } while(pce.x[2]);
}
-/* Particle - Mesh collision code
- * Features:
- * - point and swept sphere to mesh surface collisions
- * - moving colliders (but not yet rotating or deforming colliders)
- * - friction & damping
- * - angular momentum <-> linear momentum
- * - high accuracy by re-applying particle acceleration after collision
- * - behaves relatively well even if limit of 10 collisions per simulation step is exceeded
- * Main parts:
- * 1. check for all possible deflectors for closest intersection on particle path
- * 2. if deflection was found calculate new coordinates or kill the particle
- */
-static void deflect_particle(ParticleSimulationData *sim, int p, float dfra, float cfra){
- Object *ground_ob = NULL;
- ParticleSettings *part = sim->psys->part;
- ParticleData *pa = sim->psys->particles + p;
- ParticleCollision col;
+static int collision_detect(ParticleData *pa, ParticleCollision *col, BVHTreeRayHit *hit, ListBase *colliders)
+{
ColliderCache *coll;
- BVHTreeRayHit hit;
- float ray_dir[3], acc[3];
- float radius = ((part->flag & PART_SIZE_DEFL)?pa->size:0.0f), boid_z = 0.0f;
- float timestep = psys_get_timestep(sim) * dfra;
- float inv_timestep = 1.0f/timestep;
- int deflections=0, max_deflections=10;
+ float ray_dir[3];
- /* get acceleration (from gravity, forcefields etc. to be re-applied after collision) */
- sub_v3_v3v3(acc, pa->state.vel, pa->prev_state.vel);
- mul_v3_fl(acc, inv_timestep);
+ if(colliders->first == NULL)
+ return 0;
- /* set values for first iteration */
- copy_v3_v3(col.co1, pa->prev_state.co);
- copy_v3_v3(col.co2, pa->state.co);
- copy_v3_v3(col.ve1, pa->prev_state.vel);
- copy_v3_v3(col.ve2, pa->state.vel);
- col.f = 0.0f;
+ sub_v3_v3v3(ray_dir, col->co2, col->co1);
+ hit->index = -1;
+ hit->dist = col->original_ray_length = len_v3(ray_dir);
+ col->pce.inside = 0;
- /* override for boids */
- if(part->phystype == PART_PHYS_BOIDS) {
- BoidParticle *bpa = pa->boid;
- radius = pa->size;
- boid_z = pa->state.co[2];
- ground_ob = bpa->ground;
+ /* even if particle is stationary we want to check for moving colliders */
+ /* if hit.dist is zero the bvhtree_ray_cast will just ignore everything */
+ if(hit->dist == 0.0f)
+ hit->dist = col->original_ray_length = 0.000001f;
+
+ for(coll = colliders->first; coll; coll=coll->next){
+ /* for boids: don't check with current ground object */
+ if(coll->ob == col->skip)
+ continue;
+
+ /* particles should not collide with emitter at birth */
+ if(coll->ob == col->emitter && pa->time < col->cfra && pa->time >= col->old_cfra)
+ continue;
+
+ col->current = coll->ob;
+ col->md = coll->collmd;
+ col->fac1 = (col->old_cfra - coll->collmd->time_x) / (coll->collmd->time_xnew - coll->collmd->time_x);
+ col->fac2 = (col->cfra - coll->collmd->time_x) / (coll->collmd->time_xnew - coll->collmd->time_x);
+
+ if(col->md && col->md->bvhtree)
+ BLI_bvhtree_ray_cast(col->md->bvhtree, col->co1, ray_dir, col->radius, hit, BKE_psys_collision_neartest_cb, col);
}
- /* 10 iterations to catch multiple deflections */
- if(sim->colliders) while(deflections < max_deflections){
- /* 1. */
+ return hit->index >= 0;
+}
+static int collision_response(ParticleData *pa, ParticleCollision *col, BVHTreeRayHit *hit, int kill, int dynamic_rotation)
+{
+ ParticleCollisionElement *pce = &col->pce;
+ PartDeflect *pd = col->hit->pd;
+ float co[3]; /* point of collision */
+ float x = hit->dist/col->original_ray_length; /* location factor of collision between this iteration */
+ float f = col->f + x * (1.0f - col->f); /* time factor of collision between timestep */
+ float dt1 = (f - col->f) * col->total_time; /* time since previous collision (in seconds) */
+ float dt2 = (1.0f - f) * col->total_time; /* time left after collision (in seconds) */
+ int through = (BLI_frand() < pd->pdef_perm) ? 1 : 0; /* did particle pass through the collision surface? */
+
+ /* calculate exact collision location */
+ interp_v3_v3v3(co, col->co1, col->co2, x);
+
+ /* particle dies in collision */
+ if(through == 0 && (kill || pd->flag & PDEFLE_KILL_PART)) {
+ pa->alive = PARS_DYING;
+ pa->dietime = col->old_cfra + (col->cfra - col->old_cfra) * f;
+
+ copy_v3_v3(pa->state.co, co);
+ interp_v3_v3v3(pa->state.vel, pa->prev_state.vel, pa->state.vel, f);
+ interp_qt_qtqt(pa->state.rot, pa->prev_state.rot, pa->state.rot, f);
+ interp_v3_v3v3(pa->state.ave, pa->prev_state.ave, pa->state.ave, f);
+
+ /* particle is dead so we don't need to calculate further */
+ return 0;
+ }
+ /* figure out velocity and other data after collision */
+ else {
+ float v0[3]; /* velocity directly before collision to be modified into velocity directly after collision */
+ float v0_nor[3];/* normal component of v0 */
+ float v0_tan[3];/* tangential component of v0 */
+ float vc_tan[3];/* tangential component of collision surface velocity */
+ float v0_dot, vc_dot;
+ float damp = pd->pdef_damp + pd->pdef_rdamp * 2 * (BLI_frand() - 0.5f);
+ float frict = pd->pdef_frict + pd->pdef_rfrict * 2 * (BLI_frand() - 0.5f);
+ float distance, nor[3], dot;
+
+ CLAMP(damp,0.0f, 1.0f);
+ CLAMP(frict,0.0f, 1.0f);
+
+ /* get exact velocity right before collision */
+ madd_v3_v3v3fl(v0, col->ve1, col->acc, dt1);
+
+ /* convert collider velocity from 1/framestep to 1/s TODO: here we assume 1 frame step for collision modifier */
+ mul_v3_fl(pce->vel, col->inv_timestep);
+
+ /* calculate tangential particle velocity */
+ v0_dot = dot_v3v3(pce->nor, v0);
+ madd_v3_v3v3fl(v0_tan, v0, pce->nor, -v0_dot);
+
+ /* calculate tangential collider velocity */
+ vc_dot = dot_v3v3(pce->nor, pce->vel);
+ madd_v3_v3v3fl(vc_tan, pce->vel, pce->nor, -vc_dot);
+
+ /* handle friction effects (tangential and angular velocity) */
+ if(frict > 0.0f) {
+ /* angular <-> linear velocity */
+ if(dynamic_rotation) {
+ float vr_tan[3], v1_tan[3], ave[3];
+
+ /* linear velocity of particle surface */
+ cross_v3_v3v3(vr_tan, pce->nor, pa->state.ave);
+ mul_v3_fl(vr_tan, pa->size);
- sub_v3_v3v3(ray_dir, col.co2, col.co1);
- hit.index = -1;
- hit.dist = col.ray_len = len_v3(ray_dir);
+ /* change to coordinates that move with the collision plane */
+ sub_v3_v3v3(v1_tan, v0_tan, vc_tan);
+
+ /* The resulting velocity is a weighted average of particle cm & surface
+ * velocity. This weight (related to particle's moment of inertia) could
+ * be made a parameter for angular <-> linear conversion.
+ */
+ madd_v3_v3fl(v1_tan, vr_tan, -0.4);
+ mul_v3_fl(v1_tan, 1.0f/1.4f); /* 1/(1+0.4) */
- col.cfra = fmod(cfra-dfra, 1.0f);
- col.dfra = dfra;
+ /* rolling friction is around 0.01 of sliding friction (could be made a parameter) */
+ mul_v3_fl(v1_tan, 1.0f - 0.01f * frict);
- /* even if particle is stationary we want to check for moving colliders */
- /* if hit.dist is zero the bvhtree_ray_cast will just ignore everything */
- if(hit.dist == 0.0f)
- hit.dist = col.ray_len = 0.000001f;
+ /* surface_velocity is opposite to cm velocity */
+ mul_v3_v3fl(vr_tan, v1_tan, -1.0f);
- for(coll = sim->colliders->first; coll; coll=coll->next){
- /* for boids: don't check with current ground object */
- if(coll->ob == ground_ob)
- continue;
+ /* get back to global coordinates */
+ add_v3_v3(v1_tan, vc_tan);
- /* particles should not collide with emitter at birth */
- if(coll->ob == sim->ob && pa->time < cfra && pa->time >= sim->psys->cfra)
- continue;
+ /* convert to angular velocity*/
+ cross_v3_v3v3(ave, vr_tan, pce->nor);
+ mul_v3_fl(ave, 1.0f/MAX2(pa->size, 0.001f));
- col.ob = coll->ob;
- col.md = coll->collmd;
+ /* only friction will cause change in linear & angular velocity */
+ interp_v3_v3v3(pa->state.ave, pa->state.ave, ave, frict);
+ interp_v3_v3v3(v0_tan, v0_tan, v1_tan, frict);
+ }
+ else {
+ /* just basic friction (unphysical due to the friction model used in Blender) */
+ interp_v3_v3v3(v0_tan, v0_tan, vc_tan, frict);
+ }
+ }
- if(col.md && col.md->bvhtree)
- BLI_bvhtree_ray_cast(col.md->bvhtree, col.co1, ray_dir, radius, &hit, particle_intersect_face, &col);
+ /* stickness was possibly added before, so cancel that before calculating new normal velocity */
+ /* otherwise particles go flying out of the surface because of high reversed sticky velocity */
+ if(v0_dot < 0.0f) {
+ v0_dot += pd->pdef_stickness;
+ if(v0_dot > 0.0f)
+ v0_dot = 0.0f;
}
- /* 2. */
- if(hit.index>=0) {
- PartDeflect *pd = col.hit_ob->pd;
- float co[3]; /* point of collision */
- float x = hit.dist/col.ray_len; /* location factor of collision between this iteration */
- float f = col.f + x * (1.0f - col.f); /* time factor of collision between timestep */
- float dt1 = (f - col.f) * timestep; /* time since previous collision (in seconds) */
- float dt2 = (1.0f - f) * timestep; /* time left after collision (in seconds) */
- int through = (BLI_frand() < pd->pdef_perm) ? 1 : 0; /* did particle pass through the collision surface? */
-
- deflections++;
-
- interp_v3_v3v3(co, col.co1, col.co2, x);
-
- /* make sure we don't hit the current face again */
- /* TODO: could/should this be proportional to pa->size? */
- madd_v3_v3fl(co, col.nor, (through ? -0.0001f : 0.0001f));
+ /* damping and flipping of velocity around normal */
+ v0_dot *= 1.0f - damp;
+ vc_dot *= through ? damp : 1.0f;
- /* particle dies in collision */
- if(through == 0 && (part->flag & PART_DIE_ON_COL || pd->flag & PDEFLE_KILL_PART)) {
- pa->alive = PARS_DYING;
- pa->dietime = sim->psys->cfra + (cfra - sim->psys->cfra) * f;
+ /* calculate normal particle velocity */
+ /* special case for object hitting the particle from behind */
+ if(through==0 && ((vc_dot>0.0f && v0_dot>0.0f && vc_dot>v0_dot) || (vc_dot<0.0f && v0_dot<0.0f && vc_dot<v0_dot)))
+ mul_v3_v3fl(v0_nor, pce->nor, vc_dot);
+ else if(v0_dot > 0.f)
+ mul_v3_v3fl(v0_nor, pce->nor, vc_dot + (through ? -1.0f : 1.0f) * v0_dot);
+ else
+ mul_v3_v3fl(v0_nor, pce->nor, vc_dot + (through ? 1.0f : -1.0f) * v0_dot);
- copy_v3_v3(pa->state.co, co);
- interp_v3_v3v3(pa->state.vel, pa->prev_state.vel, pa->state.vel, f);
- interp_qt_qtqt(pa->state.rot, pa->prev_state.rot, pa->state.rot, f);
- interp_v3_v3v3(pa->state.ave, pa->prev_state.ave, pa->state.ave, f);
+ /* combine components together again */
+ add_v3_v3v3(v0, v0_nor, v0_tan);
- /* particle is dead so we don't need to calculate further */
- return;
+ if(col->boid) {
+ /* keep boids above ground */
+ BoidParticle *bpa = pa->boid;
+ if(bpa->data.mode == eBoidMode_OnLand || co[2] <= col->boid_z) {
+ co[2] = col->boid_z;
+ v0[2] = 0.0f;
}
- /* figure out velocity and other data after collision */
- else {
- float v0[3]; /* velocity directly before collision to be modified into velocity directly after collision */
- float v0_nor[3];/* normal component of v0 */
- float v0_tan[3];/* tangential component of v0 */
- float vc_tan[3];/* tangential component of collision surface velocity */
- float check[3];
- float v0_dot, vc_dot, check_dot;
- float damp, frict;
-
- /* get exact velocity right before collision */
- madd_v3_v3v3fl(v0, col.ve1, acc, dt1);
-
- /* convert collider velocity from 1/framestep to 1/s */
- mul_v3_fl(col.vel, inv_timestep);
-
- /* get damping & friction factors */
- damp = pd->pdef_damp + pd->pdef_rdamp * 2 * (BLI_frand() - 0.5f);
- CLAMP(damp,0.0,1.0);
+ }
+
+ /* re-apply acceleration to final location and velocity */
+ madd_v3_v3v3fl(pa->state.co, co, v0, dt2);
+ madd_v3_v3fl(pa->state.co, col->acc, 0.5f*dt2*dt2);
+ madd_v3_v3v3fl(pa->state.vel, v0, col->acc, dt2);
+
+ /* make sure particle stays on the right side of the surface */
+ if(!through) {
+ distance = collision_point_distance_with_normal(co, pce, -1.f, col, nor);
+
+ if(distance < col->radius + COLLISION_MIN_DISTANCE)
+ madd_v3_v3fl(co, nor, col->radius + COLLISION_MIN_DISTANCE - distance);
- frict = pd->pdef_frict + pd->pdef_rfrict * 2 * (BLI_frand() - 0.5f);
- CLAMP(frict,0.0,1.0);
+ dot = dot_v3v3(nor, v0);
+ if(dot < 0.f)
+ madd_v3_v3fl(v0, nor, -dot);
- /* treat normal & tangent components separately */
- v0_dot = dot_v3v3(col.nor, v0);
- madd_v3_v3v3fl(v0_tan, v0, col.nor, -v0_dot);
+ distance = collision_point_distance_with_normal(pa->state.co, pce, 1.f, col, nor);
- vc_dot = dot_v3v3(col.nor, col.vel);
- madd_v3_v3v3fl(vc_tan, col.vel, col.nor, -vc_dot);
+ if(distance < col->radius + COLLISION_MIN_DISTANCE)
+ madd_v3_v3fl(pa->state.co, nor, col->radius + COLLISION_MIN_DISTANCE - distance);
- /* handle friction effects (tangential and angular velocity) */
- if(frict > 0.0f) {
- /* angular <-> linear velocity */
- if(part->flag & PART_ROT_DYN) {
- float vr_tan[3], v1_tan[3], ave[3];
-
- /* linear velocity of particle surface */
- cross_v3_v3v3(vr_tan, col.nor, pa->state.ave);
- mul_v3_fl(vr_tan, pa->size);
+ dot = dot_v3v3(nor, pa->state.vel);
+ if(dot < 0.f)
+ madd_v3_v3fl(pa->state.vel, nor, -dot);
+ }
- /* change to coordinates that move with the collision plane */
- sub_v3_v3v3(v1_tan, v0_tan, vc_tan);
-
- /* The resulting velocity is a weighted average of particle cm & surface
- * velocity. This weight (related to particle's moment of inertia) could
- * be made a parameter for angular <-> linear conversion.
- */
- madd_v3_v3fl(v1_tan, vr_tan, -0.4);
- mul_v3_fl(v1_tan, 1.0f/1.4f); /* 1/(1+0.4) */
+ /* add stickness to surface */
+ madd_v3_v3fl(pa->state.vel, pce->nor, -pd->pdef_stickness);
- /* rolling friction is around 0.01 of sliding friction (could be made a parameter) */
- mul_v3_fl(v1_tan, 1.0f - 0.01f * frict);
+ /* set coordinates for next iteration */
+ copy_v3_v3(col->co1, co);
+ copy_v3_v3(col->co2, pa->state.co);
- /* surface_velocity is opposite to cm velocity */
- mul_v3_v3fl(vr_tan, v1_tan, -1.0f);
+ copy_v3_v3(col->ve1, v0);
+ copy_v3_v3(col->ve2, pa->state.vel);
- /* get back to global coordinates */
- add_v3_v3(v1_tan, vc_tan);
+ col->f = f;
+ }
- /* convert to angular velocity*/
- cross_v3_v3v3(ave, vr_tan, col.nor);
- mul_v3_fl(ave, 1.0f/MAX2(pa->size, 0.001));
+ col->prev = col->hit;
+ col->prev_index = hit->index;
- /* only friction will cause change in linear & angular velocity */
- interp_v3_v3v3(pa->state.ave, pa->state.ave, ave, frict);
- interp_v3_v3v3(v0_tan, v0_tan, v1_tan, frict);
- }
- else {
- /* just basic friction (unphysical due to the friction model used in Blender) */
- interp_v3_v3v3(v0_tan, v0_tan, vc_tan, frict);
- }
- }
+ return 1;
+}
+static void collision_fail(ParticleData *pa, ParticleCollision *col)
+{
+ /* final chance to prevent total failure, so stick to the surface and hope for the best */
+ collision_point_on_surface(col->co1, &col->pce, 1.f, col, pa->state.co);
- /* stickness was possibly added before, so cancel that before calculating new normal velocity */
- /* otherwise particles go flying out of the surface because of high reversed sticky velocity */
- if(v0_dot < 0.0f) {
- v0_dot += pd->pdef_stickness;
- if(v0_dot > 0.0f)
- v0_dot = 0.0f;
- }
+ copy_v3_v3(pa->state.vel, col->pce.vel);
+ mul_v3_fl(pa->state.vel, col->inv_timestep);
- /* damping and flipping of velocity around normal */
- v0_dot *= 1.0f - damp;
- vc_dot *= through ? damp : 1.0f;
- /* special case for object hitting the particle from behind */
- if(through==0 && ((vc_dot>0.0f && v0_dot>0.0f && vc_dot>v0_dot) || (vc_dot<0.0f && v0_dot<0.0f && vc_dot<v0_dot)))
- mul_v3_v3fl(v0_nor, col.nor, vc_dot);
- else
- mul_v3_v3fl(v0_nor, col.nor, vc_dot + (through ? 1.0f : -1.0f) * v0_dot);
+ /* printf("max iterations\n"); */
+}
- /* combine components together again */
- add_v3_v3v3(v0, v0_nor, v0_tan);
+/* Particle - Mesh collision detection and response
+ * Features:
+ * -friction and damping
+ * -angular momentum <-> linear momentum
+ * -high accuracy by re-applying particle acceleration after collision
+ * -handles moving, rotating and deforming meshes
+ * -uses Newton-Rhapson iteration to find the collisions
+ * -handles spherical particles and (nearly) point like particles
+ */
+static void collision_check(ParticleSimulationData *sim, int p, float dfra, float cfra){
+ ParticleSettings *part = sim->psys->part;
+ ParticleData *pa = sim->psys->particles + p;
+ ParticleCollision col;
+ BVHTreeRayHit hit;
+ int collision_count=0;
- /* keep boids above ground */
- if(part->phystype == PART_PHYS_BOIDS && part->boids->options & BOID_ALLOW_LAND) {
- BoidParticle *bpa = pa->boid;
- if(bpa->data.mode == eBoidMode_OnLand || co[2] <= boid_z) {
- co[2] = boid_z;
- v0[2] = 0.0f;
- }
- }
-
- if(deflections < max_deflections) {
- /* re-apply acceleration to final velocity and location */
- madd_v3_v3v3fl(pa->state.vel, v0, acc, dt2);
- madd_v3_v3v3fl(pa->state.co, co, v0, dt2);
- madd_v3_v3fl(pa->state.co, acc, 0.5f*dt2*dt2);
+ float timestep = psys_get_timestep(sim);
- /* make sure particle stays on the right side of the surface */
- sub_v3_v3v3(check, pa->state.co, co);
- /* (collision surface has moved during the time too) */
- madd_v3_v3fl(check, col.vel, -dt2);
+ memset(&col, 0, sizeof(ParticleCollision));
- check_dot = dot_v3v3(check, col.nor);
- if((!through && check_dot < 0.0f) || (through && check_dot > 0.0f))
- madd_v3_v3fl(pa->state.co, col.nor, (through ? -0.0001f : 0.0001f) - check_dot);
+ col.total_time = timestep * dfra;
+ col.inv_timestep = 1.0f/timestep;
- /* Stickness to surface */
- madd_v3_v3fl(pa->state.vel, col.nor, -pd->pdef_stickness);
+ col.cfra = cfra;
+ col.old_cfra = sim->psys->cfra;
- /* set coordinates for next iteration */
- copy_v3_v3(col.co1, co);
- copy_v3_v3(col.co2, pa->state.co);
+ /* get acceleration (from gravity, forcefields etc. to be re-applied in collision response) */
+ sub_v3_v3v3(col.acc, pa->state.vel, pa->prev_state.vel);
+ mul_v3_fl(col.acc, 1.f/col.total_time);
- copy_v3_v3(col.ve1, v0);
- copy_v3_v3(col.ve2, pa->state.vel);
+ /* set values for first iteration */
+ copy_v3_v3(col.co1, pa->prev_state.co);
+ copy_v3_v3(col.co2, pa->state.co);
+ copy_v3_v3(col.ve1, pa->prev_state.vel);
+ copy_v3_v3(col.ve2, pa->state.vel);
+ col.f = 0.0f;
- col.f = f;
- }
- else {
- /* final chance to prevent failure, so stick to the surface and hope for the best */
- madd_v3_v3v3fl(pa->state.co, co, col.vel, dt2);
- copy_v3_v3(pa->state.vel, v0);
- }
- }
+ col.radius = ((part->flag & PART_SIZE_DEFL) || (part->phystype == PART_PHYS_BOIDS)) ? pa->size : COLLISION_MIN_RADIUS;
+
+ /* override for boids */
+ if(part->phystype == PART_PHYS_BOIDS && part->boids->options & BOID_ALLOW_LAND) {
+ col.boid = 1;
+ col.boid_z = pa->state.co[2];
+ col.skip = pa->boid->ground;
+ }
+
+ /* 10 iterations to catch multiple collisions */
+ while(collision_count < COLLISION_MAX_COLLISIONS){
+ if(collision_detect(pa, &col, &hit, sim->colliders)) {
+
+ collision_count++;
+
+ if(collision_count == COLLISION_MAX_COLLISIONS)
+ collision_fail(pa, &col);
+ else if(collision_response(pa, &col, &hit, part->flag & PART_DIE_ON_COL, part->flag & PART_ROT_DYN)==0)
+ return;
}
else
return;
@@ -3150,7 +3333,7 @@ static void psys_update_path_cache(ParticleSimulationData *sim, float cfra)
if(!(psys->part->type == PART_HAIR) || (psys->flag & PSYS_HAIR_DONE)) {
distribute_particles(sim, PART_FROM_CHILD);
- if(part->from!=PART_FROM_PARTICLE && part->childtype==PART_CHILD_FACES && part->parents!=0.0)
+ if(part->childtype==PART_CHILD_FACES && part->parents != 0.0f)
psys_find_parents(sim);
}
}
@@ -3403,11 +3586,11 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
timestep = psys_get_timestep(sim);
dtime= dfra*timestep;
- if(dfra<0.0){
+ if(dfra < 0.0f) {
LOOP_EXISTING_PARTICLES {
psys_get_texture(sim, pa, &ptex, PAMAP_SIZE, cfra);
pa->size = part->size*ptex.size;
- if(part->randsize > 0.0)
+ if(part->randsize > 0.0f)
pa->size *= 1.0f - part->randsize * PSYS_FRAND(p + 1);
reset_particle(sim, pa, dtime, cfra);
@@ -3446,11 +3629,11 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
case PART_PHYS_FLUID:
{
ParticleTarget *pt = psys->targets.first;
- psys_update_particle_tree(psys, cfra);
+ psys_update_particle_bvhtree(psys, psys->cfra);
for(; pt; pt=pt->next) { /* Updating others systems particle tree for fluid-fluid interaction */
if(pt->ob)
- psys_update_particle_tree(BLI_findlink(&pt->ob->particlesystem, pt->psys-1), cfra);
+ psys_update_particle_bvhtree(BLI_findlink(&pt->ob->particlesystem, pt->psys-1), psys->cfra);
}
break;
}
@@ -3462,7 +3645,7 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
psys_get_texture(sim, pa, &ptex, PAMAP_SIZE, cfra);
pa->size = part->size*ptex.size;
- if(part->randsize > 0.0)
+ if(part->randsize > 0.0f)
pa->size *= 1.0f - part->randsize * PSYS_FRAND(p + 1);
birthtime = pa->time;
@@ -3502,14 +3685,14 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
{
LOOP_DYNAMIC_PARTICLES {
/* do global forces & effectors */
- apply_particle_forces(sim, p, pa->state.time, cfra);
+ basic_integrate(sim, p, pa->state.time, cfra);
/* deflection */
if(sim->colliders)
- deflect_particle(sim, p, pa->state.time, cfra);
+ collision_check(sim, p, pa->state.time, cfra);
/* rotations */
- rotate_particle(part, pa, pa->state.time, timestep);
+ basic_rotate(part, pa, pa->state.time, timestep);
}
break;
}
@@ -3525,50 +3708,35 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
/* deflection */
if(sim->colliders)
- deflect_particle(sim, p, pa->state.time, cfra);
+ collision_check(sim, p, pa->state.time, cfra);
}
}
break;
}
case PART_PHYS_FLUID:
{
- EdgeHash *springhash = build_fluid_springhash(psys);
+ EdgeHash *springhash = sph_springhash_build(psys);
float *gravity = NULL;
if(psys_uses_gravity(sim))
gravity = sim->scene->physics_settings.gravity;
- /* do global forces & effectors */
- LOOP_DYNAMIC_PARTICLES {
- apply_particle_forces(sim, p, pa->state.time, cfra);
- /* in fluids forces only effect velocity */
- copy_v3_v3(pa->state.co, pa->prev_state.co);
- }
-
- /* actual fluids calculations (not threadsafe!) */
- LOOP_DYNAMIC_PARTICLES {
- apply_particle_fluidsim(sim->ob, psys, pa, pa->state.time*timestep, gravity, springhash);
- }
-
- /* Apply springs to particles */
- apply_fluid_springs(psys, timestep);
-
- /* apply velocity, collisions and rotation */
LOOP_DYNAMIC_PARTICLES {
- /* velocity holds forces and viscosity, so apply them before collisions */
- madd_v3_v3fl(pa->state.co, pa->state.vel, pa->state.time*timestep);
+ /* do global forces & effectors */
+ basic_integrate(sim, p, pa->state.time, cfra);
- /* calculate new velocity based on new-old location */
- sub_v3_v3v3(pa->state.vel, pa->state.co, pa->prev_state.co);
- mul_v3_fl(pa->state.vel, 1.f/(pa->state.time*timestep));
+ /* actual fluids calculations */
+ sph_integrate(sim, pa, pa->state.time, gravity, springhash);
if(sim->colliders)
- deflect_particle(sim, p, pa->state.time, cfra);
+ collision_check(sim, p, pa->state.time, cfra);
/* SPH particles are not physical particles, just interpolation particles, thus rotation has not a direct sense for them */
- rotate_particle(part, pa, pa->state.time, timestep);
+ basic_rotate(part, pa, pa->state.time, timestep);
}
+ sph_springs_modify(psys, timestep);
+
if(springhash) {
BLI_edgehash_free(springhash, NULL);
springhash = NULL;
@@ -3621,7 +3789,7 @@ static void cached_step(ParticleSimulationData *sim, float cfra)
LOOP_PARTICLES {
psys_get_texture(sim, pa, &ptex, PAMAP_SIZE, cfra);
pa->size = part->size*ptex.size;
- if(part->randsize > 0.0)
+ if(part->randsize > 0.0f)
pa->size *= 1.0f - part->randsize * PSYS_FRAND(p + 1);
psys->lattice= psys_get_lattice(sim);
@@ -3917,13 +4085,6 @@ static void psys_changed_type(ParticleSimulationData *sim)
BKE_ptcache_id_from_particles(&pid, sim->ob, sim->psys);
- if(part->from == PART_FROM_PARTICLE) {
- //if(part->type != PART_REACTOR)
- part->from = PART_FROM_FACE;
- if(part->distr == PART_DISTR_GRID && part->from != PART_FROM_VERT)
- part->distr = PART_DISTR_JIT;
- }
-
if(part->phystype != PART_PHYS_KEYED)
sim->psys->flag &= ~PSYS_KEYED;
@@ -3931,6 +4092,9 @@ static void psys_changed_type(ParticleSimulationData *sim)
if(ELEM4(part->ren_as, PART_DRAW_NOT, PART_DRAW_PATH, PART_DRAW_OB, PART_DRAW_GR)==0)
part->ren_as = PART_DRAW_PATH;
+ if(part->distr == PART_DISTR_GRID)
+ part->distr = PART_DISTR_JIT;
+
if(ELEM3(part->draw_as, PART_DRAW_NOT, PART_DRAW_REND, PART_DRAW_PATH)==0)
part->draw_as = PART_DRAW_REND;
@@ -3976,17 +4140,18 @@ void psys_check_boid_data(ParticleSystem *psys)
static void fluid_default_settings(ParticleSettings *part){
SPHFluidSettings *fluid = part->fluid;
- fluid->radius = 0.5f;
fluid->spring_k = 0.f;
fluid->plasticity_constant = 0.1f;
fluid->yield_ratio = 0.1f;
- fluid->rest_length = 0.5f;
+ fluid->rest_length = 1.f;
fluid->viscosity_omega = 2.f;
- fluid->viscosity_beta = 0.f;
- fluid->stiffness_k = 0.1f;
- fluid->stiffness_knear = 0.05f;
- fluid->rest_density = 10.f;
+ fluid->viscosity_beta = 0.1f;
+ fluid->stiffness_k = 1.f;
+ fluid->stiffness_knear = 1.f;
+ fluid->rest_density = 1.f;
fluid->buoyancy = 0.f;
+ fluid->radius = 1.f;
+ fluid->flag |= SPH_FAC_REPULSION|SPH_FAC_DENSITY|SPH_FAC_RADIUS|SPH_FAC_VISCOSITY|SPH_FAC_REST_LENGTH;
}
static void psys_prepare_physics(ParticleSimulationData *sim)
@@ -4105,7 +4270,8 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys)
for(i=0; i<=part->hair_step; i++){
hcfra=100.0f*(float)i/(float)psys->part->hair_step;
- BKE_animsys_evaluate_animdata(&part->id, part->adt, hcfra, ADT_RECALC_ANIM);
+ if((part->flag & PART_HAIR_REGROW)==0)
+ BKE_animsys_evaluate_animdata(&part->id, part->adt, hcfra, ADT_RECALC_ANIM);
system_step(&sim, hcfra);
psys->cfra = hcfra;
psys->recalc = 0;
@@ -4144,11 +4310,14 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys)
free_keyed_keys(psys);
distribute_particles(&sim, part->from);
initialize_all_particles(&sim);
+
+ /* flag for possible explode modifiers after this system */
+ sim.psmd->flag |= eParticleSystemFlag_Pars;
}
LOOP_EXISTING_PARTICLES {
pa->size = part->size;
- if(part->randsize > 0.0)
+ if(part->randsize > 0.0f)
pa->size *= 1.0f - part->randsize * PSYS_FRAND(p + 1);
reset_particle(&sim, pa, 0.0, cfra);
@@ -4177,6 +4346,16 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys)
}
}
+ if(psys->cfra < cfra) {
+ /* make sure emitter is left at correct time (particle emission can change this) */
+ while(ob) {
+ BKE_animsys_evaluate_animdata(&ob->id, ob->adt, cfra, ADT_RECALC_ANIM);
+ ob = ob->parent;
+ }
+ ob = sim.ob;
+ where_is_object_time(scene, ob, cfra);
+ }
+
psys->cfra = cfra;
psys->recalc = 0;
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 6ea14606660..a8447e2a12a 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -25,6 +25,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/pointcache.c
+ * \ingroup bke
+ */
+
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -1023,7 +1028,6 @@ static int ptcache_file_compressed_read(PTCacheFile *pf, unsigned char *result,
size_t in_len;
#ifdef WITH_LZO
size_t out_len = len;
- size_t sizeOfIt = 5;
#endif
unsigned char *in;
unsigned char *props = MEM_callocN(16*sizeof(char), "tmp");
@@ -1046,6 +1050,7 @@ static int ptcache_file_compressed_read(PTCacheFile *pf, unsigned char *result,
#ifdef WITH_LZMA
if(compressed == 2)
{
+ size_t sizeOfIt;
size_t leni = in_len, leno = out_len;
ptcache_file_read(pf, &size, 1, sizeof(unsigned int));
sizeOfIt = (size_t)size;
@@ -1393,7 +1398,7 @@ static PTCacheMem *ptcache_disk_frame_to_mem(PTCacheID *pid, int cfra)
unsigned int i, error = 0;
if(pf == NULL)
- return 0;
+ return NULL;
if(!ptcache_file_header_begin_read(pf))
error = 1;
@@ -2512,14 +2517,55 @@ typedef struct {
Scene *scene;
} ptcache_bake_data;
+static void ptcache_dt_to_str(char *str, double dtime)
+{
+ if(dtime > 60.0) {
+ if(dtime > 3600.0)
+ sprintf(str, "%ih %im %is", (int)(dtime/3600), ((int)(dtime/60))%60, ((int)dtime) % 60);
+ else
+ sprintf(str, "%im %is", ((int)(dtime/60))%60, ((int)dtime) % 60);
+ }
+ else
+ sprintf(str, "%is", ((int)dtime) % 60);
+}
+
static void *ptcache_bake_thread(void *ptr) {
+ int usetimer = 0, sfra, efra;
+ double stime, ptime, ctime, fetd;
+ char run[32], cur[32], etd[32];
+
ptcache_bake_data *data = (ptcache_bake_data*)ptr;
+ stime = ptime = PIL_check_seconds_timer();
+ sfra = *data->cfra_ptr;
+ efra = data->endframe;
+
for(; (*data->cfra_ptr <= data->endframe) && !data->break_operation; *data->cfra_ptr+=data->step) {
scene_update_for_newframe(data->main, data->scene, data->scene->lay);
if(G.background) {
printf("bake: frame %d :: %d\n", (int)*data->cfra_ptr, data->endframe);
}
+ else {
+ ctime = PIL_check_seconds_timer();
+
+ fetd = (ctime-ptime)*(efra-*data->cfra_ptr)/data->step;
+
+ if(usetimer || fetd > 60.0) {
+ usetimer = 1;
+
+ ptcache_dt_to_str(cur, ctime-ptime);
+ ptcache_dt_to_str(run, ctime-stime);
+ ptcache_dt_to_str(etd, fetd);
+
+ printf("Baked for %s, current frame: %i/%i (%.3fs), ETC: %s \r", run, *data->cfra_ptr-sfra+1, efra-sfra+1, ctime-ptime, etd);
+ }
+ ptime = ctime;
+ }
+ }
+
+ if(usetimer) {
+ ptcache_dt_to_str(run, PIL_check_seconds_timer()-stime);
+ printf("Bake %s %s (%i frames simulated). \n", (data->break_operation ? "canceled after" : "finished in"), run, *data->cfra_ptr-sfra);
}
data->thread_ended = TRUE;
diff --git a/source/blender/blenkernel/intern/property.c b/source/blender/blenkernel/intern/property.c
index e907b628242..d0e4832889b 100644
--- a/source/blender/blenkernel/intern/property.c
+++ b/source/blender/blenkernel/intern/property.c
@@ -30,6 +30,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/property.c
+ * \ingroup bke
+ */
+
+
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
diff --git a/source/blender/blenkernel/intern/report.c b/source/blender/blenkernel/intern/report.c
index fa2e867d483..ed3739e897d 100644
--- a/source/blender/blenkernel/intern/report.c
+++ b/source/blender/blenkernel/intern/report.c
@@ -25,6 +25,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/report.c
+ * \ingroup bke
+ */
+
+
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c
index c8a855c8156..ceafb06fce6 100644
--- a/source/blender/blenkernel/intern/sca.c
+++ b/source/blender/blenkernel/intern/sca.c
@@ -29,6 +29,11 @@
* all data is 'direct data', not Blender lib data.
*/
+/** \file blender/blenkernel/intern/sca.c
+ * \ingroup bke
+ */
+
+
#include <stdio.h>
#include <string.h>
#include <float.h>
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 1611116f0af..c4eefb16348 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -29,6 +29,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/scene.c
+ * \ingroup bke
+ */
+
+
#include <stddef.h>
#include <stdio.h>
#include <string.h>
@@ -827,54 +832,6 @@ char *scene_find_last_marker_name(Scene *scene, int frame)
return best_marker ? best_marker->name : NULL;
}
-/* markers need transforming from different parts of the code so have
- * a generic function to do this */
-int scene_marker_tfm_translate(Scene *scene, int delta, int flag)
-{
- TimeMarker *marker;
- int tot= 0;
-
- for (marker= scene->markers.first; marker; marker= marker->next) {
- if ((marker->flag & flag) == flag) {
- marker->frame += delta;
- tot++;
- }
- }
-
- return tot;
-}
-
-int scene_marker_tfm_extend(Scene *scene, int delta, int flag, int frame, char side)
-{
- TimeMarker *marker;
- int tot= 0;
-
- for (marker= scene->markers.first; marker; marker= marker->next) {
- if ((marker->flag & flag) == flag) {
- if((side=='L' && marker->frame < frame) || (side=='R' && marker->frame >= frame)) {
- marker->frame += delta;
- tot++;
- }
- }
- }
-
- return tot;
-}
-
-int scene_marker_tfm_scale(struct Scene *scene, float value, int flag)
-{
- TimeMarker *marker;
- int tot= 0;
-
- for (marker= scene->markers.first; marker; marker= marker->next) {
- if ((marker->flag & flag) == flag) {
- marker->frame= CFRA + (int)floorf(((float)(marker->frame - CFRA) * value) + 0.5f);
- tot++;
- }
- }
-
- return tot;
-}
Base *scene_add_base(Scene *sce, Object *ob)
{
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index 58900e603e3..63e35408381 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/screen.c
+ * \ingroup bke
+ */
+
+
#include <string.h>
#include <stdio.h>
#include <math.h>
@@ -231,6 +236,26 @@ void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2)
}
}
+/* facility to set locks for drawing to survive (render) threads accessing drawing data */
+/* lock can become bitflag too */
+/* should be replaced in future by better local data handling for threads */
+void BKE_spacedata_draw_locks(int set)
+{
+ SpaceType *st;
+
+ for(st= spacetypes.first; st; st= st->next) {
+ ARegionType *art;
+
+ for(art= st->regiontypes.first; art; art= art->next) {
+ if(set)
+ art->do_lock= art->lock;
+ else
+ art->do_lock= 0;
+ }
+ }
+}
+
+
/* not region itself */
void BKE_area_region_free(SpaceType *st, ARegion *ar)
{
@@ -390,3 +415,4 @@ void BKE_screen_view3d_main_sync(ListBase *screen_lb, Scene *scene)
BKE_screen_view3d_sync((View3D*)sl, scene);
}
}
+
diff --git a/source/blender/blenkernel/intern/script.c b/source/blender/blenkernel/intern/script.c
index 6ffac09e843..77153fc37ba 100644
--- a/source/blender/blenkernel/intern/script.c
+++ b/source/blender/blenkernel/intern/script.c
@@ -31,6 +31,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/script.c
+ * \ingroup bke
+ */
+
+
#include "MEM_guardedalloc.h"
diff --git a/source/blender/blenkernel/intern/seqcache.c b/source/blender/blenkernel/intern/seqcache.c
index 000d08e4df2..42beb055140 100755
--- a/source/blender/blenkernel/intern/seqcache.c
+++ b/source/blender/blenkernel/intern/seqcache.c
@@ -22,6 +22,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/seqcache.c
+ * \ingroup bke
+ */
+
+
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c
index 7ddd1fbd6bb..3dfef2e9d78 100644
--- a/source/blender/blenkernel/intern/seqeffects.c
+++ b/source/blender/blenkernel/intern/seqeffects.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/seqeffects.c
+ * \ingroup bke
+ */
+
+
#include <string.h>
#include <math.h>
#include <stdlib.h>
@@ -411,8 +416,8 @@ static void do_alphaover_effect_byte(float facf0, float facf1, int x, int y,
rt2= (char *)rect2;
rt= (char *)out;
- fac2= (int)(256.0*facf0);
- fac4= (int)(256.0*facf1);
+ fac2= (int)(256.0f*facf0);
+ fac4= (int)(256.0f*facf1);
while(y--) {
@@ -488,9 +493,9 @@ static void do_alphaover_effect_float(float facf0, float facf1, int x, int y,
/* rt = rt1 over rt2 (alpha from rt1) */
fac= fac2;
- mfac= 1.0 - (fac2*rt1[3]) ;
+ mfac= 1.0f - (fac2*rt1[3]) ;
- if(fac <= 0.0) {
+ if(fac <= 0.0f) {
memcpy(rt, rt2, 4 * sizeof(float));
} else if(mfac <=0) {
memcpy(rt, rt1, 4 * sizeof(float));
@@ -510,11 +515,11 @@ static void do_alphaover_effect_float(float facf0, float facf1, int x, int y,
while(x--) {
fac= fac4;
- mfac= 1.0 - (fac4*rt1[3]);
+ mfac= 1.0f - (fac4*rt1[3]);
- if(fac <= 0.0) {
+ if(fac <= 0.0f) {
memcpy(rt, rt2, 4 * sizeof(float));
- } else if(mfac <= 0.0) {
+ } else if(mfac <= 0.0f) {
memcpy(rt, rt1, 4 * sizeof(float));
} else {
rt[0] = fac*rt1[0] + mfac*rt2[0];
@@ -567,8 +572,8 @@ static void do_alphaunder_effect_byte(
rt2= rect2;
rt= out;
- fac2= (int)(256.0*facf0);
- fac4= (int)(256.0*facf1);
+ fac2= (int)(256.0f*facf0);
+ fac4= (int)(256.0f*facf1);
while(y--) {
@@ -649,13 +654,13 @@ static void do_alphaunder_effect_float(float facf0, float facf1, int x, int y,
/* this complex optimalisation is because the
* 'skybuf' can be crossed in
*/
- if( rt2[3]<=0 && fac2>=1.0) {
+ if( rt2[3]<=0 && fac2 >= 1.0f) {
memcpy(rt, rt1, 4 * sizeof(float));
- } else if(rt2[3]>=1.0) {
+ } else if(rt2[3] >= 1.0f) {
memcpy(rt, rt2, 4 * sizeof(float));
} else {
mfac = rt2[3];
- fac = fac2 * (1.0 - mfac);
+ fac = fac2 * (1.0f - mfac);
if(fac == 0) {
memcpy(rt, rt2, 4 * sizeof(float));
@@ -675,14 +680,14 @@ static void do_alphaunder_effect_float(float facf0, float facf1, int x, int y,
x= xo;
while(x--) {
- if(rt2[3]<=0 && fac4 >= 1.0) {
+ if(rt2[3]<=0 && fac4 >= 1.0f) {
memcpy(rt, rt1, 4 * sizeof(float));
- } else if(rt2[3]>=1.0) {
+ } else if(rt2[3]>=1.0f) {
memcpy(rt, rt2, 4 * sizeof(float));
} else {
mfac= rt2[3];
- fac= fac4*(1.0-mfac);
+ fac= fac4*(1.0f-mfac);
if(fac == 0) {
memcpy(rt, rt2, 4 * sizeof(float));
@@ -739,9 +744,9 @@ static void do_cross_effect_byte(float facf0, float facf1, int x, int y,
rt2= rect2;
rt= out;
- fac2= (int)(256.0*facf0);
+ fac2= (int)(256.0f*facf0);
fac1= 256-fac2;
- fac4= (int)(256.0*facf1);
+ fac4= (int)(256.0f*facf1);
fac3= 256-fac4;
while(y--) {
@@ -787,9 +792,9 @@ static void do_cross_effect_float(float facf0, float facf1, int x, int y,
rt= out;
fac2= facf0;
- fac1= 1.0 - fac2;
+ fac1= 1.0f - fac2;
fac4= facf1;
- fac3= 1.0 - fac4;
+ fac3= 1.0f - fac4;
while(y--) {
@@ -874,8 +879,8 @@ static void makeGammaTables(float gamma)
int i;
valid_gamma = gamma;
- valid_inv_gamma = 1.0 / gamma;
- color_step = 1.0 / RE_GAMMA_TABLE_SIZE;
+ valid_inv_gamma = 1.0f / gamma;
+ color_step = 1.0f / RE_GAMMA_TABLE_SIZE;
inv_color_step = (float) RE_GAMMA_TABLE_SIZE;
/* We could squeeze out the two range tables to gain some memory. */
@@ -951,19 +956,19 @@ static void gamtabs(float gamma)
/* gamtab: in short, out short */
for(a=0; a<65536; a++) {
val= a;
- val/= 65535.0;
+ val/= 65535.0f;
- if(gamma==2.0) val= sqrt(val);
- else if(gamma!=1.0) val= pow(val, igamma);
+ if(gamma==2.0f) val= sqrt(val);
+ else if(gamma!=1.0f) val= pow(val, igamma);
- gamtab[a]= (65535.99*val);
+ gamtab[a]= (65535.99f*val);
}
/* inverse gamtab1 : in byte, out short */
for(a=1; a<=256; a++) {
- if(gamma==2.0) igamtab1[a-1]= a*a-1;
- else if(gamma==1.0) igamtab1[a-1]= 256*a-1;
+ if(gamma==2.0f) igamtab1[a-1]= a*a-1;
+ else if(gamma==1.0f) igamtab1[a-1]= 256*a-1;
else {
- val= a/256.0;
+ val= a/256.0f;
igamtab1[a-1]= (65535.0*pow(val, gamma)) -1 ;
}
}
@@ -1006,7 +1011,7 @@ static void do_gammacross_effect_byte(float facf0, float UNUSED(facf1),
rt2= (unsigned char *)rect2;
rt= (unsigned char *)out;
- fac2= (int)(256.0*facf0);
+ fac2= (int)(256.0f*facf0);
fac1= 256-fac2;
while(y--) {
@@ -1062,7 +1067,7 @@ static void do_gammacross_effect_float(float facf0, float UNUSED(facf1),
rt= out;
fac2= facf0;
- fac1= 1.0 - fac2;
+ fac1= 1.0f - fac2;
while(y--) {
@@ -1132,8 +1137,8 @@ static void do_add_effect_byte(float facf0, float facf1, int x, int y,
rt2= (char *)rect2;
rt= (char *)out;
- fac1= (int)(256.0*facf0);
- fac3= (int)(256.0*facf1);
+ fac1= (int)(256.0f*facf0);
+ fac3= (int)(256.0f*facf1);
while(y--) {
@@ -1248,8 +1253,8 @@ static void do_sub_effect_byte(float facf0, float facf1,
rt2= (char *)rect2;
rt= (char *)out;
- fac1= (int)(256.0*facf0);
- fac3= (int)(256.0*facf1);
+ fac1= (int)(256.0f*facf0);
+ fac3= (int)(256.0f*facf1);
while(y--) {
@@ -1366,8 +1371,8 @@ static void do_drop_effect_byte(float facf0, float facf1, int x, int y,
width= x;
height= y;
- fac1= (int)(70.0*facf0);
- fac2= (int)(70.0*facf1);
+ fac1= (int)(70.0f*facf0);
+ fac2= (int)(70.0f*facf1);
rt2= (char*) (rect2i + YOFF*width);
rt1= (char*) rect1i;
@@ -1407,8 +1412,8 @@ static void do_drop_effect_float(float facf0, float facf1, int x, int y,
width= x;
height= y;
- fac1= 70.0*facf0;
- fac2= 70.0*facf1;
+ fac1= 70.0f*facf0;
+ fac2= 70.0f*facf1;
rt2= (rect2i + YOFF*width);
rt1= rect1i;
@@ -1425,10 +1430,10 @@ static void do_drop_effect_float(float facf0, float facf1, int x, int y,
for (x=XOFF; x<width; x++) {
temp= fac * rt2[3];
- *(out++)= MAX2(0.0, *rt1 - temp); rt1++;
- *(out++)= MAX2(0.0, *rt1 - temp); rt1++;
- *(out++)= MAX2(0.0, *rt1 - temp); rt1++;
- *(out++)= MAX2(0.0, *rt1 - temp); rt1++;
+ *(out++)= MAX2(0.0f, *rt1 - temp); rt1++;
+ *(out++)= MAX2(0.0f, *rt1 - temp); rt1++;
+ *(out++)= MAX2(0.0f, *rt1 - temp); rt1++;
+ *(out++)= MAX2(0.0f, *rt1 - temp); rt1++;
rt2+=4;
}
rt2+=XOFF*4;
@@ -1452,8 +1457,8 @@ static void do_mul_effect_byte(float facf0, float facf1, int x, int y,
rt2= (char *)rect2;
rt= (char *)out;
- fac1= (int)(256.0*facf0);
- fac3= (int)(256.0*facf1);
+ fac1= (int)(256.0f*facf0);
+ fac3= (int)(256.0f*facf1);
/* formula:
* fac*(a*b) + (1-fac)*a => fac*a*(b-1)+axaux= c*px + py*s ;//+centx
@@ -1514,10 +1519,10 @@ static void do_mul_effect_float(float facf0, float facf1, int x, int y,
x= xo;
while(x--) {
- rt[0]= rt1[0] + fac1*rt1[0]*(rt2[0]-1.0);
- rt[1]= rt1[1] + fac1*rt1[1]*(rt2[1]-1.0);
- rt[2]= rt1[2] + fac1*rt1[2]*(rt2[2]-1.0);
- rt[3]= rt1[3] + fac1*rt1[3]*(rt2[3]-1.0);
+ rt[0]= rt1[0] + fac1*rt1[0]*(rt2[0]-1.0f);
+ rt[1]= rt1[1] + fac1*rt1[1]*(rt2[1]-1.0f);
+ rt[2]= rt1[2] + fac1*rt1[2]*(rt2[2]-1.0f);
+ rt[3]= rt1[3] + fac1*rt1[3]*(rt2[3]-1.0f);
rt1+= 4; rt2+= 4; rt+= 4;
}
@@ -1528,10 +1533,10 @@ static void do_mul_effect_float(float facf0, float facf1, int x, int y,
x= xo;
while(x--) {
- rt[0]= rt1[0] + fac3*rt1[0]*(rt2[0]-1.0);
- rt[1]= rt1[1] + fac3*rt1[1]*(rt2[1]-1.0);
- rt[2]= rt1[2] + fac3*rt1[2]*(rt2[2]-1.0);
- rt[3]= rt1[3] + fac3*rt1[3]*(rt2[3]-1.0);
+ rt[0]= rt1[0] + fac3*rt1[0]*(rt2[0]-1.0f);
+ rt[1]= rt1[1] + fac3*rt1[1]*(rt2[1]-1.0f);
+ rt[2]= rt1[2] + fac3*rt1[2]*(rt2[2]-1.0f);
+ rt[3]= rt1[3] + fac3*rt1[3]*(rt2[3]-1.0f);
rt1+= 4; rt2+= 4; rt+= 4;
}
@@ -1577,11 +1582,11 @@ typedef struct WipeZone {
static void precalc_wipe_zone(WipeZone *wipezone, WipeVars *wipe, int xo, int yo)
{
wipezone->flip = (wipe->angle < 0);
- wipezone->angle = pow(fabs(wipe->angle)/45.0f, log(xo)/log(2.0f));
+ wipezone->angle = pow(fabsf(wipe->angle)/45.0f, log(xo)/log(2.0f));
wipezone->xo = xo;
wipezone->yo = yo;
wipezone->width = (int)(wipe->edgeWidth*((xo+yo)/2.0f));
- wipezone->pythangle = 1.0f/sqrt(wipe->angle*wipe->angle + 1.0f);
+ wipezone->pythangle = 1.0f/sqrtf(wipe->angle*wipe->angle + 1.0f);
if(wipe->wipetype == DO_SINGLE_WIPE)
wipezone->invwidth = 1.0f/wipezone->width;
@@ -1656,7 +1661,7 @@ float hyp3,hyp4,b4,b5
else {
b1 = posy - (-angle)*posx;
b2 = y - (-angle)*x;
- hyp = fabs(angle*x+y+(-posy-angle*posx))*wipezone->pythangle;
+ hyp = fabsf(angle*x+y+(-posy-angle*posx))*wipezone->pythangle;
}
if(angle < 0) {
@@ -2132,7 +2137,7 @@ static void do_transform(Scene *scene, Sequence *seq, float UNUSED(facf0), int x
}
// Rotate
- rotate_radians = (M_PI*transform->rotIni)/180.0f;
+ rotate_radians = ((float)M_PI*transform->rotIni)/180.0f;
transform_image(x,y, ibuf1, out, scale_x, scale_y, translate_x, translate_y, rotate_radians, transform->interpolation);
}
@@ -2198,8 +2203,7 @@ static void RVBlurBitmap2_byte ( unsigned char* map, int width,int height,
/* posted to comp.graphics.algorithms by */
/* Blancmange (bmange@airdmhor.gen.nz) */
- k = -1.0/(2.0*3.14159*blur*blur);
- fval=0;
+ k = -1.0f/(2.0f*(float)M_PI*blur*blur);
for (ix = 0;ix< halfWidth;ix++){
weight = (float)exp(k*(ix*ix));
filter[halfWidth - ix] = weight;
@@ -2368,7 +2372,7 @@ static void RVBlurBitmap2_float ( float* map, int width,int height,
/* posted to comp.graphics.algorithms by */
/* Blancmange (bmange@airdmhor.gen.nz) */
- k = -1.0/(2.0*3.14159*blur*blur);
+ k = -1.0f/(2.0f*(float)M_PI*blur*blur);
fval=0;
for (ix = 0;ix< halfWidth;ix++){
weight = (float)exp(k*(ix*ix));
@@ -2525,10 +2529,10 @@ static void RVAddBitmaps_float (float* a, float* b, float* c,
for (y=0;y<height;y++){
for (x=0;x<width;x++){
index=(x+y*width)*4;
- c[index+GlowR]=MIN2(1.0,a[index+GlowR]+b[index+GlowR]);
- c[index+GlowG]=MIN2(1.0,a[index+GlowG]+b[index+GlowG]);
- c[index+GlowB]=MIN2(1.0,a[index+GlowB]+b[index+GlowB]);
- c[index+GlowA]=MIN2(1.0,a[index+GlowA]+b[index+GlowA]);
+ c[index+GlowR]= MIN2(1.0f, a[index+GlowR]+b[index+GlowR]);
+ c[index+GlowG]= MIN2(1.0f, a[index+GlowG]+b[index+GlowG]);
+ c[index+GlowB]= MIN2(1.0f, a[index+GlowB]+b[index+GlowB]);
+ c[index+GlowA]= MIN2(1.0f, a[index+GlowA]+b[index+GlowA]);
}
}
}
@@ -3069,9 +3073,9 @@ static int early_out_noop(struct Sequence *UNUSED(seq),
static int early_out_fade(struct Sequence *UNUSED(seq),
float facf0, float facf1)
{
- if (facf0 == 0.0 && facf1 == 0.0) {
+ if (facf0 == 0.0f && facf1 == 0.0f) {
return 1;
- } else if (facf0 == 1.0 && facf1 == 1.0) {
+ } else if (facf0 == 1.0f && facf1 == 1.0f) {
return 2;
}
return 0;
@@ -3080,7 +3084,7 @@ static int early_out_fade(struct Sequence *UNUSED(seq),
static int early_out_mul_input2(struct Sequence *UNUSED(seq),
float facf0, float facf1)
{
- if (facf0 == 0.0 && facf1 == 0.0) {
+ if (facf0 == 0.0f && facf1 == 0.0f) {
return 1;
}
return 0;
@@ -3102,7 +3106,7 @@ static void get_default_fac_fade(struct Sequence *seq, float cfra,
float * facf0, float * facf1)
{
*facf0 = (float)(cfra - seq->startdisp);
- *facf1 = (float)(*facf0 + 0.5);
+ *facf1 = (float)(*facf0 + 0.5f);
*facf0 /= seq->len;
*facf1 /= seq->len;
}
diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c
index 83e28db771a..7a6eb1adc9f 100644
--- a/source/blender/blenkernel/intern/sequencer.c
+++ b/source/blender/blenkernel/intern/sequencer.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/sequencer.c
+ * \ingroup bke
+ */
+
+
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
@@ -213,13 +218,25 @@ Editing *seq_give_editing(Scene *scene, int alloc)
return scene->ed;
}
+static void seq_free_clipboard_recursive(Sequence *seq_parent)
+{
+ Sequence *seq, *nseq;
+
+ for(seq= seq_parent->seqbase.first; seq; seq= nseq) {
+ nseq= seq->next;
+ seq_free_clipboard_recursive(seq);
+ }
+
+ seq_free_sequence(NULL, seq_parent);
+}
+
void seq_free_clipboard(void)
{
Sequence *seq, *nseq;
for(seq= seqbase_clipboard.first; seq; seq= nseq) {
nseq= seq->next;
- seq_free_sequence(NULL, seq);
+ seq_free_clipboard_recursive(seq);
}
seqbase_clipboard.first= seqbase_clipboard.last= NULL;
}
@@ -328,7 +345,7 @@ unsigned int seq_hash_render_data(const SeqRenderData * a)
rval ^= a->preview_render_size;
rval ^= ((intptr_t) a->bmain) << 6;
rval ^= ((intptr_t) a->scene) << 6;
- rval ^= (int) (a->motion_blur_shutter * 100.0) << 10;
+ rval ^= (int) (a->motion_blur_shutter * 100.0f) << 10;
rval ^= a->motion_blur_samples << 24;
return rval;
@@ -957,7 +974,7 @@ static void multibuf(ImBuf *ibuf, float fmul)
int a, mul, icol;
- mul= (int)(256.0*fmul);
+ mul= (int)(256.0f * fmul);
rt= (char *)ibuf->rect;
rt_float = ibuf->rect_float;
@@ -1009,10 +1026,10 @@ static float give_stripelem_index(Sequence *seq, float cfra)
else nr= cfra - sta;
}
- if (seq->strobe < 1.0) seq->strobe = 1.0;
+ if (seq->strobe < 1.0f) seq->strobe = 1.0f;
- if (seq->strobe > 1.0) {
- nr -= fmod((double)nr, (double)seq->strobe);
+ if (seq->strobe > 1.0f) {
+ nr -= fmodf((double)nr, (double)seq->strobe);
}
return nr;
@@ -1365,7 +1382,7 @@ static StripColorBalance calc_cb(StripColorBalance * cb_)
/* tweak to give more subtle results
* values above 1.0 are scaled */
if(cb.lift[c] > 1.0f)
- cb.lift[c] = pow(cb.lift[c] - 1.0f, 2.0f) + 1.0f;
+ cb.lift[c] = pow(cb.lift[c] - 1.0f, 2.0) + 1.0;
cb.lift[c] = 2.0f - cb.lift[c];
}
@@ -1373,8 +1390,8 @@ static StripColorBalance calc_cb(StripColorBalance * cb_)
if (cb.flag & SEQ_COLOR_BALANCE_INVERSE_GAIN) {
for (c = 0; c < 3; c++) {
- if (cb.gain[c] != 0.0) {
- cb.gain[c] = 1.0/cb.gain[c];
+ if (cb.gain[c] != 0.0f) {
+ cb.gain[c] = 1.0f / cb.gain[c];
} else {
cb.gain[c] = 1000000; /* should be enough :) */
}
@@ -1383,8 +1400,8 @@ static StripColorBalance calc_cb(StripColorBalance * cb_)
if (!(cb.flag & SEQ_COLOR_BALANCE_INVERSE_GAMMA)) {
for (c = 0; c < 3; c++) {
- if (cb.gamma[c] != 0.0) {
- cb.gamma[c] = 1.0/cb.gamma[c];
+ if (cb.gamma[c] != 0.0f) {
+ cb.gamma[c] = 1.0f/cb.gamma[c];
} else {
cb.gamma[c] = 1000000; /* should be enough :) */
}
@@ -1411,7 +1428,7 @@ static void make_cb_table_byte(float lift, float gain, float gamma,
int y;
for (y = 0; y < 256; y++) {
- float v= color_balance_fl((float)y * (1.0 / 255.0f), lift, gain, gamma, mul);
+ float v= color_balance_fl((float)y * (1.0f / 255.0f), lift, gain, gamma, mul);
CLAMP(v, 0.0f, 1.0f);
table[y] = v * 255;
}
@@ -1423,7 +1440,7 @@ static void make_cb_table_float(float lift, float gain, float gamma,
int y;
for (y = 0; y < 256; y++) {
- float v= color_balance_fl((float)y * (1.0 / 255.0f), lift, gain, gamma, mul);
+ float v= color_balance_fl((float)y * (1.0f / 255.0f), lift, gain, gamma, mul);
table[y] = v;
}
}
@@ -1542,14 +1559,14 @@ int input_have_to_preprocess(
mul = seq->mul;
if(seq->blend_mode == SEQ_BLEND_REPLACE) {
- mul *= seq->blend_opacity / 100.0;
+ mul *= seq->blend_opacity / 100.0f;
}
- if (mul != 1.0) {
+ if (mul != 1.0f) {
return TRUE;
}
- if (seq->sat != 1.0) {
+ if (seq->sat != 1.0f) {
return TRUE;
}
@@ -1638,7 +1655,7 @@ static ImBuf * input_preprocess(
mul = seq->mul;
if(seq->blend_mode == SEQ_BLEND_REPLACE) {
- mul *= seq->blend_opacity / 100.0;
+ mul *= seq->blend_opacity / 100.0f;
}
if(seq->flag & SEQ_USE_COLOR_BALANCE && seq->strip->color_balance) {
@@ -1655,7 +1672,7 @@ static ImBuf * input_preprocess(
}
}
- if(mul != 1.0) {
+ if(mul != 1.0f) {
multibuf(ibuf, mul);
}
@@ -1760,7 +1777,7 @@ static ImBuf* seq_render_effect_strip_impl(
if (fcu) {
fac = facf = evaluate_fcurve(fcu, cfra);
if( context.scene->r.mode & R_FIELDS ) {
- facf = evaluate_fcurve(fcu, cfra + 0.5);
+ facf = evaluate_fcurve(fcu, cfra + 0.5f);
}
} else {
fac = facf = seq->effect_fader;
@@ -1901,13 +1918,17 @@ static ImBuf * seq_render_scene_strip_impl(
#endif
if(sequencer_view3d_cb && BLI_thread_is_main() && doseq_gl && (seq->scene == context.scene || have_seq==0) && seq->scene->camera) {
+ char err_out[256]= "unknown";
/* for old scened this can be uninitialized, should probably be added to do_versions at some point if the functionality stays */
if(context.scene->r.seq_prev_type==0)
context.scene->r.seq_prev_type = 3 /* ==OB_SOLID */;
/* opengl offscreen render */
scene_update_for_newframe(context.bmain, seq->scene, seq->scene->lay);
- ibuf= sequencer_view3d_cb(seq->scene, context.rectx, context.recty, IB_rect, context.scene->r.seq_prev_type);
+ ibuf= sequencer_view3d_cb(seq->scene, context.rectx, context.recty, IB_rect, context.scene->r.seq_prev_type, err_out);
+ if(ibuf == NULL) {
+ fprintf(stderr, "seq_render_scene_strip_impl failed to get opengl buffer: %s\n", err_out);
+ }
}
else {
Render *re = RE_GetRender(sce->id.name);
@@ -2135,7 +2156,7 @@ static int seq_must_swap_input_in_blend_mode(Sequence * seq)
static int seq_get_early_out_for_blend_mode(Sequence * seq)
{
struct SeqEffectHandle sh = get_sequence_blend(seq);
- float facf = seq->blend_opacity / 100.0;
+ float facf = seq->blend_opacity / 100.0f;
int early_out = sh.early_out(seq, facf, facf);
if (ELEM(early_out, EARLY_DO_EFFECT, EARLY_NO_INPUT)) {
@@ -2243,7 +2264,7 @@ static ImBuf* seq_render_strip_stack(
ImBuf * ibuf1 = out;
ImBuf * ibuf2 = seq_render_strip(context, seq, cfra);
- float facf = seq->blend_opacity / 100.0;
+ float facf = seq->blend_opacity / 100.0f;
int swap_input = seq_must_swap_input_in_blend_mode(seq);
if (swap_input) {
@@ -2965,6 +2986,24 @@ void seq_translate(Scene *evil_scene, Sequence *seq, int delta)
calc_sequence_disp(evil_scene, seq);
}
+void seq_sound_init(Scene *scene, Sequence *seq)
+{
+ if(seq->type==SEQ_META) {
+ Sequence *seq_child;
+ for(seq_child= seq->seqbase.first; seq_child; seq_child= seq_child->next) {
+ seq_sound_init(scene, seq_child);
+ }
+ }
+ else {
+ if(seq->sound) {
+ seq->scene_sound = sound_add_scene_sound(scene, seq, seq->startdisp, seq->enddisp, seq->startofs + seq->anim_startofs);
+ }
+ if(seq->scene) {
+ sound_scene_add_scene_sound(scene, seq, seq->startdisp, seq->enddisp, seq->startofs + seq->anim_startofs);
+ }
+ }
+}
+
Sequence *seq_foreground_frame_get(Scene *scene, int frame)
{
Editing *ed= seq_give_editing(scene, FALSE);
diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c
index 1db15188dff..ce956fcb236 100644
--- a/source/blender/blenkernel/intern/shrinkwrap.c
+++ b/source/blender/blenkernel/intern/shrinkwrap.c
@@ -26,6 +26,11 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
+
+/** \file blender/blenkernel/intern/shrinkwrap.c
+ * \ingroup bke
+ */
+
#include <string.h>
#include <float.h>
#include <math.h>
@@ -556,7 +561,7 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM
//Using vertexs positions/normals as if a subsurface was applied
if(smd->subsurfLevels)
{
- SubsurfModifierData ssmd= {{0}};
+ SubsurfModifierData ssmd= {{NULL}};
ssmd.subdivType = ME_CC_SUBSURF; //catmull clark
ssmd.levels = smd->subsurfLevels; //levels
diff --git a/source/blender/blenkernel/intern/sketch.c b/source/blender/blenkernel/intern/sketch.c
index 8917d2946bd..6e234a9d115 100644
--- a/source/blender/blenkernel/intern/sketch.c
+++ b/source/blender/blenkernel/intern/sketch.c
@@ -23,6 +23,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/sketch.c
+ * \ingroup bke
+ */
+
+
#include <string.h>
#include <math.h>
#include <float.h>
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index b2f8831cced..fbde1aeae22 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -29,6 +29,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/smoke.c
+ * \ingroup bke
+ */
+
+
/* Part of the code copied from elbeem fluid library, copyright by Nils Thuerey */
#include <GL/glew.h>
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c
index d197541c620..c44136f523d 100644
--- a/source/blender/blenkernel/intern/softbody.c
+++ b/source/blender/blenkernel/intern/softbody.c
@@ -28,6 +28,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/softbody.c
+ * \ingroup bke
+ */
+
+
/*
******
variables on the UI for now
diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c
index 88ca0c33624..1756227260f 100644
--- a/source/blender/blenkernel/intern/sound.c
+++ b/source/blender/blenkernel/intern/sound.c
@@ -1,3 +1,6 @@
+/** \file blender/blenkernel/intern/sound.c
+ * \ingroup bke
+ */
/**
* sound.c (mar-2001 nzc)
*
@@ -326,7 +329,7 @@ static float sound_get_volume(Scene* scene, Sequence* sequence, float time)
fcu= list_find_fcurve(&adt->action->curves, buf, 0);
if(fcu)
- return evaluate_fcurve(fcu, time * FPS);
+ return evaluate_fcurve(fcu, time * (float)FPS);
else
return sequence->volume;
}
@@ -344,7 +347,7 @@ AUD_Device* sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start,
void sound_create_scene(struct Scene *scene)
{
- scene->sound_scene = AUD_createSequencer(scene, (AUD_volumeFunction)&sound_get_volume);
+ scene->sound_scene = AUD_createSequencer(scene->audio.flag & AUDIO_MUTE, scene, (AUD_volumeFunction)&sound_get_volume);
}
void sound_destroy_scene(struct Scene *scene)
@@ -355,6 +358,12 @@ void sound_destroy_scene(struct Scene *scene)
AUD_destroySequencer(scene->sound_scene);
}
+void sound_mute_scene(struct Scene *scene, int muted)
+{
+ if(scene->sound_scene)
+ AUD_setSequencerMuted(scene->sound_scene, muted);
+}
+
void* sound_scene_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip)
{
if(scene != sequence->scene)
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index ffea719264b..13748bf10ca 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/subsurf_ccg.c
+ * \ingroup bke
+ */
+
+
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -383,49 +388,6 @@ static void set_subsurf_uv(CCGSubSurf *ss, DerivedMesh *dm, DerivedMesh *result,
MEM_freeN(faceMap);
}
-static void calc_ss_weights(int gridFaces,
- FaceVertWeight **qweight, FaceVertWeight **tweight)
-{
- FaceVertWeight *qw, *tw;
- int x, y, j;
- int numWeights = gridFaces * gridFaces;
-
- *tweight = MEM_mallocN(sizeof(**tweight) * numWeights, "ssTriWeight");
- *qweight = MEM_mallocN(sizeof(**qweight) * numWeights, "ssQuadWeight");
-
- qw = *qweight;
- tw = *tweight;
-
- for (y = 0; y < gridFaces; y++) {
- for (x = 0; x < gridFaces; x++) {
- for (j = 0; j < 4; j++) {
- int fx = x + (j == 2 || j == 3);
- int fy = y + (j == 1 || j == 2);
- float x_v = (float) fx / gridFaces;
- float y_v = (float) fy / gridFaces;
- float tx_v = (1.0f - x_v), ty_v = (1.0f - y_v);
- float center = (1.0f / 3.0f) * tx_v * ty_v;
-
- (*tw)[j][0] = center + 0.5f * tx_v * y_v;
- (*tw)[j][2] = center + 0.5f * x_v * ty_v;
- (*tw)[j][1] = 1.0f - (*tw)[j][0] - (*tw)[j][2];
- (*tw)[j][3] = 0.0f;
-
- tx_v *= 0.5f;
- ty_v *= 0.5f;
-
- (*qw)[j][3] = tx_v * ty_v;
- (*qw)[j][0] = (*qw)[j][3] + tx_v * y_v;
- (*qw)[j][2] = (*qw)[j][3] + x_v * ty_v;
- (*qw)[j][1] = 1.0f - (*qw)[j][0] - (*qw)[j][2] - (*qw)[j][3];
-
- }
- tw++;
- qw++;
- }
- }
-}
-
/* face weighting */
typedef struct FaceVertWeightEntry {
FaceVertWeight *weight;
@@ -502,6 +464,7 @@ void free_ss_weights(WeightTable *wtable)
MEM_freeN(wtable->weight_table);
}
+#if 0
static DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh,
int drawInteriorEdges, int useSubsurfUv,
DerivedMesh *dm, struct MultiresSubsurf *ms)
@@ -521,6 +484,7 @@ static DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh,
return result;
}
+#endif
static int ss_sync_from_derivedmesh(CCGSubSurf *ss, DerivedMesh *dm,
float (*vertexCos)[3], int useFlatSubdiv)
@@ -960,7 +924,11 @@ static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert)
for(x = 1; x < edgeSize - 1; x++, i++) {
vd= ccgSubSurf_getEdgeData(ss, e, x);
copy_v3_v3(mvert[i].co, vd->co);
- /* XXX, This gives errors with -fpe, the normals dont seem to be unit length - campbell */
+ /* This gives errors with -debug-fpe
+ * the normals dont seem to be unit length.
+ * this is most likely caused by edges with no
+ * faces which are now zerod out, see comment in:
+ * ccgSubSurf__calcVertNormals(), - campbell */
normal_float_to_short_v3(mvert[i].no, vd->no);
}
}
@@ -1636,7 +1604,7 @@ static void cgdm_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo
CCGSubSurf *ss = cgdm->ss;
CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss);
GPUVertexAttribs gattribs;
- DMVertexAttribs attribs= {{{0}}};
+ DMVertexAttribs attribs= {{{NULL}}};
MTFace *tf = dm->getTessFaceDataArray(dm, CD_MTFACE);
int gridSize = ccgSubSurf_getGridSize(ss);
int gridFaces = gridSize - 1;
diff --git a/source/blender/blenkernel/intern/suggestions.c b/source/blender/blenkernel/intern/suggestions.c
index 052b545cfb4..8a8bb6dd76a 100644
--- a/source/blender/blenkernel/intern/suggestions.c
+++ b/source/blender/blenkernel/intern/suggestions.c
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/suggestions.c
+ * \ingroup bke
+ */
+
+
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index 1bd41c7aa86..376f3fb031f 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -29,6 +29,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/text.c
+ * \ingroup bke
+ */
+
+
#include <string.h> /* strstr */
#include <sys/types.h>
#include <sys/stat.h>
@@ -373,7 +378,6 @@ Text *add_text(const char *file, const char *relpath)
ta->mtime= st.st_mtime;
ta->nlines=0;
- i=0;
llen=0;
for(i=0; i<len; i++) {
if (buffer[i]=='\n') {
diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c
index c22b1d32849..a5412c6269e 100644
--- a/source/blender/blenkernel/intern/texture.c
+++ b/source/blender/blenkernel/intern/texture.c
@@ -29,6 +29,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/texture.c
+ * \ingroup bke
+ */
+
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -218,9 +223,9 @@ void init_mapping(TexMapping *texmap)
size_to_mat3( smat,texmap->size);
- eul[0]= (M_PI/180.0f)*texmap->rot[0];
- eul[1]= (M_PI/180.0f)*texmap->rot[1];
- eul[2]= (M_PI/180.0f)*texmap->rot[2];
+ eul[0]= DEG2RADF(texmap->rot[0]);
+ eul[1]= DEG2RADF(texmap->rot[1]);
+ eul[2]= DEG2RADF(texmap->rot[2]);
eul_to_mat3( rmat,eul);
mul_m3_m3m3(mat, rmat, smat);
@@ -337,8 +342,11 @@ int do_colorband(ColorBand *coba, float in, float out[4])
if(cbd2->pos!=cbd1->pos)
fac= (in-cbd1->pos)/(cbd2->pos-cbd1->pos);
- else
- fac= 0.0f;
+ else {
+ /* was setting to 0.0 in 2.56 & previous, but this
+ * is incorrect for the last element, see [#26732] */
+ fac= (a != coba->tot) ? 0.0f : 1.0f;
+ }
if (coba->ipotype==4) {
/* constant */
@@ -368,10 +376,10 @@ int do_colorband(ColorBand *coba, float in, float out[4])
out[1]= t[3]*cbd3->g +t[2]*cbd2->g +t[1]*cbd1->g +t[0]*cbd0->g;
out[2]= t[3]*cbd3->b +t[2]*cbd2->b +t[1]*cbd1->b +t[0]*cbd0->b;
out[3]= t[3]*cbd3->a +t[2]*cbd2->a +t[1]*cbd1->a +t[0]*cbd0->a;
- CLAMP(out[0], 0.0, 1.0);
- CLAMP(out[1], 0.0, 1.0);
- CLAMP(out[2], 0.0, 1.0);
- CLAMP(out[3], 0.0, 1.0);
+ CLAMP(out[0], 0.0f, 1.0f);
+ CLAMP(out[1], 0.0f, 1.0f);
+ CLAMP(out[2], 0.0f, 1.0f);
+ CLAMP(out[3], 0.0f, 1.0f);
}
else {
@@ -475,11 +483,13 @@ int colorband_element_remove(struct ColorBand *coba, int index)
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_free_animdata((struct ID *)tex);
+
BKE_previewimg_free(&tex->preview);
BKE_icon_delete((struct ID*)tex);
tex->id.icon_id = 0;
@@ -745,10 +755,6 @@ Tex *copy_texture(Tex *tex)
if(texn->type==TEX_IMAGE) id_us_plus((ID *)texn->ima);
else texn->ima= NULL;
-#if 0 // XXX old animation system
- id_us_plus((ID *)texn->ipo);
-#endif // XXX old animation system
-
if(texn->plugin) {
texn->plugin= MEM_dupallocN(texn->plugin);
open_plugin_tex(texn->plugin);
@@ -763,12 +769,56 @@ Tex *copy_texture(Tex *tex)
if(tex->nodetree) {
ntreeEndExecTree(tex->nodetree);
- texn->nodetree= ntreeCopyTree(tex->nodetree); /* 0 == full new tree */
+ texn->nodetree= ntreeCopyTree(tex->nodetree);
}
return texn;
}
+/* texture copy without adding to main dbase */
+Tex *localize_texture(Tex *tex)
+{
+ Tex *texn;
+
+ texn= copy_libblock(tex);
+ BLI_remlink(&G.main->tex, texn);
+
+ /* image texture: free_texture also doesn't decrease */
+
+ if(texn->plugin) {
+ texn->plugin= MEM_dupallocN(texn->plugin);
+ open_plugin_tex(texn->plugin);
+ }
+
+ if(texn->coba) texn->coba= MEM_dupallocN(texn->coba);
+ if(texn->env) {
+ texn->env= BKE_copy_envmap(texn->env);
+ id_us_min(&texn->env->ima->id);
+ }
+ if(texn->pd) {
+ texn->pd= MEM_dupallocN(texn->pd);
+ if(texn->pd->coba) {
+ texn->pd->point_tree = NULL;
+ texn->pd->coba= MEM_dupallocN(texn->pd->coba);
+ }
+
+ }
+ if(texn->vd) {
+ texn->vd= MEM_dupallocN(texn->vd);
+ if(texn->vd->dataset)
+ texn->vd->dataset= MEM_dupallocN(texn->vd->dataset);
+ }
+
+ texn->preview = NULL;
+
+ if(tex->nodetree) {
+ texn->nodetree= ntreeLocalize(tex->nodetree);
+ }
+
+ return texn;
+}
+
+
/* ------------------------------------------------------------------------- */
void make_local_texture(Tex *tex)
@@ -1342,7 +1392,10 @@ void BKE_free_pointdensitydata(PointDensity *pd)
MEM_freeN(pd->point_data);
pd->point_data = NULL;
}
- if(pd->coba) MEM_freeN(pd->coba);
+ if(pd->coba) {
+ MEM_freeN(pd->coba);
+ pd->coba = NULL;
+ }
}
void BKE_free_pointdensity(PointDensity *pd)
diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c
index b071f2c9da5..37e604fa0cb 100644
--- a/source/blender/blenkernel/intern/unit.c
+++ b/source/blender/blenkernel/intern/unit.c
@@ -21,6 +21,11 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
+
+/** \file blender/blenkernel/intern/unit.c
+ * \ingroup bke
+ */
+
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
@@ -339,9 +344,7 @@ static int unit_as_string(char *str, int len_max, double value, int prec, bUnitC
/* Convert to a string */
{
- char conv_str[6] = {'%', '.', '0', 'l', 'f', '\0'}; /* "%.2lf" when prec is 2, must be under 10 */
- conv_str[2] += prec;
- len= snprintf(str, len_max, conv_str, (float)value_conv);
+ len= snprintf(str, len_max, "%.*lf", prec, value_conv);
if(len >= len_max)
len= len_max;
diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c
index 5412e44f0eb..ff58e8bd0a4 100644
--- a/source/blender/blenkernel/intern/world.c
+++ b/source/blender/blenkernel/intern/world.c
@@ -30,6 +30,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/world.c
+ * \ingroup bke
+ */
+
+
#include <string.h>
#include <math.h>
#include "MEM_guardedalloc.h"
@@ -155,7 +160,7 @@ void make_local_world(World *wrld)
}
if(local && lib==0) {
- wrld->id.lib= 0;
+ wrld->id.lib= NULL;
wrld->id.flag= LIB_LOCAL;
new_id(NULL, (ID *)wrld, NULL);
}
diff --git a/source/blender/blenkernel/intern/writeavi.c b/source/blender/blenkernel/intern/writeavi.c
index 1c1febf2609..73e23bd2a05 100644
--- a/source/blender/blenkernel/intern/writeavi.c
+++ b/source/blender/blenkernel/intern/writeavi.c
@@ -31,6 +31,11 @@
*
*/
+/** \file blender/blenkernel/intern/writeavi.c
+ * \ingroup bke
+ */
+
+
#include <string.h>
#include "MEM_guardedalloc.h"
diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c
index f3b759113ff..9b1c3b2ddb8 100644
--- a/source/blender/blenkernel/intern/writeffmpeg.c
+++ b/source/blender/blenkernel/intern/writeffmpeg.c
@@ -1,3 +1,6 @@
+/** \file blender/blenkernel/intern/writeffmpeg.c
+ * \ingroup bke
+ */
/*
* $Id$
*
diff --git a/source/blender/blenkernel/intern/writeframeserver.c b/source/blender/blenkernel/intern/writeframeserver.c
index 3cb3d7e038b..2239f6d3147 100644
--- a/source/blender/blenkernel/intern/writeframeserver.c
+++ b/source/blender/blenkernel/intern/writeframeserver.c
@@ -1,3 +1,6 @@
+/** \file blender/blenkernel/intern/writeframeserver.c
+ * \ingroup bke
+ */
/*
* $Id$
*
diff --git a/source/blender/blenkernel/nla_private.h b/source/blender/blenkernel/nla_private.h
index bd760646053..367cbd90915 100644
--- a/source/blender/blenkernel/nla_private.h
+++ b/source/blender/blenkernel/nla_private.h
@@ -27,6 +27,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/nla_private.h
+ * \ingroup bke
+ */
+
+
#ifndef NLA_PRIVATE
#define NLA_PRIVATE