diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-05-12 02:48:41 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-05-12 02:48:41 +0400 |
commit | 8925ed1420ea2557abc7867cf12f89730ef77718 (patch) | |
tree | 67a95fd12253de438e1bdb30bf6c90af2ff12d7f /source/blender/blenkernel | |
parent | bf2fac79d407a1d8c0e5727cc644d98eef60a965 (diff) | |
parent | 1c0c2f4d0bd6556a3dd7293ddbd419a066e745f4 (diff) |
Merged changes in the trunk up to revision 46557.
Conflicts resolved:
source/blender/blenkernel/intern/material.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/animation/anim_channels_defines.c
source/blender/makesrna/intern/rna_scene.c
Additional changes:
* Fix for recent changes of BKE_* function renaming.
* Fix for an "attempt to free NULL pointer" in BlenderStrokeRenderer::RenderStrokeRepBasic().
Diffstat (limited to 'source/blender/blenkernel')
107 files changed, 18204 insertions, 17375 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index a15192f156a..595a1e884d7 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -74,6 +74,8 @@ #include "BKE_customdata.h" #include "BKE_bvhutils.h" +struct CCGElem; +struct CCGKey; struct MVert; struct MEdge; struct MFace; @@ -102,11 +104,6 @@ struct PBVH; * Also, the mface origindex layer indexes mpolys, not mfaces. */ -typedef struct DMGridData { - float co[3]; - float no[3]; -} DMGridData; - typedef struct DMGridAdjacency { int index[4]; int rotation[4]; @@ -250,9 +247,10 @@ struct DerivedMesh { /* optional grid access for subsurf */ int (*getNumGrids)(DerivedMesh *dm); int (*getGridSize)(DerivedMesh *dm); - DMGridData **(*getGridData)(DerivedMesh *dm); + struct CCGElem **(*getGridData)(DerivedMesh *dm); DMGridAdjacency *(*getGridAdjacency)(DerivedMesh *dm); int *(*getGridOffset)(DerivedMesh *dm); + void (*getGridKey)(DerivedMesh *dm, struct CCGKey *key); DMFlagMat *(*getGridFlagMats)(DerivedMesh *dm); unsigned int **(*getGridHidden)(DerivedMesh *dm); diff --git a/source/blender/blenkernel/BKE_action.h b/source/blender/blenkernel/BKE_action.h index 564cd235869..a326b514f9a 100644 --- a/source/blender/blenkernel/BKE_action.h +++ b/source/blender/blenkernel/BKE_action.h @@ -59,13 +59,13 @@ extern "C" { struct bAction *add_empty_action(const char name[]); /* Allocate a copy of the given Action and all its data */ -struct bAction *copy_action(struct bAction *src); +struct bAction *BKE_action_copy(struct bAction *src); /* Deallocate all of the Action's data, but not the Action itself */ -void free_action(struct bAction *act); +void BKE_action_free(struct bAction *act); // XXX is this needed? -void make_local_action(struct bAction *act); +void BKE_action_make_local(struct bAction *act); /* Action API ----------------- */ @@ -122,7 +122,7 @@ void action_groups_add_channel(struct bAction *act, struct bActionGroup *agrp, s void action_groups_remove_channel(struct bAction *act, struct FCurve *fcu); /* Find a group with the given name */ -struct bActionGroup *action_groups_find_named(struct bAction *act, const char name[]); +struct bActionGroup *BKE_action_group_find_name(struct bAction *act, const char name[]); /* Clear all 'temp' flags on all groups */ void action_groups_clear_tempflags(struct bAction *act); @@ -133,71 +133,71 @@ void action_groups_clear_tempflags(struct bAction *act); * Deallocates a pose channel. * Does not free the pose channel itself. */ -void free_pose_channel(struct bPoseChannel *pchan); +void BKE_pose_channel_free(struct bPoseChannel *pchan); /** * Removes and deallocates all channels from a pose. * Does not free the pose itself. */ -void free_pose_channels(struct bPose *pose); +void BKE_pose_channels_free(struct bPose *pose); /** * Removes the hash for quick lookup of channels, must * be done when adding/removing channels. */ -void make_pose_channels_hash(struct bPose *pose); -void free_pose_channels_hash(struct bPose *pose); +void BKE_pose_channels_hash_make(struct bPose *pose); +void BKE_pose_channels_hash_free(struct bPose *pose); /** * Removes and deallocates all data from a pose, and also frees the pose. */ -void free_pose(struct bPose *pose); +void BKE_pose_free(struct bPose *pose); /** * Allocate a new pose on the heap, and copy the src pose and it's channels * into the new pose. *dst is set to the newly allocated structure, and assumed to be NULL. */ -void copy_pose(struct bPose **dst, struct bPose *src, int copyconstraints); +void BKE_pose_copy_data(struct bPose **dst, struct bPose *src, int copyconstraints); /** * Copy the internal members of each pose channel including constraints * and ID-Props, used when duplicating bones in editmode. */ -void duplicate_pose_channel_data(struct bPoseChannel *pchan, const struct bPoseChannel *pchan_from); +void BKE_pose_channel_copy_data(struct bPoseChannel *pchan, const struct bPoseChannel *pchan_from); /** * Return a pointer to the pose channel of the given name * from this pose. */ -struct bPoseChannel *get_pose_channel(const struct bPose *pose, const char *name); +struct bPoseChannel *BKE_pose_channel_find_name(const struct bPose *pose, const char *name); /** * Return a pointer to the active pose channel from this Object. * (Note: Object, not bPose is used here, as we need layer info from Armature) */ -struct bPoseChannel *get_active_posechannel(struct Object *ob); +struct bPoseChannel *BKE_pose_channel_active(struct Object *ob); /** * Looks to see if the channel with the given name * already exists in this pose - if not a new one is * allocated and initialized. */ -struct bPoseChannel *verify_pose_channel(struct bPose* pose, const char* name); +struct bPoseChannel *BKE_pose_channel_verify(struct bPose* pose, const char* name); /* Copy the data from the action-pose (src) into the pose */ void extract_pose_from_pose(struct bPose *pose, const struct bPose *src); /* sets constraint flags */ -void update_pose_constraint_flags(struct bPose *pose); +void BKE_pose_update_constraint_flags(struct bPose *pose); /* return the name of structure pointed by pose->ikparam */ -const char *get_ikparam_name(struct bPose *pose); +const char *BKE_pose_ikparam_get_name(struct bPose *pose); /* allocate and initialize pose->ikparam according to pose->iksolver */ -void init_pose_ikparam(struct bPose *pose); +void BKE_pose_ikparam_init(struct bPose *pose); /* initialize a bItasc structure with default value */ -void init_pose_itasc(struct bItasc *itasc); +void BKE_pose_itasc_init(struct bItasc *itasc); /* clears BONE_UNKEYED flags for frame changing */ // XXX to be depreceated for a more general solution in animsys... @@ -206,10 +206,10 @@ void framechange_poses_clear_unkeyed(void); /* Bone Groups API --------------------- */ /* Adds a new bone-group */ -void pose_add_group(struct Object *ob); +void BKE_pose_add_group(struct Object *ob); /* Remove the active bone-group */ -void pose_remove_group(struct Object *ob); +void BKE_pose_remove_group(struct Object *ob); /* Assorted Evaluation ----------------- */ @@ -217,9 +217,9 @@ void pose_remove_group(struct Object *ob); void what_does_obaction(struct Object *ob, struct Object *workob, struct bPose *pose, struct bAction *act, char groupname[], float cframe); /* for proxy */ -void copy_pose_result(struct bPose *to, struct bPose *from); +void BKE_pose_copy_result(struct bPose *to, struct bPose *from); /* clear all transforms */ -void rest_pose(struct bPose *pose); +void BKE_pose_rest(struct bPose *pose); #ifdef __cplusplus }; diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h index dfe3fde17eb..b8c2c42f8d5 100644 --- a/source/blender/blenkernel/BKE_armature.h +++ b/source/blender/blenkernel/BKE_armature.h @@ -75,28 +75,28 @@ typedef struct PoseTree extern "C" { #endif -struct bArmature *add_armature(const char *name); -struct bArmature *get_armature(struct Object *ob); -void free_bonelist (struct ListBase *lb); -void free_armature(struct bArmature *arm); -void make_local_armature(struct bArmature *arm); -struct bArmature *copy_armature(struct bArmature *arm); +struct bArmature *BKE_armature_add(const char *name); +struct bArmature *BKE_armature_from_object(struct Object *ob); +void BKE_armature_bonelist_free (struct ListBase *lb); +void BKE_armature_free(struct bArmature *arm); +void BKE_armature_make_local(struct bArmature *arm); +struct bArmature *BKE_armature_copy(struct bArmature *arm); /* Bounding box. */ -struct BoundBox *BKE_armature_get_bb(struct Object *ob); +struct BoundBox *BKE_armature_boundbox_get(struct Object *ob); int bone_autoside_name (char name[64], int strip_number, short axis, float head, float tail); -struct Bone *get_named_bone (struct bArmature *arm, const char *name); +struct Bone *BKE_armature_find_bone_name (struct bArmature *arm, const char *name); float distfactor_to_bone(const float vec[3], const float b1[3], const float b2[3], float r1, float r2, float rdist); -void where_is_armature (struct bArmature *arm); -void where_is_armature_bone(struct Bone *bone, struct Bone *prevbone); -void armature_rebuild_pose(struct Object *ob, struct bArmature *arm); -void where_is_pose (struct Scene *scene, struct Object *ob); -void where_is_pose_bone(struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime, int do_extra); -void where_is_pose_bone_tail(struct bPoseChannel *pchan); +void BKE_armature_where_is(struct bArmature *arm); +void BKE_armature_where_is_bone(struct Bone *bone, struct Bone *prevbone); +void BKE_pose_rebuild(struct Object *ob, struct bArmature *arm); +void BKE_pose_where_is(struct Scene *scene, struct Object *ob); +void BKE_pose_where_is_bone(struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime, int do_extra); +void BKE_pose_where_is_bone_tail(struct bPoseChannel *pchan); /* get_objectspace_bone_matrix has to be removed still */ void get_objectspace_bone_matrix (struct Bone* bone, float M_accumulatedMatrix[][4], int root, int posed); @@ -106,23 +106,23 @@ void mat3_to_vec_roll(float mat[][3], float *vec, float *roll); int get_selected_defgroups(struct Object *ob, char *defbase_sel, int defbase_len); /* Common Conversions Between Co-ordinate Spaces */ -void armature_mat_world_to_pose(struct Object *ob, float inmat[][4], float outmat[][4]); -void armature_loc_world_to_pose(struct Object *ob, const float inloc[3], float outloc[3]); -void armature_mat_pose_to_bone(struct bPoseChannel *pchan, float inmat[][4], float outmat[][4]); -void armature_loc_pose_to_bone(struct bPoseChannel *pchan, const float inloc[3], float outloc[3]); -void armature_mat_bone_to_pose(struct bPoseChannel *pchan, float inmat[][4], float outmat[][4]); -void armature_mat_pose_to_delta(float delta_mat[][4], float pose_mat[][4], float arm_mat[][4]); +void BKE_armature_mat_world_to_pose(struct Object *ob, float inmat[][4], float outmat[][4]); +void BKE_armature_loc_world_to_pose(struct Object *ob, const float inloc[3], float outloc[3]); +void BKE_armature_mat_pose_to_bone(struct bPoseChannel *pchan, float inmat[][4], float outmat[][4]); +void BKE_armature_loc_pose_to_bone(struct bPoseChannel *pchan, const float inloc[3], float outloc[3]); +void BKE_armature_mat_bone_to_pose(struct bPoseChannel *pchan, float inmat[][4], float outmat[][4]); +void BKE_armature_mat_pose_to_delta(float delta_mat[][4], float pose_mat[][4], float arm_mat[][4]); -void armature_mat_pose_to_bone_ex(struct Object *ob, struct bPoseChannel *pchan, float inmat[][4], float outmat[][4]); +void BKE_armature_mat_pose_to_bone_ex(struct Object *ob, struct bPoseChannel *pchan, float inmat[][4], float outmat[][4]); -void pchan_mat3_to_rot(struct bPoseChannel *pchan, float mat[][3], short use_compat); -void pchan_apply_mat4(struct bPoseChannel *pchan, float mat[][4], short use_comat); -void pchan_to_mat4(struct bPoseChannel *pchan, float chan_mat[4][4]); -void pchan_calc_mat(struct bPoseChannel *pchan); +void BKE_pchan_mat3_to_rot(struct bPoseChannel *pchan, float mat[][3], short use_compat); +void BKE_pchan_apply_mat4(struct bPoseChannel *pchan, float mat[][4], short use_comat); +void BKE_pchan_to_mat4(struct bPoseChannel *pchan, float chan_mat[4][4]); +void BKE_pchan_calc_mat(struct bPoseChannel *pchan); /* Get the "pchan to pose" transform matrix. These matrices apply the effects of * HINGE/NO_SCALE/NO_LOCAL_LOCATION options over the pchan loc/rot/scale transformations. */ -void pchan_to_pose_mat(struct bPoseChannel *pchan, float rotscale_mat[][4], float loc_mat[][4]); +void BKE_pchan_to_pose_mat(struct bPoseChannel *pchan, float rotscale_mat[][4], float loc_mat[][4]); /* Rotation Mode Conversions - Used for PoseChannels + Objects... */ void BKE_rotMode_change_values(float quat[4], float eul[3], float axis[3], float *angle, short oldMode, short newMode); diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index 62f1dbc5867..29e02562be3 100644 --- a/source/blender/blenkernel/BKE_blender.h +++ b/source/blender/blenkernel/BKE_blender.h @@ -42,7 +42,7 @@ extern "C" { * and keep comment above the defines. * Use STRINGIFY() rather than defining with quotes */ #define BLENDER_VERSION 263 -#define BLENDER_SUBVERSION 4 +#define BLENDER_SUBVERSION 5 #define BLENDER_MINVERSION 250 #define BLENDER_MINSUBVERSION 0 diff --git a/source/blender/blenkernel/BKE_ccg.h b/source/blender/blenkernel/BKE_ccg.h new file mode 100644 index 00000000000..079994450d5 --- /dev/null +++ b/source/blender/blenkernel/BKE_ccg.h @@ -0,0 +1,168 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 by Nicholas Bishop. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BKE_CCG_H__ +#define __BKE_CCG_H__ + +/* defines BLI_INLINE */ +#include "BLI_utildefines.h" + +/* declares fprintf() and abort(), needed for BLI_assert */ +#include <stdio.h> +#include <stdlib.h> + +struct CCGSubSurf; + +/* Each CCGElem is CCGSubSurf's representation of a subdivided + vertex. All CCGElems in a particular CCGSubSurf have the same + layout, but the layout can vary from one CCGSubSurf to another. For + this reason, CCGElem is presented as an opaque pointer, and + elements should always be accompanied by a CCGKey, which provides + the necessary offsets to access components of a CCGElem. +*/ +typedef struct CCGElem CCGElem; + +typedef struct CCGKey { + int level; + + /* number of bytes in each element (one float per layer, plus + three floats for normals if enabled) */ + int elem_size; + + /* number of elements along each side of grid */ + int grid_size; + /* number of elements in the grid (grid size squared) */ + int grid_area; + /* number of bytes in each grid (grid_area * elem_size) */ + int grid_bytes; + + /* currently always the last three floats, unless normals are + disabled */ + int normal_offset; + + /* offset in bytes of mask value; only valid if 'has_mask' is + true */ + int mask_offset; + + int num_layers; + int has_normals; + int has_mask; +} CCGKey; + +/* initialize 'key' at the specified level */ +void CCG_key(CCGKey *key, const struct CCGSubSurf *ss, int level); +void CCG_key_top_level(CCGKey *key, const struct CCGSubSurf *ss); + +/* get a pointer to the coordinate, normal, or mask components */ +BLI_INLINE float *CCG_elem_co(const CCGKey *key, CCGElem *elem); +BLI_INLINE float *CCG_elem_no(const CCGKey *key, CCGElem *elem); +BLI_INLINE float *CCG_elem_mask(const CCGKey *key, CCGElem *elem); + +/* get the element at 'offset' in an array */ +BLI_INLINE CCGElem *CCG_elem_offset(const CCGKey *key, CCGElem *elem, int offset); + +/* get the element at coordinate (x,y) in a face-grid array */ +BLI_INLINE CCGElem *CCG_grid_elem(const CCGKey *key, CCGElem *elem, int x, int y); + +/* combinations of above functions */ +BLI_INLINE float *CCG_grid_elem_co(const CCGKey *key, CCGElem *elem, int x, int y); +BLI_INLINE float *CCG_grid_elem_no(const CCGKey *key, CCGElem *elem, int x, int y); +BLI_INLINE float *CCG_grid_elem_mask(const CCGKey *key, CCGElem *elem, int x, int y); +BLI_INLINE float *CCG_elem_offset_co(const CCGKey *key, CCGElem *elem, int offset); +BLI_INLINE float *CCG_elem_offset_no(const CCGKey *key, CCGElem *elem, int offset); +BLI_INLINE float *CCG_elem_offset_mask(const CCGKey *key, CCGElem *elem, int offset); + +/* for iteration, get a pointer to the next element in an array */ +BLI_INLINE CCGElem *CCG_elem_next(const CCGKey *key, CCGElem *elem); + + +/* inline definitions follow */ + +BLI_INLINE float *CCG_elem_co(const CCGKey *UNUSED(key), CCGElem *elem) +{ + return (float*)elem; +} + +BLI_INLINE float *CCG_elem_no(const CCGKey *key, CCGElem *elem) +{ + BLI_assert(key->has_normals); + return (float*)((char*)elem + key->normal_offset); +} + +BLI_INLINE float *CCG_elem_mask(const CCGKey *key, CCGElem *elem) +{ + BLI_assert(key->has_mask); + return (float*)((char*)elem + (key->mask_offset)); +} + +BLI_INLINE CCGElem *CCG_elem_offset(const CCGKey *key, CCGElem *elem, int offset) +{ + return (CCGElem*)(((char*)elem) + key->elem_size * offset); +} + +BLI_INLINE CCGElem *CCG_grid_elem(const CCGKey *key, CCGElem *elem, int x, int y) +{ + BLI_assert(x < key->grid_size && y < key->grid_size); + return CCG_elem_offset(key, elem, (y * key->grid_size + x)); +} + +BLI_INLINE float *CCG_grid_elem_co(const CCGKey *key, CCGElem *elem, int x, int y) +{ + return CCG_elem_co(key, CCG_grid_elem(key, elem, x, y)); +} + +BLI_INLINE float *CCG_grid_elem_no(const CCGKey *key, CCGElem *elem, int x, int y) +{ + return CCG_elem_no(key, CCG_grid_elem(key, elem, x, y)); +} + +BLI_INLINE float *CCG_grid_elem_mask(const CCGKey *key, CCGElem *elem, int x, int y) +{ + return CCG_elem_mask(key, CCG_grid_elem(key, elem, x, y)); +} + +BLI_INLINE float *CCG_elem_offset_co(const CCGKey *key, CCGElem *elem, int offset) +{ + return CCG_elem_co(key, CCG_elem_offset(key, elem, offset)); +} + +BLI_INLINE float *CCG_elem_offset_no(const CCGKey *key, CCGElem *elem, int offset) +{ + return CCG_elem_no(key, CCG_elem_offset(key, elem, offset)); +} + +BLI_INLINE float *CCG_elem_offset_mask(const CCGKey *key, CCGElem *elem, int offset) +{ + return CCG_elem_mask(key, CCG_elem_offset(key, elem, offset)); +} + +BLI_INLINE CCGElem *CCG_elem_next(const CCGKey *key, CCGElem *elem) +{ + return CCG_elem_offset(key, elem, 1); +} + +#endif diff --git a/source/blender/blenkernel/BKE_constraint.h b/source/blender/blenkernel/BKE_constraint.h index f834ad5e774..35d07e7a7a7 100644 --- a/source/blender/blenkernel/BKE_constraint.h +++ b/source/blender/blenkernel/BKE_constraint.h @@ -62,7 +62,7 @@ typedef struct bConstraintOb { /* ---------------------------------------------------------------------------- */ /* Callback format for performing operations on ID-pointers for Constraints */ -typedef void (*ConstraintIDFunc)(struct bConstraint *con, struct ID **idpoin, void *userdata); +typedef void (*ConstraintIDFunc)(struct bConstraint *con, struct ID **idpoin, short isReference, void *userdata); /* ....... */ @@ -87,8 +87,6 @@ typedef struct bConstraintTypeInfo { /* data management function pointers - special handling */ /* free any data that is allocated separately (optional) */ void (*free_data)(struct bConstraint *con); - /* adjust pointer to other ID-data using ID_NEW(), but not to targets (optional) */ - void (*relink_data)(struct bConstraint *con); /* run the provided callback function on all the ID-blocks linked to the constraint */ void (*id_looper)(struct bConstraint *con, ConstraintIDFunc func, void *userdata); /* copy any special data that is allocated separately (optional) */ diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h index 3b9328ae1aa..6267104022c 100644 --- a/source/blender/blenkernel/BKE_curve.h +++ b/source/blender/blenkernel/BKE_curve.h @@ -63,7 +63,7 @@ void BKE_curve_make_local(struct Curve *cu); short BKE_curve_type_get(struct Curve *cu); void BKE_curve_type_test(struct Object *ob); void BKE_curve_curve_dimension_update(struct Curve *cu); -void BKE_curve_tex_space_calc(struct Curve *cu); +void BKE_curve_texspace_calc(struct Curve *cu); int BKE_curve_minmax(struct Curve *cu, float min[3], float max[3]); int BKE_curve_center_median(struct Curve *cu, float cent[3]); diff --git a/source/blender/blenkernel/BKE_displist.h b/source/blender/blenkernel/BKE_displist.h index c5684e83903..cb8ddbf0b00 100644 --- a/source/blender/blenkernel/BKE_displist.h +++ b/source/blender/blenkernel/BKE_displist.h @@ -78,29 +78,28 @@ typedef struct DispList { unsigned int *bevelSplitFlag; } DispList; -extern void copy_displist(struct ListBase *lbn, struct ListBase *lb); -extern void free_disp_elem(DispList *dl); -extern DispList *find_displist_create(struct ListBase *lb, int type); -extern DispList *find_displist(struct ListBase *lb, int type); -extern void addnormalsDispList(struct ListBase *lb); -extern void count_displist(struct ListBase *lb, int *totvert, int *totface); -extern void freedisplist(struct ListBase *lb); -extern int displist_has_faces(struct ListBase *lb); - -extern void makeDispListSurf(struct Scene *scene, struct Object *ob, struct ListBase *dispbase, struct DerivedMesh **derivedFinal, int forRender, int forOrco); -extern void makeDispListCurveTypes(struct Scene *scene, struct Object *ob, int forOrco); -extern void makeDispListCurveTypes_forRender(struct Scene *scene, struct Object *ob, struct ListBase *dispbase, struct DerivedMesh **derivedFinal, int forOrco); -extern void makeDispListCurveTypes_forOrco(struct Scene *scene, struct Object *ob, struct ListBase *dispbase); -extern void makeDispListMBall(struct Scene *scene, struct Object *ob); -extern void makeDispListMBall_forRender(struct Scene *scene, struct Object *ob, struct ListBase *dispbase); - -int surfindex_displist(DispList *dl, int a, int *b, int *p1, int *p2, int *p3, int *p4); -void filldisplist(struct ListBase *dispbase, struct ListBase *to, int flipnormal); - -float calc_taper(struct Scene *scene, struct Object *taperobj, int cur, int tot); +void BKE_displist_copy(struct ListBase *lbn, struct ListBase *lb); +void BKE_displist_elem_free(DispList *dl); +DispList *BKE_displist_find_or_create(struct ListBase *lb, int type); +DispList *BKE_displist_find(struct ListBase *lb, int type); +void BKE_displist_normals_add(struct ListBase *lb); +void BKE_displist_count(struct ListBase *lb, int *totvert, int *totface); +void BKE_displist_free(struct ListBase *lb); +int BKE_displist_has_faces(struct ListBase *lb); + +void BKE_displist_make_surf(struct Scene *scene, struct Object *ob, struct ListBase *dispbase, struct DerivedMesh **derivedFinal, int forRender, int forOrco); +void BKE_displist_make_curveTypes(struct Scene *scene, struct Object *ob, int forOrco); +void BKE_displist_make_curveTypes_forRender(struct Scene *scene, struct Object *ob, struct ListBase *dispbase, struct DerivedMesh **derivedFinal, int forOrco); +void BKE_displist_make_curveTypes_forOrco(struct Scene *scene, struct Object *ob, struct ListBase *dispbase); +void BKE_displist_make_mball(struct Scene *scene, struct Object *ob); +void BKE_displist_make_mball_forRender(struct Scene *scene, struct Object *ob, struct ListBase *dispbase); + +int BKE_displist_surfindex_get(DispList *dl, int a, int *b, int *p1, int *p2, int *p3, int *p4); +void BKE_displist_fill(struct ListBase *dispbase, struct ListBase *to, int flipnormal); + +float BKE_displist_calc_taper(struct Scene *scene, struct Object *taperobj, int cur, int tot); /* add Orco layer to the displist object which has got derived mesh and return orco */ -float *makeOrcoDispList(struct Scene *scene, struct Object *ob, struct DerivedMesh *derivedFinal, int forRender); +float *BKE_displist_make_orco(struct Scene *scene, struct Object *ob, struct DerivedMesh *derivedFinal, int forRender); #endif - diff --git a/source/blender/blenkernel/BKE_font.h b/source/blender/blenkernel/BKE_font.h index 16e98f25e0c..6636a70e94d 100644 --- a/source/blender/blenkernel/BKE_font.h +++ b/source/blender/blenkernel/BKE_font.h @@ -71,17 +71,17 @@ typedef struct EditFont { } EditFont; -void BKE_font_register_builtin(void *mem, int size); +void BKE_vfont_builtin_register(void *mem, int size); -void free_vfont(struct VFont *sc); -void free_ttfont(void); -struct VFont *get_builtin_font(void); -struct VFont *load_vfont(struct Main *bmain, const char *name); -struct TmpFont *vfont_find_tmpfont(struct VFont *vfont); +void BKE_vfont_free(struct VFont *sc); +void BKE_vfont_free_global_ttf(void); +struct VFont *BKE_vfont_builtin_get(void); +struct VFont *BKE_vfont_load(struct Main *bmain, const char *name); +struct TmpFont *BKE_vfont_find_tmpfont(struct VFont *vfont); -struct chartrans *BKE_text_to_curve(struct Main *bmain, struct Scene *scene, struct Object *ob, int mode); +struct chartrans *BKE_vfont_to_curve(struct Main *bmain, struct Scene *scene, struct Object *ob, int mode); -int BKE_font_getselection(struct Object *ob, int *start, int *end); +int BKE_vfont_select_get(struct Object *ob, int *start, int *end); #ifdef __cplusplus } diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h index bb0216fe11c..134ec1acd8e 100644 --- a/source/blender/blenkernel/BKE_gpencil.h +++ b/source/blender/blenkernel/BKE_gpencil.h @@ -41,7 +41,7 @@ struct bGPDframe; void free_gpencil_strokes(struct bGPDframe *gpf); void free_gpencil_frames(struct bGPDlayer *gpl); void free_gpencil_layers(struct ListBase *list); -void free_gpencil_data(struct bGPdata *gpd); +void BKE_gpencil_free(struct bGPdata *gpd); struct bGPDframe *gpencil_frame_addnew(struct bGPDlayer *gpl, int cframe); struct bGPDlayer *gpencil_layer_addnew(struct bGPdata *gpd); diff --git a/source/blender/blenkernel/BKE_group.h b/source/blender/blenkernel/BKE_group.h index 6629f0bdf7f..ccf9e0cef5b 100644 --- a/source/blender/blenkernel/BKE_group.h +++ b/source/blender/blenkernel/BKE_group.h @@ -40,10 +40,10 @@ struct Object; struct bAction; struct Scene; -void free_group_objects(struct Group *group); -void unlink_group(struct Group *group); +void BKE_group_free(struct Group *group); +void BKE_group_unlink(struct Group *group); struct Group *add_group(const char *name); -struct Group *copy_group(struct Group *group); +struct Group *BKE_group_copy(struct Group *group); int add_to_group(struct Group *group, struct Object *ob, struct Scene *scene, struct Base *base); int rem_from_group(struct Group *group, struct Object *ob, struct Scene *scene, struct Base *base); struct Group *find_group(struct Object *ob, struct Group *group); diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index c2112d1e169..563f066bda6 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -46,14 +46,14 @@ struct Object; struct ImageFormatData; /* call from library */ -void free_image(struct Image *me); +void BKE_image_free(struct Image *me); -void BKE_stamp_info(struct Scene *scene, struct Object *camera, struct ImBuf *ibuf); +void BKE_imbuf_stamp_info(struct Scene *scene, struct Object *camera, struct ImBuf *ibuf); void BKE_stamp_buf(struct Scene *scene, struct Object *camera, unsigned char *rect, float *rectf, int width, int height, int channels); -int BKE_alphatest_ibuf(struct ImBuf *ibuf); -int BKE_write_ibuf_stamp(struct Scene *scene, struct Object *camera, struct ImBuf *ibuf, const char *name, struct ImageFormatData *imf); -int BKE_write_ibuf(struct ImBuf *ibuf, const char *name, struct ImageFormatData *imf); -int BKE_write_ibuf_as(struct ImBuf *ibuf, const char *name, struct ImageFormatData *imf, const short is_copy); +int BKE_imbuf_alpha_test(struct ImBuf *ibuf); +int BKE_imbuf_write_stamp(struct Scene *scene, struct Object *camera, struct ImBuf *ibuf, const char *name, struct ImageFormatData *imf); +int BKE_imbuf_write(struct ImBuf *ibuf, const char *name, struct ImageFormatData *imf); +int BKE_imbuf_write_as(struct ImBuf *ibuf, const char *name, struct ImageFormatData *imf, const short is_copy); void BKE_makepicstring(char *string, const char *base, const char *relbase, int frame, const char imtype, const short use_ext, const short use_frames); int BKE_add_image_extension(char *string, const char imtype); char BKE_ftype_to_imtype(const int ftype); @@ -72,11 +72,11 @@ void BKE_imformat_defaults(struct ImageFormatData *im_format); struct anim *openanim(const char *name, int flags, int streamindex); -void image_de_interlace(struct Image *ima, int odd); +void BKE_image_de_interlace(struct Image *ima, int odd); -void make_local_image(struct Image *ima); +void BKE_image_make_local(struct Image *ima); -void tag_image_time(struct Image *ima); +void BKE_image_tag_time(struct Image *ima); void free_old_images(void); /* ********************************** NEW IMAGE API *********************** */ @@ -130,13 +130,15 @@ struct ImBuf *BKE_image_get_ibuf(struct Image *ima, struct ImageUser *iuser); struct ImBuf *BKE_image_acquire_ibuf(struct Image *ima, struct ImageUser *iuser, void **lock_r); void BKE_image_release_ibuf(struct Image *ima, void *lock); +/* returns a new image or NULL if it can't load */ +struct Image *BKE_image_load(const char *filepath); /* returns existing Image when filename/type is same (frame optional) */ -struct Image *BKE_add_image_file(const char *name); +struct Image *BKE_image_load_exists(const char *filepath); /* adds image, adds ibuf, generates color or pattern */ -struct Image *BKE_add_image_size(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short uvtestgrid, float color[4]); +struct Image *BKE_image_add_generated(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short uvtestgrid, float color[4]); /* adds image from imbuf, owns imbuf */ -struct Image *BKE_add_image_imbuf(struct ImBuf *ibuf); +struct Image *BKE_image_add_from_imbuf(struct ImBuf *ibuf); /* for reload, refresh, pack */ void BKE_image_signal(struct Image *ima, struct ImageUser *iuser, int signal); @@ -148,8 +150,8 @@ struct Image *BKE_image_verify_viewer(int type, const char *name); void BKE_image_assign_ibuf(struct Image *ima, struct ImBuf *ibuf); /* called on frame change or before render */ -void BKE_image_user_calc_frame(struct ImageUser *iuser, int cfra, int fieldnr); -int BKE_image_user_get_frame(const struct ImageUser *iuser, int cfra, int fieldnr); +void BKE_image_user_frame_calc(struct ImageUser *iuser, int cfra, int fieldnr); +int BKE_image_user_frame_get(const struct ImageUser *iuser, int cfra, int fieldnr); /* sets index offset for multilayer files */ struct RenderPass *BKE_image_multilayer_index(struct RenderResult *rr, struct ImageUser *iuser); @@ -176,7 +178,7 @@ void BKE_image_memorypack(struct Image *ima); void BKE_image_print_memlist(void); /* empty image block, of similar type and filename */ -struct Image *copy_image(struct Image *ima); +struct Image *BKE_image_copy(struct Image *ima); /* merge source into dest, and free source */ void BKE_image_merge(struct Image *dest, struct Image *source); diff --git a/source/blender/blenkernel/BKE_ipo.h b/source/blender/blenkernel/BKE_ipo.h index 547e7de7634..ca86e90f192 100644 --- a/source/blender/blenkernel/BKE_ipo.h +++ b/source/blender/blenkernel/BKE_ipo.h @@ -45,7 +45,7 @@ void do_versions_ipos_to_animato(struct Main *main); /* --------------------- xxx stuff ------------------------ */ -void free_ipo(struct Ipo *ipo); +void BKE_ipo_free(struct Ipo *ipo); #ifdef __cplusplus }; diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h index 63d9d731097..757952515e5 100644 --- a/source/blender/blenkernel/BKE_key.h +++ b/source/blender/blenkernel/BKE_key.h @@ -47,12 +47,12 @@ struct Mesh; extern "C" { #endif -void free_key(struct Key *sc); +void BKE_key_free(struct Key *sc); void free_key_nolib(struct Key *key); struct Key *add_key(struct ID *id); -struct Key *copy_key(struct Key *key); +struct Key *BKE_key_copy(struct Key *key); struct Key *copy_key_nolib(struct Key *key); -void make_local_key(struct Key *key); +void BKE_key_make_local(struct Key *key); void sort_keys(struct Key *key); void key_curve_position_weights(float t, float *data, int type); diff --git a/source/blender/blenkernel/BKE_lamp.h b/source/blender/blenkernel/BKE_lamp.h index 50e25576320..f9137e50d74 100644 --- a/source/blender/blenkernel/BKE_lamp.h +++ b/source/blender/blenkernel/BKE_lamp.h @@ -38,11 +38,11 @@ extern "C" { struct Lamp; -void *add_lamp(const char *name); -struct Lamp *copy_lamp(struct Lamp *la); +void *BKE_lamp_add(const char *name); +struct Lamp *BKE_lamp_copy(struct Lamp *la); struct Lamp *localize_lamp(struct Lamp *la); -void make_local_lamp(struct Lamp *la); -void free_lamp(struct Lamp *la); +void BKE_lamp_make_local(struct Lamp *la); +void BKE_lamp_free(struct Lamp *la); #ifdef __cplusplus } diff --git a/source/blender/blenkernel/BKE_lattice.h b/source/blender/blenkernel/BKE_lattice.h index a0075c4d6be..9a952fc6b1e 100644 --- a/source/blender/blenkernel/BKE_lattice.h +++ b/source/blender/blenkernel/BKE_lattice.h @@ -41,11 +41,11 @@ struct DerivedMesh; struct BPoint; struct MDeformVert; -void resizelattice(struct Lattice *lt, int u, int v, int w, struct Object *ltOb); -struct Lattice *add_lattice(const char *name); -struct Lattice *copy_lattice(struct Lattice *lt); -void free_lattice(struct Lattice *lt); -void make_local_lattice(struct Lattice *lt); +void BKE_lattice_resize(struct Lattice *lt, int u, int v, int w, struct Object *ltOb); +struct Lattice *BKE_lattice_add(const char *name); +struct Lattice *BKE_lattice_copy(struct Lattice *lt); +void BKE_lattice_free(struct Lattice *lt); +void BKE_lattice_make_local(struct Lattice *lt); void calc_lat_fudu(int flag, int res, float *fu, float *du); void init_latt_deform(struct Object *oblatt, struct Object *ob); @@ -69,11 +69,11 @@ void armature_deform_verts(struct Object *armOb, struct Object *target, float (*defMats)[3][3], int numVerts, int deformflag, float (*prevCos)[3], const char *defgrp_name); -float (*lattice_getVertexCos(struct Object *ob, int *numVerts_r))[3]; -void lattice_applyVertexCos(struct Object *ob, float (*vertexCos)[3]); -void lattice_calc_modifiers(struct Scene *scene, struct Object *ob); +float (*BKE_lattice_vertexcos_get(struct Object *ob, int *numVerts_r))[3]; +void BKE_lattice_vertexcos_apply(struct Object *ob, float (*vertexCos)[3]); +void BKE_lattice_modifiers_calc(struct Scene *scene, struct Object *ob); -struct MDeformVert* lattice_get_deform_verts(struct Object *lattice); +struct MDeformVert* BKE_lattice_deform_verts_get(struct Object *lattice); #endif diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index be21996428a..2804eb407db 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -45,15 +45,16 @@ struct bContext; struct PointerRNA; struct PropertyRNA; -void *alloc_libblock(struct ListBase *lb, short type, const char *name); -void *copy_libblock(struct ID *id); -void copy_libblock_data(struct ID *id, const struct ID *id_from, const short do_action); +void *BKE_libblock_alloc(struct ListBase *lb, short type, const char *name); +void *BKE_libblock_copy(struct ID *id); +void BKE_libblock_copy_data(struct ID *id, const struct ID *id_from, const short do_action); void BKE_id_lib_local_paths(struct Main *bmain, struct Library *lib, struct ID *id); void id_lib_extern(struct ID *id); void BKE_library_filepath_set(struct Library *lib, const char *filepath); void id_us_plus(struct ID *id); void id_us_min(struct ID *id); + int id_make_local(struct ID *id, int test); int id_single_user(struct bContext *C, struct ID *id, struct PointerRNA *ptr, struct PropertyRNA *prop); int id_copy(struct ID *id, struct ID **newid, int test); @@ -68,8 +69,8 @@ struct ListBase *which_libbase(struct Main *mainlib, short type); #define MAX_LIBARRAY 40 int set_listbasepointers(struct Main *main, struct ListBase **lb); -void free_libblock(struct ListBase *lb, void *idv); -void free_libblock_us(struct ListBase *lb, void *idv); +void BKE_libblock_free(struct ListBase *lb, void *idv); +void BKE_libblock_free_us(struct ListBase *lb, void *idv); void free_main(struct Main *mainvar); void tag_main_idcode(struct Main *mainvar, const short type, const short tag); @@ -81,7 +82,7 @@ void name_uiprefix_id(char *name, struct ID *id); void test_idbutton(char *name); void text_idbutton(struct ID *id, char *text); void BKE_library_make_local(struct Main *bmain, struct Library *lib, int untagged_only); -struct ID *find_id(const char *type, const char *name); +struct ID *BKE_libblock_find_name(const short type, const char *name); void clear_id_newpoins(void); void IDnames_to_pupstring(const char **str, const char *title, const char *extraops, diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h index 99561a687b9..801724d1d4f 100644 --- a/source/blender/blenkernel/BKE_material.h +++ b/source/blender/blenkernel/BKE_material.h @@ -46,15 +46,15 @@ struct MTFace; /* materials */ void init_def_material(void); -void free_material(struct Material *sc); +void BKE_material_free(struct Material *sc); void test_object_materials(struct ID *id); void resize_object_material(struct Object *ob, const short totcol); void init_material(struct Material *ma); -struct Material *add_material(const char *name); -struct Material *copy_material(struct Material *ma); +struct Material *BKE_material_add(const char *name); +struct Material *BKE_material_copy(struct Material *ma); struct Material *localize_material(struct Material *ma); struct Material *give_node_material(struct Material *ma); /* returns node material or self */ -void make_local_material(struct Material *ma); +void BKE_material_make_local(struct Material *ma); void extern_local_matarar(struct Material **matar, short totcol); void automatname(struct Material *); diff --git a/source/blender/blenkernel/BKE_mball.h b/source/blender/blenkernel/BKE_mball.h index 018ee7f6c94..356f2c8901c 100644 --- a/source/blender/blenkernel/BKE_mball.h +++ b/source/blender/blenkernel/BKE_mball.h @@ -37,30 +37,30 @@ struct Object; struct Scene; struct MetaElem; -void BKE_metaball_unlink(struct MetaBall *mb); -void BKE_metaball_free(struct MetaBall *mb); -struct MetaBall *BKE_metaball_add(const char *name); -struct MetaBall *BKE_metaball_copy(struct MetaBall *mb); +void BKE_mball_unlink(struct MetaBall *mb); +void BKE_mball_free(struct MetaBall *mb); +struct MetaBall *BKE_mball_add(const char *name); +struct MetaBall *BKE_mball_copy(struct MetaBall *mb); -void BKE_metaball_make_local(struct MetaBall *mb); +void BKE_mball_make_local(struct MetaBall *mb); -void BKE_metaball_cubeTable_free(void); +void BKE_mball_cubeTable_free(void); -void BKE_metaball_polygonize(struct Scene *scene, struct Object *ob, struct ListBase *dispbase); -int BKE_metaball_is_basis_for(struct Object *ob1, struct Object *ob2); -int BKE_metaball_is_basis(struct Object *ob); -struct Object *BKE_metaball_basis_find(struct Scene *scene, struct Object *ob); +void BKE_mball_polygonize(struct Scene *scene, struct Object *ob, struct ListBase *dispbase); +int BKE_mball_is_basis_for(struct Object *ob1, struct Object *ob2); +int BKE_mball_is_basis(struct Object *ob); +struct Object *BKE_mball_basis_find(struct Scene *scene, struct Object *ob); -void BKE_metaball_tex_space_calc(struct Object *ob); -float *BKE_metaball_make_orco(struct Object *ob, struct ListBase *dispbase); +void BKE_mball_texspace_calc(struct Object *ob); +float *BKE_mball_make_orco(struct Object *ob, struct ListBase *dispbase); -void BKE_metaball_properties_copy(struct Scene *scene, struct Object *active_object); +void BKE_mball_properties_copy(struct Scene *scene, struct Object *active_object); -int BKE_metaball_minmax(struct MetaBall *mb, float min[3], float max[3]); -int BKE_metaball_center_median(struct MetaBall *mb, float cent[3]); -int BKE_metaball_center_bounds(struct MetaBall *mb, float cent[3]); -void BKE_metaball_translate(struct MetaBall *mb, float offset[3]); +int BKE_mball_minmax(struct MetaBall *mb, float min[3], float max[3]); +int BKE_mball_center_median(struct MetaBall *mb, float cent[3]); +int BKE_mball_center_bounds(struct MetaBall *mb, float cent[3]); +void BKE_mball_translate(struct MetaBall *mb, float offset[3]); -struct MetaElem *BKE_metaball_element_add(struct MetaBall *mb, const int type); +struct MetaElem *BKE_mball_element_add(struct MetaBall *mb, const int type); #endif diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 14cb5d19ddf..bdadce2c7c7 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -76,109 +76,109 @@ struct BMesh *BKE_mesh_to_bmesh(struct Mesh *me, struct Object *ob); * if both of the above are 0, it'll use the indices of the mpolys of the MPoly * data in pdata, and ignore the origindex layer altogether. */ -int mesh_recalcTessellation(struct CustomData *fdata, struct CustomData *ldata, struct CustomData *pdata, - struct MVert *mvert, - int totface, int totloop, int totpoly, - const int do_face_normals); +int BKE_mesh_recalc_tessellation(struct CustomData *fdata, struct CustomData *ldata, struct CustomData *pdata, + struct MVert *mvert, + int totface, int totloop, int totpoly, + const int do_face_normals); /* for forwards compat only quad->tri polys to mface, skip ngons. */ -int mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata, - struct CustomData *pdata, int totface, int totloop, int totpoly); +int BKE_mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata, + struct CustomData *pdata, int totface, int totloop, int totpoly); /*calculates a face normal.*/ void mesh_calc_poly_normal(struct MPoly *mpoly, struct MLoop *loopstart, struct MVert *mvarray, float no[3]); -void mesh_calc_poly_normal_coords(struct MPoly *mpoly, struct MLoop *loopstart, - const float (*vertex_coords)[3], float no[3]); +void BKE_mesh_calc_poly_normal_coords(struct MPoly *mpoly, struct MLoop *loopstart, + const float (*vertex_coords)[3], float no[3]); -void mesh_calc_poly_center(struct MPoly *mpoly, struct MLoop *loopstart, - struct MVert *mvarray, float cent[3]); +void BKE_mesh_calc_poly_center(struct MPoly *mpoly, struct MLoop *loopstart, + struct MVert *mvarray, float cent[3]); -float mesh_calc_poly_area(struct MPoly *mpoly, struct MLoop *loopstart, - struct MVert *mvarray, float polynormal[3]); +float BKE_mesh_calc_poly_area(struct MPoly *mpoly, struct MLoop *loopstart, + struct MVert *mvarray, float polynormal[3]); /* Find the index of the loop in 'poly' which references vertex, * returns -1 if not found */ int poly_find_loop_from_vert(const struct MPoly *poly, - const struct MLoop *loopstart, - unsigned vert); + const struct MLoop *loopstart, + unsigned vert); /* Fill 'adj_r' with the loop indices in 'poly' adjacent to the * vertex. Returns the index of the loop matching vertex, or -1 if the * vertex is not in 'poly' */ int poly_get_adj_loops_from_vert(unsigned adj_r[3], const struct MPoly *poly, - const struct MLoop *mloop, unsigned vert); + const struct MLoop *mloop, unsigned vert); /* update the hide flag for edges and polys from the corresponding * flag in verts */ -void mesh_flush_hidden_from_verts(const struct MVert *mvert, - const struct MLoop *mloop, - struct MEdge *medge, int totedge, - struct MPoly *mpoly, int totpoly); - -void unlink_mesh(struct Mesh *me); -void free_mesh(struct Mesh *me, int unlink); -struct Mesh *add_mesh(const char *name); -struct Mesh *copy_mesh(struct Mesh *me); +void BKE_mesh_flush_hidden_from_verts(const struct MVert *mvert, + const struct MLoop *mloop, + struct MEdge *medge, int totedge, + struct MPoly *mpoly, int totpoly); + +void BKE_mesh_unlink(struct Mesh *me); +void BKE_mesh_free(struct Mesh *me, int unlink); +struct Mesh *BKE_mesh_add(const char *name); +struct Mesh *BKE_mesh_copy(struct Mesh *me); void mesh_update_customdata_pointers(struct Mesh *me, const short do_ensure_tess_cd); -void make_local_mesh(struct Mesh *me); -void boundbox_mesh(struct Mesh *me, float *loc, float *size); -void tex_space_mesh(struct Mesh *me); -float *get_mesh_orco_verts(struct Object *ob); -void transform_mesh_orco_verts(struct Mesh *me, float (*orco)[3], int totvert, int invert); +void BKE_mesh_make_local(struct Mesh *me); +void BKE_mesh_boundbox_calc(struct Mesh *me, float *loc, float *size); +void BKE_mesh_texspace_calc(struct Mesh *me); +float *BKE_mesh_orco_verts_get(struct Object *ob); +void BKE_mesh_orco_verts_transform(struct Mesh *me, float (*orco)[3], int totvert, int invert); int test_index_face(struct MFace *mface, struct CustomData *mfdata, int mfindex, int nr); -struct Mesh *get_mesh(struct Object *ob); +struct Mesh *BKE_mesh_from_object(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 MLoop **allloop, struct MPoly **allpoly, - 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 MLoop **allloop, struct MPoly **allpoly, - int *_totloop, int *_totpoly); -void nurbs_to_mesh(struct Object *ob); -void mesh_to_curve(struct Scene *scene, struct Object *ob); +void BKE_mesh_from_metaball(struct ListBase *lb, struct Mesh *me); +int BKE_mesh_nurbs_to_mdata(struct Object *ob, struct MVert **allvert, int *totvert, + struct MEdge **alledge, int *totedge, struct MLoop **allloop, struct MPoly **allpoly, + int *totloop, int *totpoly); +int BKE_mesh_nurbs_to_mdata_customdb(struct Object *ob, struct ListBase *dispbase, struct MVert **allvert, int *_totvert, + struct MEdge **alledge, int *_totedge, struct MLoop **allloop, struct MPoly **allpoly, + int *_totloop, int *_totpoly); +void BKE_mesh_from_nurbs(struct Object *ob); +void BKE_mesh_from_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, short index); -void mesh_set_smooth_flag(struct Object *meshOb, int enableSmooth); +void BKE_mesh_delete_material_index(struct Mesh *me, short index); +void BKE_mesh_smooth_flag_set(struct Object *meshOb, int enableSmooth); void BKE_mesh_convert_mfaces_to_mpolys(struct Mesh *mesh); -void mesh_calc_normals_tessface(struct MVert *mverts, int numVerts, struct MFace *mfaces, int numFaces, float (*faceNors_r)[3]); +void BKE_mesh_calc_normals_tessface(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 * testing framework I get RNA work done, will use hackish * testing code for now.*/ -const char *mesh_cmp(struct Mesh *me1, struct Mesh *me2, float thresh); +const char *BKE_mesh_cmp(struct Mesh *me1, struct Mesh *me2, float thresh); -struct BoundBox *mesh_get_bb(struct Object *ob); -void mesh_get_texspace(struct Mesh *me, float r_loc[3], float r_rot[3], float r_size[3]); +struct BoundBox *BKE_mesh_boundbox_get(struct Object *ob); +void BKE_mesh_texspace_get(struct Mesh *me, float r_loc[3], float r_rot[3], float r_size[3]); /* if old, it converts mface->edcode to edge drawflags */ -void make_edges(struct Mesh *me, int old); +void BKE_mesh_make_edges(struct Mesh *me, int old); -void mesh_strip_loose_faces(struct Mesh *me); /* Needed for compatibility (some old read code). */ -void mesh_strip_loose_polysloops(struct Mesh *me); -void mesh_strip_loose_edges(struct Mesh *me); +void BKE_mesh_strip_loose_faces(struct Mesh *me); /* Needed for compatibility (some old read code). */ +void BKE_mesh_strip_loose_polysloops(struct Mesh *me); +void BKE_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_mapping( +void BKE_mesh_calc_normals_mapping( 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]); - /* extended version of 'mesh_calc_normals' with option not to calc vertex normals */ -void mesh_calc_normals_mapping_ex( + /* extended version of 'BKE_mesh_calc_normals' with option not to calc vertex normals */ +void BKE_mesh_calc_normals_mapping_ex( 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], const short only_face_normals); -void mesh_calc_normals( +void BKE_mesh_calc_normals( struct MVert *mverts, int numVerts, struct MLoop *mloop, struct MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3]); @@ -246,9 +246,10 @@ typedef struct UvElementMap { * to make that many islands, he can bite me :p */ #define INVALID_ISLAND 0xFFFF -UvVertMap *make_uv_vert_map(struct MPoly *mpoly, struct MLoop *mloop, struct MLoopUV *mloopuv, unsigned int totpoly, unsigned int totvert, int selected, float *limit); -UvMapVert *get_uv_map_vert(UvVertMap *vmap, unsigned int v); -void free_uv_vert_map(UvVertMap *vmap); +UvVertMap *BKE_mesh_uv_vert_map_make(struct MPoly *mpoly, struct MLoop *mloop, struct MLoopUV *mloopuv, + unsigned int totpoly, unsigned int totvert, int selected, float *limit); +UvMapVert *BKE_mesh_uv_vert_map_get_vert(UvVertMap *vmap, unsigned int v); +void BKE_mesh_uv_vert_map_free(UvVertMap *vmap); /* Connectivity data */ typedef struct MeshElemMap { @@ -270,10 +271,10 @@ void create_vert_edge_map(struct ListBase **map, IndexNode **mem, const struct M /* vertex level transformations & checks (no derived mesh) */ -int minmax_mesh(struct Mesh *me, float min[3], float max[3]); -int mesh_center_median(struct Mesh *me, float cent[3]); -int mesh_center_bounds(struct Mesh *me, float cent[3]); -void mesh_translate(struct Mesh *me, float offset[3], int do_keys); +int BKE_mesh_minmax(struct Mesh *me, float r_min[3], float r_max[3]); +int BKE_mesh_center_median(struct Mesh *me, float cent[3]); +int BKE_mesh_center_bounds(struct Mesh *me, float cent[3]); +void BKE_mesh_translate(struct Mesh *me, float offset[3], int do_keys); /* mesh_validate.c */ /* XXX Loop v/e are unsigned, so using max uint_32 value as invalid marker... */ @@ -298,10 +299,13 @@ void BKE_mesh_tessface_ensure(struct Mesh *mesh); void BKE_mesh_tessface_clear(struct Mesh *mesh); /* Convert a triangle or quadrangle of loop/poly data to tessface data */ -void mesh_loops_to_mface_corners(struct CustomData *fdata, struct CustomData *ldata, - struct CustomData *pdata, int lindex[4], int findex, - const int polyindex, const int mf_len, - const int numTex, const int numCol, const int hasPCol, const int hasOrigSpace); +void BKE_mesh_loops_to_mface_corners(struct CustomData *fdata, struct CustomData *ldata, + struct CustomData *pdata, int lindex[4], int findex, + const int polyindex, const int mf_len, + const int numTex, const int numCol, const int hasPCol, const int hasOrigSpace); + +void BKE_mesh_poly_calc_angles(struct MVert *mvert, struct MLoop *mloop, + struct MPoly *mp, float angles[]); #ifdef __cplusplus } diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h index b4320b7025a..db57d411f31 100644 --- a/source/blender/blenkernel/BKE_modifier.h +++ b/source/blender/blenkernel/BKE_modifier.h @@ -109,6 +109,12 @@ typedef void (*ObjectWalkFunc)(void *userData, struct Object *ob, struct Object typedef void (*IDWalkFunc)(void *userData, struct Object *ob, struct ID **idpoin); typedef void (*TexWalkFunc)(void *userData, struct Object *ob, struct ModifierData *md, const char *propname); +typedef enum ModifierApplyFlag { + MOD_APPLY_RENDER = 1 << 0, /* Render time. */ + MOD_APPLY_USECACHE = 1 << 1, /* Last modifier in stack. */ +} ModifierApplyFlag; + + typedef struct ModifierTypeInfo { /* The user visible name for this modifier */ char name[32]; @@ -142,7 +148,7 @@ typedef struct ModifierTypeInfo { void (*deformVerts)(struct ModifierData *md, struct Object *ob, struct DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, - int useRenderParams, int isFinalCalc); + ModifierApplyFlag flag); /* Like deformMatricesEM but called from object mode (for supporting modifiers in sculpt mode) */ void (*deformMatrices)( @@ -187,7 +193,7 @@ typedef struct ModifierTypeInfo { struct DerivedMesh *(*applyModifier)( struct ModifierData *md, struct Object *ob, struct DerivedMesh *derivedData, - int useRenderParams, int isFinalCalc); + ModifierApplyFlag flag); /* Like applyModifier but called during editmode (for supporting * modifiers). diff --git a/source/blender/blenkernel/BKE_multires.h b/source/blender/blenkernel/BKE_multires.h index bc34b0131bf..1ff53291044 100644 --- a/source/blender/blenkernel/BKE_multires.h +++ b/source/blender/blenkernel/BKE_multires.h @@ -44,7 +44,7 @@ struct MultiresModifierData; struct Object; struct Scene; -/* Delete mesh mdisps */ +/* Delete mesh mdisps and grid paint masks */ void multires_customdata_delete(struct Mesh *me); void multires_mark_as_modified(struct Object *ob, enum MultiresModifiedFlags flags); @@ -59,24 +59,32 @@ void multires_modifier_update_hidden(struct DerivedMesh *dm); void multiresModifier_set_levels_from_disps(struct MultiresModifierData *mmd, struct Object *ob); -struct DerivedMesh *multires_dm_create_from_derived(struct MultiresModifierData*, - int local_mmd, struct DerivedMesh*, struct Object *, int); +typedef enum { + MULTIRES_USE_LOCAL_MMD = 1, + MULTIRES_USE_RENDER_PARAMS = 2, + MULTIRES_ALLOC_PAINT_MASK = 4 +} MultiresFlags; + +struct DerivedMesh *multires_make_derived_from_derived(struct DerivedMesh *dm, + struct MultiresModifierData *mmd, + struct Object *ob, + MultiresFlags flags); struct MultiresModifierData *find_multires_modifier_before(struct Scene *scene, - struct ModifierData *lastmd); + struct ModifierData *lastmd); struct MultiresModifierData *get_multires_modifier(struct Scene *scene, struct Object *ob, int use_first); struct DerivedMesh *get_multires_dm(struct Scene *scene, struct MultiresModifierData *mmd, - struct Object *ob); + struct Object *ob); void multiresModifier_del_levels(struct MultiresModifierData *, struct Object *, int direction); void multiresModifier_base_apply(struct MultiresModifierData *mmd, struct Object *ob); void multiresModifier_subdivide(struct MultiresModifierData *mmd, struct Object *ob, - int updateblock, int simple); + int updateblock, int simple); int multiresModifier_reshape(struct Scene *scene, struct MultiresModifierData *mmd, - struct Object *dst, struct Object *src); + struct Object *dst, struct Object *src); int multiresModifier_reshapeFromDM(struct Scene *scene, struct MultiresModifierData *mmd, - struct Object *ob, struct DerivedMesh *srcdm); + struct Object *ob, struct DerivedMesh *srcdm); int multiresModifier_reshapeFromDeformMod(struct Scene *scene, struct MultiresModifierData *mmd, - struct Object *ob, struct ModifierData *md); + struct Object *ob, struct ModifierData *md); void multires_stitch_grids(struct Object *); diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index e7e1577c6b4..68b3e01b9ff 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -508,9 +508,10 @@ struct ShadeResult; #define SH_NODE_LAYER_WEIGHT 160 #define SH_NODE_VOLUME_TRANSPARENT 161 #define SH_NODE_VOLUME_ISOTROPIC 162 -#define SH_NODE_GAMMA 163 -#define SH_NODE_TEX_CHECKER 164 +#define SH_NODE_GAMMA 163 +#define SH_NODE_TEX_CHECKER 164 #define SH_NODE_BRIGHTCONTRAST 165 +#define SH_NODE_LIGHT_FALLOFF 166 /* custom defines options for Material node */ #define SH_NODE_MAT_DIFF 1 @@ -683,6 +684,11 @@ void ntreeCompositClearTags(struct bNodeTree *ntree); struct bNodeSocket *ntreeCompositOutputFileAddSocket(struct bNodeTree *ntree, struct bNode *node, const char *name, struct ImageFormatData *im_format); int ntreeCompositOutputFileRemoveActiveSocket(struct bNodeTree *ntree, struct bNode *node); +void ntreeCompositOutputFileSetPath(struct bNode *node, struct bNodeSocket *sock, const char *name); +void ntreeCompositOutputFileSetLayer(struct bNode *node, struct bNodeSocket *sock, const char *name); +/* needed in do_versions */ +void ntreeCompositOutputFileUniquePath(struct ListBase *list, struct bNodeSocket *sock, const char defname[], char delim); +void ntreeCompositOutputFileUniqueLayer(struct ListBase *list, struct bNodeSocket *sock, const char defname[], char delim); /* ************** TEXTURE NODES *************** */ diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index 2e334c4abc9..92a447f9351 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -50,65 +50,66 @@ struct RenderData; struct rctf; struct MovieClip; -void clear_workob(struct Object *workob); -void what_does_parent(struct Scene *scene, struct Object *ob, struct Object *workob); +void BKE_object_workob_clear(struct Object *workob); +void BKE_object_workob_calc_parent(struct Scene *scene, struct Object *ob, struct Object *workob); -void copy_baseflags(struct Scene *scene); -void copy_objectflags(struct Scene *scene); struct SoftBody *copy_softbody(struct SoftBody *sb); struct BulletSoftBody *copy_bulletsoftbody(struct BulletSoftBody *sb); -void copy_object_particlesystems(struct Object *obn, struct Object *ob); -void copy_object_softbody(struct Object *obn, struct Object *ob); -void object_free_particlesystems(struct Object *ob); -void object_free_softbody(struct Object *ob); -void object_free_bulletsoftbody(struct Object *ob); -void update_base_layer(struct Scene *scene, struct Object *ob); +void BKE_object_copy_particlesystems(struct Object *obn, struct Object *ob); +void BKE_object_copy_softbody(struct Object *obn, struct Object *ob); +void BKE_object_free_particlesystems(struct Object *ob); +void BKE_object_free_softbody(struct Object *ob); +void BKE_object_free_bulletsoftbody(struct Object *ob); +void BKE_object_update_base_layer(struct Scene *scene, struct Object *ob); -void free_object(struct Object *ob); -void object_free_display(struct Object *ob); +void BKE_object_free(struct Object *ob); +void BKE_object_free_display(struct Object *ob); -int object_support_modifier_type(struct Object *ob, int modifier_type); +int BKE_object_support_modifier_type_check(struct Object *ob, int modifier_type); -void object_link_modifiers(struct Object *ob, struct Object *from); -void object_free_modifiers(struct Object *ob); +void BKE_object_link_modifiers(struct Object *ob, struct Object *from); +void BKE_object_free_modifiers(struct Object *ob); -void object_make_proxy(struct Object *ob, struct Object *target, struct Object *gob); -void object_copy_proxy_drivers(struct Object *ob, struct Object *target); +void BKE_object_make_proxy(struct Object *ob, struct Object *target, struct Object *gob); +void BKE_object_copy_proxy_drivers(struct Object *ob, struct Object *target); -void unlink_object(struct Object *ob); -int exist_object(struct Object *obtest); +void BKE_object_unlink(struct Object *ob); +int BKE_object_exists_check(struct Object *obtest); -struct Object *add_only_object(int type, const char *name); -struct Object *add_object(struct Scene *scene, int type); -void *add_obdata_from_type(int type); - -struct Object *copy_object(struct Object *ob); -void make_local_object(struct Object *ob); -int object_is_libdata(struct Object *ob); -int object_data_is_libdata(struct Object *ob); - -void object_scale_to_mat3(struct Object *ob, float mat[][3]); -void object_rot_to_mat3(struct Object *ob, float mat[][3]); -void object_mat3_to_rot(struct Object *ob, float mat[][3], short use_compat); -void object_to_mat3(struct Object *ob, float mat[][3]); -void object_to_mat4(struct Object *ob, float mat[][4]); -void object_apply_mat4(struct Object *ob, float mat[][4], const short use_compat, const short use_parent); - -struct Object *object_pose_armature_get(struct Object *ob); - -void where_is_object_time(struct Scene *scene, struct Object *ob, float ctime); -void where_is_object(struct Scene *scene, struct Object *ob); -void where_is_object_simul(struct Scene *scene, struct Object *ob); -void where_is_object_mat(struct Scene *scene, struct Object *ob, float obmat[4][4]); - -struct BoundBox *unit_boundbox(void); -void boundbox_set_from_min_max(struct BoundBox *bb, float min[3], float max[3]); -struct BoundBox *object_get_boundbox(struct Object *ob); -void object_get_dimensions(struct Object *ob, float vec[3]); -void object_set_dimensions(struct Object *ob, const float *value); -void object_boundbox_flag(struct Object *ob, int flag, int set); -void minmax_object(struct Object *ob, float min[3], float max[3]); -int minmax_object_duplis(struct Scene *scene, struct Object *ob, float min[3], float max[3]); +struct Object *BKE_object_add_only_object(int type, const char *name); +struct Object *BKE_object_add(struct Scene *scene, int type); +void *BKE_object_obdata_add_from_type(int type); + +struct Object *BKE_object_copy(struct Object *ob); +void BKE_object_make_local(struct Object *ob); +int BKE_object_is_libdata(struct Object *ob); +int BKE_object_obdata_is_libdata(struct Object *ob); + +void BKE_object_scale_to_mat3(struct Object *ob, float mat[][3]); +void BKE_object_rot_to_mat3(struct Object *ob, float mat[][3]); +void BKE_object_mat3_to_rot(struct Object *ob, float mat[][3], short use_compat); +void BKE_object_to_mat3(struct Object *ob, float mat[][3]); +void BKE_object_to_mat4(struct Object *ob, float mat[][4]); +void BKE_object_apply_mat4(struct Object *ob, float mat[][4], const short use_compat, const short use_parent); + +struct Object *BKE_object_pose_armature_get(struct Object *ob); + +void BKE_object_where_is_calc(struct Scene *scene, struct Object *ob); +void BKE_object_where_is_calc_time(struct Scene *scene, struct Object *ob, float ctime); +void BKE_object_where_is_calc_simul(struct Scene *scene, struct Object *ob); +void BKE_object_where_is_calc_mat4(struct Scene *scene, struct Object *ob, float obmat[4][4]); + +/* possibly belong in own moduke? */ +struct BoundBox *BKE_boundbox_alloc_unit(void); +void BKE_boundbox_init_from_minmax(struct BoundBox *bb, float min[3], float max[3]); +int BKE_boundbox_ray_hit_check(struct BoundBox *bb, float ray_start[3], float ray_normal[3]); + +struct BoundBox *BKE_object_boundbox_get(struct Object *ob); +void BKE_object_dimensions_get(struct Object *ob, float vec[3]); +void BKE_object_dimensions_set(struct Object *ob, const float *value); +void BKE_object_boundbox_flag(struct Object *ob, int flag, int set); +void BKE_object_minmax(struct Object *ob, float r_min[3], float r_max[3]); +int BKE_object_minmax_dupli(struct Scene *scene, struct Object *ob, float r_min[3], float r_max[3]); /* sometimes min-max isn't enough, we need to loop over each point */ void BKE_object_foreach_display_point( @@ -122,10 +123,8 @@ void BKE_scene_foreach_display_point( int BKE_object_parent_loop_check(const struct Object *parent, const struct Object *ob); -int ray_hit_boundbox(struct BoundBox *bb, float ray_start[3], float ray_normal[3]); - -void *object_tfm_backup(struct Object *ob); -void object_tfm_restore(struct Object *ob, void *obtfm_pt); +void *BKE_object_tfm_backup(struct Object *ob); +void BKE_object_tfm_restore(struct Object *ob, void *obtfm_pt); typedef struct ObjectTfmProtectedChannels { float loc[3], dloc[3]; @@ -136,28 +135,28 @@ typedef struct ObjectTfmProtectedChannels { float rotAngle, drotAngle; } ObjectTfmProtectedChannels; -void object_tfm_protected_backup(const struct Object *ob, - ObjectTfmProtectedChannels *obtfm); +void BKE_object_tfm_protected_backup(const struct Object *ob, + ObjectTfmProtectedChannels *obtfm); -void object_tfm_protected_restore(struct Object *ob, - const ObjectTfmProtectedChannels *obtfm, - const short protectflag); +void BKE_object_tfm_protected_restore(struct Object *ob, + const ObjectTfmProtectedChannels *obtfm, + const short protectflag); -void object_handle_update(struct Scene *scene, struct Object *ob); -void object_sculpt_modifiers_changed(struct Object *ob); +void BKE_object_handle_update(struct Scene *scene, struct Object *ob); +void BKE_object_sculpt_modifiers_changed(struct Object *ob); -int give_obdata_texspace(struct Object *ob, short **texflag, float **loc, float **size, float **rot); +int BKE_object_obdata_texspace_get(struct Object *ob, short **r_texflag, float **r_loc, float **r_size, float **r_rot); -int object_insert_ptcache(struct Object *ob); +int BKE_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); +struct KeyBlock *BKE_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); -int object_is_deform_modified(struct Scene *scene, struct Object *ob); +int BKE_object_is_modified(struct Scene *scene, struct Object *ob); +int BKE_object_is_deform_modified(struct Scene *scene, struct Object *ob); -void object_relink(struct Object *ob); +void BKE_object_relink(struct Object *ob); -struct MovieClip *object_get_movieclip(struct Scene *scene, struct Object *ob, int use_default); +struct MovieClip *BKE_object_movieclip_get(struct Scene *scene, struct Object *ob, int use_default); #ifdef __cplusplus } diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index bd31a62abf9..b32b7145ff4 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -35,6 +35,7 @@ struct Brush; struct MDisps; struct MeshElemMap; +struct GridPaintMask; struct MFace; struct MultireModifierData; struct MVert; @@ -66,7 +67,11 @@ int paint_vertsel_test(struct Object *ob); /* partial visibility */ int paint_is_face_hidden(const struct MFace *f, const struct MVert *mvert); int paint_is_grid_face_hidden(const unsigned int *grid_hidden, - int gridsize, int x, int y); + int gridsize, int x, int y); + +/* paint masks */ +float paint_grid_paint_mask(const struct GridPaintMask *gpm, unsigned level, + unsigned x, unsigned y); /* Session data (mode-specific) */ @@ -79,6 +84,7 @@ typedef struct SculptSession { int totvert, totpoly; float *face_normals; struct KeyBlock *kb; + float *vmask; /* Mesh connectivity */ const struct MeshElemMap *pmap; diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h index 67dba6fd7a7..f776295b912 100644 --- a/source/blender/blenkernel/BKE_particle.h +++ b/source/blender/blenkernel/BKE_particle.h @@ -246,7 +246,7 @@ void psys_check_group_weights(struct ParticleSettings *part); int psys_uses_gravity(struct ParticleSimulationData *sim); /* free */ -void psys_free_settings(struct ParticleSettings *part); +void BKE_particlesettings_free(struct ParticleSettings *part); void psys_free_path_cache(struct ParticleSystem *psys, struct PTCacheEdit *edit); void psys_free(struct Object * ob, struct ParticleSystem * psys); @@ -266,8 +266,8 @@ struct ParticleSystemModifierData *psys_get_modifier(struct Object *ob, struct P struct ModifierData *object_add_particle_system(struct Scene *scene, struct Object *ob, const char *name); void object_remove_particle_system(struct Scene *scene, struct Object *ob); struct ParticleSettings *psys_new_settings(const char *name, struct Main *main); -struct ParticleSettings *psys_copy_settings(struct ParticleSettings *part); -void make_local_particlesettings(struct ParticleSettings *part); +struct ParticleSettings *BKE_particlesettings_copy(struct ParticleSettings *part); +void BKE_particlesettings_make_local(struct ParticleSettings *part); void psys_reset(struct ParticleSystem *psys, int mode); diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h index e46d99ed873..3a93562707d 100644 --- a/source/blender/blenkernel/BKE_scene.h +++ b/source/blender/blenkernel/BKE_scene.h @@ -61,40 +61,44 @@ struct Base *_setlooper_base_step(struct Scene **sce_iter, struct Base *base); void free_avicodecdata(struct AviCodecData *acd); void free_qtcodecdata(struct QuicktimeCodecData *acd); -void free_scene(struct Scene *sce); -struct Scene *add_scene(const char *name); -struct Base *object_in_scene(struct Object *ob, struct Scene *sce); +void BKE_scene_free(struct Scene *sce); +struct Scene *BKE_scene_add(const char *name); -void set_scene_bg(struct Main *bmain, struct Scene *sce); -struct Scene *set_scene_name(struct Main *bmain, const char *name); +/* base functions */ +struct Base *BKE_scene_base_find(struct Scene *scene, struct Object *ob); +struct Base *BKE_scene_base_add(struct Scene *sce, struct Object *ob); +void BKE_scene_base_deselect_all(struct Scene *sce); +void BKE_scene_base_select(struct Scene *sce, struct Base *selbase); +int BKE_scene_base_iter_next(struct Scene **scene, int val, struct Base **base, struct Object **ob); -struct Scene *copy_scene(struct Scene *sce, int type); -void unlink_scene(struct Main *bmain, struct Scene *sce, struct Scene *newsce); +void BKE_scene_base_flag_to_objects(struct Scene *scene); +void BKE_scene_base_flag_from_objects(struct Scene *scene); -int next_object(struct Scene **scene, int val, struct Base **base, struct Object **ob); -struct Object *scene_find_camera(struct Scene *sc); -struct Object *scene_camera_switch_find(struct Scene *scene); // DURIAN_CAMERA_SWITCH -int scene_camera_switch_update(struct Scene *scene); +void BKE_scene_set_background(struct Main *bmain, struct Scene *sce); +struct Scene *BKE_scene_set_name(struct Main *bmain, const char *name); -char *scene_find_marker_name(struct Scene *scene, int frame); -char *scene_find_last_marker_name(struct Scene *scene, int frame); +struct Scene *BKE_scene_copy(struct Scene *sce, int type); +void BKE_scene_unlink(struct Main *bmain, struct Scene *sce, struct Scene *newsce); -struct Base *scene_add_base(struct Scene *sce, struct Object *ob); -void scene_deselect_all(struct Scene *sce); -void scene_select_base(struct Scene *sce, struct Base *selbase); +struct Object *BKE_scene_camera_find(struct Scene *sc); +struct Object *BKE_scene_camera_switch_find(struct Scene *scene); // DURIAN_CAMERA_SWITCH +int BKE_scene_camera_switch_update(struct Scene *scene); + +char *BKE_scene_find_marker_name(struct Scene *scene, int frame); +char *BKE_scene_find_last_marker_name(struct Scene *scene, int frame); /* checks for cycle, returns 1 if it's all OK */ -int scene_check_setscene(struct Main *bmain, struct Scene *sce); +int BKE_scene_validate_setscene(struct Main *bmain, struct Scene *sce); -float BKE_curframe(struct Scene *scene); -float BKE_frame_to_ctime(struct Scene *scene, const float frame); +float BKE_scene_frame_get(struct Scene *scene); +float BKE_scene_frame_get_from_ctime(struct Scene *scene, const float frame); -void scene_update_tagged(struct Main *bmain, struct Scene *sce); +void BKE_scene_update_tagged(struct Main *bmain, struct Scene *sce); -void scene_update_for_newframe(struct Main *bmain, struct Scene *sce, unsigned int lay); +void BKE_scene_update_for_newframe(struct Main *bmain, struct Scene *sce, unsigned int lay); -struct SceneRenderLayer *scene_add_render_layer(struct Scene *sce, const char *name); -int scene_remove_render_layer(struct Main *main, struct Scene *scene, struct SceneRenderLayer *srl); +struct SceneRenderLayer *BKE_scene_add_render_layer(struct Scene *sce, const char *name); +int BKE_scene_remove_render_layer(struct Main *main, struct Scene *scene, struct SceneRenderLayer *srl); /* render profile */ int get_render_subsurf_level(struct RenderData *r, int level); @@ -102,7 +106,7 @@ int get_render_child_particle_number(struct RenderData *r, int num); int get_render_shadow_samples(struct RenderData *r, int samples); float get_render_aosss_error(struct RenderData *r, float error); -int scene_use_new_shading_nodes(struct Scene *scene); +int BKE_scene_use_new_shading_nodes(struct Scene *scene); #ifdef __cplusplus } diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h index fbb93c761c2..af6e793cf2f 100644 --- a/source/blender/blenkernel/BKE_screen.h +++ b/source/blender/blenkernel/BKE_screen.h @@ -252,7 +252,7 @@ float BKE_screen_view3d_zoom_to_fac(float camzoom); float BKE_screen_view3d_zoom_from_fac(float zoomfac); /* screen */ -void free_screen(struct bScreen *sc); +void BKE_screen_free(struct bScreen *sc); unsigned int BKE_screen_visible_layers(struct bScreen *screen, struct Scene *scene); #endif diff --git a/source/blender/blenkernel/BKE_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h index 598d1b681bc..decbf5d0d2a 100644 --- a/source/blender/blenkernel/BKE_sequencer.h +++ b/source/blender/blenkernel/BKE_sequencer.h @@ -170,6 +170,22 @@ struct ImBuf *give_ibuf_seq_direct(SeqRenderData context, float cfra, struct Seq struct ImBuf *give_ibuf_seqbase(SeqRenderData context, float cfra, int chan_shown, struct ListBase *seqbasep); void give_ibuf_prefetch_request(SeqRenderData context, float cfra, int chan_shown); + +/* ********************************************************************** + * sequencer scene functions + * ********************************************************************** */ +struct Editing *BKE_sequencer_editing_get(struct Scene *scene, int alloc); +struct Editing *BKE_sequencer_editing_ensure(struct Scene *scene); +void BKE_sequencer_editing_free(struct Scene *scene); + +void BKE_sequencer_sort(struct Scene *scene); + +struct Sequence *BKE_sequencer_active_get(struct Scene *scene); +int BKE_sequencer_active_get_pair(struct Scene *scene, + struct Sequence **seq_act, struct Sequence **seq_other); +void BKE_sequencer_active_set(struct Scene *scene, struct Sequence *seq); + + /* apply functions recursively */ int seqbase_recursive_apply(struct ListBase *seqbase, int (*apply_func)(struct Sequence *seq, void *), void *arg); int seq_recursive_apply(struct Sequence *seq, int (*apply_func)(struct Sequence *, void *), void *arg); @@ -179,14 +195,12 @@ int seq_recursive_apply(struct Sequence *seq, int (*apply_func)(struct Sequence void seq_free_sequence(struct Scene *scene, struct Sequence *seq); void seq_free_sequence_recurse(struct Scene *scene, struct Sequence *seq); void seq_free_strip(struct Strip *strip); -void seq_free_editing(struct Scene *scene); + void seq_free_clipboard(void); -struct Editing *seq_give_editing(struct Scene *scene, int alloc); const char *give_seqname(struct Sequence *seq); void calc_sequence(struct Scene *scene, struct Sequence *seq); void calc_sequence_disp(struct Scene *scene, struct Sequence *seq); void reload_sequence_new_file(struct Scene *scene, struct Sequence * seq, int lock_range); -void sort_seq(struct Scene *scene); void build_seqar_cb(struct ListBase *seqbase, struct Sequence ***seqar, int *totseq, int (*test_func)(struct Sequence * seq)); int evaluate_seq_frame(struct Scene *scene, int cfra); @@ -296,10 +310,6 @@ void clear_scene_in_allseqs(struct Main *bmain, struct Scene *sce); struct Sequence *get_seq_by_name(struct ListBase *seqbase, const char *name, int recursive); -struct Sequence *seq_active_get(struct Scene *scene); -void seq_active_set(struct Scene *scene, struct Sequence *seq); -int seq_active_pair_get(struct Scene *scene, struct Sequence **seq_act, struct Sequence **seq_other); - /* api for adding new sequence strips */ typedef struct SeqLoadInfo { int start_frame; diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h index 8b01dbde531..ec1b6577469 100644 --- a/source/blender/blenkernel/BKE_sound.h +++ b/source/blender/blenkernel/BKE_sound.h @@ -41,8 +41,7 @@ struct ListBase; struct Main; struct Sequence; -typedef struct SoundWaveform -{ +typedef struct SoundWaveform { int length; float *data; } SoundWaveform; @@ -58,29 +57,29 @@ void sound_exit(void); void sound_force_device(int device); int sound_define_from_str(const char *str); -struct bSound* sound_new_file(struct Main *main, const char *filename); +struct bSound *sound_new_file(struct Main *main, const char *filename); // XXX unused currently #if 0 -struct bSound* sound_new_buffer(struct Main *bmain, struct bSound *source); +struct bSound *sound_new_buffer(struct Main *bmain, struct bSound *source); -struct bSound* sound_new_limiter(struct Main *bmain, struct bSound *source, float start, float end); +struct bSound *sound_new_limiter(struct Main *bmain, struct bSound *source, float start, float end); #endif -void sound_delete(struct Main *bmain, struct bSound* sound); +void sound_delete(struct Main *bmain, struct bSound *sound); -void sound_cache(struct bSound* sound); +void sound_cache(struct bSound *sound); -void sound_cache_notifying(struct Main* main, struct bSound* sound); +void sound_cache_notifying(struct Main *main, struct bSound *sound); -void sound_delete_cache(struct bSound* sound); +void sound_delete_cache(struct bSound *sound); -void sound_load(struct Main *main, struct bSound* sound); +void sound_load(struct Main *main, struct bSound *sound); -void sound_free(struct bSound* sound); +void BKE_sound_free(struct bSound *sound); #ifdef __AUD_C_API_H__ -AUD_Device* sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, float volume); +AUD_Device *sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, float volume); #endif void sound_create_scene(struct Scene *scene); @@ -93,32 +92,32 @@ void sound_update_fps(struct Scene *scene); void sound_update_scene_listener(struct Scene *scene); -void* sound_scene_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip); -void* sound_scene_add_scene_sound_defaults(struct Scene *scene, struct Sequence* sequence); +void *sound_scene_add_scene_sound(struct Scene *scene, struct Sequence *sequence, int startframe, int endframe, int frameskip); +void *sound_scene_add_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence); -void* sound_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip); -void* sound_add_scene_sound_defaults(struct Scene *scene, struct Sequence* sequence); +void *sound_add_scene_sound(struct Scene *scene, struct Sequence *sequence, int startframe, int endframe, int frameskip); +void *sound_add_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence); -void sound_remove_scene_sound(struct Scene *scene, void* handle); +void sound_remove_scene_sound(struct Scene *scene, void *handle); -void sound_mute_scene_sound(void* handle, char mute); +void sound_mute_scene_sound(void *handle, char mute); -void sound_move_scene_sound(struct Scene *scene, void* handle, int startframe, int endframe, int frameskip); +void sound_move_scene_sound(struct Scene *scene, void *handle, int startframe, int endframe, int frameskip); void sound_move_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence); -void sound_update_scene_sound(void* handle, struct bSound* sound); +void sound_update_scene_sound(void *handle, struct bSound *sound); void sound_set_cfra(int cfra); void sound_set_scene_volume(struct Scene *scene, float volume); -void sound_set_scene_sound_volume(void* handle, float volume, char animated); +void sound_set_scene_sound_volume(void *handle, float volume, char animated); -void sound_set_scene_sound_pitch(void* handle, float pitch, char animated); +void sound_set_scene_sound_pitch(void *handle, float pitch, char animated); -void sound_set_scene_sound_pan(void* handle, float pan, char animated); +void sound_set_scene_sound_pan(void *handle, float pan, char animated); -void sound_update_sequencer(struct Main* main, struct bSound* sound); +void sound_update_sequencer(struct Main *main, struct bSound *sound); void sound_play_scene(struct Scene *scene); @@ -130,12 +129,14 @@ float sound_sync_scene(struct Scene *scene); int sound_scene_playing(struct Scene *scene); -void sound_free_waveform(struct bSound* sound); +void sound_free_waveform(struct bSound *sound); -void sound_read_waveform(struct bSound* sound); +void sound_read_waveform(struct bSound *sound); -void sound_update_scene(struct Scene* scene); +void sound_update_scene(struct Scene *scene); -void* sound_get_factory(void* sound); +void *sound_get_factory(void *sound); + +float sound_get_length(struct bSound *sound); #endif diff --git a/source/blender/blenkernel/BKE_speaker.h b/source/blender/blenkernel/BKE_speaker.h index fddcfb2c7f3..52c177fce57 100644 --- a/source/blender/blenkernel/BKE_speaker.h +++ b/source/blender/blenkernel/BKE_speaker.h @@ -33,9 +33,9 @@ * \brief General operations for speakers. */ -void *add_speaker(const char *name); -struct Speaker *copy_speaker(struct Speaker *spk); -void make_local_speaker(struct Speaker *spk); -void free_speaker(struct Speaker *spk); +void *BKE_speaker_add(const char *name); +struct Speaker *BKE_speaker_copy(struct Speaker *spk); +void BKE_speaker_make_local(struct Speaker *spk); +void BKE_speaker_free(struct Speaker *spk); #endif diff --git a/source/blender/blenkernel/BKE_subsurf.h b/source/blender/blenkernel/BKE_subsurf.h index 8179c688580..ea824a9998d 100644 --- a/source/blender/blenkernel/BKE_subsurf.h +++ b/source/blender/blenkernel/BKE_subsurf.h @@ -34,9 +34,9 @@ /* struct DerivedMesh is used directly */ #include "BKE_DerivedMesh.h" +struct CCGElem; struct DMFlagMat; struct DMGridAdjacency; -struct DMGridData; struct DerivedMesh; struct MeshElemMap; struct Mesh; @@ -51,16 +51,23 @@ struct CCGSubsurf; struct CCGVert; struct EdgeHash; struct PBVH; -struct DMGridData; struct DMGridAdjacency; /**************************** External *****************************/ +typedef enum { + SUBSURF_USE_RENDER_PARAMS = 1, + SUBSURF_IS_FINAL_CALC = 2, + SUBSURF_FOR_EDIT_MODE = 4, + SUBSURF_IN_EDIT_MODE = 8, + SUBSURF_ALLOC_PAINT_MASK = 16 +} SubsurfFlags; + struct DerivedMesh *subsurf_make_derived_from_derived( - struct DerivedMesh *dm, - struct SubsurfModifierData *smd, - int useRenderParams, float (*vertCos)[3], - int isFinalCalc, int forEditMode, int inEditMode); + struct DerivedMesh *dm, + struct SubsurfModifierData *smd, + float (*vertCos)[3], + SubsurfFlags flags); void subsurf_calculate_limit_positions(struct Mesh *me, float (*positions_r)[3]); @@ -72,9 +79,13 @@ int ccg_gridsize(int level); int ccg_factor(int low_level, int high_level); void subsurf_copy_grid_hidden(struct DerivedMesh *dm, - const struct MPoly *mpoly, - struct MVert *mvert, - const struct MDisps *mdisps); + const struct MPoly *mpoly, + struct MVert *mvert, + const struct MDisps *mdisps); + +void subsurf_copy_grid_paint_mask(struct DerivedMesh *dm, + const struct MPoly *mpoly, float *paint_mask, + const struct GridPaintMask *grid_paint_mask); typedef enum MultiresModifiedFlags { /* indicates the grids have been sculpted on, so MDisps @@ -93,10 +104,10 @@ typedef struct CCGDerivedMesh { int freeSS; int drawInteriorEdges, useSubsurfUv; - struct {int startVert; struct CCGVert *vert;} *vertMap; - struct {int startVert; int startEdge; struct CCGEdge *edge;} *edgeMap; + struct {int startVert; struct CCGVert *vert; } *vertMap; + struct {int startVert; int startEdge; struct CCGEdge *edge; } *edgeMap; struct {int startVert; int startEdge; - int startFace; struct CCGFace *face;} *faceMap; + int startFace; struct CCGFace *face; } *faceMap; short *edgeFlags; struct DMFlagMat *faceFlags; @@ -108,7 +119,7 @@ typedef struct CCGDerivedMesh { struct MeshElemMap *pmap; int *pmap_mem; - struct DMGridData **gridData; + struct CCGElem **gridData; struct DMGridAdjacency *gridAdjacency; int *gridOffset; struct CCGFace **gridFaces; diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index 115c00d9e73..875903f2e20 100644 --- a/source/blender/blenkernel/BKE_text.h +++ b/source/blender/blenkernel/BKE_text.h @@ -42,17 +42,17 @@ struct Text; struct TextLine; struct SpaceText; -void free_text (struct Text *text); +void BKE_text_free (struct Text *text); void txt_set_undostate (int u); int txt_get_undostate (void); -struct Text* add_empty_text (const char *name); +struct Text* BKE_text_add (const char *name); int txt_extended_ascii_as_utf8(char **str); -int reopen_text (struct Text *text); -struct Text* add_text (const char *file, const char *relpath); -struct Text* copy_text (struct Text *ta); -void unlink_text (struct Main *bmain, struct Text *text); -void clear_text(struct Text *text); -void write_text(struct Text *text, const char *str); +int BKE_text_reload (struct Text *text); +struct Text* BKE_text_load (const char *file, const char *relpath); +struct Text* BKE_text_copy (struct Text *ta); +void BKE_text_unlink (struct Main *bmain, struct Text *text); +void BKE_text_clear (struct Text *text); +void BKE_text_write (struct Text *text, const char *str); char* txt_to_buf (struct Text *text); void txt_clean_text (struct Text *text); diff --git a/source/blender/blenkernel/BKE_texture.h b/source/blender/blenkernel/BKE_texture.h index 2574c45eec2..ed58620b716 100644 --- a/source/blender/blenkernel/BKE_texture.h +++ b/source/blender/blenkernel/BKE_texture.h @@ -59,7 +59,7 @@ struct World; #define MAXCOLORBAND 32 -void free_texture(struct Tex *t); +void BKE_texture_free(struct Tex *t); int test_dlerr(const char *name, const char *symbol); void open_plugin_tex(struct PluginTex *pit); struct PluginTex *add_plugin_tex(char *str); @@ -79,9 +79,9 @@ void tex_set_type(struct Tex *tex, int type); 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 *BKE_texture_copy(struct Tex *tex); struct Tex *localize_texture(struct Tex *tex); -void make_local_texture(struct Tex *tex); +void BKE_texture_make_local(struct Tex *tex); void autotexname(struct Tex *tex); struct Tex *give_current_object_texture(struct Object *ob); diff --git a/source/blender/blenkernel/BKE_world.h b/source/blender/blenkernel/BKE_world.h index 16ff3acaf71..67896fffc4d 100644 --- a/source/blender/blenkernel/BKE_world.h +++ b/source/blender/blenkernel/BKE_world.h @@ -35,11 +35,11 @@ struct World; -void free_world(struct World *sc); +void BKE_world_free(struct World *sc); struct World *add_world(const char *name); -struct World *copy_world(struct World *wrld); +struct World *BKE_world_copy(struct World *wrld); struct World *localize_world(struct World *wrld); -void make_local_world(struct World *wrld); +void BKE_world_make_local(struct World *wrld); #endif diff --git a/source/blender/blenkernel/BKE_writeavi.h b/source/blender/blenkernel/BKE_writeavi.h index 03174fb5284..78875951ca4 100644 --- a/source/blender/blenkernel/BKE_writeavi.h +++ b/source/blender/blenkernel/BKE_writeavi.h @@ -51,8 +51,8 @@ typedef struct bMovieHandle { void (*get_movie_path)(char *string, struct RenderData *rd); /* optional */ } bMovieHandle; -bMovieHandle *BKE_get_movie_handle(const char imtype); -void BKE_makeanimstring(char *string, struct RenderData *rd); +bMovieHandle *BKE_movie_handle_get(const char imtype); +void BKE_movie_filepath_get(char *string, struct RenderData *rd); #ifdef __cplusplus } diff --git a/source/blender/blenkernel/BKE_writeffmpeg.h b/source/blender/blenkernel/BKE_writeffmpeg.h index c35105f7b8b..f8382f75c0a 100644 --- a/source/blender/blenkernel/BKE_writeffmpeg.h +++ b/source/blender/blenkernel/BKE_writeffmpeg.h @@ -66,20 +66,20 @@ struct RenderData; struct ReportList; struct Scene; -extern int start_ffmpeg(struct Scene *scene, struct RenderData *rd, int rectx, int recty, struct ReportList *reports); -extern void end_ffmpeg(void); -extern int append_ffmpeg(struct RenderData *rd, int start_frame, int frame, int *pixels, - int rectx, int recty, struct ReportList *reports); -void filepath_ffmpeg(char* string, struct RenderData* rd); +int BKE_ffmpeg_start(struct Scene *scene, struct RenderData *rd, int rectx, int recty, struct ReportList *reports); +void BKE_ffmpeg_end(void); +int BKE_ffmpeg_append(struct RenderData *rd, int start_frame, int frame, int *pixels, + int rectx, int recty, struct ReportList *reports); +void BKE_ffmpeg_filepath_get(char* string, struct RenderData* rd); -extern void ffmpeg_set_preset(struct RenderData *rd, int preset); -extern void ffmpeg_verify_image_type(struct RenderData *rd, struct ImageFormatData *imf); -extern void ffmpeg_verify_codec_settings(struct RenderData *rd); -extern int ffmpeg_alpha_channel_supported(struct RenderData *rd); +void BKE_ffmpeg_preset_set(struct RenderData *rd, int preset); +void BKE_ffmpeg_image_type_verify(struct RenderData *rd, struct ImageFormatData *imf); +void BKE_ffmpeg_codec_settings_verify(struct RenderData *rd); +int BKE_ffmpeg_alpha_channel_is_supported(struct RenderData *rd); -extern struct IDProperty *ffmpeg_property_add(struct RenderData *Rd, const char *type, int opt_index, int parent_index); -extern int ffmpeg_property_add_string(struct RenderData *rd, const char *type, const char *str); -extern void ffmpeg_property_del(struct RenderData *rd, void *type, void *prop_); +struct IDProperty *BKE_ffmpeg_property_add(struct RenderData *Rd, const char *type, int opt_index, int parent_index); +int BKE_ffmpeg_property_add_string(struct RenderData *rd, const char *type, const char *str); +void BKE_ffmpeg_property_del(struct RenderData *rd, void *type, void *prop_); #ifdef __cplusplus } diff --git a/source/blender/blenkernel/BKE_writeframeserver.h b/source/blender/blenkernel/BKE_writeframeserver.h index cb607e1473c..bdce9abe8ad 100644 --- a/source/blender/blenkernel/BKE_writeframeserver.h +++ b/source/blender/blenkernel/BKE_writeframeserver.h @@ -40,11 +40,11 @@ struct RenderData; struct ReportList; struct Scene; -extern int start_frameserver(struct Scene *scene, struct RenderData *rd, int rectx, int recty, struct ReportList *reports); -extern void end_frameserver(void); -extern int append_frameserver(struct RenderData *rd, int start_frame, int frame, int *pixels, - int rectx, int recty, struct ReportList *reports); -extern int frameserver_loop(struct RenderData *rd, struct ReportList *reports); +int BKE_frameserver_start(struct Scene *scene, struct RenderData *rd, int rectx, int recty, struct ReportList *reports); +void BKE_frameserver_end(void); +int BKE_frameserver_append(struct RenderData *rd, int start_frame, int frame, int *pixels, + int rectx, int recty, struct ReportList *reports); +int BKE_frameserver_loop(struct RenderData *rd, struct ReportList *reports); #ifdef __cplusplus } diff --git a/source/blender/blenkernel/intern/CCGSubSurf.c b/source/blender/blenkernel/intern/CCGSubSurf.c index 53e4a973cd4..42c9fa84a91 100644 --- a/source/blender/blenkernel/intern/CCGSubSurf.c +++ b/source/blender/blenkernel/intern/CCGSubSurf.c @@ -7,6 +7,7 @@ #include <string.h> #include <math.h> +#include "BKE_ccg.h" #include "CCGSubSurf.h" #include "BKE_subsurf.h" @@ -274,22 +275,6 @@ static int ccg_edgebase(int level) /***/ -static int VertDataEqual(const float *a, const float *b) -{ - return a[0] == b[0] && a[1] == b[1] && a[2] == b[2]; -} -#define VertDataZero(av) { float *_a = (float *)av; _a[0] = _a[1] = _a[2] = 0.0f; } -#define VertDataCopy(av, bv) { float *_a = (float *)av, *_b = (float *) bv; _a[0] = _b[0]; _a[1] = _b[1]; _a[2] = _b[2]; } -#define VertDataAdd(av, bv) { float *_a = (float *)av, *_b = (float *) bv; _a[0] += _b[0]; _a[1] += _b[1]; _a[2] += _b[2]; } -#define VertDataSub(av, bv) { float *_a = (float *)av, *_b = (float *) bv; _a[0] -= _b[0]; _a[1] -= _b[1]; _a[2] -= _b[2]; } -#define VertDataMulN(av, n) { float *_a = (float *)av; float _n = n; _a[0] *= _n; _a[1] *= _n; _a[2] *= _n; } -#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]) * 0.25f; \ - _t[1] = (_a[1] + _b[1] + _c[1] + _d[1]) * 0.25f; \ - _t[2] = (_a[2] + _b[2] + _c[2] + _d[2]) * 0.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]; } #define NormAdd(av, bv) { float *_a = (float *) av, *_b = (float *) bv; _a[0] += _b[0]; _a[1] += _b[1]; _a[2] += _b[2]; } @@ -402,6 +387,10 @@ struct CCGSubSurf { int calcVertNormals; int normalDataOffset; + /* data for paint masks */ + int allocMask; + int maskDataOffset; + /* data for age'ing (to debug sync) */ int currentAge; int useAgeCounts; @@ -424,6 +413,61 @@ struct CCGSubSurf { /***/ +static int VertDataEqual(const float a[], const float b[], const CCGSubSurf *ss) +{ + int i; + for(i = 0; i < ss->meshIFC.numLayers; i++) { + if(a[i] != b[i]) + return 0; + } + return 1; +} + +static void VertDataZero(float v[], const CCGSubSurf *ss) +{ + memset(v, 0, sizeof(float) * ss->meshIFC.numLayers); +} + +static void VertDataCopy(float dst[], const float src[], const CCGSubSurf *ss) +{ + int i; + for(i = 0; i < ss->meshIFC.numLayers; i++) + dst[i] = src[i]; +} + +static void VertDataAdd(float a[], const float b[], const CCGSubSurf *ss) +{ + int i; + for(i = 0; i < ss->meshIFC.numLayers; i++) + a[i] += b[i]; +} + +static void VertDataSub(float a[], const float b[], const CCGSubSurf *ss) +{ + int i; + for(i = 0; i < ss->meshIFC.numLayers; i++) + a[i] -= b[i]; +} + +static void VertDataMulN(float v[], float f, const CCGSubSurf *ss) +{ + int i; + for(i = 0; i < ss->meshIFC.numLayers; i++) + v[i] *= f; +} + +static void VertDataAvg4(float v[], + const float a[], const float b[], + const float c[], const float d[], + const CCGSubSurf *ss) +{ + int i; + for(i = 0; i < ss->meshIFC.numLayers; i++) + v[i] = (a[i] + b[i] + c[i] + d[i]) * 0.25f; +} + +/***/ + static CCGVert *_vert_new(CCGVertHDL vHDL, CCGSubSurf *ss) { int num_vert_data = ss->subdivLevels + 1; @@ -812,6 +856,8 @@ CCGSubSurf *ccgSubSurf_new(CCGMeshIFC *ifc, int subdivLevels, CCGAllocatorIFC *a ss->calcVertNormals = 0; ss->normalDataOffset = 0; + ss->allocMask = 0; + ss->q = CCGSUBSURF_alloc(ss, ss->meshIFC.vertDataSize); ss->r = CCGSUBSURF_alloc(ss, ss->meshIFC.vertDataSize); @@ -956,6 +1002,17 @@ CCGError ccgSubSurf_setCalcVertexNormals(CCGSubSurf *ss, int useVertNormals, int return eCCGError_None; } +void ccgSubSurf_setAllocMask(CCGSubSurf *ss, int allocMask, int maskOffset) +{ + ss->allocMask = allocMask; + ss->maskDataOffset = maskOffset; +} + +void ccgSubSurf_setNumLayers(CCGSubSurf *ss, int numLayers) +{ + ss->meshIFC.numLayers = numLayers; +} + /***/ CCGError ccgSubSurf_initFullSync(CCGSubSurf *ss) @@ -1071,14 +1128,15 @@ CCGError ccgSubSurf_syncVert(CCGSubSurf *ss, CCGVertHDL vHDL, const void *vertDa v = _ehash_lookupWithPrev(ss->vMap, vHDL, &prevp); if (!v) { v = _vert_new(vHDL, ss); - VertDataCopy(_vert_getCo(v, 0, ss->meshIFC.vertDataSize), vertData); + VertDataCopy(_vert_getCo(v, 0, ss->meshIFC.vertDataSize), vertData, ss); _ehash_insert(ss->vMap, (EHEntry *) v); v->flags = Vert_eEffected | seamflag; } - else if (!VertDataEqual(vertData, _vert_getCo(v, 0, ss->meshIFC.vertDataSize)) || ((v->flags & Vert_eSeam) != seamflag)) { + else if (!VertDataEqual(vertData, _vert_getCo(v, 0, ss->meshIFC.vertDataSize), ss) || + ((v->flags & Vert_eSeam) != seamflag)) { int i, j; - VertDataCopy(_vert_getCo(v, 0, ss->meshIFC.vertDataSize), vertData); + VertDataCopy(_vert_getCo(v, 0, ss->meshIFC.vertDataSize), vertData, ss); v->flags = Vert_eEffected | seamflag; for (i = 0; i < v->numEdges; i++) { @@ -1102,14 +1160,15 @@ CCGError ccgSubSurf_syncVert(CCGSubSurf *ss, CCGVertHDL vHDL, const void *vertDa v = _ehash_lookupWithPrev(ss->oldVMap, vHDL, &prevp); if (!v) { v = _vert_new(vHDL, ss); - VertDataCopy(_vert_getCo(v, 0, ss->meshIFC.vertDataSize), vertData); + VertDataCopy(_vert_getCo(v, 0, ss->meshIFC.vertDataSize), vertData, ss); _ehash_insert(ss->vMap, (EHEntry *) v); v->flags = Vert_eEffected | seamflag; } - else if (!VertDataEqual(vertData, _vert_getCo(v, 0, ss->meshIFC.vertDataSize)) || ((v->flags & Vert_eSeam) != seamflag)) { + else if (!VertDataEqual(vertData, _vert_getCo(v, 0, ss->meshIFC.vertDataSize), ss) || + ((v->flags & Vert_eSeam) != seamflag)) { *prevp = v->next; _ehash_insert(ss->vMap, (EHEntry *) v); - VertDataCopy(_vert_getCo(v, 0, ss->meshIFC.vertDataSize), vertData); + VertDataCopy(_vert_getCo(v, 0, ss->meshIFC.vertDataSize), vertData, ss); v->flags = Vert_eEffected | Vert_eChanged | seamflag; } else { @@ -1516,7 +1575,7 @@ static void ccgSubSurf__calcVertNormals(CCGSubSurf *ss, } VertDataCopy((float *)((byte *)FACE_getCenterData(f) + normalDataOffset), - FACE_getIFNo(f, lvl, S, 0, 0)); + FACE_getIFNo(f, lvl, S, 0, 0), ss); for (x = 1; x < gridSize - 1; x++) NormCopy(FACE_getIENo(f, lvl, S, x), @@ -1587,7 +1646,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, void *co3 = FACE_getIFCo(f, curLvl, S, x + 0, y + 1); void *co = FACE_getIFCo(f, nextLvl, S, fx, fy); - VertDataAvg4(co, co0, co1, co2, co3); + VertDataAvg4(co, co0, co1, co2, co3, ss); } } } @@ -1605,7 +1664,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, void *co3 = FACE_getIFCo(f, nextLvl, S, fx, 1); void *co = FACE_getIECo(f, nextLvl, S, fx); - VertDataAvg4(co, co0, co1, co2, co3); + VertDataAvg4(co, co0, co1, co2, co3, ss); } /* interior face interior edge midpoints @@ -1624,7 +1683,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, void *co3 = FACE_getIFCo(f, nextLvl, S, fx + 1, fy); void *co = FACE_getIFCo(f, nextLvl, S, fx, fy); - VertDataAvg4(co, co0, co1, co2, co3); + VertDataAvg4(co, co0, co1, co2, co3, ss); } } @@ -1639,7 +1698,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, void *co3 = FACE_getIFCo(f, nextLvl, S, fx, fy + 1); void *co = FACE_getIFCo(f, nextLvl, S, fx, fy); - VertDataAvg4(co, co0, co1, co2, co3); + VertDataAvg4(co, co0, co1, co2, co3, ss); } } } @@ -1661,9 +1720,9 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, void *co1 = EDGE_getCo(e, curLvl, x + 1); void *co = EDGE_getCo(e, nextLvl, fx); - VertDataCopy(co, co0); - VertDataAdd(co, co1); - VertDataMulN(co, 0.5f); + VertDataCopy(co, co0, ss); + VertDataAdd(co, co1, ss); + VertDataMulN(co, 0.5f, ss); } } else { @@ -1674,26 +1733,26 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, void *co = EDGE_getCo(e, nextLvl, fx); int numFaces = 0; - VertDataCopy(q, co0); - VertDataAdd(q, co1); + VertDataCopy(q, co0, ss); + VertDataAdd(q, co1, ss); for (j = 0; j < e->numFaces; j++) { CCGFace *f = e->faces[j]; const int f_ed_idx = _face_getEdgeIndex(f, e); - VertDataAdd(q, _face_getIFCoEdge(f, e, f_ed_idx, nextLvl, fx, 1, subdivLevels, vertDataSize)); + VertDataAdd(q, _face_getIFCoEdge(f, e, f_ed_idx, nextLvl, fx, 1, subdivLevels, vertDataSize), ss); numFaces++; } - VertDataMulN(q, 1.0f / (2.0f + numFaces)); + VertDataMulN(q, 1.0f / (2.0f + numFaces), ss); - VertDataCopy(r, co0); - VertDataAdd(r, co1); - VertDataMulN(r, 0.5f); + VertDataCopy(r, co0, ss); + VertDataAdd(r, co1, ss); + VertDataMulN(r, 0.5f, ss); - VertDataCopy(co, q); - VertDataSub(r, q); - VertDataMulN(r, sharpness); - VertDataAdd(co, r); + VertDataCopy(co, q, ss); + VertDataSub(r, q, ss); + VertDataMulN(r, sharpness, ss); + VertDataAdd(co, r, ss); } } } @@ -1738,53 +1797,53 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, seam = 0; if (!v->numEdges) { - VertDataCopy(nCo, co); + VertDataCopy(nCo, co, ss); } else if (_vert_isBoundary(v)) { int numBoundary = 0; - VertDataZero(r); + VertDataZero(r, ss); for (j = 0; j < v->numEdges; j++) { CCGEdge *e = v->edges[j]; if (_edge_isBoundary(e)) { - VertDataAdd(r, _edge_getCoVert(e, v, curLvl, 1, vertDataSize)); + VertDataAdd(r, _edge_getCoVert(e, v, curLvl, 1, vertDataSize), ss); numBoundary++; } } - VertDataCopy(nCo, co); - VertDataMulN(nCo, 0.75f); - VertDataMulN(r, 0.25f / numBoundary); - VertDataAdd(nCo, r); + VertDataCopy(nCo, co, ss); + VertDataMulN(nCo, 0.75f, ss); + VertDataMulN(r, 0.25f / numBoundary, ss); + VertDataAdd(nCo, r, ss); } else { int cornerIdx = (1 + (1 << (curLvl))) - 2; int numEdges = 0, numFaces = 0; - VertDataZero(q); + VertDataZero(q, ss); for (j = 0; j < v->numFaces; j++) { CCGFace *f = v->faces[j]; - VertDataAdd(q, FACE_getIFCo(f, nextLvl, _face_getVertIndex(f, v), cornerIdx, cornerIdx)); + VertDataAdd(q, FACE_getIFCo(f, nextLvl, _face_getVertIndex(f, v), cornerIdx, cornerIdx), ss); numFaces++; } - VertDataMulN(q, 1.0f / numFaces); - VertDataZero(r); + VertDataMulN(q, 1.0f / numFaces, ss); + VertDataZero(r, ss); for (j = 0; j < v->numEdges; j++) { CCGEdge *e = v->edges[j]; - VertDataAdd(r, _edge_getCoVert(e, v, curLvl, 1, vertDataSize)); + VertDataAdd(r, _edge_getCoVert(e, v, curLvl, 1, vertDataSize), ss); numEdges++; } - VertDataMulN(r, 1.0f / numEdges); + VertDataMulN(r, 1.0f / numEdges, ss); - VertDataCopy(nCo, co); - VertDataMulN(nCo, numEdges - 2.0f); - VertDataAdd(nCo, q); - VertDataAdd(nCo, r); - VertDataMulN(nCo, 1.0f / numEdges); + VertDataCopy(nCo, co, ss); + VertDataMulN(nCo, numEdges - 2.0f, ss); + VertDataAdd(nCo, q, ss); + VertDataAdd(nCo, r, ss); + VertDataMulN(nCo, 1.0f / numEdges, ss); } if ((sharpCount > 1 && v->numFaces) || seam) { - VertDataZero(q); + VertDataZero(q, ss); if (seam) { avgSharpness = 1.0f; @@ -1798,33 +1857,33 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, if (seam) { if (_edge_isBoundary(e)) - VertDataAdd(q, _edge_getCoVert(e, v, curLvl, 1, vertDataSize)); + VertDataAdd(q, _edge_getCoVert(e, v, curLvl, 1, vertDataSize), ss); } else if (sharpness != 0.0f) { - VertDataAdd(q, _edge_getCoVert(e, v, curLvl, 1, vertDataSize)); + VertDataAdd(q, _edge_getCoVert(e, v, curLvl, 1, vertDataSize), ss); } } - VertDataMulN(q, (float) 1 / sharpCount); + VertDataMulN(q, (float) 1 / sharpCount, ss); if (sharpCount != 2 || allSharp) { /* q = q + (co - q) * avgSharpness */ - VertDataCopy(r, co); - VertDataSub(r, q); - VertDataMulN(r, avgSharpness); - VertDataAdd(q, r); + VertDataCopy(r, co, ss); + VertDataSub(r, q, ss); + VertDataMulN(r, avgSharpness, ss); + VertDataAdd(q, r, ss); } /* r = co * 0.75 + q * 0.25 */ - VertDataCopy(r, co); - VertDataMulN(r, .75f); - VertDataMulN(q, .25f); - VertDataAdd(r, q); + VertDataCopy(r, co, ss); + VertDataMulN(r, .75f, ss); + VertDataMulN(q, .25f, ss); + VertDataAdd(r, q, ss); /* nCo = nCo + (r - nCo) * avgSharpness */ - VertDataSub(r, nCo); - VertDataMulN(r, avgSharpness); - VertDataAdd(nCo, r); + VertDataSub(r, nCo, ss); + VertDataMulN(r, avgSharpness, ss); + VertDataAdd(nCo, r, ss); } } @@ -1858,13 +1917,13 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, int fx = x * 2; void *co = EDGE_getCo(e, curLvl, x); 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.5f); - VertDataCopy(nCo, co); - VertDataMulN(nCo, 0.75f); - VertDataMulN(r, 0.25f); - VertDataAdd(nCo, r); + VertDataCopy(r, EDGE_getCo(e, curLvl, x - 1), ss); + VertDataAdd(r, EDGE_getCo(e, curLvl, x + 1), ss); + VertDataMulN(r, 0.5f, ss); + VertDataCopy(nCo, co, ss); + VertDataMulN(nCo, 0.75f, ss); + VertDataMulN(r, 0.25f, ss); + VertDataAdd(nCo, r, ss); } } else { @@ -1874,38 +1933,38 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, void *nCo = EDGE_getCo(e, nextLvl, fx); int numFaces = 0; - VertDataZero(q); - VertDataZero(r); - VertDataAdd(r, EDGE_getCo(e, curLvl, x - 1)); - VertDataAdd(r, EDGE_getCo(e, curLvl, x + 1)); + VertDataZero(q, ss); + VertDataZero(r, ss); + VertDataAdd(r, EDGE_getCo(e, curLvl, x - 1), ss); + VertDataAdd(r, EDGE_getCo(e, curLvl, x + 1), ss); for (j = 0; j < e->numFaces; j++) { CCGFace *f = e->faces[j]; int f_ed_idx = _face_getEdgeIndex(f, e); - VertDataAdd(q, _face_getIFCoEdge(f, e, f_ed_idx, nextLvl, fx - 1, 1, subdivLevels, vertDataSize)); - VertDataAdd(q, _face_getIFCoEdge(f, e, f_ed_idx, nextLvl, fx + 1, 1, subdivLevels, vertDataSize)); + VertDataAdd(q, _face_getIFCoEdge(f, e, f_ed_idx, nextLvl, fx - 1, 1, subdivLevels, vertDataSize), ss); + VertDataAdd(q, _face_getIFCoEdge(f, e, f_ed_idx, nextLvl, fx + 1, 1, subdivLevels, vertDataSize), ss); - VertDataAdd(r, _face_getIFCoEdge(f, e, f_ed_idx, curLvl, x, 1, subdivLevels, vertDataSize)); + VertDataAdd(r, _face_getIFCoEdge(f, e, f_ed_idx, curLvl, x, 1, subdivLevels, vertDataSize), ss); numFaces++; } - VertDataMulN(q, 1.0f / (numFaces * 2.0f)); - VertDataMulN(r, 1.0f / (2.0f + numFaces)); + VertDataMulN(q, 1.0f / (numFaces * 2.0f), ss); + VertDataMulN(r, 1.0f / (2.0f + numFaces), ss); - VertDataCopy(nCo, co); - VertDataMulN(nCo, (float) numFaces); - VertDataAdd(nCo, q); - VertDataAdd(nCo, r); - VertDataMulN(nCo, 1.0f / (2 + numFaces)); + VertDataCopy(nCo, co, ss); + VertDataMulN(nCo, (float) numFaces, ss); + VertDataAdd(nCo, q, ss); + VertDataAdd(nCo, r, ss); + VertDataMulN(nCo, 1.0f / (2 + numFaces), ss); if (sharpCount == 2) { - VertDataCopy(q, co); - VertDataMulN(q, 6.0f); - VertDataAdd(q, EDGE_getCo(e, curLvl, x - 1)); - VertDataAdd(q, EDGE_getCo(e, curLvl, x + 1)); - VertDataMulN(q, 1 / 8.0f); - - VertDataSub(q, nCo); - VertDataMulN(q, avgSharpness); - VertDataAdd(nCo, q); + VertDataCopy(q, co, ss); + VertDataMulN(q, 6.0f, ss); + VertDataAdd(q, EDGE_getCo(e, curLvl, x - 1), ss); + VertDataAdd(q, EDGE_getCo(e, curLvl, x + 1), ss); + VertDataMulN(q, 1 / 8.0f, ss); + + VertDataSub(q, nCo, ss); + VertDataMulN(q, avgSharpness, ss); + VertDataAdd(nCo, q, ss); } } } @@ -1931,21 +1990,21 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, * - old interior edge points * - new interior face midpoints */ - VertDataZero(q); + VertDataZero(q, ss); for (S = 0; S < f->numVerts; S++) { - VertDataAdd(q, FACE_getIFCo(f, nextLvl, S, 1, 1)); + VertDataAdd(q, FACE_getIFCo(f, nextLvl, S, 1, 1), ss); } - VertDataMulN(q, 1.0f / f->numVerts); - VertDataZero(r); + VertDataMulN(q, 1.0f / f->numVerts, ss); + VertDataZero(r, ss); for (S = 0; S < f->numVerts; S++) { - VertDataAdd(r, FACE_getIECo(f, curLvl, S, 1)); + VertDataAdd(r, FACE_getIECo(f, curLvl, S, 1), ss); } - VertDataMulN(r, 1.0f / f->numVerts); + VertDataMulN(r, 1.0f / f->numVerts, ss); - VertDataMulN(FACE_getCenterData(f), f->numVerts - 2.0f); - VertDataAdd(FACE_getCenterData(f), q); - VertDataAdd(FACE_getCenterData(f), r); - VertDataMulN(FACE_getCenterData(f), 1.0f / f->numVerts); + VertDataMulN((float*)FACE_getCenterData(f), f->numVerts - 2.0f, ss); + VertDataAdd((float*)FACE_getCenterData(f), q, ss); + VertDataAdd((float*)FACE_getCenterData(f), r, ss); + VertDataMulN((float*)FACE_getCenterData(f), 1.0f / f->numVerts, ss); for (S = 0; S < f->numVerts; S++) { /* interior face shift @@ -1964,18 +2023,20 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, FACE_getIFCo(f, nextLvl, S, fx - 1, fy - 1), FACE_getIFCo(f, nextLvl, S, fx + 1, fy - 1), FACE_getIFCo(f, nextLvl, S, fx + 1, fy + 1), - FACE_getIFCo(f, nextLvl, S, fx - 1, fy + 1)); + FACE_getIFCo(f, nextLvl, S, fx - 1, fy + 1), + ss); VertDataAvg4(r, FACE_getIFCo(f, nextLvl, S, fx - 1, fy + 0), FACE_getIFCo(f, nextLvl, S, fx + 1, fy + 0), FACE_getIFCo(f, nextLvl, S, fx + 0, fy - 1), - FACE_getIFCo(f, nextLvl, S, fx + 0, fy + 1)); + FACE_getIFCo(f, nextLvl, S, fx + 0, fy + 1), + ss); - VertDataCopy(nCo, co); - VertDataSub(nCo, q); - VertDataMulN(nCo, 0.25f); - VertDataAdd(nCo, r); + VertDataCopy(nCo, co, ss); + VertDataSub(nCo, q, ss); + VertDataMulN(nCo, 0.25f, ss); + VertDataAdd(nCo, r, ss); } } @@ -1993,18 +2054,19 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, FACE_getIFCo(f, nextLvl, (S + 1) % f->numVerts, 1, fx - 1), FACE_getIFCo(f, nextLvl, (S + 1) % f->numVerts, 1, fx + 1), FACE_getIFCo(f, nextLvl, S, fx + 1, +1), - FACE_getIFCo(f, nextLvl, S, fx - 1, +1)); + FACE_getIFCo(f, nextLvl, S, fx - 1, +1), ss); VertDataAvg4(r, FACE_getIECo(f, nextLvl, S, fx - 1), FACE_getIECo(f, nextLvl, S, fx + 1), FACE_getIFCo(f, nextLvl, (S + 1) % f->numVerts, 1, fx), - FACE_getIFCo(f, nextLvl, S, fx, 1)); + FACE_getIFCo(f, nextLvl, S, fx, 1), + ss); - VertDataCopy(nCo, co); - VertDataSub(nCo, q); - VertDataMulN(nCo, 0.25f); - VertDataAdd(nCo, r); + VertDataCopy(nCo, co, ss); + VertDataSub(nCo, q, ss); + VertDataMulN(nCo, 0.25f, ss); + VertDataAdd(nCo, r, ss); } } } @@ -2024,8 +2086,8 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, #pragma omp parallel for private(i) if (numEffectedF * edgeSize * edgeSize * 4 >= CCG_OMP_LIMIT) for (i = 0; i < numEffectedE; i++) { CCGEdge *e = effectedE[i]; - VertDataCopy(EDGE_getCo(e, nextLvl, 0), VERT_getCo(e->v0, nextLvl)); - VertDataCopy(EDGE_getCo(e, nextLvl, edgeSize - 1), VERT_getCo(e->v1, nextLvl)); + VertDataCopy(EDGE_getCo(e, nextLvl, 0), VERT_getCo(e->v0, nextLvl), ss); + VertDataCopy(EDGE_getCo(e, nextLvl, edgeSize - 1), VERT_getCo(e->v1, nextLvl), ss); } #pragma omp parallel for private(i) if (numEffectedF * edgeSize * edgeSize * 4 >= CCG_OMP_LIMIT) @@ -2037,19 +2099,19 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, CCGEdge *e = FACE_getEdges(f)[S]; CCGEdge *prevE = FACE_getEdges(f)[(S + f->numVerts - 1) % f->numVerts]; - VertDataCopy(FACE_getIFCo(f, nextLvl, S, 0, 0), FACE_getCenterData(f)); - VertDataCopy(FACE_getIECo(f, nextLvl, S, 0), FACE_getCenterData(f)); - VertDataCopy(FACE_getIFCo(f, nextLvl, S, cornerIdx, cornerIdx), VERT_getCo(FACE_getVerts(f)[S], nextLvl)); - VertDataCopy(FACE_getIECo(f, nextLvl, S, cornerIdx), EDGE_getCo(FACE_getEdges(f)[S], nextLvl, cornerIdx)); + VertDataCopy(FACE_getIFCo(f, nextLvl, S, 0, 0), (float*)FACE_getCenterData(f), ss); + VertDataCopy(FACE_getIECo(f, nextLvl, S, 0), (float*)FACE_getCenterData(f), ss); + VertDataCopy(FACE_getIFCo(f, nextLvl, S, cornerIdx, cornerIdx), VERT_getCo(FACE_getVerts(f)[S], nextLvl), ss); + VertDataCopy(FACE_getIECo(f, nextLvl, S, cornerIdx), EDGE_getCo(FACE_getEdges(f)[S], nextLvl, cornerIdx), ss); for (x = 1; x < gridSize - 1; x++) { void *co = FACE_getIECo(f, nextLvl, S, x); - VertDataCopy(FACE_getIFCo(f, nextLvl, S, x, 0), co); - VertDataCopy(FACE_getIFCo(f, nextLvl, (S + 1) % f->numVerts, 0, x), co); + VertDataCopy(FACE_getIFCo(f, nextLvl, S, x, 0), co, ss); + VertDataCopy(FACE_getIFCo(f, nextLvl, (S + 1) % f->numVerts, 0, x), co, ss); } for (x = 0; x < gridSize - 1; x++) { int eI = gridSize - 1 - x; - VertDataCopy(FACE_getIFCo(f, nextLvl, S, cornerIdx, x), _edge_getCoVert(e, FACE_getVerts(f)[S], nextLvl, eI, vertDataSize)); - VertDataCopy(FACE_getIFCo(f, nextLvl, S, x, cornerIdx), _edge_getCoVert(prevE, FACE_getVerts(f)[S], nextLvl, eI, vertDataSize)); + VertDataCopy(FACE_getIFCo(f, nextLvl, S, cornerIdx, x), _edge_getCoVert(e, FACE_getVerts(f)[S], nextLvl, eI, vertDataSize), ss); + VertDataCopy(FACE_getIFCo(f, nextLvl, S, x, cornerIdx), _edge_getCoVert(prevE, FACE_getVerts(f)[S], nextLvl, eI, vertDataSize), ss); } } } @@ -2103,11 +2165,11 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) for (ptrIdx = 0; ptrIdx < numEffectedF; ptrIdx++) { CCGFace *f = effectedF[ptrIdx]; void *co = FACE_getCenterData(f); - VertDataZero(co); + VertDataZero(co, ss); for (i = 0; i < f->numVerts; i++) { - VertDataAdd(co, VERT_getCo(FACE_getVerts(f)[i], curLvl)); + VertDataAdd(co, VERT_getCo(FACE_getVerts(f)[i], curLvl), ss); } - VertDataMulN(co, 1.0f / f->numVerts); + VertDataMulN(co, 1.0f / f->numVerts, ss); f->flags = 0; } @@ -2117,29 +2179,29 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) float sharpness = EDGE_getSharpness(e, curLvl); 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); + VertDataCopy(co, VERT_getCo(e->v0, curLvl), ss); + VertDataAdd(co, VERT_getCo(e->v1, curLvl), ss); + VertDataMulN(co, 0.5f, ss); } else { int numFaces = 0; - VertDataCopy(q, VERT_getCo(e->v0, curLvl)); - VertDataAdd(q, VERT_getCo(e->v1, curLvl)); + VertDataCopy(q, VERT_getCo(e->v0, curLvl), ss); + VertDataAdd(q, VERT_getCo(e->v1, curLvl), ss); for (i = 0; i < e->numFaces; i++) { CCGFace *f = e->faces[i]; - VertDataAdd(q, FACE_getCenterData(f)); + VertDataAdd(q, (float*)FACE_getCenterData(f), ss); numFaces++; } - VertDataMulN(q, 1.0f / (2.0f + numFaces)); + VertDataMulN(q, 1.0f / (2.0f + numFaces), ss); - VertDataCopy(r, VERT_getCo(e->v0, curLvl)); - VertDataAdd(r, VERT_getCo(e->v1, curLvl)); - VertDataMulN(r, 0.5f); + VertDataCopy(r, VERT_getCo(e->v0, curLvl), ss); + VertDataAdd(r, VERT_getCo(e->v1, curLvl), ss); + VertDataMulN(r, 0.5f, ss); - VertDataCopy(co, q); - VertDataSub(r, q); - VertDataMulN(r, sharpness); - VertDataAdd(co, r); + VertDataCopy(co, q, ss); + VertDataSub(r, q, ss); + VertDataMulN(r, sharpness, ss); + VertDataAdd(co, r, ss); } // edge flags cleared later @@ -2179,51 +2241,51 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) seam = 0; if (!v->numEdges) { - VertDataCopy(nCo, co); + VertDataCopy(nCo, co, ss); } else if (_vert_isBoundary(v)) { int numBoundary = 0; - VertDataZero(r); + VertDataZero(r, ss); for (i = 0; i < v->numEdges; i++) { CCGEdge *e = v->edges[i]; if (_edge_isBoundary(e)) { - VertDataAdd(r, VERT_getCo(_edge_getOtherVert(e, v), curLvl)); + VertDataAdd(r, VERT_getCo(_edge_getOtherVert(e, v), curLvl), ss); numBoundary++; } } - VertDataCopy(nCo, co); - VertDataMulN(nCo, 0.75f); - VertDataMulN(r, 0.25f / numBoundary); - VertDataAdd(nCo, r); + VertDataCopy(nCo, co, ss); + VertDataMulN(nCo, 0.75f, ss); + VertDataMulN(r, 0.25f / numBoundary, ss); + VertDataAdd(nCo, r, ss); } else { int numEdges = 0, numFaces = 0; - VertDataZero(q); + VertDataZero(q, ss); for (i = 0; i < v->numFaces; i++) { CCGFace *f = v->faces[i]; - VertDataAdd(q, FACE_getCenterData(f)); + VertDataAdd(q, (float*)FACE_getCenterData(f), ss); numFaces++; } - VertDataMulN(q, 1.0f / numFaces); - VertDataZero(r); + VertDataMulN(q, 1.0f / numFaces, ss); + VertDataZero(r, ss); for (i = 0; i < v->numEdges; i++) { CCGEdge *e = v->edges[i]; - VertDataAdd(r, VERT_getCo(_edge_getOtherVert(e, v), curLvl)); + VertDataAdd(r, VERT_getCo(_edge_getOtherVert(e, v), curLvl), ss); numEdges++; } - VertDataMulN(r, 1.0f / numEdges); + VertDataMulN(r, 1.0f / numEdges, ss); - VertDataCopy(nCo, co); - VertDataMulN(nCo, numEdges - 2.0f); - VertDataAdd(nCo, q); - VertDataAdd(nCo, r); - VertDataMulN(nCo, 1.0f / numEdges); + VertDataCopy(nCo, co, ss); + VertDataMulN(nCo, numEdges - 2.0f, ss); + VertDataAdd(nCo, q, ss); + VertDataAdd(nCo, r, ss); + VertDataMulN(nCo, 1.0f / numEdges, ss); } if (sharpCount > 1 || seam) { - VertDataZero(q); + VertDataZero(q, ss); if (seam) { avgSharpness = 1.0f; @@ -2238,35 +2300,35 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) if (seam) { if (_edge_isBoundary(e)) { CCGVert *oV = _edge_getOtherVert(e, v); - VertDataAdd(q, VERT_getCo(oV, curLvl)); + VertDataAdd(q, VERT_getCo(oV, curLvl), ss); } } else if (sharpness != 0.0f) { CCGVert *oV = _edge_getOtherVert(e, v); - VertDataAdd(q, VERT_getCo(oV, curLvl)); + VertDataAdd(q, VERT_getCo(oV, curLvl), ss); } } - VertDataMulN(q, (float) 1 / sharpCount); + VertDataMulN(q, (float) 1 / sharpCount, ss); if (sharpCount != 2 || allSharp) { /* q = q + (co - q) * avgSharpness */ - VertDataCopy(r, co); - VertDataSub(r, q); - VertDataMulN(r, avgSharpness); - VertDataAdd(q, r); + VertDataCopy(r, co, ss); + VertDataSub(r, q, ss); + VertDataMulN(r, avgSharpness, ss); + VertDataAdd(q, r, ss); } /* r = co * 0.75 + q * 0.25 */ - VertDataCopy(r, co); - VertDataMulN(r, 0.75f); - VertDataMulN(q, 0.25f); - VertDataAdd(r, q); + VertDataCopy(r, co, ss); + VertDataMulN(r, 0.75f, ss); + VertDataMulN(q, 0.25f, ss); + VertDataAdd(r, q, ss); /* nCo = nCo + (r - nCo) * avgSharpness */ - VertDataSub(r, nCo); - VertDataMulN(r, avgSharpness); - VertDataAdd(nCo, r); + VertDataSub(r, nCo, ss); + VertDataMulN(r, avgSharpness, ss); + VertDataAdd(nCo, r, ss); } // vert flags cleared later @@ -2294,8 +2356,8 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) for (i = 0; i < numEffectedE; i++) { CCGEdge *e = effectedE[i]; - VertDataCopy(EDGE_getCo(e, nextLvl, 0), VERT_getCo(e->v0, nextLvl)); - VertDataCopy(EDGE_getCo(e, nextLvl, 2), VERT_getCo(e->v1, nextLvl)); + VertDataCopy(EDGE_getCo(e, nextLvl, 0), VERT_getCo(e->v0, nextLvl), ss); + VertDataCopy(EDGE_getCo(e, nextLvl, 2), VERT_getCo(e->v1, nextLvl), ss); } for (i = 0; i < numEffectedF; i++) { CCGFace *f = effectedF[i]; @@ -2303,13 +2365,13 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) CCGEdge *e = FACE_getEdges(f)[S]; CCGEdge *prevE = FACE_getEdges(f)[(S + f->numVerts - 1) % f->numVerts]; - VertDataCopy(FACE_getIFCo(f, nextLvl, S, 0, 0), FACE_getCenterData(f)); - VertDataCopy(FACE_getIECo(f, nextLvl, S, 0), FACE_getCenterData(f)); - VertDataCopy(FACE_getIFCo(f, nextLvl, S, 1, 1), VERT_getCo(FACE_getVerts(f)[S], nextLvl)); - VertDataCopy(FACE_getIECo(f, nextLvl, S, 1), EDGE_getCo(FACE_getEdges(f)[S], nextLvl, 1)); + VertDataCopy(FACE_getIFCo(f, nextLvl, S, 0, 0), (float*)FACE_getCenterData(f), ss); + VertDataCopy(FACE_getIECo(f, nextLvl, S, 0), (float*)FACE_getCenterData(f), ss); + VertDataCopy(FACE_getIFCo(f, nextLvl, S, 1, 1), VERT_getCo(FACE_getVerts(f)[S], nextLvl), ss); + VertDataCopy(FACE_getIECo(f, nextLvl, S, 1), EDGE_getCo(FACE_getEdges(f)[S], nextLvl, 1), ss); - VertDataCopy(FACE_getIFCo(f, nextLvl, S, 1, 0), _edge_getCoVert(e, FACE_getVerts(f)[S], nextLvl, 1, vertDataSize)); - VertDataCopy(FACE_getIFCo(f, nextLvl, S, 0, 1), _edge_getCoVert(prevE, FACE_getVerts(f)[S], nextLvl, 1, vertDataSize)); + VertDataCopy(FACE_getIFCo(f, nextLvl, S, 1, 0), _edge_getCoVert(e, FACE_getVerts(f)[S], nextLvl, 1, vertDataSize), ss); + VertDataCopy(FACE_getIFCo(f, nextLvl, S, 0, 1), _edge_getCoVert(prevE, FACE_getVerts(f)[S], nextLvl, 1, vertDataSize), ss); } } @@ -2433,16 +2495,16 @@ CCGError ccgSubSurf_updateFromFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF CCGEdge *e = FACE_getEdges(f)[S]; CCGEdge *prevE = FACE_getEdges(f)[(S + f->numVerts - 1) % f->numVerts]; - VertDataCopy(FACE_getCenterData(f), FACE_getIFCo(f, lvl, S, 0, 0)); - VertDataCopy(VERT_getCo(FACE_getVerts(f)[S], lvl), FACE_getIFCo(f, lvl, S, cornerIdx, cornerIdx)); + VertDataCopy((float*)FACE_getCenterData(f), FACE_getIFCo(f, lvl, S, 0, 0), ss); + VertDataCopy(VERT_getCo(FACE_getVerts(f)[S], lvl), FACE_getIFCo(f, lvl, S, cornerIdx, cornerIdx), ss); for (x = 0; x < gridSize; x++) - VertDataCopy(FACE_getIECo(f, lvl, S, x), FACE_getIFCo(f, lvl, S, x, 0)); + VertDataCopy(FACE_getIECo(f, lvl, S, x), FACE_getIFCo(f, lvl, S, x, 0), ss); for (x = 0; x < gridSize; x++) { int eI = gridSize - 1 - x; - VertDataCopy(_edge_getCoVert(e, FACE_getVerts(f)[S], lvl, eI, vertDataSize), FACE_getIFCo(f, lvl, S, cornerIdx, x)); - VertDataCopy(_edge_getCoVert(prevE, FACE_getVerts(f)[S], lvl, eI, vertDataSize), FACE_getIFCo(f, lvl, S, x, cornerIdx)); + VertDataCopy(_edge_getCoVert(e, FACE_getVerts(f)[S], lvl, eI, vertDataSize), FACE_getIFCo(f, lvl, S, cornerIdx, x), ss); + VertDataCopy(_edge_getCoVert(prevE, FACE_getVerts(f)[S], lvl, eI, vertDataSize), FACE_getIFCo(f, lvl, S, x, cornerIdx), ss); } } } @@ -2475,17 +2537,17 @@ CCGError ccgSubSurf_updateToFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, for (x = 0; x < gridSize; x++) { int eI = gridSize - 1 - x; - VertDataCopy(FACE_getIFCo(f, lvl, S, cornerIdx, x), _edge_getCoVert(e, FACE_getVerts(f)[S], lvl, eI, vertDataSize)); - VertDataCopy(FACE_getIFCo(f, lvl, S, x, cornerIdx), _edge_getCoVert(prevE, FACE_getVerts(f)[S], lvl, eI, vertDataSize)); + VertDataCopy(FACE_getIFCo(f, lvl, S, cornerIdx, x), _edge_getCoVert(e, FACE_getVerts(f)[S], lvl, eI, vertDataSize), ss); + VertDataCopy(FACE_getIFCo(f, lvl, S, x, cornerIdx), _edge_getCoVert(prevE, FACE_getVerts(f)[S], lvl, eI, vertDataSize), ss); } for (x = 1; x < gridSize - 1; x++) { - VertDataCopy(FACE_getIFCo(f, lvl, S, 0, x), FACE_getIECo(f, lvl, prevS, x)); - VertDataCopy(FACE_getIFCo(f, lvl, S, x, 0), FACE_getIECo(f, lvl, S, x)); + VertDataCopy(FACE_getIFCo(f, lvl, S, 0, x), FACE_getIECo(f, lvl, prevS, x), ss); + VertDataCopy(FACE_getIFCo(f, lvl, S, x, 0), FACE_getIECo(f, lvl, S, x), ss); } - VertDataCopy(FACE_getIFCo(f, lvl, S, 0, 0), FACE_getCenterData(f)); - VertDataCopy(FACE_getIFCo(f, lvl, S, cornerIdx, cornerIdx), VERT_getCo(FACE_getVerts(f)[S], lvl)); + VertDataCopy(FACE_getIFCo(f, lvl, S, 0, 0), (float*)FACE_getCenterData(f), ss); + VertDataCopy(FACE_getIFCo(f, lvl, S, cornerIdx, cornerIdx), VERT_getCo(FACE_getVerts(f)[S], lvl), ss); } } @@ -2518,7 +2580,7 @@ CCGError ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, in for (i = 0; i < numEffectedV; i++) { CCGVert *v = effectedV[i]; if (v->numFaces) - VertDataZero(VERT_getCo(v, lvl)); + VertDataZero(VERT_getCo(v, lvl), ss); } for (i = 0; i < numEffectedE; i++) { @@ -2526,40 +2588,40 @@ CCGError ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, in if (e->numFaces) for (x = 0; x < edgeSize; x++) - VertDataZero(EDGE_getCo(e, lvl, x)); + VertDataZero(EDGE_getCo(e, lvl, x), ss); } /* add */ for (i = 0; i < numEffectedF; i++) { CCGFace *f = effectedF[i]; - VertDataZero(FACE_getCenterData(f)); + VertDataZero((float*)FACE_getCenterData(f), ss); for (S = 0; S < f->numVerts; S++) for (x = 0; x < gridSize; x++) - VertDataZero(FACE_getIECo(f, lvl, S, x)); + VertDataZero(FACE_getIECo(f, lvl, S, x), ss); for (S = 0; S < f->numVerts; S++) { int prevS = (S + f->numVerts - 1) % f->numVerts; CCGEdge *e = FACE_getEdges(f)[S]; CCGEdge *prevE = FACE_getEdges(f)[prevS]; - VertDataAdd(FACE_getCenterData(f), FACE_getIFCo(f, lvl, S, 0, 0)); + VertDataAdd((float*)FACE_getCenterData(f), FACE_getIFCo(f, lvl, S, 0, 0), ss); if (FACE_getVerts(f)[S]->flags & Vert_eEffected) - VertDataAdd(VERT_getCo(FACE_getVerts(f)[S], lvl), FACE_getIFCo(f, lvl, S, cornerIdx, cornerIdx)); + VertDataAdd(VERT_getCo(FACE_getVerts(f)[S], lvl), FACE_getIFCo(f, lvl, S, cornerIdx, cornerIdx), ss); for (x = 1; x < gridSize - 1; x++) { - VertDataAdd(FACE_getIECo(f, lvl, S, x), FACE_getIFCo(f, lvl, S, x, 0)); - VertDataAdd(FACE_getIECo(f, lvl, prevS, x), FACE_getIFCo(f, lvl, S, 0, x)); + VertDataAdd(FACE_getIECo(f, lvl, S, x), FACE_getIFCo(f, lvl, S, x, 0), ss); + VertDataAdd(FACE_getIECo(f, lvl, prevS, x), FACE_getIFCo(f, lvl, S, 0, x), ss); } for (x = 0; x < gridSize - 1; x++) { int eI = gridSize - 1 - x; if (FACE_getEdges(f)[S]->flags & Edge_eEffected) - VertDataAdd(_edge_getCoVert(e, FACE_getVerts(f)[S], lvl, eI, vertDataSize), FACE_getIFCo(f, lvl, S, cornerIdx, x)); + VertDataAdd(_edge_getCoVert(e, FACE_getVerts(f)[S], lvl, eI, vertDataSize), FACE_getIFCo(f, lvl, S, cornerIdx, x), ss); if (FACE_getEdges(f)[prevS]->flags & Edge_eEffected) if (x != 0) - VertDataAdd(_edge_getCoVert(prevE, FACE_getVerts(f)[S], lvl, eI, vertDataSize), FACE_getIFCo(f, lvl, S, x, cornerIdx)); + VertDataAdd(_edge_getCoVert(prevE, FACE_getVerts(f)[S], lvl, eI, vertDataSize), FACE_getIFCo(f, lvl, S, x, cornerIdx), ss); } } } @@ -2568,51 +2630,52 @@ CCGError ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, in for (i = 0; i < numEffectedV; i++) { CCGVert *v = effectedV[i]; if (v->numFaces) - VertDataMulN(VERT_getCo(v, lvl), 1.0f / v->numFaces); + VertDataMulN(VERT_getCo(v, lvl), 1.0f / v->numFaces, ss); } for (i = 0; i < numEffectedE; i++) { CCGEdge *e = effectedE[i]; - VertDataCopy(EDGE_getCo(e, lvl, 0), VERT_getCo(e->v0, lvl)); - VertDataCopy(EDGE_getCo(e, lvl, edgeSize - 1), VERT_getCo(e->v1, lvl)); + VertDataCopy(EDGE_getCo(e, lvl, 0), VERT_getCo(e->v0, lvl), ss); + VertDataCopy(EDGE_getCo(e, lvl, edgeSize - 1), VERT_getCo(e->v1, lvl), ss); if (e->numFaces) for (x = 1; x < edgeSize - 1; x++) - VertDataMulN(EDGE_getCo(e, lvl, x), 1.0f / e->numFaces); + VertDataMulN(EDGE_getCo(e, lvl, x), 1.0f / e->numFaces, ss); } /* copy */ for (i = 0; i < numEffectedF; i++) { CCGFace *f = effectedF[i]; - VertDataMulN(FACE_getCenterData(f), 1.0f / f->numVerts); + VertDataMulN((float*)FACE_getCenterData(f), 1.0f / f->numVerts, ss); for (S = 0; S < f->numVerts; S++) for (x = 1; x < gridSize - 1; x++) - VertDataMulN(FACE_getIECo(f, lvl, S, x), 0.5f); + VertDataMulN(FACE_getIECo(f, lvl, S, x), 0.5f, ss); for (S = 0; S < f->numVerts; S++) { int prevS = (S + f->numVerts - 1) % f->numVerts; CCGEdge *e = FACE_getEdges(f)[S]; CCGEdge *prevE = FACE_getEdges(f)[prevS]; - VertDataCopy(FACE_getIFCo(f, lvl, S, 0, 0), FACE_getCenterData(f)); - VertDataCopy(FACE_getIFCo(f, lvl, S, cornerIdx, cornerIdx), VERT_getCo(FACE_getVerts(f)[S], lvl)); + VertDataCopy(FACE_getIFCo(f, lvl, S, 0, 0), (float*)FACE_getCenterData(f), ss); + VertDataCopy(FACE_getIFCo(f, lvl, S, cornerIdx, cornerIdx), VERT_getCo(FACE_getVerts(f)[S], lvl), ss); for (x = 1; x < gridSize - 1; x++) { - VertDataCopy(FACE_getIFCo(f, lvl, S, x, 0), FACE_getIECo(f, lvl, S, x)); - VertDataCopy(FACE_getIFCo(f, lvl, S, 0, x), FACE_getIECo(f, lvl, prevS, x)); + VertDataCopy(FACE_getIFCo(f, lvl, S, x, 0), FACE_getIECo(f, lvl, S, x), ss); + VertDataCopy(FACE_getIFCo(f, lvl, S, 0, x), FACE_getIECo(f, lvl, prevS, x), ss); } for (x = 0; x < gridSize - 1; x++) { int eI = gridSize - 1 - x; - VertDataCopy(FACE_getIFCo(f, lvl, S, cornerIdx, x), _edge_getCoVert(e, FACE_getVerts(f)[S], lvl, eI, vertDataSize)); - VertDataCopy(FACE_getIFCo(f, lvl, S, x, cornerIdx), _edge_getCoVert(prevE, FACE_getVerts(f)[S], lvl, eI, vertDataSize)); + + VertDataCopy(FACE_getIFCo(f, lvl, S, cornerIdx, x), _edge_getCoVert(e, FACE_getVerts(f)[S], lvl, eI, vertDataSize), ss); + VertDataCopy(FACE_getIFCo(f, lvl, S, x, cornerIdx), _edge_getCoVert(prevE, FACE_getVerts(f)[S], lvl, eI, vertDataSize), ss); } - VertDataCopy(FACE_getIECo(f, lvl, S, 0), FACE_getCenterData(f)); - VertDataCopy(FACE_getIECo(f, lvl, S, gridSize - 1), FACE_getIFCo(f, lvl, S, gridSize - 1, 0)); + VertDataCopy(FACE_getIECo(f, lvl, S, 0), (float*)FACE_getCenterData(f), ss); + VertDataCopy(FACE_getIECo(f, lvl, S, gridSize - 1), FACE_getIFCo(f, lvl, S, gridSize - 1, 0), ss); } } @@ -3051,3 +3114,36 @@ int ccgSubSurf_getNumFinalFaces(const CCGSubSurf *ss) int numFinalFaces = ss->numGrids * ((gridSize - 1) * (gridSize - 1)); return numFinalFaces; } + +/***/ + +void CCG_key(CCGKey *key, const CCGSubSurf *ss, int level) +{ + key->level = level; + + key->elem_size = ss->meshIFC.vertDataSize; + key->has_normals = ss->calcVertNormals; + key->num_layers = ss->meshIFC.numLayers; + + /* if normals are present, always the last three floats of an + element */ + if (key->has_normals) + key->normal_offset = key->elem_size - sizeof(float) * 3; + else + key->normal_offset = -1; + + key->grid_size = ccgSubSurf_getGridLevelSize(ss, level); + key->grid_area = key->grid_size * key->grid_size; + key->grid_bytes = key->elem_size * key->grid_area; + + key->has_mask = ss->allocMask; + if (key->has_mask) + key->mask_offset = ss->maskDataOffset; + else + key->mask_offset = -1; +} + +void CCG_key_top_level(CCGKey *key, const CCGSubSurf *ss) +{ + CCG_key(key, ss, ccgSubSurf_getSubdivisionLevels(ss)); +} diff --git a/source/blender/blenkernel/intern/CCGSubSurf.h b/source/blender/blenkernel/intern/CCGSubSurf.h index e73ef6b543e..33b37ac281c 100644 --- a/source/blender/blenkernel/intern/CCGSubSurf.h +++ b/source/blender/blenkernel/intern/CCGSubSurf.h @@ -15,7 +15,7 @@ typedef struct CCGFace CCGFace; typedef struct CCGMeshIFC { int vertUserSize, edgeUserSize, faceUserSize; - + int numLayers; int vertDataSize; } CCGMeshIFC; @@ -76,6 +76,9 @@ void ccgSubSurf_getUseAgeCounts (CCGSubSurf *ss, int *useAgeCounts_r, int *ve CCGError ccgSubSurf_setUseAgeCounts (CCGSubSurf *ss, int useAgeCounts, int vertUserOffset, int edgeUserOffset, int faceUserOffset); CCGError ccgSubSurf_setCalcVertexNormals (CCGSubSurf *ss, int useVertNormals, int normalDataOffset); +void ccgSubSurf_setAllocMask (CCGSubSurf *ss, int allocMask, int maskOffset); + +void ccgSubSurf_setNumLayers (CCGSubSurf *ss, int numLayers); /***/ diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index f648a9e297c..50c10ea3c3d 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -446,10 +446,10 @@ void DM_update_tessface_data(DerivedMesh *dm) not_done--; } } - mesh_loops_to_mface_corners(fdata, ldata, pdata, - ml_idx, mf_idx, polyindex[mf_idx], - mf_len, - numTex, numCol, hasPCol, hasOrigSpace); + BKE_mesh_loops_to_mface_corners(fdata, ldata, pdata, + ml_idx, mf_idx, polyindex[mf_idx], + mf_len, + numTex, numCol, hasPCol, hasOrigSpace); } if (G.debug & G_DEBUG) @@ -814,7 +814,7 @@ DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob, int numVerts; float (*deformedVerts)[3] = mesh_getVertexCos(me, &numVerts); - mti->deformVerts(md, ob, NULL, deformedVerts, numVerts, 0, 0); + mti->deformVerts(md, ob, NULL, deformedVerts, numVerts, 0); dm = mesh_create_derived(me, ob, deformedVerts); if (build_shapekey_layers) @@ -828,7 +828,7 @@ DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob, if (build_shapekey_layers) add_shapekey_layers(tdm, me, ob); - dm = mti->applyModifier(md, ob, tdm, 0, 0); + dm = mti->applyModifier(md, ob, tdm, 0); if (tdm != dm) tdm->release(tdm); } @@ -870,7 +870,7 @@ static void *get_orco_coords_dm(Object *ob, BMEditMesh *em, int layer, int *free if (em) return (float(*)[3])get_editbmesh_orco_verts(em); else - return (float(*)[3])get_mesh_orco_verts(ob); + return (float(*)[3])BKE_mesh_orco_verts_get(ob); } else if (layer == CD_CLOTH_ORCO) { /* apply shape key for cloth, this should really be solved @@ -932,7 +932,7 @@ static void add_orco_dm(Object *ob, BMEditMesh *em, DerivedMesh *dm, if (orco) { if (layer == CD_ORCO) - transform_mesh_orco_verts(ob->data, orco, totvert, 0); + BKE_mesh_orco_verts_transform(ob->data, orco, totvert, 0); if (!(layerorco = DM_get_vert_data_layer(dm, layer))) { DM_add_vert_layer(dm, layer, CD_CALLOC, NULL); @@ -1383,6 +1383,13 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos /* XXX Same as above... For now, only weights preview in WPaint mode. */ const int do_mod_wmcol = do_init_wmcol; + ModifierApplyFlag app_flags = useRenderParams ? MOD_APPLY_RENDER : 0; + ModifierApplyFlag deform_app_flags = app_flags; + if (useCache) + app_flags |= MOD_APPLY_USECACHE; + if (useDeform) + deform_app_flags |= MOD_APPLY_USECACHE; + if (mmd && !mmd->sculptlvl) has_multires = 0; @@ -1434,7 +1441,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos if (!deformedVerts) deformedVerts = mesh_getVertexCos(me, &numVerts); - mti->deformVerts(md, ob, NULL, deformedVerts, numVerts, useRenderParams, useDeform); + mti->deformVerts(md, ob, NULL, deformedVerts, numVerts, deform_app_flags); } else { break; @@ -1547,7 +1554,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos } } - mti->deformVerts(md, ob, dm, deformedVerts, numVerts, useRenderParams, useDeform); + mti->deformVerts(md, ob, dm, deformedVerts, numVerts, deform_app_flags); } else { DerivedMesh *ndm; @@ -1622,7 +1629,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos } } - ndm = mti->applyModifier(md, ob, dm, useRenderParams, useCache); + ndm = mti->applyModifier(md, ob, dm, app_flags); if (ndm) { /* if the modifier returned a new dm, release the old one */ @@ -1645,7 +1652,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos nextmask &= ~CD_MASK_ORCO; DM_set_only_copy(orcodm, nextmask | CD_MASK_ORIGINDEX); - ndm = mti->applyModifier(md, ob, orcodm, useRenderParams, 0); + ndm = mti->applyModifier(md, ob, orcodm, app_flags & ~MOD_APPLY_USECACHE); if (ndm) { /* if the modifier returned a new dm, release the old one */ @@ -1661,7 +1668,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos nextmask &= ~CD_MASK_CLOTH_ORCO; DM_set_only_copy(clothorcodm, nextmask | CD_MASK_ORIGINDEX); - ndm = mti->applyModifier(md, ob, clothorcodm, useRenderParams, 0); + ndm = mti->applyModifier(md, ob, clothorcodm, app_flags & ~MOD_APPLY_USECACHE); if (ndm) { /* if the modifier returned a new dm, release the old one */ @@ -1928,7 +1935,8 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D if (mti->deformVertsEM) mti->deformVertsEM(md, ob, em, dm, deformedVerts, numVerts); - else mti->deformVerts(md, ob, dm, deformedVerts, numVerts, 0, 0); + else + mti->deformVerts(md, ob, dm, deformedVerts, numVerts, 0); } else { DerivedMesh *ndm; @@ -1971,7 +1979,7 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D if (mti->applyModifierEM) ndm = mti->applyModifierEM(md, ob, em, orcodm); else - ndm = mti->applyModifier(md, ob, orcodm, 0, 0); + ndm = mti->applyModifier(md, ob, orcodm, 0); if (ndm) { /* if the modifier returned a new dm, release the old one */ @@ -1995,7 +2003,7 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D if (mti->applyModifierEM) ndm = mti->applyModifierEM(md, ob, em, dm); else - ndm = mti->applyModifier(md, ob, dm, 0, 0); + ndm = mti->applyModifier(md, ob, dm, 0); if (ndm) { if (dm && dm != ndm) @@ -2097,7 +2105,7 @@ static void clear_mesh_caches(Object *ob) me->bb = NULL; } - freedisplist(&ob->disp); + BKE_displist_free(&ob->disp); if (ob->derivedFinal) { ob->derivedFinal->needsFree = 1; @@ -2111,7 +2119,7 @@ static void clear_mesh_caches(Object *ob) } if (ob->sculpt) { - object_sculpt_modifiers_changed(ob); + BKE_object_sculpt_modifiers_changed(ob); } } @@ -2666,7 +2674,7 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm) if (is_degenerate == 0) { copy_v2_v2(prev_edge, cur_edge); - ++i; + i++; } } } @@ -2725,7 +2733,7 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm) f2x_surf_area = len_v3(norm); fsurf_ratio = f2x_surf_area/f2x_area_uv; // tri area divided by texture area - ++nr_accumulated; + nr_accumulated++; dsum += (double)(fsurf_ratio); } } @@ -2884,7 +2892,7 @@ void DM_set_object_boundbox(Object *ob, DerivedMesh *dm) if (!ob->bb) ob->bb= MEM_callocN(sizeof(BoundBox), "DM-BoundBox"); - boundbox_set_from_min_max(ob->bb, min, max); + BKE_boundbox_init_from_minmax(ob->bb, min, max); } /* --- NAVMESH (begin) --- */ diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 5a2407ca56b..9e46d03a3ab 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -69,7 +69,7 @@ * - Pose is the local (object level) component of armature. The current * object pose is saved in files, and (will be) is presorted for dependency * - Actions have fewer (or other) channels, and write data to a Pose - * - Currently ob->pose data is controlled in where_is_pose only. The (recalc) + * - Currently ob->pose data is controlled in BKE_pose_where_is only. The (recalc) * event system takes care of calling that * - The NLA system (here too) uses Poses as interpolation format for Actions * - Therefore we assume poses to be static, and duplicates of poses have channels in @@ -83,14 +83,14 @@ bAction *add_empty_action(const char name[]) { bAction *act; - act= alloc_libblock(&G.main->action, ID_AC, name); + act = BKE_libblock_alloc(&G.main->action, ID_AC, name); return act; } /* .................................. */ -/* temp data for make_local_action */ +/* temp data for BKE_action_make_local */ typedef struct tMakeLocalActionContext { bAction *act; /* original action */ bAction *act_new; /* new action */ @@ -99,18 +99,18 @@ typedef struct tMakeLocalActionContext { int is_local; /* some action users were not libraries */ } tMakeLocalActionContext; -/* helper function for make_local_action() - local/lib init step */ +/* helper function for BKE_action_make_local() - local/lib init step */ static void make_localact_init_cb(ID *id, AnimData *adt, void *mlac_ptr) { tMakeLocalActionContext *mlac = (tMakeLocalActionContext *)mlac_ptr; if (adt->action == mlac->act) { - if (id->lib) mlac->is_lib= TRUE; - else mlac->is_local= TRUE; + if (id->lib) mlac->is_lib = TRUE; + else mlac->is_local = TRUE; } } -/* helper function for make_local_action() - change references */ +/* helper function for BKE_action_make_local() - change references */ static void make_localact_apply_cb(ID *id, AnimData *adt, void *mlac_ptr) { tMakeLocalActionContext *mlac = (tMakeLocalActionContext *)mlac_ptr; @@ -126,28 +126,28 @@ static void make_localact_apply_cb(ID *id, AnimData *adt, void *mlac_ptr) } // does copy_fcurve... -void make_local_action(bAction *act) +void BKE_action_make_local(bAction *act) { tMakeLocalActionContext mlac = {act, NULL, FALSE, FALSE}; - Main *bmain= G.main; + Main *bmain = G.main; - if (act->id.lib==NULL) + if (act->id.lib == NULL) return; // XXX: double-check this; it used to be just single-user check, but that was when fake-users were still default - if ((act->id.flag & LIB_FAKEUSER) && (act->id.us<=1)) { + if ((act->id.flag & LIB_FAKEUSER) && (act->id.us <= 1)) { id_clear_lib_data(bmain, &act->id); return; } BKE_animdata_main_cb(bmain, make_localact_init_cb, &mlac); - if (mlac.is_local && mlac.is_lib==FALSE) { + if (mlac.is_local && mlac.is_lib == FALSE) { id_clear_lib_data(bmain, &act->id); } else if (mlac.is_local && mlac.is_lib) { - mlac.act_new= copy_action(act); - mlac.act_new->id.us= 0; + mlac.act_new = BKE_action_copy(act); + mlac.act_new->id.us = 0; BKE_id_lib_local_paths(bmain, act->id.lib, &mlac.act_new->id); @@ -157,7 +157,7 @@ void make_local_action(bAction *act) /* .................................. */ -void free_action(bAction *act) +void BKE_action_free(bAction *act) { /* sanity check */ if (act == NULL) @@ -177,7 +177,7 @@ void free_action(bAction *act) /* .................................. */ -bAction *copy_action (bAction *src) +bAction *BKE_action_copy(bAction *src) { bAction *dst = NULL; bActionGroup *dgrp, *sgrp; @@ -185,29 +185,29 @@ bAction *copy_action (bAction *src) if (src == NULL) return NULL; - dst= copy_libblock(&src->id); + dst = BKE_libblock_copy(&src->id); /* duplicate the lists of groups and markers */ BLI_duplicatelist(&dst->groups, &src->groups); BLI_duplicatelist(&dst->markers, &src->markers); /* copy F-Curves, fixing up the links as we go */ - dst->curves.first= dst->curves.last= NULL; + dst->curves.first = dst->curves.last = NULL; - for (sfcu= src->curves.first; sfcu; sfcu= sfcu->next) { + for (sfcu = src->curves.first; sfcu; sfcu = sfcu->next) { /* duplicate F-Curve */ - dfcu= copy_fcurve(sfcu); + dfcu = copy_fcurve(sfcu); BLI_addtail(&dst->curves, dfcu); /* fix group links (kindof bad list-in-list search, but this is the most reliable way) */ - for (dgrp=dst->groups.first, sgrp=src->groups.first; dgrp && sgrp; dgrp=dgrp->next, sgrp=sgrp->next) { + for (dgrp = dst->groups.first, sgrp = src->groups.first; dgrp && sgrp; dgrp = dgrp->next, sgrp = sgrp->next) { if (sfcu->grp == sgrp) { - dfcu->grp= dgrp; + dfcu->grp = dgrp; if (dgrp->channels.first == sfcu) - dgrp->channels.first= dfcu; + dgrp->channels.first = dfcu; if (dgrp->channels.last == sfcu) - dgrp->channels.last= dfcu; + dgrp->channels.last = dfcu; break; } @@ -220,12 +220,12 @@ bAction *copy_action (bAction *src) /* *************** Action Groups *************** */ /* Get the active action-group for an Action */ -bActionGroup *get_active_actiongroup (bAction *act) +bActionGroup *get_active_actiongroup(bAction *act) { - bActionGroup *agrp= NULL; + bActionGroup *agrp = NULL; if (act && act->groups.first) { - for (agrp= act->groups.first; agrp; agrp= agrp->next) { + for (agrp = act->groups.first; agrp; agrp = agrp->next) { if (agrp->flag & AGRP_ACTIVE) break; } @@ -244,8 +244,8 @@ void set_active_action_group(bAction *act, bActionGroup *agrp, short select) return; /* Deactive all others */ - for (grp= act->groups.first; grp; grp= grp->next) { - if ((grp==agrp) && (select)) + for (grp = act->groups.first; grp; grp = grp->next) { + if ((grp == agrp) && (select)) grp->flag |= AGRP_ACTIVE; else grp->flag &= ~AGRP_ACTIVE; @@ -253,7 +253,7 @@ void set_active_action_group(bAction *act, bActionGroup *agrp, short select) } /* Add a new action group with the given name to the action */ -bActionGroup *action_groups_add_new (bAction *act, const char name[]) +bActionGroup *action_groups_add_new(bAction *act, const char name[]) { bActionGroup *agrp; @@ -303,7 +303,7 @@ void action_groups_add_channel(bAction *act, bActionGroup *agrp, FCurve *fcurve) * the lists will be in sync after linking */ if (agrp->channels.last == act->curves.last) - act->curves.last= fcurve; + act->curves.last = fcurve; /* link in the given F-Curve after the last F-Curve in the group, * which means that it should be able to fit in with the rest of the @@ -320,7 +320,7 @@ void action_groups_add_channel(bAction *act, bActionGroup *agrp, FCurve *fcurve) agrp->channels.first = agrp->channels.last = fcurve; /* step through the groups preceding this one, finding the F-Curve there to attach this one after */ - for (grp= agrp->prev; grp; grp= grp->prev) { + for (grp = agrp->prev; grp; grp = grp->prev) { /* if this group has F-Curves, we want weave the given one in right after the last channel there, * but via the Action's list not this group's list * - this is so that the F-Curve is in the right place in the Action, @@ -342,7 +342,7 @@ void action_groups_add_channel(bAction *act, bActionGroup *agrp, FCurve *fcurve) } /* set the F-Curve's new group */ - fcurve->grp= agrp; + fcurve->grp = agrp; } /* Remove the given channel from all groups */ @@ -354,28 +354,28 @@ void action_groups_remove_channel(bAction *act, FCurve *fcu) /* check if any group used this directly */ if (fcu->grp) { - bActionGroup *agrp= fcu->grp; + bActionGroup *agrp = fcu->grp; if (agrp->channels.first == agrp->channels.last) { if (agrp->channels.first == fcu) { - agrp->channels.first= NULL; - agrp->channels.last= NULL; + agrp->channels.first = NULL; + agrp->channels.last = NULL; } } else if (agrp->channels.first == fcu) { - if ((fcu->next) && (fcu->next->grp==agrp)) - agrp->channels.first= fcu->next; + if ((fcu->next) && (fcu->next->grp == agrp)) + agrp->channels.first = fcu->next; else - agrp->channels.first= NULL; + agrp->channels.first = NULL; } else if (agrp->channels.last == fcu) { - if ((fcu->prev) && (fcu->prev->grp==agrp)) - agrp->channels.last= fcu->prev; + if ((fcu->prev) && (fcu->prev->grp == agrp)) + agrp->channels.last = fcu->prev; else - agrp->channels.last= NULL; + agrp->channels.last = NULL; } - fcu->grp= NULL; + fcu->grp = NULL; } /* now just remove from list */ @@ -383,7 +383,7 @@ void action_groups_remove_channel(bAction *act, FCurve *fcu) } /* Find a group with the given name */ -bActionGroup *action_groups_find_named (bAction *act, const char name[]) +bActionGroup *BKE_action_group_find_name(bAction *act, const char name[]) { /* sanity checks */ if (ELEM3(NULL, act, act->groups.first, name) || (name[0] == 0)) @@ -410,7 +410,7 @@ void action_groups_clear_tempflags(bAction *act) /* *************** Pose channels *************** */ /* usually used within a loop, so we got a N^2 slowdown */ -bPoseChannel *get_pose_channel(const bPose *pose, const char *name) +bPoseChannel *BKE_pose_channel_find_name(const bPose *pose, const char *name) { if (ELEM(NULL, pose, name) || (name[0] == 0)) return NULL; @@ -423,7 +423,7 @@ bPoseChannel *get_pose_channel(const bPose *pose, const char *name) /* Use with care, not on Armature poses but for temporal ones */ /* (currently used for action constraints and in rebuild_pose) */ -bPoseChannel *verify_pose_channel(bPose *pose, const char *name) +bPoseChannel *BKE_pose_channel_verify(bPose *pose, const char *name) { bPoseChannel *chan; @@ -431,7 +431,7 @@ bPoseChannel *verify_pose_channel(bPose *pose, const char *name) return NULL; /* See if this channel exists */ - chan= BLI_findstring(&pose->chanbase, name, offsetof(bPoseChannel, name)); + chan = BLI_findstring(&pose->chanbase, name, offsetof(bPoseChannel, name)); if (chan) { return chan; } @@ -445,24 +445,24 @@ bPoseChannel *verify_pose_channel(bPose *pose, const char *name) unit_axis_angle(chan->rotAxis, &chan->rotAngle); chan->size[0] = chan->size[1] = chan->size[2] = 1.0f; - chan->limitmin[0]= chan->limitmin[1]= chan->limitmin[2]= -180.0f; - chan->limitmax[0]= chan->limitmax[1]= chan->limitmax[2]= 180.0f; - chan->stiffness[0]= chan->stiffness[1]= chan->stiffness[2]= 0.0f; + chan->limitmin[0] = chan->limitmin[1] = chan->limitmin[2] = -180.0f; + chan->limitmax[0] = chan->limitmax[1] = chan->limitmax[2] = 180.0f; + chan->stiffness[0] = chan->stiffness[1] = chan->stiffness[2] = 0.0f; chan->ikrotweight = chan->iklinweight = 0.0f; unit_m4(chan->constinv); - chan->protectflag = OB_LOCK_ROT4D; /* lock by components by default */ + chan->protectflag = OB_LOCK_ROT4D; /* lock by components by default */ BLI_addtail(&pose->chanbase, chan); - free_pose_channels_hash(pose); + BKE_pose_channels_hash_free(pose); return chan; } /* Find the active posechannel for an object (we can't just use pose, as layer info is in armature) */ -bPoseChannel *get_active_posechannel (Object *ob) +bPoseChannel *BKE_pose_channel_active(Object *ob) { - bArmature *arm= (ob) ? ob->data : NULL; + bArmature *arm = (ob) ? ob->data : NULL; bPoseChannel *pchan; if (ELEM3(NULL, ob, ob->pose, arm)) { @@ -470,7 +470,7 @@ bPoseChannel *get_active_posechannel (Object *ob) } /* find active */ - for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { + for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { if ((pchan->bone) && (pchan->bone == arm->act_bone) && (pchan->bone->layer & arm->layer)) return pchan; } @@ -478,37 +478,37 @@ bPoseChannel *get_active_posechannel (Object *ob) return NULL; } -const char *get_ikparam_name(bPose *pose) +const char *BKE_pose_ikparam_get_name(bPose *pose) { if (pose) { switch (pose->iksolver) { - case IKSOLVER_LEGACY: - return NULL; - case IKSOLVER_ITASC: - return "bItasc"; + case IKSOLVER_LEGACY: + return NULL; + case IKSOLVER_ITASC: + return "bItasc"; } } return NULL; } /* dst should be freed already, makes entire duplicate */ -void copy_pose(bPose **dst, bPose *src, int copycon) +void BKE_pose_copy_data(bPose **dst, bPose *src, int copycon) { bPose *outPose; bPoseChannel *pchan; ListBase listb; if (!src) { - *dst=NULL; + *dst = NULL; return; } - if (*dst==src) { - printf("copy_pose source and target are the same\n"); - *dst=NULL; + if (*dst == src) { + printf("BKE_pose_copy_data source and target are the same\n"); + *dst = NULL; return; } - outPose= MEM_callocN(sizeof(bPose), "pose"); + outPose = MEM_callocN(sizeof(bPose), "pose"); BLI_duplicatelist(&outPose->chanbase, &src->chanbase); @@ -516,16 +516,16 @@ void copy_pose(bPose **dst, bPose *src, int copycon) outPose->ikdata = NULL; outPose->ikparam = MEM_dupallocN(src->ikparam); - for (pchan=outPose->chanbase.first; pchan; pchan=pchan->next) { + for (pchan = outPose->chanbase.first; pchan; pchan = pchan->next) { // TODO: rename this argument... if (copycon) { copy_constraints(&listb, &pchan->constraints, TRUE); // copy_constraints NULLs listb - pchan->constraints= listb; - pchan->mpath= NULL; /* motion paths should not get copied yet... */ + pchan->constraints = listb; + pchan->mpath = NULL; /* motion paths should not get copied yet... */ } if (pchan->prop) { - pchan->prop= IDP_CopyProperty(pchan->prop); + pchan->prop = IDP_CopyProperty(pchan->prop); } } @@ -533,10 +533,10 @@ void copy_pose(bPose **dst, bPose *src, int copycon) if (copycon) BLI_duplicatelist(&outPose->agroups, &src->agroups); - *dst=outPose; + *dst = outPose; } -void init_pose_itasc(bItasc *itasc) +void BKE_pose_itasc_init(bItasc *itasc) { if (itasc) { itasc->iksolver = IKSOLVER_ITASC; @@ -545,7 +545,7 @@ void init_pose_itasc(bItasc *itasc) itasc->numiter = 100; itasc->numstep = 4; itasc->precision = 0.005f; - itasc->flag = ITASC_AUTO_STEP|ITASC_INITIAL_REITERATION; + itasc->flag = ITASC_AUTO_STEP | ITASC_INITIAL_REITERATION; itasc->feedback = 20.0f; itasc->maxvel = 50.0f; itasc->solver = ITASC_SOLVER_SDLS; @@ -553,48 +553,48 @@ void init_pose_itasc(bItasc *itasc) itasc->dampeps = 0.15; } } -void init_pose_ikparam(bPose *pose) +void BKE_pose_ikparam_init(bPose *pose) { bItasc *itasc; switch (pose->iksolver) { - case IKSOLVER_ITASC: - itasc = MEM_callocN(sizeof(bItasc), "itasc"); - init_pose_itasc(itasc); - pose->ikparam = itasc; - break; - case IKSOLVER_LEGACY: - default: - pose->ikparam = NULL; - break; + case IKSOLVER_ITASC: + itasc = MEM_callocN(sizeof(bItasc), "itasc"); + BKE_pose_itasc_init(itasc); + pose->ikparam = itasc; + break; + case IKSOLVER_LEGACY: + default: + pose->ikparam = NULL; + break; } } -void make_pose_channels_hash(bPose *pose) +void BKE_pose_channels_hash_make(bPose *pose) { if (!pose->chanhash) { bPoseChannel *pchan; - pose->chanhash= BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "make_pose_chan gh"); - for (pchan=pose->chanbase.first; pchan; pchan=pchan->next) + pose->chanhash = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "make_pose_chan gh"); + for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) BLI_ghash_insert(pose->chanhash, pchan->name, pchan); } } -void free_pose_channels_hash(bPose *pose) +void BKE_pose_channels_hash_free(bPose *pose) { if (pose->chanhash) { BLI_ghash_free(pose->chanhash, NULL, NULL); - pose->chanhash= NULL; + pose->chanhash = NULL; } } -void free_pose_channel(bPoseChannel *pchan) +void BKE_pose_channel_free(bPoseChannel *pchan) { if (pchan->mpath) { animviz_free_motionpath(pchan->mpath); - pchan->mpath= NULL; + pchan->mpath = NULL; } free_constraints(&pchan->constraints); @@ -605,25 +605,25 @@ void free_pose_channel(bPoseChannel *pchan) } } -void free_pose_channels(bPose *pose) +void BKE_pose_channels_free(bPose *pose) { bPoseChannel *pchan; if (pose->chanbase.first) { - for (pchan = pose->chanbase.first; pchan; pchan=pchan->next) - free_pose_channel(pchan); + for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) + BKE_pose_channel_free(pchan); BLI_freelistN(&pose->chanbase); } - free_pose_channels_hash(pose); + BKE_pose_channels_hash_free(pose); } -void free_pose(bPose *pose) +void BKE_pose_free(bPose *pose) { if (pose) { /* free pose-channels */ - free_pose_channels(pose); + BKE_pose_channels_free(pose); /* free pose-groups */ if (pose->agroups.first) @@ -649,24 +649,24 @@ static void copy_pose_channel_data(bPoseChannel *pchan, const bPoseChannel *chan copy_v3_v3(pchan->size, chan->size); copy_v3_v3(pchan->eul, chan->eul); copy_v3_v3(pchan->rotAxis, chan->rotAxis); - pchan->rotAngle= chan->rotAngle; + pchan->rotAngle = chan->rotAngle; copy_qt_qt(pchan->quat, chan->quat); - pchan->rotmode= chan->rotmode; + pchan->rotmode = chan->rotmode; copy_m4_m4(pchan->chan_mat, (float(*)[4])chan->chan_mat); copy_m4_m4(pchan->pose_mat, (float(*)[4])chan->pose_mat); - pchan->flag= chan->flag; + pchan->flag = chan->flag; - con= chan->constraints.first; - for (pcon= pchan->constraints.first; pcon && con; pcon= pcon->next, con= con->next) { - pcon->enforce= con->enforce; - pcon->headtail= con->headtail; + con = chan->constraints.first; + for (pcon = pchan->constraints.first; pcon && con; pcon = pcon->next, con = con->next) { + pcon->enforce = con->enforce; + pcon->headtail = con->headtail; } } /* makes copies of internal data, unlike copy_pose_channel_data which only * copies the pose state. - * hint: use when copying bones in editmode (on returned value from verify_pose_channel) */ -void duplicate_pose_channel_data(bPoseChannel *pchan, const bPoseChannel *pchan_from) + * hint: use when copying bones in editmode (on returned value from BKE_pose_channel_verify) */ +void BKE_pose_channel_copy_data(bPoseChannel *pchan, const bPoseChannel *pchan_from) { /* copy transform locks */ pchan->protectflag = pchan_from->protectflag; @@ -675,16 +675,16 @@ void duplicate_pose_channel_data(bPoseChannel *pchan, const bPoseChannel *pchan_ pchan->rotmode = pchan_from->rotmode; /* copy bone group */ - pchan->agrp_index= pchan_from->agrp_index; + pchan->agrp_index = pchan_from->agrp_index; /* ik (dof) settings */ pchan->ikflag = pchan_from->ikflag; copy_v3_v3(pchan->limitmin, pchan_from->limitmin); copy_v3_v3(pchan->limitmax, pchan_from->limitmax); copy_v3_v3(pchan->stiffness, pchan_from->stiffness); - pchan->ikstretch= pchan_from->ikstretch; - pchan->ikrotweight= pchan_from->ikrotweight; - pchan->iklinweight= pchan_from->iklinweight; + pchan->ikstretch = pchan_from->ikstretch; + pchan->ikrotweight = pchan_from->ikrotweight; + pchan->iklinweight = pchan_from->iklinweight; /* constraints */ copy_constraints(&pchan->constraints, &pchan_from->constraints, TRUE); @@ -694,14 +694,14 @@ void duplicate_pose_channel_data(bPoseChannel *pchan, const bPoseChannel *pchan_ /* unlikely but possible it exists */ IDP_FreeProperty(pchan->prop); MEM_freeN(pchan->prop); - pchan->prop= NULL; + pchan->prop = NULL; } if (pchan_from->prop) { - pchan->prop= IDP_CopyProperty(pchan_from->prop); + pchan->prop = IDP_CopyProperty(pchan_from->prop); } /* custom shape */ - pchan->custom= pchan_from->custom; + pchan->custom = pchan_from->custom; } @@ -709,45 +709,45 @@ void duplicate_pose_channel_data(bPoseChannel *pchan, const bPoseChannel *pchan_ * can do more constraints flags later */ /* pose should be entirely OK */ -void update_pose_constraint_flags(bPose *pose) +void BKE_pose_update_constraint_flags(bPose *pose) { bPoseChannel *pchan, *parchan; bConstraint *con; /* clear */ - for (pchan= pose->chanbase.first; pchan; pchan= pchan->next) { - pchan->constflag= 0; + for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { + pchan->constflag = 0; } pose->flag &= ~POSE_CONSTRAINTS_TIMEDEPEND; /* detect */ - for (pchan= pose->chanbase.first; pchan; pchan=pchan->next) { - for (con= pchan->constraints.first; con; con= con->next) { - if (con->type==CONSTRAINT_TYPE_KINEMATIC) { - bKinematicConstraint *data = (bKinematicConstraint*)con->data; + for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { + for (con = pchan->constraints.first; con; con = con->next) { + if (con->type == CONSTRAINT_TYPE_KINEMATIC) { + bKinematicConstraint *data = (bKinematicConstraint *)con->data; pchan->constflag |= PCHAN_HAS_IK; - if (data->tar==NULL || (data->tar->type==OB_ARMATURE && data->subtarget[0]==0)) + if (data->tar == NULL || (data->tar->type == OB_ARMATURE && data->subtarget[0] == 0)) pchan->constflag |= PCHAN_HAS_TARGET; /* negative rootbone = recalc rootbone index. used in do_versions */ - if (data->rootbone<0) { - data->rootbone= 0; + if (data->rootbone < 0) { + data->rootbone = 0; - if (data->flag & CONSTRAINT_IK_TIP) parchan= pchan; - else parchan= pchan->parent; + if (data->flag & CONSTRAINT_IK_TIP) parchan = pchan; + else parchan = pchan->parent; while (parchan) { data->rootbone++; - if ((parchan->bone->flag & BONE_CONNECTED)==0) + if ((parchan->bone->flag & BONE_CONNECTED) == 0) break; - parchan= parchan->parent; + parchan = parchan->parent; } } } else if (con->type == CONSTRAINT_TYPE_FOLLOWPATH) { - bFollowPathConstraint *data= (bFollowPathConstraint *)con->data; + bFollowPathConstraint *data = (bFollowPathConstraint *)con->data; /* for drawing constraint colors when color set allows this */ pchan->constflag |= PCHAN_HAS_CONST; @@ -755,7 +755,7 @@ void update_pose_constraint_flags(bPose *pose) /* if we have a valid target, make sure that this will get updated on frame-change * (needed for when there is no anim-data for this pose) */ - if ((data->tar) && (data->tar->type==OB_CURVE)) + if ((data->tar) && (data->tar->type == OB_CURVE)) pose->flag |= POSE_CONSTRAINTS_TIMEDEPEND; } else if (con->type == CONSTRAINT_TYPE_SPLINEIK) @@ -778,10 +778,10 @@ void framechange_poses_clear_unkeyed(void) /* This needs to be done for each object that has a pose */ // TODO: proxies may/may not be correctly handled here... (this needs checking) - for (ob= G.main->object.first; ob; ob= ob->id.next) { + for (ob = G.main->object.first; ob; ob = ob->id.next) { /* we only need to do this on objects with a pose */ - if ( (pose= ob->pose) ) { - for (pchan= pose->chanbase.first; pchan; pchan= pchan->next) { + if ( (pose = ob->pose) ) { + for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { if (pchan->bone) pchan->bone->flag &= ~BONE_UNKEYED; } @@ -792,26 +792,26 @@ void framechange_poses_clear_unkeyed(void) /* ************************** Bone Groups ************************** */ /* Adds a new bone-group */ -void pose_add_group(Object *ob) +void BKE_pose_add_group(Object *ob) { - bPose *pose= (ob) ? ob->pose : NULL; + bPose *pose = (ob) ? ob->pose : NULL; bActionGroup *grp; if (ELEM(NULL, ob, ob->pose)) return; - grp= MEM_callocN(sizeof(bActionGroup), "PoseGroup"); + grp = MEM_callocN(sizeof(bActionGroup), "PoseGroup"); BLI_strncpy(grp->name, "Group", sizeof(grp->name)); BLI_addtail(&pose->agroups, grp); BLI_uniquename(&pose->agroups, grp, "Group", '.', offsetof(bActionGroup, name), sizeof(grp->name)); - pose->active_group= BLI_countlist(&pose->agroups); + pose->active_group = BLI_countlist(&pose->agroups); } /* Remove the active bone-group */ -void pose_remove_group(Object *ob) +void BKE_pose_remove_group(Object *ob) { - bPose *pose= (ob) ? ob->pose : NULL; + bPose *pose = (ob) ? ob->pose : NULL; bActionGroup *grp = NULL; bPoseChannel *pchan; @@ -822,15 +822,15 @@ void pose_remove_group(Object *ob) return; /* get group to remove */ - grp= BLI_findlink(&pose->agroups, pose->active_group-1); + grp = BLI_findlink(&pose->agroups, pose->active_group - 1); if (grp) { /* adjust group references (the trouble of using indices!): * - firstly, make sure nothing references it * - also, make sure that those after this item get corrected */ - for (pchan= pose->chanbase.first; pchan; pchan= pchan->next) { + for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { if (pchan->agrp_index == pose->active_group) - pchan->agrp_index= 0; + pchan->agrp_index = 0; else if (pchan->agrp_index > pose->active_group) pchan->agrp_index--; } @@ -839,7 +839,7 @@ void pose_remove_group(Object *ob) BLI_freelinkN(&pose->agroups, grp); pose->active_group--; if (pose->active_group < 0 || pose->agroups.first == NULL) { - pose->active_group= 0; + pose->active_group = 0; } } } @@ -853,7 +853,7 @@ short action_has_motion(const bAction *act) /* return on the first F-Curve that has some keyframes/samples defined */ if (act) { - for (fcu= act->curves.first; fcu; fcu= fcu->next) { + for (fcu = act->curves.first; fcu; fcu = fcu->next) { if (fcu->totvert) return 1; } @@ -867,11 +867,11 @@ short action_has_motion(const bAction *act) void calc_action_range(const bAction *act, float *start, float *end, short incl_modifiers) { FCurve *fcu; - float min=999999999.0f, max=-999999999.0f; - short foundvert=0, foundmod=0; + float min = 999999999.0f, max = -999999999.0f; + short foundvert = 0, foundmod = 0; if (act) { - for (fcu= act->curves.first; fcu; fcu= fcu->next) { + for (fcu = act->curves.first; fcu; fcu = fcu->next) { /* if curve has keyframes, consider them first */ if (fcu->totvert) { float nmin, nmax; @@ -881,65 +881,65 @@ void calc_action_range(const bAction *act, float *start, float *end, short incl_ calc_fcurve_range(fcu, &nmin, &nmax, FALSE, TRUE); /* compare to the running tally */ - min= MIN2(min, nmin); - max= MAX2(max, nmax); + min = MIN2(min, nmin); + max = MAX2(max, nmax); - foundvert= 1; + foundvert = 1; } /* if incl_modifiers is enabled, need to consider modifiers too * - only really care about the last modifier */ if ((incl_modifiers) && (fcu->modifiers.last)) { - FModifier *fcm= fcu->modifiers.last; + FModifier *fcm = fcu->modifiers.last; /* only use the maximum sensible limits of the modifiers if they are more extreme */ switch (fcm->type) { case FMODIFIER_TYPE_LIMITS: /* Limits F-Modifier */ { - FMod_Limits *fmd= (FMod_Limits *)fcm->data; + FMod_Limits *fmd = (FMod_Limits *)fcm->data; if (fmd->flag & FCM_LIMIT_XMIN) { - min= MIN2(min, fmd->rect.xmin); + min = MIN2(min, fmd->rect.xmin); } if (fmd->flag & FCM_LIMIT_XMAX) { - max= MAX2(max, fmd->rect.xmax); + max = MAX2(max, fmd->rect.xmax); } } - break; + break; case FMODIFIER_TYPE_CYCLES: /* Cycles F-Modifier */ { - FMod_Cycles *fmd= (FMod_Cycles *)fcm->data; + FMod_Cycles *fmd = (FMod_Cycles *)fcm->data; if (fmd->before_mode != FCM_EXTRAPOLATE_NONE) - min= MINAFRAMEF; + min = MINAFRAMEF; if (fmd->after_mode != FCM_EXTRAPOLATE_NONE) - max= MAXFRAMEF; + max = MAXFRAMEF; } - break; + break; // TODO: function modifier may need some special limits default: /* all other standard modifiers are on the infinite range... */ - min= MINAFRAMEF; - max= MAXFRAMEF; + min = MINAFRAMEF; + max = MAXFRAMEF; break; } - foundmod= 1; + foundmod = 1; } } } if (foundvert || foundmod) { - if (min==max) max+= 1.0f; - *start= min; - *end= max; + if (min == max) max += 1.0f; + *start = min; + *end = max; } else { - *start= 0.0f; - *end= 1.0f; + *start = 0.0f; + *end = 1.0f; } } @@ -950,8 +950,8 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan, { PointerRNA ptr; FCurve *fcu; - char *basePath=NULL; - short flags=0; + char *basePath = NULL; + short flags = 0; /* build PointerRNA from provided data to obtain the paths to use */ if (pchan) @@ -962,15 +962,15 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan, return 0; /* get the basic path to the properties of interest */ - basePath= RNA_path_from_ID_to_struct(&ptr); + basePath = RNA_path_from_ID_to_struct(&ptr); if (basePath == NULL) return 0; /* search F-Curves for the given properties * - we cannot use the groups, since they may not be grouped in that way... */ - for (fcu= act->curves.first; fcu; fcu= fcu->next) { - char *bPtr=NULL, *pPtr=NULL; + for (fcu = act->curves.first; fcu; fcu = fcu->next) { + char *bPtr = NULL, *pPtr = NULL; /* if enough flags have been found, we can stop checking unless we're also getting the curves */ if ((flags == ACT_TRANS_ALL) && (curves == NULL)) @@ -981,7 +981,7 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan, continue; /* step 1: check for matching base path */ - bPtr= strstr(fcu->rna_path, basePath); + 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 @@ -991,13 +991,13 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan, /* 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 + * unless we're getting the curves too * - if we're getting the curves, the BLI_genericNodeN() creates a LinkData * node wrapping the F-Curve, which then gets added to the list * - once a match has been found, the curve cannot possibly be any other one */ if ((curves) || (flags & ACT_TRANS_LOC) == 0) { - pPtr= strstr(bPtr, "location"); + pPtr = strstr(bPtr, "location"); if (pPtr) { flags |= ACT_TRANS_LOC; @@ -1008,7 +1008,7 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan, } if ((curves) || (flags & ACT_TRANS_SCALE) == 0) { - pPtr= strstr(bPtr, "scale"); + pPtr = strstr(bPtr, "scale"); if (pPtr) { flags |= ACT_TRANS_SCALE; @@ -1019,7 +1019,7 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan, } if ((curves) || (flags & ACT_TRANS_ROT) == 0) { - pPtr= strstr(bPtr, "rotation"); + pPtr = strstr(bPtr, "rotation"); if (pPtr) { flags |= ACT_TRANS_ROT; @@ -1031,7 +1031,7 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan, if ((curves) || (flags & ACT_TRANS_PROP) == 0) { /* custom properties only */ - pPtr= strstr(bPtr, "[\""); /* extra '"' comment here to keep my texteditor functionlist working :) */ + pPtr = strstr(bPtr, "[\""); /* extra '"' comment here to keep my texteditor functionlist working :) */ if (pPtr) { flags |= ACT_TRANS_PROP; @@ -1059,20 +1059,20 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan, void extract_pose_from_pose(bPose *pose, const bPose *src) { const bPoseChannel *schan; - bPoseChannel *pchan= pose->chanbase.first; + bPoseChannel *pchan = pose->chanbase.first; - if (pose==src) { + if (pose == src) { printf("extract_pose_from_pose source and target are the same\n"); return; } - for (schan=src->chanbase.first; (schan && pchan); schan=schan->next, pchan= pchan->next) { + for (schan = src->chanbase.first; (schan && pchan); schan = schan->next, pchan = pchan->next) { copy_pose_channel_data(pchan, schan); } } /* for do_all_pose_actions, clears the pose. Now also exported for proxy and tools */ -void rest_pose(bPose *pose) +void BKE_pose_rest(bPose *pose) { bPoseChannel *pchan; @@ -1082,35 +1082,35 @@ void rest_pose(bPose *pose) memset(pose->stride_offset, 0, sizeof(pose->stride_offset)); memset(pose->cyclic_offset, 0, sizeof(pose->cyclic_offset)); - for (pchan=pose->chanbase.first; pchan; pchan= pchan->next) { + for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { zero_v3(pchan->loc); zero_v3(pchan->eul); unit_qt(pchan->quat); unit_axis_angle(pchan->rotAxis, &pchan->rotAngle); - pchan->size[0]= pchan->size[1]= pchan->size[2]= 1.0f; + pchan->size[0] = pchan->size[1] = pchan->size[2] = 1.0f; - pchan->flag &= ~(POSE_LOC|POSE_ROT|POSE_SIZE); + pchan->flag &= ~(POSE_LOC | POSE_ROT | POSE_SIZE); } } /* both poses should be in sync */ -void copy_pose_result(bPose *to, bPose *from) +void BKE_pose_copy_result(bPose *to, bPose *from) { bPoseChannel *pchanto, *pchanfrom; - if (to==NULL || from==NULL) { + if (to == NULL || from == NULL) { printf("pose result copy error to:%p from:%p\n", (void *)to, (void *)from); // debug temp return; } - if (to==from) { - printf("copy_pose_result source and target are the same\n"); + if (to == from) { + printf("BKE_pose_copy_result source and target are the same\n"); return; } - for (pchanfrom= from->chanbase.first; pchanfrom; pchanfrom= pchanfrom->next) { - pchanto= get_pose_channel(to, pchanfrom->name); + for (pchanfrom = from->chanbase.first; pchanfrom; pchanfrom = pchanfrom->next) { + pchanto = BKE_pose_channel_find_name(to, pchanfrom->name); if (pchanto) { copy_m4_m4(pchanto->pose_mat, pchanfrom->pose_mat); copy_m4_m4(pchanto->chan_mat, pchanfrom->chan_mat); @@ -1124,9 +1124,9 @@ void copy_pose_result(bPose *to, bPose *from) copy_v3_v3(pchanto->pose_head, pchanfrom->pose_head); copy_v3_v3(pchanto->pose_tail, pchanfrom->pose_tail); - pchanto->rotmode= pchanfrom->rotmode; - pchanto->flag= pchanfrom->flag; - pchanto->protectflag= pchanfrom->protectflag; + pchanto->rotmode = pchanfrom->rotmode; + pchanto->flag = pchanfrom->flag; + pchanto->protectflag = pchanfrom->protectflag; } } } @@ -1136,31 +1136,31 @@ void copy_pose_result(bPose *to, bPose *from) */ void what_does_obaction(Object *ob, Object *workob, bPose *pose, bAction *act, char groupname[], float cframe) { - bActionGroup *agrp= action_groups_find_named(act, groupname); + bActionGroup *agrp = BKE_action_group_find_name(act, groupname); /* clear workob */ - clear_workob(workob); + BKE_object_workob_clear(workob); /* init workob */ copy_m4_m4(workob->obmat, ob->obmat); copy_m4_m4(workob->parentinv, ob->parentinv); copy_m4_m4(workob->constinv, ob->constinv); - workob->parent= ob->parent; + workob->parent = ob->parent; - workob->rotmode= ob->rotmode; + workob->rotmode = ob->rotmode; - workob->trackflag= ob->trackflag; - workob->upflag= ob->upflag; + workob->trackflag = ob->trackflag; + workob->upflag = ob->upflag; - workob->partype= ob->partype; - workob->par1= ob->par1; - workob->par2= ob->par2; - workob->par3= ob->par3; + workob->partype = ob->partype; + workob->par1 = ob->par1; + workob->par2 = ob->par2; + workob->par3 = ob->par3; workob->constraints.first = ob->constraints.first; workob->constraints.last = ob->constraints.last; - workob->pose= pose; /* need to set pose too, since this is used for both types of Action Constraint */ + workob->pose = pose; /* need to set pose too, since this is used for both types of Action Constraint */ BLI_strncpy(workob->parsubstr, ob->parsubstr, sizeof(workob->parsubstr)); BLI_strncpy(workob->id.name, "OB<ConstrWorkOb>", sizeof(workob->id.name)); /* we don't use real object name, otherwise RNA screws with the real thing */ @@ -1177,13 +1177,13 @@ void what_does_obaction(Object *ob, Object *workob, bPose *pose, bAction *act, c animsys_evaluate_action_group(&id_ptr, act, agrp, NULL, cframe); } else { - AnimData adt= {NULL}; + AnimData adt = {NULL}; /* init animdata, and attach to workob */ - workob->adt= &adt; + workob->adt = &adt; - adt.recalc= ADT_RECALC_ANIM; - adt.action= act; + adt.recalc = ADT_RECALC_ANIM; + adt.action = act; /* execute effects of Action on to workob (or it's PoseChannels) */ BKE_animsys_evaluate_animdata(NULL, &workob->id, &adt, cframe, ADT_RECALC_ANIM); @@ -1207,7 +1207,7 @@ static void blend_pose_strides(bPose *dst, bPose *src, float srcweight, short mo case ACTSTRIPMODE_ADD: dstweight = 1.0F; break; - default : + default: dstweight = 1.0F; } @@ -1238,30 +1238,30 @@ static void blend_pose_offset_bone(bActionStrip *strip, bPose *dst, bPose *src, /* matching offset bones */ /* take dst offset, and put src on on that location */ - if (strip->offs_bone[0]==0) + if (strip->offs_bone[0] == 0) return; /* are we also blending with matching bones? */ - if (strip->prev && strip->start>=strip->prev->start) { - bPoseChannel *dpchan= get_pose_channel(dst, strip->offs_bone); + if (strip->prev && strip->start >= strip->prev->start) { + bPoseChannel *dpchan = BKE_pose_channel_find_name(dst, strip->offs_bone); if (dpchan) { - bPoseChannel *spchan= get_pose_channel(src, strip->offs_bone); + bPoseChannel *spchan = BKE_pose_channel_find_name(src, strip->offs_bone); if (spchan) { float vec[3]; /* dst->ctime has the internal strip->prev action time */ /* map this time to nla time */ - float ctime= get_actionstrip_frame(strip, src->ctime, 1); + float ctime = get_actionstrip_frame(strip, src->ctime, 1); - if ( ctime > strip->prev->end) { + if (ctime > strip->prev->end) { bActionChannel *achan; /* add src to dest, minus the position of src on strip->prev->end */ - ctime= get_actionstrip_frame(strip, strip->prev->end, 0); + ctime = get_actionstrip_frame(strip, strip->prev->end, 0); - achan= get_action_channel(strip->act, strip->offs_bone); + achan = get_action_channel(strip->act, strip->offs_bone); if (achan && achan->ipo) { bPoseChannel pchan; /* Evaluates and sets the internal ipo value */ @@ -1298,63 +1298,63 @@ static void blend_pose_offset_bone(bActionStrip *strip, bPose *dst, bPose *src, */ static float stridechannel_frame(Object *ob, float sizecorr, bActionStrip *strip, Path *path, float pathdist, float *stride_offset) { - bAction *act= strip->act; - const char *name= strip->stridechannel; - bActionChannel *achan= get_action_channel(act, name); - int stride_axis= strip->stride_axis; + bAction *act = strip->act; + const char *name = strip->stridechannel; + bActionChannel *achan = get_action_channel(act, name); + int stride_axis = strip->stride_axis; if (achan && achan->ipo) { - IpoCurve *icu= NULL; - float minx=0.0f, maxx=0.0f, miny=0.0f, maxy=0.0f; - int foundvert= 0; - - if (stride_axis==0) stride_axis= AC_LOC_X; - else if (stride_axis==1) stride_axis= AC_LOC_Y; - else stride_axis= AC_LOC_Z; + IpoCurve *icu = NULL; + float minx = 0.0f, maxx = 0.0f, miny = 0.0f, maxy = 0.0f; + int foundvert = 0; + + if (stride_axis == 0) stride_axis = AC_LOC_X; + else if (stride_axis == 1) stride_axis = AC_LOC_Y; + else stride_axis = AC_LOC_Z; /* calculate the min/max */ - for (icu=achan->ipo->curve.first; icu; icu=icu->next) { - if (icu->adrcode==stride_axis) { - if (icu->totvert>1) { - foundvert= 1; - minx= icu->bezt[0].vec[1][0]; - maxx= icu->bezt[icu->totvert-1].vec[1][0]; + for (icu = achan->ipo->curve.first; icu; icu = icu->next) { + if (icu->adrcode == stride_axis) { + if (icu->totvert > 1) { + foundvert = 1; + minx = icu->bezt[0].vec[1][0]; + maxx = icu->bezt[icu->totvert - 1].vec[1][0]; - miny= icu->bezt[0].vec[1][1]; - maxy= icu->bezt[icu->totvert-1].vec[1][1]; + miny = icu->bezt[0].vec[1][1]; + maxy = icu->bezt[icu->totvert - 1].vec[1][1]; } break; } } - if (foundvert && miny!=maxy) { - float stridelen= sizecorr*fabs(maxy-miny), striptime; + if (foundvert && miny != maxy) { + float stridelen = sizecorr * fabs(maxy - miny), striptime; float actiondist, pdist, pdistNewNormalized, offs; float vec1[4], vec2[4], dir[3]; /* internal cycling, actoffs is in frames */ - offs= stridelen*strip->actoffs/(maxx-minx); + offs = stridelen * strip->actoffs / (maxx - minx); /* amount path moves object */ - pdist = (float)fmod (pathdist+offs, stridelen); - striptime= pdist/stridelen; + pdist = (float)fmod(pathdist + offs, stridelen); + striptime = pdist / stridelen; /* amount stride bone moves */ - actiondist= sizecorr*eval_icu(icu, minx + striptime*(maxx-minx)) - miny; + actiondist = sizecorr * eval_icu(icu, minx + striptime * (maxx - minx)) - miny; pdist = fabs(actiondist) - pdist; - pdistNewNormalized = (pathdist+pdist)/path->totdist; + pdistNewNormalized = (pathdist + pdist) / path->totdist; /* now we need to go pdist further (or less) on cu path */ - where_on_path(ob, (pathdist)/path->totdist, vec1, dir); /* vec needs size 4 */ + where_on_path(ob, (pathdist) / path->totdist, vec1, dir); /* vec needs size 4 */ if (pdistNewNormalized <= 1) { // search for correction in positive path-direction - where_on_path(ob, pdistNewNormalized, vec2, dir); /* vec needs size 4 */ + where_on_path(ob, pdistNewNormalized, vec2, dir); /* vec needs size 4 */ sub_v3_v3v3(stride_offset, vec2, vec1); } else { // we reached the end of the path, search backwards instead - where_on_path(ob, (pathdist-pdist)/path->totdist, vec2, dir); /* vec needs size 4 */ + where_on_path(ob, (pathdist - pdist) / path->totdist, vec2, dir); /* vec needs size 4 */ sub_v3_v3v3(stride_offset, vec1, vec2); } mul_mat3_m4_v3(ob->obmat, stride_offset); @@ -1368,52 +1368,52 @@ static void cyclic_offs_bone(Object *ob, bPose *pose, bActionStrip *strip, float { /* only called when strip has cyclic, so >= 1.0f works... */ if (time >= 1.0f) { - bActionChannel *achan= get_action_channel(strip->act, strip->offs_bone); + bActionChannel *achan = get_action_channel(strip->act, strip->offs_bone); if (achan && achan->ipo) { - IpoCurve *icu= NULL; + IpoCurve *icu = NULL; Bone *bone; - float min[3]={0.0f, 0.0f, 0.0f}, max[3]={0.0f, 0.0f, 0.0f}; - int index=0, foundvert= 0; + float min[3] = {0.0f, 0.0f, 0.0f}, max[3] = {0.0f, 0.0f, 0.0f}; + int index = 0, foundvert = 0; /* calculate the min/max */ - for (icu=achan->ipo->curve.first; icu; icu=icu->next) { - if (icu->totvert>1) { + for (icu = achan->ipo->curve.first; icu; icu = icu->next) { + if (icu->totvert > 1) { - if (icu->adrcode==AC_LOC_X) - index= 0; - else if (icu->adrcode==AC_LOC_Y) - index= 1; - else if (icu->adrcode==AC_LOC_Z) - index= 2; + if (icu->adrcode == AC_LOC_X) + index = 0; + else if (icu->adrcode == AC_LOC_Y) + index = 1; + else if (icu->adrcode == AC_LOC_Z) + index = 2; else continue; - foundvert= 1; - min[index]= icu->bezt[0].vec[1][1]; - max[index]= icu->bezt[icu->totvert-1].vec[1][1]; + foundvert = 1; + min[index] = icu->bezt[0].vec[1][1]; + max[index] = icu->bezt[icu->totvert - 1].vec[1][1]; } } if (foundvert) { /* bring it into armature space */ sub_v3_v3v3(min, max, min); - bone= get_named_bone(ob->data, strip->offs_bone); /* weak */ + bone = BKE_armature_find_bone_name(ob->data, strip->offs_bone); /* weak */ if (bone) { mul_mat3_m4_v3(bone->arm_mat, min); - /* dominant motion, cyclic_offset was cleared in rest_pose */ + /* dominant motion, cyclic_offset was cleared in BKE_pose_rest */ if (strip->flag & (ACTSTRIP_CYCLIC_USEX | ACTSTRIP_CYCLIC_USEY | ACTSTRIP_CYCLIC_USEZ)) { - if (strip->flag & ACTSTRIP_CYCLIC_USEX) pose->cyclic_offset[0]= time*min[0]; - if (strip->flag & ACTSTRIP_CYCLIC_USEY) pose->cyclic_offset[1]= time*min[1]; - if (strip->flag & ACTSTRIP_CYCLIC_USEZ) pose->cyclic_offset[2]= time*min[2]; + if (strip->flag & ACTSTRIP_CYCLIC_USEX) pose->cyclic_offset[0] = time * min[0]; + if (strip->flag & ACTSTRIP_CYCLIC_USEY) pose->cyclic_offset[1] = time * min[1]; + if (strip->flag & ACTSTRIP_CYCLIC_USEZ) pose->cyclic_offset[2] = time * min[2]; } else { - if ( fabs(min[0]) >= fabs(min[1]) && fabs(min[0]) >= fabs(min[2])) - pose->cyclic_offset[0]= time*min[0]; - else if ( fabs(min[1]) >= fabs(min[0]) && fabs(min[1]) >= fabs(min[2])) - pose->cyclic_offset[1]= time*min[1]; + if (fabs(min[0]) >= fabs(min[1]) && fabs(min[0]) >= fabs(min[2])) + pose->cyclic_offset[0] = time * min[0]; + else if (fabs(min[1]) >= fabs(min[0]) && fabs(min[1]) >= fabs(min[2])) + pose->cyclic_offset[1] = time * min[1]; else - pose->cyclic_offset[2]= time*min[2]; + pose->cyclic_offset[2] = time * min[2]; } } } @@ -1427,13 +1427,13 @@ static Object *get_parent_path(Object *ob) { bConstraint *con; - if (ob->parent && ob->parent->type==OB_CURVE) + if (ob->parent && ob->parent->type == OB_CURVE) return ob->parent; - for (con = ob->constraints.first; con; con=con->next) { - if (con->type==CONSTRAINT_TYPE_FOLLOWPATH) { - if (con->enforce>0.5f) { - bFollowPathConstraint *data= con->data; + for (con = ob->constraints.first; con; con = con->next) { + if (con->type == CONSTRAINT_TYPE_FOLLOWPATH) { + if (con->enforce > 0.5f) { + bFollowPathConstraint *data = con->data; return data->tar; } } @@ -1447,71 +1447,71 @@ static Object *get_parent_path(Object *ob) static void do_nla(Scene *scene, Object *ob, int blocktype) { - bPose *tpose= NULL; - Key *key= NULL; - ListBase tchanbase={NULL, NULL}, chanbase={NULL, NULL}; - bActionStrip *strip, *striplast=NULL, *stripfirst=NULL; + bPose *tpose = NULL; + Key *key = NULL; + ListBase tchanbase = {NULL, NULL}, chanbase = {NULL, NULL}; + bActionStrip *strip, *striplast = NULL, *stripfirst = NULL; float striptime, frametime, length, actlength; float blendfac, stripframe; - float scene_cfra= BKE_curframe(scene); - int doit, dostride; + float scene_cfra = BKE_scene_frame_get(scene); + int doit, dostride; - if (blocktype==ID_AR) { - copy_pose(&tpose, ob->pose, 1); - rest_pose(ob->pose); // potentially destroying current not-keyed pose + if (blocktype == ID_AR) { + BKE_pose_copy_data(&tpose, ob->pose, 1); + BKE_pose_rest(ob->pose); // potentially destroying current not-keyed pose } else { - key= ob_get_key(ob); + key = ob_get_key(ob); } /* check on extend to left or right, when no strip is hit by 'cfra' */ - for (strip=ob->nlastrips.first; strip; strip=strip->next) { + for (strip = ob->nlastrips.first; strip; strip = strip->next) { /* escape loop on a hit */ - if ( scene_cfra >= strip->start && scene_cfra <= strip->end + 0.1f) /* note 0.1 comes back below */ + if (scene_cfra >= strip->start && scene_cfra <= strip->end + 0.1f) /* note 0.1 comes back below */ break; if (scene_cfra < strip->start) { - if (stripfirst==NULL) - stripfirst= strip; + if (stripfirst == NULL) + stripfirst = strip; else if (stripfirst->start > strip->start) - stripfirst= strip; + stripfirst = strip; } else if (scene_cfra > strip->end) { - if (striplast==NULL) - striplast= strip; + if (striplast == NULL) + striplast = strip; else if (striplast->end < strip->end) - striplast= strip; + striplast = strip; } } - if (strip==NULL) { /* extend */ + if (strip == NULL) { /* extend */ if (striplast) - scene_cfra= striplast->end; + scene_cfra = striplast->end; else if (stripfirst) - scene_cfra= stripfirst->start; + scene_cfra = stripfirst->start; } /* and now go over all strips */ - for (strip=ob->nlastrips.first; strip; strip=strip->next) { - doit=dostride= 0; + for (strip = ob->nlastrips.first; strip; strip = strip->next) { + doit = dostride = 0; - if (strip->act && !(strip->flag & ACTSTRIP_MUTE)) { /* so theres an action */ + if (strip->act && !(strip->flag & ACTSTRIP_MUTE)) { /* so theres an action */ /* Determine if the current frame is within the strip's range */ - length = strip->end-strip->start; - actlength = strip->actend-strip->actstart; + length = strip->end - strip->start; + actlength = strip->actend - strip->actstart; striptime = (scene_cfra - strip->start) / length; stripframe = (scene_cfra - strip->start); - if (striptime>=0.0) { + if (striptime >= 0.0) { - if (blocktype==ID_AR) - rest_pose(tpose); + if (blocktype == ID_AR) + BKE_pose_rest(tpose); /* To handle repeat, we add 0.1 frame extra to make sure the last frame is included */ - if (striptime < 1.0f + 0.1f/length) { + if (striptime < 1.0f + 0.1f / length) { /* Handle path */ - if ((strip->flag & ACTSTRIP_USESTRIDE) && (blocktype==ID_AR) && (ob->ipoflag & OB_DISABLE_PATH)==0) { - Object *parent= get_parent_path(ob); + if ((strip->flag & ACTSTRIP_USESTRIDE) && (blocktype == ID_AR) && (ob->ipoflag & OB_DISABLE_PATH) == 0) { + Object *parent = get_parent_path(ob); if (parent) { Curve *cu = parent->data; @@ -1519,43 +1519,43 @@ static void do_nla(Scene *scene, Object *ob, int blocktype) if (cu->flag & CU_PATH) { /* Ensure we have a valid path */ - if (cu->path==NULL || cu->path->data==NULL) makeDispListCurveTypes(scene, parent, 0); + if (cu->path == NULL || cu->path->data == NULL) makeDispListCurveTypes(scene, parent, 0); if (cu->path) { /* Find the position on the path */ - ctime= bsystem_time(scene, ob, scene_cfra, 0.0); + ctime = bsystem_time(scene, ob, scene_cfra, 0.0); - if (calc_ipo_spec(cu->ipo, CU_SPEED, &ctime)==0) { + if (calc_ipo_spec(cu->ipo, CU_SPEED, &ctime) == 0) { /* correct for actions not starting on zero */ - ctime= (ctime - strip->actstart)/cu->pathlen; + ctime = (ctime - strip->actstart) / cu->pathlen; CLAMP(ctime, 0.0, 1.0); } - pdist = ctime*cu->path->totdist; + pdist = ctime * cu->path->totdist; if (tpose && strip->stridechannel[0]) { - striptime= stridechannel_frame(parent, ob->size[0], strip, cu->path, pdist, tpose->stride_offset); + striptime = stridechannel_frame(parent, ob->size[0], strip, cu->path, pdist, tpose->stride_offset); } else { if (strip->stridelen) { striptime = pdist / strip->stridelen; - striptime = (float)fmod (striptime+strip->actoffs, 1.0); + striptime = (float)fmod(striptime + strip->actoffs, 1.0); } else striptime = 0; } frametime = (striptime * actlength) + strip->actstart; - frametime= bsystem_time(scene, ob, frametime, 0.0); + frametime = bsystem_time(scene, ob, frametime, 0.0); - if (blocktype==ID_AR) { - extract_pose_from_action (tpose, strip->act, frametime); + if (blocktype == ID_AR) { + extract_pose_from_action(tpose, strip->act, frametime); } - else if (blocktype==ID_OB) { + else if (blocktype == ID_OB) { extract_ipochannels_from_action(&tchanbase, &ob->id, strip->act, "Object", frametime); if (key) extract_ipochannels_from_action(&tchanbase, &key->id, strip->act, "Shape", frametime); } - doit=dostride= 1; + doit = dostride = 1; } } } @@ -1564,29 +1564,29 @@ static void do_nla(Scene *scene, Object *ob, int blocktype) else { /* Mod to repeat */ - if (strip->repeat!=1.0f) { - float cycle= striptime*strip->repeat; + if (strip->repeat != 1.0f) { + float cycle = striptime * strip->repeat; - striptime = (float)fmod (cycle, 1.0f + 0.1f/length); - cycle-= striptime; + striptime = (float)fmod(cycle, 1.0f + 0.1f / length); + cycle -= striptime; - if (blocktype==ID_AR) + if (blocktype == ID_AR) cyclic_offs_bone(ob, tpose, strip, cycle); } frametime = (striptime * actlength) + strip->actstart; - frametime= nla_time(scene, frametime, (float)strip->repeat); + frametime = nla_time(scene, frametime, (float)strip->repeat); - if (blocktype==ID_AR) { - extract_pose_from_action (tpose, strip->act, frametime); + if (blocktype == ID_AR) { + extract_pose_from_action(tpose, strip->act, frametime); } - else if (blocktype==ID_OB) { + else if (blocktype == ID_OB) { extract_ipochannels_from_action(&tchanbase, &ob->id, strip->act, "Object", frametime); if (key) extract_ipochannels_from_action(&tchanbase, &key->id, strip->act, "Shape", frametime); } - doit=1; + doit = 1; } } /* Handle extend */ @@ -1594,25 +1594,25 @@ static void do_nla(Scene *scene, Object *ob, int blocktype) if (strip->flag & ACTSTRIP_HOLDLASTFRAME) { /* we want the strip to hold on the exact fraction of the repeat value */ - frametime = actlength * (strip->repeat-(int)strip->repeat); - if (frametime<=0.000001f) frametime= actlength; /* rounding errors... */ - frametime= bsystem_time(scene, ob, frametime+strip->actstart, 0.0); - - if (blocktype==ID_AR) - extract_pose_from_action (tpose, strip->act, frametime); - else if (blocktype==ID_OB) { + frametime = actlength * (strip->repeat - (int)strip->repeat); + if (frametime <= 0.000001f) frametime = actlength; /* rounding errors... */ + frametime = bsystem_time(scene, ob, frametime + strip->actstart, 0.0); + + if (blocktype == ID_AR) + extract_pose_from_action(tpose, strip->act, frametime); + else if (blocktype == ID_OB) { extract_ipochannels_from_action(&tchanbase, &ob->id, strip->act, "Object", frametime); if (key) extract_ipochannels_from_action(&tchanbase, &key->id, strip->act, "Shape", frametime); } /* handle cycle hold */ - if (strip->repeat!=1.0f) { - if (blocktype==ID_AR) - cyclic_offs_bone(ob, tpose, strip, strip->repeat-1.0f); + if (strip->repeat != 1.0f) { + if (blocktype == ID_AR) + cyclic_offs_bone(ob, tpose, strip, strip->repeat - 1.0f); } - doit=1; + doit = 1; } } @@ -1620,22 +1620,22 @@ static void do_nla(Scene *scene, Object *ob, int blocktype) if (doit) { /* Handle blendin */ - if (strip->blendin>0.0 && stripframe<=strip->blendin && scene_cfra>=strip->start) { - blendfac = stripframe/strip->blendin; + if (strip->blendin > 0.0 && stripframe <= strip->blendin && scene_cfra >= strip->start) { + blendfac = stripframe / strip->blendin; } - else if (strip->blendout>0.0 && stripframe>=(length-strip->blendout) && scene_cfra<=strip->end) { - blendfac = (length-stripframe)/(strip->blendout); + else if (strip->blendout > 0.0 && stripframe >= (length - strip->blendout) && scene_cfra <= strip->end) { + blendfac = (length - stripframe) / (strip->blendout); } else blendfac = 1; - if (blocktype==ID_AR) {/* Blend this pose with the accumulated pose */ + if (blocktype == ID_AR) { /* Blend this pose with the accumulated pose */ /* offset bone, for matching cycles */ - blend_pose_offset_bone (strip, ob->pose, tpose, blendfac, strip->mode); + blend_pose_offset_bone(strip, ob->pose, tpose, blendfac, strip->mode); - blend_poses (ob->pose, tpose, blendfac, strip->mode); + blend_poses(ob->pose, tpose, blendfac, strip->mode); if (dostride) - blend_pose_strides (ob->pose, tpose, blendfac, strip->mode); + blend_pose_strides(ob->pose, tpose, blendfac, strip->mode); } else { blend_ipochannels(&chanbase, &tchanbase, blendfac, strip->mode); @@ -1646,17 +1646,17 @@ static void do_nla(Scene *scene, Object *ob, int blocktype) } } - if (blocktype==ID_OB) { + if (blocktype == ID_OB) { execute_ipochannels(&chanbase); } - else if (blocktype==ID_AR) { + else if (blocktype == ID_AR) { /* apply stride offset to object */ add_v3_v3(ob->obmat[3], ob->pose->stride_offset); } /* free */ if (tpose) - free_pose(tpose); + BKE_pose_free(tpose); if (chanbase.first) BLI_freelistN(&chanbase); } diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index afa4723bc6d..ed6eceb036b 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -88,23 +88,23 @@ void animviz_settings_init(bAnimVizSettings *avs) return; /* ghosting settings */ - avs->ghost_bc= avs->ghost_ac= 10; + avs->ghost_bc = avs->ghost_ac = 10; - avs->ghost_sf= 1; // xxx - take from scene instead? - avs->ghost_ef= 250; // xxx - take from scene instead? + avs->ghost_sf = 1; // xxx - take from scene instead? + avs->ghost_ef = 250; // xxx - take from scene instead? - avs->ghost_step= 1; + avs->ghost_step = 1; /* path settings */ - avs->path_bc= avs->path_ac= 10; + avs->path_bc = avs->path_ac = 10; - avs->path_sf= 1; // xxx - take from scene instead? - avs->path_ef= 250; // xxx - take from scene instead? + avs->path_sf = 1; // xxx - take from scene instead? + avs->path_ef = 250; // xxx - take from scene instead? - avs->path_viewflag= (MOTIONPATH_VIEW_KFRAS|MOTIONPATH_VIEW_KFNOS); + avs->path_viewflag = (MOTIONPATH_VIEW_KFRAS | MOTIONPATH_VIEW_KFNOS); - avs->path_step= 1; + avs->path_step = 1; } /* ------------------- */ @@ -121,8 +121,8 @@ void animviz_free_motionpath_cache(bMotionPath *mpath) MEM_freeN(mpath->points); /* reset the relevant parameters */ - mpath->points= NULL; - mpath->length= 0; + mpath->points = NULL; + mpath->length = 0; } /* Free the given motion path instance and its data @@ -162,22 +162,22 @@ bMotionPath *animviz_verify_motionpaths(ReportList *reports, Scene *scene, Objec /* get destination data */ if (pchan) { /* paths for posechannel - assume that posechannel belongs to the object */ - avs= &ob->pose->avs; - dst= &pchan->mpath; + avs = &ob->pose->avs; + dst = &pchan->mpath; } else { /* paths for object */ - avs= &ob->avs; - dst= &ob->mpath; + avs = &ob->avs; + dst = &ob->mpath; } /* avoid 0 size allocs */ if (avs->path_sf >= avs->path_ef) { BKE_reportf(reports, RPT_ERROR, - "Motion Path frame extents invalid for %s (%d to %d).%s\n", - (pchan)? pchan->name : ob->id.name, - avs->path_sf, avs->path_ef, - (avs->path_sf == avs->path_ef)? " Cannot have single-frame paths." : ""); + "Motion Path frame extents invalid for %s (%d to %d).%s\n", + (pchan) ? pchan->name : ob->id.name, + avs->path_sf, avs->path_ef, + (avs->path_sf == avs->path_ef) ? " Cannot have single-frame paths." : ""); return NULL; } @@ -187,7 +187,7 @@ bMotionPath *animviz_verify_motionpaths(ReportList *reports, Scene *scene, Objec if (*dst != NULL) { int expected_length = avs->path_ef - avs->path_sf; - mpath= *dst; + mpath = *dst; /* path is "valid" if length is valid, but must also be of the same length as is being requested */ if ((mpath->start_frame != mpath->end_frame) && (mpath->length > 0)) { @@ -204,15 +204,15 @@ bMotionPath *animviz_verify_motionpaths(ReportList *reports, Scene *scene, Objec } else { /* create a new motionpath, and assign it */ - mpath= MEM_callocN(sizeof(bMotionPath), "bMotionPath"); - *dst= mpath; + mpath = MEM_callocN(sizeof(bMotionPath), "bMotionPath"); + *dst = mpath; } /* set settings from the viz settings */ - mpath->start_frame= avs->path_sf; - mpath->end_frame= avs->path_ef; + mpath->start_frame = avs->path_sf; + mpath->end_frame = avs->path_ef; - mpath->length= mpath->end_frame - mpath->start_frame; + mpath->length = mpath->end_frame - mpath->start_frame; if (avs->path_bakeflag & MOTIONPATH_BAKE_HEADS) mpath->flag |= MOTIONPATH_FLAG_BHEAD; @@ -220,7 +220,7 @@ bMotionPath *animviz_verify_motionpaths(ReportList *reports, Scene *scene, Objec mpath->flag &= ~MOTIONPATH_FLAG_BHEAD; /* allocate a cache */ - mpath->points= MEM_callocN(sizeof(bMotionPathVert)*mpath->length, "bMotionPathVerts"); + mpath->points = MEM_callocN(sizeof(bMotionPathVert) * mpath->length, "bMotionPathVerts"); /* tag viz settings as currently having some path(s) which use it */ avs->path_bakeflag |= MOTIONPATH_BAKE_HAS_PATHS; @@ -235,16 +235,16 @@ bMotionPath *animviz_verify_motionpaths(ReportList *reports, Scene *scene, Objec typedef struct MPathTarget { struct MPathTarget *next, *prev; - bMotionPath *mpath; /* motion path in question */ + bMotionPath *mpath; /* motion path in question */ - Object *ob; /* source object */ - bPoseChannel *pchan; /* source posechannel (if applicable) */ + Object *ob; /* source object */ + bPoseChannel *pchan; /* source posechannel (if applicable) */ } MPathTarget; /* ........ */ /* get list of motion paths to be baked for the given object - * - assumes the given list is ready to be used + * - assumes the given list is ready to be used */ // TODO: it would be nice in future to be able to update objects dependent on these bones too? void animviz_get_object_motionpaths(Object *ob, ListBase *targets) @@ -254,27 +254,27 @@ void animviz_get_object_motionpaths(Object *ob, ListBase *targets) /* object itself first */ if ((ob->avs.recalc & ANIMVIZ_RECALC_PATHS) && (ob->mpath)) { /* new target for object */ - mpt= MEM_callocN(sizeof(MPathTarget), "MPathTarget Ob"); + mpt = MEM_callocN(sizeof(MPathTarget), "MPathTarget Ob"); BLI_addtail(targets, mpt); - mpt->mpath= ob->mpath; - mpt->ob= ob; + mpt->mpath = ob->mpath; + mpt->ob = ob; } /* bones */ if ((ob->pose) && (ob->pose->avs.recalc & ANIMVIZ_RECALC_PATHS)) { - bArmature *arm= ob->data; + bArmature *arm = ob->data; bPoseChannel *pchan; - for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { + for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { if ((pchan->bone) && (arm->layer & pchan->bone->layer) && (pchan->mpath)) { /* new target for bone */ - mpt= MEM_callocN(sizeof(MPathTarget), "MPathTarget PoseBone"); + mpt = MEM_callocN(sizeof(MPathTarget), "MPathTarget PoseBone"); BLI_addtail(targets, mpt); - mpt->mpath= pchan->mpath; - mpt->ob= ob; - mpt->pchan= pchan; + mpt->mpath = pchan->mpath; + mpt->ob = ob; + mpt->pchan = pchan; } } } @@ -296,12 +296,12 @@ static void motionpaths_calc_optimise_depsgraph(Scene *scene, ListBase *targets) MPathTarget *mpt; /* make sure our temp-tag isn't already in use */ - for (base= scene->base.first; base; base= base->next) + for (base = scene->base.first; base; base = base->next) base->object->flag &= ~BA_TEMP_TAG; /* for each target, dump its object to the start of the list if it wasn't moved already */ - for (mpt= targets->first; mpt; mpt= mpt->next) { - for (base=scene->base.first; base; base=baseNext) { + for (mpt = targets->first; mpt; mpt = mpt->next) { + for (base = scene->base.first; base; base = baseNext) { baseNext = base->next; if ((base->object == mpt->ob) && !(mpt->ob->flag & BA_TEMP_TAG)) { @@ -322,7 +322,7 @@ static void motionpaths_calc_optimise_depsgraph(Scene *scene, ListBase *targets) static void motionpaths_calc_update_scene(Scene *scene) { #if 1 // 'production' optimisations always on - Base *base, *last=NULL; + Base *base, *last = NULL; /* only stuff that moves or needs display still */ DAG_scene_update_flags(G.main, scene, scene->lay, TRUE); @@ -331,7 +331,7 @@ static void motionpaths_calc_update_scene(Scene *scene) * - all those afterwards are assumed to not be relevant for our calculations */ // optimize further by moving out... - for (base=scene->base.first; base; base=base->next) { + for (base = scene->base.first; base; base = base->next) { if (base->object->flag & BA_TEMP_TAG) last = base; } @@ -339,21 +339,21 @@ static void motionpaths_calc_update_scene(Scene *scene) /* perform updates for tagged objects */ // XXX: this will break if rigs depend on scene or other data that // is animated but not attached to/updatable from objects - for (base=scene->base.first; base; base=base->next) { + for (base = scene->base.first; base; base = base->next) { /* update this object */ - object_handle_update(scene, base->object); + BKE_object_handle_update(scene, base->object); /* if this is the last one we need to update, let's stop to save some time */ if (base == last) break; } #else // original, 'always correct' version - /* do all updates - * - if this is too slow, resort to using a more efficient way - * that doesn't force complete update, but for now, this is the - * most accurate way! - */ - scene_update_for_newframe(G.main, scene, scene->lay); // XXX this is the best way we can get anything moving + /* do all updates + * - if this is too slow, resort to using a more efficient way + * that doesn't force complete update, but for now, this is the + * most accurate way! + */ + BKE_scene_update_for_newframe(G.main, scene, scene->lay); // XXX this is the best way we can get anything moving #endif } @@ -365,8 +365,8 @@ static void motionpaths_calc_bake_targets(Scene *scene, ListBase *targets) MPathTarget *mpt; /* for each target, check if it can be baked on the current frame */ - for (mpt= targets->first; mpt; mpt= mpt->next) { - bMotionPath *mpath= mpt->mpath; + for (mpt = targets->first; mpt; mpt = mpt->next) { + bMotionPath *mpath = mpt->mpath; bMotionPathVert *mpv; /* current frame must be within the range the cache works for @@ -376,7 +376,7 @@ static void motionpaths_calc_bake_targets(Scene *scene, ListBase *targets) continue; /* get the relevant cache vert to write to */ - mpv= mpath->points + (CFRA - mpath->start_frame); + mpv = mpath->points + (CFRA - mpath->start_frame); /* pose-channel or object path baking? */ if (mpt->pchan) { @@ -421,10 +421,10 @@ void animviz_calc_motionpaths(Scene *scene, ListBase *targets) // TODO: this method could be improved... // 1) max range for standard baking // 2) minimum range for recalc baking (i.e. between keyframes, but how?) - for (mpt= targets->first; mpt; mpt= mpt->next) { + for (mpt = targets->first; mpt; mpt = mpt->next) { /* try to increase area to do (only as much as needed) */ - sfra= MIN2(sfra, mpt->mpath->start_frame); - efra= MAX2(efra, mpt->mpath->end_frame); + sfra = MIN2(sfra, mpt->mpath->start_frame); + efra = MAX2(efra, mpt->mpath->end_frame); } if (efra <= sfra) return; @@ -433,7 +433,7 @@ void animviz_calc_motionpaths(Scene *scene, ListBase *targets) motionpaths_calc_optimise_depsgraph(scene, targets); /* calculate path over requested range */ - for (CFRA=sfra; CFRA<=efra; CFRA++) { + for (CFRA = sfra; CFRA <= efra; CFRA++) { /* update relevant data for new frame */ motionpaths_calc_update_scene(scene); @@ -442,18 +442,18 @@ void animviz_calc_motionpaths(Scene *scene, ListBase *targets) } /* reset original environment */ - CFRA= cfra; + CFRA = cfra; motionpaths_calc_update_scene(scene); /* clear recalc flags from targets */ - for (mpt= targets->first; mpt; mpt= mpt->next) { + for (mpt = targets->first; mpt; mpt = mpt->next) { bAnimVizSettings *avs; /* get pointer to animviz settings for each target */ if (mpt->pchan) - avs= &mpt->ob->pose->avs; + avs = &mpt->ob->pose->avs; else - avs= &mpt->ob->avs; + avs = &mpt->ob->avs; /* clear the flag requesting recalculation of targets */ avs->recalc &= ~ANIMVIZ_RECALC_PATHS; @@ -474,7 +474,7 @@ void free_path(Path *path) } /* calculate a curve-deform path for a curve - * - only called from displist.c -> do_makeDispListCurveTypes + * - only called from displist.c -> do_makeDispListCurveTypes */ void calc_curvepath(Object *ob) { @@ -485,92 +485,92 @@ void calc_curvepath(Object *ob) Nurb *nu; Path *path; float *fp, *dist, *maxdist, xyz[3]; - float fac, d=0, fac1, fac2; - int a, tot, cycl=0; + float fac, d = 0, fac1, fac2; + int a, tot, cycl = 0; ListBase *nurbs; /* in a path vertices are with equal differences: path->len = number of verts */ /* NOW WITH BEVELCURVE!!! */ - if (ob==NULL || ob->type != OB_CURVE) return; - cu= ob->data; + if (ob == NULL || ob->type != OB_CURVE) return; + cu = ob->data; - nurbs= BKE_curve_nurbs_get(cu); - nu= nurbs->first; + nurbs = BKE_curve_nurbs_get(cu); + nu = nurbs->first; if (cu->path) free_path(cu->path); - cu->path= NULL; + cu->path = NULL; - bl= cu->bev.first; - if (bl==NULL || !bl->nr) return; + bl = cu->bev.first; + if (bl == NULL || !bl->nr) return; - cu->path=path= MEM_callocN(sizeof(Path), "calc_curvepath"); + cu->path = path = MEM_callocN(sizeof(Path), "calc_curvepath"); /* if POLY: last vertice != first vertice */ - cycl= (bl->poly!= -1); + cycl = (bl->poly != -1); - if (cycl) tot= bl->nr; - else tot= bl->nr-1; + if (cycl) tot = bl->nr; + else tot = bl->nr - 1; - path->len= tot+1; + path->len = tot + 1; /* exception: vector handle paths and polygon paths should be subdivided at least a factor resolu */ - if (path->len<nu->resolu*SEGMENTSU(nu)) path->len= nu->resolu*SEGMENTSU(nu); + if (path->len < nu->resolu * SEGMENTSU(nu)) path->len = nu->resolu * SEGMENTSU(nu); - dist= (float *)MEM_mallocN((tot+1)*4, "calcpathdist"); + dist = (float *)MEM_mallocN((tot + 1) * 4, "calcpathdist"); - /* all lengths in *dist */ - bevp= bevpfirst= (BevPoint *)(bl+1); - fp= dist; - *fp= 0; - for (a=0; a<tot; a++) { + /* all lengths in *dist */ + bevp = bevpfirst = (BevPoint *)(bl + 1); + fp = dist; + *fp = 0; + for (a = 0; a < tot; a++) { fp++; - if (cycl && a==tot-1) + if (cycl && a == tot - 1) sub_v3_v3v3(xyz, bevpfirst->vec, bevp->vec); else - sub_v3_v3v3(xyz, (bevp+1)->vec, bevp->vec); + sub_v3_v3v3(xyz, (bevp + 1)->vec, bevp->vec); - *fp= *(fp-1)+len_v3(xyz); + *fp = *(fp - 1) + len_v3(xyz); bevp++; } - path->totdist= *fp; - - /* the path verts in path->data */ - /* now also with TILT value */ - pp= path->data = (PathPoint *)MEM_callocN(sizeof(PathPoint)*path->len, "pathdata"); + path->totdist = *fp; - bevp= bevpfirst; - bevpn= bevp+1; - bevplast= bevpfirst + (bl->nr-1); - fp= dist+1; - maxdist= dist+tot; - fac= 1.0f/((float)path->len-1.0f); - fac = fac * path->totdist; + /* the path verts in path->data */ + /* now also with TILT value */ + pp = path->data = (PathPoint *)MEM_callocN(sizeof(PathPoint) * path->len, "pathdata"); + + bevp = bevpfirst; + bevpn = bevp + 1; + bevplast = bevpfirst + (bl->nr - 1); + fp = dist + 1; + maxdist = dist + tot; + fac = 1.0f / ((float)path->len - 1.0f); + fac = fac * path->totdist; - for (a=0; a<path->len; a++) { + for (a = 0; a < path->len; a++) { - d= ((float)a)*fac; + d = ((float)a) * fac; /* we're looking for location (distance) 'd' in the array */ - while ((d>= *fp) && fp<maxdist) { + while ((d >= *fp) && fp < maxdist) { fp++; - if (bevp<bevplast) bevp++; - bevpn= bevp+1; - if (bevpn>bevplast) { - if (cycl) bevpn= bevpfirst; - else bevpn= bevplast; + if (bevp < bevplast) bevp++; + bevpn = bevp + 1; + if (bevpn > bevplast) { + if (cycl) bevpn = bevpfirst; + else bevpn = bevplast; } } - fac1= *(fp)- *(fp-1); - fac2= *(fp)-d; - fac1= fac2/fac1; - fac2= 1.0f-fac1; + fac1 = *(fp) - *(fp - 1); + fac2 = *(fp) - d; + fac1 = fac2 / fac1; + fac2 = 1.0f - fac1; interp_v3_v3v3(pp->vec, bevp->vec, bevpn->vec, fac2); - pp->vec[3]= fac1*bevp->alfa + fac2*bevpn->alfa; - pp->radius= fac1*bevp->radius + fac2*bevpn->radius; - pp->weight= fac1*bevp->weight + fac2*bevpn->weight; + pp->vec[3] = fac1 * bevp->alfa + fac2 * bevpn->alfa; + pp->radius = fac1 * bevp->radius + fac2 * bevpn->radius; + pp->weight = fac1 * bevp->weight + fac2 * bevpn->weight; interp_qt_qtqt(pp->quat, bevp->quat, bevpn->quat, fac2); normalize_qt(pp->quat); @@ -586,13 +586,13 @@ int interval_test(int min, int max, int p1, int cycl) { if (cycl) { if (p1 < min) - p1= ((p1 -min) % (max-min+1)) + max+1; + p1 = ((p1 - min) % (max - min + 1)) + max + 1; else if (p1 > max) - p1= ((p1 -min) % (max-min+1)) + min; + p1 = ((p1 - min) % (max - min + 1)) + min; } else { - if (p1 < min) p1= min; - else if (p1 > max) p1= max; + if (p1 < min) p1 = min; + else if (p1 > max) p1 = max; } return p1; } @@ -614,84 +614,84 @@ int where_on_path(Object *ob, float ctime, float vec[4], float dir[3], float qua PathPoint *pp, *p0, *p1, *p2, *p3; float fac; float data[4]; - int cycl=0, s0, s1, s2, s3; + int cycl = 0, s0, s1, s2, s3; - if (ob==NULL || ob->type != OB_CURVE) return 0; - cu= ob->data; - if (cu->path==NULL || cu->path->data==NULL) { + if (ob == NULL || ob->type != OB_CURVE) return 0; + cu = ob->data; + if (cu->path == NULL || cu->path->data == NULL) { printf("no path!\n"); return 0; } - path= cu->path; - pp= path->data; + path = cu->path; + pp = path->data; /* test for cyclic */ - bl= cu->bev.first; + bl = cu->bev.first; if (!bl) return 0; if (!bl->nr) return 0; - if (bl->poly> -1) cycl= 1; + if (bl->poly > -1) cycl = 1; - ctime *= (path->len-1); + ctime *= (path->len - 1); - s1= (int)floor(ctime); - fac= (float)(s1+1)-ctime; + s1 = (int)floor(ctime); + fac = (float)(s1 + 1) - ctime; /* path->len is corected for cyclic */ - s0= interval_test(0, path->len-1-cycl, s1-1, cycl); - s1= interval_test(0, path->len-1-cycl, s1, cycl); - s2= interval_test(0, path->len-1-cycl, s1+1, cycl); - s3= interval_test(0, path->len-1-cycl, s1+2, cycl); + s0 = interval_test(0, path->len - 1 - cycl, s1 - 1, cycl); + s1 = interval_test(0, path->len - 1 - cycl, s1, cycl); + s2 = interval_test(0, path->len - 1 - cycl, s1 + 1, cycl); + s3 = interval_test(0, path->len - 1 - cycl, s1 + 2, cycl); - p0= pp + s0; - p1= pp + s1; - p2= pp + s2; - p3= pp + s3; + p0 = pp + s0; + p1 = pp + s1; + p2 = pp + s2; + p3 = pp + s3; /* note, commented out for follow constraint */ //if (cu->flag & CU_FOLLOW) { - key_curve_tangent_weights(1.0f-fac, data, KEY_BSPLINE); + key_curve_tangent_weights(1.0f - fac, data, KEY_BSPLINE); - interp_v3_v3v3v3v3(dir, p0->vec, p1->vec, p2->vec, p3->vec, data); + interp_v3_v3v3v3v3(dir, p0->vec, p1->vec, p2->vec, p3->vec, data); - /* make compatible with vectoquat */ - negate_v3(dir); + /* make compatible with vectoquat */ + negate_v3(dir); //} - nu= cu->nurb.first; + nu = cu->nurb.first; /* make sure that first and last frame are included in the vectors here */ - if (nu->type == CU_POLY) key_curve_position_weights(1.0f-fac, data, KEY_LINEAR); - else if (nu->type == CU_BEZIER) key_curve_position_weights(1.0f-fac, data, KEY_LINEAR); - else if (s0==s1 || p2==p3) key_curve_position_weights(1.0f-fac, data, KEY_CARDINAL); - else key_curve_position_weights(1.0f-fac, data, KEY_BSPLINE); + if (nu->type == CU_POLY) key_curve_position_weights(1.0f - fac, data, KEY_LINEAR); + else if (nu->type == CU_BEZIER) key_curve_position_weights(1.0f - fac, data, KEY_LINEAR); + else if (s0 == s1 || p2 == p3) key_curve_position_weights(1.0f - fac, data, KEY_CARDINAL); + else key_curve_position_weights(1.0f - fac, data, KEY_BSPLINE); - vec[0]= data[0]*p0->vec[0] + data[1]*p1->vec[0] + data[2]*p2->vec[0] + data[3]*p3->vec[0] ; /* X */ - vec[1]= data[0]*p0->vec[1] + data[1]*p1->vec[1] + data[2]*p2->vec[1] + data[3]*p3->vec[1] ; /* Y */ - vec[2]= data[0]*p0->vec[2] + data[1]*p1->vec[2] + data[2]*p2->vec[2] + data[3]*p3->vec[2] ; /* Z */ - vec[3]= data[0]*p0->vec[3] + data[1]*p1->vec[3] + data[2]*p2->vec[3] + data[3]*p3->vec[3] ; /* Tilt, should not be needed since we have quat still used */ + vec[0] = data[0] * p0->vec[0] + data[1] * p1->vec[0] + data[2] * p2->vec[0] + data[3] * p3->vec[0]; /* X */ + vec[1] = data[0] * p0->vec[1] + data[1] * p1->vec[1] + data[2] * p2->vec[1] + data[3] * p3->vec[1]; /* Y */ + vec[2] = data[0] * p0->vec[2] + data[1] * p1->vec[2] + data[2] * p2->vec[2] + data[3] * p3->vec[2]; /* Z */ + vec[3] = data[0] * p0->vec[3] + data[1] * p1->vec[3] + data[2] * p2->vec[3] + data[3] * p3->vec[3]; /* Tilt, should not be needed since we have quat still used */ if (quat) { float totfac, q1[4], q2[4]; - totfac= data[0]+data[3]; - if (totfac>FLT_EPSILON) interp_qt_qtqt(q1, p0->quat, p3->quat, data[3] / totfac); - else copy_qt_qt(q1, p1->quat); + totfac = data[0] + data[3]; + if (totfac > FLT_EPSILON) interp_qt_qtqt(q1, p0->quat, p3->quat, data[3] / totfac); + else copy_qt_qt(q1, p1->quat); - totfac= data[1]+data[2]; - if (totfac>FLT_EPSILON) interp_qt_qtqt(q2, p1->quat, p2->quat, data[2] / totfac); - else copy_qt_qt(q2, p3->quat); + totfac = data[1] + data[2]; + if (totfac > FLT_EPSILON) interp_qt_qtqt(q2, p1->quat, p2->quat, data[2] / totfac); + else copy_qt_qt(q2, p3->quat); - totfac = data[0]+data[1]+data[2]+data[3]; - if (totfac>FLT_EPSILON) interp_qt_qtqt(quat, q1, q2, (data[1]+data[2]) / totfac); - else copy_qt_qt(quat, q2); + totfac = data[0] + data[1] + data[2] + data[3]; + if (totfac > FLT_EPSILON) interp_qt_qtqt(quat, q1, q2, (data[1] + data[2]) / totfac); + else copy_qt_qt(quat, q2); } if (radius) - *radius= data[0]*p0->radius + data[1]*p1->radius + data[2]*p2->radius + data[3]*p3->radius; + *radius = data[0] * p0->radius + data[1] * p1->radius + data[2] * p2->radius + data[3] * p3->radius; if (weight) - *weight= data[0]*p0->weight + data[1]*p1->weight + data[2]*p2->weight + data[3]*p3->weight; + *weight = data[0] * p0->weight + data[1] * p1->weight + data[2] * p2->weight + data[3] * p3->weight; return 1; } @@ -701,17 +701,17 @@ int where_on_path(Object *ob, float ctime, float vec[4], float dir[3], float qua static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[][4], int lay, int index, int type, int animated) { - DupliObject *dob= MEM_callocN(sizeof(DupliObject), "dupliobject"); + DupliObject *dob = MEM_callocN(sizeof(DupliObject), "dupliobject"); BLI_addtail(lb, dob); - dob->ob= ob; + dob->ob = ob; copy_m4_m4(dob->mat, mat); copy_m4_m4(dob->omat, ob->obmat); - dob->origlay= ob->lay; - dob->index= index; - dob->type= type; - dob->animated= (type == OB_DUPLIGROUP) && animated; - ob->lay= lay; + dob->origlay = ob->lay; + dob->index = index; + dob->type = type; + dob->animated = (type == OB_DUPLIGROUP) && animated; + ob->lay = lay; return dob; } @@ -723,20 +723,20 @@ static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, i GroupObject *go; float mat[4][4], tmat[4][4]; - if (ob->dup_group==NULL) return; - group= ob->dup_group; + if (ob->dup_group == NULL) return; + group = ob->dup_group; /* simple preventing of too deep nested groups */ - if (level>MAX_DUPLI_RECUR) return; + if (level > MAX_DUPLI_RECUR) return; /* handles animated groups, and */ /* we need to check update for objects that are not in scene... */ group_handle_recalc_and_update(scene, ob, group); - animated= animated || group_is_animated(ob, group); + animated = animated || group_is_animated(ob, group); - for (go= group->gobject.first; go; go= go->next) { + for (go = group->gobject.first; go; go = go->next) { /* note, if you check on layer here, render goes wrong... it still deforms verts and uses parent imat */ - if (go->ob!=ob) { + if (go->ob != ob) { /* group dupli offset, should apply after everything else */ if (!is_zero_v3(group->dupli_ofs)) { @@ -748,22 +748,22 @@ static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, i mult_m4_m4m4(mat, ob->obmat, go->ob->obmat); } - dob= new_dupli_object(lb, go->ob, mat, ob->lay, 0, OB_DUPLIGROUP, animated); + dob = new_dupli_object(lb, go->ob, mat, ob->lay, 0, OB_DUPLIGROUP, animated); /* check the group instance and object layers match, also that the object visible flags are ok. */ - if ( (dob->origlay & group->layer)==0 || - (G.rendering==0 && dob->ob->restrictflag & OB_RESTRICT_VIEW) || - (G.rendering && dob->ob->restrictflag & OB_RESTRICT_RENDER) - ) { - dob->no_draw= 1; + if ( (dob->origlay & group->layer) == 0 || + (G.rendering == 0 && dob->ob->restrictflag & OB_RESTRICT_VIEW) || + (G.rendering && dob->ob->restrictflag & OB_RESTRICT_RENDER) + ) { + dob->no_draw = 1; } else { - dob->no_draw= 0; + dob->no_draw = 0; } if (go->ob->transflag & OB_DUPLI) { copy_m4_m4(dob->ob->obmat, dob->mat); - object_duplilist_recursive(&group->id, scene, go->ob, lb, ob->obmat, level+1, animated); + object_duplilist_recursive(&group->id, scene, go->ob, lb, ob->obmat, level + 1, animated); copy_m4_m4(dob->ob->obmat, dob->omat); } } @@ -772,7 +772,7 @@ static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, i static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, int animated) { - extern int enable_cu_speed; /* object.c */ + extern int enable_cu_speed; /* object.c */ Object copyob; int cfrao = scene->r.cfra; int dupend = ob->dupend; @@ -783,7 +783,7 @@ static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, /* if we don't have any data/settings which will lead to object movement, * don't waste time trying, as it will all look the same... */ - if (ob->parent==NULL && ob->constraints.first==NULL && ob->adt==NULL) + if (ob->parent == NULL && ob->constraints.first == NULL && ob->adt == NULL) return; /* make a copy of the object's original data (before any dupli-data overwrites it) @@ -794,18 +794,18 @@ static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, copyob = *ob; /* duplicate over the required range */ - if (ob->transflag & OB_DUPLINOSPEED) enable_cu_speed= 0; + if (ob->transflag & OB_DUPLINOSPEED) enable_cu_speed = 0; - for (scene->r.cfra= ob->dupsta; scene->r.cfra<=dupend; scene->r.cfra++) { - short ok= 1; + for (scene->r.cfra = ob->dupsta; scene->r.cfra <= dupend; scene->r.cfra++) { + short ok = 1; /* - dupoff = how often a frames within the range shouldn't be made into duplis * - dupon = the length of each "skipping" block in frames */ if (ob->dupoff) { - ok= scene->r.cfra - ob->dupsta; - ok= ok % (ob->dupon+ob->dupoff); - ok= (ok < ob->dupon); + ok = scene->r.cfra - ob->dupsta; + ok = ok % (ob->dupon + ob->dupoff); + ok = (ok < ob->dupon); } if (ok) { @@ -816,22 +816,22 @@ static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, * However, this has always been the way that this worked (i.e. pre 2.5), so I guess that it'll be fine! */ BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, (float)scene->r.cfra, ADT_RECALC_ANIM); /* ob-eval will do drivers, so we don't need to do them */ - where_is_object_time(scene, ob, (float)scene->r.cfra); + BKE_object_where_is_calc_time(scene, ob, (float)scene->r.cfra); - dob= new_dupli_object(lb, ob, ob->obmat, ob->lay, scene->r.cfra, OB_DUPLIFRAMES, animated); + dob = new_dupli_object(lb, ob, ob->obmat, ob->lay, scene->r.cfra, OB_DUPLIFRAMES, animated); copy_m4_m4(dob->omat, copyob.obmat); } } - enable_cu_speed= 1; + enable_cu_speed = 1; /* reset frame to original frame, then re-evaluate animation as above * as 2.5 animation data may have far-reaching consequences */ - scene->r.cfra= cfrao; + scene->r.cfra = cfrao; BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, (float)scene->r.cfra, ADT_RECALC_ANIM); /* ob-eval will do drivers, so we don't need to do them */ - where_is_object_time(scene, ob, (float)scene->r.cfra); + BKE_object_where_is_calc_time(scene, ob, (float)scene->r.cfra); /* but, to make sure unkeyed object transforms are still sane, * let's copy object's original data back over @@ -857,7 +857,7 @@ static void vertex_dupli__mapFunc(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3]) { DupliObject *dob; - vertexDupliData *vdd= userData; + vertexDupliData *vdd = userData; float vec[3], q2[4], mat[3][3], tmat[4][4], obmat[4][4]; int origlay; @@ -870,10 +870,10 @@ static void vertex_dupli__mapFunc(void *userData, int index, const float co[3], if (vdd->par->transflag & OB_DUPLIROT) { if (no_f) { - vec[0]= -no_f[0]; vec[1]= -no_f[1]; vec[2]= -no_f[2]; + vec[0] = -no_f[0]; vec[1] = -no_f[1]; vec[2] = -no_f[2]; } else if (no_s) { - vec[0]= -no_s[0]; vec[1]= -no_s[1]; vec[2]= -no_s[2]; + vec[0] = -no_s[0]; vec[1] = -no_s[1]; vec[2] = -no_s[2]; } vec_to_quat(q2, vec, vdd->ob->trackflag, vdd->ob->upflag); @@ -885,7 +885,7 @@ static void vertex_dupli__mapFunc(void *userData, int index, const float co[3], origlay = vdd->ob->lay; - dob= new_dupli_object(vdd->lb, vdd->ob, obmat, vdd->par->lay, index, OB_DUPLIVERTS, vdd->animated); + dob = new_dupli_object(vdd->lb, vdd->ob, obmat, vdd->par->lay, index, OB_DUPLIVERTS, vdd->animated); /* restore the original layer so that each dupli will have proper dob->origlay */ vdd->ob->lay = origlay; @@ -897,7 +897,7 @@ static void vertex_dupli__mapFunc(void *userData, int index, const float co[3], float tmpmat[4][4]; copy_m4_m4(tmpmat, vdd->ob->obmat); copy_m4_m4(vdd->ob->obmat, obmat); /* pretend we are really this mat */ - object_duplilist_recursive((ID *)vdd->id, vdd->scene, vdd->ob, vdd->lb, obmat, vdd->level+1, vdd->animated); + object_duplilist_recursive((ID *)vdd->id, vdd->scene, vdd->ob, vdd->lb, obmat, vdd->level + 1, vdd->animated); copy_m4_m4(vdd->ob->obmat, tmpmat); } } @@ -905,13 +905,13 @@ static void vertex_dupli__mapFunc(void *userData, int index, const float co[3], static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int level, int animated) { Object *ob, *ob_iter; - Mesh *me= par->data; + Mesh *me = par->data; Base *base = NULL; DerivedMesh *dm; vertexDupliData vdd; Scene *sce = NULL; Group *group = NULL; - GroupObject * go = NULL; + GroupObject *go = NULL; BMEditMesh *em; float vec[3], no[3], pmat[4][4]; int totvert, a, oblay; @@ -920,54 +920,54 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl copy_m4_m4(pmat, par->obmat); /* simple preventing of too deep nested groups */ - if (level>MAX_DUPLI_RECUR) return; + if (level > MAX_DUPLI_RECUR) return; em = me->edit_btmesh; if (em) { - dm= editbmesh_get_derived_cage(scene, par, em, CD_MASK_BAREMESH); + dm = editbmesh_get_derived_cage(scene, par, em, CD_MASK_BAREMESH); } else - dm= mesh_get_derived_deform(scene, par, CD_MASK_BAREMESH); + dm = mesh_get_derived_deform(scene, par, CD_MASK_BAREMESH); if (G.rendering) { - vdd.orco= (float(*)[3])get_mesh_orco_verts(par); - transform_mesh_orco_verts(me, vdd.orco, me->totvert, 0); + vdd.orco = (float(*)[3])BKE_mesh_orco_verts_get(par); + BKE_mesh_orco_verts_transform(me, vdd.orco, me->totvert, 0); } else - vdd.orco= NULL; + vdd.orco = NULL; totvert = dm->getNumVerts(dm); /* having to loop on scene OR group objects is NOT FUN */ if (GS(id->name) == ID_SCE) { sce = (Scene *)id; - lay= sce->lay; - base= sce->base.first; + lay = sce->lay; + base = sce->base.first; } else { group = (Group *)id; - lay= group->layer; + lay = group->layer; go = group->gobject.first; } /* Start looping on Scene OR Group objects */ while (base || go) { if (sce) { - ob_iter= base->object; + ob_iter = base->object; oblay = base->lay; } else { - ob_iter= go->ob; + ob_iter = go->ob; oblay = ob_iter->lay; } - if (lay & oblay && scene->obedit!=ob_iter) { - ob=ob_iter->parent; + if (lay & oblay && scene->obedit != ob_iter) { + ob = ob_iter->parent; while (ob) { - if (ob==par) { + if (ob == par) { ob = ob_iter; - /* End Scene/Group object loop, below is generic */ + /* End Scene/Group object loop, below is generic */ /* par_space_mat - only used for groups so we can modify the space dupli's are in @@ -978,23 +978,23 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl else copy_m4_m4(vdd.obmat, ob->obmat); - vdd.id= id; - vdd.level= level; - vdd.animated= animated; - vdd.lb= lb; - vdd.ob= ob; - vdd.scene= scene; - vdd.par= par; + vdd.id = id; + vdd.level = level; + vdd.animated = animated; + vdd.lb = lb; + vdd.ob = ob; + vdd.scene = scene; + vdd.par = par; copy_m4_m4(vdd.pmat, pmat); /* mballs have a different dupli handling */ - if (ob->type!=OB_MBALL) ob->flag |= OB_DONE; /* doesnt render */ + if (ob->type != OB_MBALL) ob->flag |= OB_DONE; /* doesnt render */ if (me->edit_btmesh) { - dm->foreachMappedVert(dm, vertex_dupli__mapFunc, (void*) &vdd); + dm->foreachMappedVert(dm, vertex_dupli__mapFunc, (void *) &vdd); } else { - for (a=0; a<totvert; a++) { + for (a = 0; a < totvert; a++) { dm->getVertCo(dm, a, vec); dm->getVertNo(dm, a, no); @@ -1012,11 +1012,11 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl break; } - ob= ob->parent; + ob = ob->parent; } } - if (sce) base= base->next; /* scene loop */ - else go= go->next; /* group loop */ + if (sce) base = base->next; /* scene loop */ + else go = go->next; /* group loop */ } if (vdd.orco) @@ -1030,7 +1030,7 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa Base *base = NULL; DupliObject *dob; DerivedMesh *dm; - Mesh *me= par->data; + Mesh *me = par->data; MLoopUV *mloopuv; MPoly *mpoly, *mp; MLoop *mloop; @@ -1044,63 +1044,63 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa float ob__obmat[4][4]; /* needed for groups where the object matrix needs to be modified */ /* simple preventing of too deep nested groups */ - if (level>MAX_DUPLI_RECUR) return; + if (level > MAX_DUPLI_RECUR) return; copy_m4_m4(pmat, par->obmat); em = me->edit_btmesh; if (em) { - dm= editbmesh_get_derived_cage(scene, par, em, CD_MASK_BAREMESH); + dm = editbmesh_get_derived_cage(scene, par, em, CD_MASK_BAREMESH); } else { dm = mesh_get_derived_deform(scene, par, CD_MASK_BAREMESH); } - totface= dm->getNumPolys(dm); - mpoly= dm->getPolyArray(dm); - mloop= dm->getLoopArray(dm); - mvert= dm->getVertArray(dm); + totface = dm->getNumPolys(dm); + mpoly = dm->getPolyArray(dm); + mloop = dm->getLoopArray(dm); + mvert = dm->getVertArray(dm); if (G.rendering) { - orco= (float(*)[3])get_mesh_orco_verts(par); - transform_mesh_orco_verts(me, orco, me->totvert, 0); - mloopuv= me->mloopuv; + orco = (float(*)[3])BKE_mesh_orco_verts_get(par); + BKE_mesh_orco_verts_transform(me, orco, me->totvert, 0); + mloopuv = me->mloopuv; } else { - orco= NULL; - mloopuv= NULL; + orco = NULL; + mloopuv = NULL; } /* having to loop on scene OR group objects is NOT FUN */ if (GS(id->name) == ID_SCE) { sce = (Scene *)id; - lay= sce->lay; - base= sce->base.first; + lay = sce->lay; + base = sce->base.first; } else { group = (Group *)id; - lay= group->layer; + lay = group->layer; go = group->gobject.first; } /* Start looping on Scene OR Group objects */ while (base || go) { if (sce) { - ob_iter= base->object; + ob_iter = base->object; oblay = base->lay; } else { - ob_iter= go->ob; + ob_iter = go->ob; oblay = ob_iter->lay; } - if (lay & oblay && scene->obedit!=ob_iter) { - ob=ob_iter->parent; + if (lay & oblay && scene->obedit != ob_iter) { + ob = ob_iter->parent; while (ob) { - if (ob==par) { + if (ob == par) { ob = ob_iter; - /* End Scene/Group object loop, below is generic */ + /* End Scene/Group object loop, below is generic */ /* par_space_mat - only used for groups so we can modify the space dupli's are in * when par_space_mat is NULL ob->obmat can be used instead of ob__obmat @@ -1113,9 +1113,9 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa copy_m3_m4(imat, ob->parentinv); /* mballs have a different dupli handling */ - if (ob->type!=OB_MBALL) ob->flag |= OB_DONE; /* doesnt render */ + if (ob->type != OB_MBALL) ob->flag |= OB_DONE; /* doesnt render */ - for (a=0, mp= mpoly; a<totface; a++, mp++) { + for (a = 0, mp = mpoly; a < totface; a++, mp++) { int mv1; int mv2; int mv3; @@ -1125,25 +1125,25 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa float *v3; /* float *v4; */ /* UNUSED */ float cent[3], quat[4], mat[3][3], mat3[3][3], tmat[4][4], obmat[4][4]; - MLoop *loopstart= mloop + mp->loopstart; + MLoop *loopstart = mloop + mp->loopstart; if (mp->totloop < 3) { /* highly unlikely but to be safe */ continue; } else { - v1= mvert[(mv1= loopstart[0].v)].co; - v2= mvert[(mv2= loopstart[1].v)].co; - v3= mvert[(mv3= loopstart[2].v)].co; + v1 = mvert[(mv1 = loopstart[0].v)].co; + v2 = mvert[(mv2 = loopstart[1].v)].co; + v3 = mvert[(mv3 = loopstart[2].v)].co; #if 0 if (mp->totloop > 3) { - v4= mvert[(mv4= loopstart[3].v)].co; + v4 = mvert[(mv4 = loopstart[3].v)].co; } #endif } /* translation */ - mesh_calc_poly_center(mp, loopstart, mvert, cent); + BKE_mesh_calc_poly_center(mp, loopstart, mvert, cent); mul_m4_v3(pmat, cent); @@ -1160,8 +1160,8 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa /* scale */ if (par->transflag & OB_DUPLIFACES_SCALE) { - float size= mesh_calc_poly_area(mp, loopstart, mvert, NULL); - size= sqrtf(size) * par->dupfacesca; + float size = BKE_mesh_calc_poly_area(mp, loopstart, mvert, NULL); + size = sqrtf(size) * par->dupfacesca; mul_m3_fl(mat, size); } @@ -1171,9 +1171,9 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa copy_m4_m4(tmat, obmat); mul_m4_m4m3(obmat, tmat, mat); - dob= new_dupli_object(lb, ob, obmat, par->lay, a, OB_DUPLIFACES, animated); + dob = new_dupli_object(lb, ob, obmat, par->lay, a, OB_DUPLIFACES, animated); if (G.rendering) { - w= 1.0f / (float)mp->totloop; + w = 1.0f / (float)mp->totloop; if (orco) { int j; @@ -1194,18 +1194,18 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa float tmpmat[4][4]; copy_m4_m4(tmpmat, ob->obmat); copy_m4_m4(ob->obmat, obmat); /* pretend we are really this mat */ - object_duplilist_recursive((ID *)id, scene, ob, lb, ob->obmat, level+1, animated); + object_duplilist_recursive((ID *)id, scene, ob, lb, ob->obmat, level + 1, animated); copy_m4_m4(ob->obmat, tmpmat); } } break; } - ob= ob->parent; + ob = ob->parent; } } - if (sce) base= base->next; /* scene loop */ - else go= go->next; /* group loop */ + if (sce) base = base->next; /* scene loop */ + else go = go->next; /* group loop */ } if (orco) @@ -1217,30 +1217,30 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], ParticleSystem *psys, int level, int animated) { GroupObject *go; - Object *ob=NULL, **oblist=NULL, obcopy, *obcopylist=NULL; + Object *ob = NULL, **oblist = NULL, obcopy, *obcopylist = NULL; DupliObject *dob; ParticleDupliWeight *dw; ParticleSettings *part; ParticleData *pa; - ChildParticle *cpa=NULL; + ChildParticle *cpa = NULL; ParticleKey state; ParticleCacheKey *cache; float ctime, pa_time, scale = 1.0f; - float tmat[4][4], mat[4][4], pamat[4][4], vec[3], size=0.0; + float tmat[4][4], mat[4][4], pamat[4][4], vec[3], size = 0.0; float (*obmat)[4], (*oldobmat)[4]; int a, b, counter, hair = 0; - int totpart, totchild, totgroup=0 /*, pa_num */; + int totpart, totchild, totgroup = 0 /*, pa_num */; int no_draw_flag = PARS_UNEXIST; - if (psys==NULL) return; + if (psys == NULL) return; /* simple preventing of too deep nested groups */ - if (level>MAX_DUPLI_RECUR) return; + if (level > MAX_DUPLI_RECUR) return; - part=psys->part; + part = psys->part; - if (part==NULL) + if (part == NULL) return; if (!psys_check_enabled(par, psys)) @@ -1249,19 +1249,19 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p if (G.rendering == 0) no_draw_flag |= PARS_NO_DISP; - ctime = BKE_curframe(scene); /* NOTE: in old animsys, used parent object's timeoffset... */ + ctime = BKE_scene_frame_get(scene); /* NOTE: in old animsys, used parent object's timeoffset... */ totpart = psys->totpart; totchild = psys->totchild; BLI_srandom(31415926 + psys->seed); - if ((psys->renderdata || part->draw_as==PART_DRAW_REND) && ELEM(part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) { - ParticleSimulationData sim= {NULL}; - sim.scene= scene; - sim.ob= par; - sim.psys= psys; - sim.psmd= psys_get_modifier(par, psys); + if ((psys->renderdata || part->draw_as == PART_DRAW_REND) && ELEM(part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) { + ParticleSimulationData sim = {NULL}; + sim.scene = scene; + sim.ob = par; + sim.psys = psys; + sim.psmd = psys_get_modifier(par, psys); /* make sure emitter imat is in global coordinates instead of render view coordinates */ invert_m4_m4(par->imat, par->obmat); @@ -1274,7 +1274,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p if (part->dup_group == NULL || part->dup_group->gobject.first == NULL) return; - for (go=part->dup_group->gobject.first; go; go=go->next) + for (go = part->dup_group->gobject.first; go; go = go->next) if (go->ob == par) return; } @@ -1282,7 +1282,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p /* if we have a hair particle system, use the path cache */ if (part->type == PART_HAIR) { if (psys->flag & PSYS_HAIR_DONE) - hair= (totchild == 0 || psys->childcache) && psys->pathcache; + hair = (totchild == 0 || psys->childcache) && psys->pathcache; if (!hair) return; @@ -1296,29 +1296,29 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p psys->lattice = psys_get_lattice(&sim); /* gather list of objects or single object */ - if (part->ren_as==PART_DRAW_GR) { + if (part->ren_as == PART_DRAW_GR) { group_handle_recalc_and_update(scene, par, part->dup_group); if (part->draw & PART_DRAW_COUNT_GR) { - for (dw=part->dupliweights.first; dw; dw=dw->next) + for (dw = part->dupliweights.first; dw; dw = dw->next) totgroup += dw->count; } else { - for (go=part->dup_group->gobject.first; go; go=go->next) + for (go = part->dup_group->gobject.first; go; go = go->next) totgroup++; } /* we also copy the actual objects to restore afterwards, since - * where_is_object_time will change the object which breaks transform */ - oblist = MEM_callocN(totgroup*sizeof(Object *), "dupgroup object list"); - obcopylist = MEM_callocN(totgroup*sizeof(Object), "dupgroup copy list"); + * BKE_object_where_is_calc_time will change the object which breaks transform */ + oblist = MEM_callocN(totgroup * sizeof(Object *), "dupgroup object list"); + obcopylist = MEM_callocN(totgroup * sizeof(Object), "dupgroup copy list"); if (part->draw & PART_DRAW_COUNT_GR && totgroup) { dw = part->dupliweights.first; - for (a=0; a<totgroup; dw=dw->next) { - for (b=0; b<dw->count; b++, a++) { + for (a = 0; a < totgroup; dw = dw->next) { + for (b = 0; b < dw->count; b++, a++) { oblist[a] = dw->ob; obcopylist[a] = *dw->ob; } @@ -1326,7 +1326,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p } else { go = part->dup_group->gobject.first; - for (a=0; a<totgroup; a++, go=go->next) { + for (a = 0; a < totgroup; a++, go = go->next) { oblist[a] = go->ob; obcopylist[a] = *go->ob; } @@ -1337,13 +1337,13 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p obcopy = *ob; } - if (totchild==0 || part->draw & PART_DRAW_PARENT) + if (totchild == 0 || part->draw & PART_DRAW_PARENT) a = 0; else a = totpart; - for (pa=psys->particles, counter=0; a<totpart+totchild; a++, pa++, counter++) { - if (a<totpart) { + for (pa = psys->particles, counter = 0; a < totpart + totchild; a++, pa++, counter++) { + if (a < totpart) { /* handle parent particle */ if (pa->flag & no_draw_flag) continue; @@ -1364,29 +1364,29 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p /* some hair paths might be non-existent so they can't be used for duplication */ if (hair && ((a < totpart && psys->pathcache[a]->steps < 0) || - (a >= totpart && psys->childcache[a-totpart]->steps < 0))) + (a >= totpart && psys->childcache[a - totpart]->steps < 0))) { continue; } - if (part->ren_as==PART_DRAW_GR) { + if (part->ren_as == PART_DRAW_GR) { /* prevent divide by zero below [#28336] */ if (totgroup == 0) continue; /* for groups, pick the object based on settings */ - if (part->draw&PART_DRAW_RAND_GR) - b= BLI_rand() % totgroup; + if (part->draw & PART_DRAW_RAND_GR) + b = BLI_rand() % totgroup; else - b= a % totgroup; + b = a % totgroup; ob = oblist[b]; obmat = oblist[b]->obmat; oldobmat = obcopylist[b].obmat; } else { - obmat= ob->obmat; - oldobmat= obcopy.obmat; + obmat = ob->obmat; + oldobmat = obcopy.obmat; } if (hair) { @@ -1396,12 +1396,12 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p psys_get_dupli_path_transform(&sim, pa, NULL, cache, pamat, &scale); } else { - cache = psys->childcache[a-totpart]; + cache = psys->childcache[a - totpart]; psys_get_dupli_path_transform(&sim, NULL, cpa, cache, pamat, &scale); } copy_v3_v3(pamat[3], cache->co); - pamat[3][3]= 1.0f; + pamat[3][3] = 1.0f; } else { @@ -1415,17 +1415,17 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p normalize_qt_qt(tquat, state.rot); quat_to_mat4(pamat, tquat); copy_v3_v3(pamat[3], state.co); - pamat[3][3]= 1.0f; + pamat[3][3] = 1.0f; } } - if (part->ren_as==PART_DRAW_GR && psys->part->draw & PART_DRAW_WHOLE_GR) { - for (go= part->dup_group->gobject.first, b=0; go; go= go->next, b++) { + if (part->ren_as == PART_DRAW_GR && psys->part->draw & PART_DRAW_WHOLE_GR) { + for (go = part->dup_group->gobject.first, b = 0; go; go = go->next, b++) { copy_m4_m4(tmat, oblist[b]->obmat); /* apply particle scale */ - mul_mat3_m4_fl(tmat, size*scale); - mul_v3_fl(tmat[3], size*scale); + mul_mat3_m4_fl(tmat, size * scale); + mul_v3_fl(tmat[3], size * scale); /* group dupli offset, should apply after everything else */ if (!is_zero_v3(part->dup_group->dupli_ofs)) sub_v3_v3v3(tmat[3], tmat[3], part->dup_group->dupli_ofs); @@ -1437,7 +1437,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p else copy_m4_m4(mat, tmat); - dob= new_dupli_object(lb, go->ob, mat, par->lay, counter, OB_DUPLIPARTS, animated); + 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(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco); @@ -1445,7 +1445,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p } else { /* to give ipos in object correct offset */ - where_is_object_time(scene, ob, ctime-pa_time); + BKE_object_where_is_calc_time(scene, ob, ctime - pa_time); copy_v3_v3(vec, obmat[3]); obmat[3][0] = obmat[3][1] = obmat[3][2] = 0.0f; @@ -1457,7 +1457,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p xvec[1] = xvec[2] = 0; vec_to_quat(q, xvec, ob->trackflag, ob->upflag); quat_to_mat4(obmat, q); - obmat[3][3]= 1.0f; + obmat[3][3] = 1.0f; } /* Normal particles and cached hair live in global space so we need to @@ -1469,7 +1469,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p copy_m4_m4(mat, pamat); mult_m4_m4m4(tmat, mat, obmat); - mul_mat3_m4_fl(tmat, size*scale); + mul_mat3_m4_fl(tmat, size * scale); if (par_space_mat) mult_m4_m4m4(mat, par_space_mat, tmat); @@ -1479,20 +1479,20 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p if (part->draw & PART_DRAW_GLOBAL_OB) add_v3_v3v3(mat[3], mat[3], vec); - dob= new_dupli_object(lb, ob, mat, ob->lay, counter, GS(id->name) == ID_GR ? OB_DUPLIGROUP : OB_DUPLIPARTS, animated); + 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(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco); } } - /* restore objects since they were changed in where_is_object_time */ - if (part->ren_as==PART_DRAW_GR) { - for (a=0; a<totgroup; a++) - *(oblist[a])= obcopylist[a]; + /* restore objects since they were changed in BKE_object_where_is_calc_time */ + if (part->ren_as == PART_DRAW_GR) { + for (a = 0; a < totgroup; a++) + *(oblist[a]) = obcopylist[a]; } else - *ob= obcopy; + *ob = obcopy; } /* clean up */ @@ -1512,19 +1512,19 @@ static Object *find_family_object(Object **obar, char *family, char ch) Object *ob; int flen; - if ( obar[(int)ch] ) return obar[(int)ch]; + if (obar[(int)ch]) return obar[(int)ch]; - flen= strlen(family); + flen = strlen(family); - ob= G.main->object.first; + ob = G.main->object.first; while (ob) { if (ob->id.name[flen + 2] == ch) { - if ( strncmp(ob->id.name+2, family, flen)==0 ) break; + if (strncmp(ob->id.name + 2, family, flen) == 0) break; } - ob= ob->id.next; + ob = ob->id.next; } - obar[(int)ch]= ob; + obar[(int)ch] = ob; return ob; } @@ -1532,37 +1532,37 @@ static Object *find_family_object(Object **obar, char *family, char ch) static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int level, int animated) { - Object *ob, *obar[256]= {NULL}; + Object *ob, *obar[256] = {NULL}; Curve *cu; struct chartrans *ct, *chartransdata; float vec[3], obmat[4][4], pmat[4][4], fsize, xof, yof; int slen, a; /* simple preventing of too deep nested groups */ - if (level>MAX_DUPLI_RECUR) return; + if (level > MAX_DUPLI_RECUR) return; copy_m4_m4(pmat, par->obmat); /* in par the family name is stored, use this to find the other objects */ - chartransdata= BKE_text_to_curve(G.main, scene, par, FO_DUPLI); - if (chartransdata==NULL) return; + chartransdata = BKE_vfont_to_curve(G.main, scene, par, FO_DUPLI); + if (chartransdata == NULL) return; - cu= par->data; - slen= strlen(cu->str); - fsize= cu->fsize; - xof= cu->xof; - yof= cu->yof; + cu = par->data; + slen = strlen(cu->str); + fsize = cu->fsize; + xof = cu->xof; + yof = cu->yof; - ct= chartransdata; + ct = chartransdata; - for (a=0; a<slen; a++, ct++) { + for (a = 0; a < slen; a++, ct++) { - ob= find_family_object(obar, cu->family, cu->str[a]); + ob = find_family_object(obar, cu->family, cu->str[a]); if (ob) { - vec[0]= fsize*(ct->xof - xof); - vec[1]= fsize*(ct->yof - yof); - vec[2]= 0.0; + vec[0] = fsize * (ct->xof - xof); + vec[1] = fsize * (ct->yof - yof); + vec[2] = 0.0; mul_m4_v3(pmat, vec); @@ -1580,7 +1580,7 @@ static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int level, i static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4], int level, int animated) { - if ((ob->transflag & OB_DUPLI)==0) + if ((ob->transflag & OB_DUPLI) == 0) return; /* Should the dupli's be generated for this object? - Respect restrict flags */ @@ -1597,35 +1597,35 @@ static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBas if (ob->transflag & OB_DUPLIPARTS) { ParticleSystem *psys = ob->particlesystem.first; - for (; psys; psys=psys->next) - new_particle_duplilist(duplilist, id, scene, ob, par_space_mat, psys, level+1, animated); + for (; psys; psys = psys->next) + new_particle_duplilist(duplilist, id, scene, ob, par_space_mat, psys, level + 1, animated); } else if (ob->transflag & OB_DUPLIVERTS) { - if (ob->type==OB_MESH) { - vertex_duplilist(duplilist, id, scene, ob, par_space_mat, level+1, animated); + if (ob->type == OB_MESH) { + vertex_duplilist(duplilist, id, scene, ob, par_space_mat, level + 1, animated); } - else if (ob->type==OB_FONT) { - if (GS(id->name)==ID_SCE) { /* TODO - support dupligroups */ - font_duplilist(duplilist, scene, ob, level+1, animated); + else if (ob->type == OB_FONT) { + if (GS(id->name) == ID_SCE) { /* TODO - support dupligroups */ + font_duplilist(duplilist, scene, ob, level + 1, animated); } } } else if (ob->transflag & OB_DUPLIFACES) { - if (ob->type==OB_MESH) - face_duplilist(duplilist, id, scene, ob, par_space_mat, level+1, animated); + if (ob->type == OB_MESH) + face_duplilist(duplilist, id, scene, ob, par_space_mat, level + 1, animated); } else if (ob->transflag & OB_DUPLIFRAMES) { - if (GS(id->name)==ID_SCE) { /* TODO - support dupligroups */ - frames_duplilist(duplilist, scene, ob, level+1, animated); + if (GS(id->name) == ID_SCE) { /* TODO - support dupligroups */ + frames_duplilist(duplilist, scene, ob, level + 1, animated); } } else if (ob->transflag & OB_DUPLIGROUP) { DupliObject *dob; - group_duplilist(duplilist, scene, ob, level+1, animated); /* now recursive */ + group_duplilist(duplilist, scene, ob, level + 1, animated); /* now recursive */ - if (level==0) { - for (dob= duplilist->first; dob; dob= dob->next) + if (level == 0) { + for (dob = duplilist->first; dob; dob = dob->next) if (dob->type == OB_DUPLIGROUP) copy_m4_m4(dob->ob->obmat, dob->mat); } @@ -1636,8 +1636,8 @@ static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBas * note; group dupli's already set transform matrix. see note in group_duplilist() */ ListBase *object_duplilist(Scene *sce, Object *ob) { - ListBase *duplilist= MEM_mallocN(sizeof(ListBase), "duplilist"); - duplilist->first= duplilist->last= NULL; + ListBase *duplilist = MEM_mallocN(sizeof(ListBase), "duplilist"); + duplilist->first = duplilist->last = NULL; object_duplilist_recursive((ID *)sce, sce, ob, duplilist, NULL, 0, 0); return duplilist; } @@ -1649,8 +1649,8 @@ void free_object_duplilist(ListBase *lb) /* loop in reverse order, if object is instanced multiple times * the original layer may not really be original otherwise, proper * solution is more complicated */ - for (dob= lb->last; dob; dob= dob->prev) { - dob->ob->lay= dob->origlay; + for (dob = lb->last; dob; dob = dob->prev) { + dob->ob->lay = dob->origlay; copy_m4_m4(dob->ob->obmat, dob->omat); } @@ -1662,16 +1662,16 @@ int count_duplilist(Object *ob) { if (ob->transflag & OB_DUPLI) { if (ob->transflag & OB_DUPLIVERTS) { - if (ob->type==OB_MESH) { + if (ob->type == OB_MESH) { if (ob->transflag & OB_DUPLIVERTS) { ParticleSystem *psys = ob->particlesystem.first; - int pdup=0; + int pdup = 0; - for (; psys; psys=psys->next) + for (; psys; psys = psys->next) pdup += psys->totpart; - if (pdup==0) { - Mesh *me= ob->data; + if (pdup == 0) { + Mesh *me = ob->data; return me->totvert; } else @@ -1680,9 +1680,9 @@ int count_duplilist(Object *ob) } } else if (ob->transflag & OB_DUPLIFRAMES) { - int tot= ob->dupend - ob->dupsta; - tot/= (ob->dupon+ob->dupoff); - return tot*ob->dupon; + int tot = ob->dupend - ob->dupsta; + tot /= (ob->dupon + ob->dupoff); + return tot * ob->dupon; } } return 1; diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 73f1ce1526a..8982017403d 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -254,8 +254,8 @@ AnimData *BKE_copy_animdata (AnimData *adt, const short do_action) /* make a copy of action - at worst, user has to delete copies... */ if (do_action) { - dadt->action= copy_action(adt->action); - dadt->tmpact= copy_action(adt->tmpact); + dadt->action= BKE_action_copy(adt->action); + dadt->tmpact= BKE_action_copy(adt->tmpact); } else { id_us_plus((ID *)dadt->action); @@ -299,11 +299,11 @@ void BKE_copy_animdata_id_action(ID *id) if (adt) { if (adt->action) { id_us_min((ID *)adt->action); - adt->action= copy_action(adt->action); + adt->action= BKE_action_copy(adt->action); } if (adt->tmpact) { id_us_min((ID *)adt->tmpact); - adt->tmpact= copy_action(adt->tmpact); + adt->tmpact= BKE_action_copy(adt->tmpact); } } } @@ -315,8 +315,8 @@ static void make_local_strips(ListBase *strips) NlaStrip *strip; for (strip=strips->first; strip; strip=strip->next) { - if (strip->act) make_local_action(strip->act); - if (strip->remap && strip->remap->target) make_local_action(strip->remap->target); + if (strip->act) BKE_action_make_local(strip->act); + if (strip->remap && strip->remap->target) BKE_action_make_local(strip->remap->target); make_local_strips(&strip->strips); } @@ -328,10 +328,10 @@ void BKE_animdata_make_local(AnimData *adt) NlaTrack *nlt; /* Actions - Active and Temp */ - if (adt->action) make_local_action(adt->action); - if (adt->tmpact) make_local_action(adt->tmpact); + if (adt->action) BKE_action_make_local(adt->action); + if (adt->tmpact) BKE_action_make_local(adt->tmpact); /* Remaps */ - if (adt->remap && adt->remap->target) make_local_action(adt->remap->target); + if (adt->remap && adt->remap->target) BKE_action_make_local(adt->remap->target); /* Drivers */ // TODO: need to remap the ID-targets too? @@ -426,7 +426,7 @@ void action_move_fcurves_by_basepath(bAction *srcAct, bAction *dstAct, const cha /* if grouped... */ if (fcu->grp) { /* make sure there will be a matching group on the other side for the migrants */ - agrp = action_groups_find_named(dstAct, fcu->grp->name); + agrp = BKE_action_group_find_name(dstAct, fcu->grp->name); if (agrp == NULL) { /* add a new one with a similar name (usually will be the same though) */ diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index b0d0ace2a7e..09b295aabf1 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -75,25 +75,25 @@ /* **************** Generic Functions, data level *************** */ -bArmature *add_armature(const char *name) +bArmature *BKE_armature_add(const char *name) { bArmature *arm; - arm = alloc_libblock (&G.main->armature, ID_AR, name); - arm->deformflag = ARM_DEF_VGROUP|ARM_DEF_ENVELOPE; + arm = BKE_libblock_alloc(&G.main->armature, ID_AR, name); + arm->deformflag = ARM_DEF_VGROUP | ARM_DEF_ENVELOPE; arm->flag = ARM_COL_CUSTOM; /* custom bone-group colors */ arm->layer = 1; return arm; } -bArmature *get_armature(Object *ob) +bArmature *BKE_armature_from_object(Object *ob) { if (ob->type == OB_ARMATURE) return (bArmature *)ob->data; return NULL; } -void free_bonelist(ListBase *lb) +void BKE_armature_bonelist_free(ListBase *lb) { Bone *bone; @@ -102,16 +102,16 @@ void free_bonelist(ListBase *lb) IDP_FreeProperty(bone->prop); MEM_freeN(bone->prop); } - free_bonelist(&bone->childbase); + BKE_armature_bonelist_free(&bone->childbase); } BLI_freelistN(lb); } -void free_armature(bArmature *arm) +void BKE_armature_free(bArmature *arm) { if (arm) { - free_bonelist(&arm->bonebase); + BKE_armature_bonelist_free(&arm->bonebase); /* free editmode data */ if (arm->edbo) { @@ -135,7 +135,7 @@ void free_armature(bArmature *arm) } } -void make_local_armature(bArmature *arm) +void BKE_armature_make_local(bArmature *arm) { Main *bmain = G.main; int is_local = FALSE, is_lib = FALSE; @@ -161,7 +161,7 @@ void make_local_armature(bArmature *arm) id_clear_lib_data(bmain, &arm->id); } else if (is_local && is_lib) { - bArmature *arm_new = copy_armature(arm); + bArmature *arm_new = BKE_armature_copy(arm); arm_new->id.us = 0; /* Remap paths of new ID using old library as base. */ @@ -179,7 +179,7 @@ void make_local_armature(bArmature *arm) } } -static void copy_bonechildren(Bone* newBone, Bone* oldBone, Bone* actBone, Bone **newActBone) +static void copy_bonechildren(Bone *newBone, Bone *oldBone, Bone *actBone, Bone **newActBone) { Bone *curBone, *newChildBone; @@ -201,13 +201,13 @@ static void copy_bonechildren(Bone* newBone, Bone* oldBone, Bone* actBone, Bone } } -bArmature *copy_armature(bArmature *arm) +bArmature *BKE_armature_copy(bArmature *arm) { bArmature *newArm; Bone *oldBone, *newBone; - Bone *newActBone= NULL; + Bone *newActBone = NULL; - newArm = copy_libblock(&arm->id); + newArm = BKE_libblock_copy(&arm->id); BLI_duplicatelist(&newArm->bonebase, &arm->bonebase); /* Duplicate the childrens' lists*/ @@ -245,7 +245,7 @@ static Bone *get_named_bone_bonechildren(Bone *bone, const char *name) /* Walk the list until the bone is found */ -Bone *get_named_bone(bArmature *arm, const char *name) +Bone *BKE_armature_find_bone_name(bArmature *arm, const char *name) { Bone *bone = NULL, *curBone; @@ -340,27 +340,27 @@ int bone_autoside_name(char name[MAXBONENAME], int UNUSED(strip_number), short a while (change) { /* remove extensions */ change = 0; - if (len > 2 && basename[len-2] == '.') { - if (basename[len-1] == 'L' || basename[len-1] == 'R') { /* L R */ - basename[len-2] = '\0'; + if (len > 2 && basename[len - 2] == '.') { + if (basename[len - 1] == 'L' || basename[len - 1] == 'R') { /* L R */ + basename[len - 2] = '\0'; len -= 2; change = 1; } } - else if (len > 3 && basename[len-3] == '.') { - if ((basename[len-2] == 'F' && basename[len-1] == 'r') || /* Fr */ - (basename[len-2] == 'B' && basename[len-1] == 'k')) /* Bk */ + else if (len > 3 && basename[len - 3] == '.') { + if ((basename[len - 2] == 'F' && basename[len - 1] == 'r') || /* Fr */ + (basename[len - 2] == 'B' && basename[len - 1] == 'k')) /* Bk */ { - basename[len-3] = '\0'; + basename[len - 3] = '\0'; len -= 3; change = 1; } } - else if (len > 4 && basename[len-4] == '.') { - if ((basename[len-3] == 'T' && basename[len-2] == 'o' && basename[len-1] == 'p') || /* Top */ - (basename[len-3] == 'B' && basename[len-2] == 'o' && basename[len-1] == 't')) /* Bot */ + else if (len > 4 && basename[len - 4] == '.') { + if ((basename[len - 3] == 'T' && basename[len - 2] == 'o' && basename[len - 1] == 'p') || /* Top */ + (basename[len - 3] == 'B' && basename[len - 2] == 'o' && basename[len - 1] == 't')) /* Bot */ { - basename[len-4] = '\0'; + basename[len - 4] = '\0'; len -= 4; change = 1; } @@ -368,7 +368,7 @@ int bone_autoside_name(char name[MAXBONENAME], int UNUSED(strip_number), short a } if ((MAXBONENAME - len) < strlen(extension) + 1) { /* add 1 for the '.' */ - strncpy(name, basename, len-strlen(extension)); + strncpy(name, basename, len - strlen(extension)); } BLI_snprintf(name, MAXBONENAME, "%s.%s", basename, extension); @@ -382,44 +382,44 @@ int bone_autoside_name(char name[MAXBONENAME], int UNUSED(strip_number), short a /* ************* B-Bone support ******************* */ -#define MAX_BBONE_SUBDIV 32 +#define MAX_BBONE_SUBDIV 32 /* data has MAX_BBONE_SUBDIV+1 interpolated points, will become desired amount with equal distances */ static void equalize_bezier(float *data, int desired) { float *fp, totdist, ddist, dist, fac1, fac2; - float pdist[MAX_BBONE_SUBDIV+1]; - float temp[MAX_BBONE_SUBDIV+1][4]; + float pdist[MAX_BBONE_SUBDIV + 1]; + float temp[MAX_BBONE_SUBDIV + 1][4]; int a, nr; pdist[0] = 0.0f; for (a = 0, fp = data; a < MAX_BBONE_SUBDIV; a++, fp += 4) { copy_qt_qt(temp[a], fp); - pdist[a+1] = pdist[a] + len_v3v3(fp, fp+4); + pdist[a + 1] = pdist[a] + len_v3v3(fp, fp + 4); } /* do last point */ copy_qt_qt(temp[a], fp); totdist = pdist[a]; /* go over distances and calculate new points */ - ddist = totdist/((float)desired); + ddist = totdist / ((float)desired); nr = 1; - for (a = 1, fp = data+4; a < desired; a++, fp += 4) { - dist = ((float)a)*ddist; + for (a = 1, fp = data + 4; a < desired; a++, fp += 4) { + dist = ((float)a) * ddist; /* we're looking for location (distance) 'dist' in the array */ while ((dist >= pdist[nr]) && nr < MAX_BBONE_SUBDIV) nr++; - fac1 = pdist[nr] - pdist[nr-1]; + fac1 = pdist[nr] - pdist[nr - 1]; fac2 = pdist[nr] - dist; fac1 = fac2 / fac1; fac2 = 1.0f - fac1; - fp[0] = fac1*temp[nr-1][0] + fac2*temp[nr][0]; - fp[1] = fac1*temp[nr-1][1] + fac2*temp[nr][1]; - fp[2] = fac1*temp[nr-1][2] + fac2*temp[nr][2]; - fp[3] = fac1*temp[nr-1][3] + fac2*temp[nr][3]; + fp[0] = fac1 * temp[nr - 1][0] + fac2 * temp[nr][0]; + fp[1] = fac1 * temp[nr - 1][1] + fac2 * temp[nr][1]; + fp[2] = fac1 * temp[nr - 1][2] + fac2 * temp[nr][2]; + fp[3] = fac1 * temp[nr - 1][3] + fac2 * temp[nr][3]; } /* set last point, needed for orientation calculus */ copy_qt_qt(fp, temp[MAX_BBONE_SUBDIV]); @@ -436,7 +436,7 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) Bone *bone = pchan->bone; float h1[3], h2[3], scale[3], length, hlength1, hlength2, roll1 = 0.0f, roll2; float mat3[3][3], imat[4][4], posemat[4][4], scalemat[4][4], iscalemat[4][4]; - float data[MAX_BBONE_SUBDIV+1][4], *fp; + float data[MAX_BBONE_SUBDIV + 1][4], *fp; int a, doscale = 0; length = bone->length; @@ -459,8 +459,8 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) } } - hlength1 = bone->ease1*length*0.390464f; /* 0.5*sqrt(2)*kappa, the handle length for near-perfect circles */ - hlength2 = bone->ease2*length*0.390464f; + hlength1 = bone->ease1 * length * 0.390464f; /* 0.5*sqrt(2)*kappa, the handle length for near-perfect circles */ + hlength2 = bone->ease2 * length * 0.390464f; /* evaluate next and prev bones */ if (bone->flag & BONE_CONNECTED) @@ -494,7 +494,7 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) copy_v3_v3(h1, prev->pose_head); mul_m4_v3(imat, h1); - if (prev->bone->segments>1) { + if (prev->bone->segments > 1) { /* if previous bone is B-bone too, use average handle direction */ h1[1] -= length; roll1 = 0.0f; @@ -534,10 +534,10 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) mul_m4_v3(imat, h2); /* if next bone is B-bone too, use average handle direction */ - if (next->bone->segments>1) + if (next->bone->segments > 1) ; else - h2[1]-= length; + h2[1] -= length; normalize_v3(h2); /* find the next roll to interpolate as well */ @@ -579,7 +579,7 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) /* make transformation matrices for the segments for drawing */ for (a = 0, fp = data[0]; a < bone->segments; a++, fp += 4) { - sub_v3_v3v3(h1, fp+4, fp); + sub_v3_v3v3(h1, fp + 4, fp); vec_roll_to_mat3(h1, fp[3], mat3); /* fp[3] is roll */ copy_m4_m3(result_array[a].mat, mat3); @@ -613,11 +613,11 @@ static void pchan_b_bone_defmats(bPoseChannel *pchan, bPoseChanDeform *pdef_info int a; /* allocate b_bone matrices and dual quats */ - b_bone_mats = MEM_mallocN((1+bone->segments)*sizeof(Mat4), "BBone defmats"); + b_bone_mats = MEM_mallocN((1 + bone->segments) * sizeof(Mat4), "BBone defmats"); pdef_info->b_bone_mats = b_bone_mats; if (use_quaternion) { - b_bone_dual_quats = MEM_mallocN((bone->segments)*sizeof(DualQuat), "BBone dqs"); + b_bone_dual_quats = MEM_mallocN((bone->segments) * sizeof(DualQuat), "BBone dqs"); pdef_info->b_bone_dual_quats = b_bone_dual_quats; } @@ -634,11 +634,11 @@ static void pchan_b_bone_defmats(bPoseChannel *pchan, bPoseChanDeform *pdef_info for (a = 0; a < bone->segments; a++) { invert_m4_m4(tmat, b_bone_rest[a].mat); - mul_serie_m4(b_bone_mats[a+1].mat, pchan->chan_mat, bone->arm_mat, b_bone[a].mat, tmat, b_bone_mats[0].mat, + mul_serie_m4(b_bone_mats[a + 1].mat, pchan->chan_mat, bone->arm_mat, b_bone[a].mat, tmat, b_bone_mats[0].mat, NULL, NULL, NULL); if (use_quaternion) - mat4_to_dquat(&b_bone_dual_quats[a], bone->arm_mat, b_bone_mats[a+1].mat); + mat4_to_dquat(&b_bone_dual_quats[a], bone->arm_mat, b_bone_mats[a + 1].mat); } } @@ -650,24 +650,24 @@ static void b_bone_deform(bPoseChanDeform *pdef_info, Bone *bone, float co[3], D int a; /* need to transform co back to bonespace, only need y */ - y = mat[0][1]*co[0] + mat[1][1]*co[1] + mat[2][1]*co[2] + mat[3][1]; + y = mat[0][1] * co[0] + mat[1][1] * co[1] + mat[2][1] * co[2] + mat[3][1]; /* now calculate which of the b_bones are deforming this */ - segment = bone->length/((float)bone->segments); - a = (int)(y/segment); + segment = bone->length / ((float)bone->segments); + a = (int)(y / segment); /* note; by clamping it extends deform at endpoints, goes best with * straight joints in restpos. */ - CLAMP(a, 0, bone->segments-1); + CLAMP(a, 0, bone->segments - 1); if (dq) { copy_dq_dq(dq, &(pdef_info->b_bone_dual_quats)[a]); } else { - mul_m4_v3(b_bone[a+1].mat, co); + mul_m4_v3(b_bone[a + 1].mat, co); if (defmat) { - copy_m3_m4(defmat, b_bone[a+1].mat); + copy_m3_m4(defmat, b_bone[a + 1].mat); } } } @@ -699,27 +699,27 @@ float distfactor_to_bone(const float vec[3], const float b1[3], const float b2[3 rad = rad2; } else { - dist = (hsqr - (a*a)); + dist = (hsqr - (a * a)); if (l != 0.0f) { - rad = a/l; - rad = rad*rad2 + (1.0f-rad)*rad1; + rad = a / l; + rad = rad * rad2 + (1.0f - rad) * rad1; } else rad = rad1; } - a = rad*rad; + a = rad * rad; if (dist < a) return 1.0f; else { - l = rad+rdist; + l = rad + rdist; l *= l; if (rdist == 0.0f || dist >= l) return 0.0f; else { - a = sqrtf(dist)-rad; - return 1.0f-( a*a )/( rdist*rdist ); + a = sqrtf(dist) - rad; + return 1.0f - (a * a) / (rdist * rdist); } } } @@ -796,15 +796,15 @@ static void pchan_bone_deform(bPoseChannel *pchan, bPoseChanDeform *pdef_info, f copy_v3_v3(cop, co); if (vec) { - if (pchan->bone->segments>1) + if (pchan->bone->segments > 1) /* applies on cop and bbonemat */ b_bone_deform(pdef_info, pchan->bone, cop, NULL, (mat) ? bbonemat : NULL); else mul_m4_v3(pchan->chan_mat, cop); - vec[0] += (cop[0]-co[0])*weight; - vec[1] += (cop[1]-co[1])*weight; - vec[2] += (cop[2]-co[2])*weight; + vec[0] += (cop[0] - co[0]) * weight; + vec[1] += (cop[1] - co[1]) * weight; + vec[2] += (cop[2] - co[2]) * weight; if (mat) pchan_deform_mat_add(pchan, weight, bbonemat, mat); @@ -856,10 +856,10 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float totchan = BLI_countlist(&armOb->pose->chanbase); if (use_quaternion) { - dualquats = MEM_callocN(sizeof(DualQuat)*totchan, "dualquats"); + dualquats = MEM_callocN(sizeof(DualQuat) * totchan, "dualquats"); } - pdef_info_array = MEM_callocN(sizeof(bPoseChanDeform)*totchan, "bPoseChanDeform"); + pdef_info_array = MEM_callocN(sizeof(bPoseChanDeform) * totchan, "bPoseChanDeform"); totchan = 0; pdef_info = pdef_info_array; @@ -891,7 +891,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float Lattice *lt = target->data; dverts = lt->dvert; if (dverts) - target_totvert = lt->pntsu*lt->pntsv*lt->pntsw; + target_totvert = lt->pntsu * lt->pntsv * lt->pntsw; } } @@ -909,7 +909,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float defnrToPC = MEM_callocN(sizeof(*defnrToPC) * defbase_tot, "defnrToBone"); defnrToPCIndex = MEM_callocN(sizeof(*defnrToPCIndex) * defbase_tot, "defnrToIndex"); for (i = 0, dg = target->defbase.first; dg; i++, dg = dg->next) { - defnrToPC[i] = get_pose_channel(armOb->pose, dg->name); + defnrToPC[i] = BKE_pose_channel_find_name(armOb->pose, dg->name); /* exclude non-deforming bones */ if (defnrToPC[i]) { if (defnrToPC[i]->bone->flag & BONE_NO_DEFORM) { @@ -963,7 +963,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float armature_weight = defvert_find_weight(dvert, armature_def_nr); if (invert_vgroup) - armature_weight = 1.0f-armature_weight; + armature_weight = 1.0f - armature_weight; /* hackish: the blending factor can be used for blending with prevCos too */ if (prevCos) { @@ -1039,7 +1039,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float smat = summat; } else { - mul_v3_fl(vec, armature_weight/contrib); + mul_v3_fl(vec, armature_weight / contrib); add_v3_v3v3(co, vec, co); } @@ -1051,7 +1051,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float copy_m3_m3(tmpmat, defMats[i]); if (!use_quaternion) /* quaternion already is scale corrected */ - mul_m3_fl(smat, armature_weight/contrib); + mul_m3_fl(smat, armature_weight / contrib); mul_serie_m3(defMats[i], tmpmat, pre, smat, post, NULL, NULL, NULL, NULL); } @@ -1063,9 +1063,9 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float /* interpolate with previous modifier position using weight group */ if (prevCos) { float mw = 1.0f - prevco_weight; - vertexCos[i][0] = prevco_weight*vertexCos[i][0] + mw*co[0]; - vertexCos[i][1] = prevco_weight*vertexCos[i][1] + mw*co[1]; - vertexCos[i][2] = prevco_weight*vertexCos[i][2] + mw*co[2]; + vertexCos[i][0] = prevco_weight * vertexCos[i][0] + mw * co[0]; + vertexCos[i][1] = prevco_weight * vertexCos[i][1] + mw * co[1]; + vertexCos[i][2] = prevco_weight * vertexCos[i][2] + mw * co[2]; } } @@ -1090,7 +1090,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float /* ************ END Armature Deform ******************* */ -void get_objectspace_bone_matrix(struct Bone* bone, float M_accumulatedMatrix[][4], int UNUSED(root), +void get_objectspace_bone_matrix(struct Bone *bone, float M_accumulatedMatrix[][4], int UNUSED(root), int UNUSED(posed)) { copy_m4_m4(M_accumulatedMatrix, bone->arm_mat); @@ -1099,7 +1099,7 @@ void get_objectspace_bone_matrix(struct Bone* bone, float M_accumulatedMatrix[][ /* **************** Space to Space API ****************** */ /* Convert World-Space Matrix to Pose-Space Matrix */ -void armature_mat_world_to_pose(Object *ob, float inmat[][4], float outmat[][4]) +void BKE_armature_mat_world_to_pose(Object *ob, float inmat[][4], float outmat[][4]) { float obmat[4][4]; @@ -1117,7 +1117,7 @@ void armature_mat_world_to_pose(Object *ob, float inmat[][4], float outmat[][4]) /* Convert World-Space Location to Pose-Space Location * NOTE: this cannot be used to convert to pose-space location of the supplied * pose-channel into its local space (i.e. 'visual'-keyframing) */ -void armature_loc_world_to_pose(Object *ob, const float inloc[3], float outloc[3]) +void BKE_armature_loc_world_to_pose(Object *ob, const float inloc[3], float outloc[3]) { float xLocMat[4][4] = MAT4_UNITY; float nLocMat[4][4]; @@ -1126,7 +1126,7 @@ void armature_loc_world_to_pose(Object *ob, const float inloc[3], float outloc[3 copy_v3_v3(xLocMat[3], inloc); /* get bone-space cursor matrix and extract location */ - armature_mat_world_to_pose(ob, xLocMat, nLocMat); + BKE_armature_mat_world_to_pose(ob, xLocMat, nLocMat); copy_v3_v3(outloc, nLocMat[3]); } @@ -1165,7 +1165,7 @@ static void get_offset_bone_mat(Bone *bone, float offs_bone[][4]) * pose-channel into its local space (i.e. 'visual'-keyframing). * (note: I don't understand that, so I keep it :p --mont29). */ -void pchan_to_pose_mat(bPoseChannel *pchan, float rotscale_mat[][4], float loc_mat[][4]) +void BKE_pchan_to_pose_mat(bPoseChannel *pchan, float rotscale_mat[][4], float loc_mat[][4]) { Bone *bone, *parbone; bPoseChannel *parchan; @@ -1229,7 +1229,7 @@ void pchan_to_pose_mat(bPoseChannel *pchan, float rotscale_mat[][4], float loc_m mult_m4_m4m4(loc_mat, bone_loc, tmat4); } /* Those flags do not affect position, use plain parent transform space! */ - else if (bone->flag & (BONE_HINGE|BONE_NO_SCALE)) { + else if (bone->flag & (BONE_HINGE | BONE_NO_SCALE)) { mult_m4_m4m4(loc_mat, parchan->pose_mat, offs_bone); } /* Else (i.e. default, usual case), just use the same matrix for rotation/scaling, and location. */ @@ -1254,14 +1254,14 @@ void pchan_to_pose_mat(bPoseChannel *pchan, float rotscale_mat[][4], float loc_m /* Convert Pose-Space Matrix to Bone-Space Matrix. * NOTE: this cannot be used to convert to pose-space transforms of the supplied * pose-channel into its local space (i.e. 'visual'-keyframing) */ -void armature_mat_pose_to_bone(bPoseChannel *pchan, float inmat[][4], float outmat[][4]) +void BKE_armature_mat_pose_to_bone(bPoseChannel *pchan, float inmat[][4], float outmat[][4]) { float rotscale_mat[4][4], loc_mat[4][4], inmat_[4][4]; /* Security, this allows to call with inmat == outmat! */ copy_m4_m4(inmat_, inmat); - pchan_to_pose_mat(pchan, rotscale_mat, loc_mat); + BKE_pchan_to_pose_mat(pchan, rotscale_mat, loc_mat); invert_m4(rotscale_mat); invert_m4(loc_mat); @@ -1270,14 +1270,14 @@ void armature_mat_pose_to_bone(bPoseChannel *pchan, float inmat[][4], float outm } /* Convert Bone-Space Matrix to Pose-Space Matrix. */ -void armature_mat_bone_to_pose(bPoseChannel *pchan, float inmat[][4], float outmat[][4]) +void BKE_armature_mat_bone_to_pose(bPoseChannel *pchan, float inmat[][4], float outmat[][4]) { float rotscale_mat[4][4], loc_mat[4][4], inmat_[4][4]; /* Security, this allows to call with inmat == outmat! */ copy_m4_m4(inmat_, inmat); - pchan_to_pose_mat(pchan, rotscale_mat, loc_mat); + BKE_pchan_to_pose_mat(pchan, rotscale_mat, loc_mat); mult_m4_m4m4(outmat, rotscale_mat, inmat_); mul_v3_m4v3(outmat[3], loc_mat, inmat_[3]); @@ -1286,7 +1286,7 @@ void armature_mat_bone_to_pose(bPoseChannel *pchan, float inmat[][4], float outm /* Convert Pose-Space Location to Bone-Space Location * NOTE: this cannot be used to convert to pose-space location of the supplied * pose-channel into its local space (i.e. 'visual'-keyframing) */ -void armature_loc_pose_to_bone(bPoseChannel *pchan, const float inloc[3], float outloc[3]) +void BKE_armature_loc_pose_to_bone(bPoseChannel *pchan, const float inloc[3], float outloc[3]) { float xLocMat[4][4] = MAT4_UNITY; float nLocMat[4][4]; @@ -1295,29 +1295,29 @@ void armature_loc_pose_to_bone(bPoseChannel *pchan, const float inloc[3], float copy_v3_v3(xLocMat[3], inloc); /* get bone-space cursor matrix and extract location */ - armature_mat_pose_to_bone(pchan, xLocMat, nLocMat); + BKE_armature_mat_pose_to_bone(pchan, xLocMat, nLocMat); copy_v3_v3(outloc, nLocMat[3]); } -void armature_mat_pose_to_bone_ex(Object *ob, bPoseChannel *pchan, float inmat[][4], float outmat[][4]) +void BKE_armature_mat_pose_to_bone_ex(Object *ob, bPoseChannel *pchan, float inmat[][4], float outmat[][4]) { bPoseChannel work_pchan = *pchan; /* recalculate pose matrix with only parent transformations, * bone loc/sca/rot is ignored, scene and frame are not used. */ - where_is_pose_bone(NULL, ob, &work_pchan, 0.0f, FALSE); + BKE_pose_where_is_bone(NULL, ob, &work_pchan, 0.0f, FALSE); /* find the matrix, need to remove the bone transforms first so this is * calculated as a matrix to set rather then a difference ontop of whats * already there. */ unit_m4(outmat); - pchan_apply_mat4(&work_pchan, outmat, FALSE); + BKE_pchan_apply_mat4(&work_pchan, outmat, FALSE); - armature_mat_pose_to_bone(&work_pchan, inmat, outmat); + BKE_armature_mat_pose_to_bone(&work_pchan, inmat, outmat); } -/* same as object_mat3_to_rot() */ -void pchan_mat3_to_rot(bPoseChannel *pchan, float mat[][3], short use_compat) +/* same as BKE_object_mat3_to_rot() */ +void BKE_pchan_mat3_to_rot(bPoseChannel *pchan, float mat[][3], short use_compat) { switch (pchan->rotmode) { case ROT_MODE_QUAT: @@ -1335,18 +1335,18 @@ void pchan_mat3_to_rot(bPoseChannel *pchan, float mat[][3], short use_compat) } /* Apply a 4x4 matrix to the pose bone, - * similar to object_apply_mat4() */ -void pchan_apply_mat4(bPoseChannel *pchan, float mat[][4], short use_compat) + * similar to BKE_object_apply_mat4() */ +void BKE_pchan_apply_mat4(bPoseChannel *pchan, float mat[][4], short use_compat) { float rot[3][3]; mat4_to_loc_rot_size(pchan->loc, rot, pchan->size, mat); - pchan_mat3_to_rot(pchan, rot, use_compat); + BKE_pchan_mat3_to_rot(pchan, rot, use_compat); } /* Remove rest-position effects from pose-transform for obtaining * 'visual' transformation of pose-channel. * (used by the Visual-Keyframing stuff) */ -void armature_mat_pose_to_delta(float delta_mat[][4], float pose_mat[][4], float arm_mat[][4]) +void BKE_armature_mat_pose_to_delta(float delta_mat[][4], float pose_mat[][4], float arm_mat[][4]) { float imat[4][4]; @@ -1463,8 +1463,12 @@ void vec_roll_to_mat3(const float vec[3], const float roll, float mat[][3]) * * was 0.000001, causes bug [#30438] (which is same as [#27675, imho). * Reseting it to org value seems to cause no more [#23954]... + * + * was 0.0000000000001, caused bug [#31333], smaller values give unstable + * roll when toggling editmode again... + * No good value here, trying 0.000000001 as best compromize. :/ */ - if (dot_v3v3(axis, axis) > 1.0e-13f) { + if (dot_v3v3(axis, axis) > 1.0e-9f) { /* if nor is *not* a multiple of target ... */ normalize_v3(axis); @@ -1496,7 +1500,7 @@ void vec_roll_to_mat3(const float vec[3], const float roll, float mat[][3]) /* recursive part, calculates restposition of entire tree of children */ /* used by exiting editmode too */ -void where_is_armature_bone(Bone *bone, Bone *prevbone) +void BKE_armature_where_is_bone(Bone *bone, Bone *prevbone) { float vec[3]; @@ -1529,19 +1533,19 @@ void where_is_armature_bone(Bone *bone, Bone *prevbone) /* and the kiddies */ prevbone = bone; for (bone = bone->childbase.first; bone; bone = bone->next) { - where_is_armature_bone(bone, prevbone); + BKE_armature_where_is_bone(bone, prevbone); } } /* updates vectors and matrices on rest-position level, only needed * after editing armature itself, now only on reading file */ -void where_is_armature(bArmature *arm) +void BKE_armature_where_is(bArmature *arm) { Bone *bone; /* hierarchical from root to children */ for (bone = arm->bonebase.first; bone; bone = bone->next) { - where_is_armature_bone(bone, NULL); + BKE_armature_where_is_bone(bone, NULL); } } @@ -1561,7 +1565,7 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected * to avoid crashing check for possible errors here */ for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { if (pchan->bone->layer & layer_protected) { - if (get_pose_channel(frompose, pchan->name) == NULL) { + if (BKE_pose_channel_find_name(frompose, pchan->name) == NULL) { printf("failed to sync proxy armature because '%s' is missing pose channel '%s'\n", from->id.name, pchan->name); error = 1; @@ -1573,19 +1577,19 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected return; /* clear all transformation values from library */ - rest_pose(frompose); + BKE_pose_rest(frompose); /* copy over all of the proxy's bone groups */ - /* TODO for later - * - implement 'local' bone groups as for constraints - * Note: this isn't trivial, as bones reference groups by index not by pointer, - * so syncing things correctly needs careful attention */ + /* TODO for later + * - implement 'local' bone groups as for constraints + * Note: this isn't trivial, as bones reference groups by index not by pointer, + * so syncing things correctly needs careful attention */ BLI_freelistN(&pose->agroups); BLI_duplicatelist(&pose->agroups, &frompose->agroups); pose->active_group = frompose->active_group; for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { - pchanp = get_pose_channel(frompose, pchan->name); + pchanp = BKE_pose_channel_find_name(frompose, pchan->name); if (pchan->bone->layer & layer_protected) { ListBase proxylocal_constraints = {NULL, NULL}; @@ -1638,7 +1642,7 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected } /* free stuff from current channel */ - free_pose_channel(pchan); + BKE_pose_channel_free(pchan); /* the final copy */ *pchan = pchanw; @@ -1672,7 +1676,7 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected static int rebuild_pose_bone(bPose *pose, Bone *bone, bPoseChannel *parchan, int counter) { - bPoseChannel *pchan = verify_pose_channel(pose, bone->name); /* verify checks and/or adds */ + bPoseChannel *pchan = BKE_pose_channel_verify(pose, bone->name); /* verify checks and/or adds */ pchan->bone = bone; pchan->parent = parchan; @@ -1683,7 +1687,7 @@ static int rebuild_pose_bone(bPose *pose, Bone *bone, bPoseChannel *parchan, int counter = rebuild_pose_bone(pose, bone, pchan, counter); /* for quick detecting of next bone in chain, only b-bone uses it now */ if (bone->flag & BONE_CONNECTED) - pchan->child = get_pose_channel(pose, bone->name); + pchan->child = BKE_pose_channel_find_name(pose, bone->name); } return counter; @@ -1691,7 +1695,7 @@ static int rebuild_pose_bone(bPose *pose, Bone *bone, bPoseChannel *parchan, int /* only after leave editmode, duplicating, validating older files, library syncing */ /* NOTE: pose->flag is set for it */ -void armature_rebuild_pose(Object *ob, bArmature *arm) +void BKE_pose_rebuild(Object *ob, bArmature *arm) { Bone *bone; bPose *pose; @@ -1723,8 +1727,8 @@ void armature_rebuild_pose(Object *ob, bArmature *arm) for (pchan = pose->chanbase.first; pchan; pchan = next) { next = pchan->next; if (pchan->bone == NULL) { - free_pose_channel(pchan); - free_pose_channels_hash(pose); + BKE_pose_channel_free(pchan); + BKE_pose_channels_hash_free(pose); BLI_freelinkN(&pose->chanbase, pchan); } } @@ -1732,20 +1736,20 @@ void armature_rebuild_pose(Object *ob, bArmature *arm) /* synchronize protected layers with proxy */ if (ob->proxy) { - object_copy_proxy_drivers(ob, ob->proxy); + BKE_object_copy_proxy_drivers(ob, ob->proxy); pose_proxy_synchronize(ob, ob->proxy, arm->layer_protected); } - update_pose_constraint_flags(ob->pose); /* for IK detection for example */ + BKE_pose_update_constraint_flags(ob->pose); /* for IK detection for example */ /* the sorting */ - if (counter>1) + if (counter > 1) DAG_pose_sort(ob); ob->pose->flag &= ~POSE_RECALC; ob->pose->flag |= POSE_WAS_REBUILT; - make_pose_channels_hash(ob->pose); + BKE_pose_channels_hash_make(ob->pose); } @@ -1792,7 +1796,7 @@ static void splineik_init_tree_from_pchan(Scene *scene, Object *UNUSED(ob), bPos if ((ikData->tar == NULL) || (ikData->tar->type != OB_CURVE)) continue; /* skip if disabled */ - if ((con->enforce == 0.0f) || (con->flag & (CONSTRAINT_DISABLE|CONSTRAINT_OFF))) + if ((con->enforce == 0.0f) || (con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF))) continue; /* otherwise, constraint is ok... */ @@ -1814,7 +1818,7 @@ static void splineik_init_tree_from_pchan(Scene *scene, Object *UNUSED(ob), bPos /* only happens on reload file, but violates depsgraph still... fix! */ if ((cu->path == NULL) || (cu->path->data == NULL)) - makeDispListCurveTypes(scene, ikData->tar, 0); + BKE_displist_make_curveTypes(scene, ikData->tar, 0); } /* find the root bone and the chain of bones from the root to the tip @@ -1831,7 +1835,7 @@ static void splineik_init_tree_from_pchan(Scene *scene, Object *UNUSED(ob), bPos if (segcount == 0) return; else - pchanRoot = pchanChain[segcount-1]; + pchanRoot = pchanChain[segcount - 1]; /* perform binding step if required */ if ((ikData->flag & CONSTRAINT_SPLINEIK_BOUND) == 0) { @@ -1841,8 +1845,8 @@ static void splineik_init_tree_from_pchan(Scene *scene, Object *UNUSED(ob), bPos /* setup new empty array for the points list */ if (ikData->points) MEM_freeN(ikData->points); - ikData->numpoints = ikData->chainlen+1; - ikData->points = MEM_callocN(sizeof(float)*ikData->numpoints, "Spline IK Binding"); + ikData->numpoints = ikData->chainlen + 1; + ikData->points = MEM_callocN(sizeof(float) * ikData->numpoints, "Spline IK Binding"); /* bind 'tip' of chain (i.e. first joint = tip of bone with the Spline IK Constraint) */ ikData->points[0] = 1.0f; @@ -1856,13 +1860,13 @@ static void splineik_init_tree_from_pchan(Scene *scene, Object *UNUSED(ob), bPos */ if ((ikData->flag & CONSTRAINT_SPLINEIK_EVENSPLITS) || (totLength == 0.0f)) { /* 1) equi-spaced joints */ - ikData->points[i+1] = ikData->points[i] - segmentLen; + ikData->points[i + 1] = ikData->points[i] - segmentLen; } else { /* 2) to find this point on the curve, we take a step from the previous joint * a distance given by the proportion that this bone takes */ - ikData->points[i+1] = ikData->points[i] - (boneLengths[i] / totLength); + ikData->points[i + 1] = ikData->points[i] - (boneLengths[i] / totLength); } } @@ -1916,8 +1920,8 @@ static void splineik_init_tree_from_pchan(Scene *scene, Object *UNUSED(ob), bPos tree->chainlen = segcount; /* copy over the array of links to bones in the chain (from tip to root) */ - tree->chain = MEM_callocN(sizeof(bPoseChannel*)*segcount, "SplineIK Chain"); - memcpy(tree->chain, pchanChain, sizeof(bPoseChannel*)*segcount); + tree->chain = MEM_callocN(sizeof(bPoseChannel *) * segcount, "SplineIK Chain"); + memcpy(tree->chain, pchanChain, sizeof(bPoseChannel *) * segcount); /* store reference to joint position array */ tree->points = jointPoints; @@ -1956,10 +1960,10 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o { bSplineIKConstraint *ikData = tree->ikData; float poseHead[3], poseTail[3], poseMat[4][4]; - float splineVec[3], scaleFac, radius =1.0f; + float splineVec[3], scaleFac, radius = 1.0f; /* firstly, calculate the bone matrix the standard way, since this is needed for roll control */ - where_is_pose_bone(scene, ob, pchan, ctime, 1); + BKE_pose_where_is_bone(scene, ob, pchan, ctime, 1); copy_v3_v3(poseHead, pchan->pose_head); copy_v3_v3(poseTail, pchan->pose_tail); @@ -1970,14 +1974,14 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o float tailBlendFac = 1.0f; /* determine if the bone should still be affected by SplineIK */ - if (tree->points[index+1] >= 1.0f) { + if (tree->points[index + 1] >= 1.0f) { /* spline doesn't affect the bone anymore, so done... */ pchan->flag |= POSE_DONE; return; } - else if ((tree->points[index] >= 1.0f) && (tree->points[index+1] < 1.0f)) { + else if ((tree->points[index] >= 1.0f) && (tree->points[index + 1] < 1.0f)) { /* blending factor depends on the amount of the bone still left on the chain */ - tailBlendFac = (1.0f - tree->points[index+1]) / (tree->points[index] - tree->points[index+1]); + tailBlendFac = (1.0f - tree->points[index + 1]) / (tree->points[index] - tree->points[index + 1]); } /* tail endpoint */ @@ -1997,7 +2001,7 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o } /* head endpoint */ - if (where_on_path(ikData->tar, tree->points[index+1], vec, dir, NULL, &rad, NULL)) { + if (where_on_path(ikData->tar, tree->points[index + 1], vec, dir, NULL, &rad, NULL)) { /* apply curve's object-mode transforms to the position * unless the option to allow curve to be positioned elsewhere is activated (i.e. no root) */ @@ -2009,7 +2013,7 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o copy_v3_v3(poseHead, vec); /* set the new radius (it should be the average value) */ - radius = (radius+rad) / 2; + radius = (radius + rad) / 2; } } @@ -2083,7 +2087,7 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o scale = len_v3(pchan->pose_mat[2]); mul_v3_fl(poseMat[2], scale); } - break; + break; case CONSTRAINT_SPLINEIK_XZS_VOLUMETRIC: { /* 'volume preservation' */ @@ -2106,7 +2110,7 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o mul_v3_fl(poseMat[0], scale); mul_v3_fl(poseMat[2], scale); } - break; + break; } /* finally, multiply the x and z scaling by the radius of the curve too, @@ -2145,7 +2149,7 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o copy_v3_v3(pchan->pose_head, poseHead); /* recalculate tail, as it's now outdated after the head gets adjusted above! */ - where_is_pose_bone_tail(pchan); + BKE_pose_where_is_bone_tail(pchan); /* done! */ pchan->flag |= POSE_DONE; @@ -2164,7 +2168,7 @@ static void splineik_execute_tree(Scene *scene, Object *ob, bPoseChannel *pchan_ * - the chain is traversed in the opposite order to storage order (i.e. parent to children) * so that dependencies are correct */ - for (i = tree->chainlen-1; i >= 0; i--) { + for (i = tree->chainlen - 1; i >= 0; i--) { bPoseChannel *pchan = tree->chain[i]; splineik_evaluate_bone(tree, scene, ob, pchan, i, ctime); } @@ -2183,7 +2187,7 @@ static void splineik_execute_tree(Scene *scene, Object *ob, bPoseChannel *pchan_ /* ********************** THE POSE SOLVER ******************* */ /* loc/rot/size to given mat4 */ -void pchan_to_mat4(bPoseChannel *pchan, float chan_mat[4][4]) +void BKE_pchan_to_mat4(bPoseChannel *pchan, float chan_mat[4][4]) { float smat[3][3]; float rmat[3][3]; @@ -2226,12 +2230,12 @@ void pchan_to_mat4(bPoseChannel *pchan, float chan_mat[4][4]) /* loc/rot/size to mat4 */ /* used in constraint.c too */ -void pchan_calc_mat(bPoseChannel *pchan) +void BKE_pchan_calc_mat(bPoseChannel *pchan) { /* this is just a wrapper around the copy of this function which calculates the matrix * and stores the result in any given channel */ - pchan_to_mat4(pchan, pchan->chan_mat); + BKE_pchan_to_mat4(pchan, pchan->chan_mat); } #if 0 /* XXX OLD ANIMSYS, NLASTRIPS ARE NO LONGER USED */ @@ -2241,116 +2245,116 @@ static void do_strip_modifiers(Scene *scene, Object *armob, Bone *bone, bPoseCha { bActionModifier *amod; bActionStrip *strip, *strip2; - float scene_cfra= (float)scene->r.cfra; + float scene_cfra = (float)scene->r.cfra; int do_modif; - for (strip=armob->nlastrips.first; strip; strip=strip->next) { - do_modif=0; + for (strip = armob->nlastrips.first; strip; strip = strip->next) { + do_modif = 0; - if (scene_cfra>=strip->start && scene_cfra<=strip->end) - do_modif=1; + if (scene_cfra >= strip->start && scene_cfra <= strip->end) + do_modif = 1; if ((scene_cfra > strip->end) && (strip->flag & ACTSTRIP_HOLDLASTFRAME)) { - do_modif=1; + do_modif = 1; /* if there are any other strips active, ignore modifiers for this strip - * 'hold' option should only hold action modifiers if there are * no other active strips */ - for (strip2=strip->next; strip2; strip2=strip2->next) { + for (strip2 = strip->next; strip2; strip2 = strip2->next) { if (strip2 == strip) continue; - if (scene_cfra>=strip2->start && scene_cfra<=strip2->end) { + if (scene_cfra >= strip2->start && scene_cfra <= strip2->end) { if (!(strip2->flag & ACTSTRIP_MUTE)) - do_modif=0; + do_modif = 0; } } /* if there are any later, activated, strips with 'hold' set, they take precedence, * so ignore modifiers for this strip */ - for (strip2=strip->next; strip2; strip2=strip2->next) { + for (strip2 = strip->next; strip2; strip2 = strip2->next) { if (scene_cfra < strip2->start) continue; if ((strip2->flag & ACTSTRIP_HOLDLASTFRAME) && !(strip2->flag & ACTSTRIP_MUTE)) { - do_modif=0; + do_modif = 0; } } } if (do_modif) { /* temporal solution to prevent 2 strips accumulating */ - if (scene_cfra==strip->end && strip->next && strip->next->start==scene_cfra) + if (scene_cfra == strip->end && strip->next && strip->next->start == scene_cfra) continue; - for (amod= strip->modifiers.first; amod; amod= amod->next) { + for (amod = strip->modifiers.first; amod; amod = amod->next) { switch (amod->type) { - case ACTSTRIP_MOD_DEFORM: - { - /* validate first */ - if (amod->ob && amod->ob->type==OB_CURVE && amod->channel[0]) { + case ACTSTRIP_MOD_DEFORM: + { + /* validate first */ + if (amod->ob && amod->ob->type == OB_CURVE && amod->channel[0]) { - if ( strcmp(pchan->name, amod->channel)==0 ) { - float mat4[4][4], mat3[3][3]; + if (strcmp(pchan->name, amod->channel) == 0) { + float mat4[4][4], mat3[3][3]; - curve_deform_vector(scene, amod->ob, armob, bone->arm_mat[3], pchan->pose_mat[3], mat3, amod->no_rot_axis); - copy_m4_m4(mat4, pchan->pose_mat); - mul_m4_m3m4(pchan->pose_mat, mat3, mat4); + curve_deform_vector(scene, amod->ob, armob, bone->arm_mat[3], pchan->pose_mat[3], mat3, amod->no_rot_axis); + copy_m4_m4(mat4, pchan->pose_mat); + mul_m4_m3m4(pchan->pose_mat, mat3, mat4); + } } } - } break; - case ACTSTRIP_MOD_NOISE: - { - if ( strcmp(pchan->name, amod->channel)==0 ) { - float nor[3], loc[3], ofs; - float eul[3], size[3], eulo[3], sizeo[3]; - - /* calculate turbulance */ - ofs = amod->turbul / 200.0f; - - /* make a copy of starting conditions */ - copy_v3_v3(loc, pchan->pose_mat[3]); - mat4_to_eul(eul, pchan->pose_mat); - mat4_to_size(size, pchan->pose_mat); - copy_v3_v3(eulo, eul); - copy_v3_v3(sizeo, size); - - /* apply noise to each set of channels */ - if (amod->channels & 4) { - /* for scaling */ - nor[0] = BLI_gNoise(amod->noisesize, size[0]+ofs, size[1], size[2], 0, 0) - ofs; - nor[1] = BLI_gNoise(amod->noisesize, size[0], size[1]+ofs, size[2], 0, 0) - ofs; - nor[2] = BLI_gNoise(amod->noisesize, size[0], size[1], size[2]+ofs, 0, 0) - ofs; - add_v3_v3(size, nor); - - if (sizeo[0] != 0) - mul_v3_fl(pchan->pose_mat[0], size[0] / sizeo[0]); - if (sizeo[1] != 0) - mul_v3_fl(pchan->pose_mat[1], size[1] / sizeo[1]); - if (sizeo[2] != 0) - mul_v3_fl(pchan->pose_mat[2], size[2] / sizeo[2]); - } - if (amod->channels & 2) { - /* for rotation */ - nor[0] = BLI_gNoise(amod->noisesize, eul[0]+ofs, eul[1], eul[2], 0, 0) - ofs; - nor[1] = BLI_gNoise(amod->noisesize, eul[0], eul[1]+ofs, eul[2], 0, 0) - ofs; - nor[2] = BLI_gNoise(amod->noisesize, eul[0], eul[1], eul[2]+ofs, 0, 0) - ofs; - - compatible_eul(nor, eulo); - add_v3_v3(eul, nor); - compatible_eul(eul, eulo); - - loc_eul_size_to_mat4(pchan->pose_mat, loc, eul, size); - } - if (amod->channels & 1) { - /* for location */ - nor[0] = BLI_gNoise(amod->noisesize, loc[0]+ofs, loc[1], loc[2], 0, 0) - ofs; - nor[1] = BLI_gNoise(amod->noisesize, loc[0], loc[1]+ofs, loc[2], 0, 0) - ofs; - nor[2] = BLI_gNoise(amod->noisesize, loc[0], loc[1], loc[2]+ofs, 0, 0) - ofs; - - add_v3_v3v3(pchan->pose_mat[3], loc, nor); + case ACTSTRIP_MOD_NOISE: + { + if (strcmp(pchan->name, amod->channel) == 0) { + float nor[3], loc[3], ofs; + float eul[3], size[3], eulo[3], sizeo[3]; + + /* calculate turbulance */ + ofs = amod->turbul / 200.0f; + + /* make a copy of starting conditions */ + copy_v3_v3(loc, pchan->pose_mat[3]); + mat4_to_eul(eul, pchan->pose_mat); + mat4_to_size(size, pchan->pose_mat); + copy_v3_v3(eulo, eul); + copy_v3_v3(sizeo, size); + + /* apply noise to each set of channels */ + if (amod->channels & 4) { + /* for scaling */ + nor[0] = BLI_gNoise(amod->noisesize, size[0] + ofs, size[1], size[2], 0, 0) - ofs; + nor[1] = BLI_gNoise(amod->noisesize, size[0], size[1] + ofs, size[2], 0, 0) - ofs; + nor[2] = BLI_gNoise(amod->noisesize, size[0], size[1], size[2] + ofs, 0, 0) - ofs; + add_v3_v3(size, nor); + + if (sizeo[0] != 0) + mul_v3_fl(pchan->pose_mat[0], size[0] / sizeo[0]); + if (sizeo[1] != 0) + mul_v3_fl(pchan->pose_mat[1], size[1] / sizeo[1]); + if (sizeo[2] != 0) + mul_v3_fl(pchan->pose_mat[2], size[2] / sizeo[2]); + } + if (amod->channels & 2) { + /* for rotation */ + nor[0] = BLI_gNoise(amod->noisesize, eul[0] + ofs, eul[1], eul[2], 0, 0) - ofs; + nor[1] = BLI_gNoise(amod->noisesize, eul[0], eul[1] + ofs, eul[2], 0, 0) - ofs; + nor[2] = BLI_gNoise(amod->noisesize, eul[0], eul[1], eul[2] + ofs, 0, 0) - ofs; + + compatible_eul(nor, eulo); + add_v3_v3(eul, nor); + compatible_eul(eul, eulo); + + loc_eul_size_to_mat4(pchan->pose_mat, loc, eul, size); + } + if (amod->channels & 1) { + /* for location */ + nor[0] = BLI_gNoise(amod->noisesize, loc[0] + ofs, loc[1], loc[2], 0, 0) - ofs; + nor[1] = BLI_gNoise(amod->noisesize, loc[0], loc[1] + ofs, loc[2], 0, 0) - ofs; + nor[2] = BLI_gNoise(amod->noisesize, loc[0], loc[1], loc[2] + ofs, 0, 0) - ofs; + + add_v3_v3v3(pchan->pose_mat[3], loc, nor); + } } } - } break; } } @@ -2361,7 +2365,7 @@ static void do_strip_modifiers(Scene *scene, Object *armob, Bone *bone, bPoseCha #endif /* calculate tail of posechannel */ -void where_is_pose_bone_tail(bPoseChannel *pchan) +void BKE_pose_where_is_bone_tail(bPoseChannel *pchan) { float vec[3]; @@ -2374,17 +2378,17 @@ void where_is_pose_bone_tail(bPoseChannel *pchan) /* pchan is validated, as having bone and parent pointer * 'do_extra': when zero skips loc/size/rot, constraints and strip modifiers. */ -void where_is_pose_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float ctime, int do_extra) +void BKE_pose_where_is_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float ctime, int do_extra) { /* This gives a chan_mat with actions (ipos) results. */ if (do_extra) - pchan_calc_mat(pchan); + BKE_pchan_calc_mat(pchan); else unit_m4(pchan->chan_mat); /* Construct the posemat based on PoseChannels, that we do before applying constraints. */ /* pose_mat(b) = pose_mat(b-1) * yoffs(b-1) * d_root(b) * bone_mat(b) * chan_mat(b) */ - armature_mat_bone_to_pose(pchan, pchan->chan_mat, pchan->pose_mat); + BKE_armature_mat_bone_to_pose(pchan, pchan->chan_mat, pchan->pose_mat); /* Only rootbones get the cyclic offset (unless user doesn't want that). */ /* XXX That could be a problem for snapping and other "reverse transform" features... */ @@ -2394,7 +2398,7 @@ void where_is_pose_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float cti } if (do_extra) { -#if 0 /* XXX OLD ANIMSYS, NLASTRIPS ARE NO LONGER USED */ +#if 0 /* XXX OLD ANIMSYS, NLASTRIPS ARE NO LONGER USED */ /* do NLA strip modifiers - i.e. curve follow */ do_strip_modifiers(scene, ob, bone, pchan); #endif @@ -2413,7 +2417,7 @@ void where_is_pose_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float cti cob = constraints_make_evalob(scene, ob, pchan, CONSTRAINT_OBTYPE_BONE); /* Solve PoseChannel's Constraints */ - solve_constraints(&pchan->constraints, cob, ctime); /* ctime doesnt alter objects */ + solve_constraints(&pchan->constraints, cob, ctime); /* ctime doesnt alter objects */ /* cleanup after Constraint Solving * - applies matrix back to pchan, and frees temporary struct used @@ -2430,12 +2434,12 @@ void where_is_pose_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float cti /* calculate head */ copy_v3_v3(pchan->pose_head, pchan->pose_mat[3]); /* calculate tail */ - where_is_pose_bone_tail(pchan); + BKE_pose_where_is_bone_tail(pchan); } /* This only reads anim data from channels, and writes to channels */ /* This is the only function adding poses */ -void where_is_pose(Scene *scene, Object *ob) +void BKE_pose_where_is(Scene *scene, Object *ob) { bArmature *arm; Bone *bone; @@ -2450,9 +2454,9 @@ void where_is_pose(Scene *scene, Object *ob) if (ELEM(NULL, arm, scene)) return; if ((ob->pose == NULL) || (ob->pose->flag & POSE_RECALC)) - armature_rebuild_pose(ob, arm); + BKE_pose_rebuild(ob, arm); - ctime = BKE_curframe(scene); /* not accurate... */ + ctime = BKE_scene_frame_get(scene); /* not accurate... */ /* In editmode or restposition we read the data from the bones */ if (arm->edbo || (arm->flag & ARM_RESTPOS)) { @@ -2470,7 +2474,7 @@ void where_is_pose(Scene *scene, Object *ob) /* 1. clear flags */ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { - pchan->flag &= ~(POSE_DONE|POSE_CHAIN|POSE_IKTREE|POSE_IKSPLINE); + pchan->flag &= ~(POSE_DONE | POSE_CHAIN | POSE_IKTREE | POSE_IKSPLINE); } /* 2a. construct the IK tree (standard IK) */ @@ -2494,7 +2498,7 @@ void where_is_pose(Scene *scene, Object *ob) } /* 5. otherwise just call the normal solver */ else if (!(pchan->flag & POSE_DONE)) { - where_is_pose_bone(scene, ob, pchan, ctime, 1); + BKE_pose_where_is_bone(scene, ob, pchan, ctime, 1); } } /* 6. release the IK tree */ @@ -2517,13 +2521,13 @@ int get_selected_defgroups(Object *ob, char *dg_selection, int defbase_tot) { bDeformGroup *defgroup; unsigned int i; - Object *armob = object_pose_armature_get(ob); + Object *armob = BKE_object_pose_armature_get(ob); int dg_flags_sel_tot = 0; if (armob) { bPose *pose = armob->pose; for (i = 0, defgroup = ob->defbase.first; i < defbase_tot && defgroup; defgroup = defgroup->next, i++) { - bPoseChannel *pchan = get_pose_channel(pose, defgroup->name); + bPoseChannel *pchan = BKE_pose_channel_find_name(pose, defgroup->name); if (pchan && (pchan->bone->flag & BONE_SELECTED)) { dg_selection[i] = TRUE; dg_flags_sel_tot++; @@ -2545,7 +2549,7 @@ int minmax_armature(Object *ob, float min[3], float max[3]) { bPoseChannel *pchan; - /* For now, we assume where_is_pose has already been called (hence we have valid data in pachan). */ + /* For now, we assume BKE_pose_where_is has already been called (hence we have valid data in pachan). */ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { DO_MINMAX(pchan->pose_head, min, max); DO_MINMAX(pchan->pose_tail, min, max); @@ -2581,10 +2585,10 @@ void boundbox_armature(Object *ob, float *loc, float *size) size[1] = (max[1] - min[1]) / 2.0f; size[2] = (max[2] - min[2]) / 2.0f; - boundbox_set_from_min_max(bb, min, max); + BKE_boundbox_init_from_minmax(bb, min, max); } -BoundBox *BKE_armature_get_bb(Object *ob) +BoundBox *BKE_armature_boundbox_get(Object *ob) { boundbox_armature(ob, NULL, NULL); diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index b0bfd2ee98d..b2cbf0a1ce1 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -91,11 +91,15 @@ #include "WM_api.h" // XXXXX BAD, very BAD dependency (bad level call) - remove asap, elubie +#ifdef WITH_PYTHON +#include "BPY_extern.h" +#endif + Global G; UserDef U; /* ListBase = {NULL, NULL}; */ -char versionstr[48]= ""; +char versionstr[48] = ""; /* ********** free ********** */ @@ -104,9 +108,9 @@ void free_blender(void) { /* samples are in a global list..., also sets G.main->sound->sample NULL */ free_main(G.main); - G.main= NULL; + G.main = NULL; - BKE_spacetypes_free(); /* after free main, it uses space callbacks */ + BKE_spacetypes_free(); /* after free main, it uses space callbacks */ IMB_exit(); @@ -122,18 +126,18 @@ void initglobals(void) { memset(&G, 0, sizeof(Global)); - U.savetime= 1; + U.savetime = 1; - G.main= MEM_callocN(sizeof(Main), "initglobals"); + G.main = MEM_callocN(sizeof(Main), "initglobals"); strcpy(G.ima, "//"); if (BLENDER_SUBVERSION) - BLI_snprintf(versionstr, sizeof(versionstr), "v%d.%02d.%d", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION); + BLI_snprintf(versionstr, sizeof(versionstr), "v%d.%02d.%d", BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION); else - BLI_snprintf(versionstr, sizeof(versionstr), "v%d.%02d", BLENDER_VERSION/100, BLENDER_VERSION%100); + BLI_snprintf(versionstr, sizeof(versionstr), "v%d.%02d", BLENDER_VERSION / 100, BLENDER_VERSION % 100); -#ifdef _WIN32 // FULLSCREEN +#ifdef _WIN32 // FULLSCREEN G.windowstate = G_WINDOWSTATE_USERDEF; #endif @@ -154,11 +158,11 @@ static void clear_global(void) { // extern short winqueue_break; /* screen.c */ - free_main(G.main); /* free all lib data */ + free_main(G.main); /* free all lib data */ // free_vertexpaint(); - G.main= NULL; + G.main = NULL; } static int clean_paths_visit_cb(void *UNUSED(userdata), char *path_dst, const char *path_src) @@ -175,7 +179,7 @@ static void clean_paths(Main *main) BLI_bpath_traverse_main(main, clean_paths_visit_cb, BLI_BPATH_TRAVERSE_SKIP_MULTIFILE, NULL); - for (scene= main->scene.first; scene; scene= scene->id.next) { + for (scene = main->scene.first; scene; scene = scene->id.next) { BLI_clean(scene->r.pic); } } @@ -188,17 +192,17 @@ static void clean_paths(Main *main) static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath) { - bScreen *curscreen= NULL; - Scene *curscene= NULL; + bScreen *curscreen = NULL; + Scene *curscene = NULL; int recover; char mode; /* 'u' = undo save, 'n' = no UI load */ - if (bfd->main->screen.first==NULL) mode= 'u'; - else if (G.fileflags & G_FILE_NO_UI) mode= 'n'; - else mode= 0; + if (bfd->main->screen.first == NULL) mode = 'u'; + else if (G.fileflags & G_FILE_NO_UI) mode = 'n'; + else mode = 0; - recover= (G.fileflags & G_FILE_RECOVER); + recover = (G.fileflags & G_FILE_RECOVER); /* Free all render results, without this stale data gets displayed after loading files */ if (mode != 'u') { @@ -222,12 +226,12 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath SWAP(ListBase, G.main->script, bfd->main->script); /* we re-use current screen */ - curscreen= CTX_wm_screen(C); + curscreen = CTX_wm_screen(C); /* but use new Scene pointer */ - curscene= bfd->curscene; - if (curscene==NULL) curscene= bfd->main->scene.first; + curscene = bfd->curscene; + if (curscene == NULL) curscene = bfd->main->scene.first; /* and we enforce curscene to be in current screen */ - if (curscreen) curscreen->scene= curscene; /* can run in bgmode */ + if (curscreen) curscreen->scene = curscene; /* can run in bgmode */ /* clear_global will free G.main, here we can still restore pointers */ lib_link_screen_restore(bfd->main, curscreen, curscene); @@ -240,7 +244,7 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath /* clear old property update cache, in case some old references are left dangling */ RNA_property_update_cache_free(); - G.main= bfd->main; + G.main = bfd->main; CTX_data_main_set(C, G.main); @@ -251,7 +255,7 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath /* only here free userdef themes... */ BKE_userdef_free(); - U= *bfd->user; + U = *bfd->user; MEM_freeN(bfd->user); } @@ -261,9 +265,9 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath CTX_data_scene_set(C, curscene); } else { - G.winpos= bfd->winpos; - G.displaymode= bfd->displaymode; - G.fileflags= bfd->fileflags; + G.winpos = bfd->winpos; + G.displaymode = bfd->displaymode; + G.fileflags = bfd->fileflags; CTX_wm_manager_set(C, bfd->main->wm.first); CTX_wm_screen_set(C, bfd->curscreen); CTX_data_scene_set(C, bfd->curscreen->scene); @@ -273,20 +277,25 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath } /* this can happen when active scene was lib-linked, and doesn't exist anymore */ - if (CTX_data_scene(C)==NULL) { + if (CTX_data_scene(C) == NULL) { CTX_data_scene_set(C, bfd->main->scene.first); - CTX_wm_screen(C)->scene= CTX_data_scene(C); - curscene= CTX_data_scene(C); + CTX_wm_screen(C)->scene = CTX_data_scene(C); + curscene = CTX_data_scene(C); } /* special cases, override loaded flags: */ if (G.f != bfd->globalf) { const int flags_keep = (G_SWAP_EXCHANGE | G_SCRIPT_AUTOEXEC | G_SCRIPT_OVERRIDE_PREF); - bfd->globalf= (bfd->globalf & ~flags_keep) | (G.f & flags_keep); + bfd->globalf = (bfd->globalf & ~flags_keep) | (G.f & flags_keep); } - G.f= bfd->globalf; + G.f = bfd->globalf; + +#ifdef WITH_PYTHON + /* let python know about new main */ + BPY_context_update(C); +#endif if (!G.background) { //setscreen(G.curscreen); @@ -300,12 +309,12 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath if (recover && bfd->filename[0] && G.relbase_valid) { /* in case of autosave or quit.blend, use original filename instead * use relbase_valid to make sure the file is saved, else we get <memory2> in the filename */ - filepath= bfd->filename; + filepath = bfd->filename; } #if 0 else if (!G.relbase_valid) { /* otherwise, use an empty string as filename, rather than <memory2> */ - filepath=""; + filepath = ""; } #endif @@ -314,7 +323,7 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath BLI_strncpy(G.main->name, filepath, FILE_MAX); /* baseflags, groups, make depsgraph, etc */ - set_scene_bg(G.main, CTX_data_scene(C)); + BKE_scene_set_background(G.main, CTX_data_scene(C)); MEM_freeN(bfd); @@ -324,8 +333,8 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath static int handle_subversion_warning(Main *main, ReportList *reports) { if (main->minversionfile > BLENDER_VERSION || - (main->minversionfile == BLENDER_VERSION && - main->minsubversionfile > BLENDER_SUBVERSION)) { + (main->minversionfile == BLENDER_VERSION && + main->minsubversionfile > BLENDER_SUBVERSION)) { BKE_reportf(reports, RPT_ERROR, "File written by newer Blender binary: %d.%d , expect loss of data!", main->minversionfile, main->minsubversionfile); } @@ -348,8 +357,8 @@ void BKE_userdef_free(void) wmKeyMapItem *kmi; wmKeyMapDiffItem *kmdi; - for (km=U.user_keymaps.first; km; km=km->next) { - for (kmdi=km->diff_items.first; kmdi; kmdi=kmdi->next) { + for (km = U.user_keymaps.first; km; km = km->next) { + for (kmdi = km->diff_items.first; kmdi; kmdi = kmdi->next) { if (kmdi->add_item) { keymap_item_free(kmdi->add_item); MEM_freeN(kmdi->add_item); @@ -360,7 +369,7 @@ void BKE_userdef_free(void) } } - for (kmi=km->items.first; kmi; kmi=kmi->next) + for (kmi = km->items.first; kmi; kmi = kmi->next) keymap_item_free(kmi); BLI_freelistN(&km->diff_items); @@ -377,41 +386,41 @@ void BKE_userdef_free(void) int BKE_read_file(bContext *C, const char *filepath, ReportList *reports) { BlendFileData *bfd; - int retval= BKE_READ_FILE_OK; + int retval = BKE_READ_FILE_OK; - if (strstr(filepath, BLENDER_STARTUP_FILE)==NULL) /* don't print user-pref loading */ + if (strstr(filepath, BLENDER_STARTUP_FILE) == NULL) /* don't print user-pref loading */ printf("read blend: %s\n", filepath); - bfd= BLO_read_from_file(filepath, reports); + bfd = BLO_read_from_file(filepath, reports); if (bfd) { - if (bfd->user) retval= BKE_READ_FILE_OK_USERPREFS; + if (bfd->user) retval = BKE_READ_FILE_OK_USERPREFS; - if (0==handle_subversion_warning(bfd->main, reports)) { + if (0 == handle_subversion_warning(bfd->main, reports)) { free_main(bfd->main); MEM_freeN(bfd); - bfd= NULL; - retval= BKE_READ_FILE_FAIL; + bfd = NULL; + retval = BKE_READ_FILE_FAIL; } else - setup_app_data(C, bfd, filepath); // frees BFD + setup_app_data(C, bfd, filepath); // frees BFD } else BKE_reports_prependf(reports, "Loading %s failed: ", filepath); - return (bfd?retval:BKE_READ_FILE_FAIL); + return (bfd ? retval : BKE_READ_FILE_FAIL); } -int BKE_read_file_from_memory(bContext *C, char* filebuf, int filelength, ReportList *reports) +int BKE_read_file_from_memory(bContext *C, char *filebuf, int filelength, ReportList *reports) { BlendFileData *bfd; - bfd= BLO_read_from_memory(filebuf, filelength, reports); + bfd = BLO_read_from_memory(filebuf, filelength, reports); if (bfd) setup_app_data(C, bfd, "<memory2>"); else BKE_reports_prepend(reports, "Loading failed: "); - return (bfd?1:0); + return (bfd ? 1 : 0); } /* memfile is the undo buffer */ @@ -419,13 +428,13 @@ int BKE_read_file_from_memfile(bContext *C, MemFile *memfile, ReportList *report { BlendFileData *bfd; - bfd= BLO_read_from_memfile(CTX_data_main(C), G.main->name, memfile, reports); + bfd = BLO_read_from_memfile(CTX_data_main(C), G.main->name, memfile, reports); if (bfd) setup_app_data(C, bfd, "<memory1>"); else BKE_reports_prepend(reports, "Loading failed: "); - return (bfd?1:0); + return (bfd ? 1 : 0); } @@ -435,7 +444,7 @@ static void (*blender_test_break_cb)(void) = NULL; void set_blender_test_break_cb(void (*func)(void) ) { - blender_test_break_cb= func; + blender_test_break_cb = func; } @@ -446,15 +455,15 @@ int blender_test_break(void) blender_test_break_cb(); } - return (G.afbreek==1); + return (G.afbreek == 1); } /* ***************** GLOBAL UNDO *************** */ -#define UNDO_DISK 0 +#define UNDO_DISK 0 -#define MAXUNDONAME 64 +#define MAXUNDONAME 64 typedef struct UndoElem { struct UndoElem *next, *prev; char str[FILE_MAX]; @@ -463,31 +472,31 @@ typedef struct UndoElem { uintptr_t undosize; } UndoElem; -static ListBase undobase={NULL, NULL}; -static UndoElem *curundo= NULL; +static ListBase undobase = {NULL, NULL}; +static UndoElem *curundo = NULL; static int read_undosave(bContext *C, UndoElem *uel) { char mainstr[sizeof(G.main->name)]; - int success=0, fileflags; + int success = 0, fileflags; /* This is needed so undoing/redoing doesn't crash with threaded previews going */ WM_jobs_stop_all(CTX_wm_manager(C)); - BLI_strncpy(mainstr, G.main->name, sizeof(mainstr)); /* temporal store */ + BLI_strncpy(mainstr, G.main->name, sizeof(mainstr)); /* temporal store */ - fileflags= G.fileflags; + fileflags = G.fileflags; G.fileflags |= G_FILE_NO_UI; if (UNDO_DISK) - success= (BKE_read_file(C, uel->str, NULL) != BKE_READ_FILE_FAIL); + success = (BKE_read_file(C, uel->str, NULL) != BKE_READ_FILE_FAIL); else - success= BKE_read_file_from_memfile(C, &uel->memfile, NULL); + success = BKE_read_file_from_memfile(C, &uel->memfile, NULL); /* restore */ BLI_strncpy(G.main->name, mainstr, sizeof(G.main->name)); /* restore */ - G.fileflags= fileflags; + G.fileflags = fileflags; if (success) { /* important not to update time here, else non keyed tranforms are lost */ @@ -504,33 +513,33 @@ void BKE_write_undo(bContext *C, const char *name) int nr /*, success */ /* UNUSED */; UndoElem *uel; - if ( (U.uiflag & USER_GLOBALUNDO)==0) return; - if ( U.undosteps==0) return; + if ( (U.uiflag & USER_GLOBALUNDO) == 0) return; + if (U.undosteps == 0) return; /* remove all undos after (also when curundo==NULL) */ while (undobase.last != curundo) { - uel= undobase.last; + uel = undobase.last; BLI_remlink(&undobase, uel); BLO_free_memfile(&uel->memfile); MEM_freeN(uel); } /* make new */ - curundo= uel= MEM_callocN(sizeof(UndoElem), "undo file"); + curundo = uel = MEM_callocN(sizeof(UndoElem), "undo file"); BLI_strncpy(uel->name, name, sizeof(uel->name)); BLI_addtail(&undobase, uel); /* and limit amount to the maximum */ - nr= 0; - uel= undobase.last; + nr = 0; + uel = undobase.last; while (uel) { nr++; - if (nr==U.undosteps) break; - uel= uel->prev; + if (nr == U.undosteps) break; + uel = uel->prev; } if (uel) { - while (undobase.first!=uel) { - UndoElem *first= undobase.first; + while (undobase.first != uel) { + UndoElem *first = undobase.first; BLI_remlink(&undobase, first); /* the merge is because of compression */ BLO_merge_memfile(&first->memfile, &first->next->memfile); @@ -541,14 +550,14 @@ void BKE_write_undo(bContext *C, const char *name) /* disk save version */ if (UNDO_DISK) { - static int counter= 0; + static int counter = 0; char filepath[FILE_MAX]; char numstr[32]; int fileflags = G.fileflags & ~(G_FILE_HISTORY); /* don't do file history on undo */ /* calculate current filepath */ counter++; - counter= counter % U.undosteps; + counter = counter % U.undosteps; BLI_snprintf(numstr, sizeof(numstr), "%d.blend", counter); BLI_make_file_string("/", filepath, BLI_temporary_dir(), numstr); @@ -558,34 +567,34 @@ void BKE_write_undo(bContext *C, const char *name) BLI_strncpy(curundo->str, filepath, sizeof(curundo->str)); } else { - MemFile *prevfile=NULL; + MemFile *prevfile = NULL; - if (curundo->prev) prevfile= &(curundo->prev->memfile); + if (curundo->prev) prevfile = &(curundo->prev->memfile); - memused= MEM_get_memory_in_use(); + memused = MEM_get_memory_in_use(); /* success= */ /* UNUSED */ BLO_write_file_mem(CTX_data_main(C), prevfile, &curundo->memfile, G.fileflags); - curundo->undosize= MEM_get_memory_in_use() - memused; + curundo->undosize = MEM_get_memory_in_use() - memused; } if (U.undomemory != 0) { /* limit to maximum memory (afterwards, we can't know in advance) */ - totmem= 0; - maxmem= ((uintptr_t)U.undomemory)*1024*1024; + totmem = 0; + maxmem = ((uintptr_t)U.undomemory) * 1024 * 1024; /* keep at least two (original + other) */ - uel= undobase.last; + uel = undobase.last; while (uel && uel->prev) { - totmem+= uel->undosize; - if (totmem>maxmem) break; - uel= uel->prev; + totmem += uel->undosize; + if (totmem > maxmem) break; + uel = uel->prev; } if (uel) { if (uel->prev && uel->prev->prev) - uel= uel->prev; + uel = uel->prev; - while (undobase.first!=uel) { - UndoElem *first= undobase.first; + while (undobase.first != uel) { + UndoElem *first = undobase.first; BLI_remlink(&undobase, first); /* the merge is because of compression */ BLO_merge_memfile(&first->memfile, &first->next->memfile); @@ -599,25 +608,25 @@ void BKE_write_undo(bContext *C, const char *name) void BKE_undo_step(bContext *C, int step) { - if (step==0) { + if (step == 0) { read_undosave(C, curundo); } - else if (step==1) { + else if (step == 1) { /* curundo should never be NULL, after restart or load file it should call undo_save */ - if (curundo==NULL || curundo->prev==NULL) ; // XXX error("No undo available"); + if (curundo == NULL || curundo->prev == NULL) ; // XXX error("No undo available"); else { if (G.debug & G_DEBUG) printf("undo %s\n", curundo->name); - curundo= curundo->prev; + curundo = curundo->prev; read_undosave(C, curundo); } } else { /* curundo has to remain current situation! */ - if (curundo==NULL || curundo->next==NULL) ; // XXX error("No redo available"); + if (curundo == NULL || curundo->next == NULL) ; // XXX error("No redo available"); else { read_undosave(C, curundo->next); - curundo= curundo->next; + curundo = curundo->next; if (G.debug & G_DEBUG) printf("redo %s\n", curundo->name); } } @@ -627,30 +636,30 @@ void BKE_reset_undo(void) { UndoElem *uel; - uel= undobase.first; + uel = undobase.first; while (uel) { BLO_free_memfile(&uel->memfile); - uel= uel->next; + uel = uel->next; } BLI_freelistN(&undobase); - curundo= NULL; + curundo = NULL; } /* based on index nr it does a restore */ void BKE_undo_number(bContext *C, int nr) { - curundo= BLI_findlink(&undobase, nr); + curundo = BLI_findlink(&undobase, nr); BKE_undo_step(C, 0); } /* go back to the last occurance of name in stack */ void BKE_undo_name(bContext *C, const char *name) { - UndoElem *uel= BLI_rfindstring(&undobase, name, offsetof(UndoElem, name)); + UndoElem *uel = BLI_rfindstring(&undobase, name, offsetof(UndoElem, name)); if (uel && uel->prev) { - curundo= uel->prev; + curundo = uel->prev; BKE_undo_step(C, 0); } } @@ -659,7 +668,7 @@ void BKE_undo_name(bContext *C, const char *name) int BKE_undo_valid(const char *name) { if (name) { - UndoElem *uel= BLI_rfindstring(&undobase, name, offsetof(UndoElem, name)); + UndoElem *uel = BLI_rfindstring(&undobase, name, offsetof(UndoElem, name)); return uel && uel->prev; } @@ -670,13 +679,13 @@ int BKE_undo_valid(const char *name) /* if active pointer, set it to 1 if true */ const char *BKE_undo_get_name(int nr, int *active) { - UndoElem *uel= BLI_findlink(&undobase, nr); + UndoElem *uel = BLI_findlink(&undobase, nr); - if (active) *active= 0; + if (active) *active = 0; if (uel) { - if (active && uel==curundo) - *active= 1; + if (active && uel == curundo) + *active = 1; return uel->name; } return NULL; @@ -685,23 +694,23 @@ const char *BKE_undo_get_name(int nr, int *active) char *BKE_undo_menu_string(void) { UndoElem *uel; - DynStr *ds= BLI_dynstr_new(); + DynStr *ds = BLI_dynstr_new(); char *menu; BLI_dynstr_append(ds, "Global Undo History %t"); - for (uel= undobase.first; uel; uel= uel->next) { + for (uel = undobase.first; uel; uel = uel->next) { BLI_dynstr_append(ds, "|"); BLI_dynstr_append(ds, uel->name); } - menu= BLI_dynstr_get_cstring(ds); + menu = BLI_dynstr_get_cstring(ds); BLI_dynstr_free(ds); return menu; } - /* saves quit.blend */ +/* saves quit.blend */ void BKE_undo_save_quit(void) { UndoElem *uel; @@ -709,16 +718,16 @@ void BKE_undo_save_quit(void) int file; char str[FILE_MAX]; - if ( (U.uiflag & USER_GLOBALUNDO)==0) return; + if ( (U.uiflag & USER_GLOBALUNDO) == 0) return; - uel= curundo; - if (uel==NULL) { + uel = curundo; + if (uel == NULL) { printf("No undo buffer to save recovery file\n"); return; } /* no undo state to save */ - if (undobase.first==undobase.last) return; + if (undobase.first == undobase.last) return; BLI_make_file_string("/", str, BLI_temporary_dir(), "quit.blend"); @@ -728,28 +737,28 @@ void BKE_undo_save_quit(void) return; } - chunk= uel->memfile.chunks.first; + chunk = uel->memfile.chunks.first; while (chunk) { - if ( write(file, chunk->buf, chunk->size) != chunk->size) break; - chunk= chunk->next; + if (write(file, chunk->buf, chunk->size) != chunk->size) break; + chunk = chunk->next; } close(file); - if (chunk) ; //XXX error("Unable to save %s, internal error", str); + if (chunk) ; //XXX error("Unable to save %s, internal error", str); else printf("Saved session recovery to %s\n", str); } /* sets curscene */ Main *BKE_undo_get_main(Scene **scene) { - Main *mainp= NULL; - BlendFileData *bfd= BLO_read_from_memfile(G.main, G.main->name, &curundo->memfile, NULL); + Main *mainp = NULL; + BlendFileData *bfd = BLO_read_from_memfile(G.main, G.main->name, &curundo->memfile, NULL); if (bfd) { - mainp= bfd->main; + mainp = bfd->main; if (scene) - *scene= bfd->curscene; + *scene = bfd->curscene; MEM_freeN(bfd); } diff --git a/source/blender/blenkernel/intern/booleanops_mesh.c b/source/blender/blenkernel/intern/booleanops_mesh.c index 7c225eb0fad..972793227a8 100644 --- a/source/blender/blenkernel/intern/booleanops_mesh.c +++ b/source/blender/blenkernel/intern/booleanops_mesh.c @@ -78,7 +78,7 @@ MakeCSGMeshFromBlenderBase( Mesh *me; if (output == NULL || base == NULL) return 0; - me = get_mesh(base->object); + me = BKE_mesh_from_object(base->object); output->m_descriptor.user_face_vertex_data_size = 0; output->m_descriptor.user_data_size = sizeof(FaceData); @@ -105,7 +105,7 @@ CSG_LoadBlenderMesh( Mesh *me; if (output == NULL || obj == NULL) return 0; - me = get_mesh(obj); + me = BKE_mesh_from_object(obj); output->m_descriptor.user_face_vertex_data_size = 0; output->m_descriptor.user_data_size = sizeof(FaceData); diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 51258b13f68..f019287144d 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -75,49 +75,49 @@ static void brush_defaults(Brush *brush) brush->ob_mode = OB_MODE_ALL_PAINT; /* BRUSH SCULPT TOOL SETTINGS */ - brush->weight= 1.0f; /* weight of brush 0 - 1.0 */ - brush->size= 35; /* radius of the brush in pixels */ - brush->alpha= 0.5f; /* brush strength/intensity probably variable should be renamed? */ - brush->autosmooth_factor= 0.0f; - brush->crease_pinch_factor= 0.5f; + brush->weight = 1.0f; /* weight of brush 0 - 1.0 */ + brush->size = 35; /* radius of the brush in pixels */ + brush->alpha = 0.5f; /* brush strength/intensity probably variable should be renamed? */ + brush->autosmooth_factor = 0.0f; + brush->crease_pinch_factor = 0.5f; brush->sculpt_plane = SCULPT_DISP_DIR_AREA; - brush->plane_offset= 0.0f; /* how far above or below the plane that is found by averaging the faces */ - brush->plane_trim= 0.5f; - brush->clone.alpha= 0.5f; - brush->normal_weight= 0.0f; + brush->plane_offset = 0.0f; /* how far above or below the plane that is found by averaging the faces */ + brush->plane_trim = 0.5f; + brush->clone.alpha = 0.5f; + brush->normal_weight = 0.0f; brush->flag |= BRUSH_ALPHA_PRESSURE; /* BRUSH PAINT TOOL SETTINGS */ - brush->rgb[0]= 1.0f; /* default rgb color of the brush when painting - white */ - brush->rgb[1]= 1.0f; - brush->rgb[2]= 1.0f; + brush->rgb[0] = 1.0f; /* default rgb color of the brush when painting - white */ + brush->rgb[1] = 1.0f; + brush->rgb[2] = 1.0f; /* BRUSH STROKE SETTINGS */ - brush->flag |= (BRUSH_SPACE|BRUSH_SPACE_ATTEN); - brush->spacing= 10; /* how far each brush dot should be spaced as a percentage of brush diameter */ + brush->flag |= (BRUSH_SPACE | BRUSH_SPACE_ATTEN); + brush->spacing = 10; /* how far each brush dot should be spaced as a percentage of brush diameter */ - brush->smooth_stroke_radius= 75; - brush->smooth_stroke_factor= 0.9f; + brush->smooth_stroke_radius = 75; + brush->smooth_stroke_factor = 0.9f; - brush->rate= 0.1f; /* time delay between dots of paint or sculpting when doing airbrush mode */ + brush->rate = 0.1f; /* time delay between dots of paint or sculpting when doing airbrush mode */ - brush->jitter= 0.0f; + brush->jitter = 0.0f; /* BRUSH TEXTURE SETTINGS */ default_mtex(&brush->mtex); - brush->texture_sample_bias= 0; /* value to added to texture samples */ - brush->texture_overlay_alpha= 33; + brush->texture_sample_bias = 0; /* value to added to texture samples */ + brush->texture_overlay_alpha = 33; /* brush appearance */ - brush->add_col[0]= 1.00; /* add mode color is light red */ - brush->add_col[1]= 0.39; - brush->add_col[2]= 0.39; + brush->add_col[0] = 1.00; /* add mode color is light red */ + brush->add_col[1] = 0.39; + brush->add_col[2] = 0.39; - brush->sub_col[0]= 0.39; /* subtract mode color is light blue */ - brush->sub_col[1]= 0.39; - brush->sub_col[2]= 1.00; + brush->sub_col[0] = 0.39; /* subtract mode color is light blue */ + brush->sub_col[1] = 0.39; + brush->sub_col[2] = 1.00; } /* Datablock add/copy/free/make_local */ @@ -126,7 +126,7 @@ Brush *BKE_brush_add(const char *name) { Brush *brush; - brush= alloc_libblock(&G.main->brush, ID_BR, name); + brush = BKE_libblock_alloc(&G.main->brush, ID_BR, name); /* enable fake user by default */ brush->id.flag |= LIB_FAKEUSER; @@ -135,7 +135,7 @@ Brush *BKE_brush_add(const char *name) brush->sculpt_tool = SCULPT_TOOL_DRAW; /* sculpting defaults to the draw tool for new brushes */ - /* the default alpha falloff curve */ + /* the default alpha falloff curve */ BKE_brush_curve_preset(brush, CURVE_PRESET_SMOOTH); return brush; @@ -145,17 +145,17 @@ Brush *BKE_brush_copy(Brush *brush) { Brush *brushn; - brushn= copy_libblock(&brush->id); + brushn = BKE_libblock_copy(&brush->id); if (brush->mtex.tex) - id_us_plus((ID*)brush->mtex.tex); + id_us_plus((ID *)brush->mtex.tex); if (brush->icon_imbuf) - brushn->icon_imbuf= IMB_dupImBuf(brush->icon_imbuf); + brushn->icon_imbuf = IMB_dupImBuf(brush->icon_imbuf); brushn->preview = NULL; - brushn->curve= curvemapping_copy(brush->curve); + brushn->curve = curvemapping_copy(brush->curve); /* enable fake user by default */ if (!(brushn->id.flag & LIB_FAKEUSER)) { @@ -194,11 +194,11 @@ void BKE_brush_make_local(Brush *brush) * - mixed: make copy */ - Main *bmain= G.main; + Main *bmain = G.main; Scene *scene; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; - if (brush->id.lib==NULL) return; + if (brush->id.lib == NULL) return; if (brush->clone.image) { /* special case: ima always local immediately. Clone image should only @@ -207,10 +207,10 @@ void BKE_brush_make_local(Brush *brush) extern_local_brush(brush); } - for (scene= bmain->scene.first; scene && ELEM(0, is_lib, is_local); scene=scene->id.next) { - if (paint_brush(&scene->toolsettings->imapaint.paint)==brush) { - if (scene->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (scene = bmain->scene.first; scene && ELEM(0, is_lib, is_local); scene = scene->id.next) { + if (paint_brush(&scene->toolsettings->imapaint.paint) == brush) { + if (scene->id.lib) is_lib = TRUE; + else is_local = TRUE; } } @@ -225,16 +225,16 @@ void BKE_brush_make_local(Brush *brush) } } else if (is_local && is_lib) { - Brush *brush_new= BKE_brush_copy(brush); - brush_new->id.us= 1; /* only keep fake user */ + Brush *brush_new = BKE_brush_copy(brush); + brush_new->id.us = 1; /* only keep fake user */ brush_new->id.flag |= LIB_FAKEUSER; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, brush->id.lib, &brush_new->id); - for (scene= bmain->scene.first; scene; scene=scene->id.next) { - if (paint_brush(&scene->toolsettings->imapaint.paint)==brush) { - if (scene->id.lib==NULL) { + for (scene = bmain->scene.first; scene; scene = scene->id.next) { + if (paint_brush(&scene->toolsettings->imapaint.paint) == brush) { + if (scene->id.lib == NULL) { paint_brush_set(&scene->toolsettings->imapaint.paint, brush_new); } } @@ -245,16 +245,16 @@ void BKE_brush_make_local(Brush *brush) void BKE_brush_debug_print_state(Brush *br) { /* create a fake brush and set it to the defaults */ - Brush def= {{NULL}}; + Brush def = {{NULL}}; brush_defaults(&def); #define BR_TEST(field, t) \ if (br->field != def.field) \ printf("br->" #field " = %" #t ";\n", br->field) -#define BR_TEST_FLAG(_f) \ +#define BR_TEST_FLAG(_f) \ if ((br->flag & _f) && !(def.flag & _f)) \ - printf("br->flag |= " #_f ";\n"); \ + printf("br->flag |= " #_f ";\n"); \ else if (!(br->flag & _f) && (def.flag & _f)) \ printf("br->flag &= ~" #_f ";\n") @@ -339,77 +339,77 @@ void BKE_brush_sculpt_reset(Brush *br) BKE_brush_curve_preset(br, CURVE_PRESET_SMOOTH); switch (br->sculpt_tool) { - case SCULPT_TOOL_CLAY: - br->flag |= BRUSH_FRONTFACE; - break; - case SCULPT_TOOL_CREASE: - br->flag |= BRUSH_DIR_IN; - br->alpha = 0.25; - break; - case SCULPT_TOOL_FILL: - br->add_col[1] = 1; - br->sub_col[0] = 0.25; - br->sub_col[1] = 1; - break; - case SCULPT_TOOL_FLATTEN: - br->add_col[1] = 1; - br->sub_col[0] = 0.25; - br->sub_col[1] = 1; - break; - case SCULPT_TOOL_INFLATE: - br->add_col[0] = 0.750000; - br->add_col[1] = 0.750000; - br->add_col[2] = 0.750000; - br->sub_col[0] = 0.250000; - br->sub_col[1] = 0.250000; - br->sub_col[2] = 0.250000; - break; - case SCULPT_TOOL_NUDGE: - br->add_col[0] = 0.250000; - br->add_col[1] = 1.000000; - br->add_col[2] = 0.250000; - break; - case SCULPT_TOOL_PINCH: - br->add_col[0] = 0.750000; - br->add_col[1] = 0.750000; - br->add_col[2] = 0.750000; - br->sub_col[0] = 0.250000; - br->sub_col[1] = 0.250000; - br->sub_col[2] = 0.250000; - break; - case SCULPT_TOOL_SCRAPE: - br->add_col[1] = 1.000000; - br->sub_col[0] = 0.250000; - br->sub_col[1] = 1.000000; - break; - case SCULPT_TOOL_ROTATE: - br->alpha = 1.0; - break; - case SCULPT_TOOL_SMOOTH: - br->flag &= ~BRUSH_SPACE_ATTEN; - br->spacing = 5; - br->add_col[0] = 0.750000; - br->add_col[1] = 0.750000; - br->add_col[2] = 0.750000; - break; - case SCULPT_TOOL_GRAB: - case SCULPT_TOOL_SNAKE_HOOK: - case SCULPT_TOOL_THUMB: - br->size = 75; - br->flag &= ~BRUSH_ALPHA_PRESSURE; - br->flag &= ~BRUSH_SPACE; - br->flag &= ~BRUSH_SPACE_ATTEN; - br->add_col[0] = 0.250000; - br->add_col[1] = 1.000000; - br->add_col[2] = 0.250000; - break; - default: - break; + case SCULPT_TOOL_CLAY: + br->flag |= BRUSH_FRONTFACE; + break; + case SCULPT_TOOL_CREASE: + br->flag |= BRUSH_DIR_IN; + br->alpha = 0.25; + break; + case SCULPT_TOOL_FILL: + br->add_col[1] = 1; + br->sub_col[0] = 0.25; + br->sub_col[1] = 1; + break; + case SCULPT_TOOL_FLATTEN: + br->add_col[1] = 1; + br->sub_col[0] = 0.25; + br->sub_col[1] = 1; + break; + case SCULPT_TOOL_INFLATE: + br->add_col[0] = 0.750000; + br->add_col[1] = 0.750000; + br->add_col[2] = 0.750000; + br->sub_col[0] = 0.250000; + br->sub_col[1] = 0.250000; + br->sub_col[2] = 0.250000; + break; + case SCULPT_TOOL_NUDGE: + br->add_col[0] = 0.250000; + br->add_col[1] = 1.000000; + br->add_col[2] = 0.250000; + break; + case SCULPT_TOOL_PINCH: + br->add_col[0] = 0.750000; + br->add_col[1] = 0.750000; + br->add_col[2] = 0.750000; + br->sub_col[0] = 0.250000; + br->sub_col[1] = 0.250000; + br->sub_col[2] = 0.250000; + break; + case SCULPT_TOOL_SCRAPE: + br->add_col[1] = 1.000000; + br->sub_col[0] = 0.250000; + br->sub_col[1] = 1.000000; + break; + case SCULPT_TOOL_ROTATE: + br->alpha = 1.0; + break; + case SCULPT_TOOL_SMOOTH: + br->flag &= ~BRUSH_SPACE_ATTEN; + br->spacing = 5; + br->add_col[0] = 0.750000; + br->add_col[1] = 0.750000; + br->add_col[2] = 0.750000; + break; + case SCULPT_TOOL_GRAB: + case SCULPT_TOOL_SNAKE_HOOK: + case SCULPT_TOOL_THUMB: + br->size = 75; + br->flag &= ~BRUSH_ALPHA_PRESSURE; + br->flag &= ~BRUSH_SPACE; + br->flag &= ~BRUSH_SPACE_ATTEN; + br->add_col[0] = 0.250000; + br->add_col[1] = 1.000000; + br->add_col[2] = 0.250000; + break; + default: + break; } } /* Library Operations */ -void BKE_brush_curve_preset(Brush *b, /*CurveMappingPreset*/int preset) +void BKE_brush_curve_preset(Brush *b, /*CurveMappingPreset*/ int preset) { CurveMap *cm = NULL; @@ -426,20 +426,20 @@ void BKE_brush_curve_preset(Brush *b, /*CurveMappingPreset*/int preset) int BKE_brush_texture_set_nr(Brush *brush, int nr) { - ID *idtest, *id=NULL; + ID *idtest, *id = NULL; - id= (ID *)brush->mtex.tex; + id = (ID *)brush->mtex.tex; - idtest= (ID*)BLI_findlink(&G.main->tex, nr-1); - if (idtest==NULL) { /* new tex */ - if (id) idtest= (ID *)copy_texture((Tex *)id); - else idtest= (ID *)add_texture("Tex"); + idtest = (ID *)BLI_findlink(&G.main->tex, nr - 1); + if (idtest == NULL) { /* new tex */ + if (id) idtest = (ID *)BKE_texture_copy((Tex *)id); + else idtest = (ID *)add_texture("Tex"); idtest->us--; } - if (idtest!=id) { + if (idtest != id) { BKE_brush_texture_delete(brush); - brush->mtex.tex= (Tex*)idtest; + brush->mtex.tex = (Tex *)idtest; id_us_plus(idtest); return 1; @@ -459,13 +459,13 @@ int BKE_brush_texture_delete(Brush *brush) int BKE_brush_clone_image_set_nr(Brush *brush, int nr) { if (brush && nr > 0) { - Image *ima= (Image*)BLI_findlink(&G.main->image, nr-1); + Image *ima = (Image *)BLI_findlink(&G.main->image, nr - 1); if (ima) { BKE_brush_clone_image_delete(brush); - brush->clone.image= ima; + brush->clone.image = ima; id_us_plus(&ima->id); - brush->clone.offset[0]= brush->clone.offset[1]= 0.0f; + brush->clone.offset[0] = brush->clone.offset[1] = 0.0f; return 1; } @@ -478,7 +478,7 @@ int BKE_brush_clone_image_delete(Brush *brush) { if (brush && brush->clone.image) { brush->clone.image->id.us--; - brush->clone.image= NULL; + brush->clone.image = NULL; return 1; } @@ -488,34 +488,34 @@ int BKE_brush_clone_image_delete(Brush *brush) /* Brush Sampling */ void BKE_brush_sample_tex(const Scene *scene, Brush *brush, const float xy[2], float rgba[4], const int thread) { - MTex *mtex= &brush->mtex; + MTex *mtex = &brush->mtex; if (mtex && mtex->tex) { float co[3], tin, tr, tg, tb, ta; int hasrgb; - const int radius= BKE_brush_size_get(scene, brush); + const int radius = BKE_brush_size_get(scene, brush); - co[0]= xy[0]/radius; - co[1]= xy[1]/radius; - co[2]= 0.0f; + co[0] = xy[0] / radius; + co[1] = xy[1] / radius; + co[2] = 0.0f; - hasrgb= externtex(mtex, co, &tin, &tr, &tg, &tb, &ta, thread); + hasrgb = externtex(mtex, co, &tin, &tr, &tg, &tb, &ta, thread); if (hasrgb) { - rgba[0]= tr; - rgba[1]= tg; - rgba[2]= tb; - rgba[3]= ta; + rgba[0] = tr; + rgba[1] = tg; + rgba[2] = tb; + rgba[3] = ta; } else { - rgba[0]= tin; - rgba[1]= tin; - rgba[2]= tin; - rgba[3]= 1.0f; + rgba[0] = tin; + rgba[1] = tin; + rgba[2] = tin; + rgba[3] = 1.0f; } } else { - rgba[0]= rgba[1]= rgba[2]= rgba[3]= 1.0f; + rgba[0] = rgba[1] = rgba[2] = rgba[3] = 1.0f; } } @@ -525,20 +525,20 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf ImBuf *ibuf; float xy[2], rgba[4], *dstf; int x, y, rowbytes, xoff, yoff, imbflag; - const int radius= BKE_brush_size_get(scene, brush); + const int radius = BKE_brush_size_get(scene, brush); unsigned char *dst, crgb[3]; - const float alpha= BKE_brush_alpha_get(scene, brush); + const float alpha = BKE_brush_alpha_get(scene, brush); float brush_rgb[3]; - imbflag= (flt)? IB_rectfloat: IB_rect; - xoff = -bufsize/2.0f + 0.5f; - yoff = -bufsize/2.0f + 0.5f; - rowbytes= bufsize*4; + imbflag = (flt) ? IB_rectfloat : IB_rect; + xoff = -bufsize / 2.0f + 0.5f; + yoff = -bufsize / 2.0f + 0.5f; + rowbytes = bufsize * 4; if (*outbuf) - ibuf= *outbuf; + ibuf = *outbuf; else - ibuf= IMB_allocImBuf(bufsize, bufsize, 32, imbflag); + ibuf = IMB_allocImBuf(bufsize, bufsize, 32, imbflag); if (flt) { copy_v3_v3(brush_rgb, brush->rgb); @@ -546,16 +546,16 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf srgb_to_linearrgb_v3_v3(brush_rgb, brush_rgb); } - for (y=0; y < ibuf->y; y++) { - dstf = ibuf->rect_float + y*rowbytes; + for (y = 0; y < ibuf->y; y++) { + dstf = ibuf->rect_float + y * rowbytes; - for (x=0; x < ibuf->x; x++, dstf+=4) { + for (x = 0; x < ibuf->x; x++, dstf += 4) { xy[0] = x + xoff; xy[1] = y + yoff; if (texfall == 0) { copy_v3_v3(dstf, brush_rgb); - dstf[3]= alpha*BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius); + dstf[3] = alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius); } else if (texfall == 1) { BKE_brush_sample_tex(scene, brush, xy, dstf, 0); @@ -563,7 +563,7 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf else { BKE_brush_sample_tex(scene, brush, xy, rgba, 0); mul_v3_v3v3(dstf, rgba, brush_rgb); - dstf[3] = rgba[3]*alpha*BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius); + dstf[3] = rgba[3] *alpha *BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius); } } } @@ -572,10 +572,10 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf float alpha_f; /* final float alpha to convert to char */ rgb_float_to_uchar(crgb, brush->rgb); - for (y=0; y < ibuf->y; y++) { - dst = (unsigned char *)ibuf->rect + y*rowbytes; + for (y = 0; y < ibuf->y; y++) { + dst = (unsigned char *)ibuf->rect + y * rowbytes; - for (x=0; x < ibuf->x; x++, dst+=4) { + for (x = 0; x < ibuf->x; x++, dst += 4) { xy[0] = x + xoff; xy[1] = y + yoff; @@ -594,7 +594,7 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf else if (texfall == 2) { BKE_brush_sample_tex(scene, brush, xy, rgba, 0); mul_v3_v3(rgba, brush->rgb); - alpha_f = rgba[3] * alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius); + alpha_f = rgba[3] *alpha *BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius); rgb_float_to_uchar(dst, rgba); @@ -602,7 +602,7 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf } else { BKE_brush_sample_tex(scene, brush, xy, rgba, 0); - alpha_f = rgba[3] * alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius); + alpha_f = rgba[3] *alpha *BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius); dst[0] = crgb[0]; dst[1] = crgb[1]; @@ -613,7 +613,7 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf } } - *outbuf= ibuf; + *outbuf = ibuf; } /* Unified Size and Strength */ @@ -636,9 +636,9 @@ void BKE_brush_size_set(Scene *scene, Brush *brush, int size) UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; if (ups->flag & UNIFIED_PAINT_SIZE) - ups->size= size; + ups->size = size; else - brush->size= size; + brush->size = size; } int BKE_brush_size_get(const Scene *scene, Brush *brush) @@ -653,8 +653,8 @@ int BKE_brush_use_locked_size(const Scene *scene, Brush *brush) const short us_flag = scene->toolsettings->unified_paint_settings.flag; return (us_flag & UNIFIED_PAINT_SIZE) ? - (us_flag & UNIFIED_PAINT_BRUSH_LOCK_SIZE) : - (brush->flag & BRUSH_LOCK_SIZE); + (us_flag & UNIFIED_PAINT_BRUSH_LOCK_SIZE) : + (brush->flag & BRUSH_LOCK_SIZE); } int BKE_brush_use_size_pressure(const Scene *scene, Brush *brush) @@ -662,8 +662,8 @@ int BKE_brush_use_size_pressure(const Scene *scene, Brush *brush) const short us_flag = scene->toolsettings->unified_paint_settings.flag; return (us_flag & UNIFIED_PAINT_SIZE) ? - (us_flag & UNIFIED_PAINT_BRUSH_SIZE_PRESSURE) : - (brush->flag & BRUSH_SIZE_PRESSURE); + (us_flag & UNIFIED_PAINT_BRUSH_SIZE_PRESSURE) : + (brush->flag & BRUSH_SIZE_PRESSURE); } int BKE_brush_use_alpha_pressure(const Scene *scene, Brush *brush) @@ -671,8 +671,8 @@ int BKE_brush_use_alpha_pressure(const Scene *scene, Brush *brush) const short us_flag = scene->toolsettings->unified_paint_settings.flag; return (us_flag & UNIFIED_PAINT_ALPHA) ? - (us_flag & UNIFIED_PAINT_BRUSH_ALPHA_PRESSURE) : - (brush->flag & BRUSH_ALPHA_PRESSURE); + (us_flag & UNIFIED_PAINT_BRUSH_ALPHA_PRESSURE) : + (brush->flag & BRUSH_ALPHA_PRESSURE); } void BKE_brush_unprojected_radius_set(Scene *scene, Brush *brush, float unprojected_radius) @@ -680,9 +680,9 @@ void BKE_brush_unprojected_radius_set(Scene *scene, Brush *brush, float unprojec UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; if (ups->flag & UNIFIED_PAINT_SIZE) - ups->unprojected_radius= unprojected_radius; + ups->unprojected_radius = unprojected_radius; else - brush->unprojected_radius= unprojected_radius; + brush->unprojected_radius = unprojected_radius; } float BKE_brush_unprojected_radius_get(const Scene *scene, Brush *brush) @@ -690,8 +690,8 @@ float BKE_brush_unprojected_radius_get(const Scene *scene, Brush *brush) UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; return (ups->flag & UNIFIED_PAINT_SIZE) ? - ups->unprojected_radius : - brush->unprojected_radius; + ups->unprojected_radius : + brush->unprojected_radius; } static void brush_alpha_set(Scene *scene, Brush *brush, float alpha) @@ -699,9 +699,9 @@ static void brush_alpha_set(Scene *scene, Brush *brush, float alpha) UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; if (ups->flag & UNIFIED_PAINT_ALPHA) - ups->alpha= alpha; + ups->alpha = alpha; else - brush->alpha= alpha; + brush->alpha = alpha; } float BKE_brush_alpha_get(const Scene *scene, Brush *brush) @@ -722,7 +722,7 @@ void BKE_brush_weight_set(const Scene *scene, Brush *brush, float value) { UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; - if(ups->flag & UNIFIED_PAINT_WEIGHT) + if (ups->flag & UNIFIED_PAINT_WEIGHT) ups->weight = value; else brush->weight = value; @@ -749,7 +749,7 @@ void BKE_brush_scale_size(int *BKE_brush_size_get, /* avoid division by zero */ if (old_unprojected_radius != 0) scale /= new_unprojected_radius; - (*BKE_brush_size_get)= (int)((float)(*BKE_brush_size_get) * scale); + (*BKE_brush_size_get) = (int)((float)(*BKE_brush_size_get) * scale); } /* Brush Painting */ @@ -757,9 +757,9 @@ void BKE_brush_scale_size(int *BKE_brush_size_get, typedef struct BrushPainterCache { short enabled; - int size; /* size override, if 0 uses 2*BKE_brush_size_get(brush) */ - short flt; /* need float imbuf? */ - short texonly; /* no alpha, color or fallof, only texture in imbuf */ + int size; /* size override, if 0 uses 2*BKE_brush_size_get(brush) */ + short flt; /* need float imbuf? */ + short texonly; /* no alpha, color or fallof, only texture in imbuf */ int lastsize; float lastalpha; @@ -774,18 +774,18 @@ struct BrushPainter { Scene *scene; Brush *brush; - float lastmousepos[2]; /* mouse position of last paint call */ + float lastmousepos[2]; /* mouse position of last paint call */ - float accumdistance; /* accumulated distance of brush since last paint op */ - float lastpaintpos[2]; /* position of last paint op */ + float accumdistance; /* accumulated distance of brush since last paint op */ + float lastpaintpos[2]; /* position of last paint op */ float startpaintpos[2]; /* position of first paint */ - double accumtime; /* accumulated time since last paint op (airbrush) */ - double lasttime; /* time of last update */ + double accumtime; /* accumulated time since last paint op (airbrush) */ + double lasttime; /* time of last update */ float lastpressure; - short firsttouch; /* first paint op */ + short firsttouch; /* first paint op */ float startsize; float startalpha; @@ -797,12 +797,12 @@ struct BrushPainter { BrushPainter *BKE_brush_painter_new(Scene *scene, Brush *brush) { - BrushPainter *painter= MEM_callocN(sizeof(BrushPainter), "BrushPainter"); + BrushPainter *painter = MEM_callocN(sizeof(BrushPainter), "BrushPainter"); - painter->brush= brush; - painter->scene= scene; - painter->firsttouch= 1; - painter->cache.lastsize= -1; /* force ibuf create in refresh */ + painter->brush = brush; + painter->scene = scene; + painter->firsttouch = 1; + painter->cache.lastsize = -1; /* force ibuf create in refresh */ painter->startsize = BKE_brush_size_get(scene, brush); painter->startalpha = BKE_brush_alpha_get(scene, brush); @@ -815,23 +815,24 @@ BrushPainter *BKE_brush_painter_new(Scene *scene, Brush *brush) void BKE_brush_painter_require_imbuf(BrushPainter *painter, short flt, short texonly, int size) { if ((painter->cache.flt != flt) || (painter->cache.size != size) || - ((painter->cache.texonly != texonly) && texonly)) { + ((painter->cache.texonly != texonly) && texonly)) + { if (painter->cache.ibuf) IMB_freeImBuf(painter->cache.ibuf); if (painter->cache.maskibuf) IMB_freeImBuf(painter->cache.maskibuf); - painter->cache.ibuf= painter->cache.maskibuf= NULL; - painter->cache.lastsize= -1; /* force ibuf create in refresh */ + painter->cache.ibuf = painter->cache.maskibuf = NULL; + painter->cache.lastsize = -1; /* force ibuf create in refresh */ } if (painter->cache.flt != flt) { if (painter->cache.texibuf) IMB_freeImBuf(painter->cache.texibuf); - painter->cache.texibuf= NULL; - painter->cache.lastsize= -1; /* force ibuf create in refresh */ + painter->cache.texibuf = NULL; + painter->cache.lastsize = -1; /* force ibuf create in refresh */ } - painter->cache.size= size; - painter->cache.flt= flt; - painter->cache.texonly= texonly; - painter->cache.enabled= 1; + painter->cache.size = size; + painter->cache.flt = flt; + painter->cache.texonly = texonly; + painter->cache.enabled = 1; } void BKE_brush_painter_free(BrushPainter *painter) @@ -853,13 +854,13 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, int x, int y, int w, int h, int xt, int yt, const float pos[2]) { - Scene *scene= painter->scene; - Brush *brush= painter->brush; + Scene *scene = painter->scene; + Brush *brush = painter->brush; ImBuf *ibuf, *maskibuf, *texibuf; - float *bf, *mf, *tf, *otf=NULL, xoff, yoff, xy[2], rgba[4]; - unsigned char *b, *m, *t, *ot= NULL; - int dotexold, origx= x, origy= y; - const int radius= BKE_brush_size_get(painter->scene, brush); + float *bf, *mf, *tf, *otf = NULL, xoff, yoff, xy[2], rgba[4]; + unsigned char *b, *m, *t, *ot = NULL; + int dotexold, origx = x, origy = y; + const int radius = BKE_brush_size_get(painter->scene, brush); xoff = -radius + 0.5f; yoff = -radius + 0.5f; @@ -880,14 +881,14 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, if (painter->cache.flt) { for (; y < h; y++) { - bf = ibuf->rect_float + (y*ibuf->x + origx)*4; - tf = texibuf->rect_float + (y*texibuf->x + origx)*4; - mf = maskibuf->rect_float + (y*maskibuf->x + origx)*4; + bf = ibuf->rect_float + (y * ibuf->x + origx) * 4; + tf = texibuf->rect_float + (y * texibuf->x + origx) * 4; + mf = maskibuf->rect_float + (y * maskibuf->x + origx) * 4; if (dotexold) - otf = oldtexibuf->rect_float + ((y - origy + yt)*oldtexibuf->x + xt)*4; + otf = oldtexibuf->rect_float + ((y - origy + yt) * oldtexibuf->x + xt) * 4; - for (x=origx; x < w; x++, bf+=4, mf+=4, tf+=4) { + for (x = origx; x < w; x++, bf += 4, mf += 4, tf += 4) { if (dotexold) { copy_v3_v3(tf, otf); tf[3] = otf[3]; @@ -900,23 +901,23 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, BKE_brush_sample_tex(scene, brush, xy, tf, 0); } - bf[0] = tf[0]*mf[0]; - bf[1] = tf[1]*mf[1]; - bf[2] = tf[2]*mf[2]; - bf[3] = tf[3]*mf[3]; + bf[0] = tf[0] * mf[0]; + bf[1] = tf[1] * mf[1]; + bf[2] = tf[2] * mf[2]; + bf[3] = tf[3] * mf[3]; } } } else { for (; y < h; y++) { - b = (unsigned char *)ibuf->rect + (y*ibuf->x + origx)*4; - t = (unsigned char *)texibuf->rect + (y*texibuf->x + origx)*4; - m = (unsigned char *)maskibuf->rect + (y*maskibuf->x + origx)*4; + b = (unsigned char *)ibuf->rect + (y * ibuf->x + origx) * 4; + t = (unsigned char *)texibuf->rect + (y * texibuf->x + origx) * 4; + m = (unsigned char *)maskibuf->rect + (y * maskibuf->x + origx) * 4; if (dotexold) - ot = (unsigned char *)oldtexibuf->rect + ((y - origy + yt)*oldtexibuf->x + xt)*4; + ot = (unsigned char *)oldtexibuf->rect + ((y - origy + yt) * oldtexibuf->x + xt) * 4; - for (x=origx; x < w; x++, b+=4, m+=4, t+=4) { + for (x = origx; x < w; x++, b += 4, m += 4, t += 4) { if (dotexold) { t[0] = ot[0]; t[1] = ot[1]; @@ -932,10 +933,10 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, rgba_float_to_uchar(t, rgba); } - b[0] = t[0]*m[0]/255; - b[1] = t[1]*m[1]/255; - b[2] = t[2]*m[2]/255; - b[3] = t[3]*m[3]/255; + b[0] = t[0] * m[0] / 255; + b[1] = t[1] * m[1] / 255; + b[2] = t[2] * m[2] / 255; + b[3] = t[3] * m[3] / 255; } } } @@ -943,40 +944,40 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, static void brush_painter_fixed_tex_partial_update(BrushPainter *painter, const float pos[2]) { - const Scene *scene= painter->scene; - Brush *brush= painter->brush; - BrushPainterCache *cache= &painter->cache; + const Scene *scene = painter->scene; + Brush *brush = painter->brush; + BrushPainterCache *cache = &painter->cache; ImBuf *oldtexibuf, *ibuf; int imbflag, destx, desty, srcx, srcy, w, h, x1, y1, x2, y2; - const int diameter= 2*BKE_brush_size_get(scene, brush); + const int diameter = 2 * BKE_brush_size_get(scene, brush); - imbflag= (cache->flt)? IB_rectfloat: IB_rect; + imbflag = (cache->flt) ? IB_rectfloat : IB_rect; if (!cache->ibuf) - cache->ibuf= IMB_allocImBuf(diameter, diameter, 32, imbflag); - ibuf= cache->ibuf; + cache->ibuf = IMB_allocImBuf(diameter, diameter, 32, imbflag); + ibuf = cache->ibuf; - oldtexibuf= cache->texibuf; - cache->texibuf= IMB_allocImBuf(diameter, diameter, 32, imbflag); + oldtexibuf = cache->texibuf; + cache->texibuf = IMB_allocImBuf(diameter, diameter, 32, imbflag); if (oldtexibuf) { - srcx= srcy= 0; - destx= (int)painter->lastpaintpos[0] - (int)pos[0]; - desty= (int)painter->lastpaintpos[1] - (int)pos[1]; - w= oldtexibuf->x; - h= oldtexibuf->y; + srcx = srcy = 0; + destx = (int)painter->lastpaintpos[0] - (int)pos[0]; + desty = (int)painter->lastpaintpos[1] - (int)pos[1]; + w = oldtexibuf->x; + h = oldtexibuf->y; IMB_rectclip(cache->texibuf, oldtexibuf, &destx, &desty, &srcx, &srcy, &w, &h); } else { - srcx= srcy= 0; - destx= desty= 0; - w= h= 0; + srcx = srcy = 0; + destx = desty = 0; + w = h = 0; } - x1= destx; - y1= desty; - x2= destx+w; - y2= desty+h; + x1 = destx; + y1 = desty; + x2 = destx + w; + y2 = desty + h; /* blend existing texture in new position */ if ((x1 < x2) && (y1 < y2)) @@ -998,30 +999,30 @@ static void brush_painter_fixed_tex_partial_update(BrushPainter *painter, const static void brush_painter_refresh_cache(BrushPainter *painter, const float pos[2], int use_color_correction) { - const Scene *scene= painter->scene; - Brush *brush= painter->brush; - BrushPainterCache *cache= &painter->cache; - MTex *mtex= &brush->mtex; + const Scene *scene = painter->scene; + Brush *brush = painter->brush; + BrushPainterCache *cache = &painter->cache; + MTex *mtex = &brush->mtex; int size; short flt; - const int diameter= 2*BKE_brush_size_get(scene, brush); - const float alpha= BKE_brush_alpha_get(scene, brush); + const int diameter = 2 * BKE_brush_size_get(scene, brush); + const float alpha = BKE_brush_alpha_get(scene, brush); if (diameter != cache->lastsize || - alpha != cache->lastalpha || - brush->jitter != cache->lastjitter) + alpha != cache->lastalpha || + brush->jitter != cache->lastjitter) { if (cache->ibuf) { IMB_freeImBuf(cache->ibuf); - cache->ibuf= NULL; + cache->ibuf = NULL; } if (cache->maskibuf) { IMB_freeImBuf(cache->maskibuf); - cache->maskibuf= NULL; + cache->maskibuf = NULL; } - flt= cache->flt; - size= (cache->size)? cache->size: diameter; + flt = cache->flt; + size = (cache->size) ? cache->size : diameter; if (brush->flag & BRUSH_FIXED_TEX) { BKE_brush_imbuf_new(scene, brush, flt, 3, size, &cache->maskibuf, use_color_correction); @@ -1030,9 +1031,9 @@ static void brush_painter_refresh_cache(BrushPainter *painter, const float pos[2 else BKE_brush_imbuf_new(scene, brush, flt, 2, size, &cache->ibuf, use_color_correction); - cache->lastsize= diameter; - cache->lastalpha= alpha; - cache->lastjitter= brush->jitter; + cache->lastsize = diameter; + cache->lastalpha = alpha; + cache->lastjitter = brush->jitter; } else if ((brush->flag & BRUSH_FIXED_TEX) && mtex && mtex->tex) { int dx = (int)painter->lastpaintpos[0] - (int)pos[0]; @@ -1045,42 +1046,42 @@ static void brush_painter_refresh_cache(BrushPainter *painter, const float pos[2 void BKE_brush_painter_break_stroke(BrushPainter *painter) { - painter->firsttouch= 1; + painter->firsttouch = 1; } static void brush_pressure_apply(BrushPainter *painter, Brush *brush, float pressure) { if (BKE_brush_use_alpha_pressure(painter->scene, brush)) - brush_alpha_set(painter->scene, brush, MAX2(0.0f, painter->startalpha*pressure)); + brush_alpha_set(painter->scene, brush, MAX2(0.0f, painter->startalpha * pressure)); if (BKE_brush_use_size_pressure(painter->scene, brush)) - BKE_brush_size_set(painter->scene, brush, MAX2(1.0f, painter->startsize*pressure)); + BKE_brush_size_set(painter->scene, brush, MAX2(1.0f, painter->startsize * pressure)); if (brush->flag & BRUSH_JITTER_PRESSURE) - brush->jitter = MAX2(0.0f, painter->startjitter*pressure); + brush->jitter = MAX2(0.0f, painter->startjitter * pressure); if (brush->flag & BRUSH_SPACING_PRESSURE) - brush->spacing = MAX2(1.0f, painter->startspacing*(1.5f-pressure)); + brush->spacing = MAX2(1.0f, painter->startspacing * (1.5f - pressure)); } void BKE_brush_jitter_pos(const Scene *scene, Brush *brush, const float pos[2], float jitterpos[2]) { - int use_jitter= brush->jitter != 0; + int use_jitter = brush->jitter != 0; /* jitter-ed brush gives weird and unpredictable result for this * kinds of stroke, so manyally disable jitter usage (sergey) */ - use_jitter &= (brush->flag & (BRUSH_RESTORE_MESH|BRUSH_ANCHORED)) == 0; + use_jitter &= (brush->flag & (BRUSH_RESTORE_MESH | BRUSH_ANCHORED)) == 0; if (use_jitter) { float rand_pos[2]; - const int radius= BKE_brush_size_get(scene, brush); - const int diameter= 2*radius; + const int radius = BKE_brush_size_get(scene, brush); + const int diameter = 2 * radius; // find random position within a circle of diameter 1 do { - rand_pos[0] = BLI_frand()-0.5f; - rand_pos[1] = BLI_frand()-0.5f; + rand_pos[0] = BLI_frand() - 0.5f; + rand_pos[1] = BLI_frand() - 0.5f; } while (len_v2(rand_pos) > 0.5f); - jitterpos[0] = pos[0] + 2*rand_pos[0]*diameter*brush->jitter; - jitterpos[1] = pos[1] + 2*rand_pos[1]*diameter*brush->jitter; + jitterpos[0] = pos[0] + 2 * rand_pos[0] * diameter * brush->jitter; + jitterpos[1] = pos[1] + 2 * rand_pos[1] * diameter * brush->jitter; } else { copy_v2_v2(jitterpos, pos); @@ -1090,92 +1091,92 @@ void BKE_brush_jitter_pos(const Scene *scene, Brush *brush, const float pos[2], int BKE_brush_painter_paint(BrushPainter *painter, BrushFunc func, const float pos[2], double time, float pressure, void *user, int use_color_correction) { - Scene *scene= painter->scene; - Brush *brush= painter->brush; - int totpaintops= 0; + Scene *scene = painter->scene; + Brush *brush = painter->brush; + int totpaintops = 0; if (pressure == 0.0f) { if (painter->lastpressure) // XXX - hack, operator misses - pressure= painter->lastpressure; + pressure = painter->lastpressure; else - pressure = 1.0f; /* zero pressure == not using tablet */ + pressure = 1.0f; /* zero pressure == not using tablet */ } if (painter->firsttouch) { /* paint exactly once on first touch */ - painter->startpaintpos[0]= pos[0]; - painter->startpaintpos[1]= pos[1]; + painter->startpaintpos[0] = pos[0]; + painter->startpaintpos[1] = pos[1]; brush_pressure_apply(painter, brush, pressure); if (painter->cache.enabled) brush_painter_refresh_cache(painter, pos, use_color_correction); totpaintops += func(user, painter->cache.ibuf, pos, pos); - painter->lasttime= time; - painter->firsttouch= 0; - painter->lastpaintpos[0]= pos[0]; - painter->lastpaintpos[1]= pos[1]; + painter->lasttime = time; + painter->firsttouch = 0; + painter->lastpaintpos[0] = pos[0]; + painter->lastpaintpos[1] = pos[1]; } #if 0 else if (painter->brush->flag & BRUSH_AIRBRUSH) { float spacing, step, paintpos[2], dmousepos[2], len; - double starttime, curtime= time; + double starttime, curtime = time; /* compute brush spacing adapted to brush size */ - spacing= brush->rate; //radius*brush->spacing*0.01f; + spacing = brush->rate; //radius*brush->spacing*0.01f; /* setup starting time, direction vector and accumulated time */ - starttime= painter->accumtime; + starttime = painter->accumtime; sub_v2_v2v2(dmousepos, pos, painter->lastmousepos); - len= normalize_v2(dmousepos); + len = normalize_v2(dmousepos); painter->accumtime += curtime - painter->lasttime; /* do paint op over unpainted time distance */ while (painter->accumtime >= spacing) { - step= (spacing - starttime)*len; - paintpos[0]= painter->lastmousepos[0] + dmousepos[0]*step; - paintpos[1]= painter->lastmousepos[1] + dmousepos[1]*step; + step = (spacing - starttime) * len; + paintpos[0] = painter->lastmousepos[0] + dmousepos[0] * step; + paintpos[1] = painter->lastmousepos[1] + dmousepos[1] * step; if (painter->cache.enabled) brush_painter_refresh_cache(painter); totpaintops += func(user, painter->cache.ibuf, - painter->lastpaintpos, paintpos); + painter->lastpaintpos, paintpos); - painter->lastpaintpos[0]= paintpos[0]; - painter->lastpaintpos[1]= paintpos[1]; + painter->lastpaintpos[0] = paintpos[0]; + painter->lastpaintpos[1] = paintpos[1]; painter->accumtime -= spacing; starttime -= spacing; } - painter->lasttime= curtime; + painter->lasttime = curtime; } #endif else { float startdistance, spacing, step, paintpos[2], dmousepos[2], finalpos[2]; float t, len, press; - const int radius= BKE_brush_size_get(scene, brush); + const int radius = BKE_brush_size_get(scene, brush); /* compute brush spacing adapted to brush radius, spacing may depend * on pressure, so update it */ brush_pressure_apply(painter, brush, painter->lastpressure); - spacing= MAX2(1.0f, radius)*brush->spacing*0.01f; + spacing = MAX2(1.0f, radius) * brush->spacing * 0.01f; /* setup starting distance, direction vector and accumulated distance */ - startdistance= painter->accumdistance; + startdistance = painter->accumdistance; sub_v2_v2v2(dmousepos, pos, painter->lastmousepos); - len= normalize_v2(dmousepos); + len = normalize_v2(dmousepos); painter->accumdistance += len; 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; + 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; + t = step / len; + press = (1.0f - t) * painter->lastpressure + t * pressure; brush_pressure_apply(painter, brush, press); - spacing= MAX2(1.0f, radius)*brush->spacing*0.01f; + spacing = MAX2(1.0f, radius) * brush->spacing * 0.01f; BKE_brush_jitter_pos(scene, brush, paintpos, finalpos); @@ -1183,10 +1184,10 @@ int BKE_brush_painter_paint(BrushPainter *painter, BrushFunc func, const float p brush_painter_refresh_cache(painter, finalpos, use_color_correction); totpaintops += - func(user, painter->cache.ibuf, painter->lastpaintpos, finalpos); + func(user, painter->cache.ibuf, painter->lastpaintpos, finalpos); - painter->lastpaintpos[0]= paintpos[0]; - painter->lastpaintpos[1]= paintpos[1]; + painter->lastpaintpos[0] = paintpos[0]; + painter->lastpaintpos[1] = paintpos[1]; painter->accumdistance -= spacing; startdistance -= spacing; } @@ -1199,21 +1200,21 @@ int BKE_brush_painter_paint(BrushPainter *painter, BrushFunc func, const float p totpaintops += func(user, painter->cache.ibuf, pos, finalpos); - painter->lastpaintpos[0]= pos[0]; - painter->lastpaintpos[1]= pos[1]; - painter->accumdistance= 0; + 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 * from regular painting. this is a temporary solution until we have * accurate time stamps for mouse move events */ if (brush->flag & BRUSH_AIRBRUSH) { - double curtime= time; - double painttime= brush->rate*totpaintops; + double curtime = time; + double painttime = brush->rate * totpaintops; painter->accumtime += curtime - painter->lasttime; if (painter->accumtime <= painttime) - painter->accumtime= 0.0; + painter->accumtime = 0.0; else painter->accumtime -= painttime; @@ -1226,17 +1227,17 @@ int BKE_brush_painter_paint(BrushPainter *painter, BrushFunc func, const float p brush_painter_refresh_cache(painter, finalpos, use_color_correction); totpaintops += - func(user, painter->cache.ibuf, painter->lastmousepos, finalpos); + func(user, painter->cache.ibuf, painter->lastmousepos, finalpos); painter->accumtime -= (double)brush->rate; } - painter->lasttime= curtime; + painter->lasttime = curtime; } } - painter->lastmousepos[0]= pos[0]; - painter->lastmousepos[1]= pos[1]; - painter->lastpressure= pressure; + painter->lastmousepos[0] = pos[0]; + painter->lastmousepos[1] = pos[1]; + painter->lastpressure = pressure; brush_alpha_set(scene, brush, painter->startalpha); BKE_brush_size_set(scene, brush, painter->startsize); @@ -1249,12 +1250,12 @@ int BKE_brush_painter_paint(BrushPainter *painter, BrushFunc func, const float p /* Uses the brush curve control to find a strength value between 0 and 1 */ float BKE_brush_curve_strength_clamp(Brush *br, float p, const float len) { - if (p >= len) return 0; - else p= p/len; + if (p >= len) return 0; + else p = p / len; - p= curvemapping_evaluateF(br->curve, 0, p); - if (p < 0.0f) p= 0.0f; - else if (p > 1.0f) p= 1.0f; + p = curvemapping_evaluateF(br->curve, 0, p); + if (p < 0.0f) p = 0.0f; + else if (p > 1.0f) p = 1.0f; return p; } /* same as above but can return negative values if the curve enables @@ -1262,9 +1263,9 @@ float BKE_brush_curve_strength_clamp(Brush *br, float p, const float len) float BKE_brush_curve_strength(Brush *br, float p, const float len) { if (p >= len) - p= 1.0f; + p = 1.0f; else - p= p/len; + p = p / len; return curvemapping_evaluateF(br->curve, 0, p); } @@ -1274,7 +1275,7 @@ unsigned int *BKE_brush_gen_texture_cache(Brush *br, int half_side) { unsigned int *texcache = NULL; MTex *mtex = &br->mtex; - TexResult texres= {0}; + TexResult texres = {0}; int hasrgb, ix, iy; int side = half_side * 2; @@ -1286,11 +1287,11 @@ unsigned int *BKE_brush_gen_texture_cache(Brush *br, int half_side) BKE_image_get_ibuf(mtex->tex->ima, NULL); /*do normalized cannonical view coords for texture*/ - for (y=-1.0, iy=0; iy<side; iy++, y += step) { - for (x=-1.0, ix=0; ix<side; ix++, x += step) { - co[0]= x; - co[1]= y; - co[2]= 0.0f; + for (y = -1.0, iy = 0; iy < side; iy++, y += step) { + for (x = -1.0, ix = 0; ix < side; ix++, x += step) { + co[0] = x; + co[1] = y; + co[2] = 0.0f; /* This is copied from displace modifier code */ hasrgb = multitex_ext(mtex->tex, co, NULL, NULL, 0, &texres); @@ -1300,14 +1301,12 @@ unsigned int *BKE_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.35f * texres.tr + 0.45f * - texres.tg + 0.2f * texres.tb); - - 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; - ((char*)texcache)[(iy*side+ix)*4+3] = (char)texres.tin; + texres.tin = rgb_to_grayscale(&texres.tr); + + ((char *)texcache)[(iy * side + ix) * 4] = + ((char *)texcache)[(iy * side + ix) * 4 + 1] = + ((char *)texcache)[(iy * side + ix) * 4 + 2] = + ((char *)texcache)[(iy * side + ix) * 4 + 3] = (char)(texres.tin * 255.0f); } } } @@ -1328,19 +1327,19 @@ struct ImBuf *BKE_brush_gen_radial_control_imbuf(Brush *br) im->rect_float = MEM_callocN(sizeof(float) * side * side, "radial control rect"); im->x = im->y = side; - for (i=0; i<side; ++i) { - for (j=0; j<side; ++j) { - float magn= sqrt(pow(i - half, 2) + pow(j - half, 2)); - im->rect_float[i*side + j]= BKE_brush_curve_strength_clamp(br, magn, half); + for (i = 0; i < side; ++i) { + for (j = 0; j < side; ++j) { + float magn = sqrt(pow(i - half, 2) + pow(j - half, 2)); + im->rect_float[i * side + j] = BKE_brush_curve_strength_clamp(br, magn, half); } } /* Modulate curve with texture */ if (texcache) { - for (i=0; i<side; ++i) { - for (j=0; j<side; ++j) { - const int col= texcache[i*side+j]; - im->rect_float[i*side+j]*= (((char*)&col)[0]+((char*)&col)[1]+((char*)&col)[2])/3.0f/255.0f; + for (i = 0; i < side; ++i) { + for (j = 0; j < side; ++j) { + const int col = texcache[i * side + j]; + im->rect_float[i * side + j] *= (((char *)&col)[0] + ((char *)&col)[1] + ((char *)&col)[2]) / 3.0f / 255.0f; } } diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index f0bc2dddbad..24583c124e6 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -101,11 +101,11 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f sub_v3_v3v3(e1, v2, v0); A00 = dot_v3v3(e0, e0); - A01 = dot_v3v3(e0, e1 ); - A11 = dot_v3v3(e1, e1 ); - B0 = dot_v3v3(diff, e0 ); - B1 = dot_v3v3(diff, e1 ); - C = dot_v3v3(diff, diff ); + A01 = dot_v3v3(e0, e1); + A11 = dot_v3v3(e1, e1); + B0 = dot_v3v3(diff, e0); + B1 = dot_v3v3(diff, e1); + C = dot_v3v3(diff, diff); Det = fabs(A00 * A11 - A01 * A01); S = A01 * B1 - A11 * B0; T = A01 * B0 - A00 * B1; @@ -122,7 +122,7 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f } else { if (fabsf(A00) > FLT_EPSILON) - S = -B0/A00; + S = -B0 / A00; else S = 0.0f; sqrDist = B0 * S + C; @@ -195,7 +195,7 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f } } else { /* Region 0 */ - // Minimum at interior lv + /* Minimum at interior lv */ float invDet; if (fabsf(Det) > FLT_EPSILON) invDet = 1.0f / Det; @@ -203,8 +203,8 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f invDet = 0.0f; S *= invDet; T *= invDet; - sqrDist = S * ( A00 * S + A01 * T + 2.0f * B0) + - T * ( A01 * S + A11 * T + 2.0f * B1 ) + C; + sqrDist = S * (A00 * S + A01 * T + 2.0f * B0) + + T * (A01 * S + A11 * T + 2.0f * B1) + C; } } else { @@ -213,10 +213,10 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f if (S < 0.0f) { /* Region 2 */ tmp0 = A01 + B0; tmp1 = A11 + B1; - if ( tmp1 > tmp0 ) { + if (tmp1 > tmp0) { numer = tmp1 - tmp0; denom = A00 - 2.0f * A01 + A11; - if ( numer >= denom ) { + if (numer >= denom) { S = 1.0f; T = 0.0f; sqrDist = A00 + 2.0f * B0 + C; @@ -228,14 +228,14 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f else S = 0.0f; T = 1.0f - S; - sqrDist = S * ( A00 * S + A01 * T + 2.0f * B0 ) + - T * ( A01 * S + A11 * T + 2.0f * B1 ) + C; + sqrDist = S * (A00 * S + A01 * T + 2.0f * B0) + + T * (A01 * S + A11 * T + 2.0f * B1) + C; le = 2; } } else { S = 0.0f; - if ( tmp1 <= 0.0f ) { + if (tmp1 <= 0.0f) { T = 1.0f; sqrDist = A11 + 2.0f * B1 + C; lv = 2; @@ -258,10 +258,10 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f else if (T < 0.0f) { /* Region 6 */ tmp0 = A01 + B1; tmp1 = A00 + B0; - if ( tmp1 > tmp0 ) { + if (tmp1 > tmp0) { numer = tmp1 - tmp0; denom = A00 - 2.0f * A01 + A11; - if ( numer >= denom ) { + if (numer >= denom) { T = 1.0f; S = 0.0f; sqrDist = A11 + 2.0f * B1 + C; @@ -273,8 +273,8 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f else T = 0.0f; S = 1.0f - T; - sqrDist = S * ( A00 * S + A01 * T + 2.0f * B0 ) + - T * ( A01 * S + A11 * T + 2.0f * B1 ) + C; + sqrDist = S * (A00 * S + A01 * T + 2.0f * B0) + + T * (A01 * S + A11 * T + 2.0f * B1) + C; le = 2; } } @@ -302,7 +302,7 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f } else { /* Region 1 */ numer = A11 + B1 - A01 - B0; - if ( numer <= 0.0f ) { + if (numer <= 0.0f) { S = 0.0f; T = 1.0f; sqrDist = A11 + 2.0f * B1 + C; @@ -310,7 +310,7 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f } else { denom = A00 - 2.0f * A01 + A11; - if ( numer >= denom ) { + if (numer >= denom) { S = 1.0f; T = 0.0f; sqrDist = A00 + 2.0f * B0 + C; @@ -322,8 +322,8 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f else S = 0.0f; T = 1.0f - S; - sqrDist = S * ( A00 * S + A01 * T + 2.0f * B0 ) + - T * ( A01 * S + A11 * T + 2.0f * B1 ) + C; + sqrDist = S * (A00 * S + A01 * T + 2.0f * B0) + + T * (A01 * S + A11 * T + 2.0f * B1) + C; le = 2; } } @@ -331,7 +331,7 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f } // Account for numerical round-off error - if ( sqrDist < FLT_EPSILON ) + if (sqrDist < FLT_EPSILON) sqrDist = 0.0f; { @@ -362,19 +362,18 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f // userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree. static void mesh_faces_nearest_point(void *userdata, int index, const float co[3], BVHTreeNearest *nearest) { - const BVHTreeFromMesh *data = (BVHTreeFromMesh*) userdata; - MVert *vert = data->vert; + const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata; + MVert *vert = data->vert; MFace *face = data->face + index; float *t0, *t1, *t2, *t3; - t0 = vert[ face->v1 ].co; - t1 = vert[ face->v2 ].co; - t2 = vert[ face->v3 ].co; - t3 = face->v4 ? vert[ face->v4].co : NULL; + t0 = vert[face->v1].co; + t1 = vert[face->v2].co; + t2 = vert[face->v3].co; + t3 = face->v4 ? vert[face->v4].co : NULL; - do - { + do { float nearest_tmp[3], dist; int vertex, edge; @@ -397,8 +396,8 @@ static void mesh_faces_nearest_point(void *userdata, int index, const float co[3 // userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree. static void mesh_faces_spherecast(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit) { - const BVHTreeFromMesh *data = (BVHTreeFromMesh*) userdata; - MVert *vert = data->vert; + const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata; + MVert *vert = data->vert; MFace *face = data->face + index; float *t0, *t1, *t2, *t3; @@ -408,8 +407,7 @@ static void mesh_faces_spherecast(void *userdata, int index, const BVHTreeRay *r t3 = face->v4 ? vert[face->v4].co : NULL; - do - { + do { float dist; if (data->sphere_radius == 0.0f) dist = bvhtree_ray_tri_intersection(ray, hit->dist, t0, t1, t2); @@ -435,14 +433,14 @@ static void mesh_faces_spherecast(void *userdata, int index, const BVHTreeRay *r // userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree. static void mesh_edges_nearest_point(void *userdata, int index, const float co[3], BVHTreeNearest *nearest) { - const BVHTreeFromMesh *data = (BVHTreeFromMesh*) userdata; - MVert *vert = data->vert; + const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata; + MVert *vert = data->vert; MEdge *edge = data->edge + index; float nearest_tmp[3], dist; float *t0, *t1; - t0 = vert[ edge->v1 ].co; - t1 = vert[ edge->v2 ].co; + t0 = vert[edge->v1].co; + t1 = vert[edge->v2].co; closest_to_line_segment_v3(nearest_tmp, co, t0, t1); dist = len_squared_v3v3(nearest_tmp, co); @@ -460,15 +458,15 @@ static void mesh_edges_nearest_point(void *userdata, int index, const float co[3 * BVH builders */ // Builds a bvh tree.. where nodes are the vertexs of the given mesh -BVHTree* bvhtree_from_mesh_verts(BVHTreeFromMesh *data, DerivedMesh *mesh, float epsilon, int tree_type, int axis) +BVHTree *bvhtree_from_mesh_verts(BVHTreeFromMesh *data, DerivedMesh *mesh, float epsilon, int tree_type, int axis) { BVHTree *tree = bvhcache_find(&mesh->bvhCache, BVHTREE_FROM_VERTICES); //Not in cache if (tree == NULL) { int i; - int numVerts= mesh->getNumVerts(mesh); - MVert *vert = mesh->getVertDataArray(mesh, CD_MVERT); + int numVerts = mesh->getNumVerts(mesh); + MVert *vert = mesh->getVertDataArray(mesh, CD_MVERT); if (vert != NULL) { tree = BLI_bvhtree_new(numVerts, epsilon, tree_type, axis); @@ -514,14 +512,14 @@ BVHTree* bvhtree_from_mesh_verts(BVHTreeFromMesh *data, DerivedMesh *mesh, float } // Builds a bvh tree.. where nodes are the faces of the given mesh. -BVHTree* bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *mesh, float epsilon, int tree_type, int axis) +BVHTree *bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *mesh, float epsilon, int tree_type, int axis) { BVHTree *tree = bvhcache_find(&mesh->bvhCache, BVHTREE_FROM_FACES); //Not in cache if (tree == NULL) { int i; - int numFaces= mesh->getNumTessFaces(mesh); + int numFaces = mesh->getNumTessFaces(mesh); /* BMESH specific check that we have tessfaces, * we _could_ tessellate here but rather not - campbell @@ -534,7 +532,7 @@ BVHTree* bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *mesh, float /* Create a bvh-tree of the given target */ tree = BLI_bvhtree_new(numFaces, epsilon, tree_type, axis); if (tree != NULL) { - BMEditMesh *em= data->em_evil; + BMEditMesh *em = data->em_evil; if (em) { /* data->em_evil is only set for snapping, and only for the mesh of the object * which is currently open in edit mode. When set, the bvhtree should not contain @@ -594,17 +592,17 @@ BVHTree* bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *mesh, float } } else { - MVert *vert = mesh->getVertDataArray(mesh, CD_MVERT); + MVert *vert = mesh->getVertDataArray(mesh, CD_MVERT); MFace *face = mesh->getTessFaceDataArray(mesh, CD_MFACE); if (vert != NULL && face != NULL) { for (i = 0; i < numFaces; i++) { float co[4][3]; - copy_v3_v3(co[0], vert[ face[i].v1 ].co); - copy_v3_v3(co[1], vert[ face[i].v2 ].co); - copy_v3_v3(co[2], vert[ face[i].v3 ].co); + copy_v3_v3(co[0], vert[face[i].v1].co); + copy_v3_v3(co[1], vert[face[i].v2].co); + copy_v3_v3(co[2], vert[face[i].v3].co); if (face[i].v4) - copy_v3_v3(co[3], vert[ face[i].v4 ].co); + copy_v3_v3(co[3], vert[face[i].v4].co); BLI_bvhtree_insert(tree, i, co[0], face[i].v4 ? 4 : 3); } @@ -644,15 +642,15 @@ BVHTree* bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *mesh, float } // Builds a bvh tree.. where nodes are the faces of the given mesh. -BVHTree* bvhtree_from_mesh_edges(BVHTreeFromMesh *data, DerivedMesh *mesh, float epsilon, int tree_type, int axis) +BVHTree *bvhtree_from_mesh_edges(BVHTreeFromMesh *data, DerivedMesh *mesh, float epsilon, int tree_type, int axis) { BVHTree *tree = bvhcache_find(&mesh->bvhCache, BVHTREE_FROM_EDGES); //Not in cache if (tree == NULL) { int i; - int numEdges= mesh->getNumEdges(mesh); - MVert *vert = mesh->getVertDataArray(mesh, CD_MVERT); + int numEdges = mesh->getNumEdges(mesh); + MVert *vert = mesh->getVertDataArray(mesh, CD_MVERT); MEdge *edge = mesh->getEdgeDataArray(mesh, CD_MEDGE); if (vert != NULL && edge != NULL) { @@ -661,8 +659,8 @@ BVHTree* bvhtree_from_mesh_edges(BVHTreeFromMesh *data, DerivedMesh *mesh, float if (tree != NULL) { for (i = 0; i < numEdges; i++) { float co[4][3]; - copy_v3_v3(co[0], vert[ edge[i].v1 ].co); - copy_v3_v3(co[1], vert[ edge[i].v2 ].co); + copy_v3_v3(co[0], vert[edge[i].v1].co); + copy_v3_v3(co[1], vert[edge[i].v2].co); BLI_bvhtree_insert(tree, i, co[0], 2); } @@ -712,8 +710,7 @@ void free_bvhtree_from_mesh(struct BVHTreeFromMesh *data) /* BVHCache */ -typedef struct BVHCacheItem -{ +typedef struct BVHCacheItem { int type; BVHTree *tree; @@ -721,8 +718,8 @@ typedef struct BVHCacheItem static void bvhcacheitem_set_if_match(void *_cached, void *_search) { - BVHCacheItem * cached = (BVHCacheItem *)_cached; - BVHCacheItem * search = (BVHCacheItem *)_search; + BVHCacheItem *cached = (BVHCacheItem *)_cached; + BVHCacheItem *search = (BVHCacheItem *)_search; if (search->type == cached->type) { search->tree = cached->tree; diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index 11c628e7848..e1cfcee1367 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -54,15 +54,15 @@ void *BKE_camera_add(const char *name) { Camera *cam; - cam= alloc_libblock(&G.main->camera, ID_CA, name); - - cam->lens= 35.0f; - cam->sensor_x= 32.0f; - cam->sensor_y= 18.0f; - cam->clipsta= 0.1f; - cam->clipend= 100.0f; - cam->drawsize= 0.5f; - cam->ortho_scale= 6.0; + cam = BKE_libblock_alloc(&G.main->camera, ID_CA, name); + + cam->lens = 35.0f; + cam->sensor_x = 32.0f; + cam->sensor_y = 18.0f; + cam->clipsta = 0.1f; + cam->clipend = 100.0f; + cam->drawsize = 0.5f; + cam->ortho_scale = 6.0; cam->flag |= CAM_SHOWPASSEPARTOUT; cam->passepartalpha = 0.5f; @@ -73,7 +73,7 @@ Camera *BKE_camera_copy(Camera *cam) { Camera *camn; - camn= copy_libblock(&cam->id); + camn = BKE_libblock_copy(&cam->id); id_lib_extern((ID *)camn->dof_ob); @@ -82,25 +82,25 @@ Camera *BKE_camera_copy(Camera *cam) void BKE_camera_make_local(Camera *cam) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (cam->id.lib==NULL) return; - if (cam->id.us==1) { + if (cam->id.lib == NULL) return; + if (cam->id.us == 1) { id_clear_lib_data(bmain, &cam->id); return; } - for (ob= bmain->object.first; ob && ELEM(0, is_lib, is_local); ob= ob->id.next) { - if (ob->data==cam) { - if (ob->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (ob = bmain->object.first; ob && ELEM(0, is_lib, is_local); ob = ob->id.next) { + if (ob->data == cam) { + if (ob->id.lib) is_lib = TRUE; + else is_local = TRUE; } } @@ -108,17 +108,17 @@ void BKE_camera_make_local(Camera *cam) id_clear_lib_data(bmain, &cam->id); } else if (is_local && is_lib) { - Camera *cam_new= BKE_camera_copy(cam); + Camera *cam_new = BKE_camera_copy(cam); - cam_new->id.us= 0; + cam_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, cam->id.lib, &cam_new->id); - for (ob= bmain->object.first; ob; ob= ob->id.next) { + for (ob = bmain->object.first; ob; ob = ob->id.next) { if (ob->data == cam) { - if (ob->id.lib==NULL) { - ob->data= cam_new; + if (ob->id.lib == NULL) { + ob->data = cam_new; cam_new->id.us++; cam->id.us--; } @@ -136,10 +136,10 @@ void BKE_camera_free(Camera *ca) void BKE_camera_object_mode(RenderData *rd, Object *cam_ob) { - rd->mode &= ~(R_ORTHO|R_PANORAMA); + rd->mode &= ~(R_ORTHO | R_PANORAMA); - if (cam_ob && cam_ob->type==OB_CAMERA) { - Camera *cam= cam_ob->data; + if (cam_ob && cam_ob->type == OB_CAMERA) { + Camera *cam = cam_ob->data; if (cam->type == CAM_ORTHO) rd->mode |= R_ORTHO; if (cam->type == CAM_PANO) rd->mode |= R_PANORAMA; } @@ -193,11 +193,11 @@ void BKE_camera_params_init(CameraParams *params) memset(params, 0, sizeof(CameraParams)); /* defaults */ - params->sensor_x= DEFAULT_SENSOR_WIDTH; - params->sensor_y= DEFAULT_SENSOR_HEIGHT; - params->sensor_fit= CAMERA_SENSOR_FIT_AUTO; + params->sensor_x = DEFAULT_SENSOR_WIDTH; + params->sensor_y = DEFAULT_SENSOR_HEIGHT; + params->sensor_fit = CAMERA_SENSOR_FIT_AUTO; - params->zoom= 1.0f; + params->zoom = 1.0f; } void BKE_camera_params_from_object(CameraParams *params, Object *ob) @@ -205,73 +205,73 @@ void BKE_camera_params_from_object(CameraParams *params, Object *ob) if (!ob) return; - if (ob->type==OB_CAMERA) { + if (ob->type == OB_CAMERA) { /* camera object */ - Camera *cam= ob->data; + Camera *cam = ob->data; if (cam->type == CAM_ORTHO) - params->is_ortho= TRUE; - params->lens= cam->lens; - params->ortho_scale= cam->ortho_scale; + params->is_ortho = TRUE; + params->lens = cam->lens; + params->ortho_scale = cam->ortho_scale; - params->shiftx= cam->shiftx; - params->shifty= cam->shifty; + params->shiftx = cam->shiftx; + params->shifty = cam->shifty; - params->sensor_x= cam->sensor_x; - params->sensor_y= cam->sensor_y; - params->sensor_fit= cam->sensor_fit; + params->sensor_x = cam->sensor_x; + params->sensor_y = cam->sensor_y; + params->sensor_fit = cam->sensor_fit; - params->clipsta= cam->clipsta; - params->clipend= cam->clipend; + params->clipsta = cam->clipsta; + params->clipend = cam->clipend; } - else if (ob->type==OB_LAMP) { + else if (ob->type == OB_LAMP) { /* lamp object */ - Lamp *la= ob->data; - float fac= cosf((float)M_PI*la->spotsize/360.0f); - float phi= acos(fac); + Lamp *la = ob->data; + float fac = cosf((float)M_PI * la->spotsize / 360.0f); + float phi = acos(fac); - params->lens= 16.0f*fac/sinf(phi); - if (params->lens==0.0f) - params->lens= 35.0f; + params->lens = 16.0f * fac / sinf(phi); + if (params->lens == 0.0f) + params->lens = 35.0f; - params->clipsta= la->clipsta; - params->clipend= la->clipend; + params->clipsta = la->clipsta; + params->clipend = la->clipend; } } void BKE_camera_params_from_view3d(CameraParams *params, View3D *v3d, RegionView3D *rv3d) { /* common */ - params->lens= v3d->lens; - params->clipsta= v3d->near; - params->clipend= v3d->far; + params->lens = v3d->lens; + params->clipsta = v3d->near; + params->clipend = v3d->far; - if (rv3d->persp==RV3D_CAMOB) { + if (rv3d->persp == RV3D_CAMOB) { /* camera view */ BKE_camera_params_from_object(params, v3d->camera); - params->zoom= BKE_screen_view3d_zoom_to_fac((float)rv3d->camzoom); + params->zoom = BKE_screen_view3d_zoom_to_fac((float)rv3d->camzoom); - params->offsetx= 2.0f*rv3d->camdx*params->zoom; - params->offsety= 2.0f*rv3d->camdy*params->zoom; + params->offsetx = 2.0f * rv3d->camdx * params->zoom; + params->offsety = 2.0f * rv3d->camdy * params->zoom; params->shiftx *= params->zoom; params->shifty *= params->zoom; - params->zoom= 1.0f/params->zoom; + params->zoom = 1.0f / params->zoom; } - else if (rv3d->persp==RV3D_ORTHO) { + else if (rv3d->persp == RV3D_ORTHO) { /* orthographic view */ - params->clipend *= 0.5f; // otherwise too extreme low zbuffer quality - params->clipsta= - params->clipend; + params->clipend *= 0.5f; // otherwise too extreme low zbuffer quality + params->clipsta = -params->clipend; - params->is_ortho= TRUE; + params->is_ortho = TRUE; params->ortho_scale = rv3d->dist; - params->zoom= 2.0f; + params->zoom = 2.0f; } else { /* perspective view */ - params->zoom= 2.0f; + params->zoom = 2.0f; } } @@ -282,28 +282,28 @@ void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int win int sensor_fit; /* fields rendering */ - params->ycor= yasp/xasp; + params->ycor = yasp / xasp; if (params->use_fields) params->ycor *= 2.0f; if (params->is_ortho) { /* orthographic camera */ /* scale == 1.0 means exact 1 to 1 mapping */ - pixsize= params->ortho_scale; + pixsize = params->ortho_scale; } else { /* perspective camera */ - sensor_size= BKE_camera_sensor_size(params->sensor_fit, params->sensor_x, params->sensor_y); - pixsize= (sensor_size * params->clipsta)/params->lens; + sensor_size = BKE_camera_sensor_size(params->sensor_fit, params->sensor_x, params->sensor_y); + pixsize = (sensor_size * params->clipsta) / params->lens; } /* determine sensor fit */ - sensor_fit = BKE_camera_sensor_fit(params->sensor_fit, xasp*winx, yasp*winy); + sensor_fit = BKE_camera_sensor_fit(params->sensor_fit, xasp * winx, yasp * winy); - if (sensor_fit==CAMERA_SENSOR_FIT_HOR) - viewfac= winx; + if (sensor_fit == CAMERA_SENSOR_FIT_HOR) + viewfac = winx; else - viewfac= params->ycor * winy; + viewfac = params->ycor * winy; pixsize /= viewfac; @@ -312,14 +312,14 @@ void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int win /* compute view plane: * fully centered, zbuffer fills in jittered between -.5 and +.5 */ - viewplane.xmin = -0.5f*(float)winx; - viewplane.ymin = -0.5f*params->ycor*(float)winy; - viewplane.xmax = 0.5f*(float)winx; - viewplane.ymax = 0.5f*params->ycor*(float)winy; + viewplane.xmin = -0.5f * (float)winx; + viewplane.ymin = -0.5f * params->ycor * (float)winy; + viewplane.xmax = 0.5f * (float)winx; + viewplane.ymax = 0.5f * params->ycor * (float)winy; /* lens shift and offset */ - dx= params->shiftx*viewfac + winx*params->offsetx; - dy= params->shifty*viewfac + winy*params->offsety; + dx = params->shiftx * viewfac + winx * params->offsetx; + dy = params->shifty * viewfac + winy * params->offsety; viewplane.xmin += dx; viewplane.ymin += dy; @@ -329,12 +329,12 @@ void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int win /* fields offset */ if (params->field_second) { if (params->field_odd) { - viewplane.ymin-= 0.5f * params->ycor; - viewplane.ymax-= 0.5f * params->ycor; + viewplane.ymin -= 0.5f * params->ycor; + viewplane.ymax -= 0.5f * params->ycor; } else { - viewplane.ymin+= 0.5f * params->ycor; - viewplane.ymax+= 0.5f * params->ycor; + viewplane.ymin += 0.5f * params->ycor; + viewplane.ymax += 0.5f * params->ycor; } } @@ -345,9 +345,9 @@ void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int win viewplane.ymin *= pixsize; viewplane.ymax *= pixsize; - params->viewdx= pixsize; - params->viewdy= params->ycor * pixsize; - params->viewplane= viewplane; + params->viewdx = pixsize; + params->viewdy = params->ycor * pixsize; + params->viewplane = viewplane; } /* viewplane is assumed to be already computed */ @@ -374,61 +374,61 @@ void BKE_camera_view_frame_ex(Scene *scene, Camera *camera, float drawsize, cons /* aspect correcton */ if (scene) { - float aspx= (float) scene->r.xsch*scene->r.xasp; - float aspy= (float) scene->r.ysch*scene->r.yasp; - int sensor_fit= BKE_camera_sensor_fit(camera->sensor_fit, aspx, aspy); + float aspx = (float) scene->r.xsch * scene->r.xasp; + float aspy = (float) scene->r.ysch * scene->r.yasp; + int sensor_fit = BKE_camera_sensor_fit(camera->sensor_fit, aspx, aspy); - if (sensor_fit==CAMERA_SENSOR_FIT_HOR) { - r_asp[0]= 1.0; - r_asp[1]= aspy / aspx; + if (sensor_fit == CAMERA_SENSOR_FIT_HOR) { + r_asp[0] = 1.0; + r_asp[1] = aspy / aspx; } else { - r_asp[0]= aspx / aspy; - r_asp[1]= 1.0; + r_asp[0] = aspx / aspy; + r_asp[1] = 1.0; } } else { - r_asp[0]= 1.0f; - r_asp[1]= 1.0f; + r_asp[0] = 1.0f; + r_asp[1] = 1.0f; } - if (camera->type==CAM_ORTHO) { - facx= 0.5f * camera->ortho_scale * r_asp[0] * scale[0]; - facy= 0.5f * camera->ortho_scale * r_asp[1] * scale[1]; - r_shift[0]= camera->shiftx * camera->ortho_scale * scale[0]; - r_shift[1]= camera->shifty * camera->ortho_scale * scale[1]; - depth= do_clip ? -((camera->clipsta * scale[2]) + 0.1f) : - drawsize * camera->ortho_scale * scale[2]; + if (camera->type == CAM_ORTHO) { + facx = 0.5f * camera->ortho_scale * r_asp[0] * scale[0]; + facy = 0.5f * camera->ortho_scale * r_asp[1] * scale[1]; + r_shift[0] = camera->shiftx * camera->ortho_scale * scale[0]; + r_shift[1] = camera->shifty * camera->ortho_scale * scale[1]; + depth = do_clip ? -((camera->clipsta * scale[2]) + 0.1f) : -drawsize * camera->ortho_scale * scale[2]; - *r_drawsize= 0.5f * camera->ortho_scale; + *r_drawsize = 0.5f * camera->ortho_scale; } else { /* that way it's always visible - clipsta+0.1 */ float fac; - float half_sensor= 0.5f*((camera->sensor_fit==CAMERA_SENSOR_FIT_VERT) ? (camera->sensor_y) : (camera->sensor_x)); + float half_sensor = 0.5f * ((camera->sensor_fit == CAMERA_SENSOR_FIT_VERT) ? (camera->sensor_y) : (camera->sensor_x)); - *r_drawsize= drawsize / ((scale[0] + scale[1] + scale[2]) / 3.0f); + *r_drawsize = drawsize / ((scale[0] + scale[1] + scale[2]) / 3.0f); if (do_clip) { /* fixed depth, variable size (avoids exceeding clipping range) */ depth = -(camera->clipsta + 0.1f); - fac = depth / (camera->lens/(-half_sensor) * scale[2]); + fac = depth / (camera->lens / (-half_sensor) * scale[2]); } else { /* fixed size, variable depth (stays a reasonable size in the 3D view) */ - depth= *r_drawsize * camera->lens/(-half_sensor) * scale[2]; - fac= *r_drawsize; + depth = *r_drawsize * camera->lens / (-half_sensor) * scale[2]; + fac = *r_drawsize; } - facx= fac * r_asp[0] * scale[0]; - facy= fac * r_asp[1] * scale[1]; - r_shift[0]= camera->shiftx*fac*2 * scale[0]; - r_shift[1]= camera->shifty*fac*2 * scale[1]; + facx = fac * r_asp[0] * scale[0]; + facy = fac * r_asp[1] * scale[1]; + r_shift[0] = camera->shiftx * fac * 2 * scale[0]; + r_shift[1] = camera->shifty * fac * 2 * scale[1]; } - r_vec[0][0]= r_shift[0] + facx; r_vec[0][1]= r_shift[1] + facy; r_vec[0][2]= depth; - r_vec[1][0]= r_shift[0] + facx; r_vec[1][1]= r_shift[1] - facy; r_vec[1][2]= depth; - r_vec[2][0]= r_shift[0] - facx; r_vec[2][1]= r_shift[1] - facy; r_vec[2][2]= depth; - r_vec[3][0]= r_shift[0] - facx; r_vec[3][1]= r_shift[1] + facy; r_vec[3][2]= depth; + r_vec[0][0] = r_shift[0] + facx; r_vec[0][1] = r_shift[1] + facy; r_vec[0][2] = depth; + r_vec[1][0] = r_shift[0] + facx; r_vec[1][1] = r_shift[1] - facy; r_vec[1][2] = depth; + r_vec[2][0] = r_shift[0] - facx; r_vec[2][1] = r_shift[1] - facy; r_vec[2][2] = depth; + r_vec[3][0] = r_shift[0] - facx; r_vec[3][1] = r_shift[1] + facy; r_vec[3][2] = depth; } void BKE_camera_view_frame(Scene *scene, Camera *camera, float r_vec[4][3]) @@ -436,10 +436,10 @@ void BKE_camera_view_frame(Scene *scene, Camera *camera, float r_vec[4][3]) float dummy_asp[2]; float dummy_shift[2]; float dummy_drawsize; - const float dummy_scale[3]= {1.0f, 1.0f, 1.0f}; + const float dummy_scale[3] = {1.0f, 1.0f, 1.0f}; BKE_camera_view_frame_ex(scene, camera, FALSE, 1.0, dummy_scale, - dummy_asp, dummy_shift, &dummy_drawsize, r_vec); + dummy_asp, dummy_shift, &dummy_drawsize, r_vec); } @@ -452,13 +452,13 @@ typedef struct CameraViewFrameData { static void BKE_camera_to_frame_view_cb(const float co[3], void *user_data) { - CameraViewFrameData *data= (CameraViewFrameData *)user_data; + CameraViewFrameData *data = (CameraViewFrameData *)user_data; unsigned int i; - for (i= 0; i < 4; i++) { - float nd= dist_to_plane_v3(co, data->frame_tx[i], data->normal_tx[i]); + for (i = 0; i < 4; i++) { + float nd = dist_to_plane_v3(co, data->frame_tx[i], data->normal_tx[i]); if (nd < data->dist_vals[i]) { - data->dist_vals[i]= nd; + data->dist_vals[i] = nd; } } @@ -472,7 +472,7 @@ int BKE_camera_view_frame_fit_to_scene(Scene *scene, struct View3D *v3d, Object float shift[2]; float plane_tx[4][3]; float rot_obmat[3][3]; - const float zero[3]= {0, 0, 0}; + const float zero[3] = {0, 0, 0}; CameraViewFrameData data_cb; unsigned int i; @@ -482,36 +482,36 @@ int BKE_camera_view_frame_fit_to_scene(Scene *scene, struct View3D *v3d, Object copy_m3_m4(rot_obmat, camera_ob->obmat); normalize_m3(rot_obmat); - for (i= 0; i < 4; i++) { + for (i = 0; i < 4; i++) { /* normalize so Z is always 1.0f*/ - mul_v3_fl(data_cb.frame_tx[i], 1.0f/data_cb.frame_tx[i][2]); + mul_v3_fl(data_cb.frame_tx[i], 1.0f / data_cb.frame_tx[i][2]); } /* get the shift back out of the frame */ - shift[0]= (data_cb.frame_tx[0][0] + - data_cb.frame_tx[1][0] + - data_cb.frame_tx[2][0] + - data_cb.frame_tx[3][0]) / 4.0f; - shift[1]= (data_cb.frame_tx[0][1] + - data_cb.frame_tx[1][1] + - data_cb.frame_tx[2][1] + - data_cb.frame_tx[3][1]) / 4.0f; - - for (i= 0; i < 4; i++) { + shift[0] = (data_cb.frame_tx[0][0] + + data_cb.frame_tx[1][0] + + data_cb.frame_tx[2][0] + + data_cb.frame_tx[3][0]) / 4.0f; + shift[1] = (data_cb.frame_tx[0][1] + + data_cb.frame_tx[1][1] + + data_cb.frame_tx[2][1] + + data_cb.frame_tx[3][1]) / 4.0f; + + for (i = 0; i < 4; i++) { mul_m3_v3(rot_obmat, data_cb.frame_tx[i]); } - for (i= 0; i < 4; i++) { + for (i = 0; i < 4; i++) { normal_tri_v3(data_cb.normal_tx[i], zero, data_cb.frame_tx[i], data_cb.frame_tx[(i + 1) % 4]); } /* initialize callback data */ - data_cb.dist_vals[0]= - data_cb.dist_vals[1]= - data_cb.dist_vals[2]= - data_cb.dist_vals[3]= FLT_MAX; - data_cb.tot= 0; + data_cb.dist_vals[0] = + data_cb.dist_vals[1] = + data_cb.dist_vals[2] = + data_cb.dist_vals[3] = FLT_MAX; + data_cb.tot = 0; /* run callback on all visible points */ BKE_scene_foreach_display_point(scene, v3d, BA_SELECT, BKE_camera_to_frame_view_cb, &data_cb); @@ -526,7 +526,7 @@ int BKE_camera_view_frame_fit_to_scene(Scene *scene, struct View3D *v3d, Object float plane_isect_pt_1[3], plane_isect_pt_2[3]; /* apply the dist-from-plane's to the transformed plane points */ - for (i= 0; i < 4; i++) { + for (i = 0; i < 4; i++) { mul_v3_v3fl(plane_tx[i], data_cb.normal_tx[i], data_cb.dist_vals[i]); } @@ -547,14 +547,14 @@ int BKE_camera_view_frame_fit_to_scene(Scene *scene, struct View3D *v3d, Object return FALSE; } else { - float cam_plane_no[3]= {0.0f, 0.0f, -1.0f}; + float cam_plane_no[3] = {0.0f, 0.0f, -1.0f}; float plane_isect_delta[3]; float plane_isect_delta_len; mul_m3_v3(rot_obmat, cam_plane_no); sub_v3_v3v3(plane_isect_delta, plane_isect_pt_2, plane_isect_pt_1); - plane_isect_delta_len= len_v3(plane_isect_delta); + plane_isect_delta_len = len_v3(plane_isect_delta); if (dot_v3v3(plane_isect_delta, cam_plane_no) > 0.0f) { copy_v3_v3(r_co, plane_isect_pt_1); diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 78a8b975b85..3ef2ce56cd6 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -1,4 +1,4 @@ - /* +/* * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or @@ -172,7 +172,7 @@ static void cdDM_copyPolyArray(DerivedMesh *dm, MPoly *poly_r) static void cdDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3]) { - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + CDDerivedMesh *cddm = (CDDerivedMesh *) dm; int i; if (dm->numVertData) { @@ -188,7 +188,7 @@ static void cdDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3]) static void cdDM_getVertCo(DerivedMesh *dm, int index, float co_r[3]) { - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + CDDerivedMesh *cddm = (CDDerivedMesh *) dm; copy_v3_v3(co_r, cddm->mvert[index].co); } @@ -204,16 +204,16 @@ static void cdDM_getVertCos(DerivedMesh *dm, float (*cos_r)[3]) static void cdDM_getVertNo(DerivedMesh *dm, int index, float no_r[3]) { - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + CDDerivedMesh *cddm = (CDDerivedMesh *) dm; normal_short_to_float_v3(no_r, cddm->mvert[index].no); } static const MeshElemMap *cdDM_getPolyMap(Object *ob, DerivedMesh *dm) { - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + CDDerivedMesh *cddm = (CDDerivedMesh *) dm; if (!cddm->pmap && ob->type == OB_MESH) { - Mesh *me= ob->data; + Mesh *me = ob->data; create_vert_poly_map(&cddm->pmap, &cddm->pmap_mem, me->mpoly, me->mloop, @@ -225,7 +225,7 @@ static const MeshElemMap *cdDM_getPolyMap(Object *ob, DerivedMesh *dm) static int can_pbvh_draw(Object *ob, DerivedMesh *dm) { - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + CDDerivedMesh *cddm = (CDDerivedMesh *) dm; Mesh *me = ob->data; int deformed = 0; @@ -245,12 +245,12 @@ static int can_pbvh_draw(Object *ob, DerivedMesh *dm) return cddm->mvert == me->mvert || ob->sculpt->kb; } -static struct PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm) +static PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm) { - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + CDDerivedMesh *cddm = (CDDerivedMesh *) dm; if (!ob) { - cddm->pbvh= NULL; + cddm->pbvh = NULL; return NULL; } @@ -258,7 +258,7 @@ static struct PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm) return NULL; if (ob->sculpt->pbvh) { - cddm->pbvh= ob->sculpt->pbvh; + cddm->pbvh = ob->sculpt->pbvh; cddm->pbvh_draw = can_pbvh_draw(ob, dm); } @@ -276,7 +276,7 @@ static struct PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm) BKE_mesh_tessface_ensure(me); BLI_pbvh_build_mesh(cddm->pbvh, me->mface, me->mvert, - me->totface, me->totvert); + me->totface, me->totvert, &me->vdata); deformed = ss->modifiers_active || me->key; @@ -286,7 +286,7 @@ static struct PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm) int totvert; totvert = deformdm->getNumVerts(deformdm); - vertCos = MEM_callocN(3*totvert*sizeof(float), "cdDM_getPBVH vertCos"); + vertCos = MEM_callocN(3 * totvert * sizeof(float), "cdDM_getPBVH vertCos"); deformdm->getVertCos(deformdm, vertCos); BLI_pbvh_apply_vertCos(cddm->pbvh, vertCos); MEM_freeN(vertCos); @@ -300,7 +300,7 @@ static struct PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm) * TODO: proper fix is to support the pbvh in all drawing modes */ static void cdDM_update_normals_from_pbvh(DerivedMesh *dm) { - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + CDDerivedMesh *cddm = (CDDerivedMesh *) dm; float (*face_nors)[3]; if (!cddm->pbvh || !cddm->pbvh_draw || !dm->numTessFaceData) @@ -313,7 +313,7 @@ static void cdDM_update_normals_from_pbvh(DerivedMesh *dm) static void cdDM_drawVerts(DerivedMesh *dm) { - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + CDDerivedMesh *cddm = (CDDerivedMesh *) dm; MVert *mv = cddm->mvert; int i; @@ -323,7 +323,7 @@ static void cdDM_drawVerts(DerivedMesh *dm) glVertex3fv(mv->co); glEnd(); } - else { /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */ + else { /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */ GPU_vertex_setup(dm); if (!GPU_buffer_legacy(dm)) { if (dm->drawObject->tot_triangle_point) @@ -337,7 +337,7 @@ static void cdDM_drawVerts(DerivedMesh *dm) static void cdDM_drawUVEdges(DerivedMesh *dm) { - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + CDDerivedMesh *cddm = (CDDerivedMesh *) dm; MFace *mf = cddm->mface; MTFace *tf = DM_get_tessface_data_layer(dm, CD_MTFACE); int i; @@ -346,7 +346,7 @@ static void cdDM_drawUVEdges(DerivedMesh *dm) if (GPU_buffer_legacy(dm)) { glBegin(GL_LINES); for (i = 0; i < dm->numTessFaceData; i++, mf++, tf++) { - if (!(mf->flag&ME_HIDE)) { + if (!(mf->flag & ME_HIDE)) { glVertex2fv(tf->uv[0]); glVertex2fv(tf->uv[1]); @@ -377,19 +377,19 @@ static void cdDM_drawUVEdges(DerivedMesh *dm) GPU_uvedge_setup(dm); if (!GPU_buffer_legacy(dm)) { for (i = 0; i < dm->numTessFaceData; i++, mf++) { - if (!(mf->flag&ME_HIDE)) { + if (!(mf->flag & ME_HIDE)) { draw = 1; } else { draw = 0; } - if ( prevdraw != draw ) { - if ( prevdraw > 0 && (curpos-prevstart) > 0) { - glDrawArrays(GL_LINES, prevstart, curpos-prevstart); + if (prevdraw != draw) { + if (prevdraw > 0 && (curpos - prevstart) > 0) { + glDrawArrays(GL_LINES, prevstart, curpos - prevstart); } prevstart = curpos; } - if ( mf->v4 ) { + if (mf->v4) { curpos += 8; } else { @@ -397,8 +397,8 @@ static void cdDM_drawUVEdges(DerivedMesh *dm) } prevdraw = draw; } - if ( prevdraw > 0 && (curpos-prevstart) > 0 ) { - glDrawArrays(GL_LINES, prevstart, curpos-prevstart); + if (prevdraw > 0 && (curpos - prevstart) > 0) { + glDrawArrays(GL_LINES, prevstart, curpos - prevstart); } } GPU_buffer_unbind(); @@ -408,7 +408,7 @@ static void cdDM_drawUVEdges(DerivedMesh *dm) static void cdDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int drawAllEdges) { - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + CDDerivedMesh *cddm = (CDDerivedMesh *) dm; MVert *mvert = cddm->mvert; MEdge *medge = cddm->medge; int i; @@ -426,7 +426,7 @@ static void cdDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int drawAllEdges } glEnd(); } - else { /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */ + else { /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */ int prevstart = 0; int prevdraw = 1; int draw = TRUE; @@ -442,16 +442,16 @@ static void cdDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int drawAllEdges else { draw = FALSE; } - if ( prevdraw != draw ) { - if ( prevdraw > 0 && (i-prevstart) > 0 ) { + if (prevdraw != draw) { + if (prevdraw > 0 && (i - prevstart) > 0) { GPU_buffer_draw_elements(dm->drawObject->edges, GL_LINES, prevstart * 2, (i - prevstart) * 2); } prevstart = i; } prevdraw = draw; } - if ( prevdraw > 0 && (i-prevstart) > 0 ) { - GPU_buffer_draw_elements(dm->drawObject->edges, GL_LINES, prevstart * 2, (i-prevstart) * 2); + if (prevdraw > 0 && (i - prevstart) > 0) { + GPU_buffer_draw_elements(dm->drawObject->edges, GL_LINES, prevstart * 2, (i - prevstart) * 2); } } GPU_buffer_unbind(); @@ -460,7 +460,7 @@ static void cdDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int drawAllEdges static void cdDM_drawLooseEdges(DerivedMesh *dm) { - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + CDDerivedMesh *cddm = (CDDerivedMesh *) dm; MVert *mvert = cddm->mvert; MEdge *medge = cddm->medge; int i; @@ -469,14 +469,14 @@ static void cdDM_drawLooseEdges(DerivedMesh *dm) DEBUG_VBO("Using legacy code. cdDM_drawLooseEdges\n"); glBegin(GL_LINES); for (i = 0; i < dm->numEdgeData; i++, medge++) { - if (medge->flag&ME_LOOSEEDGE) { + if (medge->flag & ME_LOOSEEDGE) { glVertex3fv(mvert[medge->v1].co); glVertex3fv(mvert[medge->v2].co); } } glEnd(); } - else { /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */ + else { /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */ int prevstart = 0; int prevdraw = 1; int draw = 1; @@ -484,21 +484,21 @@ static void cdDM_drawLooseEdges(DerivedMesh *dm) GPU_edge_setup(dm); if (!GPU_buffer_legacy(dm)) { for (i = 0; i < dm->numEdgeData; i++, medge++) { - if (medge->flag&ME_LOOSEEDGE) { + if (medge->flag & ME_LOOSEEDGE) { draw = 1; } else { draw = 0; } - if ( prevdraw != draw ) { - if ( prevdraw > 0 && (i-prevstart) > 0) { + if (prevdraw != draw) { + if (prevdraw > 0 && (i - prevstart) > 0) { GPU_buffer_draw_elements(dm->drawObject->edges, GL_LINES, prevstart * 2, (i - prevstart) * 2); } prevstart = i; } prevdraw = draw; } - if ( prevdraw > 0 && (i-prevstart) > 0 ) { + if (prevdraw > 0 && (i - prevstart) > 0) { GPU_buffer_draw_elements(dm->drawObject->edges, GL_LINES, prevstart * 2, (i - prevstart) * 2); } } @@ -507,13 +507,13 @@ static void cdDM_drawLooseEdges(DerivedMesh *dm) } static void cdDM_drawFacesSolid(DerivedMesh *dm, - float (*partial_redraw_planes)[4], - int UNUSED(fast), DMSetMaterial setMaterial) + float (*partial_redraw_planes)[4], + int UNUSED(fast), DMSetMaterial setMaterial) { - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + CDDerivedMesh *cddm = (CDDerivedMesh *) dm; MVert *mvert = cddm->mvert; MFace *mface = cddm->mface; - float *nors= dm->getTessFaceDataArray(dm, CD_NORMAL); + float *nors = dm->getTessFaceDataArray(dm, CD_NORMAL); int a, glmode = -1, shademodel = -1, matnr = -1, drawCurrentMat = 1; #define PASSVERT(index) { \ @@ -521,7 +521,7 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm, short *no = mvert[index].no; \ glNormal3sv(no); \ } \ - glVertex3fv(mvert[index].co); \ + glVertex3fv(mvert[index].co); \ } if (cddm->pbvh && cddm->pbvh_draw) { @@ -541,9 +541,9 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm, for (a = 0; a < dm->numTessFaceData; a++, mface++) { int new_glmode, new_matnr, new_shademodel; - new_glmode = mface->v4?GL_QUADS:GL_TRIANGLES; + new_glmode = mface->v4 ? GL_QUADS : GL_TRIANGLES; new_matnr = mface->mat_nr + 1; - new_shademodel = (mface->flag & ME_SMOOTH)?GL_SMOOTH:GL_FLAT; + new_shademodel = (mface->flag & ME_SMOOTH) ? GL_SMOOTH : GL_FLAT; if (new_glmode != glmode || new_matnr != matnr || new_shademodel != shademodel) { glEnd(); @@ -584,7 +584,7 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm, } glEnd(); } - else { /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */ + else { /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */ GPU_vertex_setup(dm); GPU_normal_setup(dm); if (!GPU_buffer_legacy(dm)) { @@ -604,16 +604,16 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm, } static void cdDM_drawFacesTex_common(DerivedMesh *dm, - DMSetDrawOptionsTex drawParams, - DMSetDrawOptions drawParamsMapped, - DMCompareDrawOptions compareDrawOptions, - void *userData) + DMSetDrawOptionsTex drawParams, + DMSetDrawOptions drawParamsMapped, + DMCompareDrawOptions compareDrawOptions, + void *userData) { - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + CDDerivedMesh *cddm = (CDDerivedMesh *) dm; MVert *mv = cddm->mvert; MFace *mf = DM_get_tessface_data_layer(dm, CD_MFACE); MCol *realcol = dm->getTessFaceDataArray(dm, CD_TEXTURE_MCOL); - float *nors= dm->getTessFaceDataArray(dm, CD_NORMAL); + float *nors = dm->getTessFaceDataArray(dm, CD_NORMAL); MTFace *tf = DM_get_tessface_data_layer(dm, CD_MTFACE); int i, j, orig, *index = DM_get_tessface_data_layer(dm, CD_ORIGINDEX); int startFace = 0 /*, lastFlag = 0xdeadbeef */ /* UNUSED */; @@ -631,25 +631,25 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, unsigned char *cp = NULL; if (drawParams) { - draw_option = drawParams(tf? &tf[i]: NULL, (mcol != NULL), mf->mat_nr); + draw_option = drawParams(tf ? &tf[i] : NULL, (mcol != NULL), mf->mat_nr); } else { if (index) { orig = *index++; - if (orig == ORIGINDEX_NONE) { if (nors) nors += 3; continue; } + if (orig == ORIGINDEX_NONE) { if (nors) nors += 3; continue; } if (drawParamsMapped) draw_option = drawParamsMapped(userData, orig); - else { if (nors) nors += 3; continue; } + else { if (nors) nors += 3; continue; } } else - if (drawParamsMapped) draw_option = drawParamsMapped(userData, i); - else { if (nors) nors += 3; continue; } + if (drawParamsMapped) draw_option = drawParamsMapped(userData, i); + else { if (nors) nors += 3; continue; } } if (draw_option != DM_DRAW_OPTION_SKIP) { if (draw_option != DM_DRAW_OPTION_NO_MCOL && mcol) - cp = (unsigned char*) &mcol[i*4]; + cp = (unsigned char *) &mcol[i * 4]; - if (!(mf->flag&ME_SMOOTH)) { + if (!(mf->flag & ME_SMOOTH)) { if (nors) { glNormal3fv(nors); } @@ -665,30 +665,30 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, } } - glBegin(mf->v4?GL_QUADS:GL_TRIANGLES); + glBegin(mf->v4 ? GL_QUADS : GL_TRIANGLES); if (tf) glTexCoord2fv(tf[i].uv[0]); if (cp) glColor3ub(cp[3], cp[2], cp[1]); mvert = &mv[mf->v1]; - if (mf->flag&ME_SMOOTH) glNormal3sv(mvert->no); + if (mf->flag & ME_SMOOTH) glNormal3sv(mvert->no); glVertex3fv(mvert->co); if (tf) glTexCoord2fv(tf[i].uv[1]); if (cp) glColor3ub(cp[7], cp[6], cp[5]); mvert = &mv[mf->v2]; - if (mf->flag&ME_SMOOTH) glNormal3sv(mvert->no); + if (mf->flag & ME_SMOOTH) glNormal3sv(mvert->no); glVertex3fv(mvert->co); if (tf) glTexCoord2fv(tf[i].uv[2]); if (cp) glColor3ub(cp[11], cp[10], cp[9]); mvert = &mv[mf->v3]; - if (mf->flag&ME_SMOOTH) glNormal3sv(mvert->no); + if (mf->flag & ME_SMOOTH) glNormal3sv(mvert->no); glVertex3fv(mvert->co); if (mf->v4) { if (tf) glTexCoord2fv(tf[i].uv[3]); if (cp) glColor3ub(cp[15], cp[14], cp[13]); mvert = &mv[mf->v4]; - if (mf->flag&ME_SMOOTH) glNormal3sv(mvert->no); + if (mf->flag & ME_SMOOTH) glNormal3sv(mvert->no); glVertex3fv(mvert->co); } glEnd(); @@ -705,7 +705,7 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, GPU_vertex_setup(dm); GPU_normal_setup(dm); GPU_uv_setup(dm); - if ( col != NULL ) { + if (col != NULL) { #if 0 if (realcol && dm->drawObject->colType == CD_TEXTURE_MCOL) { col = 0; @@ -717,13 +717,13 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, if (col != 0) #endif { - unsigned char *colors = MEM_mallocN(dm->getNumTessFaces(dm)*4*3*sizeof(unsigned char), "cdDM_drawFacesTex_common"); + unsigned char *colors = MEM_mallocN(dm->getNumTessFaces(dm) * 4 * 3 * sizeof(unsigned char), "cdDM_drawFacesTex_common"); for (i = 0; i < dm->getNumTessFaces(dm); i++) { for (j = 0; j < 4; j++) { /* bgr -> rgb is intentional (and stupid), but how its stored internally */ - colors[i*12+j*3] = col[i*4+j].b; - colors[i*12+j*3+1] = col[i*4+j].g; - colors[i*12+j*3+2] = col[i*4+j].r; + colors[i * 12 + j * 3] = col[i * 4 + j].b; + colors[i * 12 + j * 3 + 1] = col[i * 4 + j].g; + colors[i * 12 + j * 3 + 2] = col[i * 4 + j].r; } } GPU_color3_upload(dm, colors); @@ -737,7 +737,7 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, } if (!GPU_buffer_legacy(dm)) { - int tottri = dm->drawObject->tot_triangle_point/3; + int tottri = dm->drawObject->tot_triangle_point / 3; int next_actualFace = dm->drawObject->triangle_to_mface[0]; glShadeModel(GL_SMOOTH); @@ -747,11 +747,11 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL; int flush = 0; - if (i != tottri-1) - next_actualFace= dm->drawObject->triangle_to_mface[i+1]; + if (i != tottri - 1) + next_actualFace = dm->drawObject->triangle_to_mface[i + 1]; if (drawParams) { - draw_option = drawParams(tf? &tf[actualFace]: NULL, (mcol != NULL), mf[actualFace].mat_nr); + draw_option = drawParams(tf ? &tf[actualFace] : NULL, (mcol != NULL), mf[actualFace].mat_nr); } else { if (index) { @@ -761,8 +761,8 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, draw_option = drawParamsMapped(userData, orig); } else - if (drawParamsMapped) - draw_option = drawParamsMapped(userData, actualFace); + if (drawParamsMapped) + draw_option = drawParamsMapped(userData, actualFace); } /* flush buffer if current triangle isn't drawable or it's last triangle */ @@ -771,13 +771,13 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, if (!flush && compareDrawOptions) { /* also compare draw options and flush buffer if they're different * need for face selection highlight in edit mode */ - flush|= compareDrawOptions(userData, actualFace, next_actualFace) == 0; + flush |= compareDrawOptions(userData, actualFace, next_actualFace) == 0; } if (flush) { - int first = startFace*3; + int first = startFace * 3; /* Add one to the length if we're drawing at the end of the array */ - int count = (i-startFace+(draw_option != DM_DRAW_OPTION_SKIP ? 1 : 0))*3; + int count = (i - startFace + (draw_option != DM_DRAW_OPTION_SKIP ? 1 : 0)) * 3; if (count) { if (col) @@ -799,24 +799,24 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, } static void cdDM_drawFacesTex(DerivedMesh *dm, - DMSetDrawOptionsTex setDrawOptions, - DMCompareDrawOptions compareDrawOptions, - void *userData) + DMSetDrawOptionsTex setDrawOptions, + DMCompareDrawOptions compareDrawOptions, + void *userData) { cdDM_drawFacesTex_common(dm, setDrawOptions, NULL, compareDrawOptions, userData); } static void cdDM_drawMappedFaces(DerivedMesh *dm, - DMSetDrawOptions setDrawOptions, - DMSetMaterial setMaterial, - DMCompareDrawOptions compareDrawOptions, - void *userData, DMDrawFlag flag) + DMSetDrawOptions setDrawOptions, + DMSetMaterial setMaterial, + DMCompareDrawOptions compareDrawOptions, + void *userData, DMDrawFlag flag) { - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + CDDerivedMesh *cddm = (CDDerivedMesh *) dm; MVert *mv = cddm->mvert; MFace *mf = cddm->mface; MCol *mc; - float *nors= DM_get_tessface_data_layer(dm, CD_NORMAL); + float *nors = DM_get_tessface_data_layer(dm, CD_NORMAL); int useColors = flag & DM_DRAW_USE_COLORS; int i, orig, *index = DM_get_tessface_data_layer(dm, CD_ORIGINDEX); @@ -836,12 +836,12 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, int drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : (mf->flag & ME_SMOOTH); DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL; - orig = (index==NULL) ? i : *index++; + orig = (index == NULL) ? i : *index++; if (orig == ORIGINDEX_NONE) - draw_option= setMaterial(mf->mat_nr + 1, NULL); + draw_option = setMaterial(mf->mat_nr + 1, NULL); else if (setDrawOptions != NULL) - draw_option= setDrawOptions(userData, orig); + draw_option = setDrawOptions(userData, orig); if (draw_option != DM_DRAW_OPTION_SKIP) { unsigned char *cp = NULL; @@ -852,7 +852,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, /* no need to set shading mode to flat because * normals are already used to change shading */ glShadeModel(GL_SMOOTH); - glBegin(mf->v4?GL_QUADS:GL_TRIANGLES); + glBegin(mf->v4 ? GL_QUADS : GL_TRIANGLES); if (!drawSmooth) { if (nors) { @@ -907,10 +907,10 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, int prevstart = 0; GPU_vertex_setup(dm); GPU_normal_setup(dm); - if ( useColors && mc ) + if (useColors && mc) GPU_color_setup(dm); if (!GPU_buffer_legacy(dm)) { - int tottri = dm->drawObject->tot_triangle_point/3; + int tottri = dm->drawObject->tot_triangle_point / 3; glShadeModel(GL_SMOOTH); if (tottri == 0) { @@ -932,15 +932,15 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL; int flush = 0; - if (i != tottri-1) - next_actualFace= dm->drawObject->triangle_to_mface[i+1]; + if (i != tottri - 1) + next_actualFace = dm->drawObject->triangle_to_mface[i + 1]; - orig = (index==NULL) ? actualFace : index[actualFace]; + orig = (index == NULL) ? actualFace : index[actualFace]; if (orig == ORIGINDEX_NONE) - draw_option= setMaterial(mface->mat_nr + 1, NULL); + draw_option = setMaterial(mface->mat_nr + 1, NULL); else if (setDrawOptions != NULL) - draw_option= setDrawOptions(userData, orig); + draw_option = setDrawOptions(userData, orig); /* Goal is to draw as long of a contiguous triangle * array as possible, so draw when we hit either an @@ -957,9 +957,9 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, } if (flush) { - int first = prevstart*3; + int first = prevstart * 3; /* Add one to the length if we're drawing at the end of the array */ - int count = (i-prevstart+(draw_option != DM_DRAW_OPTION_SKIP ? 1 : 0))*3; + int count = (i - prevstart + (draw_option != DM_DRAW_OPTION_SKIP ? 1 : 0)) * 3; if (count) glDrawArrays(GL_TRIANGLES, first, count); @@ -976,9 +976,9 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, } static void cdDM_drawMappedFacesTex(DerivedMesh *dm, - DMSetDrawOptions setDrawOptions, - DMCompareDrawOptions compareDrawOptions, - void *userData) + DMSetDrawOptions setDrawOptions, + DMCompareDrawOptions compareDrawOptions, + void *userData) { cdDM_drawFacesTex_common(dm, NULL, setDrawOptions, compareDrawOptions, userData); } @@ -1007,15 +1007,15 @@ static void cddm_draw_attrib_vertex(DMVertexAttribs *attribs, MVert *mvert, int /* vertex colors */ for (b = 0; b < attribs->totmcol; b++) { - MCol *cp = &attribs->mcol[b].array[a*4 + vert]; + MCol *cp = &attribs->mcol[b].array[a * 4 + vert]; GLubyte col[4]; - col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; + col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; glVertexAttrib4ubvARB(attribs->mcol[b].gl_index, col); } /* tangent for normal mapping */ if (attribs->tottang) { - float *tang = attribs->tang.array[a*4 + vert]; + float *tang = attribs->tang.array[a * 4 + vert]; glVertexAttrib4fvARB(attribs->tang.gl_index, tang); } @@ -1028,11 +1028,11 @@ static void cddm_draw_attrib_vertex(DMVertexAttribs *attribs, MVert *mvert, int } static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, - DMSetMaterial setMaterial, - DMSetDrawOptions setDrawOptions, - void *userData) + DMSetMaterial setMaterial, + DMSetDrawOptions setDrawOptions, + void *userData) { - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + CDDerivedMesh *cddm = (CDDerivedMesh *) dm; GPUVertexAttribs gattribs; DMVertexAttribs attribs; MVert *mvert = cddm->mvert; @@ -1049,7 +1049,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, glShadeModel(GL_SMOOTH); - if ( GPU_buffer_legacy(dm) || setDrawOptions != NULL ) { + if (GPU_buffer_legacy(dm) || setDrawOptions != NULL) { DEBUG_VBO("Using legacy code. cdDM_drawMappedFacesGLSL\n"); memset(&attribs, 0, sizeof(attribs)); @@ -1073,7 +1073,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, continue; } else if (setDrawOptions) { - orig = (index)? index[a]: a; + orig = (index) ? index[a] : a; if (orig == ORIGINDEX_NONE) { /* since the material is set by setMaterial(), faces with no @@ -1128,7 +1128,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, GPU_normal_setup(dm); if (!GPU_buffer_legacy(dm)) { - for (i = 0; i < dm->drawObject->tot_triangle_point/3; i++) { + for (i = 0; i < dm->drawObject->tot_triangle_point / 3; i++) { a = dm->drawObject->triangle_to_mface[i]; @@ -1148,7 +1148,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, GPU_interleaved_attrib_setup(buffer, datatypes, numdata); } - glDrawArrays(GL_TRIANGLES, start*3, numfaces*3); + glDrawArrays(GL_TRIANGLES, start * 3, numfaces * 3); if (numdata != 0) { @@ -1215,84 +1215,84 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, } } - if (dodraw && numdata != 0 ) { + if (dodraw && numdata != 0) { offset = 0; if (attribs.totorco) { - copy_v3_v3((float *)&varray[elementsize*curface*3], (float *)attribs.orco.array[mface->v1]); - copy_v3_v3((float *)&varray[elementsize*curface*3+elementsize], (float *)attribs.orco.array[mface->v2]); - copy_v3_v3((float *)&varray[elementsize*curface*3+elementsize*2], (float *)attribs.orco.array[mface->v3]); - offset += sizeof(float)*3; + copy_v3_v3((float *)&varray[elementsize * curface * 3], (float *)attribs.orco.array[mface->v1]); + copy_v3_v3((float *)&varray[elementsize * curface * 3 + elementsize], (float *)attribs.orco.array[mface->v2]); + copy_v3_v3((float *)&varray[elementsize * curface * 3 + elementsize * 2], (float *)attribs.orco.array[mface->v3]); + offset += sizeof(float) * 3; } for (b = 0; b < attribs.tottface; b++) { MTFace *tf = &attribs.tface[b].array[a]; - copy_v2_v2((float *)&varray[elementsize*curface*3+offset], tf->uv[0]); - copy_v2_v2((float *)&varray[elementsize*curface*3+offset+elementsize], tf->uv[1]); + copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset], tf->uv[0]); + copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize], tf->uv[1]); - copy_v2_v2((float *)&varray[elementsize*curface*3+offset+elementsize*2], tf->uv[2]); - offset += sizeof(float)*2; + copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize * 2], tf->uv[2]); + offset += sizeof(float) * 2; } for (b = 0; b < attribs.totmcol; b++) { - MCol *cp = &attribs.mcol[b].array[a*4 + 0]; + MCol *cp = &attribs.mcol[b].array[a * 4 + 0]; GLubyte col[4]; - col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; - copy_v4_v4_char((char *)&varray[elementsize*curface*3+offset], (char *)col); - cp = &attribs.mcol[b].array[a*4 + 1]; - col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; - copy_v4_v4_char((char *)&varray[elementsize*curface*3+offset+elementsize], (char *)col); - cp = &attribs.mcol[b].array[a*4 + 2]; - col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; - copy_v4_v4_char((char *)&varray[elementsize*curface*3+offset+elementsize*2], (char *)col); - offset += sizeof(unsigned char)*4; + col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; + copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset], (char *)col); + cp = &attribs.mcol[b].array[a * 4 + 1]; + col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; + copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize], (char *)col); + cp = &attribs.mcol[b].array[a * 4 + 2]; + col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; + copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize * 2], (char *)col); + offset += sizeof(unsigned char) * 4; } if (attribs.tottang) { - float *tang = attribs.tang.array[a*4 + 0]; - copy_v4_v4((float *)&varray[elementsize*curface*3+offset], tang); - tang = attribs.tang.array[a*4 + 1]; - copy_v4_v4((float *)&varray[elementsize*curface*3+offset+elementsize], tang); - tang = attribs.tang.array[a*4 + 2]; - copy_v4_v4((float *)&varray[elementsize*curface*3+offset+elementsize*2], tang); - offset += sizeof(float)*4; + float *tang = attribs.tang.array[a * 4 + 0]; + copy_v4_v4((float *)&varray[elementsize * curface * 3 + offset], tang); + tang = attribs.tang.array[a * 4 + 1]; + copy_v4_v4((float *)&varray[elementsize * curface * 3 + offset + elementsize], tang); + tang = attribs.tang.array[a * 4 + 2]; + copy_v4_v4((float *)&varray[elementsize * curface * 3 + offset + elementsize * 2], tang); + offset += sizeof(float) * 4; } (void)offset; } curface++; if (mface->v4) { - if (dodraw && numdata != 0 ) { + if (dodraw && numdata != 0) { offset = 0; if (attribs.totorco) { - copy_v3_v3((float *)&varray[elementsize*curface*3], (float *)attribs.orco.array[mface->v3]); - copy_v3_v3((float *)&varray[elementsize*curface*3+elementsize], (float *)attribs.orco.array[mface->v4]); - copy_v3_v3((float *)&varray[elementsize*curface*3+elementsize*2], (float *)attribs.orco.array[mface->v1]); - offset += sizeof(float)*3; + copy_v3_v3((float *)&varray[elementsize * curface * 3], (float *)attribs.orco.array[mface->v3]); + copy_v3_v3((float *)&varray[elementsize * curface * 3 + elementsize], (float *)attribs.orco.array[mface->v4]); + copy_v3_v3((float *)&varray[elementsize * curface * 3 + elementsize * 2], (float *)attribs.orco.array[mface->v1]); + offset += sizeof(float) * 3; } for (b = 0; b < attribs.tottface; b++) { MTFace *tf = &attribs.tface[b].array[a]; - copy_v2_v2((float *)&varray[elementsize*curface*3+offset], tf->uv[2]); - copy_v2_v2((float *)&varray[elementsize*curface*3+offset+elementsize], tf->uv[3]); - copy_v2_v2((float *)&varray[elementsize*curface*3+offset+elementsize*2], tf->uv[0]); - offset += sizeof(float)*2; + copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset], tf->uv[2]); + copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize], tf->uv[3]); + copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize * 2], tf->uv[0]); + offset += sizeof(float) * 2; } for (b = 0; b < attribs.totmcol; b++) { - MCol *cp = &attribs.mcol[b].array[a*4 + 2]; + MCol *cp = &attribs.mcol[b].array[a * 4 + 2]; GLubyte col[4]; - col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; - copy_v4_v4_char((char *)&varray[elementsize*curface*3+offset], (char *)col); - cp = &attribs.mcol[b].array[a*4 + 3]; - col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; - copy_v4_v4_char((char *)&varray[elementsize*curface*3+offset+elementsize], (char *)col); - cp = &attribs.mcol[b].array[a*4 + 0]; - col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; - copy_v4_v4_char((char *)&varray[elementsize*curface*3+offset+elementsize*2], (char *)col); - offset += sizeof(unsigned char)*4; + col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; + copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset], (char *)col); + cp = &attribs.mcol[b].array[a * 4 + 3]; + col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; + copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize], (char *)col); + cp = &attribs.mcol[b].array[a * 4 + 0]; + col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; + copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize * 2], (char *)col); + offset += sizeof(unsigned char) * 4; } if (attribs.tottang) { - float *tang = attribs.tang.array[a*4 + 2]; - copy_v4_v4((float *)&varray[elementsize*curface*3+offset], tang); - tang = attribs.tang.array[a*4 + 3]; - copy_v4_v4((float *)&varray[elementsize*curface*3+offset+elementsize], tang); - tang = attribs.tang.array[a*4 + 0]; - copy_v4_v4((float *)&varray[elementsize*curface*3+offset+elementsize*2], tang); - offset += sizeof(float)*4; + float *tang = attribs.tang.array[a * 4 + 2]; + copy_v4_v4((float *)&varray[elementsize * curface * 3 + offset], tang); + tang = attribs.tang.array[a * 4 + 3]; + copy_v4_v4((float *)&varray[elementsize * curface * 3 + offset + elementsize], tang); + tang = attribs.tang.array[a * 4 + 0]; + copy_v4_v4((float *)&varray[elementsize * curface * 3 + offset + elementsize * 2], tang); + offset += sizeof(float) * 4; } (void)offset; } @@ -1307,7 +1307,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, GPU_buffer_unlock(buffer); GPU_interleaved_attrib_setup(buffer, datatypes, numdata); } - glDrawArrays(GL_TRIANGLES, start*3, (curface-start)*3); + glDrawArrays(GL_TRIANGLES, start * 3, (curface - start) * 3); } } GPU_buffer_unbind(); @@ -1324,10 +1324,10 @@ static void cdDM_drawFacesGLSL(DerivedMesh *dm, DMSetMaterial setMaterial) } static void cdDM_drawMappedFacesMat(DerivedMesh *dm, - void (*setMaterial)(void *userData, int, void *attribs), - int (*setFace)(void *userData, int index), void *userData) + void (*setMaterial)(void *userData, int, void *attribs), + int (*setFace)(void *userData, int index), void *userData) { - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + CDDerivedMesh *cddm = (CDDerivedMesh *) dm; GPUVertexAttribs gattribs; DMVertexAttribs attribs; MVert *mvert = cddm->mvert; @@ -1363,7 +1363,7 @@ static void cdDM_drawMappedFacesMat(DerivedMesh *dm, /* skipping faces */ if (setFace) { - orig = (index)? index[a]: a; + orig = (index) ? index[a] : a; if (orig != ORIGINDEX_NONE && !setFace(userData, orig)) continue; @@ -1404,7 +1404,7 @@ static void cdDM_drawMappedFacesMat(DerivedMesh *dm, static void cdDM_drawMappedEdges(DerivedMesh *dm, DMSetDrawOptions setDrawOptions, void *userData) { - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + CDDerivedMesh *cddm = (CDDerivedMesh *) dm; MVert *vert = cddm->mvert; MEdge *edge = cddm->medge; int i, orig, *index = DM_get_edge_data_layer(dm, CD_ORIGINDEX); @@ -1450,7 +1450,7 @@ static void cdDM_foreachMappedEdge( void (*func)(void *userData, int index, const float v0co[3], const float v1co[3]), void *userData) { - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + CDDerivedMesh *cddm = (CDDerivedMesh *) dm; MVert *mv = cddm->mvert; MEdge *med = cddm->medge; int i, orig, *index = DM_get_edge_data_layer(dm, CD_ORIGINDEX); @@ -1471,7 +1471,7 @@ static void cdDM_foreachMappedFaceCenter( void (*func)(void *userData, int index, const float cent[3], const float no[3]), void *userData) { - CDDerivedMesh *cddm = (CDDerivedMesh*)dm; + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; MVert *mv = cddm->mvert; MPoly *mp = cddm->mpoly; MLoop *ml = cddm->mloop; @@ -1492,7 +1492,7 @@ static void cdDM_foreachMappedFaceCenter( ml = &cddm->mloop[mp->loopstart]; cent[0] = cent[1] = cent[2] = 0.0f; - for (j=0; j<mp->totloop; j++, ml++) { + for (j = 0; j < mp->totloop; j++, ml++) { add_v3_v3v3(cent, cent, mv[ml->v].co); } mul_v3_fl(cent, 1.0f / (float)j); @@ -1519,12 +1519,12 @@ static void cdDM_foreachMappedFaceCenter( void CDDM_recalc_tessellation_ex(DerivedMesh *dm, const int do_face_nor_cpy) { - CDDerivedMesh *cddm = (CDDerivedMesh*)dm; + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; - dm->numTessFaceData = mesh_recalcTessellation(&dm->faceData, &dm->loopData, &dm->polyData, - cddm->mvert, - dm->numTessFaceData, dm->numLoopData, dm->numPolyData, - do_face_nor_cpy); + dm->numTessFaceData = BKE_mesh_recalc_tessellation(&dm->faceData, &dm->loopData, &dm->polyData, + cddm->mvert, + dm->numTessFaceData, dm->numLoopData, dm->numPolyData, + do_face_nor_cpy); if (!CustomData_get_layer(&dm->faceData, CD_ORIGINDEX)) { int *polyIndex = CustomData_get_layer(&dm->faceData, CD_POLYINDEX); @@ -1551,7 +1551,7 @@ static void cdDM_free_internal(CDDerivedMesh *cddm) static void cdDM_release(DerivedMesh *dm) { - CDDerivedMesh *cddm = (CDDerivedMesh*)dm; + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; if (DM_release(dm)) { cdDM_free_internal(cddm); @@ -1671,18 +1671,18 @@ DerivedMesh *CDDM_from_mesh(Mesh *mesh, Object *UNUSED(ob)) /* this does a referenced copy, with an exception for fluidsim */ DM_init(dm, DM_TYPE_CDDM, mesh->totvert, mesh->totedge, mesh->totface, - mesh->totloop, mesh->totpoly); + mesh->totloop, mesh->totpoly); dm->deformedOnly = 1; - alloctype= CD_REFERENCE; + alloctype = CD_REFERENCE; CustomData_merge(&mesh->vdata, &dm->vertData, mask, alloctype, - mesh->totvert); + mesh->totvert); CustomData_merge(&mesh->edata, &dm->edgeData, mask, alloctype, - mesh->totedge); - CustomData_merge(&mesh->fdata, &dm->faceData, mask|CD_MASK_POLYINDEX, alloctype, - mesh->totface); + mesh->totedge); + CustomData_merge(&mesh->fdata, &dm->faceData, mask | CD_MASK_POLYINDEX, alloctype, + mesh->totface); CustomData_merge(&mesh->ldata, &dm->loopData, mask, alloctype, mesh->totloop); CustomData_merge(&mesh->pdata, &dm->polyData, mask, alloctype, @@ -1723,8 +1723,9 @@ DerivedMesh *CDDM_from_curve_customDB(Object *ob, ListBase *dispbase) MPoly *allpoly; int totvert, totedge, totloop, totpoly; - if (nurbs_to_mdata_customdb(ob, dispbase, &allvert, &totvert, &alledge, - &totedge, &allloop, &allpoly, &totloop, &totpoly) != 0) { + if (BKE_mesh_nurbs_to_mdata_customdb(ob, dispbase, &allvert, &totvert, &alledge, + &totedge, &allloop, &allpoly, &totloop, &totpoly) != 0) + { /* Error initializing mdata. This often happens when curve is empty */ return CDDM_new(0, 0, 0, 0, 0); } @@ -1732,12 +1733,12 @@ DerivedMesh *CDDM_from_curve_customDB(Object *ob, ListBase *dispbase) dm = CDDM_new(totvert, totedge, 0, totloop, totpoly); dm->deformedOnly = 1; - cddm = (CDDerivedMesh*)dm; + cddm = (CDDerivedMesh *)dm; - memcpy(cddm->mvert, allvert, totvert*sizeof(MVert)); - memcpy(cddm->medge, alledge, totedge*sizeof(MEdge)); - memcpy(cddm->mloop, allloop, totloop*sizeof(MLoop)); - memcpy(cddm->mpoly, allpoly, totpoly*sizeof(MPoly)); + memcpy(cddm->mvert, allvert, totvert * sizeof(MVert)); + memcpy(cddm->medge, alledge, totedge * sizeof(MEdge)); + memcpy(cddm->mloop, allloop, totloop * sizeof(MLoop)); + memcpy(cddm->mpoly, allpoly, totpoly * sizeof(MPoly)); MEM_freeN(allvert); MEM_freeN(alledge); @@ -1750,8 +1751,8 @@ DerivedMesh *CDDM_from_curve_customDB(Object *ob, ListBase *dispbase) } static void loops_to_customdata_corners(BMesh *bm, CustomData *facedata, - int cdindex, BMLoop *l3[3], - int numCol, int numTex) + int cdindex, BMLoop *l3[3], + int numCol, int numTex) { BMLoop *l; BMFace *f = l3[0]->f; @@ -1768,7 +1769,7 @@ static void loops_to_customdata_corners(BMesh *bm, CustomData *facedata, ME_MTEXFACE_CPY(texface, texpoly); - for (j = 0 ; j < 3; j++) { + for (j = 0; j < 3; j++) { l = l3[j]; mloopuv = CustomData_bmesh_get_n(&bm->ldata, l->head.data, CD_MLOOPUV, i); copy_v2_v2(texface->uv[j], mloopuv->uv); @@ -1806,7 +1807,7 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *UNUSED(me), int use_mdis bm->totloop, bm->totface); - CDDerivedMesh *cddm = (CDDerivedMesh*)dm; + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; BMIter iter, liter; BMVert *eve; BMEdge *eed; @@ -1832,7 +1833,7 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *UNUSED(me), int use_mdis /*don't add origindex layer if one already exists*/ add_orig = !CustomData_has_layer(&bm->pdata, CD_ORIGINDEX); - mask = use_mdisps ? CD_MASK_DERIVEDMESH|CD_MASK_MDISPS : CD_MASK_DERIVEDMESH; + mask = use_mdisps ? CD_MASK_DERIVEDMESH | CD_MASK_MDISPS : CD_MASK_DERIVEDMESH; /* don't process shapekeys, we only feed them through the modifier stack as needed, * e.g. for applying modifiers or the like*/ @@ -1866,7 +1867,7 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *UNUSED(me), int use_mdis mv->flag = BM_vert_flag_to_mflag(eve); if (has_vert_bweight) - mv->bweight = (unsigned char)(BM_elem_float_data_get(&bm->vdata, eve, CD_BWEIGHT)*255.0f); + mv->bweight = (unsigned char)(BM_elem_float_data_get(&bm->vdata, eve, CD_BWEIGHT) * 255.0f); if (add_orig) *index = i; @@ -1885,9 +1886,9 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *UNUSED(me), int use_mdis med->v2 = BM_elem_index_get(eed->v2); if (has_crease) - med->crease = (unsigned char)(BM_elem_float_data_get(&bm->edata, eed, CD_CREASE)*255.0f); + med->crease = (unsigned char)(BM_elem_float_data_get(&bm->edata, eed, CD_CREASE) * 255.0f); if (has_edge_bweight) - med->bweight = (unsigned char)(BM_elem_float_data_get(&bm->edata, eed, CD_BWEIGHT)*255.0f); + med->bweight = (unsigned char)(BM_elem_float_data_get(&bm->edata, eed, CD_BWEIGHT) * 255.0f); med->flag = BM_edge_flag_to_mflag(eed); @@ -1916,7 +1917,7 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *UNUSED(me), int use_mdis mf->mat_nr = efa->mat_nr; mf->flag = BM_face_flag_to_mflag(efa); - *index = add_orig ? BM_elem_index_get(efa) : *(int*)CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_ORIGINDEX); + *index = add_orig ? BM_elem_index_get(efa) : *(int *)CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_ORIGINDEX); *polyindex = BM_elem_index_get(efa); loops_to_customdata_corners(bm, &dm->faceData, i, l, numCol, numTex); @@ -1973,7 +1974,7 @@ static DerivedMesh *cddm_copy_ex(DerivedMesh *source, int faces_from_tessfaces) /* this initializes dm, and copies all non mvert/medge/mface layers */ DM_from_template(dm, source, DM_TYPE_CDDM, numVerts, numEdges, numTessFaces, - numLoops, numPolys); + numLoops, numPolys); dm->deformedOnly = source->deformedOnly; dm->dirty = source->dirty; @@ -2055,7 +2056,7 @@ DerivedMesh *CDDM_from_template(DerivedMesh *source, void CDDM_apply_vert_coords(DerivedMesh *dm, float (*vertCoords)[3]) { - CDDerivedMesh *cddm = (CDDerivedMesh*)dm; + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; MVert *vert; int i; @@ -2069,7 +2070,7 @@ void CDDM_apply_vert_coords(DerivedMesh *dm, float (*vertCoords)[3]) void CDDM_apply_vert_normals(DerivedMesh *dm, short (*vertNormals)[3]) { - CDDerivedMesh *cddm = (CDDerivedMesh*)dm; + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; MVert *vert; int i; @@ -2083,7 +2084,7 @@ void CDDM_apply_vert_normals(DerivedMesh *dm, short (*vertNormals)[3]) void CDDM_calc_normals_mapping_ex(DerivedMesh *dm, const short only_face_normals) { - CDDerivedMesh *cddm = (CDDerivedMesh*)dm; + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; float (*face_nors)[3] = NULL; if (dm->numVertData == 0) return; @@ -2113,16 +2114,16 @@ void CDDM_calc_normals_mapping_ex(DerivedMesh *dm, const short only_face_normals } - face_nors = MEM_mallocN(sizeof(float)*3*dm->numTessFaceData, "face_nors"); + face_nors = MEM_mallocN(sizeof(float) * 3 * dm->numTessFaceData, "face_nors"); /* calculate face normals */ - mesh_calc_normals_mapping_ex(cddm->mvert, dm->numVertData, CDDM_get_loops(dm), CDDM_get_polys(dm), - dm->numLoopData, dm->numPolyData, NULL, cddm->mface, dm->numTessFaceData, - CustomData_get_layer(&dm->faceData, CD_POLYINDEX), face_nors, - only_face_normals); + BKE_mesh_calc_normals_mapping_ex(cddm->mvert, dm->numVertData, CDDM_get_loops(dm), CDDM_get_polys(dm), + dm->numLoopData, dm->numPolyData, NULL, cddm->mface, dm->numTessFaceData, + CustomData_get_layer(&dm->faceData, CD_POLYINDEX), face_nors, + only_face_normals); CustomData_add_layer(&dm->faceData, CD_NORMAL, CD_ASSIGN, - face_nors, dm->numTessFaceData); + face_nors, dm->numTessFaceData); } @@ -2137,7 +2138,7 @@ void CDDM_calc_normals_mapping(DerivedMesh *dm) /* bmesh note: this matches what we have in trunk */ void CDDM_calc_normals(DerivedMesh *dm) { - CDDerivedMesh *cddm = (CDDerivedMesh*)dm; + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; float (*poly_nors)[3]; if (dm->numVertData == 0) return; @@ -2151,13 +2152,13 @@ void CDDM_calc_normals(DerivedMesh *dm) poly_nors = CustomData_add_layer(&dm->polyData, CD_NORMAL, CD_CALLOC, NULL, dm->numPolyData); } - mesh_calc_normals(cddm->mvert, dm->numVertData, CDDM_get_loops(dm), CDDM_get_polys(dm), - dm->numLoopData, dm->numPolyData, poly_nors); + BKE_mesh_calc_normals(cddm->mvert, dm->numVertData, CDDM_get_loops(dm), CDDM_get_polys(dm), + dm->numLoopData, dm->numPolyData, poly_nors); } void CDDM_calc_normals_tessface(DerivedMesh *dm) { - CDDerivedMesh *cddm = (CDDerivedMesh*)dm; + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; float (*face_nors)[3]; if (dm->numVertData == 0) return; @@ -2171,8 +2172,8 @@ void CDDM_calc_normals_tessface(DerivedMesh *dm) face_nors = CustomData_add_layer(&dm->faceData, CD_NORMAL, CD_CALLOC, NULL, dm->numTessFaceData); } - mesh_calc_normals_tessface(cddm->mvert, dm->numVertData, - cddm->mface, dm->numTessFaceData, face_nors); + BKE_mesh_calc_normals_tessface(cddm->mvert, dm->numVertData, + cddm->mface, dm->numTessFaceData, face_nors); } #if 1 @@ -2189,7 +2190,7 @@ void CDDM_calc_normals_tessface(DerivedMesh *dm) */ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap) { - CDDerivedMesh *cddm = (CDDerivedMesh*)dm; + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; CDDerivedMesh *cddm2 = NULL; MVert *mv, *mvert = NULL; BLI_array_declare(mvert); @@ -2208,9 +2209,9 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap) totloop = dm->numLoopData; totpoly = dm->numPolyData; - newv = MEM_callocN(sizeof(int)*dm->numVertData, "newv vtable CDDM_merge_verts"); - newe = MEM_callocN(sizeof(int)*dm->numEdgeData, "newv etable CDDM_merge_verts"); - newl = MEM_callocN(sizeof(int)*totloop, "newv ltable CDDM_merge_verts"); + newv = MEM_callocN(sizeof(int) * dm->numVertData, "newv vtable CDDM_merge_verts"); + newe = MEM_callocN(sizeof(int) * dm->numEdgeData, "newv etable CDDM_merge_verts"); + newl = MEM_callocN(sizeof(int) * totloop, "newv ltable CDDM_merge_verts"); /*fill newl with destination vertex indices*/ mv = cddm->mvert; @@ -2246,7 +2247,7 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap) if (LIKELY(med->v1 != med->v2)) { const unsigned int v1 = (vtargetmap[med->v1] != -1) ? vtargetmap[med->v1] : med->v1; const unsigned int v2 = (vtargetmap[med->v2] != -1) ? vtargetmap[med->v2] : med->v2; - void **eh_p= BLI_edgehash_lookup_p(ehash, v1, v2); + void **eh_p = BLI_edgehash_lookup_p(ehash, v1, v2); if (eh_p) { newe[i] = GET_INT_FROM_POINTER(*eh_p); @@ -2274,8 +2275,8 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap) for (j = 0; j < mp->totloop; j++, ml++) { med = cddm->medge + ml->e; if (LIKELY(med->v1 != med->v2)) { - newl[j+mp->loopstart] = BLI_array_count(mloop); - BLI_array_append(oldl, j+mp->loopstart); + newl[j + mp->loopstart] = BLI_array_count(mloop); + BLI_array_append(oldl, j + mp->loopstart); BLI_array_append(mloop, *ml); c++; } @@ -2293,7 +2294,7 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap) } /*create new cddm*/ - cddm2 = (CDDerivedMesh*) CDDM_from_template((DerivedMesh*)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*/ med = medge; @@ -2330,10 +2331,10 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap) } /*copy over data. CustomData_add_layer can do this, need to look it up.*/ - memcpy(cddm2->mvert, mvert, sizeof(MVert)*BLI_array_count(mvert)); - memcpy(cddm2->medge, medge, sizeof(MEdge)*BLI_array_count(medge)); - memcpy(cddm2->mloop, mloop, sizeof(MLoop)*BLI_array_count(mloop)); - memcpy(cddm2->mpoly, mpoly, sizeof(MPoly)*BLI_array_count(mpoly)); + memcpy(cddm2->mvert, mvert, sizeof(MVert) * BLI_array_count(mvert)); + memcpy(cddm2->medge, medge, sizeof(MEdge) * BLI_array_count(medge)); + memcpy(cddm2->mloop, mloop, sizeof(MLoop) * BLI_array_count(mloop)); + 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); if (newv) @@ -2357,13 +2358,13 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap) dm->needsFree = 1; dm->release(dm); - return (DerivedMesh*)cddm2; + return (DerivedMesh *)cddm2; } #endif void CDDM_calc_edges_tessface(DerivedMesh *dm) { - CDDerivedMesh *cddm = (CDDerivedMesh*)dm; + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; CustomData edgeData; EdgeHashIterator *ehi; MFace *mf = cddm->mface; @@ -2400,10 +2401,10 @@ void CDDM_calc_edges_tessface(DerivedMesh *dm) med = CustomData_get_layer(&edgeData, CD_MEDGE); index = CustomData_get_layer(&edgeData, CD_ORIGINDEX); for (i = 0; !BLI_edgehashIterator_isDone(ehi); - BLI_edgehashIterator_step(ehi), ++i, ++med, ++index) { + BLI_edgehashIterator_step(ehi), ++i, ++med, ++index) { BLI_edgehashIterator_getKey(ehi, &med->v1, &med->v2); - med->flag = ME_EDGEDRAW|ME_EDGERENDER; + med->flag = ME_EDGEDRAW | ME_EDGERENDER; *index = ORIGINDEX_NONE; } BLI_edgehashIterator_free(ehi); @@ -2421,7 +2422,7 @@ void CDDM_calc_edges_tessface(DerivedMesh *dm) /* warning, this uses existing edges but CDDM_calc_edges_tessface() doesn't */ void CDDM_calc_edges(DerivedMesh *dm) { - CDDerivedMesh *cddm = (CDDerivedMesh*)dm; + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; CustomData edgeData; EdgeHashIterator *ehi; MPoly *mp = cddm->mpoly; @@ -2437,7 +2438,7 @@ void CDDM_calc_edges(DerivedMesh *dm) med = cddm->medge; if (med) { for (i = 0; i < numEdges; i++, med++) { - BLI_edgehash_insert(eh, med->v1, med->v2, SET_INT_IN_POINTER(i+1)); + BLI_edgehash_insert(eh, med->v1, med->v2, SET_INT_IN_POINTER(i + 1)); } } @@ -2463,12 +2464,12 @@ void CDDM_calc_edges(DerivedMesh *dm) med = CustomData_get_layer(&edgeData, CD_MEDGE); index = CustomData_get_layer(&edgeData, CD_ORIGINDEX); for (i = 0; !BLI_edgehashIterator_isDone(ehi); - BLI_edgehashIterator_step(ehi), ++i, ++med, ++index) { + BLI_edgehashIterator_step(ehi), ++i, ++med, ++index) { BLI_edgehashIterator_getKey(ehi, &med->v1, &med->v2); j = GET_INT_FROM_POINTER(BLI_edgehashIterator_getValue(ehi)); - med->flag = ME_EDGEDRAW|ME_EDGERENDER; - *index = j==0 ? ORIGINDEX_NONE : eindex[j-1]; + med->flag = ME_EDGEDRAW | ME_EDGERENDER; + *index = j == 0 ? ORIGINDEX_NONE : eindex[j - 1]; BLI_edgehashIterator_setValue(ehi, SET_INT_IN_POINTER(i)); } @@ -2497,7 +2498,7 @@ void CDDM_calc_edges(DerivedMesh *dm) void CDDM_lower_num_verts(DerivedMesh *dm, int numVerts) { if (numVerts < dm->numVertData) - CustomData_free_elem(&dm->vertData, numVerts, dm->numVertData-numVerts); + CustomData_free_elem(&dm->vertData, numVerts, dm->numVertData - numVerts); dm->numVertData = numVerts; } @@ -2505,7 +2506,7 @@ void CDDM_lower_num_verts(DerivedMesh *dm, int numVerts) void CDDM_lower_num_edges(DerivedMesh *dm, int numEdges) { if (numEdges < dm->numEdgeData) - CustomData_free_elem(&dm->edgeData, numEdges, dm->numEdgeData-numEdges); + CustomData_free_elem(&dm->edgeData, numEdges, dm->numEdgeData - numEdges); dm->numEdgeData = numEdges; } @@ -2513,7 +2514,7 @@ void CDDM_lower_num_edges(DerivedMesh *dm, int numEdges) void CDDM_lower_num_tessfaces(DerivedMesh *dm, int numTessFaces) { if (numTessFaces < dm->numTessFaceData) - CustomData_free_elem(&dm->faceData, numTessFaces, dm->numTessFaceData-numTessFaces); + CustomData_free_elem(&dm->faceData, numTessFaces, dm->numTessFaceData - numTessFaces); dm->numTessFaceData = numTessFaces; } @@ -2521,7 +2522,7 @@ void CDDM_lower_num_tessfaces(DerivedMesh *dm, int numTessFaces) void CDDM_lower_num_polys(DerivedMesh *dm, int numPolys) { if (numPolys < dm->numPolyData) - CustomData_free_elem(&dm->polyData, numPolys, dm->numPolyData-numPolys); + CustomData_free_elem(&dm->polyData, numPolys, dm->numPolyData - numPolys); dm->numPolyData = numPolys; } @@ -2530,60 +2531,60 @@ void CDDM_lower_num_polys(DerivedMesh *dm, int numPolys) MVert *CDDM_get_vert(DerivedMesh *dm, int index) { - return &((CDDerivedMesh*)dm)->mvert[index]; + return &((CDDerivedMesh *)dm)->mvert[index]; } MEdge *CDDM_get_edge(DerivedMesh *dm, int index) { - return &((CDDerivedMesh*)dm)->medge[index]; + return &((CDDerivedMesh *)dm)->medge[index]; } MFace *CDDM_get_tessface(DerivedMesh *dm, int index) { - return &((CDDerivedMesh*)dm)->mface[index]; + return &((CDDerivedMesh *)dm)->mface[index]; } MLoop *CDDM_get_loop(DerivedMesh *dm, int index) { - return &((CDDerivedMesh*)dm)->mloop[index]; + return &((CDDerivedMesh *)dm)->mloop[index]; } MPoly *CDDM_get_poly(DerivedMesh *dm, int index) { - return &((CDDerivedMesh*)dm)->mpoly[index]; + return &((CDDerivedMesh *)dm)->mpoly[index]; } /* array access functions */ MVert *CDDM_get_verts(DerivedMesh *dm) { - return ((CDDerivedMesh*)dm)->mvert; + return ((CDDerivedMesh *)dm)->mvert; } MEdge *CDDM_get_edges(DerivedMesh *dm) { - return ((CDDerivedMesh*)dm)->medge; + return ((CDDerivedMesh *)dm)->medge; } MFace *CDDM_get_tessfaces(DerivedMesh *dm) { - return ((CDDerivedMesh*)dm)->mface; + return ((CDDerivedMesh *)dm)->mface; } MLoop *CDDM_get_loops(DerivedMesh *dm) { - return ((CDDerivedMesh*)dm)->mloop; + return ((CDDerivedMesh *)dm)->mloop; } MPoly *CDDM_get_polys(DerivedMesh *dm) { - return ((CDDerivedMesh*)dm)->mpoly; + return ((CDDerivedMesh *)dm)->mpoly; } void CDDM_tessfaces_to_faces(DerivedMesh *dm) { /*converts mfaces to mpolys/mloops*/ - CDDerivedMesh *cddm = (CDDerivedMesh*)dm; + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; MFace *mf; MEdge *me; EdgeHash *eh = BLI_edgehash_new(); @@ -2627,13 +2628,13 @@ void CDDM_tessfaces_to_faces(DerivedMesh *dm) MPoly *mp; int l, *polyindex; - cddm->mloop = MEM_callocN(sizeof(MLoop)*totloop, "cddm->mloop in CDDM_tessfaces_to_faces"); - cddm->mpoly = MEM_callocN(sizeof(MPoly)*cddm->dm.numTessFaceData, "cddm->mpoly in CDDM_tessfaces_to_faces"); + cddm->mloop = MEM_callocN(sizeof(MLoop) * totloop, "cddm->mloop in CDDM_tessfaces_to_faces"); + cddm->mpoly = MEM_callocN(sizeof(MPoly) * cddm->dm.numTessFaceData, "cddm->mpoly in CDDM_tessfaces_to_faces"); CustomData_add_layer(&cddm->dm.loopData, CD_MLOOP, CD_ASSIGN, cddm->mloop, totloop); CustomData_add_layer(&cddm->dm.polyData, CD_MPOLY, CD_ASSIGN, cddm->mpoly, cddm->dm.numPolyData); CustomData_merge(&cddm->dm.faceData, &cddm->dm.polyData, - CD_MASK_ORIGINDEX, CD_DUPLICATE, cddm->dm.numTessFaceData); + CD_MASK_ORIGINDEX, CD_DUPLICATE, cddm->dm.numTessFaceData); polyindex = CustomData_get_layer(&cddm->dm.faceData, CD_POLYINDEX); @@ -2656,12 +2657,12 @@ void CDDM_tessfaces_to_faces(DerivedMesh *dm) ml++, l++; ml->v = mf->v3; - ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v3, mf->v4?mf->v4:mf->v1)); + ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v3, mf->v4 ? mf->v4 : mf->v1)); ml++, l++; if (mf->v4) { ml->v = mf->v4; - ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v4, mf->v1)); + ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v4, mf->v1)); ml++, l++; } @@ -2674,7 +2675,7 @@ void CDDM_tessfaces_to_faces(DerivedMesh *dm) void CDDM_set_mvert(DerivedMesh *dm, MVert *mvert) { - CDDerivedMesh *cddm = (CDDerivedMesh*)dm; + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; if (!CustomData_has_layer(&dm->vertData, CD_MVERT)) CustomData_add_layer(&dm->vertData, CD_MVERT, CD_ASSIGN, mvert, dm->numVertData); @@ -2684,7 +2685,7 @@ void CDDM_set_mvert(DerivedMesh *dm, MVert *mvert) void CDDM_set_medge(DerivedMesh *dm, MEdge *medge) { - CDDerivedMesh *cddm = (CDDerivedMesh*)dm; + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; if (!CustomData_has_layer(&dm->edgeData, CD_MEDGE)) CustomData_add_layer(&dm->edgeData, CD_MEDGE, CD_ASSIGN, medge, dm->numEdgeData); @@ -2694,7 +2695,7 @@ void CDDM_set_medge(DerivedMesh *dm, MEdge *medge) void CDDM_set_mface(DerivedMesh *dm, MFace *mface) { - CDDerivedMesh *cddm = (CDDerivedMesh*)dm; + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; if (!CustomData_has_layer(&dm->faceData, CD_MFACE)) CustomData_add_layer(&dm->faceData, CD_MFACE, CD_ASSIGN, mface, dm->numTessFaceData); @@ -2704,7 +2705,7 @@ void CDDM_set_mface(DerivedMesh *dm, MFace *mface) void CDDM_set_mloop(DerivedMesh *dm, MLoop *mloop) { - CDDerivedMesh *cddm = (CDDerivedMesh*)dm; + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; if (!CustomData_has_layer(&dm->loopData, CD_MLOOP)) CustomData_add_layer(&dm->loopData, CD_MLOOP, CD_ASSIGN, mloop, dm->numLoopData); @@ -2714,7 +2715,7 @@ void CDDM_set_mloop(DerivedMesh *dm, MLoop *mloop) void CDDM_set_mpoly(DerivedMesh *dm, MPoly *mpoly) { - CDDerivedMesh *cddm = (CDDerivedMesh*)dm; + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; if (!CustomData_has_layer(&dm->polyData, CD_MPOLY)) CustomData_add_layer(&dm->polyData, CD_MPOLY, CD_ASSIGN, mpoly, dm->numPolyData); diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index 2955e20c9e2..7ba117861bb 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -62,9 +62,9 @@ CurveMapping *curvemapping_add(int tot, float minx, float miny, float maxx, floa int a; float clipminx, clipminy, clipmaxx, clipmaxy; - cumap= MEM_callocN(sizeof(CurveMapping), "new curvemap"); - cumap->flag= CUMA_DO_CLIP; - if (tot==4) cumap->cur= 3; /* rhms, hack for 'col' curve? */ + cumap = MEM_callocN(sizeof(CurveMapping), "new curvemap"); + cumap->flag = CUMA_DO_CLIP; + if (tot == 4) cumap->cur = 3; /* rhms, hack for 'col' curve? */ clipminx = MIN2(minx, maxx); clipminy = MIN2(miny, maxy); @@ -72,20 +72,20 @@ CurveMapping *curvemapping_add(int tot, float minx, float miny, float maxx, floa clipmaxy = MAX2(miny, maxy); BLI_init_rctf(&cumap->curr, clipminx, clipmaxx, clipminy, clipmaxy); - cumap->clipr= cumap->curr; + cumap->clipr = cumap->curr; - cumap->white[0]= cumap->white[1]= cumap->white[2]= 1.0f; - cumap->bwmul[0]= cumap->bwmul[1]= cumap->bwmul[2]= 1.0f; + cumap->white[0] = cumap->white[1] = cumap->white[2] = 1.0f; + cumap->bwmul[0] = cumap->bwmul[1] = cumap->bwmul[2] = 1.0f; - for (a=0; a<tot; a++) { - cumap->cm[a].flag= CUMA_EXTEND_EXTRAPOLATE; - cumap->cm[a].totpoint= 2; - cumap->cm[a].curve= MEM_callocN(2*sizeof(CurveMapPoint), "curve points"); - - cumap->cm[a].curve[0].x= minx; - cumap->cm[a].curve[0].y= miny; - cumap->cm[a].curve[1].x= maxx; - cumap->cm[a].curve[1].y= maxy; + for (a = 0; a < tot; a++) { + cumap->cm[a].flag = CUMA_EXTEND_EXTRAPOLATE; + cumap->cm[a].totpoint = 2; + cumap->cm[a].curve = MEM_callocN(2 * sizeof(CurveMapPoint), "curve points"); + + cumap->cm[a].curve[0].x = minx; + cumap->cm[a].curve[0].y = miny; + cumap->cm[a].curve[1].x = maxx; + cumap->cm[a].curve[1].y = maxy; } cumap->changed_timestamp = 0; @@ -98,7 +98,7 @@ void curvemapping_free(CurveMapping *cumap) int a; if (cumap) { - for (a=0; a<CM_TOT; a++) { + for (a = 0; a < CM_TOT; a++) { if (cumap->cm[a].curve) MEM_freeN(cumap->cm[a].curve); if (cumap->cm[a].table) MEM_freeN(cumap->cm[a].table); if (cumap->cm[a].premultable) MEM_freeN(cumap->cm[a].premultable); @@ -112,14 +112,14 @@ CurveMapping *curvemapping_copy(CurveMapping *cumap) int a; if (cumap) { - CurveMapping *cumapn= MEM_dupallocN(cumap); - for (a=0; a<CM_TOT; a++) { + CurveMapping *cumapn = MEM_dupallocN(cumap); + for (a = 0; a < CM_TOT; a++) { if (cumap->cm[a].curve) - cumapn->cm[a].curve= MEM_dupallocN(cumap->cm[a].curve); + cumapn->cm[a].curve = MEM_dupallocN(cumap->cm[a].curve); if (cumap->cm[a].table) - cumapn->cm[a].table= MEM_dupallocN(cumap->cm[a].table); + cumapn->cm[a].table = MEM_dupallocN(cumap->cm[a].table); if (cumap->cm[a].premultable) - cumapn->cm[a].premultable= MEM_dupallocN(cumap->cm[a].premultable); + cumapn->cm[a].premultable = MEM_dupallocN(cumap->cm[a].premultable); } return cumapn; } @@ -135,11 +135,11 @@ void curvemapping_set_black_white(CurveMapping *cumap, const float black[3], con if (black) copy_v3_v3(cumap->black, black); - for (a=0; a<3; a++) { - if (cumap->white[a]==cumap->black[a]) - cumap->bwmul[a]= 0.0f; + for (a = 0; a < 3; a++) { + if (cumap->white[a] == cumap->black[a]) + cumap->bwmul[a] = 0.0f; else - cumap->bwmul[a]= 1.0f/(cumap->white[a] - cumap->black[a]); + cumap->bwmul[a] = 1.0f / (cumap->white[a] - cumap->black[a]); } } @@ -149,52 +149,52 @@ void curvemapping_set_black_white(CurveMapping *cumap, const float black[3], con /* removes with flag set */ void curvemap_remove(CurveMap *cuma, int flag) { - CurveMapPoint *cmp= MEM_mallocN((cuma->totpoint)*sizeof(CurveMapPoint), "curve points"); - int a, b, removed=0; + CurveMapPoint *cmp = MEM_mallocN((cuma->totpoint) * sizeof(CurveMapPoint), "curve points"); + int a, b, removed = 0; /* well, lets keep the two outer points! */ - cmp[0]= cuma->curve[0]; - for (a=1, b=1; a<cuma->totpoint-1; a++) { + cmp[0] = cuma->curve[0]; + for (a = 1, b = 1; a < cuma->totpoint - 1; a++) { if (!(cuma->curve[a].flag & flag)) { - cmp[b]= cuma->curve[a]; + cmp[b] = cuma->curve[a]; b++; } else removed++; } - cmp[b]= cuma->curve[a]; + cmp[b] = cuma->curve[a]; MEM_freeN(cuma->curve); - cuma->curve= cmp; + cuma->curve = cmp; cuma->totpoint -= removed; } void curvemap_insert(CurveMap *cuma, float x, float y) { - CurveMapPoint *cmp= MEM_callocN((cuma->totpoint+1)*sizeof(CurveMapPoint), "curve points"); - int a, b, foundloc= 0; + CurveMapPoint *cmp = MEM_callocN((cuma->totpoint + 1) * sizeof(CurveMapPoint), "curve points"); + int a, b, foundloc = 0; /* insert fragments of the old one and the new point to the new curve */ cuma->totpoint++; - for (a=0, b=0; a<cuma->totpoint; a++) { + for (a = 0, b = 0; a < cuma->totpoint; a++) { if ((x < cuma->curve[a].x) && !foundloc) { - cmp[a].x= x; - cmp[a].y= y; - cmp[a].flag= CUMA_SELECT; - foundloc= 1; + cmp[a].x = x; + cmp[a].y = y; + cmp[a].flag = CUMA_SELECT; + foundloc = 1; } else { - cmp[a].x= cuma->curve[b].x; - cmp[a].y= cuma->curve[b].y; - cmp[a].flag= cuma->curve[b].flag; + cmp[a].x = cuma->curve[b].x; + cmp[a].y = cuma->curve[b].y; + cmp[a].flag = cuma->curve[b].flag; cmp[a].flag &= ~CUMA_SELECT; /* make sure old points don't remain selected */ - cmp[a].shorty= cuma->curve[b].shorty; + cmp[a].shorty = cuma->curve[b].shorty; b++; } } /* free old curve and replace it with new one */ MEM_freeN(cuma->curve); - cuma->curve= cmp; + cuma->curve = cmp; } void curvemap_reset(CurveMap *cuma, rctf *clipr, int preset, int slope) @@ -203,91 +203,91 @@ void curvemap_reset(CurveMap *cuma, rctf *clipr, int preset, int slope) MEM_freeN(cuma->curve); switch (preset) { - case CURVE_PRESET_LINE: cuma->totpoint= 2; break; - case CURVE_PRESET_SHARP: cuma->totpoint= 4; break; - case CURVE_PRESET_SMOOTH: cuma->totpoint= 4; break; - case CURVE_PRESET_MAX: cuma->totpoint= 2; break; - case CURVE_PRESET_MID9: cuma->totpoint= 9; break; - case CURVE_PRESET_ROUND: cuma->totpoint= 4; break; - case CURVE_PRESET_ROOT: cuma->totpoint= 4; break; + case CURVE_PRESET_LINE: cuma->totpoint = 2; break; + case CURVE_PRESET_SHARP: cuma->totpoint = 4; break; + case CURVE_PRESET_SMOOTH: cuma->totpoint = 4; break; + case CURVE_PRESET_MAX: cuma->totpoint = 2; break; + case CURVE_PRESET_MID9: cuma->totpoint = 9; break; + case CURVE_PRESET_ROUND: cuma->totpoint = 4; break; + case CURVE_PRESET_ROOT: cuma->totpoint = 4; break; } - cuma->curve= MEM_callocN(cuma->totpoint*sizeof(CurveMapPoint), "curve points"); + cuma->curve = MEM_callocN(cuma->totpoint * sizeof(CurveMapPoint), "curve points"); switch (preset) { case CURVE_PRESET_LINE: - cuma->curve[0].x= clipr->xmin; - cuma->curve[0].y= clipr->ymax; - cuma->curve[0].flag= 0; - cuma->curve[1].x= clipr->xmax; - cuma->curve[1].y= clipr->ymin; - cuma->curve[1].flag= 0; + cuma->curve[0].x = clipr->xmin; + cuma->curve[0].y = clipr->ymax; + cuma->curve[0].flag = 0; + cuma->curve[1].x = clipr->xmax; + cuma->curve[1].y = clipr->ymin; + cuma->curve[1].flag = 0; break; case CURVE_PRESET_SHARP: - cuma->curve[0].x= 0; - cuma->curve[0].y= 1; - cuma->curve[1].x= 0.25; - cuma->curve[1].y= 0.50; - cuma->curve[2].x= 0.75; - cuma->curve[2].y= 0.04; - cuma->curve[3].x= 1; - cuma->curve[3].y= 0; + cuma->curve[0].x = 0; + cuma->curve[0].y = 1; + cuma->curve[1].x = 0.25; + cuma->curve[1].y = 0.50; + cuma->curve[2].x = 0.75; + cuma->curve[2].y = 0.04; + cuma->curve[3].x = 1; + cuma->curve[3].y = 0; break; case CURVE_PRESET_SMOOTH: - cuma->curve[0].x= 0; - cuma->curve[0].y= 1; - cuma->curve[1].x= 0.25; - cuma->curve[1].y= 0.94; - cuma->curve[2].x= 0.75; - cuma->curve[2].y= 0.06; - cuma->curve[3].x= 1; - cuma->curve[3].y= 0; + cuma->curve[0].x = 0; + cuma->curve[0].y = 1; + cuma->curve[1].x = 0.25; + cuma->curve[1].y = 0.94; + cuma->curve[2].x = 0.75; + cuma->curve[2].y = 0.06; + cuma->curve[3].x = 1; + cuma->curve[3].y = 0; break; case CURVE_PRESET_MAX: - cuma->curve[0].x= 0; - cuma->curve[0].y= 1; - cuma->curve[1].x= 1; - cuma->curve[1].y= 1; + cuma->curve[0].x = 0; + cuma->curve[0].y = 1; + cuma->curve[1].x = 1; + cuma->curve[1].y = 1; break; case CURVE_PRESET_MID9: - { - int i; - for (i = 0; i < cuma->totpoint; i++) { - cuma->curve[i].x = i / ((float)cuma->totpoint - 1); - cuma->curve[i].y = 0.5; - } + { + int i; + for (i = 0; i < cuma->totpoint; i++) { + cuma->curve[i].x = i / ((float)cuma->totpoint - 1); + cuma->curve[i].y = 0.5; } - break; + } + break; case CURVE_PRESET_ROUND: - cuma->curve[0].x= 0; - cuma->curve[0].y= 1; - cuma->curve[1].x= 0.5; - cuma->curve[1].y= 0.90; - cuma->curve[2].x= 0.86; - cuma->curve[2].y= 0.5; - cuma->curve[3].x= 1; - cuma->curve[3].y= 0; + cuma->curve[0].x = 0; + cuma->curve[0].y = 1; + cuma->curve[1].x = 0.5; + cuma->curve[1].y = 0.90; + cuma->curve[2].x = 0.86; + cuma->curve[2].y = 0.5; + cuma->curve[3].x = 1; + cuma->curve[3].y = 0; break; case CURVE_PRESET_ROOT: - cuma->curve[0].x= 0; - cuma->curve[0].y= 1; - cuma->curve[1].x= 0.25; - cuma->curve[1].y= 0.95; - cuma->curve[2].x= 0.75; - cuma->curve[2].y= 0.44; - cuma->curve[3].x= 1; - cuma->curve[3].y= 0; + cuma->curve[0].x = 0; + cuma->curve[0].y = 1; + cuma->curve[1].x = 0.25; + cuma->curve[1].y = 0.95; + cuma->curve[2].x = 0.75; + cuma->curve[2].y = 0.44; + cuma->curve[3].x = 1; + cuma->curve[3].y = 0; break; } /* mirror curve in x direction to have positive slope * rather than default negative slope */ if (slope == CURVEMAP_SLOPE_POSITIVE) { - int i, last=cuma->totpoint-1; - CurveMapPoint *newpoints= MEM_dupallocN(cuma->curve); + int i, last = cuma->totpoint - 1; + CurveMapPoint *newpoints = MEM_dupallocN(cuma->curve); - for (i=0; i<cuma->totpoint; i++) { - newpoints[i].y = cuma->curve[last-i].y; + for (i = 0; i < cuma->totpoint; i++) { + newpoints[i].y = cuma->curve[last - i].y; } MEM_freeN(cuma->curve); @@ -296,7 +296,7 @@ void curvemap_reset(CurveMap *cuma, rctf *clipr, int preset, int slope) if (cuma->table) { MEM_freeN(cuma->table); - cuma->table= NULL; + cuma->table = NULL; } } @@ -305,7 +305,7 @@ void curvemap_sethandle(CurveMap *cuma, int type) { int a; - for (a=0; a<cuma->totpoint; a++) { + for (a = 0; a < cuma->totpoint; a++) { if (cuma->curve[a].flag & CUMA_SELECT) { if (type) cuma->curve[a].flag |= CUMA_VECTOR; else cuma->curve[a].flag &= ~CUMA_VECTOR; @@ -322,65 +322,65 @@ static void calchandle_curvemap(BezTriple *bezt, BezTriple *prev, BezTriple *nex float len, len_a, len_b; float dvec_a[2], dvec_b[2]; - if (bezt->h1==0 && bezt->h2==0) { + if (bezt->h1 == 0 && bezt->h2 == 0) { return; } - p2= bezt->vec[1]; + p2 = bezt->vec[1]; - if (prev==NULL) { - p3= next->vec[1]; - pt[0]= 2.0f*p2[0] - p3[0]; - pt[1]= 2.0f*p2[1] - p3[1]; - p1= pt; + if (prev == NULL) { + p3 = next->vec[1]; + pt[0] = 2.0f * p2[0] - p3[0]; + pt[1] = 2.0f * p2[1] - p3[1]; + p1 = pt; } else { - p1= prev->vec[1]; + p1 = prev->vec[1]; } - if (next==NULL) { - p1= prev->vec[1]; - pt[0]= 2.0f*p2[0] - p1[0]; - pt[1]= 2.0f*p2[1] - p1[1]; - p3= pt; + if (next == NULL) { + p1 = prev->vec[1]; + pt[0] = 2.0f * p2[0] - p1[0]; + pt[1] = 2.0f * p2[1] - p1[1]; + p3 = pt; } else { - p3= next->vec[1]; + p3 = next->vec[1]; } sub_v2_v2v2(dvec_a, p2, p1); sub_v2_v2v2(dvec_b, p3, p2); - len_a= len_v2(dvec_a); - len_b= len_v2(dvec_b); + len_a = len_v2(dvec_a); + len_b = len_v2(dvec_b); - if (len_a==0.0f) len_a=1.0f; - if (len_b==0.0f) len_b=1.0f; + if (len_a == 0.0f) len_a = 1.0f; + if (len_b == 0.0f) len_b = 1.0f; - if (bezt->h1==HD_AUTO || bezt->h2==HD_AUTO) { /* auto */ + if (bezt->h1 == HD_AUTO || bezt->h2 == HD_AUTO) { /* auto */ float tvec[2]; - tvec[0]= dvec_b[0]/len_b + dvec_a[0]/len_a; - tvec[1]= dvec_b[1]/len_b + dvec_a[1]/len_a; + tvec[0] = dvec_b[0] / len_b + dvec_a[0] / len_a; + tvec[1] = dvec_b[1] / len_b + dvec_a[1] / len_a; - len= len_v2(tvec) * 2.5614f; - if (len!=0.0f) { + len = len_v2(tvec) * 2.5614f; + if (len != 0.0f) { - if (bezt->h1==HD_AUTO) { - len_a/=len; - madd_v2_v2v2fl(p2-3, p2, tvec, -len_a); + if (bezt->h1 == HD_AUTO) { + len_a /= len; + madd_v2_v2v2fl(p2 - 3, p2, tvec, -len_a); } - if (bezt->h2==HD_AUTO) { - len_b/=len; - madd_v2_v2v2fl(p2+3, p2, tvec, len_b); + if (bezt->h2 == HD_AUTO) { + len_b /= len; + madd_v2_v2v2fl(p2 + 3, p2, tvec, len_b); } } } - if (bezt->h1==HD_VECT) { /* vector */ - madd_v2_v2v2fl(p2-3, p2, dvec_a, -1.0f/3.0f); + if (bezt->h1 == HD_VECT) { /* vector */ + madd_v2_v2v2fl(p2 - 3, p2, dvec_a, -1.0f / 3.0f); } - if (bezt->h2==HD_VECT) { - madd_v2_v2v2fl(p2+3, p2, dvec_b, 1.0f/3.0f); + if (bezt->h2 == HD_VECT) { + madd_v2_v2v2fl(p2 + 3, p2, dvec_b, 1.0f / 3.0f); } } @@ -389,27 +389,27 @@ static void calchandle_curvemap(BezTriple *bezt, BezTriple *prev, BezTriple *nex static float curvemap_calc_extend(CurveMap *cuma, float x, const float first[2], const float last[2]) { if (x <= first[0]) { - if ((cuma->flag & CUMA_EXTEND_EXTRAPOLATE)==0) { + if ((cuma->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) { /* no extrapolate */ return first[1]; } else { - if (cuma->ext_in[0]==0.0f) - return first[1] + cuma->ext_in[1]*10000.0f; + if (cuma->ext_in[0] == 0.0f) + return first[1] + cuma->ext_in[1] * 10000.0f; else - return first[1] + cuma->ext_in[1]*(x - first[0])/cuma->ext_in[0]; + return first[1] + cuma->ext_in[1] * (x - first[0]) / cuma->ext_in[0]; } } else if (x >= last[0]) { - if ((cuma->flag & CUMA_EXTEND_EXTRAPOLATE)==0) { + if ((cuma->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) { /* no extrapolate */ return last[1]; } else { - if (cuma->ext_out[0]==0.0f) - return last[1] - cuma->ext_out[1]*10000.0f; + if (cuma->ext_out[0] == 0.0f) + return last[1] - cuma->ext_out[1] * 10000.0f; else - return last[1] + cuma->ext_out[1]*(x - last[0])/cuma->ext_out[0]; + return last[1] + cuma->ext_out[1] * (x - last[0]) / cuma->ext_out[0]; } } return 0.0f; @@ -418,74 +418,74 @@ static float curvemap_calc_extend(CurveMap *cuma, float x, const float first[2], /* only creates a table for a single channel in CurveMapping */ static void curvemap_make_table(CurveMap *cuma, rctf *clipr) { - CurveMapPoint *cmp= cuma->curve; + CurveMapPoint *cmp = cuma->curve; BezTriple *bezt; float *fp, *allpoints, *lastpoint, curf, range; int a, totpoint; - if (cuma->curve==NULL) return; + if (cuma->curve == NULL) return; /* default rect also is table range */ - cuma->mintable= clipr->xmin; - cuma->maxtable= clipr->xmax; + cuma->mintable = clipr->xmin; + cuma->maxtable = clipr->xmax; /* hrmf... we now rely on blender ipo beziers, these are more advanced */ - bezt= MEM_callocN(cuma->totpoint*sizeof(BezTriple), "beztarr"); + bezt = MEM_callocN(cuma->totpoint * sizeof(BezTriple), "beztarr"); - for (a=0; a<cuma->totpoint; a++) { - cuma->mintable= MIN2(cuma->mintable, cmp[a].x); - cuma->maxtable= MAX2(cuma->maxtable, cmp[a].x); - bezt[a].vec[1][0]= cmp[a].x; - bezt[a].vec[1][1]= cmp[a].y; + for (a = 0; a < cuma->totpoint; a++) { + cuma->mintable = MIN2(cuma->mintable, cmp[a].x); + cuma->maxtable = MAX2(cuma->maxtable, cmp[a].x); + bezt[a].vec[1][0] = cmp[a].x; + bezt[a].vec[1][1] = cmp[a].y; if (cmp[a].flag & CUMA_VECTOR) - bezt[a].h1= bezt[a].h2= HD_VECT; + bezt[a].h1 = bezt[a].h2 = HD_VECT; else - bezt[a].h1= bezt[a].h2= HD_AUTO; + bezt[a].h1 = bezt[a].h2 = HD_AUTO; } - for (a=0; a<cuma->totpoint; a++) { - if (a==0) - calchandle_curvemap(bezt, NULL, bezt+1, 0); - else if (a==cuma->totpoint-1) - calchandle_curvemap(bezt+a, bezt+a-1, NULL, 0); + for (a = 0; a < cuma->totpoint; a++) { + if (a == 0) + calchandle_curvemap(bezt, NULL, bezt + 1, 0); + else if (a == cuma->totpoint - 1) + calchandle_curvemap(bezt + a, bezt + a - 1, NULL, 0); else - calchandle_curvemap(bezt+a, bezt+a-1, bezt+a+1, 0); + calchandle_curvemap(bezt + a, bezt + a - 1, bezt + a + 1, 0); } /* first and last handle need correction, instead of pointing to center of next/prev, * we let it point to the closest handle */ - if (cuma->totpoint>2) { + if (cuma->totpoint > 2) { float hlen, nlen, vec[3]; - if (bezt[0].h2==HD_AUTO) { + if (bezt[0].h2 == HD_AUTO) { - hlen= len_v3v3(bezt[0].vec[1], bezt[0].vec[2]); /* original handle length */ + hlen = len_v3v3(bezt[0].vec[1], bezt[0].vec[2]); /* original handle length */ /* clip handle point */ copy_v3_v3(vec, bezt[1].vec[0]); if (vec[0] < bezt[0].vec[1][0]) - vec[0]= bezt[0].vec[1][0]; + vec[0] = bezt[0].vec[1][0]; sub_v3_v3(vec, bezt[0].vec[1]); - nlen= len_v3(vec); - if (nlen>FLT_EPSILON) { - mul_v3_fl(vec, hlen/nlen); + nlen = len_v3(vec); + if (nlen > FLT_EPSILON) { + mul_v3_fl(vec, hlen / nlen); add_v3_v3v3(bezt[0].vec[2], vec, bezt[0].vec[1]); sub_v3_v3v3(bezt[0].vec[0], bezt[0].vec[1], vec); } } - a= cuma->totpoint-1; - if (bezt[a].h2==HD_AUTO) { + a = cuma->totpoint - 1; + if (bezt[a].h2 == HD_AUTO) { - hlen= len_v3v3(bezt[a].vec[1], bezt[a].vec[0]); /* original handle length */ + hlen = len_v3v3(bezt[a].vec[1], bezt[a].vec[0]); /* original handle length */ /* clip handle point */ - copy_v3_v3(vec, bezt[a-1].vec[2]); + copy_v3_v3(vec, bezt[a - 1].vec[2]); if (vec[0] > bezt[a].vec[1][0]) - vec[0]= bezt[a].vec[1][0]; + vec[0] = bezt[a].vec[1][0]; sub_v3_v3(vec, bezt[a].vec[1]); - nlen= len_v3(vec); - if (nlen>FLT_EPSILON) { - mul_v3_fl(vec, hlen/nlen); + nlen = len_v3(vec); + if (nlen > FLT_EPSILON) { + mul_v3_fl(vec, hlen / nlen); add_v3_v3v3(bezt[a].vec[0], vec, bezt[a].vec[1]); sub_v3_v3v3(bezt[a].vec[2], bezt[a].vec[1], vec); } @@ -494,63 +494,63 @@ static void curvemap_make_table(CurveMap *cuma, rctf *clipr) /* make the bezier curve */ if (cuma->table) MEM_freeN(cuma->table); - totpoint= (cuma->totpoint-1)*CM_RESOL; - fp= allpoints= MEM_callocN(totpoint*2*sizeof(float), "table"); + totpoint = (cuma->totpoint - 1) * CM_RESOL; + fp = allpoints = MEM_callocN(totpoint * 2 * sizeof(float), "table"); - for (a=0; a<cuma->totpoint-1; a++, fp += 2*CM_RESOL) { - correct_bezpart(bezt[a].vec[1], bezt[a].vec[2], bezt[a+1].vec[0], bezt[a+1].vec[1]); - BKE_curve_forward_diff_bezier(bezt[a].vec[1][0], bezt[a].vec[2][0], bezt[a+1].vec[0][0], bezt[a+1].vec[1][0], fp, CM_RESOL-1, 2*sizeof(float)); - BKE_curve_forward_diff_bezier(bezt[a].vec[1][1], bezt[a].vec[2][1], bezt[a+1].vec[0][1], bezt[a+1].vec[1][1], fp+1, CM_RESOL-1, 2*sizeof(float)); + for (a = 0; a < cuma->totpoint - 1; a++, fp += 2 * CM_RESOL) { + correct_bezpart(bezt[a].vec[1], bezt[a].vec[2], bezt[a + 1].vec[0], bezt[a + 1].vec[1]); + BKE_curve_forward_diff_bezier(bezt[a].vec[1][0], bezt[a].vec[2][0], bezt[a + 1].vec[0][0], bezt[a + 1].vec[1][0], fp, CM_RESOL - 1, 2 * sizeof(float)); + BKE_curve_forward_diff_bezier(bezt[a].vec[1][1], bezt[a].vec[2][1], bezt[a + 1].vec[0][1], bezt[a + 1].vec[1][1], fp + 1, CM_RESOL - 1, 2 * sizeof(float)); } /* store first and last handle for extrapolation, unit length */ - cuma->ext_in[0]= bezt[0].vec[0][0] - bezt[0].vec[1][0]; - cuma->ext_in[1]= bezt[0].vec[0][1] - bezt[0].vec[1][1]; - range= sqrt(cuma->ext_in[0]*cuma->ext_in[0] + cuma->ext_in[1]*cuma->ext_in[1]); - cuma->ext_in[0]/= range; - cuma->ext_in[1]/= range; - - a= cuma->totpoint-1; - cuma->ext_out[0]= bezt[a].vec[1][0] - bezt[a].vec[2][0]; - cuma->ext_out[1]= bezt[a].vec[1][1] - bezt[a].vec[2][1]; - range= sqrt(cuma->ext_out[0]*cuma->ext_out[0] + cuma->ext_out[1]*cuma->ext_out[1]); - cuma->ext_out[0]/= range; - cuma->ext_out[1]/= range; + cuma->ext_in[0] = bezt[0].vec[0][0] - bezt[0].vec[1][0]; + cuma->ext_in[1] = bezt[0].vec[0][1] - bezt[0].vec[1][1]; + range = sqrt(cuma->ext_in[0] * cuma->ext_in[0] + cuma->ext_in[1] * cuma->ext_in[1]); + cuma->ext_in[0] /= range; + cuma->ext_in[1] /= range; + + a = cuma->totpoint - 1; + cuma->ext_out[0] = bezt[a].vec[1][0] - bezt[a].vec[2][0]; + cuma->ext_out[1] = bezt[a].vec[1][1] - bezt[a].vec[2][1]; + range = sqrt(cuma->ext_out[0] * cuma->ext_out[0] + cuma->ext_out[1] * cuma->ext_out[1]); + cuma->ext_out[0] /= range; + cuma->ext_out[1] /= range; /* cleanup */ MEM_freeN(bezt); - range= CM_TABLEDIV*(cuma->maxtable - cuma->mintable); - cuma->range= 1.0f/range; + range = CM_TABLEDIV * (cuma->maxtable - cuma->mintable); + cuma->range = 1.0f / range; /* now make a table with CM_TABLE equal x distances */ - fp= allpoints; - lastpoint= allpoints + 2*(totpoint-1); - cmp= MEM_callocN((CM_TABLE+1)*sizeof(CurveMapPoint), "dist table"); - - for (a=0; a<=CM_TABLE; a++) { - curf= cuma->mintable + range*(float)a; - cmp[a].x= curf; + fp = allpoints; + lastpoint = allpoints + 2 * (totpoint - 1); + cmp = MEM_callocN((CM_TABLE + 1) * sizeof(CurveMapPoint), "dist table"); + + for (a = 0; a <= CM_TABLE; a++) { + curf = cuma->mintable + range * (float)a; + cmp[a].x = curf; /* get the first x coordinate larger than curf */ - while (curf >= fp[0] && fp!=lastpoint) { - fp+=2; + while (curf >= fp[0] && fp != lastpoint) { + fp += 2; } - if (fp==allpoints || (curf >= fp[0] && fp==lastpoint)) - cmp[a].y= curvemap_calc_extend(cuma, curf, allpoints, lastpoint); + if (fp == allpoints || (curf >= fp[0] && fp == lastpoint)) + cmp[a].y = curvemap_calc_extend(cuma, curf, allpoints, lastpoint); else { - float fac1= fp[0] - fp[-2]; - float fac2= fp[0] - curf; + float fac1 = fp[0] - fp[-2]; + float fac2 = fp[0] - curf; if (fac1 > FLT_EPSILON) - fac1= fac2/fac1; + fac1 = fac2 / fac1; else - fac1= 0.0f; - cmp[a].y= fac1*fp[-1] + (1.0f-fac1)*fp[1]; + fac1 = 0.0f; + cmp[a].y = fac1 * fp[-1] + (1.0f - fac1) * fp[1]; } } MEM_freeN(allpoints); - cuma->table= cmp; + cuma->table = cmp; } /* call when you do images etc, needs restore too. also verifies tables */ @@ -561,34 +561,34 @@ void curvemapping_premultiply(CurveMapping *cumap, int restore) if (restore) { if (cumap->flag & CUMA_PREMULLED) { - for (a=0; a<3; a++) { + for (a = 0; a < 3; a++) { MEM_freeN(cumap->cm[a].table); - cumap->cm[a].table= cumap->cm[a].premultable; - cumap->cm[a].premultable= NULL; + cumap->cm[a].table = cumap->cm[a].premultable; + cumap->cm[a].premultable = NULL; } cumap->flag &= ~CUMA_PREMULLED; } } else { - if ((cumap->flag & CUMA_PREMULLED)==0) { + if ((cumap->flag & CUMA_PREMULLED) == 0) { /* verify and copy */ - for (a=0; a<3; a++) { - if (cumap->cm[a].table==NULL) - curvemap_make_table(cumap->cm+a, &cumap->clipr); - cumap->cm[a].premultable= cumap->cm[a].table; - cumap->cm[a].table= MEM_mallocN((CM_TABLE+1)*sizeof(CurveMapPoint), "premul table"); - memcpy(cumap->cm[a].table, cumap->cm[a].premultable, (CM_TABLE+1)*sizeof(CurveMapPoint)); + for (a = 0; a < 3; a++) { + if (cumap->cm[a].table == NULL) + curvemap_make_table(cumap->cm + a, &cumap->clipr); + cumap->cm[a].premultable = cumap->cm[a].table; + cumap->cm[a].table = MEM_mallocN((CM_TABLE + 1) * sizeof(CurveMapPoint), "premul table"); + memcpy(cumap->cm[a].table, cumap->cm[a].premultable, (CM_TABLE + 1) * sizeof(CurveMapPoint)); } - if (cumap->cm[3].table==NULL) - curvemap_make_table(cumap->cm+3, &cumap->clipr); + if (cumap->cm[3].table == NULL) + curvemap_make_table(cumap->cm + 3, &cumap->clipr); /* premul */ - for (a=0; a<3; a++) { + for (a = 0; a < 3; a++) { int b; - for (b=0; b<=CM_TABLE; b++) { - cumap->cm[a].table[b].y= curvemap_evaluateF(cumap->cm+3, cumap->cm[a].table[b].y); + for (b = 0; b <= CM_TABLE; b++) { + cumap->cm[a].table[b].y = curvemap_evaluateF(cumap->cm + 3, cumap->cm[a].table[b].y); } } @@ -599,10 +599,10 @@ void curvemapping_premultiply(CurveMapping *cumap, int restore) static int sort_curvepoints(const void *a1, const void *a2) { - const struct CurveMapPoint *x1=a1, *x2=a2; + const struct CurveMapPoint *x1 = a1, *x2 = a2; - if ( x1->x > x2->x ) return 1; - else if ( x1->x < x2->x) return -1; + if (x1->x > x2->x) return 1; + else if (x1->x < x2->x) return -1; return 0; } @@ -611,30 +611,30 @@ static int sort_curvepoints(const void *a1, const void *a2) /* note; only does current curvemap! */ void curvemapping_changed(CurveMapping *cumap, int rem_doubles) { - CurveMap *cuma= cumap->cm+cumap->cur; - CurveMapPoint *cmp= cuma->curve; - rctf *clipr= &cumap->clipr; - float thresh= 0.01f*(clipr->xmax - clipr->xmin); - float dx= 0.0f, dy= 0.0f; + CurveMap *cuma = cumap->cm + cumap->cur; + CurveMapPoint *cmp = cuma->curve; + rctf *clipr = &cumap->clipr; + float thresh = 0.01f * (clipr->xmax - clipr->xmin); + float dx = 0.0f, dy = 0.0f; int a; cumap->changed_timestamp++; /* clamp with clip */ if (cumap->flag & CUMA_DO_CLIP) { - for (a=0; a<cuma->totpoint; a++) { + for (a = 0; a < cuma->totpoint; a++) { if (cmp[a].flag & CUMA_SELECT) { if (cmp[a].x < clipr->xmin) - dx= MIN2(dx, cmp[a].x - clipr->xmin); + dx = MIN2(dx, cmp[a].x - clipr->xmin); else if (cmp[a].x > clipr->xmax) - dx= MAX2(dx, cmp[a].x - clipr->xmax); + dx = MAX2(dx, cmp[a].x - clipr->xmax); if (cmp[a].y < clipr->ymin) - dy= MIN2(dy, cmp[a].y - clipr->ymin); + dy = MIN2(dy, cmp[a].y - clipr->ymin); else if (cmp[a].y > clipr->ymax) - dy= MAX2(dy, cmp[a].y - clipr->ymax); + dy = MAX2(dy, cmp[a].y - clipr->ymax); } } - for (a=0; a<cuma->totpoint; a++) { + for (a = 0; a < cuma->totpoint; a++) { if (cmp[a].flag & CUMA_SELECT) { cmp[a].x -= dx; cmp[a].y -= dy; @@ -646,25 +646,25 @@ void curvemapping_changed(CurveMapping *cumap, int rem_doubles) qsort(cmp, cuma->totpoint, sizeof(CurveMapPoint), sort_curvepoints); /* remove doubles, threshold set on 1% of default range */ - if (rem_doubles && cuma->totpoint>2) { - 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 ( sqrtf(dx*dx + dy*dy) < thresh ) { - if (a==0) { - cmp[a+1].flag|= 2; - if (cmp[a+1].flag & CUMA_SELECT) + if (rem_doubles && cuma->totpoint > 2) { + 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 (sqrtf(dx * dx + dy * dy) < thresh) { + if (a == 0) { + cmp[a + 1].flag |= 2; + if (cmp[a + 1].flag & CUMA_SELECT) cmp[a].flag |= CUMA_SELECT; } else { - cmp[a].flag|= 2; + cmp[a].flag |= 2; if (cmp[a].flag & CUMA_SELECT) - cmp[a+1].flag |= CUMA_SELECT; + cmp[a + 1].flag |= CUMA_SELECT; } - break; /* we assume 1 deletion per edit is ok */ + break; /* we assume 1 deletion per edit is ok */ } } - if (a != cuma->totpoint-1) + if (a != cuma->totpoint - 1) curvemap_remove(cuma, 2); } curvemap_make_table(cuma, clipr); @@ -677,31 +677,31 @@ float curvemap_evaluateF(CurveMap *cuma, float value) int i; /* index in table */ - fi= (value-cuma->mintable)*cuma->range; - i= (int)fi; + fi = (value - cuma->mintable) * cuma->range; + i = (int)fi; /* fi is table float index and should check against table range i.e. [0.0 CM_TABLE] */ - if (fi<0.0f || fi>CM_TABLE) + if (fi < 0.0f || fi > CM_TABLE) return curvemap_calc_extend(cuma, value, &cuma->table[0].x, &cuma->table[CM_TABLE].x); else { - if (i<0) return cuma->table[0].y; - if (i>=CM_TABLE) return cuma->table[CM_TABLE].y; + if (i < 0) return cuma->table[0].y; + if (i >= CM_TABLE) return cuma->table[CM_TABLE].y; - fi= fi-(float)i; - return (1.0f-fi)*cuma->table[i].y + (fi)*cuma->table[i+1].y; + fi = fi - (float)i; + return (1.0f - fi) * cuma->table[i].y + (fi) * cuma->table[i + 1].y; } } /* works with curve 'cur' */ float curvemapping_evaluateF(CurveMapping *cumap, int cur, float value) { - CurveMap *cuma= cumap->cm+cur; + CurveMap *cuma = cumap->cm + cur; /* allocate or bail out */ - if (cuma->table==NULL) { + if (cuma->table == NULL) { curvemap_make_table(cuma, &cumap->clipr); - if (cuma->table==NULL) - return 1.0f-value; + if (cuma->table == NULL) + return 1.0f - value; } return curvemap_evaluateF(cuma, value); } @@ -709,17 +709,17 @@ float curvemapping_evaluateF(CurveMapping *cumap, int cur, float value) /* vector case */ void curvemapping_evaluate3F(CurveMapping *cumap, float vecout[3], const float vecin[3]) { - vecout[0]= curvemapping_evaluateF(cumap, 0, vecin[0]); - vecout[1]= curvemapping_evaluateF(cumap, 1, vecin[1]); - vecout[2]= curvemapping_evaluateF(cumap, 2, vecin[2]); + vecout[0] = curvemapping_evaluateF(cumap, 0, vecin[0]); + vecout[1] = curvemapping_evaluateF(cumap, 1, vecin[1]); + vecout[2] = curvemapping_evaluateF(cumap, 2, vecin[2]); } /* RGB case, no black/white points, no premult */ void curvemapping_evaluateRGBF(CurveMapping *cumap, float vecout[3], const float vecin[3]) { - vecout[0]= curvemapping_evaluateF(cumap, 0, curvemapping_evaluateF(cumap, 3, vecin[0])); - vecout[1]= curvemapping_evaluateF(cumap, 1, curvemapping_evaluateF(cumap, 3, vecin[1])); - vecout[2]= curvemapping_evaluateF(cumap, 2, curvemapping_evaluateF(cumap, 3, vecin[2])); + vecout[0] = curvemapping_evaluateF(cumap, 0, curvemapping_evaluateF(cumap, 3, vecin[0])); + vecout[1] = curvemapping_evaluateF(cumap, 1, curvemapping_evaluateF(cumap, 3, vecin[1])); + vecout[2] = curvemapping_evaluateF(cumap, 2, curvemapping_evaluateF(cumap, 3, vecin[2])); } @@ -728,14 +728,14 @@ void curvemapping_evaluate_premulRGBF(CurveMapping *cumap, float vecout[3], cons { float fac; - fac= (vecin[0] - cumap->black[0])*cumap->bwmul[0]; - vecout[0]= curvemap_evaluateF(cumap->cm, fac); + fac = (vecin[0] - cumap->black[0]) * cumap->bwmul[0]; + vecout[0] = curvemap_evaluateF(cumap->cm, fac); - fac= (vecin[1] - cumap->black[1])*cumap->bwmul[1]; - vecout[1]= curvemap_evaluateF(cumap->cm+1, fac); + fac = (vecin[1] - cumap->black[1]) * cumap->bwmul[1]; + vecout[1] = curvemap_evaluateF(cumap->cm + 1, fac); - fac= (vecin[2] - cumap->black[2])*cumap->bwmul[2]; - vecout[2]= curvemap_evaluateF(cumap->cm+2, fac); + fac = (vecin[2] - cumap->black[2]) * cumap->bwmul[2]; + vecout[2] = curvemap_evaluateF(cumap->cm + 2, fac); } @@ -746,14 +746,14 @@ void curvemapping_do_ibuf(CurveMapping *cumap, ImBuf *ibuf) int pixel; float *pix_in; float col[3]; - int stride= 4; + int stride = 4; float *pix_out; - if (ibuf==NULL) + if (ibuf == NULL) return; - if (ibuf->rect_float==NULL) + if (ibuf->rect_float == NULL) IMB_float_from_rect(ibuf); - else if (ibuf->rect==NULL) + else if (ibuf->rect == NULL) imb_addrectImBuf(ibuf); if (!ibuf->rect || !ibuf->rect_float) @@ -765,27 +765,27 @@ void curvemapping_do_ibuf(CurveMapping *cumap, ImBuf *ibuf) curvemapping_premultiply(cumap, 0); - pix_in= ibuf->rect_float; - pix_out= tmpbuf->rect_float; + pix_in = ibuf->rect_float; + pix_out = tmpbuf->rect_float; if (ibuf->channels) - stride= ibuf->channels; + stride = ibuf->channels; - for (pixel= ibuf->x*ibuf->y; pixel>0; pixel--, pix_in+=stride, pix_out+=stride) { - if (stride<3) { - col[0]= curvemap_evaluateF(cumap->cm, *pix_in); + for (pixel = ibuf->x * ibuf->y; pixel > 0; pixel--, pix_in += stride, pix_out += stride) { + if (stride < 3) { + col[0] = curvemap_evaluateF(cumap->cm, *pix_in); - pix_out[1]= pix_out[2]= pix_out[3]= pix_out[0]= col[0]; + pix_out[1] = pix_out[2] = pix_out[3] = pix_out[0] = col[0]; } else { curvemapping_evaluate_premulRGBF(cumap, col, pix_in); - pix_out[0]= col[0]; - pix_out[1]= col[1]; - pix_out[2]= col[2]; - if (stride>3) - pix_out[3]= pix_in[3]; + pix_out[0] = col[0]; + pix_out[1] = col[1]; + pix_out[2] = col[2]; + if (stride > 3) + pix_out[3] = pix_in[3]; else - pix_out[3]= 1.f; + pix_out[3] = 1.f; } } @@ -800,16 +800,16 @@ int curvemapping_RGBA_does_something(CurveMapping *cumap) { int a; - if (cumap->black[0]!=0.0f) return 1; - if (cumap->black[1]!=0.0f) return 1; - if (cumap->black[2]!=0.0f) return 1; - if (cumap->white[0]!=1.0f) return 1; - if (cumap->white[1]!=1.0f) return 1; - if (cumap->white[2]!=1.0f) return 1; + if (cumap->black[0] != 0.0f) return 1; + if (cumap->black[1] != 0.0f) return 1; + if (cumap->black[2] != 0.0f) return 1; + if (cumap->white[0] != 1.0f) return 1; + if (cumap->white[1] != 1.0f) return 1; + if (cumap->white[2] != 1.0f) return 1; - for (a=0; a<CM_TOT; a++) { + for (a = 0; a < CM_TOT; a++) { if (cumap->cm[a].curve) { - if (cumap->cm[a].totpoint!=2) return 1; + if (cumap->cm[a].totpoint != 2) return 1; if (cumap->cm[a].curve[0].x != 0.0f) return 1; if (cumap->cm[a].curve[0].y != 0.0f) return 1; @@ -824,11 +824,11 @@ void curvemapping_initialize(CurveMapping *cumap) { int a; - if (cumap==NULL) return; + if (cumap == NULL) return; - for (a=0; a<CM_TOT; a++) { - if (cumap->cm[a].table==NULL) - curvemap_make_table(cumap->cm+a, &cumap->clipr); + for (a = 0; a < CM_TOT; a++) { + if (cumap->cm[a].table == NULL) + curvemap_make_table(cumap->cm + a, &cumap->clipr); } } @@ -836,29 +836,29 @@ void curvemapping_table_RGBA(CurveMapping *cumap, float **array, int *size) { int a; - *size = CM_TABLE+1; - *array = MEM_callocN(sizeof(float)*(*size)*4, "CurveMapping"); + *size = CM_TABLE + 1; + *array = MEM_callocN(sizeof(float) * (*size) * 4, "CurveMapping"); curvemapping_initialize(cumap); - for (a=0; a<*size; a++) { + for (a = 0; a < *size; a++) { if (cumap->cm[0].table) - (*array)[a*4+0]= cumap->cm[0].table[a].y; + (*array)[a * 4 + 0] = cumap->cm[0].table[a].y; if (cumap->cm[1].table) - (*array)[a*4+1]= cumap->cm[1].table[a].y; + (*array)[a * 4 + 1] = cumap->cm[1].table[a].y; if (cumap->cm[2].table) - (*array)[a*4+2]= cumap->cm[2].table[a].y; + (*array)[a * 4 + 2] = cumap->cm[2].table[a].y; if (cumap->cm[3].table) - (*array)[a*4+3]= cumap->cm[3].table[a].y; + (*array)[a * 4 + 3] = cumap->cm[3].table[a].y; } } /* ***************** Histogram **************** */ -#define INV_255 (1.f/255.f) +#define INV_255 (1.f / 255.f) DO_INLINE int get_bin_float(float f) { - int bin= (int)((f*255.0f) + 0.5f); /* 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); @@ -907,17 +907,17 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management) int x, y, c; unsigned int n, nl; double div, divl; - float *rf=NULL; - unsigned char *rc=NULL; + float *rf = NULL; + unsigned char *rc = NULL; unsigned int *bin_r, *bin_g, *bin_b, *bin_lum; int savedlines, saveline; float rgb[3], ycc[3], luma; - int ycc_mode=-1; + int ycc_mode = -1; const short is_float = (ibuf->rect_float != NULL); - if (ibuf->rect==NULL && ibuf->rect_float==NULL) return; + if (ibuf->rect == NULL && ibuf->rect_float == NULL) return; - if (scopes->ok == 1 ) return; + if (scopes->ok == 1) return; if (scopes->hist.ymax == 0.f) scopes->hist.ymax = 1.f; @@ -950,19 +950,19 @@ 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.01f) * (scopes->accuracy*0.01f) * ibuf->y; + scopes->sample_lines = (scopes->accuracy * 0.01f) * (scopes->accuracy * 0.01f) * ibuf->y; if (scopes->sample_full) scopes->sample_lines = ibuf->y; /* scan the image */ - savedlines=0; - for (c=0; c<3; c++) { - scopes->minmax[c][0]=25500.0f; - scopes->minmax[c][1]=-25500.0f; + savedlines = 0; + for (c = 0; c < 3; c++) { + scopes->minmax[c][0] = 25500.0f; + scopes->minmax[c][1] = -25500.0f; } - scopes->waveform_tot = ibuf->x*scopes->sample_lines; + scopes->waveform_tot = ibuf->x * scopes->sample_lines; if (scopes->waveform_1) MEM_freeN(scopes->waveform_1); @@ -973,10 +973,10 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management) if (scopes->vecscope) MEM_freeN(scopes->vecscope); - scopes->waveform_1= MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "waveform point channel 1"); - scopes->waveform_2= MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "waveform point channel 2"); - scopes->waveform_3= MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "waveform point channel 3"); - scopes->vecscope= MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "vectorscope point channel"); + scopes->waveform_1 = MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "waveform point channel 1"); + scopes->waveform_2 = MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "waveform point channel 2"); + scopes->waveform_3 = MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "waveform point channel 3"); + scopes->vecscope = MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "vectorscope point channel"); if (is_float) rf = ibuf->rect_float; @@ -984,7 +984,7 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management) rc = (unsigned char *)ibuf->rect; for (y = 0; y < ibuf->y; y++) { - if (savedlines<scopes->sample_lines && y>=((savedlines)*ibuf->y)/(scopes->sample_lines+1)) { + if (savedlines < scopes->sample_lines && y >= ((savedlines) * ibuf->y) / (scopes->sample_lines + 1)) { saveline = 1; } else { @@ -999,7 +999,7 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management) copy_v3_v3(rgb, rf); } else { - for (c=0; c<3; c++) + for (c = 0; c < 3; c++) rgb[c] = rc[c] * INV_255; } @@ -1007,44 +1007,44 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management) luma = rgb_to_luma(rgb); /* check for min max */ - if (ycc_mode == -1 ) { - for (c=0; c<3; c++) { + if (ycc_mode == -1) { + for (c = 0; c < 3; c++) { if (rgb[c] < scopes->minmax[c][0]) scopes->minmax[c][0] = rgb[c]; if (rgb[c] > scopes->minmax[c][1]) scopes->minmax[c][1] = rgb[c]; } } else { rgb_to_ycc(rgb[0], rgb[1], rgb[2], &ycc[0], &ycc[1], &ycc[2], ycc_mode); - for (c=0; c<3; c++) { - ycc[c] *=INV_255; + for (c = 0; c < 3; c++) { + ycc[c] *= INV_255; if (ycc[c] < scopes->minmax[c][0]) scopes->minmax[c][0] = ycc[c]; if (ycc[c] > scopes->minmax[c][1]) scopes->minmax[c][1] = ycc[c]; } } /* increment count for histo*/ - bin_r[ get_bin_float(rgb[0]) ] += 1; - bin_g[ get_bin_float(rgb[1]) ] += 1; - bin_b[ get_bin_float(rgb[2]) ] += 1; - bin_lum[ get_bin_float(luma) ] += 1; + bin_r[get_bin_float(rgb[0])] += 1; + bin_g[get_bin_float(rgb[1])] += 1; + bin_b[get_bin_float(rgb[2])] += 1; + bin_lum[get_bin_float(luma)] += 1; /* save sample if needed */ if (saveline) { const float fx = (float)x / (float)ibuf->x; - const int idx = 2*(ibuf->x*savedlines+x); + const int idx = 2 * (ibuf->x * savedlines + x); save_sample_line(scopes, idx, fx, rgb, ycc); } - rf+= ibuf->channels; - rc+= ibuf->channels; + rf += ibuf->channels; + rc += ibuf->channels; } if (saveline) - savedlines +=1; + savedlines += 1; } /* convert hist data to float (proportional to max count) */ - n=0; - nl=0; - for (x=0; x<256; x++) { + n = 0; + nl = 0; + for (x = 0; x < 256; x++) { if (bin_r[x] > n) n = bin_r[x]; if (bin_g[x] > n) @@ -1054,9 +1054,9 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management) if (bin_lum[x] > nl) nl = bin_lum[x]; } - div = 1.0/(double)n; - divl = 1.0/(double)nl; - for (x=0; x<256; x++) { + 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; scopes->hist.data_b[x] = bin_b[x] * div; @@ -1092,14 +1092,14 @@ void scopes_free(Scopes *scopes) void scopes_new(Scopes *scopes) { - scopes->accuracy=30.0; - scopes->hist.mode=HISTO_MODE_RGB; - scopes->wavefrm_alpha=0.3; - scopes->vecscope_alpha=0.3; - scopes->wavefrm_height= 100; - scopes->vecscope_height= 100; - scopes->hist.height= 100; - scopes->ok= 0; + scopes->accuracy = 30.0; + scopes->hist.mode = HISTO_MODE_RGB; + scopes->wavefrm_alpha = 0.3; + scopes->vecscope_alpha = 0.3; + scopes->wavefrm_height = 100; + scopes->vecscope_height = 100; + scopes->hist.height = 100; + scopes->ok = 0; scopes->waveform_1 = NULL; scopes->waveform_2 = NULL; scopes->waveform_3 = NULL; diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 424ded0397e..868da0fda94 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -69,7 +69,7 @@ #include "BKE_constraint.h" #include "BKE_displist.h" #include "BKE_deform.h" -#include "BKE_DerivedMesh.h" /* for geometry targets */ +#include "BKE_DerivedMesh.h" /* for geometry targets */ #include "BKE_cdderivedmesh.h" /* for geometry targets */ #include "BKE_object.h" #include "BKE_ipo.h" @@ -90,7 +90,7 @@ #endif #ifndef M_PI -#define M_PI 3.14159265358979323846 +#define M_PI 3.14159265358979323846 #endif @@ -113,15 +113,15 @@ void unique_constraint_name(bConstraint *con, ListBase *list) /* package an object/bone for use in constraint evaluation */ /* This function MEM_calloc's a bConstraintOb struct, that will need to be freed after evaluation */ -bConstraintOb *constraints_make_evalob (Scene *scene, Object *ob, void *subdata, short datatype) +bConstraintOb *constraints_make_evalob(Scene *scene, Object *ob, void *subdata, short datatype) { bConstraintOb *cob; /* create regardless of whether we have any data! */ - cob= MEM_callocN(sizeof(bConstraintOb), "bConstraintOb"); + cob = MEM_callocN(sizeof(bConstraintOb), "bConstraintOb"); /* for system time, part of deglobalization, code nicer later with local time (ton) */ - cob->scene= scene; + cob->scene = scene; /* based on type of available data */ switch (datatype) { @@ -139,7 +139,7 @@ bConstraintOb *constraints_make_evalob (Scene *scene, Object *ob, void *subdata, copy_m4_m4(cob->startmat, cob->matrix); } - break; + break; case CONSTRAINT_OBTYPE_BONE: { /* only set if we have valid bone, otherwise default */ @@ -150,11 +150,11 @@ bConstraintOb *constraints_make_evalob (Scene *scene, Object *ob, void *subdata, if (cob->pchan->rotmode > 0) { /* should be some type of Euler order */ - cob->rotOrder= cob->pchan->rotmode; + cob->rotOrder = cob->pchan->rotmode; } else { /* Quats, so eulers should just use default order */ - cob->rotOrder= EULER_ORDER_DEFAULT; + cob->rotOrder = EULER_ORDER_DEFAULT; } /* matrix in world-space */ @@ -165,7 +165,7 @@ bConstraintOb *constraints_make_evalob (Scene *scene, Object *ob, void *subdata, copy_m4_m4(cob->startmat, cob->matrix); } - break; + break; default: /* other types not yet handled */ unit_m4(cob->matrix); @@ -202,7 +202,7 @@ void constraints_clear_evalob(bConstraintOb *cob) invert_m4_m4(cob->ob->constinv, delta); } } - break; + break; case CONSTRAINT_OBTYPE_BONE: { /* cob->ob or cob->pchan might not exist */ @@ -214,7 +214,7 @@ void constraints_clear_evalob(bConstraintOb *cob) invert_m4_m4(cob->pchan->constinv, delta); } } - break; + break; } /* free tempolary struct */ @@ -278,7 +278,7 @@ void constraint_mat_convertspace(Object *ob, bPoseChannel *pchan, float mat[][4] float imat[4][4]; /* prevent crashes in these unlikely events */ - if (ob==NULL || mat==NULL) return; + if (ob == NULL || mat == NULL) return; /* optimize trick - check if need to do anything */ if (from == to) return; @@ -298,8 +298,8 @@ void constraint_mat_convertspace(Object *ob, bPoseChannel *pchan, float mat[][4] constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, to); } } - break; - case CONSTRAINT_SPACE_POSE: /* ---------- FROM POSESPACE ---------- */ + break; + case CONSTRAINT_SPACE_POSE: /* ---------- FROM POSESPACE ---------- */ { /* pose to world */ if (to == CONSTRAINT_SPACE_WORLD) { @@ -308,7 +308,7 @@ void constraint_mat_convertspace(Object *ob, bPoseChannel *pchan, float mat[][4] /* pose to local */ else if (to == CONSTRAINT_SPACE_LOCAL) { if (pchan->bone) { - armature_mat_pose_to_bone(pchan, mat, mat); + BKE_armature_mat_pose_to_bone(pchan, mat, mat); #if 0 /* XXX Old code, will remove it later. */ constraint_pchan_diff_mat(pchan, diff_mat); @@ -317,7 +317,7 @@ void constraint_mat_convertspace(Object *ob, bPoseChannel *pchan, float mat[][4] /* override with local location */ if ((pchan->parent) && (pchan->bone->flag & BONE_NO_LOCAL_LOCATION)) { - armature_mat_pose_to_bone_ex(ob, pchan, pchan->pose_mat, tempmat); + BKE_armature_mat_pose_to_bone_ex(ob, pchan, pchan->pose_mat, tempmat); copy_v3_v3(mat[3], tempmat[3]); } #endif @@ -331,13 +331,13 @@ void constraint_mat_convertspace(Object *ob, bPoseChannel *pchan, float mat[][4] } } } - break; + break; case CONSTRAINT_SPACE_LOCAL: /* ------------ FROM LOCALSPACE --------- */ { /* local to pose - do inverse procedure that was done for pose to local */ if (pchan->bone) { /* we need the posespace_matrix = local_matrix + (parent_posespace_matrix + restpos) */ - armature_mat_bone_to_pose(pchan, mat, mat); + BKE_armature_mat_bone_to_pose(pchan, mat, mat); #if 0 constraint_pchan_diff_mat(pchan, diff_mat); @@ -351,7 +351,7 @@ void constraint_mat_convertspace(Object *ob, bPoseChannel *pchan, float mat[][4] constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, to); } } - break; + break; case CONSTRAINT_SPACE_PARLOCAL: /* -------------- FROM LOCAL WITH PARENT ---------- */ { /* local + parent to pose */ @@ -366,12 +366,12 @@ void constraint_mat_convertspace(Object *ob, bPoseChannel *pchan, float mat[][4] constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, to); } } - break; + break; } } else { /* objects */ - if (from==CONSTRAINT_SPACE_WORLD && to==CONSTRAINT_SPACE_LOCAL) { + if (from == CONSTRAINT_SPACE_WORLD && to == CONSTRAINT_SPACE_LOCAL) { /* check if object has a parent */ if (ob->parent) { /* 'subtract' parent's effects from owner */ @@ -383,7 +383,7 @@ void constraint_mat_convertspace(Object *ob, bPoseChannel *pchan, float mat[][4] /* Local space in this case will have to be defined as local to the owner's * transform-property-rotated axes. So subtract this rotation component. */ - object_to_mat4(ob, diff_mat); + BKE_object_to_mat4(ob, diff_mat); normalize_m4(diff_mat); zero_v3(diff_mat[3]); @@ -391,7 +391,7 @@ void constraint_mat_convertspace(Object *ob, bPoseChannel *pchan, float mat[][4] mult_m4_m4m4(mat, imat, mat); } } - else if (from==CONSTRAINT_SPACE_LOCAL && to==CONSTRAINT_SPACE_WORLD) { + else if (from == CONSTRAINT_SPACE_LOCAL && to == CONSTRAINT_SPACE_WORLD) { /* check that object has a parent - otherwise this won't work */ if (ob->parent) { /* 'add' parent's effect back to owner */ @@ -402,7 +402,7 @@ void constraint_mat_convertspace(Object *ob, bPoseChannel *pchan, float mat[][4] /* Local space in this case will have to be defined as local to the owner's * transform-property-rotated axes. So add back this rotation component. */ - object_to_mat4(ob, diff_mat); + BKE_object_to_mat4(ob, diff_mat); normalize_m4(diff_mat); zero_v3(diff_mat[3]); @@ -415,15 +415,15 @@ void constraint_mat_convertspace(Object *ob, bPoseChannel *pchan, float mat[][4] /* ------------ General Target Matrix Tools ---------- */ /* function that sets the given matrix based on given vertex group in mesh */ -static void contarget_get_mesh_mat (Object *ob, const char *substring, float mat[][4]) +static void contarget_get_mesh_mat(Object *ob, const char *substring, float mat[][4]) { DerivedMesh *dm = NULL; - Mesh *me= ob->data; + Mesh *me = ob->data; BMEditMesh *em = me->edit_btmesh; float vec[3] = {0.0f, 0.0f, 0.0f}; float normal[3] = {0.0f, 0.0f, 0.0f}, plane[3]; float imat[3][3], tmat[3][3]; - const int defgroup= defgroup_name_index(ob, substring); + const int defgroup = defgroup_name_index(ob, substring); short freeDM = 0; /* initialize target matrix using target matrix */ @@ -436,7 +436,7 @@ static void contarget_get_mesh_mat (Object *ob, const char *substring, float mat if (em) { /* target is in editmode, so get a special derived mesh */ dm = CDDM_from_BMEditMesh(em, ob->data, FALSE, FALSE); - freeDM= 1; + freeDM = 1; } else { /* when not in EditMode, use the 'final' derived mesh, depsgraph @@ -454,10 +454,10 @@ static void contarget_get_mesh_mat (Object *ob, const char *substring, float mat /* check that dvert is a valid pointers (just in case) */ if (dvert) { - MDeformVert *dv= dvert; + MDeformVert *dv = dvert; /* get the average of all verts with that are in the vertex-group */ for (i = 0; i < numVerts; i++, dv++) { - MDeformWeight *dw= defvert_find_index(dv, defgroup); + MDeformWeight *dw = defvert_find_index(dv, defgroup); if (dw && dw->weight != 0.0f) { dm->getVertCo(dm, i, co); dm->getVertNo(dm, i, nor); @@ -512,20 +512,20 @@ static void contarget_get_mesh_mat (Object *ob, const char *substring, float mat } /* function that sets the given matrix based on given vertex group in lattice */ -static void contarget_get_lattice_mat (Object *ob, const char *substring, float mat[][4]) +static void contarget_get_lattice_mat(Object *ob, const char *substring, float mat[][4]) { - Lattice *lt= (Lattice *)ob->data; + Lattice *lt = (Lattice *)ob->data; - DispList *dl = find_displist(&ob->disp, DL_VERTS); - float *co = dl?dl->verts:NULL; + DispList *dl = BKE_displist_find(&ob->disp, DL_VERTS); + float *co = dl ? dl->verts : NULL; BPoint *bp = lt->def; MDeformVert *dv = lt->dvert; - int tot_verts= lt->pntsu*lt->pntsv*lt->pntsw; - float vec[3]= {0.0f, 0.0f, 0.0f}, tvec[3]; - int grouped=0; + int tot_verts = lt->pntsu * lt->pntsv * lt->pntsw; + float vec[3] = {0.0f, 0.0f, 0.0f}, tvec[3]; + int grouped = 0; int i, n; - const int defgroup= defgroup_name_index(ob, substring); + const int defgroup = defgroup_name_index(ob, substring); /* initialize target matrix using target matrix */ copy_m4_m4(mat, ob->obmat); @@ -537,9 +537,9 @@ static void contarget_get_lattice_mat (Object *ob, const char *substring, float /* 1. Loop through control-points checking if in nominated vertex-group. * 2. If it is, add it to vec to find the average point. */ - for (i=0; i < tot_verts; i++, dv++) { - for (n= 0; n < dv->totweight; n++) { - MDeformWeight *dw= defvert_find_index(dv, defgroup); + for (i = 0; i < tot_verts; i++, dv++) { + for (n = 0; n < dv->totweight; n++) { + MDeformWeight *dw = defvert_find_index(dv, defgroup); if (dw && dw->weight > 0.0f) { /* copy coordinates of point to temporary vector, then add to find average */ memcpy(tvec, co ? co : bp->vec, 3 * sizeof(float)); @@ -551,7 +551,7 @@ static void contarget_get_lattice_mat (Object *ob, const char *substring, float /* advance pointer to coordinate data */ if (co) co += 3; - else bp++; + else bp++; } /* find average location, then multiply by ob->obmat to find world-space location */ @@ -565,14 +565,14 @@ static void contarget_get_lattice_mat (Object *ob, const char *substring, float /* generic function to get the appropriate matrix for most target cases */ /* The cases where the target can be object data have not been implemented */ -static void constraint_target_to_mat4 (Object *ob, const char *substring, float mat[][4], short from, short to, float headtail) +static void constraint_target_to_mat4(Object *ob, const char *substring, float mat[][4], short from, short to, float headtail) { /* Case OBJECT */ if (!strlen(substring)) { copy_m4_m4(mat, ob->obmat); constraint_mat_convertspace(ob, NULL, mat, from, to); } - /* Case VERTEXGROUP */ + /* Case VERTEXGROUP */ /* Current method just takes the average location of all the points in the * VertexGroup, and uses that as the location value of the targets. Where * possible, the orientation will also be calculated, by calculating an @@ -593,7 +593,7 @@ static void constraint_target_to_mat4 (Object *ob, const char *substring, float else { bPoseChannel *pchan; - pchan = get_pose_channel(ob->pose, substring); + pchan = BKE_pose_channel_find_name(ob->pose, substring); if (pchan) { /* Multiply the PoseSpace accumulation/final matrix for this * PoseChannel by the Armature Object's Matrix to get a worldspace @@ -631,14 +631,14 @@ static void constraint_target_to_mat4 (Object *ob, const char *substring, float */ /* Template for type-info data: - * - make a copy of this when creating new constraints, and just change the functions - * pointed to as necessary - * - although the naming of functions doesn't matter, it would help for code - * readability, to follow the same naming convention as is presented here - * - any functions that a constraint doesn't need to define, don't define - * for such cases, just use NULL - * - these should be defined after all the functions have been defined, so that - * forward-definitions/prototypes don't need to be used! + * - make a copy of this when creating new constraints, and just change the functions + * pointed to as necessary + * - although the naming of functions doesn't matter, it would help for code + * readability, to follow the same naming convention as is presented here + * - any functions that a constraint doesn't need to define, don't define + * for such cases, just use NULL + * - these should be defined after all the functions have been defined, so that + * forward-definitions/prototypes don't need to be used! * - keep this copy #if-def'd so that future constraints can get based off this */ #if 0 @@ -648,7 +648,6 @@ static bConstraintTypeInfo CTI_CONSTRNAME = { "ConstrName", /* name */ "bConstrNameConstraint", /* struct name */ constrname_free, /* free data */ - constrname_relink, /* relink data */ constrname_id_looper, /* id looper */ constrname_copy, /* copy data */ constrname_new_data, /* new data */ @@ -662,7 +661,7 @@ static bConstraintTypeInfo CTI_CONSTRNAME = { /* This function should be used for the get_target_matrix member of all * constraints that are not picky about what happens to their target matrix. */ -static void default_get_tarmat (bConstraint *con, bConstraintOb *UNUSED(cob), bConstraintTarget *ct, float UNUSED(ctime)) +static void default_get_tarmat(bConstraint *con, bConstraintOb *UNUSED(cob), bConstraintTarget *ct, float UNUSED(ctime)) { if (VALID_CONS_TARGET(ct)) constraint_target_to_mat4(ct->tar, ct->subtarget, ct->matrix, CONSTRAINT_SPACE_WORLD, ct->space, con->headtail); @@ -678,26 +677,26 @@ static void default_get_tarmat (bConstraint *con, bConstraintOb *UNUSED(cob), bC // TODO: cope with getting rotation order... #define SINGLETARGET_GET_TARS(con, datatar, datasubtarget, ct, list) \ { \ - ct= MEM_callocN(sizeof(bConstraintTarget), "tempConstraintTarget"); \ + ct = MEM_callocN(sizeof(bConstraintTarget), "tempConstraintTarget"); \ \ - ct->tar= datatar; \ + ct->tar = datatar; \ BLI_strncpy(ct->subtarget, datasubtarget, sizeof(ct->subtarget)); \ - ct->space= con->tarspace; \ - ct->flag= CONSTRAINT_TAR_TEMP; \ + ct->space = con->tarspace; \ + ct->flag = CONSTRAINT_TAR_TEMP; \ \ if (ct->tar) { \ - if ((ct->tar->type==OB_ARMATURE) && (ct->subtarget[0])) { \ - bPoseChannel *pchan= get_pose_channel(ct->tar->pose, ct->subtarget); \ + if ((ct->tar->type == OB_ARMATURE) && (ct->subtarget[0])) { \ + bPoseChannel *pchan = BKE_pose_channel_find_name(ct->tar->pose, ct->subtarget); \ ct->type = CONSTRAINT_OBTYPE_BONE; \ - ct->rotOrder= (pchan) ? (pchan->rotmode) : EULER_ORDER_DEFAULT; \ - }\ + ct->rotOrder = (pchan) ? (pchan->rotmode) : EULER_ORDER_DEFAULT; \ + } \ else if (OB_TYPE_SUPPORT_VGROUP(ct->tar->type) && (ct->subtarget[0])) { \ ct->type = CONSTRAINT_OBTYPE_VERT; \ ct->rotOrder = EULER_ORDER_DEFAULT; \ } \ - else {\ + else { \ ct->type = CONSTRAINT_OBTYPE_OBJECT; \ - ct->rotOrder= ct->tar->rotmode; \ + ct->rotOrder = ct->tar->rotmode; \ } \ } \ \ @@ -712,11 +711,11 @@ static void default_get_tarmat (bConstraint *con, bConstraintOb *UNUSED(cob), bC // TODO: cope with getting rotation order... #define SINGLETARGETNS_GET_TARS(con, datatar, ct, list) \ { \ - ct= MEM_callocN(sizeof(bConstraintTarget), "tempConstraintTarget"); \ + ct = MEM_callocN(sizeof(bConstraintTarget), "tempConstraintTarget"); \ \ - ct->tar= datatar; \ - ct->space= con->tarspace; \ - ct->flag= CONSTRAINT_TAR_TEMP; \ + ct->tar = datatar; \ + ct->space = con->tarspace; \ + ct->flag = CONSTRAINT_TAR_TEMP; \ \ if (ct->tar) ct->type = CONSTRAINT_OBTYPE_OBJECT; \ \ @@ -734,13 +733,13 @@ static void default_get_tarmat (bConstraint *con, bConstraintOb *UNUSED(cob), bC if (ct) { \ bConstraintTarget *ctn = ct->next; \ if (nocopy == 0) { \ - datatar= ct->tar; \ + datatar = ct->tar; \ BLI_strncpy(datasubtarget, ct->subtarget, sizeof(datasubtarget)); \ - con->tarspace= (char)ct->space; \ + con->tarspace = (char)ct->space; \ } \ \ BLI_freelinkN(list, ct); \ - ct= ctn; \ + ct = ctn; \ } \ } @@ -755,39 +754,39 @@ static void default_get_tarmat (bConstraint *con, bConstraintOb *UNUSED(cob), bC if (ct) { \ bConstraintTarget *ctn = ct->next; \ if (nocopy == 0) { \ - datatar= ct->tar; \ - con->tarspace= (char)ct->space; \ + datatar = ct->tar; \ + con->tarspace = (char)ct->space; \ } \ \ BLI_freelinkN(list, ct); \ - ct= ctn; \ + ct = ctn; \ } \ } /* --------- ChildOf Constraint ------------ */ -static void childof_new_data (void *cdata) +static void childof_new_data(void *cdata) { - bChildOfConstraint *data= (bChildOfConstraint *)cdata; + bChildOfConstraint *data = (bChildOfConstraint *)cdata; data->flag = (CHILDOF_LOCX | CHILDOF_LOCY | CHILDOF_LOCZ | - CHILDOF_ROTX |CHILDOF_ROTY | CHILDOF_ROTZ | - CHILDOF_SIZEX | CHILDOF_SIZEY | CHILDOF_SIZEZ); + CHILDOF_ROTX | CHILDOF_ROTY | CHILDOF_ROTZ | + CHILDOF_SIZEX | CHILDOF_SIZEY | CHILDOF_SIZEZ); unit_m4(data->invmat); } -static void childof_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void childof_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bChildOfConstraint *data= con->data; + bChildOfConstraint *data = con->data; /* target only */ - func(con, (ID**)&data->tar, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); } -static int childof_get_tars (bConstraint *con, ListBase *list) +static int childof_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bChildOfConstraint *data= con->data; + bChildOfConstraint *data = con->data; bConstraintTarget *ct; /* standard target-getting macro for single-target constraints */ @@ -799,21 +798,21 @@ static int childof_get_tars (bConstraint *con, ListBase *list) return 0; } -static void childof_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void childof_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bChildOfConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bChildOfConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy) } } -static void childof_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) +static void childof_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets) { - bChildOfConstraint *data= con->data; - bConstraintTarget *ct= targets->first; + bChildOfConstraint *data = con->data; + bConstraintTarget *ct = targets->first; /* only evaluate if there is a target */ if (VALID_CONS_TARGET(ct)) { @@ -850,15 +849,15 @@ static void childof_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta mat4_to_size(sizo, invmat); /* disable channels not enabled */ - if (!(data->flag & CHILDOF_LOCX)) loc[0]= loco[0]= 0.0f; - if (!(data->flag & CHILDOF_LOCY)) loc[1]= loco[1]= 0.0f; - if (!(data->flag & CHILDOF_LOCZ)) loc[2]= loco[2]= 0.0f; - if (!(data->flag & CHILDOF_ROTX)) eul[0]= eulo[0]= 0.0f; - if (!(data->flag & CHILDOF_ROTY)) eul[1]= eulo[1]= 0.0f; - if (!(data->flag & CHILDOF_ROTZ)) eul[2]= eulo[2]= 0.0f; - if (!(data->flag & CHILDOF_SIZEX)) size[0]= sizo[0]= 1.0f; - if (!(data->flag & CHILDOF_SIZEY)) size[1]= sizo[1]= 1.0f; - if (!(data->flag & CHILDOF_SIZEZ)) size[2]= sizo[2]= 1.0f; + if (!(data->flag & CHILDOF_LOCX)) loc[0] = loco[0] = 0.0f; + if (!(data->flag & CHILDOF_LOCY)) loc[1] = loco[1] = 0.0f; + if (!(data->flag & CHILDOF_LOCZ)) loc[2] = loco[2] = 0.0f; + if (!(data->flag & CHILDOF_ROTX)) eul[0] = eulo[0] = 0.0f; + if (!(data->flag & CHILDOF_ROTY)) eul[1] = eulo[1] = 0.0f; + if (!(data->flag & CHILDOF_ROTZ)) eul[2] = eulo[2] = 0.0f; + if (!(data->flag & CHILDOF_SIZEX)) size[0] = sizo[0] = 1.0f; + if (!(data->flag & CHILDOF_SIZEY)) size[1] = sizo[1] = 1.0f; + if (!(data->flag & CHILDOF_SIZEZ)) size[2] = sizo[2] = 1.0f; /* make new target mat and offset mat */ loc_eulO_size_to_mat4(ct->matrix, loc, eul, size, ct->rotOrder); @@ -874,13 +873,13 @@ static void childof_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta */ copy_m4_m4(tempmat, cob->matrix); mult_m4_m4m4(cob->matrix, parmat, tempmat); - + /* without this, changes to scale and rotation can change location * of a parentless bone or a disconnected bone. Even though its set * to zero above. */ - if (!(data->flag & CHILDOF_LOCX)) cob->matrix[3][0]= tempmat[3][0]; - if (!(data->flag & CHILDOF_LOCY)) cob->matrix[3][1]= tempmat[3][1]; - if (!(data->flag & CHILDOF_LOCZ)) cob->matrix[3][2]= tempmat[3][2]; + if (!(data->flag & CHILDOF_LOCX)) cob->matrix[3][0] = tempmat[3][0]; + if (!(data->flag & CHILDOF_LOCY)) cob->matrix[3][1] = tempmat[3][1]; + if (!(data->flag & CHILDOF_LOCZ)) cob->matrix[3][2] = tempmat[3][2]; } } } @@ -892,7 +891,6 @@ static bConstraintTypeInfo CTI_CHILDOF = { "ChildOf", /* name */ "bChildOfConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ childof_id_looper, /* id looper */ NULL, /* copy data */ childof_new_data, /* new data */ @@ -904,26 +902,26 @@ static bConstraintTypeInfo CTI_CHILDOF = { /* -------- TrackTo Constraint ------- */ -static void trackto_new_data (void *cdata) +static void trackto_new_data(void *cdata) { - bTrackToConstraint *data= (bTrackToConstraint *)cdata; + bTrackToConstraint *data = (bTrackToConstraint *)cdata; data->reserved1 = TRACK_Y; data->reserved2 = UP_Z; } -static void trackto_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void trackto_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bTrackToConstraint *data= con->data; + bTrackToConstraint *data = con->data; /* target only */ - func(con, (ID**)&data->tar, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); } -static int trackto_get_tars (bConstraint *con, ListBase *list) +static int trackto_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bTrackToConstraint *data= con->data; + bTrackToConstraint *data = con->data; bConstraintTarget *ct; /* standard target-getting macro for single-target constraints */ @@ -935,11 +933,11 @@ static int trackto_get_tars (bConstraint *con, ListBase *list) return 0; } -static void trackto_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void trackto_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bTrackToConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bTrackToConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy) @@ -947,9 +945,9 @@ static void trackto_flush_tars (bConstraint *con, ListBase *list, short nocopy) } -static int basis_cross (int n, int m) +static int basis_cross(int n, int m) { - switch (n-m) { + switch (n - m) { case 1: case -2: return 1; @@ -963,7 +961,7 @@ static int basis_cross (int n, int m) } } -static void vectomat (float *vec, float *target_up, short axis, short upflag, short flags, float m[][3]) +static void vectomat(float *vec, float *target_up, short axis, short upflag, short flags, float m[][3]) { float n[3]; float u[3]; /* vector specifying the up axis */ @@ -1027,10 +1025,10 @@ static void vectomat (float *vec, float *target_up, short axis, short upflag, sh } -static void trackto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) +static void trackto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets) { - bTrackToConstraint *data= con->data; - bConstraintTarget *ct= targets->first; + bTrackToConstraint *data = con->data; + bConstraintTarget *ct = targets->first; if (VALID_CONS_TARGET(ct)) { float size[3], vec[3]; @@ -1041,23 +1039,23 @@ static void trackto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta mat4_to_size(size, cob->matrix); /* Clear the object's rotation */ - cob->matrix[0][0]=size[0]; - cob->matrix[0][1]=0; - cob->matrix[0][2]=0; - cob->matrix[1][0]=0; - cob->matrix[1][1]=size[1]; - cob->matrix[1][2]=0; - cob->matrix[2][0]=0; - cob->matrix[2][1]=0; - cob->matrix[2][2]=size[2]; + cob->matrix[0][0] = size[0]; + cob->matrix[0][1] = 0; + cob->matrix[0][2] = 0; + cob->matrix[1][0] = 0; + cob->matrix[1][1] = size[1]; + cob->matrix[1][2] = 0; + cob->matrix[2][0] = 0; + cob->matrix[2][1] = 0; + cob->matrix[2][2] = size[2]; /* targetmat[2] instead of ownermat[2] is passed to vectomat * for backwards compatibility it seems... (Aligorith) */ sub_v3_v3v3(vec, cob->matrix[3], ct->matrix[3]); vectomat(vec, ct->matrix[2], - (short)data->reserved1, (short)data->reserved2, - data->flags, totmat); + (short)data->reserved1, (short)data->reserved2, + data->flags, totmat); copy_m4_m4(tmat, cob->matrix); mul_m4_m3m4(cob->matrix, totmat, tmat); @@ -1070,7 +1068,6 @@ static bConstraintTypeInfo CTI_TRACKTO = { "TrackTo", /* name */ "bTrackToConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ trackto_id_looper, /* id looper */ NULL, /* copy data */ trackto_new_data, /* new data */ @@ -1082,32 +1079,32 @@ static bConstraintTypeInfo CTI_TRACKTO = { /* --------- Inverse-Kinemetics --------- */ -static void kinematic_new_data (void *cdata) +static void kinematic_new_data(void *cdata) { - bKinematicConstraint *data= (bKinematicConstraint *)cdata; + bKinematicConstraint *data = (bKinematicConstraint *)cdata; - data->weight= 1.0f; - data->orientweight= 1.0f; + data->weight = 1.0f; + data->orientweight = 1.0f; data->iterations = 500; - data->dist= 1.0f; - data->flag= CONSTRAINT_IK_TIP|CONSTRAINT_IK_STRETCH|CONSTRAINT_IK_POS; + data->dist = 1.0f; + data->flag = CONSTRAINT_IK_TIP | CONSTRAINT_IK_STRETCH | CONSTRAINT_IK_POS; } -static void kinematic_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void kinematic_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bKinematicConstraint *data= con->data; + bKinematicConstraint *data = con->data; /* chain target */ - func(con, (ID**)&data->tar, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); /* poletarget */ - func(con, (ID**)&data->poletar, userdata); + func(con, (ID **)&data->poletar, FALSE, userdata); } -static int kinematic_get_tars (bConstraint *con, ListBase *list) +static int kinematic_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bKinematicConstraint *data= con->data; + bKinematicConstraint *data = con->data; bConstraintTarget *ct; /* standard target-getting macro for single-target constraints is used twice here */ @@ -1120,11 +1117,11 @@ static int kinematic_get_tars (bConstraint *con, ListBase *list) return 0; } -static void kinematic_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void kinematic_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bKinematicConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bKinematicConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy) @@ -1132,15 +1129,15 @@ static void kinematic_flush_tars (bConstraint *con, ListBase *list, short nocopy } } -static void kinematic_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) +static void kinematic_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) { - bKinematicConstraint *data= con->data; + bKinematicConstraint *data = con->data; if (VALID_CONS_TARGET(ct)) constraint_target_to_mat4(ct->tar, ct->subtarget, ct->matrix, CONSTRAINT_SPACE_WORLD, ct->space, con->headtail); else if (ct) { if (data->flag & CONSTRAINT_IK_AUTO) { - Object *ob= cob->ob; + Object *ob = cob->ob; if (ob == NULL) { unit_m4(ct->matrix); @@ -1164,7 +1161,6 @@ static bConstraintTypeInfo CTI_KINEMATIC = { "IK", /* name */ "bKinematicConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ kinematic_id_looper, /* id looper */ NULL, /* copy data */ kinematic_new_data, /* new data */ @@ -1176,9 +1172,9 @@ static bConstraintTypeInfo CTI_KINEMATIC = { /* -------- Follow-Path Constraint ---------- */ -static void followpath_new_data (void *cdata) +static void followpath_new_data(void *cdata) { - bFollowPathConstraint *data= (bFollowPathConstraint *)cdata; + bFollowPathConstraint *data = (bFollowPathConstraint *)cdata; data->trackflag = TRACK_Y; data->upflag = UP_Z; @@ -1186,18 +1182,18 @@ static void followpath_new_data (void *cdata) data->followflag = 0; } -static void followpath_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void followpath_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bFollowPathConstraint *data= con->data; + bFollowPathConstraint *data = con->data; /* target only */ - func(con, (ID**)&data->tar, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); } -static int followpath_get_tars (bConstraint *con, ListBase *list) +static int followpath_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bFollowPathConstraint *data= con->data; + bFollowPathConstraint *data = con->data; bConstraintTarget *ct; /* standard target-getting macro for single-target constraints without subtargets */ @@ -1209,25 +1205,25 @@ static int followpath_get_tars (bConstraint *con, ListBase *list) return 0; } -static void followpath_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void followpath_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bFollowPathConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bFollowPathConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGETNS_FLUSH_TARS(con, data->tar, ct, list, nocopy) } } -static void followpath_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) +static void followpath_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) { - bFollowPathConstraint *data= con->data; + bFollowPathConstraint *data = con->data; if (VALID_CONS_TARGET(ct)) { - Curve *cu= ct->tar->data; + Curve *cu = ct->tar->data; float vec[4], dir[3], radius; - float totmat[4][4]= MAT4_UNITY; + float totmat[4][4] = MAT4_UNITY; float curvetime; unit_m4(ct->matrix); @@ -1237,15 +1233,15 @@ static void followpath_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr */ /* only happens on reload file, but violates depsgraph still... fix! */ - if (cu->path==NULL || cu->path->data==NULL) - makeDispListCurveTypes(cob->scene, ct->tar, 0); + if (cu->path == NULL || cu->path->data == NULL) + BKE_displist_make_curveTypes(cob->scene, ct->tar, 0); if (cu->path && cu->path->data) { float quat[4]; if ((data->followflag & FOLLOWPATH_STATIC) == 0) { /* animated position along curve depending on time */ Nurb *nu = cu->nurb.first; - curvetime= cu->ctime - data->offset; + curvetime = cu->ctime - data->offset; /* ctime is now a proper var setting of Curve which gets set by Animato like any other var that's animated, * but this will only work if it actually is animated... @@ -1269,21 +1265,21 @@ static void followpath_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr } else { /* fixed position along curve */ - curvetime= data->offset_fac; + curvetime = data->offset_fac; } - if ( where_on_path(ct->tar, curvetime, vec, dir, (data->followflag & FOLLOWPATH_FOLLOW) ? quat : NULL, &radius, NULL) ) { /* quat_pt is quat or NULL*/ + if (where_on_path(ct->tar, curvetime, vec, dir, (data->followflag & FOLLOWPATH_FOLLOW) ? quat : NULL, &radius, NULL) ) { /* quat_pt is quat or NULL*/ if (data->followflag & FOLLOWPATH_FOLLOW) { #if 0 float x1, q[4]; vec_to_quat(quat, dir, (short)data->trackflag, (short)data->upflag); normalize_v3(dir); - q[0]= (float)cos(0.5*vec[3]); - x1= (float)sin(0.5*vec[3]); - q[1]= -x1*dir[0]; - q[2]= -x1*dir[1]; - q[3]= -x1*dir[2]; + q[0] = (float)cos(0.5 * vec[3]); + x1 = (float)sin(0.5 * vec[3]); + q[1] = -x1 * dir[0]; + q[2] = -x1 * dir[1]; + q[3] = -x1 * dir[2]; mul_qt_qtqt(quat, q, quat); #else quat_apply_track(quat, data->trackflag, data->upflag); @@ -1309,15 +1305,15 @@ static void followpath_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr unit_m4(ct->matrix); } -static void followpath_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) +static void followpath_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets) { - bConstraintTarget *ct= targets->first; + bConstraintTarget *ct = targets->first; /* only evaluate if there is a target */ if (VALID_CONS_TARGET(ct)) { float obmat[4][4]; float size[3]; - bFollowPathConstraint *data= con->data; + bFollowPathConstraint *data = con->data; /* get Object transform (loc/rot/size) to determine transformation from path */ // TODO: this used to be local at one point, but is probably more useful as-is @@ -1330,7 +1326,7 @@ static void followpath_evaluate (bConstraint *con, bConstraintOb *cob, ListBase mul_serie_m4(cob->matrix, ct->matrix, obmat, NULL, NULL, NULL, NULL, NULL, NULL); /* un-apply scaling caused by path */ - if ((data->followflag & FOLLOWPATH_RADIUS)==0) { /* XXX - assume that scale correction means that radius will have some scale error in it - Campbell */ + if ((data->followflag & FOLLOWPATH_RADIUS) == 0) { /* XXX - assume that scale correction means that radius will have some scale error in it - Campbell */ float obsize[3]; mat4_to_size(obsize, cob->matrix); @@ -1350,7 +1346,6 @@ static bConstraintTypeInfo CTI_FOLLOWPATH = { "Follow Path", /* name */ "bFollowPathConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ followpath_id_looper, /* id looper */ NULL, /* copy data */ followpath_new_data, /* new data */ @@ -1363,7 +1358,7 @@ static bConstraintTypeInfo CTI_FOLLOWPATH = { /* --------- Limit Location --------- */ -static void loclimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) +static void loclimit_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) { bLocLimitConstraint *data = con->data; @@ -1399,7 +1394,6 @@ static bConstraintTypeInfo CTI_LOCLIMIT = { "Limit Location", /* name */ "bLocLimitConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ NULL, /* id looper */ NULL, /* copy data */ NULL, /* new data */ @@ -1411,7 +1405,7 @@ static bConstraintTypeInfo CTI_LOCLIMIT = { /* -------- Limit Rotation --------- */ -static void rotlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) +static void rotlimit_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) { bRotLimitConstraint *data = con->data; float loc[3]; @@ -1457,7 +1451,6 @@ static bConstraintTypeInfo CTI_ROTLIMIT = { "Limit Rotation", /* name */ "bRotLimitConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ NULL, /* id looper */ NULL, /* copy data */ NULL, /* new data */ @@ -1470,7 +1463,7 @@ static bConstraintTypeInfo CTI_ROTLIMIT = { /* --------- Limit Scaling --------- */ -static void sizelimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) +static void sizelimit_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) { bSizeLimitConstraint *data = con->data; float obsize[3], size[3]; @@ -1504,11 +1497,11 @@ static void sizelimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * } if (obsize[0]) - mul_v3_fl(cob->matrix[0], size[0]/obsize[0]); + mul_v3_fl(cob->matrix[0], size[0] / obsize[0]); if (obsize[1]) - mul_v3_fl(cob->matrix[1], size[1]/obsize[1]); + mul_v3_fl(cob->matrix[1], size[1] / obsize[1]); if (obsize[2]) - mul_v3_fl(cob->matrix[2], size[2]/obsize[2]); + mul_v3_fl(cob->matrix[2], size[2] / obsize[2]); } static bConstraintTypeInfo CTI_SIZELIMIT = { @@ -1517,7 +1510,6 @@ static bConstraintTypeInfo CTI_SIZELIMIT = { "Limit Scaling", /* name */ "bSizeLimitConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ NULL, /* id looper */ NULL, /* copy data */ NULL, /* new data */ @@ -1529,25 +1521,25 @@ static bConstraintTypeInfo CTI_SIZELIMIT = { /* ----------- Copy Location ------------- */ -static void loclike_new_data (void *cdata) +static void loclike_new_data(void *cdata) { - bLocateLikeConstraint *data= (bLocateLikeConstraint *)cdata; + bLocateLikeConstraint *data = (bLocateLikeConstraint *)cdata; - data->flag = LOCLIKE_X|LOCLIKE_Y|LOCLIKE_Z; + data->flag = LOCLIKE_X | LOCLIKE_Y | LOCLIKE_Z; } -static void loclike_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void loclike_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bLocateLikeConstraint *data= con->data; + bLocateLikeConstraint *data = con->data; /* target only */ - func(con, (ID**)&data->tar, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); } -static int loclike_get_tars (bConstraint *con, ListBase *list) +static int loclike_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bLocateLikeConstraint *data= con->data; + bLocateLikeConstraint *data = con->data; bConstraintTarget *ct; /* standard target-getting macro for single-target constraints */ @@ -1559,21 +1551,21 @@ static int loclike_get_tars (bConstraint *con, ListBase *list) return 0; } -static void loclike_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void loclike_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bLocateLikeConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bLocateLikeConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy) } } -static void loclike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) +static void loclike_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets) { - bLocateLikeConstraint *data= con->data; - bConstraintTarget *ct= targets->first; + bLocateLikeConstraint *data = con->data; + bConstraintTarget *ct = targets->first; if (VALID_CONS_TARGET(ct)) { float offset[3] = {0.0f, 0.0f, 0.0f}; @@ -1608,7 +1600,6 @@ static bConstraintTypeInfo CTI_LOCLIKE = { "Copy Location", /* name */ "bLocateLikeConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ loclike_id_looper, /* id looper */ NULL, /* copy data */ loclike_new_data, /* new data */ @@ -1620,25 +1611,25 @@ static bConstraintTypeInfo CTI_LOCLIKE = { /* ----------- Copy Rotation ------------- */ -static void rotlike_new_data (void *cdata) +static void rotlike_new_data(void *cdata) { - bRotateLikeConstraint *data= (bRotateLikeConstraint *)cdata; + bRotateLikeConstraint *data = (bRotateLikeConstraint *)cdata; - data->flag = ROTLIKE_X|ROTLIKE_Y|ROTLIKE_Z; + data->flag = ROTLIKE_X | ROTLIKE_Y | ROTLIKE_Z; } -static void rotlike_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void rotlike_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bChildOfConstraint *data= con->data; + bChildOfConstraint *data = con->data; /* target only */ - func(con, (ID**)&data->tar, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); } -static int rotlike_get_tars (bConstraint *con, ListBase *list) +static int rotlike_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bRotateLikeConstraint *data= con->data; + bRotateLikeConstraint *data = con->data; bConstraintTarget *ct; /* standard target-getting macro for single-target constraints */ @@ -1650,26 +1641,26 @@ static int rotlike_get_tars (bConstraint *con, ListBase *list) return 0; } -static void rotlike_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void rotlike_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bRotateLikeConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bRotateLikeConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy) } } -static void rotlike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) +static void rotlike_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets) { - bRotateLikeConstraint *data= con->data; - bConstraintTarget *ct= targets->first; + bRotateLikeConstraint *data = con->data; + bConstraintTarget *ct = targets->first; if (VALID_CONS_TARGET(ct)) { - float loc[3]; - float eul[3], obeul[3]; - float size[3]; + float loc[3]; + float eul[3], obeul[3]; + float size[3]; copy_v3_v3(loc, cob->matrix[3]); mat4_to_size(size, cob->matrix); @@ -1679,7 +1670,7 @@ static void rotlike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta /* we must get compatible eulers from the beginning because some of them can be modified below (see bug #21875) */ mat4_to_compatible_eulO(eul, obeul, cob->rotOrder, ct->matrix); - if ((data->flag & ROTLIKE_X)==0) + if ((data->flag & ROTLIKE_X) == 0) eul[0] = obeul[0]; else { if (data->flag & ROTLIKE_OFFSET) @@ -1689,7 +1680,7 @@ static void rotlike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta eul[0] *= -1; } - if ((data->flag & ROTLIKE_Y)==0) + if ((data->flag & ROTLIKE_Y) == 0) eul[1] = obeul[1]; else { if (data->flag & ROTLIKE_OFFSET) @@ -1699,7 +1690,7 @@ static void rotlike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta eul[1] *= -1; } - if ((data->flag & ROTLIKE_Z)==0) + if ((data->flag & ROTLIKE_Z) == 0) eul[2] = obeul[2]; else { if (data->flag & ROTLIKE_OFFSET) @@ -1721,7 +1712,6 @@ static bConstraintTypeInfo CTI_ROTLIKE = { "Copy Rotation", /* name */ "bRotateLikeConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ rotlike_id_looper, /* id looper */ NULL, /* copy data */ rotlike_new_data, /* new data */ @@ -1733,25 +1723,25 @@ static bConstraintTypeInfo CTI_ROTLIKE = { /* ---------- Copy Scaling ---------- */ -static void sizelike_new_data (void *cdata) +static void sizelike_new_data(void *cdata) { - bSizeLikeConstraint *data= (bSizeLikeConstraint *)cdata; + bSizeLikeConstraint *data = (bSizeLikeConstraint *)cdata; - data->flag = SIZELIKE_X|SIZELIKE_Y|SIZELIKE_Z; + data->flag = SIZELIKE_X | SIZELIKE_Y | SIZELIKE_Z; } -static void sizelike_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void sizelike_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bSizeLikeConstraint *data= con->data; + bSizeLikeConstraint *data = con->data; /* target only */ - func(con, (ID**)&data->tar, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); } -static int sizelike_get_tars (bConstraint *con, ListBase *list) +static int sizelike_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bSizeLikeConstraint *data= con->data; + bSizeLikeConstraint *data = con->data; bConstraintTarget *ct; /* standard target-getting macro for single-target constraints */ @@ -1763,21 +1753,21 @@ static int sizelike_get_tars (bConstraint *con, ListBase *list) return 0; } -static void sizelike_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void sizelike_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bSizeLikeConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bSizeLikeConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy) } } -static void sizelike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) +static void sizelike_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets) { - bSizeLikeConstraint *data= con->data; - bConstraintTarget *ct= targets->first; + bSizeLikeConstraint *data = con->data; + bConstraintTarget *ct = targets->first; if (VALID_CONS_TARGET(ct)) { float obsize[3], size[3]; @@ -1818,7 +1808,6 @@ static bConstraintTypeInfo CTI_SIZELIKE = { "Copy Scale", /* name */ "bSizeLikeConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ sizelike_id_looper, /* id looper */ NULL, /* copy data */ sizelike_new_data, /* new data */ @@ -1830,18 +1819,18 @@ static bConstraintTypeInfo CTI_SIZELIKE = { /* ----------- Copy Transforms ------------- */ -static void translike_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void translike_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bTransLikeConstraint *data= con->data; + bTransLikeConstraint *data = con->data; /* target only */ - func(con, (ID**)&data->tar, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); } -static int translike_get_tars (bConstraint *con, ListBase *list) +static int translike_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bTransLikeConstraint *data= con->data; + bTransLikeConstraint *data = con->data; bConstraintTarget *ct; /* standard target-getting macro for single-target constraints */ @@ -1853,20 +1842,20 @@ static int translike_get_tars (bConstraint *con, ListBase *list) return 0; } -static void translike_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void translike_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bTransLikeConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bTransLikeConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy) } } -static void translike_evaluate (bConstraint *UNUSED(con), bConstraintOb *cob, ListBase *targets) +static void translike_evaluate(bConstraint *UNUSED(con), bConstraintOb *cob, ListBase *targets) { - bConstraintTarget *ct= targets->first; + bConstraintTarget *ct = targets->first; if (VALID_CONS_TARGET(ct)) { /* just copy the entire transform matrix of the target */ @@ -1880,7 +1869,6 @@ static bConstraintTypeInfo CTI_TRANSLIKE = { "Copy Transforms", /* name */ "bTransLikeConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ translike_id_looper, /* id looper */ NULL, /* copy data */ NULL, /* new data */ @@ -1892,17 +1880,17 @@ static bConstraintTypeInfo CTI_TRANSLIKE = { /* ---------- Maintain Volume ---------- */ -static void samevolume_new_data (void *cdata) +static void samevolume_new_data(void *cdata) { - bSameVolumeConstraint *data= (bSameVolumeConstraint *)cdata; + bSameVolumeConstraint *data = (bSameVolumeConstraint *)cdata; data->flag = SAMEVOL_Y; data->volume = 1.0f; } -static void samevolume_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) +static void samevolume_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) { - bSameVolumeConstraint *data= con->data; + bSameVolumeConstraint *data = con->data; float volume = data->volume; float fac = 1.0f; @@ -1937,7 +1925,6 @@ static bConstraintTypeInfo CTI_SAMEVOL = { "Maintain Volume", /* name */ "bSameVolumeConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ NULL, /* id looper */ NULL, /* copy data */ samevolume_new_data, /* new data */ @@ -1949,9 +1936,9 @@ static bConstraintTypeInfo CTI_SAMEVOL = { /* ----------- Python Constraint -------------- */ -static void pycon_free (bConstraint *con) +static void pycon_free(bConstraint *con) { - bPythonConstraint *data= con->data; + bPythonConstraint *data = con->data; /* id-properties */ IDP_FreeProperty(data->prop); @@ -1961,14 +1948,7 @@ static void pycon_free (bConstraint *con) BLI_freelistN(&data->targets); } -static void pycon_relink (bConstraint *con) -{ - bPythonConstraint *data= con->data; - - ID_NEW(data->text); -} - -static void pycon_copy (bConstraint *con, bConstraint *srccon) +static void pycon_copy(bConstraint *con, bConstraint *srccon) { bPythonConstraint *pycon = (bPythonConstraint *)con->data; bPythonConstraint *opycon = (bPythonConstraint *)srccon->data; @@ -1977,19 +1957,19 @@ static void pycon_copy (bConstraint *con, bConstraint *srccon) BLI_duplicatelist(&pycon->targets, &opycon->targets); } -static void pycon_new_data (void *cdata) +static void pycon_new_data(void *cdata) { - bPythonConstraint *data= (bPythonConstraint *)cdata; + bPythonConstraint *data = (bPythonConstraint *)cdata; /* everything should be set correctly by calloc, except for the prop->type constant.*/ data->prop = MEM_callocN(sizeof(IDProperty), "PyConstraintProps"); data->prop->type = IDP_GROUP; } -static int pycon_get_tars (bConstraint *con, ListBase *list) +static int pycon_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bPythonConstraint *data= con->data; + bPythonConstraint *data = con->data; list->first = data->targets.first; list->last = data->targets.last; @@ -2000,34 +1980,34 @@ static int pycon_get_tars (bConstraint *con, ListBase *list) return 0; } -static void pycon_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void pycon_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bPythonConstraint *data= con->data; + bPythonConstraint *data = con->data; bConstraintTarget *ct; /* targets */ - for (ct= data->targets.first; ct; ct= ct->next) - func(con, (ID**)&ct->tar, userdata); + for (ct = data->targets.first; ct; ct = ct->next) + func(con, (ID **)&ct->tar, FALSE, userdata); /* script */ - func(con, (ID**)&data->text, userdata); + func(con, (ID **)&data->text, TRUE, userdata); } /* Whether this approach is maintained remains to be seen (aligorith) */ -static void pycon_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) +static void pycon_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) { #ifdef WITH_PYTHON - bPythonConstraint *data= con->data; + bPythonConstraint *data = con->data; #endif if (VALID_CONS_TARGET(ct)) { /* special exception for curves - depsgraph issues */ if (ct->tar->type == OB_CURVE) { - Curve *cu= ct->tar->data; + Curve *cu = ct->tar->data; /* this check is to make sure curve objects get updated on file load correctly.*/ - if (cu->path==NULL || cu->path->data==NULL) /* only happens on reload file, but violates depsgraph still... fix! */ - makeDispListCurveTypes(cob->scene, ct->tar, 0); + if (cu->path == NULL || cu->path->data == NULL) /* only happens on reload file, but violates depsgraph still... fix! */ + BKE_displist_make_curveTypes(cob->scene, ct->tar, 0); } /* firstly calculate the matrix the normal way, then let the py-function override @@ -2045,16 +2025,16 @@ static void pycon_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraintT unit_m4(ct->matrix); } -static void pycon_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) +static void pycon_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets) { #ifndef WITH_PYTHON (void)con; (void)cob; (void)targets; /* unused */ return; #else - bPythonConstraint *data= con->data; + bPythonConstraint *data = con->data; /* only evaluate in python if we're allowed to do so */ - if ((G.f & G_SCRIPT_AUTOEXEC)==0) return; + if ((G.f & G_SCRIPT_AUTOEXEC) == 0) return; /* currently removed, until I this can be re-implemented for multiple targets */ #if 0 @@ -2076,7 +2056,6 @@ static bConstraintTypeInfo CTI_PYTHON = { "Script", /* name */ "bPythonConstraint", /* struct name */ pycon_free, /* free data */ - pycon_relink, /* relink data */ pycon_id_looper, /* id looper */ pycon_copy, /* copy data */ pycon_new_data, /* new data */ @@ -2088,35 +2067,29 @@ static bConstraintTypeInfo CTI_PYTHON = { /* -------- Action Constraint ----------- */ -static void actcon_relink (bConstraint *con) +static void actcon_new_data(void *cdata) { - bActionConstraint *data= con->data; - ID_NEW(data->act); -} - -static void actcon_new_data (void *cdata) -{ - bActionConstraint *data= (bActionConstraint *)cdata; + bActionConstraint *data = (bActionConstraint *)cdata; /* set type to 20 (Loc X), as 0 is Rot X for backwards compatibility */ data->type = 20; } -static void actcon_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void actcon_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bActionConstraint *data= con->data; + bActionConstraint *data = con->data; /* target */ - func(con, (ID**)&data->tar, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); /* action */ - func(con, (ID**)&data->act, userdata); + func(con, (ID **)&data->act, TRUE, userdata); } -static int actcon_get_tars (bConstraint *con, ListBase *list) +static int actcon_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bActionConstraint *data= con->data; + bActionConstraint *data = con->data; bConstraintTarget *ct; /* standard target-getting macro for single-target constraints */ @@ -2128,18 +2101,18 @@ static int actcon_get_tars (bConstraint *con, ListBase *list) return 0; } -static void actcon_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void actcon_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bActionConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bActionConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy) } } -static void actcon_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) +static void actcon_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) { bActionConstraint *data = con->data; @@ -2157,33 +2130,33 @@ static void actcon_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraint /* determine where in transform range target is */ /* data->type is mapped as follows for backwards compatibility: * 00,01,02 - rotation (it used to be like this) - * 10,11,12 - scaling + * 10,11,12 - scaling * 20,21,22 - location */ if (data->type < 10) { /* extract rotation (is in whatever space target should be in) */ mat4_to_eul(vec, tempmat); mul_v3_fl(vec, RAD2DEGF(1.0f)); /* rad -> deg */ - axis= data->type; + axis = data->type; } else if (data->type < 20) { /* extract scaling (is in whatever space target should be in) */ mat4_to_size(vec, tempmat); - axis= data->type - 10; + axis = data->type - 10; } else { /* extract location */ copy_v3_v3(vec, tempmat[3]); - axis= data->type - 20; + axis = data->type - 20; } /* Target defines the animation */ - s = (vec[axis]-data->min) / (data->max-data->min); + s = (vec[axis] - data->min) / (data->max - data->min); CLAMP(s, 0, 1); - t = (s * (data->end-data->start)) + data->start; + t = (s * (data->end - data->start)) + data->start; if (G.debug & G_DEBUG) - printf("do Action Constraint %s - Ob %s Pchan %s\n", con->name, cob->ob->id.name+2, (cob->pchan)?cob->pchan->name:NULL); + printf("do Action Constraint %s - Ob %s Pchan %s\n", con->name, cob->ob->id.name + 2, (cob->pchan) ? cob->pchan->name : NULL); /* Get the appropriate information from the action */ if (cob->type == CONSTRAINT_OBTYPE_BONE) { @@ -2199,18 +2172,18 @@ static void actcon_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraint */ pchan = cob->pchan; - tchan= verify_pose_channel(pose, pchan->name); - tchan->rotmode= pchan->rotmode; + tchan = BKE_pose_channel_verify(pose, pchan->name); + tchan->rotmode = pchan->rotmode; /* evaluate action using workob (it will only set the PoseChannel in question) */ what_does_obaction(cob->ob, &workob, pose, data->act, pchan->name, t); /* convert animation to matrices for use here */ - pchan_calc_mat(tchan); + BKE_pchan_calc_mat(tchan); copy_m4_m4(ct->matrix, tchan->chan_mat); /* Clean up */ - free_pose(pose); + BKE_pose_free(pose); } else if (cob->type == CONSTRAINT_OBTYPE_OBJECT) { Object workob; @@ -2218,7 +2191,7 @@ static void actcon_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraint /* evaluate using workob */ // FIXME: we don't have any consistent standards on limiting effects on object... what_does_obaction(cob->ob, &workob, NULL, data->act, NULL, t); - object_to_mat4(&workob, ct->matrix); + BKE_object_to_mat4(&workob, ct->matrix); } else { /* behavior undefined... */ @@ -2227,9 +2200,9 @@ static void actcon_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraint } } -static void actcon_evaluate (bConstraint *UNUSED(con), bConstraintOb *cob, ListBase *targets) +static void actcon_evaluate(bConstraint *UNUSED(con), bConstraintOb *cob, ListBase *targets) { - bConstraintTarget *ct= targets->first; + bConstraintTarget *ct = targets->first; if (VALID_CONS_TARGET(ct)) { float temp[4][4]; @@ -2248,7 +2221,6 @@ static bConstraintTypeInfo CTI_ACTION = { "Action", /* name */ "bActionConstraint", /* struct name */ NULL, /* free data */ - actcon_relink, /* relink data */ actcon_id_looper, /* id looper */ NULL, /* copy data */ actcon_new_data, /* new data */ @@ -2260,26 +2232,26 @@ static bConstraintTypeInfo CTI_ACTION = { /* --------- Locked Track ---------- */ -static void locktrack_new_data (void *cdata) +static void locktrack_new_data(void *cdata) { - bLockTrackConstraint *data= (bLockTrackConstraint *)cdata; + bLockTrackConstraint *data = (bLockTrackConstraint *)cdata; data->trackflag = TRACK_Y; data->lockflag = LOCK_Z; } -static void locktrack_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void locktrack_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bLockTrackConstraint *data= con->data; + bLockTrackConstraint *data = con->data; /* target only */ - func(con, (ID**)&data->tar, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); } -static int locktrack_get_tars (bConstraint *con, ListBase *list) +static int locktrack_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bLockTrackConstraint *data= con->data; + bLockTrackConstraint *data = con->data; bConstraintTarget *ct; /* the following macro is used for all standard single-target constraints */ @@ -2291,21 +2263,21 @@ static int locktrack_get_tars (bConstraint *con, ListBase *list) return 0; } -static void locktrack_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void locktrack_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bLockTrackConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bLockTrackConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy) } } -static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) +static void locktrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets) { - bLockTrackConstraint *data= con->data; - bConstraintTarget *ct= targets->first; + bLockTrackConstraint *data = con->data; + bConstraintTarget *ct = targets->first; if (VALID_CONS_TARGET(ct)) { float vec[3], vec2[3]; @@ -2318,217 +2290,217 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * /* Vector object -> target */ sub_v3_v3v3(vec, ct->matrix[3], cob->matrix[3]); switch (data->lockflag) { - case LOCK_X: /* LOCK X */ - { - switch (data->trackflag) { - case TRACK_Y: /* LOCK X TRACK Y */ - { - /* Projection of Vector on the plane */ - project_v3_v3v3(vec2, vec, cob->matrix[0]); - sub_v3_v3v3(totmat[1], vec, vec2); - normalize_v3(totmat[1]); + case LOCK_X: /* LOCK X */ + { + switch (data->trackflag) { + case TRACK_Y: /* LOCK X TRACK Y */ + { + /* Projection of Vector on the plane */ + project_v3_v3v3(vec2, vec, cob->matrix[0]); + sub_v3_v3v3(totmat[1], vec, vec2); + normalize_v3(totmat[1]); - /* the x axis is fixed */ - normalize_v3_v3(totmat[0], cob->matrix[0]); + /* the x axis is fixed */ + normalize_v3_v3(totmat[0], cob->matrix[0]); - /* the z axis gets mapped onto a third orthogonal vector */ - cross_v3_v3v3(totmat[2], totmat[0], totmat[1]); - } + /* the z axis gets mapped onto a third orthogonal vector */ + cross_v3_v3v3(totmat[2], totmat[0], totmat[1]); + } break; - case TRACK_Z: /* LOCK X TRACK Z */ - { - /* Projection of Vector on the plane */ - project_v3_v3v3(vec2, vec, cob->matrix[0]); - sub_v3_v3v3(totmat[2], vec, vec2); - normalize_v3(totmat[2]); + case TRACK_Z: /* LOCK X TRACK Z */ + { + /* Projection of Vector on the plane */ + project_v3_v3v3(vec2, vec, cob->matrix[0]); + sub_v3_v3v3(totmat[2], vec, vec2); + normalize_v3(totmat[2]); - /* the x axis is fixed */ - normalize_v3_v3(totmat[0], cob->matrix[0]); + /* the x axis is fixed */ + normalize_v3_v3(totmat[0], cob->matrix[0]); - /* the z axis gets mapped onto a third orthogonal vector */ - cross_v3_v3v3(totmat[1], totmat[2], totmat[0]); - } + /* the z axis gets mapped onto a third orthogonal vector */ + cross_v3_v3v3(totmat[1], totmat[2], totmat[0]); + } break; - case TRACK_nY: /* LOCK X TRACK -Y */ - { - /* Projection of Vector on the plane */ - project_v3_v3v3(vec2, vec, cob->matrix[0]); - sub_v3_v3v3(totmat[1], vec, vec2); - normalize_v3(totmat[1]); - negate_v3(totmat[1]); + case TRACK_nY: /* LOCK X TRACK -Y */ + { + /* Projection of Vector on the plane */ + project_v3_v3v3(vec2, vec, cob->matrix[0]); + sub_v3_v3v3(totmat[1], vec, vec2); + normalize_v3(totmat[1]); + negate_v3(totmat[1]); - /* the x axis is fixed */ - normalize_v3_v3(totmat[0], cob->matrix[0]); + /* the x axis is fixed */ + normalize_v3_v3(totmat[0], cob->matrix[0]); - /* the z axis gets mapped onto a third orthogonal vector */ - cross_v3_v3v3(totmat[2], totmat[0], totmat[1]); - } + /* the z axis gets mapped onto a third orthogonal vector */ + cross_v3_v3v3(totmat[2], totmat[0], totmat[1]); + } break; - case TRACK_nZ: /* LOCK X TRACK -Z */ - { - /* Projection of Vector on the plane */ - project_v3_v3v3(vec2, vec, cob->matrix[0]); - sub_v3_v3v3(totmat[2], vec, vec2); - normalize_v3(totmat[2]); - negate_v3(totmat[2]); + case TRACK_nZ: /* LOCK X TRACK -Z */ + { + /* Projection of Vector on the plane */ + project_v3_v3v3(vec2, vec, cob->matrix[0]); + sub_v3_v3v3(totmat[2], vec, vec2); + normalize_v3(totmat[2]); + negate_v3(totmat[2]); - /* the x axis is fixed */ - normalize_v3_v3(totmat[0], cob->matrix[0]); + /* the x axis is fixed */ + normalize_v3_v3(totmat[0], cob->matrix[0]); - /* the z axis gets mapped onto a third orthogonal vector */ - cross_v3_v3v3(totmat[1], totmat[2], totmat[0]); - } + /* the z axis gets mapped onto a third orthogonal vector */ + cross_v3_v3v3(totmat[1], totmat[2], totmat[0]); + } break; - default: - { - unit_m3(totmat); - } + default: + { + unit_m3(totmat); + } break; + } } - } break; - case LOCK_Y: /* LOCK Y */ - { - switch (data->trackflag) { - case TRACK_X: /* LOCK Y TRACK X */ - { - /* Projection of Vector on the plane */ - project_v3_v3v3(vec2, vec, cob->matrix[1]); - sub_v3_v3v3(totmat[0], vec, vec2); - normalize_v3(totmat[0]); + case LOCK_Y: /* LOCK Y */ + { + switch (data->trackflag) { + case TRACK_X: /* LOCK Y TRACK X */ + { + /* Projection of Vector on the plane */ + project_v3_v3v3(vec2, vec, cob->matrix[1]); + sub_v3_v3v3(totmat[0], vec, vec2); + normalize_v3(totmat[0]); - /* the y axis is fixed */ - normalize_v3_v3(totmat[1], cob->matrix[1]); + /* the y axis is fixed */ + normalize_v3_v3(totmat[1], cob->matrix[1]); - /* the z axis gets mapped onto a third orthogonal vector */ - cross_v3_v3v3(totmat[2], totmat[0], totmat[1]); - } + /* the z axis gets mapped onto a third orthogonal vector */ + cross_v3_v3v3(totmat[2], totmat[0], totmat[1]); + } break; - case TRACK_Z: /* LOCK Y TRACK Z */ - { - /* Projection of Vector on the plane */ - project_v3_v3v3(vec2, vec, cob->matrix[1]); - sub_v3_v3v3(totmat[2], vec, vec2); - normalize_v3(totmat[2]); + case TRACK_Z: /* LOCK Y TRACK Z */ + { + /* Projection of Vector on the plane */ + project_v3_v3v3(vec2, vec, cob->matrix[1]); + sub_v3_v3v3(totmat[2], vec, vec2); + normalize_v3(totmat[2]); - /* the y axis is fixed */ - normalize_v3_v3(totmat[1], cob->matrix[1]); + /* the y axis is fixed */ + normalize_v3_v3(totmat[1], cob->matrix[1]); - /* the z axis gets mapped onto a third orthogonal vector */ - cross_v3_v3v3(totmat[0], totmat[1], totmat[2]); - } + /* the z axis gets mapped onto a third orthogonal vector */ + cross_v3_v3v3(totmat[0], totmat[1], totmat[2]); + } break; - case TRACK_nX: /* LOCK Y TRACK -X */ - { - /* Projection of Vector on the plane */ - project_v3_v3v3(vec2, vec, cob->matrix[1]); - sub_v3_v3v3(totmat[0], vec, vec2); - normalize_v3(totmat[0]); - negate_v3(totmat[0]); + case TRACK_nX: /* LOCK Y TRACK -X */ + { + /* Projection of Vector on the plane */ + project_v3_v3v3(vec2, vec, cob->matrix[1]); + sub_v3_v3v3(totmat[0], vec, vec2); + normalize_v3(totmat[0]); + negate_v3(totmat[0]); - /* the y axis is fixed */ - normalize_v3_v3(totmat[1], cob->matrix[1]); + /* the y axis is fixed */ + normalize_v3_v3(totmat[1], cob->matrix[1]); - /* the z axis gets mapped onto a third orthogonal vector */ - cross_v3_v3v3(totmat[2], totmat[0], totmat[1]); - } + /* the z axis gets mapped onto a third orthogonal vector */ + cross_v3_v3v3(totmat[2], totmat[0], totmat[1]); + } break; - case TRACK_nZ: /* LOCK Y TRACK -Z */ - { - /* Projection of Vector on the plane */ - project_v3_v3v3(vec2, vec, cob->matrix[1]); - sub_v3_v3v3(totmat[2], vec, vec2); - normalize_v3(totmat[2]); - negate_v3(totmat[2]); + case TRACK_nZ: /* LOCK Y TRACK -Z */ + { + /* Projection of Vector on the plane */ + project_v3_v3v3(vec2, vec, cob->matrix[1]); + sub_v3_v3v3(totmat[2], vec, vec2); + normalize_v3(totmat[2]); + negate_v3(totmat[2]); - /* the y axis is fixed */ - normalize_v3_v3(totmat[1], cob->matrix[1]); + /* the y axis is fixed */ + normalize_v3_v3(totmat[1], cob->matrix[1]); - /* the z axis gets mapped onto a third orthogonal vector */ - cross_v3_v3v3(totmat[0], totmat[1], totmat[2]); - } + /* the z axis gets mapped onto a third orthogonal vector */ + cross_v3_v3v3(totmat[0], totmat[1], totmat[2]); + } break; - default: - { - unit_m3(totmat); - } + default: + { + unit_m3(totmat); + } break; + } } - } break; - case LOCK_Z: /* LOCK Z */ - { - switch (data->trackflag) { - case TRACK_X: /* LOCK Z TRACK X */ - { - /* Projection of Vector on the plane */ - project_v3_v3v3(vec2, vec, cob->matrix[2]); - sub_v3_v3v3(totmat[0], vec, vec2); - normalize_v3(totmat[0]); + case LOCK_Z: /* LOCK Z */ + { + switch (data->trackflag) { + case TRACK_X: /* LOCK Z TRACK X */ + { + /* Projection of Vector on the plane */ + project_v3_v3v3(vec2, vec, cob->matrix[2]); + sub_v3_v3v3(totmat[0], vec, vec2); + normalize_v3(totmat[0]); - /* the z axis is fixed */ - normalize_v3_v3(totmat[2], cob->matrix[2]); + /* the z axis is fixed */ + normalize_v3_v3(totmat[2], cob->matrix[2]); - /* the x axis gets mapped onto a third orthogonal vector */ - cross_v3_v3v3(totmat[1], totmat[2], totmat[0]); - } + /* the x axis gets mapped onto a third orthogonal vector */ + cross_v3_v3v3(totmat[1], totmat[2], totmat[0]); + } break; - case TRACK_Y: /* LOCK Z TRACK Y */ - { - /* Projection of Vector on the plane */ - project_v3_v3v3(vec2, vec, cob->matrix[2]); - sub_v3_v3v3(totmat[1], vec, vec2); - normalize_v3(totmat[1]); + case TRACK_Y: /* LOCK Z TRACK Y */ + { + /* Projection of Vector on the plane */ + project_v3_v3v3(vec2, vec, cob->matrix[2]); + sub_v3_v3v3(totmat[1], vec, vec2); + normalize_v3(totmat[1]); - /* the z axis is fixed */ - normalize_v3_v3(totmat[2], cob->matrix[2]); + /* the z axis is fixed */ + normalize_v3_v3(totmat[2], cob->matrix[2]); - /* the x axis gets mapped onto a third orthogonal vector */ - cross_v3_v3v3(totmat[0], totmat[1], totmat[2]); - } + /* the x axis gets mapped onto a third orthogonal vector */ + cross_v3_v3v3(totmat[0], totmat[1], totmat[2]); + } break; - case TRACK_nX: /* LOCK Z TRACK -X */ - { - /* Projection of Vector on the plane */ - project_v3_v3v3(vec2, vec, cob->matrix[2]); - sub_v3_v3v3(totmat[0], vec, vec2); - normalize_v3(totmat[0]); - negate_v3(totmat[0]); + case TRACK_nX: /* LOCK Z TRACK -X */ + { + /* Projection of Vector on the plane */ + project_v3_v3v3(vec2, vec, cob->matrix[2]); + sub_v3_v3v3(totmat[0], vec, vec2); + normalize_v3(totmat[0]); + negate_v3(totmat[0]); - /* the z axis is fixed */ - normalize_v3_v3(totmat[2], cob->matrix[2]); + /* the z axis is fixed */ + normalize_v3_v3(totmat[2], cob->matrix[2]); - /* the x axis gets mapped onto a third orthogonal vector */ - cross_v3_v3v3(totmat[1], totmat[2], totmat[0]); - } + /* the x axis gets mapped onto a third orthogonal vector */ + cross_v3_v3v3(totmat[1], totmat[2], totmat[0]); + } break; - case TRACK_nY: /* LOCK Z TRACK -Y */ - { - /* Projection of Vector on the plane */ - project_v3_v3v3(vec2, vec, cob->matrix[2]); - sub_v3_v3v3(totmat[1], vec, vec2); - normalize_v3(totmat[1]); - negate_v3(totmat[1]); + case TRACK_nY: /* LOCK Z TRACK -Y */ + { + /* Projection of Vector on the plane */ + project_v3_v3v3(vec2, vec, cob->matrix[2]); + sub_v3_v3v3(totmat[1], vec, vec2); + normalize_v3(totmat[1]); + negate_v3(totmat[1]); - /* the z axis is fixed */ - normalize_v3_v3(totmat[2], cob->matrix[2]); + /* the z axis is fixed */ + normalize_v3_v3(totmat[2], cob->matrix[2]); - /* the x axis gets mapped onto a third orthogonal vector */ - cross_v3_v3v3(totmat[0], totmat[1], totmat[2]); - } + /* the x axis gets mapped onto a third orthogonal vector */ + cross_v3_v3v3(totmat[0], totmat[1], totmat[2]); + } break; - default: - { - unit_m3(totmat); - } + default: + { + unit_m3(totmat); + } break; + } } - } break; - default: - { - unit_m3(totmat); - } + default: + { + unit_m3(totmat); + } break; } /* Block to keep matrix heading */ @@ -2536,16 +2508,16 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * normalize_m3(tmpmat); invert_m3_m3(invmat, tmpmat); mul_m3_m3m3(tmpmat, totmat, invmat); - totmat[0][0] = tmpmat[0][0];totmat[0][1] = tmpmat[0][1];totmat[0][2] = tmpmat[0][2]; - totmat[1][0] = tmpmat[1][0];totmat[1][1] = tmpmat[1][1];totmat[1][2] = tmpmat[1][2]; - totmat[2][0] = tmpmat[2][0];totmat[2][1] = tmpmat[2][1];totmat[2][2] = tmpmat[2][2]; + totmat[0][0] = tmpmat[0][0]; totmat[0][1] = tmpmat[0][1]; totmat[0][2] = tmpmat[0][2]; + totmat[1][0] = tmpmat[1][0]; totmat[1][1] = tmpmat[1][1]; totmat[1][2] = tmpmat[1][2]; + totmat[2][0] = tmpmat[2][0]; totmat[2][1] = tmpmat[2][1]; totmat[2][2] = tmpmat[2][2]; copy_m4_m4(tmat, cob->matrix); mdet = determinant_m3(totmat[0][0], totmat[0][1], totmat[0][2], totmat[1][0], totmat[1][1], totmat[1][2], totmat[2][0], totmat[2][1], totmat[2][2]); - if (mdet==0) { + if (mdet == 0) { unit_m3(totmat); } @@ -2560,7 +2532,6 @@ static bConstraintTypeInfo CTI_LOCKTRACK = { "Locked Track", /* name */ "bLockTrackConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ locktrack_id_looper, /* id looper */ NULL, /* copy data */ locktrack_new_data, /* new data */ @@ -2572,25 +2543,25 @@ static bConstraintTypeInfo CTI_LOCKTRACK = { /* ---------- Limit Distance Constraint ----------- */ -static void distlimit_new_data (void *cdata) +static void distlimit_new_data(void *cdata) { - bDistLimitConstraint *data= (bDistLimitConstraint *)cdata; + bDistLimitConstraint *data = (bDistLimitConstraint *)cdata; - data->dist= 0.0f; + data->dist = 0.0f; } -static void distlimit_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void distlimit_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bDistLimitConstraint *data= con->data; + bDistLimitConstraint *data = con->data; /* target only */ - func(con, (ID**)&data->tar, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); } -static int distlimit_get_tars (bConstraint *con, ListBase *list) +static int distlimit_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bDistLimitConstraint *data= con->data; + bDistLimitConstraint *data = con->data; bConstraintTarget *ct; /* standard target-getting macro for single-target constraints */ @@ -2602,40 +2573,40 @@ static int distlimit_get_tars (bConstraint *con, ListBase *list) return 0; } -static void distlimit_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void distlimit_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bDistLimitConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bDistLimitConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy) } } -static void distlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) +static void distlimit_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets) { - bDistLimitConstraint *data= con->data; - bConstraintTarget *ct= targets->first; + bDistLimitConstraint *data = con->data; + bConstraintTarget *ct = targets->first; /* only evaluate if there is a target */ if (VALID_CONS_TARGET(ct)) { - float dvec[3], dist=0.0f, sfac=1.0f; - short clamp_surf= 0; + float dvec[3], dist = 0.0f, sfac = 1.0f; + short clamp_surf = 0; /* calculate our current distance from the target */ - dist= len_v3v3(cob->matrix[3], ct->matrix[3]); + dist = len_v3v3(cob->matrix[3], ct->matrix[3]); /* set distance (flag is only set when user demands it) */ if (data->dist == 0) - data->dist= dist; + data->dist = dist; /* check if we're which way to clamp from, and calculate interpolation factor (if needed) */ if (data->mode == LIMITDIST_OUTSIDE) { /* if inside, then move to surface */ if (dist <= data->dist) { - clamp_surf= 1; - if (dist != 0.0f) sfac= data->dist / dist; + clamp_surf = 1; + if (dist != 0.0f) sfac = data->dist / dist; } /* if soft-distance is enabled, start fading once owner is dist+softdist from the target */ else if (data->flag & LIMITDIST_USESOFT) { @@ -2647,24 +2618,24 @@ static void distlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * else if (data->mode == LIMITDIST_INSIDE) { /* if outside, then move to surface */ if (dist >= data->dist) { - clamp_surf= 1; - if (dist != 0.0f) sfac= data->dist / dist; + clamp_surf = 1; + if (dist != 0.0f) sfac = data->dist / dist; } /* if soft-distance is enabled, start fading once owner is dist-soft from the target */ 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.0f - expf(-(dist - data->dist)/data->soft)) + data->dist ); + sfac = (float)(data->soft * (1.0f - expf(-(dist - data->dist) / data->soft)) + data->dist); if (dist != 0.0f) sfac /= dist; - clamp_surf= 1; + clamp_surf = 1; } } } else { - if (IS_EQF(dist, data->dist)==0) { - clamp_surf= 1; - if (dist != 0.0f) sfac= data->dist / dist; + if (IS_EQF(dist, data->dist) == 0) { + clamp_surf = 1; + if (dist != 0.0f) sfac = data->dist / dist; } } @@ -2685,7 +2656,6 @@ static bConstraintTypeInfo CTI_DISTLIMIT = { "Limit Distance", /* name */ "bDistLimitConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ distlimit_id_looper, /* id looper */ NULL, /* copy data */ distlimit_new_data, /* new data */ @@ -2697,9 +2667,9 @@ static bConstraintTypeInfo CTI_DISTLIMIT = { /* ---------- Stretch To ------------ */ -static void stretchto_new_data (void *cdata) +static void stretchto_new_data(void *cdata) { - bStretchToConstraint *data= (bStretchToConstraint *)cdata; + bStretchToConstraint *data = (bStretchToConstraint *)cdata; data->volmode = 0; data->plane = 0; @@ -2707,18 +2677,18 @@ static void stretchto_new_data (void *cdata) data->bulge = 1.0; } -static void stretchto_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void stretchto_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bStretchToConstraint *data= con->data; + bStretchToConstraint *data = con->data; /* target only */ - func(con, (ID**)&data->tar, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); } -static int stretchto_get_tars (bConstraint *con, ListBase *list) +static int stretchto_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bStretchToConstraint *data= con->data; + bStretchToConstraint *data = con->data; bConstraintTarget *ct; /* standard target-getting macro for single-target constraints */ @@ -2730,21 +2700,21 @@ static int stretchto_get_tars (bConstraint *con, ListBase *list) return 0; } -static void stretchto_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void stretchto_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bStretchToConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bStretchToConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy) } } -static void stretchto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) +static void stretchto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets) { - bStretchToConstraint *data= con->data; - bConstraintTarget *ct= targets->first; + bStretchToConstraint *data = con->data; + bConstraintTarget *ct = targets->first; /* only evaluate if there is a target */ if (VALID_CONS_TARGET(ct)) { @@ -2780,40 +2750,40 @@ static void stretchto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * if (data->bulge == 0) data->bulge = 1.0; - scale[1] = dist/data->orglength; + scale[1] = dist / data->orglength; switch (data->volmode) { - /* volume preserving scaling */ - case VOLUME_XZ : - scale[0] = 1.0f - (float)sqrt(data->bulge) + (float)sqrt(data->bulge*(data->orglength/dist)); - scale[2] = scale[0]; - break; - case VOLUME_X: - scale[0] = 1.0f + data->bulge * (data->orglength /dist - 1); - scale[2] = 1.0; - break; - case VOLUME_Z: - scale[0] = 1.0; - scale[2] = 1.0f + data->bulge * (data->orglength /dist - 1); - break; + /* volume preserving scaling */ + case VOLUME_XZ: + scale[0] = 1.0f - (float)sqrt(data->bulge) + (float)sqrt(data->bulge * (data->orglength / dist)); + scale[2] = scale[0]; + break; + case VOLUME_X: + scale[0] = 1.0f + data->bulge * (data->orglength / dist - 1); + scale[2] = 1.0; + break; + case VOLUME_Z: + scale[0] = 1.0; + scale[2] = 1.0f + data->bulge * (data->orglength / dist - 1); + break; /* don't care for volume */ - case NO_VOLUME: - scale[0] = 1.0; - scale[2] = 1.0; - break; - default: /* should not happen, but in case*/ - return; + case NO_VOLUME: + scale[0] = 1.0; + scale[2] = 1.0; + break; + default: /* should not happen, but in case*/ + return; } /* switch (data->volmode) */ /* Clear the object's rotation and scale */ - cob->matrix[0][0]=size[0]*scale[0]; - cob->matrix[0][1]=0; - cob->matrix[0][2]=0; - cob->matrix[1][0]=0; - cob->matrix[1][1]=size[1]*scale[1]; - cob->matrix[1][2]=0; - cob->matrix[2][0]=0; - cob->matrix[2][1]=0; - cob->matrix[2][2]=size[2]*scale[2]; + cob->matrix[0][0] = size[0] * scale[0]; + cob->matrix[0][1] = 0; + cob->matrix[0][2] = 0; + cob->matrix[1][0] = 0; + cob->matrix[1][1] = size[1] * scale[1]; + cob->matrix[1][2] = 0; + cob->matrix[2][0] = 0; + cob->matrix[2][1] = 0; + cob->matrix[2][2] = size[2] * scale[2]; sub_v3_v3v3(vec, cob->matrix[3], ct->matrix[3]); normalize_v3(vec); @@ -2821,32 +2791,32 @@ static void stretchto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * /* new Y aligns object target connection*/ negate_v3_v3(totmat[1], vec); switch (data->plane) { - case PLANE_X: - /* build new Z vector */ - /* othogonal to "new Y" "old X! plane */ - cross_v3_v3v3(orth, vec, xx); - normalize_v3(orth); - - /* new Z*/ - copy_v3_v3(totmat[2], orth); - - /* we decided to keep X plane*/ - cross_v3_v3v3(xx, orth, vec); - normalize_v3_v3(totmat[0], xx); - break; - case PLANE_Z: - /* build new X vector */ - /* othogonal to "new Y" "old Z! plane */ - cross_v3_v3v3(orth, vec, zz); - normalize_v3(orth); - - /* new X */ - negate_v3_v3(totmat[0], orth); - - /* we decided to keep Z */ - cross_v3_v3v3(zz, orth, vec); - normalize_v3_v3(totmat[2], zz); - break; + case PLANE_X: + /* build new Z vector */ + /* othogonal to "new Y" "old X! plane */ + cross_v3_v3v3(orth, vec, xx); + normalize_v3(orth); + + /* new Z*/ + copy_v3_v3(totmat[2], orth); + + /* we decided to keep X plane*/ + cross_v3_v3v3(xx, orth, vec); + normalize_v3_v3(totmat[0], xx); + break; + case PLANE_Z: + /* build new X vector */ + /* othogonal to "new Y" "old Z! plane */ + cross_v3_v3v3(orth, vec, zz); + normalize_v3(orth); + + /* new X */ + negate_v3_v3(totmat[0], orth); + + /* we decided to keep Z */ + cross_v3_v3v3(zz, orth, vec); + normalize_v3_v3(totmat[2], zz); + break; } /* switch (data->plane) */ copy_m4_m4(tmat, cob->matrix); @@ -2860,7 +2830,6 @@ static bConstraintTypeInfo CTI_STRETCHTO = { "Stretch To", /* name */ "bStretchToConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ stretchto_id_looper, /* id looper */ NULL, /* copy data */ stretchto_new_data, /* new data */ @@ -2872,9 +2841,9 @@ static bConstraintTypeInfo CTI_STRETCHTO = { /* ---------- Floor ------------ */ -static void minmax_new_data (void *cdata) +static void minmax_new_data(void *cdata) { - bMinMaxConstraint *data= (bMinMaxConstraint *)cdata; + bMinMaxConstraint *data = (bMinMaxConstraint *)cdata; data->minmaxflag = TRACK_Z; data->offset = 0.0f; @@ -2882,18 +2851,18 @@ static void minmax_new_data (void *cdata) data->flag = 0; } -static void minmax_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void minmax_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bMinMaxConstraint *data= con->data; + bMinMaxConstraint *data = con->data; /* target only */ - func(con, (ID**)&data->tar, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); } -static int minmax_get_tars (bConstraint *con, ListBase *list) +static int minmax_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bMinMaxConstraint *data= con->data; + bMinMaxConstraint *data = con->data; bConstraintTarget *ct; /* standard target-getting macro for single-target constraints */ @@ -2905,21 +2874,21 @@ static int minmax_get_tars (bConstraint *con, ListBase *list) return 0; } -static void minmax_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void minmax_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bMinMaxConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bMinMaxConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy) } } -static void minmax_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) +static void minmax_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets) { - bMinMaxConstraint *data= con->data; - bConstraintTarget *ct= targets->first; + bMinMaxConstraint *data = con->data; + bConstraintTarget *ct = targets->first; /* only evaluate if there is a target */ if (VALID_CONS_TARGET(ct)) { @@ -2939,38 +2908,38 @@ static void minmax_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *tar } switch (data->minmaxflag) { - case TRACK_Z: - val1 = tarmat[3][2]; - val2 = obmat[3][2]-data->offset; - index = 2; - break; - case TRACK_Y: - val1 = tarmat[3][1]; - val2 = obmat[3][1]-data->offset; - index = 1; - break; - case TRACK_X: - val1 = tarmat[3][0]; - val2 = obmat[3][0]-data->offset; - index = 0; - break; - case TRACK_nZ: - val2 = tarmat[3][2]; - val1 = obmat[3][2]-data->offset; - index = 2; - break; - case TRACK_nY: - val2 = tarmat[3][1]; - val1 = obmat[3][1]-data->offset; - index = 1; - break; - case TRACK_nX: - val2 = tarmat[3][0]; - val1 = obmat[3][0]-data->offset; - index = 0; - break; - default: - return; + case TRACK_Z: + val1 = tarmat[3][2]; + val2 = obmat[3][2] - data->offset; + index = 2; + break; + case TRACK_Y: + val1 = tarmat[3][1]; + val2 = obmat[3][1] - data->offset; + index = 1; + break; + case TRACK_X: + val1 = tarmat[3][0]; + val2 = obmat[3][0] - data->offset; + index = 0; + break; + case TRACK_nZ: + val2 = tarmat[3][2]; + val1 = obmat[3][2] - data->offset; + index = 2; + break; + case TRACK_nY: + val2 = tarmat[3][1]; + val1 = obmat[3][1] - data->offset; + index = 1; + break; + case TRACK_nX: + val2 = tarmat[3][0]; + val1 = obmat[3][0] - data->offset; + index = 0; + break; + default: + return; } if (val1 > val2) { @@ -3005,7 +2974,6 @@ static bConstraintTypeInfo CTI_MINMAX = { "Floor", /* name */ "bMinMaxConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ minmax_id_looper, /* id looper */ NULL, /* copy data */ minmax_new_data, /* new data */ @@ -3017,27 +2985,27 @@ static bConstraintTypeInfo CTI_MINMAX = { /* ------- RigidBody Joint ---------- */ -static void rbj_new_data (void *cdata) +static void rbj_new_data(void *cdata) { - bRigidBodyJointConstraint *data= (bRigidBodyJointConstraint *)cdata; + bRigidBodyJointConstraint *data = (bRigidBodyJointConstraint *)cdata; // removed code which set target of this constraint - data->type=1; + data->type = 1; } -static void rbj_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void rbj_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bRigidBodyJointConstraint *data= con->data; + bRigidBodyJointConstraint *data = con->data; /* target only */ - func(con, (ID**)&data->tar, userdata); - func(con, (ID**)&data->child, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); + func(con, (ID **)&data->child, FALSE, userdata); } -static int rbj_get_tars (bConstraint *con, ListBase *list) +static int rbj_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bRigidBodyJointConstraint *data= con->data; + bRigidBodyJointConstraint *data = con->data; bConstraintTarget *ct; /* standard target-getting macro for single-target constraints without subtargets */ @@ -3049,11 +3017,11 @@ static int rbj_get_tars (bConstraint *con, ListBase *list) return 0; } -static void rbj_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void rbj_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bRigidBodyJointConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bRigidBodyJointConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGETNS_FLUSH_TARS(con, data->tar, ct, list, nocopy) @@ -3066,7 +3034,6 @@ static bConstraintTypeInfo CTI_RIGIDBODYJOINT = { "Rigid Body Joint", /* name */ "bRigidBodyJointConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ rbj_id_looper, /* id looper */ NULL, /* copy data */ rbj_new_data, /* new data */ @@ -3078,18 +3045,18 @@ static bConstraintTypeInfo CTI_RIGIDBODYJOINT = { /* -------- Clamp To ---------- */ -static void clampto_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void clampto_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bClampToConstraint *data= con->data; + bClampToConstraint *data = con->data; /* target only */ - func(con, (ID**)&data->tar, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); } -static int clampto_get_tars (bConstraint *con, ListBase *list) +static int clampto_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bClampToConstraint *data= con->data; + bClampToConstraint *data = con->data; bConstraintTarget *ct; /* standard target-getting macro for single-target constraints without subtargets */ @@ -3101,29 +3068,29 @@ static int clampto_get_tars (bConstraint *con, ListBase *list) return 0; } -static void clampto_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void clampto_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bClampToConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bClampToConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGETNS_FLUSH_TARS(con, data->tar, ct, list, nocopy) } } -static void clampto_get_tarmat (bConstraint *UNUSED(con), bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) +static void clampto_get_tarmat(bConstraint *UNUSED(con), bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) { if (VALID_CONS_TARGET(ct)) { - Curve *cu= ct->tar->data; + Curve *cu = ct->tar->data; /* note: when creating constraints that follow path, the curve gets the CU_PATH set now, * currently for paths to work it needs to go through the bevlist/displist system (ton) */ /* only happens on reload file, but violates depsgraph still... fix! */ - if (cu->path==NULL || cu->path->data==NULL) - makeDispListCurveTypes(cob->scene, ct->tar, 0); + if (cu->path == NULL || cu->path->data == NULL) + BKE_displist_make_curveTypes(cob->scene, ct->tar, 0); } /* technically, this isn't really needed for evaluation, but we don't know what else @@ -3133,23 +3100,23 @@ static void clampto_get_tarmat (bConstraint *UNUSED(con), bConstraintOb *cob, bC unit_m4(ct->matrix); } -static void clampto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) +static void clampto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets) { - bClampToConstraint *data= con->data; - bConstraintTarget *ct= targets->first; + bClampToConstraint *data = con->data; + bConstraintTarget *ct = targets->first; /* only evaluate if there is a target and it is a curve */ if (VALID_CONS_TARGET(ct) && (ct->tar->type == OB_CURVE)) { - Curve *cu= data->tar->data; + Curve *cu = data->tar->data; float obmat[4][4], ownLoc[3]; float curveMin[3], curveMax[3]; - float targetMatrix[4][4]= MAT4_UNITY; + float targetMatrix[4][4] = MAT4_UNITY; copy_m4_m4(obmat, cob->matrix); copy_v3_v3(ownLoc, obmat[3]); INIT_MINMAX(curveMin, curveMax) - minmax_object(ct->tar, curveMin, curveMax); + BKE_object_minmax(ct->tar, curveMin, curveMax); /* get targetmatrix */ if (cu->path && cu->path->data) { @@ -3167,20 +3134,20 @@ static void clampto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta * extent. Otherwise, default to the x-axis, as that is quite * frequently used. */ - if ((size[2]>size[0]) && (size[2]>size[1])) - clamp_axis= CLAMPTO_Z - 1; - else if ((size[1]>size[0]) && (size[1]>size[2])) - clamp_axis= CLAMPTO_Y - 1; + if ((size[2] > size[0]) && (size[2] > size[1])) + clamp_axis = CLAMPTO_Z - 1; + else if ((size[1] > size[0]) && (size[1] > size[2])) + clamp_axis = CLAMPTO_Y - 1; else clamp_axis = CLAMPTO_X - 1; } else - clamp_axis= data->flag - 1; + clamp_axis = data->flag - 1; /* 2. determine position relative to curve on a 0-1 scale based on bounding box */ if (data->flag2 & CLAMPTO_CYCLIC) { /* cyclic, so offset within relative bounding box is used */ - float len= (curveMax[clamp_axis] - curveMin[clamp_axis]); + float len = (curveMax[clamp_axis] - curveMin[clamp_axis]); float offset; /* check to make sure len is not so close to zero that it'll cause errors */ @@ -3195,7 +3162,7 @@ static void clampto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta } else if (ownLoc[clamp_axis] > curveMax[clamp_axis]) { /* bounding-box range is after */ - offset= curveMax[clamp_axis] + (int)((ownLoc[clamp_axis] - curveMax[clamp_axis]) / len) * len; + offset = curveMax[clamp_axis] + (int)((ownLoc[clamp_axis] - curveMax[clamp_axis]) / len) * len; /* now, we calculate as per normal, except using offset instead of curveMax[clamp_axis] */ curvetime = (ownLoc[clamp_axis] - offset) / (len); @@ -3207,7 +3174,7 @@ static void clampto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta } else { /* as length is close to zero, curvetime by default should be 0 (i.e. the start) */ - curvetime= 0.0f; + curvetime = 0.0f; } } else { @@ -3216,7 +3183,7 @@ static void clampto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta curvetime = 0.0f; else if (ownLoc[clamp_axis] >= curveMax[clamp_axis]) curvetime = 1.0f; - else if ( IS_EQ((curveMax[clamp_axis] - curveMin[clamp_axis]), 0) == 0 ) + else if (IS_EQ((curveMax[clamp_axis] - curveMin[clamp_axis]), 0) == 0) curvetime = (ownLoc[clamp_axis] - curveMin[clamp_axis]) / (curveMax[clamp_axis] - curveMin[clamp_axis]); else curvetime = 0.0f; @@ -3242,7 +3209,6 @@ static bConstraintTypeInfo CTI_CLAMPTO = { "Clamp To", /* name */ "bClampToConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ clampto_id_looper, /* id looper */ NULL, /* copy data */ NULL, /* new data */ @@ -3254,27 +3220,27 @@ static bConstraintTypeInfo CTI_CLAMPTO = { /* ---------- Transform Constraint ----------- */ -static void transform_new_data (void *cdata) +static void transform_new_data(void *cdata) { - bTransformConstraint *data= (bTransformConstraint *)cdata; + bTransformConstraint *data = (bTransformConstraint *)cdata; - data->map[0]= 0; - data->map[1]= 1; - data->map[2]= 2; + data->map[0] = 0; + data->map[1] = 1; + data->map[2] = 2; } -static void transform_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void transform_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bTransformConstraint *data= con->data; + bTransformConstraint *data = con->data; /* target only */ - func(con, (ID**)&data->tar, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); } -static int transform_get_tars (bConstraint *con, ListBase *list) +static int transform_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bTransformConstraint *data= con->data; + bTransformConstraint *data = con->data; bConstraintTarget *ct; /* standard target-getting macro for single-target constraints */ @@ -3286,21 +3252,21 @@ static int transform_get_tars (bConstraint *con, ListBase *list) return 0; } -static void transform_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void transform_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bTransformConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bTransformConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy) } } -static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) +static void transform_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets) { - bTransformConstraint *data= con->data; - bConstraintTarget *ct= targets->first; + bTransformConstraint *data = con->data; + bConstraintTarget *ct = targets->first; /* only evaluate if there is a target */ if (VALID_CONS_TARGET(ct)) { @@ -3329,21 +3295,21 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * /* determine where in range current transforms lie */ if (data->expo) { - for (i=0; i<3; i++) { + for (i = 0; i < 3; i++) { if (data->from_max[i] - data->from_min[i]) - sval[i]= (dvec[i] - data->from_min[i]) / (data->from_max[i] - data->from_min[i]); + sval[i] = (dvec[i] - data->from_min[i]) / (data->from_max[i] - data->from_min[i]); else - sval[i]= 0.0f; + sval[i] = 0.0f; } } else { /* clamp transforms out of range */ - for (i=0; i<3; i++) { + for (i = 0; i < 3; i++) { CLAMP(dvec[i], data->from_min[i], data->from_max[i]); if (data->from_max[i] - data->from_min[i]) - sval[i]= (dvec[i] - data->from_min[i]) / (data->from_max[i] - data->from_min[i]); + sval[i] = (dvec[i] - data->from_min[i]) / (data->from_max[i] - data->from_min[i]); else - sval[i]= 0.0f; + sval[i] = 0.0f; } } @@ -3351,18 +3317,18 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * /* apply transforms */ switch (data->to) { case 2: /* scaling */ - for (i=0; i<3; i++) - size[i]= data->to_min[i] + (sval[(int)data->map[i]] * (data->to_max[i] - data->to_min[i])); + for (i = 0; i < 3; i++) + size[i] = data->to_min[i] + (sval[(int)data->map[i]] * (data->to_max[i] - data->to_min[i])); break; case 1: /* rotation */ - for (i=0; i<3; i++) { + for (i = 0; i < 3; i++) { float tmin, tmax; - tmin= data->to_min[i]; - tmax= data->to_max[i]; + tmin = data->to_min[i]; + tmax = data->to_max[i]; /* all values here should be in degrees */ - eul[i]= tmin + (sval[(int)data->map[i]] * (tmax - tmin)); + eul[i] = tmin + (sval[(int)data->map[i]] * (tmax - tmin)); /* now convert final value back to radians */ eul[i] = DEG2RADF(eul[i]); @@ -3370,8 +3336,8 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * break; default: /* location */ /* get new location */ - for (i=0; i<3; i++) - loc[i]= (data->to_min[i] + (sval[(int)data->map[i]] * (data->to_max[i] - data->to_min[i]))); + for (i = 0; i < 3; i++) + loc[i] = (data->to_min[i] + (sval[(int)data->map[i]] * (data->to_max[i] - data->to_min[i]))); /* add original location back on (so that it can still be moved) */ add_v3_v3v3(loc, cob->matrix[3], loc); @@ -3389,7 +3355,6 @@ static bConstraintTypeInfo CTI_TRANSFORM = { "Transform", /* name */ "bTransformConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ transform_id_looper, /* id looper */ NULL, /* copy data */ transform_new_data, /* new data */ @@ -3401,15 +3366,15 @@ static bConstraintTypeInfo CTI_TRANSFORM = { /* ---------- Shrinkwrap Constraint ----------- */ -static void shrinkwrap_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void shrinkwrap_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bShrinkwrapConstraint *data= con->data; + bShrinkwrapConstraint *data = con->data; /* target only */ - func(con, (ID**)&data->target, userdata); + func(con, (ID **)&data->target, FALSE, userdata); } -static int shrinkwrap_get_tars (bConstraint *con, ListBase *list) +static int shrinkwrap_get_tars(bConstraint *con, ListBase *list) { if (con && list) { bShrinkwrapConstraint *data = con->data; @@ -3424,22 +3389,22 @@ static int shrinkwrap_get_tars (bConstraint *con, ListBase *list) } -static void shrinkwrap_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void shrinkwrap_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { bShrinkwrapConstraint *data = con->data; - bConstraintTarget *ct= list->first; + bConstraintTarget *ct = list->first; SINGLETARGETNS_FLUSH_TARS(con, data->target, ct, list, nocopy) } } -static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) +static void shrinkwrap_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) { bShrinkwrapConstraint *scon = (bShrinkwrapConstraint *) con->data; - if ( VALID_CONS_TARGET(ct) && (ct->tar->type == OB_MESH) ) { + if (VALID_CONS_TARGET(ct) && (ct->tar->type == OB_MESH) ) { int fail = FALSE; float co[3] = {0.0f, 0.0f, 0.0f}; float no[3] = {0.0f, 0.0f, 0.0f}; @@ -3450,7 +3415,7 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr BVHTreeRayHit hit; BVHTreeNearest nearest; - BVHTreeFromMesh treeData= {NULL}; + BVHTreeFromMesh treeData = {NULL}; nearest.index = -1; nearest.dist = FLT_MAX; @@ -3483,10 +3448,10 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr dist = len_v3v3(co, nearest.co); if (dist != 0.0f) { - interp_v3_v3v3(co, co, nearest.co, (dist - scon->dist)/dist); /* linear interpolation */ + interp_v3_v3v3(co, co, nearest.co, (dist - scon->dist) / dist); /* linear interpolation */ } space_transform_invert(&transform, co); - break; + break; case MOD_SHRINKWRAP_PROJECT: if (scon->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_X_AXIS) no[0] = 1.0f; @@ -3512,7 +3477,7 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr break; } copy_v3_v3(co, hit.co); - break; + break; } free_bvhtree_from_mesh(&treeData); @@ -3531,9 +3496,9 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr } } -static void shrinkwrap_evaluate (bConstraint *UNUSED(con), bConstraintOb *cob, ListBase *targets) +static void shrinkwrap_evaluate(bConstraint *UNUSED(con), bConstraintOb *cob, ListBase *targets) { - bConstraintTarget *ct= targets->first; + bConstraintTarget *ct = targets->first; /* only evaluate if there is a target */ if (VALID_CONS_TARGET(ct)) { @@ -3547,7 +3512,6 @@ static bConstraintTypeInfo CTI_SHRINKWRAP = { "Shrinkwrap", /* name */ "bShrinkwrapConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ shrinkwrap_id_looper, /* id looper */ NULL, /* copy data */ NULL, /* new data */ @@ -3559,25 +3523,25 @@ static bConstraintTypeInfo CTI_SHRINKWRAP = { /* --------- Damped Track ---------- */ -static void damptrack_new_data (void *cdata) +static void damptrack_new_data(void *cdata) { - bDampTrackConstraint *data= (bDampTrackConstraint *)cdata; + bDampTrackConstraint *data = (bDampTrackConstraint *)cdata; data->trackflag = TRACK_Y; } -static void damptrack_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void damptrack_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bDampTrackConstraint *data= con->data; + bDampTrackConstraint *data = con->data; /* target only */ - func(con, (ID**)&data->tar, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); } -static int damptrack_get_tars (bConstraint *con, ListBase *list) +static int damptrack_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bDampTrackConstraint *data= con->data; + bDampTrackConstraint *data = con->data; bConstraintTarget *ct; /* the following macro is used for all standard single-target constraints */ @@ -3589,11 +3553,11 @@ static int damptrack_get_tars (bConstraint *con, ListBase *list) return 0; } -static void damptrack_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void damptrack_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bDampTrackConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bDampTrackConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy) @@ -3602,14 +3566,14 @@ static void damptrack_flush_tars (bConstraint *con, ListBase *list, short nocopy /* array of direction vectors for the tracking flags */ static const float track_dir_vecs[6][3] = { - {+1, 0, 0}, {0, +1, 0}, {0, 0, +1}, /* TRACK_X, TRACK_Y, TRACK_Z */ - {-1, 0, 0}, {0, -1, 0}, {0, 0, -1} /* TRACK_NX, TRACK_NY, TRACK_NZ */ + {+1, 0, 0}, {0, +1, 0}, {0, 0, +1}, /* TRACK_X, TRACK_Y, TRACK_Z */ + {-1, 0, 0}, {0, -1, 0}, {0, 0, -1} /* TRACK_NX, TRACK_NY, TRACK_NZ */ }; -static void damptrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) +static void damptrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets) { - bDampTrackConstraint *data= con->data; - bConstraintTarget *ct= targets->first; + bDampTrackConstraint *data = con->data; + bConstraintTarget *ct = targets->first; if (VALID_CONS_TARGET(ct)) { float obvec[3], tarvec[3], obloc[3]; @@ -3650,8 +3614,8 @@ static void damptrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * */ cross_v3_v3v3(raxis, obvec, tarvec); - rangle= dot_v3v3(obvec, tarvec); - rangle= acos( MAX2(-1.0f, MIN2(1.0f, rangle)) ); + rangle = dot_v3v3(obvec, tarvec); + rangle = acos(MAX2(-1.0f, MIN2(1.0f, rangle)) ); /* construct rotation matrix from the axis-angle rotation found above * - this call takes care to make sure that the axis provided is a unit vector first @@ -3675,7 +3639,6 @@ static bConstraintTypeInfo CTI_DAMPTRACK = { "Damped Track", /* name */ "bDampTrackConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ damptrack_id_looper, /* id looper */ NULL, /* copy data */ damptrack_new_data, /* new data */ @@ -3687,43 +3650,43 @@ static bConstraintTypeInfo CTI_DAMPTRACK = { /* ----------- Spline IK ------------ */ -static void splineik_free (bConstraint *con) +static void splineik_free(bConstraint *con) { - bSplineIKConstraint *data= con->data; + bSplineIKConstraint *data = con->data; /* binding array */ if (data->points) MEM_freeN(data->points); } -static void splineik_copy (bConstraint *con, bConstraint *srccon) +static void splineik_copy(bConstraint *con, bConstraint *srccon) { - bSplineIKConstraint *src= srccon->data; - bSplineIKConstraint *dst= con->data; + bSplineIKConstraint *src = srccon->data; + bSplineIKConstraint *dst = con->data; /* copy the binding array */ - dst->points= MEM_dupallocN(src->points); + dst->points = MEM_dupallocN(src->points); } -static void splineik_new_data (void *cdata) +static void splineik_new_data(void *cdata) { - bSplineIKConstraint *data= (bSplineIKConstraint *)cdata; + bSplineIKConstraint *data = (bSplineIKConstraint *)cdata; - data->chainlen= 1; + data->chainlen = 1; } -static void splineik_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void splineik_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bSplineIKConstraint *data= con->data; + bSplineIKConstraint *data = con->data; /* target only */ - func(con, (ID**)&data->tar, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); } -static int splineik_get_tars (bConstraint *con, ListBase *list) +static int splineik_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bSplineIKConstraint *data= con->data; + bSplineIKConstraint *data = con->data; bConstraintTarget *ct; /* standard target-getting macro for single-target constraints without subtargets */ @@ -3735,29 +3698,29 @@ static int splineik_get_tars (bConstraint *con, ListBase *list) return 0; } -static void splineik_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void splineik_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bSplineIKConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bSplineIKConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGETNS_FLUSH_TARS(con, data->tar, ct, list, nocopy) } } -static void splineik_get_tarmat (bConstraint *UNUSED(con), bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) +static void splineik_get_tarmat(bConstraint *UNUSED(con), bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) { if (VALID_CONS_TARGET(ct)) { - Curve *cu= ct->tar->data; + Curve *cu = ct->tar->data; /* note: when creating constraints that follow path, the curve gets the CU_PATH set now, * currently for paths to work it needs to go through the bevlist/displist system (ton) */ /* only happens on reload file, but violates depsgraph still... fix! */ - if (cu->path==NULL || cu->path->data==NULL) - makeDispListCurveTypes(cob->scene, ct->tar, 0); + if (cu->path == NULL || cu->path->data == NULL) + BKE_displist_make_curveTypes(cob->scene, ct->tar, 0); } /* technically, this isn't really needed for evaluation, but we don't know what else @@ -3773,7 +3736,6 @@ static bConstraintTypeInfo CTI_SPLINEIK = { "Spline IK", /* name */ "bSplineIKConstraint", /* struct name */ splineik_free, /* free data */ - NULL, /* relink data */ splineik_id_looper, /* id looper */ splineik_copy, /* copy data */ splineik_new_data, /* new data */ @@ -3785,18 +3747,18 @@ static bConstraintTypeInfo CTI_SPLINEIK = { /* ----------- Pivot ------------- */ -static void pivotcon_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void pivotcon_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bPivotConstraint *data= con->data; + bPivotConstraint *data = con->data; /* target only */ - func(con, (ID**)&data->tar, userdata); + func(con, (ID **)&data->tar, FALSE, userdata); } -static int pivotcon_get_tars (bConstraint *con, ListBase *list) +static int pivotcon_get_tars(bConstraint *con, ListBase *list) { if (con && list) { - bPivotConstraint *data= con->data; + bPivotConstraint *data = con->data; bConstraintTarget *ct; /* standard target-getting macro for single-target constraints */ @@ -3808,21 +3770,21 @@ static int pivotcon_get_tars (bConstraint *con, ListBase *list) return 0; } -static void pivotcon_flush_tars (bConstraint *con, ListBase *list, short nocopy) +static void pivotcon_flush_tars(bConstraint *con, ListBase *list, short nocopy) { if (con && list) { - bPivotConstraint *data= con->data; - bConstraintTarget *ct= list->first; + bPivotConstraint *data = con->data; + bConstraintTarget *ct = list->first; /* the following macro is used for all standard single-target constraints */ SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy) } } -static void pivotcon_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) +static void pivotcon_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets) { - bPivotConstraint *data= con->data; - bConstraintTarget *ct= targets->first; + bPivotConstraint *data = con->data; + bConstraintTarget *ct = targets->first; float pivot[3], vec[3]; float rotMat[3][3]; @@ -3883,11 +3845,11 @@ static void pivotcon_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *t } /* perform the pivoting... */ - /* 1. take the vector from owner to the pivot */ + /* 1. take the vector from owner to the pivot */ sub_v3_v3v3(vec, cob->matrix[3], pivot); - /* 2. rotate this vector by the rotation of the object... */ + /* 2. rotate this vector by the rotation of the object... */ mul_m3_v3(rotMat, vec); - /* 3. make the rotation in terms of the pivot now */ + /* 3. make the rotation in terms of the pivot now */ add_v3_v3v3(cob->matrix[3], pivot, vec); } @@ -3898,7 +3860,6 @@ static bConstraintTypeInfo CTI_PIVOT = { "Pivot", /* name */ "bPivotConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ pivotcon_id_looper, /* id looper */ NULL, /* copy data */ NULL, /* new data */ // XXX: might be needed to get 'normal' pivot behavior... @@ -3922,9 +3883,9 @@ static void followtrack_id_looper(bConstraint *con, ConstraintIDFunc func, void { bFollowTrackConstraint *data = con->data; - func(con, (ID**)&data->clip, userdata); - func(con, (ID**)&data->camera, userdata); - func(con, (ID**)&data->depth_ob, userdata); + func(con, (ID **)&data->clip, TRUE, userdata); + func(con, (ID **)&data->camera, FALSE, userdata); + func(con, (ID **)&data->depth_ob, FALSE, userdata); } static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) @@ -3935,10 +3896,10 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase MovieTracking *tracking; MovieTrackingTrack *track; MovieTrackingObject *tracking_object; - Object *camob= data->camera ? data->camera : scene->camera; + Object *camob = data->camera ? data->camera : scene->camera; if (data->flag & FOLLOWTRACK_ACTIVECLIP) - clip= scene->clip; + clip = scene->clip; if (!clip || !data->track[0] || !camob) return; @@ -3964,7 +3925,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase copy_m4_m4(obmat, cob->matrix); - if ((tracking_object->flag & TRACKING_OBJECT_CAMERA)==0) { + if ((tracking_object->flag & TRACKING_OBJECT_CAMERA) == 0) { float imat[4][4]; copy_m4_m4(mat, camob->obmat); @@ -3986,10 +3947,10 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase else { MovieTrackingMarker *marker; float vec[3], disp[3], axis[3], mat[4][4]; - float aspect= (scene->r.xsch * scene->r.xasp) / (scene->r.ysch * scene->r.yasp); + float aspect = (scene->r.xsch * scene->r.xasp) / (scene->r.ysch * scene->r.yasp); float len, d; - where_is_object_mat(scene, camob, mat); + BKE_object_where_is_calc_mat4(scene, camob, mat); /* camera axis */ vec[0] = 0.0f; @@ -4034,7 +3995,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase copy_v3_v3(cob->matrix[3], disp); } else { - d= (len * params.sensor_x) / (2.0f * params.lens); + d = (len * params.sensor_x) / (2.0f * params.lens); vec[0] = d * (2.0f * (pos[0] + params.shiftx) - 1.0f); vec[1] = d * (2.0f * (pos[1] + params.shifty) - 1.0f); @@ -4092,7 +4053,6 @@ static bConstraintTypeInfo CTI_FOLLOWTRACK = { "Follow Track", /* name */ "bFollowTrackConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ followtrack_id_looper, /* id looper */ NULL, /* copy data */ followtrack_new_data, /* new data */ @@ -4116,7 +4076,7 @@ static void camerasolver_id_looper(bConstraint *con, ConstraintIDFunc func, void { bCameraSolverConstraint *data = con->data; - func(con, (ID**)&data->clip, userdata); + func(con, (ID **)&data->clip, TRUE, userdata); } static void camerasolver_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) @@ -4147,7 +4107,6 @@ static bConstraintTypeInfo CTI_CAMERASOLVER = { "Camera Solver", /* name */ "bCameraSolverConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ camerasolver_id_looper, /* id looper */ NULL, /* copy data */ camerasolver_new_data, /* new data */ @@ -4170,10 +4129,10 @@ static void objectsolver_new_data(void *cdata) static void objectsolver_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bObjectSolverConstraint *data= con->data; + bObjectSolverConstraint *data = con->data; - func(con, (ID**)&data->clip, userdata); - func(con, (ID**)&data->camera, userdata); + func(con, (ID **)&data->clip, FALSE, userdata); + func(con, (ID **)&data->camera, FALSE, userdata); } static void objectsolver_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) @@ -4184,7 +4143,7 @@ static void objectsolver_evaluate(bConstraint *con, bConstraintOb *cob, ListBase Object *camob = data->camera ? data->camera : scene->camera; if (data->flag & OBJECTSOLVER_ACTIVECLIP) - clip= scene->clip; + clip = scene->clip; if (!camob || !clip) return; @@ -4198,7 +4157,7 @@ static void objectsolver_evaluate(bConstraint *con, bConstraintOb *cob, ListBase if (object) { float mat[4][4], obmat[4][4], imat[4][4], cammat[4][4], camimat[4][4], parmat[4][4]; - where_is_object_mat(scene, camob, cammat); + BKE_object_where_is_calc_mat4(scene, camob, cammat); BKE_tracking_get_interpolated_camera(tracking, object, scene->r.cfra, mat); @@ -4221,7 +4180,6 @@ static bConstraintTypeInfo CTI_OBJECTSOLVER = { "Object Solver", /* name */ "bObjectSolverConstraint", /* struct name */ NULL, /* free data */ - NULL, /* relink data */ objectsolver_id_looper, /* id looper */ NULL, /* copy data */ objectsolver_new_data, /* new data */ @@ -4238,46 +4196,46 @@ static bConstraintTypeInfo CTI_OBJECTSOLVER = { /* These globals only ever get directly accessed in this file */ static bConstraintTypeInfo *constraintsTypeInfo[NUM_CONSTRAINT_TYPES]; -static short CTI_INIT= 1; /* when non-zero, the list needs to be updated */ +static short CTI_INIT = 1; /* when non-zero, the list needs to be updated */ /* This function only gets called when CTI_INIT is non-zero */ -static void constraints_init_typeinfo (void) -{ - constraintsTypeInfo[0]= NULL; /* 'Null' Constraint */ - constraintsTypeInfo[1]= &CTI_CHILDOF; /* ChildOf Constraint */ - constraintsTypeInfo[2]= &CTI_TRACKTO; /* TrackTo Constraint */ - constraintsTypeInfo[3]= &CTI_KINEMATIC; /* IK Constraint */ - constraintsTypeInfo[4]= &CTI_FOLLOWPATH; /* Follow-Path Constraint */ - constraintsTypeInfo[5]= &CTI_ROTLIMIT; /* Limit Rotation Constraint */ - constraintsTypeInfo[6]= &CTI_LOCLIMIT; /* Limit Location Constraint */ - constraintsTypeInfo[7]= &CTI_SIZELIMIT; /* Limit Scaling Constraint */ - constraintsTypeInfo[8]= &CTI_ROTLIKE; /* Copy Rotation Constraint */ - constraintsTypeInfo[9]= &CTI_LOCLIKE; /* Copy Location Constraint */ - constraintsTypeInfo[10]= &CTI_SIZELIKE; /* Copy Scaling Constraint */ - constraintsTypeInfo[11]= &CTI_PYTHON; /* Python/Script Constraint */ - constraintsTypeInfo[12]= &CTI_ACTION; /* Action Constraint */ - constraintsTypeInfo[13]= &CTI_LOCKTRACK; /* Locked-Track Constraint */ - constraintsTypeInfo[14]= &CTI_DISTLIMIT; /* Limit Distance Constraint */ - constraintsTypeInfo[15]= &CTI_STRETCHTO; /* StretchTo Constaint */ - constraintsTypeInfo[16]= &CTI_MINMAX; /* Floor Constraint */ - constraintsTypeInfo[17]= &CTI_RIGIDBODYJOINT; /* RigidBody Constraint */ - constraintsTypeInfo[18]= &CTI_CLAMPTO; /* ClampTo Constraint */ - constraintsTypeInfo[19]= &CTI_TRANSFORM; /* Transformation Constraint */ - constraintsTypeInfo[20]= &CTI_SHRINKWRAP; /* Shrinkwrap Constraint */ - constraintsTypeInfo[21]= &CTI_DAMPTRACK; /* Damped TrackTo Constraint */ - constraintsTypeInfo[22]= &CTI_SPLINEIK; /* Spline IK Constraint */ - constraintsTypeInfo[23]= &CTI_TRANSLIKE; /* Copy Transforms Constraint */ - constraintsTypeInfo[24]= &CTI_SAMEVOL; /* Maintain Volume Constraint */ - constraintsTypeInfo[25]= &CTI_PIVOT; /* Pivot Constraint */ - constraintsTypeInfo[26]= &CTI_FOLLOWTRACK; /* Follow Track Constraint */ - constraintsTypeInfo[27]= &CTI_CAMERASOLVER; /* Camera Solver Constraint */ - constraintsTypeInfo[28]= &CTI_OBJECTSOLVER; /* Object Solver Constraint */ +static void constraints_init_typeinfo(void) +{ + constraintsTypeInfo[0] = NULL; /* 'Null' Constraint */ + constraintsTypeInfo[1] = &CTI_CHILDOF; /* ChildOf Constraint */ + constraintsTypeInfo[2] = &CTI_TRACKTO; /* TrackTo Constraint */ + constraintsTypeInfo[3] = &CTI_KINEMATIC; /* IK Constraint */ + constraintsTypeInfo[4] = &CTI_FOLLOWPATH; /* Follow-Path Constraint */ + constraintsTypeInfo[5] = &CTI_ROTLIMIT; /* Limit Rotation Constraint */ + constraintsTypeInfo[6] = &CTI_LOCLIMIT; /* Limit Location Constraint */ + constraintsTypeInfo[7] = &CTI_SIZELIMIT; /* Limit Scaling Constraint */ + constraintsTypeInfo[8] = &CTI_ROTLIKE; /* Copy Rotation Constraint */ + constraintsTypeInfo[9] = &CTI_LOCLIKE; /* Copy Location Constraint */ + constraintsTypeInfo[10] = &CTI_SIZELIKE; /* Copy Scaling Constraint */ + constraintsTypeInfo[11] = &CTI_PYTHON; /* Python/Script Constraint */ + constraintsTypeInfo[12] = &CTI_ACTION; /* Action Constraint */ + constraintsTypeInfo[13] = &CTI_LOCKTRACK; /* Locked-Track Constraint */ + constraintsTypeInfo[14] = &CTI_DISTLIMIT; /* Limit Distance Constraint */ + constraintsTypeInfo[15] = &CTI_STRETCHTO; /* StretchTo Constaint */ + constraintsTypeInfo[16] = &CTI_MINMAX; /* Floor Constraint */ + constraintsTypeInfo[17] = &CTI_RIGIDBODYJOINT; /* RigidBody Constraint */ + constraintsTypeInfo[18] = &CTI_CLAMPTO; /* ClampTo Constraint */ + constraintsTypeInfo[19] = &CTI_TRANSFORM; /* Transformation Constraint */ + constraintsTypeInfo[20] = &CTI_SHRINKWRAP; /* Shrinkwrap Constraint */ + constraintsTypeInfo[21] = &CTI_DAMPTRACK; /* Damped TrackTo Constraint */ + constraintsTypeInfo[22] = &CTI_SPLINEIK; /* Spline IK Constraint */ + constraintsTypeInfo[23] = &CTI_TRANSLIKE; /* Copy Transforms Constraint */ + constraintsTypeInfo[24] = &CTI_SAMEVOL; /* Maintain Volume Constraint */ + constraintsTypeInfo[25] = &CTI_PIVOT; /* Pivot Constraint */ + constraintsTypeInfo[26] = &CTI_FOLLOWTRACK; /* Follow Track Constraint */ + constraintsTypeInfo[27] = &CTI_CAMERASOLVER; /* Camera Solver Constraint */ + constraintsTypeInfo[28] = &CTI_OBJECTSOLVER; /* Object Solver Constraint */ } /* This function should be used for getting the appropriate type-info when only * a constraint type is known */ -bConstraintTypeInfo *get_constraint_typeinfo (int type) +bConstraintTypeInfo *get_constraint_typeinfo(int type) { /* initialize the type-info list? */ if (CTI_INIT) { @@ -4287,7 +4245,7 @@ bConstraintTypeInfo *get_constraint_typeinfo (int type) /* only return for valid types */ if ( (type >= CONSTRAINT_TYPE_NULL) && - (type < NUM_CONSTRAINT_TYPES ) ) + (type < NUM_CONSTRAINT_TYPES) ) { /* there shouldn't be any segfaults here... */ return constraintsTypeInfo[type]; @@ -4302,7 +4260,7 @@ bConstraintTypeInfo *get_constraint_typeinfo (int type) /* This function should always be used to get the appropriate type-info, as it * has checks which prevent segfaults in some weird cases. */ -bConstraintTypeInfo *constraint_get_typeinfo (bConstraint *con) +bConstraintTypeInfo *constraint_get_typeinfo(bConstraint *con) { /* only return typeinfo for valid constraints */ if (con) @@ -4318,17 +4276,31 @@ bConstraintTypeInfo *constraint_get_typeinfo (bConstraint *con) /* ---------- Data Management ------- */ +/* helper function for free_constraint_data() - unlinks references */ +static void con_unlink_refs_cb(bConstraint *UNUSED(con), ID **idpoin, short isReference, void *UNUSED(userData)) +{ + if (*idpoin && isReference) + id_us_min(*idpoin); +} + /* Free data of a specific constraint if it has any info. * be sure to run BIK_clear_data() when freeing an IK constraint, - * unless DAG_scene_sort is called. */ + * unless DAG_scene_sort is called. + */ void free_constraint_data(bConstraint *con) { if (con->data) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); - /* perform any special freeing constraint may have */ - if (cti && cti->free_data) - cti->free_data(con); + if (cti) { + /* perform any special freeing constraint may have */ + if (cti->free_data) + cti->free_data(con); + + /* unlink the referenced resources it uses */ + if (cti->id_looper) + cti->id_looper(con, con_unlink_refs_cb, NULL); + } /* free constraint data now */ MEM_freeN(con->data); @@ -4341,7 +4313,7 @@ void free_constraints(ListBase *list) bConstraint *con; /* Free constraint data and also any extra data */ - for (con= list->first; con; con= con->next) + for (con = list->first; con; con = con->next) free_constraint_data(con); /* Free the whole list */ @@ -4370,8 +4342,8 @@ void remove_constraints_type(ListBase *list, short type, short last_only) return; /* remove from the end of the list to make it faster to find the last instance */ - for (con= list->last; con; con= conp) { - conp= con->prev; + for (con = list->last; con; con = conp) { + conp = con->prev; if (con->type == type) { remove_constraint(list, con); @@ -4384,10 +4356,10 @@ void remove_constraints_type(ListBase *list, short type, short last_only) /* ......... */ /* Creates a new constraint, initializes its data, and returns it */ -static bConstraint *add_new_constraint_internal (const char *name, short type) +static bConstraint *add_new_constraint_internal(const char *name, short type) { - bConstraint *con= MEM_callocN(sizeof(bConstraint), "Constraint"); - bConstraintTypeInfo *cti= get_constraint_typeinfo(type); + bConstraint *con = MEM_callocN(sizeof(bConstraint), "Constraint"); + bConstraintTypeInfo *cti = get_constraint_typeinfo(type); const char *newName; /* Set up a generic constraint datablock */ @@ -4405,12 +4377,12 @@ static bConstraint *add_new_constraint_internal (const char *name, short type) cti->new_data(con->data); /* if no name is provided, use the type of the constraint as the name */ - newName= (name && name[0]) ? name : cti->name; + newName = (name && name[0]) ? name : cti->name; } else { /* if no name is provided, use the generic "Const" name */ // NOTE: any constraint type that gets here really shouldn't get added... - newName= (name && name[0]) ? name : "Const"; + newName = (name && name[0]) ? name : "Const"; } /* copy the name */ @@ -4421,13 +4393,13 @@ static bConstraint *add_new_constraint_internal (const char *name, short type) } /* if pchan is not NULL then assume we're adding a pose constraint */ -static bConstraint *add_new_constraint (Object *ob, bPoseChannel *pchan, const char *name, short type) +static bConstraint *add_new_constraint(Object *ob, bPoseChannel *pchan, const char *name, short type) { bConstraint *con; ListBase *list; /* add the constraint */ - con= add_new_constraint_internal(name, type); + con = add_new_constraint_internal(name, type); /* find the constraint stack - bone or object? */ list = (pchan) ? (&pchan->constraints) : (&ob->constraints); @@ -4462,7 +4434,7 @@ static bConstraint *add_new_constraint (Object *ob, bPoseChannel *pchan, const c con->flag |= CONSTRAINT_SPACEONCE; } } - break; + break; } return con; @@ -4471,7 +4443,7 @@ static bConstraint *add_new_constraint (Object *ob, bPoseChannel *pchan, const c /* ......... */ /* Add new constraint for the given bone */ -bConstraint *add_pose_constraint (Object *ob, bPoseChannel *pchan, const char *name, short type) +bConstraint *add_pose_constraint(Object *ob, bPoseChannel *pchan, const char *name, short type) { if (pchan == NULL) return NULL; @@ -4487,43 +4459,34 @@ bConstraint *add_ob_constraint(Object *ob, const char *name, short type) /* ......... */ +/* helper for relink_constraints() - call ID_NEW() on every ID reference the constraint has */ +static void con_relink_id_cb(bConstraint *UNUSED(con), ID **idpoin, short UNUSED(isReference), void *UNUSED(userdata)) +{ + /* ID_NEW() expects a struct with inline "id" member as first + * since we've got the actual ID block, let's just inline this + * code. + * + * See ID_NEW(a) in BKE_utildefines.h + */ + if ((*idpoin) && (*idpoin)->newid) + (*idpoin) = (void *)(*idpoin)->newid; +} + /* Reassign links that constraints have to other data (called during file loading?) */ void relink_constraints(ListBase *conlist) { - bConstraint *con; - bConstraintTarget *ct; - - for (con= conlist->first; con; con= con->next) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); - - if (cti) { - /* relink any targets */ - if (cti->get_constraint_targets) { - ListBase targets = {NULL, NULL}; - - cti->get_constraint_targets(con, &targets); - for (ct= targets.first; ct; ct= ct->next) { - ID_NEW(ct->tar); - } - - if (cti->flush_constraint_targets) - cti->flush_constraint_targets(con, &targets, 0); - } - - /* relink any other special data */ - if (cti->relink_data) - cti->relink_data(con); - } - } + /* just a wrapper around ID-loop for just calling ID_NEW() on all ID refs */ + id_loop_constraints(conlist, con_relink_id_cb, NULL); } + /* Run the given callback on all ID-blocks in list of constraints */ void id_loop_constraints(ListBase *conlist, ConstraintIDFunc func, void *userdata) { bConstraint *con; - for (con= conlist->first; con; con= con->next) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + for (con = conlist->first; con; con = con->next) { + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); if (cti) { if (cti->id_looper) @@ -4535,22 +4498,30 @@ void id_loop_constraints(ListBase *conlist, ConstraintIDFunc func, void *userdat /* ......... */ /* helper for copy_constraints(), to be used for making sure that ID's are valid */ -static void con_extern_cb(bConstraint *UNUSED(con), ID **idpoin, void *UNUSED(userData)) +static void con_extern_cb(bConstraint *UNUSED(con), ID **idpoin, short UNUSED(isReference), void *UNUSED(userData)) { if (*idpoin && (*idpoin)->lib) id_lib_extern(*idpoin); } +/* helper for copy_constraints(), to be used for making sure that usercounts of copied ID's are fixed up */ +static void con_fix_copied_refs_cb(bConstraint *UNUSED(con), ID **idpoin, short isReference, void *UNUSED(userData)) +{ + /* increment usercount if this is a reference type */ + if ((*idpoin) && (isReference)) + id_us_plus(*idpoin); +} + /* duplicate all of the constraints in a constraint stack */ void copy_constraints(ListBase *dst, const ListBase *src, int do_extern) { bConstraint *con, *srccon; - dst->first= dst->last= NULL; + dst->first = dst->last = NULL; BLI_duplicatelist(dst, src); - for (con=dst->first, srccon=src->first; con && srccon; srccon=srccon->next, con=con->next) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + for (con = dst->first, srccon = src->first; con && srccon; srccon = srccon->next, con = con->next) { + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); /* make a new copy of the constraint's data */ con->data = MEM_dupallocN(con->data); @@ -4560,6 +4531,10 @@ void copy_constraints(ListBase *dst, const ListBase *src, int do_extern) /* perform custom copying operations if needed */ if (cti->copy_data) cti->copy_data(con, srccon); + + /* fix usercounts for all referenced data in referenced data */ + if (cti->id_looper) + cti->id_looper(con, con_fix_copied_refs_cb, NULL); /* for proxies we don't want to make extern */ if (do_extern) { @@ -4579,13 +4554,13 @@ bConstraint *constraints_findByName(ListBase *list, const char *name) } /* finds the 'active' constraint in a constraint stack */ -bConstraint *constraints_get_active (ListBase *list) +bConstraint *constraints_get_active(ListBase *list) { bConstraint *con; /* search for the first constraint with the 'active' flag set */ if (list) { - for (con= list->first; con; con= con->next) { + for (con = list->first; con; con = con->next) { if (con->flag & CONSTRAINT_ACTIVE) return con; } @@ -4601,7 +4576,7 @@ void constraints_set_active(ListBase *list, bConstraint *con) bConstraint *c; if (list) { - for (c= list->first; c; c= c->next) { + for (c = list->first; c; c = c->next) { if (c == con) c->flag |= CONSTRAINT_ACTIVE; else @@ -4618,8 +4593,8 @@ void extract_proxylocal_constraints(ListBase *dst, ListBase *src) bConstraint *con, *next; /* for each tagged constraint, remove from src and move to dst */ - for (con= src->first; con; con= next) { - next= con->next; + for (con = src->first; con; con = next) { + next = con->next; /* check if tagged */ if (con->flag & CONSTRAINT_PROXY_LOCAL) { @@ -4635,7 +4610,7 @@ short proxylocked_constraints_owner(Object *ob, bPoseChannel *pchan) /* Currently, constraints can only be on object or bone level */ if (ob && ob->proxy) { if (ob->pose && pchan) { - bArmature *arm= ob->data; + bArmature *arm = ob->data; /* On bone-level, check if bone is on proxy-protected layer */ if ((pchan->bone) && (pchan->bone->layer & arm->layer_protected)) @@ -4661,21 +4636,21 @@ short proxylocked_constraints_owner(Object *ob, bPoseChannel *pchan) */ void get_constraint_target_matrix(struct Scene *scene, bConstraint *con, int n, short ownertype, void *ownerdata, float mat[][4], float ctime) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); ListBase targets = {NULL, NULL}; bConstraintOb *cob; bConstraintTarget *ct; if (cti && cti->get_constraint_targets) { /* make 'constraint-ob' */ - cob= MEM_callocN(sizeof(bConstraintOb), "tempConstraintOb"); - cob->type= ownertype; + cob = MEM_callocN(sizeof(bConstraintOb), "tempConstraintOb"); + cob->type = ownertype; cob->scene = scene; switch (ownertype) { case CONSTRAINT_OBTYPE_OBJECT: /* it is usually this case */ { - cob->ob= (Object *)ownerdata; - cob->pchan= NULL; + cob->ob = (Object *)ownerdata; + cob->pchan = NULL; if (cob->ob) { copy_m4_m4(cob->matrix, cob->ob->obmat); copy_m4_m4(cob->startmat, cob->matrix); @@ -4685,11 +4660,11 @@ void get_constraint_target_matrix(struct Scene *scene, bConstraint *con, int n, unit_m4(cob->startmat); } } - break; + break; case CONSTRAINT_OBTYPE_BONE: /* this may occur in some cases */ { - cob->ob= NULL; /* this might not work at all :/ */ - cob->pchan= (bPoseChannel *)ownerdata; + cob->ob = NULL; /* this might not work at all :/ */ + cob->pchan = (bPoseChannel *)ownerdata; if (cob->pchan) { copy_m4_m4(cob->matrix, cob->pchan->pose_mat); copy_m4_m4(cob->startmat, cob->matrix); @@ -4699,16 +4674,16 @@ void get_constraint_target_matrix(struct Scene *scene, bConstraint *con, int n, unit_m4(cob->startmat); } } - break; + break; } /* get targets - we only need the first one though (and there should only be one) */ cti->get_constraint_targets(con, &targets); /* only calculate the target matrix on the first target */ - ct= (bConstraintTarget *)targets.first; + ct = (bConstraintTarget *)targets.first; while (ct && n-- > 0) - ct= ct->next; + ct = ct->next; if (ct) { if (cti->get_target_matrix) @@ -4730,26 +4705,26 @@ void get_constraint_target_matrix(struct Scene *scene, bConstraint *con, int n, /* Get the list of targets required for solving a constraint */ void get_constraint_targets_for_solving(bConstraint *con, bConstraintOb *cob, ListBase *targets, float ctime) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); if (cti && cti->get_constraint_targets) { bConstraintTarget *ct; /* get targets - * - constraints should use ct->matrix, not directly accessing values + * - constraints should use ct->matrix, not directly accessing values * - ct->matrix members have not yet been calculated here! */ cti->get_constraint_targets(con, targets); /* set matrices - * - calculate if possible, otherwise just initialize as identity matrix + * - calculate if possible, otherwise just initialize as identity matrix */ if (cti->get_target_matrix) { - for (ct= targets->first; ct; ct= ct->next) + for (ct = targets->first; ct; ct = ct->next) cti->get_target_matrix(con, cob, ct, ctime); } else { - for (ct= targets->first; ct; ct= ct->next) + for (ct = targets->first; ct; ct = ct->next) unit_m4(ct->matrix); } } @@ -4774,20 +4749,20 @@ void solve_constraints(ListBase *conlist, bConstraintOb *cob, float ctime) return; /* loop over available constraints, solving and blending them */ - for (con= conlist->first; con; con= con->next) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + for (con = conlist->first; con; con = con->next) { + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); ListBase targets = {NULL, NULL}; /* these we can skip completely (invalid constraints...) */ if (cti == NULL) continue; - if (con->flag & (CONSTRAINT_DISABLE|CONSTRAINT_OFF)) continue; + if (con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)) continue; /* these constraints can't be evaluated anyway */ if (cti->evaluate_constraint == NULL) continue; /* influence == 0 should be ignored */ if (con->enforce == 0.0f) continue; /* influence of constraint - * - value should have been set from animation data already + * - value should have been set from animation data already */ enf = con->enforce; @@ -4816,9 +4791,9 @@ void solve_constraints(ListBase *conlist, bConstraintOb *cob, float ctime) 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 + * - 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.0f) { diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index bd47e7cbd37..d736309f605 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -92,14 +92,14 @@ bContext *CTX_create(void) { bContext *C; - C= MEM_callocN(sizeof(bContext), "bContext"); + C = MEM_callocN(sizeof(bContext), "bContext"); return C; } bContext *CTX_copy(const bContext *C) { - bContext *newC= MEM_dupallocN((void*)C); + bContext *newC = MEM_dupallocN((void *)C); return newC; } @@ -118,23 +118,23 @@ bContextStore *CTX_store_add(ListBase *contexts, const char *name, PointerRNA *p /* ensure we have a context to put the entry in, if it was already used * we have to copy the context to ensure */ - ctx= contexts->last; + ctx = contexts->last; if (!ctx || ctx->used) { if (ctx) { - lastctx= ctx; - ctx= MEM_dupallocN(lastctx); + lastctx = ctx; + ctx = MEM_dupallocN(lastctx); BLI_duplicatelist(&ctx->entries, &lastctx->entries); } else - ctx= MEM_callocN(sizeof(bContextStore), "bContextStore"); + ctx = MEM_callocN(sizeof(bContextStore), "bContextStore"); BLI_addtail(contexts, ctx); } - entry= MEM_callocN(sizeof(bContextStoreEntry), "bContextStoreEntry"); + entry = MEM_callocN(sizeof(bContextStoreEntry), "bContextStoreEntry"); BLI_strncpy(entry->name, name, sizeof(entry->name)); - entry->ptr= *ptr; + entry->ptr = *ptr; BLI_addtail(&ctx->entries, entry); @@ -148,22 +148,22 @@ bContextStore *CTX_store_add_all(ListBase *contexts, bContextStore *context) /* ensure we have a context to put the entries in, if it was already used * we have to copy the context to ensure */ - ctx= contexts->last; + ctx = contexts->last; if (!ctx || ctx->used) { if (ctx) { - lastctx= ctx; - ctx= MEM_dupallocN(lastctx); + lastctx = ctx; + ctx = MEM_dupallocN(lastctx); BLI_duplicatelist(&ctx->entries, &lastctx->entries); } else - ctx= MEM_callocN(sizeof(bContextStore), "bContextStore"); + ctx = MEM_callocN(sizeof(bContextStore), "bContextStore"); BLI_addtail(contexts, ctx); } - for (tentry= context->entries.first; tentry; tentry= tentry->next) { - entry= MEM_dupallocN(tentry); + for (tentry = context->entries.first; tentry; tentry = tentry->next) { + entry = MEM_dupallocN(tentry); BLI_addtail(&ctx->entries, entry); } @@ -172,14 +172,14 @@ bContextStore *CTX_store_add_all(ListBase *contexts, bContextStore *context) void CTX_store_set(bContext *C, bContextStore *store) { - C->wm.store= store; + C->wm.store = store; } bContextStore *CTX_store_copy(bContextStore *store) { bContextStore *ctx; - ctx= MEM_dupallocN(store); + ctx = MEM_dupallocN(store); BLI_duplicatelist(&ctx->entries, &store->entries); return ctx; @@ -195,7 +195,7 @@ void CTX_store_free_list(ListBase *contexts) { bContextStore *ctx; - while ((ctx= contexts->first)) { + while ((ctx = contexts->first)) { BLI_remlink(contexts, ctx); CTX_store_free(ctx); } @@ -209,7 +209,7 @@ int CTX_py_init_get(bContext *C) } void CTX_py_init_set(bContext *C, int value) { - C->data.py_init= value; + C->data.py_init = value; } void *CTX_py_dict_get(const bContext *C) @@ -218,7 +218,7 @@ void *CTX_py_dict_get(const bContext *C) } void CTX_py_dict_set(bContext *C, void *value) { - C->data.py_context= value; + C->data.py_context = value; } /* data context utility functions */ @@ -237,8 +237,8 @@ static void *ctx_wm_python_context_get(const bContext *C, const char *member, vo if (C && CTX_py_dict_get(C)) { memset(&result, 0, sizeof(bContextDataResult)); - BPY_context_member_get((bContext*)C, member, &result); - if(result.ptr.data) + BPY_context_member_get((bContext *)C, member, &result); + if (result.ptr.data) return result.ptr.data; } #endif @@ -251,8 +251,8 @@ static int ctx_data_get(bContext *C, const char *member, bContextDataResult *res bScreen *sc; ScrArea *sa; ARegion *ar; - int done= 0, recursion= C->data.recursion; - int ret= 0; + int done = 0, recursion = C->data.recursion; + int ret = 0; memset(result, 0, sizeof(bContextDataResult)); #ifdef WITH_PYTHON @@ -271,42 +271,42 @@ static int ctx_data_get(bContext *C, const char *member, bContextDataResult *res * Values in order of importance * (0, -1, 1) - Where 1 is highest priority * */ - if (done!=1 && recursion < 1 && C->wm.store) { + if (done != 1 && recursion < 1 && C->wm.store) { bContextStoreEntry *entry; - C->data.recursion= 1; + C->data.recursion = 1; - entry= BLI_rfindstring(&C->wm.store->entries, member, offsetof(bContextStoreEntry, name)); + entry = BLI_rfindstring(&C->wm.store->entries, member, offsetof(bContextStoreEntry, name)); if (entry) { - result->ptr= entry->ptr; - done= 1; + result->ptr = entry->ptr; + done = 1; } } - if (done!=1 && recursion < 2 && (ar=CTX_wm_region(C))) { - C->data.recursion= 2; + if (done != 1 && recursion < 2 && (ar = CTX_wm_region(C))) { + C->data.recursion = 2; if (ar->type && ar->type->context) { ret = ar->type->context(C, member, result); - if (ret) done= -(-ret | -done); + if (ret) done = -(-ret | -done); } } - if (done!=1 && recursion < 3 && (sa=CTX_wm_area(C))) { - C->data.recursion= 3; + if (done != 1 && recursion < 3 && (sa = CTX_wm_area(C))) { + C->data.recursion = 3; if (sa->type && sa->type->context) { ret = sa->type->context(C, member, result); - if (ret) done= -(-ret | -done); + if (ret) done = -(-ret | -done); } } - if (done!=1 && recursion < 4 && (sc=CTX_wm_screen(C))) { - bContextDataCallback cb= sc->context; - C->data.recursion= 4; + if (done != 1 && recursion < 4 && (sc = CTX_wm_screen(C))) { + bContextDataCallback cb = sc->context; + C->data.recursion = 4; if (cb) { ret = cb(C, member, result); - if (ret) done= -(-ret | -done); + if (ret) done = -(-ret | -done); } } - C->data.recursion= recursion; + C->data.recursion = recursion; return done; } @@ -315,7 +315,7 @@ static void *ctx_data_pointer_get(const bContext *C, const char *member) { bContextDataResult result; - if (C && ctx_data_get((bContext*)C, member, &result)==1) + if (C && ctx_data_get((bContext *)C, member, &result) == 1) return result.ptr.data; return NULL; @@ -327,15 +327,15 @@ static int ctx_data_pointer_verify(const bContext *C, const char *member, void * /* if context is NULL, pointer must be NULL too and that is a valid return */ if (C == NULL) { - *pointer= NULL; + *pointer = NULL; return 1; } - else if (ctx_data_get((bContext*)C, member, &result)==1) { - *pointer= result.ptr.data; + else if (ctx_data_get((bContext *)C, member, &result) == 1) { + *pointer = result.ptr.data; return 1; } else { - *pointer= NULL; + *pointer = NULL; return 0; } } @@ -344,13 +344,13 @@ static int ctx_data_collection_get(const bContext *C, const char *member, ListBa { bContextDataResult result; - if (ctx_data_get((bContext*)C, member, &result)==1) { - *list= result.list; + if (ctx_data_get((bContext *)C, member, &result) == 1) { + *list = result.list; return 1; } - list->first= NULL; - list->last= NULL; + list->first = NULL; + list->last = NULL; return 0; } @@ -359,7 +359,7 @@ PointerRNA CTX_data_pointer_get(const bContext *C, const char *member) { bContextDataResult result; - if (ctx_data_get((bContext*)C, member, &result)==1) + if (ctx_data_get((bContext *)C, member, &result) == 1) return result.ptr; else return PointerRNA_NULL; @@ -379,11 +379,11 @@ ListBase CTX_data_collection_get(const bContext *C, const char *member) { bContextDataResult result; - if (ctx_data_get((bContext*)C, member, &result)==1) { + if (ctx_data_get((bContext *)C, member, &result) == 1) { return result.list; } else { - ListBase list= {NULL, NULL}; + ListBase list = {NULL, NULL}; return list; } } @@ -392,17 +392,17 @@ ListBase CTX_data_collection_get(const bContext *C, const char *member) int CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, ListBase *r_lb, short *r_type) { bContextDataResult result; - int ret= ctx_data_get((bContext*)C, member, &result); + int ret = ctx_data_get((bContext *)C, member, &result); - if (ret==1) { - *r_ptr= result.ptr; - *r_lb= result.list; - *r_type= result.type; + if (ret == 1) { + *r_ptr = result.ptr; + *r_lb = result.list; + *r_type = result.type; } else { memset(r_ptr, 0, sizeof(*r_ptr)); memset(r_lb, 0, sizeof(*r_lb)); - *r_type= 0; + *r_type = 0; } return ret; @@ -418,8 +418,8 @@ static void data_dir_add(ListBase *lb, const char *member) if (BLI_findstring(lb, member, offsetof(LinkData, data))) return; - link= MEM_callocN(sizeof(LinkData), "LinkData"); - link->data= (void*)member; + link = MEM_callocN(sizeof(LinkData), "LinkData"); + link->data = (void *)member; BLI_addtail(lb, link); } @@ -437,32 +437,32 @@ ListBase CTX_data_dir_get(const bContext *C) if (C->wm.store) { bContextStoreEntry *entry; - for (entry=C->wm.store->entries.first; entry; entry=entry->next) + for (entry = C->wm.store->entries.first; entry; entry = entry->next) data_dir_add(&lb, entry->name); } - if ((ar=CTX_wm_region(C)) && ar->type && ar->type->context) { + if ((ar = CTX_wm_region(C)) && ar->type && ar->type->context) { memset(&result, 0, sizeof(result)); ar->type->context(C, "", &result); if (result.dir) - for (a=0; result.dir[a]; a++) + for (a = 0; result.dir[a]; a++) data_dir_add(&lb, result.dir[a]); } - if ((sa=CTX_wm_area(C)) && sa->type && sa->type->context) { + if ((sa = CTX_wm_area(C)) && sa->type && sa->type->context) { memset(&result, 0, sizeof(result)); sa->type->context(C, "", &result); if (result.dir) - for (a=0; result.dir[a]; a++) + for (a = 0; result.dir[a]; a++) data_dir_add(&lb, result.dir[a]); } - if ((sc=CTX_wm_screen(C)) && sc->context) { - bContextDataCallback cb= sc->context; + if ((sc = CTX_wm_screen(C)) && sc->context) { + bContextDataCallback cb = sc->context; memset(&result, 0, sizeof(result)); cb(C, "", &result); if (result.dir) - for (a=0; result.dir[a]; a++) + for (a = 0; result.dir[a]; a++) data_dir_add(&lb, result.dir[a]); } @@ -493,7 +493,7 @@ void CTX_data_id_list_add(bContextDataResult *result, ID *id) { CollectionPointerLink *link; - link= MEM_callocN(sizeof(CollectionPointerLink), "CTX_data_id_list_add"); + link = MEM_callocN(sizeof(CollectionPointerLink), "CTX_data_id_list_add"); RNA_id_pointer_create(id, &link->ptr); BLI_addtail(&result->list, link); @@ -503,18 +503,18 @@ void CTX_data_list_add(bContextDataResult *result, ID *id, StructRNA *type, void { CollectionPointerLink *link; - link= MEM_callocN(sizeof(CollectionPointerLink), "CTX_data_list_add"); + link = MEM_callocN(sizeof(CollectionPointerLink), "CTX_data_list_add"); RNA_pointer_create(id, type, data, &link->ptr); BLI_addtail(&result->list, link); } -int ctx_data_list_count(const bContext *C, int (*func)(const bContext*, ListBase*)) +int ctx_data_list_count(const bContext *C, int (*func)(const bContext *, ListBase *)) { ListBase list; if (func(C, &list)) { - int tot= BLI_countlist(&list); + int tot = BLI_countlist(&list); BLI_freelistN(&list); return tot; } @@ -524,12 +524,12 @@ int ctx_data_list_count(const bContext *C, int (*func)(const bContext*, ListBase void CTX_data_dir_set(bContextDataResult *result, const char **dir) { - result->dir= dir; + result->dir = dir; } void CTX_data_type_set(bContextDataResult *result, short type) { - result->type= type; + result->type = type; } short CTX_data_type_get(bContextDataResult *result) @@ -564,7 +564,7 @@ ScrArea *CTX_wm_area(const bContext *C) SpaceLink *CTX_wm_space_data(const bContext *C) { ScrArea *sa = CTX_wm_area(C); - return (sa)? sa->spacedata.first: NULL; + return (sa) ? sa->spacedata.first : NULL; } ARegion *CTX_wm_region(const bContext *C) @@ -575,7 +575,7 @@ ARegion *CTX_wm_region(const bContext *C) void *CTX_wm_region_data(const bContext *C) { ARegion *ar = CTX_wm_region(C); - return (ar)? ar->regiondata: NULL; + return (ar) ? ar->regiondata : NULL; } struct ARegion *CTX_wm_menu(const bContext *C) @@ -594,7 +594,7 @@ struct ReportList *CTX_wm_reports(const bContext *C) View3D *CTX_wm_view3d(const bContext *C) { ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype==SPACE_VIEW3D) + if (sa && sa->spacetype == SPACE_VIEW3D) return sa->spacedata.first; return NULL; } @@ -604,7 +604,7 @@ RegionView3D *CTX_wm_region_view3d(const bContext *C) ScrArea *sa = CTX_wm_area(C); ARegion *ar = CTX_wm_region(C); - if (sa && sa->spacetype==SPACE_VIEW3D) + if (sa && sa->spacetype == SPACE_VIEW3D) if (ar) return ar->regiondata; return NULL; @@ -613,7 +613,7 @@ RegionView3D *CTX_wm_region_view3d(const bContext *C) struct SpaceText *CTX_wm_space_text(const bContext *C) { ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype==SPACE_TEXT) + if (sa && sa->spacetype == SPACE_TEXT) return sa->spacedata.first; return NULL; } @@ -621,7 +621,7 @@ struct SpaceText *CTX_wm_space_text(const bContext *C) struct SpaceConsole *CTX_wm_space_console(const bContext *C) { ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype==SPACE_CONSOLE) + if (sa && sa->spacetype == SPACE_CONSOLE) return sa->spacedata.first; return NULL; } @@ -629,7 +629,7 @@ struct SpaceConsole *CTX_wm_space_console(const bContext *C) struct SpaceImage *CTX_wm_space_image(const bContext *C) { ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype==SPACE_IMAGE) + if (sa && sa->spacetype == SPACE_IMAGE) return sa->spacedata.first; return NULL; } @@ -637,7 +637,7 @@ struct SpaceImage *CTX_wm_space_image(const bContext *C) struct SpaceButs *CTX_wm_space_buts(const bContext *C) { ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype==SPACE_BUTS) + if (sa && sa->spacetype == SPACE_BUTS) return sa->spacedata.first; return NULL; } @@ -645,7 +645,7 @@ struct SpaceButs *CTX_wm_space_buts(const bContext *C) struct SpaceFile *CTX_wm_space_file(const bContext *C) { ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype==SPACE_FILE) + if (sa && sa->spacetype == SPACE_FILE) return sa->spacedata.first; return NULL; } @@ -653,7 +653,7 @@ struct SpaceFile *CTX_wm_space_file(const bContext *C) struct SpaceSeq *CTX_wm_space_seq(const bContext *C) { ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype==SPACE_SEQ) + if (sa && sa->spacetype == SPACE_SEQ) return sa->spacedata.first; return NULL; } @@ -661,7 +661,7 @@ struct SpaceSeq *CTX_wm_space_seq(const bContext *C) struct SpaceOops *CTX_wm_space_outliner(const bContext *C) { ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype==SPACE_OUTLINER) + if (sa && sa->spacetype == SPACE_OUTLINER) return sa->spacedata.first; return NULL; } @@ -669,7 +669,7 @@ struct SpaceOops *CTX_wm_space_outliner(const bContext *C) struct SpaceNla *CTX_wm_space_nla(const bContext *C) { ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype==SPACE_NLA) + if (sa && sa->spacetype == SPACE_NLA) return sa->spacedata.first; return NULL; } @@ -677,7 +677,7 @@ struct SpaceNla *CTX_wm_space_nla(const bContext *C) struct SpaceTime *CTX_wm_space_time(const bContext *C) { ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype==SPACE_TIME) + if (sa && sa->spacetype == SPACE_TIME) return sa->spacedata.first; return NULL; } @@ -685,7 +685,7 @@ struct SpaceTime *CTX_wm_space_time(const bContext *C) struct SpaceNode *CTX_wm_space_node(const bContext *C) { ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype==SPACE_NODE) + if (sa && sa->spacetype == SPACE_NODE) return sa->spacedata.first; return NULL; } @@ -693,7 +693,7 @@ struct SpaceNode *CTX_wm_space_node(const bContext *C) struct SpaceLogic *CTX_wm_space_logic(const bContext *C) { ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype==SPACE_LOGIC) + if (sa && sa->spacetype == SPACE_LOGIC) return sa->spacedata.first; return NULL; } @@ -701,7 +701,7 @@ struct SpaceLogic *CTX_wm_space_logic(const bContext *C) struct SpaceIpo *CTX_wm_space_graph(const bContext *C) { ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype==SPACE_IPO) + if (sa && sa->spacetype == SPACE_IPO) return sa->spacedata.first; return NULL; } @@ -709,7 +709,7 @@ struct SpaceIpo *CTX_wm_space_graph(const bContext *C) struct SpaceAction *CTX_wm_space_action(const bContext *C) { ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype==SPACE_ACTION) + if (sa && sa->spacetype == SPACE_ACTION) return sa->spacedata.first; return NULL; } @@ -717,7 +717,7 @@ struct SpaceAction *CTX_wm_space_action(const bContext *C) struct SpaceInfo *CTX_wm_space_info(const bContext *C) { ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype==SPACE_INFO) + if (sa && sa->spacetype == SPACE_INFO) return sa->spacedata.first; return NULL; } @@ -725,7 +725,7 @@ struct SpaceInfo *CTX_wm_space_info(const bContext *C) struct SpaceUserPref *CTX_wm_space_userpref(const bContext *C) { ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype==SPACE_USERPREF) + if (sa && sa->spacetype == SPACE_USERPREF) return sa->spacedata.first; return NULL; } @@ -733,58 +733,58 @@ struct SpaceUserPref *CTX_wm_space_userpref(const bContext *C) struct SpaceClip *CTX_wm_space_clip(const bContext *C) { ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype==SPACE_CLIP) + if (sa && sa->spacetype == SPACE_CLIP) return sa->spacedata.first; return NULL; } void CTX_wm_manager_set(bContext *C, wmWindowManager *wm) { - C->wm.manager= wm; - C->wm.window= NULL; - C->wm.screen= NULL; - C->wm.area= NULL; - C->wm.region= NULL; + C->wm.manager = wm; + C->wm.window = NULL; + C->wm.screen = NULL; + C->wm.area = NULL; + C->wm.region = NULL; } void CTX_wm_window_set(bContext *C, wmWindow *win) { - C->wm.window= win; - C->wm.screen= (win)? win->screen: NULL; + C->wm.window = win; + C->wm.screen = (win) ? win->screen : NULL; if (C->wm.screen) - C->data.scene= C->wm.screen->scene; - C->wm.area= NULL; - C->wm.region= NULL; + C->data.scene = C->wm.screen->scene; + C->wm.area = NULL; + C->wm.region = NULL; } void CTX_wm_screen_set(bContext *C, bScreen *screen) { - C->wm.screen= screen; + C->wm.screen = screen; if (C->wm.screen) - C->data.scene= C->wm.screen->scene; - C->wm.area= NULL; - C->wm.region= NULL; + C->data.scene = C->wm.screen->scene; + C->wm.area = NULL; + C->wm.region = NULL; } void CTX_wm_area_set(bContext *C, ScrArea *area) { - C->wm.area= area; - C->wm.region= NULL; + C->wm.area = area; + C->wm.region = NULL; } void CTX_wm_region_set(bContext *C, ARegion *region) { - C->wm.region= region; + C->wm.region = region; } void CTX_wm_menu_set(bContext *C, ARegion *menu) { - C->wm.menu= menu; + C->wm.menu = menu; } void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg) { - C->wm.operator_poll_msg= msg; + C->wm.operator_poll_msg = msg; } const char *CTX_wm_operator_poll_msg_get(bContext *C) @@ -798,7 +798,7 @@ Main *CTX_data_main(const bContext *C) { Main *bmain; - if (ctx_data_pointer_verify(C, "blend_data", (void*)&bmain)) + if (ctx_data_pointer_verify(C, "blend_data", (void *)&bmain)) return bmain; else return C->data.main; @@ -806,14 +806,14 @@ Main *CTX_data_main(const bContext *C) void CTX_data_main_set(bContext *C, Main *bmain) { - C->data.main= bmain; + C->data.main = bmain; } Scene *CTX_data_scene(const bContext *C) { Scene *scene; - if (ctx_data_pointer_verify(C, "scene", (void*)&scene)) + if (ctx_data_pointer_verify(C, "scene", (void *)&scene)) return scene; else return C->data.scene; @@ -821,7 +821,7 @@ Scene *CTX_data_scene(const bContext *C) int CTX_data_mode_enum(const bContext *C) { - Object *obedit= CTX_data_edit_object(C); + Object *obedit = CTX_data_edit_object(C); if (obedit) { switch (obedit->type) { @@ -846,7 +846,7 @@ int CTX_data_mode_enum(const bContext *C) if (ob) { if (ob->mode & OB_MODE_POSE) return CTX_MODE_POSE; - else if (ob->mode & OB_MODE_SCULPT) return CTX_MODE_SCULPT; + else if (ob->mode & OB_MODE_SCULPT) return CTX_MODE_SCULPT; else if (ob->mode & OB_MODE_WEIGHT_PAINT) return CTX_MODE_PAINT_WEIGHT; else if (ob->mode & OB_MODE_VERTEX_PAINT) return CTX_MODE_PAINT_VERTEX; else if (ob->mode & OB_MODE_TEXTURE_PAINT) return CTX_MODE_PAINT_TEXTURE; @@ -884,7 +884,7 @@ const char *CTX_data_mode_string(const bContext *C) void CTX_data_scene_set(bContext *C, Scene *scene) { - C->data.scene= scene; + C->data.scene = scene; } ToolSettings *CTX_data_tool_settings(const bContext *C) diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 85e3d85dfc4..43cc63aefa6 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -32,7 +32,7 @@ #include <math.h> // floor #include <string.h> -#include <stdlib.h> +#include <stdlib.h> #include "MEM_guardedalloc.h" @@ -42,24 +42,24 @@ #include "BLI_utildefines.h" #include "BLI_ghash.h" -#include "DNA_curve_types.h" -#include "DNA_material_types.h" +#include "DNA_curve_types.h" +#include "DNA_material_types.h" /* for dereferencing pointers */ -#include "DNA_key_types.h" -#include "DNA_scene_types.h" -#include "DNA_vfont_types.h" +#include "DNA_key_types.h" +#include "DNA_scene_types.h" +#include "DNA_vfont_types.h" #include "DNA_object_types.h" #include "BKE_animsys.h" -#include "BKE_anim.h" -#include "BKE_curve.h" -#include "BKE_displist.h" -#include "BKE_font.h" -#include "BKE_global.h" -#include "BKE_key.h" -#include "BKE_library.h" -#include "BKE_main.h" +#include "BKE_anim.h" +#include "BKE_curve.h" +#include "BKE_displist.h" +#include "BKE_font.h" +#include "BKE_global.h" +#include "BKE_key.h" +#include "BKE_library.h" +#include "BKE_main.h" #include "BKE_object.h" #include "BKE_material.h" @@ -73,42 +73,53 @@ static int cu_isectLL(const float v1[3], const float v2[3], const float v3[3], c void BKE_curve_unlink(Curve *cu) { int a; - - for (a=0; a<cu->totcol; a++) { + + for (a = 0; a < cu->totcol; a++) { if (cu->mat[a]) cu->mat[a]->id.us--; - cu->mat[a]= NULL; + cu->mat[a] = NULL; } - if (cu->vfont) cu->vfont->id.us--; - cu->vfont= NULL; + if (cu->vfont) + cu->vfont->id.us--; + cu->vfont = NULL; + + if (cu->vfontb) + cu->vfontb->id.us--; + cu->vfontb = NULL; - if (cu->vfontb) cu->vfontb->id.us--; - cu->vfontb= NULL; + if (cu->vfonti) + cu->vfonti->id.us--; + cu->vfonti = NULL; - if (cu->vfonti) cu->vfonti->id.us--; - cu->vfonti= NULL; + if (cu->vfontbi) + cu->vfontbi->id.us--; + cu->vfontbi = NULL; - if (cu->vfontbi) cu->vfontbi->id.us--; - cu->vfontbi= NULL; - - if (cu->key) cu->key->id.us--; - cu->key= NULL; + if (cu->key) + cu->key->id.us--; + cu->key = NULL; } /* frees editcurve entirely */ void BKE_curve_editfont_free(Curve *cu) { if (cu->editfont) { - EditFont *ef= cu->editfont; - - if (ef->oldstr) MEM_freeN(ef->oldstr); - if (ef->oldstrinfo) MEM_freeN(ef->oldstrinfo); - if (ef->textbuf) MEM_freeN(ef->textbuf); - if (ef->textbufinfo) MEM_freeN(ef->textbufinfo); - if (ef->copybuf) MEM_freeN(ef->copybuf); - if (ef->copybufinfo) MEM_freeN(ef->copybufinfo); - + EditFont *ef = cu->editfont; + + if (ef->oldstr) + MEM_freeN(ef->oldstr); + if (ef->oldstrinfo) + MEM_freeN(ef->oldstrinfo); + if (ef->textbuf) + MEM_freeN(ef->textbuf); + if (ef->textbufinfo) + MEM_freeN(ef->textbufinfo); + if (ef->copybuf) + MEM_freeN(ef->copybuf); + if (ef->copybufinfo) + MEM_freeN(ef->copybufinfo); + MEM_freeN(ef); - cu->editfont= NULL; + cu->editfont = NULL; } } @@ -118,7 +129,7 @@ void BKE_curve_editNurb_keyIndex_free(EditNurb *editnurb) return; } BLI_ghash_free(editnurb->keyindex, NULL, (GHashValFreeFP)MEM_freeN); - editnurb->keyindex= NULL; + editnurb->keyindex = NULL; } void BKE_curve_editNurb_free(Curve *cu) @@ -127,7 +138,7 @@ void BKE_curve_editNurb_free(Curve *cu) BKE_nurbList_free(&cu->editnurb->nurbs); BKE_curve_editNurb_keyIndex_free(cu->editnurb); MEM_freeN(cu->editnurb); - cu->editnurb= NULL; + cu->editnurb = NULL; } } @@ -136,56 +147,63 @@ void BKE_curve_free(Curve *cu) { BKE_nurbList_free(&cu->nurb); BLI_freelistN(&cu->bev); - freedisplist(&cu->disp); + BKE_displist_free(&cu->disp); BKE_curve_editfont_free(cu); BKE_curve_editNurb_free(cu); BKE_curve_unlink(cu); BKE_free_animdata((ID *)cu); - - if (cu->mat) MEM_freeN(cu->mat); - if (cu->str) MEM_freeN(cu->str); - if (cu->strinfo) MEM_freeN(cu->strinfo); - if (cu->bb) MEM_freeN(cu->bb); - if (cu->path) free_path(cu->path); - if (cu->tb) MEM_freeN(cu->tb); + + if (cu->mat) + MEM_freeN(cu->mat); + if (cu->str) + MEM_freeN(cu->str); + if (cu->strinfo) + MEM_freeN(cu->strinfo); + if (cu->bb) + MEM_freeN(cu->bb); + if (cu->path) + free_path(cu->path); + if (cu->tb) + MEM_freeN(cu->tb); } Curve *BKE_curve_add(const char *name, int type) { Curve *cu; - cu = alloc_libblock(&G.main->curve, ID_CU, name); + cu = BKE_libblock_alloc(&G.main->curve, ID_CU, name); copy_v3_fl(cu->size, 1.0f); - cu->flag= CU_FRONT|CU_BACK|CU_DEFORM_BOUNDS_OFF|CU_PATH_RADIUS; - cu->pathlen= 100; - cu->resolu= cu->resolv= (type == OB_SURF) ? 4 : 12; - cu->width= 1.0; + cu->flag = CU_FRONT | CU_BACK | CU_DEFORM_BOUNDS_OFF | CU_PATH_RADIUS; + cu->pathlen = 100; + cu->resolu = cu->resolv = (type == OB_SURF) ? 4 : 12; + cu->width = 1.0; cu->wordspace = 1.0; - cu->spacing= cu->linedist= 1.0; - cu->fsize= 1.0; - cu->ulheight = 0.05; - cu->texflag= CU_AUTOSPACE; - cu->smallcaps_scale= 0.75f; - cu->twist_mode= CU_TWIST_MINIMUM; // XXX: this one seems to be the best one in most cases, at least for curve deform... - cu->type= type; - cu->bevfac1= 0.0f; - cu->bevfac2= 1.0f; - - cu->bb= unit_boundbox(); - - if (type==OB_FONT) { - cu->vfont= cu->vfontb= cu->vfonti= cu->vfontbi= get_builtin_font(); - cu->vfont->id.us+=4; - cu->str= MEM_mallocN(12, "str"); + cu->spacing = cu->linedist = 1.0; + cu->fsize = 1.0; + cu->ulheight = 0.05; + cu->texflag = CU_AUTOSPACE; + cu->smallcaps_scale = 0.75f; + /* XXX: this one seems to be the best one in most cases, at least for curve deform... */ + cu->twist_mode = CU_TWIST_MINIMUM; + cu->type = type; + cu->bevfac1 = 0.0f; + cu->bevfac2 = 1.0f; + + cu->bb = BKE_boundbox_alloc_unit(); + + if (type == OB_FONT) { + cu->vfont = cu->vfontb = cu->vfonti = cu->vfontbi = BKE_vfont_builtin_get(); + cu->vfont->id.us += 4; + cu->str = MEM_mallocN(12, "str"); BLI_strncpy(cu->str, "Text", 12); - cu->len= cu->pos= 4; - cu->strinfo= MEM_callocN(12*sizeof(CharInfo), "strinfo new"); - cu->totbox= cu->actbox= 1; - cu->tb= MEM_callocN(MAXTEXTBOX*sizeof(TextBox), "textbox"); + cu->len = cu->pos = 4; + cu->strinfo = MEM_callocN(12 * sizeof(CharInfo), "strinfo new"); + cu->totbox = cu->actbox = 1; + cu->tb = MEM_callocN(MAXTEXTBOX * sizeof(TextBox), "textbox"); cu->tb[0].w = cu->tb[0].h = 0.0; } - + return cu; } @@ -193,52 +211,52 @@ Curve *BKE_curve_copy(Curve *cu) { Curve *cun; int a; - - cun= copy_libblock(&cu->id); - cun->nurb.first= cun->nurb.last= NULL; + + cun = BKE_libblock_copy(&cu->id); + cun->nurb.first = cun->nurb.last = NULL; BKE_nurbList_duplicate(&(cun->nurb), &(cu->nurb)); - cun->mat= MEM_dupallocN(cu->mat); - for (a=0; a<cun->totcol; a++) { + cun->mat = MEM_dupallocN(cu->mat); + for (a = 0; a < cun->totcol; a++) { id_us_plus((ID *)cun->mat[a]); } - - cun->str= MEM_dupallocN(cu->str); - cun->strinfo= MEM_dupallocN(cu->strinfo); - cun->tb= MEM_dupallocN(cu->tb); - cun->bb= MEM_dupallocN(cu->bb); - - cun->key= copy_key(cu->key); - if (cun->key) cun->key->from= (ID *)cun; - - cun->disp.first= cun->disp.last= NULL; - cun->bev.first= cun->bev.last= NULL; - cun->path= NULL; - - cun->editnurb= NULL; - cun->editfont= NULL; - cun->selboxes= NULL; - -#if 0 // XXX old animation system + + cun->str = MEM_dupallocN(cu->str); + cun->strinfo = MEM_dupallocN(cu->strinfo); + cun->tb = MEM_dupallocN(cu->tb); + cun->bb = MEM_dupallocN(cu->bb); + + cun->key = BKE_key_copy(cu->key); + if (cun->key) cun->key->from = (ID *)cun; + + cun->disp.first = cun->disp.last = NULL; + cun->bev.first = cun->bev.last = NULL; + cun->path = NULL; + + cun->editnurb = NULL; + cun->editfont = NULL; + cun->selboxes = NULL; + +#if 0 // XXX old animation system /* single user ipo too */ - if (cun->ipo) cun->ipo= copy_ipo(cun->ipo); + if (cun->ipo) cun->ipo = copy_ipo(cun->ipo); #endif // XXX old animation system id_us_plus((ID *)cun->vfont); - id_us_plus((ID *)cun->vfontb); + id_us_plus((ID *)cun->vfontb); id_us_plus((ID *)cun->vfonti); id_us_plus((ID *)cun->vfontbi); - + return cun; } static void extern_local_curve(Curve *cu) -{ +{ id_lib_extern((ID *)cu->vfont); - id_lib_extern((ID *)cu->vfontb); + id_lib_extern((ID *)cu->vfontb); id_lib_extern((ID *)cu->vfonti); id_lib_extern((ID *)cu->vfontbi); - + if (cu->mat) { extern_local_matarar(cu->mat, cu->totcol); } @@ -246,27 +264,28 @@ static void extern_local_curve(Curve *cu) void BKE_curve_make_local(Curve *cu) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; - int is_local= FALSE, is_lib= FALSE; - + int is_local = FALSE, is_lib = FALSE; + /* - when there are only lib users: don't do * - when there are only local users: set flag * - mixed: do a copy */ - - if (cu->id.lib==NULL) return; - if (cu->id.us==1) { + if (cu->id.lib == NULL) + return; + + if (cu->id.us == 1) { id_clear_lib_data(bmain, &cu->id); extern_local_curve(cu); return; } - for (ob= bmain->object.first; ob && ELEM(0, is_lib, is_local); ob= ob->id.next) { + for (ob = bmain->object.first; ob && ELEM(0, is_lib, is_local); ob = ob->id.next) { if (ob->data == cu) { - if (ob->id.lib) is_lib= TRUE; - else is_local= TRUE; + if (ob->id.lib) is_lib = TRUE; + else is_local = TRUE; } } @@ -275,15 +294,15 @@ void BKE_curve_make_local(Curve *cu) extern_local_curve(cu); } else if (is_local && is_lib) { - Curve *cu_new= BKE_curve_copy(cu); - cu_new->id.us= 0; + Curve *cu_new = BKE_curve_copy(cu); + cu_new->id.us = 0; BKE_id_lib_local_paths(bmain, cu->id.lib, &cu_new->id); - for (ob= bmain->object.first; ob; ob= ob->id.next) { - if (ob->data==cu) { - if (ob->id.lib==NULL) { - ob->data= cu_new; + for (ob = bmain->object.first; ob; ob = ob->id.next) { + if (ob->data == cu) { + if (ob->id.lib == NULL) { + ob->data = cu_new; cu_new->id.us++; cu->id.us--; } @@ -305,18 +324,18 @@ ListBase *BKE_curve_editNurbs_get(Curve *cu) short BKE_curve_type_get(Curve *cu) { Nurb *nu; - int type= cu->type; + int type = cu->type; if (cu->vfont) { return OB_FONT; } if (!cu->type) { - type= OB_CURVE; + type = OB_CURVE; - for (nu= cu->nurb.first; nu; nu= nu->next) { - if (nu->pntsv>1) { - type= OB_SURF; + for (nu = cu->nurb.first; nu; nu = nu->next) { + if (nu->pntsv > 1) { + type = OB_SURF; } } } @@ -326,16 +345,16 @@ short BKE_curve_type_get(Curve *cu) void BKE_curve_curve_dimension_update(Curve *cu) { - ListBase *nurbs= BKE_curve_nurbs_get(cu); - Nurb *nu= nurbs->first; + ListBase *nurbs = BKE_curve_nurbs_get(cu); + Nurb *nu = nurbs->first; - if (cu->flag&CU_3D) { - for ( ; nu; nu= nu->next) { + if (cu->flag & CU_3D) { + for (; nu; nu = nu->next) { nu->flag &= ~CU_2D; } } else { - for ( ; nu; nu= nu->next) { + for (; nu; nu = nu->next) { nu->flag |= CU_2D; BKE_nurb_test2D(nu); @@ -348,36 +367,36 @@ void BKE_curve_curve_dimension_update(Curve *cu) void BKE_curve_type_test(Object *ob) { - ob->type= BKE_curve_type_get(ob->data); + ob->type = BKE_curve_type_get(ob->data); - if (ob->type==OB_CURVE) + if (ob->type == OB_CURVE) BKE_curve_curve_dimension_update((Curve *)ob->data); } -void BKE_curve_tex_space_calc(Curve *cu) +void BKE_curve_texspace_calc(Curve *cu) { DispList *dl; BoundBox *bb; float *fp, min[3], max[3]; - int tot, doit= 0; - - if (cu->bb==NULL) cu->bb= MEM_callocN(sizeof(BoundBox), "boundbox"); - bb= cu->bb; - + int tot, doit = 0; + + if (cu->bb == NULL) + cu->bb = MEM_callocN(sizeof(BoundBox), "boundbox"); + bb = cu->bb; + INIT_MINMAX(min, max); - dl= cu->disp.first; + dl = cu->disp.first; while (dl) { - tot = ELEM(dl->type, DL_INDEX3, DL_INDEX4) ? dl->nr : dl->nr * dl->parts; - if (tot) doit= 1; - fp= dl->verts; + if (tot) doit = 1; + fp = dl->verts; while (tot--) { DO_MINMAX(fp, min, max); fp += 3; } - dl= dl->next; + dl = dl->next; } if (!doit) { @@ -385,27 +404,27 @@ void BKE_curve_tex_space_calc(Curve *cu) max[0] = max[1] = max[2] = 1.0f; } - boundbox_set_from_min_max(bb, min, max); + BKE_boundbox_init_from_minmax(bb, min, max); if (cu->texflag & CU_AUTOSPACE) { mid_v3_v3v3(cu->loc, min, max); - cu->size[0]= (max[0]-min[0])/2.0f; - cu->size[1]= (max[1]-min[1])/2.0f; - cu->size[2]= (max[2]-min[2])/2.0f; + cu->size[0] = (max[0] - min[0]) / 2.0f; + cu->size[1] = (max[1] - min[1]) / 2.0f; + cu->size[2] = (max[2] - min[2]) / 2.0f; zero_v3(cu->rot); - 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.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.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; + 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.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.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; } } @@ -413,14 +432,16 @@ void BKE_curve_tex_space_calc(Curve *cu) int BKE_nurbList_verts_count(ListBase *nurb) { Nurb *nu; - int tot=0; - - nu= nurb->first; + int tot = 0; + + nu = nurb->first; while (nu) { - if (nu->bezt) tot+= 3*nu->pntsu; - else if (nu->bp) tot+= nu->pntsu*nu->pntsv; - - nu= nu->next; + if (nu->bezt) + tot += 3 * nu->pntsu; + else if (nu->bp) + tot += nu->pntsu * nu->pntsv; + + nu = nu->next; } return tot; } @@ -428,14 +449,16 @@ int BKE_nurbList_verts_count(ListBase *nurb) int BKE_nurbList_verts_count_without_handles(ListBase *nurb) { Nurb *nu; - int tot=0; - - nu= nurb->first; + int tot = 0; + + nu = nurb->first; while (nu) { - if (nu->bezt) tot+= nu->pntsu; - else if (nu->bp) tot+= nu->pntsu*nu->pntsv; - - nu= nu->next; + if (nu->bezt) + tot += nu->pntsu; + else if (nu->bp) + tot += nu->pntsu * nu->pntsv; + + nu = nu->next; } return tot; } @@ -445,16 +468,20 @@ int BKE_nurbList_verts_count_without_handles(ListBase *nurb) void BKE_nurb_free(Nurb *nu) { - if (nu==NULL) return; - - if (nu->bezt) MEM_freeN(nu->bezt); - nu->bezt= NULL; - if (nu->bp) MEM_freeN(nu->bp); - nu->bp= NULL; - if (nu->knotsu) MEM_freeN(nu->knotsu); - nu->knotsu= NULL; - if (nu->knotsv) MEM_freeN(nu->knotsv); - nu->knotsv= NULL; + if (nu == NULL) return; + + if (nu->bezt) + MEM_freeN(nu->bezt); + nu->bezt = NULL; + if (nu->bp) + MEM_freeN(nu->bp); + nu->bp = NULL; + if (nu->knotsu) + MEM_freeN(nu->knotsu); + nu->knotsu = NULL; + if (nu->knotsv) + MEM_freeN(nu->knotsv); + nu->knotsv = NULL; /* if (nu->trim.first) freeNurblist(&(nu->trim)); */ MEM_freeN(nu); @@ -466,15 +493,15 @@ void BKE_nurbList_free(ListBase *lb) { Nurb *nu, *next; - if (lb==NULL) return; + if (lb == NULL) return; - nu= lb->first; + nu = lb->first; while (nu) { - next= nu->next; + next = nu->next; BKE_nurb_free(nu); - nu= next; + nu = next; } - lb->first= lb->last= NULL; + lb->first = lb->last = NULL; } Nurb *BKE_nurb_duplicate(Nurb *nu) @@ -482,35 +509,35 @@ Nurb *BKE_nurb_duplicate(Nurb *nu) Nurb *newnu; int len; - newnu= (Nurb*)MEM_mallocN(sizeof(Nurb), "duplicateNurb"); - if (newnu==NULL) return NULL; + newnu = (Nurb *)MEM_mallocN(sizeof(Nurb), "duplicateNurb"); + if (newnu == NULL) return NULL; memcpy(newnu, nu, sizeof(Nurb)); if (nu->bezt) { - newnu->bezt= - (BezTriple*)MEM_mallocN((nu->pntsu)* sizeof(BezTriple), "duplicateNurb2"); - memcpy(newnu->bezt, nu->bezt, nu->pntsu*sizeof(BezTriple)); + newnu->bezt = + (BezTriple *)MEM_mallocN((nu->pntsu) * sizeof(BezTriple), "duplicateNurb2"); + memcpy(newnu->bezt, nu->bezt, nu->pntsu * sizeof(BezTriple)); } else { - len= nu->pntsu*nu->pntsv; - newnu->bp= - (BPoint*)MEM_mallocN((len)* sizeof(BPoint), "duplicateNurb3"); - memcpy(newnu->bp, nu->bp, len*sizeof(BPoint)); - - newnu->knotsu= newnu->knotsv= NULL; - + len = nu->pntsu * nu->pntsv; + newnu->bp = + (BPoint *)MEM_mallocN((len) * sizeof(BPoint), "duplicateNurb3"); + memcpy(newnu->bp, nu->bp, len * sizeof(BPoint)); + + newnu->knotsu = newnu->knotsv = NULL; + if (nu->knotsu) { - len= KNOTSU(nu); + len = KNOTSU(nu); if (len) { - newnu->knotsu= MEM_mallocN(len*sizeof(float), "duplicateNurb4"); - memcpy(newnu->knotsu, nu->knotsu, sizeof(float)*len); + newnu->knotsu = MEM_mallocN(len * sizeof(float), "duplicateNurb4"); + memcpy(newnu->knotsu, nu->knotsu, sizeof(float) * len); } } - if (nu->pntsv>1 && nu->knotsv) { - len= KNOTSV(nu); + if (nu->pntsv > 1 && nu->knotsv) { + len = KNOTSV(nu); if (len) { - newnu->knotsv= MEM_mallocN(len*sizeof(float), "duplicateNurb5"); - memcpy(newnu->knotsv, nu->knotsv, sizeof(float)*len); + newnu->knotsv = MEM_mallocN(len * sizeof(float), "duplicateNurb5"); + memcpy(newnu->knotsv, nu->knotsv, sizeof(float) * len); } } } @@ -520,15 +547,15 @@ Nurb *BKE_nurb_duplicate(Nurb *nu) void BKE_nurbList_duplicate(ListBase *lb1, ListBase *lb2) { Nurb *nu, *nun; - + BKE_nurbList_free(lb1); - - nu= lb2->first; + + nu = lb2->first; while (nu) { - nun= BKE_nurb_duplicate(nu); + nun = BKE_nurb_duplicate(nu); BLI_addtail(lb1, nun); - - nu= nu->next; + + nu = nu->next; } } @@ -537,25 +564,25 @@ void BKE_nurb_test2D(Nurb *nu) BezTriple *bezt; BPoint *bp; int a; - - if ((nu->flag & CU_2D)==0) + + if ((nu->flag & CU_2D) == 0) return; if (nu->type == CU_BEZIER) { - a= nu->pntsu; - bezt= nu->bezt; + a = nu->pntsu; + bezt = nu->bezt; while (a--) { - bezt->vec[0][2]= 0.0; - bezt->vec[1][2]= 0.0; - bezt->vec[2][2]= 0.0; + bezt->vec[0][2] = 0.0; + bezt->vec[1][2] = 0.0; + bezt->vec[2][2] = 0.0; bezt++; } } else { - a= nu->pntsu*nu->pntsv; - bp= nu->bp; + a = nu->pntsu * nu->pntsv; + bp = nu->bp; while (a--) { - bp->vec[2]= 0.0; + bp->vec[2] = 0.0; bp++; } } @@ -568,8 +595,8 @@ void BKE_nurb_minmax(Nurb *nu, float *min, float *max) int a; if (nu->type == CU_BEZIER) { - a= nu->pntsu; - bezt= nu->bezt; + a = nu->pntsu; + bezt = nu->bezt; while (a--) { DO_MINMAX(bezt->vec[0], min, max); DO_MINMAX(bezt->vec[1], min, max); @@ -578,8 +605,8 @@ void BKE_nurb_minmax(Nurb *nu, float *min, float *max) } } else { - a= nu->pntsu*nu->pntsv; - bp= nu->bp; + a = nu->pntsu * nu->pntsv; + bp = nu->bp; while (a--) { DO_MINMAX(bp->vec, min, max); bp++; @@ -590,9 +617,9 @@ void BKE_nurb_minmax(Nurb *nu, float *min, float *max) /* be sure to call makeknots after this */ void BKE_nurb_points_add(Nurb *nu, int number) { - BPoint *tmp= nu->bp; + BPoint *tmp = nu->bp; int i; - nu->bp= (BPoint *)MEM_mallocN((nu->pntsu + number) * sizeof(BPoint), "rna_Curve_spline_points_add"); + nu->bp = (BPoint *)MEM_mallocN((nu->pntsu + number) * sizeof(BPoint), "rna_Curve_spline_points_add"); if (tmp) { memmove(nu->bp, tmp, nu->pntsu * sizeof(BPoint)); @@ -601,8 +628,8 @@ void BKE_nurb_points_add(Nurb *nu, int number) memset(nu->bp + nu->pntsu, 0, number * sizeof(BPoint)); - for (i=0, tmp= nu->bp + nu->pntsu; i < number; i++, tmp++) { - tmp->radius= 1.0f; + for (i = 0, tmp = nu->bp + nu->pntsu; i < number; i++, tmp++) { + tmp->radius = 1.0f; } nu->pntsu += number; @@ -610,9 +637,9 @@ void BKE_nurb_points_add(Nurb *nu, int number) void BKE_nurb_bezierPoints_add(Nurb *nu, int number) { - BezTriple *tmp= nu->bezt; + BezTriple *tmp = nu->bezt; int i; - nu->bezt= (BezTriple *)MEM_mallocN((nu->pntsu + number) * sizeof(BezTriple), "rna_Curve_spline_points_add"); + nu->bezt = (BezTriple *)MEM_mallocN((nu->pntsu + number) * sizeof(BezTriple), "rna_Curve_spline_points_add"); if (tmp) { memmove(nu->bezt, tmp, nu->pntsu * sizeof(BezTriple)); @@ -621,8 +648,8 @@ void BKE_nurb_bezierPoints_add(Nurb *nu, int number) memset(nu->bezt + nu->pntsu, 0, number * sizeof(BezTriple)); - for (i=0, tmp= nu->bezt + nu->pntsu; i < number; i++, tmp++) { - tmp->radius= 1.0f; + for (i = 0, tmp = nu->bezt + nu->pntsu; i < number; i++, tmp++) { + tmp->radius = 1.0f; } nu->pntsu += number; @@ -634,44 +661,46 @@ void BKE_nurb_bezierPoints_add(Nurb *nu, int number) static void calcknots(float *knots, const short pnts, const short order, const short flag) { /* knots: number of pnts NOT corrected for cyclic */ - const int pnts_order= pnts + order; + const int pnts_order = pnts + order; float k; int a; - switch (flag & (CU_NURB_ENDPOINT|CU_NURB_BEZIER)) { - case CU_NURB_ENDPOINT: - k= 0.0; - for (a=1; a <= pnts_order; a++) { - knots[a-1]= k; - if (a >= order && a <= pnts) k+= 1.0f; - } - break; - case CU_NURB_BEZIER: - /* Warning, the order MUST be 2 or 4, - * if this is not enforced, the displist will be corrupt */ - if (order==4) { - k= 0.34; - for (a=0; a < pnts_order; a++) { - knots[a]= floorf(k); - k+= (1.0f/3.0f); + switch (flag & (CU_NURB_ENDPOINT | CU_NURB_BEZIER)) { + case CU_NURB_ENDPOINT: + k = 0.0; + for (a = 1; a <= pnts_order; a++) { + knots[a - 1] = k; + if (a >= order && a <= pnts) + k += 1.0f; } - } - else if (order==3) { - k= 0.6f; - for (a=0; a < pnts_order; a++) { - if (a >= order && a <= pnts) k+= 0.5f; - knots[a]= floorf(k); + break; + case CU_NURB_BEZIER: + /* Warning, the order MUST be 2 or 4, + * if this is not enforced, the displist will be corrupt */ + if (order == 4) { + k = 0.34; + for (a = 0; a < pnts_order; a++) { + knots[a] = floorf(k); + k += (1.0f / 3.0f); + } } - } - else { - printf("bez nurb curve order is not 3 or 4, should never happen\n"); - } - break; - default: - for (a=0; a < pnts_order; a++) { - knots[a]= (float)a; - } - break; + else if (order == 3) { + k = 0.6f; + for (a = 0; a < pnts_order; a++) { + if (a >= order && a <= pnts) + k += 0.5f; + knots[a] = floorf(k); + } + } + else { + printf("bez nurb curve order is not 3 or 4, should never happen\n"); + } + break; + default: + for (a = 0; a < pnts_order; a++) { + knots[a] = (float)a; + } + break; } } @@ -680,23 +709,26 @@ static void makecyclicknots(float *knots, short pnts, short order) { int a, b, order2, c; - if (knots==NULL) return; + if (knots == NULL) + return; - order2=order-1; + order2 = order - 1; /* do first long rows (order -1), remove identical knots at endpoints */ - if (order>2) { - b= pnts+order2; - for (a=1; a<order2; a++) { - if (knots[b]!= knots[b-a]) break; + if (order > 2) { + b = pnts + order2; + for (a = 1; a < order2; a++) { + if (knots[b] != knots[b - a]) + break; } - if (a==order2) knots[pnts+order-2]+= 1.0f; + if (a == order2) + knots[pnts + order - 2] += 1.0f; } - b= order; - c=pnts + order + order2; - for (a=pnts+order2; a<c; a++) { - knots[a]= knots[a-1]+ (knots[b]-knots[b-1]); + b = order; + c = pnts + order + order2; + for (a = pnts + order2; a < c; a++) { + knots[a] = knots[a - 1] + (knots[b] - knots[b - 1]); b--; } } @@ -707,9 +739,10 @@ static void makeknots(Nurb *nu, short uv) { if (nu->type == CU_NURBS) { if (uv == 1) { - if (nu->knotsu) MEM_freeN(nu->knotsu); + if (nu->knotsu) + MEM_freeN(nu->knotsu); if (BKE_nurb_check_valid_u(nu)) { - nu->knotsu= MEM_callocN(4+sizeof(float)*KNOTSU(nu), "makeknots"); + nu->knotsu = MEM_callocN(4 + sizeof(float) * KNOTSU(nu), "makeknots"); if (nu->flagu & CU_NURB_CYCLIC) { calcknots(nu->knotsu, nu->pntsu, nu->orderu, 0); /* cyclic should be uniform */ makecyclicknots(nu->knotsu, nu->pntsu, nu->orderu); @@ -718,13 +751,14 @@ static void makeknots(Nurb *nu, short uv) calcknots(nu->knotsu, nu->pntsu, nu->orderu, nu->flagu); } } - else nu->knotsu= NULL; - + else + nu->knotsu = NULL; } else if (uv == 2) { - if (nu->knotsv) MEM_freeN(nu->knotsv); + if (nu->knotsv) + MEM_freeN(nu->knotsv); if (BKE_nurb_check_valid_v(nu)) { - nu->knotsv= MEM_callocN(4+sizeof(float)*KNOTSV(nu), "makeknots"); + nu->knotsv = MEM_callocN(4 + sizeof(float) * KNOTSV(nu), "makeknots"); if (nu->flagv & CU_NURB_CYCLIC) { calcknots(nu->knotsv, nu->pntsv, nu->orderv, 0); /* cyclic should be uniform */ makecyclicknots(nu->knotsv, nu->pntsv, nu->orderv); @@ -733,7 +767,7 @@ static void makeknots(Nurb *nu, short uv) calcknots(nu->knotsv, nu->pntsv, nu->orderv, nu->flagv); } } - else nu->knotsv= NULL; + else nu->knotsv = NULL; } } } @@ -753,59 +787,62 @@ static void basisNurb(float t, short order, short pnts, float *knots, float *bas float d, e; int i, i1 = 0, i2 = 0, j, orderpluspnts, opp2, o2; - orderpluspnts= order+pnts; - opp2 = orderpluspnts-1; + orderpluspnts = order + pnts; + opp2 = orderpluspnts - 1; /* this is for float inaccuracy */ - if (t < knots[0]) t= knots[0]; - else if (t > knots[opp2]) t= knots[opp2]; + if (t < knots[0]) + t = knots[0]; + else + if (t > knots[opp2]) t = knots[opp2]; /* this part is order '1' */ - o2 = order + 1; - for (i=0;i<opp2;i++) { - if (knots[i]!=knots[i+1] && t>= knots[i] && t<=knots[i+1]) { - basis[i]= 1.0; - i1= i-o2; - if (i1<0) i1= 0; - i2= i; + o2 = order + 1; + for (i = 0; i < opp2; i++) { + if (knots[i] != knots[i + 1] && t >= knots[i] && t <= knots[i + 1]) { + basis[i] = 1.0; + i1 = i - o2; + if (i1 < 0) i1 = 0; + i2 = i; i++; - while (i<opp2) { - basis[i]= 0.0; + while (i < opp2) { + basis[i] = 0.0; i++; } break; } - else basis[i]= 0.0; + else + basis[i] = 0.0; } - basis[i]= 0.0; - + basis[i] = 0.0; + /* this is order 2, 3, ... */ - for (j=2; j<=order; j++) { + for (j = 2; j <= order; j++) { - if (i2+j>= orderpluspnts) i2= opp2-j; + if (i2 + j >= orderpluspnts) i2 = opp2 - j; - for (i= i1; i<=i2; i++) { - if (basis[i]!=0.0f) - d= ((t-knots[i])*basis[i]) / (knots[i+j-1]-knots[i]); + for (i = i1; i <= i2; i++) { + if (basis[i] != 0.0f) + d = ((t - knots[i]) * basis[i]) / (knots[i + j - 1] - knots[i]); else - d= 0.0f; + d = 0.0f; - if (basis[i+1] != 0.0f) - e= ((knots[i+j]-t)*basis[i+1]) / (knots[i+j]-knots[i+1]); + if (basis[i + 1] != 0.0f) + e = ((knots[i + j] - t) * basis[i + 1]) / (knots[i + j] - knots[i + 1]); else - e= 0.0; + e = 0.0; - basis[i]= d+e; + basis[i] = d + e; } } - *start= 1000; - *end= 0; + *start = 1000; + *end = 0; - for (i=i1; i<=i2; i++) { + for (i = i1; i <= i2; i++) { if (basis[i] > 0.0f) { - *end= i; - if (*start==1000) *start= i; + *end = i; + if (*start == 1000) *start = i; } } } @@ -819,151 +856,165 @@ void BKE_nurb_makeFaces(Nurb *nu, float *coord_array, int rowstride, int resolu, float u, v, ustart, uend, ustep, vstart, vend, vstep, sumdiv; int i, j, iofs, jofs, cycl, len, curu, curv; int istart, iend, jsta, jen, *jstart, *jend, ratcomp; - - int totu = nu->pntsu*resolu, totv = nu->pntsv*resolv; - - if (nu->knotsu==NULL || nu->knotsv==NULL) return; - if (nu->orderu>nu->pntsu) return; - if (nu->orderv>nu->pntsv) return; - if (coord_array==NULL) return; - + + int totu = nu->pntsu * resolu, totv = nu->pntsv * resolv; + + if (nu->knotsu == NULL || nu->knotsv == NULL) + return; + if (nu->orderu > nu->pntsu) + return; + if (nu->orderv > nu->pntsv) + return; + if (coord_array == NULL) + return; + /* allocate and initialize */ len = totu * totv; - if (len==0) return; - - - - sum= (float *)MEM_callocN(sizeof(float)*len, "makeNurbfaces1"); - - len= totu*totv; - if (len==0) { + if (len == 0) + return; + + sum = (float *)MEM_callocN(sizeof(float) * len, "makeNurbfaces1"); + + len = totu * totv; + if (len == 0) { MEM_freeN(sum); return; } - bp= nu->bp; - i= nu->pntsu*nu->pntsv; - ratcomp=0; + bp = nu->bp; + i = nu->pntsu * nu->pntsv; + ratcomp = 0; while (i--) { if (bp->vec[3] != 1.0f) { - ratcomp= 1; + ratcomp = 1; break; } bp++; } - - fp= nu->knotsu; - ustart= fp[nu->orderu-1]; - if (nu->flagu & CU_NURB_CYCLIC) uend= fp[nu->pntsu+nu->orderu-1]; - else uend= fp[nu->pntsu]; - ustep= (uend-ustart)/((nu->flagu & CU_NURB_CYCLIC) ? totu : totu - 1); - - basisu= (float *)MEM_mallocN(sizeof(float)*KNOTSU(nu), "makeNurbfaces3"); - - fp= nu->knotsv; - vstart= fp[nu->orderv-1]; - - if (nu->flagv & CU_NURB_CYCLIC) vend= fp[nu->pntsv+nu->orderv-1]; - else vend= fp[nu->pntsv]; - vstep= (vend-vstart)/((nu->flagv & CU_NURB_CYCLIC) ? totv : totv - 1); - - len= KNOTSV(nu); - basisv= (float *)MEM_mallocN(sizeof(float)*len*totv, "makeNurbfaces3"); - jstart= (int *)MEM_mallocN(sizeof(float)*totv, "makeNurbfaces4"); - jend= (int *)MEM_mallocN(sizeof(float)*totv, "makeNurbfaces5"); + + fp = nu->knotsu; + ustart = fp[nu->orderu - 1]; + if (nu->flagu & CU_NURB_CYCLIC) + uend = fp[nu->pntsu + nu->orderu - 1]; + else + uend = fp[nu->pntsu]; + ustep = (uend - ustart) / ((nu->flagu & CU_NURB_CYCLIC) ? totu : totu - 1); + + basisu = (float *)MEM_mallocN(sizeof(float) * KNOTSU(nu), "makeNurbfaces3"); + + fp = nu->knotsv; + vstart = fp[nu->orderv - 1]; + + if (nu->flagv & CU_NURB_CYCLIC) + vend = fp[nu->pntsv + nu->orderv - 1]; + else + vend = fp[nu->pntsv]; + vstep = (vend - vstart) / ((nu->flagv & CU_NURB_CYCLIC) ? totv : totv - 1); + + len = KNOTSV(nu); + basisv = (float *)MEM_mallocN(sizeof(float) * len * totv, "makeNurbfaces3"); + jstart = (int *)MEM_mallocN(sizeof(float) * totv, "makeNurbfaces4"); + jend = (int *)MEM_mallocN(sizeof(float) * totv, "makeNurbfaces5"); /* precalculation of basisv and jstart, jend */ - if (nu->flagv & CU_NURB_CYCLIC) cycl= nu->orderv-1; - else cycl= 0; - v= vstart; - basis= basisv; - curv= totv; + if (nu->flagv & CU_NURB_CYCLIC) + cycl = nu->orderv - 1; + else cycl = 0; + v = vstart; + basis = basisv; + curv = totv; while (curv--) { - basisNurb(v, nu->orderv, (short)(nu->pntsv+cycl), nu->knotsv, basis, jstart+curv, jend+curv); - basis+= KNOTSV(nu); - v+= vstep; - } - - if (nu->flagu & CU_NURB_CYCLIC) cycl= nu->orderu-1; - else cycl= 0; - in= coord_array; - u= ustart; - curu= totu; + basisNurb(v, nu->orderv, (short)(nu->pntsv + cycl), nu->knotsv, basis, jstart + curv, jend + curv); + basis += KNOTSV(nu); + v += vstep; + } + + if (nu->flagu & CU_NURB_CYCLIC) + cycl = nu->orderu - 1; + else + cycl = 0; + in = coord_array; + u = ustart; + curu = totu; while (curu--) { + basisNurb(u, nu->orderu, (short)(nu->pntsu + cycl), nu->knotsu, basisu, &istart, &iend); - basisNurb(u, nu->orderu, (short)(nu->pntsu+cycl), nu->knotsu, basisu, &istart, &iend); - - basis= basisv; - curv= totv; + basis = basisv; + curv = totv; while (curv--) { - - jsta= jstart[curv]; - jen= jend[curv]; + jsta = jstart[curv]; + jen = jend[curv]; /* calculate sum */ - sumdiv= 0.0; - fp= sum; - - for (j= jsta; j<=jen; j++) { + sumdiv = 0.0; + fp = sum; - if (j>=nu->pntsv) jofs= (j - nu->pntsv); - else jofs= j; - bp= nu->bp+ nu->pntsu*jofs+istart-1; + for (j = jsta; j <= jen; j++) { - for (i= istart; i<=iend; i++, fp++) { + if (j >= nu->pntsv) + jofs = (j - nu->pntsv); + else + jofs = j; + bp = nu->bp + nu->pntsu * jofs + istart - 1; - if (i>= nu->pntsu) { - iofs= i- nu->pntsu; - bp= nu->bp+ nu->pntsu*jofs+iofs; + for (i = istart; i <= iend; i++, fp++) { + if (i >= nu->pntsu) { + iofs = i - nu->pntsu; + bp = nu->bp + nu->pntsu * jofs + iofs; } - else bp++; + else + bp++; if (ratcomp) { - *fp= basisu[i]*basis[j]*bp->vec[3]; - sumdiv+= *fp; + *fp = basisu[i] * basis[j] * bp->vec[3]; + sumdiv += *fp; } - else *fp= basisu[i]*basis[j]; + else + *fp = basisu[i] * basis[j]; } } - + if (ratcomp) { - fp= sum; - for (j= jsta; j<=jen; j++) { - for (i= istart; i<=iend; i++, fp++) { - *fp/= sumdiv; + fp = sum; + for (j = jsta; j <= jen; j++) { + for (i = istart; i <= iend; i++, fp++) { + *fp /= sumdiv; } } } /* one! (1.0) real point now */ - fp= sum; - for (j= jsta; j<=jen; j++) { - - if (j>=nu->pntsv) jofs= (j - nu->pntsv); - else jofs= j; - bp= nu->bp+ nu->pntsu*jofs+istart-1; + fp = sum; + for (j = jsta; j <= jen; j++) { - for (i= istart; i<=iend; i++, fp++) { + if (j >= nu->pntsv) + jofs = (j - nu->pntsv); + else + jofs = j; + bp = nu->bp + nu->pntsu * jofs + istart - 1; - if (i>= nu->pntsu) { - iofs= i- nu->pntsu; - bp= nu->bp+ nu->pntsu*jofs+iofs; + for (i = istart; i <= iend; i++, fp++) { + if (i >= nu->pntsu) { + iofs = i - nu->pntsu; + bp = nu->bp + nu->pntsu * jofs + iofs; } - else bp++; + else + bp++; if (*fp != 0.0f) { - in[0]+= (*fp) * bp->vec[0]; - in[1]+= (*fp) * bp->vec[1]; - in[2]+= (*fp) * bp->vec[2]; + in[0] += (*fp) * bp->vec[0]; + in[1] += (*fp) * bp->vec[1]; + in[2] += (*fp) * bp->vec[2]; } } } - in+=3; - basis+= KNOTSV(nu); + in += 3; + basis += KNOTSV(nu); } - u+= ustep; - if (rowstride!=0) in = (float*) (((unsigned char*) in) + (rowstride - 3*totv*sizeof(*in))); + u += ustep; + if (rowstride != 0) + in = (float *) (((unsigned char *) in) + (rowstride - 3 * totv * sizeof(*in))); } /* free */ @@ -974,100 +1025,112 @@ void BKE_nurb_makeFaces(Nurb *nu, float *coord_array, int rowstride, int resolu, MEM_freeN(jend); } -void BKE_nurb_makeCurve(Nurb *nu, float *coord_array, float *tilt_array, float *radius_array, float *weight_array, int resolu, int stride) +void BKE_nurb_makeCurve(Nurb *nu, float *coord_array, float *tilt_array, float *radius_array, float *weight_array, + int resolu, int stride) /* coord_array has to be 3*4*pntsu*resolu in size and zero-ed * tilt_array and radius_array will be written to if valid */ { BPoint *bp; float u, ustart, uend, ustep, sumdiv; float *basisu, *sum, *fp; - float *coord_fp= coord_array, *tilt_fp= tilt_array, *radius_fp= radius_array, *weight_fp= weight_array; + float *coord_fp = coord_array, *tilt_fp = tilt_array, *radius_fp = radius_array, *weight_fp = weight_array; int i, len, istart, iend, cycl; - if (nu->knotsu==NULL) return; - if (nu->orderu>nu->pntsu) return; - if (coord_array==NULL) return; + if (nu->knotsu == NULL) + return; + if (nu->orderu > nu->pntsu) + return; + if (coord_array == NULL) + return; /* allocate and initialize */ - len= nu->pntsu; - if (len==0) return; - sum= (float *)MEM_callocN(sizeof(float)*len, "makeNurbcurve1"); - - resolu= (resolu*SEGMENTSU(nu)); - - if (resolu==0) { + len = nu->pntsu; + if (len == 0) + return; + sum = (float *)MEM_callocN(sizeof(float) * len, "makeNurbcurve1"); + + resolu = (resolu * SEGMENTSU(nu)); + + if (resolu == 0) { MEM_freeN(sum); return; } - fp= nu->knotsu; - ustart= fp[nu->orderu-1]; - if (nu->flagu & CU_NURB_CYCLIC) uend= fp[nu->pntsu+nu->orderu-1]; - else uend= fp[nu->pntsu]; - ustep= (uend-ustart)/(resolu - ((nu->flagu & CU_NURB_CYCLIC) ? 0 : 1)); - - basisu= (float *)MEM_mallocN(sizeof(float)*KNOTSU(nu), "makeNurbcurve3"); + fp = nu->knotsu; + ustart = fp[nu->orderu - 1]; + if (nu->flagu & CU_NURB_CYCLIC) + uend = fp[nu->pntsu + nu->orderu - 1]; + else + uend = fp[nu->pntsu]; + ustep = (uend - ustart) / (resolu - ((nu->flagu & CU_NURB_CYCLIC) ? 0 : 1)); - if (nu->flagu & CU_NURB_CYCLIC) cycl= nu->orderu-1; - else cycl= 0; + basisu = (float *)MEM_mallocN(sizeof(float) * KNOTSU(nu), "makeNurbcurve3"); - u= ustart; + if (nu->flagu & CU_NURB_CYCLIC) + cycl = nu->orderu - 1; + else + cycl = 0; + + u = ustart; while (resolu--) { + basisNurb(u, nu->orderu, (short)(nu->pntsu + cycl), nu->knotsu, basisu, &istart, &iend); - basisNurb(u, nu->orderu, (short)(nu->pntsu+cycl), nu->knotsu, basisu, &istart, &iend); /* calc sum */ - sumdiv= 0.0; - fp= sum; - bp= nu->bp+ istart-1; - for (i= istart; i<=iend; i++, fp++) { - - if (i>=nu->pntsu) bp= nu->bp+(i - nu->pntsu); - else bp++; + sumdiv = 0.0; + fp = sum; + bp = nu->bp + istart - 1; + for (i = istart; i <= iend; i++, fp++) { + if (i >= nu->pntsu) + bp = nu->bp + (i - nu->pntsu); + else + bp++; - *fp= basisu[i]*bp->vec[3]; - sumdiv+= *fp; + *fp = basisu[i] * bp->vec[3]; + sumdiv += *fp; } if (sumdiv != 0.0f) if (sumdiv < 0.999f || sumdiv > 1.001f) { - /* is normalizing needed? */ - fp= sum; - for (i= istart; i<=iend; i++, fp++) { - *fp/= sumdiv; + /* is normalizing needed? */ + fp = sum; + for (i = istart; i <= iend; i++, fp++) { + *fp /= sumdiv; + } } - } /* one! (1.0) real point */ - fp= sum; - bp= nu->bp+ istart-1; - for (i= istart; i<=iend; i++, fp++) { - - if (i>=nu->pntsu) bp= nu->bp+(i - nu->pntsu); - else bp++; + fp = sum; + bp = nu->bp + istart - 1; + for (i = istart; i <= iend; i++, fp++) { + if (i >= nu->pntsu) + bp = nu->bp + (i - nu->pntsu); + else + bp++; if (*fp != 0.0f) { - - coord_fp[0]+= (*fp) * bp->vec[0]; - coord_fp[1]+= (*fp) * bp->vec[1]; - coord_fp[2]+= (*fp) * bp->vec[2]; - + coord_fp[0] += (*fp) * bp->vec[0]; + coord_fp[1] += (*fp) * bp->vec[1]; + coord_fp[2] += (*fp) * bp->vec[2]; + if (tilt_fp) (*tilt_fp) += (*fp) * bp->alfa; - + if (radius_fp) (*radius_fp) += (*fp) * bp->radius; if (weight_fp) (*weight_fp) += (*fp) * bp->weight; - } } coord_fp = (float *)(((char *)coord_fp) + stride); - - if (tilt_fp) tilt_fp = (float *)(((char *)tilt_fp) + stride); - if (radius_fp) radius_fp = (float *)(((char *)radius_fp) + stride); - if (weight_fp) weight_fp = (float *)(((char *)weight_fp) + stride); - - u+= ustep; + + if (tilt_fp) + tilt_fp = (float *)(((char *)tilt_fp) + stride); + if (radius_fp) + radius_fp = (float *)(((char *)radius_fp) + stride); + if (weight_fp) + weight_fp = (float *)(((char *)weight_fp) + stride); + + u += ustep; } /* free */ @@ -1081,25 +1144,25 @@ void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float float rt0, rt1, rt2, rt3, f; int a; - f= (float)it; - rt0= q0; - rt1= 3.0f*(q1-q0)/f; - f*= f; - rt2= 3.0f*(q0-2.0f*q1+q2)/f; - f*= it; - rt3= (q3-q0+3.0f*(q1-q2))/f; + f = (float)it; + rt0 = q0; + rt1 = 3.0f * (q1 - q0) / f; + f *= f; + rt2 = 3.0f * (q0 - 2.0f * q1 + q2) / f; + f *= it; + rt3 = (q3 - q0 + 3.0f * (q1 - q2)) / f; - q0= rt0; - q1= rt1+rt2+rt3; - q2= 2*rt2+6*rt3; - q3= 6*rt3; + q0 = rt0; + q1 = rt1 + rt2 + rt3; + q2 = 2 * rt2 + 6 * rt3; + q3 = 6 * rt3; - for (a=0; a<=it; a++) { - *p= q0; - p = (float *)(((char *)p)+stride); - q0+= q1; - q1+= q2; - q2+= q3; + for (a = 0; a <= it; a++) { + *p = q0; + p = (float *)(((char *)p) + stride); + q0 += q1; + q1 += q2; + q2 += q3; } } @@ -1110,15 +1173,15 @@ static void forward_diff_bezier_cotangent(float *p0, float *p1, float *p2, float * * This could also be optimized like forward_diff_bezier */ int a; - for (a=0; a<=it; a++) { + for (a = 0; a <= it; a++) { float t = (float)a / (float)it; int i; - for (i=0; i<3; i++) { - p[i]= (-6*t + 6)*p0[i] + (18*t - 12)*p1[i] + (-18*t + 6)*p2[i] + (6*t)*p3[i]; + for (i = 0; i < 3; i++) { + p[i] = (-6 * t + 6) * p0[i] + (18 * t - 12) * p1[i] + (-18 * t + 6) * p2[i] + (6 * t) * p3[i]; } normalize_v3(p); - p = (float *)(((char *)p)+stride); + p = (float *)(((char *)p) + stride); } } @@ -1128,15 +1191,15 @@ float *BKE_curve_surf_make_orco(Object *ob) { /* Note: this function is used in convertblender only atm, so * suppose nonzero curve's render resolution should always be used */ - Curve *cu= ob->data; + Curve *cu = ob->data; Nurb *nu; - int a, b, tot=0; + int a, b, tot = 0; int sizeu, sizev; int resolu, resolv; float *fp, *coord_array; - + /* first calculate the size of the datablock */ - nu= cu->nurb.first; + nu = cu->nurb.first; while (nu) { /* as we want to avoid the seam in a cyclic nurbs * texture wrapping, reserve extra orco data space to save these extra needed @@ -1147,85 +1210,93 @@ float *BKE_curve_surf_make_orco(Object *ob) * See also convertblender.c: init_render_surf() */ - resolu= cu->resolu_ren ? cu->resolu_ren : nu->resolu; - resolv= cu->resolv_ren ? cu->resolv_ren : nu->resolv; - - sizeu = nu->pntsu*resolu; - sizev = nu->pntsv*resolv; + resolu = cu->resolu_ren ? cu->resolu_ren : nu->resolu; + resolv = cu->resolv_ren ? cu->resolv_ren : nu->resolv; + + sizeu = nu->pntsu * resolu; + sizev = nu->pntsv * resolv; if (nu->flagu & CU_NURB_CYCLIC) sizeu++; if (nu->flagv & CU_NURB_CYCLIC) sizev++; - if (nu->pntsv>1) tot+= sizeu * sizev; - - nu= nu->next; + if (nu->pntsv > 1) tot += sizeu * sizev; + + nu = nu->next; } /* makeNurbfaces wants zeros */ - fp= coord_array= MEM_callocN(3*sizeof(float)*tot, "make_orco"); - - nu= cu->nurb.first; + fp = coord_array = MEM_callocN(3 * sizeof(float) * tot, "make_orco"); + + nu = cu->nurb.first; while (nu) { - resolu= cu->resolu_ren ? cu->resolu_ren : nu->resolu; - resolv= cu->resolv_ren ? cu->resolv_ren : nu->resolv; - - if (nu->pntsv>1) { - sizeu = nu->pntsu*resolu; - sizev = nu->pntsv*resolv; - if (nu->flagu & CU_NURB_CYCLIC) sizeu++; - if (nu->flagv & CU_NURB_CYCLIC) sizev++; - + resolu = cu->resolu_ren ? cu->resolu_ren : nu->resolu; + resolv = cu->resolv_ren ? cu->resolv_ren : nu->resolv; + + if (nu->pntsv > 1) { + sizeu = nu->pntsu * resolu; + sizev = nu->pntsv * resolv; + + if (nu->flagu & CU_NURB_CYCLIC) + sizeu++; + if (nu->flagv & CU_NURB_CYCLIC) + sizev++; + if (cu->flag & CU_UV_ORCO) { - for (b=0; b< sizeu; b++) { - for (a=0; a< sizev; a++) { - - if (sizev <2) fp[0]= 0.0f; - else fp[0]= -1.0f + 2.0f*((float)a)/(sizev - 1); - - if (sizeu <2) fp[1]= 0.0f; - else fp[1]= -1.0f + 2.0f*((float)b)/(sizeu - 1); - - fp[2]= 0.0; - - fp+= 3; + for (b = 0; b < sizeu; b++) { + for (a = 0; a < sizev; a++) { + + if (sizev < 2) + fp[0] = 0.0f; + else + fp[0] = -1.0f + 2.0f * ((float)a) / (sizev - 1); + + if (sizeu < 2) + fp[1] = 0.0f; + else + fp[1] = -1.0f + 2.0f * ((float)b) / (sizeu - 1); + + fp[2] = 0.0; + + fp += 3; } } } else { - float *_tdata= MEM_callocN((nu->pntsu*resolu) * (nu->pntsv*resolv) *3*sizeof(float), "temp data"); - float *tdata= _tdata; - + int size = (nu->pntsu * resolu) * (nu->pntsv * resolv) * 3 * sizeof(float); + float *_tdata = MEM_callocN(size, "temp data"); + float *tdata = _tdata; + BKE_nurb_makeFaces(nu, tdata, 0, resolu, resolv); - - for (b=0; b<sizeu; b++) { - int use_b= b; - if (b==sizeu-1 && (nu->flagu & CU_NURB_CYCLIC)) - use_b= 0; - - for (a=0; a<sizev; a++) { - int use_a= a; - if (a==sizev-1 && (nu->flagv & CU_NURB_CYCLIC)) - use_a= 0; - - tdata = _tdata + 3 * (use_b * (nu->pntsv*resolv) + use_a); - - fp[0]= (tdata[0]-cu->loc[0])/cu->size[0]; - fp[1]= (tdata[1]-cu->loc[1])/cu->size[1]; - fp[2]= (tdata[2]-cu->loc[2])/cu->size[2]; - fp+= 3; + + for (b = 0; b < sizeu; b++) { + int use_b = b; + if (b == sizeu - 1 && (nu->flagu & CU_NURB_CYCLIC)) + use_b = 0; + + for (a = 0; a < sizev; a++) { + int use_a = a; + if (a == sizev - 1 && (nu->flagv & CU_NURB_CYCLIC)) + use_a = 0; + + tdata = _tdata + 3 * (use_b * (nu->pntsv * resolv) + use_a); + + fp[0] = (tdata[0] - cu->loc[0]) / cu->size[0]; + fp[1] = (tdata[1] - cu->loc[1]) / cu->size[1]; + fp[2] = (tdata[2] - cu->loc[2]) / cu->size[2]; + fp += 3; } } - + MEM_freeN(_tdata); } } - nu= nu->next; + nu = nu->next; } - + return coord_array; } - /* NOTE: This routine is tied to the order of vertex - * built by displist and as passed to the renderer. - */ +/* NOTE: This routine is tied to the order of vertex + * built by displist and as passed to the renderer. + */ float *BKE_curve_make_orco(Scene *scene, Object *ob) { Curve *cu = ob->data; @@ -1234,79 +1305,81 @@ float *BKE_curve_make_orco(Scene *scene, Object *ob) float *fp, *coord_array; ListBase disp = {NULL, NULL}; - makeDispListCurveTypes_forOrco(scene, ob, &disp); + BKE_displist_make_curveTypes_forOrco(scene, ob, &disp); numVerts = 0; - for (dl=disp.first; dl; dl=dl->next) { - if (dl->type==DL_INDEX3) { + for (dl = disp.first; dl; dl = dl->next) { + if (dl->type == DL_INDEX3) { numVerts += dl->nr; } - else if (dl->type==DL_SURF) { - /* convertblender.c uses the Surface code for creating renderfaces when cyclic U only (closed circle beveling) */ + else if (dl->type == DL_SURF) { + /* convertblender.c uses the Surface code for creating renderfaces when cyclic U only + * (closed circle beveling) + */ if (dl->flag & DL_CYCL_U) { if (dl->flag & DL_CYCL_V) - numVerts += (dl->parts+1)*(dl->nr+1); + numVerts += (dl->parts + 1) * (dl->nr + 1); else - numVerts += dl->parts*(dl->nr+1); + numVerts += dl->parts * (dl->nr + 1); } else - numVerts += dl->parts*dl->nr; + numVerts += dl->parts * dl->nr; } } - fp= coord_array= MEM_mallocN(3*sizeof(float)*numVerts, "cu_orco"); - for (dl=disp.first; dl; dl=dl->next) { - if (dl->type==DL_INDEX3) { - for (u=0; u<dl->nr; u++, fp+=3) { + fp = coord_array = MEM_mallocN(3 * sizeof(float) * numVerts, "cu_orco"); + for (dl = disp.first; dl; dl = dl->next) { + if (dl->type == DL_INDEX3) { + for (u = 0; u < dl->nr; u++, fp += 3) { if (cu->flag & CU_UV_ORCO) { - fp[0]= 2.0f*u/(dl->nr-1) - 1.0f; - fp[1]= 0.0; - fp[2]= 0.0; + fp[0] = 2.0f * u / (dl->nr - 1) - 1.0f; + fp[1] = 0.0; + fp[2] = 0.0; } else { - copy_v3_v3(fp, &dl->verts[u*3]); + copy_v3_v3(fp, &dl->verts[u * 3]); - fp[0]= (fp[0]-cu->loc[0])/cu->size[0]; - fp[1]= (fp[1]-cu->loc[1])/cu->size[1]; - fp[2]= (fp[2]-cu->loc[2])/cu->size[2]; + fp[0] = (fp[0] - cu->loc[0]) / cu->size[0]; + fp[1] = (fp[1] - cu->loc[1]) / cu->size[1]; + fp[2] = (fp[2] - cu->loc[2]) / cu->size[2]; } } } - else if (dl->type==DL_SURF) { - int sizeu= dl->nr, sizev= dl->parts; - + else if (dl->type == DL_SURF) { + int sizeu = dl->nr, sizev = dl->parts; + /* exception as handled in convertblender.c too */ if (dl->flag & DL_CYCL_U) { sizeu++; if (dl->flag & DL_CYCL_V) sizev++; } - - for (u=0; u<sizev; u++) { - for (v=0; v<sizeu; v++, fp+=3) { + + for (u = 0; u < sizev; u++) { + for (v = 0; v < sizeu; v++, fp += 3) { if (cu->flag & CU_UV_ORCO) { - fp[0]= 2.0f*u/(sizev - 1) - 1.0f; - fp[1]= 2.0f*v/(sizeu - 1) - 1.0f; - fp[2]= 0.0; + fp[0] = 2.0f * u / (sizev - 1) - 1.0f; + fp[1] = 2.0f * v / (sizeu - 1) - 1.0f; + fp[2] = 0.0; } else { float *vert; - int realv= v % dl->nr; - int realu= u % dl->parts; - - vert= dl->verts + 3*(dl->nr*realu + realv); + int realv = v % dl->nr; + int realu = u % dl->parts; + + vert = dl->verts + 3 * (dl->nr * realu + realv); copy_v3_v3(fp, vert); - fp[0]= (fp[0]-cu->loc[0])/cu->size[0]; - fp[1]= (fp[1]-cu->loc[1])/cu->size[1]; - fp[2]= (fp[2]-cu->loc[2])/cu->size[2]; + fp[0] = (fp[0] - cu->loc[0]) / cu->size[0]; + fp[1] = (fp[1] - cu->loc[1]) / cu->size[1]; + fp[2] = (fp[2] - cu->loc[2]) / cu->size[2]; } } } } } - freedisplist(&disp); + BKE_displist_free(&disp); return coord_array; } @@ -1321,189 +1394,190 @@ void BKE_curve_bevel_make(Scene *scene, Object *ob, ListBase *disp, int forRende float *fp, facx, facy, angle, dangle; int nr, a; - cu= ob->data; + cu = ob->data; disp->first = disp->last = NULL; /* if a font object is being edited, then do nothing */ // XXX if ( ob == obedit && ob->type == OB_FONT ) return; if (cu->bevobj) { - if (cu->bevobj->type!=OB_CURVE) return; + if (cu->bevobj->type != OB_CURVE) + return; - bevcu= cu->bevobj->data; - if (bevcu->ext1==0.0f && bevcu->ext2==0.0f) { - ListBase bevdisp= {NULL, NULL}; - facx= cu->bevobj->size[0]; - facy= cu->bevobj->size[1]; + bevcu = cu->bevobj->data; + if (bevcu->ext1 == 0.0f && bevcu->ext2 == 0.0f) { + ListBase bevdisp = {NULL, NULL}; + facx = cu->bevobj->size[0]; + facy = cu->bevobj->size[1]; if (forRender) { - makeDispListCurveTypes_forRender(scene, cu->bevobj, &bevdisp, NULL, 0); - dl= bevdisp.first; + BKE_displist_make_curveTypes_forRender(scene, cu->bevobj, &bevdisp, NULL, 0); + dl = bevdisp.first; } else { - dl= cu->bevobj->disp.first; - if (dl==NULL) { - makeDispListCurveTypes(scene, cu->bevobj, 0); - dl= cu->bevobj->disp.first; + dl = cu->bevobj->disp.first; + if (dl == NULL) { + BKE_displist_make_curveTypes(scene, cu->bevobj, 0); + dl = cu->bevobj->disp.first; } } while (dl) { if (ELEM(dl->type, DL_POLY, DL_SEGM)) { - dlnew= MEM_mallocN(sizeof(DispList), "makebevelcurve1"); - *dlnew= *dl; - dlnew->verts= MEM_mallocN(3*sizeof(float)*dl->parts*dl->nr, "makebevelcurve1"); - memcpy(dlnew->verts, dl->verts, 3*sizeof(float)*dl->parts*dl->nr); + dlnew = MEM_mallocN(sizeof(DispList), "makebevelcurve1"); + *dlnew = *dl; + dlnew->verts = MEM_mallocN(3 * sizeof(float) * dl->parts * dl->nr, "makebevelcurve1"); + memcpy(dlnew->verts, dl->verts, 3 * sizeof(float) * dl->parts * dl->nr); - if (dlnew->type==DL_SEGM) dlnew->flag |= (DL_FRONT_CURVE|DL_BACK_CURVE); + if (dlnew->type == DL_SEGM) + dlnew->flag |= (DL_FRONT_CURVE | DL_BACK_CURVE); BLI_addtail(disp, dlnew); - fp= dlnew->verts; - nr= dlnew->parts*dlnew->nr; + fp = dlnew->verts; + nr = dlnew->parts * dlnew->nr; while (nr--) { - fp[2]= fp[1]*facy; - fp[1]= -fp[0]*facx; - fp[0]= 0.0; - fp+= 3; + fp[2] = fp[1] * facy; + fp[1] = -fp[0] * facx; + fp[0] = 0.0; + fp += 3; } } - dl= dl->next; + dl = dl->next; } - freedisplist(&bevdisp); + BKE_displist_free(&bevdisp); } } - else if (cu->ext1==0.0f && cu->ext2==0.0f) { + else if (cu->ext1 == 0.0f && cu->ext2 == 0.0f) { ; } - else if (cu->ext2==0.0f) { - dl= MEM_callocN(sizeof(DispList), "makebevelcurve2"); - dl->verts= MEM_mallocN(2*3*sizeof(float), "makebevelcurve2"); + 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); - dl->type= DL_SEGM; - dl->parts= 1; - dl->flag= DL_FRONT_CURVE|DL_BACK_CURVE; - dl->nr= 2; - - fp= dl->verts; - fp[0]= fp[1]= 0.0; - fp[2]= -cu->ext1; - fp[3]= fp[4]= 0.0; - fp[5]= cu->ext1; - } - else if ( (cu->flag & (CU_FRONT|CU_BACK))==0 && cu->ext1==0.0f) { // we make a full round bevel in that case - - nr= 4+ 2*cu->bevresol; - - dl= MEM_callocN(sizeof(DispList), "makebevelcurve p1"); - dl->verts= MEM_mallocN(nr*3*sizeof(float), "makebevelcurve p1"); + dl->type = DL_SEGM; + dl->parts = 1; + dl->flag = DL_FRONT_CURVE | DL_BACK_CURVE; + dl->nr = 2; + + fp = dl->verts; + fp[0] = fp[1] = 0.0; + fp[2] = -cu->ext1; + fp[3] = fp[4] = 0.0; + fp[5] = cu->ext1; + } + else if ( (cu->flag & (CU_FRONT | CU_BACK)) == 0 && cu->ext1 == 0.0f) { // we make a full round bevel in that case + nr = 4 + 2 * cu->bevresol; + + dl = MEM_callocN(sizeof(DispList), "makebevelcurve p1"); + dl->verts = MEM_mallocN(nr * 3 * sizeof(float), "makebevelcurve p1"); BLI_addtail(disp, dl); - dl->type= DL_POLY; - dl->parts= 1; - dl->flag= DL_BACK_CURVE; - dl->nr= nr; + dl->type = DL_POLY; + dl->parts = 1; + dl->flag = DL_BACK_CURVE; + dl->nr = nr; /* a circle */ - fp= dl->verts; - dangle= (2.0f*(float)M_PI/(nr)); - angle= -(nr-1)*dangle; - - for (a=0; a<nr; a++) { - fp[0]= 0.0; - fp[1]= (cosf(angle)*(cu->ext2)); - fp[2]= (sinf(angle)*(cu->ext2)) - cu->ext1; - angle+= dangle; - fp+= 3; + fp = dl->verts; + dangle = (2.0f * (float)M_PI / (nr)); + angle = -(nr - 1) * dangle; + + for (a = 0; a < nr; a++) { + fp[0] = 0.0; + fp[1] = (cosf(angle) * (cu->ext2)); + fp[2] = (sinf(angle) * (cu->ext2)) - cu->ext1; + angle += dangle; + fp += 3; } } else { short dnr; - + /* bevel now in three parts, for proper vertex normals */ /* part 1, back */ if ((cu->flag & CU_BACK) || !(cu->flag & CU_FRONT)) { - dnr= nr= 2+ cu->bevresol; - if ( (cu->flag & (CU_FRONT|CU_BACK))==0) - nr= 3+ 2*cu->bevresol; + dnr = nr = 2 + cu->bevresol; + if ( (cu->flag & (CU_FRONT | CU_BACK)) == 0) + nr = 3 + 2 * cu->bevresol; - dl= MEM_callocN(sizeof(DispList), "makebevelcurve p1"); - dl->verts= MEM_mallocN(nr*3*sizeof(float), "makebevelcurve p1"); + dl = MEM_callocN(sizeof(DispList), "makebevelcurve p1"); + dl->verts = MEM_mallocN(nr * 3 * sizeof(float), "makebevelcurve p1"); BLI_addtail(disp, dl); - dl->type= DL_SEGM; - dl->parts= 1; - dl->flag= DL_BACK_CURVE; - dl->nr= nr; + dl->type = DL_SEGM; + dl->parts = 1; + dl->flag = DL_BACK_CURVE; + dl->nr = nr; /* half a circle */ - fp= dl->verts; - dangle= (0.5*M_PI/(dnr-1)); - angle= -(nr-1)*dangle; + fp = dl->verts; + dangle = (0.5 * M_PI / (dnr - 1)); + angle = -(nr - 1) * dangle; - for (a=0; a<nr; a++) { - fp[0]= 0.0; - fp[1]= (float)(cosf(angle)*(cu->ext2)); - fp[2]= (float)(sinf(angle)*(cu->ext2)) - cu->ext1; - angle+= dangle; - fp+= 3; + for (a = 0; a < nr; a++) { + fp[0] = 0.0; + 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.0f) { - nr= 2; - - dl= MEM_callocN(sizeof(DispList), "makebevelcurve p2"); - dl->verts= MEM_callocN(nr*3*sizeof(float), "makebevelcurve p2"); + if (cu->ext1 != 0.0f) { + nr = 2; + + dl = MEM_callocN(sizeof(DispList), "makebevelcurve p2"); + dl->verts = MEM_callocN(nr * 3 * sizeof(float), "makebevelcurve p2"); BLI_addtail(disp, dl); - dl->type= DL_SEGM; - dl->parts= 1; - dl->nr= nr; - - fp= dl->verts; - fp[1]= cu->ext2; - fp[2]= -cu->ext1; - fp[4]= cu->ext2; - fp[5]= cu->ext1; - - if ( (cu->flag & (CU_FRONT|CU_BACK))==0) { - dl= MEM_dupallocN(dl); - dl->verts= MEM_dupallocN(dl->verts); + dl->type = DL_SEGM; + dl->parts = 1; + dl->nr = nr; + + fp = dl->verts; + fp[1] = cu->ext2; + fp[2] = -cu->ext1; + fp[4] = cu->ext2; + fp[5] = cu->ext1; + + if ( (cu->flag & (CU_FRONT | CU_BACK)) == 0) { + dl = MEM_dupallocN(dl); + dl->verts = MEM_dupallocN(dl->verts); BLI_addtail(disp, dl); - - fp= dl->verts; - fp[1]= -fp[1]; - fp[2]= -fp[2]; - fp[4]= -fp[4]; - fp[5]= -fp[5]; + + fp = dl->verts; + fp[1] = -fp[1]; + fp[2] = -fp[2]; + fp[4] = -fp[4]; + fp[5] = -fp[5]; } } - + /* part 3, front */ if ((cu->flag & CU_FRONT) || !(cu->flag & CU_BACK)) { - dnr= nr= 2+ cu->bevresol; - if ( (cu->flag & (CU_FRONT|CU_BACK))==0) - nr= 3+ 2*cu->bevresol; + dnr = nr = 2 + cu->bevresol; + if ( (cu->flag & (CU_FRONT | CU_BACK)) == 0) + nr = 3 + 2 * cu->bevresol; - dl= MEM_callocN(sizeof(DispList), "makebevelcurve p3"); - dl->verts= MEM_mallocN(nr*3*sizeof(float), "makebevelcurve p3"); + dl = MEM_callocN(sizeof(DispList), "makebevelcurve p3"); + dl->verts = MEM_mallocN(nr * 3 * sizeof(float), "makebevelcurve p3"); BLI_addtail(disp, dl); - dl->type= DL_SEGM; - dl->flag= DL_FRONT_CURVE; - dl->parts= 1; - dl->nr= nr; + dl->type = DL_SEGM; + dl->flag = DL_FRONT_CURVE; + dl->parts = 1; + dl->nr = nr; /* half a circle */ - fp= dl->verts; - angle= 0.0; - dangle= (0.5*M_PI/(dnr-1)); + fp = dl->verts; + angle = 0.0; + dangle = (0.5 * M_PI / (dnr - 1)); - for (a=0; a<nr; a++) { - fp[0]= 0.0; - fp[1]= (float)(cosf(angle)*(cu->ext2)); - fp[2]= (float)(sinf(angle)*(cu->ext2)) + cu->ext1; - angle+= dangle; - fp+= 3; + for (a = 0; a < nr; a++) { + fp[0] = 0.0; + fp[1] = (float)(cosf(angle) * (cu->ext2)); + fp[2] = (float)(sinf(angle) * (cu->ext2)) + cu->ext1; + angle += dangle; + fp += 3; } } } @@ -1521,25 +1595,27 @@ static int cu_isectLL(const float v1[3], const float v2[3], const float v3[3], c */ float deler; - deler= (v1[cox]-v2[cox])*(v3[coy]-v4[coy])-(v3[cox]-v4[cox])*(v1[coy]-v2[coy]); - if (deler==0.0f) return -1; + deler = (v1[cox] - v2[cox]) * (v3[coy] - v4[coy]) - (v3[cox] - v4[cox]) * (v1[coy] - v2[coy]); + 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); + *labda = (v1[coy] - v3[coy]) * (v3[cox] - v4[cox]) - (v1[cox] - v3[cox]) * (v3[coy] - v4[coy]); + *labda = -(*labda / deler); - deler= v3[coy]-v4[coy]; - if (deler==0) { - deler=v3[cox]-v4[cox]; - *mu= -(*labda*(v2[cox]-v1[cox])+v1[cox]-v3[cox])/deler; + deler = v3[coy] - v4[coy]; + if (deler == 0) { + deler = v3[cox] - v4[cox]; + *mu = -(*labda * (v2[cox] - v1[cox]) + v1[cox] - v3[cox]) / deler; } else { - *mu= -(*labda*(v2[coy]-v1[coy])+v1[coy]-v3[coy])/deler; + *mu = -(*labda * (v2[coy] - v1[coy]) + v1[coy] - v3[coy]) / deler; } - vec[cox]= *labda*(v2[cox]-v1[cox])+v1[cox]; - vec[coy]= *labda*(v2[coy]-v1[coy])+v1[coy]; + vec[cox] = *labda * (v2[cox] - v1[cox]) + v1[cox]; + vec[coy] = *labda * (v2[coy] - v1[coy]) + v1[coy]; - 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; + 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; @@ -1552,49 +1628,50 @@ static short bevelinside(BevList *bl1, BevList *bl2) /* returns '1' if correct hole */ BevPoint *bevp, *prevbevp; float min, max, vec[3], hvec1[3], hvec2[3], lab, mu; - int nr, links=0, rechts=0, mode; + int nr, links = 0, rechts = 0, mode; /* take first vertex of possible hole */ - bevp= (BevPoint *)(bl2+1); - hvec1[0]= bevp->vec[0]; - hvec1[1]= bevp->vec[1]; - hvec1[2]= 0.0; + bevp = (BevPoint *)(bl2 + 1); + hvec1[0] = bevp->vec[0]; + hvec1[1] = bevp->vec[1]; + hvec1[2] = 0.0; copy_v3_v3(hvec2, hvec1); - hvec2[0]+=1000; + hvec2[0] += 1000; /* test it with all edges of potential surounding poly */ /* count number of transitions left-right */ - bevp= (BevPoint *)(bl1+1); - nr= bl1->nr; - prevbevp= bevp+(nr-1); + bevp = (BevPoint *)(bl1 + 1); + nr = bl1->nr; + prevbevp = bevp + (nr - 1); while (nr--) { - min= prevbevp->vec[1]; - max= bevp->vec[1]; - if (max<min) { - min= max; - max= prevbevp->vec[1]; - } - if (min!=max) { - if (min<=hvec1[1] && max>=hvec1[1]) { + min = prevbevp->vec[1]; + max = bevp->vec[1]; + if (max < min) { + min = max; + max = prevbevp->vec[1]; + } + if (min != max) { + if (min <= hvec1[1] && max >= hvec1[1]) { /* there's a transition, calc intersection point */ - mode= cu_isectLL(prevbevp->vec, bevp->vec, hvec1, hvec2, 0, 1, &lab, &mu, vec); + mode = cu_isectLL(prevbevp->vec, bevp->vec, hvec1, hvec2, 0, 1, &lab, &mu, vec); /* if lab==0.0 or lab==1.0 then the edge intersects exactly a transition * only allow for one situation: we choose lab= 1.0 */ if (mode >= 0 && lab != 0.0f) { - if (vec[0]<hvec1[0]) links++; + if (vec[0] < hvec1[0]) links++; else rechts++; } } } - prevbevp= bevp; + prevbevp = bevp; bevp++; } - - if ( (links & 1) && (rechts & 1) ) return 1; + + if ( (links & 1) && (rechts & 1) ) + return 1; return 0; } @@ -1607,10 +1684,12 @@ struct bevelsort { static int vergxcobev(const void *a1, const void *a2) { - const struct bevelsort *x1=a1, *x2=a2; + const struct bevelsort *x1 = a1, *x2 = a2; - if ( x1->left > x2->left ) return 1; - else if ( x1->left < x2->left) return -1; + if (x1->left > x2->left) + return 1; + else if (x1->left < x2->left) + return -1; return 0; } @@ -1620,103 +1699,119 @@ static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2, float *si { float t01, t02, x3, y3; - t01= (float)sqrt(x1*x1+y1*y1); - t02= (float)sqrt(x2*x2+y2*y2); - if (t01==0.0f) t01= 1.0f; - if (t02==0.0f) t02= 1.0f; - - x1/=t01; - y1/=t01; - x2/=t02; - y2/=t02; - - t02= x1*x2+y1*y2; - if (fabs(t02)>=1.0) t02= .5*M_PI; - else t02= (saacos(t02))/2.0f; - - t02= (float)sin(t02); - if (t02==0.0f) t02= 1.0f; - - x3= x1-x2; - y3= y1-y2; - if (x3==0 && y3==0) { - x3= y1; - y3= -x1; + t01 = (float)sqrt(x1 * x1 + y1 * y1); + t02 = (float)sqrt(x2 * x2 + y2 * y2); + if (t01 == 0.0f) + t01 = 1.0f; + if (t02 == 0.0f) + t02 = 1.0f; + + x1 /= t01; + y1 /= t01; + x2 /= t02; + y2 /= t02; + + t02 = x1 * x2 + y1 * y2; + if (fabs(t02) >= 1.0) + t02 = .5 * M_PI; + else + t02 = (saacos(t02)) / 2.0f; + + t02 = (float)sin(t02); + if (t02 == 0.0f) + t02 = 1.0f; + + x3 = x1 - x2; + y3 = y1 - y2; + if (x3 == 0 && y3 == 0) { + x3 = y1; + y3 = -x1; } else { - t01= (float)sqrt(x3*x3+y3*y3); - x3/=t01; - y3/=t01; + t01 = (float)sqrt(x3 * x3 + y3 * y3); + x3 /= t01; + y3 /= t01; } - *sina= -y3/t02; - *cosa= x3/t02; + *sina = -y3 / t02; + *cosa = x3 / t02; } -static void alfa_bezpart(BezTriple *prevbezt, BezTriple *bezt, Nurb *nu, float *tilt_array, float *radius_array, float *weight_array, int resolu, int stride) +static void alfa_bezpart(BezTriple *prevbezt, BezTriple *bezt, Nurb *nu, float *tilt_array, float *radius_array, + float *weight_array, int resolu, int stride) { BezTriple *pprev, *next, *last; float fac, dfac, t[4]; int a; - - if (tilt_array==NULL && radius_array==NULL) + + if (tilt_array == NULL && radius_array == NULL) return; - - last= nu->bezt+(nu->pntsu-1); - + + last = nu->bezt + (nu->pntsu - 1); + /* returns a point */ - if (prevbezt==nu->bezt) { - if (nu->flagu & CU_NURB_CYCLIC) pprev= last; - else pprev= prevbezt; + if (prevbezt == nu->bezt) { + if (nu->flagu & CU_NURB_CYCLIC) + pprev = last; + else + pprev = prevbezt; } - else pprev= prevbezt-1; - + else + pprev = prevbezt - 1; + /* next point */ - if (bezt==last) { - if (nu->flagu & CU_NURB_CYCLIC) next= nu->bezt; - else next= bezt; - } - else next= bezt+1; - - fac= 0.0; - dfac= 1.0f/(float)resolu; - - for (a=0; a<resolu; a++, fac+= dfac) { + if (bezt == last) { + if (nu->flagu & CU_NURB_CYCLIC) + next = nu->bezt; + else + next = bezt; + } + else + next = bezt + 1; + + fac = 0.0; + dfac = 1.0f / (float)resolu; + + for (a = 0; a < resolu; a++, fac += dfac) { if (tilt_array) { - if (nu->tilt_interp==KEY_CU_EASE) { /* May as well support for tilt also 2.47 ease interp */ - *tilt_array = prevbezt->alfa + (bezt->alfa - prevbezt->alfa)*(3.0f*fac*fac - 2.0f*fac*fac*fac); + if (nu->tilt_interp == KEY_CU_EASE) { /* May as well support for tilt also 2.47 ease interp */ + *tilt_array = prevbezt->alfa + + (bezt->alfa - prevbezt->alfa) * (3.0f * fac * fac - 2.0f * fac * fac * fac); } else { key_curve_position_weights(fac, t, nu->tilt_interp); - *tilt_array= t[0]*pprev->alfa + t[1]*prevbezt->alfa + t[2]*bezt->alfa + t[3]*next->alfa; + *tilt_array = t[0] * pprev->alfa + t[1] * prevbezt->alfa + t[2] * bezt->alfa + t[3] * next->alfa; } - - tilt_array = (float *)(((char *)tilt_array) + stride); + + tilt_array = (float *)(((char *)tilt_array) + stride); } - + if (radius_array) { - if (nu->radius_interp==KEY_CU_EASE) { + if (nu->radius_interp == KEY_CU_EASE) { /* Support 2.47 ease interp * Note! - this only takes the 2 points into account, * giving much more localized results to changes in radius, sometimes you want that */ - *radius_array = prevbezt->radius + (bezt->radius - prevbezt->radius)*(3.0f*fac*fac - 2.0f*fac*fac*fac); + *radius_array = prevbezt->radius + + (bezt->radius - prevbezt->radius) * (3.0f * fac * fac - 2.0f * fac * fac * fac); } else { - + /* reuse interpolation from tilt if we can */ - if (tilt_array==NULL || nu->tilt_interp != nu->radius_interp) { + if (tilt_array == NULL || nu->tilt_interp != nu->radius_interp) { key_curve_position_weights(fac, t, nu->radius_interp); } - *radius_array= t[0]*pprev->radius + t[1]*prevbezt->radius + t[2]*bezt->radius + t[3]*next->radius; + *radius_array = t[0] * pprev->radius + t[1] * prevbezt->radius + + t[2] * bezt->radius + t[3] * next->radius; } - - radius_array = (float *)(((char *)radius_array) + stride); + + radius_array = (float *)(((char *)radius_array) + stride); } if (weight_array) { /* basic interpolation for now, could copy tilt interp too */ - *weight_array = prevbezt->weight + (bezt->weight - prevbezt->weight)*(3.0f*fac*fac - 2.0f*fac*fac*fac); + *weight_array = prevbezt->weight + + (bezt->weight - prevbezt->weight) * (3.0f * fac * fac - 2.0f * fac * fac * fac); weight_array = (float *)(((char *)weight_array) + stride); } @@ -1732,35 +1827,36 @@ static void bevel_list_cyclic_fix_3D(BevList *bl) { BevPoint *bevp, *bevp1; - bevp= (BevPoint *)(bl+1); - bevp1= bevp+1; + bevp = (BevPoint *)(bl + 1); + bevp1 = bevp + 1; copy_qt_qt(bevp->quat, bevp1->quat); copy_v3_v3(bevp->dir, bevp1->dir); copy_v3_v3(bevp->tan, bevp1->tan); - bevp= (BevPoint *)(bl+1); - bevp+= (bl->nr-1); - bevp1= bevp-1; + bevp = (BevPoint *)(bl + 1); + bevp += (bl->nr - 1); + bevp1 = bevp - 1; copy_qt_qt(bevp->quat, bevp1->quat); copy_v3_v3(bevp->dir, bevp1->dir); copy_v3_v3(bevp->tan, bevp1->tan); } + /* utility for make_bevel_list_3D_* funcs */ static void bevel_list_calc_bisect(BevList *bl) { BevPoint *bevp2, *bevp1, *bevp0; int nr; - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); - bevp0= bevp1-1; + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); + bevp0 = bevp1 - 1; - nr= bl->nr; + nr = bl->nr; while (nr--) { /* totally simple */ bisect_v3_v3v3v3(bevp1->dir, bevp0->vec, bevp1->vec, bevp2->vec); - bevp0= bevp1; - bevp1= bevp2; + bevp0 = bevp1; + bevp1 = bevp2; bevp2++; } } @@ -1769,17 +1865,17 @@ static void bevel_list_flip_tangents(BevList *bl) BevPoint *bevp2, *bevp1, *bevp0; int nr; - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); - bevp0= bevp1-1; + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); + bevp0 = bevp1 - 1; - nr= bl->nr; + nr = bl->nr; while (nr--) { if (RAD2DEGF(angle_v2v2(bevp0->tan, bevp1->tan)) > 90.0f) negate_v3(bevp1->tan); - bevp0= bevp1; - bevp1= bevp2; + bevp0 = bevp1; + bevp1 = bevp2; bevp2++; } } @@ -1790,16 +1886,16 @@ static void bevel_list_apply_tilt(BevList *bl) int nr; float q[4]; - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); - nr= bl->nr; + nr = bl->nr; while (nr--) { axis_angle_to_quat(q, bevp1->dir, bevp1->alfa); mul_qt_qtqt(bevp1->quat, q, bevp1->quat); normalize_qt(bevp1->quat); - bevp1= bevp2; + bevp1 = bevp2; bevp2++; } } @@ -1813,26 +1909,24 @@ static void bevel_list_smooth(BevList *bl, int smooth_iter) float bevp0_quat[4]; int a; - for (a=0; a < smooth_iter; a++) { - - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); - bevp0= bevp1-1; + for (a = 0; a < smooth_iter; a++) { + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); + bevp0 = bevp1 - 1; - nr= bl->nr; + nr = bl->nr; - if (bl->poly== -1) { /* check its not cyclic */ + if (bl->poly == -1) { /* check its not cyclic */ /* skip the first point */ /* bevp0= bevp1; */ - bevp1= bevp2; + bevp1 = bevp2; bevp2++; nr--; - bevp0= bevp1; - bevp1= bevp2; + bevp0 = bevp1; + bevp1 = bevp2; bevp2++; nr--; - } copy_qt_qt(bevp0_quat, bevp0->quat); @@ -1853,9 +1947,8 @@ static void bevel_list_smooth(BevList *bl, int smooth_iter) interp_qt_qtqt(bevp1->quat, bevp1->quat, q, 0.5); normalize_qt(bevp1->quat); - /* bevp0= bevp1; */ /* UNUSED */ - bevp1= bevp2; + bevp1 = bevp2; bevp2++; } } @@ -1866,18 +1959,18 @@ static void make_bevel_list_3D_zup(BevList *bl) BevPoint *bevp2, *bevp1, *bevp0; /* standard for all make_bevel_list_3D_* funcs */ int nr; - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); - bevp0= bevp1-1; + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); + bevp0 = bevp1 - 1; - nr= bl->nr; + nr = bl->nr; while (nr--) { /* totally simple */ bisect_v3_v3v3v3(bevp1->dir, bevp0->vec, bevp1->vec, bevp2->vec); vec_to_quat(bevp1->quat, bevp1->dir, 5, 1); - bevp0= bevp1; - bevp1= bevp2; + bevp0 = bevp1; + bevp1 = bevp2; bevp2++; } } @@ -1890,18 +1983,18 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl) bevel_list_calc_bisect(bl); - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); - bevp0= bevp1-1; + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); + bevp0 = bevp1 - 1; - nr= bl->nr; + nr = bl->nr; while (nr--) { - if (nr+4 > bl->nr) { /* first time and second time, otherwise first point adjusts last */ + if (nr + 4 > bl->nr) { /* first time and second time, otherwise first point adjusts last */ vec_to_quat(bevp1->quat, bevp1->dir, 5, 1); } else { - float angle= angle_normalized_v3v3(bevp0->dir, bevp1->dir); + float angle = angle_normalized_v3v3(bevp0->dir, bevp1->dir); if (angle > 0.0f) { /* otherwise we can keep as is */ float cross_tmp[3]; @@ -1914,8 +2007,8 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl) } } - bevp0= bevp1; - bevp1= bevp2; + bevp0 = bevp1; + bevp1 = bevp2; bevp2++; } @@ -1932,14 +2025,14 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl) * * this is why we compare last with second last * */ - float vec_1[3]= {0, 1, 0}, vec_2[3]= {0, 1, 0}, angle, ang_fac, cross_tmp[3]; + float vec_1[3] = {0, 1, 0}, vec_2[3] = {0, 1, 0}, angle, ang_fac, cross_tmp[3]; BevPoint *bevp_first; BevPoint *bevp_last; - bevp_first= (BevPoint *)(bl+1); - bevp_first+= bl->nr-1; + bevp_first = (BevPoint *)(bl + 1); + bevp_first += bl->nr - 1; bevp_last = bevp_first; bevp_last--; @@ -1950,7 +2043,7 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl) normalize_v3(vec_2); /* align the vector, can avoid this and it looks 98% OK but - * better to align the angle quat roll's before comparing */ + * better to align the angle quat roll's before comparing */ { cross_v3_v3v3(cross_tmp, bevp_last->dir, bevp_first->dir); angle = angle_normalized_v3v3(bevp_first->dir, bevp_last->dir); @@ -1958,7 +2051,7 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl) mul_qt_v3(q, vec_2); } - angle= angle_normalized_v3v3(vec_1, vec_2); + angle = angle_normalized_v3v3(vec_1, vec_2); /* flip rotation if needs be */ cross_v3_v3v3(cross_tmp, vec_1, vec_2); @@ -1966,19 +2059,19 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl) if (angle_normalized_v3v3(bevp_first->dir, cross_tmp) < DEG2RADF(90.0f)) angle = -angle; - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); - bevp0= bevp1-1; + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); + bevp0 = bevp1 - 1; - nr= bl->nr; + nr = bl->nr; while (nr--) { - ang_fac= angle * (1.0f-((float)nr/bl->nr)); /* also works */ + ang_fac = angle * (1.0f - ((float)nr / bl->nr)); /* also works */ axis_angle_to_quat(q, bevp1->dir, ang_fac); mul_qt_qtqt(bevp1->quat, q, bevp1->quat); - bevp0= bevp1; - bevp1= bevp2; + bevp0 = bevp1; + bevp1 = bevp2; bevp2++; } } @@ -1992,38 +2085,36 @@ static void make_bevel_list_3D_tangent(BevList *bl) float bevp0_tan[3], cross_tmp[3]; bevel_list_calc_bisect(bl); - if (bl->poly== -1) /* check its not cyclic */ - bevel_list_cyclic_fix_3D(bl); // XXX - run this now so tangents will be right before doing the flipping + if (bl->poly == -1) /* check its not cyclic */ + bevel_list_cyclic_fix_3D(bl); // XXX - run this now so tangents will be right before doing the flipping bevel_list_flip_tangents(bl); /* correct the tangents */ - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); - bevp0= bevp1-1; + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); + bevp0 = bevp1 - 1; - nr= bl->nr; + nr = bl->nr; while (nr--) { - cross_v3_v3v3(cross_tmp, bevp1->tan, bevp1->dir); cross_v3_v3v3(bevp1->tan, cross_tmp, bevp1->dir); normalize_v3(bevp1->tan); - bevp0= bevp1; - bevp1= bevp2; + bevp0 = bevp1; + bevp1 = bevp2; bevp2++; } /* now for the real twist calc */ - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); - bevp0= bevp1-1; + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); + bevp0 = bevp1 - 1; copy_v3_v3(bevp0_tan, bevp0->tan); - nr= bl->nr; + nr = bl->nr; while (nr--) { - /* make perpendicular, modify tan in place, is ok */ float cross_tmp[3]; float zero[3] = {0, 0, 0}; @@ -2033,7 +2124,7 @@ static void make_bevel_list_3D_tangent(BevList *bl) tri_to_quat(bevp1->quat, zero, cross_tmp, bevp1->tan); /* XXX - could be faster */ /* bevp0= bevp1; */ /* UNUSED */ - bevp1= bevp2; + bevp1 = bevp2; bevp2++; } } @@ -2041,17 +2132,17 @@ static void make_bevel_list_3D_tangent(BevList *bl) static void make_bevel_list_3D(BevList *bl, int smooth_iter, int twist_mode) { switch (twist_mode) { - case CU_TWIST_TANGENT: - make_bevel_list_3D_tangent(bl); - break; - case CU_TWIST_MINIMUM: - make_bevel_list_3D_minimum_twist(bl); - break; - default: /* CU_TWIST_Z_UP default, pre 2.49c */ - make_bevel_list_3D_zup(bl); + case CU_TWIST_TANGENT: + make_bevel_list_3D_tangent(bl); + break; + case CU_TWIST_MINIMUM: + make_bevel_list_3D_minimum_twist(bl); + break; + default: /* CU_TWIST_Z_UP default, pre 2.49c */ + make_bevel_list_3D_zup(bl); } - if (bl->poly== -1) /* check its not cyclic */ + if (bl->poly == -1) /* check its not cyclic */ bevel_list_cyclic_fix_3D(bl); if (smooth_iter) @@ -2060,15 +2151,13 @@ static void make_bevel_list_3D(BevList *bl, int smooth_iter, int twist_mode) bevel_list_apply_tilt(bl); } - - /* only for 2 points */ static void make_bevel_list_segment_3D(BevList *bl) { float q[4]; - BevPoint *bevp2= (BevPoint *)(bl+1); - BevPoint *bevp1= bevp2+1; + BevPoint *bevp2 = (BevPoint *)(bl + 1); + BevPoint *bevp1 = bevp2 + 1; /* simple quat/dir */ sub_v3_v3v3(bevp1->dir, bevp1->vec, bevp2->vec); @@ -2083,8 +2172,6 @@ static void make_bevel_list_segment_3D(BevList *bl) copy_qt_qt(bevp2->quat, bevp1->quat); } - - void BKE_curve_bevelList_make(Object *ob) { /* @@ -2103,160 +2190,162 @@ void BKE_curve_bevelList_make(Object *ob) struct bevelsort *sortdata, *sd, *sd1; int a, b, nr, poly, resolu = 0, len = 0; int do_tilt, do_radius, do_weight; - + /* this function needs an object, because of tflag and upflag */ - cu= ob->data; + cu = ob->data; /* do we need to calculate the radius for each point? */ /* do_radius = (cu->bevobj || cu->taperobj || (cu->flag & CU_FRONT) || (cu->flag & CU_BACK)) ? 0 : 1; */ - + /* STEP 1: MAKE POLYS */ BLI_freelistN(&(cu->bev)); - if (cu->editnurb && ob->type!=OB_FONT) { - ListBase *nurbs= BKE_curve_editNurbs_get(cu); + if (cu->editnurb && ob->type != OB_FONT) { + ListBase *nurbs = BKE_curve_editNurbs_get(cu); nu = nurbs->first; } else { nu = cu->nurb.first; } - + while (nu) { - /* check if we will calculate tilt data */ do_tilt = CU_DO_TILT(cu, nu); do_radius = CU_DO_RADIUS(cu, nu); /* normal display uses the radius, better just to calculate them */ do_weight = 1; - + /* check we are a single point? also check we are not a surface and that the orderu is sane, * enforced in the UI but can go wrong possibly */ if (!BKE_nurb_check_valid_u(nu)) { - bl= MEM_callocN(sizeof(BevList)+1*sizeof(BevPoint), "makeBevelList1"); + bl = MEM_callocN(sizeof(BevList) + 1 * sizeof(BevPoint), "makeBevelList1"); BLI_addtail(&(cu->bev), bl); - bl->nr= 0; + bl->nr = 0; } else { - if (G.rendering && cu->resolu_ren!=0) - resolu= cu->resolu_ren; + if (G.rendering && cu->resolu_ren != 0) + resolu = cu->resolu_ren; else - resolu= nu->resolu; - + resolu = nu->resolu; + if (nu->type == CU_POLY) { - len= nu->pntsu; - bl= MEM_callocN(sizeof(BevList)+len*sizeof(BevPoint), "makeBevelList2"); + len = nu->pntsu; + bl = MEM_callocN(sizeof(BevList) + len * sizeof(BevPoint), "makeBevelList2"); BLI_addtail(&(cu->bev), bl); - - if (nu->flagu & CU_NURB_CYCLIC) bl->poly= 0; - else bl->poly= -1; - bl->nr= len; - bl->dupe_nr= 0; - bevp= (BevPoint *)(bl+1); - bp= nu->bp; - + + if (nu->flagu & CU_NURB_CYCLIC) bl->poly = 0; + else bl->poly = -1; + bl->nr = len; + bl->dupe_nr = 0; + bevp = (BevPoint *)(bl + 1); + bp = nu->bp; + while (len--) { copy_v3_v3(bevp->vec, bp->vec); - bevp->alfa= bp->alfa; - bevp->radius= bp->radius; - bevp->weight= bp->weight; - bevp->split_tag= TRUE; + bevp->alfa = bp->alfa; + bevp->radius = bp->radius; + bevp->weight = bp->weight; + bevp->split_tag = TRUE; bevp++; bp++; } } else if (nu->type == CU_BEZIER) { - - len= resolu*(nu->pntsu+ (nu->flagu & CU_NURB_CYCLIC) -1)+1; /* in case last point is not cyclic */ - bl= MEM_callocN(sizeof(BevList)+len*sizeof(BevPoint), "makeBevelBPoints"); + /* in case last point is not cyclic */ + len = resolu * (nu->pntsu + (nu->flagu & CU_NURB_CYCLIC) - 1) + 1; + bl = MEM_callocN(sizeof(BevList) + len * sizeof(BevPoint), "makeBevelBPoints"); BLI_addtail(&(cu->bev), bl); - - if (nu->flagu & CU_NURB_CYCLIC) bl->poly= 0; - else bl->poly= -1; - bevp= (BevPoint *)(bl+1); - - a= nu->pntsu-1; - bezt= nu->bezt; + + if (nu->flagu & CU_NURB_CYCLIC) bl->poly = 0; + else bl->poly = -1; + bevp = (BevPoint *)(bl + 1); + + a = nu->pntsu - 1; + bezt = nu->bezt; if (nu->flagu & CU_NURB_CYCLIC) { a++; - prevbezt= nu->bezt+(nu->pntsu-1); + prevbezt = nu->bezt + (nu->pntsu - 1); } else { - prevbezt= bezt; + prevbezt = bezt; bezt++; } - + while (a--) { - if (prevbezt->h2==HD_VECT && bezt->h1==HD_VECT) { + if (prevbezt->h2 == HD_VECT && bezt->h1 == HD_VECT) { copy_v3_v3(bevp->vec, prevbezt->vec[1]); - bevp->alfa= prevbezt->alfa; - bevp->radius= prevbezt->radius; - bevp->weight= prevbezt->weight; - bevp->split_tag= TRUE; - bevp->dupe_tag= FALSE; + bevp->alfa = prevbezt->alfa; + bevp->radius = prevbezt->radius; + bevp->weight = prevbezt->weight; + bevp->split_tag = TRUE; + bevp->dupe_tag = FALSE; bevp++; bl->nr++; - bl->dupe_nr= 1; + bl->dupe_nr = 1; } else { /* always do all three, to prevent data hanging around */ int j; - + /* BevPoint must stay aligned to 4 so sizeof(BevPoint)/sizeof(float) works */ - for (j=0; j<3; j++) { + for (j = 0; j < 3; j++) { BKE_curve_forward_diff_bezier(prevbezt->vec[1][j], prevbezt->vec[2][j], bezt->vec[0][j], bezt->vec[1][j], &(bevp->vec[j]), resolu, sizeof(BevPoint)); } - + /* if both arrays are NULL do nothiong */ alfa_bezpart(prevbezt, bezt, nu, - do_tilt ? &bevp->alfa : NULL, - do_radius ? &bevp->radius : NULL, - do_weight ? &bevp->weight : NULL, + do_tilt ? &bevp->alfa : NULL, + do_radius ? &bevp->radius : NULL, + do_weight ? &bevp->weight : NULL, resolu, sizeof(BevPoint)); - - if (cu->twist_mode==CU_TWIST_TANGENT) { + + if (cu->twist_mode == CU_TWIST_TANGENT) { forward_diff_bezier_cotangent(prevbezt->vec[1], prevbezt->vec[2], bezt->vec[0], bezt->vec[1], bevp->tan, resolu, sizeof(BevPoint)); } /* indicate with handlecodes double points */ - if (prevbezt->h1==prevbezt->h2) { - if (prevbezt->h1==0 || prevbezt->h1==HD_VECT) bevp->split_tag= TRUE; + if (prevbezt->h1 == prevbezt->h2) { + if (prevbezt->h1 == 0 || prevbezt->h1 == HD_VECT) + bevp->split_tag = TRUE; } else { - if (prevbezt->h1==0 || prevbezt->h1==HD_VECT) bevp->split_tag= TRUE; - else if (prevbezt->h2==0 || prevbezt->h2==HD_VECT) bevp->split_tag= TRUE; + if (prevbezt->h1 == 0 || prevbezt->h1 == HD_VECT) + bevp->split_tag = TRUE; + else if (prevbezt->h2 == 0 || prevbezt->h2 == HD_VECT) + bevp->split_tag = TRUE; } - bl->nr+= resolu; - bevp+= resolu; + bl->nr += resolu; + bevp += resolu; } - prevbezt= bezt; + prevbezt = bezt; bezt++; } - - if ((nu->flagu & CU_NURB_CYCLIC)==0) { /* not cyclic: endpoint */ + + if ((nu->flagu & CU_NURB_CYCLIC) == 0) { /* not cyclic: endpoint */ copy_v3_v3(bevp->vec, prevbezt->vec[1]); - bevp->alfa= prevbezt->alfa; - bevp->radius= prevbezt->radius; - bevp->weight= prevbezt->weight; + bevp->alfa = prevbezt->alfa; + bevp->radius = prevbezt->radius; + bevp->weight = prevbezt->weight; bl->nr++; } } else if (nu->type == CU_NURBS) { - if (nu->pntsv==1) { - len= (resolu*SEGMENTSU(nu)); - - bl= MEM_callocN(sizeof(BevList)+len*sizeof(BevPoint), "makeBevelList3"); + if (nu->pntsv == 1) { + len = (resolu * SEGMENTSU(nu)); + + bl = MEM_callocN(sizeof(BevList) + len * sizeof(BevPoint), "makeBevelList3"); BLI_addtail(&(cu->bev), bl); - bl->nr= len; - bl->dupe_nr= 0; - if (nu->flagu & CU_NURB_CYCLIC) bl->poly= 0; - else bl->poly= -1; - bevp= (BevPoint *)(bl+1); - + bl->nr = len; + bl->dupe_nr = 0; + if (nu->flagu & CU_NURB_CYCLIC) bl->poly = 0; + else bl->poly = -1; + bevp = (BevPoint *)(bl + 1); + BKE_nurb_makeCurve(nu, &bevp->vec[0], do_tilt ? &bevp->alfa : NULL, do_radius ? &bevp->radius : NULL, @@ -2265,47 +2354,47 @@ void BKE_curve_bevelList_make(Object *ob) } } } - nu= nu->next; + nu = nu->next; } /* STEP 2: DOUBLE POINTS AND AUTOMATIC RESOLUTION, REDUCE DATABLOCKS */ - bl= cu->bev.first; + bl = cu->bev.first; while (bl) { if (bl->nr) { /* null bevel items come from single points */ - nr= bl->nr; - bevp1= (BevPoint *)(bl+1); - bevp0= bevp1+(nr-1); + nr = bl->nr; + bevp1 = (BevPoint *)(bl + 1); + bevp0 = bevp1 + (nr - 1); nr--; while (nr--) { - if ( fabs(bevp0->vec[0]-bevp1->vec[0])<0.00001 ) { - if ( fabs(bevp0->vec[1]-bevp1->vec[1])<0.00001 ) { - if ( fabs(bevp0->vec[2]-bevp1->vec[2])<0.00001 ) { - bevp0->dupe_tag= TRUE; + if (fabs(bevp0->vec[0] - bevp1->vec[0]) < 0.00001) { + if (fabs(bevp0->vec[1] - bevp1->vec[1]) < 0.00001) { + if (fabs(bevp0->vec[2] - bevp1->vec[2]) < 0.00001) { + bevp0->dupe_tag = TRUE; bl->dupe_nr++; } } } - bevp0= bevp1; + bevp0 = bevp1; bevp1++; } } - bl= bl->next; + bl = bl->next; } - bl= cu->bev.first; + bl = cu->bev.first; while (bl) { - blnext= bl->next; + blnext = bl->next; if (bl->nr && bl->dupe_nr) { - nr= bl->nr- bl->dupe_nr+1; /* +1 because vectorbezier sets flag too */ - blnew= MEM_mallocN(sizeof(BevList)+nr*sizeof(BevPoint), "makeBevelList4"); + nr = bl->nr - bl->dupe_nr + 1; /* +1 because vectorbezier sets flag too */ + blnew = MEM_mallocN(sizeof(BevList) + nr * sizeof(BevPoint), "makeBevelList4"); memcpy(blnew, bl, sizeof(BevList)); - blnew->nr= 0; + blnew->nr = 0; BLI_remlink(&(cu->bev), bl); - BLI_insertlinkbefore(&(cu->bev), blnext, blnew); /* to make sure bevlijst is tuned with nurblist */ - bevp0= (BevPoint *)(bl+1); - bevp1= (BevPoint *)(blnew+1); - nr= bl->nr; + BLI_insertlinkbefore(&(cu->bev), blnext, blnew); /* to make sure bevlijst is tuned with nurblist */ + bevp0 = (BevPoint *)(bl + 1); + bevp1 = (BevPoint *)(blnew + 1); + nr = bl->nr; while (nr--) { - if (bevp0->dupe_tag==0) { + if (bevp0->dupe_tag == 0) { memcpy(bevp1, bevp0, sizeof(BevPoint)); bevp1++; blnew->nr++; @@ -2313,84 +2402,90 @@ void BKE_curve_bevelList_make(Object *ob) bevp0++; } MEM_freeN(bl); - blnew->dupe_nr= 0; + blnew->dupe_nr = 0; } - bl= blnext; + bl = blnext; } /* STEP 3: POLYS COUNT AND AUTOHOLE */ - bl= cu->bev.first; - poly= 0; + bl = cu->bev.first; + poly = 0; while (bl) { - if (bl->nr && bl->poly>=0) { + if (bl->nr && bl->poly >= 0) { poly++; - bl->poly= poly; - bl->hole= 0; + bl->poly = poly; + bl->hole = 0; } - bl= bl->next; + bl = bl->next; } - /* find extreme left points, also test (turning) direction */ - if (poly>0) { - sd= sortdata= MEM_mallocN(sizeof(struct bevelsort)*poly, "makeBevelList5"); - bl= cu->bev.first; + if (poly > 0) { + sd = sortdata = MEM_mallocN(sizeof(struct bevelsort) * poly, "makeBevelList5"); + bl = cu->bev.first; while (bl) { - if (bl->poly>0) { + if (bl->poly > 0) { - min= 300000.0; - bevp= (BevPoint *)(bl+1); - nr= bl->nr; + min = 300000.0; + bevp = (BevPoint *)(bl + 1); + nr = bl->nr; while (nr--) { - if (min>bevp->vec[0]) { - min= bevp->vec[0]; - bevp1= bevp; + if (min > bevp->vec[0]) { + min = bevp->vec[0]; + bevp1 = bevp; } bevp++; } - sd->bl= bl; - sd->left= min; + sd->bl = bl; + sd->left = min; - bevp= (BevPoint *)(bl+1); - if (bevp1== bevp) bevp0= bevp+ (bl->nr-1); - else bevp0= bevp1-1; - bevp= bevp+ (bl->nr-1); - if (bevp1== bevp) bevp2= (BevPoint *)(bl+1); - else bevp2= bevp1+1; + bevp = (BevPoint *)(bl + 1); + if (bevp1 == bevp) + bevp0 = bevp + (bl->nr - 1); + else + bevp0 = bevp1 - 1; + bevp = bevp + (bl->nr - 1); + if (bevp1 == bevp) + bevp2 = (BevPoint *)(bl + 1); + else + bevp2 = bevp1 + 1; - 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]); + 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.0f) sd->dir= 1; - else sd->dir= 0; + if (inp > 0.0f) + sd->dir = 1; + else + sd->dir = 0; sd++; } - bl= bl->next; + bl = bl->next; } qsort(sortdata, poly, sizeof(struct bevelsort), vergxcobev); - sd= sortdata+1; - for (a=1; a<poly; a++, sd++) { - bl= sd->bl; /* is bl a hole? */ - sd1= sortdata+ (a-1); - for (b=a-1; b>=0; b--, sd1--) { /* all polys to the left */ + sd = sortdata + 1; + for (a = 1; a < poly; a++, sd++) { + bl = sd->bl; /* is bl a hole? */ + sd1 = sortdata + (a - 1); + for (b = a - 1; b >= 0; b--, sd1--) { /* all polys to the left */ if (bevelinside(sd1->bl, bl)) { - bl->hole= 1- sd1->bl->hole; + bl->hole = 1 - sd1->bl->hole; break; } } } /* turning direction */ - if ((cu->flag & CU_3D)==0) { - sd= sortdata; - for (a=0; a<poly; a++, sd++) { - if (sd->bl->hole==sd->dir) { - bl= sd->bl; - bevp1= (BevPoint *)(bl+1); - bevp2= bevp1+ (bl->nr-1); - nr= bl->nr/2; + if ((cu->flag & CU_3D) == 0) { + sd = sortdata; + for (a = 0; a < poly; a++, sd++) { + if (sd->bl->hole == sd->dir) { + bl = sd->bl; + bevp1 = (BevPoint *)(bl + 1); + bevp2 = bevp1 + (bl->nr - 1); + nr = bl->nr / 2; while (nr--) { SWAP(BevPoint, *bevp1, *bevp2); bevp1++; @@ -2403,40 +2498,40 @@ void BKE_curve_bevelList_make(Object *ob) } /* STEP 4: 2D-COSINES or 3D ORIENTATION */ - if ((cu->flag & CU_3D)==0) { + if ((cu->flag & CU_3D) == 0) { /* note: bevp->dir and bevp->quat are not needed for beveling but are * used when making a path from a 2D curve, therefor they need to be set - Campbell */ - bl= cu->bev.first; + bl = cu->bev.first; while (bl) { if (bl->nr < 2) { /* do nothing */ } - else if (bl->nr==2) { /* 2 pnt, treat separate */ - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+1; + else if (bl->nr == 2) { /* 2 pnt, treat separate */ + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + 1; - x1= bevp1->vec[0]- bevp2->vec[0]; - y1= bevp1->vec[1]- bevp2->vec[1]; + x1 = bevp1->vec[0] - bevp2->vec[0]; + y1 = bevp1->vec[1] - bevp2->vec[1]; calc_bevel_sin_cos(x1, y1, -x1, -y1, &(bevp1->sina), &(bevp1->cosa)); - bevp2->sina= bevp1->sina; - bevp2->cosa= bevp1->cosa; + bevp2->sina = bevp1->sina; + bevp2->cosa = bevp1->cosa; /* fill in dir & quat */ make_bevel_list_segment_3D(bl); } else { - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); - bevp0= bevp1-1; + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); + bevp0 = bevp1 - 1; - nr= bl->nr; + nr = bl->nr; while (nr--) { - x1= bevp1->vec[0]- bevp0->vec[0]; - x2= bevp1->vec[0]- bevp2->vec[0]; - y1= bevp1->vec[1]- bevp0->vec[1]; - y2= bevp1->vec[1]- bevp2->vec[1]; + x1 = bevp1->vec[0] - bevp0->vec[0]; + x2 = bevp1->vec[0] - bevp2->vec[0]; + y1 = bevp1->vec[1] - bevp0->vec[1]; + y2 = bevp1->vec[1] - bevp2->vec[1]; calc_bevel_sin_cos(x1, y1, x2, y2, &(bevp1->sina), &(bevp1->cosa)); @@ -2446,44 +2541,44 @@ void BKE_curve_bevelList_make(Object *ob) vec_to_quat(bevp1->quat, bevp1->dir, 5, 1); /* done with inline make_bevel_list_3D_zup */ - bevp0= bevp1; - bevp1= bevp2; + bevp0 = bevp1; + bevp1 = bevp2; bevp2++; } /* correct non-cyclic cases */ - if (bl->poly== -1) { - bevp= (BevPoint *)(bl+1); - bevp1= bevp+1; - bevp->sina= bevp1->sina; - bevp->cosa= bevp1->cosa; - bevp= (BevPoint *)(bl+1); - bevp+= (bl->nr-1); - bevp1= bevp-1; - bevp->sina= bevp1->sina; - bevp->cosa= bevp1->cosa; + if (bl->poly == -1) { + bevp = (BevPoint *)(bl + 1); + bevp1 = bevp + 1; + bevp->sina = bevp1->sina; + bevp->cosa = bevp1->cosa; + bevp = (BevPoint *)(bl + 1); + bevp += (bl->nr - 1); + bevp1 = bevp - 1; + bevp->sina = bevp1->sina; + bevp->cosa = bevp1->cosa; /* correct for the dir/quat, see above why its needed */ bevel_list_cyclic_fix_3D(bl); } } - bl= bl->next; + bl = bl->next; } } else { /* 3D Curves */ - bl= cu->bev.first; + bl = cu->bev.first; while (bl) { if (bl->nr < 2) { /* do nothing */ } - else if (bl->nr==2) { /* 2 pnt, treat separate */ + else if (bl->nr == 2) { /* 2 pnt, treat separate */ make_bevel_list_segment_3D(bl); } else { - make_bevel_list_3D(bl, (int)(resolu*cu->twist_smooth), cu->twist_mode); + make_bevel_list_3D(bl, (int)(resolu * cu->twist_smooth), cu->twist_mode); } - bl= bl->next; + bl = bl->next; } } } @@ -2501,111 +2596,113 @@ static void calchandleNurb_intern(BezTriple *bezt, BezTriple *prev, BezTriple *n float *p1, *p2, *p3, pt[3]; float dvec_a[3], dvec_b[3]; float len, len_a, len_b; - const float eps= 1e-5; + const float eps = 1e-5; - if (bezt->h1==0 && bezt->h2==0) { + if (bezt->h1 == 0 && bezt->h2 == 0) { return; } - p2= bezt->vec[1]; + p2 = bezt->vec[1]; - if (prev==NULL) { - p3= next->vec[1]; - pt[0]= 2.0f*p2[0] - p3[0]; - pt[1]= 2.0f*p2[1] - p3[1]; - pt[2]= 2.0f*p2[2] - p3[2]; - p1= pt; + if (prev == NULL) { + p3 = next->vec[1]; + pt[0] = 2.0f * p2[0] - p3[0]; + pt[1] = 2.0f * p2[1] - p3[1]; + pt[2] = 2.0f * p2[2] - p3[2]; + p1 = pt; } else { - p1= prev->vec[1]; + p1 = prev->vec[1]; } - if (next==NULL) { - pt[0]= 2.0f*p2[0] - p1[0]; - pt[1]= 2.0f*p2[1] - p1[1]; - pt[2]= 2.0f*p2[2] - p1[2]; - p3= pt; + if (next == NULL) { + pt[0] = 2.0f * p2[0] - p1[0]; + pt[1] = 2.0f * p2[1] - p1[1]; + pt[2] = 2.0f * p2[2] - p1[2]; + p3 = pt; } else { - p3= next->vec[1]; + p3 = next->vec[1]; } sub_v3_v3v3(dvec_a, p2, p1); sub_v3_v3v3(dvec_b, p3, p2); if (mode != 0) { - len_a= dvec_a[0]; - len_b= dvec_b[0]; + len_a = dvec_a[0]; + len_b = dvec_b[0]; } else { - len_a= len_v3(dvec_a); - len_b= len_v3(dvec_b); + len_a = len_v3(dvec_a); + len_b = len_v3(dvec_b); } - if (len_a==0.0f) len_a=1.0f; - if (len_b==0.0f) len_b=1.0f; + if (len_a == 0.0f) len_a = 1.0f; + if (len_b == 0.0f) len_b = 1.0f; if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM) || ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM)) { /* auto */ float tvec[3]; - tvec[0]= dvec_b[0]/len_b + dvec_a[0]/len_a; - tvec[1]= dvec_b[1]/len_b + dvec_a[1]/len_a; - tvec[2]= dvec_b[2]/len_b + dvec_a[2]/len_a; - len= len_v3(tvec) * 2.5614f; - - if (len!=0.0f) { - int leftviolate=0, rightviolate=0; /* for mode==2 */ - - if (len_a>5.0f*len_b) len_a= 5.0f*len_b; - if (len_b>5.0f*len_a) len_b= 5.0f*len_a; - + tvec[0] = dvec_b[0] / len_b + dvec_a[0] / len_a; + tvec[1] = dvec_b[1] / len_b + dvec_a[1] / len_a; + tvec[2] = dvec_b[2] / len_b + dvec_a[2] / len_a; + len = len_v3(tvec) * 2.5614f; + + if (len != 0.0f) { + int leftviolate = 0, rightviolate = 0; /* for mode==2 */ + + if (len_a > 5.0f * len_b) + len_a = 5.0f * len_b; + if (len_b > 5.0f * len_a) + len_b = 5.0f * len_a; + if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM)) { - len_a/=len; - madd_v3_v3v3fl(p2-3, p2, tvec, -len_a); - - if ((bezt->h1==HD_AUTO_ANIM) && 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.0f && ydiff2 <= 0.0f) || (ydiff1 >= 0.0f && ydiff2 >= 0.0f) ) { - bezt->vec[0][1]= bezt->vec[1][1]; + len_a /= len; + madd_v3_v3v3fl(p2 - 3, p2, tvec, -len_a); + + if ((bezt->h1 == HD_AUTO_ANIM) && 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.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.0f) { if (prev->vec[1][1] > bezt->vec[0][1]) { - bezt->vec[0][1]= prev->vec[1][1]; - leftviolate= 1; + bezt->vec[0][1] = prev->vec[1][1]; + leftviolate = 1; } } else { if (prev->vec[1][1] < bezt->vec[0][1]) { - bezt->vec[0][1]= prev->vec[1][1]; - leftviolate= 1; + bezt->vec[0][1] = prev->vec[1][1]; + leftviolate = 1; } } } } } if (ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM)) { - len_b/=len; - madd_v3_v3v3fl(p2+3, p2, tvec, len_b); - - if ((bezt->h2==HD_AUTO_ANIM) && 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]; + len_b /= len; + madd_v3_v3v3fl(p2 + 3, p2, tvec, len_b); + + if ((bezt->h2 == HD_AUTO_ANIM) && 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.0f && ydiff2 <= 0.0f) || (ydiff1 >= 0.0f && ydiff2 >= 0.0f) ) { - bezt->vec[2][1]= bezt->vec[1][1]; + bezt->vec[2][1] = bezt->vec[1][1]; } else { /* andles should not be beyond y coord of two others */ if (ydiff1 <= 0.0f) { if (next->vec[1][1] < bezt->vec[2][1]) { - bezt->vec[2][1]= next->vec[1][1]; - rightviolate= 1; + bezt->vec[2][1] = next->vec[1][1]; + rightviolate = 1; } } else { if (next->vec[1][1] > bezt->vec[2][1]) { - bezt->vec[2][1]= next->vec[1][1]; - rightviolate= 1; + bezt->vec[2][1] = next->vec[1][1]; + rightviolate = 1; } } } @@ -2614,33 +2711,32 @@ static void calchandleNurb_intern(BezTriple *bezt, BezTriple *prev, BezTriple *n if (leftviolate || rightviolate) { /* align left handle */ float h1[3], h2[3]; float dot; - - sub_v3_v3v3(h1, p2-3, p2); - sub_v3_v3v3(h2, p2, p2+3); - len_a= normalize_v3(h1); - len_b= normalize_v3(h2); + sub_v3_v3v3(h1, p2 - 3, p2); + sub_v3_v3v3(h2, p2, p2 + 3); + + len_a = normalize_v3(h1); + len_b = normalize_v3(h2); - dot= dot_v3v3(h1, h2); + dot = dot_v3v3(h1, h2); if (leftviolate) { mul_v3_fl(h1, dot * len_b); - sub_v3_v3v3(p2+3, p2, h1); + sub_v3_v3v3(p2 + 3, p2, h1); } else { mul_v3_fl(h2, dot * len_a); - add_v3_v3v3(p2-3, p2, h2); + add_v3_v3v3(p2 - 3, p2, h2); } } - } } - if (bezt->h1==HD_VECT) { /* vector */ - madd_v3_v3v3fl(p2-3, p2, dvec_a, -1.0f/3.0f); + if (bezt->h1 == HD_VECT) { /* vector */ + madd_v3_v3v3fl(p2 - 3, p2, dvec_a, -1.0f / 3.0f); } - if (bezt->h2==HD_VECT) { - madd_v3_v3v3fl(p2+3, p2, dvec_b, 1.0f/3.0f); + if (bezt->h2 == HD_VECT) { + madd_v3_v3v3fl(p2 + 3, p2, dvec_b, 1.0f / 3.0f); } if (skip_align) { @@ -2650,44 +2746,46 @@ static void calchandleNurb_intern(BezTriple *bezt, BezTriple *prev, BezTriple *n return; } - len_b= len_v3v3(p2, p2+3); - len_a= len_v3v3(p2, p2-3); - if (len_a==0.0f) len_a= 1.0f; - if (len_b==0.0f) len_b= 1.0f; + len_b = len_v3v3(p2, p2 + 3); + len_a = len_v3v3(p2, p2 - 3); + if (len_a == 0.0f) + len_a = 1.0f; + if (len_b == 0.0f) + len_b = 1.0f; if (bezt->f1 & SELECT) { /* order of calculation */ - if (bezt->h2==HD_ALIGN) { /* aligned */ - if (len_a>eps) { - len= len_b/len_a; - p2[3]= p2[0]+len*(p2[0] - p2[-3]); - p2[4]= p2[1]+len*(p2[1] - p2[-2]); - p2[5]= p2[2]+len*(p2[2] - p2[-1]); + if (bezt->h2 == HD_ALIGN) { /* aligned */ + if (len_a > eps) { + len = len_b / len_a; + p2[3] = p2[0] + len * (p2[0] - p2[-3]); + p2[4] = p2[1] + len * (p2[1] - p2[-2]); + p2[5] = p2[2] + len * (p2[2] - p2[-1]); } } - if (bezt->h1==HD_ALIGN) { - if (len_b>eps) { - len= len_a/len_b; - p2[-3]= p2[0]+len*(p2[0] - p2[3]); - p2[-2]= p2[1]+len*(p2[1] - p2[4]); - p2[-1]= p2[2]+len*(p2[2] - p2[5]); + if (bezt->h1 == HD_ALIGN) { + if (len_b > eps) { + len = len_a / len_b; + p2[-3] = p2[0] + len * (p2[0] - p2[3]); + p2[-2] = p2[1] + len * (p2[1] - p2[4]); + p2[-1] = p2[2] + len * (p2[2] - p2[5]); } } } else { - if (bezt->h1==HD_ALIGN) { - if (len_b>eps) { - len= len_a/len_b; - p2[-3]= p2[0]+len*(p2[0] - p2[3]); - p2[-2]= p2[1]+len*(p2[1] - p2[4]); - p2[-1]= p2[2]+len*(p2[2] - p2[5]); + if (bezt->h1 == HD_ALIGN) { + if (len_b > eps) { + len = len_a / len_b; + p2[-3] = p2[0] + len * (p2[0] - p2[3]); + p2[-2] = p2[1] + len * (p2[1] - p2[4]); + p2[-1] = p2[2] + len * (p2[2] - p2[5]); } } - if (bezt->h2==HD_ALIGN) { /* aligned */ - if (len_a>eps) { - len= len_b/len_a; - p2[3]= p2[0]+len*(p2[0] - p2[-3]); - p2[4]= p2[1]+len*(p2[1] - p2[-2]); - p2[5]= p2[2]+len*(p2[2] - p2[-1]); + if (bezt->h2 == HD_ALIGN) { /* aligned */ + if (len_a > eps) { + len = len_b / len_a; + p2[3] = p2[0] + len * (p2[0] - p2[-3]); + p2[4] = p2[1] + len * (p2[1] - p2[-2]); + p2[5] = p2[2] + len * (p2[2] - p2[-1]); } } } @@ -2698,23 +2796,28 @@ static void calchandlesNurb_intern(Nurb *nu, int skip_align) BezTriple *bezt, *prev, *next; short a; - if (nu->type != CU_BEZIER) return; - if (nu->pntsu<2) return; - - a= nu->pntsu; - bezt= nu->bezt; - if (nu->flagu & CU_NURB_CYCLIC) prev= bezt+(a-1); - else prev= NULL; - next= bezt+1; + if (nu->type != CU_BEZIER) + return; + if (nu->pntsu < 2) + return; + + a = nu->pntsu; + bezt = nu->bezt; + if (nu->flagu & CU_NURB_CYCLIC) prev = bezt + (a - 1); + else prev = NULL; + next = bezt + 1; while (a--) { calchandleNurb_intern(bezt, prev, next, 0, skip_align); - prev= bezt; - if (a==1) { - if (nu->flagu & CU_NURB_CYCLIC) next= nu->bezt; - else next= NULL; + prev = bezt; + if (a == 1) { + if (nu->flagu & CU_NURB_CYCLIC) + next = nu->bezt; + else + next = NULL; } - else next++; + else + next++; bezt++; } @@ -2745,100 +2848,105 @@ void BKE_nurb_handles_test(Nurb *nu) if (nu->type != CU_BEZIER) return; - bezt= nu->bezt; - a= nu->pntsu; + bezt = nu->bezt; + a = nu->pntsu; while (a--) { - flag= 0; - if (bezt->f1 & SELECT) flag++; - if (bezt->f2 & SELECT) flag += 2; - if (bezt->f3 & SELECT) flag += 4; - - if ( !(flag==0 || flag==7) ) { + flag = 0; + if (bezt->f1 & SELECT) + flag++; + if (bezt->f2 & SELECT) + flag += 2; + if (bezt->f3 & SELECT) + flag += 4; + + if (!(flag == 0 || flag == 7) ) { if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM)) { /* auto */ - bezt->h1= HD_ALIGN; + bezt->h1 = HD_ALIGN; } if (ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM)) { /* auto */ - bezt->h2= HD_ALIGN; + bezt->h2 = HD_ALIGN; } - - if (bezt->h1==HD_VECT) { /* vector */ - if (flag < 4) bezt->h1= 0; + + if (bezt->h1 == HD_VECT) { /* vector */ + if (flag < 4) bezt->h1 = 0; } - if (bezt->h2==HD_VECT) { /* vector */ - if ( flag > 3) bezt->h2= 0; + if (bezt->h2 == HD_VECT) { /* vector */ + if (flag > 3) bezt->h2 = 0; } } bezt++; } - + BKE_nurb_handles_calc(nu); } void BKE_nurb_handles_autocalc(Nurb *nu, int flag) { /* checks handle coordinates and calculates type */ - + BezTriple *bezt2, *bezt1, *bezt0; int i, align, leftsmall, rightsmall; - if (nu==NULL || nu->bezt==NULL) return; - + if (nu == NULL || nu->bezt == NULL) + return; + bezt2 = nu->bezt; - bezt1 = bezt2 + (nu->pntsu-1); + bezt1 = bezt2 + (nu->pntsu - 1); bezt0 = bezt1 - 1; i = nu->pntsu; while (i--) { - - align= leftsmall= rightsmall= 0; - + align = leftsmall = rightsmall = 0; + /* left handle: */ - if (flag==0 || (bezt1->f1 & flag) ) { - bezt1->h1= 0; + if (flag == 0 || (bezt1->f1 & flag) ) { + bezt1->h1 = 0; /* distance too short: vectorhandle */ if (len_v3v3(bezt1->vec[1], bezt0->vec[1]) < 0.0001f) { - bezt1->h1= HD_VECT; - leftsmall= 1; + bezt1->h1 = HD_VECT; + leftsmall = 1; } else { /* aligned handle? */ if (dist_to_line_v2(bezt1->vec[1], bezt1->vec[0], bezt1->vec[2]) < 0.0001f) { - align= 1; - bezt1->h1= HD_ALIGN; + align = 1; + bezt1->h1 = HD_ALIGN; } /* or vector handle? */ if (dist_to_line_v2(bezt1->vec[0], bezt1->vec[1], bezt0->vec[1]) < 0.0001f) - bezt1->h1= HD_VECT; - + bezt1->h1 = HD_VECT; } } /* right handle: */ - if (flag==0 || (bezt1->f3 & flag) ) { - bezt1->h2= 0; + if (flag == 0 || (bezt1->f3 & flag) ) { + bezt1->h2 = 0; /* distance too short: vectorhandle */ if (len_v3v3(bezt1->vec[1], bezt2->vec[1]) < 0.0001f) { - bezt1->h2= HD_VECT; - rightsmall= 1; + bezt1->h2 = HD_VECT; + rightsmall = 1; } else { /* aligned handle? */ - if (align) bezt1->h2= HD_ALIGN; + if (align) bezt1->h2 = HD_ALIGN; /* or vector handle? */ if (dist_to_line_v2(bezt1->vec[2], bezt1->vec[1], bezt2->vec[1]) < 0.0001f) - bezt1->h2= HD_VECT; - + bezt1->h2 = HD_VECT; } } - if (leftsmall && bezt1->h2==HD_ALIGN) bezt1->h2= 0; - if (rightsmall && bezt1->h1==HD_ALIGN) bezt1->h1= 0; - + if (leftsmall && bezt1->h2 == HD_ALIGN) + bezt1->h2 = 0; + if (rightsmall && bezt1->h1 == HD_ALIGN) + bezt1->h1 = 0; + /* undesired combination: */ - if (bezt1->h1==HD_ALIGN && bezt1->h2==HD_VECT) bezt1->h1= 0; - if (bezt1->h2==HD_ALIGN && bezt1->h1==HD_VECT) bezt1->h2= 0; - - bezt0= bezt1; - bezt1= bezt2; + if (bezt1->h1 == HD_ALIGN && bezt1->h2 == HD_VECT) + bezt1->h1 = 0; + if (bezt1->h2 == HD_ALIGN && bezt1->h1 == HD_VECT) + bezt1->h2 = 0; + + bezt0 = bezt1; + bezt1 = bezt2; bezt2++; } @@ -2848,11 +2956,11 @@ void BKE_nurb_handles_autocalc(Nurb *nu, int flag) void BKE_nurbList_handles_autocalc(ListBase *editnurb, int flag) { Nurb *nu; - - nu= editnurb->first; + + nu = editnurb->first; while (nu) { BKE_nurb_handles_autocalc(nu, flag); - nu= nu->next; + nu = nu->next; } } @@ -2866,34 +2974,37 @@ void BKE_nurbList_handles_set(ListBase *editnurb, short code) /* code==6: Clear align, like 3 but no toggle */ Nurb *nu; BezTriple *bezt; - short a, ok=0; + short a, ok = 0; - if (code==1 || code==2) { - nu= editnurb->first; + if (code == 1 || code == 2) { + nu = editnurb->first; while (nu) { if (nu->type == CU_BEZIER) { - bezt= nu->bezt; - a= nu->pntsu; + bezt = nu->bezt; + a = nu->pntsu; while (a--) { if ((bezt->f1 & SELECT) || (bezt->f3 & SELECT)) { - if (bezt->f1 & SELECT) bezt->h1= code; - if (bezt->f3 & SELECT) bezt->h2= code; - if (bezt->h1!=bezt->h2) { - if (ELEM(bezt->h1, HD_ALIGN, HD_AUTO)) bezt->h1 = HD_FREE; - if (ELEM(bezt->h2, HD_ALIGN, HD_AUTO)) bezt->h2 = HD_FREE; + if (bezt->f1 & SELECT) + bezt->h1 = code; + if (bezt->f3 & SELECT) + bezt->h2 = code; + if (bezt->h1 != bezt->h2) { + if (ELEM(bezt->h1, HD_ALIGN, HD_AUTO)) + bezt->h1 = HD_FREE; + if (ELEM(bezt->h2, HD_ALIGN, HD_AUTO)) + bezt->h2 = HD_FREE; } } bezt++; } BKE_nurb_handles_calc(nu); } - nu= nu->next; + nu = nu->next; } } else { /* there is 1 handle not FREE: FREE it all, else make ALIGNED */ - - nu= editnurb->first; + nu = editnurb->first; if (code == 5) { ok = HD_ALIGN; } @@ -2904,34 +3015,34 @@ void BKE_nurbList_handles_set(ListBase *editnurb, short code) /* Toggle */ while (nu) { if (nu->type == CU_BEZIER) { - bezt= nu->bezt; - a= nu->pntsu; + bezt = nu->bezt; + a = nu->pntsu; while (a--) { - if ((bezt->f1 & SELECT) && bezt->h1) ok= 1; - if ((bezt->f3 & SELECT) && bezt->h2) ok= 1; + if ((bezt->f1 & SELECT) && bezt->h1) ok = 1; + if ((bezt->f3 & SELECT) && bezt->h2) ok = 1; if (ok) break; bezt++; } } - nu= nu->next; + nu = nu->next; } - if (ok) ok= HD_FREE; - else ok= HD_ALIGN; + if (ok) ok = HD_FREE; + else ok = HD_ALIGN; } - nu= editnurb->first; + nu = editnurb->first; while (nu) { if (nu->type == CU_BEZIER) { - bezt= nu->bezt; - a= nu->pntsu; + bezt = nu->bezt; + a = nu->pntsu; while (a--) { - if (bezt->f1 & SELECT) bezt->h1= ok; - if (bezt->f3 & SELECT) bezt->h2= ok; - + if (bezt->f1 & SELECT) bezt->h1 = ok; + if (bezt->f3 & SELECT) bezt->h2 = ok; + bezt++; } BKE_nurb_handles_calc(nu); } - nu= nu->next; + nu = nu->next; } } } @@ -2939,9 +3050,9 @@ void BKE_nurbList_handles_set(ListBase *editnurb, short code) static void swapdata(void *adr1, void *adr2, int len) { - if (len<=0) return; + if (len <= 0) return; - if (len<65) { + if (len < 65) { char adr[64]; memcpy(adr, adr1, len); @@ -2951,7 +3062,7 @@ static void swapdata(void *adr1, void *adr2, int len) else { char *adr; - adr= (char *)MEM_mallocN(len, "curve swap"); + adr = (char *)MEM_mallocN(len, "curve swap"); memcpy(adr, adr1, len); memcpy(adr1, adr2, len); memcpy(adr2, adr, len); @@ -2966,78 +3077,80 @@ void BKE_nurb_direction_switch(Nurb *nu) float *fp1, *fp2, *tempf; int a, b; - if (nu->pntsu==1 && nu->pntsv==1) return; + if (nu->pntsu == 1 && nu->pntsv == 1) return; if (nu->type == CU_BEZIER) { - a= nu->pntsu; - bezt1= nu->bezt; - bezt2= bezt1+(a-1); - if (a & 1) a+= 1; /* if odd, also swap middle content */ - a/= 2; - while (a>0) { - if (bezt1!=bezt2) SWAP(BezTriple, *bezt1, *bezt2); + a = nu->pntsu; + bezt1 = nu->bezt; + bezt2 = bezt1 + (a - 1); + if (a & 1) a += 1; /* if odd, also swap middle content */ + a /= 2; + while (a > 0) { + if (bezt1 != bezt2) + SWAP(BezTriple, *bezt1, *bezt2); swapdata(bezt1->vec[0], bezt1->vec[2], 12); - if (bezt1!=bezt2) swapdata(bezt2->vec[0], bezt2->vec[2], 12); + if (bezt1 != bezt2) + swapdata(bezt2->vec[0], bezt2->vec[2], 12); SWAP(char, bezt1->h1, bezt1->h2); SWAP(short, bezt1->f1, bezt1->f3); - - if (bezt1!=bezt2) { + + if (bezt1 != bezt2) { SWAP(char, bezt2->h1, bezt2->h2); SWAP(short, bezt2->f1, bezt2->f3); - bezt1->alfa= -bezt1->alfa; - bezt2->alfa= -bezt2->alfa; + bezt1->alfa = -bezt1->alfa; + bezt2->alfa = -bezt2->alfa; } a--; - bezt1++; + bezt1++; bezt2--; } } - else if (nu->pntsv==1) { - a= nu->pntsu; - bp1= nu->bp; - bp2= bp1+(a-1); - a/= 2; - while (bp1!=bp2 && a>0) { + else if (nu->pntsv == 1) { + a = nu->pntsu; + bp1 = nu->bp; + bp2 = bp1 + (a - 1); + a /= 2; + while (bp1 != bp2 && a > 0) { SWAP(BPoint, *bp1, *bp2); a--; - bp1->alfa= -bp1->alfa; - bp2->alfa= -bp2->alfa; - bp1++; + bp1->alfa = -bp1->alfa; + bp2->alfa = -bp2->alfa; + bp1++; bp2--; } if (nu->type == CU_NURBS) { /* no knots for too short paths */ if (nu->knotsu) { /* inverse knots */ - a= KNOTSU(nu); - fp1= nu->knotsu; - fp2= fp1+(a-1); - a/= 2; - while (fp1!=fp2 && a>0) { + a = KNOTSU(nu); + fp1 = nu->knotsu; + fp2 = fp1 + (a - 1); + a /= 2; + while (fp1 != fp2 && a > 0) { SWAP(float, *fp1, *fp2); a--; - fp1++; + fp1++; fp2--; } /* and make in increasing order again */ - a= KNOTSU(nu); - fp1= nu->knotsu; - fp2=tempf= MEM_mallocN(sizeof(float)*a, "switchdirect"); + a = KNOTSU(nu); + fp1 = nu->knotsu; + fp2 = tempf = MEM_mallocN(sizeof(float) * a, "switchdirect"); while (a--) { - fp2[0]= fabs(fp1[1]-fp1[0]); + fp2[0] = fabs(fp1[1] - fp1[0]); fp1++; fp2++; } - - a= KNOTSU(nu)-1; - fp1= nu->knotsu; - fp2= tempf; - fp1[0]= 0.0; + + a = KNOTSU(nu) - 1; + fp1 = nu->knotsu; + fp2 = tempf; + fp1[0] = 0.0; fp1++; while (a--) { - fp1[0]= fp1[-1]+fp2[0]; + fp1[0] = fp1[-1] + fp2[0]; fp1++; fp2++; } @@ -3046,18 +3159,16 @@ void BKE_nurb_direction_switch(Nurb *nu) } } else { - - for (b=0; b<nu->pntsv; b++) { - - bp1= nu->bp+b*nu->pntsu; - a= nu->pntsu; - bp2= bp1+(a-1); - a/= 2; - - while (bp1!=bp2 && a>0) { + for (b = 0; b < nu->pntsv; b++) { + bp1 = nu->bp + b * nu->pntsu; + a = nu->pntsu; + bp2 = bp1 + (a - 1); + a /= 2; + + while (bp1 != bp2 && a > 0) { SWAP(BPoint, *bp1, *bp2); a--; - bp1++; + bp1++; bp2--; } } @@ -3065,28 +3176,28 @@ void BKE_nurb_direction_switch(Nurb *nu) } -float (*BKE_curve_vertexCos_get(Curve *UNUSED(cu), ListBase *lb, int *numVerts_r))[3] +float (*BKE_curve_vertexCos_get(Curve * UNUSED(cu), ListBase * lb, int *numVerts_r))[3] { int i, numVerts = *numVerts_r = BKE_nurbList_verts_count(lb); - float *co, (*cos)[3] = MEM_mallocN(sizeof(*cos)*numVerts, "cu_vcos"); + float *co, (*cos)[3] = MEM_mallocN(sizeof(*cos) * numVerts, "cu_vcos"); Nurb *nu; co = cos[0]; - for (nu=lb->first; nu; nu=nu->next) { + for (nu = lb->first; nu; nu = nu->next) { if (nu->type == CU_BEZIER) { BezTriple *bezt = nu->bezt; - for (i=0; i<nu->pntsu; i++, bezt++) { - copy_v3_v3(co, bezt->vec[0]); co+=3; - copy_v3_v3(co, bezt->vec[1]); co+=3; - copy_v3_v3(co, bezt->vec[2]); co+=3; + for (i = 0; i < nu->pntsu; i++, bezt++) { + copy_v3_v3(co, bezt->vec[0]); co += 3; + copy_v3_v3(co, bezt->vec[1]); co += 3; + copy_v3_v3(co, bezt->vec[2]); co += 3; } } else { BPoint *bp = nu->bp; - for (i=0; i<nu->pntsu*nu->pntsv; i++, bp++) { - copy_v3_v3(co, bp->vec); co+=3; + for (i = 0; i < nu->pntsu * nu->pntsv; i++, bp++) { + copy_v3_v3(co, bp->vec); co += 3; } } } @@ -3100,21 +3211,21 @@ void BK_curve_vertexCos_apply(Curve *UNUSED(cu), ListBase *lb, float (*vertexCos Nurb *nu; int i; - for (nu=lb->first; nu; nu=nu->next) { + for (nu = lb->first; nu; nu = nu->next) { if (nu->type == CU_BEZIER) { BezTriple *bezt = nu->bezt; - for (i=0; i<nu->pntsu; i++, bezt++) { - copy_v3_v3(bezt->vec[0], co); co+=3; - copy_v3_v3(bezt->vec[1], co); co+=3; - copy_v3_v3(bezt->vec[2], co); co+=3; + for (i = 0; i < nu->pntsu; i++, bezt++) { + copy_v3_v3(bezt->vec[0], co); co += 3; + copy_v3_v3(bezt->vec[1], co); co += 3; + copy_v3_v3(bezt->vec[2], co); co += 3; } } else { BPoint *bp = nu->bp; - for (i=0; i<nu->pntsu*nu->pntsv; i++, bp++) { - copy_v3_v3(bp->vec, co); co+=3; + for (i = 0; i < nu->pntsu * nu->pntsv; i++, bp++) { + copy_v3_v3(bp->vec, co); co += 3; } } @@ -3122,29 +3233,29 @@ void BK_curve_vertexCos_apply(Curve *UNUSED(cu), ListBase *lb, float (*vertexCos } } -float (*BKE_curve_keyVertexCos_get(Curve *UNUSED(cu), ListBase *lb, float *key))[3] +float (*BKE_curve_keyVertexCos_get(Curve * UNUSED(cu), ListBase * lb, float *key))[3] { int i, numVerts = BKE_nurbList_verts_count(lb); - float *co, (*cos)[3] = MEM_mallocN(sizeof(*cos)*numVerts, "cu_vcos"); + float *co, (*cos)[3] = MEM_mallocN(sizeof(*cos) * numVerts, "cu_vcos"); Nurb *nu; co = cos[0]; - for (nu=lb->first; nu; nu=nu->next) { + for (nu = lb->first; nu; nu = nu->next) { if (nu->type == CU_BEZIER) { BezTriple *bezt = nu->bezt; - for (i=0; i<nu->pntsu; i++, bezt++) { - copy_v3_v3(co, key); co+=3; key+=3; - copy_v3_v3(co, key); co+=3; key+=3; - copy_v3_v3(co, key); co+=3; key+=3; - key+=3; /* skip tilt */ + for (i = 0; i < nu->pntsu; i++, bezt++) { + copy_v3_v3(co, key); co += 3; key += 3; + copy_v3_v3(co, key); co += 3; key += 3; + copy_v3_v3(co, key); co += 3; key += 3; + key += 3; /* skip tilt */ } } else { BPoint *bp = nu->bp; - for (i=0; i<nu->pntsu*nu->pntsv; i++, bp++) { - copy_v3_v3(co, key); co+=3; key+=3; + for (i = 0; i < nu->pntsu * nu->pntsv; i++, bp++) { + copy_v3_v3(co, key); co += 3; key += 3; key++; /* skip tilt */ } } @@ -3158,22 +3269,22 @@ void BKE_curve_keyVertexTilts_apply(Curve *UNUSED(cu), ListBase *lb, float *key) Nurb *nu; int i; - for (nu=lb->first; nu; nu=nu->next) { + for (nu = lb->first; nu; nu = nu->next) { if (nu->type == CU_BEZIER) { BezTriple *bezt = nu->bezt; - for (i=0; i<nu->pntsu; i++, bezt++) { - key+=3*3; - bezt->alfa= *key; - key+=3; + for (i = 0; i < nu->pntsu; i++, bezt++) { + key += 3 * 3; + bezt->alfa = *key; + key += 3; } } else { BPoint *bp = nu->bp; - for (i=0; i<nu->pntsu*nu->pntsv; i++, bp++) { - key+=3; - bp->alfa= *key; + for (i = 0; i < nu->pntsu * nu->pntsv; i++, bp++) { + key += 3; + bp->alfa = *key; key++; } } @@ -3182,31 +3293,46 @@ void BKE_curve_keyVertexTilts_apply(Curve *UNUSED(cu), ListBase *lb, float *key) int BKE_nurb_check_valid_u(struct Nurb *nu) { - if (nu==NULL) return 0; - if (nu->pntsu <= 1) return 0; - if (nu->type != CU_NURBS) return 1; /* not a nurb, lets assume its valid */ - - if (nu->pntsu < nu->orderu) return 0; - if (((nu->flag & CU_NURB_CYCLIC)==0) && (nu->flagu & CU_NURB_BEZIER)) { /* Bezier U Endpoints */ - if (nu->orderu==4) { - if (nu->pntsu < 5) return 0; /* bezier with 4 orderu needs 5 points */ + if (nu == NULL) + return 0; + if (nu->pntsu <= 1) + return 0; + if (nu->type != CU_NURBS) + return 1; /* not a nurb, lets assume its valid */ + + if (nu->pntsu < nu->orderu) return 0; + if (((nu->flag & CU_NURB_CYCLIC) == 0) && (nu->flagu & CU_NURB_BEZIER)) { /* Bezier U Endpoints */ + if (nu->orderu == 4) { + if (nu->pntsu < 5) + return 0; /* bezier with 4 orderu needs 5 points */ + } + else { + if (nu->orderu != 3) + return 0; /* order must be 3 or 4 */ } - else if (nu->orderu != 3) return 0; /* order must be 3 or 4 */ } return 1; } int BKE_nurb_check_valid_v(struct Nurb *nu) { - if (nu==NULL) return 0; - if (nu->pntsv <= 1) return 0; - if (nu->type != CU_NURBS) return 1; /* not a nurb, lets assume its valid */ - - if (nu->pntsv < nu->orderv) return 0; - if (((nu->flag & CU_NURB_CYCLIC)==0) && (nu->flagv & CU_NURB_BEZIER)) { /* Bezier V Endpoints */ - if (nu->orderv==4) { - if (nu->pntsv < 5) return 0; /* bezier with 4 orderu needs 5 points */ + if (nu == NULL) + return 0; + if (nu->pntsv <= 1) + return 0; + if (nu->type != CU_NURBS) + return 1; /* not a nurb, lets assume its valid */ + + if (nu->pntsv < nu->orderv) + return 0; + if (((nu->flag & CU_NURB_CYCLIC) == 0) && (nu->flagv & CU_NURB_BEZIER)) { /* Bezier V Endpoints */ + if (nu->orderv == 4) { + if (nu->pntsv < 5) + return 0; /* bezier with 4 orderu needs 5 points */ + } + else { + if (nu->orderv != 3) + return 0; /* order must be 3 or 4 */ } - else if (nu->orderv != 3) return 0; /* order must be 3 or 4 */ } return 1; } @@ -3214,13 +3340,13 @@ int BKE_nurb_check_valid_v(struct Nurb *nu) int BKE_nurb_order_clamp_u(struct Nurb *nu) { int change = 0; - if (nu->pntsu<nu->orderu) { - nu->orderu= nu->pntsu; - change= 1; + if (nu->pntsu < nu->orderu) { + nu->orderu = nu->pntsu; + change = 1; } - if (((nu->flagu & CU_NURB_CYCLIC)==0) && (nu->flagu & CU_NURB_BEZIER)) { + if (((nu->flagu & CU_NURB_CYCLIC) == 0) && (nu->flagu & CU_NURB_BEZIER)) { CLAMP(nu->orderu, 3, 4); - change= 1; + change = 1; } return change; } @@ -3228,13 +3354,13 @@ int BKE_nurb_order_clamp_u(struct Nurb *nu) int BKE_nurb_order_clamp_v(struct Nurb *nu) { int change = 0; - if (nu->pntsv<nu->orderv) { - nu->orderv= nu->pntsv; - change= 1; + if (nu->pntsv < nu->orderv) { + nu->orderv = nu->pntsv; + change = 1; } - if (((nu->flagv & CU_NURB_CYCLIC)==0) && (nu->flagv & CU_NURB_BEZIER)) { + if (((nu->flagv & CU_NURB_CYCLIC) == 0) && (nu->flagv & CU_NURB_BEZIER)) { CLAMP(nu->orderv, 3, 4); - change= 1; + change = 1; } return change; } @@ -3253,10 +3379,10 @@ ListBase *BKE_curve_nurbs_get(Curve *cu) /* basic vertex data functions */ int BKE_curve_minmax(Curve *cu, float min[3], float max[3]) { - ListBase *nurb_lb= BKE_curve_nurbs_get(cu); + ListBase *nurb_lb = BKE_curve_nurbs_get(cu); Nurb *nu; - for (nu= nurb_lb->first; nu; nu= nu->next) + for (nu = nurb_lb->first; nu; nu = nu->next) BKE_nurb_minmax(nu, min, max); return (nurb_lb->first != NULL); @@ -3264,20 +3390,20 @@ int BKE_curve_minmax(Curve *cu, float min[3], float max[3]) int BKE_curve_center_median(Curve *cu, float cent[3]) { - ListBase *nurb_lb= BKE_curve_nurbs_get(cu); + ListBase *nurb_lb = BKE_curve_nurbs_get(cu); Nurb *nu; - int total= 0; + int total = 0; zero_v3(cent); - for (nu= nurb_lb->first; nu; nu= nu->next) { + for (nu = nurb_lb->first; nu; nu = nu->next) { int i; if (nu->type == CU_BEZIER) { BezTriple *bezt; - i= nu->pntsu; + i = nu->pntsu; total += i * 3; - for (bezt= nu->bezt; i--; bezt++) { + for (bezt = nu->bezt; i--; bezt++) { add_v3_v3(cent, bezt->vec[0]); add_v3_v3(cent, bezt->vec[1]); add_v3_v3(cent, bezt->vec[2]); @@ -3285,15 +3411,15 @@ int BKE_curve_center_median(Curve *cu, float cent[3]) } else { BPoint *bp; - i= nu->pntsu*nu->pntsv; + i = nu->pntsu * nu->pntsv; total += i; - for (bp= nu->bp; i--; bp++) { + for (bp = nu->bp; i--; bp++) { add_v3_v3(cent, bp->vec); } } } - mul_v3_fl(cent, 1.0f/(float)total); + mul_v3_fl(cent, 1.0f / (float)total); return (total != 0); } @@ -3312,25 +3438,25 @@ int BKE_curve_center_bounds(Curve *cu, float cent[3]) void BKE_curve_translate(Curve *cu, float offset[3], int do_keys) { - ListBase *nurb_lb= BKE_curve_nurbs_get(cu); + ListBase *nurb_lb = BKE_curve_nurbs_get(cu); Nurb *nu; int i; - for (nu= nurb_lb->first; nu; nu= nu->next) { + for (nu = nurb_lb->first; nu; nu = nu->next) { BezTriple *bezt; BPoint *bp; if (nu->type == CU_BEZIER) { - i= nu->pntsu; - for (bezt= nu->bezt; i--; bezt++) { + i = nu->pntsu; + for (bezt = nu->bezt; i--; bezt++) { add_v3_v3(bezt->vec[0], offset); add_v3_v3(bezt->vec[1], offset); add_v3_v3(bezt->vec[2], offset); } } else { - i= nu->pntsu*nu->pntsv; - for (bp= nu->bp; i--; bp++) { + i = nu->pntsu * nu->pntsv; + for (bp = nu->bp; i--; bp++) { add_v3_v3(bp->vec, offset); } } @@ -3338,9 +3464,9 @@ void BKE_curve_translate(Curve *cu, float offset[3], int do_keys) if (do_keys && cu->key) { KeyBlock *kb; - for (kb=cu->key->block.first; kb; kb=kb->next) { - float *fp= kb->data; - for (i= kb->totelem; i--; fp+=3) { + for (kb = cu->key->block.first; kb; kb = kb->next) { + float *fp = kb->data; + for (i = kb->totelem; i--; fp += 3) { add_v3_v3(fp, offset); } } @@ -3349,13 +3475,13 @@ void BKE_curve_translate(Curve *cu, float offset[3], int do_keys) void BKE_curve_delete_material_index(Curve *cu, int index) { - const int curvetype= BKE_curve_type_get(cu); + const int curvetype = BKE_curve_type_get(cu); if (curvetype == OB_FONT) { - struct CharInfo *info= cu->strinfo; + struct CharInfo *info = cu->strinfo; int i; - for (i= cu->len-1; i >= 0; i--, info++) { - if (info->mat_nr && info->mat_nr>=index) { + for (i = cu->len - 1; i >= 0; i--, info++) { + if (info->mat_nr && info->mat_nr >= index) { info->mat_nr--; } } @@ -3363,10 +3489,11 @@ void BKE_curve_delete_material_index(Curve *cu, int index) else { Nurb *nu; - for (nu= cu->nurb.first; nu; nu= nu->next) { - if (nu->mat_nr && nu->mat_nr>=index) { + for (nu = cu->nurb.first; nu; nu = nu->next) { + if (nu->mat_nr && nu->mat_nr >= index) { nu->mat_nr--; - if (curvetype == OB_CURVE) nu->charidx--; + if (curvetype == OB_CURVE) + nu->charidx--; } } } diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index e32182ed36e..5eab6aeccef 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -565,6 +565,38 @@ static size_t layerFilesize_mdisps(CDataFile *UNUSED(cdf), void *data, int count return size; } +static void layerCopy_grid_paint_mask(const void *source, void *dest, int count) +{ + int i; + const GridPaintMask *s = source; + GridPaintMask *d = dest; + + for(i = 0; i < count; ++i) { + if(s[i].data) { + d[i].data = MEM_dupallocN(s[i].data); + d[i].level = s[i].level; + } + else { + d[i].data = NULL; + d[i].level = 0; + } + + } +} + +static void layerFree_grid_paint_mask(void *data, int count, int UNUSED(size)) +{ + int i; + GridPaintMask *gpm = data; + + for(i = 0; i < count; ++i) { + if(gpm[i].data) + MEM_freeN(gpm[i].data); + gpm[i].data = NULL; + gpm[i].level = 0; + } +} + /* --------- */ static void layerCopyValue_mloopcol(void *source, void *dest) { @@ -1059,7 +1091,11 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = { /* END BMESH ONLY */ - + /* 34: CD_PAINT_MASK */ + {sizeof(float), "", 0, NULL, NULL, NULL, NULL, NULL, NULL}, + /* 35: CD_GRID_PAINT_MASK */ + {sizeof(GridPaintMask), "GridPaintMask", 1, NULL, layerCopy_grid_paint_mask, + layerFree_grid_paint_mask, NULL, NULL, NULL} }; /* note, numbers are from trunk and need updating for bmesh */ @@ -1073,7 +1109,9 @@ static const char *LAYERTYPENAMES[CD_NUMTYPES] = { /* BMESH ONLY */ /* 25-29 */ "CDMPoly", "CDMLoop", "CDShapeKeyIndex", "CDShapeKey", "CDBevelWeight", - /* 30-32 */ "CDSubSurfCrease", "CDOrigSpaceLoop", "CDPreviewLoopCol" + /* 30-34 */ "CDSubSurfCrease", "CDOrigSpaceLoop", "CDPreviewLoopCol", "CDBMElemPyPtr", "CDPaintMask", + /* 35 */ "CDGridPaintMask" + /* END BMESH ONLY */ }; @@ -1086,12 +1124,14 @@ const CustomDataMask CD_MASK_MESH = CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MPOLY | CD_MASK_MLOOP | - CD_MASK_MTEXPOLY | CD_MASK_NORMAL | CD_MASK_RECAST; + CD_MASK_MTEXPOLY | CD_MASK_NORMAL | CD_MASK_RECAST | CD_MASK_PAINT_MASK | + CD_MASK_GRID_PAINT_MASK; const CustomDataMask CD_MASK_EDITMESH = CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_SHAPE_KEYINDEX | CD_MASK_MCOL|CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | - CD_MASK_MDISPS | CD_MASK_SHAPEKEY | CD_MASK_RECAST; + CD_MASK_MDISPS | CD_MASK_SHAPEKEY | CD_MASK_RECAST | CD_MASK_PAINT_MASK | + CD_MASK_GRID_PAINT_MASK; const CustomDataMask CD_MASK_DERIVEDMESH = CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_CLOTH_ORCO | @@ -1101,7 +1141,9 @@ const CustomDataMask CD_MASK_DERIVEDMESH = CD_MASK_ORIGINDEX | CD_MASK_POLYINDEX; const CustomDataMask CD_MASK_BMESH = CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | - CD_MASK_PROP_STR | CD_MASK_SHAPEKEY | CD_MASK_SHAPE_KEYINDEX | CD_MASK_MDISPS | CD_MASK_CREASE | CD_MASK_BWEIGHT | CD_MASK_RECAST; + CD_MASK_PROP_STR | CD_MASK_SHAPEKEY | CD_MASK_SHAPE_KEYINDEX | CD_MASK_MDISPS | + CD_MASK_CREASE | CD_MASK_BWEIGHT | CD_MASK_RECAST | CD_MASK_PAINT_MASK | + CD_MASK_GRID_PAINT_MASK; const CustomDataMask CD_MASK_FACECORNERS = CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_MTEXPOLY | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL; @@ -1915,8 +1957,7 @@ void CustomData_interp(const CustomData *source, CustomData *dest, void *src_data = source->layers[src_i].data; for (j = 0; j < count; ++j) - sources[j] = (char *)src_data - + typeInfo->size * src_indices[j]; + sources[j] = (char *)src_data + typeInfo->size * src_indices[j]; dest_offset = dest_index * typeInfo->size; diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index 75e22195c6a..fc54ea6eed5 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -82,10 +82,10 @@ * the queue store a list of freenodes to avoid successive alloc/dealloc */ -DagNodeQueue * queue_create (int slots) +DagNodeQueue *queue_create(int slots) { - DagNodeQueue * queue; - DagNodeQueueElem * elem; + DagNodeQueue *queue; + DagNodeQueueElem *elem; int i; queue = MEM_mallocN(sizeof(DagNodeQueue), "DAG queue"); @@ -98,7 +98,7 @@ DagNodeQueue * queue_create (int slots) elem->next = NULL; queue->freenodes->first = queue->freenodes->last = elem; - for (i = 1; i <slots;i++) { + for (i = 1; i < slots; i++) { elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem4"); elem->node = NULL; elem->next = NULL; @@ -111,7 +111,7 @@ DagNodeQueue * queue_create (int slots) void queue_raz(DagNodeQueue *queue) { - DagNodeQueueElem * elem; + DagNodeQueueElem *elem; elem = queue->first; if (queue->freenodes->last) @@ -132,8 +132,8 @@ void queue_raz(DagNodeQueue *queue) void queue_delete(DagNodeQueue *queue) { - DagNodeQueueElem * elem; - DagNodeQueueElem * temp; + DagNodeQueueElem *elem; + DagNodeQueueElem *temp; elem = queue->first; while (elem) { @@ -156,7 +156,7 @@ void queue_delete(DagNodeQueue *queue) /* insert in queue, remove in front */ void push_queue(DagNodeQueue *queue, DagNode *node) { - DagNodeQueueElem * elem; + DagNodeQueueElem *elem; int i; if (node == NULL) { @@ -168,7 +168,7 @@ void push_queue(DagNodeQueue *queue, DagNode *node) elem = queue->freenodes->first; if (elem != NULL) { queue->freenodes->first = elem->next; - if ( queue->freenodes->last == elem) { + if (queue->freenodes->last == elem) { queue->freenodes->last = NULL; queue->freenodes->first = NULL; } @@ -180,7 +180,7 @@ void push_queue(DagNodeQueue *queue, DagNode *node) elem->next = NULL; queue->freenodes->first = queue->freenodes->last = elem; - for (i = 1; i <DAGQUEUEALLOC;i++) { + for (i = 1; i < DAGQUEUEALLOC; i++) { elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem2"); elem->node = NULL; elem->next = NULL; @@ -207,13 +207,13 @@ void push_queue(DagNodeQueue *queue, DagNode *node) /* insert in front, remove in front */ void push_stack(DagNodeQueue *queue, DagNode *node) { - DagNodeQueueElem * elem; + DagNodeQueueElem *elem; int i; elem = queue->freenodes->first; if (elem != NULL) { queue->freenodes->first = elem->next; - if ( queue->freenodes->last == elem) { + if (queue->freenodes->last == elem) { queue->freenodes->last = NULL; queue->freenodes->first = NULL; } @@ -225,7 +225,7 @@ void push_stack(DagNodeQueue *queue, DagNode *node) elem->next = NULL; queue->freenodes->first = queue->freenodes->last = elem; - for (i = 1; i <DAGQUEUEALLOC;i++) { + for (i = 1; i < DAGQUEUEALLOC; i++) { elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem2"); elem->node = NULL; elem->next = NULL; @@ -246,24 +246,24 @@ void push_stack(DagNodeQueue *queue, DagNode *node) } -DagNode * pop_queue(DagNodeQueue *queue) +DagNode *pop_queue(DagNodeQueue *queue) { - DagNodeQueueElem * elem; + DagNodeQueueElem *elem; DagNode *node; elem = queue->first; if (elem) { queue->first = elem->next; if (queue->last == elem) { - queue->last=NULL; - queue->first=NULL; + queue->last = NULL; + queue->first = NULL; } queue->count--; if (queue->freenodes->last) - queue->freenodes->last->next=elem; - queue->freenodes->last=elem; + queue->freenodes->last->next = elem; + queue->freenodes->last = elem; if (queue->freenodes->first == NULL) - queue->freenodes->first=elem; + queue->freenodes->first = elem; node = elem->node; elem->node = NULL; elem->next = NULL; @@ -276,17 +276,17 @@ DagNode * pop_queue(DagNodeQueue *queue) } } -void *pop_ob_queue(struct DagNodeQueue *queue) +void *pop_ob_queue(struct DagNodeQueue *queue) { return(pop_queue(queue)->ob); } -DagNode * get_top_node_queue(DagNodeQueue *queue) +DagNode *get_top_node_queue(DagNodeQueue *queue) { return queue->first->node; } -int queue_count(struct DagNodeQueue *queue) +int queue_count(struct DagNodeQueue *queue) { return queue->count; } @@ -307,37 +307,37 @@ static void dag_add_driver_relation(AnimData *adt, DagForest *dag, DagNode *node FCurve *fcu; DagNode *node1; - for (fcu= adt->drivers.first; fcu; fcu= fcu->next) { - ChannelDriver *driver= fcu->driver; + for (fcu = adt->drivers.first; fcu; fcu = fcu->next) { + ChannelDriver *driver = fcu->driver; DriverVar *dvar; int isdata_fcu = isdata || (fcu->rna_path && strstr(fcu->rna_path, "modifiers[")); /* loop over variables to get the target relationships */ - for (dvar= driver->variables.first; dvar; dvar= dvar->next) { + for (dvar = driver->variables.first; dvar; dvar = dvar->next) { /* only used targets */ DRIVER_TARGETS_USED_LOOPER(dvar) { if (dtar->id) { // FIXME: other data types need to be added here so that they can work! - if (GS(dtar->id->name)==ID_OB) { - Object *ob= (Object *)dtar->id; + if (GS(dtar->id->name) == ID_OB) { + Object *ob = (Object *)dtar->id; /* normal channel-drives-channel */ node1 = dag_get_node(dag, dtar->id); /* check if bone... */ - if ((ob->type==OB_ARMATURE) && - ( ((dtar->rna_path) && strstr(dtar->rna_path, "pose.bones[")) || - ((dtar->flag & DTAR_FLAG_STRUCT_REF) && (dtar->pchan_name[0])) )) + if ((ob->type == OB_ARMATURE) && + ( ((dtar->rna_path) && strstr(dtar->rna_path, "pose.bones[")) || + ((dtar->flag & DTAR_FLAG_STRUCT_REF) && (dtar->pchan_name[0])) )) { - dag_add_relation(dag, node1, node, isdata_fcu?DAG_RL_DATA_DATA:DAG_RL_DATA_OB, "Driver"); + dag_add_relation(dag, node1, node, isdata_fcu ? DAG_RL_DATA_DATA : DAG_RL_DATA_OB, "Driver"); } /* check if ob data */ else if (dtar->rna_path && strstr(dtar->rna_path, "data.")) - dag_add_relation(dag, node1, node, isdata_fcu?DAG_RL_DATA_DATA:DAG_RL_DATA_OB, "Driver"); + dag_add_relation(dag, node1, node, isdata_fcu ? DAG_RL_DATA_DATA : DAG_RL_DATA_OB, "Driver"); /* normal */ else - dag_add_relation(dag, node1, node, isdata_fcu?DAG_RL_OB_DATA:DAG_RL_OB_OB, "Driver"); + dag_add_relation(dag, node1, node, isdata_fcu ? DAG_RL_OB_DATA : DAG_RL_OB_OB, "Driver"); } } } @@ -353,12 +353,12 @@ static void dag_add_collision_field_relation(DagForest *dag, Scene *scene, Objec // would be nice to have a list of colliders here // so for now walk all objects in scene check 'same layer rule' - for (base = scene->base.first; base; base= base->next) { + for (base = scene->base.first; base; base = base->next) { if ((base->lay & ob->lay) && base->object->pd) { - Object *ob1= base->object; + Object *ob1 = base->object; if ((ob1->pd->deflect || ob1->pd->forcefield) && (ob1 != ob)) { node2 = dag_get_node(dag, ob1); - dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Field Collision"); + dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Field Collision"); } } } @@ -367,16 +367,16 @@ static void dag_add_collision_field_relation(DagForest *dag, Scene *scene, Objec static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, Object *ob, int mask) { bConstraint *con; - DagNode * node; - DagNode * node2; - DagNode * node3; + DagNode *node; + DagNode *node2; + DagNode *node3; Key *key; ParticleSystem *psys; - int addtoroot= 1; + int addtoroot = 1; node = dag_get_node(dag, ob); - if ((ob->data) && (mask&DAG_RL_DATA)) { + if ((ob->data) && (mask & DAG_RL_DATA)) { node2 = dag_get_node(dag, ob->data); dag_add_relation(dag, node, node2, DAG_RL_DATA, "Object-Data Relation"); node2->first_ancestor = ob; @@ -384,34 +384,34 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O } /* also build a custom data mask for dependencies that need certain layers */ - node->customdata_mask= 0; + node->customdata_mask = 0; if (ob->type == OB_ARMATURE) { if (ob->pose) { bPoseChannel *pchan; bConstraint *con; - for (pchan = ob->pose->chanbase.first; pchan; pchan=pchan->next) { - for (con = pchan->constraints.first; con; con=con->next) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { + for (con = pchan->constraints.first; con; con = con->next) { + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); ListBase targets = {NULL, NULL}; bConstraintTarget *ct; if (cti && cti->get_constraint_targets) { cti->get_constraint_targets(con, &targets); - for (ct= targets.first; ct; ct= ct->next) { + for (ct = targets.first; ct; ct = ct->next) { if (ct->tar && ct->tar != ob) { // fprintf(stderr, "armature %s target :%s\n", ob->id.name, target->id.name); node3 = dag_get_node(dag, ct->tar); if (ct->subtarget[0]) { - dag_add_relation(dag, node3, node, DAG_RL_OB_DATA|DAG_RL_DATA_DATA, cti->name); + dag_add_relation(dag, node3, node, DAG_RL_OB_DATA | DAG_RL_DATA_DATA, cti->name); if (ct->tar->type == OB_MESH) node3->customdata_mask |= CD_MASK_MDEFORMVERT; } else if (ELEM3(con->type, CONSTRAINT_TYPE_FOLLOWPATH, CONSTRAINT_TYPE_CLAMPTO, CONSTRAINT_TYPE_SPLINEIK)) - dag_add_relation(dag, node3, node, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, cti->name); + dag_add_relation(dag, node3, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, cti->name); else dag_add_relation(dag, node3, node, DAG_RL_OB_DATA, cti->name); } @@ -431,13 +431,13 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O if (ob->nlastrips.first) { bActionStrip *strip; bActionChannel *chan; - for (strip= ob->nlastrips.first; strip; strip= strip->next) { + for (strip = ob->nlastrips.first; strip; strip = strip->next) { if (strip->modifiers.first) { bActionModifier *amod; - for (amod= strip->modifiers.first; amod; amod= amod->next) { + for (amod = strip->modifiers.first; amod; amod = amod->next) { if (amod->ob) { node2 = dag_get_node(dag, amod->ob); - dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "NLA Strip Modifier"); + dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "NLA Strip Modifier"); } } } @@ -445,16 +445,16 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O } #endif // XXX old animation system if (ob->adt) - dag_add_driver_relation(ob->adt, dag, node, (ob->type == OB_ARMATURE)); // XXX isdata arg here doesn't give an accurate picture of situation + dag_add_driver_relation(ob->adt, dag, node, (ob->type == OB_ARMATURE)); // XXX isdata arg here doesn't give an accurate picture of situation - key= ob_get_key(ob); + key = ob_get_key(ob); if (key && key->adt) dag_add_driver_relation(key->adt, dag, node, 1); if (ob->modifiers.first) { ModifierData *md; - for (md=ob->modifiers.first; md; md=md->next) { + for (md = ob->modifiers.first; md; md = md->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); if (mti->updateDepgraph) mti->updateDepgraph(md, dag, scene, ob, node); @@ -465,22 +465,22 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O switch (ob->partype) { case PARSKEL: - dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA|DAG_RL_OB_OB, "Parent"); + dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Parent"); break; case PARVERT1: case PARVERT3: - dag_add_relation(dag, node2, node, DAG_RL_DATA_OB|DAG_RL_OB_OB, "Vertex Parent"); + dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, "Vertex Parent"); node2->customdata_mask |= CD_MASK_ORIGINDEX; break; case PARBONE: - dag_add_relation(dag, node2, node, DAG_RL_DATA_OB|DAG_RL_OB_OB, "Bone Parent"); + dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, "Bone Parent"); break; default: - if (ob->parent->type==OB_LATTICE) - dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA|DAG_RL_OB_OB, "Lattice Parent"); - else if (ob->parent->type==OB_CURVE) { - Curve *cu= ob->parent->data; + if (ob->parent->type == OB_LATTICE) + dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Lattice Parent"); + else if (ob->parent->type == OB_CURVE) { + Curve *cu = ob->parent->data; if (cu->flag & CU_PATH) - dag_add_relation(dag, node2, node, DAG_RL_DATA_OB|DAG_RL_OB_OB, "Curve Parent"); + dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, "Curve Parent"); else dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Curve Parent"); } @@ -488,22 +488,22 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Parent"); } /* exception case: parent is duplivert */ - if (ob->type==OB_MBALL && (ob->parent->transflag & OB_DUPLIVERTS)) { - dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA|DAG_RL_OB_OB, "Duplivert"); + if (ob->type == OB_MBALL && (ob->parent->transflag & OB_DUPLIVERTS)) { + dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Duplivert"); } addtoroot = 0; } if (ob->proxy) { node2 = dag_get_node(dag, ob->proxy); - dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA|DAG_RL_OB_OB, "Proxy"); + dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Proxy"); /* inverted relation, so addtoroot shouldn't be set to zero */ } if (ob->transflag & OB_DUPLI) { if ((ob->transflag & OB_DUPLIGROUP) && ob->dup_group) { GroupObject *go; - for (go= ob->dup_group->gobject.first; go; go= go->next) { + for (go = ob->dup_group->gobject.first; go; go = go->next) { if (go->ob) { node2 = dag_get_node(dag, go->ob); /* node2 changes node1, this keeps animations updated in groups?? not logical? */ @@ -514,14 +514,14 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O } /* softbody collision */ - if ((ob->type==OB_MESH) || (ob->type==OB_CURVE) || (ob->type==OB_LATTICE)) { + if ((ob->type == OB_MESH) || (ob->type == OB_CURVE) || (ob->type == OB_LATTICE)) { if (modifiers_isSoftbodyEnabled(ob) || modifiers_isClothEnabled(ob) || ob->particlesystem.first) - dag_add_collision_field_relation(dag, scene, ob, node); /* TODO: use effectorweight->group */ + dag_add_collision_field_relation(dag, scene, ob, node); /* TODO: use effectorweight->group */ } /* object data drivers */ if (ob->data) { - AnimData *adt= BKE_animdata_from_id((ID *)ob->data); + AnimData *adt = BKE_animdata_from_id((ID *)ob->data); if (adt) dag_add_driver_relation(adt, dag, node, 1); } @@ -537,49 +537,49 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Camera DoF"); } } - break; + break; case OB_MBALL: { - Object *mom= BKE_metaball_basis_find(scene, ob); + Object *mom = BKE_mball_basis_find(scene, ob); - if (mom!=ob) { + if (mom != ob) { node2 = dag_get_node(dag, mom); - dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Metaball"); // mom depends on children! + dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Metaball"); // mom depends on children! } } - break; + break; case OB_CURVE: case OB_FONT: { - Curve *cu= ob->data; + Curve *cu = ob->data; if (cu->bevobj) { node2 = dag_get_node(dag, cu->bevobj); - dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Curve Bevel"); + dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Curve Bevel"); } if (cu->taperobj) { node2 = dag_get_node(dag, cu->taperobj); - dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Curve Taper"); + dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Curve Taper"); } if (ob->type == OB_FONT) { if (cu->textoncurve) { node2 = dag_get_node(dag, cu->textoncurve); - dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Texture On Curve"); + dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Texture On Curve"); } } } - break; + break; } /* particles */ - psys= ob->particlesystem.first; + psys = ob->particlesystem.first; if (psys) { GroupObject *go; - for (; psys; psys=psys->next) { + for (; psys; psys = psys->next) { BoidRule *rule = NULL; BoidState *state = NULL; - ParticleSettings *part= psys->part; + ParticleSettings *part = psys->part; ListBase *effectors = NULL; EffectorCache *eff; @@ -591,12 +591,12 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O if (ELEM(part->phystype, PART_PHYS_KEYED, PART_PHYS_BOIDS)) { ParticleTarget *pt = psys->targets.first; - for (; pt; pt=pt->next) { - if (pt->ob && BLI_findlink(&pt->ob->particlesystem, pt->psys-1)) { + for (; pt; pt = pt->next) { + if (pt->ob && BLI_findlink(&pt->ob->particlesystem, pt->psys - 1)) { node2 = dag_get_node(dag, pt->ob); - dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Particle Targets"); + dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Particle Targets"); } - } + } } if (part->ren_as == PART_DRAW_OB && part->dup_ob) { @@ -610,7 +610,7 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O } if (part->ren_as == PART_DRAW_GR && part->dup_group) { - for (go=part->dup_group->gobject.first; go; go=go->next) { + for (go = part->dup_group->gobject.first; go; go = go->next) { node2 = dag_get_node(dag, go->ob); dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Particle Group Visualisation"); } @@ -618,23 +618,25 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O effectors = pdInitEffectors(scene, ob, psys, part->effector_weights); - if (effectors) for (eff = effectors->first; eff; eff=eff->next) { - if (eff->psys) { - node2 = dag_get_node(dag, eff->ob); - dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Particle Field"); + if (effectors) { + for (eff = effectors->first; eff; eff = eff->next) { + if (eff->psys) { + node2 = dag_get_node(dag, eff->ob); + dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Particle Field"); + } } } pdEndEffectors(&effectors); if (part->boids) { - for (state = part->boids->states.first; state; state=state->next) { - for (rule = state->rules.first; rule; rule=rule->next) { + for (state = part->boids->states.first; state; state = state->next) { + for (rule = state->rules.first; rule; rule = rule->next) { Object *ruleob = NULL; - if (rule->type==eBoidRuleType_Avoid) - ruleob = ((BoidRuleGoalAvoid*)rule)->ob; - else if (rule->type==eBoidRuleType_FollowLeader) - ruleob = ((BoidRuleFollowLeader*)rule)->ob; + if (rule->type == eBoidRuleType_Avoid) + ruleob = ((BoidRuleGoalAvoid *)rule)->ob; + else if (rule->type == eBoidRuleType_FollowLeader) + ruleob = ((BoidRuleFollowLeader *)rule)->ob; if (ruleob) { node2 = dag_get_node(dag, ruleob); @@ -647,8 +649,8 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O } /* object constraints */ - for (con = ob->constraints.first; con; con=con->next) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + for (con = ob->constraints.first; con; con = con->next) { + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); ListBase targets = {NULL, NULL}; bConstraintTarget *ct; @@ -657,25 +659,25 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O /* special case for camera tracking -- it doesn't use targets to define relations */ if (ELEM3(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER, CONSTRAINT_TYPE_OBJECTSOLVER)) { - int depends_on_camera= 0; + int depends_on_camera = 0; - if (cti->type==CONSTRAINT_TYPE_FOLLOWTRACK) { - bFollowTrackConstraint *data= (bFollowTrackConstraint *)con->data; + if (cti->type == CONSTRAINT_TYPE_FOLLOWTRACK) { + bFollowTrackConstraint *data = (bFollowTrackConstraint *)con->data; - if ((data->clip || data->flag&FOLLOWTRACK_ACTIVECLIP) && data->track[0]) - depends_on_camera= 1; + if ((data->clip || data->flag & FOLLOWTRACK_ACTIVECLIP) && data->track[0]) + depends_on_camera = 1; if (data->depth_ob) { node2 = dag_get_node(dag, data->depth_ob); - dag_add_relation(dag, node2, node, DAG_RL_DATA_OB|DAG_RL_OB_OB, cti->name); + dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, cti->name); } } - else if (cti->type==CONSTRAINT_TYPE_OBJECTSOLVER) - depends_on_camera= 1; + else if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER) + depends_on_camera = 1; if (depends_on_camera && scene->camera) { node2 = dag_get_node(dag, scene->camera); - dag_add_relation(dag, node2, node, DAG_RL_DATA_OB|DAG_RL_OB_OB, cti->name); + dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, cti->name); } dag_add_relation(dag, scenenode, node, DAG_RL_SCENE, "Scene Relation"); @@ -684,20 +686,20 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O else if (cti->get_constraint_targets) { cti->get_constraint_targets(con, &targets); - for (ct= targets.first; ct; ct= ct->next) { + for (ct = targets.first; ct; ct = ct->next) { Object *obt; if (ct->tar) - obt= ct->tar; + obt = ct->tar; else continue; node2 = dag_get_node(dag, obt); if (ELEM(con->type, CONSTRAINT_TYPE_FOLLOWPATH, CONSTRAINT_TYPE_CLAMPTO)) - dag_add_relation(dag, node2, node, DAG_RL_DATA_OB|DAG_RL_OB_OB, cti->name); + dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, cti->name); else { if (ELEM3(obt->type, OB_ARMATURE, OB_MESH, OB_LATTICE) && (ct->subtarget[0])) { - dag_add_relation(dag, node2, node, DAG_RL_DATA_OB|DAG_RL_OB_OB, cti->name); + dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, cti->name); if (obt->type == OB_MESH) node2->customdata_mask |= CD_MASK_MDEFORMVERT; } @@ -712,12 +714,11 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O } } - if (addtoroot == 1 ) + if (addtoroot == 1) dag_add_relation(dag, scenenode, node, DAG_RL_SCENE, "Scene Relation"); } -struct DagForest *build_dag(Main *bmain, Scene *sce, short mask) -{ +struct DagForest *build_dag(Main *bmain, Scene *sce, short mask){ Base *base; Object *ob; Group *group; @@ -728,8 +729,8 @@ struct DagForest *build_dag(Main *bmain, Scene *sce, short mask) DagAdjList *itA; dag = sce->theDag; - sce->dagisvalid=1; - if ( dag) + sce->dagisvalid = 1; + if (dag) free_forest(dag); else { dag = dag_init(); @@ -740,8 +741,8 @@ struct DagForest *build_dag(Main *bmain, Scene *sce, short mask) scenenode = dag_add_node(dag, sce); /* add current scene objects */ - for (base = sce->base.first; base; base= base->next) { - ob= base->object; + for (base = sce->base.first; base; base = base->next) { + ob = base->object; build_dag_object(dag, scenenode, sce, ob, mask); if (ob->proxy) @@ -753,9 +754,9 @@ struct DagForest *build_dag(Main *bmain, Scene *sce, short mask) } /* add groups used in current scene objects */ - for (group= bmain->group.first; group; group= group->id.next) { + for (group = bmain->group.first; group; group = group->id.next) { if (group->id.flag & LIB_DOIT) { - for (go= group->gobject.first; go; go= go->next) { + for (go = group->gobject.first; go; go = go->next) { build_dag_object(dag, scenenode, sce, go->ob, mask); } group->id.flag &= ~LIB_DOIT; @@ -767,23 +768,23 @@ struct DagForest *build_dag(Main *bmain, Scene *sce, short mask) * the relation type has to be synced. One of the parents can change, and should give same event to child */ /* nodes were callocced, so we can use node->color for temporal storage */ - for (node = sce->theDag->DagNode.first; node; node= node->next) { - if (node->type==ID_OB) { - for (itA = node->child; itA; itA= itA->next) { - if (itA->node->type==ID_OB) { + for (node = sce->theDag->DagNode.first; node; node = node->next) { + if (node->type == ID_OB) { + for (itA = node->child; itA; itA = itA->next) { + if (itA->node->type == ID_OB) { itA->node->color |= itA->type; } } /* also flush custom data mask */ - ((Object*)node->ob)->customdata_mask= node->customdata_mask; + ((Object *)node->ob)->customdata_mask = node->customdata_mask; } } /* now set relations equal, so that when only one parent changes, the correct recalcs are found */ - for (node = sce->theDag->DagNode.first; node; node= node->next) { - if (node->type==ID_OB) { - for (itA = node->child; itA; itA= itA->next) { - if (itA->node->type==ID_OB) { + for (node = sce->theDag->DagNode.first; node; node = node->next) { + if (node->type == ID_OB) { + for (itA = node->child; itA; itA = itA->next) { + if (itA->node->type == ID_OB) { itA->type |= itA->node->color; } } @@ -825,14 +826,14 @@ void free_forest(DagForest *Dag) } BLI_ghash_free(Dag->nodeHash, NULL, NULL); - Dag->nodeHash= NULL; + Dag->nodeHash = NULL; Dag->DagNode.first = NULL; Dag->DagNode.last = NULL; Dag->numNodes = 0; } -DagNode * dag_find_node (DagForest *forest, void * fob) +DagNode *dag_find_node(DagForest *forest, void *fob) { if (forest->nodeHash) return BLI_ghash_lookup(forest->nodeHash, fob); @@ -840,11 +841,11 @@ DagNode * dag_find_node (DagForest *forest, void * fob) return NULL; } -static int ugly_hack_sorry= 1; // prevent type check -static int dag_print_dependencies= 0; // debugging +static int ugly_hack_sorry = 1; // prevent type check +static int dag_print_dependencies = 0; // debugging /* no checking of existence, use dag_find_node first or dag_get_node */ -DagNode * dag_add_node (DagForest *forest, void * fob) +DagNode *dag_add_node(DagForest *forest, void *fob) { DagNode *node; @@ -853,7 +854,7 @@ DagNode * dag_add_node (DagForest *forest, void * fob) node->ob = fob; node->color = DAG_WHITE; - if (ugly_hack_sorry) node->type = GS(((ID *) fob)->name); // sorry, done for pose sorting + if (ugly_hack_sorry) node->type = GS(((ID *) fob)->name); // sorry, done for pose sorting if (forest->numNodes) { ((DagNode *) forest->DagNode.last)->next = node; forest->DagNode.last = node; @@ -866,18 +867,18 @@ DagNode * dag_add_node (DagForest *forest, void * fob) } if (!forest->nodeHash) - forest->nodeHash= BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "dag_add_node gh"); + forest->nodeHash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "dag_add_node gh"); BLI_ghash_insert(forest->nodeHash, fob, node); } return node; } -DagNode * dag_get_node (DagForest *forest, void * fob) +DagNode *dag_get_node(DagForest *forest, void *fob) { DagNode *node; - node = dag_find_node (forest, fob); + node = dag_find_node(forest, fob); if (!node) node = dag_add_node(forest, fob); return node; @@ -885,10 +886,10 @@ DagNode * dag_get_node (DagForest *forest, void * fob) -DagNode * dag_get_sub_node (DagForest *forest, void * fob) +DagNode *dag_get_sub_node(DagForest *forest, void *fob) { DagNode *node; - DagAdjList *mainchild, *prev=NULL; + DagAdjList *mainchild, *prev = NULL; mainchild = ((DagNode *) forest->DagNode.first)->child; /* remove from first node (scene) adj list if present */ @@ -908,7 +909,7 @@ DagNode * dag_get_sub_node (DagForest *forest, void * fob) prev = mainchild; mainchild = mainchild->next; } - node = dag_find_node (forest, fob); + node = dag_find_node(forest, fob); if (!node) node = dag_add_node(forest, fob); return node; @@ -966,9 +967,9 @@ static const char *dag_node_name(DagNode *node) if (node->ob == NULL) return "null"; else if (ugly_hack_sorry) - return ((ID*)(node->ob))->name+2; + return ((ID *)(node->ob))->name + 2; else - return ((bPoseChannel*)(node->ob))->name; + return ((bPoseChannel *)(node->ob))->name; } static void dag_node_print_dependencies(DagNode *node) @@ -977,7 +978,7 @@ static void dag_node_print_dependencies(DagNode *node) printf("%s depends on:\n", dag_node_name(node)); - for (itA= node->parent; itA; itA= itA->next) + for (itA = node->parent; itA; itA = itA->next) printf(" %s through %s\n", dag_node_name(itA->node), itA->name); printf("\n"); } @@ -989,12 +990,12 @@ static int dag_node_print_dependency_recurs(DagNode *node, DagNode *endnode) if (node->color == DAG_BLACK) return 0; - node->color= DAG_BLACK; + node->color = DAG_BLACK; if (node == endnode) return 1; - for (itA= node->parent; itA; itA= itA->next) { + for (itA = node->parent; itA; itA = itA->next) { if (dag_node_print_dependency_recurs(itA->node, endnode)) { printf(" %s depends on %s through %s.\n", dag_node_name(node), dag_node_name(itA->node), itA->name); return 1; @@ -1008,8 +1009,8 @@ static void dag_node_print_dependency_cycle(DagForest *dag, DagNode *startnode, { DagNode *node; - for (node = dag->DagNode.first; node; node= node->next) - node->color= DAG_WHITE; + for (node = dag->DagNode.first; node; node = node->next) + node->color = DAG_WHITE; printf(" %s depends on %s through %s.\n", dag_node_name(endnode), dag_node_name(startnode), name); dag_node_print_dependency_recurs(startnode, endnode); @@ -1021,16 +1022,16 @@ static int dag_node_recurs_level(DagNode *node, int level) DagAdjList *itA; int newlevel; - node->color= DAG_BLACK; /* done */ - newlevel= ++level; + node->color = DAG_BLACK; /* done */ + newlevel = ++level; - for (itA= node->parent; itA; itA= itA->next) { - if (itA->node->color==DAG_WHITE) { - itA->node->ancestor_count= dag_node_recurs_level(itA->node, level); - newlevel= MAX2(newlevel, level+itA->node->ancestor_count); + for (itA = node->parent; itA; itA = itA->next) { + if (itA->node->color == DAG_WHITE) { + itA->node->ancestor_count = dag_node_recurs_level(itA->node, level); + newlevel = MAX2(newlevel, level + itA->node->ancestor_count); } else - newlevel= MAX2(newlevel, level+itA->node->ancestor_count); + newlevel = MAX2(newlevel, level + itA->node->ancestor_count); } return newlevel; @@ -1043,22 +1044,22 @@ static void dag_check_cycle(DagForest *dag) /* debugging print */ if (dag_print_dependencies) - for (node = dag->DagNode.first; node; node= node->next) + for (node = dag->DagNode.first; node; node = node->next) dag_node_print_dependencies(node); /* tag nodes unchecked */ - for (node = dag->DagNode.first; node; node= node->next) - node->color= DAG_WHITE; + for (node = dag->DagNode.first; node; node = node->next) + node->color = DAG_WHITE; - for (node = dag->DagNode.first; node; node= node->next) { - if (node->color==DAG_WHITE) { - node->ancestor_count= dag_node_recurs_level(node, 0); + for (node = dag->DagNode.first; node; node = node->next) { + if (node->color == DAG_WHITE) { + node->ancestor_count = dag_node_recurs_level(node, 0); } } /* check relations, and print errors */ - for (node = dag->DagNode.first; node; node= node->next) { - for (itA= node->parent; itA; itA= itA->next) { + for (node = dag->DagNode.first; node; node = node->next) { + for (itA = node->parent; itA; itA = itA->next) { if (itA->node->ancestor_count > node->ancestor_count) { if (node->ob && itA->node->ob) { printf("Dependency cycle detected:\n"); @@ -1069,7 +1070,7 @@ static void dag_check_cycle(DagForest *dag) } /* parent relations are only needed for cycle checking, so free now */ - for (node = dag->DagNode.first; node; node= node->next) { + for (node = dag->DagNode.first; node; node = node->next) { while (node->parent) { itA = node->parent->next; MEM_freeN(node->parent); @@ -1082,7 +1083,7 @@ static void dag_check_cycle(DagForest *dag) * MainDAG is the DAG of all objects in current scene * used only for drawing there is one also in each scene */ -static DagForest * MainDag = NULL; +static DagForest *MainDag = NULL; DagForest *getMainDag(void) { @@ -1121,7 +1122,7 @@ void graph_bfs(void) /* fprintf(stderr, "starting BFS\n ------------\n"); */ nqueue = queue_create(DAGQUEUEALLOC); - for ( i=0; i<50; i++) + for (i = 0; i < 50; i++) pos[i] = 0; /* Init @@ -1160,14 +1161,14 @@ void graph_bfs(void) itA = itA->next; } - if (pos[node->BFS_dist] > node->k ) { + if (pos[node->BFS_dist] > node->k) { pos[node->BFS_dist] += 1; node->k = (float) pos[node->BFS_dist]; } else { - pos[node->BFS_dist] = (int) node->k +1; + pos[node->BFS_dist] = (int) node->k + 1; } - set_node_xy(node, node->BFS_dist*DEPSX*2, pos[node->BFS_dist]*DEPSY*2); + set_node_xy(node, node->BFS_dist * DEPSX * 2, pos[node->BFS_dist] * DEPSY * 2); node->color = DAG_BLACK; // fprintf(stderr, "BFS node : %20s %i %5.0f %5.0f\n", ((ID *) node->ob)->name, node->BFS_dist, node->x, node->y); @@ -1190,7 +1191,7 @@ int pre_and_post_source_BFS(DagForest *dag, short mask, DagNode *source, graph_a DagNode *node; DagNodeQueue *nqueue; DagAdjList *itA; - int retval = 0; + int retval = 0; /* fprintf(stderr, "starting BFS\n ------------\n"); */ /* Init @@ -1238,7 +1239,7 @@ int pre_and_post_source_BFS(DagForest *dag, short mask, DagNode *source, graph_a } /* non recursive version of DFS, return queue -- outer loop present to catch odd cases (first level cycles)*/ -DagNodeQueue * graph_dfs(void) +DagNodeQueue *graph_dfs(void) { DagNode *node; DagNodeQueue *nqueue; @@ -1249,14 +1250,14 @@ DagNodeQueue * graph_dfs(void) int time; int skip = 0; int minheight; - int maxpos=0; + int maxpos = 0; /* int is_cycle = 0; */ /* UNUSED */ /* - *fprintf(stderr, "starting DFS\n ------------\n"); + *fprintf(stderr, "starting DFS\n ------------\n"); */ nqueue = queue_create(DAGQUEUEALLOC); retqueue = queue_create(MainDag->numNodes); - for ( i=0; i<50; i++) + for (i = 0; i < 50; i++) pos[i] = 0; /* Init @@ -1276,86 +1277,86 @@ DagNodeQueue * graph_dfs(void) node = MainDag->DagNode.first; do { - if (node->color == DAG_WHITE) { - node->color = DAG_GRAY; - node->DFS_dist = 1; - node->DFS_dvtm = time; - time++; - push_stack(nqueue, node); + if (node->color == DAG_WHITE) { + node->color = DAG_GRAY; + node->DFS_dist = 1; + node->DFS_dvtm = time; + time++; + push_stack(nqueue, node); - while (nqueue->count) { - //graph_print_queue(nqueue); + while (nqueue->count) { + //graph_print_queue(nqueue); - skip = 0; - node = get_top_node_queue(nqueue); + skip = 0; + node = get_top_node_queue(nqueue); - minheight = pos[node->DFS_dist]; + minheight = pos[node->DFS_dist]; - itA = node->child; - while (itA != NULL) { - if (itA->node->color == DAG_WHITE) { - itA->node->DFS_dvtm = time; - itA->node->color = DAG_GRAY; + itA = node->child; + while (itA != NULL) { + if (itA->node->color == DAG_WHITE) { + itA->node->DFS_dvtm = time; + itA->node->color = DAG_GRAY; - time++; - itA->node->DFS_dist = node->DFS_dist + 1; - itA->node->k = (float) minheight; - push_stack(nqueue, itA->node); - skip = 1; - break; - } - else { - if (itA->node->color == DAG_GRAY) { // back edge - fprintf(stderr, "dfs back edge :%15s %15s\n", ((ID *) node->ob)->name, ((ID *) itA->node->ob)->name); - /* is_cycle = 1; */ /* UNUSED */ + time++; + itA->node->DFS_dist = node->DFS_dist + 1; + itA->node->k = (float) minheight; + push_stack(nqueue, itA->node); + skip = 1; + break; } - else if (itA->node->color == DAG_BLACK) { - /* already processed node but we may want later to change distance either to shorter to longer. - * DFS_dist is the first encounter - */ + else { + if (itA->node->color == DAG_GRAY) { // back edge + fprintf(stderr, "dfs back edge :%15s %15s\n", ((ID *) node->ob)->name, ((ID *) itA->node->ob)->name); + /* is_cycle = 1; */ /* UNUSED */ + } + else if (itA->node->color == DAG_BLACK) { + /* already processed node but we may want later to change distance either to shorter to longer. + * DFS_dist is the first encounter + */ #if 0 - if (node->DFS_dist >= itA->node->DFS_dist) - itA->node->DFS_dist = node->DFS_dist + 1; + if (node->DFS_dist >= itA->node->DFS_dist) + itA->node->DFS_dist = node->DFS_dist + 1; fprintf(stderr, "dfs forward or cross edge :%15s %i-%i %15s %i-%i\n", - ((ID *) node->ob)->name, - node->DFS_dvtm, - node->DFS_fntm, - ((ID *) itA->node->ob)->name, - itA->node->DFS_dvtm, - itA->node->DFS_fntm); + ((ID *) node->ob)->name, + node->DFS_dvtm, + node->DFS_fntm, + ((ID *) itA->node->ob)->name, + itA->node->DFS_dvtm, + itA->node->DFS_fntm); #endif + } + else + fprintf(stderr, "dfs unknown edge\n"); } - else - fprintf(stderr, "dfs unknown edge\n"); + itA = itA->next; } - itA = itA->next; - } - if (!skip) { - node = pop_queue(nqueue); - node->color = DAG_BLACK; + if (!skip) { + node = pop_queue(nqueue); + node->color = DAG_BLACK; - node->DFS_fntm = time; - time++; - if (node->DFS_dist > maxpos) - maxpos = node->DFS_dist; - if (pos[node->DFS_dist] > node->k ) { - pos[node->DFS_dist] += 1; - node->k = (float) pos[node->DFS_dist]; - } - else { - pos[node->DFS_dist] = (int) node->k +1; - } - set_node_xy(node, node->DFS_dist*DEPSX*2, pos[node->DFS_dist]*DEPSY*2); + node->DFS_fntm = time; + time++; + if (node->DFS_dist > maxpos) + maxpos = node->DFS_dist; + if (pos[node->DFS_dist] > node->k) { + pos[node->DFS_dist] += 1; + node->k = (float) pos[node->DFS_dist]; + } + else { + pos[node->DFS_dist] = (int) node->k + 1; + } + set_node_xy(node, node->DFS_dist * DEPSX * 2, pos[node->DFS_dist] * DEPSY * 2); - // fprintf(stderr, "DFS node : %20s %i %i %i %i\n", ((ID *) node->ob)->name, node->BFS_dist, node->DFS_dist, node->DFS_dvtm, node->DFS_fntm ); + // fprintf(stderr, "DFS node : %20s %i %i %i %i\n", ((ID *) node->ob)->name, node->BFS_dist, node->DFS_dist, node->DFS_dvtm, node->DFS_fntm ); - push_stack(retqueue, node); + push_stack(retqueue, node); + } } } - } node = node->next; } while (node); // fprintf(stderr, "i size : %i\n", maxpos); @@ -1382,7 +1383,7 @@ int pre_and_post_source_DFS(DagForest *dag, short mask, DagNode *source, graph_a int skip = 0; int retval = 0; /* - *fprintf(stderr, "starting DFS\n ------------\n"); + * fprintf(stderr, "starting DFS\n ------------\n"); */ nqueue = queue_create(DAGQUEUEALLOC); @@ -1429,7 +1430,7 @@ int pre_and_post_source_DFS(DagForest *dag, short mask, DagNode *source, graph_a break; } else { - if (itA->node->color == DAG_GRAY) {// back edge + if (itA->node->color == DAG_GRAY) { // back edge retval = 1; } // else if (itA->node->color == DAG_BLACK) { // cross or forward @@ -1457,14 +1458,13 @@ int pre_and_post_source_DFS(DagForest *dag, short mask, DagNode *source, graph_a // used to get the obs owning a datablock -struct DagNodeQueue *get_obparents(struct DagForest *dag, void *ob) -{ - DagNode * node, *node1; +struct DagNodeQueue *get_obparents(struct DagForest *dag, void *ob){ + DagNode *node, *node1; DagNodeQueue *nqueue; DagAdjList *itA; node = dag_find_node(dag, ob); - if (node==NULL) { + if (node == NULL) { return NULL; } else if (node->ancestor_count == 1) { // simple case @@ -1491,9 +1491,8 @@ struct DagNodeQueue *get_obparents(struct DagForest *dag, void *ob) return nqueue; } -struct DagNodeQueue *get_first_ancestors(struct DagForest *dag, void *ob) -{ - DagNode * node, *node1; +struct DagNodeQueue *get_first_ancestors(struct DagForest *dag, void *ob){ + DagNode *node, *node1; DagNodeQueue *nqueue; DagAdjList *itA; @@ -1520,8 +1519,7 @@ struct DagNodeQueue *get_first_ancestors(struct DagForest *dag, void *ob) } // standard DFS list -struct DagNodeQueue *get_all_childs(struct DagForest *dag, void *ob) -{ +struct DagNodeQueue *get_all_childs(struct DagForest *dag, void *ob){ DagNode *node; DagNodeQueue *nqueue; DagNodeQueue *retqueue; @@ -1581,9 +1579,9 @@ struct DagNodeQueue *get_all_childs(struct DagForest *dag, void *ob) /* unused */ #if 0 -short are_obs_related(struct DagForest *dag, void *ob1, void *ob2) +short are_obs_related(struct DagForest *dag, void *ob1, void *ob2) { - DagNode * node; + DagNode *node; DagAdjList *itA; node = dag_find_node(dag, ob1); @@ -1599,7 +1597,7 @@ short are_obs_related(struct DagForest *dag, void *ob1, void *ob2) } #endif -int is_acyclic(DagForest *dag) +int is_acyclic(DagForest *dag) { return dag->is_acyclic; } @@ -1634,9 +1632,9 @@ void graph_print_queue_dist(DagNodeQueue *nqueue) count = 0; while (queueElem) { fprintf(stderr, "** %25s %2.2i-%2.2i ", ((ID *) queueElem->node->ob)->name, queueElem->node->DFS_dvtm, queueElem->node->DFS_fntm); - while (count < queueElem->node->DFS_dvtm-1) { fputc(' ', stderr); count++;} + while (count < queueElem->node->DFS_dvtm - 1) { fputc(' ', stderr); count++; } fputc('|', stderr); - while (count < queueElem->node->DFS_fntm-2) { fputc('-', stderr); count++;} + while (count < queueElem->node->DFS_fntm - 2) { fputc('-', stderr); count++; } fputc('|', stderr); fputc('\n', stderr); count = 0; @@ -1668,13 +1666,13 @@ void graph_print_adj_list(void) /* mechanism to allow editors to be informed of depsgraph updates, * to do their own updates based on changes... */ -static void (*EditorsUpdateIDCb)(Main *bmain, ID *id)= NULL; -static void (*EditorsUpdateSceneCb)(Main *bmain, Scene *scene, int updated)= NULL; +static void (*EditorsUpdateIDCb)(Main *bmain, ID *id) = NULL; +static void (*EditorsUpdateSceneCb)(Main *bmain, Scene *scene, int updated) = NULL; void DAG_editors_update_cb(void (*id_func)(Main *bmain, ID *id), void (*scene_func)(Main *bmain, Scene *scene, int updated)) { - EditorsUpdateIDCb= id_func; - EditorsUpdateSceneCb= scene_func; + EditorsUpdateIDCb = id_func; + EditorsUpdateSceneCb = scene_func; } static void dag_editors_id_update(Main *bmain, ID *id) @@ -1698,37 +1696,37 @@ static void scene_sort_groups(Main *bmain, Scene *sce) Object *ob; /* test; are group objects all in this scene? */ - for (ob= bmain->object.first; ob; ob= ob->id.next) { + for (ob = bmain->object.first; ob; ob = ob->id.next) { ob->id.flag &= ~LIB_DOIT; - ob->id.newid= NULL; /* newid abuse for GroupObject */ + ob->id.newid = NULL; /* newid abuse for GroupObject */ } - for (base = sce->base.first; base; base= base->next) + for (base = sce->base.first; base; base = base->next) base->object->id.flag |= LIB_DOIT; - for (group= bmain->group.first; group; group= group->id.next) { - for (go= group->gobject.first; go; go= go->next) { - if ((go->ob->id.flag & LIB_DOIT)==0) + for (group = bmain->group.first; group; group = group->id.next) { + for (go = group->gobject.first; go; go = go->next) { + if ((go->ob->id.flag & LIB_DOIT) == 0) break; } /* this group is entirely in this scene */ - if (go==NULL) { - ListBase listb= {NULL, NULL}; + if (go == NULL) { + ListBase listb = {NULL, NULL}; - for (go= group->gobject.first; go; go= go->next) - go->ob->id.newid= (ID *)go; + for (go = group->gobject.first; go; go = go->next) + go->ob->id.newid = (ID *)go; /* in order of sorted bases we reinsert group objects */ - for (base = sce->base.first; base; base= base->next) { + for (base = sce->base.first; base; base = base->next) { if (base->object->id.newid) { - go= (GroupObject *)base->object->id.newid; - base->object->id.newid= NULL; + go = (GroupObject *)base->object->id.newid; + base->object->id.newid = NULL; BLI_remlink(&group->gobject, go); BLI_addtail(&listb, go); } } /* copy the newly sorted listbase */ - group->gobject= listb; + group->gobject = listb; } } } @@ -1744,7 +1742,7 @@ void DAG_scene_sort(Main *bmain, Scene *sce) ListBase tempbase; Base *base; - tempbase.first= tempbase.last= NULL; + tempbase.first = tempbase.last = NULL; build_dag(bmain, sce, DAG_RL_ALL_BUT_DATA); @@ -1752,7 +1750,7 @@ void DAG_scene_sort(Main *bmain, Scene *sce) nqueue = queue_create(DAGQUEUEALLOC); - for (node = sce->theDag->DagNode.first; node; node= node->next) { + for (node = sce->theDag->DagNode.first; node; node = node->next) { node->color = DAG_WHITE; } @@ -1785,7 +1783,7 @@ void DAG_scene_sort(Main *bmain, Scene *sce) if (!skip) { if (node) { node = pop_queue(nqueue); - if (node->ob == sce) // we are done + if (node->ob == sce) // we are done break; node->color = DAG_BLACK; @@ -1807,7 +1805,7 @@ void DAG_scene_sort(Main *bmain, Scene *sce) BLI_remlink(&sce->base, base); BLI_addhead(&tempbase, base); //if (G.debug & G_DEBUG) - printf("cyclic %s\n", base->object->id.name); + printf("cyclic %s\n", base->object->id.name); base = sce->base.first; } @@ -1819,12 +1817,12 @@ void DAG_scene_sort(Main *bmain, Scene *sce) if (G.debug & G_DEBUG) { printf("\nordered\n"); - for (base = sce->base.first; base; base= base->next) { + for (base = sce->base.first; base; base = base->next) { printf(" %s\n", base->object->id.name); } } /* temporal...? */ - sce->recalc |= SCE_PRV_CHANGED; /* test for 3d preview */ + sce->recalc |= SCE_PRV_CHANGED; /* test for 3d preview */ } static void lib_id_recalc_tag(Main *bmain, ID *id) @@ -1842,26 +1840,26 @@ static void lib_id_recalc_data_tag(Main *bmain, ID *id) /* node was checked to have lasttime != curtime and is if type ID_OB */ static void flush_update_node(DagNode *node, unsigned int layer, int curtime) { - Main *bmain= G.main; + Main *bmain = G.main; DagAdjList *itA; Object *ob, *obc; - int oldflag, changed=0; + int oldflag, changed = 0; unsigned int all_layer; - node->lasttime= curtime; + node->lasttime = curtime; - ob= node->ob; + ob = node->ob; if (ob && (ob->recalc & OB_RECALC_ALL)) { - all_layer= node->scelay; + all_layer = node->scelay; /* got an object node that changes, now check relations */ - for (itA = node->child; itA; itA= itA->next) { + for (itA = node->child; itA; itA = itA->next) { all_layer |= itA->lay; /* the relationship is visible */ if ((itA->lay & layer)) { // XXX || (itA->node->ob == obedit) - if (itA->node->type==ID_OB) { - obc= itA->node->ob; - oldflag= obc->recalc; + if (itA->node->type == ID_OB) { + obc = itA->node->ob; + oldflag = obc->recalc; /* got a ob->obc relation, now check if flag needs flush */ if (ob->recalc & OB_RECALC_OB) { @@ -1888,15 +1886,15 @@ static void flush_update_node(DagNode *node, unsigned int layer, int curtime) lib_id_recalc_data_tag(bmain, &obc->id); } } - if (oldflag!=obc->recalc) changed= 1; + if (oldflag != obc->recalc) changed = 1; } } } /* even nicer, we can clear recalc flags... */ - if ((all_layer & layer)==0) { // XXX && (ob != obedit)) { + if ((all_layer & layer) == 0) { // XXX && (ob != obedit)) { /* but existing displaylists or derivedmesh should be freed */ if (ob->recalc & OB_RECALC_DATA) - object_free_display(ob); + BKE_object_free_display(ob); ob->recalc &= ~OB_RECALC_ALL; } @@ -1905,15 +1903,15 @@ static void flush_update_node(DagNode *node, unsigned int layer, int curtime) /* check case where child changes and parent forcing obdata to change */ /* should be done regardless if this ob has recalc set */ /* could merge this in with loop above...? (ton) */ - for (itA = node->child; itA; itA= itA->next) { + for (itA = node->child; itA; itA = itA->next) { /* the relationship is visible */ - if ((itA->lay & layer)) { // XXX || (itA->node->ob == obedit) - if (itA->node->type==ID_OB) { - obc= itA->node->ob; + if ((itA->lay & layer)) { // XXX || (itA->node->ob == obedit) + if (itA->node->type == ID_OB) { + obc = itA->node->ob; /* child moves */ - if ((obc->recalc & OB_RECALC_ALL)==OB_RECALC_OB) { + if ((obc->recalc & OB_RECALC_ALL) == OB_RECALC_OB) { /* parent has deforming info */ - if (itA->type & (DAG_RL_OB_DATA|DAG_RL_DATA_DATA)) { + if (itA->type & (DAG_RL_OB_DATA | DAG_RL_DATA_DATA)) { // printf("parent %s changes ob %s\n", ob->id.name, obc->id.name); obc->recalc |= OB_RECALC_DATA; lib_id_recalc_data_tag(bmain, &obc->id); @@ -1924,8 +1922,8 @@ static void flush_update_node(DagNode *node, unsigned int layer, int curtime) } /* we only go deeper if node not checked or something changed */ - for (itA = node->child; itA; itA= itA->next) { - if (changed || itA->node->lasttime!=curtime) + for (itA = node->child; itA; itA = itA->next) { + if (changed || itA->node->lasttime != curtime) flush_update_node(itA->node, layer, curtime); } @@ -1936,15 +1934,15 @@ static unsigned int flush_layer_node(Scene *sce, DagNode *node, int curtime) { DagAdjList *itA; - node->lasttime= curtime; - node->lay= node->scelay; + node->lasttime = curtime; + node->lay = node->scelay; - for (itA = node->child; itA; itA= itA->next) { - if (itA->node->type==ID_OB) { - if (itA->node->lasttime!=curtime) { - itA->lay= flush_layer_node(sce, itA->node, curtime); // lay is only set once for each relation + for (itA = node->child; itA; itA = itA->next) { + if (itA->node->type == ID_OB) { + if (itA->node->lasttime != curtime) { + itA->lay = flush_layer_node(sce, itA->node, curtime); // lay is only set once for each relation } - else itA->lay= itA->node->lay; + else itA->lay = itA->node->lay; node->lay |= itA->lay; } @@ -1956,16 +1954,16 @@ static unsigned int flush_layer_node(Scene *sce, DagNode *node, int curtime) /* node was checked to have lasttime != curtime, and is of type ID_OB */ static void flush_pointcache_reset(Scene *scene, DagNode *node, int curtime, int reset) { - Main *bmain= G.main; + Main *bmain = G.main; DagAdjList *itA; Object *ob; - node->lasttime= curtime; + node->lasttime = curtime; - for (itA = node->child; itA; itA= itA->next) { - if (itA->node->type==ID_OB) { - if (itA->node->lasttime!=curtime) { - ob= (Object*)(itA->node->ob); + for (itA = node->child; itA; itA = itA->next) { + if (itA->node->type == ID_OB) { + if (itA->node->lasttime != curtime) { + ob = (Object *)(itA->node->ob); if (reset || (ob->recalc & OB_RECALC_ALL)) { if (BKE_ptcache_object_reset(scene, ob, PTCACHE_RESET_DEPSGRAPH)) { @@ -1990,18 +1988,18 @@ static void dag_scene_flush_layers(Scene *sce, int lay) Base *base; int lasttime; - firstnode= sce->theDag->DagNode.first; // always scene node + firstnode = sce->theDag->DagNode.first; // always scene node - for (itA = firstnode->child; itA; itA= itA->next) - itA->lay= 0; + for (itA = firstnode->child; itA; itA = itA->next) + itA->lay = 0; - sce->theDag->time++; // so we know which nodes were accessed - lasttime= sce->theDag->time; + sce->theDag->time++; // so we know which nodes were accessed + lasttime = sce->theDag->time; /* update layer flags in nodes */ - for (base= sce->base.first; base; base= base->next) { - node= dag_get_node(sce->theDag, base->object); - node->scelay= base->object->lay; + for (base = sce->base.first; base; base = base->next) { + node = dag_get_node(sce->theDag, base->object); + node->scelay = base->object->lay; } /* ensure cameras are set as if they are on a visible layer, because @@ -2009,7 +2007,7 @@ static void dag_scene_flush_layers(Scene *sce, int lay) * * XXX, this wont work for local view / unlocked camera's */ if (sce->camera) { - node= dag_get_node(sce->theDag, sce->camera); + node = dag_get_node(sce->theDag, sce->camera); node->scelay |= lay; } @@ -2017,9 +2015,9 @@ static void dag_scene_flush_layers(Scene *sce, int lay) { TimeMarker *m; - for (m= sce->markers.first; m; m= m->next) { + for (m = sce->markers.first; m; m = m->next) { if (m->camera) { - node= dag_get_node(sce->theDag, m->camera); + node = dag_get_node(sce->theDag, m->camera); node->scelay |= lay; } } @@ -2027,8 +2025,8 @@ static void dag_scene_flush_layers(Scene *sce, int lay) #endif /* flush layer nodes to dependencies */ - for (itA = firstnode->child; itA; itA= itA->next) - if (itA->node->lasttime!=lasttime && itA->node->type==ID_OB) + for (itA = firstnode->child; itA; itA = itA->next) + if (itA->node->lasttime != lasttime && itA->node->type == ID_OB) flush_layer_node(sce, itA->node, lasttime); } @@ -2037,16 +2035,16 @@ static void dag_tag_renderlayers(Scene *sce, unsigned int lay) if (sce->nodetree) { bNode *node; Base *base; - unsigned int lay_changed= 0; + unsigned int lay_changed = 0; - for (base= sce->base.first; base; base= base->next) + for (base = sce->base.first; base; base = base->next) if (base->lay & lay) if (base->object->recalc) lay_changed |= base->lay; - for (node= sce->nodetree->nodes.first; node; node= node->next) { - if (node->id==(ID *)sce) { - SceneRenderLayer *srl= BLI_findlink(&sce->r.layers, node->custom1); + for (node = sce->nodetree->nodes.first; node; node = node->next) { + if (node->id == (ID *)sce) { + SceneRenderLayer *srl = BLI_findlink(&sce->r.layers, node->custom1); if (srl && (srl->lay & lay_changed)) nodeUpdate(sce->nodetree, node); } @@ -2062,30 +2060,30 @@ void DAG_scene_flush_update(Main *bmain, Scene *sce, unsigned int lay, const sho Object *ob; int lasttime; - if (sce->theDag==NULL) { + if (sce->theDag == NULL) { printf("DAG zero... not allowed to happen!\n"); DAG_scene_sort(bmain, sce); } - firstnode= sce->theDag->DagNode.first; // always scene node + firstnode = sce->theDag->DagNode.first; // always scene node /* first we flush the layer flags */ dag_scene_flush_layers(sce, lay); /* then we use the relationships + layer info to flush update events */ - sce->theDag->time++; // so we know which nodes were accessed - lasttime= sce->theDag->time; - for (itA = firstnode->child; itA; itA= itA->next) - if (itA->node->lasttime!=lasttime && itA->node->type==ID_OB) + sce->theDag->time++; // so we know which nodes were accessed + lasttime = sce->theDag->time; + for (itA = firstnode->child; itA; itA = itA->next) + if (itA->node->lasttime != lasttime && itA->node->type == ID_OB) flush_update_node(itA->node, lay, lasttime); /* if update is not due to time change, do pointcache clears */ if (!time) { - sce->theDag->time++; // so we know which nodes were accessed - lasttime= sce->theDag->time; - for (itA = firstnode->child; itA; itA= itA->next) { - if (itA->node->lasttime!=lasttime && itA->node->type==ID_OB) { - ob= (Object*)(itA->node->ob); + sce->theDag->time++; // so we know which nodes were accessed + lasttime = sce->theDag->time; + for (itA = firstnode->child; itA; itA = itA->next) { + if (itA->node->lasttime != lasttime && itA->node->type == ID_OB) { + ob = (Object *)(itA->node->ob); if (ob->recalc & OB_RECALC_ALL) { if (BKE_ptcache_object_reset(sce, ob, PTCACHE_RESET_DEPSGRAPH)) { @@ -2109,7 +2107,7 @@ static int object_modifiers_use_time(Object *ob) ModifierData *md; /* check if a modifier in modifier stack needs time input */ - for (md=ob->modifiers.first; md; md=md->next) + for (md = ob->modifiers.first; md; md = md->next) if (modifier_dependsOnTime(md)) return 1; @@ -2148,14 +2146,14 @@ static short animdata_use_time(AnimData *adt) { NlaTrack *nlt; - if (adt==NULL) return 0; + if (adt == NULL) return 0; /* check action - only if assigned, and it has anim curves */ if (adt->action && adt->action->curves.first) return 1; /* check NLA tracks + strips */ - for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) { + for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { if (nlt->strips.first) return 1; } @@ -2184,8 +2182,8 @@ static void dag_object_time_update_flags(Object *ob) { if (ob->constraints.first) { bConstraint *con; - for (con = ob->constraints.first; con; con=con->next) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + for (con = ob->constraints.first; con; con = con->next) { + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); ListBase targets = {NULL, NULL}; bConstraintTarget *ct; @@ -2197,7 +2195,7 @@ static void dag_object_time_update_flags(Object *ob) else if (cti->get_constraint_targets) { cti->get_constraint_targets(con, &targets); - for (ct= targets.first; ct; ct= ct->next) { + for (ct = targets.first; ct; ct = ct->next) { if (ct->tar) { ob->recalc |= OB_RECALC_OB; break; @@ -2214,7 +2212,7 @@ static void dag_object_time_update_flags(Object *ob) if (ob->parent) { /* motion path or bone child */ - if (ob->parent->type==OB_CURVE || ob->parent->type==OB_ARMATURE) ob->recalc |= OB_RECALC_OB; + if (ob->parent->type == OB_CURVE || ob->parent->type == OB_ARMATURE) ob->recalc |= OB_RECALC_OB; } #if 0 // XXX old animation system @@ -2222,7 +2220,7 @@ static void dag_object_time_update_flags(Object *ob) if (ob->dup_group) { bActionStrip *strip; /* this case is for groups with nla, whilst nla target has no action or nla */ - for (strip= ob->nlastrips.first; strip; strip= strip->next) { + for (strip = ob->nlastrips.first; strip; strip = strip->next) { if (strip->object) strip->object->recalc |= OB_RECALC_ALL; } @@ -2235,20 +2233,20 @@ static void dag_object_time_update_flags(Object *ob) ob->adt->recalc |= ADT_RECALC_ANIM; } - if ((ob->adt) && (ob->type==OB_ARMATURE)) ob->recalc |= OB_RECALC_DATA; + if ((ob->adt) && (ob->type == OB_ARMATURE)) ob->recalc |= OB_RECALC_DATA; if (object_modifiers_use_time(ob)) ob->recalc |= OB_RECALC_DATA; if ((ob->pose) && (ob->pose->flag & POSE_CONSTRAINTS_TIMEDEPEND)) ob->recalc |= OB_RECALC_DATA; { - AnimData *adt= BKE_animdata_from_id((ID *)ob->data); + AnimData *adt = BKE_animdata_from_id((ID *)ob->data); Mesh *me; Curve *cu; Lattice *lt; switch (ob->type) { case OB_MESH: - me= ob->data; + me = ob->data; if (me->key) { if (!(ob->shapeflag & OB_SHAPE_LOCK)) { ob->recalc |= OB_RECALC_DATA; @@ -2259,7 +2257,7 @@ static void dag_object_time_update_flags(Object *ob) break; case OB_CURVE: case OB_SURF: - cu= ob->data; + cu = ob->data; if (cu->key) { if (!(ob->shapeflag & OB_SHAPE_LOCK)) { ob->recalc |= OB_RECALC_DATA; @@ -2267,18 +2265,18 @@ static void dag_object_time_update_flags(Object *ob) } break; case OB_FONT: - cu= ob->data; - if (cu->nurb.first==NULL && cu->str && cu->vfont) + cu = ob->data; + if (cu->nurb.first == NULL && cu->str && cu->vfont) ob->recalc |= OB_RECALC_DATA; break; case OB_LATTICE: - lt= ob->data; + lt = ob->data; if (lt->key) { if (!(ob->shapeflag & OB_SHAPE_LOCK)) { ob->recalc |= OB_RECALC_DATA; } } - break; + break; case OB_MBALL: if (ob->transflag & OB_DUPLI) ob->recalc |= OB_RECALC_DATA; break; @@ -2290,9 +2288,9 @@ static void dag_object_time_update_flags(Object *ob) } if (ob->particlesystem.first) { - ParticleSystem *psys= ob->particlesystem.first; + ParticleSystem *psys = ob->particlesystem.first; - for (; psys; psys=psys->next) { + for (; psys; psys = psys->next) { if (psys_check_enabled(ob, psys)) { ob->recalc |= OB_RECALC_DATA; break; @@ -2319,7 +2317,7 @@ void DAG_scene_update_flags(Main *bmain, Scene *scene, unsigned int lay, const s /* set ob flags where animated systems are */ for (SETLOOPER(scene, sce_iter, base)) { - ob= base->object; + ob = base->object; if (do_time) { /* now if DagNode were part of base, the node->lay could be checked... */ @@ -2334,22 +2332,22 @@ void DAG_scene_update_flags(Main *bmain, Scene *scene, unsigned int lay, const s if (do_time) { /* we do groups each once */ - for (group= bmain->group.first; group; group= group->id.next) { + for (group = bmain->group.first; group; group = group->id.next) { if (group->id.flag & LIB_DOIT) { - for (go= group->gobject.first; go; go= go->next) { + for (go = group->gobject.first; go; go = go->next) { dag_object_time_update_flags(go->ob); } } } } - for (sce_iter= scene; sce_iter; sce_iter= sce_iter->set) + for (sce_iter = scene; sce_iter; sce_iter = sce_iter->set) DAG_scene_flush_update(bmain, sce_iter, lay, 1); if (do_time) { /* test: set time flag, to disable baked systems to update */ for (SETLOOPER(scene, sce_iter, base)) { - ob= base->object; + ob = base->object; if (ob->recalc) ob->recalc |= OB_RECALC_TIME; } @@ -2360,10 +2358,10 @@ void DAG_scene_update_flags(Main *bmain, Scene *scene, unsigned int lay, const s } /* and store the info in groupobject */ - for (group= bmain->group.first; group; group= group->id.next) { + for (group = bmain->group.first; group; group = group->id.next) { if (group->id.flag & LIB_DOIT) { - for (go= group->gobject.first; go; go= go->next) { - go->recalc= go->ob->recalc; + for (go = group->gobject.first; go; go = go->next) { + go->recalc = go->ob->recalc; // printf("ob %s recalc %d\n", go->ob->id.name, go->recalc); } group->id.flag &= ~LIB_DOIT; @@ -2380,22 +2378,22 @@ static void dag_current_scene_layers(Main *bmain, Scene **sce, unsigned int *lay /* only one scene supported currently, making more scenes work * correctly requires changes beyond just the dependency graph */ - *sce= NULL; - *lay= 0; + *sce = NULL; + *lay = 0; - if ((wm= bmain->wm.first)) { + if ((wm = bmain->wm.first)) { /* if we have a windowmanager, look into windows */ - for (win=wm->windows.first; win; win=win->next) { + for (win = wm->windows.first; win; win = win->next) { if (win->screen) { - if (!*sce) *sce= win->screen->scene; + if (!*sce) *sce = win->screen->scene; *lay |= BKE_screen_visible_layers(win->screen, win->screen->scene); } } } else { /* if not, use the first sce */ - *sce= bmain->scene.first; - if (*sce) *lay= (*sce)->lay; + *sce = bmain->scene.first; + if (*sce) *lay = (*sce)->lay; /* XXX for background mode, we should get the scene * from somewhere, for the -S option, but it's in @@ -2435,9 +2433,9 @@ void DAG_on_visible_update(Main *bmain, const short do_time) dag_scene_flush_layers(scene, lay); for (SETLOOPER(scene, sce_iter, base)) { - ob= base->object; - node= (sce_iter->theDag)? dag_get_node(sce_iter->theDag, ob): NULL; - oblay= (node)? node->lay: ob->lay; + ob = base->object; + node = (sce_iter->theDag) ? dag_get_node(sce_iter->theDag, ob) : NULL; + oblay = (node) ? node->lay : ob->lay; if ((oblay & lay) & ~scene->lay_updated) { if (ELEM6(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_LATTICE)) @@ -2447,9 +2445,9 @@ void DAG_on_visible_update(Main *bmain, const short do_time) } } - for (group= bmain->group.first; group; group= group->id.next) { + for (group = bmain->group.first; group; group = group->id.next) { if (group->id.flag & LIB_DOIT) { - for (go= group->gobject.first; go; go= go->next) { + for (go = group->gobject.first; go; go = go->next) { if (ELEM6(go->ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_LATTICE)) go->ob->recalc |= OB_RECALC_DATA; if (go->ob->proxy_from) @@ -2473,7 +2471,7 @@ static void dag_id_flush_update__isDependentTexture(void *userData, Object *UNUS { struct { ID *id; int is_dependent; } *data = userData; - if (*idpoin && GS((*idpoin)->name)==ID_TE) { + if (*idpoin && GS((*idpoin)->name) == ID_TE) { if (data->id == (*idpoin)) data->is_dependent = 1; } @@ -2481,8 +2479,8 @@ static void dag_id_flush_update__isDependentTexture(void *userData, Object *UNUS static void dag_id_flush_update(Scene *sce, ID *id) { - Main *bmain= G.main; - Object *obt, *ob= NULL; + Main *bmain = G.main; + Object *obt, *ob = NULL; short idtype; /* here we flush a few things before actual scene wide flush, mostly @@ -2490,27 +2488,27 @@ static void dag_id_flush_update(Scene *sce, ID *id) /* set flags & pointcache for object */ if (GS(id->name) == ID_OB) { - ob= (Object*)id; + ob = (Object *)id; BKE_ptcache_object_reset(sce, ob, PTCACHE_RESET_DEPSGRAPH); if (ob->recalc & OB_RECALC_DATA) { /* all users of this ob->data should be checked */ - id= ob->data; + id = ob->data; /* no point in trying in this cases */ if (id && id->us <= 1) { dag_editors_id_update(bmain, id); - id= NULL; + id = NULL; } } } /* set flags & pointcache for object data */ if (id) { - idtype= GS(id->name); + idtype = GS(id->name); if (ELEM8(idtype, ID_ME, ID_CU, ID_MB, ID_LA, ID_LT, ID_CA, ID_AR, ID_SPK)) { - for (obt=bmain->object.first; obt; obt= obt->id.next) { + for (obt = bmain->object.first; obt; obt = obt->id.next) { if (!(ob && obt == ob) && obt->data == id) { obt->recalc |= OB_RECALC_DATA; lib_id_recalc_data_tag(bmain, &obt->id); @@ -2521,10 +2519,10 @@ static void dag_id_flush_update(Scene *sce, ID *id) /* set flags based on textures - can influence depgraph via modifiers */ if (idtype == ID_TE) { - for (obt=bmain->object.first; obt; obt= obt->id.next) { + for (obt = bmain->object.first; obt; obt = obt->id.next) { struct { ID *id; int is_dependent; } data; - data.id= id; - data.is_dependent= 0; + data.id = id; + data.is_dependent = 0; modifiers_foreachIDLink(obt, dag_id_flush_update__isDependentTexture, &data); if (data.is_dependent) { @@ -2537,11 +2535,11 @@ static void dag_id_flush_update(Scene *sce, ID *id) ParticleSystem *psys = obt->particlesystem.first; MTex **mtexp, *mtex; int a; - for (; psys; psys=psys->next) { + for (; psys; psys = psys->next) { mtexp = psys->part->mtex; - for (a=0; a<MAX_MTEX; a++, mtexp++) { + for (a = 0; a < MAX_MTEX; a++, mtexp++) { mtex = *mtexp; - if (mtex && mtex->tex == (Tex*)id) { + if (mtex && mtex->tex == (Tex *)id) { obt->recalc |= OB_RECALC_DATA; lib_id_recalc_data_tag(bmain, &obt->id); @@ -2560,10 +2558,10 @@ static void dag_id_flush_update(Scene *sce, ID *id) /* set flags based on ShapeKey */ if (idtype == ID_KE) { - for (obt=bmain->object.first; obt; obt= obt->id.next) { - Key *key= ob_get_key(obt); + for (obt = bmain->object.first; obt; obt = obt->id.next) { + Key *key = ob_get_key(obt); if (!(ob && obt == ob) && ((ID *)key == id)) { - obt->flag |= (OB_RECALC_OB|OB_RECALC_DATA); + obt->flag |= (OB_RECALC_OB | OB_RECALC_DATA); lib_id_recalc_tag(bmain, &obt->id); lib_id_recalc_data_tag(bmain, &obt->id); BKE_ptcache_object_reset(sce, obt, PTCACHE_RESET_DEPSGRAPH); @@ -2574,8 +2572,8 @@ static void dag_id_flush_update(Scene *sce, ID *id) /* set flags based on particle settings */ if (idtype == ID_PA) { ParticleSystem *psys; - for (obt=bmain->object.first; obt; obt= obt->id.next) - for (psys=obt->particlesystem.first; psys; psys=psys->next) + for (obt = bmain->object.first; obt; obt = obt->id.next) + for (psys = obt->particlesystem.first; psys; psys = psys->next) if (&psys->part->id == id) BKE_ptcache_object_reset(sce, obt, PTCACHE_RESET_DEPSGRAPH); } @@ -2585,12 +2583,12 @@ static void dag_id_flush_update(Scene *sce, ID *id) BKE_tracking_dopesheet_tag_update(&clip->tracking); - for (obt=bmain->object.first; obt; obt= obt->id.next) { + for (obt = bmain->object.first; obt; obt = obt->id.next) { bConstraint *con; - for (con = obt->constraints.first; con; con=con->next) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + for (con = obt->constraints.first; con; con = con->next) { + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); if (ELEM3(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER, - CONSTRAINT_TYPE_OBJECTSOLVER)) + CONSTRAINT_TYPE_OBJECTSOLVER)) { obt->recalc |= OB_RECALC_OB; break; @@ -2601,8 +2599,8 @@ static void dag_id_flush_update(Scene *sce, ID *id) if (sce->nodetree) { bNode *node; - for (node= sce->nodetree->nodes.first; node; node= node->next) { - if (node->id==id) { + for (node = sce->nodetree->nodes.first; node; node = node->next) { + if (node->id == id) { nodeUpdate(sce->nodetree, node); } } @@ -2613,7 +2611,7 @@ static void dag_id_flush_update(Scene *sce, ID *id) * so it should happen tracking-related constraints recalculation * when camera is changing (sergey) */ if (sce->camera && &sce->camera->id == id) { - MovieClip *clip = object_get_movieclip(sce, sce->camera, 1); + MovieClip *clip = BKE_object_movieclip_get(sce, sce->camera, 1); if (clip) dag_id_flush_update(sce, &clip->id); @@ -2646,8 +2644,8 @@ void DAG_ids_flush_tagged(Main *bmain) /* we tag based on first ID type character to avoid * looping over all ID's in case there are no tags */ if (id && bmain->id_tag_update[id->name[0]]) { - for (; id; id=id->next) { - if (id->flag & (LIB_ID_RECALC|LIB_ID_RECALC_DATA)) { + for (; id; id = id->next) { + if (id->flag & (LIB_ID_RECALC | LIB_ID_RECALC_DATA)) { dag_id_flush_update(sce, id); do_flush = 1; } @@ -2675,7 +2673,7 @@ void DAG_ids_check_recalc(Main *bmain, Scene *scene, int time) /* we tag based on first ID type character to avoid * looping over all ID's in case there are no tags */ if (id && bmain->id_tag_update[id->name[0]]) { - updated= 1; + updated = 1; break; } } @@ -2698,9 +2696,9 @@ void DAG_ids_clear_recalc(Main *bmain) /* we tag based on first ID type character to avoid * looping over all ID's in case there are no tags */ if (id && bmain->id_tag_update[id->name[0]]) { - for (; id; id=id->next) - if (id->flag & (LIB_ID_RECALC|LIB_ID_RECALC_DATA)) - id->flag &= ~(LIB_ID_RECALC|LIB_ID_RECALC_DATA); + for (; id; id = id->next) + if (id->flag & (LIB_ID_RECALC | LIB_ID_RECALC_DATA)) + id->flag &= ~(LIB_ID_RECALC | LIB_ID_RECALC_DATA); } } @@ -2709,15 +2707,15 @@ void DAG_ids_clear_recalc(Main *bmain) void DAG_id_tag_update(ID *id, short flag) { - Main *bmain= G.main; + Main *bmain = G.main; - if (id==NULL) return; + if (id == NULL) return; /* tag ID for update */ if (flag) { if (flag & OB_RECALC_OB) lib_id_recalc_tag(bmain, id); - if (flag & (OB_RECALC_DATA|PSYS_RECALC)) + if (flag & (OB_RECALC_DATA | PSYS_RECALC)) lib_id_recalc_data_tag(bmain, id); } else @@ -2730,14 +2728,14 @@ void DAG_id_tag_update(ID *id, short flag) if (idtype == ID_OB) { /* only quick tag */ - ob = (Object*)id; + ob = (Object *)id; ob->recalc |= (flag & OB_RECALC_ALL); } else if (idtype == ID_PA) { ParticleSystem *psys; /* this is weak still, should be done delayed as well */ - for (ob=bmain->object.first; ob; ob=ob->id.next) { - for (psys=ob->particlesystem.first; psys; psys=psys->next) { + for (ob = bmain->object.first; ob; ob = ob->id.next) { + for (psys = ob->particlesystem.first; psys; psys = psys->next) { if (&psys->part->id == id) { ob->recalc |= (flag & OB_RECALC_ALL); psys->recalc |= (flag & PSYS_RECALC); @@ -2757,12 +2755,12 @@ void DAG_id_tag_update(ID *id, short flag) void DAG_id_type_tag(struct Main *bmain, short idtype) { - bmain->id_tag_update[((char*)&idtype)[0]] = 1; + bmain->id_tag_update[((char *)&idtype)[0]] = 1; } int DAG_id_type_tagged(Main *bmain, short idtype) { - return bmain->id_tag_update[((char*)&idtype)[0]]; + return bmain->id_tag_update[((char *)&idtype)[0]]; } #if 0 // UNUSED @@ -2772,22 +2770,22 @@ static int parent_check_node(DagNode *node, int curtime) { DagAdjList *itA; - node->lasttime= curtime; + node->lasttime = curtime; - if (node->color==DAG_GRAY) + if (node->color == DAG_GRAY) return DAG_GRAY; - for (itA = node->child; itA; itA= itA->next) { - if (itA->node->type==ID_OB) { + for (itA = node->child; itA; itA = itA->next) { + if (itA->node->type == ID_OB) { - if (itA->node->color==DAG_GRAY) + if (itA->node->color == DAG_GRAY) return DAG_GRAY; /* descend if not done */ - if (itA->node->lasttime!=curtime) { - itA->node->color= parent_check_node(itA->node, curtime); + if (itA->node->lasttime != curtime) { + itA->node->color = parent_check_node(itA->node, curtime); - if (itA->node->color==DAG_GRAY) + if (itA->node->color == DAG_GRAY) return DAG_GRAY; } } @@ -2802,7 +2800,7 @@ static int parent_check_node(DagNode *node, int curtime) /* we assume its an armature with pose */ void DAG_pose_sort(Object *ob) { - bPose *pose= ob->pose; + bPose *pose = ob->pose; bPoseChannel *pchan; bConstraint *con; DagNode *node; @@ -2815,12 +2813,12 @@ void DAG_pose_sort(Object *ob) int skip = 0; dag = dag_init(); - ugly_hack_sorry= 0; // no ID structs + ugly_hack_sorry = 0; // no ID structs - rootnode = dag_add_node(dag, NULL); // node->ob becomes NULL + rootnode = dag_add_node(dag, NULL); // node->ob becomes NULL /* we add the hierarchy and the constraints */ - for (pchan = pose->chanbase.first; pchan; pchan= pchan->next) { + for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { int addtoroot = 1; node = dag_get_node(dag, pchan); @@ -2830,40 +2828,40 @@ void DAG_pose_sort(Object *ob) dag_add_relation(dag, node2, node, 0, "Parent Relation"); addtoroot = 0; } - for (con = pchan->constraints.first; con; con=con->next) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + for (con = pchan->constraints.first; con; con = con->next) { + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); ListBase targets = {NULL, NULL}; bConstraintTarget *ct; if (cti && cti->get_constraint_targets) { cti->get_constraint_targets(con, &targets); - for (ct= targets.first; ct; ct= ct->next) { - if (ct->tar==ob && ct->subtarget[0]) { - bPoseChannel *target= get_pose_channel(ob->pose, ct->subtarget); + for (ct = targets.first; ct; ct = ct->next) { + if (ct->tar == ob && ct->subtarget[0]) { + bPoseChannel *target = BKE_pose_channel_find_name(ob->pose, ct->subtarget); if (target) { - node2= dag_get_node(dag, target); + node2 = dag_get_node(dag, target); dag_add_relation(dag, node2, node, 0, "Pose Constraint"); - if (con->type==CONSTRAINT_TYPE_KINEMATIC) { + if (con->type == CONSTRAINT_TYPE_KINEMATIC) { bKinematicConstraint *data = (bKinematicConstraint *)con->data; bPoseChannel *parchan; - int segcount= 0; + int segcount = 0; /* exclude tip from chain? */ if (!(data->flag & CONSTRAINT_IK_TIP)) - parchan= pchan->parent; + parchan = pchan->parent; else - parchan= pchan; + parchan = pchan; /* Walk to the chain's root */ while (parchan) { - node3= dag_get_node(dag, parchan); + node3 = dag_get_node(dag, parchan); dag_add_relation(dag, node2, node3, 0, "IK Constraint"); segcount++; - if (segcount==data->rootbone || segcount>255) break; // 255 is weak - parchan= parchan->parent; + if (segcount == data->rootbone || segcount > 255) break; // 255 is weak + parchan = parchan->parent; } } } @@ -2874,7 +2872,7 @@ void DAG_pose_sort(Object *ob) cti->flush_constraint_targets(con, &targets, 1); } } - if (addtoroot == 1 ) { + if (addtoroot == 1) { dag_add_relation(dag, rootnode, node, 0, "Root Bone Relation"); } } @@ -2882,12 +2880,12 @@ void DAG_pose_sort(Object *ob) dag_check_cycle(dag); /* now we try to sort... */ - tempbase.first= tempbase.last= NULL; + tempbase.first = tempbase.last = NULL; nqueue = queue_create(DAGQUEUEALLOC); /* tag nodes unchecked */ - for (node = dag->DagNode.first; node; node= node->next) + for (node = dag->DagNode.first; node; node = node->next) node->color = DAG_WHITE; rootnode->color = DAG_GRAY; @@ -2912,7 +2910,7 @@ void DAG_pose_sort(Object *ob) if (!skip) { if (node) { node = pop_queue(nqueue); - if (node->ob == NULL) // we are done + if (node->ob == NULL) // we are done break; node->color = DAG_BLACK; @@ -2925,7 +2923,7 @@ void DAG_pose_sort(Object *ob) /* temporal correction for circular dependencies */ while (pose->chanbase.first) { - pchan= pose->chanbase.first; + pchan = pose->chanbase.first; BLI_remlink(&pose->chanbase, pchan); BLI_addhead(&tempbase, pchan); @@ -2943,7 +2941,7 @@ void DAG_pose_sort(Object *ob) free_forest(dag); MEM_freeN(dag); - ugly_hack_sorry= 1; + ugly_hack_sorry = 1; } /* ************************ DAG DEBUGGING ********************* */ @@ -2951,17 +2949,17 @@ void DAG_pose_sort(Object *ob) void DAG_print_dependencies(Main *bmain, Scene *scene, Object *ob) { /* utility for debugging dependencies */ - dag_print_dependencies= 1; + dag_print_dependencies = 1; if (ob && (ob->mode & OB_MODE_POSE)) { - printf("\nDEPENDENCY RELATIONS for %s\n\n", ob->id.name+2); + printf("\nDEPENDENCY RELATIONS for %s\n\n", ob->id.name + 2); DAG_pose_sort(ob); } else { - printf("\nDEPENDENCY RELATIONS for %s\n\n", scene->id.name+2); + printf("\nDEPENDENCY RELATIONS for %s\n\n", scene->id.name + 2); DAG_scene_sort(bmain, scene); } - dag_print_dependencies= 0; + dag_print_dependencies = 0; } diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index cf7750520a3..0154a2fa1e5 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -64,7 +64,7 @@ static void boundbox_displist(Object *ob); -void free_disp_elem(DispList *dl) +void BKE_displist_elem_free(DispList *dl) { if (dl) { if (dl->verts) MEM_freeN(dl->verts); @@ -77,84 +77,87 @@ void free_disp_elem(DispList *dl) } } -void freedisplist(ListBase *lb) +void BKE_displist_free(ListBase *lb) { DispList *dl; - dl= lb->first; + dl = lb->first; while (dl) { BLI_remlink(lb, dl); - free_disp_elem(dl); - dl= lb->first; + BKE_displist_elem_free(dl); + dl = lb->first; } } -DispList *find_displist_create(ListBase *lb, int type) +DispList *BKE_displist_find_or_create(ListBase *lb, int type) { DispList *dl; - - dl= lb->first; + + dl = lb->first; while (dl) { - if (dl->type==type) return dl; - dl= dl->next; + if (dl->type == type) + return dl; + dl = dl->next; } - dl= MEM_callocN(sizeof(DispList), "find_disp"); - dl->type= type; + dl = MEM_callocN(sizeof(DispList), "find_disp"); + dl->type = type; BLI_addtail(lb, dl); return dl; } -DispList *find_displist(ListBase *lb, int type) +DispList *BKE_displist_find(ListBase *lb, int type) { DispList *dl; - - dl= lb->first; + + dl = lb->first; while (dl) { - if (dl->type==type) return dl; - dl= dl->next; + if (dl->type == type) + return dl; + dl = dl->next; } return NULL; } -int displist_has_faces(ListBase *lb) +int BKE_displist_has_faces(ListBase *lb) { DispList *dl; - for (dl= lb->first; dl; dl= dl->next) { + + for (dl = lb->first; dl; dl = dl->next) { if (ELEM3(dl->type, DL_INDEX3, DL_INDEX4, DL_SURF)) { - return 1; + return TRUE; } } - return 0; + + return FALSE; } -void copy_displist(ListBase *lbn, ListBase *lb) +void BKE_displist_copy(ListBase *lbn, ListBase *lb) { DispList *dln, *dl; - - freedisplist(lbn); - - dl= lb->first; + + BKE_displist_free(lbn); + + dl = lb->first; while (dl) { - - dln= MEM_dupallocN(dl); + dln = MEM_dupallocN(dl); BLI_addtail(lbn, dln); - dln->verts= MEM_dupallocN(dl->verts); - dln->nors= MEM_dupallocN(dl->nors); - dln->index= MEM_dupallocN(dl->index); - dln->col1= MEM_dupallocN(dl->col1); - dln->col2= MEM_dupallocN(dl->col2); + dln->verts = MEM_dupallocN(dl->verts); + dln->nors = MEM_dupallocN(dl->nors); + dln->index = MEM_dupallocN(dl->index); + dln->col1 = MEM_dupallocN(dl->col1); + dln->col2 = MEM_dupallocN(dl->col2); if (dl->bevelSplitFlag) - dln->bevelSplitFlag= MEM_dupallocN(dl->bevelSplitFlag); + dln->bevelSplitFlag = MEM_dupallocN(dl->bevelSplitFlag); - dl= dl->next; + dl = dl->next; } } -void addnormalsDispList(ListBase *lb) +void BKE_displist_normals_add(ListBase *lb) { DispList *dl = NULL; float *vdata, *ndata, nor[3]; @@ -162,117 +165,118 @@ void addnormalsDispList(ListBase *lb) float *n1, *n2, *n3, *n4; int a, b, p1, p2, p3, p4; + dl = lb->first; - dl= lb->first; - while (dl) { - if (dl->type==DL_INDEX3) { - if (dl->nors==NULL) { - dl->nors= MEM_callocN(sizeof(float)*3, "dlnors"); - if (dl->verts[2] < 0.0f) dl->nors[2]= -1.0f; - else dl->nors[2]= 1.0f; + if (dl->type == DL_INDEX3) { + if (dl->nors == NULL) { + dl->nors = MEM_callocN(sizeof(float) * 3, "dlnors"); + + if (dl->verts[2] < 0.0f) + dl->nors[2] = -1.0f; + else + dl->nors[2] = 1.0f; } } - else if (dl->type==DL_SURF) { - if (dl->nors==NULL) { - dl->nors= MEM_callocN(sizeof(float)*3*dl->nr*dl->parts, "dlnors"); - - vdata= dl->verts; - ndata= dl->nors; - - for (a=0; a<dl->parts; a++) { - - if (surfindex_displist(dl, a, &b, &p1, &p2, &p3, &p4)==0) + else if (dl->type == DL_SURF) { + if (dl->nors == NULL) { + dl->nors = MEM_callocN(sizeof(float) * 3 * dl->nr * dl->parts, "dlnors"); + + vdata = dl->verts; + ndata = dl->nors; + + for (a = 0; a < dl->parts; a++) { + + if (BKE_displist_surfindex_get(dl, a, &b, &p1, &p2, &p3, &p4) == 0) break; - - v1= vdata+ 3*p1; - n1= ndata+ 3*p1; - v2= vdata+ 3*p2; - n2= ndata+ 3*p2; - v3= vdata+ 3*p3; - n3= ndata+ 3*p3; - v4= vdata+ 3*p4; - n4= ndata+ 3*p4; - - for (; b<dl->nr; b++) { - + + v1 = vdata + 3 * p1; + n1 = ndata + 3 * p1; + v2 = vdata + 3 * p2; + n2 = ndata + 3 * p2; + v3 = vdata + 3 * p3; + n3 = ndata + 3 * p3; + v4 = vdata + 3 * p4; + n4 = ndata + 3 * p4; + + for (; b < dl->nr; b++) { normal_quad_v3(nor, v1, v3, v4, v2); - + add_v3_v3(n1, nor); add_v3_v3(n2, nor); add_v3_v3(n3, nor); add_v3_v3(n4, nor); - - v2= v1; v1+= 3; - v4= v3; v3+= 3; - n2= n1; n1+= 3; - n4= n3; n3+= 3; + + v2 = v1; v1 += 3; + v4 = v3; v3 += 3; + n2 = n1; n1 += 3; + n4 = n3; n3 += 3; } } - a= dl->parts*dl->nr; - v1= ndata; + a = dl->parts * dl->nr; + v1 = ndata; while (a--) { normalize_v3(v1); - v1+= 3; + v1 += 3; } } } - dl= dl->next; + dl = dl->next; } } -void count_displist(ListBase *lb, int *totvert, int *totface) +void BKE_displist_count(ListBase *lb, int *totvert, int *totface) { DispList *dl; - - dl= lb->first; + + dl = lb->first; while (dl) { - switch (dl->type) { case DL_SURF: - *totvert+= dl->nr*dl->parts; - *totface+= (dl->nr-1)*(dl->parts-1); + *totvert += dl->nr * dl->parts; + *totface += (dl->nr - 1) * (dl->parts - 1); break; case DL_INDEX3: case DL_INDEX4: - *totvert+= dl->nr; - *totface+= dl->parts; + *totvert += dl->nr; + *totface += dl->parts; break; case DL_POLY: case DL_SEGM: - *totvert+= dl->nr*dl->parts; + *totvert += dl->nr * dl->parts; + break; } - - dl= dl->next; + + dl = dl->next; } } -int surfindex_displist(DispList *dl, int a, int *b, int *p1, int *p2, int *p3, int *p4) +int BKE_displist_surfindex_get(DispList *dl, int a, int *b, int *p1, int *p2, int *p3, int *p4) { - if ((dl->flag & DL_CYCL_V)==0 && a==(dl->parts)-1) { + if ((dl->flag & DL_CYCL_V) == 0 && a == (dl->parts) - 1) { return 0; } - + if (dl->flag & DL_CYCL_U) { - (*p1)= dl->nr*a; - (*p2)= (*p1)+ dl->nr-1; - (*p3)= (*p1)+ dl->nr; - (*p4)= (*p2)+ dl->nr; - (*b)= 0; + (*p1) = dl->nr * a; + (*p2) = (*p1) + dl->nr - 1; + (*p3) = (*p1) + dl->nr; + (*p4) = (*p2) + dl->nr; + (*b) = 0; } else { - (*p2)= dl->nr*a; - (*p1)= (*p2)+1; - (*p4)= (*p2)+ dl->nr; - (*p3)= (*p1)+ dl->nr; - (*b)= 1; + (*p2) = dl->nr * a; + (*p1) = (*p2) + 1; + (*p4) = (*p2) + dl->nr; + (*p3) = (*p1) + dl->nr; + (*b) = 1; } - - if ( (dl->flag & DL_CYCL_V) && a==dl->parts-1) { - (*p3)-= dl->nr*dl->parts; - (*p4)-= dl->nr*dl->parts; + + if ((dl->flag & DL_CYCL_V) && a == dl->parts - 1) { + (*p3) -= dl->nr * dl->parts; + (*p4) -= dl->nr * dl->parts; } - + return 1; } @@ -286,237 +290,244 @@ static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase, i BPoint *bp; float *data; int a, len, resolu; - - nu= nubase->first; + + nu = nubase->first; while (nu) { - if (nu->hide==0) { - - if (forRender && cu->resolu_ren!=0) - resolu= cu->resolu_ren; + if (nu->hide == 0) { + if (forRender && cu->resolu_ren != 0) + resolu = cu->resolu_ren; else - resolu= nu->resolu; - - if (!BKE_nurb_check_valid_u(nu)); + resolu = nu->resolu; + + if (!BKE_nurb_check_valid_u(nu)) ; else if (nu->type == CU_BEZIER) { - /* count */ - len= 0; - a= nu->pntsu-1; + len = 0; + a = nu->pntsu - 1; if (nu->flagu & CU_NURB_CYCLIC) a++; - prevbezt= nu->bezt; - bezt= prevbezt+1; + prevbezt = nu->bezt; + bezt = prevbezt + 1; while (a--) { - if (a==0 && (nu->flagu & CU_NURB_CYCLIC)) bezt= nu->bezt; - - if (prevbezt->h2==HD_VECT && bezt->h1==HD_VECT) len++; - else len+= resolu; - - if (a==0 && (nu->flagu & CU_NURB_CYCLIC)==0) len++; - - prevbezt= bezt; + if (a == 0 && (nu->flagu & CU_NURB_CYCLIC)) + bezt = nu->bezt; + + if (prevbezt->h2 == HD_VECT && bezt->h1 == HD_VECT) + len++; + else + len += resolu; + + if (a == 0 && (nu->flagu & CU_NURB_CYCLIC) == 0) + len++; + + prevbezt = bezt; bezt++; } - - dl= MEM_callocN(sizeof(DispList), "makeDispListbez"); + + dl = MEM_callocN(sizeof(DispList), "makeDispListbez"); /* len+1 because of 'forward_diff_bezier' function */ - dl->verts= MEM_callocN((len+1)*3*sizeof(float), "dlverts"); + dl->verts = MEM_callocN((len + 1) * 3 * sizeof(float), "dlverts"); BLI_addtail(dispbase, dl); - dl->parts= 1; - dl->nr= len; - dl->col= nu->mat_nr; - dl->charidx= nu->charidx; + dl->parts = 1; + dl->nr = len; + dl->col = nu->mat_nr; + dl->charidx = nu->charidx; - data= dl->verts; + data = dl->verts; if (nu->flagu & CU_NURB_CYCLIC) { - dl->type= DL_POLY; - a= nu->pntsu; + dl->type = DL_POLY; + a = nu->pntsu; } else { - dl->type= DL_SEGM; - a= nu->pntsu-1; + dl->type = DL_SEGM; + a = nu->pntsu - 1; } - - prevbezt= nu->bezt; - bezt= prevbezt+1; - + + prevbezt = nu->bezt; + bezt = prevbezt + 1; + while (a--) { - if (a==0 && dl->type== DL_POLY) bezt= nu->bezt; - - if (prevbezt->h2==HD_VECT && bezt->h1==HD_VECT) { + if (a == 0 && dl->type == DL_POLY) + bezt = nu->bezt; + + if (prevbezt->h2 == HD_VECT && bezt->h1 == HD_VECT) { copy_v3_v3(data, prevbezt->vec[1]); - data+= 3; + data += 3; } else { int j; - for (j=0; j<3; j++) { + for (j = 0; j < 3; j++) { BKE_curve_forward_diff_bezier(prevbezt->vec[1][j], prevbezt->vec[2][j], bezt->vec[0][j], bezt->vec[1][j], data + j, resolu, 3 * sizeof(float)); } - - data+= 3*resolu; + + data += 3 * resolu; } - - if (a==0 && dl->type==DL_SEGM) { + + if (a == 0 && dl->type == DL_SEGM) { copy_v3_v3(data, bezt->vec[1]); } - - prevbezt= bezt; + + prevbezt = bezt; bezt++; } } else if (nu->type == CU_NURBS) { - len= (resolu*SEGMENTSU(nu)); - - dl= MEM_callocN(sizeof(DispList), "makeDispListsurf"); - dl->verts= MEM_callocN(len*3*sizeof(float), "dlverts"); + len = (resolu * SEGMENTSU(nu)); + + dl = MEM_callocN(sizeof(DispList), "makeDispListsurf"); + dl->verts = MEM_callocN(len * 3 * sizeof(float), "dlverts"); BLI_addtail(dispbase, dl); - dl->parts= 1; - - dl->nr= len; - dl->col= nu->mat_nr; + dl->parts = 1; + + dl->nr = len; + dl->col = nu->mat_nr; dl->charidx = nu->charidx; - data= dl->verts; - if (nu->flagu & CU_NURB_CYCLIC) dl->type= DL_POLY; - else dl->type= DL_SEGM; - BKE_nurb_makeCurve(nu, data, NULL, NULL, NULL, resolu, 3*sizeof(float)); + data = dl->verts; + if (nu->flagu & CU_NURB_CYCLIC) + dl->type = DL_POLY; + else dl->type = DL_SEGM; + BKE_nurb_makeCurve(nu, data, NULL, NULL, NULL, resolu, 3 * sizeof(float)); } else if (nu->type == CU_POLY) { - len= nu->pntsu; - dl= MEM_callocN(sizeof(DispList), "makeDispListpoly"); - dl->verts= MEM_callocN(len*3*sizeof(float), "dlverts"); + len = nu->pntsu; + dl = MEM_callocN(sizeof(DispList), "makeDispListpoly"); + dl->verts = MEM_callocN(len * 3 * sizeof(float), "dlverts"); BLI_addtail(dispbase, dl); - dl->parts= 1; - dl->nr= len; - dl->col= nu->mat_nr; + dl->parts = 1; + dl->nr = len; + dl->col = nu->mat_nr; dl->charidx = nu->charidx; - data= dl->verts; - if (nu->flagu & CU_NURB_CYCLIC) dl->type= DL_POLY; - else dl->type= DL_SEGM; - - a= len; - bp= nu->bp; + data = dl->verts; + if (nu->flagu & CU_NURB_CYCLIC) dl->type = DL_POLY; + else dl->type = DL_SEGM; + + a = len; + bp = nu->bp; while (a--) { copy_v3_v3(data, bp->vec); bp++; - data+= 3; + data += 3; } } } - nu= nu->next; + nu = nu->next; } } -void filldisplist(ListBase *dispbase, ListBase *to, int flipnormal) +void BKE_displist_fill(ListBase *dispbase, ListBase *to, int flipnormal) { ScanFillContext sf_ctx; ScanFillVert *eve, *v1, *vlast; ScanFillFace *efa; - DispList *dlnew=NULL, *dl; + DispList *dlnew = NULL, *dl; float *f1; - int colnr=0, charidx=0, cont=1, tot, a, *index, nextcol= 0; + int colnr = 0, charidx = 0, cont = 1, tot, a, *index, nextcol = 0; intptr_t totvert; - - if (dispbase==NULL) return; - if (dispbase->first==NULL) return; + + if (dispbase == NULL) + return; + if (dispbase->first == NULL) + return; while (cont) { - cont= 0; - totvert= 0; - nextcol= 0; - + cont = 0; + totvert = 0; + nextcol = 0; + BLI_scanfill_begin(&sf_ctx); - - dl= dispbase->first; + + dl = dispbase->first; while (dl) { - - if (dl->type==DL_POLY) { - if (charidx<dl->charidx) cont= 1; - else if (charidx==dl->charidx) { /* character with needed index */ - if (colnr==dl->col) { + if (dl->type == DL_POLY) { + if (charidx < dl->charidx) + cont = 1; + else if (charidx == dl->charidx) { /* character with needed index */ + if (colnr == dl->col) { /* make editverts and edges */ - f1= dl->verts; - a= dl->nr; - eve= v1= NULL; - + f1 = dl->verts; + a = dl->nr; + eve = v1 = NULL; + while (a--) { - vlast= eve; + vlast = eve; eve = BLI_scanfill_vert_add(&sf_ctx, f1); totvert++; - if (vlast==NULL) v1= eve; + if (vlast == NULL) + v1 = eve; else { BLI_scanfill_edge_add(&sf_ctx, vlast, eve); } - f1+=3; + f1 += 3; } - if (eve!=NULL && v1!=NULL) { + if (eve != NULL && v1 != NULL) { BLI_scanfill_edge_add(&sf_ctx, eve, v1); } } - else if (colnr<dl->col) { + else if (colnr < dl->col) { /* got poly with next material at current char */ - cont= 1; - nextcol= 1; + cont = 1; + nextcol = 1; } } } - dl= dl->next; + dl = dl->next; } - - if (totvert && (tot= BLI_scanfill_calc(&sf_ctx, FALSE))) { // XXX (obedit && obedit->actcol)?(obedit->actcol-1):0)) { + + /* XXX (obedit && obedit->actcol)?(obedit->actcol-1):0)) { */ + if (totvert && (tot = BLI_scanfill_calc(&sf_ctx, FALSE))) { if (tot) { - dlnew= MEM_callocN(sizeof(DispList), "filldisplist"); - dlnew->type= DL_INDEX3; - dlnew->col= colnr; - dlnew->nr= totvert; - dlnew->parts= tot; - - dlnew->index= MEM_mallocN(tot*3*sizeof(int), "dlindex"); - dlnew->verts= MEM_mallocN(totvert*3*sizeof(float), "dlverts"); - + dlnew = MEM_callocN(sizeof(DispList), "filldisplist"); + dlnew->type = DL_INDEX3; + dlnew->col = colnr; + dlnew->nr = totvert; + dlnew->parts = tot; + + dlnew->index = MEM_mallocN(tot * 3 * sizeof(int), "dlindex"); + dlnew->verts = MEM_mallocN(totvert * 3 * sizeof(float), "dlverts"); + /* vert data */ - f1= dlnew->verts; - totvert= 0; - eve= sf_ctx.fillvertbase.first; + f1 = dlnew->verts; + totvert = 0; + eve = sf_ctx.fillvertbase.first; while (eve) { copy_v3_v3(f1, eve->co); - f1+= 3; - + f1 += 3; + /* index number */ eve->tmp.l = totvert; totvert++; - - eve= eve->next; + + eve = eve->next; } - + /* index data */ efa = sf_ctx.fillfacebase.first; - index= dlnew->index; + index = dlnew->index; while (efa) { - index[0]= (intptr_t)efa->v1->tmp.l; - index[1]= (intptr_t)efa->v2->tmp.l; - index[2]= (intptr_t)efa->v3->tmp.l; + index[0] = (intptr_t)efa->v1->tmp.l; + index[1] = (intptr_t)efa->v2->tmp.l; + index[2] = (intptr_t)efa->v3->tmp.l; if (flipnormal) SWAP(int, index[0], index[2]); - - index+= 3; - efa= efa->next; + + index += 3; + efa = efa->next; } } BLI_addhead(to, dlnew); - } BLI_scanfill_end(&sf_ctx); @@ -527,12 +538,11 @@ void filldisplist(ListBase *dispbase, ListBase *to, int flipnormal) else { /* switch to next char and start filling from first material */ charidx++; - colnr= 0; + colnr = 0; } } - + /* do not free polys, needed for wireframe display */ - } static void bevels_to_filledpoly(Curve *cu, ListBase *dispbase) @@ -541,77 +551,77 @@ static void bevels_to_filledpoly(Curve *cu, ListBase *dispbase) DispList *dl, *dlnew; float *fp, *fp1; int a, dpoly; - - front.first= front.last= back.first= back.last= NULL; - - dl= dispbase->first; + + front.first = front.last = back.first = back.last = NULL; + + dl = dispbase->first; while (dl) { - if (dl->type==DL_SURF) { - if ( (dl->flag & DL_CYCL_V) && (dl->flag & DL_CYCL_U)==0 ) { - if ( (cu->flag & CU_BACK) && (dl->flag & DL_BACK_CURVE) ) { - dlnew= MEM_callocN(sizeof(DispList), "filldisp"); + if (dl->type == DL_SURF) { + if ((dl->flag & DL_CYCL_V) && (dl->flag & DL_CYCL_U) == 0) { + if ( (cu->flag & CU_BACK) && (dl->flag & DL_BACK_CURVE)) { + dlnew = MEM_callocN(sizeof(DispList), "filldisp"); BLI_addtail(&front, dlnew); - dlnew->verts= fp1= MEM_mallocN(sizeof(float)*3*dl->parts, "filldisp1"); - dlnew->nr= dl->parts; - dlnew->parts= 1; - dlnew->type= DL_POLY; - dlnew->col= dl->col; + dlnew->verts = fp1 = MEM_mallocN(sizeof(float) * 3 * dl->parts, "filldisp1"); + dlnew->nr = dl->parts; + dlnew->parts = 1; + dlnew->type = DL_POLY; + dlnew->col = dl->col; dlnew->charidx = dl->charidx; - - fp= dl->verts; - dpoly= 3*dl->nr; - - a= dl->parts; + + fp = dl->verts; + dpoly = 3 * dl->nr; + + a = dl->parts; while (a--) { copy_v3_v3(fp1, fp); - fp1+= 3; - fp+= dpoly; + fp1 += 3; + fp += dpoly; } } - if ( (cu->flag & CU_FRONT) && (dl->flag & DL_FRONT_CURVE) ) { - dlnew= MEM_callocN(sizeof(DispList), "filldisp"); + if ((cu->flag & CU_FRONT) && (dl->flag & DL_FRONT_CURVE)) { + dlnew = MEM_callocN(sizeof(DispList), "filldisp"); BLI_addtail(&back, dlnew); - dlnew->verts= fp1= MEM_mallocN(sizeof(float)*3*dl->parts, "filldisp1"); - dlnew->nr= dl->parts; - dlnew->parts= 1; - dlnew->type= DL_POLY; - dlnew->col= dl->col; - dlnew->charidx= dl->charidx; - - fp= dl->verts+3*(dl->nr-1); - dpoly= 3*dl->nr; - - a= dl->parts; + dlnew->verts = fp1 = MEM_mallocN(sizeof(float) * 3 * dl->parts, "filldisp1"); + dlnew->nr = dl->parts; + dlnew->parts = 1; + dlnew->type = DL_POLY; + dlnew->col = dl->col; + dlnew->charidx = dl->charidx; + + fp = dl->verts + 3 * (dl->nr - 1); + dpoly = 3 * dl->nr; + + a = dl->parts; while (a--) { copy_v3_v3(fp1, fp); - fp1+= 3; - fp+= dpoly; + fp1 += 3; + fp += dpoly; } } } } - dl= dl->next; + dl = dl->next; } - filldisplist(&front, dispbase, 1); - filldisplist(&back, dispbase, 0); - - freedisplist(&front); - freedisplist(&back); + BKE_displist_fill(&front, dispbase, 1); + BKE_displist_fill(&back, dispbase, 0); - filldisplist(dispbase, dispbase, 0); - + BKE_displist_free(&front); + BKE_displist_free(&back); + + BKE_displist_fill(dispbase, dispbase, 0); } static void curve_to_filledpoly(Curve *cu, ListBase *UNUSED(nurb), ListBase *dispbase) { - if (cu->flag & CU_3D) return; + if (cu->flag & CU_3D) + return; - if (dispbase->first && ((DispList*) dispbase->first)->type==DL_SURF) { + if (dispbase->first && ((DispList *) dispbase->first)->type == DL_SURF) { bevels_to_filledpoly(cu, dispbase); } else { - filldisplist(dispbase, dispbase, 0); + BKE_displist_fill(dispbase, dispbase, 0); } } @@ -620,74 +630,77 @@ static void curve_to_filledpoly(Curve *cu, ListBase *UNUSED(nurb), ListBase *dis * - first point left, last point right * - based on subdivided points in original curve, not on points in taper curve (still) */ -float calc_taper(Scene *scene, Object *taperobj, int cur, int tot) +float BKE_displist_calc_taper(Scene *scene, Object *taperobj, int cur, int tot) { DispList *dl; - - if (taperobj==NULL || taperobj->type!=OB_CURVE) return 1.0; - - dl= taperobj->disp.first; - if (dl==NULL) { - makeDispListCurveTypes(scene, taperobj, 0); - dl= taperobj->disp.first; + + if (taperobj == NULL || taperobj->type != OB_CURVE) + return 1.0; + + dl = taperobj->disp.first; + if (dl == NULL) { + BKE_displist_make_curveTypes(scene, taperobj, 0); + dl = taperobj->disp.first; } if (dl) { - float fac= ((float)cur)/(float)(tot-1); + float fac = ((float)cur) / (float)(tot - 1); float minx, dx, *fp; int a; - + /* horizontal size */ - minx= dl->verts[0]; - dx= dl->verts[3*(dl->nr-1)] - minx; + minx = dl->verts[0]; + dx = dl->verts[3 * (dl->nr - 1)] - minx; if (dx > 0.0f) { - - fp= dl->verts; - for (a=0; a<dl->nr; a++, fp+=3) { - if ( (fp[0]-minx)/dx >= fac) { + fp = dl->verts; + for (a = 0; a < dl->nr; a++, fp += 3) { + if ((fp[0] - minx) / dx >= fac) { /* interpolate with prev */ - if (a>0) { - float fac1= (fp[-3]-minx)/dx; - float fac2= (fp[0]-minx)/dx; - if (fac1!=fac2) - return fp[1]*(fac1-fac)/(fac1-fac2) + fp[-2]*(fac-fac2)/(fac1-fac2); + if (a > 0) { + float fac1 = (fp[-3] - minx) / dx; + float fac2 = (fp[0] - minx) / dx; + if (fac1 != fac2) + return fp[1] * (fac1 - fac) / (fac1 - fac2) + fp[-2] * (fac - fac2) / (fac1 - fac2); } return fp[1]; } } - return fp[-2]; // last y coord + return fp[-2]; // last y coord } } - + return 1.0; } -void makeDispListMBall(Scene *scene, Object *ob) +void BKE_displist_make_mball(Scene *scene, Object *ob) { - if (!ob || ob->type!=OB_MBALL) return; + if (!ob || ob->type != OB_MBALL) + return; - // XXX: mball stuff uses plenty of global variables - // while this is unchanged updating during render is unsafe - if (G.rendering) return; + /* XXX: mball stuff uses plenty of global variables + * while this is unchanged updating during render is unsafe + */ + if (G.rendering) + return; - freedisplist(&(ob->disp)); + BKE_displist_free(&(ob->disp)); - if (ob->type==OB_MBALL) { - if (ob==BKE_metaball_basis_find(scene, ob)) { - BKE_metaball_polygonize(scene, ob, &ob->disp); - BKE_metaball_tex_space_calc(ob); + if (ob->type == OB_MBALL) { + if (ob == BKE_mball_basis_find(scene, ob)) { + BKE_mball_polygonize(scene, ob, &ob->disp); + BKE_mball_texspace_calc(ob); object_deform_mball(ob, &ob->disp); } } - + boundbox_displist(ob); } -void makeDispListMBall_forRender(Scene *scene, Object *ob, ListBase *dispbase) +void BKE_displist_make_mball_forRender(Scene *scene, Object *ob, ListBase *dispbase) { - BKE_metaball_polygonize(scene, ob, dispbase); - BKE_metaball_tex_space_calc(ob); - + BKE_mball_polygonize(scene, ob, dispbase); + BKE_mball_texspace_calc(ob); + object_deform_mball(ob, dispbase); } @@ -697,27 +710,33 @@ static ModifierData *curve_get_tessellate_point(Scene *scene, Object *ob, int fo ModifierData *pretessellatePoint; int required_mode; - if (forRender) required_mode = eModifierMode_Render; - else required_mode = eModifierMode_Realtime; + if (forRender) + required_mode = eModifierMode_Render; + else + required_mode = eModifierMode_Realtime; - if (editmode) required_mode |= eModifierMode_Editmode; + if (editmode) + required_mode |= eModifierMode_Editmode; pretessellatePoint = NULL; - for (; md; md=md->next) { + for (; md; md = md->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); - if (!modifier_isEnabled(scene, md, required_mode)) continue; - if (mti->type == eModifierTypeType_Constructive) return pretessellatePoint; + if (!modifier_isEnabled(scene, md, required_mode)) + continue; + if (mti->type == eModifierTypeType_Constructive) + return pretessellatePoint; if (ELEM3(md->type, eModifierType_Hook, eModifierType_Softbody, eModifierType_MeshDeform)) { pretessellatePoint = md; /* this modifiers are moving point of tessellation automatically * (some of them even can't be applied on tessellated curve), set flag - * for incformation button in modifier's header */ + * for incformation button in modifier's header + */ md->mode |= eModifierMode_ApplyOnSpline; } - else if (md->mode&eModifierMode_ApplyOnSpline) { + else if (md->mode & eModifierMode_ApplyOnSpline) { pretessellatePoint = md; } } @@ -725,58 +744,70 @@ static ModifierData *curve_get_tessellate_point(Scene *scene, Object *ob, int fo return pretessellatePoint; } -static void curve_calc_modifiers_pre(Scene *scene, Object *ob, int forRender, float (**originalVerts_r)[3], float (**deformedVerts_r)[3], int *numVerts_r) +static void curve_calc_modifiers_pre(Scene *scene, Object *ob, int forRender, float (**originalVerts_r)[3], + float (**deformedVerts_r)[3], int *numVerts_r) { ModifierData *md = modifiers_getVirtualModifierList(ob); ModifierData *pretessellatePoint; - Curve *cu= ob->data; - ListBase *nurb= BKE_curve_nurbs_get(cu); + Curve *cu = ob->data; + ListBase *nurb = BKE_curve_nurbs_get(cu); int numVerts = 0; - int editmode = (!forRender && cu->editnurb); + const int editmode = (!forRender && cu->editnurb); + ModifierApplyFlag app_flag = 0; float (*originalVerts)[3] = NULL; float (*deformedVerts)[3] = NULL; - float *keyVerts= NULL; + float *keyVerts = NULL; int required_mode; - if (forRender) required_mode = eModifierMode_Render; - else required_mode = eModifierMode_Realtime; + if (editmode) + app_flag |= MOD_APPLY_USECACHE; + if (forRender) { + app_flag |= MOD_APPLY_RENDER; + required_mode = eModifierMode_Render; + } + else + required_mode = eModifierMode_Realtime; pretessellatePoint = curve_get_tessellate_point(scene, ob, forRender, editmode); - - if (editmode) required_mode |= eModifierMode_Editmode; - if (cu->editnurb==NULL) { - keyVerts= do_ob_key(scene, ob); + if (editmode) + required_mode |= eModifierMode_Editmode; + + if (cu->editnurb == NULL) { + keyVerts = do_ob_key(scene, ob); if (keyVerts) { /* split coords from key data, the latter also includes * tilts, which is passed through in the modifier stack. * this is also the reason curves do not use a virtual * shape key modifier yet. */ - deformedVerts= BKE_curve_keyVertexCos_get(cu, nurb, keyVerts); - originalVerts= MEM_dupallocN(deformedVerts); - numVerts = BKE_nurbList_verts_count_without_handles(nurb); + deformedVerts = BKE_curve_keyVertexCos_get(cu, nurb, keyVerts); + originalVerts = MEM_dupallocN(deformedVerts); + numVerts = BKE_nurbList_verts_count(nurb); } } - + if (pretessellatePoint) { - for (; md; md=md->next) { + for (; md; md = md->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); - md->scene= scene; - - if ((md->mode & required_mode) != required_mode) continue; - if (mti->isDisabled && mti->isDisabled(md, forRender)) continue; - if (mti->type!=eModifierTypeType_OnlyDeform) continue; + md->scene = scene; + + if ((md->mode & required_mode) != required_mode) + continue; + if (mti->isDisabled && mti->isDisabled(md, forRender)) + continue; + if (mti->type != eModifierTypeType_OnlyDeform) + continue; if (!deformedVerts) { deformedVerts = BKE_curve_vertexCos_get(cu, nurb, &numVerts); originalVerts = MEM_dupallocN(deformedVerts); } - mti->deformVerts(md, ob, NULL, deformedVerts, numVerts, forRender, editmode); + mti->deformVerts(md, ob, NULL, deformedVerts, numVerts, app_flag); - if (md==pretessellatePoint) + if (md == pretessellatePoint) break; } } @@ -794,22 +825,22 @@ static void curve_calc_modifiers_pre(Scene *scene, Object *ob, int forRender, fl *numVerts_r = numVerts; } -static float (*displist_get_allverts (ListBase *dispbase, int *totvert))[3] +static float (*displist_get_allverts(ListBase * dispbase, int *totvert))[3] { DispList *dl; float (*allverts)[3], *fp; - *totvert= 0; + *totvert = 0; - for (dl=dispbase->first; dl; dl=dl->next) - *totvert+= (dl->type==DL_INDEX3)?dl->nr:dl->parts*dl->nr; + for (dl = dispbase->first; dl; dl = dl->next) + *totvert += (dl->type == DL_INDEX3) ? dl->nr : dl->parts * dl->nr; - allverts= MEM_mallocN((*totvert)*sizeof(float)*3, "displist_get_allverts allverts"); - fp= (float*)allverts; - for (dl=dispbase->first; dl; dl=dl->next) { - int offs= 3 * ((dl->type==DL_INDEX3)?dl->nr:dl->parts*dl->nr); + allverts = MEM_mallocN((*totvert) * sizeof(float) * 3, "displist_get_allverts allverts"); + fp = (float *)allverts; + for (dl = dispbase->first; dl; dl = dl->next) { + int offs = 3 * ((dl->type == DL_INDEX3) ? dl->nr : dl->parts * dl->nr); memcpy(fp, dl->verts, sizeof(float) * offs); - fp+= offs; + fp += offs; } return allverts; @@ -820,52 +851,63 @@ static void displist_apply_allverts(ListBase *dispbase, float (*allverts)[3]) DispList *dl; float *fp; - fp= (float*)allverts; - for (dl=dispbase->first; dl; dl=dl->next) { - int offs= 3 * ((dl->type==DL_INDEX3)?dl->nr:dl->parts*dl->nr); + fp = (float *)allverts; + for (dl = dispbase->first; dl; dl = dl->next) { + int offs = 3 * ((dl->type == DL_INDEX3) ? dl->nr : dl->parts * dl->nr); memcpy(dl->verts, fp, sizeof(float) * offs); - fp+= offs; + fp += offs; } } -static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *dispbase, - DerivedMesh **derivedFinal, int forRender, float (*originalVerts)[3], float (*deformedVerts)[3]) +static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *dispbase, DerivedMesh **derivedFinal, + int forRender, float (*originalVerts)[3], float (*deformedVerts)[3]) { ModifierData *md = modifiers_getVirtualModifierList(ob); ModifierData *pretessellatePoint; - Curve *cu= ob->data; - ListBase *nurb= BKE_curve_nurbs_get(cu); + Curve *cu = ob->data; + ListBase *nurb = BKE_curve_nurbs_get(cu); int required_mode = 0, totvert = 0; int editmode = (!forRender && cu->editnurb); - DerivedMesh *dm= NULL, *ndm; + DerivedMesh *dm = NULL, *ndm; float (*vertCos)[3] = NULL; int useCache = !forRender; + ModifierApplyFlag app_flag = 0; - if (forRender) required_mode = eModifierMode_Render; - else required_mode = eModifierMode_Realtime; + if (forRender) { + app_flag |= MOD_APPLY_RENDER; + required_mode = eModifierMode_Render; + } + else + required_mode = eModifierMode_Realtime; pretessellatePoint = curve_get_tessellate_point(scene, ob, forRender, editmode); - - if (editmode) required_mode |= eModifierMode_Editmode; + + if (editmode) + required_mode |= eModifierMode_Editmode; if (pretessellatePoint) { md = pretessellatePoint->next; } if (derivedFinal && *derivedFinal) { - (*derivedFinal)->release (*derivedFinal); + (*derivedFinal)->release(*derivedFinal); } - for (; md; md=md->next) { + for (; md; md = md->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); + ModifierApplyFlag appf = app_flag; - md->scene= scene; + md->scene = scene; - if ((md->mode & required_mode) != required_mode) continue; - if (mti->isDisabled && mti->isDisabled(md, forRender)) continue; + if ((md->mode & required_mode) != required_mode) + continue; + if (mti->isDisabled && mti->isDisabled(md, forRender)) + continue; if (mti->type == eModifierTypeType_OnlyDeform || - (mti->type == eModifierTypeType_DeformOrConstruct && !dm)) { + (mti->type == eModifierTypeType_DeformOrConstruct && !dm)) { + if (editmode) + appf |= MOD_APPLY_USECACHE; if (dm) { if (!vertCos) { totvert = dm->getNumVerts(dm); @@ -873,21 +915,22 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *dispba dm->getVertCos(dm, vertCos); } - mti->deformVerts(md, ob, dm, vertCos, totvert, forRender, editmode); + mti->deformVerts(md, ob, dm, vertCos, totvert, appf); } else { if (!vertCos) { - vertCos= displist_get_allverts(dispbase, &totvert); + vertCos = displist_get_allverts(dispbase, &totvert); } - mti->deformVerts(md, ob, NULL, vertCos, totvert, forRender, editmode); + mti->deformVerts(md, ob, NULL, vertCos, totvert, appf); } } else { if (!derivedFinal) { - /* makeDisplistCurveTypes could be used for beveling, where derived mesh */ - /* is totally unnecessary, so we could stop modifiers applying */ - /* when we found constructive modifier but derived mesh is unwanted result */ + /* makeDisplistCurveTypes could be used for beveling, where derived mesh + * is totally unnecessary, so we could stop modifiers applying + * when we found constructive modifier but derived mesh is unwanted result + */ break; } @@ -910,7 +953,7 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *dispba curve_to_filledpoly(cu, nurb, dispbase); } - dm= CDDM_from_curve_customDB(ob, dispbase); + dm = CDDM_from_curve_customDB(ob, dispbase); CDDM_calc_normals_mapping(dm); } @@ -918,16 +961,18 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *dispba if (vertCos) { /* Vertex coordinates were applied to necessary data, could free it */ MEM_freeN(vertCos); - vertCos= NULL; + vertCos = NULL; } - ndm = mti->applyModifier(md, ob, dm, forRender, useCache); + if (useCache) + appf |= MOD_APPLY_USECACHE; + ndm = mti->applyModifier(md, ob, dm, appf); if (ndm) { /* Modifier returned a new derived mesh */ if (dm && dm != ndm) /* Modifier */ - dm->release (dm); + dm->release(dm); dm = ndm; } } @@ -946,12 +991,13 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *dispba else { displist_apply_allverts(dispbase, vertCos); MEM_freeN(vertCos); - vertCos= NULL; + vertCos = NULL; } } if (derivedFinal) { - if (dm) DM_ensure_tessface(dm); /* needed for drawing */ + if (dm) + DM_ensure_tessface(dm); /* needed for drawing */ (*derivedFinal) = dm; } @@ -966,42 +1012,40 @@ static void displist_surf_indices(DispList *dl) { int a, b, p1, p2, p3, p4; int *index; - - dl->totindex= 0; - - index=dl->index= MEM_mallocN(4*sizeof(int)*(dl->parts+1)*(dl->nr+1), "index array nurbs"); - - for (a=0; a<dl->parts; a++) { - - if (surfindex_displist(dl, a, &b, &p1, &p2, &p3, &p4)==0) + + dl->totindex = 0; + + index = dl->index = MEM_mallocN(4 * sizeof(int) * (dl->parts + 1) * (dl->nr + 1), "index array nurbs"); + + for (a = 0; a < dl->parts; a++) { + + if (BKE_displist_surfindex_get(dl, a, &b, &p1, &p2, &p3, &p4) == 0) break; - - for (; b<dl->nr; b++, index+=4) { - index[0]= p1; - index[1]= p2; - index[2]= p4; - index[3]= p3; - + + for (; b < dl->nr; b++, index += 4) { + index[0] = p1; + index[1] = p2; + index[2] = p4; + index[3] = p3; + dl->totindex++; - - p2= p1; p1++; - p4= p3; p3++; + p2 = p1; p1++; + p4 = p3; p3++; } } - } static DerivedMesh *create_orco_dm(Scene *scene, Object *ob) { DerivedMesh *dm; - ListBase disp= {NULL, NULL}; + ListBase disp = {NULL, NULL}; /* OrcoDM should be created from underformed disp lists */ - makeDispListCurveTypes_forOrco(scene, ob, &disp); - dm= CDDM_from_curve_customDB(ob, &disp); + BKE_displist_make_curveTypes_forOrco(scene, ob, &disp); + dm = CDDM_from_curve_customDB(ob, &disp); - freedisplist(&disp); + BKE_displist_free(&disp); return dm; } @@ -1010,12 +1054,12 @@ static void add_orco_dm(Scene *scene, Object *ob, DerivedMesh *dm, DerivedMesh * { float (*orco)[3], (*layerorco)[3]; int totvert, a; - Curve *cu= ob->data; + Curve *cu = ob->data; - totvert= dm->getNumVerts(dm); + totvert = dm->getNumVerts(dm); if (orcodm) { - orco= MEM_callocN(sizeof(float)*3*totvert, "dm orco"); + orco = MEM_callocN(sizeof(float) * 3 * totvert, "dm orco"); if (orcodm->getNumVerts(orcodm) == totvert) orcodm->getVertCos(orcodm, orco); @@ -1023,18 +1067,18 @@ static void add_orco_dm(Scene *scene, Object *ob, DerivedMesh *dm, DerivedMesh * dm->getVertCos(dm, orco); } else { - orco= (float(*)[3])BKE_curve_make_orco(scene, ob); + orco = (float(*)[3])BKE_curve_make_orco(scene, ob); } - for (a=0; a<totvert; a++) { + for (a = 0; a < totvert; a++) { float *co = orco[a]; - co[0] = (co[0]-cu->loc[0])/cu->size[0]; - co[1] = (co[1]-cu->loc[1])/cu->size[1]; - co[2] = (co[2]-cu->loc[2])/cu->size[2]; + co[0] = (co[0] - cu->loc[0]) / cu->size[0]; + co[1] = (co[1] - cu->loc[1]) / cu->size[1]; + co[2] = (co[2] - cu->loc[2]) / cu->size[2]; } if ((layerorco = DM_get_vert_data_layer(dm, CD_ORCO))) { - memcpy(layerorco, orco, sizeof(float)*totvert); + memcpy(layerorco, orco, sizeof(float) * totvert); MEM_freeN(orco); } else @@ -1043,40 +1087,48 @@ static void add_orco_dm(Scene *scene, Object *ob, DerivedMesh *dm, DerivedMesh * static void curve_calc_orcodm(Scene *scene, Object *ob, DerivedMesh *derivedFinal, int forRender) { - /* this function represents logic of mesh's orcodm calculation */ - /* for displist-based objects */ + /* this function represents logic of mesh's orcodm calculation + * for displist-based objects + */ ModifierData *md = modifiers_getVirtualModifierList(ob); ModifierData *pretessellatePoint; - Curve *cu= ob->data; + Curve *cu = ob->data; int required_mode; int editmode = (!forRender && cu->editnurb); - DerivedMesh *ndm, *orcodm= NULL; + DerivedMesh *ndm, *orcodm = NULL; + const ModifierApplyFlag app_flag = forRender ? MOD_APPLY_RENDER : 0; - if (forRender) required_mode = eModifierMode_Render; - else required_mode = eModifierMode_Realtime; + if (forRender) + required_mode = eModifierMode_Render; + else + required_mode = eModifierMode_Realtime; pretessellatePoint = curve_get_tessellate_point(scene, ob, forRender, editmode); - if (editmode) required_mode |= eModifierMode_Editmode; + if (editmode) + required_mode |= eModifierMode_Editmode; if (pretessellatePoint) { md = pretessellatePoint->next; } - for (; md; md=md->next) { + for (; md; md = md->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); - md->scene= scene; + md->scene = scene; - if ((md->mode & required_mode) != required_mode) continue; - if (mti->isDisabled && mti->isDisabled(md, forRender)) continue; - if (mti->type!=eModifierTypeType_Constructive) continue; + if ((md->mode & required_mode) != required_mode) + continue; + if (mti->isDisabled && mti->isDisabled(md, forRender)) + continue; + if (mti->type != eModifierTypeType_Constructive) + continue; if (!orcodm) - orcodm= create_orco_dm(scene, ob); + orcodm = create_orco_dm(scene, ob); - ndm = mti->applyModifier(md, ob, orcodm, forRender, 0); + ndm = mti->applyModifier(md, ob, orcodm, app_flag); if (ndm) { /* if the modifier returned a new dm, release the old one */ @@ -1094,8 +1146,8 @@ static void curve_calc_orcodm(Scene *scene, Object *ob, DerivedMesh *derivedFina orcodm->release(orcodm); } -void makeDispListSurf(Scene *scene, Object *ob, ListBase *dispbase, - DerivedMesh **derivedFinal, int forRender, int forOrco) +void BKE_displist_make_surf(Scene *scene, Object *ob, ListBase *dispbase, + DerivedMesh **derivedFinal, int forRender, int forOrco) { ListBase *nubase; Nurb *nu; @@ -1108,68 +1160,70 @@ void makeDispListSurf(Scene *scene, Object *ob, ListBase *dispbase, float (*deformedVerts)[3]; if (!forRender && cu->editnurb) - nubase= BKE_curve_editNurbs_get(cu); + nubase = BKE_curve_editNurbs_get(cu); else - nubase= &cu->nurb; + nubase = &cu->nurb; if (!forOrco) curve_calc_modifiers_pre(scene, ob, forRender, &originalVerts, &deformedVerts, &numVerts); - for (nu=nubase->first; nu; nu=nu->next) { - if (forRender || nu->hide==0) { - int resolu= nu->resolu, resolv= nu->resolv; + for (nu = nubase->first; nu; nu = nu->next) { + if (forRender || nu->hide == 0) { + int resolu = nu->resolu, resolv = nu->resolv; if (forRender) { - if (cu->resolu_ren) resolu= cu->resolu_ren; - if (cu->resolv_ren) resolv= cu->resolv_ren; + if (cu->resolu_ren) + resolu = cu->resolu_ren; + if (cu->resolv_ren) + resolv = cu->resolv_ren; } - if (nu->pntsv==1) { - len= SEGMENTSU(nu)*resolu; + if (nu->pntsv == 1) { + len = SEGMENTSU(nu) * resolu; - dl= MEM_callocN(sizeof(DispList), "makeDispListsurf"); - dl->verts= MEM_callocN(len*3*sizeof(float), "dlverts"); + dl = MEM_callocN(sizeof(DispList), "makeDispListsurf"); + dl->verts = MEM_callocN(len * 3 * sizeof(float), "dlverts"); BLI_addtail(dispbase, dl); - dl->parts= 1; - dl->nr= len; - dl->col= nu->mat_nr; - dl->charidx= nu->charidx; + dl->parts = 1; + dl->nr = len; + dl->col = nu->mat_nr; + dl->charidx = nu->charidx; /* dl->rt will be used as flag for render face and */ /* CU_2D conflicts with R_NOPUNOFLIP */ - dl->rt= nu->flag & ~CU_2D; + dl->rt = nu->flag & ~CU_2D; - data= dl->verts; - if (nu->flagu & CU_NURB_CYCLIC) dl->type= DL_POLY; - else dl->type= DL_SEGM; + data = dl->verts; + if (nu->flagu & CU_NURB_CYCLIC) dl->type = DL_POLY; + else dl->type = DL_SEGM; - BKE_nurb_makeCurve(nu, data, NULL, NULL, NULL, resolu, 3*sizeof(float)); + BKE_nurb_makeCurve(nu, data, NULL, NULL, NULL, resolu, 3 * sizeof(float)); } else { - len= (nu->pntsu*resolu) * (nu->pntsv*resolv); - - dl= MEM_callocN(sizeof(DispList), "makeDispListsurf"); - dl->verts= MEM_callocN(len*3*sizeof(float), "dlverts"); + len = (nu->pntsu * resolu) * (nu->pntsv * resolv); + + dl = MEM_callocN(sizeof(DispList), "makeDispListsurf"); + dl->verts = MEM_callocN(len * 3 * sizeof(float), "dlverts"); BLI_addtail(dispbase, dl); - dl->col= nu->mat_nr; - dl->charidx= nu->charidx; + dl->col = nu->mat_nr; + dl->charidx = nu->charidx; /* dl->rt will be used as flag for render face and */ /* CU_2D conflicts with R_NOPUNOFLIP */ - dl->rt= nu->flag & ~CU_2D; + dl->rt = nu->flag & ~CU_2D; - data= dl->verts; - dl->type= DL_SURF; + data = dl->verts; + dl->type = DL_SURF; - dl->parts= (nu->pntsu*resolu); /* in reverse, because makeNurbfaces works that way */ - dl->nr= (nu->pntsv*resolv); - if (nu->flagv & CU_NURB_CYCLIC) dl->flag|= DL_CYCL_U; /* reverse too! */ - if (nu->flagu & CU_NURB_CYCLIC) dl->flag|= DL_CYCL_V; + dl->parts = (nu->pntsu * resolu); /* in reverse, because makeNurbfaces works that way */ + dl->nr = (nu->pntsv * resolv); + if (nu->flagv & CU_NURB_CYCLIC) dl->flag |= DL_CYCL_U; /* reverse too! */ + if (nu->flagu & CU_NURB_CYCLIC) dl->flag |= DL_CYCL_V; BKE_nurb_makeFaces(nu, data, 0, resolu, resolv); - + /* gl array drawing: using indices */ displist_surf_indices(dl); } @@ -1179,15 +1233,16 @@ void makeDispListSurf(Scene *scene, Object *ob, ListBase *dispbase, /* make copy of 'undeformed" displist for texture space calculation * actually, it's not totally undeformed -- pre-tessellation modifiers are * already applied, thats how it worked for years, so keep for compatibility (sergey) */ - copy_displist(&cu->disp, dispbase); + BKE_displist_copy(&cu->disp, dispbase); if (!forRender) { - BKE_curve_tex_space_calc(cu); + BKE_curve_texspace_calc(cu); } - if (!forOrco) + if (!forOrco) { curve_calc_modifiers_post(scene, ob, dispbase, derivedFinal, - forRender, originalVerts, deformedVerts); + forRender, originalVerts, deformedVerts); + } } static void rotateBevelPiece(Curve *cu, BevPoint *bevp, DispList *dlb, float widfac, float fac, float **data_r) @@ -1196,24 +1251,24 @@ static void rotateBevelPiece(Curve *cu, BevPoint *bevp, DispList *dlb, float wid int b; fp = dlb->verts; - for (b = 0; b<dlb->nr; b++, fp += 3, data += 3) { + for (b = 0; b < dlb->nr; b++, fp += 3, data += 3) { if (cu->flag & CU_3D) { float vec[3]; - vec[0] = fp[1]+widfac; + vec[0] = fp[1] + widfac; vec[1] = fp[2]; - vec[2 ]= 0.0; + vec[2] = 0.0; mul_qt_v3(bevp->quat, vec); - data[0] = bevp->vec[0] + fac*vec[0]; - data[1] = bevp->vec[1] + fac*vec[1]; - data[2] = bevp->vec[2] + fac*vec[2]; + data[0] = bevp->vec[0] + fac * vec[0]; + data[1] = bevp->vec[1] + fac * vec[1]; + data[2] = bevp->vec[2] + fac * vec[2]; } else { - data[0] = bevp->vec[0] + fac*(widfac+fp[1])*bevp->sina; - data[1] = bevp->vec[1] + fac*(widfac+fp[1])*bevp->cosa; - data[2] = bevp->vec[2] + fac*fp[2]; + data[0] = bevp->vec[0] + fac * (widfac + fp[1]) * bevp->sina; + data[1] = bevp->vec[1] + fac * (widfac + fp[1]) * bevp->cosa; + data[2] = bevp->vec[2] + fac * fp[2]; } } @@ -1226,19 +1281,19 @@ static void fillBevelCap(Nurb *nu, DispList *dlb, float *prev_fp, ListBase *disp float *data; int b; - dl= MEM_callocN(sizeof(DispList), "makeDispListbev2"); - dl->verts= data= MEM_callocN(3*sizeof(float)*dlb->nr, "dlverts"); + dl = MEM_callocN(sizeof(DispList), "makeDispListbev2"); + dl->verts = data = MEM_callocN(3 * sizeof(float) * dlb->nr, "dlverts"); - dl->type= DL_POLY; + dl->type = DL_POLY; - dl->parts= 1; - dl->nr= dlb->nr; - dl->col= nu->mat_nr; - dl->charidx= nu->charidx; + dl->parts = 1; + dl->nr = dlb->nr; + dl->col = nu->mat_nr; + dl->charidx = nu->charidx; /* dl->rt will be used as flag for render face and */ /* CU_2D conflicts with R_NOPUNOFLIP */ - dl->rt= nu->flag & ~CU_2D; + dl->rt = nu->flag & ~CU_2D; for (b = 0; b < dlb->nr; b++, prev_fp += 3, data += 3) copy_v3_v3(data, prev_fp); @@ -1247,15 +1302,15 @@ static void fillBevelCap(Nurb *nu, DispList *dlb, float *prev_fp, ListBase *disp } static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispbase, - DerivedMesh **derivedFinal, int forRender, int forOrco) + DerivedMesh **derivedFinal, int forRender, int forOrco) { Curve *cu = ob->data; /* we do allow duplis... this is only displist on curve level */ if (!ELEM3(ob->type, OB_SURF, OB_CURVE, OB_FONT)) return; - if (ob->type==OB_SURF) { - makeDispListSurf(scene, ob, dispbase, derivedFinal, forRender, forOrco); + if (ob->type == OB_SURF) { + BKE_displist_make_surf(scene, ob, dispbase, derivedFinal, forRender, forOrco); } else if (ELEM(ob->type, OB_CURVE, OB_FONT)) { ListBase dlbev; @@ -1264,16 +1319,18 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba float (*deformedVerts)[3]; int numVerts; - nubase= BKE_curve_nurbs_get(cu); + nubase = BKE_curve_nurbs_get(cu); BLI_freelistN(&(cu->bev)); if (cu->path) free_path(cu->path); - cu->path= NULL; + cu->path = NULL; - if (ob->type==OB_FONT) BKE_text_to_curve(G.main, scene, ob, 0); + if (ob->type == OB_FONT) + BKE_vfont_to_curve(G.main, scene, ob, 0); - if (!forOrco) curve_calc_modifiers_pre(scene, ob, forRender, &originalVerts, &deformedVerts, &numVerts); + if (!forOrco) + curve_calc_modifiers_pre(scene, ob, forRender, &originalVerts, &deformedVerts, &numVerts); BKE_curve_bevelList_make(ob); @@ -1281,15 +1338,15 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba BKE_curve_bevel_make(scene, ob, &dlbev, forRender); /* no bevel or extrude, and no width correction? */ - if (!dlbev.first && cu->width==1.0f) { + if (!dlbev.first && cu->width == 1.0f) { curve_to_displist(cu, nubase, dispbase, forRender); } else { - float widfac= cu->width - 1.0f; - BevList *bl= cu->bev.first; - Nurb *nu= nubase->first; + float widfac = cu->width - 1.0f; + BevList *bl = cu->bev.first; + Nurb *nu = nubase->first; - for (; bl && nu; bl=bl->next, nu=nu->next) { + for (; bl && nu; bl = bl->next, nu = nu->next) { DispList *dl; float *data; BevPoint *bevp; @@ -1298,34 +1355,34 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba if (bl->nr) { /* blank bevel lists can happen */ /* exception handling; curve without bevel or extrude, with width correction */ - if (dlbev.first==NULL) { - dl= MEM_callocN(sizeof(DispList), "makeDispListbev"); - dl->verts= MEM_callocN(3*sizeof(float)*bl->nr, "dlverts"); + if (dlbev.first == NULL) { + dl = MEM_callocN(sizeof(DispList), "makeDispListbev"); + dl->verts = MEM_callocN(3 * sizeof(float) * bl->nr, "dlverts"); BLI_addtail(dispbase, dl); - if (bl->poly!= -1) dl->type= DL_POLY; - else dl->type= DL_SEGM; + if (bl->poly != -1) dl->type = DL_POLY; + else dl->type = DL_SEGM; - if (dl->type==DL_SEGM) dl->flag = (DL_FRONT_CURVE|DL_BACK_CURVE); + if (dl->type == DL_SEGM) dl->flag = (DL_FRONT_CURVE | DL_BACK_CURVE); - dl->parts= 1; - dl->nr= bl->nr; - dl->col= nu->mat_nr; - dl->charidx= nu->charidx; + dl->parts = 1; + dl->nr = bl->nr; + dl->col = nu->mat_nr; + dl->charidx = nu->charidx; /* dl->rt will be used as flag for render face and */ /* CU_2D conflicts with R_NOPUNOFLIP */ - dl->rt= nu->flag & ~CU_2D; + dl->rt = nu->flag & ~CU_2D; - a= dl->nr; - bevp= (BevPoint *)(bl+1); - data= dl->verts; + a = dl->nr; + bevp = (BevPoint *)(bl + 1); + data = dl->verts; while (a--) { - data[0]= bevp->vec[0]+widfac*bevp->sina; - data[1]= bevp->vec[1]+widfac*bevp->cosa; - data[2]= bevp->vec[2]; + data[0] = bevp->vec[0] + widfac * bevp->sina; + data[1] = bevp->vec[1] + widfac * bevp->cosa; + data[2] = bevp->vec[2]; bevp++; - data+=3; + data += 3; } } else { @@ -1333,7 +1390,7 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba ListBase bottom_capbase = {NULL, NULL}; ListBase top_capbase = {NULL, NULL}; - for (dlb=dlbev.first; dlb; dlb=dlb->next) { + for (dlb = dlbev.first; dlb; dlb = dlb->next) { int i, start, steps; float bevfac1 = MIN2(cu->bevfac1, cu->bevfac2), bevfac2 = MAX2(cu->bevfac1, cu->bevfac2); float firstblend = 0.0f, lastblend = 0.0f; @@ -1341,10 +1398,10 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba if (cu->bevfac1 - cu->bevfac2 == 0.0f) continue; - start = (int)(bevfac1*(bl->nr-1)); - steps = 2+(int)((bevfac2)*(bl->nr-1)) - start; - firstblend = 1.0f - ((float)bevfac1*(bl->nr-1) - (int)((float)bevfac1*(bl->nr-1))); - lastblend = (float)bevfac2*(bl->nr-1) - (int)((float)bevfac2*(bl->nr-1)); + start = (int)(bevfac1 * (bl->nr - 1)); + steps = 2 + (int)((bevfac2) * (bl->nr - 1)) - start; + firstblend = 1.0f - ((float)bevfac1 * (bl->nr - 1) - (int)((float)bevfac1 * (bl->nr - 1))); + lastblend = (float)bevfac2 * (bl->nr - 1) - (int)((float)bevfac2 * (bl->nr - 1)); if (steps > bl->nr) { steps = bl->nr; @@ -1352,50 +1409,51 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba } /* for each part of the bevel use a separate displblock */ - dl= MEM_callocN(sizeof(DispList), "makeDispListbev1"); - dl->verts= data= MEM_callocN(3*sizeof(float)*dlb->nr*steps, "dlverts"); + dl = MEM_callocN(sizeof(DispList), "makeDispListbev1"); + dl->verts = data = MEM_callocN(3 * sizeof(float) * dlb->nr * steps, "dlverts"); BLI_addtail(dispbase, dl); - - dl->type= DL_SURF; - - dl->flag= dlb->flag & (DL_FRONT_CURVE|DL_BACK_CURVE); - if (dlb->type==DL_POLY) dl->flag |= DL_CYCL_U; - if (bl->poly>=0) dl->flag |= DL_CYCL_V; - - dl->parts= steps; - dl->nr= dlb->nr; - dl->col= nu->mat_nr; - dl->charidx= nu->charidx; + + dl->type = DL_SURF; + + dl->flag = dlb->flag & (DL_FRONT_CURVE | DL_BACK_CURVE); + if (dlb->type == DL_POLY) dl->flag |= DL_CYCL_U; + if (bl->poly >= 0) dl->flag |= DL_CYCL_V; + + dl->parts = steps; + dl->nr = dlb->nr; + dl->col = nu->mat_nr; + dl->charidx = nu->charidx; /* dl->rt will be used as flag for render face and */ /* CU_2D conflicts with R_NOPUNOFLIP */ - dl->rt= nu->flag & ~CU_2D; + dl->rt = nu->flag & ~CU_2D; + + dl->bevelSplitFlag = MEM_callocN(sizeof(*dl->col2) * ((steps + 0x1F) >> 5), + "bevelSplitFlag"); - dl->bevelSplitFlag= MEM_callocN(sizeof(*dl->col2)*((steps+0x1F)>>5), "bevelSplitFlag"); - /* for each point of poly make a bevel piece */ - bevp= (BevPoint *)(bl+1) + start; - for (i=start, a=0; a<steps; i++,bevp++,a++) { - float fac=1.0; + bevp = (BevPoint *)(bl + 1) + start; + for (i = start, a = 0; a < steps; i++, bevp++, a++) { + float fac = 1.0; float *cur_data = data; - if (cu->taperobj==NULL) { - if ( (cu->bevobj!=NULL) || !((cu->flag & CU_FRONT) || (cu->flag & CU_BACK)) ) + if (cu->taperobj == NULL) { + if ( (cu->bevobj != NULL) || !((cu->flag & CU_FRONT) || (cu->flag & CU_BACK)) ) fac = bevp->radius; } else { - fac = calc_taper(scene, cu->taperobj, i, bl->nr); + fac = BKE_displist_calc_taper(scene, cu->taperobj, i, bl->nr); } if (bevp->split_tag) { - dl->bevelSplitFlag[a>>5] |= 1<<(a&0x1F); + dl->bevelSplitFlag[a >> 5] |= 1 << (a & 0x1F); } - + /* rotate bevel piece and write in data */ rotateBevelPiece(cu, bevp, dlb, widfac, fac, &data); if (a == 1 || a == steps - 1) { - float *cur_fp = cur_data, *prev_fp = cur_data - 3*dlb->nr; + float *cur_fp = cur_data, *prev_fp = cur_data - 3 * dlb->nr; int b; for (b = 0; b < dlb->nr; b++, prev_fp += 3, cur_fp += 3) { @@ -1415,8 +1473,8 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba } if (cu->bevobj && (cu->flag & CU_FILL_CAPS)) { - if (a == 1) - fillBevelCap(nu, dlb, cur_data - 3*dlb->nr, &bottom_capbase); + if (a == 1) + fillBevelCap(nu, dlb, cur_data - 3 * dlb->nr, &bottom_capbase); if (a == steps - 1) fillBevelCap(nu, dlb, cur_data, &top_capbase); } @@ -1427,34 +1485,36 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba } if (bottom_capbase.first) { - filldisplist(&bottom_capbase, dispbase, 1); - filldisplist(&top_capbase, dispbase, 0); - freedisplist(&bottom_capbase); - freedisplist(&top_capbase); + BKE_displist_fill(&bottom_capbase, dispbase, 1); + BKE_displist_fill(&top_capbase, dispbase, 0); + BKE_displist_free(&bottom_capbase); + BKE_displist_free(&top_capbase); } } } } - freedisplist(&dlbev); + BKE_displist_free(&dlbev); } if (!(cu->flag & CU_DEFORM_FILL)) { curve_to_filledpoly(cu, nubase, dispbase); } - if ((cu->flag & CU_PATH) && !forOrco) calc_curvepath(ob); + if ((cu->flag & CU_PATH) && !forOrco) + calc_curvepath(ob); /* make copy of 'undeformed" displist for texture space calculation * actually, it's not totally undeformed -- pre-tessellation modifiers are * already applied, thats how it worked for years, so keep for compatibility (sergey) */ - copy_displist(&cu->disp, dispbase); + BKE_displist_copy(&cu->disp, dispbase); if (!forRender) { - BKE_curve_tex_space_calc(cu); + BKE_curve_texspace_calc(cu); } - if (!forOrco) curve_calc_modifiers_post(scene, ob, dispbase, derivedFinal, forRender, originalVerts, deformedVerts); + if (!forOrco) + curve_calc_modifiers_post(scene, ob, dispbase, derivedFinal, forRender, originalVerts, deformedVerts); if (cu->flag & CU_DEFORM_FILL && !ob->derivedFinal) { curve_to_filledpoly(cu, nubase, dispbase); @@ -1462,66 +1522,67 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba } } -void makeDispListCurveTypes(Scene *scene, Object *ob, int forOrco) +void BKE_displist_make_curveTypes(Scene *scene, Object *ob, int forOrco) { - Curve *cu= ob->data; + Curve *cu = ob->data; ListBase *dispbase; /* The same check for duplis as in do_makeDispListCurveTypes. * Happens when curve used for constraint/bevel was converted to mesh. * check there is still needed for render displist and orco displists. */ - if (!ELEM3(ob->type, OB_SURF, OB_CURVE, OB_FONT)) return; + if (!ELEM3(ob->type, OB_SURF, OB_CURVE, OB_FONT)) + return; - freedisplist(&(ob->disp)); - dispbase= &(ob->disp); - freedisplist(dispbase); + BKE_displist_free(&(ob->disp)); + dispbase = &(ob->disp); + BKE_displist_free(dispbase); /* free displist used for textspace */ - freedisplist(&cu->disp); + BKE_displist_free(&cu->disp); do_makeDispListCurveTypes(scene, ob, dispbase, &ob->derivedFinal, 0, forOrco); if (ob->derivedFinal) { - DM_set_object_boundbox (ob, ob->derivedFinal); + DM_set_object_boundbox(ob, ob->derivedFinal); } else { - boundbox_displist (ob); + boundbox_displist(ob); /* if there is no derivedMesh, object's boundbox is unneeded */ if (ob->bb) { MEM_freeN(ob->bb); - ob->bb= NULL; + ob->bb = NULL; } } } -void makeDispListCurveTypes_forRender(Scene *scene, Object *ob, ListBase *dispbase, - DerivedMesh **derivedFinal, int forOrco) +void BKE_displist_make_curveTypes_forRender(Scene *scene, Object *ob, ListBase *dispbase, + DerivedMesh **derivedFinal, int forOrco) { do_makeDispListCurveTypes(scene, ob, dispbase, derivedFinal, 1, forOrco); } -void makeDispListCurveTypes_forOrco(struct Scene *scene, struct Object *ob, struct ListBase *dispbase) +void BKE_displist_make_curveTypes_forOrco(struct Scene *scene, struct Object *ob, struct ListBase *dispbase) { do_makeDispListCurveTypes(scene, ob, dispbase, NULL, 1, 1); } /* add Orco layer to the displist object which has got derived mesh and return orco */ -float *makeOrcoDispList(Scene *scene, Object *ob, DerivedMesh *derivedFinal, int forRender) +float *BKE_displist_make_orco(Scene *scene, Object *ob, DerivedMesh *derivedFinal, int forRender) { float *orco; if (derivedFinal == NULL) - derivedFinal= ob->derivedFinal; + derivedFinal = ob->derivedFinal; if (!derivedFinal->getVertDataArray(derivedFinal, CD_ORCO)) { curve_calc_orcodm(scene, ob, derivedFinal, forRender); } - orco= derivedFinal->getVertDataArray(derivedFinal, CD_ORCO); + orco = derivedFinal->getVertDataArray(derivedFinal, CD_ORCO); if (orco) { - orco= MEM_dupallocN(orco); + orco = MEM_dupallocN(orco); } return orco; @@ -1530,46 +1591,45 @@ float *makeOrcoDispList(Scene *scene, Object *ob, DerivedMesh *derivedFinal, int /* this is confusing, there's also min_max_object, appplying the obmat... */ static void boundbox_displist(Object *ob) { - BoundBox *bb=NULL; + BoundBox *bb = NULL; float min[3], max[3]; DispList *dl; float *vert; - int a, tot=0; - + int a, tot = 0; + INIT_MINMAX(min, max); if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) { - Curve *cu= ob->data; - int doit= 0; + Curve *cu = ob->data; + int doit = 0; - if (cu->bb==NULL) cu->bb= MEM_callocN(sizeof(BoundBox), "boundbox"); - bb= cu->bb; - - dl= ob->disp.first; + if (cu->bb == NULL) cu->bb = MEM_callocN(sizeof(BoundBox), "boundbox"); + bb = cu->bb; + + dl = ob->disp.first; while (dl) { - if (dl->type==DL_INDEX3) tot= dl->nr; - else tot= dl->nr*dl->parts; - - vert= dl->verts; - for (a=0; a<tot; a++, vert+=3) { - doit= 1; + if (dl->type == DL_INDEX3) tot = dl->nr; + else tot = dl->nr * dl->parts; + + vert = dl->verts; + for (a = 0; a < tot; a++, vert += 3) { + doit = 1; DO_MINMAX(vert, min, max); } - dl= dl->next; + dl = dl->next; } - + if (!doit) { /* there's no geometry in displist, use zero-sized boundbox */ zero_v3(min); zero_v3(max); } - + } - + if (bb) { - boundbox_set_from_min_max(bb, min, max); + BKE_boundbox_init_from_minmax(bb, min, max); } } - diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 6c5826c5bab..2bde31cfd63 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -540,11 +540,11 @@ static int subframe_updateObject(Scene *scene, Object *ob, int flags, float fram /* ignore cache clear during subframe updates * to not mess up cache validity */ object_cacheIgnoreClear(ob, 1); - object_handle_update(scene, ob); + BKE_object_handle_update(scene, ob); object_cacheIgnoreClear(ob, 0); } else - where_is_object_time(scene, ob, frame); + BKE_object_where_is_calc_time(scene, ob, frame); return 0; } @@ -3066,7 +3066,7 @@ static void dynamicPaint_brushMeshCalculateVelocity(Scene *scene, Object *ob, Dy scene->r.cfra = prev_fra; scene->r.subframe = prev_sfra; - subframe_updateObject(scene, ob, UPDATE_EVERYTHING, BKE_curframe(scene)); + subframe_updateObject(scene, ob, UPDATE_EVERYTHING, BKE_scene_frame_get(scene)); dm_p = CDDM_copy(brush->dm); numOfVerts_p = dm_p->getNumVerts(dm_p); mvert_p = dm_p->getVertArray(dm_p); @@ -3076,7 +3076,7 @@ static void dynamicPaint_brushMeshCalculateVelocity(Scene *scene, Object *ob, Dy scene->r.cfra = cur_fra; scene->r.subframe = cur_sfra; - subframe_updateObject(scene, ob, UPDATE_EVERYTHING, BKE_curframe(scene)); + subframe_updateObject(scene, ob, UPDATE_EVERYTHING, BKE_scene_frame_get(scene)); dm_c = brush->dm; numOfVerts_c = dm_c->getNumVerts(dm_c); mvert_c = dm_p->getVertArray(dm_c); @@ -3126,13 +3126,13 @@ static void dynamicPaint_brushObjectCalculateVelocity(Scene *scene, Object *ob, /* previous frame dm */ scene->r.cfra = prev_fra; scene->r.subframe = prev_sfra; - subframe_updateObject(scene, ob, UPDATE_PARENTS, BKE_curframe(scene)); + subframe_updateObject(scene, ob, UPDATE_PARENTS, BKE_scene_frame_get(scene)); copy_m4_m4(prev_obmat, ob->obmat); /* current frame dm */ scene->r.cfra = cur_fra; scene->r.subframe = cur_sfra; - subframe_updateObject(scene, ob, UPDATE_PARENTS, BKE_curframe(scene)); + subframe_updateObject(scene, ob, UPDATE_PARENTS, BKE_scene_frame_get(scene)); /* calculate speed */ mul_m4_v3(prev_obmat, prev_loc); @@ -4841,7 +4841,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su /* update object data on this subframe */ if (subframe) { scene_setSubframe(scene, subframe); - subframe_updateObject(scene, brushObj, UPDATE_EVERYTHING, BKE_curframe(scene)); + subframe_updateObject(scene, brushObj, UPDATE_EVERYTHING, BKE_scene_frame_get(scene)); } /* Prepare materials if required */ if (brush_usesMaterial(brush, scene)) @@ -4854,7 +4854,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su psys_check_enabled(brushObj, brush->psys)) { /* Paint a particle system */ - BKE_animsys_evaluate_animdata(scene, &brush->psys->part->id, brush->psys->part->adt, BKE_curframe(scene), ADT_RECALC_ANIM); + BKE_animsys_evaluate_animdata(scene, &brush->psys->part->id, brush->psys->part->adt, BKE_scene_frame_get(scene), ADT_RECALC_ANIM); dynamicPaint_paintParticles(surface, brush->psys, brush, timescale); } } @@ -4874,7 +4874,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su if (subframe) { scene->r.cfra = scene_frame; scene->r.subframe = scene_subframe; - subframe_updateObject(scene, brushObj, UPDATE_EVERYTHING, BKE_curframe(scene)); + subframe_updateObject(scene, brushObj, UPDATE_EVERYTHING, BKE_scene_frame_get(scene)); } /* process special brush effects, like smudge */ diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index 7fb0cf9f0fa..1d109d5f616 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -181,7 +181,7 @@ static void precalculate_effector(EffectorCache *eff) Curve *cu= eff->ob->data; if (cu->flag & CU_PATH) { if (cu->path==NULL || cu->path->data==NULL) - makeDispListCurveTypes(eff->scene, eff->ob, 0); + BKE_displist_make_curveTypes(eff->scene, eff->ob, 0); if (cu->path && cu->path->data) { where_on_path(eff->ob, 0.0, eff->guide_loc, eff->guide_dir, NULL, &eff->guide_radius, NULL); @@ -202,9 +202,9 @@ static void precalculate_effector(EffectorCache *eff) if (eff->ob) { float old_vel[3]; - where_is_object_time(eff->scene, eff->ob, cfra - 1.0f); + BKE_object_where_is_calc_time(eff->scene, eff->ob, cfra - 1.0f); copy_v3_v3(old_vel, eff->ob->obmat[3]); - where_is_object_time(eff->scene, eff->ob, cfra); + BKE_object_where_is_calc_time(eff->scene, eff->ob, cfra); sub_v3_v3v3(eff->velocity, eff->ob->obmat[3], old_vel); } } diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 0414d69785f..9d878cd185f 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -107,19 +107,19 @@ void free_fcurves(ListBase *list) * as we store reference to next, and freeing only touches the curve * it's given */ - for (fcu= list->first; fcu; fcu= fcn) { - fcn= fcu->next; + for (fcu = list->first; fcu; fcu = fcn) { + fcn = fcu->next; free_fcurve(fcu); } /* clear pointers just in case */ - list->first= list->last= NULL; + list->first = list->last = NULL; } /* ---------------------- Copy --------------------------- */ /* duplicate an F-Curve */ -FCurve *copy_fcurve (FCurve *fcu) +FCurve *copy_fcurve(FCurve *fcu) { FCurve *fcu_d; @@ -128,20 +128,20 @@ FCurve *copy_fcurve (FCurve *fcu) return NULL; /* make a copy */ - fcu_d= MEM_dupallocN(fcu); + fcu_d = MEM_dupallocN(fcu); - fcu_d->next= fcu_d->prev= NULL; - fcu_d->grp= NULL; + fcu_d->next = fcu_d->prev = NULL; + fcu_d->grp = NULL; /* copy curve data */ - fcu_d->bezt= MEM_dupallocN(fcu_d->bezt); - fcu_d->fpt= MEM_dupallocN(fcu_d->fpt); + fcu_d->bezt = MEM_dupallocN(fcu_d->bezt); + fcu_d->fpt = MEM_dupallocN(fcu_d->fpt); /* copy rna-path */ - fcu_d->rna_path= MEM_dupallocN(fcu_d->rna_path); + fcu_d->rna_path = MEM_dupallocN(fcu_d->rna_path); /* copy driver */ - fcu_d->driver= fcurve_copy_driver(fcu_d->driver); + fcu_d->driver = fcurve_copy_driver(fcu_d->driver); /* copy modifiers */ copy_fmodifiers(&fcu_d->modifiers, &fcu->modifiers); @@ -160,11 +160,11 @@ void copy_fcurves(ListBase *dst, ListBase *src) return; /* clear destination list first */ - dst->first= dst->last= NULL; + dst->first = dst->last = NULL; /* copy one-by-one */ - for (sfcu= src->first; sfcu; sfcu= sfcu->next) { - dfcu= copy_fcurve(sfcu); + for (sfcu = src->first; sfcu; sfcu = sfcu->next) { + dfcu = copy_fcurve(sfcu); BLI_addtail(dst, dfcu); } } @@ -175,8 +175,8 @@ void copy_fcurves(ListBase *dst, ListBase *src) FCurve *id_data_find_fcurve(ID *id, void *data, StructRNA *type, const char *prop_name, int index, char *driven) { /* anim vars */ - AnimData *adt= BKE_animdata_from_id(id); - FCurve *fcu= NULL; + AnimData *adt = BKE_animdata_from_id(id); + FCurve *fcu = NULL; /* rna vars */ PointerRNA ptr; @@ -194,16 +194,16 @@ FCurve *id_data_find_fcurve(ID *id, void *data, StructRNA *type, const char *pro prop = RNA_struct_find_property(&ptr, prop_name); if (prop) { - path= RNA_path_from_ID_to_property(&ptr, prop); + path = RNA_path_from_ID_to_property(&ptr, prop); if (path) { /* animation takes priority over drivers */ if ((adt->action) && (adt->action->curves.first)) - fcu= list_find_fcurve(&adt->action->curves, path, index); + fcu = list_find_fcurve(&adt->action->curves, path, index); /* if not animated, check if driven */ if ((fcu == NULL) && (adt->drivers.first)) { - fcu= list_find_fcurve(&adt->drivers, path, index); + fcu = list_find_fcurve(&adt->drivers, path, index); if (fcu && driven) *driven = TRUE; fcu = NULL; @@ -218,16 +218,16 @@ FCurve *id_data_find_fcurve(ID *id, void *data, StructRNA *type, const char *pro /* Find the F-Curve affecting the given RNA-access path + index, in the list of F-Curves provided */ -FCurve *list_find_fcurve (ListBase *list, const char rna_path[], const int array_index) +FCurve *list_find_fcurve(ListBase *list, const char rna_path[], const int array_index) { FCurve *fcu; /* sanity checks */ - if ( ELEM(NULL, list, rna_path) || (array_index < 0) ) + if (ELEM(NULL, list, rna_path) || (array_index < 0) ) return NULL; /* check paths of curves, then array indices... */ - for (fcu= list->first; fcu; fcu= fcu->next) { + for (fcu = list->first; fcu; fcu = fcu->next) { /* simple string-compare (this assumes that they have the same root...) */ if (fcu->rna_path && !strcmp(fcu->rna_path, rna_path)) { /* now check indices */ @@ -241,7 +241,7 @@ FCurve *list_find_fcurve (ListBase *list, const char rna_path[], const int array } /* quick way to loop over all fcurves of a given 'path' */ -FCurve *iter_step_fcurve (FCurve *fcu_iter, const char rna_path[]) +FCurve *iter_step_fcurve(FCurve *fcu_iter, const char rna_path[]) { FCurve *fcu; @@ -250,7 +250,7 @@ FCurve *iter_step_fcurve (FCurve *fcu_iter, const char rna_path[]) return NULL; /* check paths of curves, then array indices... */ - for (fcu= fcu_iter; fcu; fcu= fcu->next) { + for (fcu = fcu_iter; fcu; fcu = fcu->next) { /* simple string-compare (this assumes that they have the same root...) */ if (fcu->rna_path && !strcmp(fcu->rna_path, rna_path)) { return fcu; @@ -267,8 +267,8 @@ FCurve *iter_step_fcurve (FCurve *fcu_iter, const char rna_path[]) * List must be freed after use, and is assumed to be empty when passed. * - src: list of F-Curves to search through * Filters... - * - dataPrefix: i.e. 'pose.bones[' or 'nodes[' - * - dataName: name of entity within "" immediately following the prefix + * - dataPrefix: i.e. 'pose.bones[' or 'nodes[' + * - dataName: name of entity within "" immediately following the prefix */ int list_find_data_fcurves(ListBase *dst, ListBase *src, const char *dataPrefix, const char *dataName) { @@ -282,17 +282,17 @@ int list_find_data_fcurves(ListBase *dst, ListBase *src, const char *dataPrefix, return 0; /* search each F-Curve one by one */ - for (fcu= src->first; fcu; fcu= fcu->next) { + for (fcu = src->first; fcu; fcu = fcu->next) { /* check if quoted string matches the path */ if ((fcu->rna_path) && strstr(fcu->rna_path, dataPrefix)) { - char *quotedName= BLI_getQuotedStr(fcu->rna_path, dataPrefix); + char *quotedName = BLI_getQuotedStr(fcu->rna_path, dataPrefix); if (quotedName) { /* check if the quoted name matches the required name */ if (strcmp(quotedName, dataName) == 0) { - LinkData *ld= MEM_callocN(sizeof(LinkData), "list_find_data_fcurves"); + LinkData *ld = MEM_callocN(sizeof(LinkData), "list_find_data_fcurves"); - ld->data= fcu; + ld->data = fcu; BLI_addtail(dst, ld); matches++; @@ -308,37 +308,37 @@ int list_find_data_fcurves(ListBase *dst, ListBase *src, const char *dataPrefix, return matches; } -FCurve *rna_get_fcurve (PointerRNA *ptr, PropertyRNA *prop, int rnaindex, bAction **action, int *driven) +FCurve *rna_get_fcurve(PointerRNA *ptr, PropertyRNA *prop, int rnaindex, bAction **action, int *driven) { - FCurve *fcu= NULL; + FCurve *fcu = NULL; - *driven= 0; + *driven = 0; /* there must be some RNA-pointer + property combon */ if (prop && ptr->id.data && RNA_property_animateable(ptr, prop)) { - AnimData *adt= BKE_animdata_from_id(ptr->id.data); + AnimData *adt = BKE_animdata_from_id(ptr->id.data); char *path; if (adt) { if ((adt->action && adt->action->curves.first) || (adt->drivers.first)) { /* XXX this function call can become a performance bottleneck */ - path= RNA_path_from_ID_to_property(ptr, prop); + path = RNA_path_from_ID_to_property(ptr, prop); if (path) { /* animation takes priority over drivers */ if (adt->action && adt->action->curves.first) - fcu= list_find_fcurve(&adt->action->curves, path, rnaindex); + fcu = list_find_fcurve(&adt->action->curves, path, rnaindex); /* if not animated, check if driven */ if (!fcu && (adt->drivers.first)) { - fcu= list_find_fcurve(&adt->drivers, path, rnaindex); + fcu = list_find_fcurve(&adt->drivers, path, rnaindex); if (fcu) - *driven= 1; + *driven = 1; } if (fcu && action) - *action= adt->action; + *action = adt->action; MEM_freeN(path); } @@ -352,18 +352,18 @@ FCurve *rna_get_fcurve (PointerRNA *ptr, PropertyRNA *prop, int rnaindex, bActio /* ----------------- Finding Keyframes/Extents -------------------------- */ /* threshold for binary-searching keyframes - threshold here should be good enough for now, but should become userpref */ -#define BEZT_BINARYSEARCH_THRESH 0.01f /* was 0.00001, but giving errors */ +#define BEZT_BINARYSEARCH_THRESH 0.01f /* was 0.00001, but giving errors */ /* Binary search algorithm for finding where to insert BezTriple. (for use by insert_bezt_fcurve) * Returns the index to insert at (data already at that index will be offset if replace is 0) */ int binarysearch_bezt_index(BezTriple array[], float frame, int arraylen, short *replace) { - int start=0, end=arraylen; - int loopbreaker= 0, maxloop= arraylen * 2; + int start = 0, end = arraylen; + int loopbreaker = 0, maxloop = arraylen * 2; /* initialize replace-flag first */ - *replace= 0; + *replace = 0; /* sneaky optimisations (don't go through searching process if...): * - keyframe to be added is to be added out of current bounds @@ -378,7 +378,7 @@ int binarysearch_bezt_index(BezTriple array[], float frame, int arraylen, short float framenum; /* 'First' Keyframe (when only one keyframe, this case is used) */ - framenum= array[0].vec[1][0]; + framenum = array[0].vec[1][0]; if (IS_EQT(frame, framenum, BEZT_BINARYSEARCH_THRESH)) { *replace = 1; return 0; @@ -387,9 +387,9 @@ int binarysearch_bezt_index(BezTriple array[], float frame, int arraylen, short return 0; /* 'Last' Keyframe */ - framenum= array[(arraylen-1)].vec[1][0]; + framenum = array[(arraylen - 1)].vec[1][0]; if (IS_EQT(frame, framenum, BEZT_BINARYSEARCH_THRESH)) { - *replace= 1; + *replace = 1; return (arraylen - 1); } else if (frame > framenum) @@ -400,10 +400,10 @@ int binarysearch_bezt_index(BezTriple array[], float frame, int arraylen, short /* most of the time, this loop is just to find where to put it * 'loopbreaker' is just here to prevent infinite loops */ - for (loopbreaker=0; (start <= end) && (loopbreaker < maxloop); loopbreaker++) { + for (loopbreaker = 0; (start <= end) && (loopbreaker < maxloop); loopbreaker++) { /* compute and get midpoint */ - int mid = start + ((end - start) / 2); /* we calculate the midpoint this way to avoid int overflows... */ - float midfra= array[mid].vec[1][0]; + int mid = start + ((end - start) / 2); /* we calculate the midpoint this way to avoid int overflows... */ + float midfra = array[mid].vec[1][0]; /* check if exactly equal to midpoint */ if (IS_EQT(frame, midfra, BEZT_BINARYSEARCH_THRESH)) { @@ -413,13 +413,13 @@ int binarysearch_bezt_index(BezTriple array[], float frame, int arraylen, short /* repeat in upper/lower half */ if (frame > midfra) - start= mid + 1; + start = mid + 1; else if (frame < midfra) - end= mid - 1; + end = mid - 1; } /* print error if loop-limit exceeded */ - if (loopbreaker == (maxloop-1)) { + if (loopbreaker == (maxloop - 1)) { printf("Error: binarysearch_bezt_index() was taking too long\n"); // include debug info @@ -433,8 +433,8 @@ int binarysearch_bezt_index(BezTriple array[], float frame, int arraylen, short /* ...................................... */ /* 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 do_sel_only) +static void get_fcurve_end_keyframes(FCurve *fcu, BezTriple **first, BezTriple **last, + const short do_sel_only) { /* init outputs */ *first = NULL; @@ -451,18 +451,18 @@ static void get_fcurve_end_keyframes (FCurve *fcu, BezTriple **first, BezTriple /* find first selected */ bezt = fcu->bezt; - for (i=0; i < fcu->totvert; bezt++, i++) { + for (i = 0; i < fcu->totvert; bezt++, i++) { if (BEZSELECTED(bezt)) { - *first= 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++) { + for (i = 0; i < fcu->totvert; bezt--, i++) { if (BEZSELECTED(bezt)) { - *last= bezt; + *last = bezt; break; } } @@ -479,14 +479,14 @@ static void get_fcurve_end_keyframes (FCurve *fcu, BezTriple **first, BezTriple void calc_fcurve_bounds(FCurve *fcu, float *xmin, float *xmax, float *ymin, float *ymax, const short do_sel_only) { - float xminv=999999999.0f, xmaxv=-999999999.0f; - float yminv=999999999.0f, ymaxv=-999999999.0f; - short foundvert= FALSE; + float xminv = 999999999.0f, xmaxv = -999999999.0f; + float yminv = 999999999.0f, ymaxv = -999999999.0f; + short foundvert = FALSE; unsigned int i; if (fcu->totvert) { if (fcu->bezt) { - BezTriple *bezt_first= NULL, *bezt_last= NULL; + BezTriple *bezt_first = NULL, *bezt_last = NULL; if (xmin || xmax) { /* get endpoint keyframes */ @@ -495,8 +495,8 @@ void calc_fcurve_bounds(FCurve *fcu, float *xmin, float *xmax, float *ymin, floa if (bezt_first) { BLI_assert(bezt_last != NULL); - xminv= MIN2(xminv, bezt_first->vec[1][0]); - xmaxv= MAX2(xmaxv, bezt_last->vec[1][0]); + xminv = MIN2(xminv, bezt_first->vec[1][0]); + xmaxv = MAX2(xmaxv, bezt_last->vec[1][0]); } } @@ -504,13 +504,13 @@ void calc_fcurve_bounds(FCurve *fcu, float *xmin, float *xmax, float *ymin, floa if (ymin || ymax) { BezTriple *bezt; - for (bezt=fcu->bezt, i=0; i < fcu->totvert; bezt++, i++) { + for (bezt = fcu->bezt, i = 0; i < fcu->totvert; bezt++, i++) { if ((do_sel_only == 0) || BEZSELECTED(bezt)) { if (bezt->vec[1][1] < yminv) - yminv= bezt->vec[1][1]; + yminv = bezt->vec[1][1]; if (bezt->vec[1][1] > ymaxv) - ymaxv= bezt->vec[1][1]; - foundvert= TRUE; + ymaxv = bezt->vec[1][1]; + foundvert = TRUE; } } } @@ -518,42 +518,42 @@ void calc_fcurve_bounds(FCurve *fcu, float *xmin, float *xmax, float *ymin, floa else if (fcu->fpt) { /* frame range can be directly calculated from end verts */ if (xmin || xmax) { - xminv= MIN2(xminv, fcu->fpt[0].vec[0]); - xmaxv= MAX2(xmaxv, fcu->fpt[fcu->totvert-1].vec[0]); + xminv = MIN2(xminv, fcu->fpt[0].vec[0]); + xmaxv = MAX2(xmaxv, fcu->fpt[fcu->totvert - 1].vec[0]); } /* only loop over keyframes to find extents for values if needed */ if (ymin || ymax) { FPoint *fpt; - for (fpt=fcu->fpt, i=0; i < fcu->totvert; fpt++, i++) { + for (fpt = fcu->fpt, i = 0; i < fcu->totvert; fpt++, i++) { if (fpt->vec[1] < yminv) - yminv= fpt->vec[1]; + yminv = fpt->vec[1]; if (fpt->vec[1] > ymaxv) - ymaxv= fpt->vec[1]; + ymaxv = fpt->vec[1]; - foundvert= TRUE; + foundvert = TRUE; } } } } if (foundvert) { - if (xmin) *xmin= xminv; - if (xmax) *xmax= xmaxv; + if (xmin) *xmin = xminv; + if (xmax) *xmax = xmaxv; - if (ymin) *ymin= yminv; - if (ymax) *ymax= ymaxv; + if (ymin) *ymin = yminv; + if (ymax) *ymax = ymaxv; } else { if (G.debug & G_DEBUG) printf("F-Curve calc bounds didn't find anything, so assuming minimum bounds of 1.0\n"); - if (xmin) *xmin= 0.0f; - if (xmax) *xmax= 1.0f; + if (xmin) *xmin = 0.0f; + if (xmax) *xmax = 1.0f; - if (ymin) *ymin= 0.0f; - if (ymax) *ymax= 1.0f; + if (ymin) *ymin = 0.0f; + if (ymax) *ymax = 1.0f; } } @@ -561,12 +561,12 @@ void calc_fcurve_bounds(FCurve *fcu, float *xmin, float *xmax, float *ymin, floa void calc_fcurve_range(FCurve *fcu, float *start, float *end, const short do_sel_only, const short do_min_length) { - float min=999999999.0f, max=-999999999.0f; - short foundvert= FALSE; + float min = 999999999.0f, max = -999999999.0f; + short foundvert = FALSE; if (fcu->totvert) { if (fcu->bezt) { - BezTriple *bezt_first= NULL, *bezt_last= NULL; + BezTriple *bezt_first = NULL, *bezt_last = NULL; /* get endpoint keyframes */ get_fcurve_end_keyframes(fcu, &bezt_first, &bezt_last, do_sel_only); @@ -574,23 +574,23 @@ void calc_fcurve_range(FCurve *fcu, float *start, float *end, if (bezt_first) { BLI_assert(bezt_last != NULL); - min= MIN2(min, bezt_first->vec[1][0]); - max= MAX2(max, bezt_last->vec[1][0]); + min = MIN2(min, bezt_first->vec[1][0]); + max = MAX2(max, bezt_last->vec[1][0]); - foundvert= TRUE; + foundvert = TRUE; } } else if (fcu->fpt) { - min= MIN2(min, fcu->fpt[0].vec[0]); - max= MAX2(max, fcu->fpt[fcu->totvert-1].vec[0]); + min = MIN2(min, fcu->fpt[0].vec[0]); + max = MAX2(max, fcu->fpt[fcu->totvert - 1].vec[0]); - foundvert= TRUE; + foundvert = TRUE; } } if (foundvert == FALSE) { - min= max= 0.0f; + min = max = 0.0f; } if (do_min_length) { @@ -600,8 +600,8 @@ void calc_fcurve_range(FCurve *fcu, float *start, float *end, } } - *start= min; - *end= max; + *start = min; + *end = max; } /* ----------------- Status Checks -------------------------- */ @@ -628,7 +628,7 @@ short fcurve_are_keyframes_usable(FCurve *fcu) // TODO: optionally, only check modifier if it is the active one... for (fcm = fcu->modifiers.last; fcm; fcm = fcm->prev) { /* ignore if muted/disabled */ - if (fcm->flag & (FMODIFIER_FLAG_DISABLED|FMODIFIER_FLAG_MUTED)) + if (fcm->flag & (FMODIFIER_FLAG_DISABLED | FMODIFIER_FLAG_MUTED)) continue; /* type checks */ @@ -647,7 +647,7 @@ short fcurve_are_keyframes_usable(FCurve *fcu) if ((data->flag & FCM_GENERATOR_ADDITIVE) == 0) return 0; } - break; + break; case FMODIFIER_TYPE_FN_GENERATOR: { FMod_FunctionGenerator *data = (FMod_FunctionGenerator *)fcm->data; @@ -655,7 +655,7 @@ short fcurve_are_keyframes_usable(FCurve *fcu) if ((data->flag & FCM_GENERATOR_ADDITIVE) == 0) return 0; } - break; + break; /* always harmful - cannot allow */ default: @@ -692,10 +692,10 @@ void bezt_add_to_cfra_elem(ListBase *lb, BezTriple *bezt) { CfraElem *ce, *cen; - for (ce= lb->first; ce; ce= ce->next) { + for (ce = lb->first; ce; ce = ce->next) { /* double key? */ if (ce->cfra == bezt->vec[1][0]) { - if (bezt->f2 & SELECT) ce->sel= bezt->f2; + if (bezt->f2 & SELECT) ce->sel = bezt->f2; return; } /* should key be inserted before this column? */ @@ -703,12 +703,12 @@ void bezt_add_to_cfra_elem(ListBase *lb, BezTriple *bezt) } /* create a new column */ - cen= MEM_callocN(sizeof(CfraElem), "add_to_cfra_elem"); + cen = MEM_callocN(sizeof(CfraElem), "add_to_cfra_elem"); if (ce) BLI_insertlinkbefore(lb, ce, cen); else BLI_addtail(lb, cen); - cen->cfra= bezt->vec[1][0]; - cen->sel= bezt->f2; + cen->cfra = bezt->vec[1][0]; + cen->sel = bezt->f2; } /* ***************************** Samples Utilities ******************************* */ @@ -748,12 +748,12 @@ void fcurve_store_samples(FCurve *fcu, void *data, int start, int end, FcuSample } /* set up sample data */ - fpt= new_fpt= MEM_callocN(sizeof(FPoint)*(end-start+1), "FPoint Samples"); + fpt = new_fpt = MEM_callocN(sizeof(FPoint) * (end - start + 1), "FPoint Samples"); /* use the sampling callback at 1-frame intervals from start to end frames */ - for (cfra= start; cfra <= end; cfra++, fpt++) { - fpt->vec[0]= (float)cfra; - fpt->vec[1]= sample_cb(fcu, data, (float)cfra); + for (cfra = start; cfra <= end; cfra++, fpt++) { + fpt->vec[0] = (float)cfra; + fpt->vec[1] = sample_cb(fcu, data, (float)cfra); } /* free any existing sample/keyframe data on curve */ @@ -761,9 +761,9 @@ void fcurve_store_samples(FCurve *fcu, void *data, int start, int end, FcuSample if (fcu->fpt) MEM_freeN(fcu->fpt); /* store the samples */ - fcu->bezt= NULL; - fcu->fpt= new_fpt; - fcu->totvert= end - start + 1; + fcu->bezt = NULL; + fcu->fpt = new_fpt; + fcu->totvert = end - start + 1; } /* ***************************** F-Curve Sanity ********************************* */ @@ -778,7 +778,7 @@ void fcurve_store_samples(FCurve *fcu, void *data, int start, int end, FcuSample void calchandles_fcurve(FCurve *fcu) { BezTriple *bezt, *prev, *next; - int a= fcu->totvert; + int a = fcu->totvert; /* Error checking: * - need at least two points @@ -789,33 +789,33 @@ void calchandles_fcurve(FCurve *fcu) return; /* get initial pointers */ - bezt= fcu->bezt; - prev= NULL; - next= (bezt + 1); + bezt = fcu->bezt; + prev = NULL; + next = (bezt + 1); /* loop over all beztriples, adjusting handles */ while (a--) { /* clamp timing of handles to be on either side of beztriple */ - if (bezt->vec[0][0] > bezt->vec[1][0]) bezt->vec[0][0]= bezt->vec[1][0]; - if (bezt->vec[2][0] < bezt->vec[1][0]) bezt->vec[2][0]= bezt->vec[1][0]; + if (bezt->vec[0][0] > bezt->vec[1][0]) bezt->vec[0][0] = bezt->vec[1][0]; + if (bezt->vec[2][0] < bezt->vec[1][0]) bezt->vec[2][0] = bezt->vec[1][0]; /* calculate auto-handles */ - BKE_nurb_handle_calc(bezt, prev, next, 1); /* 1==special autohandle */ + BKE_nurb_handle_calc(bezt, prev, next, 1); /* 1==special autohandle */ /* for automatic ease in and out */ if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM) && ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM)) { /* only do this on first or last beztriple */ - if ((a == 0) || (a == fcu->totvert-1)) { + if ((a == 0) || (a == fcu->totvert - 1)) { /* set both handles to have same horizontal value as keyframe */ if (fcu->extend == FCURVE_EXTRAPOLATE_CONSTANT) { - bezt->vec[0][1]= bezt->vec[2][1]= bezt->vec[1][1]; + bezt->vec[0][1] = bezt->vec[2][1] = bezt->vec[1][1]; } } } /* advance pointers for next iteration */ - prev= bezt; - if (a == 1) next= NULL; + prev = bezt; + if (a == 1) next = NULL; else next++; bezt++; } @@ -824,8 +824,8 @@ void calchandles_fcurve(FCurve *fcu) /* Use when F-Curve with handles has changed * It treats all BezTriples with the following rules: * - PHASE 1: do types have to be altered? - * -> Auto handles: become aligned when selection status is NOT(000 || 111) - * -> Vector handles: become 'nothing' when (one half selected AND other not) + * -> Auto handles: become aligned when selection status is NOT(000 || 111) + * -> Vector handles: become 'nothing' when (one half selected AND other not) * - PHASE 2: recalculate handles */ void testhandles_fcurve(FCurve *fcu, const short use_handle) @@ -838,41 +838,41 @@ void testhandles_fcurve(FCurve *fcu, const short use_handle) return; /* loop over beztriples */ - for (a=0, bezt=fcu->bezt; a < fcu->totvert; a++, bezt++) { - short flag= 0; + for (a = 0, bezt = fcu->bezt; a < fcu->totvert; a++, bezt++) { + short flag = 0; /* flag is initialized as selection status * of beztriple control-points (labelled 0,1,2) */ - if (bezt->f2 & SELECT) flag |= (1<<1); // == 2 + if (bezt->f2 & SELECT) flag |= (1 << 1); // == 2 if (use_handle == FALSE) { if (flag & 2) { - flag |= (1<<0) | (1<<2); + flag |= (1 << 0) | (1 << 2); } } else { - if (bezt->f1 & SELECT) flag |= (1<<0); // == 1 - if (bezt->f3 & SELECT) flag |= (1<<2); // == 4 + if (bezt->f1 & SELECT) flag |= (1 << 0); // == 1 + if (bezt->f3 & SELECT) flag |= (1 << 2); // == 4 } /* one or two handles selected only */ - if (ELEM(flag, 0, 7)==0) { + if (ELEM(flag, 0, 7) == 0) { /* auto handles become aligned */ if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM)) - bezt->h1= HD_ALIGN; + bezt->h1 = HD_ALIGN; if (ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM)) - bezt->h2= HD_ALIGN; + bezt->h2 = HD_ALIGN; /* vector handles become 'free' when only one half selected */ - if (bezt->h1==HD_VECT) { + if (bezt->h1 == HD_VECT) { /* only left half (1 or 2 or 1+2) */ if (flag < 4) - bezt->h1= 0; + bezt->h1 = 0; } - if (bezt->h2==HD_VECT) { + if (bezt->h2 == HD_VECT) { /* only right half (4 or 2+4) */ if (flag > 3) - bezt->h2= 0; + bezt->h2 = 0; } } } @@ -886,11 +886,11 @@ void testhandles_fcurve(FCurve *fcu, const short use_handle) */ void sort_time_fcurve(FCurve *fcu) { - short ok= 1; + short ok = 1; /* keep adjusting order of beztriples until nothing moves (bubble-sort) */ while (ok) { - ok= 0; + ok = 0; /* currently, will only be needed when there are beztriples */ if (fcu->bezt) { @@ -898,13 +898,13 @@ void sort_time_fcurve(FCurve *fcu) unsigned int a; /* loop over ALL points to adjust position in array and recalculate handles */ - for (a=0, bezt=fcu->bezt; a < fcu->totvert; a++, bezt++) { + for (a = 0, bezt = fcu->bezt; a < fcu->totvert; a++, bezt++) { /* check if thee's a next beztriple which we could try to swap with current */ - if (a < (fcu->totvert-1)) { + if (a < (fcu->totvert - 1)) { /* swap if one is after the other (and indicate that order has changed) */ - if (bezt->vec[1][0] > (bezt+1)->vec[1][0]) { - SWAP(BezTriple, *bezt, *(bezt+1)); - ok= 1; + if (bezt->vec[1][0] > (bezt + 1)->vec[1][0]) { + SWAP(BezTriple, *bezt, *(bezt + 1)); + ok = 1; } /* if either one of both of the points exceeds crosses over the keyframe time... */ @@ -916,9 +916,9 @@ void sort_time_fcurve(FCurve *fcu) else { /* clamp handles */ if (bezt->vec[0][0] > bezt->vec[1][0]) - bezt->vec[0][0]= bezt->vec[1][0]; + bezt->vec[0][0] = bezt->vec[1][0]; if (bezt->vec[2][0] < bezt->vec[1][0]) - bezt->vec[2][0]= bezt->vec[1][0]; + bezt->vec[2][0] = bezt->vec[1][0]; } } } @@ -940,8 +940,8 @@ short test_time_fcurve(FCurve *fcu) BezTriple *bezt; /* loop through all BezTriples, stopping when one exceeds the one after it */ - for (a=0, bezt= fcu->bezt; a < (fcu->totvert - 1); a++, bezt++) { - if (bezt->vec[1][0] > (bezt+1)->vec[1][0]) + for (a = 0, bezt = fcu->bezt; a < (fcu->totvert - 1); a++, bezt++) { + if (bezt->vec[1][0] > (bezt + 1)->vec[1][0]) return 1; } } @@ -949,8 +949,8 @@ short test_time_fcurve(FCurve *fcu) FPoint *fpt; /* loop through all FPoints, stopping when one exceeds the one after it */ - for (a=0, fpt= fcu->fpt; a < (fcu->totvert - 1); a++, fpt++) { - if (fpt->vec[0] > (fpt+1)->vec[0]) + for (a = 0, fpt = fcu->fpt; a < (fcu->totvert - 1); a++, fpt++) { + if (fpt->vec[0] > (fpt + 1)->vec[0]) return 1; } } @@ -969,9 +969,9 @@ typedef struct DriverVarTypeInfo { float (*get_value)(ChannelDriver *driver, DriverVar *dvar); /* allocation of target slots */ - int num_targets; /* number of target slots required */ - const char *target_names[MAX_DRIVER_TARGETS]; /* UI names that should be given to the slots */ - int target_flags[MAX_DRIVER_TARGETS]; /* flags defining the requirements for each slot */ + int num_targets; /* number of target slots required */ + const char *target_names[MAX_DRIVER_TARGETS]; /* UI names that should be given to the slots */ + int target_flags[MAX_DRIVER_TARGETS]; /* flags defining the requirements for each slot */ } DriverVarTypeInfo; /* Macro to begin definitions */ @@ -986,25 +986,25 @@ typedef struct DriverVarTypeInfo { static ID *dtar_id_ensure_proxy_from(ID *id) { - if (id && GS(id->name)==ID_OB && ((Object *)id)->proxy_from) + if (id && GS(id->name) == ID_OB && ((Object *)id)->proxy_from) return (ID *)(((Object *)id)->proxy_from); return id; } /* Helper function to obtain a value using RNA from the specified source (for evaluating drivers) */ -static float dtar_get_prop_val (ChannelDriver *driver, DriverTarget *dtar) +static float dtar_get_prop_val(ChannelDriver *driver, DriverTarget *dtar) { PointerRNA id_ptr, ptr; PropertyRNA *prop; ID *id; int index; - float value= 0.0f; + float value = 0.0f; /* sanity check */ if (ELEM(NULL, driver, dtar)) return 0.0f; - id= dtar_id_ensure_proxy_from(dtar->id); + id = dtar_id_ensure_proxy_from(dtar->id); /* error check for missing pointer... */ // TODO: tag the specific target too as having issues @@ -1024,37 +1024,37 @@ static float dtar_get_prop_val (ChannelDriver *driver, DriverTarget *dtar) /* array */ if (index < RNA_property_array_length(&ptr, prop)) { switch (RNA_property_type(prop)) { + case PROP_BOOLEAN: + value = (float)RNA_property_boolean_get_index(&ptr, prop, index); + break; + case PROP_INT: + value = (float)RNA_property_int_get_index(&ptr, prop, index); + break; + case PROP_FLOAT: + value = RNA_property_float_get_index(&ptr, prop, index); + break; + default: + break; + } + } + } + else { + /* not an array */ + switch (RNA_property_type(prop)) { case PROP_BOOLEAN: - value= (float)RNA_property_boolean_get_index(&ptr, prop, index); + value = (float)RNA_property_boolean_get(&ptr, prop); break; case PROP_INT: - value= (float)RNA_property_int_get_index(&ptr, prop, index); + value = (float)RNA_property_int_get(&ptr, prop); break; case PROP_FLOAT: - value= RNA_property_float_get_index(&ptr, prop, index); + value = RNA_property_float_get(&ptr, prop); + break; + case PROP_ENUM: + value = (float)RNA_property_enum_get(&ptr, prop); break; default: break; - } - } - } - else { - /* not an array */ - switch (RNA_property_type(prop)) { - case PROP_BOOLEAN: - value= (float)RNA_property_boolean_get(&ptr, prop); - break; - case PROP_INT: - value= (float)RNA_property_int_get(&ptr, prop); - break; - case PROP_FLOAT: - value= RNA_property_float_get(&ptr, prop); - break; - case PROP_ENUM: - value= (float)RNA_property_enum_get(&ptr, prop); - break; - default: - break; } } @@ -1071,21 +1071,21 @@ static float dtar_get_prop_val (ChannelDriver *driver, DriverTarget *dtar) } /* Helper function to obtain a pointer to a Pose Channel (for evaluating drivers) */ -static bPoseChannel *dtar_get_pchan_ptr (ChannelDriver *driver, DriverTarget *dtar) +static bPoseChannel *dtar_get_pchan_ptr(ChannelDriver *driver, DriverTarget *dtar) { ID *id; /* sanity check */ if (ELEM(NULL, driver, dtar)) return NULL; - id= dtar_id_ensure_proxy_from(dtar->id); + id = dtar_id_ensure_proxy_from(dtar->id); /* check if the ID here is a valid object */ if (id && GS(id->name)) { - Object *ob= (Object *)id; + Object *ob = (Object *)id; /* get pose, and subsequently, posechannel */ - return get_pose_channel(ob->pose, dtar->pchan_name); + return BKE_pose_channel_find_name(ob->pose, dtar->pchan_name); } else { /* cannot find a posechannel this way */ @@ -1096,21 +1096,21 @@ static bPoseChannel *dtar_get_pchan_ptr (ChannelDriver *driver, DriverTarget *dt /* ......... */ /* evaluate 'single prop' driver variable */ -static float dvar_eval_singleProp (ChannelDriver *driver, DriverVar *dvar) +static float dvar_eval_singleProp(ChannelDriver *driver, DriverVar *dvar) { /* just evaluate the first target slot */ return dtar_get_prop_val(driver, &dvar->targets[0]); } /* evaluate 'rotation difference' driver variable */ -static float dvar_eval_rotDiff (ChannelDriver *driver, DriverVar *dvar) +static float dvar_eval_rotDiff(ChannelDriver *driver, DriverVar *dvar) { bPoseChannel *pchan, *pchan2; float q1[4], q2[4], quat[4], angle; /* get pose channels, and check if we've got two */ - pchan= dtar_get_pchan_ptr(driver, &dvar->targets[0]); - pchan2= dtar_get_pchan_ptr(driver, &dvar->targets[1]); + pchan = dtar_get_pchan_ptr(driver, &dvar->targets[0]); + pchan2 = dtar_get_pchan_ptr(driver, &dvar->targets[1]); if (ELEM(NULL, pchan, pchan2)) { /* disable this driver, since it doesn't work correctly... */ @@ -1135,14 +1135,14 @@ static float dvar_eval_rotDiff (ChannelDriver *driver, DriverVar *dvar) invert_qt(q1); mul_qt_qtqt(quat, q1, q2); angle = 2.0f * (saacos(quat[0])); - angle= ABS(angle); + angle = ABS(angle); return (angle > (float)M_PI) ? (float)((2.0f * (float)M_PI) - angle) : (float)(angle); } /* evaluate 'location difference' driver variable */ // TODO: this needs to take into account space conversions... -static float dvar_eval_locDiff (ChannelDriver *driver, DriverVar *dvar) +static float dvar_eval_locDiff(ChannelDriver *driver, DriverVar *dvar) { float loc1[3] = {0.0f, 0.0f, 0.0f}; float loc2[3] = {0.0f, 0.0f, 0.0f}; @@ -1152,7 +1152,7 @@ static float dvar_eval_locDiff (ChannelDriver *driver, DriverVar *dvar) DRIVER_TARGETS_USED_LOOPER(dvar) { /* get pointer to loc values to store in */ - Object *ob= (Object *)dtar_id_ensure_proxy_from(dtar->id); + Object *ob = (Object *)dtar_id_ensure_proxy_from(dtar->id); bPoseChannel *pchan; float tmp_loc[3]; @@ -1164,7 +1164,7 @@ static float dvar_eval_locDiff (ChannelDriver *driver, DriverVar *dvar) } /* try to get posechannel */ - pchan= get_pose_channel(ob->pose, dtar->pchan_name); + pchan = BKE_pose_channel_find_name(ob->pose, dtar->pchan_name); /* check if object or bone */ if (pchan) { @@ -1234,14 +1234,14 @@ static float dvar_eval_locDiff (ChannelDriver *driver, DriverVar *dvar) } /* evaluate 'transform channel' driver variable */ -static float dvar_eval_transChan (ChannelDriver *driver, DriverVar *dvar) +static float dvar_eval_transChan(ChannelDriver *driver, DriverVar *dvar) { - DriverTarget *dtar= &dvar->targets[0]; - Object *ob= (Object *)dtar_id_ensure_proxy_from(dtar->id); + DriverTarget *dtar = &dvar->targets[0]; + Object *ob = (Object *)dtar_id_ensure_proxy_from(dtar->id); bPoseChannel *pchan; float mat[4][4]; float oldEul[3] = {0.0f, 0.0f, 0.0f}; - short useEulers=0, rotOrder=ROT_MODE_EUL; + short useEulers = 0, rotOrder = ROT_MODE_EUL; /* check if this target has valid data */ if ((ob == NULL) || (GS(ob->id.name) != ID_OB)) { @@ -1251,7 +1251,7 @@ static float dvar_eval_transChan (ChannelDriver *driver, DriverVar *dvar) } /* try to get posechannel */ - pchan= get_pose_channel(ob->pose, dtar->pchan_name); + pchan = BKE_pose_channel_find_name(ob->pose, dtar->pchan_name); /* check if object or bone, and get transform matrix accordingly * - "useEulers" code is used to prevent the problems associated with non-uniqueness @@ -1263,7 +1263,7 @@ static float dvar_eval_transChan (ChannelDriver *driver, DriverVar *dvar) /* bone */ if (pchan->rotmode > 0) { copy_v3_v3(oldEul, pchan->eul); - rotOrder= pchan->rotmode; + rotOrder = pchan->rotmode; useEulers = 1; } @@ -1278,7 +1278,7 @@ static float dvar_eval_transChan (ChannelDriver *driver, DriverVar *dvar) * since it stores delta transform of pose_mat so that deforms work * so it cannot be used here for "transform" space */ - pchan_to_mat4(pchan, mat); + BKE_pchan_to_mat4(pchan, mat); } } else { @@ -1290,7 +1290,7 @@ static float dvar_eval_transChan (ChannelDriver *driver, DriverVar *dvar) /* object */ if (ob->rotmode > 0) { copy_v3_v3(oldEul, ob->rot); - rotOrder= ob->rotmode; + rotOrder = ob->rotmode; useEulers = 1; } @@ -1302,7 +1302,7 @@ static float dvar_eval_transChan (ChannelDriver *driver, DriverVar *dvar) } else { /* transforms to matrix */ - object_to_mat4(ob, mat); + BKE_object_to_mat4(ob, mat); } } else { @@ -1353,36 +1353,36 @@ static float dvar_eval_transChan (ChannelDriver *driver, DriverVar *dvar) /* Table of Driver Varaiable Type Info Data */ static DriverVarTypeInfo dvar_types[MAX_DVAR_TYPES] = { BEGIN_DVAR_TYPEDEF(DVAR_TYPE_SINGLE_PROP) - dvar_eval_singleProp, /* eval callback */ - 1, /* number of targets used */ - {"Property"}, /* UI names for targets */ - {0} /* flags */ + dvar_eval_singleProp, /* eval callback */ + 1, /* number of targets used */ + {"Property"}, /* UI names for targets */ + {0} /* flags */ END_DVAR_TYPEDEF, BEGIN_DVAR_TYPEDEF(DVAR_TYPE_ROT_DIFF) - dvar_eval_rotDiff, /* eval callback */ - 2, /* number of targets used */ - {"Bone 1", "Bone 2"}, /* UI names for targets */ - {DTAR_FLAG_STRUCT_REF|DTAR_FLAG_ID_OB_ONLY, DTAR_FLAG_STRUCT_REF|DTAR_FLAG_ID_OB_ONLY} /* flags */ + dvar_eval_rotDiff, /* eval callback */ + 2, /* number of targets used */ + {"Bone 1", "Bone 2"}, /* UI names for targets */ + {DTAR_FLAG_STRUCT_REF | DTAR_FLAG_ID_OB_ONLY, DTAR_FLAG_STRUCT_REF | DTAR_FLAG_ID_OB_ONLY} /* flags */ END_DVAR_TYPEDEF, BEGIN_DVAR_TYPEDEF(DVAR_TYPE_LOC_DIFF) - dvar_eval_locDiff, /* eval callback */ - 2, /* number of targets used */ - {"Object/Bone 1", "Object/Bone 2"}, /* UI names for targets */ - {DTAR_FLAG_STRUCT_REF|DTAR_FLAG_ID_OB_ONLY, DTAR_FLAG_STRUCT_REF|DTAR_FLAG_ID_OB_ONLY} /* flags */ + dvar_eval_locDiff, /* eval callback */ + 2, /* number of targets used */ + {"Object/Bone 1", "Object/Bone 2"}, /* UI names for targets */ + {DTAR_FLAG_STRUCT_REF | DTAR_FLAG_ID_OB_ONLY, DTAR_FLAG_STRUCT_REF | DTAR_FLAG_ID_OB_ONLY} /* flags */ END_DVAR_TYPEDEF, BEGIN_DVAR_TYPEDEF(DVAR_TYPE_TRANSFORM_CHAN) - dvar_eval_transChan, /* eval callback */ - 1, /* number of targets used */ - {"Object/Bone"}, /* UI names for targets */ - {DTAR_FLAG_STRUCT_REF|DTAR_FLAG_ID_OB_ONLY} /* flags */ + dvar_eval_transChan, /* eval callback */ + 1, /* number of targets used */ + {"Object/Bone"}, /* UI names for targets */ + {DTAR_FLAG_STRUCT_REF | DTAR_FLAG_ID_OB_ONLY} /* flags */ END_DVAR_TYPEDEF, }; /* Get driver variable typeinfo */ -static DriverVarTypeInfo *get_dvar_typeinfo (int type) +static DriverVarTypeInfo *get_dvar_typeinfo(int type) { /* check if valid type */ if ((type >= 0) && (type < MAX_DVAR_TYPES)) @@ -1403,7 +1403,7 @@ void driver_free_variable(ChannelDriver *driver, DriverVar *dvar) /* free target vars * - need to go over all of them, not just up to the ones that are used * currently, since there may be some lingering RNA paths from - * previous users needing freeing + * previous users needing freeing */ DRIVER_TARGETS_LOOPER(dvar) { @@ -1418,7 +1418,7 @@ void driver_free_variable(ChannelDriver *driver, DriverVar *dvar) #ifdef WITH_PYTHON /* since driver variables are cached, the expression needs re-compiling too */ - if (driver->type==DRIVER_TYPE_PYTHON) + if (driver->type == DRIVER_TYPE_PYTHON) driver->flag |= DRIVER_FLAG_RENAMEVAR; #endif } @@ -1426,15 +1426,15 @@ void driver_free_variable(ChannelDriver *driver, DriverVar *dvar) /* Change the type of driver variable */ void driver_change_variable_type(DriverVar *dvar, int type) { - DriverVarTypeInfo *dvti= get_dvar_typeinfo(type); + DriverVarTypeInfo *dvti = get_dvar_typeinfo(type); /* sanity check */ if (ELEM(NULL, dvar, dvti)) return; /* set the new settings */ - dvar->type= type; - dvar->num_targets= dvti->num_targets; + dvar->type = type; + dvar->num_targets = dvti->num_targets; /* make changes to the targets based on the defines for these types * NOTE: only need to make sure the ones we're using here are valid... @@ -1448,13 +1448,13 @@ void driver_change_variable_type(DriverVar *dvar, int type) /* object ID types only, or idtype not yet initialized*/ if ((flags & DTAR_FLAG_ID_OB_ONLY) || (dtar->idtype == 0)) - dtar->idtype= ID_OB; + dtar->idtype = ID_OB; } DRIVER_TARGETS_LOOPER_END } /* Add a new driver variable */ -DriverVar *driver_add_new_variable (ChannelDriver *driver) +DriverVar *driver_add_new_variable(ChannelDriver *driver) { DriverVar *dvar; @@ -1463,7 +1463,7 @@ DriverVar *driver_add_new_variable (ChannelDriver *driver) return NULL; /* make a new variable */ - dvar= MEM_callocN(sizeof(DriverVar), "DriverVar"); + dvar = MEM_callocN(sizeof(DriverVar), "DriverVar"); BLI_addtail(&driver->variables, dvar); /* give the variable a 'unique' name */ @@ -1475,7 +1475,7 @@ DriverVar *driver_add_new_variable (ChannelDriver *driver) #ifdef WITH_PYTHON /* since driver variables are cached, the expression needs re-compiling too */ - if (driver->type==DRIVER_TYPE_PYTHON) + if (driver->type == DRIVER_TYPE_PYTHON) driver->flag |= DRIVER_FLAG_RENAMEVAR; #endif @@ -1492,11 +1492,11 @@ void fcurve_free_driver(FCurve *fcu) /* sanity checks */ if (ELEM(NULL, fcu, fcu->driver)) return; - driver= fcu->driver; + driver = fcu->driver; /* free driver targets */ - for (dvar= driver->variables.first; dvar; dvar= dvarn) { - dvarn= dvar->next; + for (dvar = driver->variables.first; dvar; dvar = dvarn) { + dvarn = dvar->next; driver_free_variable(driver, dvar); } @@ -1508,11 +1508,11 @@ void fcurve_free_driver(FCurve *fcu) /* free driver itself, then set F-Curve's point to this to NULL (as the curve may still be used) */ MEM_freeN(driver); - fcu->driver= NULL; + fcu->driver = NULL; } /* This makes a copy of the given driver */ -ChannelDriver *fcurve_copy_driver (ChannelDriver *driver) +ChannelDriver *fcurve_copy_driver(ChannelDriver *driver) { ChannelDriver *ndriver; DriverVar *dvar; @@ -1522,14 +1522,14 @@ ChannelDriver *fcurve_copy_driver (ChannelDriver *driver) return NULL; /* copy all data */ - ndriver= MEM_dupallocN(driver); - ndriver->expr_comp= NULL; + ndriver = MEM_dupallocN(driver); + ndriver->expr_comp = NULL; /* copy variables */ - ndriver->variables.first= ndriver->variables.last= NULL; + ndriver->variables.first = ndriver->variables.last = NULL; BLI_duplicatelist(&ndriver->variables, &driver->variables); - for (dvar= ndriver->variables.first; dvar; dvar= dvar->next) { + for (dvar = ndriver->variables.first; dvar; dvar = dvar->next) { /* need to go over all targets so that we don't leave any dangling paths */ DRIVER_TARGETS_LOOPER(dvar) { @@ -1559,21 +1559,21 @@ float driver_get_variable_value(ChannelDriver *driver, DriverVar *dvar) * using the variable type info, storing the obtained value * in dvar->curval so that drivers can be debugged */ - dvti= get_dvar_typeinfo(dvar->type); + dvti = get_dvar_typeinfo(dvar->type); if (dvti && dvti->get_value) - dvar->curval= dvti->get_value(driver, dvar); + dvar->curval = dvti->get_value(driver, dvar); else - dvar->curval= 0.0f; + dvar->curval = 0.0f; return dvar->curval; } /* Evaluate an Channel-Driver to get a 'time' value to use instead of "evaltime" * - "evaltime" is the frame at which F-Curve is being evaluated - * - has to return a float value + * - has to return a float value */ -static float evaluate_driver (ChannelDriver *driver, const float evaltime) +static float evaluate_driver(ChannelDriver *driver, const float evaltime) { DriverVar *dvar; @@ -1588,8 +1588,8 @@ static float evaluate_driver (ChannelDriver *driver, const float evaltime) /* check how many variables there are first (i.e. just one?) */ if (driver->variables.first == driver->variables.last) { /* just one target, so just use that */ - dvar= driver->variables.first; - driver->curval= driver_get_variable_value(driver, dvar); + dvar = driver->variables.first; + driver->curval = driver_get_variable_value(driver, dvar); } else { /* more than one target, so average the values of the targets */ @@ -1597,19 +1597,19 @@ static float evaluate_driver (ChannelDriver *driver, const float evaltime) int tot = 0; /* loop through targets, adding (hopefully we don't get any overflow!) */ - for (dvar= driver->variables.first; dvar; dvar=dvar->next) { + for (dvar = driver->variables.first; dvar; dvar = dvar->next) { value += driver_get_variable_value(driver, dvar); tot++; } /* perform operations on the total if appropriate */ if (driver->type == DRIVER_TYPE_AVERAGE) - driver->curval= (value / (float)tot); + driver->curval = (value / (float)tot); else - driver->curval= value; + driver->curval = value; } } - break; + break; case DRIVER_TYPE_MIN: /* smallest value */ case DRIVER_TYPE_MAX: /* largest value */ @@ -1617,9 +1617,9 @@ static float evaluate_driver (ChannelDriver *driver, const float evaltime) float value = 0.0f; /* loop through the variables, getting the values and comparing them to existing ones */ - for (dvar= driver->variables.first; dvar; dvar= dvar->next) { + for (dvar = driver->variables.first; dvar; dvar = dvar->next) { /* get value */ - float tmp_val= driver_get_variable_value(driver, dvar); + float tmp_val = driver_get_variable_value(driver, dvar); /* store this value if appropriate */ if (dvar->prev) { @@ -1627,51 +1627,51 @@ static float evaluate_driver (ChannelDriver *driver, const float evaltime) if (driver->type == DRIVER_TYPE_MAX) { /* max? */ if (tmp_val > value) - value= tmp_val; + value = tmp_val; } else { /* min? */ if (tmp_val < value) - value= tmp_val; + value = tmp_val; } } else { /* first item - make this the baseline for comparisons */ - value= tmp_val; + value = tmp_val; } } /* store value in driver */ - driver->curval= value; + driver->curval = value; } - break; + break; case DRIVER_TYPE_PYTHON: /* expression */ { #ifdef WITH_PYTHON /* check for empty or invalid expression */ if ( (driver->expression[0] == '\0') || - (driver->flag & DRIVER_FLAG_INVALID) ) + (driver->flag & DRIVER_FLAG_INVALID) ) { - driver->curval= 0.0f; + driver->curval = 0.0f; } else { /* this evaluates the expression using Python, and returns its result: - * - on errors it reports, then returns 0.0f + * - on errors it reports, then returns 0.0f */ - driver->curval= BPY_driver_exec(driver, evaltime); + driver->curval = BPY_driver_exec(driver, evaltime); } #else /* WITH_PYTHON*/ - (void)evaltime; + (void)evaltime; #endif /* WITH_PYTHON*/ } - break; + break; default: { /* special 'hack' - just use stored value * This is currently used as the mechanism which allows animated settings to be able - * to be changed via the UI. + * to be changed via the UI. */ } } @@ -1691,127 +1691,127 @@ void correct_bezpart(float v1[2], float v2[2], float v3[2], float v4[2]) float h1[2], h2[2], len1, len2, len, fac; /* calculate handle deltas */ - h1[0]= v1[0] - v2[0]; - h1[1]= v1[1] - v2[1]; + h1[0] = v1[0] - v2[0]; + h1[1] = v1[1] - v2[1]; - h2[0]= v4[0] - v3[0]; - h2[1]= v4[1] - v3[1]; + h2[0] = v4[0] - v3[0]; + h2[1] = v4[1] - v3[1]; /* calculate distances: - * - len = span of time between keyframes + * - len = span of time between keyframes * - len1 = length of handle of start key - * - len2 = length of handle of end key + * - len2 = length of handle of end key */ - len= v4[0]- v1[0]; - len1= fabsf(h1[0]); - len2= fabsf(h2[0]); + len = v4[0] - v1[0]; + len1 = fabsf(h1[0]); + len2 = fabsf(h2[0]); /* if the handles have no length, no need to do any corrections */ - if ((len1+len2) == 0.0f) + if ((len1 + len2) == 0.0f) return; /* the two handles cross over each other, so force them * apart using the proportion they overlap */ - if ((len1+len2) > len) { - fac= len / (len1+len2); + if ((len1 + len2) > len) { + fac = len / (len1 + len2); - v2[0]= (v1[0] - fac*h1[0]); - v2[1]= (v1[1] - fac*h1[1]); + v2[0] = (v1[0] - fac * h1[0]); + v2[1] = (v1[1] - fac * h1[1]); - v3[0]= (v4[0] - fac*h2[0]); - v3[1]= (v4[1] - fac*h2[1]); + v3[0] = (v4[0] - fac * h2[0]); + v3[1] = (v4[1] - fac * h2[1]); } } /* find root ('zero') */ -static int findzero (float x, float q0, float q1, float q2, float q3, float *o) +static int findzero(float x, float q0, float q1, float q2, float q3, float *o) { double c0, c1, c2, c3, a, b, c, p, q, d, t, phi; - int nr= 0; + int nr = 0; - c0= q0 - x; - c1= 3.0f * (q1 - q0); - c2= 3.0f * (q0 - 2.0f*q1 + q2); - c3= q3 - q0 + 3.0f * (q1 - q2); + c0 = q0 - x; + 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; - b= c1/c3; - c= c0/c3; - a= a/3; - - p= b/3 - a*a; - q= (2*a*a*a - a*b + c) / 2; - d= q*q + p*p*p; + a = c2 / c3; + b = c1 / c3; + c = c0 / c3; + a = a / 3; + + p = b / 3 - a * a; + q = (2 * a * a * a - a * b + c) / 2; + d = q * q + p * p * p; if (d > 0.0) { - t= sqrt(d); - o[0]= (float)(sqrt3d(-q+t) + sqrt3d(-q-t) - a); + t = sqrt(d); + o[0] = (float)(sqrt3d(-q + t) + sqrt3d(-q - t) - a); 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); + t = sqrt3d(-q); + o[0] = (float)(2 * t - a); if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) nr++; - o[nr]= (float)(-t-a); + o[nr] = (float)(-t - a); - if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) return nr+1; + if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) return nr + 1; else return nr; } else { - phi= acos(-q / sqrt(-(p*p*p))); - t= sqrt(-p); - p= cos(phi/3); - q= sqrt(3 - 3*p*p); - o[0]= (float)(2*t*p - a); + phi = acos(-q / sqrt(-(p * p * p))); + t = sqrt(-p); + p = cos(phi / 3); + q = sqrt(3 - 3 * p * p); + o[0] = (float)(2 * t * p - a); if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) nr++; - o[nr]= (float)(-t * (p + q) - a); + o[nr] = (float)(-t * (p + q) - a); if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) nr++; - o[nr]= (float)(-t * (p - q) - a); + o[nr] = (float)(-t * (p - q) - a); - if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) return nr+1; + if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) return nr + 1; else return nr; } } else { - a=c2; - b=c1; - c=c0; + a = c2; + b = c1; + c = c0; if (a != 0.0) { // discriminant - p= b*b - 4*a*c; + p = b * b - 4 * a * c; if (p > 0) { - p= sqrt(p); - o[0]= (float)((-b-p) / (2 * a)); + p = sqrt(p); + o[0] = (float)((-b - p) / (2 * a)); if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) nr++; - o[nr]= (float)((-b+p)/(2*a)); + o[nr] = (float)((-b + p) / (2 * a)); - if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) 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)); + o[0] = (float)(-b / (2 * a)); if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) return 1; else return 0; } } else if (b != 0.0) { - o[0]= (float)(-c/b); + o[0] = (float)(-c / b); if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) return 1; else return 0; } else if (c == 0.0) { - o[0]= 0.0; + o[0] = 0.0; return 1; } @@ -1819,36 +1819,36 @@ static int findzero (float x, float q0, float q1, float q2, float q3, float *o) } } -static void berekeny (float f1, float f2, float f3, float f4, float *o, int b) +static void berekeny(float f1, float f2, float f3, float f4, float *o, int b) { float t, c0, c1, c2, c3; int a; - c0= f1; - c1= 3.0f * (f2 - f1); - c2= 3.0f * (f1 - 2.0f*f2 + f3); - c3= f4 - f1 + 3.0f * (f2 - f3); - - for (a=0; a < b; a++) { - t= o[a]; - o[a]= c0 + t*c1 + t*t*c2 + t*t*t*c3; + c0 = f1; + c1 = 3.0f * (f2 - f1); + c2 = 3.0f * (f1 - 2.0f * f2 + f3); + c3 = f4 - f1 + 3.0f * (f2 - f3); + + for (a = 0; a < b; a++) { + t = o[a]; + o[a] = c0 + t * c1 + t * t * c2 + t * t * t * c3; } } #if 0 -static void berekenx (float *f, float *o, int b) +static void berekenx(float *f, float *o, int b) { float t, c0, c1, c2, c3; int a; - c0= f[0]; - c1= 3.0f * (f[3] - f[0]); - c2= 3.0f * (f[0] - 2.0f*f[3] + f[6]); - c3= f[9] - f[0] + 3.0f * (f[3] - f[6]); - - for (a=0; a < b; a++) { - t= o[a]; - o[a]= c0 + t*c1 + t*t*c2 + t*t*t*c3; + c0 = f[0]; + c1 = 3.0f * (f[3] - f[0]); + c2 = 3.0f * (f[0] - 2.0f * f[3] + f[6]); + c3 = f[9] - f[0] + 3.0f * (f[3] - f[6]); + + for (a = 0; a < b; a++) { + t = o[a]; + o[a] = c0 + t * c1 + t * t * c2 + t * t * t * c3; } } #endif @@ -1857,7 +1857,7 @@ static void berekenx (float *f, float *o, int b) /* -------------------------- */ /* Calculate F-Curve value for 'evaltime' using BezTriple keyframes */ -static float fcurve_eval_keyframes (FCurve *fcu, BezTriple *bezts, float evaltime) +static float fcurve_eval_keyframes(FCurve *fcu, BezTriple *bezts, float evaltime) { BezTriple *bezt, *prevbezt, *lastbezt; float v1[2], v2[2], v3[2], v4[2], opl[32], dx, fac; @@ -1866,37 +1866,37 @@ static float fcurve_eval_keyframes (FCurve *fcu, BezTriple *bezts, float evaltim float cvalue = 0.0f; /* get pointers */ - a= fcu->totvert-1; - prevbezt= bezts; - bezt= prevbezt+1; - lastbezt= prevbezt + a; + a = fcu->totvert - 1; + prevbezt = bezts; + bezt = prevbezt + 1; + lastbezt = prevbezt + a; /* evaluation time at or past endpoints? */ if (prevbezt->vec[1][0] >= evaltime) { /* before or on first keyframe */ if ( (fcu->extend == FCURVE_EXTRAPOLATE_LINEAR) && (prevbezt->ipo != BEZT_IPO_CONST) && - !(fcu->flag & FCURVE_DISCRETE_VALUES) ) + !(fcu->flag & FCURVE_DISCRETE_VALUES) ) { /* linear or bezier interpolation */ - if (prevbezt->ipo==BEZT_IPO_LIN) { + if (prevbezt->ipo == BEZT_IPO_LIN) { /* Use the next center point instead of our own handle for * linear interpolated extrapolate */ if (fcu->totvert == 1) { - cvalue= prevbezt->vec[1][1]; + cvalue = prevbezt->vec[1][1]; } else { - bezt = prevbezt+1; - dx= prevbezt->vec[1][0] - evaltime; - fac= bezt->vec[1][0] - prevbezt->vec[1][0]; + bezt = prevbezt + 1; + dx = prevbezt->vec[1][0] - evaltime; + fac = bezt->vec[1][0] - prevbezt->vec[1][0]; /* prevent division by zero */ if (fac) { - fac= (bezt->vec[1][1] - prevbezt->vec[1][1]) / fac; - cvalue= prevbezt->vec[1][1] - (fac * dx); + fac = (bezt->vec[1][1] - prevbezt->vec[1][1]) / fac; + cvalue = prevbezt->vec[1][1] - (fac * dx); } else { - cvalue= prevbezt->vec[1][1]; + cvalue = prevbezt->vec[1][1]; } } } @@ -1904,16 +1904,16 @@ static float fcurve_eval_keyframes (FCurve *fcu, BezTriple *bezts, float evaltim /* Use the first handle (earlier) of first BezTriple to calculate the * gradient and thus the value of the curve at evaltime */ - dx= prevbezt->vec[1][0] - evaltime; - fac= prevbezt->vec[1][0] - prevbezt->vec[0][0]; + dx = prevbezt->vec[1][0] - evaltime; + fac = prevbezt->vec[1][0] - prevbezt->vec[0][0]; /* prevent division by zero */ if (fac) { - fac= (prevbezt->vec[1][1] - prevbezt->vec[0][1]) / fac; - cvalue= prevbezt->vec[1][1] - (fac * dx); + fac = (prevbezt->vec[1][1] - prevbezt->vec[0][1]) / fac; + cvalue = prevbezt->vec[1][1] - (fac * dx); } else { - cvalue= prevbezt->vec[1][1]; + cvalue = prevbezt->vec[1][1]; } } } @@ -1921,34 +1921,34 @@ static float fcurve_eval_keyframes (FCurve *fcu, BezTriple *bezts, float evaltim /* constant (BEZT_IPO_HORIZ) extrapolation or constant interpolation, * so just extend first keyframe's value */ - cvalue= prevbezt->vec[1][1]; + cvalue = prevbezt->vec[1][1]; } } else if (lastbezt->vec[1][0] <= evaltime) { /* after or on last keyframe */ if ( (fcu->extend == FCURVE_EXTRAPOLATE_LINEAR) && (lastbezt->ipo != BEZT_IPO_CONST) && - !(fcu->flag & FCURVE_DISCRETE_VALUES) ) + !(fcu->flag & FCURVE_DISCRETE_VALUES) ) { /* linear or bezier interpolation */ - if (lastbezt->ipo==BEZT_IPO_LIN) { + if (lastbezt->ipo == BEZT_IPO_LIN) { /* Use the next center point instead of our own handle for * linear interpolated extrapolate */ if (fcu->totvert == 1) { - cvalue= lastbezt->vec[1][1]; + cvalue = lastbezt->vec[1][1]; } else { prevbezt = lastbezt - 1; - dx= evaltime - lastbezt->vec[1][0]; - fac= lastbezt->vec[1][0] - prevbezt->vec[1][0]; + dx = evaltime - lastbezt->vec[1][0]; + fac = lastbezt->vec[1][0] - prevbezt->vec[1][0]; /* prevent division by zero */ if (fac) { - fac= (lastbezt->vec[1][1] - prevbezt->vec[1][1]) / fac; - cvalue= lastbezt->vec[1][1] + (fac * dx); + fac = (lastbezt->vec[1][1] - prevbezt->vec[1][1]) / fac; + cvalue = lastbezt->vec[1][1] + (fac * dx); } else { - cvalue= lastbezt->vec[1][1]; + cvalue = lastbezt->vec[1][1]; } } } @@ -1956,16 +1956,16 @@ static float fcurve_eval_keyframes (FCurve *fcu, BezTriple *bezts, float evaltim /* Use the gradient of the second handle (later) of last BezTriple to calculate the * gradient and thus the value of the curve at evaltime */ - dx= evaltime - lastbezt->vec[1][0]; - fac= lastbezt->vec[2][0] - lastbezt->vec[1][0]; + dx = evaltime - lastbezt->vec[1][0]; + fac = lastbezt->vec[2][0] - lastbezt->vec[1][0]; /* prevent division by zero */ if (fac) { - fac= (lastbezt->vec[2][1] - lastbezt->vec[1][1]) / fac; - cvalue= lastbezt->vec[1][1] + (fac * dx); + fac = (lastbezt->vec[2][1] - lastbezt->vec[1][1]) / fac; + cvalue = lastbezt->vec[1][1] + (fac * dx); } else { - cvalue= lastbezt->vec[1][1]; + cvalue = lastbezt->vec[1][1]; } } } @@ -1973,57 +1973,57 @@ static float fcurve_eval_keyframes (FCurve *fcu, BezTriple *bezts, float evaltim /* constant (BEZT_IPO_HORIZ) extrapolation or constant interpolation, * so just extend last keyframe's value */ - cvalue= lastbezt->vec[1][1]; + cvalue = lastbezt->vec[1][1]; } } else { /* evaltime occurs somewhere in the middle of the curve */ - for (a=0; prevbezt && bezt && (a < fcu->totvert-1); a++, prevbezt=bezt, bezt++) { + for (a = 0; prevbezt && bezt && (a < fcu->totvert - 1); a++, prevbezt = bezt, bezt++) { /* use if the key is directly on the frame, rare cases this is needed else we get 0.0 instead. */ if (fabsf(bezt->vec[1][0] - evaltime) < SMALL_NUMBER) { - cvalue= bezt->vec[1][1]; + cvalue = bezt->vec[1][1]; } /* evaltime occurs within the interval defined by these two keyframes */ else if ((prevbezt->vec[1][0] <= evaltime) && (bezt->vec[1][0] >= evaltime)) { /* value depends on interpolation mode */ if ((prevbezt->ipo == BEZT_IPO_CONST) || (fcu->flag & FCURVE_DISCRETE_VALUES)) { /* constant (evaltime not relevant, so no interpolation needed) */ - cvalue= prevbezt->vec[1][1]; + cvalue = prevbezt->vec[1][1]; } else if (prevbezt->ipo == BEZT_IPO_LIN) { /* linear - interpolate between values of the two keyframes */ - fac= bezt->vec[1][0] - prevbezt->vec[1][0]; + fac = bezt->vec[1][0] - prevbezt->vec[1][0]; /* prevent division by zero */ if (fac) { - fac= (evaltime - prevbezt->vec[1][0]) / fac; - cvalue= prevbezt->vec[1][1] + (fac * (bezt->vec[1][1] - prevbezt->vec[1][1])); + fac = (evaltime - prevbezt->vec[1][0]) / fac; + cvalue = prevbezt->vec[1][1] + (fac * (bezt->vec[1][1] - prevbezt->vec[1][1])); } else { - cvalue= prevbezt->vec[1][1]; + cvalue = prevbezt->vec[1][1]; } } else { /* bezier interpolation */ - /* v1,v2 are the first keyframe and its 2nd handle */ - v1[0]= prevbezt->vec[1][0]; - v1[1]= prevbezt->vec[1][1]; - v2[0]= prevbezt->vec[2][0]; - v2[1]= prevbezt->vec[2][1]; - /* v3,v4 are the last keyframe's 1st handle + the last keyframe */ - v3[0]= bezt->vec[0][0]; - v3[1]= bezt->vec[0][1]; - v4[0]= bezt->vec[1][0]; - v4[1]= bezt->vec[1][1]; + /* v1,v2 are the first keyframe and its 2nd handle */ + v1[0] = prevbezt->vec[1][0]; + v1[1] = prevbezt->vec[1][1]; + v2[0] = prevbezt->vec[2][0]; + v2[1] = prevbezt->vec[2][1]; + /* v3,v4 are the last keyframe's 1st handle + the last keyframe */ + v3[0] = bezt->vec[0][0]; + v3[1] = bezt->vec[0][1]; + v4[0] = bezt->vec[1][0]; + v4[1] = bezt->vec[1][1]; /* adjust handles so that they don't overlap (forming a loop) */ correct_bezpart(v1, v2, v3, v4); /* try to get a value for this position - if failure, try another set of points */ - b= findzero(evaltime, v1[0], v2[0], v3[0], v4[0], opl); + b = findzero(evaltime, v1[0], v2[0], v3[0], v4[0], opl); if (b) { berekeny(v1[1], v2[1], v3[1], v4[1], opl, 1); - cvalue= opl[0]; + cvalue = opl[0]; break; } } @@ -2036,35 +2036,35 @@ static float fcurve_eval_keyframes (FCurve *fcu, BezTriple *bezts, float evaltim } /* Calculate F-Curve value for 'evaltime' using FPoint samples */ -static float fcurve_eval_samples (FCurve *fcu, FPoint *fpts, float evaltime) +static float fcurve_eval_samples(FCurve *fcu, FPoint *fpts, float evaltime) { FPoint *prevfpt, *lastfpt, *fpt; - float cvalue= 0.0f; + float cvalue = 0.0f; /* get pointers */ - prevfpt= fpts; - lastfpt= prevfpt + fcu->totvert-1; + prevfpt = fpts; + lastfpt = prevfpt + fcu->totvert - 1; /* evaluation time at or past endpoints? */ if (prevfpt->vec[0] >= evaltime) { /* before or on first sample, so just extend value */ - cvalue= prevfpt->vec[1]; + cvalue = prevfpt->vec[1]; } else if (lastfpt->vec[0] <= evaltime) { /* after or on last sample, so just extend value */ - cvalue= lastfpt->vec[1]; + cvalue = lastfpt->vec[1]; } else { - float t= (float)abs(evaltime - (int)evaltime); + float t = (float)abs(evaltime - (int)evaltime); /* find the one on the right frame (assume that these are spaced on 1-frame intervals) */ - fpt= prevfpt + (int)(evaltime - prevfpt->vec[0]); + fpt = prevfpt + (int)(evaltime - prevfpt->vec[0]); /* if not exactly on the frame, perform linear interpolation with the next one */ if (t != 0.0f) - cvalue= interpf(fpt->vec[1], (fpt+1)->vec[1], t); + cvalue = interpf(fpt->vec[1], (fpt + 1)->vec[1], t); else - cvalue= fpt->vec[1]; + cvalue = fpt->vec[1]; } /* return value */ @@ -2078,7 +2078,7 @@ static float fcurve_eval_samples (FCurve *fcu, FPoint *fpts, float evaltime) */ float evaluate_fcurve(FCurve *fcu, float evaltime) { - float cvalue= 0.0f; + float cvalue = 0.0f; float devaltime; /* if there is a driver (only if this F-Curve is acting as 'driver'), evaluate it to find value to use as "evaltime" @@ -2087,20 +2087,20 @@ float evaluate_fcurve(FCurve *fcu, float evaltime) */ if (fcu->driver) { /* evaltime now serves as input for the curve */ - evaltime= cvalue= evaluate_driver(fcu->driver, evaltime); + evaltime = cvalue = evaluate_driver(fcu->driver, evaltime); } /* evaluate modifiers which modify time to evaluate the base curve at */ - devaltime= evaluate_time_fmodifiers(&fcu->modifiers, fcu, cvalue, evaltime); + devaltime = evaluate_time_fmodifiers(&fcu->modifiers, fcu, cvalue, evaltime); /* evaluate curve-data * - 'devaltime' instead of 'evaltime', as this is the time that the last time-modifying * F-Curve modifier on the stack requested the curve to be evaluated at */ if (fcu->bezt) - cvalue= fcurve_eval_keyframes(fcu, fcu->bezt, devaltime); + cvalue = fcurve_eval_keyframes(fcu, fcu->bezt, devaltime); else if (fcu->fpt) - cvalue= fcurve_eval_samples(fcu, fcu->fpt, devaltime); + cvalue = fcurve_eval_samples(fcu, fcu->fpt, devaltime); /* evaluate modifiers */ evaluate_value_fmodifiers(&fcu->modifiers, fcu, &cvalue, evaltime); @@ -2109,7 +2109,7 @@ float evaluate_fcurve(FCurve *fcu, float evaltime) * here so that the curve can be sampled correctly */ if (fcu->flag & FCURVE_INT_VALUES) - cvalue= floorf(cvalue + 0.5f); + cvalue = floorf(cvalue + 0.5f); /* return evaluated value */ return cvalue; @@ -2125,7 +2125,7 @@ void calculate_fcurve(FCurve *fcu, float ctime) list_has_suitable_fmodifier(&fcu->modifiers, 0, FMI_TYPE_GENERATE_CURVE)) { /* calculate and set curval (evaluates driver too if necessary) */ - fcu->curval= evaluate_fcurve(fcu, ctime); + fcu->curval = evaluate_fcurve(fcu, ctime); } } diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c index 92c73b23239..59c8a529d85 100644 --- a/source/blender/blenkernel/intern/fmodifier.c +++ b/source/blender/blenkernel/intern/fmodifier.c @@ -68,14 +68,14 @@ */ /* Template for type-info data: - * - make a copy of this when creating new modifiers, and just change the functions - * pointed to as necessary - * - although the naming of functions doesn't matter, it would help for code - * readability, to follow the same naming convention as is presented here - * - any functions that a constraint doesn't need to define, don't define - * for such cases, just use NULL - * - these should be defined after all the functions have been defined, so that - * forward-definitions/prototypes don't need to be used! + * - make a copy of this when creating new modifiers, and just change the functions + * pointed to as necessary + * - although the naming of functions doesn't matter, it would help for code + * readability, to follow the same naming convention as is presented here + * - any functions that a constraint doesn't need to define, don't define + * for such cases, just use NULL + * - these should be defined after all the functions have been defined, so that + * forward-definitions/prototypes don't need to be used! * - keep this copy #if-def'd so that future constraints can get based off this */ #if 0 @@ -99,74 +99,74 @@ static FModifierTypeInfo FMI_MODNAME = { /* Generator F-Curve Modifier --------------------------- */ /* Generators available: - * 1) simple polynomial generator: + * 1) simple polynomial generator: * - Exanded form - (y = C[0]*(x^(n)) + C[1]*(x^(n-1)) + ... + C[n]) * - Factorized form - (y = (C[0][0]*x + C[0][1]) * (C[1][0]*x + C[1][1]) * ... * (C[n][0]*x + C[n][1])) */ -static void fcm_generator_free (FModifier *fcm) +static void fcm_generator_free(FModifier *fcm) { - FMod_Generator *data= (FMod_Generator *)fcm->data; + FMod_Generator *data = (FMod_Generator *)fcm->data; /* free polynomial coefficients array */ if (data->coefficients) MEM_freeN(data->coefficients); } -static void fcm_generator_copy (FModifier *fcm, FModifier *src) +static void fcm_generator_copy(FModifier *fcm, FModifier *src) { - FMod_Generator *gen= (FMod_Generator *)fcm->data; - FMod_Generator *ogen= (FMod_Generator *)src->data; + FMod_Generator *gen = (FMod_Generator *)fcm->data; + FMod_Generator *ogen = (FMod_Generator *)src->data; /* copy coefficients array? */ if (ogen->coefficients) - gen->coefficients= MEM_dupallocN(ogen->coefficients); + gen->coefficients = MEM_dupallocN(ogen->coefficients); } -static void fcm_generator_new_data (void *mdata) +static void fcm_generator_new_data(void *mdata) { - FMod_Generator *data= (FMod_Generator *)mdata; + FMod_Generator *data = (FMod_Generator *)mdata; float *cp; /* set default generator to be linear 0-1 (gradient = 1, y-offset = 0) */ - data->poly_order= 1; - data->arraysize= 2; - cp= data->coefficients= MEM_callocN(sizeof(float)*2, "FMod_Generator_Coefs"); + data->poly_order = 1; + data->arraysize = 2; + cp = data->coefficients = MEM_callocN(sizeof(float) * 2, "FMod_Generator_Coefs"); cp[0] = 0; // y-offset cp[1] = 1; // gradient } -static void fcm_generator_verify (FModifier *fcm) +static void fcm_generator_verify(FModifier *fcm) { - FMod_Generator *data= (FMod_Generator *)fcm->data; + FMod_Generator *data = (FMod_Generator *)fcm->data; /* requirements depend on mode */ switch (data->mode) { case FCM_GENERATOR_POLYNOMIAL: /* expanded polynomial expression */ { /* arraysize needs to be order+1, so resize if not */ - if (data->arraysize != (data->poly_order+1)) { + if (data->arraysize != (data->poly_order + 1)) { float *nc; /* make new coefficients array, and copy over as much data as can fit */ - nc= MEM_callocN(sizeof(float)*(data->poly_order+1), "FMod_Generator_Coefs"); + nc = MEM_callocN(sizeof(float) * (data->poly_order + 1), "FMod_Generator_Coefs"); if (data->coefficients) { - if ((int)data->arraysize > (data->poly_order+1)) - memcpy(nc, data->coefficients, sizeof(float)*(data->poly_order+1)); + if ((int)data->arraysize > (data->poly_order + 1)) + memcpy(nc, data->coefficients, sizeof(float) * (data->poly_order + 1)); else - memcpy(nc, data->coefficients, sizeof(float)*data->arraysize); + memcpy(nc, data->coefficients, sizeof(float) * data->arraysize); /* free the old data */ MEM_freeN(data->coefficients); } /* set the new data */ - data->coefficients= nc; - data->arraysize= data->poly_order+1; + data->coefficients = nc; + data->arraysize = data->poly_order + 1; } } - break; + break; case FCM_GENERATOR_POLYNOMIAL_FACTORISED: /* expanded polynomial expression */ { @@ -175,30 +175,30 @@ static void fcm_generator_verify (FModifier *fcm) float *nc; /* make new coefficients array, and copy over as much data as can fit */ - nc= MEM_callocN(sizeof(float)*(data->poly_order*2), "FMod_Generator_Coefs"); + nc = MEM_callocN(sizeof(float) * (data->poly_order * 2), "FMod_Generator_Coefs"); if (data->coefficients) { if (data->arraysize > (unsigned int)(data->poly_order * 2)) - memcpy(nc, data->coefficients, sizeof(float)*(data->poly_order * 2)); + memcpy(nc, data->coefficients, sizeof(float) * (data->poly_order * 2)); else - memcpy(nc, data->coefficients, sizeof(float)*data->arraysize); + memcpy(nc, data->coefficients, sizeof(float) * data->arraysize); /* free the old data */ MEM_freeN(data->coefficients); } /* set the new data */ - data->coefficients= nc; - data->arraysize= data->poly_order * 2; + data->coefficients = nc; + data->arraysize = data->poly_order * 2; } } - break; + break; } } -static void fcm_generator_evaluate (FCurve *UNUSED(fcu), FModifier *fcm, float *cvalue, float evaltime) +static void fcm_generator_evaluate(FCurve *UNUSED(fcu), FModifier *fcm, float *cvalue, float evaltime) { - FMod_Generator *data= (FMod_Generator *)fcm->data; + FMod_Generator *data = (FMod_Generator *)fcm->data; /* behavior depends on mode * NOTE: the data in its default state is fine too @@ -207,23 +207,23 @@ static void fcm_generator_evaluate (FCurve *UNUSED(fcu), FModifier *fcm, float * case FCM_GENERATOR_POLYNOMIAL: /* expanded polynomial expression */ { /* we overwrite cvalue with the sum of the polynomial */ - float *powers = MEM_callocN(sizeof(float)*data->arraysize, "Poly Powers"); - float value= 0.0f; + float *powers = MEM_callocN(sizeof(float) * data->arraysize, "Poly Powers"); + float value = 0.0f; unsigned int i; /* for each x^n, precalculate value based on previous one first... this should be * faster that calling pow() for each entry */ - for (i=0; i < data->arraysize; i++) { + for (i = 0; i < data->arraysize; i++) { /* first entry is x^0 = 1, otherwise, calculate based on previous */ if (i) - powers[i]= powers[i-1] * evaltime; + powers[i] = powers[i - 1] * evaltime; else - powers[0]= 1; + powers[0] = 1; } /* for each coefficient, add to value, which we'll write to *cvalue in one go */ - for (i=0; i < data->arraysize; i++) + for (i = 0; i < data->arraysize; i++) value += data->coefficients[i] * powers[i]; /* only if something changed, write *cvalue in one go */ @@ -231,33 +231,33 @@ static void fcm_generator_evaluate (FCurve *UNUSED(fcu), FModifier *fcm, float * if (data->flag & FCM_GENERATOR_ADDITIVE) *cvalue += value; else - *cvalue= value; + *cvalue = value; } /* cleanup */ if (powers) MEM_freeN(powers); } - break; + break; case FCM_GENERATOR_POLYNOMIAL_FACTORISED: /* Factorized polynomial */ { - float value= 1.0f, *cp=NULL; + float value = 1.0f, *cp = NULL; unsigned int i; /* for each coefficient pair, solve for that bracket before accumulating in value by multiplying */ - for (cp=data->coefficients, i=0; (cp) && (i < (unsigned int)data->poly_order); cp+=2, i++) - value *= (cp[0]*evaltime + cp[1]); + for (cp = data->coefficients, i = 0; (cp) && (i < (unsigned int)data->poly_order); cp += 2, i++) + value *= (cp[0] * evaltime + cp[1]); /* only if something changed, write *cvalue in one go */ if (data->poly_order) { if (data->flag & FCM_GENERATOR_ADDITIVE) *cvalue += value; else - *cvalue= value; + *cvalue = value; } } - break; + break; } } @@ -279,7 +279,7 @@ static FModifierTypeInfo FMI_GENERATOR = { /* Built-In Function Generator F-Curve Modifier --------------------------- */ /* This uses the general equation for equations: - * y = amplitude * fn(phase_multiplier*x + phase_offset) + y_offset + * y = amplitude * fn(phase_multiplier*x + phase_offset) + y_offset * * where amplitude, phase_multiplier/offset, y_offset are user-defined coefficients, * x is the evaluation 'time', and 'y' is the resultant value @@ -288,20 +288,20 @@ static FModifierTypeInfo FMI_GENERATOR = { * sin, cos, tan, sinc (normalised sin), natural log, square root */ -static void fcm_fn_generator_new_data (void *mdata) +static void fcm_fn_generator_new_data(void *mdata) { - FMod_FunctionGenerator *data= (FMod_FunctionGenerator *)mdata; + FMod_FunctionGenerator *data = (FMod_FunctionGenerator *)mdata; /* set amplitude and phase multiplier to 1.0f so that something is generated */ - data->amplitude= 1.0f; - data->phase_multiplier= 1.0f; + data->amplitude = 1.0f; + data->phase_multiplier = 1.0f; } /* Unary 'normalised sine' function - * y = sin(PI + x) / (PI * x), + * y = sin(PI + x) / (PI * x), * except for x = 0 when y = 1. */ -static double sinc (double x) +static double sinc(double x) { if (fabs(x) < 0.0001) return 1.0; @@ -309,10 +309,10 @@ static double sinc (double x) return sin(M_PI * x) / (M_PI * x); } -static void fcm_fn_generator_evaluate (FCurve *UNUSED(fcu), FModifier *fcm, float *cvalue, float evaltime) +static void fcm_fn_generator_evaluate(FCurve *UNUSED(fcu), FModifier *fcm, float *cvalue, float evaltime) { - FMod_FunctionGenerator *data= (FMod_FunctionGenerator *)fcm->data; - double arg= data->phase_multiplier*evaltime + data->phase_offset; + FMod_FunctionGenerator *data = (FMod_FunctionGenerator *)fcm->data; + double arg = data->phase_multiplier * evaltime + data->phase_offset; double (*fn)(double v) = NULL; /* get function pointer to the func to use: @@ -321,13 +321,13 @@ static void fcm_fn_generator_evaluate (FCurve *UNUSED(fcu), FModifier *fcm, floa switch (data->type) { /* simple ones */ case FCM_GENERATOR_FN_SIN: /* sine wave */ - fn= sin; + fn = sin; break; case FCM_GENERATOR_FN_COS: /* cosine wave */ - fn= cos; + fn = cos; break; case FCM_GENERATOR_FN_SINC: /* normalised sine wave */ - fn= sinc; + fn = sinc; break; /* validation required */ @@ -336,36 +336,36 @@ static void fcm_fn_generator_evaluate (FCurve *UNUSED(fcu), FModifier *fcm, floa /* check that argument is not on one of the discontinuities (i.e. 90deg, 270 deg, etc) */ if (IS_EQ(fmod((arg - M_PI_2), M_PI), 0.0)) { if ((data->flag & FCM_GENERATOR_ADDITIVE) == 0) - *cvalue = 0.0f; /* no value possible here */ + *cvalue = 0.0f; /* no value possible here */ } else - fn= tan; + fn = tan; } - break; + break; case FCM_GENERATOR_FN_LN: /* natural log */ { /* check that value is greater than 1? */ if (arg > 1.0) { - fn= log; + fn = log; } else { if ((data->flag & FCM_GENERATOR_ADDITIVE) == 0) - *cvalue = 0.0f; /* no value possible here */ + *cvalue = 0.0f; /* no value possible here */ } } - break; + break; case FCM_GENERATOR_FN_SQRT: /* square root */ { /* no negative numbers */ if (arg > 0.0) { - fn= sqrt; + fn = sqrt; } else { if ((data->flag & FCM_GENERATOR_ADDITIVE) == 0) - *cvalue = 0.0f; /* no value possible here */ + *cvalue = 0.0f; /* no value possible here */ } } - break; + break; default: printf("Invalid Function-Generator for F-Modifier - %d\n", data->type); @@ -373,12 +373,12 @@ 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*(float)fn(arg) + data->value_offset); + float value = (float)(data->amplitude * (float)fn(arg) + data->value_offset); if (data->flag & FCM_GENERATOR_ADDITIVE) *cvalue += value; else - *cvalue= value; + *cvalue = value; } } @@ -399,37 +399,37 @@ static FModifierTypeInfo FMI_FN_GENERATOR = { /* Envelope F-Curve Modifier --------------------------- */ -static void fcm_envelope_free (FModifier *fcm) +static void fcm_envelope_free(FModifier *fcm) { - FMod_Envelope *env= (FMod_Envelope *)fcm->data; + FMod_Envelope *env = (FMod_Envelope *)fcm->data; /* free envelope data array */ if (env->data) MEM_freeN(env->data); } -static void fcm_envelope_copy (FModifier *fcm, FModifier *src) +static void fcm_envelope_copy(FModifier *fcm, FModifier *src) { - FMod_Envelope *env= (FMod_Envelope *)fcm->data; - FMod_Envelope *oenv= (FMod_Envelope *)src->data; + FMod_Envelope *env = (FMod_Envelope *)fcm->data; + FMod_Envelope *oenv = (FMod_Envelope *)src->data; /* copy envelope data array */ if (oenv->data) - env->data= MEM_dupallocN(oenv->data); + env->data = MEM_dupallocN(oenv->data); } -static void fcm_envelope_new_data (void *mdata) +static void fcm_envelope_new_data(void *mdata) { - FMod_Envelope *env= (FMod_Envelope *)mdata; + FMod_Envelope *env = (FMod_Envelope *)mdata; /* set default min/max ranges */ - env->min= -1.0f; - env->max= 1.0f; + env->min = -1.0f; + env->max = 1.0f; } -static void fcm_envelope_verify (FModifier *fcm) +static void fcm_envelope_verify(FModifier *fcm) { - FMod_Envelope *env= (FMod_Envelope *)fcm->data; + FMod_Envelope *env = (FMod_Envelope *)fcm->data; /* if the are points, perform bubble-sort on them, as user may have changed the order */ if (env->data) { @@ -437,44 +437,44 @@ static void fcm_envelope_verify (FModifier *fcm) } } -static void fcm_envelope_evaluate (FCurve *UNUSED(fcu), FModifier *fcm, float *cvalue, float evaltime) +static void fcm_envelope_evaluate(FCurve *UNUSED(fcu), FModifier *fcm, float *cvalue, float evaltime) { - FMod_Envelope *env= (FMod_Envelope *)fcm->data; + FMod_Envelope *env = (FMod_Envelope *)fcm->data; FCM_EnvelopeData *fed, *prevfed, *lastfed; - float min=0.0f, max=0.0f, fac=0.0f; + float min = 0.0f, max = 0.0f, fac = 0.0f; int a; /* get pointers */ if (env->data == NULL) return; - prevfed= env->data; - fed= prevfed + 1; - lastfed= prevfed + (env->totvert-1); + prevfed = env->data; + fed = prevfed + 1; + lastfed = prevfed + (env->totvert - 1); /* get min/max values for envelope at evaluation time (relative to mid-value) */ if (prevfed->time >= evaltime) { /* before or on first sample, so just extend value */ - min= prevfed->min; - max= prevfed->max; + min = prevfed->min; + max = prevfed->max; } else if (lastfed->time <= evaltime) { /* after or on last sample, so just extend value */ - min= lastfed->min; - max= lastfed->max; + min = lastfed->min; + max = lastfed->max; } else { /* evaltime occurs somewhere between segments */ // TODO: implement binary search for this to make it faster? - for (a=0; prevfed && fed && (a < env->totvert-1); a++, prevfed=fed, fed++) { + for (a = 0; prevfed && fed && (a < env->totvert - 1); a++, prevfed = fed, fed++) { /* evaltime occurs within the interval defined by these two envelope points */ if ((prevfed->time <= evaltime) && (fed->time >= evaltime)) { float afac, bfac, diff; - diff= fed->time - prevfed->time; - afac= (evaltime - prevfed->time) / diff; - bfac= (fed->time - evaltime) / diff; + diff = fed->time - prevfed->time; + afac = (evaltime - prevfed->time) / diff; + bfac = (fed->time - evaltime) / diff; - min= bfac*prevfed->min + afac*fed->min; - max= bfac*prevfed->max + afac*fed->max; + min = bfac * prevfed->min + afac * fed->min; + max = bfac * prevfed->max + afac * fed->max; break; } @@ -485,8 +485,8 @@ static void fcm_envelope_evaluate (FCurve *UNUSED(fcu), FModifier *fcm, float *c * - fac is the ratio of how the current y-value corresponds to the reference range * - thus, the new value is found by mapping the old range to the new! */ - fac= (*cvalue - (env->midval + env->min)) / (env->max - env->min); - *cvalue= min + fac*(max - min); + fac = (*cvalue - (env->midval + env->min)) / (env->max - env->min); + *cvalue = min + fac * (max - min); } static FModifierTypeInfo FMI_ENVELOPE = { @@ -520,23 +520,23 @@ static FModifierTypeInfo FMI_ENVELOPE = { /* temp data used during evaluation */ typedef struct tFCMED_Cycles { - float cycyofs; /* y-offset to apply */ + float cycyofs; /* y-offset to apply */ } tFCMED_Cycles; -static void fcm_cycles_new_data (void *mdata) +static void fcm_cycles_new_data(void *mdata) { - FMod_Cycles *data= (FMod_Cycles *)mdata; + FMod_Cycles *data = (FMod_Cycles *)mdata; /* turn on cycles by default */ - data->before_mode= data->after_mode= FCM_EXTRAPOLATE_CYCLIC; + data->before_mode = data->after_mode = FCM_EXTRAPOLATE_CYCLIC; } -static float fcm_cycles_time (FCurve *fcu, FModifier *fcm, float UNUSED(cvalue), float evaltime) +static float fcm_cycles_time(FCurve *fcu, FModifier *fcm, float UNUSED(cvalue), float evaltime) { - FMod_Cycles *data= (FMod_Cycles *)fcm->data; - float prevkey[2], lastkey[2], cycyofs=0.0f; - short side=0, mode=0; - int cycles=0, ofs=0; + FMod_Cycles *data = (FMod_Cycles *)fcm->data; + float prevkey[2], lastkey[2], cycyofs = 0.0f; + short side = 0, mode = 0; + int cycles = 0, ofs = 0; /* check if modifier is first in stack, otherwise disable ourself... */ // FIXME... @@ -547,24 +547,24 @@ static float fcm_cycles_time (FCurve *fcu, FModifier *fcm, float UNUSED(cvalue), /* calculate new evaltime due to cyclic interpolation */ if (fcu && fcu->bezt) { - BezTriple *prevbezt= fcu->bezt; - BezTriple *lastbezt= prevbezt + fcu->totvert-1; + BezTriple *prevbezt = fcu->bezt; + BezTriple *lastbezt = prevbezt + fcu->totvert - 1; - prevkey[0]= prevbezt->vec[1][0]; - prevkey[1]= prevbezt->vec[1][1]; + prevkey[0] = prevbezt->vec[1][0]; + prevkey[1] = prevbezt->vec[1][1]; - lastkey[0]= lastbezt->vec[1][0]; - lastkey[1]= lastbezt->vec[1][1]; + lastkey[0] = lastbezt->vec[1][0]; + lastkey[1] = lastbezt->vec[1][1]; } else if (fcu && fcu->fpt) { - FPoint *prevfpt= fcu->fpt; - FPoint *lastfpt= prevfpt + fcu->totvert-1; + FPoint *prevfpt = fcu->fpt; + FPoint *lastfpt = prevfpt + fcu->totvert - 1; - prevkey[0]= prevfpt->vec[0]; - prevkey[1]= prevfpt->vec[1]; + prevkey[0] = prevfpt->vec[0]; + prevkey[1] = prevfpt->vec[1]; - lastkey[0]= lastfpt->vec[0]; - lastkey[1]= lastfpt->vec[1]; + lastkey[0] = lastfpt->vec[0]; + lastkey[1] = lastfpt->vec[1]; } else return evaltime; @@ -575,18 +575,18 @@ static float fcm_cycles_time (FCurve *fcu, FModifier *fcm, float UNUSED(cvalue), */ if (evaltime < prevkey[0]) { if (data->before_mode) { - side= -1; - mode= data->before_mode; - cycles= data->before_cycles; - ofs= prevkey[0]; + side = -1; + mode = data->before_mode; + cycles = data->before_cycles; + ofs = prevkey[0]; } } else if (evaltime > lastkey[0]) { if (data->after_mode) { - side= 1; - mode= data->after_mode; - cycles= data->after_cycles; - ofs= lastkey[0]; + side = 1; + mode = data->after_mode; + cycles = data->after_cycles; + ofs = lastkey[0]; } } if ((ELEM(0, side, mode))) @@ -594,22 +594,22 @@ static float fcm_cycles_time (FCurve *fcu, FModifier *fcm, float UNUSED(cvalue), /* find relative place within a cycle */ { - float cycdx=0, cycdy=0; - float cycle= 0, cyct=0; + float cycdx = 0, cycdy = 0; + float cycle = 0, cyct = 0; /* calculate period and amplitude (total height) of a cycle */ - cycdx= lastkey[0] - prevkey[0]; - cycdy= lastkey[1] - prevkey[1]; + cycdx = lastkey[0] - prevkey[0]; + cycdy = lastkey[1] - prevkey[1]; /* check if cycle is infinitely small, to be point of being impossible to use */ if (cycdx == 0) return evaltime; /* calculate the 'number' of the cycle */ - cycle= ((float)side * (evaltime - ofs) / cycdx); + cycle = ((float)side * (evaltime - ofs) / cycdx); /* calculate the time inside the cycle */ - cyct= fmod(evaltime - ofs, cycdx); + cyct = fmod(evaltime - ofs, cycdx); /* check that cyclic is still enabled for the specified time */ if (cycles == 0) { @@ -641,19 +641,19 @@ static float fcm_cycles_time (FCurve *fcu, FModifier *fcm, float UNUSED(cvalue), evaltime = (side == 1 ? prevkey[0] : lastkey[0]); } /* calculate where in the cycle we are (overwrite evaltime to reflect this) */ - else if ((mode == FCM_EXTRAPOLATE_MIRROR) && ((int)(cycle+1) % 2)) { + else if ((mode == FCM_EXTRAPOLATE_MIRROR) && ((int)(cycle + 1) % 2)) { /* when 'mirror' option is used and cycle number is odd, this cycle is played in reverse * - for 'before' extrapolation, we need to flip in a different way, otherwise values past * then end of the curve get referenced (result of fmod will be negative, and with different phase) */ if (side < 0) - evaltime= prevkey[0] - cyct; + evaltime = prevkey[0] - cyct; else - evaltime= lastkey[0] - cyct; + evaltime = lastkey[0] - cyct; } else { /* the cycle is played normally... */ - evaltime= prevkey[0] + cyct; + evaltime = prevkey[0] + cyct; } if (evaltime < prevkey[0]) evaltime += cycdx; } @@ -663,17 +663,17 @@ static float fcm_cycles_time (FCurve *fcu, FModifier *fcm, float UNUSED(cvalue), tFCMED_Cycles *edata; /* for now, this is just a float, but we could get more stuff... */ - fcm->edata= edata= MEM_callocN(sizeof(tFCMED_Cycles), "tFCMED_Cycles"); - edata->cycyofs= cycyofs; + fcm->edata = edata = MEM_callocN(sizeof(tFCMED_Cycles), "tFCMED_Cycles"); + edata->cycyofs = cycyofs; } /* return the new frame to evaluate */ return evaltime; } -static void fcm_cycles_evaluate (FCurve *UNUSED(fcu), FModifier *fcm, float *cvalue, float UNUSED(evaltime)) +static void fcm_cycles_evaluate(FCurve *UNUSED(fcu), FModifier *fcm, float *cvalue, float UNUSED(evaltime)) { - tFCMED_Cycles *edata= (tFCMED_Cycles *)fcm->edata; + tFCMED_Cycles *edata = (tFCMED_Cycles *)fcm->edata; /* use temp data */ if (edata) { @@ -682,7 +682,7 @@ static void fcm_cycles_evaluate (FCurve *UNUSED(fcu), FModifier *fcm, float *cva /* free temp data */ MEM_freeN(edata); - fcm->edata= NULL; + fcm->edata = NULL; } } @@ -703,21 +703,21 @@ static FModifierTypeInfo FMI_CYCLES = { /* Noise F-Curve Modifier --------------------------- */ -static void fcm_noise_new_data (void *mdata) +static void fcm_noise_new_data(void *mdata) { - FMod_Noise *data= (FMod_Noise *)mdata; + FMod_Noise *data = (FMod_Noise *)mdata; /* defaults */ - data->size= 1.0f; - data->strength= 1.0f; - data->phase= 1.0f; + data->size = 1.0f; + data->strength = 1.0f; + data->phase = 1.0f; data->depth = 0; data->modification = FCM_NOISE_MODIF_REPLACE; } -static void fcm_noise_evaluate (FCurve *UNUSED(fcu), FModifier *fcm, float *cvalue, float evaltime) +static void fcm_noise_evaluate(FCurve *UNUSED(fcu), FModifier *fcm, float *cvalue, float evaltime) { - FMod_Noise *data= (FMod_Noise *)fcm->data; + FMod_Noise *data = (FMod_Noise *)fcm->data; float noise; /* generate noise using good ol' Blender Noise @@ -729,17 +729,17 @@ static void fcm_noise_evaluate (FCurve *UNUSED(fcu), FModifier *fcm, float *cval /* combine the noise with existing motion data */ switch (data->modification) { case FCM_NOISE_MODIF_ADD: - *cvalue= *cvalue + noise * data->strength; + *cvalue = *cvalue + noise * data->strength; break; case FCM_NOISE_MODIF_SUBTRACT: - *cvalue= *cvalue - noise * data->strength; + *cvalue = *cvalue - noise * data->strength; break; case FCM_NOISE_MODIF_MULTIPLY: - *cvalue= *cvalue * noise * data->strength; + *cvalue = *cvalue * noise * data->strength; break; case FCM_NOISE_MODIF_REPLACE: default: - *cvalue= *cvalue + (noise - 0.5f) * data->strength; + *cvalue = *cvalue + (noise - 0.5f) * data->strength; break; } } @@ -781,25 +781,25 @@ static FModifierTypeInfo FMI_FILTER = { /* Python F-Curve Modifier --------------------------- */ -static void fcm_python_free (FModifier *fcm) +static void fcm_python_free(FModifier *fcm) { - FMod_Python *data= (FMod_Python *)fcm->data; + FMod_Python *data = (FMod_Python *)fcm->data; /* id-properties */ IDP_FreeProperty(data->prop); MEM_freeN(data->prop); } -static void fcm_python_new_data (void *mdata) +static void fcm_python_new_data(void *mdata) { - FMod_Python *data= (FMod_Python *)mdata; + FMod_Python *data = (FMod_Python *)mdata; /* everything should be set correctly by calloc, except for the prop->type constant.*/ data->prop = MEM_callocN(sizeof(IDProperty), "PyFModifierProps"); data->prop->type = IDP_GROUP; } -static void fcm_python_copy (FModifier *fcm, FModifier *src) +static void fcm_python_copy(FModifier *fcm, FModifier *src) { FMod_Python *pymod = (FMod_Python *)fcm->data; FMod_Python *opymod = (FMod_Python *)src->data; @@ -807,7 +807,7 @@ static void fcm_python_copy (FModifier *fcm, FModifier *src) pymod->prop = IDP_CopyProperty(opymod->prop); } -static void fcm_python_evaluate (FCurve *UNUSED(fcu), FModifier *UNUSED(fcm), float *UNUSED(cvalue), float UNUSED(evaltime)) +static void fcm_python_evaluate(FCurve *UNUSED(fcu), FModifier *UNUSED(fcm), float *UNUSED(cvalue), float UNUSED(evaltime)) { #ifdef WITH_PYTHON //FMod_Python *data= (FMod_Python *)fcm->data; @@ -836,9 +836,9 @@ static FModifierTypeInfo FMI_PYTHON = { /* Limits F-Curve Modifier --------------------------- */ -static float fcm_limits_time (FCurve *UNUSED(fcu), FModifier *fcm, float UNUSED(cvalue), float evaltime) +static float fcm_limits_time(FCurve *UNUSED(fcu), FModifier *fcm, float UNUSED(cvalue), float evaltime) { - FMod_Limits *data= (FMod_Limits *)fcm->data; + FMod_Limits *data = (FMod_Limits *)fcm->data; /* check for the time limits */ if ((data->flag & FCM_LIMIT_XMIN) && (evaltime < data->rect.xmin)) @@ -850,15 +850,15 @@ static float fcm_limits_time (FCurve *UNUSED(fcu), FModifier *fcm, float UNUSED( return evaltime; } -static void fcm_limits_evaluate (FCurve *UNUSED(fcu), FModifier *fcm, float *cvalue, float UNUSED(evaltime)) +static void fcm_limits_evaluate(FCurve *UNUSED(fcu), FModifier *fcm, float *cvalue, float UNUSED(evaltime)) { - FMod_Limits *data= (FMod_Limits *)fcm->data; + FMod_Limits *data = (FMod_Limits *)fcm->data; /* value limits now */ if ((data->flag & FCM_LIMIT_YMIN) && (*cvalue < data->rect.ymin)) - *cvalue= data->rect.ymin; + *cvalue = data->rect.ymin; if ((data->flag & FCM_LIMIT_YMAX) && (*cvalue > data->rect.ymax)) - *cvalue= data->rect.ymax; + *cvalue = data->rect.ymax; } static FModifierTypeInfo FMI_LIMITS = { @@ -878,18 +878,18 @@ static FModifierTypeInfo FMI_LIMITS = { /* Stepped F-Curve Modifier --------------------------- */ -static void fcm_stepped_new_data (void *mdata) +static void fcm_stepped_new_data(void *mdata) { - FMod_Stepped *data= (FMod_Stepped *)mdata; + FMod_Stepped *data = (FMod_Stepped *)mdata; /* just need to set the step-size to 2-frames by default */ // XXX: or would 5 be more normal? data->step_size = 2.0f; } -static float fcm_stepped_time (FCurve *UNUSED(fcu), FModifier *fcm, float UNUSED(cvalue), float evaltime) +static float fcm_stepped_time(FCurve *UNUSED(fcu), FModifier *fcm, float UNUSED(cvalue), float evaltime) { - FMod_Stepped *data= (FMod_Stepped *)fcm->data; + FMod_Stepped *data = (FMod_Stepped *)fcm->data; int snapblock; /* check range clamping to see if we should alter the timing to achieve the desired results */ @@ -936,27 +936,27 @@ static FModifierTypeInfo FMI_STEPPED = { /* These globals only ever get directly accessed in this file */ static FModifierTypeInfo *fmodifiersTypeInfo[FMODIFIER_NUM_TYPES]; -static short FMI_INIT= 1; /* when non-zero, the list needs to be updated */ +static short FMI_INIT = 1; /* when non-zero, the list needs to be updated */ /* This function only gets called when FMI_INIT is non-zero */ -static void fmods_init_typeinfo (void) +static void fmods_init_typeinfo(void) { - fmodifiersTypeInfo[0]= NULL; /* 'Null' F-Curve Modifier */ - fmodifiersTypeInfo[1]= &FMI_GENERATOR; /* Generator F-Curve Modifier */ - fmodifiersTypeInfo[2]= &FMI_FN_GENERATOR; /* Built-In Function Generator F-Curve Modifier */ - fmodifiersTypeInfo[3]= &FMI_ENVELOPE; /* Envelope F-Curve Modifier */ - fmodifiersTypeInfo[4]= &FMI_CYCLES; /* Cycles F-Curve Modifier */ - fmodifiersTypeInfo[5]= &FMI_NOISE; /* Apply-Noise F-Curve Modifier */ - fmodifiersTypeInfo[6]= NULL/*&FMI_FILTER*/; /* Filter F-Curve Modifier */ // XXX unimplemented - fmodifiersTypeInfo[7]= &FMI_PYTHON; /* Custom Python F-Curve Modifier */ - fmodifiersTypeInfo[8]= &FMI_LIMITS; /* Limits F-Curve Modifier */ - fmodifiersTypeInfo[9]= &FMI_STEPPED; /* Stepped F-Curve Modifier */ + fmodifiersTypeInfo[0] = NULL; /* 'Null' F-Curve Modifier */ + fmodifiersTypeInfo[1] = &FMI_GENERATOR; /* Generator F-Curve Modifier */ + fmodifiersTypeInfo[2] = &FMI_FN_GENERATOR; /* Built-In Function Generator F-Curve Modifier */ + fmodifiersTypeInfo[3] = &FMI_ENVELOPE; /* Envelope F-Curve Modifier */ + fmodifiersTypeInfo[4] = &FMI_CYCLES; /* Cycles F-Curve Modifier */ + fmodifiersTypeInfo[5] = &FMI_NOISE; /* Apply-Noise F-Curve Modifier */ + fmodifiersTypeInfo[6] = NULL /*&FMI_FILTER*/; /* Filter F-Curve Modifier */ // XXX unimplemented + fmodifiersTypeInfo[7] = &FMI_PYTHON; /* Custom Python F-Curve Modifier */ + fmodifiersTypeInfo[8] = &FMI_LIMITS; /* Limits F-Curve Modifier */ + fmodifiersTypeInfo[9] = &FMI_STEPPED; /* Stepped F-Curve Modifier */ } /* This function should be used for getting the appropriate type-info when only * a F-Curve modifier type is known */ -FModifierTypeInfo *get_fmodifier_typeinfo (int type) +FModifierTypeInfo *get_fmodifier_typeinfo(int type) { /* initialize the type-info list? */ if (FMI_INIT) { @@ -966,7 +966,7 @@ FModifierTypeInfo *get_fmodifier_typeinfo (int type) /* only return for valid types */ if ( (type >= FMODIFIER_TYPE_NULL) && - (type <= FMODIFIER_NUM_TYPES ) ) + (type <= FMODIFIER_NUM_TYPES) ) { /* there shouldn't be any segfaults here... */ return fmodifiersTypeInfo[type]; @@ -981,7 +981,7 @@ FModifierTypeInfo *get_fmodifier_typeinfo (int type) /* This function should always be used to get the appropriate type-info, as it * has checks which prevent segfaults in some weird cases. */ -FModifierTypeInfo *fmodifier_get_typeinfo (FModifier *fcm) +FModifierTypeInfo *fmodifier_get_typeinfo(FModifier *fcm) { /* only return typeinfo for valid modifiers */ if (fcm) @@ -993,9 +993,9 @@ FModifierTypeInfo *fmodifier_get_typeinfo (FModifier *fcm) /* API --------------------------- */ /* Add a new F-Curve Modifier to the given F-Curve of a certain type */ -FModifier *add_fmodifier (ListBase *modifiers, int type) +FModifier *add_fmodifier(ListBase *modifiers, int type) { - FModifierTypeInfo *fmi= get_fmodifier_typeinfo(type); + FModifierTypeInfo *fmi = get_fmodifier_typeinfo(type); FModifier *fcm; /* sanity checks */ @@ -1011,7 +1011,7 @@ FModifier *add_fmodifier (ListBase *modifiers, int type) } /* add modifier itself */ - fcm= MEM_callocN(sizeof(FModifier), "F-Curve Modifier"); + fcm = MEM_callocN(sizeof(FModifier), "F-Curve Modifier"); fcm->type = type; fcm->flag = FMODIFIER_FLAG_EXPANDED; fcm->influence = 1.0f; @@ -1022,7 +1022,7 @@ FModifier *add_fmodifier (ListBase *modifiers, int type) fcm->flag |= FMODIFIER_FLAG_ACTIVE; /* add modifier's data */ - fcm->data= MEM_callocN(fmi->size, fmi->structName); + fcm->data = MEM_callocN(fmi->size, fmi->structName); /* init custom settings if necessary */ if (fmi->new_data) @@ -1033,9 +1033,9 @@ FModifier *add_fmodifier (ListBase *modifiers, int type) } /* Make a copy of the specified F-Modifier */ -FModifier *copy_fmodifier (FModifier *src) +FModifier *copy_fmodifier(FModifier *src) { - FModifierTypeInfo *fmi= fmodifier_get_typeinfo(src); + FModifierTypeInfo *fmi = fmodifier_get_typeinfo(src); FModifier *dst; /* sanity check */ @@ -1065,11 +1065,11 @@ void copy_fmodifiers(ListBase *dst, ListBase *src) if (ELEM(NULL, dst, src)) return; - dst->first= dst->last= NULL; + dst->first = dst->last = NULL; BLI_duplicatelist(dst, src); - for (fcm=dst->first, srcfcm=src->first; fcm && srcfcm; srcfcm=srcfcm->next, fcm=fcm->next) { - FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm); + for (fcm = dst->first, srcfcm = src->first; fcm && srcfcm; srcfcm = srcfcm->next, fcm = fcm->next) { + FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm); /* make a new copy of the F-Modifier's data */ fcm->data = MEM_dupallocN(fcm->data); @@ -1083,7 +1083,7 @@ void copy_fmodifiers(ListBase *dst, ListBase *src) /* Remove and free the given F-Modifier from the given stack */ int remove_fmodifier(ListBase *modifiers, FModifier *fcm) { - FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm); + FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm); /* sanity check */ if (fcm == NULL) @@ -1121,14 +1121,14 @@ void free_fmodifiers(ListBase *modifiers) return; /* free each modifier in order - modifier is unlinked from list and freed */ - for (fcm= modifiers->first; fcm; fcm= fmn) { - fmn= fcm->next; + for (fcm = modifiers->first; fcm; fcm = fmn) { + fmn = fcm->next; remove_fmodifier(modifiers, fcm); } } /* Find the active F-Modifier */ -FModifier *find_active_fmodifier (ListBase *modifiers) +FModifier *find_active_fmodifier(ListBase *modifiers) { FModifier *fcm; @@ -1137,7 +1137,7 @@ FModifier *find_active_fmodifier (ListBase *modifiers) return NULL; /* loop over modifiers until 'active' one is found */ - for (fcm= modifiers->first; fcm; fcm= fcm->next) { + for (fcm = modifiers->first; fcm; fcm = fcm->next) { if (fcm->flag & FMODIFIER_FLAG_ACTIVE) return fcm; } @@ -1156,7 +1156,7 @@ void set_active_fmodifier(ListBase *modifiers, FModifier *fcm) return; /* deactivate all, and set current one active */ - for (fm= modifiers->first; fm; fm= fm->next) + for (fm = modifiers->first; fm; fm = fm->next) fm->flag &= ~FMODIFIER_FLAG_ACTIVE; /* make given modifier active */ @@ -1181,15 +1181,15 @@ short list_has_suitable_fmodifier(ListBase *modifiers, int mtype, short acttype) return 0; /* find the first mdifier fitting these criteria */ - for (fcm= modifiers->first; fcm; fcm= fcm->next) { - FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm); - short mOk=1, aOk=1; /* by default 1, so that when only one test, won't fail */ + for (fcm = modifiers->first; fcm; fcm = fcm->next) { + FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm); + short mOk = 1, aOk = 1; /* by default 1, so that when only one test, won't fail */ /* check if applicable ones are fullfilled */ if (mtype) - mOk= (fcm->type == mtype); + mOk = (fcm->type == mtype); if (acttype > -1) - aOk= (fmi->acttype == acttype); + aOk = (fmi->acttype == acttype); /* if both are ok, we've found a hit */ if (mOk && aOk) @@ -1203,7 +1203,7 @@ short list_has_suitable_fmodifier(ListBase *modifiers, int mtype, short acttype) /* Evaluation API --------------------------- */ /* helper function - calculate influence of FModifier */ -static float eval_fmodifier_influence (FModifier *fcm, float evaltime) +static float eval_fmodifier_influence(FModifier *fcm, float evaltime) { float influence; @@ -1270,8 +1270,8 @@ float evaluate_time_fmodifiers(ListBase *modifiers, FCurve *fcu, float cvalue, f * effect, which should get us the desired effects when using layered time manipulations * (such as multiple 'stepped' modifiers in sequence, causing different stepping rates) */ - for (fcm= modifiers->last; fcm; fcm= fcm->prev) { - FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm); + for (fcm = modifiers->last; fcm; fcm = fcm->prev) { + FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm); if (fmi == NULL) continue; @@ -1279,12 +1279,12 @@ float evaluate_time_fmodifiers(ListBase *modifiers, FCurve *fcu, float cvalue, f /* if modifier cannot be applied on this frame (whatever scale it is on, it won't affect the results) * hence we shouldn't bother seeing what it would do given the chance */ - if ((fcm->flag & FMODIFIER_FLAG_RANGERESTRICT)==0 || - ((fcm->sfra <= evaltime) && (fcm->efra >= evaltime)) ) + if ((fcm->flag & FMODIFIER_FLAG_RANGERESTRICT) == 0 || + ((fcm->sfra <= evaltime) && (fcm->efra >= evaltime)) ) { /* only evaluate if there's a callback for this */ if (fmi->evaluate_modifier_time) { - if ((fcm->flag & (FMODIFIER_FLAG_DISABLED|FMODIFIER_FLAG_MUTED)) == 0) { + if ((fcm->flag & (FMODIFIER_FLAG_DISABLED | FMODIFIER_FLAG_MUTED)) == 0) { float influence = eval_fmodifier_influence(fcm, evaltime); float nval = fmi->evaluate_modifier_time(fcu, fcm, cvalue, evaltime); @@ -1310,18 +1310,18 @@ void evaluate_value_fmodifiers(ListBase *modifiers, FCurve *fcu, float *cvalue, return; /* evaluate modifiers */ - for (fcm= modifiers->first; fcm; fcm= fcm->next) { - FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm); + for (fcm = modifiers->first; fcm; fcm = fcm->next) { + FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm); if (fmi == NULL) continue; /* only evaluate if there's a callback for this, and if F-Modifier can be evaluated on this frame */ - if ((fcm->flag & FMODIFIER_FLAG_RANGERESTRICT)==0 || - ((fcm->sfra <= evaltime) && (fcm->efra >= evaltime)) ) + if ((fcm->flag & FMODIFIER_FLAG_RANGERESTRICT) == 0 || + ((fcm->sfra <= evaltime) && (fcm->efra >= evaltime)) ) { if (fmi->evaluate_modifier) { - if ((fcm->flag & (FMODIFIER_FLAG_DISABLED|FMODIFIER_FLAG_MUTED)) == 0) { + if ((fcm->flag & (FMODIFIER_FLAG_DISABLED | FMODIFIER_FLAG_MUTED)) == 0) { float influence = eval_fmodifier_influence(fcm, evaltime); float nval = *cvalue; @@ -1350,8 +1350,8 @@ void fcurve_bake_modifiers(FCurve *fcu, int start, int end) } /* temporarily, disable driver while we sample, so that they don't influence the outcome */ - driver= fcu->driver; - fcu->driver= NULL; + driver = fcu->driver; + fcu->driver = NULL; /* bake the modifiers, by sampling the curve at each frame */ fcurve_store_samples(fcu, NULL, start, end, fcurve_samplingcb_evalcurve); @@ -1360,5 +1360,5 @@ void fcurve_bake_modifiers(FCurve *fcu, int start, int end) free_fmodifiers(&fcu->modifiers); /* restore driver */ - fcu->driver= driver; + fcu->driver = driver; } diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index a7f01393a02..fda078f5c42 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -60,10 +60,10 @@ #include "BKE_curve.h" #include "BKE_displist.h" -static ListBase ttfdata= {NULL, NULL}; +static ListBase ttfdata = {NULL, NULL}; /* The vfont code */ -void free_vfont(struct VFont *vf) +void BKE_vfont_free(struct VFont *vf) { if (vf == NULL) return; @@ -90,13 +90,13 @@ void free_vfont(struct VFont *vf) } } -static void *builtin_font_data= NULL; -static int builtin_font_size= 0; +static void *builtin_font_data = NULL; +static int builtin_font_size = 0; -void BKE_font_register_builtin(void *mem, int size) +void BKE_vfont_builtin_register(void *mem, int size) { - builtin_font_data= mem; - builtin_font_size= size; + builtin_font_data = mem; + builtin_font_size = size; } static PackedFile *get_builtin_packedfile(void) @@ -107,7 +107,7 @@ static PackedFile *get_builtin_packedfile(void) return NULL; } else { - void *mem= MEM_mallocN(builtin_font_size, "vfd_builtin"); + void *mem = MEM_mallocN(builtin_font_size, "vfd_builtin"); memcpy(mem, builtin_font_data, builtin_font_size); @@ -115,23 +115,23 @@ static PackedFile *get_builtin_packedfile(void) } } -void free_ttfont(void) +void BKE_vfont_free_global_ttf(void) { struct TmpFont *tf; - for (tf= ttfdata.first; tf; tf= tf->next) { - if (tf->pf) freePackedFile(tf->pf); /* NULL when the font file can't be found on disk */ - tf->pf= NULL; - tf->vfont= NULL; + for (tf = ttfdata.first; tf; tf = tf->next) { + if (tf->pf) freePackedFile(tf->pf); /* NULL when the font file can't be found on disk */ + tf->pf = NULL; + tf->vfont = NULL; } BLI_freelistN(&ttfdata); } -struct TmpFont *vfont_find_tmpfont(VFont *vfont) +struct TmpFont *BKE_vfont_find_tmpfont(VFont *vfont) { struct TmpFont *tmpfnt = NULL; - if (vfont==NULL) return NULL; + if (vfont == NULL) return NULL; // Try finding the font from font list tmpfnt = ttfdata.first; @@ -148,46 +148,46 @@ static VFontData *vfont_get_data(Main *bmain, VFont *vfont) struct TmpFont *tmpfnt = NULL; PackedFile *tpf; - if (vfont==NULL) return NULL; + if (vfont == NULL) return NULL; // Try finding the font from font list - tmpfnt = vfont_find_tmpfont(vfont); + tmpfnt = BKE_vfont_find_tmpfont(vfont); // And then set the data if (!vfont->data) { PackedFile *pf; - if (strcmp(vfont->name, FO_BUILTIN_NAME)==0) { - pf= get_builtin_packedfile(); + if (strcmp(vfont->name, FO_BUILTIN_NAME) == 0) { + pf = get_builtin_packedfile(); } else { if (vfont->packedfile) { - pf= vfont->packedfile; + pf = vfont->packedfile; // We need to copy a tmp font to memory unless it is already there if (!tmpfnt) { - tpf= MEM_callocN(sizeof(*tpf), "PackedFile"); - tpf->data= MEM_mallocN(pf->size, "packFile"); - tpf->size= pf->size; + tpf = MEM_callocN(sizeof(*tpf), "PackedFile"); + tpf->data = MEM_mallocN(pf->size, "packFile"); + tpf->size = pf->size; memcpy(tpf->data, pf->data, pf->size); // Add temporary packed file to globals - tmpfnt= (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font"); - tmpfnt->pf= tpf; - tmpfnt->vfont= vfont; + tmpfnt = (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font"); + tmpfnt->pf = tpf; + tmpfnt->vfont = vfont; BLI_addtail(&ttfdata, tmpfnt); } } else { - pf= newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id)); + pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id)); if (!tmpfnt) { - tpf= newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id)); + tpf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id)); // Add temporary packed file to globals - tmpfnt= (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font"); - tmpfnt->pf= tpf; - tmpfnt->vfont= vfont; + tmpfnt = (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font"); + tmpfnt->pf = tpf; + tmpfnt->vfont = vfont; BLI_addtail(&ttfdata, tmpfnt); } } @@ -195,12 +195,12 @@ static VFontData *vfont_get_data(Main *bmain, VFont *vfont) printf("Font file doesn't exist: %s\n", vfont->name); strcpy(vfont->name, FO_BUILTIN_NAME); - pf= get_builtin_packedfile(); + pf = get_builtin_packedfile(); } } if (pf) { - vfont->data= BLI_vfontdata_from_freetypefont(pf); + vfont->data = BLI_vfontdata_from_freetypefont(pf); if (pf != vfont->packedfile) { freePackedFile(pf); } @@ -210,20 +210,20 @@ static VFontData *vfont_get_data(Main *bmain, VFont *vfont) return vfont->data; } -VFont *load_vfont(Main *bmain, const char *name) +VFont *BKE_vfont_load(Main *bmain, const char *name) { char filename[FILE_MAXFILE]; - VFont *vfont= NULL; + VFont *vfont = NULL; PackedFile *pf; PackedFile *tpf = NULL; int is_builtin; struct TmpFont *tmpfnt; - if (strcmp(name, FO_BUILTIN_NAME)==0) { + if (strcmp(name, FO_BUILTIN_NAME) == 0) { BLI_strncpy(filename, name, sizeof(filename)); - pf= get_builtin_packedfile(); - is_builtin= 1; + pf = get_builtin_packedfile(); + is_builtin = 1; } else { char dir[FILE_MAXDIR]; @@ -231,23 +231,23 @@ VFont *load_vfont(Main *bmain, const char *name) BLI_strncpy(dir, name, sizeof(dir)); BLI_splitdirstring(dir, filename); - pf= newPackedFile(NULL, name, bmain->name); - tpf= newPackedFile(NULL, name, bmain->name); + pf = newPackedFile(NULL, name, bmain->name); + tpf = newPackedFile(NULL, name, bmain->name); - is_builtin= 0; + is_builtin = 0; } if (pf) { VFontData *vfd; - vfd= BLI_vfontdata_from_freetypefont(pf); + vfd = BLI_vfontdata_from_freetypefont(pf); if (vfd) { - vfont = alloc_libblock(&bmain->vfont, ID_VF, filename); + vfont = BKE_libblock_alloc(&bmain->vfont, ID_VF, filename); vfont->data = vfd; /* if there's a font name, use it for the ID name */ if (vfd->name[0] != '\0') { - BLI_strncpy(vfont->id.name+2, vfd->name, sizeof(vfont->id.name)-2); + BLI_strncpy(vfont->id.name + 2, vfd->name, sizeof(vfont->id.name) - 2); } BLI_strncpy(vfont->name, name, sizeof(vfont->name)); @@ -258,9 +258,9 @@ VFont *load_vfont(Main *bmain, const char *name) // Do not add FO_BUILTIN_NAME to temporary listbase if (strcmp(filename, FO_BUILTIN_NAME)) { - tmpfnt= (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font"); - tmpfnt->pf= tpf; - tmpfnt->vfont= vfont; + tmpfnt = (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font"); + tmpfnt->pf = tpf; + tmpfnt->vfont = vfont; BLI_addtail(&ttfdata, tmpfnt); } } @@ -278,32 +278,32 @@ VFont *load_vfont(Main *bmain, const char *name) static VFont *which_vfont(Curve *cu, CharInfo *info) { - switch (info->flag & (CU_CHINFO_BOLD|CU_CHINFO_ITALIC)) { + switch (info->flag & (CU_CHINFO_BOLD | CU_CHINFO_ITALIC)) { case CU_CHINFO_BOLD: if (cu->vfontb) return(cu->vfontb); else return(cu->vfont); case CU_CHINFO_ITALIC: if (cu->vfonti) return(cu->vfonti); else return(cu->vfont); - case (CU_CHINFO_BOLD|CU_CHINFO_ITALIC): + case (CU_CHINFO_BOLD | CU_CHINFO_ITALIC): if (cu->vfontbi) return(cu->vfontbi); else return(cu->vfont); default: return(cu->vfont); } } -VFont *get_builtin_font(void) +VFont *BKE_vfont_builtin_get(void) { VFont *vf; - for (vf= G.main->vfont.first; vf; vf= vf->id.next) - if (strcmp(vf->name, FO_BUILTIN_NAME)==0) + for (vf = G.main->vfont.first; vf; vf = vf->id.next) + if (strcmp(vf->name, FO_BUILTIN_NAME) == 0) return vf; - return load_vfont(G.main, FO_BUILTIN_NAME); + return BKE_vfont_load(G.main, FO_BUILTIN_NAME); } static VChar *find_vfont_char(VFontData *vfd, intptr_t character) { - VChar *che= NULL; + VChar *che = NULL; for (che = vfd->characters.first; che; che = che->next) { if (che->index == character) @@ -317,21 +317,21 @@ static void build_underline(Curve *cu, float x1, float y1, float x2, float y2, i Nurb *nu2; BPoint *bp; - nu2 =(Nurb*) MEM_callocN(sizeof(Nurb), "underline_nurb"); + nu2 = (Nurb *) MEM_callocN(sizeof(Nurb), "underline_nurb"); if (nu2 == NULL) return; - nu2->resolu= cu->resolu; + nu2->resolu = cu->resolu; nu2->bezt = NULL; nu2->knotsu = nu2->knotsv = NULL; - nu2->flag= CU_2D; - nu2->charidx = charidx+1000; - if (mat_nr > 0) nu2->mat_nr= mat_nr-1; + nu2->flag = CU_2D; + nu2->charidx = charidx + 1000; + if (mat_nr > 0) nu2->mat_nr = mat_nr - 1; nu2->pntsu = 4; nu2->pntsv = 1; nu2->orderu = 4; nu2->orderv = 1; nu2->flagu = CU_NURB_CYCLIC; - bp = (BPoint*)MEM_callocN(4 * sizeof(BPoint), "underline_bp"); + bp = (BPoint *)MEM_callocN(4 * sizeof(BPoint), "underline_bp"); if (bp == NULL) { MEM_freeN(nu2); return; @@ -368,27 +368,27 @@ static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo VChar *che = NULL; int i; - vfd= vfont_get_data(bmain, which_vfont(cu, info)); + vfd = vfont_get_data(bmain, which_vfont(cu, info)); if (!vfd) return; #if 0 if (cu->selend < cu->selstart) { - if ((charidx >= (cu->selend)) && (charidx <= (cu->selstart-2))) - sel= 1; + if ((charidx >= (cu->selend)) && (charidx <= (cu->selstart - 2))) + sel = 1; } else { - if ((charidx >= (cu->selstart-1)) && (charidx <= (cu->selend-1))) - sel= 1; + if ((charidx >= (cu->selstart - 1)) && (charidx <= (cu->selend - 1))) + sel = 1; } #endif /* make a copy at distance ofsx, ofsy with shear*/ - fsize= cu->fsize; - shear= cu->shear; - si= (float)sin(rot); - co= (float)cos(rot); + fsize = cu->fsize; + shear = cu->shear; + si = (float)sin(rot); + co = (float)cos(rot); - che= find_vfont_char(vfd, character); + che = find_vfont_char(vfd, character); // Select the glyph data if (che) @@ -398,25 +398,25 @@ static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo while (nu1) { bezt1 = nu1->bezt; if (bezt1) { - nu2 =(Nurb*) MEM_mallocN(sizeof(Nurb), "duplichar_nurb"); + nu2 = (Nurb *) MEM_mallocN(sizeof(Nurb), "duplichar_nurb"); if (nu2 == NULL) break; memcpy(nu2, nu1, sizeof(struct Nurb)); - nu2->resolu= cu->resolu; + nu2->resolu = cu->resolu; nu2->bp = NULL; nu2->knotsu = nu2->knotsv = NULL; - nu2->flag= CU_SMOOTH; + nu2->flag = CU_SMOOTH; nu2->charidx = charidx; if (info->mat_nr > 0) { - nu2->mat_nr= info->mat_nr-1; + nu2->mat_nr = info->mat_nr - 1; } else { - nu2->mat_nr= 0; + nu2->mat_nr = 0; } /* nu2->trim.first = 0; */ /* nu2->trim.last = 0; */ i = nu2->pntsu; - bezt2 = (BezTriple*)MEM_mallocN(i * sizeof(BezTriple), "duplichar_bezt2"); + bezt2 = (BezTriple *)MEM_mallocN(i * sizeof(BezTriple), "duplichar_bezt2"); if (bezt2 == NULL) { MEM_freeN(nu2); break; @@ -427,7 +427,7 @@ static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo if (shear != 0.0f) { bezt2 = nu2->bezt; - for (i= nu2->pntsu; i > 0; i--) { + for (i = nu2->pntsu; i > 0; i--) { bezt2->vec[0][0] += shear * bezt2->vec[0][1]; bezt2->vec[1][0] += shear * bezt2->vec[1][1]; bezt2->vec[2][0] += shear * bezt2->vec[2][1]; @@ -435,19 +435,19 @@ static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo } } if (rot != 0.0f) { - bezt2= nu2->bezt; - for (i=nu2->pntsu; i > 0; i--) { - fp= bezt2->vec[0]; - - x= fp[0]; - fp[0]= co*x + si*fp[1]; - fp[1]= -si*x + co*fp[1]; - x= fp[3]; - fp[3]= co*x + si*fp[4]; - fp[4]= -si*x + co*fp[4]; - x= fp[6]; - fp[6]= co*x + si*fp[7]; - fp[7]= -si*x + co*fp[7]; + bezt2 = nu2->bezt; + for (i = nu2->pntsu; i > 0; i--) { + fp = bezt2->vec[0]; + + x = fp[0]; + fp[0] = co * x + si * fp[1]; + fp[1] = -si * x + co * fp[1]; + x = fp[3]; + fp[3] = co * x + si * fp[4]; + fp[4] = -si * x + co * fp[4]; + x = fp[6]; + fp[6] = co * x + si * fp[7]; + fp[7] = -si * x + co * fp[7]; bezt2++; } @@ -455,9 +455,9 @@ static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo bezt2 = nu2->bezt; if (info->flag & CU_CHINFO_SMALLCAPS_CHECK) { - const float sca= cu->smallcaps_scale; - for (i= nu2->pntsu; i > 0; i--) { - fp= bezt2->vec[0]; + const float sca = cu->smallcaps_scale; + for (i = nu2->pntsu; i > 0; i--) { + fp = bezt2->vec[0]; fp[0] *= sca; fp[1] *= sca; fp[3] *= sca; @@ -469,14 +469,14 @@ static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo } bezt2 = nu2->bezt; - for (i= nu2->pntsu; i > 0; i--) { - fp= bezt2->vec[0]; - fp[0]= (fp[0]+ofsx)*fsize; - fp[1]= (fp[1]+ofsy)*fsize; - fp[3]= (fp[3]+ofsx)*fsize; - fp[4]= (fp[4]+ofsy)*fsize; - fp[6]= (fp[6]+ofsx)*fsize; - fp[7]= (fp[7]+ofsy)*fsize; + for (i = nu2->pntsu; i > 0; i--) { + fp = bezt2->vec[0]; + fp[0] = (fp[0] + ofsx) * fsize; + fp[1] = (fp[1] + ofsy) * fsize; + fp[3] = (fp[3] + ofsx) * fsize; + fp[4] = (fp[4] + ofsy) * fsize; + fp[6] = (fp[6] + ofsx) * fsize; + fp[7] = (fp[7] + ofsy) * fsize; bezt2++; } @@ -487,21 +487,21 @@ static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo } } -int BKE_font_getselection(Object *ob, int *start, int *end) +int BKE_vfont_select_get(Object *ob, int *start, int *end) { - Curve *cu= ob->data; + Curve *cu = ob->data; - if (cu->editfont==NULL || ob->type != OB_FONT) return 0; + if (cu->editfont == NULL || ob->type != OB_FONT) return 0; if (cu->selstart == 0) return 0; if (cu->selstart <= cu->selend) { - *start = cu->selstart-1; - *end = cu->selend-1; + *start = cu->selstart - 1; + *end = cu->selend - 1; return 1; } else { *start = cu->selend; - *end = cu->selstart-2; + *end = cu->selstart - 2; return -1; } } @@ -520,32 +520,31 @@ static float char_width(Curve *cu, VChar *che, CharInfo *info) } } -struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int mode) -{ +struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int mode){ VFont *vfont, *oldvfont; - VFontData *vfd= NULL; + VFontData *vfd = NULL; Curve *cu; CharInfo *info = NULL, *custrinfo; TextBox *tb; VChar *che; - struct chartrans *chartransdata=NULL, *ct; + struct chartrans *chartransdata = NULL, *ct; float *f, xof, yof, xtrax, linedist, *linedata, *linedata2, *linedata3, *linedata4; - float twidth, maxlen= 0; + float twidth, maxlen = 0; int i, slen, j; int curbox; int selstart, selend; int utf8len; - short cnr=0, lnr=0, wsnr= 0; + short cnr = 0, lnr = 0, wsnr = 0; wchar_t *mem, *tmp, ascii; /* renark: do calculations including the trailing '\0' of a string * because the cursor can be at that location */ - if (ob->type!=OB_FONT) return NULL; + if (ob->type != OB_FONT) return NULL; // Set font data - cu= (Curve *) ob->data; - vfont= cu->vfont; + cu = (Curve *) ob->data; + vfont = cu->vfont; if (cu->str == NULL) return NULL; if (vfont == NULL) return NULL; @@ -562,17 +561,17 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m 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"); + if (cu->strinfo == NULL) /* old file */ + cu->strinfo = MEM_callocN((slen + 4) * sizeof(CharInfo), "strinfo compat"); - custrinfo= cu->strinfo; + custrinfo = cu->strinfo; if (cu->editfont) - custrinfo= cu->editfont->textbufinfo; + custrinfo = cu->editfont->textbufinfo; - if (cu->tb==NULL) - cu->tb= MEM_callocN(MAXTEXTBOX*sizeof(TextBox), "TextBox compat"); + if (cu->tb == NULL) + cu->tb = MEM_callocN(MAXTEXTBOX * sizeof(TextBox), "TextBox compat"); - vfd= vfont_get_data(bmain, vfont); + vfd = vfont_get_data(bmain, vfont); /* The VFont Data can not be found */ if (!vfd) { @@ -583,7 +582,7 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m /* calc offset and rotation of each char */ ct = chartransdata = - (struct chartrans*)MEM_callocN((slen+1)* sizeof(struct chartrans), "buildtext"); + (struct chartrans *)MEM_callocN((slen + 1) * sizeof(struct chartrans), "buildtext"); /* We assume the worst case: 1 character per line (is freed at end anyway) */ @@ -592,57 +591,57 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m linedata3 = MEM_callocN(sizeof(float) * (slen * 2 + 1), "buildtext4"); linedata4 = MEM_callocN(sizeof(float) * (slen * 2 + 1), "buildtext5"); - linedist= cu->linedist; + linedist = cu->linedist; - xof= cu->xof + (cu->tb[0].x/cu->fsize); - yof= cu->yof + (cu->tb[0].y/cu->fsize); + xof = cu->xof + (cu->tb[0].x / cu->fsize); + yof = cu->yof + (cu->tb[0].y / cu->fsize); - xtrax= 0.5f*cu->spacing-0.5f; + xtrax = 0.5f * cu->spacing - 0.5f; oldvfont = NULL; - for (i=0; i<slen; i++) custrinfo[i].flag &= ~(CU_CHINFO_WRAP|CU_CHINFO_SMALLCAPS_CHECK); + for (i = 0; i < slen; i++) custrinfo[i].flag &= ~(CU_CHINFO_WRAP | CU_CHINFO_SMALLCAPS_CHECK); if (cu->selboxes) MEM_freeN(cu->selboxes); cu->selboxes = NULL; - if (BKE_font_getselection(ob, &selstart, &selend)) - cu->selboxes = MEM_callocN((selend-selstart+1)*sizeof(SelBox), "font selboxes"); + if (BKE_vfont_select_get(ob, &selstart, &selend)) + cu->selboxes = MEM_callocN((selend - selstart + 1) * sizeof(SelBox), "font selboxes"); tb = &(cu->tb[0]); - curbox= 0; - for (i = 0 ; i<=slen ; i++) { - makebreak: + curbox = 0; + for (i = 0; i <= slen; i++) { +makebreak: // Characters in the list info = &(custrinfo[i]); ascii = mem[i]; if (info->flag & CU_CHINFO_SMALLCAPS) { ascii = towupper(ascii); if (mem[i] != ascii) { - mem[i]= ascii; + mem[i] = ascii; info->flag |= CU_CHINFO_SMALLCAPS_CHECK; } } vfont = which_vfont(cu, info); - if (vfont==NULL) break; + if (vfont == NULL) break; - che= find_vfont_char(vfd, ascii); + che = find_vfont_char(vfd, ascii); /* * The character wasn't in the current curve base so load it * But if the font is FO_BUILTIN_NAME then do not try loading since * whole font is in the memory already */ - if (che == NULL && strcmp(vfont->name, FO_BUILTIN_NAME)) { + if (che == NULL && strcmp(vfont->name, FO_BUILTIN_NAME)) { BLI_vfontchar_from_freetypefont(vfont, ascii); } /* Try getting the character again from the list */ - che= find_vfont_char(vfd, ascii); + che = find_vfont_char(vfd, ascii); /* No VFont found */ - if (vfont==NULL) { + if (vfont == NULL) { if (mem) MEM_freeN(mem); MEM_freeN(chartransdata); @@ -650,7 +649,7 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m } if (vfont != oldvfont) { - vfd= vfont_get_data(bmain, vfont); + vfd = vfont_get_data(bmain, vfont); oldvfont = vfont; } @@ -665,24 +664,24 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m twidth = char_width(cu, che, info); // Calculate positions - 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]=='-') { - ct -= (i-(j-1)); - cnr -= (i-(j-1)); + 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] == '-') { + ct -= (i - (j - 1)); + cnr -= (i - (j - 1)); if (mem[j] == ' ') wsnr--; if (mem[j] == '-') wsnr++; - i = j-1; + i = j - 1; xof = ct->xof; ct[1].dobreak = 1; - custrinfo[i+1].flag |= CU_CHINFO_WRAP; + custrinfo[i + 1].flag |= CU_CHINFO_WRAP; goto makebreak; } if (chartransdata[j].dobreak) { - // fprintf(stderr, "word too long: %c%c%c...\n", mem[j], mem[j+1], mem[j+2]); - ct->dobreak= 1; - custrinfo[i+1].flag |= CU_CHINFO_WRAP; + // fprintf(stderr, "word too long: %c%c%c...\n", mem[j], mem[j+1], mem[j+2]); + ct->dobreak = 1; + custrinfo[i + 1].flag |= CU_CHINFO_WRAP; ct -= 1; cnr -= 1; i--; @@ -691,27 +690,27 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m } } } - if (ascii== '\n' || ascii== '\r' || ascii==0 || ct->dobreak) { - ct->xof= xof; - ct->yof= yof; - ct->linenr= lnr; - ct->charnr= cnr; - - yof-= linedist; - - maxlen= MAX2(maxlen, (xof-tb->x/cu->fsize)); - linedata[lnr]= xof-tb->x/cu->fsize; - linedata2[lnr]= cnr; - linedata3[lnr]= tb->w/cu->fsize; - linedata4[lnr]= wsnr; + if (ascii == '\n' || ascii == '\r' || ascii == 0 || ct->dobreak) { + ct->xof = xof; + ct->yof = yof; + ct->linenr = lnr; + ct->charnr = cnr; + + yof -= linedist; + + maxlen = MAX2(maxlen, (xof - tb->x / cu->fsize)); + linedata[lnr] = xof - tb->x / cu->fsize; + linedata2[lnr] = cnr; + linedata3[lnr] = tb->w / cu->fsize; + linedata4[lnr] = wsnr; 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; + ((-(yof - (tb->y / cu->fsize))) > ((tb->h / cu->fsize) - (linedist * cu->fsize)) - cu->yof) && + (cu->totbox > (curbox + 1)) ) { + maxlen = 0; tb++; curbox++; - yof= cu->yof + tb->y/cu->fsize; + yof = cu->yof + tb->y / cu->fsize; } /* XXX, has been unused for years, need to check if this is useful, r4613 r5282 - campbell */ @@ -719,43 +718,43 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m if (ascii == '\n' || ascii == '\r') xof = cu->xof; else - xof= cu->xof + (tb->x/cu->fsize); + xof = cu->xof + (tb->x / cu->fsize); #else - xof= cu->xof + (tb->x/cu->fsize); + xof = cu->xof + (tb->x / cu->fsize); #endif lnr++; - cnr= 0; - wsnr= 0; + cnr = 0; + wsnr = 0; } - else if (ascii==9) { /* TAB */ + else if (ascii == 9) { /* TAB */ float tabfac; - ct->xof= xof; - ct->yof= yof; - ct->linenr= lnr; - ct->charnr= cnr++; - - tabfac= (xof-cu->xof+0.01f); - tabfac= 2.0f*ceilf(tabfac/2.0f); - xof= cu->xof+tabfac; + ct->xof = xof; + ct->yof = yof; + ct->linenr = lnr; + ct->charnr = cnr++; + + tabfac = (xof - cu->xof + 0.01f); + tabfac = 2.0f * ceilf(tabfac / 2.0f); + xof = cu->xof + tabfac; } else { - SelBox *sb= NULL; + SelBox *sb = NULL; float wsfac; - ct->xof= xof; - ct->yof= yof; - ct->linenr= lnr; - ct->charnr= cnr++; + ct->xof = xof; + ct->yof = yof; + ct->linenr = lnr; + ct->charnr = cnr++; - if (cu->selboxes && (i>=selstart) && (i<=selend)) { - sb = &(cu->selboxes[i-selstart]); - sb->y = yof*cu->fsize-linedist*cu->fsize*0.1f; - sb->h = linedist*cu->fsize; - sb->w = xof*cu->fsize; + if (cu->selboxes && (i >= selstart) && (i <= selend)) { + sb = &(cu->selboxes[i - selstart]); + sb->y = yof * cu->fsize - linedist * cu->fsize * 0.1f; + sb->h = linedist * cu->fsize; + sb->w = xof * cu->fsize; } - if (ascii==32) { + if (ascii == 32) { wsfac = cu->wordspace; wsnr++; } @@ -764,20 +763,20 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m // Set the width of the character twidth = char_width(cu, che, info); - xof += (twidth*wsfac*(1.0f+(info->kern/40.0f)) ) + xtrax; + xof += (twidth * wsfac * (1.0f + (info->kern / 40.0f)) ) + xtrax; if (sb) - sb->w = (xof*cu->fsize) - sb->w; + sb->w = (xof * cu->fsize) - sb->w; } ct++; } - cu->lines= 1; - ct= chartransdata; + cu->lines = 1; + ct = chartransdata; tmp = mem; - for (i= 0; i<=slen; i++, tmp++, ct++) { + for (i = 0; i <= slen; i++, tmp++, ct++) { ascii = *tmp; - if (ascii== '\n' || ascii== '\r' || ct->dobreak) cu->lines++; + if (ascii == '\n' || ascii == '\r' || ct->dobreak) cu->lines++; } // linedata is now: width of line @@ -785,55 +784,55 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m // linedata3 is now: maxlen of that line // linedata4 is now: number of whitespaces of line - if (cu->spacemode!=CU_LEFT) { - ct= chartransdata; + if (cu->spacemode != CU_LEFT) { + ct = chartransdata; - if (cu->spacemode==CU_RIGHT) { - for (i=0;i<lnr;i++) linedata[i]= linedata3[i]-linedata[i]; - for (i=0; i<=slen; i++) { - ct->xof+= linedata[ct->linenr]; + if (cu->spacemode == CU_RIGHT) { + for (i = 0; i < lnr; i++) linedata[i] = linedata3[i] - linedata[i]; + for (i = 0; i <= slen; i++) { + ct->xof += linedata[ct->linenr]; ct++; } } - else if (cu->spacemode==CU_MIDDLE) { - for (i=0;i<lnr;i++) linedata[i]= (linedata3[i]-linedata[i])/2; - for (i=0; i<=slen; i++) { - ct->xof+= linedata[ct->linenr]; + else if (cu->spacemode == CU_MIDDLE) { + for (i = 0; i < lnr; i++) linedata[i] = (linedata3[i] - linedata[i]) / 2; + for (i = 0; i <= slen; i++) { + ct->xof += linedata[ct->linenr]; ct++; } } - else if ((cu->spacemode==CU_FLUSH) && - (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); - for (i=0; i<=slen; i++) { - for (j=i; (!ELEM3(mem[j], '\0', '\n', '\r')) && (chartransdata[j].dobreak == 0) && (j < slen); j++) { + else if ((cu->spacemode == CU_FLUSH) && + (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); + for (i = 0; i <= slen; i++) { + for (j = i; (!ELEM3(mem[j], '\0', '\n', '\r')) && (chartransdata[j].dobreak == 0) && (j < slen); j++) { /* do nothing */ } // if ((mem[j]!='\r') && (mem[j]!='\n') && (mem[j])) { - ct->xof+= ct->charnr*linedata[ct->linenr]; + ct->xof += ct->charnr * linedata[ct->linenr]; // } ct++; } } - else if ((cu->spacemode==CU_JUSTIFY) && (cu->tb[0].w != 0.0f)) { + 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') && - (mem[j] != '\r') && (chartransdata[j].dobreak == 0) && (j < slen); + for (j = i; (mem[j]) && (mem[j] != '\n') && + (mem[j] != '\r') && (chartransdata[j].dobreak == 0) && (j < slen); j++) { /* pass */ } - if ((mem[j]!='\r') && (mem[j]!='\n') && - ((chartransdata[j].dobreak!=0))) { - if (mem[i]==' ') curofs += (linedata3[ct->linenr]-linedata[ct->linenr])/linedata4[ct->linenr]; - ct->xof+= curofs; + if ((mem[j] != '\r') && (mem[j] != '\n') && + ((chartransdata[j].dobreak != 0))) { + if (mem[i] == ' ') curofs += (linedata3[ct->linenr] - linedata[ct->linenr]) / linedata4[ct->linenr]; + ct->xof += curofs; } - if (mem[i]=='\n' || mem[i]=='\r' || chartransdata[i].dobreak) curofs= 0; + if (mem[i] == '\n' || mem[i] == '\r' || chartransdata[i].dobreak) curofs = 0; ct++; } } @@ -841,13 +840,13 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m /* TEXT ON CURVE */ /* Note: Only OB_CURVE objects could have a path */ - if (cu->textoncurve && cu->textoncurve->type==OB_CURVE) { - Curve *cucu= cu->textoncurve->data; - int oldflag= cucu->flag; + if (cu->textoncurve && cu->textoncurve->type == OB_CURVE) { + Curve *cucu = cu->textoncurve->data; + int oldflag = cucu->flag; - cucu->flag |= (CU_PATH+CU_FOLLOW); + cucu->flag |= (CU_PATH + CU_FOLLOW); - if (cucu->path==NULL) makeDispListCurveTypes(scene, cu->textoncurve, 0); + if (cucu->path == NULL) BKE_displist_make_curveTypes(scene, cu->textoncurve, 0); if (cucu->path) { float distfac, imat[4][4], imat3[3][3], cmat[3][3]; float minx, maxx, miny, maxy; @@ -858,116 +857,116 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m copy_m3_m4(cmat, cu->textoncurve->obmat); mul_m3_m3m3(cmat, cmat, imat3); - sizefac= normalize_v3(cmat[0])/cu->fsize; + sizefac = normalize_v3(cmat[0]) / cu->fsize; - minx=miny= 1.0e20f; - maxx=maxy= -1.0e20f; - ct= chartransdata; - for (i=0; i<=slen; i++, ct++) { - if (minx>ct->xof) minx= ct->xof; - if (maxx<ct->xof) maxx= ct->xof; - if (miny>ct->yof) miny= ct->yof; - if (maxy<ct->yof) maxy= ct->yof; + minx = miny = 1.0e20f; + maxx = maxy = -1.0e20f; + ct = chartransdata; + for (i = 0; i <= slen; i++, ct++) { + if (minx > ct->xof) minx = ct->xof; + if (maxx < ct->xof) maxx = ct->xof; + if (miny > ct->yof) miny = ct->yof; + if (maxy < ct->yof) maxy = ct->yof; } /* we put the x-coordinaat exact at the curve, the y is rotated */ /* length correction */ - distfac= sizefac*cucu->path->totdist/(maxx-minx); - timeofs= 0.0f; + distfac = sizefac * cucu->path->totdist / (maxx - minx); + timeofs = 0.0f; if (distfac > 1.0f) { /* path longer than text: spacemode involves */ - distfac= 1.0f/distfac; + distfac = 1.0f / distfac; - if (cu->spacemode==CU_RIGHT) { - timeofs= 1.0f-distfac; + if (cu->spacemode == CU_RIGHT) { + timeofs = 1.0f - distfac; } - else if (cu->spacemode==CU_MIDDLE) { - timeofs= (1.0f-distfac)/2.0f; + else if (cu->spacemode == CU_MIDDLE) { + timeofs = (1.0f - distfac) / 2.0f; } - else if (cu->spacemode==CU_FLUSH) distfac= 1.0f; + else if (cu->spacemode == CU_FLUSH) distfac = 1.0f; } - else distfac= 1.0; + else distfac = 1.0; - distfac/= (maxx-minx); + distfac /= (maxx - minx); - timeofs+= distfac*cu->xof; /* not cyclic */ + timeofs += distfac * cu->xof; /* not cyclic */ - ct= chartransdata; - for (i=0; i<=slen; i++, ct++) { + ct = chartransdata; + for (i = 0; i <= slen; i++, ct++) { float ctime, dtime, vec[4], tvec[4], rotvec[3]; float si, co; /* rotate around center character */ ascii = mem[i]; - che= find_vfont_char(vfd, ascii); + che = find_vfont_char(vfd, ascii); twidth = char_width(cu, che, info); - dtime= distfac*0.5f*twidth; + dtime = distfac * 0.5f * twidth; - ctime= timeofs + distfac*( ct->xof - minx); + ctime = timeofs + distfac * (ct->xof - minx); CLAMP(ctime, 0.0f, 1.0f); /* calc the right loc AND the right rot separately */ /* vec, tvec need 4 items */ where_on_path(cu->textoncurve, ctime, vec, tvec, NULL, NULL, NULL); - where_on_path(cu->textoncurve, ctime+dtime, tvec, rotvec, NULL, NULL, NULL); + where_on_path(cu->textoncurve, ctime + dtime, tvec, rotvec, NULL, NULL, NULL); mul_v3_fl(vec, sizefac); - ct->rot= (float)(M_PI-atan2(rotvec[1], rotvec[0])); + ct->rot = (float)(M_PI - atan2(rotvec[1], rotvec[0])); - si= (float)sin(ct->rot); - co= (float)cos(ct->rot); + si = (float)sin(ct->rot); + co = (float)cos(ct->rot); - yof= ct->yof; + yof = ct->yof; - ct->xof= vec[0] + si*yof; - ct->yof= vec[1] + co*yof; + ct->xof = vec[0] + si * yof; + ct->yof = vec[1] + co * yof; } - cucu->flag= oldflag; + cucu->flag = oldflag; } } if (cu->selboxes) { - ct= chartransdata; - for (i=0; i<=selend; i++, ct++) { - if (i>=selstart) { - cu->selboxes[i-selstart].x = ct->xof*cu->fsize; - cu->selboxes[i-selstart].y = ct->yof*cu->fsize; + ct = chartransdata; + for (i = 0; i <= selend; i++, ct++) { + if (i >= selstart) { + cu->selboxes[i - selstart].x = ct->xof * cu->fsize; + cu->selboxes[i - selstart].y = ct->yof * cu->fsize; } } } - if (mode==FO_CURSUP || mode==FO_CURSDOWN || mode==FO_PAGEUP || mode==FO_PAGEDOWN) { + if (mode == FO_CURSUP || mode == FO_CURSDOWN || mode == FO_PAGEUP || mode == FO_PAGEDOWN) { /* 2: curs up * 3: curs down */ - ct= chartransdata+cu->pos; + ct = chartransdata + cu->pos; - if ((mode==FO_CURSUP || mode==FO_PAGEUP) && ct->linenr==0); - else if ((mode==FO_CURSDOWN || mode==FO_PAGEDOWN) && ct->linenr==lnr); + if ((mode == FO_CURSUP || mode == FO_PAGEUP) && ct->linenr == 0) ; + else if ((mode == FO_CURSDOWN || mode == FO_PAGEDOWN) && ct->linenr == lnr) ; else { switch (mode) { - case FO_CURSUP: lnr= ct->linenr-1; break; - case FO_CURSDOWN: lnr= ct->linenr+1; break; - case FO_PAGEUP: lnr= ct->linenr-10; break; - case FO_PAGEDOWN: lnr= ct->linenr+10; break; + case FO_CURSUP: lnr = ct->linenr - 1; break; + case FO_CURSDOWN: lnr = ct->linenr + 1; break; + case FO_PAGEUP: lnr = ct->linenr - 10; break; + case FO_PAGEDOWN: lnr = ct->linenr + 10; break; } - cnr= ct->charnr; + cnr = ct->charnr; /* seek for char with lnr en cnr */ - cu->pos= 0; - ct= chartransdata; - for (i= 0; i<slen; i++) { - if (ct->linenr==lnr) { - if (ct->charnr==cnr) break; - if ( (ct+1)->charnr==0) break; + cu->pos = 0; + ct = chartransdata; + for (i = 0; i < slen; i++) { + if (ct->linenr == lnr) { + if (ct->charnr == cnr) break; + if ( (ct + 1)->charnr == 0) break; } - else if (ct->linenr>lnr) break; + else if (ct->linenr > lnr) break; cu->pos++; ct++; } @@ -978,23 +977,23 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m if (cu->editfont) { float si, co; - ct= chartransdata+cu->pos; - si= (float)sin(ct->rot); - co= (float)cos(ct->rot); + ct = chartransdata + cu->pos; + si = (float)sin(ct->rot); + co = (float)cos(ct->rot); - f= cu->editfont->textcurs[0]; + f = cu->editfont->textcurs[0]; - f[0]= cu->fsize*(-0.1f*co + ct->xof); - f[1]= cu->fsize*(0.1f*si + ct->yof); + f[0] = cu->fsize * (-0.1f * co + ct->xof); + f[1] = cu->fsize * (0.1f * si + ct->yof); - f[2]= cu->fsize*(0.1f*co + ct->xof); - f[3]= cu->fsize*(-0.1f*si + ct->yof); + f[2] = cu->fsize * (0.1f * co + ct->xof); + f[3] = cu->fsize * (-0.1f * si + ct->yof); - f[4]= cu->fsize*( 0.1f*co + 0.8f*si + ct->xof); - f[5]= cu->fsize*(-0.1f*si + 0.8f*co + ct->yof); + f[4] = cu->fsize * (0.1f * co + 0.8f * si + ct->xof); + f[5] = cu->fsize * (-0.1f * si + 0.8f * co + ct->yof); - f[6]= cu->fsize*(-0.1f*co + 0.8f*si + ct->xof); - f[7]= cu->fsize*( 0.1f*si + 0.8f*co + ct->yof); + f[6] = cu->fsize * (-0.1f * co + 0.8f * si + ct->xof); + f[7] = cu->fsize * (0.1f * si + 0.8f * co + ct->yof); } @@ -1013,9 +1012,9 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m /* make nurbdata */ BKE_nurbList_free(&cu->nurb); - ct= chartransdata; - if (cu->sepchar==0) { - for (i= 0; i<slen; i++) { + ct = chartransdata; + if (cu->sepchar == 0) { + for (i = 0; i < slen; i++) { unsigned long cha = (uintptr_t) mem[i]; info = &(custrinfo[i]); if (info->mat_nr > (ob->totcol)) { @@ -1027,42 +1026,42 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m buildchar(bmain, cu, cha, info, ct->xof, ct->yof, ct->rot, i); if ((info->flag & CU_CHINFO_UNDERLINE) && (cu->textoncurve == NULL) && (cha != '\n') && (cha != '\r')) { - float ulwidth, uloverlap= 0.0f; + float ulwidth, uloverlap = 0.0f; - 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) - ) { + 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.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); + che = find_vfont_char(vfd, cha); twidth = char_width(cu, che, info); - 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.05f)*cu->fsize - cu->ulheight*cu->fsize, - i, info->mat_nr); + 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.05f) * cu->fsize - cu->ulheight * cu->fsize, + i, info->mat_nr); } ct++; } } else { int outta = 0; - for (i= 0; (i<slen) && (outta==0); i++) { + for (i = 0; (i < slen) && (outta == 0); i++) { ascii = mem[i]; info = &(custrinfo[i]); - if (cu->sepchar == (i+1)) { + if (cu->sepchar == (i + 1)) { float vecyo[3]; - vecyo[0]= ct->xof; - vecyo[1]= ct->yof; - vecyo[2]= 0.0f; + vecyo[0] = ct->xof; + vecyo[1] = ct->yof; + vecyo[2] = 0.0f; mem[0] = ascii; mem[1] = 0; - custrinfo[0]= *info; + custrinfo[0] = *info; cu->pos = 1; cu->len = 1; mul_v3_m4v3(ob->loc, ob->obmat, vecyo); @@ -1074,7 +1073,7 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m } } - if (mode==FO_DUPLI) { + if (mode == FO_DUPLI) { MEM_freeN(mem); return chartransdata; } diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index 9ea4eafdd73..6ec19018ab5 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -62,8 +62,8 @@ void free_gpencil_strokes(bGPDframe *gpf) if (gpf == NULL) return; /* free strokes */ - for (gps= gpf->strokes.first; gps; gps= gpsn) { - gpsn= gps->next; + for (gps = gpf->strokes.first; gps; gps = gpsn) { + gpsn = gps->next; /* free stroke memory arrays, then stroke itself */ if (gps->points) MEM_freeN(gps->points); @@ -80,8 +80,8 @@ void free_gpencil_frames(bGPDlayer *gpl) if (gpl == NULL) return; /* free frames */ - for (gpf= gpl->frames.first; gpf; gpf= gpfn) { - gpfn= gpf->next; + for (gpf = gpl->frames.first; gpf; gpf = gpfn) { + gpfn = gpf->next; /* free strokes and their associated memory */ free_gpencil_strokes(gpf); @@ -98,8 +98,8 @@ void free_gpencil_layers(ListBase *list) if (list == NULL) return; /* delete layers*/ - for (gpl= list->first; gpl; gpl= gpln) { - gpln= gpl->next; + for (gpl = list->first; gpl; gpl = gpln) { + gpln = gpl->next; /* free layers and their data */ free_gpencil_frames(gpl); @@ -108,7 +108,7 @@ void free_gpencil_layers(ListBase *list) } /* Free all of GPencil datablock's related data, but not the block itself */ -void free_gpencil_data(bGPdata *gpd) +void BKE_gpencil_free(bGPdata *gpd) { /* free layers */ free_gpencil_layers(&gpd->layers); @@ -117,32 +117,32 @@ void free_gpencil_data(bGPdata *gpd) /* -------- Container Creation ---------- */ /* add a new gp-frame to the given layer */ -bGPDframe *gpencil_frame_addnew (bGPDlayer *gpl, int cframe) +bGPDframe *gpencil_frame_addnew(bGPDlayer *gpl, int cframe) { bGPDframe *gpf, *gf; - short state=0; + short state = 0; /* error checking */ if ((gpl == NULL) || (cframe <= 0)) return NULL; /* allocate memory for this frame */ - gpf= MEM_callocN(sizeof(bGPDframe), "bGPDframe"); - gpf->framenum= cframe; + gpf = MEM_callocN(sizeof(bGPDframe), "bGPDframe"); + gpf->framenum = cframe; /* find appropriate place to add frame */ if (gpl->frames.first) { - for (gf= gpl->frames.first; gf; gf= gf->next) { + for (gf = gpl->frames.first; gf; gf = gf->next) { /* check if frame matches one that is supposed to be added */ if (gf->framenum == cframe) { - state= -1; + state = -1; break; } /* if current frame has already exceeded the frame to add, add before */ if (gf->framenum > cframe) { BLI_insertlinkbefore(&gpl->frames, gf, gpf); - state= 1; + state = 1; break; } } @@ -163,7 +163,7 @@ bGPDframe *gpencil_frame_addnew (bGPDlayer *gpl, int cframe) } /* add a new gp-layer and make it the active layer */ -bGPDlayer *gpencil_layer_addnew (bGPdata *gpd) +bGPDlayer *gpencil_layer_addnew(bGPdata *gpd) { bGPDlayer *gpl; @@ -172,13 +172,13 @@ bGPDlayer *gpencil_layer_addnew (bGPdata *gpd) return NULL; /* allocate memory for frame and add to end of list */ - gpl= MEM_callocN(sizeof(bGPDlayer), "bGPDlayer"); + gpl = MEM_callocN(sizeof(bGPDlayer), "bGPDlayer"); /* add to datablock */ BLI_addtail(&gpd->layers, gpl); /* set basic settings */ - gpl->color[3]= 0.9f; + gpl->color[3] = 0.9f; gpl->thickness = 3; /* auto-name */ @@ -193,15 +193,15 @@ bGPDlayer *gpencil_layer_addnew (bGPdata *gpd) } /* add a new gp-datablock */ -bGPdata *gpencil_data_addnew (const char name[]) +bGPdata *gpencil_data_addnew(const char name[]) { bGPdata *gpd; /* allocate memory for a new block */ - gpd= alloc_libblock(&G.main->gpencil, ID_GD, name); + gpd = BKE_libblock_alloc(&G.main->gpencil, ID_GD, name); /* initial settings */ - gpd->flag = (GP_DATA_DISPINFO|GP_DATA_EXPAND); + gpd->flag = (GP_DATA_DISPINFO | GP_DATA_EXPAND); /* for now, stick to view is also enabled by default * since this is more useful... @@ -214,7 +214,7 @@ bGPdata *gpencil_data_addnew (const char name[]) /* -------- Data Duplication ---------- */ /* make a copy of a given gpencil frame */ -bGPDframe *gpencil_frame_duplicate (bGPDframe *src) +bGPDframe *gpencil_frame_duplicate(bGPDframe *src) { bGPDstroke *gps, *gpsd; bGPDframe *dst; @@ -224,15 +224,15 @@ bGPDframe *gpencil_frame_duplicate (bGPDframe *src) return NULL; /* make a copy of the source frame */ - dst= MEM_dupallocN(src); - dst->prev= dst->next= NULL; + dst = MEM_dupallocN(src); + dst->prev = dst->next = NULL; /* copy strokes */ - dst->strokes.first = dst->strokes.last= NULL; - for (gps= src->strokes.first; gps; gps= gps->next) { + dst->strokes.first = dst->strokes.last = NULL; + for (gps = src->strokes.first; gps; gps = gps->next) { /* make copy of source stroke, then adjust pointer to points too */ - gpsd= MEM_dupallocN(gps); - gpsd->points= MEM_dupallocN(gps->points); + gpsd = MEM_dupallocN(gps); + gpsd->points = MEM_dupallocN(gps->points); BLI_addtail(&dst->strokes, gpsd); } @@ -242,7 +242,7 @@ bGPDframe *gpencil_frame_duplicate (bGPDframe *src) } /* make a copy of a given gpencil layer */ -bGPDlayer *gpencil_layer_duplicate (bGPDlayer *src) +bGPDlayer *gpencil_layer_duplicate(bGPDlayer *src) { bGPDframe *gpf, *gpfd; bGPDlayer *dst; @@ -252,19 +252,19 @@ bGPDlayer *gpencil_layer_duplicate (bGPDlayer *src) return NULL; /* make a copy of source layer */ - dst= MEM_dupallocN(src); - dst->prev= dst->next= NULL; + dst = MEM_dupallocN(src); + dst->prev = dst->next = NULL; /* copy frames */ - dst->frames.first= dst->frames.last= NULL; - for (gpf= src->frames.first; gpf; gpf= gpf->next) { + dst->frames.first = dst->frames.last = NULL; + for (gpf = src->frames.first; gpf; gpf = gpf->next) { /* make a copy of source frame */ - gpfd= gpencil_frame_duplicate(gpf); + gpfd = gpencil_frame_duplicate(gpf); BLI_addtail(&dst->frames, gpfd); /* if source frame was the current layer's 'active' frame, reassign that too */ if (gpf == dst->actframe) - dst->actframe= gpfd; + dst->actframe = gpfd; } /* return new layer */ @@ -272,7 +272,7 @@ bGPDlayer *gpencil_layer_duplicate (bGPDlayer *src) } /* make a copy of a given gpencil datablock */ -bGPdata *gpencil_data_duplicate (bGPdata *src) +bGPdata *gpencil_data_duplicate(bGPdata *src) { bGPDlayer *gpl, *gpld; bGPdata *dst; @@ -282,13 +282,13 @@ bGPdata *gpencil_data_duplicate (bGPdata *src) return NULL; /* make a copy of the base-data */ - dst= MEM_dupallocN(src); + dst = MEM_dupallocN(src); /* copy layers */ - dst->layers.first= dst->layers.last= NULL; - for (gpl= src->layers.first; gpl; gpl= gpl->next) { + dst->layers.first = dst->layers.last = NULL; + for (gpl = src->layers.first; gpl; gpl = gpl->next) { /* make a copy of source layer and its data */ - gpld= gpencil_layer_duplicate(gpl); + gpld = gpencil_layer_duplicate(gpl); BLI_addtail(&dst->layers, gpld); } @@ -301,7 +301,7 @@ bGPdata *gpencil_data_duplicate (bGPdata *src) /* delete the last stroke of the given frame */ void gpencil_frame_delete_laststroke(bGPDlayer *gpl, bGPDframe *gpf) { - bGPDstroke *gps= (gpf) ? gpf->strokes.last : NULL; + bGPDstroke *gps = (gpf) ? gpf->strokes.last : NULL; int cfra = (gpf) ? gpf->framenum : 0; /* assume that the current frame was not locked */ /* error checking */ @@ -325,7 +325,7 @@ void gpencil_frame_delete_laststroke(bGPDlayer *gpl, bGPDframe *gpf) * - this sets the layer's actframe var (if allowed to) * - extension beyond range (if first gp-frame is after all frame in interest and cannot add) */ -bGPDframe *gpencil_layer_getframe (bGPDlayer *gpl, int cframe, short addnew) +bGPDframe *gpencil_layer_getframe(bGPDlayer *gpl, int cframe, short addnew) { bGPDframe *gpf = NULL; short found = 0; @@ -336,12 +336,12 @@ bGPDframe *gpencil_layer_getframe (bGPDlayer *gpl, int cframe, short addnew) /* check if there is already an active frame */ if (gpl->actframe) { - gpf= gpl->actframe; + gpf = gpl->actframe; /* do not allow any changes to layer's active frame if layer is locked from changes * or if the layer has been set to stay on the current frame */ - if (gpl->flag & (GP_LAYER_LOCKED|GP_LAYER_FRAMELOCK)) + if (gpl->flag & (GP_LAYER_LOCKED | GP_LAYER_FRAMELOCK)) return gpf; /* do not allow any changes to actframe if frame has painting tag attached to it */ if (gpf->flag & GP_FRAME_PAINT) @@ -349,13 +349,13 @@ bGPDframe *gpencil_layer_getframe (bGPDlayer *gpl, int cframe, short addnew) /* try to find matching frame */ if (gpf->framenum < cframe) { - for (; gpf; gpf= gpf->next) { + for (; gpf; gpf = gpf->next) { if (gpf->framenum == cframe) { - found= 1; + found = 1; break; } else if ((gpf->next) && (gpf->next->framenum > cframe)) { - found= 1; + found = 1; break; } } @@ -363,19 +363,19 @@ bGPDframe *gpencil_layer_getframe (bGPDlayer *gpl, int cframe, short addnew) /* set the appropriate frame */ if (addnew) { if ((found) && (gpf->framenum == cframe)) - gpl->actframe= gpf; + gpl->actframe = gpf; else - gpl->actframe= gpencil_frame_addnew(gpl, cframe); + gpl->actframe = gpencil_frame_addnew(gpl, cframe); } else if (found) - gpl->actframe= gpf; + gpl->actframe = gpf; else - gpl->actframe= gpl->frames.last; + gpl->actframe = gpl->frames.last; } else { - for (; gpf; gpf= gpf->prev) { + for (; gpf; gpf = gpf->prev) { if (gpf->framenum <= cframe) { - found= 1; + found = 1; break; } } @@ -383,35 +383,35 @@ bGPDframe *gpencil_layer_getframe (bGPDlayer *gpl, int cframe, short addnew) /* set the appropriate frame */ if (addnew) { if ((found) && (gpf->framenum == cframe)) - gpl->actframe= gpf; + gpl->actframe = gpf; else - gpl->actframe= gpencil_frame_addnew(gpl, cframe); + gpl->actframe = gpencil_frame_addnew(gpl, cframe); } else if (found) - gpl->actframe= gpf; + gpl->actframe = gpf; else - gpl->actframe= gpl->frames.first; + gpl->actframe = gpl->frames.first; } } else if (gpl->frames.first) { /* check which of the ends to start checking from */ - const int first= ((bGPDframe *)(gpl->frames.first))->framenum; - const int last= ((bGPDframe *)(gpl->frames.last))->framenum; + const int first = ((bGPDframe *)(gpl->frames.first))->framenum; + const int last = ((bGPDframe *)(gpl->frames.last))->framenum; - if (abs(cframe-first) > abs(cframe-last)) { + if (abs(cframe - first) > abs(cframe - last)) { /* find gp-frame which is less than or equal to cframe */ - for (gpf= gpl->frames.last; gpf; gpf= gpf->prev) { + for (gpf = gpl->frames.last; gpf; gpf = gpf->prev) { if (gpf->framenum <= cframe) { - found= 1; + found = 1; break; } } } else { /* find gp-frame which is less than or equal to cframe */ - for (gpf= gpl->frames.first; gpf; gpf= gpf->next) { + for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { if (gpf->framenum <= cframe) { - found= 1; + found = 1; break; } } @@ -420,12 +420,12 @@ bGPDframe *gpencil_layer_getframe (bGPDlayer *gpl, int cframe, short addnew) /* set the appropriate frame */ if (addnew) { if ((found) && (gpf->framenum == cframe)) - gpl->actframe= gpf; + gpl->actframe = gpf; else - gpl->actframe= gpencil_frame_addnew(gpl, cframe); + gpl->actframe = gpencil_frame_addnew(gpl, cframe); } else if (found) - gpl->actframe= gpf; + gpl->actframe = gpf; else { /* unresolved errogenous situation! */ printf("Error: cannot find appropriate gp-frame\n"); @@ -435,7 +435,7 @@ bGPDframe *gpencil_layer_getframe (bGPDlayer *gpl, int cframe, short addnew) else { /* currently no frames (add if allowed to) */ if (addnew) - gpl->actframe= gpencil_frame_addnew(gpl, cframe); + gpl->actframe = gpencil_frame_addnew(gpl, cframe); else { /* don't do anything... this may be when no frames yet! */ /* gpl->actframe should still be NULL */ @@ -460,7 +460,7 @@ void gpencil_layer_delframe(bGPDlayer *gpl, bGPDframe *gpf) } /* get the active gp-layer for editing */ -bGPDlayer *gpencil_layer_getactive (bGPdata *gpd) +bGPDlayer *gpencil_layer_getactive(bGPdata *gpd) { bGPDlayer *gpl; @@ -469,7 +469,7 @@ bGPDlayer *gpencil_layer_getactive (bGPdata *gpd) return NULL; /* loop over layers until found (assume only one active) */ - for (gpl=gpd->layers.first; gpl; gpl=gpl->next) { + for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { if (gpl->flag & GP_LAYER_ACTIVE) return gpl; } @@ -488,7 +488,7 @@ void gpencil_layer_setactive(bGPdata *gpd, bGPDlayer *active) return; /* loop over layers deactivating all */ - for (gpl=gpd->layers.first; gpl; gpl=gpl->next) + for (gpl = gpd->layers.first; gpl; gpl = gpl->next) gpl->flag &= ~GP_LAYER_ACTIVE; /* set as active one */ @@ -498,7 +498,7 @@ void gpencil_layer_setactive(bGPdata *gpd, bGPDlayer *active) /* delete the active gp-layer */ void gpencil_layer_delactive(bGPdata *gpd) { - bGPDlayer *gpl= gpencil_layer_getactive(gpd); + bGPDlayer *gpl = gpencil_layer_getactive(gpd); /* error checking */ if (ELEM(NULL, gpd, gpl)) diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c index 204b2b08563..ceffe269e85 100644 --- a/source/blender/blenkernel/intern/group.c +++ b/source/blender/blenkernel/intern/group.c @@ -52,7 +52,7 @@ #include "BKE_library.h" #include "BKE_main.h" #include "BKE_object.h" -#include "BKE_scene.h" /* object_in_scene */ +#include "BKE_scene.h" /* BKE_scene_base_find */ static void free_group_object(GroupObject *go) { @@ -60,21 +60,21 @@ static void free_group_object(GroupObject *go) } -void free_group_objects(Group *group) +void BKE_group_free(Group *group) { /* don't free group itself */ GroupObject *go; while (group->gobject.first) { - go= group->gobject.first; + go = group->gobject.first; BLI_remlink(&group->gobject, go); free_group_object(go); } } -void unlink_group(Group *group) +void BKE_group_unlink(Group *group) { - Main *bmain= G.main; + Main *bmain = G.main; Material *ma; Object *ob; Scene *sce; @@ -82,28 +82,28 @@ void unlink_group(Group *group) FreestyleLineSet *lineset; ParticleSystem *psys; - for (ma= bmain->mat.first; ma; ma= ma->id.next) { - if (ma->group==group) - ma->group= NULL; + for (ma = bmain->mat.first; ma; ma = ma->id.next) { + if (ma->group == group) + ma->group = NULL; } - for (ma= bmain->mat.first; ma; ma= ma->id.next) { - if (ma->group==group) - ma->group= NULL; + for (ma = bmain->mat.first; ma; ma = ma->id.next) { + if (ma->group == group) + ma->group = NULL; } - for (sce= bmain->scene.first; sce; sce= sce->id.next) { - Base *base= sce->base.first; + for (sce = bmain->scene.first; sce; sce = sce->id.next) { + Base *base = sce->base.first; /* ensure objects are not in this group */ - for (; base; base= base->next) { - if (rem_from_group(group, base->object, sce, base) && find_group(base->object, NULL)==NULL) { + for (; base; base = base->next) { + if (rem_from_group(group, base->object, sce, base) && find_group(base->object, NULL) == NULL) { base->object->flag &= ~OB_FROMGROUP; base->flag &= ~OB_FROMGROUP; } } - for (srl= sce->r.layers.first; srl; srl= srl->next) { - if (srl->light_override==group) - srl->light_override= NULL; + for (srl = sce->r.layers.first; srl; srl = srl->next) { + if (srl->light_override == group) + srl->light_override = NULL; for(lineset= srl->freestyleConfig.linesets.first; lineset; lineset= lineset->next) { if (lineset->group == group) @@ -112,51 +112,51 @@ void unlink_group(Group *group) } } - for (ob= bmain->object.first; ob; ob= ob->id.next) { + for (ob = bmain->object.first; ob; ob = ob->id.next) { - if (ob->dup_group==group) { - ob->dup_group= NULL; -#if 0 /* XXX OLD ANIMSYS, NLASTRIPS ARE NO LONGER USED */ + if (ob->dup_group == group) { + ob->dup_group = NULL; +#if 0 /* XXX OLD ANIMSYS, NLASTRIPS ARE NO LONGER USED */ { bActionStrip *strip; /* duplicator strips use a group object, we remove it */ - for (strip= ob->nlastrips.first; strip; strip= strip->next) { + for (strip = ob->nlastrips.first; strip; strip = strip->next) { if (strip->object) - strip->object= NULL; + strip->object = NULL; } } #endif } - for (psys=ob->particlesystem.first; psys; psys=psys->next) { - if (psys->part->dup_group==group) - psys->part->dup_group= NULL; -#if 0 /* not used anymore, only keps for readfile.c, no need to account for this */ - if (psys->part->eff_group==group) - psys->part->eff_group= NULL; + for (psys = ob->particlesystem.first; psys; psys = psys->next) { + if (psys->part->dup_group == group) + psys->part->dup_group = NULL; +#if 0 /* not used anymore, only keps for readfile.c, no need to account for this */ + if (psys->part->eff_group == group) + psys->part->eff_group = NULL; #endif } } /* group stays in library, but no members */ - free_group_objects(group); - group->id.us= 0; + BKE_group_free(group); + group->id.us = 0; } Group *add_group(const char *name) { Group *group; - group = alloc_libblock(&G.main->group, ID_GR, name); - group->layer= (1<<20)-1; + group = BKE_libblock_alloc(&G.main->group, ID_GR, name); + group->layer = (1 << 20) - 1; return group; } -Group *copy_group(Group *group) +Group *BKE_group_copy(Group *group) { Group *groupn; - groupn= MEM_dupallocN(group); + groupn = MEM_dupallocN(group); BLI_duplicatelist(&groupn->gobject, &group->gobject); return groupn; @@ -167,17 +167,17 @@ static int add_to_group_internal(Group *group, Object *ob) { GroupObject *go; - if (group==NULL || ob==NULL) return 0; + if (group == NULL || ob == NULL) return 0; /* check if the object has been added already */ - for (go= group->gobject.first; go; go= go->next) { - if (go->ob==ob) return 0; + for (go = group->gobject.first; go; go = go->next) { + if (go->ob == ob) return 0; } - go= MEM_callocN(sizeof(GroupObject), "groupobject"); + go = MEM_callocN(sizeof(GroupObject), "groupobject"); BLI_addtail(&group->gobject, go); - go->ob= ob; + go->ob = ob; return 1; } @@ -185,10 +185,10 @@ static int add_to_group_internal(Group *group, Object *ob) int add_to_group(Group *group, Object *object, Scene *scene, Base *base) { if (add_to_group_internal(group, object)) { - if ((object->flag & OB_FROMGROUP)==0) { + if ((object->flag & OB_FROMGROUP) == 0) { - if (scene && base==NULL) - base= object_in_scene(object, scene); + if (scene && base == NULL) + base = BKE_scene_base_find(scene, object); object->flag |= OB_FROMGROUP; @@ -207,18 +207,18 @@ static int rem_from_group_internal(Group *group, Object *ob) { GroupObject *go, *gon; int removed = 0; - if (group==NULL) return 0; + if (group == NULL) return 0; - go= group->gobject.first; + go = group->gobject.first; while (go) { - gon= go->next; - if (go->ob==ob) { + gon = go->next; + if (go->ob == ob) { BLI_remlink(&group->gobject, go); free_group_object(go); removed = 1; /* should break here since an object being in a group twice cant happen? */ } - go= gon; + go = gon; } return removed; } @@ -228,8 +228,8 @@ int rem_from_group(Group *group, Object *object, Scene *scene, Base *base) if (rem_from_group_internal(group, object)) { /* object can be NULL */ if (object && find_group(object, NULL) == NULL) { - if (scene && base==NULL) - base= object_in_scene(object, scene); + if (scene && base == NULL) + base = BKE_scene_base_find(scene, object); object->flag &= ~OB_FROMGROUP; @@ -247,10 +247,10 @@ int object_in_group(Object *ob, Group *group) { GroupObject *go; - if (group==NULL || ob==NULL) return 0; + if (group == NULL || ob == NULL) return 0; - for (go= group->gobject.first; go; go= go->next) { - if (go->ob==ob) + for (go = group->gobject.first; go; go = go->next) { + if (go->ob == ob) return 1; } return 0; @@ -259,14 +259,14 @@ int object_in_group(Object *ob, Group *group) Group *find_group(Object *ob, Group *group) { if (group) - group= group->id.next; + group = group->id.next; else - group= G.main->group.first; + group = G.main->group.first; while (group) { if (object_in_group(ob, group)) return group; - group= group->id.next; + group = group->id.next; } return NULL; } @@ -275,11 +275,11 @@ void group_tag_recalc(Group *group) { GroupObject *go; - if (group==NULL) return; + if (group == NULL) return; - for (go= group->gobject.first; go; go= go->next) { + for (go = group->gobject.first; go; go = go->next) { if (go->ob) - go->ob->recalc= go->recalc; + go->ob->recalc = go->recalc; } } @@ -292,7 +292,7 @@ int group_is_animated(Object *UNUSED(parent), Group *group) return 1; #endif - for (go= group->gobject.first; go; go= go->next) + for (go = group->gobject.first; go; go = go->next) if (go->ob && go->ob->proxy) return 1; @@ -304,38 +304,38 @@ int group_is_animated(Object *UNUSED(parent), Group *group) /* keep checking nla.c though, in case internal structure of strip changes */ static void group_replaces_nla(Object *parent, Object *target, char mode) { - static ListBase nlastrips={NULL, NULL}; - static bAction *action= NULL; - static int done= 0; + static ListBase nlastrips = {NULL, NULL}; + static bAction *action = NULL; + static int done = 0; bActionStrip *strip, *nstrip; - if (mode=='s') { + if (mode == 's') { - for (strip= parent->nlastrips.first; strip; strip= strip->next) { - if (strip->object==target) { - if (done==0) { + for (strip = parent->nlastrips.first; strip; strip = strip->next) { + if (strip->object == target) { + if (done == 0) { /* clear nla & action from object */ - nlastrips= target->nlastrips; - target->nlastrips.first= target->nlastrips.last= NULL; - action= target->action; - target->action= NULL; + nlastrips = target->nlastrips; + target->nlastrips.first = target->nlastrips.last = NULL; + action = target->action; + target->action = NULL; target->nlaflag |= OB_NLA_OVERRIDE; - done= 1; + done = 1; } - nstrip= MEM_dupallocN(strip); + nstrip = MEM_dupallocN(strip); BLI_addtail(&target->nlastrips, nstrip); } } } - else if (mode=='e') { + else if (mode == 'e') { if (done) { BLI_freelistN(&target->nlastrips); - target->nlastrips= nlastrips; - target->action= action; + target->nlastrips = nlastrips; + target->action = action; - nlastrips.first= nlastrips.last= NULL; /* not needed, but yah... :) */ - action= NULL; - done= 0; + nlastrips.first = nlastrips.last = NULL; /* not needed, but yah... :) */ + action = NULL; + done = 0; } } } @@ -359,33 +359,33 @@ void group_handle_recalc_and_update(Scene *scene, Object *UNUSED(parent), Group int cfrao; /* switch to local time */ - cfrao= scene->r.cfra; + cfrao = scene->r.cfra; /* we need a DAG per group... */ - for (go= group->gobject.first; go; go= go->next) { + for (go = group->gobject.first; go; go = go->next) { if (go->ob && go->recalc) { - go->ob->recalc= go->recalc; + go->ob->recalc = go->recalc; group_replaces_nla(parent, go->ob, 's'); - object_handle_update(scene, go->ob); + BKE_object_handle_update(scene, go->ob); group_replaces_nla(parent, go->ob, 'e'); /* leave recalc tags in case group members are in normal scene */ - go->ob->recalc= go->recalc; + go->ob->recalc = go->recalc; } } /* restore */ - scene->r.cfra= cfrao; + scene->r.cfra = cfrao; } else #endif { /* only do existing tags, as set by regular depsgraph */ - for (go= group->gobject.first; go; go= go->next) { + for (go = group->gobject.first; go; go = go->next) { if (go->ob) { if (go->ob->recalc) { - object_handle_update(scene, go->ob); + BKE_object_handle_update(scene, go->ob); } } } @@ -397,17 +397,17 @@ Object *group_get_member_with_action(Group *group, bAction *act) { GroupObject *go; - if (group==NULL || act==NULL) return NULL; + if (group == NULL || act == NULL) return NULL; - for (go= group->gobject.first; go; go= go->next) { + for (go = group->gobject.first; go; go = go->next) { if (go->ob) { - if (go->ob->action==act) + if (go->ob->action == act) return go->ob; if (go->ob->nlastrips.first) { bActionStrip *strip; - for (strip= go->ob->nlastrips.first; strip; strip= strip->next) { - if (strip->act==act) + for (strip = go->ob->nlastrips.first; strip; strip = strip->next) { + if (strip->act == act) return go->ob; } } @@ -424,21 +424,21 @@ void group_relink_nla_objects(Object *ob) GroupObject *go; bActionStrip *strip; - if (ob==NULL || ob->dup_group==NULL) return; - group= ob->dup_group; + if (ob == NULL || ob->dup_group == NULL) return; + group = ob->dup_group; - for (strip= ob->nlastrips.first; strip; strip= strip->next) { + for (strip = ob->nlastrips.first; strip; strip = strip->next) { if (strip->object) { - for (go= group->gobject.first; go; go= go->next) { + for (go = group->gobject.first; go; go = go->next) { if (go->ob) { - if (strcmp(go->ob->id.name, strip->object->id.name)==0) + if (strcmp(go->ob->id.name, strip->object->id.name) == 0) break; } } if (go) - strip->object= go->ob; + strip->object = go->ob; else - strip->object= NULL; + strip->object = NULL; } } diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index dfe73ae20db..e3735cfd374 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -47,16 +47,16 @@ static char idp_size_table[] = { 1, /*strings*/ sizeof(int), sizeof(float), - sizeof(float)*3, /*Vector type, deprecated*/ - sizeof(float)*16, /*Matrix type, deprecated*/ + sizeof(float) * 3, /*Vector type, deprecated*/ + sizeof(float) * 16, /*Matrix type, deprecated*/ 0, /*arrays don't have a fixed size*/ sizeof(ListBase), /*Group type*/ - sizeof(void*), + sizeof(void *), sizeof(double) }; /* ------------Property Array Type ----------- */ -#define GETPROP(prop, i) (((IDProperty*)(prop)->data.pointer)+(i)) +#define GETPROP(prop, i) (((IDProperty *)(prop)->data.pointer) + (i)) /* --------- property array type -------------*/ @@ -78,10 +78,10 @@ IDProperty *IDP_CopyIDPArray(IDProperty *array) IDProperty *narray = MEM_mallocN(sizeof(IDProperty), "IDP_CopyIDPArray"), *tmp; int i; - *narray= *array; + *narray = *array; narray->data.pointer = MEM_dupallocN(array->data.pointer); - for (i=0; i<narray->len; i++) { + for (i = 0; i < narray->len; i++) { /* ok, the copy functions always allocate a new structure, * which doesn't work here. instead, simply copy the * contents of the new structure into the array cell, @@ -100,7 +100,7 @@ void IDP_FreeIDPArray(IDProperty *prop) { int i; - for (i=0; i<prop->len; i++) + for (i = 0; i < prop->len; i++) IDP_FreeProperty(GETPROP(prop, i)); if (prop->data.pointer) @@ -124,22 +124,22 @@ IDProperty *IDP_GetIndexArray(IDProperty *prop, int index) IDProperty *IDP_AppendArray(IDProperty *prop, IDProperty *item) { - IDP_ResizeIDPArray(prop, prop->len+1); - IDP_SetIndexArray(prop, prop->len-1, item); + IDP_ResizeIDPArray(prop, prop->len + 1); + IDP_SetIndexArray(prop, prop->len - 1, item); return item; } void IDP_ResizeIDPArray(IDProperty *prop, int newlen) { void *newarr; - int newsize=newlen; + int newsize = newlen; /*first check if the array buffer size has room*/ /*if newlen is 200 chars less then totallen, reallocate anyway*/ if (newlen <= prop->totallen && prop->totallen - newlen < 200) { int i; - for (i=newlen; i<prop->len; i++) + for (i = newlen; i < prop->len; i++) IDP_FreeProperty(GETPROP(prop, i)); prop->len = newlen; @@ -156,18 +156,18 @@ void IDP_ResizeIDPArray(IDProperty *prop, int newlen) */ newsize = (newsize >> 3) + (newsize < 9 ? 3 : 6) + newsize; - newarr = MEM_callocN(sizeof(IDProperty)*newsize, "idproperty array resized"); + newarr = MEM_callocN(sizeof(IDProperty) * newsize, "idproperty array resized"); if (newlen >= prop->len) { /* newlen is bigger*/ - memcpy(newarr, prop->data.pointer, prop->len*sizeof(IDProperty)); + memcpy(newarr, prop->data.pointer, prop->len * sizeof(IDProperty)); } else { int i; /* newlen is smaller*/ - for (i=newlen; i<prop->len; i++) { + for (i = newlen; i < prop->len; i++) { IDP_FreeProperty(GETPROP(prop, i)); } - memcpy(newarr, prop->data.pointer, newlen*sizeof(IDProperty)); + memcpy(newarr, prop->data.pointer, newlen * sizeof(IDProperty)); } if (prop->data.pointer) @@ -185,21 +185,21 @@ static void idp_resize_group_array(IDProperty *prop, int newlen, void *newarr) if (newlen >= prop->len) { /* bigger */ - IDProperty **array= newarr; + IDProperty **array = newarr; IDPropertyTemplate val; int a; - for (a=prop->len; a<newlen; a++) { + for (a = prop->len; a < newlen; a++) { val.i = 0; /* silence MSVC warning about uninitialized var when debugging */ - array[a]= IDP_New(IDP_GROUP, &val, "IDP_ResizeArray group"); + array[a] = IDP_New(IDP_GROUP, &val, "IDP_ResizeArray group"); } } else { /* smaller */ - IDProperty **array= prop->data.pointer; + IDProperty **array = prop->data.pointer; int a; - for (a=newlen; a<prop->len; a++) { + for (a = newlen; a < prop->len; a++) { IDP_FreeProperty(array[a]); MEM_freeN(array[a]); } @@ -210,7 +210,7 @@ static void idp_resize_group_array(IDProperty *prop, int newlen, void *newarr) void IDP_ResizeArray(IDProperty *prop, int newlen) { void *newarr; - int newsize=newlen; + int newsize = newlen; /*first check if the array buffer size has room*/ /*if newlen is 200 chars less then totallen, reallocate anyway*/ @@ -230,16 +230,16 @@ void IDP_ResizeArray(IDProperty *prop, int newlen) */ newsize = (newsize >> 3) + (newsize < 9 ? 3 : 6) + newsize; - newarr = MEM_callocN(idp_size_table[(int)prop->subtype]*newsize, "idproperty array resized"); + newarr = MEM_callocN(idp_size_table[(int)prop->subtype] * newsize, "idproperty array resized"); if (newlen >= prop->len) { /* newlen is bigger*/ - memcpy(newarr, prop->data.pointer, prop->len*idp_size_table[(int)prop->subtype]); + memcpy(newarr, prop->data.pointer, prop->len * idp_size_table[(int)prop->subtype]); idp_resize_group_array(prop, newlen, newarr); } else { /* newlen is smaller*/ idp_resize_group_array(prop, newlen, newarr); - memcpy(newarr, prop->data.pointer, newlen*idp_size_table[(int)prop->subtype]); + memcpy(newarr, prop->data.pointer, newlen * idp_size_table[(int)prop->subtype]); } MEM_freeN(prop->data.pointer); @@ -257,8 +257,8 @@ void IDP_FreeArray(IDProperty *prop) } - static IDProperty *idp_generic_copy(IDProperty *prop) - { +static IDProperty *idp_generic_copy(IDProperty *prop) +{ IDProperty *newp = MEM_callocN(sizeof(IDProperty), "IDProperty array dup"); BLI_strncpy(newp->name, prop->name, MAX_IDPROP_NAME); @@ -268,7 +268,7 @@ void IDP_FreeArray(IDProperty *prop) newp->data.val2 = prop->data.val2; return newp; - } +} static IDProperty *IDP_CopyArray(IDProperty *prop) { @@ -278,11 +278,11 @@ static IDProperty *IDP_CopyArray(IDProperty *prop) newp->data.pointer = MEM_dupallocN(prop->data.pointer); if (prop->type == IDP_GROUP) { - IDProperty **array= newp->data.pointer; + IDProperty **array = newp->data.pointer; int a; - for (a=0; a<prop->len; a++) - array[a]= IDP_CopyProperty(array[a]); + for (a = 0; a < prop->len; a++) + array[a] = IDP_CopyProperty(array[a]); } } newp->len = prop->len; @@ -294,12 +294,12 @@ static IDProperty *IDP_CopyArray(IDProperty *prop) /*taken from readfile.c*/ #define SWITCH_LONGINT(a) { \ - char s_i, *p_i; \ - p_i= (char *)&(a); \ - s_i=p_i[0]; p_i[0]=p_i[7]; p_i[7]=s_i; \ - s_i=p_i[1]; p_i[1]=p_i[6]; p_i[6]=s_i; \ - s_i=p_i[2]; p_i[2]=p_i[5]; p_i[5]=s_i; \ - s_i=p_i[3]; p_i[3]=p_i[4]; p_i[4]=s_i; } + char s_i, *p_i; \ + p_i = (char *)& (a); \ + s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i; \ + s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i; \ + s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i; \ + s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i; } @@ -350,7 +350,7 @@ void IDP_AssignString(IDProperty *prop, const char *st, int maxlen) int stlen = strlen(st); if (maxlen > 0 && maxlen < stlen) - stlen= maxlen; + stlen = maxlen; if (prop->subtype == IDP_STRING_SUB_BYTE) { IDP_ResizeArray(prop, stlen); @@ -396,14 +396,14 @@ void IDP_FreeString(IDProperty *prop) void IDP_LinkID(IDProperty *prop, ID *id) { - if (prop->data.pointer) ((ID*)prop->data.pointer)->us--; + if (prop->data.pointer) ((ID *)prop->data.pointer)->us--; prop->data.pointer = id; id_us_plus(id); } void IDP_UnlinkID(IDProperty *prop) { - ((ID*)prop->data.pointer)->us--; + ((ID *)prop->data.pointer)->us--; } /*-------- Group Functions -------*/ @@ -414,7 +414,7 @@ static IDProperty *IDP_CopyGroup(IDProperty *prop) IDProperty *newp = idp_generic_copy(prop), *link; newp->len = prop->len; - for (link=prop->data.group.first; link; link=link->next) { + for (link = prop->data.group.first; link; link = link->next) { BLI_addtail(&newp->data.group, IDP_CopyProperty(link)); } @@ -426,22 +426,22 @@ static IDProperty *IDP_CopyGroup(IDProperty *prop) void IDP_SyncGroupValues(IDProperty *dest, IDProperty *src) { IDProperty *other, *prop; - for (prop=src->data.group.first; prop; prop=prop->next) { - other= BLI_findstring(&dest->data.group, prop->name, offsetof(IDProperty, name)); - if (other && prop->type==other->type) { + for (prop = src->data.group.first; prop; prop = prop->next) { + other = BLI_findstring(&dest->data.group, prop->name, offsetof(IDProperty, name)); + if (other && prop->type == other->type) { switch (prop->type) { case IDP_INT: case IDP_FLOAT: case IDP_DOUBLE: - other->data= prop->data; + other->data = prop->data; break; case IDP_GROUP: IDP_SyncGroupValues(other, prop); break; default: { - IDProperty *tmp= other; - IDProperty *copy= IDP_CopyProperty(prop); + IDProperty *tmp = other; + IDProperty *copy = IDP_CopyProperty(prop); BLI_insertlinkafter(&dest->data.group, other, copy); BLI_remlink(&dest->data.group, tmp); @@ -460,8 +460,8 @@ void IDP_SyncGroupValues(IDProperty *dest, IDProperty *src) void IDP_ReplaceGroupInGroup(IDProperty *dest, IDProperty *src) { IDProperty *loop, *prop; - for (prop=src->data.group.first; prop; prop=prop->next) { - for (loop=dest->data.group.first; loop; loop=loop->next) { + for (prop = src->data.group.first; prop; prop = prop->next) { + for (loop = dest->data.group.first; loop; loop = loop->next) { if (strcmp(loop->name, prop->name) == 0) { IDProperty *copy = IDP_CopyProperty(prop); @@ -489,7 +489,7 @@ void IDP_ReplaceGroupInGroup(IDProperty *dest, IDProperty *src) void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop) { IDProperty *loop; - if ((loop= IDP_GetPropertyFromGroup(group, prop->name))) { + if ((loop = IDP_GetPropertyFromGroup(group, prop->name))) { BLI_insertlink(&group->data.group, loop, prop); BLI_remlink(&group->data.group, loop); @@ -539,7 +539,7 @@ IDProperty *IDP_GetPropertyFromGroup(IDProperty *prop, const char *name) IDProperty *IDP_GetPropertyTypeFromGroup(IDProperty *prop, const char *name, const char type) { - IDProperty *idprop= IDP_GetPropertyFromGroup(prop, name); + IDProperty *idprop = IDP_GetPropertyFromGroup(prop, name); return (idprop && idprop->type == type) ? idprop : NULL; } @@ -553,20 +553,20 @@ void *IDP_GetGroupIterator(IDProperty *prop) IDPIter *iter = MEM_callocN(sizeof(IDPIter), "IDPIter"); iter->next = prop->data.group.first; iter->parent = prop; - return (void*) iter; + return (void *) iter; } IDProperty *IDP_GroupIterNext(void *vself) { - IDPIter *self = (IDPIter*) vself; - Link *next = (Link*) self->next; + IDPIter *self = (IDPIter *) vself; + Link *next = (Link *) self->next; if (self->next == NULL) { MEM_freeN(self); return NULL; } self->next = next->next; - return (void*) next; + return (void *) next; } void IDP_FreeIterBeforeEnd(void *vself) @@ -581,7 +581,7 @@ void IDP_FreeIterBeforeEnd(void *vself) static void IDP_FreeGroup(IDProperty *prop) { IDProperty *loop; - for (loop=prop->data.group.first; loop; loop=loop->next) { + for (loop = prop->data.group.first; loop; loop = loop->next) { IDP_FreeProperty(loop); } BLI_freelistN(&prop->data.group); @@ -635,7 +635,7 @@ int IDP_EqualsProperties(IDProperty *prop1, IDProperty *prop2) return ((prop1->len == prop2->len) && strncmp(IDP_String(prop1), IDP_String(prop2), prop1->len) == 0); else if (prop1->type == IDP_ARRAY) { if (prop1->len == prop2->len && prop1->subtype == prop2->subtype) - return memcmp(IDP_Array(prop1), IDP_Array(prop2), idp_size_table[(int)prop1->subtype]*prop1->len); + return memcmp(IDP_Array(prop1), IDP_Array(prop2), idp_size_table[(int)prop1->subtype] * prop1->len); else return 0; } @@ -645,8 +645,8 @@ int IDP_EqualsProperties(IDProperty *prop1, IDProperty *prop2) if (BLI_countlist(&prop1->data.group) != BLI_countlist(&prop2->data.group)) return 0; - for (link1=prop1->data.group.first; link1; link1=link1->next) { - link2= IDP_GetPropertyFromGroup(prop2, link1->name); + for (link1 = prop1->data.group.first; link1; link1 = link1->next) { + link2 = IDP_GetPropertyFromGroup(prop2, link1->name); if (!IDP_EqualsProperties(link1, link2)) return 0; @@ -655,14 +655,14 @@ int IDP_EqualsProperties(IDProperty *prop1, IDProperty *prop2) return 1; } else if (prop1->type == IDP_IDPARRAY) { - IDProperty *array1= IDP_IDPArray(prop1); - IDProperty *array2= IDP_IDPArray(prop2); + IDProperty *array1 = IDP_IDPArray(prop1); + IDProperty *array2 = IDP_IDPArray(prop2); int i; if (prop1->len != prop2->len) return 0; - for (i=0; i<prop1->len; i++) + for (i = 0; i < prop1->len; i++) if (!IDP_EqualsProperties(&array1[i], &array2[i])) return 0; } @@ -673,7 +673,7 @@ int IDP_EqualsProperties(IDProperty *prop1, IDProperty *prop2) /* 'val' is never NULL, don't check */ IDProperty *IDP_New(const int type, const IDPropertyTemplate *val, const char *name) { - IDProperty *prop=NULL; + IDProperty *prop = NULL; switch (type) { case IDP_INT: @@ -682,11 +682,11 @@ IDProperty *IDP_New(const int type, const IDPropertyTemplate *val, const char *n break; case IDP_FLOAT: prop = MEM_callocN(sizeof(IDProperty), "IDProperty float"); - *(float*)&prop->data.val = val->f; + *(float *)&prop->data.val = val->f; break; case IDP_DOUBLE: prop = MEM_callocN(sizeof(IDProperty), "IDProperty float"); - *(double*)&prop->data.val = val->d; + *(double *)&prop->data.val = val->d; break; case IDP_ARRAY: { @@ -699,7 +699,7 @@ IDProperty *IDP_New(const int type, const IDPropertyTemplate *val, const char *n prop = MEM_callocN(sizeof(IDProperty), "IDProperty array"); prop->subtype = val->array.type; if (val->array.len) - prop->data.pointer = MEM_callocN(idp_size_table[val->array.type]*val->array.len, "id property array"); + prop->data.pointer = MEM_callocN(idp_size_table[val->array.type] * val->array.len, "id property array"); prop->len = prop->totallen = val->array.len; break; } @@ -724,7 +724,7 @@ IDProperty *IDP_New(const int type, const IDPropertyTemplate *val, const char *n prop->len = prop->totallen = val->string.len; memcpy(prop->data.pointer, st, val->string.len); } - prop->subtype= IDP_STRING_SUB_BYTE; + prop->subtype = IDP_STRING_SUB_BYTE; } else { if (st == NULL) { @@ -738,7 +738,7 @@ IDProperty *IDP_New(const int type, const IDPropertyTemplate *val, const char *n prop->len = prop->totallen = stlen; memcpy(prop->data.pointer, st, stlen); } - prop->subtype= IDP_STRING_SUB_UTF8; + prop->subtype = IDP_STRING_SUB_UTF8; } break; } diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 9c5c99592ed..aff1e65224b 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -92,18 +92,18 @@ #include "BLO_sys_types.h" // for intptr_t support /* max int, to indicate we don't store sequences in ibuf */ -#define IMA_NO_INDEX 0x7FEFEFEF +#define IMA_NO_INDEX 0x7FEFEFEF /* quick lookup: supports 1 million frames, thousand passes */ -#define IMA_MAKE_INDEX(frame, index) ((frame)<<10)+index -#define IMA_INDEX_FRAME(index) (index>>10) -#define IMA_INDEX_PASS(index) (index & ~1023) +#define IMA_MAKE_INDEX(frame, index) ((frame) << 10) + index +#define IMA_INDEX_FRAME(index) (index >> 10) +#define IMA_INDEX_PASS(index) (index & ~1023) /* ******** IMAGE PROCESSING ************* */ -static void de_interlace_ng(struct ImBuf *ibuf) /* neogeo fields */ +static void de_interlace_ng(struct ImBuf *ibuf) /* neogeo fields */ { - struct ImBuf * tbuf1, * tbuf2; + struct ImBuf *tbuf1, *tbuf2; if (ibuf == NULL) return; if (ibuf->flags & IB_fields) return; @@ -129,9 +129,9 @@ static void de_interlace_ng(struct ImBuf *ibuf) /* neogeo fields */ ibuf->y /= 2; } -static void de_interlace_st(struct ImBuf *ibuf) /* standard fields */ +static void de_interlace_st(struct ImBuf *ibuf) /* standard fields */ { - struct ImBuf * tbuf1, * tbuf2; + struct ImBuf *tbuf1, *tbuf2; if (ibuf == NULL) return; if (ibuf->flags & IB_fields) return; @@ -157,9 +157,9 @@ static void de_interlace_st(struct ImBuf *ibuf) /* standard fields */ ibuf->y /= 2; } -void image_de_interlace(Image *ima, int odd) +void BKE_image_de_interlace(Image *ima, int odd) { - ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL); + ImBuf *ibuf = BKE_image_get_ibuf(ima, NULL); if (ibuf) { if (odd) de_interlace_st(ibuf); @@ -185,20 +185,20 @@ static void image_free_buffers(Image *ima) } if (ima->anim) IMB_free_anim(ima->anim); - ima->anim= NULL; + ima->anim = NULL; if (ima->rr) { RE_FreeRenderResult(ima->rr); - ima->rr= NULL; + ima->rr = NULL; } GPU_free_image(ima); - ima->ok= IMA_OK; + ima->ok = IMA_OK; } /* called by library too, do not free ima itself */ -void free_image(Image *ima) +void BKE_image_free(Image *ima) { int a; @@ -212,10 +212,10 @@ void free_image(Image *ima) BKE_previewimg_free(&ima->preview); - for (a=0; a<IMA_MAX_RENDER_SLOT; a++) { + for (a = 0; a < IMA_MAX_RENDER_SLOT; a++) { if (ima->renders[a]) { RE_FreeRenderResult(ima->renders[a]); - ima->renders[a]= NULL; + ima->renders[a] = NULL; } } } @@ -225,17 +225,17 @@ static Image *image_alloc(const char *name, short source, short type) { Image *ima; - ima= alloc_libblock(&G.main->image, ID_IM, name); + ima = BKE_libblock_alloc(&G.main->image, ID_IM, name); if (ima) { - ima->ok= IMA_OK; + ima->ok = IMA_OK; - ima->xrep= ima->yrep= 1; - ima->aspx= ima->aspy= 1.0; - ima->gen_x= 1024; ima->gen_y= 1024; - ima->gen_type= 1; /* no defines yet? */ + ima->xrep = ima->yrep = 1; + ima->aspx = ima->aspy = 1.0; + ima->gen_x = 1024; ima->gen_y = 1024; + ima->gen_type = 1; /* no defines yet? */ - ima->source= source; - ima->type= type; + ima->source = source; + ima->type = type; } return ima; } @@ -246,14 +246,14 @@ static ImBuf *image_get_ibuf(Image *ima, int index, int frame) /* this function is intended to be thread safe. with IMA_NO_INDEX this * should be OK, but when iterating over the list this is more tricky * */ - if (index==IMA_NO_INDEX) + if (index == IMA_NO_INDEX) return ima->ibufs.first; else { ImBuf *ibuf; - index= IMA_MAKE_INDEX(frame, index); - for (ibuf= ima->ibufs.first; ibuf; ibuf= ibuf->next) - if (ibuf->index==index) + index = IMA_MAKE_INDEX(frame, index); + for (ibuf = ima->ibufs.first; ibuf; ibuf = ibuf->next) + if (ibuf->index == index) return ibuf; return NULL; @@ -276,15 +276,15 @@ static void image_assign_ibuf(Image *ima, ImBuf *ibuf, int index, int frame) if (ibuf) { ImBuf *link; - if (index!=IMA_NO_INDEX) - index= IMA_MAKE_INDEX(frame, index); + if (index != IMA_NO_INDEX) + index = IMA_MAKE_INDEX(frame, index); /* insert based on index */ - for (link= ima->ibufs.first; link; link= link->next) - if (link->index>=index) + for (link = ima->ibufs.first; link; link = link->next) + if (link->index >= index) break; - ibuf->index= index; + ibuf->index = index; if (ima->flag & IMA_CM_PREDIVIDE) ibuf->flags |= IB_cm_predivide; else @@ -294,29 +294,29 @@ static void image_assign_ibuf(Image *ima, ImBuf *ibuf, int index, int frame) BLI_insertlinkbefore(&ima->ibufs, link, ibuf); /* now we don't want copies? */ - if (link && ibuf->index==link->index) + if (link && ibuf->index == link->index) image_remove_ibuf(ima, link); } } /* empty image block, of similar type and filename */ -Image *copy_image(Image *ima) +Image *BKE_image_copy(Image *ima) { - Image *nima= image_alloc(ima->id.name+2, ima->source, ima->type); + Image *nima = image_alloc(ima->id.name + 2, ima->source, ima->type); BLI_strncpy(nima->name, ima->name, sizeof(ima->name)); - nima->flag= ima->flag; - nima->tpageflag= ima->tpageflag; + nima->flag = ima->flag; + nima->tpageflag = ima->tpageflag; - nima->gen_x= ima->gen_x; - nima->gen_y= ima->gen_y; - nima->gen_type= ima->gen_type; + nima->gen_x = ima->gen_x; + nima->gen_y = ima->gen_y; + nima->gen_type = ima->gen_type; - nima->animspeed= ima->animspeed; + nima->animspeed = ima->animspeed; - nima->aspx= ima->aspx; - nima->aspy= ima->aspy; + nima->aspx = ima->aspx; + nima->aspy = ima->aspy; return nima; } @@ -327,56 +327,56 @@ static void extern_local_image(Image *UNUSED(ima)) * match id_make_local pattern. */ } -void make_local_image(struct Image *ima) +void BKE_image_make_local(struct Image *ima) { - Main *bmain= G.main; + Main *bmain = G.main; Tex *tex; Brush *brush; Mesh *me; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (ima->id.lib==NULL) return; + if (ima->id.lib == NULL) return; /* Can't take short cut here: must check meshes at least because of bogus * texface ID refs. - z0r */ #if 0 - if (ima->id.us==1) { + if (ima->id.us == 1) { id_clear_lib_data(bmain, &ima->id); extern_local_image(ima); return; } #endif - for (tex= bmain->tex.first; tex; tex= tex->id.next) { + for (tex = bmain->tex.first; tex; tex = tex->id.next) { if (tex->ima == ima) { - if (tex->id.lib) is_lib= TRUE; - else is_local= TRUE; + if (tex->id.lib) is_lib = TRUE; + else is_local = TRUE; } } - for (brush= bmain->brush.first; brush; brush= brush->id.next) { + for (brush = bmain->brush.first; brush; brush = brush->id.next) { if (brush->clone.image == ima) { - if (brush->id.lib) is_lib= TRUE; - else is_local= TRUE; + if (brush->id.lib) is_lib = TRUE; + else is_local = TRUE; } } - for (me= bmain->mesh.first; me; me= me->id.next) { + for (me = bmain->mesh.first; me; me = me->id.next) { if (me->mtface) { MTFace *tface; int a, i; - for (i=0; i<me->fdata.totlayer; i++) { + for (i = 0; i < me->fdata.totlayer; i++) { if (me->fdata.layers[i].type == CD_MTFACE) { - tface= (MTFace*)me->fdata.layers[i].data; + tface = (MTFace *)me->fdata.layers[i].data; - for (a=0; a<me->totface; a++, tface++) { + for (a = 0; a < me->totface; a++, tface++) { if (tface->tpage == ima) { - if (me->id.lib) is_lib= TRUE; - else is_local= TRUE; + if (me->id.lib) is_lib = TRUE; + else is_local = TRUE; } } } @@ -387,14 +387,14 @@ void make_local_image(struct Image *ima) MTexPoly *mtpoly; int a, i; - for (i=0; i<me->pdata.totlayer; i++) { + for (i = 0; i < me->pdata.totlayer; i++) { if (me->pdata.layers[i].type == CD_MTEXPOLY) { - mtpoly= (MTexPoly*)me->pdata.layers[i].data; + mtpoly = (MTexPoly *)me->pdata.layers[i].data; - for (a=0; a<me->totpoly; a++, mtpoly++) { + for (a = 0; a < me->totpoly; a++, mtpoly++) { if (mtpoly->tpage == ima) { - if (me->id.lib) is_lib= TRUE; - else is_local= TRUE; + if (me->id.lib) is_lib = TRUE; + else is_local = TRUE; } } } @@ -408,55 +408,55 @@ void make_local_image(struct Image *ima) extern_local_image(ima); } else if (is_local && is_lib) { - Image *ima_new= copy_image(ima); + Image *ima_new = BKE_image_copy(ima); - ima_new->id.us= 0; + ima_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, ima->id.lib, &ima_new->id); - tex= bmain->tex.first; + tex = bmain->tex.first; while (tex) { - if (tex->id.lib==NULL) { - if (tex->ima==ima) { + if (tex->id.lib == NULL) { + if (tex->ima == ima) { tex->ima = ima_new; ima_new->id.us++; ima->id.us--; } } - tex= tex->id.next; + tex = tex->id.next; } - brush= bmain->brush.first; + brush = bmain->brush.first; while (brush) { - if (brush->id.lib==NULL) { - if (brush->clone.image==ima) { + if (brush->id.lib == NULL) { + if (brush->clone.image == ima) { brush->clone.image = ima_new; ima_new->id.us++; ima->id.us--; } } - brush= brush->id.next; + brush = brush->id.next; } /* Transfer references in texfaces. Texfaces don't add to image ID * user count *unless* there are no other users. See * readfile.c:lib_link_mtface. */ - me= bmain->mesh.first; + me = bmain->mesh.first; while (me) { if (me->mtface) { MTFace *tface; int a, i; - for (i=0; i<me->fdata.totlayer; i++) { + for (i = 0; i < me->fdata.totlayer; i++) { if (me->fdata.layers[i].type == CD_MTFACE) { - tface= (MTFace*)me->fdata.layers[i].data; + tface = (MTFace *)me->fdata.layers[i].data; - for (a=0; a<me->totface; a++, tface++) { + for (a = 0; a < me->totface; a++, tface++) { if (tface->tpage == ima) { tface->tpage = ima_new; if (ima_new->id.us == 0) { - tface->tpage->id.us= 1; + tface->tpage->id.us = 1; } - id_lib_extern((ID*)ima_new); + id_lib_extern((ID *)ima_new); } } } @@ -467,24 +467,24 @@ void make_local_image(struct Image *ima) MTexPoly *mtpoly; int a, i; - for (i=0; i<me->pdata.totlayer; i++) { + for (i = 0; i < me->pdata.totlayer; i++) { if (me->pdata.layers[i].type == CD_MTEXPOLY) { - mtpoly= (MTexPoly*)me->pdata.layers[i].data; + mtpoly = (MTexPoly *)me->pdata.layers[i].data; - for (a=0; a<me->totpoly; a++, mtpoly++) { + for (a = 0; a < me->totpoly; a++, mtpoly++) { if (mtpoly->tpage == ima) { mtpoly->tpage = ima_new; if (ima_new->id.us == 0) { - mtpoly->tpage->id.us= 1; + mtpoly->tpage->id.us = 1; } - id_lib_extern((ID*)ima_new); + id_lib_extern((ID *)ima_new); } } } } } - me= me->id.next; + me = me->id.next; } } } @@ -494,140 +494,149 @@ void BKE_image_merge(Image *dest, Image *source) ImBuf *ibuf; /* sanity check */ - if (dest && source && dest!=source) { + if (dest && source && dest != source) { - while ((ibuf= source->ibufs.first)) { + while ((ibuf = source->ibufs.first)) { BLI_remlink(&source->ibufs, ibuf); image_assign_ibuf(dest, ibuf, IMA_INDEX_PASS(ibuf->index), IMA_INDEX_FRAME(ibuf->index)); } - free_libblock(&G.main->image, source); + BKE_libblock_free(&G.main->image, source); } } +Image *BKE_image_load(const char *filepath) +{ + Image *ima; + int file, len; + const char *libname; + char str[FILE_MAX]; + + BLI_strncpy(str, filepath, sizeof(str)); + BLI_path_abs(str, G.main->name); + + /* exists? */ + file = BLI_open(str, O_BINARY | O_RDONLY, 0); + if (file == -1) return NULL; + close(file); + + /* create a short library name */ + len = strlen(filepath); + + while (len > 0 && filepath[len - 1] != '/' && filepath[len - 1] != '\\') len--; + libname = filepath + len; + + ima = image_alloc(libname, IMA_SRC_FILE, IMA_TYPE_IMAGE); + BLI_strncpy(ima->name, filepath, sizeof(ima->name)); + + if (BLI_testextensie_array(filepath, imb_ext_movie)) + ima->source = IMA_SRC_MOVIE; + + return ima; +} /* checks if image was already loaded, then returns same image */ /* otherwise creates new. */ /* does not load ibuf itself */ /* pass on optional frame for #name images */ -Image *BKE_add_image_file(const char *name) +Image *BKE_image_load_exists(const char *filepath) { Image *ima; - int file, len; - const char *libname; char str[FILE_MAX], strtest[FILE_MAX]; - BLI_strncpy(str, name, sizeof(str)); + BLI_strncpy(str, filepath, sizeof(str)); BLI_path_abs(str, G.main->name); - - /* exists? */ - file= BLI_open(str, O_BINARY|O_RDONLY, 0); - if (file== -1) return NULL; - close(file); - + /* first search an identical image */ - for (ima= G.main->image.first; ima; ima= ima->id.next) { - if (ima->source!=IMA_SRC_VIEWER && ima->source!=IMA_SRC_GENERATED) { + for (ima = G.main->image.first; ima; ima = ima->id.next) { + if (ima->source != IMA_SRC_VIEWER && ima->source != IMA_SRC_GENERATED) { BLI_strncpy(strtest, ima->name, sizeof(ima->name)); BLI_path_abs(strtest, G.main->name); - if (BLI_path_cmp(strtest, str)==0) { - if (ima->anim==NULL || ima->id.us==0) { - BLI_strncpy(ima->name, name, sizeof(ima->name)); /* for stringcode */ - ima->id.us++; /* officially should not, it doesn't link here! */ - if (ima->ok==0) - ima->ok= IMA_OK; + if (BLI_path_cmp(strtest, str) == 0) { + if (ima->anim == NULL || ima->id.us == 0) { + BLI_strncpy(ima->name, filepath, sizeof(ima->name)); /* for stringcode */ + ima->id.us++; /* officially should not, it doesn't link here! */ + if (ima->ok == 0) + ima->ok = IMA_OK; /* RETURN! */ return ima; } } } } - /* add new image */ - - /* create a short library name */ - len= strlen(name); - - while (len > 0 && name[len - 1] != '/' && name[len - 1] != '\\') len--; - libname= name+len; - - ima= image_alloc(libname, IMA_SRC_FILE, IMA_TYPE_IMAGE); - BLI_strncpy(ima->name, name, sizeof(ima->name)); - - if (BLI_testextensie_array(name, imb_ext_movie)) - ima->source= IMA_SRC_MOVIE; - - return ima; + + return BKE_image_load(filepath); } static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short uvtestgrid, float color[4]) { ImBuf *ibuf; - unsigned char *rect= NULL; - float *rect_float= NULL; + unsigned char *rect = NULL; + float *rect_float = NULL; if (floatbuf) { - ibuf= IMB_allocImBuf(width, height, depth, IB_rectfloat); - rect_float= (float*)ibuf->rect_float; + ibuf = IMB_allocImBuf(width, height, depth, IB_rectfloat); + rect_float = (float *)ibuf->rect_float; } else { - ibuf= IMB_allocImBuf(width, height, depth, IB_rect); - rect= (unsigned char*)ibuf->rect; + ibuf = IMB_allocImBuf(width, height, depth, IB_rect); + rect = (unsigned char *)ibuf->rect; } BLI_strncpy(ibuf->name, name, sizeof(ibuf->name)); ibuf->userflags |= IB_BITMAPDIRTY; switch (uvtestgrid) { - case 1: - BKE_image_buf_fill_checker(rect, rect_float, width, height); - break; - case 2: - BKE_image_buf_fill_checker_color(rect, rect_float, width, height); - break; - default: - BKE_image_buf_fill_color(rect, rect_float, width, height, color); + case 1: + BKE_image_buf_fill_checker(rect, rect_float, width, height); + break; + case 2: + BKE_image_buf_fill_checker_color(rect, rect_float, width, height); + break; + default: + BKE_image_buf_fill_color(rect, rect_float, width, height, color); } return ibuf; } /* adds new image block, creates ImBuf and initializes color */ -Image *BKE_add_image_size(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short uvtestgrid, float color[4]) +Image *BKE_image_add_generated(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short uvtestgrid, float color[4]) { /* on save, type is changed to FILE in editsima.c */ - Image *ima= image_alloc(name, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST); + Image *ima = image_alloc(name, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST); if (ima) { ImBuf *ibuf; /* BLI_strncpy(ima->name, name, FILE_MAX); */ /* don't do this, this writes in ain invalid filepath! */ - ima->gen_x= width; - ima->gen_y= height; - ima->gen_type= uvtestgrid; + ima->gen_x = width; + ima->gen_y = height; + ima->gen_type = uvtestgrid; ima->gen_flag |= (floatbuf ? IMA_GEN_FLOAT : 0); - ibuf= add_ibuf_size(width, height, ima->name, depth, floatbuf, uvtestgrid, color); + ibuf = add_ibuf_size(width, height, ima->name, depth, floatbuf, uvtestgrid, color); image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); - ima->ok= IMA_OK_LOADED; + ima->ok = IMA_OK_LOADED; } return ima; } /* creates an image image owns the imbuf passed */ -Image *BKE_add_image_imbuf(ImBuf *ibuf) +Image *BKE_image_add_from_imbuf(ImBuf *ibuf) { /* on save, type is changed to FILE in editsima.c */ Image *ima; - ima= image_alloc(BLI_path_basename(ibuf->name), IMA_SRC_FILE, IMA_TYPE_IMAGE); + ima = image_alloc(BLI_path_basename(ibuf->name), IMA_SRC_FILE, IMA_TYPE_IMAGE); if (ima) { BLI_strncpy(ima->name, ibuf->name, FILE_MAX); image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); - ima->ok= IMA_OK_LOADED; + ima->ok = IMA_OK_LOADED; } return ima; @@ -636,20 +645,20 @@ Image *BKE_add_image_imbuf(ImBuf *ibuf) /* packs rect from memory as PNG */ void BKE_image_memorypack(Image *ima) { - ImBuf *ibuf= image_get_ibuf(ima, IMA_NO_INDEX, 0); + ImBuf *ibuf = image_get_ibuf(ima, IMA_NO_INDEX, 0); - if (ibuf==NULL) + if (ibuf == NULL) return; if (ima->packedfile) { freePackedFile(ima->packedfile); ima->packedfile = NULL; } - ibuf->ftype= PNG; - ibuf->planes= R_IMF_PLANES_RGBA; + ibuf->ftype = PNG; + ibuf->planes = R_IMF_PLANES_RGBA; IMB_saveiff(ibuf, ibuf->name, IB_rect | IB_mem); - if (ibuf->encodedbuffer==NULL) { + if (ibuf->encodedbuffer == NULL) { printf("memory save for pack error\n"); } else { @@ -657,19 +666,19 @@ void BKE_image_memorypack(Image *ima) pf->data = ibuf->encodedbuffer; pf->size = ibuf->encodedsize; - ima->packedfile= pf; - ibuf->encodedbuffer= NULL; - ibuf->encodedsize= 0; + ima->packedfile = pf; + ibuf->encodedbuffer = NULL; + ibuf->encodedsize = 0; ibuf->userflags &= ~IB_BITMAPDIRTY; - if (ima->source==IMA_SRC_GENERATED) { - ima->source= IMA_SRC_FILE; - ima->type= IMA_TYPE_IMAGE; + if (ima->source == IMA_SRC_GENERATED) { + ima->source = IMA_SRC_FILE; + ima->type = IMA_TYPE_IMAGE; } } } -void tag_image_time(Image *ima) +void BKE_image_tag_time(Image *ima) { if (ima) ima->lastused = (int)PIL_check_seconds_timer(); @@ -681,7 +690,7 @@ static void tag_all_images_time() Image *ima; int ctime = (int)PIL_check_seconds_timer(); - ima= G.main->image.first; + ima = G.main->image.first; while (ima) { if (ima->bindcode || ima->repbind || ima->ibufs.first) { ima->lastused = ctime; @@ -709,9 +718,9 @@ void free_old_images(void) lasttime = ctime; - ima= G.main->image.first; + ima = G.main->image.first; while (ima) { - if ((ima->flag & IMA_NOCOLLECT)==0 && ctime - ima->lastused > U.textimeout) { + if ((ima->flag & IMA_NOCOLLECT) == 0 && ctime - ima->lastused > U.textimeout) { /* If it's in GL memory, deallocate and set time tag to current time * This gives textures a "second chance" to be used before dying. */ if (ima->bindcode || ima->repbind) { @@ -733,18 +742,18 @@ static uintptr_t image_mem_size(Image *ima) int level; uintptr_t size = 0; - size= 0; + size = 0; /* viewers have memory depending on other rules, has no valid rect pointer */ - if (ima->source==IMA_SRC_VIEWER) + if (ima->source == IMA_SRC_VIEWER) return 0; - for (ibuf= ima->ibufs.first; ibuf; ibuf= ibuf->next) { + for (ibuf = ima->ibufs.first; ibuf; ibuf = ibuf->next) { if (ibuf->rect) size += MEM_allocN_len(ibuf->rect); else if (ibuf->rect_float) size += MEM_allocN_len(ibuf->rect_float); - for (level=0; level<IB_MIPMAP_LEVELS; level++) { - ibufm= ibuf->mipmap[level]; + for (level = 0; level < IB_MIPMAP_LEVELS; level++) { + ibufm = ibuf->mipmap[level]; if (ibufm) { if (ibufm->rect) size += MEM_allocN_len(ibufm->rect); else if (ibufm->rect_float) size += MEM_allocN_len(ibufm->rect_float); @@ -758,18 +767,18 @@ static uintptr_t image_mem_size(Image *ima) void BKE_image_print_memlist(void) { Image *ima; - uintptr_t size, totsize= 0; + uintptr_t size, totsize = 0; - for (ima= G.main->image.first; ima; ima= ima->id.next) + for (ima = G.main->image.first; ima; ima = ima->id.next) totsize += image_mem_size(ima); - printf("\ntotal image memory len: %.3f MB\n", (double)totsize/(double)(1024*1024)); + printf("\ntotal image memory len: %.3f MB\n", (double)totsize / (double)(1024 * 1024)); - for (ima= G.main->image.first; ima; ima= ima->id.next) { - size= image_mem_size(ima); + for (ima = G.main->image.first; ima; ima = ima->id.next) { + size = image_mem_size(ima); if (size) - printf("%s len: %.3f MB\n", ima->id.name+2, (double)size/(double)(1024*1024)); + printf("%s len: %.3f MB\n", ima->id.name + 2, (double)size / (double)(1024 * 1024)); } } @@ -779,30 +788,30 @@ void BKE_image_free_all_textures(void) Image *ima; /* unsigned int totsize= 0; */ - for (ima= G.main->image.first; ima; ima= ima->id.next) + for (ima = G.main->image.first; ima; ima = ima->id.next) ima->id.flag &= ~LIB_DOIT; - for (tex= G.main->tex.first; tex; tex= tex->id.next) + for (tex = G.main->tex.first; tex; tex = tex->id.next) if (tex->ima) tex->ima->id.flag |= LIB_DOIT; - for (ima= G.main->image.first; ima; ima= ima->id.next) { + for (ima = G.main->image.first; ima; ima = ima->id.next) { if (ima->ibufs.first && (ima->id.flag & LIB_DOIT)) { ImBuf *ibuf; - for (ibuf= ima->ibufs.first; ibuf; ibuf= ibuf->next) { + for (ibuf = ima->ibufs.first; ibuf; ibuf = ibuf->next) { /* escape when image is painted on */ if (ibuf->userflags & IB_BITMAPDIRTY) break; #if 0 if (ibuf->mipmap[0]) - totsize+= 1.33*ibuf->x*ibuf->y*4; + totsize += 1.33 * ibuf->x * ibuf->y * 4; else - totsize+= ibuf->x*ibuf->y*4; + totsize += ibuf->x * ibuf->y * 4; #endif } - if (ibuf==NULL) + if (ibuf == NULL) image_free_buffers(ima); } } @@ -814,13 +823,13 @@ void BKE_image_free_anim_ibufs(Image *ima, int except_frame) { ImBuf *ibuf, *nbuf; - for (ibuf= ima->ibufs.first; ibuf; ibuf= nbuf) { - nbuf= ibuf->next; + for (ibuf = ima->ibufs.first; ibuf; ibuf = nbuf) { + nbuf = ibuf->next; if (ibuf->userflags & IB_BITMAPDIRTY) continue; - if (ibuf->index==IMA_NO_INDEX) + if (ibuf->index == IMA_NO_INDEX) continue; - if (except_frame!=IMA_INDEX_FRAME(ibuf->index)) { + if (except_frame != IMA_INDEX_FRAME(ibuf->index)) { BLI_remlink(&ima->ibufs, ibuf); if (ibuf->userdata) { @@ -836,7 +845,7 @@ void BKE_image_all_free_anim_ibufs(int cfra) { Image *ima; - for (ima= G.main->image.first; ima; ima= ima->id.next) + for (ima = G.main->image.first; ima; ima = ima->id.next) if (ELEM(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) BKE_image_free_anim_ibufs(ima, cfra); } @@ -846,47 +855,47 @@ void BKE_image_all_free_anim_ibufs(int cfra) int BKE_imtype_to_ftype(const char imtype) { - if (imtype==R_IMF_IMTYPE_TARGA) + if (imtype == R_IMF_IMTYPE_TARGA) return TGA; - else if (imtype==R_IMF_IMTYPE_RAWTGA) + else if (imtype == R_IMF_IMTYPE_RAWTGA) return RAWTGA; - else if (imtype== R_IMF_IMTYPE_IRIS) + else if (imtype == R_IMF_IMTYPE_IRIS) return IMAGIC; #ifdef WITH_HDR - else if (imtype==R_IMF_IMTYPE_RADHDR) + else if (imtype == R_IMF_IMTYPE_RADHDR) return RADHDR; #endif - else if (imtype==R_IMF_IMTYPE_PNG) + else if (imtype == R_IMF_IMTYPE_PNG) return PNG; #ifdef WITH_DDS - else if (imtype==R_IMF_IMTYPE_DDS) + else if (imtype == R_IMF_IMTYPE_DDS) return DDS; #endif - else if (imtype==R_IMF_IMTYPE_BMP) + else if (imtype == R_IMF_IMTYPE_BMP) return BMP; #ifdef WITH_TIFF - else if (imtype==R_IMF_IMTYPE_TIFF) + else if (imtype == R_IMF_IMTYPE_TIFF) return TIF; #endif - else if (imtype==R_IMF_IMTYPE_OPENEXR || imtype==R_IMF_IMTYPE_MULTILAYER) + else if (imtype == R_IMF_IMTYPE_OPENEXR || imtype == R_IMF_IMTYPE_MULTILAYER) return OPENEXR; #ifdef WITH_CINEON - else if (imtype==R_IMF_IMTYPE_CINEON) + else if (imtype == R_IMF_IMTYPE_CINEON) return CINEON; - else if (imtype==R_IMF_IMTYPE_DPX) + else if (imtype == R_IMF_IMTYPE_DPX) return DPX; #endif #ifdef WITH_OPENJPEG - else if (imtype==R_IMF_IMTYPE_JP2) + else if (imtype == R_IMF_IMTYPE_JP2) return JP2; #endif else - return JPG|90; + return JPG | 90; } char BKE_ftype_to_imtype(const int ftype) { - if (ftype==0) + if (ftype == 0) return R_IMF_IMTYPE_TARGA; else if (ftype == IMAGIC) return R_IMF_IMTYPE_IRIS; @@ -930,15 +939,15 @@ char BKE_ftype_to_imtype(const int ftype) int BKE_imtype_is_movie(const char imtype) { switch (imtype) { - case R_IMF_IMTYPE_AVIRAW: - case R_IMF_IMTYPE_AVIJPEG: - case R_IMF_IMTYPE_AVICODEC: - case R_IMF_IMTYPE_QUICKTIME: - case R_IMF_IMTYPE_FFMPEG: - case R_IMF_IMTYPE_H264: - case R_IMF_IMTYPE_THEORA: - case R_IMF_IMTYPE_XVID: - case R_IMF_IMTYPE_FRAMESERVER: + case R_IMF_IMTYPE_AVIRAW: + case R_IMF_IMTYPE_AVIJPEG: + case R_IMF_IMTYPE_AVICODEC: + case R_IMF_IMTYPE_QUICKTIME: + case R_IMF_IMTYPE_FFMPEG: + case R_IMF_IMTYPE_H264: + case R_IMF_IMTYPE_THEORA: + case R_IMF_IMTYPE_XVID: + case R_IMF_IMTYPE_FRAMESERVER: return 1; } return 0; @@ -947,8 +956,8 @@ int BKE_imtype_is_movie(const char imtype) int BKE_imtype_supports_zbuf(const char imtype) { switch (imtype) { - case R_IMF_IMTYPE_IRIZ: - case R_IMF_IMTYPE_OPENEXR: /* but not R_IMF_IMTYPE_MULTILAYER */ + case R_IMF_IMTYPE_IRIZ: + case R_IMF_IMTYPE_OPENEXR: /* but not R_IMF_IMTYPE_MULTILAYER */ return 1; } return 0; @@ -957,7 +966,7 @@ int BKE_imtype_supports_zbuf(const char imtype) int BKE_imtype_supports_compress(const char imtype) { switch (imtype) { - case R_IMF_IMTYPE_PNG: + case R_IMF_IMTYPE_PNG: return 1; } return 0; @@ -966,9 +975,9 @@ int BKE_imtype_supports_compress(const char imtype) int BKE_imtype_supports_quality(const char imtype) { switch (imtype) { - case R_IMF_IMTYPE_JPEG90: - case R_IMF_IMTYPE_JP2: - case R_IMF_IMTYPE_AVIJPEG: + case R_IMF_IMTYPE_JPEG90: + case R_IMF_IMTYPE_JP2: + case R_IMF_IMTYPE_AVIJPEG: return 1; } return 0; @@ -976,32 +985,32 @@ int BKE_imtype_supports_quality(const char imtype) char BKE_imtype_valid_channels(const char imtype) { - char chan_flag= IMA_CHAN_FLAG_RGB; /* assume all support rgb */ + char chan_flag = IMA_CHAN_FLAG_RGB; /* assume all support rgb */ /* alpha */ switch (imtype) { - case R_IMF_IMTYPE_TARGA: - case R_IMF_IMTYPE_IRIS: - case R_IMF_IMTYPE_PNG: - /* case R_IMF_IMTYPE_BMP: */ /* read but not write */ - case R_IMF_IMTYPE_RADHDR: - case R_IMF_IMTYPE_TIFF: - case R_IMF_IMTYPE_OPENEXR: - case R_IMF_IMTYPE_MULTILAYER: - case R_IMF_IMTYPE_DDS: - case R_IMF_IMTYPE_JP2: - case R_IMF_IMTYPE_QUICKTIME: + case R_IMF_IMTYPE_TARGA: + case R_IMF_IMTYPE_IRIS: + case R_IMF_IMTYPE_PNG: + /* case R_IMF_IMTYPE_BMP: */ /* read but not write */ + case R_IMF_IMTYPE_RADHDR: + case R_IMF_IMTYPE_TIFF: + case R_IMF_IMTYPE_OPENEXR: + case R_IMF_IMTYPE_MULTILAYER: + case R_IMF_IMTYPE_DDS: + case R_IMF_IMTYPE_JP2: + case R_IMF_IMTYPE_QUICKTIME: chan_flag |= IMA_CHAN_FLAG_ALPHA; } /* bw */ switch (imtype) { - case R_IMF_IMTYPE_PNG: - case R_IMF_IMTYPE_JPEG90: - case R_IMF_IMTYPE_TARGA: - case R_IMF_IMTYPE_RAWTGA: - case R_IMF_IMTYPE_TIFF: - case R_IMF_IMTYPE_IRIS: + case R_IMF_IMTYPE_PNG: + case R_IMF_IMTYPE_JPEG90: + case R_IMF_IMTYPE_TARGA: + case R_IMF_IMTYPE_RAWTGA: + case R_IMF_IMTYPE_TIFF: + case R_IMF_IMTYPE_IRIS: chan_flag |= IMA_CHAN_FLAG_BW; } @@ -1011,23 +1020,23 @@ char BKE_imtype_valid_channels(const char imtype) char BKE_imtype_valid_depths(const char imtype) { switch (imtype) { - case R_IMF_IMTYPE_RADHDR: - return R_IMF_CHAN_DEPTH_32; - case R_IMF_IMTYPE_TIFF: - return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_16; - case R_IMF_IMTYPE_OPENEXR: - return R_IMF_CHAN_DEPTH_16 | R_IMF_CHAN_DEPTH_32; - case R_IMF_IMTYPE_MULTILAYER: - return R_IMF_CHAN_DEPTH_32; - /* eeh, cineone does some strange 10bits per channel */ - case R_IMF_IMTYPE_DPX: - case R_IMF_IMTYPE_CINEON: - return R_IMF_CHAN_DEPTH_12; - case R_IMF_IMTYPE_JP2: - return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_12 | R_IMF_CHAN_DEPTH_16; - /* most formats are 8bit only */ - default: - return R_IMF_CHAN_DEPTH_8; + case R_IMF_IMTYPE_RADHDR: + return R_IMF_CHAN_DEPTH_32; + case R_IMF_IMTYPE_TIFF: + return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_16; + case R_IMF_IMTYPE_OPENEXR: + return R_IMF_CHAN_DEPTH_16 | R_IMF_CHAN_DEPTH_32; + case R_IMF_IMTYPE_MULTILAYER: + return R_IMF_CHAN_DEPTH_32; + /* eeh, cineone does some strange 10bits per channel */ + case R_IMF_IMTYPE_DPX: + case R_IMF_IMTYPE_CINEON: + return R_IMF_CHAN_DEPTH_12; + case R_IMF_IMTYPE_JP2: + return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_12 | R_IMF_CHAN_DEPTH_16; + /* most formats are 8bit only */ + default: + return R_IMF_CHAN_DEPTH_8; } } @@ -1074,78 +1083,78 @@ char BKE_imtype_from_arg(const char *imtype_arg) int BKE_add_image_extension(char *string, const char imtype) { - const char *extension= NULL; + const char *extension = NULL; - if (imtype== R_IMF_IMTYPE_IRIS) { + if (imtype == R_IMF_IMTYPE_IRIS) { if (!BLI_testextensie(string, ".rgb")) - extension= ".rgb"; + extension = ".rgb"; } - else if (imtype==R_IMF_IMTYPE_IRIZ) { + else if (imtype == R_IMF_IMTYPE_IRIZ) { if (!BLI_testextensie(string, ".rgb")) - extension= ".rgb"; + extension = ".rgb"; } #ifdef WITH_HDR - else if (imtype==R_IMF_IMTYPE_RADHDR) { + else if (imtype == R_IMF_IMTYPE_RADHDR) { if (!BLI_testextensie(string, ".hdr")) - extension= ".hdr"; + extension = ".hdr"; } #endif else if (ELEM5(imtype, R_IMF_IMTYPE_PNG, R_IMF_IMTYPE_FFMPEG, R_IMF_IMTYPE_H264, R_IMF_IMTYPE_THEORA, R_IMF_IMTYPE_XVID)) { if (!BLI_testextensie(string, ".png")) - extension= ".png"; + extension = ".png"; } #ifdef WITH_DDS - else if (imtype==R_IMF_IMTYPE_DDS) { + else if (imtype == R_IMF_IMTYPE_DDS) { if (!BLI_testextensie(string, ".dds")) - extension= ".dds"; + extension = ".dds"; } #endif - else if (imtype==R_IMF_IMTYPE_RAWTGA) { + else if (imtype == R_IMF_IMTYPE_RAWTGA) { if (!BLI_testextensie(string, ".tga")) - extension= ".tga"; + extension = ".tga"; } - else if (imtype==R_IMF_IMTYPE_BMP) { + else if (imtype == R_IMF_IMTYPE_BMP) { if (!BLI_testextensie(string, ".bmp")) - extension= ".bmp"; + extension = ".bmp"; } #ifdef WITH_TIFF - else if (imtype==R_IMF_IMTYPE_TIFF) { + else if (imtype == R_IMF_IMTYPE_TIFF) { if (!BLI_testextensie(string, ".tif") && !BLI_testextensie(string, ".tiff")) { - extension= ".tif"; + extension = ".tif"; } } #endif #ifdef WITH_OPENEXR else if (ELEM(imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER)) { if (!BLI_testextensie(string, ".exr")) - extension= ".exr"; + extension = ".exr"; } #endif #ifdef WITH_CINEON - else if (imtype==R_IMF_IMTYPE_CINEON) { + else if (imtype == R_IMF_IMTYPE_CINEON) { if (!BLI_testextensie(string, ".cin")) - extension= ".cin"; + extension = ".cin"; } - else if (imtype==R_IMF_IMTYPE_DPX) { + else if (imtype == R_IMF_IMTYPE_DPX) { if (!BLI_testextensie(string, ".dpx")) - extension= ".dpx"; + extension = ".dpx"; } #endif - else if (imtype==R_IMF_IMTYPE_TARGA) { + else if (imtype == R_IMF_IMTYPE_TARGA) { if (!BLI_testextensie(string, ".tga")) - extension= ".tga"; + extension = ".tga"; } #ifdef WITH_OPENJPEG - else if (imtype==R_IMF_IMTYPE_JP2) { + else if (imtype == R_IMF_IMTYPE_JP2) { if (!BLI_testextensie(string, ".jp2")) - extension= ".jp2"; + extension = ".jp2"; } #endif else { // R_IMF_IMTYPE_AVICODEC, R_IMF_IMTYPE_AVIRAW, R_IMF_IMTYPE_AVIJPEG, R_IMF_IMTYPE_JPEG90, R_IMF_IMTYPE_QUICKTIME etc if (!(BLI_testextensie(string, ".jpg") || BLI_testextensie(string, ".jpeg"))) - extension= ".jpg"; + extension = ".jpg"; } if (extension) { @@ -1177,17 +1186,17 @@ void BKE_imformat_defaults(ImageFormatData *im_format) /* could allow access externally - 512 is for long names, 64 is for id names */ typedef struct StampData { - char file[512]; - char note[512]; - char date[512]; - char marker[512]; - char time[512]; - char frame[512]; - char camera[64]; - char cameralens[64]; - char scene[64]; - char strip[64]; - char rendertime[64]; + char file[512]; + char note[512]; + char date[512]; + char marker[512]; + char time[512]; + char frame[512]; + char camera[64]; + char cameralens[64]; + char scene[64]; + char strip[64]; + char rendertime[64]; } StampData; static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int do_prefix) @@ -1197,7 +1206,7 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d time_t t; if (scene->r.stamp & R_STAMP_FILENAME) { - BLI_snprintf(stamp_data->file, sizeof(stamp_data->file), do_prefix ? "File %s":"%s", G.relbase_valid ? G.main->name:"<untitled>"); + BLI_snprintf(stamp_data->file, sizeof(stamp_data->file), do_prefix ? "File %s" : "%s", G.relbase_valid ? G.main->name : "<untitled>"); } else { stamp_data->file[0] = '\0'; @@ -1214,20 +1223,20 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d if (scene->r.stamp & R_STAMP_DATE) { t = time(NULL); tl = localtime(&t); - BLI_snprintf(text, sizeof(text), "%04d/%02d/%02d %02d:%02d:%02d", tl->tm_year+1900, tl->tm_mon+1, tl->tm_mday, tl->tm_hour, tl->tm_min, tl->tm_sec); - BLI_snprintf(stamp_data->date, sizeof(stamp_data->date), do_prefix ? "Date %s":"%s", text); + BLI_snprintf(text, sizeof(text), "%04d/%02d/%02d %02d:%02d:%02d", tl->tm_year + 1900, tl->tm_mon + 1, tl->tm_mday, tl->tm_hour, tl->tm_min, tl->tm_sec); + BLI_snprintf(stamp_data->date, sizeof(stamp_data->date), do_prefix ? "Date %s" : "%s", text); } else { stamp_data->date[0] = '\0'; } if (scene->r.stamp & R_STAMP_MARKER) { - char *name = scene_find_last_marker_name(scene, CFRA); + char *name = BKE_scene_find_last_marker_name(scene, CFRA); - if (name) BLI_strncpy(text, name, sizeof(text)); - else BLI_strncpy(text, "<none>", sizeof(text)); + if (name) BLI_strncpy(text, name, sizeof(text)); + else BLI_strncpy(text, "<none>", sizeof(text)); - BLI_snprintf(stamp_data->marker, sizeof(stamp_data->marker), do_prefix ? "Marker %s":"%s", text); + BLI_snprintf(stamp_data->marker, sizeof(stamp_data->marker), do_prefix ? "Marker %s" : "%s", text); } else { stamp_data->marker[0] = '\0'; @@ -1236,8 +1245,8 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d if (scene->r.stamp & R_STAMP_TIME) { int f = (int)(scene->r.cfra % scene->r.frs_sec); int s = (int)(scene->r.cfra / scene->r.frs_sec); - int h= 0; - int m= 0; + int h = 0; + int m = 0; if (s) { m = (int)(s / 60); @@ -1254,7 +1263,7 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d else BLI_snprintf(text, sizeof(text), "%02d:%02d:%02d.%03d", h, m, s, f); - BLI_snprintf(stamp_data->time, sizeof(stamp_data->time), do_prefix ? "Time %s":"%s", text); + BLI_snprintf(stamp_data->time, sizeof(stamp_data->time), do_prefix ? "Time %s" : "%s", text); } else { stamp_data->time[0] = '\0'; @@ -1262,20 +1271,20 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d if (scene->r.stamp & R_STAMP_FRAME) { char fmtstr[32]; - int digits= 1; + int digits = 1; - if (scene->r.efra>9) - digits= 1 + (int) log10(scene->r.efra); + if (scene->r.efra > 9) + digits = 1 + (int) log10(scene->r.efra); - BLI_snprintf(fmtstr, sizeof(fmtstr), do_prefix ? "Frame %%0%di":"%%0%di", digits); - BLI_snprintf (stamp_data->frame, sizeof(stamp_data->frame), fmtstr, scene->r.cfra); + BLI_snprintf(fmtstr, sizeof(fmtstr), do_prefix ? "Frame %%0%di" : "%%0%di", digits); + BLI_snprintf(stamp_data->frame, sizeof(stamp_data->frame), fmtstr, scene->r.cfra); } else { stamp_data->frame[0] = '\0'; } if (scene->r.stamp & R_STAMP_CAMERA) { - BLI_snprintf(stamp_data->camera, sizeof(stamp_data->camera), do_prefix ? "Camera %s":"%s", camera ? camera->id.name+2 : "<none>"); + BLI_snprintf(stamp_data->camera, sizeof(stamp_data->camera), do_prefix ? "Camera %s" : "%s", camera ? camera->id.name + 2 : "<none>"); } else { stamp_data->camera[0] = '\0'; @@ -1285,41 +1294,41 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d if (camera && camera->type == OB_CAMERA) { BLI_snprintf(text, sizeof(text), "%.2f", ((Camera *)camera->data)->lens); } - else BLI_strncpy(text, "<none>", sizeof(text)); + else BLI_strncpy(text, "<none>", sizeof(text)); - BLI_snprintf(stamp_data->cameralens, sizeof(stamp_data->cameralens), do_prefix ? "Lens %s":"%s", text); + BLI_snprintf(stamp_data->cameralens, sizeof(stamp_data->cameralens), do_prefix ? "Lens %s" : "%s", text); } else { stamp_data->cameralens[0] = '\0'; } if (scene->r.stamp & R_STAMP_SCENE) { - BLI_snprintf(stamp_data->scene, sizeof(stamp_data->scene), do_prefix ? "Scene %s":"%s", scene->id.name+2); + BLI_snprintf(stamp_data->scene, sizeof(stamp_data->scene), do_prefix ? "Scene %s" : "%s", scene->id.name + 2); } else { stamp_data->scene[0] = '\0'; } if (scene->r.stamp & R_STAMP_SEQSTRIP) { - Sequence *seq= seq_foreground_frame_get(scene, scene->r.cfra); + Sequence *seq = seq_foreground_frame_get(scene, scene->r.cfra); - if (seq) BLI_strncpy(text, seq->name+2, sizeof(text)); - else BLI_strncpy(text, "<none>", sizeof(text)); + if (seq) BLI_strncpy(text, seq->name + 2, sizeof(text)); + else BLI_strncpy(text, "<none>", sizeof(text)); - BLI_snprintf(stamp_data->strip, sizeof(stamp_data->strip), do_prefix ? "Strip %s":"%s", text); + BLI_snprintf(stamp_data->strip, sizeof(stamp_data->strip), do_prefix ? "Strip %s" : "%s", text); } else { stamp_data->strip[0] = '\0'; } { - Render *re= RE_GetRender(scene->id.name); - RenderStats *stats= re ? RE_GetStats(re):NULL; + Render *re = RE_GetRender(scene->id.name); + RenderStats *stats = re ? RE_GetStats(re) : NULL; if (stats && (scene->r.stamp & R_STAMP_RENDERTIME)) { BLI_timestr(stats->lastframetime, text); - BLI_snprintf(stamp_data->rendertime, sizeof(stamp_data->rendertime), do_prefix ? "RenderTime %s":"%s", text); + BLI_snprintf(stamp_data->rendertime, sizeof(stamp_data->rendertime), do_prefix ? "RenderTime %s" : "%s", text); } else { stamp_data->rendertime[0] = '\0'; @@ -1333,7 +1342,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec float w, h, pad; int x, y, y_ofs; float h_fixed; - const int mono= blf_mono_font_render; // XXX + const int mono = blf_mono_font_render; // XXX #define BUFF_MARGIN_X 2 #define BUFF_MARGIN_Y 1 @@ -1345,29 +1354,29 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec /* TODO, do_versions */ if (scene->r.stamp_font_id < 8) - scene->r.stamp_font_id= 12; + scene->r.stamp_font_id = 12; /* set before return */ BLF_size(mono, scene->r.stamp_font_id, 72); BLF_buffer(mono, rectf, rect, width, height, channels); BLF_buffer_col(mono, scene->r.fg_stamp[0], scene->r.fg_stamp[1], scene->r.fg_stamp[2], 1.0); - pad= BLF_width_max(mono); + pad = BLF_width_max(mono); /* use 'h_fixed' rather than 'h', aligns better */ - h_fixed= BLF_height_max(mono); + h_fixed = BLF_height_max(mono); y_ofs = -BLF_descender(mono); - x= 0; - y= height; + x = 0; + y = height; if (stamp_data.file[0]) { /* Top left corner */ - BLF_width_and_height(mono, stamp_data.file, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.file, &w, &h); h = h_fixed; y -= h; /* also a little of space to the background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); /* and draw the text. */ BLF_position(mono, x, y + y_ofs, 0.0); @@ -1379,11 +1388,11 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec /* Top left corner, below File */ if (stamp_data.note[0]) { - BLF_width_and_height(mono, stamp_data.note, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.note, &w, &h); h = h_fixed; y -= h; /* and space for background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-BUFF_MARGIN_Y, w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); BLF_draw_buffer(mono, stamp_data.note); @@ -1394,11 +1403,11 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec /* Top left corner, below File (or Note) */ if (stamp_data.date[0]) { - BLF_width_and_height(mono, stamp_data.date, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.date, &w, &h); h = h_fixed; y -= h; /* and space for background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-BUFF_MARGIN_Y, w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); BLF_draw_buffer(mono, stamp_data.date); @@ -1409,25 +1418,25 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec /* Top left corner, below File, Date or Note */ if (stamp_data.rendertime[0]) { - BLF_width_and_height(mono, stamp_data.rendertime, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.rendertime, &w, &h); h = h_fixed; y -= h; /* and space for background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-BUFF_MARGIN_Y, w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); BLF_draw_buffer(mono, stamp_data.rendertime); } - x= 0; - y= 0; + x = 0; + y = 0; /* Bottom left corner, leaving space for timing */ if (stamp_data.marker[0]) { - BLF_width_and_height(mono, stamp_data.marker, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.marker, &w, &h); h = h_fixed; /* extra space for background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); @@ -1439,10 +1448,10 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec /* Left bottom corner */ if (stamp_data.time[0]) { - BLF_width_and_height(mono, stamp_data.time, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.time, &w, &h); h = h_fixed; /* extra space for background */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); @@ -1453,10 +1462,10 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec } if (stamp_data.frame[0]) { - BLF_width_and_height(mono, stamp_data.frame, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.frame, &w, &h); h = h_fixed; /* extra space for background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); @@ -1467,10 +1476,10 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec } if (stamp_data.camera[0]) { - BLF_width_and_height(mono, stamp_data.camera, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.camera, &w, &h); h = h_fixed; /* extra space for background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); BLF_draw_buffer(mono, stamp_data.camera); @@ -1479,37 +1488,37 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec } if (stamp_data.cameralens[0]) { - BLF_width_and_height(mono, stamp_data.cameralens, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.cameralens, &w, &h); h = h_fixed; /* extra space for background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); BLF_draw_buffer(mono, stamp_data.cameralens); } if (stamp_data.scene[0]) { - BLF_width_and_height(mono, stamp_data.scene, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.scene, &w, &h); h = h_fixed; /* Bottom right corner, with an extra space because blenfont is too strict! */ - x= width - w - 2; + x = width - w - 2; /* extra space for background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); /* and pad the text. */ - BLF_position(mono, x, y+y_ofs, 0.0); + BLF_position(mono, x, y + y_ofs, 0.0); BLF_draw_buffer(mono, stamp_data.scene); } if (stamp_data.strip[0]) { - BLF_width_and_height(mono, stamp_data.strip, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.strip, &w, &h); h = h_fixed; /* Top right corner, with an extra space because blenfont is too strict! */ - x= width - w - pad; - y= height - h; + x = width - w - pad; + y = height - h; /* extra space for background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); BLF_draw_buffer(mono, stamp_data.strip); @@ -1522,42 +1531,42 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec #undef BUFF_MARGIN_Y } -void BKE_stamp_info(Scene *scene, Object *camera, struct ImBuf *ibuf) +void BKE_imbuf_stamp_info(Scene *scene, Object *camera, struct ImBuf *ibuf) { struct StampData stamp_data; - if (!ibuf) return; + if (!ibuf) return; /* fill all the data values, no prefix */ stampdata(scene, camera, &stamp_data, 0); - if (stamp_data.file[0]) IMB_metadata_change_field (ibuf, "File", stamp_data.file); - if (stamp_data.note[0]) IMB_metadata_change_field (ibuf, "Note", stamp_data.note); - if (stamp_data.date[0]) IMB_metadata_change_field (ibuf, "Date", stamp_data.date); - if (stamp_data.marker[0]) IMB_metadata_change_field (ibuf, "Marker", stamp_data.marker); - if (stamp_data.time[0]) IMB_metadata_change_field (ibuf, "Time", stamp_data.time); - if (stamp_data.frame[0]) IMB_metadata_change_field (ibuf, "Frame", stamp_data.frame); - if (stamp_data.camera[0]) IMB_metadata_change_field (ibuf, "Camera", stamp_data.camera); - if (stamp_data.cameralens[0]) IMB_metadata_change_field (ibuf, "Lens", stamp_data.cameralens); - if (stamp_data.scene[0]) IMB_metadata_change_field (ibuf, "Scene", stamp_data.scene); - if (stamp_data.strip[0]) IMB_metadata_change_field (ibuf, "Strip", stamp_data.strip); - if (stamp_data.rendertime[0]) IMB_metadata_change_field (ibuf, "RenderTime", stamp_data.rendertime); + if (stamp_data.file[0]) IMB_metadata_change_field(ibuf, "File", stamp_data.file); + if (stamp_data.note[0]) IMB_metadata_change_field(ibuf, "Note", stamp_data.note); + if (stamp_data.date[0]) IMB_metadata_change_field(ibuf, "Date", stamp_data.date); + if (stamp_data.marker[0]) IMB_metadata_change_field(ibuf, "Marker", stamp_data.marker); + if (stamp_data.time[0]) IMB_metadata_change_field(ibuf, "Time", stamp_data.time); + if (stamp_data.frame[0]) IMB_metadata_change_field(ibuf, "Frame", stamp_data.frame); + if (stamp_data.camera[0]) IMB_metadata_change_field(ibuf, "Camera", stamp_data.camera); + if (stamp_data.cameralens[0]) IMB_metadata_change_field(ibuf, "Lens", stamp_data.cameralens); + if (stamp_data.scene[0]) IMB_metadata_change_field(ibuf, "Scene", stamp_data.scene); + if (stamp_data.strip[0]) IMB_metadata_change_field(ibuf, "Strip", stamp_data.strip); + if (stamp_data.rendertime[0]) IMB_metadata_change_field(ibuf, "RenderTime", stamp_data.rendertime); } -int BKE_alphatest_ibuf(ImBuf *ibuf) +int BKE_imbuf_alpha_test(ImBuf *ibuf) { int tot; if (ibuf->rect_float) { - float *buf= ibuf->rect_float; - for (tot= ibuf->x * ibuf->y; tot--; buf+=4) { + float *buf = ibuf->rect_float; + for (tot = ibuf->x * ibuf->y; tot--; buf += 4) { if (buf[3] < 1.0f) { return TRUE; } } } else if (ibuf->rect) { - unsigned char *buf= (unsigned char *)ibuf->rect; - for (tot= ibuf->x * ibuf->y; tot--; buf+=4) { + unsigned char *buf = (unsigned char *)ibuf->rect; + for (tot = ibuf->x * ibuf->y; tot--; buf += 4) { if (buf[3] != 255) { return TRUE; } @@ -1569,75 +1578,75 @@ int BKE_alphatest_ibuf(ImBuf *ibuf) /* note: imf->planes is ignored here, its assumed the image channels * are already set */ -int BKE_write_ibuf(ImBuf *ibuf, const char *name, ImageFormatData *imf) +int BKE_imbuf_write(ImBuf *ibuf, const char *name, ImageFormatData *imf) { - char imtype= imf->imtype; - char compress= imf->compress; - char quality= imf->quality; + char imtype = imf->imtype; + char compress = imf->compress; + char quality = imf->quality; int ok; - if (imtype== R_IMF_IMTYPE_IRIS) { - ibuf->ftype= IMAGIC; + if (imtype == R_IMF_IMTYPE_IRIS) { + ibuf->ftype = IMAGIC; } #ifdef WITH_HDR - else if (imtype==R_IMF_IMTYPE_RADHDR) { - ibuf->ftype= RADHDR; + else if (imtype == R_IMF_IMTYPE_RADHDR) { + ibuf->ftype = RADHDR; } #endif else if (ELEM5(imtype, R_IMF_IMTYPE_PNG, R_IMF_IMTYPE_FFMPEG, R_IMF_IMTYPE_H264, R_IMF_IMTYPE_THEORA, R_IMF_IMTYPE_XVID)) { - ibuf->ftype= PNG; + ibuf->ftype = PNG; - if (imtype==R_IMF_IMTYPE_PNG) + if (imtype == R_IMF_IMTYPE_PNG) ibuf->ftype |= compress; } #ifdef WITH_DDS - else if (imtype==R_IMF_IMTYPE_DDS) { - ibuf->ftype= DDS; + else if (imtype == R_IMF_IMTYPE_DDS) { + ibuf->ftype = DDS; } #endif - else if (imtype==R_IMF_IMTYPE_BMP) { - ibuf->ftype= BMP; + else if (imtype == R_IMF_IMTYPE_BMP) { + ibuf->ftype = BMP; } #ifdef WITH_TIFF - else if (imtype==R_IMF_IMTYPE_TIFF) { - ibuf->ftype= TIF; + else if (imtype == R_IMF_IMTYPE_TIFF) { + ibuf->ftype = TIF; if (imf->depth == R_IMF_CHAN_DEPTH_16) ibuf->ftype |= TIF_16BIT; } #endif #ifdef WITH_OPENEXR - else if (imtype==R_IMF_IMTYPE_OPENEXR || imtype==R_IMF_IMTYPE_MULTILAYER) { - ibuf->ftype= OPENEXR; + else if (imtype == R_IMF_IMTYPE_OPENEXR || imtype == R_IMF_IMTYPE_MULTILAYER) { + ibuf->ftype = OPENEXR; if (imf->depth == R_IMF_CHAN_DEPTH_16) ibuf->ftype |= OPENEXR_HALF; ibuf->ftype |= (imf->exr_codec & OPENEXR_COMPRESS); if (!(imf->flag & R_IMF_FLAG_ZBUF)) - ibuf->zbuf_float = NULL; /* signal for exr saving */ + ibuf->zbuf_float = NULL; /* signal for exr saving */ } #endif #ifdef WITH_CINEON - else if (imtype==R_IMF_IMTYPE_CINEON) { + else if (imtype == R_IMF_IMTYPE_CINEON) { ibuf->ftype = CINEON; } - else if (imtype==R_IMF_IMTYPE_DPX) { + else if (imtype == R_IMF_IMTYPE_DPX) { ibuf->ftype = DPX; } #endif - else if (imtype==R_IMF_IMTYPE_TARGA) { - ibuf->ftype= TGA; + else if (imtype == R_IMF_IMTYPE_TARGA) { + ibuf->ftype = TGA; } - else if (imtype==R_IMF_IMTYPE_RAWTGA) { - ibuf->ftype= RAWTGA; + else if (imtype == R_IMF_IMTYPE_RAWTGA) { + ibuf->ftype = RAWTGA; } #ifdef WITH_OPENJPEG - else if (imtype==R_IMF_IMTYPE_JP2) { - if (quality < 10) quality= 90; - ibuf->ftype= JP2|quality; + else if (imtype == R_IMF_IMTYPE_JP2) { + if (quality < 10) quality = 90; + ibuf->ftype = JP2 | quality; if (imf->depth == R_IMF_CHAN_DEPTH_16) { ibuf->ftype |= JP2_16BIT; @@ -1659,8 +1668,8 @@ int BKE_write_ibuf(ImBuf *ibuf, const char *name, ImageFormatData *imf) #endif else { /* R_IMF_IMTYPE_JPEG90, etc. default we save jpegs */ - if (quality < 10) quality= 90; - ibuf->ftype= JPG|quality; + if (quality < 10) quality = 90; + ibuf->ftype = JPG | quality; } BLI_make_existing_file(name); @@ -1673,42 +1682,42 @@ int BKE_write_ibuf(ImBuf *ibuf, const char *name, ImageFormatData *imf) return(ok); } -/* same as BKE_write_ibuf() but crappy workaround not to perminantly modify +/* same as BKE_imbuf_write() but crappy workaround not to perminantly modify * _some_, values in the imbuf */ -int BKE_write_ibuf_as(ImBuf *ibuf, const char *name, ImageFormatData *imf, - const short save_copy) +int BKE_imbuf_write_as(ImBuf *ibuf, const char *name, ImageFormatData *imf, + const short save_copy) { - ImBuf ibuf_back= *ibuf; + ImBuf ibuf_back = *ibuf; int ok; /* all data is rgba anyway, * this just controls how to save for some formats */ - ibuf->planes= imf->planes; + ibuf->planes = imf->planes; - ok= BKE_write_ibuf(ibuf, name, imf); + ok = BKE_imbuf_write(ibuf, name, imf); if (save_copy) { /* note that we are not restoring _all_ settings */ - ibuf->planes= ibuf_back.planes; - ibuf->ftype= ibuf_back.ftype; + ibuf->planes = ibuf_back.planes; + ibuf->ftype = ibuf_back.ftype; } return ok; } -int BKE_write_ibuf_stamp(Scene *scene, struct Object *camera, ImBuf *ibuf, const char *name, struct ImageFormatData *imf) +int BKE_imbuf_write_stamp(Scene *scene, struct Object *camera, ImBuf *ibuf, const char *name, struct ImageFormatData *imf) { if (scene && scene->r.stamp & R_STAMP_ALL) - BKE_stamp_info(scene, camera, ibuf); + BKE_imbuf_stamp_info(scene, camera, ibuf); - return BKE_write_ibuf(ibuf, name, imf); + return BKE_imbuf_write(ibuf, name, imf); } void BKE_makepicstring(char *string, const char *base, const char *relbase, int frame, const char imtype, const short use_ext, const short use_frames) { - if (string==NULL) return; - BLI_strncpy(string, base, FILE_MAX - 10); /* weak assumption */ + if (string == NULL) return; + BLI_strncpy(string, base, FILE_MAX - 10); /* weak assumption */ BLI_path_abs(string, relbase); if (use_frames) @@ -1720,8 +1729,7 @@ void BKE_makepicstring(char *string, const char *base, const char *relbase, int } /* used by sequencer too */ -struct anim *openanim(const char *name, int flags, int streamindex) -{ +struct anim *openanim(const char *name, int flags, int streamindex){ struct anim *anim; struct ImBuf *ibuf; @@ -1769,16 +1777,16 @@ Image *BKE_image_verify_viewer(int type, const char *name) { Image *ima; - for (ima=G.main->image.first; ima; ima= ima->id.next) - if (ima->source==IMA_SRC_VIEWER) - if (ima->type==type) + for (ima = G.main->image.first; ima; ima = ima->id.next) + if (ima->source == IMA_SRC_VIEWER) + if (ima->type == type) break; - if (ima==NULL) - ima= image_alloc(name, IMA_SRC_VIEWER, type); + if (ima == NULL) + ima = image_alloc(name, IMA_SRC_VIEWER, type); /* happens on reload, imagewindow cannot be image user when hidden*/ - if (ima->id.us==0) + if (ima->id.us == 0) id_us_plus(&ima->id); return ima; @@ -1791,78 +1799,78 @@ void BKE_image_assign_ibuf(Image *ima, ImBuf *ibuf) void BKE_image_signal(Image *ima, ImageUser *iuser, int signal) { - if (ima==NULL) + if (ima == NULL) return; switch (signal) { - case IMA_SIGNAL_FREE: - image_free_buffers(ima); - if (iuser) - iuser->ok= 1; - break; - case IMA_SIGNAL_SRC_CHANGE: - if (ima->type == IMA_TYPE_UV_TEST) - if (ima->source != IMA_SRC_GENERATED) - ima->type= IMA_TYPE_IMAGE; - - if (ima->source==IMA_SRC_GENERATED) { - if (ima->gen_x==0 || ima->gen_y==0) { - ImBuf *ibuf= image_get_ibuf(ima, IMA_NO_INDEX, 0); - if (ibuf) { - ima->gen_x= ibuf->x; - ima->gen_y= ibuf->y; + case IMA_SIGNAL_FREE: + image_free_buffers(ima); + if (iuser) + iuser->ok = 1; + break; + case IMA_SIGNAL_SRC_CHANGE: + if (ima->type == IMA_TYPE_UV_TEST) + if (ima->source != IMA_SRC_GENERATED) + ima->type = IMA_TYPE_IMAGE; + + if (ima->source == IMA_SRC_GENERATED) { + if (ima->gen_x == 0 || ima->gen_y == 0) { + ImBuf *ibuf = image_get_ibuf(ima, IMA_NO_INDEX, 0); + if (ibuf) { + ima->gen_x = ibuf->x; + ima->gen_y = ibuf->y; + } } } - } - - /* force reload on first use, but not for multilayer, that makes nodes and buttons in ui drawing fail */ - if (ima->type!=IMA_TYPE_MULTILAYER) - image_free_buffers(ima); - ima->ok= 1; - if (iuser) - iuser->ok= 1; - break; - - case IMA_SIGNAL_RELOAD: - /* try to repack file */ - if (ima->packedfile) { - PackedFile *pf; - pf = newPackedFile(NULL, ima->name, ID_BLEND_PATH(G.main, &ima->id)); - if (pf) { - freePackedFile(ima->packedfile); - ima->packedfile = pf; + /* force reload on first use, but not for multilayer, that makes nodes and buttons in ui drawing fail */ + if (ima->type != IMA_TYPE_MULTILAYER) image_free_buffers(ima); + + ima->ok = 1; + if (iuser) + iuser->ok = 1; + break; + + case IMA_SIGNAL_RELOAD: + /* try to repack file */ + if (ima->packedfile) { + PackedFile *pf; + pf = newPackedFile(NULL, ima->name, ID_BLEND_PATH(G.main, &ima->id)); + if (pf) { + freePackedFile(ima->packedfile); + ima->packedfile = pf; + image_free_buffers(ima); + } + else { + printf("ERROR: Image not available. Keeping packed image\n"); + } } - else { - printf("ERROR: Image not available. Keeping packed image\n"); - } - } - else - image_free_buffers(ima); + else + image_free_buffers(ima); - if (iuser) - iuser->ok= 1; + if (iuser) + iuser->ok = 1; - break; - case IMA_SIGNAL_USER_NEW_IMAGE: - if (iuser) { - iuser->ok= 1; - if (ima->source==IMA_SRC_FILE || ima->source==IMA_SRC_SEQUENCE) { - if (ima->type==IMA_TYPE_MULTILAYER) { - iuser->multi_index= 0; - iuser->layer= iuser->pass= 0; + break; + case IMA_SIGNAL_USER_NEW_IMAGE: + if (iuser) { + iuser->ok = 1; + if (ima->source == IMA_SRC_FILE || ima->source == IMA_SRC_SEQUENCE) { + if (ima->type == IMA_TYPE_MULTILAYER) { + iuser->multi_index = 0; + iuser->layer = iuser->pass = 0; + } } } - } - break; + break; } /* don't use notifiers because they are not 100% sure to succeeded * this also makes sure all scenes are accounted for. */ { Scene *scene; - for (scene= G.main->scene.first; scene; scene= scene->id.next) { + for (scene = G.main->scene.first; scene; scene = scene->id.next) { if (scene->nodetree) { nodeUpdateID(scene->nodetree, &ima->id); } @@ -1876,32 +1884,32 @@ void BKE_image_signal(Image *ima, ImageUser *iuser, int signal) RenderPass *BKE_image_multilayer_index(RenderResult *rr, ImageUser *iuser) { RenderLayer *rl; - RenderPass *rpass= NULL; + RenderPass *rpass = NULL; - if (rr==NULL) + if (rr == NULL) return NULL; if (iuser) { - short index= 0, rl_index= 0, rp_index; + short index = 0, rl_index = 0, rp_index; - for (rl= rr->layers.first; rl; rl= rl->next, rl_index++) { - rp_index= 0; - for (rpass= rl->passes.first; rpass; rpass= rpass->next, index++, rp_index++) - if (iuser->layer==rl_index && iuser->pass==rp_index) + for (rl = rr->layers.first; rl; rl = rl->next, rl_index++) { + rp_index = 0; + for (rpass = rl->passes.first; rpass; rpass = rpass->next, index++, rp_index++) + if (iuser->layer == rl_index && iuser->pass == rp_index) break; if (rpass) break; } if (rpass) - iuser->multi_index= index; + iuser->multi_index = index; else - iuser->multi_index= 0; + iuser->multi_index = 0; } - if (rpass==NULL) { - rl= rr->layers.first; + if (rpass == NULL) { + rl = rr->layers.first; if (rl) - rpass= rl->passes.first; + rpass = rl->passes.first; } return rpass; @@ -1912,7 +1920,7 @@ RenderResult *BKE_image_acquire_renderresult(Scene *scene, Image *ima) if (ima->rr) { return ima->rr; } - else if (ima->type==IMA_TYPE_R_RESULT) { + else if (ima->type == IMA_TYPE_R_RESULT) { if (ima->render_slot == ima->last_render_slot) return RE_AcquireResultRead(RE_GetRender(scene->id.name)); else @@ -1924,8 +1932,8 @@ RenderResult *BKE_image_acquire_renderresult(Scene *scene, Image *ima) void BKE_image_release_renderresult(Scene *scene, Image *ima) { - if (ima->rr); - else if (ima->type==IMA_TYPE_R_RESULT) { + if (ima->rr) ; + else if (ima->type == IMA_TYPE_R_RESULT) { if (ima->render_slot == ima->last_render_slot) RE_ReleaseResult(RE_GetRender(scene->id.name)); } @@ -1935,20 +1943,20 @@ void BKE_image_backup_render(Scene *scene, Image *ima) { /* called right before rendering, ima->renders contains render * result pointers for everything but the current render */ - Render *re= RE_GetRender(scene->id.name); - int slot= ima->render_slot, last= ima->last_render_slot; + Render *re = RE_GetRender(scene->id.name); + int slot = ima->render_slot, last = ima->last_render_slot; if (slot != last) { if (ima->renders[slot]) { RE_FreeRenderResult(ima->renders[slot]); - ima->renders[slot]= NULL; + ima->renders[slot] = NULL; } - ima->renders[last]= NULL; + ima->renders[last] = NULL; RE_SwapResult(re, &ima->renders[last]); } - ima->last_render_slot= slot; + ima->last_render_slot = slot; } /* after imbuf load, openexr type can return with a exrhandle open */ @@ -1956,22 +1964,22 @@ void BKE_image_backup_render(Scene *scene, Image *ima) static void image_create_multilayer(Image *ima, ImBuf *ibuf, int framenr) { - ima->rr= RE_MultilayerConvert(ibuf->userdata, ibuf->x, ibuf->y); + ima->rr = RE_MultilayerConvert(ibuf->userdata, ibuf->x, ibuf->y); #ifdef WITH_OPENEXR IMB_exr_close(ibuf->userdata); #endif - ibuf->userdata= NULL; + ibuf->userdata = NULL; if (ima->rr) - ima->rr->framenr= framenr; + ima->rr->framenr = framenr; } /* common stuff to do with images after loading */ static void image_initialize_after_load(Image *ima, ImBuf *ibuf) { /* preview is NULL when it has never been used as an icon before */ - if (G.background==0 && ima->preview==NULL) + if (G.background == 0 && ima->preview == NULL) BKE_icon_changed(BKE_icon_getid(&ima->id)); /* fields */ @@ -1982,7 +1990,7 @@ static void image_initialize_after_load(Image *ima, ImBuf *ibuf) /* timer */ ima->lastused = clock() / CLOCKS_PER_SEC; - ima->ok= IMA_OK_LOADED; + ima->ok = IMA_OK_LOADED; } @@ -1997,14 +2005,14 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame) if (ima->lastframe != frame) ima->tpageflag |= IMA_TPAGE_REFRESH; - ima->lastframe= frame; + ima->lastframe = frame; BLI_strncpy(name, ima->name, sizeof(name)); BLI_stringdec(name, head, tail, &numlen); BLI_stringenc(name, head, tail, numlen, frame); BLI_path_abs(name, ID_BLEND_PATH(G.main, &ima->id)); - flag= IB_rect|IB_multilayer; + flag = IB_rect | IB_multilayer; if (ima->flag & IMA_DO_PREMUL) flag |= IB_premul; @@ -2013,21 +2021,21 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame) #if 0 if (ibuf) { - printf(AT" loaded %s\n", name); + printf(AT " loaded %s\n", name); } else { - printf(AT" missed %s\n", name); + printf(AT " missed %s\n", name); } #endif if (ibuf) { #ifdef WITH_OPENEXR /* handle multilayer case, don't assign ibuf. will be handled in BKE_image_get_ibuf */ - if (ibuf->ftype==OPENEXR && ibuf->userdata) { + if (ibuf->ftype == OPENEXR && ibuf->userdata) { image_create_multilayer(ima, ibuf, frame); - ima->type= IMA_TYPE_MULTILAYER; + ima->type = IMA_TYPE_MULTILAYER; IMB_freeImBuf(ibuf); - ibuf= NULL; + ibuf = NULL; } else { image_initialize_after_load(ima, ibuf); @@ -2039,30 +2047,30 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame) #endif } else - ima->ok= 0; + ima->ok = 0; if (iuser) - iuser->ok= ima->ok; + iuser->ok = ima->ok; return ibuf; } static ImBuf *image_load_sequence_multilayer(Image *ima, ImageUser *iuser, int frame) { - struct ImBuf *ibuf= NULL; + struct ImBuf *ibuf = NULL; /* either we load from RenderResult, or we have to load a new one */ /* check for new RenderResult */ - if (ima->rr==NULL || frame!=ima->rr->framenr) { + if (ima->rr == NULL || frame != ima->rr->framenr) { /* copy to survive not found multilayer image */ - RenderResult *oldrr= ima->rr; + RenderResult *oldrr = ima->rr; - ima->rr= NULL; + ima->rr = NULL; ibuf = image_load_sequence_file(ima, iuser, frame); if (ibuf) { /* actually an error */ - ima->type= IMA_TYPE_IMAGE; + ima->type = IMA_TYPE_IMAGE; printf("error, multi is normal image\n"); } // printf("loaded new result %p\n", ima->rr); @@ -2072,34 +2080,34 @@ static ImBuf *image_load_sequence_multilayer(Image *ima, ImageUser *iuser, int f if (oldrr) RE_FreeRenderResult(oldrr); } else { - ima->rr= oldrr; + ima->rr = oldrr; } } if (ima->rr) { - RenderPass *rpass= BKE_image_multilayer_index(ima->rr, iuser); + RenderPass *rpass = BKE_image_multilayer_index(ima->rr, iuser); if (rpass) { // printf("load from pass %s\n", rpass->name); /* since we free render results, we copy the rect */ - ibuf= IMB_allocImBuf(ima->rr->rectx, ima->rr->recty, 32, 0); - ibuf->rect_float= MEM_dupallocN(rpass->rect); + ibuf = IMB_allocImBuf(ima->rr->rectx, ima->rr->recty, 32, 0); + ibuf->rect_float = MEM_dupallocN(rpass->rect); ibuf->flags |= IB_rectfloat; - ibuf->mall= IB_rectfloat; - ibuf->channels= rpass->channels; + ibuf->mall = IB_rectfloat; + ibuf->channels = rpass->channels; ibuf->profile = IB_PROFILE_LINEAR_RGB; image_initialize_after_load(ima, ibuf); - image_assign_ibuf(ima, ibuf, iuser?iuser->multi_index:0, frame); + image_assign_ibuf(ima, ibuf, iuser ? iuser->multi_index : 0, frame); } // else printf("pass not found\n"); } else - ima->ok= 0; + ima->ok = 0; if (iuser) - iuser->ok= ima->ok; + iuser->ok = ima->ok; return ibuf; } @@ -2107,11 +2115,11 @@ static ImBuf *image_load_sequence_multilayer(Image *ima, ImageUser *iuser, int f static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) { - struct ImBuf *ibuf= NULL; + struct ImBuf *ibuf = NULL; - ima->lastframe= frame; + ima->lastframe = frame; - if (ima->anim==NULL) { + if (ima->anim == NULL) { char str[FILE_MAX]; BLI_strncpy(str, ima->name, FILE_MAX); @@ -2121,35 +2129,35 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) ima->anim = openanim(str, IB_rect, 0); /* let's initialize this user */ - if (ima->anim && iuser && iuser->frames==0) - iuser->frames= IMB_anim_get_duration(ima->anim, - IMB_TC_RECORD_RUN); + if (ima->anim && iuser && iuser->frames == 0) + iuser->frames = IMB_anim_get_duration(ima->anim, + IMB_TC_RECORD_RUN); } if (ima->anim) { int dur = IMB_anim_get_duration(ima->anim, - IMB_TC_RECORD_RUN); - int fra= frame-1; + IMB_TC_RECORD_RUN); + int fra = frame - 1; - if (fra<0) fra = 0; - if (fra>(dur-1)) fra= dur-1; + if (fra < 0) fra = 0; + if (fra > (dur - 1)) fra = dur - 1; ibuf = IMB_makeSingleUser( - IMB_anim_absolute(ima->anim, fra, - IMB_TC_RECORD_RUN, - IMB_PROXY_NONE)); + IMB_anim_absolute(ima->anim, fra, + IMB_TC_RECORD_RUN, + IMB_PROXY_NONE)); if (ibuf) { image_initialize_after_load(ima, ibuf); image_assign_ibuf(ima, ibuf, 0, frame); } else - ima->ok= 0; + ima->ok = 0; } else - ima->ok= 0; + ima->ok = 0; if (iuser) - iuser->ok= ima->ok; + iuser->ok = ima->ok; return ibuf; } @@ -2166,13 +2174,13 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) /* is there a PackedFile with this image ? */ if (ima->packedfile) { - flag = IB_rect|IB_multilayer; + flag = IB_rect | IB_multilayer; if (ima->flag & IMA_DO_PREMUL) flag |= IB_premul; - ibuf = IMB_ibImageFromMemory((unsigned char*)ima->packedfile->data, ima->packedfile->size, flag, "<packed data>"); + ibuf = IMB_ibImageFromMemory((unsigned char *)ima->packedfile->data, ima->packedfile->size, flag, "<packed data>"); } else { - flag= IB_rect|IB_multilayer|IB_metadata; + flag = IB_rect | IB_multilayer | IB_metadata; if (ima->flag & IMA_DO_PREMUL) flag |= IB_premul; @@ -2186,15 +2194,15 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) if (ibuf) { /* handle multilayer case, don't assign ibuf. will be handled in BKE_image_get_ibuf */ - if (ibuf->ftype==OPENEXR && ibuf->userdata) { + if (ibuf->ftype == OPENEXR && ibuf->userdata) { image_create_multilayer(ima, ibuf, cfra); - ima->type= IMA_TYPE_MULTILAYER; + ima->type = IMA_TYPE_MULTILAYER; IMB_freeImBuf(ibuf); - ibuf= NULL; + ibuf = NULL; } else { image_initialize_after_load(ima, ibuf); - assign= 1; + assign = 1; /* check if the image is a font image... */ detectBitmapFont(ibuf); @@ -2205,49 +2213,49 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) } } else - ima->ok= 0; + ima->ok = 0; if (assign) image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); if (iuser) - iuser->ok= ima->ok; + iuser->ok = ima->ok; return ibuf; } static ImBuf *image_get_ibuf_multilayer(Image *ima, ImageUser *iuser) { - ImBuf *ibuf= NULL; + ImBuf *ibuf = NULL; - if (ima->rr==NULL) { + if (ima->rr == NULL) { ibuf = image_load_image_file(ima, iuser, 0); if (ibuf) { /* actually an error */ - ima->type= IMA_TYPE_IMAGE; + ima->type = IMA_TYPE_IMAGE; return ibuf; } } if (ima->rr) { - RenderPass *rpass= BKE_image_multilayer_index(ima->rr, iuser); + RenderPass *rpass = BKE_image_multilayer_index(ima->rr, iuser); if (rpass) { - ibuf= IMB_allocImBuf(ima->rr->rectx, ima->rr->recty, 32, 0); + ibuf = IMB_allocImBuf(ima->rr->rectx, ima->rr->recty, 32, 0); image_initialize_after_load(ima, ibuf); - ibuf->rect_float= rpass->rect; + ibuf->rect_float = rpass->rect; ibuf->flags |= IB_rectfloat; - ibuf->channels= rpass->channels; + ibuf->channels = rpass->channels; ibuf->profile = IB_PROFILE_LINEAR_RGB; - image_assign_ibuf(ima, ibuf, iuser?iuser->multi_index:IMA_NO_INDEX, 0); + image_assign_ibuf(ima, ibuf, iuser ? iuser->multi_index : IMA_NO_INDEX, 0); } } - if (ibuf==NULL) - ima->ok= 0; + if (ibuf == NULL) + ima->ok = 0; if (iuser) - iuser->ok= ima->ok; + iuser->ok = ima->ok; return ibuf; } @@ -2265,7 +2273,7 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_ float dither; int channels, layer, pass; ImBuf *ibuf; - int from_render= (ima->render_slot == ima->last_render_slot); + int from_render = (ima->render_slot == ima->last_render_slot); if (!(iuser && iuser->scene)) return NULL; @@ -2274,18 +2282,18 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_ if (!lock_r) return NULL; - re= RE_GetRender(iuser->scene->id.name); + re = RE_GetRender(iuser->scene->id.name); - channels= 4; - layer= (iuser)? iuser->layer: 0; - pass= (iuser)? iuser->pass: 0; + channels = 4; + layer = (iuser) ? iuser->layer : 0; + pass = (iuser) ? iuser->pass : 0; if (from_render) { RE_AcquireResultImage(re, &rres); } else if (ima->renders[ima->render_slot]) { - rres= *(ima->renders[ima->render_slot]); - rres.have_combined= rres.rectf != NULL; + rres = *(ima->renders[ima->render_slot]); + rres.have_combined = rres.rectf != NULL; } else memset(&rres, 0, sizeof(RenderResult)); @@ -2299,83 +2307,83 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_ /* release is done in BKE_image_release_ibuf using lock_r */ if (from_render) { BLI_lock_thread(LOCK_VIEWER); - *lock_r= re; + *lock_r = re; } /* this gives active layer, composite or seqence result */ - rect= (unsigned int *)rres.rect32; - rectf= rres.rectf; - rectz= rres.rectz; - dither= iuser->scene->r.dither_intensity; + rect = (unsigned int *)rres.rect32; + rectf = rres.rectf; + rectz = rres.rectz; + dither = iuser->scene->r.dither_intensity; /* combined layer gets added as first layer */ - if (rres.have_combined && layer==0); + if (rres.have_combined && layer == 0) ; else if (rres.layers.first) { - RenderLayer *rl= BLI_findlink(&rres.layers, layer-(rres.have_combined?1:0)); + RenderLayer *rl = BLI_findlink(&rres.layers, layer - (rres.have_combined ? 1 : 0)); if (rl) { RenderPass *rpass; /* there's no combined pass, is in renderlayer itself */ - if (pass==0) { - rectf= rl->rectf; + if (pass == 0) { + rectf = rl->rectf; } else { - rpass= BLI_findlink(&rl->passes, pass-1); + rpass = BLI_findlink(&rl->passes, pass - 1); if (rpass) { - channels= rpass->channels; - rectf= rpass->rect; - dither= 0.0f; /* don't dither passes */ + channels = rpass->channels; + rectf = rpass->rect; + dither = 0.0f; /* don't dither passes */ } } - for (rpass= rl->passes.first; rpass; rpass= rpass->next) + for (rpass = rl->passes.first; rpass; rpass = rpass->next) if (rpass->passtype == SCE_PASS_Z) - rectz= rpass->rect; + rectz = rpass->rect; } } - ibuf= image_get_ibuf(ima, IMA_NO_INDEX, 0); + ibuf = image_get_ibuf(ima, IMA_NO_INDEX, 0); /* make ibuf if needed, and initialize it */ - if (ibuf==NULL) { - ibuf= IMB_allocImBuf(rres.rectx, rres.recty, 32, 0); + if (ibuf == NULL) { + ibuf = IMB_allocImBuf(rres.rectx, rres.recty, 32, 0); image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); } - ibuf->x= rres.rectx; - ibuf->y= rres.recty; + ibuf->x = rres.rectx; + ibuf->y = rres.recty; /* free rect buffer if float buffer changes, so it can be recreated with * the updated result, and also in case we got byte buffer from sequencer, * so we don't keep reference to freed buffer */ - if (ibuf->rect_float!=rectf || rect || !rectf) + if (ibuf->rect_float != rectf || rect || !rectf) imb_freerectImBuf(ibuf); if (rect) - ibuf->rect= rect; + ibuf->rect = rect; if (rectf) { - ibuf->rect_float= rectf; + ibuf->rect_float = rectf; ibuf->flags |= IB_rectfloat; - ibuf->channels= channels; + ibuf->channels = channels; } else { - ibuf->rect_float= NULL; + ibuf->rect_float = NULL; ibuf->flags &= ~IB_rectfloat; } if (rectz) { - ibuf->zbuf_float= rectz; + ibuf->zbuf_float = rectz; ibuf->flags |= IB_zbuffloat; } else { - ibuf->zbuf_float= NULL; + ibuf->zbuf_float = NULL; ibuf->flags &= ~IB_zbuffloat; } /* since its possible to access the buffer from the image directly, set the profile [#25073] */ - ibuf->profile= (iuser->scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_NONE; - ibuf->dither= dither; + ibuf->profile = (iuser->scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_NONE; + ibuf->dither = dither; if (iuser->scene->r.color_mgt_flag & R_COLOR_MANAGEMENT_PREDIVIDE) { ibuf->flags |= IB_cm_predivide; @@ -2386,7 +2394,7 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_ ima->flag &= ~IMA_CM_PREDIVIDE; } - ima->ok= IMA_OK_LOADED; + ima->ok = IMA_OK_LOADED; return ibuf; } @@ -2397,18 +2405,18 @@ static ImBuf *image_get_ibuf_threadsafe(Image *ima, ImageUser *iuser, int *frame int frame = 0, index = 0; /* see if we already have an appropriate ibuf, with image source and type */ - if (ima->source==IMA_SRC_MOVIE) { - frame= iuser?iuser->framenr:ima->lastframe; - ibuf= image_get_ibuf(ima, 0, frame); + if (ima->source == IMA_SRC_MOVIE) { + frame = iuser ? iuser->framenr : ima->lastframe; + ibuf = image_get_ibuf(ima, 0, frame); /* XXX temp stuff? */ if (ima->lastframe != frame) ima->tpageflag |= IMA_TPAGE_REFRESH; ima->lastframe = frame; } - else if (ima->source==IMA_SRC_SEQUENCE) { - if (ima->type==IMA_TYPE_IMAGE) { - frame= iuser?iuser->framenr:ima->lastframe; - ibuf= image_get_ibuf(ima, 0, frame); + else if (ima->source == IMA_SRC_SEQUENCE) { + if (ima->type == IMA_TYPE_IMAGE) { + frame = iuser ? iuser->framenr : ima->lastframe; + ibuf = image_get_ibuf(ima, 0, frame); /* XXX temp stuff? */ if (ima->lastframe != frame) { @@ -2416,20 +2424,20 @@ static ImBuf *image_get_ibuf_threadsafe(Image *ima, ImageUser *iuser, int *frame } ima->lastframe = frame; } - else if (ima->type==IMA_TYPE_MULTILAYER) { - frame= iuser?iuser->framenr:ima->lastframe; - index= iuser?iuser->multi_index:IMA_NO_INDEX; - ibuf= image_get_ibuf(ima, index, frame); + else if (ima->type == IMA_TYPE_MULTILAYER) { + frame = iuser ? iuser->framenr : ima->lastframe; + index = iuser ? iuser->multi_index : IMA_NO_INDEX; + ibuf = image_get_ibuf(ima, index, frame); } } - else if (ima->source==IMA_SRC_FILE) { - if (ima->type==IMA_TYPE_IMAGE) - ibuf= image_get_ibuf(ima, IMA_NO_INDEX, 0); - else if (ima->type==IMA_TYPE_MULTILAYER) - ibuf= image_get_ibuf(ima, iuser?iuser->multi_index:IMA_NO_INDEX, 0); + else if (ima->source == IMA_SRC_FILE) { + if (ima->type == IMA_TYPE_IMAGE) + ibuf = image_get_ibuf(ima, IMA_NO_INDEX, 0); + else if (ima->type == IMA_TYPE_MULTILAYER) + ibuf = image_get_ibuf(ima, iuser ? iuser->multi_index : IMA_NO_INDEX, 0); } else if (ima->source == IMA_SRC_GENERATED) { - ibuf= image_get_ibuf(ima, IMA_NO_INDEX, 0); + ibuf = image_get_ibuf(ima, IMA_NO_INDEX, 0); } else if (ima->source == IMA_SRC_VIEWER) { /* always verify entirely, not that this shouldn't happen @@ -2448,9 +2456,9 @@ static ImBuf *image_get_ibuf_threadsafe(Image *ima, ImageUser *iuser, int *frame * if not, use BKE_image_get_ibuf which doesn't require a release */ ImBuf *BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **lock_r) { - ImBuf *ibuf= NULL; + ImBuf *ibuf = NULL; float color[] = {0, 0, 0, 1}; - int frame= 0, index= 0; + int frame = 0, index = 0; /* This function is intended to be thread-safe. It postpones the mutex lock * until it needs to load the image, if the image is already there it @@ -2464,20 +2472,20 @@ ImBuf *BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **lock_r) * 2) set ima/iuser->ok to 0 to IMA_OK_LOADED */ if (lock_r) - *lock_r= NULL; + *lock_r = NULL; /* quick reject tests */ - if (ima==NULL) + if (ima == NULL) return NULL; if (iuser) { - if (iuser->ok==0) + if (iuser->ok == 0) return NULL; } - else if (ima->ok==0) + else if (ima->ok == 0) return NULL; /* try to get the ibuf without locking */ - ibuf= image_get_ibuf_threadsafe(ima, iuser, &frame, &index); + ibuf = image_get_ibuf_threadsafe(ima, iuser, &frame, &index); if (ibuf == NULL) { /* couldn't get ibuf and image is not ok, so let's lock and try to @@ -2487,75 +2495,75 @@ ImBuf *BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **lock_r) /* need to check ok flag and loading ibuf again, because the situation * might have changed in the meantime */ if (iuser) { - if (iuser->ok==0) { + if (iuser->ok == 0) { BLI_unlock_thread(LOCK_IMAGE); return NULL; } } - else if (ima->ok==0) { + else if (ima->ok == 0) { BLI_unlock_thread(LOCK_IMAGE); return NULL; } - ibuf= image_get_ibuf_threadsafe(ima, iuser, &frame, &index); + ibuf = image_get_ibuf_threadsafe(ima, iuser, &frame, &index); if (ibuf == NULL) { /* we are sure we have to load the ibuf, using source and type */ - if (ima->source==IMA_SRC_MOVIE) { + if (ima->source == IMA_SRC_MOVIE) { /* source is from single file, use flipbook to store ibuf */ - ibuf= image_load_movie_file(ima, iuser, frame); + ibuf = image_load_movie_file(ima, iuser, frame); } - else if (ima->source==IMA_SRC_SEQUENCE) { - if (ima->type==IMA_TYPE_IMAGE) { + else if (ima->source == IMA_SRC_SEQUENCE) { + if (ima->type == IMA_TYPE_IMAGE) { /* regular files, ibufs in flipbook, allows saving */ - ibuf= image_load_sequence_file(ima, iuser, frame); + ibuf = image_load_sequence_file(ima, iuser, frame); } /* no else; on load the ima type can change */ - if (ima->type==IMA_TYPE_MULTILAYER) { + if (ima->type == IMA_TYPE_MULTILAYER) { /* only 1 layer/pass stored in imbufs, no exrhandle anim storage, no saving */ - ibuf= image_load_sequence_multilayer(ima, iuser, frame); + ibuf = image_load_sequence_multilayer(ima, iuser, frame); } } - else if (ima->source==IMA_SRC_FILE) { + else if (ima->source == IMA_SRC_FILE) { - if (ima->type==IMA_TYPE_IMAGE) - ibuf= image_load_image_file(ima, iuser, frame); /* cfra only for '#', this global is OK */ + if (ima->type == IMA_TYPE_IMAGE) + ibuf = image_load_image_file(ima, iuser, frame); /* cfra only for '#', this global is OK */ /* no else; on load the ima type can change */ - if (ima->type==IMA_TYPE_MULTILAYER) + if (ima->type == IMA_TYPE_MULTILAYER) /* keeps render result, stores ibufs in listbase, allows saving */ - ibuf= image_get_ibuf_multilayer(ima, iuser); + ibuf = image_get_ibuf_multilayer(ima, iuser); } else if (ima->source == IMA_SRC_GENERATED) { /* generated is: ibuf is allocated dynamically */ /* UV testgrid or black or solid etc */ - if (ima->gen_x==0) ima->gen_x= 1024; - if (ima->gen_y==0) ima->gen_y= 1024; - ibuf= add_ibuf_size(ima->gen_x, ima->gen_y, ima->name, 24, (ima->gen_flag & IMA_GEN_FLOAT) != 0, ima->gen_type, color); + if (ima->gen_x == 0) ima->gen_x = 1024; + if (ima->gen_y == 0) ima->gen_y = 1024; + ibuf = add_ibuf_size(ima->gen_x, ima->gen_y, ima->name, 24, (ima->gen_flag & IMA_GEN_FLOAT) != 0, ima->gen_type, color); image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); - ima->ok= IMA_OK_LOADED; + ima->ok = IMA_OK_LOADED; } else if (ima->source == IMA_SRC_VIEWER) { - if (ima->type==IMA_TYPE_R_RESULT) { + if (ima->type == IMA_TYPE_R_RESULT) { /* always verify entirely, and potentially * returns pointer to release later */ - ibuf= image_get_render_result(ima, iuser, lock_r); + ibuf = image_get_render_result(ima, iuser, lock_r); } - else if (ima->type==IMA_TYPE_COMPOSITE) { + else if (ima->type == IMA_TYPE_COMPOSITE) { /* requires lock/unlock, otherwise don't return image */ if (lock_r) { /* unlock in BKE_image_release_ibuf */ BLI_lock_thread(LOCK_VIEWER); - *lock_r= ima; + *lock_r = ima; /* XXX anim play for viewer nodes not yet supported */ - frame= 0; // XXX iuser?iuser->framenr:0; - ibuf= image_get_ibuf(ima, 0, frame); + frame = 0; // XXX iuser?iuser->framenr:0; + ibuf = image_get_ibuf(ima, 0, frame); if (!ibuf) { /* Composite Viewer, all handled in compositor */ /* fake ibuf, will be filled in compositor */ - ibuf= IMB_allocImBuf(256, 256, 32, IB_rect); + ibuf = IMB_allocImBuf(256, 256, 32, IB_rect); image_assign_ibuf(ima, ibuf, 0, frame); } } @@ -2566,7 +2574,7 @@ ImBuf *BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **lock_r) BLI_unlock_thread(LOCK_IMAGE); } - tag_image_time(ima); + BKE_image_tag_time(ima); return ibuf; } @@ -2590,57 +2598,57 @@ ImBuf *BKE_image_get_ibuf(Image *ima, ImageUser *iuser) return BKE_image_acquire_ibuf(ima, iuser, NULL); } -int BKE_image_user_get_frame(const ImageUser *iuser, int cfra, int fieldnr) +int BKE_image_user_frame_get(const ImageUser *iuser, int cfra, int fieldnr) { - const int len= (iuser->fie_ima*iuser->frames)/2; + const int len = (iuser->fie_ima * iuser->frames) / 2; - if (len==0) { + if (len == 0) { return 0; } else { int framenr; - cfra= cfra - iuser->sfra+1; + cfra = cfra - iuser->sfra + 1; /* cyclic */ if (iuser->cycl) { - cfra= ((cfra) % len); - if (cfra < 0) cfra+= len; - if (cfra==0) cfra= len; + cfra = ((cfra) % len); + if (cfra < 0) cfra += len; + if (cfra == 0) cfra = len; } - if (cfra<0) cfra= 0; - else if (cfra>len) cfra= len; + if (cfra < 0) cfra = 0; + else if (cfra > len) cfra = len; /* convert current frame to current field */ - cfra= 2*(cfra); + cfra = 2 * (cfra); if (fieldnr) cfra++; /* transform to images space */ - framenr= (cfra+iuser->fie_ima-2)/iuser->fie_ima; - if (framenr>iuser->frames) framenr= iuser->frames; - framenr+= iuser->offset; + framenr = (cfra + iuser->fie_ima - 2) / iuser->fie_ima; + if (framenr > iuser->frames) framenr = iuser->frames; + framenr += iuser->offset; if (iuser->cycl) { - framenr= ((framenr) % len); - while (framenr < 0) framenr+= len; - if (framenr==0) framenr= len; + framenr = ((framenr) % len); + while (framenr < 0) framenr += len; + if (framenr == 0) framenr = len; } return framenr; } } -void BKE_image_user_calc_frame(ImageUser *iuser, int cfra, int fieldnr) +void BKE_image_user_frame_calc(ImageUser *iuser, int cfra, int fieldnr) { - const int framenr= BKE_image_user_get_frame(iuser, cfra, fieldnr); + const int framenr = BKE_image_user_frame_get(iuser, cfra, fieldnr); /* allows image users to handle redraws */ if (iuser->flag & IMA_ANIM_ALWAYS) - if (framenr!=iuser->framenr) + if (framenr != iuser->framenr) iuser->flag |= IMA_ANIM_REFRESHED; - iuser->framenr= framenr; - if (iuser->ok==0) iuser->ok= 1; + iuser->framenr = framenr; + if (iuser->ok == 0) iuser->ok = 1; } int BKE_image_has_alpha(struct Image *image) @@ -2649,8 +2657,8 @@ int BKE_image_has_alpha(struct Image *image) void *lock; int planes; - ibuf= BKE_image_acquire_ibuf(image, NULL, &lock); - planes = (ibuf?ibuf->planes:0); + ibuf = BKE_image_acquire_ibuf(image, NULL, &lock); + planes = (ibuf ? ibuf->planes : 0); BKE_image_release_ibuf(image, lock); if (planes == 32) diff --git a/source/blender/blenkernel/intern/image_gen.c b/source/blender/blenkernel/intern/image_gen.c index 1441bd7b12b..4579e6f92aa 100644 --- a/source/blender/blenkernel/intern/image_gen.c +++ b/source/blender/blenkernel/intern/image_gen.c @@ -39,10 +39,10 @@ void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, /* blank image */ if (rect_float) { - for (y= 0; y<height; y++) { - for (x= 0; x<width; x++) { + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { copy_v4_v4(rect_float, color); - rect_float+= 4; + rect_float += 4; } } } @@ -52,14 +52,14 @@ void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, rgba_float_to_uchar(ccol, color); - for (y= 0; y<height; y++) { - for (x= 0; x<width; x++) { + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { - rect[0]= ccol[0]; - rect[1]= ccol[1]; - rect[2]= ccol[2]; - rect[3]= ccol[3]; - rect+= 4; + rect[0] = ccol[0]; + rect[1] = ccol[1]; + rect[2] = ccol[2]; + rect[3] = ccol[3]; + rect += 4; } } } @@ -71,84 +71,84 @@ void BKE_image_buf_fill_checker(unsigned char *rect, float *rect_float, int widt /* these two passes could be combined into one, but it's more readable and * easy to tweak like this, speed isn't really that much of an issue in this situation... */ - int checkerwidth= 32, dark= 1; + int checkerwidth = 32, dark = 1; int x, y; - unsigned char *rect_orig= rect; - float *rect_float_orig= rect_float; + unsigned char *rect_orig = rect; + float *rect_float_orig = rect_float; - float h=0.0, hoffs=0.0, hue=0.0, s=0.9, v=0.9, r, g, b; + float h = 0.0, hoffs = 0.0, hue = 0.0, s = 0.9, v = 0.9, r, g, b; /* checkers */ - for (y= 0; y<height; y++) { - dark= powf(-1.0f, floorf(y / checkerwidth)); + for (y = 0; y < height; y++) { + dark = powf(-1.0f, floorf(y / checkerwidth)); - for (x= 0; x<width; x++) { - if (x % checkerwidth == 0) dark= -dark; + for (x = 0; x < width; x++) { + if (x % checkerwidth == 0) dark = -dark; if (rect_float) { if (dark > 0) { - rect_float[0]= rect_float[1]= rect_float[2]= 0.25f; - rect_float[3]= 1.0f; + rect_float[0] = rect_float[1] = rect_float[2] = 0.25f; + rect_float[3] = 1.0f; } else { - rect_float[0]= rect_float[1]= rect_float[2]= 0.58f; - rect_float[3]= 1.0f; + rect_float[0] = rect_float[1] = rect_float[2] = 0.58f; + rect_float[3] = 1.0f; } - rect_float+= 4; + rect_float += 4; } else { if (dark > 0) { - rect[0]= rect[1]= rect[2]= 64; - rect[3]= 255; + rect[0] = rect[1] = rect[2] = 64; + rect[3] = 255; } else { - rect[0]= rect[1]= rect[2]= 150; - rect[3]= 255; + rect[0] = rect[1] = rect[2] = 150; + rect[3] = 255; } - rect+= 4; + rect += 4; } } } - rect= rect_orig; - rect_float= rect_float_orig; + rect = rect_orig; + rect_float = rect_float_orig; /* 2nd pass, colored + */ - for (y= 0; y<height; y++) { - hoffs= 0.125f * floorf(y / checkerwidth); + for (y = 0; y < height; y++) { + hoffs = 0.125f * floorf(y / checkerwidth); - for (x= 0; x<width; x++) { - h= 0.125f * floorf(x / checkerwidth); + for (x = 0; x < width; x++) { + h = 0.125f * floorf(x / checkerwidth); if ((fabs((x % checkerwidth) - (checkerwidth / 2)) < 4) && - (fabs((y % checkerwidth) - (checkerwidth / 2)) < 4)) { + (fabs((y % checkerwidth) - (checkerwidth / 2)) < 4)) { if ((fabs((x % checkerwidth) - (checkerwidth / 2)) < 1) || - (fabs((y % checkerwidth) - (checkerwidth / 2)) < 1)) { + (fabs((y % checkerwidth) - (checkerwidth / 2)) < 1)) { - hue= fmodf(fabs(h-hoffs), 1.0f); + hue = fmodf(fabs(h - hoffs), 1.0f); hsv_to_rgb(hue, s, v, &r, &g, &b); if (rect) { - rect[0]= (char)(r * 255.0f); - rect[1]= (char)(g * 255.0f); - rect[2]= (char)(b * 255.0f); - rect[3]= 255; + rect[0] = (char)(r * 255.0f); + rect[1] = (char)(g * 255.0f); + rect[2] = (char)(b * 255.0f); + rect[3] = 255; } if (rect_float) { - rect_float[0]= r; - rect_float[1]= g; - rect_float[2]= b; - rect_float[3]= 1.0f; + rect_float[0] = r; + rect_float[1] = g; + rect_float[2] = b; + rect_float[3] = 1.0f; } } } - if (rect_float) rect_float+= 4; - if (rect) rect+= 4; + if (rect_float) rect_float += 4; + if (rect) rect += 4; } } } @@ -156,7 +156,7 @@ 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.0f) ? (real+add) : 1.0f +#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 void checker_board_color_fill(unsigned char *rect, float *rect_float, int width, int height) @@ -164,32 +164,32 @@ static void checker_board_color_fill(unsigned char *rect, float *rect_float, int int hue_step, y, x; float hue, val, sat, r, g, b; - sat= 1.0; + sat = 1.0; - hue_step= power_of_2_max_i(width / 8); - if (hue_step < 8) hue_step= 8; + hue_step = power_of_2_max_i(width / 8); + if (hue_step < 8) hue_step = 8; - for (y= 0; y < height; y++) { + for (y = 0; y < height; y++) { - val= 0.1 + (y * (0.4 / height)); /* use a number lower then 1.0 else its too bright */ - for (x= 0; x < width; x++) { - hue= (float)((double)(x/hue_step) * 1.0 / width * hue_step); + val = 0.1 + (y * (0.4 / height)); /* use a number lower then 1.0 else its too bright */ + for (x = 0; x < width; x++) { + hue = (float)((double)(x / hue_step) * 1.0 / width * hue_step); hsv_to_rgb(hue, sat, val, &r, &g, &b); if (rect) { - rect[0]= (char)(r * 255.0f); - rect[1]= (char)(g * 255.0f); - rect[2]= (char)(b * 255.0f); - rect[3]= 255; + rect[0] = (char)(r * 255.0f); + rect[1] = (char)(g * 255.0f); + rect[2] = (char)(b * 255.0f); + rect[3] = 255; rect += 4; } if (rect_float) { - rect_float[0]= r; - rect_float[1]= g; - rect_float[2]= b; - rect_float[3]= 1.0f; + rect_float[0] = r; + rect_float[1] = g; + rect_float[2] = b; + rect_float[3] = 1.0f; rect_float += 4; } @@ -200,42 +200,42 @@ static void checker_board_color_fill(unsigned char *rect, float *rect_float, int static void checker_board_color_tint(unsigned char *rect, float *rect_float, int width, int height, int size, float blend) { int x, y; - float blend_half= blend * 0.5f; + float blend_half = blend * 0.5f; - for (y= 0; y < height; y++) { - for (x= 0; x < width; x++) { - if (((y / size) % 2 == 1 && (x / size) % 2 == 1 ) || ( (y / size) % 2 == 0 && (x / size) % 2 == 0 )) { + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + if (((y / size) % 2 == 1 && (x / size) % 2 == 1) || ( (y / size) % 2 == 0 && (x / size) % 2 == 0)) { if (rect) { - rect[0]= (char)BLEND_CHAR(rect[0], blend); - rect[1]= (char)BLEND_CHAR(rect[1], blend); - rect[2]= (char)BLEND_CHAR(rect[2], blend); - rect[3]= 255; + rect[0] = (char)BLEND_CHAR(rect[0], blend); + rect[1] = (char)BLEND_CHAR(rect[1], blend); + rect[2] = (char)BLEND_CHAR(rect[2], blend); + rect[3] = 255; rect += 4; } if (rect_float) { - rect_float[0]= BLEND_FLOAT(rect_float[0], blend); - rect_float[1]= BLEND_FLOAT(rect_float[1], blend); - rect_float[2]= BLEND_FLOAT(rect_float[2], blend); - rect_float[3]= 1.0f; + rect_float[0] = BLEND_FLOAT(rect_float[0], blend); + rect_float[1] = BLEND_FLOAT(rect_float[1], blend); + rect_float[2] = BLEND_FLOAT(rect_float[2], blend); + rect_float[3] = 1.0f; rect_float += 4; } } else { if (rect) { - rect[0]= (char)BLEND_CHAR(rect[0], blend_half); - rect[1]= (char)BLEND_CHAR(rect[1], blend_half); - rect[2]= (char)BLEND_CHAR(rect[2], blend_half); - rect[3]= 255; + rect[0] = (char)BLEND_CHAR(rect[0], blend_half); + rect[1] = (char)BLEND_CHAR(rect[1], blend_half); + rect[2] = (char)BLEND_CHAR(rect[2], blend_half); + rect[3] = 255; rect += 4; } if (rect_float) { - rect_float[0]= BLEND_FLOAT(rect_float[0], blend_half); - rect_float[1]= BLEND_FLOAT(rect_float[1], blend_half); - rect_float[2]= BLEND_FLOAT(rect_float[2], blend_half); - rect_float[3]= 1.0f; + rect_float[0] = BLEND_FLOAT(rect_float[0], blend_half); + rect_float[1] = BLEND_FLOAT(rect_float[1], blend_half); + rect_float[2] = BLEND_FLOAT(rect_float[2], blend_half); + rect_float[3] = 1.0f; rect_float += 4; } @@ -248,22 +248,22 @@ static void checker_board_color_tint(unsigned char *rect, float *rect_float, int static void checker_board_grid_fill(unsigned char *rect, float *rect_float, int width, int height, float blend) { int x, y; - for (y= 0; y < height; y++) { - for (x= 0; x < width; x++) { + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { if (((y % 32) == 0) || ((x % 32) == 0) || x == 0) { if (rect) { - rect[0]= BLEND_CHAR(rect[0], blend); - rect[1]= BLEND_CHAR(rect[1], blend); - rect[2]= BLEND_CHAR(rect[2], blend); - rect[3]= 255; + rect[0] = BLEND_CHAR(rect[0], blend); + rect[1] = BLEND_CHAR(rect[1], blend); + rect[2] = BLEND_CHAR(rect[2], blend); + rect[3] = 255; rect += 4; } if (rect_float) { - rect_float[0]= BLEND_FLOAT(rect_float[0], blend); - rect_float[1]= BLEND_FLOAT(rect_float[1], blend); - rect_float[2]= BLEND_FLOAT(rect_float[2], blend); - rect_float[3]= 1.0f; + rect_float[0] = BLEND_FLOAT(rect_float[0], blend); + rect_float[1] = BLEND_FLOAT(rect_float[1], blend); + rect_float[2] = BLEND_FLOAT(rect_float[2], blend); + rect_float[3] = 1.0f; rect_float += 4; } @@ -282,17 +282,17 @@ static void checker_board_text(unsigned char *rect, float *rect_float, int width { int x, y; int pen_x, pen_y; - char text[3]= {'A', '1', '\0'}; - const int mono= blf_mono_font; + char text[3] = {'A', '1', '\0'}; + const int mono = blf_mono_font; BLF_size(mono, 54, 72); /* hard coded size! */ BLF_buffer(mono, rect_float, rect, width, height, 4); - for (y= 0; y < height; y+=step) { - text[1]= '1'; + for (y = 0; y < height; y += step) { + text[1] = '1'; - for (x= 0; x < width; x+=step) { + for (x = 0; x < width; x += step) { /* hard coded offset */ pen_x = x + 33; pen_y = y + 44; @@ -300,22 +300,22 @@ static void checker_board_text(unsigned char *rect, float *rect_float, int width /* terribly crappy outline font! */ BLF_buffer_col(mono, 1.0, 1.0, 1.0, 1.0); - BLF_position(mono, pen_x-outline, pen_y, 0.0); + BLF_position(mono, pen_x - outline, pen_y, 0.0); BLF_draw_buffer(mono, text); - BLF_position(mono, pen_x+outline, pen_y, 0.0); + BLF_position(mono, pen_x + outline, pen_y, 0.0); BLF_draw_buffer(mono, text); - BLF_position(mono, pen_x, pen_y-outline, 0.0); + BLF_position(mono, pen_x, pen_y - outline, 0.0); BLF_draw_buffer(mono, text); - BLF_position(mono, pen_x, pen_y+outline, 0.0); + BLF_position(mono, pen_x, pen_y + outline, 0.0); BLF_draw_buffer(mono, text); - BLF_position(mono, pen_x-outline, pen_y-outline, 0.0); + BLF_position(mono, pen_x - outline, pen_y - outline, 0.0); BLF_draw_buffer(mono, text); - BLF_position(mono, pen_x+outline, pen_y+outline, 0.0); + BLF_position(mono, pen_x + outline, pen_y + outline, 0.0); BLF_draw_buffer(mono, text); - BLF_position(mono, pen_x-outline, pen_y+outline, 0.0); + BLF_position(mono, pen_x - outline, pen_y + outline, 0.0); BLF_draw_buffer(mono, text); - BLF_position(mono, pen_x+outline, pen_y-outline, 0.0); + BLF_position(mono, pen_x + outline, pen_y - outline, 0.0); BLF_draw_buffer(mono, text); BLF_buffer_col(mono, 0.0, 0.0, 0.0, 1.0); @@ -338,7 +338,7 @@ void BKE_image_buf_fill_checker_color(unsigned char *rect, float *rect_float, in checker_board_color_tint(rect, rect_float, width, height, 4, 0.05f); checker_board_color_tint(rect, rect_float, width, height, 32, 0.07f); checker_board_color_tint(rect, rect_float, width, height, 128, 0.15f); - checker_board_grid_fill(rect, rect_float, width, height, 1.0f/4.0f); + checker_board_grid_fill(rect, rect_float, width, height, 1.0f / 4.0f); checker_board_text(rect, rect_float, width, height, 128, 2); } diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index 48763382f2a..1077b5ad7c3 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -81,13 +81,13 @@ /* Free data from old IPO-Blocks (those which haven't been converted), but not IPO block itself */ // XXX this shouldn't be necessary anymore, but may occur while not all data is converted yet -void free_ipo(Ipo *ipo) +void BKE_ipo_free(Ipo *ipo) { IpoCurve *icu, *icn; - int n= 0; + int n = 0; - for (icu= ipo->curve.first; icu; icu= icn) { - icn= icu->next; + for (icu = ipo->curve.first; icu; icu = icn) { + icn = icu->next; n++; if (icu->bezt) MEM_freeN(icu->bezt); @@ -98,7 +98,7 @@ void free_ipo(Ipo *ipo) } if (G.debug & G_DEBUG) - printf("Freed %d (Unconverted) Ipo-Curves from IPO '%s'\n", n, ipo->id.name+2); + printf("Freed %d (Unconverted) Ipo-Curves from IPO '%s'\n", n, ipo->id.name + 2); } /* *************************************************** */ @@ -115,35 +115,35 @@ typedef struct AdrBit2Path { /* Mapping Tables to use bits <-> RNA paths */ /* Object layers */ -static AdrBit2Path ob_layer_bits[]= { - {(1<<0), "layers", 0}, - {(1<<1), "layers", 1}, - {(1<<2), "layers", 2}, - {(1<<3), "layers", 3}, - {(1<<4), "layers", 4}, - {(1<<5), "layers", 5}, - {(1<<6), "layers", 6}, - {(1<<7), "layers", 7}, - {(1<<8), "layers", 8}, - {(1<<9), "layers", 9}, - {(1<<10), "layers", 10}, - {(1<<11), "layers", 11}, - {(1<<12), "layers", 12}, - {(1<<13), "layers", 13}, - {(1<<14), "layers", 14}, - {(1<<15), "layers", 15}, - {(1<<16), "layers", 16}, - {(1<<17), "layers", 17}, - {(1<<18), "layers", 18}, - {(1<<19), "layers", 19} +static AdrBit2Path ob_layer_bits[] = { + {(1 << 0), "layers", 0}, + {(1 << 1), "layers", 1}, + {(1 << 2), "layers", 2}, + {(1 << 3), "layers", 3}, + {(1 << 4), "layers", 4}, + {(1 << 5), "layers", 5}, + {(1 << 6), "layers", 6}, + {(1 << 7), "layers", 7}, + {(1 << 8), "layers", 8}, + {(1 << 9), "layers", 9}, + {(1 << 10), "layers", 10}, + {(1 << 11), "layers", 11}, + {(1 << 12), "layers", 12}, + {(1 << 13), "layers", 13}, + {(1 << 14), "layers", 14}, + {(1 << 15), "layers", 15}, + {(1 << 16), "layers", 16}, + {(1 << 17), "layers", 17}, + {(1 << 18), "layers", 18}, + {(1 << 19), "layers", 19} }; /* Material mode */ -static AdrBit2Path ma_mode_bits[]= { +static AdrBit2Path ma_mode_bits[] = { // {MA_TRACEBLE, "traceable", 0}, -// {MA_SHADOW, "shadow", 0}, +// {MA_SHADOW, "shadow", 0}, // {MA_SHLESS, "shadeless", 0}, -// ... +// ... {MA_RAYTRANSP, "transparency", 0}, {MA_RAYMIRROR, "raytrace_mirror.enabled", 0}, // {MA_HALO, "type", MA_TYPE_HALO} @@ -154,99 +154,99 @@ static AdrBit2Path ma_mode_bits[]= { /* quick macro for returning the appropriate array for adrcode_bitmaps_to_paths() */ #define RET_ABP(items) \ { \ - *tot= sizeof(items)/sizeof(AdrBit2Path); \ + *tot = sizeof(items) / sizeof(AdrBit2Path); \ return items; \ } /* This function checks if a Blocktype+Adrcode combo, returning a mapping table */ -static AdrBit2Path *adrcode_bitmaps_to_paths (int blocktype, int adrcode, int *tot) +static AdrBit2Path *adrcode_bitmaps_to_paths(int blocktype, int adrcode, int *tot) { /* Object layers */ if ((blocktype == ID_OB) && (adrcode == OB_LAY)) RET_ABP(ob_layer_bits) - else if ((blocktype == ID_MA) && (adrcode == MA_MODE)) - RET_ABP(ma_mode_bits) - // XXX TODO: add other types... + else if ((blocktype == ID_MA) && (adrcode == MA_MODE)) + RET_ABP(ma_mode_bits) + // XXX TODO: add other types... - /* Normal curve */ - return NULL; + /* Normal curve */ + return NULL; } /* *************************************************** */ /* ADRCODE to RNA-Path Conversion Code - Standard */ /* Object types */ -static const char *ob_adrcodes_to_paths (int adrcode, int *array_index) +static const char *ob_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { case OB_LOC_X: - *array_index= 0; return "location"; + *array_index = 0; return "location"; case OB_LOC_Y: - *array_index= 1; return "location"; + *array_index = 1; return "location"; case OB_LOC_Z: - *array_index= 2; return "location"; + *array_index = 2; return "location"; case OB_DLOC_X: - *array_index= 0; return "delta_location"; + *array_index = 0; return "delta_location"; case OB_DLOC_Y: - *array_index= 1; return "delta_location"; + *array_index = 1; return "delta_location"; case OB_DLOC_Z: - *array_index= 2; return "delta_location"; + *array_index = 2; return "delta_location"; case OB_ROT_X: - *array_index= 0; return "rotation_euler"; + *array_index = 0; return "rotation_euler"; case OB_ROT_Y: - *array_index= 1; return "rotation_euler"; + *array_index = 1; return "rotation_euler"; case OB_ROT_Z: - *array_index= 2; return "rotation_euler"; + *array_index = 2; return "rotation_euler"; case OB_DROT_X: - *array_index= 0; return "delta_rotation_euler"; + *array_index = 0; return "delta_rotation_euler"; case OB_DROT_Y: - *array_index= 1; return "delta_rotation_euler"; + *array_index = 1; return "delta_rotation_euler"; case OB_DROT_Z: - *array_index= 2; return "delta_rotation_euler"; + *array_index = 2; return "delta_rotation_euler"; case OB_SIZE_X: - *array_index= 0; return "scale"; + *array_index = 0; return "scale"; case OB_SIZE_Y: - *array_index= 1; return "scale"; + *array_index = 1; return "scale"; case OB_SIZE_Z: - *array_index= 2; return "scale"; + *array_index = 2; return "scale"; case OB_DSIZE_X: - *array_index= 0; return "delta_scale"; + *array_index = 0; return "delta_scale"; case OB_DSIZE_Y: - *array_index= 1; return "delta_scale"; + *array_index = 1; return "delta_scale"; case OB_DSIZE_Z: - *array_index= 2; return "delta_scale"; + *array_index = 2; return "delta_scale"; case OB_COL_R: - *array_index= 0; return "color"; + *array_index = 0; return "color"; case OB_COL_G: - *array_index= 1; return "color"; + *array_index = 1; return "color"; case OB_COL_B: - *array_index= 2; return "color"; + *array_index = 2; return "color"; case OB_COL_A: - *array_index= 3; return "color"; + *array_index = 3; return "color"; #if 0 case OB_PD_FSTR: - if (ob->pd) poin= &(ob->pd->f_strength); + if (ob->pd) poin = &(ob->pd->f_strength); break; case OB_PD_FFALL: - if (ob->pd) poin= &(ob->pd->f_power); + if (ob->pd) poin = &(ob->pd->f_power); break; case OB_PD_SDAMP: - if (ob->pd) poin= &(ob->pd->pdef_damp); + if (ob->pd) poin = &(ob->pd->pdef_damp); break; case OB_PD_RDAMP: - if (ob->pd) poin= &(ob->pd->pdef_rdamp); + if (ob->pd) poin = &(ob->pd->pdef_rdamp); break; case OB_PD_PERM: - if (ob->pd) poin= &(ob->pd->pdef_perm); + if (ob->pd) poin = &(ob->pd->pdef_perm); break; case OB_PD_FMAXD: - if (ob->pd) poin= &(ob->pd->maxdist); + if (ob->pd) poin = &(ob->pd->maxdist); break; #endif } @@ -257,42 +257,42 @@ static const char *ob_adrcodes_to_paths (int adrcode, int *array_index) /* PoseChannel types * NOTE: pchan name comes from 'actname' added earlier... */ -static const char *pchan_adrcodes_to_paths (int adrcode, int *array_index) +static const char *pchan_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { case AC_QUAT_W: - *array_index= 0; return "rotation_quaternion"; + *array_index = 0; return "rotation_quaternion"; case AC_QUAT_X: - *array_index= 1; return "rotation_quaternion"; + *array_index = 1; return "rotation_quaternion"; case AC_QUAT_Y: - *array_index= 2; return "rotation_quaternion"; + *array_index = 2; return "rotation_quaternion"; case AC_QUAT_Z: - *array_index= 3; return "rotation_quaternion"; + *array_index = 3; return "rotation_quaternion"; case AC_EUL_X: - *array_index= 0; return "rotation_euler"; + *array_index = 0; return "rotation_euler"; case AC_EUL_Y: - *array_index= 1; return "rotation_euler"; + *array_index = 1; return "rotation_euler"; case AC_EUL_Z: - *array_index= 2; return "rotation_euler"; + *array_index = 2; return "rotation_euler"; case AC_LOC_X: - *array_index= 0; return "location"; + *array_index = 0; return "location"; case AC_LOC_Y: - *array_index= 1; return "location"; + *array_index = 1; return "location"; case AC_LOC_Z: - *array_index= 2; return "location"; + *array_index = 2; return "location"; case AC_SIZE_X: - *array_index= 0; return "scale"; + *array_index = 0; return "scale"; case AC_SIZE_Y: - *array_index= 1; return "scale"; + *array_index = 1; return "scale"; case AC_SIZE_Z: - *array_index= 2; return "scale"; + *array_index = 2; return "scale"; } /* for debugging only */ @@ -301,16 +301,16 @@ static const char *pchan_adrcodes_to_paths (int adrcode, int *array_index) } /* Constraint types */ -static const char *constraint_adrcodes_to_paths (int adrcode, int *array_index) +static const char *constraint_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { case CO_ENFORCE: return "influence"; - case CO_HEADTAIL: // XXX this needs to be wrapped in RNA.. probably then this path will be invalid + case CO_HEADTAIL: // XXX this needs to be wrapped in RNA.. probably then this path will be invalid return "data.head_tail"; } @@ -321,7 +321,7 @@ static const char *constraint_adrcodes_to_paths (int adrcode, int *array_index) * NOTE: as we don't have access to the keyblock where the data comes from (for now), * we'll just use numerical indices for now... */ -static char *shapekey_adrcodes_to_paths (int adrcode, int *UNUSED(array_index)) +static char *shapekey_adrcodes_to_paths(int adrcode, int *UNUSED(array_index)) { static char buf[128]; @@ -338,64 +338,64 @@ static char *shapekey_adrcodes_to_paths (int adrcode, int *UNUSED(array_index)) } /* MTex (Texture Slot) types */ -static const char *mtex_adrcodes_to_paths (int adrcode, int *UNUSED(array_index)) +static const char *mtex_adrcodes_to_paths(int adrcode, int *UNUSED(array_index)) { - const char *base=NULL, *prop=NULL; + const char *base = NULL, *prop = NULL; static char buf[128]; /* base part of path */ - if (adrcode & MA_MAP1) base= "textures[0]"; - else if (adrcode & MA_MAP2) base= "textures[1]"; - else if (adrcode & MA_MAP3) base= "textures[2]"; - else if (adrcode & MA_MAP4) base= "textures[3]"; - else if (adrcode & MA_MAP5) base= "textures[4]"; - else if (adrcode & MA_MAP6) base= "textures[5]"; - else if (adrcode & MA_MAP7) base= "textures[6]"; - else if (adrcode & MA_MAP8) base= "textures[7]"; - else if (adrcode & MA_MAP9) base= "textures[8]"; - else if (adrcode & MA_MAP10) base= "textures[9]"; - else if (adrcode & MA_MAP11) base= "textures[10]"; - else if (adrcode & MA_MAP12) base= "textures[11]"; - else if (adrcode & MA_MAP13) base= "textures[12]"; - else if (adrcode & MA_MAP14) base= "textures[13]"; - else if (adrcode & MA_MAP15) base= "textures[14]"; - else if (adrcode & MA_MAP16) base= "textures[15]"; - else if (adrcode & MA_MAP17) base= "textures[16]"; - else if (adrcode & MA_MAP18) base= "textures[17]"; + if (adrcode & MA_MAP1) base = "textures[0]"; + else if (adrcode & MA_MAP2) base = "textures[1]"; + else if (adrcode & MA_MAP3) base = "textures[2]"; + else if (adrcode & MA_MAP4) base = "textures[3]"; + else if (adrcode & MA_MAP5) base = "textures[4]"; + else if (adrcode & MA_MAP6) base = "textures[5]"; + else if (adrcode & MA_MAP7) base = "textures[6]"; + else if (adrcode & MA_MAP8) base = "textures[7]"; + else if (adrcode & MA_MAP9) base = "textures[8]"; + else if (adrcode & MA_MAP10) base = "textures[9]"; + else if (adrcode & MA_MAP11) base = "textures[10]"; + else if (adrcode & MA_MAP12) base = "textures[11]"; + else if (adrcode & MA_MAP13) base = "textures[12]"; + else if (adrcode & MA_MAP14) base = "textures[13]"; + else if (adrcode & MA_MAP15) base = "textures[14]"; + else if (adrcode & MA_MAP16) base = "textures[15]"; + else if (adrcode & MA_MAP17) base = "textures[16]"; + else if (adrcode & MA_MAP18) base = "textures[17]"; /* property identifier for path */ - adrcode= (adrcode & (MA_MAP1-1)); + adrcode = (adrcode & (MA_MAP1 - 1)); switch (adrcode) { #if 0 // XXX these are not wrapped in RNA yet! case MAP_OFS_X: - poin= &(mtex->ofs[0]); break; + poin = &(mtex->ofs[0]); break; case MAP_OFS_Y: - poin= &(mtex->ofs[1]); break; + poin = &(mtex->ofs[1]); break; case MAP_OFS_Z: - poin= &(mtex->ofs[2]); break; + poin = &(mtex->ofs[2]); break; case MAP_SIZE_X: - poin= &(mtex->size[0]); break; + poin = &(mtex->size[0]); break; case MAP_SIZE_Y: - poin= &(mtex->size[1]); break; + poin = &(mtex->size[1]); break; case MAP_SIZE_Z: - poin= &(mtex->size[2]); break; + poin = &(mtex->size[2]); break; case MAP_R: - poin= &(mtex->r); break; + poin = &(mtex->r); break; case MAP_G: - poin= &(mtex->g); break; + poin = &(mtex->g); break; case MAP_B: - poin= &(mtex->b); break; + poin = &(mtex->b); break; case MAP_DVAR: - poin= &(mtex->def_var); break; + poin = &(mtex->def_var); break; case MAP_COLF: - poin= &(mtex->colfac); break; + poin = &(mtex->colfac); break; case MAP_NORF: - poin= &(mtex->norfac); break; + poin = &(mtex->norfac); break; case MAP_VARF: - poin= &(mtex->varfac); break; + poin = &(mtex->varfac); break; #endif case MAP_DISP: - prop= "warp_factor"; break; + prop = "warp_factor"; break; } /* only build and return path if there's a property */ @@ -408,10 +408,10 @@ static const char *mtex_adrcodes_to_paths (int adrcode, int *UNUSED(array_index) } /* Texture types */ -static const char *texture_adrcodes_to_paths (int adrcode, int *array_index) +static const char *texture_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { @@ -420,7 +420,7 @@ static const char *texture_adrcodes_to_paths (int adrcode, int *array_index) case TE_TURB: return "turbulence"; - case TE_NDEPTH: // XXX texture RNA undefined + case TE_NDEPTH: // XXX texture RNA undefined //poin= &(tex->noisedepth); *type= IPO_SHORT; break; break; case TE_NTYPE: // XXX texture RNA undefined @@ -432,15 +432,15 @@ static const char *texture_adrcodes_to_paths (int adrcode, int *array_index) case TE_N_BAS2: return "noise_basis"; // XXX this is not yet defined in RNA... - /* voronoi */ + /* voronoi */ case TE_VNW1: - *array_index= 0; return "feature_weights"; + *array_index = 0; return "feature_weights"; case TE_VNW2: - *array_index= 1; return "feature_weights"; + *array_index = 1; return "feature_weights"; case TE_VNW3: - *array_index= 2; return "feature_weights"; + *array_index = 2; return "feature_weights"; case TE_VNW4: - *array_index= 3; return "feature_weights"; + *array_index = 3; return "feature_weights"; case TE_VNMEXP: return "minkovsky_exponent"; case TE_VN_DISTM: @@ -448,17 +448,17 @@ static const char *texture_adrcodes_to_paths (int adrcode, int *array_index) case TE_VN_COLT: return "color_type"; - /* distorted noise / voronoi */ + /* distorted noise / voronoi */ case TE_ISCA: return "noise_intensity"; - /* distorted noise */ + /* distorted noise */ case TE_DISTA: return "distortion_amount"; - /* musgrave */ + /* musgrave */ case TE_MG_TYP: // XXX texture RNA undefined - // poin= &(tex->stype); *type= IPO_SHORT; break; + // poin= &(tex->stype); *type= IPO_SHORT; break; break; case TE_MGH: return "highest_dimension"; @@ -472,11 +472,11 @@ static const char *texture_adrcodes_to_paths (int adrcode, int *array_index) return "gain"; case TE_COL_R: - *array_index= 0; return "rgb_factor"; + *array_index = 0; return "rgb_factor"; case TE_COL_G: - *array_index= 1; return "rgb_factor"; + *array_index = 1; return "rgb_factor"; case TE_COL_B: - *array_index= 2; return "rgb_factor"; + *array_index = 2; return "rgb_factor"; case TE_BRIGHT: return "brightness"; @@ -488,33 +488,33 @@ static const char *texture_adrcodes_to_paths (int adrcode, int *array_index) } /* Material Types */ -static const char *material_adrcodes_to_paths (int adrcode, int *array_index) +static const char *material_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { case MA_COL_R: - *array_index= 0; return "diffuse_color"; + *array_index = 0; return "diffuse_color"; case MA_COL_G: - *array_index= 1; return "diffuse_color"; + *array_index = 1; return "diffuse_color"; case MA_COL_B: - *array_index= 2; return "diffuse_color"; + *array_index = 2; return "diffuse_color"; case MA_SPEC_R: - *array_index= 0; return "specular_color"; + *array_index = 0; return "specular_color"; case MA_SPEC_G: - *array_index= 1; return "specular_color"; + *array_index = 1; return "specular_color"; case MA_SPEC_B: - *array_index= 2; return "specular_color"; + *array_index = 2; return "specular_color"; case MA_MIR_R: - *array_index= 0; return "mirror_color"; + *array_index = 0; return "mirror_color"; case MA_MIR_G: - *array_index= 1; return "mirror_color"; + *array_index = 1; return "mirror_color"; case MA_MIR_B: - *array_index= 2; return "mirror_color"; + *array_index = 2; return "mirror_color"; case MA_ALPHA: return "alpha"; @@ -572,10 +572,10 @@ static const char *material_adrcodes_to_paths (int adrcode, int *array_index) } /* Camera Types */ -static const char *camera_adrcodes_to_paths (int adrcode, int *array_index) +static const char *camera_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { @@ -596,9 +596,9 @@ static const char *camera_adrcodes_to_paths (int adrcode, int *array_index) #if 0 // XXX these are not defined in RNA case CAM_YF_APERT: - poin= &(ca->YF_aperture); break; + poin = &(ca->YF_aperture); break; case CAM_YF_FDIST: - poin= &(ca->YF_dofdist); break; + poin = &(ca->YF_dofdist); break; #endif // XXX these are not defined in RNA case CAM_SHIFT_X: @@ -612,10 +612,10 @@ static const char *camera_adrcodes_to_paths (int adrcode, int *array_index) } /* Lamp Types */ -static const char *lamp_adrcodes_to_paths (int adrcode, int *array_index) +static const char *lamp_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { @@ -623,11 +623,11 @@ static const char *lamp_adrcodes_to_paths (int adrcode, int *array_index) return "energy"; case LA_COL_R: - *array_index= 0; return "color"; + *array_index = 0; return "color"; case LA_COL_G: - *array_index= 1; return "color"; + *array_index = 1; return "color"; case LA_COL_B: - *array_index= 2; return "color"; + *array_index = 2; return "color"; case LA_DIST: return "distance"; @@ -654,10 +654,10 @@ static const char *lamp_adrcodes_to_paths (int adrcode, int *array_index) } /* Sound Types */ -static const char *sound_adrcodes_to_paths (int adrcode, int *array_index) +static const char *sound_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { @@ -665,7 +665,7 @@ static const char *sound_adrcodes_to_paths (int adrcode, int *array_index) return "volume"; case SND_PITCH: return "pitch"; - /* XXX Joshua -- I had wrapped panning in rna, but someone commented out, calling it "unused" */ + /* XXX Joshua -- I had wrapped panning in rna, but someone commented out, calling it "unused" */ #if 0 case SND_PANNING: return "panning"; @@ -679,25 +679,25 @@ static const char *sound_adrcodes_to_paths (int adrcode, int *array_index) } /* World Types */ -static const char *world_adrcodes_to_paths (int adrcode, int *array_index) +static const char *world_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { case WO_HOR_R: - *array_index= 0; return "horizon_color"; + *array_index = 0; return "horizon_color"; case WO_HOR_G: - *array_index= 1; return "horizon_color"; + *array_index = 1; return "horizon_color"; case WO_HOR_B: - *array_index= 2; return "horizon_color"; + *array_index = 2; return "horizon_color"; case WO_ZEN_R: - *array_index= 0; return "zenith_color"; + *array_index = 0; return "zenith_color"; case WO_ZEN_G: - *array_index= 1; return "zenith_color"; + *array_index = 1; return "zenith_color"; case WO_ZEN_B: - *array_index= 2; return "zenith_color"; + *array_index = 2; return "zenith_color"; case WO_EXPOS: return "exposure"; @@ -724,16 +724,16 @@ static const char *world_adrcodes_to_paths (int adrcode, int *array_index) default: /* for now, we assume that the others were MTex channels */ return mtex_adrcodes_to_paths(adrcode, array_index); - } + } return NULL; } /* Particle Types */ -static const char *particle_adrcodes_to_paths (int adrcode, int *array_index) +static const char *particle_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { @@ -752,11 +752,11 @@ static const char *particle_adrcodes_to_paths (int adrcode, int *array_index) case PART_LENGTH: return "settings.length"; case PART_GRAV_X: - *array_index= 0; return "settings.acceleration"; + *array_index = 0; return "settings.acceleration"; case PART_GRAV_Y: - *array_index= 1; return "settings.acceleration"; + *array_index = 1; return "settings.acceleration"; case PART_GRAV_Z: - *array_index= 2; return "settings.acceleration"; + *array_index = 2; return "settings.acceleration"; case PART_KINK_AMP: return "settings.kink_amplitude"; case PART_KINK_FREQ: @@ -773,22 +773,22 @@ static const char *particle_adrcodes_to_paths (int adrcode, int *array_index) * as the similar object forces */ #if 0 case PART_PD_FSTR: - if (part->pd) poin= &(part->pd->f_strength); + if (part->pd) poin = &(part->pd->f_strength); break; case PART_PD_FFALL: - if (part->pd) poin= &(part->pd->f_power); + if (part->pd) poin = &(part->pd->f_power); break; case PART_PD_FMAXD: - if (part->pd) poin= &(part->pd->maxdist); + if (part->pd) poin = &(part->pd->maxdist); break; case PART_PD2_FSTR: - if (part->pd2) poin= &(part->pd2->f_strength); + if (part->pd2) poin = &(part->pd2->f_strength); break; case PART_PD2_FFALL: - if (part->pd2) poin= &(part->pd2->f_power); + if (part->pd2) poin = &(part->pd2->f_power); break; case PART_PD2_FMAXD: - if (part->pd2) poin= &(part->pd2->maxdist); + if (part->pd2) poin = &(part->pd2->maxdist); break; #endif @@ -807,84 +807,84 @@ static const char *particle_adrcodes_to_paths (int adrcode, int *array_index) * - array_index - index in property's array (if applicable) to use * - return - the allocated path... */ -static char *get_rna_access (int blocktype, int adrcode, char actname[], char constname[], Sequence *seq, int *array_index) +static char *get_rna_access(int blocktype, int adrcode, char actname[], char constname[], Sequence *seq, int *array_index) { - DynStr *path= BLI_dynstr_new(); - const char *propname=NULL; - char *rpath=NULL; + DynStr *path = BLI_dynstr_new(); + const char *propname = NULL; + char *rpath = NULL; char buf[512]; - int dummy_index= 0; + int dummy_index = 0; /* hack: if constname is set, we can only be dealing with an Constraint curve */ if (constname) - blocktype= ID_CO; + blocktype = ID_CO; /* get property name based on blocktype */ switch (blocktype) { case ID_OB: /* object */ - propname= ob_adrcodes_to_paths(adrcode, &dummy_index); + propname = ob_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_PO: /* pose channel */ - propname= pchan_adrcodes_to_paths(adrcode, &dummy_index); + propname = pchan_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_KE: /* shapekeys */ - propname= shapekey_adrcodes_to_paths(adrcode, &dummy_index); + propname = shapekey_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_CO: /* constraint */ - propname= constraint_adrcodes_to_paths(adrcode, &dummy_index); + propname = constraint_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_TE: /* texture */ - propname= texture_adrcodes_to_paths(adrcode, &dummy_index); + propname = texture_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_MA: /* material */ - propname= material_adrcodes_to_paths(adrcode, &dummy_index); + propname = material_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_CA: /* camera */ - propname= camera_adrcodes_to_paths(adrcode, &dummy_index); + propname = camera_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_LA: /* lamp */ - propname= lamp_adrcodes_to_paths(adrcode, &dummy_index); + propname = lamp_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_SO: /* sound */ - propname= sound_adrcodes_to_paths(adrcode, &dummy_index); + propname = sound_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_WO: /* world */ - propname= world_adrcodes_to_paths(adrcode, &dummy_index); + propname = world_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_PA: /* particle */ - propname= particle_adrcodes_to_paths(adrcode, &dummy_index); + propname = particle_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_CU: /* curve */ /* this used to be a 'dummy' curve which got evaluated on the fly... * now we've got real var for this! */ - propname= "eval_time"; + propname = "eval_time"; break; /* XXX problematic blocktypes */ case ID_SEQ: /* sequencer strip */ //SEQ_FAC1: switch (adrcode) { - case SEQ_FAC1: - propname= "effect_fader"; - break; - case SEQ_FAC_SPEED: - propname= "speed_fader"; - break; - case SEQ_FAC_OPACITY: - propname= "blend_opacity"; - break; + case SEQ_FAC1: + propname = "effect_fader"; + break; + case SEQ_FAC_SPEED: + propname = "speed_fader"; + break; + case SEQ_FAC_OPACITY: + propname = "blend_opacity"; + break; } // poin= &(seq->facf0); // XXX this doesn't seem to be included anywhere in sequencer RNA... break; @@ -906,7 +906,7 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co if ((propname == NULL) && (blocktype > 0)) { /* nothing was found, so exit */ if (array_index) - *array_index= 0; + *array_index = 0; BLI_dynstr_free(path); @@ -914,7 +914,7 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co } else { if (array_index) - *array_index= dummy_index; + *array_index = dummy_index; } /* 'buf' _must_ be initialized in this block */ @@ -925,11 +925,11 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co BLI_snprintf(buf, sizeof(buf), "pose.bones[\"%s\"].constraints[\"%s\"]", actname, constname); } else if (actname && actname[0]) { - if ((blocktype == ID_OB) && strcmp(actname, "Object")==0) { + if ((blocktype == ID_OB) && strcmp(actname, "Object") == 0) { /* Actionified "Object" IPO's... no extra path stuff needed */ - buf[0]= '\0'; /* empty string */ + buf[0] = '\0'; /* empty string */ } - else if ((blocktype == ID_KE) && strcmp(actname, "Shape")==0) { + else if ((blocktype == ID_KE) && strcmp(actname, "Shape") == 0) { /* Actionified "Shape" IPO's - these are forced onto object level via the action container there... */ strcpy(buf, "data.shape_keys"); } @@ -944,10 +944,10 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co } else if (seq) { /* Sequence names in Scene */ - BLI_snprintf(buf, sizeof(buf), "sequence_editor.sequences_all[\"%s\"]", seq->name+2); + BLI_snprintf(buf, sizeof(buf), "sequence_editor.sequences_all[\"%s\"]", seq->name + 2); } else { - buf[0]= '\0'; /* empty string */ + buf[0] = '\0'; /* empty string */ } BLI_dynstr_append(path, buf); @@ -966,7 +966,7 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co } /* convert to normal MEM_malloc'd string */ - rpath= BLI_dynstr_get_cstring(path); + rpath = BLI_dynstr_get_cstring(path); BLI_dynstr_free(path); /* return path... */ @@ -977,7 +977,7 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co /* Conversion Utilities */ /* Convert adrcodes to driver target transform channel types */ -static short adrcode_to_dtar_transchan (short adrcode) +static short adrcode_to_dtar_transchan(short adrcode) { switch (adrcode) { case OB_LOC_X: @@ -1007,12 +1007,12 @@ static short adrcode_to_dtar_transchan (short adrcode) } /* Convert IpoDriver to ChannelDriver - will free the old data (i.e. the old driver) */ -static ChannelDriver *idriver_to_cdriver (IpoDriver *idriver) +static ChannelDriver *idriver_to_cdriver(IpoDriver *idriver) { ChannelDriver *cdriver; /* allocate memory for new driver */ - cdriver= MEM_callocN(sizeof(ChannelDriver), "ChannelDriver"); + cdriver = MEM_callocN(sizeof(ChannelDriver), "ChannelDriver"); /* if 'pydriver', just copy data across */ if (idriver->type == IPO_DRIVER_TYPE_PYTHON) { @@ -1027,54 +1027,54 @@ static ChannelDriver *idriver_to_cdriver (IpoDriver *idriver) DriverTarget *dtar = NULL; /* this should be ok for all types here... */ - cdriver->type= DRIVER_TYPE_AVERAGE; + cdriver->type = DRIVER_TYPE_AVERAGE; /* what to store depends on the 'blocktype' - object or posechannel */ if (idriver->blocktype == ID_AR) { /* PoseChannel */ if (idriver->adrcode == OB_ROT_DIFF) { /* Rotational Difference requires a special type of variable */ - dvar= driver_add_new_variable(cdriver); + dvar = driver_add_new_variable(cdriver); driver_change_variable_type(dvar, DVAR_TYPE_ROT_DIFF); - /* first bone target */ - dtar= &dvar->targets[0]; - dtar->id= (ID *)idriver->ob; - dtar->idtype= ID_OB; + /* first bone target */ + dtar = &dvar->targets[0]; + dtar->id = (ID *)idriver->ob; + dtar->idtype = ID_OB; if (idriver->name[0]) BLI_strncpy(dtar->pchan_name, idriver->name, sizeof(dtar->pchan_name)); - /* second bone target (name was stored in same var as the first one) */ - dtar= &dvar->targets[1]; - dtar->id= (ID *)idriver->ob; - dtar->idtype= ID_OB; + /* second bone target (name was stored in same var as the first one) */ + dtar = &dvar->targets[1]; + dtar->id = (ID *)idriver->ob; + dtar->idtype = ID_OB; if (idriver->name[0]) // xxx... for safety - BLI_strncpy(dtar->pchan_name, idriver->name+DRIVER_NAME_OFFS, sizeof(dtar->pchan_name)); + BLI_strncpy(dtar->pchan_name, idriver->name + DRIVER_NAME_OFFS, sizeof(dtar->pchan_name)); } else { /* only a single variable, of type 'transform channel' */ - dvar= driver_add_new_variable(cdriver); + dvar = driver_add_new_variable(cdriver); driver_change_variable_type(dvar, DVAR_TYPE_TRANSFORM_CHAN); /* only requires a single target */ - dtar= &dvar->targets[0]; - dtar->id= (ID *)idriver->ob; - dtar->idtype= ID_OB; + dtar = &dvar->targets[0]; + dtar->id = (ID *)idriver->ob; + dtar->idtype = ID_OB; if (idriver->name[0]) BLI_strncpy(dtar->pchan_name, idriver->name, sizeof(dtar->pchan_name)); - dtar->transChan= adrcode_to_dtar_transchan(idriver->adrcode); + dtar->transChan = adrcode_to_dtar_transchan(idriver->adrcode); dtar->flag |= DTAR_FLAG_LOCALSPACE; /* old drivers took local space */ } } else { /* Object */ - /* only a single variable, of type 'transform channel' */ - dvar= driver_add_new_variable(cdriver); + /* only a single variable, of type 'transform channel' */ + dvar = driver_add_new_variable(cdriver); driver_change_variable_type(dvar, DVAR_TYPE_TRANSFORM_CHAN); - /* only requires single target */ - dtar= &dvar->targets[0]; - dtar->id= (ID *)idriver->ob; - dtar->idtype= ID_OB; - dtar->transChan= adrcode_to_dtar_transchan(idriver->adrcode); + /* only requires single target */ + dtar = &dvar->targets[0]; + dtar->id = (ID *)idriver->ob; + dtar->idtype = ID_OB; + dtar->transChan = adrcode_to_dtar_transchan(idriver->adrcode); } } @@ -1085,7 +1085,7 @@ static ChannelDriver *idriver_to_cdriver (IpoDriver *idriver) /* Add F-Curve to the correct list * - grpname is needed to be used as group name where relevant, and is usually derived from actname */ -static void fcurve_add_to_list (ListBase *groups, ListBase *list, FCurve *fcu, char *grpname, int muteipo) +static void fcurve_add_to_list(ListBase *groups, ListBase *list, FCurve *fcu, char *grpname, int muteipo) { /* If we're adding to an action, we will have groups to write to... */ if (groups && grpname) { @@ -1093,22 +1093,22 @@ static void fcurve_add_to_list (ListBase *groups, ListBase *list, FCurve *fcu, c * and extract the resultant lists... */ bAction tmp_act; - bActionGroup *agrp= NULL; + bActionGroup *agrp = NULL; /* init the temp action */ memset(&tmp_act, 0, sizeof(bAction)); // XXX only enable this line if we get errors - tmp_act.groups.first= groups->first; - tmp_act.groups.last= groups->last; - tmp_act.curves.first= list->first; - tmp_act.curves.last= list->last; + tmp_act.groups.first = groups->first; + tmp_act.groups.last = groups->last; + tmp_act.curves.first = list->first; + tmp_act.curves.last = list->last; /* ... xxx, the other vars don't need to be filled in */ /* get the group to use */ - agrp= action_groups_find_named(&tmp_act, grpname); + agrp = BKE_action_group_find_name(&tmp_act, grpname); /* no matching group, so add one */ if (agrp == NULL) { /* Add a new group, and make it active */ - agrp= MEM_callocN(sizeof(bActionGroup), "bActionGroup"); + agrp = MEM_callocN(sizeof(bActionGroup), "bActionGroup"); agrp->flag = AGRP_SELECTED; if (muteipo) agrp->flag |= AGRP_MUTED; @@ -1127,10 +1127,10 @@ static void fcurve_add_to_list (ListBase *groups, ListBase *list, FCurve *fcu, c fcu->flag |= FCURVE_MUTED; /* set the output lists based on the ones in the temp action */ - groups->first= tmp_act.groups.first; - groups->last= tmp_act.groups.last; - list->first= tmp_act.curves.first; - list->last= tmp_act.curves.last; + groups->first = tmp_act.groups.first; + groups->last = tmp_act.groups.last; + list->first = tmp_act.curves.first; + list->last = tmp_act.curves.last; } else { /* simply add the F-Curve to the end of the given list */ @@ -1144,18 +1144,18 @@ static void fcurve_add_to_list (ListBase *groups, ListBase *list, FCurve *fcu, c * constname: name of Constraint-Channel (if applicable) that IPO-Curve's IPO-block belonged to * seq: sequencer-strip (if applicable) that IPO-Curve's IPO-block belonged to */ -static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve *icu, char *actname, char *constname, Sequence * seq, int muteipo) +static void icu_to_fcurves(ID *id, ListBase *groups, ListBase *list, IpoCurve *icu, char *actname, char *constname, Sequence *seq, int muteipo) { AdrBit2Path *abp; FCurve *fcu; int totbits; /* allocate memory for a new F-Curve */ - fcu= MEM_callocN(sizeof(FCurve), "FCurve"); + fcu = MEM_callocN(sizeof(FCurve), "FCurve"); /* convert driver */ if (icu->driver) - fcu->driver= idriver_to_cdriver(icu->driver); + fcu->driver = idriver_to_cdriver(icu->driver); /* copy flags */ if (icu->flag & IPO_VISIBLE) fcu->flag |= FCURVE_VISIBLE; @@ -1170,9 +1170,9 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * case IPO_DIR: /* linear extrapolation */ { /* just copy, as the new defines match the old ones... */ - fcu->extend= icu->extrap; + fcu->extend = icu->extrap; } - break; + break; case IPO_CYCL: /* cyclic extrapolation */ case IPO_CYCLX: /* cyclic extrapolation + offset */ @@ -1180,22 +1180,22 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * /* Add a new FModifier (Cyclic) instead of setting extend value * as that's the new equivalent of that option. */ - FModifier *fcm= add_fmodifier(&fcu->modifiers, FMODIFIER_TYPE_CYCLES); - FMod_Cycles *data= (FMod_Cycles *)fcm->data; + FModifier *fcm = add_fmodifier(&fcu->modifiers, FMODIFIER_TYPE_CYCLES); + FMod_Cycles *data = (FMod_Cycles *)fcm->data; /* if 'offset' one is in use, set appropriate settings */ if (icu->extrap == IPO_CYCLX) - data->before_mode= data->after_mode= FCM_EXTRAPOLATE_CYCLIC_OFFSET; + data->before_mode = data->after_mode = FCM_EXTRAPOLATE_CYCLIC_OFFSET; else - data->before_mode= data->after_mode= FCM_EXTRAPOLATE_CYCLIC; + data->before_mode = data->after_mode = FCM_EXTRAPOLATE_CYCLIC; } - break; + break; } /* -------- */ /* get adrcode <-> bitflags mapping to handle nasty bitflag curves? */ - abp= adrcode_bitmaps_to_paths(icu->blocktype, icu->adrcode, &totbits); + abp = adrcode_bitmaps_to_paths(icu->blocktype, icu->adrcode, &totbits); if (abp && totbits) { FCurve *fcurve; int b; @@ -1203,49 +1203,49 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * if (G.debug & G_DEBUG) printf("\tconvert bitflag ipocurve, totbits = %d\n", totbits); /* add the 'only int values' flag */ - fcu->flag |= (FCURVE_INT_VALUES|FCURVE_DISCRETE_VALUES); + fcu->flag |= (FCURVE_INT_VALUES | FCURVE_DISCRETE_VALUES); /* for each bit we have to remap + check for: * 1) we need to make copy the existing F-Curve data (fcu -> fcurve), - * except for the last one which will use the original + * except for the last one which will use the original * 2) copy the relevant path info across * 3) filter the keyframes for the flag of interest */ - for (b=0; b < totbits; b++, abp++) { - unsigned int i=0; + for (b = 0; b < totbits; b++, abp++) { + unsigned int i = 0; /* make a copy of existing base-data if not the last curve */ - if (b < (totbits-1)) - fcurve= copy_fcurve(fcu); + if (b < (totbits - 1)) + fcurve = copy_fcurve(fcu); else - fcurve= fcu; + fcurve = fcu; /* set path */ - fcurve->rna_path= BLI_strdup(abp->path); - fcurve->array_index= abp->array_index; + fcurve->rna_path = BLI_strdup(abp->path); + fcurve->array_index = abp->array_index; /* convert keyframes * - beztriples and bpoints are mutually exclusive, so we won't have both at the same time * - beztriples are more likely to be encountered as they are keyframes (the other type wasn't used yet) */ - fcurve->totvert= icu->totvert; + fcurve->totvert = icu->totvert; if (icu->bezt) { BezTriple *dst, *src; /* allocate new array for keyframes/beztriples */ - fcurve->bezt= MEM_callocN(sizeof(BezTriple)*fcurve->totvert, "BezTriples"); + fcurve->bezt = MEM_callocN(sizeof(BezTriple) * fcurve->totvert, "BezTriples"); /* loop through copying all BezTriples individually, as we need to modify a few things */ - for (dst=fcurve->bezt, src=icu->bezt, i=0; i < fcurve->totvert; i++, dst++, src++) { + for (dst = fcurve->bezt, src = icu->bezt, i = 0; i < fcurve->totvert; i++, dst++, src++) { /* firstly, copy BezTriple data */ - *dst= *src; + *dst = *src; /* interpolation can only be constant... */ - dst->ipo= BEZT_IPO_CONST; + dst->ipo = BEZT_IPO_CONST; /* 'hide' flag is now used for keytype - only 'keyframes' existed before */ - dst->hide= BEZT_KEYTYPE_KEYFRAME; + dst->hide = BEZT_KEYTYPE_KEYFRAME; /* auto-handles - per curve to per handle */ if (icu->flag & IPO_AUTO_HORIZ) { @@ -1255,9 +1255,9 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * /* correct values, by checking if the flag of interest is set */ if ( ((int)(dst->vec[1][1])) & (abp->bit) ) - dst->vec[0][1]= dst->vec[1][1]= dst->vec[2][1] = 1.0f; + dst->vec[0][1] = dst->vec[1][1] = dst->vec[2][1] = 1.0f; else - dst->vec[0][1]= dst->vec[1][1]= dst->vec[2][1] = 0.0f; + dst->vec[0][1] = dst->vec[1][1] = dst->vec[2][1] = 0.0f; } } else if (icu->bp) { @@ -1271,12 +1271,12 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * } } else { - unsigned int i=0; + unsigned int i = 0; /* get rna-path * - we will need to set the 'disabled' flag if no path is able to be made (for now) */ - fcu->rna_path= get_rna_access(icu->blocktype, icu->adrcode, actname, constname, seq, &fcu->array_index); + fcu->rna_path = get_rna_access(icu->blocktype, icu->adrcode, actname, constname, seq, &fcu->array_index); if (fcu->rna_path == NULL) fcu->flag |= FCURVE_DISABLED; @@ -1284,25 +1284,25 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * * - beztriples and bpoints are mutually exclusive, so we won't have both at the same time * - beztriples are more likely to be encountered as they are keyframes (the other type wasn't used yet) */ - fcu->totvert= icu->totvert; + fcu->totvert = icu->totvert; if (icu->bezt) { BezTriple *dst, *src; /* allocate new array for keyframes/beztriples */ - fcu->bezt= MEM_callocN(sizeof(BezTriple)*fcu->totvert, "BezTriples"); + fcu->bezt = MEM_callocN(sizeof(BezTriple) * fcu->totvert, "BezTriples"); /* loop through copying all BezTriples individually, as we need to modify a few things */ - for (dst=fcu->bezt, src=icu->bezt, i=0; i < fcu->totvert; i++, dst++, src++) { + for (dst = fcu->bezt, src = icu->bezt, i = 0; i < fcu->totvert; i++, dst++, src++) { /* firstly, copy BezTriple data */ - *dst= *src; + *dst = *src; /* now copy interpolation from curve (if not already set) */ if (icu->ipo != IPO_MIXED) - dst->ipo= icu->ipo; + dst->ipo = icu->ipo; /* 'hide' flag is now used for keytype - only 'keyframes' existed before */ - dst->hide= BEZT_KEYTYPE_KEYFRAME; + dst->hide = BEZT_KEYTYPE_KEYFRAME; /* auto-handles - per curve to per handle */ if (icu->flag & IPO_AUTO_HORIZ) { @@ -1315,9 +1315,9 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * * - we need radians for RNA to do the right thing */ if ( ((icu->blocktype == ID_OB) && ELEM3(icu->adrcode, OB_ROT_X, OB_ROT_Y, OB_ROT_Z)) || - ((icu->blocktype == ID_PO) && ELEM3(icu->adrcode, AC_EUL_X, AC_EUL_Y, AC_EUL_Z)) ) + ((icu->blocktype == ID_PO) && ELEM3(icu->adrcode, AC_EUL_X, AC_EUL_Y, AC_EUL_Z)) ) { - const float fac= (float)M_PI / 18.0f; //10.0f * M_PI/180.0f; + const float fac = (float)M_PI / 18.0f; //10.0f * M_PI/180.0f; dst->vec[0][1] *= fac; dst->vec[1][1] *= fac; @@ -1329,7 +1329,7 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * * - we now need as 'frames' */ if ( (id) && (icu->blocktype == GS(id->name)) && - (fcu->rna_path && strcmp(fcu->rna_path, "eval_time")==0) ) + (fcu->rna_path && strcmp(fcu->rna_path, "eval_time") == 0) ) { Curve *cu = (Curve *)id; @@ -1340,15 +1340,15 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * /* correct times for rotation drivers * - need to go from degrees to radians... - * - there's only really 1 target to worry about + * - there's only really 1 target to worry about * - were also degrees/10 */ if (fcu->driver && fcu->driver->variables.first) { - DriverVar *dvar= fcu->driver->variables.first; - DriverTarget *dtar= &dvar->targets[0]; + DriverVar *dvar = fcu->driver->variables.first; + DriverTarget *dtar = &dvar->targets[0]; if (ELEM3(dtar->transChan, DTAR_TRANSCHAN_ROTX, DTAR_TRANSCHAN_ROTY, DTAR_TRANSCHAN_ROTZ)) { - const float fac= (float)M_PI / 18.0f; + const float fac = (float)M_PI / 18.0f; dst->vec[0][0] *= fac; dst->vec[1][0] *= fac; @@ -1358,8 +1358,8 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * /* correct values for sequencer curves, that were not locked to frame */ if (seq && (seq->flag & SEQ_IPO_FRAME_LOCKED) == 0) { - double mul= (seq->enddisp-seq->startdisp)/100.0f; - double offset= seq->startdisp; + double mul = (seq->enddisp - seq->startdisp) / 100.0f; + double offset = seq->startdisp; dst->vec[0][0] *= mul; dst->vec[0][0] += offset; @@ -1389,7 +1389,7 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * * This does not assume that any ID or AnimData uses it, but does assume that * it is given two lists, which it will perform driver/animation-data separation. */ -static void ipo_to_animato (ID *id, Ipo *ipo, char actname[], char constname[], Sequence *seq, ListBase *animgroups, ListBase *anim, ListBase *drivers) +static void ipo_to_animato(ID *id, Ipo *ipo, char actname[], char constname[], Sequence *seq, ListBase *animgroups, ListBase *anim, ListBase *drivers) { IpoCurve *icu; @@ -1407,13 +1407,13 @@ static void ipo_to_animato (ID *id, Ipo *ipo, char actname[], char constname[], */ if (actname) { if ((ipo->blocktype == ID_OB) && (strcmp(actname, "Object") == 0)) - actname= NULL; + actname = NULL; else if ((ipo->blocktype == ID_OB) && (strcmp(actname, "Shape") == 0)) - actname= NULL; + actname = NULL; } /* loop over IPO-Curves, freeing as we progress */ - for (icu= ipo->curve.first; icu; icu= icu->next) { + for (icu = ipo->curve.first; icu; icu = icu->next) { /* Since an IPO-Curve may end up being made into many F-Curves (i.e. bitflag curves), * we figure out the best place to put the channel, then tell the curve-converter to just dump there */ @@ -1424,7 +1424,7 @@ static void ipo_to_animato (ID *id, Ipo *ipo, char actname[], char constname[], } else { MEM_freeN(icu->driver); - icu->driver= NULL; + icu->driver = NULL; } } else @@ -1436,8 +1436,8 @@ static void ipo_to_animato (ID *id, Ipo *ipo, char actname[], char constname[], if (ID_REAL_USERS(ipo) <= 0) { IpoCurve *icn; - for (icu= ipo->curve.first; icu; icu= icn) { - icn= icu->next; + for (icu = ipo->curve.first; icu; icu = icn) { + icn = icu->next; /* free driver */ if (icu->driver) @@ -1458,7 +1458,7 @@ static void ipo_to_animato (ID *id, Ipo *ipo, char actname[], char constname[], * to Objects, where ob->ipo and ob->action need to be combined). * NOTE: we need to be careful here, as same data-structs are used for new system too! */ -static void action_to_animato (ID *id, bAction *act, ListBase *groups, ListBase *curves, ListBase *drivers) +static void action_to_animato(ID *id, bAction *act, ListBase *groups, ListBase *curves, ListBase *drivers) { bActionChannel *achan, *achann; bConstraintChannel *conchan, *conchann; @@ -1473,27 +1473,27 @@ static void action_to_animato (ID *id, bAction *act, ListBase *groups, ListBase BLI_freelistN(&act->groups); /* loop through Action-Channels, converting data, freeing as we go */ - for (achan= act->chanbase.first; achan; achan= achann) { + for (achan = act->chanbase.first; achan; achan = achann) { /* get pointer to next Action Channel */ - achann= achan->next; + achann = achan->next; /* convert Action Channel's IPO data */ if (achan->ipo) { ipo_to_animato(id, achan->ipo, achan->name, NULL, NULL, groups, curves, drivers); achan->ipo->id.us--; - achan->ipo= NULL; + achan->ipo = NULL; } /* convert constraint channel IPO-data */ - for (conchan= achan->constraintChannels.first; conchan; conchan= conchann) { + for (conchan = achan->constraintChannels.first; conchan; conchan = conchann) { /* get pointer to next Constraint Channel */ - conchann= conchan->next; + conchann = conchan->next; /* convert Constraint Channel's IPO data */ if (conchan->ipo) { ipo_to_animato(id, conchan->ipo, achan->name, conchan->name, NULL, groups, curves, drivers); conchan->ipo->id.us--; - conchan->ipo= NULL; + conchan->ipo = NULL; } /* free Constraint Channel */ @@ -1512,9 +1512,9 @@ static void action_to_animato (ID *id, bAction *act, ListBase *groups, ListBase * This assumes that AnimData has been added already. Separation of drivers * from animation data is accomplished here too... */ -static void ipo_to_animdata (ID *id, Ipo *ipo, char actname[], char constname[], Sequence *seq) +static void ipo_to_animdata(ID *id, Ipo *ipo, char actname[], char constname[], Sequence *seq) { - AnimData *adt= BKE_animdata_from_id(id); + AnimData *adt = BKE_animdata_from_id(id); ListBase anim = {NULL, NULL}; ListBase drivers = {NULL, NULL}; @@ -1528,8 +1528,8 @@ static void ipo_to_animdata (ID *id, Ipo *ipo, char actname[], char constname[], if (G.debug & G_DEBUG) { printf("ipo to animdata - ID:%s, IPO:%s, actname:%s constname:%s seqname:%s curves:%d\n", - id->name+2, ipo->id.name+2, (actname)?actname:"<None>", (constname)?constname:"<None>", (seq)?(seq->name+2):"<None>", - BLI_countlist(&ipo->curve)); + id->name + 2, ipo->id.name + 2, (actname) ? actname : "<None>", (constname) ? constname : "<None>", (seq) ? (seq->name + 2) : "<None>", + BLI_countlist(&ipo->curve)); } /* Convert curves to animato system (separated into separate lists of F-Curves for animation and drivers), @@ -1545,9 +1545,9 @@ static void ipo_to_animdata (ID *id, Ipo *ipo, char actname[], char constname[], if (adt->action == NULL) { char nameBuf[MAX_ID_NAME]; - BLI_snprintf(nameBuf, sizeof(nameBuf), "CDA:%s", ipo->id.name+2); + BLI_snprintf(nameBuf, sizeof(nameBuf), "CDA:%s", ipo->id.name + 2); - adt->action= add_empty_action(nameBuf); + adt->action = add_empty_action(nameBuf); if (G.debug & G_DEBUG) printf("\t\tadded new action - '%s'\n", nameBuf); } @@ -1566,9 +1566,9 @@ static void ipo_to_animdata (ID *id, Ipo *ipo, char actname[], char constname[], /* Convert Action-block to new system * NOTE: we need to be careful here, as same data-structs are used for new system too! */ -static void action_to_animdata (ID *id, bAction *act) +static void action_to_animdata(ID *id, bAction *act) { - AnimData *adt= BKE_animdata_from_id(id); + AnimData *adt = BKE_animdata_from_id(id); /* only continue if there are Action Channels (indicating unconverted data) */ if (ELEM(NULL, adt, act->chanbase.first)) @@ -1578,7 +1578,7 @@ static void action_to_animdata (ID *id, bAction *act) if (adt->action == NULL) { /* set this Action as AnimData's Action */ if (G.debug & G_DEBUG) printf("act_to_adt - set adt action to act\n"); - adt->action= act; + adt->action = act; } /* convert Action data */ @@ -1592,16 +1592,16 @@ static void action_to_animdata (ID *id, bAction *act) // - NLA curve/stride modifiers... /* Convert NLA-Strip to new system */ -static void nlastrips_to_animdata (ID *id, ListBase *strips) +static void nlastrips_to_animdata(ID *id, ListBase *strips) { - AnimData *adt= BKE_animdata_from_id(id); + AnimData *adt = BKE_animdata_from_id(id); NlaTrack *nlt = NULL; NlaStrip *strip; bActionStrip *as, *asn; /* for each one of the original strips, convert to a new strip and free the old... */ - for (as= strips->first; as; as= asn) { - asn= as->next; + for (as = strips->first; as; as = asn) { + asn = as->next; /* this old strip is only worth something if it had an action... */ if (as->act) { @@ -1614,36 +1614,36 @@ static void nlastrips_to_animdata (ID *id, ListBase *strips) * - no need to muck around with the user-counts, since this is just * passing over the ref to the new owner, not creating an additional ref */ - strip= MEM_callocN(sizeof(NlaStrip), "NlaStrip"); - strip->act= as->act; - - /* endpoints */ - strip->start= as->start; - strip->end= as->end; - strip->actstart= as->actstart; - strip->actend= as->actend; - - /* action reuse */ - strip->repeat= as->repeat; - strip->scale= as->scale; - if (as->flag & ACTSTRIP_LOCK_ACTION) strip->flag |= NLASTRIP_FLAG_SYNC_LENGTH; + strip = MEM_callocN(sizeof(NlaStrip), "NlaStrip"); + strip->act = as->act; - /* blending */ - strip->blendin= as->blendin; - strip->blendout= as->blendout; - strip->blendmode= (as->mode==ACTSTRIPMODE_ADD) ? NLASTRIP_MODE_ADD : NLASTRIP_MODE_REPLACE; - if (as->flag & ACTSTRIP_AUTO_BLENDS) strip->flag |= NLASTRIP_FLAG_AUTO_BLENDS; - - /* assorted setting flags */ - if (as->flag & ACTSTRIP_SELECT) strip->flag |= NLASTRIP_FLAG_SELECT; - if (as->flag & ACTSTRIP_ACTIVE) strip->flag |= NLASTRIP_FLAG_ACTIVE; - - if (as->flag & ACTSTRIP_MUTE) strip->flag |= NLASTRIP_FLAG_MUTED; - if (as->flag & ACTSTRIP_REVERSE) strip->flag |= NLASTRIP_FLAG_REVERSE; - - /* by default, we now always extrapolate, while in the past this was optional */ - if ((as->flag & ACTSTRIP_HOLDLASTFRAME)==0) - strip->extendmode= NLASTRIP_EXTEND_NOTHING; + /* endpoints */ + strip->start = as->start; + strip->end = as->end; + strip->actstart = as->actstart; + strip->actend = as->actend; + + /* action reuse */ + strip->repeat = as->repeat; + strip->scale = as->scale; + if (as->flag & ACTSTRIP_LOCK_ACTION) strip->flag |= NLASTRIP_FLAG_SYNC_LENGTH; + + /* blending */ + strip->blendin = as->blendin; + strip->blendout = as->blendout; + strip->blendmode = (as->mode == ACTSTRIPMODE_ADD) ? NLASTRIP_MODE_ADD : NLASTRIP_MODE_REPLACE; + if (as->flag & ACTSTRIP_AUTO_BLENDS) strip->flag |= NLASTRIP_FLAG_AUTO_BLENDS; + + /* assorted setting flags */ + if (as->flag & ACTSTRIP_SELECT) strip->flag |= NLASTRIP_FLAG_SELECT; + if (as->flag & ACTSTRIP_ACTIVE) strip->flag |= NLASTRIP_FLAG_ACTIVE; + + if (as->flag & ACTSTRIP_MUTE) strip->flag |= NLASTRIP_FLAG_MUTED; + if (as->flag & ACTSTRIP_REVERSE) strip->flag |= NLASTRIP_FLAG_REVERSE; + + /* by default, we now always extrapolate, while in the past this was optional */ + if ((as->flag & ACTSTRIP_HOLDLASTFRAME) == 0) + strip->extendmode = NLASTRIP_EXTEND_NOTHING; } /* try to add this strip to the current NLA-Track (i.e. the 'last' one on the stack atm) */ @@ -1651,7 +1651,7 @@ static void nlastrips_to_animdata (ID *id, ListBase *strips) /* trying to add to the current failed (no space), * so add a new track to the stack, and add to that... */ - nlt= add_nlatrack(adt, NULL); + nlt = add_nlatrack(adt, NULL); BKE_nlatrack_add_strip(nlt, strip); } } @@ -1701,13 +1701,13 @@ void do_versions_ipos_to_animato(Main *main) /* ----------- Animation Attached to Data -------------- */ /* objects */ - for (id= main->object.first; id; id= id->next) { - Object *ob= (Object *)id; + for (id = main->object.first; id; id = id->next) { + Object *ob = (Object *)id; bPoseChannel *pchan; bConstraint *con; bConstraintChannel *conchan, *conchann; - if (G.debug & G_DEBUG) printf("\tconverting ob %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting ob %s\n", id->name + 2); /* check if object has any animation data */ if (ob->nlastrips.first) { @@ -1719,7 +1719,7 @@ void do_versions_ipos_to_animato(Main *main) ipo_to_animdata(id, ob->ipo, NULL, NULL, NULL); ob->ipo->id.us--; - ob->ipo= NULL; + ob->ipo = NULL; } /* Action is skipped since it'll be used by some strip in the NLA anyway, @@ -1727,7 +1727,7 @@ void do_versions_ipos_to_animato(Main *main) */ if (ob->action) { ob->action->id.us--; - ob->action= NULL; + ob->action = NULL; } /* finally NLA */ @@ -1735,7 +1735,7 @@ void do_versions_ipos_to_animato(Main *main) } else if ((ob->ipo) || (ob->action)) { /* Add AnimData block */ - AnimData *adt= BKE_id_add_animdata(id); + AnimData *adt = BKE_id_add_animdata(id); /* Action first - so that Action name get conserved */ if (ob->action) { @@ -1744,7 +1744,7 @@ void do_versions_ipos_to_animato(Main *main) /* only decrease usercount if this Action isn't now being used by AnimData */ if (ob->action != adt->action) { ob->action->id.us--; - ob->action= NULL; + ob->action = NULL; } } @@ -1752,7 +1752,7 @@ void do_versions_ipos_to_animato(Main *main) if (ob->ipo) { ipo_to_animdata(id, ob->ipo, NULL, NULL, NULL); ob->ipo->id.us--; - ob->ipo= NULL; + ob->ipo = NULL; } } @@ -1761,8 +1761,8 @@ void do_versions_ipos_to_animato(Main *main) /* Verify if there's AnimData block */ BKE_id_add_animdata(id); - for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - for (con= pchan->constraints.first; con; con= con->next) { + for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { + for (con = pchan->constraints.first; con; con = con->next) { /* if constraint has own IPO, convert add these to Object * (NOTE: they're most likely to be drivers too) */ @@ -1772,14 +1772,14 @@ void do_versions_ipos_to_animato(Main *main) */ ipo_to_animdata(id, con->ipo, pchan->name, con->name, NULL); con->ipo->id.us--; - con->ipo= NULL; + con->ipo = NULL; } } } } /* check constraints for local IPO's */ - for (con= ob->constraints.first; con; con= con->next) { + for (con = ob->constraints.first; con; con = con->next) { /* if constraint has own IPO, convert add these to Object * (NOTE: they're most likely to be drivers too) */ @@ -1792,7 +1792,7 @@ void do_versions_ipos_to_animato(Main *main) */ ipo_to_animdata(id, con->ipo, NULL, con->name, NULL); con->ipo->id.us--; - con->ipo= NULL; + con->ipo = NULL; } /* check for Action Constraint */ @@ -1804,15 +1804,15 @@ void do_versions_ipos_to_animato(Main *main) /* Verify if there's AnimData block */ BKE_id_add_animdata(id); - for (conchan= ob->constraintChannels.first; conchan; conchan= conchann) { + for (conchan = ob->constraintChannels.first; conchan; conchan = conchann) { /* get pointer to next Constraint Channel */ - conchann= conchan->next; + conchann = conchan->next; /* convert Constraint Channel's IPO data */ if (conchan->ipo) { ipo_to_animdata(id, conchan->ipo, NULL, conchan->name, NULL); conchan->ipo->id.us--; - conchan->ipo= NULL; + conchan->ipo = NULL; } /* free Constraint Channel */ @@ -1822,17 +1822,17 @@ void do_versions_ipos_to_animato(Main *main) /* object's action will always be object-rooted */ { - AnimData *adt= BKE_animdata_from_id(id); + AnimData *adt = BKE_animdata_from_id(id); if (adt && adt->action) adt->action->idroot = ID_OB; } } /* shapekeys */ - for (id= main->key.first; id; id= id->next) { - Key *key= (Key *)id; + for (id = main->key.first; id; id = id->next) { + Key *key = (Key *)id; - if (G.debug & G_DEBUG) printf("\tconverting key %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting key %s\n", id->name + 2); /* we're only interested in the IPO * NOTE: for later, it might be good to port these over to Object instead, as many of these @@ -1840,7 +1840,7 @@ void do_versions_ipos_to_animato(Main *main) */ if (key->ipo) { /* Add AnimData block */ - AnimData *adt= BKE_id_add_animdata(id); + AnimData *adt = BKE_id_add_animdata(id); /* Convert Shapekey data... */ ipo_to_animdata(id, key->ipo, NULL, NULL, NULL); @@ -1849,20 +1849,20 @@ void do_versions_ipos_to_animato(Main *main) adt->action->idroot = key->ipo->blocktype; key->ipo->id.us--; - key->ipo= NULL; + key->ipo = NULL; } } /* materials */ - for (id= main->mat.first; id; id= id->next) { - Material *ma= (Material *)id; + for (id = main->mat.first; id; id = id->next) { + Material *ma = (Material *)id; - if (G.debug & G_DEBUG) printf("\tconverting material %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting material %s\n", id->name + 2); /* we're only interested in the IPO */ if (ma->ipo) { /* Add AnimData block */ - AnimData *adt= BKE_id_add_animdata(id); + AnimData *adt = BKE_id_add_animdata(id); /* Convert Material data... */ ipo_to_animdata(id, ma->ipo, NULL, NULL, NULL); @@ -1871,20 +1871,20 @@ void do_versions_ipos_to_animato(Main *main) adt->action->idroot = ma->ipo->blocktype; ma->ipo->id.us--; - ma->ipo= NULL; + ma->ipo = NULL; } } /* worlds */ - for (id= main->world.first; id; id= id->next) { - World *wo= (World *)id; + for (id = main->world.first; id; id = id->next) { + World *wo = (World *)id; - if (G.debug & G_DEBUG) printf("\tconverting world %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting world %s\n", id->name + 2); /* we're only interested in the IPO */ if (wo->ipo) { /* Add AnimData block */ - AnimData *adt= BKE_id_add_animdata(id); + AnimData *adt = BKE_id_add_animdata(id); /* Convert World data... */ ipo_to_animdata(id, wo->ipo, NULL, NULL, NULL); @@ -1893,26 +1893,26 @@ void do_versions_ipos_to_animato(Main *main) adt->action->idroot = wo->ipo->blocktype; wo->ipo->id.us--; - wo->ipo= NULL; + wo->ipo = NULL; } } /* sequence strips */ - for (id= main->scene.first; id; id= id->next) { + for (id = main->scene.first; id; id = id->next) { Scene *scene = (Scene *)id; - Editing * ed = scene->ed; + Editing *ed = scene->ed; if (ed && ed->seqbasep) { - Sequence * seq; + Sequence *seq; - AnimData *adt= BKE_id_add_animdata(id); + AnimData *adt = BKE_id_add_animdata(id); - SEQ_BEGIN (ed, seq) + SEQ_BEGIN(ed, seq) { IpoCurve *icu = (seq->ipo) ? seq->ipo->curve.first : NULL; short adrcode = SEQ_FAC1; if (G.debug & G_DEBUG) - printf("\tconverting sequence strip %s\n", seq->name+2); + printf("\tconverting sequence strip %s\n", seq->name + 2); if (ELEM(NULL, seq->ipo, icu)) { seq->flag |= SEQ_USE_EFFECT_DEFAULT_FADE; @@ -1941,7 +1941,7 @@ void do_versions_ipos_to_animato(Main *main) ipo_to_animdata((ID *)scene, seq->ipo, NULL, NULL, seq); if (adt->action) - adt->action->idroot = ID_SCE; /* scene-rooted */ + adt->action->idroot = ID_SCE; /* scene-rooted */ seq->ipo->id.us--; seq->ipo = NULL; @@ -1952,15 +1952,15 @@ void do_versions_ipos_to_animato(Main *main) /* textures */ - for (id= main->tex.first; id; id= id->next) { - Tex *te= (Tex *)id; + for (id = main->tex.first; id; id = id->next) { + Tex *te = (Tex *)id; - if (G.debug & G_DEBUG) printf("\tconverting texture %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting texture %s\n", id->name + 2); /* we're only interested in the IPO */ if (te->ipo) { /* Add AnimData block */ - AnimData *adt= BKE_id_add_animdata(id); + AnimData *adt = BKE_id_add_animdata(id); /* Convert Texture data... */ ipo_to_animdata(id, te->ipo, NULL, NULL, NULL); @@ -1969,20 +1969,20 @@ void do_versions_ipos_to_animato(Main *main) adt->action->idroot = te->ipo->blocktype; te->ipo->id.us--; - te->ipo= NULL; + te->ipo = NULL; } } /* cameras */ - for (id= main->camera.first; id; id= id->next) { - Camera *ca= (Camera *)id; + for (id = main->camera.first; id; id = id->next) { + Camera *ca = (Camera *)id; - if (G.debug & G_DEBUG) printf("\tconverting camera %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting camera %s\n", id->name + 2); /* we're only interested in the IPO */ if (ca->ipo) { /* Add AnimData block */ - AnimData *adt= BKE_id_add_animdata(id); + AnimData *adt = BKE_id_add_animdata(id); /* Convert Camera data... */ ipo_to_animdata(id, ca->ipo, NULL, NULL, NULL); @@ -1991,20 +1991,20 @@ void do_versions_ipos_to_animato(Main *main) adt->action->idroot = ca->ipo->blocktype; ca->ipo->id.us--; - ca->ipo= NULL; + ca->ipo = NULL; } } /* lamps */ - for (id= main->lamp.first; id; id= id->next) { - Lamp *la= (Lamp *)id; + for (id = main->lamp.first; id; id = id->next) { + Lamp *la = (Lamp *)id; - if (G.debug & G_DEBUG) printf("\tconverting lamp %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting lamp %s\n", id->name + 2); /* we're only interested in the IPO */ if (la->ipo) { /* Add AnimData block */ - AnimData *adt= BKE_id_add_animdata(id); + AnimData *adt = BKE_id_add_animdata(id); /* Convert Lamp data... */ ipo_to_animdata(id, la->ipo, NULL, NULL, NULL); @@ -2013,20 +2013,20 @@ void do_versions_ipos_to_animato(Main *main) adt->action->idroot = la->ipo->blocktype; la->ipo->id.us--; - la->ipo= NULL; + la->ipo = NULL; } } /* curves */ - for (id= main->curve.first; id; id= id->next) { - Curve *cu= (Curve *)id; + for (id = main->curve.first; id; id = id->next) { + Curve *cu = (Curve *)id; - if (G.debug & G_DEBUG) printf("\tconverting curve %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting curve %s\n", id->name + 2); /* we're only interested in the IPO */ if (cu->ipo) { /* Add AnimData block */ - AnimData *adt= BKE_id_add_animdata(id); + AnimData *adt = BKE_id_add_animdata(id); /* Convert Curve data... */ ipo_to_animdata(id, cu->ipo, NULL, NULL, NULL); @@ -2035,7 +2035,7 @@ void do_versions_ipos_to_animato(Main *main) adt->action->idroot = cu->ipo->blocktype; cu->ipo->id.us--; - cu->ipo= NULL; + cu->ipo = NULL; } } @@ -2051,10 +2051,10 @@ void do_versions_ipos_to_animato(Main *main) */ /* actions */ - for (id= main->action.first; id; id= id->next) { - bAction *act= (bAction *)id; + for (id = main->action.first; id; id = id->next) { + bAction *act = (bAction *)id; - if (G.debug & G_DEBUG) printf("\tconverting action %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting action %s\n", id->name + 2); /* if old action, it will be object-only... */ if (act->chanbase.first) @@ -2065,23 +2065,23 @@ void do_versions_ipos_to_animato(Main *main) } /* ipo's */ - for (id= main->ipo.first; id; id= id->next) { - Ipo *ipo= (Ipo *)id; + for (id = main->ipo.first; id; id = id->next) { + Ipo *ipo = (Ipo *)id; - if (G.debug & G_DEBUG) printf("\tconverting ipo %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting ipo %s\n", id->name + 2); /* most likely this IPO has already been processed, so check if any curves left to convert */ if (ipo->curve.first) { bAction *new_act; /* add a new action for this, and convert all data into that action */ - new_act= add_empty_action("ConvIPO_Action"); // XXX need a better name... + new_act = add_empty_action("ConvIPO_Action"); // XXX need a better name... ipo_to_animato(NULL, ipo, NULL, NULL, NULL, NULL, &new_act->curves, &drivers); new_act->idroot = ipo->blocktype; } /* clear fake-users, and set user-count to zero to make sure it is cleared on file-save */ - ipo->id.us= 0; + ipo->id.us = 0; ipo->id.flag &= ~LIB_FAKEUSER; } diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index 54a2613991a..e36e7bf6cf3 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -78,7 +78,7 @@ int slurph_opt = 1; -void free_key(Key *key) +void BKE_key_free(Key *key) { KeyBlock *kb; @@ -126,7 +126,7 @@ Key *add_key(ID *id) /* common function */ Key *key; char *el; - key = alloc_libblock(&G.main->key, ID_KE, "Key"); + key = BKE_libblock_alloc(&G.main->key, ID_KE, "Key"); key->type = KEY_NORMAL; key->from = id; @@ -170,14 +170,14 @@ Key *add_key(ID *id) /* common function */ return key; } -Key *copy_key(Key *key) +Key *BKE_key_copy(Key *key) { Key *keyn; KeyBlock *kbn, *kb; if (key == NULL) return NULL; - keyn = copy_libblock(&key->id); + keyn = BKE_libblock_copy(&key->id); BLI_duplicatelist(&keyn->block, &key->block); @@ -223,7 +223,7 @@ Key *copy_key_nolib(Key *key) return keyn; } -void make_local_key(Key *key) +void BKE_key_make_local(Key *key) { /* - only lib users: do nothing diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c index 11c3269ad37..20e3edc7044 100644 --- a/source/blender/blenkernel/intern/lamp.c +++ b/source/blender/blenkernel/intern/lamp.c @@ -51,34 +51,34 @@ #include "BKE_main.h" #include "BKE_node.h" -void *add_lamp(const char *name) +void *BKE_lamp_add(const char *name) { Lamp *la; - la= alloc_libblock(&G.main->lamp, ID_LA, name); - - la->r= la->g= la->b= la->k= 1.0f; - la->haint= la->energy= 1.0f; - la->dist= 25.0f; - la->spotsize= 45.0f; - la->spotblend= 0.15f; - la->att2= 1.0f; - la->mode= LA_SHAD_BUF; - la->bufsize= 512; - la->clipsta= 0.5f; - la->clipend= 40.0f; - la->shadspotsize= 45.0f; - la->samp= 3; - la->bias= 1.0f; - la->soft= 3.0f; - la->compressthresh= 0.05f; - la->ray_samp= la->ray_sampy= la->ray_sampz= 1; - la->area_size=la->area_sizey=la->area_sizez= 1.0f; - la->buffers= 1; - la->buftype= LA_SHADBUF_HALFWAY; + la = BKE_libblock_alloc(&G.main->lamp, ID_LA, name); + + la->r = la->g = la->b = la->k = 1.0f; + la->haint = la->energy = 1.0f; + la->dist = 25.0f; + la->spotsize = 45.0f; + la->spotblend = 0.15f; + la->att2 = 1.0f; + la->mode = LA_SHAD_BUF; + la->bufsize = 512; + la->clipsta = 0.5f; + la->clipend = 40.0f; + la->shadspotsize = 45.0f; + la->samp = 3; + la->bias = 1.0f; + la->soft = 3.0f; + la->compressthresh = 0.05f; + la->ray_samp = la->ray_sampy = la->ray_sampz = 1; + la->area_size = la->area_sizey = la->area_sizez = 1.0f; + la->buffers = 1; + la->buftype = LA_SHADBUF_HALFWAY; la->ray_samp_method = LA_SAMP_HALTON; la->adapt_thresh = 0.001f; - la->preview=NULL; + la->preview = NULL; la->falloff_type = LA_FALLOFF_INVSQUARE; la->curfalloff = curvemapping_add(1, 0.0f, 1.0f, 1.0f, 0.0f); la->sun_effect_type = 0; @@ -92,26 +92,26 @@ void *add_lamp(const char *name) la->atm_extinction_factor = 1.0f; la->atm_distance_factor = 1.0f; la->sun_intensity = 1.0f; - la->skyblendtype= MA_RAMP_ADD; - la->skyblendfac= 1.0f; - la->sky_colorspace= BLI_XYZ_CIE; - la->sky_exposure= 1.0f; - la->shadow_frustum_size= 10.0f; + la->skyblendtype = MA_RAMP_ADD; + la->skyblendfac = 1.0f; + la->sky_colorspace = BLI_XYZ_CIE; + la->sky_exposure = 1.0f; + la->shadow_frustum_size = 10.0f; curvemapping_initialize(la->curfalloff); return la; } -Lamp *copy_lamp(Lamp *la) +Lamp *BKE_lamp_copy(Lamp *la) { Lamp *lan; int a; - lan= copy_libblock(&la->id); + lan = BKE_libblock_copy(&la->id); - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { if (lan->mtex[a]) { - lan->mtex[a]= MEM_mallocN(sizeof(MTex), "copylamptex"); + lan->mtex[a] = MEM_mallocN(sizeof(MTex), "copylamptex"); memcpy(lan->mtex[a], la->mtex[a], sizeof(MTex)); id_us_plus((ID *)lan->mtex[a]->tex); } @@ -120,7 +120,7 @@ Lamp *copy_lamp(Lamp *la) lan->curfalloff = curvemapping_copy(la->curfalloff); if (la->nodetree) - lan->nodetree= ntreeCopyTree(la->nodetree); + lan->nodetree = ntreeCopyTree(la->nodetree); if (la->preview) lan->preview = BKE_previewimg_copy(la->preview); @@ -133,12 +133,12 @@ Lamp *localize_lamp(Lamp *la) Lamp *lan; int a; - lan= copy_libblock(&la->id); + lan = BKE_libblock_copy(&la->id); BLI_remlink(&G.main->lamp, lan); - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { if (lan->mtex[a]) { - lan->mtex[a]= MEM_mallocN(sizeof(MTex), "localize_lamp"); + lan->mtex[a] = MEM_mallocN(sizeof(MTex), "localize_lamp"); memcpy(lan->mtex[a], la->mtex[a], sizeof(MTex)); /* free lamp decrements */ id_us_plus((ID *)lan->mtex[a]->tex); @@ -148,71 +148,71 @@ Lamp *localize_lamp(Lamp *la) lan->curfalloff = curvemapping_copy(la->curfalloff); if (la->nodetree) - lan->nodetree= ntreeLocalize(la->nodetree); + lan->nodetree = ntreeLocalize(la->nodetree); - lan->preview= NULL; + lan->preview = NULL; return lan; } -void make_local_lamp(Lamp *la) +void BKE_lamp_make_local(Lamp *la) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (la->id.lib==NULL) return; - if (la->id.us==1) { + if (la->id.lib == NULL) return; + if (la->id.us == 1) { id_clear_lib_data(bmain, &la->id); return; } - ob= bmain->object.first; + ob = bmain->object.first; while (ob) { - if (ob->data==la) { - if (ob->id.lib) is_lib= TRUE; - else is_local= TRUE; + if (ob->data == la) { + if (ob->id.lib) is_lib = TRUE; + else is_local = TRUE; } - ob= ob->id.next; + ob = ob->id.next; } if (is_local && is_lib == FALSE) { id_clear_lib_data(bmain, &la->id); } else if (is_local && is_lib) { - Lamp *la_new= copy_lamp(la); - la_new->id.us= 0; + Lamp *la_new = BKE_lamp_copy(la); + la_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, la->id.lib, &la_new->id); - ob= bmain->object.first; + ob = bmain->object.first; while (ob) { - if (ob->data==la) { + if (ob->data == la) { - if (ob->id.lib==NULL) { - ob->data= la_new; + if (ob->id.lib == NULL) { + ob->data = la_new; la_new->id.us++; la->id.us--; } } - ob= ob->id.next; + ob = ob->id.next; } } } -void free_lamp(Lamp *la) +void BKE_lamp_free(Lamp *la) { MTex *mtex; int a; - for (a=0; a<MAX_MTEX; a++) { - mtex= la->mtex[a]; + for (a = 0; a < MAX_MTEX; a++) { + mtex = la->mtex[a]; if (mtex && mtex->tex) mtex->tex->id.us--; if (mtex) MEM_freeN(mtex); } diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index e78da48d153..c6f2bb75858 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -69,71 +69,71 @@ void calc_lat_fudu(int flag, int res, float *fu, float *du) { - if (res==1) { - *fu= 0.0; - *du= 0.0; + if (res == 1) { + *fu = 0.0; + *du = 0.0; } else if (flag & LT_GRID) { - *fu= -0.5f*(res-1); - *du= 1.0f; + *fu = -0.5f * (res - 1); + *du = 1.0f; } else { - *fu= -1.0f; - *du= 2.0f/(res-1); + *fu = -1.0f; + *du = 2.0f / (res - 1); } } -void resizelattice(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb) +void BKE_lattice_resize(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb) { BPoint *bp; int i, u, v, w; - float fu, fv, fw, uc, vc, wc, du=0.0, dv=0.0, dw=0.0; + float fu, fv, fw, uc, vc, wc, du = 0.0, dv = 0.0, dw = 0.0; float *co, (*vertexCos)[3] = NULL; /* vertex weight groups are just freed all for now */ if (lt->dvert) { - free_dverts(lt->dvert, lt->pntsu*lt->pntsv*lt->pntsw); - lt->dvert= NULL; + free_dverts(lt->dvert, lt->pntsu * lt->pntsv * lt->pntsw); + lt->dvert = NULL; } - while (uNew*vNew*wNew > 32000) { - if ( uNew>=vNew && uNew>=wNew) uNew--; - else if ( vNew>=uNew && vNew>=wNew) vNew--; + while (uNew * vNew * wNew > 32000) { + if (uNew >= vNew && uNew >= wNew) uNew--; + else if (vNew >= uNew && vNew >= wNew) vNew--; else wNew--; } - vertexCos = MEM_mallocN(sizeof(*vertexCos)*uNew*vNew*wNew, "tmp_vcos"); + vertexCos = MEM_mallocN(sizeof(*vertexCos) * uNew * vNew * wNew, "tmp_vcos"); calc_lat_fudu(lt->flag, uNew, &fu, &du); calc_lat_fudu(lt->flag, vNew, &fv, &dv); calc_lat_fudu(lt->flag, wNew, &fw, &dw); - /* If old size is different then resolution changed in interface, - * try to do clever reinit of points. Pretty simply idea, we just - * deform new verts by old lattice, but scaling them to match old - * size first. - */ + /* If old size is different then resolution changed in interface, + * try to do clever reinit of points. Pretty simply idea, we just + * deform new verts by old lattice, but scaling them to match old + * size first. + */ if (ltOb) { - if (uNew!=1 && lt->pntsu!=1) { + if (uNew != 1 && lt->pntsu != 1) { fu = lt->fu; - du = (lt->pntsu-1)*lt->du/(uNew-1); + du = (lt->pntsu - 1) * lt->du / (uNew - 1); } - if (vNew!=1 && lt->pntsv!=1) { + if (vNew != 1 && lt->pntsv != 1) { fv = lt->fv; - dv = (lt->pntsv-1)*lt->dv/(vNew-1); + dv = (lt->pntsv - 1) * lt->dv / (vNew - 1); } - if (wNew!=1 && lt->pntsw!=1) { + if (wNew != 1 && lt->pntsw != 1) { fw = lt->fw; - dw = (lt->pntsw-1)*lt->dw/(wNew-1); + dw = (lt->pntsw - 1) * lt->dw / (wNew - 1); } } co = vertexCos[0]; - for (w=0, wc=fw; w<wNew; w++, wc+=dw) { - for (v=0, vc=fv; v<vNew; v++, vc+=dv) { - for (u=0, uc=fu; u<uNew; u++, co+=3, uc+=du) { + for (w = 0, wc = fw; w < wNew; w++, wc += dw) { + for (v = 0, vc = fv; v < vNew; v++, vc += dv) { + for (u = 0, uc = fu; u < uNew; u++, co += 3, uc += du) { co[0] = uc; co[1] = vc; co[2] = wc; @@ -145,15 +145,15 @@ void resizelattice(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb) float mat[4][4]; int typeu = lt->typeu, typev = lt->typev, typew = lt->typew; - /* works best if we force to linear type (endpoints match) */ + /* works best if we force to linear type (endpoints match) */ lt->typeu = lt->typev = lt->typew = KEY_LINEAR; - /* prevent using deformed locations */ - freedisplist(<Ob->disp); + /* prevent using deformed locations */ + BKE_displist_free(<Ob->disp); copy_m4_m4(mat, ltOb->obmat); unit_m4(ltOb->obmat); - lattice_deform_verts(ltOb, NULL, NULL, vertexCos, uNew*vNew*wNew, NULL, 1.0f); + lattice_deform_verts(ltOb, NULL, NULL, vertexCos, uNew * vNew * wNew, NULL, 1.0f); copy_m4_m4(ltOb->obmat, mat); lt->typeu = typeu; @@ -173,63 +173,63 @@ void resizelattice(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb) lt->pntsw = wNew; MEM_freeN(lt->def); - lt->def= MEM_callocN(lt->pntsu*lt->pntsv*lt->pntsw*sizeof(BPoint), "lattice bp"); + lt->def = MEM_callocN(lt->pntsu * lt->pntsv * lt->pntsw * sizeof(BPoint), "lattice bp"); - bp= lt->def; + bp = lt->def; - for (i=0; i<lt->pntsu*lt->pntsv*lt->pntsw; i++, bp++) { + for (i = 0; i < lt->pntsu * lt->pntsv * lt->pntsw; i++, bp++) { copy_v3_v3(bp->vec, vertexCos[i]); } MEM_freeN(vertexCos); } -Lattice *add_lattice(const char *name) +Lattice *BKE_lattice_add(const char *name) { Lattice *lt; - lt= alloc_libblock(&G.main->latt, ID_LT, name); + lt = BKE_libblock_alloc(&G.main->latt, ID_LT, name); - lt->flag= LT_GRID; + lt->flag = LT_GRID; - lt->typeu= lt->typev= lt->typew= KEY_BSPLINE; + lt->typeu = lt->typev = lt->typew = KEY_BSPLINE; - lt->def= MEM_callocN(sizeof(BPoint), "lattvert"); /* temporary */ - resizelattice(lt, 2, 2, 2, NULL); /* creates a uniform lattice */ + lt->def = MEM_callocN(sizeof(BPoint), "lattvert"); /* temporary */ + BKE_lattice_resize(lt, 2, 2, 2, NULL); /* creates a uniform lattice */ return lt; } -Lattice *copy_lattice(Lattice *lt) +Lattice *BKE_lattice_copy(Lattice *lt) { Lattice *ltn; - ltn= copy_libblock(<->id); - ltn->def= MEM_dupallocN(lt->def); + ltn = BKE_libblock_copy(<->id); + ltn->def = MEM_dupallocN(lt->def); - ltn->key= copy_key(ltn->key); - if (ltn->key) ltn->key->from= (ID *)ltn; + ltn->key = BKE_key_copy(ltn->key); + if (ltn->key) ltn->key->from = (ID *)ltn; if (lt->dvert) { - int tot= lt->pntsu*lt->pntsv*lt->pntsw; - ltn->dvert = MEM_mallocN (sizeof (MDeformVert)*tot, "Lattice MDeformVert"); + int tot = lt->pntsu * lt->pntsv * lt->pntsw; + ltn->dvert = MEM_mallocN(sizeof (MDeformVert) * tot, "Lattice MDeformVert"); copy_dverts(ltn->dvert, lt->dvert, tot); } - ltn->editlatt= NULL; + ltn->editlatt = NULL; return ltn; } -void free_lattice(Lattice *lt) +void BKE_lattice_free(Lattice *lt) { if (lt->def) MEM_freeN(lt->def); - if (lt->dvert) free_dverts(lt->dvert, lt->pntsu*lt->pntsv*lt->pntsw); + if (lt->dvert) free_dverts(lt->dvert, lt->pntsu * lt->pntsv * lt->pntsw); if (lt->editlatt) { - Lattice *editlt= lt->editlatt->latt; + Lattice *editlt = lt->editlatt->latt; if (editlt->def) MEM_freeN(editlt->def); - if (editlt->dvert) free_dverts(editlt->dvert, lt->pntsu*lt->pntsv*lt->pntsw); + if (editlt->dvert) free_dverts(editlt->dvert, lt->pntsu * lt->pntsv * lt->pntsw); MEM_freeN(editlt); MEM_freeN(lt->editlatt); @@ -238,49 +238,49 @@ void free_lattice(Lattice *lt) /* free animation data */ if (lt->adt) { BKE_free_animdata(<->id); - lt->adt= NULL; + lt->adt = NULL; } } -void make_local_lattice(Lattice *lt) +void BKE_lattice_make_local(Lattice *lt) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (lt->id.lib==NULL) return; - if (lt->id.us==1) { + if (lt->id.lib == NULL) return; + if (lt->id.us == 1) { id_clear_lib_data(bmain, <->id); return; } - for (ob= bmain->object.first; ob && ELEM(FALSE, is_lib, is_local); ob= ob->id.next) { - if (ob->data==lt) { - if (ob->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (ob = bmain->object.first; ob && ELEM(FALSE, is_lib, is_local); ob = ob->id.next) { + if (ob->data == lt) { + if (ob->id.lib) is_lib = TRUE; + else is_local = TRUE; } } - if (is_local && is_lib==FALSE) { + if (is_local && is_lib == FALSE) { id_clear_lib_data(bmain, <->id); } else if (is_local && is_lib) { - Lattice *lt_new= copy_lattice(lt); - lt_new->id.us= 0; + Lattice *lt_new = BKE_lattice_copy(lt); + lt_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, lt->id.lib, <_new->id); - for (ob= bmain->object.first; ob; ob= ob->id.next) { - if (ob->data==lt) { - if (ob->id.lib==NULL) { - ob->data= lt_new; + for (ob = bmain->object.first; ob; ob = ob->id.next) { + if (ob->data == lt) { + if (ob->id.lib == NULL) { + ob->data = lt_new; lt_new->id.us++; lt->id.us--; } @@ -291,22 +291,22 @@ void make_local_lattice(Lattice *lt) void init_latt_deform(Object *oblatt, Object *ob) { - /* we make an array with all differences */ - Lattice *lt= oblatt->data; + /* we make an array with all differences */ + Lattice *lt = oblatt->data; BPoint *bp; - DispList *dl = find_displist(&oblatt->disp, DL_VERTS); - float *co = dl?dl->verts:NULL; + DispList *dl = BKE_displist_find(&oblatt->disp, DL_VERTS); + float *co = dl ? dl->verts : NULL; float *fp, imat[4][4]; float fu, fv, fw; int u, v, w; - if (lt->editlatt) lt= lt->editlatt->latt; + if (lt->editlatt) lt = lt->editlatt->latt; bp = lt->def; - fp= lt->latticedata= MEM_mallocN(sizeof(float)*3*lt->pntsu*lt->pntsv*lt->pntsw, "latticedata"); + fp = lt->latticedata = MEM_mallocN(sizeof(float) * 3 * lt->pntsu * lt->pntsv * lt->pntsw, "latticedata"); - /* for example with a particle system: ob==0 */ - if (ob==NULL) { + /* for example with a particle system: ob==0 */ + if (ob == NULL) { /* in deformspace, calc matrix */ invert_m4_m4(lt->latmat, oblatt->obmat); @@ -322,9 +322,9 @@ void init_latt_deform(Object *oblatt, Object *ob) invert_m4_m4(imat, lt->latmat); } - for (w=0, fw=lt->fw; w<lt->pntsw; w++, fw+=lt->dw) { - for (v=0, fv=lt->fv; v<lt->pntsv; v++, fv+=lt->dv) { - for (u=0, fu=lt->fu; u<lt->pntsu; u++, bp++, co+=3, fp+=3, fu+=lt->du) { + for (w = 0, fw = lt->fw; w < lt->pntsw; w++, fw += lt->dw) { + for (v = 0, fv = lt->fv; v < lt->pntsv; v++, fv += lt->dv) { + for (u = 0, fu = lt->fu; u < lt->pntsu; u++, bp++, co += 3, fp += 3, fu += lt->du) { if (dl) { fp[0] = co[0] - fu; fp[1] = co[1] - fv; @@ -344,23 +344,23 @@ void init_latt_deform(Object *oblatt, Object *ob) void calc_latt_deform(Object *ob, float co[3], float weight) { - Lattice *lt= ob->data; + Lattice *lt = ob->data; float u, v, w, tu[4], tv[4], tw[4]; float vec[3]; int idx_w, idx_v, idx_u; int ui, vi, wi, uu, vv, ww; /* vgroup influence */ - int defgroup_nr= -1; - float co_prev[3], weight_blend= 0.0f; - MDeformVert *dvert= lattice_get_deform_verts(ob); + int defgroup_nr = -1; + float co_prev[3], weight_blend = 0.0f; + MDeformVert *dvert = BKE_lattice_deform_verts_get(ob); - if (lt->editlatt) lt= lt->editlatt->latt; - if (lt->latticedata==NULL) return; + if (lt->editlatt) lt = lt->editlatt->latt; + if (lt->latticedata == NULL) return; if (lt->vgroup[0] && dvert) { - defgroup_nr= defgroup_name_index(ob, lt->vgroup); + defgroup_nr = defgroup_name_index(ob, lt->vgroup); copy_v3_v3(co_prev, co); } @@ -369,68 +369,68 @@ void calc_latt_deform(Object *ob, float co[3], float weight) /* u v w coords */ - if (lt->pntsu>1) { - u= (vec[0]-lt->fu)/lt->du; - ui= (int)floor(u); + if (lt->pntsu > 1) { + u = (vec[0] - lt->fu) / lt->du; + ui = (int)floor(u); u -= ui; key_curve_position_weights(u, tu, lt->typeu); } else { - tu[0]= tu[2]= tu[3]= 0.0; tu[1]= 1.0; - ui= 0; + tu[0] = tu[2] = tu[3] = 0.0; tu[1] = 1.0; + ui = 0; } - if (lt->pntsv>1) { - v= (vec[1]-lt->fv)/lt->dv; - vi= (int)floor(v); + if (lt->pntsv > 1) { + v = (vec[1] - lt->fv) / lt->dv; + vi = (int)floor(v); v -= vi; key_curve_position_weights(v, tv, lt->typev); } else { - tv[0]= tv[2]= tv[3]= 0.0; tv[1]= 1.0; - vi= 0; + tv[0] = tv[2] = tv[3] = 0.0; tv[1] = 1.0; + vi = 0; } - if (lt->pntsw>1) { - w= (vec[2]-lt->fw)/lt->dw; - wi= (int)floor(w); + if (lt->pntsw > 1) { + w = (vec[2] - lt->fw) / lt->dw; + wi = (int)floor(w); w -= wi; key_curve_position_weights(w, tw, lt->typew); } else { - tw[0]= tw[2]= tw[3]= 0.0; tw[1]= 1.0; - wi= 0; + tw[0] = tw[2] = tw[3] = 0.0; tw[1] = 1.0; + wi = 0; } - for (ww= wi-1; ww<=wi+2; ww++) { - w= tw[ww-wi+1]; + for (ww = wi - 1; ww <= wi + 2; ww++) { + w = tw[ww - wi + 1]; 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; + if (ww > 0) { + if (ww < lt->pntsw) idx_w = ww * lt->pntsu * lt->pntsv; + else idx_w = (lt->pntsw - 1) * lt->pntsu * lt->pntsv; } - else idx_w= 0; + else idx_w = 0; - for (vv= vi-1; vv<=vi+2; vv++) { - v= w*tv[vv-vi+1]; + for (vv = vi - 1; vv <= vi + 2; vv++) { + v = w * tv[vv - vi + 1]; 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; + if (vv > 0) { + if (vv < lt->pntsv) idx_v = idx_w + vv * lt->pntsu; + else idx_v = idx_w + (lt->pntsv - 1) * lt->pntsu; } - else idx_v= idx_w; + else idx_v = idx_w; - for (uu= ui-1; uu<=ui+2; uu++) { - u= weight*v*tu[uu-ui+1]; + for (uu = ui - 1; uu <= ui + 2; uu++) { + u = weight * v * tu[uu - ui + 1]; if (u != 0.0f) { - if (uu>0) { - if (uu<lt->pntsu) idx_u= idx_v + uu; - else idx_u= idx_v + (lt->pntsu-1); + if (uu > 0) { + if (uu < lt->pntsu) idx_u = idx_v + uu; + else idx_u = idx_v + (lt->pntsu - 1); } - else idx_u= idx_v; + else idx_u = idx_v; madd_v3_v3fl(co, <->latticedata[idx_u * 3], u); @@ -450,18 +450,18 @@ void calc_latt_deform(Object *ob, float co[3], float weight) void end_latt_deform(Object *ob) { - Lattice *lt= ob->data; + Lattice *lt = ob->data; - if (lt->editlatt) lt= lt->editlatt->latt; + if (lt->editlatt) lt = lt->editlatt->latt; if (lt->latticedata) MEM_freeN(lt->latticedata); - lt->latticedata= NULL; + lt->latticedata = NULL; } - /* calculations is in local space of deformed object - * so we store in latmat transform from path coord inside object - */ +/* calculations is in local space of deformed object + * so we store in latmat transform from path coord inside object + */ typedef struct { float dmin[3], dmax[3]; float curvespace[4][4], objectspace[4][4], objectspace3[3][3]; @@ -474,7 +474,7 @@ static void init_curve_deform(Object *par, Object *ob, CurveDeform *cd) mult_m4_m4m4(cd->objectspace, ob->imat, par->obmat); invert_m4_m4(cd->curvespace, cd->objectspace); copy_m3_m4(cd->objectspace3, cd->objectspace); - cd->no_rot_axis= 0; + cd->no_rot_axis = 0; } /* this makes sure we can extend for non-cyclic. @@ -483,41 +483,41 @@ static void init_curve_deform(Object *par, Object *ob, CurveDeform *cd) */ static int where_on_path_deform(Object *ob, float ctime, float vec[4], float dir[3], float quat[4], float *radius) { - Curve *cu= ob->data; + Curve *cu = ob->data; BevList *bl; float ctime1; - int cycl=0; + int cycl = 0; /* test for cyclic */ - bl= cu->bev.first; + bl = cu->bev.first; if (!bl->nr) return 0; - if (bl && bl->poly> -1) cycl= 1; + if (bl && bl->poly > -1) cycl = 1; - if (cycl==0) { - ctime1= CLAMPIS(ctime, 0.0f, 1.0f); + if (cycl == 0) { + ctime1 = CLAMPIS(ctime, 0.0f, 1.0f); } - else ctime1= ctime; + else ctime1 = ctime; /* vec needs 4 items */ if (where_on_path(ob, ctime1, vec, dir, quat, radius, NULL)) { - if (cycl==0) { - Path *path= cu->path; + if (cycl == 0) { + Path *path = cu->path; float dvec[3]; if (ctime < 0.0f) { sub_v3_v3v3(dvec, path->data[1].vec, path->data[0].vec); - mul_v3_fl(dvec, ctime*(float)path->len); + 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; + if (radius) *radius = path->data[0].radius; } 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.0f)*(float)path->len); + sub_v3_v3v3(dvec, path->data[path->len - 1].vec, path->data[path->len - 2].vec); + 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; + if (quat) copy_qt_qt(quat, path->data[path->len - 1].quat); + if (radius) *radius = path->data[path->len - 1].radius; /* weight - not used but could be added */ } } @@ -534,43 +534,43 @@ static int where_on_path_deform(Object *ob, float ctime, float vec[4], float dir static int calc_curve_deform(Scene *scene, Object *par, float co[3], const short axis, CurveDeform *cd, float quat_r[4]) { - Curve *cu= par->data; + Curve *cu = par->data; float fac, loc[4], dir[3], new_quat[4], radius; short index; const int is_neg_axis = (axis > 2); /* to be sure, mostly after file load */ - if (cu->path==NULL) { - makeDispListCurveTypes(scene, par, 0); - if (cu->path==NULL) return 0; // happens on append... + if (cu->path == NULL) { + BKE_displist_make_curveTypes(scene, par, 0); + if (cu->path == NULL) return 0; // happens on append... } /* options */ if (is_neg_axis) { index = axis - 3; if (cu->flag & CU_STRETCH) - fac= (-co[index]-cd->dmax[index])/(cd->dmax[index] - cd->dmin[index]); + fac = (-co[index] - cd->dmax[index]) / (cd->dmax[index] - cd->dmin[index]); else - fac= - (co[index]-cd->dmax[index])/(cu->path->totdist); + fac = -(co[index] - cd->dmax[index]) / (cu->path->totdist); } else { index = axis; if (cu->flag & CU_STRETCH) - fac= (co[index]-cd->dmin[index])/(cd->dmax[index] - cd->dmin[index]); + fac = (co[index] - cd->dmin[index]) / (cd->dmax[index] - cd->dmin[index]); else - fac= + (co[index]-cd->dmin[index])/(cu->path->totdist); + fac = +(co[index] - cd->dmin[index]) / (cu->path->totdist); } - if ( where_on_path_deform(par, fac, loc, dir, new_quat, &radius)) { /* returns OK */ + if (where_on_path_deform(par, fac, loc, dir, new_quat, &radius)) { /* returns OK */ float quat[4], cent[3]; - if (cd->no_rot_axis) { /* set by caller */ + if (cd->no_rot_axis) { /* set by caller */ /* this is not exactly the same as 2.4x, since the axis is having rotation removed rather than * changing the axis before calculating the tilt but serves much the same purpose */ - float dir_flat[3]={0, 0, 0}, q[4]; + float dir_flat[3] = {0, 0, 0}, q[4]; copy_v3_v3(dir_flat, dir); - dir_flat[cd->no_rot_axis-1]= 0.0f; + dir_flat[cd->no_rot_axis - 1] = 0.0f; normalize_v3(dir); normalize_v3(dir_flat); @@ -598,9 +598,9 @@ static int calc_curve_deform(Scene *scene, Object *par, float co[3], /* zero the axis which is not used, * the big block of text above now applies to these 3 lines */ - quat_apply_track(quat, axis, (axis == 0 || axis == 2) ? 1:0); /* up flag is a dummy, set so no rotation is done */ + quat_apply_track(quat, axis, (axis == 0 || axis == 2) ? 1 : 0); /* up flag is a dummy, set so no rotation is done */ vec_apply_track(cent, axis); - cent[index]= 0.0f; + cent[index] = 0.0f; /* scale if enabled */ @@ -637,26 +637,26 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target, cu = cuOb->data; flag = cu->flag; - cu->flag |= (CU_PATH|CU_FOLLOW); // needed for path & bevlist + cu->flag |= (CU_PATH | CU_FOLLOW); // needed for path & bevlist init_curve_deform(cuOb, target, &cd); /* dummy bounds, keep if CU_DEFORM_BOUNDS_OFF is set */ if (is_neg_axis == FALSE) { - cd.dmin[0]= cd.dmin[1]= cd.dmin[2]= 0.0f; - cd.dmax[0]= cd.dmax[1]= cd.dmax[2]= 1.0f; + cd.dmin[0] = cd.dmin[1] = cd.dmin[2] = 0.0f; + cd.dmax[0] = cd.dmax[1] = cd.dmax[2] = 1.0f; } else { /* negative, these bounds give a good rest position */ - cd.dmin[0]= cd.dmin[1]= cd.dmin[2]= -1.0f; - cd.dmax[0]= cd.dmax[1]= cd.dmax[2]= 0.0f; + cd.dmin[0] = cd.dmin[1] = cd.dmin[2] = -1.0f; + cd.dmax[0] = cd.dmax[1] = cd.dmax[2] = 0.0f; } /* check whether to use vertex groups (only possible if target is a Mesh) * we want either a Mesh with no derived data, or derived data with * deformverts */ - if (target && target->type==OB_MESH) { + if (target && target->type == OB_MESH) { /* if there's derived data without deformverts, don't use vgroups */ if (dm && !dm->getVertData(dm, 0, CD_MDEFORMVERT)) use_vgroups = 0; @@ -668,8 +668,8 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target, } if (vgroup && vgroup[0] && use_vgroups) { - Mesh *me= target->data; - int index= defgroup_name_index(target, vgroup); + Mesh *me = target->data; + int index = defgroup_name_index(target, vgroup); if (index != -1 && (me->dvert || dm)) { MDeformVert *dvert = me->dvert; @@ -681,7 +681,7 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target, dvert = me->dvert; for (a = 0; a < numVerts; a++, dvert++) { if (dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT); - weight= defvert_find_weight(dvert, index); + weight = defvert_find_weight(dvert, index); if (weight > 0.0f) { mul_m4_v3(cd.curvespace, vertexCos[a]); @@ -709,7 +709,7 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target, for (a = 0; a < numVerts; a++, dvert++) { if (dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT); - weight= defvert_find_weight(dvert, index); + weight = defvert_find_weight(dvert, index); if (weight > 0.0f) { /* already in 'cd.curvespace', prev for loop */ @@ -764,7 +764,7 @@ void curve_deform_vector(Scene *scene, Object *cuOb, Object *target, } init_curve_deform(cuOb, target, &cd); - cd.no_rot_axis= no_rot_axis; /* option to only rotate for XY, for example */ + cd.no_rot_axis = no_rot_axis; /* option to only rotate for XY, for example */ copy_v3_v3(cd.dmin, orco); copy_v3_v3(cd.dmax, orco); @@ -799,7 +799,7 @@ void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm, * we want either a Mesh with no derived data, or derived data with * deformverts */ - if (target && target->type==OB_MESH) { + if (target && target->type == OB_MESH) { /* if there's derived data without deformverts, don't use vgroups */ if (dm && !dm->getVertData(dm, 0, CD_MDEFORMVERT)) use_vgroups = 0; @@ -821,7 +821,7 @@ void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm, for (a = 0; a < numVerts; a++, dvert++) { if (dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT); - weight= defvert_find_weight(dvert, index); + weight = defvert_find_weight(dvert, index); if (weight > 0.0f) calc_latt_deform(laOb, vertexCos[a], weight * fac); @@ -838,12 +838,12 @@ void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm, int object_deform_mball(Object *ob, ListBase *dispbase) { - if (ob->parent && ob->parent->type==OB_LATTICE && ob->partype==PARSKEL) { + if (ob->parent && ob->parent->type == OB_LATTICE && ob->partype == PARSKEL) { DispList *dl; - for (dl=dispbase->first; dl; dl=dl->next) { + for (dl = dispbase->first; dl; dl = dl->next) { lattice_deform_verts(ob->parent, ob, NULL, - (float(*)[3]) dl->verts, dl->nr, NULL, 1.0f); + (float(*)[3])dl->verts, dl->nr, NULL, 1.0f); } return 1; @@ -862,52 +862,52 @@ void outside_lattice(Lattice *lt) { BPoint *bp, *bp1, *bp2; int u, v, w; - float fac1, du=0.0, dv=0.0, dw=0.0; + float fac1, du = 0.0, dv = 0.0, dw = 0.0; if (lt->flag & LT_OUTSIDE) { - bp= lt->def; + bp = lt->def; - if (lt->pntsu>1) du= 1.0f/((float)lt->pntsu-1); - if (lt->pntsv>1) dv= 1.0f/((float)lt->pntsv-1); - if (lt->pntsw>1) dw= 1.0f/((float)lt->pntsw-1); + if (lt->pntsu > 1) du = 1.0f / ((float)lt->pntsu - 1); + if (lt->pntsv > 1) dv = 1.0f / ((float)lt->pntsv - 1); + if (lt->pntsw > 1) dw = 1.0f / ((float)lt->pntsw - 1); - for (w=0; w<lt->pntsw; w++) { + for (w = 0; w < lt->pntsw; w++) { - for (v=0; v<lt->pntsv; v++) { + for (v = 0; v < lt->pntsv; v++) { - for (u=0; u<lt->pntsu; u++, bp++) { - if (u==0 || v==0 || w==0 || u==lt->pntsu-1 || v==lt->pntsv-1 || w==lt->pntsw-1); + for (u = 0; u < lt->pntsu; u++, bp++) { + if (u == 0 || v == 0 || w == 0 || u == lt->pntsu - 1 || v == lt->pntsv - 1 || w == lt->pntsw - 1) ; else { - bp->hide= 1; + bp->hide = 1; bp->f1 &= ~SELECT; /* u extrema */ - bp1= latt_bp(lt, 0, v, w); - bp2= latt_bp(lt, lt->pntsu-1, v, w); + bp1 = latt_bp(lt, 0, v, w); + bp2 = latt_bp(lt, lt->pntsu - 1, v, w); - fac1= du*u; - bp->vec[0]= (1.0f-fac1)*bp1->vec[0] + fac1*bp2->vec[0]; - bp->vec[1]= (1.0f-fac1)*bp1->vec[1] + fac1*bp2->vec[1]; - bp->vec[2]= (1.0f-fac1)*bp1->vec[2] + fac1*bp2->vec[2]; + fac1 = du * u; + bp->vec[0] = (1.0f - fac1) * bp1->vec[0] + fac1 * bp2->vec[0]; + bp->vec[1] = (1.0f - fac1) * bp1->vec[1] + fac1 * bp2->vec[1]; + bp->vec[2] = (1.0f - fac1) * bp1->vec[2] + fac1 * bp2->vec[2]; /* v extrema */ - bp1= latt_bp(lt, u, 0, w); - bp2= latt_bp(lt, u, lt->pntsv-1, w); + bp1 = latt_bp(lt, u, 0, w); + bp2 = latt_bp(lt, u, lt->pntsv - 1, w); - fac1= dv*v; - bp->vec[0]+= (1.0f-fac1)*bp1->vec[0] + fac1*bp2->vec[0]; - bp->vec[1]+= (1.0f-fac1)*bp1->vec[1] + fac1*bp2->vec[1]; - bp->vec[2]+= (1.0f-fac1)*bp1->vec[2] + fac1*bp2->vec[2]; + fac1 = dv * v; + bp->vec[0] += (1.0f - fac1) * bp1->vec[0] + fac1 * bp2->vec[0]; + bp->vec[1] += (1.0f - fac1) * bp1->vec[1] + fac1 * bp2->vec[1]; + bp->vec[2] += (1.0f - fac1) * bp1->vec[2] + fac1 * bp2->vec[2]; /* w extrema */ - bp1= latt_bp(lt, u, v, 0); - bp2= latt_bp(lt, u, v, lt->pntsw-1); + bp1 = latt_bp(lt, u, v, 0); + bp2 = latt_bp(lt, u, v, lt->pntsw - 1); - fac1= dw*w; - bp->vec[0]+= (1.0f-fac1)*bp1->vec[0] + fac1*bp2->vec[0]; - bp->vec[1]+= (1.0f-fac1)*bp1->vec[1] + fac1*bp2->vec[1]; - bp->vec[2]+= (1.0f-fac1)*bp1->vec[2] + fac1*bp2->vec[2]; + fac1 = dw * w; + bp->vec[0] += (1.0f - fac1) * bp1->vec[0] + fac1 * bp2->vec[0]; + bp->vec[1] += (1.0f - fac1) * bp1->vec[1] + fac1 * bp2->vec[1]; + bp->vec[2] += (1.0f - fac1) * bp1->vec[2] + fac1 * bp2->vec[2]; mul_v3_fl(bp->vec, 0.3333333f); @@ -919,84 +919,84 @@ void outside_lattice(Lattice *lt) } } else { - bp= lt->def; + bp = lt->def; - for (w=0; w<lt->pntsw; w++) - for (v=0; v<lt->pntsv; v++) - for (u=0; u<lt->pntsu; u++, bp++) - bp->hide= 0; + for (w = 0; w < lt->pntsw; w++) + for (v = 0; v < lt->pntsv; v++) + for (u = 0; u < lt->pntsu; u++, bp++) + bp->hide = 0; } } -float (*lattice_getVertexCos(struct Object *ob, int *numVerts_r))[3] +float (*BKE_lattice_vertexcos_get(struct Object *ob, int *numVerts_r))[3] { Lattice *lt = ob->data; int i, numVerts; float (*vertexCos)[3]; - if (lt->editlatt) lt= lt->editlatt->latt; - numVerts = *numVerts_r = lt->pntsu*lt->pntsv*lt->pntsw; + if (lt->editlatt) lt = lt->editlatt->latt; + numVerts = *numVerts_r = lt->pntsu * lt->pntsv * lt->pntsw; - vertexCos = MEM_mallocN(sizeof(*vertexCos)*numVerts, "lt_vcos"); + vertexCos = MEM_mallocN(sizeof(*vertexCos) * numVerts, "lt_vcos"); - for (i=0; i<numVerts; i++) { + for (i = 0; i < numVerts; i++) { copy_v3_v3(vertexCos[i], lt->def[i].vec); } return vertexCos; } -void lattice_applyVertexCos(struct Object *ob, float (*vertexCos)[3]) +void BKE_lattice_vertexcos_apply(struct Object *ob, float (*vertexCos)[3]) { Lattice *lt = ob->data; - int i, numVerts = lt->pntsu*lt->pntsv*lt->pntsw; + int i, numVerts = lt->pntsu * lt->pntsv * lt->pntsw; - for (i=0; i<numVerts; i++) { + for (i = 0; i < numVerts; i++) { copy_v3_v3(lt->def[i].vec, vertexCos[i]); } } -void lattice_calc_modifiers(Scene *scene, Object *ob) +void BKE_lattice_modifiers_calc(Scene *scene, Object *ob) { - Lattice *lt= ob->data; + Lattice *lt = ob->data; ModifierData *md = modifiers_getVirtualModifierList(ob); float (*vertexCos)[3] = NULL; - int numVerts, editmode = (lt->editlatt!=NULL); + int numVerts, editmode = (lt->editlatt != NULL); - freedisplist(&ob->disp); + BKE_displist_free(&ob->disp); - for (; md; md=md->next) { + for (; md; md = md->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); - md->scene= scene; + md->scene = scene; - if (!(md->mode&eModifierMode_Realtime)) continue; - if (editmode && !(md->mode&eModifierMode_Editmode)) continue; + if (!(md->mode & eModifierMode_Realtime)) continue; + if (editmode && !(md->mode & eModifierMode_Editmode)) continue; if (mti->isDisabled && mti->isDisabled(md, 0)) continue; - if (mti->type!=eModifierTypeType_OnlyDeform) continue; + if (mti->type != eModifierTypeType_OnlyDeform) continue; - if (!vertexCos) vertexCos = lattice_getVertexCos(ob, &numVerts); - mti->deformVerts(md, ob, NULL, vertexCos, numVerts, 0, 0); + if (!vertexCos) vertexCos = BKE_lattice_vertexcos_get(ob, &numVerts); + mti->deformVerts(md, ob, NULL, vertexCos, numVerts, 0); } /* always displist to make this work like derivedmesh */ - if (!vertexCos) vertexCos = lattice_getVertexCos(ob, &numVerts); + if (!vertexCos) vertexCos = BKE_lattice_vertexcos_get(ob, &numVerts); { DispList *dl = MEM_callocN(sizeof(*dl), "lt_dl"); dl->type = DL_VERTS; dl->parts = 1; dl->nr = numVerts; - dl->verts = (float*) vertexCos; + dl->verts = (float *) vertexCos; BLI_addtail(&ob->disp, dl); } } -struct MDeformVert* lattice_get_deform_verts(struct Object *oblatt) +struct MDeformVert *BKE_lattice_deform_verts_get(struct Object *oblatt) { - Lattice *lt = (Lattice*)oblatt->data; + Lattice *lt = (Lattice *)oblatt->data; BLI_assert(oblatt->type == OB_LATTICE); - if (lt->editlatt) lt= lt->editlatt->latt; + 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 52c92034367..6a43c48c32b 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -116,14 +116,14 @@ #include "BPY_extern.h" #endif -#define MAX_IDPUP 60 /* was 24 */ +#define MAX_IDPUP 60 /* was 24 */ /* GS reads the memory pointed at in a specific ordering. * only use this definition, makes little and big endian systems * work fine, in conjunction with MAKE_ID */ /* from blendef: */ -#define GS(a) (*((short *)(a))) +#define GS(a) (*((short *)(a))) /* ************* general ************************ */ @@ -134,12 +134,12 @@ * also note that the id _must_ have a library - campbell */ void BKE_id_lib_local_paths(Main *bmain, Library *lib, ID *id) { - char *bpath_user_data[2]= {bmain->name, lib->filepath}; + char *bpath_user_data[2] = {bmain->name, lib->filepath}; BLI_bpath_traverse_id(bmain, id, - BLI_bpath_relocate_visitor, - BLI_BPATH_TRAVERSE_SKIP_MULTIFILE, - bpath_user_data); + BLI_bpath_relocate_visitor, + BLI_BPATH_TRAVERSE_SKIP_MULTIFILE, + bpath_user_data); } void id_lib_extern(ID *id) @@ -167,7 +167,7 @@ void id_us_min(ID *id) { if (id) { if (id->us < 2 && (id->flag & LIB_FAKEUSER)) { - id->us= 1; + id->us = 1; } else if (id->us <= 0) { printf("ID user decrement error: %s\n", id->name); @@ -189,54 +189,54 @@ int id_make_local(ID *id, int test) case ID_LI: return 0; /* can't be linked */ case ID_OB: - if (!test) make_local_object((Object*)id); + if (!test) BKE_object_make_local((Object *)id); return 1; case ID_ME: if (!test) { - make_local_mesh((Mesh*)id); - make_local_key(((Mesh*)id)->key); + BKE_mesh_make_local((Mesh *)id); + BKE_key_make_local(((Mesh *)id)->key); } return 1; case ID_CU: if (!test) { - BKE_curve_make_local((Curve*)id); - make_local_key(((Curve*)id)->key); + BKE_curve_make_local((Curve *)id); + BKE_key_make_local(((Curve *)id)->key); } return 1; case ID_MB: - if (!test) BKE_metaball_make_local((MetaBall*)id); + if (!test) BKE_mball_make_local((MetaBall *)id); return 1; case ID_MA: - if (!test) make_local_material((Material*)id); + if (!test) BKE_material_make_local((Material *)id); return 1; case ID_TE: - if (!test) make_local_texture((Tex*)id); + if (!test) BKE_texture_make_local((Tex *)id); return 1; case ID_IM: - if (!test) make_local_image((Image*)id); + if (!test) BKE_image_make_local((Image *)id); return 1; case ID_LT: if (!test) { - make_local_lattice((Lattice*)id); - make_local_key(((Lattice*)id)->key); + BKE_lattice_make_local((Lattice *)id); + BKE_key_make_local(((Lattice *)id)->key); } return 1; case ID_LA: - if (!test) make_local_lamp((Lamp*)id); + if (!test) BKE_lamp_make_local((Lamp *)id); return 1; case ID_CA: - if (!test) BKE_camera_make_local((Camera*)id); + if (!test) BKE_camera_make_local((Camera *)id); return 1; case ID_SPK: - if (!test) make_local_speaker((Speaker*)id); + if (!test) BKE_speaker_make_local((Speaker *)id); return 1; case ID_IP: return 0; /* deprecated */ case ID_KE: - if (!test) make_local_key((Key*)id); + if (!test) BKE_key_make_local((Key *)id); return 1; case ID_WO: - if (!test) make_local_world((World*)id); + if (!test) BKE_world_make_local((World *)id); return 1; case ID_SCR: return 0; /* can't be linked */ @@ -251,18 +251,18 @@ int id_make_local(ID *id, int test) case ID_GR: return 0; /* not implemented */ case ID_AR: - if (!test) make_local_armature((bArmature*)id); + if (!test) BKE_armature_make_local((bArmature *)id); return 1; case ID_AC: - if (!test) make_local_action((bAction*)id); + if (!test) BKE_action_make_local((bAction *)id); return 1; case ID_NT: return 0; /* not implemented */ case ID_BR: - if (!test) BKE_brush_make_local((Brush*)id); + if (!test) BKE_brush_make_local((Brush *)id); return 1; case ID_PA: - if (!test) make_local_particlesettings((ParticleSettings*)id); + if (!test) BKE_particlesettings_make_local((ParticleSettings *)id); return 1; case ID_WM: return 0; /* can't be linked */ @@ -277,7 +277,7 @@ int id_make_local(ID *id, int test) int id_copy(ID *id, ID **newid, int test) { - if (!test) *newid= NULL; + if (!test) *newid = NULL; /* conventions: * - make shallow copy, only this ID block @@ -288,74 +288,74 @@ int id_copy(ID *id, ID **newid, int test) case ID_LI: return 0; /* can't be copied from here */ case ID_OB: - if (!test) *newid= (ID*)copy_object((Object*)id); + if (!test) *newid = (ID *)BKE_object_copy((Object *)id); return 1; case ID_ME: - if (!test) *newid= (ID*)copy_mesh((Mesh*)id); + if (!test) *newid = (ID *)BKE_mesh_copy((Mesh *)id); return 1; case ID_CU: - if (!test) *newid= (ID*)BKE_curve_copy((Curve*)id); + if (!test) *newid = (ID *)BKE_curve_copy((Curve *)id); return 1; case ID_MB: - if (!test) *newid= (ID*)BKE_metaball_copy((MetaBall*)id); + if (!test) *newid = (ID *)BKE_mball_copy((MetaBall *)id); return 1; case ID_MA: - if (!test) *newid= (ID*)copy_material((Material*)id); + if (!test) *newid = (ID *)BKE_material_copy((Material *)id); return 1; case ID_TE: - if (!test) *newid= (ID*)copy_texture((Tex*)id); + if (!test) *newid = (ID *)BKE_texture_copy((Tex *)id); return 1; case ID_IM: - if (!test) *newid= (ID*)copy_image((Image*)id); + if (!test) *newid = (ID *)BKE_image_copy((Image *)id); return 1; case ID_LT: - if (!test) *newid= (ID*)copy_lattice((Lattice*)id); + if (!test) *newid = (ID *)BKE_lattice_copy((Lattice *)id); return 1; case ID_LA: - if (!test) *newid= (ID*)copy_lamp((Lamp*)id); + if (!test) *newid = (ID *)BKE_lamp_copy((Lamp *)id); return 1; case ID_SPK: - if (!test) *newid= (ID*)copy_speaker((Speaker*)id); + if (!test) *newid = (ID *)BKE_speaker_copy((Speaker *)id); return 1; case ID_CA: - if (!test) *newid= (ID*)BKE_camera_copy((Camera*)id); + if (!test) *newid = (ID *)BKE_camera_copy((Camera *)id); return 1; case ID_IP: return 0; /* deprecated */ case ID_KE: - if (!test) *newid= (ID*)copy_key((Key*)id); + if (!test) *newid = (ID *)BKE_key_copy((Key *)id); return 1; case ID_WO: - if (!test) *newid= (ID*)copy_world((World*)id); + if (!test) *newid = (ID *)BKE_world_copy((World *)id); return 1; case ID_SCR: return 0; /* can't be copied from here */ case ID_VF: return 0; /* not implemented */ case ID_TXT: - if (!test) *newid= (ID*)copy_text((Text*)id); + if (!test) *newid = (ID *)BKE_text_copy((Text *)id); return 1; case ID_SCRIPT: return 0; /* deprecated */ case ID_SO: return 0; /* not implemented */ case ID_GR: - if (!test) *newid= (ID*)copy_group((Group*)id); + if (!test) *newid = (ID *)BKE_group_copy((Group *)id); return 1; case ID_AR: - if (!test) *newid= (ID*)copy_armature((bArmature*)id); + if (!test) *newid = (ID *)BKE_armature_copy((bArmature *)id); return 1; case ID_AC: - if (!test) *newid= (ID*)copy_action((bAction*)id); + if (!test) *newid = (ID *)BKE_action_copy((bAction *)id); return 1; case ID_NT: - if (!test) *newid= (ID*)ntreeCopyTree((bNodeTree*)id); + if (!test) *newid = (ID *)ntreeCopyTree((bNodeTree *)id); return 1; case ID_BR: - if (!test) *newid= (ID*)BKE_brush_copy((Brush*)id); + if (!test) *newid = (ID *)BKE_brush_copy((Brush *)id); return 1; case ID_PA: - if (!test) *newid= (ID*)psys_copy_settings((ParticleSettings*)id); + if (!test) *newid = (ID *)BKE_particlesettings_copy((ParticleSettings *)id); return 1; case ID_WM: return 0; /* can't be copied from here */ @@ -371,29 +371,29 @@ int id_copy(ID *id, ID **newid, int test) int id_unlink(ID *id, int test) { - Main *mainlib= G.main; + Main *mainlib = G.main; ListBase *lb; switch (GS(id->name)) { case ID_TXT: if (test) return 1; - unlink_text(mainlib, (Text*)id); + BKE_text_unlink(mainlib, (Text *)id); break; case ID_GR: if (test) return 1; - unlink_group((Group*)id); + BKE_group_unlink((Group *)id); break; case ID_OB: if (test) return 1; - unlink_object((Object*)id); + BKE_object_unlink((Object *)id); break; } if (id->us == 0) { if (test) return 1; - lb= which_libbase(mainlib, GS(id->name)); - free_libblock(lb, id); + lb = which_libbase(mainlib, GS(id->name)); + BKE_libblock_free(lb, id); return 1; } @@ -431,7 +431,7 @@ int id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop) ListBase *which_libbase(Main *mainlib, short type) { - switch ( type ) { + switch (type) { case ID_SCE: return &(mainlib->scene); case ID_LI: @@ -503,11 +503,11 @@ void flag_listbase_ids(ListBase *lb, short flag, short value) { ID *id; if (value) { - for (id= lb->first; id; id= id->next) id->flag |= flag; + for (id = lb->first; id; id = id->next) id->flag |= flag; } else { flag = ~flag; - for (id= lb->first; id; id= id->next) id->flag &= flag; + for (id = lb->first; id; id = id->next) id->flag &= flag; } } @@ -516,8 +516,8 @@ void flag_all_listbases_ids(short flag, short value) { ListBase *lbarray[MAX_LIBARRAY]; int a; - a= set_listbasepointers(G.main, lbarray); - while (a--) flag_listbase_ids(lbarray[a], flag, value); + a = set_listbasepointers(G.main, lbarray); + while (a--) flag_listbase_ids(lbarray[a], flag, value); } void recalc_all_library_objects(Main *main) @@ -525,9 +525,9 @@ void recalc_all_library_objects(Main *main) Object *ob; /* flag for full recalc */ - for (ob=main->object.first; ob; ob=ob->id.next) + for (ob = main->object.first; ob; ob = ob->id.next) if (ob->id.lib) - ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; + ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; } /* note: MAX_LIBARRAY define should match this code */ @@ -538,132 +538,132 @@ int set_listbasepointers(Main *main, ListBase **lb) /* BACKWARDS! also watch order of free-ing! (mesh<->mat), first items freed last. * This is important because freeing data decreases usercounts of other datablocks, * if this data is its self freed it can crash. */ - lb[a++]= &(main->ipo); - lb[a++]= &(main->action); // xxx moved here to avoid problems when freeing with animato (aligorith) - lb[a++]= &(main->key); - lb[a++]= &(main->gpencil); /* referenced by nodes, objects, view, scene etc, before to free after. */ - lb[a++]= &(main->nodetree); - lb[a++]= &(main->image); - lb[a++]= &(main->tex); - lb[a++]= &(main->mat); - lb[a++]= &(main->vfont); + lb[a++] = &(main->ipo); + lb[a++] = &(main->action); // xxx moved here to avoid problems when freeing with animato (aligorith) + lb[a++] = &(main->key); + lb[a++] = &(main->gpencil); /* referenced by nodes, objects, view, scene etc, before to free after. */ + lb[a++] = &(main->nodetree); + lb[a++] = &(main->image); + lb[a++] = &(main->tex); + lb[a++] = &(main->mat); + lb[a++] = &(main->vfont); /* Important!: When adding a new object type, * the specific data should be inserted here */ - lb[a++]= &(main->armature); - - lb[a++]= &(main->mesh); - lb[a++]= &(main->curve); - lb[a++]= &(main->mball); - - lb[a++]= &(main->latt); - lb[a++]= &(main->lamp); - lb[a++]= &(main->camera); - - lb[a++]= &(main->text); - lb[a++]= &(main->sound); - lb[a++]= &(main->group); - lb[a++]= &(main->brush); - lb[a++]= &(main->script); - lb[a++]= &(main->particle); - lb[a++]= &(main->speaker); - - lb[a++]= &(main->world); - lb[a++]= &(main->screen); - lb[a++]= &(main->object); - lb[a++]= &(main->scene); - lb[a++]= &(main->library); - lb[a++]= &(main->wm); - lb[a++]= &(main->movieclip); + lb[a++] = &(main->armature); + + lb[a++] = &(main->mesh); + lb[a++] = &(main->curve); + lb[a++] = &(main->mball); + + lb[a++] = &(main->latt); + lb[a++] = &(main->lamp); + lb[a++] = &(main->camera); + + lb[a++] = &(main->text); + lb[a++] = &(main->sound); + lb[a++] = &(main->group); + lb[a++] = &(main->brush); + lb[a++] = &(main->script); + lb[a++] = &(main->particle); + lb[a++] = &(main->speaker); + + lb[a++] = &(main->world); + lb[a++] = &(main->screen); + lb[a++] = &(main->object); + lb[a++] = &(main->scene); + lb[a++] = &(main->library); + lb[a++] = &(main->wm); + lb[a++] = &(main->movieclip); lb[a++]= &(main->linestyle); - lb[a]= NULL; + lb[a] = NULL; return a; } /* *********** ALLOC AND FREE ***************** * - * free_libblock(ListBase *lb, ID *id ) + * BKE_libblock_free(ListBase *lb, ID *id ) * provide a list-basis and datablock, but only ID is read * - * void *alloc_libblock(ListBase *lb, type, name) + * void *BKE_libblock_alloc(ListBase *lb, type, name) * inserts in list and returns a new ID * * **************************** */ static ID *alloc_libblock_notest(short type) { - ID *id= NULL; + ID *id = NULL; - switch ( type ) { + switch (type) { case ID_SCE: - id= MEM_callocN(sizeof(Scene), "scene"); + id = MEM_callocN(sizeof(Scene), "scene"); break; case ID_LI: - id= MEM_callocN(sizeof(Library), "library"); + id = MEM_callocN(sizeof(Library), "library"); break; case ID_OB: - id= MEM_callocN(sizeof(Object), "object"); + id = MEM_callocN(sizeof(Object), "object"); break; case ID_ME: - id= MEM_callocN(sizeof(Mesh), "mesh"); + id = MEM_callocN(sizeof(Mesh), "mesh"); break; case ID_CU: - id= MEM_callocN(sizeof(Curve), "curve"); + id = MEM_callocN(sizeof(Curve), "curve"); break; case ID_MB: - id= MEM_callocN(sizeof(MetaBall), "mball"); + id = MEM_callocN(sizeof(MetaBall), "mball"); break; case ID_MA: - id= MEM_callocN(sizeof(Material), "mat"); + id = MEM_callocN(sizeof(Material), "mat"); break; case ID_TE: - id= MEM_callocN(sizeof(Tex), "tex"); + id = MEM_callocN(sizeof(Tex), "tex"); break; case ID_IM: - id= MEM_callocN(sizeof(Image), "image"); + id = MEM_callocN(sizeof(Image), "image"); break; case ID_LT: - id= MEM_callocN(sizeof(Lattice), "latt"); + id = MEM_callocN(sizeof(Lattice), "latt"); break; case ID_LA: - id= MEM_callocN(sizeof(Lamp), "lamp"); + id = MEM_callocN(sizeof(Lamp), "lamp"); break; case ID_CA: - id= MEM_callocN(sizeof(Camera), "camera"); + id = MEM_callocN(sizeof(Camera), "camera"); break; case ID_IP: - id= MEM_callocN(sizeof(Ipo), "ipo"); + id = MEM_callocN(sizeof(Ipo), "ipo"); break; case ID_KE: - id= MEM_callocN(sizeof(Key), "key"); + id = MEM_callocN(sizeof(Key), "key"); break; case ID_WO: - id= MEM_callocN(sizeof(World), "world"); + id = MEM_callocN(sizeof(World), "world"); break; case ID_SCR: - id= MEM_callocN(sizeof(bScreen), "screen"); + id = MEM_callocN(sizeof(bScreen), "screen"); break; case ID_VF: - id= MEM_callocN(sizeof(VFont), "vfont"); + id = MEM_callocN(sizeof(VFont), "vfont"); break; case ID_TXT: - id= MEM_callocN(sizeof(Text), "text"); + id = MEM_callocN(sizeof(Text), "text"); break; case ID_SCRIPT: //XXX id= MEM_callocN(sizeof(Script), "script"); break; case ID_SPK: - id= MEM_callocN(sizeof(Speaker), "speaker"); + id = MEM_callocN(sizeof(Speaker), "speaker"); break; case ID_SO: - id= MEM_callocN(sizeof(bSound), "sound"); + id = MEM_callocN(sizeof(bSound), "sound"); break; case ID_GR: - id= MEM_callocN(sizeof(Group), "group"); + id = MEM_callocN(sizeof(Group), "group"); break; case ID_AR: id = MEM_callocN(sizeof(bArmature), "armature"); @@ -697,16 +697,16 @@ static ID *alloc_libblock_notest(short type) } /* used everywhere in blenkernel and text.c */ -void *alloc_libblock(ListBase *lb, short type, const char *name) +void *BKE_libblock_alloc(ListBase *lb, short type, const char *name) { - ID *id= NULL; + ID *id = NULL; - id= alloc_libblock_notest(type); + id = alloc_libblock_notest(type); if (id) { BLI_addtail(lb, id); - id->us= 1; + id->us = 1; id->icon_id = 0; - *( (short *)id->name )= type; + *( (short *)id->name) = type; new_id(lb, id, name); /* alphabetic insterion: is in new_id */ } @@ -717,16 +717,16 @@ void *alloc_libblock(ListBase *lb, short type, const char *name) /* and, trust that BKE_animdata_from_id() will only find AnimData for valid ID-types */ static void id_copy_animdata(ID *id, const short do_action) { - AnimData *adt= BKE_animdata_from_id(id); + AnimData *adt = BKE_animdata_from_id(id); if (adt) { IdAdtTemplate *iat = (IdAdtTemplate *)id; - iat->adt= BKE_copy_animdata(iat->adt, do_action); /* could be set to FALSE, need to investigate */ + iat->adt = BKE_copy_animdata(iat->adt, do_action); /* could be set to FALSE, need to investigate */ } } /* material nodes use this since they are not treated as libdata */ -void copy_libblock_data(ID *id, const ID *id_from, const short do_action) +void BKE_libblock_copy_data(ID *id, const ID *id_from, const short do_action) { if (id_from->properties) id->properties = IDP_CopyProperty(id_from->properties); @@ -736,43 +736,43 @@ void copy_libblock_data(ID *id, const ID *id_from, const short do_action) } /* used everywhere in blenkernel */ -void *copy_libblock(ID *id) +void *BKE_libblock_copy(ID *id) { ID *idn; ListBase *lb; size_t idn_len; - lb= which_libbase(G.main, GS(id->name)); - idn= alloc_libblock(lb, GS(id->name), id->name+2); + lb = which_libbase(G.main, GS(id->name)); + idn = BKE_libblock_alloc(lb, GS(id->name), id->name + 2); assert(idn != NULL); - idn_len= MEM_allocN_len(idn); + idn_len = MEM_allocN_len(idn); if ((int)idn_len - (int)sizeof(ID) > 0) { /* signed to allow neg result */ - const char *cp= (const char *)id; - char *cpn= (char *)idn; + const char *cp = (const char *)id; + char *cpn = (char *)idn; - memcpy(cpn+sizeof(ID), cp+sizeof(ID), idn_len - sizeof(ID)); + memcpy(cpn + sizeof(ID), cp + sizeof(ID), idn_len - sizeof(ID)); } - id->newid= idn; + id->newid = idn; idn->flag |= LIB_NEW; - copy_libblock_data(idn, id, FALSE); + BKE_libblock_copy_data(idn, id, FALSE); return idn; } -static void free_library(Library *UNUSED(lib)) +static void BKE_library_free(Library *UNUSED(lib)) { /* no freeing needed for libraries yet */ } -static void (*free_windowmanager_cb)(bContext *, wmWindowManager *)= NULL; +static void (*free_windowmanager_cb)(bContext *, wmWindowManager *) = NULL; void set_free_windowmanager_cb(void (*func)(bContext *C, wmWindowManager *) ) { - free_windowmanager_cb= func; + free_windowmanager_cb = func; } static void animdata_dtar_clear_cb(ID *UNUSED(id), AnimData *adt, void *userdata) @@ -781,16 +781,16 @@ static void animdata_dtar_clear_cb(ID *UNUSED(id), AnimData *adt, void *userdata FCurve *fcu; /* find the driver this belongs to and update it */ - for (fcu=adt->drivers.first; fcu; fcu=fcu->next) { - driver= fcu->driver; + for (fcu = adt->drivers.first; fcu; fcu = fcu->next) { + driver = fcu->driver; if (driver) { DriverVar *dvar; - for (dvar= driver->variables.first; dvar; dvar= dvar->next) { + for (dvar = driver->variables.first; dvar; dvar = dvar->next) { DRIVER_TARGETS_USED_LOOPER(dvar) { if (dtar->id == userdata) - dtar->id= NULL; + dtar->id = NULL; } DRIVER_TARGETS_LOOPER_END } @@ -800,86 +800,86 @@ static void animdata_dtar_clear_cb(ID *UNUSED(id), AnimData *adt, void *userdata /* used in headerbuttons.c image.c mesh.c screen.c sound.c and library.c */ -void free_libblock(ListBase *lb, void *idv) +void BKE_libblock_free(ListBase *lb, void *idv) { - ID *id= idv; + ID *id = idv; #ifdef WITH_PYTHON BPY_id_release(id); #endif - switch ( GS(id->name) ) { /* GetShort from util.h */ + switch (GS(id->name) ) { /* GetShort from util.h */ case ID_SCE: - free_scene((Scene *)id); + BKE_scene_free((Scene *)id); break; case ID_LI: - free_library((Library *)id); + BKE_library_free((Library *)id); break; case ID_OB: - free_object((Object *)id); + BKE_object_free((Object *)id); break; case ID_ME: - free_mesh((Mesh *)id, 1); + BKE_mesh_free((Mesh *)id, 1); break; case ID_CU: BKE_curve_free((Curve *)id); break; case ID_MB: - BKE_metaball_free((MetaBall *)id); + BKE_mball_free((MetaBall *)id); break; case ID_MA: - free_material((Material *)id); + BKE_material_free((Material *)id); break; case ID_TE: - free_texture((Tex *)id); + BKE_texture_free((Tex *)id); break; case ID_IM: - free_image((Image *)id); + BKE_image_free((Image *)id); break; case ID_LT: - free_lattice((Lattice *)id); + BKE_lattice_free((Lattice *)id); break; case ID_LA: - free_lamp((Lamp *)id); + BKE_lamp_free((Lamp *)id); break; case ID_CA: - BKE_camera_free((Camera*) id); + BKE_camera_free((Camera *) id); break; case ID_IP: - free_ipo((Ipo *)id); + BKE_ipo_free((Ipo *)id); break; case ID_KE: - free_key((Key *)id); + BKE_key_free((Key *)id); break; case ID_WO: - free_world((World *)id); + BKE_world_free((World *)id); break; case ID_SCR: - free_screen((bScreen *)id); + BKE_screen_free((bScreen *)id); break; case ID_VF: - free_vfont((VFont *)id); + BKE_vfont_free((VFont *)id); break; case ID_TXT: - free_text((Text *)id); + BKE_text_free((Text *)id); break; case ID_SCRIPT: //XXX free_script((Script *)id); break; case ID_SPK: - free_speaker((Speaker *)id); + BKE_speaker_free((Speaker *)id); break; case ID_SO: - sound_free((bSound*)id); + BKE_sound_free((bSound *)id); break; case ID_GR: - free_group_objects((Group *)id); + BKE_group_free((Group *)id); break; case ID_AR: - free_armature((bArmature *)id); + BKE_armature_free((bArmature *)id); break; case ID_AC: - free_action((bAction *)id); + BKE_action_free((bAction *)id); break; case ID_NT: ntreeFreeTree((bNodeTree *)id); @@ -888,14 +888,14 @@ void free_libblock(ListBase *lb, void *idv) BKE_brush_free((Brush *)id); break; case ID_PA: - psys_free_settings((ParticleSettings *)id); + BKE_particlesettings_free((ParticleSettings *)id); break; case ID_WM: if (free_windowmanager_cb) free_windowmanager_cb(NULL, (wmWindowManager *)id); break; case ID_GD: - free_gpencil_data((bGPdata *)id); + BKE_gpencil_free((bGPdata *)id); break; case ID_MC: BKE_movieclip_free((MovieClip *)id); @@ -918,20 +918,20 @@ void free_libblock(ListBase *lb, void *idv) MEM_freeN(id); } -void free_libblock_us(ListBase *lb, void *idv) /* test users */ +void BKE_libblock_free_us(ListBase *lb, void *idv) /* test users */ { - ID *id= idv; + ID *id = idv; id->us--; - if (id->us<0) { + if (id->us < 0) { if (id->lib) printf("ERROR block %s %s users %d\n", id->lib->name, id->name, id->us); else printf("ERROR block %s users %d\n", id->name, id->us); } - if (id->us==0) { - if ( GS(id->name)==ID_OB ) unlink_object((Object *)id); + if (id->us == 0) { + if (GS(id->name) == ID_OB) BKE_object_unlink((Object *)id); - free_libblock(lb, id); + BKE_libblock_free(lb, id); } } @@ -942,13 +942,13 @@ void free_main(Main *mainvar) ListBase *lbarray[MAX_LIBARRAY]; int a; - a= set_listbasepointers(mainvar, lbarray); + a = set_listbasepointers(mainvar, lbarray); while (a--) { - ListBase *lb= lbarray[a]; + ListBase *lb = lbarray[a]; ID *id; - while ( (id= lb->first) ) { - free_libblock(lb, id); + while ( (id = lb->first) ) { + BKE_libblock_free(lb, id); } } @@ -958,84 +958,85 @@ void free_main(Main *mainvar) /* ***************** ID ************************ */ -ID *find_id(const char *type, const char *name) /* type: "OB" or "MA" etc */ +ID *BKE_libblock_find_name(const short type, const char *name) /* type: "OB" or "MA" etc */ { - ListBase *lb= which_libbase(G.main, GS(type)); + ListBase *lb = which_libbase(G.main, type); + BLI_assert(lb != NULL); return BLI_findstring(lb, name, offsetof(ID, name) + 2); } static void get_flags_for_id(ID *id, char *buf) { - int isfake= id->flag & LIB_FAKEUSER; - int isnode=0; - /* Writeout the flags for the entry, note there - * is a small hack that writes 5 spaces instead - * of 4 if no flags are displayed... this makes - * things usually line up ok - better would be - * to have that explicit, oh well - zr - */ + int isfake = id->flag & LIB_FAKEUSER; + int isnode = 0; + /* Writeout the flags for the entry, note there + * is a small hack that writes 5 spaces instead + * of 4 if no flags are displayed... this makes + * things usually line up ok - better would be + * to have that explicit, oh well - zr + */ - if (GS(id->name)==ID_MA) - isnode= ((Material *)id)->use_nodes; - if (GS(id->name)==ID_TE) - isnode= ((Tex *)id)->use_nodes; + if (GS(id->name) == ID_MA) + isnode = ((Material *)id)->use_nodes; + if (GS(id->name) == ID_TE) + isnode = ((Tex *)id)->use_nodes; - if (id->us<0) + if (id->us < 0) strcpy(buf, "-1W "); else if (!id->lib && !isfake && id->us && !isnode) strcpy(buf, " "); else if (isnode) - sprintf(buf, "%c%cN%c ", id->lib?'L':' ', isfake?'F':' ', (id->us==0)?'O':' '); + sprintf(buf, "%c%cN%c ", id->lib ? 'L' : ' ', isfake ? 'F' : ' ', (id->us == 0) ? 'O' : ' '); else - sprintf(buf, "%c%c%c ", id->lib?'L':' ', isfake?'F':' ', (id->us==0)?'O':' '); + sprintf(buf, "%c%c%c ", id->lib ? 'L' : ' ', isfake ? 'F' : ' ', (id->us == 0) ? 'O' : ' '); } #define IDPUP_NO_VIEWER 1 static void IDnames_to_dyn_pupstring(DynStr *pupds, ListBase *lb, ID *link, short *nr, int hideflag) { - int i, nids= BLI_countlist(lb); + int i, nids = BLI_countlist(lb); - if (nr) *nr= -1; + if (nr) *nr = -1; - if (nr && nids>MAX_IDPUP) { + if (nr && nids > MAX_IDPUP) { BLI_dynstr_append(pupds, "DataBrowse %x-2"); - *nr= -2; + *nr = -2; } else { ID *id; - for (i=0, id= lb->first; id; id= id->next, i++) { + for (i = 0, id = lb->first; id; id = id->next, i++) { char numstr[32]; - if (nr && id==link) *nr= i+1; + if (nr && id == link) *nr = i + 1; - if (U.uiflag & USER_HIDE_DOT && id->name[2]=='.') + if (U.uiflag & USER_HIDE_DOT && id->name[2] == '.') continue; if (hideflag & IDPUP_NO_VIEWER) - if (GS(id->name)==ID_IM) - if ( ((Image *)id)->source==IMA_SRC_VIEWER ) + if (GS(id->name) == ID_IM) + if ( ((Image *)id)->source == IMA_SRC_VIEWER) continue; get_flags_for_id(id, numstr); BLI_dynstr_append(pupds, numstr); - BLI_dynstr_append(pupds, id->name+2); - BLI_snprintf(numstr, sizeof(numstr), "%%x%d", i+1); + BLI_dynstr_append(pupds, id->name + 2); + BLI_snprintf(numstr, sizeof(numstr), "%%x%d", i + 1); BLI_dynstr_append(pupds, numstr); /* icon */ switch (GS(id->name)) { - case ID_MA: /* fall through */ - case ID_TE: /* fall through */ - case ID_IM: /* fall through */ - case ID_WO: /* fall through */ - case ID_LA: /* fall through */ - BLI_snprintf(numstr, sizeof(numstr), "%%i%d", BKE_icon_getid(id)); - BLI_dynstr_append(pupds, numstr); - break; - default: - break; + case ID_MA: /* fall through */ + case ID_TE: /* fall through */ + case ID_IM: /* fall through */ + case ID_WO: /* fall through */ + case ID_LA: /* fall through */ + BLI_snprintf(numstr, sizeof(numstr), "%%i%d", BKE_icon_getid(id)); + BLI_dynstr_append(pupds, numstr); + break; + default: + break; } if (id->next) @@ -1049,7 +1050,7 @@ static void IDnames_to_dyn_pupstring(DynStr *pupds, ListBase *lb, ID *link, shor /* if nr==NULL no MAX_IDPUP, this for non-header browsing */ void IDnames_to_pupstring(const char **str, const char *title, const char *extraops, ListBase *lb, ID *link, short *nr) { - DynStr *pupds= BLI_dynstr_new(); + DynStr *pupds = BLI_dynstr_new(); if (title) { BLI_dynstr_append(pupds, title); @@ -1064,7 +1065,7 @@ void IDnames_to_pupstring(const char **str, const char *title, const char *extra IDnames_to_dyn_pupstring(pupds, lb, link, nr, 0); - *str= BLI_dynstr_get_cstring(pupds); + *str = BLI_dynstr_get_cstring(pupds); BLI_dynstr_free(pupds); } @@ -1072,7 +1073,7 @@ void IDnames_to_pupstring(const char **str, const char *title, const char *extra #if 0 /* unused */ void IMAnames_to_pupstring(const char **str, const char *title, const char *extraops, ListBase *lb, ID *link, short *nr) { - DynStr *pupds= BLI_dynstr_new(); + DynStr *pupds = BLI_dynstr_new(); if (title) { BLI_dynstr_append(pupds, title); @@ -1087,7 +1088,7 @@ void IMAnames_to_pupstring(const char **str, const char *title, const char *extr IDnames_to_dyn_pupstring(pupds, lb, link, nr, IDPUP_NO_VIEWER); - *str= BLI_dynstr_get_cstring(pupds); + *str = BLI_dynstr_get_cstring(pupds); BLI_dynstr_free(pupds); } #endif @@ -1097,19 +1098,19 @@ void id_sort_by_name(ListBase *lb, ID *id) ID *idtest; /* insert alphabetically */ - if (lb->first!=lb->last) { + if (lb->first != lb->last) { BLI_remlink(lb, id); - idtest= lb->first; + idtest = lb->first; while (idtest) { - if (BLI_strcasecmp(idtest->name, id->name)>0 || (idtest->lib && !id->lib)) { + if (BLI_strcasecmp(idtest->name, id->name) > 0 || (idtest->lib && !id->lib)) { BLI_insertlinkbefore(lb, idtest, id); break; } - idtest= idtest->next; + idtest = idtest->next; } /* as last */ - if (idtest==NULL) { + if (idtest == NULL) { BLI_addtail(lb, id); } } @@ -1122,15 +1123,15 @@ void id_sort_by_name(ListBase *lb, ID *id) */ static ID *is_dupid(ListBase *lb, ID *id, const char *name) { - ID *idtest=NULL; + ID *idtest = NULL; - for ( idtest = lb->first; idtest; idtest = idtest->next ) { + for (idtest = lb->first; idtest; idtest = idtest->next) { /* if idtest is not a lib */ - if ( id != idtest && idtest->lib == NULL ) { + if (id != idtest && idtest->lib == NULL) { /* do not test alphabetic! */ /* optimized */ - if ( idtest->name[2] == name[0] ) { - if (strcmp(name, idtest->name+2)==0) break; + if (idtest->name[2] == name[0]) { + if (strcmp(name, idtest->name + 2) == 0) break; } } } @@ -1151,7 +1152,7 @@ static ID *is_dupid(ListBase *lb, ID *id, const char *name) static int check_for_dupid(ListBase *lb, ID *id, char *name) { ID *idtest; - int nr= 0, nrtest, a, left_len; + int nr = 0, nrtest, a, left_len; char in_use[64]; /* use as a boolean array, unrelated to name length */ char left[MAX_ID_NAME + 8], leftest[MAX_ID_NAME + 8]; @@ -1166,43 +1167,44 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name) idtest = is_dupid(lb, id, name); /* if there is no double, done */ - if ( idtest == NULL ) return 0; + if (idtest == NULL) return 0; /* we have a dup; need to make a new name */ /* quick check so we can reuse one of first 64 ids if vacant */ memset(in_use, 0, sizeof(in_use)); /* get name portion, number portion ("name.number") */ - left_len= BLI_split_name_num(left, &nr, name, '.'); + left_len = BLI_split_name_num(left, &nr, name, '.'); /* if new name will be too long, truncate it */ if (nr > 999 && left_len > (MAX_ID_NAME - 8)) { - left[MAX_ID_NAME - 8]= 0; - left_len= MAX_ID_NAME - 8; + left[MAX_ID_NAME - 8] = 0; + left_len = MAX_ID_NAME - 8; } else if (left_len > (MAX_ID_NAME - 7)) { - left[MAX_ID_NAME - 7]= 0; - left_len= MAX_ID_NAME - 7; + left[MAX_ID_NAME - 7] = 0; + left_len = MAX_ID_NAME - 7; } - for (idtest= lb->first; idtest; idtest= idtest->next) { - if ( (id != idtest) && - (idtest->lib == NULL) && - (*name == *(idtest->name+2)) && - (strncmp(name, idtest->name+2, left_len)==0) && - (BLI_split_name_num(leftest, &nrtest, idtest->name+2, '.') == left_len) - ) { + for (idtest = lb->first; idtest; idtest = idtest->next) { + if ( (id != idtest) && + (idtest->lib == NULL) && + (*name == *(idtest->name + 2)) && + (strncmp(name, idtest->name + 2, left_len) == 0) && + (BLI_split_name_num(leftest, &nrtest, idtest->name + 2, '.') == left_len) + ) + { if (nrtest < sizeof(in_use)) - in_use[nrtest]= 1; /* mark as used */ + in_use[nrtest] = 1; /* mark as used */ if (nr <= nrtest) - nr= nrtest+1; /* track largest unused */ + nr = nrtest + 1; /* track largest unused */ } } /* decide which value of nr to use */ - for (a=0; a < sizeof(in_use); a++) { - if (a>=nr) break; /* stop when we've check up to biggest */ - if ( in_use[a]==0 ) { /* found an unused value */ + for (a = 0; a < sizeof(in_use); a++) { + if (a >= nr) break; /* stop when we've check up to biggest */ + if (in_use[a] == 0) { /* found an unused value */ nr = a; break; } @@ -1212,13 +1214,13 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name) * rather than just chopping and adding numbers, * shave off the end chars until we have a unique name. * Check the null terminators match as well so we don't get Cube.000 -> Cube.00 */ - if (nr==0 && name[left_len]== '\0') { - int len = left_len-1; - idtest= is_dupid(lb, id, name); + if (nr == 0 && name[left_len] == '\0') { + int len = left_len - 1; + idtest = is_dupid(lb, id, name); - while (idtest && len> 1) { + while (idtest && len > 1) { name[len--] = '\0'; - idtest= is_dupid(lb, id, name); + idtest = is_dupid(lb, id, name); } if (idtest == NULL) return 1; /* otherwise just continue and use a number suffix */ @@ -1248,24 +1250,24 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name) int new_id(ListBase *lb, ID *id, const char *tname) { int result; - char name[MAX_ID_NAME-2]; + char name[MAX_ID_NAME - 2]; /* if library, don't rename */ if (id->lib) return 0; /* if no libdata given, look up based on ID */ - if (lb==NULL) lb= which_libbase(G.main, GS(id->name)); + if (lb == NULL) lb = which_libbase(G.main, GS(id->name)); /* if no name given, use name of current ID * else make a copy (tname args can be const) */ - if (tname==NULL) - tname= id->name+2; + if (tname == NULL) + tname = id->name + 2; - strncpy(name, tname, sizeof(name)-1); + strncpy(name, tname, sizeof(name) - 1); /* if result > MAX_ID_NAME-3, strncpy don't put the final '\0' to name. * easier to assign each time then to check if its needed */ - name[sizeof(name)-1]= 0; + name[sizeof(name) - 1] = 0; if (name[0] == '\0') { /* disallow empty names */ @@ -1278,14 +1280,14 @@ int new_id(ListBase *lb, ID *id, const char *tname) } result = check_for_dupid(lb, id, name); - strcpy(id->name+2, name); + strcpy(id->name + 2, name); /* This was in 2.43 and previous releases * however all data in blender should be sorted, not just duplicate names * sorting should not hurt, but noting just incause it alters the way other * functions work, so sort every time */ #if 0 - if ( result ) + if (result) id_sort_by_name(lb, id); #endif @@ -1300,8 +1302,8 @@ void id_clear_lib_data(Main *bmain, ID *id) { BKE_id_lib_local_paths(bmain, id->lib, id); - id->lib= NULL; - id->flag= LIB_LOCAL; + id->lib = NULL; + id->flag = LIB_LOCAL; new_id(which_libbase(bmain, GS(id->name)), id, NULL); } @@ -1312,18 +1314,18 @@ void clear_id_newpoins(void) ID *id; int a; - a= set_listbasepointers(G.main, lbarray); + a = set_listbasepointers(G.main, lbarray); while (a--) { - id= lbarray[a]->first; + id = lbarray[a]->first; while (id) { - id->newid= NULL; + id->newid = NULL; id->flag &= ~LIB_NEW; - id= id->next; + id = id->next; } } } -#define LIBTAG(a) if (a && a->id.lib) {a->id.flag &=~LIB_INDIRECT; a->id.flag |= LIB_EXTERN;} +#define LIBTAG(a) if (a && a->id.lib) {a->id.flag &= ~LIB_INDIRECT; a->id.flag |= LIB_EXTERN; } static void lib_indirect_test_id(ID *id, Library *lib) { @@ -1337,17 +1339,17 @@ static void lib_indirect_test_id(ID *id, Library *lib) return; } - if (GS(id->name)==ID_OB) { - Object *ob= (Object *)id; + if (GS(id->name) == ID_OB) { + Object *ob = (Object *)id; Mesh *me; int a; -#if 0 /* XXX OLD ANIMSYS, NLASTRIPS ARE NO LONGER USED */ +#if 0 /* XXX OLD ANIMSYS, NLASTRIPS ARE NO LONGER USED */ // XXX old animation system! -------------------------------------- { bActionStrip *strip; - for (strip=ob->nlastrips.first; strip; strip=strip->next) { + for (strip = ob->nlastrips.first; strip; strip = strip->next) { LIBTAG(strip->object); LIBTAG(strip->act); LIBTAG(strip->ipo); @@ -1356,14 +1358,14 @@ static void lib_indirect_test_id(ID *id, Library *lib) // XXX: new animation system needs something like this? #endif - for (a=0; a<ob->totcol; a++) { + for (a = 0; a < ob->totcol; a++) { LIBTAG(ob->mat[a]); } LIBTAG(ob->dup_group); LIBTAG(ob->proxy); - me= ob->data; + me = ob->data; LIBTAG(me); } } @@ -1372,12 +1374,12 @@ void tag_main_lb(ListBase *lb, const short tag) { ID *id; if (tag) { - for (id= lb->first; id; id= id->next) { + for (id = lb->first; id; id = id->next) { id->flag |= LIB_DOIT; } } else { - for (id= lb->first; id; id= id->next) { + for (id = lb->first; id; id = id->next) { id->flag &= ~LIB_DOIT; } } @@ -1385,7 +1387,7 @@ void tag_main_lb(ListBase *lb, const short tag) void tag_main_idcode(struct Main *mainvar, const short type, const short tag) { - ListBase *lb= which_libbase(mainvar, type); + ListBase *lb = which_libbase(mainvar, type); tag_main_lb(lb, tag); } @@ -1395,7 +1397,7 @@ void tag_main(struct Main *mainvar, const short tag) ListBase *lbarray[MAX_LIBARRAY]; int a; - a= set_listbasepointers(mainvar, lbarray); + a = set_listbasepointers(mainvar, lbarray); while (a--) { tag_main_lb(lbarray[a], tag); } @@ -1405,27 +1407,27 @@ void tag_main(struct Main *mainvar, const short tag) * bmain is almost certainly G.main */ void BKE_library_make_local(Main *bmain, Library *lib, int untagged_only) { - ListBase *lbarray[MAX_LIBARRAY], tempbase={NULL, NULL}; + ListBase *lbarray[MAX_LIBARRAY], tempbase = {NULL, NULL}; ID *id, *idn; int a; - a= set_listbasepointers(bmain, lbarray); + a = set_listbasepointers(bmain, lbarray); while (a--) { - id= lbarray[a]->first; + id = lbarray[a]->first; while (id) { - id->newid= NULL; - idn= id->next; /* id is possibly being inserted again */ + id->newid = NULL; + idn = id->next; /* id is possibly being inserted again */ /* The check on the second line (LIB_PRE_EXISTING) is done so its * possible to tag data you don't want to be made local, used for * appending data, so any libdata already linked wont become local * (very nasty to discover all your links are lost after appending) * */ - if (id->flag & (LIB_EXTERN|LIB_INDIRECT|LIB_NEW) && - (untagged_only==0 || !(id->flag & LIB_PRE_EXISTING))) + if (id->flag & (LIB_EXTERN | LIB_INDIRECT | LIB_NEW) && + (untagged_only == 0 || !(id->flag & LIB_PRE_EXISTING))) { - if (lib==NULL || id->lib==lib) { + if (lib == NULL || id->lib == lib) { if (id->lib) { id_clear_lib_data(bmain, id); /* sets 'id->flag' */ @@ -1434,15 +1436,15 @@ void BKE_library_make_local(Main *bmain, Library *lib, int untagged_only) id_sort_by_name(lbarray[a], id); } else { - id->flag &= ~(LIB_EXTERN|LIB_INDIRECT|LIB_NEW); + id->flag &= ~(LIB_EXTERN | LIB_INDIRECT | LIB_NEW); } } } - id= idn; + id = idn; } /* patch2: make it aphabetically */ - while ( (id=tempbase.first) ) { + while ( (id = tempbase.first) ) { BLI_remlink(&tempbase, id); BLI_addtail(lbarray[a], id); new_id(lbarray[a], id, NULL); @@ -1450,9 +1452,9 @@ void BKE_library_make_local(Main *bmain, Library *lib, int untagged_only) } /* patch 3: make sure library data isn't indirect falsely... */ - a= set_listbasepointers(bmain, lbarray); + a = set_listbasepointers(bmain, lbarray); while (a--) { - for (id= lbarray[a]->first; id; id=id->next) + for (id = lbarray[a]->first; id; id = id->next) lib_indirect_test_id(id, lib); } } @@ -1465,34 +1467,34 @@ void test_idbutton(char *name) ID *idtest; - lb= which_libbase(G.main, GS(name-2) ); - if (lb==NULL) return; + lb = which_libbase(G.main, GS(name - 2) ); + if (lb == NULL) return; /* search for id */ - idtest= BLI_findstring(lb, name, offsetof(ID, name) + 2); + idtest = BLI_findstring(lb, name, offsetof(ID, name) + 2); - if (idtest) if ( new_id(lb, idtest, name)==0 ) id_sort_by_name(lb, idtest); + if (idtest) if (new_id(lb, idtest, name) == 0) id_sort_by_name(lb, idtest); } void text_idbutton(struct ID *id, char *text) { if (id) { - if (GS(id->name)==ID_SCE) + if (GS(id->name) == ID_SCE) strcpy(text, "SCE: "); - else if (GS(id->name)==ID_SCR) + else if (GS(id->name) == ID_SCR) strcpy(text, "SCR: "); - else if (GS(id->name)==ID_MA && ((Material*)id)->use_nodes) + else if (GS(id->name) == ID_MA && ((Material *)id)->use_nodes) strcpy(text, "NT: "); else { - text[0]= id->name[0]; - text[1]= id->name[1]; - text[2]= ':'; - text[3]= ' '; - text[4]= 0; + text[0] = id->name[0]; + text[1] = id->name[1]; + text[2] = ':'; + text[3] = ' '; + text[4] = 0; } } else { - text[0]= '\0'; + text[0] = '\0'; } } @@ -1500,19 +1502,19 @@ void rename_id(ID *id, const char *name) { ListBase *lb; - BLI_strncpy(id->name+2, name, sizeof(id->name)-2); - lb= which_libbase(G.main, GS(id->name) ); + BLI_strncpy(id->name + 2, name, sizeof(id->name) - 2); + lb = which_libbase(G.main, GS(id->name) ); new_id(lb, id, name); } void name_uiprefix_id(char *name, ID *id) { - name[0] = id->lib ? 'L':' '; - name[1] = id->flag & LIB_FAKEUSER ? 'F': (id->us==0)?'0':' '; + name[0] = id->lib ? 'L' : ' '; + name[1] = id->flag & LIB_FAKEUSER ? 'F' : (id->us == 0) ? '0' : ' '; name[2] = ' '; - strcpy(name+3, id->name+2); + strcpy(name + 3, id->name + 2); } void BKE_library_filepath_set(Library *lib, const char *filepath) @@ -1533,7 +1535,7 @@ void BKE_library_filepath_set(Library *lib, const char *filepath) * outliner, and its not really supported but allow from here for now * since making local could cause this to be directly linked - campbell */ - const char *basepath= lib->parent ? lib->parent->filepath : G.main->name; + const char *basepath = lib->parent ? lib->parent->filepath : G.main->name; BLI_path_abs(lib->filepath, basepath); } } diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c index b2c2cb27e31..0ed1b02d3c9 100644 --- a/source/blender/blenkernel/intern/linestyle.c +++ b/source/blender/blenkernel/intern/linestyle.c @@ -102,7 +102,7 @@ FreestyleLineStyle *FRS_new_linestyle(char *name, struct Main *main) if (!main) main = G.main; - linestyle = (FreestyleLineStyle *)alloc_libblock(&main->linestyle, ID_LS, name); + linestyle = (FreestyleLineStyle *)BKE_libblock_alloc(&main->linestyle, ID_LS, name); default_linestyle_settings(linestyle); diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index c76eb3c2fb3..9e1b45a7479 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -77,13 +77,13 @@ void init_def_material(void) } /* not material itself */ -void free_material(Material *ma) +void BKE_material_free(Material *ma) { MTex *mtex; int a; - for (a=0; a<MAX_MTEX; a++) { - mtex= ma->mtex[a]; + for (a = 0; a < MAX_MTEX; a++) { + mtex = ma->mtex[a]; if (mtex && mtex->tex) mtex->tex->id.us--; if (mtex) MEM_freeN(mtex); } @@ -95,7 +95,7 @@ void free_material(Material *ma) if (ma->preview) BKE_previewimg_free(&ma->preview); - BKE_icon_delete((struct ID*)ma); + BKE_icon_delete((struct ID *)ma); ma->id.icon_id = 0; /* is no lib link block, but material extension */ @@ -110,68 +110,68 @@ void free_material(Material *ma) void init_material(Material *ma) { - ma->r= ma->g= ma->b= ma->ref= 0.8; - ma->specr= ma->specg= ma->specb= 1.0; - ma->mirr= ma->mirg= ma->mirb= 1.0; - ma->spectra= 1.0; - ma->amb= 1.0; - ma->alpha= 1.0; - ma->spec= ma->hasize= 0.5; - ma->har= 50; - ma->starc= ma->ringc= 4; - ma->linec= 12; - ma->flarec= 1; - ma->flaresize= ma->subsize= 1.0; - ma->flareboost= 1; - ma->seed2= 6; - ma->friction= 0.5; - ma->refrac= 4.0; - ma->roughness= 0.5; - ma->param[0]= 0.5; - ma->param[1]= 0.1; - ma->param[2]= 0.5; - ma->param[3]= 0.1; - ma->rms= 0.1; - ma->darkness= 1.0; - - ma->strand_sta= ma->strand_end= 1.0f; - - ma->ang= 1.0; - ma->ray_depth= 2; - ma->ray_depth_tra= 2; - ma->fresnel_mir= 0.0; - ma->fresnel_tra= 0.0; - ma->fresnel_tra_i= 1.25; - ma->fresnel_mir_i= 1.25; - ma->tx_limit= 0.0; - ma->tx_falloff= 1.0; - ma->shad_alpha= 1.0f; - ma->vcol_alpha= 0; - - ma->gloss_mir = ma->gloss_tra= 1.0; - ma->samp_gloss_mir = ma->samp_gloss_tra= 18; + ma->r = ma->g = ma->b = ma->ref = 0.8; + ma->specr = ma->specg = ma->specb = 1.0; + ma->mirr = ma->mirg = ma->mirb = 1.0; + ma->spectra = 1.0; + ma->amb = 1.0; + ma->alpha = 1.0; + ma->spec = ma->hasize = 0.5; + ma->har = 50; + ma->starc = ma->ringc = 4; + ma->linec = 12; + ma->flarec = 1; + ma->flaresize = ma->subsize = 1.0; + ma->flareboost = 1; + ma->seed2 = 6; + ma->friction = 0.5; + ma->refrac = 4.0; + ma->roughness = 0.5; + ma->param[0] = 0.5; + ma->param[1] = 0.1; + ma->param[2] = 0.5; + ma->param[3] = 0.1; + ma->rms = 0.1; + ma->darkness = 1.0; + + ma->strand_sta = ma->strand_end = 1.0f; + + ma->ang = 1.0; + ma->ray_depth = 2; + ma->ray_depth_tra = 2; + ma->fresnel_mir = 0.0; + ma->fresnel_tra = 0.0; + ma->fresnel_tra_i = 1.25; + ma->fresnel_mir_i = 1.25; + ma->tx_limit = 0.0; + ma->tx_falloff = 1.0; + ma->shad_alpha = 1.0f; + ma->vcol_alpha = 0; + + ma->gloss_mir = ma->gloss_tra = 1.0; + ma->samp_gloss_mir = ma->samp_gloss_tra = 18; ma->adapt_thresh_mir = ma->adapt_thresh_tra = 0.005; ma->dist_mir = 0.0; ma->fadeto_mir = MA_RAYMIR_FADETOSKY; - ma->rampfac_col= 1.0; - ma->rampfac_spec= 1.0; - ma->pr_lamp= 3; /* two lamps, is bits */ - ma->pr_type= MA_SPHERE; - - ma->sss_radius[0]= 1.0f; - ma->sss_radius[1]= 1.0f; - ma->sss_radius[2]= 1.0f; - ma->sss_col[0]= 1.0f; - ma->sss_col[1]= 1.0f; - ma->sss_col[2]= 1.0f; - ma->sss_error= 0.05f; - ma->sss_scale= 0.1f; - ma->sss_ior= 1.3f; - ma->sss_colfac= 1.0f; - ma->sss_texfac= 0.0f; - ma->sss_front= 1.0f; - ma->sss_back= 1.0f; + ma->rampfac_col = 1.0; + ma->rampfac_spec = 1.0; + ma->pr_lamp = 3; /* two lamps, is bits */ + ma->pr_type = MA_SPHERE; + + ma->sss_radius[0] = 1.0f; + ma->sss_radius[1] = 1.0f; + ma->sss_radius[2] = 1.0f; + ma->sss_col[0] = 1.0f; + ma->sss_col[1] = 1.0f; + ma->sss_col[2] = 1.0f; + ma->sss_error = 0.05f; + ma->sss_scale = 0.1f; + ma->sss_ior = 1.3f; + ma->sss_colfac = 1.0f; + ma->sss_texfac = 0.0f; + ma->sss_front = 1.0f; + ma->sss_back = 1.0f; ma->vol.density = 1.0f; ma->vol.emission = 0.0f; @@ -192,19 +192,19 @@ void init_material(Material *ma) ma->vol.ms_intensity = 1.f; ma->game.flag = GEMAT_BACKCULL; - ma->game.alpha_blend=0; - ma->game.face_orientation=0; + ma->game.alpha_blend = 0; + ma->game.face_orientation = 0; - ma->mode= MA_TRACEBLE|MA_SHADBUF|MA_SHADOW|MA_RAYBIAS|MA_TANGENT_STR|MA_ZTRANSP; - ma->shade_flag= MA_APPROX_OCCLUSION; + ma->mode = MA_TRACEBLE | MA_SHADBUF | MA_SHADOW | MA_RAYBIAS | MA_TANGENT_STR | MA_ZTRANSP; + ma->shade_flag = MA_APPROX_OCCLUSION; ma->preview = NULL; } -Material *add_material(const char *name) +Material *BKE_material_add(const char *name) { Material *ma; - ma= alloc_libblock(&G.main->mat, ID_MA, name); + ma = BKE_libblock_alloc(&G.main->mat, ID_MA, name); init_material(ma); @@ -212,33 +212,33 @@ Material *add_material(const char *name) } /* XXX keep synced with next function */ -Material *copy_material(Material *ma) +Material *BKE_material_copy(Material *ma) { Material *man; int a; - man= copy_libblock(&ma->id); + man = BKE_libblock_copy(&ma->id); id_lib_extern((ID *)man->group); - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { if (ma->mtex[a]) { - man->mtex[a]= MEM_mallocN(sizeof(MTex), "copymaterial"); + man->mtex[a] = MEM_mallocN(sizeof(MTex), "copymaterial"); memcpy(man->mtex[a], ma->mtex[a], sizeof(MTex)); id_us_plus((ID *)man->mtex[a]->tex); } } - if (ma->ramp_col) man->ramp_col= MEM_dupallocN(ma->ramp_col); - if (ma->ramp_spec) man->ramp_spec= MEM_dupallocN(ma->ramp_spec); + if (ma->ramp_col) man->ramp_col = MEM_dupallocN(ma->ramp_col); + if (ma->ramp_spec) man->ramp_spec = MEM_dupallocN(ma->ramp_spec); if (ma->preview) man->preview = BKE_previewimg_copy(ma->preview); if (ma->nodetree) { - man->nodetree= ntreeCopyTree(ma->nodetree); /* 0 == full new tree */ + man->nodetree = ntreeCopyTree(ma->nodetree); /* 0 == full new tree */ } - man->gpumaterial.first= man->gpumaterial.last= NULL; + man->gpumaterial.first = man->gpumaterial.last = NULL; return man; } @@ -249,26 +249,26 @@ Material *localize_material(Material *ma) Material *man; int a; - man= copy_libblock(&ma->id); + man = BKE_libblock_copy(&ma->id); 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++) { + for (a = 0; a < MAX_MTEX; a++) { if (ma->mtex[a]) { - man->mtex[a]= MEM_mallocN(sizeof(MTex), "copymaterial"); + man->mtex[a] = MEM_mallocN(sizeof(MTex), "copymaterial"); memcpy(man->mtex[a], ma->mtex[a], sizeof(MTex)); } } - if (ma->ramp_col) man->ramp_col= MEM_dupallocN(ma->ramp_col); - if (ma->ramp_spec) man->ramp_spec= MEM_dupallocN(ma->ramp_spec); + if (ma->ramp_col) man->ramp_col = MEM_dupallocN(ma->ramp_col); + if (ma->ramp_spec) man->ramp_spec = MEM_dupallocN(ma->ramp_spec); man->preview = NULL; if (ma->nodetree) - man->nodetree= ntreeLocalize(ma->nodetree); + man->nodetree = ntreeLocalize(ma->nodetree); - man->gpumaterial.first= man->gpumaterial.last= NULL; + man->gpumaterial.first = man->gpumaterial.last = NULL; return man; } @@ -276,29 +276,29 @@ Material *localize_material(Material *ma) static void extern_local_material(Material *ma) { int i; - for (i=0; i < MAX_MTEX; i++) { + for (i = 0; i < MAX_MTEX; i++) { if (ma->mtex[i]) id_lib_extern((ID *)ma->mtex[i]->tex); } } -void make_local_material(Material *ma) +void BKE_material_make_local(Material *ma) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; Mesh *me; Curve *cu; MetaBall *mb; - int a, is_local= FALSE, is_lib= FALSE; + int a, is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (ma->id.lib==NULL) return; + if (ma->id.lib == NULL) return; /* One local user; set flag and return. */ - if (ma->id.us==1) { + if (ma->id.us == 1) { id_clear_lib_data(bmain, &ma->id); extern_local_material(ma); return; @@ -307,56 +307,56 @@ void make_local_material(Material *ma) /* Check which other IDs reference this one to determine if it's used by * lib or local */ /* test objects */ - ob= bmain->object.first; + ob = bmain->object.first; while (ob) { if (ob->mat) { - for (a=0; a<ob->totcol; a++) { - if (ob->mat[a]==ma) { - if (ob->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (a = 0; a < ob->totcol; a++) { + if (ob->mat[a] == ma) { + if (ob->id.lib) is_lib = TRUE; + else is_local = TRUE; } } } - ob= ob->id.next; + ob = ob->id.next; } /* test meshes */ - me= bmain->mesh.first; + me = bmain->mesh.first; while (me) { if (me->mat) { - for (a=0; a<me->totcol; a++) { - if (me->mat[a]==ma) { - if (me->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (a = 0; a < me->totcol; a++) { + if (me->mat[a] == ma) { + if (me->id.lib) is_lib = TRUE; + else is_local = TRUE; } } } - me= me->id.next; + me = me->id.next; } /* test curves */ - cu= bmain->curve.first; + cu = bmain->curve.first; while (cu) { if (cu->mat) { - for (a=0; a<cu->totcol; a++) { - if (cu->mat[a]==ma) { - if (cu->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (a = 0; a < cu->totcol; a++) { + if (cu->mat[a] == ma) { + if (cu->id.lib) is_lib = TRUE; + else is_local = TRUE; } } } - cu= cu->id.next; + cu = cu->id.next; } /* test mballs */ - mb= bmain->mball.first; + mb = bmain->mball.first; while (mb) { if (mb->mat) { - for (a=0; a<mb->totcol; a++) { - if (mb->mat[a]==ma) { - if (mb->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (a = 0; a < mb->totcol; a++) { + if (mb->mat[a] == ma) { + if (mb->id.lib) is_lib = TRUE; + else is_local = TRUE; } } } - mb= mb->id.next; + mb = mb->id.next; } /* Only local users. */ @@ -366,76 +366,76 @@ void make_local_material(Material *ma) } /* Both user and local, so copy. */ else if (is_local && is_lib) { - Material *ma_new= copy_material(ma); + Material *ma_new = BKE_material_copy(ma); - ma_new->id.us= 0; + ma_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, ma->id.lib, &ma_new->id); /* do objects */ - ob= bmain->object.first; + ob = bmain->object.first; while (ob) { if (ob->mat) { - for (a=0; a<ob->totcol; a++) { - if (ob->mat[a]==ma) { - if (ob->id.lib==NULL) { - ob->mat[a]= ma_new; + for (a = 0; a < ob->totcol; a++) { + if (ob->mat[a] == ma) { + if (ob->id.lib == NULL) { + ob->mat[a] = ma_new; ma_new->id.us++; ma->id.us--; } } } } - ob= ob->id.next; + ob = ob->id.next; } /* do meshes */ - me= bmain->mesh.first; + me = bmain->mesh.first; while (me) { if (me->mat) { - for (a=0; a<me->totcol; a++) { - if (me->mat[a]==ma) { - if (me->id.lib==NULL) { - me->mat[a]= ma_new; + for (a = 0; a < me->totcol; a++) { + if (me->mat[a] == ma) { + if (me->id.lib == NULL) { + me->mat[a] = ma_new; ma_new->id.us++; ma->id.us--; } } } } - me= me->id.next; + me = me->id.next; } /* do curves */ - cu= bmain->curve.first; + cu = bmain->curve.first; while (cu) { if (cu->mat) { - for (a=0; a<cu->totcol; a++) { - if (cu->mat[a]==ma) { - if (cu->id.lib==NULL) { - cu->mat[a]= ma_new; + for (a = 0; a < cu->totcol; a++) { + if (cu->mat[a] == ma) { + if (cu->id.lib == NULL) { + cu->mat[a] = ma_new; ma_new->id.us++; ma->id.us--; } } } } - cu= cu->id.next; + cu = cu->id.next; } /* do mballs */ - mb= bmain->mball.first; + mb = bmain->mball.first; while (mb) { if (mb->mat) { - for (a=0; a<mb->totcol; a++) { - if (mb->mat[a]==ma) { - if (mb->id.lib==NULL) { - mb->mat[a]= ma_new; + for (a = 0; a < mb->totcol; a++) { + if (mb->mat[a] == ma) { + if (mb->id.lib == NULL) { + mb->mat[a] = ma_new; ma_new->id.us++; ma->id.us--; } } } } - mb= mb->id.next; + mb = mb->id.next; } } } @@ -444,7 +444,7 @@ void make_local_material(Material *ma) void extern_local_matarar(struct Material **matar, short totcol) { short i; - for (i= 0; i < totcol; i++) { + for (i = 0; i < totcol; i++) { id_lib_extern((ID *)matar[i]); } } @@ -455,16 +455,16 @@ Material ***give_matarar(Object *ob) Curve *cu; MetaBall *mb; - if (ob->type==OB_MESH) { - me= ob->data; + if (ob->type == OB_MESH) { + me = ob->data; return &(me->mat); } else if (ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF)) { - cu= ob->data; + cu = ob->data; return &(cu->mat); } - else if (ob->type==OB_MBALL) { - mb= ob->data; + else if (ob->type == OB_MBALL) { + mb = ob->data; return &(mb->mat); } return NULL; @@ -476,16 +476,16 @@ short *give_totcolp(Object *ob) Curve *cu; MetaBall *mb; - if (ob->type==OB_MESH) { - me= ob->data; + if (ob->type == OB_MESH) { + me = ob->data; return &(me->totcol); } else if (ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF)) { - cu= ob->data; + cu = ob->data; return &(cu->totcol); } - else if (ob->type==OB_MBALL) { - mb= ob->data; + else if (ob->type == OB_MBALL) { + mb = ob->data; return &(mb->totcol); } return NULL; @@ -495,15 +495,15 @@ short *give_totcolp(Object *ob) Material ***give_matarar_id(ID *id) { switch (GS(id->name)) { - case ID_ME: - return &(((Mesh *)id)->mat); - break; - case ID_CU: - return &(((Curve *)id)->mat); - break; - case ID_MB: - return &(((MetaBall *)id)->mat); - break; + case ID_ME: + return &(((Mesh *)id)->mat); + break; + case ID_CU: + return &(((Curve *)id)->mat); + break; + case ID_MB: + return &(((MetaBall *)id)->mat); + break; } return NULL; } @@ -511,15 +511,15 @@ Material ***give_matarar_id(ID *id) short *give_totcolp_id(ID *id) { switch (GS(id->name)) { - case ID_ME: - return &(((Mesh *)id)->totcol); - break; - case ID_CU: - return &(((Curve *)id)->totcol); - break; - case ID_MB: - return &(((MetaBall *)id)->totcol); - break; + case ID_ME: + return &(((Mesh *)id)->totcol); + break; + case ID_CU: + return &(((Curve *)id)->totcol); + break; + case ID_MB: + return &(((MetaBall *)id)->totcol); + break; } return NULL; } @@ -527,29 +527,29 @@ short *give_totcolp_id(ID *id) static void data_delete_material_index_id(ID *id, short index) { switch (GS(id->name)) { - case ID_ME: - mesh_delete_material_index((Mesh *)id, index); - break; - case ID_CU: - BKE_curve_delete_material_index((Curve *)id, index); - break; - case ID_MB: - /* meta-elems don't have materials atm */ - break; + case ID_ME: + BKE_mesh_delete_material_index((Mesh *)id, index); + break; + case ID_CU: + BKE_curve_delete_material_index((Curve *)id, index); + break; + case ID_MB: + /* meta-elems don't have materials atm */ + break; } } void material_append_id(ID *id, Material *ma) { Material ***matar; - if ((matar= give_matarar_id(id))) { - short *totcol= give_totcolp_id(id); - Material **mat= MEM_callocN(sizeof(void *) * ((*totcol) + 1), "newmatar"); + if ((matar = give_matarar_id(id))) { + short *totcol = give_totcolp_id(id); + Material **mat = MEM_callocN(sizeof(void *) * ((*totcol) + 1), "newmatar"); if (*totcol) memcpy(mat, *matar, sizeof(void *) * (*totcol)); if (*matar) MEM_freeN(*matar); - *matar= mat; - (*matar)[(*totcol)++]= ma; + *matar = mat; + (*matar)[(*totcol)++] = ma; id_us_plus((ID *)ma); test_object_materials(id); @@ -558,33 +558,33 @@ void material_append_id(ID *id, Material *ma) Material *material_pop_id(ID *id, int index_i, int remove_material_slot) { - short index= (short)index_i; - Material *ret= NULL; + short index = (short)index_i; + Material *ret = NULL; Material ***matar; - if ((matar= give_matarar_id(id))) { - short *totcol= give_totcolp_id(id); + if ((matar = give_matarar_id(id))) { + short *totcol = give_totcolp_id(id); if (index >= 0 && index < (*totcol)) { - ret= (*matar)[index]; + ret = (*matar)[index]; id_us_min((ID *)ret); if (remove_material_slot) { if (*totcol <= 1) { - *totcol= 0; + *totcol = 0; MEM_freeN(*matar); - *matar= NULL; + *matar = NULL; } else { Material **mat; if (index + 1 != (*totcol)) - memmove((*matar)+index, (*matar)+(index+1), sizeof(void *) * ((*totcol) - (index + 1))); + memmove((*matar) + index, (*matar) + (index + 1), sizeof(void *) * ((*totcol) - (index + 1))); (*totcol)--; - mat= MEM_callocN(sizeof(void *) * (*totcol), "newmatar"); + mat = MEM_callocN(sizeof(void *) * (*totcol), "newmatar"); memcpy(mat, *matar, sizeof(void *) * (*totcol)); MEM_freeN(*matar); - *matar= mat; + *matar = mat; test_object_materials(id); } @@ -594,7 +594,7 @@ Material *material_pop_id(ID *id, int index_i, int remove_material_slot) /* don't remove material slot, only clear it*/ else - (*matar)[index]= NULL; + (*matar)[index] = NULL; } } @@ -606,33 +606,33 @@ Material *give_current_material(Object *ob, short act) Material ***matarar, *ma; short *totcolp; - if (ob==NULL) return NULL; + if (ob == NULL) return NULL; /* if object cannot have material, totcolp==NULL */ - totcolp= give_totcolp(ob); - if (totcolp==NULL || ob->totcol==0) return NULL; + totcolp = give_totcolp(ob); + if (totcolp == NULL || ob->totcol == 0) return NULL; - if (act<0) { + if (act < 0) { printf("no!\n"); } - if (act>ob->totcol) act= ob->totcol; - else if (act<=0) act= 1; + if (act > ob->totcol) act = ob->totcol; + else if (act <= 0) act = 1; - if (ob->matbits && ob->matbits[act-1]) { /* in object */ - ma= ob->mat[act-1]; + if (ob->matbits && ob->matbits[act - 1]) { /* in object */ + ma = ob->mat[act - 1]; } - else { /* in data */ + else { /* in data */ /* check for inconsistency */ if (*totcolp < ob->totcol) - ob->totcol= *totcolp; - if (act>ob->totcol) act= ob->totcol; + ob->totcol = *totcolp; + if (act > ob->totcol) act = ob->totcol; - matarar= give_matarar(ob); + matarar = give_matarar(ob); - if (matarar && *matarar) ma= (*matarar)[act-1]; - else ma= NULL; + if (matarar && *matarar) ma = (*matarar)[act - 1]; + else ma = NULL; } @@ -642,19 +642,19 @@ Material *give_current_material(Object *ob, short act) ID *material_from(Object *ob, short act) { - if (ob==NULL) return NULL; + if (ob == NULL) return NULL; - if (ob->totcol==0) return ob->data; - if (act==0) act= 1; + if (ob->totcol == 0) return ob->data; + if (act == 0) act = 1; - if (ob->matbits[act-1]) return (ID *)ob; + if (ob->matbits[act - 1]) return (ID *)ob; else return ob->data; } Material *give_node_material(Material *ma) { if (ma && ma->use_nodes && ma->nodetree) { - bNode *node= nodeGetActiveID(ma->nodetree, ID_MA); + bNode *node = nodeGetActiveID(ma->nodetree, ID_MA); if (node) return (Material *)node->id; @@ -671,7 +671,7 @@ Material *give_node_material(Material *ma) * well. I expect we'll sort it out soon... */ /* from blendef: */ -#define GS(a) (*((short *)(a))) +#define GS(a) (*((short *)(a))) /* from misc_util: flip the bytes from x */ /* #define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1]) */ @@ -681,29 +681,29 @@ void resize_object_material(Object *ob, const short totcol) Material **newmatar; char *newmatbits; - if (totcol==0) { + if (totcol == 0) { if (ob->totcol) { MEM_freeN(ob->mat); MEM_freeN(ob->matbits); - ob->mat= NULL; - ob->matbits= NULL; + ob->mat = NULL; + ob->matbits = NULL; } } - else if (ob->totcol<totcol) { - newmatar= MEM_callocN(sizeof(void *)*totcol, "newmatar"); - newmatbits= MEM_callocN(sizeof(char)*totcol, "newmatbits"); + else if (ob->totcol < totcol) { + newmatar = MEM_callocN(sizeof(void *) * totcol, "newmatar"); + newmatbits = MEM_callocN(sizeof(char) * totcol, "newmatbits"); if (ob->totcol) { - memcpy(newmatar, ob->mat, sizeof(void *)*ob->totcol); - memcpy(newmatbits, ob->matbits, sizeof(char)*ob->totcol); + memcpy(newmatar, ob->mat, sizeof(void *) * ob->totcol); + memcpy(newmatbits, ob->matbits, sizeof(char) * ob->totcol); MEM_freeN(ob->mat); MEM_freeN(ob->matbits); } - ob->mat= newmatar; - ob->matbits= newmatbits; + ob->mat = newmatar; + ob->matbits = newmatbits; } - ob->totcol= totcol; - if (ob->totcol && ob->actcol==0) ob->actcol= 1; - if (ob->actcol>ob->totcol) ob->actcol= ob->totcol; + ob->totcol = totcol; + if (ob->totcol && ob->actcol == 0) ob->actcol = 1; + if (ob->actcol > ob->totcol) ob->actcol = ob->totcol; } void test_object_materials(ID *id) @@ -712,12 +712,12 @@ void test_object_materials(ID *id) Object *ob; short *totcol; - if (id==NULL || (totcol=give_totcolp_id(id))==NULL) { + if (id == NULL || (totcol = give_totcolp_id(id)) == NULL) { return; } - for (ob= G.main->object.first; ob; ob= ob->id.next) { - if (ob->data==id) { + for (ob = G.main->object.first; ob; ob = ob->id.next) { + if (ob->data == id) { resize_object_material(ob, *totcol); } } @@ -728,8 +728,8 @@ void assign_material_id(ID *id, Material *ma, short act) Material *mao, **matar, ***matarar; short *totcolp; - if (act>MAXMAT) return; - if (act<1) act= 1; + if (act > MAXMAT) return; + if (act < 1) act = 1; /* prevent crashing when using accidentally */ BLI_assert(id->lib == NULL); @@ -737,27 +737,27 @@ void assign_material_id(ID *id, Material *ma, short act) /* test arraylens */ - totcolp= give_totcolp_id(id); - matarar= give_matarar_id(id); + totcolp = give_totcolp_id(id); + matarar = give_matarar_id(id); - if (totcolp==NULL || matarar==NULL) return; + if (totcolp == NULL || matarar == NULL) return; if (act > *totcolp) { - matar= MEM_callocN(sizeof(void *)*act, "matarray1"); + matar = MEM_callocN(sizeof(void *) * act, "matarray1"); if (*totcolp) { - memcpy(matar, *matarar, sizeof(void *)*(*totcolp)); + memcpy(matar, *matarar, sizeof(void *) * (*totcolp)); MEM_freeN(*matarar); } - *matarar= matar; - *totcolp= act; + *matarar = matar; + *totcolp = act; } /* in data */ - mao= (*matarar)[act-1]; + mao = (*matarar)[act - 1]; if (mao) mao->id.us--; - (*matarar)[act-1]= ma; + (*matarar)[act - 1] = ma; if (ma) id_us_plus((ID *)ma); @@ -771,8 +771,8 @@ void assign_material(Object *ob, Material *ma, short act) char *matbits; short *totcolp; - if (act>MAXMAT) return; - if (act<1) act= 1; + if (act > MAXMAT) return; + if (act < 1) act = 1; /* prevent crashing when using accidentally */ BLI_assert(ob->id.lib == NULL); @@ -780,54 +780,54 @@ void assign_material(Object *ob, Material *ma, short act) /* test arraylens */ - totcolp= give_totcolp(ob); - matarar= give_matarar(ob); + totcolp = give_totcolp(ob); + matarar = give_matarar(ob); - if (totcolp==NULL || matarar==NULL) return; + if (totcolp == NULL || matarar == NULL) return; if (act > *totcolp) { - matar= MEM_callocN(sizeof(void *)*act, "matarray1"); + matar = MEM_callocN(sizeof(void *) * act, "matarray1"); if (*totcolp) { - memcpy(matar, *matarar, sizeof(void *)*(*totcolp)); + memcpy(matar, *matarar, sizeof(void *) * (*totcolp)); MEM_freeN(*matarar); } - *matarar= matar; - *totcolp= act; + *matarar = matar; + *totcolp = act; } if (act > ob->totcol) { - matar= MEM_callocN(sizeof(void *)*act, "matarray2"); - matbits= MEM_callocN(sizeof(char)*act, "matbits1"); - if ( ob->totcol) { + matar = MEM_callocN(sizeof(void *) * act, "matarray2"); + matbits = MEM_callocN(sizeof(char) * act, "matbits1"); + if (ob->totcol) { memcpy(matar, ob->mat, sizeof(void *) * ob->totcol); - memcpy(matbits, ob->matbits, sizeof(char)*(*totcolp)); + memcpy(matbits, ob->matbits, sizeof(char) * (*totcolp)); MEM_freeN(ob->mat); MEM_freeN(ob->matbits); } - ob->mat= matar; - ob->matbits= matbits; - ob->totcol= act; + ob->mat = matar; + ob->matbits = matbits; + ob->totcol = act; /* copy object/mesh linking, or assign based on userpref */ if (ob->actcol) - ob->matbits[act-1]= ob->matbits[ob->actcol-1]; + ob->matbits[act - 1] = ob->matbits[ob->actcol - 1]; else - ob->matbits[act-1]= (U.flag & USER_MAT_ON_OB)? 1: 0; + ob->matbits[act - 1] = (U.flag & USER_MAT_ON_OB) ? 1 : 0; } /* do it */ - if (ob->matbits[act-1]) { /* in object */ - mao= ob->mat[act-1]; + if (ob->matbits[act - 1]) { /* in object */ + mao = ob->mat[act - 1]; if (mao) mao->id.us--; - ob->mat[act-1]= ma; + ob->mat[act - 1] = ma; } - else { /* in data */ - mao= (*matarar)[act-1]; + else { /* in data */ + mao = (*matarar)[act - 1]; if (mao) mao->id.us--; - (*matarar)[act-1]= ma; + (*matarar)[act - 1] = ma; } if (ma) @@ -838,19 +838,19 @@ void assign_material(Object *ob, Material *ma, short act) /* XXX - this calls many more update calls per object then are needed, could be optimized */ void assign_matarar(struct Object *ob, struct Material ***matar, short totcol) { - int actcol_orig= ob->actcol; + int actcol_orig = ob->actcol; short i; while (object_remove_material_slot(ob)) {}; /* now we have the right number of slots */ - for (i=0; i<totcol; i++) - assign_material(ob, (*matar)[i], i+1); + for (i = 0; i < totcol; i++) + assign_material(ob, (*matar)[i], i + 1); if (actcol_orig > ob->totcol) - actcol_orig= ob->totcol; + actcol_orig = ob->totcol; - ob->actcol= actcol_orig; + ob->actcol = actcol_orig; } @@ -859,45 +859,45 @@ short find_material_index(Object *ob, Material *ma) Material ***matarar; short a, *totcolp; - if (ma==NULL) return 0; + if (ma == NULL) return 0; - totcolp= give_totcolp(ob); - matarar= give_matarar(ob); + totcolp = give_totcolp(ob); + matarar = give_matarar(ob); - if (totcolp==NULL || matarar==NULL) return 0; + if (totcolp == NULL || matarar == NULL) return 0; - for (a=0; a<*totcolp; a++) - if ((*matarar)[a]==ma) - break; - if (a<*totcolp) - return a+1; + for (a = 0; a < *totcolp; a++) + if ((*matarar)[a] == ma) + break; + if (a < *totcolp) + return a + 1; return 0; } int object_add_material_slot(Object *ob) { - if (ob==NULL) return FALSE; - if (ob->totcol>=MAXMAT) return FALSE; + if (ob == NULL) return FALSE; + if (ob->totcol >= MAXMAT) return FALSE; - assign_material(ob, NULL, ob->totcol+1); - ob->actcol= ob->totcol; + assign_material(ob, NULL, ob->totcol + 1); + ob->actcol = ob->totcol; return TRUE; } static void do_init_render_material(Material *ma, int r_mode, float *amb) { MTex *mtex; - int a, needuv=0, needtang=0; + int a, needuv = 0, needtang = 0; - if (ma->flarec==0) ma->flarec= 1; + if (ma->flarec == 0) ma->flarec = 1; /* add all texcoflags from mtex, texco and mapto were cleared in advance */ - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { /* separate tex switching */ - if (ma->septex & (1<<a)) continue; + if (ma->septex & (1 << a)) continue; - mtex= ma->mtex[a]; + mtex = ma->mtex[a]; if (mtex && mtex->tex && (mtex->tex->type | (mtex->tex->use_nodes && mtex->tex->nodetree) )) { ma->texco |= mtex->texco; @@ -905,41 +905,41 @@ static void do_init_render_material(Material *ma, int r_mode, float *amb) /* always get derivatives for these textures */ if (ELEM3(mtex->tex->type, TEX_IMAGE, TEX_PLUGIN, TEX_ENVMAP)) ma->texco |= TEXCO_OSA; - else if (mtex->texflag & (MTEX_COMPAT_BUMP|MTEX_3TAP_BUMP|MTEX_5TAP_BUMP|MTEX_BICUBIC_BUMP)) ma->texco |= TEXCO_OSA; + else if (mtex->texflag & (MTEX_COMPAT_BUMP | MTEX_3TAP_BUMP | MTEX_5TAP_BUMP | MTEX_BICUBIC_BUMP)) ma->texco |= TEXCO_OSA; - if (ma->texco & (TEXCO_ORCO|TEXCO_REFL|TEXCO_NORM|TEXCO_STRAND|TEXCO_STRESS)) needuv= 1; - else if (ma->texco & (TEXCO_GLOB|TEXCO_UV|TEXCO_OBJECT|TEXCO_SPEED)) needuv= 1; - else if (ma->texco & (TEXCO_LAVECTOR|TEXCO_VIEW|TEXCO_STICKY)) needuv= 1; + if (ma->texco & (TEXCO_ORCO | TEXCO_REFL | TEXCO_NORM | TEXCO_STRAND | TEXCO_STRESS)) needuv = 1; + else if (ma->texco & (TEXCO_GLOB | TEXCO_UV | TEXCO_OBJECT | TEXCO_SPEED)) needuv = 1; + else if (ma->texco & (TEXCO_LAVECTOR | TEXCO_VIEW | TEXCO_STICKY)) needuv = 1; if ((ma->mapto & MAP_NORM) && (mtex->normapspace == MTEX_NSPACE_TANGENT)) - needtang= 1; + needtang = 1; } } if (needtang) ma->mode |= MA_NORMAP_TANG; else ma->mode &= ~MA_NORMAP_TANG; - if (ma->mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE)) { - needuv= 1; - if (r_mode & R_OSA) ma->texco |= TEXCO_OSA; /* for texfaces */ + if (ma->mode & (MA_VERTEXCOL | MA_VERTEXCOLP | MA_FACETEXTURE)) { + needuv = 1; + if (r_mode & R_OSA) ma->texco |= TEXCO_OSA; /* for texfaces */ } if (needuv) ma->texco |= NEED_UV; /* since the raytracer doesnt recalc O structs for each ray, we have to preset them all */ if (r_mode & R_RAYTRACE) { - if ((ma->mode & (MA_RAYMIRROR|MA_SHADOW_TRA)) || ((ma->mode & MA_TRANSP) && (ma->mode & MA_RAYTRANSP))) { - ma->texco |= NEED_UV|TEXCO_ORCO|TEXCO_REFL|TEXCO_NORM; + if ((ma->mode & (MA_RAYMIRROR | MA_SHADOW_TRA)) || ((ma->mode & MA_TRANSP) && (ma->mode & MA_RAYTRANSP))) { + ma->texco |= NEED_UV | TEXCO_ORCO | TEXCO_REFL | TEXCO_NORM; if (r_mode & R_OSA) ma->texco |= TEXCO_OSA; } } if (amb) { - ma->ambr= ma->amb*amb[0]; - ma->ambg= ma->amb*amb[1]; - ma->ambb= ma->amb*amb[2]; + ma->ambr = ma->amb * amb[0]; + ma->ambg = ma->amb * amb[1]; + ma->ambb = ma->amb * amb[2]; } /* will become or-ed result of all node modes */ - ma->mode_l= ma->mode; + ma->mode_l = ma->mode; ma->mode_l &= ~MA_SHLESS; if (ma->strand_surfnor > 0.0f) @@ -954,17 +954,17 @@ static void init_render_nodetree(bNodeTree *ntree, Material *basemat, int r_mode { bNode *node; - for (node=ntree->nodes.first; node; node= node->next) { + for (node = ntree->nodes.first; node; node = node->next) { if (node->id) { - if (GS(node->id->name)==ID_MA) { - Material *ma= (Material *)node->id; - if (ma!=basemat) { + if (GS(node->id->name) == ID_MA) { + Material *ma = (Material *)node->id; + if (ma != basemat) { do_init_render_material(ma, r_mode, amb); basemat->texco |= ma->texco; - basemat->mode_l |= ma->mode_l & ~(MA_TRANSP|MA_ZTRANSP|MA_RAYTRANSP); + basemat->mode_l |= ma->mode_l & ~(MA_TRANSP | MA_ZTRANSP | MA_RAYTRANSP); } } - else if (node->type==NODE_GROUP) + else if (node->type == NODE_GROUP) init_render_nodetree((bNodeTree *)node->id, basemat, r_mode, amb); } } @@ -990,15 +990,15 @@ void init_render_materials(Main *bmain, int r_mode, float *amb) /* clear these flags before going over materials, to make sure they * are cleared only once, otherwise node materials contained in other * node materials can go wrong */ - for (ma= bmain->mat.first; ma; ma= ma->id.next) { + for (ma = bmain->mat.first; ma; ma = ma->id.next) { if (ma->id.us) { - ma->texco= 0; - ma->mapto= 0; + ma->texco = 0; + ma->mapto = 0; } } /* two steps, first initialize, then or the flags for layers */ - for (ma= bmain->mat.first; ma; ma= ma->id.next) { + for (ma = bmain->mat.first; ma; ma = ma->id.next) { /* is_used flag comes back in convertblender.c */ ma->flag &= ~MA_IS_USED; if (ma->id.us) @@ -1020,7 +1020,7 @@ void end_render_material(Material *mat) void end_render_materials(Main *bmain) { Material *ma; - for (ma= bmain->mat.first; ma; ma= ma->id.next) + for (ma = bmain->mat.first; ma; ma = ma->id.next) if (ma->id.us) end_render_material(ma); } @@ -1029,13 +1029,13 @@ static int material_in_nodetree(bNodeTree *ntree, Material *mat) { bNode *node; - for (node=ntree->nodes.first; node; node= node->next) { - if (node->id && GS(node->id->name)==ID_MA) { - if (node->id==(ID*)mat) + for (node = ntree->nodes.first; node; node = node->next) { + if (node->id && GS(node->id->name) == ID_MA) { + if (node->id == (ID *)mat) return 1; } - else if (node->type==NODE_GROUP) - if (material_in_nodetree((bNodeTree*)node->id, mat)) + else if (node->type == NODE_GROUP) + if (material_in_nodetree((bNodeTree *)node->id, mat)) return 1; } @@ -1044,7 +1044,7 @@ static int material_in_nodetree(bNodeTree *ntree, Material *mat) int material_in_material(Material *parmat, Material *mat) { - if (parmat==mat) + if (parmat == mat) return 1; else if (parmat->nodetree && parmat->use_nodes) return material_in_nodetree(parmat->nodetree, mat); @@ -1087,15 +1087,15 @@ void automatname(Material *ma) int nr, r, g, b; float ref; - if (ma==NULL) return; - if (ma->mode & MA_SHLESS) ref= 1.0; - else ref= ma->ref; - - 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; + if (ma == NULL) return; + if (ma->mode & MA_SHLESS) ref = 1.0; + else ref = ma->ref; + + 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]); } @@ -1108,7 +1108,7 @@ int object_remove_material_slot(Object *ob) short *totcolp; short a, actcol; - if (ob==NULL || ob->totcol==0) { + if (ob == NULL || ob->totcol == 0) { return FALSE; } @@ -1125,55 +1125,55 @@ int object_remove_material_slot(Object *ob) * after that check indices in mesh/curve/mball!!! */ - totcolp= give_totcolp(ob); - matarar= give_matarar(ob); + totcolp = give_totcolp(ob); + matarar = give_matarar(ob); - if (*matarar==NULL) return FALSE; + if (*matarar == NULL) return FALSE; /* we delete the actcol */ - mao= (*matarar)[ob->actcol-1]; + mao = (*matarar)[ob->actcol - 1]; if (mao) mao->id.us--; - for (a=ob->actcol; a<ob->totcol; a++) - (*matarar)[a-1]= (*matarar)[a]; + for (a = ob->actcol; a < ob->totcol; a++) + (*matarar)[a - 1] = (*matarar)[a]; (*totcolp)--; - if (*totcolp==0) { + if (*totcolp == 0) { MEM_freeN(*matarar); - *matarar= NULL; + *matarar = NULL; } - actcol= ob->actcol; - obt= G.main->object.first; + actcol = ob->actcol; + obt = G.main->object.first; while (obt) { - if (obt->data==ob->data) { + if (obt->data == ob->data) { /* WATCH IT: do not use actcol from ob or from obt (can become zero) */ - mao= obt->mat[actcol-1]; + mao = obt->mat[actcol - 1]; if (mao) mao->id.us--; - for (a=actcol; a<obt->totcol; a++) { - obt->mat[a-1]= obt->mat[a]; - obt->matbits[a-1]= obt->matbits[a]; + for (a = actcol; a < obt->totcol; a++) { + obt->mat[a - 1] = obt->mat[a]; + obt->matbits[a - 1] = obt->matbits[a]; } obt->totcol--; - if (obt->actcol > obt->totcol) obt->actcol= obt->totcol; + if (obt->actcol > obt->totcol) obt->actcol = obt->totcol; - if (obt->totcol==0) { + if (obt->totcol == 0) { MEM_freeN(obt->mat); MEM_freeN(obt->matbits); - obt->mat= NULL; - obt->matbits= NULL; + obt->mat = NULL; + obt->matbits = NULL; } } - obt= obt->id.next; + obt = obt->id.next; } /* check indices from mesh */ if (ELEM4(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT)) { - data_delete_material_index_id((ID *)ob->data, actcol-1); - freedisplist(&ob->disp); + data_delete_material_index_id((ID *)ob->data, actcol - 1); + BKE_displist_free(&ob->disp); } return TRUE; @@ -1183,253 +1183,253 @@ int object_remove_material_slot(Object *ob) /* r_col = current value, col = new value, fac==0 is no change */ void ramp_blend(int type, float r_col[3], const float fac, const float col[3]) { - float tmp, facm= 1.0f-fac; + float tmp, facm = 1.0f - fac; switch (type) { case MA_RAMP_BLEND: - r_col[0] = facm*(r_col[0]) + fac*col[0]; - r_col[1] = facm*(r_col[1]) + fac*col[1]; - r_col[2] = facm*(r_col[2]) + fac*col[2]; + r_col[0] = facm * (r_col[0]) + fac * col[0]; + r_col[1] = facm * (r_col[1]) + fac * col[1]; + r_col[2] = facm * (r_col[2]) + fac * col[2]; break; case MA_RAMP_ADD: - r_col[0] += fac*col[0]; - r_col[1] += fac*col[1]; - r_col[2] += fac*col[2]; + r_col[0] += fac * col[0]; + r_col[1] += fac * col[1]; + r_col[2] += fac * col[2]; break; case MA_RAMP_MULT: - r_col[0] *= (facm + fac*col[0]); - r_col[1] *= (facm + fac*col[1]); - r_col[2] *= (facm + fac*col[2]); + r_col[0] *= (facm + fac * col[0]); + r_col[1] *= (facm + fac * col[1]); + r_col[2] *= (facm + fac * col[2]); break; case MA_RAMP_SCREEN: - r_col[0] = 1.0f - (facm + fac*(1.0f - col[0])) * (1.0f - r_col[0]); - r_col[1] = 1.0f - (facm + fac*(1.0f - col[1])) * (1.0f - r_col[1]); - r_col[2] = 1.0f - (facm + fac*(1.0f - col[2])) * (1.0f - r_col[2]); + r_col[0] = 1.0f - (facm + fac * (1.0f - col[0])) * (1.0f - r_col[0]); + r_col[1] = 1.0f - (facm + fac * (1.0f - col[1])) * (1.0f - r_col[1]); + r_col[2] = 1.0f - (facm + fac * (1.0f - col[2])) * (1.0f - r_col[2]); break; case MA_RAMP_OVERLAY: if (r_col[0] < 0.5f) - r_col[0] *= (facm + 2.0f*fac*col[0]); + r_col[0] *= (facm + 2.0f * fac * col[0]); else - r_col[0] = 1.0f - (facm + 2.0f*fac*(1.0f - col[0])) * (1.0f - r_col[0]); + r_col[0] = 1.0f - (facm + 2.0f * fac * (1.0f - col[0])) * (1.0f - r_col[0]); if (r_col[1] < 0.5f) - r_col[1] *= (facm + 2.0f*fac*col[1]); + r_col[1] *= (facm + 2.0f * fac * col[1]); else - r_col[1] = 1.0f - (facm + 2.0f*fac*(1.0f - col[1])) * (1.0f - r_col[1]); + r_col[1] = 1.0f - (facm + 2.0f * fac * (1.0f - col[1])) * (1.0f - r_col[1]); if (r_col[2] < 0.5f) - r_col[2] *= (facm + 2.0f*fac*col[2]); + r_col[2] *= (facm + 2.0f * fac * col[2]); else - r_col[2] = 1.0f - (facm + 2.0f*fac*(1.0f - col[2])) * (1.0f - r_col[2]); + r_col[2] = 1.0f - (facm + 2.0f * fac * (1.0f - col[2])) * (1.0f - r_col[2]); break; case MA_RAMP_SUB: - r_col[0] -= fac*col[0]; - r_col[1] -= fac*col[1]; - r_col[2] -= fac*col[2]; + r_col[0] -= fac * col[0]; + r_col[1] -= fac * col[1]; + r_col[2] -= fac * col[2]; break; case MA_RAMP_DIV: - if (col[0]!=0.0f) - r_col[0] = facm*(r_col[0]) + fac*(r_col[0])/col[0]; - if (col[1]!=0.0f) - r_col[1] = facm*(r_col[1]) + fac*(r_col[1])/col[1]; - if (col[2]!=0.0f) - r_col[2] = facm*(r_col[2]) + fac*(r_col[2])/col[2]; + if (col[0] != 0.0f) + r_col[0] = facm * (r_col[0]) + fac * (r_col[0]) / col[0]; + if (col[1] != 0.0f) + r_col[1] = facm * (r_col[1]) + fac * (r_col[1]) / col[1]; + if (col[2] != 0.0f) + r_col[2] = facm * (r_col[2]) + fac * (r_col[2]) / col[2]; break; case MA_RAMP_DIFF: - r_col[0] = facm*(r_col[0]) + fac*fabsf(r_col[0]-col[0]); - r_col[1] = facm*(r_col[1]) + fac*fabsf(r_col[1]-col[1]); - r_col[2] = facm*(r_col[2]) + fac*fabsf(r_col[2]-col[2]); + r_col[0] = facm * (r_col[0]) + fac *fabsf(r_col[0] - col[0]); + r_col[1] = facm * (r_col[1]) + fac *fabsf(r_col[1] - col[1]); + r_col[2] = facm * (r_col[2]) + fac *fabsf(r_col[2] - col[2]); break; case MA_RAMP_DARK: - tmp=col[0]+((1-col[0])*facm); - if (tmp < r_col[0]) r_col[0]= tmp; - tmp=col[1]+((1-col[1])*facm); - if (tmp < r_col[1]) r_col[1]= tmp; - tmp=col[2]+((1-col[2])*facm); - if (tmp < r_col[2]) r_col[2]= tmp; + tmp = col[0] + ((1 - col[0]) * facm); + if (tmp < r_col[0]) r_col[0] = tmp; + tmp = col[1] + ((1 - col[1]) * facm); + if (tmp < r_col[1]) r_col[1] = tmp; + tmp = col[2] + ((1 - col[2]) * facm); + if (tmp < r_col[2]) r_col[2] = tmp; break; case MA_RAMP_LIGHT: - tmp= fac*col[0]; - if (tmp > r_col[0]) r_col[0]= tmp; - tmp= fac*col[1]; - if (tmp > r_col[1]) r_col[1]= tmp; - tmp= fac*col[2]; - if (tmp > r_col[2]) r_col[2]= tmp; - break; + tmp = fac * col[0]; + if (tmp > r_col[0]) r_col[0] = tmp; + tmp = fac * col[1]; + if (tmp > r_col[1]) r_col[1] = tmp; + tmp = fac * col[2]; + if (tmp > r_col[2]) r_col[2] = tmp; + break; case MA_RAMP_DODGE: if (r_col[0] != 0.0f) { - tmp = 1.0f - fac*col[0]; + tmp = 1.0f - fac * col[0]; if (tmp <= 0.0f) r_col[0] = 1.0f; - else if ((tmp = (r_col[0]) / tmp)> 1.0f) + else if ((tmp = (r_col[0]) / tmp) > 1.0f) r_col[0] = 1.0f; else r_col[0] = tmp; } if (r_col[1] != 0.0f) { - tmp = 1.0f - fac*col[1]; - if (tmp <= 0.0f ) + tmp = 1.0f - fac * col[1]; + if (tmp <= 0.0f) r_col[1] = 1.0f; - else if ((tmp = (r_col[1]) / tmp) > 1.0f ) + else if ((tmp = (r_col[1]) / tmp) > 1.0f) r_col[1] = 1.0f; else r_col[1] = tmp; } if (r_col[2] != 0.0f) { - tmp = 1.0f - fac*col[2]; + tmp = 1.0f - fac * col[2]; if (tmp <= 0.0f) r_col[2] = 1.0f; - else if ((tmp = (r_col[2]) / tmp) > 1.0f ) + else if ((tmp = (r_col[2]) / tmp) > 1.0f) r_col[2] = 1.0f; else r_col[2] = tmp; } break; case MA_RAMP_BURN: - tmp = facm + fac*col[0]; + tmp = facm + fac * col[0]; if (tmp <= 0.0f) r_col[0] = 0.0f; - else if (( tmp = (1.0f - (1.0f - (r_col[0])) / tmp )) < 0.0f) - r_col[0] = 0.0f; + else if ((tmp = (1.0f - (1.0f - (r_col[0])) / tmp)) < 0.0f) + r_col[0] = 0.0f; else if (tmp > 1.0f) - r_col[0]=1.0f; + r_col[0] = 1.0f; else r_col[0] = tmp; - tmp = facm + fac*col[1]; + tmp = facm + fac * col[1]; if (tmp <= 0.0f) r_col[1] = 0.0f; - else if (( tmp = (1.0f - (1.0f - (r_col[1])) / tmp )) < 0.0f ) - r_col[1] = 0.0f; - else if (tmp >1.0f) - r_col[1]=1.0f; + else if ((tmp = (1.0f - (1.0f - (r_col[1])) / tmp)) < 0.0f) + r_col[1] = 0.0f; + else if (tmp > 1.0f) + r_col[1] = 1.0f; else r_col[1] = tmp; - tmp = facm + fac*col[2]; - if (tmp <= 0.0f) + tmp = facm + fac * col[2]; + if (tmp <= 0.0f) + r_col[2] = 0.0f; + else if ((tmp = (1.0f - (1.0f - (r_col[2])) / tmp)) < 0.0f) r_col[2] = 0.0f; - else if (( tmp = (1.0f - (1.0f - (r_col[2])) / tmp )) < 0.0f ) - r_col[2] = 0.0f; - else if (tmp >1.0f) - r_col[2]= 1.0f; + else if (tmp > 1.0f) + r_col[2] = 1.0f; else r_col[2] = tmp; break; case MA_RAMP_HUE: - { - float rH, rS, rV; - float colH, colS, colV; - float tmpr, tmpg, tmpb; - rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); - if (colS != 0) { - rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV); - hsv_to_rgb(colH, rS, rV, &tmpr, &tmpg, &tmpb); - r_col[0] = facm*(r_col[0]) + fac*tmpr; - r_col[1] = facm*(r_col[1]) + fac*tmpg; - r_col[2] = facm*(r_col[2]) + fac*tmpb; - } - } - break; - case MA_RAMP_SAT: - { - float rH, rS, rV; - float colH, colS, colV; + { + float rH, rS, rV; + float colH, colS, colV; + float tmpr, tmpg, tmpb; + rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); + if (colS != 0) { rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV); - if (rS != 0) { - rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); - hsv_to_rgb(rH, (facm*rS +fac*colS), rV, r_col+0, r_col+1, r_col+2); - } + hsv_to_rgb(colH, rS, rV, &tmpr, &tmpg, &tmpb); + r_col[0] = facm * (r_col[0]) + fac * tmpr; + r_col[1] = facm * (r_col[1]) + fac * tmpg; + r_col[2] = facm * (r_col[2]) + fac * tmpb; } - break; - case MA_RAMP_VAL: - { - float rH, rS, rV; - float colH, colS, colV; - rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV); + } + break; + case MA_RAMP_SAT: + { + float rH, rS, rV; + float colH, colS, colV; + rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV); + if (rS != 0) { rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); - hsv_to_rgb(rH, rS, (facm*rV +fac*colV), r_col+0, r_col+1, r_col+2); + hsv_to_rgb(rH, (facm * rS + fac * colS), rV, r_col + 0, r_col + 1, r_col + 2); } - break; + } + break; + case MA_RAMP_VAL: + { + float rH, rS, rV; + float colH, colS, colV; + rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV); + rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); + hsv_to_rgb(rH, rS, (facm * rV + fac * colV), r_col + 0, r_col + 1, r_col + 2); + } + break; case MA_RAMP_COLOR: - { - float rH, rS, rV; - float colH, colS, colV; - float tmpr, tmpg, tmpb; - rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); - if (colS != 0) { - rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV); - hsv_to_rgb(colH, colS, rV, &tmpr, &tmpg, &tmpb); - r_col[0] = facm*(r_col[0]) + fac*tmpr; - r_col[1] = facm*(r_col[1]) + fac*tmpg; - r_col[2] = facm*(r_col[2]) + fac*tmpb; - } + { + float rH, rS, rV; + float colH, colS, colV; + float tmpr, tmpg, tmpb; + rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); + if (colS != 0) { + rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV); + hsv_to_rgb(colH, colS, rV, &tmpr, &tmpg, &tmpb); + r_col[0] = facm * (r_col[0]) + fac * tmpr; + r_col[1] = facm * (r_col[1]) + fac * tmpg; + r_col[2] = facm * (r_col[2]) + fac * tmpb; } - break; + } + break; case MA_RAMP_SOFT: - { - float scr, scg, scb; + { + float scr, scg, scb; - /* first calculate non-fac based Screen mix */ - scr = 1.0f - (1.0f - col[0]) * (1.0f - r_col[0]); - scg = 1.0f - (1.0f - col[1]) * (1.0f - r_col[1]); - scb = 1.0f - (1.0f - col[2]) * (1.0f - r_col[2]); + /* first calculate non-fac based Screen mix */ + scr = 1.0f - (1.0f - col[0]) * (1.0f - r_col[0]); + scg = 1.0f - (1.0f - col[1]) * (1.0f - r_col[1]); + scb = 1.0f - (1.0f - col[2]) * (1.0f - r_col[2]); - r_col[0] = facm*(r_col[0]) + fac*(((1.0f - r_col[0]) * col[0] * (r_col[0])) + (r_col[0] * scr)); - r_col[1] = facm*(r_col[1]) + fac*(((1.0f - r_col[1]) * col[1] * (r_col[1])) + (r_col[1] * scg)); - r_col[2] = facm*(r_col[2]) + fac*(((1.0f - r_col[2]) * col[2] * (r_col[2])) + (r_col[2] * scb)); - } - break; + r_col[0] = facm * (r_col[0]) + fac * (((1.0f - r_col[0]) * col[0] * (r_col[0])) + (r_col[0] * scr)); + r_col[1] = facm * (r_col[1]) + fac * (((1.0f - r_col[1]) * col[1] * (r_col[1])) + (r_col[1] * scg)); + r_col[2] = facm * (r_col[2]) + fac * (((1.0f - r_col[2]) * col[2] * (r_col[2])) + (r_col[2] * scb)); + } + break; case MA_RAMP_LINEAR: if (col[0] > 0.5f) - r_col[0] = r_col[0] + fac*(2.0f*(col[0]-0.5f)); + r_col[0] = r_col[0] + fac * (2.0f * (col[0] - 0.5f)); else - r_col[0] = r_col[0] + fac*(2.0f*(col[0]) - 1.0f); + r_col[0] = r_col[0] + fac * (2.0f * (col[0]) - 1.0f); if (col[1] > 0.5f) - r_col[1] = r_col[1] + fac*(2.0f*(col[1]-0.5f)); + r_col[1] = r_col[1] + fac * (2.0f * (col[1] - 0.5f)); else - r_col[1] = r_col[1] + fac*(2.0f*(col[1]) -1.0f); + r_col[1] = r_col[1] + fac * (2.0f * (col[1]) - 1.0f); if (col[2] > 0.5f) - r_col[2] = r_col[2] + fac*(2.0f*(col[2]-0.5f)); + r_col[2] = r_col[2] + fac * (2.0f * (col[2] - 0.5f)); else - r_col[2] = r_col[2] + fac*(2.0f*(col[2]) - 1.0f); + r_col[2] = r_col[2] + fac * (2.0f * (col[2]) - 1.0f); break; } } /* copy/paste buffer, if we had a propper py api that would be better */ static Material matcopybuf; -static short matcopied= 0; +static short matcopied = 0; void clear_matcopybuf(void) { memset(&matcopybuf, 0, sizeof(Material)); - matcopied= 0; + matcopied = 0; } void free_matcopybuf(void) { int a; - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { if (matcopybuf.mtex[a]) { MEM_freeN(matcopybuf.mtex[a]); - matcopybuf.mtex[a]= NULL; + matcopybuf.mtex[a] = NULL; } } if (matcopybuf.ramp_col) MEM_freeN(matcopybuf.ramp_col); if (matcopybuf.ramp_spec) MEM_freeN(matcopybuf.ramp_spec); - matcopybuf.ramp_col= NULL; - matcopybuf.ramp_spec= NULL; + matcopybuf.ramp_col = NULL; + matcopybuf.ramp_spec = NULL; if (matcopybuf.nodetree) { ntreeFreeTree(matcopybuf.nodetree); MEM_freeN(matcopybuf.nodetree); - matcopybuf.nodetree= NULL; + matcopybuf.nodetree = NULL; } - matcopied= 0; + matcopied = 0; } void copy_matcopybuf(Material *ma) @@ -1441,19 +1441,19 @@ void copy_matcopybuf(Material *ma) free_matcopybuf(); memcpy(&matcopybuf, ma, sizeof(Material)); - if (matcopybuf.ramp_col) matcopybuf.ramp_col= MEM_dupallocN(matcopybuf.ramp_col); - if (matcopybuf.ramp_spec) matcopybuf.ramp_spec= MEM_dupallocN(matcopybuf.ramp_spec); + if (matcopybuf.ramp_col) matcopybuf.ramp_col = MEM_dupallocN(matcopybuf.ramp_col); + if (matcopybuf.ramp_spec) matcopybuf.ramp_spec = MEM_dupallocN(matcopybuf.ramp_spec); - for (a=0; a<MAX_MTEX; a++) { - mtex= matcopybuf.mtex[a]; + for (a = 0; a < MAX_MTEX; a++) { + mtex = matcopybuf.mtex[a]; if (mtex) { - matcopybuf.mtex[a]= MEM_dupallocN(mtex); + matcopybuf.mtex[a] = MEM_dupallocN(mtex); } } - matcopybuf.nodetree= ntreeCopyTree(ma->nodetree); - matcopybuf.preview= NULL; - matcopybuf.gpumaterial.first= matcopybuf.gpumaterial.last= NULL; - matcopied= 1; + matcopybuf.nodetree = ntreeCopyTree(ma->nodetree); + matcopybuf.preview = NULL; + matcopybuf.gpumaterial.first = matcopybuf.gpumaterial.last = NULL; + matcopied = 1; } void paste_matcopybuf(Material *ma) @@ -1462,13 +1462,13 @@ void paste_matcopybuf(Material *ma) MTex *mtex; ID id; - if (matcopied==0) + if (matcopied == 0) return; /* free current mat */ if (ma->ramp_col) MEM_freeN(ma->ramp_col); if (ma->ramp_spec) MEM_freeN(ma->ramp_spec); - for (a=0; a<MAX_MTEX; a++) { - mtex= ma->mtex[a]; + for (a = 0; a < MAX_MTEX; a++) { + mtex = ma->mtex[a]; if (mtex && mtex->tex) mtex->tex->id.us--; if (mtex) MEM_freeN(mtex); } @@ -1480,22 +1480,22 @@ void paste_matcopybuf(Material *ma) GPU_material_free(ma); - id= (ma->id); + id = (ma->id); memcpy(ma, &matcopybuf, sizeof(Material)); - (ma->id)= id; + (ma->id) = id; - if (matcopybuf.ramp_col) ma->ramp_col= MEM_dupallocN(matcopybuf.ramp_col); - if (matcopybuf.ramp_spec) ma->ramp_spec= MEM_dupallocN(matcopybuf.ramp_spec); + if (matcopybuf.ramp_col) ma->ramp_col = MEM_dupallocN(matcopybuf.ramp_col); + if (matcopybuf.ramp_spec) ma->ramp_spec = MEM_dupallocN(matcopybuf.ramp_spec); - for (a=0; a<MAX_MTEX; a++) { - mtex= ma->mtex[a]; + for (a = 0; a < MAX_MTEX; a++) { + mtex = ma->mtex[a]; if (mtex) { - ma->mtex[a]= MEM_dupallocN(mtex); + ma->mtex[a] = MEM_dupallocN(mtex); if (mtex->tex) id_us_plus((ID *)mtex->tex); } } - ma->nodetree= ntreeCopyTree(matcopybuf.nodetree); + ma->nodetree = ntreeCopyTree(matcopybuf.nodetree); } @@ -1531,7 +1531,7 @@ static int encode_tfaceflag(MTFace *tf, int convertall) static void decode_tfaceflag(Material *ma, int flag, int convertall) { int alphablend; - GameSettings *game= &ma->game; + GameSettings *game = &ma->game; /* flag is shifted in 1 to make 0 != no flag yet (see encode_tfaceflag) */ flag -= 1; @@ -1540,7 +1540,7 @@ static void decode_tfaceflag(Material *ma, int flag, int convertall) (*game).flag = 0; /* General Material Options */ - if ((flag & TF_DYNAMIC)==0) (*game).flag |= GEMAT_NOPHYSICS; + if ((flag & TF_DYNAMIC) == 0) (*game).flag |= GEMAT_NOPHYSICS; /* Material Offline Rendering Properties */ if (convertall) { @@ -1548,8 +1548,8 @@ static void decode_tfaceflag(Material *ma, int flag, int convertall) } /* Special Face Properties */ - if ((flag & TF_TWOSIDE)==0) (*game).flag |= GEMAT_BACKCULL; - if (flag & TF_INVISIBLE)(*game).flag |= GEMAT_INVISIBLE; + if ((flag & TF_TWOSIDE) == 0) (*game).flag |= GEMAT_BACKCULL; + if (flag & TF_INVISIBLE) (*game).flag |= GEMAT_INVISIBLE; if (flag & TF_BMFONT) (*game).flag |= GEMAT_TEXT; /* Face Orientation */ @@ -1571,7 +1571,7 @@ static int check_tfaceneedmaterial(int flag) // also if only flags are visible and collision see if all objects using this mesh have this option in physics /* flag is shifted in 1 to make 0 != no flag yet (see encode_tfaceflag) */ - flag -=1; + flag -= 1; // deprecated flags flag &= ~TF_OBCOL; @@ -1598,11 +1598,11 @@ static int check_tfaceneedmaterial(int flag) // XXX to be optmized or replaced by an equivalent blender internal function static int integer_getdigits(int number) { - int i=0; + int i = 0; if (number == 0) return 1; while (number != 0) { - number = (int)(number/10); + number = (int)(number / 10); i++; } return i; @@ -1616,7 +1616,7 @@ static void calculate_tface_materialname(char *matname, char *newname, int flag) int digits = integer_getdigits(flag); /* clamp the old name, remove the MA prefix and add the .TF.flag suffix * e.g. matname = "MALoooooooooooooongName"; newname = "Loooooooooooooon.TF.2" */ - BLI_snprintf(newname, MAX_ID_NAME, "%.*s.TF.%0*d", MAX_ID_NAME-(digits+5), matname, digits, flag); + BLI_snprintf(newname, MAX_ID_NAME, "%.*s.TF.%0*d", MAX_ID_NAME - (digits + 5), matname, digits, flag); } /* returns -1 if no match */ @@ -1624,7 +1624,7 @@ static short mesh_getmaterialnumber(Mesh *me, Material *ma) { short a; - for (a=0; a<me->totcol; a++) { + for (a = 0; a < me->totcol; a++) { if (me->mat[a] == ma) { return a; } @@ -1637,11 +1637,11 @@ static short mesh_getmaterialnumber(Mesh *me, Material *ma) static short mesh_addmaterial(Mesh *me, Material *ma) { material_append_id(&me->id, NULL); - me->mat[me->totcol-1]= ma; + me->mat[me->totcol - 1] = ma; id_us_plus(&ma->id); - return me->totcol-1; + return me->totcol - 1; } static void set_facetexture_flags(Material *ma, Image *image) @@ -1660,26 +1660,26 @@ static short convert_tfacenomaterial(Main *main, Mesh *me, MTFace *tf, int flag) { Material *ma; char idname[MAX_ID_NAME]; - short mat_nr= -1; + short mat_nr = -1; /* new material, the name uses the flag*/ BLI_snprintf(idname, sizeof(idname), "MAMaterial.TF.%0*d", integer_getdigits(flag), flag); - if ((ma= BLI_findstring(&main->mat, idname+2, offsetof(ID, name)+2))) { - mat_nr= mesh_getmaterialnumber(me, ma); + if ((ma = BLI_findstring(&main->mat, idname + 2, offsetof(ID, name) + 2))) { + mat_nr = mesh_getmaterialnumber(me, ma); /* assign the material to the mesh */ - if (mat_nr == -1) mat_nr= mesh_addmaterial(me, ma); + if (mat_nr == -1) mat_nr = mesh_addmaterial(me, ma); /* if needed set "Face Textures [Alpha]" Material options */ set_facetexture_flags(ma, tf->tpage); } /* create a new material */ else { - ma= add_material(idname+2); + ma = BKE_material_add(idname + 2); if (ma) { - printf("TexFace Convert: Material \"%s\" created.\n", idname+2); - mat_nr= mesh_addmaterial(me, ma); + printf("TexFace Convert: Material \"%s\" created.\n", idname + 2); + mat_nr = mesh_addmaterial(me, ma); /* if needed set "Face Textures [Alpha]" Material options */ set_facetexture_flags(ma, tf->tpage); @@ -1691,7 +1691,7 @@ static short convert_tfacenomaterial(Main *main, Mesh *me, MTFace *tf, int flag) ma->game.flag = -flag; id_us_min((ID *)ma); } - else printf("Error: Unable to create Material \"%s\" for Mesh \"%s\".", idname+2, me->id.name+2); + else printf("Error: Unable to create Material \"%s\" for Mesh \"%s\".", idname + 2, me->id.name + 2); } /* set as converted, no need to go bad to this face */ @@ -1712,49 +1712,49 @@ static void convert_tfacematerial(Main *main, Material *ma) CustomDataLayer *cdl; char idname[MAX_ID_NAME]; - for (me=main->mesh.first; me; me=me->id.next) { + for (me = main->mesh.first; me; me = me->id.next) { /* check if this mesh uses this material */ - for (a=0;a<me->totcol;a++) + for (a = 0; a < me->totcol; a++) if (me->mat[a] == ma) break; /* no material found */ if (a == me->totcol) continue; /* get the active tface layer */ - index= CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); - cdl= (index == -1)? NULL: &me->fdata.layers[index]; + index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); + cdl = (index == -1) ? NULL : &me->fdata.layers[index]; if (!cdl) continue; /* loop over all the faces and stop at the ones that use the material*/ - for (a=0, mf=me->mface; a<me->totface; a++, mf++) { + for (a = 0, mf = me->mface; a < me->totface; a++, mf++) { if (me->mat[mf->mat_nr] != ma) continue; /* texface data for this face */ - tf = ((MTFace*)cdl->data) + a; + tf = ((MTFace *)cdl->data) + a; flag = encode_tfaceflag(tf, 1); /* the name of the new material */ calculate_tface_materialname(ma->id.name, (char *)&idname, flag); - if ((mat_new= BLI_findstring(&main->mat, idname+2, offsetof(ID, name)+2))) { + if ((mat_new = BLI_findstring(&main->mat, idname + 2, offsetof(ID, name) + 2))) { /* material already existent, see if the mesh has it */ mat_nr = mesh_getmaterialnumber(me, mat_new); /* material is not in the mesh, add it */ - if (mat_nr == -1) mat_nr= mesh_addmaterial(me, mat_new); + if (mat_nr == -1) mat_nr = mesh_addmaterial(me, mat_new); } /* create a new material */ else { - mat_new=copy_material(ma); + mat_new = BKE_material_copy(ma); if (mat_new) { /* rename the material*/ strcpy(mat_new->id.name, idname); id_us_min((ID *)mat_new); - mat_nr= mesh_addmaterial(me, mat_new); + mat_nr = mesh_addmaterial(me, mat_new); decode_tfaceflag(mat_new, flag, 1); } else { - printf("Error: Unable to create Material \"%s\" for Mesh \"%s.", idname+2, me->id.name+2); + printf("Error: Unable to create Material \"%s\" for Mesh \"%s.", idname + 2, me->id.name + 2); mat_nr = mf->mat_nr; continue; } @@ -1771,8 +1771,8 @@ static void convert_tfacematerial(Main *main, Material *ma) mf->mat_nr = mat_nr; } /* remove material from mesh */ - for (a=0;a<me->totcol;) - if (me->mat[a] == ma) material_pop_id(&me->id, a, 1);else a++; + for (a = 0; a < me->totcol; ) + if (me->mat[a] == ma) material_pop_id(&me->id, a, 1); else a++; } } @@ -1806,20 +1806,20 @@ int do_version_tface(Main *main, int fileload) */ /* 1st part: marking mesh materials to update */ - for (me=main->mesh.first; me; me=me->id.next) { + for (me = main->mesh.first; me; me = me->id.next) { if (me->id.lib) continue; /* get the active tface layer */ - index= CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); - cdl= (index == -1)? NULL: &me->fdata.layers[index]; + index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); + cdl = (index == -1) ? NULL : &me->fdata.layers[index]; if (!cdl) continue; - nomaterialslots = (me->totcol==0?1:0); + nomaterialslots = (me->totcol == 0 ? 1 : 0); /* loop over all the faces*/ - for (a=0, mf=me->mface; a<me->totface; a++, mf++) { + for (a = 0, mf = me->mface; a < me->totface; a++, mf++) { /* texface data for this face */ - tf = ((MTFace*)cdl->data) + a; + tf = ((MTFace *)cdl->data) + a; /* conversion should happen only once */ if (fileload) @@ -1835,7 +1835,7 @@ int do_version_tface(Main *main, int fileload) /* create/find a new material and assign to the face */ if (check_tfaceneedmaterial(flag)) { - mf->mat_nr= convert_tfacenomaterial(main, me, tf, flag); + mf->mat_nr = convert_tfacenomaterial(main, me, tf, flag); } /* else mark them as no-material to be reverted to 0 later */ else { @@ -1843,7 +1843,7 @@ int do_version_tface(Main *main, int fileload) } } else if (mf->mat_nr < me->totcol) { - ma= me->mat[mf->mat_nr]; + ma = me->mat[mf->mat_nr]; /* no material create one if necessary */ if (!ma) { @@ -1852,7 +1852,7 @@ int do_version_tface(Main *main, int fileload) /* create/find a new material and assign to the face */ if (check_tfaceneedmaterial(flag)) - mf->mat_nr= convert_tfacenomaterial(main, me, tf, flag); + mf->mat_nr = convert_tfacenomaterial(main, me, tf, flag); continue; } @@ -1870,11 +1870,11 @@ int do_version_tface(Main *main, int fileload) /* found a material */ else { - flag = encode_tfaceflag(tf, ((fileload)?0:1)); + flag = encode_tfaceflag(tf, ((fileload) ? 0 : 1)); /* first time changing this material */ if (ma->game.flag == 0) - ma->game.flag= -flag; + ma->game.flag = -flag; /* mark material as disputed */ else if (ma->game.flag != -flag) { @@ -1903,18 +1903,18 @@ int do_version_tface(Main *main, int fileload) /* if we didn't have material slot and now we do, we need to * make sure the materials are correct */ if (nomaterialslots) { - if (me->totcol>0) { - for (a=0, mf=me->mface; a<me->totface; a++, mf++) { + if (me->totcol > 0) { + for (a = 0, mf = me->mface; a < me->totface; a++, mf++) { if (mf->mat_nr == -1) { /* texface data for this face */ - tf = ((MTFace*)cdl->data) + a; - mf->mat_nr= convert_tfacenomaterial(main, me, tf, encode_tfaceflag(tf, 1)); + tf = ((MTFace *)cdl->data) + a; + mf->mat_nr = convert_tfacenomaterial(main, me, tf, encode_tfaceflag(tf, 1)); } } } else { - for (a=0, mf=me->mface; a<me->totface; a++, mf++) { - mf->mat_nr=0; + for (a = 0, mf = me->mface; a < me->totface; a++, mf++) { + mf->mat_nr = 0; } } } @@ -1925,14 +1925,14 @@ int do_version_tface(Main *main, int fileload) /* skip library files */ /* we shouldn't loop through the materials created in the loop. make the loop stop at its original length) */ - for (ma= main->mat.first, a=0; ma; ma= ma->id.next, a++) { + for (ma = main->mat.first, a = 0; ma; ma = ma->id.next, a++) { if (ma->id.lib) continue; /* disputed material */ if (ma->game.flag == MAT_BGE_DISPUTED) { ma->game.flag = 0; if (fileload) { - printf("Warning: material \"%s\" skipped - to convert old game texface to material go to the Help menu.\n", ma->id.name+2); + printf("Warning: material \"%s\" skipped - to convert old game texface to material go to the Help menu.\n", ma->id.name + 2); nowarning = 0; } else @@ -1948,24 +1948,24 @@ int do_version_tface(Main *main, int fileload) /* material is good make sure all faces using * this material are set to converted */ if (fileload) { - for (me=main->mesh.first; me; me=me->id.next) { + for (me = main->mesh.first; me; me = me->id.next) { /* check if this mesh uses this material */ - for (a=0;a<me->totcol;a++) + for (a = 0; a < me->totcol; a++) if (me->mat[a] == ma) break; /* no material found */ if (a == me->totcol) continue; /* get the active tface layer */ - index= CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); - cdl= (index == -1)? NULL: &me->fdata.layers[index]; + index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); + cdl = (index == -1) ? NULL : &me->fdata.layers[index]; if (!cdl) continue; /* loop over all the faces and stop at the ones that use the material*/ - for (a=0, mf=me->mface; a<me->totface; a++, mf++) { + for (a = 0, mf = me->mface; a < me->totface; a++, mf++) { if (me->mat[mf->mat_nr] == ma) { /* texface data for this face */ - tf = ((MTFace*)cdl->data) + a; + tf = ((MTFace *)cdl->data) + a; tf->mode |= TF_CONVERTED; } } diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index 8b2e66812c7..8075aaa21d3 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -67,67 +67,67 @@ /* Data types */ -typedef struct point { /* a three-dimensional point */ - float x, y, z; /* its coordinates */ +typedef struct point { /* a three-dimensional point */ + float x, y, z; /* its coordinates */ } MB_POINT; -typedef struct vertex { /* surface vertex */ - MB_POINT position, normal; /* position and surface normal */ +typedef struct vertex { /* surface vertex */ + MB_POINT position, normal; /* position and surface normal */ } VERTEX; -typedef struct vertices { /* list of vertices in polygonization */ - int count, max; /* # vertices, max # allowed */ - VERTEX *ptr; /* dynamically allocated */ +typedef struct vertices { /* list of vertices in polygonization */ + int count, max; /* # vertices, max # allowed */ + VERTEX *ptr; /* dynamically allocated */ } VERTICES; -typedef struct corner { /* corner of a cube */ - int i, j, k; /* (i, j, k) is index within lattice */ - float x, y, z, value; /* location and function value */ +typedef struct corner { /* corner of a cube */ + int i, j, k; /* (i, j, k) is index within lattice */ + float x, y, z, value; /* location and function value */ struct corner *next; } CORNER; -typedef struct cube { /* partitioning cell (cube) */ - int i, j, k; /* lattice location of cube */ - CORNER *corners[8]; /* eight corners */ +typedef struct cube { /* partitioning cell (cube) */ + int i, j, k; /* lattice location of cube */ + CORNER *corners[8]; /* eight corners */ } CUBE; -typedef struct cubes { /* linked list of cubes acting as stack */ - CUBE cube; /* a single cube */ - struct cubes *next; /* remaining elements */ +typedef struct cubes { /* linked list of cubes acting as stack */ + CUBE cube; /* a single cube */ + struct cubes *next; /* remaining elements */ } CUBES; -typedef struct centerlist { /* list of cube locations */ - int i, j, k; /* cube location */ - struct centerlist *next; /* remaining elements */ +typedef struct centerlist { /* list of cube locations */ + int i, j, k; /* cube location */ + struct centerlist *next; /* remaining elements */ } CENTERLIST; -typedef struct edgelist { /* list of edges */ - int i1, j1, k1, i2, j2, k2; /* edge corner ids */ - int vid; /* vertex id */ - struct edgelist *next; /* remaining elements */ +typedef struct edgelist { /* list of edges */ + int i1, j1, k1, i2, j2, k2; /* edge corner ids */ + int vid; /* vertex id */ + struct edgelist *next; /* remaining elements */ } EDGELIST; -typedef struct intlist { /* list of integers */ - int i; /* an integer */ - struct intlist *next; /* remaining elements */ +typedef struct intlist { /* list of integers */ + int i; /* an integer */ + struct intlist *next; /* remaining elements */ } INTLIST; -typedef struct intlists { /* list of list of integers */ - INTLIST *list; /* a list of integers */ - struct intlists *next; /* remaining elements */ +typedef struct intlists { /* list of list of integers */ + INTLIST *list; /* a list of integers */ + struct intlists *next; /* remaining elements */ } INTLISTS; -typedef struct process { /* parameters, function, storage */ +typedef struct process { /* parameters, function, storage */ /* what happens here? floats, I think. */ /* float (*function)(void); */ /* implicit surface function */ float (*function)(float, float, float); - float size, delta; /* cube size, normal delta */ - int bounds; /* cube range within lattice */ - CUBES *cubes; /* active cubes */ - VERTICES vertices; /* surface vertices */ - CENTERLIST **centers; /* cube center hash table */ - CORNER **corners; /* corner value hash table */ - EDGELIST **edges; /* edge and vertex id hash table */ + float size, delta; /* cube size, normal delta */ + int bounds; /* cube range within lattice */ + CUBES *cubes; /* active cubes */ + VERTICES vertices; /* surface vertices */ + CENTERLIST **centers; /* cube center hash table */ + CORNER **corners; /* corner value hash table */ + EDGELIST **edges; /* edge and vertex id hash table */ } PROCESS; /* dividing scene using octal tree makes polygonisation faster */ @@ -137,20 +137,20 @@ typedef struct ml_pointer { } ml_pointer; typedef struct octal_node { - struct octal_node *nodes[8]; /* children of current node */ - struct octal_node *parent; /* parent of current node */ - struct ListBase elems; /* ListBase of MetaElem pointers (ml_pointer) */ - float x_min, y_min, z_min; /* 1st border point */ - float x_max, y_max, z_max; /* 7th border point */ - float x, y, z; /* center of node */ - int pos, neg; /* number of positive and negative MetaElements in the node */ - int count; /* number of MetaElems, which belongs to the node */ + struct octal_node *nodes[8];/* children of current node */ + struct octal_node *parent; /* parent of current node */ + struct ListBase elems; /* ListBase of MetaElem pointers (ml_pointer) */ + float x_min, y_min, z_min; /* 1st border point */ + float x_max, y_max, z_max; /* 7th border point */ + float x, y, z; /* center of node */ + int pos, neg; /* number of positive and negative MetaElements in the node */ + int count; /* number of MetaElems, which belongs to the node */ } octal_node; typedef struct octal_tree { - struct octal_node *first; /* first node */ - int pos, neg; /* number of positive and negative MetaElements in the scene */ - short depth; /* number of scene subdivision */ + struct octal_node *first; /* first node */ + int pos, neg; /* number of positive and negative MetaElements in the scene */ + short depth; /* number of scene subdivision */ } octal_tree; struct pgn_elements { @@ -161,33 +161,33 @@ struct pgn_elements { /* Forward declarations */ static int vertid(CORNER *c1, CORNER *c2, PROCESS *p, MetaBall *mb); static int setcenter(CENTERLIST *table[], int i, int j, int k); -static CORNER *setcorner(PROCESS* p, int i, int j, int k); -static void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2, - float (*function)(float, float, float), MB_POINT *p, MetaBall *mb, int f); +static CORNER *setcorner(PROCESS *p, int i, int j, int k); +static void converge(MB_POINT *p1, MB_POINT *p2, float v1, float v2, + float (*function)(float, float, float), MB_POINT *p, MetaBall *mb, int f); /* Global variables */ -static float thresh= 0.6f; -static int totelem=0; +static float thresh = 0.6f; +static int totelem = 0; static MetaElem **mainb; static octal_tree *metaball_tree = NULL; /* Functions */ -void BKE_metaball_unlink(MetaBall *mb) +void BKE_mball_unlink(MetaBall *mb) { int a; - for (a=0; a<mb->totcol; a++) { + for (a = 0; a < mb->totcol; a++) { if (mb->mat[a]) mb->mat[a]->id.us--; - mb->mat[a]= NULL; + mb->mat[a] = NULL; } } /* do not free mball itself */ -void BKE_metaball_free(MetaBall *mb) +void BKE_mball_free(MetaBall *mb) { - BKE_metaball_unlink(mb); + BKE_mball_unlink(mb); if (mb->adt) { BKE_free_animdata((ID *)mb); @@ -196,42 +196,42 @@ void BKE_metaball_free(MetaBall *mb) if (mb->mat) MEM_freeN(mb->mat); if (mb->bb) MEM_freeN(mb->bb); BLI_freelistN(&mb->elems); - if (mb->disp.first) freedisplist(&mb->disp); + if (mb->disp.first) BKE_displist_free(&mb->disp); } -MetaBall *BKE_metaball_add(const char *name) +MetaBall *BKE_mball_add(const char *name) { MetaBall *mb; - mb= alloc_libblock(&G.main->mball, ID_MB, name); + mb = BKE_libblock_alloc(&G.main->mball, ID_MB, name); - mb->size[0]= mb->size[1]= mb->size[2]= 1.0; - mb->texflag= MB_AUTOSPACE; + mb->size[0] = mb->size[1] = mb->size[2] = 1.0; + mb->texflag = MB_AUTOSPACE; - mb->wiresize= 0.4f; - mb->rendersize= 0.2f; - mb->thresh= 0.6f; + mb->wiresize = 0.4f; + mb->rendersize = 0.2f; + mb->thresh = 0.6f; return mb; } -MetaBall *BKE_metaball_copy(MetaBall *mb) +MetaBall *BKE_mball_copy(MetaBall *mb) { MetaBall *mbn; int a; - mbn= copy_libblock(&mb->id); + mbn = BKE_libblock_copy(&mb->id); BLI_duplicatelist(&mbn->elems, &mb->elems); - mbn->mat= MEM_dupallocN(mb->mat); - for (a=0; a<mbn->totcol; a++) { + mbn->mat = MEM_dupallocN(mb->mat); + for (a = 0; a < mbn->totcol; a++) { id_us_plus((ID *)mbn->mat[a]); } - mbn->bb= MEM_dupallocN(mb->bb); + mbn->bb = MEM_dupallocN(mb->bb); - mbn->editelems= NULL; - mbn->lastelem= NULL; + mbn->editelems = NULL; + mbn->lastelem = NULL; return mbn; } @@ -243,29 +243,29 @@ static void extern_local_mball(MetaBall *mb) } } -void BKE_metaball_make_local(MetaBall *mb) +void BKE_mball_make_local(MetaBall *mb) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (mb->id.lib==NULL) return; - if (mb->id.us==1) { + if (mb->id.lib == NULL) return; + if (mb->id.us == 1) { id_clear_lib_data(bmain, &mb->id); extern_local_mball(mb); return; } - for (ob= G.main->object.first; ob && ELEM(0, is_lib, is_local); ob= ob->id.next) { + for (ob = G.main->object.first; ob && ELEM(0, is_lib, is_local); ob = ob->id.next) { if (ob->data == mb) { - if (ob->id.lib) is_lib= TRUE; - else is_local= TRUE; + if (ob->id.lib) is_lib = TRUE; + else is_local = TRUE; } } @@ -274,16 +274,16 @@ void BKE_metaball_make_local(MetaBall *mb) extern_local_mball(mb); } else if (is_local && is_lib) { - MetaBall *mb_new= BKE_metaball_copy(mb); - mb_new->id.us= 0; + MetaBall *mb_new = BKE_mball_copy(mb); + mb_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, mb->id.lib, &mb_new->id); - for (ob= G.main->object.first; ob; ob= ob->id.next) { + for (ob = G.main->object.first; ob; ob = ob->id.next) { if (ob->data == mb) { - if (ob->id.lib==NULL) { - ob->data= mb_new; + if (ob->id.lib == NULL) { + ob->data = mb_new; mb_new->id.us++; mb->id.us--; } @@ -294,46 +294,46 @@ void BKE_metaball_make_local(MetaBall *mb) /* most simple meta-element adding function * don't do context manipulation here (rna uses) */ -MetaElem *BKE_metaball_element_add(MetaBall *mb, const int type) +MetaElem *BKE_mball_element_add(MetaBall *mb, const int type) { - MetaElem *ml= MEM_callocN(sizeof(MetaElem), "metaelem"); + MetaElem *ml = MEM_callocN(sizeof(MetaElem), "metaelem"); unit_qt(ml->quat); - ml->rad= 2.0; - ml->s= 2.0; - ml->flag= MB_SCALE_RAD; + ml->rad = 2.0; + ml->s = 2.0; + ml->flag = MB_SCALE_RAD; switch (type) { - case MB_BALL: - ml->type = MB_BALL; - ml->expx= ml->expy= ml->expz= 1.0; - - break; - case MB_TUBE: - ml->type = MB_TUBE; - ml->expx= ml->expy= ml->expz= 1.0; - - break; - case MB_PLANE: - ml->type = MB_PLANE; - ml->expx= ml->expy= ml->expz= 1.0; - - break; - case MB_ELIPSOID: - ml->type = MB_ELIPSOID; - ml->expx= 1.2f; - ml->expy= 0.8f; - ml->expz= 1.0; - - break; - case MB_CUBE: - ml->type = MB_CUBE; - ml->expx= ml->expy= ml->expz= 1.0; + case MB_BALL: + ml->type = MB_BALL; + ml->expx = ml->expy = ml->expz = 1.0; + + break; + case MB_TUBE: + ml->type = MB_TUBE; + ml->expx = ml->expy = ml->expz = 1.0; + + break; + case MB_PLANE: + ml->type = MB_PLANE; + ml->expx = ml->expy = ml->expz = 1.0; + + break; + case MB_ELIPSOID: + ml->type = MB_ELIPSOID; + ml->expx = 1.2f; + ml->expy = 0.8f; + ml->expz = 1.0; + + break; + case MB_CUBE: + ml->type = MB_CUBE; + ml->expx = ml->expy = ml->expz = 1.0; - break; - default: - break; + break; + default: + break; } BLI_addtail(&mb->elems, ml); @@ -346,32 +346,32 @@ MetaElem *BKE_metaball_element_add(MetaBall *mb, const int type) * basic MetaBall (usually with name Meta). All other MetaBalls (with * names Meta.001, Meta.002, etc) are included in this Bounding Box. */ -void BKE_metaball_tex_space_calc(Object *ob) +void BKE_mball_texspace_calc(Object *ob) { DispList *dl; BoundBox *bb; float *data, min[3], max[3] /*, loc[3], size[3] */; - int tot, doit=0; + int tot, doit = 0; - if (ob->bb==NULL) ob->bb= MEM_callocN(sizeof(BoundBox), "mb boundbox"); - bb= ob->bb; + if (ob->bb == NULL) ob->bb = MEM_callocN(sizeof(BoundBox), "mb boundbox"); + bb = ob->bb; /* Weird one, this. */ -/* INIT_MINMAX(min, max); */ - (min)[0]= (min)[1]= (min)[2]= 1.0e30f; - (max)[0]= (max)[1]= (max)[2]= -1.0e30f; +/* INIT_MINMAX(min, max); */ + (min)[0] = (min)[1] = (min)[2] = 1.0e30f; + (max)[0] = (max)[1] = (max)[2] = -1.0e30f; - dl= ob->disp.first; + dl = ob->disp.first; while (dl) { - tot= dl->nr; - if (tot) doit= 1; - data= dl->verts; + tot = dl->nr; + if (tot) doit = 1; + data = dl->verts; while (tot--) { /* Also weird... but longer. From utildefines. */ DO_MINMAX(data, min, max); - data+= 3; + data += 3; } - dl= dl->next; + dl = dl->next; } if (!doit) { @@ -379,18 +379,18 @@ void BKE_metaball_tex_space_calc(Object *ob) max[0] = max[1] = max[2] = 1.0f; } #if 0 - loc[0]= (min[0]+max[0])/2.0f; - loc[1]= (min[1]+max[1])/2.0f; - loc[2]= (min[2]+max[2])/2.0f; - - size[0]= (max[0]-min[0])/2.0f; - size[1]= (max[1]-min[1])/2.0f; - size[2]= (max[2]-min[2])/2.0f; + loc[0] = (min[0] + max[0]) / 2.0f; + loc[1] = (min[1] + max[1]) / 2.0f; + loc[2] = (min[2] + max[2]) / 2.0f; + + size[0] = (max[0] - min[0]) / 2.0f; + size[1] = (max[1] - min[1]) / 2.0f; + size[2] = (max[2] - min[2]) / 2.0f; #endif - boundbox_set_from_min_max(bb, min, max); + BKE_boundbox_init_from_minmax(bb, min, max); } -float *BKE_metaball_make_orco(Object *ob, ListBase *dispbase) +float *BKE_mball_make_orco(Object *ob, ListBase *dispbase) { BoundBox *bb; DispList *dl; @@ -399,27 +399,27 @@ float *BKE_metaball_make_orco(Object *ob, ListBase *dispbase) int a; /* restore size and loc */ - bb= ob->bb; - loc[0]= (bb->vec[0][0]+bb->vec[4][0])/2.0f; - size[0]= bb->vec[4][0]-loc[0]; - loc[1]= (bb->vec[0][1]+bb->vec[2][1])/2.0f; - size[1]= bb->vec[2][1]-loc[1]; - loc[2]= (bb->vec[0][2]+bb->vec[1][2])/2.0f; - size[2]= bb->vec[1][2]-loc[2]; - - dl= dispbase->first; - orcodata= MEM_mallocN(sizeof(float)*3*dl->nr, "MballOrco"); - - data= dl->verts; - orco= orcodata; - a= dl->nr; + bb = ob->bb; + loc[0] = (bb->vec[0][0] + bb->vec[4][0]) / 2.0f; + size[0] = bb->vec[4][0] - loc[0]; + loc[1] = (bb->vec[0][1] + bb->vec[2][1]) / 2.0f; + size[1] = bb->vec[2][1] - loc[1]; + loc[2] = (bb->vec[0][2] + bb->vec[1][2]) / 2.0f; + size[2] = bb->vec[1][2] - loc[2]; + + dl = dispbase->first; + orcodata = MEM_mallocN(sizeof(float) * 3 * dl->nr, "MballOrco"); + + data = dl->verts; + orco = orcodata; + a = dl->nr; while (a--) { - orco[0]= (data[0]-loc[0])/size[0]; - orco[1]= (data[1]-loc[1])/size[1]; - orco[2]= (data[2]-loc[2])/size[2]; + orco[0] = (data[0] - loc[0]) / size[0]; + orco[1] = (data[1] - loc[1]) / size[1]; + orco[2] = (data[2] - loc[2]) / size[2]; - data+= 3; - orco+= 3; + data += 3; + orco += 3; } return orcodata; @@ -442,26 +442,26 @@ float *BKE_metaball_make_orco(Object *ob, ListBase *dispbase) * It test last character of Object ID name. If last character * is digit it return 0, else it return 1. */ -int BKE_metaball_is_basis(Object *ob) +int BKE_mball_is_basis(Object *ob) { int len; /* just a quick test */ - len= strlen(ob->id.name); - if ( isdigit(ob->id.name[len-1]) ) return 0; + len = strlen(ob->id.name); + if (isdigit(ob->id.name[len - 1]) ) return 0; return 1; } /* return nonzero if ob1 is a basis mball for ob */ -int BKE_metaball_is_basis_for(Object *ob1, Object *ob2) +int BKE_mball_is_basis_for(Object *ob1, Object *ob2) { int basis1nr, basis2nr; char basis1name[MAX_ID_NAME], basis2name[MAX_ID_NAME]; - BLI_split_name_num(basis1name, &basis1nr, ob1->id.name+2, '.'); - BLI_split_name_num(basis2name, &basis2nr, ob2->id.name+2, '.'); + BLI_split_name_num(basis1name, &basis1nr, ob1->id.name + 2, '.'); + BLI_split_name_num(basis2name, &basis2nr, ob2->id.name + 2, '.'); - if (!strcmp(basis1name, basis2name)) return BKE_metaball_is_basis(ob1); + if (!strcmp(basis1name, basis2name)) return BKE_mball_is_basis(ob1); else return 0; } @@ -471,36 +471,36 @@ int BKE_metaball_is_basis_for(Object *ob1, Object *ob2) * are copied to all metaballs in same "group" (metaballs with same base name: MBall, * MBall.001, MBall.002, etc). The most important is to copy properties to the base metaball, * because this metaball influence polygonisation of metaballs. */ -void BKE_metaball_properties_copy(Scene *scene, Object *active_object) +void BKE_mball_properties_copy(Scene *scene, Object *active_object) { - Scene *sce_iter= scene; + Scene *sce_iter = scene; Base *base; Object *ob; - MetaBall *active_mball = (MetaBall*)active_object->data; + MetaBall *active_mball = (MetaBall *)active_object->data; int basisnr, obnr; char basisname[MAX_ID_NAME], obname[MAX_ID_NAME]; - BLI_split_name_num(basisname, &basisnr, active_object->id.name+2, '.'); + BLI_split_name_num(basisname, &basisnr, active_object->id.name + 2, '.'); - /* XXX recursion check, see scene.c, just too simple code this next_object() */ - if (F_ERROR==next_object(&sce_iter, 0, NULL, NULL)) + /* XXX recursion check, see scene.c, just too simple code this BKE_scene_base_iter_next() */ + if (F_ERROR == BKE_scene_base_iter_next(&sce_iter, 0, NULL, NULL)) return; - while (next_object(&sce_iter, 1, &base, &ob)) { - if (ob->type==OB_MBALL) { + while (BKE_scene_base_iter_next(&sce_iter, 1, &base, &ob)) { + if (ob->type == OB_MBALL) { if (ob != active_object) { - BLI_split_name_num(obname, &obnr, ob->id.name+2, '.'); + BLI_split_name_num(obname, &obnr, ob->id.name + 2, '.'); /* Object ob has to be in same "group" ... it means, that it has to have * same base of its name */ - if (strcmp(obname, basisname)==0) { - MetaBall *mb= ob->data; + if (strcmp(obname, basisname) == 0) { + MetaBall *mb = ob->data; /* Copy properties from selected/edited metaball */ - mb->wiresize= active_mball->wiresize; - mb->rendersize= active_mball->rendersize; - mb->thresh= active_mball->thresh; - mb->flag= active_mball->flag; + mb->wiresize = active_mball->wiresize; + mb->rendersize = active_mball->rendersize; + mb->thresh = active_mball->thresh; + mb->flag = active_mball->flag; } } } @@ -516,52 +516,52 @@ void BKE_metaball_properties_copy(Scene *scene, Object *active_object) * * warning!, is_basis_mball() can fail on returned object, see long note above. */ -Object *BKE_metaball_basis_find(Scene *scene, Object *basis) +Object *BKE_mball_basis_find(Scene *scene, Object *basis) { - Scene *sce_iter= scene; + Scene *sce_iter = scene; Base *base; - Object *ob, *bob= basis; - MetaElem *ml=NULL; + Object *ob, *bob = basis; + MetaElem *ml = NULL; int basisnr, obnr; char basisname[MAX_ID_NAME], obname[MAX_ID_NAME]; - BLI_split_name_num(basisname, &basisnr, basis->id.name+2, '.'); - totelem= 0; + BLI_split_name_num(basisname, &basisnr, basis->id.name + 2, '.'); + totelem = 0; - /* XXX recursion check, see scene.c, just too simple code this next_object() */ - if (F_ERROR==next_object(&sce_iter, 0, NULL, NULL)) + /* XXX recursion check, see scene.c, just too simple code this BKE_scene_base_iter_next() */ + if (F_ERROR == BKE_scene_base_iter_next(&sce_iter, 0, NULL, NULL)) return NULL; - while (next_object(&sce_iter, 1, &base, &ob)) { + while (BKE_scene_base_iter_next(&sce_iter, 1, &base, &ob)) { - if (ob->type==OB_MBALL) { - if (ob==bob) { - MetaBall *mb= ob->data; + if (ob->type == OB_MBALL) { + if (ob == bob) { + MetaBall *mb = ob->data; /* if bob object is in edit mode, then dynamic list of all MetaElems * is stored in editelems */ - if (mb->editelems) ml= mb->editelems->first; + if (mb->editelems) ml = mb->editelems->first; /* if bob object is in object mode */ - else ml= mb->elems.first; + else ml = mb->elems.first; } else { - BLI_split_name_num(obname, &obnr, ob->id.name+2, '.'); + BLI_split_name_num(obname, &obnr, ob->id.name + 2, '.'); /* object ob has to be in same "group" ... it means, that it has to have * same base of its name */ - if (strcmp(obname, basisname)==0) { - MetaBall *mb= ob->data; + if (strcmp(obname, basisname) == 0) { + MetaBall *mb = ob->data; /* if object is in edit mode, then dynamic list of all MetaElems * is stored in editelems */ - if (mb->editelems) ml= mb->editelems->first; + if (mb->editelems) ml = mb->editelems->first; /* if bob object is in object mode */ - else ml= mb->elems.first; + else ml = mb->elems.first; if (obnr < basisnr) { if (!(ob->flag & OB_FROMDUPLI)) { - basis= ob; - basisnr= obnr; + basis = ob; + basisnr = obnr; } } } @@ -569,7 +569,7 @@ Object *BKE_metaball_basis_find(Scene *scene, Object *basis) while (ml) { if (!(ml->flag & MB_HIDE)) totelem++; - ml= ml->next; + ml = ml->next; } } } @@ -591,33 +591,33 @@ Object *BKE_metaball_basis_find(Scene *scene, Object *basis) * Permission is granted to reproduce, use and distribute this code for * any and all purposes, provided that this notice appears in all copies. */ -#define RES 12 /* # converge iterations */ - -#define L 0 /* left direction: -x, -i */ -#define R 1 /* right direction: +x, +i */ -#define B 2 /* bottom direction: -y, -j */ -#define T 3 /* top direction: +y, +j */ -#define N 4 /* near direction: -z, -k */ -#define F 5 /* far direction: +z, +k */ -#define LBN 0 /* left bottom near corner */ -#define LBF 1 /* left bottom far corner */ -#define LTN 2 /* left top near corner */ -#define LTF 3 /* left top far corner */ -#define RBN 4 /* right bottom near corner */ -#define RBF 5 /* right bottom far corner */ -#define RTN 6 /* right top near corner */ -#define RTF 7 /* right top far corner */ +#define RES 12 /* # converge iterations */ + +#define L 0 /* left direction: -x, -i */ +#define R 1 /* right direction: +x, +i */ +#define B 2 /* bottom direction: -y, -j */ +#define T 3 /* top direction: +y, +j */ +#define N 4 /* near direction: -z, -k */ +#define F 5 /* far direction: +z, +k */ +#define LBN 0 /* left bottom near corner */ +#define LBF 1 /* left bottom far corner */ +#define LTN 2 /* left top near corner */ +#define LTF 3 /* left top far corner */ +#define RBN 4 /* right bottom near corner */ +#define RBF 5 /* right bottom far corner */ +#define RTN 6 /* right top near corner */ +#define RTF 7 /* right top far corner */ /* the LBN corner of cube (i, j, k), corresponds with location * (i-0.5)*size, (j-0.5)*size, (k-0.5)*size) */ -#define HASHBIT (5) -#define HASHSIZE (size_t)(1<<(3*HASHBIT)) /*! < hash table size (32768) */ +#define HASHBIT (5) +#define HASHSIZE (size_t)(1 << (3 * HASHBIT)) /*! < hash table size (32768) */ -#define HASH(i, j, k) ((((( (i) & 31)<<5) | ( (j) & 31))<<5 ) | ( (k) & 31) ) +#define HASH(i, j, k) ((((( (i) & 31) << 5) | ( (j) & 31)) << 5) | ( (k) & 31) ) -#define MB_BIT(i, bit) (((i)>>(bit))&1) -#define FLIP(i, bit) ((i)^1<<(bit)) /* flip the given bit of i */ +#define MB_BIT(i, bit) (((i) >> (bit)) & 1) +#define FLIP(i, bit) ((i) ^ 1 << (bit)) /* flip the given bit of i */ /* **************** POLYGONIZATION ************************ */ @@ -634,78 +634,78 @@ static float densfunc(MetaElem *ball, float x, float y, float z) float dist2 = 0.0, dx, dy, dz; float vec[3]; - vec[0]= x; - vec[1]= y; - vec[2]= z; + vec[0] = x; + vec[1] = y; + vec[2] = z; mul_m4_v3((float (*)[4])ball->imat, vec); - dx= vec[0]; - dy= vec[1]; - dz= vec[2]; - - if (ball->type==MB_BALL) { - } - else if (ball->type==MB_TUBEX) { - if ( dx > ball->len) dx-= ball->len; - else if (dx< -ball->len) dx+= ball->len; - else dx= 0.0; - } - else if (ball->type==MB_TUBEY) { - if ( dy > ball->len) dy-= ball->len; - else if (dy< -ball->len) dy+= ball->len; - else dy= 0.0; - } - else if (ball->type==MB_TUBEZ) { - if ( dz > ball->len) dz-= ball->len; - else if (dz< -ball->len) dz+= ball->len; - else dz= 0.0; - } - else if (ball->type==MB_TUBE) { - if ( dx > ball->expx) dx-= ball->expx; - else if (dx< -ball->expx) dx+= ball->expx; - else dx= 0.0; - } - else if (ball->type==MB_PLANE) { - if ( dx > ball->expx) dx-= ball->expx; - else if (dx< -ball->expx) dx+= ball->expx; - else dx= 0.0; - if ( dy > ball->expy) dy-= ball->expy; - else if (dy< -ball->expy) dy+= ball->expy; - else dy= 0.0; - } - else if (ball->type==MB_ELIPSOID) { - dx *= 1/ball->expx; - dy *= 1/ball->expy; - dz *= 1/ball->expz; - } - else if (ball->type==MB_CUBE) { - if ( dx > ball->expx) dx-= ball->expx; - else if (dx< -ball->expx) dx+= ball->expx; - else dx= 0.0; - if ( dy > ball->expy) dy-= ball->expy; - else if (dy< -ball->expy) dy+= ball->expy; - else dy= 0.0; - if ( dz > ball->expz) dz-= ball->expz; - else if (dz< -ball->expz) dz+= ball->expz; - else dz= 0.0; - } - - dist2= (dx*dx + dy*dy + dz*dz); + dx = vec[0]; + dy = vec[1]; + dz = vec[2]; + + if (ball->type == MB_BALL) { + } + else if (ball->type == MB_TUBEX) { + if (dx > ball->len) dx -= ball->len; + else if (dx < -ball->len) dx += ball->len; + else dx = 0.0; + } + else if (ball->type == MB_TUBEY) { + if (dy > ball->len) dy -= ball->len; + else if (dy < -ball->len) dy += ball->len; + else dy = 0.0; + } + else if (ball->type == MB_TUBEZ) { + if (dz > ball->len) dz -= ball->len; + else if (dz < -ball->len) dz += ball->len; + else dz = 0.0; + } + else if (ball->type == MB_TUBE) { + if (dx > ball->expx) dx -= ball->expx; + else if (dx < -ball->expx) dx += ball->expx; + else dx = 0.0; + } + else if (ball->type == MB_PLANE) { + if (dx > ball->expx) dx -= ball->expx; + else if (dx < -ball->expx) dx += ball->expx; + else dx = 0.0; + if (dy > ball->expy) dy -= ball->expy; + else if (dy < -ball->expy) dy += ball->expy; + else dy = 0.0; + } + else if (ball->type == MB_ELIPSOID) { + dx *= 1 / ball->expx; + dy *= 1 / ball->expy; + dz *= 1 / ball->expz; + } + else if (ball->type == MB_CUBE) { + if (dx > ball->expx) dx -= ball->expx; + else if (dx < -ball->expx) dx += ball->expx; + else dx = 0.0; + if (dy > ball->expy) dy -= ball->expy; + else if (dy < -ball->expy) dy += ball->expy; + else dy = 0.0; + if (dz > ball->expz) dz -= ball->expz; + else if (dz < -ball->expz) dz += ball->expz; + else dz = 0.0; + } + + dist2 = (dx * dx + dy * dy + dz * dz); if (ball->flag & MB_NEGATIVE) { - dist2= 1.0f-(dist2/ball->rad2); + dist2 = 1.0f - (dist2 / ball->rad2); if (dist2 < 0.0f) return 0.5f; - return 0.5f-ball->s*dist2*dist2*dist2; + return 0.5f - ball->s * dist2 * dist2 * dist2; } else { - dist2= 1.0f-(dist2/ball->rad2); + dist2 = 1.0f - (dist2 / ball->rad2); if (dist2 < 0.0f) return -0.5f; - return ball->s*dist2*dist2*dist2 -0.5f; + return ball->s * dist2 * dist2 * dist2 - 0.5f; } } -static octal_node* find_metaball_octal_node(octal_node *node, float x, float y, float z, short depth) +static octal_node *find_metaball_octal_node(octal_node *node, float x, float y, float z, short depth) { if (!depth) return node; @@ -778,24 +778,24 @@ static float metaball(float x, float y, float z) { struct octal_node *node; struct ml_pointer *ml_p; - float dens=0; + float dens = 0; int a; if (totelem > 1) { - node= find_metaball_octal_node(metaball_tree->first, x, y, z, metaball_tree->depth); + node = find_metaball_octal_node(metaball_tree->first, x, y, z, metaball_tree->depth); if (node) { - ml_p= node->elems.first; + ml_p = node->elems.first; while (ml_p) { - dens+=densfunc(ml_p->ml, x, y, z); - ml_p= ml_p->next; + dens += densfunc(ml_p->ml, x, y, z); + ml_p = ml_p->next; } - dens+= -0.5f*(metaball_tree->pos - node->pos); - dens+= 0.5f*(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++) { + for (a = 0; a < totelem; a++) { dens += densfunc(mainb[a], x, y, z); } } @@ -809,7 +809,7 @@ static float metaball(float x, float y, float z) /* ******************************************** */ -static int *indices=NULL; +static int *indices = NULL; static int totindex, curindex; @@ -818,28 +818,28 @@ static void accum_mballfaces(int i1, int i2, int i3, int i4) int *newi, *cur; /* static int i=0; I would like to delete altogether, but I don't dare to, yet */ - if (totindex==curindex) { - totindex+= 256; - newi= MEM_mallocN(4*sizeof(int)*totindex, "vertindex"); + if (totindex == curindex) { + totindex += 256; + newi = MEM_mallocN(4 * sizeof(int) * totindex, "vertindex"); if (indices) { - memcpy(newi, indices, 4*sizeof(int)*(totindex-256)); + memcpy(newi, indices, 4 * sizeof(int) * (totindex - 256)); MEM_freeN(indices); } - indices= newi; + indices = newi; } - cur= indices+4*curindex; + cur = indices + 4 * curindex; /* displists now support array drawing, we treat tri's as fake quad */ - cur[0]= i1; - cur[1]= i2; - cur[2]= i3; - if (i4==0) - cur[3]= i3; + cur[0] = i1; + cur[1] = i2; + cur[2] = i3; + if (i4 == 0) + cur[3] = i3; else - cur[3]= i4; + cur[3] = i4; curindex++; @@ -851,41 +851,41 @@ static void *new_pgn_element(int size) /* during polygonize 1000s of elements are allocated * and never freed in between. Freeing only done at the end. */ - int blocksize= 16384; - static int offs= 0; /* the current free address */ - static struct pgn_elements *cur= NULL; - static ListBase lb= {NULL, NULL}; + int blocksize = 16384; + static int offs = 0; /* the current free address */ + static struct pgn_elements *cur = NULL; + static ListBase lb = {NULL, NULL}; void *adr; - if (size>10000 || size==0) { + if (size > 10000 || size == 0) { printf("incorrect use of new_pgn_element\n"); } - else if (size== -1) { - cur= lb.first; + else if (size == -1) { + cur = lb.first; while (cur) { MEM_freeN(cur->data); - cur= cur->next; + cur = cur->next; } BLI_freelistN(&lb); return NULL; } - size= 4*( (size+3)/4 ); + size = 4 * ( (size + 3) / 4); if (cur) { - if (size+offs < blocksize) { - adr= (void *) (cur->data+offs); - offs+= size; + if (size + offs < blocksize) { + adr = (void *) (cur->data + offs); + offs += size; return adr; } } - cur= MEM_callocN(sizeof(struct pgn_elements), "newpgn"); - cur->data= MEM_callocN(blocksize, "newpgn"); + cur = MEM_callocN(sizeof(struct pgn_elements), "newpgn"); + cur->data = MEM_callocN(blocksize, "newpgn"); BLI_addtail(&lb, cur); - offs= size; + offs = size; return cur->data; } @@ -902,31 +902,35 @@ static void freepolygonize(PROCESS *p) /**** Cubical Polygonization (optional) ****/ -#define LB 0 /* left bottom edge */ -#define LT 1 /* left top edge */ -#define LN 2 /* left near edge */ -#define LF 3 /* left far edge */ -#define RB 4 /* right bottom edge */ -#define RT 5 /* right top edge */ -#define RN 6 /* right near edge */ -#define RF 7 /* right far edge */ -#define BN 8 /* bottom near edge */ -#define BF 9 /* bottom far edge */ -#define TN 10 /* top near edge */ -#define TF 11 /* top far edge */ +#define LB 0 /* left bottom edge */ +#define LT 1 /* left top edge */ +#define LN 2 /* left near edge */ +#define LF 3 /* left far edge */ +#define RB 4 /* right bottom edge */ +#define RT 5 /* right top edge */ +#define RN 6 /* right near edge */ +#define RF 7 /* right far edge */ +#define BN 8 /* bottom near edge */ +#define BF 9 /* bottom far edge */ +#define TN 10 /* top near edge */ +#define TF 11 /* top far edge */ static INTLISTS *cubetable[256]; /* edge: LB, LT, LN, LF, RB, RT, RN, RF, BN, BF, TN, TF */ -static int corner1[12] = { - LBN, LTN, LBN, LBF, RBN, RTN, RBN, RBF, LBN, LBF, LTN, LTF}; -static int corner2[12] = { - LBF, LTF, LTN, LTF, RBF, RTF, RTN, RTF, RBN, RBF, RTN, RTF}; -static int leftface[12] = { - B, L, L, F, R, T, N, R, N, B, T, F}; +static int corner1[12] = { + LBN, LTN, LBN, LBF, RBN, RTN, RBN, RBF, LBN, LBF, LTN, LTF +}; +static int corner2[12] = { + LBF, LTF, LTN, LTF, RBF, RTF, RTN, RTF, RBN, RBF, RTN, RTF +}; +static int leftface[12] = { + B, L, L, F, R, T, N, R, N, B, T, F +}; /* face on left when going corner1 to corner2 */ -static int rightface[12] = { - L, T, N, L, B, R, R, F, B, F, N, T}; +static int rightface[12] = { + L, T, N, L, B, R, R, F, B, F, N, T +}; /* face on right when going corner1 to corner2 */ @@ -938,7 +942,7 @@ static 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.0f) 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; @@ -952,44 +956,44 @@ static void docube(CUBE *cube, PROCESS *p, MetaBall *mb) indexar[count] = vertid(c1, c2, p, mb); count++; } - if (count>2) { + if (count > 2) { switch (count) { - case 3: - accum_mballfaces(indexar[2], indexar[1], indexar[0], 0); - break; - case 4: - if (indexar[0]==0) accum_mballfaces(indexar[0], indexar[3], indexar[2], indexar[1]); - else accum_mballfaces(indexar[3], indexar[2], indexar[1], indexar[0]); - break; - case 5: - if (indexar[0]==0) accum_mballfaces(indexar[0], indexar[3], indexar[2], indexar[1]); - else accum_mballfaces(indexar[3], indexar[2], indexar[1], indexar[0]); - - accum_mballfaces(indexar[4], indexar[3], indexar[0], 0); - break; - case 6: - if (indexar[0]==0) { - accum_mballfaces(indexar[0], indexar[3], indexar[2], indexar[1]); - accum_mballfaces(indexar[0], indexar[5], indexar[4], indexar[3]); - } - else { - accum_mballfaces(indexar[3], indexar[2], indexar[1], indexar[0]); - accum_mballfaces(indexar[5], indexar[4], indexar[3], indexar[0]); - } - break; - case 7: - if (indexar[0]==0) { - accum_mballfaces(indexar[0], indexar[3], indexar[2], indexar[1]); - accum_mballfaces(indexar[0], indexar[5], indexar[4], indexar[3]); - } - else { - accum_mballfaces(indexar[3], indexar[2], indexar[1], indexar[0]); - accum_mballfaces(indexar[5], indexar[4], indexar[3], indexar[0]); - } + case 3: + accum_mballfaces(indexar[2], indexar[1], indexar[0], 0); + break; + case 4: + if (indexar[0] == 0) accum_mballfaces(indexar[0], indexar[3], indexar[2], indexar[1]); + else accum_mballfaces(indexar[3], indexar[2], indexar[1], indexar[0]); + break; + case 5: + if (indexar[0] == 0) accum_mballfaces(indexar[0], indexar[3], indexar[2], indexar[1]); + else accum_mballfaces(indexar[3], indexar[2], indexar[1], indexar[0]); - accum_mballfaces(indexar[6], indexar[5], indexar[0], 0); + accum_mballfaces(indexar[4], indexar[3], indexar[0], 0); + break; + case 6: + if (indexar[0] == 0) { + accum_mballfaces(indexar[0], indexar[3], indexar[2], indexar[1]); + accum_mballfaces(indexar[0], indexar[5], indexar[4], indexar[3]); + } + else { + accum_mballfaces(indexar[3], indexar[2], indexar[1], indexar[0]); + accum_mballfaces(indexar[5], indexar[4], indexar[3], indexar[0]); + } + break; + case 7: + if (indexar[0] == 0) { + accum_mballfaces(indexar[0], indexar[3], indexar[2], indexar[1]); + accum_mballfaces(indexar[0], indexar[5], indexar[4], indexar[3]); + } + else { + accum_mballfaces(indexar[3], indexar[2], indexar[1], indexar[0]); + accum_mballfaces(indexar[5], indexar[4], indexar[3], indexar[0]); + } - break; + accum_mballfaces(indexar[6], indexar[5], indexar[0], 0); + + break; } } } @@ -1000,17 +1004,17 @@ static void docube(CUBE *cube, PROCESS *p, MetaBall *mb) * if surface crosses face, compute other four corners of adjacent cube * and add new cube to cube stack */ -static void testface(int i, int j, int k, CUBE* old, int bit, int c1, int c2, int c3, int c4, PROCESS *p) +static void testface(int i, int j, int k, CUBE *old, int bit, int c1, int c2, int c3, int c4, PROCESS *p) { CUBE newc; CUBES *oldcubes = p->cubes; CORNER *corn1, *corn2, *corn3, *corn4; int n, pos; - corn1= old->corners[c1]; - corn2= old->corners[c2]; - corn3= old->corners[c3]; - corn4= old->corners[c4]; + corn1 = old->corners[c1]; + corn2 = old->corners[c2]; + corn3 = old->corners[c3]; + corn4 = old->corners[c4]; pos = corn1->value > 0.0f ? 1 : 0; @@ -1036,22 +1040,22 @@ static void testface(int i, int j, int k, CUBE* old, int bit, int c1, int c2, in newc.corners[FLIP(c3, bit)] = corn3; newc.corners[FLIP(c4, bit)] = corn4; - if (newc.corners[0]==NULL) newc.corners[0] = setcorner(p, i, j, k); - if (newc.corners[1]==NULL) newc.corners[1] = setcorner(p, i, j, k+1); - if (newc.corners[2]==NULL) newc.corners[2] = setcorner(p, i, j+1, k); - if (newc.corners[3]==NULL) newc.corners[3] = setcorner(p, i, j+1, k+1); - if (newc.corners[4]==NULL) newc.corners[4] = setcorner(p, i+1, j, k); - if (newc.corners[5]==NULL) newc.corners[5] = setcorner(p, i+1, j, k+1); - if (newc.corners[6]==NULL) newc.corners[6] = setcorner(p, i+1, j+1, k); - if (newc.corners[7]==NULL) newc.corners[7] = setcorner(p, i+1, j+1, k+1); + if (newc.corners[0] == NULL) newc.corners[0] = setcorner(p, i, j, k); + if (newc.corners[1] == NULL) newc.corners[1] = setcorner(p, i, j, k + 1); + if (newc.corners[2] == NULL) newc.corners[2] = setcorner(p, i, j + 1, k); + if (newc.corners[3] == NULL) newc.corners[3] = setcorner(p, i, j + 1, k + 1); + if (newc.corners[4] == NULL) newc.corners[4] = setcorner(p, i + 1, j, k); + if (newc.corners[5] == NULL) newc.corners[5] = setcorner(p, i + 1, j, k + 1); + if (newc.corners[6] == NULL) newc.corners[6] = setcorner(p, i + 1, j + 1, k); + if (newc.corners[7] == NULL) newc.corners[7] = setcorner(p, i + 1, j + 1, k + 1); - p->cubes->cube= newc; + p->cubes->cube = newc; } /* setcorner: return corner with the given lattice location * set (and cache) its function value */ -static CORNER *setcorner (PROCESS* p, int i, int j, int k) +static CORNER *setcorner(PROCESS *p, int i, int j, int k) { /* for speed, do corner value caching here */ CORNER *c; @@ -1070,11 +1074,11 @@ static CORNER *setcorner (PROCESS* p, int i, int j, int k) c = (CORNER *) new_pgn_element(sizeof(CORNER)); c->i = i; - c->x = ((float)i-0.5f)*p->size; + c->x = ((float)i - 0.5f) * p->size; c->j = j; - c->y = ((float)j-0.5f)*p->size; + c->y = ((float)j - 0.5f) * p->size; c->k = k; - c->z = ((float)k-0.5f)*p->size; + c->z = ((float)k - 0.5f) * p->size; c->value = p->function(c->x, c->y, c->z); c->next = p->corners[index]; @@ -1086,33 +1090,33 @@ static CORNER *setcorner (PROCESS* p, int i, int j, int k) /* nextcwedge: return next clockwise edge from given edge around given face */ -static int nextcwedge (int edge, int face) +static int nextcwedge(int edge, int face) { switch (edge) { - case LB: - return (face == L)? LF : BN; - case LT: - return (face == L)? LN : TF; - case LN: - return (face == L)? LB : TN; - case LF: - return (face == L)? LT : BF; - case RB: - return (face == R)? RN : BF; - case RT: - return (face == R)? RF : TN; - case RN: - return (face == R)? RT : BN; - case RF: - return (face == R)? RB : TF; - case BN: - return (face == B)? RB : LN; - case BF: - return (face == B)? LB : RF; - case TN: - return (face == T)? LT : RN; - case TF: - return (face == T)? RT : LF; + case LB: + return (face == L) ? LF : BN; + case LT: + return (face == L) ? LN : TF; + case LN: + return (face == L) ? LB : TN; + case LF: + return (face == L) ? LT : BF; + case RB: + return (face == R) ? RN : BF; + case RT: + return (face == R) ? RF : TN; + case RN: + return (face == R) ? RT : BN; + case RF: + return (face == R) ? RB : TF; + case BN: + return (face == B) ? RB : LN; + case BF: + return (face == B) ? LB : RF; + case TN: + return (face == T) ? LT : RN; + case TF: + return (face == T) ? RT : LF; } return 0; } @@ -1120,22 +1124,22 @@ static int nextcwedge (int edge, int face) /* otherface: return face adjoining edge that is not the given face */ -static int otherface (int edge, int face) +static int otherface(int edge, int face) { int other = leftface[edge]; - return face == other? rightface[edge] : other; + return face == other ? rightface[edge] : other; } /* makecubetable: create the 256 entry table for cubical polygonization */ -static void makecubetable (void) +static void makecubetable(void) { - static int isdone= 0; + static int isdone = 0; int i, e, c, done[12], pos[8]; if (isdone) return; - isdone= 1; + isdone = 1; for (i = 0; i < 256; i++) { for (e = 0; e < 12; e++) done[e] = 0; @@ -1147,7 +1151,7 @@ static void makecubetable (void) int start = e, edge = e; /* get face that is to right of edge from pos to neg corner: */ - int face = pos[corner1[e]]? rightface[e] : leftface[e]; + int face = pos[corner1[e]] ? rightface[e] : leftface[e]; while (1) { edge = nextcwedge(edge, face); @@ -1170,28 +1174,28 @@ static void makecubetable (void) } } -void BKE_metaball_cubeTable_free(void) +void BKE_mball_cubeTable_free(void) { int i; INTLISTS *lists, *nlists; INTLIST *ints, *nints; for (i = 0; i < 256; i++) { - lists= cubetable[i]; + lists = cubetable[i]; while (lists) { - nlists= lists->next; + nlists = lists->next; - ints= lists->list; + ints = lists->list; while (ints) { - nints= ints->next; + nints = ints->next; MEM_freeN(ints); - ints= nints; + ints = nints; } MEM_freeN(lists); - lists= nlists; + lists = nlists; } - cubetable[i]= NULL; + cubetable[i] = NULL; } } @@ -1205,8 +1209,8 @@ static int setcenter(CENTERLIST *table[], int i, int j, int k) int index; CENTERLIST *newc, *l, *q; - index= HASH(i, j, k); - q= table[index]; + index = HASH(i, j, k); + q = table[index]; for (l = q; l != NULL; l = l->next) { if (l->i == i && l->j == j && l->k == k) return 1; @@ -1225,25 +1229,25 @@ static int setcenter(CENTERLIST *table[], int i, int j, int k) /* setedge: set vertex id for edge */ -static void setedge (EDGELIST *table[], - int i1, int j1, - int k1, int i2, - int j2, int k2, - int vid) +static void setedge(EDGELIST *table[], + int i1, int j1, + int k1, int i2, + int j2, int k2, + int vid) { unsigned int index; EDGELIST *newe; - if (i1>i2 || (i1==i2 && (j1>j2 || (j1==j2 && k1>k2)))) { - int t=i1; - i1=i2; - i2=t; - t=j1; - j1=j2; - j2=t; - t=k1; - k1=k2; - k2=t; + if (i1 > i2 || (i1 == i2 && (j1 > j2 || (j1 == j2 && k1 > k2)))) { + int t = i1; + i1 = i2; + i2 = t; + t = j1; + j1 = j2; + j2 = t; + t = k1; + k1 = k2; + k2 = t; } index = HASH(i1, j1, k1) + HASH(i2, j2, k2); newe = (EDGELIST *) new_pgn_element(sizeof(EDGELIST)); @@ -1261,27 +1265,27 @@ static void setedge (EDGELIST *table[], /* getedge: return vertex id for edge; return -1 if not set */ -static int getedge (EDGELIST *table[], - int i1, int j1, int k1, - int i2, int j2, int k2) +static int getedge(EDGELIST *table[], + int i1, int j1, int k1, + int i2, int j2, int k2) { EDGELIST *q; - if (i1>i2 || (i1==i2 && (j1>j2 || (j1==j2 && k1>k2)))) { - int t=i1; - i1=i2; - i2=t; - t=j1; - j1=j2; - j2=t; - t=k1; - k1=k2; - k2=t; - } - q = table[HASH(i1, j1, k1)+HASH(i2, j2, k2)]; + if (i1 > i2 || (i1 == i2 && (j1 > j2 || (j1 == j2 && k1 > k2)))) { + int t = i1; + i1 = i2; + i2 = t; + t = j1; + j1 = j2; + j2 = t; + t = k1; + k1 = k2; + k2 = t; + } + q = table[HASH(i1, j1, k1) + HASH(i2, j2, k2)]; for (; q != NULL; q = q->next) { if (q->i1 == i1 && q->j1 == j1 && q->k1 == k1 && - q->i2 == i2 && q->j2 == j2 && q->k2 == k2) + q->i2 == i2 && q->j2 == j2 && q->k2 == k2) { return q->vid; } @@ -1302,12 +1306,12 @@ static int getedge (EDGELIST *table[], /* addtovertices: add v to sequence of vertices */ -static void addtovertices (VERTICES *vertices, VERTEX v) +static void addtovertices(VERTICES *vertices, VERTEX v) { if (vertices->count == vertices->max) { int i; VERTEX *newv; - vertices->max = vertices->count == 0 ? 10 : 2*vertices->count; + vertices->max = vertices->count == 0 ? 10 : 2 * vertices->count; newv = (VERTEX *) MEM_callocN(vertices->max * sizeof(VERTEX), "addtovertices"); for (i = 0; i < vertices->count; i++) newv[i] = vertices->ptr[i]; @@ -1320,15 +1324,15 @@ static void addtovertices (VERTICES *vertices, VERTEX v) /* vnormal: compute unit length surface normal at point */ -static void vnormal (MB_POINT *point, PROCESS *p, MB_POINT *v) +static void vnormal(MB_POINT *point, PROCESS *p, MB_POINT *v) { - float delta= 0.2f*p->delta; + float delta = 0.2f * p->delta; float f = p->function(point->x, point->y, point->z); - 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 = sqrtf(v->x*v->x + v->y*v->y + v->z*v->z); + 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 = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z); if (f != 0.0f) { v->x /= f; @@ -1343,21 +1347,21 @@ static void vnormal (MB_POINT *point, PROCESS *p, MB_POINT *v) 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 = sqrtf(temp.x*temp.x + temp.y*temp.y + temp.z*temp.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 = sqrtf(temp.x * temp.x + temp.y * temp.y + temp.z * temp.z); if (f != 0.0f) { temp.x /= f; temp.y /= f; temp.z /= f; - v->x+= temp.x; - v->y+= temp.y; - v->z+= temp.z; + v->x += temp.x; + v->y += temp.y; + v->z += temp.z; - f = sqrtf(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.0f) { v->x /= f; @@ -1370,13 +1374,13 @@ static void vnormal (MB_POINT *point, PROCESS *p, MB_POINT *v) } -static int vertid (CORNER *c1, CORNER *c2, PROCESS *p, MetaBall *mb) +static int vertid(CORNER *c1, CORNER *c2, PROCESS *p, MetaBall *mb) { VERTEX v; MB_POINT a, b; int vid = getedge(p->edges, c1->i, c1->j, c1->k, c2->i, c2->j, c2->k); - if (vid != -1) return vid; /* previously computed */ + if (vid != -1) return vid; /* previously computed */ a.x = c1->x; a.y = c1->y; a.z = c1->z; @@ -1387,8 +1391,8 @@ static int vertid (CORNER *c1, CORNER *c2, PROCESS *p, MetaBall *mb) converge(&a, &b, c1->value, c2->value, p->function, &v.position, mb, 1); /* position */ vnormal(&v.position, p, &v.normal); - addtovertices(&p->vertices, v); /* save vertex */ - vid = p->vertices.count-1; + addtovertices(&p->vertices, v); /* save vertex */ + vid = p->vertices.count - 1; setedge(p->edges, c1->i, c1->j, c1->k, c2->i, c2->j, c2->k, vid); return vid; @@ -1399,8 +1403,8 @@ static int vertid (CORNER *c1, CORNER *c2, PROCESS *p, MetaBall *mb) /* converge: from two points of differing sign, converge to zero crossing */ /* watch it: p1 and p2 are used to calculate */ -static void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2, - float (*function)(float, float, float), MB_POINT *p, MetaBall *mb, int f) +static void converge(MB_POINT *p1, MB_POINT *p2, float v1, float v2, + float (*function)(float, float, float), MB_POINT *p, MetaBall *mb, int f) { int i = 0; MB_POINT pos, neg; @@ -1408,14 +1412,14 @@ static void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2, float dx = 0.0f, dy = 0.0f, dz = 0.0f; if (v1 < 0) { - pos= *p2; - neg= *p1; + pos = *p2; + neg = *p1; positive = v2; negative = v1; } else { - pos= *p1; - neg= *p2; + pos = *p1; + neg = *p2; positive = v1; negative = v2; } @@ -1426,25 +1430,25 @@ static void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2, /* Approximation by linear interpolation is faster then binary subdivision, * but it results sometimes (mb->thresh < 0.2) into the strange results */ - 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; - p->z = neg.z; - return; - } - if ((dx == 0.0f) && (dz == 0.0f)) { - p->x = neg.x; - p->y = neg.y - negative*dy/(positive-negative); - p->z = neg.z; - return; - } - if ((dx == 0.0f) && (dy == 0.0f)) { - p->x = neg.x; - p->y = neg.y; - p->z = neg.z - negative*dz/(positive-negative); - return; - } + 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; + p->z = neg.z; + return; + } + if ((dx == 0.0f) && (dz == 0.0f)) { + p->x = neg.x; + p->y = neg.y - negative * dy / (positive - negative); + p->z = neg.z; + return; + } + if ((dx == 0.0f) && (dy == 0.0f)) { + p->x = neg.x; + p->y = neg.y; + p->z = neg.z - negative * dz / (positive - negative); + return; + } } if ((dy == 0.0f) && (dz == 0.0f)) { @@ -1452,8 +1456,8 @@ static void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2, p->z = neg.z; while (1) { if (i++ == RES) return; - p->x = 0.5f*(pos.x + neg.x); - if ((function(p->x, p->y, p->z)) > 0.0f) pos.x = p->x; else neg.x = p->x; + p->x = 0.5f * (pos.x + neg.x); + if ((function(p->x, p->y, p->z)) > 0.0f) pos.x = p->x; else neg.x = p->x; } } @@ -1462,26 +1466,26 @@ static void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2, p->z = neg.z; while (1) { if (i++ == RES) return; - p->y = 0.5f*(pos.y + neg.y); - if ((function(p->x, p->y, p->z)) > 0.0f) pos.y = p->y; else neg.y = p->y; + p->y = 0.5f * (pos.y + neg.y); + if ((function(p->x, p->y, p->z)) > 0.0f) pos.y = p->y; else neg.y = p->y; } - } + } if ((dx == 0.0f) && (dy == 0.0f)) { p->x = neg.x; p->y = neg.y; while (1) { if (i++ == RES) return; - p->z = 0.5f*(pos.z + neg.z); - if ((function(p->x, p->y, p->z)) > 0.0f) pos.z = p->z; else neg.z = p->z; + p->z = 0.5f * (pos.z + neg.z); + if ((function(p->x, p->y, p->z)) > 0.0f) pos.z = p->z; else neg.z = p->z; } } /* This is necessary to find start point */ while (1) { - p->x = 0.5f*(pos.x + neg.x); - p->y = 0.5f*(pos.y + neg.y); - p->z = 0.5f*(pos.z + neg.z); + p->x = 0.5f * (pos.x + neg.x); + p->y = 0.5f * (pos.y + neg.y); + p->z = 0.5f * (pos.z + neg.z); if (i++ == RES) return; @@ -1507,23 +1511,23 @@ static void add_cube(PROCESS *mbproc, int i, int j, int k, int count) /* hmmm, not only one, but eight cube will be added on the stack * ... */ - for (a=i-1; a<i+count; a++) - for (b=j-1; b<j+count; b++) - for (c=k-1; c<k+count; c++) { + for (a = i - 1; a < i + count; a++) + for (b = j - 1; b < j + count; b++) + for (c = k - 1; c < k + count; c++) { /* test if cube has been found before */ - if ( setcenter(mbproc->centers, a, b, c)==0 ) { + if (setcenter(mbproc->centers, a, b, c) == 0) { /* push cube on stack: */ - ncube= (CUBES *) new_pgn_element(sizeof(CUBES)); - ncube->next= mbproc->cubes; - mbproc->cubes= ncube; + ncube = (CUBES *) new_pgn_element(sizeof(CUBES)); + ncube->next = mbproc->cubes; + mbproc->cubes = ncube; - ncube->cube.i= a; - ncube->cube.j= b; - ncube->cube.k= c; + ncube->cube.i = a; + ncube->cube.j = b; + ncube->cube.k = c; /* set corners of initial cube: */ for (n = 0; n < 8; n++) - ncube->cube.corners[n] = setcorner(mbproc, a+MB_BIT(n, 2), b+MB_BIT(n, 1), c+MB_BIT(n, 0)); + ncube->cube.corners[n] = setcorner(mbproc, a + MB_BIT(n, 2), b + MB_BIT(n, 1), c + MB_BIT(n, 0)); } } } @@ -1534,64 +1538,64 @@ static void find_first_points(PROCESS *mbproc, MetaBall *mb, int a) MB_POINT IN, in, OUT, out; /*point;*/ MetaElem *ml; int i, j, k, c_i, c_j, c_k; - int index[3]={1, 0, -1}; - float f =0.0f; + int index[3] = {1, 0, -1}; + float f = 0.0f; float in_v /*, out_v*/; MB_POINT workp; float tmp_v, workp_v, max_len, len, dx, dy, dz, nx, ny, nz, MAXN; ml = mainb[a]; - f = 1-(mb->thresh/ml->s); + f = 1 - (mb->thresh / ml->s); /* Skip, when Stiffness of MetaElement is too small ... MetaElement can't be * visible alone ... but still can influence others MetaElements :-) */ 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; + OUT.x = IN.x = in.x = 0.0; + OUT.y = IN.y = in.y = 0.0; + OUT.z = IN.z = in.z = 0.0; calc_mballco(ml, (float *)&in); in_v = mbproc->function(in.x, in.y, in.z); - for (i=0;i<3;i++) { + for (i = 0; i < 3; i++) { switch (ml->type) { case MB_BALL: - OUT.x = out.x= IN.x + index[i]*ml->rad; + OUT.x = out.x = IN.x + index[i] * ml->rad; break; case MB_TUBE: case MB_PLANE: case MB_ELIPSOID: case MB_CUBE: - OUT.x = out.x= IN.x + index[i]*(ml->expx + ml->rad); + OUT.x = out.x = IN.x + index[i] * (ml->expx + ml->rad); break; } - for (j=0;j<3;j++) { + for (j = 0; j < 3; j++) { switch (ml->type) { case MB_BALL: - OUT.y = out.y= IN.y + index[j]*ml->rad; + OUT.y = out.y = IN.y + index[j] * ml->rad; break; case MB_TUBE: case MB_PLANE: case MB_ELIPSOID: case MB_CUBE: - OUT.y = out.y= IN.y + index[j]*(ml->expy + ml->rad); + OUT.y = out.y = IN.y + index[j] * (ml->expy + ml->rad); break; } - for (k=0;k<3;k++) { + for (k = 0; k < 3; k++) { out.x = OUT.x; out.y = OUT.y; switch (ml->type) { case MB_BALL: case MB_TUBE: case MB_PLANE: - out.z= IN.z + index[k]*ml->rad; + out.z = IN.z + index[k] * ml->rad; break; case MB_ELIPSOID: case MB_CUBE: - out.z= IN.z + index[k]*(ml->expz + ml->rad); + out.z = IN.z + index[k] * (ml->expz + ml->rad); break; } @@ -1604,32 +1608,32 @@ static void find_first_points(PROCESS *mbproc, MetaBall *mb, int a) workp.y = in.y; workp.z = in.z; workp_v = in_v; - 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)); + 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); - nz = abs((out.z - in.z)/mbproc->size); + nx = abs((out.x - in.x) / mbproc->size); + ny = abs((out.y - in.y) / mbproc->size); + nz = abs((out.z - in.z) / mbproc->size); MAXN = MAX3(nx, ny, nz); - if (MAXN!=0.0f) { - dx = (out.x - in.x)/MAXN; - dy = (out.y - in.y)/MAXN; - dz = (out.z - in.z)/MAXN; + if (MAXN != 0.0f) { + dx = (out.x - in.x) / MAXN; + dy = (out.y - in.y) / MAXN; + dz = (out.z - in.z) / MAXN; len = 0.0; - while (len<=max_len) { + while (len <= max_len) { workp.x += dx; workp.y += dy; workp.z += dz; /* 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.0f && workp_v>=0.0f)||(tmp_v>0.0f && workp_v<=0.0f)) { + 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); - c_j= (int)floor(workp.y/mbproc->size); - c_k= (int)floor(workp.z/mbproc->size); + c_i = (int)floor(workp.x / mbproc->size); + c_j = (int)floor(workp.y / mbproc->size); + c_k = (int)floor(workp.z / mbproc->size); /* add CUBE (with indexes c_i, c_j, c_k) to the stack, * this cube includes found point of Implicit Surface */ @@ -1638,7 +1642,7 @@ static void find_first_points(PROCESS *mbproc, MetaBall *mb, int a) else add_cube(mbproc, c_i, c_j, c_k, 1); } - 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)); + 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; } @@ -1660,10 +1664,10 @@ static void polygonize(PROCESS *mbproc, MetaBall *mb) /* allocate hash tables and build cube polygon table: */ mbproc->centers = MEM_callocN(HASHSIZE * sizeof(CENTERLIST *), "mbproc->centers"); mbproc->corners = MEM_callocN(HASHSIZE * sizeof(CORNER *), "mbproc->corners"); - mbproc->edges = MEM_callocN(2*HASHSIZE * sizeof(EDGELIST *), "mbproc->edges"); + mbproc->edges = MEM_callocN(2 * HASHSIZE * sizeof(EDGELIST *), "mbproc->edges"); makecubetable(); - for (a=0; a<totelem; a++) { + for (a = 0; a < totelem; a++) { /* try to find 8 points on the surface for each MetaElem */ find_first_points(mbproc, mb, a); @@ -1680,232 +1684,232 @@ static void polygonize(PROCESS *mbproc, MetaBall *mb) mbproc->cubes = mbproc->cubes->next; /* test six face directions, maybe add to stack: */ - testface(c.i-1, c.j, c.k, &c, 2, LBN, LBF, LTN, LTF, mbproc); - testface(c.i+1, c.j, c.k, &c, 2, RBN, RBF, RTN, RTF, mbproc); - testface(c.i, c.j-1, c.k, &c, 1, LBN, LBF, RBN, RBF, mbproc); - testface(c.i, c.j+1, c.k, &c, 1, LTN, LTF, RTN, RTF, mbproc); - testface(c.i, c.j, c.k-1, &c, 0, LBN, LTN, RBN, RTN, mbproc); - testface(c.i, c.j, c.k+1, &c, 0, LBF, LTF, RBF, RTF, mbproc); + testface(c.i - 1, c.j, c.k, &c, 2, LBN, LBF, LTN, LTF, mbproc); + testface(c.i + 1, c.j, c.k, &c, 2, RBN, RBF, RTN, RTF, mbproc); + testface(c.i, c.j - 1, c.k, &c, 1, LBN, LBF, RBN, RBF, mbproc); + testface(c.i, c.j + 1, c.k, &c, 1, LTN, LTF, RTN, RTF, mbproc); + testface(c.i, c.j, c.k - 1, &c, 0, LBN, LTN, RBN, RTN, mbproc); + testface(c.i, c.j, c.k + 1, &c, 0, LBF, LTF, RBF, RTF, mbproc); } } -static float init_meta(Scene *scene, Object *ob) /* return totsize */ +static float init_meta(Scene *scene, Object *ob) /* return totsize */ { - Scene *sce_iter= scene; + Scene *sce_iter = scene; Base *base; Object *bob; MetaBall *mb; MetaElem *ml; float size, totsize, obinv[4][4], obmat[4][4], vec[3]; //float max=0.0; - int a, obnr, zero_size=0; + int a, obnr, zero_size = 0; char obname[MAX_ID_NAME]; - copy_m4_m4(obmat, ob->obmat); /* to cope with duplicators from next_object */ + copy_m4_m4(obmat, ob->obmat); /* to cope with duplicators from BKE_scene_base_iter_next */ invert_m4_m4(obinv, ob->obmat); - a= 0; + a = 0; - BLI_split_name_num(obname, &obnr, ob->id.name+2, '.'); + BLI_split_name_num(obname, &obnr, ob->id.name + 2, '.'); /* make main array */ - next_object(&sce_iter, 0, NULL, NULL); - while (next_object(&sce_iter, 1, &base, &bob)) { + BKE_scene_base_iter_next(&sce_iter, 0, NULL, NULL); + while (BKE_scene_base_iter_next(&sce_iter, 1, &base, &bob)) { - if (bob->type==OB_MBALL) { - zero_size= 0; - ml= NULL; + if (bob->type == OB_MBALL) { + zero_size = 0; + ml = NULL; - if (bob==ob && (base->flag & OB_FROMDUPLI)==0) { - mb= ob->data; + if (bob == ob && (base->flag & OB_FROMDUPLI) == 0) { + mb = ob->data; - if (mb->editelems) ml= mb->editelems->first; - else ml= mb->elems.first; + if (mb->editelems) ml = mb->editelems->first; + else ml = mb->elems.first; } else { char name[MAX_ID_NAME]; int nr; - BLI_split_name_num(name, &nr, bob->id.name+2, '.'); - if ( strcmp(obname, name)==0 ) { - mb= bob->data; + BLI_split_name_num(name, &nr, bob->id.name + 2, '.'); + if (strcmp(obname, name) == 0) { + mb = bob->data; - if (mb->editelems) ml= mb->editelems->first; - else ml= mb->elems.first; + if (mb->editelems) ml = mb->editelems->first; + else ml = mb->elems.first; } } /* when metaball object has zero scale, then MetaElem to this MetaBall * will not be put to mainb array */ - if (bob->size[0]==0.0f || bob->size[1]==0.0f || bob->size[2]==0.0f) { - zero_size= 1; + 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; + struct Object *pob = bob->parent; while (pob) { - if (pob->size[0]==0.0f || pob->size[1]==0.0f || pob->size[2]==0.0f) { - zero_size= 1; + if (pob->size[0] == 0.0f || pob->size[1] == 0.0f || pob->size[2] == 0.0f) { + zero_size = 1; break; } - pob= pob->parent; + pob = pob->parent; } } if (zero_size) { - unsigned int ml_count=0; + unsigned int ml_count = 0; while (ml) { ml_count++; - ml= ml->next; + ml = ml->next; } totelem -= ml_count; } else { - while (ml) { - if (!(ml->flag & MB_HIDE)) { - int i; - float temp1[4][4], temp2[4][4], temp3[4][4]; - float (*mat)[4] = NULL, (*imat)[4] = NULL; - float max_x, max_y, max_z, min_x, min_y, min_z; - - max_x = max_y = max_z = -3.4e38; - min_x = min_y = min_z = 3.4e38; - - /* too big stiffness seems only ugly due to linear interpolation - * no need to have possibility for too big stiffness */ - if (ml->s > 10.0f) ml->s = 10.0f; + while (ml) { + if (!(ml->flag & MB_HIDE)) { + int i; + float temp1[4][4], temp2[4][4], temp3[4][4]; + float (*mat)[4] = NULL, (*imat)[4] = NULL; + float max_x, max_y, max_z, min_x, min_y, min_z; + + max_x = max_y = max_z = -3.4e38; + min_x = min_y = min_z = 3.4e38; + + /* too big stiffness seems only ugly due to linear interpolation + * no need to have possibility for too big stiffness */ + if (ml->s > 10.0f) ml->s = 10.0f; + + /* Rotation of MetaElem is stored in quat */ + quat_to_mat4(temp3, ml->quat); + + /* Translation of MetaElem */ + unit_m4(temp2); + temp2[3][0] = ml->x; + temp2[3][1] = ml->y; + temp2[3][2] = ml->z; + + mult_m4_m4m4(temp1, temp2, temp3); + + /* make a copy because of duplicates */ + mainb[a] = new_pgn_element(sizeof(MetaElem)); + *(mainb[a]) = *ml; + mainb[a]->bb = new_pgn_element(sizeof(BoundBox)); + + mat = new_pgn_element(4 * 4 * sizeof(float)); + imat = new_pgn_element(4 * 4 * sizeof(float)); + + /* mat is the matrix to transform from mball into the basis-mball */ + invert_m4_m4(obinv, obmat); + mult_m4_m4m4(temp2, obinv, bob->obmat); + /* MetaBall transformation */ + mult_m4_m4m4(mat, temp2, temp1); + + invert_m4_m4(imat, mat); + + mainb[a]->rad2 = ml->rad * ml->rad; + + mainb[a]->mat = (float *) mat; + mainb[a]->imat = (float *) imat; + + /* untransformed Bounding Box of MetaElem */ + /* 0 */ + mainb[a]->bb->vec[0][0] = -ml->expx; + mainb[a]->bb->vec[0][1] = -ml->expy; + mainb[a]->bb->vec[0][2] = -ml->expz; + /* 1 */ + mainb[a]->bb->vec[1][0] = ml->expx; + mainb[a]->bb->vec[1][1] = -ml->expy; + mainb[a]->bb->vec[1][2] = -ml->expz; + /* 2 */ + mainb[a]->bb->vec[2][0] = ml->expx; + mainb[a]->bb->vec[2][1] = ml->expy; + mainb[a]->bb->vec[2][2] = -ml->expz; + /* 3 */ + mainb[a]->bb->vec[3][0] = -ml->expx; + mainb[a]->bb->vec[3][1] = ml->expy; + mainb[a]->bb->vec[3][2] = -ml->expz; + /* 4 */ + mainb[a]->bb->vec[4][0] = -ml->expx; + mainb[a]->bb->vec[4][1] = -ml->expy; + mainb[a]->bb->vec[4][2] = ml->expz; + /* 5 */ + mainb[a]->bb->vec[5][0] = ml->expx; + mainb[a]->bb->vec[5][1] = -ml->expy; + mainb[a]->bb->vec[5][2] = ml->expz; + /* 6 */ + mainb[a]->bb->vec[6][0] = ml->expx; + mainb[a]->bb->vec[6][1] = ml->expy; + mainb[a]->bb->vec[6][2] = ml->expz; + /* 7 */ + mainb[a]->bb->vec[7][0] = -ml->expx; + mainb[a]->bb->vec[7][1] = ml->expy; + mainb[a]->bb->vec[7][2] = ml->expz; + + /* transformation of Metalem bb */ + for (i = 0; i < 8; i++) + mul_m4_v3((float (*)[4])mat, mainb[a]->bb->vec[i]); + + /* find max and min of transformed bb */ + for (i = 0; i < 8; i++) { + /* find maximums */ + if (mainb[a]->bb->vec[i][0] > max_x) max_x = mainb[a]->bb->vec[i][0]; + if (mainb[a]->bb->vec[i][1] > max_y) max_y = mainb[a]->bb->vec[i][1]; + if (mainb[a]->bb->vec[i][2] > max_z) max_z = mainb[a]->bb->vec[i][2]; + /* find minimums */ + if (mainb[a]->bb->vec[i][0] < min_x) min_x = mainb[a]->bb->vec[i][0]; + if (mainb[a]->bb->vec[i][1] < min_y) min_y = mainb[a]->bb->vec[i][1]; + if (mainb[a]->bb->vec[i][2] < min_z) min_z = mainb[a]->bb->vec[i][2]; + } - /* Rotation of MetaElem is stored in quat */ - quat_to_mat4(temp3, ml->quat); + /* create "new" bb, only point 0 and 6, which are + * necessary for octal tree filling */ + mainb[a]->bb->vec[0][0] = min_x - ml->rad; + mainb[a]->bb->vec[0][1] = min_y - ml->rad; + mainb[a]->bb->vec[0][2] = min_z - ml->rad; - /* Translation of MetaElem */ - unit_m4(temp2); - temp2[3][0]= ml->x; - temp2[3][1]= ml->y; - temp2[3][2]= ml->z; + mainb[a]->bb->vec[6][0] = max_x + ml->rad; + mainb[a]->bb->vec[6][1] = max_y + ml->rad; + mainb[a]->bb->vec[6][2] = max_z + ml->rad; - mult_m4_m4m4(temp1, temp2, temp3); - - /* make a copy because of duplicates */ - mainb[a]= new_pgn_element(sizeof(MetaElem)); - *(mainb[a])= *ml; - mainb[a]->bb = new_pgn_element(sizeof(BoundBox)); - - mat= new_pgn_element(4*4*sizeof(float)); - imat= new_pgn_element(4*4*sizeof(float)); - - /* mat is the matrix to transform from mball into the basis-mball */ - invert_m4_m4(obinv, obmat); - mult_m4_m4m4(temp2, obinv, bob->obmat); - /* MetaBall transformation */ - mult_m4_m4m4(mat, temp2, temp1); - - invert_m4_m4(imat, mat); - - mainb[a]->rad2= ml->rad*ml->rad; - - mainb[a]->mat= (float*) mat; - mainb[a]->imat= (float*) imat; - - /* untransformed Bounding Box of MetaElem */ - /* 0 */ - mainb[a]->bb->vec[0][0]= -ml->expx; - mainb[a]->bb->vec[0][1]= -ml->expy; - mainb[a]->bb->vec[0][2]= -ml->expz; - /* 1 */ - mainb[a]->bb->vec[1][0]= ml->expx; - mainb[a]->bb->vec[1][1]= -ml->expy; - mainb[a]->bb->vec[1][2]= -ml->expz; - /* 2 */ - mainb[a]->bb->vec[2][0]= ml->expx; - mainb[a]->bb->vec[2][1]= ml->expy; - mainb[a]->bb->vec[2][2]= -ml->expz; - /* 3 */ - mainb[a]->bb->vec[3][0]= -ml->expx; - mainb[a]->bb->vec[3][1]= ml->expy; - mainb[a]->bb->vec[3][2]= -ml->expz; - /* 4 */ - mainb[a]->bb->vec[4][0]= -ml->expx; - mainb[a]->bb->vec[4][1]= -ml->expy; - mainb[a]->bb->vec[4][2]= ml->expz; - /* 5 */ - mainb[a]->bb->vec[5][0]= ml->expx; - mainb[a]->bb->vec[5][1]= -ml->expy; - mainb[a]->bb->vec[5][2]= ml->expz; - /* 6 */ - mainb[a]->bb->vec[6][0]= ml->expx; - mainb[a]->bb->vec[6][1]= ml->expy; - mainb[a]->bb->vec[6][2]= ml->expz; - /* 7 */ - mainb[a]->bb->vec[7][0]= -ml->expx; - mainb[a]->bb->vec[7][1]= ml->expy; - mainb[a]->bb->vec[7][2]= ml->expz; - - /* transformation of Metalem bb */ - for (i=0; i<8; i++) - mul_m4_v3((float (*)[4])mat, mainb[a]->bb->vec[i]); - - /* find max and min of transformed bb */ - for (i=0; i<8; i++) { - /* find maximums */ - if (mainb[a]->bb->vec[i][0] > max_x) max_x = mainb[a]->bb->vec[i][0]; - if (mainb[a]->bb->vec[i][1] > max_y) max_y = mainb[a]->bb->vec[i][1]; - if (mainb[a]->bb->vec[i][2] > max_z) max_z = mainb[a]->bb->vec[i][2]; - /* find minimums */ - if (mainb[a]->bb->vec[i][0] < min_x) min_x = mainb[a]->bb->vec[i][0]; - if (mainb[a]->bb->vec[i][1] < min_y) min_y = mainb[a]->bb->vec[i][1]; - if (mainb[a]->bb->vec[i][2] < min_z) min_z = mainb[a]->bb->vec[i][2]; + a++; } - - /* create "new" bb, only point 0 and 6, which are - * necessary for octal tree filling */ - mainb[a]->bb->vec[0][0] = min_x - ml->rad; - mainb[a]->bb->vec[0][1] = min_y - ml->rad; - mainb[a]->bb->vec[0][2] = min_z - ml->rad; - - mainb[a]->bb->vec[6][0] = max_x + ml->rad; - mainb[a]->bb->vec[6][1] = max_y + ml->rad; - mainb[a]->bb->vec[6][2] = max_z + ml->rad; - - a++; + ml = ml->next; } - ml= ml->next; - } } } } /* totsize (= 'manhattan' radius) */ - totsize= 0.0; - for (a=0; a<totelem; a++) { + totsize = 0.0; + for (a = 0; a < totelem; a++) { - vec[0]= mainb[a]->x + mainb[a]->rad + mainb[a]->expx; - vec[1]= mainb[a]->y + mainb[a]->rad + mainb[a]->expy; - vec[2]= mainb[a]->z + mainb[a]->rad + mainb[a]->expz; + vec[0] = mainb[a]->x + mainb[a]->rad + mainb[a]->expx; + vec[1] = mainb[a]->y + mainb[a]->rad + mainb[a]->expy; + vec[2] = mainb[a]->z + mainb[a]->rad + mainb[a]->expz; calc_mballco(mainb[a], vec); - size= fabsf(vec[0]); - if ( size > totsize ) totsize= size; - size= fabsf(vec[1]); - if ( size > totsize ) totsize= size; - size= fabsf(vec[2]); - if ( size > totsize ) totsize= size; + size = fabsf(vec[0]); + if (size > totsize) totsize = size; + size = fabsf(vec[1]); + if (size > totsize) totsize = size; + size = fabsf(vec[2]); + if (size > totsize) totsize = size; - vec[0]= mainb[a]->x - mainb[a]->rad; - vec[1]= mainb[a]->y - mainb[a]->rad; - vec[2]= mainb[a]->z - mainb[a]->rad; + vec[0] = mainb[a]->x - mainb[a]->rad; + vec[1] = mainb[a]->y - mainb[a]->rad; + vec[2] = mainb[a]->z - mainb[a]->rad; calc_mballco(mainb[a], vec); - size= fabsf(vec[0]); - if ( size > totsize ) totsize= size; - size= fabsf(vec[1]); - if ( size > totsize ) totsize= size; - size= fabsf(vec[2]); - if ( size > totsize ) totsize= size; + size = fabsf(vec[0]); + if (size > totsize) totsize = size; + size = fabsf(vec[1]); + if (size > totsize) totsize = size; + size = fabsf(vec[2]); + if (size > totsize) totsize = size; } - for (a=0; a<totelem; a++) { + for (a = 0; a < totelem; a++) { thresh += densfunc(mainb[a], 2.0f * totsize, 2.0f * totsize, 2.0f * totsize); } @@ -1919,8 +1923,8 @@ static void fill_metaball_octal_node(octal_node *node, MetaElem *ml, short i) { ml_pointer *ml_p; - ml_p= MEM_mallocN(sizeof(ml_pointer), "ml_pointer"); - ml_p->ml= ml; + ml_p = MEM_mallocN(sizeof(ml_pointer), "ml_pointer"); + ml_p->ml = ml; BLI_addtail(&(node->nodes[i]->elems), ml_p); node->count++; @@ -1955,16 +1959,16 @@ static void subdivide_metaball_octal_node(octal_node *node, float size_x, float int a, i; /* create new nodes */ - for (a=0;a<8;a++) { - node->nodes[a]= MEM_mallocN(sizeof(octal_node), "octal_node"); - for (i=0;i<8;i++) - node->nodes[a]->nodes[i]= NULL; - node->nodes[a]->parent= node; - node->nodes[a]->elems.first= NULL; - node->nodes[a]->elems.last= NULL; - node->nodes[a]->count= 0; - node->nodes[a]->neg= 0; - node->nodes[a]->pos= 0; + for (a = 0; a < 8; a++) { + node->nodes[a] = MEM_mallocN(sizeof(octal_node), "octal_node"); + for (i = 0; i < 8; i++) + node->nodes[a]->nodes[i] = NULL; + node->nodes[a]->parent = node; + node->nodes[a]->elems.first = NULL; + node->nodes[a]->elems.last = NULL; + node->nodes[a]->count = 0; + node->nodes[a]->neg = 0; + node->nodes[a]->pos = 0; } size_x /= 2; @@ -1980,64 +1984,64 @@ static void subdivide_metaball_octal_node(octal_node *node, float size_x, float node->nodes[0]->x_min = node->x_min; node->nodes[0]->y_min = node->y_min; node->nodes[0]->z_min = node->z_min; - node->nodes[0]->x = node->nodes[0]->x_min + size_x/2; - node->nodes[0]->y = node->nodes[0]->y_min + size_y/2; - node->nodes[0]->z = node->nodes[0]->z_min + size_z/2; + node->nodes[0]->x = node->nodes[0]->x_min + size_x / 2; + node->nodes[0]->y = node->nodes[0]->y_min + size_y / 2; + node->nodes[0]->z = node->nodes[0]->z_min + size_z / 2; node->nodes[1]->x_min = x; node->nodes[1]->y_min = node->y_min; node->nodes[1]->z_min = node->z_min; - node->nodes[1]->x = node->nodes[1]->x_min + size_x/2; - node->nodes[1]->y = node->nodes[1]->y_min + size_y/2; - node->nodes[1]->z = node->nodes[1]->z_min + size_z/2; + node->nodes[1]->x = node->nodes[1]->x_min + size_x / 2; + node->nodes[1]->y = node->nodes[1]->y_min + size_y / 2; + node->nodes[1]->z = node->nodes[1]->z_min + size_z / 2; node->nodes[2]->x_min = x; node->nodes[2]->y_min = y; node->nodes[2]->z_min = node->z_min; - node->nodes[2]->x = node->nodes[2]->x_min + size_x/2; - node->nodes[2]->y = node->nodes[2]->y_min + size_y/2; - node->nodes[2]->z = node->nodes[2]->z_min + size_z/2; + node->nodes[2]->x = node->nodes[2]->x_min + size_x / 2; + node->nodes[2]->y = node->nodes[2]->y_min + size_y / 2; + node->nodes[2]->z = node->nodes[2]->z_min + size_z / 2; node->nodes[3]->x_min = node->x_min; node->nodes[3]->y_min = y; node->nodes[3]->z_min = node->z_min; - node->nodes[3]->x = node->nodes[3]->x_min + size_x/2; - node->nodes[3]->y = node->nodes[3]->y_min + size_y/2; - node->nodes[3]->z = node->nodes[3]->z_min + size_z/2; + node->nodes[3]->x = node->nodes[3]->x_min + size_x / 2; + node->nodes[3]->y = node->nodes[3]->y_min + size_y / 2; + node->nodes[3]->z = node->nodes[3]->z_min + size_z / 2; node->nodes[4]->x_min = node->x_min; node->nodes[4]->y_min = node->y_min; node->nodes[4]->z_min = z; - node->nodes[4]->x = node->nodes[4]->x_min + size_x/2; - node->nodes[4]->y = node->nodes[4]->y_min + size_y/2; - node->nodes[4]->z = node->nodes[4]->z_min + size_z/2; + node->nodes[4]->x = node->nodes[4]->x_min + size_x / 2; + node->nodes[4]->y = node->nodes[4]->y_min + size_y / 2; + node->nodes[4]->z = node->nodes[4]->z_min + size_z / 2; node->nodes[5]->x_min = x; node->nodes[5]->y_min = node->y_min; node->nodes[5]->z_min = z; - node->nodes[5]->x = node->nodes[5]->x_min + size_x/2; - node->nodes[5]->y = node->nodes[5]->y_min + size_y/2; - node->nodes[5]->z = node->nodes[5]->z_min + size_z/2; + node->nodes[5]->x = node->nodes[5]->x_min + size_x / 2; + node->nodes[5]->y = node->nodes[5]->y_min + size_y / 2; + node->nodes[5]->z = node->nodes[5]->z_min + size_z / 2; node->nodes[6]->x_min = x; node->nodes[6]->y_min = y; node->nodes[6]->z_min = z; - node->nodes[6]->x = node->nodes[6]->x_min + size_x/2; - node->nodes[6]->y = node->nodes[6]->y_min + size_y/2; - node->nodes[6]->z = node->nodes[6]->z_min + size_z/2; + node->nodes[6]->x = node->nodes[6]->x_min + size_x / 2; + node->nodes[6]->y = node->nodes[6]->y_min + size_y / 2; + node->nodes[6]->z = node->nodes[6]->z_min + size_z / 2; node->nodes[7]->x_min = node->x_min; node->nodes[7]->y_min = y; node->nodes[7]->z_min = z; - node->nodes[7]->x = node->nodes[7]->x_min + size_x/2; - node->nodes[7]->y = node->nodes[7]->y_min + size_y/2; - node->nodes[7]->z = node->nodes[7]->z_min + size_z/2; + node->nodes[7]->x = node->nodes[7]->x_min + size_x / 2; + node->nodes[7]->y = node->nodes[7]->y_min + size_y / 2; + node->nodes[7]->z = node->nodes[7]->z_min + size_z / 2; - ml_p= node->elems.first; + ml_p = node->elems.first; /* setting up references of MetaElems for new nodes */ while (ml_p) { - ml= ml_p->ml; + ml = ml_p->ml; if (ml->bb->vec[0][2] < z) { if (ml->bb->vec[0][1] < y) { /* vec[0][0] lies in first octant */ @@ -2187,7 +2191,7 @@ static void subdivide_metaball_octal_node(octal_node *node, float size_x, float fill_metaball_octal_node(node, ml, 6); } } - ml_p= ml_p->next; + ml_p = ml_p->next; } /* free references of MetaElems for curent node (it is not needed anymore) */ @@ -2195,8 +2199,8 @@ static void subdivide_metaball_octal_node(octal_node *node, float size_x, float depth--; - if (depth>0) { - for (a=0;a<8;a++) { + if (depth > 0) { + for (a = 0; a < 8; a++) { if (node->nodes[a]->count > 0) /* if node is not empty, then it is subdivided */ subdivide_metaball_octal_node(node->nodes[a], size_x, size_y, size_z, depth); } @@ -2207,8 +2211,8 @@ static void subdivide_metaball_octal_node(octal_node *node, float size_x, float static void free_metaball_octal_node(octal_node *node) { int a; - for (a=0;a<8;a++) { - if (node->nodes[a]!=NULL) free_metaball_octal_node(node->nodes[a]); + for (a = 0; a < 8; a++) { + if (node->nodes[a] != NULL) free_metaball_octal_node(node->nodes[a]); } BLI_freelistN(&node->elems); MEM_freeN(node); @@ -2222,36 +2226,36 @@ static void init_metaball_octal_tree(int depth) float size[3]; int a; - metaball_tree= MEM_mallocN(sizeof(octal_tree), "metaball_octal_tree"); - metaball_tree->first= node= MEM_mallocN(sizeof(octal_node), "metaball_octal_node"); + metaball_tree = MEM_mallocN(sizeof(octal_tree), "metaball_octal_tree"); + metaball_tree->first = node = MEM_mallocN(sizeof(octal_node), "metaball_octal_node"); /* maximal depth of octree */ - metaball_tree->depth= depth; + metaball_tree->depth = depth; - metaball_tree->neg= node->neg=0; - metaball_tree->pos= node->pos=0; + metaball_tree->neg = node->neg = 0; + metaball_tree->pos = node->pos = 0; - node->elems.first= NULL; - node->elems.last= NULL; - node->count=0; + node->elems.first = NULL; + node->elems.last = NULL; + node->count = 0; - for (a=0;a<8;a++) - node->nodes[a]=NULL; + for (a = 0; a < 8; a++) + node->nodes[a] = NULL; - node->x_min= node->y_min= node->z_min= FLT_MAX; - node->x_max= node->y_max= node->z_max= -FLT_MAX; + node->x_min = node->y_min = node->z_min = FLT_MAX; + node->x_max = node->y_max = node->z_max = -FLT_MAX; /* size of octal tree scene */ - for (a=0;a<totelem;a++) { - if (mainb[a]->bb->vec[0][0] < node->x_min) node->x_min= mainb[a]->bb->vec[0][0]; - if (mainb[a]->bb->vec[0][1] < node->y_min) node->y_min= mainb[a]->bb->vec[0][1]; - if (mainb[a]->bb->vec[0][2] < node->z_min) node->z_min= mainb[a]->bb->vec[0][2]; - - if (mainb[a]->bb->vec[6][0] > node->x_max) node->x_max= mainb[a]->bb->vec[6][0]; - if (mainb[a]->bb->vec[6][1] > node->y_max) node->y_max= mainb[a]->bb->vec[6][1]; - if (mainb[a]->bb->vec[6][2] > node->z_max) node->z_max= mainb[a]->bb->vec[6][2]; + for (a = 0; a < totelem; a++) { + if (mainb[a]->bb->vec[0][0] < node->x_min) node->x_min = mainb[a]->bb->vec[0][0]; + if (mainb[a]->bb->vec[0][1] < node->y_min) node->y_min = mainb[a]->bb->vec[0][1]; + if (mainb[a]->bb->vec[0][2] < node->z_min) node->z_min = mainb[a]->bb->vec[0][2]; + + if (mainb[a]->bb->vec[6][0] > node->x_max) node->x_max = mainb[a]->bb->vec[6][0]; + if (mainb[a]->bb->vec[6][1] > node->y_max) node->y_max = mainb[a]->bb->vec[6][1]; + if (mainb[a]->bb->vec[6][2] > node->z_max) node->z_max = mainb[a]->bb->vec[6][2]; - ml_p= MEM_mallocN(sizeof(ml_pointer), "ml_pointer"); - ml_p->ml= mainb[a]; + ml_p = MEM_mallocN(sizeof(ml_pointer), "ml_pointer"); + ml_p->ml = mainb[a]; BLI_addtail(&node->elems, ml_p); if (mainb[a]->flag & MB_NEGATIVE) { @@ -2265,15 +2269,15 @@ static void init_metaball_octal_tree(int depth) } /* size of first node */ - size[0]= node->x_max - node->x_min; - size[1]= node->y_max - node->y_min; - size[2]= node->z_max - node->z_min; + size[0] = node->x_max - node->x_min; + size[1] = node->y_max - node->y_min; + size[2] = node->z_max - node->z_min; /* first node is subdivided recursively */ subdivide_metaball_octal_node(node, size[0], size[1], size[2], metaball_tree->depth); } -void BKE_metaball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) +void BKE_mball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) { PROCESS mbproc; MetaBall *mb; @@ -2281,41 +2285,41 @@ void BKE_metaball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) int a, nr_cubes; float *ve, *no, totsize, width; - mb= ob->data; + mb = ob->data; - if (totelem==0) return; - if (!(G.rendering) && (mb->flag==MB_UPDATE_NEVER)) return; - if (G.moving && mb->flag==MB_UPDATE_FAST) return; + if (totelem == 0) return; + if (!(G.rendering) && (mb->flag == MB_UPDATE_NEVER)) return; + if (G.moving && mb->flag == MB_UPDATE_FAST) return; - curindex= totindex= 0; - indices= NULL; - thresh= mb->thresh; + curindex = totindex = 0; + indices = NULL; + thresh = mb->thresh; /* total number of MetaElems (totelem) is precomputed in find_basis_mball() function */ - mainb= MEM_mallocN(sizeof(void *)*totelem, "mainb"); + mainb = MEM_mallocN(sizeof(void *) * totelem, "mainb"); /* initialize all mainb (MetaElems) */ - totsize= init_meta(scene, ob); + totsize = init_meta(scene, ob); if (metaball_tree) { free_metaball_octal_node(metaball_tree->first); MEM_freeN(metaball_tree); - metaball_tree= NULL; + metaball_tree = NULL; } /* if scene includes more then one MetaElem, then octal tree optimalisation is used */ if ((totelem > 1) && (totelem <= 64)) init_metaball_octal_tree(1); if ((totelem > 64) && (totelem <= 128)) init_metaball_octal_tree(2); - if ((totelem > 128) && (totelem <= 512)) init_metaball_octal_tree(3); + if ((totelem > 128) && (totelem <= 512)) init_metaball_octal_tree(3); if ((totelem > 512) && (totelem <= 1024)) init_metaball_octal_tree(4); if (totelem > 1024) init_metaball_octal_tree(5); /* don't polygonize metaballs with too high resolution (base mball to small) * note: Eps was 0.0001f but this was giving problems for blood animation for durian, using 0.00001f */ if (metaball_tree) { - if ( ob->size[0] <= 0.00001f * (metaball_tree->first->x_max - metaball_tree->first->x_min) || - ob->size[1] <= 0.00001f * (metaball_tree->first->y_max - metaball_tree->first->y_min) || - ob->size[2] <= 0.00001f * (metaball_tree->first->z_max - metaball_tree->first->z_min)) + if (ob->size[0] <= 0.00001f * (metaball_tree->first->x_max - metaball_tree->first->x_min) || + ob->size[1] <= 0.00001f * (metaball_tree->first->y_max - metaball_tree->first->y_min) || + ob->size[2] <= 0.00001f * (metaball_tree->first->z_max - metaball_tree->first->z_min)) { new_pgn_element(-1); /* free values created by init_meta */ @@ -2324,27 +2328,27 @@ void BKE_metaball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) /* free tree */ free_metaball_octal_node(metaball_tree->first); MEM_freeN(metaball_tree); - metaball_tree= NULL; + metaball_tree = NULL; return; } } /* width is size per polygonize cube */ - if (G.rendering) width= mb->rendersize; + if (G.rendering) width = mb->rendersize; else { - width= mb->wiresize; - if (G.moving && mb->flag==MB_UPDATE_HALFRES) width*= 2; + width = mb->wiresize; + if (G.moving && mb->flag == MB_UPDATE_HALFRES) width *= 2; } /* nr_cubes is just for safety, minimum is totsize */ - nr_cubes= (int)(0.5f+totsize/width); + nr_cubes = (int)(0.5f + totsize / width); /* init process */ mbproc.function = metaball; mbproc.size = width; mbproc.bounds = nr_cubes; - mbproc.cubes= NULL; - mbproc.delta = width/(float)(RES*RES); + mbproc.cubes = NULL; + mbproc.delta = width / (float)(RES * RES); polygonize(&mbproc, mb); @@ -2354,31 +2358,31 @@ void BKE_metaball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) if (totelem > 1) { free_metaball_octal_node(metaball_tree->first); MEM_freeN(metaball_tree); - metaball_tree= NULL; + metaball_tree = NULL; } if (curindex) { - dl= MEM_callocN(sizeof(DispList), "mbaldisp"); + dl = MEM_callocN(sizeof(DispList), "mbaldisp"); BLI_addtail(dispbase, dl); - dl->type= DL_INDEX4; - dl->nr= mbproc.vertices.count; - dl->parts= curindex; + dl->type = DL_INDEX4; + dl->nr = mbproc.vertices.count; + dl->parts = curindex; - dl->index= indices; - indices= NULL; - - a= mbproc.vertices.count; - dl->verts= ve= MEM_mallocN(sizeof(float)*3*a, "mballverts"); - dl->nors= no= MEM_mallocN(sizeof(float)*3*a, "mballnors"); - - for (a=0; a<mbproc.vertices.count; a++, no+=3, ve+=3) { - ve[0]= mbproc.vertices.ptr[a].position.x; - ve[1]= mbproc.vertices.ptr[a].position.y; - ve[2]= mbproc.vertices.ptr[a].position.z; - - no[0]= mbproc.vertices.ptr[a].normal.x; - no[1]= mbproc.vertices.ptr[a].normal.y; - no[2]= mbproc.vertices.ptr[a].normal.z; + dl->index = indices; + indices = NULL; + + a = mbproc.vertices.count; + dl->verts = ve = MEM_mallocN(sizeof(float) * 3 * a, "mballverts"); + dl->nors = no = MEM_mallocN(sizeof(float) * 3 * a, "mballnors"); + + for (a = 0; a < mbproc.vertices.count; a++, no += 3, ve += 3) { + ve[0] = mbproc.vertices.ptr[a].position.x; + ve[1] = mbproc.vertices.ptr[a].position.y; + ve[2] = mbproc.vertices.ptr[a].position.z; + + no[0] = mbproc.vertices.ptr[a].normal.x; + no[1] = mbproc.vertices.ptr[a].normal.y; + no[2] = mbproc.vertices.ptr[a].normal.z; } } @@ -2386,7 +2390,7 @@ void BKE_metaball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) } /* basic vertex data functions */ -int BKE_metaball_minmax(MetaBall *mb, float min[3], float max[3]) +int BKE_mball_minmax(MetaBall *mb, float min[3], float max[3]) { MetaElem *ml; @@ -2399,10 +2403,10 @@ int BKE_metaball_minmax(MetaBall *mb, float min[3], float max[3]) return (mb->elems.first != NULL); } -int BKE_metaball_center_median(MetaBall *mb, float cent[3]) +int BKE_mball_center_median(MetaBall *mb, float cent[3]) { MetaElem *ml; - int total= 0; + int total = 0; zero_v3(cent); @@ -2411,16 +2415,16 @@ int BKE_metaball_center_median(MetaBall *mb, float cent[3]) } if (total) - mul_v3_fl(cent, 1.0f/(float)total); + mul_v3_fl(cent, 1.0f / (float)total); return (total != 0); } -int BKE_metaball_center_bounds(MetaBall *mb, float cent[3]) +int BKE_mball_center_bounds(MetaBall *mb, float cent[3]) { float min[3], max[3]; - if (BKE_metaball_minmax(mb, min, max)) { + if (BKE_mball_minmax(mb, min, max)) { mid_v3_v3v3(cent, min, max); return 1; } @@ -2428,7 +2432,7 @@ int BKE_metaball_center_bounds(MetaBall *mb, float cent[3]) return 0; } -void BKE_metaball_translate(MetaBall *mb, float offset[3]) +void BKE_mball_translate(MetaBall *mb, float offset[3]) { MetaElem *ml; diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 4b14c2aec4b..944f06cf740 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -97,28 +97,28 @@ static const char *cmpcode_to_str(int code) case MESHCMP_DVERT_WEIGHTMISMATCH: return "Vertex Weight Mismatch"; case MESHCMP_DVERT_GROUPMISMATCH: - return "Vertex Group Mismatch"; + return "Vertex Group Mismatch"; case MESHCMP_DVERT_TOTGROUPMISMATCH: - return "Vertex Doesn't Belong To Same Number Of Groups"; + return "Vertex Doesn't Belong To Same Number Of Groups"; case MESHCMP_LOOPCOLMISMATCH: - return "Vertex Color Mismatch"; + return "Vertex Color Mismatch"; case MESHCMP_LOOPUVMISMATCH: - return "UV Mismatch"; + return "UV Mismatch"; case MESHCMP_LOOPMISMATCH: - return "Loop Mismatch"; + return "Loop Mismatch"; case MESHCMP_POLYVERTMISMATCH: - return "Loop Vert Mismatch In Poly Test"; + return "Loop Vert Mismatch In Poly Test"; case MESHCMP_POLYMISMATCH: - return "Loop Vert Mismatch"; + return "Loop Vert Mismatch"; case MESHCMP_EDGEUNKNOWN: - return "Edge Mismatch"; + return "Edge Mismatch"; case MESHCMP_VERTCOMISMATCH: - return "Vertex Coordinate Mismatch"; + return "Vertex Coordinate Mismatch"; case MESHCMP_CDLAYERS_MISMATCH: - return "CustomData Layer Count Mismatch"; + return "CustomData Layer Count Mismatch"; default: - return "Mesh Comparison Code Unknown"; - } + return "Mesh Comparison Code Unknown"; + } } /* thresh is threshold for comparing vertices, uvs, vertex colors, @@ -126,7 +126,7 @@ static const char *cmpcode_to_str(int code) static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2, float thresh) { CustomDataLayer *l1, *l2; - int i, i1=0, i2=0, tot, j; + int i, i1 = 0, i2 = 0, tot, j; for (i = 0; i < c1->totlayer; i++) { if (ELEM7(c1->layers[i].type, CD_MVERT, CD_MEDGE, CD_MPOLY, @@ -150,7 +150,7 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 l1 = c1->layers; l2 = c2->layers; tot = i1; i1 = 0; i2 = 0; - for (i=0; i < tot; i++) { + for (i = 0; i < tot; i++) { while (i1 < c1->totlayer && !ELEM7(l1->type, CD_MVERT, CD_MEDGE, CD_MPOLY, CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT)) { @@ -168,7 +168,7 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 MVert *v2 = l2->data; int vtot = m1->totvert; - for (j=0; j<vtot; j++, v1++, v2++) { + for (j = 0; j < vtot; j++, v1++, v2++) { if (len_v3v3(v1->co, v2->co) > thresh) return MESHCMP_VERTCOMISMATCH; /*I don't care about normals, let's just do coodinates*/ @@ -182,11 +182,11 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 EdgeHash *eh = BLI_edgehash_new(); int etot = m1->totedge; - for (j=0; j<etot; j++, e1++) { + for (j = 0; j < etot; j++, e1++) { BLI_edgehash_insert(eh, e1->v1, e1->v2, e1); } - for (j=0; j<etot; j++, e2++) { + for (j = 0; j < etot; j++, e2++) { if (!BLI_edgehash_lookup(eh, e2->v1, e2->v2)) return MESHCMP_EDGEUNKNOWN; } @@ -198,7 +198,7 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 MPoly *p2 = l2->data; int ptot = m1->totpoly; - for (j=0; j<ptot; j++, p1++, p2++) { + for (j = 0; j < ptot; j++, p1++, p2++) { MLoop *lp1, *lp2; int k; @@ -208,7 +208,7 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 lp1 = m1->mloop + p1->loopstart; lp2 = m2->mloop + p2->loopstart; - for (k=0; k<p1->totloop; k++, lp1++, lp2++) { + for (k = 0; k < p1->totloop; k++, lp1++, lp2++) { if (lp1->v != lp2->v) return MESHCMP_POLYVERTMISMATCH; } @@ -219,7 +219,7 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 MLoop *lp2 = l2->data; int ltot = m1->totloop; - for (j=0; j<ltot; j++, lp1++, lp2++) { + for (j = 0; j < ltot; j++, lp1++, lp2++) { if (lp1->v != lp2->v) return MESHCMP_LOOPMISMATCH; } @@ -229,7 +229,7 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 MLoopUV *lp2 = l2->data; int ltot = m1->totloop; - for (j=0; j<ltot; j++, lp1++, lp2++) { + for (j = 0; j < ltot; j++, lp1++, lp2++) { if (len_v2v2(lp1->uv, lp2->uv) > thresh) return MESHCMP_LOOPUVMISMATCH; } @@ -240,7 +240,7 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 MLoopCol *lp2 = l2->data; int ltot = m1->totloop; - for (j=0; j<ltot; j++, lp1++, lp2++) { + for (j = 0; j < ltot; j++, lp1++, lp2++) { if (ABS(lp1->r - lp2->r) > thresh || ABS(lp1->g - lp2->g) > thresh || ABS(lp1->b - lp2->b) > thresh || @@ -256,14 +256,14 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 MDeformVert *dv2 = l2->data; int dvtot = m1->totvert; - for (j=0; j<dvtot; j++, dv1++, dv2++) { + for (j = 0; j < dvtot; j++, dv1++, dv2++) { int k; - MDeformWeight *dw1 = dv1->dw, *dw2=dv2->dw; + MDeformWeight *dw1 = dv1->dw, *dw2 = dv2->dw; if (dv1->totweight != dv2->totweight) return MESHCMP_DVERT_TOTGROUPMISMATCH; - for (k=0; k<dv1->totweight; k++, dw1++, dw2++) { + for (k = 0; k < dv1->totweight; k++, dw1++, dw2++) { if (dw1->def_nr != dw2->def_nr) return MESHCMP_DVERT_GROUPMISMATCH; if (ABS(dw1->weight - dw2->weight) > thresh) @@ -277,7 +277,7 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 } /*used for testing. returns an error string the two meshes don't match*/ -const char *mesh_cmp(Mesh *me1, Mesh *me2, float thresh) +const char *BKE_mesh_cmp(Mesh *me1, Mesh *me2, float thresh) { int c; @@ -293,7 +293,7 @@ const char *mesh_cmp(Mesh *me1, Mesh *me2, float thresh) if (me1->totpoly != me2->totpoly) return "Number of faces don't match"; - if (me1->totloop !=me2->totloop) + if (me1->totloop != me2->totloop) return "Number of loops don't match"; if ((c = customdata_compare(&me1->vdata, &me2->vdata, me1, me2, thresh))) @@ -327,7 +327,7 @@ static void mesh_ensure_tessellation_customdata(Mesh *me) const int totcol_tessface = CustomData_number_of_layers(&me->fdata, CD_MCOL); if (tottex_tessface != tottex_original || - totcol_tessface != totcol_original ) + totcol_tessface != totcol_original) { BKE_mesh_tessface_clear(me); @@ -340,8 +340,8 @@ static void mesh_ensure_tessellation_customdata(Mesh *me) * and check if there was any data to begin with, for now just print the warning with * some info to help troubleshoot whats going on - campbell */ printf("%s: warning! Tessellation uvs or vcol data got out of sync, " - "had to reset!\n CD_MTFACE: %d != CD_MTEXPOLY: %d || CD_MCOL: %d != CD_MLOOPCOL: %d\n", - __func__, tottex_tessface, tottex_original, totcol_tessface, totcol_original); + "had to reset!\n CD_MTFACE: %d != CD_MTEXPOLY: %d || CD_MCOL: %d != CD_MLOOPCOL: %d\n", + __func__, tottex_tessface, tottex_original, totcol_tessface, totcol_original); } } } @@ -392,30 +392,30 @@ void mesh_update_customdata_pointers(Mesh *me, const short do_ensure_tess_cd) * we need a more generic method, like the expand() functions in * readfile.c */ -void unlink_mesh(Mesh *me) +void BKE_mesh_unlink(Mesh *me) { int a; - if (me==NULL) return; + if (me == NULL) return; - for (a=0; a<me->totcol; a++) { + for (a = 0; a < me->totcol; a++) { if (me->mat[a]) me->mat[a]->id.us--; - me->mat[a]= NULL; + me->mat[a] = NULL; } if (me->key) { me->key->id.us--; } - me->key= NULL; + me->key = NULL; - if (me->texcomesh) me->texcomesh= NULL; + if (me->texcomesh) me->texcomesh = NULL; } /* do not free mesh itself */ -void free_mesh(Mesh *me, int unlink) +void BKE_mesh_free(Mesh *me, int unlink) { if (unlink) - unlink_mesh(me); + BKE_mesh_unlink(me); CustomData_free(&me->vdata, me->totvert); CustomData_free(&me->edata, me->totedge); @@ -425,7 +425,7 @@ void free_mesh(Mesh *me, int unlink) if (me->adt) { BKE_free_animdata(&me->id); - me->adt= NULL; + me->adt = NULL; } if (me->mat) MEM_freeN(me->mat); @@ -443,12 +443,12 @@ void copy_dverts(MDeformVert *dst, MDeformVert *src, int copycount) if (!src || !dst) return; - memcpy (dst, src, copycount * sizeof(MDeformVert)); + memcpy(dst, src, copycount * sizeof(MDeformVert)); - for (i=0; i<copycount; i++) { + for (i = 0; i < copycount; i++) { if (src[i].dw) { - dst[i].dw = MEM_callocN (sizeof(MDeformWeight)*src[i].totweight, "copy_deformWeight"); - memcpy (dst[i].dw, src[i].dw, sizeof (MDeformWeight)*src[i].totweight); + dst[i].dw = MEM_callocN(sizeof(MDeformWeight) * src[i].totweight, "copy_deformWeight"); + memcpy(dst[i].dw, src[i].dw, sizeof (MDeformWeight) * src[i].totweight); } } @@ -459,16 +459,16 @@ void free_dverts(MDeformVert *dvert, int totvert) /* Instead of freeing the verts directly, * call this function to delete any special * vert data */ - int i; + int i; if (!dvert) return; /* Free any special data from the verts */ - for (i=0; i<totvert; i++) { - if (dvert[i].dw) MEM_freeN (dvert[i].dw); + for (i = 0; i < totvert; i++) { + if (dvert[i].dw) MEM_freeN(dvert[i].dw); } - MEM_freeN (dvert); + MEM_freeN(dvert); } static void mesh_tessface_clear_intern(Mesh *mesh, int free_customdata) @@ -484,23 +484,22 @@ static void mesh_tessface_clear_intern(Mesh *mesh, int free_customdata) memset(&mesh->fdata, 0, sizeof(mesh->fdata)); } -Mesh *add_mesh(const char *name) +Mesh *BKE_mesh_add(const char *name) { Mesh *me; - me= alloc_libblock(&G.main->mesh, ID_ME, name); + me = BKE_libblock_alloc(&G.main->mesh, ID_ME, name); - me->size[0]= me->size[1]= me->size[2]= 1.0; - me->smoothresh= 30; - me->texflag= ME_AUTOSPACE; - me->flag= ME_TWOSIDED; - me->bb= unit_boundbox(); - me->drawflag= ME_DRAWEDGES|ME_DRAWFACES|ME_DRAWCREASES; + me->size[0] = me->size[1] = me->size[2] = 1.0; + me->smoothresh = 30; + me->texflag = ME_AUTOSPACE; + me->flag = ME_TWOSIDED; + me->drawflag = ME_DRAWEDGES | ME_DRAWFACES | ME_DRAWCREASES; return me; } -Mesh *copy_mesh(Mesh *me) +Mesh *BKE_mesh_copy(Mesh *me) { Mesh *men; MTFace *tface; @@ -508,10 +507,10 @@ Mesh *copy_mesh(Mesh *me) int a, i; const int do_tessface = ((me->totface != 0) && (me->totpoly == 0)); /* only do tessface if we have no polys */ - men= copy_libblock(&me->id); + men = BKE_libblock_copy(&me->id); - men->mat= MEM_dupallocN(me->mat); - for (a=0; a<men->totcol; a++) { + men->mat = MEM_dupallocN(me->mat); + for (a = 0; a < men->totcol; a++) { id_us_plus((ID *)men->mat[a]); } id_us_plus((ID *)men->texcomesh); @@ -530,33 +529,33 @@ Mesh *copy_mesh(Mesh *me) mesh_update_customdata_pointers(men, do_tessface); /* ensure indirect linked data becomes lib-extern */ - for (i=0; i<me->fdata.totlayer; i++) { + for (i = 0; i < me->fdata.totlayer; i++) { if (me->fdata.layers[i].type == CD_MTFACE) { - tface= (MTFace*)me->fdata.layers[i].data; + tface = (MTFace *)me->fdata.layers[i].data; - for (a=0; a<me->totface; a++, tface++) + for (a = 0; a < me->totface; a++, tface++) if (tface->tpage) - id_lib_extern((ID*)tface->tpage); + id_lib_extern((ID *)tface->tpage); } } - for (i=0; i<me->pdata.totlayer; i++) { + for (i = 0; i < me->pdata.totlayer; i++) { if (me->pdata.layers[i].type == CD_MTEXPOLY) { - txface= (MTexPoly*)me->pdata.layers[i].data; + txface = (MTexPoly *)me->pdata.layers[i].data; - for (a=0; a<me->totpoly; a++, txface++) + for (a = 0; a < me->totpoly; a++, txface++) if (txface->tpage) - id_lib_extern((ID*)txface->tpage); + id_lib_extern((ID *)txface->tpage); } } - men->mselect= NULL; - men->edit_btmesh= NULL; + men->mselect = NULL; + men->edit_btmesh = NULL; - men->bb= MEM_dupallocN(men->bb); + men->bb = MEM_dupallocN(men->bb); - men->key= copy_key(me->key); - if (men->key) men->key->from= (ID *)men; + men->key = BKE_key_copy(me->key); + if (men->key) men->key->from = (ID *)men; return men; } @@ -579,11 +578,11 @@ static void expand_local_mesh(Mesh *me) if (me->mtface || me->mtpoly) { int a, i; - for (i=0; i<me->pdata.totlayer; i++) { + for (i = 0; i < me->pdata.totlayer; i++) { if (me->pdata.layers[i].type == CD_MTEXPOLY) { - MTexPoly *txface= (MTexPoly*)me->fdata.layers[i].data; + MTexPoly *txface = (MTexPoly *)me->fdata.layers[i].data; - for (a=0; a<me->totpoly; a++, txface++) { + for (a = 0; a < me->totpoly; a++, txface++) { /* special case: ima always local immediately */ if (txface->tpage) { id_lib_extern((ID *)txface->tpage); @@ -592,11 +591,11 @@ static void expand_local_mesh(Mesh *me) } } - for (i=0; i<me->fdata.totlayer; i++) { + for (i = 0; i < me->fdata.totlayer; i++) { if (me->fdata.layers[i].type == CD_MTFACE) { - MTFace *tface= (MTFace*)me->fdata.layers[i].data; + MTFace *tface = (MTFace *)me->fdata.layers[i].data; - for (a=0; a<me->totface; a++, tface++) { + for (a = 0; a < me->totface; a++, tface++) { /* special case: ima always local immediately */ if (tface->tpage) { id_lib_extern((ID *)tface->tpage); @@ -611,28 +610,28 @@ static void expand_local_mesh(Mesh *me) } } -void make_local_mesh(Mesh *me) +void BKE_mesh_make_local(Mesh *me) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (me->id.lib==NULL) return; - if (me->id.us==1) { + if (me->id.lib == NULL) return; + if (me->id.us == 1) { id_clear_lib_data(bmain, &me->id); expand_local_mesh(me); return; } - for (ob= bmain->object.first; ob && ELEM(0, is_lib, is_local); ob= ob->id.next) { + for (ob = bmain->object.first; ob && ELEM(0, is_lib, is_local); ob = ob->id.next) { if (me == ob->data) { - if (ob->id.lib) is_lib= TRUE; - else is_local= TRUE; + if (ob->id.lib) is_lib = TRUE; + else is_local = TRUE; } } @@ -641,16 +640,16 @@ void make_local_mesh(Mesh *me) expand_local_mesh(me); } else if (is_local && is_lib) { - Mesh *me_new= copy_mesh(me); - me_new->id.us= 0; + Mesh *me_new = BKE_mesh_copy(me); + me_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, me->id.lib, &me_new->id); - for (ob= bmain->object.first; ob; ob= ob->id.next) { + for (ob = bmain->object.first; ob; ob = ob->id.next) { if (me == ob->data) { - if (ob->id.lib==NULL) { + if (ob->id.lib == NULL) { set_mesh(ob, me_new); } } @@ -658,45 +657,45 @@ void make_local_mesh(Mesh *me) } } -void boundbox_mesh(Mesh *me, float *loc, float *size) +void BKE_mesh_boundbox_calc(Mesh *me, float r_loc[3], float r_size[3]) { BoundBox *bb; float min[3], max[3]; float mloc[3], msize[3]; - if (me->bb==NULL) me->bb= MEM_callocN(sizeof(BoundBox), "boundbox"); - bb= me->bb; + if (me->bb == NULL) me->bb = MEM_callocN(sizeof(BoundBox), "boundbox"); + bb = me->bb; - if (!loc) loc= mloc; - if (!size) size= msize; + if (!r_loc) r_loc = mloc; + if (!r_size) r_size = msize; INIT_MINMAX(min, max); - if (!minmax_mesh(me, min, max)) { + if (!BKE_mesh_minmax(me, min, max)) { min[0] = min[1] = min[2] = -1.0f; max[0] = max[1] = max[2] = 1.0f; } - mid_v3_v3v3(loc, min, max); + mid_v3_v3v3(r_loc, min, max); - size[0]= (max[0]-min[0])/2.0f; - size[1]= (max[1]-min[1])/2.0f; - size[2]= (max[2]-min[2])/2.0f; + r_size[0] = (max[0] - min[0]) / 2.0f; + r_size[1] = (max[1] - min[1]) / 2.0f; + r_size[2] = (max[2] - min[2]) / 2.0f; - boundbox_set_from_min_max(bb, min, max); + BKE_boundbox_init_from_minmax(bb, min, max); } -void tex_space_mesh(Mesh *me) +void BKE_mesh_texspace_calc(Mesh *me) { float loc[3], size[3]; int a; - boundbox_mesh(me, loc, size); + BKE_mesh_boundbox_calc(me, loc, size); if (me->texflag & ME_AUTOSPACE) { - for (a=0; a<3; a++) { - 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; + for (a = 0; a < 3; a++) { + 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); @@ -705,69 +704,69 @@ void tex_space_mesh(Mesh *me) } } -BoundBox *mesh_get_bb(Object *ob) +BoundBox *BKE_mesh_boundbox_get(Object *ob) { - Mesh *me= ob->data; + Mesh *me = ob->data; if (ob->bb) return ob->bb; if (!me->bb) - tex_space_mesh(me); + BKE_mesh_texspace_calc(me); return me->bb; } -void mesh_get_texspace(Mesh *me, float r_loc[3], float r_rot[3], float r_size[3]) +void BKE_mesh_texspace_get(Mesh *me, float r_loc[3], float r_rot[3], float r_size[3]) { if (!me->bb) { - tex_space_mesh(me); + BKE_mesh_texspace_calc(me); } - if (r_loc) copy_v3_v3(r_loc, me->loc); - if (r_rot) copy_v3_v3(r_rot, me->rot); + if (r_loc) copy_v3_v3(r_loc, me->loc); + if (r_rot) copy_v3_v3(r_rot, me->rot); if (r_size) copy_v3_v3(r_size, me->size); } -float *get_mesh_orco_verts(Object *ob) +float *BKE_mesh_orco_verts_get(Object *ob) { Mesh *me = ob->data; MVert *mvert = NULL; - Mesh *tme = me->texcomesh?me->texcomesh:me; + Mesh *tme = me->texcomesh ? me->texcomesh : me; int a, totvert; float (*vcos)[3] = NULL; /* Get appropriate vertex coordinates */ - vcos = MEM_callocN(sizeof(*vcos)*me->totvert, "orco mesh"); + vcos = MEM_callocN(sizeof(*vcos) * me->totvert, "orco mesh"); mvert = tme->mvert; totvert = MIN2(tme->totvert, me->totvert); - for (a=0; a<totvert; a++, mvert++) { + for (a = 0; a < totvert; a++, mvert++) { copy_v3_v3(vcos[a], mvert->co); } - return (float*)vcos; + return (float *)vcos; } -void transform_mesh_orco_verts(Mesh *me, float (*orco)[3], int totvert, int invert) +void BKE_mesh_orco_verts_transform(Mesh *me, float (*orco)[3], int totvert, int invert) { float loc[3], size[3]; int a; - mesh_get_texspace(me->texcomesh?me->texcomesh:me, loc, NULL, size); + BKE_mesh_texspace_get(me->texcomesh ? me->texcomesh : me, loc, NULL, size); if (invert) { - for (a=0; a<totvert; a++) { + for (a = 0; a < totvert; a++) { float *co = orco[a]; madd_v3_v3v3v3(co, loc, co, size); } } else { - for (a=0; a<totvert; a++) { + for (a = 0; a < totvert; a++) { float *co = orco[a]; - co[0] = (co[0]-loc[0])/size[0]; - co[1] = (co[1]-loc[1])/size[1]; - co[2] = (co[2]-loc[2])/size[2]; + co[0] = (co[0] - loc[0]) / size[0]; + co[1] = (co[1] - loc[1]) / size[1]; + co[2] = (co[2] - loc[2]) / size[2]; } } } @@ -777,51 +776,51 @@ void transform_mesh_orco_verts(Mesh *me, float (*orco)[3], int totvert, int inve int test_index_face(MFace *mface, CustomData *fdata, int mfindex, int nr) { /* first test if the face is legal */ - if ((mface->v3 || nr==4) && mface->v3==mface->v4) { - mface->v4= 0; + if ((mface->v3 || nr == 4) && mface->v3 == mface->v4) { + mface->v4 = 0; nr--; } - if ((mface->v2 || mface->v4) && mface->v2==mface->v3) { - mface->v3= mface->v4; - mface->v4= 0; + if ((mface->v2 || mface->v4) && mface->v2 == mface->v3) { + mface->v3 = mface->v4; + mface->v4 = 0; nr--; } - if (mface->v1==mface->v2) { - mface->v2= mface->v3; - mface->v3= mface->v4; - mface->v4= 0; + if (mface->v1 == mface->v2) { + mface->v2 = mface->v3; + mface->v3 = mface->v4; + mface->v4 = 0; nr--; } /* check corrupt cases, bowtie geometry, cant handle these because edge data wont exist so just return 0 */ - if (nr==3) { + if (nr == 3) { if ( - /* real edges */ - mface->v1==mface->v2 || - mface->v2==mface->v3 || - mface->v3==mface->v1 - ) { + /* real edges */ + mface->v1 == mface->v2 || + mface->v2 == mface->v3 || + mface->v3 == mface->v1) + { return 0; } } - else if (nr==4) { + else if (nr == 4) { if ( - /* real edges */ - mface->v1==mface->v2 || - mface->v2==mface->v3 || - mface->v3==mface->v4 || - mface->v4==mface->v1 || - /* across the face */ - mface->v1==mface->v3 || - mface->v2==mface->v4 - ) { + /* real edges */ + mface->v1 == mface->v2 || + mface->v2 == mface->v3 || + mface->v3 == mface->v4 || + mface->v4 == mface->v1 || + /* across the face */ + mface->v1 == mface->v3 || + mface->v2 == mface->v4 + ) { return 0; } } /* prevent a zero at wrong index location */ - if (nr==3) { - if (mface->v3==0) { + if (nr == 3) { + if (mface->v3 == 0) { static int corner_indices[4] = {1, 2, 0, 3}; SWAP(unsigned int, mface->v1, mface->v2); @@ -831,8 +830,8 @@ int test_index_face(MFace *mface, CustomData *fdata, int mfindex, int nr) CustomData_swap(fdata, mfindex, corner_indices); } } - else if (nr==4) { - if (mface->v3==0 || mface->v4==0) { + else if (nr == 4) { + if (mface->v3 == 0 || mface->v4 == 0) { static int corner_indices[4] = {2, 3, 0, 1}; SWAP(unsigned int, mface->v1, mface->v3); @@ -846,27 +845,27 @@ int test_index_face(MFace *mface, CustomData *fdata, int mfindex, int nr) return nr; } -Mesh *get_mesh(Object *ob) +Mesh *BKE_mesh_from_object(Object *ob) { - if (ob==NULL) return NULL; - if (ob->type==OB_MESH) return ob->data; + if (ob == NULL) return NULL; + if (ob->type == OB_MESH) return ob->data; else return NULL; } void set_mesh(Object *ob, Mesh *me) { - Mesh *old=NULL; + Mesh *old = NULL; multires_force_update(ob); - if (ob==NULL) return; + if (ob == NULL) return; - if (ob->type==OB_MESH) { - old= ob->data; + if (ob->type == OB_MESH) { + old = ob->data; if (old) old->id.us--; - ob->data= me; + ob->data = me; id_us_plus((ID *)me); } @@ -887,24 +886,24 @@ static void to_edgesort(struct edgesort *ed, unsigned int v1, unsigned int v2, short is_loose, short is_draw) { - if (v1<v2) { - ed->v1= v1; ed->v2= v2; + if (v1 < v2) { + ed->v1 = v1; ed->v2 = v2; } else { - ed->v1= v2; ed->v2= v1; + ed->v1 = v2; ed->v2 = v1; } - ed->is_loose= is_loose; - ed->is_draw= is_draw; + ed->is_loose = is_loose; + ed->is_draw = is_draw; } static int vergedgesort(const void *v1, const void *v2) { - const struct edgesort *x1=v1, *x2=v2; + const struct edgesort *x1 = v1, *x2 = v2; - if ( x1->v1 > x2->v1) return 1; - else if ( x1->v1 < x2->v1) return -1; - else if ( x1->v2 > x2->v2) return 1; - else if ( x1->v2 < x2->v2) return -1; + if (x1->v1 > x2->v1) return 1; + else if (x1->v1 < x2->v1) return -1; + else if (x1->v2 > x2->v2) return 1; + else if (x1->v2 < x2->v2) return -1; return 0; } @@ -912,8 +911,8 @@ static int vergedgesort(const void *v1, const void *v2) /* Create edges based on known verts and faces */ static void make_edges_mdata(MVert *UNUSED(allvert), MFace *allface, MLoop *allloop, - MPoly *allpoly, int UNUSED(totvert), int totface, int UNUSED(totloop), int totpoly, - int old, MEdge **alledge, int *_totedge) + MPoly *allpoly, int UNUSED(totvert), int totface, int UNUSED(totloop), int totpoly, + int old, MEdge **alledge, int *_totedge) { MPoly *mpoly; MLoop *mloop; @@ -921,26 +920,26 @@ static void make_edges_mdata(MVert *UNUSED(allvert), MFace *allface, MLoop *alll MEdge *medge; EdgeHash *hash = BLI_edgehash_new(); struct edgesort *edsort, *ed; - int a, b, totedge=0, final=0; + int a, b, totedge = 0, final = 0; /* we put all edges in array, sort them, and detect doubles that way */ - for (a= totface, mface= allface; a>0; a--, mface++) { - if (mface->v4) totedge+=4; - else if (mface->v3) totedge+=3; - else totedge+=1; + for (a = totface, mface = allface; a > 0; a--, mface++) { + if (mface->v4) totedge += 4; + else if (mface->v3) totedge += 3; + else totedge += 1; } - if (totedge==0) { + if (totedge == 0) { /* flag that mesh has edges */ - (*alledge)= MEM_callocN(0, "make mesh edges"); + (*alledge) = MEM_callocN(0, "make mesh edges"); (*_totedge) = 0; return; } - ed= edsort= MEM_mallocN(totedge*sizeof(struct edgesort), "edgesort"); + ed = edsort = MEM_mallocN(totedge * sizeof(struct edgesort), "edgesort"); - for (a= totface, mface= allface; a>0; a--, mface++) { + for (a = totface, mface = allface; a > 0; a--, mface++) { to_edgesort(ed++, mface->v1, mface->v2, !mface->v3, mface->edcode & ME_V1V2); if (mface->v4) { to_edgesort(ed++, mface->v2, mface->v3, 0, mface->edcode & ME_V2V3); @@ -956,54 +955,54 @@ static void make_edges_mdata(MVert *UNUSED(allvert), MFace *allface, MLoop *alll qsort(edsort, totedge, sizeof(struct edgesort), vergedgesort); /* count final amount */ - for (a=totedge, ed=edsort; a>1; a--, ed++) { + for (a = totedge, ed = edsort; a > 1; a--, ed++) { /* edge is unique when it differs from next edge, or is last */ - if (ed->v1 != (ed+1)->v1 || ed->v2 != (ed+1)->v2) final++; + if (ed->v1 != (ed + 1)->v1 || ed->v2 != (ed + 1)->v2) final++; } final++; - (*alledge)= medge= MEM_callocN(sizeof (MEdge) * final, "make_edges mdge"); - (*_totedge)= final; + (*alledge) = medge = MEM_callocN(sizeof (MEdge) * final, "BKE_mesh_make_edges mdge"); + (*_totedge) = final; - for (a=totedge, ed=edsort; a>1; a--, ed++) { + for (a = totedge, ed = edsort; a > 1; a--, ed++) { /* edge is unique when it differs from next edge, or is last */ - if (ed->v1 != (ed+1)->v1 || ed->v2 != (ed+1)->v2) { - medge->v1= ed->v1; - medge->v2= ed->v2; - if (old==0 || ed->is_draw) medge->flag= ME_EDGEDRAW|ME_EDGERENDER; - if (ed->is_loose) medge->flag|= ME_LOOSEEDGE; + if (ed->v1 != (ed + 1)->v1 || ed->v2 != (ed + 1)->v2) { + medge->v1 = ed->v1; + medge->v2 = ed->v2; + if (old == 0 || ed->is_draw) medge->flag = ME_EDGEDRAW | ME_EDGERENDER; + if (ed->is_loose) medge->flag |= ME_LOOSEEDGE; /* order is swapped so extruding this edge as a surface wont flip face normals * with cyclic curves */ - if (ed->v1+1 != ed->v2) { + if (ed->v1 + 1 != ed->v2) { SWAP(unsigned int, medge->v1, medge->v2); } medge++; } else { /* equal edge, we merge the drawflag */ - (ed+1)->is_draw |= ed->is_draw; + (ed + 1)->is_draw |= ed->is_draw; } } /* last edge */ - medge->v1= ed->v1; - medge->v2= ed->v2; - medge->flag= ME_EDGEDRAW; - if (ed->is_loose) medge->flag|= ME_LOOSEEDGE; + medge->v1 = ed->v1; + medge->v2 = ed->v2; + medge->flag = ME_EDGEDRAW; + if (ed->is_loose) medge->flag |= ME_LOOSEEDGE; medge->flag |= ME_EDGERENDER; MEM_freeN(edsort); /*set edge members of mloops*/ - medge= *alledge; - for (a=0; a<*_totedge; a++, medge++) { + 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++) { + for (a = 0; a < totpoly; a++, mpoly++) { mloop = allloop + mpoly->loopstart; - for (b=0; b<mpoly->totloop; b++) { + for (b = 0; b < mpoly->totloop; b++) { int v1, v2; v1 = mloop[b].v; @@ -1015,28 +1014,28 @@ static void make_edges_mdata(MVert *UNUSED(allvert), MFace *allface, MLoop *alll BLI_edgehash_free(hash, NULL); } -void make_edges(Mesh *me, int old) +void BKE_mesh_make_edges(Mesh *me, int old) { MEdge *medge; - int totedge=0; + int totedge = 0; 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) { + if (totedge == 0) { /* flag that mesh has edges */ me->medge = medge; me->totedge = 0; return; } - medge= CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, medge, totedge); - me->medge= medge; - me->totedge= totedge; + medge = CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, medge, totedge); + me->medge = medge; + me->totedge = totedge; - mesh_strip_loose_faces(me); + BKE_mesh_strip_loose_faces(me); } /* We need to keep this for edge creation (for now?), and some old readfile code... */ -void mesh_strip_loose_faces(Mesh *me) +void BKE_mesh_strip_loose_faces(Mesh *me) { MFace *f; int a, b; @@ -1060,7 +1059,7 @@ void mesh_strip_loose_faces(Mesh *me) /* Note: It won't try to guess which loops of an invalid poly to remove! * this is the work of the caller, to mark those loops... * See e.g. BKE_mesh_validate_arrays(). */ -void mesh_strip_loose_polysloops(Mesh *me) +void BKE_mesh_strip_loose_polysloops(Mesh *me) { MPoly *p; MLoop *l; @@ -1131,7 +1130,7 @@ void mesh_strip_loose_polysloops(Mesh *me) MEM_freeN(new_idx); } -void mesh_strip_loose_edges(Mesh *me) +void BKE_mesh_strip_loose_edges(Mesh *me) { MEdge *e; MLoop *l; @@ -1166,7 +1165,7 @@ void mesh_strip_loose_edges(Mesh *me) MEM_freeN(new_idx); } -void mball_to_mesh(ListBase *lb, Mesh *me) +void BKE_mesh_from_metaball(ListBase *lb, Mesh *me) { DispList *dl; MVert *mvert; @@ -1175,55 +1174,55 @@ void mball_to_mesh(ListBase *lb, Mesh *me) float *nors, *verts; int a, *index; - dl= lb->first; - if (dl==NULL) return; - - if (dl->type==DL_INDEX4) { - mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, dl->nr); - allloop= mloop= CustomData_add_layer(&me->ldata, CD_MLOOP, CD_CALLOC, NULL, dl->parts * 4); - mpoly= CustomData_add_layer(&me->pdata, CD_MPOLY, CD_CALLOC, NULL, dl->parts); - me->mvert= mvert; - me->mloop= mloop; - me->mpoly= mpoly; - me->totvert= dl->nr; - me->totpoly= dl->parts; - - a= dl->nr; - nors= dl->nors; - verts= dl->verts; + dl = lb->first; + if (dl == NULL) return; + + if (dl->type == DL_INDEX4) { + mvert = CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, dl->nr); + allloop = mloop = CustomData_add_layer(&me->ldata, CD_MLOOP, CD_CALLOC, NULL, dl->parts * 4); + mpoly = CustomData_add_layer(&me->pdata, CD_MPOLY, CD_CALLOC, NULL, dl->parts); + me->mvert = mvert; + me->mloop = mloop; + me->mpoly = mpoly; + me->totvert = dl->nr; + me->totpoly = dl->parts; + + a = dl->nr; + nors = dl->nors; + verts = dl->verts; while (a--) { copy_v3_v3(mvert->co, verts); normal_float_to_short_v3(mvert->no, nors); mvert++; - nors+= 3; - verts+= 3; + nors += 3; + verts += 3; } - a= dl->parts; - index= dl->index; + a = dl->parts; + index = dl->index; while (a--) { - int count= index[2] != index[3] ? 4 : 3; + int count = index[2] != index[3] ? 4 : 3; - mloop[0].v= index[0]; - mloop[1].v= index[1]; - mloop[2].v= index[2]; + mloop[0].v = index[0]; + mloop[1].v = index[1]; + mloop[2].v = index[2]; if (count == 4) - mloop[3].v= index[3]; + mloop[3].v = index[3]; - mpoly->totloop= count; - mpoly->loopstart= (int)(mloop - allloop); - mpoly->flag= ME_SMOOTH; + mpoly->totloop = count; + mpoly->loopstart = (int)(mloop - allloop); + mpoly->flag = ME_SMOOTH; mpoly++; - mloop+= count; - me->totloop+= count; - index+= 4; + mloop += count; + me->totloop += count; + index += 4; } mesh_update_customdata_pointers(me, TRUE); - mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL); + BKE_mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL); BKE_mesh_calc_edges(me, TRUE); } @@ -1231,15 +1230,15 @@ void mball_to_mesh(ListBase *lb, Mesh *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, MLoop **allloop, MPoly **allpoly, - int *totloop, int *totpoly) +int BKE_mesh_nurbs_to_mdata(Object *ob, MVert **allvert, int *totvert, + MEdge **alledge, int *totedge, MLoop **allloop, MPoly **allpoly, + int *totloop, int *totpoly) { - return nurbs_to_mdata_customdb(ob, &ob->disp, - allvert, totvert, - alledge, totedge, - allloop, allpoly, - totloop, totpoly); + return BKE_mesh_nurbs_to_mdata_customdb(ob, &ob->disp, + allvert, totvert, + alledge, totedge, + allloop, allpoly, + totloop, totpoly); } /* BMESH: this doesn't calculate all edges from polygons, @@ -1247,11 +1246,11 @@ int nurbs_to_mdata(Object *ob, MVert **allvert, int *totvert, /* 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, - MLoop **allloop, MPoly **allpoly, - int *_totloop, int *_totpoly) +int BKE_mesh_nurbs_to_mdata_customdb(Object *ob, ListBase *dispbase, + MVert **allvert, int *_totvert, + MEdge **alledge, int *_totedge, + MLoop **allloop, MPoly **allpoly, + int *_totloop, int *_totpoly) { DispList *dl; Curve *cu; @@ -1260,46 +1259,46 @@ int nurbs_to_mdata_customdb(Object *ob, ListBase *dispbase, MLoop *mloop; MEdge *medge; float *data; - int a, b, ofs, vertcount, startvert, totvert=0, totedge=0, totloop=0, totvlak=0; + int a, b, ofs, vertcount, startvert, totvert = 0, totedge = 0, totloop = 0, totvlak = 0; int p1, p2, p3, p4, *index; - int conv_polys= 0; + int conv_polys = 0; - cu= ob->data; + cu = ob->data; - conv_polys|= cu->flag & CU_3D; /* 2d polys are filled with DL_INDEX3 displists */ - conv_polys|= ob->type == OB_SURF; /* surf polys are never filled */ + conv_polys |= cu->flag & CU_3D; /* 2d polys are filled with DL_INDEX3 displists */ + conv_polys |= ob->type == OB_SURF; /* surf polys are never filled */ /* count */ - dl= dispbase->first; + dl = dispbase->first; while (dl) { - if (dl->type==DL_SEGM) { - totvert+= dl->parts*dl->nr; - totedge+= dl->parts*(dl->nr-1); + if (dl->type == DL_SEGM) { + totvert += dl->parts * dl->nr; + totedge += dl->parts * (dl->nr - 1); } - else if (dl->type==DL_POLY) { + else if (dl->type == DL_POLY) { if (conv_polys) { - totvert+= dl->parts*dl->nr; - totedge+= dl->parts*dl->nr; + totvert += dl->parts * dl->nr; + totedge += dl->parts * dl->nr; } } - else if (dl->type==DL_SURF) { + else if (dl->type == DL_SURF) { int tot; - totvert+= dl->parts*dl->nr; - tot = (dl->parts-1+((dl->flag & DL_CYCL_V)==2))*(dl->nr-1+(dl->flag & DL_CYCL_U)); + totvert += dl->parts * dl->nr; + tot = (dl->parts - 1 + ((dl->flag & DL_CYCL_V) == 2)) * (dl->nr - 1 + (dl->flag & DL_CYCL_U)); totvlak += tot; totloop += tot * 4; } - else if (dl->type==DL_INDEX3) { + else if (dl->type == DL_INDEX3) { int tot; - totvert+= dl->nr; + totvert += dl->nr; tot = dl->parts; - totvlak+= tot; + totvlak += tot; totloop += tot * 3; } - dl= dl->next; + dl = dl->next; } - if (totvert==0) { + if (totvert == 0) { /* error("can't convert"); */ /* Make Sure you check ob->data is a curve */ return -1; @@ -1311,28 +1310,28 @@ int nurbs_to_mdata_customdb(Object *ob, ListBase *dispbase, *allpoly = mpoly = MEM_callocN(sizeof(MPoly) * totvlak, "nurbs_init mloop"); /* verts and faces */ - vertcount= 0; + vertcount = 0; - dl= dispbase->first; + dl = dispbase->first; while (dl) { - int smooth= dl->rt & CU_SMOOTH ? 1 : 0; + int smooth = dl->rt & CU_SMOOTH ? 1 : 0; - if (dl->type==DL_SEGM) { - startvert= vertcount; - a= dl->parts*dl->nr; - data= dl->verts; + if (dl->type == DL_SEGM) { + startvert = vertcount; + a = dl->parts * dl->nr; + data = dl->verts; while (a--) { copy_v3_v3(mvert->co, data); - data+=3; + data += 3; vertcount++; mvert++; } - for (a=0; a<dl->parts; a++) { - ofs= a*dl->nr; - for (b=1; b<dl->nr; b++) { - medge->v1= startvert+ofs+b-1; - medge->v2= startvert+ofs+b; + for (a = 0; a < dl->parts; a++) { + ofs = a * dl->nr; + for (b = 1; b < dl->nr; b++) { + medge->v1 = startvert + ofs + b - 1; + medge->v2 = startvert + ofs + b; medge->flag = ME_LOOSEEDGE | ME_EDGERENDER | ME_EDGEDRAW; medge++; @@ -1340,122 +1339,122 @@ int nurbs_to_mdata_customdb(Object *ob, ListBase *dispbase, } } - else if (dl->type==DL_POLY) { + else if (dl->type == DL_POLY) { if (conv_polys) { - startvert= vertcount; - a= dl->parts*dl->nr; - data= dl->verts; + startvert = vertcount; + a = dl->parts * dl->nr; + data = dl->verts; while (a--) { copy_v3_v3(mvert->co, data); - data+=3; + data += 3; vertcount++; mvert++; } - for (a=0; a<dl->parts; a++) { - ofs= a*dl->nr; - for (b=0; b<dl->nr; b++) { - medge->v1= startvert+ofs+b; - if (b==dl->nr-1) medge->v2= startvert+ofs; - else medge->v2= startvert+ofs+b+1; + for (a = 0; a < dl->parts; a++) { + ofs = a * dl->nr; + for (b = 0; b < dl->nr; b++) { + medge->v1 = startvert + ofs + b; + if (b == dl->nr - 1) medge->v2 = startvert + ofs; + else medge->v2 = startvert + ofs + b + 1; medge->flag = ME_LOOSEEDGE | ME_EDGERENDER | ME_EDGEDRAW; medge++; } } } } - else if (dl->type==DL_INDEX3) { - startvert= vertcount; - a= dl->nr; - data= dl->verts; + else if (dl->type == DL_INDEX3) { + startvert = vertcount; + a = dl->nr; + data = dl->verts; while (a--) { copy_v3_v3(mvert->co, data); - data+=3; + data += 3; vertcount++; mvert++; } - a= dl->parts; - index= dl->index; + a = dl->parts; + index = dl->index; while (a--) { - mloop[0].v = startvert+index[0]; - mloop[1].v = startvert+index[2]; - mloop[2].v = startvert+index[1]; + mloop[0].v = startvert + index[0]; + mloop[1].v = startvert + index[2]; + mloop[2].v = startvert + index[1]; mpoly->loopstart = (int)(mloop - (*allloop)); mpoly->totloop = 3; mpoly->mat_nr = dl->col; if (smooth) mpoly->flag |= ME_SMOOTH; mpoly++; - mloop+= 3; - index+= 3; + mloop += 3; + index += 3; } } - else if (dl->type==DL_SURF) { - startvert= vertcount; - a= dl->parts*dl->nr; - data= dl->verts; + else if (dl->type == DL_SURF) { + startvert = vertcount; + a = dl->parts * dl->nr; + data = dl->verts; while (a--) { copy_v3_v3(mvert->co, data); - data+=3; + data += 3; vertcount++; mvert++; } - for (a=0; a<dl->parts; a++) { + for (a = 0; a < dl->parts; a++) { - if ( (dl->flag & DL_CYCL_V)==0 && a==dl->parts-1) break; + if ( (dl->flag & DL_CYCL_V) == 0 && a == dl->parts - 1) break; - if (dl->flag & DL_CYCL_U) { /* p2 -> p1 -> */ - p1= startvert+ dl->nr*a; /* p4 -> p3 -> */ - p2= p1+ dl->nr-1; /* -----> next row */ - p3= p1+ dl->nr; - p4= p2+ dl->nr; - b= 0; + if (dl->flag & DL_CYCL_U) { /* p2 -> p1 -> */ + p1 = startvert + dl->nr * a; /* p4 -> p3 -> */ + p2 = p1 + dl->nr - 1; /* -----> next row */ + p3 = p1 + dl->nr; + p4 = p2 + dl->nr; + b = 0; } else { - p2= startvert+ dl->nr*a; - p1= p2+1; - p4= p2+ dl->nr; - p3= p1+ dl->nr; - b= 1; + p2 = startvert + dl->nr * a; + p1 = p2 + 1; + p4 = p2 + dl->nr; + p3 = p1 + dl->nr; + b = 1; } - if ( (dl->flag & DL_CYCL_V) && a==dl->parts-1) { - p3-= dl->parts*dl->nr; - p4-= dl->parts*dl->nr; + if ( (dl->flag & DL_CYCL_V) && a == dl->parts - 1) { + p3 -= dl->parts * dl->nr; + p4 -= dl->parts * dl->nr; } - for (; b<dl->nr; b++) { - mloop[0].v= p1; - mloop[1].v= p3; - mloop[2].v= p4; - mloop[3].v= p2; + for (; b < dl->nr; b++) { + mloop[0].v = p1; + mloop[1].v = p3; + mloop[2].v = p4; + mloop[3].v = p2; mpoly->loopstart = (int)(mloop - (*allloop)); mpoly->totloop = 4; mpoly->mat_nr = dl->col; if (smooth) mpoly->flag |= ME_SMOOTH; mpoly++; - mloop+= 4; + mloop += 4; - p4= p3; + p4 = p3; p3++; - p2= p1; + p2 = p1; p1++; } } } - dl= dl->next; + dl = dl->next; } - *_totpoly= totvlak; - *_totloop= totloop; - *_totedge= totedge; - *_totvert= totvert; + *_totpoly = totvlak; + *_totloop = totloop; + *_totedge = totedge; + *_totvert = totvert; /* not uded for bmesh */ #if 0 @@ -1467,72 +1466,75 @@ int nurbs_to_mdata_customdb(Object *ob, ListBase *dispbase, } /* this may fail replacing ob->data, be sure to check ob->type */ -void nurbs_to_mesh(Object *ob) +void BKE_mesh_from_nurbs(Object *ob) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob1; - DerivedMesh *dm= ob->derivedFinal; + DerivedMesh *dm = ob->derivedFinal; Mesh *me; Curve *cu; - MVert *allvert= NULL; - MEdge *alledge= NULL; + MVert *allvert = NULL; + MEdge *alledge = NULL; MLoop *allloop = NULL; MPoly *allpoly = NULL; int totvert, totedge, totloop, totpoly; - cu= ob->data; + cu = ob->data; if (dm == NULL) { - if (nurbs_to_mdata(ob, &allvert, &totvert, &alledge, &totedge, &allloop, &allpoly, &totloop, &totpoly) != 0) { + if (BKE_mesh_nurbs_to_mdata(ob, &allvert, &totvert, + &alledge, &totedge, &allloop, + &allpoly, &totloop, &totpoly) != 0) + { /* Error initializing */ return; } /* make mesh */ - me= add_mesh("Mesh"); - me->totvert= totvert; - me->totedge= totedge; + me = BKE_mesh_add("Mesh"); + me->totvert = totvert; + me->totedge = totedge; me->totloop = totloop; me->totpoly = totpoly; - me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, allvert, me->totvert); - me->medge= CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, alledge, me->totedge); - 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); + me->mvert = CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, allvert, me->totvert); + me->medge = CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, alledge, me->totedge); + 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->mloop, me->mpoly, me->totloop, me->totpoly, NULL); + BKE_mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL); BKE_mesh_calc_edges(me, TRUE); } else { - me= add_mesh("Mesh"); + me = BKE_mesh_add("Mesh"); DM_to_mesh(dm, me, ob); } - me->totcol= cu->totcol; - me->mat= cu->mat; + me->totcol = cu->totcol; + me->mat = cu->mat; - tex_space_mesh(me); + BKE_mesh_texspace_calc(me); - cu->mat= NULL; - cu->totcol= 0; + cu->mat = NULL; + cu->totcol = 0; if (ob->data) { - free_libblock(&bmain->curve, ob->data); + BKE_libblock_free(&bmain->curve, ob->data); } - ob->data= me; - ob->type= OB_MESH; + ob->data = me; + ob->type = OB_MESH; /* other users */ - ob1= bmain->object.first; + ob1 = bmain->object.first; while (ob1) { - if (ob1->data==cu) { - ob1->type= OB_MESH; + if (ob1->data == cu) { + ob1->type = OB_MESH; - ob1->data= ob->data; + ob1->data = ob->data; id_us_plus((ID *)ob->data); } - ob1= ob1->id.next; + ob1 = ob1->id.next; } } @@ -1548,26 +1550,26 @@ typedef struct VertLink { static void prependPolyLineVert(ListBase *lb, unsigned int index) { - VertLink *vl= MEM_callocN(sizeof(VertLink), "VertLink"); + VertLink *vl = MEM_callocN(sizeof(VertLink), "VertLink"); vl->index = index; BLI_addhead(lb, vl); } static void appendPolyLineVert(ListBase *lb, unsigned int index) { - VertLink *vl= MEM_callocN(sizeof(VertLink), "VertLink"); + VertLink *vl = MEM_callocN(sizeof(VertLink), "VertLink"); vl->index = index; BLI_addtail(lb, vl); } -void mesh_to_curve(Scene *scene, Object *ob) +void BKE_mesh_from_curve(Scene *scene, Object *ob) { /* make new mesh data from the original copy */ - DerivedMesh *dm= mesh_get_derived_final(scene, ob, CD_MASK_MESH); + DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_MESH); - MVert *mverts= dm->getVertArray(dm); - MEdge *med, *medge= dm->getEdgeArray(dm); - MFace *mf, *mface= dm->getTessFaceArray(dm); + MVert *mverts = dm->getVertArray(dm); + MEdge *med, *medge = dm->getEdgeArray(dm); + MFace *mf, *mface = dm->getTessFaceArray(dm); int totedge = dm->getNumEdges(dm); int totface = dm->getNumTessFaces(dm); @@ -1582,7 +1584,7 @@ void mesh_to_curve(Scene *scene, Object *ob) ListBase edges = {NULL, NULL}; /* create edges from all faces (so as to find edges not in any faces) */ - mf= mface; + mf = mface; for (i = 0; i < totface; i++, mf++) { if (!BLI_edgehash_haskey(eh, mf->v1, mf->v2)) BLI_edgehash_insert(eh, mf->v1, mf->v2, NULL); @@ -1601,22 +1603,22 @@ void mesh_to_curve(Scene *scene, Object *ob) } } - med= medge; - for (i=0; i<totedge; i++, med++) { + med = medge; + for (i = 0; i < totedge; i++, med++) { if (!BLI_edgehash_haskey(eh, med->v1, med->v2)) { - EdgeLink *edl= MEM_callocN(sizeof(EdgeLink), "EdgeLink"); + EdgeLink *edl = MEM_callocN(sizeof(EdgeLink), "EdgeLink"); BLI_edgehash_insert(eh_edge, med->v1, med->v2, NULL); - edl->edge= med; + edl->edge = med; - BLI_addtail(&edges, edl); totedges++; + BLI_addtail(&edges, edl); totedges++; } } BLI_edgehash_free(eh_edge, NULL); BLI_edgehash_free(eh, NULL); if (edges.first) { - Curve *cu = BKE_curve_add(ob->id.name+2, OB_CURVE); + Curve *cu = BKE_curve_add(ob->id.name + 2, OB_CURVE); cu->flag |= CU_3D; while (edges.first) { @@ -1624,55 +1626,55 @@ void mesh_to_curve(Scene *scene, Object *ob) ListBase polyline = {NULL, NULL}; /* store a list of VertLink's */ int closed = FALSE; - int totpoly= 0; - MEdge *med_current= ((EdgeLink *)edges.last)->edge; - unsigned int startVert= med_current->v1; - unsigned int endVert= med_current->v2; - int ok= TRUE; + int totpoly = 0; + MEdge *med_current = ((EdgeLink *)edges.last)->edge; + unsigned int startVert = med_current->v1; + unsigned int endVert = med_current->v2; + int ok = TRUE; - appendPolyLineVert(&polyline, startVert); totpoly++; - appendPolyLineVert(&polyline, endVert); totpoly++; - BLI_freelinkN(&edges, edges.last); totedges--; + appendPolyLineVert(&polyline, startVert); totpoly++; + appendPolyLineVert(&polyline, endVert); totpoly++; + BLI_freelinkN(&edges, edges.last); totedges--; while (ok) { /* while connected edges are found... */ ok = FALSE; - i= totedges; + i = totedges; while (i) { EdgeLink *edl; - i-=1; - edl= BLI_findlink(&edges, i); - med= edl->edge; + i -= 1; + edl = BLI_findlink(&edges, i); + med = edl->edge; - if (med->v1==endVert) { + if (med->v1 == endVert) { endVert = med->v2; - appendPolyLineVert(&polyline, med->v2); totpoly++; - BLI_freelinkN(&edges, edl); totedges--; - ok= TRUE; + appendPolyLineVert(&polyline, med->v2); totpoly++; + BLI_freelinkN(&edges, edl); totedges--; + ok = TRUE; } - else if (med->v2==endVert) { + else if (med->v2 == endVert) { endVert = med->v1; - appendPolyLineVert(&polyline, endVert); totpoly++; - BLI_freelinkN(&edges, edl); totedges--; - ok= TRUE; + appendPolyLineVert(&polyline, endVert); totpoly++; + BLI_freelinkN(&edges, edl); totedges--; + ok = TRUE; } - else if (med->v1==startVert) { + else if (med->v1 == startVert) { startVert = med->v2; - prependPolyLineVert(&polyline, startVert); totpoly++; - BLI_freelinkN(&edges, edl); totedges--; - ok= TRUE; + prependPolyLineVert(&polyline, startVert); totpoly++; + BLI_freelinkN(&edges, edl); totedges--; + ok = TRUE; } - else if (med->v2==startVert) { + else if (med->v2 == startVert) { startVert = med->v1; - prependPolyLineVert(&polyline, startVert); totpoly++; - BLI_freelinkN(&edges, edl); totedges--; - ok= TRUE; + prependPolyLineVert(&polyline, startVert); totpoly++; + BLI_freelinkN(&edges, edl); totedges--; + ok = TRUE; } } } /* Now we have a polyline, make into a curve */ - if (startVert==endVert) { + if (startVert == endVert) { BLI_freelinkN(&polyline, polyline.last); totpoly--; closed = TRUE; @@ -1687,19 +1689,19 @@ void mesh_to_curve(Scene *scene, Object *ob) /* create new 'nurb' within the curve */ nu = (Nurb *)MEM_callocN(sizeof(Nurb), "MeshNurb"); - nu->pntsu= totpoly; - nu->pntsv= 1; - nu->orderu= 4; - nu->flagu= CU_NURB_ENDPOINT | (closed ? CU_NURB_CYCLIC:0); /* endpoint */ - nu->resolu= 12; + nu->pntsu = totpoly; + nu->pntsv = 1; + nu->orderu = 4; + nu->flagu = CU_NURB_ENDPOINT | (closed ? CU_NURB_CYCLIC : 0); /* endpoint */ + nu->resolu = 12; - nu->bp= (BPoint *)MEM_callocN(sizeof(BPoint)*totpoly, "bpoints"); + nu->bp = (BPoint *)MEM_callocN(sizeof(BPoint) * totpoly, "bpoints"); /* add points */ - vl= polyline.first; - for (i=0, bp=nu->bp; i < totpoly; i++, bp++, vl=(VertLink *)vl->next) { + vl = polyline.first; + for (i = 0, bp = nu->bp; i < totpoly; i++, bp++, vl = (VertLink *)vl->next) { copy_v3_v3(bp->vec, mverts[vl->index].co); - bp->f1= SELECT; + bp->f1 = SELECT; bp->radius = bp->weight = 1.0; } BLI_freelistN(&polyline); @@ -1711,11 +1713,11 @@ void mesh_to_curve(Scene *scene, Object *ob) } ((Mesh *)ob->data)->id.us--; - ob->data= cu; - ob->type= OB_CURVE; + ob->data = cu; + ob->type = OB_CURVE; /* curve objects can't contain DM in usual cases, we could free memory */ - needsFree= 1; + needsFree = 1; } dm->needsFree = needsFree; @@ -1727,35 +1729,35 @@ void mesh_to_curve(Scene *scene, Object *ob) /* curve object could have got bounding box only in special cases */ if (ob->bb) { MEM_freeN(ob->bb); - ob->bb= NULL; + ob->bb = NULL; } } } -void mesh_delete_material_index(Mesh *me, short index) +void BKE_mesh_delete_material_index(Mesh *me, short index) { int i; - for (i=0; i<me->totpoly; i++) { - MPoly *mp = &((MPoly*) me->mpoly)[i]; - if (mp->mat_nr && mp->mat_nr>=index) + for (i = 0; i < me->totpoly; i++) { + MPoly *mp = &((MPoly *) me->mpoly)[i]; + if (mp->mat_nr && mp->mat_nr >= index) mp->mat_nr--; } - for (i=0; i<me->totface; i++) { - MFace *mf = &((MFace*) me->mface)[i]; - if (mf->mat_nr && mf->mat_nr>=index) + for (i = 0; i < me->totface; i++) { + MFace *mf = &((MFace *) me->mface)[i]; + if (mf->mat_nr && mf->mat_nr >= index) mf->mat_nr--; } } -void mesh_set_smooth_flag(Object *meshOb, int enableSmooth) +void BKE_mesh_smooth_flag_set(Object *meshOb, int enableSmooth) { Mesh *me = meshOb->data; int i; - for (i=0; i<me->totpoly; i++) { - MPoly *mp = &((MPoly*) me->mpoly)[i]; + for (i = 0; i < me->totpoly; i++) { + MPoly *mp = &((MPoly *) me->mpoly)[i]; if (enableSmooth) { mp->flag |= ME_SMOOTH; @@ -1765,8 +1767,8 @@ void mesh_set_smooth_flag(Object *meshOb, int enableSmooth) } } - for (i=0; i<me->totface; i++) { - MFace *mf = &((MFace*) me->mface)[i]; + for (i = 0; i < me->totface; i++) { + MFace *mf = &((MFace *) me->mface)[i]; if (enableSmooth) { mf->flag |= ME_SMOOTH; @@ -1777,20 +1779,20 @@ void mesh_set_smooth_flag(Object *meshOb, int enableSmooth) } } -void mesh_calc_normals_mapping(MVert *mverts, int numVerts, - MLoop *mloop, MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3], - MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3]) +void BKE_mesh_calc_normals_mapping(MVert *mverts, int numVerts, + MLoop *mloop, MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3], + MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3]) { - mesh_calc_normals_mapping_ex(mverts, numVerts, mloop, mpolys, - numLoops, numPolys, polyNors_r, mfaces, numFaces, - origIndexFace, faceNors_r, FALSE); + BKE_mesh_calc_normals_mapping_ex(mverts, numVerts, mloop, mpolys, + numLoops, numPolys, polyNors_r, mfaces, numFaces, + origIndexFace, faceNors_r, FALSE); } -void mesh_calc_normals_mapping_ex(MVert *mverts, int numVerts, - MLoop *mloop, MPoly *mpolys, - int numLoops, int numPolys, float (*polyNors_r)[3], - MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3], - const short only_face_normals) +void BKE_mesh_calc_normals_mapping_ex(MVert *mverts, int numVerts, + MLoop *mloop, MPoly *mpolys, + int numLoops, int numPolys, float (*polyNors_r)[3], + MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3], + const short only_face_normals) { float (*pnors)[3] = polyNors_r, (*fnors)[3] = faceNors_r; int i; @@ -1814,29 +1816,29 @@ void mesh_calc_normals_mapping_ex(MVert *mverts, int numVerts, if (only_face_normals == FALSE) { /* vertex normals are optional, they require some extra calculations, * so make them optional */ - mesh_calc_normals(mverts, numVerts, mloop, mpolys, numLoops, numPolys, pnors); + BKE_mesh_calc_normals(mverts, numVerts, mloop, mpolys, numLoops, numPolys, pnors); } else { /* only calc poly normals */ mp = mpolys; - for (i=0; i<numPolys; i++, mp++) { - mesh_calc_poly_normal(mp, mloop+mp->loopstart, mverts, pnors[i]); + for (i = 0; i < numPolys; i++, mp++) { + mesh_calc_poly_normal(mp, mloop + mp->loopstart, mverts, pnors[i]); } } - if ( origIndexFace && - /* fnors==faceNors_r */ /* NO NEED TO ALLOC YET */ - fnors != NULL && - numFaces) + if (origIndexFace && + /* fnors==faceNors_r */ /* NO NEED TO ALLOC YET */ + fnors != NULL && + numFaces) { mf = mfaces; - for (i=0; i<numFaces; i++, mf++, origIndexFace++) { + for (i = 0; i < numFaces; i++, mf++, origIndexFace++) { if (*origIndexFace < numPolys) { copy_v3_v3(fnors[i], pnors[*origIndexFace]); } else { /* eek, we're not corresponding to polys */ - printf("error in mesh_calc_normals; tessellation face indices are incorrect. normals may look bad.\n"); + printf("error in BKE_mesh_calc_normals; tessellation face indices are incorrect. normals may look bad.\n"); } } } @@ -1848,12 +1850,12 @@ void mesh_calc_normals_mapping_ex(MVert *mverts, int numVerts, } -void mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys, - int UNUSED(numLoops), int numPolys, float (*polyNors_r)[3]) +void BKE_mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys, + int UNUSED(numLoops), int numPolys, float (*polyNors_r)[3]) { float (*pnors)[3] = polyNors_r; - float (*tnorms)[3], (*edgevecbuf)[3]= NULL; + float (*tnorms)[3], (*edgevecbuf)[3] = NULL; float **vertcos = NULL, **vertnos = NULL; BLI_array_declare(vertcos); BLI_array_declare(vertnos); @@ -1866,11 +1868,11 @@ void mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys, if (!pnors) pnors = MEM_callocN(sizeof(float) * 3 * numPolys, "poly_nors mesh.c"); /*first go through and calculate normals for all the polys*/ - tnorms = MEM_callocN(sizeof(float)*3*numVerts, "tnorms mesh.c"); + tnorms = MEM_callocN(sizeof(float) * 3 * numVerts, "tnorms mesh.c"); mp = mpolys; - for (i=0; i<numPolys; i++, mp++) { - mesh_calc_poly_normal(mp, mloop+mp->loopstart, mverts, pnors[i]); + for (i = 0; i < numPolys; i++, mp++) { + mesh_calc_poly_normal(mp, mloop + mp->loopstart, mverts, pnors[i]); ml = mloop + mp->loopstart; BLI_array_empty(vertcos); @@ -1878,7 +1880,7 @@ void mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys, BLI_array_grow_items(vertcos, mp->totloop); BLI_array_grow_items(vertnos, mp->totloop); - for (j=0; j < mp->totloop; j++) { + for (j = 0; j < mp->totloop; j++) { int vindex = ml[j].v; vertcos[j] = mverts[vindex].co; vertnos[j] = tnorms[vindex]; @@ -1895,9 +1897,9 @@ void mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys, BLI_array_free(edgevecbuf); /* 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]; + 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); @@ -1910,17 +1912,17 @@ void mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys, if (pnors != polyNors_r) MEM_freeN(pnors); } -void mesh_calc_normals_tessface(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float (*faceNors_r)[3]) +void BKE_mesh_calc_normals_tessface(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float (*faceNors_r)[3]) { - float (*tnorms)[3]= MEM_callocN(numVerts*sizeof(*tnorms), "tnorms"); - float (*fnors)[3]= (faceNors_r)? faceNors_r: MEM_callocN(sizeof(*fnors)*numFaces, "meshnormals"); + float (*tnorms)[3] = MEM_callocN(numVerts * sizeof(*tnorms), "tnorms"); + float (*fnors)[3] = (faceNors_r) ? faceNors_r : MEM_callocN(sizeof(*fnors) * numFaces, "meshnormals"); int i; - for (i=0; i<numFaces; i++) { - MFace *mf= &mfaces[i]; - float *f_no= fnors[i]; - float *n4 = (mf->v4)? tnorms[mf->v4]: NULL; - float *c4 = (mf->v4)? mverts[mf->v4].co: NULL; + for (i = 0; i < numFaces; i++) { + MFace *mf = &mfaces[i]; + 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); @@ -1928,13 +1930,13 @@ void mesh_calc_normals_tessface(MVert *mverts, int numVerts, MFace *mfaces, int 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); + f_no, mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, c4); } /* 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]; + 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); @@ -1961,7 +1963,7 @@ static void bm_corners_to_loops(Mesh *me, int findex, int loopstart, int numTex, mf = me->mface + findex; - for (i=0; i < numTex; 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); @@ -1977,7 +1979,7 @@ static void bm_corners_to_loops(Mesh *me, int findex, int loopstart, int numTex, } } - for (i=0; i < numCol; i++) { + for (i = 0; i < numCol; i++) { mloopcol = CustomData_get_n(&me->ldata, CD_MLOOPCOL, loopstart, i); mcol = CustomData_get_n(&me->fdata, CD_MCOL, findex, i); @@ -1998,7 +2000,7 @@ static void bm_corners_to_loops(Mesh *me, int findex, int loopstart, int numTex, if (CustomData_external_test(&me->fdata, CD_MDISPS)) { CustomData_external_add(&me->ldata, &me->id, CD_MDISPS, - me->totloop, me->fdata.external->filename); + me->totloop, me->fdata.external->filename); } corners = multires_mdisp_corners(fd); @@ -2012,16 +2014,16 @@ static void bm_corners_to_loops(Mesh *me, int findex, int loopstart, int numTex, else { side = sqrt(fd->totdisp / corners); - for (i=0; i<tot; i++, disps += side*side, ld++) { - ld->totdisp = side*side; + for (i = 0; i < tot; i++, disps += side * side, ld++) { + ld->totdisp = side * side; ld->level = (int)(logf(side - 1.0f) / (float)M_LN2) + 1; if (ld->disps) MEM_freeN(ld->disps); - ld->disps = MEM_callocN(sizeof(float)*3*side*side, "converted loop mdisps"); + ld->disps = MEM_callocN(sizeof(float) * 3 * side * side, "converted loop mdisps"); if (fd->disps) { - memcpy(ld->disps, disps, sizeof(float)*3*side*side); + memcpy(ld->disps, disps, sizeof(float) * 3 * side * side); } } } @@ -2045,7 +2047,7 @@ void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh) memset(&mesh->pdata, 0, sizeof(mesh->pdata)); mesh->totpoly = mesh->totface; - mesh->mpoly = MEM_callocN(sizeof(MPoly)*mesh->totpoly, "mpoly converted"); + 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); @@ -2053,16 +2055,16 @@ void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh) totloop = 0; mf = mesh->mface; - for (i=0; i<mesh->totface; i++, mf++) { + 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"); + 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); + mesh->totloop, mesh->totpoly); /* ensure external data is transferred */ CustomData_external_read(&mesh->fdata, &mesh->id, CD_MASK_MDISPS, mesh->totface); @@ -2082,7 +2084,7 @@ void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh) ml = mesh->mloop; mf = mesh->mface; mp = mesh->mpoly; - for (i=0; i<mesh->totface; i++, mf++, mp++) { + for (i = 0; i < mesh->totface; i++, mf++, mp++) { mp->loopstart = j; mp->totloop = mf->v4 ? 4 : 3; @@ -2090,7 +2092,8 @@ void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh) 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++;} +# 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); @@ -2102,7 +2105,7 @@ void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh) ML(v3, v1); } -# undef ML +# undef ML bm_corners_to_loops(mesh, i, mp->loopstart, numTex, numCol); } @@ -2115,13 +2118,13 @@ void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh) BLI_edgehash_free(eh, NULL); } -float (*mesh_getVertexCos(Mesh *me, int *numVerts_r))[3] +float (*mesh_getVertexCos(Mesh * me, int *numVerts_r))[3] { int i, numVerts = me->totvert; - float (*cos)[3] = MEM_mallocN(sizeof(*cos)*numVerts, "vertexcos1"); + float (*cos)[3] = MEM_mallocN(sizeof(*cos) * numVerts, "vertexcos1"); if (numVerts_r) *numVerts_r = numVerts; - for (i=0; i<numVerts; i++) + for (i = 0; i < numVerts; i++) copy_v3_v3(cos[i], me->mvert[i].co); return cos; @@ -2132,103 +2135,103 @@ float (*mesh_getVertexCos(Mesh *me, int *numVerts_r))[3] /* this replaces the non bmesh function (in trunk) which takes MTFace's, if we ever need it back we could * but for now this replaces it because its unused. */ -UvVertMap *make_uv_vert_map(struct MPoly *mpoly, struct MLoop *mloop, struct MLoopUV *mloopuv, unsigned int totpoly, unsigned int totvert, int selected, float *limit) +UvVertMap *BKE_mesh_uv_vert_map_make(struct MPoly *mpoly, struct MLoop *mloop, struct MLoopUV *mloopuv, unsigned int totpoly, unsigned int totvert, int selected, float *limit) { UvVertMap *vmap; UvMapVert *buf; MPoly *mp; unsigned int a; - int i, totuv, nverts; + int i, totuv, nverts; totuv = 0; /* generate UvMapVert array */ - mp= mpoly; - for (a=0; a<totpoly; a++, mp++) + mp = mpoly; + for (a = 0; a < totpoly; a++, mp++) if (!selected || (!(mp->flag & ME_HIDE) && (mp->flag & ME_FACE_SEL))) totuv += mp->totloop; - if (totuv==0) + if (totuv == 0) return NULL; - vmap= (UvVertMap*)MEM_callocN(sizeof(*vmap), "UvVertMap"); + vmap = (UvVertMap *)MEM_callocN(sizeof(*vmap), "UvVertMap"); if (!vmap) return NULL; - vmap->vert= (UvMapVert**)MEM_callocN(sizeof(*vmap->vert)*totvert, "UvMapVert*"); - buf= vmap->buf= (UvMapVert*)MEM_callocN(sizeof(*vmap->buf)*totuv, "UvMapVert"); + vmap->vert = (UvMapVert **)MEM_callocN(sizeof(*vmap->vert) * totvert, "UvMapVert*"); + buf = vmap->buf = (UvMapVert *)MEM_callocN(sizeof(*vmap->buf) * totuv, "UvMapVert"); if (!vmap->vert || !vmap->buf) { - free_uv_vert_map(vmap); + BKE_mesh_uv_vert_map_free(vmap); return NULL; } - mp= mpoly; - for (a=0; a<totpoly; a++, mp++) { + mp = mpoly; + for (a = 0; a < totpoly; a++, mp++) { if (!selected || (!(mp->flag & ME_HIDE) && (mp->flag & ME_FACE_SEL))) { - nverts= mp->totloop; + nverts = mp->totloop; - for (i=0; i<nverts; i++) { - buf->tfindex= i; - buf->f= a; + for (i = 0; i < nverts; i++) { + buf->tfindex = i; + buf->f = a; buf->separate = 0; - buf->next= vmap->vert[mloop[mp->loopstart + i].v]; - vmap->vert[mloop[mp->loopstart + i].v]= buf; + buf->next = vmap->vert[mloop[mp->loopstart + i].v]; + vmap->vert[mloop[mp->loopstart + i].v] = buf; buf++; } } } /* sort individual uvs for each vert */ - for (a=0; a<totvert; a++) { - UvMapVert *newvlist= NULL, *vlist=vmap->vert[a]; + for (a = 0; a < totvert; a++) { + UvMapVert *newvlist = NULL, *vlist = vmap->vert[a]; UvMapVert *iterv, *v, *lastv, *next; float *uv, *uv2, uvdiff[2]; while (vlist) { - v= vlist; - vlist= vlist->next; - v->next= newvlist; - newvlist= v; + v = vlist; + vlist = vlist->next; + v->next = newvlist; + newvlist = v; - uv= mloopuv[mpoly[v->f].loopstart + v->tfindex].uv; - lastv= NULL; - iterv= vlist; + uv = mloopuv[mpoly[v->f].loopstart + v->tfindex].uv; + lastv = NULL; + iterv = vlist; while (iterv) { - next= iterv->next; + next = iterv->next; - uv2= mloopuv[mpoly[iterv->f].loopstart + iterv->tfindex].uv; + uv2 = mloopuv[mpoly[iterv->f].loopstart + iterv->tfindex].uv; sub_v2_v2v2(uvdiff, uv2, uv); - 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; - newvlist= iterv; + 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; + newvlist = iterv; } else - lastv=iterv; + lastv = iterv; - iterv= next; + iterv = next; } newvlist->separate = 1; } - vmap->vert[a]= newvlist; + vmap->vert[a] = newvlist; } return vmap; } -UvMapVert *get_uv_map_vert(UvVertMap *vmap, unsigned int v) +UvMapVert *BKE_mesh_uv_vert_map_get_vert(UvVertMap *vmap, unsigned int v) { return vmap->vert[v]; } -void free_uv_vert_map(UvVertMap *vmap) +void BKE_mesh_uv_vert_map_free(UvVertMap *vmap) { if (vmap) { if (vmap->vert) MEM_freeN(vmap->vert); @@ -2297,22 +2300,22 @@ void create_vert_edge_map(ListBase **map, IndexNode **mem, const MEdge *medge, c for (i = 0; i < totedge; ++i) { for (j = 0; j < 2; ++j, ++node) { node->index = i; - BLI_addtail(&(*map)[((unsigned int*)(&medge[i].v1))[j]], node); + BLI_addtail(&(*map)[((unsigned int *)(&medge[i].v1))[j]], node); } } } -void mesh_loops_to_mface_corners(CustomData *fdata, CustomData *ldata, - CustomData *pdata, int lindex[4], int findex, - const int polyindex, - const int mf_len, /* 3 or 4 */ +void BKE_mesh_loops_to_mface_corners(CustomData *fdata, CustomData *ldata, + CustomData *pdata, int lindex[4], int findex, + const int polyindex, + const int mf_len, /* 3 or 4 */ - /* cache values to avoid lookups every time */ - const int numTex, /* CustomData_number_of_layers(pdata, CD_MTEXPOLY) */ - const int numCol, /* CustomData_number_of_layers(ldata, CD_MLOOPCOL) */ - const int hasPCol, /* CustomData_has_layer(ldata, CD_PREVIEW_MLOOPCOL) */ - const int hasOrigSpace /* CustomData_has_layer(ldata, CD_ORIGSPACE_MLOOP) */ - ) + /* cache values to avoid lookups every time */ + const int numTex, /* CustomData_number_of_layers(pdata, CD_MTEXPOLY) */ + const int numCol, /* CustomData_number_of_layers(ldata, CD_MLOOPCOL) */ + const int hasPCol, /* CustomData_has_layer(ldata, CD_PREVIEW_MLOOPCOL) */ + const int hasOrigSpace /* CustomData_has_layer(ldata, CD_ORIGSPACE_MLOOP) */ + ) { MTFace *texface; MTexPoly *texpoly; @@ -2321,22 +2324,22 @@ void mesh_loops_to_mface_corners(CustomData *fdata, CustomData *ldata, MLoopUV *mloopuv; int i, j; - for (i=0; i < numTex; i++) { + for (i = 0; i < numTex; i++) { texface = CustomData_get_n(fdata, CD_MTFACE, findex, i); texpoly = CustomData_get_n(pdata, CD_MTEXPOLY, polyindex, i); ME_MTEXFACE_CPY(texface, texpoly); - for (j=0; j < mf_len; j++) { + for (j = 0; j < mf_len; j++) { mloopuv = CustomData_get_n(ldata, CD_MLOOPUV, lindex[j], i); copy_v2_v2(texface->uv[j], mloopuv->uv); } } - for (i=0; i < numCol; i++) { + for (i = 0; i < numCol; i++) { mcol = CustomData_get_n(fdata, CD_MCOL, findex, i); - for (j=0; j < mf_len; j++) { + for (j = 0; j < mf_len; j++) { mloopcol = CustomData_get_n(ldata, CD_MLOOPCOL, lindex[j], i); MESH_MLOOPCOL_TO_MCOL(mloopcol, &mcol[j]); } @@ -2345,7 +2348,7 @@ void mesh_loops_to_mface_corners(CustomData *fdata, CustomData *ldata, if (hasPCol) { mcol = CustomData_get(fdata, findex, CD_PREVIEW_MCOL); - for (j=0; j < mf_len; j++) { + for (j = 0; j < mf_len; j++) { mloopcol = CustomData_get(ldata, lindex[j], CD_PREVIEW_MLOOPCOL); MESH_MLOOPCOL_TO_MCOL(mloopcol, &mcol[j]); } @@ -2355,7 +2358,7 @@ void mesh_loops_to_mface_corners(CustomData *fdata, CustomData *ldata, OrigSpaceFace *of = CustomData_get(fdata, findex, CD_ORIGSPACE); OrigSpaceLoop *lof; - for (j=0; j < mf_len; j++) { + for (j = 0; j < mf_len; j++) { lof = CustomData_get(ldata, lindex[j], CD_ORIGSPACE_MLOOP); copy_v2_v2(of->uv[j], lof->uv); } @@ -2366,13 +2369,13 @@ void mesh_loops_to_mface_corners(CustomData *fdata, CustomData *ldata, * this function recreates a tessellation. * returns number of tessellation faces. */ -int mesh_recalcTessellation(CustomData *fdata, - CustomData *ldata, CustomData *pdata, - MVert *mvert, int totface, int UNUSED(totloop), - int totpoly, - /* when tessellating to recalculate normals after - * we can skip copying here */ - const int do_face_nor_cpy) +int BKE_mesh_recalc_tessellation(CustomData *fdata, + CustomData *ldata, CustomData *pdata, + MVert *mvert, int totface, int UNUSED(totloop), + int totpoly, + /* when tessellating to recalculate normals after + * we can skip copying here */ + const int do_face_nor_cpy) { /* use this to avoid locking pthread for _every_ polygon * and calling the fill function */ @@ -2380,8 +2383,8 @@ int mesh_recalcTessellation(CustomData *fdata, #define USE_TESSFACE_SPEEDUP #define USE_TESSFACE_QUADS // NEEDS FURTHER TESTING -#define TESSFACE_SCANFILL (1<<0) -#define TESSFACE_IS_QUAD (1<<1) +#define TESSFACE_SCANFILL (1 << 0) +#define TESSFACE_IS_QUAD (1 << 1) MPoly *mp, *mpoly; MLoop *ml, *mloop; @@ -2425,7 +2428,7 @@ int mesh_recalcTessellation(CustomData *fdata, BLI_array_grow_one(mface_to_poly_map); \ BLI_array_grow_one(mface); \ mface_to_poly_map[mface_index] = poly_index; \ - mf= &mface[mface_index]; \ + mf = &mface[mface_index]; \ /* set loop indices, transformed to vert indices later */ \ mf->v1 = mp->loopstart + i1; \ mf->v2 = mp->loopstart + i2; \ @@ -2444,7 +2447,7 @@ int mesh_recalcTessellation(CustomData *fdata, BLI_array_grow_one(mface_to_poly_map); \ BLI_array_grow_one(mface); \ mface_to_poly_map[mface_index] = poly_index; \ - mf= &mface[mface_index]; \ + mf = &mface[mface_index]; \ /* set loop indices, transformed to vert indices later */ \ mf->v1 = mp->loopstart + 0; /* EXCEPTION */ \ mf->v2 = mp->loopstart + 1; /* EXCEPTION */ \ @@ -2484,7 +2487,7 @@ int mesh_recalcTessellation(CustomData *fdata, BLI_scanfill_begin(&sf_ctx); firstv = NULL; lastv = NULL; - for (j=0; j<mp->totloop; j++, ml++) { + for (j = 0; j < mp->totloop; j++, ml++) { v = BLI_scanfill_vert_add(&sf_ctx, mvert[ml->v].co); v->keyindex = mp->loopstart + j; @@ -2508,7 +2511,7 @@ int mesh_recalcTessellation(CustomData *fdata, for (f = sf_ctx.fillfacebase.first; f; f = f->next, mf++) { mface_to_poly_map[mface_index] = poly_index; - mf= &mface[mface_index]; + mf = &mface[mface_index]; /* set loop indices, transformed to vert indices later */ mf->v1 = f->v1->keyindex; @@ -2576,7 +2579,7 @@ int mesh_recalcTessellation(CustomData *fdata, } mf = mface; - for (mface_index=0; mface_index < totface; mface_index++, mf++) { + for (mface_index = 0; mface_index < totface; mface_index++, mf++) { #ifdef USE_TESSFACE_QUADS const int mf_len = mf->edcode & TESSFACE_IS_QUAD ? 4 : 3; @@ -2618,14 +2621,14 @@ int mesh_recalcTessellation(CustomData *fdata, if (mf_len == 4) mf->v4 = mloop[mf->v4].v; #endif - mesh_loops_to_mface_corners(fdata, ldata, pdata, - lindex, mface_index, mface_to_poly_map[mface_index], + BKE_mesh_loops_to_mface_corners(fdata, ldata, pdata, + lindex, mface_index, mface_to_poly_map[mface_index], #ifdef USE_TESSFACE_QUADS - mf_len, + mf_len, #else - 3, + 3, #endif - numTex, numCol, hasPCol, hasOrigSpace); + numTex, numCol, hasPCol, hasOrigSpace); #ifdef USE_TESSFACE_QUADS @@ -2647,8 +2650,8 @@ int mesh_recalcTessellation(CustomData *fdata, * this function recreates a tessellation. * returns number of tessellation faces. */ -int mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata, - struct CustomData *pdata, int totface, int UNUSED(totloop), int totpoly) +int BKE_mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata, + struct CustomData *pdata, int totface, int UNUSED(totloop), int totpoly) { MLoop *mloop; @@ -2670,7 +2673,7 @@ int mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata, mp = mpoly; k = 0; - for (i = 0; i<totpoly; i++, mp++) { + for (i = 0; i < totpoly; i++, mp++) { if (ELEM(mp->totloop, 3, 4)) { BLI_array_grow_one(mface); mf = &mface[k]; @@ -2693,7 +2696,7 @@ int mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata, CustomData_free(fdata, totface); memset(fdata, 0, sizeof(CustomData)); - totface= k; + totface = k; CustomData_add_layer(fdata, CD_MFACE, CD_ASSIGN, mface, totface); @@ -2701,7 +2704,7 @@ int mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata, mp = mpoly; k = 0; - for (i = 0; i<totpoly; i++, mp++) { + for (i = 0; i < totpoly; i++, mp++) { if (ELEM(mp->totloop, 3, 4)) { mf = &mface[k]; @@ -2719,9 +2722,9 @@ int mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata, mf->v2 = mloop[mf->v2].v; mf->v3 = mloop[mf->v3].v; - mesh_loops_to_mface_corners(fdata, ldata, pdata, - lindex, k, i, 3, - numTex, numCol, hasPCol, hasOrigSpace); + BKE_mesh_loops_to_mface_corners(fdata, ldata, pdata, + lindex, k, i, 3, + numTex, numCol, hasPCol, hasOrigSpace); test_index_face(mf, fdata, k, 3); } else { @@ -2739,13 +2742,13 @@ int mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata, mf->v3 = mloop[mf->v3].v; mf->v4 = mloop[mf->v4].v; - mesh_loops_to_mface_corners(fdata, ldata, pdata, - lindex, k, i, 4, - numTex, numCol, hasPCol, hasOrigSpace); + BKE_mesh_loops_to_mface_corners(fdata, ldata, pdata, + lindex, k, i, 4, + numTex, numCol, hasPCol, hasOrigSpace); test_index_face(mf, fdata, k, 4); } - mf->edcode= 0; + mf->edcode = 0; k++; } @@ -2829,8 +2832,8 @@ static void mesh_calc_ngon_normal_coords(MPoly *mpoly, MLoop *loopstart, } } -void mesh_calc_poly_normal_coords(MPoly *mpoly, MLoop *loopstart, - const float (*vertex_coords)[3], float no[3]) +void BKE_mesh_calc_poly_normal_coords(MPoly *mpoly, MLoop *loopstart, + const float (*vertex_coords)[3], float no[3]) { if (mpoly->totloop > 4) { mesh_calc_ngon_normal_coords(mpoly, loopstart, vertex_coords, no); @@ -2860,7 +2863,7 @@ void mesh_calc_poly_normal_coords(MPoly *mpoly, MLoop *loopstart, static void mesh_calc_ngon_center(MPoly *mpoly, MLoop *loopstart, MVert *mvert, float cent[3]) { - const float w= 1.0f / (float)mpoly->totloop; + const float w = 1.0f / (float)mpoly->totloop; int i; zero_v3(cent); @@ -2870,8 +2873,8 @@ static void mesh_calc_ngon_center(MPoly *mpoly, MLoop *loopstart, } } -void mesh_calc_poly_center(MPoly *mpoly, MLoop *loopstart, - MVert *mvarray, float cent[3]) +void BKE_mesh_calc_poly_center(MPoly *mpoly, MLoop *loopstart, + MVert *mvarray, float cent[3]) { if (mpoly->totloop == 3) { cent_tri_v3(cent, @@ -2894,8 +2897,8 @@ void mesh_calc_poly_center(MPoly *mpoly, MLoop *loopstart, } /* note, passing polynormal is only a speedup so we can skip calculating it */ -float mesh_calc_poly_area(MPoly *mpoly, MLoop *loopstart, - MVert *mvarray, float polynormal[3]) +float BKE_mesh_calc_poly_area(MPoly *mpoly, MLoop *loopstart, + MVert *mvarray, float polynormal[3]) { if (mpoly->totloop == 3) { return area_tri_v3(mvarray[loopstart[0].v].co, @@ -2914,7 +2917,7 @@ float mesh_calc_poly_area(MPoly *mpoly, MLoop *loopstart, int i; MLoop *l_iter = loopstart; float area, polynorm_local[3], (*vertexcos)[3]; - float *no= polynormal ? polynormal : polynorm_local; + float *no = polynormal ? polynormal : polynorm_local; BLI_array_fixedstack_declare(vertexcos, BM_NGON_STACK_SIZE, mpoly->totloop, __func__); /* pack vertex cos into an array for area_poly_v3 */ @@ -2939,7 +2942,7 @@ float mesh_calc_poly_area(MPoly *mpoly, MLoop *loopstart, /* Find the index of the loop in 'poly' which references vertex, * returns -1 if not found */ int poly_find_loop_from_vert(const MPoly *poly, const MLoop *loopstart, - unsigned vert) + unsigned vert) { int j; for (j = 0; j < poly->totloop; j++, loopstart++) { @@ -2954,11 +2957,11 @@ int poly_find_loop_from_vert(const MPoly *poly, const MLoop *loopstart, * vertex. Returns the index of the loop matching vertex, or -1 if the * vertex is not in 'poly' */ int poly_get_adj_loops_from_vert(unsigned adj_r[3], const MPoly *poly, - const MLoop *mloop, unsigned vert) + const MLoop *mloop, unsigned vert) { int corner = poly_find_loop_from_vert(poly, - &mloop[poly->loopstart], - vert); + &mloop[poly->loopstart], + vert); if (corner != -1) { const MLoop *ml = &mloop[poly->loopstart + corner]; @@ -2974,10 +2977,10 @@ int poly_get_adj_loops_from_vert(unsigned adj_r[3], const MPoly *poly, /* update the hide flag for edges and faces from the corresponding * flag in verts */ -void mesh_flush_hidden_from_verts(const MVert *mvert, - const MLoop *mloop, - MEdge *medge, int totedge, - MPoly *mpoly, int totpoly) +void BKE_mesh_flush_hidden_from_verts(const MVert *mvert, + const MLoop *mloop, + MEdge *medge, int totedge, + MPoly *mpoly, int totpoly) { int i, j; @@ -3003,38 +3006,38 @@ void mesh_flush_hidden_from_verts(const MVert *mvert, } /* basic vertex data functions */ -int minmax_mesh(Mesh *me, float min[3], float max[3]) +int BKE_mesh_minmax(Mesh *me, float r_min[3], float r_max[3]) { - int i= me->totvert; + int i = me->totvert; MVert *mvert; - for (mvert= me->mvert; i--; mvert++) { - DO_MINMAX(mvert->co, min, max); + for (mvert = me->mvert; i--; mvert++) { + DO_MINMAX(mvert->co, r_min, r_max); } return (me->totvert != 0); } -int mesh_center_median(Mesh *me, float cent[3]) +int BKE_mesh_center_median(Mesh *me, float cent[3]) { - int i= me->totvert; + int i = me->totvert; MVert *mvert; zero_v3(cent); - for (mvert= me->mvert; i--; mvert++) { + for (mvert = me->mvert; i--; mvert++) { add_v3_v3(cent, mvert->co); } /* otherwise we get NAN for 0 verts */ if (me->totvert) { - mul_v3_fl(cent, 1.0f/(float)me->totvert); + mul_v3_fl(cent, 1.0f / (float)me->totvert); } return (me->totvert != 0); } -int mesh_center_bounds(Mesh *me, float cent[3]) +int BKE_mesh_center_bounds(Mesh *me, float cent[3]) { float min[3], max[3]; INIT_MINMAX(min, max); - if (minmax_mesh(me, min, max)) { + if (BKE_mesh_minmax(me, min, max)) { mid_v3_v3v3(cent, min, max); return 1; } @@ -3042,19 +3045,19 @@ int mesh_center_bounds(Mesh *me, float cent[3]) return 0; } -void mesh_translate(Mesh *me, float offset[3], int do_keys) +void BKE_mesh_translate(Mesh *me, float offset[3], int do_keys) { - int i= me->totvert; + int i = me->totvert; MVert *mvert; - for (mvert= me->mvert; i--; mvert++) { + for (mvert = me->mvert; i--; mvert++) { add_v3_v3(mvert->co, offset); } if (do_keys && me->key) { KeyBlock *kb; - for (kb=me->key->block.first; kb; kb=kb->next) { - float *fp= kb->data; - for (i= kb->totelem; i--; fp+=3) { + for (kb = me->key->block.first; kb; kb = kb->next) { + float *fp = kb->data; + for (i = kb->totelem; i--; fp += 3) { add_v3_v3(fp, offset); } } @@ -3069,9 +3072,9 @@ void BKE_mesh_ensure_navmesh(Mesh *me) int numFaces = me->totpoly; int *recastData; CustomData_add_layer_named(&me->pdata, CD_RECAST, CD_CALLOC, NULL, numFaces, "recastData"); - recastData = (int*)CustomData_get_layer(&me->pdata, CD_RECAST); - for (i=0; i<numFaces; i++) { - recastData[i] = i+1; + recastData = (int *)CustomData_get_layer(&me->pdata, CD_RECAST); + for (i = 0; i < numFaces; i++) { + recastData[i] = i + 1; } CustomData_add_layer_named(&me->pdata, CD_RECAST, CD_REFERENCE, recastData, numFaces, "recastData"); } @@ -3079,11 +3082,11 @@ void BKE_mesh_ensure_navmesh(Mesh *me) void BKE_mesh_tessface_calc(Mesh *mesh) { - mesh->totface = mesh_recalcTessellation(&mesh->fdata, &mesh->ldata, &mesh->pdata, - mesh->mvert, - mesh->totface, mesh->totloop, mesh->totpoly, - /* calc normals right after, don't copy from polys here */ - FALSE); + mesh->totface = BKE_mesh_recalc_tessellation(&mesh->fdata, &mesh->ldata, &mesh->pdata, + mesh->mvert, + mesh->totface, mesh->totloop, mesh->totpoly, + /* calc normals right after, don't copy from polys here */ + FALSE); mesh_update_customdata_pointers(mesh, TRUE); } @@ -3099,3 +3102,51 @@ void BKE_mesh_tessface_clear(Mesh *mesh) { mesh_tessface_clear_intern(mesh, TRUE); } + +#if 0 /* slow version of the function below */ +void BKE_mesh_poly_calc_angles(MVert *mvert, MLoop *mloop, + MPoly *mp, float angles[]) +{ + MLoop *ml; + + int j; + for (j = 0, ml = mloop + mp->loopstart; j < mp->totloop; j++, ml++) { + MLoop *ml_prev = ME_POLY_LOOP_PREV(mloop, mp, j); + MLoop *ml_next = ME_POLY_LOOP_NEXT(mloop, mp, j); + + float e1[3], e2[3]; + + sub_v3_v3v3(e1, mvert[ml_next->v].co, mvert[ml->v].co); + sub_v3_v3v3(e2, mvert[ml_prev->v].co, mvert[ml->v].co); + + angles[j] = (float)M_PI - angle_v3v3(e1, e2); + } +} + +#else /* equivalent the function above but avoid multiple subtractions + normalize */ + +void BKE_mesh_poly_calc_angles(MVert *mvert, MLoop *mloop, + MPoly *mp, float angles[]) +{ + MLoop *ml = mloop + mp->loopstart; + float nor_prev[3]; + float nor_next[3]; + + int i_this = mp->totloop - 1; + int i_next = 0; + + sub_v3_v3v3(nor_prev, mvert[ml[i_this - 1].v].co, mvert[ml[i_this].v].co); + normalize_v3(nor_prev); + + while (i_next < mp->totloop) { + sub_v3_v3v3(nor_next, mvert[ml[i_this].v].co, mvert[ml[i_next].v].co); + normalize_v3(nor_next); + angles[i_this] = angle_normalized_v3v3(nor_prev, nor_next); + + /* step */ + copy_v3_v3(nor_prev, nor_next); + i_this = i_next; + i_next++; + } +} +#endif diff --git a/source/blender/blenkernel/intern/mesh_validate.c b/source/blender/blenkernel/intern/mesh_validate.c index 446ad399e11..1645a8c9c9b 100644 --- a/source/blender/blenkernel/intern/mesh_validate.c +++ b/source/blender/blenkernel/intern/mesh_validate.c @@ -536,11 +536,11 @@ int BKE_mesh_validate_arrays(Mesh *mesh, if (mesh) { if (do_polyloop_free) { - mesh_strip_loose_polysloops(mesh); + BKE_mesh_strip_loose_polysloops(mesh); } if (do_edge_free) { - mesh_strip_loose_edges(mesh); + BKE_mesh_strip_loose_edges(mesh); } if (do_edge_recalc) { diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 98cbc957201..2159837c9a0 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -68,12 +68,12 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type) { - static ModifierTypeInfo *types[NUM_MODIFIER_TYPES]= {NULL}; + static ModifierTypeInfo *types[NUM_MODIFIER_TYPES] = {NULL}; static int types_init = 1; if (types_init) { modifier_type_init(types); /* MOD_utils.c */ - types_init= 0; + types_init = 0; } /* type unsigned, no need to check < 0 */ @@ -96,8 +96,7 @@ ModifierData *modifier_new(int type) BLI_strncpy(md->name, mti->name, sizeof(md->name)); md->type = type; - md->mode = eModifierMode_Realtime - | eModifierMode_Render | eModifierMode_Expanded; + md->mode = eModifierMode_Realtime | eModifierMode_Render | eModifierMode_Expanded; if (mti->flags & eModifierTypeFlag_EnableInEditmode) md->mode |= eModifierMode_Editmode; @@ -137,8 +136,8 @@ int modifier_supportsMapping(ModifierData *md) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); - return (mti->type==eModifierTypeType_OnlyDeform || - (mti->flags & eModifierTypeFlag_SupportsMapping)); + return (mti->type == eModifierTypeType_OnlyDeform || + (mti->flags & eModifierTypeFlag_SupportsMapping)); } int modifier_isPreview(ModifierData *md) @@ -158,8 +157,8 @@ ModifierData *modifiers_findByType(Object *ob, ModifierType type) { ModifierData *md = ob->modifiers.first; - for (; md; md=md->next) - if (md->type==type) + for (; md; md = md->next) + if (md->type == type) break; return md; @@ -175,7 +174,7 @@ void modifiers_clearErrors(Object *ob) ModifierData *md = ob->modifiers.first; /* int qRedraw = 0; */ - for (; md; md=md->next) { + for (; md; md = md->next) { if (md->error) { MEM_freeN(md->error); md->error = NULL; @@ -186,11 +185,11 @@ void modifiers_clearErrors(Object *ob) } void modifiers_foreachObjectLink(Object *ob, ObjectWalkFunc walk, - void *userData) + void *userData) { ModifierData *md = ob->modifiers.first; - for (; md; md=md->next) { + for (; md; md = md->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); if (mti->foreachObjectLink) @@ -202,7 +201,7 @@ void modifiers_foreachIDLink(Object *ob, IDWalkFunc walk, void *userData) { ModifierData *md = ob->modifiers.first; - for (; md; md=md->next) { + for (; md; md = md->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); if (mti->foreachIDLink) mti->foreachIDLink(md, ob, walk, userData); @@ -218,7 +217,7 @@ void modifiers_foreachTexLink(Object *ob, TexWalkFunc walk, void *userData) { ModifierData *md = ob->modifiers.first; - for (; md; md=md->next) { + for (; md; md = md->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); if (mti->foreachTexLink) @@ -240,12 +239,12 @@ int modifier_couldBeCage(struct Scene *scene, ModifierData *md) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); - md->scene= scene; + md->scene = scene; - return ( (md->mode & eModifierMode_Realtime) && - (md->mode & eModifierMode_Editmode) && - (!mti->isDisabled || !mti->isDisabled(md, 0)) && - modifier_supportsMapping(md)); + return ((md->mode & eModifierMode_Realtime) && + (md->mode & eModifierMode_Editmode) && + (!mti->isDisabled || !mti->isDisabled(md, 0)) && + modifier_supportsMapping(md)); } int modifier_sameTopology(ModifierData *md) @@ -269,7 +268,7 @@ void modifier_setError(ModifierData *md, const char *format, ...) va_start(ap, format); vsnprintf(buffer, sizeof(buffer), format, ap); va_end(ap); - buffer[sizeof(buffer) - 1]= '\0'; + buffer[sizeof(buffer) - 1] = '\0'; if (md->error) MEM_freeN(md->error); @@ -287,19 +286,19 @@ void modifier_setError(ModifierData *md, const char *format, ...) */ int modifiers_getCageIndex(struct Scene *scene, Object *ob, int *lastPossibleCageIndex_r, int virtual_) { - ModifierData *md = (virtual_)? modifiers_getVirtualModifierList(ob): ob->modifiers.first; + ModifierData *md = (virtual_) ? modifiers_getVirtualModifierList(ob) : ob->modifiers.first; int i, cageIndex = -1; if (lastPossibleCageIndex_r) { /* ensure the value is initialized */ - *lastPossibleCageIndex_r= -1; + *lastPossibleCageIndex_r = -1; } /* Find the last modifier acting on the cage. */ - for (i=0; md; i++, md=md->next) { + for (i = 0; md; i++, md = md->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); - md->scene= scene; + md->scene = scene; if (!(md->mode & eModifierMode_Realtime)) continue; if (!(md->mode & eModifierMode_Editmode)) continue; @@ -344,7 +343,7 @@ int modifier_isEnabled(struct Scene *scene, ModifierData *md, int required_mode) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); - md->scene= scene; + md->scene = scene; if ((md->mode & required_mode) != required_mode) return 0; if (mti->isDisabled && mti->isDisabled(md, required_mode == eModifierMode_Render)) return 0; @@ -396,7 +395,7 @@ CDMaskLink *modifiers_calcDataMasks(struct Scene *scene, Object *ob, ModifierDat } /* reverse the list so it's in the correct order */ - BLI_linklist_reverse((LinkNode**)&dataMasks); + BLI_linklist_reverse((LinkNode **)&dataMasks); return dataMasks; } @@ -416,6 +415,7 @@ ModifierData *modifiers_getLastPreview(struct Scene *scene, ModifierData *md, in return tmp_md; } +/* NOTE: these aren't used anymore */ ModifierData *modifiers_getVirtualModifierList(Object *ob) { /* Kinda hacky, but should be fine since we are never @@ -430,19 +430,19 @@ ModifierData *modifiers_getVirtualModifierList(Object *ob) if (init) { md = modifier_new(eModifierType_Armature); - amd = *((ArmatureModifierData*) md); + amd = *((ArmatureModifierData *) md); modifier_free(md); md = modifier_new(eModifierType_Curve); - cmd = *((CurveModifierData*) md); + cmd = *((CurveModifierData *) md); modifier_free(md); md = modifier_new(eModifierType_Lattice); - lmd = *((LatticeModifierData*) md); + lmd = *((LatticeModifierData *) md); modifier_free(md); md = modifier_new(eModifierType_ShapeKey); - smd = *((ShapeKeyModifierData*) md); + smd = *((ShapeKeyModifierData *) md); modifier_free(md); amd.modifier.mode |= eModifierMode_Virtual; @@ -456,19 +456,19 @@ ModifierData *modifiers_getVirtualModifierList(Object *ob) md = ob->modifiers.first; if (ob->parent) { - if (ob->parent->type==OB_ARMATURE && ob->partype==PARSKEL) { + if (ob->parent->type == OB_ARMATURE && ob->partype == PARSKEL) { amd.object = ob->parent; amd.modifier.next = md; - amd.deformflag= ((bArmature *)(ob->parent->data))->deformflag; + amd.deformflag = ((bArmature *)(ob->parent->data))->deformflag; md = &amd.modifier; } - else if (ob->parent->type==OB_CURVE && ob->partype==PARSKEL) { + else if (ob->parent->type == OB_CURVE && ob->partype == PARSKEL) { cmd.object = ob->parent; cmd.defaxis = ob->trackflag + 1; cmd.modifier.next = md; md = &cmd.modifier; } - else if (ob->parent->type==OB_LATTICE && ob->partype==PARSKEL) { + else if (ob->parent->type == OB_LATTICE && ob->partype == PARSKEL) { lmd.object = ob->parent; lmd.modifier.next = md; md = &lmd.modifier; @@ -478,9 +478,9 @@ ModifierData *modifiers_getVirtualModifierList(Object *ob) /* shape key modifier, not yet for curves */ if (ELEM(ob->type, OB_MESH, OB_LATTICE) && ob_get_key(ob)) { if (ob->type == OB_MESH && (ob->shapeflag & OB_SHAPE_EDIT_MODE)) - smd.modifier.mode |= eModifierMode_Editmode|eModifierMode_OnCage; + smd.modifier.mode |= eModifierMode_Editmode | eModifierMode_OnCage; else - smd.modifier.mode &= ~eModifierMode_Editmode|eModifierMode_OnCage; + smd.modifier.mode &= ~eModifierMode_Editmode | eModifierMode_OnCage; smd.modifier.next = md; md = &smd.modifier; @@ -495,12 +495,12 @@ ModifierData *modifiers_getVirtualModifierList(Object *ob) Object *modifiers_isDeformedByArmature(Object *ob) { ModifierData *md = modifiers_getVirtualModifierList(ob); - ArmatureModifierData *amd= NULL; + ArmatureModifierData *amd = NULL; /* return the first selected armature, this lets us use multiple armatures */ - for (; md; md=md->next) { - if (md->type==eModifierType_Armature) { - amd = (ArmatureModifierData*) md; + for (; md; md = md->next) { + if (md->type == eModifierType_Armature) { + amd = (ArmatureModifierData *) md; if (amd->object && (amd->object->flag & SELECT)) return amd->object; } @@ -519,12 +519,12 @@ Object *modifiers_isDeformedByArmature(Object *ob) Object *modifiers_isDeformedByLattice(Object *ob) { ModifierData *md = modifiers_getVirtualModifierList(ob); - LatticeModifierData *lmd= NULL; + LatticeModifierData *lmd = NULL; /* return the first selected lattice, this lets us use multiple lattices */ - for (; md; md=md->next) { - if (md->type==eModifierType_Lattice) { - lmd = (LatticeModifierData*) md; + for (; md; md = md->next) { + if (md->type == eModifierType_Lattice) { + lmd = (LatticeModifierData *) md; if (lmd->object && (lmd->object->flag & SELECT)) return lmd->object; } @@ -542,10 +542,10 @@ int modifiers_usesArmature(Object *ob, bArmature *arm) { ModifierData *md = modifiers_getVirtualModifierList(ob); - for (; md; md=md->next) { - if (md->type==eModifierType_Armature) { - ArmatureModifierData *amd = (ArmatureModifierData*) md; - if (amd->object && amd->object->data==arm) + for (; md; md = md->next) { + if (md->type == eModifierType_Armature) { + ArmatureModifierData *amd = (ArmatureModifierData *) md; + if (amd->object && amd->object->data == arm) return 1; } } @@ -555,9 +555,9 @@ int modifiers_usesArmature(Object *ob, bArmature *arm) int modifier_isCorrectableDeformed(ModifierData *md) { - if (md->type==eModifierType_Armature) + if (md->type == eModifierType_Armature) return 1; - if (md->type==eModifierType_ShapeKey) + if (md->type == eModifierType_ShapeKey) return 1; return 0; @@ -567,11 +567,11 @@ int modifiers_isCorrectableDeformed(Object *ob) { ModifierData *md = modifiers_getVirtualModifierList(ob); - for (; md; md=md->next) { - if (ob->mode==OB_MODE_EDIT && (md->mode & eModifierMode_Editmode)==0); + for (; md; md = md->next) { + if (ob->mode == OB_MODE_EDIT && (md->mode & eModifierMode_Editmode) == 0) ; else - if (modifier_isCorrectableDeformed(md)) - return 1; + if (modifier_isCorrectableDeformed(md)) + return 1; } return 0; } @@ -592,22 +592,22 @@ int modifiers_isPreview(Object *ob) int modifiers_indexInObject(Object *ob, ModifierData *md_seek) { - int i= 0; + int i = 0; ModifierData *md; - for (md=ob->modifiers.first; (md && md_seek!=md); md=md->next, i++); - if (!md) return -1; /* modifier isn't in the object */ + for (md = ob->modifiers.first; (md && md_seek != md); md = md->next, i++) ; + if (!md) return -1; /* modifier isn't in the object */ return i; } void modifier_freeTemporaryData(ModifierData *md) { if (md->type == eModifierType_Armature) { - ArmatureModifierData *amd= (ArmatureModifierData*)md; + ArmatureModifierData *amd = (ArmatureModifierData *)md; if (amd->prevCos) { MEM_freeN(amd->prevCos); - amd->prevCos= NULL; + amd->prevCos = NULL; } } } @@ -624,7 +624,7 @@ void test_object_modifiers(Object *ob) for (md = ob->modifiers.first; md; md = md->next) { if (md->type == eModifierType_Multires) { - MultiresModifierData *mmd = (MultiresModifierData*)md; + MultiresModifierData *mmd = (MultiresModifierData *)md; multiresModifier_set_levels_from_disps(mmd, ob); } diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 7a279572738..f07de7f0127 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -71,7 +71,7 @@ #include "BKE_main.h" #include "BKE_utildefines.h" #include "BKE_movieclip.h" -#include "BKE_image.h" /* openanim */ +#include "BKE_image.h" /* openanim */ #include "BKE_tracking.h" #include "IMB_imbuf_types.h" @@ -205,7 +205,7 @@ static ImBuf *movieclip_load_sequence_file(MovieClip *clip, MovieClipUser *user, else get_sequence_fname(clip, framenr, name); - loadflag = IB_rect|IB_multilayer; + loadflag = IB_rect | IB_multilayer; /* read ibuf */ ibuf = IMB_loadiffname(name, loadflag); @@ -250,7 +250,7 @@ static ImBuf *movieclip_load_movie_file(MovieClip *clip, MovieClipUser *user, in dur = IMB_anim_get_duration(clip->anim, tc); fra = framenr - 1; - if (fra<0) + if (fra < 0) fra = 0; if (fra > (dur - 1)) @@ -283,7 +283,7 @@ static void movieclip_calc_length(MovieClip *clip) clip->len = framenr + 1; } else { - for (;;) { + for (;; ) { get_sequence_fname(clip, framenr, name); if (!BLI_exists(name)) { @@ -338,7 +338,7 @@ typedef struct MovieClipImBufCacheKey { static void moviecache_keydata(void *userkey, int *framenr, int *proxy, int *render_flags) { - MovieClipImBufCacheKey *key = (MovieClipImBufCacheKey*)userkey; + MovieClipImBufCacheKey *key = (MovieClipImBufCacheKey *)userkey; *framenr = key->framenr; *proxy = key->proxy; @@ -347,7 +347,7 @@ static void moviecache_keydata(void *userkey, int *framenr, int *proxy, int *ren static unsigned int moviecache_hashhash(const void *keyv) { - MovieClipImBufCacheKey *key = (MovieClipImBufCacheKey*)keyv; + MovieClipImBufCacheKey *key = (MovieClipImBufCacheKey *)keyv; int rval = key->framenr; return rval; @@ -355,8 +355,8 @@ static unsigned int moviecache_hashhash(const void *keyv) static int moviecache_hashcmp(const void *av, const void *bv) { - const MovieClipImBufCacheKey *a = (MovieClipImBufCacheKey*)av; - const MovieClipImBufCacheKey *b = (MovieClipImBufCacheKey*)bv; + const MovieClipImBufCacheKey *a = (MovieClipImBufCacheKey *)av; + const MovieClipImBufCacheKey *b = (MovieClipImBufCacheKey *)bv; if (a->framenr < b->framenr) return -1; @@ -406,7 +406,7 @@ static void put_imbuf_cache(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, i clip->cache = MEM_callocN(sizeof(MovieClipCache), "movieClipCache"); clip->cache->moviecache = IMB_moviecache_create(sizeof(MovieClipImBufCacheKey), moviecache_hashhash, - moviecache_hashcmp, moviecache_keydata); + moviecache_hashcmp, moviecache_keydata); } key.framenr = user->framenr; @@ -430,7 +430,7 @@ static MovieClip *movieclip_alloc(const char *name) { MovieClip *clip; - clip = alloc_libblock(&G.main->movieclip, ID_MC, name); + clip = BKE_libblock_alloc(&G.main->movieclip, ID_MC, name); clip->aspx = clip->aspy = 1.0f; @@ -529,8 +529,8 @@ static void real_ibuf_size(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, in break; case MCLIP_PROXY_RENDER_SIZE_75: - *width = ((float)*width)*4.0f/3.0f; - *height = ((float)*height)*4.0f/3.0f; + *width = ((float)*width) * 4.0f / 3.0f; + *height = ((float)*height) * 4.0f / 3.0f; break; } } @@ -635,7 +635,8 @@ static ImBuf *get_postprocessed_cached_frame(MovieClip *clip, MovieClipUser *use return cache->postprocessed.ibuf; } -static ImBuf *put_postprocessed_frame_to_cache(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, int flag, int postprocess_flag) +static ImBuf *put_postprocessed_frame_to_cache(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, + int flag, int postprocess_flag) { MovieClipCache *cache = clip->cache; MovieTrackingCamera *camera = &clip->tracking.camera; @@ -669,8 +670,8 @@ static ImBuf *put_postprocessed_frame_to_cache(MovieClip *clip, MovieClipUser *u if (postprocess_flag) { int disable_red = postprocess_flag & MOVIECLIP_DISABLE_RED, disable_green = postprocess_flag & MOVIECLIP_DISABLE_GREEN, - disable_blue = postprocess_flag & MOVIECLIP_DISABLE_BLUE, - grayscale = postprocess_flag & MOVIECLIP_PREVIEW_GRAYSCALE; + disable_blue = postprocess_flag & MOVIECLIP_DISABLE_BLUE, + grayscale = postprocess_flag & MOVIECLIP_PREVIEW_GRAYSCALE; if (!postproc_ibuf) postproc_ibuf = IMB_dupImBuf(ibuf); @@ -801,8 +802,8 @@ static ImBuf *get_stable_cached_frame(MovieClip *clip, MovieClipUser *user, int /* check for stabilization parameters */ if (tscale != cache->stabilized.scale || - tangle != cache->stabilized.angle || - !equals_v2v2(tloc, cache->stabilized.loc)) + tangle != cache->stabilized.angle || + !equals_v2v2(tloc, cache->stabilized.loc)) { return NULL; } @@ -851,7 +852,8 @@ static ImBuf *put_stabilized_frame_to_cache(MovieClip *clip, MovieClipUser *user return stableibuf; } -ImBuf *BKE_movieclip_get_stable_ibuf(MovieClip *clip, MovieClipUser *user, float loc[2], float *scale, float *angle, int postprocess_flag) +ImBuf *BKE_movieclip_get_stable_ibuf(MovieClip *clip, MovieClipUser *user, float loc[2], float *scale, float *angle, + int postprocess_flag) { ImBuf *ibuf, *stableibuf = NULL; int framenr = user->framenr; @@ -1038,7 +1040,7 @@ void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClip scopes->track_disabled = FALSE; - if (ibuf && ibuf->rect) { + if (ibuf && (ibuf->rect || ibuf->rect_float)) { ImBuf *tmpibuf; MovieTrackingMarker undist_marker = *marker; @@ -1049,17 +1051,17 @@ void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClip BKE_movieclip_get_size(clip, user, &width, &height); undist_marker.pos[0] *= width; - undist_marker.pos[1] *= height*aspy; + undist_marker.pos[1] *= height * aspy; BKE_tracking_invert_intrinsics(&clip->tracking, undist_marker.pos, undist_marker.pos); undist_marker.pos[0] /= width; - undist_marker.pos[1] /= height*aspy; + undist_marker.pos[1] /= height * aspy; } /* NOTE: margin should be kept in sync with value from ui_draw_but_TRACKPREVIEW */ tmpibuf = BKE_tracking_get_pattern_imbuf(ibuf, track, &undist_marker, 3 /* margin */, - 1 /* anchor */, scopes->track_pos, NULL); + 1 /* anchor */, scopes->track_pos, NULL); if (tmpibuf->rect_float) IMB_rect_from_float(tmpibuf); @@ -1073,11 +1075,11 @@ void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClip IMB_freeImBuf(ibuf); } - if ((track->flag & TRACK_LOCKED)==0) { + if ((track->flag & TRACK_LOCKED) == 0) { scopes->marker = marker; scopes->track = track; - scopes->slide_scale[0] = track->pat_max[0]-track->pat_min[0]; - scopes->slide_scale[1] = track->pat_max[1]-track->pat_min[1]; + scopes->slide_scale[0] = track->pat_max[0] - track->pat_min[0]; + scopes->slide_scale[1] = track->pat_max[1] - track->pat_min[1]; } } } diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index f3901cec506..724d80afdd9 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -46,6 +46,7 @@ #include "BLI_pbvh.h" #include "BLI_utildefines.h" +#include "BKE_ccg.h" #include "BKE_cdderivedmesh.h" #include "BKE_mesh.h" #include "BKE_modifier.h" @@ -75,37 +76,42 @@ typedef enum { } DispOp; static void multires_mvert_to_ss(DerivedMesh *dm, MVert *mvert); -static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm2, DispOp op, DMGridData **oldGridData, int totlvl); +static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm2, DispOp op, CCGElem **oldGridData, int totlvl); /** Customdata **/ void multires_customdata_delete(Mesh *me) { if (me->edit_btmesh) { - BMEditMesh *em= me->edit_btmesh; + BMEditMesh *em = me->edit_btmesh; /* CustomData_external_remove is used here only to mark layer * as non-external for further free-ing, so zero element count * looks safer than em->totface */ CustomData_external_remove(&em->bm->ldata, &me->id, - CD_MDISPS, 0); + CD_MDISPS, 0); BM_data_layer_free(em->bm, &em->bm->ldata, CD_MDISPS); + + BM_data_layer_free(em->bm, &em->bm->ldata, CD_GRID_PAINT_MASK); } else { CustomData_external_remove(&me->ldata, &me->id, - CD_MDISPS, me->totloop); + CD_MDISPS, me->totloop); CustomData_free_layer_active(&me->ldata, CD_MDISPS, - me->totloop); + me->totloop); + + CustomData_free_layer_active(&me->ldata, CD_GRID_PAINT_MASK, + me->totloop); } } /** Grid hiding **/ static BLI_bitmap multires_mdisps_upsample_hidden(BLI_bitmap lo_hidden, - int lo_level, - int hi_level, - - /* assumed to be at hi_level (or - * null) */ - BLI_bitmap prev_hidden) + int lo_level, + int hi_level, + + /* assumed to be at hi_level (or + * null) */ + BLI_bitmap prev_hidden) { BLI_bitmap subd; int hi_gridsize = ccg_gridsize(hi_level); @@ -163,8 +169,8 @@ static BLI_bitmap multires_mdisps_upsample_hidden(BLI_bitmap lo_hidden, } static BLI_bitmap multires_mdisps_downsample_hidden(BLI_bitmap old_hidden, - int old_level, - int new_level) + int old_level, + int new_level) { BLI_bitmap new_hidden; int new_gridsize = ccg_gridsize(new_level); @@ -174,16 +180,16 @@ static BLI_bitmap multires_mdisps_downsample_hidden(BLI_bitmap old_hidden, BLI_assert(new_level <= old_level); factor = ccg_factor(new_level, old_level); new_hidden = BLI_BITMAP_NEW(new_gridsize * new_gridsize, - "downsample hidden"); + "downsample hidden"); for (y = 0; y < new_gridsize; y++) { for (x = 0; x < new_gridsize; x++) { old_value = BLI_BITMAP_GET(old_hidden, - factor*y*old_gridsize + x*factor); + factor * y * old_gridsize + x * factor); - BLI_BITMAP_MODIFY(new_hidden, y*new_gridsize + x, old_value); + BLI_BITMAP_MODIFY(new_hidden, y * new_gridsize + x, old_value); } } @@ -191,7 +197,7 @@ static BLI_bitmap multires_mdisps_downsample_hidden(BLI_bitmap old_hidden, } static void multires_output_hidden_to_ccgdm(CCGDerivedMesh *ccgdm, - Mesh *me, int level) + Mesh *me, int level) { const MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS); BLI_bitmap *grid_hidden = ccgdm->gridHidden; @@ -208,7 +214,7 @@ static void multires_output_hidden_to_ccgdm(CCGDerivedMesh *ccgdm, if (gh) { grid_hidden[g] = - multires_mdisps_downsample_hidden(gh, md->level, level); + multires_mdisps_downsample_hidden(gh, md->level, level); } } } @@ -227,9 +233,9 @@ static void multires_mdisps_subdivide_hidden(MDisps *md, int new_level) return; subd = multires_mdisps_upsample_hidden(md->hidden, - md->level, - new_level, - NULL); + md->level, + new_level, + NULL); /* swap in the subdivided data */ MEM_freeN(md->hidden); @@ -239,7 +245,7 @@ static void multires_mdisps_subdivide_hidden(MDisps *md, int new_level) static MDisps *multires_mdisps_initialize_hidden(Mesh *me, int level) { MDisps *mdisps = CustomData_add_layer(&me->ldata, CD_MDISPS, - CD_CALLOC, 0, me->totloop); + CD_CALLOC, 0, me->totloop); int gridsize = ccg_gridsize(level); int gridarea = gridsize * gridsize; int i, j, k; @@ -274,12 +280,12 @@ static MDisps *multires_mdisps_initialize_hidden(Mesh *me, int level) DerivedMesh *get_multires_dm(Scene *scene, MultiresModifierData *mmd, Object *ob) { - ModifierData *md= (ModifierData *)mmd; + ModifierData *md = (ModifierData *)mmd; ModifierTypeInfo *mti = modifierType_getInfo(md->type); DerivedMesh *tdm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); DerivedMesh *dm; - dm = mti->applyModifier(md, ob, tdm, 0, 1); + dm = mti->applyModifier(md, ob, tdm, MOD_APPLY_USECACHE); if (dm == tdm) { dm = CDDM_copy(tdm); } @@ -294,7 +300,7 @@ MultiresModifierData *find_multires_modifier_before(Scene *scene, ModifierData * for (md = lastmd; md; md = md->prev) { if (md->type == eModifierType_Multires) { if (modifier_isEnabled(scene, md, eModifierMode_Realtime)) - return (MultiresModifierData*)md; + return (MultiresModifierData *)md; } } @@ -307,16 +313,16 @@ MultiresModifierData *find_multires_modifier_before(Scene *scene, ModifierData * MultiresModifierData *get_multires_modifier(Scene *scene, Object *ob, int use_first) { ModifierData *md; - MultiresModifierData *mmd= NULL, *firstmmd= NULL; + MultiresModifierData *mmd = NULL, *firstmmd = NULL; /* find first active multires modifier */ for (md = ob->modifiers.first; md; md = md->next) { if (md->type == eModifierType_Multires) { if (!firstmmd) - firstmmd= (MultiresModifierData*)md; + firstmmd = (MultiresModifierData *)md; if (modifier_isEnabled(scene, md, eModifierMode_Realtime)) { - mmd= (MultiresModifierData*)md; + mmd = (MultiresModifierData *)md; break; } } @@ -334,11 +340,11 @@ MultiresModifierData *get_multires_modifier(Scene *scene, Object *ob, int use_fi static int multires_get_level(Object *ob, MultiresModifierData *mmd, int render) { if (render) - return (mmd->modifier.scene)? get_render_subsurf_level(&mmd->modifier.scene->r, mmd->renderlvl): mmd->renderlvl; + return (mmd->modifier.scene) ? get_render_subsurf_level(&mmd->modifier.scene->r, mmd->renderlvl) : mmd->renderlvl; else if (ob->mode == OB_MODE_SCULPT) return mmd->sculptlvl; else - return (mmd->modifier.scene)? get_render_subsurf_level(&mmd->modifier.scene->r, mmd->lvl): mmd->lvl; + return (mmd->modifier.scene) ? get_render_subsurf_level(&mmd->modifier.scene->r, mmd->lvl) : mmd->lvl; } static void multires_set_tot_level(Object *ob, MultiresModifierData *mmd, int lvl) @@ -354,7 +360,7 @@ static void multires_set_tot_level(Object *ob, MultiresModifierData *mmd, int lv static void multires_dm_mark_as_modified(DerivedMesh *dm, MultiresModifiedFlags flags) { - CCGDerivedMesh *ccgdm = (CCGDerivedMesh*)dm; + CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; ccgdm->multires.modified_flags |= flags; } @@ -368,20 +374,20 @@ void multires_force_update(Object *ob) { if (ob) { if (ob->derivedFinal) { - ob->derivedFinal->needsFree =1; + ob->derivedFinal->needsFree = 1; ob->derivedFinal->release(ob->derivedFinal); ob->derivedFinal = NULL; } if (ob->sculpt && ob->sculpt->pbvh) { BLI_pbvh_free(ob->sculpt->pbvh); - ob->sculpt->pbvh= NULL; + ob->sculpt->pbvh = NULL; } } } void multires_force_external_reload(Object *ob) { - Mesh *me = get_mesh(ob); + Mesh *me = BKE_mesh_from_object(ob); CustomData_external_reload(&me->ldata, &me->id, CD_MASK_MDISPS, me->totloop); multires_force_update(ob); @@ -394,9 +400,9 @@ void multires_force_render_update(Object *ob) } int multiresModifier_reshapeFromDM(Scene *scene, MultiresModifierData *mmd, - Object *ob, DerivedMesh *srcdm) + Object *ob, DerivedMesh *srcdm) { - DerivedMesh *mrdm = get_multires_dm (scene, mmd, ob); + DerivedMesh *mrdm = get_multires_dm(scene, mmd, ob); if (mrdm && srcdm && mrdm->getNumVerts(mrdm) == srcdm->getNumVerts(srcdm)) { multires_mvert_to_ss(mrdm, srcdm->getVertArray(srcdm)); @@ -422,7 +428,7 @@ int multiresModifier_reshape(Scene *scene, MultiresModifierData *mmd, Object *ds } int multiresModifier_reshapeFromDeformMod(Scene *scene, MultiresModifierData *mmd, - Object *ob, ModifierData *md) + Object *ob, ModifierData *md) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); DerivedMesh *dm, *ndm; @@ -434,20 +440,20 @@ int multiresModifier_reshapeFromDeformMod(Scene *scene, MultiresModifierData *mm /* Create DerivedMesh for deformation modifier */ dm = get_multires_dm(scene, mmd, ob); - numVerts= dm->getNumVerts(dm); - deformedVerts= MEM_callocN(sizeof(float)*numVerts*3, "multiresReshape_deformVerts"); + numVerts = dm->getNumVerts(dm); + deformedVerts = MEM_callocN(sizeof(float) * numVerts * 3, "multiresReshape_deformVerts"); dm->getVertCos(dm, deformedVerts); - mti->deformVerts(md, ob, dm, deformedVerts, numVerts, 0, 0); + mti->deformVerts(md, ob, dm, deformedVerts, numVerts, 0); - ndm= CDDM_copy(dm); + ndm = CDDM_copy(dm); CDDM_apply_vert_coords(ndm, deformedVerts); MEM_freeN(deformedVerts); dm->release(dm); /* Reshaping */ - result= multiresModifier_reshapeFromDM(scene, mmd, ob, ndm); + result = multiresModifier_reshapeFromDM(scene, mmd, ob, ndm); /* Cleanup */ ndm->release(ndm); @@ -460,25 +466,25 @@ static int get_levels_from_disps(Object *ob) { Mesh *me = ob->data; MDisps *mdisp, *md; - int i, j, totlvl= 0; + int i, j, totlvl = 0; mdisp = CustomData_get_layer(&me->ldata, CD_MDISPS); for (i = 0; i < me->totpoly; ++i) { md = mdisp + me->mpoly[i].loopstart; - for (j=0; j<me->mpoly[i].totloop; j++, md++) { + for (j = 0; j < me->mpoly[i].totloop; j++, md++) { if (md->totdisp == 0) continue; while (1) { - int side = (1 << (totlvl-1)) + 1; - int lvl_totdisp = side*side; + int side = (1 << (totlvl - 1)) + 1; + int lvl_totdisp = side * side; if (md->totdisp == lvl_totdisp) break; else if (md->totdisp < lvl_totdisp) - --totlvl; + totlvl--; else - ++totlvl; + totlvl++; } @@ -510,7 +516,7 @@ void multiresModifier_set_levels_from_disps(MultiresModifierData *mmd, Object *o static void multires_set_tot_mdisps(Mesh *me, int lvl) { - MDisps *mdisps= CustomData_get_layer(&me->ldata, CD_MDISPS); + MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS); int i; if (mdisps) { @@ -554,50 +560,79 @@ static void multires_copy_grid(float (*gridA)[3], float (*gridB)[3], int sizeA, int x, y, j, skip; if (sizeA > sizeB) { - skip = (sizeA-1)/(sizeB-1); + skip = (sizeA - 1) / (sizeB - 1); for (j = 0, y = 0; y < sizeB; y++) for (x = 0; x < sizeB; x++, j++) - copy_v3_v3(gridA[y*skip*sizeA + x*skip], gridB[j]); + copy_v3_v3(gridA[y * skip * sizeA + x * skip], gridB[j]); } else { - skip = (sizeB-1)/(sizeA-1); + skip = (sizeB - 1) / (sizeA - 1); for (j = 0, y = 0; y < sizeA; y++) for (x = 0; x < sizeA; x++, j++) - copy_v3_v3(gridA[j], gridB[y*skip*sizeB + x*skip]); + copy_v3_v3(gridA[j], gridB[y * skip * sizeB + x * skip]); } } -static void multires_copy_dm_grid(DMGridData *gridA, DMGridData *gridB, int sizeA, int sizeB) +static void multires_copy_dm_grid(CCGElem *gridA, CCGElem *gridB, CCGKey *keyA, CCGKey *keyB) { int x, y, j, skip; - if (sizeA > sizeB) { - skip = (sizeA-1)/(sizeB-1); + if (keyA->grid_size > keyB->grid_size) { + skip = (keyA->grid_size - 1) / (keyB->grid_size - 1); - for (j = 0, y = 0; y < sizeB; y++) - for (x = 0; x < sizeB; x++, j++) - copy_v3_v3(gridA[y*skip*sizeA + x*skip].co, gridB[j].co); + for (j = 0, y = 0; y < keyB->grid_size; y++) + for (x = 0; x < keyB->grid_size; x++, j++) + memcpy(CCG_elem_offset_co(keyA, gridA, y * skip * keyA->grid_size + x * skip), + CCG_elem_offset_co(keyB, gridB, j), + sizeof(float) * keyA->num_layers); } else { - skip = (sizeB-1)/(sizeA-1); + skip = (keyB->grid_size - 1) / (keyA->grid_size - 1); - for (j = 0, y = 0; y < sizeA; y++) - for (x = 0; x < sizeA; x++, j++) - copy_v3_v3(gridA[j].co, gridB[y*skip*sizeB + x*skip].co); + for (j = 0, y = 0; y < keyA->grid_size; y++) + for (x = 0; x < keyA->grid_size; x++, j++) + memcpy(CCG_elem_offset_co(keyA, gridA, j), + CCG_elem_offset_co(keyB, gridB, y * skip * keyB->grid_size + x * skip), + sizeof(float) * keyA->num_layers); + } +} + +/* Reallocate gpm->data at a lower resolution and copy values over + from the original high-resolution data */ +static void multires_grid_paint_mask_downsample(GridPaintMask *gpm, int level) +{ + if (level < gpm->level) { + int gridsize = ccg_gridsize(level); + float *data = MEM_callocN(sizeof(float) * gridsize * gridsize, + "multires_grid_paint_mask_downsample"); + int x, y; + + for (y = 0; y < gridsize; y++) { + for (x = 0; x < gridsize; x++) { + data[y * gridsize + x] = + paint_grid_paint_mask(gpm, level, x, y); + } + } + + MEM_freeN(gpm->data); + gpm->data = data; + gpm->level = level; } } static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl) { - Mesh *me = (Mesh*)ob->data; + Mesh *me = (Mesh *)ob->data; int levels = mmd->totlvl - lvl; MDisps *mdisps; + GridPaintMask *gpm; multires_set_tot_mdisps(me, mmd->totlvl); CustomData_external_read(&me->ldata, &me->id, CD_MASK_MDISPS, me->totloop); - mdisps= CustomData_get_layer(&me->ldata, CD_MDISPS); + mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS); + gpm = CustomData_get_layer(&me->ldata, CD_GRID_PAINT_MASK); multires_force_update(ob); @@ -609,8 +644,9 @@ static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl) int i, j; for (i = 0; i < me->totpoly; ++i) { - for (j=0; j<me->mpoly[i].totloop; j++) { - MDisps *mdisp= &mdisps[me->mpoly[i].loopstart+j]; + for (j = 0; j < me->mpoly[i].totloop; j++) { + int g = me->mpoly[i].loopstart + j; + MDisps *mdisp = &mdisps[g]; float (*disps)[3], (*ndisps)[3], (*hdisps)[3]; int totdisp = multires_grid_tot[lvl]; @@ -622,20 +658,22 @@ static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl) multires_copy_grid(ndisps, hdisps, nsize, hsize); if (mdisp->hidden) { BLI_bitmap gh = - multires_mdisps_downsample_hidden(mdisp->hidden, - mdisp->level, - lvl); + multires_mdisps_downsample_hidden(mdisp->hidden, + mdisp->level, + lvl); MEM_freeN(mdisp->hidden); mdisp->hidden = gh; } - ndisps += nsize*nsize; - hdisps += hsize*hsize; + ndisps += nsize * nsize; + hdisps += hsize * hsize; MEM_freeN(mdisp->disps); mdisp->disps = disps; mdisp->totdisp = totdisp; mdisp->level = lvl; + + multires_grid_paint_mask_downsample(&gpm[g], lvl); } } } @@ -650,14 +688,14 @@ static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl) /* direction=1 for delete higher, direction=0 for lower (not implemented yet) */ void multiresModifier_del_levels(MultiresModifierData *mmd, Object *ob, int direction) { - Mesh *me = get_mesh(ob); + Mesh *me = BKE_mesh_from_object(ob); int lvl = multires_get_level(ob, mmd, 0); int levels = mmd->totlvl - lvl; MDisps *mdisps; multires_set_tot_mdisps(me, mmd->totlvl); CustomData_external_read(&me->ldata, &me->id, CD_MASK_MDISPS, me->totloop); - mdisps= CustomData_get_layer(&me->ldata, CD_MDISPS); + mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS); multires_force_update(ob); @@ -668,9 +706,10 @@ void multiresModifier_del_levels(MultiresModifierData *mmd, Object *ob, int dire multires_set_tot_level(ob, mmd, lvl); } -static DerivedMesh *multires_dm_create_local(Object *ob, DerivedMesh *dm, int lvl, int totlvl, int simple) +static DerivedMesh *multires_dm_create_local(Object *ob, DerivedMesh *dm, int lvl, int totlvl, int simple, int alloc_paint_mask) { - MultiresModifierData mmd= {{NULL}}; + MultiresModifierData mmd = {{NULL}}; + MultiresFlags flags = MULTIRES_USE_LOCAL_MMD; mmd.lvl = lvl; mmd.sculptlvl = lvl; @@ -678,12 +717,16 @@ static DerivedMesh *multires_dm_create_local(Object *ob, DerivedMesh *dm, int lv mmd.totlvl = totlvl; mmd.simple = simple; - return multires_dm_create_from_derived(&mmd, 1, dm, ob, 0); + if (alloc_paint_mask) + flags |= MULTIRES_ALLOC_PAINT_MASK; + + return multires_make_derived_from_derived(dm, &mmd, ob, flags); } -static DerivedMesh *subsurf_dm_create_local(Object *ob, DerivedMesh *dm, int lvl, int simple, int optimal, int plain_uv) +static DerivedMesh *subsurf_dm_create_local(Object *ob, DerivedMesh *dm, int lvl, int simple, int optimal, int plain_uv, int alloc_paint_mask) { - SubsurfModifierData smd= {{NULL}}; + SubsurfModifierData smd = {{NULL}}; + SubsurfFlags flags = 0; smd.levels = smd.renderLevels = lvl; if (!plain_uv) @@ -693,7 +736,13 @@ static DerivedMesh *subsurf_dm_create_local(Object *ob, DerivedMesh *dm, int lvl if (optimal) smd.flags |= eSubsurfModifierFlag_ControlEdges; - return subsurf_make_derived_from_derived(dm, &smd, 0, NULL, 0, 0, (ob->mode & OB_MODE_EDIT)); + if (ob->mode & OB_MODE_EDIT) + flags |= SUBSURF_IN_EDIT_MODE; + + if (alloc_paint_mask) + flags |= SUBSURF_ALLOC_PAINT_MASK; + + return subsurf_make_derived_from_derived(dm, &smd, NULL, flags); } @@ -717,7 +766,7 @@ void multiresModifier_base_apply(MultiresModifierData *mmd, Object *ob) multires_force_update(ob); - me = get_mesh(ob); + me = BKE_mesh_from_object(ob); totlvl = mmd->totlvl; /* nothing to do */ @@ -729,7 +778,7 @@ void multiresModifier_base_apply(MultiresModifierData *mmd, Object *ob) /* generate highest level with displacements */ cddm = CDDM_from_mesh(me, NULL); DM_set_only_copy(cddm, CD_MASK_BAREMESH); - dispdm = multires_dm_create_local(ob, cddm, totlvl, totlvl, 0); + dispdm = multires_dm_create_local(ob, cddm, totlvl, totlvl, 0, 0); cddm->release(cddm); /* copy the new locations of the base verts into the mesh */ @@ -742,8 +791,8 @@ void multiresModifier_base_apply(MultiresModifierData *mmd, Object *ob) cddm = CDDM_from_mesh(me, NULL); pmap = cddm->getPolyMap(ob, cddm); - origco = MEM_callocN(sizeof(float)*3*me->totvert, "multires apply base origco"); - for (i = 0; i < me->totvert ;++i) + origco = MEM_callocN(sizeof(float) * 3 * me->totvert, "multires apply base origco"); + for (i = 0; i < me->totvert; ++i) copy_v3_v3(origco[i], me->mvert[i].co); for (i = 0; i < me->totvert; ++i) { @@ -764,7 +813,7 @@ void multiresModifier_base_apply(MultiresModifierData *mmd, Object *ob) int vndx = me->mloop[p->loopstart + k].v; if (vndx != i) { add_v3_v3(center, origco[vndx]); - ++tot; + tot++; } } } @@ -779,7 +828,7 @@ void multiresModifier_base_apply(MultiresModifierData *mmd, Object *ob) float no[3]; /* set up poly, loops, and coords in order to call - * mesh_calc_poly_normal_coords() */ + * BKE_mesh_calc_poly_normal_coords() */ fake_poly.totloop = p->totloop; fake_poly.loopstart = 0; fake_loops = MEM_mallocN(sizeof(MLoop) * p->totloop, "fake_loops"); @@ -796,8 +845,8 @@ void multiresModifier_base_apply(MultiresModifierData *mmd, Object *ob) copy_v3_v3(fake_co[k], origco[vndx]); } - mesh_calc_poly_normal_coords(&fake_poly, fake_loops, - (const float(*)[3])fake_co, no); + BKE_mesh_calc_poly_normal_coords(&fake_poly, fake_loops, + (const float(*)[3])fake_co, no); MEM_freeN(fake_loops); MEM_freeN(fake_co); @@ -819,7 +868,7 @@ void multiresModifier_base_apply(MultiresModifierData *mmd, Object *ob) /* subdivide the mesh to highest level without displacements */ cddm = CDDM_from_mesh(me, NULL); DM_set_only_copy(cddm, CD_MASK_BAREMESH); - origdm = subsurf_dm_create_local(ob, cddm, totlvl, 0, 0, mmd->flags & eMultiresModifierFlag_PlainUv); + origdm = subsurf_dm_create_local(ob, cddm, totlvl, 0, 0, mmd->flags & eMultiresModifierFlag_PlainUv, 0); cddm->release(cddm); /* calc disps */ @@ -833,7 +882,7 @@ static void multires_subdivide(MultiresModifierData *mmd, Object *ob, int totlvl { Mesh *me = ob->data; MDisps *mdisps; - int lvl= mmd->totlvl; + int lvl = mmd->totlvl; if ((totlvl > multires_max_levels) || (me->totpoly == 0)) return; @@ -847,42 +896,44 @@ static void multires_subdivide(MultiresModifierData *mmd, Object *ob, int totlvl if (mdisps->disps && !updateblock && totlvl > 1) { /* upsample */ DerivedMesh *lowdm, *cddm, *highdm; - DMGridData **highGridData, **lowGridData, **subGridData; + CCGElem **highGridData, **lowGridData, **subGridData; + CCGKey highGridKey, lowGridKey; CCGSubSurf *ss; - int i, numGrids, highGridSize, lowGridSize; + int i, numGrids, highGridSize; /* create subsurf DM from original mesh at high level */ cddm = CDDM_from_mesh(me, NULL); DM_set_only_copy(cddm, CD_MASK_BAREMESH); - highdm = subsurf_dm_create_local(ob, cddm, totlvl, simple, 0, mmd->flags & eMultiresModifierFlag_PlainUv); + highdm = subsurf_dm_create_local(ob, cddm, totlvl, simple, 0, mmd->flags & eMultiresModifierFlag_PlainUv, TRUE); + ss = ((CCGDerivedMesh *)highdm)->ss; /* create multires DM from original mesh at low level */ - lowdm = multires_dm_create_local(ob, cddm, lvl, lvl, simple); + lowdm = multires_dm_create_local(ob, cddm, lvl, lvl, simple, TRUE); cddm->release(cddm); /* copy subsurf grids and replace them with low displaced grids */ numGrids = highdm->getNumGrids(highdm); highGridSize = highdm->getGridSize(highdm); highGridData = highdm->getGridData(highdm); - lowGridSize = lowdm->getGridSize(lowdm); + highdm->getGridKey(highdm, &highGridKey); lowGridData = lowdm->getGridData(lowdm); + lowdm->getGridKey(lowdm, &lowGridKey); - subGridData = MEM_callocN(sizeof(float*)*numGrids, "subGridData*"); + subGridData = MEM_callocN(sizeof(float *) * numGrids, "subGridData*"); for (i = 0; i < numGrids; ++i) { /* backup subsurf grids */ - subGridData[i] = MEM_callocN(sizeof(DMGridData)*highGridSize*highGridSize, "subGridData"); - memcpy(subGridData[i], highGridData[i], sizeof(DMGridData)*highGridSize*highGridSize); + subGridData[i] = MEM_callocN(highGridKey.elem_size * highGridSize * highGridSize, "subGridData"); + memcpy(subGridData[i], highGridData[i], highGridKey.elem_size * highGridSize * highGridSize); /* overwrite with current displaced grids */ - multires_copy_dm_grid(highGridData[i], lowGridData[i], highGridSize, lowGridSize); + multires_copy_dm_grid(highGridData[i], lowGridData[i], &highGridKey, &lowGridKey); } /* low lower level dm no longer needed at this point */ lowdm->release(lowdm); /* subsurf higher levels again with displaced data */ - ss= ((CCGDerivedMesh*)highdm)->ss; ccgSubSurf_updateFromFaces(ss, lvl, NULL, 0); ccgSubSurf_updateLevels(ss, lvl, NULL, 0); @@ -908,39 +959,41 @@ static void multires_subdivide(MultiresModifierData *mmd, Object *ob, int totlvl void multiresModifier_subdivide(MultiresModifierData *mmd, Object *ob, int updateblock, int simple) { - multires_subdivide(mmd, ob, mmd->totlvl+1, updateblock, simple); + multires_subdivide(mmd, ob, mmd->totlvl + 1, updateblock, simple); } -void grid_tangent(int gridSize, int index, int x, int y, int axis, DMGridData **gridData, float t[3]) +void grid_tangent(const CCGKey *key, int x, int y, int axis, CCGElem *grid, float t[3]) { if (axis == 0) { - if (x == gridSize - 1) { - if (y == gridSize - 1) - sub_v3_v3v3(t, gridData[index][x + gridSize*(y - 1)].co, gridData[index][x - 1 + gridSize*(y - 1)].co); + if (x == key->grid_size - 1) { + if (y == key->grid_size - 1) + sub_v3_v3v3(t, CCG_grid_elem_co(key, grid, x, y - 1), CCG_grid_elem_co(key, grid, x - 1, y - 1)); else - sub_v3_v3v3(t, gridData[index][x + gridSize*y].co, gridData[index][x - 1 + gridSize*y].co); + sub_v3_v3v3(t, CCG_grid_elem_co(key, grid, x, y), CCG_grid_elem_co(key, grid, x - 1, y)); } else - sub_v3_v3v3(t, gridData[index][x + 1 + gridSize*y].co, gridData[index][x + gridSize*y].co); + sub_v3_v3v3(t, CCG_grid_elem_co(key, grid, x + 1, y), CCG_grid_elem_co(key, grid, x, y)); } else if (axis == 1) { - if (y == gridSize - 1) { - if (x == gridSize - 1) - sub_v3_v3v3(t, gridData[index][x - 1 + gridSize*y].co, gridData[index][x - 1 + gridSize*(y - 1)].co); + if (y == key->grid_size - 1) { + if (x == key->grid_size - 1) + sub_v3_v3v3(t, CCG_grid_elem_co(key, grid, x - 1, y), CCG_grid_elem_co(key, grid, x - 1, (y - 1))); else - sub_v3_v3v3(t, gridData[index][x + gridSize*y].co, gridData[index][x + gridSize*(y - 1)].co); + sub_v3_v3v3(t, CCG_grid_elem_co(key, grid, x, y), CCG_grid_elem_co(key, grid, x, (y - 1))); } else - sub_v3_v3v3(t, gridData[index][x + gridSize*(y + 1)].co, gridData[index][x + gridSize*y].co); + sub_v3_v3v3(t, CCG_grid_elem_co(key, grid, x, (y + 1)), CCG_grid_elem_co(key, grid, x, y)); } } -static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm2, DispOp op, DMGridData **oldGridData, int totlvl) +static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm2, DispOp op, CCGElem **oldGridData, int totlvl) { - CCGDerivedMesh *ccgdm = (CCGDerivedMesh*)dm; - DMGridData **gridData, **subGridData; + CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; + CCGElem **gridData, **subGridData; + CCGKey key; MPoly *mpoly = me->mpoly; MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS); + GridPaintMask *grid_paint_mask = NULL; int *gridOffset; int i, k, /*numGrids, */ gridSize, dGridSize, dSkip; int totloop, totpoly; @@ -968,10 +1021,15 @@ static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm gridSize = dm->getGridSize(dm); gridData = dm->getGridData(dm); gridOffset = dm->getGridOffset(dm); - subGridData = (oldGridData)? oldGridData: gridData; + dm->getGridKey(dm, &key); + subGridData = (oldGridData) ? oldGridData : gridData; dGridSize = multires_side_tot[totlvl]; - dSkip = (dGridSize-1)/(gridSize-1); + dSkip = (dGridSize - 1) / (gridSize - 1); + + /* multires paint masks */ + if (key.has_mask) + grid_paint_mask = CustomData_get_layer(&me->ldata, CD_GRID_PAINT_MASK); k = 0; /*current loop/mdisp index within the mloop array*/ @@ -982,9 +1040,10 @@ static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm int S, x, y, gIndex = gridOffset[i]; for (S = 0; S < numVerts; ++S, ++gIndex, ++k) { - MDisps *mdisp = &mdisps[mpoly[i].loopstart+S]; - DMGridData *grid = gridData[gIndex]; - DMGridData *subgrid = subGridData[gIndex]; + GridPaintMask *gpm = grid_paint_mask ? &grid_paint_mask[gIndex] : NULL; + MDisps *mdisp = &mdisps[mpoly[i].loopstart + S]; + CCGElem *grid = gridData[gIndex]; + CCGElem *subgrid = subGridData[gIndex]; float (*dispgrid)[3] = NULL; /* when adding new faces in edit mode, need to allocate disps */ @@ -996,19 +1055,28 @@ static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm dispgrid = mdisp->disps; + /* if needed, reallocate multires paint mask */ + if (gpm && op == CALC_DISPLACEMENTS) { + if (gpm->level < key.level) { + gpm->level = key.level; + MEM_freeN(gpm->data); + gpm->data = MEM_callocN(sizeof(float) * key.grid_area, "gpm.data"); + } + } + for (y = 0; y < gridSize; y++) { for (x = 0; x < gridSize; x++) { - float *co = grid[x + y*gridSize].co; - float *sco = subgrid[x + y*gridSize].co; - float *no = subgrid[x + y*gridSize].no; - float *data = dispgrid[dGridSize*y*dSkip + x*dSkip]; - float mat[3][3], tx[3], ty[3], disp[3], d[3]; + float *co = CCG_grid_elem_co(&key, grid, x, y); + float *sco = CCG_grid_elem_co(&key, subgrid, x, y); + float *no = CCG_grid_elem_no(&key, subgrid, x, y); + float *data = dispgrid[dGridSize * y * dSkip + x * dSkip]; + float mat[3][3], tx[3], ty[3], disp[3], d[3], mask; /* construct tangent space matrix */ - grid_tangent(gridSize, gIndex, x, y, 0, subGridData, tx); + grid_tangent(&key, x, y, 0, subGridData[gIndex], tx); normalize_v3(tx); - grid_tangent(gridSize, gIndex, x, y, 1, subGridData, ty); + grid_tangent(&key, x, y, 1, subGridData[gIndex], ty); normalize_v3(ty); //mul_v3_fl(tx, 1.0f/(gridSize-1)); @@ -1018,32 +1086,52 @@ static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm column_vectors_to_mat3(mat, tx, ty, no); switch (op) { - case APPLY_DISPLACEMENTS: - /* Convert displacement to object space - * and add to grid points */ - mul_v3_m3v3(disp, mat, data); - add_v3_v3v3(co, sco, disp); - break; - case CALC_DISPLACEMENTS: - /* Calculate displacement between new and old - * grid points and convert to tangent space */ - sub_v3_v3v3(disp, co, sco); - invert_m3(mat); - mul_v3_m3v3(data, mat, disp); - break; - case ADD_DISPLACEMENTS: - /* Convert subdivided displacements to tangent - * space and add to the original displacements */ - invert_m3(mat); - mul_v3_m3v3(d, mat, co); - add_v3_v3(data, d); - break; + case APPLY_DISPLACEMENTS: + /* Convert displacement to object space + * and add to grid points */ + mul_v3_m3v3(disp, mat, data); + add_v3_v3v3(co, sco, disp); + break; + case CALC_DISPLACEMENTS: + /* Calculate displacement between new and old + * grid points and convert to tangent space */ + sub_v3_v3v3(disp, co, sco); + invert_m3(mat); + mul_v3_m3v3(data, mat, disp); + break; + case ADD_DISPLACEMENTS: + /* Convert subdivided displacements to tangent + * space and add to the original displacements */ + invert_m3(mat); + mul_v3_m3v3(d, mat, co); + add_v3_v3(data, d); + break; + } + + if (gpm) { + switch (op) { + case APPLY_DISPLACEMENTS: + /* Copy mask from gpm to DM */ + *CCG_grid_elem_mask(&key, grid, x, y) = + paint_grid_paint_mask(gpm, key.level, x, y); + break; + case CALC_DISPLACEMENTS: + /* Copy mask from DM to gpm */ + mask = *CCG_grid_elem_mask(&key, grid, x, y); + gpm->data[y * gridSize + x] = CLAMPIS(mask, 0, 1); + break; + case ADD_DISPLACEMENTS: + /* Add mask displacement to gpm */ + gpm->data[y * gridSize + x] += + *CCG_grid_elem_mask(&key, grid, x, y); + break; + } } } } } } - + if (op == APPLY_DISPLACEMENTS) { ccgSubSurf_stitchFaces(ccgdm->ss, 0, NULL, 0); ccgSubSurf_updateNormals(ccgdm->ss, NULL, 0); @@ -1052,7 +1140,7 @@ static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm void multires_modifier_update_mdisps(struct DerivedMesh *dm) { - CCGDerivedMesh *ccgdm= (CCGDerivedMesh*)dm; + CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; Object *ob; Mesh *me; MDisps *mdisps; @@ -1072,7 +1160,8 @@ void multires_modifier_update_mdisps(struct DerivedMesh *dm) if (lvl < totlvl) { Mesh *me = ob->data; DerivedMesh *lowdm, *cddm, *highdm; - DMGridData **highGridData, **lowGridData, **subGridData, **gridData, *diffGrid; + CCGElem **highGridData, **lowGridData, **subGridData, **gridData, *diffGrid; + CCGKey highGridKey, lowGridKey; CCGSubSurf *ss; int i, j, numGrids, highGridSize, lowGridSize; @@ -1081,33 +1170,41 @@ void multires_modifier_update_mdisps(struct DerivedMesh *dm) else cddm = CDDM_from_mesh(me, NULL); DM_set_only_copy(cddm, CD_MASK_BAREMESH); - highdm = subsurf_dm_create_local(ob, cddm, totlvl, mmd->simple, 0, mmd->flags & eMultiresModifierFlag_PlainUv); + highdm = subsurf_dm_create_local(ob, cddm, totlvl, mmd->simple, 0, mmd->flags & eMultiresModifierFlag_PlainUv, TRUE); + ss = ((CCGDerivedMesh *)highdm)->ss; /* create multires DM from original mesh and displacements */ - lowdm = multires_dm_create_local(ob, cddm, lvl, totlvl, mmd->simple); + lowdm = multires_dm_create_local(ob, cddm, lvl, totlvl, mmd->simple, TRUE); cddm->release(cddm); /* gather grid data */ numGrids = highdm->getNumGrids(highdm); highGridSize = highdm->getGridSize(highdm); highGridData = highdm->getGridData(highdm); + highdm->getGridKey(highdm, &highGridKey); lowGridSize = lowdm->getGridSize(lowdm); lowGridData = lowdm->getGridData(lowdm); + lowdm->getGridKey(lowdm, &lowGridKey); gridData = dm->getGridData(dm); - subGridData = MEM_callocN(sizeof(DMGridData*)*numGrids, "subGridData*"); - diffGrid = MEM_callocN(sizeof(DMGridData)*lowGridSize*lowGridSize, "diff"); + BLI_assert(highGridKey.elem_size == lowGridKey.elem_size); + + subGridData = MEM_callocN(sizeof(CCGElem *) * numGrids, "subGridData*"); + diffGrid = MEM_callocN(lowGridKey.elem_size * lowGridSize * lowGridSize, "diff"); for (i = 0; i < numGrids; ++i) { /* backup subsurf grids */ - subGridData[i] = MEM_callocN(sizeof(DMGridData)*highGridSize*highGridSize, "subGridData"); - memcpy(subGridData[i], highGridData[i], sizeof(DMGridData)*highGridSize*highGridSize); + subGridData[i] = MEM_callocN(highGridKey.elem_size * highGridSize * highGridSize, "subGridData"); + memcpy(subGridData[i], highGridData[i], highGridKey.elem_size * highGridSize * highGridSize); /* write difference of subsurf and displaced low level into high subsurf */ - for (j = 0; j < lowGridSize*lowGridSize; ++j) - sub_v3_v3v3(diffGrid[j].co, gridData[i][j].co, lowGridData[i][j].co); + for (j = 0; j < lowGridSize * lowGridSize; ++j) { + sub_v4_v4v4(CCG_elem_offset_co(&lowGridKey, diffGrid, j), + CCG_elem_offset_co(&lowGridKey, gridData[i], j), + CCG_elem_offset_co(&lowGridKey, lowGridData[i], j)); + } - multires_copy_dm_grid(highGridData[i], diffGrid, highGridSize, lowGridSize); + multires_copy_dm_grid(highGridData[i], diffGrid, &highGridKey, &lowGridKey); } /* lower level dm no longer needed at this point */ @@ -1115,7 +1212,6 @@ void multires_modifier_update_mdisps(struct DerivedMesh *dm) lowdm->release(lowdm); /* subsurf higher levels again with difference of coordinates */ - ss= ((CCGDerivedMesh*)highdm)->ss; ccgSubSurf_updateFromFaces(ss, lvl, NULL, 0); ccgSubSurf_updateLevels(ss, lvl, NULL, 0); @@ -1135,7 +1231,7 @@ void multires_modifier_update_mdisps(struct DerivedMesh *dm) else cddm = CDDM_from_mesh(me, NULL); DM_set_only_copy(cddm, CD_MASK_BAREMESH); - subdm = subsurf_dm_create_local(ob, cddm, mmd->totlvl, mmd->simple, 0, mmd->flags & eMultiresModifierFlag_PlainUv); + subdm = subsurf_dm_create_local(ob, cddm, mmd->totlvl, mmd->simple, 0, mmd->flags & eMultiresModifierFlag_PlainUv, TRUE); cddm->release(cddm); multiresModifier_disp_run(dm, me, NULL, CALC_DISPLACEMENTS, subdm->getGridData(subdm), mmd->totlvl); @@ -1147,8 +1243,8 @@ void multires_modifier_update_mdisps(struct DerivedMesh *dm) void multires_modifier_update_hidden(DerivedMesh *dm) { - CCGDerivedMesh *ccgdm= (CCGDerivedMesh*)dm; - BLI_bitmap *grid_hidden= ccgdm->gridHidden; + CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; + BLI_bitmap *grid_hidden = ccgdm->gridHidden; Mesh *me = ccgdm->multires.ob->data; MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS); int totlvl = ccgdm->multires.totlvl; @@ -1167,7 +1263,7 @@ void multires_modifier_update_hidden(DerivedMesh *dm) } else if (gh) { gh = multires_mdisps_upsample_hidden(gh, lvl, totlvl, - md->hidden); + md->hidden); if (md->hidden) MEM_freeN(md->hidden); @@ -1180,7 +1276,8 @@ void multires_modifier_update_hidden(DerivedMesh *dm) void multires_set_space(DerivedMesh *dm, Object *ob, int from, int to) { DerivedMesh *ccgdm = NULL, *subsurf = NULL; - DMGridData **gridData, **subGridData=NULL; + CCGElem **gridData, **subGridData = NULL; + CCGKey key; MPoly *mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY); MDisps *mdisps; MultiresModifierData *mmd = get_multires_modifier(NULL, ob, 1); @@ -1197,29 +1294,30 @@ void multires_set_space(DerivedMesh *dm, Object *ob, int from, int to) } totlvl = mmd->totlvl; - ccgdm = multires_dm_create_local(ob, dm, totlvl, totlvl, mmd->simple); + ccgdm = multires_dm_create_local(ob, dm, totlvl, totlvl, mmd->simple, FALSE); subsurf = subsurf_dm_create_local(ob, dm, totlvl, - mmd->simple, mmd->flags & eMultiresModifierFlag_ControlEdges, mmd->flags & eMultiresModifierFlag_PlainUv); + mmd->simple, mmd->flags & eMultiresModifierFlag_ControlEdges, mmd->flags & eMultiresModifierFlag_PlainUv, 0); numGrids = subsurf->getNumGrids(subsurf); gridSize = subsurf->getGridSize(subsurf); gridData = subsurf->getGridData(subsurf); + subsurf->getGridKey(subsurf, &key); - subGridData = MEM_callocN(sizeof(DMGridData*)*numGrids, "subGridData*"); + subGridData = MEM_callocN(sizeof(CCGElem *) * numGrids, "subGridData*"); for (i = 0; i < numGrids; i++) { - subGridData[i] = MEM_callocN(sizeof(DMGridData)*gridSize*gridSize, "subGridData"); - memcpy(subGridData[i], gridData[i], sizeof(DMGridData)*gridSize*gridSize); + subGridData[i] = MEM_callocN(key.elem_size * gridSize * gridSize, "subGridData"); + memcpy(subGridData[i], gridData[i], key.elem_size * gridSize * gridSize); } /*numGrids = ccgdm->dm->getNumGrids((DerivedMesh*)ccgdm);*/ /*UNUSED*/ - gridSize = ccgdm->getGridSize((DerivedMesh*)ccgdm); - gridData = ccgdm->getGridData((DerivedMesh*)ccgdm); - gridOffset = ccgdm->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); + dSkip = (dGridSize - 1) / (gridSize - 1); k = 0; /*current loop/mdisp index within the mloop array*/ @@ -1230,32 +1328,32 @@ void multires_set_space(DerivedMesh *dm, Object *ob, int from, int to) int S, x, y, gIndex = gridOffset[i]; for (S = 0; S < numVerts; ++S, ++gIndex, ++k) { - MDisps *mdisp = &mdisps[mpoly[i].loopstart+S]; - /* DMGridData *grid = gridData[gIndex]; */ /* UNUSED */ - DMGridData *subgrid = subGridData[gIndex]; + MDisps *mdisp = &mdisps[mpoly[i].loopstart + S]; + /* CCGElem *grid = gridData[gIndex]; */ /* UNUSED */ + CCGElem *subgrid = subGridData[gIndex]; float (*dispgrid)[3] = NULL; /* when adding new faces in edit mode, need to allocate disps */ if (!mdisp->disps) { - mdisp->totdisp = gridSize*gridSize; + mdisp->totdisp = gridSize * gridSize; mdisp->level = totlvl; - mdisp->disps = MEM_callocN(sizeof(float)*3*mdisp->totdisp, "disp in multires_set_space"); + mdisp->disps = MEM_callocN(sizeof(float) * 3 * mdisp->totdisp, "disp in multires_set_space"); } dispgrid = mdisp->disps; for (y = 0; y < gridSize; y++) { for (x = 0; x < gridSize; x++) { - float *data = dispgrid[dGridSize*y*dSkip + x*dSkip]; - float *no = subgrid[x + y*gridSize].no; - float *co = subgrid[x + y*gridSize].co; + float *data = dispgrid[dGridSize * y * dSkip + x * dSkip]; + float *no = CCG_grid_elem_no(&key, subgrid, x, y); + float *co = CCG_grid_elem_co(&key, subgrid, x, y); float mat[3][3], tx[3], ty[3], dco[3]; /* construct tangent space matrix */ - grid_tangent(gridSize, gIndex, x, y, 0, subGridData, tx); + grid_tangent(&key, x, y, 0, subGridData[gIndex], tx); normalize_v3(tx); - grid_tangent(gridSize, gIndex, x, y, 1, subGridData, ty); + grid_tangent(&key, x, y, 1, subGridData[gIndex], ty); normalize_v3(ty); column_vectors_to_mat3(mat, tx, ty, no); @@ -1308,12 +1406,12 @@ void multires_stitch_grids(Object *ob) { /* utility for smooth brush */ if (ob && ob->derivedFinal) { - CCGDerivedMesh *ccgdm = (CCGDerivedMesh*)ob->derivedFinal; + CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)ob->derivedFinal; CCGFace **faces; int totface; if (ccgdm->pbvh) { - BLI_pbvh_get_grid_updates(ccgdm->pbvh, 0, (void***)&faces, &totface); + BLI_pbvh_get_grid_updates(ccgdm->pbvh, 0, (void ***)&faces, &totface); if (totface) { ccgSubSurf_stitchFaces(ccgdm->ss, 0, faces, totface); @@ -1323,30 +1421,33 @@ void multires_stitch_grids(Object *ob) } } -DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, - int local_mmd, DerivedMesh *dm, - Object *ob, int useRenderParams) +DerivedMesh *multires_make_derived_from_derived(DerivedMesh *dm, + MultiresModifierData *mmd, + Object *ob, + MultiresFlags flags) { - Mesh *me= ob->data; + Mesh *me = ob->data; DerivedMesh *result; CCGDerivedMesh *ccgdm = NULL; - DMGridData **gridData, **subGridData; - int lvl= multires_get_level(ob, mmd, useRenderParams); + CCGElem **gridData, **subGridData; + CCGKey key; + int lvl = multires_get_level(ob, mmd, (flags & MULTIRES_USE_RENDER_PARAMS)); int i, gridSize, numGrids; if (lvl == 0) return dm; result = subsurf_dm_create_local(ob, dm, lvl, - mmd->simple, mmd->flags & eMultiresModifierFlag_ControlEdges, - mmd->flags & eMultiresModifierFlag_PlainUv); + mmd->simple, mmd->flags & eMultiresModifierFlag_ControlEdges, + mmd->flags & eMultiresModifierFlag_PlainUv, + flags & MULTIRES_ALLOC_PAINT_MASK); - if (!local_mmd) { - ccgdm = (CCGDerivedMesh*)result; + if (!(flags & MULTIRES_USE_LOCAL_MMD)) { + ccgdm = (CCGDerivedMesh *)result; ccgdm->multires.ob = ob; ccgdm->multires.mmd = mmd; - ccgdm->multires.local_mmd = local_mmd; + ccgdm->multires.local_mmd = 0; ccgdm->multires.lvl = lvl; ccgdm->multires.totlvl = mmd->totlvl; ccgdm->multires.modified_flags = 0; @@ -1355,12 +1456,13 @@ DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, numGrids = result->getNumGrids(result); gridSize = result->getGridSize(result); gridData = result->getGridData(result); + result->getGridKey(result, &key); - subGridData = MEM_callocN(sizeof(DMGridData*)*numGrids, "subGridData*"); + subGridData = MEM_callocN(sizeof(CCGElem *) * numGrids, "subGridData*"); for (i = 0; i < numGrids; i++) { - subGridData[i] = MEM_callocN(sizeof(DMGridData)*gridSize*gridSize, "subGridData"); - memcpy(subGridData[i], gridData[i], sizeof(DMGridData)*gridSize*gridSize); + subGridData[i] = MEM_callocN(key.elem_size * gridSize * gridSize, "subGridData"); + memcpy(subGridData[i], gridData[i], key.elem_size * gridSize * gridSize); } multires_set_tot_mdisps(me, mmd->totlvl); @@ -1381,7 +1483,7 @@ DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, } /**** Old Multires code **** - ***************************/ +***************************/ /* Adapted from sculptmode.c */ void old_mdisps_bilinear(float out[3], float (*disps)[3], const int st, float u, float v) @@ -1430,22 +1532,22 @@ void old_mdisps_bilinear(float out[3], float (*disps)[3], const int st, float u, static void old_mdisps_rotate(int S, int UNUSED(newside), int oldside, int x, int y, float *u, float *v) { - float offset = oldside*0.5f - 0.5f; + float offset = oldside * 0.5f - 0.5f; - if (S == 1) { *u= offset + x; *v = offset - y; } - if (S == 2) { *u= offset + y; *v = offset + x; } - if (S == 3) { *u= offset - x; *v = offset + y; } - if (S == 0) { *u= offset - y; *v = offset - x; } + if (S == 1) { *u = offset + x; *v = offset - y; } + if (S == 2) { *u = offset + y; *v = offset + x; } + if (S == 3) { *u = offset - x; *v = offset + y; } + if (S == 0) { *u = offset - y; *v = offset - x; } } static void old_mdisps_convert(MFace *mface, MDisps *mdisp) { - int newlvl = log(sqrt(mdisp->totdisp)-1)/M_LN2; - int oldlvl = newlvl+1; + int newlvl = log(sqrt(mdisp->totdisp) - 1) / M_LN2; + int oldlvl = newlvl + 1; int oldside = multires_side_tot[oldlvl]; int newside = multires_side_tot[newlvl]; - int nvert = (mface->v4)? 4: 3; - int newtotdisp = multires_grid_tot[newlvl]*nvert; + int nvert = (mface->v4) ? 4 : 3; + int newtotdisp = multires_grid_tot[newlvl] * nvert; int x, y, S; float (*disps)[3], (*out)[3], u = 0.0f, v = 0.0f; /* Quite gcc barking. */ @@ -1458,19 +1560,19 @@ static void old_mdisps_convert(MFace *mface, MDisps *mdisp) old_mdisps_rotate(S, newside, oldside, x, y, &u, &v); old_mdisps_bilinear(*out, mdisp->disps, oldside, u, v); - if (S == 1) { (*out)[1]= -(*out)[1]; } + if (S == 1) { (*out)[1] = -(*out)[1]; } else if (S == 2) { SWAP(float, (*out)[0], (*out)[1]); } - else if (S == 3) { (*out)[0]= -(*out)[0]; } - else if (S == 0) { SWAP(float, (*out)[0], (*out)[1]); (*out)[0]= -(*out)[0]; (*out)[1]= -(*out)[1]; }; + else if (S == 3) { (*out)[0] = -(*out)[0]; } + else if (S == 0) { SWAP(float, (*out)[0], (*out)[1]); (*out)[0] = -(*out)[0]; (*out)[1] = -(*out)[1]; }; } } } MEM_freeN(mdisp->disps); - mdisp->totdisp= newtotdisp; - mdisp->level= newlvl; - mdisp->disps= disps; + mdisp->totdisp = newtotdisp; + mdisp->level = newlvl; + mdisp->disps = disps; } void multires_load_old_250(Mesh *me) @@ -1479,10 +1581,10 @@ void multires_load_old_250(Mesh *me) MFace *mf; int i, j, k; - mdisps= CustomData_get_layer(&me->fdata, CD_MDISPS); + mdisps = CustomData_get_layer(&me->fdata, CD_MDISPS); if (mdisps) { - for (i=0; i<me->totface; i++) + for (i = 0; i < me->totface; i++) if (mdisps[i].totdisp) old_mdisps_convert(&me->mface[i], &mdisps[i]); @@ -1491,15 +1593,15 @@ void multires_load_old_250(Mesh *me) k = 0; mf = me->mface; - for (i=0; i<me->totface; i++, mf++) { + for (i = 0; i < me->totface; i++, mf++) { int nvert = mf->v4 ? 4 : 3; int totdisp = mdisps[i].totdisp / nvert; - for (j=0; j < mf->v4 ? 4 : 3; j++, k++) { - mdisps2[k].disps = MEM_callocN(sizeof(float)*3*totdisp, "multires disp in conversion"); + for (j = 0; j < mf->v4 ? 4 : 3; j++, k++) { + mdisps2[k].disps = MEM_callocN(sizeof(float) * 3 * totdisp, "multires disp in conversion"); mdisps2[k].totdisp = totdisp; mdisps2[k].level = mdisps[i].level; - memcpy(mdisps2[k].disps, mdisps[i].disps + totdisp*j, totdisp); + memcpy(mdisps2[k].disps, mdisps[i].disps + totdisp * j, totdisp); } } @@ -1519,7 +1621,7 @@ static void multires_free_level(MultiresLevel *lvl) void multires_free(Multires *mr) { if (mr) { - MultiresLevel* lvl= mr->levels.first; + MultiresLevel *lvl = mr->levels.first; /* Free the first-level data */ if (lvl) { @@ -1533,7 +1635,7 @@ void multires_free(Multires *mr) while (lvl) { multires_free_level(lvl); - lvl= lvl->next; + lvl = lvl->next; } MEM_freeN(mr->verts); @@ -1551,12 +1653,12 @@ static void create_old_vert_face_map(ListBase **map, IndexNode **mem, const Mult IndexNode *node = NULL; (*map) = MEM_callocN(sizeof(ListBase) * totvert, "vert face map"); - (*mem) = MEM_callocN(sizeof(IndexNode) * totface*4, "vert face map mem"); + (*mem) = MEM_callocN(sizeof(IndexNode) * totface * 4, "vert face map mem"); node = *mem; /* Find the users */ for (i = 0; i < totface; ++i) { - for (j = 0; j < (mface[i].v[3]?4:3); ++j, ++node) { + for (j = 0; j < (mface[i].v[3] ? 4 : 3); ++j, ++node) { node->index = i; BLI_addtail(&(*map)[mface[i].v[j]], node); } @@ -1564,13 +1666,13 @@ static void create_old_vert_face_map(ListBase **map, IndexNode **mem, const Mult } static void create_old_vert_edge_map(ListBase **map, IndexNode **mem, const MultiresEdge *medge, - const int totvert, const int totedge) + const int totvert, const int totedge) { int i, j; IndexNode *node = NULL; (*map) = MEM_callocN(sizeof(ListBase) * totvert, "vert edge map"); - (*mem) = MEM_callocN(sizeof(IndexNode) * totedge*2, "vert edge map mem"); + (*mem) = MEM_callocN(sizeof(IndexNode) * totedge * 2, "vert edge map mem"); node = *mem; /* Find the users */ @@ -1587,10 +1689,10 @@ static MultiresFace *find_old_face(ListBase *map, MultiresFace *faces, int v1, i IndexNode *n1; int v[4], i, j; - v[0]= v1; - v[1]= v2; - v[2]= v3; - v[3]= v4; + v[0] = v1; + v[1] = v2; + v[2] = v3; + v[3] = v4; for (n1 = map[v1].first; n1; n1 = n1->next) { int fnd[4] = {0, 0, 0, 0}; @@ -1635,7 +1737,7 @@ static void multires_load_old_edges(ListBase **emap, MultiresLevel *lvl, int *vv } static void multires_load_old_faces(ListBase **fmap, ListBase **emap, MultiresLevel *lvl, int *vvmap, int dst, - int v1, int v2, int v3, int v4, int st2, int st3) + int v1, int v2, int v3, int v4, int st2, int st3) { int fmid; int emid13, emid14, emid23, emid24; @@ -1651,16 +1753,16 @@ static void multires_load_old_faces(ListBase **fmap, ListBase **emap, MultiresLe multires_load_old_faces(fmap + 1, emap + 1, lvl->next, vvmap, dst + st2 * st3 + st3, - fmid, v2, emid23, emid24, st2, st3 / 2); + fmid, v2, emid23, emid24, st2, st3 / 2); multires_load_old_faces(fmap + 1, emap + 1, lvl->next, vvmap, dst - st2 * st3 + st3, - emid14, emid24, fmid, v4, st2, st3 / 2); + emid14, emid24, fmid, v4, st2, st3 / 2); multires_load_old_faces(fmap + 1, emap + 1, lvl->next, vvmap, dst + st2 * st3 - st3, - emid13, emid23, v3, fmid, st2, st3 / 2); + emid13, emid23, v3, fmid, st2, st3 / 2); multires_load_old_faces(fmap + 1, emap + 1, lvl->next, vvmap, dst - st2 * st3 - st3, - v1, fmid, emid13, emid14, st2, st3 / 2); + v1, fmid, emid13, emid14, st2, st3 / 2); if (lvl->next->next) { multires_load_old_edges(emap, lvl->next, vvmap, dst, emid24, fmid, st3); @@ -1673,36 +1775,39 @@ static void multires_load_old_faces(ListBase **fmap, ListBase **emap, MultiresLe static void multires_mvert_to_ss(DerivedMesh *dm, MVert *mvert) { - CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm; + CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; - DMGridData *vd; + CCGElem *vd; + CCGKey key; int index; int totvert, totedge, totface; int gridSize = ccgSubSurf_getGridSize(ss); int edgeSize = ccgSubSurf_getEdgeSize(ss); int i = 0; + dm->getGridKey(dm, &key); + totface = ccgSubSurf_getNumFaces(ss); for (index = 0; index < totface; index++) { CCGFace *f = ccgdm->faceMap[index].face; int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f); - vd= ccgSubSurf_getFaceCenterData(f); - copy_v3_v3(vd->co, mvert[i].co); + vd = ccgSubSurf_getFaceCenterData(f); + copy_v3_v3(CCG_elem_co(&key, vd), mvert[i].co); i++; for (S = 0; S < numVerts; S++) { for (x = 1; x < gridSize - 1; x++, i++) { - vd= ccgSubSurf_getFaceGridEdgeData(ss, f, S, x); - copy_v3_v3(vd->co, mvert[i].co); + vd = ccgSubSurf_getFaceGridEdgeData(ss, f, S, x); + copy_v3_v3(CCG_elem_co(&key, vd), mvert[i].co); } } for (S = 0; S < numVerts; S++) { for (y = 1; y < gridSize - 1; y++) { for (x = 1; x < gridSize - 1; x++, i++) { - vd= ccgSubSurf_getFaceGridData(ss, f, S, x, y); - copy_v3_v3(vd->co, mvert[i].co); + vd = ccgSubSurf_getFaceGridData(ss, f, S, x, y); + copy_v3_v3(CCG_elem_co(&key, vd), mvert[i].co); } } } @@ -1714,8 +1819,8 @@ static void multires_mvert_to_ss(DerivedMesh *dm, MVert *mvert) int x; for (x = 1; x < edgeSize - 1; x++, i++) { - vd= ccgSubSurf_getEdgeData(ss, e, x); - copy_v3_v3(vd->co, mvert[i].co); + vd = ccgSubSurf_getEdgeData(ss, e, x); + copy_v3_v3(CCG_elem_co(&key, vd), mvert[i].co); } } @@ -1723,8 +1828,8 @@ static void multires_mvert_to_ss(DerivedMesh *dm, MVert *mvert) for (index = 0; index < totvert; index++) { CCGVert *v = ccgdm->vertMap[index].vert; - vd= ccgSubSurf_getVertData(ss, v); - copy_v3_v3(vd->co, mvert[i].co); + vd = ccgSubSurf_getVertData(ss, v); + copy_v3_v3(CCG_elem_co(&key, vd), mvert[i].co); i++; } @@ -1735,7 +1840,7 @@ static void multires_mvert_to_ss(DerivedMesh *dm, MVert *mvert) static void multires_load_old_dm(DerivedMesh *dm, Mesh *me, int totlvl) { MultiresLevel *lvl, *lvl1; - Multires *mr= me->mr; + Multires *mr = me->mr; MVert *vsrc, *vdst; unsigned int src, dst; int st = multires_side_tot[totlvl - 1] - 1; @@ -1755,7 +1860,7 @@ static void multires_load_old_dm(DerivedMesh *dm, Mesh *me, int totlvl) /* Load base verts */ for (i = 0; i < lvl1->totvert; ++i) { vvmap[totvert - lvl1->totvert + i] = src; - ++src; + src++; } /* Original edges */ @@ -1801,7 +1906,7 @@ static void multires_load_old_dm(DerivedMesh *dm, Mesh *me, int totlvl) int sides = lvl1->faces[i].v[3] ? 4 : 3; lvl = lvl1->next->next; - ++dst; + dst++; for (j = 3; j <= mr->level_count; ++j) { int base = multires_side_tot[totlvl - j + 1] - 2; @@ -1819,7 +1924,7 @@ static void multires_load_old_dm(DerivedMesh *dm, Mesh *me, int totlvl) for (s = 0; s < sides; ++s) { for (x = 0; x < st2; ++x) { vvmap[dst + crossedgelen * (s + 1) - base - x * skip - 1] = lsrc; - ++lsrc; + lsrc++; } } @@ -1834,10 +1939,10 @@ static void multires_load_old_dm(DerivedMesh *dm, Mesh *me, int totlvl) } /* calculate vert to edge/face maps for each level (except the last) */ - fmap = MEM_callocN(sizeof(ListBase*) * (mr->level_count-1), "multires fmap"); - emap = MEM_callocN(sizeof(ListBase*) * (mr->level_count-1), "multires emap"); - fmem = MEM_callocN(sizeof(IndexNode*) * (mr->level_count-1), "multires fmem"); - emem = MEM_callocN(sizeof(IndexNode*) * (mr->level_count-1), "multires emem"); + fmap = MEM_callocN(sizeof(ListBase *) * (mr->level_count - 1), "multires fmap"); + emap = MEM_callocN(sizeof(ListBase *) * (mr->level_count - 1), "multires emap"); + fmem = MEM_callocN(sizeof(IndexNode *) * (mr->level_count - 1), "multires fmem"); + emem = MEM_callocN(sizeof(IndexNode *) * (mr->level_count - 1), "multires emem"); lvl = lvl1; for (i = 0; i < (unsigned int)mr->level_count - 1; ++i) { create_old_vert_face_map(fmap + i, fmem + i, lvl->faces, lvl->totvert, lvl->totface); @@ -1862,10 +1967,10 @@ static void multires_load_old_dm(DerivedMesh *dm, Mesh *me, int totlvl) int pv = lvl1->faces[j].v[s == 0 ? sides - 1 : s - 1]; multires_load_old_faces(fmap, emap, lvl1->next, vvmap, mid, - vvmap[dst], cv, - find_old_edge(emap[0], lvl1->edges, pv, cv)->mid, - find_old_edge(emap[0], lvl1->edges, cv, nv)->mid, - st2, st4); + vvmap[dst], cv, + find_old_edge(emap[0], lvl1->edges, pv, cv)->mid, + find_old_edge(emap[0], lvl1->edges, cv, nv)->mid, + st2, st4); ldst += (st - 1) * (st - 1); } @@ -1920,10 +2025,10 @@ static void multires_load_old_vcols(Mesh *me) for (i = 0; i < me->totface; ++i) { for (j = 0; j < 4; ++j) { - mcol[i*4 + j].a = colface[i].col[j].a; - mcol[i*4 + j].r = colface[i].col[j].r; - mcol[i*4 + j].g = colface[i].col[j].g; - mcol[i*4 + j].b = colface[i].col[j].b; + mcol[i * 4 + j].a = colface[i].col[j].a; + mcol[i * 4 + j].r = colface[i].col[j].r; + mcol[i * 4 + j].g = colface[i].col[j].g; + mcol[i * 4 + j].b = colface[i].col[j].b; } } } @@ -1982,7 +2087,7 @@ void multires_load_old(Object *ob, Mesh *me) md = ob->modifiers.first; while (md && modifierType_getInfo(md->type)->type == eModifierTypeType_OnlyDeform) md = md->next; - mmd = (MultiresModifierData*)modifier_new(eModifierType_Multires); + mmd = (MultiresModifierData *)modifier_new(eModifierType_Multires); BLI_insertlinkbefore(&ob->modifiers, md, mmd); for (i = 0; i < me->mr->level_count - 1; ++i) @@ -1990,9 +2095,9 @@ void multires_load_old(Object *ob, Mesh *me) mmd->lvl = mmd->totlvl; orig = CDDM_from_mesh(me, NULL); - dm = multires_dm_create_from_derived(mmd, 0, orig, ob, 0); + dm = multires_make_derived_from_derived(orig, mmd, ob, 0); - multires_load_old_dm(dm, me, mmd->totlvl+1); + multires_load_old_dm(dm, me, mmd->totlvl + 1); multires_dm_mark_as_modified(dm, MULTIRES_COORDS_MODIFIED); dm->release(dm); @@ -2011,13 +2116,13 @@ void multires_load_old(Object *ob, Mesh *me) /* Remove the old multires */ multires_free(me->mr); - me->mr= NULL; + me->mr = NULL; } static void multires_sync_levels(Scene *scene, Object *ob, Object *to_ob) { - MultiresModifierData *mmd= get_multires_modifier(scene, ob, 1); - MultiresModifierData *to_mmd= get_multires_modifier(scene, to_ob, 1); + MultiresModifierData *mmd = get_multires_modifier(scene, ob, 1); + MultiresModifierData *to_mmd = get_multires_modifier(scene, to_ob, 1); if (!mmd) { /* object could have MDISP even when there is no multires modifier @@ -2030,84 +2135,86 @@ static void multires_sync_levels(Scene *scene, Object *ob, Object *to_ob) if (!mmd || !to_mmd) return; - if (mmd->totlvl>to_mmd->totlvl) multires_del_higher(mmd, ob, to_mmd->totlvl); + if (mmd->totlvl > to_mmd->totlvl) multires_del_higher(mmd, ob, to_mmd->totlvl); else multires_subdivide(mmd, ob, to_mmd->totlvl, 0, mmd->simple); } static void multires_apply_smat(Scene *scene, Object *ob, float smat[3][3]) { - DerivedMesh *dm= NULL, *cddm= NULL, *subdm= NULL; - DMGridData **gridData, **subGridData; - Mesh *me= (Mesh*)ob->data; - MPoly *mpoly= me->mpoly; + DerivedMesh *dm = NULL, *cddm = NULL, *subdm = NULL; + CCGElem **gridData, **subGridData; + CCGKey key; + Mesh *me = (Mesh *)ob->data; + MPoly *mpoly = me->mpoly; /* MLoop *mloop = me->mloop; */ /* UNUSED */ MDisps *mdisps; int *gridOffset; int i, /*numGrids, */ gridSize, dGridSize, dSkip, totvert; float (*vertCos)[3] = NULL; - MultiresModifierData *mmd= get_multires_modifier(scene, ob, 1); + MultiresModifierData *mmd = get_multires_modifier(scene, ob, 1); MultiresModifierData high_mmd; CustomData_external_read(&me->ldata, &me->id, CD_MASK_MDISPS, me->totloop); - mdisps= CustomData_get_layer(&me->ldata, CD_MDISPS); + mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS); if (!mdisps || !mmd || !mmd->totlvl) return; /* we need derived mesh created from highest resolution */ - high_mmd= *mmd; - high_mmd.lvl= high_mmd.totlvl; + high_mmd = *mmd; + high_mmd.lvl = high_mmd.totlvl; /* unscaled multires with applied displacement */ - subdm= get_multires_dm(scene, &high_mmd, ob); + subdm = get_multires_dm(scene, &high_mmd, ob); /* prepare scaled CDDM to create ccgDN */ - cddm= mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); + cddm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); - totvert= cddm->getNumVerts(cddm); - vertCos= MEM_mallocN(sizeof(*vertCos) * totvert, "multiresScale vertCos"); + totvert = cddm->getNumVerts(cddm); + vertCos = MEM_mallocN(sizeof(*vertCos) * totvert, "multiresScale vertCos"); cddm->getVertCos(cddm, vertCos); - for (i=0; i<totvert; i++) + for (i = 0; i < totvert; i++) mul_m3_v3(smat, vertCos[i]); CDDM_apply_vert_coords(cddm, vertCos); MEM_freeN(vertCos); /* scaled ccgDM for tangent space of object with applied scale */ - dm= subsurf_dm_create_local(ob, cddm, high_mmd.totlvl, high_mmd.simple, 0, mmd->flags & eMultiresModifierFlag_PlainUv); + dm = subsurf_dm_create_local(ob, cddm, high_mmd.totlvl, high_mmd.simple, 0, mmd->flags & eMultiresModifierFlag_PlainUv, 0); cddm->release(cddm); - /*numGrids= dm->getNumGrids(dm);*/ /*UNUSED*/ - gridSize= dm->getGridSize(dm); - gridData= dm->getGridData(dm); - gridOffset= dm->getGridOffset(dm); - subGridData= subdm->getGridData(subdm); + /*numGrids = dm->getNumGrids(dm);*/ /*UNUSED*/ + gridSize = dm->getGridSize(dm); + gridData = dm->getGridData(dm); + gridOffset = dm->getGridOffset(dm); + dm->getGridKey(dm, &key); + subGridData = subdm->getGridData(subdm); - dGridSize= multires_side_tot[high_mmd.totlvl]; - dSkip= (dGridSize-1)/(gridSize-1); + dGridSize = multires_side_tot[high_mmd.totlvl]; + dSkip = (dGridSize - 1) / (gridSize - 1); #pragma omp parallel for private(i) if (me->totface*gridSize*gridSize*4 >= CCG_OMP_LIMIT) for (i = 0; i < me->totpoly; ++i) { - const int numVerts= mpoly[i].totloop; - MDisps *mdisp= &mdisps[mpoly[i].loopstart]; + const int numVerts = mpoly[i].totloop; + MDisps *mdisp = &mdisps[mpoly[i].loopstart]; int S, x, y, gIndex = gridOffset[i]; for (S = 0; S < numVerts; ++S, ++gIndex, mdisp++) { - DMGridData *grid= gridData[gIndex]; - DMGridData *subgrid= subGridData[gIndex]; - float (*dispgrid)[3]= mdisp->disps; + CCGElem *grid = gridData[gIndex]; + CCGElem *subgrid = subGridData[gIndex]; + float (*dispgrid)[3] = mdisp->disps; for (y = 0; y < gridSize; y++) { for (x = 0; x < gridSize; x++) { - float *co= grid[x + y*gridSize].co; - float *sco= subgrid[x + y*gridSize].co; - float *no= grid[x + y*gridSize].no; - float *data= dispgrid[dGridSize*y*dSkip + x*dSkip]; + float *co = CCG_grid_elem_co(&key, grid, x, y); + float *sco = CCG_grid_elem_co(&key, subgrid, x, y); + float *no = CCG_grid_elem_no(&key, grid, x, y); + float *data = dispgrid[dGridSize * y * dSkip + x * dSkip]; float mat[3][3], tx[3], ty[3], disp[3]; /* construct tangent space matrix */ - grid_tangent(gridSize, gIndex, x, y, 0, gridData, tx); + grid_tangent(&key, x, y, 0, gridData[gIndex], tx); normalize_v3(tx); - grid_tangent(gridSize, gIndex, x, y, 1, gridData, ty); + grid_tangent(&key, x, y, 1, gridData[gIndex], ty); normalize_v3(ty); column_vectors_to_mat3(mat, tx, ty, no); @@ -2130,11 +2237,11 @@ static void multires_apply_smat(Scene *scene, Object *ob, float smat[3][3]) int multires_mdisp_corners(MDisps *s) { - int lvl= 13; + int lvl = 13; while (lvl > 0) { - int side = (1 << (lvl-1)) + 1; - if ((s->totdisp % (side*side)) == 0) return s->totdisp / (side*side); + int side = (1 << (lvl - 1)) + 1; + if ((s->totdisp % (side * side)) == 0) return s->totdisp / (side * side); lvl--; } @@ -2146,7 +2253,7 @@ void multiresModifier_scale_disp(Scene *scene, Object *ob) float smat[3][3]; /* object's scale matrix */ - object_scale_to_mat3(ob, smat); + BKE_object_scale_to_mat3(ob, smat); multires_apply_smat(scene, ob, smat); } @@ -2157,9 +2264,9 @@ void multiresModifier_prepare_join(Scene *scene, Object *ob, Object *to_ob) multires_sync_levels(scene, ob, to_ob); /* construct scale matrix for displacement */ - object_scale_to_mat3(to_ob, tmat); + BKE_object_scale_to_mat3(to_ob, tmat); invert_m3(tmat); - object_scale_to_mat3(ob, smat); + BKE_object_scale_to_mat3(ob, smat); mul_m3_m3m3(mat, smat, tmat); multires_apply_smat(scene, ob, mat); @@ -2204,14 +2311,14 @@ void multires_topology_changed(Mesh *me) /* Find per-corner coordinate with given per-face UV coord */ int mdisp_rot_face_to_crn(const int corners, const int face_side, const float u, const float v, float *x, float *y) { - const float offset = face_side*0.5f - 0.5f; + const float offset = face_side * 0.5f - 0.5f; int S = 0; if (corners == 4) { if (u <= offset && v <= offset) S = 0; else if (u > offset && v <= offset) S = 1; else if (u > offset && v > offset) S = 2; - else if (u <= offset && v >= offset) S = 3; + else if (u <= offset && v >= offset) S = 3; if (S == 0) { *y = offset - u; @@ -2226,7 +2333,7 @@ int mdisp_rot_face_to_crn(const int corners, const int face_side, const float u, *x = v - offset; } else if (S == 3) { - *x= offset - u; + *x = offset - u; *y = v - offset; } } @@ -2235,15 +2342,15 @@ int mdisp_rot_face_to_crn(const int corners, const int face_side, const float u, float w = (face_side - 1) - u - v; float W1, W2; - if (u >= v && u >= w) {S = 0; W1= w; W2= v;} - else if (v >= u && v >= w) {S = 1; W1 = u; W2 = w;} - else {S = 2; W1 = v; W2 = u;} + if (u >= v && u >= w) {S = 0; W1 = w; W2 = v; } + else if (v >= u && v >= w) {S = 1; W1 = u; W2 = w; } + else {S = 2; W1 = v; W2 = u; } - W1 /= (face_side-1); - W2 /= (face_side-1); + W1 /= (face_side - 1); + W2 /= (face_side - 1); - *x = (1-(2*W1)/(1-W2)) * grid_size; - *y = (1-(2*W2)/(1-W1)) * grid_size; + *x = (1 - (2 * W1) / (1 - W2)) * grid_size; + *y = (1 - (2 * W2) / (1 - W1)) * grid_size; } return S; diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index b2a85ad0629..a25cd0d3b38 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -339,15 +339,15 @@ bNode *nodeAddNode(bNodeTree *ntree, struct bNodeTemplate *ntemp) node_add_sockets_from_type(ntree, node, ntype); - if (ntype->initfunc!=NULL) - ntype->initfunc(ntree, node, ntemp); - /* initialize the node name with the node label */ BLI_strncpy(node->name, nodeLabel(node), NODE_MAXSTR); nodeUniqueName(ntree, node); BLI_addtail(&ntree->nodes, node); + if (ntype->initfunc!=NULL) + ntype->initfunc(ntree, node, ntemp); + ntree->update |= NTREE_UPDATE_NODES; return node; @@ -643,7 +643,7 @@ bNodeTree *ntreeAddTree(const char *name, int type, int nodetype) BLI_strncpy(ntree->id.name+2, name, sizeof(ntree->id.name)); } else - ntree= alloc_libblock(&G.main->nodetree, ID_NT, name); + ntree= BKE_libblock_alloc(&G.main->nodetree, ID_NT, name); ntree->type= type; ntree->nodetype = nodetype; @@ -675,11 +675,11 @@ bNodeTree *ntreeCopyTree(bNodeTree *ntree) for (newtree=G.main->nodetree.first; newtree; newtree= newtree->id.next) if (newtree==ntree) break; if (newtree) { - newtree= copy_libblock(&ntree->id); + newtree= BKE_libblock_copy(&ntree->id); } else { newtree= MEM_dupallocN(ntree); - copy_libblock_data(&newtree->id, &ntree->id, TRUE); /* copy animdata and ID props */ + BKE_libblock_copy_data(&newtree->id, &ntree->id, TRUE); /* copy animdata and ID props */ } id_us_plus((ID *)newtree->gpd); @@ -931,7 +931,7 @@ void nodeFreeNode(bNodeTree *ntree, bNode *node) ntree->update |= NTREE_UPDATE_NODES; } -/* do not free ntree itself here, free_libblock calls this function too */ +/* do not free ntree itself here, BKE_libblock_free calls this function too */ void ntreeFreeTree(bNodeTree *ntree) { bNode *node, *next; @@ -1969,6 +1969,7 @@ static void registerShaderNodes(bNodeTreeType *ttype) register_node_type_sh_attribute(ttype); register_node_type_sh_geometry(ttype); register_node_type_sh_light_path(ttype); + register_node_type_sh_light_falloff(ttype); register_node_type_sh_fresnel(ttype); register_node_type_sh_layer_weight(ttype); register_node_type_sh_tex_coord(ttype); @@ -2093,7 +2094,7 @@ void free_nodesystem(void) free_typeinfos(&ntreeGetType(NTREE_TEXTURE)->node_types); } -/* called from unlink_scene, when deleting a scene goes over all scenes +/* called from BKE_scene_unlink, when deleting a scene goes over all scenes * other than the input, checks if they have render layer nodes referencing * the to-be-deleted scene, and resets them to NULL. */ diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index bf2e5b833b6..7bf0eadf088 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -117,50 +117,30 @@ #include "FRS_freestyle.h" /* Local function protos */ -static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[][4], float slowmat[][4], int simul); +static void solve_parenting(Scene *scene, Object *ob, Object *par, float obmat[][4], float slowmat[][4], int simul); -float originmat[3][3]; /* after where_is_object(), can be used in other functions (bad!) */ +float originmat[3][3]; /* after BKE_object_where_is_calc(), can be used in other functions (bad!) */ -void clear_workob(Object *workob) +void BKE_object_workob_clear(Object *workob) { memset(workob, 0, sizeof(Object)); - workob->size[0]= workob->size[1]= workob->size[2]= 1.0f; - workob->dscale[0]= workob->dscale[1]= workob->dscale[2]= 1.0f; - workob->rotmode= ROT_MODE_EUL; + workob->size[0] = workob->size[1] = workob->size[2] = 1.0f; + workob->dscale[0] = workob->dscale[1] = workob->dscale[2] = 1.0f; + workob->rotmode = ROT_MODE_EUL; } -void copy_baseflags(struct Scene *scene) +void BKE_object_update_base_layer(struct Scene *scene, Object *ob) { - Base *base= scene->base.first; - - while (base) { - base->object->flag= base->flag; - base= base->next; - } -} - -void copy_objectflags(struct Scene *scene) -{ - Base *base= scene->base.first; - - while (base) { - base->flag= base->object->flag; - base= base->next; - } -} - -void update_base_layer(struct Scene *scene, Object *ob) -{ - Base *base= scene->base.first; + Base *base = scene->base.first; while (base) { - if (base->object == ob) base->lay= ob->lay; - base= base->next; + if (base->object == ob) base->lay = ob->lay; + base = base->next; } } -void object_free_particlesystems(Object *ob) +void BKE_object_free_particlesystems(Object *ob) { while (ob->particlesystem.first) { ParticleSystem *psys = ob->particlesystem.first; @@ -171,23 +151,23 @@ void object_free_particlesystems(Object *ob) } } -void object_free_softbody(Object *ob) +void BKE_object_free_softbody(Object *ob) { if (ob->soft) { sbFree(ob->soft); - ob->soft= NULL; + ob->soft = NULL; } } -void object_free_bulletsoftbody(Object *ob) +void BKE_object_free_bulletsoftbody(Object *ob) { if (ob->bsoft) { bsbFree(ob->bsoft); - ob->bsoft= NULL; + ob->bsoft = NULL; } } -void object_free_modifiers(Object *ob) +void BKE_object_free_modifiers(Object *ob) { while (ob->modifiers.first) { ModifierData *md = ob->modifiers.first; @@ -198,31 +178,31 @@ void object_free_modifiers(Object *ob) } /* particle modifiers were freed, so free the particlesystems as well */ - object_free_particlesystems(ob); + BKE_object_free_particlesystems(ob); /* same for softbody */ - object_free_softbody(ob); + BKE_object_free_softbody(ob); } -int object_support_modifier_type(Object *ob, int modifier_type) +int BKE_object_support_modifier_type_check(Object *ob, int modifier_type) { ModifierTypeInfo *mti; mti = modifierType_getInfo(modifier_type); if (!((mti->flags & eModifierTypeFlag_AcceptsCVs) || - (ob->type==OB_MESH && (mti->flags & eModifierTypeFlag_AcceptsMesh)))) + (ob->type == OB_MESH && (mti->flags & eModifierTypeFlag_AcceptsMesh)))) { - return FALSE; + return FALSE; } return TRUE; } -void object_link_modifiers(struct Object *ob, struct Object *from) +void BKE_object_link_modifiers(struct Object *ob, struct Object *from) { ModifierData *md; - object_free_modifiers(ob); + BKE_object_free_modifiers(ob); if (!ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE)) { /* only objects listed above can have modifiers and linking them to objects @@ -230,12 +210,12 @@ void object_link_modifiers(struct Object *ob, struct Object *from) return; } - for (md=from->modifiers.first; md; md=md->next) { + for (md = from->modifiers.first; md; md = md->next) { ModifierData *nmd = NULL; if (ELEM4(md->type, eModifierType_Hook, eModifierType_Softbody, eModifierType_ParticleInstance, eModifierType_Collision)) continue; - if (!object_support_modifier_type(ob, md->type)) + if (!BKE_object_support_modifier_type_check(ob, md->type)) continue; nmd = modifier_new(md->type); @@ -243,28 +223,28 @@ void object_link_modifiers(struct Object *ob, struct Object *from) BLI_addtail(&ob->modifiers, nmd); } - copy_object_particlesystems(ob, from); - copy_object_softbody(ob, from); + BKE_object_copy_particlesystems(ob, from); + BKE_object_copy_softbody(ob, from); // TODO: smoke?, cloth? } /* here we will collect all local displist stuff */ /* also (ab)used in depsgraph */ -void object_free_display(Object *ob) +void BKE_object_free_display(Object *ob) { if (ob->derivedDeform) { ob->derivedDeform->needsFree = 1; ob->derivedDeform->release(ob->derivedDeform); - ob->derivedDeform= NULL; + ob->derivedDeform = NULL; } if (ob->derivedFinal) { ob->derivedFinal->needsFree = 1; ob->derivedFinal->release(ob->derivedFinal); - ob->derivedFinal= NULL; + ob->derivedFinal = NULL; } - freedisplist(&ob->disp); + BKE_displist_free(&ob->disp); } void free_sculptsession_deformMats(SculptSession *ss) @@ -282,12 +262,12 @@ void free_sculptsession(Object *ob) { if (ob && ob->sculpt) { SculptSession *ss = ob->sculpt; - DerivedMesh *dm= ob->derivedFinal; + DerivedMesh *dm = ob->derivedFinal; if (ss->pbvh) BLI_pbvh_free(ss->pbvh); if (dm && dm->getPBVH) - dm->getPBVH(NULL, dm); /* signal to clear */ + dm->getPBVH(NULL, dm); /* signal to clear */ if (ss->texcache) MEM_freeN(ss->texcache); @@ -310,44 +290,44 @@ void free_sculptsession(Object *ob) /* do not free object itself */ -void free_object(Object *ob) +void BKE_object_free(Object *ob) { int a; - object_free_display(ob); + BKE_object_free_display(ob); /* disconnect specific data */ if (ob->data) { - ID *id= ob->data; + ID *id = ob->data; id->us--; - if (id->us==0) { - if (ob->type==OB_MESH) unlink_mesh(ob->data); - else if (ob->type==OB_CURVE) BKE_curve_unlink(ob->data); - else if (ob->type==OB_MBALL) BKE_metaball_unlink(ob->data); + if (id->us == 0) { + if (ob->type == OB_MESH) BKE_mesh_unlink(ob->data); + else if (ob->type == OB_CURVE) BKE_curve_unlink(ob->data); + else if (ob->type == OB_MBALL) BKE_mball_unlink(ob->data); } - ob->data= NULL; + ob->data = NULL; } - for (a=0; a<ob->totcol; a++) { + for (a = 0; a < ob->totcol; a++) { if (ob->mat[a]) ob->mat[a]->id.us--; } if (ob->mat) MEM_freeN(ob->mat); if (ob->matbits) MEM_freeN(ob->matbits); - ob->mat= NULL; - ob->matbits= NULL; + ob->mat = NULL; + ob->matbits = NULL; if (ob->bb) MEM_freeN(ob->bb); - ob->bb= NULL; + ob->bb = NULL; if (ob->adt) BKE_free_animdata((ID *)ob); if (ob->poselib) ob->poselib->id.us--; if (ob->gpd) ((ID *)ob->gpd)->us--; if (ob->defbase.first) BLI_freelistN(&ob->defbase); if (ob->pose) - free_pose(ob->pose); + BKE_pose_free(ob->pose); if (ob->mpath) animviz_free_motionpath(ob->mpath); free_properties(&ob->prop); - object_free_modifiers(ob); + BKE_object_free_modifiers(ob); free_sensors(&ob->sensors); free_controllers(&ob->controllers); @@ -370,15 +350,15 @@ static void unlink_object__unlinkModifierLinks(void *userData, Object *ob, Objec { Object *unlinkOb = userData; - if (*obpoin==unlinkOb) { + if (*obpoin == unlinkOb) { *obpoin = NULL; - ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; // XXX: should this just be OB_RECALC_DATA? + ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; // XXX: should this just be OB_RECALC_DATA? } } -void unlink_object(Object *ob) +void BKE_object_unlink(Object *ob) { - Main *bmain= G.main; + Main *bmain = G.main; Object *obt; Material *mat; World *wrld; @@ -400,55 +380,55 @@ void unlink_object(Object *ob) /* check all objects: parents en bevels and fields, also from libraries */ // FIXME: need to check all animation blocks (drivers) - obt= bmain->object.first; + obt = bmain->object.first; while (obt) { - if (obt->proxy==ob) - obt->proxy= NULL; - if (obt->proxy_from==ob) { - obt->proxy_from= NULL; + if (obt->proxy == ob) + obt->proxy = NULL; + if (obt->proxy_from == ob) { + obt->proxy_from = NULL; obt->recalc |= OB_RECALC_OB; } - if (obt->proxy_group==ob) - obt->proxy_group= NULL; + if (obt->proxy_group == ob) + obt->proxy_group = NULL; - if (obt->parent==ob) { - obt->parent= NULL; - obt->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; + if (obt->parent == ob) { + obt->parent = NULL; + obt->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; } modifiers_foreachObjectLink(obt, unlink_object__unlinkModifierLinks, ob); if (ELEM(obt->type, OB_CURVE, OB_FONT)) { - cu= obt->data; + cu = obt->data; - if (cu->bevobj==ob) { - cu->bevobj= NULL; - obt->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; + if (cu->bevobj == ob) { + cu->bevobj = NULL; + obt->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; } - if (cu->taperobj==ob) { - cu->taperobj= NULL; - obt->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; + if (cu->taperobj == ob) { + cu->taperobj = NULL; + obt->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; } - if (cu->textoncurve==ob) { - cu->textoncurve= NULL; - obt->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; + if (cu->textoncurve == ob) { + cu->textoncurve = NULL; + obt->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; } } - else if (obt->type==OB_ARMATURE && obt->pose) { + else if (obt->type == OB_ARMATURE && obt->pose) { bPoseChannel *pchan; - for (pchan= obt->pose->chanbase.first; pchan; pchan= pchan->next) { - for (con = pchan->constraints.first; con; con=con->next) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + for (pchan = obt->pose->chanbase.first; pchan; pchan = pchan->next) { + for (con = pchan->constraints.first; con; con = con->next) { + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); ListBase targets = {NULL, NULL}; bConstraintTarget *ct; if (cti && cti->get_constraint_targets) { cti->get_constraint_targets(con, &targets); - for (ct= targets.first; ct; ct= ct->next) { + for (ct = targets.first; ct; ct = ct->next) { if (ct->tar == ob) { ct->tar = NULL; - ct->subtarget[0]= '\0'; + ct->subtarget[0] = '\0'; obt->recalc |= OB_RECALC_DATA; } } @@ -457,29 +437,29 @@ void unlink_object(Object *ob) cti->flush_constraint_targets(con, &targets, 0); } } - if (pchan->custom==ob) - pchan->custom= NULL; + if (pchan->custom == ob) + pchan->custom = NULL; } } else if (ELEM(OB_MBALL, ob->type, obt->type)) { - if (BKE_metaball_is_basis_for (obt, ob)) - obt->recalc|= OB_RECALC_DATA; + if (BKE_mball_is_basis_for(obt, ob)) + obt->recalc |= OB_RECALC_DATA; } sca_remove_ob_poin(obt, ob); - for (con = obt->constraints.first; con; con=con->next) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + for (con = obt->constraints.first; con; con = con->next) { + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); ListBase targets = {NULL, NULL}; bConstraintTarget *ct; if (cti && cti->get_constraint_targets) { cti->get_constraint_targets(con, &targets); - for (ct= targets.first; ct; ct= ct->next) { + for (ct = targets.first; ct; ct = ct->next) { if (ct->tar == ob) { ct->tar = NULL; - ct->subtarget[0]= '\0'; + ct->subtarget[0] = '\0'; obt->recalc |= OB_RECALC_DATA; } } @@ -495,73 +475,73 @@ void unlink_object(Object *ob) obt->recalc |= OB_RECALC_DATA; /* cloth */ - for (md=obt->modifiers.first; md; md=md->next) + for (md = obt->modifiers.first; md; md = md->next) if (md->type == eModifierType_Cloth) obt->recalc |= OB_RECALC_DATA; } /* strips */ #if 0 // XXX old animation system - for (strip= obt->nlastrips.first; strip; strip= strip->next) { - if (strip->object==ob) - strip->object= NULL; + for (strip = obt->nlastrips.first; strip; strip = strip->next) { + if (strip->object == ob) + strip->object = NULL; if (strip->modifiers.first) { bActionModifier *amod; - for (amod= strip->modifiers.first; amod; amod= amod->next) - if (amod->ob==ob) - amod->ob= NULL; + for (amod = strip->modifiers.first; amod; amod = amod->next) + if (amod->ob == ob) + amod->ob = NULL; } } #endif // XXX old animation system /* particle systems */ if (obt->particlesystem.first) { - ParticleSystem *tpsys= obt->particlesystem.first; - for (; tpsys; tpsys=tpsys->next) { + ParticleSystem *tpsys = obt->particlesystem.first; + for (; tpsys; tpsys = tpsys->next) { BoidState *state = NULL; BoidRule *rule = NULL; ParticleTarget *pt = tpsys->targets.first; - for (; pt; pt=pt->next) { - if (pt->ob==ob) { + for (; pt; pt = pt->next) { + if (pt->ob == ob) { pt->ob = NULL; obt->recalc |= OB_RECALC_DATA; break; } } - if (tpsys->target_ob==ob) { - tpsys->target_ob= NULL; + if (tpsys->target_ob == ob) { + tpsys->target_ob = NULL; obt->recalc |= OB_RECALC_DATA; } - if (tpsys->part->dup_ob==ob) - tpsys->part->dup_ob= NULL; + if (tpsys->part->dup_ob == ob) + tpsys->part->dup_ob = NULL; - if (tpsys->part->phystype==PART_PHYS_BOIDS) { + if (tpsys->part->phystype == PART_PHYS_BOIDS) { ParticleData *pa; BoidParticle *bpa; int p; - for (p=0, pa=tpsys->particles; p<tpsys->totpart; p++, pa++) { + for (p = 0, pa = tpsys->particles; p < tpsys->totpart; p++, pa++) { bpa = pa->boid; if (bpa->ground == ob) bpa->ground = NULL; } } if (tpsys->part->boids) { - for (state = tpsys->part->boids->states.first; state; state=state->next) { - for (rule = state->rules.first; rule; rule=rule->next) { - if (rule->type==eBoidRuleType_Avoid) { - BoidRuleGoalAvoid *gabr = (BoidRuleGoalAvoid*)rule; - if (gabr->ob==ob) - gabr->ob= NULL; + for (state = tpsys->part->boids->states.first; state; state = state->next) { + for (rule = state->rules.first; rule; rule = rule->next) { + if (rule->type == eBoidRuleType_Avoid) { + BoidRuleGoalAvoid *gabr = (BoidRuleGoalAvoid *)rule; + if (gabr->ob == ob) + gabr->ob = NULL; } - else if (rule->type==eBoidRuleType_FollowLeader) { - BoidRuleFollowLeader *flbr = (BoidRuleFollowLeader*)rule; - if (flbr->ob==ob) - flbr->ob= NULL; + else if (rule->type == eBoidRuleType_FollowLeader) { + BoidRuleFollowLeader *flbr = (BoidRuleFollowLeader *)rule; + if (flbr->ob == ob) + flbr->ob = NULL; } } } @@ -571,64 +551,64 @@ void unlink_object(Object *ob) obt->recalc |= OB_RECALC_DATA; } - obt= obt->id.next; + obt = obt->id.next; } /* materials */ - mat= bmain->mat.first; + mat = bmain->mat.first; while (mat) { - for (a=0; a<MAX_MTEX; a++) { - if (mat->mtex[a] && ob==mat->mtex[a]->object) { + for (a = 0; a < MAX_MTEX; a++) { + if (mat->mtex[a] && ob == mat->mtex[a]->object) { /* actually, test for lib here... to do */ - mat->mtex[a]->object= NULL; + mat->mtex[a]->object = NULL; } } - mat= mat->id.next; + mat = mat->id.next; } /* textures */ - for (tex= bmain->tex.first; tex; tex= tex->id.next) { - if (tex->env && (ob==tex->env->object)) tex->env->object= NULL; - if (tex->pd && (ob==tex->pd->object)) tex->pd->object= NULL; - if (tex->vd && (ob==tex->vd->object)) tex->vd->object= NULL; + for (tex = bmain->tex.first; tex; tex = tex->id.next) { + if (tex->env && (ob == tex->env->object)) tex->env->object = NULL; + if (tex->pd && (ob == tex->pd->object)) tex->pd->object = NULL; + if (tex->vd && (ob == tex->vd->object)) tex->vd->object = NULL; } /* worlds */ - wrld= bmain->world.first; + wrld = bmain->world.first; while (wrld) { - if (wrld->id.lib==NULL) { - for (a=0; a<MAX_MTEX; a++) { - if (wrld->mtex[a] && ob==wrld->mtex[a]->object) - wrld->mtex[a]->object= NULL; + if (wrld->id.lib == NULL) { + for (a = 0; a < MAX_MTEX; a++) { + if (wrld->mtex[a] && ob == wrld->mtex[a]->object) + wrld->mtex[a]->object = NULL; } } - wrld= wrld->id.next; + wrld = wrld->id.next; } /* scenes */ - sce= bmain->scene.first; + sce = bmain->scene.first; while (sce) { - if (sce->id.lib==NULL) { - if (sce->camera==ob) sce->camera= NULL; - if (sce->toolsettings->skgen_template==ob) sce->toolsettings->skgen_template = NULL; - if (sce->toolsettings->particle.object==ob) sce->toolsettings->particle.object= NULL; + if (sce->id.lib == NULL) { + if (sce->camera == ob) sce->camera = NULL; + if (sce->toolsettings->skgen_template == ob) sce->toolsettings->skgen_template = NULL; + if (sce->toolsettings->particle.object == ob) sce->toolsettings->particle.object = NULL; #ifdef DURIAN_CAMERA_SWITCH { TimeMarker *m; - for (m= sce->markers.first; m; m= m->next) { - if (m->camera==ob) - m->camera= NULL; + for (m = sce->markers.first; m; m = m->next) { + if (m->camera == ob) + m->camera = NULL; } } #endif if (sce->ed) { Sequence *seq; - SEQ_BEGIN (sce->ed, seq) + SEQ_BEGIN(sce->ed, seq) { if (seq->scene_camera == ob) { seq->scene_camera = NULL; @@ -646,19 +626,19 @@ void unlink_object(Object *ob) } } - sce= sce->id.next; + sce = sce->id.next; } /* screens */ - sc= bmain->screen.first; + sc = bmain->screen.first; while (sc) { - ScrArea *sa= sc->areabase.first; + ScrArea *sa = sc->areabase.first; while (sa) { SpaceLink *sl; - for (sl= sa->spacedata.first; sl; sl= sl->next) { - if (sl->spacetype==SPACE_VIEW3D) { - View3D *v3d= (View3D*) sl; + for (sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *) sl; /* found doesn't need to be set here */ if (v3d->ob_centre == ob) { @@ -670,156 +650,156 @@ void unlink_object(Object *ob) v3d->localvd->ob_centre_bone[0] = '\0'; } - found= 0; - if (v3d->camera==ob) { - v3d->camera= NULL; - found= 1; + found = 0; + if (v3d->camera == ob) { + v3d->camera = NULL; + found = 1; } - if (v3d->localvd && v3d->localvd->camera==ob ) { - v3d->localvd->camera= NULL; + if (v3d->localvd && v3d->localvd->camera == ob) { + v3d->localvd->camera = NULL; found += 2; } if (found) { if (sa->spacetype == SPACE_VIEW3D) { - for (ar= sa->regionbase.first; ar; ar= ar->next) { - if (ar->regiontype==RGN_TYPE_WINDOW) { - rv3d= (RegionView3D *)ar->regiondata; + for (ar = sa->regionbase.first; ar; ar = ar->next) { + if (ar->regiontype == RGN_TYPE_WINDOW) { + rv3d = (RegionView3D *)ar->regiondata; if (found == 1 || found == 3) { if (rv3d->persp == RV3D_CAMOB) - rv3d->persp= RV3D_PERSP; + rv3d->persp = RV3D_PERSP; } if (found == 2 || found == 3) { if (rv3d->localvd && rv3d->localvd->persp == RV3D_CAMOB) - rv3d->localvd->persp= RV3D_PERSP; + rv3d->localvd->persp = RV3D_PERSP; } } } } } } - else if (sl->spacetype==SPACE_OUTLINER) { - SpaceOops *so= (SpaceOops *)sl; + else if (sl->spacetype == SPACE_OUTLINER) { + SpaceOops *so = (SpaceOops *)sl; if (so->treestore) { - TreeStoreElem *tselem= so->treestore->data; + TreeStoreElem *tselem = so->treestore->data; int a; - for (a=0; a<so->treestore->usedelem; a++, tselem++) { - if (tselem->id==(ID *)ob) tselem->id= NULL; + for (a = 0; a < so->treestore->usedelem; a++, tselem++) { + if (tselem->id == (ID *)ob) tselem->id = NULL; } } } - else if (sl->spacetype==SPACE_BUTS) { - SpaceButs *sbuts= (SpaceButs *)sl; + else if (sl->spacetype == SPACE_BUTS) { + SpaceButs *sbuts = (SpaceButs *)sl; - if (sbuts->pinid==(ID *)ob) { - sbuts->flag&= ~SB_PIN_CONTEXT; - sbuts->pinid= NULL; + if (sbuts->pinid == (ID *)ob) { + sbuts->flag &= ~SB_PIN_CONTEXT; + sbuts->pinid = NULL; } } } - sa= sa->next; + sa = sa->next; } - sc= sc->id.next; + sc = sc->id.next; } /* groups */ - group= bmain->group.first; + group = bmain->group.first; while (group) { rem_from_group(group, ob, NULL, NULL); - group= group->id.next; + group = group->id.next; } /* cameras */ - camera= bmain->camera.first; + camera = bmain->camera.first; while (camera) { - if (camera->dof_ob==ob) { + if (camera->dof_ob == ob) { camera->dof_ob = NULL; } - camera= camera->id.next; + camera = camera->id.next; } } -int exist_object(Object *obtest) +int BKE_object_exists_check(Object *obtest) { Object *ob; - if (obtest==NULL) return 0; + if (obtest == NULL) return 0; - ob= G.main->object.first; + ob = G.main->object.first; while (ob) { - if (ob==obtest) return 1; - ob= ob->id.next; + if (ob == obtest) return 1; + ob = ob->id.next; } return 0; } /* *************************************************** */ -void *add_obdata_from_type(int type) +void *BKE_object_obdata_add_from_type(int type) { switch (type) { - case OB_MESH: return add_mesh("Mesh"); - case OB_CURVE: return BKE_curve_add("Curve", OB_CURVE); - case OB_SURF: return BKE_curve_add("Surf", OB_SURF); - case OB_FONT: return BKE_curve_add("Text", OB_FONT); - case OB_MBALL: return BKE_metaball_add("Meta"); - case OB_CAMERA: return BKE_camera_add("Camera"); - case OB_LAMP: return add_lamp("Lamp"); - case OB_LATTICE: return add_lattice("Lattice"); - case OB_ARMATURE: return add_armature("Armature"); - case OB_SPEAKER: return add_speaker("Speaker"); - case OB_EMPTY: return NULL; - default: - printf("add_obdata_from_type: Internal error, bad type: %d\n", type); - return NULL; + case OB_MESH: return BKE_mesh_add("Mesh"); + case OB_CURVE: return BKE_curve_add("Curve", OB_CURVE); + case OB_SURF: return BKE_curve_add("Surf", OB_SURF); + case OB_FONT: return BKE_curve_add("Text", OB_FONT); + case OB_MBALL: return BKE_mball_add("Meta"); + case OB_CAMERA: return BKE_camera_add("Camera"); + case OB_LAMP: return BKE_lamp_add("Lamp"); + case OB_LATTICE: return BKE_lattice_add("Lattice"); + case OB_ARMATURE: return BKE_armature_add("Armature"); + case OB_SPEAKER: return BKE_speaker_add("Speaker"); + case OB_EMPTY: return NULL; + default: + printf("BKE_object_obdata_add_from_type: Internal error, bad type: %d\n", type); + return NULL; } } static const char *get_obdata_defname(int type) { switch (type) { - case OB_MESH: return "Mesh"; - case OB_CURVE: return "Curve"; - case OB_SURF: return "Surf"; - case OB_FONT: return "Text"; - case OB_MBALL: return "Mball"; - case OB_CAMERA: return "Camera"; - case OB_LAMP: return "Lamp"; - case OB_LATTICE: return "Lattice"; - case OB_ARMATURE: return "Armature"; - case OB_SPEAKER: return "Speaker"; - case OB_EMPTY: return "Empty"; - default: - printf("get_obdata_defname: Internal error, bad type: %d\n", type); - return "Empty"; + case OB_MESH: return "Mesh"; + case OB_CURVE: return "Curve"; + case OB_SURF: return "Surf"; + case OB_FONT: return "Text"; + case OB_MBALL: return "Mball"; + case OB_CAMERA: return "Camera"; + case OB_LAMP: return "Lamp"; + case OB_LATTICE: return "Lattice"; + case OB_ARMATURE: return "Armature"; + case OB_SPEAKER: return "Speaker"; + case OB_EMPTY: return "Empty"; + default: + printf("get_obdata_defname: Internal error, bad type: %d\n", type); + return "Empty"; } } /* more general add: creates minimum required data, but without vertices etc. */ -Object *add_only_object(int type, const char *name) +Object *BKE_object_add_only_object(int type, const char *name) { Object *ob; - if(!name) + if (!name) name = get_obdata_defname(type); - ob= alloc_libblock(&G.main->object, ID_OB, name); + ob = BKE_libblock_alloc(&G.main->object, ID_OB, name); /* default object vars */ - ob->type= type; + ob->type = type; - ob->col[0]= ob->col[1]= ob->col[2]= 1.0; - ob->col[3]= 1.0; + ob->col[0] = ob->col[1] = ob->col[2] = 1.0; + ob->col[3] = 1.0; - ob->size[0]= ob->size[1]= ob->size[2]= 1.0; - ob->dscale[0]= ob->dscale[1]= ob->dscale[2]= 1.0; + ob->size[0] = ob->size[1] = ob->size[2] = 1.0; + ob->dscale[0] = ob->dscale[1] = ob->dscale[2] = 1.0; /* objects should default to having Euler XYZ rotations, * but rotations default to quaternions */ - ob->rotmode= ROT_MODE_EUL; + ob->rotmode = ROT_MODE_EUL; unit_axis_angle(ob->rotAxis, &ob->rotAngle); unit_axis_angle(ob->drotAxis, &ob->drotAngle); @@ -833,35 +813,35 @@ Object *add_only_object(int type, const char *name) unit_m4(ob->constinv); unit_m4(ob->parentinv); unit_m4(ob->obmat); - ob->dt= OB_TEXTURE; - ob->empty_drawtype= OB_PLAINAXES; - ob->empty_drawsize= 1.0; + ob->dt = OB_TEXTURE; + ob->empty_drawtype = OB_PLAINAXES; + ob->empty_drawsize = 1.0; - if (type==OB_CAMERA || type==OB_LAMP || type==OB_SPEAKER) { - ob->trackflag= OB_NEGZ; - ob->upflag= OB_POSY; + if (type == OB_CAMERA || type == OB_LAMP || type == OB_SPEAKER) { + ob->trackflag = OB_NEGZ; + ob->upflag = OB_POSY; } else { - ob->trackflag= OB_POSY; - ob->upflag= OB_POSZ; + ob->trackflag = OB_POSY; + ob->upflag = OB_POSZ; } - ob->dupon= 1; ob->dupoff= 0; - ob->dupsta= 1; ob->dupend= 100; + ob->dupon = 1; ob->dupoff = 0; + ob->dupsta = 1; ob->dupend = 100; ob->dupfacesca = 1.0; /* Game engine defaults*/ - ob->mass= ob->inertia= 1.0f; - ob->formfactor= 0.4f; - ob->damping= 0.04f; - ob->rdamping= 0.1f; + ob->mass = ob->inertia = 1.0f; + ob->formfactor = 0.4f; + ob->damping = 0.04f; + ob->rdamping = 0.1f; ob->anisotropicFriction[0] = 1.0f; ob->anisotropicFriction[1] = 1.0f; ob->anisotropicFriction[2] = 1.0f; - ob->gameflag= OB_PROP|OB_COLLISION; + ob->gameflag = OB_PROP | OB_COLLISION; ob->margin = 0.0; - ob->init_state=1; - ob->state=1; + ob->init_state = 1; + ob->state = 1; /* ob->pad3 == Contact Processing Threshold */ ob->m_contactProcessingThreshold = 1.0f; ob->obstacleRad = 1.0f; @@ -879,23 +859,23 @@ Object *add_only_object(int type, const char *name) /* general add: to scene, with layer from area and default name */ /* creates minimum required data, but without vertices etc. */ -Object *add_object(struct Scene *scene, int type) +Object *BKE_object_add(struct Scene *scene, int type) { Object *ob; Base *base; char name[MAX_ID_NAME]; BLI_strncpy(name, get_obdata_defname(type), sizeof(name)); - ob = add_only_object(type, name); + ob = BKE_object_add_only_object(type, name); - ob->data= add_obdata_from_type(type); + ob->data = BKE_object_obdata_add_from_type(type); - ob->lay= scene->lay; + ob->lay = scene->lay; - base= scene_add_base(scene, ob); - scene_deselect_all(scene); - scene_select_base(scene, base); - ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; + base = BKE_scene_base_add(scene, ob); + BKE_scene_base_deselect_all(scene); + BKE_scene_base_select(scene, base); + ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; return ob; } @@ -904,19 +884,19 @@ SoftBody *copy_softbody(SoftBody *sb) { SoftBody *sbn; - if (sb==NULL) return(NULL); + if (sb == NULL) return(NULL); - sbn= MEM_dupallocN(sb); - sbn->totspring= sbn->totpoint= 0; - sbn->bpoint= NULL; - sbn->bspring= NULL; + sbn = MEM_dupallocN(sb); + sbn->totspring = sbn->totpoint = 0; + sbn->bpoint = NULL; + sbn->bspring = NULL; - sbn->keys= NULL; - sbn->totkey= sbn->totpointkey= 0; + sbn->keys = NULL; + sbn->totkey = sbn->totpointkey = 0; - sbn->scratch= NULL; + sbn->scratch = NULL; - sbn->pointcache= BKE_ptcache_copy_list(&sbn->ptcaches, &sb->ptcaches); + sbn->pointcache = BKE_ptcache_copy_list(&sbn->ptcaches, &sb->ptcaches); if (sb->effector_weights) sbn->effector_weights = MEM_dupallocN(sb->effector_weights); @@ -941,12 +921,12 @@ static ParticleSystem *copy_particlesystem(ParticleSystem *psys) ParticleData *pa; int p; - psysn= MEM_dupallocN(psys); - psysn->particles= MEM_dupallocN(psys->particles); - psysn->child= MEM_dupallocN(psys->child); + psysn = MEM_dupallocN(psys); + psysn->particles = MEM_dupallocN(psys->particles); + psysn->child = MEM_dupallocN(psys->child); if (psys->part->type == PART_HAIR) { - for (p=0, pa=psysn->particles; p<psysn->totpart; p++, pa++) + for (p = 0, pa = psysn->particles; p < psysn->totpart; p++, pa++) pa->hair = MEM_dupallocN(pa->hair); } @@ -960,7 +940,7 @@ static ParticleSystem *copy_particlesystem(ParticleSystem *psys) if (boid) boid = MEM_dupallocN(boid); - for (p=0, pa=psysn->particles; p<psysn->totpart; p++, pa++) { + for (p = 0, pa = psysn->particles; p < psysn->totpart; p++, pa++) { if (boid) pa->boid = boid++; if (key) { @@ -972,29 +952,29 @@ static ParticleSystem *copy_particlesystem(ParticleSystem *psys) if (psys->clmd) { psysn->clmd = (ClothModifierData *)modifier_new(eModifierType_Cloth); - modifier_copyData((ModifierData*)psys->clmd, (ModifierData*)psysn->clmd); + modifier_copyData((ModifierData *)psys->clmd, (ModifierData *)psysn->clmd); psys->hair_in_dm = psys->hair_out_dm = NULL; } BLI_duplicatelist(&psysn->targets, &psys->targets); - psysn->pathcache= NULL; - psysn->childcache= NULL; - psysn->edit= NULL; - psysn->frand= NULL; - psysn->pdd= NULL; - psysn->effectors= NULL; + psysn->pathcache = NULL; + psysn->childcache = NULL; + psysn->edit = NULL; + psysn->frand = NULL; + psysn->pdd = NULL; + psysn->effectors = NULL; psysn->pathcachebufs.first = psysn->pathcachebufs.last = NULL; psysn->childcachebufs.first = psysn->childcachebufs.last = NULL; psysn->renderdata = NULL; - psysn->pointcache= BKE_ptcache_copy_list(&psysn->ptcaches, &psys->ptcaches); + psysn->pointcache = BKE_ptcache_copy_list(&psysn->ptcaches, &psys->ptcaches); /* XXX - from reading existing code this seems correct but intended usage of * pointcache should /w cloth should be added in 'ParticleSystem' - campbell */ if (psysn->clmd) { - psysn->clmd->point_cache= psysn->pointcache; + psysn->clmd->point_cache = psysn->pointcache; } id_us_plus((ID *)psysn->part); @@ -1002,7 +982,7 @@ static ParticleSystem *copy_particlesystem(ParticleSystem *psys) return psysn; } -void copy_object_particlesystems(Object *obn, Object *ob) +void BKE_object_copy_particlesystems(Object *obn, Object *ob) { ParticleSystem *psys, *npsys; ModifierData *md; @@ -1012,34 +992,34 @@ void copy_object_particlesystems(Object *obn, Object *ob) return; } - obn->particlesystem.first= obn->particlesystem.last= NULL; - for (psys=ob->particlesystem.first; psys; psys=psys->next) { - npsys= copy_particlesystem(psys); + obn->particlesystem.first = obn->particlesystem.last = NULL; + for (psys = ob->particlesystem.first; psys; psys = psys->next) { + npsys = copy_particlesystem(psys); BLI_addtail(&obn->particlesystem, npsys); /* need to update particle modifiers too */ - for (md=obn->modifiers.first; md; md=md->next) { - if (md->type==eModifierType_ParticleSystem) { - ParticleSystemModifierData *psmd= (ParticleSystemModifierData*)md; - if (psmd->psys==psys) - psmd->psys= npsys; + for (md = obn->modifiers.first; md; md = md->next) { + if (md->type == eModifierType_ParticleSystem) { + ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)md; + if (psmd->psys == psys) + psmd->psys = npsys; } - else if (md->type==eModifierType_DynamicPaint) { - DynamicPaintModifierData *pmd= (DynamicPaintModifierData*)md; + else if (md->type == eModifierType_DynamicPaint) { + DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md; if (pmd->brush) { - if (pmd->brush->psys==psys) { - pmd->brush->psys= npsys; + if (pmd->brush->psys == psys) { + pmd->brush->psys = npsys; } } } - else if (md->type==eModifierType_Smoke) { - SmokeModifierData *smd = (SmokeModifierData*) md; + else if (md->type == eModifierType_Smoke) { + SmokeModifierData *smd = (SmokeModifierData *) md; - if (smd->type==MOD_SMOKE_TYPE_FLOW) { + if (smd->type == MOD_SMOKE_TYPE_FLOW) { if (smd->flow) { if (smd->flow->psys == psys) - smd->flow->psys= npsys; + smd->flow->psys = npsys; } } } @@ -1047,34 +1027,34 @@ void copy_object_particlesystems(Object *obn, Object *ob) } } -void copy_object_softbody(Object *obn, Object *ob) +void BKE_object_copy_softbody(Object *obn, Object *ob) { if (ob->soft) - obn->soft= copy_softbody(ob->soft); + obn->soft = copy_softbody(ob->soft); } static void copy_object_pose(Object *obn, Object *ob) { bPoseChannel *chan; - /* note: need to clear obn->pose pointer first, so that copy_pose works (otherwise there's a crash) */ - obn->pose= NULL; - copy_pose(&obn->pose, ob->pose, 1); /* 1 = copy constraints */ + /* note: need to clear obn->pose pointer first, so that BKE_pose_copy_data works (otherwise there's a crash) */ + obn->pose = NULL; + BKE_pose_copy_data(&obn->pose, ob->pose, 1); /* 1 = copy constraints */ - for (chan = obn->pose->chanbase.first; chan; chan=chan->next) { + for (chan = obn->pose->chanbase.first; chan; chan = chan->next) { bConstraint *con; - chan->flag &= ~(POSE_LOC|POSE_ROT|POSE_SIZE); + chan->flag &= ~(POSE_LOC | POSE_ROT | POSE_SIZE); - for (con= chan->constraints.first; con; con= con->next) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + for (con = chan->constraints.first; con; con = con->next) { + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); ListBase targets = {NULL, NULL}; bConstraintTarget *ct; if (cti && cti->get_constraint_targets) { cti->get_constraint_targets(con, &targets); - for (ct= targets.first; ct; ct= ct->next) { + for (ct = targets.first; ct; ct = ct->next) { if (ct->tar == ob) ct->tar = obn; } @@ -1088,11 +1068,11 @@ static void copy_object_pose(Object *obn, Object *ob) static int object_pose_context(Object *ob) { - if ( (ob) && - (ob->type == OB_ARMATURE) && - (ob->pose) && - (ob->mode & OB_MODE_POSE) - ) { + if ( (ob) && + (ob->type == OB_ARMATURE) && + (ob->pose) && + (ob->mode & OB_MODE_POSE)) + { return 1; } else { @@ -1100,15 +1080,15 @@ static int object_pose_context(Object *ob) } } -Object *object_pose_armature_get(Object *ob) +Object *BKE_object_pose_armature_get(Object *ob) { - if (ob==NULL) + if (ob == NULL) return NULL; if (object_pose_context(ob)) return ob; - ob= modifiers_isDeformedByArmature(ob); + ob = modifiers_isDeformedByArmature(ob); if (object_pose_context(ob)) return ob; @@ -1122,31 +1102,31 @@ static void copy_object_transform(Object *ob_tar, Object *ob_src) copy_v3_v3(ob_tar->rot, ob_src->rot); copy_v3_v3(ob_tar->quat, ob_src->quat); copy_v3_v3(ob_tar->rotAxis, ob_src->rotAxis); - ob_tar->rotAngle= ob_src->rotAngle; - ob_tar->rotmode= ob_src->rotmode; + ob_tar->rotAngle = ob_src->rotAngle; + ob_tar->rotmode = ob_src->rotmode; copy_v3_v3(ob_tar->size, ob_src->size); } -Object *copy_object(Object *ob) +Object *BKE_object_copy(Object *ob) { Object *obn; ModifierData *md; int a; - obn= copy_libblock(&ob->id); + obn = BKE_libblock_copy(&ob->id); if (ob->totcol) { - obn->mat= MEM_dupallocN(ob->mat); - obn->matbits= MEM_dupallocN(ob->matbits); - obn->totcol= ob->totcol; + obn->mat = MEM_dupallocN(ob->mat); + obn->matbits = MEM_dupallocN(ob->matbits); + obn->totcol = ob->totcol; } - if (ob->bb) obn->bb= MEM_dupallocN(ob->bb); + if (ob->bb) obn->bb = MEM_dupallocN(ob->bb); obn->flag &= ~OB_FROMGROUP; - obn->modifiers.first = obn->modifiers.last= NULL; + obn->modifiers.first = obn->modifiers.last = NULL; - for (md=ob->modifiers.first; md; md=md->next) { + for (md = ob->modifiers.first; md; md = md->next) { ModifierData *nmd = modifier_new(md->type); BLI_strncpy(nmd->name, md->name, sizeof(nmd->name)); modifier_copyData(md, nmd); @@ -1163,8 +1143,8 @@ Object *copy_object(Object *ob) if (ob->pose) { copy_object_pose(obn, ob); /* backwards compat... non-armatures can get poses in older files? */ - if (ob->type==OB_ARMATURE) - armature_rebuild_pose(obn, obn->data); + if (ob->type == OB_ARMATURE) + BKE_pose_rebuild(obn, obn->data); } defgroup_copy_list(&obn->defbase, &ob->defbase); copy_constraints(&obn->constraints, &ob->constraints, TRUE); @@ -1177,21 +1157,21 @@ Object *copy_object(Object *ob) id_us_plus((ID *)obn->gpd); id_lib_extern((ID *)obn->dup_group); - for (a=0; a<obn->totcol; a++) id_us_plus((ID *)obn->mat[a]); + for (a = 0; a < obn->totcol; a++) id_us_plus((ID *)obn->mat[a]); - obn->disp.first= obn->disp.last= NULL; + obn->disp.first = obn->disp.last = NULL; if (ob->pd) { - obn->pd= MEM_dupallocN(ob->pd); + obn->pd = MEM_dupallocN(ob->pd); if (obn->pd->tex) id_us_plus(&(obn->pd->tex->id)); if (obn->pd->rng) obn->pd->rng = MEM_dupallocN(ob->pd->rng); } - obn->soft= copy_softbody(ob->soft); + obn->soft = copy_softbody(ob->soft); obn->bsoft = copy_bulletsoftbody(ob->bsoft); - copy_object_particlesystems(obn, ob); + BKE_object_copy_particlesystems(obn, ob); obn->derivedDeform = NULL; obn->derivedFinal = NULL; @@ -1199,7 +1179,7 @@ Object *copy_object(Object *ob) obn->gpulamp.first = obn->gpulamp.last = NULL; obn->pc_ids.first = obn->pc_ids.last = NULL; - obn->mpath= NULL; + obn->mpath = NULL; return obn; } @@ -1215,35 +1195,35 @@ static void extern_local_object(Object *ob) extern_local_matarar(ob->mat, ob->totcol); - for (psys=ob->particlesystem.first; psys; psys=psys->next) + for (psys = ob->particlesystem.first; psys; psys = psys->next) id_lib_extern((ID *)psys->part); } -void make_local_object(Object *ob) +void BKE_object_make_local(Object *ob) { - Main *bmain= G.main; + Main *bmain = G.main; Scene *sce; Base *base; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (ob->id.lib==NULL) return; + if (ob->id.lib == NULL) return; - ob->proxy= ob->proxy_from= NULL; + ob->proxy = ob->proxy_from = NULL; - if (ob->id.us==1) { + if (ob->id.us == 1) { id_clear_lib_data(bmain, &ob->id); extern_local_object(ob); } else { - for (sce= bmain->scene.first; sce && ELEM(0, is_lib, is_local); sce= sce->id.next) { - if (object_in_scene(ob, sce)) { - if (sce->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (sce = bmain->scene.first; sce && ELEM(0, is_lib, is_local); sce = sce->id.next) { + if (BKE_scene_base_find(sce, ob)) { + if (sce->id.lib) is_lib = TRUE; + else is_local = TRUE; } } @@ -1252,27 +1232,27 @@ void make_local_object(Object *ob) extern_local_object(ob); } else if (is_local && is_lib) { - Object *ob_new= copy_object(ob); + Object *ob_new = BKE_object_copy(ob); - ob_new->id.us= 0; + ob_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, ob->id.lib, &ob_new->id); - sce= bmain->scene.first; + sce = bmain->scene.first; while (sce) { - if (sce->id.lib==NULL) { - base= sce->base.first; + if (sce->id.lib == NULL) { + base = sce->base.first; while (base) { - if (base->object==ob) { - base->object= ob_new; + if (base->object == ob) { + base->object = ob_new; ob_new->id.us++; ob->id.us--; } - base= base->next; + base = base->next; } } - sce= sce->id.next; + sce = sce->id.next; } } } @@ -1281,7 +1261,7 @@ void make_local_object(Object *ob) /* * Returns true if the Object is a from an external blend file (libdata) */ -int object_is_libdata(Object *ob) +int BKE_object_is_libdata(Object *ob) { if (!ob) return 0; if (ob->proxy) return 0; @@ -1290,12 +1270,12 @@ int object_is_libdata(Object *ob) } /* Returns true if the Object data is a from an external blend file (libdata) */ -int object_data_is_libdata(Object *ob) +int BKE_object_obdata_is_libdata(Object *ob) { if (!ob) return 0; - if (ob->proxy && (ob->data==NULL || ((ID *)ob->data)->lib==NULL)) return 0; + if (ob->proxy && (ob->data == NULL || ((ID *)ob->data)->lib == NULL)) return 0; if (ob->id.lib) return 1; - if (ob->data==NULL) return 0; + if (ob->data == NULL) return 0; if (((ID *)ob->data)->lib) return 1; return 0; @@ -1306,45 +1286,45 @@ int object_data_is_libdata(Object *ob) /* when you make proxy, ensure the exposed layers are extern */ static void armature_set_id_extern(Object *ob) { - bArmature *arm= ob->data; + bArmature *arm = ob->data; bPoseChannel *pchan; - unsigned int lay= arm->layer_protected; + unsigned int lay = arm->layer_protected; - for (pchan = ob->pose->chanbase.first; pchan; pchan=pchan->next) { + for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { if (!(pchan->bone->layer & lay)) id_lib_extern((ID *)pchan->custom); } } -void object_copy_proxy_drivers(Object *ob, Object *target) +void BKE_object_copy_proxy_drivers(Object *ob, Object *target) { if ((target->adt) && (target->adt->drivers.first)) { FCurve *fcu; /* add new animdata block */ if (!ob->adt) - ob->adt= BKE_id_add_animdata(&ob->id); + ob->adt = BKE_id_add_animdata(&ob->id); /* make a copy of all the drivers (for now), then correct any links that need fixing */ free_fcurves(&ob->adt->drivers); copy_fcurves(&ob->adt->drivers, &target->adt->drivers); - for (fcu= ob->adt->drivers.first; fcu; fcu= fcu->next) { - ChannelDriver *driver= fcu->driver; + for (fcu = ob->adt->drivers.first; fcu; fcu = fcu->next) { + ChannelDriver *driver = fcu->driver; DriverVar *dvar; - for (dvar= driver->variables.first; dvar; dvar= dvar->next) { + for (dvar = driver->variables.first; dvar; dvar = dvar->next) { /* all drivers */ DRIVER_TARGETS_LOOPER(dvar) { if (dtar->id) { if ((Object *)dtar->id == target) - dtar->id= (ID *)ob; + dtar->id = (ID *)ob; else { /* only on local objects because this causes indirect links a -> b -> c, blend to point directly to a.blend * when a.blend has a proxy thats linked into c.blend */ - if (ob->id.lib==NULL) + if (ob->id.lib == NULL) id_lib_extern((ID *)dtar->id); } } @@ -1359,19 +1339,19 @@ void object_copy_proxy_drivers(Object *ob, Object *target) /* local_object->proxy == pointer to library object, saved in files and read */ /* local_object->proxy_group == pointer to group dupli-object, saved in files and read */ -void object_make_proxy(Object *ob, Object *target, Object *gob) +void BKE_object_make_proxy(Object *ob, Object *target, Object *gob) { /* paranoia checks */ - if (ob->id.lib || target->id.lib==NULL) { + if (ob->id.lib || target->id.lib == NULL) { printf("cannot make proxy\n"); return; } - ob->proxy= target; - ob->proxy_group= gob; + ob->proxy = target; + ob->proxy_group = gob; id_lib_extern(&target->id); - ob->recalc= target->recalc= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; + ob->recalc = target->recalc = OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; /* copy transform * - gob means this proxy comes from a group, just apply the matrix @@ -1380,7 +1360,7 @@ void object_make_proxy(Object *ob, Object *target, Object *gob) * - no gob means this is being made from a linked object, * this is closer to making a copy of the object - in-place. */ if (gob) { - ob->rotmode= target->rotmode; + ob->rotmode = target->rotmode; mult_m4_m4m4(ob->obmat, gob->obmat, target->obmat); if (gob->dup_group) { /* should always be true */ float tvec[3]; @@ -1388,40 +1368,40 @@ void object_make_proxy(Object *ob, Object *target, Object *gob) mul_mat3_m4_v3(ob->obmat, tvec); sub_v3_v3(ob->obmat[3], tvec); } - object_apply_mat4(ob, ob->obmat, FALSE, TRUE); + BKE_object_apply_mat4(ob, ob->obmat, FALSE, TRUE); } else { copy_object_transform(ob, target); - ob->parent= target->parent; /* libdata */ + ob->parent = target->parent; /* libdata */ copy_m4_m4(ob->parentinv, target->parentinv); } /* copy animdata stuff - drivers only for now... */ - object_copy_proxy_drivers(ob, target); + BKE_object_copy_proxy_drivers(ob, target); /* skip constraints? */ // FIXME: this is considered by many as a bug /* set object type and link to data */ - ob->type= target->type; - ob->data= target->data; - id_us_plus((ID *)ob->data); /* ensures lib data becomes LIB_EXTERN */ + ob->type = target->type; + ob->data = target->data; + id_us_plus((ID *)ob->data); /* ensures lib data becomes LIB_EXTERN */ /* copy material and index information */ - ob->actcol= ob->totcol= 0; + ob->actcol = ob->totcol = 0; if (ob->mat) MEM_freeN(ob->mat); if (ob->matbits) MEM_freeN(ob->matbits); ob->mat = NULL; - ob->matbits= NULL; + ob->matbits = NULL; if ((target->totcol) && (target->mat) && OB_TYPE_SUPPORT_MATERIAL(ob->type)) { int i; - ob->actcol= target->actcol; - ob->totcol= target->totcol; + ob->actcol = target->actcol; + ob->totcol = target->totcol; ob->mat = MEM_dupallocN(target->mat); ob->matbits = MEM_dupallocN(target->matbits); - for (i=0; i<target->totcol; i++) { + for (i = 0; i < target->totcol; i++) { /* don't need to run test_object_materials since we know this object is new and not used elsewhere */ id_us_plus((ID *)ob->mat[i]); } @@ -1429,9 +1409,9 @@ void object_make_proxy(Object *ob, Object *target, Object *gob) /* type conversions */ if (target->type == OB_ARMATURE) { - copy_object_pose(ob, target); /* data copy, object pointers in constraints */ - rest_pose(ob->pose); /* clear all transforms in channels */ - armature_rebuild_pose(ob, ob->data); /* set all internal links */ + copy_object_pose(ob, target); /* data copy, object pointers in constraints */ + BKE_pose_rest(ob->pose); /* clear all transforms in channels */ + BKE_pose_rebuild(ob, ob->data); /* set all internal links */ armature_set_id_extern(ob); } @@ -1444,27 +1424,27 @@ void object_make_proxy(Object *ob, Object *target, Object *gob) if (ob->id.properties) { IDP_FreeProperty(ob->id.properties); MEM_freeN(ob->id.properties); - ob->id.properties= NULL; + ob->id.properties = NULL; } if (target->id.properties) { - ob->id.properties= IDP_CopyProperty(target->id.properties); + ob->id.properties = IDP_CopyProperty(target->id.properties); } /* copy drawtype info */ - ob->dt= target->dt; + ob->dt = target->dt; } /* *************** CALC ****************** */ -void object_scale_to_mat3(Object *ob, float mat[][3]) +void BKE_object_scale_to_mat3(Object *ob, float mat[][3]) { float vec[3]; mul_v3_v3v3(vec, ob->size, ob->dscale); size_to_mat3(mat, vec); } -void object_rot_to_mat3(Object *ob, float mat[][3]) +void BKE_object_rot_to_mat3(Object *ob, float mat[][3]) { float rmat[3][3], dmat[3][3]; @@ -1498,10 +1478,10 @@ void object_rot_to_mat3(Object *ob, float mat[][3]) mul_m3_m3m3(mat, dmat, rmat); } -void object_mat3_to_rot(Object *ob, float mat[][3], short use_compat) +void BKE_object_mat3_to_rot(Object *ob, float mat[][3], short use_compat) { switch (ob->rotmode) { - case ROT_MODE_QUAT: + case ROT_MODE_QUAT: { float dquat[4]; mat3_to_quat(ob->quat, mat); @@ -1510,12 +1490,12 @@ void object_mat3_to_rot(Object *ob, float mat[][3], short use_compat) mul_qt_qtqt(ob->quat, dquat, ob->quat); } break; - case ROT_MODE_AXISANGLE: - mat3_to_axis_angle(ob->rotAxis, &ob->rotAngle, mat); - sub_v3_v3(ob->rotAxis, ob->drotAxis); - ob->rotAngle -= ob->drotAngle; - break; - default: /* euler */ + case ROT_MODE_AXISANGLE: + mat3_to_axis_angle(ob->rotAxis, &ob->rotAngle, mat); + sub_v3_v3(ob->rotAxis, ob->drotAxis); + ob->rotAngle -= ob->drotAngle; + break; + default: /* euler */ { float quat[4]; float dquat[4]; @@ -1529,19 +1509,19 @@ void object_mat3_to_rot(Object *ob, float mat[][3], short use_compat) quat_to_mat3(tmat, quat); /* end drot correction */ - if (use_compat) mat3_to_compatible_eulO(ob->rot, ob->rot, ob->rotmode, tmat); - else mat3_to_eulO(ob->rot, ob->rotmode, tmat); + if (use_compat) mat3_to_compatible_eulO(ob->rot, ob->rot, ob->rotmode, tmat); + else mat3_to_eulO(ob->rot, ob->rotmode, tmat); } } } -void object_tfm_protected_backup(const Object *ob, - ObjectTfmProtectedChannels *obtfm) +void BKE_object_tfm_protected_backup(const Object *ob, + ObjectTfmProtectedChannels *obtfm) { -#define TFMCPY( _v) (obtfm->_v = ob->_v) -#define TFMCPY3D( _v) copy_v3_v3(obtfm->_v, ob->_v) -#define TFMCPY4D( _v) copy_v4_v4(obtfm->_v, ob->_v) +#define TFMCPY(_v) (obtfm->_v = ob->_v) +#define TFMCPY3D(_v) copy_v3_v3(obtfm->_v, ob->_v) +#define TFMCPY4D(_v) copy_v4_v4(obtfm->_v, ob->_v) TFMCPY3D(loc); TFMCPY3D(dloc); @@ -1562,46 +1542,46 @@ void object_tfm_protected_backup(const Object *ob, } -void object_tfm_protected_restore(Object *ob, - const ObjectTfmProtectedChannels *obtfm, - const short protectflag) +void BKE_object_tfm_protected_restore(Object *ob, + const ObjectTfmProtectedChannels *obtfm, + const short protectflag) { unsigned int i; - for (i= 0; i < 3; i++) { - if (protectflag & (OB_LOCK_LOCX<<i)) { - ob->loc[i]= obtfm->loc[i]; - ob->dloc[i]= obtfm->dloc[i]; + for (i = 0; i < 3; i++) { + if (protectflag & (OB_LOCK_LOCX << i)) { + ob->loc[i] = obtfm->loc[i]; + ob->dloc[i] = obtfm->dloc[i]; } - if (protectflag & (OB_LOCK_SCALEX<<i)) { - ob->size[i]= obtfm->size[i]; - ob->dscale[i]= obtfm->dscale[i]; + if (protectflag & (OB_LOCK_SCALEX << i)) { + ob->size[i] = obtfm->size[i]; + ob->dscale[i] = obtfm->dscale[i]; } - if (protectflag & (OB_LOCK_ROTX<<i)) { - ob->rot[i]= obtfm->rot[i]; - ob->drot[i]= obtfm->drot[i]; + if (protectflag & (OB_LOCK_ROTX << i)) { + ob->rot[i] = obtfm->rot[i]; + ob->drot[i] = obtfm->drot[i]; - ob->quat[i + 1]= obtfm->quat[i + 1]; - ob->dquat[i + 1]= obtfm->dquat[i + 1]; + ob->quat[i + 1] = obtfm->quat[i + 1]; + ob->dquat[i + 1] = obtfm->dquat[i + 1]; - ob->rotAxis[i]= obtfm->rotAxis[i]; - ob->drotAxis[i]= obtfm->drotAxis[i]; + ob->rotAxis[i] = obtfm->rotAxis[i]; + ob->drotAxis[i] = obtfm->drotAxis[i]; } } if ((protectflag & OB_LOCK_ROT4D) && (protectflag & OB_LOCK_ROTW)) { - ob->quat[0]= obtfm->quat[0]; - ob->dquat[0]= obtfm->dquat[0]; + ob->quat[0] = obtfm->quat[0]; + ob->dquat[0] = obtfm->dquat[0]; - ob->rotAngle= obtfm->rotAngle; - ob->drotAngle= obtfm->drotAngle; + ob->rotAngle = obtfm->rotAngle; + ob->drotAngle = obtfm->drotAngle; } } -/* see pchan_apply_mat4() for the equivalent 'pchan' function */ -void object_apply_mat4(Object *ob, float mat[][4], const short use_compat, const short use_parent) +/* see BKE_pchan_apply_mat4() for the equivalent 'pchan' function */ +void BKE_object_apply_mat4(Object *ob, float mat[][4], const short use_compat, const short use_parent) { float rot[3][3]; @@ -1610,15 +1590,15 @@ void object_apply_mat4(Object *ob, float mat[][4], const short use_compat, const mult_m4_m4m4(diff_mat, ob->parent->obmat, ob->parentinv); invert_m4_m4(imat, diff_mat); mult_m4_m4m4(rmat, imat, mat); /* get the parent relative matrix */ - object_apply_mat4(ob, rmat, use_compat, FALSE); + BKE_object_apply_mat4(ob, rmat, use_compat, FALSE); /* same as below, use rmat rather than mat */ mat4_to_loc_rot_size(ob->loc, rot, ob->size, rmat); - object_mat3_to_rot(ob, rot, use_compat); + BKE_object_mat3_to_rot(ob, rot, use_compat); } else { mat4_to_loc_rot_size(ob->loc, rot, ob->size, mat); - object_mat3_to_rot(ob, rot, use_compat); + BKE_object_mat3_to_rot(ob, rot, use_compat); } sub_v3_v3(ob->loc, ob->dloc); @@ -1627,28 +1607,28 @@ void object_apply_mat4(Object *ob, float mat[][4], const short use_compat, const if (ob->dscale[1] != 0.0f) ob->size[1] /= ob->dscale[1]; if (ob->dscale[2] != 0.0f) ob->size[2] /= ob->dscale[2]; - /* object_mat3_to_rot handles delta rotations */ + /* BKE_object_mat3_to_rot handles delta rotations */ } -void object_to_mat3(Object *ob, float mat[][3]) /* no parent */ +void BKE_object_to_mat3(Object *ob, float mat[][3]) /* no parent */ { float smat[3][3]; float rmat[3][3]; /*float q1[4];*/ /* size */ - object_scale_to_mat3(ob, smat); + BKE_object_scale_to_mat3(ob, smat); /* rot */ - object_rot_to_mat3(ob, rmat); + BKE_object_rot_to_mat3(ob, rmat); mul_m3_m3m3(mat, rmat, smat); } -void object_to_mat4(Object *ob, float mat[][4]) +void BKE_object_to_mat4(Object *ob, float mat[][4]) { float tmat[3][3]; - object_to_mat3(ob, tmat); + BKE_object_to_mat3(ob, tmat); copy_m4_m3(mat, tmat); @@ -1656,7 +1636,7 @@ void object_to_mat4(Object *ob, float mat[][4]) } /* extern */ -int enable_cu_speed= 1; +int enable_cu_speed = 1; static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4]) { @@ -1666,14 +1646,14 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4]) unit_m4(mat); - cu= par->data; - if (cu->path==NULL || cu->path->data==NULL) /* only happens on reload file, but violates depsgraph still... fix! */ - makeDispListCurveTypes(scene, par, 0); - if (cu->path==NULL) return; + cu = par->data; + if (cu->path == NULL || cu->path->data == NULL) /* only happens on reload file, but violates depsgraph still... fix! */ + BKE_displist_make_curveTypes(scene, par, 0); + if (cu->path == NULL) return; /* catch exceptions: feature for nla stride editing */ if (ob->ipoflag & OB_DISABLE_PATH) { - ctime= 0.0f; + ctime = 0.0f; } /* catch exceptions: curve paths used as a duplicator */ else if (enable_cu_speed) { @@ -1684,14 +1664,14 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4]) * factor, which then gets clamped to lie within 0.0 - 1.0 range */ if (IS_EQF(cu->pathlen, 0.0f) == 0) - ctime= cu->ctime / cu->pathlen; + ctime = cu->ctime / cu->pathlen; else - ctime= cu->ctime; + ctime = cu->ctime; CLAMP(ctime, 0.0f, 1.0f); } else { - ctime= scene->r.cfra; + ctime = scene->r.cfra; if (IS_EQF(cu->pathlen, 0.0f) == 0) ctime /= cu->pathlen; @@ -1700,7 +1680,7 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4]) /* time calculus is correct, now apply distance offset */ if (cu->flag & CU_OFFS_PATHDIST) { - ctime += timeoffs/cu->path->totdist; + ctime += timeoffs / cu->path->totdist; /* restore */ SWAP(float, sf_orig, ob->sf); @@ -1708,7 +1688,7 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4]) /* vec: 4 items! */ - if (where_on_path(par, ctime, vec, dir, cu->flag & CU_FOLLOW ? quat:NULL, &radius, NULL)) { + if (where_on_path(par, ctime, vec, dir, cu->flag & CU_FOLLOW ? quat : NULL, &radius, NULL)) { if (cu->flag & CU_FOLLOW) { #if 0 @@ -1717,11 +1697,11 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4]) /* the tilt */ normalize_v3(dir); - q[0]= (float)cos(0.5*vec[3]); - x1= (float)sin(0.5*vec[3]); - q[1]= -x1*dir[0]; - q[2]= -x1*dir[1]; - q[3]= -x1*dir[2]; + q[0] = (float)cos(0.5 * vec[3]); + x1 = (float)sin(0.5 * vec[3]); + q[1] = -x1 * dir[0]; + q[2] = -x1 * dir[1]; + q[3] = -x1 * dir[2]; mul_qt_qtqt(quat, q, quat); #else quat_apply_track(quat, ob->trackflag, ob->upflag); @@ -1747,15 +1727,15 @@ static void ob_parbone(Object *ob, Object *par, float mat[][4]) bPoseChannel *pchan; float vec[3]; - if (par->type!=OB_ARMATURE) { + if (par->type != OB_ARMATURE) { unit_m4(mat); return; } /* Make sure the bone is still valid */ - pchan= get_pose_channel(par->pose, ob->parsubstr); + pchan = BKE_pose_channel_find_name(par->pose, ob->parsubstr); if (!pchan) { - printf ("Object %s with Bone parent: bone %s doesn't exist\n", ob->id.name+2, ob->parsubstr); + printf("Object %s with Bone parent: bone %s doesn't exist\n", ob->id.name + 2, ob->parsubstr); unit_m4(mat); return; } @@ -1774,15 +1754,15 @@ static void give_parvert(Object *par, int nr, float vec[3]) BMEditMesh *em; int a, count; - vec[0]=vec[1]=vec[2]= 0.0f; + vec[0] = vec[1] = vec[2] = 0.0f; - if (par->type==OB_MESH) { - Mesh *me= par->data; + if (par->type == OB_MESH) { + Mesh *me = par->data; DerivedMesh *dm; em = me->edit_btmesh; -#if 0 /* this was bmesh only, better, evaluate why this was needed - campbell*/ +#if 0 /* this was bmesh only, better, evaluate why this was needed - campbell*/ if (em) { BMVert *eve; BMIter iter; @@ -1790,7 +1770,7 @@ static void give_parvert(Object *par, int nr, float vec[3]) BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { int *keyindex = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_SHAPE_KEYINDEX); - if (keyindex && *keyindex==nr) { + if (keyindex && *keyindex == nr) { copy_v3_v3(vec, eve->co); break; } @@ -1798,17 +1778,17 @@ static void give_parvert(Object *par, int nr, float vec[3]) } #endif - dm = (em)? em->derivedFinal: par->derivedFinal; + dm = (em) ? em->derivedFinal : par->derivedFinal; if (dm) { - MVert *mvert= dm->getVertArray(dm); + MVert *mvert = dm->getVertArray(dm); int *index = (int *)dm->getVertDataArray(dm, CD_ORIGINDEX); int i, vindex, numVerts = dm->getNumVerts(dm); /* get the average of all verts with (original index == nr) */ - count= 0; + count = 0; for (i = 0; i < numVerts; i++) { - vindex= (index)? index[i]: i; + vindex = (index) ? index[i] : i; if (vindex == nr) { add_v3_v3(vec, mvert[i].co); @@ -1816,7 +1796,7 @@ static void give_parvert(Object *par, int nr, float vec[3]) } } - if (count==0) { + if (count == 0) { /* keep as 0, 0, 0 */ } else if (count > 0) { @@ -1834,21 +1814,21 @@ static void give_parvert(Object *par, int nr, float vec[3]) Curve *cu; BPoint *bp; BezTriple *bezt; - int found= 0; + int found = 0; ListBase *nurbs; - cu= par->data; - nurbs= BKE_curve_nurbs_get(cu); - nu= nurbs->first; + cu = par->data; + nurbs = BKE_curve_nurbs_get(cu); + nu = nurbs->first; - count= 0; + count = 0; while (nu && !found) { if (nu->type == CU_BEZIER) { - bezt= nu->bezt; - a= nu->pntsu; + bezt = nu->bezt; + a = nu->pntsu; while (a--) { - if (count==nr) { - found= 1; + if (count == nr) { + found = 1; copy_v3_v3(vec, bezt->vec[1]); break; } @@ -1857,43 +1837,43 @@ static void give_parvert(Object *par, int nr, float vec[3]) } } else { - bp= nu->bp; - a= nu->pntsu*nu->pntsv; + bp = nu->bp; + a = nu->pntsu * nu->pntsv; while (a--) { - if (count==nr) { - found= 1; - memcpy(vec, bp->vec, sizeof(float)*3); + if (count == nr) { + found = 1; + memcpy(vec, bp->vec, sizeof(float) * 3); break; } count++; bp++; } } - nu= nu->next; + nu = nu->next; } } - else if (par->type==OB_LATTICE) { - Lattice *latt= par->data; + else if (par->type == OB_LATTICE) { + Lattice *latt = par->data; BPoint *bp; - DispList *dl = find_displist(&par->disp, DL_VERTS); - float *co = dl?dl->verts:NULL; + DispList *dl = BKE_displist_find(&par->disp, DL_VERTS); + float *co = dl ? dl->verts : NULL; - if (latt->editlatt) latt= latt->editlatt->latt; + if (latt->editlatt) latt = latt->editlatt->latt; - a= latt->pntsu*latt->pntsv*latt->pntsw; - count= 0; - bp= latt->def; + a = latt->pntsu * latt->pntsv * latt->pntsw; + count = 0; + bp = latt->def; while (a--) { - if (count==nr) { + if (count == nr) { if (co) - memcpy(vec, co, 3*sizeof(float)); + memcpy(vec, co, 3 * sizeof(float)); else - memcpy(vec, bp->vec, 3*sizeof(float)); + memcpy(vec, bp->vec, 3 * sizeof(float)); break; } count++; - if (co) co+= 3; + if (co) co += 3; else bp++; } } @@ -1916,7 +1896,7 @@ static void ob_parvert3(Object *ob, Object *par, float mat[][4]) quat_to_mat3(cmat, q); copy_m4_m3(mat, cmat); - if (ob->type==OB_CURVE) { + if (ob->type == OB_CURVE) { copy_v3_v3(mat[3], v1); } else { @@ -1934,48 +1914,48 @@ static int where_is_object_parslow(Object *ob, float obmat[4][4], float slowmat[ int a; // include framerate - fac1= (1.0f / (1.0f + fabsf(ob->sf)) ); + fac1 = (1.0f / (1.0f + fabsf(ob->sf)) ); if (fac1 >= 1.0f) return 0; - fac2= 1.0f-fac1; + fac2 = 1.0f - fac1; - fp1= obmat[0]; - fp2= slowmat[0]; - for (a=0; a<16; a++, fp1++, fp2++) { - fp1[0]= fac1*fp1[0] + fac2*fp2[0]; + fp1 = obmat[0]; + fp2 = slowmat[0]; + for (a = 0; a < 16; a++, fp1++, fp2++) { + fp1[0] = fac1 * fp1[0] + fac2 * fp2[0]; } return 1; } -void where_is_object_time(Scene *scene, Object *ob, float ctime) +void BKE_object_where_is_calc_time(Scene *scene, Object *ob, float ctime) { float slowmat[4][4] = MAT4_UNITY; - float stime=ctime; + float stime = ctime; /* new version: correct parent+vertexparent and track+parent */ /* this one only calculates direct attached parent and track */ /* is faster, but should keep track of timeoffs */ - if (ob==NULL) return; + if (ob == NULL) return; /* execute drivers only, as animation has already been done */ BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, ctime, ADT_RECALC_DRIVERS); if (ob->parent) { - Object *par= ob->parent; + Object *par = ob->parent; /* hurms, code below conflicts with depgraph... (ton) */ /* and even worse, it gives bad effects for NLA stride too (try ctime != par->ctime, with MBlur) */ if (stime != par->ctime) { // only for ipo systems? - Object tmp= *par; + Object tmp = *par; - if (par->proxy_from); // was a copied matrix, no where_is! bad... - else where_is_object_time(scene, par, ctime); + if (par->proxy_from) ; // was a copied matrix, no where_is! bad... + else BKE_object_where_is_calc_time(scene, par, ctime); solve_parenting(scene, ob, par, ob->obmat, slowmat, 0); - *par= tmp; + *par = tmp; } else solve_parenting(scene, ob, par, ob->obmat, slowmat, 0); @@ -1989,36 +1969,36 @@ void where_is_object_time(Scene *scene, Object *ob, float ctime) } } else { - object_to_mat4(ob, ob->obmat); + BKE_object_to_mat4(ob, ob->obmat); } /* solve constraints */ if (ob->constraints.first && !(ob->transflag & OB_NO_CONSTRAINTS)) { bConstraintOb *cob; - cob= constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT); + cob = constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT); - /* constraints need ctime, not stime. Some call where_is_object_time and bsystem_time */ - solve_constraints (&ob->constraints, cob, ctime); + /* constraints need ctime, not stime. Some call BKE_object_where_is_calc_time and bsystem_time */ + solve_constraints(&ob->constraints, cob, ctime); constraints_clear_evalob(cob); } /* set negative scale flag in object */ - if (is_negative_m4(ob->obmat)) ob->transflag |= OB_NEG_SCALE; - else ob->transflag &= ~OB_NEG_SCALE; + if (is_negative_m4(ob->obmat)) ob->transflag |= OB_NEG_SCALE; + else ob->transflag &= ~OB_NEG_SCALE; } /* get object transformation matrix without recalculating dependencies and * constraints -- assume dependencies are already solved by depsgraph. * no changes to object and it's parent would be done. * used for bundles orientation in 3d space relative to parented blender camera */ -void where_is_object_mat(Scene *scene, Object *ob, float obmat[4][4]) +void BKE_object_where_is_calc_mat4(Scene *scene, Object *ob, float obmat[4][4]) { float slowmat[4][4] = MAT4_UNITY; if (ob->parent) { - Object *par= ob->parent; + Object *par = ob->parent; solve_parenting(scene, ob, par, obmat, slowmat, 1); @@ -2026,11 +2006,11 @@ void where_is_object_mat(Scene *scene, Object *ob, float obmat[4][4]) where_is_object_parslow(ob, obmat, slowmat); } else { - object_to_mat4(ob, obmat); + BKE_object_to_mat4(ob, obmat); } } -static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[][4], float slowmat[][4], int simul) +static void solve_parenting(Scene *scene, Object *ob, Object *par, float obmat[][4], float slowmat[][4], int simul) { float totmat[4][4]; float tmat[4][4]; @@ -2038,58 +2018,58 @@ static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[ float vec[3]; int ok; - object_to_mat4(ob, locmat); + BKE_object_to_mat4(ob, locmat); if (ob->partype & PARSLOW) copy_m4_m4(slowmat, obmat); switch (ob->partype & PARTYPE) { - case PAROBJECT: - ok= 0; - if (par->type==OB_CURVE) { - if (((Curve *)par->data)->flag & CU_PATH ) { - ob_parcurve(scene, ob, par, tmat); - ok= 1; + case PAROBJECT: + ok = 0; + if (par->type == OB_CURVE) { + if (((Curve *)par->data)->flag & CU_PATH) { + ob_parcurve(scene, ob, par, tmat); + ok = 1; + } } - } - if (ok) mul_serie_m4(totmat, par->obmat, tmat, - NULL, NULL, NULL, NULL, NULL, NULL); - else copy_m4_m4(totmat, par->obmat); + if (ok) mul_serie_m4(totmat, par->obmat, tmat, + NULL, NULL, NULL, NULL, NULL, NULL); + else copy_m4_m4(totmat, par->obmat); - break; - case PARBONE: - ob_parbone(ob, par, tmat); - mul_serie_m4(totmat, par->obmat, tmat, - NULL, NULL, NULL, NULL, NULL, NULL); - break; + break; + case PARBONE: + ob_parbone(ob, par, tmat); + mul_serie_m4(totmat, par->obmat, tmat, + NULL, NULL, NULL, NULL, NULL, NULL); + break; - case PARVERT1: - unit_m4(totmat); - if (simul) { - copy_v3_v3(totmat[3], par->obmat[3]); - } - else { - give_parvert(par, ob->par1, vec); - mul_v3_m4v3(totmat[3], par->obmat, vec); - } - break; - case PARVERT3: - ob_parvert3(ob, par, tmat); + case PARVERT1: + unit_m4(totmat); + if (simul) { + copy_v3_v3(totmat[3], par->obmat[3]); + } + else { + give_parvert(par, ob->par1, vec); + mul_v3_m4v3(totmat[3], par->obmat, vec); + } + break; + case PARVERT3: + ob_parvert3(ob, par, tmat); - mul_serie_m4(totmat, par->obmat, tmat, - NULL, NULL, NULL, NULL, NULL, NULL); - break; + mul_serie_m4(totmat, par->obmat, tmat, + NULL, NULL, NULL, NULL, NULL, NULL); + break; - case PARSKEL: - copy_m4_m4(totmat, par->obmat); - break; + case PARSKEL: + copy_m4_m4(totmat, par->obmat); + break; } // total mul_serie_m4(tmat, totmat, ob->parentinv, - NULL, NULL, NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL, NULL); mul_serie_m4(obmat, tmat, locmat, - NULL, NULL, NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL, NULL); if (simul) { @@ -2099,7 +2079,7 @@ static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[ copy_m3_m4(originmat, tmat); // origin, voor help line - if ((ob->partype & PARTYPE)==PARSKEL ) { + if ((ob->partype & PARTYPE) == PARSKEL) { copy_v3_v3(ob->orig, par->obmat[3]); } else { @@ -2109,13 +2089,13 @@ static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[ } -void where_is_object(struct Scene *scene, Object *ob) +void BKE_object_where_is_calc(struct Scene *scene, Object *ob) { - where_is_object_time(scene, ob, (float)scene->r.cfra); + BKE_object_where_is_calc_time(scene, ob, (float)scene->r.cfra); } -void where_is_object_simul(Scene *scene, Object *ob) +void BKE_object_where_is_calc_simul(Scene *scene, Object *ob) /* was written for the old game engine (until 2.04) */ /* It seems that this function is only called * for a lamp that is the child of another object */ @@ -2128,114 +2108,114 @@ void where_is_object_simul(Scene *scene, Object *ob) /* NO TIMEOFFS */ if (ob->parent) { - par= ob->parent; + par = ob->parent; solve_parenting(scene, ob, par, ob->obmat, slowmat, 1); if (ob->partype & PARSLOW) { - fac1= (float)(1.0/(1.0+ fabs(ob->sf))); - fac2= 1.0f-fac1; - fp1= ob->obmat[0]; - fp2= slowmat[0]; - for (a=0; a<16; a++, fp1++, fp2++) { - fp1[0]= fac1*fp1[0] + fac2*fp2[0]; + fac1 = (float)(1.0 / (1.0 + fabs(ob->sf))); + fac2 = 1.0f - fac1; + fp1 = ob->obmat[0]; + fp2 = slowmat[0]; + for (a = 0; a < 16; a++, fp1++, fp2++) { + fp1[0] = fac1 * fp1[0] + fac2 * fp2[0]; } } } else { - object_to_mat4(ob, ob->obmat); + BKE_object_to_mat4(ob, ob->obmat); } /* solve constraints */ if (ob->constraints.first) { bConstraintOb *cob; - cob= constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT); + cob = constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT); solve_constraints(&ob->constraints, cob, (float)scene->r.cfra); constraints_clear_evalob(cob); } } /* for calculation of the inverse parent transform, only used for editor */ -void what_does_parent(Scene *scene, Object *ob, Object *workob) +void BKE_object_workob_calc_parent(Scene *scene, Object *ob, Object *workob) { - clear_workob(workob); + BKE_object_workob_clear(workob); unit_m4(workob->obmat); unit_m4(workob->parentinv); unit_m4(workob->constinv); - workob->parent= ob->parent; + workob->parent = ob->parent; - workob->trackflag= ob->trackflag; - workob->upflag= ob->upflag; + workob->trackflag = ob->trackflag; + workob->upflag = ob->upflag; - workob->partype= ob->partype; - workob->par1= ob->par1; - workob->par2= ob->par2; - workob->par3= ob->par3; + workob->partype = ob->partype; + workob->par1 = ob->par1; + workob->par2 = ob->par2; + workob->par3 = ob->par3; workob->constraints.first = ob->constraints.first; workob->constraints.last = ob->constraints.last; BLI_strncpy(workob->parsubstr, ob->parsubstr, sizeof(workob->parsubstr)); - where_is_object(scene, workob); + BKE_object_where_is_calc(scene, workob); } -BoundBox *unit_boundbox(void) +BoundBox *BKE_boundbox_alloc_unit(void) { BoundBox *bb; float min[3] = {-1.0f, -1.0f, -1.0f}, max[3] = {-1.0f, -1.0f, -1.0f}; - bb= MEM_callocN(sizeof(BoundBox), "OB-BoundBox"); - boundbox_set_from_min_max(bb, min, max); + bb = MEM_callocN(sizeof(BoundBox), "OB-BoundBox"); + BKE_boundbox_init_from_minmax(bb, min, max); return bb; } -void boundbox_set_from_min_max(BoundBox *bb, float min[3], float max[3]) +void BKE_boundbox_init_from_minmax(BoundBox *bb, float min[3], float max[3]) { - bb->vec[0][0]=bb->vec[1][0]=bb->vec[2][0]=bb->vec[3][0]= min[0]; - bb->vec[4][0]=bb->vec[5][0]=bb->vec[6][0]=bb->vec[7][0]= max[0]; + bb->vec[0][0] = bb->vec[1][0] = bb->vec[2][0] = bb->vec[3][0] = min[0]; + bb->vec[4][0] = bb->vec[5][0] = bb->vec[6][0] = bb->vec[7][0] = max[0]; - bb->vec[0][1]=bb->vec[1][1]=bb->vec[4][1]=bb->vec[5][1]= min[1]; - bb->vec[2][1]=bb->vec[3][1]=bb->vec[6][1]=bb->vec[7][1]= max[1]; + bb->vec[0][1] = bb->vec[1][1] = bb->vec[4][1] = bb->vec[5][1] = min[1]; + bb->vec[2][1] = bb->vec[3][1] = bb->vec[6][1] = bb->vec[7][1] = max[1]; - bb->vec[0][2]=bb->vec[3][2]=bb->vec[4][2]=bb->vec[7][2]= min[2]; - bb->vec[1][2]=bb->vec[2][2]=bb->vec[5][2]=bb->vec[6][2]= max[2]; + bb->vec[0][2] = bb->vec[3][2] = bb->vec[4][2] = bb->vec[7][2] = min[2]; + bb->vec[1][2] = bb->vec[2][2] = bb->vec[5][2] = bb->vec[6][2] = max[2]; } -BoundBox *object_get_boundbox(Object *ob) +BoundBox *BKE_object_boundbox_get(Object *ob) { - BoundBox *bb= NULL; + BoundBox *bb = NULL; - if (ob->type==OB_MESH) { - bb = mesh_get_bb(ob); + if (ob->type == OB_MESH) { + bb = BKE_mesh_boundbox_get(ob); } else if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) { - bb= ob->bb ? ob->bb : ((Curve *)ob->data )->bb; + bb = ob->bb ? ob->bb : ((Curve *)ob->data)->bb; } - else if (ob->type==OB_MBALL) { - bb= ob->bb; + else if (ob->type == OB_MBALL) { + bb = ob->bb; } return bb; } /* used to temporally disable/enable boundbox */ -void object_boundbox_flag(Object *ob, int flag, int set) +void BKE_object_boundbox_flag(Object *ob, int flag, int set) { - BoundBox *bb= object_get_boundbox(ob); + BoundBox *bb = BKE_object_boundbox_get(ob); if (bb) { if (set) bb->flag |= flag; else bb->flag &= ~flag; } } -void object_get_dimensions(Object *ob, float vec[3]) +void BKE_object_dimensions_get(Object *ob, float vec[3]) { BoundBox *bb = NULL; - bb= object_get_boundbox(ob); + bb = BKE_object_boundbox_get(ob); if (bb) { float scale[3]; @@ -2250,11 +2230,11 @@ void object_get_dimensions(Object *ob, float vec[3]) } } -void object_set_dimensions(Object *ob, const float *value) +void BKE_object_dimensions_set(Object *ob, const float *value) { BoundBox *bb = NULL; - bb= object_get_boundbox(ob); + bb = BKE_object_boundbox_get(ob); if (bb) { float scale[3], len[3]; @@ -2270,117 +2250,117 @@ void object_set_dimensions(Object *ob, const float *value) } } -void minmax_object(Object *ob, float min[3], float max[3]) +void BKE_object_minmax(Object *ob, float min_r[3], float max_r[3]) { BoundBox bb; float vec[3]; int a; - short change= FALSE; + short change = FALSE; switch (ob->type) { - case OB_CURVE: - case OB_FONT: - case OB_SURF: + case OB_CURVE: + case OB_FONT: + case OB_SURF: { - Curve *cu= ob->data; + Curve *cu = ob->data; - if (cu->bb==NULL) BKE_curve_tex_space_calc(cu); - bb= *(cu->bb); + if (cu->bb == NULL) BKE_curve_texspace_calc(cu); + bb = *(cu->bb); - for (a=0; a<8; a++) { + for (a = 0; a < 8; a++) { mul_m4_v3(ob->obmat, bb.vec[a]); - DO_MINMAX(bb.vec[a], min, max); + DO_MINMAX(bb.vec[a], min_r, max_r); } - change= TRUE; + change = TRUE; } break; - case OB_LATTICE: + case OB_LATTICE: { - Lattice *lt= ob->data; - BPoint *bp= lt->def; + Lattice *lt = ob->data; + BPoint *bp = lt->def; int u, v, w; - for (w=0; w<lt->pntsw; w++) { - for (v=0; v<lt->pntsv; v++) { - for (u=0; u<lt->pntsu; u++, bp++) { + for (w = 0; w < lt->pntsw; w++) { + for (v = 0; v < lt->pntsv; v++) { + for (u = 0; u < lt->pntsu; u++, bp++) { mul_v3_m4v3(vec, ob->obmat, bp->vec); - DO_MINMAX(vec, min, max); + DO_MINMAX(vec, min_r, max_r); } } } - change= TRUE; + change = TRUE; } break; - case OB_ARMATURE: - if (ob->pose) { - bPoseChannel *pchan; - for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - mul_v3_m4v3(vec, ob->obmat, pchan->pose_head); - DO_MINMAX(vec, min, max); - mul_v3_m4v3(vec, ob->obmat, pchan->pose_tail); - DO_MINMAX(vec, min, max); + case OB_ARMATURE: + if (ob->pose) { + bPoseChannel *pchan; + for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { + mul_v3_m4v3(vec, ob->obmat, pchan->pose_head); + DO_MINMAX(vec, min_r, max_r); + mul_v3_m4v3(vec, ob->obmat, pchan->pose_tail); + DO_MINMAX(vec, min_r, max_r); + } + change = TRUE; } - change= TRUE; - } - break; - case OB_MESH: + break; + case OB_MESH: { - Mesh *me= get_mesh(ob); + Mesh *me = BKE_mesh_from_object(ob); if (me) { - bb = *mesh_get_bb(ob); + bb = *BKE_mesh_boundbox_get(ob); - for (a=0; a<8; a++) { + for (a = 0; a < 8; a++) { mul_m4_v3(ob->obmat, bb.vec[a]); - DO_MINMAX(bb.vec[a], min, max); + DO_MINMAX(bb.vec[a], min_r, max_r); } - change= TRUE; + change = TRUE; } } break; } if (change == FALSE) { - DO_MINMAX(ob->obmat[3], min, max); + DO_MINMAX(ob->obmat[3], min_r, max_r); copy_v3_v3(vec, ob->obmat[3]); add_v3_v3(vec, ob->size); - DO_MINMAX(vec, min, max); + DO_MINMAX(vec, min_r, max_r); copy_v3_v3(vec, ob->obmat[3]); sub_v3_v3(vec, ob->size); - DO_MINMAX(vec, min, max); + DO_MINMAX(vec, min_r, max_r); } } -int minmax_object_duplis(Scene *scene, Object *ob, float min[3], float max[3]) +int BKE_object_minmax_dupli(Scene *scene, Object *ob, float r_min[3], float r_max[3]) { - int ok= 0; - if ((ob->transflag & OB_DUPLI)==0) { + int ok = 0; + if ((ob->transflag & OB_DUPLI) == 0) { return ok; } else { ListBase *lb; DupliObject *dob; - lb= object_duplilist(scene, ob); - for (dob= lb->first; dob; dob= dob->next) { + lb = object_duplilist(scene, ob); + for (dob = lb->first; dob; dob = dob->next) { if (dob->no_draw == 0) { - BoundBox *bb= object_get_boundbox(dob->ob); + BoundBox *bb = BKE_object_boundbox_get(dob->ob); if (bb) { int i; - for (i=0; i<8; i++) { + for (i = 0; i < 8; i++) { float vec[3]; mul_v3_m4v3(vec, dob->mat, bb->vec[i]); - DO_MINMAX(vec, min, max); + DO_MINMAX(vec, r_min, r_max); } - ok= 1; + ok = 1; } } } - free_object_duplilist(lb); /* does restore */ + free_object_duplilist(lb); /* does restore */ } return ok; @@ -2393,12 +2373,12 @@ void BKE_object_foreach_display_point( float co[3]; if (ob->derivedFinal) { - DerivedMesh *dm= ob->derivedFinal; - MVert *mv= dm->getVertArray(dm); - int totvert= dm->getNumVerts(dm); + DerivedMesh *dm = ob->derivedFinal; + MVert *mv = dm->getVertArray(dm); + int totvert = dm->getNumVerts(dm); int i; - for (i= 0; i < totvert; i++, mv++) { + for (i = 0; i < totvert; i++, mv++) { mul_v3_m4v3(co, obmat, mv->co); func_cb(co, user_data); } @@ -2406,12 +2386,12 @@ void BKE_object_foreach_display_point( else if (ob->disp.first) { DispList *dl; - for (dl=ob->disp.first; dl; dl=dl->next) { - float *v3= dl->verts; - int totvert= dl->nr; + for (dl = ob->disp.first; dl; dl = dl->next) { + float *v3 = dl->verts; + int totvert = dl->nr; int i; - for (i= 0; i < totvert; i++, v3+=3) { + for (i = 0; i < totvert; i++, v3 += 3) { mul_v3_m4v3(co, obmat, v3); func_cb(co, user_data); } @@ -2426,24 +2406,24 @@ void BKE_scene_foreach_display_point( Base *base; Object *ob; - for (base= FIRSTBASE; base; base = base->next) { + for (base = FIRSTBASE; base; base = base->next) { if (BASE_VISIBLE(v3d, base) && (base->flag & flag) == flag) { - ob= base->object; + ob = base->object; - if ((ob->transflag & OB_DUPLI)==0) { + if ((ob->transflag & OB_DUPLI) == 0) { BKE_object_foreach_display_point(ob, ob->obmat, func_cb, user_data); } else { ListBase *lb; DupliObject *dob; - lb= object_duplilist(scene, ob); - for (dob= lb->first; dob; dob= dob->next) { + lb = object_duplilist(scene, ob); + for (dob = lb->first; dob; dob = dob->next) { if (dob->no_draw == 0) { BKE_object_foreach_display_point(dob->ob, dob->mat, func_cb, user_data); } } - free_object_duplilist(lb); /* does restore */ + free_object_duplilist(lb); /* does restore */ } } } @@ -2452,20 +2432,20 @@ void BKE_scene_foreach_display_point( /* copied from DNA_object_types.h */ typedef struct ObTfmBack { float loc[3], dloc[3], orig[3]; - float size[3], dscale[3]; /* scale and delta scale */ - float rot[3], drot[3]; /* euler rotation */ - float quat[4], dquat[4]; /* quaternion rotation */ - float rotAxis[3], drotAxis[3]; /* axis angle rotation - axis part */ - float rotAngle, drotAngle; /* axis angle rotation - angle part */ - float obmat[4][4]; /* final worldspace matrix with constraints & animsys applied */ + float size[3], dscale[3]; /* scale and delta scale */ + float rot[3], drot[3]; /* euler rotation */ + float quat[4], dquat[4]; /* quaternion rotation */ + float rotAxis[3], drotAxis[3]; /* axis angle rotation - axis part */ + float rotAngle, drotAngle; /* axis angle rotation - angle part */ + float obmat[4][4]; /* final worldspace matrix with constraints & animsys applied */ float parentinv[4][4]; /* inverse result of parent, so that object doesn't 'stick' to parent */ float constinv[4][4]; /* inverse result of constraints. doesn't include effect of parent or object local transform */ - float imat[4][4]; /* inverse matrix of 'obmat' for during render, old game engine, temporally: ipokeys of transform */ + float imat[4][4]; /* inverse matrix of 'obmat' for during render, old game engine, temporally: ipokeys of transform */ } ObTfmBack; -void *object_tfm_backup(Object *ob) +void *BKE_object_tfm_backup(Object *ob) { - ObTfmBack *obtfm= MEM_mallocN(sizeof(ObTfmBack), "ObTfmBack"); + ObTfmBack *obtfm = MEM_mallocN(sizeof(ObTfmBack), "ObTfmBack"); copy_v3_v3(obtfm->loc, ob->loc); copy_v3_v3(obtfm->dloc, ob->dloc); copy_v3_v3(obtfm->orig, ob->orig); @@ -2477,8 +2457,8 @@ void *object_tfm_backup(Object *ob) copy_qt_qt(obtfm->dquat, ob->dquat); copy_v3_v3(obtfm->rotAxis, ob->rotAxis); copy_v3_v3(obtfm->drotAxis, ob->drotAxis); - obtfm->rotAngle= ob->rotAngle; - obtfm->drotAngle= ob->drotAngle; + obtfm->rotAngle = ob->rotAngle; + obtfm->drotAngle = ob->drotAngle; copy_m4_m4(obtfm->obmat, ob->obmat); copy_m4_m4(obtfm->parentinv, ob->parentinv); copy_m4_m4(obtfm->constinv, ob->constinv); @@ -2487,9 +2467,9 @@ void *object_tfm_backup(Object *ob) return (void *)obtfm; } -void object_tfm_restore(Object *ob, void *obtfm_pt) +void BKE_object_tfm_restore(Object *ob, void *obtfm_pt) { - ObTfmBack *obtfm= (ObTfmBack *)obtfm_pt; + ObTfmBack *obtfm = (ObTfmBack *)obtfm_pt; copy_v3_v3(ob->loc, obtfm->loc); copy_v3_v3(ob->dloc, obtfm->dloc); copy_v3_v3(ob->orig, obtfm->orig); @@ -2501,8 +2481,8 @@ void object_tfm_restore(Object *ob, void *obtfm_pt) copy_qt_qt(ob->dquat, obtfm->dquat); copy_v3_v3(ob->rotAxis, obtfm->rotAxis); copy_v3_v3(ob->drotAxis, obtfm->drotAxis); - ob->rotAngle= obtfm->rotAngle; - ob->drotAngle= obtfm->drotAngle; + ob->rotAngle = obtfm->rotAngle; + ob->drotAngle = obtfm->drotAngle; copy_m4_m4(ob->obmat, obtfm->obmat); copy_m4_m4(ob->parentinv, obtfm->parentinv); copy_m4_m4(ob->constinv, obtfm->constinv); @@ -2524,37 +2504,37 @@ int BKE_object_parent_loop_check(const Object *par, const Object *ob) /* the main object update call, for object matrix, constraints, keys and displist (modifiers) */ /* requires flags to be set! */ -void object_handle_update(Scene *scene, Object *ob) +void BKE_object_handle_update(Scene *scene, Object *ob) { if (ob->recalc & OB_RECALC_ALL) { /* speed optimization for animation lookups */ if (ob->pose) - make_pose_channels_hash(ob->pose); + BKE_pose_channels_hash_make(ob->pose); if (ob->recalc & OB_RECALC_DATA) { - if (ob->type==OB_ARMATURE) { + if (ob->type == OB_ARMATURE) { /* this happens for reading old files and to match library armatures - * with poses we do it ahead of where_is_object to ensure animation + * with poses we do it ahead of BKE_object_where_is_calc to ensure animation * is evaluated on the rebuilt pose, otherwise we get incorrect poses * on file load */ - if (ob->pose==NULL || (ob->pose->flag & POSE_RECALC)) - armature_rebuild_pose(ob, ob->data); + if (ob->pose == NULL || (ob->pose->flag & POSE_RECALC)) + BKE_pose_rebuild(ob, ob->data); } } /* XXX new animsys warning: depsgraph tag OB_RECALC_DATA should not skip drivers, - * which is only in where_is_object now */ + * which is only in BKE_object_where_is_calc now */ // XXX: should this case be OB_RECALC_OB instead? if (ob->recalc & OB_RECALC_ALL) { if (G.debug & G_DEBUG) - printf("recalcob %s\n", ob->id.name+2); + printf("recalcob %s\n", ob->id.name + 2); /* handle proxy copy for target */ if (ob->id.lib && ob->proxy_from) { // printf("ob proxy copy, lib ob %s proxy %s\n", ob->id.name, ob->proxy_from->id.name); - if (ob->proxy_from->proxy_group) {/* transform proxy into group space */ - Object *obg= ob->proxy_from->proxy_group; + if (ob->proxy_from->proxy_group) { /* transform proxy into group space */ + Object *obg = ob->proxy_from->proxy_group; invert_m4_m4(obg->imat, obg->obmat); mult_m4_m4m4(ob->obmat, obg->imat, ob->proxy_from->obmat); if (obg->dup_group) { /* should always be true */ @@ -2565,18 +2545,18 @@ void object_handle_update(Scene *scene, Object *ob) copy_m4_m4(ob->obmat, ob->proxy_from->obmat); } else - where_is_object(scene, ob); + BKE_object_where_is_calc(scene, ob); } if (ob->recalc & OB_RECALC_DATA) { - ID *data_id= (ID *)ob->data; - AnimData *adt= BKE_animdata_from_id(data_id); - float ctime= (float)scene->r.cfra; // XXX this is bad... + ID *data_id = (ID *)ob->data; + AnimData *adt = BKE_animdata_from_id(data_id); + float ctime = (float)scene->r.cfra; // XXX this is bad... ListBase pidlist; PTCacheID *pid; if (G.debug & G_DEBUG) - printf("recalcdata %s\n", ob->id.name+2); + printf("recalcdata %s\n", ob->id.name + 2); if (adt) { /* evaluate drivers */ @@ -2586,9 +2566,9 @@ void object_handle_update(Scene *scene, Object *ob) /* includes all keys and modifiers */ switch (ob->type) { - case OB_MESH: + case OB_MESH: { -#if 0 // XXX, comment for 2.56a release, background wont set 'scene->customdata_mask' +#if 0 // XXX, comment for 2.56a release, background wont set 'scene->customdata_mask' BMEditMesh *em = (ob == scene->obedit) ? BMEdit_FromObject(ob) : NULL; BLI_assert((scene->customdata_mask & CD_MASK_BAREMESH) == CD_MASK_BAREMESH); if (em) { @@ -2598,9 +2578,9 @@ void object_handle_update(Scene *scene, Object *ob) makeDerivedMesh(scene, ob, NULL, scene->customdata_mask, 0); } -#else /* ensure CD_MASK_BAREMESH for now */ +#else /* ensure CD_MASK_BAREMESH for now */ BMEditMesh *em = (ob == scene->obedit) ? BMEdit_FromObject(ob) : NULL; - uint64_t data_mask= scene->customdata_mask | ob->customdata_mask | CD_MASK_BAREMESH; + uint64_t data_mask = scene->customdata_mask | ob->customdata_mask | CD_MASK_BAREMESH; if (em) { makeDerivedMesh(scene, ob, em, data_mask, 0); /* was CD_MASK_BAREMESH */ } @@ -2612,29 +2592,29 @@ void object_handle_update(Scene *scene, Object *ob) } break; - case OB_ARMATURE: - if (ob->id.lib && ob->proxy_from) { - // printf("pose proxy copy, lib ob %s proxy %s\n", ob->id.name, ob->proxy_from->id.name); - copy_pose_result(ob->pose, ob->proxy_from->pose); - } - else { - where_is_pose(scene, ob); - } - break; + case OB_ARMATURE: + if (ob->id.lib && ob->proxy_from) { + // printf("pose proxy copy, lib ob %s proxy %s\n", ob->id.name, ob->proxy_from->id.name); + BKE_pose_copy_result(ob->pose, ob->proxy_from->pose); + } + else { + BKE_pose_where_is(scene, ob); + } + break; - case OB_MBALL: - makeDispListMBall(scene, ob); - break; + case OB_MBALL: + BKE_displist_make_mball(scene, ob); + break; - case OB_CURVE: - case OB_SURF: - case OB_FONT: - makeDispListCurveTypes(scene, ob, 0); - break; + case OB_CURVE: + case OB_SURF: + case OB_FONT: + BKE_displist_make_curveTypes(scene, ob, 0); + break; - case OB_LATTICE: - lattice_calc_modifiers(scene, ob); - break; + case OB_LATTICE: + BKE_lattice_modifiers_calc(scene, ob); + break; } @@ -2643,7 +2623,7 @@ void object_handle_update(Scene *scene, Object *ob) DerivedMesh *dm; ob->transflag &= ~OB_DUPLIPARTS; - psys= ob->particlesystem.first; + psys = ob->particlesystem.first; while (psys) { if (psys_check_enabled(ob, psys)) { /* check use of dupli objects here */ @@ -2655,26 +2635,26 @@ void object_handle_update(Scene *scene, Object *ob) } particle_system_update(scene, ob, psys); - psys= psys->next; + psys = psys->next; } else if (psys->flag & PSYS_DELETE) { - tpsys=psys->next; + tpsys = psys->next; BLI_remlink(&ob->particlesystem, psys); psys_free(ob, psys); - psys= tpsys; + psys = tpsys; } else - psys= psys->next; + psys = psys->next; } if (G.rendering && ob->transflag & OB_DUPLIPARTS) { /* this is to make sure we get render level duplis in groups: * the derivedmesh must be created before init_render_mesh, * since object_duplilist does dupliparticles before that */ - dm = mesh_create_derived_render(scene, ob, CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL); + dm = mesh_create_derived_render(scene, ob, CD_MASK_BAREMESH | CD_MASK_MTFACE | CD_MASK_MCOL); dm->release(dm); - for (psys=ob->particlesystem.first; psys; psys=psys->next) + for (psys = ob->particlesystem.first; psys; psys = psys->next) psys_get_modifier(ob, psys)->flag &= ~eParticleSystemFlag_psys_updated; } } @@ -2682,18 +2662,18 @@ void object_handle_update(Scene *scene, Object *ob) /* check if quick cache is needed */ BKE_ptcache_ids_from_object(&pidlist, ob, scene, MAX_DUPLI_RECUR); - for (pid=pidlist.first; pid; pid=pid->next) { + for (pid = pidlist.first; pid; pid = pid->next) { if ((pid->cache->flag & PTCACHE_BAKED) || (pid->cache->flag & PTCACHE_QUICK_CACHE) == 0) { continue; } - if (pid->cache->flag & PTCACHE_OUTDATED || (pid->cache->flag & PTCACHE_SIMULATION_VALID)==0) { + if (pid->cache->flag & PTCACHE_OUTDATED || (pid->cache->flag & PTCACHE_SIMULATION_VALID) == 0) { scene->physics_settings.quick_cache_step = - scene->physics_settings.quick_cache_step ? - MIN2(scene->physics_settings.quick_cache_step, pid->cache->step) : - pid->cache->step; + scene->physics_settings.quick_cache_step ? + MIN2(scene->physics_settings.quick_cache_step, pid->cache->step) : + pid->cache->step; } } @@ -2701,11 +2681,11 @@ void object_handle_update(Scene *scene, Object *ob) } /* the no-group proxy case, we call update */ - if (ob->proxy && ob->proxy_group==NULL) { + if (ob->proxy && ob->proxy_group == NULL) { /* set pointer in library proxy target, for copying, but restore it */ - ob->proxy->proxy_from= ob; + ob->proxy->proxy_from = ob; // printf("call update, lib ob %s proxy %s\n", ob->proxy->id.name, ob->id.name); - object_handle_update(scene, ob->proxy); + BKE_object_handle_update(scene, ob->proxy); } ob->recalc &= ~OB_RECALC_ALL; @@ -2713,22 +2693,22 @@ void object_handle_update(Scene *scene, Object *ob) /* the case when this is a group proxy, object_update is called in group.c */ if (ob->proxy) { - ob->proxy->proxy_from= ob; + ob->proxy->proxy_from = ob; // printf("set proxy pointer for later group stuff %s\n", ob->id.name); } } -void object_sculpt_modifiers_changed(Object *ob) +void BKE_object_sculpt_modifiers_changed(Object *ob) { - SculptSession *ss= ob->sculpt; + SculptSession *ss = ob->sculpt; if (!ss->cache) { /* we free pbvh on changes, except during sculpt since it can't deal with * changing PVBH node organization, we hope topology does not change in * the meantime .. weak */ if (ss->pbvh) { - BLI_pbvh_free(ss->pbvh); - ss->pbvh= NULL; + BLI_pbvh_free(ss->pbvh); + ss->pbvh = NULL; } free_sculptsession_deformMats(ob->sculpt); @@ -2746,42 +2726,42 @@ void object_sculpt_modifiers_changed(Object *ob) } } -int give_obdata_texspace(Object *ob, short **texflag, float **loc, float **size, float **rot) +int BKE_object_obdata_texspace_get(Object *ob, short **r_texflag, float **r_loc, float **r_size, float **r_rot) { - if (ob->data==NULL) + if (ob->data == NULL) return 0; switch (GS(((ID *)ob->data)->name)) { - case ID_ME: - { - Mesh *me= ob->data; - if (texflag) *texflag = &me->texflag; - if (loc) *loc = me->loc; - if (size) *size = me->size; - if (rot) *rot = me->rot; - break; - } - case ID_CU: - { - Curve *cu= ob->data; - if (texflag) *texflag = &cu->texflag; - if (loc) *loc = cu->loc; - if (size) *size = cu->size; - if (rot) *rot = cu->rot; - break; - } - case ID_MB: - { - MetaBall *mb= ob->data; - if (texflag) *texflag = &mb->texflag; - if (loc) *loc = mb->loc; - if (size) *size = mb->size; - if (rot) *rot = mb->rot; - break; - } - default: - return 0; + case ID_ME: + { + Mesh *me = ob->data; + if (r_texflag) *r_texflag = &me->texflag; + if (r_loc) *r_loc = me->loc; + if (r_size) *r_size = me->size; + if (r_rot) *r_rot = me->rot; + break; + } + case ID_CU: + { + Curve *cu = ob->data; + if (r_texflag) *r_texflag = &cu->texflag; + if (r_loc) *r_loc = cu->loc; + if (r_size) *r_size = cu->size; + if (r_rot) *r_rot = cu->rot; + break; + } + case ID_MB: + { + MetaBall *mb = ob->data; + if (r_texflag) *r_texflag = &mb->texflag; + if (r_loc) *r_loc = mb->loc; + if (r_size) *r_size = mb->size; + if (r_rot) *r_rot = mb->rot; + break; + } + default: + return 0; } return 1; } @@ -2790,7 +2770,7 @@ int give_obdata_texspace(Object *ob, short **texflag, float **loc, float **size, * Test a bounding box for ray intersection * assumes the ray is already local to the boundbox space */ -int ray_hit_boundbox(struct BoundBox *bb, float ray_start[3], float ray_normal[3]) +int BKE_boundbox_ray_hit_check(struct BoundBox *bb, float ray_start[3], float ray_normal[3]) { static int triangle_indexes[12][3] = {{0, 1, 2}, {0, 2, 3}, {3, 2, 6}, {3, 6, 7}, @@ -2821,14 +2801,14 @@ static int pc_cmp(void *a, void *b) else return 0; } -int object_insert_ptcache(Object *ob) +int BKE_object_insert_ptcache(Object *ob) { LinkData *link = NULL; int i = 0; BLI_sortlist(&ob->pc_ids, pc_cmp); - for (link=ob->pc_ids.first, i = 0; link; link=link->next, i++) { + for (link = ob->pc_ids.first, i = 0; link; link = link->next, i++) { int index = GET_INT_FROM_POINTER(link->data); if (i < index) @@ -2845,18 +2825,18 @@ int object_insert_ptcache(Object *ob) #if 0 static int pc_findindex(ListBase *listbase, int index) { - LinkData *link= NULL; - int number= 0; + LinkData *link = NULL; + int number = 0; if (listbase == NULL) return -1; - link= listbase->first; + link = listbase->first; while (link) { if ((int)link->data == index) return number; number++; - link= link->next; + link = link->next; } return -1; @@ -2875,30 +2855,30 @@ void object_delete_ptcache(Object *ob, int index) /************************* Mesh ************************/ static KeyBlock *insert_meshkey(Scene *scene, Object *ob, const char *name, int from_mix) { - Mesh *me= ob->data; - Key *key= me->key; + Mesh *me = ob->data; + Key *key = me->key; KeyBlock *kb; - int newkey= 0; + int newkey = 0; if (key == NULL) { - key= me->key= add_key((ID *)me); - key->type= KEY_RELATIVE; - newkey= 1; + key = me->key = add_key((ID *)me); + key->type = KEY_RELATIVE; + newkey = 1; } - if (newkey || from_mix==FALSE) { + if (newkey || from_mix == FALSE) { /* create from mesh */ kb = add_keyblock_ctime(key, name, FALSE); mesh_to_key(me, kb); } else { /* copy from current values */ - float *data= do_ob_key(scene, ob); + float *data = do_ob_key(scene, ob); /* create new block with prepared data */ kb = add_keyblock_ctime(key, name, FALSE); - kb->data= data; - kb->totelem= me->totvert; + kb->data = data; + kb->totelem = me->totvert; } return kb; @@ -2906,23 +2886,23 @@ static KeyBlock *insert_meshkey(Scene *scene, Object *ob, const char *name, int /************************* Lattice ************************/ static KeyBlock *insert_lattkey(Scene *scene, Object *ob, const char *name, int from_mix) { - Lattice *lt= ob->data; - Key *key= lt->key; + Lattice *lt = ob->data; + Key *key = lt->key; KeyBlock *kb; - int newkey= 0; + int newkey = 0; - if (key==NULL) { - key= lt->key= add_key((ID *)lt); - key->type= KEY_RELATIVE; - newkey= 1; + if (key == NULL) { + key = lt->key = add_key((ID *)lt); + key->type = KEY_RELATIVE; + newkey = 1; } - if (newkey || from_mix==FALSE) { + if (newkey || from_mix == FALSE) { kb = add_keyblock_ctime(key, name, FALSE); if (!newkey) { - KeyBlock *basekb= (KeyBlock *)key->block.first; - kb->data= MEM_dupallocN(basekb->data); - kb->totelem= basekb->totelem; + KeyBlock *basekb = (KeyBlock *)key->block.first; + kb->data = MEM_dupallocN(basekb->data); + kb->totelem = basekb->totelem; } else { latt_to_key(lt, kb); @@ -2930,12 +2910,12 @@ static KeyBlock *insert_lattkey(Scene *scene, Object *ob, const char *name, int } else { /* copy from current values */ - float *data= do_ob_key(scene, ob); + float *data = do_ob_key(scene, ob); /* create new block with prepared data */ kb = add_keyblock_ctime(key, name, FALSE); - kb->totelem= lt->pntsu*lt->pntsv*lt->pntsw; - kb->data= data; + kb->totelem = lt->pntsu * lt->pntsv * lt->pntsw; + kb->data = data; } return kb; @@ -2943,25 +2923,25 @@ static KeyBlock *insert_lattkey(Scene *scene, Object *ob, const char *name, int /************************* Curve ************************/ static KeyBlock *insert_curvekey(Scene *scene, Object *ob, const char *name, int from_mix) { - Curve *cu= ob->data; - Key *key= cu->key; + Curve *cu = ob->data; + Key *key = cu->key; KeyBlock *kb; - ListBase *lb= BKE_curve_nurbs_get(cu); - int newkey= 0; + ListBase *lb = BKE_curve_nurbs_get(cu); + int newkey = 0; - if (key==NULL) { - key= cu->key= add_key((ID *)cu); + if (key == NULL) { + key = cu->key = add_key((ID *)cu); key->type = KEY_RELATIVE; - newkey= 1; + newkey = 1; } - if (newkey || from_mix==FALSE) { + if (newkey || from_mix == FALSE) { /* create from curve */ kb = add_keyblock_ctime(key, name, FALSE); if (!newkey) { - KeyBlock *basekb= (KeyBlock *)key->block.first; - kb->data= MEM_dupallocN(basekb->data); - kb->totelem= basekb->totelem; + KeyBlock *basekb = (KeyBlock *)key->block.first; + kb->data = MEM_dupallocN(basekb->data); + kb->totelem = basekb->totelem; } else { curve_to_key(cu, kb, lb); @@ -2969,18 +2949,18 @@ static KeyBlock *insert_curvekey(Scene *scene, Object *ob, const char *name, int } else { /* copy from current values */ - float *data= do_ob_key(scene, ob); + float *data = do_ob_key(scene, ob); /* create new block with prepared data */ kb = add_keyblock_ctime(key, name, FALSE); - kb->totelem= BKE_nurbList_verts_count(lb); - kb->data= data; + kb->totelem = BKE_nurbList_verts_count(lb); + kb->data = data; } return kb; } -KeyBlock *object_insert_shape_key(Scene *scene, Object *ob, const char *name, int from_mix) +KeyBlock *BKE_object_insert_shape_key(Scene *scene, Object *ob, const char *name, int from_mix) { switch (ob->type) { case OB_MESH: @@ -2998,9 +2978,9 @@ KeyBlock *object_insert_shape_key(Scene *scene, Object *ob, const char *name, in /* most important if this is modified it should _always_ return True, in certain * cases false positives are hard to avoid (shape keys for example) */ -int object_is_modified(Scene *scene, Object *ob) +int BKE_object_is_modified(Scene *scene, Object *ob) { - int flag= 0; + int flag = 0; if (ob_get_key(ob)) { flag |= eModifierMode_Render; @@ -3008,9 +2988,9 @@ int object_is_modified(Scene *scene, Object *ob) else { ModifierData *md; /* cloth */ - for (md=modifiers_getVirtualModifierList(ob); + for (md = modifiers_getVirtualModifierList(ob); md && (flag != (eModifierMode_Render | eModifierMode_Realtime)); - md=md->next) + md = md->next) { if ((flag & eModifierMode_Render) == 0 && modifier_isEnabled(scene, md, eModifierMode_Render)) flag |= eModifierMode_Render; @@ -3026,15 +3006,15 @@ int object_is_modified(Scene *scene, Object *ob) /* test if object is affected by deforming modifiers (for motion blur). again * most important is to avoid false positives, this is to skip computations * and we can still if there was actual deformation afterwards */ -int object_is_deform_modified(Scene *scene, Object *ob) +int BKE_object_is_deform_modified(Scene *scene, Object *ob) { ModifierData *md; - int flag= 0; + int flag = 0; /* cloth */ - for (md=modifiers_getVirtualModifierList(ob); - md && (flag != (eModifierMode_Render | eModifierMode_Realtime)); - md=md->next) + for (md = modifiers_getVirtualModifierList(ob); + md && (flag != (eModifierMode_Render | eModifierMode_Realtime)); + md = md->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); @@ -3056,7 +3036,7 @@ static void copy_object__forwardModifierLinks(void *UNUSED(userData), Object *UN if (*idpoin && (*idpoin)->newid) *idpoin = (*idpoin)->newid; } -void object_relink(Object *ob) +void BKE_object_relink(Object *ob) { if (ob->id.lib) return; @@ -3064,7 +3044,7 @@ void object_relink(Object *ob) relink_constraints(&ob->constraints); if (ob->pose) { bPoseChannel *chan; - for (chan = ob->pose->chanbase.first; chan; chan=chan->next) { + for (chan = ob->pose->chanbase.first; chan; chan = chan->next) { relink_constraints(&chan->constraints); } } @@ -3079,26 +3059,26 @@ void object_relink(Object *ob) ID_NEW(ob->proxy_group); } -MovieClip *object_get_movieclip(Scene *scene, Object *ob, int use_default) +MovieClip *BKE_object_movieclip_get(Scene *scene, Object *ob, int use_default) { - MovieClip *clip= use_default ? scene->clip : NULL; - bConstraint *con= ob->constraints.first, *scon= NULL; + MovieClip *clip = use_default ? scene->clip : NULL; + bConstraint *con = ob->constraints.first, *scon = NULL; while (con) { - if (con->type==CONSTRAINT_TYPE_CAMERASOLVER) { - if (scon==NULL || (scon->flag&CONSTRAINT_OFF)) - scon= con; + if (con->type == CONSTRAINT_TYPE_CAMERASOLVER) { + if (scon == NULL || (scon->flag & CONSTRAINT_OFF)) + scon = con; } - con= con->next; + con = con->next; } if (scon) { - bCameraSolverConstraint *solver= scon->data; - if ((solver->flag&CAMERASOLVER_ACTIVECLIP)==0) - clip= solver->clip; + bCameraSolverConstraint *solver = scon->data; + if ((solver->flag & CAMERASOLVER_ACTIVECLIP) == 0) + clip = solver->clip; else - clip= scene->clip; + clip = scene->clip; } return clip; diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c index 4ddcd6f4b51..6242976d323 100644 --- a/source/blender/blenkernel/intern/ocean.c +++ b/source/blender/blenkernel/intern/ocean.c @@ -1251,18 +1251,18 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v /* write the images */ cache_filename(string, och->bakepath, och->relbase, f, CACHE_TYPE_DISPLACE); - if (0 == BKE_write_ibuf(ibuf_disp, string, &imf)) + if (0 == BKE_imbuf_write(ibuf_disp, string, &imf)) printf("Cannot save Displacement File Output to %s\n", string); if (o->_do_jacobian) { cache_filename(string, och->bakepath, och->relbase, f, CACHE_TYPE_FOAM); - if (0 == BKE_write_ibuf(ibuf_foam, string, &imf)) + if (0 == BKE_imbuf_write(ibuf_foam, string, &imf)) printf("Cannot save Foam File Output to %s\n", string); } if (o->_do_normals) { cache_filename(string, och->bakepath, och->relbase, f, CACHE_TYPE_NORMAL); - if (0 == BKE_write_ibuf(ibuf_normal, string, &imf)) + if (0 == BKE_imbuf_write(ibuf_normal, string, &imf)) printf("Cannot save Normal File Output to %s\n", string); } diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c index 3b5b4b766fb..a2c89967f44 100644 --- a/source/blender/blenkernel/intern/packedFile.c +++ b/source/blender/blenkernel/intern/packedFile.c @@ -73,17 +73,17 @@ int seekPackedFile(PackedFile *pf, int offset, int whence) if (pf) { oldseek = pf->seek; switch (whence) { - case SEEK_CUR: - seek = oldseek + offset; - break; - case SEEK_END: - seek = pf->size + offset; - break; - case SEEK_SET: - seek = offset; - break; - default: - oldseek = -1; + case SEEK_CUR: + seek = oldseek + offset; + break; + case SEEK_END: + seek = pf->size + offset; + break; + case SEEK_SET: + seek = offset; + break; + default: + oldseek = -1; } if (seek < 0) { seek = 0; @@ -133,15 +133,15 @@ int countPackedFiles(Main *bmain) int count = 0; // let's check if there are packed files... - for (ima=bmain->image.first; ima; ima=ima->id.next) + for (ima = bmain->image.first; ima; ima = ima->id.next) if (ima->packedfile) count++; - for (vf=bmain->vfont.first; vf; vf=vf->id.next) + for (vf = bmain->vfont.first; vf; vf = vf->id.next) if (vf->packedfile) count++; - for (sound=bmain->sound.first; sound; sound=sound->id.next) + for (sound = bmain->sound.first; sound; sound = sound->id.next) if (sound->packedfile) count++; @@ -176,7 +176,7 @@ PackedFile *newPackedFile(ReportList *reports, const char *filename, const char /* render result has no filename and can be ignored * any other files with no name can be ignored too */ - if (filename[0]=='\0') + if (filename[0] == '\0') return NULL; //XXX waitcursor(1); @@ -189,7 +189,7 @@ PackedFile *newPackedFile(ReportList *reports, const char *filename, const char // open the file // and create a PackedFile structure - file= BLI_open(name, O_BINARY|O_RDONLY, 0); + file = BLI_open(name, O_BINARY | O_RDONLY, 0); if (file <= 0) { BKE_reportf(reports, RPT_ERROR, "Unable to pack file, source path not found: \"%s\"", name); } @@ -222,23 +222,23 @@ void packAll(Main *bmain, ReportList *reports) VFont *vf; bSound *sound; - for (ima=bmain->image.first; ima; ima=ima->id.next) { - if (ima->packedfile == NULL && ima->id.lib==NULL) { - if (ima->source==IMA_SRC_FILE) { + for (ima = bmain->image.first; ima; ima = ima->id.next) { + if (ima->packedfile == NULL && ima->id.lib == NULL) { + if (ima->source == IMA_SRC_FILE) { ima->packedfile = newPackedFile(reports, ima->name, ID_BLEND_PATH(bmain, &ima->id)); } else if (ELEM(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) { - BKE_reportf(reports, RPT_WARNING, "Image '%s' skipped, movies and image sequences not supported.", ima->id.name+2); + BKE_reportf(reports, RPT_WARNING, "Image '%s' skipped, movies and image sequences not supported.", ima->id.name + 2); } } } - for (vf=bmain->vfont.first; vf; vf=vf->id.next) - if (vf->packedfile == NULL && vf->id.lib==NULL && strcmp(vf->name, FO_BUILTIN_NAME) != 0) + for (vf = bmain->vfont.first; vf; vf = vf->id.next) + if (vf->packedfile == NULL && vf->id.lib == NULL && strcmp(vf->name, FO_BUILTIN_NAME) != 0) vf->packedfile = newPackedFile(reports, vf->name, bmain->name); - for (sound=bmain->sound.first; sound; sound=sound->id.next) - if (sound->packedfile == NULL && sound->id.lib==NULL) + for (sound = bmain->sound.first; sound; sound = sound->id.next) + if (sound->packedfile == NULL && sound->id.lib == NULL) sound->packedfile = newPackedFile(reports, sound->name, bmain->name); } @@ -257,12 +257,12 @@ static char *find_new_name(char *name) if (fop_exists(name)) { for (number = 1; number <= 999; number++) { BLI_snprintf(tempname, sizeof(tempname), "%s.%03d", name, number); - if (! fop_exists(tempname)) { + if (!fop_exists(tempname)) { break; } } } - len= strlen(tempname) + 1; + len = strlen(tempname) + 1; newname = MEM_mallocN(len, "find_new_name"); memcpy(newname, tempname, len * sizeof(char)); return newname; @@ -275,7 +275,7 @@ int writePackedFile(ReportList *reports, const char *filename, PackedFile *pf, i int ret_value = RET_OK; char name[FILE_MAX]; char tempname[FILE_MAX]; -/* void *data; */ +/* void *data; */ if (guimode) {} //XXX waitcursor(1); @@ -285,7 +285,7 @@ int writePackedFile(ReportList *reports, const char *filename, PackedFile *pf, i if (BLI_exists(name)) { for (number = 1; number <= 999; number++) { BLI_snprintf(tempname, sizeof(tempname), "%s.%03d_", name, number); - if (! BLI_exists(tempname)) { + if (!BLI_exists(tempname)) { if (BLI_copy(name, tempname) == RET_OK) { remove_tmp = TRUE; } @@ -409,7 +409,7 @@ char *unpackFile(ReportList *reports, const char *abs_name, const char *local_na case PF_KEEP: break; case PF_REMOVE: - temp= abs_name; + temp = abs_name; break; case PF_USE_LOCAL: // if file exists use it @@ -417,7 +417,7 @@ char *unpackFile(ReportList *reports, const char *abs_name, const char *local_na temp = local_name; break; } - // else fall through and create it + // else fall through and create it case PF_WRITE_LOCAL: if (writePackedFile(reports, local_name, pf, 1) == RET_OK) { temp = local_name; @@ -429,7 +429,7 @@ char *unpackFile(ReportList *reports, const char *abs_name, const char *local_na temp = abs_name; break; } - // else fall through and create it + // else fall through and create it case PF_WRITE_ORIGINAL: if (writePackedFile(reports, abs_name, pf, 1) == RET_OK) { temp = abs_name; @@ -441,7 +441,7 @@ char *unpackFile(ReportList *reports, const char *abs_name, const char *local_na } if (temp) { - newname= BLI_strdup(temp); + newname = BLI_strdup(temp); } } @@ -533,15 +533,15 @@ void unpackAll(Main *bmain, ReportList *reports, int how) VFont *vf; bSound *sound; - for (ima=bmain->image.first; ima; ima=ima->id.next) + for (ima = bmain->image.first; ima; ima = ima->id.next) if (ima->packedfile) unpackImage(reports, ima, how); - for (vf=bmain->vfont.first; vf; vf=vf->id.next) + for (vf = bmain->vfont.first; vf; vf = vf->id.next) if (vf->packedfile) unpackVFont(reports, vf, how); - for (sound=bmain->sound.first; sound; sound=sound->id.next) + for (sound = bmain->sound.first; sound; sound = sound->id.next) if (sound->packedfile) unpackSound(bmain, reports, sound, how); } diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 08d8479fd93..c7f904755d9 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -60,19 +60,19 @@ Paint *paint_get_active(Scene *sce) if (sce->basact && sce->basact->object) { switch (sce->basact->object->mode) { - case OB_MODE_SCULPT: - return &ts->sculpt->paint; - case OB_MODE_VERTEX_PAINT: - return &ts->vpaint->paint; - case OB_MODE_WEIGHT_PAINT: - return &ts->wpaint->paint; - case OB_MODE_TEXTURE_PAINT: - return &ts->imapaint.paint; - case OB_MODE_EDIT: - if (ts->use_uv_sculpt) - return &ts->uvsculpt->paint; - else + case OB_MODE_SCULPT: + return &ts->sculpt->paint; + case OB_MODE_VERTEX_PAINT: + return &ts->vpaint->paint; + case OB_MODE_WEIGHT_PAINT: + return &ts->wpaint->paint; + case OB_MODE_TEXTURE_PAINT: return &ts->imapaint.paint; + case OB_MODE_EDIT: + if (ts->use_uv_sculpt) + return &ts->uvsculpt->paint; + else + return &ts->imapaint.paint; } } @@ -93,7 +93,7 @@ void paint_brush_set(Paint *p, Brush *br) if (p) { id_us_min((ID *)p->brush); id_us_plus((ID *)br); - p->brush= br; + p->brush = br; } } @@ -104,7 +104,7 @@ int paint_facesel_test(Object *ob) (ob->type == OB_MESH) && (ob->data != NULL) && (((Mesh *)ob->data)->editflag & ME_EDIT_PAINT_MASK) && - (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT)) + (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) ); } @@ -126,7 +126,7 @@ void paint_init(Paint *p, const char col[3]) /* If there's no brush, create one */ brush = paint_brush(p); if (brush == NULL) - brush= BKE_brush_add("Brush"); + brush = BKE_brush_add("Brush"); paint_brush_set(p, brush); memcpy(p->paint_cursor_col, col, 3); @@ -146,7 +146,7 @@ void free_paint(Paint *paint) * with paint_brush_set() */ void copy_paint(Paint *src, Paint *tar) { - tar->brush= src->brush; + tar->brush = src->brush; id_us_plus((ID *)tar->brush); } @@ -155,20 +155,29 @@ void copy_paint(Paint *src, Paint *tar) int paint_is_face_hidden(const MFace *f, const MVert *mvert) { return ((mvert[f->v1].flag & ME_HIDE) || - (mvert[f->v2].flag & ME_HIDE) || - (mvert[f->v3].flag & ME_HIDE) || - (f->v4 && (mvert[f->v4].flag & ME_HIDE))); + (mvert[f->v2].flag & ME_HIDE) || + (mvert[f->v3].flag & ME_HIDE) || + (f->v4 && (mvert[f->v4].flag & ME_HIDE))); } /* returns non-zero if any of the corners of the grid * face whose inner corner is at (x,y) are hidden, * zero otherwise */ int paint_is_grid_face_hidden(const unsigned int *grid_hidden, - int gridsize, int x, int y) + int gridsize, int x, int y) { /* skip face if any of its corners are hidden */ return (BLI_BITMAP_GET(grid_hidden, y * gridsize + x) || - BLI_BITMAP_GET(grid_hidden, y * gridsize + x+1) || - BLI_BITMAP_GET(grid_hidden, (y+1) * gridsize + x+1) || - BLI_BITMAP_GET(grid_hidden, (y+1) * gridsize + x)); + BLI_BITMAP_GET(grid_hidden, y * gridsize + x + 1) || + BLI_BITMAP_GET(grid_hidden, (y + 1) * gridsize + x + 1) || + BLI_BITMAP_GET(grid_hidden, (y + 1) * gridsize + x)); +} + +float paint_grid_paint_mask(const GridPaintMask *gpm, unsigned level, + unsigned x, unsigned y) +{ + int factor = ccg_factor(level, gpm->level); + int gridsize = ccg_gridsize(gpm->level); + + return gpm->data[(y * factor) * gridsize + (x * factor)]; } diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 1a1ae8e949c..8676a3e75a0 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -84,35 +84,35 @@ #include "RE_render_ext.h" static void get_child_modifier_parameters(ParticleSettings *part, ParticleThreadContext *ctx, - ChildParticle *cpa, short cpa_from, int cpa_num, float *cpa_fuv, float *orco, ParticleTexture *ptex); + ChildParticle *cpa, short cpa_from, int cpa_num, float *cpa_fuv, float *orco, ParticleTexture *ptex); static void do_child_modifiers(ParticleSimulationData *sim, - ParticleTexture *ptex, ParticleKey *par, float *par_rot, ChildParticle *cpa, - float *orco, float mat[4][4], ParticleKey *state, float t); + ParticleTexture *ptex, ParticleKey *par, float *par_rot, ChildParticle *cpa, + float *orco, float mat[4][4], ParticleKey *state, float t); /* few helpers for countall etc. */ int count_particles(ParticleSystem *psys) { - ParticleSettings *part=psys->part; + ParticleSettings *part = psys->part; PARTICLE_P; - int tot=0; + int tot = 0; LOOP_SHOWN_PARTICLES { - if (pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN)==0); - else if (pa->alive == PARS_DEAD && (part->flag & PART_DIED)==0); + if (pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN) == 0) ; + else if (pa->alive == PARS_DEAD && (part->flag & PART_DIED) == 0) ; else tot++; } return tot; } int count_particles_mod(ParticleSystem *psys, int totgr, int cur) { - ParticleSettings *part=psys->part; + ParticleSettings *part = psys->part; PARTICLE_P; - int tot=0; + int tot = 0; LOOP_SHOWN_PARTICLES { - if (pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN)==0); - else if (pa->alive == PARS_DEAD && (part->flag & PART_DIED)==0); - else if (p%totgr==cur) tot++; + if (pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN) == 0) ; + else if (pa->alive == PARS_DEAD && (part->flag & PART_DIED) == 0) ; + else if (p % totgr == cur) tot++; } return tot; } @@ -127,17 +127,17 @@ static ParticleCacheKey **psys_alloc_path_cache_buffers(ListBase *bufs, int tot, ParticleCacheKey **cache; int i, totkey, totbufkey; - tot= MAX2(tot, 1); + tot = MAX2(tot, 1); totkey = 0; - cache = MEM_callocN(tot*sizeof(void*), "PathCacheArray"); + cache = MEM_callocN(tot * sizeof(void *), "PathCacheArray"); while (totkey < tot) { - totbufkey= MIN2(tot-totkey, PATH_CACHE_BUF_SIZE); - buf= MEM_callocN(sizeof(LinkData), "PathCacheLinkData"); - buf->data= MEM_callocN(sizeof(ParticleCacheKey)*totbufkey*steps, "ParticleCacheKey"); + totbufkey = MIN2(tot - totkey, PATH_CACHE_BUF_SIZE); + buf = MEM_callocN(sizeof(LinkData), "PathCacheLinkData"); + buf->data = MEM_callocN(sizeof(ParticleCacheKey) * totbufkey * steps, "ParticleCacheKey"); - for (i=0; i<totbufkey; i++) - cache[totkey+i] = ((ParticleCacheKey*)buf->data) + i*steps; + for (i = 0; i < totbufkey; i++) + cache[totkey + i] = ((ParticleCacheKey *)buf->data) + i * steps; totkey += totbufkey; BLI_addtail(bufs, buf); @@ -153,7 +153,7 @@ static void psys_free_path_cache_buffers(ParticleCacheKey **cache, ListBase *buf if (cache) MEM_freeN(cache); - for (buf= bufs->first; buf; buf=buf->next) + for (buf = bufs->first; buf; buf = buf->next) MEM_freeN(buf->data); BLI_freelistN(bufs); } @@ -165,9 +165,9 @@ static void psys_free_path_cache_buffers(ParticleCacheKey **cache, ListBase *buf ParticleSystem *psys_get_current(Object *ob) { ParticleSystem *psys; - if (ob==NULL) return NULL; + if (ob == NULL) return NULL; - for (psys=ob->particlesystem.first; psys; psys=psys->next) { + for (psys = ob->particlesystem.first; psys; psys = psys->next) { if (psys->flag & PSYS_CURRENT) return psys; } @@ -179,9 +179,9 @@ short psys_get_current_num(Object *ob) ParticleSystem *psys; short i; - if (ob==NULL) return 0; + if (ob == NULL) return 0; - for (psys=ob->particlesystem.first, i=0; psys; psys=psys->next, i++) + for (psys = ob->particlesystem.first, i = 0; psys; psys = psys->next, i++) if (psys->flag & PSYS_CURRENT) return i; @@ -192,9 +192,9 @@ void psys_set_current_num(Object *ob, int index) ParticleSystem *psys; short i; - if (ob==NULL) return; + if (ob == NULL) return; - for (psys=ob->particlesystem.first, i=0; psys; psys=psys->next, i++) { + for (psys = ob->particlesystem.first, i = 0; psys; psys = psys->next, i++) { if (i == index) psys->flag |= PSYS_CURRENT; else @@ -209,7 +209,7 @@ Object *psys_find_object(Scene *scene, ParticleSystem *psys) ParticleSystem *tpsys; for (base = scene->base.first; base; base = base->next) { - for (tpsys = base->object->particlesystem.first; psys; psys=psys->next) { + for (tpsys = base->object->particlesystem.first; psys; psys = psys->next) { if (tpsys == psys) return base->object; } @@ -221,16 +221,16 @@ Object *psys_find_object(Scene *scene, ParticleSystem *psys) Object *psys_get_lattice(ParticleSimulationData *sim) { - Object *lattice=NULL; + Object *lattice = NULL; - if (psys_in_edit_mode(sim->scene, sim->psys)==0) { + if (psys_in_edit_mode(sim->scene, sim->psys) == 0) { - ModifierData *md = (ModifierData*)psys_get_modifier(sim->ob, sim->psys); + ModifierData *md = (ModifierData *)psys_get_modifier(sim->ob, sim->psys); - for (; md; md=md->next) { - if (md->type==eModifierType_Lattice) { + for (; md; md = md->next) { + if (md->type == eModifierType_Lattice) { LatticeModifierData *lmd = (LatticeModifierData *)md; - lattice=lmd->object; + lattice = lmd->object; break; } } @@ -242,21 +242,21 @@ Object *psys_get_lattice(ParticleSimulationData *sim) } void psys_disable_all(Object *ob) { - ParticleSystem *psys=ob->particlesystem.first; + ParticleSystem *psys = ob->particlesystem.first; - for (; psys; psys=psys->next) + for (; psys; psys = psys->next) psys->flag |= PSYS_DISABLED; } void psys_enable_all(Object *ob) { - ParticleSystem *psys=ob->particlesystem.first; + ParticleSystem *psys = ob->particlesystem.first; - for (; psys; psys=psys->next) + for (; psys; psys = psys->next) psys->flag &= ~PSYS_DISABLED; } int psys_in_edit_mode(Scene *scene, ParticleSystem *psys) { - return (scene->basact && (scene->basact->object->mode & OB_MODE_PARTICLE_EDIT) && psys==psys_get_current((scene->basact)->object) && (psys->edit || psys->pointcache->edit) && !psys->renderdata); + return (scene->basact && (scene->basact->object->mode & OB_MODE_PARTICLE_EDIT) && psys == psys_get_current((scene->basact)->object) && (psys->edit || psys->pointcache->edit) && !psys->renderdata); } static void psys_create_frand(ParticleSystem *psys) { @@ -265,7 +265,7 @@ static void psys_create_frand(ParticleSystem *psys) BLI_srandom(psys->seed); - for (i=0; i<1024; i++, rand++) + for (i = 0; i < 1024; i++, rand++) *rand = BLI_frand(); } int psys_check_enabled(Object *ob, ParticleSystem *psys) @@ -275,7 +275,7 @@ int psys_check_enabled(Object *ob, ParticleSystem *psys) if (psys->flag & PSYS_DISABLED || psys->flag & PSYS_DELETE || !psys->part) return 0; - psmd= psys_get_modifier(ob, psys); + psmd = psys_get_modifier(ob, psys); if (psys->renderdata || G.rendering) { if (!(psmd->modifier.mode & eModifierMode_Render)) return 0; @@ -296,7 +296,7 @@ int psys_check_enabled(Object *ob, ParticleSystem *psys) int psys_check_edited(ParticleSystem *psys) { - if (psys->part && psys->part->type==PART_HAIR) + if (psys->part && psys->part->type == PART_HAIR) return (psys->flag & PSYS_EDITED || (psys->edit && psys->edit->edited)); else return (psys->pointcache->edit && psys->pointcache->edit->edited); @@ -339,7 +339,7 @@ void psys_check_group_weights(ParticleSettings *part) } dw = part->dupliweights.first; - for (; dw; dw=dw->next) { + for (; dw; dw = dw->next) { if (dw->flag & PART_DUPLIW_CURRENT) { current = 1; break; @@ -369,7 +369,7 @@ static void fluid_free_settings(SPHFluidSettings *fluid) MEM_freeN(fluid); } -void psys_free_settings(ParticleSettings *part) +void BKE_particlesettings_free(ParticleSettings *part) { MTex *mtex; int a; @@ -385,8 +385,8 @@ void psys_free_settings(ParticleSettings *part) boid_free_settings(part->boids); fluid_free_settings(part->fluid); - for (a=0; a<MAX_MTEX; a++) { - mtex= part->mtex[a]; + for (a = 0; a < MAX_MTEX; a++) { + mtex = part->mtex[a]; if (mtex && mtex->tex) mtex->tex->id.us--; if (mtex) MEM_freeN(mtex); } @@ -411,7 +411,7 @@ void free_hair(Object *UNUSED(ob), ParticleSystem *psys, int dynamics) psys->clmd->point_cache = psys->pointcache = NULL; psys->clmd->ptcaches.first = psys->clmd->ptcaches.last = NULL; - modifier_free((ModifierData*)psys->clmd); + modifier_free((ModifierData *)psys->clmd); psys->clmd = NULL; psys->pointcache = BKE_ptcache_add(&psys->ptcaches); @@ -441,8 +441,8 @@ void free_keyed_keys(ParticleSystem *psys) LOOP_PARTICLES { if (pa->keys) { - pa->keys= NULL; - pa->totkey= 0; + pa->keys = NULL; + pa->totkey = 0; } } } @@ -457,13 +457,13 @@ void psys_free_path_cache(ParticleSystem *psys, PTCacheEdit *edit) { if (edit) { psys_free_path_cache_buffers(edit->pathcache, &edit->pathcachebufs); - edit->pathcache= NULL; - edit->totcached= 0; + edit->pathcache = NULL; + edit->totcached = 0; } if (psys) { psys_free_path_cache_buffers(psys->pathcache, &psys->pathcachebufs); - psys->pathcache= NULL; - psys->totcached= 0; + psys->pathcache = NULL; + psys->totcached = 0; free_child_path_cache(psys); } @@ -472,8 +472,8 @@ void psys_free_children(ParticleSystem *psys) { if (psys->child) { MEM_freeN(psys->child); - psys->child= NULL; - psys->totchild=0; + psys->child = NULL; + psys->totchild = 0; } free_child_path_cache(psys); @@ -483,7 +483,7 @@ void psys_free_particles(ParticleSystem *psys) PARTICLE_P; if (psys->particles) { - if (psys->part->type==PART_HAIR) { + if (psys->part->type == PART_HAIR) { LOOP_PARTICLES { if (pa->hair) MEM_freeN(pa->hair); @@ -497,8 +497,8 @@ void psys_free_particles(ParticleSystem *psys) MEM_freeN(psys->particles->boid); MEM_freeN(psys->particles); - psys->particles= NULL; - psys->totpart= 0; + psys->particles = NULL; + psys->totpart = 0; } } void psys_free_pdd(ParticleSystem *psys) @@ -525,11 +525,11 @@ void psys_free_pdd(ParticleSystem *psys) } } /* free everything */ -void psys_free(Object *ob, ParticleSystem * psys) +void psys_free(Object *ob, ParticleSystem *psys) { if (psys) { int nr = 0; - ParticleSystem * tpsys; + ParticleSystem *tpsys; psys_free_path_cache(psys, NULL); @@ -547,7 +547,7 @@ void psys_free(Object *ob, ParticleSystem * psys) } // check if we are last non-visible particle system - for (tpsys=ob->particlesystem.first; tpsys; tpsys=tpsys->next) { + for (tpsys = ob->particlesystem.first; tpsys; tpsys = tpsys->next) { if (tpsys->part) { if (ELEM(tpsys->part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) { nr++; @@ -561,7 +561,7 @@ void psys_free(Object *ob, ParticleSystem * psys) if (psys->part) { psys->part->id.us--; - psys->part=NULL; + psys->part = NULL; } BKE_ptcache_free_list(&psys->ptcaches); @@ -622,17 +622,17 @@ typedef struct ParticleRenderData { static float psys_render_viewport_falloff(double rate, float dist, float width) { - return pow(rate, dist/width); + return pow(rate, dist / width); } static float psys_render_projected_area(ParticleSystem *psys, const float center[3], float area, double vprate, float *viewport) { - ParticleRenderData *data= psys->renderdata; + ParticleRenderData *data = psys->renderdata; float co[4], view[3], ortho1[3], ortho2[3], w, dx, dy, radius; /* transform to view space */ copy_v3_v3(co, center); - co[3]= 1.0f; + co[3] = 1.0f; mul_m4_v4(data->viewmat, co); /* compute two vectors orthogonal to view vector */ @@ -640,87 +640,87 @@ static float psys_render_projected_area(ParticleSystem *psys, const float center ortho_basis_v3v3_v3(ortho1, ortho2, view); /* compute on screen minification */ - w= co[2]*data->winmat[2][3] + data->winmat[3][3]; - dx= data->winx*ortho2[0]*data->winmat[0][0]; - dy= data->winy*ortho2[1]*data->winmat[1][1]; - w= sqrtf(dx*dx + dy*dy)/w; + w = co[2] * data->winmat[2][3] + data->winmat[3][3]; + dx = data->winx * ortho2[0] * data->winmat[0][0]; + dy = data->winy * ortho2[1] * data->winmat[1][1]; + w = sqrtf(dx * dx + dy * dy) / w; /* w squared because we are working with area */ - area= area*w*w; + area = area * w * w; /* viewport of the screen test */ /* project point on screen */ mul_m4_v4(data->winmat, co); if (co[3] != 0.0f) { - co[0]= 0.5f*data->winx*(1.0f + co[0]/co[3]); - co[1]= 0.5f*data->winy*(1.0f + co[1]/co[3]); + co[0] = 0.5f * data->winx * (1.0f + co[0] / co[3]); + co[1] = 0.5f * data->winy * (1.0f + co[1] / co[3]); } /* screen space radius */ - radius= sqrt(area/(float)M_PI); + radius = sqrt(area / (float)M_PI); /* make smaller using fallof once over screen edge */ - *viewport= 1.0f; + *viewport = 1.0f; - if (co[0]+radius < 0.0f) - *viewport *= psys_render_viewport_falloff(vprate, -(co[0]+radius), data->winx); - else if (co[0]-radius > data->winx) - *viewport *= psys_render_viewport_falloff(vprate, (co[0]-radius) - data->winx, data->winx); + if (co[0] + radius < 0.0f) + *viewport *= psys_render_viewport_falloff(vprate, -(co[0] + radius), data->winx); + else if (co[0] - radius > data->winx) + *viewport *= psys_render_viewport_falloff(vprate, (co[0] - radius) - data->winx, data->winx); - if (co[1]+radius < 0.0f) - *viewport *= psys_render_viewport_falloff(vprate, -(co[1]+radius), data->winy); - else if (co[1]-radius > data->winy) - *viewport *= psys_render_viewport_falloff(vprate, (co[1]-radius) - data->winy, data->winy); + if (co[1] + radius < 0.0f) + *viewport *= psys_render_viewport_falloff(vprate, -(co[1] + radius), data->winy); + else if (co[1] - radius > data->winy) + *viewport *= psys_render_viewport_falloff(vprate, (co[1] - radius) - data->winy, data->winy); return area; } void psys_render_set(Object *ob, ParticleSystem *psys, float viewmat[][4], float winmat[][4], int winx, int winy, int timeoffset) { - ParticleRenderData*data; - ParticleSystemModifierData *psmd= psys_get_modifier(ob, psys); + ParticleRenderData *data; + ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys); if (!G.rendering) return; if (psys->renderdata) return; - data= MEM_callocN(sizeof(ParticleRenderData), "ParticleRenderData"); + data = MEM_callocN(sizeof(ParticleRenderData), "ParticleRenderData"); - data->child= psys->child; - data->totchild= psys->totchild; - data->pathcache= psys->pathcache; + data->child = psys->child; + data->totchild = psys->totchild; + data->pathcache = psys->pathcache; data->pathcachebufs.first = psys->pathcachebufs.first; data->pathcachebufs.last = psys->pathcachebufs.last; - data->totcached= psys->totcached; - data->childcache= psys->childcache; + data->totcached = psys->totcached; + data->childcache = psys->childcache; data->childcachebufs.first = psys->childcachebufs.first; data->childcachebufs.last = psys->childcachebufs.last; - data->totchildcache= psys->totchildcache; + data->totchildcache = psys->totchildcache; if (psmd->dm) - data->dm= CDDM_copy(psmd->dm); - data->totdmvert= psmd->totdmvert; - data->totdmedge= psmd->totdmedge; - data->totdmface= psmd->totdmface; - - psys->child= NULL; - psys->pathcache= NULL; - psys->childcache= NULL; - psys->totchild= psys->totcached= psys->totchildcache= 0; + data->dm = CDDM_copy(psmd->dm); + data->totdmvert = psmd->totdmvert; + data->totdmedge = psmd->totdmedge; + data->totdmface = psmd->totdmface; + + psys->child = NULL; + psys->pathcache = NULL; + psys->childcache = NULL; + psys->totchild = psys->totcached = psys->totchildcache = 0; psys->pathcachebufs.first = psys->pathcachebufs.last = NULL; psys->childcachebufs.first = psys->childcachebufs.last = NULL; copy_m4_m4(data->winmat, winmat); mult_m4_m4m4(data->viewmat, viewmat, ob->obmat); mult_m4_m4m4(data->mat, winmat, data->viewmat); - data->winx= winx; - data->winy= winy; + data->winx = winx; + data->winy = winy; - data->timeoffset= timeoffset; + data->timeoffset = timeoffset; - psys->renderdata= data; + psys->renderdata = data; /* Hair can and has to be recalculated if everything isn't displayed. */ if (psys->part->disp != 100 && psys->part->type == PART_HAIR) @@ -729,10 +729,10 @@ void psys_render_set(Object *ob, ParticleSystem *psys, float viewmat[][4], float void psys_render_restore(Object *ob, ParticleSystem *psys) { - ParticleRenderData*data; - ParticleSystemModifierData *psmd= psys_get_modifier(ob, psys); + ParticleRenderData *data; + ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys); - data= psys->renderdata; + data = psys->renderdata; if (!data) return; @@ -740,7 +740,7 @@ void psys_render_restore(Object *ob, ParticleSystem *psys) MEM_freeN(data->elems); if (psmd->dm) { - psmd->dm->needsFree= 1; + psmd->dm->needsFree = 1; psmd->dm->release(psmd->dm); } @@ -748,93 +748,93 @@ void psys_render_restore(Object *ob, ParticleSystem *psys) if (psys->child) { MEM_freeN(psys->child); - psys->child= 0; - psys->totchild= 0; + psys->child = 0; + psys->totchild = 0; } - psys->child= data->child; - psys->totchild= data->totchild; - psys->pathcache= data->pathcache; + psys->child = data->child; + psys->totchild = data->totchild; + psys->pathcache = data->pathcache; psys->pathcachebufs.first = data->pathcachebufs.first; psys->pathcachebufs.last = data->pathcachebufs.last; - psys->totcached= data->totcached; - psys->childcache= data->childcache; + psys->totcached = data->totcached; + psys->childcache = data->childcache; psys->childcachebufs.first = data->childcachebufs.first; psys->childcachebufs.last = data->childcachebufs.last; - psys->totchildcache= data->totchildcache; + psys->totchildcache = data->totchildcache; - psmd->dm= data->dm; - psmd->totdmvert= data->totdmvert; - psmd->totdmedge= data->totdmedge; - psmd->totdmface= data->totdmface; + psmd->dm = data->dm; + psmd->totdmvert = data->totdmvert; + psmd->totdmedge = data->totdmedge; + psmd->totdmface = data->totdmface; psmd->flag &= ~eParticleSystemFlag_psys_updated; if (psmd->dm) psys_calc_dmcache(ob, psmd->dm, psys); MEM_freeN(data); - psys->renderdata= NULL; + psys->renderdata = NULL; } /* BMESH_TODO, for orig face data, we need to use MPoly */ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot) { - DerivedMesh *dm= ctx->dm; - Mesh *me= (Mesh*)(ctx->sim.ob->data); + DerivedMesh *dm = ctx->dm; + Mesh *me = (Mesh *)(ctx->sim.ob->data); MFace *mf, *mface; MVert *mvert; ParticleRenderData *data; ParticleRenderElem *elems, *elem; - ParticleSettings *part= ctx->sim.psys->part; + ParticleSettings *part = ctx->sim.psys->part; float *facearea, (*facecenter)[3], size[3], fac, powrate, scaleclamp; float co1[3], co2[3], co3[3], co4[3], lambda, arearatio, t, area, viewport; double vprate; int *origindex, *facetotvert; int a, b, totorigface, totface, newtot, skipped; - if (part->ren_as!=PART_DRAW_PATH || !(part->draw & PART_DRAW_REN_STRAND)) + if (part->ren_as != PART_DRAW_PATH || !(part->draw & PART_DRAW_REN_STRAND)) return tot; if (!ctx->sim.psys->renderdata) return tot; - data= ctx->sim.psys->renderdata; + data = ctx->sim.psys->renderdata; if (data->timeoffset) return 0; if (!(part->simplify_flag & PART_SIMPLIFY_ENABLE)) return tot; - mvert= dm->getVertArray(dm); - mface= dm->getTessFaceArray(dm); - origindex= dm->getTessFaceDataArray(dm, CD_ORIGINDEX); - totface= dm->getNumTessFaces(dm); - totorigface= me->totpoly; + mvert = dm->getVertArray(dm); + mface = dm->getTessFaceArray(dm); + origindex = dm->getTessFaceDataArray(dm, CD_ORIGINDEX); + totface = dm->getNumTessFaces(dm); + totorigface = me->totpoly; if (totface == 0 || totorigface == 0) return tot; - facearea= MEM_callocN(sizeof(float)*totorigface, "SimplifyFaceArea"); - facecenter= MEM_callocN(sizeof(float[3])*totorigface, "SimplifyFaceCenter"); - facetotvert= MEM_callocN(sizeof(int)*totorigface, "SimplifyFaceArea"); - elems= MEM_callocN(sizeof(ParticleRenderElem)*totorigface, "SimplifyFaceElem"); + facearea = MEM_callocN(sizeof(float) * totorigface, "SimplifyFaceArea"); + facecenter = MEM_callocN(sizeof(float[3]) * totorigface, "SimplifyFaceCenter"); + facetotvert = MEM_callocN(sizeof(int) * totorigface, "SimplifyFaceArea"); + elems = MEM_callocN(sizeof(ParticleRenderElem) * totorigface, "SimplifyFaceElem"); if (data->elems) MEM_freeN(data->elems); - data->dosimplify= 1; - data->elems= elems; - data->origindex= origindex; + data->dosimplify = 1; + data->elems = elems; + data->origindex = origindex; /* compute number of children per original face */ - for (a=0; a<tot; a++) { - b= (origindex)? origindex[ctx->index[a]]: ctx->index[a]; + for (a = 0; a < tot; a++) { + b = (origindex) ? origindex[ctx->index[a]] : ctx->index[a]; if (b != -1) elems[b].totchild++; } /* compute areas and centers of original faces */ - for (mf=mface, a=0; a<totface; a++, mf++) { - b= (origindex)? origindex[a]: a; + for (mf = mface, a = 0; a < totface; a++, mf++) { + b = (origindex) ? origindex[a] : a; if (b != -1) { copy_v3_v3(co1, mvert[mf->v1].co); @@ -858,67 +858,67 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot) } } - for (a=0; a<totorigface; a++) + for (a = 0; a < totorigface; a++) if (facetotvert[a] > 0) - mul_v3_fl(facecenter[a], 1.0f/facetotvert[a]); + mul_v3_fl(facecenter[a], 1.0f / facetotvert[a]); /* for conversion from BU area / pixel area to reference screen size */ - mesh_get_texspace(me, 0, 0, size); - fac= ((size[0] + size[1] + size[2])/3.0f)/part->simplify_refsize; - fac= fac*fac; + BKE_mesh_texspace_get(me, 0, 0, size); + fac = ((size[0] + size[1] + size[2]) / 3.0f) / part->simplify_refsize; + fac = fac * fac; - powrate= log(0.5f)/log(part->simplify_rate*0.5f); + powrate = log(0.5f) / log(part->simplify_rate * 0.5f); if (part->simplify_flag & PART_SIMPLIFY_VIEWPORT) - vprate= pow(1.0f - part->simplify_viewport, 5.0); + vprate = pow(1.0f - part->simplify_viewport, 5.0); else - vprate= 1.0; + vprate = 1.0; /* set simplification parameters per original face */ - for (a=0, elem=elems; a<totorigface; a++, elem++) { + for (a = 0, elem = elems; a < totorigface; a++, elem++) { area = psys_render_projected_area(ctx->sim.psys, facecenter[a], facearea[a], vprate, &viewport); - arearatio= fac*area/facearea[a]; + arearatio = fac * area / facearea[a]; if ((arearatio < 1.0f || viewport < 1.0f) && elem->totchild) { /* lambda is percentage of elements to keep */ - lambda= (arearatio < 1.0f)? powf(arearatio, powrate): 1.0f; + lambda = (arearatio < 1.0f) ? powf(arearatio, powrate) : 1.0f; lambda *= viewport; - lambda= MAX2(lambda, 1.0f/elem->totchild); + lambda = MAX2(lambda, 1.0f / elem->totchild); /* compute transition region */ - t= part->simplify_transition; - elem->t= (lambda-t < 0.0f)? lambda: (lambda+t > 1.0f)? 1.0f-lambda: t; - elem->reduce= 1; + t = part->simplify_transition; + elem->t = (lambda - t < 0.0f) ? lambda : (lambda + t > 1.0f) ? 1.0f - lambda : t; + elem->reduce = 1; /* scale at end and beginning of the transition region */ - elem->scalemax= (lambda+t < 1.0f)? 1.0f/lambda: 1.0f/(1.0f - elem->t*elem->t/t); - elem->scalemin= (lambda+t < 1.0f)? 0.0f: elem->scalemax*(1.0f-elem->t/t); + elem->scalemax = (lambda + t < 1.0f) ? 1.0f / lambda : 1.0f / (1.0f - elem->t * elem->t / t); + elem->scalemin = (lambda + t < 1.0f) ? 0.0f : elem->scalemax * (1.0f - elem->t / t); - elem->scalemin= sqrt(elem->scalemin); - elem->scalemax= sqrt(elem->scalemax); + elem->scalemin = sqrt(elem->scalemin); + elem->scalemax = sqrt(elem->scalemax); /* clamp scaling */ - scaleclamp= MIN2(elem->totchild, 10.0f); - elem->scalemin= MIN2(scaleclamp, elem->scalemin); - elem->scalemax= MIN2(scaleclamp, elem->scalemax); + scaleclamp = MIN2(elem->totchild, 10.0f); + elem->scalemin = MIN2(scaleclamp, elem->scalemin); + elem->scalemax = MIN2(scaleclamp, elem->scalemax); /* extend lambda to include transition */ - lambda= lambda + elem->t; + lambda = lambda + elem->t; if (lambda > 1.0f) - lambda= 1.0f; + lambda = 1.0f; } else { - lambda= arearatio; + lambda = arearatio; - elem->scalemax= 1.0f; //sqrt(lambda); - elem->scalemin= 1.0f; //sqrt(lambda); - elem->reduce= 0; + elem->scalemax = 1.0f; //sqrt(lambda); + elem->scalemin = 1.0f; //sqrt(lambda); + elem->reduce = 0; } - elem->lambda= lambda; - elem->scalemin= sqrt(elem->scalemin); - elem->scalemax= sqrt(elem->scalemax); - elem->curchild= 0; + elem->lambda = lambda; + elem->scalemin = sqrt(elem->scalemin); + elem->scalemax = sqrt(elem->scalemax); + elem->curchild = 0; } MEM_freeN(facearea); @@ -926,16 +926,16 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot) MEM_freeN(facetotvert); /* move indices and set random number skipping */ - ctx->skip= MEM_callocN(sizeof(int)*tot, "SimplificationSkip"); + ctx->skip = MEM_callocN(sizeof(int) * tot, "SimplificationSkip"); - skipped= 0; - for (a=0, newtot=0; a<tot; a++) { - b= (origindex)? origindex[ctx->index[a]]: ctx->index[a]; + skipped = 0; + for (a = 0, newtot = 0; a < tot; a++) { + b = (origindex) ? origindex[ctx->index[a]] : ctx->index[a]; if (b != -1) { - if (elems[b].curchild++ < ceil(elems[b].lambda*elems[b].totchild)) { - ctx->index[newtot]= ctx->index[a]; - ctx->skip[newtot]= skipped; - skipped= 0; + if (elems[b].curchild++ < ceil(elems[b].lambda * elems[b].totchild)) { + ctx->index[newtot] = ctx->index[a]; + ctx->skip[newtot] = skipped; + skipped = 0; newtot++; } else skipped++; @@ -943,8 +943,8 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot) else skipped++; } - for (a=0, elem=elems; a<totorigface; a++, elem++) - elem->curchild= 0; + for (a = 0, elem = elems; a < totorigface; a++, elem++) + elem->curchild = 0; return newtot; } @@ -959,44 +959,44 @@ int psys_render_simplify_params(ParticleSystem *psys, ChildParticle *cpa, float if (!(psys->renderdata && (psys->part->simplify_flag & PART_SIMPLIFY_ENABLE))) return 0; - data= psys->renderdata; + data = psys->renderdata; if (!data->dosimplify) return 0; - b= (data->origindex)? data->origindex[cpa->num]: cpa->num; + b = (data->origindex) ? data->origindex[cpa->num] : cpa->num; if (b == -1) return 0; - elem= &data->elems[b]; + elem = &data->elems[b]; - lambda= elem->lambda; - t= elem->t; - scalemin= elem->scalemin; - scalemax= elem->scalemax; + lambda = elem->lambda; + t = elem->t; + scalemin = elem->scalemin; + scalemax = elem->scalemax; if (!elem->reduce) { - scale= scalemin; - alpha= 1.0f; + scale = scalemin; + alpha = 1.0f; } else { - x= (elem->curchild+0.5f)/elem->totchild; - if (x < lambda-t) { - scale= scalemax; - alpha= 1.0f; + x = (elem->curchild + 0.5f) / elem->totchild; + if (x < lambda - t) { + scale = scalemax; + alpha = 1.0f; } - else if (x >= lambda+t) { - scale= scalemin; - alpha= 0.0f; + else if (x >= lambda + t) { + scale = scalemin; + alpha = 0.0f; } else { - w= (lambda+t - x)/(2.0f*t); - scale= scalemin + (scalemax - scalemin)*w; - alpha= w; + w = (lambda + t - x) / (2.0f * t); + scale = scalemin + (scalemax - scalemin) * w; + alpha = w; } } - params[0]= scale; - params[1]= alpha; + params[0] = scale; + params[1] = alpha; elem->curchild++; @@ -1010,9 +1010,9 @@ static float interpolate_particle_value(float v1, float v2, float v3, float v4, { float value; - value= w[0]*v1 + w[1]*v2 + w[2]*v3; + value = w[0] * v1 + w[1] * v2 + w[2] * v3; if (four) - value += w[3]*v4; + value += w[3] * v4; CLAMP(value, 0.f, 1.f); @@ -1023,7 +1023,7 @@ void psys_interpolate_particle(short type, ParticleKey keys[4], float dt, Partic { float t[4]; - if (type<0) { + if (type < 0) { interp_cubic_v3(result->co, result->vel, keys[1].co, keys[1].vel, keys[2].co, keys[2].vel, dt); } else { @@ -1034,13 +1034,13 @@ void psys_interpolate_particle(short type, ParticleKey keys[4], float dt, Partic if (velocity) { float temp[3]; - if (dt>0.999f) { - key_curve_position_weights(dt-0.001f, t, type); + if (dt > 0.999f) { + key_curve_position_weights(dt - 0.001f, t, type); interp_v3_v3v3v3v3(temp, keys[0].co, keys[1].co, keys[2].co, keys[3].co, t); sub_v3_v3v3(result->vel, result->co, temp); } else { - key_curve_position_weights(dt+0.001f, t, type); + key_curve_position_weights(dt + 0.001f, t, type); interp_v3_v3v3v3v3(temp, keys[0].co, keys[1].co, keys[2].co, keys[3].co, t); sub_v3_v3v3(result->vel, temp, result->co); } @@ -1110,7 +1110,7 @@ static int get_pointcache_times_for_particle(PointCache *cache, int index, float PTCacheMem *pm; int ret = 0; - for (pm=cache->mem_cache.first; pm; pm=pm->next) { + for (pm = cache->mem_cache.first; pm; pm = pm->next) { if (BKE_ptcache_mem_index_find(pm, index) >= 0) { *start = pm->frame; ret++; @@ -1118,7 +1118,7 @@ static int get_pointcache_times_for_particle(PointCache *cache, int index, float } } - for (pm=cache->mem_cache.last; pm; pm=pm->prev) { + for (pm = cache->mem_cache.last; pm; pm = pm->prev) { if (BKE_ptcache_mem_index_find(pm, index) >= 0) { *end = pm->frame; ret++; @@ -1134,7 +1134,7 @@ float psys_get_dietime_from_cache(PointCache *cache, int index) PTCacheMem *pm; int dietime = 10000000; /* some max value so that we can default to pa->time+lifetime */ - for (pm=cache->mem_cache.last; pm; pm=pm->prev) { + for (pm = cache->mem_cache.last; pm; pm = pm->prev) { if (BKE_ptcache_mem_index_find(pm, index) >= 0) return (float)pm->frame; } @@ -1163,7 +1163,7 @@ static void init_particle_interpolation(Object *ob, ParticleSystem *psys, Partic pind->dietime = (key + pa->totkey - 1)->time; } else if (pind->cache) { - float start=0.0f, end=0.0f; + float start = 0.0f, end = 0.0f; get_pointcache_keys_for_time(ob, pind->cache, &pind->pm, -1, 0.0f, NULL, NULL); pind->birthtime = pa ? pa->time : pind->cache->startframe; pind->dietime = pa ? pa->dietime : pind->cache->endframe; @@ -1222,7 +1222,7 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData if (result->time < 0.0f) real_t = -result->time; else - real_t = *(pind->ekey[0]->time) + t * (*(pind->ekey[0][point->totkey-1].time) - *(pind->ekey[0]->time)); + real_t = *(pind->ekey[0]->time) + t * (*(pind->ekey[0][point->totkey - 1].time) - *(pind->ekey[0]->time)); while (*(pind->ekey[1]->time) < real_t) pind->ekey[1]++; @@ -1231,7 +1231,7 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData } else if (pind->keyed) { /* we have only one key, so let's use that */ - if (pind->kkey[1]==NULL) { + if (pind->kkey[1] == NULL) { copy_particle_key(result, pind->kkey[0], 1); return; } @@ -1239,24 +1239,24 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData if (result->time < 0.0f) real_t = -result->time; else - real_t = pind->kkey[0]->time + t * (pind->kkey[0][pa->totkey-1].time - pind->kkey[0]->time); + real_t = pind->kkey[0]->time + t * (pind->kkey[0][pa->totkey - 1].time - pind->kkey[0]->time); - if (psys->part->phystype==PART_PHYS_KEYED && psys->flag & PSYS_KEYED_TIMING) { + if (psys->part->phystype == PART_PHYS_KEYED && psys->flag & PSYS_KEYED_TIMING) { ParticleTarget *pt = psys->targets.first; - pt=pt->next; + pt = pt->next; while (pt && pa->time + pt->time < real_t) - pt= pt->next; + pt = pt->next; if (pt) { - pt=pt->prev; + pt = pt->prev; if (pa->time + pt->time + pt->duration > real_t) real_t = pa->time + pt->time; } else - real_t = pa->time + ((ParticleTarget*)psys->targets.last)->time; + real_t = pa->time + ((ParticleTarget *)psys->targets.last)->time; } CLAMP(real_t, pa->time, pa->dietime); @@ -1276,7 +1276,7 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData if (result->time < 0.0f) real_t = -result->time; else - real_t = pind->hkey[0]->time + t * (pind->hkey[0][pa->totkey-1].time - pind->hkey[0]->time); + real_t = pind->hkey[0]->time + t * (pind->hkey[0][pa->totkey - 1].time - pind->hkey[0]->time); while (pind->hkey[1]->time < real_t) { pind->hkey[1]++; @@ -1301,7 +1301,7 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData memcpy(keys + 2, pind->kkey[1], sizeof(ParticleKey)); } else if (pind->cache) { - get_pointcache_keys_for_time(NULL, pind->cache, &pind->pm, p, real_t, keys+1, keys+2); + get_pointcache_keys_for_time(NULL, pind->cache, &pind->pm, p, real_t, keys + 1, keys + 2); } else { hair_to_particle(keys + 1, pind->hkey[0]); @@ -1362,37 +1362,37 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData /* now we should have in chronologiacl order k1<=k2<=t<=k3<=k4 with keytime between [0, 1]->[k2, k3] (k1 & k4 used for cardinal & bspline interpolation)*/ psys_interpolate_particle((pind->keyed || pind->cache || point_vel) ? -1 /* signal for cubic interpolation */ - : (pind->bspline ? KEY_BSPLINE : KEY_CARDINAL), - keys, keytime, result, 1); + : (pind->bspline ? KEY_BSPLINE : KEY_CARDINAL), + keys, keytime, result, 1); /* the velocity needs to be converted back from cubic interpolation */ if (pind->keyed || pind->cache || point_vel) - mul_v3_fl(result->vel, 1.f/invdt); + mul_v3_fl(result->vel, 1.f / invdt); } static void interpolate_pathcache(ParticleCacheKey *first, float t, ParticleCacheKey *result) { - int i=0; + int i = 0; ParticleCacheKey *cur = first; /* scale the requested time to fit the entire path even if the path is cut early */ - t *= (first+first->steps)->time; + t *= (first + first->steps)->time; - while (i<first->steps && cur->time < t) + while (i < first->steps && cur->time < t) cur++; if (cur->time == t) *result = *cur; else { - float dt = (t-(cur-1)->time)/(cur->time-(cur-1)->time); - interp_v3_v3v3(result->co, (cur-1)->co, cur->co, dt); - interp_v3_v3v3(result->vel, (cur-1)->vel, cur->vel, dt); - interp_qt_qtqt(result->rot, (cur-1)->rot, cur->rot, dt); + float dt = (t - (cur - 1)->time) / (cur->time - (cur - 1)->time); + interp_v3_v3v3(result->co, (cur - 1)->co, cur->co, dt); + interp_v3_v3v3(result->vel, (cur - 1)->vel, cur->vel, dt); + interp_qt_qtqt(result->rot, (cur - 1)->rot, cur->rot, dt); result->time = t; } /* first is actual base rotation, others are incremental from first */ - if (cur==first || cur-1==first) + if (cur == first || cur - 1 == first) copy_qt_qt(result->rot, first->rot); else mul_qt_qtqt(result->rot, first->rot, result->rot); @@ -1405,23 +1405,23 @@ static void interpolate_pathcache(ParticleCacheKey *first, float t, ParticleCach void psys_interpolate_face(MVert *mvert, MFace *mface, MTFace *tface, float (*orcodata)[3], float *w, float *vec, float *nor, float *utan, float *vtan, float *orco, float *ornor) { - float *v1=0, *v2=0, *v3=0, *v4=0; + float *v1 = 0, *v2 = 0, *v3 = 0, *v4 = 0; float e1[3], e2[3], s1, s2, t1, t2; float *uv1, *uv2, *uv3, *uv4; float n1[3], n2[3], n3[3], n4[3]; float tuv[4][2]; float *o1, *o2, *o3, *o4; - v1= mvert[mface->v1].co; - v2= mvert[mface->v2].co; - v3= mvert[mface->v3].co; + v1 = mvert[mface->v1].co; + v2 = mvert[mface->v2].co; + v3 = mvert[mface->v3].co; normal_short_to_float_v3(n1, mvert[mface->v1].no); normal_short_to_float_v3(n2, mvert[mface->v2].no); normal_short_to_float_v3(n3, mvert[mface->v3].no); if (mface->v4) { - v4= mvert[mface->v4].co; + v4 = mvert[mface->v4].co; normal_short_to_float_v3(n4, mvert[mface->v4].no); interp_v3_v3v3v3v3(vec, v1, v2, v3, v4, w); @@ -1447,58 +1447,58 @@ void psys_interpolate_face(MVert *mvert, MFace *mface, MTFace *tface, float (*or /* calculate tangent vectors */ if (utan && vtan) { if (tface) { - uv1= tface->uv[0]; - uv2= tface->uv[1]; - uv3= tface->uv[2]; - uv4= tface->uv[3]; + uv1 = tface->uv[0]; + uv2 = tface->uv[1]; + uv3 = tface->uv[2]; + uv4 = tface->uv[3]; } else { - uv1= tuv[0]; uv2= tuv[1]; uv3= tuv[2]; uv4= tuv[3]; - map_to_sphere(uv1, uv1+1, v1[0], v1[1], v1[2]); - map_to_sphere(uv2, uv2+1, v2[0], v2[1], v2[2]); - map_to_sphere(uv3, uv3+1, v3[0], v3[1], v3[2]); + uv1 = tuv[0]; uv2 = tuv[1]; uv3 = tuv[2]; uv4 = tuv[3]; + map_to_sphere(uv1, uv1 + 1, v1[0], v1[1], v1[2]); + map_to_sphere(uv2, uv2 + 1, v2[0], v2[1], v2[2]); + map_to_sphere(uv3, uv3 + 1, v3[0], v3[1], v3[2]); if (v4) - map_to_sphere(uv4, uv4+1, v4[0], v4[1], v4[2]); + map_to_sphere(uv4, uv4 + 1, v4[0], v4[1], v4[2]); } if (v4) { - s1= uv3[0] - uv1[0]; - s2= uv4[0] - uv1[0]; + s1 = uv3[0] - uv1[0]; + s2 = uv4[0] - uv1[0]; - t1= uv3[1] - uv1[1]; - t2= uv4[1] - uv1[1]; + t1 = uv3[1] - uv1[1]; + t2 = uv4[1] - uv1[1]; sub_v3_v3v3(e1, v3, v1); sub_v3_v3v3(e2, v4, v1); } else { - s1= uv2[0] - uv1[0]; - s2= uv3[0] - uv1[0]; + s1 = uv2[0] - uv1[0]; + s2 = uv3[0] - uv1[0]; - t1= uv2[1] - uv1[1]; - t2= uv3[1] - uv1[1]; + t1 = uv2[1] - uv1[1]; + t2 = uv3[1] - uv1[1]; sub_v3_v3v3(e1, v2, v1); sub_v3_v3v3(e2, v3, v1); } - vtan[0] = (s1*e2[0] - s2*e1[0]); - vtan[1] = (s1*e2[1] - s2*e1[1]); - vtan[2] = (s1*e2[2] - s2*e1[2]); + vtan[0] = (s1 * e2[0] - s2 * e1[0]); + vtan[1] = (s1 * e2[1] - s2 * e1[1]); + vtan[2] = (s1 * e2[2] - s2 * e1[2]); - utan[0] = (t1*e2[0] - t2*e1[0]); - utan[1] = (t1*e2[1] - t2*e1[1]); - utan[2] = (t1*e2[2] - t2*e1[2]); + utan[0] = (t1 * e2[0] - t2 * e1[0]); + utan[1] = (t1 * e2[1] - t2 * e1[1]); + utan[2] = (t1 * e2[2] - t2 * e1[2]); } if (orco) { if (orcodata) { - o1= orcodata[mface->v1]; - o2= orcodata[mface->v2]; - o3= orcodata[mface->v3]; + o1 = orcodata[mface->v1]; + o2 = orcodata[mface->v2]; + o3 = orcodata[mface->v3]; if (mface->v4) { - o4= orcodata[mface->v4]; + o4 = orcodata[mface->v4]; interp_v3_v3v3v3v3(orco, o1, o2, o3, o4, w); @@ -1521,24 +1521,24 @@ void psys_interpolate_face(MVert *mvert, MFace *mface, MTFace *tface, float (*or } void psys_interpolate_uvs(const MTFace *tface, int quad, const float w[4], float uvco[2]) { - float v10= tface->uv[0][0]; - float v11= tface->uv[0][1]; - float v20= tface->uv[1][0]; - float v21= tface->uv[1][1]; - float v30= tface->uv[2][0]; - float v31= tface->uv[2][1]; + float v10 = tface->uv[0][0]; + float v11 = tface->uv[0][1]; + float v20 = tface->uv[1][0]; + float v21 = tface->uv[1][1]; + float v30 = tface->uv[2][0]; + float v31 = tface->uv[2][1]; float v40, v41; if (quad) { - v40= tface->uv[3][0]; - v41= tface->uv[3][1]; + v40 = tface->uv[3][0]; + v41 = tface->uv[3][1]; - uvco[0]= w[0]*v10 + w[1]*v20 + w[2]*v30 + w[3]*v40; - uvco[1]= w[0]*v11 + w[1]*v21 + w[2]*v31 + w[3]*v41; + uvco[0] = w[0] * v10 + w[1] * v20 + w[2] * v30 + w[3] * v40; + uvco[1] = w[0] * v11 + w[1] * v21 + w[2] * v31 + w[3] * v41; } else { - uvco[0]= w[0]*v10 + w[1]*v20 + w[2]*v30; - uvco[1]= w[0]*v11 + w[1]*v21 + w[2]*v31; + uvco[0] = w[0] * v10 + w[1] * v20 + w[2] * v30; + uvco[1] = w[0] * v11 + w[1] * v21 + w[2] * v31; } } @@ -1546,30 +1546,30 @@ void psys_interpolate_mcol(const MCol *mcol, int quad, const float w[4], MCol *m { char *cp, *cp1, *cp2, *cp3, *cp4; - cp= (char *)mc; - cp1= (char *)&mcol[0]; - cp2= (char *)&mcol[1]; - cp3= (char *)&mcol[2]; + cp = (char *)mc; + cp1 = (char *)&mcol[0]; + cp2 = (char *)&mcol[1]; + cp3 = (char *)&mcol[2]; if (quad) { - cp4= (char *)&mcol[3]; + cp4 = (char *)&mcol[3]; - cp[0]= (int)(w[0]*cp1[0] + w[1]*cp2[0] + w[2]*cp3[0] + w[3]*cp4[0]); - cp[1]= (int)(w[0]*cp1[1] + w[1]*cp2[1] + w[2]*cp3[1] + w[3]*cp4[1]); - cp[2]= (int)(w[0]*cp1[2] + w[1]*cp2[2] + w[2]*cp3[2] + w[3]*cp4[2]); - cp[3]= (int)(w[0]*cp1[3] + w[1]*cp2[3] + w[2]*cp3[3] + w[3]*cp4[3]); + cp[0] = (int)(w[0] * cp1[0] + w[1] * cp2[0] + w[2] * cp3[0] + w[3] * cp4[0]); + cp[1] = (int)(w[0] * cp1[1] + w[1] * cp2[1] + w[2] * cp3[1] + w[3] * cp4[1]); + cp[2] = (int)(w[0] * cp1[2] + w[1] * cp2[2] + w[2] * cp3[2] + w[3] * cp4[2]); + cp[3] = (int)(w[0] * cp1[3] + w[1] * cp2[3] + w[2] * cp3[3] + w[3] * cp4[3]); } else { - cp[0]= (int)(w[0]*cp1[0] + w[1]*cp2[0] + w[2]*cp3[0]); - cp[1]= (int)(w[0]*cp1[1] + w[1]*cp2[1] + w[2]*cp3[1]); - cp[2]= (int)(w[0]*cp1[2] + w[1]*cp2[2] + w[2]*cp3[2]); - cp[3]= (int)(w[0]*cp1[3] + w[1]*cp2[3] + w[2]*cp3[3]); + cp[0] = (int)(w[0] * cp1[0] + w[1] * cp2[0] + w[2] * cp3[0]); + cp[1] = (int)(w[0] * cp1[1] + w[1] * cp2[1] + w[2] * cp3[1]); + cp[2] = (int)(w[0] * cp1[2] + w[1] * cp2[2] + w[2] * cp3[2]); + cp[3] = (int)(w[0] * cp1[3] + w[1] * cp2[3] + w[2] * cp3[3]); } } static float psys_interpolate_value_from_verts(DerivedMesh *dm, short from, int index, const float fw[4], const float *values) { - if (values==0 || index==-1) + if (values == 0 || index == -1) return 0.0; switch (from) { @@ -1578,7 +1578,7 @@ static float psys_interpolate_value_from_verts(DerivedMesh *dm, short from, int case PART_FROM_FACE: case PART_FROM_VOLUME: { - MFace *mf=dm->getTessFaceData(dm, index, CD_MFACE); + MFace *mf = dm->getTessFaceData(dm, index, CD_MFACE); return interpolate_particle_value(values[mf->v1], values[mf->v2], values[mf->v3], values[mf->v4], fw, mf->v4); } @@ -1589,8 +1589,8 @@ static float psys_interpolate_value_from_verts(DerivedMesh *dm, short from, int /* conversion of pa->fw to origspace layer coordinates */ static void psys_w_to_origspace(const float w[4], float uv[2]) { - uv[0]= w[1] + w[2]; - uv[1]= w[2] + w[3]; + uv[0] = w[1] + w[2]; + uv[1] = w[2] + w[3]; } /* conversion of pa->fw to weights in face from origspace */ @@ -1598,20 +1598,20 @@ static void psys_origspace_to_w(OrigSpaceFace *osface, int quad, const float w[4 { float v[4][3], co[3]; - v[0][0]= osface->uv[0][0]; v[0][1]= osface->uv[0][1]; v[0][2]= 0.0f; - v[1][0]= osface->uv[1][0]; v[1][1]= osface->uv[1][1]; v[1][2]= 0.0f; - v[2][0]= osface->uv[2][0]; v[2][1]= osface->uv[2][1]; v[2][2]= 0.0f; + v[0][0] = osface->uv[0][0]; v[0][1] = osface->uv[0][1]; v[0][2] = 0.0f; + v[1][0] = osface->uv[1][0]; v[1][1] = osface->uv[1][1]; v[1][2] = 0.0f; + v[2][0] = osface->uv[2][0]; v[2][1] = osface->uv[2][1]; v[2][2] = 0.0f; psys_w_to_origspace(w, co); - co[2]= 0.0f; + co[2] = 0.0f; if (quad) { - v[3][0]= osface->uv[3][0]; v[3][1]= osface->uv[3][1]; v[3][2]= 0.0f; + v[3][0] = osface->uv[3][0]; v[3][1] = osface->uv[3][1]; v[3][2] = 0.0f; interp_weights_poly_v3(neww, v, 4, co); } else { interp_weights_poly_v3(neww, v, 3, co); - neww[3]= 0.0f; + neww[3] = 0.0f; } } @@ -1619,7 +1619,7 @@ static void psys_origspace_to_w(OrigSpaceFace *osface, int quad, const float w[4 * and can be optimized but only for many lookups. returns the face index. */ int psys_particle_dm_face_lookup(Object *ob, DerivedMesh *dm, int index, const float fw[4], struct LinkNode *node) { - Mesh *me= (Mesh*)ob->data; + Mesh *me = (Mesh *)ob->data; MPoly *mpoly; OrigSpaceFace *osface; int *origindex; @@ -1632,9 +1632,9 @@ int psys_particle_dm_face_lookup(Object *ob, DerivedMesh *dm, int index, const f totface = dm->getNumTessFaces(dm); - if (osface==NULL || origindex==NULL) { + if (osface == NULL || origindex == NULL) { /* Assume we don't need osface data */ - if (index <totface) { + if (index < totface) { //printf("\tNO CD_ORIGSPACE, assuming not needed\n"); return index; } @@ -1644,14 +1644,14 @@ int psys_particle_dm_face_lookup(Object *ob, DerivedMesh *dm, int index, const f } } else if (index >= me->totpoly) - return DMCACHE_NOTFOUND; /* index not in the original mesh */ + return DMCACHE_NOTFOUND; /* index not in the original mesh */ psys_w_to_origspace(fw, uv); if (node) { /* we have a linked list of faces that we use, faster! */ - for (;node; node=node->next) { - findex= GET_INT_FROM_POINTER(node->link); - faceuv= osface[findex].uv; + for (; node; node = node->next) { + findex = GET_INT_FROM_POINTER(node->link); + faceuv = osface[findex].uv; quad = (mpoly[findex].totloop == 4); /* check that this intersects - Its possible this misses :/ - @@ -1665,9 +1665,9 @@ int psys_particle_dm_face_lookup(Object *ob, DerivedMesh *dm, int index, const f } } else { /* if we have no node, try every face */ - for (findex=0; findex<totface; findex++) { + for (findex = 0; findex < totface; findex++) { if (origindex[findex] == index) { - faceuv= osface[findex].uv; + faceuv = osface[findex].uv; quad = (mpoly[findex].totloop == 4); /* check that this intersects - Its possible this misses :/ - @@ -1718,25 +1718,25 @@ static int psys_map_index_on_dm(DerivedMesh *dm, int from, int index, int index_ *mapindex = index_dmcache; } else { /* FROM_FACE/FROM_VOLUME */ - /* find a face on the derived mesh that uses this face */ + /* find a face on the derived mesh that uses this face */ MFace *mface; OrigSpaceFace *osface; int i; i = index_dmcache; - if (i== DMCACHE_NOTFOUND || i >= dm->getNumTessFaces(dm)) + if (i == DMCACHE_NOTFOUND || i >= dm->getNumTessFaces(dm)) return 0; *mapindex = i; /* modify the original weights to become * weights for the derived mesh face */ - osface= dm->getTessFaceDataArray(dm, CD_ORIGSPACE); - mface= dm->getTessFaceData(dm, i, CD_MFACE); + osface = dm->getTessFaceDataArray(dm, CD_ORIGSPACE); + mface = dm->getTessFaceData(dm, i, CD_MFACE); if (osface == NULL) - mapfw[0]= mapfw[1]= mapfw[2]= mapfw[3]= 0.0f; + mapfw[0] = mapfw[1] = mapfw[2] = mapfw[3] = 0.0f; else psys_origspace_to_w(&osface[i], mface->v4, fw, mapfw); } @@ -1753,17 +1753,17 @@ void psys_particle_on_dm(DerivedMesh *dm, int from, int index, int index_dmcache int mapindex; if (!psys_map_index_on_dm(dm, from, index, index_dmcache, fw, foffset, &mapindex, mapfw)) { - if (vec) { vec[0]=vec[1]=vec[2]=0.0; } - if (nor) { nor[0]=nor[1]=0.0; nor[2]=1.0; } - if (orco) { orco[0]=orco[1]=orco[2]=0.0; } - if (ornor) { ornor[0]=ornor[1]=0.0; ornor[2]=1.0; } - if (utan) { utan[0]=utan[1]=utan[2]=0.0; } - if (vtan) { vtan[0]=vtan[1]=vtan[2]=0.0; } + if (vec) { vec[0] = vec[1] = vec[2] = 0.0; } + if (nor) { nor[0] = nor[1] = 0.0; nor[2] = 1.0; } + if (orco) { orco[0] = orco[1] = orco[2] = 0.0; } + if (ornor) { ornor[0] = ornor[1] = 0.0; ornor[2] = 1.0; } + if (utan) { utan[0] = utan[1] = utan[2] = 0.0; } + if (vtan) { vtan[0] = vtan[1] = vtan[2] = 0.0; } return; } - orcodata= dm->getVertDataArray(dm, CD_ORCO); + orcodata = dm->getVertDataArray(dm, CD_ORCO); if (from == PART_FROM_VERT) { dm->getVertCo(dm, mapindex, vec); @@ -1782,8 +1782,8 @@ void psys_particle_on_dm(DerivedMesh *dm, int from, int index, int index_dmcache } if (utan && vtan) { - utan[0]= utan[1]= utan[2]= 0.0f; - vtan[0]= vtan[1]= vtan[2]= 0.0f; + utan[0] = utan[1] = utan[2] = 0.0f; + vtan[0] = vtan[1] = vtan[2] = 0.0f; } } else { /* PART_FROM_FACE / PART_FROM_VOLUME */ @@ -1791,14 +1791,14 @@ void psys_particle_on_dm(DerivedMesh *dm, int from, int index, int index_dmcache MTFace *mtface; MVert *mvert; - mface=dm->getTessFaceData(dm, mapindex, CD_MFACE); - mvert=dm->getVertDataArray(dm, CD_MVERT); - mtface=CustomData_get_layer(&dm->faceData, CD_MTFACE); + mface = dm->getTessFaceData(dm, mapindex, CD_MFACE); + mvert = dm->getVertDataArray(dm, CD_MVERT); + mtface = CustomData_get_layer(&dm->faceData, CD_MTFACE); if (mtface) mtface += mapindex; - if (from==PART_FROM_VOLUME) { + if (from == PART_FROM_VOLUME) { psys_interpolate_face(mvert, mface, mtface, orcodata, mapfw, vec, tmpnor, utan, vtan, orco, ornor); if (nor) copy_v3_v3(nor, tmpnor); @@ -1828,10 +1828,10 @@ ParticleSystemModifierData *psys_get_modifier(Object *ob, ParticleSystem *psys) ModifierData *md; ParticleSystemModifierData *psmd; - for (md=ob->modifiers.first; md; md=md->next) { - if (md->type==eModifierType_ParticleSystem) { - psmd= (ParticleSystemModifierData*) md; - if (psmd->psys==psys) { + for (md = ob->modifiers.first; md; md = md->next) { + if (md->type == eModifierType_ParticleSystem) { + psmd = (ParticleSystemModifierData *) md; + if (psmd->psys == psys) { return psmd; } } @@ -1845,7 +1845,7 @@ ParticleSystemModifierData *psys_get_modifier(Object *ob, ParticleSystem *psys) static void psys_particle_on_shape(int UNUSED(distr), int UNUSED(index), float *UNUSED(fuv), float *vec, float *nor, float *utan, float *vtan, float *orco, float *ornor) { /* TODO */ - float zerovec[3]={0.0f, 0.0f, 0.0f}; + float zerovec[3] = {0.0f, 0.0f, 0.0f}; if (vec) { copy_v3_v3(vec, zerovec); } @@ -1871,7 +1871,7 @@ static void psys_particle_on_shape(int UNUSED(distr), int UNUSED(index), float * void psys_particle_on_emitter(ParticleSystemModifierData *psmd, int from, int index, int index_dmcache, float *fuv, float foffset, float *vec, float *nor, float *utan, float *vtan, float *orco, float *ornor) { if (psmd) { - if (psmd->psys->part->distr==PART_DISTR_GRID && psmd->psys->part->from != PART_FROM_VERT) { + if (psmd->psys->part->distr == PART_DISTR_GRID && psmd->psys->part->from != PART_FROM_VERT) { if (vec) copy_v3_v3(vec, fuv); @@ -1892,34 +1892,34 @@ void psys_particle_on_emitter(ParticleSystemModifierData *psmd, int from, int in static void do_kink(ParticleKey *state, ParticleKey *par, float *par_rot, float time, float freq, float shape, float amplitude, float flat, short type, short axis, float obmat[][4], int smooth_start) { - float kink[3]={1.f, 0.f, 0.f}, par_vec[3], q1[4]={1.f, 0.f, 0.f, 0.f}; - float t, dt=1.f, result[3]; + float kink[3] = {1.f, 0.f, 0.f}, par_vec[3], q1[4] = {1.f, 0.f, 0.f, 0.f}; + float t, dt = 1.f, result[3]; if (par == NULL || type == PART_KINK_NO) return; CLAMP(time, 0.f, 1.f); - if (shape!=0.0f && type!=PART_KINK_BRAID) { - if (shape<0.0f) - time= (float)pow(time, 1.f+shape); + if (shape != 0.0f && type != PART_KINK_BRAID) { + if (shape < 0.0f) + time = (float)pow(time, 1.f + shape); else - time= (float)pow(time, 1.f/(1.f-shape)); + time = (float)pow(time, 1.f / (1.f - shape)); } - t = time * freq *(float)M_PI; + t = time * freq * (float)M_PI; if (smooth_start) { dt = fabs(t); /* smooth the beginning of kink */ CLAMP(dt, 0.f, (float)M_PI); - dt = sin(dt/2.f); + dt = sin(dt / 2.f); } if (type != PART_KINK_RADIAL) { float temp[3]; - kink[axis]=1.f; + kink[axis] = 1.f; if (obmat) mul_mat3_m4_v3(obmat, kink); @@ -1937,124 +1937,124 @@ static void do_kink(ParticleKey *state, ParticleKey *par, float *par_rot, float sub_v3_v3v3(par_vec, par->co, state->co); switch (type) { - case PART_KINK_CURL: - { - negate_v3(par_vec); + case PART_KINK_CURL: + { + negate_v3(par_vec); - if (flat > 0.f) { - float proj[3]; - project_v3_v3v3(proj, par_vec, par->vel); - madd_v3_v3fl(par_vec, proj, -flat); + if (flat > 0.f) { + float proj[3]; + project_v3_v3v3(proj, par_vec, par->vel); + madd_v3_v3fl(par_vec, proj, -flat); - project_v3_v3v3(proj, par_vec, kink); - madd_v3_v3fl(par_vec, proj, -flat); - } + project_v3_v3v3(proj, par_vec, kink); + madd_v3_v3fl(par_vec, proj, -flat); + } - axis_angle_to_quat(q1, kink, (float)M_PI/2.f); + axis_angle_to_quat(q1, kink, (float)M_PI / 2.f); - mul_qt_v3(q1, par_vec); + mul_qt_v3(q1, par_vec); - madd_v3_v3fl(par_vec, kink, amplitude); + madd_v3_v3fl(par_vec, kink, amplitude); - /* rotate kink vector around strand tangent */ - if (t!=0.f) { - axis_angle_to_quat(q1, par->vel, t); - mul_qt_v3(q1, par_vec); - } + /* rotate kink vector around strand tangent */ + if (t != 0.f) { + axis_angle_to_quat(q1, par->vel, t); + mul_qt_v3(q1, par_vec); + } - add_v3_v3v3(result, par->co, par_vec); - break; - } - case PART_KINK_RADIAL: - { - if (flat > 0.f) { - float proj[3]; - /* flatten along strand */ - project_v3_v3v3(proj, par_vec, par->vel); - madd_v3_v3fl(result, proj, flat); + add_v3_v3v3(result, par->co, par_vec); + break; } + case PART_KINK_RADIAL: + { + if (flat > 0.f) { + float proj[3]; + /* flatten along strand */ + project_v3_v3v3(proj, par_vec, par->vel); + madd_v3_v3fl(result, proj, flat); + } - madd_v3_v3fl(result, par_vec, -amplitude*(float)sin(t)); - break; - } - case PART_KINK_WAVE: - { - madd_v3_v3fl(result, kink, amplitude*(float)sin(t)); + madd_v3_v3fl(result, par_vec, -amplitude * (float)sin(t)); + break; + } + case PART_KINK_WAVE: + { + madd_v3_v3fl(result, kink, amplitude * (float)sin(t)); - if (flat > 0.f) { - float proj[3]; - /* flatten along wave */ - project_v3_v3v3(proj, par_vec, kink); - madd_v3_v3fl(result, proj, flat); + if (flat > 0.f) { + float proj[3]; + /* flatten along wave */ + project_v3_v3v3(proj, par_vec, kink); + madd_v3_v3fl(result, proj, flat); - /* flatten along strand */ - project_v3_v3v3(proj, par_vec, par->vel); - madd_v3_v3fl(result, proj, flat); - } - break; - } - case PART_KINK_BRAID: - { - float y_vec[3]={0.f, 1.f, 0.f}; - float z_vec[3]={0.f, 0.f, 1.f}; - float vec_one[3], state_co[3]; - float inp_y, inp_z, length; - - if (par_rot) { - mul_qt_v3(par_rot, y_vec); - mul_qt_v3(par_rot, z_vec); + /* flatten along strand */ + project_v3_v3v3(proj, par_vec, par->vel); + madd_v3_v3fl(result, proj, flat); + } + break; } + case PART_KINK_BRAID: + { + float y_vec[3] = {0.f, 1.f, 0.f}; + float z_vec[3] = {0.f, 0.f, 1.f}; + float vec_one[3], state_co[3]; + float inp_y, inp_z, length; - negate_v3(par_vec); - normalize_v3_v3(vec_one, par_vec); + if (par_rot) { + mul_qt_v3(par_rot, y_vec); + mul_qt_v3(par_rot, z_vec); + } - inp_y=dot_v3v3(y_vec, vec_one); - inp_z=dot_v3v3(z_vec, vec_one); + negate_v3(par_vec); + normalize_v3_v3(vec_one, par_vec); - if (inp_y > 0.5f) { - copy_v3_v3(state_co, y_vec); + inp_y = dot_v3v3(y_vec, vec_one); + inp_z = dot_v3v3(z_vec, vec_one); - 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.0f) { - mul_v3_v3fl(state_co, z_vec, (float)sin((float)M_PI/3.f)); - madd_v3_v3fl(state_co, y_vec, -0.5f); + if (inp_y > 0.5f) { + copy_v3_v3(state_co, y_vec); - 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((float)M_PI/3.f)); - madd_v3_v3fl(state_co, y_vec, -0.5f); + 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.0f) { + 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 + (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(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((float)M_PI / 3.f)); + madd_v3_v3fl(state_co, y_vec, -0.5f); - mul_v3_fl(state_co, amplitude); - add_v3_v3(state_co, par->co); - sub_v3_v3v3(par_vec, state->co, state_co); + 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)); + } - length = normalize_v3(par_vec); - mul_v3_fl(par_vec, MIN2(length, amplitude/2.f)); + mul_v3_fl(state_co, amplitude); + add_v3_v3(state_co, par->co); + sub_v3_v3v3(par_vec, state->co, state_co); - add_v3_v3v3(state_co, par->co, y_vec); - add_v3_v3(state_co, z_vec); - add_v3_v3(state_co, par_vec); + length = normalize_v3(par_vec); + mul_v3_fl(par_vec, MIN2(length, amplitude / 2.f)); - shape = 2.f*(float)M_PI * (1.f+shape); + add_v3_v3v3(state_co, par->co, y_vec); + add_v3_v3(state_co, z_vec); + add_v3_v3(state_co, par_vec); - if (t<shape) { - shape = t/shape; - shape = (float)sqrt((double)shape); - interp_v3_v3v3(result, result, state_co, shape); - } - else { - copy_v3_v3(result, state_co); + shape = 2.f * (float)M_PI * (1.f + shape); + + if (t < shape) { + shape = t / shape; + shape = (float)sqrt((double)shape); + interp_v3_v3v3(result, result, state_co, shape); + } + else { + copy_v3_v3(result, state_co); + } + break; } - break; - } } /* blend the start of the kink */ @@ -2068,18 +2068,18 @@ static float do_clump(ParticleKey *state, ParticleKey *par, float time, float cl { float clump = 0.f; - if (par && clumpfac!=0.0f) { + if (par && clumpfac != 0.0f) { float cpow; if (clumppow < 0.0f) - cpow=1.0f+clumppow; + cpow = 1.0f + clumppow; else - cpow=1.0f+9.0f*clumppow; + cpow = 1.0f + 9.0f * clumppow; if (clumpfac < 0.0f) /* clump roots instead of tips */ - clump = -clumpfac*pa_clump*(float)pow(1.0-(double)time, (double)cpow); + clump = -clumpfac * pa_clump * (float)pow(1.0 - (double)time, (double)cpow); else - clump = clumpfac*pa_clump*(float)pow((double)time, (double)cpow); + clump = clumpfac * pa_clump * (float)pow((double)time, (double)cpow); interp_v3_v3v3(state->co, state->co, par->co, clump); } @@ -2108,12 +2108,12 @@ void precalc_guides(ParticleSimulationData *sim, ListBase *effectors) pd_point_from_particle(sim, pa, &state, &point); - for (eff = effectors->first; eff; eff=eff->next) { + for (eff = effectors->first; eff; eff = eff->next) { if (eff->pd->forcefield != PFIELD_GUIDE) continue; if (!eff->guide_data) - eff->guide_data = MEM_callocN(sizeof(GuideEffectorData)*psys->totpart, "GuideEffectorData"); + eff->guide_data = MEM_callocN(sizeof(GuideEffectorData) * psys->totpart, "GuideEffectorData"); data = eff->guide_data + p; @@ -2139,78 +2139,78 @@ int do_guides(ListBase *effectors, ParticleKey *state, int index, float time) float guidetime, radius, weight, angle, totstrength = 0.0f; float vec_to_point[3]; - if (effectors) for (eff = effectors->first; eff; eff=eff->next) { - pd = eff->pd; + if (effectors) for (eff = effectors->first; eff; eff = eff->next) { + pd = eff->pd; - if (pd->forcefield != PFIELD_GUIDE) - continue; + if (pd->forcefield != PFIELD_GUIDE) + continue; - data = eff->guide_data + index; + data = eff->guide_data + index; - if (data->strength <= 0.0f) - continue; + if (data->strength <= 0.0f) + continue; - guidetime = time / (1.0f - pd->free_end); + guidetime = time / (1.0f - pd->free_end); - if (guidetime>1.0f) - continue; + if (guidetime > 1.0f) + continue; - cu = (Curve*)eff->ob->data; + cu = (Curve *)eff->ob->data; - if (pd->flag & PFIELD_GUIDE_PATH_ADD) { - if (where_on_path(eff->ob, data->strength * guidetime, guidevec, guidedir, NULL, &radius, &weight)==0) - return 0; - } - else { - if (where_on_path(eff->ob, guidetime, guidevec, guidedir, NULL, &radius, &weight)==0) - return 0; - } + if (pd->flag & PFIELD_GUIDE_PATH_ADD) { + if (where_on_path(eff->ob, data->strength * guidetime, guidevec, guidedir, NULL, &radius, &weight) == 0) + return 0; + } + else { + if (where_on_path(eff->ob, guidetime, guidevec, guidedir, NULL, &radius, &weight) == 0) + return 0; + } - mul_m4_v3(eff->ob->obmat, guidevec); - mul_mat3_m4_v3(eff->ob->obmat, guidedir); + mul_m4_v3(eff->ob->obmat, guidevec); + mul_mat3_m4_v3(eff->ob->obmat, guidedir); - normalize_v3(guidedir); + normalize_v3(guidedir); - copy_v3_v3(vec_to_point, data->vec_to_point); + copy_v3_v3(vec_to_point, data->vec_to_point); - 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)); - angle = saacos(angle); - axis_angle_to_quat(rot2, temp, angle); - mul_qt_v3(rot2, vec_to_point); + 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)); + angle = saacos(angle); + axis_angle_to_quat(rot2, temp, angle); + mul_qt_v3(rot2, vec_to_point); - /* curve tilt */ - axis_angle_to_quat(rot2, guidedir, guidevec[3] - eff->guide_loc[3]); - mul_qt_v3(rot2, vec_to_point); - } + /* curve tilt */ + axis_angle_to_quat(rot2, guidedir, guidevec[3] - eff->guide_loc[3]); + mul_qt_v3(rot2, vec_to_point); + } - /* curve taper */ - if (cu->taperobj) - mul_v3_fl(vec_to_point, calc_taper(eff->scene, cu->taperobj, (int)(data->strength*guidetime*100.0f), 100)); + /* curve taper */ + if (cu->taperobj) + mul_v3_fl(vec_to_point, BKE_displist_calc_taper(eff->scene, cu->taperobj, (int)(data->strength * guidetime * 100.0f), 100)); - else { /* curve size*/ - if (cu->flag & CU_PATH_RADIUS) { - mul_v3_fl(vec_to_point, radius); + else { /* curve size*/ + if (cu->flag & CU_PATH_RADIUS) { + mul_v3_fl(vec_to_point, radius); + } } - } - par.co[0] = par.co[1] = par.co[2] = 0.0f; - copy_v3_v3(key.co, vec_to_point); - do_kink(&key, &par, 0, guidetime, pd->kink_freq, pd->kink_shape, pd->kink_amp, 0.f, pd->kink, pd->kink_axis, 0, 0); - do_clump(&key, &par, guidetime, pd->clump_fac, pd->clump_pow, 1.0f); - copy_v3_v3(vec_to_point, key.co); + par.co[0] = par.co[1] = par.co[2] = 0.0f; + copy_v3_v3(key.co, vec_to_point); + do_kink(&key, &par, 0, guidetime, pd->kink_freq, pd->kink_shape, pd->kink_amp, 0.f, pd->kink, pd->kink_axis, 0, 0); + do_clump(&key, &par, guidetime, pd->clump_fac, pd->clump_pow, 1.0f); + copy_v3_v3(vec_to_point, key.co); - add_v3_v3(vec_to_point, guidevec); + add_v3_v3(vec_to_point, guidevec); - //sub_v3_v3v3(pa_loc, pa_loc, pa_zero); - madd_v3_v3fl(effect, vec_to_point, data->strength); - madd_v3_v3fl(veffect, guidedir, data->strength); - totstrength += data->strength; + //sub_v3_v3v3(pa_loc, pa_loc, pa_zero); + madd_v3_v3fl(effect, vec_to_point, data->strength); + madd_v3_v3fl(veffect, guidedir, data->strength); + totstrength += data->strength; - if (pd->flag & PFIELD_GUIDE_PATH_WEIGHT) - totstrength *= weight; - } + if (pd->flag & PFIELD_GUIDE_PATH_WEIGHT) + totstrength *= weight; + } if (totstrength != 0.0f) { if (totstrength > 1.0f) @@ -2232,13 +2232,13 @@ static void do_rough(float *loc, float mat[4][4], float t, float fac, float size float rco[3]; if (thres != 0.0f) - if ((float)fabs((float)(-1.5f+loc[0]+loc[1]+loc[2]))<1.5f*thres) return; + if ((float)fabs((float)(-1.5f + loc[0] + loc[1] + loc[2])) < 1.5f * thres) return; copy_v3_v3(rco, loc); mul_v3_fl(rco, t); - rough[0]=-1.0f+2.0f*BLI_gTurbulence(size, rco[0], rco[1], rco[2], 2, 0, 2); - rough[1]=-1.0f+2.0f*BLI_gTurbulence(size, rco[1], rco[2], rco[0], 2, 0, 2); - rough[2]=-1.0f+2.0f*BLI_gTurbulence(size, rco[2], rco[0], rco[1], 2, 0, 2); + rough[0] = -1.0f + 2.0f * BLI_gTurbulence(size, rco[0], rco[1], rco[2], 2, 0, 2); + rough[1] = -1.0f + 2.0f * BLI_gTurbulence(size, rco[1], rco[2], rco[0], 2, 0, 2); + rough[2] = -1.0f + 2.0f * BLI_gTurbulence(size, rco[2], rco[0], rco[1], 2, 0, 2); madd_v3_v3fl(state->co, mat[0], fac * rough[0]); madd_v3_v3fl(state->co, mat[1], fac * rough[1]); @@ -2249,10 +2249,10 @@ static void do_rough_end(float *loc, float mat[4][4], float t, float fac, float float rough[2]; float roughfac; - roughfac=fac*(float)pow((double)t, shape); + roughfac = fac * (float)pow((double)t, shape); copy_v2_v2(rough, loc); - rough[0]=-1.0f+2.0f*rough[0]; - rough[1]=-1.0f+2.0f*rough[1]; + rough[0] = -1.0f + 2.0f * rough[0]; + rough[1] = -1.0f + 2.0f * rough[1]; mul_v2_fl(rough, roughfac); madd_v3_v3fl(state->co, mat[0], rough[0]); @@ -2268,23 +2268,23 @@ static void do_path_effectors(ParticleSimulationData *sim, int i, ParticleCacheK if (sim->psys->flag & PSYS_HAIR_DYNAMICS) return; - copy_v3_v3(eff_key.co, (ca-1)->co); - copy_v3_v3(eff_key.vel, (ca-1)->vel); - copy_qt_qt(eff_key.rot, (ca-1)->rot); + copy_v3_v3(eff_key.co, (ca - 1)->co); + copy_v3_v3(eff_key.vel, (ca - 1)->vel); + copy_qt_qt(eff_key.rot, (ca - 1)->rot); - pd_point_from_particle(sim, sim->psys->particles+i, &eff_key, &epoint); + 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*powf((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); normalize_v3(force); if (k < steps) - sub_v3_v3v3(vec, (ca+1)->co, ca->co); + sub_v3_v3v3(vec, (ca + 1)->co, ca->co); - madd_v3_v3v3fl(ca->co, (ca-1)->co, force, *length); + madd_v3_v3v3fl(ca->co, (ca - 1)->co, force, *length); if (k < steps) *length = len_v3(vec); @@ -2296,10 +2296,10 @@ static int check_path_length(int k, ParticleCacheKey *keys, ParticleCacheKey *st add_v3_v3v3(state->co, (state - 1)->co, dvec); keys->steps = k; /* something over the maximum step value */ - return k=100000; + return k = 100000; } else { - *cur_length+=length; + *cur_length += length; return k; } } @@ -2308,7 +2308,7 @@ static void offset_child(ChildParticle *cpa, ParticleKey *par, float *par_rot, P copy_v3_v3(child->co, cpa->fuv); mul_v3_fl(child->co, radius); - child->co[0]*=flat; + child->co[0] *= flat; copy_v3_v3(child->vel, par->vel); @@ -2323,7 +2323,7 @@ static void offset_child(ChildParticle *cpa, ParticleKey *par, float *par_rot, P } float *psys_cache_vgroup(DerivedMesh *dm, ParticleSystem *psys, int vgroup) { - float *vg=0; + float *vg = 0; if (vgroup < 0) { /* hair dynamics pinning vgroup */ @@ -2332,15 +2332,15 @@ float *psys_cache_vgroup(DerivedMesh *dm, ParticleSystem *psys, int vgroup) else if (psys->vgroup[vgroup]) { MDeformVert *dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); if (dvert) { - int totvert=dm->getNumVerts(dm), i; - vg=MEM_callocN(sizeof(float)*totvert, "vg_cache"); - if (psys->vg_neg&(1<<vgroup)) { - for (i=0; i<totvert; i++) - vg[i]= 1.0f - defvert_find_weight(&dvert[i], psys->vgroup[vgroup] - 1); + int totvert = dm->getNumVerts(dm), i; + vg = MEM_callocN(sizeof(float) * totvert, "vg_cache"); + if (psys->vg_neg & (1 << vgroup)) { + for (i = 0; i < totvert; i++) + vg[i] = 1.0f - defvert_find_weight(&dvert[i], psys->vgroup[vgroup] - 1); } else { - for (i=0; i<totvert; i++) - vg[i]= defvert_find_weight(&dvert[i], psys->vgroup[vgroup] - 1); + for (i = 0; i < totvert; i++) + vg[i] = defvert_find_weight(&dvert[i], psys->vgroup[vgroup] - 1); } } } @@ -2348,29 +2348,29 @@ float *psys_cache_vgroup(DerivedMesh *dm, ParticleSystem *psys, int vgroup) } void psys_find_parents(ParticleSimulationData *sim) { - ParticleSettings *part=sim->psys->part; + ParticleSettings *part = sim->psys->part; KDTree *tree; ChildParticle *cpa; - int p, totparent, totchild=sim->psys->totchild; + int p, totparent, totchild = sim->psys->totchild; float co[3], orco[3]; - int from=PART_FROM_FACE; - totparent=(int)(totchild*part->parents*0.3f); + int from = PART_FROM_FACE; + 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; + totparent *= (float)part->child_nbr / (float)part->ren_child_nbr; - tree=BLI_kdtree_new(totparent); + tree = BLI_kdtree_new(totparent); - for (p=0, cpa=sim->psys->child; p<totparent; p++, cpa++) { + for (p = 0, cpa = sim->psys->child; p < totparent; p++, cpa++) { psys_particle_on_emitter(sim->psmd, from, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, co, 0, 0, 0, orco, 0); BLI_kdtree_insert(tree, p, orco, NULL); } BLI_kdtree_balance(tree); - for (; p<totchild; p++, cpa++) { + for (; p < totchild; p++, cpa++) { psys_particle_on_emitter(sim->psmd, from, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, co, 0, 0, 0, orco, 0); - cpa->parent=BLI_kdtree_find_nearest(tree, orco, NULL, NULL); + cpa->parent = BLI_kdtree_find_nearest(tree, orco, NULL, NULL); } BLI_kdtree_free(tree); @@ -2399,7 +2399,7 @@ static void get_strand_normal(Material *ma, const float surfnor[3], float surfdi if (ma->strand_surfnor > 0.0f) { if (ma->strand_surfnor > surfdist) { - blend= (ma->strand_surfnor - surfdist)/ma->strand_surfnor; + blend = (ma->strand_surfnor - surfdist) / ma->strand_surfnor; interp_v3_v3v3(vnor, vnor, surfnor, blend); normalize_v3(vnor); } @@ -2410,64 +2410,64 @@ static void get_strand_normal(Material *ma, const float surfnor[3], float surfdi static int psys_threads_init_path(ParticleThread *threads, Scene *scene, float cfra, int editupdate) { - ParticleThreadContext *ctx= threads[0].ctx; + ParticleThreadContext *ctx = threads[0].ctx; /* Object *ob= ctx->sim.ob; */ - ParticleSystem *psys= ctx->sim.psys; + ParticleSystem *psys = ctx->sim.psys; ParticleSettings *part = psys->part; /* ParticleEditSettings *pset = &scene->toolsettings->particle; */ - int totparent=0, between=0; + int totparent = 0, between = 0; int steps = (int)pow(2.0, (double)part->draw_step); int totchild = psys->totchild; - int i, seed, totthread= threads[0].tot; + int i, seed, totthread = threads[0].tot; /*---start figuring out what is actually wanted---*/ if (psys_in_edit_mode(scene, psys)) { ParticleEditSettings *pset = &scene->toolsettings->particle; - if (psys->renderdata==0 && (psys->edit==NULL || pset->flag & PE_DRAW_PART)==0) - totchild=0; + if (psys->renderdata == 0 && (psys->edit == NULL || pset->flag & PE_DRAW_PART) == 0) + totchild = 0; steps = (int)pow(2.0, (double)pset->draw_step); } - if (totchild && part->childtype==PART_CHILD_FACES) { - totparent=(int)(totchild*part->parents*0.3f); + 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; + totparent *= (float)part->child_nbr / (float)part->ren_child_nbr; /* part->parents could still be 0 so we can't test with totparent */ - between=1; + between = 1; } if (psys->renderdata) - steps=(int)pow(2.0, (double)part->ren_step); + steps = (int)pow(2.0, (double)part->ren_step); else { - totchild=(int)((float)totchild*(float)part->disp/100.0f); - totparent=MIN2(totparent, totchild); + totchild = (int)((float)totchild * (float)part->disp / 100.0f); + totparent = MIN2(totparent, totchild); } - if (totchild==0) return 0; + if (totchild == 0) return 0; /* init random number generator */ - seed= 31415926 + ctx->sim.psys->seed; + seed = 31415926 + ctx->sim.psys->seed; if (ctx->editupdate || totchild < 10000) - totthread= 1; + totthread = 1; - for (i=0; i<totthread; i++) { - threads[i].rng_path= rng_new(seed); - threads[i].tot= totthread; + for (i = 0; i < totthread; i++) { + threads[i].rng_path = rng_new(seed); + threads[i].tot = totthread; } /* fill context values */ - ctx->between= between; - ctx->steps= steps; - ctx->totchild= totchild; - ctx->totparent= totparent; - ctx->parent_pass= 0; - ctx->cfra= cfra; - ctx->editupdate= editupdate; + ctx->between = between; + ctx->steps = steps; + ctx->totchild = totchild; + ctx->totparent = totparent; + ctx->parent_pass = 0; + ctx->cfra = cfra; + ctx->editupdate = editupdate; psys->lattice = psys_get_lattice(&ctx->sim); @@ -2483,7 +2483,7 @@ static int psys_threads_init_path(ParticleThread *threads, Scene *scene, float c /* set correct ipo timing */ #if 0 // XXX old animation system - if (part->flag&PART_ABS_TIME && part->ipo) { + if (part->flag & PART_ABS_TIME && part->ipo) { calc_ipo(part->ipo, cfra); execute_ipo((ID *)part, part->ipo); } @@ -2495,15 +2495,15 @@ static int psys_threads_init_path(ParticleThread *threads, Scene *scene, float c /* note: this function must be thread safe, except for branching! */ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle *cpa, ParticleCacheKey *child_keys, int i) { - ParticleThreadContext *ctx= thread->ctx; - Object *ob= ctx->sim.ob; + ParticleThreadContext *ctx = thread->ctx; + Object *ob = ctx->sim.ob; ParticleSystem *psys = ctx->sim.psys; ParticleSettings *part = psys->part; - ParticleCacheKey **cache= psys->childcache; - ParticleCacheKey **pcache= psys_in_edit_mode(ctx->sim.scene, psys) ? psys->edit->pathcache : psys->pathcache; + ParticleCacheKey **cache = psys->childcache; + ParticleCacheKey **pcache = psys_in_edit_mode(ctx->sim.scene, psys) ? psys->edit->pathcache : psys->pathcache; ParticleCacheKey *child, *par = NULL, *key[4]; ParticleTexture ptex; - float *cpa_fuv=0, *par_rot=0, rot[4]; + float *cpa_fuv = 0, *par_rot = 0, rot[4]; float orco[3], ornor[3], hairmat[4][4], t, dvec[3], off1[4][3], off2[4][3]; float length, max_length = 1.0f, cur_length = 0.0f; float eff_length, eff_vec[3], weight[4]; @@ -2516,7 +2516,7 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle if (ctx->between) { ParticleData *pa = psys->particles + cpa->pa[0]; int w, needupdate; - float foffset, wsum=0.f; + float foffset, wsum = 0.f; float co[3]; float p_min = part->parting_min; float p_max = part->parting_max; @@ -2524,11 +2524,11 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle float p_fac = part->parents > 0.f ? 0.f : part->parting_fac; if (ctx->editupdate) { - needupdate= 0; - w= 0; - while (w<4 && cpa->pa[w]>=0) { + needupdate = 0; + w = 0; + while (w < 4 && cpa->pa[w] >= 0) { if (psys->edit->points[cpa->pa[w]].flag & PEP_EDIT_RECALC) { - needupdate= 1; + needupdate = 1; break; } w++; @@ -2537,11 +2537,11 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle if (!needupdate) return; else - memset(child_keys, 0, sizeof(*child_keys)*(ctx->steps+1)); + memset(child_keys, 0, sizeof(*child_keys) * (ctx->steps + 1)); } /* get parent paths */ - for (w=0; w<4; w++) { + for (w = 0; w < 4; w++) { if (cpa->pa[w] >= 0) { key[w] = pcache[cpa->pa[w]]; weight[w] = cpa->w[w]; @@ -2554,20 +2554,20 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle /* modify weights to create parting */ if (p_fac > 0.f) { - for (w=0; w<4; w++) { + for (w = 0; w < 4; w++) { if (w && weight[w] > 0.f) { float d; if (part->flag & PART_CHILD_LONG_HAIR) { /* For long hair use tip distance/root distance as parting factor instead of root to tip angle. */ float d1 = len_v3v3(key[0]->co, key[w]->co); - float d2 = len_v3v3((key[0]+key[0]->steps-1)->co, (key[w]+key[w]->steps-1)->co); + float d2 = len_v3v3((key[0] + key[0]->steps - 1)->co, (key[w] + key[w]->steps - 1)->co); - d = d1 > 0.f ? d2/d1 - 1.f : 10000.f; + d = d1 > 0.f ? d2 / d1 - 1.f : 10000.f; } else { float v1[3], v2[3]; - sub_v3_v3v3(v1, (key[0]+key[0]->steps-1)->co, key[0]->co); - sub_v3_v3v3(v2, (key[w]+key[w]->steps-1)->co, key[w]->co); + sub_v3_v3v3(v1, (key[0] + key[0]->steps - 1)->co, key[0]->co); + sub_v3_v3v3(v2, (key[w] + key[w]->steps - 1)->co, key[w]->co); normalize_v3(v1); normalize_v3(v2); @@ -2575,7 +2575,7 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle } if (p_max > p_min) - d = (d - p_min)/(p_max - p_min); + d = (d - p_min) / (p_max - p_min); else d = (d - p_min) <= 0.f ? 0.f : 1.f; @@ -2586,7 +2586,7 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle } wsum += weight[w]; } - for (w=0; w<4; w++) + for (w = 0; w < 4; w++) weight[w] /= wsum; interp_v4_v4v4(weight, cpa->w, weight, p_fac); @@ -2603,7 +2603,7 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle mul_m4_v3(ob->obmat, co); - for (w=0; w<4; w++) + for (w = 0; w < 4; w++) sub_v3_v3v3(off1[w], co, key[w]->co); psys_mat_hair_to_global(ob, ctx->sim.psmd->dm, psys->part->from, pa, hairmat); @@ -2615,7 +2615,7 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle if (!(psys->edit->points[cpa->parent].flag & PEP_EDIT_RECALC)) return; - memset(child_keys, 0, sizeof(*child_keys)*(ctx->steps+1)); + memset(child_keys, 0, sizeof(*child_keys) * (ctx->steps + 1)); } /* get the parent path */ @@ -2642,66 +2642,66 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle } /* create the child path */ - for (k=0, child=child_keys; k<=ctx->steps; k++, child++) { + for (k = 0, child = child_keys; k <= ctx->steps; k++, child++) { if (ctx->between) { - int w=0; + int w = 0; zero_v3(child->co); zero_v3(child->vel); unit_qt(child->rot); - for (w=0; w<4; w++) { + for (w = 0; w < 4; w++) { copy_v3_v3(off2[w], off1[w]); if (part->flag & PART_CHILD_LONG_HAIR) { /* Use parent rotation (in addition to emission location) to determine child offset. */ if (k) - mul_qt_v3((key[w]+k)->rot, off2[w]); + mul_qt_v3((key[w] + k)->rot, off2[w]); /* Fade the effect of rotation for even lengths in the end */ - project_v3_v3v3(dvec, off2[w], (key[w]+k)->vel); - madd_v3_v3fl(off2[w], dvec, -(float)k/(float)ctx->steps); + project_v3_v3v3(dvec, off2[w], (key[w] + k)->vel); + madd_v3_v3fl(off2[w], dvec, -(float)k / (float)ctx->steps); } - add_v3_v3(off2[w], (key[w]+k)->co); + add_v3_v3(off2[w], (key[w] + k)->co); } /* child position is the weighted sum of parent positions */ interp_v3_v3v3v3v3(child->co, off2[0], off2[1], off2[2], off2[3], weight); - interp_v3_v3v3v3v3(child->vel, (key[0]+k)->vel, (key[1]+k)->vel, (key[2]+k)->vel, (key[3]+k)->vel, weight); + interp_v3_v3v3v3v3(child->vel, (key[0] + k)->vel, (key[1] + k)->vel, (key[2] + k)->vel, (key[3] + k)->vel, weight); - copy_qt_qt(child->rot, (key[0]+k)->rot); + copy_qt_qt(child->rot, (key[0] + k)->rot); } else { if (k) { - mul_qt_qtqt(rot, (key[0]+k)->rot, key[0]->rot); + mul_qt_qtqt(rot, (key[0] + k)->rot, key[0]->rot); par_rot = rot; } else { par_rot = key[0]->rot; } /* offset the child from the parent position */ - offset_child(cpa, (ParticleKey*)(key[0]+k), par_rot, (ParticleKey*)child, part->childflat, part->childrad); + offset_child(cpa, (ParticleKey *)(key[0] + k), par_rot, (ParticleKey *)child, part->childflat, part->childrad); } - child->time = (float)k/(float)ctx->steps; + child->time = (float)k / (float)ctx->steps; } /* apply effectors */ if (part->flag & PART_CHILD_EFFECT) { - for (k=0, child=child_keys; k<=ctx->steps; k++, child++) { + for (k = 0, child = child_keys; k <= ctx->steps; k++, child++) { if (k) { do_path_effectors(&ctx->sim, cpa->pa[0], child, k, ctx->steps, child_keys->co, ptex.effector, 0.0f, ctx->cfra, &eff_length, eff_vec); } else { - sub_v3_v3v3(eff_vec, (child+1)->co, child->co); + sub_v3_v3v3(eff_vec, (child + 1)->co, child->co); eff_length = len_v3(eff_vec); } } } - for (k=0, child=child_keys; k<=ctx->steps; k++, child++) { - t = (float)k/(float)ctx->steps; + for (k = 0, child = child_keys; k <= ctx->steps; k++, child++) { + t = (float)k / (float)ctx->steps; if (ctx->totparent) /* this is now threadsafe, virtual parents are calculated before rest of children */ @@ -2711,7 +2711,7 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle if (par) { if (k) { - mul_qt_qtqt(rot, (par+k)->rot, par->rot); + mul_qt_qtqt(rot, (par + k)->rot, par->rot); par_rot = rot; } else { @@ -2724,21 +2724,21 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle do_child_modifiers(&ctx->sim, &ptex, (ParticleKey *)par, par_rot, cpa, orco, hairmat, (ParticleKey *)child, t); /* we have to correct velocity because of kink & clump */ - if (k>1) { - sub_v3_v3v3((child-1)->vel, child->co, (child-2)->co); - mul_v3_fl((child-1)->vel, 0.5); + if (k > 1) { + sub_v3_v3v3((child - 1)->vel, child->co, (child - 2)->co); + mul_v3_fl((child - 1)->vel, 0.5); if (ctx->ma && (part->draw_col == PART_DRAW_COL_MAT)) - get_strand_normal(ctx->ma, ornor, cur_length, (child-1)->vel); + get_strand_normal(ctx->ma, ornor, cur_length, (child - 1)->vel); } if (k == ctx->steps) - sub_v3_v3v3(child->vel, child->co, (child-1)->co); + sub_v3_v3v3(child->vel, child->co, (child - 1)->co); /* check if path needs to be cut before actual end of data points */ if (k) { - sub_v3_v3v3(dvec, child->co, (child-1)->co); - length = 1.0f/(float)ctx->steps; + sub_v3_v3v3(dvec, child->co, (child - 1)->co); + length = 1.0f / (float)ctx->steps; k = check_path_length(k, child_keys, child, max_length, &cur_length, length, dvec); } else { @@ -2760,20 +2760,20 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle static void *exec_child_path_cache(void *data) { - ParticleThread *thread= (ParticleThread*)data; - ParticleThreadContext *ctx= thread->ctx; - ParticleSystem *psys= ctx->sim.psys; - ParticleCacheKey **cache= psys->childcache; + ParticleThread *thread = (ParticleThread *)data; + ParticleThreadContext *ctx = thread->ctx; + ParticleSystem *psys = ctx->sim.psys; + ParticleCacheKey **cache = psys->childcache; ChildParticle *cpa; - int i, totchild= ctx->totchild, first= 0; + int i, totchild = ctx->totchild, first = 0; if (thread->tot > 1) { - first= ctx->parent_pass? 0 : ctx->totparent; - totchild= ctx->parent_pass? ctx->totparent : ctx->totchild; + first = ctx->parent_pass ? 0 : ctx->totparent; + totchild = ctx->parent_pass ? ctx->totparent : ctx->totchild; } - cpa= psys->child + first + thread->num; - for (i=first+thread->num; i<totchild; i+=thread->tot, cpa+=thread->tot) + cpa = psys->child + first + thread->num; + for (i = first + thread->num; i < totchild; i += thread->tot, cpa += thread->tot) psys_thread_create_path(thread, cpa, cache[i], i); return 0; @@ -2789,16 +2789,16 @@ void psys_cache_child_paths(ParticleSimulationData *sim, float cfra, int editupd if (sim->psys->flag & PSYS_GLOBAL_HAIR) return; - pthreads= psys_threads_create(sim); + pthreads = psys_threads_create(sim); if (!psys_threads_init_path(pthreads, sim->scene, cfra, editupdate)) { psys_threads_free(pthreads); return; } - ctx= pthreads[0].ctx; - totchild= ctx->totchild; - totparent= ctx->totparent; + ctx = pthreads[0].ctx; + totchild = ctx->totchild; + totparent = ctx->totparent; if (editupdate && sim->psys->childcache && totchild == sim->psys->totchildcache) { ; /* just overwrite the existing cache */ @@ -2806,11 +2806,11 @@ void psys_cache_child_paths(ParticleSimulationData *sim, float cfra, int editupd else { /* clear out old and create new empty path cache */ free_child_path_cache(sim->psys); - sim->psys->childcache= psys_alloc_path_cache_buffers(&sim->psys->childcachebufs, totchild, ctx->steps+1); + sim->psys->childcache = psys_alloc_path_cache_buffers(&sim->psys->childcachebufs, totchild, ctx->steps + 1); sim->psys->totchildcache = totchild; } - totthread= pthreads[0].tot; + totthread = pthreads[0].tot; if (totthread > 1) { @@ -2818,20 +2818,20 @@ void psys_cache_child_paths(ParticleSimulationData *sim, float cfra, int editupd if (totparent) { BLI_init_threads(&threads, exec_child_path_cache, totthread); - for (i=0; i<totthread; i++) { + for (i = 0; i < totthread; i++) { pthreads[i].ctx->parent_pass = 1; BLI_insert_thread(&threads, &pthreads[i]); } BLI_end_threads(&threads); - for (i=0; i<totthread; i++) + for (i = 0; i < totthread; i++) pthreads[i].ctx->parent_pass = 0; } BLI_init_threads(&threads, exec_child_path_cache, totthread); - for (i=0; i<totthread; i++) + for (i = 0; i < totthread; i++) BLI_insert_thread(&threads, &pthreads[i]); BLI_end_threads(&threads); @@ -2847,35 +2847,35 @@ static void cache_key_incremental_rotation(ParticleCacheKey *key0, ParticleCache float cosangle, angle, tangent[3], normal[3], q[4]; switch (i) { - case 0: - /* start from second key */ - break; - case 1: - /* calculate initial tangent for incremental rotations */ - sub_v3_v3v3(prev_tangent, key0->co, key1->co); - normalize_v3(prev_tangent); - unit_qt(key1->rot); - break; - default: - sub_v3_v3v3(tangent, key0->co, key1->co); - normalize_v3(tangent); - - cosangle= dot_v3v3(tangent, prev_tangent); - - /* note we do the comparison on cosangle instead of - * angle, since floating point accuracy makes it give - * different results across platforms */ - if (cosangle > 0.999999f) { - copy_v4_v4(key1->rot, key2->rot); - } - else { - angle= saacos(cosangle); - cross_v3_v3v3(normal, prev_tangent, tangent); - axis_angle_to_quat(q, normal, angle); - mul_qt_qtqt(key1->rot, q, key2->rot); - } + case 0: + /* start from second key */ + break; + case 1: + /* calculate initial tangent for incremental rotations */ + sub_v3_v3v3(prev_tangent, key0->co, key1->co); + normalize_v3(prev_tangent); + unit_qt(key1->rot); + break; + default: + sub_v3_v3v3(tangent, key0->co, key1->co); + normalize_v3(tangent); + + cosangle = dot_v3v3(tangent, prev_tangent); - copy_v3_v3(prev_tangent, tangent); + /* note we do the comparison on cosangle instead of + * angle, since floating point accuracy makes it give + * different results across platforms */ + if (cosangle > 0.999999f) { + copy_v4_v4(key1->rot, key2->rot); + } + else { + angle = saacos(cosangle); + cross_v3_v3v3(normal, prev_tangent, tangent); + axis_angle_to_quat(q, normal, angle); + mul_qt_qtqt(key1->rot, q, key2->rot); + } + + copy_v3_v3(prev_tangent, tangent); } } @@ -2892,7 +2892,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) ParticleSettings *part = psys->part; ParticleCacheKey *ca, **cache; - DerivedMesh *hair_dm = (psys->part->type==PART_HAIR && psys->flag & PSYS_HAIR_DYNAMICS) ? psys->hair_out_dm : NULL; + DerivedMesh *hair_dm = (psys->part->type == PART_HAIR && psys->flag & PSYS_HAIR_DYNAMICS) ? psys->hair_out_dm : NULL; ParticleKey result; @@ -2911,16 +2911,16 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) int steps = (int)pow(2.0, (double)(psys->renderdata ? part->ren_step : part->draw_step)); int totpart = psys->totpart; float length, vec[3]; - float *vg_effector= NULL; - float *vg_length= NULL, pa_length=1.0f; + float *vg_effector = NULL; + float *vg_length = NULL, pa_length = 1.0f; int keyed, baked; /* we don't have anything valid to create paths from so let's quit here */ - if ((psys->flag & PSYS_HAIR_DONE || psys->flag & PSYS_KEYED || psys->pointcache)==0) + if ((psys->flag & PSYS_HAIR_DONE || psys->flag & PSYS_KEYED || psys->pointcache) == 0) return; if (psys_in_edit_mode(sim->scene, psys)) - if (psys->renderdata==0 && (psys->edit==NULL || pset->flag & PE_DRAW_PART)==0) + if (psys->renderdata == 0 && (psys->edit == NULL || pset->flag & PE_DRAW_PART) == 0) return; keyed = psys->flag & PSYS_KEYED; @@ -2928,15 +2928,15 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) /* clear out old and create new empty path cache */ psys_free_path_cache(psys, psys->edit); - cache= psys->pathcache= psys_alloc_path_cache_buffers(&psys->pathcachebufs, totpart, steps+1); + cache = psys->pathcache = psys_alloc_path_cache_buffers(&psys->pathcachebufs, totpart, steps + 1); psys->lattice = psys_get_lattice(sim); - ma= give_current_material(sim->ob, psys->part->omat); + ma = give_current_material(sim->ob, psys->part->omat); if (ma && (psys->part->draw_col == PART_DRAW_COL_MAT)) copy_v3_v3(col, &ma->r); - if ((psys->flag & PSYS_GLOBAL_HAIR)==0) { - if ((psys->part->flag & PART_CHILD_EFFECT)==0) + 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) @@ -2963,7 +2963,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) pind.bspline = (psys->part->flag & PART_HAIR_BSPLINE); pind.dm = hair_dm; - memset(cache[p], 0, sizeof(*cache[p])*(steps+1)); + memset(cache[p], 0, sizeof(*cache[p]) * (steps + 1)); cache[p]->steps = steps; @@ -2994,7 +2994,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) dietime = birthtime + pa_length * (dietime - birthtime); /*--interpolate actual path from data points--*/ - for (k=0, ca=cache[p]; k<=steps; k++, ca++) { + for (k = 0, ca = cache[p]; k <= steps; k++, ca++) { time = (float)k / (float)steps; t = birthtime + time * (dietime - birthtime); result.time = -t; @@ -3016,45 +3016,45 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) if (!(psys->flag & PSYS_GLOBAL_HAIR)) { /* apply effectors */ if ((psys->part->flag & PART_CHILD_EFFECT) == 0) { - float effector= 1.0f; + float effector = 1.0f; if (vg_effector) - effector*= psys_particle_value_from_verts(psmd->dm, psys->part->from, pa, vg_effector); + effector *= psys_particle_value_from_verts(psmd->dm, psys->part->from, pa, vg_effector); - sub_v3_v3v3(vec, (cache[p]+1)->co, cache[p]->co); + sub_v3_v3v3(vec, (cache[p] + 1)->co, cache[p]->co); length = len_v3(vec); - for (k=1, ca=cache[p]+1; k<=steps; k++, ca++) + for (k = 1, ca = cache[p] + 1; k <= steps; k++, ca++) do_path_effectors(sim, p, ca, k, steps, cache[p]->co, effector, dfra, cfra, &length, vec); } /* apply guide curves to path data */ - if (sim->psys->effectors && (psys->part->flag & PART_CHILD_EFFECT)==0) { - for (k=0, ca=cache[p]; k<=steps; k++, ca++) + if (sim->psys->effectors && (psys->part->flag & PART_CHILD_EFFECT) == 0) { + for (k = 0, ca = cache[p]; k <= steps; k++, ca++) /* ca is safe to cast, since only co and vel are used */ - do_guides(sim->psys->effectors, (ParticleKey*)ca, p, (float)k/(float)steps); + do_guides(sim->psys->effectors, (ParticleKey *)ca, p, (float)k / (float)steps); } /* lattices have to be calculated separately to avoid mixups between effector calculations */ if (psys->lattice) { - for (k=0, ca=cache[p]; k<=steps; k++, ca++) + for (k = 0, ca = cache[p]; k <= steps; k++, ca++) calc_latt_deform(psys->lattice, ca->co, 1.0f); } } /* finally do rotation & velocity */ - for (k=1, ca=cache[p]+1; k<=steps; k++, ca++) { + for (k = 1, ca = cache[p] + 1; k <= steps; k++, ca++) { cache_key_incremental_rotation(ca, ca - 1, ca - 2, prev_tangent, k); if (k == steps) copy_qt_qt(ca->rot, (ca - 1)->rot); /* set velocity */ - sub_v3_v3v3(ca->vel, ca->co, (ca-1)->co); + sub_v3_v3v3(ca->vel, ca->co, (ca - 1)->co); - if (k==1) - copy_v3_v3((ca-1)->vel, ca->vel); + if (k == 1) + copy_v3_v3((ca - 1)->vel, ca->vel); - ca->time = (float)k/(float)steps; + ca->time = (float)k / (float)steps; } /* First rotation is based on emitting face orientation. * This is way better than having flipping rotations resulting @@ -3070,7 +3070,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) if (psys->lattice) { end_latt_deform(psys->lattice); - psys->lattice= NULL; + psys->lattice = NULL; } if (vg_effector) @@ -3081,7 +3081,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) } void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cfra) { - ParticleCacheKey *ca, **cache= edit->pathcache; + ParticleCacheKey *ca, **cache = edit->pathcache; ParticleEditSettings *pset = &scene->toolsettings->particle; PTCacheEditPoint *point = NULL; @@ -3099,7 +3099,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf 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); - int totpart = edit->totpoint, recalc_set=0; + int totpart = edit->totpoint, recalc_set = 0; float sel_col[3]; float nosel_col[3]; @@ -3108,10 +3108,10 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf if (!cache || edit->totpoint != edit->totcached) { /* clear out old and create new empty path cache */ psys_free_path_cache(edit->psys, edit); - cache= edit->pathcache= psys_alloc_path_cache_buffers(&edit->pathcachebufs, totpart, steps+1); + cache = edit->pathcache = psys_alloc_path_cache_buffers(&edit->pathcachebufs, totpart, steps + 1); /* set flag for update (child particles check this too) */ - for (i=0, point=edit->points; i<totpart; i++, point++) + for (i = 0, point = edit->points; i < totpart; i++, point++) point->flag |= PEP_EDIT_RECALC; recalc_set = 1; } @@ -3119,7 +3119,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf /* frs_sec = (psys || edit->pid.flag & PTCACHE_VEL_PER_SEC) ? 25.0f : 1.0f; */ /* UNUSED */ if (pset->brushtype == PE_BRUSH_WEIGHT) { - ;/* use weight painting colors now... */ + ; /* use weight painting colors now... */ } else { sel_col[0] = (float)edit->sel_col[0] / 255.0f; @@ -3131,7 +3131,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf } /*---first main loop: create all actual particles' paths---*/ - for (i=0, point=edit->points; i<totpart; i++, pa+=pa?1:0, point++) { + for (i = 0, point = edit->points; i < totpart; i++, pa += pa ? 1 : 0, point++) { if (edit->totcached && !(point->flag & PEP_EDIT_RECALC)) continue; @@ -3148,14 +3148,14 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf /* should init_particle_interpolation set this ? */ - if (pset->brushtype==PE_BRUSH_WEIGHT) { + if (pset->brushtype == PE_BRUSH_WEIGHT) { pind.hkey[0] = NULL; /* pa != NULL since the weight brush is only available for hair */ pind.hkey[1] = pa->hair; } - memset(cache[i], 0, sizeof(*cache[i])*(steps+1)); + memset(cache[i], 0, sizeof(*cache[i]) * (steps + 1)); cache[i]->steps = steps; @@ -3178,14 +3178,14 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf } /*--interpolate actual path from data points--*/ - for (k=0, ca=cache[i]; k<=steps; k++, ca++) { + for (k = 0, ca = cache[i]; k <= steps; k++, ca++) { time = (float)k / (float)steps; t = birthtime + time * (dietime - birthtime); result.time = -t; do_particle_interpolation(psys, i, pa, t, &pind, &result); copy_v3_v3(ca->co, result.co); - /* non-hair points are already in global space */ + /* non-hair points are already in global space */ if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) { mul_m4_v3(hairmat, ca->co); @@ -3198,7 +3198,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf /* set velocity */ sub_v3_v3v3(ca->vel, ca->co, (ca - 1)->co); - if (k==1) + if (k == 1) copy_v3_v3((ca - 1)->vel, ca->vel); } } @@ -3208,15 +3208,15 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf } /* selection coloring in edit mode */ - if (pset->brushtype==PE_BRUSH_WEIGHT) { + if (pset->brushtype == PE_BRUSH_WEIGHT) { float t2; - if (k==0) { + if (k == 0) { weight_to_rgb(ca->col, pind.hkey[1]->weight); } else { float w1[3], w2[3]; - keytime = (t - (*pind.ekey[0]->time))/((*pind.ekey[1]->time) - (*pind.ekey[0]->time)); + keytime = (t - (*pind.ekey[0]->time)) / ((*pind.ekey[1]->time) - (*pind.ekey[0]->time)); weight_to_rgb(w1, pind.hkey[0]->weight); weight_to_rgb(w2, pind.hkey[1]->weight); @@ -3226,7 +3226,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf /* at the moment this is only used for weight painting. * will need to move out of this check if its used elsewhere. */ - t2 = birthtime + ((float)k/(float)steps) * (dietime - birthtime); + t2 = birthtime + ((float)k / (float)steps) * (dietime - birthtime); while (pind.hkey[1]->time < t2) pind.hkey[1]++; pind.hkey[0] = pind.hkey[1] - 1; @@ -3237,13 +3237,13 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf copy_v3_v3(ca->col, sel_col); } else { - keytime = (t - (*pind.ekey[0]->time))/((*pind.ekey[1]->time) - (*pind.ekey[0]->time)); + keytime = (t - (*pind.ekey[0]->time)) / ((*pind.ekey[1]->time) - (*pind.ekey[0]->time)); interp_v3_v3v3(ca->col, sel_col, nosel_col, keytime); } } else { if ((ekey + (pind.ekey[1] - point->keys))->flag & PEK_SELECT) { - keytime = (t - (*pind.ekey[0]->time))/((*pind.ekey[1]->time) - (*pind.ekey[0]->time)); + keytime = (t - (*pind.ekey[0]->time)) / ((*pind.ekey[1]->time) - (*pind.ekey[0]->time)); interp_v3_v3v3(ca->col, nosel_col, sel_col, keytime); } else { @@ -3269,18 +3269,18 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf edit->totcached = totpart; if (psys) { - ParticleSimulationData sim= {0}; - sim.scene= scene; - sim.ob= ob; - sim.psys= psys; - sim.psmd= psys_get_modifier(ob, psys); + ParticleSimulationData sim = {0}; + sim.scene = scene; + sim.ob = ob; + sim.psys = psys; + sim.psmd = psys_get_modifier(ob, psys); psys_cache_child_paths(&sim, cfra, 1); } /* clear recalc flag if set here */ if (recalc_set) { - for (i=0, point=edit->points; i<totpart; i++, point++) + for (i = 0, point = edit->points; i < totpart; i++, point++) point->flag &= ~PEP_EDIT_RECALC; } } @@ -3293,9 +3293,9 @@ void copy_particle_key(ParticleKey *to, ParticleKey *from, int time) memcpy(to, from, sizeof(ParticleKey)); } else { - float to_time=to->time; + float to_time = to->time; memcpy(to, from, sizeof(ParticleKey)); - to->time=to_time; + to->time = to_time; } } void psys_get_from_key(ParticleKey *key, float *loc, float *vel, float *rot, float *time) @@ -3303,7 +3303,7 @@ void psys_get_from_key(ParticleKey *key, float *loc, float *vel, float *rot, flo if (loc) copy_v3_v3(loc, key->co); if (vel) copy_v3_v3(vel, key->vel); if (rot) copy_qt_qt(rot, key->rot); - if (time) *time=key->time; + if (time) *time = key->time; } /*-------changing particle keys from space to another-------*/ #if 0 @@ -3326,33 +3326,33 @@ static void triatomat(float *v1, float *v2, float *v3, float (*uv)[2], float mat { float det, w1, w2, d1[2], d2[2]; - memset(mat, 0, sizeof(float)*4*4); - mat[3][3]= 1.0f; + memset(mat, 0, sizeof(float) * 4 * 4); + mat[3][3] = 1.0f; /* first axis is the normal */ normal_tri_v3(mat[2], v1, v2, v3); /* second axis along (1, 0) in uv space */ if (uv) { - d1[0]= uv[1][0] - uv[0][0]; - d1[1]= uv[1][1] - uv[0][1]; - d2[0]= uv[2][0] - uv[0][0]; - d2[1]= uv[2][1] - uv[0][1]; + d1[0] = uv[1][0] - uv[0][0]; + d1[1] = uv[1][1] - uv[0][1]; + d2[0] = uv[2][0] - uv[0][0]; + d2[1] = uv[2][1] - uv[0][1]; - det = d2[0]*d1[1] - d2[1]*d1[0]; + det = d2[0] * d1[1] - d2[1] * d1[0]; if (det != 0.0f) { - det= 1.0f/det; - w1= -d2[1]*det; - w2= d1[1]*det; + det = 1.0f / det; + w1 = -d2[1] * det; + w2 = d1[1] * det; - mat[1][0]= w1*(v2[0] - v1[0]) + w2*(v3[0] - v1[0]); - mat[1][1]= w1*(v2[1] - v1[1]) + w2*(v3[1] - v1[1]); - mat[1][2]= w1*(v2[2] - v1[2]) + w2*(v3[2] - v1[2]); + mat[1][0] = w1 * (v2[0] - v1[0]) + w2 * (v3[0] - v1[0]); + mat[1][1] = w1 * (v2[1] - v1[1]) + w2 * (v3[1] - v1[1]); + mat[1][2] = w1 * (v2[2] - v1[2]) + w2 * (v3[2] - v1[2]); normalize_v3(mat[1]); } else - mat[1][0]= mat[1][1]= mat[1][2]= 0.0f; + mat[1][0] = mat[1][1] = mat[1][2] = 0.0f; } else { sub_v3_v3v3(mat[1], v2, v1); @@ -3370,14 +3370,14 @@ static void psys_face_mat(Object *ob, DerivedMesh *dm, ParticleData *pa, float m OrigSpaceFace *osface; float (*orcodata)[3]; - int i = pa->num_dmcache==DMCACHE_NOTFOUND ? pa->num : pa->num_dmcache; + int i = pa->num_dmcache == DMCACHE_NOTFOUND ? pa->num : pa->num_dmcache; - if (i==-1 || i >= dm->getNumTessFaces(dm)) { unit_m4(mat); return; } + if (i == -1 || i >= dm->getNumTessFaces(dm)) { unit_m4(mat); return; } - mface=dm->getTessFaceData(dm, i, CD_MFACE); - osface=dm->getTessFaceData(dm, i, CD_ORIGSPACE); + mface = dm->getTessFaceData(dm, i, CD_MFACE); + osface = dm->getTessFaceData(dm, i, CD_ORIGSPACE); - if (orco && (orcodata=dm->getVertDataArray(dm, CD_ORCO))) { + if (orco && (orcodata = dm->getVertDataArray(dm, CD_ORCO))) { copy_v3_v3(v[0], orcodata[mface->v1]); copy_v3_v3(v[1], orcodata[mface->v2]); copy_v3_v3(v[2], orcodata[mface->v3]); @@ -3385,7 +3385,7 @@ 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 */ if (DM_get_vert_data_layer(dm, CD_ORIGINDEX)) - transform_mesh_orco_verts(ob->data, v, 3, 1); + BKE_mesh_orco_verts_transform(ob->data, v, 3, 1); } else { dm->getVertCo(dm, mface->v1, v[0]); @@ -3393,7 +3393,7 @@ static void psys_face_mat(Object *ob, DerivedMesh *dm, ParticleData *pa, float m dm->getVertCo(dm, mface->v3, v[2]); } - triatomat(v[0], v[1], v[2], (osface)? osface->uv: NULL, mat); + triatomat(v[0], v[1], v[2], (osface) ? osface->uv : NULL, mat); } void psys_mat_hair_to_object(Object *UNUSED(ob), DerivedMesh *dm, short from, ParticleData *pa, float hairmat[][4]) @@ -3414,7 +3414,7 @@ void psys_mat_hair_to_orco(Object *ob, DerivedMesh *dm, short from, ParticleData /* see psys_face_mat for why this function is called */ if (DM_get_vert_data_layer(dm, CD_ORIGINDEX)) - transform_mesh_orco_verts(ob->data, &orco, 1, 1); + BKE_mesh_orco_verts_transform(ob->data, &orco, 1, 1); copy_v3_v3(hairmat[3], orco); } @@ -3449,7 +3449,7 @@ ModifierData *object_add_particle_system(Scene *scene, Object *ob, const char *n return NULL; psys = ob->particlesystem.first; - for (; psys; psys=psys->next) + for (; psys; psys = psys->next) psys->flag &= ~PSYS_CURRENT; psys = MEM_callocN(sizeof(ParticleSystem), "particle_system"); @@ -3458,24 +3458,24 @@ ModifierData *object_add_particle_system(Scene *scene, Object *ob, const char *n psys->part = psys_new_settings("ParticleSettings", NULL); - if (BLI_countlist(&ob->particlesystem)>1) + if (BLI_countlist(&ob->particlesystem) > 1) BLI_snprintf(psys->name, sizeof(psys->name), "ParticleSystem %i", BLI_countlist(&ob->particlesystem)); else strcpy(psys->name, "ParticleSystem"); - md= modifier_new(eModifierType_ParticleSystem); + md = modifier_new(eModifierType_ParticleSystem); - if (name) BLI_strncpy(md->name, name, sizeof(md->name)); - else BLI_snprintf(md->name, sizeof(md->name), "ParticleSystem %i", BLI_countlist(&ob->particlesystem)); + if (name) BLI_strncpy(md->name, name, sizeof(md->name)); + else BLI_snprintf(md->name, sizeof(md->name), "ParticleSystem %i", BLI_countlist(&ob->particlesystem)); modifier_unique_name(&ob->modifiers, md); - psmd= (ParticleSystemModifierData*) md; - psmd->psys=psys; + psmd = (ParticleSystemModifierData *) md; + psmd->psys = psys; BLI_addtail(&ob->modifiers, md); - psys->totpart=0; - psys->flag = PSYS_ENABLED|PSYS_CURRENT; - psys->cfra = BKE_frame_to_ctime(scene, CFRA + 1); + psys->totpart = 0; + psys->flag = PSYS_ENABLED | PSYS_CURRENT; + psys->cfra = BKE_scene_frame_get_from_ctime(scene, CFRA + 1); DAG_scene_sort(G.main, scene); DAG_id_tag_update(&ob->id, OB_RECALC_DATA); @@ -3507,7 +3507,7 @@ void object_remove_particle_system(Scene *scene, Object *ob) } /* clear modifier */ - psmd= psys_get_modifier(ob, psys); + psmd = psys_get_modifier(ob, psys); BLI_remlink(&ob->modifiers, psmd); modifier_free((ModifierData *)psmd); @@ -3525,64 +3525,64 @@ void object_remove_particle_system(Scene *scene, Object *ob) } static void default_particle_settings(ParticleSettings *part) { - part->type= PART_EMITTER; - part->distr= PART_DISTR_JIT; + part->type = PART_EMITTER; + part->distr = PART_DISTR_JIT; part->draw_as = PART_DRAW_REND; part->ren_as = PART_DRAW_HALO; - part->bb_uv_split=1; - part->bb_align=PART_BB_VIEW; - part->bb_split_offset=PART_BB_OFF_LINEAR; - part->flag=PART_EDISTR|PART_TRAND|PART_HIDE_ADVANCED_HAIR; - - part->sta= 1.0; - part->end= 200.0; - part->lifetime= 50.0; - part->jitfac= 1.0; - part->totpart= 1000; - part->grid_res= 10; - part->timetweak= 1.0; + part->bb_uv_split = 1; + part->bb_align = PART_BB_VIEW; + part->bb_split_offset = PART_BB_OFF_LINEAR; + part->flag = PART_EDISTR | PART_TRAND | PART_HIDE_ADVANCED_HAIR; + + part->sta = 1.0; + part->end = 200.0; + part->lifetime = 50.0; + part->jitfac = 1.0; + part->totpart = 1000; + part->grid_res = 10; + part->timetweak = 1.0; part->courant_target = 0.2; - part->integrator= PART_INT_MIDPOINT; - part->phystype= PART_PHYS_NEWTON; - part->hair_step= 5; - part->keys_step= 5; - part->draw_step= 2; - part->ren_step= 3; - part->adapt_angle= 5; - part->adapt_pix= 3; - part->kink_axis= 2; - part->kink_amp_clump= 1.f; - part->reactevent= PART_EVENT_DEATH; - part->disp=100; - part->from= PART_FROM_FACE; - - part->normfac= 1.0f; - - part->mass=1.0; - part->size=0.05; - part->childsize=1.0; + part->integrator = PART_INT_MIDPOINT; + part->phystype = PART_PHYS_NEWTON; + part->hair_step = 5; + part->keys_step = 5; + part->draw_step = 2; + part->ren_step = 3; + part->adapt_angle = 5; + part->adapt_pix = 3; + part->kink_axis = 2; + part->kink_amp_clump = 1.f; + part->reactevent = PART_EVENT_DEATH; + part->disp = 100; + part->from = PART_FROM_FACE; + + part->normfac = 1.0f; + + part->mass = 1.0; + part->size = 0.05; + part->childsize = 1.0; part->rotmode = PART_ROT_VEL; part->avemode = PART_AVE_VELOCITY; - part->child_nbr=10; - part->ren_child_nbr=100; - part->childrad=0.2f; - part->childflat=0.0f; - part->clumppow=0.0f; - part->kink_amp=0.2f; - part->kink_freq=2.0; + part->child_nbr = 10; + part->ren_child_nbr = 100; + part->childrad = 0.2f; + part->childflat = 0.0f; + part->clumppow = 0.0f; + part->kink_amp = 0.2f; + part->kink_freq = 2.0; - part->rough1_size=1.0; - part->rough2_size=1.0; - part->rough_end_shape=1.0; + part->rough1_size = 1.0; + part->rough2_size = 1.0; + part->rough_end_shape = 1.0; - part->clength=1.0f; - part->clength_thres=0.0f; + part->clength = 1.0f; + part->clength_thres = 0.0f; - part->draw= PART_DRAW_EMITTER; - part->draw_line[0]=0.5; + part->draw = PART_DRAW_EMITTER; + part->draw_line[0] = 0.5; part->path_start = 0.0f; part->path_end = 1.0f; @@ -3593,10 +3593,10 @@ static void default_particle_settings(ParticleSettings *part) part->color_vec_max = 1.f; part->draw_col = PART_DRAW_COL_MAT; - part->simplify_refsize= 1920; - part->simplify_rate= 1.0f; - part->simplify_transition= 0.1f; - part->simplify_viewport= 0.8; + part->simplify_refsize = 1920; + part->simplify_rate = 1.0f; + part->simplify_transition = 0.1f; + part->simplify_viewport = 0.8; if (!part->effector_weights) part->effector_weights = BKE_add_effector_weights(NULL); @@ -3607,32 +3607,32 @@ ParticleSettings *psys_new_settings(const char *name, Main *main) { ParticleSettings *part; - if (main==NULL) + if (main == NULL) main = G.main; - part= alloc_libblock(&main->particle, ID_PA, name); + part = BKE_libblock_alloc(&main->particle, ID_PA, name); default_particle_settings(part); return part; } -ParticleSettings *psys_copy_settings(ParticleSettings *part) +ParticleSettings *BKE_particlesettings_copy(ParticleSettings *part) { ParticleSettings *partn; int a; - partn= copy_libblock(&part->id); - partn->pd= MEM_dupallocN(part->pd); - partn->pd2= MEM_dupallocN(part->pd2); - partn->effector_weights= MEM_dupallocN(part->effector_weights); - partn->fluid= MEM_dupallocN(part->fluid); + partn = BKE_libblock_copy(&part->id); + partn->pd = MEM_dupallocN(part->pd); + partn->pd2 = MEM_dupallocN(part->pd2); + partn->effector_weights = MEM_dupallocN(part->effector_weights); + partn->fluid = MEM_dupallocN(part->fluid); partn->boids = boid_copy_settings(part->boids); - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { if (part->mtex[a]) { - partn->mtex[a]= MEM_mallocN(sizeof(MTex), "psys_copy_tex"); + partn->mtex[a] = MEM_mallocN(sizeof(MTex), "psys_copy_tex"); memcpy(partn->mtex[a], part->mtex[a], sizeof(MTex)); id_us_plus((ID *)partn->mtex[a]->tex); } @@ -3648,57 +3648,57 @@ static void expand_local_particlesettings(ParticleSettings *part) int i; id_lib_extern((ID *)part->dup_group); - for (i=0; i<MAX_MTEX; i++) { + for (i = 0; i < MAX_MTEX; i++) { if (part->mtex[i]) id_lib_extern((ID *)part->mtex[i]->tex); } } -void make_local_particlesettings(ParticleSettings *part) +void BKE_particlesettings_make_local(ParticleSettings *part) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (part->id.lib==0) return; - if (part->id.us==1) { + if (part->id.lib == 0) return; + if (part->id.us == 1) { id_clear_lib_data(bmain, &part->id); expand_local_particlesettings(part); return; } /* test objects */ - for (ob= bmain->object.first; ob && ELEM(FALSE, is_lib, is_local); ob= ob->id.next) { - ParticleSystem *psys=ob->particlesystem.first; - for (; psys; psys=psys->next) { - if (psys->part==part) { - if (ob->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (ob = bmain->object.first; ob && ELEM(FALSE, is_lib, is_local); ob = ob->id.next) { + ParticleSystem *psys = ob->particlesystem.first; + for (; psys; psys = psys->next) { + if (psys->part == part) { + if (ob->id.lib) is_lib = TRUE; + else is_local = TRUE; } } } - if (is_local && is_lib==FALSE) { + if (is_local && is_lib == FALSE) { id_clear_lib_data(bmain, &part->id); expand_local_particlesettings(part); } else if (is_local && is_lib) { - ParticleSettings *part_new= psys_copy_settings(part); - part_new->id.us= 0; + ParticleSettings *part_new = BKE_particlesettings_copy(part); + part_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, part->id.lib, &part_new->id); /* do objects */ - for (ob= bmain->object.first; ob; ob= ob->id.next) { + for (ob = bmain->object.first; ob; ob = ob->id.next) { ParticleSystem *psys; - for (psys= ob->particlesystem.first; psys; psys=psys->next) { - if (psys->part==part && ob->id.lib==0) { - psys->part= part_new; + for (psys = ob->particlesystem.first; psys; psys = psys->next) { + if (psys->part == part && ob->id.lib == 0) { + psys->part = part_new; part_new->id.us++; part->id.us--; } @@ -3717,42 +3717,42 @@ static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, co MTFace *tf; int i; - tf= CustomData_get_layer_named(&dm->faceData, CD_MTFACE, name); + tf = CustomData_get_layer_named(&dm->faceData, CD_MTFACE, name); if (tf == NULL) - tf= CustomData_get_layer(&dm->faceData, CD_MTFACE); + tf = CustomData_get_layer(&dm->faceData, CD_MTFACE); if (tf == NULL) return 0; if (pa) { - i= (pa->num_dmcache==DMCACHE_NOTFOUND)? pa->num: pa->num_dmcache; + i = (pa->num_dmcache == DMCACHE_NOTFOUND) ? pa->num : pa->num_dmcache; if (i >= dm->getNumTessFaces(dm)) i = -1; } else - i= face_index; + i = face_index; - if (i==-1) { - texco[0]= 0.0f; - texco[1]= 0.0f; - texco[2]= 0.0f; + if (i == -1) { + texco[0] = 0.0f; + texco[1] = 0.0f; + texco[2] = 0.0f; } else { - mf= dm->getTessFaceData(dm, i, CD_MFACE); + mf = dm->getTessFaceData(dm, i, CD_MFACE); psys_interpolate_uvs(&tf[i], mf->v4, fuv, texco); - texco[0]= texco[0]*2.0f - 1.0f; - texco[1]= texco[1]*2.0f - 1.0f; - texco[2]= 0.0f; + texco[0] = texco[0] * 2.0f - 1.0f; + texco[1] = texco[1] * 2.0f - 1.0f; + texco[2] = 0.0f; } return 1; } -#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.0f, 1.0f); } +#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.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, const float fw[4], float *orco, ParticleTexture *ptex, int event, float cfra) @@ -3762,50 +3762,50 @@ static void get_cpa_texture(DerivedMesh *dm, ParticleSystem *psys, ParticleSetti float value, rgba[4], texvec[3]; ptex->ivel = ptex->life = ptex->exist = ptex->size = ptex->damp = - ptex->gravity = ptex->field = ptex->time = ptex->clump = ptex->kink = - ptex->effector = ptex->rough1 = ptex->rough2 = ptex->roughe = 1.f; + ptex->gravity = ptex->field = ptex->time = ptex->clump = ptex->kink = + ptex->effector = ptex->rough1 = ptex->rough2 = ptex->roughe = 1.f; - ptex->length= 1.0f - part->randlength * PSYS_FRAND(child_index + 26); - ptex->length*= part->clength_thres < PSYS_FRAND(child_index + 27) ? part->clength : 1.0f; + ptex->length = 1.0f - part->randlength *PSYS_FRAND(child_index + 26); + ptex->length *= part->clength_thres < PSYS_FRAND(child_index + 27) ? part->clength : 1.0f; - for (m=0; m<MAX_MTEX; m++, mtexp++) { + for (m = 0; m < MAX_MTEX; m++, mtexp++) { mtex = *mtexp; if (mtex && mtex->mapto) { - float def=mtex->def_var; - short blend=mtex->blendtype; + float def = mtex->def_var; + short blend = mtex->blendtype; short texco = mtex->texco; if (ELEM(texco, TEXCO_UV, TEXCO_ORCO) && (ELEM(part->from, PART_FROM_FACE, PART_FROM_VOLUME) == 0 || part->distr == PART_DISTR_GRID)) texco = TEXCO_GLOB; switch (texco) { - case TEXCO_GLOB: - copy_v3_v3(texvec, par->state.co); - break; - case TEXCO_OBJECT: - copy_v3_v3(texvec, par->state.co); - if (mtex->object) - mul_m4_v3(mtex->object->imat, texvec); - break; - case TEXCO_UV: - if (fw && get_particle_uv(dm, NULL, face_index, fw, mtex->uvname, texvec)) + case TEXCO_GLOB: + copy_v3_v3(texvec, par->state.co); break; + case TEXCO_OBJECT: + copy_v3_v3(texvec, par->state.co); + if (mtex->object) + mul_m4_v3(mtex->object->imat, texvec); + break; + case TEXCO_UV: + if (fw && get_particle_uv(dm, NULL, face_index, fw, mtex->uvname, texvec)) + break; /* no break, failed to get uv's, so let's try orco's */ - case TEXCO_ORCO: - copy_v3_v3(texvec, orco); - break; - case TEXCO_PARTICLE: - /* texture coordinates in range [-1, 1] */ - texvec[0] = 2.f * (cfra - par->time)/(par->dietime-par->time) - 1.f; - texvec[1] = 0.f; - texvec[2] = 0.f; - break; + case TEXCO_ORCO: + copy_v3_v3(texvec, orco); + break; + case TEXCO_PARTICLE: + /* texture coordinates in range [-1, 1] */ + texvec[0] = 2.f * (cfra - par->time) / (par->dietime - par->time) - 1.f; + texvec[1] = 0.f; + texvec[2] = 0.f; + break; } - externtex(mtex, texvec, &value, rgba, rgba+1, rgba+2, rgba+3, 0); + externtex(mtex, texvec, &value, rgba, rgba + 1, rgba + 2, rgba + 3, 0); if ((event & mtex->mapto) & PAMAP_ROUGH) - ptex->rough1= ptex->rough2= ptex->roughe= texture_value_blend(def, ptex->rough1, value, mtex->roughfac, blend); + ptex->rough1 = ptex->rough2 = ptex->roughe = texture_value_blend(def, ptex->rough1, value, mtex->roughfac, blend); SET_PARTICLE_TEXTURE(PAMAP_LENGTH, ptex->length, mtex->lengthfac); SET_PARTICLE_TEXTURE(PAMAP_CLUMP, ptex->clump, mtex->clumpfac); @@ -3827,62 +3827,62 @@ void psys_get_texture(ParticleSimulationData *sim, ParticleData *pa, ParticleTex MTex *mtex; int m; float value, rgba[4], co[3], texvec[3]; - int setvars=0; + int setvars = 0; /* initialize ptex */ ptex->ivel = ptex->life = ptex->exist = ptex->size = ptex->damp = - ptex->gravity = ptex->field = ptex->length = ptex->clump = ptex->kink = - ptex->effector = ptex->rough1 = ptex->rough2 = ptex->roughe = 1.f; + ptex->gravity = ptex->field = ptex->length = ptex->clump = ptex->kink = + ptex->effector = ptex->rough1 = ptex->rough2 = ptex->roughe = 1.0f; - ptex->time = (float)(pa - sim->psys->particles)/(float)sim->psys->totpart; + ptex->time = (float)(pa - sim->psys->particles) / (float)sim->psys->totpart; - for (m=0; m<MAX_MTEX; m++, mtexp++) { + for (m = 0; m < MAX_MTEX; m++, mtexp++) { mtex = *mtexp; if (mtex && mtex->mapto) { - float def=mtex->def_var; - short blend=mtex->blendtype; + float def = mtex->def_var; + short blend = mtex->blendtype; short texco = mtex->texco; if (texco == TEXCO_UV && (ELEM(part->from, PART_FROM_FACE, PART_FROM_VOLUME) == 0 || part->distr == PART_DISTR_GRID)) texco = TEXCO_GLOB; switch (texco) { - case TEXCO_GLOB: - copy_v3_v3(texvec, pa->state.co); - break; - case TEXCO_OBJECT: - copy_v3_v3(texvec, pa->state.co); - if (mtex->object) - mul_m4_v3(mtex->object->imat, texvec); - break; - case TEXCO_UV: - if (get_particle_uv(sim->psmd->dm, pa, 0, pa->fuv, mtex->uvname, texvec)) + case TEXCO_GLOB: + copy_v3_v3(texvec, pa->state.co); + break; + case TEXCO_OBJECT: + copy_v3_v3(texvec, pa->state.co); + if (mtex->object) + mul_m4_v3(mtex->object->imat, texvec); break; + case TEXCO_UV: + if (get_particle_uv(sim->psmd->dm, pa, 0, pa->fuv, mtex->uvname, texvec)) + break; /* no break, failed to get uv's, so let's try orco's */ - case TEXCO_ORCO: - psys_particle_on_emitter(sim->psmd, sim->psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co, 0, 0, 0, texvec, 0); - break; - case TEXCO_PARTICLE: - /* texture coordinates in range [-1, 1] */ - texvec[0] = 2.f * (cfra - pa->time)/(pa->dietime-pa->time) - 1.f; - texvec[1] = 0.f; - texvec[2] = 0.f; - break; + case TEXCO_ORCO: + psys_particle_on_emitter(sim->psmd, sim->psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co, 0, 0, 0, texvec, 0); + break; + case TEXCO_PARTICLE: + /* texture coordinates in range [-1, 1] */ + texvec[0] = 2.f * (cfra - pa->time) / (pa->dietime - pa->time) - 1.f; + texvec[1] = 0.f; + texvec[2] = 0.f; + break; } - externtex(mtex, texvec, &value, rgba, rgba+1, rgba+2, rgba+3, 0); + externtex(mtex, texvec, &value, rgba, rgba + 1, rgba + 2, rgba + 3, 0); if ((event & mtex->mapto) & PAMAP_TIME) { /* the first time has to set the base value for time regardless of blend mode */ - if ((setvars&MAP_PA_TIME)==0) { - int flip= (mtex->timefac < 0.0f); - float timefac= fabsf(mtex->timefac); + if ((setvars & MAP_PA_TIME) == 0) { + int flip = (mtex->timefac < 0.0f); + float timefac = fabsf(mtex->timefac); ptex->time *= 1.0f - timefac; - ptex->time += timefac * ((flip)? 1.0f - value : value); + ptex->time += timefac * ((flip) ? 1.0f - value : value); setvars |= MAP_PA_TIME; } else - ptex->time= texture_value_blend(def, ptex->time, value, mtex->timefac, blend); + ptex->time = texture_value_blend(def, ptex->time, value, mtex->timefac, blend); } SET_PARTICLE_TEXTURE(PAMAP_LIFE, ptex->life, mtex->lifefac) SET_PARTICLE_TEXTURE(PAMAP_DENS, ptex->exist, mtex->padensfac) @@ -3917,11 +3917,11 @@ float psys_get_child_time(ParticleSystem *psys, ChildParticle *cpa, float cfra, ParticleSettings *part = psys->part; float time, life; - if (part->childtype==PART_CHILD_FACES) { - int w=0; - time=0.0; - while (w<4 && cpa->pa[w]>=0) { - time+=cpa->w[w]*(psys->particles+cpa->pa[w])->time; + if (part->childtype == PART_CHILD_FACES) { + int w = 0; + time = 0.0; + while (w < 4 && cpa->pa[w] >= 0) { + time += cpa->w[w] * (psys->particles + cpa->pa[w])->time; w++; } @@ -3937,24 +3937,24 @@ float psys_get_child_time(ParticleSystem *psys, ChildParticle *cpa, float cfra, if (birthtime) *birthtime = time; if (dietime) - *dietime = time+life; + *dietime = time + life; - return (cfra-time)/life; + return (cfra - time) / life; } float psys_get_child_size(ParticleSystem *psys, ChildParticle *cpa, float UNUSED(cfra), float *UNUSED(pa_time)) { ParticleSettings *part = psys->part; float size; // time XXX - if (part->childtype==PART_CHILD_FACES) - size=part->size; + if (part->childtype == PART_CHILD_FACES) + size = part->size; else - size=psys->particles[cpa->parent].size; + size = psys->particles[cpa->parent].size; - size*=part->childsize; + size *= part->childsize; if (part->childrandsize != 0.0f) - size *= 1.0f - part->childrandsize * PSYS_FRAND(cpa - psys->child + 26); + size *= 1.0f - part->childrandsize *PSYS_FRAND(cpa - psys->child + 26); return size; } @@ -3963,26 +3963,26 @@ static void get_child_modifier_parameters(ParticleSettings *part, ParticleThread ParticleSystem *psys = ctx->sim.psys; int i = cpa - psys->child; - get_cpa_texture(ctx->dm, psys, part, psys->particles + cpa->pa[0], i, cpa_num, cpa_fuv, orco, ptex, PAMAP_DENS|PAMAP_CHILD, psys->cfra); + get_cpa_texture(ctx->dm, psys, part, psys->particles + cpa->pa[0], i, cpa_num, cpa_fuv, orco, ptex, PAMAP_DENS | PAMAP_CHILD, psys->cfra); if (ptex->exist < PSYS_FRAND(i + 24)) return; if (ctx->vg_length) - ptex->length*=psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_length); + ptex->length *= psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_length); if (ctx->vg_clump) - ptex->clump*=psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_clump); + ptex->clump *= psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_clump); if (ctx->vg_kink) - ptex->kink*=psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_kink); + ptex->kink *= psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_kink); if (ctx->vg_rough1) - ptex->rough1*=psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_rough1); + ptex->rough1 *= psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_rough1); if (ctx->vg_rough2) - ptex->rough2*=psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_rough2); + ptex->rough2 *= psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_rough2); if (ctx->vg_roughe) - ptex->roughe*=psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_roughe); + ptex->roughe *= psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_roughe); if (ctx->vg_effector) - ptex->effector*=psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_effector); + ptex->effector *= psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_effector); } static void do_child_modifiers(ParticleSimulationData *sim, ParticleTexture *ptex, ParticleKey *par, float *par_rot, ChildParticle *cpa, float *orco, float mat[4][4], ParticleKey *state, float t) { @@ -4004,17 +4004,17 @@ static void do_child_modifiers(ParticleSimulationData *sim, ParticleTexture *pte if (part->flag & PART_CHILD_EFFECT) /* state is safe to cast, since only co and vel are used */ - guided = do_guides(sim->psys->effectors, (ParticleKey*)state, cpa->parent, t); + guided = do_guides(sim->psys->effectors, (ParticleKey *)state, cpa->parent, t); - if (guided==0) { + if (guided == 0) { float clump = do_clump(state, par, t, part->clumpfac, part->clumppow, ptex ? ptex->clump : 1.f); if (kink_freq != 0.f) { float kink_amp = part->kink_amp * (1.f - part->kink_amp_clump * clump); do_kink(state, par, par_rot, t, kink_freq, part->kink_shape, - kink_amp, part->kink_flat, part->kink, part->kink_axis, - sim->ob->obmat, sim->psys->part->childtype == PART_CHILD_FACES); + kink_amp, part->kink_flat, part->kink, part->kink_axis, + sim->ob->obmat, sim->psys->part->childtype == PART_CHILD_FACES); } } @@ -4037,7 +4037,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * ParticleData *pa; ChildParticle *cpa; ParticleTexture ptex; - ParticleKey *par=0, keys[4], tstate; + ParticleKey *par = 0, keys[4], tstate; ParticleThreadContext ctx; /* fake thread context for child modifiers */ ParticleInterpolationData pind; @@ -4054,12 +4054,12 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * float *cpa_fuv; int cpa_num; short cpa_from; /* initialize keys to zero */ - memset(keys, 0, 4*sizeof(ParticleKey)); + memset(keys, 0, 4 * sizeof(ParticleKey)); - t=state->time; + t = state->time; CLAMP(t, 0.0f, 1.0f); - if (p<totpart) { + if (p < totpart) { /* interpolate pathcache directly if it exist */ if (psys->pathcache) { ParticleCacheKey result; @@ -4087,17 +4087,17 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * mul_mat3_m4_v3(sim->ob->obmat, state->vel); } else if (!keyed && !cached && !(psys->flag & PSYS_GLOBAL_HAIR)) { - if ((pa->flag & PARS_REKEY)==0) { + if ((pa->flag & PARS_REKEY) == 0) { psys_mat_hair_to_global(sim->ob, sim->psmd->dm, part->from, pa, hairmat); mul_m4_v3(hairmat, state->co); mul_mat3_m4_v3(hairmat, state->vel); - if (sim->psys->effectors && (part->flag & PART_CHILD_GUIDE)==0) { + if (sim->psys->effectors && (part->flag & PART_CHILD_GUIDE) == 0) { do_guides(sim->psys->effectors, state, p, state->time); /* TODO: proper velocity handling */ } - if (psys->lattice && edit==0) + if (psys->lattice && edit == 0) calc_latt_deform(psys->lattice, state->co, 1.0f); } } @@ -4109,36 +4109,36 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * /* interpolate childcache directly if it exists */ if (psys->childcache) { ParticleCacheKey result; - interpolate_pathcache(psys->childcache[p-totpart], t, &result); + interpolate_pathcache(psys->childcache[p - totpart], t, &result); copy_v3_v3(state->co, result.co); copy_v3_v3(state->vel, result.vel); copy_qt_qt(state->rot, result.rot); } else { - cpa=psys->child+p-totpart; + cpa = psys->child + p - totpart; if (state->time < 0.0f) t = psys_get_child_time(psys, cpa, -state->time, NULL, NULL); - if (totchild && 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; + between = 1; } if (between) { int w = 0; float foffset; /* get parent states */ - while (w<4 && cpa->pa[w]>=0) { + while (w < 4 && cpa->pa[w] >= 0) { keys[w].time = state->time; - psys_get_particle_on_path(sim, cpa->pa[w], keys+w, 1); + psys_get_particle_on_path(sim, cpa->pa[w], keys + w, 1); w++; } /* get the original coordinates (orco) for texture usage */ - cpa_num=cpa->num; + cpa_num = cpa->num; - foffset= cpa->foffset; + foffset = cpa->foffset; cpa_fuv = cpa->fuv; cpa_from = PART_FROM_FACE; @@ -4156,7 +4156,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * else unit_m4(hairmat); - pa=0; + pa = 0; } else { /* get the parent state */ @@ -4164,11 +4164,11 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * psys_get_particle_on_path(sim, cpa->parent, keys, 1); /* get the original coordinates (orco) for texture usage */ - pa=psys->particles+cpa->parent; + pa = psys->particles + cpa->parent; - cpa_from=part->from; - cpa_num=pa->num; - cpa_fuv=pa->fuv; + cpa_from = part->from; + cpa_num = pa->num; + cpa_fuv = pa->fuv; @@ -4184,8 +4184,8 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * /* correct child ipo timing */ #if 0 // XXX old animation system - if ((part->flag&PART_ABS_TIME)==0 && part->ipo) { - calc_ipo(part->ipo, 100.0f*t); + if ((part->flag & PART_ABS_TIME) == 0 && part->ipo) { + calc_ipo(part->ipo, 100.0f * t); execute_ipo((ID *)part, part->ipo); } #endif // XXX old animation system @@ -4199,13 +4199,13 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * get_child_modifier_parameters(part, &ctx, cpa, cpa_from, cpa_num, cpa_fuv, orco, &ptex); if (between) { - int w=0; + int w = 0; state->co[0] = state->co[1] = state->co[2] = 0.0f; state->vel[0] = state->vel[1] = state->vel[2] = 0.0f; /* child position is the weighted sum of parent positions */ - while (w<4 && cpa->pa[w]>=0) { + while (w < 4 && cpa->pa[w] >= 0) { state->co[0] += cpa->w[w] * keys[w].co[0]; state->co[1] += cpa->w[w] * keys[w].co[1]; state->co[2] += cpa->w[w] * keys[w].co[2]; @@ -4236,14 +4236,14 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * ParticleKey tstate; float length = len_v3(state->vel); - if (t>=0.001f) { - tstate.time=t-0.001f; + if (t >= 0.001f) { + tstate.time = t - 0.001f; psys_get_particle_on_path(sim, p, &tstate, 0); sub_v3_v3v3(state->vel, state->co, tstate.co); normalize_v3(state->vel); } else { - tstate.time=t+0.001f; + tstate.time = t + 0.001f; psys_get_particle_on_path(sim, p, &tstate, 0); sub_v3_v3v3(state->vel, tstate.co, state->co); normalize_v3(state->vel); @@ -4266,9 +4266,9 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta float timestep = psys_get_timestep(sim); /* negative time means "use current time" */ - cfra = state->time > 0 ? state->time : BKE_curframe(sim->scene); + cfra = state->time > 0 ? state->time : BKE_scene_frame_get(sim->scene); - if (p>=totpart) { + if (p >= totpart) { if (!psys->totchild) return 0; @@ -4288,7 +4288,7 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta } } - state->time= (cfra - (part->sta + (part->end - part->sta) * PSYS_FRAND(p + 23))) / (part->lifetime * PSYS_FRAND(p + 24)); + state->time = (cfra - (part->sta + (part->end - part->sta) * PSYS_FRAND(p + 23))) / (part->lifetime * PSYS_FRAND(p + 24)); psys_get_particle_on_path(sim, p, state, 1); return 1; @@ -4315,7 +4315,7 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta } if (sim->psys->flag & PSYS_KEYED) { - state->time= -cfra; + state->time = -cfra; psys_get_particle_on_path(sim, p, state, 1); return 1; } @@ -4325,7 +4325,7 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta ParticleKey *key1; float t = (cfra - pa->time) / pa->lifetime; - key1=&pa->state; + key1 = &pa->state; offset_child(cpa, key1, key1->rot, state, part->childflat, part->childrad); CLAMP(t, 0.0f, 1.0f); @@ -4337,9 +4337,9 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta calc_latt_deform(sim->psys->lattice, state->co, 1.0f); } else { - if (pa->state.time==cfra || ELEM(part->phystype, PART_PHYS_NO, PART_PHYS_KEYED)) + if (pa->state.time == cfra || ELEM(part->phystype, PART_PHYS_NO, PART_PHYS_KEYED)) copy_particle_key(state, &pa->state, 1); - else if (pa->prev_state.time==cfra) + else if (pa->prev_state.time == cfra) copy_particle_key(state, &pa->prev_state, 1); else { float dfra, frs_sec = sim->scene->r.frs_sec; @@ -4351,14 +4351,14 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta copy_particle_key(state, &pa->state, 1); - madd_v3_v3v3fl(state->co, state->co, state->vel, dfra/frs_sec); + madd_v3_v3v3fl(state->co, state->co, state->vel, dfra / frs_sec); } else { ParticleKey keys[4]; float keytime; - copy_particle_key(keys+1, &pa->prev_state, 1); - copy_particle_key(keys+2, &pa->state, 1); + copy_particle_key(keys + 1, &pa->prev_state, 1); + copy_particle_key(keys + 2, &pa->state, 1); dfra = keys[2].time - keys[1].time; @@ -4384,7 +4384,7 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta copy_particle_key(state, &pa->state, 1); - madd_v3_v3v3fl(state->co, state->co, state->vel, dfra/frs_sec); + madd_v3_v3v3fl(state->co, state->co, state->vel, dfra / frs_sec); } else { /* extrapolating over big ranges is not accurate so let's just give something close to reasonable back */ @@ -4411,9 +4411,9 @@ void psys_get_dupli_texture(ParticleSystem *psys, ParticleSettings *part, Partic if (cpa) { if (part->childtype == PART_CHILD_FACES) { - mtface= CustomData_get_layer(&psmd->dm->faceData, CD_MTFACE); + mtface = CustomData_get_layer(&psmd->dm->faceData, CD_MTFACE); if (mtface) { - mface= psmd->dm->getTessFaceData(psmd->dm, cpa->num, CD_MFACE); + mface = psmd->dm->getTessFaceData(psmd->dm, cpa->num, CD_MFACE); mtface += cpa->num; psys_interpolate_uvs(mtface, mface->v4, cpa->fuv, uv); } @@ -4427,20 +4427,20 @@ void psys_get_dupli_texture(ParticleSystem *psys, ParticleSettings *part, Partic } if (part->from == PART_FROM_FACE) { - mtface= CustomData_get_layer(&psmd->dm->faceData, CD_MTFACE); - num= pa->num_dmcache; + mtface = CustomData_get_layer(&psmd->dm->faceData, CD_MTFACE); + num = pa->num_dmcache; if (num == DMCACHE_NOTFOUND) - num= pa->num; + num = pa->num; if (num >= psmd->dm->getNumTessFaces(psmd->dm)) { /* happens when simplify is enabled * gives invalid coords but would crash otherwise */ - num= DMCACHE_NOTFOUND; + num = DMCACHE_NOTFOUND; } if (mtface && num != DMCACHE_NOTFOUND) { - mface= psmd->dm->getTessFaceData(psmd->dm, num, CD_MFACE); + mface = psmd->dm->getTessFaceData(psmd->dm, num, CD_MFACE); mtface += num; psys_interpolate_uvs(mtface, mface->v4, pa->fuv, uv); } @@ -4457,8 +4457,8 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa float loc[3], nor[3], vec[3], side[3], len; float xvec[3] = {-1.0, 0.0, 0.0}, nmat[3][3]; - sub_v3_v3v3(vec, (cache+cache->steps)->co, cache->co); - len= normalize_v3(vec); + sub_v3_v3v3(vec, (cache + cache->steps)->co, cache->co); + len = normalize_v3(vec); if (pa == NULL && psys->part->childflat != PART_CHILD_FACES) pa = psys->particles + cpa->pa[0]; @@ -4475,8 +4475,8 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa normalize_v3(nor); /* make sure that we get a proper side vector */ - if (fabs(dot_v3v3(nor, vec))>0.999999) { - if (fabs(dot_v3v3(nor, xvec))>0.999999) { + if (fabs(dot_v3v3(nor, vec)) > 0.999999) { + if (fabs(dot_v3v3(nor, xvec)) > 0.999999) { nor[0] = 0.0f; nor[1] = 1.0f; nor[2] = 0.0f; @@ -4495,8 +4495,8 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa float q_phase[4]; float phasefac = psys->part->phasefac; if (psys->part->randphasefac != 0.0f) - phasefac += psys->part->randphasefac * PSYS_FRAND((pa-psys->particles) + 20); - axis_angle_to_quat(q_phase, vec, phasefac*(float)M_PI); + phasefac += psys->part->randphasefac * PSYS_FRAND((pa - psys->particles) + 20); + axis_angle_to_quat(q_phase, vec, phasefac * (float)M_PI); mul_qt_v3(q_phase, side); } @@ -4512,7 +4512,7 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa quat_to_mat4(mat, pa->state.rot); } - *scale= len; + *scale = len; } void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3], float zvec[3], float center[3]) @@ -4525,7 +4525,7 @@ void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3] /* can happen with bad pointcache or physics calculation * since this becomes geometry, nan's and inf's crash raytrace code. * better not allow this. */ - if ( !finite(bb->vec[0]) || !finite(bb->vec[1]) || !finite(bb->vec[2]) || + if (!finite(bb->vec[0]) || !finite(bb->vec[1]) || !finite(bb->vec[2]) || !finite(bb->vel[0]) || !finite(bb->vel[1]) || !finite(bb->vel[2]) ) { zero_v3(bb->vec); @@ -4540,7 +4540,7 @@ void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3] } if (bb->align < PART_BB_VIEW) - onevec[bb->align]=1.0f; + onevec[bb->align] = 1.0f; if (bb->lock && (bb->align == PART_BB_VIEW)) { normalize_v3_v3(xvec, bb->ob->obmat[0]); @@ -4601,11 +4601,11 @@ void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3] void psys_apply_hair_lattice(Scene *scene, Object *ob, ParticleSystem *psys) { - ParticleSimulationData sim= {0}; - sim.scene= scene; - sim.ob= ob; - sim.psys= psys; - sim.psmd= psys_get_modifier(ob, psys); + ParticleSimulationData sim = {0}; + sim.scene = scene; + sim.ob = ob; + sim.psys = psys; + sim.psmd = psys_get_modifier(ob, psys); psys->lattice = psys_get_lattice(&sim); @@ -4615,12 +4615,12 @@ void psys_apply_hair_lattice(Scene *scene, Object *ob, ParticleSystem *psys) int p, h; float hairmat[4][4], imat[4][4]; - for (p=0; p<psys->totpart; p++, pa++) { + for (p = 0; p < psys->totpart; p++, pa++) { psys_mat_hair_to_global(sim.ob, sim.psmd->dm, psys->part->from, pa, hairmat); invert_m4_m4(imat, hairmat); hkey = pa->hair; - for (h=0; h<pa->totkey; h++, hkey++) { + for (h = 0; h < pa->totkey; h++, hkey++) { mul_m4_v3(hairmat, hkey->co); calc_latt_deform(psys->lattice, hkey->co, 1.0f); mul_m4_v3(imat, hkey->co); @@ -4628,7 +4628,7 @@ void psys_apply_hair_lattice(Scene *scene, Object *ob, ParticleSystem *psys) } end_latt_deform(psys->lattice); - psys->lattice= NULL; + psys->lattice = NULL; /* protect the applied shape */ psys->flag |= PSYS_EDITED; diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index a4d61cea3fb..cd1561734cc 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -512,9 +512,9 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) vec[0]/=delta[0]; vec[1]/=delta[1]; vec[2]/=delta[2]; - (pa +((int)(vec[0]*(size[0]-1))*res - +(int)(vec[1]*(size[1]-1)))*res - +(int)(vec[2]*(size[2]-1)))->flag &= ~PARS_UNEXIST; + (pa + ((int)(vec[0] * (size[0] - 1)) * res + + (int)(vec[1] * (size[1] - 1))) * res + + (int)(vec[2] * (size[2] - 1)))->flag &= ~PARS_UNEXIST; } } else if (ELEM(from, PART_FROM_FACE, PART_FROM_VOLUME)) { @@ -772,7 +772,7 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch int w, maxw; psys_particle_on_dm(ctx->dm, from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co1, 0, 0, 0, orco1, 0); - transform_mesh_orco_verts((Mesh*)ob->data, &orco1, 1, 1); + BKE_mesh_orco_verts_transform((Mesh*)ob->data, &orco1, 1, 1); maxw = BLI_kdtree_find_n_nearest(ctx->tree, 3, orco1, NULL, ptn); for (w=0; w<maxw; w++) { @@ -895,7 +895,7 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch float pweight[10]; psys_particle_on_dm(dm, cfrom, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, co1, nor1, NULL, NULL, orco1, NULL); - transform_mesh_orco_verts((Mesh*)ob->data, &orco1, 1, 1); + BKE_mesh_orco_verts_transform((Mesh*)ob->data, &orco1, 1, 1); maxw = BLI_kdtree_find_n_nearest(ctx->tree, 4, orco1, NULL, ptn); maxd=ptn[maxw-1].dist; @@ -1086,7 +1086,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D 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); + BKE_mesh_orco_verts_transform((Mesh*)ob->data, &orco, 1, 1); BLI_kdtree_insert(tree, p, orco, ornor); } @@ -1107,7 +1107,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D } /* we need orco for consistent distributions */ - DM_add_vert_layer(dm, CD_ORCO, CD_ASSIGN, get_mesh_orco_verts(ob)); + DM_add_vert_layer(dm, CD_ORCO, CD_ASSIGN, BKE_mesh_orco_verts_get(ob)); if (from == PART_FROM_VERT) { MVert *mv= dm->getVertDataArray(dm, CD_MVERT); @@ -1119,7 +1119,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D for (p=0; p<totvert; p++) { if (orcodata) { copy_v3_v3(co, orcodata[p]); - transform_mesh_orco_verts((Mesh*)ob->data, &co, 1, 1); + BKE_mesh_orco_verts_transform((Mesh*)ob->data, &co, 1, 1); } else copy_v3_v3(co, mv[p].co); @@ -1166,12 +1166,12 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D copy_v3_v3(co1, orcodata[mf->v1]); copy_v3_v3(co2, orcodata[mf->v2]); copy_v3_v3(co3, orcodata[mf->v3]); - 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); + BKE_mesh_orco_verts_transform((Mesh*)ob->data, &co1, 1, 1); + BKE_mesh_orco_verts_transform((Mesh*)ob->data, &co2, 1, 1); + BKE_mesh_orco_verts_transform((Mesh*)ob->data, &co3, 1, 1); if (mf->v4) { copy_v3_v3(co4, orcodata[mf->v4]); - transform_mesh_orco_verts((Mesh*)ob->data, &co4, 1, 1); + BKE_mesh_orco_verts_transform((Mesh*)ob->data, &co4, 1, 1); } } else { @@ -1854,7 +1854,7 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime, ob = ob->parent; } ob = sim->ob; - where_is_object_time(sim->scene, ob, pa->time); + BKE_object_where_is_calc_time(sim->scene, ob, pa->time); psys->flag |= PSYS_OB_ANIM_RESTORE; } @@ -4465,7 +4465,7 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys) if (!psys_check_enabled(ob, psys)) return; - cfra= BKE_curframe(scene); + cfra= BKE_scene_frame_get(scene); sim.scene= scene; sim.ob= ob; @@ -4612,7 +4612,7 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys) ob = ob->parent; } ob = sim.ob; - where_is_object_time(scene, ob, cfra); + BKE_object_where_is_calc_time(scene, ob, cfra); psys->flag &= ~PSYS_OB_ANIM_RESTORE; } diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 1e80f1e6d1e..69808db52b6 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -1122,7 +1122,7 @@ static int ptcache_filename(PTCacheID *pid, char *filename, int cfra, short do_p if (do_ext) { if (pid->cache->index < 0) - pid->cache->index = pid->stack_index = object_insert_ptcache(pid->ob); + pid->cache->index = pid->stack_index = BKE_object_insert_ptcache(pid->ob); if (pid->cache->flag & PTCACHE_EXTERNAL) { if (pid->cache->index >= 0) @@ -2320,8 +2320,8 @@ void BKE_ptcache_id_time(PTCacheID *pid, Scene *scene, float cfra, int *startfra cache= pid->cache; if (timescale) { - time= BKE_curframe(scene); - nexttime = BKE_frame_to_ctime(scene, CFRA + 1.0f); + time= BKE_scene_frame_get(scene); + nexttime = BKE_scene_frame_get_from_ctime(scene, CFRA + 1.0f); *timescale= MAX2(nexttime - time, 0.0f); } @@ -2743,7 +2743,7 @@ static void *ptcache_bake_thread(void *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); + BKE_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); } @@ -2974,7 +2974,7 @@ void BKE_ptcache_bake(PTCacheBaker* baker) CFRA = cfrao; if (bake) /* already on cfra unless baking */ - scene_update_for_newframe(bmain, scene, scene->lay); + BKE_scene_update_for_newframe(bmain, scene, scene->lay); if (thread_data.break_operation) WM_cursor_wait(0); diff --git a/source/blender/blenkernel/intern/property.c b/source/blender/blenkernel/intern/property.c index e7247be7f51..b82521504dd 100644 --- a/source/blender/blenkernel/intern/property.c +++ b/source/blender/blenkernel/intern/property.c @@ -57,7 +57,7 @@ void free_properties(ListBase *lb) { bProperty *prop; - while ( (prop= lb->first) ) { + while ( (prop = lb->first) ) { BLI_remlink(lb, prop); free_property(prop); } @@ -67,11 +67,11 @@ bProperty *copy_property(bProperty *prop) { bProperty *propn; - propn= MEM_dupallocN(prop); + propn = MEM_dupallocN(prop); if (prop->poin && prop->poin != &prop->data) { - propn->poin= MEM_dupallocN(prop->poin); + propn->poin = MEM_dupallocN(prop->poin); } - else propn->poin= &propn->data; + else propn->poin = &propn->data; return propn; } @@ -80,11 +80,11 @@ void copy_properties(ListBase *lbn, ListBase *lbo) { bProperty *prop, *propn; free_properties(lbn); /* in case we are copying to an object with props */ - prop= lbo->first; + prop = lbo->first; while (prop) { - propn= copy_property(prop); + propn = copy_property(prop); BLI_addtail(lbn, propn); - prop= prop->next; + prop = prop->next; } @@ -95,20 +95,20 @@ void init_property(bProperty *prop) /* also use when property changes type */ if (prop->poin && prop->poin != &prop->data) MEM_freeN(prop->poin); - prop->poin= NULL; + prop->poin = NULL; - prop->data= 0; + prop->data = 0; switch (prop->type) { - case GPROP_BOOL: - case GPROP_INT: - case GPROP_FLOAT: - case GPROP_TIME: - prop->poin= &prop->data; - break; - case GPROP_STRING: - prop->poin= MEM_callocN(MAX_PROPSTRING, "property string"); - break; + case GPROP_BOOL: + case GPROP_INT: + case GPROP_FLOAT: + case GPROP_TIME: + prop->poin = &prop->data; + break; + case GPROP_STRING: + prop->poin = MEM_callocN(MAX_PROPSTRING, "property string"); + break; } } @@ -117,8 +117,8 @@ bProperty *new_property(int type) { bProperty *prop; - prop= MEM_callocN(sizeof(bProperty), "property"); - prop->type= type; + prop = MEM_callocN(sizeof(bProperty), "property"); + prop->type = type; init_property(prop); @@ -131,8 +131,8 @@ bProperty *new_property(int type) static bProperty *get_property__internal(bProperty *first, bProperty *self, const char *name) { bProperty *p; - for (p= first; p; p= p->next) { - if (p!=self && (strcmp(p->name, name)==0)) + for (p = first; p; p = p->next) { + if (p != self && (strcmp(p->name, name) == 0)) return p; } return NULL; @@ -142,10 +142,10 @@ void unique_property(bProperty *first, bProperty *prop, int force) bProperty *p; /* set the first if its not set */ - if (first==NULL) { - first= prop; + if (first == NULL) { + first = prop; while (first->prev) { - first= first->prev; + first = first->prev; } } @@ -162,14 +162,14 @@ void unique_property(bProperty *first, bProperty *prop, int force) char new_name[sizeof(prop->name)]; char base_name[sizeof(prop->name)]; char num[sizeof(prop->name)]; - int i= 0; + int i = 0; /* strip numbers */ BLI_strncpy(base_name, prop->name, sizeof(base_name)); - for (i= strlen(base_name)-1; (i>=0 && isdigit(base_name[i])); i--) { - base_name[i]= '\0'; + for (i = strlen(base_name) - 1; (i >= 0 && isdigit(base_name[i])); i--) { + base_name[i] = '\0'; } - i= 0; + i = 0; do { /* ensure we have enough chars for the new number in the name */ BLI_snprintf(num, sizeof(num), "%d", i++); @@ -190,7 +190,7 @@ bProperty *get_ob_property(Object *ob, const char *name) void set_ob_property(Object *ob, bProperty *propc) { bProperty *prop; - prop= get_ob_property(ob, propc->name); + prop = get_ob_property(ob, propc->name); if (prop) { free_property(prop); BLI_remlink(&ob->prop, prop); @@ -207,32 +207,32 @@ int compare_property(bProperty *prop, const char *str) float fvalue, ftest; switch (prop->type) { - case GPROP_BOOL: - if (BLI_strcasecmp(str, "true")==0) { - if (prop->data==1) return 0; - else return 1; - } - else if (BLI_strcasecmp(str, "false")==0) { - if (prop->data==0) return 0; - else return 1; - } + case GPROP_BOOL: + if (BLI_strcasecmp(str, "true") == 0) { + if (prop->data == 1) return 0; + else return 1; + } + else if (BLI_strcasecmp(str, "false") == 0) { + if (prop->data == 0) return 0; + else return 1; + } /* no break, do GPROP_int too! */ - case GPROP_INT: - return prop->data - atoi(str); - - case GPROP_FLOAT: - case GPROP_TIME: - // WARNING: untested for GPROP_TIME - // function isn't used currently - fvalue= *((float *)&prop->data); - ftest= (float)atof(str); - if ( fvalue > ftest) return 1; - else if ( fvalue < ftest) return -1; - return 0; - - case GPROP_STRING: - return strcmp(prop->poin, str); + case GPROP_INT: + return prop->data - atoi(str); + + case GPROP_FLOAT: + case GPROP_TIME: + // WARNING: untested for GPROP_TIME + // function isn't used currently + fvalue = *((float *)&prop->data); + ftest = (float)atof(str); + if (fvalue > ftest) return 1; + else if (fvalue < ftest) return -1; + return 0; + + case GPROP_STRING: + return strcmp(prop->poin, str); } return 0; @@ -243,21 +243,21 @@ void set_property(bProperty *prop, const char *str) // extern int Gdfra; /* sector.c */ switch (prop->type) { - case GPROP_BOOL: - if (BLI_strcasecmp(str, "true")==0) prop->data= 1; - else if (BLI_strcasecmp(str, "false")==0) prop->data= 0; - else prop->data= (atoi(str)!=0); - break; - case GPROP_INT: - prop->data= atoi(str); - break; - case GPROP_FLOAT: - case GPROP_TIME: - *((float *)&prop->data)= (float)atof(str); - break; - case GPROP_STRING: - strcpy(prop->poin, str); /* TODO - check size? */ - break; + case GPROP_BOOL: + if (BLI_strcasecmp(str, "true") == 0) prop->data = 1; + else if (BLI_strcasecmp(str, "false") == 0) prop->data = 0; + else prop->data = (atoi(str) != 0); + break; + case GPROP_INT: + prop->data = atoi(str); + break; + case GPROP_FLOAT: + case GPROP_TIME: + *((float *)&prop->data) = (float)atof(str); + break; + case GPROP_STRING: + strcpy(prop->poin, str); /* TODO - check size? */ + break; } } @@ -267,17 +267,17 @@ void add_property(bProperty *prop, const char *str) // extern int Gdfra; /* sector.c */ switch (prop->type) { - case GPROP_BOOL: - case GPROP_INT: - prop->data+= atoi(str); - break; - case GPROP_FLOAT: - case GPROP_TIME: - *((float *)&prop->data)+= (float)atof(str); - break; - case GPROP_STRING: - /* strcpy(prop->poin, str); */ - break; + case GPROP_BOOL: + case GPROP_INT: + prop->data += atoi(str); + break; + case GPROP_FLOAT: + case GPROP_TIME: + *((float *)&prop->data) += (float)atof(str); + break; + case GPROP_STRING: + /* strcpy(prop->poin, str); */ + break; } } @@ -289,17 +289,17 @@ void set_property_valstr(bProperty *prop, char *str) if (str == NULL) return; switch (prop->type) { - case GPROP_BOOL: - case GPROP_INT: - sprintf(str, "%d", prop->data); - break; - case GPROP_FLOAT: - case GPROP_TIME: - sprintf(str, "%f", *((float *)&prop->data)); - break; - case GPROP_STRING: - BLI_strncpy(str, prop->poin, MAX_PROPSTRING); - break; + case GPROP_BOOL: + case GPROP_INT: + sprintf(str, "%d", prop->data); + break; + case GPROP_FLOAT: + case GPROP_TIME: + sprintf(str, "%f", *((float *)&prop->data)); + break; + case GPROP_STRING: + BLI_strncpy(str, prop->poin, MAX_PROPSTRING); + break; } } diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 2d3c18ff03b..36963e55606 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -112,7 +112,7 @@ void free_qtcodecdata(QuicktimeCodecData *qcd) } } -Scene *copy_scene(Scene *sce, int type) +Scene *BKE_scene_copy(Scene *sce, int type) { Scene *scen; ToolSettings *ts; @@ -120,20 +120,20 @@ Scene *copy_scene(Scene *sce, int type) if (type == SCE_COPY_EMPTY) { ListBase lb; - scen= add_scene(sce->id.name+2); + scen = BKE_scene_add(sce->id.name + 2); - lb= scen->r.layers; - scen->r= sce->r; - scen->r.layers= lb; - scen->unit= sce->unit; - scen->physics_settings= sce->physics_settings; - scen->gm= sce->gm; - scen->audio= sce->audio; + lb = scen->r.layers; + scen->r = sce->r; + scen->r.layers = lb; + scen->unit = sce->unit; + scen->physics_settings = sce->physics_settings; + scen->gm = sce->gm; + scen->audio = sce->audio; MEM_freeN(scen->toolsettings); } else { - scen= copy_libblock(&sce->id); + scen = BKE_libblock_copy(&sce->id); BLI_duplicatelist(&(scen->base), &(sce->base)); clear_id_newpoins(); @@ -142,11 +142,11 @@ Scene *copy_scene(Scene *sce, int type) id_us_plus((ID *)scen->set); id_us_plus((ID *)scen->gm.dome.warptext); - scen->ed= NULL; - scen->theDag= NULL; - scen->obedit= NULL; - scen->stats= NULL; - scen->fps_info= NULL; + scen->ed = NULL; + scen->theDag = NULL; + scen->obedit = NULL; + scen->stats = NULL; + scen->fps_info = NULL; BLI_duplicatelist(&(scen->markers), &(sce->markers)); BLI_duplicatelist(&(scen->transform_spaces), &(sce->transform_spaces)); @@ -154,48 +154,48 @@ Scene *copy_scene(Scene *sce, int type) BKE_keyingsets_copy(&(scen->keyingsets), &(sce->keyingsets)); if (sce->nodetree) { - scen->nodetree= ntreeCopyTree(sce->nodetree); /* copies actions */ + scen->nodetree = ntreeCopyTree(sce->nodetree); /* copies actions */ ntreeSwitchID(scen->nodetree, &sce->id, &scen->id); } - obase= sce->base.first; - base= scen->base.first; + obase = sce->base.first; + base = scen->base.first; while (base) { id_us_plus(&base->object->id); - if (obase==sce->basact) scen->basact= base; + if (obase == sce->basact) scen->basact = base; - obase= obase->next; - base= base->next; + obase = obase->next; + base = base->next; } } /* tool settings */ - scen->toolsettings= MEM_dupallocN(sce->toolsettings); + scen->toolsettings = MEM_dupallocN(sce->toolsettings); - ts= scen->toolsettings; + ts = scen->toolsettings; if (ts) { if (ts->vpaint) { - ts->vpaint= MEM_dupallocN(ts->vpaint); - ts->vpaint->paintcursor= NULL; - ts->vpaint->vpaint_prev= NULL; - ts->vpaint->wpaint_prev= NULL; + ts->vpaint = MEM_dupallocN(ts->vpaint); + ts->vpaint->paintcursor = NULL; + ts->vpaint->vpaint_prev = NULL; + ts->vpaint->wpaint_prev = NULL; copy_paint(&ts->vpaint->paint, &ts->vpaint->paint); } if (ts->wpaint) { - ts->wpaint= MEM_dupallocN(ts->wpaint); - ts->wpaint->paintcursor= NULL; - ts->wpaint->vpaint_prev= NULL; - ts->wpaint->wpaint_prev= NULL; + ts->wpaint = MEM_dupallocN(ts->wpaint); + ts->wpaint->paintcursor = NULL; + ts->wpaint->vpaint_prev = NULL; + ts->wpaint->wpaint_prev = NULL; copy_paint(&ts->wpaint->paint, &ts->wpaint->paint); } if (ts->sculpt) { - ts->sculpt= MEM_dupallocN(ts->sculpt); + ts->sculpt = MEM_dupallocN(ts->sculpt); copy_paint(&ts->sculpt->paint, &ts->sculpt->paint); } copy_paint(&ts->imapaint.paint, &ts->imapaint.paint); - ts->imapaint.paintcursor= NULL; - ts->particle.paintcursor= NULL; + ts->imapaint.paintcursor = NULL; + ts->particle.paintcursor = NULL; } /* make a private copy of the avicodecdata */ @@ -212,7 +212,7 @@ Scene *copy_scene(Scene *sce, int type) } if (sce->r.ffcodecdata.properties) { /* intentionally check scen not sce. */ - scen->r.ffcodecdata.properties= IDP_CopyProperty(sce->r.ffcodecdata.properties); + scen->r.ffcodecdata.properties = IDP_CopyProperty(sce->r.ffcodecdata.properties); } /* NOTE: part of SCE_COPY_LINK_DATA and SCE_COPY_FULL operations @@ -231,13 +231,13 @@ Scene *copy_scene(Scene *sce, int type) BKE_copy_animdata_id_action((ID *)scen); if (scen->world) { id_us_plus((ID *)scen->world); - scen->world= copy_world(scen->world); + scen->world = BKE_world_copy(scen->world); BKE_copy_animdata_id_action((ID *)scen->world); } if (sce->ed) { - scen->ed= MEM_callocN(sizeof(Editing), "addseq"); - scen->ed->seqbasep= &scen->ed->seqbase; + scen->ed = MEM_callocN(sizeof(Editing), "addseq"); + scen->ed->seqbasep = &scen->ed->seqbase; seqbase_dupli_recursive(sce, scen, &scen->ed->seqbase, &sce->ed->seqbase, SEQ_DUPE_ALL); } } @@ -246,15 +246,15 @@ Scene *copy_scene(Scene *sce, int type) } /* do not free scene itself */ -void free_scene(Scene *sce) +void BKE_scene_free(Scene *sce) { Base *base; SceneRenderLayer *srl; - base= sce->base.first; + base = sce->base.first; while (base) { base->object->id.us--; - base= base->next; + base = base->next; } /* do not free objects! */ @@ -265,11 +265,11 @@ void free_scene(Scene *sce) // its probably safe not to do this, some save and reload will free this. sce->gpd->id.us--; #endif - sce->gpd= NULL; + sce->gpd = NULL; } BLI_freelistN(&sce->base); - seq_free_editing(sce); + BKE_sequencer_editing_free(sce); BKE_free_animdata((ID *)sce); BKE_keyingsets_free(&sce->keyingsets); @@ -339,76 +339,76 @@ void free_scene(Scene *sce) sound_destroy_scene(sce); } -Scene *add_scene(const char *name) +Scene *BKE_scene_add(const char *name) { - Main *bmain= G.main; + Main *bmain = G.main; Scene *sce; ParticleEditSettings *pset; int a; - sce= alloc_libblock(&bmain->scene, ID_SCE, name); - sce->lay= sce->layact= 1; + sce = BKE_libblock_alloc(&bmain->scene, ID_SCE, name); + sce->lay = sce->layact = 1; - sce->r.mode= R_GAMMA|R_OSA|R_SHADOW|R_SSS|R_ENVMAP|R_RAYTRACE; - sce->r.cfra= 1; - sce->r.sfra= 1; - sce->r.efra= 250; - sce->r.frame_step= 1; - sce->r.xsch= 1920; - sce->r.ysch= 1080; - sce->r.xasp= 1; - sce->r.yasp= 1; - sce->r.xparts= 8; - sce->r.yparts= 8; - sce->r.mblur_samples= 1; - sce->r.filtertype= R_FILTER_MITCH; - sce->r.size= 50; - - sce->r.im_format.planes= R_IMF_PLANES_RGB; - sce->r.im_format.imtype= R_IMF_IMTYPE_PNG; - sce->r.im_format.quality= 90; - - sce->r.displaymode= R_OUTPUT_AREA; - sce->r.framapto= 100; - sce->r.images= 100; - sce->r.framelen= 1.0; - sce->r.blurfac= 0.5; - sce->r.frs_sec= 24; - sce->r.frs_sec_base= 1; - sce->r.edgeint= 10; + sce->r.mode = R_GAMMA | R_OSA | R_SHADOW | R_SSS | R_ENVMAP | R_RAYTRACE; + sce->r.cfra = 1; + sce->r.sfra = 1; + sce->r.efra = 250; + sce->r.frame_step = 1; + sce->r.xsch = 1920; + sce->r.ysch = 1080; + sce->r.xasp = 1; + sce->r.yasp = 1; + sce->r.xparts = 8; + sce->r.yparts = 8; + sce->r.mblur_samples = 1; + sce->r.filtertype = R_FILTER_MITCH; + sce->r.size = 50; + + sce->r.im_format.planes = R_IMF_PLANES_RGB; + sce->r.im_format.imtype = R_IMF_IMTYPE_PNG; + sce->r.im_format.quality = 90; + + sce->r.displaymode = R_OUTPUT_AREA; + sce->r.framapto = 100; + sce->r.images = 100; + sce->r.framelen = 1.0; + sce->r.blurfac = 0.5; + sce->r.frs_sec = 24; + sce->r.frs_sec_base = 1; + sce->r.edgeint = 10; sce->r.ocres = 128; sce->r.color_mgt_flag |= R_COLOR_MANAGEMENT; - sce->r.gauss= 1.0; + sce->r.gauss = 1.0; /* deprecated but keep for upwards compat */ - sce->r.postgamma= 1.0; - sce->r.posthue= 0.0; - sce->r.postsat= 1.0; - - sce->r.bake_mode= 1; /* prevent to include render stuff here */ - sce->r.bake_filter= 2; - sce->r.bake_osa= 5; - sce->r.bake_flag= R_BAKE_CLEAR; - sce->r.bake_normal_space= R_BAKE_SPACE_TANGENT; - sce->r.scemode= R_DOCOMP|R_DOSEQ|R_EXTENSION; - sce->r.stamp= R_STAMP_TIME|R_STAMP_FRAME|R_STAMP_DATE|R_STAMP_CAMERA|R_STAMP_SCENE|R_STAMP_FILENAME|R_STAMP_RENDERTIME; - sce->r.stamp_font_id= 12; - sce->r.fg_stamp[0]= sce->r.fg_stamp[1]= sce->r.fg_stamp[2]= 0.8f; - sce->r.fg_stamp[3]= 1.0f; - sce->r.bg_stamp[0]= sce->r.bg_stamp[1]= sce->r.bg_stamp[2]= 0.0f; - sce->r.bg_stamp[3]= 0.25f; + sce->r.postgamma = 1.0; + sce->r.posthue = 0.0; + sce->r.postsat = 1.0; + + sce->r.bake_mode = 1; /* prevent to include render stuff here */ + sce->r.bake_filter = 2; + sce->r.bake_osa = 5; + sce->r.bake_flag = R_BAKE_CLEAR; + sce->r.bake_normal_space = R_BAKE_SPACE_TANGENT; + sce->r.scemode = R_DOCOMP | R_DOSEQ | R_EXTENSION; + sce->r.stamp = R_STAMP_TIME | R_STAMP_FRAME | R_STAMP_DATE | R_STAMP_CAMERA | R_STAMP_SCENE | R_STAMP_FILENAME | R_STAMP_RENDERTIME; + sce->r.stamp_font_id = 12; + sce->r.fg_stamp[0] = sce->r.fg_stamp[1] = sce->r.fg_stamp[2] = 0.8f; + sce->r.fg_stamp[3] = 1.0f; + sce->r.bg_stamp[0] = sce->r.bg_stamp[1] = sce->r.bg_stamp[2] = 0.0f; + sce->r.bg_stamp[3] = 0.25f; sce->r.raytrace_options = R_RAYTRACE_USE_INSTANCES; - sce->r.seq_prev_type= OB_SOLID; - sce->r.seq_rend_type= OB_SOLID; - sce->r.seq_flag= R_SEQ_GL_PREV; + sce->r.seq_prev_type = OB_SOLID; + sce->r.seq_rend_type = OB_SOLID; + sce->r.seq_flag = R_SEQ_GL_PREV; - sce->r.threads= 1; + sce->r.threads = 1; - sce->r.simplify_subsurf= 6; - sce->r.simplify_particles= 1.0f; - sce->r.simplify_shadowsamples= 16; - sce->r.simplify_aosss= 1.0f; + sce->r.simplify_subsurf = 6; + sce->r.simplify_particles = 1.0f; + sce->r.simplify_shadowsamples = 16; + sce->r.simplify_aosss = 1.0f; sce->r.border.xmin = 0.0f; sce->r.border.ymin = 0.0f; @@ -416,7 +416,7 @@ Scene *add_scene(const char *name) sce->r.border.ymax = 1.0f; sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings), "Tool Settings Struct"); - sce->toolsettings->cornertype=1; + sce->toolsettings->cornertype = 1; sce->toolsettings->degr = 90; sce->toolsettings->step = 9; sce->toolsettings->turn = 1; @@ -430,25 +430,25 @@ Scene *add_scene(const char *name) sce->toolsettings->uvcalc_mapdir = 1; sce->toolsettings->uvcalc_mapalign = 1; sce->toolsettings->unwrapper = 1; - sce->toolsettings->select_thresh= 0.01f; + sce->toolsettings->select_thresh = 0.01f; sce->toolsettings->jointrilimit = 0.8f; - sce->toolsettings->selectmode= SCE_SELECT_VERTEX; - sce->toolsettings->uv_selectmode= UV_SELECT_VERTEX; - sce->toolsettings->normalsize= 0.1; - sce->toolsettings->autokey_mode= U.autokey_mode; + sce->toolsettings->selectmode = SCE_SELECT_VERTEX; + sce->toolsettings->uv_selectmode = UV_SELECT_VERTEX; + sce->toolsettings->normalsize = 0.1; + sce->toolsettings->autokey_mode = U.autokey_mode; sce->toolsettings->skgen_resolution = 100; - sce->toolsettings->skgen_threshold_internal = 0.01f; - sce->toolsettings->skgen_threshold_external = 0.01f; - sce->toolsettings->skgen_angle_limit = 45.0f; - sce->toolsettings->skgen_length_ratio = 1.3f; - sce->toolsettings->skgen_length_limit = 1.5f; - sce->toolsettings->skgen_correlation_limit = 0.98f; - sce->toolsettings->skgen_symmetry_limit = 0.1f; + sce->toolsettings->skgen_threshold_internal = 0.01f; + sce->toolsettings->skgen_threshold_external = 0.01f; + sce->toolsettings->skgen_angle_limit = 45.0f; + sce->toolsettings->skgen_length_ratio = 1.3f; + sce->toolsettings->skgen_length_limit = 1.5f; + sce->toolsettings->skgen_correlation_limit = 0.98f; + sce->toolsettings->skgen_symmetry_limit = 0.1f; sce->toolsettings->skgen_postpro = SKGEN_SMOOTH; sce->toolsettings->skgen_postpro_passes = 1; - sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL|SKGEN_FILTER_EXTERNAL|SKGEN_FILTER_SMART|SKGEN_HARMONIC|SKGEN_SUB_CORRELATION|SKGEN_STICK_TO_EMBEDDING; + sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL | SKGEN_FILTER_EXTERNAL | SKGEN_FILTER_SMART | SKGEN_HARMONIC | SKGEN_SUB_CORRELATION | SKGEN_STICK_TO_EMBEDDING; sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION; sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH; sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE; @@ -462,22 +462,22 @@ Scene *add_scene(const char *name) sce->unit.scale_length = 1.0f; - pset= &sce->toolsettings->particle; - pset->flag= PE_KEEP_LENGTHS|PE_LOCK_FIRST|PE_DEFLECT_EMITTER|PE_AUTO_VELOCITY; - pset->emitterdist= 0.25f; - pset->totrekey= 5; - pset->totaddkey= 5; - pset->brushtype= PE_BRUSH_NONE; - pset->draw_step= 2; - pset->fade_frames= 2; - pset->selectmode= SCE_SELECT_PATH; - for (a=0; a<PE_TOT_BRUSH; a++) { - pset->brush[a].strength= 0.5; - pset->brush[a].size= 50; - pset->brush[a].step= 10; - pset->brush[a].count= 10; + pset = &sce->toolsettings->particle; + pset->flag = PE_KEEP_LENGTHS | PE_LOCK_FIRST | PE_DEFLECT_EMITTER | PE_AUTO_VELOCITY; + pset->emitterdist = 0.25f; + pset->totrekey = 5; + pset->totaddkey = 5; + pset->brushtype = PE_BRUSH_NONE; + pset->draw_step = 2; + pset->fade_frames = 2; + pset->selectmode = SCE_SELECT_PATH; + for (a = 0; a < PE_TOT_BRUSH; a++) { + pset->brush[a].strength = 0.5; + pset->brush[a].size = 50; + pset->brush[a].step = 10; + pset->brush[a].count = 10; } - pset->brush[PE_BRUSH_CUT].strength= 100; + pset->brush[PE_BRUSH_CUT].strength = 100; sce->r.ffcodecdata.audio_mixrate = 44100; sce->r.ffcodecdata.audio_volume = 1.0f; @@ -494,10 +494,10 @@ Scene *add_scene(const char *name) BLI_strncpy(sce->r.pic, U.renderdir, sizeof(sce->r.pic)); BLI_init_rctf(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f); - sce->r.osa= 8; + sce->r.osa = 8; /* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */ - scene_add_render_layer(sce, NULL); + BKE_scene_add_render_layer(sce, NULL); /* game data */ sce->gm.stereoflag = STEREO_NOSTEREO; @@ -510,13 +510,13 @@ Scene *add_scene(const char *name) sce->gm.dome.resbuf = 1.0f; sce->gm.dome.tilt = 0; - sce->gm.xplay= 640; - sce->gm.yplay= 480; - sce->gm.freqplay= 60; - sce->gm.depth= 32; + sce->gm.xplay = 640; + sce->gm.yplay = 480; + sce->gm.freqplay = 60; + sce->gm.depth = 32; - sce->gm.gravity= 9.8f; - sce->gm.physicsEngine= WOPHY_BULLET; + sce->gm.gravity = 9.8f; + sce->gm.physicsEngine = WOPHY_BULLET; sce->gm.mode = 32; //XXX ugly harcoding, still not sure we should drop mode. 32 == 1 << 5 == use_occlusion_culling sce->gm.occlusionRes = 128; sce->gm.ticrate = 60; @@ -527,12 +527,12 @@ Scene *add_scene(const char *name) sce->gm.flag = GAME_DISPLAY_LISTS; sce->gm.matmode = GAME_MAT_MULTITEX; - sce->gm.obstacleSimulation= OBSTSIMULATION_NONE; + sce->gm.obstacleSimulation = OBSTSIMULATION_NONE; sce->gm.levelHeight = 2.f; sce->gm.recastData.cellsize = 0.3f; sce->gm.recastData.cellheight = 0.2f; - sce->gm.recastData.agentmaxslope = M_PI/2; + sce->gm.recastData.agentmaxslope = M_PI / 2; sce->gm.recastData.agentmaxclimb = 0.9f; sce->gm.recastData.agentheight = 2.0f; sce->gm.recastData.agentradius = 0.6f; @@ -551,19 +551,19 @@ Scene *add_scene(const char *name) return sce; } -Base *object_in_scene(Object *ob, Scene *sce) +Base *BKE_scene_base_find(Scene *scene, Object *ob) { Base *base; - base= sce->base.first; + base = scene->base.first; while (base) { if (base->object == ob) return base; - base= base->next; + base = base->next; } return NULL; } -void set_scene_bg(Main *bmain, Scene *scene) +void BKE_scene_set_background(Main *bmain, Scene *scene) { Scene *sce; Base *base; @@ -573,22 +573,22 @@ void set_scene_bg(Main *bmain, Scene *scene) int flag; /* check for cyclic sets, for reading old files but also for definite security (py?) */ - scene_check_setscene(bmain, scene); + BKE_scene_validate_setscene(bmain, scene); /* can happen when switching modes in other scenes */ if (scene->obedit && !(scene->obedit->mode & OB_MODE_EDIT)) - scene->obedit= NULL; + scene->obedit = NULL; /* deselect objects (for dataselect) */ - for (ob= bmain->object.first; ob; ob= ob->id.next) - ob->flag &= ~(SELECT|OB_FROMGROUP); + for (ob = bmain->object.first; ob; ob = ob->id.next) + ob->flag &= ~(SELECT | OB_FROMGROUP); /* group flags again */ - for (group= bmain->group.first; group; group= group->id.next) { - go= group->gobject.first; + for (group = bmain->group.first; group; group = group->id.next) { + go = group->gobject.first; while (go) { if (go->ob) go->ob->flag |= OB_FROMGROUP; - go= go->next; + go = go->next; } } @@ -596,35 +596,35 @@ void set_scene_bg(Main *bmain, Scene *scene) DAG_scene_sort(bmain, scene); /* ensure dags are built for sets */ - for (sce= scene->set; sce; sce= sce->set) - if (sce->theDag==NULL) + for (sce = scene->set; sce; sce = sce->set) + if (sce->theDag == NULL) DAG_scene_sort(bmain, sce); /* copy layers and flags from bases to objects */ - for (base= scene->base.first; base; base= base->next) { - ob= base->object; - ob->lay= base->lay; + for (base = scene->base.first; base; base = base->next) { + ob = base->object; + ob->lay = base->lay; /* group patch... */ base->flag &= ~(OB_FROMGROUP); - flag= ob->flag & (OB_FROMGROUP); + flag = ob->flag & (OB_FROMGROUP); base->flag |= flag; /* not too nice... for recovering objects with lost data */ //if (ob->pose==NULL) base->flag &= ~OB_POSEMODE; - ob->flag= base->flag; + ob->flag = base->flag; - ob->ctime= -1234567.0; /* force ipo to be calculated later */ + ob->ctime = -1234567.0; /* force ipo to be calculated later */ } /* no full animation update, this to enable render code to work (render code calls own animation updates) */ } /* called from creator.c */ -Scene *set_scene_name(Main *bmain, const char *name) +Scene *BKE_scene_set_name(Main *bmain, const char *name) { - Scene *sce= (Scene *)find_id("SC", name); + Scene *sce = (Scene *)BKE_libblock_find_name(ID_SCE, name); if (sce) { - set_scene_bg(bmain, sce); + BKE_scene_set_background(bmain, sce); printf("Scene switch: '%s' in file: '%s'\n", name, G.main->name); return sce; } @@ -633,15 +633,15 @@ Scene *set_scene_name(Main *bmain, const char *name) return NULL; } -void unlink_scene(Main *bmain, Scene *sce, Scene *newsce) +void BKE_scene_unlink(Main *bmain, Scene *sce, Scene *newsce) { Scene *sce1; bScreen *sc; /* check all sets */ - for (sce1= bmain->scene.first; sce1; sce1= sce1->id.next) + for (sce1 = bmain->scene.first; sce1; sce1 = sce1->id.next) if (sce1->set == sce) - sce1->set= NULL; + sce1->set = NULL; /* check all sequences */ clear_scene_in_allseqs(bmain, sce); @@ -650,27 +650,27 @@ void unlink_scene(Main *bmain, Scene *sce, Scene *newsce) clear_scene_in_nodes(bmain, sce); /* al screens */ - for (sc= bmain->screen.first; sc; sc= sc->id.next) + for (sc = bmain->screen.first; sc; sc = sc->id.next) if (sc->scene == sce) - sc->scene= newsce; + sc->scene = newsce; - free_libblock(&bmain->scene, sce); + BKE_libblock_free(&bmain->scene, sce); } /* used by metaballs * doesnt return the original duplicated object, only dupli's */ -int next_object(Scene **scene, int val, Base **base, Object **ob) +int BKE_scene_base_iter_next(Scene **scene, int val, Base **base, Object **ob) { - static ListBase *duplilist= NULL; + static ListBase *duplilist = NULL; static DupliObject *dupob; - static int fase= F_START, in_next_object= 0; - int run_again=1; + static int fase = F_START, in_next_object = 0; + int run_again = 1; /* init */ - if (val==0) { - fase= F_START; - dupob= NULL; + if (val == 0) { + fase = F_START; + dupob = NULL; /* XXX particle systems with metas+dupligroups call this recursively */ /* see bug #18725 */ @@ -681,44 +681,44 @@ int next_object(Scene **scene, int val, Base **base, Object **ob) } } else { - in_next_object= 1; + in_next_object = 1; /* run_again is set when a duplilist has been ended */ while (run_again) { - run_again= 0; + run_again = 0; /* the first base */ - if (fase==F_START) { - *base= (*scene)->base.first; + if (fase == F_START) { + *base = (*scene)->base.first; if (*base) { - *ob= (*base)->object; - fase= F_SCENE; + *ob = (*base)->object; + fase = F_SCENE; } else { /* exception: empty scene */ while ((*scene)->set) { - (*scene)= (*scene)->set; + (*scene) = (*scene)->set; if ((*scene)->base.first) { - *base= (*scene)->base.first; - *ob= (*base)->object; - fase= F_SCENE; + *base = (*scene)->base.first; + *ob = (*base)->object; + fase = F_SCENE; break; } } } } else { - if (*base && fase!=F_DUPLI) { - *base= (*base)->next; - if (*base) *ob= (*base)->object; + if (*base && fase != F_DUPLI) { + *base = (*base)->next; + if (*base) *ob = (*base)->object; else { - if (fase==F_SCENE) { + if (fase == F_SCENE) { /* (*scene) is finished, now do the set */ while ((*scene)->set) { - (*scene)= (*scene)->set; + (*scene) = (*scene)->set; if ((*scene)->base.first) { - *base= (*scene)->base.first; - *ob= (*base)->object; + *base = (*scene)->base.first; + *ob = (*base)->object; break; } } @@ -727,17 +727,17 @@ int next_object(Scene **scene, int val, Base **base, Object **ob) } } - if (*base == NULL) fase= F_START; + if (*base == NULL) fase = F_START; else { - if (fase!=F_DUPLI) { + if (fase != F_DUPLI) { if ( (*base)->object->transflag & OB_DUPLI) { /* groups cannot be duplicated for mballs yet, * this enters eternal loop because of * makeDispListMBall getting called inside of group_duplilist */ if ((*base)->object->dup_group == NULL) { - duplilist= object_duplilist((*scene), (*base)->object); + duplilist = object_duplilist((*scene), (*base)->object); - dupob= duplilist->first; + dupob = duplilist->first; if (!dupob) free_object_duplilist(duplilist); @@ -750,22 +750,22 @@ int next_object(Scene **scene, int val, Base **base, Object **ob) copy_m4_m4(dupob->ob->obmat, dupob->mat); (*base)->flag |= OB_FROMDUPLI; - *ob= dupob->ob; - fase= F_DUPLI; + *ob = dupob->ob; + fase = F_DUPLI; - dupob= dupob->next; + dupob = dupob->next; } - else if (fase==F_DUPLI) { - fase= F_SCENE; + else if (fase == F_DUPLI) { + fase = F_SCENE; (*base)->flag &= ~OB_FROMDUPLI; - for (dupob= duplilist->first; dupob; dupob= dupob->next) { + for (dupob = duplilist->first; dupob; dupob = dupob->next) { copy_m4_m4(dupob->ob->obmat, dupob->omat); } free_object_duplilist(duplilist); - duplilist= NULL; - run_again= 1; + duplilist = NULL; + run_again = 1; } } } @@ -773,39 +773,39 @@ int next_object(Scene **scene, int val, Base **base, Object **ob) #if 0 if (ob && *ob) { - printf("Scene: '%s', '%s'\n", (*scene)->id.name+2, (*ob)->id.name+2); + printf("Scene: '%s', '%s'\n", (*scene)->id.name + 2, (*ob)->id.name + 2); } #endif /* reset recursion test */ - in_next_object= 0; + in_next_object = 0; return fase; } -Object *scene_find_camera(Scene *sc) +Object *BKE_scene_camera_find(Scene *sc) { Base *base; - for (base= sc->base.first; base; base= base->next) - if (base->object->type==OB_CAMERA) + for (base = sc->base.first; base; base = base->next) + if (base->object->type == OB_CAMERA) return base->object; return NULL; } #ifdef DURIAN_CAMERA_SWITCH -Object *scene_camera_switch_find(Scene *scene) +Object *BKE_scene_camera_switch_find(Scene *scene) { TimeMarker *m; int cfra = scene->r.cfra; int frame = -(MAXFRAME + 1); - Object *camera= NULL; + Object *camera = NULL; - for (m= scene->markers.first; m; m= m->next) { - if (m->camera && (m->camera->restrictflag & OB_RESTRICT_RENDER)==0 && (m->frame <= cfra) && (m->frame > frame)) { - camera= m->camera; - frame= m->frame; + for (m = scene->markers.first; m; m = m->next) { + if (m->camera && (m->camera->restrictflag & OB_RESTRICT_RENDER) == 0 && (m->frame <= cfra) && (m->frame > frame)) { + camera = m->camera; + frame = m->frame; if (frame == cfra) break; @@ -816,12 +816,12 @@ Object *scene_camera_switch_find(Scene *scene) } #endif -int scene_camera_switch_update(Scene *scene) +int BKE_scene_camera_switch_update(Scene *scene) { #ifdef DURIAN_CAMERA_SWITCH - Object *camera= scene_camera_switch_find(scene); + Object *camera = BKE_scene_camera_switch_find(scene); if (camera) { - scene->camera= camera; + scene->camera = camera; return 1; } #else @@ -830,20 +830,20 @@ int scene_camera_switch_update(Scene *scene) return 0; } -char *scene_find_marker_name(Scene *scene, int frame) +char *BKE_scene_find_marker_name(Scene *scene, int frame) { - ListBase *markers= &scene->markers; + ListBase *markers = &scene->markers; TimeMarker *m1, *m2; /* search through markers for match */ - for (m1=markers->first, m2=markers->last; m1 && m2; m1=m1->next, m2=m2->prev) { - if (m1->frame==frame) + for (m1 = markers->first, m2 = markers->last; m1 && m2; m1 = m1->next, m2 = m2->prev) { + if (m1->frame == frame) return m1->name; if (m1 == m2) break; - if (m2->frame==frame) + if (m2->frame == frame) return m2->name; } @@ -852,16 +852,16 @@ char *scene_find_marker_name(Scene *scene, int frame) /* return the current marker for this frame, * we can have more then 1 marker per frame, this just returns the first :/ */ -char *scene_find_last_marker_name(Scene *scene, int frame) +char *BKE_scene_find_last_marker_name(Scene *scene, int frame) { TimeMarker *marker, *best_marker = NULL; - int best_frame = -MAXFRAME*2; - for (marker= scene->markers.first; marker; marker= marker->next) { - if (marker->frame==frame) { + int best_frame = -MAXFRAME * 2; + for (marker = scene->markers.first; marker; marker = marker->next) { + if (marker->frame == frame) { return marker->name; } - if ( marker->frame > best_frame && marker->frame < frame) { + if (marker->frame > best_frame && marker->frame < frame) { best_marker = marker; best_frame = marker->frame; } @@ -871,53 +871,53 @@ char *scene_find_last_marker_name(Scene *scene, int frame) } -Base *scene_add_base(Scene *sce, Object *ob) +Base *BKE_scene_base_add(Scene *sce, Object *ob) { - Base *b= MEM_callocN(sizeof(*b), "scene_add_base"); + Base *b = MEM_callocN(sizeof(*b), "BKE_scene_base_add"); BLI_addhead(&sce->base, b); - b->object= ob; - b->flag= ob->flag; - b->lay= ob->lay; + b->object = ob; + b->flag = ob->flag; + b->lay = ob->lay; return b; } -void scene_deselect_all(Scene *sce) +void BKE_scene_base_deselect_all(Scene *sce) { Base *b; - for (b= sce->base.first; b; b= b->next) { - b->flag&= ~SELECT; - b->object->flag= b->flag; + for (b = sce->base.first; b; b = b->next) { + b->flag &= ~SELECT; + b->object->flag = b->flag; } } -void scene_select_base(Scene *sce, Base *selbase) +void BKE_scene_base_select(Scene *sce, Base *selbase) { selbase->flag |= SELECT; - selbase->object->flag= selbase->flag; + selbase->object->flag = selbase->flag; - sce->basact= selbase; + sce->basact = selbase; } /* checks for cycle, returns 1 if it's all OK */ -int scene_check_setscene(Main *bmain, Scene *sce) +int BKE_scene_validate_setscene(Main *bmain, Scene *sce) { Scene *scene; int a, totscene; - if (sce->set==NULL) return 1; + if (sce->set == NULL) return 1; - totscene= 0; - for (scene= bmain->scene.first; scene; scene= scene->id.next) + totscene = 0; + for (scene = bmain->scene.first; scene; scene = scene->id.next) totscene++; - for (a=0, scene=sce; scene->set; scene=scene->set, a++) { + for (a = 0, scene = sce; scene->set; scene = scene->set, a++) { /* more iterations than scenes means we have a cycle */ if (a > totscene) { /* the tested scene gets zero'ed, that's typically current scene */ - sce->set= NULL; + sce->set = NULL; return 0; } } @@ -928,13 +928,13 @@ int scene_check_setscene(Main *bmain, Scene *sce) /* This function is needed to cope with fractional frames - including two Blender rendering features * mblur (motion blur that renders 'subframes' and blurs them together), and fields rendering. */ -float BKE_curframe(Scene *scene) +float BKE_scene_frame_get(Scene *scene) { - return BKE_frame_to_ctime(scene, scene->r.cfra); + return BKE_scene_frame_get_from_ctime(scene, scene->r.cfra); } /* This function is used to obtain arbitrary fractional frames */ -float BKE_frame_to_ctime(Scene *scene, const float frame) +float BKE_scene_frame_get_from_ctime(Scene *scene, const float frame) { float ctime = frame; ctime += scene->r.subframe; @@ -944,14 +944,14 @@ float BKE_frame_to_ctime(Scene *scene, const float frame) } /* drivers support/hacks - * - this method is called from scene_update_tagged_recursive(), so gets included in viewport + render + * - this method is called from scene_update_tagged_recursive(), so gets included in viewport + render * - these are always run since the depsgraph can't handle non-object data * - these happen after objects are all done so that we can read in their final transform values, * though this means that objects can't refer to scene info for guidance... */ static void scene_update_drivers(Main *UNUSED(bmain), Scene *scene) { - float ctime = BKE_curframe(scene); + float ctime = BKE_scene_frame_get(scene); /* scene itself */ if (scene->adt && scene->adt->drivers.first) { @@ -962,7 +962,7 @@ static void scene_update_drivers(Main *UNUSED(bmain), Scene *scene) // TODO: what about world textures? but then those have nodes too... if (scene->world) { ID *wid = (ID *)scene->world; - AnimData *adt= BKE_animdata_from_id(wid); + AnimData *adt = BKE_animdata_from_id(wid); if (adt && adt->drivers.first) BKE_animsys_evaluate_animdata(scene, wid, adt, ctime, ADT_RECALC_DRIVERS); @@ -971,7 +971,7 @@ static void scene_update_drivers(Main *UNUSED(bmain), Scene *scene) /* nodes */ if (scene->nodetree) { ID *nid = (ID *)scene->nodetree; - AnimData *adt= BKE_animdata_from_id(nid); + AnimData *adt = BKE_animdata_from_id(nid); if (adt && adt->drivers.first) BKE_animsys_evaluate_animdata(scene, nid, adt, ctime, ADT_RECALC_DRIVERS); @@ -983,7 +983,7 @@ static void scene_update_tagged_recursive(Main *bmain, Scene *scene, Scene *scen Base *base; - scene->customdata_mask= scene_parent->customdata_mask; + scene->customdata_mask = scene_parent->customdata_mask; /* sets first, we allow per definition current scene to have * dependencies on sets, but not the other way around. */ @@ -991,16 +991,16 @@ static void scene_update_tagged_recursive(Main *bmain, Scene *scene, Scene *scen scene_update_tagged_recursive(bmain, scene->set, scene_parent); /* scene objects */ - for (base= scene->base.first; base; base= base->next) { - Object *ob= base->object; + for (base = scene->base.first; base; base = base->next) { + Object *ob = base->object; - object_handle_update(scene_parent, ob); + BKE_object_handle_update(scene_parent, ob); if (ob->dup_group && (ob->transflag & OB_DUPLIGROUP)) group_handle_recalc_and_update(scene_parent, ob, ob->dup_group); /* always update layer, so that animating layers works */ - base->lay= ob->lay; + base->lay = ob->lay; } /* scene drivers... */ @@ -1011,7 +1011,7 @@ static void scene_update_tagged_recursive(Main *bmain, Scene *scene, Scene *scen } /* this is called in main loop, doing tagged updates before redraw */ -void scene_update_tagged(Main *bmain, Scene *scene) +void BKE_scene_update_tagged(Main *bmain, Scene *scene) { /* keep this first */ BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_SCENE_UPDATE_PRE); @@ -1019,7 +1019,7 @@ void scene_update_tagged(Main *bmain, Scene *scene) /* flush recalc flags to dependencies */ DAG_ids_flush_tagged(bmain); - scene->physics_settings.quick_cache_step= 0; + scene->physics_settings.quick_cache_step = 0; /* update all objects: drivers, matrices, displists, etc. flags set * by depgraph or manual, no layer check here, gets correct flushed @@ -1030,8 +1030,8 @@ void scene_update_tagged(Main *bmain, Scene *scene) /* extra call here to recalc scene animation (for sequencer) */ { - AnimData *adt= BKE_animdata_from_id(&scene->id); - float ctime = BKE_curframe(scene); + AnimData *adt = BKE_animdata_from_id(&scene->id); + float ctime = BKE_scene_frame_get(scene); if (adt && (adt->recalc & ADT_RECALC_ANIM)) BKE_animsys_evaluate_animdata(scene, &scene->id, adt, ctime, 0); @@ -1050,9 +1050,9 @@ void scene_update_tagged(Main *bmain, Scene *scene) } /* applies changes right away, does all sets too */ -void scene_update_for_newframe(Main *bmain, Scene *sce, unsigned int lay) +void BKE_scene_update_for_newframe(Main *bmain, Scene *sce, unsigned int lay) { - float ctime = BKE_curframe(sce); + float ctime = BKE_scene_frame_get(sce); Scene *sce_iter; /* keep this first */ @@ -1064,14 +1064,14 @@ void scene_update_for_newframe(Main *bmain, Scene *sce, unsigned int lay) /* clear animation overrides */ // XXX TODO... - for (sce_iter= sce; sce_iter; sce_iter= sce_iter->set) { - if (sce_iter->theDag==NULL) + for (sce_iter = sce; sce_iter; sce_iter = sce_iter->set) { + if (sce_iter->theDag == NULL) DAG_scene_sort(bmain, sce_iter); } /* flush recalc flags to dependencies, if we were only changing a frame * this would not be necessary, but if a user or a script has modified - * some datablock before scene_update_tagged was called, we need the flush */ + * some datablock before BKE_scene_update_tagged was called, we need the flush */ DAG_ids_flush_tagged(bmain); /* Following 2 functions are recursive @@ -1087,7 +1087,7 @@ void scene_update_for_newframe(Main *bmain, Scene *sce, unsigned int lay) BKE_animsys_evaluate_all_animation(bmain, sce, ctime); /*...done with recusrive funcs */ - /* object_handle_update() on all objects, groups and sets */ + /* BKE_object_handle_update() on all objects, groups and sets */ scene_update_tagged_recursive(bmain, sce, sce); /* notify editors and python about recalc */ @@ -1101,30 +1101,30 @@ void scene_update_for_newframe(Main *bmain, Scene *sce, unsigned int lay) } /* return default layer, also used to patch old files */ -SceneRenderLayer *scene_add_render_layer(Scene *sce, const char *name) +SceneRenderLayer *BKE_scene_add_render_layer(Scene *sce, const char *name) { SceneRenderLayer *srl; if (!name) - name= "RenderLayer"; + name = "RenderLayer"; - srl= MEM_callocN(sizeof(SceneRenderLayer), "new render layer"); + srl = MEM_callocN(sizeof(SceneRenderLayer), "new render layer"); BLI_strncpy(srl->name, name, sizeof(srl->name)); BLI_uniquename(&sce->r.layers, srl, "RenderLayer", '.', offsetof(SceneRenderLayer, name), sizeof(srl->name)); BLI_addtail(&sce->r.layers, srl); /* note, this is also in render, pipeline.c, to make layer when scenedata doesnt have it */ - srl->lay= (1<<20) -1; - srl->layflag= 0x7FFF; /* solid ztra halo edge strand */ - srl->passflag= SCE_PASS_COMBINED|SCE_PASS_Z; + srl->lay = (1 << 20) - 1; + srl->layflag = 0x7FFF; /* solid ztra halo edge strand */ + srl->passflag = SCE_PASS_COMBINED | SCE_PASS_Z; FRS_add_freestyle_config( srl ); return srl; } -int scene_remove_render_layer(Main *bmain, Scene *scene, SceneRenderLayer *srl) +int BKE_scene_remove_render_layer(Main *bmain, Scene *scene, SceneRenderLayer *srl) { - const int act= BLI_findindex(&scene->r.layers, srl); + const int act = BLI_findindex(&scene->r.layers, srl); Scene *sce; if (act == -1) { @@ -1140,16 +1140,16 @@ int scene_remove_render_layer(Main *bmain, Scene *scene, SceneRenderLayer *srl) BLI_remlink(&scene->r.layers, srl); MEM_freeN(srl); - scene->r.actlay= 0; + scene->r.actlay = 0; for (sce = bmain->scene.first; sce; sce = sce->id.next) { if (sce->nodetree) { bNode *node; for (node = sce->nodetree->nodes.first; node; node = node->next) { - if (node->type==CMP_NODE_R_LAYERS && (Scene*)node->id==scene) { - if (node->custom1==act) - node->custom1= 0; - else if (node->custom1>act) + if (node->type == CMP_NODE_R_LAYERS && (Scene *)node->id == scene) { + if (node->custom1 == act) + node->custom1 = 0; + else if (node->custom1 > act) node->custom1--; } } @@ -1172,7 +1172,7 @@ int get_render_subsurf_level(RenderData *r, int lvl) int get_render_child_particle_number(RenderData *r, int num) { if (r->mode & R_SIMPLIFY) - return (int)(r->simplify_particles*num); + return (int)(r->simplify_particles * num); else return num; } @@ -1188,7 +1188,7 @@ int get_render_shadow_samples(RenderData *r, int samples) float get_render_aosss_error(RenderData *r, float error) { if (r->mode & R_SIMPLIFY) - return ((1.0f-r->simplify_aosss)*10.0f + 1.0f)*error; + return ((1.0f - r->simplify_aosss) * 10.0f + 1.0f) * error; else return error; } @@ -1200,14 +1200,14 @@ Base *_setlooper_base_step(Scene **sce_iter, Base *base) /* common case, step to the next */ return base->next; } - else if (base==NULL && (*sce_iter)->base.first) { + else if (base == NULL && (*sce_iter)->base.first) { /* first time looping, return the scenes first base */ return (Base *)(*sce_iter)->base.first; } else { /* reached the end, get the next base in the set */ - while ((*sce_iter= (*sce_iter)->set)) { - base= (Base *)(*sce_iter)->base.first; + while ((*sce_iter = (*sce_iter)->set)) { + base = (Base *)(*sce_iter)->base.first; if (base) { return base; } @@ -1217,9 +1217,28 @@ Base *_setlooper_base_step(Scene **sce_iter, Base *base) return NULL; } -int scene_use_new_shading_nodes(Scene *scene) +int BKE_scene_use_new_shading_nodes(Scene *scene) { - RenderEngineType *type= RE_engines_find(scene->r.engine); + RenderEngineType *type = RE_engines_find(scene->r.engine); return (type && type->flag & RE_USE_SHADING_NODES); } +void BKE_scene_base_flag_to_objects(struct Scene *scene) +{ + Base *base = scene->base.first; + + while (base) { + base->object->flag = base->flag; + base = base->next; + } +} + +void BKE_scene_base_flag_from_objects(struct Scene *scene) +{ + Base *base = scene->base.first; + + while (base) { + base->flag = base->object->flag; + base = base->next; + } +} diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index f69495483ea..1f129b1c547 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -51,7 +51,7 @@ /* ************ Spacetype/regiontype handling ************** */ /* keep global; this has to be accessible outside of windowmanager */ -static ListBase spacetypes= {NULL, NULL}; +static ListBase spacetypes = {NULL, NULL}; /* not SpaceType itself */ static void spacetype_free(SpaceType *st) @@ -60,14 +60,14 @@ static void spacetype_free(SpaceType *st) PanelType *pt; HeaderType *ht; - for (art= st->regiontypes.first; art; art= art->next) { + for (art = st->regiontypes.first; art; art = art->next) { BLI_freelistN(&art->drawcalls); - for (pt= art->paneltypes.first; pt; pt= pt->next) + for (pt = art->paneltypes.first; pt; pt = pt->next) if (pt->ext.free) pt->ext.free(pt->ext.data); - for (ht= art->headertypes.first; ht; ht= ht->next) + for (ht = art->headertypes.first; ht; ht = ht->next) if (ht->ext.free) ht->ext.free(ht->ext.data); @@ -84,7 +84,7 @@ void BKE_spacetypes_free(void) { SpaceType *st; - for (st= spacetypes.first; st; st= st->next) { + for (st = spacetypes.first; st; st = st->next) { spacetype_free(st); } @@ -95,8 +95,8 @@ SpaceType *BKE_spacetype_from_id(int spaceid) { SpaceType *st; - for (st= spacetypes.first; st; st= st->next) { - if (st->spaceid==spaceid) + for (st = spacetypes.first; st; st = st->next) { + if (st->spaceid == spaceid) return st; } return NULL; @@ -106,8 +106,8 @@ ARegionType *BKE_regiontype_from_id(SpaceType *st, int regionid) { ARegionType *art; - for (art= st->regiontypes.first; art; art= art->next) - if (art->regionid==regionid) + for (art = st->regiontypes.first; art; art = art->next) + if (art->regionid == regionid) return art; printf("Error, region type missing in - name:\"%s\", id:%d\n", st->name, st->spaceid); @@ -125,7 +125,7 @@ void BKE_spacetype_register(SpaceType *st) SpaceType *stype; /* sanity check */ - stype= BKE_spacetype_from_id(st->spaceid); + stype = BKE_spacetype_from_id(st->spaceid); if (stype) { printf("error: redefinition of spacetype %s\n", stype->name); spacetype_free(stype); @@ -142,11 +142,11 @@ void BKE_spacedata_freelist(ListBase *lb) SpaceLink *sl; ARegion *ar; - for (sl= lb->first; sl; sl= sl->next) { - SpaceType *st= BKE_spacetype_from_id(sl->spacetype); + for (sl = lb->first; sl; sl = sl->next) { + SpaceType *st = BKE_spacetype_from_id(sl->spacetype); /* free regions for pushed spaces */ - for (ar=sl->regionbase.first; ar; ar=ar->next) + for (ar = sl->regionbase.first; ar; ar = ar->next) BKE_area_region_free(st, ar); BLI_freelistN(&sl->regionbase); @@ -160,41 +160,41 @@ void BKE_spacedata_freelist(ListBase *lb) ARegion *BKE_area_region_copy(SpaceType *st, ARegion *ar) { - ARegion *newar= MEM_dupallocN(ar); + ARegion *newar = MEM_dupallocN(ar); Panel *pa, *newpa, *patab; - newar->prev= newar->next= NULL; - newar->handlers.first= newar->handlers.last= NULL; - newar->uiblocks.first= newar->uiblocks.last= NULL; - newar->swinid= 0; + newar->prev = newar->next = NULL; + newar->handlers.first = newar->handlers.last = NULL; + newar->uiblocks.first = newar->uiblocks.last = NULL; + newar->swinid = 0; /* use optional regiondata callback */ if (ar->regiondata) { - ARegionType *art= BKE_regiontype_from_id(st, ar->regiontype); + ARegionType *art = BKE_regiontype_from_id(st, ar->regiontype); if (art && art->duplicate) - newar->regiondata= art->duplicate(ar->regiondata); + newar->regiondata = art->duplicate(ar->regiondata); else - newar->regiondata= MEM_dupallocN(ar->regiondata); + newar->regiondata = MEM_dupallocN(ar->regiondata); } if (ar->v2d.tab_offset) - newar->v2d.tab_offset= MEM_dupallocN(ar->v2d.tab_offset); + newar->v2d.tab_offset = MEM_dupallocN(ar->v2d.tab_offset); - newar->panels.first= newar->panels.last= NULL; + newar->panels.first = newar->panels.last = NULL; BLI_duplicatelist(&newar->panels, &ar->panels); /* copy panel pointers */ - for (newpa= newar->panels.first; newpa; newpa= newpa->next) { - patab= newar->panels.first; - pa= ar->panels.first; + for (newpa = newar->panels.first; newpa; newpa = newpa->next) { + patab = newar->panels.first; + pa = ar->panels.first; while (patab) { if (newpa->paneltab == pa) { newpa->paneltab = patab; break; } - patab= patab->next; - pa= pa->next; + patab = patab->next; + pa = pa->next; } } @@ -208,10 +208,10 @@ static void region_copylist(SpaceType *st, ListBase *lb1, ListBase *lb2) ARegion *ar; /* to be sure */ - lb1->first= lb1->last= NULL; + lb1->first = lb1->last = NULL; - for (ar= lb2->first; ar; ar= ar->next) { - ARegion *arnew= BKE_area_region_copy(st, ar); + for (ar = lb2->first; ar; ar = ar->next) { + ARegion *arnew = BKE_area_region_copy(st, ar); BLI_addtail(lb1, arnew); } } @@ -222,13 +222,13 @@ void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2) { SpaceLink *sl; - lb1->first= lb1->last= NULL; /* to be sure */ + lb1->first = lb1->last = NULL; /* to be sure */ - for (sl= lb2->first; sl; sl= sl->next) { - SpaceType *st= BKE_spacetype_from_id(sl->spacetype); + for (sl = lb2->first; sl; sl = sl->next) { + SpaceType *st = BKE_spacetype_from_id(sl->spacetype); if (st && st->duplicate) { - SpaceLink *slnew= st->duplicate(sl); + SpaceLink *slnew = st->duplicate(sl); BLI_addtail(lb1, slnew); @@ -244,14 +244,14 @@ void BKE_spacedata_draw_locks(int set) { SpaceType *st; - for (st= spacetypes.first; st; st= st->next) { + for (st = spacetypes.first; st; st = st->next) { ARegionType *art; - for (art= st->regiontypes.first; art; art= art->next) { + for (art = st->regiontypes.first; art; art = art->next) { if (set) - art->do_lock= art->lock; + art->do_lock = art->lock; else - art->do_lock= 0; + art->do_lock = 0; } } } @@ -261,7 +261,7 @@ void BKE_spacedata_draw_locks(int set) void BKE_area_region_free(SpaceType *st, ARegion *ar) { if (st) { - ARegionType *art= BKE_regiontype_from_id(st, ar->regiontype); + ARegionType *art = BKE_regiontype_from_id(st, ar->regiontype); if (art && art->free) art->free(ar); @@ -274,7 +274,7 @@ void BKE_area_region_free(SpaceType *st, ARegion *ar) if (ar->v2d.tab_offset) { MEM_freeN(ar->v2d.tab_offset); - ar->v2d.tab_offset= NULL; + ar->v2d.tab_offset = NULL; } BLI_freelistN(&ar->panels); @@ -283,10 +283,10 @@ void BKE_area_region_free(SpaceType *st, ARegion *ar) /* not area itself */ void BKE_screen_area_free(ScrArea *sa) { - SpaceType *st= BKE_spacetype_from_id(sa->spacetype); + SpaceType *st = BKE_spacetype_from_id(sa->spacetype); ARegion *ar; - for (ar=sa->regionbase.first; ar; ar=ar->next) + for (ar = sa->regionbase.first; ar; ar = ar->next) BKE_area_region_free(st, ar); BLI_freelistN(&sa->regionbase); @@ -297,18 +297,18 @@ void BKE_screen_area_free(ScrArea *sa) } /* don't free screen itself */ -void free_screen(bScreen *sc) +void BKE_screen_free(bScreen *sc) { ScrArea *sa, *san; ARegion *ar; - for (ar=sc->regionbase.first; ar; ar=ar->next) + for (ar = sc->regionbase.first; ar; ar = ar->next) BKE_area_region_free(NULL, ar); BLI_freelistN(&sc->regionbase); - for (sa= sc->areabase.first; sa; sa= san) { - san= sa->next; + for (sa = sc->areabase.first; sa; sa = san) { + san = sa->next; BKE_screen_area_free(sa); } @@ -321,12 +321,12 @@ void free_screen(bScreen *sc) unsigned int BKE_screen_visible_layers(bScreen *screen, Scene *scene) { ScrArea *sa; - unsigned int layer= 0; + unsigned int layer = 0; if (screen) { /* get all used view3d layers */ - for (sa= screen->areabase.first; sa; sa= sa->next) - if (sa->spacetype==SPACE_VIEW3D) + for (sa = screen->areabase.first; sa; sa = sa->next) + if (sa->spacetype == SPACE_VIEW3D) layer |= ((View3D *)sa->spacedata.first)->lay; } @@ -344,7 +344,7 @@ ARegion *BKE_area_find_region_type(ScrArea *sa, int type) if (sa) { ARegion *ar; - for (ar=sa->regionbase.first; ar; ar= ar->next) { + for (ar = sa->regionbase.first; ar; ar = ar->next) { if (ar->regiontype == type) return ar; } @@ -357,16 +357,16 @@ ARegion *BKE_area_find_region_type(ScrArea *sa, int type) * -1 for any type */ struct ScrArea *BKE_screen_find_big_area(struct bScreen *sc, const int spacetype, const short min) { - ScrArea *sa, *big= NULL; - int size, maxsize= 0; + ScrArea *sa, *big = NULL; + int size, maxsize = 0; - for (sa= sc->areabase.first; sa; sa= sa->next) { + for (sa = sc->areabase.first; sa; sa = sa->next) { if ((spacetype == -1) || sa->spacetype == spacetype) { if (min <= sa->winx && min <= sa->winy) { - size= sa->winx*sa->winy; + size = sa->winx * sa->winy; if (size > maxsize) { - maxsize= size; - big= sa; + maxsize = size; + big = sa; } } } @@ -379,26 +379,26 @@ void BKE_screen_view3d_sync(struct View3D *v3d, struct Scene *scene) { int bit; - if (v3d->scenelock && v3d->localvd==NULL) { - v3d->lay= scene->lay; - v3d->camera= scene->camera; + if (v3d->scenelock && v3d->localvd == NULL) { + v3d->lay = scene->lay; + v3d->camera = scene->camera; - if (v3d->camera==NULL) { + if (v3d->camera == NULL) { ARegion *ar; - for (ar=v3d->regionbase.first; ar; ar= ar->next) { + for (ar = v3d->regionbase.first; ar; ar = ar->next) { if (ar->regiontype == RGN_TYPE_WINDOW) { - RegionView3D *rv3d= ar->regiondata; - if (rv3d->persp==RV3D_CAMOB) - rv3d->persp= RV3D_PERSP; + RegionView3D *rv3d = ar->regiondata; + if (rv3d->persp == RV3D_CAMOB) + rv3d->persp = RV3D_PERSP; } } } if ((v3d->lay & v3d->layact) == 0) { - for (bit= 0; bit<32; bit++) { - if (v3d->lay & (1<<bit)) { - v3d->layact= 1<<bit; + for (bit = 0; bit < 32; bit++) { + if (v3d->lay & (1 << bit)) { + v3d->layact = 1 << bit; break; } } @@ -410,11 +410,11 @@ void BKE_screen_view3d_scene_sync(bScreen *sc) { /* are there cameras in the views that are not in the scene? */ ScrArea *sa; - for (sa= sc->areabase.first; sa; sa= sa->next) { + for (sa = sc->areabase.first; sa; sa = sa->next) { SpaceLink *sl; - for (sl= sa->spacedata.first; sl; sl= sl->next) { - if (sl->spacetype==SPACE_VIEW3D) { - View3D *v3d= (View3D*) sl; + for (sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *) sl; BKE_screen_view3d_sync(v3d, sc->scene); } } @@ -428,14 +428,14 @@ void BKE_screen_view3d_main_sync(ListBase *screen_lb, Scene *scene) SpaceLink *sl; /* from scene copy to the other views */ - for (sc=screen_lb->first; sc; sc=sc->id.next) { - if (sc->scene!=scene) + for (sc = screen_lb->first; sc; sc = sc->id.next) { + if (sc->scene != scene) continue; - for (sa=sc->areabase.first; sa; sa=sa->next) - for (sl=sa->spacedata.first; sl; sl=sl->next) - if (sl->spacetype==SPACE_VIEW3D) - BKE_screen_view3d_sync((View3D*)sl, scene); + for (sa = sc->areabase.first; sa; sa = sa->next) + for (sl = sa->spacedata.first; sl; sl = sl->next) + if (sl->spacetype == SPACE_VIEW3D) + BKE_screen_view3d_sync((View3D *)sl, scene); } } @@ -449,7 +449,7 @@ void BKE_screen_view3d_main_sync(ListBase *screen_lb, Scene *scene) */ float BKE_screen_view3d_zoom_to_fac(float camzoom) { - return powf(((float)M_SQRT2 + camzoom/50.0f), 2.0f) / 4.0f; + return powf(((float)M_SQRT2 + camzoom / 50.0f), 2.0f) / 4.0f; } float BKE_screen_view3d_zoom_from_fac(float zoomfac) diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index 5983beac4ef..9358b786472 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -58,27 +58,27 @@ #include "RNA_access.h" /* **** XXX **** */ -static void error(const char *UNUSED(error), ...) {} +static void error(const char *UNUSED(error), ...) { +} -#define INT 96 -#define FLO 128 +#define INT 96 +#define FLO 128 /* **** XXX **** */ /* Glow effect */ enum { - GlowR=0, - GlowG=1, - GlowB=2, - GlowA=3 + GlowR = 0, + GlowG = 1, + GlowB = 2, + GlowA = 3 }; -static struct ImBuf * prepare_effect_imbufs( - SeqRenderData context, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) -{ - struct ImBuf * out; +static struct ImBuf *prepare_effect_imbufs( + SeqRenderData context, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3){ + struct ImBuf *out; int x = context.rectx; int y = context.recty; @@ -87,8 +87,9 @@ static struct ImBuf * prepare_effect_imbufs( out = IMB_allocImBuf((short)x, (short)y, 32, IB_rect); } else if ((ibuf1 && ibuf1->rect_float) || - (ibuf2 && ibuf2->rect_float) || - (ibuf3 && ibuf3->rect_float)) { + (ibuf2 && ibuf2->rect_float) || + (ibuf3 && ibuf3->rect_float)) + { /* if any inputs are rectfloat, output is float too */ out = IMB_allocImBuf((short)x, (short)y, 32, IB_rectfloat); @@ -127,15 +128,15 @@ static struct ImBuf * prepare_effect_imbufs( static void open_plugin_seq(PluginSeq *pis, const char *seqname) { int (*version)(void); - void* (*alloc_private)(void); + void * (*alloc_private)(void); char *cp; /* to be sure: (is tested for) */ - pis->doit= NULL; - pis->pname= NULL; - pis->varstr= NULL; - pis->cfra= NULL; - pis->version= 0; + pis->doit = NULL; + pis->pname = NULL; + pis->varstr = NULL; + pis->cfra = NULL; + pis->version = 0; pis->instance_private_data = NULL; /* clear the error list */ @@ -145,55 +146,54 @@ static void open_plugin_seq(PluginSeq *pis, const char *seqname) /* pis->handle= 0; */ /* open the needed object */ - pis->handle= BLI_dynlib_open(pis->name); + pis->handle = BLI_dynlib_open(pis->name); if (test_dlerr(pis->name, pis->name)) return; if (pis->handle != NULL) { /* find the address of the version function */ - version= (int (*)(void))BLI_dynlib_find_symbol(pis->handle, "plugin_seq_getversion"); + version = (int (*)(void))BLI_dynlib_find_symbol(pis->handle, "plugin_seq_getversion"); if (test_dlerr(pis->name, "plugin_seq_getversion")) return; if (version != NULL) { - pis->version= version(); + pis->version = version(); if (pis->version >= 2 && pis->version <= 6) { int (*info_func)(PluginInfo *); - PluginInfo *info= (PluginInfo*) MEM_mallocN(sizeof(PluginInfo), "plugin_info"); + PluginInfo *info = (PluginInfo *) MEM_mallocN(sizeof(PluginInfo), "plugin_info"); - info_func= (int (*)(PluginInfo *))BLI_dynlib_find_symbol(pis->handle, "plugin_getinfo"); + info_func = (int (*)(PluginInfo *))BLI_dynlib_find_symbol(pis->handle, "plugin_getinfo"); if (info_func == NULL) error("No info func"); else { info_func(info); - pis->pname= info->name; - pis->vars= info->nvars; - pis->cfra= info->cfra; + pis->pname = info->name; + pis->vars = info->nvars; + pis->cfra = info->cfra; - pis->varstr= info->varstr; + pis->varstr = info->varstr; - pis->doit= (void(*)(void))info->seq_doit; + pis->doit = (void (*)(void))info->seq_doit; if (info->init) info->init(); } MEM_freeN(info); - cp= BLI_dynlib_find_symbol(pis->handle, "seqname"); + cp = BLI_dynlib_find_symbol(pis->handle, "seqname"); if (cp) BLI_strncpy(cp, seqname, SEQ_NAME_MAXSTR); } else { - printf ("Plugin returned unrecognized version number\n"); + printf("Plugin returned unrecognized version number\n"); return; } } - alloc_private = (void* (*)(void))BLI_dynlib_find_symbol( - pis->handle, "plugin_seq_alloc_private_data"); + alloc_private = (void * (*)(void))BLI_dynlib_find_symbol( + pis->handle, "plugin_seq_alloc_private_data"); if (alloc_private) { pis->instance_private_data = alloc_private(); } - pis->current_private_data = (void**) - BLI_dynlib_find_symbol( - pis->handle, "plugin_private_data"); + pis->current_private_data = (void **) + BLI_dynlib_find_symbol(pis->handle, "plugin_private_data"); } } @@ -203,25 +203,25 @@ static PluginSeq *add_plugin_seq(const char *str, const char *seqname) VarStruct *varstr; int a; - pis= MEM_callocN(sizeof(PluginSeq), "PluginSeq"); + pis = MEM_callocN(sizeof(PluginSeq), "PluginSeq"); BLI_strncpy(pis->name, str, FILE_MAX); open_plugin_seq(pis, seqname); - if (pis->doit==NULL) { - if (pis->handle==NULL) error("no plugin: %s", str); + if (pis->doit == NULL) { + if (pis->handle == NULL) error("no plugin: %s", str); else error("in plugin: %s", str); MEM_freeN(pis); return NULL; } /* default values */ - varstr= pis->varstr; - for (a=0; a<pis->vars; a++, varstr++) { - if ( (varstr->type & FLO)==FLO) - pis->data[a]= varstr->def; - else if ( (varstr->type & INT)==INT) - *((int *)(pis->data+a))= (int) varstr->def; + varstr = pis->varstr; + for (a = 0; a < pis->vars; a++, varstr++) { + if ( (varstr->type & FLO) == FLO) + pis->data[a] = varstr->def; + else if ( (varstr->type & INT) == INT) + *((int *)(pis->data + a)) = (int) varstr->def; } return pis; @@ -229,7 +229,7 @@ static PluginSeq *add_plugin_seq(const char *str, const char *seqname) static void free_plugin_seq(PluginSeq *pis) { - if (pis==NULL) return; + if (pis == NULL) return; /* no BLI_dynlib_close: same plugin can be opened multiple times with 1 handle */ @@ -237,7 +237,7 @@ static void free_plugin_seq(PluginSeq *pis) void (*free_private)(void *); free_private = (void (*)(void *))BLI_dynlib_find_symbol( - pis->handle, "plugin_seq_free_private_data"); + pis->handle, "plugin_seq_free_private_data"); if (free_private) { free_private(pis->instance_private_data); } @@ -246,9 +246,9 @@ static void free_plugin_seq(PluginSeq *pis) MEM_freeN(pis); } -static void init_plugin(Sequence * seq, const char * fname) +static void init_plugin(Sequence *seq, const char *fname) { - seq->plugin= (PluginSeq *)add_plugin_seq(fname, seq->name+2); + seq->plugin = (PluginSeq *)add_plugin_seq(fname, seq->name + 2); } /* @@ -259,34 +259,34 @@ static int num_inputs_plugin(void) return 1; } -static void load_plugin(Sequence * seq) +static void load_plugin(Sequence *seq) { if (seq) { - open_plugin_seq(seq->plugin, seq->name+2); + open_plugin_seq(seq->plugin, seq->name + 2); } } -static void copy_plugin(Sequence * dst, Sequence * src) +static void copy_plugin(Sequence *dst, Sequence *src) { if (src->plugin) { - dst->plugin= MEM_dupallocN(src->plugin); - open_plugin_seq(dst->plugin, dst->name+2); + dst->plugin = MEM_dupallocN(src->plugin); + open_plugin_seq(dst->plugin, dst->name + 2); } } -static ImBuf * IMB_cast_away_list(ImBuf * i) +static ImBuf *IMB_cast_away_list(ImBuf *i) { if (!i) { return NULL; } - return (ImBuf*) (((void**) i) + 2); + return (ImBuf *) (((void **) i) + 2); } -static struct ImBuf * do_plugin_effect( - SeqRenderData context, Sequence *seq, float cfra, - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static struct ImBuf *do_plugin_effect( + SeqRenderData context, Sequence *seq, float cfra, + float facf0, float facf1, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { char *cp; int float_rendering; @@ -294,31 +294,30 @@ static struct ImBuf * do_plugin_effect( * old plugins) do very bad stuff * with imbuf-internals */ - struct ImBuf * out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); + struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); int x = context.rectx; int y = context.recty; if (seq->plugin && seq->plugin->doit) { if (seq->plugin->cfra) - *(seq->plugin->cfra)= cfra; + *(seq->plugin->cfra) = cfra; cp = BLI_dynlib_find_symbol( - seq->plugin->handle, "seqname"); + seq->plugin->handle, "seqname"); /* XXX: it's crappy to limit copying buffer by it's lemgth, * but assuming plugin stuff is using correct buffer size * it should be fine */ - if (cp) strncpy(cp, seq->name+2, sizeof(seq->name)-2); + if (cp) strncpy(cp, seq->name + 2, sizeof(seq->name) - 2); if (seq->plugin->current_private_data) { - *seq->plugin->current_private_data - = seq->plugin->instance_private_data; + *seq->plugin->current_private_data = seq->plugin->instance_private_data; } float_rendering = (out->rect_float != NULL); - if (seq->plugin->version<=3 && float_rendering) { + if (seq->plugin->version <= 3 && float_rendering) { use_temp_bufs = 1; if (ibuf1) { @@ -344,27 +343,27 @@ static struct ImBuf * do_plugin_effect( out->flags &= ~IB_rectfloat; } - if (seq->plugin->version<=2) { + if (seq->plugin->version <= 2) { if (ibuf1) IMB_convert_rgba_to_abgr(ibuf1); if (ibuf2) IMB_convert_rgba_to_abgr(ibuf2); if (ibuf3) IMB_convert_rgba_to_abgr(ibuf3); } - if (seq->plugin->version<=4) { + if (seq->plugin->version <= 4) { ((SeqDoit)seq->plugin->doit)( - seq->plugin->data, facf0, facf1, x, y, - IMB_cast_away_list(ibuf1), - IMB_cast_away_list(ibuf2), - IMB_cast_away_list(out), - IMB_cast_away_list(ibuf3)); + seq->plugin->data, facf0, facf1, x, y, + IMB_cast_away_list(ibuf1), + IMB_cast_away_list(ibuf2), + IMB_cast_away_list(out), + IMB_cast_away_list(ibuf3)); } else { ((SeqDoit)seq->plugin->doit)( - seq->plugin->data, facf0, facf1, x, y, - ibuf1, ibuf2, out, ibuf3); + seq->plugin->data, facf0, facf1, x, y, + ibuf1, ibuf2, out, ibuf3); } - if (seq->plugin->version<=2) { + if (seq->plugin->version <= 2) { if (!use_temp_bufs) { if (ibuf1) IMB_convert_rgba_to_abgr(ibuf1); if (ibuf2) IMB_convert_rgba_to_abgr(ibuf2); @@ -372,7 +371,7 @@ static struct ImBuf * do_plugin_effect( } IMB_convert_rgba_to_abgr(out); } - if (seq->plugin->version<=3 && float_rendering) { + if (seq->plugin->version <= 3 && float_rendering) { IMB_float_from_rect_simple(out); } @@ -386,12 +385,12 @@ static struct ImBuf * do_plugin_effect( } static int do_plugin_early_out(struct Sequence *UNUSED(seq), - float UNUSED(facf0), float UNUSED(facf1)) + float UNUSED(facf0), float UNUSED(facf1)) { return 0; } -static void free_plugin(struct Sequence * seq) +static void free_plugin(struct Sequence *seq) { free_plugin_seq(seq->plugin); seq->plugin = NULL; @@ -401,129 +400,129 @@ static void free_plugin(struct Sequence * seq) * ALPHA OVER * ********************************************************************** */ -static void init_alpha_over_or_under(Sequence * seq) +static void init_alpha_over_or_under(Sequence *seq) { - Sequence * seq1 = seq->seq1; - Sequence * seq2 = seq->seq2; + Sequence *seq1 = seq->seq1; + Sequence *seq2 = seq->seq2; - seq->seq2= seq1; - seq->seq1= seq2; + seq->seq2 = seq1; + seq->seq1 = seq2; } static void do_alphaover_effect_byte(float facf0, float facf1, int x, int y, - char * rect1, char *rect2, char *out) + char *rect1, char *rect2, char *out) { int fac2, mfac, fac, fac4; int xo, tempc; char *rt1, *rt2, *rt; - xo= x; - rt1= (char *)rect1; - rt2= (char *)rect2; - rt= (char *)out; + xo = x; + rt1 = (char *)rect1; + rt2 = (char *)rect2; + rt = (char *)out; - fac2= (int)(256.0f*facf0); - fac4= (int)(256.0f*facf1); + fac2 = (int)(256.0f * facf0); + fac4 = (int)(256.0f * facf1); while (y--) { - x= xo; + x = xo; while (x--) { /* rt = rt1 over rt2 (alpha from rt1) */ - fac= fac2; - mfac= 256 - ( (fac2*rt1[3])>>8 ); + fac = fac2; + mfac = 256 - ( (fac2 * rt1[3]) >> 8); - if (fac==0) *( (unsigned int *)rt) = *( (unsigned int *)rt2); - else if (mfac==0) *( (unsigned int *)rt) = *( (unsigned int *)rt1); + if (fac == 0) *( (unsigned int *)rt) = *( (unsigned int *)rt2); + else if (mfac == 0) *( (unsigned int *)rt) = *( (unsigned int *)rt1); else { - tempc= ( fac*rt1[0] + mfac*rt2[0])>>8; - if (tempc>255) rt[0]= 255; else rt[0]= tempc; - tempc= ( fac*rt1[1] + mfac*rt2[1])>>8; - if (tempc>255) rt[1]= 255; else rt[1]= tempc; - tempc= ( fac*rt1[2] + mfac*rt2[2])>>8; - if (tempc>255) rt[2]= 255; else rt[2]= tempc; - tempc= ( fac*rt1[3] + mfac*rt2[3])>>8; - if (tempc>255) rt[3]= 255; else rt[3]= tempc; + tempc = (fac * rt1[0] + mfac * rt2[0]) >> 8; + if (tempc > 255) rt[0] = 255; else rt[0] = tempc; + tempc = (fac * rt1[1] + mfac * rt2[1]) >> 8; + if (tempc > 255) rt[1] = 255; else rt[1] = tempc; + tempc = (fac * rt1[2] + mfac * rt2[2]) >> 8; + if (tempc > 255) rt[2] = 255; else rt[2] = tempc; + tempc = (fac * rt1[3] + mfac * rt2[3]) >> 8; + if (tempc > 255) rt[3] = 255; else rt[3] = tempc; } - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } - if (y==0) break; + if (y == 0) break; y--; - x= xo; + x = xo; while (x--) { - fac= fac4; - mfac= 256 - ( (fac4*rt1[3])>>8 ); + fac = fac4; + mfac = 256 - ( (fac4 * rt1[3]) >> 8); - if (fac==0) *( (unsigned int *)rt) = *( (unsigned int *)rt2); - else if (mfac==0) *( (unsigned int *)rt) = *( (unsigned int *)rt1); + if (fac == 0) *( (unsigned int *)rt) = *( (unsigned int *)rt2); + else if (mfac == 0) *( (unsigned int *)rt) = *( (unsigned int *)rt1); else { - tempc= ( fac*rt1[0] + mfac*rt2[0])>>8; - if (tempc>255) rt[0]= 255; else rt[0]= tempc; - tempc= ( fac*rt1[1] + mfac*rt2[1])>>8; - if (tempc>255) rt[1]= 255; else rt[1]= tempc; - tempc= ( fac*rt1[2] + mfac*rt2[2])>>8; - if (tempc>255) rt[2]= 255; else rt[2]= tempc; - tempc= ( fac*rt1[3] + mfac*rt2[3])>>8; - if (tempc>255) rt[3]= 255; else rt[3]= tempc; + tempc = (fac * rt1[0] + mfac * rt2[0]) >> 8; + if (tempc > 255) rt[0] = 255; else rt[0] = tempc; + tempc = (fac * rt1[1] + mfac * rt2[1]) >> 8; + if (tempc > 255) rt[1] = 255; else rt[1] = tempc; + tempc = (fac * rt1[2] + mfac * rt2[2]) >> 8; + if (tempc > 255) rt[2] = 255; else rt[2] = tempc; + tempc = (fac * rt1[3] + mfac * rt2[3]) >> 8; + if (tempc > 255) rt[3] = 255; else rt[3] = tempc; } - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } } } static void do_alphaover_effect_float(float facf0, float facf1, int x, int y, - float * rect1, float *rect2, float *out) + float *rect1, float *rect2, float *out) { float fac2, mfac, fac, fac4; int xo; float *rt1, *rt2, *rt; - xo= x; - rt1= rect1; - rt2= rect2; - rt= out; + xo = x; + rt1 = rect1; + rt2 = rect2; + rt = out; - fac2= facf0; - fac4= facf1; + fac2 = facf0; + fac4 = facf1; while (y--) { - x= xo; + x = xo; while (x--) { /* rt = rt1 over rt2 (alpha from rt1) */ - fac= fac2; - mfac= 1.0f - (fac2 * rt1[3]); + fac = fac2; + mfac = 1.0f - (fac2 * rt1[3]); if (fac <= 0.0f) { memcpy(rt, rt2, 4 * sizeof(float)); } - else if (mfac <=0) { + else if (mfac <= 0) { memcpy(rt, rt1, 4 * sizeof(float)); } else { - rt[0] = fac*rt1[0] + mfac*rt2[0]; - rt[1] = fac*rt1[1] + mfac*rt2[1]; - rt[2] = fac*rt1[2] + mfac*rt2[2]; - rt[3] = fac*rt1[3] + mfac*rt2[3]; + rt[0] = fac * rt1[0] + mfac * rt2[0]; + rt[1] = fac * rt1[1] + mfac * rt2[1]; + rt[2] = fac * rt1[2] + mfac * rt2[2]; + rt[3] = fac * rt1[3] + mfac * rt2[3]; } - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } - if (y==0) break; + if (y == 0) break; y--; - x= xo; + x = xo; while (x--) { - fac= fac4; - mfac= 1.0f - (fac4*rt1[3]); + fac = fac4; + mfac = 1.0f - (fac4 * rt1[3]); if (fac <= 0.0f) { memcpy(rt, rt2, 4 * sizeof(float)); @@ -532,35 +531,35 @@ static void do_alphaover_effect_float(float facf0, float facf1, int x, int y, memcpy(rt, rt1, 4 * sizeof(float)); } else { - rt[0] = fac*rt1[0] + mfac*rt2[0]; - rt[1] = fac*rt1[1] + mfac*rt2[1]; - rt[2] = fac*rt1[2] + mfac*rt2[2]; - rt[3] = fac*rt1[3] + mfac*rt2[3]; + rt[0] = fac * rt1[0] + mfac * rt2[0]; + rt[1] = fac * rt1[1] + mfac * rt2[1]; + rt[2] = fac * rt1[2] + mfac * rt2[2]; + rt[3] = fac * rt1[3] + mfac * rt2[3]; } - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } } } -static struct ImBuf * do_alphaover_effect( - SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static struct ImBuf *do_alphaover_effect( + SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), + float facf0, float facf1, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { - struct ImBuf * out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); + struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); if (out->rect_float) { do_alphaover_effect_float( - facf0, facf1, context.rectx, context.recty, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + facf0, facf1, context.rectx, context.recty, + ibuf1->rect_float, ibuf2->rect_float, + out->rect_float); } else { do_alphaover_effect_byte( - facf0, facf1, context.rectx, context.recty, - (char*) ibuf1->rect, (char*) ibuf2->rect, - (char*) out->rect); + facf0, facf1, context.rectx, context.recty, + (char *) ibuf1->rect, (char *) ibuf2->rect, + (char *) out->rect); } return out; } @@ -571,24 +570,24 @@ static struct ImBuf * do_alphaover_effect( * ********************************************************************** */ static void do_alphaunder_effect_byte( - float facf0, float facf1, int x, int y, char *rect1, - char *rect2, char *out) + float facf0, float facf1, int x, int y, char *rect1, + char *rect2, char *out) { int fac2, mfac, fac, fac4; int xo; char *rt1, *rt2, *rt; - xo= x; - rt1= rect1; - rt2= rect2; - rt= out; + xo = x; + rt1 = rect1; + rt2 = rect2; + rt = out; - fac2= (int)(256.0f*facf0); - fac4= (int)(256.0f*facf1); + fac2 = (int)(256.0f * facf0); + fac4 = (int)(256.0f * facf1); while (y--) { - x= xo; + x = xo; while (x--) { /* rt = rt1 under rt2 (alpha from rt2) */ @@ -596,68 +595,68 @@ static void do_alphaunder_effect_byte( /* this complex optimalisation is because the * 'skybuf' can be crossed in */ - if (rt2[3]==0 && fac2==256) *( (unsigned int *)rt) = *( (unsigned int *)rt1); - else if (rt2[3]==255) *( (unsigned int *)rt) = *( (unsigned int *)rt2); + if (rt2[3] == 0 && fac2 == 256) *( (unsigned int *)rt) = *( (unsigned int *)rt1); + else if (rt2[3] == 255) *( (unsigned int *)rt) = *( (unsigned int *)rt2); else { - mfac= rt2[3]; - fac= (fac2*(256-mfac))>>8; + mfac = rt2[3]; + fac = (fac2 * (256 - mfac)) >> 8; - if (fac==0) *( (unsigned int *)rt) = *( (unsigned int *)rt2); + if (fac == 0) *( (unsigned int *)rt) = *( (unsigned int *)rt2); else { - rt[0]= ( fac*rt1[0] + mfac*rt2[0])>>8; - rt[1]= ( fac*rt1[1] + mfac*rt2[1])>>8; - rt[2]= ( fac*rt1[2] + mfac*rt2[2])>>8; - rt[3]= ( fac*rt1[3] + mfac*rt2[3])>>8; + rt[0] = (fac * rt1[0] + mfac * rt2[0]) >> 8; + rt[1] = (fac * rt1[1] + mfac * rt2[1]) >> 8; + rt[2] = (fac * rt1[2] + mfac * rt2[2]) >> 8; + rt[3] = (fac * rt1[3] + mfac * rt2[3]) >> 8; } } - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } - if (y==0) break; + if (y == 0) break; y--; - x= xo; + x = xo; while (x--) { - if (rt2[3]==0 && fac4==256) *( (unsigned int *)rt) = *( (unsigned int *)rt1); - else if (rt2[3]==255) *( (unsigned int *)rt) = *( (unsigned int *)rt2); + if (rt2[3] == 0 && fac4 == 256) *( (unsigned int *)rt) = *( (unsigned int *)rt1); + else if (rt2[3] == 255) *( (unsigned int *)rt) = *( (unsigned int *)rt2); else { - mfac= rt2[3]; - fac= (fac4*(256-mfac))>>8; + mfac = rt2[3]; + fac = (fac4 * (256 - mfac)) >> 8; - if (fac==0) *( (unsigned int *)rt) = *( (unsigned int *)rt2); + if (fac == 0) *( (unsigned int *)rt) = *( (unsigned int *)rt2); else { - rt[0]= ( fac*rt1[0] + mfac*rt2[0])>>8; - rt[1]= ( fac*rt1[1] + mfac*rt2[1])>>8; - rt[2]= ( fac*rt1[2] + mfac*rt2[2])>>8; - rt[3]= ( fac*rt1[3] + mfac*rt2[3])>>8; + rt[0] = (fac * rt1[0] + mfac * rt2[0]) >> 8; + rt[1] = (fac * rt1[1] + mfac * rt2[1]) >> 8; + rt[2] = (fac * rt1[2] + mfac * rt2[2]) >> 8; + rt[3] = (fac * rt1[3] + mfac * rt2[3]) >> 8; } } - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } } } static void do_alphaunder_effect_float(float facf0, float facf1, int x, int y, - float *rect1, float *rect2, - float *out) + float *rect1, float *rect2, + float *out) { float fac2, mfac, fac, fac4; int xo; float *rt1, *rt2, *rt; - xo= x; - rt1= rect1; - rt2= rect2; - rt= out; + xo = x; + rt1 = rect1; + rt2 = rect2; + rt = out; - fac2= facf0; - fac4= facf1; + fac2 = facf0; + fac4 = facf1; while (y--) { - x= xo; + x = xo; while (x--) { /* rt = rt1 under rt2 (alpha from rt2) */ @@ -665,7 +664,7 @@ 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.0f) { + if (rt2[3] <= 0 && fac2 >= 1.0f) { memcpy(rt, rt1, 4 * sizeof(float)); } else if (rt2[3] >= 1.0f) { @@ -679,67 +678,67 @@ static void do_alphaunder_effect_float(float facf0, float facf1, int x, int y, memcpy(rt, rt2, 4 * sizeof(float)); } else { - rt[0]= fac*rt1[0] + mfac*rt2[0]; - rt[1]= fac*rt1[1] + mfac*rt2[1]; - rt[2]= fac*rt1[2] + mfac*rt2[2]; - rt[3]= fac*rt1[3] + mfac*rt2[3]; + rt[0] = fac * rt1[0] + mfac * rt2[0]; + rt[1] = fac * rt1[1] + mfac * rt2[1]; + rt[2] = fac * rt1[2] + mfac * rt2[2]; + rt[3] = fac * rt1[3] + mfac * rt2[3]; } } - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } - if (y==0) break; + if (y == 0) break; y--; - x= xo; + x = xo; while (x--) { - if (rt2[3]<=0 && fac4 >= 1.0f) { + if (rt2[3] <= 0 && fac4 >= 1.0f) { memcpy(rt, rt1, 4 * sizeof(float)); } - else if (rt2[3]>=1.0f) { + else if (rt2[3] >= 1.0f) { memcpy(rt, rt2, 4 * sizeof(float)); } else { - mfac= rt2[3]; - fac= fac4*(1.0f-mfac); + mfac = rt2[3]; + fac = fac4 * (1.0f - mfac); if (fac == 0) { memcpy(rt, rt2, 4 * sizeof(float)); } else { - rt[0]= fac * rt1[0] + mfac * rt2[0]; - rt[1]= fac * rt1[1] + mfac * rt2[1]; - rt[2]= fac * rt1[2] + mfac * rt2[2]; - rt[3]= fac * rt1[3] + mfac * rt2[3]; + rt[0] = fac * rt1[0] + mfac * rt2[0]; + rt[1] = fac * rt1[1] + mfac * rt2[1]; + rt[2] = fac * rt1[2] + mfac * rt2[2]; + rt[3] = fac * rt1[3] + mfac * rt2[3]; } } - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } } } -static struct ImBuf* do_alphaunder_effect( - SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static struct ImBuf *do_alphaunder_effect( + SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), + float facf0, float facf1, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { - struct ImBuf * out = prepare_effect_imbufs( - context, ibuf1, ibuf2, ibuf3); + struct ImBuf *out = prepare_effect_imbufs( + context, ibuf1, ibuf2, ibuf3); if (out->rect_float) { do_alphaunder_effect_float( - facf0, facf1, context.rectx, context.recty, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + facf0, facf1, context.rectx, context.recty, + ibuf1->rect_float, ibuf2->rect_float, + out->rect_float); } else { do_alphaunder_effect_byte( - facf0, facf1, context.rectx, context.recty, - (char*) ibuf1->rect, (char*) ibuf2->rect, - (char*) out->rect); + facf0, facf1, context.rectx, context.recty, + (char *) ibuf1->rect, (char *) ibuf2->rect, + (char *) out->rect); } return out; } @@ -750,95 +749,95 @@ static struct ImBuf* do_alphaunder_effect( * ********************************************************************** */ static void do_cross_effect_byte(float facf0, float facf1, int x, int y, - char *rect1, char *rect2, - char *out) + char *rect1, char *rect2, + char *out) { int fac1, fac2, fac3, fac4; int xo; char *rt1, *rt2, *rt; - xo= x; - rt1= rect1; - rt2= rect2; - rt= out; + xo = x; + rt1 = rect1; + rt2 = rect2; + rt = out; - fac2= (int)(256.0f*facf0); - fac1= 256-fac2; - fac4= (int)(256.0f*facf1); - fac3= 256-fac4; + fac2 = (int)(256.0f * facf0); + fac1 = 256 - fac2; + fac4 = (int)(256.0f * facf1); + fac3 = 256 - fac4; while (y--) { - x= xo; + x = xo; while (x--) { - rt[0]= (fac1*rt1[0] + fac2*rt2[0])>>8; - rt[1]= (fac1*rt1[1] + fac2*rt2[1])>>8; - rt[2]= (fac1*rt1[2] + fac2*rt2[2])>>8; - rt[3]= (fac1*rt1[3] + fac2*rt2[3])>>8; + rt[0] = (fac1 * rt1[0] + fac2 * rt2[0]) >> 8; + rt[1] = (fac1 * rt1[1] + fac2 * rt2[1]) >> 8; + rt[2] = (fac1 * rt1[2] + fac2 * rt2[2]) >> 8; + rt[3] = (fac1 * rt1[3] + fac2 * rt2[3]) >> 8; - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } - if (y==0) break; + if (y == 0) break; y--; - x= xo; + x = xo; while (x--) { - rt[0]= (fac3*rt1[0] + fac4*rt2[0])>>8; - rt[1]= (fac3*rt1[1] + fac4*rt2[1])>>8; - rt[2]= (fac3*rt1[2] + fac4*rt2[2])>>8; - rt[3]= (fac3*rt1[3] + fac4*rt2[3])>>8; + rt[0] = (fac3 * rt1[0] + fac4 * rt2[0]) >> 8; + rt[1] = (fac3 * rt1[1] + fac4 * rt2[1]) >> 8; + rt[2] = (fac3 * rt1[2] + fac4 * rt2[2]) >> 8; + rt[3] = (fac3 * rt1[3] + fac4 * rt2[3]) >> 8; - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } } } static void do_cross_effect_float(float facf0, float facf1, int x, int y, - float *rect1, float *rect2, float *out) + float *rect1, float *rect2, float *out) { float fac1, fac2, fac3, fac4; int xo; float *rt1, *rt2, *rt; - xo= x; - rt1= rect1; - rt2= rect2; - rt= out; + xo = x; + rt1 = rect1; + rt2 = rect2; + rt = out; - fac2= facf0; - fac1= 1.0f - fac2; - fac4= facf1; - fac3= 1.0f - fac4; + fac2 = facf0; + fac1 = 1.0f - fac2; + fac4 = facf1; + fac3 = 1.0f - fac4; while (y--) { - x= xo; + x = xo; while (x--) { - rt[0]= fac1*rt1[0] + fac2*rt2[0]; - rt[1]= fac1*rt1[1] + fac2*rt2[1]; - rt[2]= fac1*rt1[2] + fac2*rt2[2]; - rt[3]= fac1*rt1[3] + fac2*rt2[3]; + rt[0] = fac1 * rt1[0] + fac2 * rt2[0]; + rt[1] = fac1 * rt1[1] + fac2 * rt2[1]; + rt[2] = fac1 * rt1[2] + fac2 * rt2[2]; + rt[3] = fac1 * rt1[3] + fac2 * rt2[3]; - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } - if (y==0) break; + if (y == 0) break; y--; - x= xo; + x = xo; while (x--) { - rt[0]= fac3*rt1[0] + fac4*rt2[0]; - rt[1]= fac3*rt1[1] + fac4*rt2[1]; - rt[2]= fac3*rt1[2] + fac4*rt2[2]; - rt[3]= fac3*rt1[3] + fac4*rt2[3]; + rt[0] = fac3 * rt1[0] + fac4 * rt2[0]; + rt[1] = fac3 * rt1[1] + fac4 * rt2[1]; + rt[2] = fac3 * rt1[2] + fac4 * rt2[2]; + rt[3] = fac3 * rt1[3] + fac4 * rt2[3]; - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } } @@ -846,26 +845,26 @@ static void do_cross_effect_float(float facf0, float facf1, int x, int y, /* careful: also used by speed effect! */ -static struct ImBuf* do_cross_effect( - SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static struct ImBuf *do_cross_effect( + SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), + float facf0, float facf1, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { - struct ImBuf * out = prepare_effect_imbufs( - context, ibuf1, ibuf2, ibuf3); + struct ImBuf *out = prepare_effect_imbufs( + context, ibuf1, ibuf2, ibuf3); if (out->rect_float) { do_cross_effect_float( - facf0, facf1, context.rectx, context.recty, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + facf0, facf1, context.rectx, context.recty, + ibuf1->rect_float, ibuf2->rect_float, + out->rect_float); } else { do_cross_effect_byte( - facf0, facf1, context.rectx, context.recty, - (char*) ibuf1->rect, (char*) ibuf2->rect, - (char*) out->rect); + facf0, facf1, context.rectx, context.recty, + (char *) ibuf1->rect, (char *) ibuf2->rect, + (char *) out->rect); } return out; } @@ -906,9 +905,9 @@ static void makeGammaTables(float gamma) for (i = 0; i < RE_GAMMA_TABLE_SIZE; i++) { color_domain_table[i] = i * color_step; gamma_range_table[i] = pow(color_domain_table[i], - valid_gamma); + valid_gamma); inv_gamma_range_table[i] = pow(color_domain_table[i], - valid_inv_gamma); + valid_inv_gamma); } /* The end of the table should match 1.0 carefully. In order to avoid */ @@ -921,11 +920,11 @@ static void makeGammaTables(float gamma) /* To speed up calculations, we make these calc factor tables. They are */ /* multiplication factors used in scaling the interpolation. */ - for (i = 0; i < RE_GAMMA_TABLE_SIZE; i++ ) { - gamfactor_table[i] = inv_color_step - * (gamma_range_table[i + 1] - gamma_range_table[i]); - inv_gamfactor_table[i] = inv_color_step - * (inv_gamma_range_table[i + 1] - inv_gamma_range_table[i]); + for (i = 0; i < RE_GAMMA_TABLE_SIZE; i++) { + gamfactor_table[i] = inv_color_step * + (gamma_range_table[i + 1] - gamma_range_table[i]); + inv_gamfactor_table[i] = inv_color_step * + (inv_gamma_range_table[i + 1] - inv_gamma_range_table[i]); } } /* end of void makeGammaTables(float gamma) */ @@ -942,9 +941,9 @@ static float gammaCorrect(float c) /* may help solve that, by exchanging LUT size for the interpolation. */ /* Negative colors are explicitly handled. */ if (i < 0) res = -pow(abs(c), valid_gamma); - else if (i >= RE_GAMMA_TABLE_SIZE ) res = pow(c, valid_gamma); + else if (i >= RE_GAMMA_TABLE_SIZE) res = pow(c, valid_gamma); else res = gamma_range_table[i] + - ( (c - color_domain_table[i]) * gamfactor_table[i]); + ( (c - color_domain_table[i]) * gamfactor_table[i]); return res; } /* end of float gammaCorrect(float col) */ @@ -956,12 +955,12 @@ static float invGammaCorrect(float col) int i; float res = 0.0; - i = floor(col*inv_color_step); + i = floor(col * inv_color_step); /* Negative colors are explicitly handled. */ if (i < 0) res = -pow(abs(col), valid_inv_gamma); else if (i >= RE_GAMMA_TABLE_SIZE) res = pow(col, valid_inv_gamma); else res = inv_gamma_range_table[i] + - ( (col - color_domain_table[i]) * inv_gamfactor_table[i]); + ( (col - color_domain_table[i]) * inv_gamfactor_table[i]); return res; } /* end of float invGammaCorrect(float col) */ @@ -969,26 +968,26 @@ static float invGammaCorrect(float col) static void gamtabs(float gamma) { - float val, igamma= 1.0f/gamma; + float val, igamma = 1.0f / gamma; int a; /* gamtab: in short, out short */ - for (a=0; a<65536; a++) { - val= a; - val/= 65535.0f; + for (a = 0; a < 65536; a++) { + val = a; + val /= 65535.0f; - if (gamma==2.0f) val= sqrt(val); - else if (gamma!=1.0f) val= pow(val, igamma); + if (gamma == 2.0f) val = sqrt(val); + else if (gamma != 1.0f) val = pow(val, igamma); - gamtab[a]= (65535.99f*val); + gamtab[a] = (65535.99f * val); } /* inverse gamtab1 : in byte, out short */ - for (a=1; a<=256; a++) { - if (gamma==2.0f) igamtab1[a-1]= a*a-1; - else if (gamma==1.0f) igamtab1[a-1]= 256*a-1; + for (a = 1; a <= 256; a++) { + 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.0f; - igamtab1[a - 1]= (65535.0 * pow(val, gamma)) - 1; + val = a / 256.0f; + igamtab1[a - 1] = (65535.0 * pow(val, gamma)) - 1; } } @@ -1003,139 +1002,137 @@ static void build_gammatabs(void) } } -static void init_gammacross(Sequence * UNUSED(seq)) +static void init_gammacross(Sequence *UNUSED(seq)) { } -static void load_gammacross(Sequence * UNUSED(seq)) +static void load_gammacross(Sequence *UNUSED(seq)) { } -static void free_gammacross(Sequence * UNUSED(seq)) +static void free_gammacross(Sequence *UNUSED(seq)) { } static void do_gammacross_effect_byte(float facf0, float UNUSED(facf1), - int x, int y, - unsigned char *rect1, - unsigned char *rect2, - unsigned char *out) + int x, int y, + unsigned char *rect1, + unsigned char *rect2, + unsigned char *out) { int fac1, fac2, col; int xo; unsigned char *rt1, *rt2, *rt; - xo= x; - rt1= (unsigned char *)rect1; - rt2= (unsigned char *)rect2; - rt= (unsigned char *)out; + xo = x; + rt1 = (unsigned char *)rect1; + rt2 = (unsigned char *)rect2; + rt = (unsigned char *)out; - fac2= (int)(256.0f*facf0); - fac1= 256-fac2; + fac2 = (int)(256.0f * facf0); + fac1 = 256 - fac2; while (y--) { - x= xo; + x = xo; while (x--) { - col= (fac1*igamtab1[rt1[0]] + fac2*igamtab1[rt2[0]])>>8; - if (col>65535) rt[0]= 255; else rt[0]= ( (char *)(gamtab+col))[MOST_SIG_BYTE]; - col=(fac1*igamtab1[rt1[1]] + fac2*igamtab1[rt2[1]])>>8; - if (col>65535) rt[1]= 255; else rt[1]= ( (char *)(gamtab+col))[MOST_SIG_BYTE]; - col= (fac1*igamtab1[rt1[2]] + fac2*igamtab1[rt2[2]])>>8; - if (col>65535) rt[2]= 255; else rt[2]= ( (char *)(gamtab+col))[MOST_SIG_BYTE]; - col= (fac1*igamtab1[rt1[3]] + fac2*igamtab1[rt2[3]])>>8; - if (col>65535) rt[3]= 255; else rt[3]= ( (char *)(gamtab+col))[MOST_SIG_BYTE]; + col = (fac1 * igamtab1[rt1[0]] + fac2 * igamtab1[rt2[0]]) >> 8; + if (col > 65535) rt[0] = 255; else rt[0] = ( (char *)(gamtab + col))[MOST_SIG_BYTE]; + col = (fac1 * igamtab1[rt1[1]] + fac2 * igamtab1[rt2[1]]) >> 8; + if (col > 65535) rt[1] = 255; else rt[1] = ( (char *)(gamtab + col))[MOST_SIG_BYTE]; + col = (fac1 * igamtab1[rt1[2]] + fac2 * igamtab1[rt2[2]]) >> 8; + if (col > 65535) rt[2] = 255; else rt[2] = ( (char *)(gamtab + col))[MOST_SIG_BYTE]; + col = (fac1 * igamtab1[rt1[3]] + fac2 * igamtab1[rt2[3]]) >> 8; + if (col > 65535) rt[3] = 255; else rt[3] = ( (char *)(gamtab + col))[MOST_SIG_BYTE]; - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } - if (y==0) break; + if (y == 0) break; y--; - x= xo; + x = xo; while (x--) { - col= (fac1*igamtab1[rt1[0]] + fac2*igamtab1[rt2[0]])>>8; - if (col>65535) rt[0]= 255; else rt[0]= ( (char *)(gamtab+col))[MOST_SIG_BYTE]; - col= (fac1*igamtab1[rt1[1]] + fac2*igamtab1[rt2[1]])>>8; - if (col>65535) rt[1]= 255; else rt[1]= ( (char *)(gamtab+col))[MOST_SIG_BYTE]; - col= (fac1*igamtab1[rt1[2]] + fac2*igamtab1[rt2[2]])>>8; - if (col>65535) rt[2]= 255; else rt[2]= ( (char *)(gamtab+col))[MOST_SIG_BYTE]; - col= (fac1*igamtab1[rt1[3]] + fac2*igamtab1[rt2[3]])>>8; - if (col>65535) rt[3]= 255; else rt[3]= ( (char *)(gamtab+col))[MOST_SIG_BYTE]; + col = (fac1 * igamtab1[rt1[0]] + fac2 * igamtab1[rt2[0]]) >> 8; + if (col > 65535) rt[0] = 255; else rt[0] = ( (char *)(gamtab + col))[MOST_SIG_BYTE]; + col = (fac1 * igamtab1[rt1[1]] + fac2 * igamtab1[rt2[1]]) >> 8; + if (col > 65535) rt[1] = 255; else rt[1] = ( (char *)(gamtab + col))[MOST_SIG_BYTE]; + col = (fac1 * igamtab1[rt1[2]] + fac2 * igamtab1[rt2[2]]) >> 8; + if (col > 65535) rt[2] = 255; else rt[2] = ( (char *)(gamtab + col))[MOST_SIG_BYTE]; + col = (fac1 * igamtab1[rt1[3]] + fac2 * igamtab1[rt2[3]]) >> 8; + if (col > 65535) rt[3] = 255; else rt[3] = ( (char *)(gamtab + col))[MOST_SIG_BYTE]; - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } } } static void do_gammacross_effect_float(float facf0, float UNUSED(facf1), - int x, int y, - float *rect1, float *rect2, - float *out) + int x, int y, + float *rect1, float *rect2, + float *out) { float fac1, fac2; int xo; float *rt1, *rt2, *rt; - xo= x; - rt1= rect1; - rt2= rect2; - rt= out; + xo = x; + rt1 = rect1; + rt2 = rect2; + rt = out; - fac2= facf0; - fac1= 1.0f - fac2; + fac2 = facf0; + fac1 = 1.0f - fac2; while (y--) { - x= xo * 4; + x = xo * 4; while (x--) { - *rt= gammaCorrect( - fac1 * invGammaCorrect(*rt1) - + fac2 * invGammaCorrect(*rt2)); + *rt = gammaCorrect( + fac1 * invGammaCorrect(*rt1) + fac2 * invGammaCorrect(*rt2)); rt1++; rt2++; rt++; } - if (y==0) break; + if (y == 0) break; y--; - x= xo * 4; + x = xo * 4; while (x--) { - *rt= gammaCorrect( - fac1*invGammaCorrect(*rt1) - + fac2*invGammaCorrect(*rt2)); + *rt = gammaCorrect( + fac1 * invGammaCorrect(*rt1) + fac2 * invGammaCorrect(*rt2)); rt1++; rt2++; rt++; } } } -static struct ImBuf * do_gammacross_effect( - SeqRenderData context, - Sequence *UNUSED(seq), float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static struct ImBuf *do_gammacross_effect( + SeqRenderData context, + Sequence *UNUSED(seq), float UNUSED(cfra), + float facf0, float facf1, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { - struct ImBuf * out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); + struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); build_gammatabs(); if (out->rect_float) { do_gammacross_effect_float( - facf0, facf1, context.rectx, context.recty, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + facf0, facf1, context.rectx, context.recty, + ibuf1->rect_float, ibuf2->rect_float, + out->rect_float); } else { do_gammacross_effect_byte( - facf0, facf1, context.rectx, context.recty, - (unsigned char*) ibuf1->rect, (unsigned char*) ibuf2->rect, - (unsigned char*) out->rect); + facf0, facf1, context.rectx, context.recty, + (unsigned char *) ibuf1->rect, (unsigned char *) ibuf2->rect, + (unsigned char *) out->rect); } return out; } @@ -1146,86 +1143,86 @@ static struct ImBuf * do_gammacross_effect( * ********************************************************************** */ static void do_add_effect_byte(float facf0, float facf1, int x, int y, - unsigned char *rect1, unsigned char *rect2, - unsigned char *out) + unsigned char *rect1, unsigned char *rect2, + unsigned char *out) { int col, xo, fac1, fac3; char *rt1, *rt2, *rt; - xo= x; - rt1= (char *)rect1; - rt2= (char *)rect2; - rt= (char *)out; + xo = x; + rt1 = (char *)rect1; + rt2 = (char *)rect2; + rt = (char *)out; - fac1= (int)(256.0f*facf0); - fac3= (int)(256.0f*facf1); + fac1 = (int)(256.0f * facf0); + fac3 = (int)(256.0f * facf1); while (y--) { - x= xo; + x = xo; while (x--) { - col= rt1[0]+ ((fac1*rt2[0])>>8); - if (col>255) rt[0]= 255; else rt[0]= col; - col= rt1[1]+ ((fac1*rt2[1])>>8); - if (col>255) rt[1]= 255; else rt[1]= col; - col= rt1[2]+ ((fac1*rt2[2])>>8); - if (col>255) rt[2]= 255; else rt[2]= col; - col= rt1[3]+ ((fac1*rt2[3])>>8); - if (col>255) rt[3]= 255; else rt[3]= col; + col = rt1[0] + ((fac1 * rt2[0]) >> 8); + if (col > 255) rt[0] = 255; else rt[0] = col; + col = rt1[1] + ((fac1 * rt2[1]) >> 8); + if (col > 255) rt[1] = 255; else rt[1] = col; + col = rt1[2] + ((fac1 * rt2[2]) >> 8); + if (col > 255) rt[2] = 255; else rt[2] = col; + col = rt1[3] + ((fac1 * rt2[3]) >> 8); + if (col > 255) rt[3] = 255; else rt[3] = col; - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } - if (y==0) break; + if (y == 0) break; y--; - x= xo; + x = xo; while (x--) { - col= rt1[0]+ ((fac3*rt2[0])>>8); - if (col>255) rt[0]= 255; else rt[0]= col; - col= rt1[1]+ ((fac3*rt2[1])>>8); - if (col>255) rt[1]= 255; else rt[1]= col; - col= rt1[2]+ ((fac3*rt2[2])>>8); - if (col>255) rt[2]= 255; else rt[2]= col; - col= rt1[3]+ ((fac3*rt2[3])>>8); - if (col>255) rt[3]= 255; else rt[3]= col; + col = rt1[0] + ((fac3 * rt2[0]) >> 8); + if (col > 255) rt[0] = 255; else rt[0] = col; + col = rt1[1] + ((fac3 * rt2[1]) >> 8); + if (col > 255) rt[1] = 255; else rt[1] = col; + col = rt1[2] + ((fac3 * rt2[2]) >> 8); + if (col > 255) rt[2] = 255; else rt[2] = col; + col = rt1[3] + ((fac3 * rt2[3]) >> 8); + if (col > 255) rt[3] = 255; else rt[3] = col; - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } } } static void do_add_effect_float(float facf0, float facf1, int x, int y, - float *rect1, float *rect2, - float *out) + float *rect1, float *rect2, + float *out) { int xo; float fac1, fac3; float *rt1, *rt2, *rt; - xo= x; - rt1= rect1; - rt2= rect2; - rt= out; + xo = x; + rt1 = rect1; + rt2 = rect2; + rt = out; - fac1= facf0; - fac3= facf1; + fac1 = facf0; + fac3 = facf1; while (y--) { - x= xo * 4; + x = xo * 4; while (x--) { *rt = *rt1 + fac1 * (*rt2); rt1++; rt2++; rt++; } - if (y==0) break; + if (y == 0) break; y--; - x= xo * 4; + x = xo * 4; while (x--) { *rt = *rt1 + fac3 * (*rt2); @@ -1234,25 +1231,24 @@ static void do_add_effect_float(float facf0, float facf1, int x, int y, } } -static struct ImBuf * do_add_effect(SeqRenderData context, - Sequence *UNUSED(seq), float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) -{ - struct ImBuf * out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); +static struct ImBuf *do_add_effect(SeqRenderData context, + Sequence *UNUSED(seq), float UNUSED(cfra), + float facf0, float facf1, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3){ + struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); if (out->rect_float) { do_add_effect_float( - facf0, facf1, context.rectx, context.recty, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + facf0, facf1, context.rectx, context.recty, + ibuf1->rect_float, ibuf2->rect_float, + out->rect_float); } else { do_add_effect_byte( - facf0, facf1, context.rectx, context.recty, - (unsigned char*) ibuf1->rect, (unsigned char*) ibuf2->rect, - (unsigned char*) out->rect); + facf0, facf1, context.rectx, context.recty, + (unsigned char *) ibuf1->rect, (unsigned char *) ibuf2->rect, + (unsigned char *) out->rect); } return out; } @@ -1263,86 +1259,86 @@ static struct ImBuf * do_add_effect(SeqRenderData context, * ********************************************************************** */ static void do_sub_effect_byte(float facf0, float facf1, - int x, int y, - char *rect1, char *rect2, char *out) + int x, int y, + char *rect1, char *rect2, char *out) { int col, xo, fac1, fac3; char *rt1, *rt2, *rt; - xo= x; - rt1= (char *)rect1; - rt2= (char *)rect2; - rt= (char *)out; + xo = x; + rt1 = (char *)rect1; + rt2 = (char *)rect2; + rt = (char *)out; - fac1= (int)(256.0f*facf0); - fac3= (int)(256.0f*facf1); + fac1 = (int)(256.0f * facf0); + fac3 = (int)(256.0f * facf1); while (y--) { - x= xo; + x = xo; while (x--) { - col= rt1[0]- ((fac1*rt2[0])>>8); - if (col<0) rt[0]= 0; else rt[0]= col; - col= rt1[1]- ((fac1*rt2[1])>>8); - if (col<0) rt[1]= 0; else rt[1]= col; - col= rt1[2]- ((fac1*rt2[2])>>8); - if (col<0) rt[2]= 0; else rt[2]= col; - col= rt1[3]- ((fac1*rt2[3])>>8); - if (col<0) rt[3]= 0; else rt[3]= col; + col = rt1[0] - ((fac1 * rt2[0]) >> 8); + if (col < 0) rt[0] = 0; else rt[0] = col; + col = rt1[1] - ((fac1 * rt2[1]) >> 8); + if (col < 0) rt[1] = 0; else rt[1] = col; + col = rt1[2] - ((fac1 * rt2[2]) >> 8); + if (col < 0) rt[2] = 0; else rt[2] = col; + col = rt1[3] - ((fac1 * rt2[3]) >> 8); + if (col < 0) rt[3] = 0; else rt[3] = col; - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } - if (y==0) break; + if (y == 0) break; y--; - x= xo; + x = xo; while (x--) { - col= rt1[0]- ((fac3*rt2[0])>>8); - if (col<0) rt[0]= 0; else rt[0]= col; - col= rt1[1]- ((fac3*rt2[1])>>8); - if (col<0) rt[1]= 0; else rt[1]= col; - col= rt1[2]- ((fac3*rt2[2])>>8); - if (col<0) rt[2]= 0; else rt[2]= col; - col= rt1[3]- ((fac3*rt2[3])>>8); - if (col<0) rt[3]= 0; else rt[3]= col; + col = rt1[0] - ((fac3 * rt2[0]) >> 8); + if (col < 0) rt[0] = 0; else rt[0] = col; + col = rt1[1] - ((fac3 * rt2[1]) >> 8); + if (col < 0) rt[1] = 0; else rt[1] = col; + col = rt1[2] - ((fac3 * rt2[2]) >> 8); + if (col < 0) rt[2] = 0; else rt[2] = col; + col = rt1[3] - ((fac3 * rt2[3]) >> 8); + if (col < 0) rt[3] = 0; else rt[3] = col; - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } } } static void do_sub_effect_float(float facf0, float facf1, int x, int y, - float *rect1, float *rect2, - float *out) + float *rect1, float *rect2, + float *out) { int xo; float fac1, fac3; float *rt1, *rt2, *rt; - xo= x; - rt1= rect1; - rt2= rect2; - rt= out; + xo = x; + rt1 = rect1; + rt2 = rect2; + rt = out; - fac1= facf0; - fac3= facf1; + fac1 = facf0; + fac3 = facf1; while (y--) { - x= xo * 4; + x = xo * 4; while (x--) { *rt = *rt1 - fac1 * (*rt2); rt1++; rt2++; rt++; } - if (y==0) break; + if (y == 0) break; y--; - x= xo * 4; + x = xo * 4; while (x--) { *rt = *rt1 - fac3 * (*rt2); @@ -1351,25 +1347,24 @@ static void do_sub_effect_float(float facf0, float facf1, int x, int y, } } -static struct ImBuf * do_sub_effect( - SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) -{ - struct ImBuf * out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); +static struct ImBuf *do_sub_effect( + SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), + float facf0, float facf1, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3){ + struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); if (out->rect_float) { do_sub_effect_float( - facf0, facf1, context.rectx, context.recty, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + facf0, facf1, context.rectx, context.recty, + ibuf1->rect_float, ibuf2->rect_float, + out->rect_float); } else { do_sub_effect_byte( - facf0, facf1, context.rectx, context.recty, - (char*) ibuf1->rect, (char*) ibuf2->rect, - (char*) out->rect); + facf0, facf1, context.rectx, context.recty, + (char *) ibuf1->rect, (char *) ibuf2->rect, + (char *) out->rect); } return out; } @@ -1379,88 +1374,88 @@ static struct ImBuf * do_sub_effect( * ********************************************************************** */ /* Must be > 0 or add precopy, etc to the function */ -#define XOFF 8 -#define YOFF 8 +#define XOFF 8 +#define YOFF 8 static void do_drop_effect_byte(float facf0, float facf1, int x, int y, - char *rect2i, char *rect1i, - char *outi) + char *rect2i, char *rect1i, + char *outi) { int height, width, temp, fac, fac1, fac2; char *rt1, *rt2, *out; - int field= 1; + int field = 1; - width= x; - height= y; + width = x; + height = y; - fac1= (int)(70.0f*facf0); - fac2= (int)(70.0f*facf1); + fac1 = (int)(70.0f * facf0); + fac2 = (int)(70.0f * facf1); - rt2= (char*) (rect2i + YOFF*width); - rt1= (char*) rect1i; - out= (char*) outi; - for (y=0; y<height-YOFF; y++) { - if (field) fac= fac1; - else fac= fac2; - field= !field; + rt2 = (char *) (rect2i + YOFF * width); + rt1 = (char *) rect1i; + out = (char *) outi; + for (y = 0; y < height - YOFF; y++) { + if (field) fac = fac1; + else fac = fac2; + field = !field; - memcpy(out, rt1, sizeof(int)*XOFF); - rt1+= XOFF*4; - out+= XOFF*4; + memcpy(out, rt1, sizeof(int) * XOFF); + rt1 += XOFF * 4; + out += XOFF * 4; - for (x=XOFF; x<width; x++) { - temp= ((fac*rt2[3])>>8); + for (x = XOFF; x < width; x++) { + temp = ((fac * rt2[3]) >> 8); - *(out++)= MAX2(0, *rt1 - temp); rt1++; - *(out++)= MAX2(0, *rt1 - temp); rt1++; - *(out++)= MAX2(0, *rt1 - temp); rt1++; - *(out++)= MAX2(0, *rt1 - temp); rt1++; - rt2+=4; + *(out++) = MAX2(0, *rt1 - temp); rt1++; + *(out++) = MAX2(0, *rt1 - temp); rt1++; + *(out++) = MAX2(0, *rt1 - temp); rt1++; + *(out++) = MAX2(0, *rt1 - temp); rt1++; + rt2 += 4; } - rt2+=XOFF*4; + rt2 += XOFF * 4; } - memcpy(out, rt1, sizeof(int)*YOFF*width); + memcpy(out, rt1, sizeof(int) * YOFF * width); } static void do_drop_effect_float(float facf0, float facf1, int x, int y, - float *rect2i, float *rect1i, - float *outi) + float *rect2i, float *rect1i, + float *outi) { int height, width; float temp, fac, fac1, fac2; float *rt1, *rt2, *out; - int field= 1; + int field = 1; - width= x; - height= y; + width = x; + height = y; - fac1= 70.0f*facf0; - fac2= 70.0f*facf1; + fac1 = 70.0f * facf0; + fac2 = 70.0f * facf1; - rt2= (rect2i + YOFF*width); - rt1= rect1i; - out= outi; - for (y=0; y<height-YOFF; y++) { - if (field) fac= fac1; - else fac= fac2; - field= !field; + rt2 = (rect2i + YOFF * width); + rt1 = rect1i; + out = outi; + for (y = 0; y < height - YOFF; y++) { + if (field) fac = fac1; + else fac = fac2; + field = !field; - memcpy(out, rt1, 4 * sizeof(float)*XOFF); - rt1+= XOFF*4; - out+= XOFF*4; + memcpy(out, rt1, 4 * sizeof(float) * XOFF); + rt1 += XOFF * 4; + out += XOFF * 4; - for (x=XOFF; x<width; x++) { - temp= fac * rt2[3]; + for (x = XOFF; x < width; x++) { + temp = fac * rt2[3]; - *(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; + *(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; + rt2 += XOFF * 4; } - memcpy(out, rt1, 4 * sizeof(float)*YOFF*width); + memcpy(out, rt1, 4 * sizeof(float) * YOFF * width); } /* ********************************************************************** @@ -1468,19 +1463,19 @@ static void do_drop_effect_float(float facf0, float facf1, int x, int y, * ********************************************************************** */ static void do_mul_effect_byte(float facf0, float facf1, int x, int y, - unsigned char *rect1, unsigned char *rect2, - unsigned char *out) + unsigned char *rect1, unsigned char *rect2, + unsigned char *out) { int xo, fac1, fac3; char *rt1, *rt2, *rt; - xo= x; - rt1= (char *)rect1; - rt2= (char *)rect2; - rt= (char *)out; + xo = x; + rt1 = (char *)rect1; + rt2 = (char *)rect2; + rt = (char *)out; - fac1= (int)(256.0f*facf0); - fac3= (int)(256.0f*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 @@ -1489,48 +1484,48 @@ static void do_mul_effect_byte(float facf0, float facf1, int x, int y, while (y--) { - x= xo; + x = xo; while (x--) { - rt[0]= rt1[0] + ((fac1*rt1[0]*(rt2[0]-256))>>16); - rt[1]= rt1[1] + ((fac1*rt1[1]*(rt2[1]-256))>>16); - rt[2]= rt1[2] + ((fac1*rt1[2]*(rt2[2]-256))>>16); - rt[3]= rt1[3] + ((fac1*rt1[3]*(rt2[3]-256))>>16); + rt[0] = rt1[0] + ((fac1 * rt1[0] * (rt2[0] - 256)) >> 16); + rt[1] = rt1[1] + ((fac1 * rt1[1] * (rt2[1] - 256)) >> 16); + rt[2] = rt1[2] + ((fac1 * rt1[2] * (rt2[2] - 256)) >> 16); + rt[3] = rt1[3] + ((fac1 * rt1[3] * (rt2[3] - 256)) >> 16); - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } - if (y==0) break; + if (y == 0) break; y--; - x= xo; + x = xo; while (x--) { - rt[0]= rt1[0] + ((fac3*rt1[0]*(rt2[0]-256))>>16); - rt[1]= rt1[1] + ((fac3*rt1[1]*(rt2[1]-256))>>16); - rt[2]= rt1[2] + ((fac3*rt1[2]*(rt2[2]-256))>>16); - rt[3]= rt1[3] + ((fac3*rt1[3]*(rt2[3]-256))>>16); + rt[0] = rt1[0] + ((fac3 * rt1[0] * (rt2[0] - 256)) >> 16); + rt[1] = rt1[1] + ((fac3 * rt1[1] * (rt2[1] - 256)) >> 16); + rt[2] = rt1[2] + ((fac3 * rt1[2] * (rt2[2] - 256)) >> 16); + rt[3] = rt1[3] + ((fac3 * rt1[3] * (rt2[3] - 256)) >> 16); - rt1+= 4; rt2+= 4; rt+= 4; + rt1 += 4; rt2 += 4; rt += 4; } } } static void do_mul_effect_float(float facf0, float facf1, int x, int y, - float *rect1, float *rect2, - float *out) + float *rect1, float *rect2, + float *out) { int xo; float fac1, fac3; float *rt1, *rt2, *rt; - xo= x; - rt1= rect1; - rt2= rect2; - rt= out; + xo = x; + rt1 = rect1; + rt2 = rect2; + rt = out; - fac1= facf0; - fac3= facf1; + fac1 = facf0; + fac3 = facf1; /* formula: * fac*(a*b) + (1-fac)*a => fac*a*(b-1)+a @@ -1538,52 +1533,52 @@ static void do_mul_effect_float(float facf0, float facf1, int x, int y, while (y--) { - x= xo; + x = xo; while (x--) { - 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); + 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; + rt1 += 4; rt2 += 4; rt += 4; } - if (y==0) break; + if (y == 0) break; y--; - x= xo; + x = xo; while (x--) { - 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); + 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; + rt1 += 4; rt2 += 4; rt += 4; } } } -static struct ImBuf * do_mul_effect( - SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static struct ImBuf *do_mul_effect( + SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), + float facf0, float facf1, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { - struct ImBuf * out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); + struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); if (out->rect_float) { do_mul_effect_float( - facf0, facf1, context.rectx, context.recty, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + facf0, facf1, context.rectx, context.recty, + ibuf1->rect_float, ibuf2->rect_float, + out->rect_float); } else { do_mul_effect_byte( - facf0, facf1, context.rectx, context.recty, - (unsigned char*) ibuf1->rect, (unsigned char*) ibuf2->rect, - (unsigned char*) out->rect); + facf0, facf1, context.rectx, context.recty, + (unsigned char *) ibuf1->rect, (unsigned char *) ibuf2->rect, + (unsigned char *) out->rect); } return out; @@ -1607,8 +1602,8 @@ static void precalc_wipe_zone(WipeZone *wipezone, WipeVars *wipe, int xo, int yo wipezone->angle = tanf(DEG2RADF(fabsf(wipe->angle))); wipezone->xo = xo; wipezone->yo = yo; - wipezone->width = (int)(wipe->edgeWidth*((xo+yo)/2.0f)); - wipezone->pythangle = 1.0f/sqrtf(wipezone->angle*wipezone->angle + 1.0f); + wipezone->width = (int)(wipe->edgeWidth * ((xo + yo) / 2.0f)); + wipezone->pythangle = 1.0f / sqrtf(wipezone->angle * wipezone->angle + 1.0f); } // This function calculates the blur band for the wipe effects @@ -1623,18 +1618,18 @@ static float in_band(float width, float dist, int side, int dir) return (float)side; if (side == 1) - alpha = (dist+0.5f*width) / (width); + alpha = (dist + 0.5f * width) / (width); else - alpha = (0.5f*width-dist) / (width); + alpha = (0.5f * width - dist) / (width); if (dir == 0) - alpha = 1-alpha; + alpha = 1 - alpha; return alpha; } static float check_zone(WipeZone *wipezone, int x, int y, - Sequence *seq, float facf0) + Sequence *seq, float facf0) { float posx, posy, hyp, hyp2, angle, hwidth, b1, b2, b3, pointdist; /* some future stuff */ @@ -1642,9 +1637,9 @@ static float check_zone(WipeZone *wipezone, int x, int y, float temp1, temp2, temp3, temp4; //some placeholder variables int xo = wipezone->xo; int yo = wipezone->yo; - float halfx = xo*0.5f; - float halfy = yo*0.5f; - float widthf, output=0; + float halfx = xo * 0.5f; + float halfy = yo * 0.5f; + float widthf, output = 0; WipeVars *wipe = (WipeVars *)seq->effectdata; int width; @@ -1670,9 +1665,9 @@ static float check_zone(WipeZone *wipezone, int x, int y, hyp = fabs(y - posy); } else { - b1 = posy - (-angle)*posx; - b2 = y - (-angle)*x; - hyp = fabsf(angle*x+y+(-posy-angle*posx))*wipezone->pythangle; + b1 = posy - (-angle) * posx; + b2 = y - (-angle) * x; + hyp = fabsf(angle * x + y + (-posy - angle * posx)) * wipezone->pythangle; } if (angle < 0) { @@ -1693,49 +1688,49 @@ static float check_zone(WipeZone *wipezone, int x, int y, else output = in_band(width, hyp, 1, 1); } - break; + break; case DO_DOUBLE_WIPE: if (!wipe->forward) - facf0 = 1.0f-facf0; // Go the other direction + facf0 = 1.0f - facf0; // Go the other direction width = wipezone->width; // calculate the blur width - hwidth = width*0.5f; + hwidth = width * 0.5f; if (angle == 0) { - b1 = posy*0.5f; - b3 = yo-posy*0.5f; + b1 = posy * 0.5f; + b3 = yo - posy * 0.5f; b2 = y; - hyp = abs(y - posy*0.5f); - hyp2 = abs(y - (yo-posy*0.5f)); + hyp = abs(y - posy * 0.5f); + hyp2 = abs(y - (yo - posy * 0.5f)); } else { - b1 = posy*0.5f - (-angle)*posx*0.5f; - b3 = (yo-posy*0.5f) - (-angle)*(xo-posx*0.5f); - b2 = y - (-angle)*x; + b1 = posy * 0.5f - (-angle) * posx * 0.5f; + b3 = (yo - posy * 0.5f) - (-angle) * (xo - posx * 0.5f); + b2 = y - (-angle) * x; - hyp = fabsf(angle*x+y+(-posy*0.5f-angle*posx*0.5f))*wipezone->pythangle; - hyp2 = fabsf(angle*x+y+(-(yo-posy*0.5f)-angle*(xo-posx*0.5f)))*wipezone->pythangle; + hyp = fabsf(angle * x + y + (-posy * 0.5f - angle * posx * 0.5f)) * wipezone->pythangle; + hyp2 = fabsf(angle * x + y + (-(yo - posy * 0.5f) - angle * (xo - posx * 0.5f))) * wipezone->pythangle; } - hwidth = minf(hwidth, fabsf(b3-b1)/2.0f); + hwidth = minf(hwidth, fabsf(b3 - b1) / 2.0f); - if (b2 < b1 && b2 < b3 ) { + if (b2 < b1 && b2 < b3) { output = in_band(hwidth, hyp, 0, 1); } - else if (b2 > b1 && b2 > b3 ) { + else if (b2 > b1 && b2 > b3) { output = in_band(hwidth, hyp2, 0, 1); } else { - if ( hyp < hwidth && hyp2 > hwidth ) + if (hyp < hwidth && hyp2 > hwidth) output = in_band(hwidth, hyp, 1, 1); - else if ( hyp > hwidth && hyp2 < hwidth ) - output = in_band(hwidth, hyp2, 1, 1); + else if (hyp > hwidth && hyp2 < hwidth) + output = in_band(hwidth, hyp2, 1, 1); else - output = in_band(hwidth, hyp2, 1, 1) * in_band(hwidth, hyp, 1, 1); + output = in_band(hwidth, hyp2, 1, 1) * in_band(hwidth, hyp, 1, 1); } - if (!wipe->forward)output = 1-output; - break; + if (!wipe->forward) output = 1 - output; + break; case DO_CLOCK_WIPE: /* * temp1: angle of effect center in rads @@ -1744,125 +1739,125 @@ static float check_zone(WipeZone *wipezone, int x, int y, * temp4: angle of high side of blur */ output = 1.0f - facf0; - widthf = wipe->edgeWidth*2.0f*(float)M_PI; + widthf = wipe->edgeWidth * 2.0f * (float)M_PI; temp1 = 2.0f * (float)M_PI * facf0; if (wipe->forward) { - temp1 = 2.0f*(float)M_PI - temp1; + temp1 = 2.0f * (float)M_PI - temp1; } x = x - halfx; y = y - halfy; - temp2 = asin(abs(y)/sqrt(x*x + y*y)); + temp2 = asin(abs(y) / sqrt(x * x + y * y)); if (x <= 0 && y >= 0) temp2 = (float)M_PI - temp2; - else if (x<=0 && y <= 0) temp2 += (float)M_PI; - else if (x >= 0 && y <= 0) temp2 = 2.0f*(float)M_PI - temp2; + else if (x <= 0 && y <= 0) temp2 += (float)M_PI; + else if (x >= 0 && y <= 0) temp2 = 2.0f * (float)M_PI - temp2; if (wipe->forward) { - temp3 = temp1-(widthf*0.5f)*facf0; - temp4 = temp1+(widthf*0.5f)*(1-facf0); + temp3 = temp1 - (widthf * 0.5f) * facf0; + temp4 = temp1 + (widthf * 0.5f) * (1 - facf0); } else { - temp3 = temp1-(widthf*0.5f)*(1-facf0); - temp4 = temp1+(widthf*0.5f)*facf0; + temp3 = temp1 - (widthf * 0.5f) * (1 - facf0); + temp4 = temp1 + (widthf * 0.5f) * facf0; } if (temp3 < 0) temp3 = 0; - if (temp4 > 2.0f*(float)M_PI) temp4 = 2.0f*(float)M_PI; + if (temp4 > 2.0f * (float)M_PI) temp4 = 2.0f * (float)M_PI; if (temp2 < temp3) output = 0; else if (temp2 > temp4) output = 1; - else output = (temp2-temp3)/(temp4-temp3); + else output = (temp2 - temp3) / (temp4 - temp3); if (x == 0 && y == 0) output = 1; if (output != output) output = 1; if (wipe->forward) output = 1 - output; - break; - /* BOX WIPE IS NOT WORKING YET */ - /* case DO_CROSS_WIPE: */ - /* BOX WIPE IS NOT WORKING YET */ + break; + /* BOX WIPE IS NOT WORKING YET */ + /* case DO_CROSS_WIPE: */ + /* BOX WIPE IS NOT WORKING YET */ #if 0 case DO_BOX_WIPE: - if (invert)facf0 = 1-facf0; + if (invert) facf0 = 1 - facf0; - width = (int)(wipe->edgeWidth*((xo+yo)/2.0)); - hwidth = (float)width/2.0; - if (angle == 0)angle = 0.000001; - b1 = posy/2 - (-angle)*posx/2; - b3 = (yo-posy/2) - (-angle)*(xo-posx/2); - b2 = y - (-angle)*x; + width = (int)(wipe->edgeWidth * ((xo + yo) / 2.0)); + hwidth = (float)width / 2.0; + if (angle == 0) angle = 0.000001; + b1 = posy / 2 - (-angle) * posx / 2; + b3 = (yo - posy / 2) - (-angle) * (xo - posx / 2); + b2 = y - (-angle) * x; - hyp = abs(angle*x+y+(-posy/2-angle*posx/2))*wipezone->pythangle; - hyp2 = abs(angle*x+y+(-(yo-posy/2)-angle*(xo-posx/2)))*wipezone->pythangle; + hyp = abs(angle * x + y + (-posy / 2 - angle * posx / 2)) * wipezone->pythangle; + hyp2 = abs(angle * x + y + (-(yo - posy / 2) - angle * (xo - posx / 2))) * wipezone->pythangle; - temp1 = xo*(1-facf0/2)-xo*facf0/2; - temp2 = yo*(1-facf0/2)-yo*facf0/2; - pointdist = sqrt(temp1*temp1 + temp2*temp2); + temp1 = xo * (1 - facf0 / 2) - xo * facf0 / 2; + temp2 = yo * (1 - facf0 / 2) - yo * facf0 / 2; + pointdist = sqrt(temp1 * temp1 + temp2 * temp2); - if (b2 < b1 && b2 < b3 ) { + if (b2 < b1 && b2 < b3) { if (hwidth < pointdist) output = in_band(wipezone, hwidth, hyp, facf0, 0, 1); - } - else if (b2 > b1 && b2 > b3 ) { + } + else if (b2 > b1 && b2 > b3) { if (hwidth < pointdist) output = in_band(wipezone, hwidth, hyp2, facf0, 0, 1); - } - else { - if ( hyp < hwidth && hyp2 > hwidth ) + } + else { + if (hyp < hwidth && hyp2 > hwidth) output = in_band(wipezone, hwidth, hyp, facf0, 1, 1); - else if ( hyp > hwidth && hyp2 < hwidth ) - output = in_band(wipezone, hwidth, hyp2, facf0, 1, 1); + else if (hyp > hwidth && hyp2 < hwidth) + output = in_band(wipezone, hwidth, hyp2, facf0, 1, 1); else - output = in_band(wipezone, hwidth, hyp2, facf0, 1, 1) * in_band(wipezone, hwidth, hyp, facf0, 1, 1); + output = in_band(wipezone, hwidth, hyp2, facf0, 1, 1) * in_band(wipezone, hwidth, hyp, facf0, 1, 1); } - if (invert)facf0 = 1-facf0; - angle = -1/angle; - b1 = posy/2 - (-angle)*posx/2; - b3 = (yo-posy/2) - (-angle)*(xo-posx/2); - b2 = y - (-angle)*x; + if (invert) facf0 = 1 - facf0; + angle = -1 / angle; + b1 = posy / 2 - (-angle) * posx / 2; + b3 = (yo - posy / 2) - (-angle) * (xo - posx / 2); + b2 = y - (-angle) * x; - hyp = abs(angle*x+y+(-posy/2-angle*posx/2))*wipezone->pythangle; - hyp2 = abs(angle*x+y+(-(yo-posy/2)-angle*(xo-posx/2)))*wipezone->pythangle; + hyp = abs(angle * x + y + (-posy / 2 - angle * posx / 2)) * wipezone->pythangle; + hyp2 = abs(angle * x + y + (-(yo - posy / 2) - angle * (xo - posx / 2))) * wipezone->pythangle; - if (b2 < b1 && b2 < b3 ) { + if (b2 < b1 && b2 < b3) { if (hwidth < pointdist) output *= in_band(wipezone, hwidth, hyp, facf0, 0, 1); - } - else if (b2 > b1 && b2 > b3 ) { + } + else if (b2 > b1 && b2 > b3) { if (hwidth < pointdist) output *= in_band(wipezone, hwidth, hyp2, facf0, 0, 1); - } - else { - if ( hyp < hwidth && hyp2 > hwidth ) + } + else { + if (hyp < hwidth && hyp2 > hwidth) output *= in_band(wipezone, hwidth, hyp, facf0, 1, 1); - else if ( hyp > hwidth && hyp2 < hwidth ) + else if (hyp > hwidth && hyp2 < hwidth) output *= in_band(wipezone, hwidth, hyp2, facf0, 1, 1); else output *= in_band(wipezone, hwidth, hyp2, facf0, 1, 1) * in_band(wipezone, hwidth, hyp, facf0, 1, 1); } - break; + break; #endif case DO_IRIS_WIPE: if (xo > yo) yo = xo; else xo = yo; - if (!wipe->forward) facf0 = 1-facf0; + if (!wipe->forward) facf0 = 1 - facf0; width = wipezone->width; - hwidth = width*0.5f; + hwidth = width * 0.5f; - temp1 = (halfx-(halfx)*facf0); - pointdist = sqrt(temp1*temp1 + temp1*temp1); + temp1 = (halfx - (halfx) * facf0); + pointdist = sqrt(temp1 * temp1 + temp1 * temp1); - temp2 = sqrt((halfx-x)*(halfx-x) + (halfy-y)*(halfy-y)); - if (temp2 > pointdist) output = in_band(hwidth, fabs(temp2-pointdist), 0, 1); - else output = in_band(hwidth, fabs(temp2-pointdist), 1, 1); + temp2 = sqrt((halfx - x) * (halfx - x) + (halfy - y) * (halfy - y)); + if (temp2 > pointdist) output = in_band(hwidth, fabs(temp2 - pointdist), 0, 1); + else output = in_band(hwidth, fabs(temp2 - pointdist), 1, 1); - if (!wipe->forward) output = 1-output; + if (!wipe->forward) output = 1 - output; - break; + break; } if (output < 0) output = 0; else if (output > 1) output = 1; @@ -1871,7 +1866,7 @@ static float check_zone(WipeZone *wipezone, int x, int y, static void init_wipe_effect(Sequence *seq) { - if (seq->effectdata)MEM_freeN(seq->effectdata); + if (seq->effectdata) MEM_freeN(seq->effectdata); seq->effectdata = MEM_callocN(sizeof(struct WipeVars), "wipevars"); } @@ -1882,7 +1877,7 @@ static int num_inputs_wipe(void) static void free_wipe_effect(Sequence *seq) { - if (seq->effectdata)MEM_freeN(seq->effectdata); + if (seq->effectdata) MEM_freeN(seq->effectdata); seq->effectdata = NULL; } @@ -1892,9 +1887,9 @@ static void copy_wipe_effect(Sequence *dst, Sequence *src) } static void do_wipe_effect_byte(Sequence *seq, float facf0, float UNUSED(facf1), - int x, int y, - unsigned char *rect1, - unsigned char *rect2, unsigned char *out) + int x, int y, + unsigned char *rect1, + unsigned char *rect2, unsigned char *out) { WipeZone wipezone; WipeVars *wipe = (WipeVars *)seq->effectdata; @@ -1909,15 +1904,15 @@ static void do_wipe_effect_byte(Sequence *seq, float facf0, float UNUSED(facf1), xo = x; yo = y; - for (y=0;y<yo;y++) { - for (x=0;x<xo;x++) { + for (y = 0; y < yo; y++) { + for (x = 0; x < xo; x++) { float check = check_zone(&wipezone, x, y, seq, facf0); if (check) { if (rt1) { - rt[0] = (int)(rt1[0]*check)+ (int)(rt2[0]*(1-check)); - rt[1] = (int)(rt1[1]*check)+ (int)(rt2[1]*(1-check)); - rt[2] = (int)(rt1[2]*check)+ (int)(rt2[2]*(1-check)); - rt[3] = (int)(rt1[3]*check)+ (int)(rt2[3]*(1-check)); + rt[0] = (int)(rt1[0] * check) + (int)(rt2[0] * (1 - check)); + rt[1] = (int)(rt1[1] * check) + (int)(rt2[1] * (1 - check)); + rt[2] = (int)(rt1[2] * check) + (int)(rt2[2] * (1 - check)); + rt[3] = (int)(rt1[3] * check) + (int)(rt2[3] * (1 - check)); } else { rt[0] = 0; @@ -1941,21 +1936,21 @@ static void do_wipe_effect_byte(Sequence *seq, float facf0, float UNUSED(facf1), } } - rt+=4; - if (rt1 !=NULL) { - rt1+=4; + rt += 4; + if (rt1 != NULL) { + rt1 += 4; } - if (rt2 !=NULL) { - rt2+=4; + if (rt2 != NULL) { + rt2 += 4; } } } } static void do_wipe_effect_float(Sequence *seq, float facf0, float UNUSED(facf1), - int x, int y, - float *rect1, - float *rect2, float *out) + int x, int y, + float *rect1, + float *rect2, float *out) { WipeZone wipezone; WipeVars *wipe = (WipeVars *)seq->effectdata; @@ -1970,15 +1965,15 @@ static void do_wipe_effect_float(Sequence *seq, float facf0, float UNUSED(facf1) xo = x; yo = y; - for (y=0;y<yo;y++) { - for (x=0;x<xo;x++) { + for (y = 0; y < yo; y++) { + for (x = 0; x < xo; x++) { float check = check_zone(&wipezone, x, y, seq, facf0); if (check) { if (rt1) { - rt[0] = rt1[0]*check+ rt2[0]*(1-check); - rt[1] = rt1[1]*check+ rt2[1]*(1-check); - rt[2] = rt1[2]*check+ rt2[2]*(1-check); - rt[3] = rt1[3]*check+ rt2[3]*(1-check); + rt[0] = rt1[0] * check + rt2[0] * (1 - check); + rt[1] = rt1[1] * check + rt2[1] * (1 - check); + rt[2] = rt1[2] * check + rt2[2] * (1 - check); + rt[3] = rt1[3] * check + rt2[3] * (1 - check); } else { rt[0] = 0; @@ -2002,36 +1997,35 @@ static void do_wipe_effect_float(Sequence *seq, float facf0, float UNUSED(facf1) } } - rt+=4; - if (rt1 !=NULL) { - rt1+=4; + rt += 4; + if (rt1 != NULL) { + rt1 += 4; } - if (rt2 !=NULL) { - rt2+=4; + if (rt2 != NULL) { + rt2 += 4; } } } } -static struct ImBuf * do_wipe_effect( - SeqRenderData context, Sequence *seq, float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) -{ - struct ImBuf * out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); +static struct ImBuf *do_wipe_effect( + SeqRenderData context, Sequence *seq, float UNUSED(cfra), + float facf0, float facf1, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3){ + struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); if (out->rect_float) { do_wipe_effect_float(seq, - facf0, facf1, context.rectx, context.recty, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + facf0, facf1, context.rectx, context.recty, + ibuf1->rect_float, ibuf2->rect_float, + out->rect_float); } else { do_wipe_effect_byte(seq, - facf0, facf1, context.rectx, context.recty, - (unsigned char*) ibuf1->rect, (unsigned char*) ibuf2->rect, - (unsigned char*) out->rect); + facf0, facf1, context.rectx, context.recty, + (unsigned char *) ibuf1->rect, (unsigned char *) ibuf2->rect, + (unsigned char *) out->rect); } return out; @@ -2043,7 +2037,7 @@ static void init_transform_effect(Sequence *seq) { TransformVars *transform; - if (seq->effectdata)MEM_freeN(seq->effectdata); + if (seq->effectdata) MEM_freeN(seq->effectdata); seq->effectdata = MEM_callocN(sizeof(struct TransformVars), "transformvars"); transform = (TransformVars *)seq->effectdata; @@ -2051,14 +2045,14 @@ static void init_transform_effect(Sequence *seq) transform->ScalexIni = 1.0f; transform->ScaleyIni = 1.0f; - transform->xIni=0.0f; - transform->yIni=0.0f; + transform->xIni = 0.0f; + transform->yIni = 0.0f; - transform->rotIni=0.0f; + transform->rotIni = 0.0f; - transform->interpolation=1; - transform->percent=1; - transform->uniform_scale=0; + transform->interpolation = 1; + transform->percent = 1; + transform->uniform_scale = 0; } static int num_inputs_transform(void) @@ -2068,7 +2062,7 @@ static int num_inputs_transform(void) static void free_transform_effect(Sequence *seq) { - if (seq->effectdata)MEM_freeN(seq->effectdata); + if (seq->effectdata) MEM_freeN(seq->effectdata); seq->effectdata = NULL; } @@ -2078,8 +2072,8 @@ static void copy_transform_effect(Sequence *dst, Sequence *src) } static void transform_image(int x, int y, struct ImBuf *ibuf1, struct ImBuf *out, - float scale_x, float scale_y, float translate_x, float translate_y, - float rotate, int interpolation) + float scale_x, float scale_y, float translate_x, float translate_y, + float rotate, int interpolation) { int xo, yo, xi, yi; float xt, yt, xr, yr; @@ -2089,19 +2083,19 @@ static void transform_image(int x, int y, struct ImBuf *ibuf1, struct ImBuf *out yo = y; // Rotate - s= sin(rotate); - c= cos(rotate); + s = sin(rotate); + c = cos(rotate); for (yi = 0; yi < yo; yi++) { for (xi = 0; xi < xo; xi++) { //translate point - xt = xi-translate_x; - yt = yi-translate_y; + xt = xi - translate_x; + yt = yi - translate_y; //rotate point with center ref - xr = c*xt + s*yt; - yr = -s*xt + c*yt; + xr = c * xt + s * yt; + yr = -s * xt + c * yt; //scale point with center ref xt = xr / scale_x; @@ -2113,22 +2107,22 @@ static void transform_image(int x, int y, struct ImBuf *ibuf1, struct ImBuf *out //interpolate switch (interpolation) { - case 0: - neareast_interpolation(ibuf1, out, xt, yt, xi, yi); - break; - case 1: - bilinear_interpolation(ibuf1, out, xt, yt, xi, yi); - break; - case 2: - bicubic_interpolation(ibuf1, out, xt, yt, xi, yi); - break; + case 0: + neareast_interpolation(ibuf1, out, xt, yt, xi, yi); + break; + case 1: + bilinear_interpolation(ibuf1, out, xt, yt, xi, yi); + break; + case 2: + bicubic_interpolation(ibuf1, out, xt, yt, xi, yi); + break; } } } } static void do_transform(Scene *scene, Sequence *seq, float UNUSED(facf0), int x, int y, - struct ImBuf *ibuf1, struct ImBuf *out) + struct ImBuf *ibuf1, struct ImBuf *out) { TransformVars *transform = (TransformVars *)seq->effectdata; float scale_x, scale_y, translate_x, translate_y, rotate_radians; @@ -2144,14 +2138,14 @@ static void do_transform(Scene *scene, Sequence *seq, float UNUSED(facf0), int x // Translate if (!transform->percent) { - float rd_s = (scene->r.size/100.0f); + float rd_s = (scene->r.size / 100.0f); - translate_x = transform->xIni*rd_s+(x/2.0f); - translate_y = transform->yIni*rd_s+(y/2.0f); + translate_x = transform->xIni * rd_s + (x / 2.0f); + translate_y = transform->yIni * rd_s + (y / 2.0f); } else { - translate_x = x*(transform->xIni/100.0f)+(x/2.0f); - translate_y = y*(transform->yIni/100.0f)+(y/2.0f); + translate_x = x * (transform->xIni / 100.0f) + (x / 2.0f); + translate_y = y * (transform->yIni / 100.0f) + (y / 2.0f); } // Rotate @@ -2161,13 +2155,12 @@ static void do_transform(Scene *scene, Sequence *seq, float UNUSED(facf0), int x } -static struct ImBuf * do_transform_effect( - SeqRenderData context, Sequence *seq, float UNUSED(cfra), - float facf0, float UNUSED(facf1), - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) -{ - struct ImBuf * out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); +static struct ImBuf *do_transform_effect( + SeqRenderData context, Sequence *seq, float UNUSED(cfra), + float facf0, float UNUSED(facf1), + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3){ + struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); do_transform(context.scene, seq, facf0, context.rectx, context.recty, ibuf1, out); @@ -2180,7 +2173,7 @@ static struct ImBuf * do_transform_effect( * GLOW * ********************************************************************** */ -static void RVBlurBitmap2_byte(unsigned char* map, int width, int height, +static void RVBlurBitmap2_byte(unsigned char *map, int width, int height, float blur, int quality) /* MUUUCCH better than the previous blur. */ @@ -2192,26 +2185,26 @@ static void RVBlurBitmap2_byte(unsigned char* map, int width, int height, /* a small bitmap. Avoid avoid avoid. */ /*=============================== */ { - unsigned char* temp=NULL, *swap; - float *filter=NULL; - int x, y, i, fx, fy; - int index, ix, halfWidth; - float fval, k, curColor[3], curColor2[3], weight=0; + unsigned char *temp = NULL, *swap; + float *filter = NULL; + int x, y, i, fx, fy; + int index, ix, halfWidth; + float fval, k, curColor[3], curColor2[3], weight = 0; /* If we're not really blurring, bail out */ - if (blur<=0) + if (blur <= 0) return; /* Allocate memory for the tempmap and the blur filter matrix */ - temp= MEM_mallocN((width*height*4), "blurbitmaptemp"); + temp = MEM_mallocN((width * height * 4), "blurbitmaptemp"); if (!temp) return; /* Allocate memory for the filter elements */ - halfWidth = ((quality+1)*blur); - filter = (float *)MEM_mallocN(sizeof(float)*halfWidth*2, "blurbitmapfilter"); + halfWidth = ((quality + 1) * blur); + filter = (float *)MEM_mallocN(sizeof(float) * halfWidth * 2, "blurbitmapfilter"); if (!filter) { - MEM_freeN (temp); + MEM_freeN(temp); return; } @@ -2221,137 +2214,137 @@ static void RVBlurBitmap2_byte(unsigned char* map, int width, int height, /* posted to comp.graphics.algorithms by */ /* Blancmange (bmange@airdmhor.gen.nz) */ - k = -1.0f/(2.0f*(float)M_PI*blur*blur); - for (ix = 0;ix< halfWidth;ix++) { - weight = (float)exp(k*(ix*ix)); + 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; filter[halfWidth + ix] = weight; } filter[0] = weight; /* Normalize the array */ - fval=0; - for (ix = 0;ix< halfWidth*2;ix++) - fval+=filter[ix]; + fval = 0; + for (ix = 0; ix < halfWidth * 2; ix++) + fval += filter[ix]; - for (ix = 0;ix< halfWidth*2;ix++) - filter[ix]/=fval; + for (ix = 0; ix < halfWidth * 2; ix++) + filter[ix] /= fval; /* Blur the rows */ - for (y=0;y<height;y++) { + for (y = 0; y < height; y++) { /* Do the left & right strips */ - for (x=0;x<halfWidth;x++) { - index=(x+y*width)*4; - fx=0; + for (x = 0; x < halfWidth; x++) { + index = (x + y * width) * 4; + fx = 0; zero_v3(curColor); zero_v3(curColor2); - for (i=x-halfWidth;i<x+halfWidth;i++) { - if ((i>=0)&&(i<width)) { - curColor[0]+=map[(i+y*width)*4+GlowR]*filter[fx]; - curColor[1]+=map[(i+y*width)*4+GlowG]*filter[fx]; - curColor[2]+=map[(i+y*width)*4+GlowB]*filter[fx]; - - curColor2[0]+=map[(width-1-i+y*width)*4+GlowR] * - filter[fx]; - curColor2[1]+=map[(width-1-i+y*width)*4+GlowG] * - filter[fx]; - curColor2[2]+=map[(width-1-i+y*width)*4+GlowB] * - filter[fx]; + for (i = x - halfWidth; i < x + halfWidth; i++) { + if ((i >= 0) && (i < width)) { + curColor[0] += map[(i + y * width) * 4 + GlowR] * filter[fx]; + curColor[1] += map[(i + y * width) * 4 + GlowG] * filter[fx]; + curColor[2] += map[(i + y * width) * 4 + GlowB] * filter[fx]; + + curColor2[0] += map[(width - 1 - i + y * width) * 4 + GlowR] * + filter[fx]; + curColor2[1] += map[(width - 1 - i + y * width) * 4 + GlowG] * + filter[fx]; + curColor2[2] += map[(width - 1 - i + y * width) * 4 + GlowB] * + filter[fx]; } fx++; } - temp[index+GlowR]=curColor[0]; - temp[index+GlowG]=curColor[1]; - temp[index+GlowB]=curColor[2]; + temp[index + GlowR] = curColor[0]; + temp[index + GlowG] = curColor[1]; + temp[index + GlowB] = curColor[2]; - temp[((width-1-x+y*width)*4)+GlowR]=curColor2[0]; - temp[((width-1-x+y*width)*4)+GlowG]=curColor2[1]; - temp[((width-1-x+y*width)*4)+GlowB]=curColor2[2]; + temp[((width - 1 - x + y * width) * 4) + GlowR] = curColor2[0]; + temp[((width - 1 - x + y * width) * 4) + GlowG] = curColor2[1]; + temp[((width - 1 - x + y * width) * 4) + GlowB] = curColor2[2]; } /* Do the main body */ - for (x=halfWidth;x<width-halfWidth;x++) { - index=(x+y*width)*4; - fx=0; + for (x = halfWidth; x < width - halfWidth; x++) { + index = (x + y * width) * 4; + fx = 0; zero_v3(curColor); - for (i=x-halfWidth;i<x+halfWidth;i++) { - curColor[0]+=map[(i+y*width)*4+GlowR]*filter[fx]; - curColor[1]+=map[(i+y*width)*4+GlowG]*filter[fx]; - curColor[2]+=map[(i+y*width)*4+GlowB]*filter[fx]; + for (i = x - halfWidth; i < x + halfWidth; i++) { + curColor[0] += map[(i + y * width) * 4 + GlowR] * filter[fx]; + curColor[1] += map[(i + y * width) * 4 + GlowG] * filter[fx]; + curColor[2] += map[(i + y * width) * 4 + GlowB] * filter[fx]; fx++; } - temp[index+GlowR]=curColor[0]; - temp[index+GlowG]=curColor[1]; - temp[index+GlowB]=curColor[2]; + temp[index + GlowR] = curColor[0]; + temp[index + GlowG] = curColor[1]; + temp[index + GlowB] = curColor[2]; } } /* Swap buffers */ - swap=temp;temp=map;map=swap; + swap = temp; temp = map; map = swap; /* Blur the columns */ - for (x=0;x<width;x++) { + for (x = 0; x < width; x++) { /* Do the top & bottom strips */ - for (y=0;y<halfWidth;y++) { - index=(x+y*width)*4; - fy=0; + for (y = 0; y < halfWidth; y++) { + index = (x + y * width) * 4; + fy = 0; zero_v3(curColor); zero_v3(curColor2); - for (i=y-halfWidth;i<y+halfWidth;i++) { - if ((i>=0)&&(i<height)) { + for (i = y - halfWidth; i < y + halfWidth; i++) { + if ((i >= 0) && (i < height)) { /* Bottom */ - curColor[0]+=map[(x+i*width)*4+GlowR]*filter[fy]; - curColor[1]+=map[(x+i*width)*4+GlowG]*filter[fy]; - curColor[2]+=map[(x+i*width)*4+GlowB]*filter[fy]; + curColor[0] += map[(x + i * width) * 4 + GlowR] * filter[fy]; + curColor[1] += map[(x + i * width) * 4 + GlowG] * filter[fy]; + curColor[2] += map[(x + i * width) * 4 + GlowB] * filter[fy]; /* Top */ - curColor2[0]+=map[(x+(height-1-i)*width) * - 4+GlowR]*filter[fy]; - curColor2[1]+=map[(x+(height-1-i)*width) * - 4+GlowG]*filter[fy]; - curColor2[2]+=map[(x+(height-1-i)*width) * - 4+GlowB]*filter[fy]; + curColor2[0] += map[(x + (height - 1 - i) * width) * + 4 + GlowR] * filter[fy]; + curColor2[1] += map[(x + (height - 1 - i) * width) * + 4 + GlowG] * filter[fy]; + curColor2[2] += map[(x + (height - 1 - i) * width) * + 4 + GlowB] * filter[fy]; } fy++; } - temp[index+GlowR]=curColor[0]; - temp[index+GlowG]=curColor[1]; - temp[index+GlowB]=curColor[2]; - temp[((x+(height-1-y)*width)*4)+GlowR]=curColor2[0]; - temp[((x+(height-1-y)*width)*4)+GlowG]=curColor2[1]; - temp[((x+(height-1-y)*width)*4)+GlowB]=curColor2[2]; + temp[index + GlowR] = curColor[0]; + temp[index + GlowG] = curColor[1]; + temp[index + GlowB] = curColor[2]; + temp[((x + (height - 1 - y) * width) * 4) + GlowR] = curColor2[0]; + temp[((x + (height - 1 - y) * width) * 4) + GlowG] = curColor2[1]; + temp[((x + (height - 1 - y) * width) * 4) + GlowB] = curColor2[2]; } /* Do the main body */ - for (y=halfWidth;y<height-halfWidth;y++) { - index=(x+y*width)*4; - fy=0; + for (y = halfWidth; y < height - halfWidth; y++) { + index = (x + y * width) * 4; + fy = 0; zero_v3(curColor); - for (i=y-halfWidth;i<y+halfWidth;i++) { - curColor[0]+=map[(x+i*width)*4+GlowR]*filter[fy]; - curColor[1]+=map[(x+i*width)*4+GlowG]*filter[fy]; - curColor[2]+=map[(x+i*width)*4+GlowB]*filter[fy]; + for (i = y - halfWidth; i < y + halfWidth; i++) { + curColor[0] += map[(x + i * width) * 4 + GlowR] * filter[fy]; + curColor[1] += map[(x + i * width) * 4 + GlowG] * filter[fy]; + curColor[2] += map[(x + i * width) * 4 + GlowB] * filter[fy]; fy++; } - temp[index+GlowR]=curColor[0]; - temp[index+GlowG]=curColor[1]; - temp[index+GlowB]=curColor[2]; + temp[index + GlowR] = curColor[0]; + temp[index + GlowG] = curColor[1]; + temp[index + GlowB] = curColor[2]; } } /* Swap buffers */ - swap=temp;temp=map; /* map=swap; */ /* UNUSED */ + swap = temp; temp = map; /* map=swap; */ /* UNUSED */ /* Tidy up */ - MEM_freeN (filter); - MEM_freeN (temp); + MEM_freeN(filter); + MEM_freeN(temp); } -static void RVBlurBitmap2_float ( float* map, int width, int height, - float blur, - int quality) +static void RVBlurBitmap2_float(float *map, int width, int height, + float blur, + int quality) /* MUUUCCH better than the previous blur. */ /* We do the blurring in two passes which is a whole lot faster. */ /* I changed the math arount to implement an actual Gaussian */ @@ -2361,26 +2354,26 @@ static void RVBlurBitmap2_float ( float* map, int width, int height, /* a small bitmap. Avoid avoid avoid. */ /*=============================== */ { - float* temp=NULL, *swap; - float *filter=NULL; - int x, y, i, fx, fy; - int index, ix, halfWidth; - float fval, k, curColor[3], curColor2[3], weight=0; + float *temp = NULL, *swap; + float *filter = NULL; + int x, y, i, fx, fy; + int index, ix, halfWidth; + float fval, k, curColor[3], curColor2[3], weight = 0; /* If we're not really blurring, bail out */ - if (blur<=0) + if (blur <= 0) return; /* Allocate memory for the tempmap and the blur filter matrix */ - temp= MEM_mallocN((width*height*4*sizeof(float)), "blurbitmaptemp"); + temp = MEM_mallocN((width * height * 4 * sizeof(float)), "blurbitmaptemp"); if (!temp) return; /* Allocate memory for the filter elements */ - halfWidth = ((quality+1)*blur); - filter = (float *)MEM_mallocN(sizeof(float)*halfWidth*2, "blurbitmapfilter"); + halfWidth = ((quality + 1) * blur); + filter = (float *)MEM_mallocN(sizeof(float) * halfWidth * 2, "blurbitmapfilter"); if (!filter) { - MEM_freeN (temp); + MEM_freeN(temp); return; } @@ -2390,133 +2383,133 @@ static void RVBlurBitmap2_float ( float* map, int width, int height, /* posted to comp.graphics.algorithms by */ /* Blancmange (bmange@airdmhor.gen.nz) */ - k = -1.0f/(2.0f*(float)M_PI*blur*blur); + k = -1.0f / (2.0f * (float)M_PI * blur * blur); - for (ix = 0;ix< halfWidth;ix++) { - weight = (float)exp(k*(ix*ix)); + for (ix = 0; ix < halfWidth; ix++) { + weight = (float)exp(k * (ix * ix)); filter[halfWidth - ix] = weight; filter[halfWidth + ix] = weight; } filter[0] = weight; /* Normalize the array */ - fval=0; - for (ix = 0;ix< halfWidth*2;ix++) - fval+=filter[ix]; + fval = 0; + for (ix = 0; ix < halfWidth * 2; ix++) + fval += filter[ix]; - for (ix = 0;ix< halfWidth*2;ix++) - filter[ix]/=fval; + for (ix = 0; ix < halfWidth * 2; ix++) + filter[ix] /= fval; /* Blur the rows */ - for (y=0;y<height;y++) { + for (y = 0; y < height; y++) { /* Do the left & right strips */ - for (x=0;x<halfWidth;x++) { - index=(x+y*width)*4; - fx=0; - curColor[0]=curColor[1]=curColor[2]=0.0f; - curColor2[0]=curColor2[1]=curColor2[2]=0.0f; - - for (i=x-halfWidth;i<x+halfWidth;i++) { - if ((i>=0)&&(i<width)) { - curColor[0]+=map[(i+y*width)*4+GlowR]*filter[fx]; - curColor[1]+=map[(i+y*width)*4+GlowG]*filter[fx]; - curColor[2]+=map[(i+y*width)*4+GlowB]*filter[fx]; - - curColor2[0]+=map[(width-1-i+y*width)*4+GlowR] * - filter[fx]; - curColor2[1]+=map[(width-1-i+y*width)*4+GlowG] * - filter[fx]; - curColor2[2]+=map[(width-1-i+y*width)*4+GlowB] * - filter[fx]; + for (x = 0; x < halfWidth; x++) { + index = (x + y * width) * 4; + fx = 0; + curColor[0] = curColor[1] = curColor[2] = 0.0f; + curColor2[0] = curColor2[1] = curColor2[2] = 0.0f; + + for (i = x - halfWidth; i < x + halfWidth; i++) { + if ((i >= 0) && (i < width)) { + curColor[0] += map[(i + y * width) * 4 + GlowR] * filter[fx]; + curColor[1] += map[(i + y * width) * 4 + GlowG] * filter[fx]; + curColor[2] += map[(i + y * width) * 4 + GlowB] * filter[fx]; + + curColor2[0] += map[(width - 1 - i + y * width) * 4 + GlowR] * + filter[fx]; + curColor2[1] += map[(width - 1 - i + y * width) * 4 + GlowG] * + filter[fx]; + curColor2[2] += map[(width - 1 - i + y * width) * 4 + GlowB] * + filter[fx]; } fx++; } - temp[index+GlowR]=curColor[0]; - temp[index+GlowG]=curColor[1]; - temp[index+GlowB]=curColor[2]; + temp[index + GlowR] = curColor[0]; + temp[index + GlowG] = curColor[1]; + temp[index + GlowB] = curColor[2]; - temp[((width-1-x+y*width)*4)+GlowR]=curColor2[0]; - temp[((width-1-x+y*width)*4)+GlowG]=curColor2[1]; - temp[((width-1-x+y*width)*4)+GlowB]=curColor2[2]; + temp[((width - 1 - x + y * width) * 4) + GlowR] = curColor2[0]; + temp[((width - 1 - x + y * width) * 4) + GlowG] = curColor2[1]; + temp[((width - 1 - x + y * width) * 4) + GlowB] = curColor2[2]; } /* Do the main body */ - for (x=halfWidth;x<width-halfWidth;x++) { - index=(x+y*width)*4; - fx=0; + for (x = halfWidth; x < width - halfWidth; x++) { + index = (x + y * width) * 4; + fx = 0; zero_v3(curColor); - for (i=x-halfWidth;i<x+halfWidth;i++) { - curColor[0]+=map[(i+y*width)*4+GlowR]*filter[fx]; - curColor[1]+=map[(i+y*width)*4+GlowG]*filter[fx]; - curColor[2]+=map[(i+y*width)*4+GlowB]*filter[fx]; + for (i = x - halfWidth; i < x + halfWidth; i++) { + curColor[0] += map[(i + y * width) * 4 + GlowR] * filter[fx]; + curColor[1] += map[(i + y * width) * 4 + GlowG] * filter[fx]; + curColor[2] += map[(i + y * width) * 4 + GlowB] * filter[fx]; fx++; } - temp[index+GlowR]=curColor[0]; - temp[index+GlowG]=curColor[1]; - temp[index+GlowB]=curColor[2]; + temp[index + GlowR] = curColor[0]; + temp[index + GlowG] = curColor[1]; + temp[index + GlowB] = curColor[2]; } } /* Swap buffers */ - swap=temp;temp=map;map=swap; + swap = temp; temp = map; map = swap; /* Blur the columns */ - for (x=0;x<width;x++) { + for (x = 0; x < width; x++) { /* Do the top & bottom strips */ - for (y=0;y<halfWidth;y++) { - index=(x+y*width)*4; - fy=0; + for (y = 0; y < halfWidth; y++) { + index = (x + y * width) * 4; + fy = 0; zero_v3(curColor); zero_v3(curColor2); - for (i=y-halfWidth;i<y+halfWidth;i++) { - if ((i>=0)&&(i<height)) { + for (i = y - halfWidth; i < y + halfWidth; i++) { + if ((i >= 0) && (i < height)) { /* Bottom */ - curColor[0]+=map[(x+i*width)*4+GlowR]*filter[fy]; - curColor[1]+=map[(x+i*width)*4+GlowG]*filter[fy]; - curColor[2]+=map[(x+i*width)*4+GlowB]*filter[fy]; + curColor[0] += map[(x + i * width) * 4 + GlowR] * filter[fy]; + curColor[1] += map[(x + i * width) * 4 + GlowG] * filter[fy]; + curColor[2] += map[(x + i * width) * 4 + GlowB] * filter[fy]; /* Top */ - curColor2[0]+=map[(x+(height-1-i)*width) * - 4+GlowR]*filter[fy]; - curColor2[1]+=map[(x+(height-1-i)*width) * - 4+GlowG]*filter[fy]; - curColor2[2]+=map[(x+(height-1-i)*width) * - 4+GlowB]*filter[fy]; + curColor2[0] += map[(x + (height - 1 - i) * width) * + 4 + GlowR] * filter[fy]; + curColor2[1] += map[(x + (height - 1 - i) * width) * + 4 + GlowG] * filter[fy]; + curColor2[2] += map[(x + (height - 1 - i) * width) * + 4 + GlowB] * filter[fy]; } fy++; } - temp[index+GlowR]=curColor[0]; - temp[index+GlowG]=curColor[1]; - temp[index+GlowB]=curColor[2]; - temp[((x+(height-1-y)*width)*4)+GlowR]=curColor2[0]; - temp[((x+(height-1-y)*width)*4)+GlowG]=curColor2[1]; - temp[((x+(height-1-y)*width)*4)+GlowB]=curColor2[2]; + temp[index + GlowR] = curColor[0]; + temp[index + GlowG] = curColor[1]; + temp[index + GlowB] = curColor[2]; + temp[((x + (height - 1 - y) * width) * 4) + GlowR] = curColor2[0]; + temp[((x + (height - 1 - y) * width) * 4) + GlowG] = curColor2[1]; + temp[((x + (height - 1 - y) * width) * 4) + GlowB] = curColor2[2]; } /* Do the main body */ - for (y=halfWidth;y<height-halfWidth;y++) { - index=(x+y*width)*4; - fy=0; + for (y = halfWidth; y < height - halfWidth; y++) { + index = (x + y * width) * 4; + fy = 0; zero_v3(curColor); - for (i=y-halfWidth;i<y+halfWidth;i++) { - curColor[0]+=map[(x+i*width)*4+GlowR]*filter[fy]; - curColor[1]+=map[(x+i*width)*4+GlowG]*filter[fy]; - curColor[2]+=map[(x+i*width)*4+GlowB]*filter[fy]; + for (i = y - halfWidth; i < y + halfWidth; i++) { + curColor[0] += map[(x + i * width) * 4 + GlowR] * filter[fy]; + curColor[1] += map[(x + i * width) * 4 + GlowG] * filter[fy]; + curColor[2] += map[(x + i * width) * 4 + GlowB] * filter[fy]; fy++; } - temp[index+GlowR]=curColor[0]; - temp[index+GlowG]=curColor[1]; - temp[index+GlowB]=curColor[2]; + temp[index + GlowR] = curColor[0]; + temp[index + GlowG] = curColor[1]; + temp[index + GlowB] = curColor[2]; } } /* Swap buffers */ - swap=temp;temp=map; /* map=swap; */ /* UNUSED */ + swap = temp; temp = map; /* map=swap; */ /* UNUSED */ /* Tidy up */ - MEM_freeN (filter); - MEM_freeN (temp); + MEM_freeN(filter); + MEM_freeN(temp); } @@ -2524,94 +2517,94 @@ static void RVBlurBitmap2_float ( float* map, int width, int height, /* C must have been previously allocated but it may be A or B. */ /* We clamp values to 255 to prevent weirdness */ /*=============================== */ -static void RVAddBitmaps_byte (unsigned char* a, unsigned char* b, unsigned char* c, int width, int height) +static void RVAddBitmaps_byte(unsigned char *a, unsigned char *b, unsigned char *c, int width, int height) { - int x, y, index; + int x, y, index; - for (y=0;y<height;y++) { - for (x=0;x<width;x++) { - index=(x+y*width)*4; - c[index+GlowR]=MIN2(255, a[index+GlowR]+b[index+GlowR]); - c[index+GlowG]=MIN2(255, a[index+GlowG]+b[index+GlowG]); - c[index+GlowB]=MIN2(255, a[index+GlowB]+b[index+GlowB]); - c[index+GlowA]=MIN2(255, a[index+GlowA]+b[index+GlowA]); + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + index = (x + y * width) * 4; + c[index + GlowR] = MIN2(255, a[index + GlowR] + b[index + GlowR]); + c[index + GlowG] = MIN2(255, a[index + GlowG] + b[index + GlowG]); + c[index + GlowB] = MIN2(255, a[index + GlowB] + b[index + GlowB]); + c[index + GlowA] = MIN2(255, a[index + GlowA] + b[index + GlowA]); } } } -static void RVAddBitmaps_float (float* a, float* b, float* c, - int width, int height) +static void RVAddBitmaps_float(float *a, float *b, float *c, + int width, int height) { - int x, y, index; + int x, y, index; - for (y=0;y<height;y++) { - for (x=0;x<width;x++) { - index=(x+y*width)*4; - 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]); + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + index = (x + y * width) * 4; + 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]); } } } /* For each pixel whose total luminance exceeds the threshold, */ /* Multiply it's value by BOOST and add it to the output map */ -static void RVIsolateHighlights_byte (unsigned char* in, unsigned char* out, - int width, int height, int threshold, - float boost, float clamp) +static void RVIsolateHighlights_byte(unsigned char *in, unsigned char *out, + int width, int height, int threshold, + float boost, float clamp) { int x, y, index; - int intensity; + int intensity; - for (y=0;y< height;y++) { - for (x=0;x< width;x++) { - index= (x+y*width)*4; + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + index = (x + y * width) * 4; /* Isolate the intensity */ - intensity=(in[index+GlowR]+in[index+GlowG]+in[index+GlowB]-threshold); - if (intensity>0) { - out[index+GlowR]=MIN2(255*clamp, (in[index+GlowR]*boost*intensity)/255); - out[index+GlowG]=MIN2(255*clamp, (in[index+GlowG]*boost*intensity)/255); - out[index+GlowB]=MIN2(255*clamp, (in[index+GlowB]*boost*intensity)/255); - out[index+GlowA]=MIN2(255*clamp, (in[index+GlowA]*boost*intensity)/255); + intensity = (in[index + GlowR] + in[index + GlowG] + in[index + GlowB] - threshold); + if (intensity > 0) { + out[index + GlowR] = MIN2(255 * clamp, (in[index + GlowR] * boost * intensity) / 255); + out[index + GlowG] = MIN2(255 * clamp, (in[index + GlowG] * boost * intensity) / 255); + out[index + GlowB] = MIN2(255 * clamp, (in[index + GlowB] * boost * intensity) / 255); + out[index + GlowA] = MIN2(255 * clamp, (in[index + GlowA] * boost * intensity) / 255); } else { - out[index+GlowR]=0; - out[index+GlowG]=0; - out[index+GlowB]=0; - out[index+GlowA]=0; + out[index + GlowR] = 0; + out[index + GlowG] = 0; + out[index + GlowB] = 0; + out[index + GlowA] = 0; } } } } -static void RVIsolateHighlights_float (float* in, float* out, - int width, int height, float threshold, - float boost, float clamp) +static void RVIsolateHighlights_float(float *in, float *out, + int width, int height, float threshold, + float boost, float clamp) { int x, y, index; - float intensity; + float intensity; - for (y=0;y< height;y++) { - for (x=0;x< width;x++) { - index= (x+y*width)*4; + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + index = (x + y * width) * 4; /* Isolate the intensity */ - intensity=(in[index+GlowR]+in[index+GlowG]+in[index+GlowB]-threshold); - if (intensity>0) { - out[index+GlowR]=MIN2(clamp, (in[index+GlowR]*boost*intensity)); - out[index+GlowG]=MIN2(clamp, (in[index+GlowG]*boost*intensity)); - out[index+GlowB]=MIN2(clamp, (in[index+GlowB]*boost*intensity)); - out[index+GlowA]=MIN2(clamp, (in[index+GlowA]*boost*intensity)); + intensity = (in[index + GlowR] + in[index + GlowG] + in[index + GlowB] - threshold); + if (intensity > 0) { + out[index + GlowR] = MIN2(clamp, (in[index + GlowR] * boost * intensity)); + out[index + GlowG] = MIN2(clamp, (in[index + GlowG] * boost * intensity)); + out[index + GlowB] = MIN2(clamp, (in[index + GlowB] * boost * intensity)); + out[index + GlowA] = MIN2(clamp, (in[index + GlowA] * boost * intensity)); } else { - out[index+GlowR]=0; - out[index+GlowG]=0; - out[index+GlowB]=0; - out[index+GlowA]=0; + out[index + GlowR] = 0; + out[index + GlowG] = 0; + out[index + GlowB] = 0; + out[index + GlowA] = 0; } } } @@ -2621,7 +2614,7 @@ static void init_glow_effect(Sequence *seq) { GlowVars *glow; - if (seq->effectdata)MEM_freeN(seq->effectdata); + if (seq->effectdata) MEM_freeN(seq->effectdata); seq->effectdata = MEM_callocN(sizeof(struct GlowVars), "glowvars"); glow = (GlowVars *)seq->effectdata; @@ -2640,7 +2633,7 @@ static int num_inputs_glow(void) static void free_glow_effect(Sequence *seq) { - if (seq->effectdata)MEM_freeN(seq->effectdata); + if (seq->effectdata) MEM_freeN(seq->effectdata); seq->effectdata = NULL; } @@ -2651,56 +2644,56 @@ static void copy_glow_effect(Sequence *dst, Sequence *src) //void do_glow_effect(Cast *cast, float facf0, float facf1, int xo, int yo, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *outbuf, ImBuf *use) static void do_glow_effect_byte(Sequence *seq, int render_size, float facf0, float UNUSED(facf1), - int x, int y, char *rect1, - char *UNUSED(rect2), char *out) + int x, int y, char *rect1, + char *UNUSED(rect2), char *out) { - unsigned char *outbuf=(unsigned char *)out; - unsigned char *inbuf=(unsigned char *)rect1; + unsigned char *outbuf = (unsigned char *)out; + unsigned char *inbuf = (unsigned char *)rect1; GlowVars *glow = (GlowVars *)seq->effectdata; - RVIsolateHighlights_byte(inbuf, outbuf, x, y, glow->fMini*765, glow->fBoost * facf0, glow->fClamp); - RVBlurBitmap2_byte (outbuf, x, y, glow->dDist * (render_size / 100.0f), glow->dQuality); + RVIsolateHighlights_byte(inbuf, outbuf, x, y, glow->fMini * 765, glow->fBoost * facf0, glow->fClamp); + RVBlurBitmap2_byte(outbuf, x, y, glow->dDist * (render_size / 100.0f), glow->dQuality); if (!glow->bNoComp) - RVAddBitmaps_byte (inbuf, outbuf, outbuf, x, y); + RVAddBitmaps_byte(inbuf, outbuf, outbuf, x, y); } static void do_glow_effect_float(Sequence *seq, int render_size, float facf0, float UNUSED(facf1), - int x, int y, - float *rect1, float *UNUSED(rect2), float *out) + int x, int y, + float *rect1, float *UNUSED(rect2), float *out) { float *outbuf = out; float *inbuf = rect1; GlowVars *glow = (GlowVars *)seq->effectdata; - RVIsolateHighlights_float(inbuf, outbuf, x, y, glow->fMini*3.0f, glow->fBoost * facf0, glow->fClamp); - RVBlurBitmap2_float (outbuf, x, y, glow->dDist * (render_size / 100.0f), glow->dQuality); + RVIsolateHighlights_float(inbuf, outbuf, x, y, glow->fMini * 3.0f, glow->fBoost * facf0, glow->fClamp); + RVBlurBitmap2_float(outbuf, x, y, glow->dDist * (render_size / 100.0f), glow->dQuality); if (!glow->bNoComp) - RVAddBitmaps_float (inbuf, outbuf, outbuf, x, y); + RVAddBitmaps_float(inbuf, outbuf, outbuf, x, y); } -static struct ImBuf * do_glow_effect( - SeqRenderData context, Sequence *seq, float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static struct ImBuf *do_glow_effect( + SeqRenderData context, Sequence *seq, float UNUSED(cfra), + float facf0, float facf1, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) { - struct ImBuf * out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); + struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); - int render_size = 100*context.rectx/context.scene->r.xsch; + int render_size = 100 * context.rectx / context.scene->r.xsch; if (out->rect_float) { do_glow_effect_float(seq, render_size, - facf0, facf1, - context.rectx, context.recty, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + facf0, facf1, + context.rectx, context.recty, + ibuf1->rect_float, ibuf2->rect_float, + out->rect_float); } else { do_glow_effect_byte(seq, render_size, - facf0, facf1, - context.rectx, context.recty, - (char*) ibuf1->rect, (char*) ibuf2->rect, - (char*) out->rect); + facf0, facf1, + context.rectx, context.recty, + (char *) ibuf1->rect, (char *) ibuf2->rect, + (char *) out->rect); } return out; @@ -2714,7 +2707,7 @@ static void init_solid_color(Sequence *seq) { SolidColorVars *cv; - if (seq->effectdata)MEM_freeN(seq->effectdata); + if (seq->effectdata) MEM_freeN(seq->effectdata); seq->effectdata = MEM_callocN(sizeof(struct SolidColorVars), "solidcolor"); cv = (SolidColorVars *)seq->effectdata; @@ -2728,7 +2721,7 @@ static int num_inputs_color(void) static void free_solid_color(Sequence *seq) { - if (seq->effectdata)MEM_freeN(seq->effectdata); + if (seq->effectdata) MEM_freeN(seq->effectdata); seq->effectdata = NULL; } @@ -2738,18 +2731,17 @@ static void copy_solid_color(Sequence *dst, Sequence *src) } static int early_out_color(struct Sequence *UNUSED(seq), - float UNUSED(facf0), float UNUSED(facf1)) + float UNUSED(facf0), float UNUSED(facf1)) { return -1; } -static struct ImBuf * do_solid_color( - SeqRenderData context, Sequence *seq, float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) -{ - struct ImBuf * out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); +static struct ImBuf *do_solid_color( + SeqRenderData context, Sequence *seq, float UNUSED(cfra), + float facf0, float facf1, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3){ + struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); SolidColorVars *cv = (SolidColorVars *)seq->effectdata; @@ -2772,20 +2764,20 @@ static struct ImBuf * do_solid_color( rect = (unsigned char *)out->rect; - for (y=0; y<out->y; y++) { - for (x=0; x<out->x; x++, rect+=4) { - rect[0]= col0[0]; - rect[1]= col0[1]; - rect[2]= col0[2]; - rect[3]= 255; + for (y = 0; y < out->y; y++) { + for (x = 0; x < out->x; x++, rect += 4) { + rect[0] = col0[0]; + rect[1] = col0[1]; + rect[2] = col0[2]; + rect[3] = 255; } y++; - if (y<out->y) { - for (x=0; x<out->x; x++, rect+=4) { - rect[0]= col1[0]; - rect[1]= col1[1]; - rect[2]= col1[2]; - rect[3]= 255; + if (y < out->y) { + for (x = 0; x < out->x; x++, rect += 4) { + rect[0] = col1[0]; + rect[1] = col1[1]; + rect[2] = col1[2]; + rect[3] = 255; } } } @@ -2805,20 +2797,20 @@ static struct ImBuf * do_solid_color( rect_float = out->rect_float; - for (y=0; y<out->y; y++) { - for (x=0; x<out->x; x++, rect_float+=4) { - rect_float[0]= col0[0]; - rect_float[1]= col0[1]; - rect_float[2]= col0[2]; - rect_float[3]= 1.0; + for (y = 0; y < out->y; y++) { + for (x = 0; x < out->x; x++, rect_float += 4) { + rect_float[0] = col0[0]; + rect_float[1] = col0[1]; + rect_float[2] = col0[2]; + rect_float[3] = 1.0; } y++; - if (y<out->y) { - for (x=0; x<out->x; x++, rect_float+=4) { - rect_float[0]= col1[0]; - rect_float[1]= col1[1]; - rect_float[2]= col1[2]; - rect_float[3]= 1.0; + if (y < out->y) { + for (x = 0; x < out->x; x++, rect_float += 4) { + rect_float[0] = col1[0]; + rect_float[1] = col1[1]; + rect_float[2] = col1[2]; + rect_float[3] = 1.0; } } } @@ -2841,16 +2833,15 @@ static int early_out_multicam(struct Sequence *UNUSED(seq), float UNUSED(facf0), return -1; } -static struct ImBuf * do_multicam( - SeqRenderData context, Sequence *seq, float cfra, - float UNUSED(facf0), float UNUSED(facf1), - struct ImBuf *UNUSED(ibuf1), struct ImBuf *UNUSED(ibuf2), - struct ImBuf *UNUSED(ibuf3)) -{ - struct ImBuf * i; - struct ImBuf * out; - Editing * ed; - ListBase * seqbasep; +static struct ImBuf *do_multicam( + SeqRenderData context, Sequence *seq, float cfra, + float UNUSED(facf0), float UNUSED(facf1), + struct ImBuf *UNUSED(ibuf1), struct ImBuf *UNUSED(ibuf2), + struct ImBuf *UNUSED(ibuf3)){ + struct ImBuf *i; + struct ImBuf *out; + Editing *ed; + ListBase *seqbasep; if (seq->multicam_source == 0 || seq->multicam_source >= seq->machine) { return NULL; @@ -2896,12 +2887,11 @@ static int early_out_adjustment(struct Sequence *UNUSED(seq), float UNUSED(facf0 return -1; } -static struct ImBuf * do_adjustment_impl(SeqRenderData context, Sequence * seq, - float cfra) -{ - Editing * ed; - ListBase * seqbasep; - struct ImBuf * i= NULL; +static struct ImBuf *do_adjustment_impl(SeqRenderData context, Sequence *seq, + float cfra){ + Editing *ed; + ListBase *seqbasep; + struct ImBuf *i = NULL; ed = context.scene->ed; @@ -2909,7 +2899,7 @@ static struct ImBuf * do_adjustment_impl(SeqRenderData context, Sequence * seq, if (seq->machine > 0) { i = give_ibuf_seqbase(context, cfra, - seq->machine - 1, seqbasep); + seq->machine - 1, seqbasep); } /* found nothing? so let's work the way up the metastrip stack, so @@ -2918,7 +2908,7 @@ static struct ImBuf * do_adjustment_impl(SeqRenderData context, Sequence * seq, */ if (!i) { - Sequence * meta; + Sequence *meta; meta = seq_metastrip(&ed->seqbase, NULL, seq); @@ -2930,15 +2920,14 @@ static struct ImBuf * do_adjustment_impl(SeqRenderData context, Sequence * seq, return i; } -static struct ImBuf * do_adjustment( - SeqRenderData context, Sequence *seq, float cfra, - float UNUSED(facf0), float UNUSED(facf1), - struct ImBuf *UNUSED(ibuf1), struct ImBuf *UNUSED(ibuf2), - struct ImBuf *UNUSED(ibuf3)) -{ - struct ImBuf * i = NULL; - struct ImBuf * out; - Editing * ed; +static struct ImBuf *do_adjustment( + SeqRenderData context, Sequence *seq, float cfra, + float UNUSED(facf0), float UNUSED(facf1), + struct ImBuf *UNUSED(ibuf1), struct ImBuf *UNUSED(ibuf2), + struct ImBuf *UNUSED(ibuf3)){ + struct ImBuf *i = NULL; + struct ImBuf *out; + Editing *ed; ed = context.scene->ed; @@ -2964,11 +2953,11 @@ static struct ImBuf * do_adjustment( * ********************************************************************** */ static void init_speed_effect(Sequence *seq) { - SpeedControlVars * v; + SpeedControlVars *v; if (seq->effectdata) MEM_freeN(seq->effectdata); seq->effectdata = MEM_callocN(sizeof(struct SpeedControlVars), - "speedcontrolvars"); + "speedcontrolvars"); v = (SpeedControlVars *)seq->effectdata; v->globalSpeed = 1.0; @@ -2977,9 +2966,9 @@ static void init_speed_effect(Sequence *seq) v->length = 0; } -static void load_speed_effect(Sequence * seq) +static void load_speed_effect(Sequence *seq) { - SpeedControlVars * v = (SpeedControlVars *)seq->effectdata; + SpeedControlVars *v = (SpeedControlVars *)seq->effectdata; v->frameMap = NULL; v->length = 0; @@ -2992,7 +2981,7 @@ static int num_inputs_speed(void) static void free_speed_effect(Sequence *seq) { - SpeedControlVars * v = (SpeedControlVars *)seq->effectdata; + SpeedControlVars *v = (SpeedControlVars *)seq->effectdata; if (v->frameMap) MEM_freeN(v->frameMap); if (seq->effectdata) MEM_freeN(seq->effectdata); seq->effectdata = NULL; @@ -3000,7 +2989,7 @@ static void free_speed_effect(Sequence *seq) static void copy_speed_effect(Sequence *dst, Sequence *src) { - SpeedControlVars * v; + SpeedControlVars *v; dst->effectdata = MEM_dupallocN(src->effectdata); v = (SpeedControlVars *)dst->effectdata; v->frameMap = NULL; @@ -3008,15 +2997,15 @@ static void copy_speed_effect(Sequence *dst, Sequence *src) } static int early_out_speed(struct Sequence *UNUSED(seq), - float UNUSED(facf0), float UNUSED(facf1)) + float UNUSED(facf0), float UNUSED(facf1)) { return 1; } -static void store_icu_yrange_speed(struct Sequence * seq, - short UNUSED(adrcode), float * ymin, float * ymax) +static void store_icu_yrange_speed(struct Sequence *seq, + short UNUSED(adrcode), float *ymin, float *ymax) { - SpeedControlVars * v = (SpeedControlVars *)seq->effectdata; + SpeedControlVars *v = (SpeedControlVars *)seq->effectdata; /* if not already done, load / initialize data */ get_sequence_effect(seq); @@ -3036,32 +3025,31 @@ static void store_icu_yrange_speed(struct Sequence * seq, } } } -void sequence_effect_speed_rebuild_map(Scene *scene, Sequence * seq, int force) +void sequence_effect_speed_rebuild_map(Scene *scene, Sequence *seq, int force) { int cfra; float fallback_fac = 1.0f; - SpeedControlVars * v = (SpeedControlVars *)seq->effectdata; - FCurve *fcu= NULL; + SpeedControlVars *v = (SpeedControlVars *)seq->effectdata; + FCurve *fcu = NULL; int flags = v->flags; /* if not already done, load / initialize data */ get_sequence_effect(seq); - if ( (force == FALSE) && - (seq->len == v->length) && - (v->frameMap != NULL) - ) { + if ((force == FALSE) && + (seq->len == v->length) && + (v->frameMap != NULL)) + { return; } - if ( (seq->seq1 == NULL) || - (seq->len < 1) - ) { /* make coverity happy and check for (CID 598) input strip ... */ + if ((seq->seq1 == NULL) || (seq->len < 1)) { + /* make coverity happy and check for (CID 598) input strip ... */ return; } /* XXX - new in 2.5x. should we use the animation system this way? * The fcurve is needed because many frames need evaluating at once - campbell */ - fcu= id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "speed_factor", 0, NULL); + fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "speed_factor", 0, NULL); if (!v->frameMap || v->length != seq->len) { @@ -3070,7 +3058,7 @@ void sequence_effect_speed_rebuild_map(Scene *scene, Sequence * seq, int force) v->length = seq->len; v->frameMap = MEM_callocN(sizeof(float) * v->length, - "speedcontrol frameMap"); + "speedcontrol frameMap"); } fallback_fac = 1.0; @@ -3080,7 +3068,7 @@ void sequence_effect_speed_rebuild_map(Scene *scene, Sequence * seq, int force) (seq->seq1->len != 0)) { fallback_fac = (float) seq->seq1->len / - (float) (seq->seq1->enddisp - seq->seq1->start); + (float) (seq->seq1->enddisp - seq->seq1->start); flags = SEQ_SPEED_INTEGRATE; fcu = NULL; } @@ -3179,13 +3167,13 @@ static int num_inputs_default(void) } static int early_out_noop(struct Sequence *UNUSED(seq), - float UNUSED(facf0), float UNUSED(facf1)) + float UNUSED(facf0), float UNUSED(facf1)) { return 0; } static int early_out_fade(struct Sequence *UNUSED(seq), - float facf0, float facf1) + float facf0, float facf1) { if (facf0 == 0.0f && facf1 == 0.0f) { return 1; @@ -3197,7 +3185,7 @@ static int early_out_fade(struct Sequence *UNUSED(seq), } static int early_out_mul_input2(struct Sequence *UNUSED(seq), - float facf0, float facf1) + float facf0, float facf1) { if (facf0 == 0.0f && facf1 == 0.0f) { return 1; @@ -3205,20 +3193,20 @@ static int early_out_mul_input2(struct Sequence *UNUSED(seq), return 0; } -static void store_icu_yrange_noop(struct Sequence * UNUSED(seq), - short UNUSED(adrcode), float *UNUSED(ymin), float *UNUSED(ymax)) +static void store_icu_yrange_noop(struct Sequence *UNUSED(seq), + short UNUSED(adrcode), float *UNUSED(ymin), float *UNUSED(ymax)) { /* defaults are fine */ } static void get_default_fac_noop(struct Sequence *UNUSED(seq), float UNUSED(cfra), - float * facf0, float * facf1) + float *facf0, float *facf1) { *facf0 = *facf1 = 1.0; } static void get_default_fac_fade(struct Sequence *seq, float cfra, - float * facf0, float * facf1) + float *facf0, float *facf1) { *facf0 = (float)(cfra - seq->startdisp); *facf1 = (float)(*facf0 + 0.5f); @@ -3226,45 +3214,43 @@ static void get_default_fac_fade(struct Sequence *seq, float cfra, *facf1 /= seq->len; } -static struct ImBuf * do_overdrop_effect(SeqRenderData context, - Sequence *UNUSED(seq), - float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf * ibuf1, - struct ImBuf * ibuf2, - struct ImBuf * ibuf3) -{ - struct ImBuf * out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); +static struct ImBuf *do_overdrop_effect(SeqRenderData context, + Sequence *UNUSED(seq), + float UNUSED(cfra), + float facf0, float facf1, + struct ImBuf *ibuf1, + struct ImBuf *ibuf2, + struct ImBuf *ibuf3){ + struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); int x = context.rectx; int y = context.recty; if (out->rect_float) { do_drop_effect_float( - facf0, facf1, x, y, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + facf0, facf1, x, y, + ibuf1->rect_float, ibuf2->rect_float, + out->rect_float); do_alphaover_effect_float( - facf0, facf1, x, y, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + facf0, facf1, x, y, + ibuf1->rect_float, ibuf2->rect_float, + out->rect_float); } else { do_drop_effect_byte( - facf0, facf1, x, y, - (char*) ibuf1->rect, - (char*) ibuf2->rect, - (char*) out->rect); + facf0, facf1, x, y, + (char *) ibuf1->rect, + (char *) ibuf2->rect, + (char *) out->rect); do_alphaover_effect_byte( - facf0, facf1, x, y, - (char*) ibuf1->rect, (char*) ibuf2->rect, - (char*) out->rect); + facf0, facf1, x, y, + (char *) ibuf1->rect, (char *) ibuf2->rect, + (char *) out->rect); } return out; } -static struct SeqEffectHandle get_sequence_effect_impl(int seq_type) -{ +static struct SeqEffectHandle get_sequence_effect_impl(int seq_type){ struct SeqEffectHandle rval; int sequence_type = seq_type; @@ -3280,112 +3266,112 @@ static struct SeqEffectHandle get_sequence_effect_impl(int seq_type) rval.copy = NULL; switch (sequence_type) { - case SEQ_CROSS: - rval.execute = do_cross_effect; - rval.early_out = early_out_fade; - rval.get_default_fac = get_default_fac_fade; - break; - case SEQ_GAMCROSS: - rval.init = init_gammacross; - rval.load = load_gammacross; - rval.free = free_gammacross; - rval.early_out = early_out_fade; - rval.get_default_fac = get_default_fac_fade; - rval.execute = do_gammacross_effect; - break; - case SEQ_ADD: - rval.execute = do_add_effect; - rval.early_out = early_out_mul_input2; - break; - case SEQ_SUB: - rval.execute = do_sub_effect; - rval.early_out = early_out_mul_input2; - break; - case SEQ_MUL: - rval.execute = do_mul_effect; - rval.early_out = early_out_mul_input2; - break; - case SEQ_ALPHAOVER: - rval.init = init_alpha_over_or_under; - rval.execute = do_alphaover_effect; - break; - case SEQ_OVERDROP: - rval.execute = do_overdrop_effect; - break; - case SEQ_ALPHAUNDER: - rval.init = init_alpha_over_or_under; - rval.execute = do_alphaunder_effect; - break; - case SEQ_WIPE: - rval.init = init_wipe_effect; - rval.num_inputs = num_inputs_wipe; - rval.free = free_wipe_effect; - rval.copy = copy_wipe_effect; - rval.early_out = early_out_fade; - rval.get_default_fac = get_default_fac_fade; - rval.execute = do_wipe_effect; - break; - case SEQ_GLOW: - rval.init = init_glow_effect; - rval.num_inputs = num_inputs_glow; - rval.free = free_glow_effect; - rval.copy = copy_glow_effect; - rval.execute = do_glow_effect; - break; - case SEQ_TRANSFORM: - rval.init = init_transform_effect; - rval.num_inputs = num_inputs_transform; - rval.free = free_transform_effect; - rval.copy = copy_transform_effect; - rval.execute = do_transform_effect; - break; - case SEQ_SPEED: - rval.init = init_speed_effect; - rval.num_inputs = num_inputs_speed; - rval.load = load_speed_effect; - rval.free = free_speed_effect; - rval.copy = copy_speed_effect; - rval.execute = do_cross_effect; - rval.early_out = early_out_speed; - rval.store_icu_yrange = store_icu_yrange_speed; - break; - case SEQ_COLOR: - rval.init = init_solid_color; - rval.num_inputs = num_inputs_color; - rval.early_out = early_out_color; - rval.free = free_solid_color; - rval.copy = copy_solid_color; - rval.execute = do_solid_color; - break; - case SEQ_PLUGIN: - rval.init_plugin = init_plugin; - rval.num_inputs = num_inputs_plugin; - rval.load = load_plugin; - rval.free = free_plugin; - rval.copy = copy_plugin; - rval.execute = do_plugin_effect; - rval.early_out = do_plugin_early_out; - rval.get_default_fac = get_default_fac_fade; - break; - case SEQ_MULTICAM: - rval.num_inputs = num_inputs_multicam; - rval.early_out = early_out_multicam; - rval.execute = do_multicam; - break; - case SEQ_ADJUSTMENT: - rval.num_inputs = num_inputs_adjustment; - rval.early_out = early_out_adjustment; - rval.execute = do_adjustment; - break; + case SEQ_CROSS: + rval.execute = do_cross_effect; + rval.early_out = early_out_fade; + rval.get_default_fac = get_default_fac_fade; + break; + case SEQ_GAMCROSS: + rval.init = init_gammacross; + rval.load = load_gammacross; + rval.free = free_gammacross; + rval.early_out = early_out_fade; + rval.get_default_fac = get_default_fac_fade; + rval.execute = do_gammacross_effect; + break; + case SEQ_ADD: + rval.execute = do_add_effect; + rval.early_out = early_out_mul_input2; + break; + case SEQ_SUB: + rval.execute = do_sub_effect; + rval.early_out = early_out_mul_input2; + break; + case SEQ_MUL: + rval.execute = do_mul_effect; + rval.early_out = early_out_mul_input2; + break; + case SEQ_ALPHAOVER: + rval.init = init_alpha_over_or_under; + rval.execute = do_alphaover_effect; + break; + case SEQ_OVERDROP: + rval.execute = do_overdrop_effect; + break; + case SEQ_ALPHAUNDER: + rval.init = init_alpha_over_or_under; + rval.execute = do_alphaunder_effect; + break; + case SEQ_WIPE: + rval.init = init_wipe_effect; + rval.num_inputs = num_inputs_wipe; + rval.free = free_wipe_effect; + rval.copy = copy_wipe_effect; + rval.early_out = early_out_fade; + rval.get_default_fac = get_default_fac_fade; + rval.execute = do_wipe_effect; + break; + case SEQ_GLOW: + rval.init = init_glow_effect; + rval.num_inputs = num_inputs_glow; + rval.free = free_glow_effect; + rval.copy = copy_glow_effect; + rval.execute = do_glow_effect; + break; + case SEQ_TRANSFORM: + rval.init = init_transform_effect; + rval.num_inputs = num_inputs_transform; + rval.free = free_transform_effect; + rval.copy = copy_transform_effect; + rval.execute = do_transform_effect; + break; + case SEQ_SPEED: + rval.init = init_speed_effect; + rval.num_inputs = num_inputs_speed; + rval.load = load_speed_effect; + rval.free = free_speed_effect; + rval.copy = copy_speed_effect; + rval.execute = do_cross_effect; + rval.early_out = early_out_speed; + rval.store_icu_yrange = store_icu_yrange_speed; + break; + case SEQ_COLOR: + rval.init = init_solid_color; + rval.num_inputs = num_inputs_color; + rval.early_out = early_out_color; + rval.free = free_solid_color; + rval.copy = copy_solid_color; + rval.execute = do_solid_color; + break; + case SEQ_PLUGIN: + rval.init_plugin = init_plugin; + rval.num_inputs = num_inputs_plugin; + rval.load = load_plugin; + rval.free = free_plugin; + rval.copy = copy_plugin; + rval.execute = do_plugin_effect; + rval.early_out = do_plugin_early_out; + rval.get_default_fac = get_default_fac_fade; + break; + case SEQ_MULTICAM: + rval.num_inputs = num_inputs_multicam; + rval.early_out = early_out_multicam; + rval.execute = do_multicam; + break; + case SEQ_ADJUSTMENT: + rval.num_inputs = num_inputs_adjustment; + rval.early_out = early_out_adjustment; + rval.execute = do_adjustment; + break; } return rval; } -struct SeqEffectHandle get_sequence_effect(Sequence * seq) +struct SeqEffectHandle get_sequence_effect(Sequence *seq) { - struct SeqEffectHandle rval= {NULL}; + struct SeqEffectHandle rval = {NULL}; if (seq->type & SEQ_EFFECT) { rval = get_sequence_effect_impl(seq->type); @@ -3398,9 +3384,9 @@ struct SeqEffectHandle get_sequence_effect(Sequence * seq) return rval; } -struct SeqEffectHandle get_sequence_blend(Sequence * seq) +struct SeqEffectHandle get_sequence_blend(Sequence *seq) { - struct SeqEffectHandle rval= {NULL}; + struct SeqEffectHandle rval = {NULL}; if (seq->blend_mode != 0) { rval = get_sequence_effect_impl(seq->blend_mode); diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 395214b1609..41858eeecb4 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -216,13 +216,10 @@ void seq_free_sequence_recurse(Scene *scene, Sequence *seq) } -Editing *seq_give_editing(Scene *scene, int alloc) +Editing *BKE_sequencer_editing_get(Scene *scene, int alloc) { - if (scene->ed == NULL && alloc) { - Editing *ed; - - ed = scene->ed = MEM_callocN(sizeof(Editing), "addseq"); - ed->seqbasep = &ed->seqbase; + if (alloc) { + BKE_sequencer_editing_ensure(scene); } return scene->ed; } @@ -250,7 +247,19 @@ void seq_free_clipboard(void) seqbase_clipboard.first = seqbase_clipboard.last = NULL; } -void seq_free_editing(Scene *scene) +Editing *BKE_sequencer_editing_ensure(Scene *scene) +{ + if (scene->ed == NULL) { + Editing *ed; + + ed = scene->ed = MEM_callocN(sizeof(Editing), "addseq"); + ed->seqbasep = &ed->seqbase; + } + + return scene->ed; +} + +void BKE_sequencer_editing_free(Scene *scene) { Editing *ed = scene->ed; MetaStack *ms; @@ -271,6 +280,8 @@ void seq_free_editing(Scene *scene) } MEM_freeN(ed); + + scene->ed = NULL; } /* ********************************************************************** @@ -754,11 +765,11 @@ void reload_sequence_new_file(Scene *scene, Sequence *seq, int lock_range) calc_sequence(scene, seq); } -void sort_seq(Scene *scene) +void BKE_sequencer_sort(Scene *scene) { /* all strips together per kind, and in order of y location ("machine") */ ListBase seqbase, effbase; - Editing *ed = seq_give_editing(scene, FALSE); + Editing *ed = BKE_sequencer_editing_get(scene, FALSE); Sequence *seq, *seqt; @@ -1075,7 +1086,7 @@ static int evaluate_seq_frame_gen(Sequence **seq_arr, ListBase *seqbase, int cfr int evaluate_seq_frame(Scene *scene, int cfra) { - Editing *ed = seq_give_editing(scene, FALSE); + Editing *ed = BKE_sequencer_editing_get(scene, FALSE); Sequence *seq_arr[MAXSEQ + 1]; if (ed == NULL) return 0; @@ -2099,7 +2110,7 @@ static ImBuf *seq_render_scene_strip( if (seq->scene_camera) camera = seq->scene_camera; else { - scene_camera_switch_update(scene); + BKE_scene_camera_switch_update(scene); camera = scene->camera; } @@ -2127,7 +2138,7 @@ static ImBuf *seq_render_scene_strip( context.scene->r.seq_prev_type = 3 /* ==OB_SOLID */; /* opengl offscreen render */ - scene_update_for_newframe(context.bmain, scene, scene->lay); + BKE_scene_update_for_newframe(context.bmain, scene, scene->lay); ibuf = sequencer_view3d_cb(scene, camera, context.rectx, context.recty, IB_rect, context.scene->r.seq_prev_type, TRUE, err_out); if (ibuf == NULL) { @@ -2182,7 +2193,7 @@ static ImBuf *seq_render_scene_strip( scene->r.cfra = oldcfra; if (frame != oldcfra) - scene_update_for_newframe(context.bmain, scene, scene->lay); + BKE_scene_update_for_newframe(context.bmain, scene, scene->lay); #ifdef DURIAN_CAMERA_SWITCH /* stooping to new low's in hackyness :( */ @@ -2530,7 +2541,7 @@ static ImBuf *seq_render_strip_stack( ImBuf *give_ibuf_seq(SeqRenderData context, float cfra, int chanshown) { - Editing *ed = seq_give_editing(context.scene, FALSE); + Editing *ed = BKE_sequencer_editing_get(context.scene, FALSE); int count; ListBase *seqbasep; @@ -3007,7 +3018,7 @@ static int update_changed_seq_recurs(Scene *scene, Sequence *seq, Sequence *chan void update_changed_seq_and_deps(Scene *scene, Sequence *changed_seq, int len_change, int ibuf_change) { - Editing *ed = seq_give_editing(scene, FALSE); + Editing *ed = BKE_sequencer_editing_get(scene, FALSE); Sequence *seq; if (ed == NULL) return; @@ -3254,7 +3265,7 @@ void seq_sound_init(Scene *scene, Sequence *seq) Sequence *seq_foreground_frame_get(Scene *scene, int frame) { - Editing *ed = seq_give_editing(scene, FALSE); + Editing *ed = BKE_sequencer_editing_get(scene, FALSE); Sequence *seq, *best_seq = NULL; int best_machine = -1; @@ -3660,26 +3671,26 @@ Sequence *get_seq_by_name(ListBase *seqbase, const char *name, int recursive) } -Sequence *seq_active_get(Scene *scene) +Sequence *BKE_sequencer_active_get(Scene *scene) { - Editing *ed = seq_give_editing(scene, FALSE); + Editing *ed = BKE_sequencer_editing_get(scene, FALSE); if (ed == NULL) return NULL; return ed->act_seq; } -void seq_active_set(Scene *scene, Sequence *seq) +void BKE_sequencer_active_set(Scene *scene, Sequence *seq) { - Editing *ed = seq_give_editing(scene, FALSE); + Editing *ed = BKE_sequencer_editing_get(scene, FALSE); if (ed == NULL) return; ed->act_seq = seq; } -int seq_active_pair_get(Scene *scene, Sequence **seq_act, Sequence **seq_other) +int BKE_sequencer_active_get_pair(Scene *scene, Sequence **seq_act, Sequence **seq_other) { - Editing *ed = seq_give_editing(scene, FALSE); + Editing *ed = BKE_sequencer_editing_get(scene, FALSE); - *seq_act = seq_active_get(scene); + *seq_act = BKE_sequencer_active_get(scene); if (*seq_act == NULL) { return 0; @@ -3718,7 +3729,7 @@ void seq_load_apply(Scene *scene, Sequence *seq, SeqLoadInfo *seq_load) if (seq_load->flag & SEQ_LOAD_REPLACE_SEL) { seq_load->flag |= SELECT; - seq_active_set(scene, seq); + BKE_sequencer_active_set(scene, seq); } if (seq_load->flag & SEQ_LOAD_SOUND_CACHE) { @@ -3785,7 +3796,7 @@ Sequence *sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); /* only for sound */ - Editing *ed = seq_give_editing(scene, TRUE); + Editing *ed = BKE_sequencer_editing_get(scene, TRUE); bSound *sound; Sequence *seq; /* generic strip vars */ @@ -3934,8 +3945,7 @@ static Sequence *seq_dupli(struct Scene *scene, struct Scene *scene_to, Sequence } if (seq->strip->color_balance) { - seqn->strip->color_balance - = MEM_dupallocN(seq->strip->color_balance); + seqn->strip->color_balance = MEM_dupallocN(seq->strip->color_balance); } if (seq->type == SEQ_META) { @@ -4016,7 +4026,7 @@ void seqbase_dupli_recursive(Scene *scene, Scene *scene_to, ListBase *nseqbase, { Sequence *seq; Sequence *seqn = NULL; - Sequence *last_seq = seq_active_get(scene); + Sequence *last_seq = BKE_sequencer_active_get(scene); for (seq = seqbase->first; seq; seq = seq->next) { seq->tmp = NULL; @@ -4034,7 +4044,7 @@ void seqbase_dupli_recursive(Scene *scene, Scene *scene_to, ListBase *nseqbase, if (dupe_flag & SEQ_DUPE_CONTEXT) { if (seq == last_seq) { - seq_active_set(scene, seqn); + BKE_sequencer_active_set(scene, seqn); } } } diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index d6fea87397d..6c1c18c7cf8 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -57,7 +57,7 @@ #include "BKE_tessmesh.h" /* Util macros */ -#define OUT_OF_MEMORY() ((void)printf("Shrinkwrap: Out of memory\n")) +#define OUT_OF_MEMORY() ((void)printf("Shrinkwrap: Out of memory\n")) /* Benchmark macros */ #if !defined(_WIN32) && 0 @@ -79,17 +79,17 @@ #else -#define BENCH(a) (a) +#define BENCH(a) (a) #endif -typedef void ( *Shrinkwrap_ForeachVertexCallback) (DerivedMesh *target, float *co, float *normal); +typedef void (*Shrinkwrap_ForeachVertexCallback)(DerivedMesh *target, float *co, float *normal); /* get derived mesh */ //TODO is anyfunction that does this? returning the derivedFinal without we caring if its in edit mode or not? DerivedMesh *object_get_derived_final(Object *ob) { - Mesh *me= ob->data; + Mesh *me = ob->data; BMEditMesh *em = me->edit_btmesh; if (em) { @@ -111,12 +111,12 @@ void space_transform_from_matrixs(SpaceTransform *data, float local[4][4], float void space_transform_apply(const SpaceTransform *data, float *co) { - mul_v3_m4v3(co, ((SpaceTransform*)data)->local2target, co); + mul_v3_m4v3(co, ((SpaceTransform *)data)->local2target, co); } void space_transform_invert(const SpaceTransform *data, float *co) { - mul_v3_m4v3(co, ((SpaceTransform*)data)->target2local, co); + mul_v3_m4v3(co, ((SpaceTransform *)data)->target2local, co); } static void space_transform_apply_normal(const SpaceTransform *data, float *no) @@ -127,7 +127,7 @@ static void space_transform_apply_normal(const SpaceTransform *data, float *no) static void space_transform_invert_normal(const SpaceTransform *data, float *no) { - mul_mat3_m4_v3(((SpaceTransform*)data)->target2local, no); + mul_mat3_m4_v3(((SpaceTransform *)data)->target2local, no); normalize_v3(no); // TODO: could we just determine de scale value from the matrix? } @@ -142,7 +142,7 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) int i; BVHTreeFromMesh treeData = NULL_BVHTreeFromMesh; - BVHTreeNearest nearest = NULL_BVHTreeNearest; + BVHTreeNearest nearest = NULL_BVHTreeNearest; BENCH(bvhtree_from_mesh_verts(&treeData, calc->target, 0.0, 2, 6)); @@ -157,7 +157,7 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) #ifndef __APPLE__ #pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(treeData,calc) schedule(static) #endif - for (i = 0; i<calc->numVerts; ++i) { + for (i = 0; i < calc->numVerts; ++i) { float *co = calc->vertexCos[i]; float tmp_co[3]; float weight = defvert_array_find_weight_safe(calc->dvert, i, calc->vgroup); @@ -190,13 +190,13 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) if (nearest.index != -1) { //Adjusting the vertex weight, so that after interpolating it keeps a certain distance from the nearest position float dist = sasqrt(nearest.dist); - if (dist > FLT_EPSILON) weight *= (dist - calc->keepDist)/dist; + if (dist > FLT_EPSILON) weight *= (dist - calc->keepDist) / dist; //Convert the coordinates back to mesh coordinates copy_v3_v3(tmp_co, nearest.co); space_transform_invert(&calc->local2target, tmp_co); - interp_v3_v3v3(co, co, tmp_co, weight); //linear interpolation + interp_v3_v3v3(co, co, tmp_co, weight); //linear interpolation } } @@ -230,7 +230,7 @@ int normal_projection_project_vertex(char options, const float *vert, const floa space_transform_apply_normal(transf, tmp_no); no = tmp_no; - hit_tmp.dist *= mat4_to_scale(((SpaceTransform*)transf)->local2target); + hit_tmp.dist *= mat4_to_scale(((SpaceTransform *)transf)->local2target); } else { co = vert; @@ -247,12 +247,12 @@ int normal_projection_project_vertex(char options, const float *vert, const floa space_transform_invert_normal(transf, hit_tmp.no); } - if (options & (MOD_SHRINKWRAP_CULL_TARGET_FRONTFACE|MOD_SHRINKWRAP_CULL_TARGET_BACKFACE)) { + if (options & (MOD_SHRINKWRAP_CULL_TARGET_FRONTFACE | MOD_SHRINKWRAP_CULL_TARGET_BACKFACE)) { /* apply backface */ - const float dot= dot_v3v3(dir, hit_tmp.no); - if ( ((options & MOD_SHRINKWRAP_CULL_TARGET_FRONTFACE) && dot <= 0.0f) || - ((options & MOD_SHRINKWRAP_CULL_TARGET_BACKFACE) && dot >= 0.0f) - ) { + const float dot = dot_v3v3(dir, hit_tmp.no); + if (((options & MOD_SHRINKWRAP_CULL_TARGET_FRONTFACE) && dot <= 0.0f) || + ((options & MOD_SHRINKWRAP_CULL_TARGET_BACKFACE) && dot >= 0.0f)) + { return FALSE; /* Ignore hit */ } } @@ -275,16 +275,16 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc) int i; //Options about projection direction - const char use_normal = calc->smd->shrinkOpts; - float proj_axis[3] = {0.0f, 0.0f, 0.0f}; + const char use_normal = calc->smd->shrinkOpts; + float proj_axis[3] = {0.0f, 0.0f, 0.0f}; //Raycast and tree stuff BVHTreeRayHit hit; - BVHTreeFromMesh treeData= NULL_BVHTreeFromMesh; + BVHTreeFromMesh treeData = NULL_BVHTreeFromMesh; //auxiliary target - DerivedMesh *auxMesh = NULL; - BVHTreeFromMesh auxData = NULL_BVHTreeFromMesh; + DerivedMesh *auxMesh = NULL; + BVHTreeFromMesh auxData = NULL_BVHTreeFromMesh; SpaceTransform local2aux; //If the user doesn't allows to project in any direction of projection axis @@ -326,7 +326,7 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc) #ifndef __APPLE__ #pragma omp parallel for private(i,hit) schedule(static) #endif - for (i = 0; i<calc->numVerts; ++i) { + for (i = 0; i < calc->numVerts; ++i) { float *co = calc->vertexCos[i]; float tmp_co[3], tmp_no[3]; float weight = defvert_array_find_weight_safe(calc->dvert, i, calc->vgroup); @@ -399,10 +399,10 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) int i; BVHTreeFromMesh treeData = NULL_BVHTreeFromMesh; - BVHTreeNearest nearest = NULL_BVHTreeNearest; + BVHTreeNearest nearest = NULL_BVHTreeNearest; //Create a bvh-tree of the given target - BENCH(bvhtree_from_mesh_faces( &treeData, calc->target, 0.0, 2, 6)); + BENCH(bvhtree_from_mesh_faces(&treeData, calc->target, 0.0, 2, 6)); if (treeData.tree == NULL) { OUT_OF_MEMORY(); return; @@ -417,7 +417,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) #ifndef __APPLE__ #pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(calc,treeData) schedule(static) #endif - for (i = 0; i<calc->numVerts; ++i) { + for (i = 0; i < calc->numVerts; ++i) { float *co = calc->vertexCos[i]; float tmp_co[3]; float weight = defvert_array_find_weight_safe(calc->dvert, i, calc->vgroup); @@ -452,16 +452,16 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) } else { //Adjusting the vertex weight, so that after interpolating it keeps a certain distance from the nearest position - float dist = sasqrt( nearest.dist ); + float dist = sasqrt(nearest.dist); if (dist > FLT_EPSILON) - interp_v3_v3v3(tmp_co, tmp_co, nearest.co, (dist - calc->keepDist)/dist); //linear interpolation + interp_v3_v3v3(tmp_co, tmp_co, nearest.co, (dist - calc->keepDist) / dist); //linear interpolation else copy_v3_v3(tmp_co, nearest.co); } //Convert the coordinates back to mesh coordinates space_transform_invert(&calc->local2target, tmp_co); - interp_v3_v3v3(co, co, tmp_co, weight); //linear interpolation + interp_v3_v3v3(co, co, tmp_co, weight); //linear interpolation } } @@ -472,7 +472,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedMesh *dm, float (*vertexCos)[3], int numVerts) { - DerivedMesh *ss_mesh = NULL; + DerivedMesh *ss_mesh = NULL; ShrinkwrapCalcData calc = NULL_ShrinkwrapCalcData; //remove loop dependencies on derived meshs (TODO should this be done elsewhere?) @@ -492,7 +492,7 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM calc.dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); } else if (calc.ob->type == OB_LATTICE) { - calc.dvert = lattice_get_deform_verts(calc.ob); + calc.dvert = BKE_lattice_deform_verts_get(calc.ob); } @@ -519,11 +519,11 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM //Using vertexs positions/normals as if a subsurface was applied if (smd->subsurfLevels) { - SubsurfModifierData ssmd= {{NULL}}; - ssmd.subdivType = ME_CC_SUBSURF; //catmull clark - ssmd.levels = smd->subsurfLevels; //levels + SubsurfModifierData ssmd = {{NULL}}; + ssmd.subdivType = ME_CC_SUBSURF; //catmull clark + ssmd.levels = smd->subsurfLevels; //levels - ss_mesh = subsurf_make_derived_from_derived(dm, &ssmd, FALSE, NULL, 0, 0, (ob->mode & OB_MODE_EDIT)); + ss_mesh = subsurf_make_derived_from_derived(dm, &ssmd, NULL, (ob->mode & OB_MODE_EDIT) ? SUBSURF_IN_EDIT_MODE : 0); if (ss_mesh) { calc.vert = ss_mesh->getVertDataArray(ss_mesh, CD_MVERT); @@ -545,15 +545,15 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM switch (smd->shrinkType) { case MOD_SHRINKWRAP_NEAREST_SURFACE: BENCH(shrinkwrap_calc_nearest_surface_point(&calc)); - break; + break; case MOD_SHRINKWRAP_PROJECT: BENCH(shrinkwrap_calc_normal_projection(&calc)); - break; + break; case MOD_SHRINKWRAP_NEAREST_VERTEX: BENCH(shrinkwrap_calc_nearest_vertex(&calc)); - break; + break; } } diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index f98b6366e97..4b814a5b22b 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -279,29 +279,6 @@ static int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, smd->time = scene->r.cfra; - if (smd->flow->psys && smd->flow->psys->part && !(smd->flow->flags & MOD_SMOKE_FLOW_INIT)) - { - // update particle lifetime to be one frame - smd->flow->psys->part->lifetime = 1; // scene->r.efra + 1; - - // use "unborn" flag as standard setting - smd->flow->psys->part->flag |= PART_UNBORN; - - smd->flow->flags |= MOD_SMOKE_FLOW_INIT; - } - -/* - if(!smd->flow->bvh) - { - // smd->flow->bvh = MEM_callocN(sizeof(BVHTreeFromMesh), "smoke_bvhfromfaces"); - // bvhtree_from_mesh_faces(smd->flow->bvh, dm, 0.0, 2, 6); - - // copy obmat - // copy_m4_m4(smd->flow->mat, ob->obmat); - // copy_m4_m4(smd->flow->mat_old, ob->obmat); - } -*/ - return 1; } else if((smd->type & MOD_SMOKE_TYPE_COLL)) diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 690b6c83870..ee70d4228de 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -3514,11 +3514,11 @@ static void lattice_to_softbody(Scene *scene, Object *ob) totvert= lt->pntsu*lt->pntsv*lt->pntsw; if (ob->softflag & OB_SB_EDGES) { - totspring = ((lt->pntsu -1) * lt->pntsv - + (lt->pntsv -1) * lt->pntsu) * lt->pntsw - +lt->pntsu*lt->pntsv*(lt->pntsw -1); + totspring = ((lt->pntsu - 1) * lt->pntsv + + (lt->pntsv - 1) * lt->pntsu) * lt->pntsw + + lt->pntsu*lt->pntsv * (lt->pntsw - 1); if (ob->softflag & OB_SB_QUADS) { - totspring += 4*(lt->pntsu -1) * (lt->pntsv -1) * (lt->pntsw-1); + totspring += 4 * (lt->pntsu - 1) * (lt->pntsv -1) * (lt->pntsw - 1); } } diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 28ce95ea8d1..52007f1f43e 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -63,16 +63,16 @@ // evil quiet NaN definition static const int NAN_INT = 0x7FC00000; -#define NAN_FLT *((float*)(&NAN_INT)) +#define NAN_FLT *((float *)(&NAN_INT)) #ifdef WITH_AUDASPACE // evil global ;-) static int sound_cfra; #endif -struct bSound* sound_new_file(struct Main *bmain, const char *filename) +bSound *sound_new_file(struct Main *bmain, const char *filename) { - bSound* sound = NULL; + bSound *sound = NULL; char str[FILE_MAX]; char *path; @@ -86,24 +86,24 @@ struct bSound* sound_new_file(struct Main *bmain, const char *filename) BLI_path_abs(str, path); len = strlen(filename); - while (len > 0 && filename[len-1] != '/' && filename[len-1] != '\\') + while (len > 0 && filename[len - 1] != '/' && filename[len - 1] != '\\') len--; - sound = alloc_libblock(&bmain->sound, ID_SO, filename+len); + sound = BKE_libblock_alloc(&bmain->sound, ID_SO, filename + len); BLI_strncpy(sound->name, filename, FILE_MAX); // XXX unused currently sound->type = SOUND_TYPE_FILE; sound_load(bmain, sound); if (!sound->playback_handle) { - free_libblock(&bmain->sound, sound); + BKE_libblock_free(&bmain->sound, sound); sound = NULL; } return sound; } -void sound_free(struct bSound* sound) +void BKE_sound_free(bSound *sound) { if (sound->packedfile) { freePackedFile(sound->packedfile); @@ -131,10 +131,10 @@ void sound_free(struct bSound* sound) static int force_device = -1; #ifdef WITH_JACK -static void sound_sync_callback(void* data, int mode, float time) +static void sound_sync_callback(void *data, int mode, float time) { - struct Main* bmain = (struct Main*)data; - struct Scene* scene; + struct Main *bmain = (struct Main *)data; + struct Scene *scene; scene = bmain->scene.first; while (scene) { @@ -223,15 +223,15 @@ void sound_exit(void) // XXX unused currently #if 0 -struct bSound* sound_new_buffer(struct Main *bmain, struct bSound *source) +bSound *sound_new_buffer(struct Main *bmain, bSound *source) { - bSound* sound = NULL; + bSound *sound = NULL; - char name[MAX_ID_NAME+5]; + char name[MAX_ID_NAME + 5]; strcpy(name, "buf_"); strcpy(name + 4, source->id.name); - sound = alloc_libblock(&bmain->sound, ID_SO, name); + sound = BKE_libblock_alloc(&bmain->sound, ID_SO, name); sound->child_sound = source; sound->type = SOUND_TYPE_BUFFER; @@ -240,22 +240,22 @@ struct bSound* sound_new_buffer(struct Main *bmain, struct bSound *source) if (!sound->playback_handle) { - free_libblock(&bmain->sound, sound); + BKE_libblock_free(&bmain->sound, sound); sound = NULL; } return sound; } -struct bSound* sound_new_limiter(struct Main *bmain, struct bSound *source, float start, float end) +bSound *sound_new_limiter(struct Main *bmain, bSound *source, float start, float end) { - bSound* sound = NULL; + bSound *sound = NULL; - char name[MAX_ID_NAME+5]; + char name[MAX_ID_NAME + 5]; strcpy(name, "lim_"); strcpy(name + 4, source->id.name); - sound = alloc_libblock(&bmain->sound, ID_SO, name); + sound = BKE_libblock_alloc(&bmain->sound, ID_SO, name); sound->child_sound = source; sound->start = start; @@ -266,7 +266,7 @@ struct bSound* sound_new_limiter(struct Main *bmain, struct bSound *source, floa if (!sound->playback_handle) { - free_libblock(&bmain->sound, sound); + BKE_libblock_free(&bmain->sound, sound); sound = NULL; } @@ -274,16 +274,16 @@ struct bSound* sound_new_limiter(struct Main *bmain, struct bSound *source, floa } #endif -void sound_delete(struct Main *bmain, struct bSound* sound) +void sound_delete(struct Main *bmain, bSound *sound) { if (sound) { - sound_free(sound); + BKE_sound_free(sound); - free_libblock(&bmain->sound, sound); + BKE_libblock_free(&bmain->sound, sound); } } -void sound_cache(struct bSound* sound) +void sound_cache(bSound *sound) { sound->flags |= SOUND_FLAGS_CACHING; if (sound->cache) @@ -296,13 +296,13 @@ void sound_cache(struct bSound* sound) sound->playback_handle = sound->handle; } -void sound_cache_notifying(struct Main* main, struct bSound* sound) +void sound_cache_notifying(struct Main *main, bSound *sound) { sound_cache(sound); sound_update_sequencer(main, sound); } -void sound_delete_cache(struct bSound* sound) +void sound_delete_cache(bSound *sound) { sound->flags &= ~SOUND_FLAGS_CACHING; if (sound->cache) { @@ -312,7 +312,7 @@ void sound_delete_cache(struct bSound* sound) } } -void sound_load(struct Main *bmain, struct bSound* sound) +void sound_load(struct Main *bmain, bSound *sound) { if (sound) { if (sound->cache) { @@ -332,13 +332,13 @@ void sound_load(struct Main *bmain, struct bSound* sound) #if 0 switch (sound->type) { - case SOUND_TYPE_FILE: + case SOUND_TYPE_FILE: #endif { char fullpath[FILE_MAX]; /* load sound */ - PackedFile* pf = sound->packedfile; + PackedFile *pf = sound->packedfile; /* don't modify soundact->sound->name, only change a copy */ BLI_strncpy(fullpath, sound->name, sizeof(fullpath)); @@ -346,27 +346,27 @@ void sound_load(struct Main *bmain, struct bSound* sound) /* but we need a packed file then */ if (pf) - sound->handle = AUD_loadBuffer((unsigned char*) pf->data, pf->size); + sound->handle = AUD_loadBuffer((unsigned char *) pf->data, pf->size); /* or else load it from disk */ else sound->handle = AUD_load(fullpath); } // XXX unused currently #if 0 - break; - } - case SOUND_TYPE_BUFFER: - if (sound->child_sound && sound->child_sound->handle) - sound->handle = AUD_bufferSound(sound->child_sound->handle); - break; - case SOUND_TYPE_LIMITER: - if (sound->child_sound && sound->child_sound->handle) - sound->handle = AUD_limitSound(sound->child_sound, sound->start, sound->end); - break; - } + break; + } + case SOUND_TYPE_BUFFER: + if (sound->child_sound && sound->child_sound->handle) + sound->handle = AUD_bufferSound(sound->child_sound->handle); + break; + case SOUND_TYPE_LIMITER: + if (sound->child_sound && sound->child_sound->handle) + sound->handle = AUD_limitSound(sound->child_sound, sound->start, sound->end); + break; +} #endif if (sound->flags & SOUND_FLAGS_MONO) { - void* handle = AUD_monoSound(sound->handle); + void *handle = AUD_monoSound(sound->handle); AUD_unload(sound->handle); sound->handle = handle; } @@ -384,16 +384,20 @@ void sound_load(struct Main *bmain, struct bSound* sound) } } -AUD_Device* sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, float volume) +AUD_Device *sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, float volume) { return AUD_openMixdownDevice(specs, scene->sound_scene, volume, start / FPS); } void sound_create_scene(struct Scene *scene) { + /* should be done in version patch, but this gets called before */ + if (scene->r.frs_sec_base == 0) + scene->r.frs_sec_base = 1; + scene->sound_scene = AUD_createSequencer(FPS, scene->audio.flag & AUDIO_MUTE); AUD_updateSequencerData(scene->sound_scene, scene->audio.speed_of_sound, - scene->audio.doppler_factor, scene->audio.distance_model); + scene->audio.doppler_factor, scene->audio.distance_model); scene->sound_scene_handle = NULL; scene->sound_scrub_handle = NULL; scene->speaker_handles = NULL; @@ -426,26 +430,26 @@ void sound_update_fps(struct Scene *scene) void sound_update_scene_listener(struct Scene *scene) { AUD_updateSequencerData(scene->sound_scene, scene->audio.speed_of_sound, - scene->audio.doppler_factor, scene->audio.distance_model); + scene->audio.doppler_factor, scene->audio.distance_model); } -void* sound_scene_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip) +void *sound_scene_add_scene_sound(struct Scene *scene, struct Sequence *sequence, int startframe, int endframe, int frameskip) { if (scene != sequence->scene) return AUD_addSequence(scene->sound_scene, sequence->scene->sound_scene, startframe / FPS, endframe / FPS, frameskip / FPS); return NULL; } -void* sound_scene_add_scene_sound_defaults(struct Scene *scene, struct Sequence* sequence) +void *sound_scene_add_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence) { return sound_scene_add_scene_sound(scene, sequence, sequence->startdisp, sequence->enddisp, sequence->startofs + sequence->anim_startofs); } -void* sound_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) { - void* handle = AUD_addSequence(scene->sound_scene, sequence->sound->playback_handle, startframe / FPS, endframe / FPS, frameskip / FPS); + void *handle = AUD_addSequence(scene->sound_scene, sequence->sound->playback_handle, startframe / FPS, endframe / FPS, frameskip / FPS); AUD_muteSequence(handle, (sequence->flag & SEQ_MUTE) != 0); AUD_setSequenceAnimData(handle, AUD_AP_VOLUME, CFRA, &sequence->volume, 0); AUD_setSequenceAnimData(handle, AUD_AP_PITCH, CFRA, &sequence->pitch, 0); @@ -453,29 +457,29 @@ void* sound_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int return handle; } -void* sound_add_scene_sound_defaults(struct Scene *scene, struct Sequence* sequence) +void *sound_add_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence) { return sound_add_scene_sound(scene, sequence, sequence->startdisp, sequence->enddisp, sequence->startofs + sequence->anim_startofs); } -void sound_remove_scene_sound(struct Scene *scene, void* handle) +void sound_remove_scene_sound(struct Scene *scene, void *handle) { AUD_removeSequence(scene->sound_scene, handle); } -void sound_mute_scene_sound(void* handle, char mute) +void sound_mute_scene_sound(void *handle, char mute) { AUD_muteSequence(handle, mute); } -void sound_move_scene_sound(struct Scene *scene, void* handle, int startframe, int endframe, int frameskip) +void sound_move_scene_sound(struct Scene *scene, void *handle, int startframe, int endframe, int frameskip) { AUD_moveSequence(handle, startframe / FPS, endframe / FPS, frameskip / FPS); } -void sound_move_scene_sound_defaults(struct Scene *scene, struct Sequence* sequence) +void sound_move_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence) { if (sequence->scene_sound) { sound_move_scene_sound(scene, sequence->scene_sound, @@ -484,7 +488,7 @@ void sound_move_scene_sound_defaults(struct Scene *scene, struct Sequence* seque } } -void sound_update_scene_sound(void* handle, struct bSound* sound) +void sound_update_scene_sound(void *handle, bSound *sound) { AUD_updateSequenceSound(handle, sound->playback_handle); } @@ -499,24 +503,24 @@ void sound_set_scene_volume(struct Scene *scene, float volume) AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_VOLUME, CFRA, &volume, (scene->audio.flag & AUDIO_VOLUME_ANIMATED) != 0); } -void sound_set_scene_sound_volume(void* handle, float volume, char animated) +void sound_set_scene_sound_volume(void *handle, float volume, char animated) { AUD_setSequenceAnimData(handle, AUD_AP_VOLUME, sound_cfra, &volume, animated); } -void sound_set_scene_sound_pitch(void* handle, float pitch, char animated) +void sound_set_scene_sound_pitch(void *handle, float pitch, char animated) { AUD_setSequenceAnimData(handle, AUD_AP_PITCH, sound_cfra, &pitch, animated); } -void sound_set_scene_sound_pan(void* handle, float pan, char animated) +void sound_set_scene_sound_pan(void *handle, float pan, char animated) { AUD_setSequenceAnimData(handle, AUD_AP_PANNING, sound_cfra, &pan, animated); } -void sound_update_sequencer(struct Main* main, struct bSound* sound) +void sound_update_sequencer(struct Main *main, bSound *sound) { - struct Scene* scene; + struct Scene *scene; for (scene = main->scene.first; scene; scene = scene->id.next) { seq_update_sound(scene, sound); @@ -592,7 +596,7 @@ void sound_seek_scene(struct Main *bmain, struct Scene *scene) } animation_playing = 0; - for (screen=bmain->screen.first; screen; screen=screen->id.next) { + for (screen = bmain->screen.first; screen; screen = screen->id.next) { if (screen->animtimer) { animation_playing = 1; } @@ -645,24 +649,24 @@ int sound_scene_playing(struct Scene *scene) return -1; } -void sound_free_waveform(struct bSound* sound) +void sound_free_waveform(bSound *sound) { if (sound->waveform) { - MEM_freeN(((SoundWaveform*)sound->waveform)->data); + MEM_freeN(((SoundWaveform *)sound->waveform)->data); MEM_freeN(sound->waveform); } sound->waveform = NULL; } -void sound_read_waveform(struct bSound* sound) +void sound_read_waveform(bSound *sound) { AUD_SoundInfo info; info = AUD_getInfo(sound->playback_handle); if (info.length > 0) { - SoundWaveform* waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform"); + SoundWaveform *waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform"); int length = info.length * SOUND_WAVE_SAMPLES_PER_SECOND; waveform->data = MEM_mallocN(length * sizeof(float) * 3, "SoundWaveform.samples"); @@ -673,17 +677,17 @@ void sound_read_waveform(struct bSound* sound) } } -void sound_update_scene(struct Scene* scene) +void sound_update_scene(struct Scene *scene) { - Object* ob; - Base* base; - NlaTrack* track; - NlaStrip* strip; - Speaker* speaker; - Scene* sce_it; + Object *ob; + Base *base; + NlaTrack *track; + NlaStrip *strip; + Speaker *speaker; + Scene *sce_it; - void* new_set = AUD_createSet(); - void* handle; + void *new_set = AUD_createSet(); + void *handle; float quat[4]; for (SETLOOPER(scene, sce_it, base)) { @@ -693,7 +697,7 @@ void sound_update_scene(struct Scene* scene) for (track = ob->adt->nla_tracks.first; track; track = track->next) { for (strip = track->strips.first; strip; strip = strip->next) { if (strip->type == NLASTRIP_TYPE_SOUND) { - speaker = (Speaker*)ob->data; + speaker = (Speaker *)ob->data; if (AUD_removeSet(scene->speaker_handles, strip->speaker_handle)) { if (speaker->sound) @@ -713,10 +717,10 @@ void sound_update_scene(struct Scene* scene) if (strip->speaker_handle) { AUD_addSet(new_set, strip->speaker_handle); AUD_updateSequenceData(strip->speaker_handle, speaker->volume_max, - speaker->volume_min, speaker->distance_max, - speaker->distance_reference, speaker->attenuation, - speaker->cone_angle_outer, speaker->cone_angle_inner, - speaker->cone_volume_outer); + speaker->volume_min, speaker->distance_max, + speaker->distance_reference, speaker->attenuation, + speaker->cone_angle_outer, speaker->cone_angle_inner, + speaker->cone_volume_outer); mat4_to_quat(quat, ob->obmat); AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_LOCATION, CFRA, ob->obmat[3], 1); @@ -747,9 +751,17 @@ void sound_update_scene(struct Scene* scene) scene->speaker_handles = new_set; } -void* sound_get_factory(void* sound) +void *sound_get_factory(void *sound) { - return ((struct bSound*) sound)->playback_handle; + return ((bSound *) sound)->playback_handle; +} + +/* stupid wrapper because AUD_C-API.h includes Python.h which makesrna doesn't like */ +float sound_get_length(bSound *sound) +{ + AUD_SoundInfo info = AUD_getInfo(sound->playback_handle); + + return info.length; } #else // WITH_AUDASPACE @@ -793,5 +805,5 @@ void sound_set_scene_sound_volume(void* handle, float volume, char animated) { ( void sound_set_scene_sound_pan(void* handle, float pan, char animated) { (void)handle; (void)pan; (void)animated; } void sound_set_scene_volume(struct Scene *scene, float volume) { (void)scene; (void)volume; } void sound_set_scene_sound_pitch(void* handle, float pitch, char animated) { (void)handle; (void)pitch; (void)animated; } - +float sound_get_length(struct bSound* sound) { (void)sound; return 0; } #endif // WITH_AUDASPACE diff --git a/source/blender/blenkernel/intern/speaker.c b/source/blender/blenkernel/intern/speaker.c index 5466630f621..09440591826 100644 --- a/source/blender/blenkernel/intern/speaker.c +++ b/source/blender/blenkernel/intern/speaker.c @@ -43,11 +43,11 @@ #include "BKE_main.h" #include "BKE_speaker.h" -void *add_speaker(const char *name) +void *BKE_speaker_add(const char *name) { Speaker *spk; - spk= alloc_libblock(&G.main->speaker, ID_SPK, name); + spk = BKE_libblock_alloc(&G.main->speaker, ID_SPK, name); spk->attenuation = 1.0f; spk->cone_angle_inner = 360.0f; @@ -65,69 +65,69 @@ void *add_speaker(const char *name) return spk; } -Speaker *copy_speaker(Speaker *spk) +Speaker *BKE_speaker_copy(Speaker *spk) { Speaker *spkn; - spkn= copy_libblock(&spk->id); + spkn = BKE_libblock_copy(&spk->id); if (spkn->sound) spkn->sound->id.us++; return spkn; } -void make_local_speaker(Speaker *spk) +void BKE_speaker_make_local(Speaker *spk) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (spk->id.lib==NULL) return; - if (spk->id.us==1) { + if (spk->id.lib == NULL) return; + if (spk->id.us == 1) { id_clear_lib_data(bmain, &spk->id); return; } - ob= bmain->object.first; + ob = bmain->object.first; while (ob) { - if (ob->data==spk) { - if (ob->id.lib) is_lib= TRUE; - else is_local= TRUE; + if (ob->data == spk) { + if (ob->id.lib) is_lib = TRUE; + else is_local = TRUE; } - ob= ob->id.next; + ob = ob->id.next; } if (is_local && is_lib == FALSE) { id_clear_lib_data(bmain, &spk->id); } else if (is_local && is_lib) { - Speaker *spk_new= copy_speaker(spk); - spk_new->id.us= 0; + Speaker *spk_new = BKE_speaker_copy(spk); + spk_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, spk->id.lib, &spk_new->id); - ob= bmain->object.first; + ob = bmain->object.first; while (ob) { - if (ob->data==spk) { + if (ob->data == spk) { - if (ob->id.lib==NULL) { - ob->data= spk_new; + if (ob->id.lib == NULL) { + ob->data = spk_new; spk_new->id.us++; spk->id.us--; } } - ob= ob->id.next; + ob = ob->id.next; } } } -void free_speaker(Speaker *spk) +void BKE_speaker_free(Speaker *spk) { if (spk->sound) spk->sound->id.us--; diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index c69458f236a..2c05029e82e 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -52,6 +52,7 @@ #include "BLI_memarena.h" #include "BLI_pbvh.h" +#include "BKE_ccg.h" #include "BKE_cdderivedmesh.h" #include "BKE_global.h" #include "BKE_mesh.h" @@ -110,15 +111,19 @@ static void arena_release(CCGAllocatorHDL a) typedef enum { CCG_USE_AGING = 1, CCG_USE_ARENA = 2, - CCG_CALC_NORMALS = 4 + CCG_CALC_NORMALS = 4, + /* add an extra four bytes for a mask layer */ + CCG_ALLOC_MASK = 8 } CCGFlags; -static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, CCGFlags flags) +static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, + int numLayers, CCGFlags flags) { CCGMeshIFC ifc; CCGSubSurf *ccgSS; int useAging = !!(flags & CCG_USE_AGING); int useArena = flags & CCG_USE_ARENA; + int normalOffset = 0; /* subdivLevels==0 is not allowed */ subdivLevels = MAX2(subdivLevels, 1); @@ -144,7 +149,13 @@ static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, CCGFlags fl else { ifc.vertUserSize = ifc.edgeUserSize = ifc.faceUserSize = 8; } - ifc.vertDataSize = sizeof(float) * (flags & CCG_CALC_NORMALS ? 6 : 3); + ifc.numLayers = numLayers; + ifc.vertDataSize = sizeof(float) * numLayers; + normalOffset += sizeof(float) * numLayers; + if (flags & CCG_CALC_NORMALS) + ifc.vertDataSize += sizeof(float) * 3; + if (flags & CCG_ALLOC_MASK) + ifc.vertDataSize += sizeof(float); if (useArena) { CCGAllocatorIFC allocatorIFC; @@ -165,8 +176,14 @@ static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, CCGFlags fl ccgSubSurf_setUseAgeCounts(ccgSS, 1, 8, 8, 8); } + if (flags & CCG_ALLOC_MASK) { + normalOffset += sizeof(float); + /* mask is allocated after regular layers */ + ccgSubSurf_setAllocMask(ccgSS, 1, sizeof(float) * numLayers); + } + if (flags & CCG_CALC_NORMALS) - ccgSubSurf_setCalcVertexNormals(ccgSS, 1, offsetof(DMGridData, no)); + ccgSubSurf_setCalcVertexNormals(ccgSS, 1, normalOffset); else ccgSubSurf_setCalcVertexNormals(ccgSS, 0, 0); @@ -244,7 +261,7 @@ static void get_face_uv_map_vert(UvVertMap *vmap, struct MPoly *mpoly, struct ML int j, nverts = mpoly[fi].totloop; for (j = 0; j < nverts; j++) { - for (nv = v = get_uv_map_vert(vmap, ml[j].v); v; v = v->next) { + for (nv = v = BKE_mesh_uv_vert_map_get_vert(vmap, ml[j].v); v; v = v->next) { if (v->separate) nv = v; if (v->f == fi) @@ -273,7 +290,7 @@ static int ss_sync_from_uv(CCGSubSurf *ss, CCGSubSurf *origss, DerivedMesh *dm, float uv[3] = {0.0f, 0.0f, 0.0f}; /* only first 2 values are written into */ limit[0] = limit[1] = STD_UV_CONNECT_LIMIT; - vmap = make_uv_vert_map(mpoly, mloop, mloopuv, totface, totvert, 0, limit); + vmap = BKE_mesh_uv_vert_map_make(mpoly, mloop, mloopuv, totface, totvert, 0, limit); if (!vmap) return 0; @@ -281,16 +298,16 @@ static int ss_sync_from_uv(CCGSubSurf *ss, CCGSubSurf *origss, DerivedMesh *dm, /* create vertices */ for (i = 0; i < totvert; i++) { - if (!get_uv_map_vert(vmap, i)) + if (!BKE_mesh_uv_vert_map_get_vert(vmap, i)) continue; - for (v = get_uv_map_vert(vmap, i)->next; v; v = v->next) + for (v = BKE_mesh_uv_vert_map_get_vert(vmap, i)->next; v; v = v->next) if (v->separate) break; seam = (v != NULL) || ((mvert + i)->flag & ME_VERT_MERGED); - for (v = get_uv_map_vert(vmap, i); v; v = v->next) { + for (v = BKE_mesh_uv_vert_map_get_vert(vmap, i); v; v = v->next) { if (v->separate) { CCGVert *ssv; int loopid = mpoly[v->f].loopstart + v->tfindex; @@ -358,7 +375,7 @@ static int ss_sync_from_uv(CCGSubSurf *ss, CCGSubSurf *origss, DerivedMesh *dm, BLI_array_free(fverts); - free_uv_vert_map(vmap); + BKE_mesh_uv_vert_map_free(vmap); ccgSubSurf_processSync(ss); return 1; @@ -382,7 +399,7 @@ static void set_subsurf_uv(CCGSubSurf *ss, DerivedMesh *dm, DerivedMesh *result, return; /* create a CCGSubSurf from uv's */ - uvss = _getSubSurf(NULL, ccgSubSurf_getSubdivisionLevels(ss), CCG_USE_ARENA); + uvss = _getSubSurf(NULL, ccgSubSurf_getSubdivisionLevels(ss), 2, CCG_USE_ARENA); if (!ss_sync_from_uv(uvss, ss, dm, dmloopuv)) { ccgSubSurf_free(uvss); @@ -414,7 +431,7 @@ static void set_subsurf_uv(CCGSubSurf *ss, DerivedMesh *dm, DerivedMesh *result, int numVerts = ccgSubSurf_getFaceNumVerts(f); for (S = 0; S < numVerts; S++) { - float (*faceGridData)[3] = ccgSubSurf_getFaceGridDataArray(uvss, f, S); + float (*faceGridData)[2] = ccgSubSurf_getFaceGridDataArray(uvss, f, S); for (y = 0; y < gridFaces; y++) { for (x = 0; x < gridFaces; x++) { @@ -633,6 +650,16 @@ static int ccgDM_getFaceMapIndex(CCGSubSurf *ss, CCGFace *f) return ((int *) ccgSubSurf_getFaceUserData(ss, f))[1]; } +static void minmax_v3_v3v3(const float vec[3], float min[3], float max[3]) +{ + if (min[0] > vec[0]) min[0] = vec[0]; + if (min[1] > vec[1]) min[1] = vec[1]; + if (min[2] > vec[2]) min[2] = vec[2]; + if (max[0] < vec[0]) max[0] = vec[0]; + if (max[1] < vec[1]) max[1] = vec[1]; + if (max[2] < vec[2]) max[2] = vec[2]; +} + static void ccgDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3]) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; @@ -640,9 +667,12 @@ static void ccgDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3]) CCGVertIterator *vi = ccgSubSurf_getVertIterator(ss); CCGEdgeIterator *ei = ccgSubSurf_getEdgeIterator(ss); CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss); + CCGKey key; int i, edgeSize = ccgSubSurf_getEdgeSize(ss); int gridSize = ccgSubSurf_getGridSize(ss); + CCG_key_top_level(&key, ss); + if (!ccgSubSurf_getNumVerts(ss)) min_r[0] = min_r[1] = min_r[2] = max_r[0] = max_r[1] = max_r[2] = 0.0; @@ -650,15 +680,15 @@ static void ccgDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3]) CCGVert *v = ccgVertIterator_getCurrent(vi); float *co = ccgSubSurf_getVertData(ss, v); - DO_MINMAX(co, min_r, max_r); + minmax_v3_v3v3(co, min_r, max_r); } for (; !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) { CCGEdge *e = ccgEdgeIterator_getCurrent(ei); - DMGridData *edgeData = ccgSubSurf_getEdgeDataArray(ss, e); + CCGElem *edgeData = ccgSubSurf_getEdgeDataArray(ss, e); for (i = 0; i < edgeSize; i++) - DO_MINMAX(edgeData[i].co, min_r, max_r); + minmax_v3_v3v3(CCG_elem_offset_co(&key, edgeData, i), min_r, max_r); } for (; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) { @@ -666,11 +696,11 @@ static void ccgDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3]) int S, x, y, numVerts = ccgSubSurf_getFaceNumVerts(f); for (S = 0; S < numVerts; S++) { - DMGridData *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S); + CCGElem *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S); for (y = 0; y < gridSize; y++) for (x = 0; x < gridSize; x++) - DO_MINMAX(faceGridData[y * gridSize + x].co, min_r, max_r); + minmax_v3_v3v3(CCG_grid_elem_co(&key, faceGridData, x, y), min_r, max_r); } } @@ -712,9 +742,11 @@ static void ccgDM_getFinalVert(DerivedMesh *dm, int vertNum, MVert *mv) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; - DMGridData *vd; + CCGElem *vd; + CCGKey key; int i; + CCG_key_top_level(&key, ss); memset(mv, 0, sizeof(*mv)); if ((vertNum < ccgdm->edgeMap[0].startVert) && (ccgSubSurf_getNumFaces(ss) > 0)) { @@ -730,8 +762,9 @@ static void ccgDM_getFinalVert(DerivedMesh *dm, int vertNum, MVert *mv) int gridInternalEnd; i = 0; - while (i < lastface && vertNum >= ccgdm->faceMap[i + 1].startVert) - ++i; + while (i < lastface && vertNum >= ccgdm->faceMap[i + 1].startVert) { + i++; + } f = ccgdm->faceMap[i].face; numVerts = ccgSubSurf_getFaceNumVerts(f); @@ -745,16 +778,16 @@ static void ccgDM_getFinalVert(DerivedMesh *dm, int vertNum, MVert *mv) offset = vertNum - ccgdm->faceMap[i].startVert; if (offset < 1) { vd = ccgSubSurf_getFaceCenterData(f); - copy_v3_v3(mv->co, vd->co); - normal_float_to_short_v3(mv->no, vd->no); + copy_v3_v3(mv->co, CCG_elem_co(&key, vd)); + normal_float_to_short_v3(mv->no, CCG_elem_no(&key, vd)); } else if (offset < gridSideEnd) { offset -= 1; grid = offset / gridSideVerts; x = offset % gridSideVerts + 1; vd = ccgSubSurf_getFaceGridEdgeData(ss, f, grid, x); - copy_v3_v3(mv->co, vd->co); - normal_float_to_short_v3(mv->no, vd->no); + copy_v3_v3(mv->co, CCG_elem_co(&key, vd)); + normal_float_to_short_v3(mv->no, CCG_elem_no(&key, vd)); } else if (offset < gridInternalEnd) { offset -= gridSideEnd; @@ -763,8 +796,8 @@ static void ccgDM_getFinalVert(DerivedMesh *dm, int vertNum, MVert *mv) y = offset / gridSideVerts + 1; x = offset % gridSideVerts + 1; vd = ccgSubSurf_getFaceGridData(ss, f, grid, x, y); - copy_v3_v3(mv->co, vd->co); - normal_float_to_short_v3(mv->no, vd->no); + copy_v3_v3(mv->co, CCG_elem_co(&key, vd)); + normal_float_to_short_v3(mv->no, CCG_elem_no(&key, vd)); } } else if ((vertNum < ccgdm->vertMap[0].startVert) && (ccgSubSurf_getNumEdges(ss) > 0)) { @@ -774,15 +807,16 @@ static void ccgDM_getFinalVert(DerivedMesh *dm, int vertNum, MVert *mv) int x; i = 0; - while (i < lastedge && vertNum >= ccgdm->edgeMap[i + 1].startVert) - ++i; + while (i < lastedge && vertNum >= ccgdm->edgeMap[i + 1].startVert) { + i++; + } e = ccgdm->edgeMap[i].edge; x = vertNum - ccgdm->edgeMap[i].startVert + 1; vd = ccgSubSurf_getEdgeData(ss, e, x); - copy_v3_v3(mv->co, vd->co); - normal_float_to_short_v3(mv->no, vd->no); + copy_v3_v3(mv->co, CCG_elem_co(&key, vd)); + normal_float_to_short_v3(mv->no, CCG_elem_no(&key, vd)); } else { /* this vert comes from vert data */ @@ -791,8 +825,8 @@ static void ccgDM_getFinalVert(DerivedMesh *dm, int vertNum, MVert *mv) v = ccgdm->vertMap[i].vert; vd = ccgSubSurf_getVertData(ss, v); - copy_v3_v3(mv->co, vd->co); - normal_float_to_short_v3(mv->no, vd->no); + copy_v3_v3(mv->co, CCG_elem_co(&key, vd)); + normal_float_to_short_v3(mv->no, CCG_elem_no(&key, vd)); } } @@ -869,8 +903,9 @@ static void ccgDM_getFinalEdge(DerivedMesh *dm, int edgeNum, MEdge *med) #endif i = 0; - while (i < lastface && edgeNum >= ccgdm->faceMap[i + 1].startEdge) - ++i; + while (i < lastface && edgeNum >= ccgdm->faceMap[i + 1].startEdge) { + i++; + } f = ccgdm->faceMap[i].face; /* numVerts = ccgSubSurf_getFaceNumVerts(f); */ /*UNUSED*/ @@ -1012,32 +1047,74 @@ void subsurf_copy_grid_hidden(DerivedMesh *dm, const MPoly *mpoly, } } +/* Translate GridPaintMask into vertex paint masks. Assumes vertices + are in the order output by ccgDM_copyFinalVertArray. */ +void subsurf_copy_grid_paint_mask(DerivedMesh *dm, const MPoly *mpoly, + float *paint_mask, + const GridPaintMask *grid_paint_mask) +{ + CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; + CCGSubSurf *ss = ccgdm->ss; + int level = ccgSubSurf_getSubdivisionLevels(ss); + int gridSize = ccgSubSurf_getGridSize(ss); + int edgeSize = ccgSubSurf_getEdgeSize(ss); + int totface = ccgSubSurf_getNumFaces(ss); + int i, j, x, y, factor, gpm_gridsize; + + for (i = 0; i < totface; i++) { + CCGFace *f = ccgdm->faceMap[i].face; + const MPoly *p = &mpoly[i]; + + for (j = 0; j < p->totloop; j++) { + const GridPaintMask *gpm = &grid_paint_mask[p->loopstart + j]; + if (!gpm->data) + continue; + + factor = ccg_factor(level, gpm->level); + gpm_gridsize = ccg_gridsize(gpm->level); + + for (y = 0; y < gridSize; y++) { + for (x = 0; x < gridSize; x++) { + int vndx, offset; + + vndx = getFaceIndex(ss, f, j, x, y, edgeSize, gridSize); + offset = y * factor * gpm_gridsize + x * factor; + paint_mask[vndx] = gpm->data[offset]; + } + } + } + } +} + static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; - DMGridData *vd; + CCGElem *vd; + CCGKey key; int index; int totvert, totedge, totface; int gridSize = ccgSubSurf_getGridSize(ss); int edgeSize = ccgSubSurf_getEdgeSize(ss); int i = 0; + CCG_key_top_level(&key, ss); + totface = ccgSubSurf_getNumFaces(ss); for (index = 0; index < totface; index++) { CCGFace *f = ccgdm->faceMap[index].face; int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f); vd = ccgSubSurf_getFaceCenterData(f); - copy_v3_v3(mvert[i].co, vd->co); - normal_float_to_short_v3(mvert[i].no, vd->no); + copy_v3_v3(mvert[i].co, CCG_elem_co(&key, vd)); + normal_float_to_short_v3(mvert[i].no, CCG_elem_no(&key, vd)); i++; for (S = 0; S < numVerts; S++) { for (x = 1; x < gridSize - 1; x++, i++) { vd = ccgSubSurf_getFaceGridEdgeData(ss, f, S, x); - copy_v3_v3(mvert[i].co, vd->co); - normal_float_to_short_v3(mvert[i].no, vd->no); + copy_v3_v3(mvert[i].co, CCG_elem_co(&key, vd)); + normal_float_to_short_v3(mvert[i].no, CCG_elem_no(&key, vd)); } } @@ -1045,8 +1122,8 @@ static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert) for (y = 1; y < gridSize - 1; y++) { for (x = 1; x < gridSize - 1; x++, i++) { vd = ccgSubSurf_getFaceGridData(ss, f, S, x, y); - copy_v3_v3(mvert[i].co, vd->co); - normal_float_to_short_v3(mvert[i].no, vd->no); + copy_v3_v3(mvert[i].co, CCG_elem_co(&key, vd)); + normal_float_to_short_v3(mvert[i].no, CCG_elem_no(&key, vd)); } } } @@ -1059,13 +1136,13 @@ 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); + copy_v3_v3(mvert[i].co, CCG_elem_co(&key, vd)); /* This gives errors with -debug-fpe * the normals don't 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); + normal_float_to_short_v3(mvert[i].no, CCG_elem_no(&key, vd)); } } @@ -1074,8 +1151,8 @@ static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert) CCGVert *v = ccgdm->vertMap[index].vert; vd = ccgSubSurf_getVertData(ss, v); - copy_v3_v3(mvert[i].co, vd->co); - normal_float_to_short_v3(mvert[i].no, vd->no); + copy_v3_v3(mvert[i].co, CCG_elem_co(&key, vd)); + normal_float_to_short_v3(mvert[i].no, CCG_elem_no(&key, vd)); i++; } } @@ -1144,8 +1221,7 @@ static void ccgDM_copyFinalEdgeArray(DerivedMesh *dm, MEdge *medge) if (edgeFlags) { if (edgeIdx != -1) { - flags |= (edgeFlags[index] & (ME_SEAM | ME_SHARP | ME_FREESTYLE_EDGE)) - | ME_EDGEDRAW | ME_EDGERENDER; + flags |= ((edgeFlags[index] & (ME_SEAM | ME_SHARP | ME_FREESTYLE_EDGE)) | ME_EDGEDRAW | ME_EDGERENDER); } } else { @@ -1398,14 +1474,16 @@ static void ccgDM_foreachMappedVert( { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGVertIterator *vi = ccgSubSurf_getVertIterator(ccgdm->ss); + CCGKey key; + CCG_key_top_level(&key, ccgdm->ss); for (; !ccgVertIterator_isStopped(vi); ccgVertIterator_next(vi)) { CCGVert *v = ccgVertIterator_getCurrent(vi); - DMGridData *vd = ccgSubSurf_getVertData(ccgdm->ss, v); + CCGElem *vd = ccgSubSurf_getVertData(ccgdm->ss, v); int index = ccgDM_getVertMapIndex(ccgdm->ss, v); if (index != -1) - func(userData, index, vd->co, vd->no, NULL); + func(userData, index, CCG_elem_co(&key, vd), CCG_elem_no(&key, vd), NULL); } ccgVertIterator_free(vi); @@ -1419,16 +1497,19 @@ static void ccgDM_foreachMappedEdge( CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; CCGEdgeIterator *ei = ccgSubSurf_getEdgeIterator(ss); + CCGKey key; int i, edgeSize = ccgSubSurf_getEdgeSize(ss); + CCG_key_top_level(&key, ss); + for (; !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) { CCGEdge *e = ccgEdgeIterator_getCurrent(ei); - DMGridData *edgeData = ccgSubSurf_getEdgeDataArray(ss, e); + CCGElem *edgeData = ccgSubSurf_getEdgeDataArray(ss, e); int index = ccgDM_getEdgeMapIndex(ss, e); if (index != -1) { for (i = 0; i < edgeSize - 1; i++) - func(userData, index, edgeData[i].co, edgeData[i + 1].co); + func(userData, index, CCG_elem_offset_co(&key, edgeData, i), CCG_elem_offset_co(&key, edgeData, i + 1)); } } @@ -1500,18 +1581,20 @@ static void ccgDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int drawAllEdge { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; + CCGKey key; int i, j, edgeSize = ccgSubSurf_getEdgeSize(ss); int totedge = ccgSubSurf_getNumEdges(ss); int gridSize = ccgSubSurf_getGridSize(ss); int useAging; + CCG_key_top_level(&key, ss); ccgdm_pbvh_update(ccgdm); ccgSubSurf_getUseAgeCounts(ss, &useAging, NULL, NULL, NULL); for (j = 0; j < totedge; j++) { CCGEdge *e = ccgdm->edgeMap[j].edge; - DMGridData *edgeData = ccgSubSurf_getEdgeDataArray(ss, e); + CCGElem *edgeData = ccgSubSurf_getEdgeDataArray(ss, e); if (!drawLooseEdges && !ccgSubSurf_getEdgeNumFaces(e)) continue; @@ -1526,8 +1609,8 @@ static void ccgDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int drawAllEdge glBegin(GL_LINE_STRIP); for (i = 0; i < edgeSize - 1; i++) { - glVertex3fv(edgeData[i].co); - glVertex3fv(edgeData[i + 1].co); + glVertex3fv(CCG_elem_offset_co(&key, edgeData, i)); + glVertex3fv(CCG_elem_offset_co(&key, edgeData, i + 1)); } glEnd(); } @@ -1544,22 +1627,22 @@ static void ccgDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int drawAllEdge int S, x, y, numVerts = ccgSubSurf_getFaceNumVerts(f); for (S = 0; S < numVerts; S++) { - DMGridData *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S); + CCGElem *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S); glBegin(GL_LINE_STRIP); for (x = 0; x < gridSize; x++) - glVertex3fv(faceGridData[x].co); + glVertex3fv(CCG_elem_offset_co(&key, faceGridData, x)); glEnd(); for (y = 1; y < gridSize - 1; y++) { glBegin(GL_LINE_STRIP); for (x = 0; x < gridSize; x++) - glVertex3fv(faceGridData[y * gridSize + x].co); + glVertex3fv(CCG_grid_elem_co(&key, faceGridData, x, y)); glEnd(); } for (x = 1; x < gridSize - 1; x++) { glBegin(GL_LINE_STRIP); for (y = 0; y < gridSize; y++) - glVertex3fv(faceGridData[y * gridSize + x].co); + glVertex3fv(CCG_grid_elem_co(&key, faceGridData, x, y)); glEnd(); } } @@ -1571,18 +1654,21 @@ static void ccgDM_drawLooseEdges(DerivedMesh *dm) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; + CCGKey key; int totedge = ccgSubSurf_getNumEdges(ss); int i, j, edgeSize = ccgSubSurf_getEdgeSize(ss); + CCG_key_top_level(&key, ss); + for (j = 0; j < totedge; j++) { CCGEdge *e = ccgdm->edgeMap[j].edge; - DMGridData *edgeData = ccgSubSurf_getEdgeDataArray(ss, e); + CCGElem *edgeData = ccgSubSurf_getEdgeDataArray(ss, e); if (!ccgSubSurf_getEdgeNumFaces(e)) { glBegin(GL_LINE_STRIP); for (i = 0; i < edgeSize - 1; i++) { - glVertex3fv(edgeData[i].co); - glVertex3fv(edgeData[i + 1].co); + glVertex3fv(CCG_elem_offset_co(&key, edgeData, i)); + glVertex3fv(CCG_elem_offset_co(&key, edgeData, i + 1)); } glEnd(); } @@ -1608,12 +1694,14 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; + CCGKey key; int gridSize = ccgSubSurf_getGridSize(ss); DMFlagMat *faceFlags = ccgdm->faceFlags; int step = (fast) ? gridSize - 1 : 1; int i, totface = ccgSubSurf_getNumFaces(ss); int drawcurrent = 0, matnr = -1, shademodel = -1; + CCG_key_top_level(&key, ss); ccgdm_pbvh_update(ccgdm); if (ccgdm->pbvh && ccgdm->multires.mmd && !fast) { @@ -1653,19 +1741,19 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes) continue; for (S = 0; S < numVerts; S++) { - DMGridData *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S); + CCGElem *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S); if (shademodel == GL_SMOOTH) { for (y = 0; y < gridSize - 1; y += step) { glBegin(GL_QUAD_STRIP); for (x = 0; x < gridSize; x += step) { - DMGridData *a = &faceGridData[(y + 0) * gridSize + x]; - DMGridData *b = &faceGridData[(y + step) * gridSize + x]; + CCGElem *a = CCG_grid_elem(&key, faceGridData, x, y + 0); + CCGElem *b = CCG_grid_elem(&key, faceGridData, x, y + step); - glNormal3fv(a->no); - glVertex3fv(a->co); - glNormal3fv(b->no); - glVertex3fv(b->co); + glNormal3fv(CCG_elem_no(&key, a)); + glVertex3fv(CCG_elem_co(&key, a)); + glNormal3fv(CCG_elem_no(&key, b)); + glVertex3fv(CCG_elem_co(&key, b)); } glEnd(); } @@ -1674,10 +1762,10 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes) glBegin(GL_QUADS); for (y = 0; y < gridSize - 1; y += step) { for (x = 0; x < gridSize - 1; x += step) { - float *a = faceGridData[(y + 0) * gridSize + x].co; - float *b = faceGridData[(y + 0) * gridSize + x + step].co; - float *c = faceGridData[(y + step) * gridSize + x + step].co; - float *d = faceGridData[(y + step) * gridSize + x].co; + float *a = CCG_grid_elem_co(&key, faceGridData, x, y + 0); + float *b = CCG_grid_elem_co(&key, faceGridData, x + step, y + 0); + float *c = CCG_grid_elem_co(&key, faceGridData, x + step, y + step); + float *d = CCG_grid_elem_co(&key, faceGridData, x, y + step); ccgDM_glNormalFast(a, b, c, d); @@ -1701,6 +1789,7 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm, { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; + CCGKey key; GPUVertexAttribs gattribs; DMVertexAttribs attribs = {{{NULL}}}; /* MTFace *tf = dm->getTessFaceDataArray(dm, CD_MTFACE); */ /* UNUSED */ @@ -1710,6 +1799,7 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm, DMFlagMat *faceFlags = ccgdm->faceFlags; int a, b, i, doDraw, numVerts, matnr, new_matnr, totface; + CCG_key_top_level(&key, ss); ccgdm_pbvh_update(ccgdm); doDraw = 0; @@ -1769,38 +1859,38 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm, glShadeModel(drawSmooth ? GL_SMOOTH : GL_FLAT); for (S = 0; S < numVerts; S++) { - DMGridData *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S); - DMGridData *vda, *vdb; + CCGElem *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S); + CCGElem *vda, *vdb; if (drawSmooth) { for (y = 0; y < gridFaces; y++) { glBegin(GL_QUAD_STRIP); for (x = 0; x < gridFaces; x++) { - vda = &faceGridData[(y + 0) * gridSize + x]; - vdb = &faceGridData[(y + 1) * gridSize + x]; + vda = CCG_grid_elem(&key, faceGridData, x, y + 0); + vdb = CCG_grid_elem(&key, faceGridData, x, y + 1); PASSATTRIB(0, 0, 0); - glNormal3fv(vda->no); - glVertex3fv(vda->co); + glNormal3fv(CCG_elem_no(&key, vda)); + glVertex3fv(CCG_elem_co(&key, vda)); PASSATTRIB(0, 1, 1); - glNormal3fv(vdb->no); - glVertex3fv(vdb->co); + glNormal3fv(CCG_elem_no(&key, vdb)); + glVertex3fv(CCG_elem_co(&key, vdb)); if (x != gridFaces - 1) a++; } - vda = &faceGridData[(y + 0) * gridSize + x]; - vdb = &faceGridData[(y + 1) * gridSize + x]; + vda = CCG_grid_elem(&key, faceGridData, x, y + 0); + vdb = CCG_grid_elem(&key, faceGridData, x, y + 1); PASSATTRIB(0, 0, 3); - glNormal3fv(vda->no); - glVertex3fv(vda->co); + glNormal3fv(CCG_elem_no(&key, vda)); + glVertex3fv(CCG_elem_co(&key, vda)); PASSATTRIB(0, 1, 2); - glNormal3fv(vdb->no); - glVertex3fv(vdb->co); + glNormal3fv(CCG_elem_no(&key, vdb)); + glVertex3fv(CCG_elem_co(&key, vdb)); glEnd(); @@ -1811,10 +1901,10 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm, glBegin(GL_QUADS); for (y = 0; y < gridFaces; y++) { for (x = 0; x < gridFaces; x++) { - float *aco = faceGridData[(y + 0) * gridSize + x].co; - float *bco = faceGridData[(y + 0) * gridSize + x + 1].co; - float *cco = faceGridData[(y + 1) * gridSize + x + 1].co; - float *dco = faceGridData[(y + 1) * gridSize + x].co; + float *aco = CCG_grid_elem_co(&key, faceGridData, x, y); + float *bco = CCG_grid_elem_co(&key, faceGridData, x + 1, y); + float *cco = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 1); + float *dco = CCG_grid_elem_co(&key, faceGridData, x, y + 1); ccgDM_glNormalFast(aco, bco, cco, dco); @@ -1848,6 +1938,7 @@ static void ccgDM_drawMappedFacesMat(DerivedMesh *dm, void (*setMaterial)(void * { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; + CCGKey key; GPUVertexAttribs gattribs; DMVertexAttribs attribs = {{{NULL}}}; int gridSize = ccgSubSurf_getGridSize(ss); @@ -1856,6 +1947,7 @@ static void ccgDM_drawMappedFacesMat(DerivedMesh *dm, void (*setMaterial)(void * DMFlagMat *faceFlags = ccgdm->faceFlags; int a, b, i, numVerts, matnr, new_matnr, totface; + CCG_key_top_level(&key, ss); ccgdm_pbvh_update(ccgdm); matnr = -1; @@ -1921,38 +2013,38 @@ static void ccgDM_drawMappedFacesMat(DerivedMesh *dm, void (*setMaterial)(void * /* draw face*/ glShadeModel(drawSmooth ? GL_SMOOTH : GL_FLAT); for (S = 0; S < numVerts; S++) { - DMGridData *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S); - DMGridData *vda, *vdb; + CCGElem *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S); + CCGElem *vda, *vdb; if (drawSmooth) { for (y = 0; y < gridFaces; y++) { glBegin(GL_QUAD_STRIP); for (x = 0; x < gridFaces; x++) { - vda = &faceGridData[(y + 0) * gridSize + x]; - vdb = &faceGridData[(y + 1) * gridSize + x]; + vda = CCG_grid_elem(&key, faceGridData, x, y); + vdb = CCG_grid_elem(&key, faceGridData, x, y + 1); PASSATTRIB(0, 0, 0); - glNormal3fv(vda->no); - glVertex3fv(vda->co); + glNormal3fv(CCG_elem_no(&key, vda)); + glVertex3fv(CCG_elem_co(&key, vda)); PASSATTRIB(0, 1, 1); - glNormal3fv(vdb->no); - glVertex3fv(vdb->co); + glNormal3fv(CCG_elem_no(&key, vdb)); + glVertex3fv(CCG_elem_co(&key, vdb)); if (x != gridFaces - 1) a++; } - vda = &faceGridData[(y + 0) * gridSize + x]; - vdb = &faceGridData[(y + 1) * gridSize + x]; + vda = CCG_grid_elem(&key, faceGridData, x, y + 0); + vdb = CCG_grid_elem(&key, faceGridData, x, y + 1); PASSATTRIB(0, 0, 3); - glNormal3fv(vda->no); - glVertex3fv(vda->co); + glNormal3fv(CCG_elem_no(&key, vda)); + glVertex3fv(CCG_elem_co(&key, vda)); PASSATTRIB(0, 1, 2); - glNormal3fv(vdb->no); - glVertex3fv(vdb->co); + glNormal3fv(CCG_elem_no(&key, vdb)); + glVertex3fv(CCG_elem_co(&key, vdb)); glEnd(); @@ -1963,10 +2055,10 @@ static void ccgDM_drawMappedFacesMat(DerivedMesh *dm, void (*setMaterial)(void * glBegin(GL_QUADS); for (y = 0; y < gridFaces; y++) { for (x = 0; x < gridFaces; x++) { - float *aco = faceGridData[(y + 0) * gridSize + x].co; - float *bco = faceGridData[(y + 0) * gridSize + x + 1].co; - float *cco = faceGridData[(y + 1) * gridSize + x + 1].co; - float *dco = faceGridData[(y + 1) * gridSize + x].co; + float *aco = CCG_grid_elem_co(&key, faceGridData, x, y + 0); + float *bco = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 0); + float *cco = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 1); + float *dco = CCG_grid_elem_co(&key, faceGridData, x, y + 1); ccgDM_glNormalFast(aco, bco, cco, dco); @@ -1998,6 +2090,7 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm, { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; + CCGKey key; MCol *mcol = dm->getTessFaceDataArray(dm, CD_PREVIEW_MCOL); MTFace *tf = DM_get_tessface_data_layer(dm, CD_MTFACE); DMFlagMat *faceFlags = ccgdm->faceFlags; @@ -2007,6 +2100,7 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm, (void) compareDrawOptions; + CCG_key_top_level(&key, ss); ccgdm_pbvh_update(ccgdm); if (!mcol) @@ -2055,26 +2149,26 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm, } for (S = 0; S < numVerts; S++) { - DMGridData *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S); - DMGridData *a, *b; + CCGElem *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S); + CCGElem *a, *b; if (drawSmooth) { glShadeModel(GL_SMOOTH); for (y = 0; y < gridFaces; y++) { glBegin(GL_QUAD_STRIP); for (x = 0; x < gridFaces; x++) { - a = &faceGridData[(y + 0) * gridSize + x]; - b = &faceGridData[(y + 1) * gridSize + x]; + a = CCG_grid_elem(&key, faceGridData, x, y + 0); + b = CCG_grid_elem(&key, faceGridData, x, y + 1); if (tf) glTexCoord2fv(tf->uv[0]); if (cp) glColor3ub(cp[3], cp[2], cp[1]); - glNormal3fv(a->no); - glVertex3fv(a->co); + glNormal3fv(CCG_elem_no(&key, a)); + glVertex3fv(CCG_elem_co(&key, a)); if (tf) glTexCoord2fv(tf->uv[1]); if (cp) glColor3ub(cp[7], cp[6], cp[5]); - glNormal3fv(b->no); - glVertex3fv(b->co); + glNormal3fv(CCG_elem_no(&key, b)); + glVertex3fv(CCG_elem_co(&key, b)); if (x != gridFaces - 1) { if (tf) tf++; @@ -2082,18 +2176,18 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm, } } - a = &faceGridData[(y + 0) * gridSize + x]; - b = &faceGridData[(y + 1) * gridSize + x]; + a = CCG_grid_elem(&key, faceGridData, x, y + 0); + b = CCG_grid_elem(&key, faceGridData, x, y + 1); if (tf) glTexCoord2fv(tf->uv[3]); if (cp) glColor3ub(cp[15], cp[14], cp[13]); - glNormal3fv(a->no); - glVertex3fv(a->co); + glNormal3fv(CCG_elem_no(&key, a)); + glVertex3fv(CCG_elem_co(&key, a)); if (tf) glTexCoord2fv(tf->uv[2]); if (cp) glColor3ub(cp[11], cp[10], cp[9]); - glNormal3fv(b->no); - glVertex3fv(b->co); + glNormal3fv(CCG_elem_no(&key, b)); + glVertex3fv(CCG_elem_co(&key, b)); if (tf) tf++; if (cp) cp += 16; @@ -2102,14 +2196,14 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm, } } else { - glShadeModel((cp)? GL_SMOOTH: GL_FLAT); + glShadeModel((cp) ? GL_SMOOTH : GL_FLAT); glBegin(GL_QUADS); for (y = 0; y < gridFaces; y++) { for (x = 0; x < gridFaces; x++) { - float *a_co = faceGridData[(y + 0) * gridSize + x].co; - float *b_co = faceGridData[(y + 0) * gridSize + x + 1].co; - float *c_co = faceGridData[(y + 1) * gridSize + x + 1].co; - float *d_co = faceGridData[(y + 1) * gridSize + x].co; + float *a_co = CCG_grid_elem_co(&key, faceGridData, x, y + 0); + float *b_co = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 0); + float *c_co = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 1); + float *d_co = CCG_grid_elem_co(&key, faceGridData, x, y + 1); ccgDM_glNormalFast(a_co, b_co, c_co, d_co); @@ -2197,12 +2291,15 @@ static void ccgDM_drawMappedFaces(DerivedMesh *dm, { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; + CCGKey key; MCol *mcol = NULL; int i, gridSize = ccgSubSurf_getGridSize(ss); DMFlagMat *faceFlags = ccgdm->faceFlags; int useColors = flag & DM_DRAW_USE_COLORS; int gridFaces = gridSize - 1, totface; + CCG_key_top_level(&key, ss); + /* currently unused -- each original face is handled separately */ (void)compareDrawOptions; @@ -2250,36 +2347,36 @@ static void ccgDM_drawMappedFaces(DerivedMesh *dm, glShadeModel(GL_SMOOTH); for (S = 0; S < numVerts; S++) { - DMGridData *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S); + CCGElem *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S); if (drawSmooth) { for (y = 0; y < gridFaces; y++) { - DMGridData *a, *b; + CCGElem *a, *b; glBegin(GL_QUAD_STRIP); for (x = 0; x < gridFaces; x++) { - a = &faceGridData[(y + 0) * gridSize + x]; - b = &faceGridData[(y + 1) * gridSize + x]; + a = CCG_grid_elem(&key, faceGridData, x, y + 0); + b = CCG_grid_elem(&key, faceGridData, x, y + 1); if (cp) glColor3ub(cp[3], cp[2], cp[1]); - glNormal3fv(a->no); - glVertex3fv(a->co); + glNormal3fv(CCG_elem_no(&key, a)); + glVertex3fv(CCG_elem_co(&key, a)); if (cp) glColor3ub(cp[7], cp[6], cp[5]); - glNormal3fv(b->no); - glVertex3fv(b->co); + glNormal3fv(CCG_elem_no(&key, b)); + glVertex3fv(CCG_elem_co(&key, b)); if (x != gridFaces - 1) { if (cp) cp += 16; } } - a = &faceGridData[(y + 0) * gridSize + x]; - b = &faceGridData[(y + 1) * gridSize + x]; + a = CCG_grid_elem(&key, faceGridData, x, y + 0); + b = CCG_grid_elem(&key, faceGridData, x, y + 1); if (cp) glColor3ub(cp[15], cp[14], cp[13]); - glNormal3fv(a->no); - glVertex3fv(a->co); + glNormal3fv(CCG_elem_no(&key, a)); + glVertex3fv(CCG_elem_co(&key, a)); if (cp) glColor3ub(cp[11], cp[10], cp[9]); - glNormal3fv(b->no); - glVertex3fv(b->co); + glNormal3fv(CCG_elem_no(&key, b)); + glVertex3fv(CCG_elem_co(&key, b)); if (cp) cp += 16; @@ -2290,10 +2387,10 @@ static void ccgDM_drawMappedFaces(DerivedMesh *dm, glBegin(GL_QUADS); for (y = 0; y < gridFaces; y++) { for (x = 0; x < gridFaces; x++) { - float *a = faceGridData[(y + 0) * gridSize + x].co; - float *b = faceGridData[(y + 0) * gridSize + x + 1].co; - float *c = faceGridData[(y + 1) * gridSize + x + 1].co; - float *d = faceGridData[(y + 1) * gridSize + x].co; + float *a = CCG_grid_elem_co(&key, faceGridData, x, y + 0); + float *b = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 0); + float *c = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 1); + float *d = CCG_grid_elem_co(&key, faceGridData, x, y + 1); ccgDM_glNormalFast(a, b, c, d); @@ -2326,13 +2423,15 @@ static void ccgDM_drawMappedEdges(DerivedMesh *dm, CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; CCGEdgeIterator *ei = ccgSubSurf_getEdgeIterator(ss); + CCGKey key; int i, useAging, edgeSize = ccgSubSurf_getEdgeSize(ss); + CCG_key_top_level(&key, ss); ccgSubSurf_getUseAgeCounts(ss, &useAging, NULL, NULL, NULL); for (; !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) { CCGEdge *e = ccgEdgeIterator_getCurrent(ei); - DMGridData *edgeData = ccgSubSurf_getEdgeDataArray(ss, e); + CCGElem *edgeData = ccgSubSurf_getEdgeDataArray(ss, e); int index = ccgDM_getEdgeMapIndex(ss, e); glBegin(GL_LINE_STRIP); @@ -2343,8 +2442,8 @@ static void ccgDM_drawMappedEdges(DerivedMesh *dm, } for (i = 0; i < edgeSize - 1; i++) { - glVertex3fv(edgeData[i].co); - glVertex3fv(edgeData[i + 1].co); + glVertex3fv(CCG_elem_offset_co(&key, edgeData, i)); + glVertex3fv(CCG_elem_offset_co(&key, edgeData, i + 1)); } } glEnd(); @@ -2360,14 +2459,16 @@ static void ccgDM_drawMappedEdgesInterp(DerivedMesh *dm, { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; + CCGKey key; CCGEdgeIterator *ei = ccgSubSurf_getEdgeIterator(ss); int i, useAging, edgeSize = ccgSubSurf_getEdgeSize(ss); + CCG_key_top_level(&key, ss); ccgSubSurf_getUseAgeCounts(ss, &useAging, NULL, NULL, NULL); for (; !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) { CCGEdge *e = ccgEdgeIterator_getCurrent(ei); - DMGridData *edgeData = ccgSubSurf_getEdgeDataArray(ss, e); + CCGElem *edgeData = ccgSubSurf_getEdgeDataArray(ss, e); int index = ccgDM_getEdgeMapIndex(ss, e); glBegin(GL_LINE_STRIP); @@ -2380,7 +2481,7 @@ static void ccgDM_drawMappedEdgesInterp(DerivedMesh *dm, glColor3ub(0, ageCol > 0 ? ageCol : 0, 0); } - glVertex3fv(edgeData[i].co); + glVertex3fv(CCG_elem_offset_co(&key, edgeData, i)); } } glEnd(); @@ -2396,17 +2497,20 @@ static void ccgDM_foreachMappedFaceCenter( { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; + CCGKey key; CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss); + CCG_key_top_level(&key, ss); + for (; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) { CCGFace *f = ccgFaceIterator_getCurrent(fi); int index = ccgDM_getFaceMapIndex(ss, f); if (index != -1) { /* Face center data normal isn't updated atm. */ - DMGridData *vd = ccgSubSurf_getFaceGridData(ss, f, 0, 0, 0); + CCGElem *vd = ccgSubSurf_getFaceGridData(ss, f, 0, 0, 0); - func(userData, index, vd->co, vd->no); + func(userData, index, CCG_elem_co(&key, vd), CCG_elem_no(&key, vd)); } } @@ -2719,7 +2823,7 @@ static void ccgdm_create_grids(DerivedMesh *dm) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; CCGSubSurf *ss = ccgdm->ss; - DMGridData **gridData; + CCGElem **gridData; DMGridAdjacency *gridAdjacency, *adj; DMFlagMat *gridFlagMats; CCGFace **gridFaces; @@ -2745,7 +2849,7 @@ static void ccgdm_create_grids(DerivedMesh *dm) } /* compute grid data */ - gridData = MEM_mallocN(sizeof(DMGridData *) * numGrids, "ccgdm.gridData"); + gridData = MEM_mallocN(sizeof(CCGElem *) * numGrids, "ccgdm.gridData"); gridAdjacency = MEM_mallocN(sizeof(DMGridAdjacency) * numGrids, "ccgdm.gridAdjacency"); gridFaces = MEM_mallocN(sizeof(CCGFace *) * numGrids, "ccgdm.gridFaces"); gridFlagMats = MEM_mallocN(sizeof(DMFlagMat) * numGrids, "ccgdm.gridFlagMats"); @@ -2784,7 +2888,7 @@ static void ccgdm_create_grids(DerivedMesh *dm) ccgdm->gridFlagMats = gridFlagMats; } -static DMGridData **ccgDM_getGridData(DerivedMesh *dm) +static CCGElem **ccgDM_getGridData(DerivedMesh *dm) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; @@ -2808,6 +2912,12 @@ static int *ccgDM_getGridOffset(DerivedMesh *dm) return ccgdm->gridOffset; } +static void ccgDM_getGridKey(DerivedMesh *dm, CCGKey *key) +{ + CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; + CCG_key_top_level(key, ccgdm->ss); +} + static DMFlagMat *ccgDM_getGridFlagMats(DerivedMesh *dm) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; @@ -2854,7 +2964,10 @@ static int ccgDM_use_grid_pbvh(CCGDerivedMesh *ccgdm) static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; - int gridSize, numGrids, grid_pbvh; + CCGKey key; + int numGrids, grid_pbvh; + + CCG_key_top_level(&key, ccgdm->ss); if (!ob) { ccgdm->pbvh = NULL; @@ -2888,19 +3001,18 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm) if (grid_pbvh) { ccgdm_create_grids(dm); - gridSize = ccgDM_getGridSize(dm); numGrids = ccgDM_getNumGrids(dm); ob->sculpt->pbvh = ccgdm->pbvh = BLI_pbvh_new(); BLI_pbvh_build_grids(ccgdm->pbvh, ccgdm->gridData, ccgdm->gridAdjacency, - numGrids, gridSize, (void **)ccgdm->gridFaces, ccgdm->gridFlagMats, ccgdm->gridHidden); + numGrids, &key, (void **) ccgdm->gridFaces, ccgdm->gridFlagMats, ccgdm->gridHidden); } else if (ob->type == OB_MESH) { Mesh *me = ob->data; ob->sculpt->pbvh = ccgdm->pbvh = BLI_pbvh_new(); BLI_assert(!(me->mface == NULL && me->mpoly != NULL)); /* BMESH ONLY complain if mpoly is valid but not mface */ BLI_pbvh_build_mesh(ccgdm->pbvh, me->mface, me->mvert, - me->totface, me->totvert); + me->totface, me->totvert, &me->vdata); } return ccgdm->pbvh; @@ -3014,6 +3126,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, ccgdm->dm.getGridData = ccgDM_getGridData; ccgdm->dm.getGridAdjacency = ccgDM_getGridAdjacency; ccgdm->dm.getGridOffset = ccgDM_getGridOffset; + ccgdm->dm.getGridKey = ccgDM_getGridKey; ccgdm->dm.getGridFlagMats = ccgDM_getGridFlagMats; ccgdm->dm.getGridHidden = ccgDM_getGridHidden; ccgdm->dm.getPolyMap = ccgDM_getPolyMap; @@ -3169,10 +3282,10 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, numVerts, vertNum); if (vertOrigIndex) { *vertOrigIndex = ORIGINDEX_NONE; - ++vertOrigIndex; + vertOrigIndex++; } - ++vertNum; + vertNum++; /*interpolate per-vert data*/ for (s = 0; s < numVerts; s++) { @@ -3183,10 +3296,10 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, if (vertOrigIndex) { *vertOrigIndex = ORIGINDEX_NONE; - ++vertOrigIndex; + vertOrigIndex++; } - ++vertNum; + vertNum++; } } @@ -3200,10 +3313,10 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, if (vertOrigIndex) { *vertOrigIndex = ORIGINDEX_NONE; - ++vertOrigIndex; + vertOrigIndex++; } - ++vertNum; + vertNum++; } } } @@ -3299,9 +3412,9 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, DM_interp_vert_data(dm, &ccgdm->dm, vertIdx, w, 2, vertNum); if (vertOrigIndex) { *vertOrigIndex = ORIGINDEX_NONE; - ++vertOrigIndex; + vertOrigIndex++; } - ++vertNum; + vertNum++; } for (i = 0; i < numFinalEdges; ++i) { @@ -3339,9 +3452,9 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, if (vertOrigIndex) { *vertOrigIndex = mapIndex; - ++vertOrigIndex; + vertOrigIndex++; } - ++vertNum; + vertNum++; } ccgdm->dm.numVertData = vertNum; @@ -3365,8 +3478,8 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, struct DerivedMesh *subsurf_make_derived_from_derived( struct DerivedMesh *dm, struct SubsurfModifierData *smd, - int useRenderParams, float (*vertCos)[3], - int isFinalCalc, int forEditMode, int inEditMode) + float (*vertCos)[3], + SubsurfFlags flags) { int useSimple = smd->subdivType == ME_SIMPLE_SUBSURF; CCGFlags useAging = smd->flags & eSubsurfModifierFlag_DebugIncr ? CCG_USE_AGING : 0; @@ -3374,17 +3487,17 @@ struct DerivedMesh *subsurf_make_derived_from_derived( int drawInteriorEdges = !(smd->flags & eSubsurfModifierFlag_ControlEdges); CCGDerivedMesh *result; - if (forEditMode) { + if (flags & SUBSURF_FOR_EDIT_MODE) { int levels = (smd->modifier.scene) ? get_render_subsurf_level(&smd->modifier.scene->r, smd->levels) : smd->levels; - smd->emCache = _getSubSurf(smd->emCache, levels, useAging | CCG_CALC_NORMALS); + smd->emCache = _getSubSurf(smd->emCache, levels, 3, useAging | CCG_CALC_NORMALS); ss_sync_from_derivedmesh(smd->emCache, dm, vertCos, useSimple); result = getCCGDerivedMesh(smd->emCache, drawInteriorEdges, useSubsurfUv, dm); } - else if (useRenderParams) { + else if (flags & SUBSURF_USE_RENDER_PARAMS) { /* Do not use cache in render mode. */ CCGSubSurf *ss; int levels = (smd->modifier.scene) ? get_render_subsurf_level(&smd->modifier.scene->r, smd->renderLevels) : smd->renderLevels; @@ -3392,7 +3505,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived( if (levels == 0) return dm; - ss = _getSubSurf(NULL, levels, CCG_USE_ARENA | CCG_CALC_NORMALS); + ss = _getSubSurf(NULL, levels, 3, CCG_USE_ARENA | CCG_CALC_NORMALS); ss_sync_from_derivedmesh(ss, dm, vertCos, useSimple); @@ -3417,13 +3530,13 @@ struct DerivedMesh *subsurf_make_derived_from_derived( * Addendum: we can't really ensure that this is never called in edit * mode, so now we have a parameter to verify it. - brecht */ - if (!inEditMode && smd->emCache) { + if (!(flags & SUBSURF_IN_EDIT_MODE) && smd->emCache) { ccgSubSurf_free(smd->emCache); smd->emCache = NULL; } - if (useIncremental && isFinalCalc) { - smd->mCache = ss = _getSubSurf(smd->mCache, levels, useAging | CCG_CALC_NORMALS); + if (useIncremental && (flags & SUBSURF_IS_FINAL_CALC)) { + smd->mCache = ss = _getSubSurf(smd->mCache, levels, 3, useAging | CCG_CALC_NORMALS); ss_sync_from_derivedmesh(ss, dm, vertCos, useSimple); @@ -3432,20 +3545,28 @@ struct DerivedMesh *subsurf_make_derived_from_derived( useSubsurfUv, dm); } else { - if (smd->mCache && isFinalCalc) { + CCGFlags ccg_flags = CCG_USE_ARENA | CCG_CALC_NORMALS; + + if (smd->mCache && (flags & SUBSURF_IS_FINAL_CALC)) { ccgSubSurf_free(smd->mCache); smd->mCache = NULL; } - ss = _getSubSurf(NULL, levels, CCG_USE_ARENA | CCG_CALC_NORMALS); + if (flags & SUBSURF_ALLOC_PAINT_MASK) + ccg_flags |= CCG_ALLOC_MASK; + + ss = _getSubSurf(NULL, levels, 3, ccg_flags); ss_sync_from_derivedmesh(ss, dm, vertCos, useSimple); result = getCCGDerivedMesh(ss, drawInteriorEdges, useSubsurfUv, dm); - if (isFinalCalc) + if (flags & SUBSURF_IS_FINAL_CALC) smd->mCache = ss; else result->freeSS = 1; + + if (flags & SUBSURF_ALLOC_PAINT_MASK) + ccgSubSurf_setNumLayers(ss, 4); } } @@ -3459,7 +3580,7 @@ void subsurf_calculate_limit_positions(Mesh *me, float (*positions_r)[3]) * calculated vert positions is incorrect for the verts * on the boundary of the mesh. */ - CCGSubSurf *ss = _getSubSurf(NULL, 1, CCG_USE_ARENA); + CCGSubSurf *ss = _getSubSurf(NULL, 1, 3, CCG_USE_ARENA); float edge_sum[3], face_sum[3]; CCGVertIterator *vi; DerivedMesh *dm = CDDM_from_mesh(me, NULL); diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index d67c5fb3698..7634528927a 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -135,8 +135,8 @@ static void txt_pop_last(Text *text); static void txt_undo_add_op(Text *text, int op); static void txt_undo_add_block(Text *text, int op, const char *buf); static void txt_delete_line(Text *text, TextLine *line); -static void txt_delete_sel (Text *text); -static void txt_make_dirty (Text *text); +static void txt_delete_sel(Text *text); +static void txt_make_dirty(Text *text); /***/ @@ -155,19 +155,19 @@ int txt_get_undostate(void) static void init_undo_text(Text *text) { - text->undo_pos= -1; - text->undo_len= TXT_INIT_UNDO; - text->undo_buf= MEM_mallocN(text->undo_len, "undo buf"); + text->undo_pos = -1; + text->undo_len = TXT_INIT_UNDO; + text->undo_buf = MEM_mallocN(text->undo_len, "undo buf"); } -void free_text(Text *text) +void BKE_text_free(Text *text) { TextLine *tmp; - for (tmp= text->lines.first; tmp; tmp= tmp->next) { + for (tmp = text->lines.first; tmp; tmp = tmp->next) { MEM_freeN(tmp->line); if (tmp->format) - MEM_freeN(tmp->format); + MEM_freeN(tmp->format); } BLI_freelistN(&text->lines); @@ -180,43 +180,43 @@ void free_text(Text *text) #endif } -Text *add_empty_text(const char *name) +Text *BKE_text_add(const char *name) { - Main *bmain= G.main; + Main *bmain = G.main; Text *ta; TextLine *tmp; - ta= alloc_libblock(&bmain->text, ID_TXT, name); - ta->id.us= 1; + ta = BKE_libblock_alloc(&bmain->text, ID_TXT, name); + ta->id.us = 1; - ta->name= NULL; + ta->name = NULL; init_undo_text(ta); - ta->nlines=1; - ta->flags= TXT_ISDIRTY | TXT_ISMEM; - if ((U.flag & USER_TXT_TABSTOSPACES_DISABLE)==0) + ta->nlines = 1; + ta->flags = TXT_ISDIRTY | TXT_ISMEM; + if ((U.flag & USER_TXT_TABSTOSPACES_DISABLE) == 0) ta->flags |= TXT_TABSTOSPACES; - ta->lines.first= ta->lines.last= NULL; - ta->markers.first= ta->markers.last= NULL; + ta->lines.first = ta->lines.last = NULL; + ta->markers.first = ta->markers.last = NULL; - tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line= (char*) MEM_mallocN(1, "textline_string"); - tmp->format= NULL; + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = (char *) MEM_mallocN(1, "textline_string"); + tmp->format = NULL; - tmp->line[0]=0; - tmp->len= 0; + tmp->line[0] = 0; + tmp->len = 0; - tmp->next= NULL; - tmp->prev= NULL; + tmp->next = NULL; + tmp->prev = NULL; BLI_addhead(&ta->lines, tmp); - ta->curl= ta->lines.first; - ta->curc= 0; - ta->sell= ta->lines.first; - ta->selc= 0; + ta->curl = ta->lines.first; + ta->curc = 0; + ta->sell = ta->lines.first; + ta->selc = 0; return ta; } @@ -225,35 +225,35 @@ Text *add_empty_text(const char *name) /* to a valid utf-8 sequences */ int txt_extended_ascii_as_utf8(char **str) { - int bad_char, added= 0, i= 0; + int bad_char, added = 0, i = 0; int length = strlen(*str); while ((*str)[i]) { - if ((bad_char= BLI_utf8_invalid_byte(*str+i, length-i)) == -1) + if ((bad_char = BLI_utf8_invalid_byte(*str + i, length - i)) == -1) break; added++; - i+= bad_char + 1; + i += bad_char + 1; } if (added != 0) { - char *newstr = MEM_mallocN(length+added+1, "text_line"); + char *newstr = MEM_mallocN(length + added + 1, "text_line"); int mi = 0; - i= 0; + i = 0; while ((*str)[i]) { - if ((bad_char= BLI_utf8_invalid_byte((*str)+i, length-i)) == -1) { - memcpy(newstr+mi, (*str)+i, length - i + 1); + if ((bad_char = BLI_utf8_invalid_byte((*str) + i, length - i)) == -1) { + memcpy(newstr + mi, (*str) + i, length - i + 1); break; } - memcpy(newstr+mi, (*str)+i, bad_char); + memcpy(newstr + mi, (*str) + i, bad_char); - BLI_str_utf8_from_unicode((*str)[i+bad_char], newstr+mi+bad_char); - i+= bad_char+1; - mi+= bad_char+2; + BLI_str_utf8_from_unicode((*str)[i + bad_char], newstr + mi + bad_char); + i += bad_char + 1; + mi += bad_char + 2; } - newstr[length+added] = '\0'; + newstr[length + added] = '\0'; MEM_freeN(*str); *str = newstr; } @@ -264,21 +264,21 @@ int txt_extended_ascii_as_utf8(char **str) // this function removes any control characters from // a textline and fixes invalid utf-8 sequences -static void cleanup_textline(TextLine * tl) +static void cleanup_textline(TextLine *tl) { int i; - for (i = 0; i < tl->len; i++ ) { + for (i = 0; i < tl->len; i++) { if (tl->line[i] < ' ' && tl->line[i] != '\t') { memmove(tl->line + i, tl->line + i + 1, tl->len - i); tl->len--; i--; } } - tl->len+= txt_extended_ascii_as_utf8(&tl->line); + tl->len += txt_extended_ascii_as_utf8(&tl->line); } -int reopen_text(Text *text) +int BKE_text_reload(Text *text) { FILE *fp; int i, llen, len; @@ -292,32 +292,32 @@ int reopen_text(Text *text) BLI_strncpy(str, text->name, FILE_MAX); BLI_path_abs(str, G.main->name); - fp= BLI_fopen(str, "r"); - if (fp==NULL) return 0; + fp = BLI_fopen(str, "r"); + if (fp == NULL) return 0; /* free memory: */ - for (tmp= text->lines.first; tmp; tmp= tmp->next) { + for (tmp = text->lines.first; tmp; tmp = tmp->next) { MEM_freeN(tmp->line); if (tmp->format) MEM_freeN(tmp->format); } BLI_freelistN(&text->lines); - text->lines.first= text->lines.last= NULL; - text->curl= text->sell= NULL; + text->lines.first = text->lines.last = NULL; + text->curl = text->sell = NULL; /* clear undo buffer */ MEM_freeN(text->undo_buf); init_undo_text(text); fseek(fp, 0L, SEEK_END); - len= ftell(fp); + len = ftell(fp); fseek(fp, 0L, SEEK_SET); - text->undo_pos= -1; + text->undo_pos = -1; - buffer= MEM_mallocN(len, "text_buffer"); + buffer = MEM_mallocN(len, "text_buffer"); // under windows fread can return less then len bytes because // of CR stripping len = fread(buffer, 1, len, fp); @@ -325,40 +325,40 @@ int reopen_text(Text *text) fclose(fp); stat(str, &st); - text->mtime= st.st_mtime; - - text->nlines=0; - llen=0; - for (i=0; i<len; i++) { - if (buffer[i]=='\n') { - tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line= (char*) MEM_mallocN(llen+1, "textline_string"); - tmp->format= NULL; - - if (llen) memcpy(tmp->line, &buffer[i-llen], llen); - tmp->line[llen]=0; - tmp->len= llen; + text->mtime = st.st_mtime; + + text->nlines = 0; + llen = 0; + for (i = 0; i < len; i++) { + if (buffer[i] == '\n') { + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = (char *) MEM_mallocN(llen + 1, "textline_string"); + tmp->format = NULL; + + if (llen) memcpy(tmp->line, &buffer[i - llen], llen); + tmp->line[llen] = 0; + tmp->len = llen; cleanup_textline(tmp); BLI_addtail(&text->lines, tmp); text->nlines++; - llen=0; + llen = 0; continue; } llen++; } - if (llen!=0 || text->nlines==0) { - tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line= (char*) MEM_mallocN(llen+1, "textline_string"); - tmp->format= NULL; + if (llen != 0 || text->nlines == 0) { + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = (char *) MEM_mallocN(llen + 1, "textline_string"); + tmp->format = NULL; - if (llen) memcpy(tmp->line, &buffer[i-llen], llen); + if (llen) memcpy(tmp->line, &buffer[i - llen], llen); - tmp->line[llen]=0; - tmp->len= llen; + tmp->line[llen] = 0; + tmp->len = llen; cleanup_textline(tmp); @@ -366,16 +366,16 @@ int reopen_text(Text *text) text->nlines++; } - text->curl= text->sell= text->lines.first; - text->curc= text->selc= 0; + text->curl = text->sell = text->lines.first; + text->curc = text->selc = 0; MEM_freeN(buffer); return 1; } -Text *add_text(const char *file, const char *relpath) +Text *BKE_text_load(const char *file, const char *relpath) { - Main *bmain= G.main; + Main *bmain = G.main; FILE *fp; int i, llen, len; unsigned char *buffer; @@ -388,29 +388,29 @@ Text *add_text(const char *file, const char *relpath) if (relpath) /* can be NULL (bg mode) */ BLI_path_abs(str, relpath); - fp= BLI_fopen(str, "r"); - if (fp==NULL) return NULL; + fp = BLI_fopen(str, "r"); + if (fp == NULL) return NULL; - ta= alloc_libblock(&bmain->text, ID_TXT, BLI_path_basename(str)); - ta->id.us= 1; + ta = BKE_libblock_alloc(&bmain->text, ID_TXT, BLI_path_basename(str)); + ta->id.us = 1; - ta->lines.first= ta->lines.last= NULL; - ta->markers.first= ta->markers.last= NULL; - ta->curl= ta->sell= NULL; + ta->lines.first = ta->lines.last = NULL; + ta->markers.first = ta->markers.last = NULL; + ta->curl = ta->sell = NULL; - if ((U.flag & USER_TXT_TABSTOSPACES_DISABLE)==0) - ta->flags= TXT_TABSTOSPACES; + if ((U.flag & USER_TXT_TABSTOSPACES_DISABLE) == 0) + ta->flags = TXT_TABSTOSPACES; fseek(fp, 0L, SEEK_END); - len= ftell(fp); + len = ftell(fp); fseek(fp, 0L, SEEK_SET); - ta->name= MEM_mallocN(strlen(file)+1, "text_name"); + ta->name = MEM_mallocN(strlen(file) + 1, "text_name"); strcpy(ta->name, file); init_undo_text(ta); - buffer= MEM_mallocN(len, "text_buffer"); + buffer = MEM_mallocN(len, "text_buffer"); // under windows fread can return less then len bytes because // of CR stripping len = fread(buffer, 1, len, fp); @@ -418,26 +418,26 @@ Text *add_text(const char *file, const char *relpath) fclose(fp); stat(str, &st); - ta->mtime= st.st_mtime; - - ta->nlines=0; - llen=0; - for (i=0; i<len; i++) { - if (buffer[i]=='\n') { - tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line= (char*) MEM_mallocN(llen+1, "textline_string"); - tmp->format= NULL; - - if (llen) memcpy(tmp->line, &buffer[i-llen], llen); - tmp->line[llen]=0; - tmp->len= llen; + ta->mtime = st.st_mtime; + + ta->nlines = 0; + llen = 0; + for (i = 0; i < len; i++) { + if (buffer[i] == '\n') { + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = (char *) MEM_mallocN(llen + 1, "textline_string"); + tmp->format = NULL; + + if (llen) memcpy(tmp->line, &buffer[i - llen], llen); + tmp->line[llen] = 0; + tmp->len = llen; cleanup_textline(tmp); BLI_addtail(&ta->lines, tmp); ta->nlines++; - llen=0; + llen = 0; continue; } llen++; @@ -449,15 +449,15 @@ Text *add_text(const char *file, const char *relpath) * - file is empty. in this case new line is needed to start editing from. * - last characted in buffer is \n. in this case new line is needed to * deal with newline at end of file. (see [#28087]) (sergey) */ - if (llen!=0 || ta->nlines==0 || buffer[len-1]=='\n') { - tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line= (char*) MEM_mallocN(llen+1, "textline_string"); - tmp->format= NULL; + if (llen != 0 || ta->nlines == 0 || buffer[len - 1] == '\n') { + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = (char *) MEM_mallocN(llen + 1, "textline_string"); + tmp->format = NULL; - if (llen) memcpy(tmp->line, &buffer[i-llen], llen); + if (llen) memcpy(tmp->line, &buffer[i - llen], llen); - tmp->line[llen]=0; - tmp->len= llen; + tmp->line[llen] = 0; + tmp->len = llen; cleanup_textline(tmp); @@ -465,63 +465,63 @@ Text *add_text(const char *file, const char *relpath) ta->nlines++; } - ta->curl= ta->sell= ta->lines.first; - ta->curc= ta->selc= 0; + ta->curl = ta->sell = ta->lines.first; + ta->curc = ta->selc = 0; MEM_freeN(buffer); return ta; } -Text *copy_text(Text *ta) +Text *BKE_text_copy(Text *ta) { Text *tan; TextLine *line, *tmp; - tan= copy_libblock(&ta->id); + tan = BKE_libblock_copy(&ta->id); /* file name can be NULL */ if (ta->name) { - tan->name= MEM_mallocN(strlen(ta->name)+1, "text_name"); + tan->name = MEM_mallocN(strlen(ta->name) + 1, "text_name"); strcpy(tan->name, ta->name); } else { - tan->name= NULL; + tan->name = NULL; } tan->flags = ta->flags | TXT_ISDIRTY; - tan->lines.first= tan->lines.last= NULL; - tan->markers.first= tan->markers.last= NULL; - tan->curl= tan->sell= NULL; + tan->lines.first = tan->lines.last = NULL; + tan->markers.first = tan->markers.last = NULL; + tan->curl = tan->sell = NULL; - tan->nlines= ta->nlines; + tan->nlines = ta->nlines; - line= ta->lines.first; + line = ta->lines.first; /* Walk down, reconstructing */ while (line) { - tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line= MEM_mallocN(line->len+1, "textline_string"); - tmp->format= NULL; + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = MEM_mallocN(line->len + 1, "textline_string"); + tmp->format = NULL; strcpy(tmp->line, line->line); - tmp->len= line->len; + tmp->len = line->len; BLI_addtail(&tan->lines, tmp); - line= line->next; + line = line->next; } - tan->curl= tan->sell= tan->lines.first; - tan->curc= tan->selc= 0; + tan->curl = tan->sell = tan->lines.first; + tan->curc = tan->selc = 0; init_undo_text(tan); return tan; } -void unlink_text(Main *bmain, Text *text) +void BKE_text_unlink(Main *bmain, Text *text) { bScreen *scr; ScrArea *area; @@ -531,27 +531,27 @@ void unlink_text(Main *bmain, Text *text) bConstraint *con; short update; - for (ob=bmain->object.first; ob; ob=ob->id.next) { + for (ob = bmain->object.first; ob; ob = ob->id.next) { /* game controllers */ - for (cont=ob->controllers.first; cont; cont=cont->next) { - if (cont->type==CONT_PYTHON) { + for (cont = ob->controllers.first; cont; cont = cont->next) { + if (cont->type == CONT_PYTHON) { bPythonCont *pc; - pc= cont->data; - if (pc->text==text) pc->text= NULL; + pc = cont->data; + if (pc->text == text) pc->text = NULL; } } /* pyconstraints */ update = 0; - if (ob->type==OB_ARMATURE && ob->pose) { + if (ob->type == OB_ARMATURE && ob->pose) { bPoseChannel *pchan; - for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - for (con = pchan->constraints.first; con; con=con->next) { - if (con->type==CONSTRAINT_TYPE_PYTHON) { + for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { + for (con = pchan->constraints.first; con; con = con->next) { + if (con->type == CONSTRAINT_TYPE_PYTHON) { bPythonConstraint *data = con->data; - if (data->text==text) data->text = NULL; + if (data->text == text) data->text = NULL; update = 1; } @@ -559,10 +559,10 @@ void unlink_text(Main *bmain, Text *text) } } - for (con = ob->constraints.first; con; con=con->next) { - if (con->type==CONSTRAINT_TYPE_PYTHON) { + for (con = ob->constraints.first; con; con = con->next) { + if (con->type == CONSTRAINT_TYPE_PYTHON) { bPythonConstraint *data = con->data; - if (data->text==text) data->text = NULL; + if (data->text == text) data->text = NULL; update = 1; } } @@ -575,25 +575,25 @@ void unlink_text(Main *bmain, Text *text) // XXX nodeDynamicUnlinkText(&text->id); /* text space */ - for (scr= bmain->screen.first; scr; scr= scr->id.next) { - for (area= scr->areabase.first; area; area= area->next) { - for (sl= area->spacedata.first; sl; sl= sl->next) { - if (sl->spacetype==SPACE_TEXT) { - SpaceText *st= (SpaceText*) sl; - - if (st->text==text) { - st->text= NULL; - st->top= 0; + for (scr = bmain->screen.first; scr; scr = scr->id.next) { + for (area = scr->areabase.first; area; area = area->next) { + for (sl = area->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_TEXT) { + SpaceText *st = (SpaceText *) sl; + + if (st->text == text) { + st->text = NULL; + st->top = 0; } } } } } - text->id.us= 0; + text->id.us = 0; } -void clear_text(Text *text) /* called directly from rna */ +void BKE_text_clear(Text *text) /* called directly from rna */ { int oldstate; @@ -606,7 +606,7 @@ void clear_text(Text *text) /* called directly from rna */ txt_make_dirty(text); } -void write_text(Text *text, const char *str) /* called directly from rna */ +void BKE_text_write(Text *text, const char *str) /* called directly from rna */ { int oldstate; @@ -627,25 +627,25 @@ static void make_new_line(TextLine *line, char *newline) if (line->line) MEM_freeN(line->line); if (line->format) MEM_freeN(line->format); - line->line= newline; - line->len= strlen(newline); - line->format= NULL; + line->line = newline; + line->len = strlen(newline); + line->format = NULL; } static TextLine *txt_new_line(const char *str) { TextLine *tmp; - if (!str) str= ""; + if (!str) str = ""; - tmp= (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line= MEM_mallocN(strlen(str)+1, "textline_string"); - tmp->format= NULL; + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = MEM_mallocN(strlen(str) + 1, "textline_string"); + tmp->format = NULL; strcpy(tmp->line, str); - tmp->len= strlen(str); - tmp->next= tmp->prev= NULL; + tmp->len = strlen(str); + tmp->next = tmp->prev = NULL; return tmp; } @@ -654,14 +654,14 @@ static TextLine *txt_new_linen(const char *str, int n) { TextLine *tmp; - tmp= (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line= MEM_mallocN(n+1, "textline_string"); - tmp->format= NULL; + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = MEM_mallocN(n + 1, "textline_string"); + tmp->format = NULL; - BLI_strncpy(tmp->line, (str)? str: "", n+1); + BLI_strncpy(tmp->line, (str) ? str : "", n + 1); - tmp->len= strlen(tmp->line); - tmp->next= tmp->prev= NULL; + tmp->len = strlen(tmp->line); + tmp->next = tmp->prev = NULL; return tmp; } @@ -673,61 +673,61 @@ void txt_clean_text(Text *text) if (!text) return; if (!text->lines.first) { - if (text->lines.last) text->lines.first= text->lines.last; - else text->lines.first= text->lines.last= txt_new_line(NULL); + if (text->lines.last) text->lines.first = text->lines.last; + else text->lines.first = text->lines.last = txt_new_line(NULL); } - if (!text->lines.last) text->lines.last= text->lines.first; + if (!text->lines.last) text->lines.last = text->lines.first; - top= (TextLine **) &text->lines.first; - bot= (TextLine **) &text->lines.last; + top = (TextLine **) &text->lines.first; + bot = (TextLine **) &text->lines.last; - while ((*top)->prev) *top= (*top)->prev; - while ((*bot)->next) *bot= (*bot)->next; + while ((*top)->prev) *top = (*top)->prev; + while ((*bot)->next) *bot = (*bot)->next; if (!text->curl) { - if (text->sell) text->curl= text->sell; - else text->curl= text->lines.first; - text->curc= 0; + if (text->sell) text->curl = text->sell; + else text->curl = text->lines.first; + text->curc = 0; } if (!text->sell) { - text->sell= text->curl; - text->selc= 0; + text->sell = text->curl; + text->selc = 0; } } int txt_get_span(TextLine *from, TextLine *to) { - int ret=0; - TextLine *tmp= from; + int ret = 0; + TextLine *tmp = from; if (!to || !from) return 0; - if (from==to) return 0; + if (from == to) return 0; /* Look forwards */ while (tmp) { if (tmp == to) return ret; ret++; - tmp= tmp->next; + tmp = tmp->next; } /* Look backwards */ if (!tmp) { - tmp= from; - ret=0; + tmp = from; + ret = 0; while (tmp) { if (tmp == to) break; ret--; - tmp= tmp->prev; + tmp = tmp->prev; } - if (!tmp) ret=0; + if (!tmp) ret = 0; } return ret; } -static void txt_make_dirty (Text *text) +static void txt_make_dirty(Text *text) { text->flags |= TXT_ISDIRTY; #ifdef WITH_PYTHON @@ -739,30 +739,30 @@ static void txt_make_dirty (Text *text) /* Cursor utility functions */ /****************************/ -static void txt_curs_cur (Text *text, TextLine ***linep, int **charp) +static void txt_curs_cur(Text *text, TextLine ***linep, int **charp) { - *linep= &text->curl; *charp= &text->curc; + *linep = &text->curl; *charp = &text->curc; } -static void txt_curs_sel (Text *text, TextLine ***linep, int **charp) +static void txt_curs_sel(Text *text, TextLine ***linep, int **charp) { - *linep= &text->sell; *charp= &text->selc; + *linep = &text->sell; *charp = &text->selc; } -static void txt_curs_first (Text *text, TextLine **linep, int *charp) +static void txt_curs_first(Text *text, TextLine **linep, int *charp) { - if (text->curl==text->sell) { - *linep= text->curl; - if (text->curc<text->selc) *charp= text->curc; - else *charp= text->selc; + if (text->curl == text->sell) { + *linep = text->curl; + if (text->curc < text->selc) *charp = text->curc; + else *charp = text->selc; } - else if (txt_get_span(text->lines.first, text->curl)<txt_get_span(text->lines.first, text->sell)) { - *linep= text->curl; - *charp= text->curc; + else if (txt_get_span(text->lines.first, text->curl) < txt_get_span(text->lines.first, text->sell)) { + *linep = text->curl; + *charp = text->curc; } else { - *linep= text->sell; - *charp= text->selc; + *linep = text->sell; + *charp = text->selc; } } @@ -772,7 +772,7 @@ static void txt_curs_first (Text *text, TextLine **linep, int *charp) int txt_utf8_offset_to_index(const char *str, int offset) { - int index= 0, pos= 0; + int index = 0, pos = 0; while (pos != offset) { pos += BLI_str_utf8_size(str + pos); index++; @@ -782,7 +782,7 @@ int txt_utf8_offset_to_index(const char *str, int offset) int txt_utf8_index_to_offset(const char *str, int index) { - int offset= 0, pos= 0; + int offset = 0, pos = 0; while (pos != index) { offset += BLI_str_utf8_size(str + offset); pos++; @@ -796,7 +796,7 @@ static int txt_utf8_len(const char *src) { int len; - for (len=0; *src; len++) { + for (len = 0; *src; len++) { src += BLI_str_utf8_size(src); } @@ -817,12 +817,12 @@ void txt_move_up(Text *text, short sel) if ((*linep)->prev) { int index = txt_utf8_offset_to_index((*linep)->line, *charp); - *linep= (*linep)->prev; - if (index > txt_utf8_len((*linep)->line)) *charp= (*linep)->len; - else *charp= txt_utf8_index_to_offset((*linep)->line, index); + *linep = (*linep)->prev; + if (index > txt_utf8_len((*linep)->line)) *charp = (*linep)->len; + else *charp = txt_utf8_index_to_offset((*linep)->line, index); if (!undoing) - txt_undo_add_op(text, sel?UNDO_SUP:UNDO_CUP); + txt_undo_add_op(text, sel ? UNDO_SUP : UNDO_CUP); } else { txt_move_bol(text, sel); @@ -845,12 +845,12 @@ void txt_move_down(Text *text, short sel) if ((*linep)->next) { int index = txt_utf8_offset_to_index((*linep)->line, *charp); - *linep= (*linep)->next; - if (index > txt_utf8_len((*linep)->line)) *charp= (*linep)->len; - else *charp= txt_utf8_index_to_offset((*linep)->line, index); + *linep = (*linep)->next; + if (index > txt_utf8_len((*linep)->line)) *charp = (*linep)->len; + else *charp = txt_utf8_index_to_offset((*linep)->line, index); if (!undoing) - txt_undo_add_op(text, sel?UNDO_SDOWN:UNDO_CDOWN); + txt_undo_add_op(text, sel ? UNDO_SDOWN : UNDO_CDOWN); } else { txt_move_eol(text, sel); @@ -862,49 +862,49 @@ void txt_move_down(Text *text, short sel) void txt_move_left(Text *text, short sel) { TextLine **linep; - int *charp, oundoing= undoing; - int tabsize= 0, i= 0; + int *charp, oundoing = undoing; + int tabsize = 0, i = 0; if (!text) return; if (sel) txt_curs_sel(text, &linep, &charp); else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); } if (!*linep) return; - undoing= 1; + undoing = 1; - if (*charp== 0) { + if (*charp == 0) { if ((*linep)->prev) { txt_move_up(text, sel); - *charp= (*linep)->len; + *charp = (*linep)->len; } } else { // do nice left only if there are only spaces // TXT_TABSIZE hardcoded in DNA_text_types.h if (text->flags & TXT_TABSTOSPACES) { - tabsize= (*charp < TXT_TABSIZE) ? *charp : TXT_TABSIZE; + tabsize = (*charp < TXT_TABSIZE) ? *charp : TXT_TABSIZE; - for (i=0; i<(*charp); i++) + for (i = 0; i < (*charp); i++) if ((*linep)->line[i] != ' ') { - tabsize= 0; + tabsize = 0; break; } // if in the middle of the space-tab if (tabsize && (*charp) % TXT_TABSIZE != 0) - tabsize= ((*charp) % TXT_TABSIZE); + tabsize = ((*charp) % TXT_TABSIZE); } if (tabsize) - (*charp)-= tabsize; + (*charp) -= tabsize; else { - const char *prev= BLI_str_prev_char_utf8((*linep)->line + *charp); - *charp= prev - (*linep)->line; + const char *prev = BLI_str_prev_char_utf8((*linep)->line + *charp); + *charp = prev - (*linep)->line; } } - undoing= oundoing; - if (!undoing) txt_undo_add_op(text, sel?UNDO_SLEFT:UNDO_CLEFT); + undoing = oundoing; + if (!undoing) txt_undo_add_op(text, sel ? UNDO_SLEFT : UNDO_CLEFT); if (!sel) txt_pop_sel(text); } @@ -912,104 +912,90 @@ void txt_move_left(Text *text, short sel) void txt_move_right(Text *text, short sel) { TextLine **linep; - int *charp, oundoing= undoing, do_tab= 0, i; + int *charp, oundoing = undoing, do_tab = 0, i; if (!text) return; if (sel) txt_curs_sel(text, &linep, &charp); else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); } if (!*linep) return; - undoing= 1; + undoing = 1; - if (*charp== (*linep)->len) { + if (*charp == (*linep)->len) { if ((*linep)->next) { txt_move_down(text, sel); - *charp= 0; + *charp = 0; } } else { // do nice right only if there are only spaces // spaces hardcoded in DNA_text_types.h - if (text->flags & TXT_TABSTOSPACES && (*linep)->line[*charp]== ' ') { - do_tab= 1; - for (i=0; i<*charp; i++) - if ((*linep)->line[i]!= ' ') { - do_tab= 0; + if (text->flags & TXT_TABSTOSPACES && (*linep)->line[*charp] == ' ') { + do_tab = 1; + for (i = 0; i < *charp; i++) + if ((*linep)->line[i] != ' ') { + do_tab = 0; break; } } if (do_tab) { - int tabsize= (*charp) % TXT_TABSIZE + 1; - for (i=*charp+1; (*linep)->line[i]==' ' && tabsize<TXT_TABSIZE; i++) + int tabsize = (*charp) % TXT_TABSIZE + 1; + for (i = *charp + 1; (*linep)->line[i] == ' ' && tabsize < TXT_TABSIZE; i++) tabsize++; - (*charp)= i; + (*charp) = i; } - else (*charp)+= BLI_str_utf8_size((*linep)->line + *charp); + else (*charp) += BLI_str_utf8_size((*linep)->line + *charp); } - undoing= oundoing; - if (!undoing) txt_undo_add_op(text, sel?UNDO_SRIGHT:UNDO_CRIGHT); + undoing = oundoing; + if (!undoing) txt_undo_add_op(text, sel ? UNDO_SRIGHT : UNDO_CRIGHT); if (!sel) txt_pop_sel(text); } void txt_jump_left(Text *text, short sel) { - TextLine **linep, *oldl; - int *charp, oldc, oldflags; - unsigned char oldu; - + TextLine **linep; + int *charp, oldc; + if (!text) return; if (sel) txt_curs_sel(text, &linep, &charp); else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); } if (!*linep) return; - - oldflags = text->flags; - text->flags &= ~TXT_TABSTOSPACES; - - oldl= *linep; - oldc= *charp; - oldu= undoing; - undoing= 1; /* Don't push individual moves to undo stack */ + oldc = *charp; BLI_str_cursor_step_utf8((*linep)->line, (*linep)->len, - charp, STRCUR_DIR_PREV, + charp, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM); - - text->flags = oldflags; - - undoing= oldu; - if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); + + if (!sel) txt_pop_sel(text); + if (!undoing) { + int span = txt_get_span(text->lines.first, *linep); + txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, span, oldc, span, (unsigned short)*charp); + } } void txt_jump_right(Text *text, short sel) { - TextLine **linep, *oldl; - int *charp, oldc, oldflags; - unsigned char oldu; - + TextLine **linep; + int *charp, oldc; + if (!text) return; if (sel) txt_curs_sel(text, &linep, &charp); else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); } if (!*linep) return; - - oldflags = text->flags; - text->flags &= ~TXT_TABSTOSPACES; - - oldl= *linep; - oldc= *charp; - oldu= undoing; - undoing= 1; /* Don't push individual moves to undo stack */ - + oldc = *charp; + BLI_str_cursor_step_utf8((*linep)->line, (*linep)->len, - charp, STRCUR_DIR_NEXT, + charp, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM); - - text->flags = oldflags; - - undoing= oldu; - if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); + + if (!sel) txt_pop_sel(text); + if (!undoing) { + int span = txt_get_span(text->lines.first, *linep); + txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, span, oldc, span, (unsigned short)*charp); + } } void txt_move_bol(Text *text, short sel) @@ -1021,12 +1007,12 @@ void txt_move_bol(Text *text, short sel) if (sel) txt_curs_sel(text, &linep, &charp); else txt_curs_cur(text, &linep, &charp); if (!*linep) return; - old= *charp; + old = *charp; - *charp= 0; + *charp = 0; if (!sel) txt_pop_sel(text); - if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); + if (!undoing) txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); } void txt_move_eol(Text *text, short sel) @@ -1038,12 +1024,12 @@ void txt_move_eol(Text *text, short sel) if (sel) txt_curs_sel(text, &linep, &charp); else txt_curs_cur(text, &linep, &charp); if (!*linep) return; - old= *charp; + old = *charp; - *charp= (*linep)->len; + *charp = (*linep)->len; if (!sel) txt_pop_sel(text); - if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); + if (!undoing) txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); } void txt_move_bof(Text *text, short sel) @@ -1055,13 +1041,13 @@ void txt_move_bof(Text *text, short sel) if (sel) txt_curs_sel(text, &linep, &charp); else txt_curs_cur(text, &linep, &charp); if (!*linep) return; - old= *charp; + old = *charp; - *linep= text->lines.first; - *charp= 0; + *linep = text->lines.first; + *charp = 0; if (!sel) txt_pop_sel(text); - if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); + if (!undoing) txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); } void txt_move_eof(Text *text, short sel) @@ -1073,13 +1059,13 @@ void txt_move_eof(Text *text, short sel) if (sel) txt_curs_sel(text, &linep, &charp); else txt_curs_cur(text, &linep, &charp); if (!*linep) return; - old= *charp; + old = *charp; - *linep= text->lines.last; - *charp= (*linep)->len; + *linep = text->lines.last; + *charp = (*linep)->len; if (!sel) txt_pop_sel(text); - if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); + if (!undoing) txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); } void txt_move_toline(Text *text, unsigned int line, short sel) @@ -1098,71 +1084,71 @@ void txt_move_to(Text *text, unsigned int line, unsigned int ch, short sel) if (sel) txt_curs_sel(text, &linep, &charp); else txt_curs_cur(text, &linep, &charp); if (!*linep) return; - oldc= *charp; - oldl= *linep; + oldc = *charp; + oldl = *linep; - *linep= text->lines.first; - for (i=0; i<line; i++) { - if ((*linep)->next) *linep= (*linep)->next; + *linep = text->lines.first; + for (i = 0; i < line; i++) { + if ((*linep)->next) *linep = (*linep)->next; else break; } - if (ch>(unsigned int)((*linep)->len)) - ch= (unsigned int)((*linep)->len); - *charp= ch; + if (ch > (unsigned int)((*linep)->len)) + ch = (unsigned int)((*linep)->len); + *charp = ch; if (!sel) txt_pop_sel(text); - if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); + if (!undoing) txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); } /****************************/ /* Text selection functions */ /****************************/ -static void txt_curs_swap (Text *text) +static void txt_curs_swap(Text *text) { TextLine *tmpl; int tmpc; - tmpl= text->curl; - text->curl= text->sell; - text->sell= tmpl; - - tmpc= text->curc; - text->curc= text->selc; - text->selc= tmpc; + tmpl = text->curl; + text->curl = text->sell; + text->sell = tmpl; + + tmpc = text->curc; + text->curc = text->selc; + text->selc = tmpc; if (!undoing) txt_undo_add_op(text, UNDO_SWAP); } -static void txt_pop_first (Text *text) +static void txt_pop_first(Text *text) { - if (txt_get_span(text->curl, text->sell)<0 || - (text->curl==text->sell && text->curc>text->selc)) { + if (txt_get_span(text->curl, text->sell) < 0 || + (text->curl == text->sell && text->curc > text->selc)) { txt_curs_swap(text); } if (!undoing) txt_undo_add_toop(text, UNDO_STO, - txt_get_span(text->lines.first, text->sell), - text->selc, - txt_get_span(text->lines.first, text->curl), - text->curc); + txt_get_span(text->lines.first, text->sell), + text->selc, + txt_get_span(text->lines.first, text->curl), + text->curc); txt_pop_sel(text); } -static void txt_pop_last (Text *text) +static void txt_pop_last(Text *text) { - if (txt_get_span(text->curl, text->sell)>0 || - (text->curl==text->sell && text->curc<text->selc)) { + if (txt_get_span(text->curl, text->sell) > 0 || + (text->curl == text->sell && text->curc < text->selc)) { txt_curs_swap(text); } if (!undoing) txt_undo_add_toop(text, UNDO_STO, - txt_get_span(text->lines.first, text->sell), - text->selc, - txt_get_span(text->lines.first, text->curl), - text->curc); + txt_get_span(text->lines.first, text->sell), + text->selc, + txt_get_span(text->lines.first, text->curl), + text->curc); txt_pop_sel(text); } @@ -1172,8 +1158,8 @@ static void txt_pop_last (Text *text) void txt_pop_sel(Text *text) { - text->sell= text->curl; - text->selc= text->curc; + text->sell = text->curl; + text->selc = text->curc; } void txt_order_cursors(Text *text) @@ -1182,7 +1168,7 @@ void txt_order_cursors(Text *text) if (!text->curl) return; if (!text->sell) return; - /* Flip so text->curl is before text->sell */ + /* Flip so text->curl is before text->sell */ if ((txt_get_span(text->curl, text->sell) < 0) || (text->curl == text->sell && text->curc > text->selc)) { @@ -1192,10 +1178,10 @@ void txt_order_cursors(Text *text) int txt_has_sel(Text *text) { - return ((text->curl!=text->sell) || (text->curc!=text->selc)); + return ((text->curl != text->sell) || (text->curc != text->selc)); } -static void txt_delete_sel (Text *text) +static void txt_delete_sel(Text *text) { TextLine *tmpl; TextMarker *mrk; @@ -1211,62 +1197,62 @@ static void txt_delete_sel (Text *text) txt_order_cursors(text); if (!undoing) { - buf= txt_sel_to_buf(text); + buf = txt_sel_to_buf(text); txt_undo_add_block(text, UNDO_DBLOCK, buf); MEM_freeN(buf); } - buf= MEM_mallocN(text->curc+(text->sell->len - text->selc)+1, "textline_string"); + buf = MEM_mallocN(text->curc + (text->sell->len - text->selc) + 1, "textline_string"); if (text->curl != text->sell) { txt_clear_marker_region(text, text->curl, text->curc, text->curl->len, 0, 0); - move= txt_get_span(text->curl, text->sell); + move = txt_get_span(text->curl, text->sell); } else { - mrk= txt_find_marker_region(text, text->curl, text->curc, text->selc, 0, 0); + mrk = txt_find_marker_region(text, text->curl, text->curc, text->selc, 0, 0); if (mrk && (mrk->start > text->curc || mrk->end < text->selc)) txt_clear_marker_region(text, text->curl, text->curc, text->selc, 0, 0); - move= 0; + move = 0; } - mrk= txt_find_marker_region(text, text->sell, text->selc-1, text->sell->len, 0, 0); + mrk = txt_find_marker_region(text, text->sell, text->selc - 1, text->sell->len, 0, 0); if (mrk) { - lineno= mrk->lineno; + lineno = mrk->lineno; do { mrk->lineno -= move; if (mrk->start > text->curc) mrk->start -= text->selc - text->curc; mrk->end -= text->selc - text->curc; - mrk= mrk->next; - } while (mrk && mrk->lineno==lineno); + mrk = mrk->next; + } while (mrk && mrk->lineno == lineno); } strncpy(buf, text->curl->line, text->curc); - strcpy(buf+text->curc, text->sell->line + text->selc); - buf[text->curc+(text->sell->len - text->selc)]=0; + strcpy(buf + text->curc, text->sell->line + text->selc); + buf[text->curc + (text->sell->len - text->selc)] = 0; make_new_line(text->curl, buf); - tmpl= text->sell; + tmpl = text->sell; while (tmpl != text->curl) { - tmpl= tmpl->prev; + tmpl = tmpl->prev; if (!tmpl) break; txt_delete_line(text, tmpl->next); } - text->sell= text->curl; - text->selc= text->curc; + text->sell = text->curl; + text->selc = text->curc; } void txt_sel_all(Text *text) { if (!text) return; - text->curl= text->lines.first; - text->curc= 0; + text->curl = text->lines.first; + text->curc = 0; - text->sell= text->lines.last; - text->selc= text->sell->len; + text->sell = text->lines.last; + text->selc = text->sell->len; } void txt_sel_line(Text *text) @@ -1274,16 +1260,16 @@ void txt_sel_line(Text *text) if (!text) return; if (!text->curl) return; - text->curc= 0; - text->sell= text->curl; - text->selc= text->sell->len; + text->curc = 0; + text->sell = text->curl; + text->selc = text->sell->len; } /***************************/ /* Cut and paste functions */ /***************************/ -char *txt_to_buf (Text *text) +char *txt_to_buf(Text *text) { int length; TextLine *tmp, *linef, *linel; @@ -1295,53 +1281,53 @@ char *txt_to_buf (Text *text) if (!text->sell) return NULL; if (!text->lines.first) return NULL; - linef= text->lines.first; - charf= 0; + linef = text->lines.first; + charf = 0; - linel= text->lines.last; - charl= linel->len; + linel = text->lines.last; + charl = linel->len; if (linef == text->lines.last) { - length= charl-charf; + length = charl - charf; - buf= MEM_mallocN(length+2, "text buffer"); + buf = MEM_mallocN(length + 2, "text buffer"); - BLI_strncpy(buf, linef->line + charf, length+1); - buf[length]=0; + BLI_strncpy(buf, linef->line + charf, length + 1); + buf[length] = 0; } else { - length= linef->len - charf; - length+= charl; - length+= 2; /* For the 2 '\n' */ + length = linef->len - charf; + length += charl; + length += 2; /* For the 2 '\n' */ - tmp= linef->next; - while (tmp && tmp!= linel) { - length+= tmp->len+1; - tmp= tmp->next; + tmp = linef->next; + while (tmp && tmp != linel) { + length += tmp->len + 1; + tmp = tmp->next; } - buf= MEM_mallocN(length+1, "cut buffer"); + buf = MEM_mallocN(length + 1, "cut buffer"); - strncpy(buf, linef->line + charf, linef->len-charf); - length= linef->len - charf; + strncpy(buf, linef->line + charf, linef->len - charf); + length = linef->len - charf; - buf[length++]='\n'; + buf[length++] = '\n'; - tmp= linef->next; - while (tmp && tmp!=linel) { - strncpy(buf+length, tmp->line, tmp->len); - length+= tmp->len; + tmp = linef->next; + while (tmp && tmp != linel) { + strncpy(buf + length, tmp->line, tmp->len); + length += tmp->len; - buf[length++]='\n'; + buf[length++] = '\n'; - tmp= tmp->next; + tmp = tmp->next; } - strncpy(buf+length, linel->line, charl); - length+= charl; + strncpy(buf + length, linel->line, charl); + length += charl; /* python compiler wants an empty end line */ - buf[length++]='\n'; - buf[length]=0; + buf[length++] = '\n'; + buf[length] = 0; } return buf; @@ -1350,34 +1336,34 @@ char *txt_to_buf (Text *text) int txt_find_string(Text *text, const char *findstr, int wrap, int match_case) { TextLine *tl, *startl; - char *s= NULL; + char *s = NULL; if (!text || !text->curl || !text->sell) return 0; txt_order_cursors(text); - tl= startl= text->sell; + tl = startl = text->sell; - if (match_case) s= strstr(&tl->line[text->selc], findstr); - else s= BLI_strcasestr(&tl->line[text->selc], findstr); + if (match_case) s = strstr(&tl->line[text->selc], findstr); + else s = BLI_strcasestr(&tl->line[text->selc], findstr); while (!s) { - tl= tl->next; + tl = tl->next; if (!tl) { if (wrap) - tl= text->lines.first; + tl = text->lines.first; else break; } - if (match_case) s= strstr(tl->line, findstr); - else s= BLI_strcasestr(tl->line, findstr); - if (tl==startl) + if (match_case) s = strstr(tl->line, findstr); + else s = BLI_strcasestr(tl->line, findstr); + if (tl == startl) break; } if (s) { - int newl= txt_get_span(text->lines.first, tl); - int newc= (int)(s-tl->line); + int newl = txt_get_span(text->lines.first, tl); + int newc = (int)(s - tl->line); txt_move_to(text, newl, newc, 0); txt_move_to(text, newl, newc + strlen(findstr), 1); return 1; @@ -1386,10 +1372,10 @@ int txt_find_string(Text *text, const char *findstr, int wrap, int match_case) return 0; } -char *txt_sel_to_buf (Text *text) +char *txt_sel_to_buf(Text *text) { char *buf; - int length=0; + int length = 0; TextLine *tmp, *linef, *linel; int charf, charl; @@ -1397,71 +1383,71 @@ char *txt_sel_to_buf (Text *text) if (!text->curl) return NULL; if (!text->sell) return NULL; - if (text->curl==text->sell) { - linef= linel= text->curl; + if (text->curl == text->sell) { + linef = linel = text->curl; if (text->curc < text->selc) { - charf= text->curc; - charl= text->selc; + charf = text->curc; + charl = text->selc; } else { - charf= text->selc; - charl= text->curc; + charf = text->selc; + charl = text->curc; } } - else if (txt_get_span(text->curl, text->sell)<0) { - linef= text->sell; - linel= text->curl; + else if (txt_get_span(text->curl, text->sell) < 0) { + linef = text->sell; + linel = text->curl; - charf= text->selc; - charl= text->curc; + charf = text->selc; + charl = text->curc; } else { - linef= text->curl; - linel= text->sell; + linef = text->curl; + linel = text->sell; - charf= text->curc; - charl= text->selc; + charf = text->curc; + charl = text->selc; } if (linef == linel) { - length= charl-charf; + length = charl - charf; - buf= MEM_mallocN(length+1, "sel buffer"); + buf = MEM_mallocN(length + 1, "sel buffer"); - BLI_strncpy(buf, linef->line + charf, length+1); + BLI_strncpy(buf, linef->line + charf, length + 1); } else { - length+= linef->len - charf; - length+= charl; + length += linef->len - charf; + length += charl; length++; /* For the '\n' */ - tmp= linef->next; - while (tmp && tmp!= linel) { - length+= tmp->len+1; - tmp= tmp->next; + tmp = linef->next; + while (tmp && tmp != linel) { + length += tmp->len + 1; + tmp = tmp->next; } - buf= MEM_mallocN(length+1, "sel buffer"); + buf = MEM_mallocN(length + 1, "sel buffer"); - strncpy(buf, linef->line+ charf, linef->len-charf); - length= linef->len-charf; + strncpy(buf, linef->line + charf, linef->len - charf); + length = linef->len - charf; - buf[length++]='\n'; + buf[length++] = '\n'; - tmp= linef->next; - while (tmp && tmp!=linel) { - strncpy(buf+length, tmp->line, tmp->len); - length+= tmp->len; + tmp = linef->next; + while (tmp && tmp != linel) { + strncpy(buf + length, tmp->line, tmp->len); + length += tmp->len; - buf[length++]='\n'; + buf[length++] = '\n'; - tmp= tmp->next; + tmp = tmp->next; } - strncpy(buf+length, linel->line, charl); - length+= charl; + strncpy(buf + length, linel->line, charl); + length += charl; - buf[length]=0; + buf[length] = 0; } return buf; @@ -1471,16 +1457,16 @@ static void txt_shift_markers(Text *text, int lineno, int count) { TextMarker *marker; - for (marker=text->markers.first; marker; marker= marker->next) - if (marker->lineno>=lineno) { - marker->lineno+= count; + for (marker = text->markers.first; marker; marker = marker->next) + if (marker->lineno >= lineno) { + marker->lineno += count; } } void txt_insert_buf(Text *text, const char *in_buffer) { - int l=0, u, len, lineno= -1, count= 0; - size_t i=0, j; + int l = 0, u, len, lineno = -1, count = 0; + size_t i = 0, j; TextLine *add; char *buffer; @@ -1489,35 +1475,35 @@ void txt_insert_buf(Text *text, const char *in_buffer) txt_delete_sel(text); - len= strlen(in_buffer); - buffer= BLI_strdupn(in_buffer, len); - len+= txt_extended_ascii_as_utf8(&buffer); + len = strlen(in_buffer); + buffer = BLI_strdupn(in_buffer, len); + len += txt_extended_ascii_as_utf8(&buffer); if (!undoing) txt_undo_add_block(text, UNDO_IBLOCK, buffer); - u= undoing; - undoing= 1; + u = undoing; + undoing = 1; /* Read the first line (or as close as possible */ - while (buffer[i] && buffer[i]!='\n') + while (buffer[i] && buffer[i] != '\n') txt_add_raw_char(text, BLI_str_utf8_as_unicode_step(buffer, &i)); - if (buffer[i]=='\n') txt_split_curline(text); + if (buffer[i] == '\n') txt_split_curline(text); else { undoing = u; MEM_freeN(buffer); return; } i++; /* Read as many full lines as we can */ - lineno= txt_get_span(text->lines.first, text->curl); + lineno = txt_get_span(text->lines.first, text->curl); - while (i<len) { - l=0; + while (i < len) { + l = 0; - while (buffer[i] && buffer[i]!='\n') { + while (buffer[i] && buffer[i] != '\n') { i++; l++; } - if (buffer[i]=='\n') { - add= txt_new_linen(buffer +(i-l), l); + if (buffer[i] == '\n') { + add = txt_new_linen(buffer + (i - l), l); BLI_insertlinkbefore(&text->lines, text->curl, add); i++; count++; @@ -1525,10 +1511,10 @@ void txt_insert_buf(Text *text, const char *in_buffer) else { if (count) { txt_shift_markers(text, lineno, count); - count= 0; + count = 0; } - for (j= i-l; j<i && j<len; ) + for (j = i - l; j < i && j < len; ) txt_add_raw_char(text, BLI_str_utf8_as_unicode_step(buffer, &j)); break; } @@ -1540,7 +1526,7 @@ void txt_insert_buf(Text *text, const char *in_buffer) txt_shift_markers(text, lineno, count); } - undoing= u; + undoing = u; } /******************/ @@ -1549,18 +1535,18 @@ void txt_insert_buf(Text *text, const char *in_buffer) static int max_undo_test(Text *text, int x) { - while (text->undo_pos+x >= text->undo_len) { - if (text->undo_len*2 > TXT_MAX_UNDO) { + while (text->undo_pos + x >= text->undo_len) { + if (text->undo_len * 2 > TXT_MAX_UNDO) { /* XXX error("Undo limit reached, buffer cleared\n"); */ MEM_freeN(text->undo_buf); init_undo_text(text); return 0; } else { - void *tmp= text->undo_buf; - text->undo_buf= MEM_callocN(text->undo_len*2, "undo buf"); + void *tmp = text->undo_buf; + text->undo_buf = MEM_callocN(text->undo_len * 2, "undo buf"); memcpy(text->undo_buf, tmp, text->undo_len); - text->undo_len*=2; + text->undo_len *= 2; MEM_freeN(tmp); } } @@ -1570,218 +1556,218 @@ static int max_undo_test(Text *text, int x) static void dump_buffer(Text *text) { - int i= 0; + int i = 0; - while (i++<text->undo_pos) printf("%d: %d %c\n", i, text->undo_buf[i], text->undo_buf[i]); + while (i++ < text->undo_pos) printf("%d: %d %c\n", i, text->undo_buf[i], text->undo_buf[i]); } void txt_print_undo(Text *text) { - int i= 0; + int i = 0; int op; const char *ops; int linep, charp; dump_buffer(text); - printf ("---< Undo Buffer >---\n"); + printf("---< Undo Buffer >---\n"); - printf ("UndoPosition is %d\n", text->undo_pos); + printf("UndoPosition is %d\n", text->undo_pos); - while (i<=text->undo_pos) { - op= text->undo_buf[i]; + while (i <= text->undo_pos) { + op = text->undo_buf[i]; - if (op==UNDO_CLEFT) { - ops= "Cursor left"; + if (op == UNDO_CLEFT) { + ops = "Cursor left"; } - else if (op==UNDO_CRIGHT) { - ops= "Cursor right"; + else if (op == UNDO_CRIGHT) { + ops = "Cursor right"; } - else if (op==UNDO_CUP) { - ops= "Cursor up"; + else if (op == UNDO_CUP) { + ops = "Cursor up"; } - else if (op==UNDO_CDOWN) { - ops= "Cursor down"; + else if (op == UNDO_CDOWN) { + ops = "Cursor down"; } - else if (op==UNDO_SLEFT) { - ops= "Selection left"; + else if (op == UNDO_SLEFT) { + ops = "Selection left"; } - else if (op==UNDO_SRIGHT) { - ops= "Selection right"; + else if (op == UNDO_SRIGHT) { + ops = "Selection right"; } - else if (op==UNDO_SUP) { - ops= "Selection up"; + else if (op == UNDO_SUP) { + ops = "Selection up"; } - else if (op==UNDO_SDOWN) { - ops= "Selection down"; + else if (op == UNDO_SDOWN) { + ops = "Selection down"; } - else if (op==UNDO_STO) { - ops= "Selection "; + else if (op == UNDO_STO) { + ops = "Selection "; } - else if (op==UNDO_CTO) { - ops= "Cursor "; + else if (op == UNDO_CTO) { + ops = "Cursor "; } - else if (op==UNDO_INSERT_1) { - ops= "Insert ascii "; + else if (op == UNDO_INSERT_1) { + ops = "Insert ascii "; } - else if (op==UNDO_INSERT_2) { - ops= "Insert 2 bytes "; + else if (op == UNDO_INSERT_2) { + ops = "Insert 2 bytes "; } - else if (op==UNDO_INSERT_3) { - ops= "Insert 3 bytes "; + else if (op == UNDO_INSERT_3) { + ops = "Insert 3 bytes "; } - else if (op==UNDO_INSERT_4) { - ops= "Insert unicode "; + else if (op == UNDO_INSERT_4) { + ops = "Insert unicode "; } - else if (op==UNDO_BS_1) { - ops= "Backspace for ascii "; + else if (op == UNDO_BS_1) { + ops = "Backspace for ascii "; } - else if (op==UNDO_BS_2) { - ops= "Backspace for 2 bytes "; + else if (op == UNDO_BS_2) { + ops = "Backspace for 2 bytes "; } - else if (op==UNDO_BS_3) { - ops= "Backspace for 3 bytes "; + else if (op == UNDO_BS_3) { + ops = "Backspace for 3 bytes "; } - else if (op==UNDO_BS_4) { - ops= "Backspace for unicode "; + else if (op == UNDO_BS_4) { + ops = "Backspace for unicode "; } - else if (op==UNDO_DEL_1) { - ops= "Delete ascii "; + else if (op == UNDO_DEL_1) { + ops = "Delete ascii "; } - else if (op==UNDO_DEL_2) { - ops= "Delete 2 bytes "; + else if (op == UNDO_DEL_2) { + ops = "Delete 2 bytes "; } - else if (op==UNDO_DEL_3) { - ops= "Delete 3 bytes "; + else if (op == UNDO_DEL_3) { + ops = "Delete 3 bytes "; } - else if (op==UNDO_DEL_4) { - ops= "Delete unicode "; + else if (op == UNDO_DEL_4) { + ops = "Delete unicode "; } - else if (op==UNDO_SWAP) { - ops= "Cursor swap"; + else if (op == UNDO_SWAP) { + ops = "Cursor swap"; } - else if (op==UNDO_DBLOCK) { - ops= "Delete text block"; + else if (op == UNDO_DBLOCK) { + ops = "Delete text block"; } - else if (op==UNDO_IBLOCK) { - ops= "Insert text block"; + else if (op == UNDO_IBLOCK) { + ops = "Insert text block"; } - else if (op==UNDO_INDENT) { - ops= "Indent "; + else if (op == UNDO_INDENT) { + ops = "Indent "; } - else if (op==UNDO_UNINDENT) { - ops= "Unindent "; + else if (op == UNDO_UNINDENT) { + ops = "Unindent "; } - else if (op==UNDO_COMMENT) { - ops= "Comment "; + else if (op == UNDO_COMMENT) { + ops = "Comment "; } - else if (op==UNDO_UNCOMMENT) { - ops= "Uncomment "; + else if (op == UNDO_UNCOMMENT) { + ops = "Uncomment "; } else { - ops= "Unknown"; + ops = "Unknown"; } - printf ("Op (%o) at %d = %s", op, i, ops); + printf("Op (%o) at %d = %s", op, i, ops); if (op >= UNDO_INSERT_1 && op <= UNDO_DEL_4) { i++; - printf (" - Char is "); + printf(" - Char is "); switch (op) { case UNDO_INSERT_1: case UNDO_BS_1: case UNDO_DEL_1: - printf ("%c", text->undo_buf[i]); + printf("%c", text->undo_buf[i]); i++; break; case UNDO_INSERT_2: case UNDO_BS_2: case UNDO_DEL_2: - printf ("%c%c", text->undo_buf[i], text->undo_buf[i+1]); - i+=2; + printf("%c%c", text->undo_buf[i], text->undo_buf[i + 1]); + i += 2; break; case UNDO_INSERT_3: case UNDO_BS_3: case UNDO_DEL_3: - printf ("%c%c%c", text->undo_buf[i], text->undo_buf[i+1], text->undo_buf[i+2]); - i+=3; + printf("%c%c%c", text->undo_buf[i], text->undo_buf[i + 1], text->undo_buf[i + 2]); + i += 3; break; case UNDO_INSERT_4: case UNDO_BS_4: case UNDO_DEL_4: { unsigned int uc; - char c[BLI_UTF8_MAX+1]; + char c[BLI_UTF8_MAX + 1]; size_t c_len; - uc= text->undo_buf[i]; i++; - uc= uc+(text->undo_buf[i]<<8); i++; - uc= uc+(text->undo_buf[i]<<16); i++; - uc= uc+(text->undo_buf[i]<<24); i++; - c_len= BLI_str_utf8_from_unicode(uc, c); - c[c_len]= '\0'; + uc = text->undo_buf[i]; i++; + uc = uc + (text->undo_buf[i] << 8); i++; + uc = uc + (text->undo_buf[i] << 16); i++; + uc = uc + (text->undo_buf[i] << 24); i++; + c_len = BLI_str_utf8_from_unicode(uc, c); + c[c_len] = '\0'; puts(c); } } } - else if (op==UNDO_STO || op==UNDO_CTO) { + else if (op == UNDO_STO || op == UNDO_CTO) { i++; - charp= text->undo_buf[i]; i++; - charp= charp+(text->undo_buf[i]<<8); i++; + charp = text->undo_buf[i]; i++; + charp = charp + (text->undo_buf[i] << 8); i++; - linep= text->undo_buf[i]; i++; - linep= linep+(text->undo_buf[i]<<8); i++; - linep= linep+(text->undo_buf[i]<<16); i++; - linep= linep+(text->undo_buf[i]<<24); i++; + linep = text->undo_buf[i]; i++; + linep = linep + (text->undo_buf[i] << 8); i++; + linep = linep + (text->undo_buf[i] << 16); i++; + linep = linep + (text->undo_buf[i] << 24); i++; - printf ("to <%d, %d> ", linep, charp); + printf("to <%d, %d> ", linep, charp); - charp= text->undo_buf[i]; i++; - charp= charp+(text->undo_buf[i]<<8); i++; + charp = text->undo_buf[i]; i++; + charp = charp + (text->undo_buf[i] << 8); i++; - linep= text->undo_buf[i]; i++; - linep= linep+(text->undo_buf[i]<<8); i++; - linep= linep+(text->undo_buf[i]<<16); i++; - linep= linep+(text->undo_buf[i]<<24); i++; + linep = text->undo_buf[i]; i++; + linep = linep + (text->undo_buf[i] << 8); i++; + linep = linep + (text->undo_buf[i] << 16); i++; + linep = linep + (text->undo_buf[i] << 24); i++; - printf ("from <%d, %d>", linep, charp); + printf("from <%d, %d>", linep, charp); } - else if (op==UNDO_DBLOCK || op==UNDO_IBLOCK) { + else if (op == UNDO_DBLOCK || op == UNDO_IBLOCK) { i++; - linep= text->undo_buf[i]; i++; - linep= linep+(text->undo_buf[i]<<8); i++; - linep= linep+(text->undo_buf[i]<<16); i++; - linep= linep+(text->undo_buf[i]<<24); i++; + linep = text->undo_buf[i]; i++; + linep = linep + (text->undo_buf[i] << 8); i++; + linep = linep + (text->undo_buf[i] << 16); i++; + linep = linep + (text->undo_buf[i] << 24); i++; - printf (" (length %d) <", linep); + printf(" (length %d) <", linep); - while (linep>0) { + while (linep > 0) { putchar(text->undo_buf[i]); linep--; i++; } - linep= text->undo_buf[i]; i++; - linep= linep+(text->undo_buf[i]<<8); i++; - linep= linep+(text->undo_buf[i]<<16); i++; - linep= linep+(text->undo_buf[i]<<24); i++; - printf ("> (%d)", linep); + linep = text->undo_buf[i]; i++; + linep = linep + (text->undo_buf[i] << 8); i++; + linep = linep + (text->undo_buf[i] << 16); i++; + linep = linep + (text->undo_buf[i] << 24); i++; + printf("> (%d)", linep); } - else if (op==UNDO_INDENT || op==UNDO_UNINDENT) { + else if (op == UNDO_INDENT || op == UNDO_UNINDENT) { i++; - charp= text->undo_buf[i]; i++; - charp= charp+(text->undo_buf[i]<<8); i++; + charp = text->undo_buf[i]; i++; + charp = charp + (text->undo_buf[i] << 8); i++; - linep= text->undo_buf[i]; i++; - linep= linep+(text->undo_buf[i]<<8); i++; - linep= linep+(text->undo_buf[i]<<16); i++; - linep= linep+(text->undo_buf[i]<<24); i++; + linep = text->undo_buf[i]; i++; + linep = linep + (text->undo_buf[i] << 8); i++; + linep = linep + (text->undo_buf[i] << 16); i++; + linep = linep + (text->undo_buf[i] << 24); i++; - printf ("to <%d, %d> ", linep, charp); + printf("to <%d, %d> ", linep, charp); - charp= text->undo_buf[i]; i++; - charp= charp+(text->undo_buf[i]<<8); i++; + charp = text->undo_buf[i]; i++; + charp = charp + (text->undo_buf[i] << 8); i++; - linep= text->undo_buf[i]; i++; - linep= linep+(text->undo_buf[i]<<8); i++; - linep= linep+(text->undo_buf[i]<<16); i++; - linep= linep+(text->undo_buf[i]<<24); i++; + linep = text->undo_buf[i]; i++; + linep = linep + (text->undo_buf[i] << 8); i++; + linep = linep + (text->undo_buf[i] << 16); i++; + linep = linep + (text->undo_buf[i] << 24); i++; - printf ("from <%d, %d>", linep, charp); + printf("from <%d, %d>", linep, charp); } - printf (" %d\n", i); + printf(" %d\n", i); i++; } } @@ -1792,50 +1778,50 @@ static void txt_undo_add_op(Text *text, int op) return; text->undo_pos++; - text->undo_buf[text->undo_pos]= op; - text->undo_buf[text->undo_pos+1]= 0; + text->undo_buf[text->undo_pos] = op; + text->undo_buf[text->undo_pos + 1] = 0; } static void txt_undo_store_uint16(char *undo_buf, int *undo_pos, unsigned short value) { - undo_buf[*undo_pos]= (value)&0xff; + undo_buf[*undo_pos] = (value) & 0xff; (*undo_pos)++; - undo_buf[*undo_pos]= (value>>8)&0xff; + undo_buf[*undo_pos] = (value >> 8) & 0xff; (*undo_pos)++; } static void txt_undo_store_uint32(char *undo_buf, int *undo_pos, unsigned int value) { - undo_buf[*undo_pos]= (value)&0xff; + undo_buf[*undo_pos] = (value) & 0xff; (*undo_pos)++; - undo_buf[*undo_pos]= (value>>8)&0xff; + undo_buf[*undo_pos] = (value >> 8) & 0xff; (*undo_pos)++; - undo_buf[*undo_pos]= (value>>16)&0xff; + undo_buf[*undo_pos] = (value >> 16) & 0xff; (*undo_pos)++; - undo_buf[*undo_pos]= (value>>24)&0xff; + undo_buf[*undo_pos] = (value >> 24) & 0xff; (*undo_pos)++; } static void txt_undo_add_block(Text *text, int op, const char *buf) { - unsigned int length= strlen(buf); + unsigned int length = strlen(buf); - if (!max_undo_test(text, length+11)) + if (!max_undo_test(text, length + 11)) return; text->undo_pos++; - text->undo_buf[text->undo_pos]= op; + text->undo_buf[text->undo_pos] = op; text->undo_pos++; txt_undo_store_uint32(text->undo_buf, &text->undo_pos, length); - strncpy(text->undo_buf+text->undo_pos, buf, length); - text->undo_pos+=length; + strncpy(text->undo_buf + text->undo_pos, buf, length); + text->undo_pos += length; txt_undo_store_uint32(text->undo_buf, &text->undo_pos, length); - text->undo_buf[text->undo_pos]= op; + text->undo_buf[text->undo_pos] = op; - text->undo_buf[text->undo_pos+1]= 0; + text->undo_buf[text->undo_pos + 1] = 0; } void txt_undo_add_toop(Text *text, int op, unsigned int froml, unsigned short fromc, unsigned int tol, unsigned short toc) @@ -1843,10 +1829,10 @@ void txt_undo_add_toop(Text *text, int op, unsigned int froml, unsigned short fr if (!max_undo_test(text, 15)) return; - if (froml==tol && fromc==toc) return; + if (froml == tol && fromc == toc) return; text->undo_pos++; - text->undo_buf[text->undo_pos]= op; + text->undo_buf[text->undo_pos] = op; text->undo_pos++; @@ -1855,9 +1841,9 @@ void txt_undo_add_toop(Text *text, int op, unsigned int froml, unsigned short fr txt_undo_store_uint16(text->undo_buf, &text->undo_pos, toc); txt_undo_store_uint32(text->undo_buf, &text->undo_pos, tol); - text->undo_buf[text->undo_pos]= op; + text->undo_buf[text->undo_pos] = op; - text->undo_buf[text->undo_pos+1]= 0; + text->undo_buf[text->undo_pos + 1] = 0; } static void txt_undo_add_charop(Text *text, int op_start, unsigned int c) @@ -1871,48 +1857,48 @@ static void txt_undo_add_charop(Text *text, int op_start, unsigned int c) text->undo_pos++; if (utf8_size < 4) { - text->undo_buf[text->undo_pos]= op_start + utf8_size - 1; + text->undo_buf[text->undo_pos] = op_start + utf8_size - 1; text->undo_pos++; for (i = 0; i < utf8_size; i++) { - text->undo_buf[text->undo_pos]= utf8[i]; + text->undo_buf[text->undo_pos] = utf8[i]; text->undo_pos++; } - text->undo_buf[text->undo_pos]= op_start + utf8_size - 1; + text->undo_buf[text->undo_pos] = op_start + utf8_size - 1; } else { - text->undo_buf[text->undo_pos]= op_start + 3; + text->undo_buf[text->undo_pos] = op_start + 3; text->undo_pos++; txt_undo_store_uint32(text->undo_buf, &text->undo_pos, c); - text->undo_buf[text->undo_pos]= op_start + 3; + text->undo_buf[text->undo_pos] = op_start + 3; } - text->undo_buf[text->undo_pos+1]= 0; + text->undo_buf[text->undo_pos + 1] = 0; } static unsigned short txt_undo_read_uint16(const char *undo_buf, int *undo_pos) { unsigned short val; - val= undo_buf[*undo_pos]; (*undo_pos)--; - val= (val<<8)+undo_buf[*undo_pos]; (*undo_pos)--; + val = undo_buf[*undo_pos]; (*undo_pos)--; + val = (val << 8) + undo_buf[*undo_pos]; (*undo_pos)--; return val; } static unsigned int txt_undo_read_uint32(const char *undo_buf, int *undo_pos) { unsigned int val; - val= undo_buf[*undo_pos]; (*undo_pos)--; - val= (val<<8)+undo_buf[*undo_pos]; (*undo_pos)--; - val= (val<<8)+undo_buf[*undo_pos]; (*undo_pos)--; - val= (val<<8)+undo_buf[*undo_pos]; (*undo_pos)--; + val = undo_buf[*undo_pos]; (*undo_pos)--; + val = (val << 8) + undo_buf[*undo_pos]; (*undo_pos)--; + val = (val << 8) + undo_buf[*undo_pos]; (*undo_pos)--; + val = (val << 8) + undo_buf[*undo_pos]; (*undo_pos)--; return val; } static unsigned int txt_undo_read_unicode(const char *undo_buf, int *undo_pos, short bytes) { unsigned int unicode; - char utf8[BLI_UTF8_MAX+1]; + char utf8[BLI_UTF8_MAX + 1]; switch (bytes) { case 1: /* ascii */ @@ -1922,21 +1908,21 @@ static unsigned int txt_undo_read_unicode(const char *undo_buf, int *undo_pos, s utf8[2] = '\0'; utf8[1] = undo_buf[*undo_pos]; (*undo_pos)--; utf8[0] = undo_buf[*undo_pos]; (*undo_pos)--; - unicode= BLI_str_utf8_as_unicode(utf8); + unicode = BLI_str_utf8_as_unicode(utf8); break; case 3: /* 3-byte symbol */ utf8[3] = '\0'; utf8[2] = undo_buf[*undo_pos]; (*undo_pos)--; utf8[1] = undo_buf[*undo_pos]; (*undo_pos)--; utf8[0] = undo_buf[*undo_pos]; (*undo_pos)--; - unicode= BLI_str_utf8_as_unicode(utf8); + unicode = BLI_str_utf8_as_unicode(utf8); break; case 4: /* 32-bit unicode symbol */ - unicode= txt_undo_read_uint32(undo_buf, undo_pos); + unicode = txt_undo_read_uint32(undo_buf, undo_pos); default: /* should never happen */ BLI_assert(0); - unicode= 0; + unicode = 0; } return unicode; @@ -1946,24 +1932,24 @@ static unsigned short txt_redo_read_uint16(const char *undo_buf, int *undo_pos) { unsigned short val; val = undo_buf[*undo_pos]; (*undo_pos)++; - val = val+(undo_buf[*undo_pos]<<8); (*undo_pos)++; + val = val + (undo_buf[*undo_pos] << 8); (*undo_pos)++; return val; } static unsigned int txt_redo_read_uint32(const char *undo_buf, int *undo_pos) { unsigned int val; - val= undo_buf[*undo_pos]; (*undo_pos)++; - val= val+(undo_buf[*undo_pos]<<8); (*undo_pos)++; - val= val+(undo_buf[*undo_pos]<<16); (*undo_pos)++; - val= val+(undo_buf[*undo_pos]<<24); (*undo_pos)++; + val = undo_buf[*undo_pos]; (*undo_pos)++; + val = val + (undo_buf[*undo_pos] << 8); (*undo_pos)++; + val = val + (undo_buf[*undo_pos] << 16); (*undo_pos)++; + val = val + (undo_buf[*undo_pos] << 24); (*undo_pos)++; return val; } static unsigned int txt_redo_read_unicode(const char *undo_buf, int *undo_pos, short bytes) { unsigned int unicode; - char utf8[BLI_UTF8_MAX+1]; + char utf8[BLI_UTF8_MAX + 1]; switch (bytes) { case 1: /* ascii */ @@ -1973,21 +1959,21 @@ static unsigned int txt_redo_read_unicode(const char *undo_buf, int *undo_pos, s utf8[0] = undo_buf[*undo_pos]; (*undo_pos)++; utf8[1] = undo_buf[*undo_pos]; (*undo_pos)++; utf8[2] = '\0'; - unicode= BLI_str_utf8_as_unicode(utf8); + unicode = BLI_str_utf8_as_unicode(utf8); break; case 3: /* 3-byte symbol */ utf8[0] = undo_buf[*undo_pos]; (*undo_pos)++; utf8[1] = undo_buf[*undo_pos]; (*undo_pos)++; utf8[2] = undo_buf[*undo_pos]; (*undo_pos)++; utf8[3] = '\0'; - unicode= BLI_str_utf8_as_unicode(utf8); + unicode = BLI_str_utf8_as_unicode(utf8); break; case 4: /* 32-bit unicode symbol */ - unicode= txt_undo_read_uint32(undo_buf, undo_pos); + unicode = txt_undo_read_uint32(undo_buf, undo_pos); default: /* should never happen */ BLI_assert(0); - unicode= 0; + unicode = 0; } return unicode; @@ -1995,20 +1981,20 @@ static unsigned int txt_redo_read_unicode(const char *undo_buf, int *undo_pos, s void txt_do_undo(Text *text) { - int op= text->undo_buf[text->undo_pos]; + int op = text->undo_buf[text->undo_pos]; unsigned int linep, i; unsigned short charp; TextLine *holdl; int holdc, holdln; char *buf; - if (text->undo_pos<0) { + if (text->undo_pos < 0) { return; } text->undo_pos--; - undoing= 1; + undoing = 1; switch (op) { case UNDO_CLEFT: @@ -2053,17 +2039,17 @@ void txt_do_undo(Text *text) text->undo_pos--; text->undo_pos--; - linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos); - charp= txt_undo_read_uint16(text->undo_buf, &text->undo_pos); + linep = txt_undo_read_uint32(text->undo_buf, &text->undo_pos); + charp = txt_undo_read_uint16(text->undo_buf, &text->undo_pos); - if (op==UNDO_CTO) { + if (op == UNDO_CTO) { txt_move_toline(text, linep, 0); - text->curc= charp; + text->curc = charp; txt_pop_sel(text); } else { txt_move_toline(text, linep, 1); - text->selc= charp; + text->selc = charp; } text->undo_pos--; @@ -2071,7 +2057,7 @@ void txt_do_undo(Text *text) case UNDO_INSERT_1: case UNDO_INSERT_2: case UNDO_INSERT_3: case UNDO_INSERT_4: txt_backspace_char(text); - text->undo_pos-= op - UNDO_INSERT_1 + 1; + text->undo_pos -= op - UNDO_INSERT_1 + 1; text->undo_pos--; break; @@ -2093,29 +2079,29 @@ void txt_do_undo(Text *text) break; case UNDO_DBLOCK: - linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos); + linep = txt_undo_read_uint32(text->undo_buf, &text->undo_pos); - buf= MEM_mallocN(linep+1, "dblock buffer"); - for (i=0; i < linep; i++) { - buf[(linep-1)-i]= text->undo_buf[text->undo_pos]; + buf = MEM_mallocN(linep + 1, "dblock buffer"); + for (i = 0; i < linep; i++) { + buf[(linep - 1) - i] = text->undo_buf[text->undo_pos]; text->undo_pos--; } - buf[i]= 0; + buf[i] = 0; txt_curs_first(text, &holdl, &holdc); - holdln= txt_get_span(text->lines.first, holdl); + holdln = txt_get_span(text->lines.first, holdl); txt_insert_buf(text, buf); MEM_freeN(buf); - text->curl= text->lines.first; - while (holdln>0) { + text->curl = text->lines.first; + while (holdln > 0) { if (text->curl->next) - text->curl= text->curl->next; + text->curl = text->curl->next; holdln--; } - text->curc= holdc; + text->curc = holdc; text->undo_pos--; text->undo_pos--; @@ -2127,20 +2113,20 @@ void txt_do_undo(Text *text) break; case UNDO_IBLOCK: - linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos); + linep = txt_undo_read_uint32(text->undo_buf, &text->undo_pos); txt_delete_sel(text); /* txt_backspace_char removes utf8-characters, not bytes */ - buf= MEM_mallocN(linep+1, "iblock buffer"); - for (i=0; i < linep; i++) { - buf[(linep-1)-i]= text->undo_buf[text->undo_pos]; + buf = MEM_mallocN(linep + 1, "iblock buffer"); + for (i = 0; i < linep; i++) { + buf[(linep - 1) - i] = text->undo_buf[text->undo_pos]; text->undo_pos--; } - buf[i]= 0; - linep= txt_utf8_len(buf); + buf[i] = 0; + linep = txt_utf8_len(buf); MEM_freeN(buf); - while (linep>0) { + while (linep > 0) { txt_backspace_char(text); linep--; } @@ -2157,7 +2143,7 @@ void txt_do_undo(Text *text) case UNDO_UNINDENT: case UNDO_COMMENT: case UNDO_UNCOMMENT: - linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos); + linep = txt_undo_read_uint32(text->undo_buf, &text->undo_pos); //linep is now the end line of the selection charp = txt_undo_read_uint16(text->undo_buf, &text->undo_pos); @@ -2166,11 +2152,11 @@ void txt_do_undo(Text *text) //set the selection for this now text->selc = charp; text->sell = text->lines.first; - for (i= 0; i < linep; i++) { + for (i = 0; i < linep; i++) { text->sell = text->sell->next; } - linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos); + linep = txt_undo_read_uint32(text->undo_buf, &text->undo_pos); //first line to be selected charp = txt_undo_read_uint16(text->undo_buf, &text->undo_pos); @@ -2182,10 +2168,10 @@ void txt_do_undo(Text *text) } - if (op==UNDO_INDENT) { + if (op == UNDO_INDENT) { txt_unindent(text); } - else if (op== UNDO_UNINDENT) { + else if (op == UNDO_UNINDENT) { txt_indent(text); } else if (op == UNDO_COMMENT) { @@ -2208,13 +2194,13 @@ void txt_do_undo(Text *text) break; default: //XXX error("Undo buffer error - resetting"); - text->undo_pos= -1; + text->undo_pos = -1; break; } /* next undo step may need evaluating */ - if (text->undo_pos>=0) { + if (text->undo_pos >= 0) { switch (text->undo_buf[text->undo_pos]) { case UNDO_STO: txt_do_undo(text); @@ -2226,7 +2212,7 @@ void txt_do_undo(Text *text) } } - undoing= 0; + undoing = 0; } void txt_do_redo(Text *text) @@ -2237,14 +2223,14 @@ void txt_do_redo(Text *text) char *buf; text->undo_pos++; - op= text->undo_buf[text->undo_pos]; + op = text->undo_buf[text->undo_pos]; if (!op) { text->undo_pos--; return; } - undoing= 1; + undoing = 1; switch (op) { case UNDO_CLEFT: @@ -2288,13 +2274,13 @@ void txt_do_redo(Text *text) case UNDO_BS_1: case UNDO_BS_2: case UNDO_BS_3: case UNDO_BS_4: text->undo_pos++; txt_backspace_char(text); - text->undo_pos+= op - UNDO_BS_1 + 1; + text->undo_pos += op - UNDO_BS_1 + 1; break; case UNDO_DEL_1: case UNDO_DEL_2: case UNDO_DEL_3: case UNDO_DEL_4: text->undo_pos++; txt_delete_char(text); - text->undo_pos+= op - UNDO_DEL_1 + 1; + text->undo_pos += op - UNDO_DEL_1 + 1; break; case UNDO_SWAP: @@ -2314,27 +2300,27 @@ void txt_do_redo(Text *text) text->undo_pos++; - charp= txt_redo_read_uint16(text->undo_buf, &text->undo_pos); - linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos); + charp = txt_redo_read_uint16(text->undo_buf, &text->undo_pos); + linep = txt_redo_read_uint32(text->undo_buf, &text->undo_pos); - if (op==UNDO_CTO) { + if (op == UNDO_CTO) { txt_move_toline(text, linep, 0); - text->curc= charp; + text->curc = charp; txt_pop_sel(text); } else { txt_move_toline(text, linep, 1); - text->selc= charp; + text->selc = charp; } break; case UNDO_DBLOCK: text->undo_pos++; - linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos); + linep = txt_redo_read_uint32(text->undo_buf, &text->undo_pos); txt_delete_sel(text); - text->undo_pos+=linep; + text->undo_pos += linep; text->undo_pos++; text->undo_pos++; @@ -2345,12 +2331,12 @@ void txt_do_redo(Text *text) case UNDO_IBLOCK: text->undo_pos++; - linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos); + linep = txt_redo_read_uint32(text->undo_buf, &text->undo_pos); - buf= MEM_mallocN(linep+1, "iblock buffer"); - memcpy (buf, &text->undo_buf[text->undo_pos], linep); - text->undo_pos+= linep; - buf[linep]= 0; + buf = MEM_mallocN(linep + 1, "iblock buffer"); + memcpy(buf, &text->undo_buf[text->undo_pos], linep); + text->undo_pos += linep; + buf[linep] = 0; txt_insert_buf(text, buf); MEM_freeN(buf); @@ -2369,19 +2355,19 @@ void txt_do_redo(Text *text) charp = txt_redo_read_uint16(text->undo_buf, &text->undo_pos); //charp is the first char selected or 0 - linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos); + linep = txt_redo_read_uint32(text->undo_buf, &text->undo_pos); //linep is now the first line of the selection //set the selcetion for this now text->curc = charp; text->curl = text->lines.first; - for (i= 0; i < linep; i++) { + for (i = 0; i < linep; i++) { text->curl = text->curl->next; } charp = txt_redo_read_uint16(text->undo_buf, &text->undo_pos); //last postion to be selected - linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos); + linep = txt_redo_read_uint32(text->undo_buf, &text->undo_pos); //Last line to be selected text->selc = charp; @@ -2390,10 +2376,10 @@ void txt_do_redo(Text *text) text->sell = text->sell->next; } - if (op==UNDO_INDENT) { + if (op == UNDO_INDENT) { txt_indent(text); } - else if (op== UNDO_UNINDENT) { + else if (op == UNDO_UNINDENT) { txt_unindent(text); } else if (op == UNDO_COMMENT) { @@ -2414,12 +2400,12 @@ void txt_do_redo(Text *text) break; default: //XXX error("Undo buffer error - resetting"); - text->undo_pos= -1; + text->undo_pos = -1; break; } - undoing= 0; + undoing = 0; } /**************************/ @@ -2431,7 +2417,7 @@ void txt_split_curline(Text *text) TextLine *ins; TextMarker *mrk; char *left, *right; - int lineno= -1; + int lineno = -1; if (!text) return; if (!text->curl) return; @@ -2440,10 +2426,10 @@ void txt_split_curline(Text *text) /* Move markers */ - lineno= txt_get_span(text->lines.first, text->curl); - mrk= text->markers.first; + lineno = txt_get_span(text->lines.first, text->curl); + mrk = text->markers.first; while (mrk) { - if (mrk->lineno==lineno && mrk->start>text->curc) { + if (mrk->lineno == lineno && mrk->start > text->curc) { mrk->lineno++; mrk->start -= text->curc; mrk->end -= text->curc; @@ -2451,35 +2437,35 @@ void txt_split_curline(Text *text) else if (mrk->lineno > lineno) { mrk->lineno++; } - mrk= mrk->next; + mrk = mrk->next; } /* Make the two half strings */ - left= MEM_mallocN(text->curc+1, "textline_string"); + left = MEM_mallocN(text->curc + 1, "textline_string"); if (text->curc) memcpy(left, text->curl->line, text->curc); - left[text->curc]=0; + left[text->curc] = 0; - right= MEM_mallocN(text->curl->len - text->curc+1, "textline_string"); - memcpy(right, text->curl->line+text->curc, text->curl->len-text->curc+1); + right = MEM_mallocN(text->curl->len - text->curc + 1, "textline_string"); + memcpy(right, text->curl->line + text->curc, text->curl->len - text->curc + 1); MEM_freeN(text->curl->line); if (text->curl->format) MEM_freeN(text->curl->format); /* Make the new TextLine */ - ins= MEM_mallocN(sizeof(TextLine), "textline"); - ins->line= left; - ins->format= NULL; - ins->len= text->curc; - - text->curl->line= right; - text->curl->format= NULL; - text->curl->len= text->curl->len - text->curc; + ins = MEM_mallocN(sizeof(TextLine), "textline"); + ins->line = left; + ins->format = NULL; + ins->len = text->curc; + + text->curl->line = right; + text->curl->format = NULL; + text->curl->len = text->curl->len - text->curc; BLI_insertlinkbefore(&text->lines, text->curl, ins); - text->curc=0; + text->curc = 0; txt_make_dirty(text); txt_clean_text(text); @@ -2488,26 +2474,26 @@ void txt_split_curline(Text *text) if (!undoing) txt_undo_add_charop(text, UNDO_INSERT_1, '\n'); } -static void txt_delete_line (Text *text, TextLine *line) +static void txt_delete_line(Text *text, TextLine *line) { - TextMarker *mrk=NULL, *nxt; - int lineno= -1; + TextMarker *mrk = NULL, *nxt; + int lineno = -1; if (!text) return; if (!text->curl) return; - lineno= txt_get_span(text->lines.first, line); - mrk= text->markers.first; + lineno = txt_get_span(text->lines.first, line); + mrk = text->markers.first; while (mrk) { - nxt= mrk->next; - if (mrk->lineno==lineno) + nxt = mrk->next; + if (mrk->lineno == lineno) BLI_freelinkN(&text->markers, mrk); else if (mrk->lineno > lineno) mrk->lineno--; - mrk= nxt; + mrk = nxt; } - BLI_remlink (&text->lines, line); + BLI_remlink(&text->lines, line); if (line->line) MEM_freeN(line->line); if (line->format) MEM_freeN(line->format); @@ -2518,29 +2504,29 @@ static void txt_delete_line (Text *text, TextLine *line) txt_clean_text(text); } -static void txt_combine_lines (Text *text, TextLine *linea, TextLine *lineb) +static void txt_combine_lines(Text *text, TextLine *linea, TextLine *lineb) { char *tmp; - TextMarker *mrk= NULL; - int lineno=-1; + TextMarker *mrk = NULL; + int lineno = -1; if (!text) return; if (!linea || !lineb) return; - mrk= txt_find_marker_region(text, lineb, 0, lineb->len, 0, 0); + mrk = txt_find_marker_region(text, lineb, 0, lineb->len, 0, 0); if (mrk) { - lineno= mrk->lineno; + lineno = mrk->lineno; do { mrk->lineno--; mrk->start += linea->len; mrk->end += linea->len; - mrk= mrk->next; - } while (mrk && mrk->lineno==lineno); + mrk = mrk->next; + } while (mrk && mrk->lineno == lineno); } - if (lineno==-1) lineno= txt_get_span(text->lines.first, lineb); + if (lineno == -1) lineno = txt_get_span(text->lines.first, lineb); - tmp= MEM_mallocN(linea->len+lineb->len+1, "textline_string"); + tmp = MEM_mallocN(linea->len + lineb->len + 1, "textline_string"); strcpy(tmp, linea->line); strcat(tmp, lineb->line); @@ -2572,7 +2558,7 @@ void txt_duplicate_line(Text *text) void txt_delete_char(Text *text) { - unsigned int c='\n'; + unsigned int c = '\n'; if (!text) return; if (!text->curl) return; @@ -2582,7 +2568,7 @@ void txt_delete_char(Text *text) txt_make_dirty(text); return; } - else if (text->curc== text->curl->len) { /* Appending two lines */ + else if (text->curc == text->curl->len) { /* Appending two lines */ if (text->curl->next) { txt_combine_lines(text, text->curl, text->curl->next); txt_pop_sel(text); @@ -2593,12 +2579,12 @@ void txt_delete_char(Text *text) else { /* Just deleting a char */ size_t c_len = 0; TextMarker *mrk; - c= BLI_str_utf8_as_unicode_and_size(text->curl->line + text->curc, &c_len); + c = BLI_str_utf8_as_unicode_and_size(text->curl->line + text->curc, &c_len); - mrk= txt_find_marker_region(text, text->curl, text->curc - c_len, text->curl->len, 0, 0); + mrk = txt_find_marker_region(text, text->curl, text->curc - c_len, text->curl->len, 0, 0); if (mrk) { - int lineno= mrk->lineno; - if (mrk->end==text->curc) { + int lineno = mrk->lineno; + if (mrk->end == text->curc) { if ((mrk->flags & TMARK_TEMP) && !(mrk->flags & TMARK_EDITALL)) { txt_clear_markers(text, mrk->group, TMARK_TEMP); } @@ -2608,15 +2594,15 @@ void txt_delete_char(Text *text) return; } do { - if (mrk->start>text->curc) mrk->start-= c_len; - mrk->end-= c_len; - mrk= mrk->next; - } while (mrk && mrk->lineno==lineno); + if (mrk->start > text->curc) mrk->start -= c_len; + mrk->end -= c_len; + mrk = mrk->next; + } while (mrk && mrk->lineno == lineno); } - memmove(text->curl->line+text->curc, text->curl->line+text->curc+c_len, text->curl->len-text->curc-c_len+1); + memmove(text->curl->line + text->curc, text->curl->line + text->curc + c_len, text->curl->len - text->curc - c_len + 1); - text->curl->len-= c_len; + text->curl->len -= c_len; txt_pop_sel(text); } @@ -2635,7 +2621,7 @@ void txt_delete_word(Text *text) void txt_backspace_char(Text *text) { - unsigned int c='\n'; + unsigned int c = '\n'; if (!text) return; if (!text->curl) return; @@ -2645,11 +2631,11 @@ void txt_backspace_char(Text *text) txt_make_dirty(text); return; } - else if (text->curc==0) { /* Appending two lines */ + else if (text->curc == 0) { /* Appending two lines */ if (!text->curl->prev) return; - text->curl= text->curl->prev; - text->curc= text->curl->len; + text->curl = text->curl->prev; + text->curc = text->curl->len; txt_combine_lines(text, text->curl, text->curl->next); txt_pop_sel(text); @@ -2658,12 +2644,12 @@ void txt_backspace_char(Text *text) size_t c_len = 0; TextMarker *mrk; char *prev = BLI_str_prev_char_utf8(text->curl->line + text->curc); - c= BLI_str_utf8_as_unicode_and_size(prev, &c_len); + c = BLI_str_utf8_as_unicode_and_size(prev, &c_len); - mrk= txt_find_marker_region(text, text->curl, text->curc - c_len, text->curl->len, 0, 0); + mrk = txt_find_marker_region(text, text->curl, text->curc - c_len, text->curl->len, 0, 0); if (mrk) { - int lineno= mrk->lineno; - if (mrk->start==text->curc) { + int lineno = mrk->lineno; + if (mrk->start == text->curc) { if ((mrk->flags & TMARK_TEMP) && !(mrk->flags & TMARK_EDITALL)) { txt_clear_markers(text, mrk->group, TMARK_TEMP); } @@ -2673,10 +2659,10 @@ void txt_backspace_char(Text *text) return; } do { - if (mrk->start>text->curc - c_len) mrk->start-= c_len; - mrk->end-= c_len; - mrk= mrk->next; - } while (mrk && mrk->lineno==lineno); + if (mrk->start > text->curc - c_len) mrk->start -= c_len; + mrk->end -= c_len; + mrk = mrk->next; + } while (mrk && mrk->lineno == lineno); } /* source and destination overlap, don't use memcpy() */ @@ -2684,8 +2670,8 @@ void txt_backspace_char(Text *text) text->curl->line + text->curc, text->curl->len - text->curc + 1); - text->curl->len-= c_len; - text->curc-= c_len; + text->curl->len -= c_len; + text->curc -= c_len; txt_pop_sel(text); } @@ -2707,7 +2693,7 @@ void txt_backspace_word(Text *text) * Remember to change this string according to max tab size */ static char tab_to_spaces[] = " "; -static void txt_convert_tab_to_spaces (Text *text) +static void txt_convert_tab_to_spaces(Text *text) { /* sb aims to pad adjust the tab-width needed so that the right number of spaces * is added so that the indention of the line is the right width (i.e. aligned @@ -2717,7 +2703,7 @@ static void txt_convert_tab_to_spaces (Text *text) txt_insert_buf(text, sb); } -static int txt_add_char_intern (Text *text, unsigned int add, int replace_tabs) +static int txt_add_char_intern(Text *text, unsigned int add, int replace_tabs) { int lineno; char *tmp, ch[BLI_UTF8_MAX]; @@ -2727,7 +2713,7 @@ static int txt_add_char_intern (Text *text, unsigned int add, int replace_tabs) if (!text) return 0; if (!text->curl) return 0; - if (add=='\n') { + if (add == '\n') { txt_split_curline(text); return 1; } @@ -2741,25 +2727,25 @@ static int txt_add_char_intern (Text *text, unsigned int add, int replace_tabs) txt_delete_sel(text); add_len = BLI_str_utf8_from_unicode(add, ch); - mrk= txt_find_marker_region(text, text->curl, text->curc-1, text->curl->len, 0, 0); + mrk = txt_find_marker_region(text, text->curl, text->curc - 1, text->curl->len, 0, 0); if (mrk) { - lineno= mrk->lineno; + lineno = mrk->lineno; do { - if (mrk->start>text->curc) mrk->start+= add_len; - mrk->end+= add_len; - mrk= mrk->next; - } while (mrk && mrk->lineno==lineno); + if (mrk->start > text->curc) mrk->start += add_len; + mrk->end += add_len; + mrk = mrk->next; + } while (mrk && mrk->lineno == lineno); } - tmp= MEM_mallocN(text->curl->len+add_len+1, "textline_string"); + tmp = MEM_mallocN(text->curl->len + add_len + 1, "textline_string"); memcpy(tmp, text->curl->line, text->curc); - memcpy(tmp+text->curc, ch, add_len); - memcpy(tmp+text->curc+add_len, text->curl->line+text->curc, text->curl->len-text->curc+1); + memcpy(tmp + text->curc, ch, add_len); + memcpy(tmp + text->curc + add_len, text->curl->line + text->curc, text->curl->len - text->curc + 1); make_new_line(text->curl, tmp); - text->curc+= add_len; + text->curc += add_len; txt_pop_sel(text); @@ -2796,30 +2782,30 @@ int txt_replace_char(Text *text, unsigned int add) if (!text->curl) return 0; /* If text is selected or we're at the end of the line just use txt_add_char */ - if (text->curc==text->curl->len || txt_has_sel(text) || add=='\n') { - int i= txt_add_char(text, add); - TextMarker *mrk= txt_find_marker(text, text->curl, text->curc, 0, 0); + if (text->curc == text->curl->len || txt_has_sel(text) || add == '\n') { + int i = txt_add_char(text, add); + TextMarker *mrk = txt_find_marker(text, text->curl, text->curc, 0, 0); if (mrk) BLI_freelinkN(&text->markers, mrk); return i; } - del= BLI_str_utf8_as_unicode_and_size(text->curl->line + text->curc, &del_size); - add_size= BLI_str_utf8_from_unicode(add, ch); + del = BLI_str_utf8_as_unicode_and_size(text->curl->line + text->curc, &del_size); + add_size = BLI_str_utf8_from_unicode(add, ch); if (add_size > del_size) { - char *tmp= MEM_mallocN(text->curl->len+add_size-del_size+1, "textline_string"); + char *tmp = MEM_mallocN(text->curl->len + add_size - del_size + 1, "textline_string"); memcpy(tmp, text->curl->line, text->curc); - memcpy(tmp+text->curc+add_size, text->curl->line+text->curc+del_size, text->curl->len-text->curc-del_size+1); + memcpy(tmp + text->curc + add_size, text->curl->line + text->curc + del_size, text->curl->len - text->curc - del_size + 1); MEM_freeN(text->curl->line); text->curl->line = tmp; } else if (add_size < del_size) { - char *tmp= text->curl->line; - memmove(tmp+text->curc+add_size, tmp+text->curc+del_size, text->curl->len-text->curc-del_size+1); + char *tmp = text->curl->line; + memmove(tmp + text->curc + add_size, tmp + text->curc + del_size, text->curl->len - text->curc - del_size + 1); } memcpy(text->curl->line + text->curc, ch, add_size); - text->curc+= add_size; + text->curc += add_size; txt_pop_sel(text); txt_make_dirty(text); @@ -2860,19 +2846,19 @@ void txt_indent(Text *text) num = 0; while (TRUE) { - tmp= MEM_mallocN(text->curl->len+indentlen+1, "textline_string"); + tmp = MEM_mallocN(text->curl->len + indentlen + 1, "textline_string"); text->curc = 0; - if (text->curc) memcpy(tmp, text->curl->line, text->curc); /* XXX never true, check prev line */ - memcpy(tmp+text->curc, add, indentlen); + if (text->curc) memcpy(tmp, text->curl->line, text->curc); /* XXX never true, check prev line */ + memcpy(tmp + text->curc, add, indentlen); - len= text->curl->len - text->curc; - if (len>0) memcpy(tmp+text->curc+indentlen, text->curl->line+text->curc, len); - tmp[text->curl->len+indentlen]= 0; + len = text->curl->len - text->curc; + if (len > 0) memcpy(tmp + text->curc + indentlen, text->curl->line + text->curc, len); + tmp[text->curl->len + indentlen] = 0; make_new_line(text->curl, tmp); - text->curc+= indentlen; + text->curc += indentlen; txt_make_dirty(text); txt_clean_text(text); @@ -2887,7 +2873,7 @@ void txt_indent(Text *text) } } text->curc = 0; - while ( num > 0 ) { + while (num > 0) { text->curl = text->curl->prev; num--; } @@ -2920,11 +2906,11 @@ void txt_unindent(Text *text) int i = 0; if (BLI_strncasecmp(text->curl->line, remove, indent) == 0) { - while (i< text->curl->len) { - text->curl->line[i]= text->curl->line[i+indent]; + while (i < text->curl->len) { + text->curl->line[i] = text->curl->line[i + indent]; i++; } - text->curl->len-= indent; + text->curl->len -= indent; } txt_make_dirty(text); @@ -2941,7 +2927,7 @@ void txt_unindent(Text *text) } text->curc = 0; - while ( num > 0 ) { + while (num > 0) { text->curl = text->curl->prev; num--; } @@ -2959,19 +2945,19 @@ void txt_comment(Text *text) if (!text) return; if (!text->curl) return; - if (!text->sell) return;// Need to change this need to check if only one line is selected to more then one + if (!text->sell) return; // Need to change this need to check if only one line is selected to more then one num = 0; while (TRUE) { - tmp= MEM_mallocN(text->curl->len+2, "textline_string"); + tmp = MEM_mallocN(text->curl->len + 2, "textline_string"); text->curc = 0; if (text->curc) memcpy(tmp, text->curl->line, text->curc); - tmp[text->curc]= add; + tmp[text->curc] = add; - len= text->curl->len - text->curc; - if (len>0) memcpy(tmp+text->curc+1, text->curl->line+text->curc, len); - tmp[text->curl->len+1]=0; + len = text->curl->len - text->curc; + if (len > 0) memcpy(tmp + text->curc + 1, text->curl->line + text->curc, len); + tmp[text->curl->len + 1] = 0; make_new_line(text->curl, tmp); @@ -2990,7 +2976,7 @@ void txt_comment(Text *text) } } text->curc = 0; - while ( num > 0 ) { + while (num > 0) { text->curl = text->curl->prev; num--; } @@ -3013,8 +2999,8 @@ void txt_uncomment(Text *text) int i = 0; if (text->curl->line[i] == remove) { - while (i< text->curl->len) { - text->curl->line[i]= text->curl->line[i+1]; + while (i < text->curl->len) { + text->curl->line[i] = text->curl->line[i + 1]; i++; } text->curl->len--; @@ -3035,7 +3021,7 @@ void txt_uncomment(Text *text) } text->curc = 0; - while ( num > 0 ) { + while (num > 0) { text->curl = text->curl->prev; num--; } @@ -3054,7 +3040,7 @@ void txt_move_lines_up(struct Text *text) txt_order_cursors(text); - prev_line= text->curl->prev; + prev_line = text->curl->prev; if (!prev_line) return; @@ -3106,8 +3092,8 @@ int setcurr_tab_spaces(Text *text, int space) int test = 0; const char *word = ":"; const char *comm = "#"; - const char indent= (text->flags & TXT_TABSTOSPACES) ? ' ' : '\t'; - static const char *back_words[]= {"return", "break", "continue", "pass", "yield", NULL}; + const char indent = (text->flags & TXT_TABSTOSPACES) ? ' ' : '\t'; + static const char *back_words[] = {"return", "break", "continue", "pass", "yield", NULL}; if (!text) return 0; if (!text->curl) return 0; @@ -3122,20 +3108,20 @@ int setcurr_tab_spaces(Text *text, int space) } if (strstr(text->curl->line, word)) { /* if we find a ':' on this line, then add a tab but not if it is: - * 1) in a comment - * 2) within an identifier + * 1) in a comment + * 2) within an identifier * 3) after the cursor (text->curc), i.e. when creating space before a function def [#25414] */ int a, is_indent = 0; - for (a=0; (a < text->curc) && (text->curl->line[a] != '\0'); a++) { - char ch= text->curl->line[a]; - if (ch=='#') { + for (a = 0; (a < text->curc) && (text->curl->line[a] != '\0'); a++) { + char ch = text->curl->line[a]; + if (ch == '#') { break; } - else if (ch==':') { + else if (ch == ':') { is_indent = 1; } - else if (ch!=' ' && ch!='\t') { + else if (ch != ' ' && ch != '\t') { is_indent = 0; } } @@ -3144,7 +3130,7 @@ int setcurr_tab_spaces(Text *text, int space) } } - for (test=0; back_words[test]; test++) { + for (test = 0; back_words[test]; test++) { /* if there are these key words then remove a tab because we are done with the block */ if (strstr(text->curl->line, back_words[test]) && i > 0) { if (strcspn(text->curl->line, back_words[test]) < strcspn(text->curl->line, comm)) { @@ -3164,21 +3150,21 @@ void txt_add_marker(Text *text, TextLine *line, int start, int end, const unsign { TextMarker *tmp, *marker; - marker= MEM_mallocN(sizeof(TextMarker), "text_marker"); + marker = MEM_mallocN(sizeof(TextMarker), "text_marker"); - marker->lineno= txt_get_span(text->lines.first, line); - marker->start= MIN2(start, end); - marker->end= MAX2(start, end); - marker->group= group; - marker->flags= flags; + marker->lineno = txt_get_span(text->lines.first, line); + marker->start = MIN2(start, end); + marker->end = MAX2(start, end); + marker->group = group; + marker->flags = flags; - marker->color[0]= color[0]; - marker->color[1]= color[1]; - marker->color[2]= color[2]; - marker->color[3]= color[3]; + marker->color[0] = color[0]; + marker->color[1] = color[1]; + marker->color[2] = color[2]; + marker->color[3] = color[3]; - for (tmp=text->markers.last; tmp; tmp=tmp->prev) - if (tmp->lineno < marker->lineno || (tmp->lineno==marker->lineno && tmp->start < marker->start)) + for (tmp = text->markers.last; tmp; tmp = tmp->prev) + if (tmp->lineno < marker->lineno || (tmp->lineno == marker->lineno && tmp->start < marker->start)) break; if (tmp) BLI_insertlinkafter(&text->markers, tmp, marker); @@ -3191,18 +3177,18 @@ void txt_add_marker(Text *text, TextLine *line, int start, int end, const unsign TextMarker *txt_find_marker_region(Text *text, TextLine *line, int start, int end, int group, int flags) { TextMarker *marker, *next; - int lineno= txt_get_span(text->lines.first, line); + int lineno = txt_get_span(text->lines.first, line); - for (marker=text->markers.first; marker; marker=next) { - next= marker->next; + for (marker = text->markers.first; marker; marker = next) { + next = marker->next; - if (group && marker->group != group) continue; + if (group && marker->group != group) continue; else if ((marker->flags & flags) != flags) continue; - else if (marker->lineno < lineno) continue; + else if (marker->lineno < lineno) continue; else if (marker->lineno > lineno) break; - if ((marker->start==marker->end && start<=marker->start && marker->start<=end) || - (marker->start<end && marker->end>start)) + if ((marker->start == marker->end && start <= marker->start && marker->start <= end) || + (marker->start < end && marker->end > start)) { return marker; } @@ -3216,21 +3202,21 @@ TextMarker *txt_find_marker_region(Text *text, TextLine *line, int start, int en short txt_clear_marker_region(Text *text, TextLine *line, int start, int end, int group, int flags) { TextMarker *marker, *next; - int lineno= txt_get_span(text->lines.first, line); - short cleared= 0; + int lineno = txt_get_span(text->lines.first, line); + short cleared = 0; - for (marker=text->markers.first; marker; marker=next) { - next= marker->next; + for (marker = text->markers.first; marker; marker = next) { + next = marker->next; if (group && marker->group != group) continue; else if ((marker->flags & flags) != flags) continue; else if (marker->lineno < lineno) continue; else if (marker->lineno > lineno) break; - if ((marker->start==marker->end && start<=marker->start && marker->start<=end) || - (marker->start<end && marker->end>start)) { + if ((marker->start == marker->end && start <= marker->start && marker->start <= end) || + (marker->start < end && marker->end > start)) { BLI_freelinkN(&text->markers, marker); - cleared= 1; + cleared = 1; } } return cleared; @@ -3242,15 +3228,15 @@ short txt_clear_marker_region(Text *text, TextLine *line, int start, int end, in short txt_clear_markers(Text *text, int group, int flags) { TextMarker *marker, *next; - short cleared= 0; + short cleared = 0; - for (marker=text->markers.first; marker; marker=next) { - next= marker->next; + for (marker = text->markers.first; marker; marker = next) { + next = marker->next; - if ((!group || marker->group==group) && - (marker->flags & flags) == flags) { + if ((!group || marker->group == group) && + (marker->flags & flags) == flags) { BLI_freelinkN(&text->markers, marker); - cleared= 1; + cleared = 1; } } return cleared; @@ -3261,9 +3247,9 @@ short txt_clear_markers(Text *text, int group, int flags) TextMarker *txt_find_marker(Text *text, TextLine *line, int curs, int group, int flags) { TextMarker *marker; - int lineno= txt_get_span(text->lines.first, line); + int lineno = txt_get_span(text->lines.first, line); - for (marker=text->markers.first; marker; marker=marker->next) { + for (marker = text->markers.first; marker; marker = marker->next) { if (group && marker->group != group) continue; else if ((marker->flags & flags) != flags) continue; else if (marker->lineno < lineno) continue; @@ -3279,10 +3265,10 @@ TextMarker *txt_find_marker(Text *text, TextLine *line, int curs, int group, int * marker will be returned */ TextMarker *txt_prev_marker(Text *text, TextMarker *marker) { - TextMarker *tmp= marker; + TextMarker *tmp = marker; while (tmp) { - if (tmp->prev) tmp= tmp->prev; - else tmp= text->markers.last; + if (tmp->prev) tmp = tmp->prev; + else tmp = text->markers.last; if (tmp->group == marker->group) return tmp; } @@ -3293,10 +3279,10 @@ TextMarker *txt_prev_marker(Text *text, TextMarker *marker) * marker will be returned */ TextMarker *txt_next_marker(Text *text, TextMarker *marker) { - TextMarker *tmp= marker; + TextMarker *tmp = marker; while (tmp) { - if (tmp->next) tmp= tmp->next; - else tmp= text->markers.first; + if (tmp->next) tmp = tmp->next; + else tmp = text->markers.first; if (tmp->group == marker->group) return tmp; } @@ -3314,11 +3300,11 @@ int text_check_bracket(const char ch) char opens[] = "([{"; char close[] = ")]}"; - for (a=0; a<(sizeof(opens)-1); a++) { - if (ch==opens[a]) - return a+1; - else if (ch==close[a]) - return -(a+1); + for (a = 0; a < (sizeof(opens) - 1); a++) { + if (ch == opens[a]) + return a + 1; + else if (ch == close[a]) + return -(a + 1); } return 0; } @@ -3329,8 +3315,8 @@ int text_check_delim(const char ch) int a; char delims[] = "():\"\' ~!%^&*-+=[]{};/<>|.#\t,@"; - for (a=0; a<(sizeof(delims)-1); a++) { - if (ch==delims[a]) + for (a = 0; a < (sizeof(delims) - 1); a++) { + if (ch == delims[a]) return 1; } return 0; diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 9200b1dca18..2c868ca2601 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -80,7 +80,7 @@ int test_dlerr(const char *name, const char *symbol) { char *err; - err= BLI_dynlib_get_error_as_string(NULL); + err = BLI_dynlib_get_error_as_string(NULL); if (err) { printf("var1: %s, var2: %s, var3: %s\n", name, symbol, err); return 1; @@ -96,14 +96,14 @@ void open_plugin_tex(PluginTex *pit) int (*version)(void); /* init all the happy variables */ - pit->doit= NULL; - pit->pname= NULL; - pit->stnames= NULL; - pit->varstr= NULL; - pit->result= NULL; - pit->cfra= NULL; - pit->version= 0; - pit->instance_init= NULL; + pit->doit = NULL; + pit->pname = NULL; + pit->stnames = NULL; + pit->varstr = NULL; + pit->result = NULL; + pit->cfra = NULL; + pit->version = 0; + pit->instance_init = NULL; /* clear the error list */ BLI_dynlib_get_error_as_string(NULL); @@ -113,42 +113,42 @@ void open_plugin_tex(PluginTex *pit) /* pit->handle= 0; */ /* open the needed object */ - pit->handle= BLI_dynlib_open(pit->name); + pit->handle = BLI_dynlib_open(pit->name); if (test_dlerr(pit->name, pit->name)) return; if (pit->handle != NULL) { /* find the address of the version function */ - version= (int (*)(void)) BLI_dynlib_find_symbol(pit->handle, "plugin_tex_getversion"); + version = (int (*)(void))BLI_dynlib_find_symbol(pit->handle, "plugin_tex_getversion"); if (test_dlerr(pit->name, "plugin_tex_getversion")) return; if (version != NULL) { - pit->version= version(); - if ( pit->version >= 2 && pit->version <=6) { + pit->version = version(); + if (pit->version >= 2 && pit->version <= 6) { int (*info_func)(PluginInfo *); - PluginInfo *info= (PluginInfo*) MEM_mallocN(sizeof(PluginInfo), "plugin_info"); + PluginInfo *info = (PluginInfo *) MEM_mallocN(sizeof(PluginInfo), "plugin_info"); - info_func= (int (*)(PluginInfo *))BLI_dynlib_find_symbol(pit->handle, "plugin_getinfo"); + info_func = (int (*)(PluginInfo *))BLI_dynlib_find_symbol(pit->handle, "plugin_getinfo"); if (!test_dlerr(pit->name, "plugin_getinfo")) { info->instance_init = NULL; info_func(info); - pit->doit= (int(*)(void)) info->tex_doit; - pit->callback= (void(*)(unsigned short)) info->callback; - pit->stypes= info->stypes; - pit->vars= info->nvars; - pit->pname= info->name; - pit->stnames= info->snames; - pit->varstr= info->varstr; - pit->result= info->result; - pit->cfra= info->cfra; + pit->doit = (int (*)(void))info->tex_doit; + pit->callback = (void (*)(unsigned short))info->callback; + pit->stypes = info->stypes; + pit->vars = info->nvars; + pit->pname = info->name; + pit->stnames = info->snames; + pit->varstr = info->varstr; + pit->result = info->result; + pit->cfra = info->cfra; pit->instance_init = info->instance_init; if (info->init) info->init(); } MEM_freeN(info); } else { - printf ("Plugin returned unrecognized version number\n"); + printf("Plugin returned unrecognized version number\n"); return; } } @@ -158,8 +158,8 @@ void open_plugin_tex(PluginTex *pit) /* ------------------------------------------------------------------------- */ /* very badlevel define to bypass linking with BIF_interface.h */ -#define INT 96 -#define FLO 128 +#define INT 96 +#define FLO 128 PluginTex *add_plugin_tex(char *str) { @@ -167,24 +167,24 @@ PluginTex *add_plugin_tex(char *str) VarStruct *varstr; int a; - pit= MEM_callocN(sizeof(PluginTex), "plugintex"); + pit = MEM_callocN(sizeof(PluginTex), "plugintex"); BLI_strncpy(pit->name, str, sizeof(pit->name)); open_plugin_tex(pit); - if (pit->doit==NULL) { - if (pit->handle==NULL) {;} //XXX error("no plugin: %s", str); - else {;} //XXX error("in plugin: %s", str); + if (pit->doit == NULL) { + if (pit->handle == NULL) {; } //XXX error("no plugin: %s", str); + else {; } //XXX error("in plugin: %s", str); MEM_freeN(pit); return NULL; } - varstr= pit->varstr; - for (a=0; a<pit->vars; a++, varstr++) { - if ( (varstr->type & FLO)==FLO) - pit->data[a]= varstr->def; - else if ( (varstr->type & INT)==INT) - *((int *)(pit->data+a))= (int) varstr->def; + varstr = pit->varstr; + for (a = 0; a < pit->vars; a++, varstr++) { + if ( (varstr->type & FLO) == FLO) + pit->data[a] = varstr->def; + else if ( (varstr->type & INT) == INT) + *((int *)(pit->data + a)) = (int) varstr->def; } if (pit->instance_init) @@ -197,7 +197,7 @@ PluginTex *add_plugin_tex(char *str) void free_plugin_tex(PluginTex *pit) { - if (pit==NULL) return; + if (pit == NULL) return; /* no BLI_dynlib_close: same plugin can be opened multiple times, 1 handle */ MEM_freeN(pit); @@ -207,7 +207,7 @@ void free_plugin_tex(PluginTex *pit) TexMapping *add_tex_mapping(void) { - TexMapping *texmap= MEM_callocN(sizeof(TexMapping), "TexMapping"); + TexMapping *texmap = MEM_callocN(sizeof(TexMapping), "TexMapping"); default_tex_mapping(texmap); @@ -218,14 +218,14 @@ void default_tex_mapping(TexMapping *texmap) { memset(texmap, 0, sizeof(TexMapping)); - texmap->size[0]= texmap->size[1]= texmap->size[2]= 1.0f; - texmap->max[0]= texmap->max[1]= texmap->max[2]= 1.0f; + texmap->size[0] = texmap->size[1] = texmap->size[2] = 1.0f; + texmap->max[0] = texmap->max[1] = texmap->max[2] = 1.0f; unit_m4(texmap->mat); - texmap->projx= PROJ_X; - texmap->projy= PROJ_Y; - texmap->projz= PROJ_Z; - texmap->mapping= MTEX_FLAT; + texmap->projx = PROJ_X; + texmap->projy = PROJ_Y; + texmap->projz = PROJ_Z; + texmap->mapping = MTEX_FLAT; } void init_tex_mapping(TexMapping *texmap) @@ -233,7 +233,7 @@ void init_tex_mapping(TexMapping *texmap) float smat[3][3], rmat[3][3], mat[3][3], proj[3][3]; if (texmap->projx == PROJ_X && texmap->projy == PROJ_Y && texmap->projz == PROJ_Z && - is_zero_v3(texmap->loc) && is_zero_v3(texmap->rot) && is_one_v3(texmap->size)) { + is_zero_v3(texmap->loc) && is_zero_v3(texmap->rot) && is_one_v3(texmap->size)) { unit_m4(texmap->mat); texmap->flag |= TEXMAP_UNIT_MATRIX; @@ -243,11 +243,11 @@ void init_tex_mapping(TexMapping *texmap) zero_m3(proj); if (texmap->projx != PROJ_N) - proj[texmap->projx-1][0]= 1.0f; + proj[texmap->projx - 1][0] = 1.0f; if (texmap->projy != PROJ_N) - proj[texmap->projy-1][1]= 1.0f; + proj[texmap->projy - 1][1] = 1.0f; if (texmap->projz != PROJ_N) - proj[texmap->projz-1][2]= 1.0f; + proj[texmap->projz - 1][2] = 1.0f; /* scale */ size_to_mat3(smat, texmap->size); @@ -270,7 +270,7 @@ void init_tex_mapping(TexMapping *texmap) ColorMapping *add_color_mapping(void) { - ColorMapping *colormap= MEM_callocN(sizeof(ColorMapping), "ColorMapping"); + ColorMapping *colormap = MEM_callocN(sizeof(ColorMapping), "ColorMapping"); default_color_mapping(colormap); @@ -283,15 +283,15 @@ void default_color_mapping(ColorMapping *colormap) init_colorband(&colormap->coba, 1); - colormap->bright= 1.0; - colormap->contrast= 1.0; - colormap->saturation= 1.0; + colormap->bright = 1.0; + colormap->contrast = 1.0; + colormap->saturation = 1.0; - colormap->blend_color[0]= 0.8f; - colormap->blend_color[1]= 0.8f; - colormap->blend_color[2]= 0.8f; - colormap->blend_type= MA_RAMP_BLEND; - colormap->blend_factor= 0.0f; + colormap->blend_color[0] = 0.8f; + colormap->blend_color[1] = 0.8f; + colormap->blend_color[2] = 0.8f; + colormap->blend_type = MA_RAMP_BLEND; + colormap->blend_factor = 0.0f; } /* ****************** COLORBAND ******************* */ @@ -300,41 +300,41 @@ void init_colorband(ColorBand *coba, int rangetype) { int a; - coba->data[0].pos= 0.0; - coba->data[1].pos= 1.0; + coba->data[0].pos = 0.0; + coba->data[1].pos = 1.0; - if (rangetype==0) { - coba->data[0].r= 0.0; - coba->data[0].g= 0.0; - coba->data[0].b= 0.0; - coba->data[0].a= 0.0; - - coba->data[1].r= 1.0; - coba->data[1].g= 1.0; - coba->data[1].b= 1.0; - coba->data[1].a= 1.0; + if (rangetype == 0) { + coba->data[0].r = 0.0; + coba->data[0].g = 0.0; + coba->data[0].b = 0.0; + coba->data[0].a = 0.0; + + coba->data[1].r = 1.0; + coba->data[1].g = 1.0; + coba->data[1].b = 1.0; + coba->data[1].a = 1.0; } else { - coba->data[0].r= 0.0; - coba->data[0].g= 0.0; - coba->data[0].b= 0.0; - coba->data[0].a= 1.0; - - coba->data[1].r= 1.0; - coba->data[1].g= 1.0; - coba->data[1].b= 1.0; - coba->data[1].a= 1.0; + coba->data[0].r = 0.0; + coba->data[0].g = 0.0; + coba->data[0].b = 0.0; + coba->data[0].a = 1.0; + + coba->data[1].r = 1.0; + coba->data[1].g = 1.0; + coba->data[1].b = 1.0; + coba->data[1].a = 1.0; } - - for (a=2; a<MAXCOLORBAND; a++) { - coba->data[a].r= 0.5; - coba->data[a].g= 0.5; - coba->data[a].b= 0.5; - coba->data[a].a= 1.0; - coba->data[a].pos= 0.5; + + for (a = 2; a < MAXCOLORBAND; a++) { + coba->data[a].r = 0.5; + coba->data[a].g = 0.5; + coba->data[a].b = 0.5; + coba->data[a].a = 1.0; + coba->data[a].pos = 0.5; } - coba->tot= 2; + coba->tot = 2; } @@ -342,7 +342,7 @@ ColorBand *add_colorband(int rangetype) { ColorBand *coba; - coba= MEM_callocN(sizeof(ColorBand), "colorband"); + coba = MEM_callocN(sizeof(ColorBand), "colorband"); init_colorband(coba, rangetype); return coba; @@ -356,85 +356,85 @@ int do_colorband(const ColorBand *coba, float in, float out[4]) float fac, mfac, t[4]; int a; - if (coba==NULL || coba->tot==0) return 0; + if (coba == NULL || coba->tot == 0) return 0; - cbd1= coba->data; - if (coba->tot==1) { - out[0]= cbd1->r; - out[1]= cbd1->g; - out[2]= cbd1->b; - out[3]= cbd1->a; + cbd1 = coba->data; + if (coba->tot == 1) { + out[0] = cbd1->r; + out[1] = cbd1->g; + out[2] = cbd1->b; + out[3] = cbd1->a; } else { - if (in <= cbd1->pos && coba->ipotype<2) { - out[0]= cbd1->r; - out[1]= cbd1->g; - out[2]= cbd1->b; - out[3]= cbd1->a; + if (in <= cbd1->pos && coba->ipotype < 2) { + out[0] = cbd1->r; + out[1] = cbd1->g; + out[2] = cbd1->b; + out[3] = cbd1->a; } else { CBData left, right; /* we're looking for first pos > in */ - for (a=0; a<coba->tot; a++, cbd1++) if (cbd1->pos > in) break; + for (a = 0; a < coba->tot; a++, cbd1++) if (cbd1->pos > in) break; - if (a==coba->tot) { - cbd2= cbd1-1; - right= *cbd2; - right.pos= 1.0f; - cbd1= &right; + if (a == coba->tot) { + cbd2 = cbd1 - 1; + right = *cbd2; + right.pos = 1.0f; + cbd1 = &right; } - else if (a==0) { - left= *cbd1; - left.pos= 0.0f; - cbd2= &left; + else if (a == 0) { + left = *cbd1; + left.pos = 0.0f; + cbd2 = &left; } - else cbd2= cbd1-1; + else cbd2 = cbd1 - 1; - if (in >= cbd1->pos && coba->ipotype<2) { - out[0]= cbd1->r; - out[1]= cbd1->g; - out[2]= cbd1->b; - out[3]= cbd1->a; + if (in >= cbd1->pos && coba->ipotype < 2) { + out[0] = cbd1->r; + out[1] = cbd1->g; + out[2] = cbd1->b; + out[3] = cbd1->a; } else { - if (cbd2->pos!=cbd1->pos) - fac= (in-cbd1->pos)/(cbd2->pos-cbd1->pos); + if (cbd2->pos != cbd1->pos) + fac = (in - cbd1->pos) / (cbd2->pos - cbd1->pos); 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; + fac = (a != coba->tot) ? 0.0f : 1.0f; } - if (coba->ipotype==4) { + if (coba->ipotype == 4) { /* constant */ - out[0]= cbd2->r; - out[1]= cbd2->g; - out[2]= cbd2->b; - out[3]= cbd2->a; + out[0] = cbd2->r; + out[1] = cbd2->g; + out[2] = cbd2->b; + out[3] = cbd2->a; return 1; } - if (coba->ipotype>=2) { + if (coba->ipotype >= 2) { /* ipo from right to left: 3 2 1 0 */ - if (a>=coba->tot-1) cbd0= cbd1; - else cbd0= cbd1+1; - if (a<2) cbd3= cbd2; - else cbd3= cbd2-1; + if (a >= coba->tot - 1) cbd0 = cbd1; + else cbd0 = cbd1 + 1; + if (a < 2) cbd3 = cbd2; + else cbd3 = cbd2 - 1; CLAMP(fac, 0.0f, 1.0f); - if (coba->ipotype==3) + if (coba->ipotype == 3) key_curve_position_weights(fac, t, KEY_CARDINAL); else key_curve_position_weights(fac, t, KEY_BSPLINE); - out[0]= t[3]*cbd3->r +t[2]*cbd2->r +t[1]*cbd1->r +t[0]*cbd0->r; - out[1]= t[3]*cbd3->g +t[2]*cbd2->g +t[1]*cbd1->g +t[0]*cbd0->g; - 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; + out[0] = t[3] * cbd3->r + t[2] * cbd2->r + t[1] * cbd1->r + t[0] * cbd0->r; + out[1] = t[3] * cbd3->g + t[2] * cbd2->g + t[1] * cbd1->g + t[0] * cbd0->g; + 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.0f, 1.0f); CLAMP(out[1], 0.0f, 1.0f); CLAMP(out[2], 0.0f, 1.0f); @@ -442,40 +442,40 @@ int do_colorband(const ColorBand *coba, float in, float out[4]) } else { - if (coba->ipotype==1) { /* EASE */ - mfac= fac*fac; - fac= 3.0f*mfac-2.0f*mfac*fac; + if (coba->ipotype == 1) { /* EASE */ + mfac = fac * fac; + fac = 3.0f * mfac - 2.0f * mfac * fac; } - mfac= 1.0f-fac; + mfac = 1.0f - fac; - out[0]= mfac*cbd1->r + fac*cbd2->r; - out[1]= mfac*cbd1->g + fac*cbd2->g; - out[2]= mfac*cbd1->b + fac*cbd2->b; - out[3]= mfac*cbd1->a + fac*cbd2->a; + out[0] = mfac * cbd1->r + fac * cbd2->r; + out[1] = mfac * cbd1->g + fac * cbd2->g; + out[2] = mfac * cbd1->b + fac * cbd2->b; + out[3] = mfac * cbd1->a + fac * cbd2->a; } } } } - return 1; /* OK */ + return 1; /* OK */ } void colorband_table_RGBA(ColorBand *coba, float **array, int *size) { int a; - *size = CM_TABLE+1; - *array = MEM_callocN(sizeof(float)*(*size)*4, "ColorBand"); + *size = CM_TABLE + 1; + *array = MEM_callocN(sizeof(float) * (*size) * 4, "ColorBand"); - for (a=0; a<*size; a++) - do_colorband(coba, (float)a/(float)CM_TABLE, &(*array)[a*4]); + for (a = 0; a < *size; a++) + do_colorband(coba, (float)a / (float)CM_TABLE, &(*array)[a * 4]); } int vergcband(const void *a1, const void *a2) { - const CBData *x1=a1, *x2=a2; + const CBData *x1 = a1, *x2 = a2; - if ( x1->pos > x2->pos ) return 1; - else if ( x1->pos < x2->pos) return -1; + if (x1->pos > x2->pos) return 1; + else if (x1->pos < x2->pos) return -1; return 0; } @@ -483,17 +483,17 @@ void colorband_update_sort(ColorBand *coba) { int a; - if (coba->tot<2) + if (coba->tot < 2) return; - for (a=0; a<coba->tot; a++) - coba->data[a].cur= a; + for (a = 0; a < coba->tot; a++) + coba->data[a].cur = a; qsort(coba->data, coba->tot, sizeof(CBData), vergcband); - for (a=0; a<coba->tot; a++) { - if (coba->data[a].cur==coba->cur) { - coba->cur= a; + for (a = 0; a < coba->tot; a++) { + if (coba->data[a].cur == coba->cur) { + coba->cur = a; break; } } @@ -501,7 +501,7 @@ void colorband_update_sort(ColorBand *coba) CBData *colorband_element_add(struct ColorBand *coba, float position) { - if (coba->tot==MAXCOLORBAND) { + if (coba->tot == MAXCOLORBAND) { return NULL; } else if (coba->tot > 0) { @@ -520,7 +520,7 @@ CBData *colorband_element_add(struct ColorBand *coba, float position) } coba->tot++; - coba->cur = coba->tot-1; + coba->cur = coba->tot - 1; colorband_update_sort(coba); @@ -547,7 +547,7 @@ int colorband_element_remove(struct ColorBand *coba, int index) /* ******************* TEX ************************ */ -void free_texture(Tex *tex) +void BKE_texture_free(Tex *tex) { free_plugin_tex(tex->plugin); @@ -559,7 +559,7 @@ void free_texture(Tex *tex) BKE_free_animdata((struct ID *)tex); BKE_previewimg_free(&tex->preview); - BKE_icon_delete((struct ID*)tex); + BKE_icon_delete((struct ID *)tex); tex->id.icon_id = 0; if (tex->nodetree) { @@ -576,31 +576,31 @@ void default_tex(Tex *tex) VarStruct *varstr; int a; - tex->type= TEX_CLOUDS; - tex->stype= 0; - tex->flag= TEX_CHECKER_ODD; - tex->imaflag= TEX_INTERPOL|TEX_MIPMAP|TEX_USEALPHA; - tex->extend= TEX_REPEAT; - tex->cropxmin= tex->cropymin= 0.0; - tex->cropxmax= tex->cropymax= 1.0; + tex->type = TEX_CLOUDS; + tex->stype = 0; + tex->flag = TEX_CHECKER_ODD; + tex->imaflag = TEX_INTERPOL | TEX_MIPMAP | TEX_USEALPHA; + tex->extend = TEX_REPEAT; + tex->cropxmin = tex->cropymin = 0.0; + tex->cropxmax = tex->cropymax = 1.0; tex->texfilter = TXF_EWA; tex->afmax = 8; - tex->xrepeat= tex->yrepeat= 1; - tex->fie_ima= 2; - tex->sfra= 1; - tex->frames= 0; - tex->offset= 0; - tex->noisesize= 0.25; - tex->noisedepth= 2; - tex->turbul= 5.0; - tex->nabla= 0.025; // also in do_versions - tex->bright= 1.0; - tex->contrast= 1.0; - tex->saturation= 1.0; - tex->filtersize= 1.0; - tex->rfac= 1.0; - tex->gfac= 1.0; - tex->bfac= 1.0; + tex->xrepeat = tex->yrepeat = 1; + tex->fie_ima = 2; + tex->sfra = 1; + tex->frames = 0; + tex->offset = 0; + tex->noisesize = 0.25; + tex->noisedepth = 2; + tex->turbul = 5.0; + tex->nabla = 0.025; // also in do_versions + tex->bright = 1.0; + tex->contrast = 1.0; + tex->saturation = 1.0; + tex->filtersize = 1.0; + tex->rfac = 1.0; + tex->gfac = 1.0; + tex->bfac = 1.0; /* newnoise: init. */ tex->noisebasis = 0; tex->noisebasis2 = 0; @@ -621,11 +621,11 @@ void default_tex(Tex *tex) tex->vn_coltype = 0; if (tex->env) { - tex->env->stype=ENV_ANIM; - tex->env->clipsta=0.1; - tex->env->clipend=100; - tex->env->cuberes=600; - tex->env->depth=0; + tex->env->stype = ENV_ANIM; + tex->env->clipsta = 0.1; + tex->env->clipend = 100; + tex->env->cuberes = 600; + tex->env->depth = 0; } if (tex->pd) { @@ -635,8 +635,8 @@ void default_tex(Tex *tex) if (tex->vd) { tex->vd->resol[0] = tex->vd->resol[1] = tex->vd->resol[2] = 0; - tex->vd->interp_type=TEX_VD_LINEAR; - tex->vd->file_format=TEX_VD_SMOKE; + tex->vd->interp_type = TEX_VD_LINEAR; + tex->vd->file_format = TEX_VD_SMOKE; } if (tex->ot) { @@ -645,18 +645,18 @@ void default_tex(Tex *tex) } pit = tex->plugin; if (pit) { - varstr= pit->varstr; + varstr = pit->varstr; if (varstr) { - for (a=0; a<pit->vars; a++, varstr++) { + for (a = 0; a < pit->vars; a++, varstr++) { pit->data[a] = varstr->def; } } } - tex->iuser.fie_ima= 2; - tex->iuser.ok= 1; - tex->iuser.frames= 100; - tex->iuser.sfra= 1; + tex->iuser.fie_ima = 2; + tex->iuser.ok = 1; + tex->iuser.frames = 100; + tex->iuser.sfra = 1; tex->preview = NULL; } @@ -690,10 +690,10 @@ void tex_set_type(Tex *tex, int type) Tex *add_texture(const char *name) { - Main *bmain= G.main; + Main *bmain = G.main; Tex *tex; - tex= alloc_libblock(&bmain->tex, ID_TE, name); + tex = BKE_libblock_alloc(&bmain->tex, ID_TE, name); default_tex(tex); @@ -704,65 +704,65 @@ Tex *add_texture(const char *name) void default_mtex(MTex *mtex) { - mtex->texco= TEXCO_ORCO; - mtex->mapto= MAP_COL; - mtex->object= NULL; - mtex->projx= PROJ_X; - mtex->projy= PROJ_Y; - mtex->projz= PROJ_Z; - mtex->mapping= MTEX_FLAT; - mtex->ofs[0]= 0.0; - mtex->ofs[1]= 0.0; - mtex->ofs[2]= 0.0; - mtex->size[0]= 1.0; - mtex->size[1]= 1.0; - mtex->size[2]= 1.0; - mtex->tex= NULL; - mtex->texflag= MTEX_3TAP_BUMP | MTEX_BUMP_OBJECTSPACE; - mtex->colormodel= 0; - mtex->r= 1.0; - mtex->g= 0.0; - mtex->b= 1.0; - mtex->k= 1.0; - mtex->def_var= 1.0; - mtex->blendtype= MTEX_BLEND; - mtex->colfac= 1.0; - mtex->norfac= 1.0; - mtex->varfac= 1.0; - mtex->dispfac=0.2; - mtex->colspecfac= 1.0f; - mtex->mirrfac= 1.0f; - mtex->alphafac= 1.0f; - mtex->difffac= 1.0f; - mtex->specfac= 1.0f; - mtex->emitfac= 1.0f; - mtex->hardfac= 1.0f; - mtex->raymirrfac= 1.0f; - mtex->translfac= 1.0f; - mtex->ambfac= 1.0f; - mtex->colemitfac= 1.0f; - mtex->colreflfac= 1.0f; - mtex->coltransfac= 1.0f; - mtex->densfac= 1.0f; - mtex->scatterfac= 1.0f; - mtex->reflfac= 1.0f; - mtex->shadowfac= 1.0f; - mtex->zenupfac= 1.0f; - mtex->zendownfac= 1.0f; - mtex->blendfac= 1.0f; - mtex->timefac= 1.0f; - mtex->lengthfac= 1.0f; - mtex->clumpfac= 1.0f; - mtex->kinkfac= 1.0f; - mtex->roughfac= 1.0f; - mtex->padensfac= 1.0f; - mtex->lifefac= 1.0f; - mtex->sizefac= 1.0f; - mtex->ivelfac= 1.0f; - mtex->dampfac= 1.0f; - mtex->gravityfac= 1.0f; - mtex->fieldfac= 1.0f; - mtex->normapspace= MTEX_NSPACE_TANGENT; + mtex->texco = TEXCO_ORCO; + mtex->mapto = MAP_COL; + mtex->object = NULL; + mtex->projx = PROJ_X; + mtex->projy = PROJ_Y; + mtex->projz = PROJ_Z; + mtex->mapping = MTEX_FLAT; + mtex->ofs[0] = 0.0; + mtex->ofs[1] = 0.0; + mtex->ofs[2] = 0.0; + mtex->size[0] = 1.0; + mtex->size[1] = 1.0; + mtex->size[2] = 1.0; + mtex->tex = NULL; + mtex->texflag = MTEX_3TAP_BUMP | MTEX_BUMP_OBJECTSPACE; + mtex->colormodel = 0; + mtex->r = 1.0; + mtex->g = 0.0; + mtex->b = 1.0; + mtex->k = 1.0; + mtex->def_var = 1.0; + mtex->blendtype = MTEX_BLEND; + mtex->colfac = 1.0; + mtex->norfac = 1.0; + mtex->varfac = 1.0; + mtex->dispfac = 0.2; + mtex->colspecfac = 1.0f; + mtex->mirrfac = 1.0f; + mtex->alphafac = 1.0f; + mtex->difffac = 1.0f; + mtex->specfac = 1.0f; + mtex->emitfac = 1.0f; + mtex->hardfac = 1.0f; + mtex->raymirrfac = 1.0f; + mtex->translfac = 1.0f; + mtex->ambfac = 1.0f; + mtex->colemitfac = 1.0f; + mtex->colreflfac = 1.0f; + mtex->coltransfac = 1.0f; + mtex->densfac = 1.0f; + mtex->scatterfac = 1.0f; + mtex->reflfac = 1.0f; + mtex->shadowfac = 1.0f; + mtex->zenupfac = 1.0f; + mtex->zendownfac = 1.0f; + mtex->blendfac = 1.0f; + mtex->timefac = 1.0f; + mtex->lengthfac = 1.0f; + mtex->clumpfac = 1.0f; + mtex->kinkfac = 1.0f; + mtex->roughfac = 1.0f; + mtex->padensfac = 1.0f; + mtex->lifefac = 1.0f; + mtex->sizefac = 1.0f; + mtex->ivelfac = 1.0f; + mtex->dampfac = 1.0f; + mtex->gravityfac = 1.0f; + mtex->fieldfac = 1.0f; + mtex->normapspace = MTEX_NSPACE_TANGENT; } @@ -772,7 +772,7 @@ MTex *add_mtex(void) { MTex *mtex; - mtex= MEM_callocN(sizeof(MTex), "add_mtex"); + mtex = MEM_callocN(sizeof(MTex), "add_mtex"); default_mtex(mtex); @@ -787,16 +787,16 @@ MTex *add_mtex_id(ID *id, int slot) give_active_mtex(id, &mtex_ar, &act); - if (mtex_ar==NULL) { + if (mtex_ar == NULL) { return NULL; } - if (slot==-1) { + if (slot == -1) { /* find first free */ int i; - for (i= 0; i < MAX_MTEX; i++) { + for (i = 0; i < MAX_MTEX; i++) { if (!mtex_ar[i]) { - slot= i; + slot = i; break; } } @@ -814,41 +814,41 @@ MTex *add_mtex_id(ID *id, int slot) if (mtex_ar[slot]) { id_us_min((ID *)mtex_ar[slot]->tex); MEM_freeN(mtex_ar[slot]); - mtex_ar[slot]= NULL; + mtex_ar[slot] = NULL; } - mtex_ar[slot]= add_mtex(); + mtex_ar[slot] = add_mtex(); return mtex_ar[slot]; } /* ------------------------------------------------------------------------- */ -Tex *copy_texture(Tex *tex) +Tex *BKE_texture_copy(Tex *tex) { Tex *texn; - texn= copy_libblock(&tex->id); - if (texn->type==TEX_IMAGE) id_us_plus((ID *)texn->ima); - else texn->ima= NULL; + texn = BKE_libblock_copy(&tex->id); + if (texn->type == TEX_IMAGE) id_us_plus((ID *)texn->ima); + else texn->ima = NULL; if (texn->plugin) { - texn->plugin= MEM_dupallocN(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); - if (texn->pd) texn->pd= BKE_copy_pointdensity(texn->pd); - if (texn->vd) texn->vd= MEM_dupallocN(texn->vd); - if (texn->ot) texn->ot= BKE_copy_oceantex(texn->ot); + if (texn->coba) texn->coba = MEM_dupallocN(texn->coba); + if (texn->env) texn->env = BKE_copy_envmap(texn->env); + if (texn->pd) texn->pd = BKE_copy_pointdensity(texn->pd); + if (texn->vd) texn->vd = MEM_dupallocN(texn->vd); + if (texn->ot) texn->ot = BKE_copy_oceantex(texn->ot); if (tex->preview) texn->preview = BKE_previewimg_copy(tex->preview); if (tex->nodetree) { if (tex->nodetree->execdata) { ntreeTexEndExecTree(tex->nodetree->execdata, 1); } - texn->nodetree= ntreeCopyTree(tex->nodetree); + texn->nodetree = ntreeCopyTree(tex->nodetree); } return texn; @@ -859,35 +859,35 @@ Tex *localize_texture(Tex *tex) { Tex *texn; - texn= copy_libblock(&tex->id); + texn = BKE_libblock_copy(&tex->id); BLI_remlink(&G.main->tex, texn); - /* image texture: free_texture also doesn't decrease */ + /* image texture: BKE_texture_free also doesn't decrease */ if (texn->plugin) { - texn->plugin= MEM_dupallocN(texn->plugin); + texn->plugin = MEM_dupallocN(texn->plugin); open_plugin_tex(texn->plugin); } - if (texn->coba) texn->coba= MEM_dupallocN(texn->coba); + if (texn->coba) texn->coba = MEM_dupallocN(texn->coba); if (texn->env) { - texn->env= BKE_copy_envmap(texn->env); + texn->env = BKE_copy_envmap(texn->env); id_us_min(&texn->env->ima->id); } - if (texn->pd) texn->pd= BKE_copy_pointdensity(texn->pd); + if (texn->pd) texn->pd = BKE_copy_pointdensity(texn->pd); if (texn->vd) { - texn->vd= MEM_dupallocN(texn->vd); + texn->vd = MEM_dupallocN(texn->vd); if (texn->vd->dataset) - texn->vd->dataset= MEM_dupallocN(texn->vd->dataset); + texn->vd->dataset = MEM_dupallocN(texn->vd->dataset); } if (texn->ot) { - texn->ot= BKE_copy_oceantex(tex->ot); + texn->ot = BKE_copy_oceantex(tex->ot); } texn->preview = NULL; if (tex->nodetree) { - texn->nodetree= ntreeLocalize(tex->nodetree); + texn->nodetree = ntreeLocalize(tex->nodetree); } return texn; @@ -901,76 +901,76 @@ static void extern_local_texture(Tex *tex) id_lib_extern((ID *)tex->ima); } -void make_local_texture(Tex *tex) +void BKE_texture_make_local(Tex *tex) { - Main *bmain= G.main; + Main *bmain = G.main; Material *ma; World *wrld; Lamp *la; Brush *br; ParticleSettings *pa; - int a, is_local= FALSE, is_lib= FALSE; + int a, is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (tex->id.lib==NULL) return; + if (tex->id.lib == NULL) return; - if (tex->id.us==1) { + if (tex->id.us == 1) { id_clear_lib_data(bmain, &tex->id); extern_local_texture(tex); return; } - ma= bmain->mat.first; + ma = bmain->mat.first; while (ma) { - for (a=0; a<MAX_MTEX; a++) { - if (ma->mtex[a] && ma->mtex[a]->tex==tex) { - if (ma->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (a = 0; a < MAX_MTEX; a++) { + if (ma->mtex[a] && ma->mtex[a]->tex == tex) { + if (ma->id.lib) is_lib = TRUE; + else is_local = TRUE; } } - ma= ma->id.next; + ma = ma->id.next; } - la= bmain->lamp.first; + la = bmain->lamp.first; while (la) { - for (a=0; a<MAX_MTEX; a++) { - if (la->mtex[a] && la->mtex[a]->tex==tex) { - if (la->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (a = 0; a < MAX_MTEX; a++) { + if (la->mtex[a] && la->mtex[a]->tex == tex) { + if (la->id.lib) is_lib = TRUE; + else is_local = TRUE; } } - la= la->id.next; + la = la->id.next; } - wrld= bmain->world.first; + wrld = bmain->world.first; while (wrld) { - for (a=0; a<MAX_MTEX; a++) { - if (wrld->mtex[a] && wrld->mtex[a]->tex==tex) { - if (wrld->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (a = 0; a < MAX_MTEX; a++) { + if (wrld->mtex[a] && wrld->mtex[a]->tex == tex) { + if (wrld->id.lib) is_lib = TRUE; + else is_local = TRUE; } } - wrld= wrld->id.next; + wrld = wrld->id.next; } - br= bmain->brush.first; + br = bmain->brush.first; while (br) { - if (br->mtex.tex==tex) { - if (br->id.lib) is_lib= TRUE; - else is_local= TRUE; + if (br->mtex.tex == tex) { + if (br->id.lib) is_lib = TRUE; + else is_local = TRUE; } - br= br->id.next; + br = br->id.next; } - pa= bmain->particle.first; + pa = bmain->particle.first; while (pa) { - for (a=0; a<MAX_MTEX; a++) { - if (pa->mtex[a] && pa->mtex[a]->tex==tex) { - if (pa->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (a = 0; a < MAX_MTEX; a++) { + if (pa->mtex[a] && pa->mtex[a]->tex == tex) { + if (pa->id.lib) is_lib = TRUE; + else is_local = TRUE; } } - pa= pa->id.next; + pa = pa->id.next; } if (is_local && is_lib == FALSE) { @@ -978,75 +978,75 @@ void make_local_texture(Tex *tex) extern_local_texture(tex); } else if (is_local && is_lib) { - Tex *tex_new= copy_texture(tex); + Tex *tex_new = BKE_texture_copy(tex); - tex_new->id.us= 0; + tex_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, tex->id.lib, &tex_new->id); - ma= bmain->mat.first; + ma = bmain->mat.first; while (ma) { - for (a=0; a<MAX_MTEX; a++) { - if (ma->mtex[a] && ma->mtex[a]->tex==tex) { - if (ma->id.lib==NULL) { - ma->mtex[a]->tex= tex_new; + for (a = 0; a < MAX_MTEX; a++) { + if (ma->mtex[a] && ma->mtex[a]->tex == tex) { + if (ma->id.lib == NULL) { + ma->mtex[a]->tex = tex_new; tex_new->id.us++; tex->id.us--; } } } - ma= ma->id.next; + ma = ma->id.next; } - la= bmain->lamp.first; + la = bmain->lamp.first; while (la) { - for (a=0; a<MAX_MTEX; a++) { - if (la->mtex[a] && la->mtex[a]->tex==tex) { - if (la->id.lib==NULL) { - la->mtex[a]->tex= tex_new; + for (a = 0; a < MAX_MTEX; a++) { + if (la->mtex[a] && la->mtex[a]->tex == tex) { + if (la->id.lib == NULL) { + la->mtex[a]->tex = tex_new; tex_new->id.us++; tex->id.us--; } } } - la= la->id.next; + la = la->id.next; } - wrld= bmain->world.first; + wrld = bmain->world.first; while (wrld) { - for (a=0; a<MAX_MTEX; a++) { - if (wrld->mtex[a] && wrld->mtex[a]->tex==tex) { - if (wrld->id.lib==NULL) { - wrld->mtex[a]->tex= tex_new; + for (a = 0; a < MAX_MTEX; a++) { + if (wrld->mtex[a] && wrld->mtex[a]->tex == tex) { + if (wrld->id.lib == NULL) { + wrld->mtex[a]->tex = tex_new; tex_new->id.us++; tex->id.us--; } } } - wrld= wrld->id.next; + wrld = wrld->id.next; } - br= bmain->brush.first; + br = bmain->brush.first; while (br) { - if (br->mtex.tex==tex) { - if (br->id.lib==NULL) { - br->mtex.tex= tex_new; + if (br->mtex.tex == tex) { + if (br->id.lib == NULL) { + br->mtex.tex = tex_new; tex_new->id.us++; tex->id.us--; } } - br= br->id.next; + br = br->id.next; } - pa= bmain->particle.first; + pa = bmain->particle.first; while (pa) { - for (a=0; a<MAX_MTEX; a++) { - if (pa->mtex[a] && pa->mtex[a]->tex==tex) { - if (pa->id.lib==NULL) { - pa->mtex[a]->tex= tex_new; + for (a = 0; a < MAX_MTEX; a++) { + if (pa->mtex[a] && pa->mtex[a]->tex == tex) { + if (pa->id.lib == NULL) { + pa->mtex[a]->tex = tex_new; tex_new->id.us++; tex->id.us--; } } } - pa= pa->id.next; + pa = pa->id.next; } } } @@ -1055,10 +1055,10 @@ void make_local_texture(Tex *tex) #if 0 /* UNUSED */ void autotexname(Tex *tex) { - Main *bmain= G.main; - char texstr[20][15]= {"None", "Clouds", "Wood", "Marble", "Magic", "Blend", - "Stucci", "Noise", "Image", "Plugin", "EnvMap", "Musgrave", - "Voronoi", "DistNoise", "Point Density", "Voxel Data", "Ocean", "", "", ""}; + Main *bmain = G.main; + char texstr[20][15] = {"None", "Clouds", "Wood", "Marble", "Magic", "Blend", + "Stucci", "Noise", "Image", "Plugin", "EnvMap", "Musgrave", + "Voronoi", "DistNoise", "Point Density", "Voxel Data", "Ocean", "", "", ""}; Image *ima; char di[FILE_MAXDIR], fi[FILE_MAXFILE]; @@ -1067,8 +1067,8 @@ void autotexname(Tex *tex) new_id(&bmain->tex, (ID *)tex, "Noddy"); } else - if (tex->type==TEX_IMAGE) { - ima= tex->ima; + if (tex->type == TEX_IMAGE) { + ima = tex->ima; if (ima) { BLI_strncpy(di, ima->name, sizeof(di)); BLI_splitdirstring(di, fi); @@ -1078,7 +1078,7 @@ void autotexname(Tex *tex) } else new_id(&bmain->tex, (ID *)tex, texstr[tex->type]); } - else if (tex->type==TEX_PLUGIN && tex->plugin) new_id(&bmain->tex, (ID *)tex, tex->plugin->pname); + else if (tex->type == TEX_PLUGIN && tex->plugin) new_id(&bmain->tex, (ID *)tex, tex->plugin->pname); else new_id(&bmain->tex, (ID *)tex, texstr[tex->type]); } } @@ -1089,21 +1089,21 @@ void autotexname(Tex *tex) Tex *give_current_object_texture(Object *ob) { Material *ma, *node_ma; - Tex *tex= NULL; + Tex *tex = NULL; - if (ob==NULL) return NULL; - if (ob->totcol==0 && !(ob->type==OB_LAMP)) return NULL; + if (ob == NULL) return NULL; + if (ob->totcol == 0 && !(ob->type == OB_LAMP)) return NULL; - if (ob->type==OB_LAMP) { - tex= give_current_lamp_texture(ob->data); + if (ob->type == OB_LAMP) { + tex = give_current_lamp_texture(ob->data); } else { - ma= give_current_material(ob, ob->actcol); + ma = give_current_material(ob, ob->actcol); - if ((node_ma=give_node_material(ma))) - ma= node_ma; + if ((node_ma = give_node_material(ma))) + ma = node_ma; - tex= give_current_material_texture(ma); + tex = give_current_material_texture(ma); } return tex; @@ -1111,12 +1111,12 @@ Tex *give_current_object_texture(Object *ob) Tex *give_current_lamp_texture(Lamp *la) { - MTex *mtex= NULL; - Tex *tex= NULL; + MTex *mtex = NULL; + Tex *tex = NULL; if (la) { - mtex= la->mtex[(int)(la->texact)]; - if (mtex) tex= mtex->tex; + mtex = la->mtex[(int)(la->texact)]; + if (mtex) tex = mtex->tex; } return tex; @@ -1124,23 +1124,23 @@ Tex *give_current_lamp_texture(Lamp *la) void set_current_lamp_texture(Lamp *la, Tex *newtex) { - int act= la->texact; + int act = la->texact; if (la->mtex[act] && la->mtex[act]->tex) id_us_min(&la->mtex[act]->tex->id); if (newtex) { if (!la->mtex[act]) { - la->mtex[act]= add_mtex(); - la->mtex[act]->texco= TEXCO_GLOB; + la->mtex[act] = add_mtex(); + la->mtex[act]->texco = TEXCO_GLOB; } - la->mtex[act]->tex= newtex; + la->mtex[act]->tex = newtex; id_us_plus(&newtex->id); } else if (la->mtex[act]) { MEM_freeN(la->mtex[act]); - la->mtex[act]= NULL; + la->mtex[act] = NULL; } } @@ -1154,25 +1154,25 @@ bNode *give_current_material_texture_node(Material *ma) Tex *give_current_material_texture(Material *ma) { - MTex *mtex= NULL; - Tex *tex= NULL; + MTex *mtex = NULL; + Tex *tex = NULL; bNode *node; if (ma && ma->use_nodes && ma->nodetree) { /* first check texture, then material, this works together * with a hack that clears the active ID flag for textures on * making a material node active */ - node= nodeGetActiveID(ma->nodetree, ID_TE); + node = nodeGetActiveID(ma->nodetree, ID_TE); if (node) { - tex= (Tex *)node->id; - ma= NULL; + tex = (Tex *)node->id; + ma = NULL; } } if (ma) { - mtex= ma->mtex[(int)(ma->texact)]; - if (mtex) tex= mtex->tex; + mtex = ma->mtex[(int)(ma->texact)]; + if (mtex) tex = mtex->tex; } return tex; @@ -1181,26 +1181,26 @@ Tex *give_current_material_texture(Material *ma) int give_active_mtex(ID *id, MTex ***mtex_ar, short *act) { switch (GS(id->name)) { - case ID_MA: - *mtex_ar= ((Material *)id)->mtex; - if (act) *act= (((Material *)id)->texact); - break; - case ID_WO: - *mtex_ar= ((World *)id)->mtex; - if (act) *act= (((World *)id)->texact); - break; - case ID_LA: - *mtex_ar= ((Lamp *)id)->mtex; - if (act) *act= (((Lamp *)id)->texact); - break; - case ID_PA: - *mtex_ar= ((ParticleSettings *)id)->mtex; - if (act) *act= (((ParticleSettings *)id)->texact); - break; - default: - *mtex_ar = NULL; - if (act) *act= 0; - return FALSE; + case ID_MA: + *mtex_ar = ((Material *)id)->mtex; + if (act) *act = (((Material *)id)->texact); + break; + case ID_WO: + *mtex_ar = ((World *)id)->mtex; + if (act) *act = (((World *)id)->texact); + break; + case ID_LA: + *mtex_ar = ((Lamp *)id)->mtex; + if (act) *act = (((Lamp *)id)->texact); + break; + case ID_PA: + *mtex_ar = ((ParticleSettings *)id)->mtex; + if (act) *act = (((ParticleSettings *)id)->texact); + break; + default: + *mtex_ar = NULL; + if (act) *act = 0; + return FALSE; } return TRUE; @@ -1208,57 +1208,57 @@ int give_active_mtex(ID *id, MTex ***mtex_ar, short *act) void set_active_mtex(ID *id, short act) { - if (act<0) act= 0; - else if (act>=MAX_MTEX) act= MAX_MTEX-1; + if (act < 0) act = 0; + else if (act >= MAX_MTEX) act = MAX_MTEX - 1; switch (GS(id->name)) { - case ID_MA: - ((Material *)id)->texact= act; - break; - case ID_WO: - ((World *)id)->texact= act; - break; - case ID_LA: - ((Lamp *)id)->texact= act; - break; - case ID_PA: - ((ParticleSettings *)id)->texact= act; - break; + case ID_MA: + ((Material *)id)->texact = act; + break; + case ID_WO: + ((World *)id)->texact = act; + break; + case ID_LA: + ((Lamp *)id)->texact = act; + break; + case ID_PA: + ((ParticleSettings *)id)->texact = act; + break; } } void set_current_material_texture(Material *ma, Tex *newtex) { - Tex *tex= NULL; + Tex *tex = NULL; bNode *node; if (ma && ma->use_nodes && ma->nodetree) { - node= nodeGetActiveID(ma->nodetree, ID_TE); + node = nodeGetActiveID(ma->nodetree, ID_TE); if (node) { - tex= (Tex *)node->id; + tex = (Tex *)node->id; id_us_min(&tex->id); - node->id= &newtex->id; + node->id = &newtex->id; id_us_plus(&newtex->id); - ma= NULL; + ma = NULL; } } if (ma) { - int act= (int)ma->texact; + int act = (int)ma->texact; - tex= (ma->mtex[act])? ma->mtex[act]->tex: NULL; + tex = (ma->mtex[act]) ? ma->mtex[act]->tex : NULL; id_us_min(&tex->id); if (newtex) { if (!ma->mtex[act]) - ma->mtex[act]= add_mtex(); + ma->mtex[act] = add_mtex(); - ma->mtex[act]->tex= newtex; + ma->mtex[act]->tex = newtex; id_us_plus(&newtex->id); } else if (ma->mtex[act]) { MEM_freeN(ma->mtex[act]); - ma->mtex[act]= NULL; + ma->mtex[act] = NULL; } } } @@ -1268,7 +1268,7 @@ int has_current_material_texture(Material *ma) bNode *node; if (ma && ma->use_nodes && ma->nodetree) { - node= nodeGetActiveID(ma->nodetree, ID_TE); + node = nodeGetActiveID(ma->nodetree, ID_TE); if (node) return 1; @@ -1279,36 +1279,36 @@ int has_current_material_texture(Material *ma) Tex *give_current_world_texture(World *world) { - MTex *mtex= NULL; - Tex *tex= NULL; + MTex *mtex = NULL; + Tex *tex = NULL; if (!world) return NULL; - mtex= world->mtex[(int)(world->texact)]; - if (mtex) tex= mtex->tex; + mtex = world->mtex[(int)(world->texact)]; + if (mtex) tex = mtex->tex; return tex; } void set_current_world_texture(World *wo, Tex *newtex) { - int act= wo->texact; + int act = wo->texact; if (wo->mtex[act] && wo->mtex[act]->tex) id_us_min(&wo->mtex[act]->tex->id); if (newtex) { if (!wo->mtex[act]) { - wo->mtex[act]= add_mtex(); - wo->mtex[act]->texco= TEXCO_VIEW; + wo->mtex[act] = add_mtex(); + wo->mtex[act]->texco = TEXCO_VIEW; } - wo->mtex[act]->tex= newtex; + wo->mtex[act]->tex = newtex; id_us_plus(&newtex->id); } else if (wo->mtex[act]) { MEM_freeN(wo->mtex[act]); - wo->mtex[act]= NULL; + wo->mtex[act] = NULL; } } @@ -1323,44 +1323,44 @@ void set_current_brush_texture(Brush *br, Tex *newtex) id_us_min(&br->mtex.tex->id); if (newtex) { - br->mtex.tex= newtex; + br->mtex.tex = newtex; id_us_plus(&newtex->id); } } Tex *give_current_particle_texture(ParticleSettings *part) { - MTex *mtex= NULL; - Tex *tex= NULL; + MTex *mtex = NULL; + Tex *tex = NULL; if (!part) return NULL; - mtex= part->mtex[(int)(part->texact)]; - if (mtex) tex= mtex->tex; + mtex = part->mtex[(int)(part->texact)]; + if (mtex) tex = mtex->tex; return tex; } void set_current_particle_texture(ParticleSettings *part, Tex *newtex) { - int act= part->texact; + int act = part->texact; if (part->mtex[act] && part->mtex[act]->tex) id_us_min(&part->mtex[act]->tex->id); if (newtex) { if (!part->mtex[act]) { - part->mtex[act]= add_mtex(); - part->mtex[act]->texco= TEXCO_ORCO; - part->mtex[act]->blendtype= MTEX_MUL; + part->mtex[act] = add_mtex(); + part->mtex[act]->texco = TEXCO_ORCO; + part->mtex[act]->blendtype = MTEX_MUL; } - part->mtex[act]->tex= newtex; + part->mtex[act]->tex = newtex; id_us_plus(&newtex->id); } else if (part->mtex[act]) { MEM_freeN(part->mtex[act]); - part->mtex[act]= NULL; + part->mtex[act] = NULL; } } @@ -1370,12 +1370,12 @@ EnvMap *BKE_add_envmap(void) { EnvMap *env; - env= MEM_callocN(sizeof(EnvMap), "envmap"); - env->type= ENV_CUBE; - env->stype= ENV_ANIM; - env->clipsta= 0.1; - env->clipend= 100.0; - env->cuberes= 600; + env = MEM_callocN(sizeof(EnvMap), "envmap"); + env->type = ENV_CUBE; + env->stype = ENV_ANIM; + env->clipsta = 0.1; + env->clipend = 100.0; + env->cuberes = 600; env->viewscale = 0.5; return env; @@ -1388,9 +1388,9 @@ EnvMap *BKE_copy_envmap(EnvMap *env) EnvMap *envn; int a; - envn= MEM_dupallocN(env); - envn->ok= 0; - for (a=0; a<6; a++) envn->cube[a]= NULL; + envn = MEM_dupallocN(env); + envn->ok = 0; + for (a = 0; a < 6; a++) envn->cube[a] = NULL; if (envn->ima) id_us_plus((ID *)envn->ima); return envn; @@ -1402,12 +1402,12 @@ void BKE_free_envmapdata(EnvMap *env) { unsigned int part; - for (part=0; part<6; part++) { + for (part = 0; part < 6; part++) { if (env->cube[part]) IMB_freeImBuf(env->cube[part]); - env->cube[part]= NULL; + env->cube[part] = NULL; } - env->ok= 0; + env->ok = 0; } /* ------------------------------------------------------------------------- */ @@ -1426,7 +1426,7 @@ PointDensity *BKE_add_pointdensity(void) { PointDensity *pd; - pd= MEM_callocN(sizeof(PointDensity), "pointdensity"); + pd = MEM_callocN(sizeof(PointDensity), "pointdensity"); pd->flag = 0; pd->radius = 0.3f; pd->falloff_type = TEX_PD_FALLOFF_STD; @@ -1443,7 +1443,7 @@ PointDensity *BKE_add_pointdensity(void) pd->totpoints = 0; pd->object = NULL; pd->psys = 0; - pd->psys_cache_space= TEX_PD_WORLDSPACE; + pd->psys_cache_space = TEX_PD_WORLDSPACE; pd->falloff_curve = curvemapping_add(1, 0, 0, 1, 1); pd->falloff_curve->preset = CURVE_PRESET_LINE; @@ -1458,10 +1458,10 @@ PointDensity *BKE_copy_pointdensity(PointDensity *pd) { PointDensity *pdn; - pdn= MEM_dupallocN(pd); + pdn = MEM_dupallocN(pd); pdn->point_tree = NULL; pdn->point_data = NULL; - if (pdn->coba) pdn->coba= MEM_dupallocN(pdn->coba); + if (pdn->coba) pdn->coba = MEM_dupallocN(pdn->coba); pdn->falloff_curve = curvemapping_copy(pdn->falloff_curve); /* can be NULL */ return pdn; } @@ -1492,7 +1492,7 @@ void BKE_free_pointdensity(PointDensity *pd) /* ------------------------------------------------------------------------- */ -void BKE_free_voxeldatadata(struct VoxelData *vd) +void BKE_free_voxeldatadata(VoxelData *vd) { if (vd->dataset) { MEM_freeN(vd->dataset); @@ -1501,21 +1501,21 @@ void BKE_free_voxeldatadata(struct VoxelData *vd) } -void BKE_free_voxeldata(struct VoxelData *vd) +void BKE_free_voxeldata(VoxelData *vd) { BKE_free_voxeldatadata(vd); MEM_freeN(vd); } -struct VoxelData *BKE_add_voxeldata(void) +VoxelData *BKE_add_voxeldata(void) { VoxelData *vd; - vd= MEM_callocN(sizeof(struct VoxelData), "voxeldata"); + vd = MEM_callocN(sizeof(VoxelData), "voxeldata"); vd->dataset = NULL; vd->resol[0] = vd->resol[1] = vd->resol[2] = 1; - vd->interp_type= TEX_VD_LINEAR; - vd->file_format= TEX_VD_SMOKE; + vd->interp_type = TEX_VD_LINEAR; + vd->file_format = TEX_VD_SMOKE; vd->int_multiplier = 1.0; vd->extend = TEX_CLIP; vd->object = NULL; @@ -1523,13 +1523,13 @@ struct VoxelData *BKE_add_voxeldata(void) vd->ok = 0; return vd; - } +} -struct VoxelData *BKE_copy_voxeldata(struct VoxelData *vd) +VoxelData *BKE_copy_voxeldata(VoxelData *vd) { VoxelData *vdn; - vdn= MEM_dupallocN(vd); + vdn = MEM_dupallocN(vd); vdn->dataset = NULL; return vdn; @@ -1537,20 +1537,20 @@ struct VoxelData *BKE_copy_voxeldata(struct VoxelData *vd) /* ------------------------------------------------------------------------- */ -struct OceanTex *BKE_add_oceantex(void) +OceanTex *BKE_add_oceantex(void) { OceanTex *ot; - ot= MEM_callocN(sizeof(struct OceanTex), "ocean texture"); + ot = MEM_callocN(sizeof(struct OceanTex), "ocean texture"); ot->output = TEX_OCN_DISPLACEMENT; ot->object = NULL; return ot; } -struct OceanTex *BKE_copy_oceantex(struct OceanTex *ot) +OceanTex *BKE_copy_oceantex(struct OceanTex *ot) { - OceanTex *otn= MEM_dupallocN(ot); + OceanTex *otn = MEM_dupallocN(ot); return otn; } @@ -1568,8 +1568,9 @@ int BKE_texture_dependsOnTime(const struct Tex *texture) // assume all plugins depend on time return 1; } - else if ( texture->ima && - ELEM(texture->ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) { + else if (texture->ima && + ELEM(texture->ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) + { return 1; } else if (texture->adt) { diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index f4335862629..4e2b4be474b 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -166,11 +166,11 @@ void BKE_tracking_clamp_track(MovieTrackingTrack *track, int event) /* search shouldn't be moved inside pattern */ if (track->search_min[a] > pat_min[a]) { track->search_min[a] = pat_min[a]; - track->search_max[a] = track->search_min[a]+dim[a]; + track->search_max[a] = track->search_min[a] + dim[a]; } if (track->search_max[a] < pat_max[a]) { track->search_max[a] = pat_max[a]; - track->search_min[a] = track->search_max[a]-dim[a]; + track->search_min[a] = track->search_max[a] - dim[a]; } } } @@ -196,8 +196,8 @@ void BKE_tracking_clamp_track(MovieTrackingTrack *track, int event) sub_v2_v2v2(dim, track->pat_max, track->pat_min); for (a = 0; a < 2; a++) { - track->pat_min[a] = -dim[a]/2.0f; - track->pat_max[a] = dim[a]/2.0f; + track->pat_min[a] = -dim[a] / 2.0f; + track->pat_max[a] = dim[a] / 2.0f; } } } @@ -302,8 +302,9 @@ MovieTrackingMarker *BKE_tracking_insert_marker(MovieTrackingTrack *track, Movie else track->markers = MEM_callocN(sizeof(MovieTrackingMarker), "MovieTracking markers"); - memmove(track->markers+a+2, track->markers+a+1, (track->markersnr-a-2)*sizeof(MovieTrackingMarker)); - track->markers[a+1] = *marker; + memmove(track->markers + a + 2, track->markers + a + 1, + (track->markersnr - a - 2) * sizeof(MovieTrackingMarker)); + track->markers[a + 1] = *marker; track->last_marker = a + 1; @@ -315,12 +316,13 @@ void BKE_tracking_delete_marker(MovieTrackingTrack *track, int framenr) { int a = 0; - while (a<track->markersnr) { + while (a < track->markersnr) { if (track->markers[a].framenr == framenr) { if (track->markersnr > 1) { - memmove(track->markers+a, track->markers+a+1, (track->markersnr-a-1)*sizeof(MovieTrackingMarker)); + memmove(track->markers + a, track->markers + a + 1, + (track->markersnr - a - 1) * sizeof(MovieTrackingMarker)); track->markersnr--; - track->markers = MEM_reallocN(track->markers, sizeof(MovieTrackingMarker)*track->markersnr); + track->markers = MEM_reallocN(track->markers, sizeof(MovieTrackingMarker) * track->markersnr); } else { MEM_freeN(track->markers); @@ -337,7 +339,7 @@ void BKE_tracking_delete_marker(MovieTrackingTrack *track, int framenr) MovieTrackingMarker *BKE_tracking_get_marker(MovieTrackingTrack *track, int framenr) { - int a = track->markersnr-1; + int a = track->markersnr - 1; if (!track->markersnr) return NULL; @@ -360,7 +362,7 @@ MovieTrackingMarker *BKE_tracking_get_marker(MovieTrackingTrack *track, int fram } /* if there's no marker for exact position, use nearest marker from left side */ - return &track->markers[a-1]; + return &track->markers[a - 1]; } else { while (a >= 0 && track->markers[a].framenr >= framenr) { @@ -461,16 +463,16 @@ void BKE_tracking_clear_path(MovieTrackingTrack *track, int ref_frame, int actio } if (track->markersnr) - put_disabled_marker(track, &track->markers[track->markersnr-1], 0, 1); + put_disabled_marker(track, &track->markers[track->markersnr - 1], 0, 1); } else if (action == TRACK_CLEAR_UPTO) { - a = track->markersnr-1; + a = track->markersnr - 1; while (a >= 0) { if (track->markers[a].framenr <= ref_frame) { - memmove(track->markers, track->markers+a, (track->markersnr-a)*sizeof(MovieTrackingMarker)); + memmove(track->markers, track->markers + a, (track->markersnr - a) * sizeof(MovieTrackingMarker)); - track->markersnr = track->markersnr-a; + track->markersnr = track->markersnr - a; track->markers = MEM_reallocN(track->markers, sizeof(MovieTrackingMarker)*track->markersnr); break; @@ -521,8 +523,8 @@ void BKE_tracking_join_tracks(MovieTrackingTrack *dst_track, MovieTrackingTrack markers[i] = dst_track->markers[b++]; } else { - if ((src_track->markers[a].flag & MARKER_DISABLED)==0) { - if ((dst_track->markers[b].flag & MARKER_DISABLED)==0) { + if ((src_track->markers[a].flag & MARKER_DISABLED) == 0) { + if ((dst_track->markers[b].flag & MARKER_DISABLED) == 0) { /* both tracks are enabled on this frame, so find the whole segment * on which tracks are intersecting and blend tracks using linear * interpolation to prevent jumps */ @@ -532,8 +534,8 @@ void BKE_tracking_join_tracks(MovieTrackingTrack *dst_track, MovieTrackingTrack int j, inverse = 0; inverse = (b == 0) || - (dst_track->markers[b-1].flag & MARKER_DISABLED) || - (dst_track->markers[b-1].framenr != frame - 1); + (dst_track->markers[b - 1].flag & MARKER_DISABLED) || + (dst_track->markers[b - 1].framenr != frame - 1); /* find length of intersection */ while (a < src_track->markersnr && b < dst_track->markersnr) { @@ -969,7 +971,7 @@ MovieTrackingContext *BKE_tracking_context_new(MovieClip *clip, MovieClipUser *u /* count */ track = tracksbase->first; while (track) { - if (TRACK_SELECTED(track) && (track->flag & (TRACK_LOCKED | TRACK_HIDDEN))==0) { + if (TRACK_SELECTED(track) && (track->flag & (TRACK_LOCKED | TRACK_HIDDEN)) == 0) { MovieTrackingMarker *marker = BKE_tracking_get_marker(track, user->framenr); if ((marker->flag & MARKER_DISABLED) == 0) @@ -1000,13 +1002,13 @@ MovieTrackingContext *BKE_tracking_context_new(MovieClip *clip, MovieClipUser *u #ifdef WITH_LIBMV { - float patx = (int)((track->pat_max[0]-track->pat_min[0])*width), - paty = (int)((track->pat_max[1]-track->pat_min[1])*height); + float patx = (int)((track->pat_max[0] - track->pat_min[0]) * width), + paty = (int)((track->pat_max[1] - track->pat_min[1]) * height); - float search_size_x = (track->search_max[0]-track->search_min[0])*width; - float search_size_y = (track->search_max[1]-track->search_min[1])*height; - float pattern_size_x = (track->pat_max[0]-track->pat_min[0])*width; - float pattern_size_y = (track->pat_max[1]-track->pat_min[1])*height; + float search_size_x = (track->search_max[0] - track->search_min[0]) * width; + float search_size_y = (track->search_max[1] - track->search_min[1]) * height; + float pattern_size_x = (track->pat_max[0] - track->pat_min[0]) * width; + float pattern_size_y = (track->pat_max[1] - track->pat_min[1]) * height; int wndx = (int)patx / 2, wndy = (int)paty / 2; int half_wnd = MAX2(wndx, wndy); @@ -1021,17 +1023,20 @@ MovieTrackingContext *BKE_tracking_context_new(MovieClip *clip, MovieClipUser *u * than the search size */ int level = MIN2(track->pyramid_levels, max_pyramid_levels); + struct libmv_RegionTracker *region_tracker; + if (track->tracker == TRACKER_KLT) { - track_context.region_tracker = - libmv_pyramidRegionTrackerNew(100, level, half_wnd, track->minimum_correlation); + region_tracker = libmv_pyramidRegionTrackerNew(100, level, half_wnd, + track->minimum_correlation); } else if (track->tracker == TRACKER_HYBRID) { - track_context.region_tracker = - libmv_hybridRegionTrackerNew(100, half_wnd, track->minimum_correlation); + region_tracker = libmv_hybridRegionTrackerNew(100, half_wnd, track->minimum_correlation); } else if (track->tracker == TRACKER_SAD) { - track_context.region_tracker = libmv_bruteRegionTrackerNew(MAX2(wndx, wndy), track->minimum_correlation); + region_tracker = libmv_bruteRegionTrackerNew(MAX2(wndx, wndy), track->minimum_correlation); } + + track_context.region_tracker = region_tracker; } #endif @@ -1094,7 +1099,8 @@ void BKE_tracking_context_free(MovieTrackingContext *context) /* zap channels from the imbuf that are disabled by the user. this can lead to * better tracks sometimes. however, instead of simply zeroing the channels * out, do a partial grayscale conversion so the display is better. */ -void BKE_tracking_disable_imbuf_channels(ImBuf *ibuf, int disable_red, int disable_green, int disable_blue, int grayscale) +void BKE_tracking_disable_imbuf_channels(ImBuf *ibuf, int disable_red, int disable_green, int disable_blue, + int grayscale) { int x, y; float scale; @@ -1181,13 +1187,19 @@ static ImBuf *get_area_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTracki h = (max[1] - min[1]) * ibuf->y; /* dimensions should be odd */ - w = w|1; - h = h|1; + w = w | 1; + h = h | 1; + + x1 = x - (int)(w * (-min[0] / (max[0] - min[0]))); + y1 = y - (int)(h * (-min[1] / (max[1] - min[1]))); - x1 = x-(int)(w * (-min[0] / (max[0] - min[0]))); - y1 = y-(int)(h * (-min[1] / (max[1] - min[1]))); + if (ibuf->rect_float) + tmpibuf = IMB_allocImBuf(w + margin * 2, h + margin * 2, 32, IB_rectfloat); + else + tmpibuf = IMB_allocImBuf(w + margin * 2, h + margin * 2, 32, IB_rect); + + tmpibuf->profile = ibuf->profile; - tmpibuf = IMB_allocImBuf(w+margin*2, h+margin*2, 32, IB_rect); IMB_rectcpy(tmpibuf, ibuf, 0, 0, x1 - margin, y1 - margin, w + margin * 2, h + margin * 2); if (pos != NULL) { @@ -1310,17 +1322,17 @@ static ImBuf *get_keyframed_ibuf(MovieTrackingContext *context, MovieTrackingTra MovieTrackingMarker *marker, MovieTrackingMarker **marker_keyed) { int framenr = marker->framenr; - int a = marker-track->markers; + int a = marker - track->markers; *marker_keyed = marker; while (a >= 0 && a < track->markersnr) { - int next = (context->backwards) ? a+1 : a-1; + int next = (context->backwards) ? a + 1 : a - 1; int is_keyframed = FALSE; MovieTrackingMarker *cur_marker = &track->markers[a]; MovieTrackingMarker *next_marker = NULL; - if (next>=0 && next<track->markersnr) + if (next >= 0 && next < track->markersnr) next_marker = &track->markers[next]; /* if next mrker is disabled, stop searching keyframe and use current frame as keyframe */ @@ -1442,8 +1454,8 @@ int BKE_tracking_next(MovieTrackingContext *context) margin[1] = MAX2(margin[1], (float)track->margin / ibuf_new->y); /* do not track markers which are too close to boundary */ - if (marker->pos[0]<margin[0] || marker->pos[0]>1.0f-margin[0] || - marker->pos[1]<margin[1] || marker->pos[1]>1.0f-margin[1]) + if (marker->pos[0] < margin[0] || marker->pos[0] > 1.0f - margin[0] || + marker->pos[1] < margin[1] || marker->pos[1] > 1.0f - margin[1]) { onbound = TRUE; } @@ -1669,7 +1681,8 @@ static int retrieve_libmv_reconstruct_tracks(MovieReconstructContext *context, M reconstruction->camnr = 0; reconstruction->cameras = NULL; - reconstructed = MEM_callocN((efra-sfra+1)*sizeof(MovieReconstructedCamera), "temp reconstructed camera"); + reconstructed = MEM_callocN((efra - sfra + 1) * sizeof(MovieReconstructedCamera), + "temp reconstructed camera"); for (a = sfra; a <= efra; a++) { double matd[4][4]; @@ -1704,8 +1717,9 @@ static int retrieve_libmv_reconstruct_tracks(MovieReconstructContext *context, M } if (reconstruction->camnr) { - reconstruction->cameras = MEM_callocN(reconstruction->camnr * sizeof(MovieReconstructedCamera), "reconstructed camera"); - memcpy(reconstruction->cameras, reconstructed, reconstruction->camnr * sizeof(MovieReconstructedCamera)); + int size = reconstruction->camnr * sizeof(MovieReconstructedCamera); + reconstruction->cameras = MEM_callocN(size, "reconstructed camera"); + memcpy(reconstruction->cameras, reconstructed, size); } if (origin_set) { @@ -1783,7 +1797,8 @@ int BKE_tracking_can_reconstruct(MovieTracking *tracking, MovieTrackingObject *o return TRUE; } else if (count_tracks_on_both_keyframes(tracking, tracksbase) < 8) { - BLI_strncpy(error_msg, "At least 8 common tracks on both of keyframes are needed for reconstruction", error_size); + BLI_strncpy(error_msg, "At least 8 common tracks on both of keyframes are needed for reconstruction", + error_size); return FALSE; } @@ -1818,7 +1833,7 @@ MovieReconstructContext* BKE_tracking_reconstruction_context_new(MovieTracking * track = tracksbase->first; while (track) { - int first = 0, last = track->markersnr-1; + int first = 0, last = track->markersnr - 1; MovieTrackingMarker *first_marker = &track->markers[0]; MovieTrackingMarker *last_marker = &track->markers[track->markersnr - 1]; @@ -1834,7 +1849,7 @@ MovieReconstructContext* BKE_tracking_reconstruction_context_new(MovieTracking * last_marker--; } - if (first<track->markersnr - 1) + if (first < track->markersnr - 1) sfra = MIN2(sfra, first_marker->framenr); if (last >= 0) @@ -2010,21 +2025,21 @@ static int reconstruction_camera_index(MovieTrackingReconstruction *reconstructi if (!reconstruction->camnr) return -1; - if (framenr<cameras[0].framenr) { + if (framenr < cameras[0].framenr) { if (nearest) return 0; else return -1; } - if (framenr>cameras[reconstruction->camnr - 1].framenr) { + if (framenr > cameras[reconstruction->camnr - 1].framenr) { if (nearest) return reconstruction->camnr - 1; else return -1; } - if (reconstruction->last_camera<reconstruction->camnr) + if (reconstruction->last_camera < reconstruction->camnr) a = reconstruction->last_camera; if (cameras[a].framenr >= framenr) @@ -2106,9 +2121,9 @@ void BKE_tracking_get_interpolated_camera(MovieTracking *tracking, MovieTracking } if (cameras[a].framenr != framenr && a > 0 && a < reconstruction->camnr - 1) { - float t = ((float)framenr-cameras[a].framenr) / (cameras[a + 1].framenr-cameras[a].framenr); + float t = ((float)framenr - cameras[a].framenr) / (cameras[a + 1].framenr - cameras[a].framenr); - blend_m4_m4m4(mat, cameras[a].mat, cameras[a+1].mat, t); + blend_m4_m4m4(mat, cameras[a].mat, cameras[a + 1].mat, t); } else { copy_m4_m4(mat, cameras[a].mat); @@ -2123,11 +2138,11 @@ void BKE_get_tracking_mat(Scene *scene, Object *ob, float mat[4][4]) if (scene->camera) ob = scene->camera; else - ob = scene_find_camera(scene); + ob = BKE_scene_camera_find(scene); } if (ob) - where_is_object_mat(scene, ob, mat); + BKE_object_where_is_calc_mat4(scene, ob, mat); else unit_m4(mat); } @@ -2135,8 +2150,8 @@ void BKE_get_tracking_mat(Scene *scene, Object *ob, float mat[4][4]) void BKE_tracking_camera_shift(MovieTracking *tracking, int winx, int winy, float *shiftx, float *shifty) { /* indeed in both of cases it should be winx -- it's just how camera shift works for blender's camera */ - *shiftx = (0.5f * winx-tracking->camera.principal[0]) / winx; - *shifty = (0.5f * winy-tracking->camera.principal[1]) / winx; + *shiftx = (0.5f * winx - tracking->camera.principal[0]) / winx; + *shifty = (0.5f * winy - tracking->camera.principal[1]) / winx; } void BKE_tracking_camera_to_blender(MovieTracking *tracking, Scene *scene, Camera *camera, int width, int height) @@ -2145,9 +2160,9 @@ void BKE_tracking_camera_to_blender(MovieTracking *tracking, Scene *scene, Camer camera->sensor_x = tracking->camera.sensor_width; camera->sensor_fit = CAMERA_SENSOR_FIT_AUTO; - camera->lens = focal*camera->sensor_x/width; + camera->lens = focal * camera->sensor_x / width; - scene->r.xsch = width*tracking->camera.pixel_aspect; + scene->r.xsch = width * tracking->camera.pixel_aspect; scene->r.ysch = height; scene->r.xasp = 1.0f; @@ -2160,7 +2175,7 @@ void BKE_tracking_projection_matrix(MovieTracking *tracking, MovieTrackingObject int framenr, int winx, int winy, float mat[4][4]) { MovieReconstructedCamera *camera; - float lens = tracking->camera.focal*tracking->camera.sensor_width/(float)winx; + float lens = tracking->camera.focal * tracking->camera.sensor_width / (float)winx; float viewfac, pixsize, left, right, bottom, top, clipsta, clipend; float winmat[4][4]; float ycor = 1.0f / tracking->camera.pixel_aspect; @@ -2172,11 +2187,11 @@ void BKE_tracking_projection_matrix(MovieTracking *tracking, MovieTrackingObject clipend = 1000.0f; if (winx >= winy) - viewfac = (lens*winx)/tracking->camera.sensor_width; + viewfac = (lens * winx) / tracking->camera.sensor_width; else - viewfac = (ycor*lens*winy)/tracking->camera.sensor_width; + viewfac = (ycor * lens * winy) / tracking->camera.sensor_width; - pixsize = clipsta/viewfac; + pixsize = clipsta / viewfac; left = -0.5f * (float)winx + shiftx * winside; bottom = -0.5f * (ycor) * (float)winy + shifty * winside; @@ -2278,7 +2293,7 @@ void BKE_tracking_apply_intrinsics(MovieTracking *tracking, float co[2], float n #ifdef WITH_LIBMV double x, y; - float aspy = 1.0f/tracking->camera.pixel_aspect; + float aspy = 1.0f / tracking->camera.pixel_aspect; /* normalize coords */ x = (co[0] - camera->principal[0]) / camera->focal; @@ -2326,7 +2341,7 @@ static int point_in_stroke(bGPDstroke *stroke, float x, float y) prev = stroke->totpoints - 1; - for (i = 0; i<stroke->totpoints; i++) { + for (i = 0; i < stroke->totpoints; i++) { if ((points[i].y < y && points[prev].y >= y) || (points[prev].y < y && points[i].y >= y)) { float fac = (y - points[i].y) / (points[prev].y - points[i].y); @@ -2507,7 +2522,7 @@ static void calculate_stabdata(MovieTracking *tracking, int framenr, float width b[0] *= width; b[1] *= height; - *angle = -atan2(a[0]*b[1]-a[1]*b[0], a[0]*b[0]+a[1]*b[1]); + *angle = -atan2(a[0] * b[1] - a[1] * b[0], a[0] * b[0] + a[1] * b[1]); *angle *= stab->rotinf; /* convert to rotation around image center */ @@ -2563,10 +2578,10 @@ static float stabilization_auto_scale_factor(MovieTracking *tracking, int width, for (i = 0; i < 4; i++) { int j; - float a[3] = {0.0f, 0.0f, 0.0f}, b[3]= {0.0f, 0.0f, 0.0f}; + float a[3] = {0.0f, 0.0f, 0.0f}, b[3] = {0.0f, 0.0f, 0.0f}; copy_v3_v3(a, points[i]); - copy_v3_v3(b, points[(i+1)%4]); + copy_v3_v3(b, points[(i + 1) % 4]); mul_m4_v3(mat, a); mul_m4_v3(mat, b); @@ -2622,7 +2637,7 @@ static float stabilization_auto_scale_factor(MovieTracking *tracking, int width, stab->scale = scale; - if (stab->maxscale>0.0f) + if (stab->maxscale > 0.0f) stab->scale = MIN2(stab->scale, stab->maxscale); } else { @@ -2663,7 +2678,8 @@ static ImBuf* stabilize_alloc_ibuf(ImBuf *cacheibuf, ImBuf *srcibuf, int fill) return cacheibuf; } -void BKE_tracking_stabilization_data(MovieTracking *tracking, int framenr, int width, int height, float loc[2], float *scale, float *angle) +void BKE_tracking_stabilization_data(MovieTracking *tracking, int framenr, int width, int height, + float loc[2], float *scale, float *angle) { float firstmedian[2], median[2]; MovieTrackingStabilization *stab = &tracking->stabilization; @@ -2701,7 +2717,8 @@ void BKE_tracking_stabilization_data(MovieTracking *tracking, int framenr, int w } } -ImBuf *BKE_tracking_stabilize(MovieTracking *tracking, int framenr, ImBuf *ibuf, float loc[2], float *scale, float *angle) +ImBuf *BKE_tracking_stabilize(MovieTracking *tracking, int framenr, ImBuf *ibuf, + float loc[2], float *scale, float *angle) { float tloc[2], tscale, tangle; MovieTrackingStabilization *stab = &tracking->stabilization; @@ -2798,10 +2815,11 @@ ImBuf *BKE_tracking_stabilize(MovieTracking *tracking, int framenr, ImBuf *ibuf, return tmpibuf; } -void BKE_tracking_stabdata_to_mat4(int width, int height, float aspect, float loc[2], float scale, float angle, float mat[4][4]) +void BKE_tracking_stabdata_to_mat4(int width, int height, float aspect, + float loc[2], float scale, float angle, float mat[4][4]) { float lmat[4][4], rmat[4][4], smat[4][4], cmat[4][4], icmat[4][4], amat[4][4], iamat[4][4]; - float svec[3]= {scale, scale, scale}; + float svec[3] = {scale, scale, scale}; unit_m4(rmat); unit_m4(lmat); @@ -3013,7 +3031,7 @@ void BKE_tracking_remove_object(MovieTracking *tracking, MovieTrackingObject *ob MovieTrackingTrack *track; int index = BLI_findindex(&tracking->objects, object); - if (index<0) + if (index < 0) return; if (object->flag & TRACKING_OBJECT_CAMERA) { @@ -3034,7 +3052,7 @@ void BKE_tracking_remove_object(MovieTracking *tracking, MovieTrackingObject *ob tracking->tot_object--; - if (index>0) + if (index > 0) tracking->objectnr = index - 1; else tracking->objectnr = 0; @@ -3042,7 +3060,8 @@ void BKE_tracking_remove_object(MovieTracking *tracking, MovieTrackingObject *ob void BKE_tracking_object_unique_name(MovieTracking *tracking, MovieTrackingObject *object) { - BLI_uniquename(&tracking->objects, object, "Object", '.', offsetof(MovieTrackingObject, name), sizeof(object->name)); + BLI_uniquename(&tracking->objects, object, "Object", '.', + offsetof(MovieTrackingObject, name), sizeof(object->name)); } MovieTrackingObject *BKE_tracking_named_object(MovieTracking *tracking, const char *name) diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index 07a83da3d8c..303098ea0bd 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -51,13 +51,13 @@ #include "BKE_node.h" #include "BKE_world.h" -void free_world(World *wrld) +void BKE_world_free(World *wrld) { MTex *mtex; int a; - for (a=0; a<MAX_MTEX; a++) { - mtex= wrld->mtex[a]; + for (a = 0; a < MAX_MTEX; a++) { + mtex = wrld->mtex[a]; if (mtex && mtex->tex) mtex->tex->id.us--; if (mtex) MEM_freeN(mtex); } @@ -71,40 +71,40 @@ void free_world(World *wrld) MEM_freeN(wrld->nodetree); } - BKE_icon_delete((struct ID*)wrld); + BKE_icon_delete((struct ID *)wrld); wrld->id.icon_id = 0; } World *add_world(const char *name) { - Main *bmain= G.main; + Main *bmain = G.main; World *wrld; - wrld= alloc_libblock(&bmain->world, ID_WO, name); + wrld = BKE_libblock_alloc(&bmain->world, ID_WO, name); - wrld->horr= 0.05f; - wrld->horg= 0.05f; - wrld->horb= 0.05f; - wrld->zenr= 0.01f; - wrld->zeng= 0.01f; - wrld->zenb= 0.01f; - wrld->skytype= 0; - wrld->stardist= 15.0f; - wrld->starsize= 2.0f; - - wrld->exp= 0.0f; - wrld->exposure=wrld->range= 1.0f; - - wrld->aodist= 10.0f; - wrld->aosamp= 5; - wrld->aoenergy= 1.0f; - wrld->ao_env_energy= 1.0f; - wrld->ao_indirect_energy= 1.0f; - wrld->ao_indirect_bounces= 1; - wrld->aobias= 0.05f; + wrld->horr = 0.05f; + wrld->horg = 0.05f; + wrld->horb = 0.05f; + wrld->zenr = 0.01f; + wrld->zeng = 0.01f; + wrld->zenb = 0.01f; + wrld->skytype = 0; + wrld->stardist = 15.0f; + wrld->starsize = 2.0f; + + wrld->exp = 0.0f; + wrld->exposure = wrld->range = 1.0f; + + wrld->aodist = 10.0f; + wrld->aosamp = 5; + wrld->aoenergy = 1.0f; + wrld->ao_env_energy = 1.0f; + wrld->ao_indirect_energy = 1.0f; + wrld->ao_indirect_bounces = 1; + wrld->aobias = 0.05f; wrld->ao_samp_method = WO_AOSAMP_HAMMERSLEY; - wrld->ao_approx_error= 0.25f; + wrld->ao_approx_error = 0.25f; wrld->preview = NULL; wrld->miststa = 5.0f; @@ -113,23 +113,23 @@ World *add_world(const char *name) return wrld; } -World *copy_world(World *wrld) +World *BKE_world_copy(World *wrld) { World *wrldn; int a; - wrldn= copy_libblock(&wrld->id); + wrldn = BKE_libblock_copy(&wrld->id); - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { if (wrld->mtex[a]) { - wrldn->mtex[a]= MEM_mallocN(sizeof(MTex), "copy_world"); + wrldn->mtex[a] = MEM_mallocN(sizeof(MTex), "BKE_world_copy"); memcpy(wrldn->mtex[a], wrld->mtex[a], sizeof(MTex)); id_us_plus((ID *)wrldn->mtex[a]->tex); } } if (wrld->nodetree) - wrldn->nodetree= ntreeCopyTree(wrld->nodetree); + wrldn->nodetree = ntreeCopyTree(wrld->nodetree); if (wrld->preview) wrldn->preview = BKE_previewimg_copy(wrld->preview); @@ -142,12 +142,12 @@ World *localize_world(World *wrld) World *wrldn; int a; - wrldn= copy_libblock(&wrld->id); + wrldn = BKE_libblock_copy(&wrld->id); BLI_remlink(&G.main->world, wrldn); - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { if (wrld->mtex[a]) { - wrldn->mtex[a]= MEM_mallocN(sizeof(MTex), "localize_world"); + wrldn->mtex[a] = MEM_mallocN(sizeof(MTex), "localize_world"); memcpy(wrldn->mtex[a], wrld->mtex[a], sizeof(MTex)); /* free world decrements */ id_us_plus((ID *)wrldn->mtex[a]->tex); @@ -155,51 +155,51 @@ World *localize_world(World *wrld) } if (wrld->nodetree) - wrldn->nodetree= ntreeLocalize(wrld->nodetree); + wrldn->nodetree = ntreeLocalize(wrld->nodetree); - wrldn->preview= NULL; + wrldn->preview = NULL; return wrldn; } -void make_local_world(World *wrld) +void BKE_world_make_local(World *wrld) { - Main *bmain= G.main; + Main *bmain = G.main; Scene *sce; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (wrld->id.lib==NULL) return; - if (wrld->id.us==1) { + if (wrld->id.lib == NULL) return; + if (wrld->id.us == 1) { id_clear_lib_data(bmain, &wrld->id); return; } - for (sce= bmain->scene.first; sce && ELEM(FALSE, is_lib, is_local); sce= sce->id.next) { + for (sce = bmain->scene.first; sce && ELEM(FALSE, is_lib, is_local); sce = sce->id.next) { if (sce->world == wrld) { - if (sce->id.lib) is_lib= TRUE; - else is_local= TRUE; + if (sce->id.lib) is_lib = TRUE; + else is_local = TRUE; } } - if (is_local && is_lib==FALSE) { + if (is_local && is_lib == FALSE) { id_clear_lib_data(bmain, &wrld->id); } else if (is_local && is_lib) { - World *wrld_new= copy_world(wrld); - wrld_new->id.us= 0; + World *wrld_new = BKE_world_copy(wrld); + wrld_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, wrld->id.lib, &wrld_new->id); - for (sce= bmain->scene.first; sce; sce= sce->id.next) { + for (sce = bmain->scene.first; sce; sce = sce->id.next) { if (sce->world == wrld) { - if (sce->id.lib==NULL) { - sce->world= wrld_new; + if (sce->id.lib == NULL) { + sce->world = wrld_new; wrld_new->id.us++; wrld->id.us--; } diff --git a/source/blender/blenkernel/intern/writeavi.c b/source/blender/blenkernel/intern/writeavi.c index ba8a46256c5..841a0f84fed 100644 --- a/source/blender/blenkernel/intern/writeavi.c +++ b/source/blender/blenkernel/intern/writeavi.c @@ -68,7 +68,7 @@ static void filepath_avi(char *string, RenderData *rd); #include "BKE_writeframeserver.h" -bMovieHandle *BKE_get_movie_handle(const char imtype) +bMovieHandle *BKE_movie_handle_get(const char imtype) { static bMovieHandle mh; @@ -97,18 +97,18 @@ bMovieHandle *BKE_get_movie_handle(const char imtype) #endif #ifdef WITH_FFMPEG if (ELEM4(imtype, R_IMF_IMTYPE_FFMPEG, R_IMF_IMTYPE_H264, R_IMF_IMTYPE_XVID, R_IMF_IMTYPE_THEORA)) { - mh.start_movie = start_ffmpeg; - mh.append_movie = append_ffmpeg; - mh.end_movie = end_ffmpeg; - mh.get_movie_path = filepath_ffmpeg; + mh.start_movie = BKE_ffmpeg_start; + mh.append_movie = BKE_ffmpeg_append; + mh.end_movie = BKE_ffmpeg_end; + mh.get_movie_path = BKE_ffmpeg_filepath_get; } #endif #ifdef WITH_FRAMESERVER if (imtype == R_IMF_IMTYPE_FRAMESERVER) { - mh.start_movie = start_frameserver; - mh.append_movie = append_frameserver; - mh.end_movie = end_frameserver; - mh.get_next_frame = frameserver_loop; + mh.start_movie = BKE_frameserver_start; + mh.append_movie = BKE_frameserver_append; + mh.end_movie = BKE_frameserver_end; + mh.get_next_frame = BKE_frameserver_loop; } #endif @@ -228,9 +228,9 @@ static void end_avi(void) } /* similar to BKE_makepicstring() */ -void BKE_makeanimstring(char *string, RenderData *rd) +void BKE_movie_filepath_get(char *string, RenderData *rd) { - bMovieHandle *mh= BKE_get_movie_handle(rd->im_format.imtype); + bMovieHandle *mh= BKE_movie_handle_get(rd->im_format.imtype); if (mh->get_movie_path) mh->get_movie_path(string, rd); else diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c index 7330269c1f4..a29de3b0157 100644 --- a/source/blender/blenkernel/intern/writeffmpeg.c +++ b/source/blender/blenkernel/intern/writeffmpeg.c @@ -317,8 +317,7 @@ static AVFrame* generate_video_frame(uint8_t* pixels, ReportList *reports) if (ENDIAN_ORDER == L_ENDIAN) { int y; for (y = 0; y < height; y++) { - uint8_t* target = rgb_frame->data[0] - + width * 4 * (height - y - 1); + uint8_t* target = rgb_frame->data[0] + width * 4 * (height - y - 1); uint8_t* src = rendered_frame + width * 4 * y; uint8_t* end = src + width * 4; while (src != end) { @@ -335,8 +334,7 @@ static AVFrame* generate_video_frame(uint8_t* pixels, ReportList *reports) else { int y; for (y = 0; y < height; y++) { - uint8_t* target = rgb_frame->data[0] - + width * 4 * (height - y - 1); + uint8_t* target = rgb_frame->data[0] + width * 4 * (height - y - 1); uint8_t* src = rendered_frame + width * 4 * y; uint8_t* end = src + width * 4; while (src != end) { @@ -488,8 +486,7 @@ static AVStream* alloc_video_stream(RenderData *rd, int codec_id, AVFormatContex c->rc_max_rate = rd->ffcodecdata.rc_max_rate*1000; c->rc_min_rate = rd->ffcodecdata.rc_min_rate*1000; c->rc_buffer_size = rd->ffcodecdata.rc_buffer_size * 1024; - c->rc_initial_buffer_occupancy - = rd->ffcodecdata.rc_buffer_size*3/4; + c->rc_initial_buffer_occupancy = rd->ffcodecdata.rc_buffer_size * 3 / 4; c->rc_buffer_aggressivity = 1.0; c->me_method = ME_EPZS; @@ -678,7 +675,7 @@ static int start_ffmpeg_impl(struct RenderData *rd, int rectx, int recty, Report do_init_ffmpeg(); /* Determine the correct filename */ - filepath_ffmpeg(name, rd); + BKE_ffmpeg_filepath_get(name, rd); fprintf(stderr, "Starting output to %s(ffmpeg)...\n" " Using type=%d, codec=%d, audio_codec=%d,\n" " video_bitrate=%d, audio_bitrate=%d,\n" @@ -884,7 +881,7 @@ void flush_ffmpeg(void) * ********************************************************************** */ /* Get the output filename-- similar to the other output formats */ -void filepath_ffmpeg(char* string, RenderData* rd) +void BKE_ffmpeg_filepath_get(char* string, RenderData* rd) { char autosplit[20]; @@ -925,7 +922,7 @@ void filepath_ffmpeg(char* string, RenderData* rd) } } -int start_ffmpeg(struct Scene *scene, RenderData *rd, int rectx, int recty, ReportList *reports) +int BKE_ffmpeg_start(struct Scene *scene, RenderData *rd, int rectx, int recty, ReportList *reports) { int success; @@ -949,7 +946,7 @@ int start_ffmpeg(struct Scene *scene, RenderData *rd, int rectx, int recty, Repo return success; } -void end_ffmpeg(void); +void BKE_ffmpeg_end(void); #ifdef WITH_AUDASPACE static void write_audio_frames(double to_pts) @@ -965,7 +962,7 @@ static void write_audio_frames(double to_pts) } #endif -int append_ffmpeg(RenderData *rd, int start_frame, int frame, int *pixels, int rectx, int recty, ReportList *reports) +int BKE_ffmpeg_append(RenderData *rd, int start_frame, int frame, int *pixels, int rectx, int recty, ReportList *reports) { AVFrame* avframe; int success = 1; @@ -983,7 +980,7 @@ int append_ffmpeg(RenderData *rd, int start_frame, int frame, int *pixels, int r if (ffmpeg_autosplit) { if (avio_tell(outfile->pb) > FFMPEG_AUTOSPLIT_SIZE) { - end_ffmpeg(); + BKE_ffmpeg_end(); ffmpeg_autosplit_count++; success &= start_ffmpeg_impl(rd, rectx, recty, reports); } @@ -996,7 +993,7 @@ int append_ffmpeg(RenderData *rd, int start_frame, int frame, int *pixels, int r return success; } -void end_ffmpeg(void) +void BKE_ffmpeg_end(void) { unsigned int i; @@ -1074,7 +1071,7 @@ void end_ffmpeg(void) /* properties */ -void ffmpeg_property_del(RenderData *rd, void *type, void *prop_) +void BKE_ffmpeg_property_del(RenderData *rd, void *type, void *prop_) { struct IDProperty *prop = (struct IDProperty *) prop_; IDProperty * group; @@ -1091,7 +1088,7 @@ void ffmpeg_property_del(RenderData *rd, void *type, void *prop_) } } -IDProperty *ffmpeg_property_add(RenderData *rd, const char *type, int opt_index, int parent_index) +IDProperty *BKE_ffmpeg_property_add(RenderData *rd, const char *type, int opt_index, int parent_index) { AVCodecContext c; const AVOption * o; @@ -1110,8 +1107,7 @@ IDProperty *ffmpeg_property_add(RenderData *rd, const char *type, int opt_index, parent = c.av_class->option + parent_index; if (!rd->ffcodecdata.properties) { - rd->ffcodecdata.properties - = IDP_New(IDP_GROUP, &val, "ffmpeg"); + rd->ffcodecdata.properties = IDP_New(IDP_GROUP, &val, "ffmpeg"); } group = IDP_GetPropertyFromGroup(rd->ffcodecdata.properties, type); @@ -1184,7 +1180,7 @@ static const AVOption *my_av_find_opt(void *v, const char *name, return NULL; } -int ffmpeg_property_add_string(RenderData *rd, const char * type, const char * str) +int BKE_ffmpeg_property_add_string(RenderData *rd, const char * type, const char * str) { AVCodecContext c; const AVOption * o = 0; @@ -1220,12 +1216,12 @@ int ffmpeg_property_add_string(RenderData *rd, const char * type, const char * s } if (param && o->type != FF_OPT_TYPE_CONST && o->unit) { p = my_av_find_opt(&c, param, o->unit, 0, 0); - prop = ffmpeg_property_add(rd, + prop = BKE_ffmpeg_property_add(rd, (char*) type, p - c.av_class->option, o - c.av_class->option); } else { - prop = ffmpeg_property_add(rd, + prop = BKE_ffmpeg_property_add(rd, (char*) type, o - c.av_class->option, 0); } @@ -1268,37 +1264,37 @@ static void ffmpeg_set_expert_options(RenderData *rd) * Use CABAC coder. Using "coder:1", which should be equivalent, * crashes Blender for some reason. Either way - this is no big deal. */ - ffmpeg_property_add_string(rd, "video", "coder:vlc"); + BKE_ffmpeg_property_add_string(rd, "video", "coder:vlc"); /* * The other options were taken from the libx264-default.preset * included in the ffmpeg distribution. */ // ffmpeg_property_add_string(rd, "video", "flags:loop"); // this breaks compatibility for QT - ffmpeg_property_add_string(rd, "video", "cmp:chroma"); - ffmpeg_property_add_string(rd, "video", "partitions:parti4x4"); - ffmpeg_property_add_string(rd, "video", "partitions:partp8x8"); - ffmpeg_property_add_string(rd, "video", "partitions:partb8x8"); - ffmpeg_property_add_string(rd, "video", "me:hex"); - ffmpeg_property_add_string(rd, "video", "subq:6"); - ffmpeg_property_add_string(rd, "video", "me_range:16"); - ffmpeg_property_add_string(rd, "video", "qdiff:4"); - ffmpeg_property_add_string(rd, "video", "keyint_min:25"); - ffmpeg_property_add_string(rd, "video", "sc_threshold:40"); - ffmpeg_property_add_string(rd, "video", "i_qfactor:0.71"); - ffmpeg_property_add_string(rd, "video", "b_strategy:1"); - ffmpeg_property_add_string(rd, "video", "bf:3"); - ffmpeg_property_add_string(rd, "video", "refs:2"); - ffmpeg_property_add_string(rd, "video", "qcomp:0.6"); - ffmpeg_property_add_string(rd, "video", "directpred:3"); - ffmpeg_property_add_string(rd, "video", "trellis:0"); - ffmpeg_property_add_string(rd, "video", "flags2:wpred"); - ffmpeg_property_add_string(rd, "video", "flags2:dct8x8"); - ffmpeg_property_add_string(rd, "video", "flags2:fastpskip"); - ffmpeg_property_add_string(rd, "video", "wpredp:2"); + BKE_ffmpeg_property_add_string(rd, "video", "cmp:chroma"); + BKE_ffmpeg_property_add_string(rd, "video", "partitions:parti4x4"); + BKE_ffmpeg_property_add_string(rd, "video", "partitions:partp8x8"); + BKE_ffmpeg_property_add_string(rd, "video", "partitions:partb8x8"); + BKE_ffmpeg_property_add_string(rd, "video", "me:hex"); + BKE_ffmpeg_property_add_string(rd, "video", "subq:6"); + BKE_ffmpeg_property_add_string(rd, "video", "me_range:16"); + BKE_ffmpeg_property_add_string(rd, "video", "qdiff:4"); + BKE_ffmpeg_property_add_string(rd, "video", "keyint_min:25"); + BKE_ffmpeg_property_add_string(rd, "video", "sc_threshold:40"); + BKE_ffmpeg_property_add_string(rd, "video", "i_qfactor:0.71"); + BKE_ffmpeg_property_add_string(rd, "video", "b_strategy:1"); + BKE_ffmpeg_property_add_string(rd, "video", "bf:3"); + BKE_ffmpeg_property_add_string(rd, "video", "refs:2"); + BKE_ffmpeg_property_add_string(rd, "video", "qcomp:0.6"); + BKE_ffmpeg_property_add_string(rd, "video", "directpred:3"); + BKE_ffmpeg_property_add_string(rd, "video", "trellis:0"); + BKE_ffmpeg_property_add_string(rd, "video", "flags2:wpred"); + BKE_ffmpeg_property_add_string(rd, "video", "flags2:dct8x8"); + BKE_ffmpeg_property_add_string(rd, "video", "flags2:fastpskip"); + BKE_ffmpeg_property_add_string(rd, "video", "wpredp:2"); if (rd->ffcodecdata.flags & FFMPEG_LOSSLESS_OUTPUT) - ffmpeg_property_add_string(rd, "video", "cqp:0"); + BKE_ffmpeg_property_add_string(rd, "video", "cqp:0"); } #if 0 /* disabled for after release */ else if (codec_id == CODEC_ID_DNXHD) { @@ -1308,7 +1304,7 @@ static void ffmpeg_set_expert_options(RenderData *rd) #endif } -void ffmpeg_set_preset(RenderData *rd, int preset) +void BKE_ffmpeg_preset_set(RenderData *rd, int preset) { int isntsc = (rd->frs_sec != 25); @@ -1402,7 +1398,7 @@ void ffmpeg_set_preset(RenderData *rd, int preset) ffmpeg_set_expert_options(rd); } -void ffmpeg_verify_image_type(RenderData *rd, ImageFormatData *imf) +void BKE_ffmpeg_image_type_verify(RenderData *rd, ImageFormatData *imf) { int audio= 0; @@ -1414,7 +1410,7 @@ void ffmpeg_verify_image_type(RenderData *rd, ImageFormatData *imf) rd->ffcodecdata.codec = CODEC_ID_MPEG2VIDEO; - ffmpeg_set_preset(rd, FFMPEG_PRESET_DVD); + BKE_ffmpeg_preset_set(rd, FFMPEG_PRESET_DVD); } if (rd->ffcodecdata.type == FFMPEG_OGG) { rd->ffcodecdata.type = FFMPEG_MPEG2; @@ -1424,19 +1420,19 @@ void ffmpeg_verify_image_type(RenderData *rd, ImageFormatData *imf) } else if (imf->imtype == R_IMF_IMTYPE_H264) { if (rd->ffcodecdata.codec != CODEC_ID_H264) { - ffmpeg_set_preset(rd, FFMPEG_PRESET_H264); + BKE_ffmpeg_preset_set(rd, FFMPEG_PRESET_H264); audio= 1; } } else if (imf->imtype == R_IMF_IMTYPE_XVID) { if (rd->ffcodecdata.codec != CODEC_ID_MPEG4) { - ffmpeg_set_preset(rd, FFMPEG_PRESET_XVID); + BKE_ffmpeg_preset_set(rd, FFMPEG_PRESET_XVID); audio= 1; } } else if (imf->imtype == R_IMF_IMTYPE_THEORA) { if (rd->ffcodecdata.codec != CODEC_ID_THEORA) { - ffmpeg_set_preset(rd, FFMPEG_PRESET_THEORA); + BKE_ffmpeg_preset_set(rd, FFMPEG_PRESET_THEORA); audio= 1; } } @@ -1447,12 +1443,12 @@ void ffmpeg_verify_image_type(RenderData *rd, ImageFormatData *imf) } } -void ffmpeg_verify_codec_settings(RenderData *rd) +void BKE_ffmpeg_codec_settings_verify(RenderData *rd) { ffmpeg_set_expert_options(rd); } -int ffmpeg_alpha_channel_supported(RenderData *rd) +int BKE_ffmpeg_alpha_channel_is_supported(RenderData *rd) { int codec = rd->ffcodecdata.codec; diff --git a/source/blender/blenkernel/intern/writeframeserver.c b/source/blender/blenkernel/intern/writeframeserver.c index 0ff095607e3..b5965838a30 100644 --- a/source/blender/blenkernel/intern/writeframeserver.c +++ b/source/blender/blenkernel/intern/writeframeserver.c @@ -110,7 +110,7 @@ static int closesocket(int fd) } #endif -int start_frameserver(struct Scene *scene, RenderData *UNUSED(rd), int rectx, int recty, ReportList *reports) +int BKE_frameserver_start(struct Scene *scene, RenderData *UNUSED(rd), int rectx, int recty, ReportList *reports) { struct sockaddr_in addr; int arg = 1; @@ -258,7 +258,7 @@ static int handle_request(RenderData *rd, char * req) return -1; } -int frameserver_loop(RenderData *rd, ReportList *UNUSED(reports)) +int BKE_frameserver_loop(RenderData *rd, ReportList *UNUSED(reports)) { fd_set readfds; struct timeval tv; @@ -371,7 +371,7 @@ static void serve_ppm(int *pixels, int rectx, int recty) connsock = -1; } -int append_frameserver(RenderData *UNUSED(rd), int UNUSED(start_frame), int frame, int *pixels, +int BKE_frameserver_append(RenderData *UNUSED(rd), int UNUSED(start_frame), int frame, int *pixels, int rectx, int recty, ReportList *UNUSED(reports)) { fprintf(stderr, "Serving frame: %d\n", frame); @@ -386,7 +386,7 @@ int append_frameserver(RenderData *UNUSED(rd), int UNUSED(start_frame), int fram return 0; } -void end_frameserver(void) +void BKE_frameserver_end(void) { if (connsock != -1) { closesocket(connsock); |