diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-09-15 04:15:24 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-09-15 04:15:24 +0400 |
commit | 41729976753523ee08a0afaf6a26b6caf3dee1d6 (patch) | |
tree | ba264fba22084f44eb50b952f375715f501acff9 /source | |
parent | a5f8298ea5d13d7707bc0cbf0722013276bab9d6 (diff) | |
parent | a425790065fedb2ae49f1b79770945d8528790d9 (diff) |
Merged changes in the trunk up to revision 50607.
Conflicts resolved:
source/blender/blenloader/intern/readfile.c
Diffstat (limited to 'source')
400 files changed, 5950 insertions, 3985 deletions
diff --git a/source/blender/avi/intern/avi.c b/source/blender/avi/intern/avi.c index 39424057faf..cda2cf303eb 100644 --- a/source/blender/avi/intern/avi.c +++ b/source/blender/avi/intern/avi.c @@ -734,9 +734,10 @@ AviError AVI_close(AviMovie *movie) fclose(movie->fp); - for (i = 0; i < movie->header->Streams; i++) { - if (movie->streams[i].sf != NULL) + for (i = 0; movie->header && (i < movie->header->Streams); i++) { + if (movie->streams && (movie->streams[i].sf != NULL)) { MEM_freeN(movie->streams[i].sf); + } } if (movie->header != NULL) @@ -1081,9 +1082,10 @@ AviError AVI_close_compress(AviMovie *movie) fclose(movie->fp); - for (i = 0; i < movie->header->Streams; i++) { - if (movie->streams[i].sf != NULL) + for (i = 0; movie->header && (i < movie->header->Streams); i++) { + if (movie->streams && (movie->streams[i].sf != NULL)) { MEM_freeN(movie->streams[i].sf); + } } if (movie->header != NULL) MEM_freeN(movie->header); diff --git a/source/blender/blenfont/intern/blf_dir.c b/source/blender/blenfont/intern/blf_dir.c index da916067302..b6a98faa48c 100644 --- a/source/blender/blenfont/intern/blf_dir.c +++ b/source/blender/blenfont/intern/blf_dir.c @@ -41,8 +41,6 @@ #include "DNA_vec_types.h" -#include "BKE_utildefines.h" - #include "BLI_fileops.h" #include "BLI_listbase.h" #include "BLI_path_util.h" diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c index b37180d499c..2b7e225d709 100644 --- a/source/blender/blenfont/intern/blf_lang.c +++ b/source/blender/blenfont/intern/blf_lang.c @@ -82,7 +82,7 @@ static const char *locales[] = { "spanish", "es", "catalan", "ca_AD", "czech", "cs_CZ", - "portuguese", "pt", + "portuguese", "pt_PT", #if defined(_WIN32) && !defined(FREE_WINDOWS) "Chinese (Simplified)_China.1252", "zh_CN", "Chinese (Traditional)_China.1252", "zh_TW", @@ -107,6 +107,8 @@ static const char *locales[] = { "kyrgyz", "ky_KG", "turkish", "tr_TR", "hungarian", "hu_HU", + "brazilian portuguese", "pt_BR", + "hebrew", "he_IL", }; void BLF_lang_init(void) diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index 64512dcaac8..fa9223ba6e2 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -698,6 +698,7 @@ void DM_init_origspace(DerivedMesh *dm); #ifndef NDEBUG char *DM_debug_info(DerivedMesh *dm); void DM_debug_print(DerivedMesh *dm); +void DM_debug_print_cdlayers(CustomData *cdata); #endif #endif diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h index acb9234b2d4..f506c67a36c 100644 --- a/source/blender/blenkernel/BKE_anim.h +++ b/source/blender/blenkernel/BKE_anim.h @@ -60,12 +60,12 @@ void animviz_calc_motionpaths(struct Scene *scene, ListBase *targets); void free_path(struct Path *path); void calc_curvepath(struct Object *ob); -int interval_test(int min, int max, int p1, int cycl); int where_on_path(struct Object *ob, float ctime, float vec[4], float dir[3], float quat[4], float *radius, float *weight); /* ---------------------------------------------------- */ /* Dupli-Geometry */ +struct ListBase *object_duplilist_ex(struct Scene *sce, struct Object *ob, int update); struct ListBase *object_duplilist(struct Scene *sce, struct Object *ob); void free_object_duplilist(struct ListBase *lb); int count_duplilist(struct Object *ob); diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h index 44e47e779e7..d750e88ac04 100644 --- a/source/blender/blenkernel/BKE_armature.h +++ b/source/blender/blenkernel/BKE_armature.h @@ -101,8 +101,6 @@ void get_objectspace_bone_matrix(struct Bone *bone, float M_accumulatedMatrix[][ void vec_roll_to_mat3(const float vec[3], const float roll, float mat[][3]); 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 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]); diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index dec4d3cb8cb..1e67027ae8c 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 17 +#define BLENDER_SUBVERSION 18 /* 262 was the last editmesh release but its has compatibility code for bmesh data, * so set the minversion to 2.61 */ @@ -83,6 +83,8 @@ void BKE_userdef_free(void); void set_blender_test_break_cb(void (*func)(void) ); int blender_test_break(void); +#define BKE_UNDO_STR_MAX 64 + /* global undo */ extern void BKE_write_undo(struct bContext *C, const char *name); extern void BKE_undo_step(struct bContext *C, int step); diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index 8d486218d21..19dd67b88f8 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -124,8 +124,6 @@ void CustomData_free_temporary(struct CustomData *data, int totelem); /* adds a data layer of the given type to the CustomData object, optionally * backed by an external data array. the different allocation types are * defined above. returns the data of the layer. - * - * in editmode, use EDBM_data_layer_add instead of this function */ void *CustomData_add_layer(struct CustomData *data, int type, int alloctype, void *layer, int totelem); diff --git a/source/blender/blenkernel/BKE_deform.h b/source/blender/blenkernel/BKE_deform.h index 25677165fc2..52a143ddf55 100644 --- a/source/blender/blenkernel/BKE_deform.h +++ b/source/blender/blenkernel/BKE_deform.h @@ -67,7 +67,8 @@ void defvert_remap(struct MDeformVert *dvert, int *map, const int map_len); void defvert_flip(struct MDeformVert *dvert, const int *flip_map, const int flip_map_len); void defvert_flip_merged(struct MDeformVert *dvert, const int *flip_map, const int flip_map_len); void defvert_normalize(struct MDeformVert *dvert); -void defvert_normalize_lock(struct MDeformVert *dvert, const int def_nr_lock); +void defvert_normalize_lock_single(struct MDeformVert *dvert, const int def_nr_lock); +void defvert_normalize_lock_map(struct MDeformVert *dvert, const char *lock_flags, const int defbase_tot); /* utility function, note that MAX_VGROUP_NAME chars is the maximum string length since its only * used with defgroups currently */ diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index 909ed471081..67461281674 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -106,6 +106,12 @@ struct RenderResult; #define IMA_TYPE_R_RESULT 4 #define IMA_TYPE_COMPOSITE 5 +enum { + IMA_GENTYPE_BLANK = 0, + IMA_GENTYPE_GRID = 1, + IMA_GENTYPE_GRID_COLOR = 2 +}; + /* ima->ok */ #define IMA_OK 1 #define IMA_OK_LOADED 2 @@ -196,6 +202,10 @@ int BKE_image_scale(struct Image *image, int width, int height); /* check if texture has alpha (depth=32) */ int BKE_image_has_alpha(struct Image *image); +void BKE_image_get_size(struct Image *image, struct ImageUser *iuser, int *width, int *height); +void BKE_image_get_size_fl(struct Image *image, struct ImageUser *iuser, float size[2]); +void BKE_image_get_aspect(struct Image *image, float *aspx, float *aspy); + /* image_gen.c */ void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, const float color[4]); void BKE_image_buf_fill_checker(unsigned char *rect, float *rect_float, int height, int width); diff --git a/source/blender/blenkernel/BKE_mask.h b/source/blender/blenkernel/BKE_mask.h index 9cf5a7f31a5..51e301fec80 100644 --- a/source/blender/blenkernel/BKE_mask.h +++ b/source/blender/blenkernel/BKE_mask.h @@ -28,6 +28,8 @@ #ifndef __BKE_MASK_H__ #define __BKE_MASK_H__ +struct ImageUser; +struct Image; struct ListBase; struct Main; struct Mask; @@ -100,13 +102,15 @@ struct Mask *BKE_mask_new(const char *name); struct Mask *BKE_mask_copy_nolib(struct Mask *mask); struct Mask *BKE_mask_copy(struct Mask *mask); -void BKE_mask_free(struct Mask *mask); -void BKE_mask_unlink(struct Main *bmain, struct Mask *mask); +void BKE_mask_free_nolib(struct Mask *mask); +void BKE_mask_free(struct Main *bmain, struct Mask *mask); -void BKE_mask_coord_from_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2]); void BKE_mask_coord_from_frame(float r_co[2], const float co[2], const float frame_size[2]); -void BKE_mask_coord_to_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2]); +void BKE_mask_coord_from_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2]); +void BKE_mask_coord_from_image(struct Image *image, struct ImageUser *iuser, float r_co[2], const float co[2]); void BKE_mask_coord_to_frame(float r_co[2], const float co[2], const float frame_size[2]); +void BKE_mask_coord_to_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2]); +void BKE_mask_coord_to_image(struct Image *image, struct ImageUser *iuser, float r_co[2], const float co[2]); /* parenting */ @@ -127,7 +131,6 @@ void BKE_mask_get_handle_point_adjacent(struct MaskSpline *spline, struct MaskSp void BKE_mask_layer_calc_handles(struct MaskLayer *masklay); void BKE_mask_layer_calc_handles_deform(struct MaskLayer *masklay); void BKE_mask_calc_handles(struct Mask *mask); -void BKE_mask_calc_handles_deform(struct Mask *mask); void BKE_mask_spline_ensure_deform(struct MaskSpline *spline); /* animation */ @@ -153,8 +156,6 @@ int BKE_mask_layer_shape_spline_from_index(struct MaskLayer *masklay, int index, struct MaskSpline **r_masklay_shape, int *r_index); int BKE_mask_layer_shape_spline_to_index(struct MaskLayer *masklay, struct MaskSpline *spline); -int BKE_mask_layer_shape_spline_index(struct MaskLayer *masklay, int index, - struct MaskSpline **r_masklay_shape, int *r_index); void BKE_mask_layer_shape_changed_add(struct MaskLayer *masklay, int index, int do_init, int do_init_interpolate); diff --git a/source/blender/blenkernel/BKE_movieclip.h b/source/blender/blenkernel/BKE_movieclip.h index 739b63ca174..25d2678ea47 100644 --- a/source/blender/blenkernel/BKE_movieclip.h +++ b/source/blender/blenkernel/BKE_movieclip.h @@ -51,9 +51,10 @@ struct ImBuf *BKE_movieclip_get_postprocessed_ibuf(struct MovieClip *clip, struc struct ImBuf *BKE_movieclip_get_stable_ibuf(struct MovieClip *clip, struct MovieClipUser *user, float loc[2], float *scale, float *angle, int postprocess_flag); struct ImBuf *BKE_movieclip_get_ibuf_flag(struct MovieClip *clip, struct MovieClipUser *user, int flag, int cache_flag); void BKE_movieclip_get_size(struct MovieClip *clip, struct MovieClipUser *user, int *width, int *height); -int BKE_movieclip_get_duration(struct MovieClip *clip); -void BKE_movieclip_aspect(struct MovieClip *clip, float *aspx, float *aspy); -int BKE_movieclip_has_frame(struct MovieClip *clip, struct MovieClipUser *user); +void BKE_movieclip_get_size_fl(struct MovieClip *clip, struct MovieClipUser *user, float size[2]); +int BKE_movieclip_get_duration(struct MovieClip *clip); +void BKE_movieclip_get_aspect(struct MovieClip *clip, float *aspx, float *aspy); +int BKE_movieclip_has_frame(struct MovieClip *clip, struct MovieClipUser *user); void BKE_movieclip_user_set_frame(struct MovieClipUser *user, int framenr); void BKE_movieclip_update_scopes(struct MovieClip *clip, struct MovieClipUser *user, struct MovieClipScopes *scopes); diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index c8b69898daa..438d5110666 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -546,6 +546,7 @@ struct ShadeResult; #define SH_NODE_LIGHT_FALLOFF 166 #define SH_NODE_OBJECT_INFO 167 #define SH_NODE_PARTICLE_INFO 168 +#define SH_NODE_TEX_BRICK 169 /* custom defines options for Material node */ #define SH_NODE_MAT_DIFF 1 diff --git a/source/blender/blenkernel/BKE_object_deform.h b/source/blender/blenkernel/BKE_object_deform.h new file mode 100644 index 00000000000..ecc521a77fb --- /dev/null +++ b/source/blender/blenkernel/BKE_object_deform.h @@ -0,0 +1,38 @@ +/* + * ***** 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. + * + * Contributor(s): Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BKE_OBJECT_DEFORM_H__ +#define __BKE_OBJECT_DEFORM_H__ + +/** \file BKE_object_deform.h + * \ingroup bke + * \brief Functions for dealing with objects and deform verts, + * used by painting and tools. + */ + +struct Object; + +char *BKE_objdef_lock_flags_get(struct Object *ob, const int defbase_tot); +char *BKE_objdef_validmap_get(struct Object *ob, const int defbase_tot); +char *BKE_objdef_selected_get(struct Object *ob, int defbase_tot, int *r_dg_flags_sel_tot); + +#endif /* __BKE_OBJECT_DEFORM_H__ */ diff --git a/source/blender/blenkernel/BKE_script.h b/source/blender/blenkernel/BKE_script.h index 9976009c4c2..c3789733a04 100644 --- a/source/blender/blenkernel/BKE_script.h +++ b/source/blender/blenkernel/BKE_script.h @@ -40,8 +40,6 @@ extern "C" { struct Script; -void free_script(struct Script *script); - #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/BKE_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h index 2a90bb2c679..51a64c97ca6 100644 --- a/source/blender/blenkernel/BKE_sequencer.h +++ b/source/blender/blenkernel/BKE_sequencer.h @@ -291,12 +291,13 @@ void BKE_sequencer_dupe_animdata(struct Scene *scene, const char *name_src, cons int BKE_sequence_base_shuffle(struct ListBase *seqbasep, struct Sequence *test, struct Scene *evil_scene); int BKE_sequence_base_shuffle_time(ListBase *seqbasep, struct Scene *evil_scene); int BKE_sequence_base_isolated_sel_check(struct ListBase *seqbase); -void BKE_sequencer_free_imbuf(struct Scene *scene, struct ListBase *seqbasep, int check_mem_usage, int keep_file_handles); +void BKE_sequencer_free_imbuf(struct Scene *scene, struct ListBase *seqbasep, int for_render); struct Sequence *BKE_sequence_dupli_recursive(struct Scene *scene, struct Scene *scene_to, struct Sequence *seq, int dupe_flag); int BKE_sequence_swap(struct Sequence *seq_a, struct Sequence *seq_b, const char **error_str); int BKE_sequence_check_depend(struct Sequence *seq, struct Sequence *cur); void BKE_sequence_invalidate_cache(struct Scene *scene, struct Sequence *seq); +void BKE_sequence_invalidate_deendent(struct Scene *scene, struct Sequence *seq); void BKE_sequence_invalidate_cache_for_modifier(struct Scene *scene, struct Sequence *seq); void BKE_sequencer_update_sound_bounds_all(struct Scene *scene); @@ -380,7 +381,7 @@ typedef struct SequenceModifierTypeInfo { void (*copy_data) (struct SequenceModifierData *smd, struct SequenceModifierData *target); /* apply modifier on a given image buffer */ - struct ImBuf *(*apply) (struct SequenceModifierData *smd, struct ImBuf *ibuf, struct ImBuf *mask); + void (*apply) (struct SequenceModifierData *smd, struct ImBuf *ibuf, struct ImBuf *mask); } SequenceModifierTypeInfo; struct SequenceModifierTypeInfo *BKE_sequence_modifier_type_info_get(int type); diff --git a/source/blender/blenkernel/BKE_shrinkwrap.h b/source/blender/blenkernel/BKE_shrinkwrap.h index a7b03cef933..d1332ba937e 100644 --- a/source/blender/blenkernel/BKE_shrinkwrap.h +++ b/source/blender/blenkernel/BKE_shrinkwrap.h @@ -52,7 +52,7 @@ struct DerivedMesh *object_get_derived_final(struct Object *ob); * the matrix calculation. * * A SpaceTransform is initialized using: - * space_transform_setup( &data, ob1, ob2 ) + * SPACE_TRANSFORM_SETUP( &data, ob1, ob2 ) * * After that the following calls can be used: * space_transform_apply (&data, co); //converts a coordinate in ob1 coords space to the corresponding ob2 coords @@ -75,7 +75,7 @@ void space_transform_from_matrixs(struct SpaceTransform *data, float local[4][4] void space_transform_apply(const struct SpaceTransform *data, float co[3]); void space_transform_invert(const struct SpaceTransform *data, float co[3]); -#define space_transform_setup(data, local, target) space_transform_from_matrixs(data, (local)->obmat, (target)->obmat) +#define SPACE_TRANSFORM_SETUP(data, local, target) space_transform_from_matrixs(data, (local)->obmat, (target)->obmat) /* Shrinkwrap stuff */ #include "BKE_bvhutils.h" @@ -126,7 +126,7 @@ void shrinkwrapModifier_deform(struct ShrinkwrapModifierData *smd, struct Object /* * This function casts a ray in the given BVHTree.. but it takes into consideration the space_transform, that is: * - * if transf was configured with "space_transform_setup( &transf, ob1, ob2 )" + * if transf was configured with "SPACE_TRANSFORM_SETUP( &transf, ob1, ob2 )" * then the input (vert, dir, BVHTreeRayHit) must be defined in ob1 coordinates space * and the BVHTree must be built in ob2 coordinate space. * diff --git a/source/blender/blenkernel/BKE_tessmesh.h b/source/blender/blenkernel/BKE_tessmesh.h index 3a806651d61..dea5e726671 100644 --- a/source/blender/blenkernel/BKE_tessmesh.h +++ b/source/blender/blenkernel/BKE_tessmesh.h @@ -72,10 +72,12 @@ typedef struct BMEditMesh { short selectmode; short mat_nr; - /*Mesh structure this editmesh came from, if it came from one*/ - struct Mesh *me; + /* Object this editmesh came from (if it came from one) */ struct Object *ob; + /* Unused for now, we could bring it back and assign in the same way 'ob' is */ + // struct Mesh *me; + /*temp variables for x-mirror editing*/ int mirror_cdlayer; /* -1 is invalid */ int mirr_free_arrays; diff --git a/source/blender/blenkernel/BKE_utildefines.h b/source/blender/blenkernel/BKE_utildefines.h index 0ed2db2aad2..63f5ec59a0b 100644 --- a/source/blender/blenkernel/BKE_utildefines.h +++ b/source/blender/blenkernel/BKE_utildefines.h @@ -15,13 +15,6 @@ * 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) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * * ***** END GPL LICENSE BLOCK ***** */ @@ -39,48 +32,7 @@ extern "C" { #endif -/* these values need to be hardcoded in structs, dna does not recognize defines */ -/* also defined in DNA_space_types.h */ -#ifndef FILE_MAXDIR -#define FILE_MAXDIR 768 -#define FILE_MAXFILE 256 -#define FILE_MAX 1024 -#endif - -/* this weirdo pops up in two places ... */ -#if !defined(WIN32) -# ifndef O_BINARY -# define O_BINARY 0 -# endif -#endif - -/* INTEGER CODES */ -#ifdef __BIG_ENDIAN__ -/* Big Endian */ -# define MAKE_ID(a, b, c, d) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d) ) -#else -/* Little Endian */ -# define MAKE_ID(a, b, c, d) ( (int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a) ) -#endif - -#define DATA MAKE_ID('D', 'A', 'T', 'A') -#define GLOB MAKE_ID('G', 'L', 'O', 'B') - -#define DNA1 MAKE_ID('D', 'N', 'A', '1') -#define TEST MAKE_ID('T', 'E', 'S', 'T') /* used as preview between 'REND' and 'GLOB' */ -#define REND MAKE_ID('R', 'E', 'N', 'D') -#define USER MAKE_ID('U', 'S', 'E', 'R') - -#define ENDB MAKE_ID('E', 'N', 'D', 'B') - -/* Bit operations */ -#define BTST(a, b) ( ( (a) & 1 << (b) ) != 0) -#define BNTST(a, b) ( ( (a) & 1 << (b) ) == 0) -#define BTST2(a, b, c) (BTST( (a), (b) ) || BTST( (a), (c) ) ) -#define BSET(a, b) ( (a) | 1 << (b) ) -#define BCLR(a, b) ( (a) & ~(1 << (b)) ) -/* bit-row */ -#define BROW(min, max) (((max) >= 31 ? 0xFFFFFFFF : (1 << (max + 1)) - 1) - ((min) ? ((1 << (min)) - 1) : 0) ) +/* currently unused but we may want to add macros here for BKE later */ #ifdef __cplusplus } diff --git a/source/blender/blenkernel/BKE_world.h b/source/blender/blenkernel/BKE_world.h index 67896fffc4d..7a23bff0184 100644 --- a/source/blender/blenkernel/BKE_world.h +++ b/source/blender/blenkernel/BKE_world.h @@ -35,7 +35,8 @@ struct World; -void BKE_world_free(struct World *sc); +void BKE_world_free(struct World *sc); +void BKE_world_free_ex(struct World *sc, int do_id_user); struct World *add_world(const char *name); struct World *BKE_world_copy(struct World *wrld); struct World *localize_world(struct World *wrld); diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index d6422e89997..c89d0ecb142 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -116,6 +116,7 @@ set(SRC intern/nla.c intern/node.c intern/object.c + intern/object_deform.c intern/ocean.c intern/packedFile.c intern/paint.c @@ -205,6 +206,7 @@ set(SRC BKE_nla.h BKE_node.h BKE_object.h + BKE_object_deform.h BKE_ocean.h BKE_packedFile.h BKE_paint.h diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index a29484638c0..8c0aea5723f 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -59,6 +59,7 @@ #include "BKE_modifier.h" #include "BKE_mesh.h" #include "BKE_object.h" +#include "BKE_object_deform.h" #include "BKE_paint.h" #include "BKE_texture.h" #include "BKE_multires.h" @@ -1015,14 +1016,14 @@ static void calc_weightpaint_vert_color( unsigned char r_col[4], MDeformVert *dv, ColorBand *coba, const int defbase_tot, const int defbase_act, - const char *dg_flags, - const int selected, const int draw_flag) + const char *defbase_sel, const int defbase_sel_tot, + const int draw_flag) { float input = 0.0f; int make_black = FALSE; - if ((selected > 1) && (draw_flag & CALC_WP_MULTIPAINT)) { + if ((defbase_sel_tot > 1) && (draw_flag & CALC_WP_MULTIPAINT)) { int was_a_nonzero = FALSE; unsigned int i; @@ -1031,7 +1032,7 @@ static void calc_weightpaint_vert_color( /* in multipaint, get the average if auto normalize is inactive * get the sum if it is active */ if (dw->def_nr < defbase_tot) { - if (dg_flags[dw->def_nr]) { + if (defbase_sel[dw->def_nr]) { if (dw->weight) { input += dw->weight; was_a_nonzero = TRUE; @@ -1045,7 +1046,7 @@ static void calc_weightpaint_vert_color( make_black = TRUE; } else if ((draw_flag & CALC_WP_AUTO_NORMALIZE) == FALSE) { - input /= selected; /* get the average */ + input /= defbase_sel_tot; /* get the average */ } } else { @@ -1090,14 +1091,21 @@ static unsigned char *calc_weightpaint_vert_array(Object *ob, DerivedMesh *dm, i /* variables for multipaint */ const int defbase_tot = BLI_countlist(&ob->defbase); const int defbase_act = ob->actdef - 1; - char *dg_flags = MEM_mallocN(defbase_tot * sizeof(char), __func__); - const int selected = get_selected_defgroups(ob, dg_flags, defbase_tot); + + int defbase_sel_tot = 0; + char *defbase_sel = NULL; + + if (draw_flag & CALC_WP_MULTIPAINT) { + defbase_sel = BKE_objdef_selected_get(ob, defbase_tot, &defbase_sel_tot); + } for (i = numVerts; i != 0; i--, wc += 4, dv++) { - calc_weightpaint_vert_color(wc, dv, coba, defbase_tot, defbase_act, dg_flags, selected, draw_flag); + calc_weightpaint_vert_color(wc, dv, coba, defbase_tot, defbase_act, defbase_sel, defbase_sel_tot, draw_flag); } - MEM_freeN(dg_flags); + if (defbase_sel) { + MEM_freeN(defbase_sel); + } } else { int col_i; @@ -2073,7 +2081,7 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D if ((*final_r)->type != DM_TYPE_EDITBMESH) { DM_ensure_tessface(*final_r); } - if (cage_r) { + if (cage_r && *cage_r) { if ((*cage_r)->type != DM_TYPE_EDITBMESH) { if (*cage_r != *final_r) { DM_ensure_tessface(*cage_r); @@ -3187,4 +3195,25 @@ void DM_debug_print(DerivedMesh *dm) MEM_freeN(str); } +void DM_debug_print_cdlayers(CustomData *data) +{ + int i; + CustomDataLayer *layer; + + printf("{\n"); + + for (i = 0, layer = data->layers; i < data->totlayer; i++, layer++) { + + const char *name = CustomData_layertype_name(layer->type); + const int size = CustomData_sizeof(layer->type); + const char *structname; + int structnum; + CustomData_file_write_info(layer->type, &structname, &structnum); + printf(" dict(name='%s', struct='%s', type=%d, ptr='%p', elem=%d, length=%d),\n", + name, structname, layer->type, (void *)layer->data, size, (int)(MEM_allocN_len(layer->data) / size)); + } + + printf("}\n"); +} + #endif /* NDEBUG */ diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 6a8ddd8e00a..06bf5211abb 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -526,18 +526,12 @@ void BKE_pose_copy_data(bPose **dst, bPose *src, int copycon) bPose *outPose; bPoseChannel *pchan; ListBase listb; - + if (!src) { *dst = NULL; return; } - if (*dst == src) { - printf("BKE_pose_copy_data source and target are the same\n"); - *dst = NULL; - return; - } - outPose = MEM_callocN(sizeof(bPose), "pose"); BLI_duplicatelist(&outPose->chanbase, &src->chanbase); @@ -810,7 +804,7 @@ void framechange_poses_clear_unkeyed(void) /* TODO: proxies may/may not be correctly handled here... (this needs checking) */ 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) ) { + if ((pose = ob->pose)) { for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { if (pchan->bone) pchan->bone->flag &= ~BONE_UNKEYED; diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index 9b4f0a31e28..1b301ba43b3 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -63,7 +63,6 @@ #include "BKE_object.h" #include "BKE_particle.h" #include "BKE_scene.h" -#include "BKE_utildefines.h" #include "BKE_tessmesh.h" #include "BKE_depsgraph.h" #include "BKE_anim.h" @@ -75,7 +74,8 @@ /* --------------------- */ /* forward declarations */ -static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4], int par_index, int level, int animated); +static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4], int par_index, + int level, short animated, short update); /* ******************************************************************** */ /* Animation Visualization */ @@ -494,36 +494,42 @@ void calc_curvepath(Object *ob) /* in a path vertices are with equal differences: path->len = number of verts */ /* NOW WITH BEVELCURVE!!! */ - if (ob == NULL || ob->type != OB_CURVE) return; + if (ob == NULL || ob->type != OB_CURVE) { + return; + } cu = ob->data; - nurbs = BKE_curve_nurbs_get(cu); - nu = nurbs->first; - if (cu->path) free_path(cu->path); cu->path = NULL; + /* weak! can only use first curve */ bl = cu->bev.first; - if (bl == NULL || !bl->nr) return; + if (bl == NULL || !bl->nr) { + return; + } + + nurbs = BKE_curve_nurbs_get(cu); + nu = nurbs->first; cu->path = path = MEM_callocN(sizeof(Path), "calc_curvepath"); /* if POLY: last vertice != first vertice */ cycl = (bl->poly != -1); - if (cycl) tot = bl->nr; - else tot = bl->nr - 1; + tot = cycl ? bl->nr : bl->nr - 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"); /* all lengths in *dist */ bevp = bevpfirst = (BevPoint *)(bl + 1); fp = dist; - *fp = 0; + *fp = 0.0f; for (a = 0; a < tot; a++) { fp++; if (cycl && a == tot - 1) @@ -558,19 +564,16 @@ void calc_curvepath(Object *ob) fp++; if (bevp < bevplast) bevp++; bevpn = bevp + 1; - if (bevpn > bevplast) { - if (cycl) bevpn = bevpfirst; - else bevpn = bevplast; + if (UNLIKELY(bevpn > bevplast)) { + bevpn = cycl ? bevpfirst : bevplast; } } - fac1 = *(fp) - *(fp - 1); - fac2 = *(fp) - d; - fac1 = fac2 / fac1; + fac1 = (*(fp) - d) / (*(fp) - *(fp - 1)); fac2 = 1.0f - fac1; - + interp_v3_v3v3(pp->vec, bevp->vec, bevpn->vec, fac2); - pp->vec[3] = fac1 * bevp->alfa + fac2 * bevpn->alfa; + 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); @@ -582,18 +585,14 @@ void calc_curvepath(Object *ob) MEM_freeN(dist); } - -/* is this only used internally?*/ -int interval_test(int min, int max, int p1, int cycl) +static int interval_test(const int min, const int max, int p1, const int cycl) { if (cycl) { - if (p1 < min) - p1 = ((p1 - min) % (max - min + 1)) + max + 1; - else if (p1 > max) - p1 = ((p1 - min) % (max - min + 1)) + min; + if (p1 < min) p1 = ((p1 - min) % (max - min + 1)) + max + 1; + else if (p1 > max) p1 = ((p1 - min) % (max - min + 1)) + min; } else { - if (p1 < min) p1 = min; + if (p1 < min) p1 = min; else if (p1 > max) p1 = max; } return p1; @@ -701,7 +700,7 @@ int where_on_path(Object *ob, float ctime, float vec[4], float dir[3], float qua /* ******************************************************************** */ /* Dupli-Geometry */ -static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[][4], int lay, int index, int par_index, int type, int animated) +static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[][4], int lay, int index, int par_index, int type, short animated) { DupliObject *dob = MEM_callocN(sizeof(DupliObject), "dupliobject"); @@ -719,7 +718,8 @@ static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[][4], i return dob; } -static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_index, int level, int animated) +static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_index, + int level, short animated, short update) { DupliObject *dob; Group *group; @@ -733,8 +733,14 @@ static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_inde 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); + if (update) { + /* note: update is optional because we don't always need object + * transformations to be correct. Also fixes bug [#29616]. */ + group_handle_recalc_and_update(scene, ob, group); + } + animated = animated || group_is_animated(ob, group); for (go = group->gobject.first; go; go = go->next) { @@ -766,14 +772,14 @@ static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_inde 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, par_index, level + 1, animated); + object_duplilist_recursive(&group->id, scene, go->ob, lb, ob->obmat, par_index, level + 1, animated, update); copy_m4_m4(dob->ob->obmat, dob->omat); } } } } -static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_index, int level, int animated) +static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_index, int level, short animated) { extern int enable_cu_speed; /* object.c */ Object copyob; @@ -845,7 +851,8 @@ static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_ind typedef struct VertexDupliData { ID *id; /* scene or group, for recursive loops */ int level; - int animated; + short animated; + short update; ListBase *lb; float pmat[4][4]; float obmat[4][4]; /* Only used for dupliverts inside dupligroups, where the ob->obmat is modified */ @@ -901,12 +908,13 @@ 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->par_index, vdd->level + 1, vdd->animated); + object_duplilist_recursive((ID *)vdd->id, vdd->scene, vdd->ob, vdd->lb, obmat, vdd->par_index, vdd->level + 1, vdd->animated, vdd->update); copy_m4_m4(vdd->ob->obmat, tmpmat); } } -static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int par_index, int level, int animated) +static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int par_index, + int level, short animated, short update) { Object *ob, *ob_iter; Mesh *me = par->data; @@ -926,7 +934,7 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl /* simple preventing of too deep nested groups */ if (level > MAX_DUPLI_RECUR) return; - em = me->edit_btmesh; + em = BMEdit_FromObject(par); if (em) { dm = editbmesh_get_derived_cage(scene, par, em, CD_MASK_BAREMESH); @@ -985,6 +993,7 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl vdd.id = id; vdd.level = level; vdd.animated = animated; + vdd.update = update; vdd.lb = lb; vdd.ob = ob; vdd.scene = scene; @@ -1029,7 +1038,8 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl dm->release(dm); } -static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int par_index, int level, int animated) +static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int par_index, + int level, short animated, short update) { Object *ob, *ob_iter; Base *base = NULL; @@ -1052,7 +1062,7 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa if (level > MAX_DUPLI_RECUR) return; copy_m4_m4(pmat, par->obmat); - em = me->edit_btmesh; + em = BMEdit_FromObject(par); if (em) { dm = editbmesh_get_derived_cage(scene, par, em, CD_MASK_BAREMESH); @@ -1199,7 +1209,7 @@ 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, par_index, level + 1, animated); + object_duplilist_recursive((ID *)id, scene, ob, lb, ob->obmat, par_index, level + 1, animated, update); copy_m4_m4(ob->obmat, tmpmat); } } @@ -1219,7 +1229,8 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa dm->release(dm); } -static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int UNUSED(par_index), ParticleSystem *psys, int level, int animated) +static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int UNUSED(par_index), ParticleSystem *psys, + int level, short animated, short update) { GroupObject *go; Object *ob = NULL, **oblist = NULL, obcopy, *obcopylist = NULL; @@ -1302,7 +1313,9 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p /* gather list of objects or single object */ if (part->ren_as == PART_DRAW_GR) { - group_handle_recalc_and_update(scene, par, part->dup_group); + if (update) { + 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) @@ -1557,7 +1570,7 @@ static Object *find_family_object(Object **obar, char *family, char ch) } -static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int par_index, int level, int animated) +static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int par_index, int level, short animated) { Object *ob, *obar[256] = {NULL}; Curve *cu; @@ -1605,7 +1618,8 @@ static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int par_inde /* ------------- */ -static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4], int par_index, int level, int animated) +static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4], int par_index, + int level, short animated, short update) { if ((ob->transflag & OB_DUPLI) == 0) return; @@ -1625,11 +1639,11 @@ 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, par_index, psys, level + 1, animated); + new_particle_duplilist(duplilist, id, scene, ob, par_space_mat, par_index, psys, level + 1, animated, update); } else if (ob->transflag & OB_DUPLIVERTS) { if (ob->type == OB_MESH) { - vertex_duplilist(duplilist, id, scene, ob, par_space_mat, par_index, level + 1, animated); + vertex_duplilist(duplilist, id, scene, ob, par_space_mat, par_index, level + 1, animated, update); } else if (ob->type == OB_FONT) { if (GS(id->name) == ID_SCE) { /* TODO - support dupligroups */ @@ -1639,7 +1653,7 @@ static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBas } else if (ob->transflag & OB_DUPLIFACES) { if (ob->type == OB_MESH) - face_duplilist(duplilist, id, scene, ob, par_space_mat, par_index, level + 1, animated); + face_duplilist(duplilist, id, scene, ob, par_space_mat, par_index, level + 1, animated, update); } else if (ob->transflag & OB_DUPLIFRAMES) { if (GS(id->name) == ID_SCE) { /* TODO - support dupligroups */ @@ -1649,7 +1663,7 @@ static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBas else if (ob->transflag & OB_DUPLIGROUP) { DupliObject *dob; - group_duplilist(duplilist, scene, ob, par_index, level + 1, animated); /* now recursive */ + group_duplilist(duplilist, scene, ob, par_index, level + 1, animated, update); /* now recursive */ if (level == 0) { for (dob = duplilist->first; dob; dob = dob->next) @@ -1661,14 +1675,22 @@ static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBas /* Returns a list of DupliObject * note; group dupli's already set transform matrix. see note in group_duplilist() */ -ListBase *object_duplilist(Scene *sce, Object *ob) +ListBase *object_duplilist_ex(Scene *sce, Object *ob, int update) { ListBase *duplilist = MEM_mallocN(sizeof(ListBase), "duplilist"); duplilist->first = duplilist->last = NULL; - object_duplilist_recursive((ID *)sce, sce, ob, duplilist, NULL, 0, 0, 0); + object_duplilist_recursive((ID *)sce, sce, ob, duplilist, NULL, 0, 0, 0, update); return duplilist; } +/* note: previously updating was always done, this is why it defaults to be on + * but there are likely places it can be called without updating */ +ListBase *object_duplilist(Scene *sce, Object *ob) +{ + return object_duplilist_ex(sce, ob, TRUE); +} + + void free_object_duplilist(ListBase *lb) { DupliObject *dob; diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index ea625ec7699..cf785a4bb42 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -59,7 +59,6 @@ #include "BKE_main.h" #include "BKE_library.h" #include "BKE_report.h" -#include "BKE_utildefines.h" #include "RNA_access.h" @@ -622,15 +621,30 @@ static char *rna_path_rename_fix(ID *owner_id, const char *prefix, const char *o } /* Check RNA-Paths for a list of F-Curves */ -static void fcurves_path_rename_fix(ID *owner_id, const char *prefix, char *oldName, char *newName, ListBase *curves, int verify_paths) +static void fcurves_path_rename_fix(ID *owner_id, const char *prefix, const char *oldName, const char *newName, + const char *oldKey, const char *newKey, ListBase *curves, int verify_paths) { FCurve *fcu; /* we need to check every curve... */ for (fcu = curves->first; fcu; fcu = fcu->next) { - /* firstly, handle the F-Curve's own path */ - if (fcu->rna_path) - fcu->rna_path = rna_path_rename_fix(owner_id, prefix, oldName, newName, fcu->rna_path, verify_paths); + if (fcu->rna_path) { + char *old_path = fcu->rna_path; + + /* firstly, handle the F-Curve's own path */ + fcu->rna_path = rna_path_rename_fix(owner_id, prefix, oldKey, newKey, fcu->rna_path, verify_paths); + + /* if path changed and the F-Curve is grouped, check if its group also needs renaming + * (i.e. F-Curve is first of a bone's F-Curves; hence renaming this should also trigger rename) + */ + if (fcu->rna_path != old_path) { + bActionGroup *agrp = fcu->grp; + + if ((agrp) && strcmp(oldName, agrp->name)==0) { + BLI_strncpy(agrp->name, newName, sizeof(agrp->name)); + } + } + } } } @@ -676,7 +690,8 @@ static void drivers_path_rename_fix(ID *owner_id, ID *ref_id, const char *prefix } /* Fix all RNA-Paths for Actions linked to NLA Strips */ -static void nlastrips_path_rename_fix(ID *owner_id, const char *prefix, char *oldName, char *newName, ListBase *strips, int verify_paths) +static void nlastrips_path_rename_fix(ID *owner_id, const char *prefix, const char *oldName, const char *newName, + const char *oldKey, const char *newKey, ListBase *strips, int verify_paths) { NlaStrip *strip; @@ -684,11 +699,11 @@ static void nlastrips_path_rename_fix(ID *owner_id, const char *prefix, char *ol for (strip = strips->first; strip; strip = strip->next) { /* fix strip's action */ if (strip->act) - fcurves_path_rename_fix(owner_id, prefix, oldName, newName, &strip->act->curves, verify_paths); + fcurves_path_rename_fix(owner_id, prefix, oldName, newName, oldKey, newKey, &strip->act->curves, verify_paths); /* ignore own F-Curves, since those are local... */ /* check sub-strips (if metas) */ - nlastrips_path_rename_fix(owner_id, prefix, oldName, newName, &strip->strips, verify_paths); + nlastrips_path_rename_fix(owner_id, prefix, oldName, newName, oldKey, newKey, &strip->strips, verify_paths); } } @@ -718,16 +733,16 @@ void BKE_animdata_fix_paths_rename(ID *owner_id, AnimData *adt, ID *ref_id, cons /* Active action and temp action */ if (adt->action) - fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->action->curves, verify_paths); + fcurves_path_rename_fix(owner_id, prefix, oldName, newName, oldN, newN, &adt->action->curves, verify_paths); if (adt->tmpact) - fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->tmpact->curves, verify_paths); + fcurves_path_rename_fix(owner_id, prefix, oldName, newName, oldN, newN, &adt->tmpact->curves, verify_paths); /* Drivers - Drivers are really F-Curves */ drivers_path_rename_fix(owner_id, ref_id, prefix, oldName, newName, oldN, newN, &adt->drivers, verify_paths); /* NLA Data - Animation Data for Strips */ for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) - nlastrips_path_rename_fix(owner_id, prefix, oldN, newN, &nlt->strips, verify_paths); + nlastrips_path_rename_fix(owner_id, prefix, oldName, newName, oldN, newN, &nlt->strips, verify_paths); /* free the temp names */ MEM_freeN(oldN); @@ -1152,6 +1167,7 @@ static short animsys_write_rna_setting(PointerRNA *ptr, char *path, int array_in /* set value - only for animatable numerical values */ if (RNA_property_animateable(&new_ptr, prop)) { int array_len = RNA_property_array_length(&new_ptr, prop); + int written = FALSE; if (array_len && array_index >= array_len) { if (G.debug & G_DEBUG) { @@ -1165,25 +1181,52 @@ static short animsys_write_rna_setting(PointerRNA *ptr, char *path, int array_in switch (RNA_property_type(prop)) { case PROP_BOOLEAN: - if (array_len) - RNA_property_boolean_set_index(&new_ptr, prop, array_index, ANIMSYS_FLOAT_AS_BOOL(value)); - else - RNA_property_boolean_set(&new_ptr, prop, ANIMSYS_FLOAT_AS_BOOL(value)); + if (array_len) { + if (RNA_property_boolean_get_index(&new_ptr, prop, array_index) != ANIMSYS_FLOAT_AS_BOOL(value)) { + RNA_property_boolean_set_index(&new_ptr, prop, array_index, ANIMSYS_FLOAT_AS_BOOL(value)); + written = TRUE; + } + } + else { + if (RNA_property_boolean_get(&new_ptr, prop) != ANIMSYS_FLOAT_AS_BOOL(value)) { + RNA_property_boolean_set(&new_ptr, prop, ANIMSYS_FLOAT_AS_BOOL(value)); + written = TRUE; + } + } break; case PROP_INT: - if (array_len) - RNA_property_int_set_index(&new_ptr, prop, array_index, (int)value); - else - RNA_property_int_set(&new_ptr, prop, (int)value); + if (array_len) { + if (RNA_property_int_get_index(&new_ptr, prop, array_index) != (int)value) { + RNA_property_int_set_index(&new_ptr, prop, array_index, (int)value); + written = TRUE; + } + } + else { + if (RNA_property_int_get(&new_ptr, prop) != (int)value) { + RNA_property_int_set(&new_ptr, prop, (int)value); + written = TRUE; + } + } break; case PROP_FLOAT: - if (array_len) - RNA_property_float_set_index(&new_ptr, prop, array_index, value); - else - RNA_property_float_set(&new_ptr, prop, value); + if (array_len) { + if (RNA_property_float_get_index(&new_ptr, prop, array_index) != value) { + RNA_property_float_set_index(&new_ptr, prop, array_index, value); + written = TRUE; + } + } + else { + if (RNA_property_float_get(&new_ptr, prop) != value) { + RNA_property_float_set(&new_ptr, prop, value); + written = TRUE; + } + } break; case PROP_ENUM: - RNA_property_enum_set(&new_ptr, prop, (int)value); + if (RNA_property_enum_get(&new_ptr, prop) != (int)value) { + RNA_property_enum_set(&new_ptr, prop, (int)value); + written = TRUE; + } break; default: /* nothing can be done here... so it is unsuccessful? */ @@ -1193,7 +1236,7 @@ static short animsys_write_rna_setting(PointerRNA *ptr, char *path, int array_in /* RNA property update disabled for now - [#28525] [#28690] [#28774] [#28777] */ #if 0 /* buffer property update for later flushing */ - if (RNA_property_update_check(prop)) { + if (written && RNA_property_update_check(prop)) { short skip_updates_hack = 0; /* optimization hacks: skip property updates for those properties @@ -1213,7 +1256,7 @@ static short animsys_write_rna_setting(PointerRNA *ptr, char *path, int array_in /* as long as we don't do property update, we still tag datablock * as having been updated. this flag does not cause any updates to * be run, it's for e.g. render engines to synchronize data */ - if (new_ptr.id.data) { + if (written && new_ptr.id.data) { ID *id = new_ptr.id.data; id->flag |= LIB_ID_RECALC; DAG_id_type_tag(G.main, GS(id->name)); diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 04585791135..b87342f85fa 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -1551,7 +1551,7 @@ void BKE_armature_where_is(bArmature *arm) static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected) { bPose *pose = ob->pose, *frompose = from->pose; - bPoseChannel *pchan, *pchanp, pchanw; + bPoseChannel *pchan, *pchanp; bConstraint *con; int error = 0; @@ -1587,31 +1587,32 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { pchanp = BKE_pose_channel_find_name(frompose, pchan->name); - + if (UNLIKELY(pchanp == NULL)) { /* happens for proxies that become invalid because of a missing link * for regulat cases it shouldn't happen at all */ } else if (pchan->bone->layer & layer_protected) { ListBase proxylocal_constraints = {NULL, NULL}; - + bPoseChannel pchanw = {NULL}; + /* copy posechannel to temp, but restore important pointers */ pchanw = *pchanp; pchanw.prev = pchan->prev; pchanw.next = pchan->next; pchanw.parent = pchan->parent; pchanw.child = pchan->child; - + /* this is freed so copy a copy, else undo crashes */ if (pchanw.prop) { pchanw.prop = IDP_CopyProperty(pchanw.prop); - + /* use the values from the the existing props */ if (pchan->prop) { IDP_SyncGroupValues(pchanw.prop, pchan->prop); } } - + /* constraints - proxy constraints are flushed... local ones are added after * 1. extract constraints not from proxy (CONSTRAINT_PROXY_LOCAL) from pchan's constraints * 2. copy proxy-pchan's constraints on-to new @@ -1622,30 +1623,30 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected extract_proxylocal_constraints(&proxylocal_constraints, &pchan->constraints); copy_constraints(&pchanw.constraints, &pchanp->constraints, FALSE); BLI_movelisttolist(&pchanw.constraints, &proxylocal_constraints); - + /* constraints - set target ob pointer to own object */ for (con = pchanw.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 == from) ct->tar = ob; } - + if (cti->flush_constraint_targets) cti->flush_constraint_targets(con, &targets, 0); } } - + /* free stuff from current channel */ BKE_pose_channel_free(pchan); - - /* the final copy */ + + /* copy data in temp back over to the cleaned-out (but still allocated) original channel */ *pchan = pchanw; } else { @@ -2516,36 +2517,6 @@ void BKE_pose_where_is(Scene *scene, Object *ob) } } - -/* Returns total selected vgroups, - * wpi.defbase_sel is assumed malloc'd, all values are set */ -int get_selected_defgroups(Object *ob, char *dg_selection, int defbase_tot) -{ - bDeformGroup *defgroup; - unsigned int i; - 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 = BKE_pose_channel_find_name(pose, defgroup->name); - if (pchan && (pchan->bone->flag & BONE_SELECTED)) { - dg_selection[i] = TRUE; - dg_flags_sel_tot++; - } - else { - dg_selection[i] = FALSE; - } - } - } - else { - memset(dg_selection, FALSE, sizeof(char) * defbase_tot); - } - - return dg_flags_sel_tot; -} - /************** Bounding box ********************/ static int minmax_armature(Object *ob, float r_min[3], float r_max[3]) { diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 0b5d0d90c67..09519f68415 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -44,7 +44,8 @@ #include <stdio.h> #include <stddef.h> #include <string.h> -#include <fcntl.h> // for open +#include <fcntl.h> /* for open */ +#include <errno.h> #include "MEM_guardedalloc.h" @@ -80,13 +81,10 @@ #include "BKE_sound.h" #include "RE_pipeline.h" - #include "BLO_undofile.h" #include "BLO_readfile.h" #include "BLO_writefile.h" -#include "BKE_utildefines.h" - #include "RNA_access.h" #include "WM_api.h" // XXXXX BAD, very BAD dependency (bad level call) - remove asap, elubie @@ -465,11 +463,10 @@ int blender_test_break(void) #define UNDO_DISK 0 -#define MAXUNDONAME 64 typedef struct UndoElem { struct UndoElem *next, *prev; char str[FILE_MAX]; - char name[MAXUNDONAME]; + char name[BKE_UNDO_STR_MAX]; MemFile memfile; uintptr_t undosize; } UndoElem; @@ -515,8 +512,13 @@ 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) { @@ -717,38 +719,60 @@ void BKE_undo_save_quit(void) { UndoElem *uel; MemFileChunk *chunk; - int file; char str[FILE_MAX]; - - if ( (U.uiflag & USER_GLOBALUNDO) == 0) return; - + const int flag = O_BINARY + O_WRONLY + O_CREAT + O_TRUNC + O_EXCL; + int file; + + if ((U.uiflag & USER_GLOBALUNDO) == 0) { + return; + } + uel = curundo; if (uel == NULL) { - printf("No undo buffer to save recovery file\n"); + fprintf(stderr, "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; + } + + /* save the undo state as quit.blend */ BLI_make_file_string("/", str, BLI_temporary_dir(), "quit.blend"); - file = BLI_open(str, O_BINARY + O_WRONLY + O_CREAT + O_TRUNC, 0666); + /* first try create the file, if it exists call without 'O_CREAT', + * to avoid writing to a symlink - use 'O_EXCL' (CVE-2008-1103) */ + errno = 0; + file = BLI_open(str, flag, 0666); if (file == -1) { - //XXX error("Unable to save %s, check you have permissions", str); + if (errno == EEXIST) { + errno = 0; + file = BLI_open(str, flag & ~O_CREAT, 0666); + } + } + + if (file == -1) { + fprintf(stderr, "Unable to save '%s': %s\n", + str, errno ? strerror(errno) : "Unknown error opening file"); return; } - chunk = uel->memfile.chunks.first; - while (chunk) { - if (write(file, chunk->buf, chunk->size) != chunk->size) break; - chunk = chunk->next; + for (chunk = uel->memfile.chunks.first; chunk; chunk = chunk->next) { + if (write(file, chunk->buf, chunk->size) != chunk->size) { + break; + } } - + close(file); - if (chunk) ; //XXX error("Unable to save %s, internal error", str); - else printf("Saved session recovery to %s\n", str); + if (chunk) { + fprintf(stderr, "Unable to save '%s': %s\n", + str, errno ? strerror(errno) : "Unknown error writing file"); + } + else { + printf("Saved session recovery to '%s'\n", str); + } } /* sets curscene */ diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 881caec8a58..b176ed429f8 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -50,7 +50,6 @@ #include "BKE_global.h" #include "BKE_mesh.h" #include "BKE_paint.h" -#include "BKE_utildefines.h" #include "BKE_tessmesh.h" #include "BKE_curve.h" diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 00130dd3583..6b9e0921c3b 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -416,8 +416,7 @@ void constraint_mat_convertspace(Object *ob, bPoseChannel *pchan, float mat[][4] static void contarget_get_mesh_mat(Object *ob, const char *substring, float mat[][4]) { DerivedMesh *dm = NULL; - Mesh *me = ob->data; - BMEditMesh *em = me->edit_btmesh; + BMEditMesh *em = BMEdit_FromObject(ob); 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]; @@ -4292,8 +4291,8 @@ bConstraintTypeInfo *get_constraint_typeinfo(int type) } /* only return for valid types */ - if ( (type >= CONSTRAINT_TYPE_NULL) && - (type < NUM_CONSTRAINT_TYPES) ) + if ((type >= CONSTRAINT_TYPE_NULL) && + (type < NUM_CONSTRAINT_TYPES)) { /* there shouldn't be any segfaults here... */ return constraintsTypeInfo[type]; @@ -4514,7 +4513,7 @@ static void con_relink_id_cb(bConstraint *UNUSED(con), ID **idpoin, short UNUSED * since we've got the actual ID block, let's just inline this * code. * - * See ID_NEW(a) in BKE_utildefines.h + * See ID_NEW(a) in DNA_ID.h */ if ((*idpoin) && (*idpoin)->newid) (*idpoin) = (void *)(*idpoin)->newid; diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index a00bea38e51..342ee5bba41 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -51,7 +51,6 @@ #include "BLI_mempool.h" #include "BLI_utildefines.h" -#include "BKE_utildefines.h" #include "BKE_customdata.h" #include "BKE_customdata_file.h" #include "BKE_global.h" diff --git a/source/blender/blenkernel/intern/customdata_file.c b/source/blender/blenkernel/intern/customdata_file.c index 71801c4729f..78449879f72 100644 --- a/source/blender/blenkernel/intern/customdata_file.c +++ b/source/blender/blenkernel/intern/customdata_file.c @@ -32,6 +32,7 @@ #include "BLI_fileops.h" #include "BLI_string.h" #include "BLI_utildefines.h" +#include "BLI_endian_switch.h" #include "BKE_customdata_file.h" #include "BKE_global.h" @@ -165,9 +166,9 @@ static int cdf_read_header(CDataFile *cdf) header->endian = cdf_endian(); if (cdf->switchendian) { - SWITCH_INT(header->type); - SWITCH_INT(header->totlayer); - SWITCH_INT(header->structbytes); + BLI_endian_switch_int32(&header->type); + BLI_endian_switch_int32(&header->totlayer); + BLI_endian_switch_int32(&header->structbytes); } if (!ELEM(header->type, CDF_TYPE_IMAGE, CDF_TYPE_MESH)) @@ -185,10 +186,10 @@ static int cdf_read_header(CDataFile *cdf) return 0; if (cdf->switchendian) { - SWITCH_INT(image->width); - SWITCH_INT(image->height); - SWITCH_INT(image->tile_size); - SWITCH_INT(image->structbytes); + BLI_endian_switch_int32(&image->width); + BLI_endian_switch_int32(&image->height); + BLI_endian_switch_int32(&image->tile_size); + BLI_endian_switch_int32(&image->structbytes); } offset += image->structbytes; @@ -200,7 +201,7 @@ static int cdf_read_header(CDataFile *cdf) return 0; if (cdf->switchendian) - SWITCH_INT(mesh->structbytes); + BLI_endian_switch_int32(&mesh->structbytes); offset += mesh->structbytes; mesh->structbytes = sizeof(CDataFileMeshHeader); @@ -219,10 +220,10 @@ static int cdf_read_header(CDataFile *cdf) return 0; if (cdf->switchendian) { - SWITCH_INT(layer->type); - SWITCH_INT(layer->datatype); - SWITCH_INT64(layer->datasize); - SWITCH_INT(layer->structbytes); + BLI_endian_switch_int32(&layer->type); + BLI_endian_switch_int32(&layer->datatype); + BLI_endian_switch_uint64(&layer->datasize); + BLI_endian_switch_int32(&layer->structbytes); } if (layer->datatype != CDF_DATA_FLOAT) @@ -317,20 +318,13 @@ int cdf_read_layer(CDataFile *cdf, CDataFileLayer *blay) int cdf_read_data(CDataFile *cdf, unsigned int size, void *data) { - float *fdata; - unsigned int a; - /* read data */ if (!fread(data, size, 1, cdf->readf)) return 0; /* switch endian if necessary */ if (cdf->switchendian) { - fdata = data; - - for (a = 0; a < size / sizeof(float); a++) { - SWITCH_INT(fdata[a]); - } + BLI_endian_switch_float_array(data, size / sizeof(float)); } return 1; diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index 547a64a70d4..4110d4565b2 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -33,6 +33,7 @@ #include <string.h> #include <math.h> #include <ctype.h> +#include <stdlib.h> #include "MEM_guardedalloc.h" @@ -41,7 +42,10 @@ #include "BKE_deform.h" -#include "BLI_blenlib.h" +#include "BLI_listbase.h" +#include "BLI_math.h" +#include "BLI_path_util.h" +#include "BLI_string.h" #include "BLI_utildefines.h" @@ -204,13 +208,15 @@ void defvert_normalize(MDeformVert *dvert) } } -void defvert_normalize_lock(MDeformVert *dvert, const int def_nr_lock) +void defvert_normalize_lock_single(MDeformVert *dvert, const int def_nr_lock) { if (dvert->totweight <= 0) { /* nothing */ } else if (dvert->totweight == 1) { - dvert->dw[0].weight = 1.0f; + if (def_nr_lock != 0) { + dvert->dw[0].weight = 1.0f; + } } else { MDeformWeight *dw_lock = NULL; @@ -246,6 +252,50 @@ void defvert_normalize_lock(MDeformVert *dvert, const int def_nr_lock) } } +void defvert_normalize_lock_map(MDeformVert *dvert, const char *lock_flags, const int defbase_tot) +{ + if (dvert->totweight <= 0) { + /* nothing */ + } + else if (dvert->totweight == 1) { + if (LIKELY(defbase_tot >= 1) && lock_flags[0]) { + dvert->dw[0].weight = 1.0f; + } + } + else { + MDeformWeight *dw; + unsigned int i; + float tot_weight = 0.0f; + float lock_iweight = 0.0f; + + for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) { + if ((dw->def_nr < defbase_tot) && (lock_flags[dw->def_nr] == FALSE)) { + tot_weight += dw->weight; + } + else { + /* invert after */ + lock_iweight += dw->weight; + } + } + + lock_iweight = maxf(0.0f, 1.0f - lock_iweight); + + if (tot_weight > 0.0f) { + /* paranoid, should be 1.0 but in case of float error clamp anyway */ + + float scalar = (1.0f / tot_weight) * lock_iweight; + for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) { + if ((dw->def_nr < defbase_tot) && (lock_flags[dw->def_nr] == FALSE)) { + dw->weight *= scalar; + + /* in case of division errors with very low weights */ + CLAMP(dw->weight, 0.0f, 1.0f); + } + } + } + } +} + void defvert_flip(MDeformVert *dvert, const int *flip_map, const int flip_map_len) { MDeformWeight *dw; diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index 1b53f8980cb..b8d5294eabc 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -75,7 +75,6 @@ #include "BKE_scene.h" #include "BKE_screen.h" #include "BKE_tracking.h" -#include "BKE_utildefines.h" #include "depsgraph_private.h" diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 06807dfcbad..f47ac641cf9 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -2595,7 +2595,7 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char *filenam int format = (surface->image_fileformat & MOD_DPAINT_IMGFORMAT_OPENEXR) ? R_IMF_IMTYPE_OPENEXR : R_IMF_IMTYPE_PNG; char output_file[FILE_MAX]; - if (!sData || !sData->type_data) { setError(surface->canvas, "Image save failed: Invalid surface."); return; } + if (!sData->type_data) { setError(surface->canvas, "Image save failed: Invalid surface."); return; } /* if selected format is openexr, but current build doesnt support one */ #ifndef WITH_OPENEXR if (format == R_IMF_IMTYPE_OPENEXR) format = R_IMF_IMTYPE_PNG; @@ -4800,7 +4800,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su PaintBakeData *bData = sData->bData; DynamicPaintCanvasSettings *canvas = surface->canvas; int ret = 1; - if (!sData || sData->total_points < 1) return 0; + if (sData->total_points < 1) return 0; dynamicPaint_surfacePreStep(surface, timescale); /* @@ -4875,7 +4875,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su /* Apply brush on the surface depending on it's collision type */ /* Particle brush: */ if (brush->collision == MOD_DPAINT_COL_PSYS) { - if (brush && brush->psys && brush->psys->part && brush->psys->part->type == PART_EMITTER && + if (brush->psys && brush->psys->part && brush->psys->part->type == PART_EMITTER && psys_check_enabled(brushObj, brush->psys)) { diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index c6ba6a0d841..befec1907da 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -1747,5 +1747,11 @@ DerivedMesh *getEditDerivedBMesh(BMEditMesh *em, BMEditMesh *BMEdit_FromObject(Object *ob) { BLI_assert(ob->type == OB_MESH); + /* sanity check */ +#ifndef NDEBUG + if (((Mesh *)ob->data)->edit_btmesh) { + BLI_assert(((Mesh *)ob->data)->edit_btmesh->ob == ob); + } +#endif return ((Mesh *)ob->data)->edit_btmesh; } diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 53c12d32bc1..2dbc63e6944 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -55,7 +55,6 @@ #include "BKE_curve.h" #include "BKE_global.h" #include "BKE_object.h" -#include "BKE_utildefines.h" #include "RNA_access.h" @@ -75,12 +74,10 @@ void free_fcurve(FCurve *fcu) { if (fcu == NULL) return; - + /* free curve data */ - if (fcu) { - if (fcu->bezt) MEM_freeN(fcu->bezt); - if (fcu->fpt) MEM_freeN(fcu->fpt); - } + if (fcu->bezt) MEM_freeN(fcu->bezt); + if (fcu->fpt) MEM_freeN(fcu->fpt); /* free RNA-path, as this were allocated when getting the path string */ if (fcu->rna_path) @@ -507,8 +504,8 @@ short calc_fcurve_bounds(FCurve *fcu, float *xmin, float *xmax, float *ymin, flo xmaxv = MAX3(xmaxv, bezt_last->vec[1][0], bezt_last->vec[2][0]); } else { - xminv = MIN2(xminv, bezt_first->vec[1][0]); - xmaxv = MAX2(xmaxv, bezt_last->vec[1][0]); + xminv = minf(xminv, bezt_first->vec[1][0]); + xmaxv = maxf(xmaxv, bezt_last->vec[1][0]); } } } @@ -524,8 +521,8 @@ short calc_fcurve_bounds(FCurve *fcu, float *xmin, float *xmax, float *ymin, flo ymaxv = MAX4(ymaxv, bezt->vec[1][1], bezt->vec[0][1], bezt->vec[2][1]); } else { - yminv = MIN2(yminv, bezt->vec[1][1]); - ymaxv = MAX2(ymaxv, bezt->vec[1][1]); + yminv = minf(yminv, bezt->vec[1][1]); + ymaxv = maxf(ymaxv, bezt->vec[1][1]); } foundvert = TRUE; @@ -536,8 +533,8 @@ short calc_fcurve_bounds(FCurve *fcu, float *xmin, float *xmax, float *ymin, flo 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 = minf(xminv, fcu->fpt[0].vec[0]); + xmaxv = maxf(xmaxv, fcu->fpt[fcu->totvert - 1].vec[0]); } /* only loop over keyframes to find extents for values if needed */ @@ -594,15 +591,15 @@ 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 = minf(min, bezt_first->vec[1][0]); + max = maxf(max, bezt_last->vec[1][0]); 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 = minf(min, fcu->fpt[0].vec[0]); + max = maxf(max, fcu->fpt[fcu->totvert - 1].vec[0]); foundvert = TRUE; } diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c index 438188b1e2a..538d2469a93 100644 --- a/source/blender/blenkernel/intern/fmodifier.c +++ b/source/blender/blenkernel/intern/fmodifier.c @@ -965,8 +965,8 @@ FModifierTypeInfo *get_fmodifier_typeinfo(int type) } /* only return for valid types */ - if ( (type >= FMODIFIER_TYPE_NULL) && - (type <= FMODIFIER_NUM_TYPES) ) + if ((type >= FMODIFIER_TYPE_NULL) && + (type < FMODIFIER_NUM_TYPES)) { /* there shouldn't be any segfaults here... */ return fmodifiersTypeInfo[type]; diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 0ffd68c9079..8b35974ea62 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -50,7 +50,6 @@ #include "DNA_scene_types.h" #include "DNA_object_types.h" -#include "BKE_utildefines.h" #include "BKE_packedFile.h" #include "BKE_library.h" #include "BKE_font.h" diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 7456f9aab8b..8229df28ab8 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -293,18 +293,6 @@ static IDProperty *IDP_CopyArray(IDProperty *prop) return newp; } -/*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; \ - } (void)0 - - - /* ---------- String Type ------------ */ IDProperty *IDP_NewString(const char *st, const char *name, int maxlen) { diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 2b2128439c7..3f756e74b26 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -79,7 +79,6 @@ #include "BKE_scene.h" #include "BKE_node.h" #include "BKE_sequencer.h" /* seq_foreground_frame_get() */ -#include "BKE_utildefines.h" #include "BLF_api.h" @@ -595,7 +594,7 @@ Image *BKE_image_load_exists(const char *filepath) 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]) +static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short gen_type, float color[4]) { ImBuf *ibuf; unsigned char *rect = NULL; @@ -615,11 +614,11 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char BLI_strncpy(ibuf->name, name, sizeof(ibuf->name)); ibuf->userflags |= IB_BITMAPDIRTY; - switch (uvtestgrid) { - case 1: + switch (gen_type) { + case IMA_GENTYPE_GRID: BKE_image_buf_fill_checker(rect, rect_float, width, height); break; - case 2: + case IMA_GENTYPE_GRID_COLOR: BKE_image_buf_fill_checker_color(rect, rect_float, width, height); break; default: @@ -630,7 +629,7 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char } /* adds new image block, creates ImBuf and initializes color */ -Image *BKE_image_add_generated(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 gen_type, 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); @@ -641,10 +640,10 @@ Image *BKE_image_add_generated(unsigned int width, unsigned int height, const ch /* 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_type = gen_type; 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, gen_type, color); image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); ima->ok = IMA_OK_LOADED; @@ -2527,7 +2526,9 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_ 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) { + /* pass */ + } else if (rres.layers.first) { RenderLayer *rl = BLI_findlink(&rres.layers, layer - (rres.have_combined ? 1 : 0)); if (rl) { @@ -2930,3 +2931,40 @@ int BKE_image_has_alpha(struct Image *image) else return 0; } + +void BKE_image_get_size(Image *image, ImageUser *iuser, int *width, int *height) +{ + ImBuf *ibuf = NULL; + void *lock; + + ibuf = BKE_image_acquire_ibuf(image, iuser, &lock); + + if (ibuf && ibuf->x > 0 && ibuf->y > 0) { + *width = ibuf->x; + *height = ibuf->y; + } + else { + *width = IMG_SIZE_FALLBACK; + *height = IMG_SIZE_FALLBACK; + } + + BKE_image_release_ibuf(image, lock); +} + +void BKE_image_get_size_fl(Image *image, ImageUser *iuser, float size[2]) +{ + int width, height; + BKE_image_get_size(image, iuser, &width, &height); + + size[0] = (float)width; + size[1] = (float)height; + +} + +void BKE_image_get_aspect(Image *image, float *aspx, float *aspy) +{ + *aspx = 1.0; + + /* x is always 1 */ + *aspy = image->aspy / image->aspx; +} diff --git a/source/blender/blenkernel/intern/implicit.c b/source/blender/blenkernel/intern/implicit.c index 616214c21ff..1c6974b2615 100644 --- a/source/blender/blenkernel/intern/implicit.c +++ b/source/blender/blenkernel/intern/implicit.c @@ -193,7 +193,7 @@ DO_INLINE lfVector *create_lfvector(unsigned int verts) DO_INLINE void del_lfvector(float (*fLongVector)[3]) { if (fLongVector != NULL) { - MEM_freeN (fLongVector); + MEM_freeN(fLongVector); // cloth_aligned_free(&MEMORY_BASE, fLongVector); } } @@ -523,7 +523,7 @@ DO_INLINE fmatrix3x3 *create_bfmatrix(unsigned int verts, unsigned int springs) DO_INLINE void del_bfmatrix(fmatrix3x3 *matrix) { if (matrix != NULL) { - MEM_freeN (matrix); + MEM_freeN(matrix); } } diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index 17a3c595ea7..b79608342dd 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -691,8 +691,8 @@ static void cp_cu_key(Curve *cu, Key *key, KeyBlock *actkb, KeyBlock *kb, const if (nu->bp) { step = nu->pntsu * nu->pntsv; - a1 = MAX2(a, start); - a2 = MIN2(a + step, end); + a1 = maxi(a, start); + a2 = mini(a + step, end); if (a1 < a2) cp_key(a1, a2, tot, out, key, actkb, kb, NULL, KEY_MODE_BPOINT); } @@ -700,8 +700,8 @@ static void cp_cu_key(Curve *cu, Key *key, KeyBlock *actkb, KeyBlock *kb, const step = 3 * nu->pntsu; /* exception because keys prefer to work with complete blocks */ - a1 = MAX2(a, start); - a2 = MIN2(a + step, end); + a1 = maxi(a, start); + a2 = mini(a + step, end); if (a1 < a2) cp_key(a1, a2, tot, out, key, actkb, kb, NULL, KEY_MODE_BEZTRIPLE); } @@ -1217,7 +1217,7 @@ static void do_curve_key(Scene *scene, Object *ob, Key *key, char *out, const in remain = step; } - count = MIN2(remain, estep); + count = mini(remain, estep); if (mode == KEY_MODE_BEZTRIPLE) { count += 3 - count % 3; } @@ -1573,7 +1573,7 @@ void key_to_latt(KeyBlock *kb, Lattice *lt) fp = kb->data; tot = lt->pntsu * lt->pntsv * lt->pntsw; - tot = MIN2(kb->totelem, tot); + tot = mini(kb->totelem, tot); for (a = 0; a < tot; a++, fp += 3, bp++) { copy_v3_v3(bp->vec, fp); @@ -1645,7 +1645,7 @@ void key_to_curve(KeyBlock *kb, Curve *UNUSED(cu), ListBase *nurb) tot = BKE_nurbList_verts_count(nurb); - tot = MIN2(kb->totelem, tot); + tot = mini(kb->totelem, tot); while (nu && tot > 0) { @@ -1713,7 +1713,7 @@ void key_to_mesh(KeyBlock *kb, Mesh *me) mvert = me->mvert; fp = kb->data; - tot = MIN2(kb->totelem, me->totvert); + tot = mini(kb->totelem, me->totvert); for (a = 0; a < tot; a++, fp += 3, mvert++) { copy_v3_v3(mvert->co, fp); diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 0e73d10fa5f..17e4103c7d3 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -488,7 +488,7 @@ static int where_on_path_deform(Object *ob, float ctime, float vec[4], float dir /* test for cyclic */ bl = cu->bev.first; if (!bl->nr) return 0; - if (bl && bl->poly > -1) cycl = 1; + if (bl->poly > -1) cycl = 1; if (cycl == 0) { ctime1 = CLAMPIS(ctime, 0.0f, 1.0f); diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 77e7623ae3d..f6e86bdbb5a 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -107,7 +107,6 @@ #include "BKE_gpencil.h" #include "BKE_fcurve.h" #include "BKE_speaker.h" -#include "BKE_utildefines.h" #include "BKE_movieclip.h" #include "BKE_mask.h" #include "BKE_linestyle.h" @@ -813,6 +812,7 @@ 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 BKE_libblock_free(ListBase *lb, void *idv) { + Main *bmain = G.main; /* should eventually be an arg */ ID *id = idv; #ifdef WITH_PYTHON @@ -875,7 +875,7 @@ void BKE_libblock_free(ListBase *lb, void *idv) BKE_text_free((Text *)id); break; case ID_SCRIPT: - //XXX free_script((Script *)id); + /* deprecated */ break; case ID_SPK: BKE_speaker_free((Speaker *)id); @@ -912,7 +912,7 @@ void BKE_libblock_free(ListBase *lb, void *idv) BKE_movieclip_free((MovieClip *)id); break; case ID_MSK: - BKE_mask_free((Mask *)id); + BKE_mask_free(bmain, (Mask *)id); break; case ID_LS: FRS_free_linestyle((FreestyleLineStyle *)id); @@ -927,7 +927,7 @@ void BKE_libblock_free(ListBase *lb, void *idv) BLI_remlink(lb, id); /* this ID may be a driver target! */ - BKE_animdata_main_cb(G.main, animdata_dtar_clear_cb, (void *)id); + BKE_animdata_main_cb(bmain, animdata_dtar_clear_cb, (void *)id); MEM_freeN(id); } @@ -962,9 +962,52 @@ void free_main(Main *mainvar) ID *id; while ( (id = lb->first) ) { +#if 1 BKE_libblock_free(lb, id); +#else + /* errors freeing ID's can be hard to track down, + * enable this so valgrind will give the line number in its error log */ + switch (a) { + case 0: BKE_libblock_free(lb, id); break; + case 1: BKE_libblock_free(lb, id); break; + case 2: BKE_libblock_free(lb, id); break; + case 3: BKE_libblock_free(lb, id); break; + case 4: BKE_libblock_free(lb, id); break; + case 5: BKE_libblock_free(lb, id); break; + case 6: BKE_libblock_free(lb, id); break; + case 7: BKE_libblock_free(lb, id); break; + case 8: BKE_libblock_free(lb, id); break; + case 9: BKE_libblock_free(lb, id); break; + case 10: BKE_libblock_free(lb, id); break; + case 11: BKE_libblock_free(lb, id); break; + case 12: BKE_libblock_free(lb, id); break; + case 13: BKE_libblock_free(lb, id); break; + case 14: BKE_libblock_free(lb, id); break; + case 15: BKE_libblock_free(lb, id); break; + case 16: BKE_libblock_free(lb, id); break; + case 17: BKE_libblock_free(lb, id); break; + case 18: BKE_libblock_free(lb, id); break; + case 19: BKE_libblock_free(lb, id); break; + case 20: BKE_libblock_free(lb, id); break; + case 21: BKE_libblock_free(lb, id); break; + case 22: BKE_libblock_free(lb, id); break; + case 23: BKE_libblock_free(lb, id); break; + case 24: BKE_libblock_free(lb, id); break; + case 25: BKE_libblock_free(lb, id); break; + case 26: BKE_libblock_free(lb, id); break; + case 27: BKE_libblock_free(lb, id); break; + case 28: BKE_libblock_free(lb, id); break; + case 29: BKE_libblock_free(lb, id); break; + case 30: BKE_libblock_free(lb, id); break; + case 31: BKE_libblock_free(lb, id); break; + case 32: BKE_libblock_free(lb, id); break; + default: + BLI_assert(0); + } +#endif } } + a = set_listbasepointers(mainvar, lbarray); MEM_freeN(mainvar); } @@ -1543,7 +1586,7 @@ void BKE_library_filepath_set(Library *lib, const char *filepath) /* not essential but set filepath is an absolute copy of value which * is more useful if its kept in sync */ - if (strncmp(lib->filepath, "//", 2) == 0) { + if (BLI_path_is_rel(lib->filepath)) { /* note that the file may be unsaved, in this case, setting the * filepath on an indirectly linked path is not allowed from the * outliner, and its not really supported but allow from here for now diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index f73fb3879b8..97b46d4829d 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -55,6 +55,7 @@ #include "BKE_sequencer.h" #include "BKE_tracking.h" #include "BKE_movieclip.h" +#include "BKE_image.h" static MaskSplinePoint *mask_spline_point_next(MaskSpline *spline, MaskSplinePoint *points_array, MaskSplinePoint *point) { @@ -909,7 +910,8 @@ void BKE_mask_layer_free_list(ListBase *masklayers) } } -void BKE_mask_free(Mask *mask) +/** free for temp copy, but don't manage unlinking from other pointers */ +void BKE_mask_free_nolib(Mask *mask) { BKE_mask_layer_free_list(&mask->masklayers); } @@ -927,7 +929,7 @@ static void ntree_unlink_mask_cb(void *calldata, struct ID *UNUSED(owner_id), st } } -void BKE_mask_unlink(Main *bmain, Mask *mask) +void BKE_mask_free(Main *bmain, Mask *mask) { bScreen *scr; ScrArea *area; @@ -990,7 +992,8 @@ void BKE_mask_unlink(Main *bmain, Mask *mask) treetype->foreach_nodetree(bmain, (void *)mask, &ntree_unlink_mask_cb); } - BKE_libblock_free(&bmain->mask, mask); + /* free mask data */ + BKE_mask_layer_free_list(&mask->masklayers); } void BKE_mask_coord_from_frame(float r_co[2], const float co[2], const float frame_size[2]) @@ -1010,14 +1013,26 @@ void BKE_mask_coord_from_frame(float r_co[2], const float co[2], const float fra } void BKE_mask_coord_from_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2]) { - int width, height; + float aspx, aspy; float frame_size[2]; /* scaling for the clip */ - BKE_movieclip_get_size(clip, user, &width, &height); + BKE_movieclip_get_size_fl(clip, user, frame_size); + BKE_movieclip_get_aspect(clip, &aspx, &aspy); + + frame_size[1] *= (aspy / aspx); + + BKE_mask_coord_from_frame(r_co, co, frame_size); +} +void BKE_mask_coord_from_image(Image *image, ImageUser *iuser, float r_co[2], const float co[2]) +{ + float aspx, aspy; + float frame_size[2]; + + BKE_image_get_size_fl(image, iuser, frame_size); + BKE_image_get_aspect(image, &aspx, &aspy); - frame_size[0] = (float)width; - frame_size[1] = (float)height; + frame_size[1] *= (aspy / aspx); BKE_mask_coord_from_frame(r_co, co, frame_size); } @@ -1040,14 +1055,27 @@ void BKE_mask_coord_to_frame(float r_co[2], const float co[2], const float frame } void BKE_mask_coord_to_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2]) { - int width, height; + float aspx, aspy; + float frame_size[2]; + + /* scaling for the clip */ + BKE_movieclip_get_size_fl(clip, user, frame_size); + BKE_movieclip_get_aspect(clip, &aspx, &aspy); + + frame_size[1] /= (aspy / aspx); + + BKE_mask_coord_to_frame(r_co, co, frame_size); +} +void BKE_mask_coord_to_image(Image *image, ImageUser *iuser, float r_co[2], const float co[2]) +{ + float aspx, aspy; float frame_size[2]; /* scaling for the clip */ - BKE_movieclip_get_size(clip, user, &width, &height); + BKE_image_get_size_fl(image, iuser, frame_size); + BKE_image_get_aspect(image, &aspx, &aspy); - frame_size[0] = (float)width; - frame_size[1] = (float)height; + frame_size[1] /= (aspy / aspx); BKE_mask_coord_to_frame(r_co, co, frame_size); } diff --git a/source/blender/blenkernel/intern/mask_evaluate.c b/source/blender/blenkernel/intern/mask_evaluate.c index 065dc38c81e..4a8601df0b8 100644 --- a/source/blender/blenkernel/intern/mask_evaluate.c +++ b/source/blender/blenkernel/intern/mask_evaluate.c @@ -61,7 +61,6 @@ #include "BKE_sequencer.h" #include "BKE_tracking.h" #include "BKE_movieclip.h" -#include "BKE_utildefines.h" unsigned int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height) diff --git a/source/blender/blenkernel/intern/mask_rasterize.c b/source/blender/blenkernel/intern/mask_rasterize.c index eb96d6726b9..18617f0ef2e 100644 --- a/source/blender/blenkernel/intern/mask_rasterize.c +++ b/source/blender/blenkernel/intern/mask_rasterize.c @@ -26,6 +26,46 @@ /** \file blender/blenkernel/intern/mask_rasterize.c * \ingroup bke + * + * This module exposes a rasterizer that works as a black box - implementation details are confined to this file, + * + * The basic method to access is: + * - create & initialize a handle from a #Mask datablock. + * - execute pixel lookups. + * - free the handle. + * + * This file is admittedly a bit confusticated, in quite few areas speed was chosen over readability, + * though it is commented - so shouldn't be so hard to see whats going on. + * + * + * Implementation: + * + * To rasterize the mask its converted into geometry that use a ray-cast for each pixel lookup. + * + * Initially 'kdopbvh' was used but this ended up being too slow. + * + * To gain some extra speed we take advantage of a few shortcuts that can be made rasterizing masks specifically. + * - all triangles are known to be completely white - so no depth check is done on triangle intersection. + * - all quads are known to be feather outlines - the 1 and 0 depths are known by the vertex order in the quad, + * - there is no color - just a value for each mask pixel. + * - the mask spacial structure always maps to space 0-1 on X and Y axis. + * - bucketing is used to speed up lookups for geometry. + * + * Other Details: + * - used unsigned values all over for some extra speed on some arch's. + * - anti-aliasing is faked, just ensuring at least one pixel feather - avoids oversampling. + * - initializing the spacial structure doesn't need to be as optimized as pixel lookups are. + * - mask lookups need not be pixel aligned so any sub-pixel values from x/y (0 - 1), can be found. + * (perhaps masks can be used as a vector texture in 3D later on) + * + * + * Currently, to build the spacial structure we have to calculate the total number of faces ahead of time. + * + * This is getting a bit complicated with the addition of unfilled splines and end capping - + * If large changes are needed here we would be better off using an iterable + * BLI_mempool for triangles and converting to a contiguous array afterwards. + * + * - Campbell */ #include "MEM_guardedalloc.h" diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index a92497ffb9d..3925c3cc858 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -157,17 +157,19 @@ struct pgn_elements { /* Forward declarations */ static int vertid(const CORNER *c1, const CORNER *c2, PROCESS *p, MetaBall *mb); -static int setcenter(CENTERLIST *table[], int i, int j, int k); +static int setcenter(CENTERLIST *table[], const int i, const int j, const int k); static CORNER *setcorner(PROCESS *p, int i, int j, int k); static void converge(const float p1[3], const float p2[3], float v1, float v2, float (*function)(float, float, float), float p[3], MetaBall *mb, int f); /* Global variables */ +static struct { + float thresh; + int totelem; + MetaElem **mainb; + octal_tree *metaball_tree; +} G_mb = {0}; -static float thresh = 0.6f; -static int totelem = 0; -static MetaElem **mainb; -static octal_tree *metaball_tree = NULL; /* Functions */ void BKE_mball_unlink(MetaBall *mb) @@ -523,7 +525,7 @@ Object *BKE_mball_basis_find(Scene *scene, Object *basis) char basisname[MAX_ID_NAME], obname[MAX_ID_NAME]; BLI_split_name_num(basisname, &basisnr, basis->id.name + 2, '.'); - totelem = 0; + G_mb.totelem = 0; /* 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)) @@ -564,9 +566,10 @@ Object *BKE_mball_basis_find(Scene *scene, Object *basis) } } - while (ml) { - if (!(ml->flag & MB_HIDE)) totelem++; - ml = ml->next; + for ( ; ml; ml = ml->next) { + if (!(ml->flag & MB_HIDE)) { + G_mb.totelem++; + } } } } @@ -637,21 +640,6 @@ static float densfunc(MetaElem *ball, float x, float y, float z) case MB_BALL: /* do nothing */ break; - case MB_TUBEX: - if (dvec[0] > ball->len) dvec[0] -= ball->len; - else if (dvec[0] < -ball->len) dvec[0] += ball->len; - else dvec[0] = 0.0; - break; - case MB_TUBEY: - if (dvec[1] > ball->len) dvec[1] -= ball->len; - else if (dvec[1] < -ball->len) dvec[1] += ball->len; - else dvec[1] = 0.0; - break; - case MB_TUBEZ: - if (dvec[2] > ball->len) dvec[2] -= ball->len; - else if (dvec[2] < -ball->len) dvec[2] += ball->len; - else dvec[2] = 0.0; - break; case MB_TUBE: if (dvec[0] > ball->expx) dvec[0] -= ball->expx; else if (dvec[0] < -ball->expx) dvec[0] += ball->expx; @@ -683,6 +671,24 @@ static float densfunc(MetaElem *ball, float x, float y, float z) else if (dvec[2] < -ball->expz) dvec[2] += ball->expz; else dvec[2] = 0.0; break; + + /* *** deprecated, could be removed?, do-versioned at least *** */ + case MB_TUBEX: + if (dvec[0] > ball->len) dvec[0] -= ball->len; + else if (dvec[0] < -ball->len) dvec[0] += ball->len; + else dvec[0] = 0.0; + break; + case MB_TUBEY: + if (dvec[1] > ball->len) dvec[1] -= ball->len; + else if (dvec[1] < -ball->len) dvec[1] += ball->len; + else dvec[1] = 0.0; + break; + case MB_TUBEZ: + if (dvec[2] > ball->len) dvec[2] -= ball->len; + else if (dvec[2] < -ball->len) dvec[2] += ball->len; + else dvec[2] = 0.0; + break; + /* *** end deprecated *** */ } dist2 = 1.0f - (len_v3(dvec) / ball->rad2); @@ -771,27 +777,27 @@ static float metaball(float x, float y, float z) float dens = 0; int a; - if (totelem > 1) { - node = find_metaball_octal_node(metaball_tree->first, x, y, z, metaball_tree->depth); + if (G_mb.totelem > 1) { + node = find_metaball_octal_node(G_mb.metaball_tree->first, x, y, z, G_mb.metaball_tree->depth); if (node) { for (ml_p = node->elems.first; ml_p; ml_p = ml_p->next) { dens += densfunc(ml_p->ml, x, y, z); } - dens += -0.5f * (metaball_tree->pos - node->pos); - dens += 0.5f * (metaball_tree->neg - node->neg); + dens += -0.5f * (G_mb.metaball_tree->pos - node->pos); + dens += 0.5f * (G_mb.metaball_tree->neg - node->neg); } else { - for (a = 0; a < totelem; a++) { - dens += densfunc(mainb[a], x, y, z); + for (a = 0; a < G_mb.totelem; a++) { + dens += densfunc(G_mb.mainb[a], x, y, z); } } } else { - dens += densfunc(mainb[0], x, y, z); + dens += densfunc(G_mb.mainb[0], x, y, z); } - return thresh - dens; + return G_mb.thresh - dens; } /* ******************************************** */ @@ -1493,7 +1499,7 @@ static void find_first_points(PROCESS *mbproc, MetaBall *mb, int a) MetaElem *ml; float f = 0.0f; - ml = mainb[a]; + ml = G_mb.mainb[a]; f = 1.0 - (mb->thresh / ml->s); /* Skip, when Stiffness of MetaElement is too small ... MetaElement can't be @@ -1619,7 +1625,7 @@ static void polygonize(PROCESS *mbproc, MetaBall *mb) mbproc->edges = MEM_callocN(2 * HASHSIZE * sizeof(EDGELIST *), "mbproc->edges"); makecubetable(); - for (a = 0; a < totelem; a++) { + for (a = 0; a < G_mb.totelem; a++) { /* try to find 8 points on the surface for each MetaElem */ find_first_points(mbproc, mb, a); @@ -1712,7 +1718,7 @@ static float init_meta(Scene *scene, Object *ob) /* return totsize */ ml_count++; ml = ml->next; } - totelem -= ml_count; + G_mb.totelem -= ml_count; } else { while (ml) { @@ -1741,9 +1747,9 @@ static float init_meta(Scene *scene, Object *ob) /* return totsize */ 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)); + G_mb.mainb[a] = new_pgn_element(sizeof(MetaElem)); + *(G_mb.mainb[a]) = *ml; + G_mb.mainb[a]->bb = new_pgn_element(sizeof(BoundBox)); mat = new_pgn_element(4 * 4 * sizeof(float)); imat = new_pgn_element(4 * 4 * sizeof(float)); @@ -1756,70 +1762,70 @@ static float init_meta(Scene *scene, Object *ob) /* return totsize */ invert_m4_m4(imat, mat); - mainb[a]->rad2 = ml->rad * ml->rad; + G_mb.mainb[a]->rad2 = ml->rad * ml->rad; - mainb[a]->mat = (float *) mat; - mainb[a]->imat = (float *) imat; + G_mb.mainb[a]->mat = (float *) mat; + G_mb.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; + G_mb.mainb[a]->bb->vec[0][0] = -ml->expx; + G_mb.mainb[a]->bb->vec[0][1] = -ml->expy; + G_mb.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; + G_mb.mainb[a]->bb->vec[1][0] = ml->expx; + G_mb.mainb[a]->bb->vec[1][1] = -ml->expy; + G_mb.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; + G_mb.mainb[a]->bb->vec[2][0] = ml->expx; + G_mb.mainb[a]->bb->vec[2][1] = ml->expy; + G_mb.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; + G_mb.mainb[a]->bb->vec[3][0] = -ml->expx; + G_mb.mainb[a]->bb->vec[3][1] = ml->expy; + G_mb.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; + G_mb.mainb[a]->bb->vec[4][0] = -ml->expx; + G_mb.mainb[a]->bb->vec[4][1] = -ml->expy; + G_mb.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; + G_mb.mainb[a]->bb->vec[5][0] = ml->expx; + G_mb.mainb[a]->bb->vec[5][1] = -ml->expy; + G_mb.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; + G_mb.mainb[a]->bb->vec[6][0] = ml->expx; + G_mb.mainb[a]->bb->vec[6][1] = ml->expy; + G_mb.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; + G_mb.mainb[a]->bb->vec[7][0] = -ml->expx; + G_mb.mainb[a]->bb->vec[7][1] = ml->expy; + G_mb.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]); + mul_m4_v3((float (*)[4])mat, G_mb.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]; + if (G_mb.mainb[a]->bb->vec[i][0] > max_x) max_x = G_mb.mainb[a]->bb->vec[i][0]; + if (G_mb.mainb[a]->bb->vec[i][1] > max_y) max_y = G_mb.mainb[a]->bb->vec[i][1]; + if (G_mb.mainb[a]->bb->vec[i][2] > max_z) max_z = G_mb.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]; + if (G_mb.mainb[a]->bb->vec[i][0] < min_x) min_x = G_mb.mainb[a]->bb->vec[i][0]; + if (G_mb.mainb[a]->bb->vec[i][1] < min_y) min_y = G_mb.mainb[a]->bb->vec[i][1]; + if (G_mb.mainb[a]->bb->vec[i][2] < min_z) min_z = G_mb.mainb[a]->bb->vec[i][2]; } /* 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; + G_mb.mainb[a]->bb->vec[0][0] = min_x - ml->rad; + G_mb.mainb[a]->bb->vec[0][1] = min_y - ml->rad; + G_mb.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; + G_mb.mainb[a]->bb->vec[6][0] = max_x + ml->rad; + G_mb.mainb[a]->bb->vec[6][1] = max_y + ml->rad; + G_mb.mainb[a]->bb->vec[6][2] = max_z + ml->rad; a++; } @@ -1832,13 +1838,13 @@ static float init_meta(Scene *scene, Object *ob) /* return totsize */ /* totsize (= 'manhattan' radius) */ totsize = 0.0; - for (a = 0; a < totelem; a++) { + for (a = 0; a < G_mb.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] = G_mb.mainb[a]->x + G_mb.mainb[a]->rad + G_mb.mainb[a]->expx; + vec[1] = G_mb.mainb[a]->y + G_mb.mainb[a]->rad + G_mb.mainb[a]->expy; + vec[2] = G_mb.mainb[a]->z + G_mb.mainb[a]->rad + G_mb.mainb[a]->expz; - calc_mballco(mainb[a], vec); + calc_mballco(G_mb.mainb[a], vec); size = fabsf(vec[0]); if (size > totsize) totsize = size; @@ -1847,11 +1853,11 @@ static float init_meta(Scene *scene, Object *ob) /* return totsize */ 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] = G_mb.mainb[a]->x - G_mb.mainb[a]->rad; + vec[1] = G_mb.mainb[a]->y - G_mb.mainb[a]->rad; + vec[2] = G_mb.mainb[a]->z - G_mb.mainb[a]->rad; - calc_mballco(mainb[a], vec); + calc_mballco(G_mb.mainb[a], vec); size = fabsf(vec[0]); if (size > totsize) totsize = size; @@ -1861,8 +1867,8 @@ static float init_meta(Scene *scene, Object *ob) /* return totsize */ if (size > totsize) totsize = size; } - for (a = 0; a < totelem; a++) { - thresh += densfunc(mainb[a], 2.0f * totsize, 2.0f * totsize, 2.0f * totsize); + for (a = 0; a < G_mb.totelem; a++) { + G_mb.thresh += densfunc(G_mb.mainb[a], 2.0f * totsize, 2.0f * totsize, 2.0f * totsize); } return totsize; @@ -2178,13 +2184,13 @@ 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"); + G_mb.metaball_tree = MEM_mallocN(sizeof(octal_tree), "metaball_octal_tree"); + G_mb.metaball_tree->first = node = MEM_mallocN(sizeof(octal_node), "metaball_octal_node"); /* maximal depth of octree */ - metaball_tree->depth = depth; + G_mb.metaball_tree->depth = depth; - metaball_tree->neg = node->neg = 0; - metaball_tree->pos = node->pos = 0; + G_mb.metaball_tree->neg = node->neg = 0; + G_mb.metaball_tree->pos = node->pos = 0; node->elems.first = NULL; node->elems.last = NULL; @@ -2197,26 +2203,26 @@ static void init_metaball_octal_tree(int depth) 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]; + for (a = 0; a < G_mb.totelem; a++) { + if (G_mb.mainb[a]->bb->vec[0][0] < node->x_min) node->x_min = G_mb.mainb[a]->bb->vec[0][0]; + if (G_mb.mainb[a]->bb->vec[0][1] < node->y_min) node->y_min = G_mb.mainb[a]->bb->vec[0][1]; + if (G_mb.mainb[a]->bb->vec[0][2] < node->z_min) node->z_min = G_mb.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]; + if (G_mb.mainb[a]->bb->vec[6][0] > node->x_max) node->x_max = G_mb.mainb[a]->bb->vec[6][0]; + if (G_mb.mainb[a]->bb->vec[6][1] > node->y_max) node->y_max = G_mb.mainb[a]->bb->vec[6][1]; + if (G_mb.mainb[a]->bb->vec[6][2] > node->z_max) node->z_max = G_mb.mainb[a]->bb->vec[6][2]; ml_p = MEM_mallocN(sizeof(ml_pointer), "ml_pointer"); - ml_p->ml = mainb[a]; + ml_p->ml = G_mb.mainb[a]; BLI_addtail(&node->elems, ml_p); - if ((mainb[a]->flag & MB_NEGATIVE) == 0) { + if ((G_mb.mainb[a]->flag & MB_NEGATIVE) == 0) { /* number of positive MetaElem in scene */ - metaball_tree->pos++; + G_mb.metaball_tree->pos++; } else { /* number of negative MetaElem in scene */ - metaball_tree->neg++; + G_mb.metaball_tree->neg++; } } @@ -2226,7 +2232,7 @@ static void init_metaball_octal_tree(int depth) 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); + subdivide_metaball_octal_node(node, size[0], size[1], size[2], G_mb.metaball_tree->depth); } void BKE_mball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) @@ -2239,48 +2245,48 @@ void BKE_mball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) mb = ob->data; - if (totelem == 0) return; + if (G_mb.totelem == 0) return; if ((G.is_rendering == FALSE) && (mb->flag == MB_UPDATE_NEVER)) return; if (G.moving && mb->flag == MB_UPDATE_FAST) return; curindex = totindex = 0; indices = NULL; - thresh = mb->thresh; + G_mb.thresh = mb->thresh; /* total number of MetaElems (totelem) is precomputed in find_basis_mball() function */ - mainb = MEM_mallocN(sizeof(void *) * totelem, "mainb"); + G_mb.mainb = MEM_mallocN(sizeof(void *) * G_mb.totelem, "mainb"); /* initialize all mainb (MetaElems) */ totsize = init_meta(scene, ob); - if (metaball_tree) { - free_metaball_octal_node(metaball_tree->first); - MEM_freeN(metaball_tree); - metaball_tree = NULL; + if (G_mb.metaball_tree) { + free_metaball_octal_node(G_mb.metaball_tree->first); + MEM_freeN(G_mb.metaball_tree); + G_mb.metaball_tree = NULL; } /* if scene includes more then one MetaElem, then octal tree optimization 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 > 512) && (totelem <= 1024)) init_metaball_octal_tree(4); - if (totelem > 1024) init_metaball_octal_tree(5); + if ((G_mb.totelem > 1) && (G_mb.totelem <= 64)) init_metaball_octal_tree(1); + if ((G_mb.totelem > 64) && (G_mb.totelem <= 128)) init_metaball_octal_tree(2); + if ((G_mb.totelem > 128) && (G_mb.totelem <= 512)) init_metaball_octal_tree(3); + if ((G_mb.totelem > 512) && (G_mb.totelem <= 1024)) init_metaball_octal_tree(4); + if (G_mb.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 (G_mb.metaball_tree) { + if (ob->size[0] <= 0.00001f * (G_mb.metaball_tree->first->x_max - G_mb.metaball_tree->first->x_min) || + ob->size[1] <= 0.00001f * (G_mb.metaball_tree->first->y_max - G_mb.metaball_tree->first->y_min) || + ob->size[2] <= 0.00001f * (G_mb.metaball_tree->first->z_max - G_mb.metaball_tree->first->z_min)) { new_pgn_element(-1); /* free values created by init_meta */ - MEM_freeN(mainb); + MEM_freeN(G_mb.mainb); /* free tree */ - free_metaball_octal_node(metaball_tree->first); - MEM_freeN(metaball_tree); - metaball_tree = NULL; + free_metaball_octal_node(G_mb.metaball_tree->first); + MEM_freeN(G_mb.metaball_tree); + G_mb.metaball_tree = NULL; return; } @@ -2304,13 +2310,13 @@ void BKE_mball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) polygonize(&mbproc, mb); - MEM_freeN(mainb); + MEM_freeN(G_mb.mainb); /* free octal tree */ - if (totelem > 1) { - free_metaball_octal_node(metaball_tree->first); - MEM_freeN(metaball_tree); - metaball_tree = NULL; + if (G_mb.totelem > 1) { + free_metaball_octal_node(G_mb.metaball_tree->first); + MEM_freeN(G_mb.metaball_tree); + G_mb.metaball_tree = NULL; } if (curindex) { diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 4c23a370a5d..268234c7e73 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -69,7 +69,6 @@ #include "BKE_library.h" #include "BKE_global.h" #include "BKE_main.h" -#include "BKE_utildefines.h" #include "BKE_movieclip.h" #include "BKE_image.h" /* openanim */ #include "BKE_tracking.h" @@ -1002,6 +1001,14 @@ void BKE_movieclip_get_size(MovieClip *clip, MovieClipUser *user, int *width, in IMB_freeImBuf(ibuf); } } +void BKE_movieclip_get_size_fl(MovieClip *clip, MovieClipUser *user, float size[2]) +{ + int width, height; + BKE_movieclip_get_size(clip, user, &width, &height); + + size[0] = (float)width; + size[1] = (float)height; +} int BKE_movieclip_get_duration(MovieClip *clip) { @@ -1012,9 +1019,9 @@ int BKE_movieclip_get_duration(MovieClip *clip) return clip->len; } -void BKE_movieclip_aspect(MovieClip *clip, float *aspx, float *aspy) +void BKE_movieclip_get_aspect(MovieClip *clip, float *aspx, float *aspy) { - *aspx = *aspy = 1.0; + *aspx = 1.0; /* x is always 1 */ *aspy = clip->aspy / clip->aspx / clip->tracking.camera.pixel_aspect; diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index c283db94103..ade418e409f 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -58,8 +58,6 @@ #include "BKE_library.h" #include "BKE_main.h" #include "BKE_node.h" -#include "BKE_utildefines.h" -#include "BKE_utildefines.h" #include "RNA_access.h" @@ -2265,6 +2263,7 @@ static void registerShaderNodes(bNodeTreeType *ttype) register_node_type_sh_tex_gradient(ttype); register_node_type_sh_tex_magic(ttype); register_node_type_sh_tex_checker(ttype); + register_node_type_sh_tex_brick(ttype); } static void registerTextureNodes(bNodeTreeType *ttype) diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 5bb0e0929ff..f8f2ae86f1d 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -2710,7 +2710,7 @@ void BKE_object_handle_update(Scene *scene, Object *ob) 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) : + mini(scene->physics_settings.quick_cache_step, pid->cache->step) : pid->cache->step; } } diff --git a/source/blender/blenkernel/intern/object_deform.c b/source/blender/blenkernel/intern/object_deform.c new file mode 100644 index 00000000000..7f9578250f2 --- /dev/null +++ b/source/blender/blenkernel/intern/object_deform.c @@ -0,0 +1,156 @@ +/* + * ***** 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. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/blenkernel/intern/object_deform.c + * \ingroup bke + */ + +#include <stdlib.h> +#include <string.h> + +#include "MEM_guardedalloc.h" + +#include "BLI_utildefines.h" +#include "BLI_ghash.h" + +#include "BKE_action.h" +#include "BKE_object_deform.h" /* own include */ +#include "BKE_object.h" +#include "BKE_modifier.h" + +#include "DNA_armature_types.h" +#include "DNA_modifier_types.h" +#include "DNA_object_types.h" + +/* --- functions for getting vgroup aligned maps --- */ + +/** + * gets the status of "flag" for each bDeformGroup + * in ob->defbase and returns an array containing them + */ +char *BKE_objdef_lock_flags_get(Object *ob, const int defbase_tot) +{ + char is_locked = FALSE; + int i; + //int defbase_tot = BLI_countlist(&ob->defbase); + char *lock_flags = MEM_mallocN(defbase_tot * sizeof(char), "defflags"); + bDeformGroup *defgroup; + + for (i = 0, defgroup = ob->defbase.first; i < defbase_tot && defgroup; defgroup = defgroup->next, i++) { + lock_flags[i] = ((defgroup->flag & DG_LOCK_WEIGHT) != 0); + is_locked |= lock_flags[i]; + } + if (is_locked) { + return lock_flags; + } + + MEM_freeN(lock_flags); + return NULL; +} + +char *BKE_objdef_validmap_get(Object *ob, const int defbase_tot) +{ + bDeformGroup *dg; + ModifierData *md; + char *vgroup_validmap; + GHash *gh; + int i, step1 = 1; + //int defbase_tot = BLI_countlist(&ob->defbase); + + if (ob->defbase.first == NULL) { + return NULL; + } + + gh = BLI_ghash_str_new("BKE_objdef_validmap_get gh"); + + /* add all names to a hash table */ + for (dg = ob->defbase.first; dg; dg = dg->next) { + BLI_ghash_insert(gh, dg->name, NULL); + } + + BLI_assert(BLI_ghash_size(gh) == defbase_tot); + + /* now loop through the armature modifiers and identify deform bones */ + for (md = ob->modifiers.first; md; md = !md->next && step1 ? (step1 = 0), modifiers_getVirtualModifierList(ob) : md->next) { + if (!(md->mode & (eModifierMode_Realtime | eModifierMode_Virtual))) + continue; + + if (md->type == eModifierType_Armature) { + ArmatureModifierData *amd = (ArmatureModifierData *) md; + + if (amd->object && amd->object->pose) { + bPose *pose = amd->object->pose; + bPoseChannel *chan; + + for (chan = pose->chanbase.first; chan; chan = chan->next) { + if (chan->bone->flag & BONE_NO_DEFORM) + continue; + + if (BLI_ghash_remove(gh, chan->name, NULL, NULL)) { + BLI_ghash_insert(gh, chan->name, SET_INT_IN_POINTER(1)); + } + } + } + } + } + + vgroup_validmap = MEM_mallocN(defbase_tot, "wpaint valid map"); + + /* add all names to a hash table */ + for (dg = ob->defbase.first, i = 0; dg; dg = dg->next, i++) { + vgroup_validmap[i] = (BLI_ghash_lookup(gh, dg->name) != NULL); + } + + BLI_assert(i == BLI_ghash_size(gh)); + + BLI_ghash_free(gh, NULL, NULL); + + return vgroup_validmap; +} + +/* Returns total selected vgroups, + * wpi.defbase_sel is assumed malloc'd, all values are set */ +char *BKE_objdef_selected_get(Object *ob, int defbase_tot, int *r_dg_flags_sel_tot) +{ + char *dg_selection = MEM_mallocN(defbase_tot * sizeof(char), __func__); + bDeformGroup *defgroup; + unsigned int i; + Object *armob = BKE_object_pose_armature_get(ob); + (*r_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 = BKE_pose_channel_find_name(pose, defgroup->name); + if (pchan && (pchan->bone->flag & BONE_SELECTED)) { + dg_selection[i] = TRUE; + (*r_dg_flags_sel_tot) += 1; + } + else { + dg_selection[i] = FALSE; + } + } + } + else { + memset(dg_selection, FALSE, sizeof(char) * defbase_tot); + } + + return dg_selection; +} diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c index 66b0cff691e..b862a824d50 100644 --- a/source/blender/blenkernel/intern/ocean.c +++ b/source/blender/blenkernel/intern/ocean.c @@ -37,8 +37,6 @@ #include "BKE_image.h" #include "BKE_ocean.h" -#include "BKE_utildefines.h" - #include "BKE_global.h" // XXX TESTING #include "BLI_math_base.h" diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c index 9787a5025f7..03342d0f6d1 100644 --- a/source/blender/blenkernel/intern/packedFile.c +++ b/source/blender/blenkernel/intern/packedFile.c @@ -57,7 +57,6 @@ #include "BKE_packedFile.h" #include "BKE_report.h" #include "BKE_sound.h" -#include "BKE_utildefines.h" #ifdef _WIN32 #define open _open diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index e990f461d4c..780528f4a0d 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -69,7 +69,6 @@ #include "BKE_scene.h" #include "BKE_smoke.h" #include "BKE_softbody.h" -#include "BKE_utildefines.h" #include "BIK_api.h" @@ -1030,7 +1029,8 @@ void BKE_ptcache_ids_from_object(ListBase *lb, Object *ob, Scene *scene, int dup if (scene && (duplis-- > 0) && (ob->transflag & OB_DUPLI)) { ListBase *lb_dupli_ob; - if ((lb_dupli_ob=object_duplilist(scene, ob))) { + /* don't update the dupli groups, we only wan't their pid's */ + if ((lb_dupli_ob = object_duplilist_ex(scene, ob, FALSE))) { DupliObject *dob; for (dob= lb_dupli_ob->first; dob; dob= dob->next) { if (dob->ob != ob) { /* avoids recursive loops with dupliframes: bug 22988 */ @@ -1067,8 +1067,9 @@ static int ptcache_path(PTCacheID *pid, char *filename) if (pid->cache->flag & PTCACHE_EXTERNAL) { strcpy(filename, pid->cache->path); - if (strncmp(filename, "//", 2)==0) + if (BLI_path_is_rel(filename)) { BLI_path_abs(filename, blendfilename); + } return BLI_add_slash(filename); /* new strlen() */ } diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c index c440d21f56d..7d9d2f02c06 100644 --- a/source/blender/blenkernel/intern/sca.c +++ b/source/blender/blenkernel/intern/sca.c @@ -44,7 +44,6 @@ #include "DNA_object_types.h" #include "BLI_blenlib.h" -#include "BKE_utildefines.h" #include "BKE_global.h" #include "BKE_main.h" #include "BKE_library.h" diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index d137393e698..4dbe0b6290c 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -49,7 +49,6 @@ #include "BKE_main.h" #include "BKE_sequencer.h" #include "BKE_texture.h" -#include "BKE_utildefines.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" diff --git a/source/blender/blenkernel/intern/seqmodifier.c b/source/blender/blenkernel/intern/seqmodifier.c index 70f27db0f74..6028b40756d 100644 --- a/source/blender/blenkernel/intern/seqmodifier.c +++ b/source/blender/blenkernel/intern/seqmodifier.c @@ -43,7 +43,6 @@ #include "BKE_colortools.h" #include "BKE_sequencer.h" -#include "BKE_utildefines.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" @@ -155,14 +154,11 @@ void colorBalance_init_data(SequenceModifierData *smd) } } -ImBuf *colorBalance_apply(SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask) +void colorBalance_apply(SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask) { ColorBalanceModifierData *cbmd = (ColorBalanceModifierData *) smd; - ImBuf *ibuf_new = IMB_dupImBuf(ibuf); - BKE_sequencer_color_balance_apply(&cbmd->color_balance, ibuf_new, cbmd->color_multiply, FALSE, mask); - - return ibuf_new; + BKE_sequencer_color_balance_apply(&cbmd->color_balance, ibuf, cbmd->color_multiply, FALSE, mask); } static SequenceModifierTypeInfo seqModifier_ColorBalance = { @@ -253,10 +249,9 @@ void curves_apply_threaded(int width, int height, unsigned char *rect, float *re } } -ImBuf *curves_apply(struct SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask) +void curves_apply(struct SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask) { CurvesModifierData *cmd = (CurvesModifierData *) smd; - ImBuf *ibuf_new = IMB_dupImBuf(ibuf); float black[3] = {0.0f, 0.0f, 0.0f}; float white[3] = {1.0f, 1.0f, 1.0f}; @@ -266,11 +261,9 @@ ImBuf *curves_apply(struct SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask) curvemapping_premultiply(&cmd->curve_mapping, 0); curvemapping_set_black_white(&cmd->curve_mapping, black, white); - modifier_apply_threaded(ibuf_new, mask, curves_apply_threaded, &cmd->curve_mapping); + modifier_apply_threaded(ibuf, mask, curves_apply_threaded, &cmd->curve_mapping); curvemapping_premultiply(&cmd->curve_mapping, 1); - - return ibuf_new; } static SequenceModifierTypeInfo seqModifier_Curves = { @@ -372,16 +365,13 @@ void hue_correct_apply_threaded(int width, int height, unsigned char *rect, floa } } -ImBuf *hue_correct_apply(struct SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask) +void hue_correct_apply(struct SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask) { HueCorrectModifierData *hcmd = (HueCorrectModifierData *) smd; - ImBuf *ibuf_new = IMB_dupImBuf(ibuf); curvemapping_initialize(&hcmd->curve_mapping); - modifier_apply_threaded(ibuf_new, mask, hue_correct_apply_threaded, &hcmd->curve_mapping); - - return ibuf_new; + modifier_apply_threaded(ibuf, mask, hue_correct_apply_threaded, &hcmd->curve_mapping); } static SequenceModifierTypeInfo seqModifier_HueCorrect = { @@ -470,18 +460,15 @@ void brightcontrast_apply_threaded(int width, int height, unsigned char *rect, f } } -ImBuf *brightcontrast_apply(struct SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask) +void brightcontrast_apply(struct SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask) { BrightContrastModifierData *bcmd = (BrightContrastModifierData *) smd; BrightContrastThreadData data; - ImBuf *ibuf_new = IMB_dupImBuf(ibuf); data.bright = bcmd->bright; data.contrast = bcmd->contrast; - modifier_apply_threaded(ibuf_new, mask, brightcontrast_apply_threaded, &data); - - return ibuf_new; + modifier_apply_threaded(ibuf, mask, brightcontrast_apply_threaded, &data); } static SequenceModifierTypeInfo seqModifier_BrightContrast = { @@ -596,7 +583,6 @@ ImBuf *BKE_sequence_modifier_apply_stack(SeqRenderData context, Sequence *seq, I for (smd = seq->modifiers.first; smd; smd = smd->next) { SequenceModifierTypeInfo *smti = BKE_sequence_modifier_type_info_get(smd->type); - ImBuf *ibuf_new; /* could happen if modifier is being removed or not exists in current version of blender */ if (!smti) @@ -612,12 +598,7 @@ ImBuf *BKE_sequence_modifier_apply_stack(SeqRenderData context, Sequence *seq, I if (processed_ibuf == ibuf) processed_ibuf = IMB_dupImBuf(ibuf); - ibuf_new = smti->apply(smd, processed_ibuf, mask); - - if (ibuf_new != processed_ibuf) { - IMB_freeImBuf(processed_ibuf); - processed_ibuf = ibuf_new; - } + smti->apply(smd, processed_ibuf, mask); if (mask) IMB_freeImBuf(mask); diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 8aab622148b..2596bf57f05 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -62,7 +62,6 @@ #include "BKE_fcurve.h" #include "BKE_scene.h" #include "BKE_mask.h" -#include "BKE_utildefines.h" #include "RNA_access.h" @@ -166,14 +165,12 @@ static void seq_free_strip(Strip *strip) if (strip->transform) { MEM_freeN(strip->transform); } - if (strip->color_balance) { - MEM_freeN(strip->color_balance); - } MEM_freeN(strip); } -void BKE_sequence_free(Scene *scene, Sequence *seq) +/* only give option to skip cache locally (static func) */ +static void BKE_sequence_free_ex(Scene *scene, Sequence *seq, const int do_cache) { if (seq->strip) seq_free_strip(seq->strip); @@ -209,21 +206,37 @@ void BKE_sequence_free(Scene *scene, Sequence *seq) /* free cached data used by this strip, * also invalidate cache for all dependent sequences + * + * be _very_ careful here, invalidating cache loops over the scene sequences and + * assumes the listbase is valid for all strips, this may not be the case if lists are being freed. + * this is optional BKE_sequence_invalidate_cache */ - BKE_sequence_invalidate_cache(scene, seq); + if (do_cache) { + if (scene) { + BKE_sequence_invalidate_cache(scene, seq); + } + } MEM_freeN(seq); } +void BKE_sequence_free(Scene *scene, Sequence *seq) +{ + BKE_sequence_free_ex(scene, seq, TRUE); +} + +/* cache must be freed before calling this function + * since it leaves the seqbase in an invalid state */ static void seq_free_sequence_recurse(Scene *scene, Sequence *seq) { - Sequence *iseq; + Sequence *iseq, *iseq_next; - for (iseq = seq->seqbase.first; iseq; iseq = iseq->next) { + for (iseq = seq->seqbase.first; iseq; iseq = iseq_next) { + iseq_next = iseq->next; seq_free_sequence_recurse(scene, iseq); } - BKE_sequence_free(scene, seq); + BKE_sequence_free_ex(scene, seq, FALSE); } @@ -244,7 +257,7 @@ static void seq_free_clipboard_recursive(Sequence *seq_parent) seq_free_clipboard_recursive(seq); } - BKE_sequence_free(NULL, seq_parent); + BKE_sequence_free_ex(NULL, seq_parent, FALSE); } void BKE_sequencer_free_clipboard(void) @@ -273,22 +286,22 @@ Editing *BKE_sequencer_editing_ensure(Scene *scene) void BKE_sequencer_editing_free(Scene *scene) { Editing *ed = scene->ed; - MetaStack *ms; Sequence *seq; if (ed == NULL) return; + /* this may not be the active scene!, could be smarter about this */ + BKE_sequencer_cache_cleanup(); + SEQ_BEGIN (ed, seq) { - BKE_sequence_free(scene, seq); + /* handle cache freeing above */ + BKE_sequence_free_ex(scene, seq, FALSE); } SEQ_END - while ((ms = ed->metastack.first)) { - BLI_remlink(&ed->metastack, ms); - MEM_freeN(ms); - } + BLI_freelistN(&ed->metastack); MEM_freeN(ed); @@ -1671,26 +1684,6 @@ void BKE_sequencer_color_balance_apply(StripColorBalance *cb, ImBuf *ibuf, float imb_freerectImBuf(ibuf); } -static void sequence_color_balance(SeqRenderData context, Sequence *seq, ImBuf *ibuf, float mul, int cfra) -{ - StripColorBalance *cb = seq->strip->color_balance; - ImBuf *mask_input = NULL; - short make_float = seq->flag & SEQ_MAKE_FLOAT; - - if (seq->mask_sequence) { - if (seq->mask_sequence != seq && !BKE_sequence_check_depend(seq, seq->mask_sequence)) { - int make_float = ibuf->rect_float != NULL; - - mask_input = BKE_sequencer_render_mask_input(context, SEQUENCE_MASK_INPUT_STRIP, seq->mask_sequence, NULL, cfra, make_float); - } - } - - BKE_sequencer_color_balance_apply(cb, ibuf, mul, make_float, mask_input); - - if (mask_input) - IMB_freeImBuf(mask_input); -} - /* * input preprocessing for SEQ_TYPE_IMAGE, SEQ_TYPE_MOVIE, SEQ_TYPE_MOVIECLIP and SEQ_TYPE_SCENE * @@ -1713,9 +1706,7 @@ int BKE_sequencer_input_have_to_preprocess(SeqRenderData UNUSED(context), Sequen { float mul; - if (seq->flag & (SEQ_FILTERY | SEQ_USE_CROP | SEQ_USE_TRANSFORM | SEQ_FLIPX | - SEQ_FLIPY | SEQ_USE_COLOR_BALANCE | SEQ_MAKE_PREMUL)) - { + if (seq->flag & (SEQ_FILTERY | SEQ_USE_CROP | SEQ_USE_TRANSFORM | SEQ_FLIPX | SEQ_FLIPY | SEQ_MAKE_PREMUL)) { return TRUE; } @@ -1834,11 +1825,6 @@ static ImBuf *input_preprocess(SeqRenderData context, Sequence *seq, float cfra, mul *= seq->blend_opacity / 100.0f; } - if (seq->flag & SEQ_USE_COLOR_BALANCE && seq->strip->color_balance) { - sequence_color_balance(context, seq, ibuf, mul, cfra); - mul = 1.0; - } - if (seq->flag & SEQ_MAKE_FLOAT) { if (!ibuf->rect_float) IMB_float_from_rect_simple(ibuf); @@ -2171,7 +2157,7 @@ static ImBuf *seq_render_mask(SeqRenderData context, Mask *mask, float nr, short BKE_maskrasterize_handle_init(mr_handle, mask_temp, context.rectx, context.recty, TRUE, TRUE, TRUE); - BKE_mask_free(mask_temp); + BKE_mask_free_nolib(mask_temp); MEM_freeN(mask_temp); BKE_maskrasterize_buffer(mr_handle, context.rectx, context.recty, maskbuf); @@ -2962,13 +2948,18 @@ int BKE_sequence_check_depend(Sequence *seq, Sequence *cur) return TRUE; } -static void sequence_invalidate_cache(Scene *scene, Sequence *seq, int invalidate_preprocess) +static void sequence_invalidate_cache(Scene *scene, Sequence *seq, int invalidate_self, int invalidate_preprocess) { Editing *ed = scene->ed; Sequence *cur; /* invalidate cache for current sequence */ - BKE_sequencer_cache_cleanup_sequence(seq); + if (invalidate_self) + BKE_sequencer_cache_cleanup_sequence(seq); + + /* if invalidation is invoked from sequence free routine, effectdata would be NULL here */ + if (seq->effectdata && seq->type == SEQ_TYPE_SPEED) + BKE_sequence_effect_speed_rebuild_map(scene, seq, TRUE); if (invalidate_preprocess) BKE_sequencer_preprocessed_cache_cleanup_sequence(seq); @@ -2989,54 +2980,40 @@ static void sequence_invalidate_cache(Scene *scene, Sequence *seq, int invalidat void BKE_sequence_invalidate_cache(Scene *scene, Sequence *seq) { - sequence_invalidate_cache(scene, seq, TRUE); + sequence_invalidate_cache(scene, seq, TRUE, TRUE); +} + +void BKE_sequence_invalidate_deendent(Scene *scene, Sequence *seq) +{ + sequence_invalidate_cache(scene, seq, FALSE, TRUE); } void BKE_sequence_invalidate_cache_for_modifier(Scene *scene, Sequence *seq) { - sequence_invalidate_cache(scene, seq, FALSE); + sequence_invalidate_cache(scene, seq, TRUE, FALSE); } -void BKE_sequencer_free_imbuf(Scene *scene, ListBase *seqbase, int check_mem_usage, int keep_file_handles) +void BKE_sequencer_free_imbuf(Scene *scene, ListBase *seqbase, int for_render) { Sequence *seq; - if (check_mem_usage) { - /* Let the cache limitor take care of this (schlaile) */ - /* While render let's keep all memory available for render - * (ton) - * At least if free memory is tight... - * This can make a big difference in encoding speed - * (it is around 4 times(!) faster, if we do not waste time - * on freeing _all_ buffers every time on long timelines...) - * (schlaile) - */ - - uintptr_t mem_in_use; - uintptr_t mmap_in_use; - uintptr_t max; - - mem_in_use = MEM_get_memory_in_use(); - mmap_in_use = MEM_get_mapped_memory_in_use(); - max = MEM_CacheLimiter_get_maximum(); - - if (max == 0 || mem_in_use + mmap_in_use <= max) { - return; - } - } - BKE_sequencer_cache_cleanup(); - + for (seq = seqbase->first; seq; seq = seq->next) { + if (for_render && CFRA >= seq->startdisp && CFRA <= seq->enddisp) { + continue; + } + if (seq->strip) { - if (seq->type == SEQ_TYPE_MOVIE && !keep_file_handles) + if (seq->type == SEQ_TYPE_MOVIE) { free_anim_seq(seq); + } if (seq->type == SEQ_TYPE_SPEED) { BKE_sequence_effect_speed_rebuild_map(scene, seq, 1); } } if (seq->type == SEQ_TYPE_META) { - BKE_sequencer_free_imbuf(scene, &seq->seqbase, FALSE, keep_file_handles); + BKE_sequencer_free_imbuf(scene, &seq->seqbase, for_render); } if (seq->type == SEQ_TYPE_SCENE) { /* FIXME: recurs downwards, @@ -4038,10 +4015,6 @@ static Sequence *seq_dupli(Scene *scene, Scene *scene_to, Sequence *seq, int dup seqn->strip->proxy->anim = NULL; } - if (seq->strip->color_balance) { - seqn->strip->color_balance = MEM_dupallocN(seq->strip->color_balance); - } - if (seqn->modifiers.first) { seqn->modifiers.first = seqn->modifiers.last = NULL; diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index f9399946570..9a8bcaabe0c 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -313,7 +313,7 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc) auxMesh = object_get_derived_final(calc->smd->auxTarget); if (!auxMesh) return; - space_transform_setup(&local2aux, calc->ob, calc->smd->auxTarget); + SPACE_TRANSFORM_SETUP(&local2aux, calc->ob, calc->smd->auxTarget); } //After sucessufuly build the trees, start projection vertexs @@ -500,7 +500,7 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM //TODO there might be several "bugs" on non-uniform scales matrixs //because it will no longer be nearest surface, not sphere projection //because space has been deformed - space_transform_setup(&calc.local2target, ob, smd->target); + SPACE_TRANSFORM_SETUP(&calc.local2target, ob, smd->target); //TODO: smd->keepDist is in global units.. must change to local calc.keepDist = smd->keepDist; diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 008dc332710..4a88bfbfdad 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -2291,7 +2291,7 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo /* done goal stuff */ /* gravitation */ - if (sb && scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) { + if (scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) { float gravity[3]; copy_v3_v3(gravity, scene->physics_settings.gravity); mul_v3_fl(gravity, sb_grav_force_scale(ob)*_final_mass(ob, bp)*sb->effector_weights->global_gravity); /* individual mass of node here */ diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 2462de07a18..f340bcb5b1e 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -50,7 +50,6 @@ # include "AUD_C-API.h" #endif -#include "BKE_utildefines.h" #include "BKE_global.h" #include "BKE_main.h" #include "BKE_sound.h" diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 7de5f97588b..787def5c20b 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -1684,7 +1684,8 @@ void txt_print_undo(Text *text) 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: { + case UNDO_INSERT_4: case UNDO_BS_4: case UNDO_DEL_4: + { unsigned int uc; char c[BLI_UTF8_MAX + 1]; size_t c_len; diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 2f54fe6cebd..ee904de4af6 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -56,7 +56,6 @@ #include "IMB_imbuf.h" -#include "BKE_utildefines.h" #include "BKE_global.h" #include "BKE_main.h" #include "BKE_ocean.h" diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 78e7dab045f..2ed9d992c3f 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -411,6 +411,8 @@ void BKE_tracking_clipboard_free(void) track = next_track; } + + tracking_clipboard.tracks.first = tracking_clipboard.tracks.last = NULL; } void BKE_tracking_clipboard_copy_tracks(MovieTracking *tracking, MovieTrackingObject *object) diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index dd71e43182e..434bfe19c1f 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -51,14 +51,14 @@ #include "BKE_node.h" #include "BKE_world.h" -void BKE_world_free(World *wrld) +void BKE_world_free_ex(World *wrld, int do_id_user) { MTex *mtex; int a; for (a = 0; a < MAX_MTEX; a++) { mtex = wrld->mtex[a]; - if (mtex && mtex->tex) mtex->tex->id.us--; + if (do_id_user && mtex && mtex->tex) mtex->tex->id.us--; if (mtex) MEM_freeN(mtex); } BKE_previewimg_free(&wrld->preview); @@ -67,7 +67,7 @@ void BKE_world_free(World *wrld) /* is no lib link block, but world extension */ if (wrld->nodetree) { - ntreeFreeTree(wrld->nodetree); + ntreeFreeTree_ex(wrld->nodetree, do_id_user); MEM_freeN(wrld->nodetree); } @@ -75,6 +75,10 @@ void BKE_world_free(World *wrld) wrld->id.icon_id = 0; } +void BKE_world_free(World *wrld) +{ + BKE_world_free_ex(wrld, TRUE); +} World *add_world(const char *name) { diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c index 3526058e12b..bd25ff8c6e6 100644 --- a/source/blender/blenkernel/intern/writeffmpeg.c +++ b/source/blender/blenkernel/intern/writeffmpeg.c @@ -177,58 +177,71 @@ static AVFrame *alloc_picture(int pix_fmt, int width, int height) static const char **get_file_extensions(int format) { switch (format) { - case FFMPEG_DV: { + case FFMPEG_DV: + { static const char *rv[] = { ".dv", NULL }; return rv; } - case FFMPEG_MPEG1: { + case FFMPEG_MPEG1: + { static const char *rv[] = { ".mpg", ".mpeg", NULL }; return rv; } - case FFMPEG_MPEG2: { + case FFMPEG_MPEG2: + { static const char *rv[] = { ".dvd", ".vob", ".mpg", ".mpeg", NULL }; return rv; } - case FFMPEG_MPEG4: { + case FFMPEG_MPEG4: + { static const char *rv[] = { ".mp4", ".mpg", ".mpeg", NULL }; return rv; } - case FFMPEG_AVI: { + case FFMPEG_AVI: + { static const char *rv[] = { ".avi", NULL }; return rv; } - case FFMPEG_MOV: { + case FFMPEG_MOV: + { static const char *rv[] = { ".mov", NULL }; return rv; } - case FFMPEG_H264: { + case FFMPEG_H264: + { /* FIXME: avi for now... */ static const char *rv[] = { ".avi", NULL }; return rv; } - case FFMPEG_XVID: { + case FFMPEG_XVID: + { /* FIXME: avi for now... */ static const char *rv[] = { ".avi", NULL }; return rv; } - case FFMPEG_FLV: { + case FFMPEG_FLV: + { static const char *rv[] = { ".flv", NULL }; return rv; } - case FFMPEG_MKV: { + case FFMPEG_MKV: + { static const char *rv[] = { ".mkv", NULL }; return rv; } - case FFMPEG_OGG: { + case FFMPEG_OGG: + { static const char *rv[] = { ".ogg", ".ogv", NULL }; return rv; } - case FFMPEG_MP3: { + case FFMPEG_MP3: + { static const char *rv[] = { ".mp3", NULL }; return rv; } - case FFMPEG_WAV: { + case FFMPEG_WAV: + { static const char *rv[] = { ".wav", NULL }; return rv; } @@ -946,6 +959,7 @@ int BKE_ffmpeg_start(struct Scene *scene, RenderData *rd, int rectx, int recty, } void BKE_ffmpeg_end(void); +static void end_ffmpeg_impl(int is_autosplit); #ifdef WITH_AUDASPACE static void write_audio_frames(double to_pts) @@ -978,7 +992,7 @@ int BKE_ffmpeg_append(RenderData *rd, int start_frame, int frame, int *pixels, i if (ffmpeg_autosplit) { if (avio_tell(outfile->pb) > FFMPEG_AUTOSPLIT_SIZE) { - BKE_ffmpeg_end(); + end_ffmpeg_impl(TRUE); ffmpeg_autosplit_count++; success &= start_ffmpeg_impl(rd, rectx, recty, reports); } @@ -991,7 +1005,7 @@ int BKE_ffmpeg_append(RenderData *rd, int start_frame, int frame, int *pixels, i return success; } -void BKE_ffmpeg_end(void) +static void end_ffmpeg_impl(int is_autosplit) { unsigned int i; @@ -1004,9 +1018,11 @@ void BKE_ffmpeg_end(void) #endif #ifdef WITH_AUDASPACE - if (audio_mixdown_device) { - AUD_closeReadDevice(audio_mixdown_device); - audio_mixdown_device = 0; + if (is_autosplit == FALSE) { + if (audio_mixdown_device) { + AUD_closeReadDevice(audio_mixdown_device); + audio_mixdown_device = 0; + } } #endif @@ -1069,6 +1085,11 @@ void BKE_ffmpeg_end(void) } } +void BKE_ffmpeg_end(void) +{ + end_ffmpeg_impl(FALSE); +} + /* properties */ void BKE_ffmpeg_property_del(RenderData *rd, void *type, void *prop_) diff --git a/source/blender/blenlib/BLI_endian_switch.h b/source/blender/blenlib/BLI_endian_switch.h new file mode 100644 index 00000000000..7017e7ba789 --- /dev/null +++ b/source/blender/blenlib/BLI_endian_switch.h @@ -0,0 +1,42 @@ +/* + * ***** 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. + * + * Contributor(s): Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BLI_ENDIAN_SWITCH_H__ +#define __BLI_ENDIAN_SWITCH_H__ + +/** \file BLI_endian_switch.h + * \ingroup bli + */ + +#include "BLI_endian_switch_inline.h" + +/* endian_switch.c */ +void BLI_endian_switch_int16_array(short *val, const int size); +void BLI_endian_switch_uint16_array(unsigned short *val, const int size); +void BLI_endian_switch_int32_array(int *val, const int size); +void BLI_endian_switch_uint32_array(unsigned int *val, const int size); +void BLI_endian_switch_float_array(float *val, const int size); +void BLI_endian_switch_int64_array(int64_t *val, const int size); +void BLI_endian_switch_uint64_array(uint64_t *val, const int size); +void BLI_endian_switch_double_array(double *val, const int size); + +#endif /* __BLI_ENDIAN_SWITCH_H__ */ diff --git a/source/blender/blenlib/BLI_endian_switch_inline.h b/source/blender/blenlib/BLI_endian_switch_inline.h new file mode 100644 index 00000000000..b747da3b738 --- /dev/null +++ b/source/blender/blenlib/BLI_endian_switch_inline.h @@ -0,0 +1,116 @@ +/* + * ***** 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. + * + * Contributor(s): Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/* only include from header */ +#ifndef __BLI_ENDIAN_SWITCH_H__ +# error "this file isnt to be directly included" +#endif + +#ifndef __BLI_ENDIAN_SWITCH_INLINE_H__ +#define __BLI_ENDIAN_SWITCH_INLINE_H__ + +/** \file blender/blenlib/BLI_endian_switch_inline.h + * \ingroup bli + */ + + +BLI_INLINE void BLI_endian_switch_int16(short *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; + p_i[0] = p_i[1]; + p_i[1] = s_i; +} + +BLI_INLINE void BLI_endian_switch_uint16(unsigned short *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; + p_i[0] = p_i[1]; + p_i[1] = s_i; +} + +BLI_INLINE void BLI_endian_switch_int32(int *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i; + s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i; +} + +BLI_INLINE void BLI_endian_switch_uint32(unsigned int *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i; + s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i; +} + +BLI_INLINE void BLI_endian_switch_float(float *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i; + s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i; +} + +BLI_INLINE void BLI_endian_switch_int64(int64_t *val) +{ + char *p_i = (char *)val; + char s_i; + + 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; +} + +BLI_INLINE void BLI_endian_switch_uint64(uint64_t *val) +{ + char *p_i = (char *)val; + char s_i; + + 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; +} + +BLI_INLINE void BLI_endian_switch_double(double *val) +{ + char *p_i = (char *)val; + char s_i; + + 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; +} + +#endif /* __BLI_ENDIAN_SWITCH_INLINE_H__ */ diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h index ac0ec6a52a7..e8d6336a994 100644 --- a/source/blender/blenlib/BLI_fileops.h +++ b/source/blender/blenlib/BLI_fileops.h @@ -91,6 +91,13 @@ int BLI_file_older(const char *file1, const char *file2); struct LinkNode *BLI_file_read_as_lines(const char *file); void BLI_file_free_lines(struct LinkNode *lines); +/* this weirdo pops up in two places ... */ +#if !defined(WIN32) +# ifndef O_BINARY +# define O_BINARY 0 +# endif +#endif + #ifdef __cplusplus } #endif diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h index 4a89776a52e..886ed6f495d 100644 --- a/source/blender/blenlib/BLI_math_base.h +++ b/source/blender/blenlib/BLI_math_base.h @@ -164,7 +164,10 @@ #endif #ifndef CLAMP -# define CLAMP(a, b, c) if ((a) < (b)) (a) = (b); else if ((a) > (c)) (a) = (c) +# define CLAMP(a, b, c) { \ + if ((a) < (b)) (a) = (b); \ + else if ((a) > (c)) (a) = (c); \ +} (void)0 #endif #ifdef __BLI_MATH_INLINE_H__ diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index eef8c9daaef..6c81ca3f0a9 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -81,6 +81,7 @@ MINLINE void copy_v4db_v4fl(double r[4], const float a[4]); /********************************* Arithmetic ********************************/ +MINLINE void add_v2_fl(float r[2], float f); MINLINE void add_v3_fl(float r[3], float f); MINLINE void add_v4_fl(float r[4], float f); MINLINE void add_v2_v2(float r[2], const float a[2]); diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 9b68406cc54..5e47adf25ef 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -97,7 +97,6 @@ typedef enum bli_rebase_state { } bli_rebase_state; int BLI_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const char *base_dir, const char *src_dir, const char *dest_dir); -#define BKE_rebase_path BLI_rebase_path /* remove after a 2012 */ char *BLI_last_slash(const char *string); int BLI_add_slash(char *string); @@ -154,6 +153,8 @@ int BLI_path_frame_range(char *path, int sta, int end, int digits); int BLI_path_cwd(char *path); void BLI_path_rel(char *file, const char *relfile); +int BLI_path_is_rel(const char *path); + #ifdef WIN32 # define BLI_path_cmp BLI_strcasecmp # define BLI_path_ncmp BLI_strncasecmp @@ -191,6 +192,14 @@ void BLI_system_temporary_dir(char *dir); void BLI_string_to_utf8(char *original, char *utf_8, const char *code); #endif +/* these values need to be hardcoded in structs, dna does not recognize defines */ +/* also defined in DNA_space_types.h */ +#ifndef FILE_MAXDIR +# define FILE_MAXDIR 768 +# define FILE_MAXFILE 256 +# define FILE_MAX 1024 +#endif + #ifdef __cplusplus } #endif diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 8a459b9b07c..29097a4c6c3 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -198,7 +198,10 @@ #define INPR(v1, v2) ( (v1)[0] * (v2)[0] + (v1)[1] * (v2)[1] + (v1)[2] * (v2)[2]) /* some misc stuff.... */ -#define CLAMP(a, b, c) if ((a) < (b)) (a) = (b); else if ((a) > (c)) (a) = (c) +#define CLAMP(a, b, c) { \ + if ((a) < (b)) (a) = (b); \ + else if ((a) > (c)) (a) = (c); \ +} (void)0 #define CLAMPIS(a, b, c) ((a) < (b) ? (b) : (a) > (c) ? (c) : (a)) #define CLAMPTEST(a, b, c) \ @@ -225,30 +228,6 @@ (item <= ARRAY_LAST_ITEM(arr_start, arr_dtype, elem_size, tot)) \ ) -/* This one rotates the bytes in an int64, int (32) and short (16) */ -#define SWITCH_INT64(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; \ - } (void)0 - -#define SWITCH_INT(a) { \ - char s_i, *p_i; \ - p_i = (char *)&(a); \ - s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i; \ - s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i; \ - } (void)0 - -#define SWITCH_SHORT(a) { \ - char s_i, *p_i; \ - p_i = (char *)&(a); \ - s_i = p_i[0]; p_i[0] = p_i[1]; p_i[1] = s_i; \ - } (void)0 - - /* Warning-free macros for storing ints in pointers. Use these _only_ * for storing an int in a pointer, not a pointer in an int (64bit)! */ #define SET_INT_IN_POINTER(i) ((void *)(intptr_t)(i)) diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index e4c4166953c..eef0a72d3b2 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -56,6 +56,7 @@ set(SRC intern/cpu.c intern/dynlib.c intern/edgehash.c + intern/endian_switch.c intern/fileops.c intern/fnmatch.c intern/freetypefont.c @@ -106,6 +107,8 @@ set(SRC BLI_dynlib.h BLI_dynstr.h BLI_edgehash.h + BLI_endian_switch.h + BLI_endian_switch_inline.h BLI_fileops.h BLI_fileops_types.h BLI_fnmatch.h @@ -145,6 +148,7 @@ set(SRC BLI_utildefines.h BLI_uvproject.h BLI_vfontdata.h + BLI_voronoi.h BLI_voxel.h BLI_winstuff.h PIL_time.h diff --git a/source/blender/blenlib/intern/BLI_memarena.c b/source/blender/blenlib/intern/BLI_memarena.c index 8c9993afee8..0ac6209fc95 100644 --- a/source/blender/blenlib/intern/BLI_memarena.c +++ b/source/blender/blenlib/intern/BLI_memarena.c @@ -46,7 +46,7 @@ struct MemArena { LinkNode *bufs; }; -MemArena *BLI_memarena_new(int bufsize, const char *name) +MemArena *BLI_memarena_new(const int bufsize, const char *name) { MemArena *ma = MEM_callocN(sizeof(*ma), "memarena"); ma->bufsize = bufsize; @@ -66,7 +66,7 @@ void BLI_memarena_use_malloc(MemArena *ma) ma->use_calloc = 0; } -void BLI_memarena_use_align(struct MemArena *ma, int align) +void BLI_memarena_use_align(struct MemArena *ma, const int align) { /* align should be a power of two */ ma->align = align; diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index c7e610edd9e..d98e63d88dd 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -45,7 +45,7 @@ #include <string.h> #include <stdlib.h> -/* note: copied from BKE_utildefines.h, don't use here because we're in BLI */ +/* note: copied from BLO_blend_defs.h, don't use here because we're in BLI */ #ifdef __BIG_ENDIAN__ /* Big Endian */ # define MAKE_ID(a, b, c, d) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d) ) diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index ccc45b465f4..5bafb75d9c0 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -79,7 +79,6 @@ #include "BKE_main.h" #include "BKE_report.h" #include "BKE_sequencer.h" -#include "BKE_utildefines.h" #include "BKE_image.h" /* so we can check the image's type */ static int checkMissingFiles_visit_cb(void *userdata, char *UNUSED(path_dst), const char *path_src) @@ -114,13 +113,13 @@ static int makeFilesRelative_visit_cb(void *userdata, char *path_dst, const char data->count_tot++; - if (strncmp(path_src, "//", 2) == 0) { + if (BLI_path_is_rel(path_src)) { return FALSE; /* already relative */ } else { strcpy(path_dst, path_src); BLI_path_rel(path_dst, data->basedir); - if (strncmp(path_dst, "//", 2) == 0) { + if (BLI_path_is_rel(path_dst)) { data->count_changed++; } else { @@ -156,13 +155,13 @@ static int makeFilesAbsolute_visit_cb(void *userdata, char *path_dst, const char data->count_tot++; - if (strncmp(path_src, "//", 2) != 0) { + if (BLI_path_is_rel(path_src) == FALSE) { return FALSE; /* already absolute */ } else { strcpy(path_dst, path_src); BLI_path_abs(path_dst, data->basedir); - if (strncmp(path_dst, "//", 2) != 0) { + if (BLI_path_is_rel(path_dst) == FALSE) { data->count_changed++; } else { @@ -604,7 +603,7 @@ int BLI_bpath_relocate_visitor(void *pathbase_v, char *path_dst, const char *pat const char *base_new = ((char **)pathbase_v)[0]; const char *base_old = ((char **)pathbase_v)[1]; - if (strncmp(base_old, "//", 2) == 0) { + if (BLI_path_is_rel(base_old)) { printf("%s: error, old base path '%s' is not absolute.\n", __func__, base_old); return FALSE; diff --git a/source/blender/blenlib/intern/endian_switch.c b/source/blender/blenlib/intern/endian_switch.c new file mode 100644 index 00000000000..b9b18136863 --- /dev/null +++ b/source/blender/blenlib/intern/endian_switch.c @@ -0,0 +1,118 @@ +/* + * ***** 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. + * + * Contributor(s): Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/blenlib/intern/endian_switch.c + * \ingroup bli + */ + +#include "BLO_sys_types.h" +#include "BLI_utildefines.h" +#include "BLI_endian_switch.h" + +void BLI_endian_switch_int16_array(short *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_int16(val--); + } + } +} + +void BLI_endian_switch_uint16_array(unsigned short *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_uint16(val--); + } + } +} + +void BLI_endian_switch_int32_array(int *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_int32(val--); + } + } +} + +void BLI_endian_switch_uint32_array(unsigned int *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_uint32(val--); + } + } +} + +void BLI_endian_switch_float_array(float *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_float(val--); + } + } +} + +void BLI_endian_switch_int64_array(int64_t *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_int64(val--); + } + } +} + +void BLI_endian_switch_uint64_array(uint64_t *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_uint64(val--); + } + } +} + + +void BLI_endian_switch_double_array(double *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_double(val--); + } + } +} diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index 7aa956a0548..f3107b565b9 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -60,8 +60,6 @@ #include "BLI_blenlib.h" #include "BLI_utildefines.h" -#include "BKE_utildefines.h" - #include "BLO_sys_types.h" // for intptr_t support diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 76f4f26b728..53e9a6b66cb 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -2229,7 +2229,7 @@ void interp_weights_poly_v3(float *w, float v[][3], const int n, const float co[ t2 = mean_value_half_tan_v3(co, vmid, vnext); len = len_v3v3(co, vmid); - w[i] = (t1 + t2) / len; + w[i] = (len != 0.0f)? (t1 + t2) / len: 0.0f; totweight += w[i]; } @@ -2257,7 +2257,7 @@ void interp_weights_poly_v2(float *w, float v[][2], const int n, const float co[ t2 = mean_value_half_tan_v2(co, vmid, vnext); len = len_v2v2(co, vmid); - w[i] = (t1 + t2) / len; + w[i] = (len != 0.0f)? (t1 + t2) / len: 0.0f; totweight += w[i]; } diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 177c099d647..0a8f57214d7 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -231,6 +231,13 @@ MINLINE void swap_v4_v4(float a[4], float b[4]) /********************************* Arithmetic ********************************/ +MINLINE void add_v2_fl(float r[2], float f) +{ + r[0] += f; + r[1] += f; +} + + MINLINE void add_v3_fl(float r[3], float f) { r[0] += f; diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 22b160ad0b4..a7a66718445 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -47,7 +47,6 @@ #include "BLI_string_utf8.h" #include "BLI_utildefines.h" -#include "BKE_utildefines.h" #include "BKE_blender.h" // BLENDER_VERSION #include "GHOST_Path-api.h" @@ -411,6 +410,11 @@ void BLI_cleanup_file(const char *relabase, char *dir) BLI_del_slash(dir); } +int BLI_path_is_rel(const char *path) +{ + return path[0] == '/' && path[1] == '/'; +} + void BLI_path_rel(char *file, const char *relfile) { char *lslash; @@ -418,10 +422,14 @@ void BLI_path_rel(char *file, const char *relfile) char res[FILE_MAX]; /* if file is already relative, bail out */ - if (file[0] == '/' && file[1] == '/') return; + if (BLI_path_is_rel(file)) { + return; + } /* also bail out if relative path is not set */ - if (relfile[0] == 0) return; + if (relfile[0] == '\0') { + return; + } #ifdef WIN32 if (BLI_strnlen(relfile, 3) > 2 && relfile[1] != ':') { @@ -630,7 +638,7 @@ int BLI_path_frame_range(char *path, int sta, int end, int digits) int BLI_path_abs(char *path, const char *basepath) { - int wasrelative = (strncmp(path, "//", 2) == 0); + int wasrelative = BLI_path_is_rel(path); char tmp[FILE_MAX]; char base[FILE_MAX]; #ifdef WIN32 diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c index 4ce718aeb16..32afaba2b5c 100644 --- a/source/blender/blenlib/intern/scanfill.c +++ b/source/blender/blenlib/intern/scanfill.c @@ -423,12 +423,16 @@ static void testvertexnearedge(ScanFillContext *sf_ctx) for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) { if (eve->h == 1) { - /* find the edge which has vertex eve */ - ed1 = sf_ctx->filledgebase.first; - while (ed1) { - if (ed1->v1 == eve || ed1->v2 == eve) break; - ed1 = ed1->next; + /* find the edge which has vertex eve, + * note: we _know_ this will crash if 'ed1' becomes NULL + * but this will never happen. */ + for (ed1 = sf_ctx->filledgebase.first; + !(ed1->v1 == eve || ed1->v2 == eve); + ed1 = ed1->next) + { + /* do nothing */ } + if (ed1->v1 == eve) { ed1->v1 = ed1->v2; ed1->v2 = eve; diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index 965e8b5eec3..0fccd91fc02 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -86,13 +86,10 @@ #include "BLI_listbase.h" #include "BLI_linklist.h" -#include "BLI_fileops.h" - -#include "BLI_fileops_types.h" #include "BLI_string.h" #include "BLI_fileops.h" - -#include "BKE_utildefines.h" +#include "BLI_fileops_types.h" +#include "BLI_path_util.h" /* vars: */ static int totnum, actnum; diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c index 0dc4d3c2db6..5b5f4cf8b80 100644 --- a/source/blender/blenlib/intern/winstuff.c +++ b/source/blender/blenlib/intern/winstuff.c @@ -41,12 +41,12 @@ #include "BLI_path_util.h" #include "BLI_string.h" -#include "BKE_utildefines.h" #include "BKE_global.h" #define WIN32_SKIP_HKEY_PROTECTION // need to use HKEY #include "BLI_winstuff.h" #include "BLI_utildefines.h" +#include "BLI_path_util.h" #include "utf_winfunc.h" #include "utfconv.h" diff --git a/source/blender/blenloader/BLO_blend_defs.h b/source/blender/blenloader/BLO_blend_defs.h new file mode 100644 index 00000000000..8005be158ce --- /dev/null +++ b/source/blender/blenloader/BLO_blend_defs.h @@ -0,0 +1,47 @@ +/* + * ***** 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. + * + * ***** END GPL LICENSE BLOCK ***** + */ +#ifndef __BLO_BLEND_DEFS_H__ +#define __BLO_BLEND_DEFS_H__ + +/** \file BLO_blend_defs.h + * \ingroup blenloader + * \brief defines for blendfile codes + */ + +/* INTEGER CODES */ +#ifdef __BIG_ENDIAN__ +/* Big Endian */ +# define BLEND_MAKE_ID(a, b, c, d) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d) ) +#else +/* Little Endian */ +# define BLEND_MAKE_ID(a, b, c, d) ( (int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a) ) +#endif + +#define DATA BLEND_MAKE_ID('D', 'A', 'T', 'A') +#define GLOB BLEND_MAKE_ID('G', 'L', 'O', 'B') + +#define DNA1 BLEND_MAKE_ID('D', 'N', 'A', '1') +#define TEST BLEND_MAKE_ID('T', 'E', 'S', 'T') /* used as preview between 'REND' and 'GLOB' */ +#define REND BLEND_MAKE_ID('R', 'E', 'N', 'D') +#define USER BLEND_MAKE_ID('U', 'S', 'E', 'R') + +#define ENDB BLEND_MAKE_ID('E', 'N', 'D', 'B') + +#endif /* __BLO_BLEND_DEFS_H__ */ diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt index a0fe042e7fb..74df5211dad 100644 --- a/source/blender/blenloader/CMakeLists.txt +++ b/source/blender/blenloader/CMakeLists.txt @@ -48,6 +48,7 @@ set(SRC intern/versioning_legacy.c intern/writefile.c + BLO_blend_defs.h BLO_readfile.h BLO_runtime.h BLO_soundfile.h diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c index eb12a7bd837..e917ccdf342 100644 --- a/source/blender/blenloader/intern/readblenentry.c +++ b/source/blender/blenloader/intern/readblenentry.c @@ -40,12 +40,13 @@ #include "MEM_guardedalloc.h" +#include "BLI_utildefines.h" +#include "BLI_path_util.h" #include "BLI_fileops.h" #include "BLI_ghash.h" #include "BLI_linklist.h" #include "BLI_listbase.h" #include "BLI_string.h" -#include "BLI_utildefines.h" #include "DNA_genfile.h" #include "DNA_sdna_types.h" @@ -55,10 +56,10 @@ #include "BKE_library.h" // for free_main #include "BKE_idcode.h" #include "BKE_report.h" -#include "BKE_utildefines.h" #include "BLO_readfile.h" #include "BLO_undofile.h" +#include "BLO_blend_defs.h" #include "readfile.h" diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 2dd6c8992d9..845228fb1b9 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -101,6 +101,7 @@ #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" +#include "BLI_endian_switch.h" #include "BLI_blenlib.h" #include "BLI_math.h" #include "BLI_edgehash.h" @@ -141,7 +142,6 @@ #include "BKE_sequencer.h" #include "BKE_text.h" // for txt_extended_ascii_as_utf8 #include "BKE_tracking.h" -#include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND #include "BKE_sound.h" #include "IMB_imbuf.h" // for proxy / timecode versioning stuff @@ -150,6 +150,7 @@ #include "BLO_readfile.h" #include "BLO_undofile.h" +#include "BLO_blend_defs.h" #include "RE_engine.h" @@ -222,16 +223,6 @@ /* from misc_util: flip the bytes from x */ /* #define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1]) */ -// only used here in 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; \ -} (void)0 - /***/ typedef struct OldNew { @@ -578,9 +569,9 @@ static void switch_endian_bh4(BHead4 *bhead) if ((bhead->code & 0xFFFF)==0) bhead->code >>= 16; if (bhead->code != ENDB) { - SWITCH_INT(bhead->len); - SWITCH_INT(bhead->SDNAnr); - SWITCH_INT(bhead->nr); + BLI_endian_switch_int32(&bhead->len); + BLI_endian_switch_int32(&bhead->SDNAnr); + BLI_endian_switch_int32(&bhead->nr); } } @@ -590,9 +581,9 @@ static void switch_endian_bh8(BHead8 *bhead) if ((bhead->code & 0xFFFF)==0) bhead->code >>= 16; if (bhead->code != ENDB) { - SWITCH_INT(bhead->len); - SWITCH_INT(bhead->SDNAnr); - SWITCH_INT(bhead->nr); + BLI_endian_switch_int32(&bhead->len); + BLI_endian_switch_int32(&bhead->SDNAnr); + BLI_endian_switch_int32(&bhead->nr); } } @@ -613,7 +604,7 @@ static void bh4_from_bh8(BHead *bhead, BHead8 *bhead8, int do_endian_swap) * 0x0000000000000000000012345678 would become 0x12345678000000000000000000000000 */ if (do_endian_swap) { - SWITCH_LONGINT(bhead8->old); + BLI_endian_switch_int64(&bhead8->old); } /* this patch is to avoid a long long being read from not-eight aligned positions @@ -1477,11 +1468,7 @@ static void link_glob_list(FileData *fd, ListBase *lb) /* for glob data */ static void test_pointer_array(FileData *fd, void **mat) { -#if defined(WIN32) && !defined(FREE_WINDOWS) - __int64 *lpoin, *lmat; -#else - long long *lpoin, *lmat; -#endif + int64_t *lpoin, *lmat; int *ipoin, *imat; size_t len; @@ -1498,7 +1485,7 @@ static void test_pointer_array(FileData *fd, void **mat) while (len-- > 0) { if ((fd->flags & FD_FLAGS_SWITCH_ENDIAN)) - SWITCH_LONGINT(*lpoin); + BLI_endian_switch_int64(lpoin); *ipoin = (int)((*lpoin) >> 3); ipoin++; lpoin++; @@ -1568,16 +1555,13 @@ static void IDP_DirectLinkArray(IDProperty *prop, int switch_endian, FileData *f } else if (prop->subtype == IDP_DOUBLE) { if (switch_endian) { - for (i = 0; i < prop->len; i++) { - SWITCH_LONGINT(((double *)prop->data.pointer)[i]); - } + BLI_endian_switch_double_array(prop->data.pointer, prop->len); } } else { if (switch_endian) { - for (i = 0; i < prop->len; i++) { - SWITCH_INT(((int *)prop->data.pointer)[i]); - } + /* also used for floats */ + BLI_endian_switch_int32_array(prop->data.pointer, prop->len); } } } @@ -1629,9 +1613,9 @@ static void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, FileData */ if (switch_endian) { - SWITCH_INT(prop->data.val); - SWITCH_INT(prop->data.val2); - SWITCH_LONGINT(prop->data.val); + BLI_endian_switch_int32(&prop->data.val); + BLI_endian_switch_int32(&prop->data.val2); + BLI_endian_switch_int64((int64_t *)&prop->data.val); } break; @@ -1872,9 +1856,7 @@ static void direct_link_fmodifiers(FileData *fd, ListBase *list) data->coefficients = newdataadr(fd, data->coefficients); if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) { - unsigned int a; - for (a = 0; a < data->arraysize; a++) - SWITCH_INT(data->coefficients[a]); + BLI_endian_switch_float_array(data->coefficients, data->arraysize); } } break; @@ -2778,11 +2760,8 @@ static void switch_endian_keyblock(Key *key, KeyBlock *kb) case IPO_BPOINT: case IPO_BEZTRIPLE: b = cp[0]; - - while (b--) { - SWITCH_INT((*poin)); - poin += 4; - } + BLI_endian_switch_float_array((float *)poin, b); + poin += sizeof(float) * b; break; } @@ -3073,19 +3052,11 @@ static void lib_link_curve(FileData *fd, Main *main) static void switch_endian_knots(Nurb *nu) { - int len; - if (nu->knotsu) { - len = KNOTSU(nu); - while (len--) { - SWITCH_INT(nu->knotsu[len]); - } + BLI_endian_switch_float_array(nu->knotsu, KNOTSU(nu)); } if (nu->knotsv) { - len = KNOTSV(nu); - while (len--) { - SWITCH_INT(nu->knotsv[len]); - } + BLI_endian_switch_float_array(nu->knotsv, KNOTSV(nu)); } } @@ -3303,11 +3274,10 @@ static void direct_link_pointcache(FileData *fd, PointCache *cache) /* the cache saves non-struct data without DNA */ if (pm->data[i] && ptcache_data_struct[i][0]=='\0' && (fd->flags & FD_FLAGS_SWITCH_ENDIAN)) { - int j, tot = (BKE_ptcache_data_size (i) * pm->totpoint)/4; /* data_size returns bytes */ + int tot = (BKE_ptcache_data_size (i) * pm->totpoint) / sizeof(int); /* data_size returns bytes */ int *poin = pm->data[i]; - for (j = 0; j < tot; j++) - SWITCH_INT(poin[j]); + BLI_endian_switch_int32_array(poin, tot); } } @@ -3776,12 +3746,7 @@ static void direct_link_mdisps(FileData *fd, int count, MDisps *mdisps, int exte if ((fd->flags & FD_FLAGS_SWITCH_ENDIAN) && (mdisps[i].disps)) { /* DNA_struct_switch_endian doesn't do endian swap for (*disps)[] */ /* this does swap for data written at write_mdisps() - readfile.c */ - int x; - float *tmpdisps = *mdisps[i].disps; - for (x = 0; x < mdisps[i].totdisp * 3; x++) { - SWITCH_INT(*tmpdisps); - tmpdisps++; - } + BLI_endian_switch_float_array(*mdisps[i].disps, mdisps[i].totdisp * 3); } if (!external && !mdisps[i].disps) mdisps[i].totdisp = 0; @@ -3951,11 +3916,8 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh) TFace *tf = mesh->tface; int i; - for (i = 0; i < (mesh->totface); i++, tf++) { - SWITCH_INT(tf->col[0]); - SWITCH_INT(tf->col[1]); - SWITCH_INT(tf->col[2]); - SWITCH_INT(tf->col[3]); + for (i = 0; i < mesh->totface; i++, tf++) { + BLI_endian_switch_uint32_array(tf->col, 4); } } } @@ -4481,10 +4443,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) hmd->indexar = newdataadr(fd, hmd->indexar); if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) { - int a; - for (a = 0; a < hmd->totindex; a++) { - SWITCH_INT(hmd->indexar[a]); - } + BLI_endian_switch_int32_array(hmd->indexar, hmd->totindex); } } else if (md->type == eModifierType_ParticleSystem) { @@ -4514,24 +4473,11 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) mmd->bindcos = newdataadr(fd, mmd->bindcos); if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) { - int a; - - if (mmd->bindoffsets) - for (a=0; a<mmd->totvert+1; a++) - SWITCH_INT(mmd->bindoffsets[a]); - if (mmd->bindcagecos) - for (a=0; a<mmd->totcagevert*3; a++) - SWITCH_INT(mmd->bindcagecos[a]); - if (mmd->dynverts) - for (a=0; a<mmd->totvert; a++) - SWITCH_INT(mmd->dynverts[a]); - - if (mmd->bindweights) - for (a=0; a<mmd->totcagevert*mmd->totvert; a++) - SWITCH_INT(mmd->bindweights[a]); - if (mmd->bindcos) - for (a=0; a<mmd->totcagevert*3; a++) - SWITCH_INT(mmd->bindcos[a]); + if (mmd->bindoffsets) BLI_endian_switch_int32_array(mmd->bindoffsets, mmd->totvert + 1); + if (mmd->bindcagecos) BLI_endian_switch_float_array(mmd->bindcagecos, mmd->totcagevert * 3); + if (mmd->dynverts) BLI_endian_switch_int32_array(mmd->dynverts, mmd->totvert); + if (mmd->bindweights) BLI_endian_switch_float_array(mmd->bindweights, mmd->totvert); + if (mmd->bindcos) BLI_endian_switch_float_array(mmd->bindcos, mmd->totcagevert * 3); } } else if (md->type == eModifierType_Ocean) { @@ -4725,10 +4671,7 @@ static void direct_link_object(FileData *fd, Object *ob) hook->indexar= newdataadr(fd, hook->indexar); if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) { - int a; - for (a = 0; a < hook->totindex; a++) { - SWITCH_INT(hook->indexar[a]); - } + BLI_endian_switch_int32_array(hook->indexar, hook->totindex); } /* Do conversion here because if we have loaded @@ -5023,7 +4966,6 @@ static void direct_link_scene(FileData *fd, Scene *sce) seq->seq1= newdataadr(fd, seq->seq1); seq->seq2= newdataadr(fd, seq->seq2); seq->seq3= newdataadr(fd, seq->seq3); - seq->mask_sequence= newdataadr(fd, seq->mask_sequence); /* a patch: after introduction of effects with 3 input strips */ if (seq->seq3 == NULL) seq->seq3 = seq->seq2; @@ -5069,16 +5011,9 @@ static void direct_link_scene(FileData *fd, Scene *sce) else { seq->strip->proxy = NULL; } - if (seq->flag & SEQ_USE_COLOR_BALANCE) { - seq->strip->color_balance = newdataadr( - fd, seq->strip->color_balance); - } - else { - seq->strip->color_balance = NULL; - } - if (seq->strip->color_balance) { - // seq->strip->color_balance->gui = 0; // XXX - peter, is this relevant in 2.5? - } + + /* need to load color balance to it could be converted to modifier */ + seq->strip->color_balance = newdataadr(fd, seq->strip->color_balance); } direct_link_sequence_modifiers(fd, &seq->modifiers); @@ -5825,7 +5760,6 @@ static void direct_link_screen(FileData *fd, bScreen *sc) ScrArea *sa; ScrVert *sv; ScrEdge *se; - int a; link_list(fd, &(sc->vertbase)); link_list(fd, &(sc->edgebase)); @@ -5835,16 +5769,7 @@ static void direct_link_screen(FileData *fd, bScreen *sc) sc->mainwin = sc->subwinactive= 0; /* indices */ sc->swap = 0; - - /* hacky patch... but people have been saving files with the verse-blender, - * causing the handler to keep running for ever, with no means to disable it */ - for (a = 0; a < SCREEN_MAXHANDLER; a+=2) { - if (sc->handler[a] == SCREEN_HANDLER_VERSE) { - sc->handler[a] = 0; - break; - } - } - + /* edges */ for (se = sc->edgebase.first; se; se = se->next) { se->v1 = newdataadr(fd, se->v1); @@ -6123,7 +6048,7 @@ static void fix_relpaths_library(const char *basepath, Main *main) * it absolute. This can happen when appending an object with a relative * link into an unsaved blend file. See [#27405]. * The remap relative option will make it relative again on save - campbell */ - if (strncmp(lib->name, "//", 2) == 0) { + if (BLI_path_is_rel(lib->name)) { BLI_strncpy(lib->name, lib->filepath, sizeof(lib->name)); } } @@ -6132,7 +6057,7 @@ static void fix_relpaths_library(const char *basepath, Main *main) for (lib = main->library.first; lib; lib = lib->id.next) { /* Libraries store both relative and abs paths, recreate relative paths, * relative to the blend file since indirectly linked libs will be relative to their direct linked library */ - if (strncmp(lib->name, "//", 2) == 0) { /* if this is relative to begin with? */ + if (BLI_path_is_rel(lib->name)) { /* if this is relative to begin with? */ BLI_strncpy(lib->name, lib->filepath, sizeof(lib->name)); BLI_path_rel(lib->name, basepath); } @@ -7275,8 +7200,8 @@ static void do_version_ntree_mask_264(void *UNUSED(data), ID *UNUSED(id), bNodeT if (node->storage == NULL) { NodeMask *data = MEM_callocN(sizeof(NodeMask), __func__); /* move settings into own struct */ - data->size_x = node->custom3; - data->size_y = node->custom4; + data->size_x = (int)node->custom3; + data->size_y = (int)node->custom4; node->custom3 = 0.5f; /* default shutter */ node->storage = data; } @@ -8134,6 +8059,42 @@ static void do_versions(FileData *fd, Library *lib, Main *main) ntreetype->foreach_nodetree(main, NULL, do_version_ntree_mask_264); } + if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 18)) { + Scene *scene; + + for (scene = main->scene.first; scene; scene = scene->id.next) { + if (scene->ed) { + Sequence *seq; + + SEQ_BEGIN (scene->ed, seq) + { + Strip *strip = seq->strip; + + if (strip && strip->color_balance) { + SequenceModifierData *smd; + ColorBalanceModifierData *cbmd; + + smd = BKE_sequence_modifier_new(seq, NULL, seqModifierType_ColorBalance); + cbmd = (ColorBalanceModifierData *) smd; + + cbmd->color_balance = *strip->color_balance; + + /* multiplication with color balance used is handled differently, + * so we need to move multiplication to modifier so files would be + * compatible + */ + cbmd->color_multiply = seq->mul; + seq->mul = 1.0f; + + MEM_freeN(strip->color_balance); + strip->color_balance = NULL; + } + } + SEQ_END + } + } + } + /* default values in Freestyle settings */ { Scene *sce; @@ -9750,9 +9711,9 @@ static void read_libraries(FileData *basefd, ListBase *mainlist) cleanup_path(G.main->name, mainptr->curlib->filepath); fd = blo_openblenderfile(mainptr->curlib->filepath, basefd->reports); - fd->mainlist = mainlist; - + if (fd) { + fd->mainlist = mainlist; printf("found: '%s', party on macuno!\n", mainptr->curlib->filepath); } } diff --git a/source/blender/blenloader/intern/runtime.c b/source/blender/blenloader/intern/runtime.c index a7dae22cda2..eaf725dda9e 100644 --- a/source/blender/blenloader/intern/runtime.c +++ b/source/blender/blenloader/intern/runtime.c @@ -50,7 +50,6 @@ #include "BKE_blender.h" #include "BKE_report.h" -#include "BKE_utildefines.h" #include "BLI_blenlib.h" diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index 1bad1bd80df..a4f190c8167 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -89,7 +89,6 @@ #include "BKE_screen.h" #include "BKE_sequencer.h" #include "BKE_texture.h" -#include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND #include "BKE_sound.h" #include "NOD_socket.h" diff --git a/source/blender/blenloader/intern/versioning_legacy.c b/source/blender/blenloader/intern/versioning_legacy.c index 8ace277b42d..1cc0d4180ab 100644 --- a/source/blender/blenloader/intern/versioning_legacy.c +++ b/source/blender/blenloader/intern/versioning_legacy.c @@ -95,7 +95,6 @@ #include "BKE_property.h" // for get_ob_property #include "BKE_scene.h" #include "BKE_sequencer.h" -#include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND #include "IMB_imbuf.h" // for proxy / timecode versioning stuff diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 769d33778ba..b2d4e905dc9 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -155,7 +155,6 @@ Any case: direct data is ALWAYS after the lib block #include "BKE_report.h" #include "BKE_sequencer.h" #include "BKE_subsurf.h" -#include "BKE_utildefines.h" #include "BKE_modifier.h" #include "BKE_fcurve.h" #include "BKE_pointcache.h" @@ -164,6 +163,7 @@ Any case: direct data is ALWAYS after the lib block #include "BLO_writefile.h" #include "BLO_readfile.h" #include "BLO_undofile.h" +#include "BLO_blend_defs.h" #include "readfile.h" @@ -2217,9 +2217,6 @@ static void write_scenes(WriteData *wd, ListBase *scebase) if (seq->flag & SEQ_USE_PROXY && strip->proxy) { writestruct(wd, DATA, "StripProxy", 1, strip->proxy); } - if (seq->flag & SEQ_USE_COLOR_BALANCE && strip->color_balance) { - writestruct(wd, DATA, "StripColorBalance", 1, strip->color_balance); - } if (seq->type==SEQ_TYPE_IMAGE) writestruct(wd, DATA, "StripElem", MEM_allocN_len(strip->stripdata) / sizeof(struct StripElem), strip->stripdata); else if (seq->type==SEQ_TYPE_MOVIE || seq->type==SEQ_TYPE_SOUND_RAM || seq->type == SEQ_TYPE_SOUND_HD) diff --git a/source/blender/bmesh/bmesh.h b/source/blender/bmesh/bmesh.h index ac002070484..955b1a729c5 100644 --- a/source/blender/bmesh/bmesh.h +++ b/source/blender/bmesh/bmesh.h @@ -196,6 +196,11 @@ * * There may be a better place for this section, but adding here for now. * + * \subsection bm_todo_api API + * + * - make crease and bevel weight optional, they come for free in meshes but are allocated layers + * in the bmesh data structure. + * * * \subsection bm_todo_tools Tools * diff --git a/source/blender/bmesh/intern/bmesh_core.c b/source/blender/bmesh/intern/bmesh_core.c index 94d94cbec3e..f03ce9b8543 100644 --- a/source/blender/bmesh/intern/bmesh_core.c +++ b/source/blender/bmesh/intern/bmesh_core.c @@ -86,8 +86,9 @@ BMVert *BM_vert_create(BMesh *bm, const float co[3], const BMVert *example) /* exception: don't copy the original shapekey index */ keyi = CustomData_bmesh_get(&bm->vdata, v->head.data, CD_SHAPE_KEYINDEX); - if(keyi) + if (keyi) { *keyi = ORIGINDEX_NONE; + } } BM_CHECK_ELEMENT(v); @@ -339,6 +340,8 @@ BMFace *BM_face_create(BMesh *bm, BMVert **verts, BMEdge **edges, const int len, return f; } +#ifndef NDEBUG + /** * Check the element is valid. * @@ -357,14 +360,16 @@ int bmesh_elem_check(void *element, const char htype) return 2; switch (htype) { - case BM_VERT: { + case BM_VERT: + { BMVert *v = element; if (v->e && v->e->head.htype != BM_EDGE) { err |= 4; } break; } - case BM_EDGE: { + case BM_EDGE: + { BMEdge *e = element; if (e->l && e->l->head.htype != BM_LOOP) err |= 8; @@ -383,7 +388,8 @@ int bmesh_elem_check(void *element, const char htype) err |= 128; break; } - case BM_LOOP: { + case BM_LOOP: + { BMLoop *l = element, *l2; int i; @@ -423,7 +429,8 @@ int bmesh_elem_check(void *element, const char htype) break; } - case BM_FACE: { + case BM_FACE: + { BMFace *f = element; BMLoop *l_iter; BMLoop *l_first; @@ -471,6 +478,8 @@ int bmesh_elem_check(void *element, const char htype) return err; } +#endif /* NDEBUG */ + /** * low level function, only frees the vert, * doesn't change or adjust surrounding geometry @@ -1483,6 +1492,7 @@ BMVert *bmesh_semv(BMesh *bm, BMVert *tv, BMEdge *e, BMEdge **r_e) * and collapses the edge on that vertex. * * \par Examples: + * * <pre> * Before: OE KE * ------- ------- @@ -1792,18 +1802,21 @@ BMFace *bmesh_jfke(BMesh *bm, BMFace *f1, BMFace *f2, BMEdge *e) int BM_vert_splice(BMesh *bm, BMVert *v, BMVert *vtarget) { BMEdge *e; - BMLoop *l; - BMIter liter; + + BMLoop **loops; + int i, loops_tot; /* verts already spliced */ if (v == vtarget) { return FALSE; } - /* retarget all the loops of v to vtarget */ - BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) { - l->v = vtarget; + /* we can't modify the vert while iterating so first allocate an array of loops */ + loops = BM_iter_as_arrayN(bm, BM_LOOPS_OF_VERT, v, &loops_tot); + for (i = 0; i < loops_tot; i++) { + loops[i]->v = vtarget; } + MEM_freeN(loops); /* move all the edges from v's disk to vtarget's disk */ while ((e = v->e)) { diff --git a/source/blender/bmesh/intern/bmesh_iterators.c b/source/blender/bmesh/intern/bmesh_iterators.c index 8103ae1ee11..726127fdcad 100644 --- a/source/blender/bmesh/intern/bmesh_iterators.c +++ b/source/blender/bmesh/intern/bmesh_iterators.c @@ -28,6 +28,8 @@ * See: bmesh_iterators_inlin.c too, some functions are here for speed reasons. */ +#include "MEM_guardedalloc.h" + #include "BLI_utildefines.h" #include "bmesh.h" @@ -105,6 +107,38 @@ int BM_iter_as_array(BMesh *bm, const char itype, void *data, void **array, cons } /** + * \brief Iterator as Array + * + * Allocates a new array, has the advantage that you dont need to know the size ahead of time. + * + * Takes advantage of less common iterator usage to avoid counting twice, + * which you might end up doing when #BM_iter_as_array is used. + * + * Caller needs to free the array. + */ +void *BM_iter_as_arrayN(BMesh *bm, const char itype, void *data, int *r_len) +{ + BMIter iter; + + if (BM_iter_init(&iter, bm, itype, data) && iter.count > 0) { + BMElem *ele; + BMElem **array = MEM_mallocN(sizeof(ele) * iter.count, __func__); + int i = 0; + + *r_len = iter.count; /* set before iterating */ + + while ((ele = BM_iter_step(&iter))) { + array[i++] = ele; + } + return array; + } + else { + *r_len = 0; + return NULL; + } +} + +/** * \brief Elem Iter Flag Count * * Counts how many flagged / unflagged items are found in this element. diff --git a/source/blender/bmesh/intern/bmesh_iterators.h b/source/blender/bmesh/intern/bmesh_iterators.h index 1361a91a692..8d0eeca31ed 100644 --- a/source/blender/bmesh/intern/bmesh_iterators.h +++ b/source/blender/bmesh/intern/bmesh_iterators.h @@ -115,10 +115,19 @@ typedef struct BMIter { char itype; } BMIter; -void *BM_iter_at_index(BMesh *bm, const char itype, void *data, int index); -int BM_iter_as_array(BMesh *bm, const char itype, void *data, void **array, const int len); -int BM_iter_elem_count_flag(const char itype, void *data, const char hflag, const short value); -int BM_iter_mesh_count_flag(const char itype, BMesh *bm, const char hflag, const short value); +void *BM_iter_at_index(BMesh *bm, const char itype, void *data, int index) +#ifdef __GNUC__ +__attribute__((warn_unused_result)) +#endif +; +int BM_iter_as_array(BMesh *bm, const char itype, void *data, void **array, const int len); +void *BM_iter_as_arrayN(BMesh *bm, const char itype, void *data, int *r_len) +#ifdef __GNUC__ +__attribute__((warn_unused_result)) +#endif +; +int BM_iter_elem_count_flag(const char itype, void *data, const char hflag, const short value); +int BM_iter_mesh_count_flag(const char itype, BMesh *bm, const char hflag, const short value); /* private for bmesh_iterators_inline.c */ void bmiter__vert_of_mesh_begin(struct BMIter *iter); diff --git a/source/blender/bmesh/intern/bmesh_marking.c b/source/blender/bmesh/intern/bmesh_marking.c index 58ccfa79a02..c0439311104 100644 --- a/source/blender/bmesh/intern/bmesh_marking.c +++ b/source/blender/bmesh/intern/bmesh_marking.c @@ -527,9 +527,9 @@ void BM_active_face_set(BMesh *bm, BMFace *efa) bm->act_face = efa; } -BMFace *BM_active_face_get(BMesh *bm, int sloppy) +BMFace *BM_active_face_get(BMesh *bm, int sloppy, int selected) { - if (bm->act_face) { + if (bm->act_face && (!selected || BM_elem_flag_test(bm->act_face, BM_ELEM_SELECT))) { return bm->act_face; } else if (sloppy) { @@ -546,6 +546,9 @@ BMFace *BM_active_face_get(BMesh *bm, int sloppy) if (BM_elem_flag_test(f, BM_ELEM_HIDDEN)) { f = NULL; } + else if (selected && !BM_elem_flag_test(f, BM_ELEM_SELECT)) { + f = NULL; + } else { break; } @@ -768,7 +771,7 @@ void BM_select_history_validate(BMesh *bm) int BM_select_history_active_get(BMesh *bm, BMEditSelection *ese) { BMEditSelection *ese_last = bm->selected.last; - BMFace *efa = BM_active_face_get(bm, FALSE); + BMFace *efa = BM_active_face_get(bm, FALSE, FALSE); ese->next = ese->prev = NULL; diff --git a/source/blender/bmesh/intern/bmesh_marking.h b/source/blender/bmesh/intern/bmesh_marking.h index 9b73ed2c390..8d4397794d5 100644 --- a/source/blender/bmesh/intern/bmesh_marking.h +++ b/source/blender/bmesh/intern/bmesh_marking.h @@ -71,7 +71,7 @@ int BM_mesh_elem_hflag_count_disabled(BMesh *bm, const char htype, const char hf /* edit selection stuff */ void BM_active_face_set(BMesh *bm, BMFace *f); -BMFace *BM_active_face_get(BMesh *bm, int sloppy); +BMFace *BM_active_face_get(BMesh *bm, int sloppy, int selected); void BM_editselection_center(BMEditSelection *ese, float r_center[3]); void BM_editselection_normal(BMEditSelection *ese, float r_normal[3]); diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c index 0f2dc7041fa..53b95c97c8b 100644 --- a/source/blender/bmesh/intern/bmesh_operators.c +++ b/source/blender/bmesh/intern/bmesh_operators.c @@ -1417,7 +1417,8 @@ int BMO_op_vinitf(BMesh *bm, BMOperator *op, const int flag, const char *_fmt, v case '=': case '%': break; - case 'm': { + case 'm': + { int size, c; c = NEXT_CHAR(fmt); @@ -1431,12 +1432,14 @@ int BMO_op_vinitf(BMesh *bm, BMOperator *op, const int flag, const char *_fmt, v state = 1; break; } - case 'v': { + case 'v': + { BMO_slot_vec_set(op, slot_name, va_arg(vlist, float *)); state = 1; break; } - case 'e': { + case 'e': + { BMHeader *ele = va_arg(vlist, void *); BMOpSlot *slot = BMO_slot_get(op, slot_name); @@ -1447,7 +1450,8 @@ int BMO_op_vinitf(BMesh *bm, BMOperator *op, const int flag, const char *_fmt, v state = 1; break; } - case 's': { + case 's': + { BMOperator *op2 = va_arg(vlist, void *); const char *slot_name2 = va_arg(vlist, char *); diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index 807570f0d86..eb2b7721bdc 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.c +++ b/source/blender/bmesh/intern/bmesh_polygon.c @@ -285,7 +285,7 @@ void calc_poly_plane(float (*verts)[3], const int nverts) * the list that bridges a concave region of the face or intersects * any of the faces's edges. */ -static void shrink_edgef(float v1[3], float v2[3], const float fac) +static void scale_edge_v3f(float v1[3], float v2[3], const float fac) { float mid[3]; @@ -502,7 +502,7 @@ void BM_face_normal_flip(BMesh *bm, BMFace *f) /* detects if two line segments cross each other (intersects). * note, there could be more winding cases then there needs to be. */ -static int linecrossesf(const float v1[2], const float v2[2], const float v3[2], const float v4[2]) +static int line_crosses_v2f(const float v1[2], const float v2[2], const float v3[2], const float v4[2]) { #define GETMIN2_AXIS(a, b, ma, mb, axis) \ @@ -606,13 +606,13 @@ int BM_face_point_inside_test(BMFace *f, const float co[3]) do { float v1[2], v2[2]; - v1[0] = (l_iter->prev->v->co[ax] - cent[ax]) * onepluseps + cent[ax]; - v1[1] = (l_iter->prev->v->co[ay] - cent[ay]) * onepluseps + cent[ay]; + v1[0] = (l_iter->prev->v->co[ax] - cent[0]) * onepluseps + cent[0]; + v1[1] = (l_iter->prev->v->co[ay] - cent[1]) * onepluseps + cent[1]; - v2[0] = (l_iter->v->co[ax] - cent[ax]) * onepluseps + cent[ax]; - v2[1] = (l_iter->v->co[ay] - cent[ay]) * onepluseps + cent[ay]; + v2[0] = (l_iter->v->co[ax] - cent[0]) * onepluseps + cent[0]; + v2[1] = (l_iter->v->co[ay] - cent[1]) * onepluseps + cent[1]; - crosses += linecrossesf(v1, v2, co2, out) != 0; + crosses += line_crosses_v2f(v1, v2, co2, out) != 0; } while ((l_iter = l_iter->next) != l_first); return crosses % 2 != 0; @@ -959,7 +959,7 @@ void BM_face_legal_splits(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len) BMIter iter; BMLoop *l; float v1[3], v2[3], v3[3] /*, v4[3 */, no[3], mid[3], *p1, *p2, *p3, *p4; - float out[3] = {-234324.0f, -234324.0f, 0.0f}; + float out[3] = {-FLT_MAX, -FLT_MAX, 0.0f}; float (*projverts)[3]; float (*edgeverts)[3]; float fac1 = 1.0000001f, fac2 = 0.9f; //9999f; //0.999f; @@ -980,7 +980,7 @@ void BM_face_legal_splits(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len) copy_v3_v3(v1, loops[i][0]->v->co); copy_v3_v3(v2, loops[i][1]->v->co); - shrink_edgef(v1, v2, fac2); + scale_edge_v3f(v1, v2, fac2); copy_v3_v3(edgeverts[a], v1); a++; @@ -994,14 +994,16 @@ void BM_face_legal_splits(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len) for (i = 0, l = BM_FACE_FIRST_LOOP(f); i < f->len; i++, l = l->next) { p1 = projverts[i]; - out[0] = maxf(out[0], p1[0]) + 0.01f; - out[1] = maxf(out[1], p1[1]) + 0.01f; - out[2] = 0.0f; - p1[2] = 0.0f; + out[0] = maxf(out[0], p1[0]); + out[1] = maxf(out[1], p1[1]); + /* out[2] = 0.0f; */ /* keep at zero */ - //copy_v3_v3(l->v->co, p1); + p1[2] = 0.0f; } + /* ensure we are well outside the face bounds (value is arbitrary) */ + add_v2_fl(out, 1.0f); + for (i = 0; i < len; i++) { edgeverts[i * 2][2] = 0.0f; edgeverts[i * 2 + 1][2] = 0.0f; @@ -1019,19 +1021,26 @@ void BM_face_legal_splits(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len) p1 = projverts[j]; p2 = projverts[(j + 1) % f->len]; +#if 0 copy_v3_v3(v1, p1); copy_v3_v3(v2, p2); - shrink_edgef(v1, v2, fac1); - - if (linecrossesf(p1, p2, mid, out)) clen++; + scale_edge_v3f(v1, v2, fac1); + if (line_crosses_v2f(v1, v2, mid, out)) { + clen++; + } +#else + if (line_crosses_v2f(p1, p2, mid, out)) { + clen++; + } +#endif } - + if (clen % 2 == 0) { loops[i][0] = NULL; } } - + /* do line crossing test */ for (i = 0; i < f->len; i++) { p1 = projverts[i]; @@ -1040,7 +1049,7 @@ void BM_face_legal_splits(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len) copy_v3_v3(v1, p1); copy_v3_v3(v2, p2); - shrink_edgef(v1, v2, fac1); + scale_edge_v3f(v1, v2, fac1); for (j = 0; j < len; j++) { if (!loops[j][0]) { @@ -1050,7 +1059,7 @@ void BM_face_legal_splits(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len) p3 = edgeverts[j * 2]; p4 = edgeverts[j * 2 + 1]; - if (linecrossesf(v1, v2, p3, p4)) { + if (line_crosses_v2f(v1, v2, p3, p4)) { loops[j][0] = NULL; } } @@ -1067,9 +1076,9 @@ void BM_face_legal_splits(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len) copy_v3_v3(v1, p1); copy_v3_v3(v2, p2); - shrink_edgef(v1, v2, fac1); + scale_edge_v3f(v1, v2, fac1); - if (linecrossesf(v1, v2, p3, p4)) { + if (line_crosses_v2f(v1, v2, p3, p4)) { loops[i][0] = NULL; } } diff --git a/source/blender/bmesh/intern/bmesh_private.h b/source/blender/bmesh/intern/bmesh_private.h index 0827901f5c2..b3fe3676ab8 100644 --- a/source/blender/bmesh/intern/bmesh_private.h +++ b/source/blender/bmesh/intern/bmesh_private.h @@ -37,21 +37,21 @@ */ /* returns positive nonzero on error */ -int bmesh_elem_check(void *element, const char htype); -#define BM_CHECK_ELEMENT(el) \ +#ifdef NDEBUG + /* no error checking for release, + * it can take most of the CPU time when running some tools */ +# define BM_CHECK_ELEMENT(el) (void)(el) +#else +int bmesh_elem_check(void *element, const char htype); +# define BM_CHECK_ELEMENT(el) \ if (bmesh_elem_check(el, ((BMHeader *)el)->htype)) { \ printf("check_element failure, with code %i on line %i in file\n" \ " \"%s\"\n\n", \ - bmesh_elem_check(el, ((BMHeader *)el)->htype), \ + bmesh_elem_check(el, ((BMHeader *)el)->htype), \ __LINE__, __FILE__); \ - } - -#define BM_DISK_EDGE_LINK_GET(e, v) ( \ - ((v) == ((BMEdge *)(e))->v1) ? \ - &((e)->v1_disk_link) : \ - &((e)->v2_disk_link) \ - ) + } (void)0 +#endif int bmesh_radial_length(BMLoop *l); int bmesh_disk_count(BMVert *v); diff --git a/source/blender/bmesh/intern/bmesh_queries.c b/source/blender/bmesh/intern/bmesh_queries.c index a9f146e4962..d850eb34477 100644 --- a/source/blender/bmesh/intern/bmesh_queries.c +++ b/source/blender/bmesh/intern/bmesh_queries.c @@ -470,31 +470,12 @@ int BM_edge_face_count(BMEdge *e) } /** - * Returns the number of faces around this vert + * Returns the number of faces around this vert + * length matches #BM_LOOPS_OF_VERT iterator */ int BM_vert_face_count(BMVert *v) { - int count = 0; - BMLoop *l; - BMIter iter; - - BM_ITER_ELEM (l, &iter, v, BM_LOOPS_OF_VERT) { - count++; - } - - return count; -#if 0 //this code isn't working - BMEdge *curedge = NULL; - - if (v->e) { - curedge = v->e; - do { - if (curedge->l) count += BM_edge_face_count(curedge); - curedge = bmesh_disk_edge_next(curedge, v); - } while (curedge != v->e); - } - return count; -#endif + return bmesh_disk_facevert_count(v); } /** @@ -503,22 +484,21 @@ int BM_vert_face_count(BMVert *v) */ int BM_vert_is_wire(BMVert *v) { - BMEdge *curedge; + if (v->e) { + BMEdge *e_first, *e_iter; - if (v->e == NULL) { + e_first = e_iter = v->e; + do { + if (e_iter->l) { + return FALSE; + } + } while ((e_iter = bmesh_disk_edge_next(e_iter, v)) != e_first); + + return TRUE; + } + else { return FALSE; } - - curedge = v->e; - do { - if (curedge->l) { - return FALSE; - } - - curedge = bmesh_disk_edge_next(curedge, v); - } while (curedge != v->e); - - return TRUE; } /** diff --git a/source/blender/bmesh/intern/bmesh_structure.c b/source/blender/bmesh/intern/bmesh_structure.c index 2ff9e707b59..b58e61a3066 100644 --- a/source/blender/bmesh/intern/bmesh_structure.c +++ b/source/blender/bmesh/intern/bmesh_structure.c @@ -153,10 +153,22 @@ int bmesh_edge_swapverts(BMEdge *e, BMVert *orig, BMVert *newv) * advantage is that no intrinsic properties of the data structures are dependent upon the * cycle order and all non-manifold conditions are represented trivially. */ + +BLI_INLINE BMDiskLink *bmesh_disk_edge_link_from_vert(BMEdge *e, BMVert *v) +{ + if (v == e->v1) { + return &e->v1_disk_link; + } + else { + BLI_assert(v == e->v2); + return &e->v2_disk_link; + } +} + int bmesh_disk_edge_append(BMEdge *e, BMVert *v) { if (!v->e) { - BMDiskLink *dl1 = BM_DISK_EDGE_LINK_GET(e, v); + BMDiskLink *dl1 = bmesh_disk_edge_link_from_vert(e, v); v->e = e; dl1->next = dl1->prev = e; @@ -164,9 +176,9 @@ int bmesh_disk_edge_append(BMEdge *e, BMVert *v) else { BMDiskLink *dl1, *dl2, *dl3; - dl1 = BM_DISK_EDGE_LINK_GET(e, v); - dl2 = BM_DISK_EDGE_LINK_GET(v->e, v); - dl3 = dl2->prev ? BM_DISK_EDGE_LINK_GET(dl2->prev, v) : NULL; + dl1 = bmesh_disk_edge_link_from_vert(e, v); + dl2 = bmesh_disk_edge_link_from_vert(v->e, v); + dl3 = dl2->prev ? bmesh_disk_edge_link_from_vert(dl2->prev, v) : NULL; dl1->next = v->e; dl1->prev = dl2->prev; @@ -183,14 +195,14 @@ void bmesh_disk_edge_remove(BMEdge *e, BMVert *v) { BMDiskLink *dl1, *dl2; - dl1 = BM_DISK_EDGE_LINK_GET(e, v); + dl1 = bmesh_disk_edge_link_from_vert(e, v); if (dl1->prev) { - dl2 = BM_DISK_EDGE_LINK_GET(dl1->prev, v); + dl2 = bmesh_disk_edge_link_from_vert(dl1->prev, v); dl2->next = dl1->next; } if (dl1->next) { - dl2 = BM_DISK_EDGE_LINK_GET(dl1->next, v); + dl2 = bmesh_disk_edge_link_from_vert(dl1->next, v); dl2->prev = dl1->prev; } diff --git a/source/blender/bmesh/operators/bmo_connect.c b/source/blender/bmesh/operators/bmo_connect.c index 6943dcb3e5d..1987294fc42 100644 --- a/source/blender/bmesh/operators/bmo_connect.c +++ b/source/blender/bmesh/operators/bmo_connect.c @@ -45,18 +45,18 @@ void bmo_connect_verts_exec(BMesh *bm, BMOperator *op) { BMIter iter, liter; BMFace *f, *nf; - BMLoop **loops = NULL, *lastl = NULL; - BLI_array_declare(loops); - BMLoop *l, *nl; - BMVert **verts = NULL; - BLI_array_declare(verts); + BMLoop *(*loops_split)[2] = NULL; + BLI_array_declare(loops_split); + BMLoop *l, *nl, *lastl = NULL; + BMVert *(*verts_pair)[2] = NULL; + BLI_array_declare(verts_pair); int i; BMO_slot_buffer_flag_enable(bm, op, "verts", BM_VERT, VERT_INPUT); for (f = BM_iter_new(&iter, bm, BM_FACES_OF_MESH, NULL); f; f = BM_iter_step(&iter)) { - BLI_array_empty(loops); - BLI_array_empty(verts); + BLI_array_empty(loops_split); + BLI_array_empty(verts_pair); if (BMO_elem_flag_test(bm, f, FACE_NEW)) { continue; @@ -72,50 +72,44 @@ void bmo_connect_verts_exec(BMesh *bm, BMOperator *op) } if (lastl != l->prev && lastl != l->next) { - BLI_array_grow_one(loops); - loops[BLI_array_count(loops) - 1] = lastl; - - BLI_array_grow_one(loops); - loops[BLI_array_count(loops) - 1] = l; + BLI_array_grow_one(loops_split); + loops_split[BLI_array_count(loops_split) - 1][0] = lastl; + loops_split[BLI_array_count(loops_split) - 1][1] = l; } lastl = l; } } - if (BLI_array_count(loops) == 0) { + if (BLI_array_count(loops_split) == 0) { continue; } - if (BLI_array_count(loops) > 2) { - BLI_array_grow_one(loops); - loops[BLI_array_count(loops) - 1] = loops[BLI_array_count(loops) - 2]; - - BLI_array_grow_one(loops); - loops[BLI_array_count(loops) - 1] = loops[0]; + if (BLI_array_count(loops_split) > 1) { + BLI_array_grow_one(loops_split); + loops_split[BLI_array_count(loops_split) - 1][0] = loops_split[BLI_array_count(loops_split) - 2][1]; + loops_split[BLI_array_count(loops_split) - 1][1] = loops_split[0][0]; } - BM_face_legal_splits(bm, f, (BMLoop *(*)[2])loops, BLI_array_count(loops) / 2); + BM_face_legal_splits(bm, f, loops_split, BLI_array_count(loops_split)); - for (i = 0; i < BLI_array_count(loops) / 2; i++) { - if (loops[i * 2] == NULL) { + for (i = 0; i < BLI_array_count(loops_split); i++) { + if (loops_split[i][0] == NULL) { continue; } - BLI_array_grow_one(verts); - verts[BLI_array_count(verts) - 1] = loops[i * 2]->v; - - BLI_array_grow_one(verts); - verts[BLI_array_count(verts) - 1] = loops[i * 2 + 1]->v; + BLI_array_grow_one(verts_pair); + verts_pair[BLI_array_count(verts_pair) - 1][0] = loops_split[i][0]->v; + verts_pair[BLI_array_count(verts_pair) - 1][1] = loops_split[i][1]->v; } - for (i = 0; i < BLI_array_count(verts) / 2; i++) { - nf = BM_face_split(bm, f, verts[i * 2], verts[i * 2 + 1], &nl, NULL, FALSE); + for (i = 0; i < BLI_array_count(verts_pair); i++) { + nf = BM_face_split(bm, f, verts_pair[i][0], verts_pair[i][1], &nl, NULL, FALSE); f = nf; if (!nl || !nf) { BMO_error_raise(bm, op, BMERR_CONNECTVERT_FAILED, NULL); - BLI_array_free(loops); + BLI_array_free(loops_split); return; } BMO_elem_flag_enable(bm, nf, FACE_NEW); @@ -125,8 +119,8 @@ void bmo_connect_verts_exec(BMesh *bm, BMOperator *op) BMO_slot_buffer_from_enabled_flag(bm, op, "edgeout", BM_EDGE, EDGE_OUT); - BLI_array_free(loops); - BLI_array_free(verts); + BLI_array_free(loops_split); + BLI_array_free(verts_pair); } static BMVert *get_outer_vert(BMesh *bm, BMEdge *e) @@ -345,7 +339,6 @@ void bmo_bridge_loops_exec(BMesh *bm, BMOperator *op) goto cleanup; } - j = 0; if (vv1[0] == vv1[lenv1 - 1]) { lenv1--; } diff --git a/source/blender/bmesh/operators/bmo_extrude.c b/source/blender/bmesh/operators/bmo_extrude.c index 9ea8e631435..c8be7c9ce34 100644 --- a/source/blender/bmesh/operators/bmo_extrude.c +++ b/source/blender/bmesh/operators/bmo_extrude.c @@ -390,7 +390,7 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) if (!v1->e) BM_vert_kill(bm, v1); if (!v2->e) - BM_vert_kill(bm, v1); + BM_vert_kill(bm, v2); continue; } diff --git a/source/blender/bmesh/operators/bmo_inset.c b/source/blender/bmesh/operators/bmo_inset.c index 3aa6e6dbe49..132d7050b31 100644 --- a/source/blender/bmesh/operators/bmo_inset.c +++ b/source/blender/bmesh/operators/bmo_inset.c @@ -283,7 +283,8 @@ void bmo_inset_exec(BMesh *bm, BMOperator *op) * cross product between both face normals */ add_v3_v3v3(tvec, e_info_a->no, e_info_b->no); - if ((f_a == f_b) || compare_v3v3(f_a->no, f_b->no, 0.00001f)) { + /* epsilon increased to fix [#32329] */ + if ((f_a == f_b) || compare_v3v3(f_a->no, f_b->no, 0.001f)) { normalize_v3(tvec); } else { diff --git a/source/blender/bmesh/operators/bmo_subdivide.c b/source/blender/bmesh/operators/bmo_subdivide.c index 2af764060fb..b239be1c83b 100644 --- a/source/blender/bmesh/operators/bmo_subdivide.c +++ b/source/blender/bmesh/operators/bmo_subdivide.c @@ -308,7 +308,7 @@ static void quad_1edge_split(BMesh *bm, BMFace *UNUSED(face), } } -static SubDPattern quad_1edge = { +static const SubDPattern quad_1edge = { {1, 0, 0, 0}, quad_1edge_split, 4, @@ -337,7 +337,7 @@ static void quad_2edge_split_path(BMesh *bm, BMFace *UNUSED(face), BMVert **vert connect_smallest_face(bm, verts[numcuts * 2 + 3], verts[numcuts * 2 + 1], &nf); } -static SubDPattern quad_2edge_path = { +static const SubDPattern quad_2edge_path = { {1, 1, 0, 0}, quad_2edge_split_path, 4, @@ -379,7 +379,7 @@ static void quad_2edge_split_innervert(BMesh *bm, BMFace *UNUSED(face), BMVert * connect_smallest_face(bm, lastv, verts[numcuts * 2 + 2], &nf); } -static SubDPattern quad_2edge_innervert = { +static const SubDPattern quad_2edge_innervert = { {1, 1, 0, 0}, quad_2edge_split_innervert, 4, @@ -410,7 +410,7 @@ static void quad_2edge_split_fan(BMesh *bm, BMFace *UNUSED(face), BMVert **verts } } -static SubDPattern quad_2edge_fan = { +static const SubDPattern quad_2edge_fan = { {1, 1, 0, 0}, quad_2edge_split_fan, 4, @@ -449,7 +449,7 @@ static void quad_3edge_split(BMesh *bm, BMFace *UNUSED(face), BMVert **verts, } } -static SubDPattern quad_3edge = { +static const SubDPattern quad_3edge = { {1, 1, 1, 0}, quad_3edge_split, 4, @@ -559,7 +559,7 @@ static void tri_1edge_split(BMesh *bm, BMFace *UNUSED(face), BMVert **verts, } } -static SubDPattern tri_1edge = { +static const SubDPattern tri_1edge = { {1, 0, 0}, tri_1edge_split, 3, @@ -660,51 +660,55 @@ cleanup: MEM_freeN(lines); } -static SubDPattern tri_3edge = { +static const SubDPattern tri_3edge = { {1, 1, 1}, tri_3edge_subdivide, 3, }; -static SubDPattern quad_4edge = { +static const SubDPattern quad_4edge = { {1, 1, 1, 1}, quad_4edge_subdivide, 4, }; -static SubDPattern *patterns[] = { - NULL, //quad single edge pattern is inserted here - NULL, //quad corner vert pattern is inserted here - NULL, //tri single edge pattern is inserted here +static const SubDPattern *patterns[] = { + NULL, /* quad single edge pattern is inserted here */ + NULL, /* quad corner vert pattern is inserted here */ + NULL, /* tri single edge pattern is inserted here */ NULL, &quad_3edge, NULL, }; -#define PLEN (sizeof(patterns) / sizeof(void *)) +#define PATTERNS_TOT (sizeof(patterns) / sizeof(void *)) typedef struct SubDFaceData { - BMVert *start; SubDPattern *pat; - int totedgesel; //only used if pat was NULL, e.g. no pattern was found + BMVert *start; + const SubDPattern *pat; + int totedgesel; /* only used if pat was NULL, e.g. no pattern was found */ BMFace *face; } SubDFaceData; void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) { BMOpSlot *einput; - SubDPattern *pat; + const SubDPattern *pat; SubDParams params; SubDFaceData *facedata = NULL; + BLI_array_declare(facedata); BMIter viter, fiter, liter; BMVert *v, **verts = NULL; - BMEdge *edge, **edges = NULL; - BMLoop *nl, *l, **splits = NULL, **loops = NULL; - BMFace *face; - BLI_array_declare(splits); - BLI_array_declare(loops); - BLI_array_declare(facedata); + BMEdge *edge; + BMEdge **edges = NULL; BLI_array_declare(edges); + BMLoop *(*loops_split)[2] = NULL; + BLI_array_declare(loops_split); + BMLoop **loops = NULL; + BLI_array_declare(loops); + BMLoop *nl, *l; + BMFace *face; BLI_array_declare(verts); float smooth, fractal, along_normal; int use_sphere, cornertype, use_singleedge, use_gridfill; @@ -726,7 +730,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) BLI_srandom(seed); patterns[1] = NULL; - //straight cut is patterns[1] == NULL + /* straight cut is patterns[1] == NULL */ switch (cornertype) { case SUBD_PATH: patterns[1] = &quad_2edge_path; @@ -861,7 +865,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) continue; } - for (i = 0; i < PLEN; i++) { + for (i = 0; i < PATTERNS_TOT; i++) { pat = patterns[i]; if (!pat) { continue; @@ -935,12 +939,12 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) /* ok, no pattern. we still may be able to do something */ BLI_array_empty(loops); - BLI_array_empty(splits); + BLI_array_empty(loops_split); /* for case of two edges, connecting them shouldn't be too hard */ - BM_ITER_ELEM (l, &liter, face, BM_LOOPS_OF_FACE) { - BLI_array_grow_one(loops); - loops[BLI_array_count(loops) - 1] = l; + BLI_array_grow_items(loops, face->len); + BM_ITER_ELEM_INDEX (l, &liter, face, BM_LOOPS_OF_FACE, a) { + loops[a] = l; } vlen = BLI_array_count(loops); @@ -971,23 +975,65 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) b += numcuts - 1; + BLI_array_grow_items(loops_split, numcuts); for (j = 0; j < numcuts; j++) { - BLI_array_grow_one(splits); - splits[BLI_array_count(splits) - 1] = loops[a]; - - BLI_array_grow_one(splits); - splits[BLI_array_count(splits) - 1] = loops[b]; + int ok = TRUE; + + /* Check for special case: [#32500] + * This edge pair could be used by more then one face, + * in this case it used to (2.63), split both faces along the same verts + * while it could be calculated which face should do the split, + * its ambigious, so in this case we're better off to skip them as exceptional cases + * and not try to be clever guessing which face to cut up. + * + * To avoid this case we need to check: + * Do the verts of each share a face besides the one we are subdividing, + * (but not connect to make an edge of that face). + */ + { + BMLoop *other_loop; + BMIter other_fiter; + BM_ITER_ELEM (other_loop, &other_fiter, loops[a]->v, BM_LOOPS_OF_VERT) { + if (other_loop->f != face) { + if (BM_vert_in_face(other_loop->f, loops[b]->v)) { + /* we assume that these verts are not making an edge in the face */ + BLI_assert(other_loop->prev->v != loops[a]->v); + BLI_assert(other_loop->next->v != loops[a]->v); + + ok = FALSE; + break; + } + } + } + } + + + if (ok == TRUE) { + loops_split[j][0] = loops[a]; + loops_split[j][1] = loops[b]; + } + else { + loops_split[j][0] = NULL; + loops_split[j][1] = NULL; + } b = (b - 1) % vlen; a = (a + 1) % vlen; } - //BM_face_legal_splits(bmesh, face, splits, BLI_array_count(splits) / 2); + /* Since these are newly created vertices, we don't need to worry about them being legal, + * ... though there are some cases we _should_ check for + * - concave corner of an ngon. + * - 2 edges being used in 2+ ngons. + */ +// BM_face_legal_splits(bm, face, loops_split, BLI_array_count(loops_split)); + + for (j = 0; j < BLI_array_count(loops_split); j++) { + if (loops_split[j][0]) { + BLI_assert(BM_edge_exists(loops_split[j][0]->v, loops_split[j][1]->v) == FALSE); - for (j = 0; j < BLI_array_count(splits) / 2; j++) { - if (splits[j * 2]) { /* BMFace *nf = */ /* UNUSED */ - BM_face_split(bm, face, splits[j * 2]->v, splits[j * 2 + 1]->v, &nl, NULL, FALSE); + BM_face_split(bm, face, loops_split[j][0]->v, loops_split[j][1]->v, &nl, NULL, FALSE); } } @@ -997,27 +1043,19 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) continue; } - j = a = 0; - for (nl = BM_iter_new(&liter, bm, BM_LOOPS_OF_FACE, face); - nl; - nl = BM_iter_step(&liter)) - { + a = 0; + BM_ITER_ELEM_INDEX (nl, &liter, face, BM_LOOPS_OF_FACE, j) { if (nl->v == facedata[i].start) { a = j + 1; break; } - j++; } - for (j = 0; j < face->len; j++) { - BLI_array_grow_one(verts); - } - - j = 0; - for (nl = BM_iter_new(&liter, bm, BM_LOOPS_OF_FACE, face); nl; nl = BM_iter_step(&liter)) { + BLI_array_grow_items(verts, face->len); + + BM_ITER_ELEM_INDEX (nl, &liter, face, BM_LOOPS_OF_FACE, j) { b = (j - a + face->len) % face->len; verts[b] = nl->v; - j += 1; } BM_CHECK_ELEMENT(face); @@ -1035,7 +1073,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) if (facedata) BLI_array_free(facedata); if (edges) BLI_array_free(edges); if (verts) BLI_array_free(verts); - BLI_array_free(splits); + BLI_array_free(loops_split); BLI_array_free(loops); BMO_slot_buffer_from_enabled_flag(bm, op, "outinner", BM_ALL, ELE_INNER); diff --git a/source/blender/bmesh/tools/BME_bevel.c b/source/blender/bmesh/tools/BME_bevel.c index 85beb6d092b..91527313972 100644 --- a/source/blender/bmesh/tools/BME_bevel.c +++ b/source/blender/bmesh/tools/BME_bevel.c @@ -38,7 +38,6 @@ #include "BLI_ghash.h" #include "BLI_memarena.h" -#include "BKE_utildefines.h" #include "BKE_tessmesh.h" #include "BKE_bmesh.h" diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp index d241926c20c..b2748a55b6a 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -683,12 +683,11 @@ void AnimationImporter::Assign_lens_animations(const COLLADAFW::UniqueId& listid for (unsigned int i = 0; i < fcu->totvert; i++) { double input_fov = fcu->bezt[i].vec[1][1]; - double xfov = (fov_type == CAMERA_YFOV) ? aspect * input_fov : input_fov; - // fov is in degrees, cam->lens is in millimiters - double fov = fov_to_focallength(DEG2RADF(input_fov), cam->sensor_x); + // NOTE: Needs more testing (As we curretnly have no official test data for this) + double xfov = (fov_type == CAMERA_YFOV) ? (2.0f * atanf(aspect * tanf(DEG2RADF(input_fov) * 0.5f))) : DEG2RADF(input_fov); - fcu->bezt[i].vec[1][1] = fov; + fcu->bezt[i].vec[1][1] = fov_to_focallength(xfov, cam->sensor_x); } BLI_addtail(AnimCurves, fcu); diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp index c47798ee804..7683ec1e9cd 100644 --- a/source/blender/collada/DocumentExporter.cpp +++ b/source/blender/collada/DocumentExporter.cpp @@ -99,7 +99,6 @@ extern char build_rev[]; #include "BKE_action.h" // pose functions #include "BKE_armature.h" #include "BKE_image.h" -#include "BKE_utildefines.h" #include "BKE_object.h" #include "BLI_math.h" @@ -164,6 +163,8 @@ void DocumentExporter::exportCurrentScene(Scene *sce) COLLADABU::NativeString(std::string(this->export_settings->filepath)); COLLADASW::StreamWriter sw(native_filename); + fprintf(stdout, "Collada export: %s\n", this->export_settings->filepath); + // open <collada> sw.startDocument(); diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 60b03a211ba..f29933ea0c1 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -62,13 +62,13 @@ extern "C" { #include "BKE_texture.h" #include "BKE_fcurve.h" #include "BKE_depsgraph.h" -#include "BLI_path_util.h" #include "BKE_scene.h" #include "BKE_global.h" #include "BKE_material.h" -#include "BKE_utildefines.h" #include "BKE_image.h" +#include "BLI_path_util.h" + #include "DNA_camera_types.h" #include "DNA_lamp_types.h" @@ -867,9 +867,11 @@ bool DocumentImporter::writeCamera(const COLLADAFW::Camera *camera) { double yfov = camera->getYFov().getValue(); double aspect = camera->getAspectRatio().getValue(); - double xfov = aspect * yfov; - // xfov is in degrees, cam->lens is in millimiters - cam->lens = fov_to_focallength(DEG2RADF(xfov), cam->sensor_x); + + // NOTE: Needs more testing (As we curretnly have no official test data for this) + + double xfov = 2.0f * atanf(aspect * tanf(DEG2RADF(yfov) * 0.5f)); + cam->lens = fov_to_focallength(xfov, cam->sensor_x); } break; } diff --git a/source/blender/collada/GeometryExporter.cpp b/source/blender/collada/GeometryExporter.cpp index c7ad2ff3975..27700444ba9 100644 --- a/source/blender/collada/GeometryExporter.cpp +++ b/source/blender/collada/GeometryExporter.cpp @@ -132,14 +132,17 @@ void GeometryExporter::operator()(Object *ob) createLooseEdgeList(ob, me, geom_id, norind); - // XXX slow - if (ob->totcol) { - for (int a = 0; a < ob->totcol; a++) { - createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind); + // Only create Polylists if number of faces > 0 + if (me->totface > 0) { + // XXX slow + if (ob->totcol) { + for (int a = 0; a < ob->totcol; a++) { + createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind); + } + } + else { + createPolylist(0, has_uvs, has_color, ob, me, geom_id, norind); } - } - else { - createPolylist(0, has_uvs, has_color, ob, me, geom_id, norind); } closeMesh(); @@ -248,7 +251,7 @@ void GeometryExporter::createPolylist(short material_index, // no faces using this material if (faces_in_polylist == 0) { - fprintf(stderr, "%s: no faces use material %d\n", id_name(ob).c_str(), material_index); + fprintf(stderr, "%s: material with index %d is not used.\n", id_name(ob).c_str(), material_index); return; } diff --git a/source/blender/collada/ImageExporter.cpp b/source/blender/collada/ImageExporter.cpp index 66dcec7d8e4..a15dadda8cf 100644 --- a/source/blender/collada/ImageExporter.cpp +++ b/source/blender/collada/ImageExporter.cpp @@ -39,7 +39,6 @@ extern "C" { #include "BKE_image.h" #include "BKE_main.h" #include "BKE_mesh.h" -#include "BKE_utildefines.h" #include "BLI_fileops.h" #include "BLI_path_util.h" #include "BLI_string.h" @@ -75,6 +74,7 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies) short image_source = image->source; bool is_generated = image_source == IMA_SRC_GENERATED; + bool is_packed = image->packedfile != NULL; char export_path[FILE_MAX]; char source_path[FILE_MAX]; @@ -84,7 +84,7 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies) // Destination folder for exported assets BLI_split_dir_part(this->export_settings->filepath, export_dir, sizeof(export_dir)); - if (is_generated || is_dirty || use_copies) { + if (is_generated || is_dirty || use_copies || is_packed) { // make absolute destination path @@ -97,7 +97,7 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies) BLI_make_existing_file(export_path); } - if (is_generated || is_dirty) { + if (is_generated || is_dirty || is_packed) { // This image in its current state only exists in Blender memory. // So we have to export it. The export will keep the image state intact, @@ -120,12 +120,15 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies) // This image is already located on the file system. // But we want to create copies here. - // To avoid overwroting images with same file name but - // differenet source locations - - if (BLI_copy(source_path, export_path) != 0) { - fprintf(stderr, "Collada export: Cannot copy image:\n source:%s\ndest :%s\n", source_path, export_path); - return; + // To move images into the same export directory. + // Note: If an image is already located in the export folder, + // then skip the copy (as it would result in a file copy error). + + if (BLI_path_cmp(source_path, export_path) != 0) { + if (BLI_copy(source_path, export_path) != 0) { + fprintf(stderr, "Collada export: Cannot copy image:\n source:%s\ndest :%s\n", source_path, export_path); + return; + } } BLI_strncpy(export_path, export_file, sizeof(export_path)); @@ -133,7 +136,7 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies) } else { - // Do not make any vopies, but use the source path directly as reference + // Do not make any copies, but use the source path directly as reference // to the original image BLI_strncpy(export_path, source_path, sizeof(export_path)); diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp index 5593fe993f4..cf211e2fbb1 100644 --- a/source/blender/collada/MeshImporter.cpp +++ b/source/blender/collada/MeshImporter.cpp @@ -570,7 +570,7 @@ void MeshImporter::read_lines(COLLADAFW::Mesh *mesh, Mesh *me) if (loose_edge_count > 0) { unsigned int face_edge_count = me->totedge; - unsigned int total_edge_count = loose_edge_count + face_edge_count; + /* unsigned int total_edge_count = loose_edge_count + face_edge_count; */ /* UNUSED */ mesh_add_edges(me, loose_edge_count); MEdge *med = me->medge + face_edge_count; diff --git a/source/blender/compositor/COM_compositor.h b/source/blender/compositor/COM_compositor.h index d9cfae8edb9..f35bf71392c 100644 --- a/source/blender/compositor/COM_compositor.h +++ b/source/blender/compositor/COM_compositor.h @@ -277,6 +277,9 @@ extern "C" { * It can be executed during editing (blenkernel/node.c) or rendering * (renderer/pipeline.c) * + * @param rd [struct RenderData] + * Render data for this composite, this won't always belong to a scene. + * * @param editingtree [struct bNodeTree] * reference to the compositor editing tree * @@ -301,10 +304,17 @@ void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering); /** * @brief Deinitialize the compositor caches and allocated memory. + * Use COM_clearCaches to only free the caches. */ void COM_deinitialize(void); /** + * @brief Clear all compositor caches. (Compositor system will still remain available). + * To deinitialize the compositor use the COM_deinitialize method. + */ +// void COM_clearCaches(void); // NOT YET WRITTEN + +/** * @brief Return a list of highlighted bnodes pointers. * @return */ diff --git a/source/blender/compositor/intern/COM_Converter.cpp b/source/blender/compositor/intern/COM_Converter.cpp index d4fad80ed07..71067ac8f15 100644 --- a/source/blender/compositor/intern/COM_Converter.cpp +++ b/source/blender/compositor/intern/COM_Converter.cpp @@ -500,7 +500,8 @@ void Converter::convertResolution(SocketConnection *connection, ExecutionSystem system->addOperation(sxop); system->addOperation(syop); - unsigned int resolution[2] = {fromWidth, fromHeight}; + unsigned int resolution[2] = {fromOperation->getWidth(), + fromOperation->getHeight()}; scaleOperation->setResolution(resolution); sxop->setResolution(resolution); syop->setResolution(resolution); @@ -522,7 +523,8 @@ void Converter::convertResolution(SocketConnection *connection, ExecutionSystem system->addOperation(xop); system->addOperation(yop); - unsigned int resolution[2] = {toWidth, toHeight}; + unsigned int resolution[2] = {toOperation->getWidth(), + toOperation->getHeight()}; translateOperation->setResolution(resolution); xop->setResolution(resolution); yop->setResolution(resolution); diff --git a/source/blender/compositor/intern/COM_Device.h b/source/blender/compositor/intern/COM_Device.h index e33a2a4288f..dc39b2baca7 100644 --- a/source/blender/compositor/intern/COM_Device.h +++ b/source/blender/compositor/intern/COM_Device.h @@ -31,8 +31,15 @@ * work are packaged as a WorkPackage instance. */ class Device { + public: /** + * @brief Declaration of the virtual destructor + * @note resolve warning gcc 4.7 + */ + virtual ~Device() {} + + /** * @brief initialize the device */ virtual bool initialize() { return true; } diff --git a/source/blender/compositor/intern/COM_ExecutionSystemHelper.h b/source/blender/compositor/intern/COM_ExecutionSystemHelper.h index bd34fe8ab02..307e082ea80 100644 --- a/source/blender/compositor/intern/COM_ExecutionSystemHelper.h +++ b/source/blender/compositor/intern/COM_ExecutionSystemHelper.h @@ -55,7 +55,7 @@ public: * this node is converted to a Node instance. * and the converted node is returned * - * @param bNode node to add + * @param b_node node to add * @return Node that represents the bNode or null when not able to convert. */ static Node *addNode(vector<Node *>& nodes, bNode *b_node, bool isInActiveGroup, bool fast); diff --git a/source/blender/compositor/intern/COM_Node.cpp b/source/blender/compositor/intern/COM_Node.cpp index 320baacb669..50393d14f35 100644 --- a/source/blender/compositor/intern/COM_Node.cpp +++ b/source/blender/compositor/intern/COM_Node.cpp @@ -137,6 +137,21 @@ void Node::addSetVectorOperation(ExecutionSystem *graph, InputSocket *inputsocke graph->addOperation(operation); } +/* when a node has no valid data (missing image or group pointer) */ +void Node::convertToOperations_invalid(ExecutionSystem *graph, CompositorContext *context) +{ + /* this is a really bad situation - bring on the pink! - so artists know this is bad */ + const float warning_color[4] = {1.0f, 0.0f, 1.0f, 1.0f}; + int index; + vector<OutputSocket *> &outputsockets = this->getOutputSockets(); + for (index = 0; index < outputsockets.size(); index++) { + SetColorOperation *operation = new SetColorOperation(); + this->getOutputSocket(index)->relinkConnections(operation->getOutputSocket()); + operation->setChannels(warning_color); + graph->addOperation(operation); + } +} + bNodeSocket *Node::getEditorInputSocket(int editorNodeInputSocketIndex) { bNodeSocket *bSock = (bNodeSocket *)this->getbNode()->inputs.first; diff --git a/source/blender/compositor/intern/COM_Node.h b/source/blender/compositor/intern/COM_Node.h index e19b1d774c9..7ce40e3cb34 100644 --- a/source/blender/compositor/intern/COM_Node.h +++ b/source/blender/compositor/intern/COM_Node.h @@ -100,6 +100,13 @@ public: void addSetVectorOperation(ExecutionSystem *graph, InputSocket *inputsocket, int editorNodeInputSocketIndex); /** + * when a node has no valid data (missing image or a group nodes ID pointer is NULL) + * call this function from #convertToOperations, this way the node sockets are converted + * into valid outputs, without this the compositor system gets confused and crashes, see [#32490] + */ + void convertToOperations_invalid(ExecutionSystem *graph, CompositorContext *context); + + /** * Creates a new link between an outputSocket and inputSocket and registrates the link to the graph * @return the new created link */ diff --git a/source/blender/compositor/intern/COM_NodeBase.h b/source/blender/compositor/intern/COM_NodeBase.h index 3c390f6bcdb..b55e444be80 100644 --- a/source/blender/compositor/intern/COM_NodeBase.h +++ b/source/blender/compositor/intern/COM_NodeBase.h @@ -71,13 +71,14 @@ protected: inline vector<OutputSocket *>& getOutputSockets() { return this->m_outputsockets; } -public: +protected: /** * @brief destructor * clean up memory related to this NodeBase. */ virtual ~NodeBase(); +public: /** * @brief get the reference to the SDNA bNode struct */ diff --git a/source/blender/compositor/intern/COM_NodeOperation.cpp b/source/blender/compositor/intern/COM_NodeOperation.cpp index bae884d713e..4ae114bd031 100644 --- a/source/blender/compositor/intern/COM_NodeOperation.cpp +++ b/source/blender/compositor/intern/COM_NodeOperation.cpp @@ -124,19 +124,26 @@ bool NodeOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOper return false; } else { - unsigned int index; - vector<InputSocket *> &inputsockets = this->getInputSockets(); - - for (index = 0; index < inputsockets.size(); index++) { - InputSocket *inputsocket = inputsockets[index]; - if (inputsocket->isConnected()) { - NodeOperation *inputoperation = (NodeOperation *)inputsocket->getConnection()->getFromNode(); - bool result = inputoperation->determineDependingAreaOfInterest(input, readOperation, output); - if (result) { - return true; + rcti tempOutput; + bool first = true; + for (int i = 0 ; i < getNumberOfInputSockets() ; i ++) { + NodeOperation * inputOperation = this->getInputOperation(i); + if (inputOperation && inputOperation->determineDependingAreaOfInterest(input, readOperation, &tempOutput)) { + if (first) { + output->xmin = tempOutput.xmin; + output->ymin = tempOutput.ymin; + output->xmax = tempOutput.xmax; + output->ymax = tempOutput.ymax; + first = false; + } + else { + output->xmin = MIN2(output->xmin, tempOutput.xmin); + output->ymin = MIN2(output->ymin, tempOutput.ymin); + output->xmax = MAX2(output->xmax, tempOutput.xmax); + output->ymax = MAX2(output->ymax, tempOutput.ymax); } } } - return false; + return !first; } } diff --git a/source/blender/compositor/intern/COM_OpenCLDevice.cpp b/source/blender/compositor/intern/COM_OpenCLDevice.cpp index be5936b495e..d23ed245844 100644 --- a/source/blender/compositor/intern/COM_OpenCLDevice.cpp +++ b/source/blender/compositor/intern/COM_OpenCLDevice.cpp @@ -110,7 +110,7 @@ void OpenCLDevice::COM_clAttachSizeToKernelParameter(cl_kernel kernel, int offse { if (offsetIndex != -1) { cl_int error; - cl_int2 offset = {operation->getWidth(), operation->getHeight()}; + cl_int2 offset = {(cl_int)operation->getWidth(), (cl_int)operation->getHeight()}; error = clSetKernelArg(kernel, offsetIndex, sizeof(cl_int2), &offset); if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } @@ -127,7 +127,7 @@ void OpenCLDevice::COM_clAttachOutputMemoryBufferToKernelParameter(cl_kernel ker void OpenCLDevice::COM_clEnqueueRange(cl_kernel kernel, MemoryBuffer *outputMemoryBuffer) { cl_int error; - const size_t size[] = {outputMemoryBuffer->getWidth(), outputMemoryBuffer->getHeight()}; + const size_t size[] = {(size_t)outputMemoryBuffer->getWidth(), (size_t)outputMemoryBuffer->getHeight()}; error = clEnqueueNDRangeKernel(this->m_queue, kernel, 2, NULL, size, 0, 0, 0, NULL); if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } @@ -144,7 +144,10 @@ void OpenCLDevice::COM_clEnqueueRange(cl_kernel kernel, MemoryBuffer *outputMemo size_t size[2]; cl_int2 offset; - if (this->m_vendorID == NVIDIA) {localSize = 32;} + if (this->m_vendorID == NVIDIA) { + localSize = 32; + } + bool breaked = false; for (offsety = 0; offsety < height && (!breaked); offsety += localSize) { offset[1] = offsety; @@ -154,6 +157,7 @@ void OpenCLDevice::COM_clEnqueueRange(cl_kernel kernel, MemoryBuffer *outputMemo else { size[1] = height - offsety; } + for (offsetx = 0; offsetx < width && (!breaked); offsetx += localSize) { if (offsetx + localSize < width) { size[0] = localSize; diff --git a/source/blender/compositor/intern/COM_Socket.h b/source/blender/compositor/intern/COM_Socket.h index 2aebe262594..bad112d20c7 100644 --- a/source/blender/compositor/intern/COM_Socket.h +++ b/source/blender/compositor/intern/COM_Socket.h @@ -62,6 +62,14 @@ private: DataType m_datatype; bNodeSocket *m_editorSocket; + +protected: + /** + * @brief Declaration of the virtual destructor + * @note resolve warning gcc 4.7 + */ + virtual ~Socket() {} + public: Socket(DataType datatype); diff --git a/source/blender/compositor/intern/COM_WorkScheduler.cpp b/source/blender/compositor/intern/COM_WorkScheduler.cpp index 5f133fe071f..f732a40e768 100644 --- a/source/blender/compositor/intern/COM_WorkScheduler.cpp +++ b/source/blender/compositor/intern/COM_WorkScheduler.cpp @@ -54,6 +54,7 @@ static vector<CPUDevice *> g_cpudevices; #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE /// @brief list of all thread for every CPUDevice in cpudevices a thread exists static ListBase g_cputhreads; +static bool g_cpuInitialized = false; /// @brief all scheduled work for the cpu static ThreadQueue *g_cpuqueue; static ThreadQueue *g_gpuqueue; @@ -67,11 +68,13 @@ static ListBase g_gputhreads; /// @brief all scheduled work for the gpu #ifdef COM_OPENCL_ENABLED static bool g_openclActive = false; +static bool g_openclInitialized = false; #endif #endif #endif #define MAX_HIGHLIGHT 8 +static bool g_highlightInitialized = false; extern "C" { int g_highlightIndex; void **g_highlightedNodes; @@ -90,8 +93,10 @@ void **g_highlightedNodesRead; if (node->original) { \ node = node->original; \ } \ - if (g_highlightIndex < MAX_HIGHLIGHT) { \ - g_highlightedNodes[g_highlightIndex++] = node; \ + if (g_highlightInitialized && g_highlightedNodes) { \ + if (g_highlightIndex < MAX_HIGHLIGHT) { \ + g_highlightedNodes[g_highlightIndex++] = node; \ + } \ } \ } \ } \ @@ -100,7 +105,13 @@ void **g_highlightedNodesRead; void COM_startReadHighlights() { - if (g_highlightedNodesRead) { + if (!g_highlightInitialized) + { + return; + } + + if (g_highlightedNodesRead) + { MEM_freeN(g_highlightedNodesRead); } @@ -111,11 +122,15 @@ void COM_startReadHighlights() int COM_isHighlightedbNode(bNode *bnode) { + if (!g_highlightInitialized) { + return false; + } + if (!g_highlightedNodesRead) { return false; } - for (int i = 0 ; i < MAX_HIGHLIGHT; i++) { + for (int i = 0; i < MAX_HIGHLIGHT; i++) { void *p = g_highlightedNodesRead[i]; if (!p) return false; if (p == bnode) return true; @@ -255,40 +270,59 @@ extern void clContextError(const char *errinfo, const void *private_info, size_t printf("OPENCL error: %s\n", errinfo); } -void WorkScheduler::initialize() +void WorkScheduler::initialize(bool use_opencl) { - if (g_highlightedNodesRead) MEM_freeN(g_highlightedNodesRead); - if (g_highlightedNodes) MEM_freeN(g_highlightedNodes); + /* initialize highlighting */ + if (!g_highlightInitialized) { + if (g_highlightedNodesRead) MEM_freeN(g_highlightedNodesRead); + if (g_highlightedNodes) MEM_freeN(g_highlightedNodes); + + g_highlightedNodesRead = NULL; + g_highlightedNodes = NULL; - g_highlightedNodesRead = NULL; - g_highlightedNodes = NULL; + COM_startReadHighlights(); + + g_highlightInitialized = true; + } - COM_startReadHighlights(); #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE - int numberOfCPUThreads = BLI_system_thread_count(); + /* initialize CPU threads */ + if (!g_cpuInitialized) { + int numberOfCPUThreads = BLI_system_thread_count(); - for (int index = 0; index < numberOfCPUThreads; index++) { - CPUDevice *device = new CPUDevice(); - device->initialize(); - g_cpudevices.push_back(device); + for (int index = 0; index < numberOfCPUThreads; index++) { + CPUDevice *device = new CPUDevice(); + device->initialize(); + g_cpudevices.push_back(device); + } + + g_cpuInitialized = true; } + #ifdef COM_OPENCL_ENABLED - g_context = NULL; - g_program = NULL; - if (clCreateContextFromType) { - cl_uint numberOfPlatforms = 0; - cl_int error; - error = clGetPlatformIDs(0, 0, &numberOfPlatforms); - if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } - if (G.f & G_DEBUG) printf("%d number of platforms\n", numberOfPlatforms); - cl_platform_id *platforms = (cl_platform_id *)MEM_mallocN(sizeof(cl_platform_id) * numberOfPlatforms, __func__); - error = clGetPlatformIDs(numberOfPlatforms, platforms, 0); - unsigned int indexPlatform; - for (indexPlatform = 0; indexPlatform < numberOfPlatforms; indexPlatform++) { - cl_platform_id platform = platforms[indexPlatform]; - cl_uint numberOfDevices = 0; - clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, 0, &numberOfDevices); - if (numberOfDevices > 0) { + /* deinitialize OpenCL GPU's */ + if (use_opencl && !g_openclInitialized) { + g_context = NULL; + g_program = NULL; + + OCL_init(); /* this will check and skip if already initialized */ + + if (clCreateContextFromType) { + cl_uint numberOfPlatforms = 0; + cl_int error; + error = clGetPlatformIDs(0, 0, &numberOfPlatforms); + if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } + if (G.f & G_DEBUG) printf("%d number of platforms\n", numberOfPlatforms); + cl_platform_id *platforms = (cl_platform_id *)MEM_mallocN(sizeof(cl_platform_id) * numberOfPlatforms, __func__); + error = clGetPlatformIDs(numberOfPlatforms, platforms, 0); + unsigned int indexPlatform; + for (indexPlatform = 0; indexPlatform < numberOfPlatforms; indexPlatform++) { + cl_platform_id platform = platforms[indexPlatform]; + cl_uint numberOfDevices = 0; + clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, 0, &numberOfDevices); + if (numberOfDevices <= 0) + continue; + cl_device_id *cldevices = (cl_device_id *)MEM_mallocN(sizeof(cl_device_id) * numberOfDevices, __func__); clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numberOfDevices, cldevices, 0); @@ -324,8 +358,10 @@ void WorkScheduler::initialize() } MEM_freeN(cldevices); } + MEM_freeN(platforms); } - MEM_freeN(platforms); + + g_openclInitialized = true; } #endif #endif @@ -334,37 +370,55 @@ void WorkScheduler::initialize() void WorkScheduler::deinitialize() { #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE - Device *device; - while (g_cpudevices.size() > 0) { - device = g_cpudevices.back(); - g_cpudevices.pop_back(); - device->deinitialize(); - delete device; + /* deinitialize CPU threads */ + if (g_cpuInitialized) { + Device *device; + while (g_cpudevices.size() > 0) { + device = g_cpudevices.back(); + g_cpudevices.pop_back(); + device->deinitialize(); + delete device; + } + + g_cpuInitialized = false; } + #ifdef COM_OPENCL_ENABLED - while (g_gpudevices.size() > 0) { - device = g_gpudevices.back(); - g_gpudevices.pop_back(); - device->deinitialize(); - delete device; - } - if (g_program) { - clReleaseProgram(g_program); - g_program = NULL; - } - if (g_context) { - clReleaseContext(g_context); - g_context = NULL; + /* deinitialize OpenCL GPU's */ + if (g_openclInitialized) { + Device *device; + while (g_gpudevices.size() > 0) { + device = g_gpudevices.back(); + g_gpudevices.pop_back(); + device->deinitialize(); + delete device; + } + if (g_program) { + clReleaseProgram(g_program); + g_program = NULL; + } + if (g_context) { + clReleaseContext(g_context); + g_context = NULL; + } + + g_openclInitialized = false; } #endif #endif - if (g_highlightedNodes) { - MEM_freeN(g_highlightedNodes); - } + /* deinitialize highlighting */ + if (g_highlightInitialized) { + g_highlightInitialized = false; + if (g_highlightedNodes) { + MEM_freeN(g_highlightedNodes); + g_highlightedNodes = NULL; + } - if (g_highlightedNodesRead) { - MEM_freeN(g_highlightedNodesRead); + if (g_highlightedNodesRead) { + MEM_freeN(g_highlightedNodesRead); + g_highlightedNodesRead = NULL; + } } } diff --git a/source/blender/compositor/intern/COM_WorkScheduler.h b/source/blender/compositor/intern/COM_WorkScheduler.h index f56fe94201e..4ab23cf9ae4 100644 --- a/source/blender/compositor/intern/COM_WorkScheduler.h +++ b/source/blender/compositor/intern/COM_WorkScheduler.h @@ -74,8 +74,10 @@ public: * After mutex initialization the system is queried in order to count the number of CPUDevices and GPUDevices to be created. * For every hardware thread a CPUDevice and for every OpenCL GPU device a OpenCLDevice is created. * these devices are stored in a separate list (cpudevices & gpudevices) + * + * This function can be called multiple times to lazily initialize OpenCL. */ - static void initialize(); + static void initialize(bool use_opencl); /** * @brief deinitialize the WorkScheduler diff --git a/source/blender/compositor/intern/COM_compositor.cpp b/source/blender/compositor/intern/COM_compositor.cpp index 7dcb3572a14..cb9166c929d 100644 --- a/source/blender/compositor/intern/COM_compositor.cpp +++ b/source/blender/compositor/intern/COM_compositor.cpp @@ -36,29 +36,39 @@ extern "C" { static ThreadMutex s_compositorMutex; static char is_compositorMutex_init = FALSE; + +void intern_freeCompositorCaches() +{ + deintializeDistortionCache(); +} + void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering) { - if (is_compositorMutex_init == FALSE) { /// TODO: move to blender startup phase - memset(&s_compositorMutex, 0, sizeof(s_compositorMutex)); + /* initialize mutex, TODO this mutex init is actually not thread safe and + * should be done somewhere as part of blender startup, all the other + * initializations can be done lazily */ + if (is_compositorMutex_init == FALSE) { BLI_mutex_init(&s_compositorMutex); - OCL_init(); - WorkScheduler::initialize(); ///TODO: call workscheduler.deinitialize somewhere is_compositorMutex_init = TRUE; } + BLI_mutex_lock(&s_compositorMutex); + if (editingtree->test_break(editingtree->tbh)) { // during editing multiple calls to this method can be triggered. // make sure one the last one will be doing the work. BLI_mutex_unlock(&s_compositorMutex); return; - } + /* initialize workscheduler, will check if already done. TODO deinitialize somewhere */ + bool use_opencl = (editingtree->flag & NTREE_COM_OPENCL); + WorkScheduler::initialize(use_opencl); /* set progress bar to 0% and status to init compositing */ editingtree->progress(editingtree->prh, 0.0); - bool twopass = (editingtree->flag&NTREE_TWO_PASS) > 0 && !rendering; + bool twopass = (editingtree->flag & NTREE_TWO_PASS) > 0 && !rendering; /* initialize execution system */ if (twopass) { ExecutionSystem *system = new ExecutionSystem(rd, editingtree, rendering, twopass); @@ -81,12 +91,20 @@ void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering) BLI_mutex_unlock(&s_compositorMutex); } +void COM_freeCaches() +{ + if (is_compositorMutex_init) { + BLI_mutex_lock(&s_compositorMutex); + intern_freeCompositorCaches(); + BLI_mutex_unlock(&s_compositorMutex); + } +} + void COM_deinitialize() { - if (is_compositorMutex_init) - { + if (is_compositorMutex_init) { BLI_mutex_lock(&s_compositorMutex); - deintializeDistortionCache(); + intern_freeCompositorCaches(); WorkScheduler::deinitialize(); is_compositorMutex_init = FALSE; BLI_mutex_unlock(&s_compositorMutex); diff --git a/source/blender/compositor/nodes/COM_GroupNode.cpp b/source/blender/compositor/nodes/COM_GroupNode.cpp index b1bc0966687..e10d7dbad2e 100644 --- a/source/blender/compositor/nodes/COM_GroupNode.cpp +++ b/source/blender/compositor/nodes/COM_GroupNode.cpp @@ -33,16 +33,7 @@ GroupNode::GroupNode(bNode *editorNode) : Node(editorNode) void GroupNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) { if (this->getbNode()->id == NULL) { - /* this is a really bad situation - bring on the pink! - so artists know this is bad */ - const float warning_color[4] = {1.0f, 0.0f, 1.0f, 1.0f}; - int index; - vector<OutputSocket *> &outputsockets = this->getOutputSockets(); - for (index = 0; index < outputsockets.size(); index++) { - SetColorOperation *operation = new SetColorOperation(); - this->getOutputSocket(index)->relinkConnections(operation->getOutputSocket()); - operation->setChannels(warning_color); - graph->addOperation(operation); - } + convertToOperations_invalid(graph, context); } } diff --git a/source/blender/compositor/nodes/COM_ImageNode.cpp b/source/blender/compositor/nodes/COM_ImageNode.cpp index addde140b9f..2d13ffb82b6 100644 --- a/source/blender/compositor/nodes/COM_ImageNode.cpp +++ b/source/blender/compositor/nodes/COM_ImageNode.cpp @@ -72,12 +72,16 @@ void ImageNode::convertToOperations(ExecutionSystem *graph, CompositorContext *c /* force a load, we assume iuser index will be set OK anyway */ if (image && image->type == IMA_TYPE_MULTILAYER) { + bool is_multilayer_ok = false; BKE_image_get_ibuf(image, imageuser); if (image->rr) { RenderLayer *rl = (RenderLayer *)BLI_findlink(&image->rr->layers, imageuser->layer); if (rl) { OutputSocket *socket; int index; + + is_multilayer_ok = true; + for (index = 0; index < numberOfOutputs; index++) { socket = this->getOutputSocket(index); if (socket->isConnected() || index == 0) { @@ -114,6 +118,11 @@ void ImageNode::convertToOperations(ExecutionSystem *graph, CompositorContext *c } } } + + /* without this, multilayer that fail to load will crash blender [#32490] */ + if (is_multilayer_ok == false) { + convertToOperations_invalid(graph, context); + } } else { if (numberOfOutputs > 0) { diff --git a/source/blender/compositor/nodes/COM_MovieClipNode.cpp b/source/blender/compositor/nodes/COM_MovieClipNode.cpp index a250841b160..6d5b9bba8aa 100644 --- a/source/blender/compositor/nodes/COM_MovieClipNode.cpp +++ b/source/blender/compositor/nodes/COM_MovieClipNode.cpp @@ -49,10 +49,14 @@ void MovieClipNode::convertToOperations(ExecutionSystem *graph, CompositorContex bNode *editorNode = this->getbNode(); MovieClip *movieClip = (MovieClip *)editorNode->id; MovieClipUser *movieClipUser = (MovieClipUser *)editorNode->storage; - + bool cacheFrame = !context->isRendering(); + ImBuf *ibuf = NULL; if (movieClip) { - ibuf = BKE_movieclip_get_ibuf(movieClip, movieClipUser); + if (cacheFrame) + ibuf = BKE_movieclip_get_ibuf(movieClip, movieClipUser); + else + ibuf = BKE_movieclip_get_ibuf_flag(movieClip, movieClipUser, movieClip->flag, MOVIECLIP_CACHE_SKIP); } // always connect the output image @@ -78,10 +82,11 @@ void MovieClipNode::convertToOperations(ExecutionSystem *graph, CompositorContex outputMovieClip->relinkConnections(operation->getOutputSocket()); } } + operation->setMovieClip(movieClip); operation->setMovieClipUser(movieClipUser); operation->setFramenumber(context->getFramenumber()); - operation->setCacheFrame(!context->isRendering()); + operation->setCacheFrame(cacheFrame); graph->addOperation(operation); MovieTrackingStabilization *stab = &movieClip->tracking.stabilization; diff --git a/source/blender/compositor/nodes/COM_OutputFileNode.cpp b/source/blender/compositor/nodes/COM_OutputFileNode.cpp index e85f521def0..b8cee29fee6 100644 --- a/source/blender/compositor/nodes/COM_OutputFileNode.cpp +++ b/source/blender/compositor/nodes/COM_OutputFileNode.cpp @@ -24,8 +24,8 @@ #include "COM_OutputFileNode.h" #include "COM_OutputFileOperation.h" #include "COM_ExecutionSystem.h" + #include "BLI_path_util.h" -#include "BKE_utildefines.h" OutputFileNode::OutputFileNode(bNode *editorNode) : Node(editorNode) { diff --git a/source/blender/compositor/operations/COM_AntiAliasOperation.cpp b/source/blender/compositor/operations/COM_AntiAliasOperation.cpp index c37830a9d92..867053bf1d2 100644 --- a/source/blender/compositor/operations/COM_AntiAliasOperation.cpp +++ b/source/blender/compositor/operations/COM_AntiAliasOperation.cpp @@ -23,7 +23,6 @@ #include "COM_AntiAliasOperation.h" #include "BLI_math.h" #include "BLI_utildefines.h" -#include "BKE_utildefines.h" #include "MEM_guardedalloc.h" diff --git a/source/blender/compositor/operations/COM_CombineChannelsOperation.cpp b/source/blender/compositor/operations/COM_CombineChannelsOperation.cpp index ded686bb5de..3ced0548bb8 100644 --- a/source/blender/compositor/operations/COM_CombineChannelsOperation.cpp +++ b/source/blender/compositor/operations/COM_CombineChannelsOperation.cpp @@ -37,31 +37,6 @@ CombineChannelsOperation::CombineChannelsOperation() : NodeOperation() this->m_inputChannel4Operation = NULL; } -bool CombineChannelsOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) -{ - rcti tempOutput; - bool first = true; - for (int i = 0 ; i < 4 ; i ++) { - NodeOperation * inputOperation = this->getInputOperation(i); - if (inputOperation->determineDependingAreaOfInterest(input, readOperation, &tempOutput)) { - if (first) { - output->xmin = tempOutput.xmin; - output->ymin = tempOutput.ymin; - output->xmax = tempOutput.xmax; - output->ymax = tempOutput.ymax; - first = false; - } - else { - output->xmin = MIN2(output->xmin, tempOutput.xmin); - output->ymin = MIN2(output->ymin, tempOutput.ymin); - output->xmax = MAX2(output->xmax, tempOutput.xmax); - output->ymax = MAX2(output->ymax, tempOutput.ymax); - } - } - } - return !first; -} - void CombineChannelsOperation::initExecution() { this->m_inputChannel1Operation = this->getInputSocketReader(0); @@ -82,7 +57,6 @@ void CombineChannelsOperation::deinitExecution() void CombineChannelsOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float input[4]; - /// @todo: remove if statements if (this->m_inputChannel1Operation) { this->m_inputChannel1Operation->read(input, x, y, sampler); output[0] = input[0]; diff --git a/source/blender/compositor/operations/COM_CombineChannelsOperation.h b/source/blender/compositor/operations/COM_CombineChannelsOperation.h index 460eb9bdcb1..7c8742b1557 100644 --- a/source/blender/compositor/operations/COM_CombineChannelsOperation.h +++ b/source/blender/compositor/operations/COM_CombineChannelsOperation.h @@ -37,8 +37,6 @@ public: void initExecution(); void deinitExecution(); - - bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); }; #endif diff --git a/source/blender/compositor/operations/COM_CompositorOperation.h b/source/blender/compositor/operations/COM_CompositorOperation.h index ae94e974db0..c1d91c16a3c 100644 --- a/source/blender/compositor/operations/COM_CompositorOperation.h +++ b/source/blender/compositor/operations/COM_CompositorOperation.h @@ -31,6 +31,9 @@ */ class CompositorOperation : public NodeOperation { private: + /** + * @brief Scene name, used for getting the render output, includes 'SC' prefix. + */ char m_sceneName[MAX_ID_NAME]; /** diff --git a/source/blender/compositor/operations/COM_MaskOperation.cpp b/source/blender/compositor/operations/COM_MaskOperation.cpp index a156dfc1d99..36b3f2023ae 100644 --- a/source/blender/compositor/operations/COM_MaskOperation.cpp +++ b/source/blender/compositor/operations/COM_MaskOperation.cpp @@ -93,7 +93,7 @@ void MaskOperation::initExecution() frame_iter += frame_step; } - BKE_mask_free(mask_temp); + BKE_mask_free_nolib(mask_temp); MEM_freeN(mask_temp); } } diff --git a/source/blender/compositor/operations/COM_MovieClipOperation.cpp b/source/blender/compositor/operations/COM_MovieClipOperation.cpp index b73db74b061..709e4b7d4b0 100644 --- a/source/blender/compositor/operations/COM_MovieClipOperation.cpp +++ b/source/blender/compositor/operations/COM_MovieClipOperation.cpp @@ -48,14 +48,10 @@ void MovieClipOperation::initExecution() BKE_movieclip_user_set_frame(this->m_movieClipUser, this->m_framenumber); ImBuf *ibuf; - if (this->m_cacheFrame) { + if (this->m_cacheFrame) ibuf = BKE_movieclip_get_ibuf(this->m_movieClip, this->m_movieClipUser); - } - else { - int flag = this->m_movieClip->flag & MCLIP_TIMECODE_FLAGS; - - ibuf = BKE_movieclip_get_ibuf_flag(this->m_movieClip, this->m_movieClipUser, flag, MOVIECLIP_CACHE_SKIP); - } + else + ibuf = BKE_movieclip_get_ibuf_flag(this->m_movieClip, this->m_movieClipUser, this->m_movieClip->flag, MOVIECLIP_CACHE_SKIP); if (ibuf) { this->m_movieClipBuffer = ibuf; diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.h b/source/blender/compositor/operations/COM_OutputFileOperation.h index 0d6e5bfa61a..532242c97ce 100644 --- a/source/blender/compositor/operations/COM_OutputFileOperation.h +++ b/source/blender/compositor/operations/COM_OutputFileOperation.h @@ -24,8 +24,9 @@ #ifndef _COM_OutputFileOperation_h #define _COM_OutputFileOperation_h #include "COM_NodeOperation.h" + #include "BLI_rect.h" -#include "BKE_utildefines.h" +#include "BLI_path_util.h" #include "intern/openexr/openexr_multi.h" diff --git a/source/blender/compositor/operations/COM_RenderLayersImageProg.h b/source/blender/compositor/operations/COM_RenderLayersImageProg.h index 2d63bad235b..5fa74c8b21f 100644 --- a/source/blender/compositor/operations/COM_RenderLayersImageProg.h +++ b/source/blender/compositor/operations/COM_RenderLayersImageProg.h @@ -25,7 +25,7 @@ #include "COM_RenderLayersBaseProg.h" -/// @TODO rename to image operation +/// @todo rename to image operation class RenderLayersColorProg : public RenderLayersBaseProg { public: RenderLayersColorProg(); diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c index eb9889ce847..f220f0ee762 100644 --- a/source/blender/editors/animation/anim_channels_defines.c +++ b/source/blender/editors/animation/anim_channels_defines.c @@ -62,7 +62,6 @@ #include "BKE_curve.h" #include "BKE_key.h" #include "BKE_context.h" -#include "BKE_utildefines.h" /* FILE_MAX */ #include "UI_interface.h" #include "UI_interface_icons.h" diff --git a/source/blender/editors/animation/anim_deps.c b/source/blender/editors/animation/anim_deps.c index 3255bc47148..6ce9fc638be 100644 --- a/source/blender/editors/animation/anim_deps.c +++ b/source/blender/editors/animation/anim_deps.c @@ -50,7 +50,6 @@ #include "BKE_global.h" #include "BKE_node.h" #include "BKE_sequencer.h" -#include "BKE_utildefines.h" #include "RNA_access.h" diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c index dd6778a79cd..7a80cab93e5 100644 --- a/source/blender/editors/animation/anim_filter.c +++ b/source/blender/editors/animation/anim_filter.c @@ -90,7 +90,6 @@ #include "BKE_node.h" #include "BKE_mask.h" #include "BKE_sequencer.h" -#include "BKE_utildefines.h" #include "ED_anim_api.h" #include "ED_markers.h" @@ -1409,13 +1408,13 @@ static size_t animdata_filter_mask_data(ListBase *anim_data, Mask *mask, const i /* only if selected */ if (ANIMCHANNEL_SELOK(SEL_MASKLAY(masklay)) ) { /* only if editable */ -// if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_GPL(gpl)) { + if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_MASK(masklay)) { /* active... */ if (!(filter_mode & ANIMFILTER_ACTIVE) || (masklay_act == masklay)) { /* add to list */ ANIMCHANNEL_NEW_CHANNEL(masklay, ANIMTYPE_MASKLAYER, mask); } -// } + } } } diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c index 95adaa01b94..445b684c261 100644 --- a/source/blender/editors/animation/anim_markers.c +++ b/source/blender/editors/animation/anim_markers.c @@ -1019,6 +1019,7 @@ static void select_timeline_marker_frame(ListBase *markers, int frame, unsigned static int ed_marker_select(bContext *C, wmEvent *evt, int extend, int camera) { ListBase *markers = ED_context_get_markers(C); + ARegion *ar = CTX_wm_region(C); View2D *v2d = UI_view2d_fromcontext(C); float viewx; int x, y, cfra; @@ -1026,8 +1027,8 @@ static int ed_marker_select(bContext *C, wmEvent *evt, int extend, int camera) if (markers == NULL) return OPERATOR_PASS_THROUGH; - x = evt->x - CTX_wm_region(C)->winrct.xmin; - y = evt->y - CTX_wm_region(C)->winrct.ymin; + x = evt->x - ar->winrct.xmin; + y = evt->y - ar->winrct.ymin; UI_view2d_region_to_view(v2d, x, y, &viewx, NULL); diff --git a/source/blender/editors/animation/keyframes_draw.c b/source/blender/editors/animation/keyframes_draw.c index 46537674e59..6c9105dde69 100644 --- a/source/blender/editors/animation/keyframes_draw.c +++ b/source/blender/editors/animation/keyframes_draw.c @@ -412,7 +412,7 @@ static void add_bezt_to_keyblocks_list(DLRBT_Tree *blocks, DLRBT_Tree *beztTree, * -> firstly, handles must have same central value as each other * -> secondly, handles which control that section of the curve must be constant */ - if ((!prev) || (!beztn)) return; + if (prev == NULL) return; if (IS_EQF(beztn->vec[1][1], prev->vec[1][1]) == 0) return; if (IS_EQF(beztn->vec[1][1], beztn->vec[0][1]) == 0) return; if (IS_EQF(prev->vec[1][1], prev->vec[2][1]) == 0) return; diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 3883dce7671..b5c0555bf63 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -45,7 +45,6 @@ #include "BKE_fcurve.h" -#include "BKE_utildefines.h" #include "BKE_report.h" #include "BKE_library.h" #include "BKE_global.h" diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index 3ef686910e6..8cd8cfaea51 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -164,10 +164,7 @@ FCurve *verify_fcurve(bAction *act, const char group[], PointerRNA *ptr, * - add if not found and allowed to add one * TODO: add auto-grouping support? how this works will need to be resolved */ - if (act) - fcu = list_find_fcurve(&act->curves, rna_path, array_index); - else - fcu = NULL; + fcu = list_find_fcurve(&act->curves, rna_path, array_index); if ((fcu == NULL) && (add)) { /* use default settings to make a F-Curve */ diff --git a/source/blender/editors/armature/poselib.c b/source/blender/editors/armature/poselib.c index 23c987c3536..eea7424c59a 100644 --- a/source/blender/editors/armature/poselib.c +++ b/source/blender/editors/armature/poselib.c @@ -1006,7 +1006,7 @@ static void poselib_preview_apply(bContext *C, wmOperator *op) /* get search-string */ index = pld->search_cursor; - if (index >= 0 && index <= sizeof(tempstr) - 1) { + if (index >= 0 && index < sizeof(tempstr) - 1) { memcpy(&tempstr[0], &pld->searchstr[0], index); tempstr[index] = '|'; memcpy(&tempstr[index + 1], &pld->searchstr[index], (sizeof(tempstr) - 1) - index); diff --git a/source/blender/editors/armature/poseobject.c b/source/blender/editors/armature/poseobject.c index cd2ca16fec5..e9424a08b0c 100644 --- a/source/blender/editors/armature/poseobject.c +++ b/source/blender/editors/armature/poseobject.c @@ -274,7 +274,7 @@ void POSE_OT_paths_calculate(wmOperatorType *ot) /* api callbacks */ ot->invoke = pose_calculate_paths_invoke; ot->exec = pose_calculate_paths_exec; - ot->poll = ED_operator_posemode; + ot->poll = ED_operator_posemode_exclusive; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -319,7 +319,7 @@ void POSE_OT_paths_update(wmOperatorType *ot) /* api callbakcs */ ot->exec = pose_update_paths_exec; - ot->poll = ED_operator_posemode; /* TODO: this should probably check for active bone and/or existing paths */ + ot->poll = ED_operator_posemode_exclusive; /* TODO: this should probably check for active bone and/or existing paths */ /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -380,7 +380,7 @@ void POSE_OT_paths_clear(wmOperatorType *ot) /* api callbacks */ ot->exec = pose_clear_paths_exec; - ot->poll = ED_operator_posemode; + ot->poll = ED_operator_posemode_exclusive; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -2192,7 +2192,7 @@ void POSE_OT_bone_layers(wmOperatorType *ot) /* callbacks */ ot->invoke = pose_bone_layers_invoke; ot->exec = pose_bone_layers_exec; - ot->poll = ED_operator_posemode; + ot->poll = ED_operator_posemode_exclusive; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -2350,20 +2350,18 @@ static int pose_clear_user_transforms_exec(bContext *C, wmOperator *op) for (pchan = dummyPose->chanbase.first; pchan; pchan = pchan->next) { pose_bone_do_paste(ob, pchan, only_select, 0); } - + /* free temp data - free manually as was copied without constraints */ - if (dummyPose) { - for (pchan = dummyPose->chanbase.first; pchan; pchan = pchan->next) { - if (pchan->prop) { - IDP_FreeProperty(pchan->prop); - MEM_freeN(pchan->prop); - } + for (pchan = dummyPose->chanbase.first; pchan; pchan = pchan->next) { + if (pchan->prop) { + IDP_FreeProperty(pchan->prop); + MEM_freeN(pchan->prop); } - - /* was copied without constraints */ - BLI_freelistN(&dummyPose->chanbase); - MEM_freeN(dummyPose); } + + /* was copied without constraints */ + BLI_freelistN(&dummyPose->chanbase); + MEM_freeN(dummyPose); } else { /* no animation, so just reset whole pose to rest pose diff --git a/source/blender/editors/armature/reeb.c b/source/blender/editors/armature/reeb.c index ce4e1db23b5..00f88a69fb6 100644 --- a/source/blender/editors/armature/reeb.c +++ b/source/blender/editors/armature/reeb.c @@ -3272,7 +3272,7 @@ ReebGraph *BIF_ReebGraphFromEditMesh(void) freeEdgeIndex(&indexed_edges); #ifdef DEBUG_REEB - weightToVCol(em, 1); +// weightToVCol(em, 1); #endif rg = generateReebGraph(em, G.scene->toolsettings->skgen_resolution); diff --git a/source/blender/editors/armature/reeb.h b/source/blender/editors/armature/reeb.h index d71e80ca0ca..bb8b3003baf 100644 --- a/source/blender/editors/armature/reeb.h +++ b/source/blender/editors/armature/reeb.h @@ -146,9 +146,9 @@ struct EdgeIndex; int weightToHarmonic(struct EditMesh *em, struct EdgeIndex *indexed_edges); int weightFromDistance(struct EditMesh *em, struct EdgeIndex *indexed_edges); int weightFromLoc(struct EditMesh *me, int axis); -void weightToVCol(struct EditMesh *em, int index); +//void weightToVCol(struct EditMesh *em, int index); void arcToVCol(struct ReebGraph *rg, struct EditMesh *em, int index); -void angleToVCol(struct EditMesh *em, int index); +//void angleToVCol(struct EditMesh *em, int index); void renormalizeWeight(struct EditMesh *em, float newmax); ReebGraph *generateReebGraph(struct EditMesh *me, int subdivisions); diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index e2d15897233..d780429784f 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -107,7 +107,7 @@ void selectend_nurb(Object *obedit, short selfirst, short doswap, short selstatu static void select_adjacent_cp(ListBase *editnurb, short next, short cont, short selstatus); /* still need to eradicate a few :( */ -#define callocstructN(x, y, name) (x *)MEM_callocN((y) * sizeof(x), name) +#define CALLOC_STRUCT_N(x, y, name) (x *)MEM_callocN((y) * sizeof(x), name) static float nurbcircle[8][2] = { {0.0, -1.0}, {-1.0, -1.0}, {-1.0, 0.0}, {-1.0, 1.0}, @@ -6265,7 +6265,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob) nu->pntsu = 4; nu->pntsv = 1; nu->orderu = 4; - nu->bp = callocstructN(BPoint, 4, "addNurbprim3"); + nu->bp = CALLOC_STRUCT_N(BPoint, 4, "addNurbprim3"); bp = nu->bp; for (a = 0; a < 4; a++, bp++) { @@ -6301,7 +6301,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob) nu->orderu = 5; nu->flagu = CU_NURB_ENDPOINT; /* endpoint */ nu->resolu = cu->resolu; - nu->bp = callocstructN(BPoint, 5, "addNurbprim3"); + nu->bp = CALLOC_STRUCT_N(BPoint, 5, "addNurbprim3"); bp = nu->bp; for (a = 0; a < 5; a++, bp++) { @@ -6334,7 +6334,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob) if (cutype == CU_BEZIER) { if (!force_3d) nu->flag |= CU_2D; nu->pntsu = 4; - nu->bezt = callocstructN(BezTriple, 4, "addNurbprim1"); + nu->bezt = CALLOC_STRUCT_N(BezTriple, 4, "addNurbprim1"); nu->flagu = CU_NURB_CYCLIC; bezt = nu->bezt; @@ -6371,7 +6371,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob) nu->pntsu = 8; nu->pntsv = 1; nu->orderu = 4; - nu->bp = callocstructN(BPoint, 8, "addNurbprim6"); + nu->bp = CALLOC_STRUCT_N(BPoint, 8, "addNurbprim6"); nu->flagu = CU_NURB_CYCLIC; bp = nu->bp; @@ -6404,7 +6404,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob) nu->orderu = 4; nu->orderv = 4; nu->flag = CU_SMOOTH; - nu->bp = callocstructN(BPoint, 4 * 4, "addNurbprim6"); + nu->bp = CALLOC_STRUCT_N(BPoint, 4 * 4, "addNurbprim6"); nu->flagu = 0; nu->flagv = 0; bp = nu->bp; @@ -6471,7 +6471,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob) nu->resolu = cu->resolu; nu->resolv = cu->resolv; nu->flag = CU_SMOOTH; - nu->bp = callocstructN(BPoint, 5, "addNurbprim6"); + nu->bp = CALLOC_STRUCT_N(BPoint, 5, "addNurbprim6"); nu->flagu = 0; bp = nu->bp; diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c index 7906d632f86..5a94d54f329 100644 --- a/source/blender/editors/gpencil/drawgpencil.c +++ b/source/blender/editors/gpencil/drawgpencil.c @@ -177,8 +177,8 @@ static void gp_draw_stroke_point(bGPDspoint *points, short thickness, short dfla /* if thickness is less than GP_DRAWTHICKNESS_SPECIAL, simple dot looks ok * - also mandatory in if Image Editor 'image-based' dot */ - if ( (thickness < GP_DRAWTHICKNESS_SPECIAL) || - ((dflag & GP_DRAWDATA_IEDITHACK) && (sflag & GP_STROKE_2DSPACE)) ) + if ((thickness < GP_DRAWTHICKNESS_SPECIAL) || + ((dflag & GP_DRAWDATA_IEDITHACK) && (sflag & GP_STROKE_2DSPACE))) { glBegin(GL_POINTS); glVertex2fv(co); @@ -253,8 +253,8 @@ static void gp_draw_stroke(bGPDspoint *points, int totpoints, short thickness_s, /* if thickness is less than GP_DRAWTHICKNESS_SPECIAL, 'smooth' opengl lines look better * - 'smooth' opengl lines are also required if Image Editor 'image-based' stroke */ - if ( (thickness < GP_DRAWTHICKNESS_SPECIAL) || - ((dflag & GP_DRAWDATA_IEDITHACK) && (dflag & GP_DRAWDATA_ONLYV2D)) ) + if ((thickness < GP_DRAWTHICKNESS_SPECIAL) || + ((dflag & GP_DRAWDATA_IEDITHACK) && (dflag & GP_DRAWDATA_ONLYV2D))) { bGPDspoint *pt; int i; diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index e4bfbea75b0..4e281b96fc3 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -27,7 +27,6 @@ * \ingroup edgpencil */ - #include <stdio.h> #include <stddef.h> #include <stdlib.h> @@ -778,7 +777,8 @@ static short gp_stroke_eraser_splitdel(bGPDframe *gpf, bGPDstroke *gps, int i) } /* eraser tool - check if part of stroke occurs within last segment drawn by eraser */ -static short gp_stroke_eraser_strokeinside(int mval[], int UNUSED(mvalo[]), short rad, short x0, short y0, short x1, short y1) +static short gp_stroke_eraser_strokeinside(const int mval[], const int UNUSED(mvalo[]), + int rad, int x0, int y0, int x1, int y1) { /* simple within-radius check for now */ if (edge_inside_circle(mval[0], mval[1], rad, x0, y0, x1, y1)) @@ -790,7 +790,9 @@ static short gp_stroke_eraser_strokeinside(int mval[], int UNUSED(mvalo[]), shor /* eraser tool - evaluation per stroke */ // TODO: this could really do with some optimization (KD-Tree/BVH?) -static void gp_stroke_eraser_dostroke(tGPsdata *p, int mval[], int mvalo[], short rad, rcti *rect, bGPDframe *gpf, bGPDstroke *gps) +static void gp_stroke_eraser_dostroke(tGPsdata *p, + const int mval[], const int mvalo[], + short rad, const rcti *rect, bGPDframe *gpf, bGPDstroke *gps) { bGPDspoint *pt1, *pt2; int x0 = 0, y0 = 0, x1 = 0, y1 = 0; @@ -827,7 +829,7 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p, int mval[], int mvalo[], shor /* do boundbox check first */ if (BLI_rcti_isect_pt(rect, x0, y0)) { /* only check if point is inside */ - if ( ((x0 - mval[0]) * (x0 - mval[0]) + (y0 - mval[1]) * (y0 - mval[1])) <= rad * rad) { + if (((x0 - mval[0]) * (x0 - mval[0]) + (y0 - mval[1]) * (y0 - mval[1])) <= rad * rad) { /* free stroke */ MEM_freeN(gps->points); BLI_freelinkN(&gpf->strokes, gps); diff --git a/source/blender/editors/gpencil/gpencil_undo.c b/source/blender/editors/gpencil/gpencil_undo.c index 61f7e1bb86f..fa9f5196866 100644 --- a/source/blender/editors/gpencil/gpencil_undo.c +++ b/source/blender/editors/gpencil/gpencil_undo.c @@ -25,6 +25,10 @@ * ***** END GPL LICENSE BLOCK ***** */ +/** \file blender/editors/gpencil/gpencil_undo.c + * \ingroup edgpencil + */ + #include <stdlib.h> #include <string.h> @@ -34,6 +38,7 @@ #include "DNA_listBase.h" #include "DNA_windowmanager_types.h" +#include "BKE_blender.h" #include "BKE_context.h" #include "BKE_gpencil.h" @@ -46,12 +51,10 @@ #include "gpencil_intern.h" -#define MAXUNDONAME 64 - typedef struct bGPundonode { struct bGPundonode *next, *prev; - char name[MAXUNDONAME]; + char name[BKE_UNDO_STR_MAX]; struct bGPdata *gpd; } bGPundonode; diff --git a/source/blender/editors/include/ED_image.h b/source/blender/editors/include/ED_image.h index 6f41bef81f4..87f12b8ac9c 100644 --- a/source/blender/editors/include/ED_image.h +++ b/source/blender/editors/include/ED_image.h @@ -60,9 +60,7 @@ void ED_space_image_get_uv_aspect(struct SpaceImage *sima, float *aspx, float *a void ED_space_image_paint_update(struct wmWindowManager *wm, struct ToolSettings *settings); void ED_space_image_uv_sculpt_update(struct wmWindowManager *wm, struct ToolSettings *settings); -void ED_image_get_size(struct Image *ima, int *width, int *height); -void ED_image_get_aspect(struct Image *ima, float *aspx, float *aspy); -void ED_image_get_uv_aspect(struct Image *ima, float *aspx, float *aspy); +void ED_image_get_uv_aspect(struct Image *ima, struct ImageUser *iuser, float *aspx, float *aspy); void ED_image_mouse_pos(struct SpaceImage *sima, struct ARegion *ar, const int mval[2], float co[2]); void ED_image_point_pos(struct SpaceImage *sima, struct ARegion *ar, float x, float y, float *xr, float *yr); void ED_image_point_pos__reverse(struct SpaceImage *sima, struct ARegion *ar, const float co[2], float r_co[2]); diff --git a/source/blender/editors/include/ED_mask.h b/source/blender/editors/include/ED_mask.h index 88667729eee..8ebf932fd96 100644 --- a/source/blender/editors/include/ED_mask.h +++ b/source/blender/editors/include/ED_mask.h @@ -56,7 +56,8 @@ void ED_operatormacros_mask(void); void ED_mask_draw(const bContext *C, const char draw_flag, const char draw_type); void ED_mask_draw_region(struct Mask *mask, struct ARegion *ar, const char draw_flag, const char draw_type, - int width, int height, + const int width_i, const int height_i, + const float aspx, const float aspy, const short do_scale_applied, const short do_post_draw, float stabmat[4][4], const bContext *C); diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 35284b26d29..1d4fbe81e02 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -71,14 +71,8 @@ struct Material; struct Object; struct rcti; -intptr_t mesh_octree_table(struct Object *ob, struct BMEditMesh *em, const float co[3], char mode); -int mesh_mirrtopo_table(struct Object *ob, char mode); /* editmesh_utils.c */ - -/* retrieves mirrored cache vert, or NULL if there isn't one. - * note: calling this without ensuring the mirror cache state - * is bad.*/ void EDBM_verts_mirror_cache_begin(struct BMEditMesh *em, const short use_select); /* note, replaces EM_cache_x_mirror_vert in trunk */ void EDBM_verts_mirror_apply(struct BMEditMesh *em, const int sel_from, const int sel_to); struct BMVert *EDBM_verts_mirror_get(struct BMEditMesh *em, struct BMVert *v); @@ -86,7 +80,9 @@ void EDBM_verts_mirror_cache_clear(struct BMEditMesh *em, struct BMVer void EDBM_verts_mirror_cache_end(struct BMEditMesh *em); void EDBM_mesh_normals_update(struct BMEditMesh *em); +void EDBM_mesh_clear(struct BMEditMesh *em); +void EDBM_selectmode_to_scene(struct bContext *C); void EDBM_mesh_make(struct ToolSettings *ts, struct Scene *scene, struct Object *ob); void EDBM_mesh_free(struct BMEditMesh *tm); void EDBM_mesh_load(struct Object *ob); @@ -110,94 +106,105 @@ void EDBM_selectmode_flush(struct BMEditMesh *em); void EDBM_deselect_flush(struct BMEditMesh *em); void EDBM_select_flush(struct BMEditMesh *em); -void EDBM_selectmode_set(struct BMEditMesh *em); -void EDBM_selectmode_convert(struct BMEditMesh *em, short oldmode, const short selectmode); void undo_push_mesh(struct bContext *C, const char *name); int EDBM_vert_color_check(struct BMEditMesh *em); - void EDBM_mesh_hide(struct BMEditMesh *em, int swap); void EDBM_mesh_reveal(struct BMEditMesh *em); void EDBM_update_generic(struct bContext *C, struct BMEditMesh *em, const short do_tessface); -int EDBM_backbuf_check(unsigned int index); -int EDBM_backbuf_border_mask_init(struct ViewContext *vc, int mcords[][2], short tot, - short xmin, short ymin, short xmax, short ymax); -void EDBM_backbuf_free(void); -int EDBM_backbuf_border_init(struct ViewContext *vc, short xmin, short ymin, short xmax, short ymax); -int EDBM_backbuf_circle_init(struct ViewContext *vc, short xs, short ys, short rads); - -void EDBM_deselect_by_material(struct BMEditMesh *em, const short index, const short select); - struct UvElementMap *EDBM_uv_element_map_create(struct BMEditMesh *em, int selected, int doIslands); void EDBM_uv_element_map_free(struct UvElementMap *vmap); int EDBM_mtexpoly_check(struct BMEditMesh *em); -struct MTexPoly *EDBM_mtexpoly_active_get(struct BMEditMesh *em, struct BMFace **r_act_efa, int sloppy); +struct MTexPoly *EDBM_mtexpoly_active_get(struct BMEditMesh *em, struct BMFace **r_act_efa, int sloppy, int selected); void EDBM_uv_vert_map_free(struct UvVertMap *vmap); struct UvMapVert *EDBM_uv_vert_map_at_index(struct UvVertMap *vmap, unsigned int v); struct UvVertMap *EDBM_uv_vert_map_create(struct BMEditMesh *em, int selected, int do_face_idx_array, const float limit[2]); -void EDBM_data_layer_add(struct BMEditMesh *em, struct CustomData *data, int type, const char *name); -void EDBM_data_layer_free(struct BMEditMesh *em, struct CustomData *data, int type); - -void EDBM_select_toggle_all(struct BMEditMesh *em); -void EDBM_select_swap(struct BMEditMesh *em); /* exported for UV */ -int EDBM_select_interior_faces(struct BMEditMesh *em); - void EDBM_flag_enable_all(struct BMEditMesh *em, const char hflag); void EDBM_flag_disable_all(struct BMEditMesh *em, const char hflag); + + +/* editmesh_select.c */ void EDBM_select_mirrored(struct Object *obedit, struct BMEditMesh *em, int extend); void EDBM_automerge(struct Scene *scene, struct Object *ob, int update); -/* editmesh_mods.c */ -extern unsigned int bm_vertoffs, bm_solidoffs, bm_wireoffs; +int EDBM_backbuf_border_init(struct ViewContext *vc, short xmin, short ymin, short xmax, short ymax); +int EDBM_backbuf_check(unsigned int index); +void EDBM_backbuf_free(void); -int mouse_mesh(struct bContext *C, const int mval[2], short extend, short deselect, short toggle); +int EDBM_backbuf_border_mask_init(struct ViewContext *vc, int mcords[][2], short tot, + short xmin, short ymin, short xmax, short ymax); +int EDBM_backbuf_circle_init(struct ViewContext *vc, short xs, short ys, short rads); -struct BMVert *editbmesh_get_x_mirror_vert(struct Object *ob, struct BMEditMesh *em, struct BMVert *eve, const float co[3], int index); -int mesh_get_x_mirror_vert(struct Object *ob, int index); -int *mesh_get_x_mirror_faces(struct Object *ob, struct BMEditMesh *em); +struct BMVert *EDBM_vert_find_nearest(struct ViewContext *vc, int *dist, short sel, short strict); +struct BMEdge *EDBM_edge_find_nearest(struct ViewContext *vc, int *dist); +struct BMFace *EDBM_face_find_nearest(struct ViewContext *vc, int *dist); + +int EDBM_select_pick(struct bContext *C, const int mval[2], short extend, short deselect, short toggle); + +void EDBM_selectmode_set(struct BMEditMesh *em); +void EDBM_selectmode_convert(struct BMEditMesh *em, short oldmode, const short selectmode); + +void EDBM_deselect_by_material(struct BMEditMesh *em, const short index, const short select); + +void EDBM_select_toggle_all(struct BMEditMesh *em); + +void EDBM_select_swap(struct BMEditMesh *em); /* exported for UV */ +int EDBM_select_interior_faces(struct BMEditMesh *em); +void em_setup_viewcontext(struct bContext *C, struct ViewContext *vc); /* rename? */ + +extern unsigned int bm_vertoffs, bm_solidoffs, bm_wireoffs; -int join_mesh_exec(struct bContext *C, struct wmOperator *op); -int join_mesh_shapes_exec(struct bContext *C, struct wmOperator *op); /* mesh_ops.c */ void ED_operatortypes_mesh(void); void ED_operatormacros_mesh(void); void ED_keymap_mesh(struct wmKeyConfig *keyconf); +void ED_keymap_mesh(struct wmKeyConfig *keyconf); -/* editmesh.c */ - +/* spacetypes.c */ void ED_spacetypes_init(void); -void ED_keymap_mesh(struct wmKeyConfig *keyconf); -/* bmesh_mods.c */ -extern unsigned int bm_vertoffs, bm_solidoffs, bm_wireoffs; -/* bmesh_tools.c (could be moved) */ +/* editmesh_tools.c (could be moved) */ void EMBM_project_snap_verts(struct bContext *C, struct ARegion *ar, struct Object *obedit, struct BMEditMesh *em); + /* editface.c */ void paintface_flush_flags(struct Object *ob); -int paintface_mouse_select(struct bContext *C, struct Object *ob, const int mval[2], int extend, int deselect, int toggle); -int do_paintface_box_select(struct ViewContext *vc, struct rcti *rect, int select, int extend); +int paintface_mouse_select(struct bContext *C, struct Object *ob, const int mval[2], int extend, int deselect, int toggle); +int do_paintface_box_select(struct ViewContext *vc, struct rcti *rect, int select, int extend); void paintface_deselect_all_visible(struct Object *ob, int action, short flush_flags); void paintface_select_linked(struct bContext *C, struct Object *ob, int mval[2], int mode); -int paintface_minmax(struct Object *ob, float r_min[3], float r_max[3]); +int paintface_minmax(struct Object *ob, float r_min[3], float r_max[3]); void paintface_hide(struct Object *ob, const int unselected); void paintface_reveal(struct Object *ob); void paintvert_deselect_all_visible(struct Object *ob, int action, short flush_flags); -void paintvert_flush_flags(struct Object *ob); +void paintvert_flush_flags(struct Object *ob); + +/* mirrtopo */ +typedef struct MirrTopoStore_t { + intptr_t *index_lookup; + int prev_vert_tot; + int prev_edge_tot; + int prev_ob_mode; +} MirrTopoStore_t; + +int ED_mesh_mirrtopo_recalc_check(struct Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_topo_store); +void ED_mesh_mirrtopo_init(struct Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_topo_store, + const short skip_em_vert_array_init); +void ED_mesh_mirrtopo_free(MirrTopoStore_t *mesh_topo_store); -/* object_vgroup.c */ +/* object_vgroup.c */ #define WEIGHT_REPLACE 1 #define WEIGHT_ADD 2 #define WEIGHT_SUBTRACT 3 @@ -218,9 +225,6 @@ void ED_vgroup_vert_add(struct Object *ob, struct bDeformGroup * void ED_vgroup_vert_remove(struct Object *ob, struct bDeformGroup *dg, int vertnum); float ED_vgroup_vert_weight(struct Object *ob, struct bDeformGroup *dg, int vertnum); -struct BMVert *EDBM_vert_find_nearest(struct ViewContext *vc, int *dist, short sel, short strict); -struct BMEdge *EDBM_edge_find_nearest(struct ViewContext *vc, int *dist); -struct BMFace *EDBM_face_find_nearest(struct ViewContext *vc, int *dist); /* mesh_data.c */ // void ED_mesh_geometry_add(struct Mesh *mesh, struct ReportList *reports, int verts, int edges, int faces); @@ -248,25 +252,6 @@ int ED_mesh_color_add(struct bContext *C, struct Scene *scene, struct Object *ob int ED_mesh_color_remove(struct bContext *C, struct Object *ob, struct Mesh *me); int ED_mesh_color_remove_named(struct bContext *C, struct Object *ob, struct Mesh *me, const char *name); -void EDBM_selectmode_to_scene(struct bContext *C); -void EDBM_mesh_clear(struct BMEditMesh *em); - -#include "../mesh/editmesh_bvh.h" - - -/* mirrtopo */ -typedef struct MirrTopoStore_t { - intptr_t *index_lookup; - int prev_vert_tot; - int prev_edge_tot; - int prev_ob_mode; -} MirrTopoStore_t; - -int ED_mesh_mirrtopo_recalc_check(struct Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_topo_store); -void ED_mesh_mirrtopo_init(struct Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_topo_store, - const short skip_em_vert_array_init); -void ED_mesh_mirrtopo_free(MirrTopoStore_t *mesh_topo_store); - /* mesh backup */ typedef struct BMBackup { struct BMesh *bmcopy; @@ -279,6 +264,30 @@ void EDBM_redo_state_restore(struct BMBackup, struct BMEditMesh *em, int recalct /* delete the backup, optionally flushing it to an editmesh */ void EDBM_redo_state_free(struct BMBackup *, struct BMEditMesh *em, int recalctess); + +/* meshtools.c */ +int join_mesh_exec(struct bContext *C, struct wmOperator *op); +int join_mesh_shapes_exec(struct bContext *C, struct wmOperator *op); + +intptr_t mesh_octree_table(struct Object *ob, struct BMEditMesh *em, const float co[3], char mode); +int mesh_mirrtopo_table(struct Object *ob, char mode); + +/* retrieves mirrored cache vert, or NULL if there isn't one. + * note: calling this without ensuring the mirror cache state + * is bad.*/ +int mesh_get_x_mirror_vert(struct Object *ob, int index); +struct BMVert *editbmesh_get_x_mirror_vert(struct Object *ob, struct BMEditMesh *em, struct BMVert *eve, const float co[3], int index); +int *mesh_get_x_mirror_faces(struct Object *ob, struct BMEditMesh *em); + +int ED_mesh_pick_vert(struct bContext *C, struct Mesh *me, const int mval[2], unsigned int *index, int size); +int ED_mesh_pick_face(struct bContext *C, struct Mesh *me, const int mval[2], unsigned int *index, int size); +int ED_mesh_pick_face_vert(struct bContext *C, struct Mesh *me, struct Object *ob, const int mval[2], unsigned int *index, int size); + +#define ED_MESH_PICK_DEFAULT_VERT_SIZE 50 +#define ED_MESH_PICK_DEFAULT_FACE_SIZE 3 + +#include "../mesh/editmesh_bvh.h" + #ifdef __cplusplus } #endif diff --git a/source/blender/editors/include/ED_render.h b/source/blender/editors/include/ED_render.h index 7891315be9f..39e2c28a61a 100644 --- a/source/blender/editors/include/ED_render.h +++ b/source/blender/editors/include/ED_render.h @@ -56,18 +56,12 @@ void ED_render_scene_update(struct Main *bmain, struct Scene *scene, int updated typedef struct RenderInfo { int pr_rectx; int pr_recty; - short curtile, tottile, status; + short curtile, tottile; rcti disprect; /* storage for view3d preview rect */ unsigned int *rect; struct Render *re; /* persistent render */ } RenderInfo; -/* ri->status */ -#define PR_DBASE 1 -#define PR_DISPRECT 2 -#define PR_PROJECTED 4 -#define PR_ROTATED 8 - /* Render the preview * * pr_method: diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index 4faf82eec36..fc20bdfb9c5 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -169,6 +169,7 @@ int ED_operator_editlattice(struct bContext *C); int ED_operator_editmball(struct bContext *C); int ED_operator_uvedit(struct bContext *C); int ED_operator_uvmap(struct bContext *C); +int ED_operator_posemode_exclusive(struct bContext *C); int ED_operator_posemode(struct bContext *C); int ED_operator_mask(struct bContext *C); diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index f055c89235d..c6f58fdd70b 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -187,70 +187,73 @@ typedef struct uiLayout uiLayout; * - bit 8: for 'bit' * - bit 9-15: button type (now 6 bits, 64 types) * */ - -#define CHA 32 -#define SHO 64 -#define INT 96 -#define FLO 128 -/*#define FUN 192*/ /*UNUSED*/ -#define BIT 256 - -/* button reqyires a pointer */ -#define BUTPOIN (FLO | SHO | CHA) +typedef enum { + UI_BUT_POIN_CHAR = 32, + UI_BUT_POIN_SHORT = 64, + UI_BUT_POIN_INT = 96, + UI_BUT_POIN_FLOAT = 128, +/* UI_BUT_POIN_FUNCTION = 192, */ /*UNUSED*/ + UI_BUT_POIN_BIT = 256 /* OR'd with a bit index*/ +} eButPointerType; + +/* requires (but->poin != NULL) */ +#define UI_BUT_POIN_TYPES (UI_BUT_POIN_FLOAT | UI_BUT_POIN_SHORT | UI_BUT_POIN_CHAR) /* assigned to but->type, OR'd with the flags above when passing args */ -#define BUT (1 << 9) -#define ROW (2 << 9) -#define TOG (3 << 9) -#define SLI (4 << 9) -#define NUM (5 << 9) -#define TEX (6 << 9) -#define TOG3 (7 << 9) -#define TOGR (8 << 9) -#define TOGN (9 << 9) -#define LABEL (10 << 9) -#define MENU (11 << 9) -#define ICONROW (12 << 9) -#define ICONTOG (13 << 9) -#define NUMSLI (14 << 9) -#define COL (15 << 9) -#define IDPOIN (16 << 9) -#define HSVSLI (17 << 9) -#define SCROLL (18 << 9) -#define BLOCK (19 << 9) -#define BUTM (20 << 9) -#define SEPR (21 << 9) -#define LINK (22 << 9) -#define INLINK (23 << 9) -#define KEYEVT (24 << 9) -#define ICONTEXTROW (25 << 9) -#define HSVCUBE (26 << 9) -#define PULLDOWN (27 << 9) -#define ROUNDBOX (28 << 9) -#define CHARTAB (29 << 9) -#define BUT_COLORBAND (30 << 9) -#define BUT_NORMAL (31 << 9) -#define BUT_CURVE (32 << 9) -#define BUT_TOGDUAL (33 << 9) -#define ICONTOGN (34 << 9) -#define FTPREVIEW (35 << 9) -#define NUMABS (36 << 9) -#define TOGBUT (37 << 9) -#define OPTION (38 << 9) -#define OPTIONN (39 << 9) -#define TRACKPREVIEW (40 << 9) -/* buttons with value >= SEARCH_MENU don't get undo pushes */ -#define SEARCH_MENU (41 << 9) -#define BUT_EXTRA (42 << 9) -#define HSVCIRCLE (43 << 9) -#define LISTBOX (44 << 9) -#define LISTROW (45 << 9) -#define HOTKEYEVT (46 << 9) -#define BUT_IMAGE (47 << 9) -#define HISTOGRAM (48 << 9) -#define WAVEFORM (49 << 9) -#define VECTORSCOPE (50 << 9) -#define PROGRESSBAR (51 << 9) +typedef enum { + BUT = (1 << 9), + ROW = (2 << 9), + TOG = (3 << 9), + SLI = (4 << 9), + NUM = (5 << 9), + TEX = (6 << 9), + TOG3 = (7 << 9), + TOGR = (8 << 9), + TOGN = (9 << 9), + LABEL = (10 << 9), + MENU = (11 << 9), + ICONROW = (12 << 9), + ICONTOG = (13 << 9), + NUMSLI = (14 << 9), + COLOR = (15 << 9), + IDPOIN = (16 << 9), + HSVSLI = (17 << 9), + SCROLL = (18 << 9), + BLOCK = (19 << 9), + BUTM = (20 << 9), + SEPR = (21 << 9), + LINK = (22 << 9), + INLINK = (23 << 9), + KEYEVT = (24 << 9), + ICONTEXTROW = (25 << 9), + HSVCUBE = (26 << 9), + PULLDOWN = (27 << 9), + ROUNDBOX = (28 << 9), + CHARTAB = (29 << 9), + BUT_COLORBAND = (30 << 9), + BUT_NORMAL = (31 << 9), + BUT_CURVE = (32 << 9), + BUT_TOGDUAL = (33 << 9), + ICONTOGN = (34 << 9), + /* FTPREVIEW = (35 << 9), */ /* UNUSED */ + NUMABS = (36 << 9), + TOGBUT = (37 << 9), + OPTION = (38 << 9), + OPTIONN = (39 << 9), + TRACKPREVIEW = (40 << 9), + /* buttons with value >= SEARCH_MENU don't get undo pushes */ + SEARCH_MENU = (41 << 9), + BUT_EXTRA = (42 << 9), + HSVCIRCLE = (43 << 9), + LISTBOX = (44 << 9), + LISTROW = (45 << 9), + HOTKEYEVT = (46 << 9), + BUT_IMAGE = (47 << 9), + HISTOGRAM = (48 << 9), + WAVEFORM = (49 << 9), + VECTORSCOPE = (50 << 9), + PROGRESSBAR = (51 << 9) +} eButType; #define BUTTYPE (63 << 9) @@ -395,7 +398,8 @@ void uiBlockBeginAlign(uiBlock *block); void uiBlockEndAlign(uiBlock *block); /* block bounds/position calculation */ -enum { +typedef enum { + UI_BLOCK_BOUNDS_NONE = 0, UI_BLOCK_BOUNDS = 1, UI_BLOCK_BOUNDS_TEXT, UI_BLOCK_BOUNDS_POPUP_MOUSE, @@ -527,7 +531,7 @@ enum { BUT_GET_TIP, BUT_GET_RNA_TIP, BUT_GET_RNAENUM_TIP, - BUT_GET_OP_KEYMAP, + BUT_GET_OP_KEYMAP }; typedef struct uiStringInfo { @@ -538,7 +542,7 @@ typedef struct uiStringInfo { /* Note: Expects pointers to uiStringInfo structs as parameters. * Will fill them with translated strings, when possible. * Strings in uiStringInfo must be MEM_freeN'ed by caller. */ -void uiButGetStrInfo(struct bContext *C, uiBut *but, const int nbr, ...); +void uiButGetStrInfo(struct bContext *C, uiBut *but, int nbr, ...); /* Edit i18n stuff. */ /* Name of the main py op from i18n addon. */ @@ -573,7 +577,7 @@ typedef void (*uiIDPoinFuncFP)(struct bContext *C, const char *str, struct ID ** typedef void (*uiIDPoinFunc)(struct bContext *C, struct ID *id, int event); uiBut *uiDefIDPoinBut(uiBlock *block, uiIDPoinFuncFP func, short blocktype, int retval, const char *str, - int x, int y, short width, short height, void *idpp, const char *tip); + int x, int y, short width, short height, void *idpp, const char *tip); int uiIconFromID(struct ID *id); @@ -624,7 +628,9 @@ void uiButSetNFunc(uiBut *but, uiButHandleNFunc func, void *argN, void void uiButSetCompleteFunc(uiBut *but, uiButCompleteFunc func, void *arg); -void uiBlockSetDrawExtraFunc(uiBlock *block, void (*func)(const struct bContext *C, void *, void *, void *, struct rcti *rect), void *arg1, void *arg2); +void uiBlockSetDrawExtraFunc(uiBlock *block, + void (*func)(const struct bContext *C, void *, void *, void *, struct rcti *rect), + void *arg1, void *arg2); void uiButSetFocusOnEnter(struct wmWindow *win, uiBut *but); @@ -743,7 +749,9 @@ void uiLayoutSetFunc(uiLayout *layout, uiMenuHandleFunc handlefunc, void *argv); void uiLayoutSetContextPointer(uiLayout *layout, const char *name, struct PointerRNA *ptr); void uiLayoutContextCopy(uiLayout *layout, struct bContextStore *context); const char *uiLayoutIntrospect(uiLayout *layout); // XXX - testing -void uiLayoutOperatorButs(const struct bContext *C, struct uiLayout *layout, struct wmOperator *op, int (*check_prop)(struct PointerRNA *, struct PropertyRNA *), const char label_align, const short flag); +void uiLayoutOperatorButs(const struct bContext *C, struct uiLayout *layout, struct wmOperator *op, + int (*check_prop)(struct PointerRNA *, struct PropertyRNA *), + const char label_align, const short flag); struct MenuType *uiButGetMenuType(uiBut *but); void uiLayoutSetOperatorContext(uiLayout *layout, int opcontext); diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h index 3a8f05a76f0..792c96fe7c8 100644 --- a/source/blender/editors/include/UI_view2d.h +++ b/source/blender/editors/include/UI_view2d.h @@ -203,7 +203,7 @@ void UI_view2d_operatortypes(void); void UI_view2d_keymap(struct wmKeyConfig *keyconf); void UI_view2d_smooth_view(struct bContext *C, struct ARegion *ar, - const struct rctf *cur); + const struct rctf *cur); #endif /* __UI_VIEW2D_H__ */ diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index afbabaaa8d7..823f8d7be39 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -33,7 +33,8 @@ #include <math.h> #include <string.h> #include <ctype.h> - +#include <stddef.h> /* offsetof() */ + #include "MEM_guardedalloc.h" #include "DNA_scene_types.h" @@ -41,7 +42,12 @@ #include "DNA_userdef_types.h" #include "BLI_math.h" -#include "BLI_blenlib.h" +#include "BLI_listbase.h" +#include "BLI_string.h" +#include "BLI_string_utf8.h" +#include "BLI_path_util.h" +#include "BLI_rect.h" + #include "BLI_dynstr.h" #include "BLI_utildefines.h" @@ -50,7 +56,6 @@ #include "BKE_unit.h" #include "BKE_screen.h" #include "BKE_idprop.h" -#include "BKE_utildefines.h" /* FILE_MAX */ #include "BIF_gl.h" @@ -129,7 +134,7 @@ void ui_block_to_window(const ARegion *ar, uiBlock *block, int *x, int *y) *y = (int)(fy + 0.5f); } -void ui_block_to_window_rct(const ARegion *ar, uiBlock *block, rctf *graph, rcti *winr) +void ui_block_to_window_rct(const ARegion *ar, uiBlock *block, const rctf *graph, rcti *winr) { rctf tmpr; @@ -312,7 +317,7 @@ static void ui_centered_bounds_block(const bContext *C, uiBlock *block) ui_bounds_block(block); } -static void ui_popup_bounds_block(const bContext *C, uiBlock *block, int bounds_calc) +static void ui_popup_bounds_block(const bContext *C, uiBlock *block, eBlockBoundsCalc bounds_calc) { wmWindow *window = CTX_wm_window(C); int startx, starty, endx, endy, width, height, oldwidth, oldheight; @@ -383,21 +388,21 @@ void uiBoundsBlock(uiBlock *block, int addval) return; block->bounds = addval; - block->dobounds = UI_BLOCK_BOUNDS; + block->bounds_type = UI_BLOCK_BOUNDS; } /* used for pulldowns */ void uiTextBoundsBlock(uiBlock *block, int addval) { block->bounds = addval; - block->dobounds = UI_BLOCK_BOUNDS_TEXT; + block->bounds_type = UI_BLOCK_BOUNDS_TEXT; } /* used for block popups */ void uiPopupBoundsBlock(uiBlock *block, int addval, int mx, int my) { block->bounds = addval; - block->dobounds = UI_BLOCK_BOUNDS_POPUP_MOUSE; + block->bounds_type = UI_BLOCK_BOUNDS_POPUP_MOUSE; block->mx = mx; block->my = my; } @@ -406,7 +411,7 @@ void uiPopupBoundsBlock(uiBlock *block, int addval, int mx, int my) void uiMenuPopupBoundsBlock(uiBlock *block, int addval, int mx, int my) { block->bounds = addval; - block->dobounds = UI_BLOCK_BOUNDS_POPUP_MENU; + block->bounds_type = UI_BLOCK_BOUNDS_POPUP_MENU; block->mx = mx; block->my = my; } @@ -415,7 +420,7 @@ void uiMenuPopupBoundsBlock(uiBlock *block, int addval, int mx, int my) void uiCenteredBoundsBlock(uiBlock *block, int addval) { block->bounds = addval; - block->dobounds = UI_BLOCK_BOUNDS_POPUP_CENTER; + block->bounds_type = UI_BLOCK_BOUNDS_POPUP_CENTER; } void uiExplicitBoundsBlock(uiBlock *block, int minx, int miny, int maxx, int maxy) @@ -424,7 +429,7 @@ void uiExplicitBoundsBlock(uiBlock *block, int minx, int miny, int maxx, int max block->rect.ymin = miny; block->rect.xmax = maxx; block->rect.ymax = maxy; - block->dobounds = 0; + block->bounds_type = UI_BLOCK_BOUNDS_NONE; } /* ************** LINK LINE DRAWING ************* */ @@ -754,7 +759,7 @@ static void ui_menu_block_set_keyaccels(uiBlock *block) * fun first pass on all buttons so first word chars always get first priority */ for (but = block->buttons.first; but; but = but->next) { - if (!ELEM4(but->type, BUT, MENU, BLOCK, PULLDOWN) || (but->flag & UI_HIDDEN)) { + if (!ELEM5(but->type, BUT, BUTM, MENU, BLOCK, PULLDOWN) || (but->flag & UI_HIDDEN)) { /* pass */ } else if (but->menu_key == '\0') { @@ -929,21 +934,45 @@ void uiEndBlock(const bContext *C, uiBlock *block) } /* handle pending stuff */ - if (block->layouts.first) uiBlockLayoutResolve(block, NULL, NULL); + if (block->layouts.first) { + uiBlockLayoutResolve(block, NULL, NULL); + } ui_block_do_align(block); if ((block->flag & UI_BLOCK_LOOP) && (block->flag & UI_BLOCK_NUMSELECT)) { ui_menu_block_set_keyaccels(block); /* could use a different flag to check */ } - if (block->flag & UI_BLOCK_LOOP) ui_menu_block_set_keymaps(C, block); + + if (block->flag & UI_BLOCK_LOOP) { + ui_menu_block_set_keymaps(C, block); + } /* after keymaps! */ - if (block->dobounds == UI_BLOCK_BOUNDS) ui_bounds_block(block); - else if (block->dobounds == UI_BLOCK_BOUNDS_TEXT) ui_text_bounds_block(block, 0.0f); - else if (block->dobounds == UI_BLOCK_BOUNDS_POPUP_CENTER) ui_centered_bounds_block(C, block); - else if (block->dobounds) ui_popup_bounds_block(C, block, block->dobounds); + switch (block->bounds_type) { + case UI_BLOCK_BOUNDS_NONE: + break; + case UI_BLOCK_BOUNDS: + ui_bounds_block(block); + break; + case UI_BLOCK_BOUNDS_TEXT: + ui_text_bounds_block(block, 0.0f); + break; + case UI_BLOCK_BOUNDS_POPUP_CENTER: + ui_centered_bounds_block(C, block); + break; - if (block->rect.xmin == 0.0f && block->rect.xmax == 0.0f) uiBoundsBlock(block, 0); - if (block->flag & UI_BUT_ALIGN) uiBlockEndAlign(block); + /* fallback */ + case UI_BLOCK_BOUNDS_POPUP_MOUSE: + case UI_BLOCK_BOUNDS_POPUP_MENU: + ui_popup_bounds_block(C, block, block->bounds_type); + break; + } + + if (block->rect.xmin == 0.0f && block->rect.xmax == 0.0f) { + uiBoundsBlock(block, 0); + } + if (block->flag & UI_BUT_ALIGN) { + uiBlockEndAlign(block); + } block->endblock = 1; } @@ -1077,8 +1106,12 @@ static void ui_is_but_sel(uiBut *but, double *value) int lvalue; UI_GET_BUT_VALUE_INIT(but, *value); lvalue = (int)*value; - if (BTST(lvalue, (but->bitnr)) ) is_push = is_true; - else is_push = !is_true; + if (UI_BITBUT_TEST(lvalue, (but->bitnr))) { + is_push = is_true; + } + else { + is_push = !is_true; + } } else { switch (but->type) { @@ -1116,7 +1149,7 @@ static void ui_is_but_sel(uiBut *but, double *value) if (*value == (double)but->hardmax) is_push = 1; } break; - case COL: + case COLOR: is_push = 2; break; default: @@ -1233,8 +1266,7 @@ void ui_delete_linkline(uiLinkLine *line, uiBut *but) else { b = 0; for (a = 0; a < (*(link->totlink)); a++) { - - if ( (*(link->ppoin))[a] != line->to->poin) { + if ((*(link->ppoin))[a] != line->to->poin) { (*(link->ppoin))[b] = (*(link->ppoin))[a]; b++; } @@ -1277,13 +1309,13 @@ void ui_get_but_vectorf(uiBut *but, float vec[3]) vec[a] = RNA_property_float_get_index(&but->rnapoin, prop, a); } } - else if (but->pointype == CHA) { + else if (but->pointype == UI_BUT_POIN_CHAR) { char *cp = (char *)but->poin; vec[0] = ((float)cp[0]) / 255.0f; vec[1] = ((float)cp[1]) / 255.0f; vec[2] = ((float)cp[2]) / 255.0f; } - else if (but->pointype == FLO) { + else if (but->pointype == UI_BUT_POIN_FLOAT) { float *fp = (float *)but->poin; copy_v3_v3(vec, fp); } @@ -1323,13 +1355,13 @@ void ui_set_but_vectorf(uiBut *but, const float vec[3]) } } } - else if (but->pointype == CHA) { + else if (but->pointype == UI_BUT_POIN_CHAR) { char *cp = (char *)but->poin; cp[0] = (char)(0.5f + vec[0] * 255.0f); cp[1] = (char)(0.5f + vec[1] * 255.0f); cp[2] = (char)(0.5f + vec[2] * 255.0f); } - else if (but->pointype == FLO) { + else if (but->pointype == UI_BUT_POIN_FLOAT) { float *fp = (float *)but->poin; copy_v3_v3(fp, vec); } @@ -1337,7 +1369,7 @@ void ui_set_but_vectorf(uiBut *but, const float vec[3]) int ui_is_but_float(uiBut *but) { - if (but->pointype == FLO && but->poin) + if (but->pointype == UI_BUT_POIN_FLOAT && but->poin) return 1; if (but->rnaprop && RNA_property_type(but->rnaprop) == PROP_FLOAT) @@ -1433,16 +1465,16 @@ double ui_get_but_val(uiBut *but) case 'V': value = hsv[2]; break; } } - else if (but->pointype == CHA) { + else if (but->pointype == UI_BUT_POIN_CHAR) { value = *(char *)but->poin; } - else if (but->pointype == SHO) { + else if (but->pointype == UI_BUT_POIN_SHORT) { value = *(short *)but->poin; } - else if (but->pointype == INT) { + else if (but->pointype == UI_BUT_POIN_INT) { value = *(int *)but->poin; } - else if (but->pointype == FLO) { + else if (but->pointype == UI_BUT_POIN_FLOAT) { value = *(float *)but->poin; } @@ -1514,9 +1546,10 @@ void ui_set_but_val(uiBut *but, double value) } else { /* first do rounding */ - if (but->pointype == CHA) + if (but->pointype == UI_BUT_POIN_CHAR) { value = (char)floor(value + 0.5); - else if (but->pointype == SHO) { + } + else if (but->pointype == UI_BUT_POIN_SHORT) { /* gcc 3.2.1 seems to have problems * casting a double like 32772.0 to * a short so we cast to an int, then @@ -1530,9 +1563,9 @@ void ui_set_but_val(uiBut *but, double value) gcckludge = (int) floor(value + 0.5); value = (short)gcckludge; } - else if (but->pointype == INT) + else if (but->pointype == UI_BUT_POIN_INT) value = (int)floor(value + 0.5); - else if (but->pointype == FLO) { + else if (but->pointype == UI_BUT_POIN_FLOAT) { float fval = (float)value; if (fval >= -0.00001f && fval <= 0.00001f) fval = 0.0f; /* prevent negative zero */ value = fval; @@ -1541,13 +1574,13 @@ void ui_set_but_val(uiBut *but, double value) /* then set value with possible edit override */ if (but->editval) value = *but->editval = value; - else if (but->pointype == CHA) + else if (but->pointype == UI_BUT_POIN_CHAR) value = *((char *)but->poin) = (char)value; - else if (but->pointype == SHO) + else if (but->pointype == UI_BUT_POIN_SHORT) value = *((short *)but->poin) = (short)value; - else if (but->pointype == INT) + else if (but->pointype == UI_BUT_POIN_INT) value = *((int *)but->poin) = (int)value; - else if (but->pointype == FLO) + else if (but->pointype == UI_BUT_POIN_FLOAT) value = *((float *)but->poin) = (float)value; } @@ -2207,6 +2240,10 @@ void ui_check_but(uiBut *but) but->iconadd = (int)value - (int)(but->hardmin); } break; + + /* quiet warnings for unhandled types */ + default: + break; } @@ -2459,7 +2496,7 @@ static void ui_block_do_align_but(uiBut *first, short nr) flag |= UI_BUT_ALIGN_TOP; } - if ( (flag & UI_BUT_ALIGN_TOP) == 0) { /* stil top row */ + if ((flag & UI_BUT_ALIGN_TOP) == 0) { /* stil top row */ if (prev) { if (next && buts_are_horiz(but, next)) flag = UI_BUT_ALIGN_DOWN | UI_BUT_ALIGN_LEFT | UI_BUT_ALIGN_RIGHT; @@ -2528,11 +2565,13 @@ void ui_block_do_align(uiBlock *block) /* skip with same number */ for (; but && but->alignnr == nr; but = but->next) ; - if (!but) + if (!but) { break; + } } - else + else { but = but->next; + } } } @@ -2548,22 +2587,29 @@ void ui_block_do_align(uiBlock *block) * 1,2,3, and a maximum of 4, all greater values will be clamped to 4. */ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str, - int x, int y, short width, short height, + int x, int y, short width, short height, void *poin, float min, float max, float a1, float a2, const char *tip) { uiBut *but; int slen; - - if (type & BUTPOIN) { /* a pointer is required */ - if (poin == NULL) + + /* we could do some more error checks here */ + if ((type & BUTTYPE) == LABEL) { + BLI_assert((poin != NULL || min != 0.0f || max != 0.0f || (a1 == 0.0f && a2 != 0.0f) || (a1 != 0.0f && a1 != 1.0f)) == FALSE); + } + + if (type & UI_BUT_POIN_TYPES) { /* a pointer is required */ + if (poin == NULL) { + BLI_assert(0); return NULL; + } } but = MEM_callocN(sizeof(uiBut), "uiBut"); but->type = type & BUTTYPE; - but->pointype = type & BUTPOIN; - but->bit = type & BIT; + but->pointype = type & UI_BUT_POIN_TYPES; + but->bit = type & UI_BUT_POIN_BIT; but->bitnr = type & 31; but->icon = ICON_NONE; but->iconadd = 0; @@ -2640,7 +2686,7 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str, /* keep track of UI_interface.h */ if (ELEM7(but->type, BLOCK, BUT, LABEL, PULLDOWN, ROUNDBOX, LISTBOX, BUTM)) ; - else if (ELEM3(but->type, SCROLL, SEPR, FTPREVIEW)) ; + else if (ELEM(but->type, SCROLL, SEPR /* , FTPREVIEW */ )) ; else if (but->type >= SEARCH_MENU) ; else but->flag |= UI_BUT_UNDO; @@ -3036,40 +3082,40 @@ static uiBut *uiDefButBit(uiBlock *block, int type, int bit, int retval, const c return NULL; } else { - return uiDefBut(block, type | BIT | bitIdx, retval, str, x, y, width, height, poin, min, max, a1, a2, tip); + return uiDefBut(block, type | UI_BUT_POIN_BIT | bitIdx, retval, str, x, y, width, height, poin, min, max, a1, a2, tip); } } uiBut *uiDefButF(uiBlock *block, int type, int retval, const char *str, int x, int y, short width, short height, float *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefBut(block, type | FLO, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefBut(block, type | UI_BUT_POIN_FLOAT, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefButBitF(uiBlock *block, int type, int bit, int retval, const char *str, int x, int y, short width, short height, float *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefButBit(block, type | FLO, bit, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefButBit(block, type | UI_BUT_POIN_FLOAT, bit, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefButI(uiBlock *block, int type, int retval, const char *str, int x, int y, short width, short height, int *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefBut(block, type | INT, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefBut(block, type | UI_BUT_POIN_INT, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefButBitI(uiBlock *block, int type, int bit, int retval, const char *str, int x, int y, short width, short height, int *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefButBit(block, type | INT, bit, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefButBit(block, type | UI_BUT_POIN_INT, bit, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefButS(uiBlock *block, int type, int retval, const char *str, int x, int y, short width, short height, short *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefBut(block, type | SHO, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefBut(block, type | UI_BUT_POIN_SHORT, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefButBitS(uiBlock *block, int type, int bit, int retval, const char *str, int x, int y, short width, short height, short *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefButBit(block, type | SHO, bit, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefButBit(block, type | UI_BUT_POIN_SHORT, bit, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefButC(uiBlock *block, int type, int retval, const char *str, int x, int y, short width, short height, char *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefBut(block, type | CHA, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefBut(block, type | UI_BUT_POIN_CHAR, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefButBitC(uiBlock *block, int type, int bit, int retval, const char *str, int x, int y, short width, short height, char *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefButBit(block, type | CHA, bit, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefButBit(block, type | UI_BUT_POIN_CHAR, bit, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefButR(uiBlock *block, int type, int retval, const char *str, int x, int y, short width, short height, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip) { @@ -3121,41 +3167,41 @@ static uiBut *uiDefIconButBit(uiBlock *block, int type, int bit, int retval, int return NULL; } else { - return uiDefIconBut(block, type | BIT | bitIdx, retval, icon, x, y, width, height, poin, min, max, a1, a2, tip); + return uiDefIconBut(block, type | UI_BUT_POIN_BIT | bitIdx, retval, icon, x, y, width, height, poin, min, max, a1, a2, tip); } } uiBut *uiDefIconButF(uiBlock *block, int type, int retval, int icon, int x, int y, short width, short height, float *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconBut(block, type | FLO, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconBut(block, type | UI_BUT_POIN_FLOAT, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconButBitF(uiBlock *block, int type, int bit, int retval, int icon, int x, int y, short width, short height, float *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconButBit(block, type | FLO, bit, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconButBit(block, type | UI_BUT_POIN_FLOAT, bit, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconButI(uiBlock *block, int type, int retval, int icon, int x, int y, short width, short height, int *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconBut(block, type | INT, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconBut(block, type | UI_BUT_POIN_INT, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconButBitI(uiBlock *block, int type, int bit, int retval, int icon, int x, int y, short width, short height, int *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconButBit(block, type | INT, bit, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconButBit(block, type | UI_BUT_POIN_INT, bit, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconButS(uiBlock *block, int type, int retval, int icon, int x, int y, short width, short height, short *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconBut(block, type | SHO, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconBut(block, type | UI_BUT_POIN_SHORT, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconButBitS(uiBlock *block, int type, int bit, int retval, int icon, int x, int y, short width, short height, short *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconButBit(block, type | SHO, bit, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconButBit(block, type | UI_BUT_POIN_SHORT, bit, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconButC(uiBlock *block, int type, int retval, int icon, int x, int y, short width, short height, char *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconBut(block, type | CHA, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconBut(block, type | UI_BUT_POIN_CHAR, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconButBitC(uiBlock *block, int type, int bit, int retval, int icon, int x, int y, short width, short height, char *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconButBit(block, type | CHA, bit, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconButBit(block, type | UI_BUT_POIN_CHAR, bit, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconButR(uiBlock *block, int type, int retval, int icon, int x, int y, short width, short height, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip) { @@ -3200,41 +3246,41 @@ static uiBut *uiDefIconTextButBit(uiBlock *block, int type, int bit, int retval, return NULL; } else { - return uiDefIconTextBut(block, type | BIT | bitIdx, retval, icon, str, x, y, width, height, poin, min, max, a1, a2, tip); + return uiDefIconTextBut(block, type | UI_BUT_POIN_BIT | bitIdx, retval, icon, str, x, y, width, height, poin, min, max, a1, a2, tip); } } uiBut *uiDefIconTextButF(uiBlock *block, int type, int retval, int icon, const char *str, int x, int y, short width, short height, float *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconTextBut(block, type | FLO, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconTextBut(block, type | UI_BUT_POIN_FLOAT, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconTextButBitF(uiBlock *block, int type, int bit, int retval, int icon, const char *str, int x, int y, short width, short height, float *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconTextButBit(block, type | FLO, bit, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconTextButBit(block, type | UI_BUT_POIN_FLOAT, bit, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconTextButI(uiBlock *block, int type, int retval, int icon, const char *str, int x, int y, short width, short height, int *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconTextBut(block, type | INT, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconTextBut(block, type | UI_BUT_POIN_INT, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconTextButBitI(uiBlock *block, int type, int bit, int retval, int icon, const char *str, int x, int y, short width, short height, int *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconTextButBit(block, type | INT, bit, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconTextButBit(block, type | UI_BUT_POIN_INT, bit, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconTextButS(uiBlock *block, int type, int retval, int icon, const char *str, int x, int y, short width, short height, short *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconTextBut(block, type | SHO, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconTextBut(block, type | UI_BUT_POIN_SHORT, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconTextButBitS(uiBlock *block, int type, int bit, int retval, int icon, const char *str, int x, int y, short width, short height, short *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconTextButBit(block, type | SHO, bit, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconTextButBit(block, type | UI_BUT_POIN_SHORT, bit, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconTextButC(uiBlock *block, int type, int retval, int icon, const char *str, int x, int y, short width, short height, char *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconTextBut(block, type | CHA, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconTextBut(block, type | UI_BUT_POIN_CHAR, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconTextButBitC(uiBlock *block, int type, int bit, int retval, int icon, const char *str, int x, int y, short width, short height, char *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconTextButBit(block, type | CHA, bit, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconTextButBit(block, type | UI_BUT_POIN_CHAR, bit, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconTextButR(uiBlock *block, int type, int retval, int icon, const char *str, int x, int y, short width, short height, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip) { @@ -3632,7 +3678,7 @@ uiBut *uiDefIconBlockBut(uiBlock *block, uiBlockCreateFunc func, void *arg, int uiBut *uiDefKeyevtButS(uiBlock *block, int retval, const char *str, int x, int y, short width, short height, short *spoin, const char *tip) { - uiBut *but = ui_def_but(block, KEYEVT | SHO, retval, str, x, y, width, height, spoin, 0.0, 0.0, 0.0, 0.0, tip); + uiBut *but = ui_def_but(block, KEYEVT | UI_BUT_POIN_SHORT, retval, str, x, y, width, height, spoin, 0.0, 0.0, 0.0, 0.0, tip); ui_check_but(but); return but; } @@ -3641,7 +3687,7 @@ uiBut *uiDefKeyevtButS(uiBlock *block, int retval, const char *str, int x, int y /* modkeypoin will be set to KM_SHIFT, KM_ALT, KM_CTRL, KM_OSKEY bits */ uiBut *uiDefHotKeyevtButS(uiBlock *block, int retval, const char *str, int x, int y, short width, short height, short *keypoin, short *modkeypoin, const char *tip) { - uiBut *but = ui_def_but(block, HOTKEYEVT | SHO, retval, str, x, y, width, height, keypoin, 0.0, 0.0, 0.0, 0.0, tip); + uiBut *but = ui_def_but(block, HOTKEYEVT | UI_BUT_POIN_SHORT, retval, str, x, y, width, height, keypoin, 0.0, 0.0, 0.0, 0.0, tip); but->modifier_key = *modkeypoin; ui_check_but(but); return but; @@ -3713,8 +3759,14 @@ void uiButGetStrInfo(bContext *C, uiBut *but, int nbr, ...) if (type == BUT_GET_LABEL) { if (but->str) { - /* Menu labels can have some complex formating stuff marked by pipes, we don't want those here! */ - char *tc = strchr(but->str, '|'); + /* Menu labels can have some complex formating stuff marked by pipes or %t, we don't want those here! */ + const char *tc; + + if (but->type == MENU) + tc = strstr(but->str, "%t"); + else + tc = strchr(but->str, '|'); + if (tc) tmp = BLI_strdupn(but->str, tc - but->str); else diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index ca52daa8cd2..b8a84e1638a 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -54,6 +54,7 @@ #include "PIL_time.h" +#include "BKE_blender.h" #include "BKE_colortools.h" #include "BKE_context.h" #include "BKE_idprop.h" @@ -120,8 +121,10 @@ typedef struct uiHandleButtonData { /* overall state */ uiHandleButtonState state; - int cancel, escapecancel, retval; - int applied, appliedinteractive; + int retval; + /* booleans (could be made into flags) */ + char cancel, escapecancel; + char applied, appliedinteractive; wmTimer *flashtimer; /* edited value */ @@ -193,7 +196,7 @@ typedef struct uiAfterFunc { bContextStore *context; - char undostr[512]; + char undostr[BKE_UNDO_STR_MAX]; int autokey; } uiAfterFunc; @@ -461,7 +464,7 @@ static void ui_apply_but_BUT(bContext *C, uiBut *but, uiHandleButtonData *data) ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_BUTM(bContext *C, uiBut *but, uiHandleButtonData *data) @@ -470,7 +473,7 @@ static void ui_apply_but_BUTM(bContext *C, uiBut *but, uiHandleButtonData *data) ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data) @@ -481,7 +484,7 @@ static void ui_apply_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data ui_check_but(but); ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data) @@ -491,19 +494,21 @@ static void ui_apply_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data) /* local hack... */ if (but->type == BUT_TOGDUAL && data->togdual) { - if (but->pointype == SHO) + if (but->pointype == UI_BUT_POIN_SHORT) { but->poin += 2; - else if (but->pointype == INT) + } + else if (but->pointype == UI_BUT_POIN_INT) { but->poin += 4; + } } value = ui_get_but_val(but); lvalue = (int)value; if (but->bit) { - w = BTST(lvalue, but->bitnr); - if (w) lvalue = BCLR(lvalue, but->bitnr); - else lvalue = BSET(lvalue, but->bitnr); + w = UI_BITBUT_TEST(lvalue, but->bitnr); + if (w) lvalue = UI_BITBUT_CLR(lvalue, but->bitnr); + else lvalue = UI_BITBUT_SET(lvalue, but->bitnr); if (but->type == TOGR) { if (!data->togonly) { @@ -531,16 +536,18 @@ static void ui_apply_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data) /* end local hack... */ if (but->type == BUT_TOGDUAL && data->togdual) { - if (but->pointype == SHO) + if (but->pointype == UI_BUT_POIN_SHORT) { but->poin -= 2; - else if (but->pointype == INT) + } + else if (but->pointype == UI_BUT_POIN_INT) { but->poin -= 4; + } } ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_ROW(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data) @@ -557,7 +564,7 @@ static void ui_apply_but_ROW(bContext *C, uiBlock *block, uiBut *but, uiHandleBu ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_TEX(bContext *C, uiBut *but, uiHandleButtonData *data) @@ -576,7 +583,7 @@ static void ui_apply_but_TEX(bContext *C, uiBut *but, uiHandleButtonData *data) ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_NUM(bContext *C, uiBut *but, uiHandleButtonData *data) @@ -586,7 +593,7 @@ static void ui_apply_but_NUM(bContext *C, uiBut *but, uiHandleButtonData *data) data->value = ui_get_but_val(but); } else { - data->cancel = 1; + data->cancel = TRUE; return; } } @@ -597,42 +604,42 @@ static void ui_apply_but_NUM(bContext *C, uiBut *but, uiHandleButtonData *data) ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_TOG3(bContext *C, uiBut *but, uiHandleButtonData *data) { - if (but->pointype == SHO) { + if (but->pointype == UI_BUT_POIN_SHORT) { short *sp = (short *)but->poin; - if (BTST(sp[1], but->bitnr)) { - sp[1] = BCLR(sp[1], but->bitnr); - sp[0] = BCLR(sp[0], but->bitnr); + if (UI_BITBUT_TEST(sp[1], but->bitnr)) { + sp[1] = UI_BITBUT_CLR(sp[1], but->bitnr); + sp[0] = UI_BITBUT_CLR(sp[0], but->bitnr); } - else if (BTST(sp[0], but->bitnr)) { - sp[1] = BSET(sp[1], but->bitnr); + else if (UI_BITBUT_TEST(sp[0], but->bitnr)) { + sp[1] = UI_BITBUT_SET(sp[1], but->bitnr); } else { - sp[0] = BSET(sp[0], but->bitnr); + sp[0] = UI_BITBUT_SET(sp[0], but->bitnr); } } else { - if (BTST(*(but->poin + 2), but->bitnr)) { - *(but->poin + 2) = BCLR(*(but->poin + 2), but->bitnr); - *(but->poin) = BCLR(*(but->poin), but->bitnr); + if (UI_BITBUT_TEST(*(but->poin + 2), but->bitnr)) { + *(but->poin + 2) = UI_BITBUT_CLR(*(but->poin + 2), but->bitnr); + *(but->poin) = UI_BITBUT_CLR(*(but->poin), but->bitnr); } - else if (BTST(*(but->poin), but->bitnr)) { - *(but->poin + 2) = BSET(*(but->poin + 2), but->bitnr); + else if (UI_BITBUT_TEST(*(but->poin), but->bitnr)) { + *(but->poin + 2) = UI_BITBUT_SET(*(but->poin + 2), but->bitnr); } else { - *(but->poin) = BSET(*(but->poin), but->bitnr); + *(but->poin) = UI_BITBUT_SET(*(but->poin), but->bitnr); } } ui_check_but(but); ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_VEC(bContext *C, uiBut *but, uiHandleButtonData *data) @@ -642,21 +649,21 @@ static void ui_apply_but_VEC(bContext *C, uiBut *but, uiHandleButtonData *data) ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_COLORBAND(bContext *C, uiBut *but, uiHandleButtonData *data) { ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_CURVE(bContext *C, uiBut *but, uiHandleButtonData *data) { ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_IDPOIN(bContext *C, uiBut *but, uiHandleButtonData *data) @@ -665,7 +672,7 @@ static void ui_apply_but_IDPOIN(bContext *C, uiBut *but, uiHandleButtonData *dat ui_check_but(but); ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } #ifdef WITH_INTERNATIONAL @@ -673,7 +680,7 @@ static void ui_apply_but_CHARTAB(bContext *C, uiBut *but, uiHandleButtonData *da { ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } #endif @@ -710,7 +717,7 @@ static int ui_but_start_drag(bContext *C, uiBut *but, uiHandleButtonData *data, wmDrag *drag; button_activate_state(C, but, BUTTON_STATE_EXIT); - data->cancel = 1; + data->cancel = TRUE; drag = WM_event_start_drag(C, but->icon, but->dragtype, but->dragpoin, ui_get_but_val(but)); if (but->imb) @@ -729,13 +736,10 @@ static void ui_delete_active_linkline(uiBlock *block) uiLink *link; uiLinkLine *line, *nline; int a, b; - - but = block->buttons.first; - while (but) { + + for (but = block->buttons.first; but; but = but->next) { if (but->type == LINK && but->link) { - line = but->link->lines.first; - while (line) { - + for (line = but->link->lines.first; line; line = nline) { nline = line->next; if (line->flag & UI_SELECT) { @@ -755,7 +759,7 @@ static void ui_delete_active_linkline(uiBlock *block) b = 0; for (a = 0; a < (*(link->totlink)); a++) { - if ( (*(link->ppoin))[a] != line->to->poin) { + if ((*(link->ppoin))[a] != line->to->poin) { (*(link->ppoin))[b] = (*(link->ppoin))[a]; b++; } @@ -769,10 +773,8 @@ static void ui_delete_active_linkline(uiBlock *block) MEM_freeN(line); } - line = nline; } } - but = but->next; } } @@ -784,10 +786,10 @@ static uiLinkLine *ui_is_a_link(uiBut *from, uiBut *to) link = from->link; if (link) { - line = link->lines.first; - while (line) { - if (line->from == from && line->to == to) return line; - line = line->next; + for (line = link->lines.first; line; line = line->next) { + if (line->from == from && line->to == to) { + return line; + } } } return NULL; @@ -866,7 +868,7 @@ static void ui_add_link(bContext *C, uiBut *from, uiBut *to) void **oldppoin; int a; - if ( (line = ui_is_a_link(from, to)) ) { + if ((line = ui_is_a_link(from, to))) { line->flag |= UI_SELECT; ui_delete_active_linkline(from->block); return; @@ -929,35 +931,35 @@ static void ui_apply_but_LINK(bContext *C, uiBut *but, uiHandleButtonData *data) ui_apply_but_func(C, but); data->retval = but->retval; } - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_IMAGE(bContext *C, uiBut *but, uiHandleButtonData *data) { ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_HISTOGRAM(bContext *C, uiBut *but, uiHandleButtonData *data) { ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_WAVEFORM(bContext *C, uiBut *but, uiHandleButtonData *data) { ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonData *data) { ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } @@ -988,10 +990,12 @@ static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleBut else { /* we avoid applying interactive edits a second time * at the end with the appliedinteractive flag */ - if (interactive) - data->appliedinteractive = 1; - else if (data->appliedinteractive) + if (interactive) { + data->appliedinteractive = TRUE; + } + else if (data->appliedinteractive) { return; + } } /* ensures we are writing actual values */ @@ -1049,7 +1053,7 @@ static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleBut case PULLDOWN: ui_apply_but_BLOCK(C, but, data); break; - case COL: + case COLOR: if (data->cancel) ui_apply_but_VEC(C, but, data); else @@ -1180,19 +1184,27 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data, } /* RGB triple */ - else if (but->type == COL) { + else if (but->type == COLOR) { float rgb[3]; if (but->poin == NULL && but->rnapoin.data == NULL) ; else if (mode == 'c') { ui_get_but_vectorf(but, rgb); + /* convert to linear color to do compatible copy between gamma and non-gamma */ + if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) + srgb_to_linearrgb_v3_v3(rgb, rgb); + BLI_snprintf(buf, sizeof(buf), "[%f, %f, %f]", rgb[0], rgb[1], rgb[2]); WM_clipboard_text_set(buf, 0); } else { if (sscanf(buf, "[%f, %f, %f]", &rgb[0], &rgb[1], &rgb[2]) == 3) { + /* assume linear colors in buffer */ + if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) + linearrgb_to_srgb_v3_v3(rgb, rgb); + button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); ui_set_but_vectorf(but, rgb); button_activate_state(C, but, BUTTON_STATE_EXIT); @@ -1209,7 +1221,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data, button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); BLI_strncpy(buf, active_data->str, UI_MAX_DRAW_STR); WM_clipboard_text_set(active_data->str, 0); - active_data->cancel = 1; + active_data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else { @@ -1312,7 +1324,10 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho while (i > 0) { if (BLI_str_cursor_step_prev_utf8(origstr, but->ofs, &i)) { - if (BLF_width(fstyle->uifont_id, origstr + i) > (startx - x) * 0.25f) break; // 0.25 == scale factor for less sensitivity + /* 0.25 == scale factor for less sensitivity */ + if (BLF_width(fstyle->uifont_id, origstr + i) > (startx - x) * 0.25f) { + break; + } } else { break; /* unlikely but possible */ @@ -1375,7 +1390,7 @@ static void ui_textedit_set_cursor_select(uiBut *but, uiHandleButtonData *data, else if (x < data->selstartx) data->selextend = EXTEND_LEFT; ui_textedit_set_cursor_pos(but, data, x); - + if (data->selextend == EXTEND_RIGHT) but->selend = but->pos; if (data->selextend == EXTEND_LEFT) but->selsta = but->pos; @@ -1429,7 +1444,8 @@ static int ui_textedit_type_ascii(uiBut *but, uiHandleButtonData *data, char asc return ui_textedit_type_buf(but, data, buf, 1); } -static void ui_textedit_move(uiBut *but, uiHandleButtonData *data, strCursorJumpDirection direction, int select, strCursorJumpType jump) +static void ui_textedit_move(uiBut *but, uiHandleButtonData *data, strCursorJumpDirection direction, + int select, strCursorJumpType jump) { const char *str = data->str; const int len = strlen(str); @@ -1778,13 +1794,13 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle break; case RIGHTMOUSE: case ESCKEY: - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); retval = WM_UI_HANDLER_BREAK; break; - case LEFTMOUSE: { - + case LEFTMOUSE: + { /* exit on LMB only on RELEASE for searchbox, to mimic other popups, and allow multiple menu levels */ if (data->searchbox) inbox = ui_searchbox_inside(data->searchbox, event->x, event->y); @@ -1805,7 +1821,7 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle else if (inbox == 0) { /* if searchbox, click outside will cancel */ if (data->searchbox) - data->cancel = data->escapecancel = 1; + data->cancel = data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); retval = WM_UI_HANDLER_BREAK; } @@ -1835,11 +1851,13 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle } break; case RIGHTARROWKEY: - ui_textedit_move(but, data, STRCUR_DIR_NEXT, event->shift, event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); + ui_textedit_move(but, data, STRCUR_DIR_NEXT, + event->shift, event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); retval = WM_UI_HANDLER_BREAK; break; case LEFTARROWKEY: - ui_textedit_move(but, data, STRCUR_DIR_PREV, event->shift, event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); + ui_textedit_move(but, data, STRCUR_DIR_PREV, + event->shift, event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); retval = WM_UI_HANDLER_BREAK; break; case DOWNARROWKEY: @@ -1849,7 +1867,8 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle } /* pass on purposedly */ case ENDKEY: - ui_textedit_move(but, data, STRCUR_DIR_NEXT, event->shift, STRCUR_JUMP_ALL); + ui_textedit_move(but, data, STRCUR_DIR_NEXT, + event->shift, STRCUR_JUMP_ALL); retval = WM_UI_HANDLER_BREAK; break; case UPARROWKEY: @@ -1859,7 +1878,8 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle } /* pass on purposedly */ case HOMEKEY: - ui_textedit_move(but, data, STRCUR_DIR_PREV, event->shift, STRCUR_JUMP_ALL); + ui_textedit_move(but, data, STRCUR_DIR_PREV, + event->shift, STRCUR_JUMP_ALL); retval = WM_UI_HANDLER_BREAK; break; case PADENTER: @@ -1868,12 +1888,14 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle retval = WM_UI_HANDLER_BREAK; break; case DELKEY: - changed = ui_textedit_delete(but, data, 1, event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); + changed = ui_textedit_delete(but, data, 1, + event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); retval = WM_UI_HANDLER_BREAK; break; case BACKSPACEKEY: - changed = ui_textedit_delete(but, data, 0, event->shift ? STRCUR_JUMP_ALL : (event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE)); + changed = ui_textedit_delete(but, data, 0, + event->shift ? STRCUR_JUMP_ALL : (event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE)); retval = WM_UI_HANDLER_BREAK; break; @@ -1950,7 +1972,8 @@ static void ui_do_but_textedit_select(bContext *C, uiBlock *block, uiBut *but, u int mx, my, retval = WM_UI_HANDLER_CONTINUE; switch (event->type) { - case MOUSEMOVE: { + case MOUSEMOVE: + { mx = event->x; my = event->y; ui_window_to_block(data->region, block, &mx, &my); @@ -2073,14 +2096,18 @@ static void ui_blockopen_begin(bContext *C, uiBut *but, uiHandleButtonData *data menufunc = ui_block_func_ICONTEXTROW; arg = but; break; - case COL: + case COLOR: ui_get_but_vectorf(but, data->origvec); copy_v3_v3(data->vec, data->origvec); but->editvec = data->vec; - handlefunc = ui_block_func_COL; + handlefunc = ui_block_func_COLOR; arg = but; break; + + /* quiet warnings for unhandled types */ + default: + break; } if (func || handlefunc) { @@ -2134,7 +2161,7 @@ static int ui_do_but_BUT(bContext *C, uiBut *but, uiHandleButtonData *data, wmEv else if (data->state == BUTTON_STATE_WAIT_RELEASE) { if (event->type == LEFTMOUSE && event->val != KM_PRESS) { if (!(but->flag & UI_SELECT)) - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); return WM_UI_HANDLER_BREAK; } @@ -2165,7 +2192,7 @@ static int ui_do_but_HOTKEYEVT(bContext *C, uiBut *but, uiHandleButtonData *data if (but->flag & UI_BUT_IMMEDIATE) ui_set_but_val(but, 0); else - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); return WM_UI_HANDLER_BREAK; } @@ -2187,14 +2214,14 @@ static int ui_do_but_HOTKEYEVT(bContext *C, uiBut *but, uiHandleButtonData *data if (WM_key_event_string(event->type)[0]) ui_set_but_val(but, event->type); else - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); return WM_UI_HANDLER_BREAK; } else if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } @@ -2220,7 +2247,7 @@ static int ui_do_but_KEYEVT(bContext *C, uiBut *but, uiHandleButtonData *data, w if (WM_key_event_string(event->type)[0]) ui_set_but_val(but, event->type); else - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } @@ -2568,8 +2595,8 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton } else if (data->state == BUTTON_STATE_NUM_EDITING) { if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (event->type == LEFTMOUSE && event->val != KM_PRESS) { @@ -2619,7 +2646,7 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton if (temp >= softmin && temp <= softmax) data->value = (double)temp; else - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } @@ -2630,7 +2657,7 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton if (temp >= softmin && temp <= softmax) data->value = (double)temp; else - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } @@ -2790,8 +2817,8 @@ static int ui_do_but_SLI(bContext *C, uiBlock *block, uiBut *but, uiHandleButton } else if (data->state == BUTTON_STATE_NUM_EDITING) { if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (event->type == LEFTMOUSE && event->val != KM_PRESS) { @@ -2849,7 +2876,7 @@ static int ui_do_but_SLI(bContext *C, uiBlock *block, uiBut *but, uiHandleButton if (temp >= softmin && temp <= softmax) data->value = temp; else - data->cancel = 1; + data->cancel = TRUE; } else { if (f < tempf) tempf -= 0.01f; @@ -2858,7 +2885,7 @@ static int ui_do_but_SLI(bContext *C, uiBlock *block, uiBut *but, uiHandleButton if (tempf >= softmin && tempf <= softmax) data->value = tempf; else - data->cancel = 1; + data->cancel = TRUE; } button_activate_state(C, but, BUTTON_STATE_EXIT); @@ -2907,8 +2934,8 @@ static int ui_do_but_SCROLL(bContext *C, uiBlock *block, uiBut *but, uiHandleBut } else if (data->state == BUTTON_STATE_NUM_EDITING) { if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (event->type == LEFTMOUSE && event->val != KM_PRESS) { @@ -2978,7 +3005,7 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, wm return WM_UI_HANDLER_BREAK; } } - else if (but->type == COL) { + else if (but->type == COLOR) { if (ELEM(event->type, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->alt) { float *hsv = ui_block_hsv_get(but->block); float col[3]; @@ -3010,7 +3037,7 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, wm /* outside icon quit, not needed if drag activated */ if (0 == ui_but_mouse_inside_icon(but, data->region, event)) { button_activate_state(C, but, BUTTON_STATE_EXIT); - data->cancel = 1; + data->cancel = TRUE; return WM_UI_HANDLER_BREAK; } @@ -3321,8 +3348,8 @@ static int ui_do_but_HSVCUBE(bContext *C, uiBlock *block, uiBut *but, uiHandleBu } else if (data->state == BUTTON_STATE_NUM_EDITING) { if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (event->type == MOUSEMOVE) { @@ -3501,8 +3528,8 @@ static int ui_do_but_HSVCIRCLE(bContext *C, uiBlock *block, uiBut *but, uiHandle } else if (data->state == BUTTON_STATE_NUM_EDITING) { if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } /* XXX hardcoded keymap check.... */ @@ -3794,7 +3821,7 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt } else { /* move the view */ - data->cancel = 1; + data->cancel = TRUE; } data->dragsel = sel; @@ -3916,8 +3943,8 @@ static int ui_do_but_HISTOGRAM(bContext *C, uiBlock *block, uiBut *but, uiHandle } else if (data->state == BUTTON_STATE_NUM_EDITING) { if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (event->type == MOUSEMOVE) { @@ -3999,8 +4026,8 @@ static int ui_do_but_WAVEFORM(bContext *C, uiBlock *block, uiBut *but, uiHandleB } else if (data->state == BUTTON_STATE_NUM_EDITING) { if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (event->type == MOUSEMOVE) { @@ -4066,8 +4093,8 @@ static int ui_do_but_VECTORSCOPE(bContext *C, uiBlock *block, uiBut *but, uiHand } else if (data->state == BUTTON_STATE_NUM_EDITING) { if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (event->type == MOUSEMOVE) { @@ -4209,7 +4236,7 @@ static int ui_do_but_LINK(bContext *C, uiBut *but, uiHandleButtonData *data, wmE if (event->type == LEFTMOUSE && event->val != KM_PRESS) { if (!(but->flag & UI_SELECT)) - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); return WM_UI_HANDLER_BREAK; } @@ -4283,8 +4310,8 @@ static int ui_do_but_TRACKPREVIEW(bContext *C, uiBlock *block, uiBut *but, uiHan } else if (data->state == BUTTON_STATE_NUM_EDITING) { if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (event->type == MOUSEMOVE) { @@ -4736,7 +4763,10 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event) ui_but_drop(C, event, but, data); } /* handle keyframing */ - else if (event->type == IKEY && !ELEM(KM_MOD_FIRST, event->ctrl, event->oskey) && event->val == KM_PRESS) { + else if ((event->type == IKEY) && + !ELEM(KM_MOD_FIRST, event->ctrl, event->oskey) && + (event->val == KM_PRESS)) + { if (event->alt) { if (event->shift) { ui_but_anim_clear_keyframe(C); @@ -4754,7 +4784,10 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event) return WM_UI_HANDLER_BREAK; } /* handle drivers */ - else if (event->type == DKEY && !ELEM3(KM_MOD_FIRST, event->ctrl, event->oskey, event->shift) && event->val == KM_PRESS) { + else if ((event->type == DKEY) && + !ELEM3(KM_MOD_FIRST, event->ctrl, event->oskey, event->shift) && + (event->val == KM_PRESS)) + { if (event->alt) ui_but_anim_remove_driver(C); else @@ -4765,7 +4798,10 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event) return WM_UI_HANDLER_BREAK; } /* handle keyingsets */ - else if (event->type == KKEY && !ELEM3(KM_MOD_FIRST, event->ctrl, event->oskey, event->shift) && event->val == KM_PRESS) { + else if ((event->type == KKEY) && + !ELEM3(KM_MOD_FIRST, event->ctrl, event->oskey, event->shift) && + (event->val == KM_PRESS)) + { if (event->alt) ui_but_anim_remove_keyingset(C); else @@ -4876,7 +4912,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event) case BUTM: retval = ui_do_but_BUT(C, but, data, event); break; - case COL: + case COLOR: if (but->a1 == UI_GRAD_V_ALT) /* signal to prevent calling up color picker */ retval = ui_do_but_EXIT(C, but, data, event); else @@ -4901,6 +4937,10 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event) case CHARTAB: retval = ui_do_but_CHARTAB(C, block, but, data, event); break; +#else + /* do nothing */ + case CHARTAB: + break; #endif case LINK: @@ -4910,6 +4950,11 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event) case TRACKPREVIEW: retval = ui_do_but_TRACKPREVIEW(C, block, but, data, event); break; + + /* quiet warnings for unhandled types */ + case SEPR: + case BUT_EXTRA: + break; } return retval; @@ -5186,17 +5231,33 @@ static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState s /* automatic open pulldown block timer */ if (ELEM3(but->type, BLOCK, PULLDOWN, ICONTEXTROW)) { - if (data->used_mouse && !data->autoopentimer) { + if ((data->used_mouse == TRUE) && + (data->autoopentimer == FALSE) && + /* don't popup the first time, + * see description on this member for info */ + (but->block->auto_is_first_event == FALSE)) + { int time; - if (but->block->auto_open == TRUE) time = 1; // test for toolbox - else if ((but->block->flag & UI_BLOCK_LOOP && but->type != BLOCK) || but->block->auto_open == TRUE) time = 5 * U.menuthreshold2; - else if (U.uiflag & USER_MENUOPENAUTO) time = 5 * U.menuthreshold1; - else time = -1; + if (but->block->auto_open == TRUE) { /* test for toolbox */ + time = 1; + } + else if ((but->block->flag & UI_BLOCK_LOOP && but->type != BLOCK) || but->block->auto_open == TRUE) { + time = 5 * U.menuthreshold2; + } + else if (U.uiflag & USER_MENUOPENAUTO) { + time = 5 * U.menuthreshold1; + } + else { + time = -1; /* do nothing */ + } - if (time >= 0) + if (time >= 0) { data->autoopentimer = WM_event_add_timer(data->wm, data->window, TIMER, 0.02 * (double)time); + } } + + but->block->auto_is_first_event = FALSE; } } else { @@ -5288,7 +5349,7 @@ static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonA /* XXX curve is temp */ } else { - data->interactive = 1; + data->interactive = TRUE; } data->state = BUTTON_STATE_INIT; @@ -5417,7 +5478,7 @@ void ui_button_active_free(const bContext *C, uiBut *but) * case cleanly anyway in case it happens */ if (but->active) { data = but->active; - data->cancel = 1; + data->cancel = TRUE; button_activate_exit((bContext *)C, data, but, 0, 1); } } @@ -5647,7 +5708,7 @@ static void ui_handle_button_activate(bContext *C, ARegion *ar, uiBut *but, uiBu oldbut = ui_but_find_activated(ar); if (oldbut) { data = oldbut->active; - data->cancel = 1; + data->cancel = TRUE; button_activate_exit(C, data, oldbut, 0, 0); } @@ -5675,18 +5736,18 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but) switch (event->type) { case WINDEACTIVATE: case EVT_BUT_CANCEL: - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); retval = WM_UI_HANDLER_CONTINUE; break; case MOUSEMOVE: /* verify if we are still over the button, if not exit */ if (!ui_mouse_inside_button(ar, but, event->x, event->y)) { - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (ui_but_find_mouse_over(ar, event->x, event->y) != but) { - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (event->x != event->prevx || event->y != event->prevy) { @@ -5696,7 +5757,8 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but) } break; - case TIMER: { + case TIMER: + { /* handle tooltip timer */ if (event->customdata == data->tooltiptimer) { WM_event_remove_timer(data->wm, data->window, data->tooltiptimer); @@ -5734,7 +5796,7 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but) else if (data->state == BUTTON_STATE_WAIT_RELEASE) { switch (event->type) { case WINDEACTIVATE: - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); break; @@ -5750,18 +5812,18 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but) if (ui_mouse_inside_button(ar, but, event->x, event->y)) { if (!(but->flag & UI_SELECT)) { but->flag |= (UI_SELECT | UI_ACTIVE); - data->cancel = 0; + data->cancel = FALSE; ED_region_tag_redraw(data->region); } } else { if (but->flag & UI_SELECT) { but->flag &= ~(UI_SELECT | UI_ACTIVE); - data->cancel = 1; + data->cancel = TRUE; ED_region_tag_redraw(data->region); } } - } + } break; default: /* otherwise catch mouse release event */ @@ -5773,9 +5835,11 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but) } else if (data->state == BUTTON_STATE_WAIT_FLASH) { switch (event->type) { - case TIMER: { - if (event->customdata == data->flashtimer) + case TIMER: + { + if (event->customdata == data->flashtimer) { button_activate_state(C, but, BUTTON_STATE_EXIT); + } } } @@ -5785,21 +5849,41 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but) /* check for exit because of mouse-over another button */ switch (event->type) { case MOUSEMOVE: - - if (data->menu && data->menu->region) - if (ui_mouse_inside_region(data->menu->region, event->x, event->y)) + { + /* if the mouse is over the button, do nothing */ + if (ui_mouse_inside_button(data->region, but, event->x, event->y)) { + break; + } + + /* if the mouse is over the menu, also do nothing */ + if (data->menu && data->menu->region) { + if (ui_mouse_inside_region(data->menu->region, event->x, event->y)) { break; - - { - uiBut *bt = ui_but_find_mouse_over(ar, event->x, event->y); + } + else { + /* make a rectangle between the menu and the button that opened it, + * this avoids any space between them exiting the popup. see [#29072] - campbell */ + rctf rct_all = but->rect; + rctf rct_win; + + ui_block_to_window_fl(ar, block, &rct_all.xmin, &rct_all.ymin); + ui_block_to_window_fl(ar, block, &rct_all.xmax, &rct_all.ymax); + + BLI_rctf_rcti_copy(&rct_win, &data->menu->region->winrct); + BLI_rctf_union(&rct_all, &rct_win); - if (bt && bt->active != data) { - if (but->type != COL) /* exception */ - data->cancel = 1; - button_activate_state(C, but, BUTTON_STATE_EXIT); + if (BLI_rctf_isect_pt(&rct_all, event->x, event->y)) { + break; + } } - break; } + + if (but->type != COLOR) { /* exception */ + data->cancel = TRUE; + } + button_activate_state(C, but, BUTTON_STATE_EXIT); + break; + } } ui_do_button(C, block, but, event); @@ -5904,15 +5988,19 @@ static void ui_handle_button_return_submenu(bContext *C, wmEvent *event, uiBut * /* copy over return values from the closing menu */ if ((menu->menuretval & UI_RETURN_OK) || (menu->menuretval & UI_RETURN_UPDATE)) { - if (but->type == COL) + if (but->type == COLOR) copy_v3_v3(data->vec, menu->retvec); else if (ELEM3(but->type, MENU, ICONROW, ICONTEXTROW)) data->value = menu->retvalue; } if (menu->menuretval & UI_RETURN_UPDATE) { - if (data->interactive) ui_apply_button(C, but->block, but, data, 1); - else ui_check_but(but); + if (data->interactive) { + ui_apply_button(C, but->block, but, data, TRUE); + } + else { + ui_check_but(but); + } menu->menuretval = 0; } @@ -5920,7 +6008,7 @@ static void ui_handle_button_return_submenu(bContext *C, wmEvent *event, uiBut * /* now change button state or exit, which will close the submenu */ if ((menu->menuretval & UI_RETURN_OK) || (menu->menuretval & UI_RETURN_CANCEL)) { if (menu->menuretval != UI_RETURN_OK) - data->cancel = 1; + data->cancel = TRUE; button_activate_exit(C, data, but, 1, 0); } @@ -5935,7 +6023,7 @@ static void ui_handle_button_return_submenu(bContext *C, wmEvent *event, uiBut * button_activate_state(C, but, BUTTON_STATE_HIGHLIGHT); } else { - data->cancel = 1; + data->cancel = TRUE; button_activate_exit(C, data, but, 1, 0); } } @@ -5956,7 +6044,7 @@ static void ui_handle_button_return_submenu(bContext *C, wmEvent *event, uiBut * static void ui_mouse_motion_towards_init(uiPopupBlockHandle *menu, int mx, int my, int force) { if (!menu->dotowards || force) { - menu->dotowards = 1; + menu->dotowards = TRUE; menu->towardsx = mx; menu->towardsy = my; @@ -5972,7 +6060,9 @@ static int ui_mouse_motion_towards_check(uiBlock *block, uiPopupBlockHandle *men float p1[2], p2[2], p3[2], p4[2], oldp[2], newp[2]; int closer; - if (!menu->dotowards) return 0; + if (!menu->dotowards) { + return 0; + } /* verify that we are moving towards one of the edges of the * menu block, in other words, in the triangle formed by the @@ -6004,11 +6094,11 @@ static int ui_mouse_motion_towards_check(uiBlock *block, uiPopupBlockHandle *men isect_point_tri_v2(newp, oldp, p4, p1)); if (!closer) - menu->dotowards = 0; + menu->dotowards = FALSE; /* 1 second timer */ if (PIL_check_seconds_timer() - menu->towardstime > BUTTON_MOUSE_TOWARDS_THRESH) - menu->dotowards = 0; + menu->dotowards = FALSE; return menu->dotowards; } @@ -6164,7 +6254,9 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle case WHEELUPMOUSE: case WHEELDOWNMOUSE: /* arrowkeys: only handle for block_loop blocks */ - if (event->alt || event->shift || event->ctrl || event->oskey) ; + if (event->alt || event->shift || event->ctrl || event->oskey) { + /* pass */ + } else if (inside || (block->flag & UI_BLOCK_LOOP)) { if (event->val == KM_PRESS) { but = ui_but_find_activated(ar); @@ -6213,8 +6305,9 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle } } - if (bt) + if (bt) { ui_handle_button_activate(C, ar, bt, BUTTON_ACTIVATE); + } } } @@ -6249,7 +6342,7 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle count = 0; for (but = block->buttons.first; but; but = but->next) { - int doit = 0; + int doit = FALSE; if (but->type != LABEL && but->type != SEPR) count++; @@ -6258,19 +6351,29 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle if (but->rnapoin.data && but->rnaprop) { if (ELEM(RNA_property_subtype(but->rnaprop), PROP_LAYER, PROP_LAYER_MEMBER)) { if (but->rnaindex == act - 1) - doit = 1; + doit = TRUE; } } /* exception for menus like layer buts, with button aligning they're not drawn in order */ else if (but->type == TOGR) { if (but->bitnr == act - 1) - doit = 1; + doit = TRUE; + } + else if (count == act) { + doit = TRUE; } - else if (count == act) - doit = 1; if (doit) { - ui_handle_button_activate(C, ar, but, BUTTON_ACTIVATE_APPLY); + /* activate buttons but open menu's */ + uiButtonActivateType activate; + if (but->type == PULLDOWN) { + activate = BUTTON_ACTIVATE_OPEN; + } + else { + activate = BUTTON_ACTIVATE_APPLY; + } + + ui_handle_button_activate(C, ar, but, activate); break; } } @@ -6315,7 +6418,7 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle for (but = block->buttons.first; but; but = but->next) { if (but->menu_key == event->type) { - if (but->type == BUT) { + if (ELEM(but->type, BUT, BUTM)) { /* mainly for operator buttons */ ui_handle_button_activate(C, ar, but, BUTTON_ACTIVATE_APPLY); } @@ -6408,7 +6511,9 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle * buttons inside this region. disabled inside check .. not sure * anymore why it was there? but it meant enter didn't work * for example when mouse was not over submenu */ - if ((/*inside &&*/ (!menu->menuretval || (menu->menuretval & UI_RETURN_UPDATE)) && retval == WM_UI_HANDLER_CONTINUE) || event->type == TIMER) { + if ((event->type == TIMER) || + (/*inside &&*/ (!menu->menuretval || (menu->menuretval & UI_RETURN_UPDATE)) && retval == WM_UI_HANDLER_CONTINUE)) + { but = ui_but_find_activated(ar); if (but) { diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index dd3c2e491a7..f6f12f98181 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -59,7 +59,6 @@ #include "BKE_context.h" #include "BKE_global.h" #include "BKE_icons.h" -#include "BKE_utildefines.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" @@ -621,7 +620,7 @@ static void init_iconfile_list(struct ListBase *list) if (restoredir && !chdir(olddir)) {} /* fix warning about checking return value */ for (i = 0; i < totfile; i++) { - if ( (dir[i].type & S_IFREG) ) { + if ((dir[i].type & S_IFREG)) { char *filename = dir[i].relname; if (BLI_testextensie(filename, ".png")) { @@ -836,7 +835,7 @@ static void icon_create_rect(struct PreviewImage *prv_img, enum eIconSizes size) if (G.debug & G_DEBUG) printf("%s, error: requested preview image does not exist", __func__); } - if (!prv_img->rect[size]) { + else if (!prv_img->rect[size]) { prv_img->w[size] = render_size; prv_img->h[size] = render_size; prv_img->changed[size] = 1; diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 567109e26d0..73e6427d1cb 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -94,8 +94,7 @@ typedef enum { UI_WTYPE_BOX, UI_WTYPE_SCROLL, UI_WTYPE_LISTITEM, - UI_WTYPE_PROGRESSBAR, - + UI_WTYPE_PROGRESSBAR } uiWidgetTypeEnum; /* panel limits */ @@ -131,6 +130,14 @@ typedef enum { /* for scope resize zone */ #define SCOPE_RESIZE_PAD 9 +/* bit button defines */ +/* Bit operations */ +#define UI_BITBUT_TEST(a, b) ( ( (a) & 1 << (b) ) != 0) +#define UI_BITBUT_SET(a, b) ( (a) | 1 << (b) ) +#define UI_BITBUT_CLR(a, b) ( (a) & ~(1 << (b)) ) +/* bit-row */ +#define UI_BITBUT_ROW(min, max) (((max) >= 31 ? 0xFFFFFFFF : (1 << (max + 1)) - 1) - ((min) ? ((1 << (min)) - 1) : 0) ) + typedef struct uiLinkLine { /* only for draw/edit */ struct uiLinkLine *next, *prev; struct uiBut *from, *to; @@ -151,8 +158,9 @@ typedef struct { struct uiBut { struct uiBut *next, *prev; int flag, drawflag; - short type, pointype, bit, bitnr, retval, strwidth, ofs, pos, selsta, selend, alignnr; - short pad1; + eButType type; + eButPointerType pointype; + short bit, bitnr, retval, strwidth, ofs, pos, selsta, selend, alignnr; char *str; char strdata[UI_MAX_NAME_STR]; @@ -297,7 +305,17 @@ struct uiBlock { char direction; char dt; /* drawtype: UI_EMBOSS, UI_EMBOSSN ... etc, copied to buttons */ char auto_open; - char _pad[7]; + + /* this setting is used so newly opened menu's dont popout the first item under the mouse, + * the reasoning behind this is because of muscle memory for opening menus. + * + * Without this, the first time opening a Submenu and activating an item in it will be 2 steps, + * but the second time the same item is accessed the menu memory would auto activate the + * last used menu and the key intended to select that submenu ends up being passed into the submenu. + * - Campbell + */ + char auto_is_first_event; + char _pad[6]; double auto_open_last; const char *lockstr; @@ -308,7 +326,8 @@ struct uiBlock { char endblock; /* uiEndBlock done? */ float xofs, yofs; /* offset to parent button */ - int dobounds, mx, my; /* for doing delayed */ + eBlockBoundsCalc bounds_type; /* for doing delayed */ + int mx, my; int bounds, minbounds; /* for doing delayed */ rctf safety; /* pulldowns, to detect outside, can differ per case how it is created */ @@ -340,7 +359,7 @@ void ui_fontscale(short *points, float aspect); extern void ui_block_to_window_fl(const struct ARegion *ar, uiBlock *block, float *x, float *y); extern void ui_block_to_window(const struct ARegion *ar, uiBlock *block, int *x, int *y); -extern void ui_block_to_window_rct(const struct ARegion *ar, uiBlock *block, rctf *graph, rcti *winr); +extern void ui_block_to_window_rct(const struct ARegion *ar, uiBlock *block, const rctf *graph, rcti *winr); extern void ui_window_to_block_fl(const struct ARegion *ar, uiBlock *block, float *x, float *y); extern void ui_window_to_block(const struct ARegion *ar, uiBlock *block, int *x, int *y); extern void ui_window_to_region(const ARegion *ar, int *x, int *y); @@ -402,7 +421,7 @@ struct uiPopupBlockHandle { float retvec[4]; }; -uiBlock *ui_block_func_COL(struct bContext *C, uiPopupBlockHandle *handle, void *arg_but); +uiBlock *ui_block_func_COLOR(struct bContext *C, uiPopupBlockHandle *handle, void *arg_but); void ui_block_func_ICONROW(struct bContext *C, uiLayout *layout, void *arg_but); void ui_block_func_ICONTEXTROW(struct bContext *C, uiLayout *layout, void *arg_but); @@ -521,4 +540,3 @@ int ui_but_anim_expression_create(uiBut *but, const char *str); void ui_but_anim_autokey(struct bContext *C, uiBut *but, struct Scene *scene, float cfra); #endif - diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index b68e14898d0..803fd928085 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -2837,7 +2837,9 @@ static void ui_layout_operator_buts__reset_cb(bContext *UNUSED(C), void *op_pt, } /* this function does not initialize the layout, functions can be called on the layout before and after */ -void uiLayoutOperatorButs(const bContext *C, uiLayout *layout, wmOperator *op, int (*check_prop)(struct PointerRNA *, struct PropertyRNA *), const char label_align, const short flag) +void uiLayoutOperatorButs(const bContext *C, uiLayout *layout, wmOperator *op, + int (*check_prop)(struct PointerRNA *, struct PropertyRNA *), + const char label_align, const short flag) { if (!op->properties) { IDPropertyTemplate val = {0}; diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index 67c0d04a79f..e8b8959fd43 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -908,19 +908,19 @@ static void UI_OT_editsource(wmOperatorType *ot) void edittranslation_find_po_file(const char *root, const char *uilng, char *path, const size_t maxlen) { - char t[32]; /* Should be more than enough! */ + char tstr[32]; /* Should be more than enough! */ /* First, full lang code. */ - sprintf(t, "%s.po", uilng); + BLI_snprintf(tstr, sizeof(tstr), "%s.po", uilng); BLI_join_dirfile(path, maxlen, root, uilng); - BLI_join_dirfile(path, maxlen, path, t); + BLI_join_dirfile(path, maxlen, path, tstr); if (BLI_is_file(path)) return; /* Now try without the second iso code part (_ES in es_ES). */ - strncpy(t, uilng, 2); - strcpy(t + 2, uilng + 5); /* Because of some codes like sr_SR@latin... */ - BLI_join_dirfile(path, maxlen, root, t); - sprintf(t, "%s.po", t); - BLI_join_dirfile(path, maxlen, path, t); + strncpy(tstr, uilng, 2); + BLI_strncpy(tstr + 2, uilng + 5, sizeof(tstr) - 2); /* Because of some codes like sr_SR@latin... */ + BLI_join_dirfile(path, maxlen, root, tstr); + strcat(tstr, ".po"); + BLI_join_dirfile(path, maxlen, path, tstr); if (BLI_is_file(path)) return; path[0] = '\0'; diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 96c1b00d46d..10a64d50887 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -1648,6 +1648,18 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut ar->regiondata = handle; + /* set UI_BLOCK_NUMSELECT before uiEndBlock() so we get alphanumeric keys assigned */ + if (but) { + if (but->type == PULLDOWN) { + block->flag |= UI_BLOCK_NUMSELECT; + } + } + else { + block->flag |= UI_BLOCK_POPUP | UI_BLOCK_NUMSELECT; + } + + block->flag |= UI_BLOCK_LOOP; + if (!block->endblock) uiEndBlock(C, block); @@ -1665,7 +1677,6 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut saferct = MEM_callocN(sizeof(uiSafetyRct), "uiSafetyRct"); saferct->safety = block->safety; BLI_addhead(&block->saferct, saferct); - block->flag |= UI_BLOCK_POPUP | UI_BLOCK_NUMSELECT; } /* clip block with window boundary */ @@ -1680,8 +1691,6 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut ar->winrct.ymax = block->rect.ymax + MENU_TOP; ui_block_translate(block, -ar->winrct.xmin, -ar->winrct.ymin); - - block->flag |= UI_BLOCK_LOOP; /* adds subwindow */ ED_region_init(C, ar); @@ -1797,11 +1806,11 @@ static void ui_block_func_MENUSTR(bContext *UNUSED(C), uiLayout *layout, void *a bt->flag = UI_TEXT_LEFT; } else if (entry->icon) { - uiDefIconTextButF(block, BUTM | FLO, B_NOP, entry->icon, entry->str, 0, 0, + uiDefIconTextButF(block, BUTM, B_NOP, entry->icon, entry->str, 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, &handle->retvalue, (float) entry->retval, 0.0, 0, 0, ""); } else { - uiDefButF(block, BUTM | FLO, B_NOP, entry->str, 0, 0, + uiDefButF(block, BUTM, B_NOP, entry->str, 0, 0, UI_UNIT_X * 5, UI_UNIT_X, &handle->retvalue, (float) entry->retval, 0.0, 0, 0, ""); } } @@ -1819,7 +1828,7 @@ void ui_block_func_ICONROW(bContext *UNUSED(C), uiLayout *layout, void *arg_but) uiBlockSetFlag(block, UI_BLOCK_MOVEMOUSE_QUIT); for (a = (int)but->hardmin; a <= (int)but->hardmax; a++) - uiDefIconButF(block, BUTM | FLO, B_NOP, but->icon + (a - but->hardmin), 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, + uiDefIconButF(block, BUTM, B_NOP, but->icon + (a - but->hardmin), 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, &handle->retvalue, (float)a, 0.0, 0, 0, ""); } @@ -1849,7 +1858,7 @@ void ui_block_func_ICONTEXTROW(bContext *UNUSED(C), uiLayout *layout, void *arg_ if (entry->sepr) uiItemS(layout); else - uiDefIconTextButF(block, BUTM | FLO, B_NOP, (short)((but->icon) + (entry->retval - but->hardmin)), entry->str, + uiDefIconTextButF(block, BUTM, B_NOP, (short)((but->icon) + (entry->retval - but->hardmin)), entry->str, 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, &handle->retvalue, (float) entry->retval, 0.0, 0, 0, ""); } @@ -2021,27 +2030,20 @@ static void picker_new_hide_reveal(uiBlock *block, short colormode) /* tag buttons */ for (bt = block->buttons.first; bt; bt = bt->next) { - - if (bt->type == LABEL) { - if (bt->str[1] == 'G') { - if (colormode == 2) bt->flag &= ~UI_HIDDEN; - else bt->flag |= UI_HIDDEN; - } + if (bt->func == do_picker_rna_cb && bt->type == NUMSLI && bt->rnaindex != 3) { + /* RGB sliders (color circle and alpha are always shown) */ + if (colormode == 0) bt->flag &= ~UI_HIDDEN; + else bt->flag |= UI_HIDDEN; } - - if (bt->type == NUMSLI || bt->type == TEX) { - if (bt->str[1] == 'e') { - if (colormode == 2) bt->flag &= ~UI_HIDDEN; - else bt->flag |= UI_HIDDEN; - } - else if (ELEM3(bt->str[0], 'R', 'G', 'B')) { - if (colormode == 0) bt->flag &= ~UI_HIDDEN; - else bt->flag |= UI_HIDDEN; - } - else if (ELEM3(bt->str[0], 'H', 'S', 'V')) { - if (colormode == 1) bt->flag &= ~UI_HIDDEN; - else bt->flag |= UI_HIDDEN; - } + else if (bt->func == do_hsv_rna_cb) { + /* HSV sliders */ + if (colormode == 1) bt->flag &= ~UI_HIDDEN; + else bt->flag |= UI_HIDDEN; + } + else if (bt->func == do_hex_rna_cb || bt->type == LABEL) { + /* hex input or gamma correction status label */ + if (colormode == 2) bt->flag &= ~UI_HIDDEN; + else bt->flag |= UI_HIDDEN; } } } @@ -2235,7 +2237,7 @@ static int ui_picker_small_wheel_cb(const bContext *UNUSED(C), uiBlock *block, w return 0; } -uiBlock *ui_block_func_COL(bContext *C, uiPopupBlockHandle *handle, void *arg_but) +uiBlock *ui_block_func_COLOR(bContext *C, uiPopupBlockHandle *handle, void *arg_but) { uiBut *but = arg_but; uiBlock *block; @@ -2434,6 +2436,7 @@ uiPopupBlockHandle *ui_popup_menu_create(bContext *C, ARegion *butregion, uiBut uiPopupMenu *pup; pup = MEM_callocN(sizeof(uiPopupMenu), __func__); pup->block = uiBeginBlock(C, NULL, __func__, UI_EMBOSSP); + pup->block->flag |= UI_BLOCK_NUMSELECT; /* default menus to numselect */ pup->layout = uiBlockLayout(pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 0, 0, 200, 0, style); pup->slideout = (but && (but->block->flag & UI_BLOCK_LOOP)); pup->but = but; @@ -2499,6 +2502,7 @@ uiPopupMenu *uiPupMenuBegin(bContext *C, const char *title, int icon) pup->block = uiBeginBlock(C, NULL, __func__, UI_EMBOSSP); pup->block->flag |= UI_BLOCK_POPUP_MEMORY; pup->block->puphash = ui_popup_menu_hash(title); + pup->block->auto_is_first_event = TRUE; pup->layout = uiBlockLayout(pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 0, 0, 200, 0, style); uiLayoutSetOperatorContext(pup->layout, WM_OP_EXEC_REGION_WIN); diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index ee0613ea0d0..b16250021d3 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -257,7 +257,7 @@ uiStyle *UI_GetStyle(void) { uiStyle *style = NULL; /* offset is two struct uiStyle pointers */ - /* style = BLI_findstring( &U.uistyles, "Unifont Style", sizeof(style)*2 ) */; + /* style = BLI_findstring(&U.uistyles, "Unifont Style", sizeof(style) * 2) */; return (style != NULL) ? style : U.uistyles.first; } diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 2137f4ec14c..9f0dc4af226 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -1025,7 +1025,7 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con) uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, xco + 10, yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); if (con->flag & CONSTRAINT_DISABLE) - uiLayoutSetRedAlert(row, 1); + uiLayoutSetRedAlert(row, TRUE); if (proxy_protected == 0) { uiItemR(row, &ptr, "name", 0, "", ICON_NONE); @@ -1033,7 +1033,7 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con) else uiItemL(row, con->name, ICON_NONE); - uiLayoutSetRedAlert(row, 0); + uiLayoutSetRedAlert(row, FALSE); /* proxy-protected constraints cannot be edited, so hide up/down + close buttons */ if (proxy_protected) { @@ -1201,7 +1201,7 @@ void uiTemplatePreview(uiLayout *layout, ID *id, int show_buttons, ID *parent, M block = uiLayoutGetBlock(layout); row = uiLayoutRow(layout, FALSE); col = uiLayoutColumn(row, FALSE); - uiLayoutSetKeepAspect(col, 1); + uiLayoutSetKeepAspect(col, TRUE); /* add preview */ uiDefBut(block, BUT_EXTRA, 0, "", 0, 0, UI_UNIT_X * 6, UI_UNIT_Y * 6, pid, 0.0, 0.0, 0, 0, ""); @@ -1745,6 +1745,13 @@ static void curvemap_buttons_redraw(bContext *C, void *UNUSED(arg1), void *UNUSE ED_region_tag_redraw(CTX_wm_region(C)); } +static void curvemap_buttons_update(bContext *UNUSED(C), void *UNUSED(arg1), void *cumap_v) +{ + CurveMapping *cumap = cumap_v; + + curvemapping_changed(cumap, TRUE); +} + static void curvemap_buttons_reset(bContext *C, void *cb_v, void *cumap_v) { CurveMapping *cumap = cumap_v; @@ -1767,12 +1774,14 @@ static void curvemap_buttons_reset(bContext *C, void *cb_v, void *cumap_v) static void curvemap_buttons_layout(uiLayout *layout, PointerRNA *ptr, char labeltype, int levels, int brush, RNAUpdateCb *cb) { CurveMapping *cumap = ptr->data; + CurveMap *cm = &cumap->cm[cumap->cur]; + CurveMapPoint *cmp = NULL; uiLayout *row, *sub, *split; uiBlock *block; uiBut *bt; float dx = UI_UNIT_X; int icon, size; - int bg = -1; + int bg = -1, i; block = uiLayoutGetBlock(layout); @@ -1877,6 +1886,21 @@ static void curvemap_buttons_layout(uiLayout *layout, PointerRNA *ptr, char labe row = uiLayoutRow(layout, FALSE); uiDefBut(block, BUT_CURVE, 0, "", 0, 0, size, MIN2(size, 200), cumap, 0.0f, 1.0f, bg, 0, ""); + /* sliders for selected point */ + for (i = 0; i < cm->totpoint; i++) { + if (cm->curve[i].flag & CUMA_SELECT) { + cmp = &cm->curve[i]; + break; + } + } + + if (cmp) { + uiLayoutRow(layout, TRUE); + uiBlockSetNFunc(block, curvemap_buttons_update, NULL, cumap); + uiDefButF(block, NUM, 0, "X", 0, 2 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, &cmp->x, 0.0f, 1.0f, 1, 5, ""); + uiDefButF(block, NUM, 0, "Y", 0, 1 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, &cmp->y, 0.0f, 1.0f, 1, 5, ""); + } + /* black/white levels */ if (levels) { split = uiLayoutSplit(layout, 0.0f, FALSE); @@ -2182,7 +2206,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe row = uiLayoutRow(split, TRUE); if (i == 0 || (key->type != KEY_RELATIVE)) uiItemL(row, "", ICON_NONE); else uiItemR(row, itemptr, "value", 0, "", ICON_NONE); - uiItemR(row, itemptr, "mute", 0, "", 0); + uiItemR(row, itemptr, "mute", 0, "", ICON_NONE); if ((kb->flag & KEYBLOCK_MUTE) || (ob->mode == OB_MODE_EDIT && !((ob->shapeflag & OB_SHAPE_EDIT_MODE) && ob->type == OB_MESH))) @@ -2251,9 +2275,9 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe uiBlockSetEmboss(block, UI_EMBOSSN); row = uiLayoutRow(split, TRUE); uiItemR(row, itemptr, "alpha", 0, "", ICON_NONE); - uiItemR(row, itemptr, "hide", 0, "", 0); - uiItemR(row, itemptr, "hide_select", 0, "", 0); - uiItemR(row, itemptr, "hide_render", 0, "", 0); + uiItemR(row, itemptr, "hide", 0, "", ICON_NONE); + uiItemR(row, itemptr, "hide_select", 0, "", ICON_NONE); + uiItemR(row, itemptr, "hide_render", 0, "", ICON_NONE); uiBlockSetEmboss(block, UI_EMBOSS); } @@ -2298,7 +2322,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe while (id < prop_names_end) { if ((id_next = strchr(id, ':'))) *id_next++ = '\0'; else id_next = prop_names_end; - uiItemR(row, itemptr, id, 0, NULL, 0); + uiItemR(row, itemptr, id, 0, NULL, ICON_NONE); id = id_next; } MEM_freeN(prop_names); @@ -2558,6 +2582,7 @@ void uiTemplateOperatorSearch(uiLayout *layout) #define B_STOPCOMPO 4 #define B_STOPSEQ 5 #define B_STOPCLIP 6 +#define B_STOPOTHER 7 static void do_running_jobs(bContext *C, void *UNUSED(arg), int event) { @@ -2580,6 +2605,9 @@ static void do_running_jobs(bContext *C, void *UNUSED(arg), int event) case B_STOPCLIP: WM_jobs_stop(CTX_wm_manager(C), CTX_wm_area(C), NULL); break; + case B_STOPOTHER: + G.is_break = TRUE; + break; } } @@ -2619,6 +2647,10 @@ void uiTemplateRunningJobs(uiLayout *layout, bContext *C) handle_event = B_STOPCOMPO; break; } + else if (WM_jobs_test(wm, scene, WM_JOB_TYPE_ANY)) { + handle_event = B_STOPOTHER; + break; + } } owner = scene; } diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c index 8ff8e0824d6..d363609fbd9 100644 --- a/source/blender/editors/interface/interface_utils.c +++ b/source/blender/editors/interface/interface_utils.c @@ -78,7 +78,7 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind if (arraylen && index == -1) { if (ELEM(RNA_property_subtype(prop), PROP_COLOR, PROP_COLOR_GAMMA)) - but = uiDefButR_prop(block, COL, 0, name, x1, y1, x2, y2, ptr, prop, 0, 0, 0, -1, -1, NULL); + but = uiDefButR_prop(block, COLOR, 0, name, x1, y1, x2, y2, ptr, prop, 0, 0, 0, -1, -1, NULL); } else if (RNA_property_subtype(prop) == PROP_PERCENTAGE || RNA_property_subtype(prop) == PROP_FACTOR) but = uiDefButR_prop(block, NUMSLI, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); @@ -102,7 +102,8 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind else but = uiDefButR_prop(block, TEX, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); break; - case PROP_POINTER: { + case PROP_POINTER: + { PointerRNA pptr; pptr = RNA_property_pointer_get(ptr, prop); @@ -115,7 +116,8 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind but = uiDefIconTextButR_prop(block, IDPOIN, 0, icon, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); break; } - case PROP_COLLECTION: { + case PROP_COLLECTION: + { char text[256]; BLI_snprintf(text, sizeof(text), IFACE_("%d items"), RNA_property_collection_length(ptr, prop)); but = uiDefBut(block, LABEL, 0, text, x1, y1, x2, y2, NULL, 0, 0, 0, 0, NULL); diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index ef8d8302fa7..026f02d1089 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -46,7 +46,6 @@ #include "BKE_context.h" #include "BKE_curve.h" -#include "BKE_utildefines.h" #include "RNA_access.h" @@ -1256,10 +1255,12 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB if (but->type == BUT_TOGDUAL) { int dualset = 0; - if (but->pointype == SHO) - dualset = BTST(*(((short *)but->poin) + 1), but->bitnr); - else if (but->pointype == INT) - dualset = BTST(*(((int *)but->poin) + 1), but->bitnr); + if (but->pointype == UI_BUT_POIN_SHORT) { + dualset = UI_BITBUT_TEST(*(((short *)but->poin) + 1), but->bitnr); + } + else if (but->pointype == UI_BUT_POIN_INT) { + dualset = UI_BITBUT_TEST(*(((int *)but->poin) + 1), but->bitnr); + } widget_draw_icon(but, ICON_DOT, dualset ? 1.0f : 0.25f, rect); } @@ -3155,7 +3156,7 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct wt = widget_type(UI_WTYPE_MENU_ITEM); break; - case COL: + case COLOR: wt = widget_type(UI_WTYPE_SWATCH); break; diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index 3926fe291c7..1d0cd2707ac 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -950,7 +950,7 @@ void UI_SetTheme(int spacetype, int regionid) } } -bTheme *UI_GetTheme() +bTheme *UI_GetTheme(void) { return U.themes.first; } diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index c3059b8d575..0f1d1a24dcb 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -544,7 +544,7 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize) curheight = BLI_RCT_SIZE_Y(cur); /* width */ - if ( (curwidth > totwidth) && !(v2d->keepzoom & (V2D_KEEPZOOM | V2D_LOCKZOOM_X | V2D_LIMITZOOM)) ) { + if ((curwidth > totwidth) && !(v2d->keepzoom & (V2D_KEEPZOOM | V2D_LOCKZOOM_X | V2D_LIMITZOOM))) { /* if zoom doesn't have to be maintained, just clamp edges */ if (cur->xmin < tot->xmin) cur->xmin = tot->xmin; if (cur->xmax > tot->xmax) cur->xmax = tot->xmax; @@ -627,7 +627,7 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize) } /* height */ - if ( (curheight > totheight) && !(v2d->keepzoom & (V2D_KEEPZOOM | V2D_LOCKZOOM_Y | V2D_LIMITZOOM)) ) { + if ((curheight > totheight) && !(v2d->keepzoom & (V2D_KEEPZOOM | V2D_LOCKZOOM_Y | V2D_LIMITZOOM))) { /* if zoom doesn't have to be maintained, just clamp edges */ if (cur->ymin < tot->ymin) cur->ymin = tot->ymin; if (cur->ymax > tot->ymax) cur->ymax = tot->ymax; @@ -1874,7 +1874,7 @@ void UI_view2d_listview_view_to_cell(View2D *v2d, short columnwidth, short rowhe const int y = (int)(floorf(fabsf(viewy) + 0.5f) - starty); /* sizes must not be negative */ - if ( (v2d == NULL) || ((columnwidth <= 0) && (rowheight <= 0)) ) { + if ((v2d == NULL) || ((columnwidth <= 0) && (rowheight <= 0))) { if (column) *column = 0; if (row) *row = 0; diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index 5b19bb2d3c9..99313edc289 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -1719,8 +1719,8 @@ static int scroller_activate_invoke(bContext *C, wmOperator *op, wmEvent *event) * NOTE: see view2d.c for latest conditions, and keep this in sync with that */ if (ELEM(vsm->zone, SCROLLHANDLE_MIN, SCROLLHANDLE_MAX)) { - if ( ((vsm->scroller == 'h') && (v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL) == 0) || - ((vsm->scroller == 'v') && (v2d->scroll & V2D_SCROLL_SCALE_VERTICAL) == 0) ) + if (((vsm->scroller == 'h') && (v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL) == 0) || + ((vsm->scroller == 'v') && (v2d->scroll & V2D_SCROLL_SCALE_VERTICAL) == 0)) { /* switch to bar (i.e. no scaling gets handled) */ vsm->zone = SCROLLHANDLE_BAR; @@ -1729,8 +1729,8 @@ static int scroller_activate_invoke(bContext *C, wmOperator *op, wmEvent *event) /* check if zone is inappropriate (i.e. 'bar' but panning is banned), so cannot continue */ if (vsm->zone == SCROLLHANDLE_BAR) { - if ( ((vsm->scroller == 'h') && (v2d->keepofs & V2D_LOCKOFS_X)) || - ((vsm->scroller == 'v') && (v2d->keepofs & V2D_LOCKOFS_Y)) ) + if (((vsm->scroller == 'h') && (v2d->keepofs & V2D_LOCKOFS_X)) || + ((vsm->scroller == 'v') && (v2d->keepofs & V2D_LOCKOFS_Y))) { /* free customdata initialized */ scroller_activate_exit(C, op); @@ -1741,8 +1741,8 @@ static int scroller_activate_invoke(bContext *C, wmOperator *op, wmEvent *event) } /* zone is also inappropriate if scroller is not visible... */ - if ( ((vsm->scroller == 'h') && (v2d->scroll & (V2D_SCROLL_HORIZONTAL_HIDE | V2D_SCROLL_HORIZONTAL_FULLR))) || - ((vsm->scroller == 'v') && (v2d->scroll & (V2D_SCROLL_VERTICAL_HIDE | V2D_SCROLL_VERTICAL_FULLR))) ) + if (((vsm->scroller == 'h') && (v2d->scroll & (V2D_SCROLL_HORIZONTAL_HIDE | V2D_SCROLL_HORIZONTAL_FULLR))) || + ((vsm->scroller == 'v') && (v2d->scroll & (V2D_SCROLL_VERTICAL_HIDE | V2D_SCROLL_VERTICAL_FULLR))) ) { /* free customdata initialized */ scroller_activate_exit(C, op); diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c index d0ce3f0cace..0e6b8f77528 100644 --- a/source/blender/editors/io/io_collada.c +++ b/source/blender/editors/io/io_collada.c @@ -152,10 +152,10 @@ void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr) /* Export Options: */ box = uiLayoutBox(layout); - row = uiLayoutRow(box, 0); + row = uiLayoutRow(box, FALSE); uiItemL(row, IFACE_("Export Data Options:"), ICON_MESH_DATA); - row = uiLayoutRow(box, 0); + row = uiLayoutRow(box, FALSE); split = uiLayoutSplit(row, 0.6f, UI_LAYOUT_ALIGN_RIGHT); col = uiLayoutColumn(split, FALSE); uiItemR(col, imfptr, "apply_modifiers", 0, NULL, ICON_NONE); diff --git a/source/blender/editors/io/io_collada.h b/source/blender/editors/io/io_collada.h index 5cb255e1b7c..4bb1475a3b2 100644 --- a/source/blender/editors/io/io_collada.h +++ b/source/blender/editors/io/io_collada.h @@ -24,7 +24,7 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file blender/editor/io/io_collada.h +/** \file blender/editors/io/io_collada.h * \ingroup editor/io */ diff --git a/source/blender/editors/io/io_ops.h b/source/blender/editors/io/io_ops.h index 4c04b349655..4fffca4607c 100644 --- a/source/blender/editors/io/io_ops.h +++ b/source/blender/editors/io/io_ops.h @@ -24,7 +24,7 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file blender/editor/io/io_ops.h +/** \file blender/editors/io/io_ops.h * \ingroup editor/io */ diff --git a/source/blender/editors/mask/mask_add.c b/source/blender/editors/mask/mask_add.c index b37f758596b..7fe1ac09df6 100644 --- a/source/blender/editors/mask/mask_add.c +++ b/source/blender/editors/mask/mask_add.c @@ -556,6 +556,7 @@ static int add_vertex_new(const bContext *C, Mask *mask, MaskLayer *masklay, con static int add_vertex_exec(bContext *C, wmOperator *op) { + Scene *scene = CTX_data_scene(C); Mask *mask = CTX_data_edit_mask(C); MaskLayer *masklay; @@ -595,7 +596,7 @@ static int add_vertex_exec(bContext *C, wmOperator *op) BKE_mask_calc_handle_point_auto(spline, point_other, FALSE); /* TODO: only update this spline */ - BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra); + BKE_mask_update_display(mask, CFRA); WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask); return OPERATOR_FINISHED; @@ -617,7 +618,7 @@ static int add_vertex_exec(bContext *C, wmOperator *op) } /* TODO: only update this spline */ - BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra); + BKE_mask_update_display(mask, CFRA); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/mask/mask_draw.c b/source/blender/editors/mask/mask_draw.c index 00bbfcf3188..655458bd4cb 100644 --- a/source/blender/editors/mask/mask_draw.c +++ b/source/blender/editors/mask/mask_draw.c @@ -496,7 +496,8 @@ void ED_mask_draw(const bContext *C, * width, height are to match the values from ED_mask_get_size() */ void ED_mask_draw_region(Mask *mask, ARegion *ar, const char draw_flag, const char draw_type, - int width, int height, + const int width_i, const int height_i, /* convert directly into aspect corrected vars */ + const float aspx, const float aspy, const short do_scale_applied, const short do_post_draw, float stabmat[4][4], /* optional - only used by clip */ const bContext *C /* optional - only used when do_post_draw is set */ @@ -504,6 +505,9 @@ void ED_mask_draw_region(Mask *mask, ARegion *ar, { struct View2D *v2d = &ar->v2d; + /* aspect always scales vertically in movie and image spaces */ + const float width = width_i, height = (float)height_i * (aspy / aspx); + int x, y; /* int w, h; */ float zoomx, zoomy; diff --git a/source/blender/editors/mask/mask_edit.c b/source/blender/editors/mask/mask_edit.c index 85a8ae11111..39a19bdaa5f 100644 --- a/source/blender/editors/mask/mask_edit.c +++ b/source/blender/editors/mask/mask_edit.c @@ -109,11 +109,9 @@ void ED_mask_mouse_pos(ScrArea *sa, ARegion *ar, const int mval[2], float co[2]) } case SPACE_IMAGE: { - float frame_size[2]; SpaceImage *sima = sa->spacedata.first; - ED_space_image_get_size_fl(sima, frame_size); ED_image_mouse_pos(sima, ar, mval, co); - BKE_mask_coord_from_frame(co, co, frame_size); + BKE_mask_coord_from_image(sima->image, &sima->iuser, co, co); break; } default: @@ -149,11 +147,9 @@ void ED_mask_point_pos(ScrArea *sa, ARegion *ar, float x, float y, float *xr, fl break; case SPACE_IMAGE: { - float frame_size[2]; SpaceImage *sima = sa->spacedata.first; - ED_space_image_get_size_fl(sima, frame_size); ED_image_point_pos(sima, ar, x, y, &co[0], &co[1]); - BKE_mask_coord_from_frame(co, co, frame_size); + BKE_mask_coord_from_image(sima->image, &sima->iuser, co, co); break; } default: @@ -192,13 +188,10 @@ void ED_mask_point_pos__reverse(ScrArea *sa, ARegion *ar, float x, float y, floa break; case SPACE_IMAGE: { - float frame_size[2]; SpaceImage *sima = sa->spacedata.first; - ED_space_image_get_size_fl(sima, frame_size); - co[0] = x; co[1] = y; - BKE_mask_coord_to_frame(co, co, frame_size); + BKE_mask_coord_to_image(sima->image, &sima->iuser, co, co); ED_image_point_pos__reverse(sima, ar, co, co); break; } diff --git a/source/blender/editors/mask/mask_ops.c b/source/blender/editors/mask/mask_ops.c index 1df1e5a66fe..88fbb91edfb 100644 --- a/source/blender/editors/mask/mask_ops.c +++ b/source/blender/editors/mask/mask_ops.c @@ -915,6 +915,7 @@ static void delete_feather_points(MaskSplinePoint *point) static int delete_exec(bContext *C, wmOperator *UNUSED(op)) { + Scene *scene = CTX_data_scene(C); Mask *mask = CTX_data_edit_mask(C); MaskLayer *masklay; @@ -1002,7 +1003,7 @@ static int delete_exec(bContext *C, wmOperator *UNUSED(op)) } /* TODO: only update edited splines */ - BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra); + BKE_mask_update_display(mask, CFRA); WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask); @@ -1060,7 +1061,7 @@ static int mask_switch_direction_exec(bContext *C, wmOperator *UNUSED(op)) if (change) { /* TODO: only update this spline */ - BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra); + BKE_mask_update_display(mask, CFRA); WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask); @@ -1126,7 +1127,7 @@ static int mask_normals_make_consistent_exec(bContext *C, wmOperator *UNUSED(op) if (change) { /* TODO: only update this spline */ - BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra); + BKE_mask_update_display(mask, CFRA); WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask); @@ -1324,6 +1325,7 @@ void MASK_OT_hide_view_set(wmOperatorType *ot) static int mask_feather_weight_clear_exec(bContext *C, wmOperator *UNUSED(op)) { + Scene *scene = CTX_data_scene(C); Mask *mask = CTX_data_edit_mask(C); MaskLayer *masklay; int changed = FALSE; @@ -1351,7 +1353,7 @@ static int mask_feather_weight_clear_exec(bContext *C, wmOperator *UNUSED(op)) if (changed) { /* TODO: only update edited splines */ - BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra); + BKE_mask_update_display(mask, CFRA); WM_event_add_notifier(C, NC_MASK | ND_DRAW, mask); DAG_id_tag_update(&mask->id, 0); diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c index 3431bea18ea..94e10b53b29 100644 --- a/source/blender/editors/mesh/editface.c +++ b/source/blender/editors/mesh/editface.c @@ -123,43 +123,6 @@ void paintface_flush_flags(Object *ob) } } -/* returns 0 if not found, otherwise 1 */ -static int facesel_face_pick(struct bContext *C, Mesh *me, Object *ob, const int mval[2], unsigned int *index, short rect) -{ - Scene *scene = CTX_data_scene(C); - ViewContext vc; - view3d_set_viewcontext(C, &vc); - - if (!me || me->totpoly == 0) - return 0; - - makeDerivedMesh(scene, ob, NULL, CD_MASK_BAREMESH, 0); - - // XXX if (v3d->flag & V3D_INVALID_BACKBUF) { -// XXX drawview.c! check_backbuf(); -// XXX persp(PERSP_VIEW); -// XXX } - - if (rect) { - /* sample rect to increase changes of selecting, so that when clicking - * on an edge in the backbuf, we can still select a face */ - - int dist; - *index = view3d_sample_backbuf_rect(&vc, mval, 3, 1, me->totpoly + 1, &dist, 0, NULL, NULL); - } - else { - /* sample only on the exact position */ - *index = view3d_sample_backbuf(&vc, mval[0], mval[1]); - } - - if ((*index) <= 0 || (*index) > (unsigned int)me->totpoly) - return 0; - - (*index)--; - - return 1; -} - void paintface_hide(Object *ob, const int unselected) { Mesh *me; @@ -174,10 +137,10 @@ void paintface_hide(Object *ob, const int unselected) while (a--) { if ((mpoly->flag & ME_HIDE) == 0) { if (unselected) { - if ( (mpoly->flag & ME_FACE_SEL) == 0) mpoly->flag |= ME_HIDE; + if ((mpoly->flag & ME_FACE_SEL) == 0) mpoly->flag |= ME_HIDE; } else { - if ( (mpoly->flag & ME_FACE_SEL)) mpoly->flag |= ME_HIDE; + if ((mpoly->flag & ME_FACE_SEL)) mpoly->flag |= ME_HIDE; } } if (mpoly->flag & ME_HIDE) mpoly->flag &= ~ME_FACE_SEL; @@ -331,7 +294,7 @@ void paintface_select_linked(bContext *UNUSED(C), Object *ob, int UNUSED(mval[2] if (mode == 0 || mode == 1) { /* XXX - Causes glitches, not sure why */ #if 0 - if (!facesel_face_pick(C, me, mval, &index, 1)) + if (!ED_mesh_pick_face(C, me, mval, &index, ED_MESH_PICK_DEFAULT_FACE_SIZE)) return; #endif } @@ -518,7 +481,7 @@ int paintface_mouse_select(struct bContext *C, Object *ob, const int mval[2], in /* Get the face under the cursor */ me = BKE_mesh_from_object(ob); - if (!facesel_face_pick(C, me, ob, mval, &index, 1)) + if (!ED_mesh_pick_face(C, me, mval, &index, ED_MESH_PICK_DEFAULT_FACE_SIZE)) return 0; if (index >= me->totpoly) diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c index 9cbd9e0b7da..8b032bb1a3d 100644 --- a/source/blender/editors/mesh/editmesh_add.c +++ b/source/blender/editors/mesh/editmesh_add.c @@ -97,7 +97,6 @@ static void make_prim_finish(bContext *C, int *state, int enter_editmode) static int add_primitive_plane_exec(bContext *C, wmOperator *op) { Object *obedit; - Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; @@ -108,8 +107,7 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op) make_prim_init(C, "Plane", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + em = BMEdit_FromObject(obedit); if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_grid xsegments=%i ysegments=%i size=%f mat=%m4", 1, 1, dia, mat)) @@ -143,7 +141,6 @@ void MESH_OT_primitive_plane_add(wmOperatorType *ot) static int add_primitive_cube_exec(bContext *C, wmOperator *op) { Object *obedit; - Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; @@ -154,8 +151,7 @@ static int add_primitive_cube_exec(bContext *C, wmOperator *op) make_prim_init(C, "Cube", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + em = BMEdit_FromObject(obedit); if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_cube mat=%m4 size=%f", mat, dia * 2.0f)) { return OPERATOR_CANCELLED; @@ -194,7 +190,6 @@ static const EnumPropertyItem fill_type_items[] = { static int add_primitive_circle_exec(bContext *C, wmOperator *op) { Object *obedit; - Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; @@ -208,8 +203,7 @@ static int add_primitive_circle_exec(bContext *C, wmOperator *op) make_prim_init(C, "Circle", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + em = BMEdit_FromObject(obedit); if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_circle segments=%i diameter=%f cap_ends=%b cap_tris=%b mat=%m4", @@ -253,7 +247,6 @@ void MESH_OT_primitive_circle_add(wmOperatorType *ot) static int add_primitive_cylinder_exec(bContext *C, wmOperator *op) { Object *obedit; - Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; @@ -267,8 +260,7 @@ static int add_primitive_cylinder_exec(bContext *C, wmOperator *op) make_prim_init(C, "Cylinder", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + em = BMEdit_FromObject(obedit); if (!EDBM_op_call_and_selectf( em, op, "vertout", @@ -318,7 +310,6 @@ void MESH_OT_primitive_cylinder_add(wmOperatorType *ot) static int add_primitive_cone_exec(bContext *C, wmOperator *op) { Object *obedit; - Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; @@ -332,8 +323,7 @@ static int add_primitive_cone_exec(bContext *C, wmOperator *op) make_prim_init(C, "Cone", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + em = BMEdit_FromObject(obedit); if (!EDBM_op_call_and_selectf( em, op, "vertout", @@ -382,7 +372,6 @@ void MESH_OT_primitive_cone_add(wmOperatorType *ot) static int add_primitive_grid_exec(bContext *C, wmOperator *op) { Object *obedit; - Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; @@ -393,8 +382,7 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op) make_prim_init(C, "Grid", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + em = BMEdit_FromObject(obedit); if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_grid xsegments=%i ysegments=%i size=%f mat=%m4", @@ -438,7 +426,6 @@ void MESH_OT_primitive_grid_add(wmOperatorType *ot) static int add_primitive_monkey_exec(bContext *C, wmOperator *op) { Object *obedit; - Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; @@ -452,8 +439,7 @@ static int add_primitive_monkey_exec(bContext *C, wmOperator *op) make_prim_init(C, "Monkey", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + em = BMEdit_FromObject(obedit); if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_monkey mat=%m4", mat)) { return OPERATOR_CANCELLED; @@ -484,7 +470,6 @@ void MESH_OT_primitive_monkey_add(wmOperatorType *ot) static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op) { Object *obedit; - Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; @@ -495,8 +480,7 @@ static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op) make_prim_init(C, "Sphere", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + em = BMEdit_FromObject(obedit); if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_uvsphere segments=%i revolutions=%i diameter=%f mat=%m4", @@ -540,7 +524,6 @@ void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot) static int add_primitive_icosphere_exec(bContext *C, wmOperator *op) { Object *obedit; - Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; @@ -551,8 +534,7 @@ static int add_primitive_icosphere_exec(bContext *C, wmOperator *op) make_prim_init(C, "Icosphere", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + em = BMEdit_FromObject(obedit); if (!EDBM_op_call_and_selectf( em, op, "vertout", diff --git a/source/blender/editors/mesh/editmesh_bvh.c b/source/blender/editors/mesh/editmesh_bvh.c index 549032f7286..0b7d396b696 100644 --- a/source/blender/editors/mesh/editmesh_bvh.c +++ b/source/blender/editors/mesh/editmesh_bvh.c @@ -49,6 +49,7 @@ #include "ED_mesh.h" #include "ED_view3d.h" +#include "editmesh_bvh.h" /* own include */ typedef struct BMBVHTree { BMEditMesh *em; @@ -394,15 +395,10 @@ int BMBVH_EdgeVisible(BMBVHTree *tree, BMEdge *e, ARegion *ar, View3D *v3d, Obje float co1[3], co2[3], co3[3], dir1[4], dir2[4], dir3[4]; float origin[3], invmat[4][4]; float epsilon = 0.01f; - float mval_f[2], end[3]; - - if (!ar) { - printf("error in BMBVH_EdgeVisible!\n"); - return 0; - } - - mval_f[0] = ar->winx / 2.0f; - mval_f[1] = ar->winy / 2.0f; + float end[3]; + const float mval_f[2] = {ar->winx / 2.0f, + ar->winy / 2.0f}; + ED_view3d_win_to_segment_clip(ar, v3d, mval_f, origin, end); invert_m4_m4(invmat, obedit->obmat); diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index 229bbdbefb7..7ecfb712c18 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -160,7 +160,7 @@ typedef struct KnifeTool_OpData { int totlinehit; /* Data for mouse-position-derived data (cur) and previous click (prev) */ - KnifePosData cur, prev; + KnifePosData curr, prev; int totkedge, totkvert; @@ -290,7 +290,7 @@ static void knife_add_edge_faces_to_vert(KnifeTool_OpData *kcd, KnifeVert *kfv, } /* Find a face in common in the two faces lists. - If more than one, return the first; if none, return NULL */ + * If more than one, return the first; if none, return NULL */ static BMFace *knife_find_common_face(ListBase *faces1, ListBase *faces2) { Ref *ref1, *ref2; @@ -368,22 +368,22 @@ static KnifeEdge *get_bm_knife_edge(KnifeTool_OpData *kcd, BMEdge *e) * Copy the current position data into prev. */ static void knife_start_cut(KnifeTool_OpData *kcd) { - kcd->prev = kcd->cur; - kcd->cur.is_space = 0; /*TODO: why do we do this? */ + kcd->prev = kcd->curr; + kcd->curr.is_space = 0; /*TODO: why do we do this? */ if (kcd->prev.vert == NULL && kcd->prev.edge == NULL && is_zero_v3(kcd->prev.cage)) { /* Make prevcage a point on the view ray to mouse closest to a point on model: choose vertex 0 */ float origin[3], ray[3], co[3]; BMVert *v0; - knife_input_ray_cast(kcd, kcd->cur.mval, origin, ray); + knife_input_ray_cast(kcd, kcd->curr.mval, origin, ray); add_v3_v3v3(co, origin, ray); v0 = BM_vert_at_index(kcd->em->bm, 0); if (v0) { closest_to_line_v3(kcd->prev.cage, v0->co, co, origin); copy_v3_v3(kcd->prev.co, kcd->prev.cage); /*TODO: do we need this? */ - copy_v3_v3(kcd->cur.cage, kcd->prev.cage); - copy_v3_v3(kcd->cur.co, kcd->prev.co); + copy_v3_v3(kcd->curr.cage, kcd->prev.cage); + copy_v3_v3(kcd->curr.co, kcd->prev.co); } } } @@ -471,15 +471,15 @@ static KnifeVert *knife_split_edge(KnifeTool_OpData *kcd, KnifeEdge *kfe, float return newkfe->v2; } -/* Make a single KnifeEdge for cut from kcd->prev to kcd->cur. +/* Make a single KnifeEdge for cut from kcd->prev to kcd->curr. * and move cur data to prev. */ static void knife_add_single_cut(KnifeTool_OpData *kcd) { KnifeEdge *kfe = new_knife_edge(kcd), *kfe2 = NULL, *kfe3 = NULL; - if (kcd->prev.vert && kcd->prev.vert == kcd->cur.vert) + if (kcd->prev.vert && kcd->prev.vert == kcd->curr.vert) return; - if (kcd->prev.edge && kcd->prev.edge == kcd->cur.edge) + if (kcd->prev.edge && kcd->prev.edge == kcd->curr.edge) return; kfe->draw = 1; @@ -500,25 +500,25 @@ static void knife_add_single_cut(KnifeTool_OpData *kcd) knife_append_list(kcd, &kfe->v1->faces, kcd->prev.bmface); } - if (kcd->cur.vert) { - kfe->v2 = kcd->cur.vert; + if (kcd->curr.vert) { + kfe->v2 = kcd->curr.vert; } - else if (kcd->cur.edge) { - kfe->v2 = knife_split_edge(kcd, kcd->cur.edge, kcd->cur.co, &kfe3); - kcd->cur.vert = kfe->v2; + else if (kcd->curr.edge) { + kfe->v2 = knife_split_edge(kcd, kcd->curr.edge, kcd->curr.co, &kfe3); + kcd->curr.vert = kfe->v2; } else { - kfe->v2 = new_knife_vert(kcd, kcd->cur.co, kcd->cur.co); - kfe->v2->draw = !kcd->cur.is_space; + kfe->v2 = new_knife_vert(kcd, kcd->curr.co, kcd->curr.co); + kfe->v2->draw = !kcd->curr.is_space; kfe->v2->isface = 1; - kfe->v2->inspace = kcd->cur.is_space; - if (kfe->v2->draw && kcd->cur.bmface) - knife_append_list(kcd, &kfe->v2->faces, kcd->cur.bmface); + kfe->v2->inspace = kcd->curr.is_space; + if (kfe->v2->draw && kcd->curr.bmface) + knife_append_list(kcd, &kfe->v2->faces, kcd->curr.bmface); - if (kcd->cur.is_space) + if (kcd->curr.is_space) kfe->draw = 0; - kcd->cur.vert = kfe->v2; + kcd->curr.vert = kfe->v2; } knife_find_basef(kfe); @@ -529,12 +529,12 @@ static void knife_add_single_cut(KnifeTool_OpData *kcd) knife_edge_append_face(kcd, kfe, kfe->basef); /* sanity check to make sure we're in the right edge/face lists */ - if (kcd->cur.bmface) { - if (!find_ref(&kfe->faces, kcd->cur.bmface)) { - knife_edge_append_face(kcd, kfe, kcd->cur.bmface); + if (kcd->curr.bmface) { + if (!find_ref(&kfe->faces, kcd->curr.bmface)) { + knife_edge_append_face(kcd, kfe, kcd->curr.bmface); } - if (kcd->prev.bmface && kcd->prev.bmface != kcd->cur.bmface) { + if (kcd->prev.bmface && kcd->prev.bmface != kcd->curr.bmface) { if (!find_ref(&kfe->faces, kcd->prev.bmface)) { knife_edge_append_face(kcd, kfe, kcd->prev.bmface); } @@ -542,7 +542,7 @@ static void knife_add_single_cut(KnifeTool_OpData *kcd) } /* set up for next cut */ - kcd->prev = kcd->cur; + kcd->prev = kcd->curr; } static int verge_linehit(const void *vlh1, const void *vlh2) @@ -554,6 +554,65 @@ static int verge_linehit(const void *vlh1, const void *vlh2) else return 0; } +/* If there's a linehit connected (same face) as testi in range [firsti, lasti], return the first such, else -1. + * If testi is out of range, look for connection to f instead, if f is non-NULL */ +static int find_connected_linehit(KnifeTool_OpData *kcd, int testi, BMFace *f, int firsti, int lasti) +{ + int i; + + for (i = firsti; i <= lasti; i++) { + if (testi >= 0 && testi < kcd->totlinehit) { + if (knife_find_common_face(&kcd->linehits[testi].kfe->faces, + &kcd->linehits[i].kfe->faces)) + return i; + } + else if (f) { + if (find_ref(&kcd->linehits[i].kfe->faces, f)) + return i; + } + } + return -1; +} + +/* Sort in order of distance along cut line, but take care when distances are equal */ +static void knife_sort_linehits(KnifeTool_OpData *kcd) +{ + int i, j, k, nexti, nsame; + + qsort(kcd->linehits, kcd->totlinehit, sizeof(BMEdgeHit), verge_linehit); + + /* for ranges of equal "l", swap if neccesary to make predecessor and + * successor faces connected to the linehits at either end of the range */ + for (i = 0; i < kcd->totlinehit - 1; i = nexti) { + for (j = i + 1; j < kcd->totlinehit; j++) { + if (fabsf(kcd->linehits[j].l - kcd->linehits[i].l) > 80 * FLT_EPSILON) + break; + } + nexti = j; + j--; + nsame = j - i; + if (nsame > 0) { + /* find something connected to predecessor of equal range */ + k = find_connected_linehit(kcd, i - 1, kcd->prev.bmface, i, j); + if (k != -1) { + if (k != i) { + SWAP(BMEdgeHit, kcd->linehits[i], kcd->linehits[k]); + } + i++; + nsame--; + } + if (nsame > 0) { + /* find something connected to successor of equal range */ + k = find_connected_linehit(kcd, j + 1, kcd->curr.bmface, i, j); + if (k != -1 && k != j) { + SWAP(BMEdgeHit, kcd->linehits[j], kcd->linehits[k]); + } + } + /* rest of same range doesn't matter because we won't connect them */ + } + } +} + static void knife_add_single_cut_through(KnifeTool_OpData *kcd, KnifeVert *v1, KnifeVert *v2, BMFace *f) { KnifeEdge *kfenew; @@ -618,29 +677,30 @@ static void knife_cut_through(KnifeTool_OpData *kcd) return; } + /* TODO: probably don't need to sort at all */ qsort(kcd->linehits, kcd->totlinehit, sizeof(BMEdgeHit), verge_linehit); splitkfe = MEM_callocN(kcd->totlinehit * sizeof(KnifeEdge *), "knife_cut_through"); if (kcd->prev.vert) { - if (kcd->prev.vert == kcd->cur.vert) + if (kcd->prev.vert == kcd->curr.vert) return; firstv = kcd->prev.vert; knife_get_vert_faces(kcd, firstv, kcd->prev.bmface, &firstfaces); } else if (kcd->prev.edge) { - if (kcd->prev.edge == kcd->cur.edge) + if (kcd->prev.edge == kcd->curr.edge) return; firstv = knife_split_edge(kcd, kcd->prev.edge, kcd->prev.co, &kfe3); knife_get_edge_faces(kcd, kcd->prev.edge, &firstfaces); } - if (kcd->cur.vert) { - lastv = kcd->cur.vert; - knife_get_vert_faces(kcd, lastv, kcd->cur.bmface, &lastfaces); + if (kcd->curr.vert) { + lastv = kcd->curr.vert; + knife_get_vert_faces(kcd, lastv, kcd->curr.bmface, &lastfaces); } - else if (kcd->cur.edge) { - lastv = knife_split_edge(kcd, kcd->cur.edge, kcd->cur.co, &kfe3); - knife_get_edge_faces(kcd, kcd->cur.edge, &lastfaces); + else if (kcd->curr.edge) { + lastv = knife_split_edge(kcd, kcd->curr.edge, kcd->curr.co, &kfe3); + knife_get_edge_faces(kcd, kcd->curr.edge, &lastfaces); } if (firstv) { @@ -709,15 +769,15 @@ static void knife_cut_through(KnifeTool_OpData *kcd) kcd->totlinehit = 0; /* set up for next cut */ - kcd->prev = kcd->cur; + kcd->prev = kcd->curr; } /* User has just left-clicked after the first time. - * Add all knife cuts implied by line from prev to cur. + * Add all knife cuts implied by line from prev to curr. * If that line crossed edges then kcd->linehits will be non-NULL. */ static void knife_add_cut(KnifeTool_OpData *kcd) { - KnifePosData savcur = kcd->cur; + KnifePosData savcur = kcd->curr; if (kcd->cut_through) { knife_cut_through(kcd); @@ -726,8 +786,7 @@ static void knife_add_cut(KnifeTool_OpData *kcd) BMEdgeHit *lh, *lastlh, *firstlh; int i; - /* TODO: not a stable sort! need to figure out what to do for equal lambdas */ - qsort(kcd->linehits, kcd->totlinehit, sizeof(BMEdgeHit), verge_linehit); + knife_sort_linehits(kcd); lh = kcd->linehits; lastlh = firstlh = NULL; @@ -755,7 +814,11 @@ static void knife_add_cut(KnifeTool_OpData *kcd) if (len_v3v3(kcd->prev.cage, lh->realhit) < FLT_EPSILON * 80) continue; - if (len_v3v3(kcd->cur.cage, lh->realhit) < FLT_EPSILON * 80) + if (len_v3v3(kcd->curr.cage, lh->realhit) < FLT_EPSILON * 80) + continue; + + /* first linehit may be down face parallel to view */ + if (!lastlh && fabsf(lh->l) < FLT_EPSILON * 80) continue; if (kcd->prev.is_space) { @@ -768,12 +831,18 @@ static void knife_add_cut(KnifeTool_OpData *kcd) continue; } - kcd->cur.is_space = 0; - kcd->cur.edge = lh->kfe; - kcd->cur.bmface = lh->f; - kcd->cur.vert = lh->v; - copy_v3_v3(kcd->cur.co, lh->hit); - copy_v3_v3(kcd->cur.cage, lh->cagehit); + kcd->curr.is_space = 0; + kcd->curr.edge = lh->kfe; + kcd->curr.bmface = lh->f; + kcd->curr.vert = lh->v; + copy_v3_v3(kcd->curr.co, lh->hit); + copy_v3_v3(kcd->curr.cage, lh->cagehit); + + /* don't draw edges down faces parallel to view */ + if (lastlh && fabsf(lastlh->l - lh->l) < FLT_EPSILON * 80) { + kcd->prev = kcd->curr; + continue; + } knife_add_single_cut(kcd); } @@ -782,7 +851,7 @@ static void knife_add_cut(KnifeTool_OpData *kcd) kcd->prev = savcur; } else { - kcd->cur = savcur; + kcd->curr = savcur; knife_add_single_cut(kcd); } @@ -935,38 +1004,38 @@ static void knifetool_draw(const bContext *C, ARegion *UNUSED(ar), void *arg) glBegin(GL_LINES); glVertex3fv(kcd->prev.cage); - glVertex3fv(kcd->cur.cage); + glVertex3fv(kcd->curr.cage); glEnd(); glLineWidth(1.0); } - if (kcd->cur.edge) { + if (kcd->curr.edge) { glColor3ubv(kcd->colors.edge); glLineWidth(2.0); glBegin(GL_LINES); - glVertex3fv(kcd->cur.edge->v1->cageco); - glVertex3fv(kcd->cur.edge->v2->cageco); + glVertex3fv(kcd->curr.edge->v1->cageco); + glVertex3fv(kcd->curr.edge->v2->cageco); glEnd(); glLineWidth(1.0); } - else if (kcd->cur.vert) { + else if (kcd->curr.vert) { glColor3ubv(kcd->colors.point); glPointSize(11); glBegin(GL_POINTS); - glVertex3fv(kcd->cur.cage); + glVertex3fv(kcd->curr.cage); glEnd(); } - if (kcd->cur.bmface) { + if (kcd->curr.bmface) { glColor3ubv(kcd->colors.curpoint); glPointSize(9); glBegin(GL_POINTS); - glVertex3fv(kcd->cur.cage); + glVertex3fv(kcd->curr.cage); glEnd(); } @@ -1113,7 +1182,7 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, KnifeEdge *kfe = ref->ref; if (BLI_smallhash_haskey(ehash, (intptr_t)kfe)) { - continue; // We already found a hit on this knife edge + continue; /* We already found a hit on this knife edge */ } if (isect_line_tri_v3(kfe->v1->cageco, kfe->v2->cageco, v1, v2, v3, &lambda, NULL)) { @@ -1121,13 +1190,17 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, interp_v3_v3v3(p, kfe->v1->cageco, kfe->v2->cageco, lambda); - if (kcd->cur.vert && len_squared_v3v3(kcd->cur.vert->cageco, p) < depsilon_squared) + if (kcd->curr.vert && len_squared_v3v3(kcd->curr.vert->cageco, p) < depsilon_squared) { continue; - if (kcd->prev.vert && len_squared_v3v3(kcd->prev.vert->cageco, p) < depsilon_squared) + } + if (kcd->prev.vert && len_squared_v3v3(kcd->prev.vert->cageco, p) < depsilon_squared) { continue; + } if (len_squared_v3v3(kcd->prev.cage, p) < depsilon_squared || - len_squared_v3v3(kcd->cur.cage, p) < depsilon_squared) + len_squared_v3v3(kcd->curr.cage, p) < depsilon_squared) + { continue; + } knife_project_v3(kcd, p, sp); view3d_unproject(mats, view, sp[0], sp[1], 0.0f); @@ -1135,15 +1208,17 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, if (kcd->cut_through) { hitf = FALSE; - } else { + } + else { /* check if this point is visible in the viewport */ float p1[3], lambda1; /* if face isn't planer, p may be behind the current tesselated tri, - so move it onto that and then a little towards eye */ + * so move it onto that and then a little towards eye */ if (isect_line_tri_v3(p, view, ls[0]->v->co, ls[1]->v->co, ls[2]->v->co, &lambda1, NULL)) { interp_v3_v3v3(p1, p, view, lambda1); - } else { + } + else { copy_v3_v3(p1, p); } sub_v3_v3(view, p1); @@ -1163,9 +1238,11 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, if (!hitf && !BLI_smallhash_haskey(ehash, (intptr_t)kfe)) { BMEdgeHit hit; - if (len_squared_v3v3(p, kcd->cur.co) < depsilon_squared || + if (len_squared_v3v3(p, kcd->curr.co) < depsilon_squared || len_squared_v3v3(p, kcd->prev.co) < depsilon_squared) + { continue; + } hit.kfe = kfe; hit.v = NULL; @@ -1185,15 +1262,18 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, /* select the closest from the edge endpoints or the midpoint */ if (perc < 0.25f) { perc = 0.0f; - } else if (perc < 0.75f) { + } + else if (perc < 0.75f) { perc = 0.5f; - } else { + } + else { perc = 1.0f; } interp_v3_v3v3(hit.hit, kfe->v1->co, kfe->v2->co, perc); interp_v3_v3v3(hit.cagehit, kfe->v1->cageco, kfe->v2->cageco, perc); - } else { + } + else { copy_v3_v3(hit.hit, p); } knife_project_v3(kcd, hit.cagehit, hit.schit); @@ -1239,7 +1319,7 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd) } copy_v3_v3(v1, kcd->prev.cage); - copy_v3_v3(v2, kcd->cur.cage); + copy_v3_v3(v2, kcd->curr.cage); /* project screen line's 3d coordinates back into 2d */ knife_project_v3(kcd, v1, s1); @@ -1435,7 +1515,7 @@ static KnifeEdge *knife_find_closest_edge(KnifeTool_OpData *kcd, float p[3], flo copy_v3_v3(p, co); copy_v3_v3(cagep, cageco); - kcd->cur.bmface = f; + kcd->curr.bmface = f; if (f) { KnifeEdge *cure = NULL; @@ -1499,8 +1579,8 @@ static KnifeEdge *knife_find_closest_edge(KnifeTool_OpData *kcd, float p[3], flo /* update mouse coordinates to the snapped-to edge's screen coordinates * this is important for angle snap, which uses the previous mouse position */ edgesnap = new_knife_vert(kcd, p, cagep); - kcd->cur.mval[0] = (int)edgesnap->sco[0]; - kcd->cur.mval[1] = (int)edgesnap->sco[1]; + kcd->curr.mval[0] = (int)edgesnap->sco[0]; + kcd->curr.mval[1] = (int)edgesnap->sco[1]; } else { @@ -1532,7 +1612,7 @@ static KnifeVert *knife_find_closest_vert(KnifeTool_OpData *kcd, float p[3], flo /* set p to co, in case we don't find anything, means a face cut */ copy_v3_v3(p, co); copy_v3_v3(cagep, p); - kcd->cur.bmface = f; + kcd->curr.bmface = f; if (f) { ListBase *lst; @@ -1583,8 +1663,8 @@ static KnifeVert *knife_find_closest_vert(KnifeTool_OpData *kcd, float p[3], flo /* update mouse coordinates to the snapped-to vertex's screen coordinates * this is important for angle snap, which uses the previous mouse position */ - kcd->cur.mval[0] = (int)curv->sco[0]; - kcd->cur.mval[1] = (int)curv->sco[1]; + kcd->curr.mval[0] = (int)curv->sco[0]; + kcd->curr.mval[1] = (int)curv->sco[1]; } return curv; @@ -1641,30 +1721,30 @@ static int knife_update_active(KnifeTool_OpData *kcd) if (kcd->angle_snapping != ANGLE_FREE && kcd->mode == MODE_DRAGGING) knife_snap_angle(kcd); - knife_pos_data_clear(&kcd->cur); - kcd->cur.mval[0] = kcd->vc.mval[0]; - kcd->cur.mval[1] = kcd->vc.mval[1]; + knife_pos_data_clear(&kcd->curr); + kcd->curr.mval[0] = kcd->vc.mval[0]; + kcd->curr.mval[1] = kcd->vc.mval[1]; /* XXX knife_snap_angle updates the view coordinate mouse values to constrained angles, * which current mouse values are set to current mouse values are then used * for vertex and edge snap detection, without regard to the exact angle constraint */ - kcd->cur.vert = knife_find_closest_vert(kcd, kcd->cur.co, kcd->cur.cage, &kcd->cur.bmface, &kcd->cur.is_space); + kcd->curr.vert = knife_find_closest_vert(kcd, kcd->curr.co, kcd->curr.cage, &kcd->curr.bmface, &kcd->curr.is_space); - if (!kcd->cur.vert) { - kcd->cur.edge = knife_find_closest_edge(kcd, kcd->cur.co, kcd->cur.cage, &kcd->cur.bmface, &kcd->cur.is_space); + if (!kcd->curr.vert) { + kcd->curr.edge = knife_find_closest_edge(kcd, kcd->curr.co, kcd->curr.cage, &kcd->curr.bmface, &kcd->curr.is_space); } /* if no hits are found this would normally default to (0, 0, 0) so instead * get a point at the mouse ray closest to the previous point. * Note that drawing lines in `free-space` isn't properly supported * but theres no guarantee (0, 0, 0) has any geometry either - campbell */ - if (kcd->cur.vert == NULL && kcd->cur.edge == NULL) { + if (kcd->curr.vert == NULL && kcd->curr.edge == NULL) { float origin[3], ray[3], co[3]; knife_input_ray_cast(kcd, kcd->vc.mval, origin, ray); add_v3_v3v3(co, origin, ray); - closest_to_line_v3(kcd->cur.cage, kcd->prev.cage, co, origin); + closest_to_line_v3(kcd->curr.cage, kcd->prev.cage, co, origin); } if (kcd->mode == MODE_DRAGGING) { @@ -2872,7 +2952,7 @@ static int knifetool_init(bContext *C, wmOperator *op, int UNUSED(do_cut)) /* can't usefully select resulting edges in face mode */ kcd->select_result = (kcd->em->selectmode != SCE_SELECT_FACE); - knife_pos_data_clear(&kcd->cur); + knife_pos_data_clear(&kcd->curr); knife_pos_data_clear(&kcd->prev); knife_init_colors(&kcd->colors); diff --git a/source/blender/editors/mesh/editmesh_rip.c b/source/blender/editors/mesh/editmesh_rip.c index 8325e0a50d4..4d4a890300f 100644 --- a/source/blender/editors/mesh/editmesh_rip.c +++ b/source/blender/editors/mesh/editmesh_rip.c @@ -380,6 +380,7 @@ static int edbm_rip_invoke__vert(bContext *C, wmOperator *op, wmEvent *event) float projectMat[4][4], fmval[3] = {event->mval[0], event->mval[1]}; float dist = FLT_MAX; float d; + int is_wire; BMEditSelection ese; int totboundary_edge = 0; @@ -403,6 +404,8 @@ static int edbm_rip_invoke__vert(bContext *C, wmOperator *op, wmEvent *event) if (!v) return OPERATOR_CANCELLED; + is_wire = BM_vert_is_wire(v); + e2 = NULL; if (v->e) { @@ -430,8 +433,11 @@ static int edbm_rip_invoke__vert(bContext *C, wmOperator *op, wmEvent *event) * - we cant find an edge - this means we are ripping a faces vert that is connected to other * geometry only at the vertex. * - the boundary edge total is greater then 2, - * in this case edge split _can_ work but we get far nicer results if we use this special case. */ - if (totboundary_edge > 2) { + * in this case edge split _can_ work but we get far nicer results if we use this special case. + * - there are only 2 edges but we are a wire vert. */ + if ((is_wire == FALSE && totboundary_edge > 2) || + (is_wire == TRUE && totboundary_edge > 1)) + { BMVert **vout; int vout_len; @@ -458,21 +464,44 @@ static int edbm_rip_invoke__vert(bContext *C, wmOperator *op, wmEvent *event) dist = FLT_MAX; + /* in the loop below we find the best vertex to drag based on its connected geometry, + * either by its face corner, or connected edge (when no faces are attached) */ for (i = 0; i < vout_len; i++) { - BM_ITER_ELEM (l, &iter, vout[i], BM_LOOPS_OF_VERT) { - if (!BM_elem_flag_test(l->f, BM_ELEM_HIDDEN)) { - float l_mid_co[3]; - BM_loop_calc_face_tangent(l, l_mid_co); - /* scale to average of surrounding edge size, only needs to be approx */ - mul_v3_fl(l_mid_co, (BM_edge_calc_length(l->e) + BM_edge_calc_length(l->prev->e)) / 2.0f); - add_v3_v3(l_mid_co, v->co); + if (BM_vert_is_wire(vout[i]) == FALSE) { + /* find the best face corner */ + BM_ITER_ELEM (l, &iter, vout[i], BM_LOOPS_OF_VERT) { + if (!BM_elem_flag_test(l->f, BM_ELEM_HIDDEN)) { + float l_mid_co[3]; + BM_loop_calc_face_tangent(l, l_mid_co); + + /* scale to average of surrounding edge size, only needs to be approx, but should + * be roughly equivalent to the check below which uses the middle of the edge. */ + mul_v3_fl(l_mid_co, (BM_edge_calc_length(l->e) + BM_edge_calc_length(l->prev->e)) / 2.0f); + add_v3_v3(l_mid_co, v->co); - d = edbm_rip_rip_edgedist(ar, projectMat, v->co, l_mid_co, fmval); + d = edbm_rip_rip_edgedist(ar, projectMat, v->co, l_mid_co, fmval); - if (d < dist) { - dist = d; - vi_best = i; + if (d < dist) { + dist = d; + vi_best = i; + } + } + } + } + else { + /* a wire vert, find the best edge */ + BM_ITER_ELEM (e, &iter, vout[i], BM_EDGES_OF_VERT) { + if (!BM_elem_flag_test(e, BM_ELEM_HIDDEN)) { + float e_mid_co[3]; + mid_v3_v3v3(e_mid_co, e->v1->co, e->v2->co); + + d = edbm_rip_rip_edgedist(ar, projectMat, v->co, e_mid_co, fmval); + + if (d < dist) { + dist = d; + vi_best = i; + } } } } diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index c50726ca9c2..de9b3c5ba05 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -268,11 +268,14 @@ int EDBM_backbuf_border_mask_init(ViewContext *vc, int mcords[][2], short tot, s /* grab mask */ bufmask = view3d_read_backbuf(vc, xmin, ymin, xmax, ymax); - drm = bufmask->rect; + if (bufmask == NULL) { return 0; /* only when mem alloc fails, go crash somewhere else! */ } - + else { + drm = bufmask->rect; + } + /* build selection lookup */ selbuf = MEM_callocN(bm_vertoffs + 1, "selbuf"); @@ -1504,7 +1507,7 @@ void MESH_OT_select_shortest_path(wmOperatorType *ot) /* ************************************************** */ /* here actual select happens */ /* gets called via generic mouse select operator */ -int mouse_mesh(bContext *C, const int mval[2], short extend, short deselect, short toggle) +int EDBM_select_pick(bContext *C, const int mval[2], short extend, short deselect, short toggle) { ViewContext vc; BMVert *eve = NULL; @@ -2231,7 +2234,7 @@ static void deselect_nth_active(BMEditMesh *em, BMVert **r_eve, BMEdge **r_eed, } } else if (em->selectmode & SCE_SELECT_FACE) { - f = BM_active_face_get(em->bm, TRUE); + f = BM_active_face_get(em->bm, TRUE, FALSE); if (f) { *r_efa = f; return; @@ -2306,8 +2309,7 @@ void em_setup_viewcontext(bContext *C, ViewContext *vc) view3d_set_viewcontext(C, vc); if (vc->obedit) { - Mesh *me = vc->obedit->data; - vc->em = me->edit_btmesh; + vc->em = BMEdit_FromObject(vc->obedit); } } @@ -2332,25 +2334,19 @@ static int edbm_select_sharp_edges_exec(bContext *C, wmOperator *op) BMIter iter; BMEdge *e; BMLoop *l1, *l2; - float sharp = RNA_float_get(op->ptr, "sharpness"), angle; + const float sharp = RNA_float_get(op->ptr, "sharpness"); BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { - if (BM_elem_flag_test(e, BM_ELEM_HIDDEN) || !e->l) - continue; - - l1 = e->l; - l2 = l1->radial_next; - - if (l1 == l2) - continue; - - /* edge has exactly two neighboring faces, check angle */ - angle = angle_normalized_v3v3(l1->f->no, l2->f->no); + if (BM_elem_flag_test(e, BM_ELEM_HIDDEN) == FALSE && + BM_edge_loop_pair(e, &l1, &l2)) + { + /* edge has exactly two neighboring faces, check angle */ + const float angle = angle_normalized_v3v3(l1->f->no, l2->f->no); - if (fabsf(angle) < sharp) { - BM_edge_select_set(em->bm, e, TRUE); + if (fabsf(angle) > sharp) { + BM_edge_select_set(em->bm, e, TRUE); + } } - } WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); @@ -2377,7 +2373,7 @@ void MESH_OT_edges_select_sharp(wmOperatorType *ot) /* props */ prop = RNA_def_float_rotation(ot->srna, "sharpness", 0, NULL, DEG2RADF(0.01f), DEG2RADF(180.0f), "Sharpness", "", DEG2RADF(1.0f), DEG2RADF(180.0f)); - RNA_def_property_float_default(prop, DEG2RADF(1.0f)); + RNA_def_property_float_default(prop, DEG2RADF(30.0f)); } static int edbm_select_linked_flat_faces_exec(bContext *C, wmOperator *op) diff --git a/source/blender/editors/mesh/editmesh_slide.c b/source/blender/editors/mesh/editmesh_slide.c index f08c229d38a..86ea5bc8651 100644 --- a/source/blender/editors/mesh/editmesh_slide.c +++ b/source/blender/editors/mesh/editmesh_slide.c @@ -27,6 +27,7 @@ /* Takes heavily from editmesh_loopcut.c */ #include "DNA_object_types.h" +#include "DNA_mesh_types.h" #include "MEM_guardedalloc.h" @@ -99,7 +100,7 @@ typedef struct VertexSlideOp { } VertexSlideOp; static void vtx_slide_draw(const bContext *C, ARegion *ar, void *arg); -static int edbm_vertex_slide_exec(bContext *C, wmOperator *op); +static int edbm_vertex_slide_exec_ex(bContext *C, wmOperator *op, const int do_update); static void vtx_slide_exit(const bContext *C, wmOperator *op); static int vtx_slide_set_frame(VertexSlideOp *vso); @@ -195,16 +196,38 @@ static void vtx_slide_confirm(bContext *C, wmOperator *op) VertexSlideOp *vso = op->customdata; BMEditMesh *em = BMEdit_FromObject(vso->obj); BMesh *bm = em->bm; + BMVert *other = NULL; + + BMVert *mirr_vtx = NULL; + BMVert *mirr_vtx_other = NULL; /* Select new edge */ BM_edge_select_set(bm, vso->sel_edge, TRUE); - /* Invoke operator */ - edbm_vertex_slide_exec(C, op); + if (vso->snap_n_merge) { + other = BM_edge_other_vert(vso->sel_edge, vso->start_vtx); + } + + if (((Mesh *)em->ob->data)->editflag & ME_EDIT_MIRROR_X) { + EDBM_verts_mirror_cache_begin(em, TRUE); + + mirr_vtx = EDBM_verts_mirror_get(em, vso->start_vtx); + if (vso->snap_n_merge) { + mirr_vtx_other = EDBM_verts_mirror_get(em, other); + } + } + + /* Invoke operator - warning */ + edbm_vertex_slide_exec_ex(C, op, FALSE); + + if (mirr_vtx) { + mirr_vtx->co[0] = -vso->start_vtx->co[0]; + mirr_vtx->co[1] = vso->start_vtx->co[1]; + mirr_vtx->co[2] = vso->start_vtx->co[2]; + } if (vso->snap_n_merge) { float other_d; - BMVert *other = BM_edge_other_vert(vso->sel_edge, vso->start_vtx); other_d = len_v3v3(vso->interp, other->co); /* Only snap if within threshold */ @@ -213,6 +236,13 @@ static void vtx_slide_confirm(bContext *C, wmOperator *op) BM_vert_select_set(bm, vso->start_vtx, TRUE); EDBM_op_callf(em, op, "pointmerge verts=%hv merge_co=%v", BM_ELEM_SELECT, other->co); EDBM_flag_disable_all(em, BM_ELEM_SELECT); + + if (mirr_vtx_other) { + BM_vert_select_set(bm, mirr_vtx, TRUE); + BM_vert_select_set(bm, mirr_vtx_other, TRUE); + EDBM_op_callf(em, op, "pointmerge verts=%hv merge_co=%v", BM_ELEM_SELECT, mirr_vtx_other->co); + EDBM_flag_disable_all(em, BM_ELEM_SELECT); + } } else { /* Store in historty if not merging */ @@ -225,6 +255,10 @@ static void vtx_slide_confirm(bContext *C, wmOperator *op) BM_select_history_store(em->bm, vso->start_vtx); } + if (((Mesh *)em->ob->data)->editflag & ME_EDIT_MIRROR_X) { + EDBM_verts_mirror_cache_end(em); + } + EDBM_selectmode_flush(em); /* NC_GEOM | ND_DATA & Retess */ @@ -644,7 +678,7 @@ static int edbm_vertex_slide_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED } /* Vertex Slide */ -static int edbm_vertex_slide_exec(bContext *C, wmOperator *op) +static int edbm_vertex_slide_exec_ex(bContext *C, wmOperator *op, const int do_update) { Object *obedit = CTX_data_edit_object(C); BMEditMesh *em = BMEdit_FromObject(obedit); @@ -708,12 +742,21 @@ static int edbm_vertex_slide_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - /* Update Geometry */ - EDBM_update_generic(C, em, TRUE); + if (do_update) { + /* Update Geometry */ + EDBM_update_generic(C, em, TRUE); + } return OPERATOR_FINISHED; } +#if 0 +static int edbm_vertex_slide_exec(bContext *C, wmOperator *op) +{ + return edbm_vertex_slide_exec_ex(C, op, TRUE); +} +#endif + void MESH_OT_vert_slide(wmOperatorType *ot) { PropertyRNA *prop; diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 91c76ffd6fd..9e83742a909 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -751,10 +751,8 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent float nor[3] = {0.0, 0.0, 0.0}; /* 2D normal calc */ - float mval_f[2]; - - mval_f[0] = (float)event->mval[0]; - mval_f[1] = (float)event->mval[1]; + const float mval_f[2] = {(float)event->mval[0], + (float)event->mval[1]}; /* check for edges that are half selected, use for rotation */ done = FALSE; diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c index 6b7409cd031..03e2f2691a8 100644 --- a/source/blender/editors/mesh/editmesh_utils.c +++ b/source/blender/editors/mesh/editmesh_utils.c @@ -345,7 +345,6 @@ void EDBM_mesh_make(ToolSettings *ts, Scene *UNUSED(scene), Object *ob) me->edit_btmesh->selectmode = me->edit_btmesh->bm->selectmode = ts->selectmode; me->edit_btmesh->mat_nr = (ob->actcol > 0) ? ob->actcol - 1 : 0; - me->edit_btmesh->me = me; me->edit_btmesh->ob = ob; } @@ -580,6 +579,7 @@ static void undoMesh_to_editbtMesh(void *umv, void *em_v, void *UNUSED(obdata)) *em = *em_tmp; em->selectmode = um->selectmode; + bm->selectmode = um->selectmode; em->ob = ob; MEM_freeN(em_tmp); @@ -991,15 +991,15 @@ void EDBM_uv_element_map_free(UvElementMap *element_map) /* last_sel, use em->act_face otherwise get the last selected face in the editselections * at the moment, last_sel is mainly useful for making sure the space image dosnt flicker */ -MTexPoly *EDBM_mtexpoly_active_get(BMEditMesh *em, BMFace **r_act_efa, int sloppy) +MTexPoly *EDBM_mtexpoly_active_get(BMEditMesh *em, BMFace **r_act_efa, int sloppy, int selected) { BMFace *efa = NULL; if (!EDBM_mtexpoly_check(em)) return NULL; - efa = BM_active_face_get(em->bm, sloppy); - + efa = BM_active_face_get(em->bm, sloppy, selected); + if (efa) { if (r_act_efa) *r_act_efa = efa; return CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); @@ -1055,14 +1055,14 @@ static BMVert *cache_mirr_intptr_as_bmvert(intptr_t *index_lookup, int index) #define BM_CD_LAYER_ID "__mirror_index" void EDBM_verts_mirror_cache_begin(BMEditMesh *em, const short use_select) { - Mesh *me = em->me; + Mesh *me = (Mesh *)em->ob->data; BMesh *bm = em->bm; BMIter iter; BMVert *v; int li, topo = 0; /* one or the other is used depending if topo is enabled */ - BMBVHTree *tree = NULL; + struct BMBVHTree *tree = NULL; MirrTopoStore_t mesh_topo_store = {NULL, -1, -1, -1}; if (me && (me->editflag & ME_EDIT_MIRROR_TOPO)) { diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index 19ca30b9c45..09d89a961e4 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -43,10 +43,10 @@ #include "DNA_view3d_types.h" #include "BLI_utildefines.h" +#include "BLI_path_util.h" #include "BLI_array.h" #include "BLI_math.h" #include "BLI_edgehash.h" -#include "BLI_utildefines.h" #include "BKE_context.h" #include "BKE_depsgraph.h" diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h index ee74cea48af..aed57141c2a 100644 --- a/source/blender/editors/mesh/mesh_intern.h +++ b/source/blender/editors/mesh/mesh_intern.h @@ -85,8 +85,6 @@ float labda_PdistVL2Dfl(const float v1[3], const float v2[3], const float v3[3]) /* ******************** editface.c */ -void em_setup_viewcontext(struct bContext *C, struct ViewContext *vc); - void MESH_OT_separate(struct wmOperatorType *ot); /* ******************* editmesh_add.c */ diff --git a/source/blender/editors/mesh/mesh_navmesh.c b/source/blender/editors/mesh/mesh_navmesh.c index 14d20d68455..88b1f191e3a 100644 --- a/source/blender/editors/mesh/mesh_navmesh.c +++ b/source/blender/editors/mesh/mesh_navmesh.c @@ -491,7 +491,7 @@ static int navmesh_face_copy_exec(bContext *C, wmOperator *op) BMEditMesh *em = BMEdit_FromObject(obedit); /* do work here */ - BMFace *efa_act = BM_active_face_get(em->bm, FALSE); + BMFace *efa_act = BM_active_face_get(em->bm, FALSE, FALSE); if (efa_act) { if (CustomData_has_layer(&em->bm->pdata, CD_RECAST)) { diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 2e75a779fed..a7467ee4c79 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -42,6 +42,7 @@ #include "MEM_guardedalloc.h" #include "DNA_mesh_types.h" +#include "DNA_view3d_types.h" #include "DNA_key_types.h" #include "DNA_material_types.h" #include "DNA_meshdata_types.h" @@ -441,18 +442,20 @@ int join_mesh_exec(bContext *C, wmOperator *op) } if (me->totpoly) { - /* make mapping for materials */ - for (a = 1; a <= base->object->totcol; a++) { - ma = give_current_material(base->object, a); + if (totmat) { + /* make mapping for materials */ + for (a = 1; a <= base->object->totcol; a++) { + ma = give_current_material(base->object, a); - for (b = 0; b < totcol; b++) { - if (ma == matar[b]) { - matmap[a - 1] = b; - break; + for (b = 0; b < totcol; b++) { + if (ma == matar[b]) { + matmap[a - 1] = b; + break; + } } } } - + CustomData_merge(&me->pdata, &pdata, CD_MASK_MESH, CD_DEFAULT, totpoly); CustomData_copy_data(&me->pdata, &pdata, 0, polyofs, me->totpoly); @@ -877,7 +880,7 @@ intptr_t mesh_octree_table(Object *ob, BMEditMesh *em, const float co[3], char m return 0; } -MirrTopoStore_t mesh_topo_store = {NULL, -1. - 1, -1}; +static MirrTopoStore_t mesh_topo_store = {NULL, -1. - 1, -1}; /* mode is 's' start, or 'e' end, or 'u' use */ /* if end, ob can be NULL */ @@ -1146,3 +1149,125 @@ int *mesh_get_x_mirror_faces(Object *ob, BMEditMesh *em) return mirrorfaces; } + +/* selection, vertex and face */ +/* returns 0 if not found, otherwise 1 */ + +/** + * Face selection in object mode, + * currently only weight-paint and vertex-paint use this. + * + * \return boolean TRUE == Found + */ +int ED_mesh_pick_face(bContext *C, Mesh *me, const int mval[2], unsigned int *index, int size) +{ + ViewContext vc; + + if (!me || me->totpoly == 0) + return 0; + + view3d_set_viewcontext(C, &vc); + + if (size) { + /* sample rect to increase chances of selecting, so that when clicking + * on an edge in the backbuf, we can still select a face */ + + int dummy_dist; + *index = view3d_sample_backbuf_rect(&vc, mval, size, 1, me->totpoly + 1, &dummy_dist, 0, NULL, NULL); + } + else { + /* sample only on the exact position */ + *index = view3d_sample_backbuf(&vc, mval[0], mval[1]); + } + + if ((*index) <= 0 || (*index) > (unsigned int)me->totpoly) + return 0; + + (*index)--; + + return 1; +} +/** + * Use when the back buffer stores face index values. but we want a vert. + * This gets the face then finds the closest vertex to mval. + */ +int ED_mesh_pick_face_vert(bContext *C, Mesh *me, Object *ob, const int mval[2], unsigned int *index, int size) +{ + unsigned int poly_index; + + if (ED_mesh_pick_face(C, me, mval, &poly_index, size)) { + Scene *scene = CTX_data_scene(C); + struct ARegion *ar = CTX_wm_region(C); + + /* derived mesh to find deformed locations */ + DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); + int v_idx_best = -1; + + if (dm->getVertCo) { + /* find the vert closest to 'mval' */ + const float mval_f[2] = {(float)mval[0], + (float)mval[1]}; + MPoly *mp = &me->mpoly[poly_index]; + int fidx; + float len_best = FLT_MAX; + + fidx = mp->totloop - 1; + do { + float co[3], sco[2], len; + const int v_idx = me->mloop[mp->loopstart + fidx].v; + dm->getVertCo(dm, v_idx, co); + mul_m4_v3(ob->obmat, co); + project_float_noclip(ar, co, sco); + len = len_squared_v2v2(mval_f, sco); + if (len < len_best) { + len_best = len; + v_idx_best = v_idx; + } + } while (fidx--); + } + + dm->release(dm); + + if (v_idx_best != -1) { + *index = v_idx_best; + return 1; + } + } + + return 0; +} + +/** + * Vertex selection in object mode, + * currently only weight paint uses this. + * + * \return boolean TRUE == Found + */ +int ED_mesh_pick_vert(bContext *C, Mesh *me, const int mval[2], unsigned int *index, int size) +{ + ViewContext vc; + + if (!me || me->totvert == 0) + return 0; + + view3d_set_viewcontext(C, &vc); + + if (size > 0) { + /* sample rect to increase chances of selecting, so that when clicking + * on an face in the backbuf, we can still select a vert */ + + int dummy_dist; + *index = view3d_sample_backbuf_rect(&vc, mval, size, 1, me->totvert + 1, &dummy_dist, 0, NULL, NULL); + } + else { + /* sample only on the exact position */ + *index = view3d_sample_backbuf(&vc, mval[0], mval[1]); + } + + if ((*index) <= 0 || (*index) > (unsigned int)me->totvert) + return 0; + + (*index)--; + + return 1; +} diff --git a/source/blender/editors/object/object_bake.c b/source/blender/editors/object/object_bake.c index 59cc782f3eb..f9b73a56403 100644 --- a/source/blender/editors/object/object_bake.c +++ b/source/blender/editors/object/object_bake.c @@ -1347,6 +1347,8 @@ static void init_bake_internal(BakeRender *bkr, bContext *C) static void finish_bake_internal(BakeRender *bkr) { + Image *ima; + RE_Database_Free(bkr->re); /* restore raytrace and AO */ @@ -1358,26 +1360,29 @@ static void finish_bake_internal(BakeRender *bkr) if (bkr->prev_r_raytrace == 0) bkr->scene->r.mode &= ~R_RAYTRACE; - if (bkr->result == BAKE_RESULT_OK) { - Image *ima; - /* force OpenGL reload and mipmap recalc */ - for (ima = G.main->image.first; ima; ima = ima->id.next) { + + /* force OpenGL reload and mipmap recalc */ + for (ima = G.main->image.first; ima; ima = ima->id.next) { + ImBuf *ibuf = BKE_image_get_ibuf(ima, NULL); + + if (bkr->result == BAKE_RESULT_OK) { if (ima->ok == IMA_OK_LOADED) { - ImBuf *ibuf = BKE_image_get_ibuf(ima, NULL); if (ibuf) { if (ibuf->userflags & IB_BITMAPDIRTY) { GPU_free_image(ima); imb_freemipmapImBuf(ibuf); } - - /* freed when baking is done, but if its canceled we need to free here */ - if (ibuf->userdata) { - MEM_freeN(ibuf->userdata); - ibuf->userdata = NULL; - } } } } + + /* freed when baking is done, but if its canceled we need to free here */ + if (ibuf) { + if (ibuf->userdata) { + MEM_freeN(ibuf->userdata); + ibuf->userdata = NULL; + } + } } } diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c index be25c79ba25..1ef7c12b409 100644 --- a/source/blender/editors/object/object_constraint.c +++ b/source/blender/editors/object/object_constraint.c @@ -1185,7 +1185,7 @@ void POSE_OT_constraints_clear(wmOperatorType *ot) /* callbacks */ ot->exec = pose_constraints_clear_exec; - ot->poll = ED_operator_posemode; // XXX - do we want to ensure there are selected bones too? + ot->poll = ED_operator_posemode_exclusive; // XXX - do we want to ensure there are selected bones too? } @@ -1266,7 +1266,7 @@ void POSE_OT_constraints_copy(wmOperatorType *ot) /* api callbacks */ ot->exec = pose_constraint_copy_exec; - ot->poll = ED_operator_posemode; + ot->poll = ED_operator_posemode_exclusive; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -1392,9 +1392,9 @@ static short get_new_constraint_target(bContext *C, int con_type, Object **tar_o /* just use the first object we encounter (that isn't the active object) * and which fulfills the criteria for the object-target that we've got */ - if ( (ob != obact) && - ((!only_curve) || (ob->type == OB_CURVE)) && - ((!only_mesh) || (ob->type == OB_MESH)) ) + if ((ob != obact) && + ((!only_curve) || (ob->type == OB_CURVE)) && + ((!only_mesh) || (ob->type == OB_MESH))) { /* set target */ *tar_ob = ob; @@ -1478,15 +1478,15 @@ static int constraint_add_exec(bContext *C, wmOperator *op, Object *ob, ListBase if (type == CONSTRAINT_TYPE_NULL) { return OPERATOR_CANCELLED; } - if ( (type == CONSTRAINT_TYPE_RIGIDBODYJOINT) && (list != &ob->constraints) ) { + if ((type == CONSTRAINT_TYPE_RIGIDBODYJOINT) && (list != &ob->constraints)) { BKE_report(op->reports, RPT_ERROR, "Rigid Body Joint Constraint can only be added to Objects"); return OPERATOR_CANCELLED; } - if ( (type == CONSTRAINT_TYPE_KINEMATIC) && ((!pchan) || (list != &pchan->constraints)) ) { + if ((type == CONSTRAINT_TYPE_KINEMATIC) && ((!pchan) || (list != &pchan->constraints))) { BKE_report(op->reports, RPT_ERROR, "IK Constraint can only be added to Bones"); return OPERATOR_CANCELLED; } - if ( (type == CONSTRAINT_TYPE_SPLINEIK) && ((!pchan) || (list != &pchan->constraints)) ) { + if ((type == CONSTRAINT_TYPE_SPLINEIK) && ((!pchan) || (list != &pchan->constraints))) { BKE_report(op->reports, RPT_ERROR, "Spline IK Constraint can only be added to Bones"); return OPERATOR_CANCELLED; } @@ -1661,7 +1661,7 @@ void POSE_OT_constraint_add(wmOperatorType *ot) /* api callbacks */ ot->invoke = WM_menu_invoke; ot->exec = pose_constraint_add_exec; - ot->poll = ED_operator_posemode; + ot->poll = ED_operator_posemode_exclusive; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -1680,7 +1680,7 @@ void POSE_OT_constraint_add_with_targets(wmOperatorType *ot) /* api callbacks */ ot->invoke = WM_menu_invoke; ot->exec = pose_constraint_add_exec; - ot->poll = ED_operator_posemode; + ot->poll = ED_operator_posemode_exclusive; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -1766,7 +1766,7 @@ void POSE_OT_ik_add(wmOperatorType *ot) /* api callbacks */ ot->invoke = pose_ik_add_invoke; ot->exec = pose_ik_add_exec; - ot->poll = ED_operator_posemode; + ot->poll = ED_operator_posemode_exclusive; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -1816,7 +1816,7 @@ void POSE_OT_ik_clear(wmOperatorType *ot) /* api callbacks */ ot->exec = pose_ik_clear_exec; - ot->poll = ED_operator_posemode; + ot->poll = ED_operator_posemode_exclusive; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 2b1492aa732..4858fdf1c35 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -1658,7 +1658,7 @@ static int skin_radii_equalize_exec(bContext *C, wmOperator *UNUSED(op)) void OBJECT_OT_skin_radii_equalize(wmOperatorType *ot) { ot->name = "Skin Radii Equalize"; - ot->description = "Make skin radii of selected vertices equal"; + ot->description = "Make skin radii of selected vertices equal on each axis"; ot->idname = "OBJECT_OT_skin_radii_equalize"; ot->poll = skin_edit_poll; diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index d8c964ff2df..cafc7ce9300 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -1518,7 +1518,7 @@ static void single_object_users(Scene *scene, View3D *v3d, int flag) */ ob->id.newid = NULL; - if ( (base->flag & flag) == flag) { + if ((base->flag & flag) == flag) { if (ob->id.lib == NULL && ob->id.us > 1) { /* base gets copy of object */ obn = BKE_object_copy(ob); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index c4616fc39c6..b31d2b8b076 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -62,6 +62,7 @@ #include "BKE_tessmesh.h" #include "BKE_report.h" #include "BKE_DerivedMesh.h" +#include "BKE_object_deform.h" #include "RNA_access.h" #include "RNA_define.h" @@ -1136,7 +1137,6 @@ static void vgroup_levels(Object *ob, float offset, float gain) } } -/* TODO - select between groups */ static void vgroup_normalize_all(Object *ob, int lock_active) { MDeformVert *dv, **dvert_array = NULL; @@ -1152,29 +1152,35 @@ static void vgroup_normalize_all(Object *ob, int lock_active) ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot, use_vert_sel); if (dvert_array) { - if (lock_active) { + const int defbase_tot = BLI_countlist(&ob->defbase); + char *lock_flags = BKE_objdef_lock_flags_get(ob, defbase_tot); - for (i = 0; i < dvert_tot; i++) { - /* in case its not selected */ - if (!(dv = dvert_array[i])) { - continue; - } - - defvert_normalize_lock(dv, def_nr); - } + if ((lock_active == TRUE) && + (lock_flags != NULL) && + (def_nr < defbase_tot)) + { + lock_flags[def_nr] = TRUE; } - else { - for (i = 0; i < dvert_tot; i++) { - /* in case its not selected */ - if (!(dv = dvert_array[i])) { - continue; + for (i = 0; i < dvert_tot; i++) { + /* in case its not selected */ + if ((dv = dvert_array[i])) { + if (lock_flags) { + defvert_normalize_lock_map(dv, lock_flags, defbase_tot); + } + else if (lock_active) { + defvert_normalize_lock_single(dv, def_nr); + } + else { + defvert_normalize(dv); } - - defvert_normalize(dv); } } + if (lock_flags) { + MEM_freeN(lock_flags); + } + MEM_freeN(dvert_array); } } @@ -1536,8 +1542,8 @@ void ED_vgroup_mirror(Object *ob, const short mirror_weights, const short flip_v int *flip_map, flip_map_len; const int def_nr = ob->actdef - 1; - if ( (mirror_weights == 0 && flip_vgroups == 0) || - (BLI_findlink(&ob->defbase, def_nr) == NULL) ) + if ((mirror_weights == 0 && flip_vgroups == 0) || + (BLI_findlink(&ob->defbase, def_nr) == NULL)) { return; } @@ -1682,6 +1688,10 @@ void ED_vgroup_mirror(Object *ob, const short mirror_weights, const short flip_v } } + /* flip active group index */ + if (flip_vgroups && flip_map[def_nr] >= 0) + ob->actdef = flip_map[def_nr] + 1; + cleanup: if (flip_map) MEM_freeN(flip_map); @@ -1782,6 +1792,21 @@ static void vgroup_delete_object_mode(Object *ob, bDeformGroup *dg) if (ob->actdef < 1 && ob->defbase.first) ob->actdef = 1; + /* remove all dverts */ + if (ob->defbase.first == NULL) { + if (ob->type == OB_MESH) { + Mesh *me = ob->data; + CustomData_free_layer_active(&me->vdata, CD_MDEFORMVERT, me->totvert); + me->dvert = NULL; + } + else if (ob->type == OB_LATTICE) { + Lattice *lt = ob->data; + if (lt->dvert) { + MEM_freeN(lt->dvert); + lt->dvert = NULL; + } + } + } } /* only in editmode */ @@ -2674,7 +2699,7 @@ void OBJECT_OT_vertex_group_mirror(wmOperatorType *ot) /* properties */ RNA_def_boolean(ot->srna, "mirror_weights", TRUE, "Mirror Weights", "Mirror weights"); - RNA_def_boolean(ot->srna, "flip_group_names", TRUE, "Flip Groups", "Flip vertex group names"); + RNA_def_boolean(ot->srna, "flip_group_names", TRUE, "Flip Group Names", "Flip vertex group names"); RNA_def_boolean(ot->srna, "all_groups", FALSE, "All Groups", "Mirror all vertex groups weights"); } diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 72d2d67e081..b7ce32aa10a 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -3540,7 +3540,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) switch (pset->brushtype) { case PE_BRUSH_COMB: { - float mval_f[2]; + const float mval_f[2] = {dx, dy}; data.mval= mval; data.rad= (float)brush->size; @@ -3552,8 +3552,6 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) invert_m4_m4(ob->imat, ob->obmat); - mval_f[0]= dx; - mval_f[1]= dy; ED_view3d_win_to_delta(ar, mval_f, vec); data.dvec= vec; @@ -4137,7 +4135,7 @@ static void PE_create_particle_edit(Scene *scene, Object *ob, PointCache *cache, if (cache && cache->flag & PTCACHE_DISK_CACHE) return; - if (psys == NULL && cache->mem_cache.first == NULL) + if (psys == NULL && (cache && cache->mem_cache.first == NULL)) return; if (!edit) { diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c index b57500df719..a17d84af128 100644 --- a/source/blender/editors/physics/particle_object.c +++ b/source/blender/editors/physics/particle_object.c @@ -98,12 +98,14 @@ void OBJECT_OT_particle_system_add(wmOperatorType *ot) static int particle_system_remove_exec(bContext *C, wmOperator *UNUSED(op)) { - Object *ob= ED_object_context(C); + Object *ob = ED_object_context(C); Scene *scene = CTX_data_scene(C); - int mode_orig = ob->mode; + int mode_orig; + if (!scene || !ob) return OPERATOR_CANCELLED; + mode_orig = ob->mode; object_remove_particle_system(scene, ob); /* possible this isn't the active object diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index add2cbd566b..068a7aaa50a 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -788,7 +788,7 @@ static void shader_preview_free(void *customdata) /* get rid of copied world */ BLI_remlink(&pr_main->world, sp->worldcopy); - BKE_world_free(sp->worldcopy); + BKE_world_free_ex(sp->worldcopy, FALSE); properties = IDP_GetProperties((ID *)sp->worldcopy, FALSE); if (properties) { diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index 967c6e85590..c93f4156eeb 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -298,13 +298,13 @@ void setlinestyle(int nr) /* Invert line handling */ -#define gl_toggle(mode, onoff) (((onoff) ? glEnable : glDisable)(mode)) +#define GL_TOGGLE(mode, onoff) (((onoff) ? glEnable : glDisable)(mode)) void set_inverted_drawing(int enable) { glLogicOp(enable ? GL_INVERT : GL_COPY); - gl_toggle(GL_COLOR_LOGIC_OP, enable); - gl_toggle(GL_DITHER, !enable); + GL_TOGGLE(GL_COLOR_LOGIC_OP, enable); + GL_TOGGLE(GL_DITHER, !enable); } void sdrawXORline(int x0, int y0, int x1, int y1) diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index adffb97c16f..11d32e11cd0 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -1471,7 +1471,7 @@ void ED_screen_set_scene(bContext *C, bScreen *screen, Scene *scene) /* are there cameras in the views that are not in the scene? */ for (sc = CTX_data_main(C)->screen.first; sc; sc = sc->id.next) { - if ( (U.flag & USER_SCENEGLOBAL) || sc == screen) { + if ((U.flag & USER_SCENEGLOBAL) || sc == screen) { ScrArea *sa = sc->areabase.first; while (sa) { SpaceLink *sl = sa->spacedata.first; @@ -1767,12 +1767,22 @@ void ED_screen_animation_timer(bContext *C, int redraws, int refresh, int sync, sad->ar = CTX_wm_region(C); /* if startframe is larger than current frame, we put currentframe on startframe. * note: first frame then is not drawn! (ton) */ - if (scene->r.sfra > scene->r.cfra) { - sad->sfra = scene->r.cfra; - scene->r.cfra = scene->r.sfra; + if (PRVRANGEON) { + if (scene->r.psfra > scene->r.cfra) { + sad->sfra = scene->r.cfra; + scene->r.cfra = scene->r.psfra; + } + else + sad->sfra = scene->r.cfra; + } + else { + if (scene->r.sfra > scene->r.cfra) { + sad->sfra = scene->r.cfra; + scene->r.cfra = scene->r.sfra; + } + else + sad->sfra = scene->r.cfra; } - else - sad->sfra = scene->r.cfra; sad->redraws = redraws; sad->refresh = refresh; sad->flag |= (enable < 0) ? ANIMPLAY_FLAG_REVERSE : 0; diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 823037a7903..50a210e5d7c 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -349,6 +349,29 @@ int ED_operator_editarmature(bContext *C) return 0; } +/** + * \brief check for pose mode (no mixed modes) + * + * We wan't to enable most pose operations in weight paint mode, + * when it comes to transforming bones, but managing bomes layers/groups + * can be left for pose mode only. (not weight paint mode) + */ +int ED_operator_posemode_exclusive(bContext *C) +{ + Object *obact = CTX_data_active_object(C); + + if (obact && !(obact->mode & OB_MODE_EDIT)) { + Object *obpose; + if ((obpose = BKE_object_pose_armature_get(obact))) { + if (obact == obpose) { + return 1; + } + } + } + + return 0; +} + int ED_operator_posemode(bContext *C) { Object *obact = CTX_data_active_object(C); @@ -1347,12 +1370,12 @@ static int area_split_invoke(bContext *C, wmOperator *op, wmEvent *event) if (event->type == EVT_ACTIONZONE_AREA) { sActionzoneData *sad = event->customdata; - if (sad->modifier > 0) { + if (sad == NULL || sad->modifier > 0) { return OPERATOR_PASS_THROUGH; } /* verify *sad itself */ - if (sad == NULL || sad->sa1 == NULL || sad->az == NULL) + if (sad->sa1 == NULL || sad->az == NULL) return OPERATOR_PASS_THROUGH; /* is this our *sad? if areas not equal it should be passed on */ @@ -2261,12 +2284,12 @@ static int area_join_invoke(bContext *C, wmOperator *op, wmEvent *event) if (event->type == EVT_ACTIONZONE_AREA) { sActionzoneData *sad = event->customdata; - if (sad->modifier > 0) { + if (sad == NULL || sad->modifier > 0) { return OPERATOR_PASS_THROUGH; } /* verify *sad itself */ - if (sad == NULL || sad->sa1 == NULL || sad->sa2 == NULL) + if (sad->sa1 == NULL || sad->sa2 == NULL) return OPERATOR_PASS_THROUGH; /* is this our *sad? if areas equal it should be passed on */ diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 953215b83aa..7c3f376df91 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -1410,24 +1410,46 @@ static float project_paint_uvpixel_mask( /* calculate mask */ if (ps->do_mask_normal) { - MFace *mf = ps->dm_mface + face_index; - short *no1, *no2, *no3; + MFace *mf = &ps->dm_mface[face_index]; float no[3], angle; - no1 = ps->dm_mvert[mf->v1].no; - if (side == 1) { - no2 = ps->dm_mvert[mf->v3].no; - no3 = ps->dm_mvert[mf->v4].no; + if (mf->flag & ME_SMOOTH) { + short *no1, *no2, *no3; + no1 = ps->dm_mvert[mf->v1].no; + if (side == 1) { + no2 = ps->dm_mvert[mf->v3].no; + no3 = ps->dm_mvert[mf->v4].no; + } + else { + no2 = ps->dm_mvert[mf->v2].no; + no3 = ps->dm_mvert[mf->v3].no; + } + + no[0] = w[0] * no1[0] + w[1] * no2[0] + w[2] * no3[0]; + no[1] = w[0] * no1[1] + w[1] * no2[1] + w[2] * no3[1]; + no[2] = w[0] * no1[2] + w[1] * no2[2] + w[2] * no3[2]; + normalize_v3(no); } else { - no2 = ps->dm_mvert[mf->v2].no; - no3 = ps->dm_mvert[mf->v3].no; + /* incase the */ +#if 1 + /* normalizing per pixel isn't optimal, we could cache or check ps->*/ + if (mf->v4) + normal_quad_v3(no, + ps->dm_mvert[mf->v1].co, + ps->dm_mvert[mf->v2].co, + ps->dm_mvert[mf->v3].co, + ps->dm_mvert[mf->v4].co); + else + normal_tri_v3(no, + ps->dm_mvert[mf->v1].co, + ps->dm_mvert[mf->v2].co, + ps->dm_mvert[mf->v3].co); +#else + /* don't use because some modifiers dont have normal data (subsurf for eg) */ + copy_v3_v3(no, (float *)ps->dm->getTessFaceData(ps->dm, face_index, CD_NORMAL)); +#endif } - no[0] = w[0] * no1[0] + w[1] * no2[0] + w[2] * no3[0]; - no[1] = w[0] * no1[1] + w[1] * no2[1] + w[2] * no3[1]; - no[2] = w[0] * no1[2] + w[1] * no2[2] + w[2] * no3[2]; - normalize_v3(no); - /* now we can use the normal as a mask */ if (ps->is_ortho) { angle = angle_normalized_v3v3((float *)ps->viewDir, no); @@ -3695,7 +3717,7 @@ typedef struct ProjectHandle { int thread_index; } ProjectHandle; -static void blend_color_mix(unsigned char *cp, const unsigned char *cp1, const unsigned char *cp2, const int fac) +static void blend_color_mix(unsigned char cp[4], const unsigned char cp1[4], const unsigned char cp2[4], const int fac) { /* this and other blending modes previously used >>8 instead of /255. both * are not equivalent (>>8 is /256), and the former results in rounding @@ -3708,7 +3730,7 @@ static void blend_color_mix(unsigned char *cp, const unsigned char *cp1, const u cp[3] = (mfac * cp1[3] + fac * cp2[3]) / 255; } -static void blend_color_mix_float(float *cp, const float *cp1, const float *cp2, const float fac) +static void blend_color_mix_float(float cp[4], const float cp1[4], const float cp2[4], const float fac) { const float mfac = 1.0f - fac; cp[0] = mfac * cp1[0] + fac * cp2[0]; @@ -5334,12 +5356,25 @@ static void toggle_paint_cursor(bContext *C, int enable) * ensure that the cursor is hidden when not in paint mode */ void ED_space_image_paint_update(wmWindowManager *wm, ToolSettings *settings) { + wmWindow *win; + ScrArea *sa; ImagePaintSettings *imapaint = &settings->imapaint; + int enabled = FALSE; - if (!imapaint->paintcursor) { - imapaint->paintcursor = - WM_paint_cursor_activate(wm, image_paint_poll, - brush_drawcursor, NULL); + for (win = wm->windows.first; win; win = win->next) + for (sa = win->screen->areabase.first; sa; sa = sa->next) + if (sa->spacetype == SPACE_IMAGE) + if (((SpaceImage*)sa->spacedata.first)->mode == SI_MODE_PAINT) + enabled = TRUE; + + if (enabled) { + BKE_paint_init(&imapaint->paint, PAINT_CURSOR_TEXTURE_PAINT); + + if (!imapaint->paintcursor) { + imapaint->paintcursor = + WM_paint_cursor_activate(wm, image_paint_poll, + brush_drawcursor, NULL); + } } } diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 104f727c603..cc71be4938e 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -584,19 +584,21 @@ static void ed_keymap_paint_brush_radial_control(wmKeyMap *keymap, const char *p RCFlags flags) { wmKeyMapItem *kmi; + /* only size needs to follow zoom, strength shows fixed size circle */ + int flags_nozoom = flags & (~RC_ZOOM); kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, 0, 0); set_brush_rc_props(kmi->ptr, paint, "size", "use_unified_size", flags); kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0); - set_brush_rc_props(kmi->ptr, paint, "strength", "use_unified_strength", flags); + set_brush_rc_props(kmi->ptr, paint, "strength", "use_unified_strength", flags_nozoom); kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", WKEY, KM_PRESS, 0, 0); - set_brush_rc_props(kmi->ptr, paint, "weight", "use_unified_weight", flags); + set_brush_rc_props(kmi->ptr, paint, "weight", "use_unified_weight", flags_nozoom); if (flags & RC_ROTATION) { kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_CTRL, 0); - set_brush_rc_props(kmi->ptr, paint, "texture_slot.angle", NULL, flags); + set_brush_rc_props(kmi->ptr, paint, "texture_slot.angle", NULL, flags_nozoom); } } diff --git a/source/blender/editors/sculpt_paint/paint_undo.c b/source/blender/editors/sculpt_paint/paint_undo.c index 8e6c87c1510..f5b9aa742c6 100644 --- a/source/blender/editors/sculpt_paint/paint_undo.c +++ b/source/blender/editors/sculpt_paint/paint_undo.c @@ -23,7 +23,6 @@ * \brief Undo system for painting and sculpting. */ - #include <stdlib.h> #include <string.h> @@ -35,7 +34,7 @@ #include "DNA_userdef_types.h" - +#include "BKE_blender.h" #include "BKE_context.h" #include "BKE_global.h" @@ -43,11 +42,9 @@ #include "paint_intern.h" -#define MAXUNDONAME 64 - typedef struct UndoElem { struct UndoElem *next, *prev; - char name[MAXUNDONAME]; + char name[BKE_UNDO_STR_MAX]; uintptr_t undosize; ListBase elems; @@ -272,4 +269,3 @@ void ED_undo_paint_free(void) undo_stack_free(&ImageUndoStack); undo_stack_free(&MeshUndoStack); } - diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 99bc192042c..df64e1c9d90 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -159,14 +159,12 @@ float paint_calc_object_space_radius(ViewContext *vc, const float center[3], { Object *ob = vc->obact; float delta[3], scale, loc[3]; - float mval_f[2]; + const float mval_f[2] = {pixel_radius, 0.0f}; mul_v3_m4v3(loc, ob->obmat, center); initgrabz(vc->rv3d, loc[0], loc[1], loc[2]); - mval_f[0] = pixel_radius; - mval_f[1] = 0.0f; ED_view3d_win_to_delta(vc->ar, mval_f, delta); scale = fabsf(mat4_to_scale(ob->obmat)); diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 3c389f97b34..ba440e98290 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -72,6 +72,7 @@ #include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_object.h" +#include "BKE_object_deform.h" #include "BKE_paint.h" #include "BKE_report.h" @@ -1008,52 +1009,34 @@ static int weight_sample_invoke(bContext *C, wmOperator *op, wmEvent *event) me = BKE_mesh_from_object(vc.obact); if (me && me->dvert && vc.v3d && vc.rv3d) { - int index; + const int use_vert_sel = (me->editflag & ME_EDIT_VERT_SEL) != 0; + int v_idx_best = -1; + unsigned int index; view3d_operator_needs_opengl(C); - index = view3d_sample_backbuf(&vc, event->mval[0], event->mval[1]); - - if (index && index <= me->totpoly) { - DerivedMesh *dm = mesh_get_derived_final(vc.scene, vc.obact, CD_MASK_BAREMESH); - - if (dm->getVertCo == NULL) { + if (use_vert_sel) { + if (ED_mesh_pick_vert(C, me, event->mval, &index, ED_MESH_PICK_DEFAULT_VERT_SIZE)) { + v_idx_best = index; + } + } + else { + if (ED_mesh_pick_face_vert(C, me, vc.obact, event->mval, &index, ED_MESH_PICK_DEFAULT_FACE_SIZE)) { + v_idx_best = index; + } + else if (ED_mesh_pick_face(C, me, event->mval, &index, ED_MESH_PICK_DEFAULT_FACE_SIZE)) { + /* this relies on knowning the internal worksings of ED_mesh_pick_face_vert() */ BKE_report(op->reports, RPT_WARNING, "The modifier used does not support deformed locations"); } - else { - MPoly *mp = ((MPoly *)me->mpoly) + (index - 1); - const int vgroup_active = vc.obact->actdef - 1; - Scene *scene = vc.scene; - ToolSettings *ts = vc.scene->toolsettings; - Brush *brush = paint_brush(&ts->wpaint->paint); - float mval_f[2]; - int v_idx_best = -1; - int fidx; - float len_best = FLT_MAX; - - mval_f[0] = (float)event->mval[0]; - mval_f[1] = (float)event->mval[1]; - - fidx = mp->totloop - 1; - do { - float co[3], sco[3], len; - const int v_idx = me->mloop[mp->loopstart + fidx].v; - dm->getVertCo(dm, v_idx, co); - project_float_noclip(vc.ar, co, sco); - len = len_squared_v2v2(mval_f, sco); - if (len < len_best) { - len_best = len; - v_idx_best = v_idx; - } - } while (fidx--); + } - if (v_idx_best != -1) { /* should always be valid */ - float vgroup_weight = defvert_find_weight(&me->dvert[v_idx_best], vgroup_active); - BKE_brush_weight_set(scene, brush, vgroup_weight); - change = TRUE; - } - } - dm->release(dm); + if (v_idx_best != -1) { /* should always be valid */ + ToolSettings *ts = vc.scene->toolsettings; + Brush *brush = paint_brush(&ts->wpaint->paint); + const int vgroup_active = vc.obact->actdef - 1; + float vgroup_weight = defvert_find_weight(&me->dvert[v_idx_best], vgroup_active); + BKE_brush_weight_set(vc.scene, brush, vgroup_weight); + change = TRUE; } } @@ -1084,6 +1067,20 @@ void PAINT_OT_weight_sample(wmOperatorType *ot) } /* samples cursor location, and gives menu with vertex groups to activate */ +static int weight_paint_sample_enum_itemf__helper(const MDeformVert *dvert, const int defbase_tot, int *groups) +{ + /* this func fills in used vgroup's */ + int found = FALSE; + int i = dvert->totweight; + MDeformWeight *dw; + for (dw = dvert->dw; i > 0; dw++, i--) { + if (dw->def_nr < defbase_tot) { + groups[dw->def_nr] = TRUE; + found = TRUE; + } + } + return found; +} static EnumPropertyItem *weight_paint_sample_enum_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free) { if (C) { @@ -1095,56 +1092,57 @@ static EnumPropertyItem *weight_paint_sample_enum_itemf(bContext *C, PointerRNA view3d_set_viewcontext(C, &vc); me = BKE_mesh_from_object(vc.obact); - if (me && me->dvert && vc.v3d && vc.rv3d) { - int index; + if (me && me->dvert && vc.v3d && vc.rv3d && vc.obact->defbase.first) { + const int defbase_tot = BLI_countlist(&vc.obact->defbase); + const int use_vert_sel = (me->editflag & ME_EDIT_VERT_SEL) != 0; + int *groups = MEM_callocN(defbase_tot * sizeof(int), "groups"); + int found = FALSE; + unsigned int index; - view3d_operator_needs_opengl(C); + int mval[2] = {win->eventstate->x - vc.ar->winrct.xmin, + win->eventstate->y - vc.ar->winrct.ymin}; - index = view3d_sample_backbuf(&vc, win->eventstate->x - vc.ar->winrct.xmin, win->eventstate->y - vc.ar->winrct.ymin); + view3d_operator_needs_opengl(C); - if (index && index <= me->totpoly) { - const int defbase_tot = BLI_countlist(&vc.obact->defbase); - if (defbase_tot) { - MPoly *mp = ((MPoly *)me->mpoly) + (index - 1); + if (use_vert_sel) { + if (ED_mesh_pick_vert(C, me, mval, &index, ED_MESH_PICK_DEFAULT_VERT_SIZE)) { + MDeformVert *dvert = &me->dvert[index]; + found |= weight_paint_sample_enum_itemf__helper(dvert, defbase_tot, groups); + } + } + else { + if (ED_mesh_pick_face(C, me, mval, &index, ED_MESH_PICK_DEFAULT_FACE_SIZE)) { + MPoly *mp = &me->mpoly[index]; unsigned int fidx = mp->totloop - 1; - int *groups = MEM_callocN(defbase_tot * sizeof(int), "groups"); - int found = FALSE; do { - MDeformVert *dvert = me->dvert + me->mloop[mp->loopstart + fidx].v; - int i = dvert->totweight; - MDeformWeight *dw; - for (dw = dvert->dw; i > 0; dw++, i--) { - if (dw->def_nr < defbase_tot) { - groups[dw->def_nr] = TRUE; - found = TRUE; - } - } + MDeformVert *dvert = &me->dvert[me->mloop[mp->loopstart + fidx].v]; + found |= weight_paint_sample_enum_itemf__helper(dvert, defbase_tot, groups); } while (fidx--); + } + } - if (found == FALSE) { - MEM_freeN(groups); + if (found == FALSE) { + MEM_freeN(groups); + } + else { + EnumPropertyItem *item = NULL, item_tmp = {0}; + int totitem = 0; + int i = 0; + bDeformGroup *dg; + for (dg = vc.obact->defbase.first; dg && i < defbase_tot; i++, dg = dg->next) { + if (groups[i]) { + item_tmp.identifier = item_tmp.name = dg->name; + item_tmp.value = i; + RNA_enum_item_add(&item, &totitem, &item_tmp); } - else { - EnumPropertyItem *item = NULL, item_tmp = {0}; - int totitem = 0; - int i = 0; - bDeformGroup *dg; - for (dg = vc.obact->defbase.first; dg && i < defbase_tot; i++, dg = dg->next) { - if (groups[i]) { - item_tmp.identifier = item_tmp.name = dg->name; - item_tmp.value = i; - RNA_enum_item_add(&item, &totitem, &item_tmp); - } - } + } - RNA_enum_item_end(&item, &totitem); - *free = 1; + RNA_enum_item_end(&item, &totitem); + *free = 1; - MEM_freeN(groups); - return item; - } - } + MEM_freeN(groups); + return item; } } } @@ -1308,29 +1306,6 @@ static char has_locked_group(MDeformVert *dvert, const int defbase_tot, } return FALSE; } -/* - * gen_lck_flags gets the status of "flag" for each bDeformGroup - * in ob->defbase and returns an array containing them - */ -static char *gen_lock_flags(Object *ob, int defbase_tot) -{ - char is_locked = FALSE; - int i; - //int defbase_tot = BLI_countlist(&ob->defbase); - char *lock_flags = MEM_mallocN(defbase_tot * sizeof(char), "defflags"); - bDeformGroup *defgroup; - - for (i = 0, defgroup = ob->defbase.first; i < defbase_tot && defgroup; defgroup = defgroup->next, i++) { - lock_flags[i] = ((defgroup->flag & DG_LOCK_WEIGHT) != 0); - is_locked |= lock_flags[i]; - } - if (is_locked) { - return lock_flags; - } - - MEM_freeN(lock_flags); - return NULL; -} static int has_locked_group_selected(int defbase_tot, const char *defbase_sel, const char *lock_flags) { @@ -1664,9 +1639,9 @@ static int apply_mp_locks_normalize(Mesh *me, const WeightPaintInfo *wpi, dv_test.totweight = dv->totweight; /* do not multi-paint if a locked group is selected or the active group is locked * !lock_flags[dw->def_nr] helps if nothing is selected, but active group is locked */ - if ( (wpi->lock_flags == NULL) || - ((wpi->lock_flags[dw->def_nr] == FALSE) && /* def_nr range has to be checked for by caller */ - has_locked_group_selected(wpi->defbase_tot, wpi->defbase_sel, wpi->lock_flags) == FALSE)) + if ((wpi->lock_flags == NULL) || + ((wpi->lock_flags[dw->def_nr] == FALSE) && /* def_nr range has to be checked for by caller */ + has_locked_group_selected(wpi->defbase_tot, wpi->defbase_sel, wpi->lock_flags) == FALSE)) { if (wpi->do_multipaint && wpi->defbase_tot_sel > 1) { if (change && change != 1) { @@ -1722,10 +1697,6 @@ static int get_first_selected_nonzero_weight(MDeformVert *dvert, const int defba return -1; } - -static char *wpaint_make_validmap(Object *ob); - - static void do_weight_paint_vertex( /* vars which remain the same for every vert */ VPaint *wp, Object *ob, const WeightPaintInfo *wpi, @@ -1816,8 +1787,8 @@ static void do_weight_paint_vertex( /* If there are no locks or multipaint, * then there is no need to run the more complicated checks */ - if ( (do_multipaint_totsel == FALSE) && - (wpi->lock_flags == NULL || has_locked_group(dv, wpi->defbase_tot, wpi->vgroup_validmap, wpi->lock_flags) == FALSE)) + if ((do_multipaint_totsel == FALSE) && + (wpi->lock_flags == NULL || has_locked_group(dv, wpi->defbase_tot, wpi->vgroup_validmap, wpi->lock_flags) == FALSE)) { dw->weight = wpaint_blend(wp, dw->weight, dw_prev->weight, alpha, paintweight, wpi->brush_alpha_value, wpi->do_flip, FALSE); @@ -2067,63 +2038,6 @@ struct WPaintData { int defbase_tot; }; -static char *wpaint_make_validmap(Object *ob) -{ - bDeformGroup *dg; - ModifierData *md; - char *vgroup_validmap; - GHash *gh; - int i, step1 = 1; - - if (ob->defbase.first == NULL) { - return NULL; - } - - gh = BLI_ghash_str_new("wpaint_make_validmap gh"); - - /* add all names to a hash table */ - for (dg = ob->defbase.first; dg; dg = dg->next) { - BLI_ghash_insert(gh, dg->name, NULL); - } - - /* now loop through the armature modifiers and identify deform bones */ - for (md = ob->modifiers.first; md; md = !md->next && step1 ? (step1 = 0), modifiers_getVirtualModifierList(ob) : md->next) { - if (!(md->mode & (eModifierMode_Realtime | eModifierMode_Virtual))) - continue; - - if (md->type == eModifierType_Armature) { - ArmatureModifierData *amd = (ArmatureModifierData *) md; - - if (amd->object && amd->object->pose) { - bPose *pose = amd->object->pose; - bPoseChannel *chan; - - for (chan = pose->chanbase.first; chan; chan = chan->next) { - if (chan->bone->flag & BONE_NO_DEFORM) - continue; - - if (BLI_ghash_remove(gh, chan->name, NULL, NULL)) { - BLI_ghash_insert(gh, chan->name, SET_INT_IN_POINTER(1)); - } - } - } - } - } - - vgroup_validmap = MEM_mallocN(BLI_ghash_size(gh), "wpaint valid map"); - - /* add all names to a hash table */ - for (dg = ob->defbase.first, i = 0; dg; dg = dg->next, i++) { - vgroup_validmap[i] = (BLI_ghash_lookup(gh, dg->name) != NULL); - } - - BLI_assert(i == BLI_ghash_size(gh)); - - BLI_ghash_free(gh, NULL, NULL); - - return vgroup_validmap; -} - static int wpaint_stroke_test_start(bContext *C, wmOperator *op, const float UNUSED(mouse[2])) { Scene *scene = CTX_data_scene(C); @@ -2202,9 +2116,9 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, const float UNU /* set up auto-normalize, and generate map for detecting which * vgroups affect deform bones */ wpd->defbase_tot = BLI_countlist(&ob->defbase); - wpd->lock_flags = gen_lock_flags(ob, wpd->defbase_tot); + wpd->lock_flags = BKE_objdef_lock_flags_get(ob, wpd->defbase_tot); if (ts->auto_normalize || ts->multipaint || wpd->lock_flags) { - wpd->vgroup_validmap = wpaint_make_validmap(ob); + wpd->vgroup_validmap = BKE_objdef_validmap_get(ob, wpd->defbase_tot); } /* painting on subsurfs should give correct points too, this returns me->totvert amount */ @@ -2243,7 +2157,6 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P float alpha; float mval[2]; int use_vert_sel; - char *defbase_sel; const float pressure = RNA_float_get(itemptr, "pressure"); const float brush_size_pressure = BKE_brush_size_get(scene, brush) * (BKE_brush_use_size_pressure(scene, brush) ? pressure : 1.0f); @@ -2277,12 +2190,13 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P + /* *** setup WeightPaintInfo - pass onto do_weight_paint_vertex *** */ wpi.defbase_tot = wpd->defbase_tot; - defbase_sel = MEM_mallocN(wpi.defbase_tot * sizeof(char), "wpi.defbase_sel"); - wpi.defbase_tot_sel = get_selected_defgroups(ob, defbase_sel, wpi.defbase_tot); - wpi.defbase_sel = defbase_sel; /* so we can stay const */ - if (wpi.defbase_tot_sel == 0 && ob->actdef > 0) wpi.defbase_tot_sel = 1; + wpi.defbase_sel = BKE_objdef_selected_get(ob, wpi.defbase_tot, &wpi.defbase_tot_sel); + if (wpi.defbase_tot_sel == 0 && ob->actdef > 0) { + wpi.defbase_tot_sel = 1; + } wpi.defbase_tot_unsel = wpi.defbase_tot - wpi.defbase_tot_sel; wpi.vgroup_active = wpd->vgroup_active; diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index e2289bc9cfc..210477e3e5a 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -3074,12 +3074,12 @@ void sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob, int need_ /* BMESH ONLY --- at some point we should move sculpt code to use polygons only - but for now it needs tessfaces */ BKE_mesh_tessface_ensure(me); - /* needs to be called after we ensure tessface */ - dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); - if (!mmd) ss->kb = ob_get_keyblock(ob); else ss->kb = NULL; + /* needs to be called after we ensure tessface */ + dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); + if (mmd) { ss->multires = mmd; ss->totvert = dm->getNumVerts(dm); diff --git a/source/blender/editors/space_action/action_select.c b/source/blender/editors/space_action/action_select.c index c9f765ac3db..9ab79d73e76 100644 --- a/source/blender/editors/space_action/action_select.c +++ b/source/blender/editors/space_action/action_select.c @@ -255,8 +255,8 @@ static void borderselect_action(bAnimContext *ac, rcti rect, short mode, short s } /* perform vertical suitability check (if applicable) */ - if ( (mode == ACTKEYS_BORDERSEL_FRAMERANGE) || - !((ymax < rectf.ymin) || (ymin > rectf.ymax)) ) + if ((mode == ACTKEYS_BORDERSEL_FRAMERANGE) || + !((ymax < rectf.ymin) || (ymin > rectf.ymax))) { /* loop over data selecting */ if (ale->type == ANIMTYPE_GPLAYER) @@ -802,8 +802,8 @@ static void actkeys_select_leftright(bAnimContext *ac, short leftright, short se TimeMarker *marker; for (marker = markers->first; marker; marker = marker->next) { - if ( ((leftright == ACTKEYS_LRSEL_LEFT) && (marker->frame < CFRA)) || - ((leftright == ACTKEYS_LRSEL_RIGHT) && (marker->frame >= CFRA)) ) + if (((leftright == ACTKEYS_LRSEL_LEFT) && (marker->frame < CFRA)) || + ((leftright == ACTKEYS_LRSEL_RIGHT) && (marker->frame >= CFRA))) { marker->flag |= SELECT; } diff --git a/source/blender/editors/space_buttons/buttons_texture.c b/source/blender/editors/space_buttons/buttons_texture.c index cdecda63432..0e82d8651f3 100644 --- a/source/blender/editors/space_buttons/buttons_texture.c +++ b/source/blender/editors/space_buttons/buttons_texture.c @@ -341,7 +341,7 @@ static void template_texture_user_menu(bContext *C, uiLayout *layout, void *UNUS { /* callback when opening texture user selection menu, to create buttons. */ SpaceButs *sbuts = CTX_wm_space_buts(C); - ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL; + ButsContextTexture *ct = sbuts->texuser; ButsTextureUser *user; uiBlock *block = uiLayoutGetBlock(layout); const char *last_category = NULL; diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c index 7a54a39ee48..08ad6aac970 100644 --- a/source/blender/editors/space_clip/clip_editor.c +++ b/source/blender/editors/space_clip/clip_editor.c @@ -158,7 +158,7 @@ void ED_space_clip_get_aspect(SpaceClip *sc, float *aspx, float *aspy) MovieClip *clip = ED_space_clip_get_clip(sc); if (clip) - BKE_movieclip_aspect(clip, aspx, aspy); + BKE_movieclip_get_aspect(clip, aspx, aspy); else *aspx = *aspy = 1.0f; diff --git a/source/blender/editors/space_clip/clip_toolbar.c b/source/blender/editors/space_clip/clip_toolbar.c index d8c7bf3f809..1bdf5214192 100644 --- a/source/blender/editors/space_clip/clip_toolbar.c +++ b/source/blender/editors/space_clip/clip_toolbar.c @@ -230,7 +230,7 @@ static void clip_panel_operator_redo(const bContext *C, Panel *pa) block = uiLayoutGetBlock(pa->layout); if (!WM_operator_check_ui_enabled(C, op->type->name)) - uiLayoutSetEnabled(pa->layout, 0); + uiLayoutSetEnabled(pa->layout, FALSE); /* note, blockfunc is a default but->func, use Handle func to allow button callbacks too */ uiBlockSetHandleFunc(block, ED_undo_operator_repeat_cb_evt, op); diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c index bb06104d442..7f43c404095 100644 --- a/source/blender/editors/space_clip/space_clip.c +++ b/source/blender/editors/space_clip/space_clip.c @@ -1131,10 +1131,13 @@ static void clip_main_area_draw(const bContext *C, ARegion *ar) if (mask) { ScrArea *sa = CTX_wm_area(C); int width, height; + float aspx, aspy; ED_mask_get_size(sa, &width, &height); + ED_space_clip_get_aspect(sc, &aspx, &aspy); ED_mask_draw_region(mask, ar, sc->mask_info.draw_flag, sc->mask_info.draw_type, width, height, + aspx, aspy, TRUE, TRUE, sc->stabmat, C); } diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index ff7a71af8c2..040f276940d 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -156,7 +156,7 @@ static FileSelection file_selection_get(bContext *C, const rcti *rect, short fil return sel; } -static FileSelect file_select_do(bContext *C, int selected_idx) +static FileSelect file_select_do(bContext *C, int selected_idx, short do_diropen) { FileSelect retval = FILE_SELECT_NOTHING; SpaceFile *sfile = CTX_wm_space_file(C); @@ -172,8 +172,12 @@ static FileSelect file_select_do(bContext *C, int selected_idx) params->active_file = selected_idx; if (S_ISDIR(file->type)) { + if (do_diropen == FALSE) { + params->file[0] = '\0'; + retval = FILE_SELECT_DIR; + } /* the path is too long and we are not going up! */ - if (strcmp(file->relname, "..") && strlen(params->dir) + strlen(file->relname) >= FILE_MAX) { + else if (strcmp(file->relname, "..") && strlen(params->dir) + strlen(file->relname) >= FILE_MAX) { // XXX error("Path too long, cannot enter this directory"); } else { @@ -202,7 +206,7 @@ static FileSelect file_select_do(bContext *C, int selected_idx) } -static FileSelect file_select(bContext *C, const rcti *rect, FileSelType select, short fill) +static FileSelect file_select(bContext *C, const rcti *rect, FileSelType select, short fill, short do_diropen) { SpaceFile *sfile = CTX_wm_space_file(C); FileSelect retval = FILE_SELECT_NOTHING; @@ -219,7 +223,7 @@ static FileSelect file_select(bContext *C, const rcti *rect, FileSelType select, if ((sel.last >= 0) && ((select == FILE_SEL_ADD) || (select == FILE_SEL_TOGGLE))) { /* Check last selection, if selected, act on the file or dir */ if (filelist_is_selected(sfile->files, sel.last, check_type)) { - retval = file_select_do(C, sel.last); + retval = file_select_do(C, sel.last, do_diropen); } } @@ -284,7 +288,7 @@ static int file_border_select_exec(bContext *C, wmOperator *op) BLI_rcti_isect(&(ar->v2d.mask), &rect, &rect); - ret = file_select(C, &rect, select ? FILE_SEL_ADD : FILE_SEL_REMOVE, 0); + ret = file_select(C, &rect, select ? FILE_SEL_ADD : FILE_SEL_REMOVE, FALSE, FALSE); if (FILE_SELECT_DIR == ret) { WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); } @@ -320,6 +324,7 @@ static int file_select_invoke(bContext *C, wmOperator *op, wmEvent *event) rcti rect; int extend = RNA_boolean_get(op->ptr, "extend"); int fill = RNA_boolean_get(op->ptr, "fill"); + int do_diropen = RNA_boolean_get(op->ptr, "open"); if (ar->regiontype != RGN_TYPE_WINDOW) return OPERATOR_CANCELLED; @@ -333,7 +338,7 @@ static int file_select_invoke(bContext *C, wmOperator *op, wmEvent *event) /* single select, deselect all selected first */ if (!extend) file_deselect_all(sfile, SELECTED_FILE); - ret = file_select(C, &rect, extend ? FILE_SEL_TOGGLE : FILE_SEL_ADD, fill); + ret = file_select(C, &rect, extend ? FILE_SEL_TOGGLE : FILE_SEL_ADD, fill, do_diropen); if (FILE_SELECT_DIR == ret) WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); else if (FILE_SELECT_FILE == ret) @@ -357,8 +362,9 @@ void FILE_OT_select(wmOperatorType *ot) ot->poll = ED_operator_file_active; /* rna */ - RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend selection instead of deselecting everything first"); - RNA_def_boolean(ot->srna, "fill", 0, "Fill", "Select everything beginning with the last selection"); + RNA_def_boolean(ot->srna, "extend", FALSE, "Extend", "Extend selection instead of deselecting everything first"); + RNA_def_boolean(ot->srna, "fill", FALSE, "Fill", "Select everything beginning with the last selection"); + RNA_def_boolean(ot->srna, "open", TRUE, "Open", "Open a directory when selecting it"); } static int file_select_all_exec(bContext *C, wmOperator *UNUSED(op)) @@ -1113,7 +1119,7 @@ static void file_expand_directory(bContext *C) if (sfile->params) { /* TODO, what about // when relbase isn't valid? */ - if (G.relbase_valid && strncmp(sfile->params->dir, "//", 2) == 0) { + if (G.relbase_valid && BLI_path_is_rel(sfile->params->dir)) { BLI_path_abs(sfile->params->dir, G.main->name); } else if (sfile->params->dir[0] == '~') { diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index fcf6f28b406..4b568b43695 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -284,8 +284,6 @@ static void file_main_area_init(wmWindowManager *wm, ARegion *ar) keymap = WM_keymap_find(wm->defaultconf, "File Browser Main", SPACE_FILE, 0); WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); - - } static void file_main_area_listener(ARegion *ar, wmNotifier *wmn) @@ -418,12 +416,26 @@ static void file_keymap(struct wmKeyConfig *keyconf) keymap = WM_keymap_find(keyconf, "File Browser Main", SPACE_FILE, 0); kmi = WM_keymap_add_item(keymap, "FILE_OT_execute", LEFTMOUSE, KM_DBL_CLICK, 0, 0); RNA_boolean_set(kmi->ptr, "need_active", TRUE); + + /* left mouse selects and opens */ WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, 0, 0); kmi = WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, KM_SHIFT, 0); RNA_boolean_set(kmi->ptr, "extend", TRUE); kmi = WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, KM_ALT, 0); RNA_boolean_set(kmi->ptr, "extend", TRUE); RNA_boolean_set(kmi->ptr, "fill", TRUE); + + /* right mouse selects without opening */ + kmi = WM_keymap_add_item(keymap, "FILE_OT_select", RIGHTMOUSE, KM_CLICK, 0, 0); + RNA_boolean_set(kmi->ptr, "open", FALSE); + kmi = WM_keymap_add_item(keymap, "FILE_OT_select", RIGHTMOUSE, KM_CLICK, KM_SHIFT, 0); + RNA_boolean_set(kmi->ptr, "extend", TRUE); + RNA_boolean_set(kmi->ptr, "open", FALSE); + kmi = WM_keymap_add_item(keymap, "FILE_OT_select", RIGHTMOUSE, KM_CLICK, KM_ALT, 0); + RNA_boolean_set(kmi->ptr, "extend", TRUE); + RNA_boolean_set(kmi->ptr, "fill", TRUE); + RNA_boolean_set(kmi->ptr, "open", FALSE); + WM_keymap_add_item(keymap, "FILE_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "FILE_OT_refresh", PADPERIOD, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "FILE_OT_select_border", BKEY, KM_PRESS, 0, 0); diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c index ad97b7853c4..e4bda15bc7d 100644 --- a/source/blender/editors/space_graph/graph_draw.c +++ b/source/blender/editors/space_graph/graph_draw.c @@ -235,7 +235,7 @@ static void draw_fcurve_vertices_handles(FCurve *fcu, SpaceIpo *sipo, View2D *v2 * if a Graph Editor option to only show handles of selected keys is on. */ if (!sel_handle_only || BEZSELECTED(bezt) ) { - if ( (!prevbezt && (bezt->ipo == BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ)) ) { + if ((!prevbezt && (bezt->ipo == BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ))) { if ((bezt->f1 & SELECT) == sel) /* && v2d->cur.xmin < bezt->vec[0][0] < v2d->cur.xmax)*/ draw_fcurve_handle_control(bezt->vec[0][0], bezt->vec[0][1], xscale, yscale, hsize); } @@ -378,8 +378,8 @@ static void draw_fcurve_handles(SpaceIpo *sipo, FCurve *fcu) } else { /* only draw first handle if previous segment was had handles, and selection is ok */ - if ( ((bezt->f1 & SELECT) == sel) && - ( (!prevbezt && (bezt->ipo == BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ)) ) ) + if (((bezt->f1 & SELECT) == sel) && + ((!prevbezt && (bezt->ipo == BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ)))) { fp = bezt->vec[0]; UI_GetThemeColor3ubv(basecol + bezt->h1, col); @@ -390,8 +390,8 @@ static void draw_fcurve_handles(SpaceIpo *sipo, FCurve *fcu) } /* only draw second handle if this segment is bezier, and selection is ok */ - if ( ((bezt->f3 & SELECT) == sel) && - (bezt->ipo == BEZT_IPO_BEZ) ) + if (((bezt->f3 & SELECT) == sel) && + (bezt->ipo == BEZT_IPO_BEZ)) { fp = bezt->vec[1]; UI_GetThemeColor3ubv(basecol + bezt->h2, col); @@ -846,11 +846,11 @@ void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid /* 1) draw curve line */ { /* set color/drawing style for curve itself */ - if ( ((fcu->grp) && (fcu->grp->flag & AGRP_PROTECTED)) || (fcu->flag & FCURVE_PROTECTED) ) { + if (((fcu->grp) && (fcu->grp->flag & AGRP_PROTECTED)) || (fcu->flag & FCURVE_PROTECTED)) { /* protected curves (non editable) are drawn with dotted lines */ setlinestyle(2); } - if ( ((fcu->grp) && (fcu->grp->flag & AGRP_MUTED)) || (fcu->flag & FCURVE_MUTED) ) { + if (((fcu->grp) && (fcu->grp->flag & AGRP_MUTED)) || (fcu->flag & FCURVE_MUTED)) { /* muted curves are drawn in a grayish hue */ // XXX should we have some variations? UI_ThemeColorShade(TH_HEADER, 50); @@ -878,7 +878,7 @@ void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid */ draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, grid); } - else if ( ((fcu->bezt) || (fcu->fpt)) && (fcu->totvert) ) { + else if (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)) { /* just draw curve based on defined data (i.e. no modifiers) */ if (fcu->bezt) draw_fcurve_curve_bezts(ac, ale->id, fcu, &ar->v2d); @@ -908,7 +908,7 @@ void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid } } } - else if ( ((fcu->bezt) || (fcu->fpt)) && (fcu->totvert) ) { + else if (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)) { /* apply unit mapping */ ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, fcu, 0); diff --git a/source/blender/editors/space_graph/graph_select.c b/source/blender/editors/space_graph/graph_select.c index 32abad86828..633f2b72cf6 100644 --- a/source/blender/editors/space_graph/graph_select.c +++ b/source/blender/editors/space_graph/graph_select.c @@ -942,7 +942,7 @@ static void nearest_fcurve_vert_store(ListBase *matches, View2D *v2d, FCurve *fc /* if there is already a point for the F-Curve, check if this point is closer than that was */ if ((nvi) && (nvi->fcu == fcu)) { /* replace if we are closer, or if equal and that one wasn't selected but we are... */ - if ( (nvi->dist > dist) || ((nvi->sel == 0) && BEZSELECTED(bezt)) ) + if ((nvi->dist > dist) || ((nvi->sel == 0) && BEZSELECTED(bezt))) replace = 1; } /* add new if not replacing... */ diff --git a/source/blender/editors/space_image/image_edit.c b/source/blender/editors/space_image/image_edit.c index ac9883b411d..79d01491df7 100644 --- a/source/blender/editors/space_image/image_edit.c +++ b/source/blender/editors/space_image/image_edit.c @@ -143,27 +143,6 @@ int ED_space_image_has_buffer(SpaceImage *sima) return has_buffer; } -void ED_image_get_size(Image *ima, int *width, int *height) -{ - ImBuf *ibuf = NULL; - void *lock; - - if (ima) - ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); - - if (ibuf && ibuf->x > 0 && ibuf->y > 0) { - *width = ibuf->x; - *height = ibuf->y; - } - else { - *width = IMG_SIZE_FALLBACK; - *height = IMG_SIZE_FALLBACK; - } - - if (ima) - BKE_image_release_ibuf(ima, lock); -} - void ED_space_image_get_size(SpaceImage *sima, int *width, int *height) { Scene *scene = sima->iuser.scene; @@ -205,23 +184,18 @@ void ED_space_image_get_size_fl(SpaceImage *sima, float size[2]) size[1] = size_i[1]; } -void ED_image_get_aspect(Image *ima, float *aspx, float *aspy) -{ - *aspx = *aspy = 1.0; +void ED_space_image_get_aspect(SpaceImage *sima, float *aspx, float *aspy) +{ + Image *ima = sima->image; if ((ima == NULL) || (ima->type == IMA_TYPE_R_RESULT) || (ima->type == IMA_TYPE_COMPOSITE) || (ima->aspx == 0.0f || ima->aspy == 0.0f)) { - return; + *aspx = *aspy = 1.0; + } + else { + BKE_image_get_aspect(ima, aspx, aspy); } - - /* x is always 1 */ - *aspy = ima->aspy / ima->aspx; -} - -void ED_space_image_get_aspect(SpaceImage *sima, float *aspx, float *aspy) -{ - ED_image_get_aspect(ED_space_image(sima), aspx, aspy); } void ED_space_image_get_zoom(SpaceImage *sima, ARegion *ar, float *zoomx, float *zoomy) @@ -254,15 +228,21 @@ void ED_space_image_get_uv_aspect(SpaceImage *sima, float *aspx, float *aspy) } } -void ED_image_get_uv_aspect(Image *ima, float *aspx, float *aspy) +void ED_image_get_uv_aspect(Image *ima, ImageUser *iuser, float *aspx, float *aspy) { - int w, h; + if (ima) { + int w, h; - ED_image_get_aspect(ima, aspx, aspy); - ED_image_get_size(ima, &w, &h); + BKE_image_get_aspect(ima, aspx, aspy); + BKE_image_get_size(ima, iuser, &w, &h); - *aspx *= (float)w; - *aspy *= (float)h; + *aspx *= (float)w; + *aspy *= (float)h; + } + else { + *aspx = 1.0f; + *aspy = 1.0f; + } } /* takes event->mval */ diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 3d6b316b743..86722c5158e 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -632,7 +632,7 @@ static int image_view_selected_exec(bContext *C, wmOperator *UNUSED(op)) ima = ED_space_image(sima); ED_space_image_get_size(sima, &width, &height); - ED_image_get_aspect(ima, &aspx, &aspy); + ED_space_image_get_aspect(sima, &aspx, &aspy); width = width * aspx; height = height * aspy; @@ -1051,7 +1051,7 @@ static int image_replace_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(eve return image_replace_exec(C, op); if (!RNA_struct_property_is_set(op->ptr, "relative_path")) - RNA_boolean_set(op->ptr, "relative_path", (strncmp(sima->image->name, "//", 2)) == 0); + RNA_boolean_set(op->ptr, "relative_path", BLI_path_is_rel(sima->image->name)); image_filesel(C, op, sima->image->name); @@ -1160,7 +1160,7 @@ static int save_image_options_init(SaveImageOptions *simopts, SpaceImage *sima, /* check for empty path */ if (guess_path && simopts->filepath[0] == 0) { - if ( (G.ima[0] == '/') && (G.ima[1] == '/') && (G.ima[2] == '\0') ) { + if ((G.ima[0] == '/') && (G.ima[1] == '/') && (G.ima[2] == '\0')) { BLI_strncpy(simopts->filepath, "//untitled", FILE_MAX); } else { @@ -1586,7 +1586,7 @@ static int image_new_exec(bContext *C, wmOperator *op) PropertyRNA *prop; char name[MAX_ID_NAME - 2]; float color[4]; - int width, height, floatbuf, uvtestgrid, alpha; + int width, height, floatbuf, gen_type, alpha; /* retrieve state */ sima = CTX_wm_space_image(C); @@ -1597,7 +1597,7 @@ static int image_new_exec(bContext *C, wmOperator *op) width = RNA_int_get(op->ptr, "width"); height = RNA_int_get(op->ptr, "height"); floatbuf = RNA_boolean_get(op->ptr, "float"); - uvtestgrid = RNA_boolean_get(op->ptr, "uv_test_grid"); + gen_type = RNA_enum_get(op->ptr, "generated_type"); RNA_float_get_array(op->ptr, "color", color); alpha = RNA_boolean_get(op->ptr, "alpha"); @@ -1607,7 +1607,7 @@ static int image_new_exec(bContext *C, wmOperator *op) if (!alpha) color[3] = 1.0f; - ima = BKE_image_add_generated(width, height, name, alpha ? 32 : 24, floatbuf, uvtestgrid, color); + ima = BKE_image_add_generated(width, height, name, alpha ? 32 : 24, floatbuf, gen_type, color); if (!ima) return OPERATOR_CANCELLED; @@ -1664,7 +1664,8 @@ void IMAGE_OT_new(wmOperatorType *ot) prop = RNA_def_float_color(ot->srna, "color", 4, NULL, 0.0f, FLT_MAX, "Color", "Default fill color", 0.0f, 1.0f); RNA_def_property_float_array_default(prop, default_color); RNA_def_boolean(ot->srna, "alpha", 1, "Alpha", "Create an image with an alpha channel"); - RNA_def_boolean(ot->srna, "uv_test_grid", 0, "UV Test Grid", "Fill the image with a grid for UV map testing"); + RNA_def_enum(ot->srna, "generated_type", image_generated_type_items, IMA_GENTYPE_BLANK, + "Generated Type", "Fill the image with a grid for UV map testing"); RNA_def_boolean(ot->srna, "float", 0, "32 bit Float", "Create image with 32 bit floating point bit depth"); } diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index d2639edb276..91a0cba2555 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -392,11 +392,12 @@ static void image_refresh(const bContext *C, ScrArea *sa) else if (obedit && obedit->type == OB_MESH) { Mesh *me = (Mesh *)obedit->data; struct BMEditMesh *em = me->edit_btmesh; - int sloppy = 1; /* partially selected face is ok */ + int sloppy = TRUE; /* partially selected face is ok */ + int selected = !(scene->toolsettings->uv_flag & UV_SYNC_SELECTION); /* only selected active face? */ if (BKE_scene_use_new_shading_nodes(scene)) { /* new shading system, get image from material */ - BMFace *efa = BM_active_face_get(em->bm, sloppy); + BMFace *efa = BM_active_face_get(em->bm, sloppy, selected); if (efa) { Image *node_ima; @@ -413,8 +414,8 @@ static void image_refresh(const bContext *C, ScrArea *sa) if (em && EDBM_mtexpoly_check(em)) { sima->image = NULL; - tf = EDBM_mtexpoly_active_get(em, NULL, TRUE); /* partially selected face is ok */ - + tf = EDBM_mtexpoly_active_get(em, NULL, sloppy, selected); + if (tf) { /* don't need to check for pin here, see above */ sima->image = tf->tpage; @@ -681,10 +682,13 @@ static void image_main_area_draw(const bContext *C, ARegion *ar) if (mask) { int width, height; + float aspx, aspy; ED_space_image_get_size(sima, &width, &height); + ED_space_image_get_aspect(sima, &aspx, &aspy); ED_mask_draw_region(mask, ar, sima->mask_info.draw_flag, sima->mask_info.draw_type, width, height, + aspx, aspy, TRUE, FALSE, NULL, C); diff --git a/source/blender/editors/space_info/info_stats.c b/source/blender/editors/space_info/info_stats.c index 7870e64228a..4ffa99319c4 100644 --- a/source/blender/editors/space_info/info_stats.c +++ b/source/blender/editors/space_info/info_stats.c @@ -70,7 +70,8 @@ typedef struct SceneStats { static void stats_object(Object *ob, int sel, int totob, SceneStats *stats) { switch (ob->type) { - case OB_MESH: { + case OB_MESH: + { /* we assume derivedmesh is already built, this strictly does stats now. */ DerivedMesh *dm = ob->derivedFinal; int totvert, totedge, totface; @@ -101,7 +102,8 @@ static void stats_object(Object *ob, int sel, int totob, SceneStats *stats) break; case OB_SURF: case OB_CURVE: - case OB_FONT: { + case OB_FONT: + { int tot = 0, totf = 0; stats->totcurve += totob; @@ -121,7 +123,8 @@ static void stats_object(Object *ob, int sel, int totob, SceneStats *stats) } break; } - case OB_MBALL: { + case OB_MBALL: + { int tot = 0, totf = 0; BKE_displist_count(&ob->disp, &tot, &totf); diff --git a/source/blender/editors/space_logic/logic_window.c b/source/blender/editors/space_logic/logic_window.c index 08e0934e8ae..6ffac1dcd34 100644 --- a/source/blender/editors/space_logic/logic_window.c +++ b/source/blender/editors/space_logic/logic_window.c @@ -878,7 +878,7 @@ static ID **get_selected_and_linked_obs(bContext *C, short *count, short scavisf } /* 4th case: select actuator when controller selected */ - if ( (scavisflag & (BUTS_ACT_LINK|BUTS_ACT_STATE)) && (ob->scavisflag & OB_VIS_CONT)) { + if ((scavisflag & (BUTS_ACT_LINK|BUTS_ACT_STATE)) && (ob->scavisflag & OB_VIS_CONT)) { cont= ob->controllers.first; while (cont) { for (a=0; a<cont->totlinks; a++) { @@ -921,7 +921,7 @@ static ID **get_selected_and_linked_obs(bContext *C, short *count, short scavisf } while (ob) { - if ( (ob->scavisflag) && (ob != obact)) { + if ((ob->scavisflag) && (ob != obact)) { idar[nr]= (ID *)ob; nr++; } @@ -2162,7 +2162,7 @@ static short draw_actuatorbuttons(Main *bmain, Object *ob, bActuator *act, uiBlo 0.0, 1.0, 0, 0, "Sets the volume of this sound"); uiDefButF(block, NUM, 0, "Pitch:", xco+wval+10, yco-66, wval, 19, &sa->pitch, -12.0, 12.0, 0, 0, "Sets the pitch of this sound"); - uiDefButS(block, TOG | BIT, 0, "3D Sound", xco+10, yco-88, width-20, 19, + uiDefButS(block, TOG | UI_BUT_POIN_BIT, 0, "3D Sound", xco+10, yco-88, width-20, 19, &sa->flag, 0.0, 1.0, 0.0, 0.0, "Plays the sound positioned in 3D space"); if (sa->flag & ACT_SND_3D_SOUND) { uiDefButF(block, NUM, 0, "Minimum Gain: ", xco+10, yco-110, wval, 19, @@ -3398,7 +3398,13 @@ static void draw_sensor_message(uiLayout *layout, PointerRNA *ptr) static void draw_sensor_mouse(uiLayout *layout, PointerRNA *ptr) { - uiItemR(layout, ptr, "mouse_event", 0, NULL, ICON_NONE); + uiLayout *split; + + split = uiLayoutSplit(layout, 0.8f, FALSE); + uiItemR(split, ptr, "mouse_event", 0, NULL, ICON_NONE); + + if (RNA_enum_get(ptr, "mouse_event") == BL_SENS_MOUSE_MOUSEOVER_ANY) + uiItemR(split, ptr, "use_pulse", UI_ITEM_R_TOGGLE, NULL, ICON_NONE); } static void draw_sensor_near(uiLayout *layout, PointerRNA *ptr) @@ -4352,38 +4358,38 @@ static void draw_actuator_steering(uiLayout *layout, PointerRNA *ptr) uiLayout *row; uiLayout *col; - uiItemR(layout, ptr, "mode", 0, NULL, 0); - uiItemR(layout, ptr, "target", 0, NULL, 0); - uiItemR(layout, ptr, "navmesh", 0, NULL, 0); + uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "target", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "navmesh", 0, NULL, ICON_NONE); row = uiLayoutRow(layout, FALSE); - uiItemR(row, ptr, "distance", 0, NULL, 0); - uiItemR(row, ptr, "velocity", 0, NULL, 0); + uiItemR(row, ptr, "distance", 0, NULL, ICON_NONE); + uiItemR(row, ptr, "velocity", 0, NULL, ICON_NONE); row = uiLayoutRow(layout, FALSE); - uiItemR(row, ptr, "acceleration", 0, NULL, 0); - uiItemR(row, ptr, "turn_speed", 0, NULL, 0); + uiItemR(row, ptr, "acceleration", 0, NULL, ICON_NONE); + uiItemR(row, ptr, "turn_speed", 0, NULL, ICON_NONE); row = uiLayoutRow(layout, FALSE); col = uiLayoutColumn(row, FALSE); - uiItemR(col, ptr, "facing", 0, NULL, 0); + uiItemR(col, ptr, "facing", 0, NULL, ICON_NONE); col = uiLayoutColumn(row, FALSE); - uiItemR(col, ptr, "facing_axis", 0, NULL, 0); + uiItemR(col, ptr, "facing_axis", 0, NULL, ICON_NONE); if (!RNA_boolean_get(ptr, "facing")) { uiLayoutSetActive(col, FALSE); } col = uiLayoutColumn(row, FALSE); - uiItemR(col, ptr, "normal_up", 0, NULL, 0); + uiItemR(col, ptr, "normal_up", 0, NULL, ICON_NONE); if (!RNA_pointer_get(ptr, "navmesh").data) { uiLayoutSetActive(col, FALSE); } row = uiLayoutRow(layout, FALSE); - uiItemR(row, ptr, "self_terminated", 0, NULL, 0); + uiItemR(row, ptr, "self_terminated", 0, NULL, ICON_NONE); if (RNA_enum_get(ptr, "mode")==ACT_STEERING_PATHFOLLOWING) { - uiItemR(row, ptr, "update_period", 0, NULL, 0); + uiItemR(row, ptr, "update_period", 0, NULL, ICON_NONE); row = uiLayoutRow(layout, FALSE); } - uiItemR(row, ptr, "show_visualization", 0, NULL, 0); + uiItemR(row, ptr, "show_visualization", 0, NULL, ICON_NONE); } static void draw_brick_actuator(uiLayout *layout, PointerRNA *ptr, bContext *C) @@ -4539,7 +4545,9 @@ static void logic_buttons_new(bContext *C, ARegion *ar) ob= (Object *)idar[a]; /* only draw the controller common header if "use_visible" */ - if ( (ob->scavisflag & OB_VIS_CONT) == 0) continue; + if ( (ob->scavisflag & OB_VIS_CONT) == 0) { + continue; + } /* Drawing the Controller Header common to all Selected Objects */ @@ -4707,7 +4715,9 @@ static void logic_buttons_new(bContext *C, ARegion *ar) ob= (Object *)idar[a]; /* only draw the actuator common header if "use_visible" */ - if ( (ob->scavisflag & OB_VIS_ACT) == 0) continue; + if ((ob->scavisflag & OB_VIS_ACT) == 0) { + continue; + } row = uiLayoutRow(layout, TRUE); uiDefButBitS(block, TOG, OB_SHOWACT, B_REDR, ob->id.name+2, (short)(xco-10), yco, (short)(width-30), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide actuators"); @@ -4834,7 +4844,9 @@ void logic_buttons(bContext *C, ARegion *ar) ob= (Object *)idar[a]; // uiClearButLock(); // uiSetButLock(BKE_object_is_libdata(ob), ERROR_LIBDATA_MESSAGE); - if ( (ob->scavisflag & OB_VIS_CONT) == 0) continue; + if ((ob->scavisflag & OB_VIS_CONT) == 0) { + continue; + } /* presume it is only objects for now */ uiBlockBeginAlign(block); @@ -4972,7 +4984,9 @@ void logic_buttons(bContext *C, ARegion *ar) // uiClearButLock(); // uiSetButLock(BKE_object_is_libdata(ob), ERROR_LIBDATA_MESSAGE); - if ( (ob->scavisflag & OB_VIS_SENS) == 0) continue; + if ((ob->scavisflag & OB_VIS_SENS) == 0) { + continue; + } /* presume it is only objects for now */ uiBlockBeginAlign(block); @@ -5052,7 +5066,9 @@ void logic_buttons(bContext *C, ARegion *ar) ob= (Object *)idar[a]; // uiClearButLock(); // uiSetButLock(BKE_object_is_libdata(ob), ERROR_LIBDATA_MESSAGE); - if ( (ob->scavisflag & OB_VIS_ACT) == 0) continue; + if ((ob->scavisflag & OB_VIS_ACT) == 0) { + continue; + } /* presume it is only objects for now */ uiBlockBeginAlign(block); diff --git a/source/blender/editors/space_nla/nla_select.c b/source/blender/editors/space_nla/nla_select.c index e7610210881..222c2414fcb 100644 --- a/source/blender/editors/space_nla/nla_select.c +++ b/source/blender/editors/space_nla/nla_select.c @@ -245,8 +245,8 @@ static void borderselect_nla_strips(bAnimContext *ac, rcti rect, short mode, sho ymin = ymax - NLACHANNEL_STEP(snla); /* perform vertical suitability check (if applicable) */ - if ( (mode == NLA_BORDERSEL_FRAMERANGE) || - !((ymax < rectf.ymin) || (ymin > rectf.ymax)) ) + if ((mode == NLA_BORDERSEL_FRAMERANGE) || + !((ymax < rectf.ymin) || (ymin > rectf.ymax))) { /* loop over data selecting (only if NLA-Track) */ if (ale->type == ANIMTYPE_NLATRACK) { @@ -255,8 +255,8 @@ static void borderselect_nla_strips(bAnimContext *ac, rcti rect, short mode, sho /* only select strips if they fall within the required ranges (if applicable) */ for (strip = nlt->strips.first; strip; strip = strip->next) { - if ( (mode == NLA_BORDERSEL_CHANNELS) || - BKE_nlastrip_within_bounds(strip, rectf.xmin, rectf.xmax)) + if ((mode == NLA_BORDERSEL_CHANNELS) || + BKE_nlastrip_within_bounds(strip, rectf.xmin, rectf.xmax)) { /* set selection */ ACHANNEL_SET_FLAG(strip, selectmode, NLASTRIP_FLAG_SELECT); diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 8a1f0e5b611..5ebcef1d9a7 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -171,7 +171,7 @@ static void node_socket_button_color(const bContext *C, uiBlock *block, int labelw = width - 40; RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr); - bt = uiDefButR(block, COL, B_NODE_EXEC, "", + bt = uiDefButR(block, COLOR, B_NODE_EXEC, "", x, y + 2, (labelw > 0 ? 40 : width), NODE_DY - 2, &ptr, "default_value", 0, 0, 0, -1, -1, NULL); if (node) @@ -647,23 +647,22 @@ static void update_group_output_cb(bContext *UNUSED(C), void *UNUSED(snode_v), v static void draw_group_socket_name(SpaceNode *snode, bNode *gnode, bNodeSocket *sock, int in_out, float xoffset, float yoffset) { - bNodeTree *ngroup = (bNodeTree *)gnode->id; - uiBut *bt; - const char *ui_name = IFACE_(sock->name); - if (sock->flag & SOCK_DYNAMIC) { - bt = uiDefBut(gnode->block, TEX, 0, "", - sock->locx + xoffset, sock->locy + 1 + yoffset, 72, NODE_DY, - sock->name, 0, sizeof(sock->name), 0, 0, ""); + bNodeTree *ngroup = (bNodeTree *)gnode->id; + uiBut *but; + but = uiDefBut(gnode->block, TEX, 0, "", + sock->locx + xoffset, sock->locy + 1 + yoffset, 72, NODE_DY, + sock->name, 0, sizeof(sock->name), 0, 0, ""); if (in_out == SOCK_IN) - uiButSetFunc(bt, update_group_input_cb, snode, ngroup); + uiButSetFunc(but, update_group_input_cb, snode, ngroup); else - uiButSetFunc(bt, update_group_output_cb, snode, ngroup); + uiButSetFunc(but, update_group_output_cb, snode, ngroup); } else { + const char *ui_name = IFACE_(sock->name); uiDefBut(gnode->block, LABEL, 0, ui_name, sock->locx + xoffset, sock->locy + 1 + yoffset, 72, NODE_DY, - NULL, 0, sizeof(ui_name), 0, 0, ""); + NULL, 0, 0, 0, 0, ""); } } @@ -900,7 +899,7 @@ void node_uifunc_group(uiLayout *layout, bContext *C, PointerRNA *ptr) static void node_common_buts_whileloop(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "max_iterations", 0, NULL, 0); + uiItemR(layout, ptr, "max_iterations", 0, NULL, ICON_NONE); } /* XXX Does a bounding box update by iterating over all children. @@ -1324,6 +1323,11 @@ static void node_shader_buts_tex_image(uiLayout *layout, bContext *C, PointerRNA uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL); uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE); + uiItemR(layout, ptr, "projection", 0, "", ICON_NONE); + + if (RNA_enum_get(ptr, "projection") == SHD_PROJ_BOX) { + uiItemR(layout, ptr, "projection_blend", 0, "Blend", ICON_NONE); + } /* note: image user properties used directly here, unlike compositor image node, * which redefines them in the node struct RNA to get proper updates. @@ -1359,6 +1363,19 @@ static void node_shader_buts_tex_magic(uiLayout *layout, bContext *UNUSED(C), Po uiItemR(layout, ptr, "turbulence_depth", 0, NULL, ICON_NONE); } +static void node_shader_buts_tex_brick(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +{ + uiLayout *col; + + col = uiLayoutColumn(layout, TRUE); + uiItemR(col, ptr, "offset", 0, IFACE_("Offset"), ICON_NONE); + uiItemR(col, ptr, "offset_frequency", 0, IFACE_("Frequency"), ICON_NONE); + + col = uiLayoutColumn(layout, TRUE); + uiItemR(col, ptr, "squash", 0, IFACE_("Squash"), ICON_NONE); + uiItemR(col, ptr, "squash_frequency", 0, IFACE_("Frequency"), ICON_NONE); +} + static void node_shader_buts_tex_wave(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { uiItemR(layout, ptr, "wave_type", 0, "", ICON_NONE); @@ -1443,6 +1460,9 @@ static void node_shader_set_butfunc(bNodeType *ntype) case SH_NODE_TEX_MAGIC: ntype->uifunc = node_shader_buts_tex_magic; break; + case SH_NODE_TEX_BRICK: + ntype->uifunc = node_shader_buts_tex_brick; + break; case SH_NODE_TEX_WAVE: ntype->uifunc = node_shader_buts_tex_wave; break; @@ -1534,9 +1554,9 @@ static void node_composit_buts_blur(uiLayout *layout, bContext *UNUSED(C), Point uiItemR(col, ptr, "use_relative", 0, NULL, ICON_NONE); if (RNA_boolean_get(ptr, "use_relative")) { - uiItemL(col, IFACE_("Aspect Correction"), 0); + uiItemL(col, IFACE_("Aspect Correction"), ICON_NONE); row = uiLayoutRow(layout, TRUE); - uiItemR(row, ptr, "aspect_correction", UI_ITEM_R_EXPAND, NULL, 0); + uiItemR(row, ptr, "aspect_correction", UI_ITEM_R_EXPAND, NULL, ICON_NONE); col = uiLayoutColumn(layout, TRUE); uiItemR(col, ptr, "factor_x", 0, IFACE_("X"), ICON_NONE); @@ -1960,7 +1980,7 @@ static void node_draw_input_file_output(const bContext *C, uiBlock *block, NodeImageMultiFileSocket *input = sock->storage; RNA_pointer_create(&ntree->id, &RNA_NodeOutputFileSlotLayer, input, &inputptr); - uiItemL(row, input->layer, 0); + uiItemL(row, input->layer, ICON_NONE); } else { NodeImageMultiFileSocket *input = sock->storage; @@ -1968,7 +1988,7 @@ static void node_draw_input_file_output(const bContext *C, uiBlock *block, const char *imtype_name; RNA_pointer_create(&ntree->id, &RNA_NodeOutputFileSlotFile, input, &inputptr); - uiItemL(row, input->path, 0); + uiItemL(row, input->path, ICON_NONE); if (!RNA_boolean_get(&inputptr, "use_node_format")) imfptr = RNA_pointer_get(&inputptr, "format"); @@ -1977,7 +1997,7 @@ static void node_draw_input_file_output(const bContext *C, uiBlock *block, RNA_property_enum_name((bContext *)C, &imfptr, imtype_prop, RNA_property_enum_get(&imfptr, imtype_prop), &imtype_name); uiBlockSetEmboss(block, UI_EMBOSSP); - uiItemL(row, imtype_name, 0); + uiItemL(row, imtype_name, ICON_NONE); uiBlockSetEmboss(block, UI_EMBOSSN); } @@ -1989,9 +2009,9 @@ static void node_composit_buts_file_output(uiLayout *layout, bContext *UNUSED(C) int multilayer = (RNA_enum_get(&imfptr, "file_format") == R_IMF_IMTYPE_MULTILAYER); if (multilayer) - uiItemL(layout, IFACE_("Path:"), 0); + uiItemL(layout, IFACE_("Path:"), ICON_NONE); else - uiItemL(layout, IFACE_("Base Path:"), 0); + uiItemL(layout, IFACE_("Base Path:"), ICON_NONE); uiItemR(layout, ptr, "base_path", 0, "", ICON_NONE); } static void node_composit_buts_file_output_details(uiLayout *layout, bContext *C, PointerRNA *ptr) @@ -2037,9 +2057,9 @@ static void node_composit_buts_file_output_details(uiLayout *layout, bContext *C uiLayout *row, *col; col = uiLayoutColumn(layout, TRUE); - uiItemL(col, IFACE_("Layer:"), 0); + uiItemL(col, IFACE_("Layer:"), ICON_NONE); row = uiLayoutRow(col, FALSE); - uiItemR(row, &active_input_ptr, "name", 0, "", 0); + uiItemR(row, &active_input_ptr, "name", 0, "", ICON_NONE); uiItemFullO(row, "NODE_OT_output_file_remove_active_socket", "", ICON_X, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_R_ICON_ONLY); } @@ -2047,9 +2067,9 @@ static void node_composit_buts_file_output_details(uiLayout *layout, bContext *C uiLayout *row, *col; col = uiLayoutColumn(layout, TRUE); - uiItemL(col, IFACE_("File Path:"), 0); + uiItemL(col, IFACE_("File Path:"), ICON_NONE); row = uiLayoutRow(col, FALSE); - uiItemR(row, &active_input_ptr, "path", 0, "", 0); + uiItemR(row, &active_input_ptr, "path", 0, "", ICON_NONE); uiItemFullO(row, "NODE_OT_output_file_remove_active_socket", "", ICON_X, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_R_ICON_ONLY); @@ -2057,8 +2077,8 @@ static void node_composit_buts_file_output_details(uiLayout *layout, bContext *C imfptr = RNA_pointer_get(&active_input_ptr, "format"); col = uiLayoutColumn(layout, TRUE); - uiItemL(col, IFACE_("Format:"), 0); - uiItemR(col, &active_input_ptr, "use_node_format", 0, NULL, 0); + uiItemL(col, IFACE_("Format:"), ICON_NONE); + uiItemR(col, &active_input_ptr, "use_node_format", 0, NULL, ICON_NONE); col = uiLayoutColumn(layout, FALSE); uiLayoutSetActive(col, RNA_boolean_get(&active_input_ptr, "use_node_format") == FALSE); @@ -2212,12 +2232,12 @@ static void node_composit_buts_stabilize2d(uiLayout *layout, bContext *C, Pointe if (!node->id) return; - uiItemR(layout, ptr, "filter_type", 0, "", 0); + uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE); } static void node_composit_buts_transform(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "filter_type", 0, "", 0); + uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE); } static void node_composit_buts_moviedistortion(uiLayout *layout, bContext *C, PointerRNA *ptr) @@ -2229,7 +2249,7 @@ static void node_composit_buts_moviedistortion(uiLayout *layout, bContext *C, Po if (!node->id) return; - uiItemR(layout, ptr, "distortion_type", 0, "", 0); + uiItemR(layout, ptr, "distortion_type", 0, "", ICON_NONE); } static void node_composit_buts_colorcorrection(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) @@ -2242,15 +2262,15 @@ static void node_composit_buts_colorcorrection(uiLayout *layout, bContext *UNUSE uiItemR(row, ptr, "blue", 0, NULL, ICON_NONE); row = uiLayoutRow(layout, FALSE); - uiItemL(row, "", 0); - uiItemL(row, IFACE_("Saturation"), 0); - uiItemL(row, IFACE_("Contrast"), 0); - uiItemL(row, IFACE_("Gamma"), 0); - uiItemL(row, IFACE_("Gain"), 0); - uiItemL(row, IFACE_("Lift"), 0); + uiItemL(row, "", ICON_NONE); + uiItemL(row, IFACE_("Saturation"), ICON_NONE); + uiItemL(row, IFACE_("Contrast"), ICON_NONE); + uiItemL(row, IFACE_("Gamma"), ICON_NONE); + uiItemL(row, IFACE_("Gain"), ICON_NONE); + uiItemL(row, IFACE_("Lift"), ICON_NONE); row = uiLayoutRow(layout, FALSE); - uiItemL(row, IFACE_("Master"), 0); + uiItemL(row, IFACE_("Master"), ICON_NONE); uiItemR(row, ptr, "master_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE); uiItemR(row, ptr, "master_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE); uiItemR(row, ptr, "master_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE); @@ -2258,7 +2278,7 @@ static void node_composit_buts_colorcorrection(uiLayout *layout, bContext *UNUSE uiItemR(row, ptr, "master_lift", UI_ITEM_R_SLIDER, "", ICON_NONE); row = uiLayoutRow(layout, FALSE); - uiItemL(row, IFACE_("Highlights"), 0); + uiItemL(row, IFACE_("Highlights"), ICON_NONE); uiItemR(row, ptr, "highlights_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE); uiItemR(row, ptr, "highlights_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE); uiItemR(row, ptr, "highlights_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE); @@ -2266,7 +2286,7 @@ static void node_composit_buts_colorcorrection(uiLayout *layout, bContext *UNUSE uiItemR(row, ptr, "highlights_lift", UI_ITEM_R_SLIDER, "", ICON_NONE); row = uiLayoutRow(layout, FALSE); - uiItemL(row, IFACE_("Midtones"), 0); + uiItemL(row, IFACE_("Midtones"), ICON_NONE); uiItemR(row, ptr, "midtones_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE); uiItemR(row, ptr, "midtones_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE); uiItemR(row, ptr, "midtones_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE); @@ -2274,7 +2294,7 @@ static void node_composit_buts_colorcorrection(uiLayout *layout, bContext *UNUSE uiItemR(row, ptr, "midtones_lift", UI_ITEM_R_SLIDER, "", ICON_NONE); row = uiLayoutRow(layout, FALSE); - uiItemL(row, IFACE_("Shadows"), 0); + uiItemL(row, IFACE_("Shadows"), ICON_NONE); uiItemR(row, ptr, "shadows_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE); uiItemR(row, ptr, "shadows_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE); uiItemR(row, ptr, "shadows_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE); @@ -2295,31 +2315,31 @@ static void node_composit_buts_colorcorrection_but(uiLayout *layout, bContext *U uiItemR(row, ptr, "green", 0, NULL, ICON_NONE); uiItemR(row, ptr, "blue", 0, NULL, ICON_NONE); row = layout; - uiItemL(row, IFACE_("Saturation"), 0); + uiItemL(row, IFACE_("Saturation"), ICON_NONE); uiItemR(row, ptr, "master_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "highlights_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "midtones_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "shadows_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemL(row, IFACE_("Contrast"), 0); + uiItemL(row, IFACE_("Contrast"), ICON_NONE); uiItemR(row, ptr, "master_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "highlights_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "midtones_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "shadows_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemL(row, IFACE_("Gamma"), 0); + uiItemL(row, IFACE_("Gamma"), ICON_NONE); uiItemR(row, ptr, "master_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "highlights_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "midtones_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "shadows_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemL(row, IFACE_("Gain"), 0); + uiItemL(row, IFACE_("Gain"), ICON_NONE); uiItemR(row, ptr, "master_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "highlights_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "midtones_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "shadows_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemL(row, IFACE_("Lift"), 0); + uiItemL(row, IFACE_("Lift"), ICON_NONE); uiItemR(row, ptr, "master_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "highlights_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "midtones_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); @@ -2570,7 +2590,7 @@ static void node_composit_buts_trackpos(uiLayout *layout, bContext *C, PointerRN RNA_pointer_create(&clip->id, &RNA_MovieTracking, tracking, &tracking_ptr); - col = uiLayoutColumn(layout, 0); + col = uiLayoutColumn(layout, FALSE); uiItemPointerR(col, ptr, "tracking_object", &tracking_ptr, "objects", "", ICON_OBJECT_DATA); object = BKE_tracking_object_get_named(tracking, data->tracking_object); diff --git a/source/blender/editors/space_node/node_buttons.c b/source/blender/editors/space_node/node_buttons.c index e50b1dc4ba6..da077d93641 100644 --- a/source/blender/editors/space_node/node_buttons.c +++ b/source/blender/editors/space_node/node_buttons.c @@ -110,8 +110,8 @@ static void active_node_panel(const bContext *C, Panel *pa) uiItemR(col, &ptr, "use_custom_color", UI_ITEM_R_ICON_ONLY, NULL, ICON_NONE); sub = uiLayoutRow(col, FALSE); if (!(node->flag & NODE_CUSTOM_COLOR)) - uiLayoutSetEnabled(sub, 0); - uiItemR(sub, &ptr, "color", 0, "", 0); + uiLayoutSetEnabled(sub, FALSE); + uiItemR(sub, &ptr, "color", 0, "", ICON_NONE); col = uiLayoutColumn(row, TRUE); uiItemO(col, "", ICON_ZOOMIN, "node.node_color_preset_add"); diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index fbae8b17ebf..9e04bd36a1f 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -309,7 +309,8 @@ void ED_node_shader_default(Scene *scene, ID *id) ntree = ntreeAddTree("Shader Nodetree", NTREE_SHADER, 0); switch (GS(id->name)) { - case ID_MA: { + case ID_MA: + { Material *ma = (Material *)id; ma->nodetree = ntree; @@ -326,7 +327,8 @@ void ED_node_shader_default(Scene *scene, ID *id) strength = 0.0f; break; } - case ID_WO: { + case ID_WO: + { World *wo = (World *)id; wo->nodetree = ntree; @@ -337,7 +339,8 @@ void ED_node_shader_default(Scene *scene, ID *id) strength = 1.0f; break; } - case ID_LA: { + case ID_LA: + { Lamp *la = (Lamp *)id; la->nodetree = ntree; @@ -1456,7 +1459,7 @@ static void node_flag_toggle_exec(SpaceNode *snode, int toggle_flag) if (toggle_flag == NODE_OPTIONS && (node->typeinfo->flag & NODE_OPTIONS) == 0) continue; - if ( (tot_eq && tot_neq) || tot_eq == 0) + if ((tot_eq && tot_neq) || tot_eq == 0) node->flag |= toggle_flag; else node->flag &= ~toggle_flag; diff --git a/source/blender/editors/space_node/node_group.c b/source/blender/editors/space_node/node_group.c index 77583ae1325..b76cc05af5c 100644 --- a/source/blender/editors/space_node/node_group.c +++ b/source/blender/editors/space_node/node_group.c @@ -950,7 +950,7 @@ static int node_group_make_insert_selected(bNodeTree *ntree, bNode *gnode) int toselect = (link->tonode && (link->tonode->flag & NODE_SELECT) && link->tonode != gnode); linkn = link->next; - if (gnode && ((fromselect && link->tonode == gnode) || (toselect && link->fromnode == gnode))) { + if ((fromselect && link->tonode == gnode) || (toselect && link->fromnode == gnode)) { /* remove all links to/from the gnode. * this can remove link information, but there's no general way to preserve it. */ diff --git a/source/blender/editors/space_node/node_header.c b/source/blender/editors/space_node/node_header.c index f461174d74f..e17961b6c7c 100644 --- a/source/blender/editors/space_node/node_header.c +++ b/source/blender/editors/space_node/node_header.c @@ -41,6 +41,7 @@ #include "BLF_translation.h" +#include "BKE_blender.h" #include "BKE_context.h" #include "BKE_global.h" #include "BKE_main.h" @@ -64,7 +65,7 @@ static void do_node_add(bContext *C, bNodeTemplate *ntemp) SpaceNode *snode = CTX_wm_space_node(C); ScrArea *sa = CTX_wm_area(C); ARegion *ar; - bNode *node; + bNode *node, *node_new; /* get location to add node at mouse */ for (ar = sa->regionbase.first; ar; ar = ar->next) { @@ -84,7 +85,7 @@ static void do_node_add(bContext *C, bNodeTemplate *ntemp) else node->flag &= ~NODE_TEST; } - /* node= */ node_add_node(snode, bmain, scene, ntemp, snode->cursor[0], snode->cursor[1]); + node_new = node_add_node(snode, bmain, scene, ntemp, snode->cursor[0], snode->cursor[1]); /* select previous selection before autoconnect */ for (node = snode->edittree->nodes.first; node; node = node->next) { @@ -95,7 +96,14 @@ static void do_node_add(bContext *C, bNodeTemplate *ntemp) for (node = snode->edittree->nodes.first; node; node = node->next) { if (node->flag & NODE_TEST) node->flag &= ~NODE_SELECT; } - + + /* once this is called from an operator, this should be removed */ + if (node_new) { + char undostr[BKE_UNDO_STR_MAX]; + BLI_snprintf(undostr, sizeof(BKE_UNDO_STR_MAX), "Add Node %s", nodeLabel(node_new)); + BKE_write_undo(C, undostr); + } + snode_notify(C, snode); snode_dag_update(C, snode); } diff --git a/source/blender/editors/space_node/node_relationships.c b/source/blender/editors/space_node/node_relationships.c index 12c221b9273..fec7366ee73 100644 --- a/source/blender/editors/space_node/node_relationships.c +++ b/source/blender/editors/space_node/node_relationships.c @@ -560,7 +560,8 @@ static int node_link_modal(bContext *C, wmOperator *op, wmEvent *event) case LEFTMOUSE: case RIGHTMOUSE: - case MIDDLEMOUSE: { + case MIDDLEMOUSE: + { for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { link = linkdata->data; diff --git a/source/blender/editors/space_node/node_templates.c b/source/blender/editors/space_node/node_templates.c index 989b3999018..7881014ed54 100644 --- a/source/blender/editors/space_node/node_templates.c +++ b/source/blender/editors/space_node/node_templates.c @@ -627,11 +627,11 @@ static void ui_node_draw_input(uiLayout *layout, bContext *C, bNodeTree *ntree, row = uiLayoutRow(split, FALSE); col = uiLayoutColumn(row, FALSE); - uiItemR(col, &inputptr, "default_value", 0, "", 0); + uiItemR(col, &inputptr, "default_value", 0, "", ICON_NONE); } else { row = uiLayoutRow(split, TRUE); - uiItemR(row, &inputptr, "default_value", 0, "", 0); + uiItemR(row, &inputptr, "default_value", 0, "", ICON_NONE); } } else diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index 42fdd5173d4..21e06f00d8e 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -1273,8 +1273,8 @@ static void outliner_draw_tree_element(bContext *C, uiBlock *block, Scene *scene * we don't expand items when searching in the datablocks but we * still want to highlight any filter matches. */ - if ( (SEARCHING_OUTLINER(soops) || (soops->outlinevis == SO_DATABLOCKS && soops->search_string[0] != 0)) && - (tselem->flag & TSE_SEARCHMATCH)) + if ((SEARCHING_OUTLINER(soops) || (soops->outlinevis == SO_DATABLOCKS && soops->search_string[0] != 0)) && + (tselem->flag & TSE_SEARCHMATCH)) { char col[4]; UI_GetThemeColorType4ubv(TH_MATCH, SPACE_OUTLINER, col); diff --git a/source/blender/editors/space_outliner/outliner_tree.c b/source/blender/editors/space_outliner/outliner_tree.c index 63907f530eb..3e1ce1fea6e 100644 --- a/source/blender/editors/space_outliner/outliner_tree.c +++ b/source/blender/editors/space_outliner/outliner_tree.c @@ -1216,8 +1216,8 @@ static int treesort_obtype_alpha(const void *v1, const void *v2) else { /* 2nd we check ob type */ if (x1->idcode == ID_OB && x2->idcode == ID_OB) { - if ( ((Object *)x1->id)->type > ((Object *)x2->id)->type) return 1; - else if ( ((Object *)x1->id)->type > ((Object *)x2->id)->type) return -1; + if (((Object *)x1->id)->type > ((Object *)x2->id)->type) return 1; + else if (((Object *)x1->id)->type > ((Object *)x2->id)->type) return -1; else return 0; } else { @@ -1243,7 +1243,7 @@ static void outliner_sort(SpaceOops *soops, ListBase *lb) tselem = TREESTORE(te); /* sorting rules; only object lists or deformgroups */ - if ( (tselem->type == TSE_DEFGROUP) || (tselem->type == 0 && te->idcode == ID_OB)) { + if ((tselem->type == TSE_DEFGROUP) || (tselem->type == 0 && te->idcode == ID_OB)) { /* count first */ for (te = lb->first; te; te = te->next) totelem++; diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index d6a2b0a001e..0c316450c29 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -852,7 +852,7 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq struct ImBuf *ibuf = NULL; struct ImBuf *scope = NULL; struct View2D *v2d = &ar->v2d; - int rectx, recty; + /* int rectx, recty; */ /* UNUSED */ float viewrectx, viewrecty; float render_size = 0.0; float proxy_size = 100.0; @@ -874,8 +874,8 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq viewrectx = (render_size * (float)scene->r.xsch) / 100.0f; viewrecty = (render_size * (float)scene->r.ysch) / 100.0f; - rectx = viewrectx + 0.5f; - recty = viewrecty + 0.5f; + /* rectx = viewrectx + 0.5f; */ /* UNUSED */ + /* recty = viewrecty + 0.5f; */ /* UNUSED */ if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) { viewrectx *= scene->r.xasp / scene->r.yasp; @@ -1049,6 +1049,7 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq if (mask) { int width, height; + float aspx = 1.0f, aspy = 1.0f; // ED_mask_get_size(C, &width, &height); //Scene *scene = CTX_data_scene(C); @@ -1058,6 +1059,7 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq ED_mask_draw_region(mask, ar, 0, 0, /* TODO */ width, height, + aspx, aspy, FALSE, TRUE, NULL, C); } diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index 5a40c2ce4e7..f47eb339878 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -170,7 +170,7 @@ static void proxy_endjob(void *pjv) BKE_sequencer_proxy_rebuild_finish(link->data, pj->stop); } - BKE_sequencer_free_imbuf(pj->scene, &ed->seqbase, FALSE, FALSE); + BKE_sequencer_free_imbuf(pj->scene, &ed->seqbase, FALSE); WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, pj->scene); } @@ -381,8 +381,8 @@ Sequence *find_nearest_seq(Scene *scene, View2D *v2d, int *hand, const int mval[ while (seq) { if (seq->machine == (int)y) { /* check for both normal strips, and strips that have been flipped horizontally */ - if ( ((seq->startdisp < seq->enddisp) && (seq->startdisp <= x && seq->enddisp >= x)) || - ((seq->startdisp > seq->enddisp) && (seq->startdisp >= x && seq->enddisp <= x)) ) + if (((seq->startdisp < seq->enddisp) && (seq->startdisp <= x && seq->enddisp >= x)) || + ((seq->startdisp > seq->enddisp) && (seq->startdisp >= x && seq->enddisp <= x)) ) { if (BKE_sequence_tx_test(seq)) { @@ -1141,12 +1141,16 @@ static int sequencer_mute_exec(bContext *C, wmOperator *op) for (seq = ed->seqbasep->first; seq; seq = seq->next) { if ((seq->flag & SEQ_LOCK) == 0) { if (selected) { /* mute unselected */ - if (seq->flag & SELECT) + if (seq->flag & SELECT) { seq->flag |= SEQ_MUTE; + BKE_sequence_invalidate_deendent(scene, seq); + } } else { - if ((seq->flag & SELECT) == 0) + if ((seq->flag & SELECT) == 0) { seq->flag |= SEQ_MUTE; + BKE_sequence_invalidate_deendent(scene, seq); + } } } } @@ -1188,12 +1192,16 @@ static int sequencer_unmute_exec(bContext *C, wmOperator *op) for (seq = ed->seqbasep->first; seq; seq = seq->next) { if ((seq->flag & SEQ_LOCK) == 0) { if (selected) { /* unmute unselected */ - if (seq->flag & SELECT) + if (seq->flag & SELECT) { seq->flag &= ~SEQ_MUTE; + BKE_sequence_invalidate_deendent(scene, seq); + } } else { - if ((seq->flag & SELECT) == 0) + if ((seq->flag & SELECT) == 0) { seq->flag &= ~SEQ_MUTE; + BKE_sequence_invalidate_deendent(scene, seq); + } } } } @@ -1340,7 +1348,7 @@ static int sequencer_refresh_all_exec(bContext *C, wmOperator *UNUSED(op)) Scene *scene = CTX_data_scene(C); Editing *ed = BKE_sequencer_editing_get(scene, FALSE); - BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE, FALSE); + BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -2447,7 +2455,7 @@ static Sequence *sequence_find_parent(Scene *scene, Sequence *child) if (ed == NULL) return NULL; for (seq = ed->seqbasep->first; seq; seq = seq->next) { - if ( (seq != child) && seq_is_parent(seq, child) ) { + if ((seq != child) && seq_is_parent(seq, child)) { parent = seq; break; } @@ -2563,7 +2571,7 @@ static int sequencer_rendersize_exec(bContext *C, wmOperator *UNUSED(op)) if (se) { // prevent setting the render size if sequence values aren't initialized - if ( (se->orig_width > 0) && (se->orig_height > 0) ) { + if ((se->orig_width > 0) && (se->orig_height > 0)) { scene->r.xsch = se->orig_width; scene->r.ysch = se->orig_height; WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene); @@ -2903,7 +2911,7 @@ static int sequencer_change_effect_input_exec(bContext *C, wmOperator *op) BKE_sequencer_update_changed_seq_and_deps(scene, seq, 0, 1); /* important else we don't get the imbuf cache flushed */ - BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE, FALSE); + BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -2963,7 +2971,7 @@ static int sequencer_change_effect_type_exec(bContext *C, wmOperator *op) BKE_sequencer_update_changed_seq_and_deps(scene, seq, 0, 1); /* important else we don't get the imbuf cache flushed */ - BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE, FALSE); + BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -3036,7 +3044,7 @@ static int sequencer_change_path_exec(bContext *C, wmOperator *op) BKE_sequence_calc(scene, seq); /* important else we don't get the imbuf cache flushed */ - BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE, FALSE); + BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE); } else { /* lame, set rna filepath */ diff --git a/source/blender/editors/space_sequencer/sequencer_intern.h b/source/blender/editors/space_sequencer/sequencer_intern.h index f5c3a4c4d89..935bd13fcfc 100644 --- a/source/blender/editors/space_sequencer/sequencer_intern.h +++ b/source/blender/editors/space_sequencer/sequencer_intern.h @@ -118,8 +118,6 @@ void SEQUENCER_OT_paste(struct wmOperatorType *ot); void SEQUENCER_OT_rebuild_proxy(struct wmOperatorType *ot); -void SEQUENCER_OT_update_strip_length(struct wmOperatorType *ot); - /* preview specific operators */ void SEQUENCER_OT_view_all_preview(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_sequencer/sequencer_view.c b/source/blender/editors/space_sequencer/sequencer_view.c index fa39003bd55..d500bef4f02 100644 --- a/source/blender/editors/space_sequencer/sequencer_view.c +++ b/source/blender/editors/space_sequencer/sequencer_view.c @@ -162,8 +162,12 @@ static void sample_exit(bContext *C, wmOperator *op) static int sample_invoke(bContext *C, wmOperator *op, wmEvent *event) { ARegion *ar = CTX_wm_region(C); + SpaceSeq *sseq = CTX_wm_space_seq(C); ImageSampleInfo *info; + if (sseq->mainb != SEQ_DRAW_IMG_IMBUF) + return OPERATOR_CANCELLED; + info = MEM_callocN(sizeof(ImageSampleInfo), "ImageSampleInfo"); info->art = ar->type; info->draw_handle = ED_region_draw_cb_activate(ar->type, sample_draw, info, REGION_DRAW_POST_PIXEL); diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c index a05bc5eddc7..ecce12b8cba 100644 --- a/source/blender/editors/space_view3d/drawarmature.c +++ b/source/blender/editors/space_view3d/drawarmature.c @@ -272,7 +272,7 @@ static short set_pchan_glColor(short colCode, int boneflag, short constflag) case PCHAN_COLOR_LINEBONE: { /* inner part in background color or constraint */ - if ( (constflag) && ((bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS)) ) { + if ((constflag) && ((bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS))) { if (constflag & PCHAN_HAS_TARGET) glColor3ub(255, 150, 0); else if (constflag & PCHAN_HAS_IK) glColor3ub(255, 255, 0); else if (constflag & PCHAN_HAS_SPLINEIK) glColor3ub(200, 255, 0); @@ -1540,7 +1540,7 @@ static void draw_pose_dofs(Object *ob) for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { bone = pchan->bone; - if ( (bone) && !(bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG))) { + if ((bone != NULL) && !(bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG))) { if (bone->flag & BONE_SELECTED) { if (bone->layer & arm->layer) { if (pchan->ikflag & (BONE_IK_XLIMIT | BONE_IK_ZLIMIT)) { @@ -1701,8 +1701,8 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194] * NOTE: this is the only case with (NO_DEFORM == 0) flag, as this is for envelope influence drawing */ - if ( (bone->flag & (BONE_HIDDEN_P | BONE_NO_DEFORM | BONE_HIDDEN_PG)) == 0 && - ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0) ) + if (((bone->flag & (BONE_HIDDEN_P | BONE_NO_DEFORM | BONE_HIDDEN_PG)) == 0) && + ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0)) { if (bone->flag & (BONE_SELECTED)) { if (bone->layer & arm->layer) @@ -1732,8 +1732,8 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, arm->layer_used |= bone->layer; /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194] */ - if ( (bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0 && - ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0) ) + if (((bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0) && + ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0)) { if (bone->layer & arm->layer) { int use_custom = (pchan->custom) && !(arm->flag & ARM_NO_CUSTOM); @@ -1748,8 +1748,9 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, /* catch exception for bone with hidden parent */ flag = bone->flag; - if ( (bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) ) + if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG))) { flag &= ~BONE_CONNECTED; + } /* set temporary flag for drawing bone as active, but only if selected */ if (bone == arm->act_bone) @@ -1819,8 +1820,8 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, bone = pchan->bone; /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194] */ - if ( (bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0 && - ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0) ) + if (((bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0) && + ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0) ) { if (bone->layer & arm->layer) { if (pchan->custom) { @@ -1895,8 +1896,8 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, arm->layer_used |= bone->layer; /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194] */ - if ( (bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0 && - ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0) ) + if (((bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0) && + ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0)) { if (bone->layer & arm->layer) { const short constflag = pchan->constflag; @@ -1904,7 +1905,7 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, /* Draw a line from our root to the parent's tip * - only if V3D_HIDE_HELPLINES is enabled... */ - if ( (do_dashed & 2) && ((bone->flag & BONE_CONNECTED) == 0) ) { + if ((do_dashed & 2) && ((bone->flag & BONE_CONNECTED) == 0)) { if (arm->flag & ARM_POSEMODE) { glLoadName(index & 0xFFFF); /* object tag, for bordersel optim */ UI_ThemeColor(TH_WIRE); @@ -2047,7 +2048,7 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, } /* Draw additional axes on the bone tail */ - if ( (arm->flag & ARM_DRAWAXES) && (arm->flag & ARM_POSEMODE) ) { + if ((arm->flag & ARM_DRAWAXES) && (arm->flag & ARM_POSEMODE)) { glPushMatrix(); copy_m4_m4(bmat, pchan->pose_mat); bone_matrix_translate_y(bmat, pchan->bone->length); @@ -2134,8 +2135,9 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, const short dt) /* catch exception for bone with hidden parent */ flag = eBone->flag; - if ( (eBone->parent) && !EBONE_VISIBLE(arm, eBone->parent)) + if ((eBone->parent) && !EBONE_VISIBLE(arm, eBone->parent)) { flag &= ~BONE_CONNECTED; + } /* set temporary flag for drawing bone as active, but only if selected */ if (eBone == arm->act_edbone) @@ -2176,8 +2178,9 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, const short dt) /* catch exception for bone with hidden parent */ flag = eBone->flag; - if ( (eBone->parent) && !EBONE_VISIBLE(arm, eBone->parent)) + if ((eBone->parent) && !EBONE_VISIBLE(arm, eBone->parent)) { flag &= ~BONE_CONNECTED; + } /* set temporary flag for drawing bone as active, but only if selected */ if (eBone == arm->act_edbone) @@ -2378,7 +2381,11 @@ static void draw_ghost_poses_range(Scene *scene, View3D *v3d, ARegion *ar, Base } glDisable(GL_BLEND); if (v3d->zbuf) glEnable(GL_DEPTH_TEST); - + + /* before disposing of temp pose, use it to restore object to a sane state */ + BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)cfrao, ADT_RECALC_ALL); + + /* clean up temporary pose */ ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */ BKE_pose_free(posen); @@ -2386,7 +2393,6 @@ static void draw_ghost_poses_range(Scene *scene, View3D *v3d, ARegion *ar, Base CFRA = cfrao; ob->pose = poseo; arm->flag = flago; - BKE_pose_rebuild(ob, ob->data); ob->mode |= OB_MODE_POSE; ob->ipoflag = ipoflago; } @@ -2457,7 +2463,11 @@ static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, ARegion *ar, Base * } glDisable(GL_BLEND); if (v3d->zbuf) glEnable(GL_DEPTH_TEST); - + + /* before disposing of temp pose, use it to restore object to a sane state */ + BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)cfrao, ADT_RECALC_ALL); + + /* clean up temporary pose */ ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */ BLI_dlrbTree_free(&keys); BKE_pose_free(posen); @@ -2466,7 +2476,6 @@ static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, ARegion *ar, Base * CFRA = cfrao; ob->pose = poseo; arm->flag = flago; - BKE_pose_rebuild(ob, ob->data); ob->mode |= OB_MODE_POSE; } @@ -2544,7 +2553,11 @@ static void draw_ghost_poses(Scene *scene, View3D *v3d, ARegion *ar, Base *base) } glDisable(GL_BLEND); if (v3d->zbuf) glEnable(GL_DEPTH_TEST); - + + /* before disposing of temp pose, use it to restore object to a sane state */ + BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)cfrao, ADT_RECALC_ALL); + + /* clean up temporary pose */ ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */ BKE_pose_free(posen); @@ -2552,7 +2565,6 @@ static void draw_ghost_poses(Scene *scene, View3D *v3d, ARegion *ar, Base *base) CFRA = cfrao; ob->pose = poseo; arm->flag = flago; - BKE_pose_rebuild(ob, ob->data); ob->mode |= OB_MODE_POSE; } diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index 5069c4219c3..da93e07748a 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -772,7 +772,8 @@ static int compareDrawOptionsEm(void *userData, int cur_index, int next_index) return 1; } -void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *dm, int draw_flags) +void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, + Object *ob, DerivedMesh *dm, const int draw_flags) { Mesh *me = ob->data; @@ -871,7 +872,7 @@ static void tex_mat_set_texture_cb(void *userData, int mat_nr, void *attribs) if (ED_object_get_active_image(data->ob, mat_nr, &ima, &iuser, &node)) { /* get openl texture */ int mipmap = 1; - int bindcode = (ima) ? GPU_verify_image(ima, iuser, 0, 0, mipmap) : 0; + int bindcode = (ima) ? GPU_verify_image(ima, iuser, 0, 0, mipmap, FALSE) : 0; float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}; if (bindcode) { @@ -941,7 +942,8 @@ static int tex_mat_set_face_editmesh_cb(void *userData, int index) return !BM_elem_flag_test(efa, BM_ELEM_HIDDEN); } -void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *dm, const int draw_flags) +void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, + Object *ob, DerivedMesh *dm, const int draw_flags) { if ((!BKE_scene_use_new_shading_nodes(scene)) || (draw_flags & DRAW_MODIFIERS_PREVIEW)) { draw_mesh_textured_old(scene, v3d, rv3d, ob, dm, draw_flags); @@ -1017,7 +1019,8 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *o /* Vertex Paint and Weight Paint */ -void draw_mesh_paint(View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *dm, int draw_flags) +void draw_mesh_paint(View3D *v3d, RegionView3D *rv3d, + Object *ob, DerivedMesh *dm, const int draw_flags) { DMSetDrawOptions facemask = NULL; Mesh *me = ob->data; @@ -1027,7 +1030,7 @@ void draw_mesh_paint(View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *d if (draw_flags & DRAW_FACE_SELECT) facemask = wpaint__setSolidDrawOptions_facemask; - if (ob && ob->mode & OB_MODE_WEIGHT_PAINT) { + if (ob->mode & OB_MODE_WEIGHT_PAINT) { if (do_light) { const float spec[4] = {0.47f, 0.47f, 0.47f, 0.47f}; diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index f63171789a0..83bc094270b 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -2904,7 +2904,7 @@ static void draw_em_fancy_edges(BMEditMesh *em, Scene *scene, View3D *v3d, if (ts->selectmode == SCE_SELECT_FACE) { draw_dm_edges_sel(em, cageDM, wireCol, selCol, actCol, eed_act); } - else if ( (me->drawflag & ME_DRAWEDGES) || (ts->selectmode & SCE_SELECT_EDGE) ) { + else if ((me->drawflag & ME_DRAWEDGES) || (ts->selectmode & SCE_SELECT_EDGE)) { if (cageDM->drawMappedEdgesInterp && (ts->selectmode & SCE_SELECT_VERTEX)) { glShadeModel(GL_SMOOTH); draw_dm_edges_sel_interp(em, cageDM, wireCol, selCol); @@ -3180,7 +3180,7 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, { Mesh *me = ob->data; - BMFace *efa_act = BM_active_face_get(em->bm, FALSE); /* annoying but active faces is stored differently */ + BMFace *efa_act = BM_active_face_get(em->bm, FALSE, FALSE); /* annoying but active faces is stored differently */ BMEdge *eed_act = NULL; BMVert *eve_act = NULL; @@ -3347,8 +3347,8 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, draw_dm_vert_normals(em, scene, ob, cageDM); } - if ( (me->drawflag & (ME_DRAWEXTRA_EDGELEN | ME_DRAWEXTRA_FACEAREA | ME_DRAWEXTRA_FACEANG)) && - !(v3d->flag2 & V3D_RENDER_OVERRIDE)) + if ((me->drawflag & (ME_DRAWEXTRA_EDGELEN | ME_DRAWEXTRA_FACEAREA | ME_DRAWEXTRA_FACEANG)) && + !(v3d->flag2 & V3D_RENDER_OVERRIDE)) { draw_em_measure_stats(v3d, ob, em, &scene->unit); } @@ -3445,14 +3445,14 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D else if (dt == OB_WIRE || totface == 0) { draw_wire = OBDRAW_WIRE_ON; /* draw wire only, no depth buffer stuff */ } - else if ( ((is_obact && ob->mode & OB_MODE_TEXTURE_PAINT)) || - check_object_draw_texture(scene, v3d, dt)) + else if (((is_obact && ob->mode & OB_MODE_TEXTURE_PAINT)) || + check_object_draw_texture(scene, v3d, dt)) { - if ( (v3d->flag & V3D_SELECT_OUTLINE) && - ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) && - (base->flag & SELECT) && - !(G.f & G_PICKSEL || (draw_flags & DRAW_FACE_SELECT)) && - (draw_wire == OBDRAW_WIRE_OFF)) + if ((v3d->flag & V3D_SELECT_OUTLINE) && + ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) && + (base->flag & SELECT) && + !(G.f & G_PICKSEL || (draw_flags & DRAW_FACE_SELECT)) && + (draw_wire == OBDRAW_WIRE_OFF)) { draw_mesh_object_outline(v3d, ob, dm); } @@ -3490,11 +3490,11 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D const float spec[4] = {0.47f, 0.47f, 0.47f, 0.47f}; /* draw outline */ - if ( (v3d->flag & V3D_SELECT_OUTLINE) && - ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) && - (base->flag & SELECT) && - (draw_wire == OBDRAW_WIRE_OFF) && - (ob->sculpt == NULL)) + if ((v3d->flag & V3D_SELECT_OUTLINE) && + ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) && + (base->flag & SELECT) && + (draw_wire == OBDRAW_WIRE_OFF) && + (ob->sculpt == NULL)) { draw_mesh_object_outline(v3d, ob, dm); } @@ -3522,11 +3522,11 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D else { Paint *p; - if ( (v3d->flag & V3D_SELECT_OUTLINE) && - ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) && - (base->flag & SELECT) && - (draw_wire == OBDRAW_WIRE_OFF) && - (ob->sculpt == NULL)) + if ((v3d->flag & V3D_SELECT_OUTLINE) && + ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) && + (base->flag & SELECT) && + (draw_wire == OBDRAW_WIRE_OFF) && + (ob->sculpt == NULL)) { draw_mesh_object_outline(v3d, ob, dm); } @@ -3791,12 +3791,14 @@ static int drawDispListwire(ListBase *dlbase) } glEnd(); -/* (ton) this code crashes for me when resolv is 86 or higher... no clue */ -// glVertexPointer(3, GL_FLOAT, sizeof(float)*3*dl->nr, data + 3*nr); -// if (dl->flag & DL_CYCL_V) -// glDrawArrays(GL_LINE_LOOP, 0, dl->parts); -// else -// glDrawArrays(GL_LINE_STRIP, 0, dl->parts); +#if 0 + /* (ton) this code crashes for me when resolv is 86 or higher... no clue */ + glVertexPointer(3, GL_FLOAT, sizeof(float) * 3 * dl->nr, data + 3*nr); + if (dl->flag & DL_CYCL_V) + glDrawArrays(GL_LINE_LOOP, 0, dl->parts); + else + glDrawArrays(GL_LINE_STRIP, 0, dl->parts); +#endif } break; @@ -4375,7 +4377,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv timestep = psys_get_timestep(&sim); - if ( (base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP) ) { + if ((base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP)) { float mat[4][4]; mult_m4_m4m4(mat, ob->obmat, psys->imat); glMultMatrixf(mat); @@ -4921,7 +4923,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv pdd->ma_col = NULL; } - if ( (base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP) ) { + if ((base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP)) { glLoadMatrixf(rv3d->viewmat); } } @@ -5281,7 +5283,7 @@ static void tekenhandlesN(Nurb *nu, short sel, short hide_handles) a = nu->pntsu; while (a--) { if (bezt->hide == 0) { - if ( (bezt->f2 & SELECT) == sel) { + if ((bezt->f2 & SELECT) == sel) { fp = bezt->vec[0]; glColor3ubv(handle_cols[MIN2(bezt->h1, TH_HANDLE_COL_TOT - 1)]); @@ -5292,14 +5294,14 @@ static void tekenhandlesN(Nurb *nu, short sel, short hide_handles) glVertex3fv(fp + 3); glVertex3fv(fp + 6); } - else if ( (bezt->f1 & SELECT) == sel) { + else if ((bezt->f1 & SELECT) == sel) { fp = bezt->vec[0]; glColor3ubv(handle_cols[MIN2(bezt->h1, TH_HANDLE_COL_TOT - 1)]); glVertex3fv(fp); glVertex3fv(fp + 3); } - else if ( (bezt->f3 & SELECT) == sel) { + else if ((bezt->f3 & SELECT) == sel) { fp = bezt->vec[1]; glColor3ubv(handle_cols[MIN2(bezt->h2, TH_HANDLE_COL_TOT - 1)]); @@ -5534,7 +5536,7 @@ static void draw_editnurb(Object *ob, Nurb *nurb, int sel) for (a = nu->pntsu - 1; a > 0; a--, bp++) { if (bp->hide == 0 && bp1->hide == 0) { if (sel) { - if ( (bp->f1 & SELECT) && (bp1->f1 & SELECT) ) { + if ((bp->f1 & SELECT) && (bp1->f1 & SELECT)) { UI_ThemeColor(TH_NURB_SEL_ULINE); glBegin(GL_LINE_STRIP); @@ -5569,7 +5571,7 @@ static void draw_editnurb(Object *ob, Nurb *nurb, int sel) for (a = nu->pntsv - 1; a > 0; a--, bp += ofs) { if (bp->hide == 0 && bp1->hide == 0) { if (sel) { - if ( (bp->f1 & SELECT) && (bp1->f1 & SELECT) ) { + if ((bp->f1 & SELECT) && (bp1->f1 & SELECT)) { UI_ThemeColor(TH_NURB_SEL_VLINE); glBegin(GL_LINE_STRIP); @@ -6958,9 +6960,9 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short } /* draw edit particles last so that they can draw over child particles */ - if ( (warning_recursive == 0) && - (dflag & DRAW_PICKING) == 0 && - (!scene->obedit)) + if ((warning_recursive == 0) && + (dflag & DRAW_PICKING) == 0 && + (!scene->obedit)) { if (ob->mode & OB_MODE_PARTICLE_EDIT && is_obact) { @@ -7260,7 +7262,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short setlinestyle(0); } } - else if ((curcon->flag & CONSTRAINT_EXPAND) && (cti) && (cti->get_constraint_targets)) { + else if ((curcon->flag & CONSTRAINT_EXPAND) && (cti->get_constraint_targets)) { cti->get_constraint_targets(curcon, &targets); for (ct = targets.first; ct; ct = ct->next) { diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 24395865a5e..8a334423ab0 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -48,6 +48,7 @@ #include "BLI_math.h" #include "BLI_rand.h" #include "BLI_utildefines.h" +#include "BLI_endian_switch.h" #include "BKE_anim.h" #include "BKE_camera.h" @@ -1388,16 +1389,21 @@ unsigned int view3d_sample_backbuf(ViewContext *vc, int x, int y) { unsigned int col; - if (x >= vc->ar->winx || y >= vc->ar->winy) return 0; + if (x >= vc->ar->winx || y >= vc->ar->winy) { + return 0; + } + x += vc->ar->winrct.xmin; y += vc->ar->winrct.ymin; view3d_validate_backbuf(vc); - glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col); - glReadBuffer(GL_BACK); + glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col); + glReadBuffer(GL_BACK); - if (ENDIAN_ORDER == B_ENDIAN) SWITCH_INT(col); + if (ENDIAN_ORDER == B_ENDIAN) { + BLI_endian_switch_uint32(&col); + } return WM_framebuffer_to_index(col); } @@ -2824,13 +2830,21 @@ static int view3d_main_area_draw_engine(const bContext *C, ARegion *ar, int draw /* create render engine */ if (!rv3d->render_engine) { + RenderEngine *engine; + type = RE_engines_find(scene->r.engine); if (!(type->view_update && type->view_draw)) return 0; - rv3d->render_engine = RE_engine_create(type); - type->view_update(rv3d->render_engine, C); + engine = RE_engine_create(type); + + engine->tile_x = ceil(ar->winx/(float)scene->r.xparts); + engine->tile_y = ceil(ar->winy/(float)scene->r.yparts); + + type->view_update(engine, C); + + rv3d->render_engine = engine; } /* setup view matrices */ diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 5169d823bd8..7accdb0c0e4 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -475,8 +475,8 @@ static void viewops_data_create(bContext *C, wmOperator *op, wmEvent *event) { /* for dolly */ - float mval_f[2]; - VECCOPY2D(mval_f, event->mval); + const float mval_f[2] = {(float)event->mval[0], + (float)event->mval[1]}; ED_view3d_win_to_vector(vod->ar, mval_f, vod->mousevec); } @@ -2733,12 +2733,12 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } /* convert border to 3d coordinates */ - if ( (!gluUnProject(cent[0], cent[1], depth_close, - mats.modelview, mats.projection, (GLint *)mats.viewport, - &p[0], &p[1], &p[2])) || - (!gluUnProject((double)rect.xmin, (double)rect.ymin, depth_close, - mats.modelview, mats.projection, (GLint *)mats.viewport, - &p_corner[0], &p_corner[1], &p_corner[2]))) + if ((!gluUnProject(cent[0], cent[1], depth_close, + mats.modelview, mats.projection, (GLint *)mats.viewport, + &p[0], &p[1], &p[2])) || + (!gluUnProject((double)rect.xmin, (double)rect.ymin, depth_close, + mats.modelview, mats.projection, (GLint *)mats.viewport, + &p_corner[0], &p_corner[1], &p_corner[2]))) { return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 465279ee6ed..fd43333acfe 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -370,7 +370,7 @@ static void do_view3d_header_buttons(bContext *C, void *UNUSED(arg), int event) case B_SEL_EDGE: if (em) { if (shift == 0 || em->selectmode == 0) { - if ( (em->selectmode ^ SCE_SELECT_EDGE) == SCE_SELECT_VERTEX) { + if ((em->selectmode ^ SCE_SELECT_EDGE) == SCE_SELECT_VERTEX) { if (ctrl) EDBM_selectmode_convert(em, SCE_SELECT_VERTEX, SCE_SELECT_EDGE); } em->selectmode = SCE_SELECT_EDGE; @@ -384,7 +384,9 @@ static void do_view3d_header_buttons(bContext *C, void *UNUSED(arg), int event) case B_SEL_FACE: if (em) { if (shift == 0 || em->selectmode == 0) { - if ( ((ts->selectmode ^ SCE_SELECT_FACE) == SCE_SELECT_VERTEX) || ((ts->selectmode ^ SCE_SELECT_FACE) == SCE_SELECT_EDGE)) { + if (((ts->selectmode ^ SCE_SELECT_FACE) == SCE_SELECT_VERTEX) || + ((ts->selectmode ^ SCE_SELECT_FACE) == SCE_SELECT_EDGE)) + { if (ctrl) EDBM_selectmode_convert(em, (ts->selectmode ^ SCE_SELECT_FACE), SCE_SELECT_FACE); } em->selectmode = SCE_SELECT_FACE; diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index 71e87e73747..5bfabf4fc4a 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -175,7 +175,7 @@ void VIEW3D_OT_game_start(struct wmOperatorType *ot); int ED_view3d_boundbox_clip(RegionView3D * rv3d, float obmat[][4], struct BoundBox *bb); void view3d_smooth_view(struct bContext *C, struct View3D *v3d, struct ARegion *ar, struct Object *, struct Object *, - float *ofs, float *quat, float *dist, float *lens); + float *ofs, float *quat, float *dist, float *lens); void setwinmatrixview3d(ARegion *ar, View3D *v3d, rctf *rect); /* rect: for picking */ void setviewmatrixview3d(Scene *scene, View3D *v3d, RegionView3D *rv3d); diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 6f3cc744537..5712144caf1 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -119,8 +119,8 @@ int view3d_get_view_aligned_coordinate(ViewContext *vc, float fp[3], const int m initgrabz(vc->rv3d, fp[0], fp[1], fp[2]); if (mval_cpy[0] != IS_CLIPPED) { - float mval_f[2]; - VECSUB2D(mval_f, mval_cpy, mval); + const float mval_f[2] = {(float)(mval_cpy[0] - mval[0]), + (float)(mval_cpy[1] - mval[1])}; ED_view3d_win_to_delta(vc->ar, mval_f, dvec); sub_v3_v3(fp, dvec); @@ -1527,10 +1527,10 @@ int edge_inside_circle(int centx, int centy, int rad, int x1, int y1, int x2, in int radsq = rad * rad; /* check points in circle itself */ - if ( (x1 - centx) * (x1 - centx) + (y1 - centy) * (y1 - centy) <= radsq) { + if ((x1 - centx) * (x1 - centx) + (y1 - centy) * (y1 - centy) <= radsq) { return TRUE; } - else if ( (x2 - centx) * (x2 - centx) + (y2 - centy) * (y2 - centy) <= radsq) { + else if ((x2 - centx) * (x2 - centx) + (y2 - centy) * (y2 - centy) <= radsq) { return TRUE; } else { @@ -2027,36 +2027,6 @@ void VIEW3D_OT_select_border(wmOperatorType *ot) WM_operator_properties_gesture_border(ot, TRUE); } -/* much like facesel_face_pick()*/ -/* returns 0 if not found, otherwise 1 */ -static int vertsel_vert_pick(struct bContext *C, Mesh *me, const int mval[2], unsigned int *index, int size) -{ - ViewContext vc; - view3d_set_viewcontext(C, &vc); - - if (!me || me->totvert == 0) - return 0; - - if (size > 0) { - /* sample rect to increase changes of selecting, so that when clicking - * on an face in the backbuf, we can still select a vert */ - - int dist; - *index = view3d_sample_backbuf_rect(&vc, mval, size, 1, me->totvert + 1, &dist, 0, NULL, NULL); - } - else { - /* sample only on the exact position */ - *index = view3d_sample_backbuf(&vc, mval[0], mval[1]); - } - - if ((*index) <= 0 || (*index) > (unsigned int)me->totvert) - return 0; - - (*index)--; - - return 1; -} - /* mouse selection in weight paint */ /* gets called via generic mouse select operator */ static int mouse_weight_paint_vertex_select(bContext *C, const int mval[2], short extend, short deselect, short toggle, Object *obact) @@ -2065,8 +2035,8 @@ static int mouse_weight_paint_vertex_select(bContext *C, const int mval[2], shor unsigned int index = 0; MVert *mv; - if (vertsel_vert_pick(C, me, mval, &index, 50)) { - mv = me->mvert + index; + if (ED_mesh_pick_vert(C, me, mval, &index, ED_MESH_PICK_DEFAULT_VERT_SIZE)) { + mv = &me->mvert[index]; if (extend) { mv->flag |= SELECT; } @@ -2116,7 +2086,7 @@ static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event) if (obedit && object == FALSE) { if (obedit->type == OB_MESH) - retval = mouse_mesh(C, event->mval, extend, deselect, toggle); + retval = EDBM_select_pick(C, event->mval, extend, deselect, toggle); else if (obedit->type == OB_ARMATURE) retval = mouse_armature(C, event->mval, extend, deselect, toggle); else if (obedit->type == OB_LATTICE) @@ -2268,6 +2238,7 @@ static void paint_facesel_circle_select(ViewContext *vc, int select, const int m /* bbsel= */ /* UNUSED */ EDBM_backbuf_circle_init(vc, mval[0], mval[1], (short)(rad + 1.0f)); edbm_backbuf_check_and_select_tfaces(me, select == LEFTMOUSE); EDBM_backbuf_free(); + paintface_flush_flags(ob); } } @@ -2496,7 +2467,7 @@ static void armature_circle_select(ViewContext *vc, int select, const int mval[2 /* only if the endpoints didn't get selected, deal with the middle of the bone too */ /* XXX should we just do this always? */ - if ( (didpoint == 0) && edge_inside_circle(mval[0], mval[1], rad, sco1[0], sco1[1], sco2[0], sco2[1]) ) { + if ((didpoint == 0) && edge_inside_circle(mval[0], mval[1], rad, sco1[0], sco1[1], sco2[0], sco2[1])) { if (select) ebone->flag |= BONE_TIPSEL | BONE_ROOTSEL | BONE_SELECTED; else diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c index fc97b9bbb36..4ca9bd95485 100644 --- a/source/blender/editors/space_view3d/view3d_snap.c +++ b/source/blender/editors/space_view3d/view3d_snap.c @@ -101,8 +101,8 @@ static void special_transvert_update(Object *obedit) DAG_id_tag_update(obedit->data, 0); if (obedit->type == OB_MESH) { - Mesh *me = obedit->data; - BM_mesh_normals_update(me->edit_btmesh->bm, TRUE); /* does face centers too */ + BMEditMesh *em = BMEdit_FromObject(obedit); + BM_mesh_normals_update(em->bm, TRUE); /* does face centers too */ } else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) { Curve *cu = obedit->data; @@ -229,8 +229,7 @@ static void make_trans_verts(Object *obedit, float min[3], float max[3], int mod zero_v3(centroid); if (obedit->type == OB_MESH) { - Mesh *me = obedit->data; - BMEditMesh *em = me->edit_btmesh; + BMEditMesh *em = BMEdit_FromObject(obedit); BMesh *bm = em->bm; BMIter iter; void *userdata[2] = {em, NULL}; @@ -992,11 +991,11 @@ static int snap_curs_to_active(bContext *C, wmOperator *UNUSED(op)) if (obedit) { if (obedit->type == OB_MESH) { + BMEditMesh *em = BMEdit_FromObject(obedit); /* check active */ - Mesh *me = obedit->data; BMEditSelection ese; - if (BM_select_history_active_get(me->edit_btmesh->bm, &ese)) { + if (BM_select_history_active_get(em->bm, &ese)) { BM_editselection_center(&ese, curs); } diff --git a/source/blender/editors/space_view3d/view3d_toolbar.c b/source/blender/editors/space_view3d/view3d_toolbar.c index ee1ead76f7c..b40e880591a 100644 --- a/source/blender/editors/space_view3d/view3d_toolbar.c +++ b/source/blender/editors/space_view3d/view3d_toolbar.c @@ -111,7 +111,7 @@ static void view3d_panel_operator_redo(const bContext *C, Panel *pa) block = uiLayoutGetBlock(pa->layout); if (!WM_operator_check_ui_enabled(C, op->type->name)) - uiLayoutSetEnabled(pa->layout, 0); + uiLayoutSetEnabled(pa->layout, FALSE); /* note, blockfunc is a default but->func, use Handle func to allow button callbacks too */ uiBlockSetHandleFunc(block, ED_undo_operator_repeat_cb_evt, op); diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index fbbf23beca4..c25bb80bfde 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -87,8 +87,9 @@ void view3d_operator_needs_opengl(const bContext *C) void view3d_region_operator_needs_opengl(wmWindow *win, ARegion *ar) { /* for debugging purpose, context should always be OK */ - if ((ar == NULL) || (ar->regiontype != RGN_TYPE_WINDOW)) + if ((ar == NULL) || (ar->regiontype != RGN_TYPE_WINDOW)) { printf("view3d_region_operator_needs_opengl error, wrong region\n"); + } else { RegionView3D *rv3d = ar->regiondata; @@ -1652,7 +1653,7 @@ static void game_set_commmandline_options(GameData *gm) SYS_SystemHandle syshandle; int test; - if ( (syshandle = SYS_GetSystem()) ) { + if ((syshandle = SYS_GetSystem())) { /* User defined settings */ test = (U.gameflags & USER_DISABLE_MIPMAP); GPU_set_mipmap(!test); diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index c5f9546e467..dccd0c27234 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -65,6 +65,7 @@ #include "BKE_particle.h" #include "BKE_pointcache.h" #include "BKE_unit.h" +#include "BKE_mask.h" #include "ED_image.h" #include "ED_keyframing.h" @@ -164,9 +165,7 @@ static void convertViewVec2D_mask(View2D *v2d, float r_vec[3], int dx, int dy) void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy) { if ((t->spacetype == SPACE_VIEW3D) && (t->ar->regiontype == RGN_TYPE_WINDOW)) { - float mval_f[2]; - mval_f[0] = dx; - mval_f[1] = dy; + const float mval_f[2] = {(float)dx, (float)dy}; ED_view3d_win_to_delta(t->ar, mval_f, r_vec); } else if (t->spacetype == SPACE_IMAGE) { @@ -230,9 +229,27 @@ void projectIntView(TransInfo *t, const float vec[3], int adr[2]) project_int_noclip(t->ar, vec, adr); } else if (t->spacetype == SPACE_IMAGE) { + SpaceImage *sima = t->sa->spacedata.first; + if (t->options & CTX_MASK) { + /* not working quite right, TODO (see below too) */ + float aspx, aspy; float v[2]; - ED_mask_point_pos__reverse(t->sa, t->ar, vec[0], vec[1], &v[0], &v[1]); + + ED_space_image_get_aspect(sima, &aspx, &aspy); + + copy_v2_v2(v, vec); + + v[0] = v[0] / aspx; + v[1] = v[1] / aspy; + + BKE_mask_coord_to_image(sima->image, &sima->iuser, v, v); + + v[0] = v[0] / aspx; + v[1] = v[1] / aspy; + + ED_image_point_pos__reverse(sima, t->ar, v, v); + adr[0] = v[0]; adr[1] = v[1]; } @@ -280,23 +297,41 @@ void projectIntView(TransInfo *t, const float vec[3], int adr[2]) adr[1] = out[1]; } else if (t->spacetype == SPACE_CLIP) { - float v[2]; - float aspx = 1.0f, aspy = 1.0f; + SpaceClip *sc = t->sa->spacedata.first; - copy_v2_v2(v, vec); + if (t->options & CTX_MASK) { + /* not working quite right, TODO (see above too) */ + float aspx, aspy; + float v[2]; - if (t->options & CTX_MOVIECLIP) { - ED_space_clip_get_aspect_dimension_aware(t->sa->spacedata.first, &aspx, &aspy); - } - else if (t->options & CTX_MASK) { - /* MASKTODO - not working as expected */ - ED_space_clip_get_aspect(t->sa->spacedata.first, &aspx, &aspy); + ED_space_clip_get_aspect(sc, &aspx, &aspy); + + copy_v2_v2(v, vec); + + v[0] = v[0] / aspx; + v[1] = v[1] / aspy; + + BKE_mask_coord_to_movieclip(sc->clip, &sc->user, v, v); + + v[0] = v[0] / aspx; + v[1] = v[1] / aspy; + + ED_clip_point_stable_pos__reverse(sc, t->ar, v, v); + + adr[0] = v[0]; + adr[1] = v[1]; } + else if (t->options & CTX_MOVIECLIP) { + float v[2], aspx, aspy; + + copy_v2_v2(v, vec); + ED_space_clip_get_aspect_dimension_aware(t->sa->spacedata.first, &aspx, &aspy); - v[0] /= aspx; - v[1] /= aspy; + v[0] /= aspx; + v[1] /= aspy; - UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr + 1); + UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr + 1); + } } else if (t->spacetype == SPACE_NODE) { UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], adr, adr + 1); @@ -2431,8 +2466,9 @@ void initWarp(TransInfo *t) mul_m3_v3(t->data[i].mtx, center); mul_m4_v3(t->viewmat, center); sub_v3_v3(center, t->viewmat[3]); - if (i) + if (i) { minmax_v3v3_v3(min, max, center); + } else { copy_v3_v3(max, center); copy_v3_v3(min, center); @@ -2739,12 +2775,14 @@ static void headerResize(TransInfo *t, float vec[3], char *str) } } else { - if (t->flag & T_2D_EDIT) + if (t->flag & T_2D_EDIT) { spos += sprintf(spos, "Scale X: %s Y: %s%s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], t->con.text, t->proptext); - else + } + else { spos += sprintf(spos, "Scale X: %s Y: %s Z: %s%s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], &tvec[NUM_STR_REP_LEN * 2], t->con.text, t->proptext); + } } if (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) { @@ -3647,9 +3685,10 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) if (!(t->flag & T_2D_EDIT) && t->scene->unit.system) { int i, do_split = t->scene->unit.flag & USER_UNIT_OPT_SPLIT ? 1 : 0; - for (i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { bUnit_AsString(&tvec[i * NUM_STR_REP_LEN], NUM_STR_REP_LEN, dvec[i] * t->scene->unit.scale_length, 4, t->scene->unit.system, B_UNIT_LENGTH, do_split, 1); + } } else { sprintf(&tvec[0], "%.4f", dvec[0]); @@ -3691,12 +3730,14 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) } } else { - if (t->flag & T_2D_EDIT) + if (t->flag & T_2D_EDIT) { spos += sprintf(spos, "Dx: %s Dy: %s (%s)%s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], distvec, t->con.text, t->proptext); - else + } + else { spos += sprintf(spos, "Dx: %s Dy: %s Dz: %s (%s)%s %s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], &tvec[NUM_STR_REP_LEN * 2], distvec, t->con.text, t->proptext, &autoik[0]); + } } if (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) { @@ -4749,11 +4790,10 @@ static void calcNonProportionalEdgeSlide(TransInfo *t, SlideData *sld, const flo static int createSlideVerts(TransInfo *t) { - Mesh *me = t->obedit->data; - BMEditMesh *em = me->edit_btmesh; + BMEditMesh *em = BMEdit_FromObject(t->obedit); BMesh *bm = em->bm; BMIter iter, iter2; - BMEdge *e, *e1 /*, *ee, *le */ /* UNUSED */; + BMEdge *e, *e1; BMVert *v, *v2, *first; BMLoop *l, *l1, *l2; TransDataSlideVert *sv_array; @@ -4765,9 +4805,10 @@ static int createSlideVerts(TransInfo *t) ARegion *ar = t->ar; float projectMat[4][4]; float mval[2] = {(float)t->mval[0], (float)t->mval[1]}; - float start[3] = {0.0f, 0.0f, 0.0f}, dir[3], end[3] = {0.0f, 0.0f, 0.0f}; + float start[3] = {0.0f, 0.0f, 0.0f}, end[3] = {0.0f, 0.0f, 0.0f}; float vec[3], vec2[3] /*, lastvec[3], size, dis=0.0, z */ /* UNUSED */; - int numsel, i, j; + float dir[3], maxdist, (*loop_dir)[3], *loop_maxdist; + int numsel, i, j, loop_nr, l_nr; if (t->spacetype == SPACE_VIEW3D) { /* background mode support */ @@ -4842,6 +4883,7 @@ static int createSlideVerts(TransInfo *t) } sv_array = MEM_callocN(sizeof(TransDataSlideVert) * j, "sv_array"); + loop_nr = 0; j = 0; while (1) { @@ -4904,6 +4946,8 @@ static int createSlideVerts(TransInfo *t) sv->v = v; sv->origvert = *v; + sv->loop_nr = loop_nr; + copy_v3_v3(sv->upvec, vec); if (l2) copy_v3_v3(sv->downvec, vec2); @@ -4926,6 +4970,7 @@ static int createSlideVerts(TransInfo *t) sv = sv_array + j + 1; sv->v = v; sv->origvert = *v; + sv->loop_nr = loop_nr; l = BM_face_other_edge_loop(l1->f, l1->e, v); sv->up = BM_edge_other_vert(l->e, v); @@ -4952,6 +4997,8 @@ static int createSlideVerts(TransInfo *t) BM_elem_flag_disable(v, BM_ELEM_TAG); BM_elem_flag_disable(v2, BM_ELEM_TAG); } while (e != first->e && l1); + + loop_nr++; } /* EDBM_flag_disable_all(em, BM_ELEM_SELECT); */ @@ -4959,21 +5006,24 @@ static int createSlideVerts(TransInfo *t) sld->sv = sv_array; sld->totsv = j; - /*find mouse vector*/ - /* dis = z = -1.0f; */ /* UNUSED */ - /* size = 50.0; */ /* UNUSED */ - /* zero_v3(lastvec); */ /* UNUSED */ + /* find mouse vectors, the global one, and one per loop in case we have + * multiple loops selected, in case they are oriented different */ zero_v3(dir); - /* ee = le = NULL; */ /* UNUSED */ + maxdist = -1.0f; + + loop_dir = MEM_callocN(sizeof(float) * 3 * loop_nr, "sv loop_dir"); + loop_maxdist = MEM_callocN(sizeof(float) * loop_nr, "sv loop_maxdist"); + for (j = 0; j < loop_nr; j++) + loop_maxdist[j] = -1.0f; + BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { if (BM_elem_flag_test(e, BM_ELEM_SELECT)) { BMIter iter2; BMEdge *e2; - float vec1[3], dis2, mval[2] = {t->mval[0], t->mval[1]}, d; + float vec1[3], mval[2] = {t->mval[0], t->mval[1]}, d; /* search cross edges for visible edge to the mouse cursor, * then use the shared vertex to calculate screen vector*/ - dis2 = -1.0f; for (i = 0; i < 2; i++) { v = i ? e->v1 : e->v2; BM_ITER_ELEM (e2, &iter2, v, BM_EDGES_OF_VERT) { @@ -5001,17 +5051,23 @@ static int createSlideVerts(TransInfo *t) ED_view3d_project_float_v3(ar, sv_array[j].up->co, vec2, projectMat); } else { - add_v3_v3v3(vec1, v->co, sv_array[j].upvec); + add_v3_v3v3(vec2, v->co, sv_array[j].upvec); ED_view3d_project_float_v3(ar, vec2, vec2, projectMat); } - + + /* global direction */ d = dist_to_line_segment_v2(mval, vec1, vec2); - if (dis2 == -1.0f || d < dis2) { - dis2 = d; - /* ee = e2; */ /* UNUSED */ - /* size = len_v3v3(vec1, vec2); */ /* UNUSED */ + if (maxdist == -1.0f || d < maxdist) { + maxdist = d; sub_v3_v3v3(dir, vec1, vec2); } + + /* per loop direction */ + l_nr = sv_array[j].loop_nr; + if (loop_maxdist[l_nr] == -1.0f || d < loop_maxdist[l_nr]) { + loop_maxdist[l_nr] = d; + sub_v3_v3v3(loop_dir[l_nr], vec1, vec2); + } } } } @@ -5045,6 +5101,14 @@ static int createSlideVerts(TransInfo *t) } BLI_smallhash_insert(&sld->vhash, (uintptr_t)sv_array->v, sv_array); + + /* switch up/down if loop direction is different from global direction */ + l_nr = sv_array->loop_nr; + if (dot_v3v3(loop_dir[l_nr], dir) < 0.0f) { + swap_v3_v3(sv_array->upvec, sv_array->downvec); + SWAP(BMVert, sv_array->vup, sv_array->vdown); + SWAP(BMVert*, sv_array->up, sv_array->down); + } } if (rv3d) @@ -5055,7 +5119,7 @@ static int createSlideVerts(TransInfo *t) /*zero out start*/ zero_v3(start); - + /*dir holds a vector along edge loop*/ copy_v3_v3(end, dir); mul_v3_fl(end, 0.5f); @@ -5072,6 +5136,8 @@ static int createSlideVerts(TransInfo *t) BLI_smallhash_release(&table); BMBVH_FreeBVH(btree); + MEM_freeN(loop_dir); + MEM_freeN(loop_maxdist); return 1; } @@ -5333,7 +5399,8 @@ int handleEventEdgeSlide(struct TransInfo *t, struct wmEvent *event) return 1; } break; - case FKEY: { + case FKEY: + { if (event->val == KM_PRESS) { if (sld->is_proportional == FALSE) { sld->flipped_vtx = !sld->flipped_vtx; @@ -5342,13 +5409,16 @@ int handleEventEdgeSlide(struct TransInfo *t, struct wmEvent *event) } break; } - case EVT_MODAL_MAP: { + case EVT_MODAL_MAP: + { switch (event->val) { - case TFM_MODAL_EDGESLIDE_DOWN: { + case TFM_MODAL_EDGESLIDE_DOWN: + { sld->curr_sv_index = ((sld->curr_sv_index - 1) + sld->totsv) % sld->totsv; break; } - case TFM_MODAL_EDGESLIDE_UP: { + case TFM_MODAL_EDGESLIDE_UP: + { sld->curr_sv_index = (sld->curr_sv_index + 1) % sld->totsv; break; } diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index 8a7148aad95..e645cb2fed6 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -198,6 +198,8 @@ typedef struct TransDataSlideVert { float edge_len; float upvec[3], downvec[3]; + + int loop_nr; } TransDataSlideVert; typedef struct SlideData { diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 7f77341447d..181f9fe6036 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -861,7 +861,7 @@ static short pose_grab_with_ik_add(bPoseChannel *pchan) data->rootbone = 0; /* watch-it! has to be 0 here, since we're still on the same bone for the first time through the loop [#25885] */ /* we only include bones that are part of a continual connected chain */ - while (pchan) { + do { /* here, we set ik-settings for bone from pchan->protectflag */ // XXX: careful with quats/axis-angle rotations where we're locking 4d components if (pchan->protectflag & OB_LOCK_ROTX) pchan->ikflag |= BONE_IK_NO_XDOF_TEMP; @@ -876,7 +876,7 @@ static short pose_grab_with_ik_add(bPoseChannel *pchan) pchan = pchan->parent; else pchan = NULL; - } + } while (pchan); /* make a copy of maximum chain-length */ data->max_rootbone = data->rootbone; @@ -992,6 +992,9 @@ static void createTransPose(TransInfo *t, Object *ob) t->flag |= T_POSE; t->poseobj = ob; /* we also allow non-active objects to be transformed, in weightpaint */ + /* disable PET, its not usable in pose mode yet [#32444] */ + t->flag &= ~(T_PROP_EDIT | T_PROP_CONNECTED); + /* init trans data */ td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransPoseBone"); tdx = t->ext = MEM_callocN(t->total * sizeof(TransDataExtension), "TransPoseBoneExt"); @@ -4990,7 +4993,7 @@ void autokeyframe_pose_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *o static void special_aftertrans_update__mask(bContext *C, TransInfo *t) { - Mask *mask; + Mask *mask = NULL; if (t->spacetype == SPACE_CLIP) { SpaceClip *sc = t->sa->spacedata.first; @@ -5606,6 +5609,9 @@ static void createTransNodeData(bContext *UNUSED(C), TransInfo *t) return; } + /* nodes dont support PET and probably never will */ + t->flag &= ~(T_PROP_EDIT | T_PROP_CONNECTED); + /* set transform flags on nodes */ for (node = snode->edittree->nodes.first; node; node = node->next) { if (node->flag & NODE_SELECT && is_node_parent_select(node) == FALSE) { diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index bcebca52ce8..325dbe639b4 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -40,6 +40,7 @@ #include "DNA_armature_types.h" #include "DNA_lattice_types.h" #include "DNA_screen_types.h" +#include "DNA_sequence_types.h" #include "DNA_space_types.h" #include "DNA_scene_types.h" #include "DNA_object_types.h" @@ -894,6 +895,17 @@ static void recalcData_view3d(TransInfo *t) /* helper for recalcData() - for sequencer transforms */ static void recalcData_sequencer(TransInfo *t) { + Editing *ed = BKE_sequencer_editing_get(t->scene, FALSE); + Sequence *seq; + + SEQ_BEGIN(ed, seq) + { + if (seq->flag & SELECT) { + BKE_sequence_invalidate_deendent(t->scene, seq); + } + } + SEQ_END + BKE_sequencer_preprocessed_cache_cleanup(); flushTransSeq(t); diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index 237f6b35eb0..a155ff7786a 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -565,8 +565,7 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], ob = obedit; if (ob->type == OB_MESH) { - Mesh *me = ob->data; - BMEditMesh *em = me->edit_btmesh; + BMEditMesh *em = BMEdit_FromObject(ob); BMVert *eve; BMEditSelection ese; float vec[3] = {0, 0, 0}; diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 89cb83e3661..b88ae68e00b 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -410,9 +410,8 @@ static void initSnappingMode(TransInfo *t) } else { /* force project off when not supported */ - if (ts->snap_mode != SCE_SNAP_MODE_FACE) { + if (t->spacetype == SPACE_IMAGE || ts->snap_mode != SCE_SNAP_MODE_FACE) t->tsnap.project = 0; - } t->tsnap.mode = ts->snap_mode; } diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt index c13e6c16413..e0991c48fa6 100644 --- a/source/blender/editors/util/CMakeLists.txt +++ b/source/blender/editors/util/CMakeLists.txt @@ -62,6 +62,7 @@ set(SRC ../include/ED_lattice.h ../include/ED_logic.h ../include/ED_markers.h + ../include/ED_mask.h ../include/ED_mball.h ../include/ED_mesh.h ../include/ED_node.h diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index 6d9f2732d8a..23d6b0a075e 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -45,10 +45,10 @@ #include "BKE_context.h" #include "BKE_global.h" #include "BKE_main.h" -#include "BKE_utildefines.h" #include "BKE_packedFile.h" #include "ED_armature.h" +#include "ED_image.h" #include "ED_mesh.h" #include "ED_object.h" #include "ED_sculpt.h" @@ -67,6 +67,7 @@ void ED_editors_init(bContext *C) { + wmWindowManager *wm = CTX_wm_manager(C); Main *bmain = CTX_data_main(C); Scene *sce = CTX_data_scene(C); Object *ob, *obact = (sce && sce->basact) ? sce->basact->object : NULL; @@ -86,6 +87,11 @@ void ED_editors_init(bContext *C) ED_object_toggle_modes(C, mode); } } + + /* image editor paint mode */ + if (sce) { + ED_space_image_paint_update(wm, sce->toolsettings); + } } /* frees all editmode stuff */ diff --git a/source/blender/editors/util/editmode_undo.c b/source/blender/editors/util/editmode_undo.c index 18610d57bbd..9a3b0476205 100644 --- a/source/blender/editors/util/editmode_undo.c +++ b/source/blender/editors/util/editmode_undo.c @@ -29,8 +29,6 @@ * \ingroup edutil */ - - #include <stdlib.h> #include <string.h> #include <math.h> @@ -44,7 +42,7 @@ #include "BLI_dynstr.h" #include "BLI_utildefines.h" - +#include "BKE_blender.h" #include "BKE_context.h" #include "BKE_depsgraph.h" #include "BKE_global.h" @@ -82,8 +80,6 @@ static void error(const char *UNUSED(arg)) {} /* ****** XXX ***** */ - -#define MAXUNDONAME 64 typedef struct UndoElem { struct UndoElem *next, *prev; ID id; // copy of editmode object ID @@ -91,7 +87,7 @@ typedef struct UndoElem { int type; // type of edited object void *undodata; uintptr_t undosize; - char name[MAXUNDONAME]; + char name[BKE_UNDO_STR_MAX]; void * (*getdata)(bContext * C); void (*freedata)(void *); void (*to_editmode)(void *, void *, void *); diff --git a/source/blender/editors/util/undo.c b/source/blender/editors/util/undo.c index 4213ff68cf2..5eafc3e65a9 100644 --- a/source/blender/editors/util/undo.c +++ b/source/blender/editors/util/undo.c @@ -74,8 +74,6 @@ #include "util_intern.h" -#define MAXUNDONAME 64 /* XXX, make common define */ - /* ***************** generic undo system ********************* */ void ED_undo_push(bContext *C, const char *str) @@ -109,8 +107,7 @@ void ED_undo_push(bContext *C, const char *str) PE_undo_push(CTX_data_scene(C), str); } else { - if (U.uiflag & USER_GLOBALUNDO) - BKE_write_undo(C, str); + BKE_write_undo(C, str); } if (wm->file_saved) { @@ -283,7 +280,7 @@ static int ed_undo_exec(bContext *C, wmOperator *UNUSED(op)) static int ed_undo_push_exec(bContext *C, wmOperator *op) { - char str[MAXUNDONAME]; + char str[BKE_UNDO_STR_MAX]; RNA_string_get(op->ptr, "message", str); ED_undo_push(C, str); return OPERATOR_FINISHED; @@ -321,7 +318,7 @@ void ED_OT_undo_push(wmOperatorType *ot) ot->flag = OPTYPE_INTERNAL; - RNA_def_string(ot->srna, "message", "Add an undo step *function may be moved*", MAXUNDONAME, "Undo Message", ""); + RNA_def_string(ot->srna, "message", "Add an undo step *function may be moved*", BKE_UNDO_STR_MAX, "Undo Message", ""); } void ED_OT_redo(wmOperatorType *ot) diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c index 1f78bc6bddf..d6794912043 100644 --- a/source/blender/editors/uvedit/uvedit_draw.c +++ b/source/blender/editors/uvedit/uvedit_draw.c @@ -415,7 +415,7 @@ static void draw_uvs_texpaint(SpaceImage *sima, Scene *scene, Object *ob) glColor3ub(112, 112, 112); - if (me->mtface) { + if (me->mtpoly) { MPoly *mpoly = me->mpoly; MTexPoly *tface = me->mtpoly; MLoopUV *mloopuv; @@ -455,8 +455,8 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) StitchPreviewer *stitch_preview = uv_get_stitch_previewer(); - activetf = EDBM_mtexpoly_active_get(em, &efa_act, FALSE); /* will be set to NULL if hidden */ - activef = BM_active_face_get(bm, FALSE); + activetf = EDBM_mtexpoly_active_get(em, &efa_act, FALSE, FALSE); /* will be set to NULL if hidden */ + activef = BM_active_face_get(bm, FALSE, FALSE); ts = scene->toolsettings; drawfaces = draw_uvs_face_check(scene); diff --git a/source/blender/editors/uvedit/uvedit_intern.h b/source/blender/editors/uvedit/uvedit_intern.h index d258d271833..f0ff79ae25e 100644 --- a/source/blender/editors/uvedit/uvedit_intern.h +++ b/source/blender/editors/uvedit/uvedit_intern.h @@ -46,10 +46,6 @@ struct BMLoop; struct BMEdge; struct BMVert; -/* id can be from 0 to 3 */ -#define TF_PIN_MASK(id) (TF_PIN1 << id) -#define TF_SEL_MASK(id) (TF_SEL1 << id) - /* visibility and selection */ int uvedit_face_visible_nolocal(struct Scene *scene, struct BMFace *efa); diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index 6f3e6bee850..5008c35e46a 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -174,6 +174,8 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im BMIter iter; MTexPoly *tf; int update = 0; + int sloppy = TRUE; + int selected = !(scene->toolsettings->uv_flag & UV_SYNC_SELECTION); /* skip assigning these procedural images... */ if (ima && (ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE)) @@ -190,8 +192,7 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im if (BKE_scene_use_new_shading_nodes(scene)) { /* new shading system, assign image in material */ - int sloppy = 1; - BMFace *efa = BM_active_face_get(em->bm, sloppy); + BMFace *efa = BM_active_face_get(em->bm, sloppy, selected); if (efa) ED_object_assign_active_image(bmain, obedit, efa->mat_nr + 1, ima); @@ -2056,7 +2057,7 @@ static void UV_OT_select(wmOperatorType *ot) ot->name = "Select"; ot->description = "Select UV vertices"; ot->idname = "UV_OT_select"; - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ot->flag = OPTYPE_UNDO; /* api callbacks */ ot->exec = select_exec; @@ -2101,7 +2102,7 @@ static void UV_OT_select_loop(wmOperatorType *ot) ot->name = "Loop Select"; ot->description = "Select a loop of connected UV vertices"; ot->idname = "UV_OT_select_loop"; - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ot->flag = OPTYPE_UNDO; /* api callbacks */ ot->exec = select_loop_exec; @@ -2203,7 +2204,7 @@ static void UV_OT_select_linked_pick(wmOperatorType *ot) ot->name = "Select Linked Pick"; ot->description = "Select all UV vertices linked under the mouse"; ot->idname = "UV_OT_select_linked_pick"; - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ot->flag = OPTYPE_UNDO; /* api callbacks */ ot->invoke = select_linked_pick_invoke; diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c index b4903390408..c95b2e85248 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c @@ -192,13 +192,16 @@ static ParamHandle *construct_param_handle(Scene *scene, BMEditMesh *em, handle = param_construct_begin(); if (correct_aspect) { - efa = BM_active_face_get(em->bm, TRUE); + int sloppy = TRUE; + int selected = FALSE; + + efa = BM_active_face_get(em->bm, sloppy, selected); if (efa) { float aspx, aspy; tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); - ED_image_get_uv_aspect(tf->tpage, &aspx, &aspy); + ED_image_get_uv_aspect(tf->tpage, NULL, &aspx, &aspy); if (aspx != aspy) param_aspect_ratio(handle, aspx, aspy); @@ -380,14 +383,17 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, BMEditMesh *e handle = param_construct_begin(); if (correct_aspect) { - editFace = BM_active_face_get(em->bm, TRUE); + int sloppy = TRUE; + int selected = FALSE; + + editFace = BM_active_face_get(em->bm, sloppy, selected); if (editFace) { MTexPoly *tf; float aspx, aspy; tf = CustomData_bmesh_get(&em->bm->pdata, editFace->head.data, CD_MTEXPOLY); - ED_image_get_uv_aspect(tf->tpage, &aspx, &aspy); + ED_image_get_uv_aspect(tf->tpage, NULL, &aspx, &aspy); if (aspx != aspy) param_aspect_ratio(handle, aspx, aspy); @@ -1003,7 +1009,9 @@ static void uv_transform_properties(wmOperatorType *ot, int radius) static void correct_uv_aspect(BMEditMesh *em) { - BMFace *efa = BM_active_face_get(em->bm, TRUE); + int sloppy = TRUE; + int selected = FALSE; + BMFace *efa = BM_active_face_get(em->bm, sloppy, selected); BMLoop *l; BMIter iter, liter; MLoopUV *luv; @@ -1013,7 +1021,7 @@ static void correct_uv_aspect(BMEditMesh *em) MTexPoly *tf; tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); - ED_image_get_uv_aspect(tf->tpage, &aspx, &aspy); + ED_image_get_uv_aspect(tf->tpage, NULL, &aspx, &aspy); } if (aspx == aspy) diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h index 629283ce50d..1729ac06f5a 100644 --- a/source/blender/gpu/GPU_buffers.h +++ b/source/blender/gpu/GPU_buffers.h @@ -159,18 +159,18 @@ int GPU_buffer_legacy(struct DerivedMesh *dm ); typedef struct GPU_Buffers GPU_Buffers; GPU_Buffers *GPU_build_mesh_buffers(int (*face_vert_indices)[4], - struct MFace *mface, struct MVert *mvert, - int *face_indices, int totface); + struct MFace *mface, struct MVert *mvert, + int *face_indices, int totface); void GPU_update_mesh_buffers(GPU_Buffers *buffers, struct MVert *mvert, - int *vert_indices, int totvert, const float *vmask); + int *vert_indices, int totvert, const float *vmask); GPU_Buffers *GPU_build_grid_buffers(int *grid_indices, int totgrid, - unsigned int **grid_hidden, int gridsize); + unsigned int **grid_hidden, int gridsize); void GPU_update_grid_buffers(GPU_Buffers *buffers, struct CCGElem **grids, - const struct DMFlagMat *grid_flag_mats, - int *grid_indices, int totgrid, const struct CCGKey *key); + const struct DMFlagMat *grid_flag_mats, + int *grid_indices, int totgrid, const struct CCGKey *key); void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial); diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h index 7a71f33d3d0..467adbe10b8 100644 --- a/source/blender/gpu/GPU_draw.h +++ b/source/blender/gpu/GPU_draw.h @@ -122,7 +122,7 @@ void GPU_set_gpu_mipmapping(int gpu_mipmap); void GPU_paint_update_image(struct Image *ima, int x, int y, int w, int h, int mipmap); void GPU_update_images_framechange(void); int GPU_update_image_time(struct Image *ima, double time); -int GPU_verify_image(struct Image *ima, struct ImageUser *iuser, int tftile, int compare, int mipmap); +int GPU_verify_image(struct Image *ima, struct ImageUser *iuser, int tftile, int compare, int mipmap, int ncd); void GPU_create_gl_tex(unsigned int *bind, unsigned int *pix, float *frect, int rectw, int recth, int mipmap, int use_hight_bit_depth, struct Image *ima); void GPU_create_gl_tex_compressed(unsigned int *bind, unsigned int *pix, int x, int y, int mipmap, struct Image *ima, struct ImBuf *ibuf); int GPU_upload_dxt_texture(struct ImBuf *ibuf); diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h index b04da04258e..198d002ff0d 100644 --- a/source/blender/gpu/GPU_extensions.h +++ b/source/blender/gpu/GPU_extensions.h @@ -111,7 +111,7 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels); GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256]); GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256]); GPUTexture *GPU_texture_from_blender(struct Image *ima, - struct ImageUser *iuser, double time, int mipmap); + struct ImageUser *iuser, int ncd, double time, int mipmap); void GPU_texture_free(GPUTexture *tex); void GPU_texture_ref(GPUTexture *tex); diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h index a725ff4385d..baa557c3484 100644 --- a/source/blender/gpu/GPU_material.h +++ b/source/blender/gpu/GPU_material.h @@ -107,7 +107,7 @@ typedef struct GPUNodeStack { GPUNodeLink *GPU_attribute(int type, const char *name); GPUNodeLink *GPU_uniform(float *num); GPUNodeLink *GPU_dynamic_uniform(float *num, int dynamictype, void *data); -GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser); +GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser, int ncd); GPUNodeLink *GPU_texture(int size, float *pixels); GPUNodeLink *GPU_dynamic_texture(struct GPUTexture *tex, int dynamictype, void *data); GPUNodeLink *GPU_socket(GPUNodeStack *sock); @@ -135,6 +135,8 @@ int GPU_material_bound(GPUMaterial *material); void GPU_material_vertex_attributes(GPUMaterial *material, struct GPUVertexAttribs *attrib); +int GPU_material_do_color_management(GPUMaterial *mat); + /* Exported shading */ typedef struct GPUShadeInput { diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index a88a075383d..25990e8fc6e 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -761,7 +761,7 @@ void GPU_pass_bind(GPUPass *pass, double time, int mipmap) /* now bind the textures */ for (input=inputs->first; input; input=input->next) { if (input->ima) - input->tex = GPU_texture_from_blender(input->ima, input->iuser, time, mipmap); + input->tex = GPU_texture_from_blender(input->ima, input->iuser, input->imagencd, time, mipmap); if (input->tex && input->bindtex) { GPU_texture_bind(input->tex, input->texid); @@ -917,6 +917,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type) input->ima = link->ptr1; input->iuser = link->ptr2; + input->imagencd = link->imagencd; input->textarget = GL_TEXTURE_2D; input->textype = GPU_TEX2D; MEM_freeN(link); @@ -1109,13 +1110,14 @@ GPUNodeLink *GPU_dynamic_uniform(float *num, int dynamictype, void *data) return link; } -GPUNodeLink *GPU_image(Image *ima, ImageUser *iuser) +GPUNodeLink *GPU_image(Image *ima, ImageUser *iuser, int ncd) { GPUNodeLink *link = GPU_node_link_create(0); link->image= 1; link->ptr1= ima; link->ptr2= iuser; + link->imagencd= ncd; return link; } diff --git a/source/blender/gpu/intern/gpu_codegen.h b/source/blender/gpu/intern/gpu_codegen.h index db334b8bf19..3010937a2f3 100644 --- a/source/blender/gpu/intern/gpu_codegen.h +++ b/source/blender/gpu/intern/gpu_codegen.h @@ -91,6 +91,7 @@ struct GPUNodeLink { const char *attribname; int image; + int imagencd; int texture; int texturesize; @@ -137,6 +138,7 @@ typedef struct GPUInput { struct Image *ima; /* image */ struct ImageUser *iuser;/* image user */ + int imagencd; /* image does not contain color data */ float *dynamicvec; /* vector data in case it is dynamic */ int dynamictype; /* origin of the dynamic uniform (GPUDynamicType) */ void *dynamicdata; /* data source of the dynamic uniform */ diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index d03913af417..4314a784511 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -422,7 +422,7 @@ static void gpu_verify_reflection(Image *ima) } } -int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int mipmap) +int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int mipmap, int ncd) { ImBuf *ibuf = NULL; unsigned int *bind = NULL; @@ -492,7 +492,7 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int } /* TODO unneeded when float images are correctly treated as linear always */ - if (ibuf->profile == IB_PROFILE_LINEAR_RGB) + if (!ncd && ibuf->profile == IB_PROFILE_LINEAR_RGB) do_color_management = TRUE; if (ibuf->rect==NULL) @@ -807,7 +807,7 @@ int GPU_set_tpage(MTFace *tface, int mipmap, int alphablend) gpu_verify_alpha_blend(alphablend); gpu_verify_reflection(ima); - if (GPU_verify_image(ima, NULL, tface->tile, 1, mipmap)) { + if (GPU_verify_image(ima, NULL, tface->tile, 1, mipmap, FALSE)) { GTS.curtile= GTS.tile; GTS.curima= GTS.ima; GTS.curtilemode= GTS.tilemode; diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index 4974d57d64c..c5f427fbcab 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -522,7 +522,7 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels) return tex; } -GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, double time, int mipmap) +GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, int ncd, double time, int mipmap) { GPUTexture *tex; GLint w, h, border, lastbindcode, bindcode; @@ -530,7 +530,7 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, double time, glGetIntegerv(GL_TEXTURE_BINDING_2D, &lastbindcode); GPU_update_image_time(ima, time); - bindcode = GPU_verify_image(ima, iuser, 0, 0, mipmap); + bindcode = GPU_verify_image(ima, iuser, 0, 0, mipmap, ncd); if (ima->gputexture) { ima->gputexture->bindcode = bindcode; diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index efb24375729..61be4057843 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -387,7 +387,7 @@ void gpu_material_add_node(GPUMaterial *material, GPUNode *node) /* Code generation */ -static int gpu_do_color_management(GPUMaterial *mat) +int GPU_material_do_color_management(GPUMaterial *mat) { return ((mat->scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) && !((mat->scene->gm.flag & GAME_GLSL_NO_COLOR_MANAGEMENT))); @@ -645,7 +645,7 @@ static void shade_light_textures(GPUMaterial *mat, GPULamp *lamp, GPUNodeLink ** GPU_link(mat, "shade_light_texture", GPU_builtin(GPU_VIEW_POSITION), - GPU_image(mtex->tex->ima, &mtex->tex->iuser), + GPU_image(mtex->tex->ima, &mtex->tex->iuser, FALSE), GPU_dynamic_uniform((float*)lamp->dynpersmat, GPU_DYNAMIC_LAMP_DYNPERSMAT, lamp->ob), &tex_rgb); texture_rgb_blend(mat, tex_rgb, *rgb, GPU_uniform(&one), GPU_uniform(&mtex->colfac), mtex->blendtype, rgb); @@ -1028,7 +1028,7 @@ static void do_material_tex(GPUShadeInput *shi) talpha = 0; if (tex && tex->type == TEX_IMAGE && tex->ima) { - GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser), &tin, &trgb); + GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser, FALSE), &tin, &trgb); rgbnor= TEX_RGB; if (tex->imaflag & TEX_USEALPHA) @@ -1076,7 +1076,7 @@ static void do_material_tex(GPUShadeInput *shi) } if (tex->type==TEX_IMAGE) - if (gpu_do_color_management(mat)) + if (GPU_material_do_color_management(mat)) GPU_link(mat, "srgb_to_linearrgb", tcol, &tcol); if (mtex->mapto & MAP_COL) { @@ -1104,7 +1104,7 @@ static void do_material_tex(GPUShadeInput *shi) if (tex->imaflag & TEX_NORMALMAP) { /* normalmap image */ - GPU_link(mat, "mtex_normal", texco, GPU_image(tex->ima, &tex->iuser), &tnor); + GPU_link(mat, "mtex_normal", texco, GPU_image(tex->ima, &tex->iuser, TRUE), &tnor); if (mtex->norfac < 0.0f) GPU_link(mat, "mtex_negate_texnormal", tnor, &tnor); @@ -1234,26 +1234,26 @@ static void do_material_tex(GPUShadeInput *shi) if (found_deriv_map) { GPU_link(mat, "mtex_bump_deriv", - texco, GPU_image(tex->ima, &tex->iuser), GPU_uniform(&ima_x), GPU_uniform(&ima_y), tnorfac, + texco, GPU_image(tex->ima, &tex->iuser, TRUE), GPU_uniform(&ima_x), GPU_uniform(&ima_y), tnorfac, &dBs, &dBt ); } else if ( mtex->texflag & MTEX_3TAP_BUMP) GPU_link(mat, "mtex_bump_tap3", - texco, GPU_image(tex->ima, &tex->iuser), tnorfac, + texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac, &dBs, &dBt ); else if ( mtex->texflag & MTEX_5TAP_BUMP) GPU_link(mat, "mtex_bump_tap5", - texco, GPU_image(tex->ima, &tex->iuser), tnorfac, + texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac, &dBs, &dBt ); else if ( mtex->texflag & MTEX_BICUBIC_BUMP ) { if (GPU_bicubic_bump_support()) { GPU_link(mat, "mtex_bump_bicubic", - texco, GPU_image(tex->ima, &tex->iuser), tnorfac, + texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac, &dBs, &dBt); } else { GPU_link(mat, "mtex_bump_tap5", - texco, GPU_image(tex->ima, &tex->iuser), tnorfac, + texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac, &dBs, &dBt); } } @@ -1263,7 +1263,7 @@ static void do_material_tex(GPUShadeInput *shi) float imag_tspace_dimension_y = aspect*imag_tspace_dimension_x; GPU_link(mat, "mtex_bump_apply_texspace", fDet, dBs, dBt, vR1, vR2, - GPU_image(tex->ima, &tex->iuser), texco, + GPU_image(tex->ima, &tex->iuser, TRUE), texco, GPU_uniform(&imag_tspace_dimension_x), GPU_uniform(&imag_tspace_dimension_y), vNacc, &vNacc, &shi->vn ); } @@ -1372,7 +1372,7 @@ void GPU_shadeinput_set(GPUMaterial *mat, Material *ma, GPUShadeInput *shi) GPU_link(mat, "set_value", GPU_uniform(&ma->amb), &shi->amb); GPU_link(mat, "shade_view", GPU_builtin(GPU_VIEW_POSITION), &shi->view); GPU_link(mat, "vcol_attribute", GPU_attribute(CD_MCOL, ""), &shi->vcol); - if (gpu_do_color_management(mat)) + if (GPU_material_do_color_management(mat)) GPU_link(mat, "srgb_to_linearrgb", shi->vcol, &shi->vcol); GPU_link(mat, "texco_refl", shi->vn, shi->view, &shi->ref); } @@ -1396,10 +1396,10 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr) GPU_material_enable_alpha(mat); if ((mat->scene->gm.flag & GAME_GLSL_NO_LIGHTS) || (ma->mode & MA_SHLESS)) { - shr->combined = shi->rgb; - shr->alpha = shi->alpha; GPU_link(mat, "set_rgb", shi->rgb, &shr->diff); GPU_link(mat, "set_rgb_zero", &shr->spec); + GPU_link(mat, "set_value", shi->alpha, &shr->alpha); + shr->combined = shr->diff; } else { if (GPU_link_changed(shi->emit) || ma->emit != 0.0f) { @@ -1418,7 +1418,8 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr) material_lights(shi, shr); shr->combined = shr->diff; - shr->alpha = shi->alpha; + + GPU_link(mat, "set_value", shi->alpha, &shr->alpha); if (world) { /* exposure correction */ @@ -1515,12 +1516,9 @@ GPUMaterial *GPU_material_from_blender(Scene *scene, Material *ma) GPU_material_output_link(mat, outlink); } - if (!BKE_scene_use_new_shading_nodes(scene)) { - if (gpu_do_color_management(mat)) - if (mat->outlink) - GPU_link(mat, "linearrgb_to_srgb", mat->outlink, &mat->outlink); - } - + if (GPU_material_do_color_management(mat)) + if (mat->outlink) + GPU_link(mat, "linearrgb_to_srgb", mat->outlink, &mat->outlink); GPU_material_construct_end(mat); diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index fb248f1b016..81c3cab97d4 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -2114,6 +2114,12 @@ void node_tex_checker(vec3 co, vec4 color1, vec4 color2, float scale, out vec4 c fac = 1.0; } +void node_tex_brick(vec3 co, vec4 color1, vec4 color2, vec4 mortar, float scale, float mortar_size, float bias, float brick_width, float row_height, out vec4 color, out float fac) +{ + color = vec4(1.0); + fac = 1.0; +} + void node_tex_clouds(vec3 co, float size, out vec4 color, out float fac) { color = vec4(1.0); diff --git a/source/blender/ikplugin/BIK_api.h b/source/blender/ikplugin/BIK_api.h index cbc6485cb54..e1d5f50edfb 100644 --- a/source/blender/ikplugin/BIK_api.h +++ b/source/blender/ikplugin/BIK_api.h @@ -70,9 +70,9 @@ void BIK_clear_cache(struct bPose *pose); void BIK_update_param(struct bPose *pose); void BIK_test_constraint(struct Object *ob, struct bConstraint *cons); // not yet implemented -int BIK_get_constraint_param(struct bPose *pose, struct bConstraint *cons, int id, BIK_ParamValue *value); -int BIK_get_channel_param(struct bPose *pose, struct bPoseChannel *pchan, int id, BIK_ParamValue *value); -int BIK_get_solver_param(struct bPose *pose, struct bPoseChannel *pchan, int id, BIK_ParamValue *value); +// int BIK_get_constraint_param(struct bPose *pose, struct bConstraint *cons, int id, BIK_ParamValue *value); +// int BIK_get_channel_param(struct bPose *pose, struct bPoseChannel *pchan, int id, BIK_ParamValue *value); +// int BIK_get_solver_param(struct bPose *pose, struct bPoseChannel *pchan, int id, BIK_ParamValue *value); // number of solver available // 0 = iksolver diff --git a/source/blender/ikplugin/intern/itasc_plugin.cpp b/source/blender/ikplugin/intern/itasc_plugin.cpp index 7a53fe247fe..c5722995d32 100644 --- a/source/blender/ikplugin/intern/itasc_plugin.cpp +++ b/source/blender/ikplugin/intern/itasc_plugin.cpp @@ -57,7 +57,6 @@ extern "C" { #include "BKE_global.h" #include "BKE_armature.h" #include "BKE_action.h" -#include "BKE_utildefines.h" #include "BKE_constraint.h" #include "DNA_object_types.h" #include "DNA_action_types.h" diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index a04affd4891..d23d42ddd0c 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -483,8 +483,8 @@ void IMB_rectfill_alpha(struct ImBuf *ibuf, const float value); /* this should not be here, really, we needed it for operating on render data, IMB_rectfill_area calls it */ void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height, - const float col[4], const int do_color_management, - int x1, int y1, int x2, int y2); + const float col[4], const int do_color_management, + int x1, int y1, int x2, int y2); /* defined in metadata.c */ int IMB_metadata_change_field(struct ImBuf *img, const char *key, const char *field); diff --git a/source/blender/imbuf/intern/IMB_indexer.h b/source/blender/imbuf/intern/IMB_indexer.h index 16d10a5c41c..18816924a9b 100644 --- a/source/blender/imbuf/intern/IMB_indexer.h +++ b/source/blender/imbuf/intern/IMB_indexer.h @@ -31,7 +31,6 @@ #include <stdlib.h> #include <stdio.h> -#include "BKE_utildefines.h" #include "IMB_anim.h" /* * separate animation index files to solve the following problems: diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c index 9092d59c351..16dbd0823da 100644 --- a/source/blender/imbuf/intern/anim_movie.c +++ b/source/blender/imbuf/intern/anim_movie.c @@ -801,6 +801,34 @@ static int ffmpeg_decode_video_frame(struct anim *anim) anim->next_packet.stream_index = -1; } + if (rval == AVERROR_EOF) { + anim->next_packet.size = 0; + anim->next_packet.data = 0; + + anim->pFrameComplete = 0; + + avcodec_decode_video2( + anim->pCodecCtx, + anim->pFrame, &anim->pFrameComplete, + &anim->next_packet); + + if (anim->pFrameComplete) { + anim->next_pts = av_get_pts_from_frame( + anim->pFormatCtx, anim->pFrame); + + av_log(anim->pFormatCtx, + AV_LOG_DEBUG, + " FRAME DONE (after EOF): next_pts=%lld " + "pkt_pts=%lld, guessed_pts=%lld\n", + (anim->pFrame->pts == AV_NOPTS_VALUE) ? + -1 : (long long int)anim->pFrame->pts, + (anim->pFrame->pkt_pts == AV_NOPTS_VALUE) ? + -1 : (long long int)anim->pFrame->pkt_pts, + (long long int)anim->next_pts); + rval = 0; + } + } + if (rval < 0) { anim->next_packet.stream_index = -1; diff --git a/source/blender/imbuf/intern/bmp.c b/source/blender/imbuf/intern/bmp.c index 60dd4f65594..8fa468949e7 100644 --- a/source/blender/imbuf/intern/bmp.c +++ b/source/blender/imbuf/intern/bmp.c @@ -69,7 +69,7 @@ typedef struct BMPHEADER { static int checkbmp(unsigned char *mem) { -#define CHECK_HEADER_FIELD(mem, field) ((mem[0] == field[0]) && (mem[1] == field[0])) +#define CHECK_HEADER_FIELD(mem, field) ((mem[0] == field[0]) && (mem[1] == field[1])) int ret_val = 0; BMPINFOHEADER bmi; diff --git a/source/blender/imbuf/intern/filetype.c b/source/blender/imbuf/intern/filetype.c index 900bc7756f0..d67de3be68b 100644 --- a/source/blender/imbuf/intern/filetype.c +++ b/source/blender/imbuf/intern/filetype.c @@ -48,12 +48,6 @@ static int imb_ftype_default(ImFileType *type, ImBuf *ibuf) { return (ibuf->ftype & type->filetype); } -#if defined(__APPLE__) && defined(IMBUF_COCOA) -static int imb_ftype_cocoa(ImFileType *type, ImBuf *ibuf) -{ - return (ibuf->ftype & TIF); -} -#endif static int imb_ftype_iris(ImFileType *type, ImBuf *ibuf) { (void)type; @@ -83,8 +77,6 @@ ImFileType IMB_FILE_TYPES[] = { #endif #ifdef WITH_TIFF {imb_inittiff, NULL, imb_is_a_tiff, imb_ftype_default, imb_loadtiff, imb_savetiff, imb_loadtiletiff, 0, TIF}, -#elif defined(__APPLE__) && defined(IMBUF_COCOA) - {NULL, NULL, imb_is_a_cocoa, imb_ftype_cocoa, imb_imb_cocoaLoadImage, imb_savecocoa, NULL, 0, TIF}, #endif #ifdef WITH_HDR {NULL, NULL, imb_is_a_hdr, imb_ftype_default, imb_loadhdr, imb_savehdr, NULL, IM_FTYPE_FLOAT, RADHDR}, diff --git a/source/blender/imbuf/intern/imbuf_cocoa.m b/source/blender/imbuf/intern/imbuf_cocoa.m deleted file mode 100644 index 10381e9d1c3..00000000000 --- a/source/blender/imbuf/intern/imbuf_cocoa.m +++ /dev/null @@ -1,384 +0,0 @@ -/* - * ***** 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. - * - * Contributor(s): Damien Plisson 10/2009 - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/imbuf/intern/imbuf_coca.m - * \ingroup imbuf - * - * Provides image file loading and saving for Blender, via Cocoa. - */ - -#include <stdint.h> -#include <string.h> -#import <Cocoa/Cocoa.h> - -#include "imbuf.h" - -#include "IMB_cocoa.h" - -#include "BKE_global.h" -#include "BKE_colortools.h" - -#include "IMB_imbuf_types.h" -#include "IMB_imbuf.h" - -#include "IMB_allocimbuf.h" - - - -#pragma mark load/save functions - -/** - * Loads an image from the supplied buffer - * - * Loads any Core Graphics supported type - * Currently is : TIFF, BMP, JPEG, GIF, PNG, DIB, ICO, and various RAW formats - * - * \param mem: Memory containing the bitmap image - * \param size: Size of the mem buffer. - * \param flags: If flags has IB_test set then the file is not actually loaded, - * but all other operations take place. - * - * \return: A newly allocated ImBuf structure if successful, otherwise NULL. - */ -struct ImBuf *imb_cocoaLoadImage(unsigned char *mem, int size, int flags) -{ - struct ImBuf *ibuf = NULL; - NSSize bitmapSize; - uchar *rasterRGB = NULL; - uchar *rasterRGBA = NULL; - uchar *toIBuf = NULL; - int x, y, to_i, from_i; - NSData *data; - NSBitmapImageRep *bitmapImage; - NSBitmapImageRep *blBitmapFormatImageRGB,*blBitmapFormatImageRGBA; - NSAutoreleasePool *pool; - - pool = [[NSAutoreleasePool alloc] init]; - - data = [NSData dataWithBytes:mem length:size]; - bitmapImage = [[NSBitmapImageRep alloc] initWithData:data]; - - if (!bitmapImage) { - fprintf(stderr, "imb_cocoaLoadImage: error loading image\n"); - [pool drain]; - return NULL; - } - - bitmapSize.width = [bitmapImage pixelsWide]; - bitmapSize.height = [bitmapImage pixelsHigh]; - - /* Tell cocoa image resolution is same as current system one */ - [bitmapImage setSize:bitmapSize]; - - /* allocate the image buffer */ - ibuf = IMB_allocImBuf(bitmapSize.width, bitmapSize.height, 32/*RGBA*/, 0); - if (!ibuf) { - fprintf(stderr, - "imb_cocoaLoadImage: could not allocate memory for the image.\n"); - [bitmapImage release]; - [pool drain]; - return NULL; - } - - /* read in the image data */ - if (!(flags & IB_test)) { - - /* allocate memory for the ibuf->rect */ - imb_addrectImBuf(ibuf); - - /* Convert the image in a RGBA 32bit format */ - /* As Core Graphics does not support contextes with non premutliplied alpha, - we need to get alpha key values in a separate batch */ - - /* First get RGB values w/o Alpha to avoid pre-multiplication, 32bit but last byte is unused */ - blBitmapFormatImageRGB = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL - pixelsWide:bitmapSize.width - pixelsHigh:bitmapSize.height - bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO - colorSpaceName:NSCalibratedRGBColorSpace - bitmapFormat:0 - bytesPerRow:4*bitmapSize.width - bitsPerPixel:32/*RGB format padded to 32bits*/]; - - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:blBitmapFormatImageRGB]]; - [bitmapImage draw]; - [NSGraphicsContext restoreGraphicsState]; - - rasterRGB = (uchar*)[blBitmapFormatImageRGB bitmapData]; - if (rasterRGB == NULL) { - [bitmapImage release]; - [blBitmapFormatImageRGB release]; - [pool drain]; - return NULL; - } - - /* Then get Alpha values by getting the RGBA image (that is premultiplied btw) */ - blBitmapFormatImageRGBA = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL - pixelsWide:bitmapSize.width - pixelsHigh:bitmapSize.height - bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO - colorSpaceName:NSCalibratedRGBColorSpace - bitmapFormat:0 - bytesPerRow:4*bitmapSize.width - bitsPerPixel:32/* RGBA */]; - - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:blBitmapFormatImageRGBA]]; - [bitmapImage draw]; - [NSGraphicsContext restoreGraphicsState]; - - rasterRGBA = (uchar*)[blBitmapFormatImageRGBA bitmapData]; - if (rasterRGBA == NULL) { - [bitmapImage release]; - [blBitmapFormatImageRGB release]; - [blBitmapFormatImageRGBA release]; - [pool drain]; - return NULL; - } - - /*Copy the image to ibuf, flipping it vertically*/ - toIBuf = (uchar*)ibuf->rect; - for (x = 0; x < bitmapSize.width; x++) { - for (y = 0; y < bitmapSize.height; y++) { - to_i = (bitmapSize.height-y-1)*bitmapSize.width + x; - from_i = y*bitmapSize.width + x; - - toIBuf[4*to_i] = rasterRGB[4*from_i]; /* R */ - toIBuf[4*to_i+1] = rasterRGB[4*from_i+1]; /* G */ - toIBuf[4*to_i+2] = rasterRGB[4*from_i+2]; /* B */ - toIBuf[4*to_i+3] = rasterRGBA[4*from_i+3]; /* A */ - } - } - - [blBitmapFormatImageRGB release]; - [blBitmapFormatImageRGBA release]; - } - - /* release the cocoa objects */ - [bitmapImage release]; - [pool drain]; - - if (ENDIAN_ORDER == B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf); - - ibuf->ftype = TIF; - ibuf->profile = IB_PROFILE_SRGB; - - /* return successfully */ - return (ibuf); -} - -/** - * Saves an image to a file. - * - * ImBuf structures with 1, 3 or 4 bytes per pixel (GRAY, RGB, RGBA - * respectively) are accepted, and interpreted correctly. - * - * Accepted formats: TIFF, GIF, BMP, PNG, JPEG, JPEG2000 - * - * \param ibuf: Image buffer. - * \param name: Name of the image file to create. - * \param flags: Currently largely ignored. - * - * \return: 1 if the function is successful, 0 on failure. - */ - -#define FTOUSHORT(val) ((val >= 1.0f-0.5f/65535)? 65535: (val <= 0.0f)? 0: (unsigned short)(val*65535.0f + 0.5f)) - -short imb_cocoaSaveImage(struct ImBuf *ibuf, char *name, int flags) -{ - uint16_t samplesperpixel, bitspersample; - unsigned char *from = NULL, *to = NULL; - unsigned short *to16 = NULL; - float *fromf = NULL; - int x, y, from_i, to_i, i; - int success; - BOOL hasAlpha; - NSString* colorSpace; - NSBitmapImageRep *blBitmapFormatImage; - NSData *dataToWrite; - NSDictionary *imageProperties; - - NSAutoreleasePool *pool; - - if (!ibuf) return FALSE; - if (!name) return FALSE; - - /* check for a valid number of bytes per pixel. Like the PNG writer, - * the TIFF writer supports 1, 3 or 4 bytes per pixel, corresponding - * to gray, RGB, RGBA respectively. */ - samplesperpixel = (uint16_t)((ibuf->planes + 7) >> 3); - switch (samplesperpixel) { - case 4: /*RGBA type*/ - hasAlpha = YES; - colorSpace = NSCalibratedRGBColorSpace; - break; - case 3: /*RGB type*/ - hasAlpha = NO; - colorSpace = NSCalibratedRGBColorSpace; - break; - case 1: - hasAlpha = NO; - colorSpace = NSCalibratedWhiteColorSpace; - break; - default: - fprintf(stderr, - "imb_cocoaSaveImage: unsupported number of bytes per " - "pixel: %d\n", samplesperpixel); - return (0); - } - - if((ibuf->ftype & TIF_16BIT) && ibuf->rect_float) - bitspersample = 16; - else - bitspersample = 8; - - pool = [[NSAutoreleasePool alloc] init]; - - /* Create bitmap image rep in blender format */ - blBitmapFormatImage = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL - pixelsWide:ibuf->x - pixelsHigh:ibuf->y - bitsPerSample:bitspersample samplesPerPixel:samplesperpixel hasAlpha:hasAlpha isPlanar:NO - colorSpaceName:colorSpace - bitmapFormat:NSAlphaNonpremultipliedBitmapFormat - bytesPerRow:(ibuf->x*bitspersample*samplesperpixel/8) - bitsPerPixel:(bitspersample*samplesperpixel)]; - if (!blBitmapFormatImage) { - [pool drain]; - return FALSE; - } - - /* setup pointers */ - if(bitspersample == 16) { - fromf = ibuf->rect_float; - to16 = (unsigned short*)[blBitmapFormatImage bitmapData]; - } - else { - from = (unsigned char*)ibuf->rect; - to = (unsigned char*)[blBitmapFormatImage bitmapData]; - } - - /* copy pixel data. While copying, we flip the image vertically. */ - for (x = 0; x < ibuf->x; x++) { - for (y = 0; y < ibuf->y; y++) { - from_i = 4*(y*ibuf->x+x); - to_i = samplesperpixel*((ibuf->y-y-1)*ibuf->x+x); - - if(bitspersample == 16) { - if (ibuf->profile == IB_PROFILE_SRGB) { - switch (samplesperpixel) { - case 4 /*RGBA*/: - to16[to_i] = FTOUSHORT(linearrgb_to_srgb(fromf[from_i])); - to16[to_i+1] = FTOUSHORT(linearrgb_to_srgb(fromf[from_i+1])); - to16[to_i+2] = FTOUSHORT(linearrgb_to_srgb(fromf[from_i+2])); - to16[to_i+3] = FTOUSHORT(fromf[from_i+3]); - break; - case 3 /*RGB*/: - to16[to_i] = FTOUSHORT(linearrgb_to_srgb(fromf[from_i])); - to16[to_i+1] = FTOUSHORT(linearrgb_to_srgb(fromf[from_i+1])); - to16[to_i+2] = FTOUSHORT(linearrgb_to_srgb(fromf[from_i+2])); - break; - case 1 /*BW*/: - to16[to_i] = FTOUSHORT(linearrgb_to_srgb(fromf[from_i])); - break; - } - } - else { - for (i = 0; i < samplesperpixel; i++, to_i++, from_i++) - to16[to_i] = FTOUSHORT(fromf[from_i]); - } - } - else { - /* 8bits per sample*/ - for (i = 0; i < samplesperpixel; i++, to_i++, from_i++) - to[to_i] = from[from_i]; - } - } - } - - /* generate file data */ - if (IS_tiff(ibuf)) { - dataToWrite = [blBitmapFormatImage TIFFRepresentationUsingCompression:NSTIFFCompressionLZW factor:1.0]; - } - else if (IS_png(ibuf)) { - imageProperties = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:false], NSImageInterlaced, - nil]; - dataToWrite = [blBitmapFormatImage representationUsingType:NSPNGFileType properties:imageProperties]; - } - else if (IS_bmp(ibuf)) { - dataToWrite = [blBitmapFormatImage representationUsingType:NSBMPFileType properties:nil]; - } - else {/* JPEG by default */ - int quality; - - quality = ibuf->ftype & 0xff; - if (quality <= 0) quality = 90; /* Standard quality if wrong supplied*/ - if (quality > 100) quality = 100; - - imageProperties = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:quality], NSImageCompressionFactor, - [NSNumber numberWithBool:true], NSImageProgressive, - nil]; - dataToWrite = [blBitmapFormatImage representationUsingType:NSJPEGFileType properties:imageProperties]; - } - - /* Write the file */ - success = [dataToWrite writeToFile:[NSString stringWithCString:name encoding:NSISOLatin1StringEncoding] - atomically:YES]; - - [blBitmapFormatImage release]; - [pool drain]; - - return success; -} - -#pragma mark format checking functions - -/* Currently, only tiff format is handled, so need to include here function that was previously in tiff.c */ - -/** - * Checks whether a given memory buffer contains a TIFF file. - * - * FIXME: Possible memory leak if mem is less than IMB_TIFF_NCB bytes long. - * However, changing this will require up-stream modifications. - * - * This method uses the format identifiers from: - * http://www.faqs.org/faqs/graphics/fileformats-faq/part4/section-9.html - * The first four bytes of big-endian and little-endian TIFF files - * respectively are (hex): - * 4d 4d 00 2a - * 49 49 2a 00 - * Note that TIFF files on *any* platform can be either big- or little-endian; - * it's not platform-specific. - * - * AFAICT, libtiff doesn't provide a method to do this automatically, and - * hence my manual comparison. - Jonathan Merritt (lancelet) 4th Sept 2005. - */ -#define IMB_TIFF_NCB 4 /* number of comparison bytes used */ -int imb_is_a_tiff(void *mem) -{ - char big_endian[IMB_TIFF_NCB] = { 0x4d, 0x4d, 0x00, 0x2a }; - char lil_endian[IMB_TIFF_NCB] = { 0x49, 0x49, 0x2a, 0x00 }; - - return ( (memcmp(big_endian, mem, IMB_TIFF_NCB) == 0) || - (memcmp(lil_endian, mem, IMB_TIFF_NCB) == 0) ); -} diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c index 4108f0d89d7..ea493e277f3 100644 --- a/source/blender/imbuf/intern/indexer.c +++ b/source/blender/imbuf/intern/indexer.c @@ -24,18 +24,21 @@ #include <stdlib.h> -#include "IMB_indexer.h" -#include "IMB_anim.h" -#include "AVI_avi.h" -#include "imbuf.h" #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" +#include "BLI_endian_switch.h" +#include "BLI_path_util.h" #include "BLI_string.h" #include "BLI_path_util.h" #include "BLI_fileops.h" #include "BLI_math_base.h" +#include "IMB_indexer.h" +#include "IMB_anim.h" +#include "AVI_avi.h" +#include "imbuf.h" + #include "MEM_guardedalloc.h" #include "DNA_userdef_types.h" #include "BKE_global.h" @@ -208,10 +211,10 @@ struct anim_index *IMB_indexer_open(const char *name) if (((ENDIAN_ORDER == B_ENDIAN) != (header[8] == 'V'))) { for (i = 0; i < idx->num_entries; i++) { - SWITCH_INT(idx->entries[i].frameno); - SWITCH_INT64(idx->entries[i].seek_pos); - SWITCH_INT64(idx->entries[i].seek_pos_dts); - SWITCH_INT64(idx->entries[i].pts); + BLI_endian_switch_int32(&idx->entries[i].frameno); + BLI_endian_switch_int64((int64_t *)&idx->entries[i].seek_pos); + BLI_endian_switch_int64((int64_t *)&idx->entries[i].seek_pos_dts); + BLI_endian_switch_int64((int64_t *)&idx->entries[i].pts); } } @@ -720,6 +723,17 @@ typedef struct FFmpegIndexBuilderContext { IMB_Timecode_Type tcs_in_use; IMB_Proxy_Size proxy_sizes_in_use; + + unsigned long long seek_pos; + unsigned long long last_seek_pos; + unsigned long long seek_pos_dts; + unsigned long long seek_pos_pts; + unsigned long long last_seek_pos_dts; + unsigned long long start_pts; + double frame_rate; + double pts_time_base; + int frameno, frameno_gapless; + int start_pts_set; } FFmpegIndexBuilderContext; static IndexBuildContext *index_ffmpeg_create_context(struct anim *anim, IMB_Timecode_Type tcs_in_use, @@ -836,20 +850,63 @@ static void index_rebuild_ffmpeg_finish(FFmpegIndexBuilderContext *context, int MEM_freeN(context); } +static void index_rebuild_ffmpeg_proc_decoded_frame( + FFmpegIndexBuilderContext *context, + AVPacket * curr_packet, + AVFrame *in_frame) +{ + int i; + unsigned long long s_pos = context->seek_pos; + unsigned long long s_dts = context->seek_pos_dts; + unsigned long long pts = av_get_pts_from_frame(context->iFormatCtx, in_frame); + + for (i = 0; i < context->num_proxy_sizes; i++) { + add_to_proxy_output_ffmpeg(context->proxy_ctx[i], in_frame); + } + + if (!context->start_pts_set) { + context->start_pts = pts; + context->start_pts_set = TRUE; + } + + context->frameno = floor((pts - context->start_pts) + * context->pts_time_base + * context->frame_rate + 0.5f); + + /* decoding starts *always* on I-Frames, + * so: P-Frames won't work, even if all the + * information is in place, when we seek + * to the I-Frame presented *after* the P-Frame, + * but located before the P-Frame within + * the stream */ + + if (pts < context->seek_pos_pts) { + s_pos = context->last_seek_pos; + s_dts = context->last_seek_pos_dts; + } + + for (i = 0; i < context->num_indexers; i++) { + if (context->tcs_in_use & tc_types[i]) { + int tc_frameno = context->frameno; + + if (tc_types[i] == IMB_TC_RECORD_RUN_NO_GAPS) + tc_frameno = context->frameno_gapless; + + IMB_index_builder_proc_frame( + context->indexer[i], + curr_packet->data, + curr_packet->size, + tc_frameno, + s_pos, s_dts, pts); + } + } + + context->frameno_gapless++; +} + static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context, short *stop, short *do_update, float *progress) { - int i; - unsigned long long seek_pos = 0; - unsigned long long last_seek_pos = 0; - unsigned long long seek_pos_dts = 0; - unsigned long long seek_pos_pts = 0; - unsigned long long last_seek_pos_dts = 0; - unsigned long long start_pts = 0; - double frame_rate; - double pts_time_base; - int frameno = 0, frameno_gapless = 0; - int start_pts_set = FALSE; AVFrame *in_frame = 0; AVPacket next_packet; uint64_t stream_size; @@ -858,8 +915,8 @@ static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context, stream_size = avio_size(context->iFormatCtx->pb); - frame_rate = av_q2d(context->iStream->r_frame_rate); - pts_time_base = av_q2d(context->iStream->time_base); + context->frame_rate = av_q2d(context->iStream->r_frame_rate); + context->pts_time_base = av_q2d(context->iStream->time_base); while (av_read_frame(context->iFormatCtx, &next_packet) >= 0) { int frame_finished = 0; @@ -878,11 +935,11 @@ static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context, if (next_packet.stream_index == context->videoStream) { if (next_packet.flags & AV_PKT_FLAG_KEY) { - last_seek_pos = seek_pos; - last_seek_pos_dts = seek_pos_dts; - seek_pos = next_packet.pos; - seek_pos_dts = next_packet.dts; - seek_pos_pts = next_packet.pts; + context->last_seek_pos = context->seek_pos; + context->last_seek_pos_dts = context->seek_pos_dts; + context->seek_pos = next_packet.pos; + context->seek_pos_dts = next_packet.dts; + context->seek_pos_pts = next_packet.pts; } avcodec_decode_video2( @@ -891,54 +948,34 @@ static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context, } if (frame_finished) { - unsigned long long s_pos = seek_pos; - unsigned long long s_dts = seek_pos_dts; - unsigned long long pts = av_get_pts_from_frame(context->iFormatCtx, in_frame); - - for (i = 0; i < context->num_proxy_sizes; i++) { - add_to_proxy_output_ffmpeg( - context->proxy_ctx[i], in_frame); - } - - if (!start_pts_set) { - start_pts = pts; - start_pts_set = TRUE; - } + index_rebuild_ffmpeg_proc_decoded_frame( + context, &next_packet, in_frame); + } + av_free_packet(&next_packet); + } - frameno = floor((pts - start_pts) * - pts_time_base * frame_rate + 0.5f); + /* process pictures still stuck in decoder engine after EOF + according to ffmpeg docs using 0-size packets. - /* decoding starts *always* on I-Frames, - * so: P-Frames won't work, even if all the - * information is in place, when we seek - * to the I-Frame presented *after* the P-Frame, - * but located before the P-Frame within - * the stream */ + At least, if we haven't already stopped... */ + if (!*stop) { + int frame_finished; - if (pts < seek_pos_pts) { - s_pos = last_seek_pos; - s_dts = last_seek_pos_dts; - } + next_packet.size = 0; + next_packet.data = 0; - for (i = 0; i < context->num_indexers; i++) { - if (context->tcs_in_use & tc_types[i]) { - int tc_frameno = frameno; + do { + frame_finished = 0; - if (tc_types[i] == IMB_TC_RECORD_RUN_NO_GAPS) - tc_frameno = frameno_gapless; + avcodec_decode_video2( + context->iCodecCtx, in_frame, &frame_finished, + &next_packet); - IMB_index_builder_proc_frame( - context->indexer[i], - next_packet.data, - next_packet.size, - tc_frameno, - s_pos, s_dts, pts); - } + if (frame_finished) { + index_rebuild_ffmpeg_proc_decoded_frame( + context, &next_packet, in_frame); } - - frameno_gapless++; - } - av_free_packet(&next_packet); + } while (frame_finished); } av_free(in_frame); diff --git a/source/blender/imbuf/intern/indexer_dv.c b/source/blender/imbuf/intern/indexer_dv.c index 4c6b750aa41..6b960a18277 100644 --- a/source/blender/imbuf/intern/indexer_dv.c +++ b/source/blender/imbuf/intern/indexer_dv.c @@ -22,9 +22,12 @@ * ***** END GPL LICENSE BLOCK ***** */ -#include "IMB_indexer.h" #include "MEM_guardedalloc.h" + #include "BLI_utildefines.h" +#include "BLI_path_util.h" + +#include "IMB_indexer.h" #include <time.h> typedef struct indexer_dv_bitstream { diff --git a/source/blender/imbuf/intern/iris.c b/source/blender/imbuf/intern/iris.c index e76a59905cb..13b0fc1b55a 100644 --- a/source/blender/imbuf/intern/iris.c +++ b/source/blender/imbuf/intern/iris.c @@ -522,15 +522,13 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) } - if (ibuf) { - ibuf->ftype = IMAGIC; - ibuf->profile = IB_PROFILE_SRGB; + ibuf->ftype = IMAGIC; + ibuf->profile = IB_PROFILE_SRGB; - test_endian_zbuf(ibuf); + test_endian_zbuf(ibuf); - if (ibuf->rect) { - IMB_convert_rgba_to_abgr(ibuf); - } + if (ibuf->rect) { + IMB_convert_rgba_to_abgr(ibuf); } return(ibuf); diff --git a/source/blender/imbuf/intern/moviecache.c b/source/blender/imbuf/intern/moviecache.c index 71eae6c6c21..78a989ad48f 100644 --- a/source/blender/imbuf/intern/moviecache.c +++ b/source/blender/imbuf/intern/moviecache.c @@ -41,6 +41,7 @@ #include "BLI_utildefines.h" #include "BLI_ghash.h" #include "BLI_mempool.h" +#include "BLI_threads.h" #include "IMB_moviecache.h" @@ -58,6 +59,7 @@ #endif static MEM_CacheLimiterC *limitor = NULL; +static pthread_mutex_t limitor_lock = BLI_MUTEX_INITIALIZER; typedef struct MovieCache { char name[64]; @@ -172,12 +174,13 @@ static int compare_int(const void *av, const void *bv) static void IMB_moviecache_destructor(void *p) { - MovieCacheItem *item = (MovieCacheItem *) p; - MovieCache *cache = item->cache_owner; - - PRINT("%s: cache '%s' destroy item %p buffer %p\n", __func__, cache->name, item, item->ibuf); + MovieCacheItem *item = (MovieCacheItem *)p; if (item && item->ibuf) { + MovieCache *cache = item->cache_owner; + + PRINT("%s: cache '%s' destroy item %p buffer %p\n", __func__, cache->name, item, item->ibuf); + IMB_freeImBuf(item->ibuf); item->ibuf = NULL; @@ -334,16 +337,20 @@ void IMB_moviecache_put(MovieCache *cache, void *userkey, ImBuf *ibuf) BLI_ghash_remove(cache->hash, key, moviecache_keyfree, moviecache_valfree); BLI_ghash_insert(cache->hash, key, item); - item->c_handle = MEM_CacheLimiter_insert(limitor, item); - if (cache->last_userkey) { memcpy(cache->last_userkey, userkey, cache->keysize); } + BLI_mutex_lock(&limitor_lock); + + item->c_handle = MEM_CacheLimiter_insert(limitor, item); + MEM_CacheLimiter_ref(item->c_handle); MEM_CacheLimiter_enforce_limits(limitor); MEM_CacheLimiter_unref(item->c_handle); + BLI_mutex_unlock(&limitor_lock); + /* cache limiter can't remove unused keys which points to destoryed values */ check_unused_keys(cache); @@ -364,7 +371,10 @@ ImBuf *IMB_moviecache_get(MovieCache *cache, void *userkey) if (item) { if (item->ibuf) { + BLI_mutex_lock(&limitor_lock); MEM_CacheLimiter_touch(item->c_handle); + BLI_mutex_unlock(&limitor_lock); + IMB_refImBuf(item->ibuf); return item->ibuf; diff --git a/source/blender/imbuf/intern/rectop.c b/source/blender/imbuf/intern/rectop.c index ab805ea6666..c3e23246638 100644 --- a/source/blender/imbuf/intern/rectop.c +++ b/source/blender/imbuf/intern/rectop.c @@ -46,19 +46,19 @@ /* blend modes */ -static void blend_color_mix(char *cp, char *cp1, char *cp2, int fac) +static void blend_color_mix(char cp[3], const char cp1[3], const char cp2[3], const int fac) { /* this and other blending modes previously used >>8 instead of /255. both * are not equivalent (>>8 is /256), and the former results in rounding * errors that can turn colors black fast after repeated blending */ - int mfac = 255 - fac; + const int mfac = 255 - fac; cp[0] = (mfac * cp1[0] + fac * cp2[0]) / 255; cp[1] = (mfac * cp1[1] + fac * cp2[1]) / 255; cp[2] = (mfac * cp1[2] + fac * cp2[2]) / 255; } -static void blend_color_add(char *cp, char *cp1, char *cp2, int fac) +static void blend_color_add(char cp[3], const char cp1[3], const char cp2[3], const int fac) { int temp; @@ -70,7 +70,7 @@ static void blend_color_add(char *cp, char *cp1, char *cp2, int fac) if (temp > 254) cp[2] = 255; else cp[2] = temp; } -static void blend_color_sub(char *cp, char *cp1, char *cp2, int fac) +static void blend_color_sub(char cp[3], const char cp1[3], const char cp2[3], const int fac) { int temp; @@ -82,7 +82,7 @@ static void blend_color_sub(char *cp, char *cp1, char *cp2, int fac) if (temp < 0) cp[2] = 0; else cp[2] = temp; } -static void blend_color_mul(char *cp, char *cp1, char *cp2, int fac) +static void blend_color_mul(char cp[3], const char cp1[3], const char cp2[3], const int fac) { int mfac = 255 - fac; @@ -92,7 +92,7 @@ static void blend_color_mul(char *cp, char *cp1, char *cp2, int fac) cp[2] = (mfac * cp1[2] + fac * ((cp1[2] * cp2[2]) / 255)) / 255; } -static void blend_color_lighten(char *cp, char *cp1, char *cp2, int fac) +static void blend_color_lighten(char cp[3], const char cp1[3], const char cp2[3], const int fac) { /* See if are lighter, if so mix, else don't do anything. * if the paint col is darker then the original, then ignore */ @@ -101,11 +101,12 @@ static void blend_color_lighten(char *cp, char *cp1, char *cp2, int fac) cp[1] = cp1[1]; cp[2] = cp1[2]; } - else + else { blend_color_mix(cp, cp1, cp2, fac); + } } -static void blend_color_darken(char *cp, char *cp1, char *cp2, int fac) +static void blend_color_darken(char cp[3], const char cp1[3], const char cp2[3], const int fac) { /* See if were darker, if so mix, else don't do anything. * if the paint col is brighter then the original, then ignore */ @@ -114,8 +115,9 @@ static void blend_color_darken(char *cp, char *cp1, char *cp2, int fac) cp[1] = cp1[1]; cp[2] = cp1[2]; } - else + else { blend_color_mix(cp, cp1, cp2, fac); + } } unsigned int IMB_blend_color(unsigned int src1, unsigned int src2, int fac, IMB_BlendMode mode) @@ -162,7 +164,7 @@ unsigned int IMB_blend_color(unsigned int src1, unsigned int src2, int fac, IMB_ return dst; } -static void blend_color_mix_float(float *cp, float *cp1, float *cp2, float fac) +static void blend_color_mix_float(float cp[3], const float cp1[3], const float cp2[3], const float fac) { float mfac = 1.0f - fac; cp[0] = mfac * cp1[0] + fac * cp2[0]; @@ -170,7 +172,7 @@ static void blend_color_mix_float(float *cp, float *cp1, float *cp2, float fac) cp[2] = mfac * cp1[2] + fac * cp2[2]; } -static void blend_color_add_float(float *cp, float *cp1, float *cp2, float fac) +static void blend_color_add_float(float cp[3], const float cp1[3], const float cp2[3], const float fac) { cp[0] = cp1[0] + fac * cp2[0]; cp[1] = cp1[1] + fac * cp2[1]; @@ -181,7 +183,7 @@ static void blend_color_add_float(float *cp, float *cp1, float *cp2, float fac) if (cp[2] > 1.0f) cp[2] = 1.0f; } -static void blend_color_sub_float(float *cp, float *cp1, float *cp2, float fac) +static void blend_color_sub_float(float cp[3], const float cp1[3], const float cp2[3], const float fac) { cp[0] = cp1[0] - fac * cp2[0]; cp[1] = cp1[1] - fac * cp2[1]; @@ -192,7 +194,7 @@ static void blend_color_sub_float(float *cp, float *cp1, float *cp2, float fac) if (cp[2] < 0.0f) cp[2] = 0.0f; } -static void blend_color_mul_float(float *cp, float *cp1, float *cp2, float fac) +static void blend_color_mul_float(float cp[3], const float cp1[3], const float cp2[3], const float fac) { float mfac = 1.0f - fac; @@ -201,7 +203,7 @@ static void blend_color_mul_float(float *cp, float *cp1, float *cp2, float fac) cp[2] = mfac * cp1[2] + fac * (cp1[2] * cp2[2]); } -static void blend_color_lighten_float(float *cp, float *cp1, float *cp2, float fac) +static void blend_color_lighten_float(float cp[3], const float cp1[3], const float cp2[3], const float fac) { /* See if are lighter, if so mix, else don't do anything. * if the pafloat col is darker then the original, then ignore */ @@ -214,7 +216,7 @@ static void blend_color_lighten_float(float *cp, float *cp1, float *cp2, float f blend_color_mix_float(cp, cp1, cp2, fac); } -static void blend_color_darken_float(float *cp, float *cp1, float *cp2, float fac) +static void blend_color_darken_float(float cp[3], const float cp1[3], const float cp2[3], const float fac) { /* See if were darker, if so mix, else don't do anything. * if the pafloat col is brighter then the original, then ignore */ diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c index 6a234b8e29a..2a2aedb49ff 100644 --- a/source/blender/imbuf/intern/thumbs.c +++ b/source/blender/imbuf/intern/thumbs.c @@ -39,8 +39,6 @@ #include "BLI_fileops.h" #include "BLI_md5.h" -#include "BKE_utildefines.h" - #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" #include "IMB_thumbs.h" diff --git a/source/blender/imbuf/intern/thumbs_blend.c b/source/blender/imbuf/intern/thumbs_blend.c index afef2365de4..cfc49d8cef5 100644 --- a/source/blender/imbuf/intern/thumbs_blend.c +++ b/source/blender/imbuf/intern/thumbs_blend.c @@ -29,18 +29,20 @@ #include "zlib.h" +#include "MEM_guardedalloc.h" + #include "BLI_utildefines.h" +#include "BLI_endian_switch.h" #include "BLI_fileops.h" -#include "BKE_utildefines.h" +#include "BLO_blend_defs.h" + #include "BKE_global.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" #include "IMB_thumbs.h" -#include "MEM_guardedalloc.h" - /* extracts the thumbnail from between the 'REND' and the 'GLOB' * chunks of the header, don't use typical blend loader because its too slow */ @@ -78,7 +80,7 @@ static ImBuf *loadblend_thumb(gzFile gzfile) while (gzread(gzfile, bhead, sizeof_bhead) == sizeof_bhead) { if (endian_switch) - SWITCH_INT(bhead[1]); /* length */ + BLI_endian_switch_int32(&bhead[1]); /* length */ if (bhead[0] == REND) { gzseek(gzfile, bhead[1], SEEK_CUR); /* skip to the next */ @@ -97,8 +99,8 @@ static ImBuf *loadblend_thumb(gzFile gzfile) return NULL; if (endian_switch) { - SWITCH_INT(size[0]); - SWITCH_INT(size[1]); + BLI_endian_switch_int32(&size[0]); + BLI_endian_switch_int32(&size[1]); } /* length */ bhead[1] -= sizeof(int) * 2; diff --git a/source/blender/imbuf/intern/util.c b/source/blender/imbuf/intern/util.c index a765ac5c3b4..6d1e3c16631 100644 --- a/source/blender/imbuf/intern/util.c +++ b/source/blender/imbuf/intern/util.c @@ -225,16 +225,6 @@ static int isqtime(const char *name) static char ffmpeg_last_error[1024]; -void silence_log_ffmpeg(int quiet) -{ - if (quiet) { - av_log_set_level(AV_LOG_QUIET); - } - else { - av_log_set_level(AV_LOG_DEBUG); - } -} - void ffmpeg_log_callback(void *ptr, int level, const char *format, va_list arg) { if (ELEM(level, AV_LOG_FATAL, AV_LOG_ERROR)) { @@ -244,8 +234,10 @@ void ffmpeg_log_callback(void *ptr, int level, const char *format, va_list arg) ffmpeg_last_error[n - 1] = '\0'; } - /* call default logger to print all message to console */ - av_log_default_callback(ptr, level, format, arg); + if (G.debug & G_DEBUG_FFMPEG) { + /* call default logger to print all message to console */ + av_log_default_callback(ptr, level, format, arg); + } } void IMB_ffmpeg_init(void) @@ -253,13 +245,6 @@ void IMB_ffmpeg_init(void) av_register_all(); avdevice_register_all(); - if ((G.debug & G_DEBUG_FFMPEG) == 0) { - silence_log_ffmpeg(1); - } - else { - silence_log_ffmpeg(0); - } - ffmpeg_last_error[0] = '\0'; /* set own callback which could store last error to report to UI */ diff --git a/source/blender/makesdna/DNA_ipo_types.h b/source/blender/makesdna/DNA_ipo_types.h index e3ab6b4a7db..6bf8dbbe73a 100644 --- a/source/blender/makesdna/DNA_ipo_types.h +++ b/source/blender/makesdna/DNA_ipo_types.h @@ -65,8 +65,8 @@ typedef struct IpoDriver { typedef struct IpoCurve { struct IpoCurve *next, *prev; - struct BPoint *bp; /* array of BPoints (sizeof(BPoint)*totvert) - i.e. baked/imported data */ - struct BezTriple *bezt; /* array of BezTriples (sizeof(BezTriple)*totvert) - i.e. user-editable keyframes */ + struct BPoint *bp; /* array of BPoints (sizeof(BPoint) * totvert) - i.e. baked/imported data */ + struct BezTriple *bezt; /* array of BezTriples (sizeof(BezTriple) * totvert) - i.e. user-editable keyframes */ rctf maxrct, totrct; /* bounding boxes */ diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h index 316b90b69de..5408e865ab2 100644 --- a/source/blender/makesdna/DNA_mesh_types.h +++ b/source/blender/makesdna/DNA_mesh_types.h @@ -92,7 +92,8 @@ typedef struct Mesh { struct MCol *mcol; struct MSticky *msticky; struct Mesh *texcomesh; - + + /* When the object is available, the preferred access method is: BMEdit_FromObject(ob) */ struct BMEditMesh *edit_btmesh; /* not saved in file! */ struct CustomData vdata, edata, fdata; diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h index c3b11fed613..3c89e069ea0 100644 --- a/source/blender/makesdna/DNA_meshdata_types.h +++ b/source/blender/makesdna/DNA_meshdata_types.h @@ -328,7 +328,6 @@ typedef struct MVertSkin { #define TF_SEL2 8 #define TF_SEL3 16 #define TF_SEL4 32 -#define TF_HIDE 64 /* unused, same as TF_SELECT */ /* mtface->mode */ #define TF_DYNAMIC 1 diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index ffb16b96b55..3f1f4933585 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -614,17 +614,27 @@ typedef struct NodeTexSky { typedef struct NodeTexImage { NodeTexBase base; ImageUser iuser; - int color_space, pad; + int color_space; + int projection; + float projection_blend; + int pad; } NodeTexImage; typedef struct NodeTexChecker { NodeTexBase base; } NodeTexChecker; +typedef struct NodeTexBrick { + NodeTexBase base; + int offset_freq, squash_freq; + float offset, squash; +} NodeTexBrick; + typedef struct NodeTexEnvironment { NodeTexBase base; ImageUser iuser; - int color_space, projection; + int color_space; + int projection; } NodeTexEnvironment; typedef struct NodeTexGradient { @@ -764,6 +774,10 @@ typedef struct NodeTrackPosData { #define SHD_PROJ_EQUIRECTANGULAR 0 #define SHD_PROJ_MIRROR_BALL 1 +/* image texture */ +#define SHD_PROJ_FLAT 0 +#define SHD_PROJ_BOX 1 + /* blur node */ #define CMP_NODE_BLUR_ASPECT_NONE 0 #define CMP_NODE_BLUR_ASPECT_Y 1 diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 4c7273b914d..9b347a71140 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -1160,7 +1160,7 @@ typedef struct Scene { #define R_EDGE 0x0020 #define R_FIELDS 0x0040 #define R_FIELDSTILL 0x0080 -#define R_RADIO 0x0100 +/*#define R_RADIO 0x0100 */ /* deprecated */ #define R_BORDER 0x0200 #define R_PANORAMA 0x0400 /* deprecated as scene option, still used in renderer */ #define R_CROP 0x0800 @@ -1363,9 +1363,6 @@ typedef struct Scene { #define TIME2FRA(a) ((((double) scene->r.frs_sec) * (double)(a)) / (double)scene->r.frs_sec_base) #define FPS (((double) scene->r.frs_sec) / (double)scene->r.frs_sec_base) -#define RAD_PHASE_PATCHES 1 -#define RAD_PHASE_FACES 2 - /* base->flag is in DNA_object_types.h */ /* toolsettings->snap_flag */ diff --git a/source/blender/makesdna/DNA_screen_types.h b/source/blender/makesdna/DNA_screen_types.h index 34fb7ce60be..b1cd54950e6 100644 --- a/source/blender/makesdna/DNA_screen_types.h +++ b/source/blender/makesdna/DNA_screen_types.h @@ -77,8 +77,6 @@ typedef struct bScreen { struct wmTimer *animtimer; /* if set, screen has timer handler added in window */ void *context; /* context callback */ - - short handler[8]; /* similar to space handler */ } bScreen; typedef struct ScrVert { @@ -214,13 +212,6 @@ typedef struct ARegion { #define PNL_DEFAULT_CLOSED 1 #define PNL_NO_HEADER 2 -/* screen handlers */ -#define SCREEN_MAXHANDLER 8 - -#define SCREEN_HANDLER_ANIM 1 -#define SCREEN_HANDLER_PYTHON 2 -#define SCREEN_HANDLER_VERSE 3 - /* regiontype, first two are the default set */ /* Do NOT change order, append on end. Types are hardcoded needed */ enum { diff --git a/source/blender/makesdna/DNA_sdna_types.h b/source/blender/makesdna/DNA_sdna_types.h index ec02db192fd..8b2e7645823 100644 --- a/source/blender/makesdna/DNA_sdna_types.h +++ b/source/blender/makesdna/DNA_sdna_types.h @@ -81,12 +81,7 @@ typedef struct BHead4 { # typedef struct BHead8 { int code, len; -#if defined(WIN32) && !defined(FREE_WINDOWS) - /* This is a compiler type! */ - __int64 old; -#else - long long old; -#endif + int64_t old; int SDNAnr, nr; } BHead8; diff --git a/source/blender/makesdna/DNA_sequence_types.h b/source/blender/makesdna/DNA_sequence_types.h index c83bddbfc64..d094c1d6255 100644 --- a/source/blender/makesdna/DNA_sequence_types.h +++ b/source/blender/makesdna/DNA_sequence_types.h @@ -99,7 +99,7 @@ typedef struct Strip { StripProxy *proxy; StripCrop *crop; StripTransform *transform; - StripColorBalance *color_balance; + StripColorBalance *color_balance DNA_DEPRECATED; } Strip; /** @@ -150,9 +150,6 @@ typedef struct Sequence { /* pointers for effects: */ struct Sequence *seq1, *seq2, *seq3; - /* maks input for effects */ - struct Sequence *mask_sequence; - ListBase seqbase; /* list of strips for metastrips */ struct bSound *sound; /* the linked "bSound" object */ @@ -315,7 +312,7 @@ typedef struct BrightContrastModifierData { #define SEQ_USE_PROXY (1 << 15) #define SEQ_USE_TRANSFORM (1 << 16) #define SEQ_USE_CROP (1 << 17) -#define SEQ_USE_COLOR_BALANCE (1 << 18) +/* #define SEQ_USE_COLOR_BALANCE (1 << 18) */ /* DEPRECATED */ #define SEQ_USE_PROXY_CUSTOM_DIR (1 << 19) #define SEQ_USE_PROXY_CUSTOM_FILE (1 << 21) @@ -384,11 +381,6 @@ enum { SEQ_TYPE_EFFECT_MAX = 31 }; -#define STRIPELEM_FAILED 0 -#define STRIPELEM_OK 1 - -#define STRIPELEM_PREVIEW_DONE 1 - #define SEQ_MOVIECLIP_RENDER_UNDISTORTED (1 << 0) #define SEQ_MOVIECLIP_RENDER_STABILIZED (1 << 1) diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index 833cb267185..96f0c0e7a9a 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -47,7 +47,6 @@ struct ColorBand; /* ************************ style definitions ******************** */ #define MAX_STYLE_NAME 64 -#define MAX_FONT_NAME 256 /* default uifont_id offered by Blender */ #define UIFONT_DEFAULT 0 diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index d730c7d9019..9da10381af0 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -133,11 +133,11 @@ typedef struct RegionView3D { short rflag; - /* last view */ + /* last view (use when switching out of camera view) */ float lviewquat[4]; short lpersp, lview; /* lpersp can never be set to 'RV3D_CAMOB' */ + float gridview; - float twangle[3]; diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c index bd1266bba81..d55810deeac 100644 --- a/source/blender/makesdna/intern/makesdna.c +++ b/source/blender/makesdna/intern/makesdna.c @@ -146,8 +146,8 @@ static int nr_types = 0; static int nr_structs = 0; static char **names, *namedata; /* at address names[a] is string a */ static char **types, *typedata; /* at address types[a] is string a */ -static short *typelens; /* at typelens[a] is de length of type a */ -static short *alphalens; /* contains sizes as they are calculated on the DEC Alpha (64 bits), in fact any 64bit system */ +static short *typelens_native; /* at typelens[a] is the length of type 'a' on this systems bitness (32 or 64) */ +static short *typelens_64; /* contains sizes as they are calculated on 64 bit systems */ static short **structs, *structdata; /* at sp = structs[a] is the first address of a struct definition * sp[0] is type number * sp[1] is amount of elements @@ -244,8 +244,8 @@ static int add_type(const char *str, int len) for (nr = 0; nr < nr_types; nr++) { if (strcmp(str, types[nr]) == 0) { if (len) { - typelens[nr] = len; - alphalens[nr] = len; + typelens_native[nr] = len; + typelens_64[nr] = len; } return nr; } @@ -258,8 +258,8 @@ static int add_type(const char *str, int len) } strcpy(cp, str); types[nr_types] = cp; - typelens[nr_types] = len; - alphalens[nr_types] = len; + typelens_native[nr_types] = len; + typelens_64[nr_types] = len; if (nr_types >= maxnr) { printf("too many types\n"); @@ -714,7 +714,7 @@ static int arraysize(char *astr, int len) static int calculate_structlens(int firststruct) { - int a, b, len, alphalen, unknown = nr_structs, lastunknown, structtype, type, mul, namelen; + int a, b, len_native, len_64, unknown = nr_structs, lastunknown, structtype, type, mul, namelen; short *sp, *structpoin; char *cp; int has_pointer, dna_error = 0; @@ -729,11 +729,11 @@ static int calculate_structlens(int firststruct) structtype = structpoin[0]; /* when length is not known... */ - if (typelens[structtype] == 0) { + if (typelens_native[structtype] == 0) { sp = structpoin + 2; - len = 0; - alphalen = 0; + len_native = 0; + len_64 = 0; has_pointer = 0; /* check all elements in struct */ @@ -756,25 +756,25 @@ static int calculate_structlens(int firststruct) /* 4-8 aligned/ */ if (sizeof(void *) == 4) { - if (len % 4) { - printf("Align pointer error in struct (len4): %s %s\n", types[structtype], cp); + if (len_native % 4) { + printf("Align pointer error in struct (len_native 4): %s %s\n", types[structtype], cp); dna_error = 1; } } else { - if (len % 8) { - printf("Align pointer error in struct (len8): %s %s\n", types[structtype], cp); + if (len_native % 8) { + printf("Align pointer error in struct (len_native 8): %s %s\n", types[structtype], cp); dna_error = 1; } } - if (alphalen % 8) { - printf("Align pointer error in struct (alphalen8): %s %s\n", types[structtype], cp); + if (len_64 % 8) { + printf("Align pointer error in struct (len_64 8): %s %s\n", types[structtype], cp); dna_error = 1; } - len += sizeof(void *) * mul; - alphalen += 8 * mul; + len_native += sizeof(void *) * mul; + len_64 += 8 * mul; } else if (cp[0] == '[') { @@ -782,7 +782,7 @@ static int calculate_structlens(int firststruct) printf("Parse error in struct, invalid member name: %s %s\n", types[structtype], cp); dna_error = 1; } - else if (typelens[type]) { + else if (typelens_native[type]) { /* has the name an extra length? (array) */ mul = 1; if (cp[namelen - 1] == ']') mul = arraysize(cp, namelen); @@ -794,54 +794,54 @@ static int calculate_structlens(int firststruct) /* struct alignment */ if (type >= firststruct) { - if (sizeof(void *) == 8 && (len % 8) ) { + if (sizeof(void *) == 8 && (len_native % 8) ) { printf("Align struct error: %s %s\n", types[structtype], cp); dna_error = 1; } } /* 2-4-8 aligned/ */ - if (type < firststruct && typelens[type] > 4 && (len % 8)) { - printf("Align 8 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len % 8); + if (type < firststruct && typelens_native[type] > 4 && (len_native % 8)) { + printf("Align 8 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len_native % 8); dna_error = 1; } - if (typelens[type] > 3 && (len % 4) ) { - printf("Align 4 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len % 4); + if (typelens_native[type] > 3 && (len_native % 4) ) { + printf("Align 4 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len_native % 4); dna_error = 1; } - else if (typelens[type] == 2 && (len % 2) ) { - printf("Align 2 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len % 2); + else if (typelens_native[type] == 2 && (len_native % 2) ) { + printf("Align 2 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len_native % 2); dna_error = 1; } - len += mul * typelens[type]; - alphalen += mul * alphalens[type]; + len_native += mul * typelens_native[type]; + len_64 += mul * typelens_64[type]; } else { - len = 0; - alphalen = 0; + len_native = 0; + len_64 = 0; break; } } - if (len == 0) { + if (len_native == 0) { unknown++; } else { - typelens[structtype] = len; - alphalens[structtype] = alphalen; + typelens_native[structtype] = len_native; + typelens_64[structtype] = len_64; /* two ways to detect if a struct contains a pointer: - * has_pointer is set or alphalen != len */ - if (has_pointer || alphalen != len) { - if (alphalen % 8) { - printf("Sizeerror 8 in struct: %s (add %d bytes)\n", types[structtype], alphalen % 8); + * has_pointer is set or len_64 != len_native */ + if (has_pointer || len_64 != len_native) { + if (len_64 % 8) { + printf("Sizeerror 8 in struct: %s (add %d bytes)\n", types[structtype], len_64 % 8); dna_error = 1; } } - if (len % 4) { - printf("Sizeerror 4 in struct: %s (add %d bytes)\n", types[structtype], len % 4); + if (len_native % 4) { + printf("Sizeerror 4 in struct: %s (add %d bytes)\n", types[structtype], len_native % 4); dna_error = 1; } @@ -863,7 +863,7 @@ static int calculate_structlens(int firststruct) structtype = structpoin[0]; /* length unknown */ - if (typelens[structtype] != 0) { + if (typelens_native[structtype] != 0) { printf(" %s\n", types[structtype]); } } @@ -877,7 +877,7 @@ static int calculate_structlens(int firststruct) structtype = structpoin[0]; /* length unknown yet */ - if (typelens[structtype] == 0) { + if (typelens_native[structtype] == 0) { printf(" %s\n", types[structtype]); } } @@ -923,7 +923,7 @@ void printStructLengths(void) for (a = 0; a < nr_structs; a++) { structpoin = structs[a]; structtype = structpoin[0]; - printf("\t%s\t:%d\n", types[structtype], typelens[structtype]); + printf("\t%s\t:%d\n", types[structtype], typelens_native[structtype]); } } @@ -954,8 +954,8 @@ static int make_structDNA(char *baseDirectory, FILE *file) /* a maximum of 5000 variables, must be sufficient? */ names = MEM_callocN(sizeof(char *) * maxnr, "names"); types = MEM_callocN(sizeof(char *) * maxnr, "types"); - typelens = MEM_callocN(sizeof(short) * maxnr, "typelens"); - alphalens = MEM_callocN(sizeof(short) * maxnr, "alphalens"); + typelens_native = MEM_callocN(sizeof(short) * maxnr, "typelens_native"); + typelens_64 = MEM_callocN(sizeof(short) * maxnr, "typelens_64"); structs = MEM_callocN(sizeof(short) * maxnr, "structs"); /* insertion of all known types */ @@ -1008,7 +1008,7 @@ static int make_structDNA(char *baseDirectory, FILE *file) } printf("\n"); - sp = typelens; + sp = typelens_native; for (a = 0; a < nr_types; a++, sp++) { printf(" %s %d\n", types[a], *sp); } @@ -1016,7 +1016,7 @@ static int make_structDNA(char *baseDirectory, FILE *file) for (a = 0; a < nr_structs; a++) { sp = structs[a]; - printf(" struct %s elems: %d size: %d\n", types[sp[0]], sp[1], typelens[sp[0]]); + printf(" struct %s elems: %d size: %d\n", types[sp[0]], sp[1], typelens_native[sp[0]]); num_types = sp[1]; sp += 2; /* ? num_types was elem? */ @@ -1068,7 +1068,7 @@ static int make_structDNA(char *baseDirectory, FILE *file) len = 2 * nr_types; if (nr_types & 1) len += 2; - dna_write(file, typelens, len); + dna_write(file, typelens_native, len); /* WRITE STRUCTS */ strcpy(str, "STRC"); @@ -1099,7 +1099,7 @@ static int make_structDNA(char *baseDirectory, FILE *file) } fprintf(fp, "main() {\n"); - sp = typelens; + sp = typelens_native; sp += firststruct; for (a = firststruct; a < nr_types; a++, sp++) { if (*sp) { @@ -1121,8 +1121,8 @@ static int make_structDNA(char *baseDirectory, FILE *file) MEM_freeN(structdata); MEM_freeN(names); MEM_freeN(types); - MEM_freeN(typelens); - MEM_freeN(alphalens); + MEM_freeN(typelens_native); + MEM_freeN(typelens_64); MEM_freeN(structs); if (debugSDNA > -1) printf("done.\n"); diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h index 240ad95bcee..1c41c67b39c 100644 --- a/source/blender/makesrna/RNA_enum_types.h +++ b/source/blender/makesrna/RNA_enum_types.h @@ -57,6 +57,7 @@ extern EnumPropertyItem sequence_modifier_type_items[]; extern EnumPropertyItem image_type_items[]; extern EnumPropertyItem image_color_mode_items[]; extern EnumPropertyItem image_depth_mode_items[]; +extern EnumPropertyItem image_generated_type_items[]; extern EnumPropertyItem color_sets_items[]; diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index ca579dde033..4b65d7e0185 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -51,7 +51,7 @@ # define __func__ __FUNCTION__ #endif -/* copied from BKE_utildefines.h ugh */ +/* copied from BLI_utildefines.h ugh */ #ifdef __GNUC__ # define UNUSED(x) UNUSED_ ## x __attribute__((__unused__)) #else @@ -532,7 +532,8 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get"); switch (prop->type) { - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; fprintf(f, "void %s(PointerRNA *ptr, char *value)\n", func); fprintf(f, "{\n"); @@ -565,7 +566,8 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr fprintf(f, "}\n\n"); break; } - case PROP_POINTER: { + case PROP_POINTER: + { fprintf(f, "PointerRNA %s(PointerRNA *ptr)\n", func); fprintf(f, "{\n"); if (manualfunc) { @@ -584,7 +586,8 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr fprintf(f, "}\n\n"); break; } - case PROP_COLLECTION: { + case PROP_COLLECTION: + { CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; fprintf(f, "static PointerRNA %s(CollectionPropertyIterator *iter)\n", func); @@ -785,7 +788,8 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "set"); switch (prop->type) { - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; fprintf(f, "void %s(PointerRNA *ptr, const char *value)\n", func); fprintf(f, "{\n"); @@ -817,7 +821,8 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr fprintf(f, "}\n\n"); break; } - case PROP_POINTER: { + case PROP_POINTER: + { fprintf(f, "void %s(PointerRNA *ptr, PointerRNA value)\n", func); fprintf(f, "{\n"); if (manualfunc) { @@ -1275,7 +1280,8 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp) prop = dp->prop; switch (prop->type) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; if (!prop->arraydimension) { @@ -1291,7 +1297,8 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp) } break; } - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; if (!prop->arraydimension) { @@ -1310,7 +1317,8 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp) } break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; if (!prop->arraydimension) { @@ -1329,14 +1337,16 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp) } break; } - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; eprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)eprop->get); eprop->set = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)eprop->set); break; } - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; sprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)sprop->get); @@ -1344,7 +1354,8 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp) sprop->set = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)sprop->set); break; } - case PROP_POINTER: { + case PROP_POINTER: + { PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop; pprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)pprop->get); @@ -1356,7 +1367,8 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp) } break; } - case PROP_COLLECTION: { + case PROP_COLLECTION: + { CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; const char *nextfunc = (const char *)cprop->next; @@ -1421,7 +1433,8 @@ static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefR switch (prop->type) { case PROP_BOOLEAN: - case PROP_INT: { + case PROP_INT: + { if (!prop->arraydimension) { fprintf(f, "int %sget(PointerRNA *ptr);\n", func); /*fprintf(f, "void %sset(PointerRNA *ptr, int value);\n", func); */ @@ -1436,7 +1449,8 @@ static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefR } break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { if (!prop->arraydimension) { fprintf(f, "float %sget(PointerRNA *ptr);\n", func); /*fprintf(f, "void %sset(PointerRNA *ptr, float value);\n", func); */ @@ -1451,7 +1465,8 @@ static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefR } break; } - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; int i; @@ -1471,7 +1486,8 @@ static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefR break; } - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; if (sprop->maxlength) { @@ -1484,12 +1500,14 @@ static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefR break; } - case PROP_POINTER: { + case PROP_POINTER: + { fprintf(f, "PointerRNA %sget(PointerRNA *ptr);\n", func); /*fprintf(f, "void %sset(PointerRNA *ptr, PointerRNA value);\n", func); */ break; } - case PROP_COLLECTION: { + case PROP_COLLECTION: + { fprintf(f, "void %sbegin(CollectionPropertyIterator *iter, PointerRNA *ptr);\n", func); fprintf(f, "void %snext(CollectionPropertyIterator *iter);\n", func); fprintf(f, "void %send(CollectionPropertyIterator *iter);\n", func); @@ -1520,28 +1538,32 @@ static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, Property fprintf(f, "\t/* */\n"); switch (prop->type) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { if (!prop->arraydimension) fprintf(f, "\tinline bool %s(void);", rna_safe_id(prop->identifier)); else if (prop->totarraylength) fprintf(f, "\tinline Array<int, %u> %s(void);", prop->totarraylength, rna_safe_id(prop->identifier)); break; } - case PROP_INT: { + case PROP_INT: + { if (!prop->arraydimension) fprintf(f, "\tinline int %s(void);", rna_safe_id(prop->identifier)); else if (prop->totarraylength) fprintf(f, "\tinline Array<int, %u> %s(void);", prop->totarraylength, rna_safe_id(prop->identifier)); break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { if (!prop->arraydimension) fprintf(f, "\tinline float %s(void);", rna_safe_id(prop->identifier)); else if (prop->totarraylength) fprintf(f, "\tinline Array<float, %u> %s(void);", prop->totarraylength, rna_safe_id(prop->identifier)); break; } - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; int i; @@ -1559,11 +1581,13 @@ static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, Property fprintf(f, "\tinline %s_enum %s(void);", rna_safe_id(prop->identifier), rna_safe_id(prop->identifier)); break; } - case PROP_STRING: { + case PROP_STRING: + { fprintf(f, "\tinline std::string %s(void);", rna_safe_id(prop->identifier)); break; } - case PROP_POINTER: { + case PROP_POINTER: + { PointerPropertyRNA *pprop = (PointerPropertyRNA *)dp->prop; if (pprop->type) @@ -1572,7 +1596,8 @@ static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, Property fprintf(f, "\tinline %s %s(void);", "UnknownType", rna_safe_id(prop->identifier)); break; } - case PROP_COLLECTION: { + case PROP_COLLECTION: + { CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)dp->prop; if (cprop->item_type) @@ -1598,7 +1623,8 @@ static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDe return; switch (prop->type) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { if (!prop->arraydimension) fprintf(f, "\tBOOLEAN_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier)); else if (prop->totarraylength) @@ -1606,7 +1632,8 @@ static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDe rna_safe_id(prop->identifier)); break; } - case PROP_INT: { + case PROP_INT: + { if (!prop->arraydimension) fprintf(f, "\tINT_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier)); else if (prop->totarraylength) @@ -1614,7 +1641,8 @@ static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDe rna_safe_id(prop->identifier)); break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { if (!prop->arraydimension) fprintf(f, "\tFLOAT_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier)); else if (prop->totarraylength) @@ -1622,17 +1650,20 @@ static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDe rna_safe_id(prop->identifier)); break; } - case PROP_ENUM: { + case PROP_ENUM: + { fprintf(f, "\tENUM_PROPERTY(%s_enum, %s, %s)", rna_safe_id(prop->identifier), srna->identifier, rna_safe_id(prop->identifier)); break; } - case PROP_STRING: { + case PROP_STRING: + { fprintf(f, "\tSTRING_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier)); break; } - case PROP_POINTER: { + case PROP_POINTER: + { PointerPropertyRNA *pprop = (PointerPropertyRNA *)dp->prop; if (pprop->type) @@ -1643,7 +1674,8 @@ static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDe rna_safe_id(prop->identifier)); break; } - case PROP_COLLECTION: { + case PROP_COLLECTION: + { #if 0 CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)dp->prop; @@ -2218,7 +2250,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr } switch (prop->type) { - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; int i, defaultfound = 0, totflag = 0; @@ -2270,7 +2303,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr } break; } - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; unsigned int i; @@ -2291,7 +2325,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr } break; } - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; unsigned int i; @@ -2312,7 +2347,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr } break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; unsigned int i; @@ -2380,7 +2416,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr fprintf(f, "},\n"); switch (prop->type) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; fprintf(f, "\t%s, %s, %s, %s, %d, ", rna_function_string(bprop->get), @@ -2393,7 +2430,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr else fprintf(f, "NULL\n"); break; } - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; fprintf(f, "\t%s, %s, %s, %s, %s,\n\t", rna_function_string(iprop->get), @@ -2412,7 +2450,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr else fprintf(f, "NULL\n"); break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; fprintf(f, "\t%s, %s, %s, %s, %s, ", rna_function_string(fprop->get), @@ -2432,7 +2471,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr else fprintf(f, "NULL\n"); break; } - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; fprintf(f, "\t%s, %s, %s, %d, ", rna_function_string(sprop->get), @@ -2442,7 +2482,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr rna_print_c_string(f, sprop->defaultvalue); fprintf(f, "\n"); break; } - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; fprintf(f, "\t%s, %s, %s, NULL, ", rna_function_string(eprop->get), @@ -2455,7 +2496,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr fprintf(f, "%d, %d\n", eprop->totitem, eprop->defaultvalue); break; } - case PROP_POINTER: { + case PROP_POINTER: + { PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop; fprintf(f, "\t%s, %s, %s, %s,", rna_function_string(pprop->get), rna_function_string(pprop->set), @@ -2465,7 +2507,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr else fprintf(f, "NULL\n"); break; } - case PROP_COLLECTION: { + case PROP_COLLECTION: + { CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; fprintf(f, "\t%s, %s, %s, %s, %s, %s, %s, %s, ", rna_function_string(cprop->begin), @@ -2882,8 +2925,8 @@ static const char *cpp_classes = "" " T data[Tsize];\n" "\n" " Array() {}\n" -" Array(const Array<T, Tsize>& other) { memcpy(data, other.data, sizeof(T)*Tsize); }\n" -" const Array<T, Tsize>& operator=(const Array<T, Tsize>& other) { memcpy(data, other.data, sizeof(T)*Tsize); " +" Array(const Array<T, Tsize>& other) { memcpy(data, other.data, sizeof(T) * Tsize); }\n" +" const Array<T, Tsize>& operator=(const Array<T, Tsize>& other) { memcpy(data, other.data, sizeof(T) * Tsize); " "return *this; }\n" "\n" " operator T*() { return data; }\n" diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index ec4da311686..4c1c377cb9f 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1659,8 +1659,9 @@ void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, int value) IDP_Int(idprop) = value; rna_idproperty_touch(idprop); } - else if (bprop->set) + else if (bprop->set) { bprop->set(ptr, value); + } else if (prop->flag & PROP_EDITABLE) { IDPropertyTemplate val = {0}; IDProperty *group; @@ -3192,19 +3193,22 @@ static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *pro /* handle conversions */ if (set) { switch (itemtype) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { int b; RAW_GET(int, b, in, a); RNA_property_boolean_set(&itemptr, iprop, b); break; } - case PROP_INT: { + case PROP_INT: + { int i; RAW_GET(int, i, in, a); RNA_property_int_set(&itemptr, iprop, i); break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { float f; RAW_GET(float, f, in, a); RNA_property_float_set(&itemptr, iprop, f); @@ -3216,17 +3220,20 @@ static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *pro } else { switch (itemtype) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { int b = RNA_property_boolean_get(&itemptr, iprop); RAW_SET(int, in, a, b); break; } - case PROP_INT: { + case PROP_INT: + { int i = RNA_property_int_get(&itemptr, iprop); RAW_SET(int, in, a, i); break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { float f = RNA_property_float_get(&itemptr, iprop); RAW_SET(float, in, a, f); break; @@ -3251,19 +3258,22 @@ static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *pro /* handle conversions */ if (set) { switch (itemtype) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { for (j = 0; j < itemlen; j++, a++) RAW_GET(int, ((int *)tmparray)[j], in, a); RNA_property_boolean_set_array(&itemptr, iprop, tmparray); break; } - case PROP_INT: { + case PROP_INT: + { for (j = 0; j < itemlen; j++, a++) RAW_GET(int, ((int *)tmparray)[j], in, a); RNA_property_int_set_array(&itemptr, iprop, tmparray); break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { for (j = 0; j < itemlen; j++, a++) RAW_GET(float, ((float *)tmparray)[j], in, a); RNA_property_float_set_array(&itemptr, iprop, tmparray); @@ -3275,19 +3285,22 @@ static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *pro } else { switch (itemtype) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { RNA_property_boolean_get_array(&itemptr, iprop, tmparray); for (j = 0; j < itemlen; j++, a++) RAW_SET(int, in, a, ((int *)tmparray)[j]); break; } - case PROP_INT: { + case PROP_INT: + { RNA_property_int_get_array(&itemptr, iprop, tmparray); for (j = 0; j < itemlen; j++, a++) RAW_SET(int, in, a, ((int *)tmparray)[j]); break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { RNA_property_float_get_array(&itemptr, iprop, tmparray); for (j = 0; j < itemlen; j++, a++) RAW_SET(float, in, a, ((float *)tmparray)[j]); @@ -3301,17 +3314,20 @@ static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *pro else { if (set) { switch (itemtype) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { RNA_property_boolean_set_array(&itemptr, iprop, &((int *)in.array)[a]); a += itemlen; break; } - case PROP_INT: { + case PROP_INT: + { RNA_property_int_set_array(&itemptr, iprop, &((int *)in.array)[a]); a += itemlen; break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { RNA_property_float_set_array(&itemptr, iprop, &((float *)in.array)[a]); a += itemlen; break; @@ -3322,17 +3338,20 @@ static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *pro } else { switch (itemtype) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { RNA_property_boolean_get_array(&itemptr, iprop, &((int *)in.array)[a]); a += itemlen; break; } - case PROP_INT: { + case PROP_INT: + { RNA_property_int_get_array(&itemptr, iprop, &((int *)in.array)[a]); a += itemlen; break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { RNA_property_float_get_array(&itemptr, iprop, &((float *)in.array)[a]); a += itemlen; break; @@ -4924,7 +4943,8 @@ ParameterList *RNA_parameter_list_create(ParameterList *parms, PointerRNA *UNUSE case PROP_ENUM: memcpy(data, &((EnumPropertyRNA *)parm)->defaultvalue, size); break; - case PROP_STRING: { + case PROP_STRING: + { const char *defvalue = ((StringPropertyRNA *)parm)->defaultvalue; if (defvalue && defvalue[0]) { /* causes bug [#29988], possibly this is only correct for thick wrapped diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c index 738e7ad2219..be70405d165 100644 --- a/source/blender/makesrna/intern/rna_armature.c +++ b/source/blender/makesrna/intern/rna_armature.c @@ -146,6 +146,18 @@ static void rna_Armature_redraw_data(Main *UNUSED(bmain), Scene *UNUSED(scene), WM_main_add_notifier(NC_GEOM | ND_DATA, id); } +/* called whenever a bone is renamed */ +static void rna_Bone_update_renamed(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) +{ + ID *id = ptr->id.data; + + /* redraw view */ + WM_main_add_notifier(NC_GEOM | ND_DATA, id); + + /* update animation channels */ + WM_main_add_notifier(NC_ANIMATION | ND_ANIMCHAN, id); +} + static void rna_Bone_select_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { ID *id = ptr->id.data; @@ -470,7 +482,7 @@ static void rna_def_bone_common(StructRNA *srna, int editbone) RNA_def_struct_name_property(srna, prop); if (editbone) RNA_def_property_string_funcs(prop, NULL, NULL, "rna_EditBone_name_set"); else RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Bone_name_set"); - RNA_def_property_update(prop, 0, "rna_Armature_redraw_data"); + RNA_def_property_update(prop, 0, "rna_Bone_update_renamed"); /* flags */ prop = RNA_def_property(srna, "layers", PROP_BOOLEAN, PROP_LAYER_MEMBER); diff --git a/source/blender/makesrna/intern/rna_camera_api.c b/source/blender/makesrna/intern/rna_camera_api.c index 2d19047ef89..75941fa224f 100644 --- a/source/blender/makesrna/intern/rna_camera_api.c +++ b/source/blender/makesrna/intern/rna_camera_api.c @@ -29,9 +29,7 @@ #include <stdio.h> #include <string.h> - #include "RNA_define.h" -#include "BKE_utildefines.h" #ifdef RNA_RUNTIME diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index 0320c0d7142..45092d09ce1 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -926,7 +926,8 @@ PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier } } break; - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; iprop->hardmin = (subtype == PROP_UNSIGNED) ? 0 : INT_MIN; @@ -937,7 +938,8 @@ PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier iprop->step = 1; break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; fprop->hardmin = (subtype == PROP_UNSIGNED) ? 0.0f : -FLT_MAX; @@ -959,7 +961,8 @@ PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier fprop->precision = 3; break; } - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; sprop->defaultvalue = ""; @@ -1009,19 +1012,22 @@ PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier RNA_def_property_boolean_sdna(prop, NULL, identifier, 0); DefRNA.silent = 0; break; - case PROP_INT: { + case PROP_INT: + { DefRNA.silent = 1; RNA_def_property_int_sdna(prop, NULL, identifier); DefRNA.silent = 0; break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { DefRNA.silent = 1; RNA_def_property_float_sdna(prop, NULL, identifier); DefRNA.silent = 0; break; } - case PROP_STRING: { + case PROP_STRING: + { DefRNA.silent = 1; RNA_def_property_string_sdna(prop, NULL, identifier); DefRNA.silent = 0; @@ -1173,14 +1179,16 @@ void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; iprop->softmin = (int)min; iprop->softmax = (int)max; iprop->step = (int)step; break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; fprop->softmin = (float)min; fprop->softmax = (float)max; @@ -1201,7 +1209,8 @@ void RNA_def_property_range(PropertyRNA *prop, double min, double max) StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; iprop->hardmin = (int)min; iprop->hardmax = (int)max; @@ -1209,7 +1218,8 @@ void RNA_def_property_range(PropertyRNA *prop, double min, double max) iprop->softmax = MIN2((int)max, iprop->hardmax); break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; fprop->hardmin = (float)min; fprop->hardmax = (float)max; @@ -1234,12 +1244,14 @@ void RNA_def_property_struct_type(PropertyRNA *prop, const char *type) } switch (prop->type) { - case PROP_POINTER: { + case PROP_POINTER: + { PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop; pprop->type = (StructRNA *)type; break; } - case PROP_COLLECTION: { + case PROP_COLLECTION: + { CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; cprop->item_type = (StructRNA *)type; break; @@ -1262,7 +1274,8 @@ void RNA_def_property_struct_runtime(PropertyRNA *prop, StructRNA *type) } switch (prop->type) { - case PROP_POINTER: { + case PROP_POINTER: + { PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop; pprop->type = type; @@ -1271,7 +1284,8 @@ void RNA_def_property_struct_runtime(PropertyRNA *prop, StructRNA *type) break; } - case PROP_COLLECTION: { + case PROP_COLLECTION: + { CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; cprop->item_type = type; break; @@ -1290,7 +1304,8 @@ void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item int i, defaultfound = 0; switch (prop->type) { - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; eprop->item = (EnumPropertyItem *)item; eprop->totitem = 0; @@ -1325,7 +1340,8 @@ void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength) StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; sprop->maxlength = maxlength; break; @@ -1342,7 +1358,8 @@ void RNA_def_property_boolean_default(PropertyRNA *prop, int value) StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; bprop->defaultvalue = value; break; @@ -1359,7 +1376,8 @@ void RNA_def_property_boolean_array_default(PropertyRNA *prop, const int *array) StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; bprop->defaultarray = array; break; @@ -1376,7 +1394,8 @@ void RNA_def_property_int_default(PropertyRNA *prop, int value) StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; iprop->defaultvalue = value; break; @@ -1393,7 +1412,8 @@ void RNA_def_property_int_array_default(PropertyRNA *prop, const int *array) StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; iprop->defaultarray = array; break; @@ -1410,7 +1430,8 @@ void RNA_def_property_float_default(PropertyRNA *prop, float value) StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; fprop->defaultvalue = value; break; @@ -1427,7 +1448,8 @@ void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array) StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; fprop->defaultarray = array; /* WARNING, this array must not come from the stack and lost */ break; @@ -1444,7 +1466,8 @@ void RNA_def_property_string_default(PropertyRNA *prop, const char *value) StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; sprop->defaultvalue = value; break; @@ -1462,7 +1485,8 @@ void RNA_def_property_enum_default(PropertyRNA *prop, int value) int i, defaultfound = 0; switch (prop->type) { - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; eprop->defaultvalue = value; @@ -1945,7 +1969,8 @@ void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const ch } switch (prop->type) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; if (prop->arraydimension) { @@ -1975,7 +2000,8 @@ void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char * } switch (prop->type) { - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; if (prop->arraydimension) { @@ -2006,7 +2032,8 @@ void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char } switch (prop->type) { - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; if (prop->arraydimension) { @@ -2037,7 +2064,8 @@ void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char } switch (prop->type) { - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; if (get) eprop->get = (PropEnumGetFunc)get; @@ -2062,7 +2090,8 @@ void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const cha } switch (prop->type) { - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; if (get) sprop->get = (PropStringGetFunc)get; @@ -2088,7 +2117,8 @@ void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const ch } switch (prop->type) { - case PROP_POINTER: { + case PROP_POINTER: + { PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop; if (get) pprop->get = (PropPointerGetFunc)get; @@ -2116,7 +2146,8 @@ void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, con } switch (prop->type) { - case PROP_COLLECTION: { + case PROP_COLLECTION: + { CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; if (begin) cprop->begin = (PropCollectionBeginFunc)begin; @@ -2742,7 +2773,8 @@ int rna_parameter_size(PropertyRNA *parm) } else return sizeof(char *); - case PROP_POINTER: { + case PROP_POINTER: + { #ifdef RNA_RUNTIME if (parm->flag & PROP_RNAPTR) return sizeof(PointerRNA); @@ -2889,7 +2921,8 @@ void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA if (prop->description) prop->description = BLI_strdup(prop->description); switch (prop->type) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; if (bprop->defaultarray) { @@ -2899,7 +2932,8 @@ void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA } break; } - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; if (iprop->defaultarray) { @@ -2909,7 +2943,8 @@ void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA } break; } - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; if (eprop->item) { @@ -2928,7 +2963,8 @@ void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA } break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; if (fprop->defaultarray) { @@ -2938,7 +2974,8 @@ void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA } break; } - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; if (sprop->defaultvalue) sprop->defaultvalue = BLI_strdup(sprop->defaultvalue); @@ -2966,25 +3003,29 @@ void RNA_def_property_free_pointers(PropertyRNA *prop) MEM_freeN(prop->py_data); switch (prop->type) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; if (bprop->defaultarray) MEM_freeN((void *)bprop->defaultarray); break; } - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; if (iprop->defaultarray) MEM_freeN((void *)iprop->defaultarray); break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; if (fprop->defaultarray) MEM_freeN((void *)fprop->defaultarray); break; } - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; for (a = 0; a < eprop->totitem; a++) { @@ -2999,7 +3040,8 @@ void RNA_def_property_free_pointers(PropertyRNA *prop) if (eprop->item) MEM_freeN((void *)eprop->item); break; } - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; if (sprop->defaultvalue) MEM_freeN((void *)sprop->defaultvalue); diff --git a/source/blender/makesrna/intern/rna_fluidsim.c b/source/blender/makesrna/intern/rna_fluidsim.c index e84a290acb8..daa661175a1 100644 --- a/source/blender/makesrna/intern/rna_fluidsim.c +++ b/source/blender/makesrna/intern/rna_fluidsim.c @@ -24,15 +24,16 @@ * \ingroup RNA */ - #include <stdlib.h> +#include "DNA_object_fluidsim.h" + +#include "BLI_path_util.h" + #include "RNA_define.h" #include "rna_internal.h" -#include "DNA_object_fluidsim.h" - #include "WM_api.h" #include "WM_types.h" diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c index e246c6975b5..eb12a02aa99 100644 --- a/source/blender/makesrna/intern/rna_gpencil.c +++ b/source/blender/makesrna/intern/rna_gpencil.c @@ -203,7 +203,7 @@ static void rna_def_gpencil_layer(BlenderRNA *brna) RNA_def_property_editable_func(prop, "rna_GPencilLayer_active_frame_editable"); /* Drawing Color */ - prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR); + prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR_GAMMA); RNA_def_property_array(prop, 3); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Color", "Color for all strokes in this layer"); diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c index 03e446c9d91..62a06888613 100644 --- a/source/blender/makesrna/intern/rna_image.c +++ b/source/blender/makesrna/intern/rna_image.c @@ -42,6 +42,13 @@ #include "WM_types.h" #include "WM_api.h" +EnumPropertyItem image_generated_type_items[] = { + {IMA_GENTYPE_BLANK, "BLANK", 0, "Blank", "Generate a blank image"}, + {IMA_GENTYPE_GRID, "UV_GRID", 0, "UV Grid", "Generated grid to test UV mappings"}, + {IMA_GENTYPE_GRID_COLOR, "COLOR_GRID", 0, "Color Grid", "Generated improved UV grid to test UV mappings"}, + {0, NULL, 0, NULL, NULL} +}; + static EnumPropertyItem image_source_items[] = { {IMA_SRC_FILE, "FILE", 0, "Single Image", "Single image file"}, {IMA_SRC_SEQUENCE, "SEQUENCE", 0, "Image Sequence", "Multiple image files, as a sequence"}, @@ -436,12 +443,6 @@ static void rna_def_image(BlenderRNA *brna) {IMA_TYPE_COMPOSITE, "COMPOSITING", 0, "Compositing", ""}, {0, NULL, 0, NULL, NULL} }; - static const EnumPropertyItem prop_generated_type_items[] = { - {0, "BLANK", 0, "Blank", "Generate a blank image"}, - {1, "UV_GRID", 0, "UV Grid", "Generated grid to test UV mappings"}, - {2, "COLOR_GRID", 0, "Color Grid", "Generated improved UV grid to test UV mappings"}, - {0, NULL, 0, NULL, NULL} - }; static const EnumPropertyItem prop_mapping_items[] = { {0, "UV", 0, "UV Coordinates", "Use UV coordinates for mapping the image"}, {IMA_REFLECT, "REFLECTION", 0, "Reflection", "Use reflection mapping for mapping the image"}, @@ -520,7 +521,7 @@ static void rna_def_image(BlenderRNA *brna) /* generated image (image_generated_change_cb) */ prop = RNA_def_property(srna, "generated_type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "gen_type"); - RNA_def_property_enum_items(prop, prop_generated_type_items); + RNA_def_property_enum_items(prop, image_generated_type_items); RNA_def_property_ui_text(prop, "Generated Type", "Generated image type"); RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update"); diff --git a/source/blender/makesrna/intern/rna_main.c b/source/blender/makesrna/intern/rna_main.c index 17261c2c909..78e0fde5715 100644 --- a/source/blender/makesrna/intern/rna_main.c +++ b/source/blender/makesrna/intern/rna_main.c @@ -24,16 +24,15 @@ * \ingroup RNA */ - #include <stdlib.h> #include <string.h> +#include "BLI_path_util.h" + #include "RNA_define.h" #include "rna_internal.h" -#include "BKE_utildefines.h" - #ifdef RNA_RUNTIME #include "BKE_main.h" diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c index ae1e8b5548b..2d26fec0d50 100644 --- a/source/blender/makesrna/intern/rna_main_api.c +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -35,12 +35,13 @@ #include "DNA_ID.h" +#include "BLI_path_util.h" + #include "RNA_define.h" #include "RNA_access.h" #include "RNA_enum_types.h" -#include "rna_internal.h" -#include "BKE_utildefines.h" +#include "rna_internal.h" #ifdef RNA_RUNTIME @@ -556,7 +557,7 @@ Mask *rna_Main_mask_new(Main *UNUSED(bmain), const char *name) void rna_Main_masks_remove(Main *bmain, Mask *mask) { - BKE_mask_unlink(bmain, mask); + BKE_mask_free(bmain, mask); BKE_libblock_free(&bmain->mask, mask); /* XXX python now has invalid pointer? */ } diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 2f763a6ed0e..55dda3fc315 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -1526,6 +1526,15 @@ static void def_sh_tex_image(StructRNA *srna) {0, NULL, 0, NULL, NULL} }; + static const EnumPropertyItem prop_projection_items[] = { + {SHD_PROJ_FLAT, "FLAT", 0, "Flat", + "Image is projected flat using the X and Y coordinates of the texture vector"}, + {SHD_PROJ_BOX, "BOX", 0, "Box", + "Image is projected using different components for each side of the object space bounding box"}, + {0, NULL, 0, NULL, NULL} + }; + + PropertyRNA *prop; prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE); @@ -1543,6 +1552,15 @@ static void def_sh_tex_image(StructRNA *srna) RNA_def_property_ui_text(prop, "Color Space", "Image file color space"); RNA_def_property_update(prop, 0, "rna_Node_update"); + prop = RNA_def_property(srna, "projection", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, prop_projection_items); + RNA_def_property_ui_text(prop, "Projection", "Method to project 2D image on object with a 3D texture vector"); + RNA_def_property_update(prop, 0, "rna_Node_update"); + + prop = RNA_def_property(srna, "projection_blend", PROP_FLOAT, PROP_FACTOR); + RNA_def_property_ui_text(prop, "Projection Blend", "For box projection, amount of blend to use between sides"); + RNA_def_property_update(prop, 0, "rna_Node_update"); + prop = RNA_def_property(srna, "image_user", PROP_POINTER, PROP_NONE); RNA_def_property_flag(prop, PROP_NEVER_NULL); RNA_def_property_pointer_sdna(prop, NULL, "iuser"); @@ -1588,6 +1606,43 @@ static void def_sh_tex_checker(StructRNA *srna) def_sh_tex(srna); } +static void def_sh_tex_brick(StructRNA *srna) +{ + PropertyRNA *prop; + + RNA_def_struct_sdna_from(srna, "NodeTexBrick", "storage"); + def_sh_tex(srna); + + prop = RNA_def_property(srna, "offset_frequency", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "offset_freq"); + RNA_def_property_int_default(prop, 2); + RNA_def_property_range(prop, 1, 99); + RNA_def_property_ui_text(prop, "Offset Frequency", ""); + RNA_def_property_update(prop, 0, "rna_Node_update"); + + prop = RNA_def_property(srna, "squash_frequency", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "squash_freq"); + RNA_def_property_int_default(prop, 2); + RNA_def_property_range(prop, 1, 99); + RNA_def_property_ui_text(prop, "Squash Frequency", ""); + RNA_def_property_update(prop, 0, "rna_Node_update"); + + prop = RNA_def_property(srna, "offset", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "offset"); + RNA_def_property_float_default(prop, 0.5f); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Offset Amount", ""); + RNA_def_property_update(prop, 0, "rna_Node_update"); + + prop = RNA_def_property(srna, "squash", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "squash"); + RNA_def_property_float_default(prop, 1.0f); + RNA_def_property_range(prop, 0.0f, 99.0f); + RNA_def_property_ui_text(prop, "Squash Amount", ""); + RNA_def_property_update(prop, 0, "rna_Node_update"); + +} + static void def_sh_tex_magic(StructRNA *srna) { PropertyRNA *prop; diff --git a/source/blender/makesrna/intern/rna_nodetree_types.h b/source/blender/makesrna/intern/rna_nodetree_types.h index 15ad1c557a5..0baa4cc0838 100644 --- a/source/blender/makesrna/intern/rna_nodetree_types.h +++ b/source/blender/makesrna/intern/rna_nodetree_types.h @@ -91,6 +91,7 @@ DefNode( ShaderNode, SH_NODE_TEX_WAVE, def_sh_tex_wave, "TE DefNode( ShaderNode, SH_NODE_TEX_MUSGRAVE, def_sh_tex_musgrave, "TEX_MUSGRAVE", TexMusgrave, "Musgrave Texture", "" ) DefNode( ShaderNode, SH_NODE_TEX_VORONOI, def_sh_tex_voronoi, "TEX_VORONOI", TexVoronoi, "Voronoi Texture", "" ) DefNode( ShaderNode, SH_NODE_TEX_CHECKER, def_sh_tex_checker, "TEX_CHECKER", TexChecker, "Checker Texture", "" ) +DefNode( ShaderNode, SH_NODE_TEX_BRICK, def_sh_tex_brick, "TEX_BRICK", TexBrick, "Brick Texture", "" ) DefNode( ShaderNode, SH_NODE_TEX_COORD, 0, "TEX_COORD", TexCoord, "Texture Coordinate","" ) DefNode( CompositorNode, CMP_NODE_VIEWER, def_cmp_viewer, "VIEWER", Viewer, "Viewer", "" ) diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index 7ab359661c5..5bf1cc281ad 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -84,7 +84,8 @@ Mesh *rna_Object_to_mesh(Object *ob, ReportList *reports, Scene *sce, int apply_ switch (ob->type) { case OB_FONT: case OB_CURVE: - case OB_SURF: { + case OB_SURF: + { ListBase dispbase = {NULL, NULL}; DerivedMesh *derivedFinal = NULL; int uv_from_orco; @@ -163,7 +164,8 @@ Mesh *rna_Object_to_mesh(Object *ob, ReportList *reports, Scene *sce, int apply_ break; } - case OB_MBALL: { + case OB_MBALL: + { /* metaballs don't have modifiers, so just convert to mesh */ Object *basis_ob = BKE_mball_basis_find(sce, ob); /* todo, re-generatre for render-res */ diff --git a/source/blender/makesrna/intern/rna_render.c b/source/blender/makesrna/intern/rna_render.c index fff16650a93..d2e4e8edbfb 100644 --- a/source/blender/makesrna/intern/rna_render.c +++ b/source/blender/makesrna/intern/rna_render.c @@ -24,11 +24,12 @@ * \ingroup RNA */ - #include <stdlib.h> #include "DNA_scene_types.h" +#include "BLI_path_util.h" + #include "RNA_define.h" #include "RNA_enum_types.h" @@ -37,7 +38,6 @@ #include "RE_engine.h" #include "RE_pipeline.h" -#include "BKE_utildefines.h" #ifdef RNA_RUNTIME @@ -317,6 +317,7 @@ static void rna_def_render_engine(BlenderRNA *brna) RNA_def_property_flag(prop, PROP_REQUIRED); prop = RNA_def_int(func, "h", 0, 0, INT_MAX, "Height", "", 0, INT_MAX); RNA_def_property_flag(prop, PROP_REQUIRED); + RNA_def_string(func, "layer", "", 0, "Layer", "Single layer to get render result for"); /* NULL ok here */ prop = RNA_def_pointer(func, "result", "RenderResult", "Result", ""); RNA_def_function_return(func, prop); @@ -327,6 +328,8 @@ static void rna_def_render_engine(BlenderRNA *brna) func = RNA_def_function(srna, "end_result", "RE_engine_end_result"); prop = RNA_def_pointer(func, "result", "RenderResult", "Result", ""); RNA_def_property_flag(prop, PROP_REQUIRED); + prop = RNA_def_boolean(func, "cancel", 0, "Cancel", "Don't merge back results"); + RNA_def_property_flag(prop, PROP_REQUIRED); func = RNA_def_function(srna, "test_break", "RE_engine_test_break"); prop = RNA_def_boolean(func, "do_break", 0, "Break", ""); @@ -360,6 +363,19 @@ static void rna_def_render_engine(BlenderRNA *brna) RNA_def_property_pointer_sdna(prop, NULL, "camera_override"); RNA_def_property_struct_type(prop, "Object"); + prop = RNA_def_property(srna, "tile_x", PROP_INT, PROP_UNSIGNED); + RNA_def_property_int_sdna(prop, NULL, "tile_x"); + prop = RNA_def_property(srna, "tile_y", PROP_INT, PROP_UNSIGNED); + RNA_def_property_int_sdna(prop, NULL, "tile_y"); + + prop = RNA_def_property(srna, "resolution_x", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "resolution_x"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + + prop = RNA_def_property(srna, "resolution_y", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "resolution_y"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + /* registration */ prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 62631e60e2b..bd4d3e84883 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -3990,11 +3990,13 @@ static void rna_def_scene_render_data(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "mode", R_ENVMAP); RNA_def_property_ui_text(prop, "Environment Maps", "Calculate environment maps while rendering"); RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL); - + +#if 0 prop = RNA_def_property(srna, "use_radiosity", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "mode", R_RADIO); RNA_def_property_ui_text(prop, "Radiosity", "Calculate radiosity in a pre-process before rendering"); RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL); +#endif prop = RNA_def_property(srna, "use_sss", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "mode", R_SSS); diff --git a/source/blender/makesrna/intern/rna_scene_api.c b/source/blender/makesrna/intern/rna_scene_api.c index 61be48f3f02..69b61b47d8a 100644 --- a/source/blender/makesrna/intern/rna_scene_api.c +++ b/source/blender/makesrna/intern/rna_scene_api.c @@ -32,13 +32,13 @@ #include <stdlib.h> #include <stdio.h> +#include "BLI_path_util.h" + #include "RNA_define.h" #include "DNA_anim_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" -#include "BKE_utildefines.h" - #ifdef RNA_RUNTIME diff --git a/source/blender/makesrna/intern/rna_sensor.c b/source/blender/makesrna/intern/rna_sensor.c index 00e8ed5289f..314082dfd02 100644 --- a/source/blender/makesrna/intern/rna_sensor.c +++ b/source/blender/makesrna/intern/rna_sensor.c @@ -417,6 +417,11 @@ static void rna_def_mouse_sensor(BlenderRNA *brna) RNA_def_property_enum_items(prop, mouse_event_items); RNA_def_property_ui_text(prop, "Mouse Event", "Type of event this mouse sensor should trigger on"); RNA_def_property_update(prop, NC_LOGIC, NULL); + + prop = RNA_def_property(srna, "use_pulse", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_MOUSE_FOCUS_PULSE); + RNA_def_property_ui_text(prop, "Pulse", "Moving the mouse over a different object generates a pulse"); + RNA_def_property_update(prop, NC_LOGIC, NULL); } static void rna_def_touch_sensor(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_sequencer.c b/source/blender/makesrna/intern/rna_sequencer.c index a3884b62ec1..e3e467a9abb 100644 --- a/source/blender/makesrna/intern/rna_sequencer.c +++ b/source/blender/makesrna/intern/rna_sequencer.c @@ -56,7 +56,6 @@ typedef struct EffectInfo { const char *ui_desc; void (*func)(StructRNA *); int inputs; - int supports_mask; } EffectInfo; EnumPropertyItem sequence_modifier_type_items[] = { @@ -244,28 +243,6 @@ static void rna_Sequence_channel_set(PointerRNA *ptr, int value) BKE_sequencer_sort(scene); } -/* properties that need to allocate structs */ -static void rna_Sequence_use_color_balance_set(PointerRNA *ptr, int value) -{ - Sequence *seq = (Sequence *)ptr->data; - int c; - - if (value) { - seq->flag |= SEQ_USE_COLOR_BALANCE; - if (seq->strip->color_balance == NULL) { - seq->strip->color_balance = MEM_callocN(sizeof(struct StripColorBalance), "StripColorBalance"); - for (c = 0; c < 3; c++) { - seq->strip->color_balance->lift[c] = 1.0f; - seq->strip->color_balance->gamma[c] = 1.0f; - seq->strip->color_balance->gain[c] = 1.0f; - } - } - } - else { - seq->flag ^= SEQ_USE_COLOR_BALANCE; - } -} - static void rna_Sequence_use_proxy_set(PointerRNA *ptr, int value) { Sequence *seq = (Sequence *)ptr->data; @@ -608,13 +585,6 @@ static int rna_Sequence_input_count_get(PointerRNA *ptr) return BKE_sequence_effect_get_num_inputs(seq->type); } -static int rna_Sequence_supports_mask_get(PointerRNA *ptr) -{ - Sequence *seq = (Sequence *)(ptr->data); - - return BKE_sequence_effect_get_supports_mask(seq->type); -} - #if 0 static void rna_SoundSequence_filename_set(PointerRNA *ptr, const char *value) { @@ -642,26 +612,12 @@ static void rna_Sequence_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Point } } -static int rna_Sequence_otherSequence_poll(PointerRNA *ptr, PointerRNA value) -{ - Sequence *seq = (Sequence *) ptr->data; - Sequence *cur = (Sequence *) value.data; - - if (seq == cur) - return FALSE; - - if (BKE_sequence_check_depend(seq, cur)) - return FALSE; - - return TRUE; -} - static void rna_Sequence_update_reopen_files(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { Scene *scene = (Scene *) ptr->id.data; Editing *ed = BKE_sequencer_editing_get(scene, FALSE); - BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE, FALSE); + BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE); if (RNA_struct_is_a(ptr->type, &RNA_SoundSequence)) BKE_sequencer_update_sound_bounds(scene, ptr->data); @@ -1631,16 +1587,6 @@ static void rna_def_filter_video(StructRNA *srna) RNA_def_property_ui_text(prop, "Strobe", "Only display every nth frame"); RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); - prop = RNA_def_property(srna, "use_color_balance", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", SEQ_USE_COLOR_BALANCE); - RNA_def_property_ui_text(prop, "Use Color Balance", "(3-Way color correction) on input"); - RNA_def_property_boolean_funcs(prop, NULL, "rna_Sequence_use_color_balance_set"); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); - - prop = RNA_def_property(srna, "color_balance", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, NULL, "strip->color_balance"); - RNA_def_property_ui_text(prop, "Color Balance", ""); - prop = RNA_def_property(srna, "use_translation", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", SEQ_USE_TRANSFORM); RNA_def_property_ui_text(prop, "Use Translation", "Translate image before processing"); @@ -1706,7 +1652,7 @@ static void rna_def_input(StructRNA *srna) RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); } -static void rna_def_effect_inputs(StructRNA *srna, int count, int supports_mask) +static void rna_def_effect_inputs(StructRNA *srna, int count) { PropertyRNA *prop; @@ -1714,10 +1660,6 @@ static void rna_def_effect_inputs(StructRNA *srna, int count, int supports_mask) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_int_funcs(prop, "rna_Sequence_input_count_get", NULL, NULL); - prop = RNA_def_property(srna, "is_supports_mask", PROP_INT, PROP_UNSIGNED); - RNA_def_property_clear_flag(prop, PROP_EDITABLE); - RNA_def_property_int_funcs(prop, "rna_Sequence_supports_mask_get", NULL, NULL); - if (count >= 1) { prop = RNA_def_property(srna, "input_1", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "seq1"); @@ -1740,15 +1682,6 @@ static void rna_def_effect_inputs(StructRNA *srna, int count, int supports_mask) RNA_def_property_ui_text(prop, "Input 3", "Third input for the effect strip"); } */ - - if (supports_mask) { - prop = RNA_def_property(srna, "input_mask_strip", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, NULL, "mask_sequence"); - RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_Sequence_otherSequence_poll"); - RNA_def_property_flag(prop, PROP_EDITABLE); - RNA_def_property_ui_text(prop, "Mask", "Mask input for the effect strip"); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); - } } static void rna_def_image(BlenderRNA *brna) @@ -2189,28 +2122,28 @@ static void rna_def_speed_control(StructRNA *srna) } static EffectInfo def_effects[] = { - {"AddSequence", "Add Sequence", "Add Sequence", NULL, 2, FALSE}, + {"AddSequence", "Add Sequence", "Add Sequence", NULL, 2}, {"AdjustmentSequence", "Adjustment Layer Sequence", - "Sequence strip to perform filter adjustments to layers below", rna_def_input, 0, TRUE}, - {"AlphaOverSequence", "Alpha Over Sequence", "Alpha Over Sequence", NULL, 2, FALSE}, - {"AlphaUnderSequence", "Alpha Under Sequence", "Alpha Under Sequence", NULL, 2, FALSE}, + "Sequence strip to perform filter adjustments to layers below", rna_def_input, 0}, + {"AlphaOverSequence", "Alpha Over Sequence", "Alpha Over Sequence", NULL, 2}, + {"AlphaUnderSequence", "Alpha Under Sequence", "Alpha Under Sequence", NULL, 2}, {"ColorSequence", "Color Sequence", - "Sequence strip creating an image filled with a single color", rna_def_solid_color, 0, FALSE}, - {"CrossSequence", "Cross Sequence", "Cross Sequence", NULL, 2, FALSE}, - {"GammaCrossSequence", "Gamma Cross Sequence", "Gamma Cross Sequence", NULL, 2, FALSE}, - {"GlowSequence", "Glow Sequence", "Sequence strip creating a glow effect", rna_def_glow, 1, FALSE}, + "Sequence strip creating an image filled with a single color", rna_def_solid_color, 0}, + {"CrossSequence", "Cross Sequence", "Cross Sequence", NULL, 2}, + {"GammaCrossSequence", "Gamma Cross Sequence", "Gamma Cross Sequence", NULL, 2}, + {"GlowSequence", "Glow Sequence", "Sequence strip creating a glow effect", rna_def_glow, 1}, {"MulticamSequence", "Multicam Select Sequence", "Sequence strip to perform multicam editing", - rna_def_multicam, 0, FALSE}, - {"MultiplySequence", "Multiply Sequence", "Multiply Sequence", NULL, 2, FALSE}, - {"OverDropSequence", "Over Drop Sequence", "Over Drop Sequence", NULL, 2, FALSE}, + rna_def_multicam, 0}, + {"MultiplySequence", "Multiply Sequence", "Multiply Sequence", NULL, 2}, + {"OverDropSequence", "Over Drop Sequence", "Over Drop Sequence", NULL, 2}, {"SpeedControlSequence", "SpeedControl Sequence", - "Sequence strip to control the speed of other strips", rna_def_speed_control, 1, FALSE}, - {"SubtractSequence", "Subtract Sequence", "Subtract Sequence", NULL, 2, FALSE}, + "Sequence strip to control the speed of other strips", rna_def_speed_control, 1}, + {"SubtractSequence", "Subtract Sequence", "Subtract Sequence", NULL, 2}, {"TransformSequence", "Transform Sequence", - "Sequence strip applying affine transformations to other strips", rna_def_transform, 1, FALSE}, + "Sequence strip applying affine transformations to other strips", rna_def_transform, 1}, {"WipeSequence", "Wipe Sequence", "Sequence strip creating a wipe transition", - rna_def_wipe, 1, FALSE}, - {"", "", "", NULL, 0, FALSE} + rna_def_wipe, 1}, + {"", "", "", NULL, 0} }; static void rna_def_effects(BlenderRNA *brna) @@ -2223,7 +2156,7 @@ static void rna_def_effects(BlenderRNA *brna) RNA_def_struct_ui_text(srna, effect->ui_name, effect->ui_desc); RNA_def_struct_sdna(srna, "Sequence"); - rna_def_effect_inputs(srna, effect->inputs, effect->supports_mask); + rna_def_effect_inputs(srna, effect->inputs); if (effect->func) effect->func(srna); diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index ad14c60e532..a00e8bfea2d 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -531,12 +531,7 @@ static PointerRNA rna_SpaceImageEditor_uvedit_get(PointerRNA *ptr) static void rna_SpaceImageEditor_mode_update(Main *bmain, Scene *scene, PointerRNA *ptr) { - SpaceImage *sima = (SpaceImage *)(ptr->data); - if (sima->mode == SI_MODE_PAINT) { - BKE_paint_init(&scene->toolsettings->imapaint.paint, PAINT_CURSOR_TEXTURE_PAINT); - - ED_space_image_paint_update(bmain->wm.first, scene->toolsettings); - } + ED_space_image_paint_update(bmain->wm.first, scene->toolsettings); } static int rna_SpaceImageEditor_show_render_get(PointerRNA *ptr) @@ -1560,7 +1555,7 @@ static void rna_def_space_view3d(BlenderRNA *brna) RNA_def_property_float_sdna(prop, NULL, "near"); RNA_def_property_range(prop, 0.001f, FLT_MAX); RNA_def_property_float_default(prop, 0.1f); - RNA_def_property_ui_text(prop, "Clip Start", "3D View near clipping distance"); + RNA_def_property_ui_text(prop, "Clip Start", "3D View near clipping distance (perspective view only)"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); prop = RNA_def_property(srna, "clip_end", PROP_FLOAT, PROP_DISTANCE); diff --git a/source/blender/makesrna/intern/rna_texture_api.c b/source/blender/makesrna/intern/rna_texture_api.c index ff8940129a1..e62b3ecd804 100644 --- a/source/blender/makesrna/intern/rna_texture_api.c +++ b/source/blender/makesrna/intern/rna_texture_api.c @@ -24,14 +24,13 @@ * \ingroup RNA */ - #include <stdlib.h> #include <stdio.h> #include <string.h> +#include "BLI_path_util.h" #include "RNA_define.h" -#include "BKE_utildefines.h" #ifdef RNA_RUNTIME diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index ed057235f0d..018022fdde9 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -2992,11 +2992,12 @@ static void rna_def_userdef_system(BlenderRNA *brna) /* locale according to http://www.roseindia.net/tutorials/I18N/locales-list.shtml */ /* if you edit here, please also edit the source/blender/blenfont/intern/blf_lang.c 's locales */ /* Note: As this list is in alphabetical order, and not defined order, - * here is the highest define currently in use: 31 (Hungarian). */ + * here is the highest define currently in use: 33 (Hebrew). */ static EnumPropertyItem language_items[] = { { 0, "", 0, N_("Nearly done"), ""}, { 0, "DEFAULT", 0, "Default (Default)", ""}, {21, "ARABIC", 0, "Arabic (ﺔﻴﺑﺮﻌﻟﺍ)", "ar_EG"}, + {32, "BRAZILIANPORTUGUESE", 0, "Brazilian Portuguese (Português do Brasil)", "pt_BR"}, { 1, "ENGLISH", 0, "English (English)", "en_US"}, { 8, "FRENCH", 0, "French (Français)", "fr_FR"}, { 4, "ITALIAN", 0, "Italian (Italiano)", "it_IT"}, @@ -3017,6 +3018,7 @@ static void rna_def_userdef_system(BlenderRNA *brna) { 6, "FINNISH", 0, "Finnish (Suomi)", "fi_FI"}, { 5, "GERMAN", 0, "German (Deutsch)", "de_DE"}, {23, "GREEK", 0, "Greek (Ελληνικά)", "el_GR"}, + {33, "HEBREW", 0, "Hebrew (עִבְרִית)", "he_IL"}, {31, "HUNGARIAN", 0, "Hungarian (magyar)", "hu_HU"}, {27, "INDONESIAN", 0, "Indonesian (Bahasa indonesia)", "id_ID"}, {29, "KYRGYZ", 0, "Kyrgyz (Кыргыз тили)", "ky_KG"}, @@ -3273,6 +3275,7 @@ static void rna_def_userdef_system(BlenderRNA *brna) RNA_def_property_enum_items(prop, compute_device_type_items); RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_userdef_compute_device_type_itemf"); RNA_def_property_ui_text(prop, "Compute Device Type", "Device to use for computation (rendering with Cycles)"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_PROPERTIES, NULL); prop = RNA_def_property(srna, "compute_device", PROP_ENUM, PROP_NONE); RNA_def_property_flag(prop, PROP_ENUM_NO_CONTEXT); diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c index d910ed7900c..ae4d5dc493e 100644 --- a/source/blender/makesrna/intern/rna_wm_api.c +++ b/source/blender/makesrna/intern/rna_wm_api.c @@ -83,9 +83,10 @@ void rna_event_timer_remove(struct wmWindowManager *wm, wmTimer *timer) } static wmKeyMapItem *rna_KeyMap_item_new(wmKeyMap *km, ReportList *reports, const char *idname, int type, int value, - int any, int shift, int ctrl, int alt, int oskey, int keymodifier) + int any, int shift, int ctrl, int alt, int oskey, int keymodifier, int head) { /* wmWindowManager *wm = CTX_wm_manager(C); */ + wmKeyMapItem *kmi = NULL; char idname_bl[OP_MAX_TYPENAME]; int modifier = 0; @@ -103,8 +104,19 @@ static wmKeyMapItem *rna_KeyMap_item_new(wmKeyMap *km, ReportList *reports, cons if (oskey) modifier |= KM_OSKEY; if (any) modifier = KM_ANY; - - return WM_keymap_add_item(km, idname_bl, type, value, modifier, keymodifier); + + /* create keymap item */ + kmi = WM_keymap_add_item(km, idname_bl, type, value, modifier, keymodifier); + + /* [#32437] allow scripts to define hotkeys that get added to start of keymap + * so that they stand a chance against catch-all defines later on + */ + if (head) { + BLI_remlink(&km->items, kmi); + BLI_addhead(&km->items, kmi); + } + + return kmi; } static wmKeyMapItem *rna_KeyMap_item_new_modal(wmKeyMap *km, ReportList *reports, const char *propvalue_str, @@ -425,6 +437,9 @@ void RNA_api_keymapitems(StructRNA *srna) RNA_def_boolean(func, "alt", 0, "Alt", ""); RNA_def_boolean(func, "oskey", 0, "OS Key", ""); RNA_def_enum(func, "key_modifier", event_type_items, 0, "Key Modifier", ""); + RNA_def_boolean(func, "head", 0, "At Head", + "Force item to be added at start (not end) of key map so that " + "it doesn't get blocked by an existing key map item"); parm = RNA_def_pointer(func, "item", "KeyMapItem", "Item", "Added key map item"); RNA_def_function_return(func, parm); diff --git a/source/blender/makesrna/rna_cleanup/rna_cleaner.py b/source/blender/makesrna/rna_cleanup/rna_cleaner.py index b75d177d809..e3359fbae59 100755 --- a/source/blender/makesrna/rna_cleanup/rna_cleaner.py +++ b/source/blender/makesrna/rna_cleanup/rna_cleaner.py @@ -60,7 +60,7 @@ def check_commandline(): usage() if sys.argv[1] == '-h': help() - elif not (sys.argv[1].endswith(".txt") or sys.argv[1].endswith(".py")): + elif not sys.argv[1].endswith((".txt", ".py")): print ('\nBad input file extension... exiting.') usage() else: diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c index 1c98880c3db..9acac6d00cd 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.c +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c @@ -51,7 +51,6 @@ #include "BKE_fluidsim.h" /* ensure definitions here match */ #include "BKE_cdderivedmesh.h" #include "BKE_mesh.h" -#include "BKE_utildefines.h" #include "BKE_global.h" /* G.main->name only */ #include "MOD_fluidsim_util.h" diff --git a/source/blender/modifiers/intern/MOD_mirror.c b/source/blender/modifiers/intern/MOD_mirror.c index 6f3d47b3426..febc4190fdf 100644 --- a/source/blender/modifiers/intern/MOD_mirror.c +++ b/source/blender/modifiers/intern/MOD_mirror.c @@ -43,7 +43,6 @@ #include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_deform.h" -#include "BKE_utildefines.h" #include "BKE_tessmesh.h" #include "MEM_guardedalloc.h" diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c index 21836453eed..3bf8b9ffacc 100644 --- a/source/blender/modifiers/intern/MOD_ocean.c +++ b/source/blender/modifiers/intern/MOD_ocean.c @@ -37,7 +37,6 @@ #include "BKE_global.h" #include "BKE_modifier.h" #include "BKE_ocean.h" -#include "BKE_utildefines.h" #include "BLI_blenlib.h" #include "BLI_math.h" diff --git a/source/blender/modifiers/intern/MOD_particleinstance.c b/source/blender/modifiers/intern/MOD_particleinstance.c index c034832bfb4..e64e80efde3 100644 --- a/source/blender/modifiers/intern/MOD_particleinstance.c +++ b/source/blender/modifiers/intern/MOD_particleinstance.c @@ -105,6 +105,41 @@ static void foreachObjectLink(ModifierData *md, Object *ob, walk(userData, ob, &pimd->ob); } +static int particle_skip(ParticleInstanceModifierData *pimd, ParticleSystem *psys, int p) +{ + ParticleData *pa; + + if (pimd->flag & eParticleInstanceFlag_Parents) { + if (p >= psys->totpart) { + if (psys->part->childtype == PART_CHILD_PARTICLES) { + pa = psys->particles + (psys->child + p - psys->totpart)->parent; + } + else { + pa = NULL; + } + } + else { + pa = psys->particles + p; + } + } + else { + if (psys->part->childtype == PART_CHILD_PARTICLES) { + pa = psys->particles + (psys->child + p)->parent; + } + else { + pa = NULL; + } + } + + if (pa) { + if (pa->alive == PARS_UNBORN && (pimd->flag & eParticleInstanceFlag_Unborn) == 0) return 1; + if (pa->alive == PARS_ALIVE && (pimd->flag & eParticleInstanceFlag_Alive) == 0) return 1; + if (pa->alive == PARS_DEAD && (pimd->flag & eParticleInstanceFlag_Dead) == 0) return 1; + } + + return 0; +} + static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *derivedData, ModifierApplyFlag UNUSED(flag)) @@ -113,11 +148,13 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *) md; ParticleSimulationData sim; ParticleSystem *psys = NULL; - ParticleData *pa = NULL, *pars = NULL; + ParticleData *pa = NULL; MPoly *mpoly, *orig_mpoly; MLoop *mloop, *orig_mloop; MVert *mvert, *orig_mvert; - int i, totvert, totpoly, totloop, maxvert, maxpoly, maxloop, totpart = 0, first_particle = 0; + int totvert, totpoly, totloop /* , totedge */; + int maxvert, maxpoly, maxloop, totpart = 0, first_particle = 0; + int k, p, p_skip; short track = ob->trackflag % 3, trackneg, axis = pimd->axis; float max_co = 0.0, min_co = 0.0, temp_co[3], cross[3]; float *size = NULL; @@ -153,7 +190,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, sim.psmd = psys_get_modifier(pimd->ob, psys); if (pimd->flag & eParticleInstanceFlag_UseSize) { - int p; float *si; si = size = MEM_callocN(totpart * sizeof(float), "particle size array"); @@ -171,15 +207,24 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, } } - pars = psys->particles; - totvert = dm->getNumVerts(dm); totpoly = dm->getNumPolys(dm); totloop = dm->getNumLoops(dm); + /* totedge = dm->getNumEdges(dm); */ /* UNUSED */ - maxvert = totvert * totpart; - maxpoly = totpoly * totpart; - maxloop = totloop * totpart; + /* count particles */ + maxvert = 0; + maxpoly = 0; + maxloop = 0; + + for (p = 0; p < totpart; p++) { + if (particle_skip(pimd, psys, p)) + continue; + + maxvert += totvert; + maxpoly += totpoly; + maxloop += totloop; + } psys->lattice = psys_get_lattice(&sim); @@ -191,127 +236,110 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, max_co = max_r[track]; } - result = CDDM_from_template(dm, maxvert, dm->getNumEdges(dm) * totpart, 0, maxloop, maxpoly); + result = CDDM_from_template(dm, maxvert, 0, 0, maxloop, maxpoly); mvert = result->getVertArray(result); orig_mvert = dm->getVertArray(dm); - for (i = 0; i < maxvert; i++) { - MVert *inMV; - MVert *mv = mvert + i; - ParticleKey state; - - inMV = orig_mvert + i % totvert; - DM_copy_vert_data(dm, result, i % totvert, i, 1); - *mv = *inMV; - - /*change orientation based on object trackflag*/ - copy_v3_v3(temp_co, mv->co); - mv->co[axis] = temp_co[track]; - mv->co[(axis + 1) % 3] = temp_co[(track + 1) % 3]; - mv->co[(axis + 2) % 3] = temp_co[(track + 2) % 3]; - - if ((psys->flag & (PSYS_HAIR_DONE | PSYS_KEYED) || psys->pointcache->flag & PTCACHE_BAKED) && - (pimd->flag & eParticleInstanceFlag_Path)) - { - float ran = 0.0f; - if (pimd->random_position != 0.0f) { - BLI_srandom(psys->seed + (i / totvert) % totpart); - ran = pimd->random_position * BLI_frand(); - } - - if (pimd->flag & eParticleInstanceFlag_KeepShape) { - state.time = pimd->position * (1.0f - ran); - } - else { - state.time = (mv->co[axis] - min_co) / (max_co - min_co) * pimd->position * (1.0f - ran); - - if (trackneg) - state.time = 1.0f - state.time; - - mv->co[axis] = 0.0; - } - - psys_get_particle_on_path(&sim, first_particle + i / totvert, &state, 1); - - normalize_v3(state.vel); + mpoly = result->getPolyArray(result); + orig_mpoly = dm->getPolyArray(dm); + mloop = result->getLoopArray(result); + orig_mloop = dm->getLoopArray(dm); - /* TODO: incremental rotations somehow */ - if (state.vel[axis] < -0.9999f || state.vel[axis] > 0.9999f) { - unit_qt(state.rot); - } - else { - float temp[3] = {0.0f, 0.0f, 0.0f}; - temp[axis] = 1.0f; + for (p = 0, p_skip = 0; p < totpart; p++) { + /* skip particle? */ + if (particle_skip(pimd, psys, p)) + continue; + + /* set vertices coordinates */ + for (k = 0; k < totvert; k++) { + ParticleKey state; + MVert *inMV; + MVert *mv = mvert + p_skip * totvert + k; + + inMV = orig_mvert + k; + DM_copy_vert_data(dm, result, k, p_skip * totvert + k, 1); + *mv = *inMV; + + /*change orientation based on object trackflag*/ + copy_v3_v3(temp_co, mv->co); + mv->co[axis] = temp_co[track]; + mv->co[(axis + 1) % 3] = temp_co[(track + 1) % 3]; + mv->co[(axis + 2) % 3] = temp_co[(track + 2) % 3]; + + /* get particle state */ + if ((psys->flag & (PSYS_HAIR_DONE | PSYS_KEYED) || psys->pointcache->flag & PTCACHE_BAKED) && + (pimd->flag & eParticleInstanceFlag_Path)) + { + float ran = 0.0f; + if (pimd->random_position != 0.0f) { + BLI_srandom(psys->seed + p); + ran = pimd->random_position * BLI_frand(); + } - cross_v3_v3v3(cross, temp, state.vel); + if (pimd->flag & eParticleInstanceFlag_KeepShape) { + state.time = pimd->position * (1.0f - ran); + } + else { + state.time = (mv->co[axis] - min_co) / (max_co - min_co) * pimd->position * (1.0f - ran); - /* state.vel[axis] is the only component surviving from a dot product with the axis */ - axis_angle_to_quat(state.rot, cross, saacos(state.vel[axis])); - } - } - else { - state.time = -1.0; - psys_get_particle_state(&sim, first_particle + i / totvert, &state, 1); - } + if (trackneg) + state.time = 1.0f - state.time; - mul_qt_v3(state.rot, mv->co); - if (pimd->flag & eParticleInstanceFlag_UseSize) - mul_v3_fl(mv->co, size[i / totvert]); - add_v3_v3(mv->co, state.co); - } + mv->co[axis] = 0.0; + } - mpoly = result->getPolyArray(result); - orig_mpoly = dm->getPolyArray(dm); - mloop = result->getLoopArray(result); - orig_mloop = dm->getLoopArray(dm); + psys_get_particle_on_path(&sim, first_particle + p, &state, 1); - for (i = 0; i < maxpoly; i++) { - MPoly *inMP = orig_mpoly + i % totpoly; - MPoly *mp = mpoly + i; + normalize_v3(state.vel); - if (pimd->flag & eParticleInstanceFlag_Parents) { - if (i / totpoly >= psys->totpart) { - if (psys->part->childtype == PART_CHILD_PARTICLES) { - pa = psys->particles + (psys->child + i / totpoly - psys->totpart)->parent; + /* TODO: incremental rotations somehow */ + if (state.vel[axis] < -0.9999f || state.vel[axis] > 0.9999f) { + unit_qt(state.rot); } else { - pa = NULL; + float temp[3] = {0.0f, 0.0f, 0.0f}; + temp[axis] = 1.0f; + + cross_v3_v3v3(cross, temp, state.vel); + + /* state.vel[axis] is the only component surviving from a dot product with the axis */ + axis_angle_to_quat(state.rot, cross, saacos(state.vel[axis])); } } else { - pa = pars + i / totpoly; - } - } - else { - if (psys->part->childtype == PART_CHILD_PARTICLES) { - pa = psys->particles + (psys->child + i / totpoly)->parent; - } - else { - pa = NULL; + state.time = -1.0; + psys_get_particle_state(&sim, first_particle + p, &state, 1); } - } - if (pa) { - if (pa->alive == PARS_UNBORN && (pimd->flag & eParticleInstanceFlag_Unborn) == 0) continue; - if (pa->alive == PARS_ALIVE && (pimd->flag & eParticleInstanceFlag_Alive) == 0) continue; - if (pa->alive == PARS_DEAD && (pimd->flag & eParticleInstanceFlag_Dead) == 0) continue; + mul_qt_v3(state.rot, mv->co); + if (pimd->flag & eParticleInstanceFlag_UseSize) + mul_v3_fl(mv->co, size[p]); + add_v3_v3(mv->co, state.co); } - DM_copy_poly_data(dm, result, i % totpoly, i, 1); - *mp = *inMP; - mp->loopstart += (i / totpoly) * totloop; + /* create polys and loops */ + for (k = 0; k < totpoly; k++) { + MPoly *inMP = orig_mpoly + k; + MPoly *mp = mpoly + p_skip * totpoly + k; + + DM_copy_poly_data(dm, result, k, p_skip * totpoly + k, 1); + *mp = *inMP; + mp->loopstart += p_skip * totloop; - { - MLoop *inML = orig_mloop + inMP->loopstart; - MLoop *ml = mloop + mp->loopstart; - int j = mp->totloop; + { + MLoop *inML = orig_mloop + inMP->loopstart; + MLoop *ml = mloop + mp->loopstart; + int j = mp->totloop; - DM_copy_loop_data(dm, result, inMP->loopstart, mp->loopstart, j); - for (; j; j--, ml++, inML++) { - ml->v = inML->v + ((i / totpoly) * totvert); + DM_copy_loop_data(dm, result, inMP->loopstart, mp->loopstart, j); + for (; j; j--, ml++, inML++) { + ml->v = inML->v + (p_skip * totvert); + } } } + + p_skip++; } CDDM_calc_edges(result); diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c index aed8a70a805..4fd2c658380 100644 --- a/source/blender/modifiers/intern/MOD_screw.c +++ b/source/blender/modifiers/intern/MOD_screw.c @@ -857,7 +857,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, mp_new->loopstart = mpoly_index * 4; mp_new->totloop = 4; - mp_new->flag = ME_SMOOTH; + mp_new->flag = mpoly_flag; origindex[mpoly_index] = ORIGINDEX_NONE; mp_new++; ml_new += 4; diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c index d5deb50e1f9..22b1e33e2a6 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.c +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c @@ -474,7 +474,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der float *dists_e = use_trgt_edges ? MEM_mallocN(sizeof(float) * numIdx, "dists_e") : NULL; float *dists_f = use_trgt_faces ? MEM_mallocN(sizeof(float) * numIdx, "dists_f") : NULL; - space_transform_setup(&loc2trgt, ob, obr); + SPACE_TRANSFORM_SETUP(&loc2trgt, ob, obr); get_vert2geom_distance(numIdx, v_cos, dists_v, dists_e, dists_f, target_dm, &loc2trgt); for (i = 0; i < numIdx; i++) { diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index e1adb419a8a..08e0e7b0f93 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -180,6 +180,7 @@ set(SRC shader/nodes/node_shader_tex_voronoi.c shader/nodes/node_shader_tex_wave.c shader/nodes/node_shader_tex_checker.c + shader/nodes/node_shader_tex_brick.c shader/node_shader_tree.c shader/node_shader_util.c diff --git a/source/blender/nodes/NOD_shader.h b/source/blender/nodes/NOD_shader.h index 6b000181953..49428c06e5f 100644 --- a/source/blender/nodes/NOD_shader.h +++ b/source/blender/nodes/NOD_shader.h @@ -69,6 +69,7 @@ void register_node_type_sh_invert(struct bNodeTreeType *ttype); void register_node_type_sh_seprgb(struct bNodeTreeType *ttype); void register_node_type_sh_combrgb(struct bNodeTreeType *ttype); void register_node_type_sh_hue_sat(struct bNodeTreeType *ttype); +void register_node_type_sh_tex_brick(struct bNodeTreeType *ttype); void register_node_type_sh_attribute(struct bNodeTreeType *ttype); void register_node_type_sh_geometry(struct bNodeTreeType *ttype); diff --git a/source/blender/nodes/composite/node_composite_tree.c b/source/blender/nodes/composite/node_composite_tree.c index 37444b6da92..e1510f9f813 100644 --- a/source/blender/nodes/composite/node_composite_tree.c +++ b/source/blender/nodes/composite/node_composite_tree.c @@ -48,7 +48,6 @@ #include "BKE_main.h" #include "BKE_node.h" #include "BKE_tracking.h" -#include "BKE_utildefines.h" #include "node_common.h" #include "node_exec.h" @@ -607,11 +606,9 @@ static void ntreeCompositExecTreeOld(bNodeTree *ntree, RenderData *rd, int do_pr bNode *node; ListBase threads; ThreadData thdata; - int totnode, curnode, rendering= 1, n; - bNodeTreeExec *exec= ntree->execdata; - - if (ntree == NULL) return; - + int totnode, curnode, rendering = TRUE, n; + bNodeTreeExec *exec = ntree->execdata; + if (do_preview) ntreeInitPreview(ntree, 0, 0); @@ -788,7 +785,6 @@ static void force_hidden_passes(bNode *node, int passflag) if (!(passflag & SCE_PASS_TRANSM_INDIRECT)) sock->flag |= SOCK_UNAVAIL; sock= BLI_findlink(&node->outputs, RRES_OUT_TRANSM_COLOR); if (!(passflag & SCE_PASS_TRANSM_COLOR)) sock->flag |= SOCK_UNAVAIL; - sock= BLI_findlink(&node->outputs, RRES_OUT_TRANSM_COLOR); } /* based on rules, force sockets hidden always */ diff --git a/source/blender/nodes/composite/nodes/node_composite_channelMatte.c b/source/blender/nodes/composite/nodes/node_composite_channelMatte.c index cda6fa85d74..06b77de463b 100644 --- a/source/blender/nodes/composite/nodes/node_composite_channelMatte.c +++ b/source/blender/nodes/composite/nodes/node_composite_channelMatte.c @@ -82,15 +82,18 @@ static void do_channel_matte(bNode *node, float *out, float *in) } case 1: { /* Alpha=G-MAX(R, B) */ switch (node->custom2) { - case 1: { + case 1: + { alpha=in[0]-MAX2(in[1], in[2]); break; } - case 2: { + case 2: + { alpha=in[1]-MAX2(in[0], in[2]); break; } - case 3: { + case 3: + { alpha=in[2]-MAX2(in[0], in[1]); break; } diff --git a/source/blender/nodes/composite/nodes/node_composite_outputFile.c b/source/blender/nodes/composite/nodes/node_composite_outputFile.c index 399cb1d1557..2d9b9348668 100644 --- a/source/blender/nodes/composite/nodes/node_composite_outputFile.c +++ b/source/blender/nodes/composite/nodes/node_composite_outputFile.c @@ -33,8 +33,6 @@ #include <string.h> #include "BLI_path_util.h" -#include "BKE_utildefines.h" - #include "node_composite_util.h" #include "IMB_imbuf.h" diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c index ffa636fa952..fdbe82efeda 100644 --- a/source/blender/nodes/intern/node_common.c +++ b/source/blender/nodes/intern/node_common.c @@ -45,7 +45,6 @@ #include "BKE_main.h" #include "BLI_math.h" #include "BKE_node.h" -#include "BKE_utildefines.h" #include "RNA_access.h" #include "RNA_types.h" diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.c index 8f9214fa1b2..27258c45fe5 100644 --- a/source/blender/nodes/intern/node_util.c +++ b/source/blender/nodes/intern/node_util.c @@ -73,6 +73,12 @@ void node_copy_standard_storage(bNode *orig_node, bNode *new_node) new_node->storage= MEM_dupallocN(orig_node->storage); } +void *node_initexec_curves(bNode *node) +{ + curvemapping_initialize(node->storage); + return NULL; /* unused return */ +} + /**** Labels ****/ const char *node_blend_label(bNode *node) diff --git a/source/blender/nodes/intern/node_util.h b/source/blender/nodes/intern/node_util.h index 6f167e35262..9f9caef14e2 100644 --- a/source/blender/nodes/intern/node_util.h +++ b/source/blender/nodes/intern/node_util.h @@ -53,6 +53,7 @@ extern void node_free_standard_storage(struct bNode *node); extern void node_copy_curves(struct bNode *orig_node, struct bNode *new_node); extern void node_copy_standard_storage(struct bNode *orig_node, struct bNode *new_node); +extern void *node_initexec_curves(struct bNode *node); /**** Labels ****/ diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c index fa623eaad3d..ad907c317f8 100644 --- a/source/blender/nodes/shader/node_shader_tree.c +++ b/source/blender/nodes/shader/node_shader_tree.c @@ -49,7 +49,6 @@ #include "BKE_main.h" #include "BKE_node.h" #include "BKE_scene.h" -#include "BKE_utildefines.h" #include "GPU_material.h" @@ -66,15 +65,15 @@ static void foreach_nodetree(Main *main, void *calldata, bNodeTreeCallback func) Lamp *la; World *wo; - for (ma= main->mat.first; ma; ma= ma->id.next) + for (ma = main->mat.first; ma; ma = ma->id.next) if (ma->nodetree) func(calldata, &ma->id, ma->nodetree); - for (la= main->lamp.first; la; la= la->id.next) + for (la = main->lamp.first; la; la = la->id.next) if (la->nodetree) func(calldata, &la->id, la->nodetree); - for (wo= main->world.first; wo; wo= wo->id.next) + for (wo = main->world.first; wo; wo = wo->id.next) if (wo->nodetree) func(calldata, &wo->id, wo->nodetree); } @@ -101,7 +100,7 @@ static void localize(bNodeTree *localtree, bNodeTree *UNUSED(ntree)) bNode *node, *node_next; /* replace muted nodes and reroute nodes by internal links */ - for (node= localtree->nodes.first; node; node= node_next) { + for (node = localtree->nodes.first; node; node = node_next) { node_next = node->next; if (node->flag & NODE_MUTED || node->type == NODE_REROUTE) { @@ -116,15 +115,15 @@ static void local_sync(bNodeTree *localtree, bNodeTree *ntree) bNode *lnode; /* copy over contents of previews */ - for (lnode= localtree->nodes.first; lnode; lnode= lnode->next) { + for (lnode = localtree->nodes.first; lnode; lnode = lnode->next) { if (ntreeNodeExists(ntree, lnode->new_node)) { - bNode *node= lnode->new_node; + bNode *node = lnode->new_node; if (node->preview && node->preview->rect) { if (lnode->preview && lnode->preview->rect) { - int xsize= node->preview->xsize; - int ysize= node->preview->ysize; - memcpy(node->preview->rect, lnode->preview->rect, 4*xsize + xsize*ysize*sizeof(char)*4); + int xsize = node->preview->xsize; + int ysize = node->preview->ysize; + memcpy(node->preview->rect, lnode->preview->rect, 4 * xsize + xsize * ysize * sizeof(char) * 4); } } } @@ -176,7 +175,7 @@ void (*node_shader_lamp_loop)(struct ShadeInput *, struct ShadeResult *); void set_node_shader_lamp_loop(void (*lamp_loop_func)(ShadeInput *, ShadeResult *)) { - node_shader_lamp_loop= lamp_loop_func; + node_shader_lamp_loop = lamp_loop_func; } @@ -203,10 +202,10 @@ bNodeTreeExec *ntreeShaderBeginExecTree(bNodeTree *ntree, int use_tree_data) exec = ntree_exec_begin(ntree); /* allocate the thread stack listbase array */ - exec->threadstack= MEM_callocN(BLENDER_MAX_THREADS*sizeof(ListBase), "thread stack array"); + exec->threadstack = MEM_callocN(BLENDER_MAX_THREADS * sizeof(ListBase), "thread stack array"); - for (node= exec->nodetree->nodes.first; node; node= node->next) - node->need_exec= 1; + for (node = exec->nodetree->nodes.first; node; node = node->next) + node->need_exec = 1; if (use_tree_data) { /* XXX this should not be necessary, but is still used for cmp/sha/tex nodes, @@ -224,19 +223,19 @@ bNodeTreeExec *ntreeShaderBeginExecTree(bNodeTree *ntree, int use_tree_data) void ntreeShaderEndExecTree(bNodeTreeExec *exec, int use_tree_data) { if (exec) { - bNodeTree *ntree= exec->nodetree; + bNodeTree *ntree = exec->nodetree; bNodeThreadStack *nts; int a; if (exec->threadstack) { - for (a=0; a<BLENDER_MAX_THREADS; a++) { - for (nts=exec->threadstack[a].first; nts; nts=nts->next) + for (a = 0; a < BLENDER_MAX_THREADS; a++) { + for (nts = exec->threadstack[a].first; nts; nts = nts->next) if (nts->stack) MEM_freeN(nts->stack); BLI_freelistN(&exec->threadstack[a]); } MEM_freeN(exec->threadstack); - exec->threadstack= NULL; + exec->threadstack = NULL; } ntree_exec_end(exec); @@ -260,8 +259,8 @@ void ntreeShaderExecTree(bNodeTree *ntree, ShadeInput *shi, ShadeResult *shr) bNodeTreeExec *exec = ntree->execdata; /* convert caller data to struct */ - scd.shi= shi; - scd.shr= shr; + scd.shi = shi; + scd.shr = shr; /* each material node has own local shaderesult, with optional copying */ memset(shr, 0, sizeof(ShadeResult)); @@ -276,14 +275,14 @@ void ntreeShaderExecTree(bNodeTree *ntree, ShadeInput *shi, ShadeResult *shr) exec = ntree->execdata; } - nts= ntreeGetThreadStack(exec, shi->thread); + nts = ntreeGetThreadStack(exec, shi->thread); ntreeExecThreadNodes(exec, nts, &scd, shi->thread); ntreeReleaseThreadStack(nts); // \note: set material back to preserved material shi->mat = mat; /* better not allow negative for now */ - if (shr->combined[0]<0.0f) shr->combined[0]= 0.0f; - if (shr->combined[1]<0.0f) shr->combined[1]= 0.0f; - if (shr->combined[2]<0.0f) shr->combined[2]= 0.0f; + if (shr->combined[0] < 0.0f) shr->combined[0] = 0.0f; + if (shr->combined[1] < 0.0f) shr->combined[1] = 0.0f; + if (shr->combined[2] < 0.0f) shr->combined[2] = 0.0f; } diff --git a/source/blender/nodes/shader/nodes/node_shader_curves.c b/source/blender/nodes/shader/nodes/node_shader_curves.c index 8831b07d8a0..83cb1d33628 100644 --- a/source/blender/nodes/shader/nodes/node_shader_curves.c +++ b/source/blender/nodes/shader/nodes/node_shader_curves.c @@ -45,12 +45,6 @@ static bNodeSocketTemplate sh_node_curve_vec_out[]= { { -1, 0, "" } }; -static void *node_shader_initexec_curve(bNode *node) -{ - curvemapping_initialize(node->storage); - return NULL; /* unused return */ -} - static void node_shader_exec_curve_vec(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) { float vec[3]; @@ -86,7 +80,7 @@ void register_node_type_sh_curve_vec(bNodeTreeType *ttype) node_type_init(&ntype, node_shader_init_curve_vec); node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); node_type_exec(&ntype, node_shader_exec_curve_vec); - node_type_exec_new(&ntype, node_shader_initexec_curve, NULL, NULL); /* only for its initexec func */ + node_type_exec_new(&ntype, node_initexec_curves, NULL, NULL); /* only for its initexec func */ node_type_gpu(&ntype, gpu_shader_curve_vec); nodeRegisterType(ttype, &ntype); @@ -144,7 +138,7 @@ void register_node_type_sh_curve_rgb(bNodeTreeType *ttype) node_type_init(&ntype, node_shader_init_curve_rgb); node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); node_type_exec(&ntype, node_shader_exec_curve_rgb); - node_type_exec_new(&ntype, node_shader_initexec_curve, NULL, NULL); /* only for its initexec func */ + node_type_exec_new(&ntype, node_initexec_curves, NULL, NULL); /* only for its initexec func */ node_type_gpu(&ntype, gpu_shader_curve_rgb); nodeRegisterType(ttype, &ntype); diff --git a/source/blender/nodes/shader/nodes/node_shader_particle_info.c b/source/blender/nodes/shader/nodes/node_shader_particle_info.c index 5be8925b556..ddfcb9476f4 100644 --- a/source/blender/nodes/shader/nodes/node_shader_particle_info.c +++ b/source/blender/nodes/shader/nodes/node_shader_particle_info.c @@ -31,6 +31,13 @@ static bNodeSocketTemplate outputs[] = { { SOCK_FLOAT, 0, "Index" }, { SOCK_FLOAT, 0, "Age" }, { SOCK_FLOAT, 0, "Lifetime" }, + { SOCK_VECTOR, 0, "Location" }, + #if 0 /* quaternion sockets not yet supported */ + { SOCK_QUATERNION, 0, "Rotation" }, + #endif + { SOCK_FLOAT, 0, "Size" }, + { SOCK_VECTOR, 0, "Velocity" }, + { SOCK_VECTOR, 0, "Angular Velocity" }, { -1, 0, "" } }; diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_brick.c b/source/blender/nodes/shader/nodes/node_shader_tex_brick.c new file mode 100644 index 00000000000..11f7fb94ae0 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_tex_brick.c @@ -0,0 +1,90 @@ +/* + * ***** 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) 2005 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "../node_shader_util.h" + +/* **************** OUTPUT ******************** */ + +static bNodeSocketTemplate sh_node_tex_brick_in[]= { + { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + { SOCK_RGBA, 1, N_("Color1"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + { SOCK_RGBA, 1, N_("Color2"), 0.2f, 0.2f, 0.2f, 1.0f, 0.0f, 1.0f}, + { SOCK_RGBA, 1, N_("Mortar"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { SOCK_FLOAT, 1, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, + { SOCK_FLOAT, 1, N_("Mortar Size"), 0.02f, 0.0f, 0.0f, 0.0f, 0.0f, 0.125f}, + { SOCK_FLOAT, 1, N_("Bias"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f}, + { SOCK_FLOAT, 1, N_("Brick Width"), 0.5f, 0.0f, 0.0f, 0.0f, 0.01f, 100.0f}, + { SOCK_FLOAT, 1, N_("Row Height"), 0.25f, 0.0f, 0.0f, 0.0f, 0.01f, 100.0f}, + { -1, 0, "" } +}; + +static bNodeSocketTemplate sh_node_tex_brick_out[]= { + { SOCK_RGBA, 0, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + { SOCK_FLOAT, 0, N_("Fac"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + { -1, 0, "" } +}; + +static void node_shader_init_tex_brick(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) +{ + NodeTexBrick *tex = MEM_callocN(sizeof(NodeTexBrick), "NodeTexBrick"); + default_tex_mapping(&tex->base.tex_mapping); + default_color_mapping(&tex->base.color_mapping); + + tex->offset = 0.5f; + tex->squash = 1.0f; + tex->offset_freq = 2; + tex->squash_freq = 2; + + node->storage = tex; +} + +static int node_shader_gpu_tex_brick(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) +{ + if (!in[0].link) + in[0].link = GPU_attribute(CD_ORCO, ""); + + node_shader_gpu_tex_mapping(mat, node, in, out); + + return GPU_stack_link(mat, "node_tex_brick", in, out); +} + +/* node type definition */ +void register_node_type_sh_tex_brick(bNodeTreeType *ttype) +{ + static bNodeType ntype; + + node_type_base(ttype, &ntype, SH_NODE_TEX_BRICK, "Brick Texture", NODE_CLASS_TEXTURE, NODE_OPTIONS); + node_type_compatibility(&ntype, NODE_NEW_SHADING); + node_type_socket_templates(&ntype, sh_node_tex_brick_in, sh_node_tex_brick_out); + node_type_size(&ntype, 150, 60, 200); + node_type_init(&ntype, node_shader_init_tex_brick); + node_type_storage(&ntype, "NodeTexBrick", node_free_standard_storage, node_copy_standard_storage); + node_type_exec(&ntype, NULL); + node_type_gpu(&ntype, node_shader_gpu_tex_brick); + + nodeRegisterType(ttype, &ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c index 572f06e007b..ace0f0c8774 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c @@ -58,6 +58,8 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, GPUNod { Image *ima= (Image*)node->id; ImageUser *iuser= NULL; + NodeTexImage *tex = node->storage; + int ncd = tex->color_space == SHD_COLORSPACE_NONE; if (!ima) return GPU_stack_link(mat, "node_tex_environment_empty", in, out); @@ -67,7 +69,10 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, GPUNod node_shader_gpu_tex_mapping(mat, node, in, out); - return GPU_stack_link(mat, "node_tex_environment", in, out, GPU_image(ima, iuser)); + if (out[0].link && GPU_material_do_color_management(mat)) + GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link); + + return GPU_stack_link(mat, "node_tex_environment", in, out, GPU_image(ima, iuser, ncd)); } /* node type definition */ diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_image.c b/source/blender/nodes/shader/nodes/node_shader_tex_image.c index 176c50bcabb..d6c757222b9 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_image.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_image.c @@ -58,6 +58,8 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, GPUNodeStack { Image *ima= (Image*)node->id; ImageUser *iuser= NULL; + NodeTexImage *tex = node->storage; + int ncd = tex->color_space == SHD_COLORSPACE_NONE; if (!ima) return GPU_stack_link(mat, "node_tex_image_empty", in, out); @@ -67,7 +69,10 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, GPUNodeStack node_shader_gpu_tex_mapping(mat, node, in, out); - return GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser)); + if (out[0].link && GPU_material_do_color_management(mat)) + GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link); + + return GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, ncd)); } /* node type definition */ diff --git a/source/blender/nodes/shader/nodes/node_shader_texture.c b/source/blender/nodes/shader/nodes/node_shader_texture.c index 3f90d4fbcd5..73c3b846fe3 100644 --- a/source/blender/nodes/shader/nodes/node_shader_texture.c +++ b/source/blender/nodes/shader/nodes/node_shader_texture.c @@ -122,7 +122,7 @@ static int gpu_shader_texture(GPUMaterial *mat, bNode *node, GPUNodeStack *in, G Tex *tex = (Tex*)node->id; if (tex && tex->type == TEX_IMAGE && tex->ima) { - GPUNodeLink *texlink = GPU_image(tex->ima, NULL); + GPUNodeLink *texlink = GPU_image(tex->ima, NULL, FALSE); return GPU_stack_link(mat, "texture_image", in, out, texlink); } else diff --git a/source/blender/nodes/texture/node_texture_tree.c b/source/blender/nodes/texture/node_texture_tree.c index 063cc31e6f6..9656d93f1b0 100644 --- a/source/blender/nodes/texture/node_texture_tree.c +++ b/source/blender/nodes/texture/node_texture_tree.c @@ -58,7 +58,7 @@ static void foreach_nodetree(Main *main, void *calldata, bNodeTreeCallback func) { Tex *tx; - for (tx= main->tex.first; tx; tx= tx->id.next) { + for (tx = main->tex.first; tx; tx = tx->id.next) { if (tx->nodetree) { func(calldata, &tx->id, tx->nodetree); } @@ -83,7 +83,7 @@ static void localize(bNodeTree *localtree, bNodeTree *UNUSED(ntree)) bNode *node, *node_next; /* replace muted nodes and reroute nodes by internal links */ - for (node= localtree->nodes.first; node; node= node_next) { + for (node = localtree->nodes.first; node; node = node_next) { node_next = node->next; if (node->flag & NODE_MUTED || node->type == NODE_REROUTE) { @@ -98,15 +98,15 @@ static void local_sync(bNodeTree *localtree, bNodeTree *ntree) bNode *lnode; /* copy over contents of previews */ - for (lnode= localtree->nodes.first; lnode; lnode= lnode->next) { + for (lnode = localtree->nodes.first; lnode; lnode = lnode->next) { if (ntreeNodeExists(ntree, lnode->new_node)) { - bNode *node= lnode->new_node; + bNode *node = lnode->new_node; if (node->preview && node->preview->rect) { if (lnode->preview && lnode->preview->rect) { - int xsize= node->preview->xsize; - int ysize= node->preview->ysize; - memcpy(node->preview->rect, lnode->preview->rect, 4*xsize + xsize*ysize*sizeof(char)*4); + int xsize = node->preview->xsize; + int ysize = node->preview->ysize; + memcpy(node->preview->rect, lnode->preview->rect, 4 * xsize + xsize * ysize * sizeof(char) * 4); } } } @@ -141,15 +141,15 @@ int ntreeTexTagAnimated(bNodeTree *ntree) { bNode *node; - if (ntree==NULL) return 0; + if (ntree == NULL) return 0; - for (node= ntree->nodes.first; node; node= node->next) { - if (node->type==TEX_NODE_CURVE_TIME) { + for (node = ntree->nodes.first; node; node = node->next) { + if (node->type == TEX_NODE_CURVE_TIME) { nodeUpdate(ntree, node); return 1; } - else if (node->type==NODE_GROUP) { - if ( ntreeTexTagAnimated((bNodeTree *)node->id) ) { + else if (node->type == NODE_GROUP) { + if (ntreeTexTagAnimated((bNodeTree *)node->id) ) { return 1; } } @@ -178,10 +178,10 @@ bNodeTreeExec *ntreeTexBeginExecTree(bNodeTree *ntree, int use_tree_data) exec = ntree_exec_begin(ntree); /* allocate the thread stack listbase array */ - exec->threadstack= MEM_callocN(BLENDER_MAX_THREADS*sizeof(ListBase), "thread stack array"); + exec->threadstack = MEM_callocN(BLENDER_MAX_THREADS * sizeof(ListBase), "thread stack array"); - for (node= exec->nodetree->nodes.first; node; node= node->next) - node->need_exec= 1; + for (node = exec->nodetree->nodes.first; node; node = node->next) + node->need_exec = 1; if (use_tree_data) { /* XXX this should not be necessary, but is still used for cmp/sha/tex nodes, @@ -200,9 +200,9 @@ static void tex_free_delegates(bNodeTreeExec *exec) bNodeStack *ns; int th, a; - for (th=0; th<BLENDER_MAX_THREADS; th++) - for (nts=exec->threadstack[th].first; nts; nts=nts->next) - for (ns= nts->stack, a=0; a<exec->stacksize; a++, ns++) + for (th = 0; th < BLENDER_MAX_THREADS; th++) + for (nts = exec->threadstack[th].first; nts; nts = nts->next) + for (ns = nts->stack, a = 0; a < exec->stacksize; a++, ns++) if (ns->data && !ns->is_copy) MEM_freeN(ns->data); } @@ -213,21 +213,21 @@ static void tex_free_delegates(bNodeTreeExec *exec) void ntreeTexEndExecTree(bNodeTreeExec *exec, int use_tree_data) { if (exec) { - bNodeTree *ntree= exec->nodetree; + bNodeTree *ntree = exec->nodetree; bNodeThreadStack *nts; int a; if (exec->threadstack) { tex_free_delegates(exec); - for (a=0; a<BLENDER_MAX_THREADS; a++) { - for (nts=exec->threadstack[a].first; nts; nts=nts->next) + for (a = 0; a < BLENDER_MAX_THREADS; a++) { + for (nts = exec->threadstack[a].first; nts; nts = nts->next) if (nts->stack) MEM_freeN(nts->stack); BLI_freelistN(&exec->threadstack[a]); } MEM_freeN(exec->threadstack); - exec->threadstack= NULL; + exec->threadstack = NULL; } ntree_exec_end(exec); @@ -254,10 +254,10 @@ int ntreeTexExecTree( MTex *mtex ) { TexCallData data; - float *nor= texres->nor; + float *nor = texres->nor; int retval = TEX_INT; bNodeThreadStack *nts = NULL; - bNodeTreeExec *exec= nodes->execdata; + bNodeTreeExec *exec = nodes->execdata; data.co = co; data.dxt = dxt; @@ -267,9 +267,9 @@ int ntreeTexExecTree( data.do_preview = preview; data.thread = thread; data.which_output = which_output; - data.cfra= cfra; - data.mtex= mtex; - data.shi= shi; + data.cfra = cfra; + data.mtex = mtex; + data.shi = shi; /* ensure execdata is only initialized once */ if (!exec) { @@ -278,10 +278,10 @@ int ntreeTexExecTree( ntreeTexBeginExecTree(nodes, 1); BLI_unlock_thread(LOCK_NODES); - exec= nodes->execdata; + exec = nodes->execdata; } - nts= ntreeGetThreadStack(exec, thread); + nts = ntreeGetThreadStack(exec, thread); ntreeExecThreadNodes(exec, nts, &data, thread); ntreeReleaseThreadStack(nts); @@ -289,7 +289,7 @@ int ntreeTexExecTree( retval |= TEX_RGB; /* confusing stuff; the texture output node sets this to NULL to indicate no normal socket was set * however, the texture code checks this for other reasons (namely, a normal is required for material) */ - texres->nor= nor; + texres->nor = nor; return retval; } diff --git a/source/blender/nodes/texture/nodes/node_texture_curves.c b/source/blender/nodes/texture/nodes/node_texture_curves.c index 543b39ec75e..6ccb5e1e83f 100644 --- a/source/blender/nodes/texture/nodes/node_texture_curves.c +++ b/source/blender/nodes/texture/nodes/node_texture_curves.c @@ -77,6 +77,7 @@ void register_node_type_tex_curve_time(bNodeTreeType *ttype) node_type_init(&ntype, time_init); node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); node_type_exec(&ntype, time_exec); + node_type_exec_new(&ntype, node_initexec_curves, NULL, NULL); /* only for its initexec func */ nodeRegisterType(ttype, &ntype); } @@ -121,6 +122,7 @@ void register_node_type_tex_curve_rgb(bNodeTreeType *ttype) node_type_init(&ntype, rgb_init); node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); node_type_exec(&ntype, rgb_exec); + node_type_exec_new(&ntype, node_initexec_curves, NULL, NULL); /* only for its initexec func */ nodeRegisterType(ttype, &ntype); } diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c index ce11545c90d..45b767c6eda 100644 --- a/source/blender/python/generic/bgl.c +++ b/source/blender/python/generic/bgl.c @@ -44,7 +44,7 @@ #include "BLI_utildefines.h" static PyObject *Buffer_new(PyTypeObject *type, PyObject *args, PyObject *kwds); -static PyObject *Method_ShaderSource (PyObject *self, PyObject *args); +static PyObject *Method_ShaderSource(PyObject *self, PyObject *args); /* Buffer sequence methods */ diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c index 520773c1ddf..2e4d4e870b8 100644 --- a/source/blender/python/generic/py_capi_utils.c +++ b/source/blender/python/generic/py_capi_utils.c @@ -402,6 +402,15 @@ const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce) if (PyBytes_Check(py_str)) { return PyBytes_AS_STRING(py_str); } +#ifdef WIN32 + /* bug [#31856] oddly enough, Python3.2 --> 3.3 on Windows will throw an + * exception here this needs to be fixed in python: + * see: bugs.python.org/issue15859 */ + else if (!PyUnicode_Check(py_str)) { + PyErr_BadArgument(); + return NULL; + } +#endif else if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) { return PyBytes_AS_STRING(*coerce); } diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index aa9d81389da..9cd0bdd090a 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -163,8 +163,17 @@ void bpy_context_clear(bContext *UNUSED(C), PyGILState_STATE *gilstate) void BPY_text_free_code(Text *text) { if (text->compiled) { + PyGILState_STATE gilstate; + int use_gil = !PYC_INTERPRETER_ACTIVE; + + if (use_gil) + gilstate = PyGILState_Ensure(); + Py_DECREF((PyObject *)text->compiled); text->compiled = NULL; + + if (use_gil) + PyGILState_Release(gilstate); } } @@ -254,6 +263,15 @@ void BPY_python_start(int argc, const char **argv) Py_Initialize(); +#ifdef WIN32 + /* this is disappointing, its likely a bug in python? + * for some reason 'PYTHONIOENCODING' is ignored in windows + * see: [#31555] for details. */ + PyRun_SimpleString("import sys, io\n" + "sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='surrogateescape', line_buffering=True)\n" + "sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='surrogateescape', line_buffering=True)\n"); +#endif /* WIN32 */ + // PySys_SetArgv(argc, argv); // broken in py3, not a huge deal /* sigh, why do python guys not have a (char **) version anymore? */ { diff --git a/source/blender/quicktime/apple/qtkit_export.m b/source/blender/quicktime/apple/qtkit_export.m index 47df4c7363f..bb87fe21c49 100644 --- a/source/blender/quicktime/apple/qtkit_export.m +++ b/source/blender/quicktime/apple/qtkit_export.m @@ -318,7 +318,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R if(qtexport == NULL) qtexport = MEM_callocN(sizeof(QuicktimeExport), "QuicktimeExport"); - [QTMovie enterQTKitOnThread]; + [QTMovie enterQTKitOnThread]; /* Check first if the QuickTime 7.2.1 initToWritableFile: method is available */ if ([[[[QTMovie alloc] init] autorelease] respondsToSelector:@selector(initToWritableFile:error:)] != YES) { @@ -328,7 +328,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R else { makeqtstring(rd, name); qtexport->filename = [[NSString alloc] initWithCString:name - encoding:[NSString defaultCStringEncoding]]; + encoding:[NSString defaultCStringEncoding]]; qtexport->movie = nil; qtexport->audioFile = NULL; @@ -354,7 +354,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R strcpy(extension,".aiff"); break; } - + tmpnam(name); strcat(name, extension); outputFileURL = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,(UInt8*) name, strlen(name), false); @@ -362,7 +362,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R if (outputFileURL) { qtexport->audioFileName = [[NSString alloc] initWithCString:name - encoding:[NSString defaultCStringEncoding]]; + encoding:[NSString defaultCStringEncoding]]; qtexport->audioInputFormat.mSampleRate = U.audiorate; qtexport->audioInputFormat.mFormatID = kAudioFormatLinearPCM; @@ -471,7 +471,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R qtexport->audioOutputFormat.mBytesPerFrame = qtexport->audioOutputFormat.mBytesPerPacket; break; } - + err = AudioFileCreateWithURL(outputFileURL, audioFileType, &qtexport->audioOutputFormat, kAudioFileFlags_EraseFile, &qtexport->audioFile); CFRelease(outputFileURL); @@ -489,27 +489,27 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R else { UInt32 prop,propSize; /* Set up codec properties */ - if (rd->qtcodecsettings.audiocodecType == kAudioFormatMPEG4AAC) { /*Lossy compressed format*/ + if (rd->qtcodecsettings.audiocodecType == kAudioFormatMPEG4AAC) { /* Lossy compressed format */ prop = rd->qtcodecsettings.audioBitRate; AudioConverterSetProperty(qtexport->audioConverter, kAudioConverterEncodeBitRate, - sizeof(prop), &prop); + sizeof(prop), &prop); if (rd->qtcodecsettings.audioCodecFlags & QTAUDIO_FLAG_CODEC_ISCBR) prop = kAudioCodecBitRateControlMode_Constant; else prop = kAudioCodecBitRateControlMode_LongTermAverage; AudioConverterSetProperty(qtexport->audioConverter, kAudioCodecPropertyBitRateControlMode, - sizeof(prop), &prop); + sizeof(prop), &prop); } /* Conversion quality : if performance impact then offer degraded option */ - if ((rd->qtcodecsettings.audioCodecFlags & QTAUDIO_FLAG_RESAMPLE_NOHQ) == 0) { + if ((rd->qtcodecsettings.audioCodecFlags & QTAUDIO_FLAG_RESAMPLE_NOHQ) == 0) { prop = kAudioConverterSampleRateConverterComplexity_Mastering; AudioConverterSetProperty(qtexport->audioConverter, kAudioConverterSampleRateConverterComplexity, - sizeof(prop), &prop); + sizeof(prop), &prop); prop = kAudioConverterQuality_Max; AudioConverterSetProperty(qtexport->audioConverter, kAudioConverterSampleRateConverterQuality, - sizeof(prop), &prop); + sizeof(prop), &prop); } write_cookie(qtexport->audioConverter, qtexport->audioFile); @@ -517,29 +517,30 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R /* Allocate output buffer */ if (qtexport->audioOutputFormat.mBytesPerPacket ==0) /* VBR */ AudioConverterGetProperty(qtexport->audioConverter, kAudioConverterPropertyMaximumOutputPacketSize, - &propSize, &qtexport->audioCodecMaxOutputPacketSize); + &propSize, &qtexport->audioCodecMaxOutputPacketSize); else qtexport->audioCodecMaxOutputPacketSize = qtexport->audioOutputFormat.mBytesPerPacket; qtexport->audioInputBuffer = MEM_mallocN(AUDIOOUTPUTBUFFERSIZE, "qt_audio_inputPacket"); qtexport->audioOutputBuffer = MEM_mallocN(AUDIOOUTPUTBUFFERSIZE, "qt_audio_outputPacket"); - qtexport->audioOutputPktDesc = MEM_mallocN(sizeof(AudioStreamPacketDescription)*AUDIOOUTPUTBUFFERSIZE/qtexport->audioCodecMaxOutputPacketSize, - "qt_audio_pktdesc"); + qtexport->audioOutputPktDesc = MEM_mallocN(sizeof(AudioStreamPacketDescription) * AUDIOOUTPUTBUFFERSIZE / qtexport->audioCodecMaxOutputPacketSize, + "qt_audio_pktdesc"); } } } - + if (err == noErr) { - qtexport->videoTempFileName = [[NSString alloc] initWithCString:tmpnam(nil) - encoding:[NSString defaultCStringEncoding]]; - if (qtexport->videoTempFileName) + qtexport->videoTempFileName = [[NSString alloc] initWithCString:tmpnam(nil) + encoding:[NSString defaultCStringEncoding]]; + if (qtexport->videoTempFileName) { qtexport->movie = [[QTMovie alloc] initToWritableFile:qtexport->videoTempFileName error:&error]; + } } } else qtexport->movie = [[QTMovie alloc] initToWritableFile:qtexport->filename error:&error]; - + if(qtexport->movie == nil) { BKE_report(reports, RPT_ERROR, "Unable to create quicktime movie."); success= 0; @@ -585,7 +586,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R specs.rate = U.audiorate; qtexport->audioInputDevice = AUD_openReadDevice(specs); AUD_playDevice(qtexport->audioInputDevice, scene->sound_scene, rd->sfra * rd->frs_sec_base / rd->frs_sec); - + qtexport->audioOutputPktPos = 0; qtexport->audioTotalExportedFrames = 0; qtexport->audioTotalSavedFrames = 0; @@ -655,13 +656,13 @@ int append_qt(struct RenderData *rd, int start_frame, int frame, int *pixels, in audioPacketsConverted = AUDIOOUTPUTBUFFERSIZE / qtexport->audioCodecMaxOutputPacketSize; err = AudioConverterFillComplexBuffer(qtexport->audioConverter, AudioConverterInputCallback, - NULL, &audioPacketsConverted, &qtexport->audioBufferList, qtexport->audioOutputPktDesc); + NULL, &audioPacketsConverted, &qtexport->audioBufferList, qtexport->audioOutputPktDesc); if (audioPacketsConverted) { AudioFileWritePackets(qtexport->audioFile, false, qtexport->audioBufferList.mBuffers[0].mDataByteSize, - qtexport->audioOutputPktDesc, qtexport->audioOutputPktPos, &audioPacketsConverted, qtexport->audioOutputBuffer); + qtexport->audioOutputPktDesc, qtexport->audioOutputPktPos, &audioPacketsConverted, qtexport->audioOutputBuffer); qtexport->audioOutputPktPos += audioPacketsConverted; - if (qtexport->audioOutputFormat.mFramesPerPacket) { + if (qtexport->audioOutputFormat.mFramesPerPacket) { // this is the common case: format has constant frames per packet qtexport->audioTotalSavedFrames += (audioPacketsConverted * qtexport->audioOutputFormat.mFramesPerPacket); } @@ -751,8 +752,8 @@ void end_qt(void) } /* Save file */ - dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] - forKey:QTMovieFlatten]; + dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] + forKey:QTMovieFlatten]; if (dict) { [qtexport->movie writeToFile:qtexport->filename withAttributes:dict]; diff --git a/source/blender/render/extern/include/RE_engine.h b/source/blender/render/extern/include/RE_engine.h index 5afdb2a29ce..2376aeca55e 100644 --- a/source/blender/render/extern/include/RE_engine.h +++ b/source/blender/render/extern/include/RE_engine.h @@ -86,9 +86,14 @@ typedef struct RenderEngine { int flag; struct Object *camera_override; + int tile_x; + int tile_y; + struct Render *re; ListBase fullresult; char *text; + + int resolution_x, resolution_y; } RenderEngine; RenderEngine *RE_engine_create(RenderEngineType *type); @@ -97,9 +102,9 @@ void RE_engine_free(RenderEngine *engine); void RE_layer_load_from_file(struct RenderLayer *layer, struct ReportList *reports, const char *filename, int x, int y); void RE_result_load_from_file(struct RenderResult *result, struct ReportList *reports, const char *filename); -struct RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h); +struct RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h, const char *layername); void RE_engine_update_result(RenderEngine *engine, struct RenderResult *result); -void RE_engine_end_result(RenderEngine *engine, struct RenderResult *result); +void RE_engine_end_result(RenderEngine *engine, struct RenderResult *result, int cancel); int RE_engine_test_break(RenderEngine *engine); void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char *info); diff --git a/source/blender/render/extern/include/RE_pipeline.h b/source/blender/render/extern/include/RE_pipeline.h index 4695f2ba44f..1510d9adb10 100644 --- a/source/blender/render/extern/include/RE_pipeline.h +++ b/source/blender/render/extern/include/RE_pipeline.h @@ -92,6 +92,9 @@ typedef struct RenderLayer { float *acolrect; /* 4 float, optional transparent buffer, needs storage for display updates */ float *scolrect; /* 4 float, optional strand buffer, needs storage for display updates */ int rectx, recty; + + /* optional saved endresult on disk */ + void *exrhandle; ListBase passes; @@ -124,7 +127,7 @@ typedef struct RenderResult { volatile RenderLayer *renlay; /* optional saved endresult on disk */ - void *exrhandle; + int do_exr_tile; /* for render results in Image, verify validity for sequences */ int framenr; diff --git a/source/blender/render/extern/include/RE_render_ext.h b/source/blender/render/extern/include/RE_render_ext.h index 604cd940fab..c07ed42332f 100644 --- a/source/blender/render/extern/include/RE_render_ext.h +++ b/source/blender/render/extern/include/RE_render_ext.h @@ -65,7 +65,7 @@ void antialias_tagbuf(int xsize, int ysize, char *rectmove); struct Material *RE_init_sample_material(struct Material *orig_mat, struct Scene *scene); void RE_free_sample_material(struct Material *mat); void RE_sample_material_color(struct Material *mat, float color[3], float *alpha, const float volume_co[3], const float surface_co[3], - int face_index, short hit_quad, struct DerivedMesh *orcoDm, struct Object *ob); + int face_index, short hit_quad, struct DerivedMesh *orcoDm, struct Object *ob); #endif /* __RE_RENDER_EXT_H__ */ diff --git a/source/blender/render/intern/include/initrender.h b/source/blender/render/intern/include/initrender.h index 7917fd66cfa..43ab9552194 100644 --- a/source/blender/render/intern/include/initrender.h +++ b/source/blender/render/intern/include/initrender.h @@ -40,7 +40,7 @@ struct Object; void free_sample_tables(Render *re); void make_sample_tables(Render *re); -void initparts(Render *re); +void initparts(Render *re, int do_crop); void freeparts(Render *re); diff --git a/source/blender/render/intern/include/pixelshading.h b/source/blender/render/intern/include/pixelshading.h index 00d731912b6..30d574694b2 100644 --- a/source/blender/render/intern/include/pixelshading.h +++ b/source/blender/render/intern/include/pixelshading.h @@ -44,9 +44,9 @@ * \return pointer to the object */ int shadeHaloFloat(HaloRen *har, - float *col, int zz, - float dist, float xn, - float yn, short flarec); + float *col, int zz, + float dist, float xn, + float yn, short flarec); /** * Render the sky at pixel (x, y). diff --git a/source/blender/render/intern/include/render_result.h b/source/blender/render/intern/include/render_result.h index 3d73ee1e912..303d4094f8e 100644 --- a/source/blender/render/intern/include/render_result.h +++ b/source/blender/render/intern/include/render_result.h @@ -37,6 +37,8 @@ #define RR_USE_MEM 0 #define RR_USE_EXR 1 +#define RR_ALL_LAYERS NULL + struct ImBuf; struct ListBase; struct Render; @@ -49,7 +51,7 @@ struct rcti; /* New */ struct RenderResult *render_result_new(struct Render *re, - struct rcti *partrct, int crop, int savebuffers); + struct rcti *partrct, int crop, int savebuffers, const char *layername); struct RenderResult *render_result_new_full_sample(struct Render *re, struct ListBase *lb, struct rcti *partrct, int crop, int savebuffers); @@ -76,9 +78,9 @@ void render_result_exr_file_end(struct Render *re); void render_result_exr_file_merge(struct RenderResult *rr, struct RenderResult *rrpart); -void render_result_exr_file_path(struct Scene *scene, int sample, char *filepath); +void render_result_exr_file_path(struct Scene *scene, const char *layname, int sample, char *filepath); int render_result_exr_file_read(struct Render *re, int sample); -int render_result_exr_file_read_path(struct RenderResult *rr, const char *filepath); +int render_result_exr_file_read_path(struct RenderResult *rr, struct RenderLayer *rl_single, const char *filepath); /* Combined Pixel Rect */ diff --git a/source/blender/render/intern/include/render_types.h b/source/blender/render/intern/include/render_types.h index c8c8eb1fc06..60f3ced5652 100644 --- a/source/blender/render/intern/include/render_types.h +++ b/source/blender/render/intern/include/render_types.h @@ -63,7 +63,6 @@ struct ReportList; struct Main; #define TABLEINITSIZE 1024 -#define LAMPINITSIZE 256 typedef struct SampleTables { float centLut[16]; diff --git a/source/blender/render/intern/include/sunsky.h b/source/blender/render/intern/include/sunsky.h index 4bb7d99ba16..74e42109be5 100644 --- a/source/blender/render/intern/include/sunsky.h +++ b/source/blender/render/intern/include/sunsky.h @@ -27,9 +27,7 @@ #ifndef __SUNSKY_H__ #define __SUNSKY_H__ -#define SPECTRUM_MAX_COMPONENTS 100 -#define SPECTRUM_START 350.0 -#define SPECTRUM_END 800.0 +// #define SPECTRUM_MAX_COMPONENTS 100 typedef struct SunSky { short effect_type, skyblendtype, sky_colorspace; diff --git a/source/blender/render/intern/include/volumetric.h b/source/blender/render/intern/include/volumetric.h index 7f63bcbbecc..3805478fed0 100644 --- a/source/blender/render/intern/include/volumetric.h +++ b/source/blender/render/intern/include/volumetric.h @@ -41,9 +41,6 @@ void shade_volume_outside(ShadeInput *shi, ShadeResult *shr); void shade_volume_inside(ShadeInput *shi, ShadeResult *shr); void shade_volume_shadow(struct ShadeInput *shi, struct ShadeResult *shr, struct Isect *last_is); -#define STEPSIZE_VIEW 0 -#define STEPSIZE_SHADE 1 - #define VOL_IS_BACKFACE 1 #define VOL_IS_SAMEMATERIAL 2 diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index 03f00418af9..e0864533fed 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -247,32 +247,24 @@ void RE_make_stars(Render *re, Scene *scenev3d, void (*initfunc)(void), done++; } else { - mul_m4_v3(re->viewmat, vec); + if (re) + mul_m4_v3(re->viewmat, vec); /* in vec are global coordinates * calculate distance to camera * and using that, define the alpha */ - - { - float tx, ty, tz; - - tx = vec[0]; - ty = vec[1]; - tz = vec[2]; - - alpha = sqrt(tx * tx + ty * ty + tz * tz); - - if (alpha >= clipend) alpha = 0.0; - else if (alpha <= starmindist) alpha = 0.0; - else if (alpha <= 2.0f * starmindist) { - alpha = (alpha - starmindist) / starmindist; - } - else { - alpha -= 2.0f * starmindist; - alpha /= (clipend - 2.0f * starmindist); - alpha = 1.0f - alpha; - } + alpha = len_v3(vec); + + if (alpha >= clipend) alpha = 0.0; + else if (alpha <= starmindist) alpha = 0.0; + else if (alpha <= 2.0f * starmindist) { + alpha = (alpha - starmindist) / starmindist; + } + else { + alpha -= 2.0f * starmindist; + alpha /= (clipend - 2.0f * starmindist); + alpha = 1.0f - alpha; } diff --git a/source/blender/render/intern/source/external_engine.c b/source/blender/render/intern/source/external_engine.c index 487271ea1f7..636b3205b23 100644 --- a/source/blender/render/intern/source/external_engine.c +++ b/source/blender/render/intern/source/external_engine.c @@ -55,6 +55,7 @@ #include "RE_engine.h" #include "RE_pipeline.h" +#include "initrender.h" #include "render_types.h" #include "render_result.h" @@ -149,7 +150,7 @@ void RE_engine_free(RenderEngine *engine) /* Render Results */ -RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h) +RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h, const char *layername) { Render *re = engine->re; RenderResult *result; @@ -172,7 +173,9 @@ RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, disprect.ymin = y; disprect.ymax = y + h; - result = render_result_new(re, &disprect, 0, RR_USE_MEM); + result = render_result_new(re, &disprect, 0, RR_USE_MEM, layername); + + /* todo: make this thread safe */ /* can be NULL if we CLAMP the width or height to 0 */ if (result) { @@ -197,25 +200,43 @@ void RE_engine_update_result(RenderEngine *engine, RenderResult *result) } } -void RE_engine_end_result(RenderEngine *engine, RenderResult *result) +void RE_engine_end_result(RenderEngine *engine, RenderResult *result, int cancel) { Render *re = engine->re; + RenderPart *pa; - if (!result) + if (!result) { return; + } /* merge. on break, don't merge in result for preview renders, looks nicer */ - if (!(re->test_break(re->tbh) && (re->r.scemode & R_PREVIEWBUTS))) - render_result_merge(re->result, result); + if (!cancel) { + /* for exr tile render, detect tiles that are done */ + for (pa = re->parts.first; pa; pa = pa->next) { + if (result->tilerect.xmin == pa->disprect.xmin && + result->tilerect.ymin == pa->disprect.ymin && + result->tilerect.xmax == pa->disprect.xmax && + result->tilerect.ymax == pa->disprect.ymax) + { + pa->ready = 1; + } + } - /* draw */ - if (!re->test_break(re->tbh)) { - result->renlay = result->layers.first; /* weak, draws first layer always */ - re->display_draw(re->ddh, result, NULL); + if (re->result->do_exr_tile) + render_result_exr_file_merge(re->result, result); + else if (!(re->test_break(re->tbh) && (re->r.scemode & R_PREVIEWBUTS))) + render_result_merge(re->result, result); + + /* draw */ + if (!re->test_break(re->tbh)) { + result->renlay = result->layers.first; /* weak, draws first layer always */ + re->display_draw(re->ddh, result, NULL); + } } /* free */ - render_result_free_list(&engine->fullresult, result); + BLI_remlink(&engine->fullresult, result); + render_result_free(result); } /* Cancel */ @@ -294,12 +315,16 @@ int RE_engine_render(Render *re, int do_all) /* create render result */ BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); if (re->result == NULL || !(re->r.scemode & R_PREVIEWBUTS)) { + int savebuffers; + if (re->result) render_result_free(re->result); - re->result = render_result_new(re, &re->disprect, 0, 0); + + savebuffers = (re->r.scemode & R_EXR_TILE_FILE) ? RR_USE_EXR : RR_USE_MEM; + re->result = render_result_new(re, &re->disprect, 0, savebuffers, RR_ALL_LAYERS); } BLI_rw_mutex_unlock(&re->resultmutex); - + if (re->result == NULL) return 1; @@ -318,14 +343,35 @@ int RE_engine_render(Render *re, int do_all) engine->flag |= RE_ENGINE_PREVIEW; engine->camera_override = re->camera_override; + engine->resolution_x = re->winx; + engine->resolution_y = re->winy; + if ((re->r.scemode & (R_NO_FRAME_UPDATE | R_PREVIEWBUTS)) == 0) BKE_scene_update_for_newframe(re->main, re->scene, re->lay); + initparts(re, FALSE); + engine->tile_x = re->partx; + engine->tile_y = re->party; + + if (re->result->do_exr_tile) + render_result_exr_file_begin(re); + if (type->update) type->update(engine, re->main, re->scene); + if (type->render) type->render(engine, re->scene); + if (re->result->do_exr_tile) { + BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); + render_result_exr_file_end(re); + BLI_rw_mutex_unlock(&re->resultmutex); + } + + engine->tile_x = 0; + engine->tile_y = 0; + freeparts(re); + render_result_free_list(&engine->fullresult, engine->fullresult.first); RE_engine_free(engine); diff --git a/source/blender/render/intern/source/imagetexture.c b/source/blender/render/intern/source/imagetexture.c index e4fb87e8e4f..7f0484c8ee6 100644 --- a/source/blender/render/intern/source/imagetexture.c +++ b/source/blender/render/intern/source/imagetexture.c @@ -1054,6 +1054,8 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex if ((ibuf == NULL) || ((ibuf->rect == NULL) && (ibuf->rect_float == NULL))) return retval; + ima->flag |= IMA_USED_FOR_RENDER; + /* mipmap test */ image_mipmap_test(tex, ibuf); diff --git a/source/blender/render/intern/source/initrender.c b/source/blender/render/intern/source/initrender.c index 7efdba77943..66f230a40f5 100644 --- a/source/blender/render/intern/source/initrender.c +++ b/source/blender/render/intern/source/initrender.c @@ -537,7 +537,7 @@ void freeparts(Render *re) BLI_freelistN(&re->parts); } -void initparts(Render *re) +void initparts(Render *re, int do_crop) { int nr, xd, yd, partx, party, xparts, yparts; int xminb, xmaxb, yminb, ymaxb; @@ -618,7 +618,7 @@ void initparts(Render *re) RenderPart *pa = MEM_callocN(sizeof(RenderPart), "new part"); /* Non-box filters need 2 pixels extra to work */ - if ((re->r.filtertype || (re->r.mode & R_EDGE))) { + if (do_crop && (re->r.filtertype || (re->r.mode & R_EDGE))) { pa->crop = 2; disprect.xmin -= pa->crop; disprect.ymin -= pa->crop; diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 14c9df2da4e..720287510d0 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -56,7 +56,6 @@ #include "BKE_report.h" #include "BKE_scene.h" #include "BKE_sequencer.h" -#include "BKE_utildefines.h" #include "BKE_writeavi.h" /* <------ should be replaced once with generic movie module */ #include "BLI_math.h" @@ -198,14 +197,12 @@ float *RE_RenderLayerGetPass(RenderLayer *rl, int passtype) RenderLayer *RE_GetRenderLayer(RenderResult *rr, const char *name) { - RenderLayer *rl; - - if (rr == NULL) return NULL; - - for (rl = rr->layers.first; rl; rl = rl->next) - if (strncmp(rl->name, name, RE_MAXNAME) == 0) - return rl; - return NULL; + if (rr == NULL) { + return NULL; + } + else { + return BLI_findstring(&rr->layers, name, offsetof(RenderLayer, name)); + } } RenderResult *RE_MultilayerConvert(void *exrhandle, int rectx, int recty) @@ -644,7 +641,7 @@ static void *do_part_thread(void *pa_v) if (!R.sss_points && (R.r.scemode & R_FULL_SAMPLE)) pa->result = render_result_new_full_sample(&R, &pa->fullresult, &pa->disprect, pa->crop, RR_USE_MEM); else - pa->result = render_result_new(&R, &pa->disprect, pa->crop, RR_USE_MEM); + pa->result = render_result_new(&R, &pa->disprect, pa->crop, RR_USE_MEM, RR_ALL_LAYERS); if (R.sss_points) zbufshade_sss_tile(pa); @@ -654,7 +651,7 @@ static void *do_part_thread(void *pa_v) zbufshade_tile(pa); /* merge too on break! */ - if (R.result->exrhandle) { + if (R.result->do_exr_tile) { render_result_exr_file_merge(R.result, pa->result); } else if (render_display_draw_enabled(&R)) { @@ -798,12 +795,12 @@ static void threaded_tile_processor(Render *re) render_result_free(re->result); if (re->sss_points && render_display_draw_enabled(re)) - re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM); + re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS); else if (re->r.scemode & R_FULL_SAMPLE) re->result = render_result_new_full_sample(re, &re->fullresult, &re->disprect, 0, RR_USE_EXR); else re->result = render_result_new(re, &re->disprect, 0, - (re->r.scemode & R_EXR_TILE_FILE) ? RR_USE_EXR : RR_USE_MEM); + (re->r.scemode & R_EXR_TILE_FILE) ? RR_USE_EXR : RR_USE_MEM, RR_ALL_LAYERS); } BLI_rw_mutex_unlock(&re->resultmutex); @@ -813,9 +810,9 @@ static void threaded_tile_processor(Render *re) /* warning; no return here without closing exr file */ - initparts(re); + initparts(re, TRUE); - if (re->result->exrhandle) + if (re->result->do_exr_tile) render_result_exr_file_begin(re); BLI_init_threads(&threads, do_part_thread, re->r.threads); @@ -895,7 +892,7 @@ static void threaded_tile_processor(Render *re) } - if (re->result->exrhandle) { + if (re->result->do_exr_tile) { BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); render_result_exr_file_end(re); BLI_rw_mutex_unlock(&re->resultmutex); @@ -1055,7 +1052,7 @@ static void do_render_blur_3d(Render *re) int blur = re->r.mblur_samples; /* create accumulation render result */ - rres = render_result_new(re, &re->disprect, 0, RR_USE_MEM); + rres = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS); /* do the blur steps */ while (blur--) { @@ -1119,7 +1116,10 @@ static void merge_renderresult_fields(RenderResult *rr, RenderResult *rr1, Rende /* passes are allocated in sync */ rpass1 = rl1->passes.first; rpass2 = rl2->passes.first; - for (rpass = rl->passes.first; rpass && rpass1 && rpass2; rpass = rpass->next, rpass1 = rpass1->next, rpass2 = rpass2->next) { + for (rpass = rl->passes.first; + rpass && rpass1 && rpass2; + rpass = rpass->next, rpass1 = rpass1->next, rpass2 = rpass2->next) + { interleave_rect(rr, rpass->rect, rpass1->rect, rpass2->rect, rpass->channels); } } @@ -1180,7 +1180,7 @@ static void do_render_fields_3d(Render *re) re->disprect.ymax *= 2; BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); - re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM); + re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS); if (rr2) { if (re->r.mode & R_ODDFIELD) @@ -1243,7 +1243,7 @@ static void do_render_fields_blur_3d(Render *re) re->rectx = re->winx; re->recty = re->winy; - rres = render_result_new(re, &re->disprect, 0, RR_USE_MEM); + rres = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS); render_result_merge(rres, re->result); render_result_free(re->result); @@ -1632,7 +1632,7 @@ static void do_render_composite_fields_blur_3d(Render *re) BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); render_result_free(re->result); - re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM); + re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS); BLI_rw_mutex_unlock(&re->resultmutex); @@ -1770,7 +1770,7 @@ static void do_render_seq(Render *re) if (recurs_depth == 0) { /* with nested scenes, only free on toplevel... */ Editing *ed = re->scene->ed; if (ed) - BKE_sequencer_free_imbuf(re->scene, &ed->seqbase, TRUE, TRUE); + BKE_sequencer_free_imbuf(re->scene, &ed->seqbase, TRUE); } IMB_freeImBuf(ibuf); } @@ -1929,7 +1929,7 @@ int RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *r if (scene->r.scemode & (R_EXR_TILE_FILE | R_FULL_SAMPLE)) { char str[FILE_MAX]; - render_result_exr_file_path(scene, 0, str); + render_result_exr_file_path(scene, "", 0, str); if (BLI_file_is_writable(str) == 0) { BKE_report(reports, RPT_ERROR, "Can not save render buffers, check the temp default path"); @@ -2013,7 +2013,7 @@ static void validate_render_settings(Render *re) if (RE_engine_is_external(re)) { /* not supported yet */ - re->r.scemode &= ~(R_EXR_TILE_FILE | R_FULL_SAMPLE); + re->r.scemode &= ~(R_FULL_SAMPLE); re->r.mode &= ~(R_FIELDS | R_MBLUR); } } @@ -2512,7 +2512,7 @@ void RE_layer_load_from_file(RenderLayer *layer, ReportList *reports, const char void RE_result_load_from_file(RenderResult *result, ReportList *reports, const char *filename) { - if (!render_result_exr_file_read_path(result, filename)) { + if (!render_result_exr_file_read_path(result, NULL, filename)) { BKE_reportf(reports, RPT_ERROR, "RE_result_rect_from_file: failed to load '%s'\n", filename); return; } diff --git a/source/blender/render/intern/source/render_result.c b/source/blender/render/intern/source/render_result.c index 83bbaa7edbe..fb1a7885390 100644 --- a/source/blender/render/intern/source/render_result.c +++ b/source/blender/render/intern/source/render_result.c @@ -30,6 +30,7 @@ */ #include <stdio.h> +#include <stdlib.h> #include <string.h> #include "MEM_guardedalloc.h" @@ -38,7 +39,6 @@ #include "BKE_global.h" #include "BKE_main.h" #include "BKE_report.h" -#include "BKE_utildefines.h" #include "BLI_fileops.h" #include "BLI_listbase.h" @@ -387,10 +387,10 @@ static void render_layer_add_pass(RenderResult *rr, RenderLayer *rl, int channel rpass->recty = rl->recty; BLI_strncpy(rpass->name, get_pass_name(rpass->passtype, -1), sizeof(rpass->name)); - if (rr->exrhandle) { + if (rl->exrhandle) { int a; for (a = 0; a < channels; a++) - IMB_exr_add_channel(rr->exrhandle, rl->name, get_pass_name(passtype, a), 0, 0, NULL); + IMB_exr_add_channel(rl->exrhandle, rl->name, get_pass_name(passtype, a), 0, 0, NULL); } else { float *rect; @@ -416,7 +416,7 @@ static void render_layer_add_pass(RenderResult *rr, RenderLayer *rl, int channel /* will read info from Render *re to define layers */ /* called in threads */ /* re->winx,winy is coordinate space of entire image, partrct the part within */ -RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuffers) +RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuffers, const char *layername) { RenderResult *rr; RenderLayer *rl; @@ -438,17 +438,21 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf /* tilerect is relative coordinates within render disprect. do not subtract crop yet */ rr->tilerect.xmin = partrct->xmin - re->disprect.xmin; - rr->tilerect.xmax = partrct->xmax - re->disprect.xmax; + rr->tilerect.xmax = partrct->xmax - re->disprect.xmin; rr->tilerect.ymin = partrct->ymin - re->disprect.ymin; - rr->tilerect.ymax = partrct->ymax - re->disprect.ymax; + rr->tilerect.ymax = partrct->ymax - re->disprect.ymin; if (savebuffers) { - rr->exrhandle = IMB_exr_get_handle(); + rr->do_exr_tile = TRUE; } - + /* check renderdata for amount of layers */ for (nr = 0, srl = re->r.layers.first; srl; srl = srl->next, nr++) { - + + if (layername && layername[0]) + if (strcmp(srl->name, layername) != 0) + continue; + if ((re->r.scemode & R_SINGLE_LAYER) && nr != re->r.actlay) continue; if (srl->layflag & SCE_LAY_DISABLE) @@ -469,11 +473,13 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf rl->rectx = rectx; rl->recty = recty; - if (rr->exrhandle) { - IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.R", 0, 0, NULL); - IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.G", 0, 0, NULL); - IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.B", 0, 0, NULL); - IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.A", 0, 0, NULL); + if (rr->do_exr_tile) { + rl->exrhandle = IMB_exr_get_handle(); + + IMB_exr_add_channel(rl->exrhandle, rl->name, "Combined.R", 0, 0, NULL); + IMB_exr_add_channel(rl->exrhandle, rl->name, "Combined.G", 0, 0, NULL); + IMB_exr_add_channel(rl->exrhandle, rl->name, "Combined.B", 0, 0, NULL); + IMB_exr_add_channel(rl->exrhandle, rl->name, "Combined.A", 0, 0, NULL); } else rl->rectf = MEM_mapallocN(rectx * recty * sizeof(float) * 4, "Combined rgba"); @@ -535,7 +541,7 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf } /* sss, previewrender and envmap don't do layers, so we make a default one */ - if (rr->layers.first == NULL) { + if (rr->layers.first == NULL && !(layername && layername[0])) { rl = MEM_callocN(sizeof(RenderLayer), "new render layer"); BLI_addtail(&rr->layers, rl); @@ -543,14 +549,17 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf rl->recty = recty; /* duplicate code... */ - if (rr->exrhandle) { - IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.R", 0, 0, NULL); - IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.G", 0, 0, NULL); - IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.B", 0, 0, NULL); - IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.A", 0, 0, NULL); + if (rr->do_exr_tile) { + rl->exrhandle = IMB_exr_get_handle(); + + IMB_exr_add_channel(rl->exrhandle, rl->name, "Combined.R", 0, 0, NULL); + IMB_exr_add_channel(rl->exrhandle, rl->name, "Combined.G", 0, 0, NULL); + IMB_exr_add_channel(rl->exrhandle, rl->name, "Combined.B", 0, 0, NULL); + IMB_exr_add_channel(rl->exrhandle, rl->name, "Combined.A", 0, 0, NULL); } - else + else { rl->rectf = MEM_mapallocN(rectx * recty * sizeof(float) * 4, "Combined rgba"); + } /* note, this has to be in sync with scene.c */ rl->lay = (1 << 20) - 1; @@ -574,10 +583,10 @@ RenderResult *render_result_new_full_sample(Render *re, ListBase *lb, rcti *part int a; if (re->osa == 0) - return render_result_new(re, partrct, crop, savebuffers); + return render_result_new(re, partrct, crop, savebuffers, RR_ALL_LAYERS); for (a = 0; a < re->osa; a++) { - RenderResult *rr = render_result_new(re, partrct, crop, savebuffers); + RenderResult *rr = render_result_new(re, partrct, crop, savebuffers, RR_ALL_LAYERS); BLI_addtail(lb, rr); rr->sample_nr = a; } @@ -686,15 +695,20 @@ void render_result_merge(RenderResult *rr, RenderResult *rrpart) RenderLayer *rl, *rlp; RenderPass *rpass, *rpassp; - for (rl = rr->layers.first, rlp = rrpart->layers.first; rl && rlp; rl = rl->next, rlp = rlp->next) { - - /* combined */ - if (rl->rectf && rlp->rectf) - do_merge_tile(rr, rrpart, rl->rectf, rlp->rectf, 4); - - /* passes are allocated in sync */ - for (rpass = rl->passes.first, rpassp = rlp->passes.first; rpass && rpassp; rpass = rpass->next, rpassp = rpassp->next) { - do_merge_tile(rr, rrpart, rpass->rect, rpassp->rect, rpass->channels); + for (rl = rr->layers.first; rl; rl = rl->next) { + rlp = RE_GetRenderLayer(rrpart, rl->name); + if (rlp) { + /* combined */ + if (rl->rectf && rlp->rectf) + do_merge_tile(rr, rrpart, rl->rectf, rlp->rectf, 4); + + /* passes are allocated in sync */ + for (rpass = rl->passes.first, rpassp = rlp->passes.first; + rpass && rpassp; + rpass = rpass->next, rpassp = rpassp->next) + { + do_merge_tile(rr, rrpart, rpass->rect, rpassp->rect, rpass->channels); + } } } } @@ -739,21 +753,24 @@ int RE_WriteRenderResult(ReportList *reports, RenderResult *rr, const char *file /* combined */ if (rl->rectf) { int a, xstride = 4; - for (a = 0; a < xstride; a++) - IMB_exr_add_channel(exrhandle, rl->name, get_pass_name(SCE_PASS_COMBINED, a), + for (a = 0; a < xstride; a++) { + IMB_exr_add_channel(exrhandle, rl->name, get_pass_name(SCE_PASS_COMBINED, a), xstride, xstride * rr->rectx, rl->rectf + a); + } } /* passes are allocated in sync */ for (rpass = rl->passes.first; rpass; rpass = rpass->next) { int a, xstride = rpass->channels; for (a = 0; a < xstride; a++) { - if (rpass->passtype) - IMB_exr_add_channel(exrhandle, rl->name, get_pass_name(rpass->passtype, a), + if (rpass->passtype) { + IMB_exr_add_channel(exrhandle, rl->name, get_pass_name(rpass->passtype, a), xstride, xstride * rr->rectx, rpass->rect + a); - else - IMB_exr_add_channel(exrhandle, rl->name, make_pass_name(rpass, a), + } + else { + IMB_exr_add_channel(exrhandle, rl->name, make_pass_name(rpass, a), xstride, xstride * rr->rectx, rpass->rect + a); + } } } } @@ -811,8 +828,9 @@ void render_result_single_layer_end(Render *re) /* reconstruct render result layers */ for (nr = 0, srl = re->scene->r.layers.first; srl; srl = srl->next, nr++) { - if (nr == re->r.actlay) + if (nr == re->r.actlay) { BLI_addtail(&re->result->layers, rl); + } else { rlpush = RE_GetRenderLayer(re->pushedresult, srl->name); if (rlpush) { @@ -831,14 +849,21 @@ void render_result_single_layer_end(Render *re) static void save_render_result_tile(RenderResult *rr, RenderResult *rrpart) { - RenderLayer *rlp; + RenderLayer *rlp, *rl; RenderPass *rpassp; int offs, partx, party; BLI_lock_thread(LOCK_IMAGE); for (rlp = rrpart->layers.first; rlp; rlp = rlp->next) { - + rl = RE_GetRenderLayer(rr, rlp->name); + + /* should never happen but prevents crash if it does */ + BLI_assert(rl); + if (UNLIKELY(rl == NULL)) { + continue; + } + if (rrpart->crop) { /* filters add pixel extra */ offs = (rrpart->crop + rrpart->crop * rrpart->rectx); } @@ -849,24 +874,37 @@ static void save_render_result_tile(RenderResult *rr, RenderResult *rrpart) /* combined */ if (rlp->rectf) { int a, xstride = 4; - for (a = 0; a < xstride; a++) - IMB_exr_set_channel(rr->exrhandle, rlp->name, get_pass_name(SCE_PASS_COMBINED, a), + for (a = 0; a < xstride; a++) { + IMB_exr_set_channel(rl->exrhandle, rlp->name, get_pass_name(SCE_PASS_COMBINED, a), xstride, xstride * rrpart->rectx, rlp->rectf + a + xstride * offs); + } } /* passes are allocated in sync */ for (rpassp = rlp->passes.first; rpassp; rpassp = rpassp->next) { int a, xstride = rpassp->channels; - for (a = 0; a < xstride; a++) - IMB_exr_set_channel(rr->exrhandle, rlp->name, get_pass_name(rpassp->passtype, a), + for (a = 0; a < xstride; a++) { + IMB_exr_set_channel(rl->exrhandle, rlp->name, get_pass_name(rpassp->passtype, a), xstride, xstride * rrpart->rectx, rpassp->rect + a + xstride * offs); + } } } party = rrpart->tilerect.ymin + rrpart->crop; partx = rrpart->tilerect.xmin + rrpart->crop; - IMB_exrtile_write_channels(rr->exrhandle, partx, party, 0); + + for (rlp = rrpart->layers.first; rlp; rlp = rlp->next) { + rl = RE_GetRenderLayer(rr, rlp->name); + + /* should never happen but prevents crash if it does */ + BLI_assert(rl); + if (UNLIKELY(rl == NULL)) { + continue; + } + + IMB_exrtile_write_channels(rl->exrhandle, partx, party, 0); + } BLI_unlock_thread(LOCK_IMAGE); } @@ -875,15 +913,18 @@ static void save_empty_result_tiles(Render *re) { RenderPart *pa; RenderResult *rr; + RenderLayer *rl; for (rr = re->result; rr; rr = rr->next) { - IMB_exrtile_clear_channels(rr->exrhandle); + for (rl = rr->layers.first; rl; rl = rl->next) { + IMB_exrtile_clear_channels(rl->exrhandle); - for (pa = re->parts.first; pa; pa = pa->next) { - if (pa->ready == 0) { - int party = pa->disprect.ymin - re->disprect.ymin + pa->crop; - int partx = pa->disprect.xmin - re->disprect.xmin + pa->crop; - IMB_exrtile_write_channels(rr->exrhandle, partx, party, 0); + for (pa = re->parts.first; pa; pa = pa->next) { + if (pa->ready == 0) { + int party = pa->disprect.ymin - re->disprect.ymin + pa->crop; + int partx = pa->disprect.xmin - re->disprect.xmin + pa->crop; + IMB_exrtile_write_channels(rl->exrhandle, partx, party, 0); + } } } } @@ -893,13 +934,15 @@ static void save_empty_result_tiles(Render *re) void render_result_exr_file_begin(Render *re) { RenderResult *rr; + RenderLayer *rl; char str[FILE_MAX]; - + for (rr = re->result; rr; rr = rr->next) { - render_result_exr_file_path(re->scene, rr->sample_nr, str); - - printf("write exr tmp file, %dx%d, %s\n", rr->rectx, rr->recty, str); - IMB_exrtile_begin_write(rr->exrhandle, str, 0, rr->rectx, rr->recty, re->partx, re->party); + for (rl = rr->layers.first; rl; rl = rl->next) { + render_result_exr_file_path(re->scene, rl->name, rr->sample_nr, str); + printf("write exr tmp file, %dx%d, %s\n", rr->rectx, rr->recty, str); + IMB_exrtile_begin_write(rl->exrhandle, str, 0, rr->rectx, rr->recty, re->partx, re->party); + } } } @@ -907,12 +950,17 @@ void render_result_exr_file_begin(Render *re) void render_result_exr_file_end(Render *re) { RenderResult *rr; + RenderLayer *rl; save_empty_result_tiles(re); for (rr = re->result; rr; rr = rr->next) { - IMB_exr_close(rr->exrhandle); - rr->exrhandle = NULL; + for (rl = rr->layers.first; rl; rl = rl->next) { + IMB_exr_close(rl->exrhandle); + rl->exrhandle = NULL; + } + + rr->do_exr_tile = FALSE; } render_result_free_list(&re->fullresult, re->result); @@ -929,17 +977,17 @@ void render_result_exr_file_merge(RenderResult *rr, RenderResult *rrpart) } /* path to temporary exr file */ -void render_result_exr_file_path(Scene *scene, int sample, char *filepath) +void render_result_exr_file_path(Scene *scene, const char *layname, int sample, char *filepath) { - char di[FILE_MAX], name[FILE_MAXFILE + MAX_ID_NAME + 100], fi[FILE_MAXFILE]; + char di[FILE_MAX], name[FILE_MAXFILE + MAX_ID_NAME + MAX_ID_NAME + 100], fi[FILE_MAXFILE]; BLI_strncpy(di, G.main->name, FILE_MAX); BLI_splitdirstring(di, fi); if (sample == 0) - BLI_snprintf(name, sizeof(name), "%s_%s.exr", fi, scene->id.name + 2); + BLI_snprintf(name, sizeof(name), "%s_%s_%s.exr", fi, scene->id.name + 2, layname); else - BLI_snprintf(name, sizeof(name), "%s_%s%d.exr", fi, scene->id.name + 2, sample); + BLI_snprintf(name, sizeof(name), "%s_%s_%s%d.exr", fi, scene->id.name + 2, layname, sample); BLI_make_file_string("/", filepath, BLI_temporary_dir(), name); } @@ -947,29 +995,30 @@ void render_result_exr_file_path(Scene *scene, int sample, char *filepath) /* only for temp buffer files, makes exact copy of render result */ int render_result_exr_file_read(Render *re, int sample) { + RenderLayer *rl; char str[FILE_MAX]; - int success; + int success = TRUE; RE_FreeRenderResult(re->result); - re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM); + re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS); - render_result_exr_file_path(re->scene, sample, str); - printf("read exr tmp file: %s\n", str); + for (rl = re->result->layers.first; rl; rl = rl->next) { - if (render_result_exr_file_read_path(re->result, str)) { - success = TRUE; - } - else { - printf("cannot read: %s\n", str); - success = FALSE; + render_result_exr_file_path(re->scene, rl->name, sample, str); + printf("read exr tmp file: %s\n", str); + + if (!render_result_exr_file_read_path(re->result, rl, str)) { + printf("cannot read: %s\n", str); + success = FALSE; + } } return success; } /* called for reading temp files, and for external engines */ -int render_result_exr_file_read_path(RenderResult *rr, const char *filepath) +int render_result_exr_file_read_path(RenderResult *rr, RenderLayer *rl_single, const char *filepath) { RenderLayer *rl; RenderPass *rpass; @@ -992,6 +1041,9 @@ int render_result_exr_file_read_path(RenderResult *rr, const char *filepath) } for (rl = rr->layers.first; rl; rl = rl->next) { + if (rl_single && rl_single != rl) + continue; + /* combined */ if (rl->rectf) { int a, xstride = 4; diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c index 14c178c10f9..cbe8cc81451 100644 --- a/source/blender/render/intern/source/render_texture.c +++ b/source/blender/render/intern/source/render_texture.c @@ -93,13 +93,9 @@ extern struct Render R; static void init_render_texture(Render *re, Tex *tex) { - int cfra= re->scene->r.cfra; - - if (re) cfra= re->r.cfra; - /* imap test */ if (tex->ima && ELEM(tex->ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) { - BKE_image_user_frame_calc(&tex->iuser, cfra, re?re->flag & R_SEC_FIELD:0); + BKE_image_user_frame_calc(&tex->iuser, re->r.cfra, re?re->flag & R_SEC_FIELD:0); } else if (tex->type==TEX_ENVMAP) { diff --git a/source/blender/render/intern/source/texture_ocean.c b/source/blender/render/intern/source/texture_ocean.c index b842cab1d29..8c9df496dd6 100644 --- a/source/blender/render/intern/source/texture_ocean.c +++ b/source/blender/render/intern/source/texture_ocean.c @@ -36,7 +36,6 @@ #include "BKE_modifier.h" #include "BKE_ocean.h" -#include "BKE_utildefines.h" #include "render_types.h" #include "RE_shader_ext.h" diff --git a/source/blender/windowmanager/WM_keymap.h b/source/blender/windowmanager/WM_keymap.h index 78dbd253cd6..5c88babfb47 100644 --- a/source/blender/windowmanager/WM_keymap.h +++ b/source/blender/windowmanager/WM_keymap.h @@ -57,11 +57,11 @@ void WM_keymap_init (struct bContext *C); void WM_keymap_free (struct wmKeyMap *keymap); wmKeyMapItem *WM_keymap_verify_item(struct wmKeyMap *keymap, const char *idname, int type, - int val, int modifier, int keymodifier); + int val, int modifier, int keymodifier); wmKeyMapItem *WM_keymap_add_item(struct wmKeyMap *keymap, const char *idname, int type, - int val, int modifier, int keymodifier); + int val, int modifier, int keymodifier); wmKeyMapItem *WM_keymap_add_menu(struct wmKeyMap *keymap, const char *idname, int type, - int val, int modifier, int keymodifier); + int val, int modifier, int keymodifier); void WM_keymap_remove_item(struct wmKeyMap *keymap, struct wmKeyMapItem *kmi); char *WM_keymap_item_to_string(wmKeyMapItem *kmi, char *str, int len); diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 1f0a0d87cf4..4ec3d8ea755 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -115,7 +115,6 @@ struct ImBuf; #include "RNA_types.h" #include "DNA_listBase.h" -#include "BKE_utildefines.h" /* FILE_MAX */ /* exported types for WM */ #include "wm_cursors.h" diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 60c61dbe88c..17f17baba0e 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -1444,14 +1444,15 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand } else { - printf("%s: error - missing modal\n", __func__); + printf("%s: error '%s' missing modal\n", __func__, op->idname); } } else { wmOperatorType *ot = WM_operatortype_find(event->keymap_idname, 0); - if (ot) + if (ot) { retval = wm_operator_invoke(C, ot, event, properties, NULL, FALSE); + } } /* Finished and pass through flag as handled */ @@ -2707,7 +2708,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U switch (type) { /* mouse move */ - case GHOST_kEventCursorMove: { + case GHOST_kEventCursorMove: + { if (win->active) { GHOST_TEventCursorData *cd = customdata; wmEvent *lastevent = win->queue.last; @@ -2750,7 +2752,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U } break; } - case GHOST_kEventTrackpad: { + case GHOST_kEventTrackpad: + { GHOST_TEventTrackpadData *pd = customdata; switch (pd->subtype) { case GHOST_kTrackpadEventMagnify: @@ -2782,7 +2785,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U } /* mouse button */ case GHOST_kEventButtonDown: - case GHOST_kEventButtonUp: { + case GHOST_kEventButtonUp: + { GHOST_TEventButtonData *bd = customdata; event.val = (type == GHOST_kEventButtonDown) ? KM_PRESS : KM_RELEASE; @@ -2830,7 +2834,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U } /* keyboard */ case GHOST_kEventKeyDown: - case GHOST_kEventKeyUp: { + case GHOST_kEventKeyUp: + { GHOST_TEventKeyData *kd = customdata; event.type = convert_key(kd->key); event.ascii = kd->ascii; @@ -2914,7 +2919,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U break; } - case GHOST_kEventWheel: { + case GHOST_kEventWheel: + { GHOST_TEventWheelData *wheelData = customdata; if (wheelData->z > 0) @@ -2927,7 +2933,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U break; } - case GHOST_kEventTimer: { + case GHOST_kEventTimer: + { event.type = TIMER; event.custom = EVT_DATA_TIMER; event.customdata = customdata; @@ -2936,7 +2943,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U break; } - case GHOST_kEventNDOFMotion: { + case GHOST_kEventNDOFMotion: + { event.type = NDOF_MOTION; attach_ndof_data(&event, customdata); wm_event_add(win, &event); @@ -2946,7 +2954,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U break; } - case GHOST_kEventNDOFButton: { + case GHOST_kEventNDOFButton: + { GHOST_TEventNDOFButtonData *e = customdata; event.type = NDOF_BUTTON_NONE + e->button; @@ -2972,12 +2981,12 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U case GHOST_kNumEventTypes: break; - case GHOST_kEventWindowDeactivate: { + case GHOST_kEventWindowDeactivate: + { event.type = WINDEACTIVATE; wm_event_add(win, &event); break; - } } diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index f01ca9f566e..dca28c63557 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -492,6 +492,8 @@ int WM_homefile_read(bContext *C, ReportList *UNUSED(reports), short from_memory char tstr[FILE_MAX]; int success = 0; + BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_LOAD_PRE); + G.relbase_valid = 0; if (!from_memory) { char *cfgdir = BLI_get_folder(BLENDER_USER_CONFIG, NULL); @@ -569,6 +571,9 @@ int WM_homefile_read(bContext *C, ReportList *UNUSED(reports), short from_memory } #endif + /* important to do before NULL'ing the context */ + BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_LOAD_POST); + WM_event_add_notifier(C, NC_WM | ND_FILEREAD, NULL); /* in background mode the scene will stay NULL */ diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 67cd202591d..0259146a9d3 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1002,7 +1002,7 @@ static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op) layout = uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, width, UI_UNIT_Y, style); if (!WM_operator_check_ui_enabled(C, op->type->name)) - uiLayoutSetEnabled(layout, 0); + uiLayoutSetEnabled(layout, FALSE); if (op->type->flag & OPTYPE_MACRO) { for (op = op->macro.first; op; op = op->next) { diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c index 0074d6236db..e3867c0a32a 100644 --- a/source/blender/windowmanager/intern/wm_playanim.c +++ b/source/blender/windowmanager/intern/wm_playanim.c @@ -61,7 +61,6 @@ #include "BKE_blender.h" #include "BKE_global.h" -#include "BKE_utildefines.h" #include "BIF_gl.h" #include "BIF_glutil.h" @@ -327,7 +326,11 @@ static void build_pict_list(char *first, int totframes, int fstep, int fontid) int file; file = open(filepath, O_BINARY | O_RDONLY, 0); - if (file < 0) return; + if (file < 0) { + /* print errno? */ + return; + } + picture = (PlayAnimPict *)MEM_callocN(sizeof(PlayAnimPict), "picture"); if (picture == NULL) { printf("Not enough memory for pict struct '%s'\n", filepath); @@ -701,11 +704,11 @@ void playanim_window_open(const char *title, int posx, int posy, int sizex, int inital_state = start_maximized ? GHOST_kWindowStateMaximized : GHOST_kWindowStateNormal; g_WS.ghost_window = GHOST_CreateWindow(g_WS.ghost_system, - title, - posx, posy, sizex, sizey, - inital_state, - GHOST_kDrawingContextTypeOpenGL, - FALSE /* no stereo */, FALSE); + title, + posx, posy, sizex, sizey, + inital_state, + GHOST_kDrawingContextTypeOpenGL, + FALSE /* no stereo */, FALSE); //if (ghostwin) { //if (win) { diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index b83b93454e6..59c8235faf0 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -724,11 +724,13 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr break; } - case GHOST_kEventWindowClose: { + case GHOST_kEventWindowClose: + { wm_window_close(C, wm, win); break; } - case GHOST_kEventWindowUpdate: { + case GHOST_kEventWindowUpdate: + { if (G.debug & G_DEBUG_EVENTS) { printf("%s: ghost redraw %d\n", __func__, win->winid); } @@ -739,7 +741,8 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr break; } case GHOST_kEventWindowSize: - case GHOST_kEventWindowMove: { + case GHOST_kEventWindowMove: + { GHOST_TWindowState state; state = GHOST_GetWindowState(win->ghostwin); win->windowstate = state; diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 38b87824cfb..b6228849ec8 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -791,6 +791,9 @@ if(WITH_CYCLES) cycles_kernel cycles_util cycles_subd) + if(WITH_CYCLES_OSL) + list(APPEND BLENDER_LINK_LIBS cycles_kernel_osl) + endif() endif() #if(UNIX) @@ -955,6 +958,10 @@ endif() list(APPEND BLENDER_SORTED_LIBS extern_xdnd) endif() + if(WITH_CYCLES_OSL) + list_insert_after(BLENDER_SORTED_LIBS "cycles_kernel" "cycles_kernel_osl") + endif() + foreach(SORTLIB ${BLENDER_SORTED_LIBS}) set(REMLIB ${SORTLIB}) foreach(SEARCHLIB ${BLENDER_LINK_LIBS}) diff --git a/source/creator/creator.c b/source/creator/creator.c index e0e82679645..e1dc2b5df4c 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -68,7 +68,6 @@ #include "BLI_blenlib.h" -#include "BKE_utildefines.h" #include "BKE_blender.h" #include "BKE_context.h" #include "BKE_depsgraph.h" /* for DAG_on_visible_update */ diff --git a/source/darwin/blender.app/Contents/Info.plist b/source/darwin/blender.app/Contents/Info.plist index 37920dc8181..064ffe5bc3f 100644 --- a/source/darwin/blender.app/Contents/Info.plist +++ b/source/darwin/blender.app/Contents/Info.plist @@ -48,5 +48,7 @@ <key>OMP_NUM_THREADS</key> <string>4</string> </dict> + <key>NSPrincipalClass</key> + <string>NSApplication</string> </dict> </plist> diff --git a/source/darwin/blenderplayer.app/Contents/Info.plist b/source/darwin/blenderplayer.app/Contents/Info.plist index 54364d18866..c7b9ceb568e 100644 --- a/source/darwin/blenderplayer.app/Contents/Info.plist +++ b/source/darwin/blenderplayer.app/Contents/Info.plist @@ -1,33 +1,27 @@ <?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> -<plist version="0.9"> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> <dict> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> - <key>CFBundleExecutable</key> <string>blenderplayer</string> - <key>CFBundlePackageType</key> <string>APPL</string> <key>CFBundleSignature</key> <string>????</string> - <key>CFBundleIconFile</key> <string>blender player icon.icns</string> - <key>CFBundleName</key> <string>BlenderPlayer</string> <key>CFBundleIdentifier</key> <string>org.blenderfoundation.blenderplayer</string> - <key>CFBundleVersion</key> <string>${MACOSX_BUNDLE_LONG_VERSION_STRING}, Blender Foundation</string> <key>CFBundleShortVersionString</key> <string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string> <key>CFBundleGetInfoString</key> <string>${MACOSX_BUNDLE_LONG_VERSION_STRING}, Blender Foundation</string> - <key>CFBundleDocumentTypes</key> <array> <dict> @@ -49,5 +43,7 @@ <false/> </dict> </array> + <key>NSPrincipalClass</key> + <string>NSApplication</string> </dict> </plist> diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 1b8f857c2cb..3a06fe979e1 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -54,6 +54,7 @@ #include "KX_BlenderSceneConverter.h" #include "KX_PythonInit.h" #include "KX_PyConstraintBinding.h" +#include "KX_PythonMain.h" #include "RAS_GLExtensionManager.h" #include "RAS_OpenGLRasterizer.h" @@ -79,6 +80,9 @@ extern "C" { #include "DNA_windowmanager_types.h" #include "BKE_global.h" #include "BKE_report.h" + +#include "MEM_guardedalloc.h" + /* #include "BKE_screen.h" */ /* cant include this because of 'new' function name */ extern float BKE_screen_view3d_zoom_to_fac(float camzoom); @@ -121,6 +125,93 @@ static BlendFileData *load_game_data(char *filename) return bfd; } +int BL_KetsjiNextFrame(KX_KetsjiEngine *ketsjiengine, bContext *C, wmWindow *win, Scene *scene, ARegion *ar, + KX_BlenderKeyboardDevice* keyboarddevice, KX_BlenderMouseDevice* mousedevice, int draw_letterbox) +{ + int exitrequested; + + // first check if we want to exit + exitrequested = ketsjiengine->GetExitCode(); + + // kick the engine + bool render = ketsjiengine->NextFrame(); + + if (render) { + if (draw_letterbox) { + // Clear screen to border color + // We do this here since we set the canvas to be within the frames. This means the engine + // itself is unaware of the extra space, so we clear the whole region for it. + glClearColor(scene->gm.framing.col[0], scene->gm.framing.col[1], scene->gm.framing.col[2], 1.0f); + glViewport(ar->winrct.xmin, ar->winrct.ymin, + BLI_RCT_SIZE_X(&ar->winrct), BLI_RCT_SIZE_Y(&ar->winrct)); + glClear(GL_COLOR_BUFFER_BIT); + } + + // render the frame + ketsjiengine->Render(); + } + + wm_window_process_events_nosleep(); + + // test for the ESC key + //XXX while (qtest()) + while (wmEvent *event= (wmEvent *)win->queue.first) { + short val = 0; + //unsigned short event = 0; //XXX extern_qread(&val); + + if (keyboarddevice->ConvertBlenderEvent(event->type,event->val)) + exitrequested = KX_EXIT_REQUEST_BLENDER_ESC; + + /* Coordinate conversion... where + * should this really be? + */ + if (event->type == MOUSEMOVE) { + /* Note, not nice! XXX 2.5 event hack */ + val = event->x - ar->winrct.xmin; + mousedevice->ConvertBlenderEvent(MOUSEX, val); + + val = ar->winy - (event->y - ar->winrct.ymin) - 1; + mousedevice->ConvertBlenderEvent(MOUSEY, val); + } + else { + mousedevice->ConvertBlenderEvent(event->type,event->val); + } + + BLI_remlink(&win->queue, event); + wm_event_free(event); + } + + if (win != CTX_wm_window(C)) { + exitrequested= KX_EXIT_REQUEST_OUTSIDE; /* window closed while bge runs */ + } + return exitrequested; +} + +struct BL_KetsjiNextFrameState { + struct KX_KetsjiEngine* ketsjiengine; + struct bContext *C; + struct wmWindow* win; + struct Scene* scene; + struct ARegion *ar; + KX_BlenderKeyboardDevice* keyboarddevice; + KX_BlenderMouseDevice* mousedevice; + int draw_letterbox; +} ketsjinextframestate; + +int BL_KetsjiPyNextFrame(void *state0) +{ + BL_KetsjiNextFrameState *state = (BL_KetsjiNextFrameState *) state0; + return BL_KetsjiNextFrame( + state->ketsjiengine, + state->C, + state->win, + state->scene, + state->ar, + state->keyboarddevice, + state->mousedevice, + state->draw_letterbox); +} + extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *cam_frame, int always_use_expand_framing) { /* context values */ @@ -440,71 +531,49 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c // Could be in StartEngine set the framerate, we need the scene to do this ketsjiengine->SetAnimFrameRate(FPS); +#ifdef WITH_PYTHON + char *python_main = NULL; + pynextframestate.state = NULL; + pynextframestate.func = NULL; + python_main = KX_GetPythonMain(scene); + // the mainloop printf("\nBlender Game Engine Started\n"); - while (!exitrequested) - { - // first check if we want to exit - exitrequested = ketsjiengine->GetExitCode(); - - // kick the engine - bool render = ketsjiengine->NextFrame(); - - if (render) - { - if (draw_letterbox) { - // Clear screen to border color - // We do this here since we set the canvas to be within the frames. This means the engine - // itself is unaware of the extra space, so we clear the whole region for it. - glClearColor(scene->gm.framing.col[0], scene->gm.framing.col[1], scene->gm.framing.col[2], 1.0f); - glViewport(ar->winrct.xmin, ar->winrct.ymin, - BLI_RCT_SIZE_X(&ar->winrct), BLI_RCT_SIZE_Y(&ar->winrct)); - glClear(GL_COLOR_BUFFER_BIT); - } - - // render the frame - ketsjiengine->Render(); + if (python_main) { + char *python_code = KX_GetPythonCode(blenderdata, python_main); + if (python_code) { + ketsjinextframestate.ketsjiengine = ketsjiengine; + ketsjinextframestate.C = C; + ketsjinextframestate.win = win; + ketsjinextframestate.scene = scene; + ketsjinextframestate.ar = ar; + ketsjinextframestate.keyboarddevice = keyboarddevice; + ketsjinextframestate.mousedevice = mousedevice; + ketsjinextframestate.draw_letterbox = draw_letterbox; + + pynextframestate.state = &ketsjinextframestate; + pynextframestate.func = &BL_KetsjiPyNextFrame; + printf("Yielding control to Python script '%s'...\n", python_main); + PyRun_SimpleString(python_code); + printf("Exit Python script '%s'\n", python_main); + MEM_freeN(python_code); } - - wm_window_process_events_nosleep(); - - // test for the ESC key - //XXX while (qtest()) - while(wmEvent *event= (wmEvent *)win->queue.first) + } + else +#endif /* WITH_PYTHON */ + { + while (!exitrequested) { - short val = 0; - //unsigned short event = 0; //XXX extern_qread(&val); - - if (keyboarddevice->ConvertBlenderEvent(event->type,event->val)) - exitrequested = KX_EXIT_REQUEST_BLENDER_ESC; - - /* Coordinate conversion... where - * should this really be? - */ - if (event->type==MOUSEMOVE) { - /* Note, not nice! XXX 2.5 event hack */ - val = event->x - ar->winrct.xmin; - mousedevice->ConvertBlenderEvent(MOUSEX, val); - - val = ar->winy - (event->y - ar->winrct.ymin) - 1; - mousedevice->ConvertBlenderEvent(MOUSEY, val); - } - else { - mousedevice->ConvertBlenderEvent(event->type,event->val); - } - - BLI_remlink(&win->queue, event); - wm_event_free(event); - } - - if (win != CTX_wm_window(C)) { - exitrequested= KX_EXIT_REQUEST_OUTSIDE; /* window closed while bge runs */ + exitrequested = BL_KetsjiNextFrame(ketsjiengine, C, win, scene, ar, keyboarddevice, mousedevice, draw_letterbox); } } printf("Blender Game Engine Finished\n"); exitstring = ketsjiengine->GetExitString(); - gs = *(ketsjiengine->GetGlobalSettings()); +#ifdef WITH_PYTHON + if (python_main) MEM_freeN(python_main); +#endif /* WITH_PYTHON */ + gs = *(ketsjiengine->GetGlobalSettings()); // when exiting the mainloop #ifdef WITH_PYTHON diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index 89a3f365140..9caa6bbf579 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -82,8 +82,7 @@ #include "BKE_text.h" #include "BLI_blenlib.h" #include "BLI_math_base.h" - -#define FILE_MAX 1024 // repeated here to avoid dependency from BKE_utildefines.h +#include "BLI_path_util.h" #include "KX_NetworkMessageActuator.h" diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 5347aaafc65..a35cb4f9f69 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -262,7 +262,7 @@ PyMethodDef PyObjectPlus::Methods[] = { {NULL, NULL} /* Sentinel */ }; -#define attr_invalid (&(PyObjectPlus::Attributes[0])) +#define BGE_PY_ATTR_INVALID (&(PyObjectPlus::Attributes[0])) PyAttributeDef PyObjectPlus::Attributes[] = { KX_PYATTRIBUTE_RO_FUNCTION("invalid", PyObjectPlus, pyattr_get_invalid), {NULL} //Sentinel @@ -281,7 +281,7 @@ PyObject *PyObjectPlus::py_get_attrdef(PyObject *self_py, const PyAttributeDef * PyObjectPlus *ref= (BGE_PROXY_REF(self_py)); char* ptr = (attrdef->m_usePtr) ? (char*)BGE_PROXY_PTR(self_py) : (char*)ref; if (ptr == NULL || (BGE_PROXY_PYREF(self_py) && (ref==NULL || !ref->py_is_valid()))) { - if (attrdef == attr_invalid) + if (attrdef == BGE_PY_ATTR_INVALID) Py_RETURN_TRUE; // don't bother running the function PyErr_SetString(PyExc_SystemError, BGE_PROXY_ERROR_MSG); diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp index ea4ac1e150b..48fa3257d20 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp +++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp @@ -81,7 +81,7 @@ SCA_Joystick *SCA_Joystick::GetInstance( short int joyindex ) return NULL; #else /* WITH_SDL */ if (joyindex < 0 || joyindex >= JOYINDEX_MAX) { - echo("Error-invalid joystick index: " << joyindex); + ECHO("Error-invalid joystick index: " << joyindex); return NULL; } @@ -96,7 +96,7 @@ SCA_Joystick *SCA_Joystick::GetInstance( short int joyindex ) # else if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO) == -1 ) { # endif - echo("Error-Initializing-SDL: " << SDL_GetError()); + ECHO("Error-Initializing-SDL: " << SDL_GetError()); return NULL; } @@ -242,7 +242,7 @@ bool SCA_Joystick::CreateJoystickDevice(void) if (m_isinit == false) { if (m_joyindex>=m_joynum) { // don't print a message, because this is done anyway - //echo("Joystick-Error: " << SDL_NumJoysticks() << " avaiable joystick(s)"); + //ECHO("Joystick-Error: " << SDL_NumJoysticks() << " avaiable joystick(s)"); // Need this so python args can return empty lists m_axismax = m_buttonmax = m_hatmax = 0; @@ -253,7 +253,7 @@ bool SCA_Joystick::CreateJoystickDevice(void) SDL_JoystickEventState(SDL_ENABLE); m_isinit = true; - echo("Joystick " << m_joyindex << " initialized"); + ECHO("Joystick " << m_joyindex << " initialized"); /* must run after being initialized */ m_axismax = SDL_JoystickNumAxes(m_private->m_joystick); @@ -279,7 +279,7 @@ void SCA_Joystick::DestroyJoystickDevice(void) #ifdef WITH_SDL if (m_isinit) { if (SDL_JoystickOpened(m_joyindex)) { - echo("Closing-joystick " << m_joyindex); + ECHO("Closing-joystick " << m_joyindex); SDL_JoystickClose(m_private->m_joystick); } m_isinit = false; diff --git a/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h b/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h index 45766eb9057..148bdd0962e 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h +++ b/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h @@ -37,10 +37,10 @@ #endif #ifndef _DEBUG -#define echo(x) +# define ECHO(x) #else -#include <iostream> -#define echo(x) std::cout << x << std::endl; +# include <iostream> +# define ECHO(x) std::cout << x << std::endl; #endif #define JOYINDEX_MAX 8 diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index 41f641b4368..d8b07fd50d9 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -47,6 +47,7 @@ #endif // __APPLE__ #include "KX_KetsjiEngine.h" #include "KX_PythonInit.h" +#include "KX_PythonMain.h" /********************************** * Begin Blender include block @@ -97,7 +98,6 @@ extern char datatoc_bfont_ttf[]; #include "RAS_IRasterizer.h" #include "BKE_main.h" -#include "BKE_utildefines.h" #include "RNA_define.h" @@ -332,6 +332,40 @@ static BlendFileData *load_game_data(const char *progname, char *filename = NULL return bfd; } +bool GPG_NextFrame(GHOST_ISystem* system, GPG_Application *app, int &exitcode, STR_String &exitstring, GlobalSettings *gs) +{ + bool run = true; + system->processEvents(false); + system->dispatchEvents(); + app->EngineNextFrame(); + if ((exitcode = app->getExitRequested())) { + run = false; + exitstring = app->getExitString(); + *gs = *app->getGlobalSettings(); + } + return run; +} + +struct GPG_NextFrameState { + GHOST_ISystem* system; + GPG_Application *app; + GlobalSettings *gs; +} gpg_nextframestate; + +int GPG_PyNextFrame(void *state0) +{ + GPG_NextFrameState *state = (GPG_NextFrameState *) state0; + int exitcode; + STR_String exitstring; + bool run = GPG_NextFrame(state->system, state->app, exitcode, exitstring, state->gs); + if (run) return 0; + else { + if (exitcode) + fprintf(stderr, "Exit code %d: %s\n", exitcode, exitstring.ReadPtr()); + return 1; + } +} + int main(int argc, char** argv) { int i; @@ -966,17 +1000,39 @@ int main(int argc, char** argv) // Enter main loop bool run = true; - while (run) + char *python_main = NULL; + pynextframestate.state = NULL; + pynextframestate.func = NULL; +#ifdef WITH_PYTHON + python_main = KX_GetPythonMain(scene); +#endif // WITH_PYTHON + if (python_main) { - system->processEvents(false); - system->dispatchEvents(); - app.EngineNextFrame(); - - if ((exitcode = app.getExitRequested())) + char *python_code = KX_GetPythonCode(maggie, python_main); + if (python_code) + { +#ifdef WITH_PYTHON + gpg_nextframestate.system = system; + gpg_nextframestate.app = &app; + gpg_nextframestate.gs = &gs; + pynextframestate.state = &gpg_nextframestate; + pynextframestate.func = &GPG_PyNextFrame; + + printf("Yielding control to Python script '%s'...\n", python_main); + PyRun_SimpleString(python_code); + printf("Exit Python script '%s'\n", python_main); +#endif // WITH_PYTHON + MEM_freeN(python_code); + } + else { + fprintf(stderr, "ERROR: cannot yield control to Python: no Python text data block named '%s'\n", python_main); + } + } + else + { + while (run) { - run = false; - exitstring = app.getExitString(); - gs = *app.getGlobalSettings(); + run = GPG_NextFrame(system, &app, exitcode, exitstring, &gs); } } app.StopGameEngine(); @@ -986,6 +1042,7 @@ int main(int argc, char** argv) system->removeEventConsumer(&app); BLO_blendfiledata_free(bfd); + if (python_main) MEM_freeN(python_main); } } while (exitcode == KX_EXIT_REQUEST_RESTART_GAME || exitcode == KX_EXIT_REQUEST_START_OTHER_GAME); } diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt index 4b3426e0784..269311b7e00 100644 --- a/source/gameengine/Ketsji/CMakeLists.txt +++ b/source/gameengine/Ketsji/CMakeLists.txt @@ -107,6 +107,7 @@ set(SRC KX_PyMath.cpp KX_PythonInit.cpp KX_PythonInitTypes.cpp + KX_PythonMain.cpp KX_PythonSeq.cpp KX_RadarSensor.cpp KX_RayCast.cpp @@ -189,6 +190,7 @@ set(SRC KX_PyMath.h KX_PythonInit.h KX_PythonInitTypes.h + KX_PythonMain.h KX_PythonSeq.h KX_RadarSensor.h KX_RayCast.h diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 581b3712f97..7d29a20d1a2 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -133,7 +133,6 @@ extern "C" { #include "PHY_IPhysicsEnvironment.h" #include "BKE_main.h" -#include "BKE_utildefines.h" #include "BKE_global.h" #include "BLI_blenlib.h" #include "GPU_material.h" @@ -811,6 +810,23 @@ static PyObject *gLibList(PyObject*, PyObject* args) return list; } +struct PyNextFrameState pynextframestate; +static PyObject *gPyNextFrame(PyObject *) +{ + if (pynextframestate.func == NULL) Py_RETURN_NONE; + if (pynextframestate.state == NULL) Py_RETURN_NONE; //should never happen; raise exception instead? + + if (pynextframestate.func(pynextframestate.state)) //nonzero = stop + { + Py_RETURN_TRUE; + } + else // 0 = go on + { + Py_RETURN_FALSE; + } +} + + static struct PyMethodDef game_methods[] = { {"expandPath", (PyCFunction)gPyExpandPath, METH_VARARGS, (const char *)gPyExpandPath_doc}, {"startGame", (PyCFunction)gPyStartGame, METH_VARARGS, (const char *)gPyStartGame_doc}, @@ -840,7 +856,7 @@ static struct PyMethodDef game_methods[] = { {"getBlendFileList", (PyCFunction)gPyGetBlendFileList, METH_VARARGS, (const char *)"Gets a list of blend files in the same directory as the current blend file"}, {"PrintGLInfo", (PyCFunction)pyPrintExt, METH_NOARGS, (const char *)"Prints GL Extension Info"}, {"PrintMemInfo", (PyCFunction)pyPrintStats, METH_NOARGS, (const char *)"Print engine statistics"}, - + {"NextFrame", (PyCFunction)gPyNextFrame, METH_NOARGS, (const char *)"Render next frame (if Python has control)"}, /* library functions */ {"LibLoad", (PyCFunction)gLibLoad, METH_VARARGS|METH_KEYWORDS, (const char *)""}, {"LibNew", (PyCFunction)gLibNew, METH_VARARGS, (const char *)""}, diff --git a/source/gameengine/Ketsji/KX_PythonInit.h b/source/gameengine/Ketsji/KX_PythonInit.h index 866681b9da7..1500dd97ae1 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.h +++ b/source/gameengine/Ketsji/KX_PythonInit.h @@ -70,6 +70,16 @@ class KX_Scene; void KX_SetActiveScene(class KX_Scene* scene); class KX_Scene* KX_GetActiveScene(); class KX_KetsjiEngine* KX_GetActiveEngine(); + +typedef int (*PyNextFrameFunc)(void *); +struct PyNextFrameState { + //state: can be either a GPG_NextFrameState or a BL_KetsjiNextFrameState + void *state; + //func: can be either GPG_PyNextFrame or BL_KetsjiPyNextFrame + PyNextFrameFunc func; +}; +extern struct PyNextFrameState pynextframestate; + #include "MT_Vector3.h" void KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color); diff --git a/source/gameengine/Ketsji/KX_PythonMain.cpp b/source/gameengine/Ketsji/KX_PythonMain.cpp new file mode 100644 index 00000000000..d926dff0bf5 --- /dev/null +++ b/source/gameengine/Ketsji/KX_PythonMain.cpp @@ -0,0 +1,77 @@ +/* + * $Id: KX_PythonMain.cpp 37750 2011-06-27 09:27:56Z sjoerd $ + * + * ***** 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) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ +/** \file gameengine/Ketsji/KX_PythonMain.cpp + * \ingroup ketsji + */ + +#include "KX_PythonMain.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stddef.h> + +#include "MEM_guardedalloc.h" + +#include "BLI_string.h" +#include "BLI_listbase.h" + +#include "BKE_text.h" +#include "BKE_main.h" +#include "BKE_idprop.h" + + +#ifdef __cplusplus +} +#endif + +extern "C" char *KX_GetPythonMain(struct Scene *scene) +{ + /* examine custom scene properties */ + if (scene->id.properties) { + IDProperty *item = IDP_GetPropertyTypeFromGroup(scene->id.properties, "__main__", IDP_STRING); + if (item) { + return BLI_strdup(IDP_String(item)); + } + } + + return NULL; +} + +extern "C" char *KX_GetPythonCode(Main *bmain, char *python_main) +{ + Text *text; + + if ((text = (Text *)BLI_findstring(&bmain->text, python_main, offsetof(ID, name) + 2))) { + return txt_to_buf(text); + } + + return NULL; +} diff --git a/source/gameengine/Ketsji/KX_PythonMain.h b/source/gameengine/Ketsji/KX_PythonMain.h new file mode 100644 index 00000000000..1460ea2ca96 --- /dev/null +++ b/source/gameengine/Ketsji/KX_PythonMain.h @@ -0,0 +1,41 @@ +/* + * $Id: KX_PythonMain.h 37750 2011-06-27 09:27:56Z sjoerd $ + * + * ***** 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) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file KX_PythonMain.h + * \ingroup ketsji + */ + +#ifndef __KX_PYTHON_MAIN +#define __KX_PYTHON_MAIN + +#include "BKE_main.h" +#include "DNA_scene_types.h" +extern "C" char *KX_GetPythonMain(struct Scene* scene); +extern "C" char *KX_GetPythonCode(struct Main *main, char *python_main); +#endif diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index f9fa0ae65f1..c1afed82b02 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1727,11 +1727,6 @@ static void MergeScene_LogicBrick(SCA_ILogicBrick* brick, KX_Scene *to) brick->Replace_IScene(to); brick->Replace_NetworkScene(to->GetNetworkScene()); - SCA_ISensor *sensor= dynamic_cast<class SCA_ISensor *>(brick); - if (sensor) { - sensor->Replace_EventManager(logicmgr); - } - /* near sensors have physics controllers */ #ifdef USE_BULLET KX_TouchSensor *touch_sensor = dynamic_cast<class KX_TouchSensor *>(brick); @@ -1739,6 +1734,14 @@ static void MergeScene_LogicBrick(SCA_ILogicBrick* brick, KX_Scene *to) touch_sensor->GetPhysicsController()->SetPhysicsEnvironment(to->GetPhysicsEnvironment()); } #endif + + // If we end up replacing a KX_TouchEventManager, we need to make sure + // physics controllers are properly in place. In other words, do this + // after merging physics controllers! + SCA_ISensor *sensor= dynamic_cast<class SCA_ISensor *>(brick); + if (sensor) { + sensor->Replace_EventManager(logicmgr); + } } #ifdef USE_BULLET diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp index 92c390efd39..06251cd2282 100644 --- a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp +++ b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp @@ -431,7 +431,7 @@ void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas) // reverting to texunit 0, without this we get bug [#28462] glActiveTextureARB(GL_TEXTURE0); - glViewport(rect.GetLeft(), rect.GetBottom(), rect_width, rect.GetHeight()+1); + glViewport(rect.GetLeft(), rect.GetBottom(), rect_width, rect_height); glDisable(GL_DEPTH_TEST); // in case the previous material was wire diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.cpp b/source/gameengine/Rasterizer/RAS_MeshObject.cpp index 7da0be3a506..25afefbcc5a 100644 --- a/source/gameengine/Rasterizer/RAS_MeshObject.cpp +++ b/source/gameengine/Rasterizer/RAS_MeshObject.cpp @@ -536,18 +536,18 @@ void RAS_MeshObject::SortPolygons(RAS_MeshSlot& ms, const MT_Transform &transfor const MT_Vector3 pnorm(transform.getBasis()[2]); // unneeded: const MT_Scalar pval = transform.getOrigin()[2]; - vector<polygonSlot> slots(totpoly); + vector<polygonSlot> poly_slots(totpoly); /* get indices and z into temporary array */ for (j=0; j<totpoly; j++) - slots[j].get(it.vertex, it.index, j*nvert, nvert, pnorm); + poly_slots[j].get(it.vertex, it.index, j*nvert, nvert, pnorm); /* sort (stable_sort might be better, if flickering happens?) */ - std::sort(slots.begin(), slots.end(), backtofront()); + std::sort(poly_slots.begin(), poly_slots.end(), backtofront()); /* get indices from temporary array again */ for (j=0; j<totpoly; j++) - slots[j].set(it.index, j*nvert, nvert); + poly_slots[j].set(it.index, j*nvert, nvert); } } diff --git a/source/tests/bl_rna_wiki_reference.py b/source/tests/bl_rna_wiki_reference.py new file mode 100644 index 00000000000..2018c4327a3 --- /dev/null +++ b/source/tests/bl_rna_wiki_reference.py @@ -0,0 +1,70 @@ +# ##### 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. +# +# ##### END GPL LICENSE BLOCK ##### + +# <pep8 compliant> + +# Use for validating our wiki interlinking. +# ./blender.bin --background -noaudio --python source/tests/bl_rna_wiki_reference.py +# +# 1) test_lookup_coverage() -- ensure that we have lookups for _every_ RNA path +# 2) test_urls() -- ensure all the URL's are correct +# 3) test_language_coverage() -- ensure language lookup table is complete +# + +import bpy + +# a stripped down version of api_dump() in rna_info_dump.py + + +def test_lookup_coverage(): + + def rna_ids(): + + import rna_info + struct = rna_info.BuildRNAInfo()[0] + for struct_id, v in sorted(struct.items()): + props = [(prop.identifier, prop) for prop in v.properties] + for prop_id, prop in props: + yield "bpy.types.%s.%s" % (struct_id[1], prop_id) + + for submod_id in dir(bpy.ops): + for op_id in dir(getattr(bpy.ops, submod_id)): + yield "bpy.ops.%s.%s" % (submod_id, op_id) + + # check coverage + from bl_operators import wm + + for rna_id in rna_ids(): + url = wm.WM_OT_doc_view_manual._lookup_rna_url(rna_id, verbose=False) + print(rna_id, "->", url) + + +def test_urls(): + pass # TODO + + +def test_language_coverage(): + pass # TODO + + +def main(): + test_lookup_coverage() + test_language_coverage() + +if __name__ == "__main__": + main() diff --git a/source/tests/pep8.py b/source/tests/pep8.py index d12397ea81d..ccaaeb7c0cd 100644 --- a/source/tests/pep8.py +++ b/source/tests/pep8.py @@ -43,7 +43,7 @@ FORCE_PEP8_ALL = False def file_list_py(path): for dirpath, dirnames, filenames in os.walk(path): for filename in filenames: - if filename.endswith(".py") or filename.endswith(".cfg"): + if filename.endswith((".py", ".cfg")): yield os.path.join(dirpath, filename) diff --git a/source/tests/rna_info_dump.py b/source/tests/rna_info_dump.py index 293c02dfb84..615c3b035ce 100644 --- a/source/tests/rna_info_dump.py +++ b/source/tests/rna_info_dump.py @@ -19,7 +19,7 @@ # <pep8 compliant> # Used for generating API diff's between releases -# ./blender.bin --background -noaudio --python release/test/rna_info_dump.py +# ./blender.bin --background -noaudio --python source/tests/rna_info_dump.py import bpy |