diff options
Diffstat (limited to 'source/blender/blenkernel')
65 files changed, 858 insertions, 715 deletions
diff --git a/source/blender/blenkernel/BKE_action.h b/source/blender/blenkernel/BKE_action.h index 698098d28c3..3ac5c8c9a76 100644 --- a/source/blender/blenkernel/BKE_action.h +++ b/source/blender/blenkernel/BKE_action.h @@ -132,61 +132,21 @@ struct bActionGroup *BKE_action_group_find_name(struct bAction *act, const char void action_groups_clear_tempflags(struct bAction *act); /* Pose API ----------------- */ - -/** - * Deallocates a pose channel. - * Does not free the pose channel itself. - */ -void BKE_pose_channel_free(struct bPoseChannel *pchan); - -/** - * Removes and deallocates all channels from a pose. - * Does not free the pose itself. - */ -void BKE_pose_channels_free(struct bPose *pose); -/** - * Removes the hash for quick lookup of channels, must - * be done when adding/removing channels. - */ -void BKE_pose_channels_hash_make(struct bPose *pose); -void BKE_pose_channels_hash_free(struct bPose *pose); - -/** - * Removes and deallocates all data from a pose, and also frees the pose. - */ -void BKE_pose_free(struct bPose *pose); +void BKE_pose_channel_free(struct bPoseChannel *pchan); -/** - * Allocate a new pose on the heap, and copy the src pose and it's channels - * into the new pose. *dst is set to the newly allocated structure, and assumed to be NULL. - */ -void BKE_pose_copy_data(struct bPose **dst, struct bPose *src, int copyconstraints); +void BKE_pose_channels_free(struct bPose *pose); -/** - * Copy the internal members of each pose channel including constraints - * and ID-Props, used when duplicating bones in editmode. - */ -void BKE_pose_channel_copy_data(struct bPoseChannel *pchan, const struct bPoseChannel *pchan_from); +void BKE_pose_channels_hash_make(struct bPose *pose); +void BKE_pose_channels_hash_free(struct bPose *pose); -/** - * Return a pointer to the pose channel of the given name - * from this pose. - */ +void BKE_pose_free(struct bPose *pose); +void BKE_pose_copy_data(struct bPose **dst, struct bPose *src, const bool copy_constraints); +void BKE_pose_channel_copy_data(struct bPoseChannel *pchan, const struct bPoseChannel *pchan_from); struct bPoseChannel *BKE_pose_channel_find_name(const struct bPose *pose, const char *name); - -/** - * Return a pointer to the active pose channel from this Object. - * (Note: Object, not bPose is used here, as we need layer info from Armature) - */ struct bPoseChannel *BKE_pose_channel_active(struct Object *ob); - -/** - * Looks to see if the channel with the given name - * already exists in this pose - if not a new one is - * allocated and initialized. - */ struct bPoseChannel *BKE_pose_channel_verify(struct bPose *pose, const char *name); +struct bPoseChannel *BKE_pose_channel_get_mirrored(const struct bPose *pose, const char *name); #ifndef NDEBUG bool BKE_pose_channels_is_valid(const struct bPose *pose); diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h index f0f6b5a2319..a0ec6c7757f 100644 --- a/source/blender/blenkernel/BKE_animsys.h +++ b/source/blender/blenkernel/BKE_animsys.h @@ -104,6 +104,10 @@ void BKE_keyingsets_free(struct ListBase *list); /* ************************************* */ /* Path Fixing API */ +/* Fix all the paths for the the given ID + Action */ +void BKE_action_fix_paths_rename(struct ID *owner_id, struct bAction *act, const char *prefix, const char *oldName, + const char *newName, int oldSubscript, int newSubscript, int verify_paths); + /* Fix all the paths for the given ID+AnimData */ void BKE_animdata_fix_paths_rename(struct ID *owner_id, struct AnimData *adt, struct ID *ref_id, const char *prefix, const char *oldName, const char *newName, int oldSubscript, int newSubscript, diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index 5b32e7229d5..f2d9c0efc13 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 269 -#define BLENDER_SUBVERSION 1 +#define BLENDER_SUBVERSION 2 /* 262 was the last editmesh release but it has compatibility code for bmesh data */ #define BLENDER_MINVERSION 262 #define BLENDER_MINSUBVERSION 0 diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h index 8d4c9e782db..9e1bca45432 100644 --- a/source/blender/blenkernel/BKE_bvhutils.h +++ b/source/blender/blenkernel/BKE_bvhutils.h @@ -116,6 +116,8 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f #define BVHTREE_FROM_VERTICES 1 #define BVHTREE_FROM_EDGES 2 +#define BVHTREE_FROM_FACES_EDITMESH 3 + typedef struct LinkNode *BVHCache; diff --git a/source/blender/blenkernel/BKE_cdderivedmesh.h b/source/blender/blenkernel/BKE_cdderivedmesh.h index ddb36df74ca..560617db474 100644 --- a/source/blender/blenkernel/BKE_cdderivedmesh.h +++ b/source/blender/blenkernel/BKE_cdderivedmesh.h @@ -122,6 +122,7 @@ void CDDM_recalc_tessellation_ex(struct DerivedMesh *dm, const int do_face_nor_c */ void CDDM_lower_num_verts(struct DerivedMesh *dm, int numVerts); void CDDM_lower_num_edges(struct DerivedMesh *dm, int numEdges); +void CDDM_lower_num_loops(struct DerivedMesh *dm, int numLoops); void CDDM_lower_num_polys(struct DerivedMesh *dm, int numPolys); void CDDM_lower_num_tessfaces(DerivedMesh *dm, int numTessFaces); diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h index 07116979eab..dee27cebf59 100644 --- a/source/blender/blenkernel/BKE_curve.h +++ b/source/blender/blenkernel/BKE_curve.h @@ -119,6 +119,7 @@ void BKE_nurbList_flag_set(ListBase *editnurb, short flag); void BKE_nurb_free(struct Nurb *nu); struct Nurb *BKE_nurb_duplicate(struct Nurb *nu); +struct Nurb *BKE_nurb_copy(struct Nurb *src, int pntsu, int pntsv); void BKE_nurb_test2D(struct Nurb *nu); void BKE_nurb_minmax(struct Nurb *nu, float min[3], float max[3]); diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index 5a283922707..f28d16427cf 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -147,14 +147,14 @@ void *CustomData_add_layer_named(struct CustomData *data, int type, int alloctyp void *layer, int totelem, const char *name); /* frees the active or first data layer with the give type. - * returns 1 on succes, 0 if no layer with the given type is found + * returns 1 on success, 0 if no layer with the given type is found * * in editmode, use EDBM_data_layer_free instead of this function */ bool CustomData_free_layer(struct CustomData *data, int type, int totelem, int index); /* frees the layer index with the give type. - * returns 1 on succes, 0 if no layer with the given type is found + * returns 1 on success, 0 if no layer with the given type is found * * in editmode, use EDBM_data_layer_free instead of this function */ diff --git a/source/blender/blenkernel/BKE_deform.h b/source/blender/blenkernel/BKE_deform.h index 435cad17e57..e203549fef5 100644 --- a/source/blender/blenkernel/BKE_deform.h +++ b/source/blender/blenkernel/BKE_deform.h @@ -91,6 +91,7 @@ void defvert_normalize_lock_map(struct MDeformVert *dvert, void BKE_deform_split_suffix(const char string[MAX_VGROUP_NAME], char base[MAX_VGROUP_NAME], char ext[MAX_VGROUP_NAME]); void BKE_deform_split_prefix(const char string[MAX_VGROUP_NAME], char base[MAX_VGROUP_NAME], char ext[MAX_VGROUP_NAME]); -void flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_NAME], int strip_number); +void BKE_deform_flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_NAME], + const bool strip_number); #endif /* __BKE_DEFORM_H__ */ diff --git a/source/blender/blenkernel/BKE_editmesh.h b/source/blender/blenkernel/BKE_editmesh.h index 738cd87dc39..310807370da 100644 --- a/source/blender/blenkernel/BKE_editmesh.h +++ b/source/blender/blenkernel/BKE_editmesh.h @@ -71,13 +71,6 @@ typedef struct BMEditMesh { unsigned char (*derivedFaceColor)[4]; int derivedFaceColorLen; - /* index tables, to map indices to elements via - * EDBM_index_arrays_init and associated functions. don't - * touch this or read it directly.*/ - struct BMVert **vert_index; - struct BMEdge **edge_index; - struct BMFace **face_index; - /*selection mode*/ short selectmode; short mat_nr; diff --git a/source/blender/blenkernel/BKE_editmesh_bvh.h b/source/blender/blenkernel/BKE_editmesh_bvh.h index 7b4ad4284c6..aeac00b06c1 100644 --- a/source/blender/blenkernel/BKE_editmesh_bvh.h +++ b/source/blender/blenkernel/BKE_editmesh_bvh.h @@ -33,15 +33,19 @@ #define __BKE_EDITMESH_BVH_H__ struct BMEditMesh; +struct BMesh; struct BMFace; struct BMVert; +struct BMLoop; struct BMBVHTree; struct BVHTree; struct Scene; typedef struct BMBVHTree BMBVHTree; -BMBVHTree *BKE_bmbvh_new(struct BMEditMesh *em, int flag, const float (*cos_cage)[3], const bool cos_cage_free); +BMBVHTree *BKE_bmbvh_new_from_editmesh(struct BMEditMesh *em, int flag, const float (*cos_cage)[3], const bool cos_cage_free); +BMBVHTree *BKE_bmbvh_new(struct BMesh *bm, struct BMLoop *(*looptris)[3], int looptris_tot, int flag, + const float (*cos_cage)[3], const bool cos_cage_free); void BKE_bmbvh_free(BMBVHTree *tree); struct BVHTree *BKE_bmbvh_tree_get(BMBVHTree *tree); struct BMFace *BKE_bmbvh_ray_cast(BMBVHTree *tree, const float co[3], const float dir[3], const float radius, diff --git a/source/blender/blenkernel/BKE_font.h b/source/blender/blenkernel/BKE_font.h index 028ff0f93d6..8f5ccf1087e 100644 --- a/source/blender/blenkernel/BKE_font.h +++ b/source/blender/blenkernel/BKE_font.h @@ -63,8 +63,6 @@ typedef struct EditFont { wchar_t *textbuf; struct CharInfo *textbufinfo; - wchar_t *oldstr; - struct CharInfo *oldstrinfo; float textcurs[4][2]; diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h index 9d33af1a0f4..d0341ab8c89 100644 --- a/source/blender/blenkernel/BKE_global.h +++ b/source/blender/blenkernel/BKE_global.h @@ -192,6 +192,7 @@ enum { #define G_TRANSFORM_OBJ 1 #define G_TRANSFORM_EDIT 2 #define G_TRANSFORM_SEQ 4 +#define G_TRANSFORM_FCURVES 8 /* G.special1 */ diff --git a/source/blender/blenkernel/BKE_idprop.h b/source/blender/blenkernel/BKE_idprop.h index 71fd163a8ee..bd90960eced 100644 --- a/source/blender/blenkernel/BKE_idprop.h +++ b/source/blender/blenkernel/BKE_idprop.h @@ -94,7 +94,8 @@ void IDP_MergeGroup(IDProperty *dest, IDProperty *src, const int do_overwrite) A int IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL(); int IDP_InsertToGroup(struct IDProperty *group, struct IDProperty *previous, struct IDProperty *pnew) ATTR_NONNULL(1 /* group */, 3 /* pnew */); -void IDP_RemFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL(); +void IDP_RemoveFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL(); +void IDP_FreeFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL(); IDProperty *IDP_GetPropertyFromGroup(struct IDProperty *prop, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); IDProperty *IDP_GetPropertyTypeFromGroup(struct IDProperty *prop, const char *name, const char type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h index 264a7421e91..7b7b69034a9 100644 --- a/source/blender/blenkernel/BKE_main.h +++ b/source/blender/blenkernel/BKE_main.h @@ -53,7 +53,8 @@ typedef struct Main { char name[1024]; /* 1024 = FILE_MAX */ short versionfile, subversionfile; /* see BLENDER_VERSION, BLENDER_SUBVERSION */ short minversionfile, minsubversionfile; - int revision; /* svn revision of binary that saved file */ + uint64_t build_commit_timestamp; /* commit's timestamp from buildinfo */ + char build_hash[16]; /* hash from buildinfo */ short recovered; /* indicate the main->name (file) is the recovered one */ struct Library *curlib; diff --git a/source/blender/blenkernel/BKE_mask.h b/source/blender/blenkernel/BKE_mask.h index 9e73e0662ce..d73249041e8 100644 --- a/source/blender/blenkernel/BKE_mask.h +++ b/source/blender/blenkernel/BKE_mask.h @@ -90,7 +90,7 @@ float BKE_mask_spline_project_co(struct MaskSpline *spline, struct MaskSplinePoi /* point */ int BKE_mask_point_has_handle(struct MaskSplinePoint *point); void BKE_mask_point_handle(struct MaskSplinePoint *point, float handle[2]); -void BKE_mask_point_set_handle(struct MaskSplinePoint *point, float loc[2], int keep_direction, +void BKE_mask_point_set_handle(struct MaskSplinePoint *point, float loc[2], bool keep_direction, float orig_handle[2], float orig_vec[3][3]); void BKE_mask_point_segment_co(struct MaskSpline *spline, struct MaskSplinePoint *point, float u, float co[2]); @@ -123,9 +123,9 @@ void BKE_mask_coord_to_image(struct Image *image, struct ImageUser *iuser, float void BKE_mask_update_display(struct Mask *mask, float ctime); -void BKE_mask_evaluate_all_masks(struct Main *bmain, float ctime, const int do_newframe); -void BKE_mask_evaluate(struct Mask *mask, const float ctime, const int do_newframe); -void BKE_mask_layer_evaluate(struct MaskLayer *masklay, const float ctime, const int do_newframe); +void BKE_mask_evaluate_all_masks(struct Main *bmain, float ctime, const bool do_newframe); +void BKE_mask_evaluate(struct Mask *mask, const float ctime, const bool do_newframe); +void BKE_mask_layer_evaluate(struct MaskLayer *masklay, const float ctime, const bool do_newframe); void BKE_mask_update_scene(struct Main *bmain, struct Scene *scene); void BKE_mask_parent_init(struct MaskParent *parent); void BKE_mask_calc_handle_adjacent_interp(struct MaskSpline *spline, struct MaskSplinePoint *point, const float u); @@ -156,17 +156,18 @@ int BKE_mask_layer_shape_find_frame_range(struct MaskLayer *masklay, const float struct MaskLayerShape **r_masklay_shape_b); struct MaskLayerShape *BKE_mask_layer_shape_alloc(struct MaskLayer *masklay, const int frame); void BKE_mask_layer_shape_free(struct MaskLayerShape *masklay_shape); -struct MaskLayerShape *BKE_mask_layer_shape_varify_frame(struct MaskLayer *masklay, const int frame); +struct MaskLayerShape *BKE_mask_layer_shape_verify_frame(struct MaskLayer *masklay, const int frame); struct MaskLayerShape *BKE_mask_layer_shape_duplicate(struct MaskLayerShape *masklay_shape); void BKE_mask_layer_shape_unlink(struct MaskLayer *masklay, struct MaskLayerShape *masklay_shape); void BKE_mask_layer_shape_sort(struct MaskLayer *masklay); -int BKE_mask_layer_shape_spline_from_index(struct MaskLayer *masklay, int index, +bool 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); +/* TODO(sergey): do_init and do_init_interpolate are always true, so let's wipe them later. */ void BKE_mask_layer_shape_changed_add(struct MaskLayer *masklay, int index, - int do_init, int do_init_interpolate); + bool do_init, bool do_init_interpolate); void BKE_mask_layer_shape_changed_remove(struct MaskLayer *masklay, int index, int count); diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h index 6bf42a3e885..65038c7f09c 100644 --- a/source/blender/blenkernel/BKE_modifier.h +++ b/source/blender/blenkernel/BKE_modifier.h @@ -357,6 +357,7 @@ bool modifiers_usesArmature(struct Object *ob, struct bArmature *arm); bool modifiers_isCorrectableDeformed(struct Scene *scene, struct Object *ob); void modifier_freeTemporaryData(struct ModifierData *md); bool modifiers_isPreview(struct Object *ob); +void modifier_skin_customdata_ensure(struct Object *ob); typedef struct CDMaskLink { struct CDMaskLink *next; diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 7cc8c7290f7..b700cbb16db 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -132,7 +132,7 @@ typedef struct bNodeSocketType { } bNodeSocketType; typedef void *(*NodeInitExecFunction)(struct bNodeExecContext *context, struct bNode *node, bNodeInstanceKey key); -typedef void (*NodeFreeExecFunction)(struct bNode *node, void *nodedata); +typedef void (*NodeFreeExecFunction)(void *nodedata); typedef void (*NodeExecFunction)(void *data, int thread, struct bNode *, struct bNodeExecData *execdata, struct bNodeStack **in, struct bNodeStack **out); typedef int (*NodeGPUExecFunction)(struct GPUMaterial *mat, struct bNode *node, struct bNodeExecData *execdata, struct GPUNodeStack *in, struct GPUNodeStack *out); @@ -175,7 +175,7 @@ typedef struct bNodeType { void (*draw_backdrop)(struct SpaceNode *snode, struct ImBuf *backdrop, struct bNode *node, int x, int y); /// Optional custom label function for the node header. - const char *(*labelfunc)(struct bNode *); + void (*labelfunc)(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen); /// Optional custom resize handle polling. int (*resize_area_func)(struct bNode *node, int x, int y); /// Optional selection area polling. @@ -556,7 +556,7 @@ void BKE_node_preview_set_pixel(struct bNodePreview *preview, const f /* ************** NODE TYPE ACCESS *************** */ -const char *nodeLabel(struct bNode *node); +void nodeLabel(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen); int nodeGroupPoll(struct bNodeTree *nodetree, struct bNodeTree *grouptree); @@ -571,7 +571,7 @@ void node_type_storage(struct bNodeType *ntype, const char *storagename, void (*freefunc)(struct bNode *node), void (*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, struct bNode *src_node)); -void node_type_label(struct bNodeType *ntype, const char *(*labelfunc)(struct bNode *)); +void node_type_label(struct bNodeType *ntype, void (*labelfunc)(struct bNodeTree *ntree, struct bNode *, char *label, int maxlen)); void node_type_update(struct bNodeType *ntype, void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node), void (*verifyfunc)(struct bNodeTree *ntree, struct bNode *node, struct ID *id)); @@ -944,6 +944,9 @@ void ntreeCompositOutputFileSetLayer(struct bNode *node, struct bNodeSocket *soc void ntreeCompositOutputFileUniquePath(struct ListBase *list, struct bNodeSocket *sock, const char defname[], char delim); void ntreeCompositOutputFileUniqueLayer(struct ListBase *list, struct bNodeSocket *sock, const char defname[], char delim); +void ntreeCompositColorBalanceSyncFromLGG(bNodeTree *ntree, bNode *node); +void ntreeCompositColorBalanceSyncFromCDL(bNodeTree *ntree, bNode *node); + /* ************** TEXTURE NODES *************** */ struct TexResult; diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index e99eb2a64f2..434175624b7 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -48,6 +48,7 @@ struct rctf; struct MovieClip; struct Main; struct RigidBodyWorld; +struct HookModifierData; void BKE_object_workob_clear(struct Object *workob); void BKE_object_workob_calc_parent(struct Scene *scene, struct Object *ob, struct Object *workob); @@ -66,6 +67,8 @@ void BKE_object_update_base_layer(struct Scene *scene, struct Object *ob); void BKE_object_free(struct Object *ob); void BKE_object_free_derived_caches(struct Object *ob); +void BKE_object_modifier_hook_reset(struct Object *ob, struct HookModifierData *hmd); + bool BKE_object_support_modifier_type_check(struct Object *ob, int modifier_type); void BKE_object_link_modifiers(struct Object *ob, struct Object *from); diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h index 9e21831dba0..f8c21a1fa16 100644 --- a/source/blender/blenkernel/BKE_pbvh.h +++ b/source/blender/blenkernel/BKE_pbvh.h @@ -151,8 +151,9 @@ typedef enum { void BKE_pbvh_node_mark_update(PBVHNode *node); void BKE_pbvh_node_mark_rebuild_draw(PBVHNode *node); -void BKE_pbvh_node_fully_hidden_set(PBVHNode *node, int fully_hidden); +void BKE_pbvh_node_mark_redraw(PBVHNode *node); void BKE_pbvh_node_mark_topology_update(PBVHNode *node); +void BKE_pbvh_node_fully_hidden_set(PBVHNode *node, int fully_hidden); void BKE_pbvh_node_get_grids(PBVH *bvh, PBVHNode *node, int **grid_indices, int *totgrid, int *maxgrid, int *gridsize, diff --git a/source/blender/blenkernel/BKE_rigidbody.h b/source/blender/blenkernel/BKE_rigidbody.h index 929d9686328..86be3bfe770 100644 --- a/source/blender/blenkernel/BKE_rigidbody.h +++ b/source/blender/blenkernel/BKE_rigidbody.h @@ -57,7 +57,7 @@ void BKE_rigidbody_relink_constraint(struct RigidBodyCon *rbc); /* -------------- */ /* Setup */ -/* create Blender-side settings data - physics objects not initialised yet */ +/* create Blender-side settings data - physics objects not initialized yet */ struct RigidBodyWorld *BKE_rigidbody_create_world(struct Scene *scene); struct RigidBodyOb *BKE_rigidbody_create_object(struct Scene *scene, struct Object *ob, short type); struct RigidBodyCon *BKE_rigidbody_create_constraint(struct Scene *scene, struct Object *ob, short type); diff --git a/source/blender/blenkernel/BKE_texture.h b/source/blender/blenkernel/BKE_texture.h index 2a00dee2a3f..e9e351f8f37 100644 --- a/source/blender/blenkernel/BKE_texture.h +++ b/source/blender/blenkernel/BKE_texture.h @@ -52,6 +52,7 @@ struct ParticleSettings; struct PointDensity; struct Tex; struct TexMapping; +struct TexResult; struct VoxelData; struct World; @@ -129,6 +130,8 @@ struct OceanTex *BKE_copy_oceantex(struct OceanTex *ot); bool BKE_texture_dependsOnTime(const struct Tex *texture); +void BKE_texture_get_value(struct Scene *scene, struct Tex *texture, float *tex_co, struct TexResult *texres, bool use_color_management); + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/BKE_tracking.h b/source/blender/blenkernel/BKE_tracking.h index 51f97180ddb..94e530529ec 100644 --- a/source/blender/blenkernel/BKE_tracking.h +++ b/source/blender/blenkernel/BKE_tracking.h @@ -225,7 +225,7 @@ void BKE_tracking_homography_between_two_quads(/*const*/ float reference_corners bool BKE_tracking_reconstruction_check(struct MovieTracking *tracking, struct MovieTrackingObject *object, char *error_msg, int error_size); -struct MovieReconstructContext *BKE_tracking_reconstruction_context_new(struct MovieTracking *tracking, +struct MovieReconstructContext *BKE_tracking_reconstruction_context_new(struct MovieClip *clip, struct MovieTrackingObject *object, int keyframe1, int keyframe2, int width, int height); diff --git a/source/blender/blenkernel/BKE_writeffmpeg.h b/source/blender/blenkernel/BKE_writeffmpeg.h index 8a11d48d063..347c8b60532 100644 --- a/source/blender/blenkernel/BKE_writeffmpeg.h +++ b/source/blender/blenkernel/BKE_writeffmpeg.h @@ -38,31 +38,34 @@ extern "C" { #endif -#define FFMPEG_MPEG1 0 -#define FFMPEG_MPEG2 1 -#define FFMPEG_MPEG4 2 -#define FFMPEG_AVI 3 -#define FFMPEG_MOV 4 -#define FFMPEG_DV 5 -#define FFMPEG_H264 6 -#define FFMPEG_XVID 7 -#define FFMPEG_FLV 8 -#define FFMPEG_MKV 9 -#define FFMPEG_OGG 10 -#define FFMPEG_WAV 11 -#define FFMPEG_MP3 12 +enum { + FFMPEG_MPEG1 = 0, + FFMPEG_MPEG2 = 1, + FFMPEG_MPEG4 = 2, + FFMPEG_AVI = 3, + FFMPEG_MOV = 4, + FFMPEG_DV = 5, + FFMPEG_H264 = 6, + FFMPEG_XVID = 7, + FFMPEG_FLV = 8, + FFMPEG_MKV = 9, + FFMPEG_OGG = 10, + FFMPEG_INVALID = 11, +}; -#define FFMPEG_PRESET_NONE 0 -#define FFMPEG_PRESET_DVD 1 -#define FFMPEG_PRESET_SVCD 2 -#define FFMPEG_PRESET_VCD 3 -#define FFMPEG_PRESET_DV 4 -#define FFMPEG_PRESET_H264 5 -#define FFMPEG_PRESET_THEORA 6 -#define FFMPEG_PRESET_XVID 7 +enum { + FFMPEG_PRESET_NONE = 0, + FFMPEG_PRESET_DVD = 1, + FFMPEG_PRESET_SVCD = 2, + FFMPEG_PRESET_VCD = 3, + FFMPEG_PRESET_DV = 4, + FFMPEG_PRESET_H264 = 5, + FFMPEG_PRESET_THEORA = 6, + FFMPEG_PRESET_XVID = 7, +}; struct IDProperty; -struct RenderData; +struct RenderData; struct ReportList; struct Scene; diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 368c1e517ef..731196c2480 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1259,7 +1259,7 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag, } if (dm->type == DM_TYPE_EDITBMESH) { - /* editmesh draw function checks spesifically for this */ + /* editmesh draw function checks specifically for this */ } else { const int dm_totpoly = dm->getNumPolys(dm); @@ -2859,14 +2859,19 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, else layer = CustomData_get_active_layer_index(ldata, CD_MLOOPUV); - if (layer != -1) { - a = attribs->tottface++; + a = attribs->tottface++; + if (layer != -1) { attribs->tface[a].array = tfdata->layers[layer].data; attribs->tface[a].em_offset = ldata->layers[layer].offset; - attribs->tface[a].gl_index = gattribs->layer[b].glindex; - attribs->tface[a].gl_texco = gattribs->layer[b].gltexco; } + else { + attribs->tface[a].array = NULL; + attribs->tface[a].em_offset = -1; + } + + attribs->tface[a].gl_index = gattribs->layer[b].glindex; + attribs->tface[a].gl_texco = gattribs->layer[b].gltexco; } else { if (gattribs->layer[b].name[0]) @@ -2875,14 +2880,19 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, else layer = CustomData_get_active_layer_index(tfdata, CD_MTFACE); - if (layer != -1) { - a = attribs->tottface++; + a = attribs->tottface++; + if (layer != -1) { attribs->tface[a].array = tfdata->layers[layer].data; attribs->tface[a].em_offset = tfdata->layers[layer].offset; - attribs->tface[a].gl_index = gattribs->layer[b].glindex; - attribs->tface[a].gl_texco = gattribs->layer[b].gltexco; } + else { + attribs->tface[a].array = NULL; + attribs->tface[a].em_offset = -1; + } + + attribs->tface[a].gl_index = gattribs->layer[b].glindex; + attribs->tface[a].gl_texco = gattribs->layer[b].gltexco; } } else if (gattribs->layer[b].type == CD_MCOL) { @@ -2896,14 +2906,19 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, else layer = CustomData_get_active_layer_index(ldata, CD_MLOOPCOL); - if (layer != -1) { - a = attribs->totmcol++; + a = attribs->totmcol++; + if (layer != -1) { attribs->mcol[a].array = tfdata->layers[layer].data; /* odd, store the offset for a different layer type here, but editmode draw code expects it */ attribs->mcol[a].em_offset = ldata->layers[layer].offset; - attribs->mcol[a].gl_index = gattribs->layer[b].glindex; } + else { + attribs->mcol[a].array = NULL; + attribs->mcol[a].em_offset = -1; + } + + attribs->mcol[a].gl_index = gattribs->layer[b].glindex; } else { /* vertex colors */ @@ -2913,40 +2928,54 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, else layer = CustomData_get_active_layer_index(tfdata, CD_MCOL); - if (layer != -1) { - a = attribs->totmcol++; + a = attribs->totmcol++; + if (layer != -1) { attribs->mcol[a].array = tfdata->layers[layer].data; /* odd, store the offset for a different layer type here, but editmode draw code expects it */ attribs->mcol[a].em_offset = tfdata->layers[layer].offset; - attribs->mcol[a].gl_index = gattribs->layer[b].glindex; } + else { + attribs->mcol[a].array = NULL; + attribs->mcol[a].em_offset = -1; + } + + attribs->mcol[a].gl_index = gattribs->layer[b].glindex; } } else if (gattribs->layer[b].type == CD_TANGENT) { /* tangents */ layer = CustomData_get_layer_index(fdata, CD_TANGENT); - if (layer != -1) { - attribs->tottang = 1; + attribs->tottang = 1; + if (layer != -1) { attribs->tang.array = fdata->layers[layer].data; attribs->tang.em_offset = fdata->layers[layer].offset; - attribs->tang.gl_index = gattribs->layer[b].glindex; } + else { + attribs->tang.array = NULL; + attribs->tang.em_offset = -1; + } + + attribs->tang.gl_index = gattribs->layer[b].glindex; } else if (gattribs->layer[b].type == CD_ORCO) { /* original coordinates */ layer = CustomData_get_layer_index(vdata, CD_ORCO); + attribs->totorco = 1; if (layer != -1) { - attribs->totorco = 1; - attribs->orco.array = vdata->layers[layer].data; attribs->orco.em_offset = vdata->layers[layer].offset; - attribs->orco.gl_index = gattribs->layer[b].glindex; - attribs->orco.gl_texco = gattribs->layer[b].gltexco; } + else { + attribs->orco.array = NULL; + attribs->orco.em_offset = -1; + } + + attribs->orco.gl_index = gattribs->layer[b].glindex; + attribs->orco.gl_texco = gattribs->layer[b].gltexco; } } } diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index b0644da4598..c91fae2adbc 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -53,6 +53,7 @@ #include "BKE_anim.h" #include "BKE_animsys.h" #include "BKE_constraint.h" +#include "BKE_deform.h" #include "BKE_fcurve.h" #include "BKE_global.h" #include "BKE_idprop.h" @@ -440,6 +441,10 @@ void action_groups_clear_tempflags(bAction *act) /* *************** Pose channels *************** */ +/** + * Return a pointer to the pose channel of the given name + * from this pose. + */ bPoseChannel *BKE_pose_channel_find_name(const bPose *pose, const char *name) { if (ELEM(NULL, pose, name) || (name[0] == '\0')) @@ -451,8 +456,14 @@ bPoseChannel *BKE_pose_channel_find_name(const bPose *pose, const char *name) return BLI_findstring(&((bPose *)pose)->chanbase, name, offsetof(bPoseChannel, name)); } -/* Use with care, not on Armature poses but for temporal ones */ -/* (currently used for action constraints and in rebuild_pose) */ +/** + * Looks to see if the channel with the given name + * already exists in this pose - if not a new one is + * allocated and initialized. + * + * \note Use with care, not on Armature poses but for temporal ones. + * \note (currently used for action constraints and in rebuild_pose). + */ bPoseChannel *BKE_pose_channel_verify(bPose *pose, const char *name) { bPoseChannel *chan; @@ -505,7 +516,12 @@ bool BKE_pose_channels_is_valid(const bPose *pose) } #endif -/* Find the active posechannel for an object (we can't just use pose, as layer info is in armature) */ + +/** + * Find the active posechannel for an object (we can't just use pose, as layer info is in armature) + * + * \note: Object, not bPose is used here, as we need layer info from Armature) + */ bPoseChannel *BKE_pose_channel_active(Object *ob) { bArmature *arm = (ob) ? ob->data : NULL; @@ -524,6 +540,22 @@ bPoseChannel *BKE_pose_channel_active(Object *ob) return NULL; } +/** + * \see #ED_armature_bone_get_mirrored (edit-mode, matching function) + */ +bPoseChannel *BKE_pose_channel_get_mirrored(const bPose *pose, const char *name) +{ + char name_flip[MAXBONENAME]; + + BKE_deform_flip_side_name(name_flip, name, false); + + if (!STREQ(name_flip, name)) { + return BKE_pose_channel_find_name(pose, name_flip); + } + + return NULL; +} + const char *BKE_pose_ikparam_get_name(bPose *pose) { if (pose) { @@ -536,8 +568,14 @@ const char *BKE_pose_ikparam_get_name(bPose *pose) } return NULL; } -/* dst should be freed already, makes entire duplicate */ -void BKE_pose_copy_data(bPose **dst, bPose *src, int copycon) + +/** + * Allocate a new pose on the heap, and copy the src pose and it's channels + * into the new pose. *dst is set to the newly allocated structure, and assumed to be NULL. + * + * \param dst Should be freed already, makes entire duplicate. + */ +void BKE_pose_copy_data(bPose **dst, bPose *src, const bool copy_constraints) { bPose *outPose; bPoseChannel *pchan; @@ -551,15 +589,22 @@ void BKE_pose_copy_data(bPose **dst, bPose *src, int copycon) outPose = MEM_callocN(sizeof(bPose), "pose"); BLI_duplicatelist(&outPose->chanbase, &src->chanbase); - + if (outPose->chanbase.first) { + bPoseChannel *pchan; + for (pchan = outPose->chanbase.first; pchan; pchan = pchan->next) { + if (pchan->custom) { + id_us_plus(&pchan->custom->id); + } + } + } + outPose->iksolver = src->iksolver; outPose->ikdata = NULL; outPose->ikparam = MEM_dupallocN(src->ikparam); outPose->avs = src->avs; for (pchan = outPose->chanbase.first; pchan; pchan = pchan->next) { - /* TODO: rename this argument... */ - if (copycon) { + if (copy_constraints) { BKE_copy_constraints(&listb, &pchan->constraints, TRUE); // BKE_copy_constraints NULLs listb pchan->constraints = listb; pchan->mpath = NULL; /* motion paths should not get copied yet... */ @@ -571,8 +616,9 @@ void BKE_pose_copy_data(bPose **dst, bPose *src, int copycon) } /* for now, duplicate Bone Groups too when doing this */ - if (copycon) + if (copy_constraints) { BLI_duplicatelist(&outPose->agroups, &src->agroups); + } *dst = outPose; } @@ -641,7 +687,10 @@ bool BKE_pose_channel_in_IK_chain(Object *ob, bPoseChannel *pchan) return pose_channel_in_IK_chain(ob, pchan, 0); } - +/** + * Removes the hash for quick lookup of channels, must + * be done when adding/removing channels. + */ void BKE_pose_channels_hash_make(bPose *pose) { if (!pose->chanhash) { @@ -661,6 +710,10 @@ void BKE_pose_channels_hash_free(bPose *pose) } } +/** + * Deallocates a pose channel. + * Does not free the pose channel itself. + */ void BKE_pose_channel_free(bPoseChannel *pchan) { if (pchan->custom) { @@ -681,6 +734,10 @@ void BKE_pose_channel_free(bPoseChannel *pchan) } } +/** + * Removes and deallocates all channels from a pose. + * Does not free the pose itself. + */ void BKE_pose_channels_free(bPose *pose) { bPoseChannel *pchan; @@ -695,6 +752,9 @@ void BKE_pose_channels_free(bPose *pose) BKE_pose_channels_hash_free(pose); } +/** + * Removes and deallocates all data from a pose, and also frees the pose. + */ void BKE_pose_free(bPose *pose) { if (pose) { @@ -739,9 +799,13 @@ static void copy_pose_channel_data(bPoseChannel *pchan, const bPoseChannel *chan } } -/* makes copies of internal data, unlike copy_pose_channel_data which only - * copies the pose state. - * hint: use when copying bones in editmode (on returned value from BKE_pose_channel_verify) */ +/** + * Copy the internal members of each pose channel including constraints + * and ID-Props, used when duplicating bones in editmode. + * (unlike copy_pose_channel_data which only). + * + * \note use when copying bones in editmode (on returned value from #BKE_pose_channel_verify) + */ void BKE_pose_channel_copy_data(bPoseChannel *pchan, const bPoseChannel *pchan_from) { /* copy transform locks */ diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index 225be335c6d..9226538910c 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -285,7 +285,7 @@ void animviz_get_object_motionpaths(Object *ob, ListBase *targets) /* ........ */ /* Note on evaluation optimizations: - * Optimisations currently used here play tricks with the depsgraph in order to try and + * Optimization's currently used here play tricks with the depsgraph in order to try and * evaluate as few objects as strictly necessary to get nicer performance under standard * production conditions. For those people who really need the accurate version, * disable the ifdef (i.e. 1 -> 0) and comment out the call to motionpaths_calc_optimise_depsgraph() diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 74578266c63..cb628db8cd2 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -711,6 +711,49 @@ static void nlastrips_path_rename_fix(ID *owner_id, const char *prefix, const ch } } +/* Fix all RNA_Paths in the given Action, relative to the given ID block + * + * This is just an external wrapper for the F-Curve fixing function, + * with input validity checks on top of the basic method. + * + * NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]> + * i.e. pose.bones["Bone"] + */ +void BKE_action_fix_paths_rename(ID *owner_id, bAction *act, const char *prefix, const char *oldName, + const char *newName, int oldSubscript, int newSubscript, int verify_paths) +{ + char *oldN, *newN; + + /* if no action, no need to proceed */ + if (ELEM(NULL, owner_id, act)) + return; + + /* Name sanitation logic - copied from BKE_animdata_fix_paths_rename() */ + if ((oldName != NULL) && (newName != NULL)) { + /* pad the names with [" "] so that only exact matches are made */ + const size_t name_old_len = strlen(oldName); + const size_t name_new_len = strlen(newName); + char *name_old_esc = BLI_array_alloca(name_old_esc, (name_old_len * 2) + 1); + char *name_new_esc = BLI_array_alloca(name_new_esc, (name_new_len * 2) + 1); + + BLI_strescape(name_old_esc, oldName, (name_old_len * 2) + 1); + BLI_strescape(name_new_esc, newName, (name_new_len * 2) + 1); + oldN = BLI_sprintfN("[\"%s\"]", name_old_esc); + newN = BLI_sprintfN("[\"%s\"]", name_new_esc); + } + else { + oldN = BLI_sprintfN("[%d]", oldSubscript); + newN = BLI_sprintfN("[%d]", newSubscript); + } + + /* fix paths in action */ + fcurves_path_rename_fix(owner_id, prefix, oldName, newName, oldN, newN, &act->curves, verify_paths); + + /* free the temp names */ + MEM_freeN(oldN); + MEM_freeN(newN); +} + /* Fix all RNA-Paths in the AnimData block used by the given ID block * NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]> * i.e. pose.bones["Bone"] @@ -725,6 +768,7 @@ void BKE_animdata_fix_paths_rename(ID *owner_id, AnimData *adt, ID *ref_id, cons if (ELEM(NULL, owner_id, adt)) return; + /* Name sanitation logic - shared with BKE_action_fix_paths_rename() */ if ((oldName != NULL) && (newName != NULL)) { /* pad the names with [" "] so that only exact matches are made */ const size_t name_old_len = strlen(oldName); @@ -1523,11 +1567,11 @@ static float nlastrip_get_influence(NlaStrip *strip, float cframe) strip->blendout = fabsf(strip->blendout); /* result depends on where frame is in respect to blendin/out values */ - if (IS_EQ(strip->blendin, 0) == 0 && (cframe <= (strip->start + strip->blendin))) { + if (IS_EQF(strip->blendin, 0.0f) == false && (cframe <= (strip->start + strip->blendin))) { /* there is some blend-in */ return fabsf(cframe - strip->start) / (strip->blendin); } - else if (IS_EQ(strip->blendout, 0) == 0 && (cframe >= (strip->end - strip->blendout))) { + else if (IS_EQF(strip->blendout, 0.0f) == false && (cframe >= (strip->end - strip->blendout))) { /* there is some blend-out */ return fabsf(strip->end - cframe) / (strip->blendout); } @@ -1812,7 +1856,7 @@ static void nlaevalchan_accumulate(NlaEvalChannel *nec, NlaEvalStrip *nes, float inf *= nes->strip_time; /* optimisation: no need to try applying if there is no influence */ - if (IS_EQ(inf, 0)) return; + if (IS_EQF(inf, 0.0f)) return; /* perform blending */ switch (blendmode) { @@ -2030,7 +2074,7 @@ static void nlastrip_evaluate_transition(PointerRNA *ptr, ListBase *channels, Li tmp_nes = *nes; /* evaluate these strips into a temp-buffer (tmp_channels) */ - /* FIXME: modifier evalation here needs some work... */ + /* FIXME: modifier evaluation here needs some work... */ /* first strip */ tmp_nes.strip_mode = NES_TIME_TRANSITION_START; tmp_nes.strip = s1; @@ -2042,7 +2086,7 @@ static void nlastrip_evaluate_transition(PointerRNA *ptr, ListBase *channels, Li nlastrip_evaluate(ptr, &tmp_channels, &tmp_modifiers, &tmp_nes); - /* assumulate temp-buffer and full-buffer, using the 'real' strip */ + /* accumulate temp-buffer and full-buffer, using the 'real' strip */ nlaevalchan_buffers_accumulate(channels, &tmp_channels, nes); /* unlink this strip's modifiers from the parent's modifiers again */ @@ -2080,7 +2124,7 @@ static void nlastrip_evaluate_meta(PointerRNA *ptr, ListBase *channels, ListBase */ nlastrip_evaluate(ptr, &tmp_channels, &tmp_modifiers, tmp_nes); - /* assumulate temp-buffer and full-buffer, using the 'real' strip */ + /* accumulate temp-buffer and full-buffer, using the 'real' strip */ nlaevalchan_buffers_accumulate(channels, &tmp_channels, nes); /* free temp eval-strip */ @@ -2290,7 +2334,7 @@ static void animsys_calculate_nla(PointerRNA *ptr, AnimData *adt, float ctime) /* ***************************************** */ /* Overrides System - Public API */ -/* Clear all overides */ +/* Clear all overrides */ /* Add or get existing Override for given setting */ #if 0 diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 6b2b782717d..3be80a7e30d 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -285,7 +285,7 @@ int bone_autoside_name(char name[MAXBONENAME], int UNUSED(strip_number), short a */ if (axis == 2) { /* z-axis - vertical (top/bottom) */ - if (IS_EQ(head, 0)) { + if (IS_EQF(head, 0.0f)) { if (tail < 0) strcpy(extension, "Bot"); else if (tail > 0) @@ -300,7 +300,7 @@ int bone_autoside_name(char name[MAXBONENAME], int UNUSED(strip_number), short a } else if (axis == 1) { /* y-axis - depth (front/back) */ - if (IS_EQ(head, 0)) { + if (IS_EQF(head, 0.0f)) { if (tail < 0) strcpy(extension, "Fr"); else if (tail > 0) @@ -315,7 +315,7 @@ int bone_autoside_name(char name[MAXBONENAME], int UNUSED(strip_number), short a } else { /* x-axis - horizontal (left/right) */ - if (IS_EQ(head, 0)) { + if (IS_EQF(head, 0.0f)) { if (tail < 0) strcpy(extension, "R"); else if (tail > 0) @@ -405,7 +405,7 @@ static void equalize_bezier(float *data, int desired) dist = ((float)a) * ddist; /* we're looking for location (distance) 'dist' in the array */ - while ((dist >= pdist[nr]) && nr < MAX_BBONE_SUBDIV) + while ((nr < MAX_BBONE_SUBDIV) && (dist >= pdist[nr])) nr++; fac1 = pdist[nr] - pdist[nr - 1]; diff --git a/source/blender/blenkernel/intern/bmfont.c b/source/blender/blenkernel/intern/bmfont.c index 2d7249b54f5..732c0c35feb 100644 --- a/source/blender/blenkernel/intern/bmfont.c +++ b/source/blender/blenkernel/intern/bmfont.c @@ -204,7 +204,7 @@ void detectBitmapFont(ImBuf *ibuf) printf("detectBitmapFont :Unsupported version %d\n", (int)version); } - /* on succes ibuf->userdata points to the bitmapfont */ + /* on success ibuf->userdata points to the bitmapfont */ if (ibuf->userdata) { break; } diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 790c1f09ff0..33c6f3eb7c0 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -762,7 +762,7 @@ float BKE_brush_sample_masktex(const Scene *scene, Brush *br, * radius become inconsistent. * the biggest problem is that it isn't possible to change * unprojected radius because a view context is not - * available. my ussual solution to this is to use the + * available. my usual solution to this is to use the * ratio of change of the size to change the unprojected * radius. Not completely convinced that is correct. * In any case, a better solution is needed to prevent diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index 370dbc62ef8..cce511aedcb 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -557,7 +557,7 @@ BVHTree *bvhtree_from_mesh_verts(BVHTreeFromMesh *data, DerivedMesh *dm, float e data->cached = true; /* a NULL nearest callback works fine - * remeber the min distance to point is the same as the min distance to BV of point */ + * remember the min distance to point is the same as the min distance to BV of point */ data->nearest_callback = NULL; data->raycast_callback = NULL; @@ -573,8 +573,9 @@ BVHTree *bvhtree_from_mesh_verts(BVHTreeFromMesh *data, DerivedMesh *dm, float e /* Builds a bvh tree.. where nodes are the faces of the given dm. */ BVHTree *bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *dm, float epsilon, int tree_type, int axis) { - BVHTree *tree = bvhcache_find(&dm->bvhCache, BVHTREE_FROM_FACES); BMEditMesh *em = data->em_evil; + const int bvhcache_type = em ? BVHTREE_FROM_FACES_EDITMESH : BVHTREE_FROM_FACES; + BVHTree *tree = bvhcache_find(&dm->bvhCache, bvhcache_type); /* Not in cache */ if (tree == NULL) { @@ -682,7 +683,7 @@ BVHTree *bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *dm, float e /* Save on cache for later use */ // printf("BVHTree built and saved on cache\n"); - bvhcache_insert(&dm->bvhCache, tree, BVHTREE_FROM_FACES); + bvhcache_insert(&dm->bvhCache, tree, bvhcache_type); } } } diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 1bc12cffe7b..d57d9180697 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -1063,37 +1063,57 @@ static void cdDM_drawMappedFacesTex(DerivedMesh *dm, static void cddm_draw_attrib_vertex(DMVertexAttribs *attribs, MVert *mvert, int a, int index, int vert, int smoothnormal) { + const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}; int b; /* orco texture coordinates */ if (attribs->totorco) { + /*const*/ float (*array)[3] = attribs->orco.array; + const float *orco = (array) ? array[index] : zero; + if (attribs->orco.gl_texco) - glTexCoord3fv(attribs->orco.array[index]); + glTexCoord3fv(orco); else - glVertexAttrib3fvARB(attribs->orco.gl_index, attribs->orco.array[index]); + glVertexAttrib3fvARB(attribs->orco.gl_index, orco); } /* uv texture coordinates */ for (b = 0; b < attribs->tottface; b++) { - MTFace *tf = &attribs->tface[b].array[a]; + const float *uv; + + if (attribs->tface[b].array) { + MTFace *tf = &attribs->tface[b].array[a]; + uv = tf->uv[vert]; + } + else { + uv = zero; + } if (attribs->tface[b].gl_texco) - glTexCoord2fv(tf->uv[vert]); + glTexCoord2fv(uv); else - glVertexAttrib2fvARB(attribs->tface[b].gl_index, tf->uv[vert]); + glVertexAttrib2fvARB(attribs->tface[b].gl_index, uv); } /* vertex colors */ for (b = 0; b < attribs->totmcol; b++) { - MCol *cp = &attribs->mcol[b].array[a * 4 + vert]; GLubyte col[4]; - col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; + + if (attribs->mcol[b].array) { + MCol *cp = &attribs->mcol[b].array[a * 4 + vert]; + col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; + } + else { + col[0] = 0; col[1] = 0; col[2] = 0; col[3] = 0; + } + glVertexAttrib4ubvARB(attribs->mcol[b].gl_index, col); } /* tangent for normal mapping */ if (attribs->tottang) { - float *tang = attribs->tang.array[a * 4 + vert]; + /*const*/ float (*array)[4] = attribs->tang.array; + const float *tang = (array) ? array[a * 4 + vert] : zero; glVertexAttrib4fvARB(attribs->tang.gl_index, tang); } @@ -1264,25 +1284,29 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, if (do_draw) { DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs); - if (attribs.totorco) { + if (attribs.totorco && attribs.orco.array) { datatypes[numdata].index = attribs.orco.gl_index; datatypes[numdata].size = 3; datatypes[numdata].type = GL_FLOAT; numdata++; } for (b = 0; b < attribs.tottface; b++) { - datatypes[numdata].index = attribs.tface[b].gl_index; - datatypes[numdata].size = 2; - datatypes[numdata].type = GL_FLOAT; - numdata++; + if (attribs.tface[b].array) { + datatypes[numdata].index = attribs.tface[b].gl_index; + datatypes[numdata].size = 2; + datatypes[numdata].type = GL_FLOAT; + numdata++; + } } for (b = 0; b < attribs.totmcol; b++) { - datatypes[numdata].index = attribs.mcol[b].gl_index; - datatypes[numdata].size = 4; - datatypes[numdata].type = GL_UNSIGNED_BYTE; - numdata++; + if (attribs.mcol[b].array) { + datatypes[numdata].index = attribs.mcol[b].gl_index; + datatypes[numdata].size = 4; + datatypes[numdata].type = GL_UNSIGNED_BYTE; + numdata++; + } } - if (attribs.tottang) { + if (attribs.tottang && attribs.tang.array) { datatypes[numdata].index = attribs.tang.gl_index; datatypes[numdata].size = 4; datatypes[numdata].type = GL_FLOAT; @@ -1315,34 +1339,38 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, if (do_draw && numdata != 0) { offset = 0; - if (attribs.totorco) { + if (attribs.totorco && attribs.orco.array) { copy_v3_v3((float *)&varray[elementsize * curface * 3], (float *)attribs.orco.array[mface->v1]); copy_v3_v3((float *)&varray[elementsize * curface * 3 + elementsize], (float *)attribs.orco.array[mface->v2]); copy_v3_v3((float *)&varray[elementsize * curface * 3 + elementsize * 2], (float *)attribs.orco.array[mface->v3]); offset += sizeof(float) * 3; } for (b = 0; b < attribs.tottface; b++) { - MTFace *tf = &attribs.tface[b].array[a]; - copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset], tf->uv[0]); - copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize], tf->uv[1]); + if (attribs.tface[b].array) { + MTFace *tf = &attribs.tface[b].array[a]; + copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset], tf->uv[0]); + copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize], tf->uv[1]); - copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize * 2], tf->uv[2]); - offset += sizeof(float) * 2; + copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize * 2], tf->uv[2]); + offset += sizeof(float) * 2; + } } for (b = 0; b < attribs.totmcol; b++) { - MCol *cp = &attribs.mcol[b].array[a * 4 + 0]; - GLubyte col[4]; - col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; - copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset], (char *)col); - cp = &attribs.mcol[b].array[a * 4 + 1]; - col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; - copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize], (char *)col); - cp = &attribs.mcol[b].array[a * 4 + 2]; - col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; - copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize * 2], (char *)col); - offset += sizeof(unsigned char) * 4; + if (attribs.mcol[b].array) { + MCol *cp = &attribs.mcol[b].array[a * 4 + 0]; + GLubyte col[4]; + col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; + copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset], (char *)col); + cp = &attribs.mcol[b].array[a * 4 + 1]; + col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; + copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize], (char *)col); + cp = &attribs.mcol[b].array[a * 4 + 2]; + col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; + copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize * 2], (char *)col); + offset += sizeof(unsigned char) * 4; + } } - if (attribs.tottang) { + if (attribs.tottang && attribs.tang.array) { float *tang = attribs.tang.array[a * 4 + 0]; copy_v4_v4((float *)&varray[elementsize * curface * 3 + offset], tang); tang = attribs.tang.array[a * 4 + 1]; @@ -1357,33 +1385,37 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, if (mface->v4) { if (do_draw && numdata != 0) { offset = 0; - if (attribs.totorco) { + if (attribs.totorco && attribs.orco.array) { copy_v3_v3((float *)&varray[elementsize * curface * 3], (float *)attribs.orco.array[mface->v3]); copy_v3_v3((float *)&varray[elementsize * curface * 3 + elementsize], (float *)attribs.orco.array[mface->v4]); copy_v3_v3((float *)&varray[elementsize * curface * 3 + elementsize * 2], (float *)attribs.orco.array[mface->v1]); offset += sizeof(float) * 3; } for (b = 0; b < attribs.tottface; b++) { - MTFace *tf = &attribs.tface[b].array[a]; - copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset], tf->uv[2]); - copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize], tf->uv[3]); - copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize * 2], tf->uv[0]); - offset += sizeof(float) * 2; + if (attribs.tface[b].array) { + MTFace *tf = &attribs.tface[b].array[a]; + copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset], tf->uv[2]); + copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize], tf->uv[3]); + copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize * 2], tf->uv[0]); + offset += sizeof(float) * 2; + } } for (b = 0; b < attribs.totmcol; b++) { - MCol *cp = &attribs.mcol[b].array[a * 4 + 2]; - GLubyte col[4]; - col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; - copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset], (char *)col); - cp = &attribs.mcol[b].array[a * 4 + 3]; - col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; - copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize], (char *)col); - cp = &attribs.mcol[b].array[a * 4 + 0]; - col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; - copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize * 2], (char *)col); - offset += sizeof(unsigned char) * 4; + if (attribs.mcol[b].array) { + MCol *cp = &attribs.mcol[b].array[a * 4 + 2]; + GLubyte col[4]; + col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; + copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset], (char *)col); + cp = &attribs.mcol[b].array[a * 4 + 3]; + col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; + copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize], (char *)col); + cp = &attribs.mcol[b].array[a * 4 + 0]; + col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; + copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize * 2], (char *)col); + offset += sizeof(unsigned char) * 4; + } } - if (attribs.tottang) { + if (attribs.tottang && attribs.tang.array) { float *tang = attribs.tang.array[a * 4 + 2]; copy_v4_v4((float *)&varray[elementsize * curface * 3 + offset], tang); tang = attribs.tang.array[a * 4 + 3]; @@ -2754,6 +2786,7 @@ void CDDM_calc_edges(DerivedMesh *dm) void CDDM_lower_num_verts(DerivedMesh *dm, int numVerts) { + BLI_assert(numVerts >= 0); if (numVerts < dm->numVertData) CustomData_free_elem(&dm->vertData, numVerts, dm->numVertData - numVerts); @@ -2762,6 +2795,7 @@ void CDDM_lower_num_verts(DerivedMesh *dm, int numVerts) void CDDM_lower_num_edges(DerivedMesh *dm, int numEdges) { + BLI_assert(numEdges >= 0); if (numEdges < dm->numEdgeData) CustomData_free_elem(&dm->edgeData, numEdges, dm->numEdgeData - numEdges); @@ -2770,14 +2804,25 @@ void CDDM_lower_num_edges(DerivedMesh *dm, int numEdges) void CDDM_lower_num_tessfaces(DerivedMesh *dm, int numTessFaces) { + BLI_assert(numTessFaces >= 0); if (numTessFaces < dm->numTessFaceData) CustomData_free_elem(&dm->faceData, numTessFaces, dm->numTessFaceData - numTessFaces); dm->numTessFaceData = numTessFaces; } +void CDDM_lower_num_loops(DerivedMesh *dm, int numLoops) +{ + BLI_assert(numLoops >= 0); + if (numLoops < dm->numLoopData) + CustomData_free_elem(&dm->loopData, numLoops, dm->numLoopData - numLoops); + + dm->numLoopData = numLoops; +} + void CDDM_lower_num_polys(DerivedMesh *dm, int numPolys) { + BLI_assert(numPolys >= 0); if (numPolys < dm->numPolyData) CustomData_free_elem(&dm->polyData, numPolys, dm->numPolyData - numPolys); diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index e4c6f7790d7..cab4adf46bf 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -1114,8 +1114,8 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) if ( numedges==0 ) return 0; - /* NOTE: handling ownership of sptings and edgehash is quite sloppy - * currenlty they are never initialized but assert just to be sure */ + /* NOTE: handling ownership of springs and edgehash is quite sloppy + * currently they are never initialized but assert just to be sure */ BLI_assert(cloth->springs == NULL); BLI_assert(cloth->edgehash == NULL); diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 1f892432d80..0dbb739e6f8 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -1008,7 +1008,7 @@ static bConstraintTypeInfo CTI_TRACKTO = { trackto_evaluate /* evaluate */ }; -/* --------- Inverse-Kinemetics --------- */ +/* --------- Inverse-Kinematics --------- */ static void kinematic_new_data(void *cdata) { @@ -3075,7 +3075,7 @@ static void clampto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *tar float offset; /* check to make sure len is not so close to zero that it'll cause errors */ - if (IS_EQ(len, 0) == 0) { + if (IS_EQF(len, 0.0f) == false) { /* find bounding-box range where target is located */ if (ownLoc[clamp_axis] < curveMin[clamp_axis]) { /* bounding-box range is before */ @@ -3107,7 +3107,7 @@ static void clampto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *tar curvetime = 0.0f; else if (ownLoc[clamp_axis] >= curveMax[clamp_axis]) curvetime = 1.0f; - else if (IS_EQ((curveMax[clamp_axis] - curveMin[clamp_axis]), 0) == 0) + else if (IS_EQF((curveMax[clamp_axis] - curveMin[clamp_axis]), 0.0f) == false) curvetime = (ownLoc[clamp_axis] - curveMin[clamp_axis]) / (curveMax[clamp_axis] - curveMin[clamp_axis]); else curvetime = 0.0f; diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index e255732d3fb..bcf0eafaa65 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -104,10 +104,6 @@ void BKE_curve_editfont_free(Curve *cu) if (cu->editfont) { EditFont *ef = cu->editfont; - if (ef->oldstr) - MEM_freeN(ef->oldstr); - if (ef->oldstrinfo) - MEM_freeN(ef->oldstrinfo); if (ef->textbuf) MEM_freeN(ef->textbuf); if (ef->textbufinfo) @@ -120,6 +116,8 @@ void BKE_curve_editfont_free(Curve *cu) MEM_freeN(ef); cu->editfont = NULL; } + + MEM_SAFE_FREE(cu->selboxes); } void BKE_curve_editNurb_keyIndex_free(EditNurb *editnurb) @@ -230,6 +228,7 @@ Curve *BKE_curve_copy(Curve *cu) cun->editnurb = NULL; cun->editfont = NULL; cun->selboxes = NULL; + cun->lastsel = NULL; #if 0 // XXX old animation system /* single user ipo too */ @@ -579,6 +578,26 @@ Nurb *BKE_nurb_duplicate(Nurb *nu) return newnu; } +/* copy the nurb but allow for different number of points (to be copied after this) */ +Nurb *BKE_nurb_copy(Nurb *src, int pntsu, int pntsv) +{ + Nurb *newnu = (Nurb *)MEM_mallocN(sizeof(Nurb), "copyNurb"); + memcpy(newnu, src, sizeof(Nurb)); + + if (pntsu == 1) SWAP(int, pntsu, pntsv); + newnu->pntsu = pntsu; + newnu->pntsv = pntsv; + + if (src->bezt) { + newnu->bezt = (BezTriple *)MEM_mallocN(pntsu * pntsv * sizeof(BezTriple), "copyNurb2"); + } + else { + newnu->bp = (BPoint *)MEM_mallocN(pntsu * pntsv * sizeof(BPoint), "copyNurb3"); + } + + return newnu; +} + void BKE_nurbList_duplicate(ListBase *lb1, ListBase *lb2) { Nurb *nu, *nun; diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index a183872552d..8aeacda8100 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -335,9 +335,10 @@ void defvert_normalize_lock_single(MDeformVert *dvert, } /* Same as defvert_normalize() if no locked vgroup is a member of the subset */ -void defvert_normalize_lock_map(MDeformVert *dvert, - const bool *vgroup_subset, const int vgroup_tot, - const bool *lock_flags, const int defbase_tot) +void defvert_normalize_lock_map( + MDeformVert *dvert, + const bool *vgroup_subset, const int vgroup_tot, + const bool *lock_flags, const int defbase_tot) { if (dvert->totweight == 0) { /* nothing */ @@ -447,7 +448,7 @@ int *defgroup_flip_map(Object *ob, int *flip_map_len, const bool use_default) } else { bDeformGroup *dg; - char name[sizeof(dg->name)]; + char name_flip[sizeof(dg->name)]; int i, flip_num, *map = MEM_mallocN(defbase_tot * sizeof(int), __func__); for (i = 0; i < defbase_tot; i++) { @@ -461,9 +462,10 @@ int *defgroup_flip_map(Object *ob, int *flip_map_len, const bool use_default) if (use_default) map[i] = i; - flip_side_name(name, dg->name, FALSE); - if (strcmp(name, dg->name)) { - flip_num = defgroup_name_index(ob, name); + BKE_deform_flip_side_name(name_flip, dg->name, false); + + if (!STREQ(name_flip, dg->name)) { + flip_num = defgroup_name_index(ob, name_flip); if (flip_num >= 0) { map[i] = flip_num; map[flip_num] = i; /* save an extra lookup */ @@ -485,7 +487,7 @@ int *defgroup_flip_map_single(Object *ob, int *flip_map_len, const bool use_defa } else { bDeformGroup *dg; - char name[sizeof(dg->name)]; + char name_flip[sizeof(dg->name)]; int i, flip_num, *map = MEM_mallocN(defbase_tot * sizeof(int), __func__); for (i = 0; i < defbase_tot; i++) { @@ -494,9 +496,9 @@ int *defgroup_flip_map_single(Object *ob, int *flip_map_len, const bool use_defa dg = BLI_findlink(&ob->defbase, defgroup); - flip_side_name(name, dg->name, FALSE); - if (strcmp(name, dg->name)) { - flip_num = defgroup_name_index(ob, name); + BKE_deform_flip_side_name(name_flip, dg->name, false); + if (!STREQ(name_flip, dg->name)) { + flip_num = defgroup_name_index(ob, name_flip); if (flip_num != -1) { map[defgroup] = flip_num; @@ -514,11 +516,12 @@ int defgroup_flip_index(Object *ob, int index, const bool use_default) int flip_index = -1; if (dg) { - char name[sizeof(dg->name)]; - flip_side_name(name, dg->name, 0); + char name_flip[sizeof(dg->name)]; + BKE_deform_flip_side_name(name_flip, dg->name, false); - if (strcmp(name, dg->name)) - flip_index = defgroup_name_index(ob, name); + if (!STREQ(name_flip, dg->name)) { + flip_index = defgroup_name_index(ob, name_flip); + } } return (flip_index == -1 && use_default) ? index : flip_index; @@ -602,7 +605,8 @@ void BKE_deform_split_prefix(const char string[MAX_VGROUP_NAME], char pre[MAX_VG /* finds the best possible flipped name. For renaming; check for unique names afterwards */ /* if strip_number: removes number extensions * note: don't use sizeof() for 'name' or 'from_name' */ -void flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_NAME], int strip_number) +void BKE_deform_flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_NAME], + const bool strip_number) { int len; char prefix[MAX_VGROUP_NAME] = ""; /* The part before the facing */ @@ -624,7 +628,7 @@ void flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_ if (isdigit(name[len - 1])) { index = strrchr(name, '.'); // last occurrence if (index && isdigit(index[1])) { // doesnt handle case bone.1abc2 correct..., whatever! - if (strip_number == 0) { + if (strip_number == false) { BLI_strncpy(number, index, sizeof(number)); } *index = 0; diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index caa5bf90584..c3538b141b5 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -34,7 +34,7 @@ * to three loops per triangle. the derivedmesh stores a cache of tessellations * for each face. this cache will smartly update as needed (though at first * it'll simply be more brute force). keeping track of face/edge counts may - * be a small problbm. + * be a small problem. * * this won't be the most efficient thing, considering that internal edges and * faces of tessellations are exposed. looking up an edge by index in particular @@ -888,23 +888,47 @@ static void emdm_pass_attrib_vertex_glsl(DMVertexAttribs *attribs, BMLoop *loop, { BMVert *eve = loop->v; int i; + const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}; if (attribs->totorco) { - const float *orco = attribs->orco.array[BM_elem_index_get(eve)]; - glVertexAttrib3fvARB(attribs->orco.gl_index, orco); + int index = BM_elem_index_get(eve); + const float *orco = (attribs->orco.array) ? attribs->orco.array[index] : zero; + + if (attribs->orco.gl_texco) + glTexCoord3fv(orco); + else + glVertexAttrib3fvARB(attribs->orco.gl_index, orco); } for (i = 0; i < attribs->tottface; i++) { - const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(loop, attribs->tface[i].em_offset); - glVertexAttrib2fvARB(attribs->tface[i].gl_index, luv->uv); + const float *uv; + + if (attribs->tface[i].em_offset != -1) { + const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(loop, attribs->tface[i].em_offset); + uv = luv->uv; + } + else { + uv = zero; + } + + if (attribs->tface[i].gl_texco) + glTexCoord2fv(uv); + else + glVertexAttrib2fvARB(attribs->tface[i].gl_index, uv); } for (i = 0; i < attribs->totmcol; i++) { - const MLoopCol *cp = BM_ELEM_CD_GET_VOID_P(loop, attribs->mcol[i].em_offset); GLubyte col[4]; - col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; + if (attribs->mcol[i].em_offset != -1) { + const MLoopCol *cp = BM_ELEM_CD_GET_VOID_P(loop, attribs->mcol[i].em_offset); + col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; + } + else { + col[0] = 0; col[1] = 0; col[2] = 0; col[3] = 0; + } glVertexAttrib4ubvARB(attribs->mcol[i].gl_index, col); } if (attribs->tottang) { - const float *tang = attribs->tang.array[i * 4 + index_in_face]; + int index = i * 4 + index_in_face; + const float *tang = (attribs->tang.array) ? attribs->tang.array[index] : zero; glVertexAttrib4fvARB(attribs->tang.gl_index, tang); } } @@ -1020,38 +1044,6 @@ static void emDM_drawFacesGLSL(DerivedMesh *dm, dm->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL); } -/* emdm_pass_attrib_vertex_glsl's note about em_offset use applies here */ -static void emdm_pass_attrib_vertex_mat(DMVertexAttribs *attribs, BMLoop *loop, int index_in_face) -{ - BMVert *eve = loop->v; - int i; - - if (attribs->totorco) { - float *orco = attribs->orco.array[BM_elem_index_get(eve)]; - if (attribs->orco.gl_texco) - glTexCoord3fv(orco); - else - glVertexAttrib3fvARB(attribs->orco.gl_index, orco); - } - for (i = 0; i < attribs->tottface; i++) { - const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(loop, attribs->tface[i].em_offset); - if (attribs->tface[i].gl_texco) - glTexCoord2fv(luv->uv); - else - glVertexAttrib2fvARB(attribs->tface[i].gl_index, luv->uv); - } - for (i = 0; i < attribs->totmcol; i++) { - const MLoopCol *cp = BM_ELEM_CD_GET_VOID_P(loop, attribs->mcol[i].em_offset); - GLubyte col[4]; - col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; - glVertexAttrib4ubvARB(attribs->mcol[i].gl_index, col); - } - if (attribs->tottang) { - float *tang = attribs->tang.array[i * 4 + index_in_face]; - glVertexAttrib4fvARB(attribs->tang.gl_index, tang); - } -} - static void emDM_drawMappedFacesMat(DerivedMesh *dm, void (*setMaterial)(void *userData, int, void *attribs), bool (*setFace)(void *userData, int index), void *userData) @@ -1105,21 +1097,21 @@ static void emDM_drawMappedFacesMat(DerivedMesh *dm, if (vertexCos) glNormal3fv(polyNos[BM_elem_index_get(efa)]); else glNormal3fv(efa->no); - emdm_pass_attrib_vertex_mat(&attribs, ltri[0], 0); + emdm_pass_attrib_vertex_glsl(&attribs, ltri[0], 0); if (vertexCos) glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]); else glVertex3fv(ltri[0]->v->co); - emdm_pass_attrib_vertex_mat(&attribs, ltri[1], 1); + emdm_pass_attrib_vertex_glsl(&attribs, ltri[1], 1); if (vertexCos) glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]); else glVertex3fv(ltri[1]->v->co); - emdm_pass_attrib_vertex_mat(&attribs, ltri[2], 2); + emdm_pass_attrib_vertex_glsl(&attribs, ltri[2], 2); if (vertexCos) glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]); else glVertex3fv(ltri[2]->v->co); } else { - emdm_pass_attrib_vertex_mat(&attribs, ltri[0], 0); + emdm_pass_attrib_vertex_glsl(&attribs, ltri[0], 0); if (vertexCos) { glNormal3fv(vertexNos[BM_elem_index_get(ltri[0]->v)]); glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]); @@ -1129,7 +1121,7 @@ static void emDM_drawMappedFacesMat(DerivedMesh *dm, glVertex3fv(ltri[0]->v->co); } - emdm_pass_attrib_vertex_mat(&attribs, ltri[1], 1); + emdm_pass_attrib_vertex_glsl(&attribs, ltri[1], 1); if (vertexCos) { glNormal3fv(vertexNos[BM_elem_index_get(ltri[1]->v)]); glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]); @@ -1139,7 +1131,7 @@ static void emDM_drawMappedFacesMat(DerivedMesh *dm, glVertex3fv(ltri[1]->v->co); } - emdm_pass_attrib_vertex_mat(&attribs, ltri[2], 2); + emdm_pass_attrib_vertex_glsl(&attribs, ltri[2], 2); if (vertexCos) { glNormal3fv(vertexNos[BM_elem_index_get(ltri[2]->v)]); glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]); @@ -1241,7 +1233,8 @@ static void emDM_getVert(DerivedMesh *dm, int index, MVert *r_vert) return; } - ev = bmdm->em->vert_index[index]; /* should be EDBM_vert_at_index() */ + BLI_assert((bm->elem_table_dirty & BM_VERT) == 0); + ev = bm->vtable[index]; /* should be BM_vert_at_index() */ // ev = BM_vert_at_index(bm, index); /* warning, does list loop, _not_ ideal */ bmvert_to_mvert(bm, ev, r_vert); @@ -1263,7 +1256,10 @@ static void emDM_getVertCo(DerivedMesh *dm, int index, float r_co[3]) copy_v3_v3(r_co, bmdm->vertexCos[index]); } else { - BMVert *ev = bmdm->em->vert_index[index]; /* should be EDBM_vert_at_index() */ + BMVert *ev; + + BLI_assert((bm->elem_table_dirty & BM_VERT) == 0); + ev = bm->vtable[index]; /* should be BM_vert_at_index() */ // ev = BM_vert_at_index(bm, index); /* warning, does list loop, _not_ ideal */ copy_v3_v3(r_co, ev->co); } @@ -1285,7 +1281,10 @@ static void emDM_getVertNo(DerivedMesh *dm, int index, float r_no[3]) copy_v3_v3(r_no, bmdm->vertexNos[index]); } else { - BMVert *ev = bmdm->em->vert_index[index]; /* should be EDBM_vert_at_index() */ + BMVert *ev; + + BLI_assert((bm->elem_table_dirty & BM_VERT) == 0); + ev = bm->vtable[index]; /* should be BM_vert_at_index() */ // ev = BM_vert_at_index(bm, index); /* warning, does list loop, _not_ ideal */ copy_v3_v3(r_no, ev->no); } @@ -1306,7 +1305,10 @@ static void emDM_getPolyNo(DerivedMesh *dm, int index, float r_no[3]) copy_v3_v3(r_no, bmdm->polyNos[index]); } else { - BMFace *efa = bmdm->em->face_index[index]; /* should be EDBM_vert_at_index() */ + BMFace *efa; + + BLI_assert((bm->elem_table_dirty & BM_FACE) == 0); + efa = bm->ftable[index]; /* should be BM_vert_at_index() */ // efa = BM_face_at_index(bm, index); /* warning, does list loop, _not_ ideal */ copy_v3_v3(r_no, efa->no); } @@ -1324,7 +1326,8 @@ static void emDM_getEdge(DerivedMesh *dm, int index, MEdge *r_edge) return; } - e = bmdm->em->edge_index[index]; /* should be EDBM_edge_at_index() */ + BLI_assert((bm->elem_table_dirty & BM_EDGE) == 0); + e = bm->etable[index]; /* should be BM_edge_at_index() */ // e = BM_edge_at_index(bm, index); /* warning, does list loop, _not_ ideal */ r_edge->flag = BM_edge_flag_to_mflag(e); @@ -1848,7 +1851,7 @@ static void statvis_calc_thickness( BM_mesh_elem_index_ensure(bm, BM_VERT); } - bmtree = BKE_bmbvh_new(em, 0, vertexCos, false); + bmtree = BKE_bmbvh_new_from_editmesh(em, 0, vertexCos, false); for (i = 0; i < tottri; i++) { BMFace *f_hit; @@ -1948,7 +1951,7 @@ static void statvis_calc_intersect( BM_mesh_elem_index_ensure(bm, BM_VERT); } - bmtree = BKE_bmbvh_new(em, 0, vertexCos, false); + bmtree = BKE_bmbvh_new_from_editmesh(em, 0, vertexCos, false); BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { BMFace *f_hit; diff --git a/source/blender/blenkernel/intern/editmesh.c b/source/blender/blenkernel/intern/editmesh.c index 6a89d16d7bf..88cef0ec031 100644 --- a/source/blender/blenkernel/intern/editmesh.c +++ b/source/blender/blenkernel/intern/editmesh.c @@ -78,10 +78,6 @@ BMEditMesh *BKE_editmesh_copy(BMEditMesh *em) * used.*/ em_copy->looptris = NULL; - em_copy->vert_index = NULL; - em_copy->edge_index = NULL; - em_copy->face_index = NULL; - return em_copy; } @@ -106,9 +102,8 @@ BMEditMesh *BKE_editmesh_from_object(Object *ob) static void editmesh_tessface_calc_intern(BMEditMesh *em) { - /* use this to avoid locking pthread for _every_ polygon - * and calling the fill function */ -#define USE_TESSFACE_SPEEDUP + /* allocating space before calculating the tessellation */ + BMesh *bm = em->bm; @@ -118,13 +113,6 @@ static void editmesh_tessface_calc_intern(BMEditMesh *em) const int looptris_tot_prev_alloc = em->looptris ? (MEM_allocN_len(em->looptris) / sizeof(*em->looptris)) : 0; BMLoop *(*looptris)[3]; - BMIter iter; - BMFace *efa; - BMLoop *l; - int i = 0; - - ScanFillContext sf_ctx; - MemArena *sf_arena = NULL; #if 0 /* note, we could be clever and re-use this array but would need to ensure @@ -140,7 +128,7 @@ static void editmesh_tessface_calc_intern(BMEditMesh *em) /* this means no reallocs for quad dominant models, for */ if ((em->looptris != NULL) && - /* (em->tottri >= looptris_tot)) */ + /* (*em->tottri >= looptris_tot)) */ /* check against alloc'd size incase we over alloc'd a little */ ((looptris_tot_prev_alloc >= looptris_tot) && (looptris_tot_prev_alloc <= looptris_tot * 2))) { @@ -153,136 +141,10 @@ static void editmesh_tessface_calc_intern(BMEditMesh *em) #endif - BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) { - /* don't consider two-edged faces */ - if (UNLIKELY(efa->len < 3)) { - /* do nothing */ - } - -#ifdef USE_TESSFACE_SPEEDUP - - /* no need to ensure the loop order, we know its ok */ - - else if (efa->len == 3) { -#if 0 - int j; - BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, j) { - looptris[i][j] = l; - } - i += 1; -#else - /* more cryptic but faster */ - BMLoop **l_ptr = looptris[i++]; - l_ptr[0] = l = BM_FACE_FIRST_LOOP(efa); - l_ptr[1] = l = l->next; - l_ptr[2] = l->next; -#endif - } - else if (efa->len == 4) { -#if 0 - BMLoop *ltmp[4]; - int j; - BLI_array_grow_items(looptris, 2); - BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, j) { - ltmp[j] = l; - } - - looptris[i][0] = ltmp[0]; - looptris[i][1] = ltmp[1]; - looptris[i][2] = ltmp[2]; - i += 1; - - looptris[i][0] = ltmp[0]; - looptris[i][1] = ltmp[2]; - looptris[i][2] = ltmp[3]; - i += 1; -#else - /* more cryptic but faster */ - BMLoop **l_ptr_a = looptris[i++]; - BMLoop **l_ptr_b = looptris[i++]; - (l_ptr_a[0] = l_ptr_b[0] = l = BM_FACE_FIRST_LOOP(efa)); - (l_ptr_a[1] = l = l->next); - (l_ptr_a[2] = l_ptr_b[1] = l = l->next); - ( l_ptr_b[2] = l->next); -#endif - } - -#endif /* USE_TESSFACE_SPEEDUP */ - - else { - int j; - BMLoop *l_iter; - BMLoop *l_first; - - ScanFillVert *sf_vert, *sf_vert_last = NULL, *sf_vert_first = NULL; - /* ScanFillEdge *e; */ /* UNUSED */ - ScanFillFace *sf_tri; - int totfilltri; - - if (UNLIKELY(sf_arena == NULL)) { - sf_arena = BLI_memarena_new(BLI_SCANFILL_ARENA_SIZE, __func__); - } - - BLI_scanfill_begin_arena(&sf_ctx, sf_arena); - - /* scanfill time */ - j = 0; - l_iter = l_first = BM_FACE_FIRST_LOOP(efa); - do { - sf_vert = BLI_scanfill_vert_add(&sf_ctx, l_iter->v->co); - sf_vert->tmp.p = l_iter; - - if (sf_vert_last) { - /* e = */ BLI_scanfill_edge_add(&sf_ctx, sf_vert_last, sf_vert); - } - - sf_vert_last = sf_vert; - if (sf_vert_first == NULL) { - sf_vert_first = sf_vert; - } - - /*mark order */ - BM_elem_index_set(l_iter, j++); /* set_loop */ - - } while ((l_iter = l_iter->next) != l_first); - - /* complete the loop */ - BLI_scanfill_edge_add(&sf_ctx, sf_vert_first, sf_vert); - - totfilltri = BLI_scanfill_calc_ex(&sf_ctx, 0, efa->no); - BLI_assert(totfilltri <= efa->len - 2); - (void)totfilltri; - - for (sf_tri = sf_ctx.fillfacebase.first; sf_tri; sf_tri = sf_tri->next) { - BMLoop **l_ptr = looptris[i++]; - BMLoop *l1 = sf_tri->v1->tmp.p; - BMLoop *l2 = sf_tri->v2->tmp.p; - BMLoop *l3 = sf_tri->v3->tmp.p; - - if (BM_elem_index_get(l1) > BM_elem_index_get(l2)) { SWAP(BMLoop *, l1, l2); } - if (BM_elem_index_get(l2) > BM_elem_index_get(l3)) { SWAP(BMLoop *, l2, l3); } - if (BM_elem_index_get(l1) > BM_elem_index_get(l2)) { SWAP(BMLoop *, l1, l2); } - - l_ptr[0] = l1; - l_ptr[1] = l2; - l_ptr[2] = l3; - } - - BLI_scanfill_end_arena(&sf_ctx, sf_arena); - } - } - - if (sf_arena) { - BLI_memarena_free(sf_arena); - sf_arena = NULL; - } - - em->tottri = i; em->looptris = looptris; - BLI_assert(em->tottri <= looptris_tot); - -#undef USE_TESSFACE_SPEEDUP + /* after allocating the em->looptris, we're ready to tessellate */ + BM_bmesh_calc_tessellation(em->bm, em->looptris, &em->tottri); } @@ -345,10 +207,6 @@ void BKE_editmesh_free(BMEditMesh *em) if (em->looptris) MEM_freeN(em->looptris); - if (em->vert_index) MEM_freeN(em->vert_index); - if (em->edge_index) MEM_freeN(em->edge_index); - if (em->face_index) MEM_freeN(em->face_index); - if (em->bm) BM_mesh_free(em->bm); } diff --git a/source/blender/blenkernel/intern/editmesh_bvh.c b/source/blender/blenkernel/intern/editmesh_bvh.c index cb65fd80fc4..1c0e508e9e6 100644 --- a/source/blender/blenkernel/intern/editmesh_bvh.c +++ b/source/blender/blenkernel/intern/editmesh_bvh.c @@ -44,7 +44,9 @@ struct BMBVHTree { BVHTree *tree; - BMEditMesh *em; + BMLoop *(*looptris)[3]; + int looptris_tot; + BMesh *bm; const float (*cos_cage)[3]; @@ -53,33 +55,39 @@ struct BMBVHTree { int flag; }; -BMBVHTree *BKE_bmbvh_new(BMEditMesh *em, int flag, const float (*cos_cage)[3], const bool cos_cage_free) +BMBVHTree *BKE_bmbvh_new_from_editmesh(BMEditMesh *em, int flag, const float (*cos_cage)[3], const bool cos_cage_free) +{ + return BKE_bmbvh_new(em->bm, em->looptris, em->tottri, flag, cos_cage, cos_cage_free); +} + +BMBVHTree *BKE_bmbvh_new(BMesh *bm, BMLoop *(*looptris)[3], int looptris_tot, int flag, const float (*cos_cage)[3], +const bool cos_cage_free) { /* could become argument */ const float epsilon = FLT_EPSILON * 2.0f; - struct BMLoop *(*looptris)[3] = em->looptris; BMBVHTree *bmtree = MEM_callocN(sizeof(*bmtree), "BMBVHTree"); float cos[3][3]; int i; int tottri; /* BKE_editmesh_tessface_calc() must be called already */ - BLI_assert(em->tottri != 0 || em->bm->totface == 0); + BLI_assert(looptris_tot != 0 || bm->totface == 0); if (cos_cage) { - BM_mesh_elem_index_ensure(em->bm, BM_VERT); + BM_mesh_elem_index_ensure(bm, BM_VERT); } - bmtree->em = em; - bmtree->bm = em->bm; + bmtree->looptris = looptris; + bmtree->looptris_tot = looptris_tot; + bmtree->bm = bm; bmtree->cos_cage = cos_cage; bmtree->cos_cage_free = cos_cage_free; bmtree->flag = flag; if (flag & (BMBVH_RESPECT_SELECT)) { tottri = 0; - for (i = 0; i < em->tottri; i++) { + for (i = 0; i < looptris_tot; i++) { if (BM_elem_flag_test(looptris[i][0]->f, BM_ELEM_SELECT)) { tottri++; } @@ -87,23 +95,23 @@ BMBVHTree *BKE_bmbvh_new(BMEditMesh *em, int flag, const float (*cos_cage)[3], c } else if (flag & (BMBVH_RESPECT_HIDDEN)) { tottri = 0; - for (i = 0; i < em->tottri; i++) { + for (i = 0; i < looptris_tot; i++) { if (!BM_elem_flag_test(looptris[i][0]->f, BM_ELEM_HIDDEN)) { tottri++; } } } else { - tottri = em->tottri; + tottri = looptris_tot; } bmtree->tree = BLI_bvhtree_new(tottri, epsilon, 8, 8); - for (i = 0; i < em->tottri; i++) { + for (i = 0; i < looptris_tot; i++) { if (flag & BMBVH_RESPECT_SELECT) { /* note, the arrays wont align now! take care */ - if (!BM_elem_flag_test(em->looptris[i][0]->f, BM_ELEM_SELECT)) { + if (!BM_elem_flag_test(looptris[i][0]->f, BM_ELEM_SELECT)) { continue; } } @@ -231,14 +239,14 @@ BMFace *BKE_bmbvh_ray_cast(BMBVHTree *bmtree, const float co[3], const float dir hit.index = -1; /* ok to leave 'uv' uninitialized */ - bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->em->looptris; + bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->looptris; bmcb_data.cos_cage = (const float (*)[3])bmtree->cos_cage; BLI_bvhtree_ray_cast(bmtree->tree, co, dir, radius, &hit, bmbvh_ray_cast_cb, &bmcb_data); if (hit.index != -1 && hit.dist != dist) { if (r_hitout) { if (bmtree->flag & BMBVH_RETURN_ORIG) { - BMLoop **ltri = bmtree->em->looptris[hit.index]; + BMLoop **ltri = bmtree->looptris[hit.index]; interp_v3_v3v3v3_uv(r_hitout, ltri[0]->v->co, ltri[1]->v->co, ltri[2]->v->co, bmcb_data.uv); } else { @@ -254,7 +262,7 @@ BMFace *BKE_bmbvh_ray_cast(BMBVHTree *bmtree, const float co[3], const float dir *r_dist = hit.dist; } - return bmtree->em->looptris[hit.index][0]->f; + return bmtree->looptris[hit.index][0]->f; } return NULL; @@ -327,7 +335,7 @@ BMFace *BKE_bmbvh_find_face_segment(BMBVHTree *bmtree, const float co_a[3], cons hit.index = -1; /* ok to leave 'uv' uninitialized */ - bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->em->looptris; + bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->looptris; bmcb_data.cos_cage = (const float (*)[3])bmtree->cos_cage; bmcb_data.co_a = co_a; bmcb_data.co_b = co_b; @@ -337,7 +345,7 @@ BMFace *BKE_bmbvh_find_face_segment(BMBVHTree *bmtree, const float co_a[3], cons /* duplicate of BKE_bmbvh_ray_cast() */ if (r_hitout) { if (bmtree->flag & BMBVH_RETURN_ORIG) { - BMLoop **ltri = bmtree->em->looptris[hit.index]; + BMLoop **ltri = bmtree->looptris[hit.index]; interp_v3_v3v3v3_uv(r_hitout, ltri[0]->v->co, ltri[1]->v->co, ltri[2]->v->co, bmcb_data.uv); } else { @@ -354,7 +362,7 @@ BMFace *BKE_bmbvh_find_face_segment(BMBVHTree *bmtree, const float co_a[3], cons *r_fac = hit.dist / dist; } - return bmtree->em->looptris[hit.index][0]->f; + return bmtree->looptris[hit.index][0]->f; } return NULL; @@ -410,13 +418,13 @@ BMVert *BKE_bmbvh_find_vert_closest(BMBVHTree *bmtree, const float co[3], const hit.dist = maxdist_sq; hit.index = -1; - bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->em->looptris; + bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->looptris; bmcb_data.cos_cage = (const float (*)[3])bmtree->cos_cage; bmcb_data.maxdist = maxdist_sq; BLI_bvhtree_find_nearest(bmtree->tree, co, &hit, bmbvh_find_vert_closest_cb, &bmcb_data); if (hit.index != -1) { - BMLoop **ltri = bmtree->em->looptris[hit.index]; + BMLoop **ltri = bmtree->looptris[hit.index]; return ltri[bmcb_data.index_tri]->v; } diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index dbdf30ea63d..a40d7401566 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -2139,11 +2139,39 @@ float evaluate_fcurve(FCurve *fcu, float evaltime) /* if there is a driver (only if this F-Curve is acting as 'driver'), evaluate it to find value to use as "evaltime" * since drivers essentially act as alternative input (i.e. in place of 'time') for F-Curves - * - this value will also be returned as the value of the 'curve', if there are no keyframes */ if (fcu->driver) { /* evaltime now serves as input for the curve */ - evaltime = cvalue = evaluate_driver(fcu->driver, evaltime); + evaltime = evaluate_driver(fcu->driver, evaltime); + + /* only do a default 1-1 mapping if it's unlikely that anything else will set a value... */ + if (fcu->totvert == 0) { + FModifier *fcm; + bool do_linear = true; + + /* out-of-range F-Modifiers will block, as will those which just plain overwrite the values + * XXX: additive is a bit more dicey; it really depends then if things are in range or not... + */ + for (fcm = fcu->modifiers.first; fcm; fcm = fcm->next) { + /* if there are range-restrictions, we must definitely block [#36950] */ + if ((fcm->flag & FMODIFIER_FLAG_RANGERESTRICT) == 0 || + ((fcm->sfra <= evaltime) && (fcm->efra >= evaltime)) ) + { + /* within range: here it probably doesn't matter, though we'd want to check on additive... */ + } + else { + /* outside range: modifier shouldn't contribute to the curve here, though it does in other areas, + * so neither should the driver! + */ + do_linear = false; + } + } + + /* only copy over results if none of the modifiers disagreed with this */ + if (do_linear) { + cvalue = evaltime; + } + } } /* evaluate modifiers which modify time to evaluate the base curve at */ diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index f24d84df2e8..f489adc7445 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -315,25 +315,13 @@ static void build_underline(Curve *cu, float x1, float y1, float x2, float y2, i MEM_freeN(nu2); return; } - nu2->bp = bp; - nu2->bp[0].vec[0] = x1; - nu2->bp[0].vec[1] = y1; - nu2->bp[0].vec[2] = 0; - nu2->bp[0].vec[3] = 1.0f; - nu2->bp[1].vec[0] = x2; - nu2->bp[1].vec[1] = y1; - nu2->bp[1].vec[2] = 0; - nu2->bp[1].vec[3] = 1.0f; - nu2->bp[2].vec[0] = x2; - nu2->bp[2].vec[1] = y2; - nu2->bp[2].vec[2] = 0; - nu2->bp[2].vec[3] = 1.0f; - nu2->bp[3].vec[0] = x1; - nu2->bp[3].vec[1] = y2; - nu2->bp[3].vec[2] = 0; - nu2->bp[3].vec[3] = 1.0f; - + copy_v4_fl4(bp[0].vec, x1, y1, 0.0f, 1.0f); + copy_v4_fl4(bp[1].vec, x2, y1, 0.0f, 1.0f); + copy_v4_fl4(bp[2].vec, x2, y2, 0.0f, 1.0f); + copy_v4_fl4(bp[3].vec, x1, y2, 0.0f, 1.0f); + + nu2->bp = bp; BLI_addtail(&(cu->nurb), nu2); } diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index 4d17bd286b4..42e146301a2 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -38,6 +38,7 @@ #include "BLI_blenlib.h" #include "BLI_utildefines.h" +#include "BLI_math_vector.h" #include "BLF_translation.h" @@ -182,7 +183,7 @@ bGPDlayer *gpencil_layer_addnew(bGPdata *gpd, const char *name, int setactive) BLI_addtail(&gpd->layers, gpl); /* set basic settings */ - gpl->color[3] = 0.9f; + copy_v4_v4(gpl->color, U.gpencil_new_layer_col); gpl->thickness = 3; /* auto-name */ diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 6f275e4ec75..594c918b4c2 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -641,7 +641,7 @@ int IDP_InsertToGroup(IDProperty *group, IDProperty *previous, IDProperty *pnew) * IDP_FreeProperty(prop); //free all subdata * MEM_freeN(prop); //free property struct itself */ -void IDP_RemFromGroup(IDProperty *group, IDProperty *prop) +void IDP_RemoveFromGroup(IDProperty *group, IDProperty *prop) { BLI_assert(group->type == IDP_GROUP); @@ -649,6 +649,16 @@ void IDP_RemFromGroup(IDProperty *group, IDProperty *prop) BLI_remlink(&group->data.group, prop); } +/** + * Removes the property from the group and frees it. + */ +void IDP_FreeFromGroup(IDProperty *group, IDProperty *prop) +{ + IDP_RemoveFromGroup(group, prop); + IDP_FreeProperty(prop); + MEM_freeN(prop); +} + IDProperty *IDP_GetPropertyFromGroup(IDProperty *prop, const char *name) { BLI_assert(prop->type == IDP_GROUP); diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 01b41eb22cd..6a411f8c308 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -191,17 +191,21 @@ void BKE_image_de_interlace(Image *ima, int odd) /* ***************** ALLOC & FREE, DATA MANAGING *************** */ -static void image_free_buffers(Image *ima) +static void image_free_cahced_frames(Image *image) { ImBuf *ibuf; - - while ((ibuf = BLI_pophead(&ima->ibufs))) { + while ((ibuf = BLI_pophead(&image->ibufs))) { if (ibuf->userdata) { MEM_freeN(ibuf->userdata); ibuf->userdata = NULL; } IMB_freeImBuf(ibuf); } +} + +static void image_free_buffers(Image *ima) +{ + image_free_cahced_frames(ima); if (ima->anim) IMB_free_anim(ima->anim); ima->anim = NULL; @@ -2237,7 +2241,7 @@ void BKE_image_signal(Image *ima, ImageUser *iuser, int signal) #else /* image buffers for non-sequence multilayer will share buffers with RenderResult, * however sequence multilayer will own buffers. Such logic makes switching from - * single multilayer file to sequence completely instable + * single multilayer file to sequence completely unstable * since changes in nodes seems this workaround isn't needed anymore, all sockets * are nicely detecting anyway, but freeing buffers always here makes multilayer * sequences behave stable @@ -2505,26 +2509,22 @@ static ImBuf *image_load_sequence_multilayer(Image *ima, ImageUser *iuser, int f /* check for new RenderResult */ if (ima->rr == NULL || frame != ima->rr->framenr) { - /* copy to survive not found multilayer image */ - RenderResult *oldrr = ima->rr; + if (ima->rr) { + /* Cached image buffers shares pointers with render result, + * need to ensure there's no image buffers are hanging around + * with dead links after freeing the render result. + */ + image_free_cahced_frames(ima); + RE_FreeRenderResult(ima->rr); + ima->rr = NULL; + } - ima->rr = NULL; ibuf = image_load_sequence_file(ima, iuser, frame); if (ibuf) { /* actually an error */ ima->type = IMA_TYPE_IMAGE; printf("error, multi is normal image\n"); } - // printf("loaded new result %p\n", ima->rr); - /* free result if new one found */ - if (ima->rr) { - // if (oldrr) printf("freed previous result %p\n", oldrr); - if (oldrr) RE_FreeRenderResult(oldrr); - } - else { - ima->rr = oldrr; - } - } if (ima->rr) { RenderPass *rpass = BKE_image_multilayer_index(ima->rr, iuser); diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index ecc4a03d255..8ef3b7ef23d 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -712,17 +712,6 @@ static const char *world_adrcodes_to_paths(int adrcode, int *array_index) return "mist.start"; case WO_MISTHI: return "mist.height"; - - case WO_STAR_R: - case WO_STAR_G: - case WO_STAR_B: - printf("WARNING: WO_STAR_R/G/B deprecated\n"); - return NULL; - - case WO_STARDIST: - return "stars.min_distance"; - case WO_STARSIZE: - return "stars.size"; default: /* for now, we assume that the others were MTex channels */ return mtex_adrcodes_to_paths(adrcode, array_index); diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index c856d8cfea4..b20b4294f84 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -462,7 +462,7 @@ void BKE_mask_point_handle(MaskSplinePoint *point, float handle[2]) handle[1] = (point->bezt.vec[1][1] - vec[0]); } -void BKE_mask_point_set_handle(MaskSplinePoint *point, float loc[2], int keep_direction, +void BKE_mask_point_set_handle(MaskSplinePoint *point, float loc[2], bool keep_direction, float orig_handle[2], float orig_vec[3][3]) { BezTriple *bezt = &point->bezt; @@ -1443,7 +1443,7 @@ void BKE_mask_spline_ensure_deform(MaskSpline *spline) } } -void BKE_mask_layer_evaluate(MaskLayer *masklay, const float ctime, const int do_newframe) +void BKE_mask_layer_evaluate(MaskLayer *masklay, const float ctime, const bool do_newframe) { /* animation if available */ if (do_newframe) { @@ -1521,7 +1521,7 @@ void BKE_mask_layer_evaluate(MaskLayer *masklay, const float ctime, const int do } } -void BKE_mask_evaluate(Mask *mask, const float ctime, const int do_newframe) +void BKE_mask_evaluate(Mask *mask, const float ctime, const bool do_newframe) { MaskLayer *masklay; @@ -1562,10 +1562,10 @@ void BKE_mask_update_display(Mask *mask, float ctime) } #endif - BKE_mask_evaluate(mask, ctime, FALSE); + BKE_mask_evaluate(mask, ctime, false); } -void BKE_mask_evaluate_all_masks(Main *bmain, float ctime, const int do_newframe) +void BKE_mask_evaluate_all_masks(Main *bmain, float ctime, const bool do_newframe) { Mask *mask; @@ -1772,7 +1772,7 @@ int BKE_mask_layer_shape_find_frame_range(MaskLayer *masklay, const float frame, } } -MaskLayerShape *BKE_mask_layer_shape_varify_frame(MaskLayer *masklay, const int frame) +MaskLayerShape *BKE_mask_layer_shape_verify_frame(MaskLayer *masklay, const int frame) { MaskLayerShape *masklay_shape; @@ -1835,8 +1835,8 @@ void BKE_mask_layer_shape_sort(MaskLayer *masklay) BLI_sortlist(&masklay->splines_shapes, mask_layer_shape_sort_cb); } -int BKE_mask_layer_shape_spline_from_index(MaskLayer *masklay, int index, - MaskSpline **r_masklay_shape, int *r_index) +bool BKE_mask_layer_shape_spline_from_index(MaskLayer *masklay, int index, + MaskSpline **r_masklay_shape, int *r_index) { MaskSpline *spline; @@ -1844,12 +1844,12 @@ int BKE_mask_layer_shape_spline_from_index(MaskLayer *masklay, int index, if (index < spline->tot_point) { *r_masklay_shape = spline; *r_index = index; - return TRUE; + return true; } index -= spline->tot_point; } - return FALSE; + return false; } int BKE_mask_layer_shape_spline_to_index(MaskLayer *masklay, MaskSpline *spline) @@ -1891,7 +1891,7 @@ static void interp_weights_uv_v2_apply(const float uv[2], float r_pt[2], const f /* when a new points added - resize all shapekey array */ void BKE_mask_layer_shape_changed_add(MaskLayer *masklay, int index, - int do_init, int do_init_interpolate) + bool do_init, bool do_init_interpolate) { MaskLayerShape *masklay_shape; diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index a4b59153e2b..83c257dbd56 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -1637,22 +1637,6 @@ static void polygonize(PROCESS *process, MetaBall *mb) } } -/* could move to math api */ -BLI_INLINE void copy_v3_fl3(float v[3], float x, float y, float z) -{ - v[0] = x; - v[1] = y; - v[2] = z; -} - -/* TODO(sergey): Perhaps it could be general utility function in mathutils. */ -static bool has_zero_axis_m4(float matrix[4][4]) -{ - return len_squared_v3(matrix[0]) < FLT_EPSILON || - len_squared_v3(matrix[1]) < FLT_EPSILON || - len_squared_v3(matrix[2]) < FLT_EPSILON; -} - static float init_meta(PROCESS *process, Scene *scene, Object *ob) /* return totsize */ { Scene *sce_iter = scene; diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index a77f768835a..e6fca21f2af 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -708,26 +708,32 @@ bool BKE_mesh_uv_cdlayer_rename(Mesh *me, const char *old_name, const char *new_ return false; } else { - lidx = lidx_start + (fidx - fidx_start); + lidx = fidx; } } - pidx = pidx_start + (lidx - lidx_start); + pidx = lidx; } else { if (lidx == -1) { - lidx = lidx_start + (pidx - pidx_start); + lidx = pidx; } if (fidx == -1 && do_tessface) { - fidx = fidx_start + (pidx - pidx_start); + fidx = pidx; } } #if 0 /* For now, we do not consider mismatch in indices (i.e. same name leading to (relative) different indices). */ - else if ((pidx - pidx_start) != (lidx - lidx_start)) { - lidx = lidx_start + (pidx - pidx_start); + else if (pidx != lidx) { + lidx = pidx; } #endif + /* Go back to absolute indices! */ + pidx += pidx_start; + lidx += lidx_start; + if (fidx != -1) + fidx += fidx_start; + return BKE_mesh_uv_cdlayer_rename_index(me, pidx, lidx, fidx, new_name, do_tessface); } } @@ -1345,6 +1351,8 @@ int BKE_mesh_nurbs_displist_to_mdata(Object *ob, ListBase *dispbase, mloopuv->uv[1] = (v % dl->nr) / (float)orco_sizeu; /* cyclic correction */ + if ((i == 1 || i == 2) && mloopuv->uv[0] == 0.0f) + mloopuv->uv[0] = 1.0f; if ((i == 0 || i == 1) && mloopuv->uv[1] == 0.0f) mloopuv->uv[1] = 1.0f; } diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c index 47b8e053bf7..1e74ce23c2c 100644 --- a/source/blender/blenkernel/intern/mesh_evaluate.c +++ b/source/blender/blenkernel/intern/mesh_evaluate.c @@ -379,7 +379,8 @@ void BKE_mesh_normals_loop_split(MVert *mverts, const int UNUSED(numVerts), MEdg if ((e2l[0] | e2l[1]) == 0) { /* 'Empty' edge until now, set e2l[0] (and e2l[1] to INDEX_UNSET to tag it as unset). */ e2l[0] = ml_curr_index; - e2l[1] = INDEX_UNSET; + /* We have to check this here too, else we might miss some flat faces!!! */ + e2l[1] = (mp->flag & ME_SMOOTH) ? INDEX_UNSET : INDEX_INVALID; } else if (e2l[1] == INDEX_UNSET) { /* Second loop using this edge, time to test its sharpness. @@ -945,7 +946,7 @@ bool BKE_mesh_center_centroid(Mesh *me, float cent[3]) * \{ */ -/* ngon version wip, based on EDBM_uv_vert_map_create */ +/* ngon version wip, based on BM_uv_vert_map_create */ /* this replaces the non bmesh function (in trunk) which takes MTFace's, if we ever need it back we could * but for now this replaces it because its unused. */ diff --git a/source/blender/blenkernel/intern/mesh_validate.c b/source/blender/blenkernel/intern/mesh_validate.c index 1c9576d74d0..a4f5529ee43 100644 --- a/source/blender/blenkernel/intern/mesh_validate.c +++ b/source/blender/blenkernel/intern/mesh_validate.c @@ -922,7 +922,7 @@ bool BKE_mesh_validate_all_customdata(CustomData *vdata, CustomData *edata, { bool is_valid = true; bool is_change_v, is_change_e, is_change_l, is_change_p; - int tot_texpoly, tot_uvloop; + int tot_texpoly, tot_uvloop, tot_vcolloop; CustomDataMask mask = check_meshmask ? CD_MASK_MESH : 0; is_valid &= mesh_validate_customdata(vdata, mask, do_verbose, do_fixes, &is_change_v); @@ -932,10 +932,23 @@ bool BKE_mesh_validate_all_customdata(CustomData *vdata, CustomData *edata, tot_texpoly = CustomData_number_of_layers(pdata, CD_MTEXPOLY); tot_uvloop = CustomData_number_of_layers(ldata, CD_MLOOPUV); + tot_vcolloop = CustomData_number_of_layers(ldata, CD_MLOOPCOL); if (tot_texpoly != tot_uvloop) { PRINT_ERR("\tCustomDataLayer mismatch, tot_texpoly(%d), tot_uvloop(%d)\n", tot_texpoly, tot_uvloop); } + if (tot_texpoly > MAX_MTFACE) { + PRINT_ERR("\tMore UV layers than %d allowed, %d last ones won't be available for render, shaders, etc.\n", + MAX_MTFACE, tot_texpoly - MAX_MTFACE); + } + if (tot_uvloop > MAX_MTFACE) { + PRINT_ERR("\tMore UV layers than %d allowed, %d last ones won't be available for render, shaders, etc.\n", + MAX_MTFACE, tot_uvloop - MAX_MTFACE); + } + if (tot_vcolloop > MAX_MCOL) { + PRINT_ERR("\tMore VCol layers than %d allowed, %d last ones won't be available for render, shaders, etc.\n", + MAX_MCOL, tot_vcolloop - MAX_MCOL); + } *r_change = (is_change_v || is_change_e || is_change_l || is_change_p); @@ -989,10 +1002,25 @@ void BKE_mesh_cd_validate(Mesh *me) { int totlayer_mtex = CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY); int totlayer_uv = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV); + int totlayer_mcol = CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL); int mtex_index = CustomData_get_layer_index(&me->pdata, CD_MTEXPOLY); int uv_index = CustomData_get_layer_index(&me->ldata, CD_MLOOPUV); int i; + /* XXX For now, do not delete those, just warn they are not really usable. */ + if (UNLIKELY(totlayer_mtex > MAX_MTFACE)) { + printf("WARNING! More UV layers than %d allowed, %d last ones won't be available for render, shaders, etc.\n", + MAX_MTFACE, totlayer_mtex - MAX_MTFACE); + } + if (UNLIKELY(totlayer_uv > MAX_MTFACE)) { + printf("WARNING! More UV layers than %d allowed, %d last ones won't be available for render, shaders, etc.\n", + MAX_MTFACE, totlayer_uv - MAX_MTFACE); + } + if (UNLIKELY(totlayer_mcol > MAX_MCOL)) { + printf("WARNING! More VCol layers than %d allowed, %d last ones won't be available for render, shaders, etc.\n", + MAX_MCOL, totlayer_mcol - MAX_MCOL); + } + if (LIKELY(totlayer_mtex == totlayer_uv)) { /* pass */ } diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index c0df306a3fa..869dbe032c9 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -959,9 +959,6 @@ void nodeInternalRelink(bNodeTree *ntree, bNode *node) { bNodeLink *link, *link_next; - if (node->internal_links.first == NULL) - return; - /* store link pointers in output sockets, for efficient lookup */ for (link = node->internal_links.first; link; link = link->next) link->tosock->link = link; @@ -1675,8 +1672,8 @@ static void free_localized_node_groups(bNodeTree *ntree) for (node = ntree->nodes.first; node; node = node->next) { if (node->type == NODE_GROUP && node->id) { bNodeTree *ngroup = (bNodeTree *)node->id; - if (BLI_findindex(&G.main->nodetree, ngroup) == -1) { - /* ntree is not in library, i.e. localized node group: free it */ + if (ngroup->flag & NTREE_IS_LOCALIZED) { + /* ntree is a localized copy: free it */ ntreeFreeTree_ex(ngroup, false); MEM_freeN(ngroup); } @@ -1963,6 +1960,7 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree) * Note: previews are not copied here. */ ltree = ntreeCopyTree_internal(ntree, NULL, FALSE, FALSE, FALSE); + ltree->flag |= NTREE_IS_LOCALIZED; for (node = ltree->nodes.first; node; node = node->next) { if (node->type == NODE_GROUP && node->id) { @@ -3091,14 +3089,14 @@ void nodeSynchronizeID(bNode *node, bool copy_to_id) /* ************* node type access ********** */ -const char *nodeLabel(bNode *node) +void nodeLabel(bNodeTree *ntree, bNode *node, char *label, int maxlen) { if (node->label[0] != '\0') - return node->label; + BLI_strncpy(label, node->label, maxlen); else if (node->typeinfo->labelfunc) - return node->typeinfo->labelfunc(node); + node->typeinfo->labelfunc(ntree, node, label, maxlen); else - return IFACE_(node->typeinfo->ui_name); + BLI_strncpy(label, IFACE_(node->typeinfo->ui_name), maxlen); } static void node_type_base_defaults(bNodeType *ntype) @@ -3269,7 +3267,7 @@ void node_type_storage(bNodeType *ntype, ntype->freefunc = freefunc; } -void node_type_label(struct bNodeType *ntype, const char *(*labelfunc)(struct bNode *)) +void node_type_label(struct bNodeType *ntype, void (*labelfunc)(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen)) { ntype->labelfunc = labelfunc; } diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 8c2475369de..45d9d144f55 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -32,7 +32,7 @@ #include <string.h> #include <math.h> -#include <stdio.h> +#include <stdio.h> #include "MEM_guardedalloc.h" @@ -194,6 +194,28 @@ void BKE_object_free_modifiers(Object *ob) BKE_object_free_softbody(ob); } +void BKE_object_modifier_hook_reset(Object *ob, HookModifierData *hmd) +{ + /* reset functionality */ + if (hmd->object) { + bPoseChannel *pchan = BKE_pose_channel_find_name(hmd->object->pose, hmd->subtarget); + + if (hmd->subtarget[0] && pchan) { + float imat[4][4], mat[4][4]; + + /* calculate the world-space matrix for the pose-channel target first, then carry on as usual */ + mul_m4_m4m4(mat, hmd->object->obmat, pchan->pose_mat); + + invert_m4_m4(imat, mat); + mul_m4_m4m4(hmd->parentinv, imat, ob->obmat); + } + else { + invert_m4_m4(hmd->object->imat, hmd->object->obmat); + mul_m4_m4m4(hmd->parentinv, hmd->object->imat, ob->obmat); + } + } +} + bool BKE_object_support_modifier_type_check(Object *ob, int modifier_type) { ModifierTypeInfo *mti; @@ -234,6 +256,11 @@ void BKE_object_link_modifiers(struct Object *ob_dst, struct Object *ob_src) if (!BKE_object_support_modifier_type_check(ob_dst, md->type)) continue; + + if (md->type == eModifierType_Skin) { + /* ensure skin-node customdata exists */ + modifier_skin_customdata_ensure(ob_dst); + } nmd = modifier_new(md->type); BLI_strncpy(nmd->name, md->name, sizeof(nmd->name)); @@ -568,6 +595,9 @@ void BKE_object_unlink(Object *ob) } } } + + if (tpsys->parent == ob) + tpsys->parent = NULL; } if (ob->pd) DAG_id_tag_update(&obt->id, OB_RECALC_DATA); @@ -1277,6 +1307,11 @@ Object *BKE_object_copy_ex(Main *bmain, Object *ob, int copy_caches) obn->mode = 0; obn->sculpt = NULL; + /* Proxies are not to be copied. */ + obn->proxy_from = NULL; + obn->proxy_group = NULL; + obn->proxy = NULL; + /* increase user numbers */ id_us_plus((ID *)obn->data); id_us_plus((ID *)obn->gpd); diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index 526d54a97fa..41217110cd8 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -2006,6 +2006,12 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime, pa->lifetime = 100.0f; } else { + /* initialize the lifetime, in case the texture coordinates + * are from Particles/Strands, which would cause undefined values + */ + pa->lifetime = part->lifetime * (1.0f - part->randlife * PSYS_FRAND(p + 21)); + pa->dietime = pa->time + pa->lifetime; + /* get possible textural influence */ psys_get_texture(sim, pa, &ptex, PAMAP_LIFE, cfra); @@ -2844,10 +2850,10 @@ static void sphclassical_force_cb(void *sphdata_v, ParticleKey *state, float *fo continue; } - /* Find vector to neighbour. Exclude particles that are more than 2h + /* Find vector to neighbor. Exclude particles that are more than 2h * away. Can't use current state here because it may have changed on * another thread - so do own mini integration. Unlike basic_integrate, - * SPH integration depends on neighbouring particles. - z0r */ + * SPH integration depends on neighboring particles. - z0r */ madd_v3_v3v3fl(co, npa->prev_state.co, npa->prev_state.vel, state->time); sub_v3_v3v3(vec, co, state->co); rij = normalize_v3(vec); diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index 45a29f6cc90..c9822600fe7 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -1283,6 +1283,11 @@ void BKE_pbvh_node_mark_rebuild_draw(PBVHNode *node) node->flag |= PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw; } +void BKE_pbvh_node_mark_redraw(PBVHNode *node) +{ + node->flag |= PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw; +} + void BKE_pbvh_node_fully_hidden_set(PBVHNode *node, int fully_hidden) { BLI_assert(node->flag & PBVH_Leaf); diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index 334ef9b2d3d..381237f713c 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -1426,7 +1426,7 @@ void BKE_rigidbody_sync_transforms(RigidBodyWorld *rbw, Object *ob, float ctime) } } -/* Used when cancelling transforms - return rigidbody and object to initial states */ +/* Used when canceling transforms - return rigidbody and object to initial states */ void BKE_rigidbody_aftertrans_update(Object *ob, float loc[3], float rot[3], float quat[4], float rotAxis[3], float rotAngle) { RigidBodyOb *rbo = ob->rigidbody_object; diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 41e43c00457..985eae18570 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -157,6 +157,7 @@ Scene *BKE_scene_copy(Scene *sce, int type) lb = scen->r.layers; scen->r = sce->r; scen->r.layers = lb; + scen->r.actlay = 0; scen->unit = sce->unit; scen->physics_settings = sce->physics_settings; scen->gm = sce->gm; @@ -443,7 +444,6 @@ Scene *BKE_scene_add(Main *bmain, const char *name) sce->r.blurfac = 0.5; sce->r.frs_sec = 24; sce->r.frs_sec_base = 1; - sce->r.edgeint = 10; sce->r.ocres = 128; /* OCIO_TODO: for forwards compatibility only, so if no tonecurve are used, @@ -503,6 +503,8 @@ Scene *BKE_scene_add(Main *bmain, const char *name) sce->toolsettings->normalsize = 0.1; sce->toolsettings->autokey_mode = U.autokey_mode; + sce->toolsettings->snap_node_mode = SCE_SNAP_MODE_GRID; + sce->toolsettings->skgen_resolution = 100; sce->toolsettings->skgen_threshold_internal = 0.01f; sce->toolsettings->skgen_threshold_external = 0.01f; @@ -874,18 +876,35 @@ Object *BKE_scene_camera_switch_find(Scene *scene) TimeMarker *m; int cfra = scene->r.cfra; int frame = -(MAXFRAME + 1); + int min_frame = MAXFRAME + 1; Object *camera = NULL; + Object *first_camera = NULL; for (m = scene->markers.first; m; m = m->next) { - if (m->camera && (m->camera->restrictflag & OB_RESTRICT_RENDER) == 0 && (m->frame <= cfra) && (m->frame > frame)) { - camera = m->camera; - frame = m->frame; + if (m->camera && (m->camera->restrictflag & OB_RESTRICT_RENDER) == 0) { + if ((m->frame <= cfra) && (m->frame > frame)) { + camera = m->camera; + frame = m->frame; - if (frame == cfra) - break; + if (frame == cfra) + break; + } + if (m->frame < min_frame) { + first_camera = m->camera; + min_frame = m->frame; + } } } + + if (camera == NULL) { + /* If there's no marker to the left of current frame, + * use camera from left-most marker to solve all sort + * of Schrodinger uncertainties. + */ + return first_camera; + } + return camera; } #endif @@ -1285,7 +1304,7 @@ void BKE_scene_update_for_newframe(Main *bmain, Scene *sce, unsigned int lay) * so don't call within 'scene_update_tagged_recursive' */ DAG_scene_update_flags(bmain, sce, lay, TRUE); // only stuff that moves or needs display still - BKE_mask_evaluate_all_masks(bmain, ctime, TRUE); + BKE_mask_evaluate_all_masks(bmain, ctime, true); /* All 'standard' (i.e. without any dependencies) animation is handled here, * with an 'local' to 'macro' order of evaluation. This should ensure that @@ -1484,16 +1503,6 @@ void BKE_scene_disable_color_management(Scene *scene) int BKE_scene_check_color_management_enabled(const Scene *scene) { - /* TODO(sergey): shouldn't be needed. but we're currently far to close to the release, - * so better be extra-safe than sorry. - * - * Will remove the check after the release. - */ - if (!scene) { - BLI_assert(!"Shouldn't happen!"); - return TRUE; - } - return strcmp(scene->display_settings.display_device, "None") != 0; } diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index dd7e847feaf..49b237fc3ea 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -463,6 +463,7 @@ void BKE_sequencer_imbuf_to_sequencer_space(Scene *scene, ImBuf *ibuf, int make_ if (!STREQ(float_colorspace, to_colorspace)) { IMB_colormanagement_transform_threaded(ibuf->rect_float, ibuf->x, ibuf->y, ibuf->channels, from_colorspace, to_colorspace, true); + sequencer_imbuf_assign_spaces(scene, ibuf); } } } @@ -1854,7 +1855,6 @@ void BKE_sequencer_color_balance_apply(StripColorBalance *cb, ImBuf *ibuf, float init_data.cb = cb; init_data.ibuf = ibuf; init_data.mul = mul; - init_data.mask = NULL; init_data.make_float = make_float; init_data.mask = mask_input; @@ -2342,7 +2342,7 @@ static ImBuf *seq_render_mask(SeqRenderData context, Mask *mask, float nr, short mask_temp = BKE_mask_copy_nolib(mask); - BKE_mask_evaluate(mask_temp, mask->sfra + nr, TRUE); + BKE_mask_evaluate(mask_temp, mask->sfra + nr, true); maskbuf = MEM_mallocN(sizeof(float) * context.rectx * context.recty, __func__); diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index 5c9c564998e..3a6912157fd 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -136,7 +136,7 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) nearest.index = -1; nearest.dist = FLT_MAX; #ifndef __APPLE__ -#pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(treeData,calc) schedule(static) +#pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(treeData, calc) schedule(static) #endif for (i = 0; i < calc->numVerts; ++i) { float *co = calc->vertexCos[i]; @@ -331,7 +331,7 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc) { #ifndef __APPLE__ -#pragma omp parallel for private(i,hit) schedule(static) +#pragma omp parallel for private(i, hit) schedule(static) #endif for (i = 0; i < calc->numVerts; ++i) { float *co = calc->vertexCos[i]; @@ -441,7 +441,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) /* Find the nearest vertex */ #ifndef __APPLE__ -#pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(calc,treeData) schedule(static) +#pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(calc, treeData) schedule(static) #endif for (i = 0; i < calc->numVerts; ++i) { float *co = calc->vertexCos[i]; diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index fb0e22abf2a..23f7dd6ccfb 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -84,6 +84,7 @@ #include "BKE_pointcache.h" #include "BKE_scene.h" #include "BKE_smoke.h" +#include "BKE_texture.h" #include "RE_shader_ext.h" @@ -275,21 +276,21 @@ static void smoke_set_domain_from_derivedmesh(SmokeDomainSettings *sds, Object * /* define grid resolutions from longest domain side */ if (size[0] >= MAX2(size[1], size[2])) { scale = res / size[0]; - sds->scale = size[0] / fabs(ob->size[0]); + sds->scale = size[0] / fabsf(ob->size[0]); sds->base_res[0] = res; sds->base_res[1] = (int)(size[1] * scale + 0.5f); sds->base_res[2] = (int)(size[2] * scale + 0.5f); } else if (size[1] >= MAX2(size[0], size[2])) { scale = res / size[1]; - sds->scale = size[1] / fabs(ob->size[1]); + sds->scale = size[1] / fabsf(ob->size[1]); sds->base_res[0] = (int)(size[0] * scale + 0.5f); sds->base_res[1] = res; sds->base_res[2] = (int)(size[2] * scale + 0.5f); } else { scale = res / size[2]; - sds->scale = size[2] / fabs(ob->size[2]); + sds->scale = size[2] / fabsf(ob->size[2]); sds->base_res[0] = (int)(size[0] * scale + 0.5f); sds->base_res[1] = (int)(size[1] * scale + 0.5f); sds->base_res[2] = res; @@ -1108,7 +1109,7 @@ static void em_freeData(EmissionMap *em) static void em_combineMaps(EmissionMap *output, EmissionMap *em2, int hires_multiplier, int additive, float sample_size) { - int i, x,y,z; + int i, x, y, z; /* copyfill input 1 struct and clear output for new allocation */ EmissionMap em1; @@ -1226,7 +1227,7 @@ static void emit_from_particles(Object *flow_ob, SmokeDomainSettings *sds, Smoke float solid = sfs->particle_size * 0.5f; float smooth = 0.5f; /* add 0.5 cells of linear falloff to reduce aliasing */ int hires_multiplier = 1; - int i,z; + int i, z; KDTree *tree; sim.scene = scene; @@ -1337,7 +1338,7 @@ static void emit_from_particles(Object *flow_ob, SmokeDomainSettings *sds, Smoke float hr = 1.0f / ((float)hires_multiplier); /* slightly adjust high res antialias smoothness based on number of divisions * to allow smaller details but yet not differing too much from the low res size */ - float hr_smooth = smooth * pow(hr, 1.0f/3.0f); + const float hr_smooth = smooth * powf(hr, 1.0f / 3.0f); /* setup loop bounds */ for (i = 0; i < 3; i++) { @@ -1418,27 +1419,6 @@ static void emit_from_particles(Object *flow_ob, SmokeDomainSettings *sds, Smoke } } -/* TODO(sergey): de-duplicate with get_texture_value from modifier utils */ -/* NOTE: Skips color management, because result is only used for value now, not for color. */ -static void get_texture_value(Tex *texture, float tex_co[3], TexResult *texres) -{ - int result_type; - - /* no node textures for now */ - result_type = multitex_ext_safe(texture, tex_co, texres, NULL, false); - - /* if the texture gave an RGB value, we assume it didn't give a valid - * intensity, since this is in the context of modifiers don't use perceptual color conversion. - * if the texture didn't give an RGB value, copy the intensity across - */ - if (result_type & TEX_RGB) { - texres->tin = (1.0f / 3.0f) * (texres->tr + texres->tg + texres->tb); - } - else { - copy_v3_fl(&texres->tr, texres->tin); - } -} - static void sample_derivedmesh(SmokeFlowSettings *sfs, MVert *mvert, MTFace *tface, MFace *mface, float *influence_map, float *velocity_map, int index, int base_res[3], float flow_center[3], BVHTreeFromMesh *treeData, float ray_start[3], float *vert_vel, int has_velocity, int defgrp_index, MDeformVert *dvert, float x, float y, float z) { @@ -1550,7 +1530,7 @@ static void sample_derivedmesh(SmokeFlowSettings *sfs, MVert *mvert, MTFace *tfa tex_co[2] = sfs->texture_offset; } texres.nor = NULL; - get_texture_value(sfs->noise_texture, tex_co, &texres); + BKE_texture_get_value(NULL, sfs->noise_texture, tex_co, &texres, false); sample_str *= texres.tin; } } diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 9a38a5f87b8..900d92d1637 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -1817,6 +1817,64 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes) } } +static void ccgdm_draw_attrib_vertex(DMVertexAttribs *attribs, int a, int index, int vert) +{ + const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}; + int b; + + /* orco texture coordinates */ + if (attribs->totorco) { + /*const*/ float (*array)[3] = attribs->orco.array; + const float *orco = (array) ? array[index] : zero; + + if (attribs->orco.gl_texco) + glTexCoord3fv(orco); + else + glVertexAttrib3fvARB(attribs->orco.gl_index, orco); + } + + /* uv texture coordinates */ + for (b = 0; b < attribs->tottface; b++) { + const float *uv; + + if (attribs->tface[b].array) { + MTFace *tf = &attribs->tface[b].array[a]; + uv = tf->uv[vert]; + } + else { + uv = zero; + } + + if (attribs->tface[b].gl_texco) + glTexCoord2fv(uv); + else + glVertexAttrib2fvARB(attribs->tface[b].gl_index, uv); + } + + /* vertex colors */ + for (b = 0; b < attribs->totmcol; b++) { + GLubyte col[4]; + + if (attribs->mcol[b].array) { + MCol *cp = &attribs->mcol[b].array[a * 4 + vert]; + col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; + } + else { + col[0] = 0; col[1] = 0; col[2] = 0; col[3] = 0; + } + + glVertexAttrib4ubvARB(attribs->mcol[b].gl_index, col); + } + + /* tangent for normal mapping */ + if (attribs->tottang) { + /*const*/ float (*array)[4] = attribs->tang.array; + const float *tang = (array) ? array[a * 4 + vert] : zero; + + glVertexAttrib4fvARB(attribs->tang.gl_index, tang); + } +} + /* Only used by non-editmesh types */ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm, DMSetMaterial setMaterial, @@ -1833,7 +1891,7 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm, int gridFaces = gridSize - 1; int edgeSize = ccgSubSurf_getEdgeSize(ss); DMFlagMat *faceFlags = ccgdm->faceFlags; - int a, b, i, do_draw, numVerts, matnr, new_matnr, totface; + int a, i, do_draw, numVerts, matnr, new_matnr, totface; CCG_key_top_level(&key, ss); ccgdm_pbvh_update(ccgdm); @@ -1842,25 +1900,11 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm, matnr = -1; #define PASSATTRIB(dx, dy, vert) { \ - if (attribs.totorco) { \ + if (attribs.totorco) \ index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize); \ - glVertexAttrib3fvARB(attribs.orco.gl_index, \ - attribs.orco.array[index]); \ - } \ - for (b = 0; b < attribs.tottface; b++) { \ - MTFace *tf = &attribs.tface[b].array[a]; \ - glVertexAttrib2fvARB(attribs.tface[b].gl_index, tf->uv[vert]); \ - } \ - for (b = 0; b < attribs.totmcol; b++) { \ - MCol *cp = &attribs.mcol[b].array[a * 4 + vert]; \ - GLubyte col[4]; \ - col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; \ - glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, col); \ - } \ - if (attribs.tottang) { \ - float *tang = attribs.tang.array[a * 4 + vert]; \ - glVertexAttrib4fvARB(attribs.tang.gl_index, tang); \ - } \ + else \ + index = 0; \ + ccgdm_draw_attrib_vertex(&attribs, a, index, vert); \ } (void)0 totface = ccgSubSurf_getNumFaces(ss); @@ -1984,7 +2028,7 @@ static void ccgDM_drawMappedFacesMat(DerivedMesh *dm, int gridFaces = gridSize - 1; int edgeSize = ccgSubSurf_getEdgeSize(ss); DMFlagMat *faceFlags = ccgdm->faceFlags; - int a, b, i, numVerts, matnr, new_matnr, totface; + int a, i, numVerts, matnr, new_matnr, totface; CCG_key_top_level(&key, ss); ccgdm_pbvh_update(ccgdm); @@ -1992,31 +2036,11 @@ static void ccgDM_drawMappedFacesMat(DerivedMesh *dm, matnr = -1; #define PASSATTRIB(dx, dy, vert) { \ - if (attribs.totorco) { \ + if (attribs.totorco) \ index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize); \ - if (attribs.orco.gl_texco) \ - glTexCoord3fv(attribs.orco.array[index]); \ - else \ - glVertexAttrib3fvARB(attribs.orco.gl_index, \ - attribs.orco.array[index]); \ - } \ - for (b = 0; b < attribs.tottface; b++) { \ - MTFace *tf = &attribs.tface[b].array[a]; \ - if (attribs.tface[b].gl_texco) \ - glTexCoord2fv(tf->uv[vert]); \ - else \ - glVertexAttrib2fvARB(attribs.tface[b].gl_index, tf->uv[vert]); \ - } \ - for (b = 0; b < attribs.totmcol; b++) { \ - MCol *cp = &attribs.mcol[b].array[a * 4 + vert]; \ - GLubyte col[4]; \ - col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; \ - glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, col); \ - } \ - if (attribs.tottang) { \ - float *tang = attribs.tang.array[a * 4 + vert]; \ - glVertexAttrib4fvARB(attribs.tang.gl_index, tang); \ - } \ + else \ + index = 0; \ + ccgdm_draw_attrib_vertex(&attribs, a, index, vert); \ } (void)0 totface = ccgSubSurf_getNumFaces(ss); @@ -3183,9 +3207,6 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, /* reuse of ccgDM_getNumTessFaces is intentional here: subsurf polys are just created from tessfaces */ ccgdm->dm.getNumPolys = ccgDM_getNumTessFaces; - ccgdm->dm.getNumGrids = ccgDM_getNumGrids; - ccgdm->dm.getPBVH = ccgDM_getPBVH; - ccgdm->dm.getVert = ccgDM_getFinalVert; ccgdm->dm.getEdge = ccgDM_getFinalEdge; ccgdm->dm.getTessFace = ccgDM_getFinalFace; diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 22b0fe7bc24..ccbccac85cf 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -68,6 +68,9 @@ #include "BKE_node.h" #include "BKE_animsys.h" #include "BKE_colortools.h" +#include "BKE_scene.h" + +#include "RE_shader_ext.h" /* ****************** Mapping ******************* */ @@ -1436,3 +1439,27 @@ bool BKE_texture_dependsOnTime(const struct Tex *texture) } /* ------------------------------------------------------------------------- */ + +void BKE_texture_get_value(Scene *scene, Tex *texture, float *tex_co, TexResult *texres, bool use_color_management) +{ + int result_type; + bool do_color_manage = false; + + if (scene && use_color_management) { + do_color_manage = BKE_scene_check_color_management_enabled(scene); + } + + /* no node textures for now */ + result_type = multitex_ext_safe(texture, tex_co, texres, NULL, do_color_manage); + + /* if the texture gave an RGB value, we assume it didn't give a valid + * intensity, since this is in the context of modifiers don't use perceptual color conversion. + * if the texture didn't give an RGB value, copy the intensity across + */ + if (result_type & TEX_RGB) { + texres->tin = (1.0f / 3.0f) * (texres->tr + texres->tg + texres->tb); + } + else { + copy_v3_fl(&texres->tr, texres->tin); + } +} diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index b8711f6e5f6..d519b93f963 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -36,6 +36,7 @@ #include "MEM_guardedalloc.h" +#include "DNA_anim_types.h" #include "DNA_gpencil_types.h" #include "DNA_camera_types.h" #include "DNA_movieclip_types.h" @@ -53,6 +54,7 @@ #include "BLF_translation.h" +#include "BKE_fcurve.h" #include "BKE_global.h" #include "BKE_tracking.h" #include "BKE_movieclip.h" @@ -62,6 +64,8 @@ #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" +#include "RNA_access.h" + #include "raskter.h" #include "libmv-capi.h" @@ -212,7 +216,6 @@ void BKE_tracking_settings_init(MovieTracking *tracking) tracking->settings.default_algorithm_flag |= TRACK_ALGORITHM_FLAG_USE_BRUTE; tracking->settings.dist = 1; tracking->settings.object_distance = 1; - tracking->settings.reconstruction_success_threshold = 1e-3f; tracking->stabilization.scaleinf = 1.0f; tracking->stabilization.locinf = 1.0f; @@ -591,6 +594,7 @@ MovieTrackingTrack *BKE_tracking_track_add(MovieTracking *tracking, ListBase *tr track->frames_limit = settings->default_frames_limit; track->flag = settings->default_flag; track->algorithm_flag = settings->default_algorithm_flag; + track->weight = 1.0f; memset(&marker, 0, sizeof(marker)); marker.pos[0] = x; @@ -3264,23 +3268,6 @@ static int point_markers_correspondences_on_both_image(MovieTrackingPlaneTrack * return correspondence_index; } -/* TODO(sergey): Make it generic function available for everyone. */ -BLI_INLINE void mat3f_from_mat3d(float mat_float[3][3], double mat_double[3][3]) -{ - /* Keep it stupid simple for better data flow in CPU. */ - mat_float[0][0] = mat_double[0][0]; - mat_float[0][1] = mat_double[0][1]; - mat_float[0][2] = mat_double[0][2]; - - mat_float[1][0] = mat_double[1][0]; - mat_float[1][1] = mat_double[1][1]; - mat_float[1][2] = mat_double[1][2]; - - mat_float[2][0] = mat_double[2][0]; - mat_float[2][1] = mat_double[2][1]; - mat_float[2][2] = mat_double[2][2]; -} - /* NOTE: frame number should be in clip space, not scene space */ static void track_plane_from_existing_motion(MovieTrackingPlaneTrack *plane_track, int start_frame, int direction, bool retrack) @@ -3342,7 +3329,7 @@ static void track_plane_from_existing_motion(MovieTrackingPlaneTrack *plane_trac libmv_homography2DFromCorrespondencesEuc(x1, x2, num_correspondences, H_double); - mat3f_from_mat3d(H, H_double); + copy_m3_m3d(H, H_double); for (i = 0; i < 4; i++) { float vec[3] = {0.0f, 0.0f, 1.0f}, vec2[3]; @@ -3446,7 +3433,7 @@ void BKE_tracking_homography_between_two_quads(/*const*/ float reference_corners libmv_homography2DFromCorrespondencesEuc(x1, x2, 4, H_double); - mat3f_from_mat3d(H, H_double); + copy_m3_m3d(H, H_double); } /*********************** Camera solving *************************/ @@ -3473,9 +3460,6 @@ typedef struct MovieReconstructContext { TracksMap *tracks_map; - float success_threshold; - bool use_fallback_reconstruction; - int sfra, efra; } MovieReconstructContext; @@ -3488,7 +3472,7 @@ typedef struct ReconstructProgressData { } ReconstructProgressData; /* Create new libmv Tracks structure from blender's tracks list. */ -static struct libmv_Tracks *libmv_tracks_new(ListBase *tracksbase, int width, int height) +static struct libmv_Tracks *libmv_tracks_new(MovieClip *clip, ListBase *tracksbase, int width, int height) { int tracknr = 0; MovieTrackingTrack *track; @@ -3496,15 +3480,28 @@ static struct libmv_Tracks *libmv_tracks_new(ListBase *tracksbase, int width, in track = tracksbase->first; while (track) { + FCurve *weight_fcurve; int a = 0; + weight_fcurve = id_data_find_fcurve(&clip->id, track, &RNA_MovieTrackingTrack, + "weight", 0, NULL); + for (a = 0; a < track->markersnr; a++) { MovieTrackingMarker *marker = &track->markers[a]; if ((marker->flag & MARKER_DISABLED) == 0) { + float weight = track->weight; + + if (weight_fcurve) { + int scene_framenr = + BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr); + weight = evaluate_fcurve(weight_fcurve, scene_framenr); + } + libmv_tracksInsert(tracks, marker->framenr, tracknr, (marker->pos[0] + track->offset[0]) * width, - (marker->pos[1] + track->offset[1]) * height); + (marker->pos[1] + track->offset[1]) * height, + weight); } } @@ -3751,9 +3748,10 @@ bool BKE_tracking_reconstruction_check(MovieTracking *tracking, MovieTrackingObj * clip datablock, so editing this clip is safe during * reconstruction job is in progress. */ -MovieReconstructContext *BKE_tracking_reconstruction_context_new(MovieTracking *tracking, MovieTrackingObject *object, +MovieReconstructContext *BKE_tracking_reconstruction_context_new(MovieClip *clip, MovieTrackingObject *object, int keyframe1, int keyframe2, int width, int height) { + MovieTracking *tracking = &clip->tracking; MovieReconstructContext *context = MEM_callocN(sizeof(MovieReconstructContext), "MovieReconstructContext data"); MovieTrackingCamera *camera = &tracking->camera; ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object); @@ -3780,9 +3778,6 @@ MovieReconstructContext *BKE_tracking_reconstruction_context_new(MovieTracking * context->k2 = camera->k2; context->k3 = camera->k3; - context->success_threshold = tracking->settings.reconstruction_success_threshold; - context->use_fallback_reconstruction = tracking->settings.reconstruction_flag & TRACKING_USE_FALLBACK_RECONSTRUCTION; - context->tracks_map = tracks_map_new(context->object_name, context->is_camera, num_tracks, 0); track = tracksbase->first; @@ -3817,7 +3812,7 @@ MovieReconstructContext *BKE_tracking_reconstruction_context_new(MovieTracking * context->sfra = sfra; context->efra = efra; - context->tracks = libmv_tracks_new(tracksbase, width, height * aspy); + context->tracks = libmv_tracks_new(clip, tracksbase, width, height * aspy); context->keyframe1 = keyframe1; context->keyframe2 = keyframe2; context->refine_flags = reconstruct_refine_intrinsics_get_flags(tracking, object); @@ -3877,9 +3872,6 @@ static void reconstructionOptionsFromContext(libmv_ReconstructionOptions *recons reconstruction_options->keyframe2 = context->keyframe2; reconstruction_options->refine_intrinsics = context->refine_flags; - - reconstruction_options->success_threshold = context->success_threshold; - reconstruction_options->use_fallback_reconstruction = context->use_fallback_reconstruction; } /* Solve camera/object motion and reconstruct 3D markers position diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c index a69df62f505..64470542844 100644 --- a/source/blender/blenkernel/intern/unit.c +++ b/source/blender/blenkernel/intern/unit.c @@ -95,11 +95,6 @@ typedef struct bUnitDef { #define B_UNIT_DEF_SUPPRESS 1 /* Use for units that are not used enough to be translated into for common use */ #define B_UNIT_DEF_TENTH 2 /* Display a unit even if its value is 0.1, eg 0.1mm instead of 100um */ -/* workaround encoding issue with "µm", bug [#36090] */ -#define B_UNIT_CHAR_MICRO "\xb5" -#define UM B_UNIT_CHAR_MICRO"m" -#define US B_UNIT_CHAR_MICRO"s" - /* define a single unit */ typedef struct bUnitCollection { struct bUnitDef *units; @@ -121,7 +116,7 @@ static struct bUnitDef buMetricLenDef[] = { {"decimeter", "decimeters", "dm", NULL, "10 Centimeters", UN_SC_DM, 0.0, B_UNIT_DEF_SUPPRESS}, {"centimeter", "centimeters", "cm", NULL, "Centimeters", UN_SC_CM, 0.0, B_UNIT_DEF_NONE}, {"millimeter", "millimeters", "mm", NULL, "Millimeters", UN_SC_MM, 0.0, B_UNIT_DEF_NONE | B_UNIT_DEF_TENTH}, - {"micrometer", "micrometers", UM, "um", "Micrometers", UN_SC_UM, 0.0, B_UNIT_DEF_NONE}, // micron too? + {"micrometer", "micrometers", "µm", "um", "Micrometers", UN_SC_UM, 0.0, B_UNIT_DEF_NONE}, /* These get displayed because of float precision problems in the transform header, * could work around, but for now probably people wont use these */ @@ -154,7 +149,7 @@ static struct bUnitDef buMetricAreaDef[] = { {"square decimeter", "square decimetees", "dm²", "dm2", "Square Decimeters", UN_SC_DM * UN_SC_DM, 0.0, B_UNIT_DEF_SUPPRESS}, {"square centimeter", "square centimeters", "cm²", "cm2", "Square Centimeters", UN_SC_CM * UN_SC_CM, 0.0, B_UNIT_DEF_NONE}, {"square millimeter", "square millimeters", "mm²", "mm2", "Square Millimeters", UN_SC_MM * UN_SC_MM, 0.0, B_UNIT_DEF_NONE | B_UNIT_DEF_TENTH}, - {"square micrometer", "square micrometers", UM"²", "um2", "Square Micrometers", UN_SC_UM * UN_SC_UM, 0.0, B_UNIT_DEF_NONE}, + {"square micrometer", "square micrometers", "µm²", "um2", "Square Micrometers", UN_SC_UM * UN_SC_UM, 0.0, B_UNIT_DEF_NONE}, {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; static struct bUnitCollection buMetricAreaCollection = {buMetricAreaDef, 3, 0, sizeof(buMetricAreaDef) / sizeof(bUnitDef)}; @@ -180,7 +175,7 @@ static struct bUnitDef buMetricVolDef[] = { {"cubic decimeter", "cubic decimeters", "dm³", "dm3", "Cubic Decimeters", UN_SC_DM * UN_SC_DM * UN_SC_DM, 0.0, B_UNIT_DEF_SUPPRESS}, {"cubic centimeter", "cubic centimeters", "cm³", "cm3", "Cubic Centimeters", UN_SC_CM * UN_SC_CM * UN_SC_CM, 0.0, B_UNIT_DEF_NONE}, {"cubic millimeter", "cubic millimeters", "mm³", "mm3", "Cubic Millimeters", UN_SC_MM * UN_SC_MM * UN_SC_MM, 0.0, B_UNIT_DEF_NONE | B_UNIT_DEF_TENTH}, - {"cubic micrometer", "cubic micrometers", UM"³", "um3", "Cubic Micrometers", UN_SC_UM * UN_SC_UM * UN_SC_UM, 0.0, B_UNIT_DEF_NONE}, + {"cubic micrometer", "cubic micrometers", "µm³", "um3", "Cubic Micrometers", UN_SC_UM * UN_SC_UM * UN_SC_UM, 0.0, B_UNIT_DEF_NONE}, {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; static struct bUnitCollection buMetricVolCollection = {buMetricVolDef, 3, 0, sizeof(buMetricVolDef) / sizeof(bUnitDef)}; @@ -258,7 +253,7 @@ static struct bUnitDef buNaturalTimeDef[] = { {"minute", "minutes", "min", "m", "Minutes", 60.0, 0.0, B_UNIT_DEF_NONE}, {"second", "seconds", "sec", "s", "Seconds", 1.0, 0.0, B_UNIT_DEF_NONE}, /* base unit */ {"millisecond", "milliseconds", "ms", NULL, "Milliseconds", 0.001, 0.0, B_UNIT_DEF_NONE}, - {"microsecond", "microseconds", US, "us", "Microseconds", 0.000001, 0.0, B_UNIT_DEF_NONE}, + {"microsecond", "microseconds", "µs", "us", "Microseconds", 0.000001, 0.0, B_UNIT_DEF_NONE}, {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; static struct bUnitCollection buNaturalTimeCollection = {buNaturalTimeDef, 3, 0, sizeof(buNaturalTimeDef) / sizeof(bUnitDef)}; @@ -278,7 +273,7 @@ static struct bUnitDef buCameraLenDef[] = { {"decimeter", "decimeters", "dm", NULL, "10 Centimeters", UN_SC_HM, 0.0, B_UNIT_DEF_SUPPRESS}, {"centimeter", "centimeters", "cm", NULL, "Centimeters", UN_SC_DAM, 0.0, B_UNIT_DEF_SUPPRESS}, {"millimeter", "millimeters", "mm", NULL, "Millimeters", UN_SC_M, 0.0, B_UNIT_DEF_NONE}, - {"micrometer", "micrometers", UM, "um", "Micrometers", UN_SC_MM, 0.0, B_UNIT_DEF_SUPPRESS}, // micron too? + {"micrometer", "micrometers", "µm", "um", "Micrometers", UN_SC_MM, 0.0, B_UNIT_DEF_SUPPRESS}, {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; static struct bUnitCollection buCameraLenCollection = {buCameraLenDef, 3, 0, sizeof(buCameraLenDef) / sizeof(bUnitDef)}; @@ -614,9 +609,10 @@ int bUnit_ReplaceString(char *str, int len_max, const char *str_prev, double sca int i; char *ch = str; - for (i = 0; (i >= len_max || *ch == '\0'); i++, ch++) + for (i = 0; (i < len_max) && (*ch != '\0'); i++, ch++) { if ((*ch >= 'A') && (*ch <= 'Z')) *ch += ('a' - 'A'); + } } for (unit = usys->units; unit->name; unit++) { diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index 206f829eaa8..c5a932e4173 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -92,8 +92,6 @@ World *add_world(Main *bmain, const char *name) wrld->zeng = 0.01f; wrld->zenb = 0.01f; wrld->skytype = 0; - wrld->stardist = 15.0f; - wrld->starsize = 2.0f; wrld->exp = 0.0f; wrld->exposure = wrld->range = 1.0f; diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c index 538c98cc899..bcf5e712eff 100644 --- a/source/blender/blenkernel/intern/writeffmpeg.c +++ b/source/blender/blenkernel/intern/writeffmpeg.c @@ -295,17 +295,7 @@ static const char **get_file_extensions(int format) } case FFMPEG_OGG: { - static const char *rv[] = { ".ogg", ".ogv", NULL }; - return rv; - } - case FFMPEG_MP3: - { - static const char *rv[] = { ".mp3", NULL }; - return rv; - } - case FFMPEG_WAV: - { - static const char *rv[] = { ".wav", NULL }; + static const char *rv[] = { ".ogv", ".ogg", NULL }; return rv; } default: @@ -875,12 +865,6 @@ static int start_ffmpeg_impl(struct RenderData *rd, int rectx, int recty, Report case FFMPEG_FLV: fmt->video_codec = CODEC_ID_FLV1; break; - case FFMPEG_MP3: - fmt->audio_codec = CODEC_ID_MP3; - /* fall-through */ - case FFMPEG_WAV: - fmt->video_codec = CODEC_ID_NONE; - break; case FFMPEG_MPEG4: default: fmt->video_codec = CODEC_ID_MPEG4; @@ -1254,9 +1238,7 @@ void BKE_ffmpeg_property_del(RenderData *rd, void *type, void *prop_) group = IDP_GetPropertyFromGroup(rd->ffcodecdata.properties, type); if (group && prop) { - IDP_RemFromGroup(group, prop); - IDP_FreeProperty(prop); - MEM_freeN(prop); + IDP_FreeFromGroup(group, prop); } } |