diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2016-07-05 10:41:42 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2016-07-05 10:53:24 +0300 |
commit | 4e95617769c4c951a0f921feb30bc4312f86ce58 (patch) | |
tree | 7bddc6e1dafed09ee78db18cd18257c98eea683d /source | |
parent | 73140ca2834f41ee118275fd1df0d492a554f7e8 (diff) | |
parent | 39ae324918176a1a94de0c6be4466fdffa2fe711 (diff) |
Merge branch 'master' into strand_editmode
Diffstat (limited to 'source')
179 files changed, 5493 insertions, 3019 deletions
diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h index 7bd3ca88076..07db2217bac 100644 --- a/source/blender/blenkernel/BKE_bvhutils.h +++ b/source/blender/blenkernel/BKE_bvhutils.h @@ -43,9 +43,11 @@ struct BMEditMesh; struct MVert; struct MFace; +typedef struct LinkNode BVHCache; + /** -* struct that kepts basic information about a BVHTree build from a editmesh -*/ + * struct that kepts basic information about a BVHTree build from a editmesh + */ typedef struct BVHTreeFromEditMesh { struct BVHTree *tree; @@ -54,11 +56,13 @@ typedef struct BVHTreeFromEditMesh { BVHTree_RayCastCallback raycast_callback; BVHTree_NearestToRayCallback nearest_to_ray_callback; + struct BMEditMesh *em; + /* radius for raycast */ float sphere_radius; /* Private data */ - struct BMEditMesh *em; + bool cached; } BVHTreeFromEditMesh; @@ -118,6 +122,14 @@ BVHTree *bvhtree_from_mesh_verts_ex( const bool vert_allocated, const BLI_bitmap *mask, int verts_num_active, float epsilon, int tree_type, int axis); +BVHTree *bvhtree_from_editmesh_edges( + BVHTreeFromEditMesh *data, struct BMEditMesh *em, + float epsilon, int tree_type, int axis); +BVHTree *bvhtree_from_editmesh_edges_ex( + BVHTreeFromEditMesh *data, struct BMEditMesh *em, + const BLI_bitmap *edges_mask, int edges_num_active, + float epsilon, int tree_type, int axis); + BVHTree *bvhtree_from_mesh_edges( struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, int tree_type, int axis); @@ -133,12 +145,12 @@ BVHTree *bvhtree_from_mesh_faces_ex( float epsilon, int tree_type, int axis); BVHTree *bvhtree_from_editmesh_looptri( - BVHTreeFromEditMesh *data, struct BMEditMesh *em, float epsilon, - int tree_type, int axis); + BVHTreeFromEditMesh *data, struct BMEditMesh *em, + float epsilon, int tree_type, int axis, BVHCache **bvhCache); BVHTree *bvhtree_from_editmesh_looptri_ex( BVHTreeFromEditMesh *data, struct BMEditMesh *em, const BLI_bitmap *mask, int looptri_num_active, - float epsilon, int tree_type, int axis); + float epsilon, int tree_type, int axis, BVHCache **bvhCache); BVHTree *bvhtree_from_mesh_looptri( struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, int tree_type, int axis); @@ -165,9 +177,7 @@ float bvhtree_ray_tri_intersection( float bvhtree_sphereray_tri_intersection( const BVHTreeRay *ray, float radius, const float m_dist, const float v0[3], const float v1[3], const float v2[3]); -float nearest_point_in_tri_surface_squared( - const float v0[3], const float v1[3], const float v2[3], - const float p[3], int *v, int *e, float nearest[3]); + /** * BVHCache @@ -179,9 +189,10 @@ enum { BVHTREE_FROM_EDGES = 1, BVHTREE_FROM_FACES = 2, BVHTREE_FROM_LOOPTRI = 3, + + BVHTREE_FROM_EM_LOOPTRI = 4, }; -typedef struct LinkNode BVHCache; BVHTree *bvhcache_find(BVHCache *cache, int type); bool bvhcache_has_tree(const BVHCache *cache, const BVHTree *tree); @@ -189,4 +200,5 @@ void bvhcache_insert(BVHCache **cache_p, BVHTree *tree, int type); void bvhcache_init(BVHCache **cache_p); void bvhcache_free(BVHCache **cache_p); + #endif diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h index 23b3128f328..659884d96a4 100644 --- a/source/blender/blenkernel/BKE_curve.h +++ b/source/blender/blenkernel/BKE_curve.h @@ -150,6 +150,16 @@ void BKE_nurb_minmax(struct Nurb *nu, bool use_radius, float min[3], float max[3 void BKE_nurb_makeFaces(struct Nurb *nu, float *coord_array, int rowstride, int resolu, int resolv); void BKE_nurb_makeCurve(struct Nurb *nu, float *coord_array, float *tilt_array, float *radius_array, float *weight_array, int resolu, int stride); +unsigned int BKE_curve_calc_coords_axis_len( + const unsigned int bezt_array_len, const unsigned int resolu, + const bool is_cyclic, const bool use_cyclic_duplicate_endpoint); +void BKE_curve_calc_coords_axis( + const struct BezTriple *bezt_array, const unsigned int bezt_array_len, const unsigned int resolu, + const bool is_cyclic, const bool use_cyclic_duplicate_endpoint, + /* array params */ + const unsigned int axis, const unsigned int stride, + float *r_points); + void BKE_nurb_knot_calc_u(struct Nurb *nu); void BKE_nurb_knot_calc_v(struct Nurb *nu); diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h index 26a40597ca8..5ef5a807f63 100644 --- a/source/blender/blenkernel/BKE_global.h +++ b/source/blender/blenkernel/BKE_global.h @@ -178,6 +178,7 @@ enum { #define G_FILE_MESH_COMPAT (1 << 26) /* On write, restore paths after editing them (G_FILE_RELATIVE_REMAP) */ #define G_FILE_SAVE_COPY (1 << 27) +#define G_FILE_GLSL_NO_ENV_LIGHTING (1 << 28) #define G_FILE_FLAGS_RUNTIME (G_FILE_NO_UI | G_FILE_RELATIVE_REMAP | G_FILE_MESH_COMPAT | G_FILE_SAVE_COPY) diff --git a/source/blender/blenkernel/BKE_library_query.h b/source/blender/blenkernel/BKE_library_query.h index c89dce99caa..3a2b49f911c 100644 --- a/source/blender/blenkernel/BKE_library_query.h +++ b/source/blender/blenkernel/BKE_library_query.h @@ -53,7 +53,7 @@ enum { enum { IDWALK_RET_NOP = 0, - IDWALK_RET_STOP_ITER = 1 << 0, /* Completly top iteration. */ + IDWALK_RET_STOP_ITER = 1 << 0, /* Completly stop iteration. */ IDWALK_RET_STOP_RECURSION = 1 << 1, /* Stop recursion, that is, do not loop over ID used by current one. */ }; @@ -76,4 +76,6 @@ void BKE_library_update_ID_link_user(struct ID *id_dst, struct ID *id_src, const int BKE_library_ID_use_ID(struct ID *id_user, struct ID *id_used); +bool BKE_library_ID_is_indirectly_used(struct Main *bmain, void *idv); + #endif /* __BKE_LIBRARY_QUERY_H__ */ diff --git a/source/blender/blenkernel/BKE_library_remap.h b/source/blender/blenkernel/BKE_library_remap.h index e85a3e60751..754005276f0 100644 --- a/source/blender/blenkernel/BKE_library_remap.h +++ b/source/blender/blenkernel/BKE_library_remap.h @@ -56,7 +56,9 @@ void BKE_libblock_remap( struct Main *bmain, void *old_idv, void *new_idv, const short remap_flags) ATTR_NONNULL(1, 2); -void BKE_libblock_unlink(struct Main *bmain, void *idv, const bool do_flag_never_null) ATTR_NONNULL(); +void BKE_libblock_unlink( + struct Main *bmain, void *idv, + const bool do_flag_never_null, const bool do_skip_indirect) ATTR_NONNULL(); void BKE_libblock_relink_ex(void *idv, void *old_idv, void *new_idv, const bool us_min_never_null) ATTR_NONNULL(1); @@ -73,4 +75,4 @@ void BKE_library_callback_remap_editor_id_reference_set(BKE_library_remap_editor } #endif -#endif /* __BKE_LIBRARY_REMAP_H__ */
\ No newline at end of file +#endif /* __BKE_LIBRARY_REMAP_H__ */ diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 9330f41d19a..2cc28ca837f 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -32,6 +32,7 @@ */ struct ID; +struct BMeshCreateParams; struct BoundBox; struct EdgeHash; struct ListBase; @@ -69,7 +70,9 @@ extern "C" { /* *** mesh.c *** */ -struct BMesh *BKE_mesh_to_bmesh(struct Mesh *me, struct Object *ob, const bool add_key_index); +struct BMesh *BKE_mesh_to_bmesh( + struct Mesh *me, struct Object *ob, + const bool add_key_index, const struct BMeshCreateParams *params); int poly_find_loop_from_vert( const struct MPoly *poly, diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 038993777cf..b59618f46b2 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -635,6 +635,7 @@ void b_bone_spline_setup(bPoseChannel *pchan, int rest, Mat4 result_array[MAX_BB { const float circle_factor = length * (cubic_tangent_factor_circle_v3(h1, h2) / 0.75f); + const float hlength1 = bone->ease1 * circle_factor; const float hlength2 = bone->ease2 * circle_factor; diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index e0277c38e61..264d87b86f3 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -590,6 +590,77 @@ BVHTree *bvhtree_from_mesh_verts_ex( /** \name Edge Builder * \{ */ +static BVHTree *bvhtree_from_editmesh_edges_create_tree( + float epsilon, int tree_type, int axis, + BMEditMesh *em, const int edges_num, + const BLI_bitmap *edges_mask, int edges_num_active) +{ + BVHTree *tree = NULL; + int i; + BM_mesh_elem_table_ensure(em->bm, BM_EDGE); + if (edges_mask) { + BLI_assert(IN_RANGE_INCL(edges_num_active, 0, edges_num)); + } + else { + edges_num_active = edges_num; + } + + tree = BLI_bvhtree_new(edges_num_active, epsilon, tree_type, axis); + + if (tree) { + BMIter iter; + BMEdge *eed; + BM_ITER_MESH_INDEX (eed, &iter, em->bm, BM_EDGES_OF_MESH, i) { + if (edges_mask && !BLI_BITMAP_TEST_BOOL(edges_mask, i)) { + continue; + } + float co[2][3]; + copy_v3_v3(co[0], eed->v1->co); + copy_v3_v3(co[1], eed->v2->co); + + BLI_bvhtree_insert(tree, i, co[0], 2); + } + BLI_assert(BLI_bvhtree_get_size(tree) == edges_num_active); + BLI_bvhtree_balance(tree); + } + + return tree; +} + +/* Builds a bvh tree where nodes are the edges of the given em */ +BVHTree *bvhtree_from_editmesh_edges_ex( + BVHTreeFromEditMesh *data, BMEditMesh *em, + const BLI_bitmap *edges_mask, int edges_num_active, + float epsilon, int tree_type, int axis) +{ + int edge_num = em->bm->totedge; + + BVHTree *tree = bvhtree_from_editmesh_edges_create_tree( + epsilon, tree_type, axis, + em, edge_num, edges_mask, edges_num_active); + + if (tree) { + memset(data, 0, sizeof(*data)); + data->tree = tree; + data->em = em; + data->nearest_callback = NULL; /* TODO */ + data->raycast_callback = NULL; /* TODO */ + /* TODO: not urgent however since users currently define own callbacks */ + data->nearest_to_ray_callback = NULL; + } + + return tree; +} +BVHTree *bvhtree_from_editmesh_edges( + BVHTreeFromEditMesh *data, BMEditMesh *em, + float epsilon, int tree_type, int axis) +{ + return bvhtree_from_editmesh_edges_ex( + data, em, + NULL, -1, + epsilon, tree_type, axis); +} + /* Builds a bvh tree where nodes are the edges of the given dm */ BVHTree *bvhtree_from_mesh_edges( BVHTreeFromMesh *data, DerivedMesh *dm, @@ -968,17 +1039,37 @@ static void bvhtree_from_mesh_looptri_setup_data( BVHTree *bvhtree_from_editmesh_looptri_ex( BVHTreeFromEditMesh *data, BMEditMesh *em, const BLI_bitmap *looptri_mask, int looptri_num_active, - float epsilon, int tree_type, int axis) + float epsilon, int tree_type, int axis, BVHCache **bvhCache) { /* BMESH specific check that we have tessfaces, - * we _could_ tessellate here but rather not - campbell - * - * this assert checks we have tessfaces, - * if not caller should use DM_ensure_tessface() */ + * we _could_ tessellate here but rather not - campbell */ - BVHTree *tree = bvhtree_from_editmesh_looptri_create_tree( - epsilon, tree_type, axis, - em, em->tottri, looptri_mask, looptri_num_active); + BVHTree *tree; + if (bvhCache) { + BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_READ); + tree = bvhcache_find(*bvhCache, BVHTREE_FROM_EM_LOOPTRI); + BLI_rw_mutex_unlock(&cache_rwlock); + if (tree == NULL) { + BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE); + tree = bvhcache_find(*bvhCache, BVHTREE_FROM_EM_LOOPTRI); + if (tree == NULL) { + tree = bvhtree_from_editmesh_looptri_create_tree( + epsilon, tree_type, axis, + em, em->tottri, looptri_mask, looptri_num_active); + if (tree) { + /* Save on cache for later use */ + /* printf("BVHTree built and saved on cache\n"); */ + bvhcache_insert(bvhCache, tree, BVHTREE_FROM_EM_LOOPTRI); + } + } + BLI_rw_mutex_unlock(&cache_rwlock); + } + } + else { + tree = bvhtree_from_editmesh_looptri_create_tree( + epsilon, tree_type, axis, + em, em->tottri, looptri_mask, looptri_num_active); + } if (tree) { data->tree = tree; @@ -987,17 +1078,18 @@ BVHTree *bvhtree_from_editmesh_looptri_ex( data->nearest_to_ray_callback = NULL; data->sphere_radius = 0.0f; data->em = em; + data->cached = bvhCache != NULL; } return tree; } BVHTree *bvhtree_from_editmesh_looptri( BVHTreeFromEditMesh *data, BMEditMesh *em, - float epsilon, int tree_type, int axis) + float epsilon, int tree_type, int axis, BVHCache **bvhCache) { return bvhtree_from_editmesh_looptri_ex( data, em, NULL, -1, - epsilon, tree_type, axis); + epsilon, tree_type, axis, bvhCache); } /** @@ -1045,6 +1137,9 @@ BVHTree *bvhtree_from_mesh_looptri( tree = bvhcache_find(dm->bvhCache, BVHTREE_FROM_LOOPTRI); if (tree == NULL) { int looptri_num = dm->getNumLoopTri(dm); + + /* this assert checks we have looptris, + * if not caller should use DM_ensure_looptri() */ BLI_assert(!(looptri_num == 0 && dm->getNumPolys(dm) != 0)); tree = bvhtree_from_mesh_looptri_create_tree( @@ -1102,7 +1197,9 @@ BVHTree *bvhtree_from_mesh_looptri_ex( void free_bvhtree_from_editmesh(struct BVHTreeFromEditMesh *data) { if (data->tree) { - BLI_bvhtree_free(data->tree); + if (!data->cached) { + BLI_bvhtree_free(data->tree); + } memset(data, 0, sizeof(*data)); } } diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index c1f1f0128f5..2932939b208 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -1322,7 +1322,7 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, const ColorManagedViewSettings * .cm_processor = cm_processor, .display_buffer = display_buffer, .ycc_mode = ycc_mode, .bin_lum = bin_lum, .bin_r = bin_r, .bin_g = bin_g, .bin_b = bin_b, .bin_a = bin_a, }; - ScopesUpdateDataChunk data_chunk = {0}; + ScopesUpdateDataChunk data_chunk = {{0}}; INIT_MINMAX(data_chunk.min, data_chunk.max); BLI_task_parallel_range_finalize(0, ibuf->y, &data, &data_chunk, sizeof(data_chunk), diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index a591d536b43..c88b24aa381 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -2195,7 +2195,7 @@ static void actcon_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintT } else if (cob->type == CONSTRAINT_OBTYPE_BONE) { Object workob; - bPose pose = {0}; + bPose pose = {{0}}; bPoseChannel *pchan, *tchan; /* make a copy of the bone of interest in the temp pose before evaluating action, so that it can get set diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index dec6ff22360..c52b0f6a884 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -1384,6 +1384,71 @@ void BKE_nurb_makeCurve(Nurb *nu, float *coord_array, float *tilt_array, float * MEM_freeN(basisu); } +/** + * Calculate the length for arrays filled in by #BKE_curve_calc_coords_axis. + */ +unsigned int BKE_curve_calc_coords_axis_len( + const unsigned int bezt_array_len, const unsigned int resolu, + const bool is_cyclic, const bool use_cyclic_duplicate_endpoint) +{ + const unsigned int segments = bezt_array_len - (is_cyclic ? 0 : 1); + const unsigned int points_len = (segments * resolu) + (is_cyclic ? (use_cyclic_duplicate_endpoint) : 1); + return points_len; +} + +/** + * Calcualte an array for the entire curve (cyclic or non-cyclic). + * \note Call for each axis. + * + * \param use_cyclic_duplicate_endpoint: Duplicate values at the beginning & end of the array. + */ +void BKE_curve_calc_coords_axis( + const BezTriple *bezt_array, const unsigned int bezt_array_len, const unsigned int resolu, + const bool is_cyclic, const bool use_cyclic_duplicate_endpoint, + /* array params */ + const unsigned int axis, const unsigned int stride, + float *r_points) +{ + const unsigned int points_len = BKE_curve_calc_coords_axis_len( + bezt_array_len, resolu, is_cyclic, use_cyclic_duplicate_endpoint); + float *r_points_offset = r_points; + + const unsigned int resolu_stride = resolu * stride; + const unsigned int bezt_array_last = bezt_array_len - 1; + + for (unsigned int i = 0; i < bezt_array_last; i++) { + const BezTriple *bezt_curr = &bezt_array[i]; + const BezTriple *bezt_next = &bezt_array[i + 1]; + BKE_curve_forward_diff_bezier( + bezt_curr->vec[1][axis], bezt_curr->vec[2][axis], + bezt_next->vec[0][axis], bezt_next->vec[1][axis], + r_points_offset, (int)resolu, stride); + r_points_offset = POINTER_OFFSET(r_points_offset, resolu_stride); + } + + if (is_cyclic) { + const BezTriple *bezt_curr = &bezt_array[bezt_array_last]; + const BezTriple *bezt_next = &bezt_array[0]; + BKE_curve_forward_diff_bezier( + bezt_curr->vec[1][axis], bezt_curr->vec[2][axis], + bezt_next->vec[0][axis], bezt_next->vec[1][axis], + r_points_offset, (int)resolu, stride); + r_points_offset = POINTER_OFFSET(r_points_offset, resolu_stride); + if (use_cyclic_duplicate_endpoint) { + *r_points_offset = *r_points; + r_points_offset = POINTER_OFFSET(r_points_offset, stride); + } + } + else { + float *r_points_last = POINTER_OFFSET(r_points, bezt_array_last * resolu_stride); + *r_points_last = bezt_array[bezt_array_last].vec[1][axis]; + r_points_offset = POINTER_OFFSET(r_points_offset, stride); + } + + BLI_assert(POINTER_OFFSET(r_points, points_len * stride) == r_points_offset); + UNUSED_VARS_NDEBUG(points_len); +} + /* forward differencing method for bezier curve */ void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride) { diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 6207217f2c7..2c596ea68f9 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -3830,7 +3830,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, const float brush_radius = brush->paint_distance * surface->radius_scale; int numOfVerts; int ii; - Bounds3D mesh_bb = {0}; + Bounds3D mesh_bb = {{0}}; VolumeGrid *grid = bData->grid; dm = CDDM_copy(brush->dm); @@ -4100,7 +4100,7 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, const float range = solidradius + smooth; - Bounds3D part_bb = {0}; + Bounds3D part_bb = {{0}}; if (psys->totpart < 1) return 1; diff --git a/source/blender/blenkernel/intern/editstrands.c b/source/blender/blenkernel/intern/editstrands.c index a2ae106249a..23b17c77935 100644 --- a/source/blender/blenkernel/intern/editstrands.c +++ b/source/blender/blenkernel/intern/editstrands.c @@ -183,7 +183,8 @@ BMesh *BKE_editstrands_particles_to_bmesh(Object *ob, ParticleSystem *psys) const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_PSYS(psys); BMesh *bm; - bm = BM_mesh_create(&allocsize); + bm = BM_mesh_create(&allocsize, + &((struct BMeshCreateParams){.use_toolflags = false,})); if (psmd && psmd->dm_final) { DM_ensure_tessface(psmd->dm_final); @@ -225,7 +226,8 @@ BMesh *BKE_editstrands_mesh_to_bmesh(Object *ob, Mesh *me) BMesh *bm; struct BMeshFromMeshParams params = {0}; - bm = BM_mesh_create(&allocsize); + bm = BM_mesh_create(&allocsize, + &((struct BMeshCreateParams){.use_toolflags = false,})); params.use_shapekey = true; params.active_shapekey = ob->shapenr; diff --git a/source/blender/blenkernel/intern/library_query.c b/source/blender/blenkernel/intern/library_query.c index be3dde2753a..8373ad0123f 100644 --- a/source/blender/blenkernel/intern/library_query.c +++ b/source/blender/blenkernel/intern/library_query.c @@ -865,3 +865,53 @@ int BKE_library_ID_use_ID(ID *id_user, ID *id_used) return iter.count; } + + +static int foreach_libblock_check_indirect_usage_callback( + void *user_data, ID *UNUSED(id_self), ID **id_p, int UNUSED(cb_flag)) +{ + IDUsersIter *iter = user_data; + + if (*id_p && (*id_p == iter->id)) { + iter->count++; + return IDWALK_RET_STOP_ITER; + } + + return IDWALK_RET_NOP; +} + +/** + * Check wether given ID is used indirectly (i.e. by another linked ID). + */ +bool BKE_library_ID_is_indirectly_used(Main *bmain, void *idv) +{ + IDUsersIter iter; + ListBase *lb_array[MAX_LIBARRAY]; + int i = set_listbasepointers(bmain, lb_array); + + iter.id = idv; + iter.count = 0; + while (i--) { + ID *id_curr = lb_array[i]->first; + + for (; id_curr; id_curr = id_curr->next) { + if (!id_curr->lib) { + continue; + } + + iter.curr_id = id_curr; + BKE_library_foreach_ID_link( + id_curr, foreach_libblock_check_indirect_usage_callback, &iter, IDWALK_NOP); + + if (iter.count) { + break; + } + } + if (iter.count) { + break; + } + } + + return (iter.count != 0); +} + diff --git a/source/blender/blenkernel/intern/library_remap.c b/source/blender/blenkernel/intern/library_remap.c index 4bde0752ef3..81543fad0fe 100644 --- a/source/blender/blenkernel/intern/library_remap.c +++ b/source/blender/blenkernel/intern/library_remap.c @@ -163,19 +163,23 @@ static int foreach_libblock_remap_callback(void *user_data, ID *UNUSED(id_self), } if (*id_p && (*id_p == old_id)) { + const bool is_indirect = (id->lib != NULL); + const bool skip_indirect = (id_remap_data->flag & ID_REMAP_SKIP_INDIRECT_USAGE) != 0; /* Note: proxy usage implies LIB_TAG_EXTERN, so on this aspect it is direct, * on the other hand since they get reset to lib data on file open/reload it is indirect too... * Edit Mode is also a 'skip direct' case. */ const bool is_obj = (GS(id->name) == ID_OB); const bool is_proxy = (is_obj && (((Object *)id)->proxy || ((Object *)id)->proxy_group)); const bool is_obj_editmode = (is_obj && BKE_object_is_in_editmode((Object *)id)); - /* Note that indirect data from same file as processed ID is **not** considered indirect! */ - const bool is_indirect = ((id->lib != NULL) && (id->lib != old_id->lib)); - const bool skip_indirect = (id_remap_data->flag & ID_REMAP_SKIP_INDIRECT_USAGE) != 0; const bool is_never_null = ((cb_flag & IDWALK_NEVER_NULL) && (new_id == NULL) && (id_remap_data->flag & ID_REMAP_FORCE_NEVER_NULL_USAGE) == 0); const bool skip_never_null = (id_remap_data->flag & ID_REMAP_SKIP_NEVER_NULL_USAGE) != 0; +#ifdef DEBUG_PRINT + printf("In %s: Remapping %s (%p) to %s (%p) (skip_indirect: %d)\n", + id->name, old_id->name, old_id, new_id ? new_id->name : "<NONE>", new_id, skip_indirect); +#endif + if ((id_remap_data->flag & ID_REMAP_FLAG_NEVER_NULL_USAGE) && (cb_flag & IDWALK_NEVER_NULL)) { id->tag |= LIB_TAG_DOIT; } @@ -185,11 +189,14 @@ static int foreach_libblock_remap_callback(void *user_data, ID *UNUSED(id_self), (is_obj_editmode && (((Object *)id)->data == *id_p)) || (skip_indirect && (is_proxy || is_indirect))) { - if (is_never_null || is_proxy || is_obj_editmode) { + if (is_indirect) { + id_remap_data->skipped_indirect++; + } + else if (is_never_null || is_proxy || is_obj_editmode) { id_remap_data->skipped_direct++; } else { - id_remap_data->skipped_indirect++; + BLI_assert(0); } if (cb_flag & IDWALK_USER) { id_remap_data->skipped_refcounted++; @@ -394,7 +401,7 @@ void BKE_libblock_remap_locked( if (old_ob->flag & OB_FROMGROUP) { /* Note that for Scene's BaseObject->flag, either we: * - unlinked old_ob (i.e. new_ob is NULL), in which case scenes' bases have been removed already. - * - remaped old_ob by new_ob, in which case scenes' bases are still valid as is. + * - remapped old_ob by new_ob, in which case scenes' bases are still valid as is. * So in any case, no need to update them here. */ if (BKE_group_object_find(NULL, old_ob) == NULL) { old_ob->flag &= ~OB_FROMGROUP; @@ -462,9 +469,10 @@ void BKE_libblock_remap(Main *bmain, void *old_idv, void *new_idv, const short r * \param do_flag_never_null: If true, all IDs using \a idv in a 'non-NULL' way are flagged by \a LIB_TAG_DOIT flag * (quite obviously, 'non-NULL' usages can never be unlinked by this function...). */ -void BKE_libblock_unlink(Main *bmain, void *idv, const bool do_flag_never_null) +void BKE_libblock_unlink(Main *bmain, void *idv, const bool do_flag_never_null, const bool do_skip_indirect) { - const short remap_flags = ID_REMAP_SKIP_INDIRECT_USAGE | (do_flag_never_null ? ID_REMAP_FLAG_NEVER_NULL_USAGE : 0); + const short remap_flags = (do_skip_indirect ? ID_REMAP_SKIP_INDIRECT_USAGE : 0) | + (do_flag_never_null ? ID_REMAP_FLAG_NEVER_NULL_USAGE : 0); BKE_main_lock(bmain); @@ -710,7 +718,7 @@ void BKE_libblock_free_us(Main *bmain, void *idv) /* test users */ } if (id->us == 0) { - BKE_libblock_unlink(bmain, id, false); + BKE_libblock_unlink(bmain, id, false, false); BKE_libblock_free(bmain, id); } diff --git a/source/blender/blenkernel/intern/mball_tessellate.c b/source/blender/blenkernel/intern/mball_tessellate.c index e8418e876bb..2068854421f 100644 --- a/source/blender/blenkernel/intern/mball_tessellate.c +++ b/source/blender/blenkernel/intern/mball_tessellate.c @@ -1159,7 +1159,7 @@ static void init_meta(EvaluationContext *eval_ctx, PROCESS *process, Scene *scen new_ml->imat = BLI_memarena_alloc(process->pgn_elements, 4 * 4 * sizeof(float)); /* too big stiffness seems only ugly due to linear interpolation - * no need to have possibility for too big stiffness */ + * no need to have possibility for too big stiffness */ if (ml->s > 10.0f) new_ml->s = 10.0f; else new_ml->s = ml->s; @@ -1294,7 +1294,7 @@ void BKE_mball_polygonize(EvaluationContext *eval_ctx, Scene *scene, Object *ob, build_bvh_spatial(&process, &process.metaball_bvh, 0, process.totelem, &process.allbb); /* don't polygonize metaballs with too high resolution (base mball to small) - * note: Eps was 0.0001f but this was giving problems for blood animation for durian, using 0.00001f */ + * note: Eps was 0.0001f but this was giving problems for blood animation for durian, using 0.00001f */ if (ob->size[0] > 0.00001f * (process.allbb.max[0] - process.allbb.min[0]) || ob->size[1] > 0.00001f * (process.allbb.max[1] - process.allbb.min[1]) || ob->size[2] > 0.00001f * (process.allbb.max[2] - process.allbb.min[2])) diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index f82e5cf61b3..706902ef3cf 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -561,12 +561,14 @@ Mesh *BKE_mesh_copy(Mesh *me) return BKE_mesh_copy_ex(G.main, me); } -BMesh *BKE_mesh_to_bmesh(Mesh *me, Object *ob, const bool add_key_index) +BMesh *BKE_mesh_to_bmesh( + Mesh *me, Object *ob, + const bool add_key_index, const struct BMeshCreateParams *params) { BMesh *bm; const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(me); - bm = BM_mesh_create(&allocsize); + bm = BM_mesh_create(&allocsize, params); BM_mesh_bm_from_me( bm, me, (&(struct BMeshFromMeshParams){ diff --git a/source/blender/blenkernel/intern/modifiers_bmesh.c b/source/blender/blenkernel/intern/modifiers_bmesh.c index 18f3db6bd15..0838630a6cb 100644 --- a/source/blender/blenkernel/intern/modifiers_bmesh.c +++ b/source/blender/blenkernel/intern/modifiers_bmesh.c @@ -211,7 +211,9 @@ BMEditMesh *DM_to_editbmesh(DerivedMesh *dm, BMEditMesh *existing, const bool do bm = em->bm; } else { - bm = BM_mesh_create(&bm_mesh_allocsize_default); + bm = BM_mesh_create( + &bm_mesh_allocsize_default, + &((struct BMeshCreateParams){.use_toolflags = false,})); } DM_to_bmesh_ex(dm, bm, do_tessellate); @@ -233,7 +235,9 @@ BMesh *DM_to_bmesh(DerivedMesh *dm, const bool calc_face_normal) BMesh *bm; const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_DM(dm); - bm = BM_mesh_create(&allocsize); + bm = BM_mesh_create( + &allocsize, + &((struct BMeshCreateParams){.use_toolflags = false,})); DM_to_bmesh_ex(dm, bm, calc_face_normal); diff --git a/source/blender/blenkernel/intern/particle_distribute.c b/source/blender/blenkernel/intern/particle_distribute.c index c814713f3f4..44cf5b119c1 100644 --- a/source/blender/blenkernel/intern/particle_distribute.c +++ b/source/blender/blenkernel/intern/particle_distribute.c @@ -1007,13 +1007,11 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti MEM_freeN(vweight); } -#define MIN_WEIGHT 1e-7f /* Weights too small cause issues e.g. with binary search... */ - /* Calculate total weight of all elements */ int totmapped = 0; totweight = 0.0f; for (i = 0; i < totelem; i++) { - if (element_weight[i] > MIN_WEIGHT) { + if (element_weight[i] > 0.0f) { totmapped++; totweight += element_weight[i]; } @@ -1036,22 +1034,21 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti int *element_map = MEM_mallocN(sizeof(*element_map) * totmapped, __func__); int i_mapped = 0; - for (i = 0; i < totelem && element_weight[i] <= MIN_WEIGHT; i++); + for (i = 0; i < totelem && element_weight[i] == 0.0f; i++); element_sum[i_mapped] = element_weight[i] * inv_totweight; element_map[i_mapped] = i; i_mapped++; for (i++; i < totelem; i++) { - if (element_weight[i] > MIN_WEIGHT) { + if (element_weight[i] > 0.0f) { element_sum[i_mapped] = element_sum[i_mapped - 1] + element_weight[i] * inv_totweight; - BLI_assert(element_sum[i_mapped] > element_sum[i_mapped - 1]); - element_map[i_mapped] = i; - i_mapped++; + /* Skip elements which weight is so small that it does not affect the sum. */ + if (element_sum[i_mapped] > element_sum[i_mapped - 1]) { + element_map[i_mapped] = i; + i_mapped++; + } } } - - BLI_assert(i_mapped == totmapped); - -#undef MIN_WEIGHT + totmapped = i_mapped; /* Finally assign elements to particles */ if ((part->flag & PART_TRAND) || (part->simplify_flag & PART_SIMPLIFY_ENABLE)) { diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c index 88dc63d6cb2..87d22d01275 100644 --- a/source/blender/blenkernel/intern/pbvh_bmesh.c +++ b/source/blender/blenkernel/intern/pbvh_bmesh.c @@ -1909,17 +1909,22 @@ static void pbvh_bmesh_verify(PBVH *bvh) { /* build list of faces & verts to lookup */ GSet *faces_all = BLI_gset_ptr_new_ex(__func__, bvh->bm->totface); - BMFace *f; BMIter iter; - BM_ITER_MESH(f, &iter, bvh->bm, BM_FACES_OF_MESH) { - BLI_gset_insert(faces_all, f); + + { + BMFace *f; + BM_ITER_MESH(f, &iter, bvh->bm, BM_FACES_OF_MESH) { + BLI_gset_insert(faces_all, f); + } } GSet *verts_all = BLI_gset_ptr_new_ex(__func__, bvh->bm->totvert); - BMVert *v; - BM_ITER_MESH(v, &iter, bvh->bm, BM_VERTS_OF_MESH) { - if (BM_ELEM_CD_GET_INT(v, bvh->cd_vert_node_offset) != DYNTOPO_NODE_NONE) { - BLI_gset_insert(verts_all, v); + { + BMVert *v; + BM_ITER_MESH(v, &iter, bvh->bm, BM_VERTS_OF_MESH) { + if (BM_ELEM_CD_GET_INT(v, bvh->cd_vert_node_offset) != DYNTOPO_NODE_NONE) { + BLI_gset_insert(verts_all, v); + } } } @@ -1936,76 +1941,83 @@ static void pbvh_bmesh_verify(PBVH *bvh) BLI_assert(totvert == BLI_gset_size(verts_all)); } - BM_ITER_MESH(f, &iter, bvh->bm, BM_FACES_OF_MESH) { - BMIter bm_iter; - BMVert *v; - PBVHNode *n = pbvh_bmesh_node_lookup(bvh, f); + { + BMFace *f; + BM_ITER_MESH(f, &iter, bvh->bm, BM_FACES_OF_MESH) { + BMIter bm_iter; + BMVert *v; + PBVHNode *n = pbvh_bmesh_node_lookup(bvh, f); - /* Check that the face's node is a leaf */ - BLI_assert(n->flag & PBVH_Leaf); + /* Check that the face's node is a leaf */ + BLI_assert(n->flag & PBVH_Leaf); - /* Check that the face's node knows it owns the face */ - BLI_assert(BLI_gset_haskey(n->bm_faces, f)); + /* Check that the face's node knows it owns the face */ + BLI_assert(BLI_gset_haskey(n->bm_faces, f)); - /* Check the face's vertices... */ - BM_ITER_ELEM (v, &bm_iter, f, BM_VERTS_OF_FACE) { - PBVHNode *nv; + /* Check the face's vertices... */ + BM_ITER_ELEM (v, &bm_iter, f, BM_VERTS_OF_FACE) { + PBVHNode *nv; - /* Check that the vertex is in the node */ - BLI_assert(BLI_gset_haskey(n->bm_unique_verts, v) ^ - BLI_gset_haskey(n->bm_other_verts, v)); + /* Check that the vertex is in the node */ + BLI_assert(BLI_gset_haskey(n->bm_unique_verts, v) ^ + BLI_gset_haskey(n->bm_other_verts, v)); - /* Check that the vertex has a node owner */ - nv = pbvh_bmesh_node_lookup(bvh, v); + /* Check that the vertex has a node owner */ + nv = pbvh_bmesh_node_lookup(bvh, v); - /* Check that the vertex's node knows it owns the vert */ - BLI_assert(BLI_gset_haskey(nv->bm_unique_verts, v)); + /* Check that the vertex's node knows it owns the vert */ + BLI_assert(BLI_gset_haskey(nv->bm_unique_verts, v)); - /* Check that the vertex isn't duplicated as an 'other' vert */ - BLI_assert(!BLI_gset_haskey(nv->bm_other_verts, v)); + /* Check that the vertex isn't duplicated as an 'other' vert */ + BLI_assert(!BLI_gset_haskey(nv->bm_other_verts, v)); + } } } /* Check verts */ - BM_ITER_MESH(v, &iter, bvh->bm, BM_VERTS_OF_MESH) { - /* vertex isn't tracked */ - if (BM_ELEM_CD_GET_INT(v, bvh->cd_vert_node_offset) == DYNTOPO_NODE_NONE) { - continue; - } + { + BMVert *v; + BM_ITER_MESH(v, &iter, bvh->bm, BM_VERTS_OF_MESH) { + /* vertex isn't tracked */ + if (BM_ELEM_CD_GET_INT(v, bvh->cd_vert_node_offset) == DYNTOPO_NODE_NONE) { + continue; + } - PBVHNode *n = pbvh_bmesh_node_lookup(bvh, v); + PBVHNode *n = pbvh_bmesh_node_lookup(bvh, v); - /* Check that the vert's node is a leaf */ - BLI_assert(n->flag & PBVH_Leaf); + /* Check that the vert's node is a leaf */ + BLI_assert(n->flag & PBVH_Leaf); - /* Check that the vert's node knows it owns the vert */ - BLI_assert(BLI_gset_haskey(n->bm_unique_verts, v)); + /* Check that the vert's node knows it owns the vert */ + BLI_assert(BLI_gset_haskey(n->bm_unique_verts, v)); - /* Check that the vertex isn't duplicated as an 'other' vert */ - BLI_assert(!BLI_gset_haskey(n->bm_other_verts, v)); + /* Check that the vertex isn't duplicated as an 'other' vert */ + BLI_assert(!BLI_gset_haskey(n->bm_other_verts, v)); - /* Check that the vert's node also contains one of the vert's - * adjacent faces */ - bool found = false; - BMIter bm_iter; - BM_ITER_ELEM (f, &bm_iter, v, BM_FACES_OF_VERT) { - if (pbvh_bmesh_node_lookup(bvh, f) == n) { - found = true; - break; + /* Check that the vert's node also contains one of the vert's + * adjacent faces */ + bool found = false; + BMIter bm_iter; + BMFace *f; + BM_ITER_ELEM (f, &bm_iter, v, BM_FACES_OF_VERT) { + if (pbvh_bmesh_node_lookup(bvh, f) == n) { + found = true; + break; + } } - } - BLI_assert(found); + BLI_assert(found); #if 1 - /* total freak stuff, check if node exists somewhere else */ - /* Slow */ - for (int i = 0; i < bvh->totnode; i++) { - PBVHNode *n_other = &bvh->nodes[i]; - if ((n != n_other) && (n_other->bm_unique_verts)) { - BLI_assert(!BLI_gset_haskey(n_other->bm_unique_verts, v)); + /* total freak stuff, check if node exists somewhere else */ + /* Slow */ + for (int i = 0; i < bvh->totnode; i++) { + PBVHNode *n_other = &bvh->nodes[i]; + if ((n != n_other) && (n_other->bm_unique_verts)) { + BLI_assert(!BLI_gset_haskey(n_other->bm_unique_verts, v)); + } } - } #endif + } } #if 0 diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index 518d8d68919..7094d5a3547 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -405,21 +405,28 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc, bool for /* use editmesh to avoid array allocation */ BMEditMesh *emtarget = NULL, *emaux = NULL; - BVHTreeFromEditMesh emtreedata_stack, emauxdata_stack; - BVHTreeFromMesh dmtreedata_stack, dmauxdata_stack; + union { + BVHTreeFromEditMesh emtreedata; + BVHTreeFromMesh dmtreedata; + } treedata_stack, auxdata_stack; + BVHTree *targ_tree; void *targ_callback; if (calc->smd->target && calc->target->type == DM_TYPE_EDITBMESH) { emtarget = BKE_editmesh_from_object(calc->smd->target); - if ((targ_tree = bvhtree_from_editmesh_looptri(&emtreedata_stack, emtarget, 0.0, 4, 6))) { - targ_callback = emtreedata_stack.raycast_callback; - treeData = &emtreedata_stack; + if ((targ_tree = bvhtree_from_editmesh_looptri( + &treedata_stack.emtreedata, emtarget, 0.0, 4, 6, &calc->target->bvhCache))) + { + targ_callback = treedata_stack.emtreedata.raycast_callback; + treeData = &treedata_stack.emtreedata; } } else { - if ((targ_tree = bvhtree_from_mesh_looptri(&dmtreedata_stack, calc->target, 0.0, 4, 6))) { - targ_callback = dmtreedata_stack.raycast_callback; - treeData = &dmtreedata_stack; + if ((targ_tree = bvhtree_from_mesh_looptri( + &treedata_stack.dmtreedata, calc->target, 0.0, 4, 6))) + { + targ_callback = treedata_stack.dmtreedata.raycast_callback; + treeData = &treedata_stack.dmtreedata; } } if (targ_tree) { @@ -429,15 +436,17 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc, bool for /* use editmesh to avoid array allocation */ if (calc->smd->auxTarget && auxMesh->type == DM_TYPE_EDITBMESH) { emaux = BKE_editmesh_from_object(calc->smd->auxTarget); - if ((aux_tree = bvhtree_from_editmesh_looptri(&emauxdata_stack, emaux, 0.0, 4, 6)) != NULL) { - aux_callback = emauxdata_stack.raycast_callback; - auxData = &emauxdata_stack; + if ((aux_tree = bvhtree_from_editmesh_looptri( + &auxdata_stack.emtreedata, emaux, 0.0, 4, 6, &auxMesh->bvhCache))) + { + aux_callback = auxdata_stack.emtreedata.raycast_callback; + auxData = &auxdata_stack.emtreedata; } } else { - if ((aux_tree = bvhtree_from_mesh_looptri(&dmauxdata_stack, auxMesh, 0.0, 4, 6)) != NULL) { - aux_callback = dmauxdata_stack.raycast_callback; - auxData = &dmauxdata_stack; + if ((aux_tree = bvhtree_from_mesh_looptri(&auxdata_stack.dmtreedata, auxMesh, 0.0, 4, 6)) != NULL) { + aux_callback = auxdata_stack.dmtreedata.raycast_callback; + auxData = &auxdata_stack.dmtreedata; } } } @@ -455,12 +464,21 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc, bool for /* free data structures */ if (treeData) { - if (emtarget) free_bvhtree_from_editmesh(treeData); - else free_bvhtree_from_mesh(treeData); + if (emtarget) { + free_bvhtree_from_editmesh(treeData); + } + else { + free_bvhtree_from_mesh(treeData); + } } + if (auxData) { - if (emaux) free_bvhtree_from_editmesh(auxData); - else free_bvhtree_from_mesh(auxData); + if (emaux) { + free_bvhtree_from_editmesh(auxData); + } + else { + free_bvhtree_from_mesh(auxData); + } } } diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 25a4fdc0cc7..8fec817d694 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -2243,7 +2243,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa .. keeping G.debug_value==17 0x11 option for old files 'needing' the bug*/ /* rule we never alter free variables :bp->vec bp->pos in here ! - * this will ruin adaptive stepsize AKA heun! (BM) + * this will ruin adaptive stepsize AKA heun! (BM) */ SoftBody *sb= ob->soft; /* is supposed to be there */ BodyPoint *bp; diff --git a/source/blender/blenlib/BLI_kdopbvh.h b/source/blender/blenlib/BLI_kdopbvh.h index fb8c2520e67..91d39801645 100644 --- a/source/blender/blenlib/BLI_kdopbvh.h +++ b/source/blender/blenlib/BLI_kdopbvh.h @@ -96,7 +96,8 @@ typedef void (*BVHTree_NearestPointCallback)(void *userdata, int index, const fl typedef void (*BVHTree_RayCastCallback)(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit); /* callback must update nearest in case it finds a nearest result */ -typedef void (*BVHTree_NearestToRayCallback)(void *userdata, int index, const BVHTreeRay *ray, BVHTreeNearest *nearest); +typedef void (*BVHTree_NearestToRayCallback)(void *userdata, const float ray_co[3], const float ray_dir[3], + const float scale[3], int index, BVHTreeNearest *nearest); /* callback to check if 2 nodes overlap (use thread if intersection results need to be stored) */ typedef bool (*BVHTree_OverlapCallback)(void *userdata, int index_a, int index_b, int thread); @@ -142,8 +143,16 @@ int BLI_bvhtree_find_nearest( BVHTree *tree, const float co[3], BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata); +int BLI_bvhtree_find_nearest_to_ray_angle( + BVHTree *tree, const float co[3], const float dir[3], + const bool ray_is_normalized, const float scale[3], + BVHTreeNearest *nearest, + BVHTree_NearestToRayCallback callback, void *userdata); + int BLI_bvhtree_find_nearest_to_ray( - BVHTree *tree, const float co[3], const float dir[3], BVHTreeNearest *nearest, + BVHTree *tree, const float co[3], const float dir[3], + const bool ray_is_normalized, const float scale[3], + BVHTreeNearest *nearest, BVHTree_NearestToRayCallback callback, void *userdata); int BLI_bvhtree_ray_cast_ex( diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index c5f552a7a18..026ab9a9980 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -115,6 +115,13 @@ float dist_signed_squared_to_corner_v3v3v3( const float p[3], const float v1[3], const float v2[3], const float v3[3], const float axis_ref[3]); +float dist_squared_to_ray_v3( + const float ray_origin[3], const float ray_direction[3], + const float co[3], float *r_depth); +float dist_squared_ray_to_seg_v3( + const float ray_origin[3], const float ray_direction[3], + const float v0[3], const float v1[3], + float r_point[3], float *r_depth); float closest_to_line_v2(float r_close[2], const float p[2], const float l1[2], const float l2[2]); float closest_to_line_v3(float r_close[3], const float p[3], const float l1[3], const float l2[3]); void closest_to_line_segment_v2(float r_close[2], const float p[2], const float l1[2], const float l2[2]); diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index 6cef1924e33..92f4e998206 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -163,12 +163,23 @@ typedef struct BVHNearestRayData { BVHTree *tree; BVHTree_NearestToRayCallback callback; void *userdata; - BVHTreeRay ray; - struct NearestRayToAABB_Precalc nearest_precalc; + struct { + bool sign[3]; + float origin[3]; + float direction[3]; + + float direction_scaled_square[3]; + float inv_dir[3]; + + float cdot_axis[3]; + } ray; bool pick_smallest[3]; + BVHTreeNearest nearest; + + float scale[3]; } BVHNearestRayData; /** \} */ @@ -1889,58 +1900,374 @@ void BLI_bvhtree_ray_cast_all( /* -------------------------------------------------------------------- */ -/** \name BLI_bvhtree_find_nearest_to_ray +/** \name BLI_bvhtree_find_nearest_to_ray functions * * \{ */ +static void dist_squared_ray_to_aabb_scaled_v3_precalc( + BVHNearestRayData *data, + const float ray_origin[3], const float ray_direction[3], + const bool ray_is_normalized, const float scale[3]) +{ + if (scale) { + copy_v3_v3(data->scale, scale); + } + else { + copy_v3_fl(data->scale, 1.0f); + } + /* un-normalize ray */ + if (ray_is_normalized && scale && + (data->scale[0] != 1.0f || data->scale[1] != 1.0f || data->scale[2] != 1.0f)) + { + data->ray.direction[0] = ray_direction[0] * data->scale[0]; + data->ray.direction[1] = ray_direction[1] * data->scale[1]; + data->ray.direction[2] = ray_direction[2] * data->scale[2]; + + mul_v3_v3fl(data->ray.direction, ray_direction, 1 / len_v3(data->ray.direction)); + } + else { + copy_v3_v3(data->ray.direction, ray_direction); + } + + float dir_sq[3]; + + for (int i = 0; i < 3; i++) { + data->ray.origin[i] = ray_origin[i]; + data->ray.inv_dir[i] = (data->ray.direction[i] != 0.0f) ? + (1.0f / data->ray.direction[i]) : FLT_MAX; + /* It has to be in function of `ray.inv_dir`, + * since the division of 1 by 0.0f, can be -inf or +inf */ + data->ray.sign[i] = (data->ray.inv_dir[i] < 0.0f); + + data->ray.direction_scaled_square[i] = data->ray.direction[i] * data->scale[i]; + + dir_sq[i] = SQUARE(data->ray.direction_scaled_square[i]); + + data->ray.direction_scaled_square[i] *= data->scale[i]; + } + + /* `diag_sq` Length square of each face diagonal */ + float diag_sq[3] = { + dir_sq[1] + dir_sq[2], + dir_sq[0] + dir_sq[2], + dir_sq[0] + dir_sq[1], + }; + + data->ray.cdot_axis[0] = (diag_sq[0] != 0.0f) ? data->ray.direction[0] / diag_sq[0] : FLT_MAX; + data->ray.cdot_axis[1] = (diag_sq[1] != 0.0f) ? data->ray.direction[1] / diag_sq[1] : FLT_MAX; + data->ray.cdot_axis[2] = (diag_sq[2] != 0.0f) ? data->ray.direction[2] / diag_sq[2] : FLT_MAX; +} + +/** + * Returns the squared distance from a ray to a bound-box `AABB`. + * It is based on `fast_ray_nearest_hit` solution to obtain + * the coordinates of the nearest edge of Bound Box to the ray + */ +MINLINE float dist_squared_ray_to_aabb_scaled_v3__impl( + const BVHNearestRayData *data, + const float bv[6], float *r_depth_sq, bool r_axis_closest[3]) +{ + + /* `tmin` is a vector that has the smaller distances to each of the + * infinite planes of the `AABB` faces (hit in nearest face X plane, + * nearest face Y plane and nearest face Z plane) */ + float local_bvmin[3], local_bvmax[3]; + + if (data->ray.sign[0]) { + local_bvmin[0] = bv[1]; + local_bvmax[0] = bv[0]; + } + else { + local_bvmin[0] = bv[0]; + local_bvmax[0] = bv[1]; + } + + if (data->ray.sign[1]) { + local_bvmin[1] = bv[3]; + local_bvmax[1] = bv[2]; + } + else { + local_bvmin[1] = bv[2]; + local_bvmax[1] = bv[3]; + } + + if (data->ray.sign[2]) { + local_bvmin[2] = bv[5]; + local_bvmax[2] = bv[4]; + } + else { + local_bvmin[2] = bv[4]; + local_bvmax[2] = bv[5]; + } + + sub_v3_v3(local_bvmin, data->ray.origin); + sub_v3_v3(local_bvmax, data->ray.origin); + + const float tmin[3] = { + local_bvmin[0] * data->ray.inv_dir[0], + local_bvmin[1] * data->ray.inv_dir[1], + local_bvmin[2] * data->ray.inv_dir[2], + }; + + /* `tmax` is a vector that has the longer distances to each of the + * infinite planes of the `AABB` faces (hit in farthest face X plane, + * farthest face Y plane and farthest face Z plane) */ + const float tmax[3] = { + local_bvmax[0] * data->ray.inv_dir[0], + local_bvmax[1] * data->ray.inv_dir[1], + local_bvmax[2] * data->ray.inv_dir[2], + }; + /* `v1` and `v3` is be the coordinates of the nearest `AABB` edge to the ray*/ + float v1[3], v2[3]; + /* `rtmin` is the highest value of the smaller distances. == max_axis_v3(tmin) + * `rtmax` is the lowest value of longer distances. == min_axis_v3(tmax)*/ + float rtmin, rtmax, mul; + /* `main_axis` is the axis equivalent to edge close to the ray */ + int main_axis; + + r_axis_closest[0] = false; + r_axis_closest[1] = false; + r_axis_closest[2] = false; + + /* *** min_axis_v3(tmax) *** */ + if ((tmax[0] <= tmax[1]) && (tmax[0] <= tmax[2])) { + // printf("# Hit in X %s\n", data->sign[0] ? "min", "max"); + rtmax = tmax[0]; + v1[0] = v2[0] = local_bvmax[0]; + mul = local_bvmax[0] * data->ray.direction_scaled_square[0]; + main_axis = 3; + r_axis_closest[0] = data->ray.sign[0]; + } + else if ((tmax[1] <= tmax[0]) && (tmax[1] <= tmax[2])) { + // printf("# Hit in Y %s\n", data->sign[1] ? "min", "max"); + rtmax = tmax[1]; + v1[1] = v2[1] = local_bvmax[1]; + mul = local_bvmax[1] * data->ray.direction_scaled_square[1]; + main_axis = 2; + r_axis_closest[1] = data->ray.sign[1]; + } + else { + // printf("# Hit in Z %s\n", data->sign[2] ? "min", "max"); + rtmax = tmax[2]; + v1[2] = v2[2] = local_bvmax[2]; + mul = local_bvmax[2] * data->ray.direction_scaled_square[2]; + main_axis = 1; + r_axis_closest[2] = data->ray.sign[2]; + } + + /* *** max_axis_v3(tmin) *** */ + if ((tmin[0] >= tmin[1]) && (tmin[0] >= tmin[2])) { + // printf("# To X %s\n", data->sign[0] ? "max", "min"); + rtmin = tmin[0]; + v1[0] = v2[0] = local_bvmin[0]; + mul += local_bvmin[0] * data->ray.direction_scaled_square[0]; + main_axis -= 3; + r_axis_closest[0] = !data->ray.sign[0]; + } + else if ((tmin[1] >= tmin[0]) && (tmin[1] >= tmin[2])) { + // printf("# To Y %s\n", data->sign[1] ? "max", "min"); + rtmin = tmin[1]; + v1[1] = v2[1] = local_bvmin[1]; + mul += local_bvmin[1] * data->ray.direction_scaled_square[1]; + main_axis -= 1; + r_axis_closest[1] = !data->ray.sign[1]; + } + else { + // printf("# To Z %s\n", data->sign[2] ? "max", "min"); + rtmin = tmin[2]; + v1[2] = v2[2] = local_bvmin[2]; + mul += local_bvmin[2] * data->ray.direction_scaled_square[2]; + main_axis -= 2; + r_axis_closest[2] = !data->ray.sign[2]; + } + /* *** end min/max axis *** */ + + if (main_axis < 0) + main_axis += 3; + + /* if rtmin < rtmax, ray intersect `AABB` */ + if (rtmin <= rtmax) { +#ifdef IGNORE_BEHIND_RAY + /* `if rtmax < depth_min`, the whole `AABB` is behind us */ + if (rtmax < min_depth) { + return fallback; + } +#endif + const float proj = rtmin * data->ray.direction[main_axis]; + + if (data->ray.sign[main_axis]) + r_axis_closest[main_axis] = (proj - local_bvmax[main_axis]) < (local_bvmin[main_axis] - proj); + else + r_axis_closest[main_axis] = (proj - local_bvmin[main_axis]) < (local_bvmax[main_axis] - proj); + + //if (r_depth_sq) + // *r_depth_sq = SQUARE(rtmin); + + return 0.0f; + } +#ifdef IGNORE_BEHIND_RAY + /* `if rtmin < depth_min`, the whole `AABB` is behing us */ + else if (rtmin < min_depth) { + return fallback; + } +#endif + + if (data->ray.sign[main_axis]) { + v1[main_axis] = local_bvmax[main_axis]; + v2[main_axis] = local_bvmin[main_axis]; + } + else { + v1[main_axis] = local_bvmin[main_axis]; + v2[main_axis] = local_bvmax[main_axis]; + } + { + /* `proj` equals to nearest point on the ray closest to the edge `v1 v2` of the `AABB`. */ + const float proj = mul * data->ray.cdot_axis[main_axis]; + float depth_sq, r_point[3]; + if (v1[main_axis] > proj) { /* the nearest point to the ray is the point v1 */ + r_axis_closest[main_axis] = true; + /* `depth` is equivalent the distance of the the projection of v1 on the ray */ + depth_sq = mul + data->ray.direction_scaled_square[main_axis] * v1[main_axis]; + + copy_v3_v3(r_point, v1); + } + else if (v2[main_axis] < proj) { /* the nearest point of the ray is the point v2 */ + r_axis_closest[main_axis] = false; + + depth_sq = mul + data->ray.direction_scaled_square[main_axis] * v2[main_axis]; + + copy_v3_v3(r_point, v2); + } + else { /* the nearest point of the ray is on the edge of the `AABB`. */ + r_axis_closest[main_axis] = (proj - v1[main_axis]) < (v2[main_axis] - proj); + + depth_sq = mul + data->ray.direction_scaled_square[main_axis] * proj; +#if 0 + r_point[0] = main_axis == 0 ? proj : v2[0]; + r_point[1] = main_axis == 1 ? proj : v2[1]; + r_point[2] = main_axis == 2 ? proj : v2[2]; +#else + v2[main_axis] = proj; + copy_v3_v3(r_point, v2); +#endif + } + depth_sq *= depth_sq; + + if (r_depth_sq) + *r_depth_sq = depth_sq; + + /* TODO: scale can be optional */ + r_point[0] *= data->scale[0]; + r_point[1] *= data->scale[1]; + r_point[2] *= data->scale[2]; + + return len_squared_v3(r_point) - depth_sq; + } +} + +/** + * <pre> + * + r_point + * | + * | dist + * | + * +----depth----+orig <-- dir + * + * tangent = dist/depth + * </pre> + */ +static float calc_tangent_sq(BVHNearestRayData *data, BVHNode *node) +{ + float depth_sq; + const float dist_sq = dist_squared_ray_to_aabb_scaled_v3__impl( + data, node->bv, &depth_sq, data->pick_smallest); + + return (dist_sq != 0.0f) ? (dist_sq / depth_sq) : 0.0f; +} + static float calc_dist_sq_to_ray(BVHNearestRayData *data, BVHNode *node) { - const float *bv = node->bv; - const float bb_min[3] = {bv[0], bv[2], bv[4]}; - const float bb_max[3] = {bv[1], bv[3], bv[5]}; - return dist_squared_ray_to_aabb_v3(&data->nearest_precalc, bb_min, bb_max, data->pick_smallest); + return dist_squared_ray_to_aabb_scaled_v3__impl( + data, node->bv, NULL, + data->pick_smallest); } -static void dfs_find_nearest_to_ray_dfs(BVHNearestRayData *data, BVHNode *node) +static void dfs_find_lowest_tangent_dfs(BVHNearestRayData *data, BVHNode *node) { if (node->totnode == 0) { if (data->callback) { - data->callback(data->userdata, node->index, &data->ray, &data->nearest); + data->callback(data->userdata, data->ray.origin, data->ray.direction, + data->scale, node->index, &data->nearest); + } + else { + data->nearest.index = node->index; + data->nearest.dist_sq = calc_tangent_sq(data, node); + /* TODO: return a value to the data->nearest.co + * not urgent however since users currently define own callbacks */ + } + } + else { + int i; + /* First pick the closest node to dive on */ + if (data->pick_smallest[node->main_axis]) { + for (i = 0; i != node->totnode; i++) { + if (calc_tangent_sq(data, node->children[i]) < data->nearest.dist_sq) { + dfs_find_lowest_tangent_dfs(data, node->children[i]); + } + } } else { - const float dist_sq = calc_dist_sq_to_ray(data, node); - if (dist_sq != FLT_MAX) { /* not an invalid ray */ - data->nearest.index = node->index; - data->nearest.dist_sq = dist_sq; - /* TODO: return a value to the data->nearest.co - * not urgent however since users currently define own callbacks */ + for (i = node->totnode - 1; i >= 0; i--) { + if (calc_tangent_sq(data, node->children[i]) < data->nearest.dist_sq) { + dfs_find_lowest_tangent_dfs(data, node->children[i]); + } } } } +} + +static void dfs_find_nearest_to_ray_dfs(BVHNearestRayData *data, BVHNode *node) +{ + if (node->totnode == 0) { + if (data->callback) { + data->callback(data->userdata, data->ray.origin, data->ray.direction, + data->scale, node->index, &data->nearest); + } + else { + data->nearest.index = node->index; + data->nearest.dist_sq = calc_dist_sq_to_ray(data, node); + /* TODO: return a value to the data->nearest.co + * not urgent however since users currently define own callbacks */ + } + } else { int i; /* First pick the closest node to dive on */ if (data->pick_smallest[node->main_axis]) { for (i = 0; i != node->totnode; i++) { - if (calc_dist_sq_to_ray(data, node->children[i]) >= data->nearest.dist_sq) { - continue; + if (calc_dist_sq_to_ray(data, node->children[i]) < data->nearest.dist_sq) { + dfs_find_nearest_to_ray_dfs(data, node->children[i]); } - dfs_find_nearest_to_ray_dfs(data, node->children[i]); } } else { for (i = node->totnode - 1; i >= 0; i--) { - if (calc_dist_sq_to_ray(data, node->children[i]) >= data->nearest.dist_sq) { - continue; + if (calc_dist_sq_to_ray(data, node->children[i]) < data->nearest.dist_sq) { + dfs_find_nearest_to_ray_dfs(data, node->children[i]); } - dfs_find_nearest_to_ray_dfs(data, node->children[i]); } } } } -int BLI_bvhtree_find_nearest_to_ray( - BVHTree *tree, const float co[3], const float dir[3], BVHTreeNearest *nearest, +/** + * Returns the point whose tangent defined by the angle between the point and ray is the lowest + * nearest.dist_sq returns the angle's tangent + */ +int BLI_bvhtree_find_nearest_to_ray_angle( + BVHTree *tree, const float co[3], const float dir[3], + const bool ray_is_normalized, const float scale[3], + BVHTreeNearest *nearest, BVHTree_NearestToRayCallback callback, void *userdata) { BVHNearestRayData data; @@ -1951,11 +2278,46 @@ int BLI_bvhtree_find_nearest_to_ray( data.callback = callback; data.userdata = userdata; - copy_v3_v3(data.ray.origin, co); - copy_v3_v3(data.ray.direction, dir); - data.ray.radius = 0.0f; /* unused here */ + dist_squared_ray_to_aabb_scaled_v3_precalc(&data, co, dir, ray_is_normalized, scale); + + if (nearest) { + memcpy(&data.nearest, nearest, sizeof(*nearest)); + } + else { + data.nearest.index = -1; + data.nearest.dist_sq = FLT_MAX; + } + + /* dfs search */ + if (root) { + if (calc_tangent_sq(&data, root) < data.nearest.dist_sq) + dfs_find_lowest_tangent_dfs(&data, root); + } + + /* copy back results */ + if (nearest) { + memcpy(nearest, &data.nearest, sizeof(*nearest)); + } + + return data.nearest.index; +} + +/* return the nearest point to ray */ +int BLI_bvhtree_find_nearest_to_ray( + BVHTree *tree, const float co[3], const float dir[3], + const bool ray_is_normalized, const float scale[3], + BVHTreeNearest *nearest, + BVHTree_NearestToRayCallback callback, void *userdata) +{ + BVHNearestRayData data; + BVHNode *root = tree->nodes[tree->totleaf]; + + data.tree = tree; + + data.callback = callback; + data.userdata = userdata; - dist_squared_ray_to_aabb_v3_precalc(&data.nearest_precalc, co, dir); + dist_squared_ray_to_aabb_scaled_v3_precalc(&data, co, dir, ray_is_normalized, scale); if (nearest) { memcpy(&data.nearest, nearest, sizeof(*nearest)); diff --git a/source/blender/blenlib/intern/array_store.c b/source/blender/blenlib/intern/array_store.c index 33565596c1f..6000c1a680c 100644 --- a/source/blender/blenlib/intern/array_store.c +++ b/source/blender/blenlib/intern/array_store.c @@ -249,7 +249,7 @@ typedef struct BArrayMemory { /** * Main storage for all states */ -typedef struct BArrayStore { +struct BArrayStore { /* static */ BArrayInfo info; @@ -260,7 +260,7 @@ typedef struct BArrayStore { * #BArrayState may be in any order (logic should never depend on state order). */ ListBase states; -} BArrayStore; +}; /** * A single instance of an array. @@ -272,13 +272,13 @@ typedef struct BArrayStore { * While this could be moved to a memory pool, * it makes it easier to trace invalid usage, so leave as-is for now. */ -typedef struct BArrayState { +struct BArrayState { /** linked list in #BArrayStore.states */ struct BArrayState *next, *prev; struct BChunkList *chunk_list; /* BChunkList's */ -} BArrayState; +}; typedef struct BChunkList { ListBase chunk_refs; /* BChunkRef's */ @@ -1750,10 +1750,11 @@ bool BLI_array_store_is_valid( } \ } ((void)0) - /* count chunk_list's */ - int totrefs = 0; GHash *chunk_list_map = BLI_ghash_ptr_new(__func__); + GHash *chunk_map = BLI_ghash_ptr_new(__func__); + + int totrefs = 0; for (BArrayState *state = bs->states.first; state; state = state->next) { GHASH_PTR_ADD_USER(chunk_list_map, state->chunk_list); } @@ -1771,7 +1772,6 @@ bool BLI_array_store_is_valid( } /* count chunk's */ - GHash *chunk_map = BLI_ghash_ptr_new(__func__); GHASH_ITER (gh_iter, chunk_list_map) { const struct BChunkList *chunk_list = BLI_ghashIterator_getKey(&gh_iter); for (const BChunkRef *cref = chunk_list->chunk_refs.first; cref; cref = cref->next) { diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 3a5291691db..effbe3f9770 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -572,6 +572,67 @@ float dist_signed_squared_to_corner_v3v3v3( } } +/** + * return the distance squared of a point to a ray. + */ +float dist_squared_to_ray_v3( + const float ray_origin[3], const float ray_direction[3], + const float co[3], float *r_depth) +{ + float dvec[3]; + sub_v3_v3v3(dvec, co, ray_origin); + *r_depth = dot_v3v3(dvec, ray_direction); + return len_squared_v3(dvec) - SQUARE(*r_depth); +} +/** + * Find the closest point in a seg to a ray and return the distance squared. + * \param r_point : Is the point on segment closest to ray (or to ray_origin if the ray and the segment are parallel). + * \param depth: the distance of r_point projection on ray to the ray_origin. + */ +float dist_squared_ray_to_seg_v3( + const float ray_origin[3], const float ray_direction[3], + const float v0[3], const float v1[3], + float r_point[3], float *r_depth) +{ + float a[3], t[3], n[3], lambda; + sub_v3_v3v3(a, v1, v0); + sub_v3_v3v3(t, v0, ray_origin); + cross_v3_v3v3(n, a, ray_direction); + const float nlen = len_squared_v3(n); + + /* if (nlen == 0.0f) the lines are parallel, + * has no nearest point, only distance squared.*/ + if (nlen == 0.0f) { + /* Calculate the distance to the point v0 then */ + copy_v3_v3(r_point, v0); + *r_depth = dot_v3v3(t, ray_direction); + } + else { + float c[3], cray[3]; + sub_v3_v3v3(c, n, t); + cross_v3_v3v3(cray, c, ray_direction); + lambda = dot_v3v3(cray, n) / nlen; + if (lambda <= 0) { + copy_v3_v3(r_point, v0); + + *r_depth = dot_v3v3(t, ray_direction); + } + else if (lambda >= 1) { + copy_v3_v3(r_point, v1); + + sub_v3_v3v3(t, v1, ray_origin); + *r_depth = dot_v3v3(t, ray_direction); + } + else { + madd_v3_v3v3fl(r_point, v0, a, lambda); + + sub_v3_v3v3(t, r_point, ray_origin); + *r_depth = dot_v3v3(t, ray_direction); + } + } + return len_squared_v3(t) - SQUARE(*r_depth); +} + /* Adapted from "Real-Time Collision Detection" by Christer Ericson, * published by Morgan Kaufmann Publishers, copyright 2005 Elsevier Inc. * @@ -5067,7 +5128,9 @@ float cubic_tangent_factor_circle_v3(const float tan_l[3], const float tan_r[3]) BLI_ASSERT_UNIT_V3(tan_l); BLI_ASSERT_UNIT_V3(tan_r); - const float eps = 1e-7f; + /* -7f causes instability/glitches with Bendy Bones + Custom Refs */ + const float eps = 1e-5f; + const float tan_dot = dot_v3v3(tan_l, tan_r); if (tan_dot > 1.0f - eps) { /* no angle difference (use fallback, length wont make any difference) */ diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c index 0b299af88aa..bd7b7f9cdbd 100644 --- a/source/blender/blenlib/intern/task.c +++ b/source/blender/blenlib/intern/task.c @@ -992,7 +992,8 @@ void BLI_task_parallel_range( * (similar to OpenMP's firstprivate). * \param userdata_chunk_size Memory size of \a userdata_chunk. * \param func_ex Callback function (advanced version). - * \param func_finalize Callback function, called after all workers have finisehd, useful to finalize accumulative tasks. + * \param func_finalize Callback function, called after all workers have finished, + * useful to finalize accumulative tasks. * \param use_threading If \a true, actually split-execute loop in threads, else just do a sequential forloop * (allows caller to use any kind of test to switch on parallelization or not). * \param use_dynamic_scheduling If \a true, the whole range is divided in a lot of small chunks (of size 32 currently), diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt index 8364df38208..479d3a15e6c 100644 --- a/source/blender/blenloader/CMakeLists.txt +++ b/source/blender/blenloader/CMakeLists.txt @@ -35,6 +35,10 @@ set(INC ../nodes ../render/extern/include ../../../intern/guardedalloc + + # for writefile.c: dna_type_offsets.h + ${CMAKE_BINARY_DIR}/source/blender/makesdna/intern + ) set(INC_SYS @@ -74,3 +78,6 @@ if(WITH_CODEC_FFMPEG) endif() blender_add_lib(bf_blenloader "${SRC}" "${INC}" "${INC_SYS}") + +# needed so writefile.c can use dna_type_offsets.h +add_dependencies(bf_blenloader bf_dna) diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index ab034076423..6a93770f67d 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -880,8 +880,6 @@ static void decode_blender_header(FileData *fd) if (readsize == sizeof(header)) { if (STREQLEN(header, "BLENDER", 7)) { - int remove_this_endian_test = 1; - fd->flags |= FD_FLAGS_FILE_OK; /* what size are pointers in the file ? */ @@ -900,7 +898,7 @@ static void decode_blender_header(FileData *fd) /* is the file saved in a different endian * than we need ? */ - if (((((char *)&remove_this_endian_test)[0] == 1) ? L_ENDIAN : B_ENDIAN) != ((header[8] == 'v') ? L_ENDIAN : B_ENDIAN)) { + if (((header[8] == 'v') ? L_ENDIAN : B_ENDIAN) != ENDIAN_ORDER) { fd->flags |= FD_FLAGS_SWITCH_ENDIAN; } @@ -1326,6 +1324,7 @@ bool BLO_has_bfile_extension(const char *str) * * \param path the full path to explode. * \param r_dir the string that'll contain path up to blend file itself ('library' path). + * WARNING! Must be FILE_MAX_LIBEXTRA long (it also stores group and name strings)! * \param r_group the string that'll contain 'group' part of the path, if any. May be NULL. * \param r_name the string that'll contain data's name part of the path, if any. May be NULL. * \return true if path contains a blend file. @@ -6462,7 +6461,7 @@ static void *restore_pointer_by_name_main(Main *mainp, ID *id, ePointerUserMode * - USER_IGNORE: no usercount change * - USER_REAL: ensure a real user (even if a fake one is set) * \param id_map: lookup table, use when performing many lookups. - * this could be made an optional agument (falling back to a full lookup), + * this could be made an optional argument (falling back to a full lookup), * however at the moment it's always available. */ static void *restore_pointer_by_name(struct IDNameLib_Map *id_map, ID *id, ePointerUserMode user) diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index 43ebab7856c..1956a17d57b 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -1108,6 +1108,8 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main) sce->gm.flag |= GAME_GLSL_NO_NODES; if (fd->fileflags & G_FILE_GLSL_NO_EXTRA_TEX) sce->gm.flag |= GAME_GLSL_NO_EXTRA_TEX; + if (fd->fileflags & G_FILE_GLSL_NO_ENV_LIGHTING) + sce->gm.flag |= GAME_GLSL_NO_ENV_LIGHTING; if (fd->fileflags & G_FILE_IGNORE_DEPRECATION_WARNINGS) sce->gm.flag |= GAME_IGNORE_DEPRECATION_WARNINGS; diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index e7fd7bdf2c1..f3a83fb9a8b 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -173,7 +173,7 @@ #include "BKE_mesh.h" #ifdef USE_NODE_COMPAT_CUSTOMNODES -#include "NOD_socket.h" /* for sock->default_value data */ +#include "NOD_socket.h" /* for sock->default_value data */ #endif @@ -184,6 +184,9 @@ #include "readfile.h" +/* for SDNA_TYPE_FROM_STRUCT() macro */ +#include "dna_type_offsets.h" + #include <errno.h> /* ********* my write, buffered writing with minimum size chunks ************ */ @@ -304,8 +307,9 @@ typedef struct { unsigned char *buf; MemFile *compare, *current; - - int tot, count, error; + + int tot, count; + bool error; /* Wrap writing, so we can use zlib or * other compression types later, see: G_FILE_COMPRESS @@ -313,27 +317,32 @@ typedef struct { WriteWrap *ww; #ifdef USE_BMESH_SAVE_AS_COMPAT - char use_mesh_compat; /* option to save with older mesh format */ + bool use_mesh_compat; /* option to save with older mesh format */ #endif } WriteData; static WriteData *writedata_new(WriteWrap *ww) { - WriteData *wd= MEM_callocN(sizeof(*wd), "writedata"); + WriteData *wd = MEM_callocN(sizeof(*wd), "writedata"); wd->sdna = DNA_sdna_from_data(DNAstr, DNAlen, false); wd->ww = ww; - wd->buf= MEM_mallocN(MYWRITE_BUFFER_SIZE, "wd->buf"); + wd->buf = MEM_mallocN(MYWRITE_BUFFER_SIZE, "wd->buf"); return wd; } static void writedata_do_write(WriteData *wd, const void *mem, int memlen) { - if ((wd == NULL) || wd->error || (mem == NULL) || memlen < 1) return; - if (wd->error) return; + if ((wd == NULL) || wd->error || (mem == NULL) || memlen < 1) { + return; + } + + if (UNLIKELY(wd->error)) { + return; + } /* memory based save */ if (wd->current) { @@ -341,7 +350,7 @@ static void writedata_do_write(WriteData *wd, const void *mem, int memlen) } else { if (wd->ww->write(wd->ww, mem, memlen) != memlen) { - wd->error = 1; + wd->error = true; } } } @@ -362,34 +371,36 @@ static void writedata_free(WriteData *wd) * \param len Length of new chunk of data * \warning Talks to other functions with global parameters */ - + #define MYWRITE_FLUSH NULL static void mywrite(WriteData *wd, const void *adr, int len) { - if (wd->error) return; + if (UNLIKELY(wd->error)) { + return; + } /* flush helps compression for undo-save */ - if (adr==MYWRITE_FLUSH) { + if (adr == MYWRITE_FLUSH) { if (wd->count) { writedata_do_write(wd, wd->buf, wd->count); - wd->count= 0; + wd->count = 0; } return; } - wd->tot+= len; - + wd->tot += len; + /* if we have a single big chunk, write existing data in * buffer and write out big chunk in smaller pieces */ - if (len>MYWRITE_MAX_CHUNK) { + if (len > MYWRITE_MAX_CHUNK) { if (wd->count) { writedata_do_write(wd, wd->buf, wd->count); - wd->count= 0; + wd->count = 0; } do { - int writelen= MIN2(len, MYWRITE_MAX_CHUNK); + int writelen = MIN2(len, MYWRITE_MAX_CHUNK); writedata_do_write(wd, adr, writelen); adr = (const char *)adr + writelen; len -= writelen; @@ -399,14 +410,14 @@ static void mywrite(WriteData *wd, const void *adr, int len) } /* if data would overflow buffer, write out the buffer */ - if (len+wd->count>MYWRITE_BUFFER_SIZE-1) { + if (len + wd->count > MYWRITE_BUFFER_SIZE - 1) { writedata_do_write(wd, wd->buf, wd->count); - wd->count= 0; + wd->count = 0; } /* append data at end of buffer */ memcpy(&wd->buf[wd->count], adr, len); - wd->count+= len; + wd->count += len; } /** @@ -418,15 +429,17 @@ static void mywrite(WriteData *wd, const void *adr, int len) */ static WriteData *bgnwrite(WriteWrap *ww, MemFile *compare, MemFile *current) { - WriteData *wd= writedata_new(ww); + WriteData *wd = writedata_new(ww); - if (wd == NULL) return NULL; + if (wd == NULL) { + return NULL; + } - wd->compare= compare; - wd->current= current; + wd->compare = compare; + wd->current = current; /* this inits comparing */ memfile_chunk_add(compare, NULL, NULL, 0); - + return wd; } @@ -436,16 +449,14 @@ static WriteData *bgnwrite(WriteWrap *ww, MemFile *compare, MemFile *current) * \return unknown global variable otherwise * \warning Talks to other functions with global parameters */ -static int endwrite(WriteData *wd) +static bool endwrite(WriteData *wd) { - int err; - if (wd->count) { writedata_do_write(wd, wd->buf, wd->count); - wd->count= 0; + wd->count = 0; } - - err= wd->error; + + const bool err = wd->error; writedata_free(wd); return err; @@ -453,48 +464,75 @@ static int endwrite(WriteData *wd) /* ********** WRITE FILE ****************** */ -static void writestruct_at_address( - WriteData *wd, int filecode, const char *structname, int nr, +static void writestruct_at_address_nr( + WriteData *wd, int filecode, const int struct_nr, int nr, const void *adr, const void *data) { BHead bh; const short *sp; - if (adr==NULL || data==NULL || nr==0) return; - - /* init BHead */ - bh.code= filecode; - bh.old= adr; - bh.nr= nr; + BLI_assert(struct_nr > 0 && struct_nr < SDNA_TYPE_MAX); - bh.SDNAnr= DNA_struct_find_nr(wd->sdna, structname); - if (bh.SDNAnr== -1) { - printf("error: can't find SDNA code <%s>\n", structname); + if (adr == NULL || data == NULL || nr == 0) { return; } - sp= wd->sdna->structs[bh.SDNAnr]; - bh.len= nr*wd->sdna->typelens[sp[0]]; + /* init BHead */ + bh.code = filecode; + bh.old = adr; + bh.nr = nr; + + bh.SDNAnr = struct_nr; + sp = wd->sdna->structs[bh.SDNAnr]; + + bh.len = nr * wd->sdna->typelens[sp[0]]; - if (bh.len==0) return; + if (bh.len == 0) { + return; + } mywrite(wd, &bh, sizeof(BHead)); mywrite(wd, data, bh.len); } -static void writestruct( +static void writestruct_at_address_id( WriteData *wd, int filecode, const char *structname, int nr, + const void *adr, const void *data) +{ + if (adr == NULL || data == NULL || nr == 0) { + return; + } + + const int SDNAnr = DNA_struct_find_nr(wd->sdna, structname); + if (UNLIKELY(SDNAnr == -1)) { + printf("error: can't find SDNA code <%s>\n", structname); + return; + } + + writestruct_at_address_nr(wd, filecode, SDNAnr, nr, adr, data); +} + +static void writestruct_nr( + WriteData *wd, int filecode, const int struct_nr, int nr, const void *adr) { - writestruct_at_address(wd, filecode, structname, nr, adr, adr); + writestruct_at_address_nr(wd, filecode, struct_nr, nr, adr, adr); +} + +static void writestruct_id( + WriteData *wd, int filecode, const char *structname, int nr, + const void *adr) +{ + writestruct_at_address_id(wd, filecode, structname, nr, adr, adr); } static void writedata(WriteData *wd, int filecode, int len, const void *adr) /* do not use for structs */ { BHead bh; - if (adr==NULL) return; - if (len==0) return; + if (adr == NULL || len == 0) { + return; + } /* align to 4 (writes uninitialized bytes in some cases) */ len = (len + 3) & ~3; @@ -511,16 +549,45 @@ static void writedata(WriteData *wd, int filecode, int len, const void *adr) /* } /* use this to force writing of lists in same order as reading (using link_list) */ -static void writelist(WriteData *wd, int filecode, const char *structname, const ListBase *lb) +static void writelist_nr(WriteData *wd, int filecode, const int struct_nr, const ListBase *lb) { const Link *link = lb->first; - + while (link) { - writestruct(wd, filecode, structname, 1, link); + writestruct_nr(wd, filecode, struct_nr, 1, link); link = link->next; } } +#if 0 +static void writelist_id(WriteData *wd, int filecode, const char *structname, const ListBase *lb) +{ + const Link *link = lb->first; + if (link) { + + const int struct_nr = DNA_struct_find_nr(wd->sdna, structname); + if (struct_nr == -1) { + printf("error: can't find SDNA code <%s>\n", structname); + return; + } + + while (link) { + writestruct_nr(wd, filecode, struct_nr, 1, link); + link = link->next; + } + } +} +#endif + +#define writestruct_at_address(wd, filecode, struct_id, nr, adr, data) \ + writestruct_at_address_nr(wd, filecode, SDNA_TYPE_FROM_STRUCT(struct_id), nr, adr, data) + +#define writestruct(wd, filecode, struct_id, nr, adr) \ + writestruct_nr(wd, filecode, SDNA_TYPE_FROM_STRUCT(struct_id), nr, adr) + +#define writelist(wd, filecode, struct_id, lb) \ + writelist_nr(wd, filecode, SDNA_TYPE_FROM_STRUCT(struct_id), lb) + /* *************** writing some direct data structs used in more code parts **************** */ /*These functions are used by blender's .blend system for file saving/loading.*/ void IDP_WriteProperty_OnlyData(const IDProperty *prop, void *wd); @@ -533,11 +600,12 @@ static void IDP_WriteArray(const IDProperty *prop, void *wd) writedata(wd, DATA, MEM_allocN_len(prop->data.pointer), prop->data.pointer); if (prop->subtype == IDP_GROUP) { - IDProperty **array= prop->data.pointer; + IDProperty **array = prop->data.pointer; int a; - for (a=0; a<prop->len; a++) + for (a = 0; a < prop->len; a++) { IDP_WriteProperty(array[a], wd); + } } } } @@ -549,10 +617,11 @@ static void IDP_WriteIDPArray(const IDProperty *prop, void *wd) const IDProperty *array = prop->data.pointer; int a; - writestruct(wd, DATA, "IDProperty", prop->len, array); + writestruct(wd, DATA, IDProperty, prop->len, array); - for (a=0; a<prop->len; a++) + for (a = 0; a < prop->len; a++) { IDP_WriteProperty_OnlyData(&array[a], wd); + } } } @@ -566,7 +635,7 @@ static void IDP_WriteGroup(const IDProperty *prop, void *wd) { IDProperty *loop; - for (loop=prop->data.group.first; loop; loop=loop->next) { + for (loop = prop->data.group.first; loop; loop = loop->next) { IDP_WriteProperty(loop, wd); } } @@ -592,7 +661,7 @@ void IDP_WriteProperty_OnlyData(const IDProperty *prop, void *wd) void IDP_WriteProperty(const IDProperty *prop, void *wd) { - writestruct(wd, DATA, "IDProperty", 1, prop); + writestruct(wd, DATA, IDProperty, 1, prop); IDP_WriteProperty_OnlyData(prop, wd); } @@ -616,7 +685,7 @@ static void write_previews(WriteData *wd, const PreviewImage *prv_orig) prv.h[1] = 0; prv.rect[1] = NULL; } - writestruct_at_address(wd, DATA, "PreviewImage", 1, prv_orig, &prv); + writestruct_at_address(wd, DATA, PreviewImage, 1, prv_orig, &prv); if (prv.rect[0]) { writedata(wd, DATA, prv.w[0] * prv.h[0] * sizeof(unsigned int), prv.rect[0]); } @@ -629,45 +698,47 @@ static void write_previews(WriteData *wd, const PreviewImage *prv_orig) static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers) { FModifier *fcm; - + /* Write all modifiers first (for faster reloading) */ - writelist(wd, DATA, "FModifier", fmodifiers); - + writelist(wd, DATA, FModifier, fmodifiers); + /* Modifiers */ - for (fcm= fmodifiers->first; fcm; fcm= fcm->next) { - const FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm); - + for (fcm = fmodifiers->first; fcm; fcm = fcm->next) { + const FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm); + /* Write the specific data */ if (fmi && fcm->data) { /* firstly, just write the plain fmi->data struct */ - writestruct(wd, DATA, fmi->structName, 1, fcm->data); - + writestruct_id(wd, DATA, fmi->structName, 1, fcm->data); + /* do any modifier specific stuff */ switch (fcm->type) { case FMODIFIER_TYPE_GENERATOR: { - FMod_Generator *data= (FMod_Generator *)fcm->data; - + FMod_Generator *data = fcm->data; + /* write coefficients array */ - if (data->coefficients) - writedata(wd, DATA, sizeof(float)*(data->arraysize), data->coefficients); + if (data->coefficients) { + writedata(wd, DATA, sizeof(float) * (data->arraysize), data->coefficients); + } break; } case FMODIFIER_TYPE_ENVELOPE: { - FMod_Envelope *data= (FMod_Envelope *)fcm->data; - + FMod_Envelope *data = fcm->data; + /* write envelope data */ - if (data->data) - writestruct(wd, DATA, "FCM_EnvelopeData", data->totvert, data->data); + if (data->data) { + writestruct(wd, DATA, FCM_EnvelopeData, data->totvert, data->data); + } break; } case FMODIFIER_TYPE_PYTHON: { - FMod_Python *data = (FMod_Python *)fcm->data; - + FMod_Python *data = fcm->data; + /* Write ID Properties -- and copy this comment EXACTLY for easy finding * of library blocks that implement this.*/ IDP_WriteProperty(data->prop, wd); @@ -682,37 +753,41 @@ static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers) static void write_fcurves(WriteData *wd, ListBase *fcurves) { FCurve *fcu; - - writelist(wd, DATA, "FCurve", fcurves); - for (fcu=fcurves->first; fcu; fcu=fcu->next) { + + writelist(wd, DATA, FCurve, fcurves); + for (fcu = fcurves->first; fcu; fcu = fcu->next) { /* curve data */ - if (fcu->bezt) - writestruct(wd, DATA, "BezTriple", fcu->totvert, fcu->bezt); - if (fcu->fpt) - writestruct(wd, DATA, "FPoint", fcu->totvert, fcu->fpt); - - if (fcu->rna_path) - writedata(wd, DATA, strlen(fcu->rna_path)+1, fcu->rna_path); - + if (fcu->bezt) { + writestruct(wd, DATA, BezTriple, fcu->totvert, fcu->bezt); + } + if (fcu->fpt) { + writestruct(wd, DATA, FPoint, fcu->totvert, fcu->fpt); + } + + if (fcu->rna_path) { + writedata(wd, DATA, strlen(fcu->rna_path) + 1, fcu->rna_path); + } + /* driver data */ if (fcu->driver) { - ChannelDriver *driver= fcu->driver; + ChannelDriver *driver = fcu->driver; DriverVar *dvar; - - writestruct(wd, DATA, "ChannelDriver", 1, driver); - + + writestruct(wd, DATA, ChannelDriver, 1, driver); + /* variables */ - writelist(wd, DATA, "DriverVar", &driver->variables); - for (dvar= driver->variables.first; dvar; dvar= dvar->next) { + writelist(wd, DATA, DriverVar, &driver->variables); + for (dvar = driver->variables.first; dvar; dvar = dvar->next) { DRIVER_TARGETS_USED_LOOPER(dvar) { - if (dtar->rna_path) - writedata(wd, DATA, strlen(dtar->rna_path)+1, dtar->rna_path); + if (dtar->rna_path) { + writedata(wd, DATA, strlen(dtar->rna_path) + 1, dtar->rna_path); + } } DRIVER_TARGETS_LOOPER_END } } - + /* write F-Modifiers */ write_fmodifiers(wd, &fcu->modifiers); } @@ -720,27 +795,27 @@ static void write_fcurves(WriteData *wd, ListBase *fcurves) static void write_actions(WriteData *wd, ListBase *idbase) { - bAction *act; + bAction *act; bActionGroup *grp; TimeMarker *marker; - - for (act=idbase->first; act; act= act->id.next) { - if (act->id.us>0 || wd->current) { - writestruct(wd, ID_AC, "bAction", 1, act); + + for (act = idbase->first; act; act = act->id.next) { + if (act->id.us > 0 || wd->current) { + writestruct(wd, ID_AC, bAction, 1, act); write_iddata(wd, &act->id); write_fcurves(wd, &act->curves); - - for (grp=act->groups.first; grp; grp=grp->next) { - writestruct(wd, DATA, "bActionGroup", 1, grp); + + for (grp = act->groups.first; grp; grp = grp->next) { + writestruct(wd, DATA, bActionGroup, 1, grp); } - - for (marker=act->markers.first; marker; marker=marker->next) { - writestruct(wd, DATA, "TimeMarker", 1, marker); + + for (marker = act->markers.first; marker; marker = marker->next) { + writestruct(wd, DATA, TimeMarker, 1, marker); } } } - + /* flush helps the compression for undo-save */ mywrite(wd, MYWRITE_FLUSH, 0); } @@ -749,18 +824,19 @@ static void write_keyingsets(WriteData *wd, ListBase *list) { KeyingSet *ks; KS_Path *ksp; - - for (ks= list->first; ks; ks= ks->next) { + + for (ks = list->first; ks; ks = ks->next) { /* KeyingSet */ - writestruct(wd, DATA, "KeyingSet", 1, ks); - + writestruct(wd, DATA, KeyingSet, 1, ks); + /* Paths */ - for (ksp= ks->paths.first; ksp; ksp= ksp->next) { + for (ksp = ks->paths.first; ksp; ksp = ksp->next) { /* Path */ - writestruct(wd, DATA, "KS_Path", 1, ksp); - - if (ksp->rna_path) - writedata(wd, DATA, strlen(ksp->rna_path)+1, ksp->rna_path); + writestruct(wd, DATA, KS_Path, 1, ksp); + + if (ksp->rna_path) { + writedata(wd, DATA, strlen(ksp->rna_path) + 1, ksp->rna_path); + } } } } @@ -768,13 +844,13 @@ static void write_keyingsets(WriteData *wd, ListBase *list) static void write_nlastrips(WriteData *wd, ListBase *strips) { NlaStrip *strip; - - writelist(wd, DATA, "NlaStrip", strips); - for (strip= strips->first; strip; strip= strip->next) { + + writelist(wd, DATA, NlaStrip, strips); + for (strip = strips->first; strip; strip = strip->next) { /* write the strip's F-Curves and modifiers */ write_fcurves(wd, &strip->fcurves); write_fmodifiers(wd, &strip->modifiers); - + /* write the strip's children */ write_nlastrips(wd, &strip->strips); } @@ -783,12 +859,12 @@ static void write_nlastrips(WriteData *wd, ListBase *strips) static void write_nladata(WriteData *wd, ListBase *nlabase) { NlaTrack *nlt; - + /* write all the tracks */ - for (nlt= nlabase->first; nlt; nlt= nlt->next) { + for (nlt = nlabase->first; nlt; nlt = nlt->next) { /* write the track first */ - writestruct(wd, DATA, "NlaTrack", 1, nlt); - + writestruct(wd, DATA, NlaTrack, 1, nlt); + /* write the track's strips */ write_nlastrips(wd, &nlt->strips); } @@ -797,38 +873,37 @@ static void write_nladata(WriteData *wd, ListBase *nlabase) static void write_animdata(WriteData *wd, AnimData *adt) { AnimOverride *aor; - + /* firstly, just write the AnimData block */ - writestruct(wd, DATA, "AnimData", 1, adt); - + writestruct(wd, DATA, AnimData, 1, adt); + /* write drivers */ write_fcurves(wd, &adt->drivers); - + /* write overrides */ // FIXME: are these needed? - for (aor= adt->overrides.first; aor; aor= aor->next) { + for (aor = adt->overrides.first; aor; aor = aor->next) { /* overrides consist of base data + rna_path */ - writestruct(wd, DATA, "AnimOverride", 1, aor); - writedata(wd, DATA, strlen(aor->rna_path)+1, aor->rna_path); + writestruct(wd, DATA, AnimOverride, 1, aor); + writedata(wd, DATA, strlen(aor->rna_path) + 1, aor->rna_path); } - + // TODO write the remaps (if they are needed) - + /* write NLA data */ write_nladata(wd, &adt->nla_tracks); } static void write_curvemapping_curves(WriteData *wd, CurveMapping *cumap) { - int a; - - for (a = 0; a < CM_TOT; a++) - writestruct(wd, DATA, "CurveMapPoint", cumap->cm[a].totpoint, cumap->cm[a].curve); + for (int a = 0; a < CM_TOT; a++) { + writestruct(wd, DATA, CurveMapPoint, cumap->cm[a].totpoint, cumap->cm[a].curve); + } } static void write_curvemapping(WriteData *wd, CurveMapping *cumap) { - writestruct(wd, DATA, "CurveMapping", 1, cumap); + writestruct(wd, DATA, CurveMapping, 1, cumap); write_curvemapping_curves(wd, cumap); } @@ -838,14 +913,14 @@ static void write_node_socket(WriteData *wd, bNodeTree *UNUSED(ntree), bNode *no #ifdef USE_NODE_COMPAT_CUSTOMNODES /* forward compatibility code, so older blenders still open */ sock->stack_type = 1; - + if (node->type == NODE_GROUP) { bNodeTree *ngroup = (bNodeTree *)node->id; if (ngroup) { /* for node groups: look up the deprecated groupsock pointer */ sock->groupsock = ntreeFindSocketInterface(ngroup, sock->in_out, sock->identifier); BLI_assert(sock->groupsock != NULL); - + /* node group sockets now use the generic identifier string to verify group nodes, * old blender uses the own_index. */ @@ -855,20 +930,22 @@ static void write_node_socket(WriteData *wd, bNodeTree *UNUSED(ntree), bNode *no #endif /* actual socket writing */ - writestruct(wd, DATA, "bNodeSocket", 1, sock); + writestruct(wd, DATA, bNodeSocket, 1, sock); - if (sock->prop) + if (sock->prop) { IDP_WriteProperty(sock->prop, wd); - - if (sock->default_value) + } + + if (sock->default_value) { writedata(wd, DATA, MEM_allocN_len(sock->default_value), sock->default_value); + } } static void write_node_socket_interface(WriteData *wd, bNodeTree *UNUSED(ntree), bNodeSocket *sock) { #ifdef USE_NODE_COMPAT_CUSTOMNODES /* forward compatibility code, so older blenders still open */ sock->stack_type = 1; - + /* Reconstruct the deprecated default_value structs in socket interface DNA. */ if (sock->default_value == NULL && sock->typeinfo) { node_socket_init_default_value(sock); @@ -876,13 +953,15 @@ static void write_node_socket_interface(WriteData *wd, bNodeTree *UNUSED(ntree), #endif /* actual socket writing */ - writestruct(wd, DATA, "bNodeSocket", 1, sock); + writestruct(wd, DATA, bNodeSocket, 1, sock); - if (sock->prop) + if (sock->prop) { IDP_WriteProperty(sock->prop, wd); - - if (sock->default_value) + } + + if (sock->default_value) { writedata(wd, DATA, MEM_allocN_len(sock->default_value), sock->default_value); + } } /* this is only direct data, tree itself should have been written */ static void write_nodetree(WriteData *wd, bNodeTree *ntree) @@ -890,64 +969,91 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree) bNode *node; bNodeSocket *sock; bNodeLink *link; - + /* for link_list() speed, we write per list */ - - if (ntree->adt) write_animdata(wd, ntree->adt); - + + if (ntree->adt) { + write_animdata(wd, ntree->adt); + } + for (node = ntree->nodes.first; node; node = node->next) { - writestruct(wd, DATA, "bNode", 1, node); + writestruct(wd, DATA, bNode, 1, node); - if (node->prop) + if (node->prop) { IDP_WriteProperty(node->prop, wd); + } - for (sock= node->inputs.first; sock; sock= sock->next) + for (sock = node->inputs.first; sock; sock = sock->next) { write_node_socket(wd, ntree, node, sock); - for (sock= node->outputs.first; sock; sock= sock->next) + } + for (sock = node->outputs.first; sock; sock = sock->next) { write_node_socket(wd, ntree, node, sock); - - for (link = node->internal_links.first; link; link = link->next) - writestruct(wd, DATA, "bNodeLink", 1, link); + } + + for (link = node->internal_links.first; link; link = link->next) { + writestruct(wd, DATA, bNodeLink, 1, link); + } + if (node->storage) { /* could be handlerized at some point, now only 1 exception still */ - if (ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB)) + if ((ntree->type == NTREE_SHADER) && + ELEM(node->type, SH_NODE_CURVE_VEC, SH_NODE_CURVE_RGB)) + { write_curvemapping(wd, node->storage); - else if (ntree->type==NTREE_SHADER && node->type==SH_NODE_SCRIPT) { + } + else if (ntree->type == NTREE_SHADER && + (node->type == SH_NODE_SCRIPT)) + { NodeShaderScript *nss = (NodeShaderScript *)node->storage; - if (nss->bytecode) - writedata(wd, DATA, strlen(nss->bytecode)+1, nss->bytecode); - writestruct(wd, DATA, node->typeinfo->storagename, 1, node->storage); + if (nss->bytecode) { + writedata(wd, DATA, strlen(nss->bytecode) + 1, nss->bytecode); + } + writestruct_id(wd, DATA, node->typeinfo->storagename, 1, node->storage); } - else if (ntree->type==NTREE_COMPOSIT && ELEM(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT)) + else if ((ntree->type == NTREE_COMPOSIT) && + ELEM(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT)) + { write_curvemapping(wd, node->storage); - else if (ntree->type==NTREE_TEXTURE && (node->type==TEX_NODE_CURVE_RGB || node->type==TEX_NODE_CURVE_TIME) ) + } + else if ((ntree->type == NTREE_TEXTURE) && + (node->type == TEX_NODE_CURVE_RGB || node->type == TEX_NODE_CURVE_TIME)) + { write_curvemapping(wd, node->storage); - else if (ntree->type==NTREE_COMPOSIT && node->type==CMP_NODE_MOVIEDISTORTION) { + } + else if ((ntree->type == NTREE_COMPOSIT) && + (node->type == CMP_NODE_MOVIEDISTORTION)) + { /* pass */ } - else - writestruct(wd, DATA, node->typeinfo->storagename, 1, node->storage); + else { + writestruct_id(wd, DATA, node->typeinfo->storagename, 1, node->storage); + } } - - if (node->type==CMP_NODE_OUTPUT_FILE) { + + if (node->type == CMP_NODE_OUTPUT_FILE) { /* inputs have own storage data */ - for (sock = node->inputs.first; sock; sock = sock->next) - writestruct(wd, DATA, "NodeImageMultiFileSocket", 1, sock->storage); + for (sock = node->inputs.first; sock; sock = sock->next) { + writestruct(wd, DATA, NodeImageMultiFileSocket, 1, sock->storage); + } } - if (node->type==CMP_NODE_IMAGE) { + if (node->type == CMP_NODE_IMAGE) { /* write extra socket info */ - for (sock = node->outputs.first; sock; sock = sock->next) - writestruct(wd, DATA, "NodeImageLayer", 1, sock->storage); + for (sock = node->outputs.first; sock; sock = sock->next) { + writestruct(wd, DATA, NodeImageLayer, 1, sock->storage); + } } } - - for (link= ntree->links.first; link; link= link->next) - writestruct(wd, DATA, "bNodeLink", 1, link); - - for (sock = ntree->inputs.first; sock; sock = sock->next) + + for (link = ntree->links.first; link; link = link->next) { + writestruct(wd, DATA, bNodeLink, 1, link); + } + + for (sock = ntree->inputs.first; sock; sock = sock->next) { write_node_socket_interface(wd, ntree, sock); - for (sock = ntree->outputs.first; sock; sock = sock->next) + } + for (sock = ntree->outputs.first; sock; sock = sock->next) { write_node_socket_interface(wd, ntree, sock); + } } /** @@ -1002,9 +1108,11 @@ static void write_renderinfo(WriteData *wd, Main *mainvar) /* XXX in future, handle multiple windows with multiple screens? */ current_screen_compat(mainvar, &curscreen, false); - if (curscreen) curscene = curscreen->scene; - - for (sce= mainvar->scene.first; sce; sce= sce->id.next) { + if (curscreen) { + curscene = curscreen->scene; + } + + for (sce = mainvar->scene.first; sce; sce = sce->id.next) { if (sce->id.lib == NULL && (sce == curscene || (sce->r.scemode & R_BG_RENDER))) { data.sfra = sce->r.sfra; data.efra = sce->r.efra; @@ -1019,9 +1127,10 @@ static void write_renderinfo(WriteData *wd, Main *mainvar) static void write_keymapitem(WriteData *wd, wmKeyMapItem *kmi) { - writestruct(wd, DATA, "wmKeyMapItem", 1, kmi); - if (kmi->properties) + writestruct(wd, DATA, wmKeyMapItem, 1, kmi); + if (kmi->properties) { IDP_WriteProperty(kmi->properties, wd); + } } static void write_userdef(WriteData *wd) @@ -1033,75 +1142,82 @@ static void write_userdef(WriteData *wd) bAddon *bext; bPathCompare *path_cmp; uiStyle *style; - - writestruct(wd, USER, "UserDef", 1, &U); - for (btheme= U.themes.first; btheme; btheme=btheme->next) - writestruct(wd, DATA, "bTheme", 1, btheme); + writestruct(wd, USER, UserDef, 1, &U); + + for (btheme = U.themes.first; btheme; btheme = btheme->next) { + writestruct(wd, DATA, bTheme, 1, btheme); + } - for (keymap= U.user_keymaps.first; keymap; keymap=keymap->next) { - writestruct(wd, DATA, "wmKeyMap", 1, keymap); + for (keymap = U.user_keymaps.first; keymap; keymap = keymap->next) { + writestruct(wd, DATA, wmKeyMap, 1, keymap); - for (kmdi=keymap->diff_items.first; kmdi; kmdi=kmdi->next) { - writestruct(wd, DATA, "wmKeyMapDiffItem", 1, kmdi); - if (kmdi->remove_item) + for (kmdi = keymap->diff_items.first; kmdi; kmdi = kmdi->next) { + writestruct(wd, DATA, wmKeyMapDiffItem, 1, kmdi); + if (kmdi->remove_item) { write_keymapitem(wd, kmdi->remove_item); - if (kmdi->add_item) + } + if (kmdi->add_item) { write_keymapitem(wd, kmdi->add_item); + } } - for (kmi=keymap->items.first; kmi; kmi=kmi->next) + for (kmi = keymap->items.first; kmi; kmi = kmi->next) { write_keymapitem(wd, kmi); + } } - for (bext= U.addons.first; bext; bext=bext->next) { - writestruct(wd, DATA, "bAddon", 1, bext); + for (bext = U.addons.first; bext; bext = bext->next) { + writestruct(wd, DATA, bAddon, 1, bext); if (bext->prop) { IDP_WriteProperty(bext->prop, wd); } } for (path_cmp = U.autoexec_paths.first; path_cmp; path_cmp = path_cmp->next) { - writestruct(wd, DATA, "bPathCompare", 1, path_cmp); + writestruct(wd, DATA, bPathCompare, 1, path_cmp); } - - for (style= U.uistyles.first; style; style= style->next) { - writestruct(wd, DATA, "uiStyle", 1, style); + + for (style = U.uistyles.first; style; style = style->next) { + writestruct(wd, DATA, uiStyle, 1, style); } } static void write_boid_state(WriteData *wd, BoidState *state) { BoidRule *rule = state->rules.first; - //BoidCondition *cond = state->conditions.first; - writestruct(wd, DATA, "BoidState", 1, state); + writestruct(wd, DATA, BoidState, 1, state); - for (; rule; rule=rule->next) { + for (; rule; rule = rule->next) { switch (rule->type) { case eBoidRuleType_Goal: case eBoidRuleType_Avoid: - writestruct(wd, DATA, "BoidRuleGoalAvoid", 1, rule); + writestruct(wd, DATA, BoidRuleGoalAvoid, 1, rule); break; case eBoidRuleType_AvoidCollision: - writestruct(wd, DATA, "BoidRuleAvoidCollision", 1, rule); + writestruct(wd, DATA, BoidRuleAvoidCollision, 1, rule); break; case eBoidRuleType_FollowLeader: - writestruct(wd, DATA, "BoidRuleFollowLeader", 1, rule); + writestruct(wd, DATA, BoidRuleFollowLeader, 1, rule); break; case eBoidRuleType_AverageSpeed: - writestruct(wd, DATA, "BoidRuleAverageSpeed", 1, rule); + writestruct(wd, DATA, BoidRuleAverageSpeed, 1, rule); break; case eBoidRuleType_Fight: - writestruct(wd, DATA, "BoidRuleFight", 1, rule); + writestruct(wd, DATA, BoidRuleFight, 1, rule); break; default: - writestruct(wd, DATA, "BoidRule", 1, rule); + writestruct(wd, DATA, BoidRule, 1, rule); break; } } - //for (; cond; cond=cond->next) - // writestruct(wd, DATA, "BoidCondition", 1, cond); +#if 0 + BoidCondition *cond = state->conditions.first; + for (; cond; cond = cond->next) { + writestruct(wd, DATA, BoidCondition, 1, cond); + } +#endif } /* update this also to readfile.c */ @@ -1124,31 +1240,34 @@ static void write_pointcaches(WriteData *wd, ListBase *ptcaches) PointCache *cache = ptcaches->first; int i; - for (; cache; cache=cache->next) { - writestruct(wd, DATA, "PointCache", 1, cache); + for (; cache; cache = cache->next) { + writestruct(wd, DATA, PointCache, 1, cache); - if ((cache->flag & PTCACHE_DISK_CACHE)==0) { + if ((cache->flag & PTCACHE_DISK_CACHE) == 0) { PTCacheMem *pm = cache->mem_cache.first; - for (; pm; pm=pm->next) { + for (; pm; pm = pm->next) { PTCacheExtra *extra = pm->extradata.first; - writestruct(wd, DATA, "PTCacheMem", 1, pm); - - for (i=0; i<BPHYS_TOT_DATA; i++) { - if (pm->data[i] && pm->data_types & (1<<i)) { - if (ptcache_data_struct[i][0] == '\0') + writestruct(wd, DATA, PTCacheMem, 1, pm); + + for (i = 0; i < BPHYS_TOT_DATA; i++) { + if (pm->data[i] && pm->data_types & (1 << i)) { + if (ptcache_data_struct[i][0] == '\0') { writedata(wd, DATA, MEM_allocN_len(pm->data[i]), pm->data[i]); - else - writestruct(wd, DATA, ptcache_data_struct[i], pm->totpoint, pm->data[i]); + } + else { + writestruct_id(wd, DATA, ptcache_data_struct[i], pm->totpoint, pm->data[i]); + } } } - for (; extra; extra=extra->next) { - if (ptcache_extra_struct[extra->type][0] == '\0') + for (; extra; extra = extra->next) { + if (ptcache_extra_struct[extra->type][0] == '\0') { continue; - writestruct(wd, DATA, "PTCacheExtra", 1, extra); - writestruct(wd, DATA, ptcache_extra_struct[extra->type], extra->totdata, extra->data); + } + writestruct(wd, DATA, PTCacheExtra, 1, extra); + writestruct_id(wd, DATA, ptcache_extra_struct[extra->type], extra->totdata, extra->data); } } } @@ -1161,91 +1280,109 @@ static void write_particlesettings(WriteData *wd, ListBase *idbase) GroupObject *go; int a; - part= idbase->first; + part = idbase->first; while (part) { - if (part->id.us>0 || wd->current) { + if (part->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_PA, "ParticleSettings", 1, part); + writestruct(wd, ID_PA, ParticleSettings, 1, part); write_iddata(wd, &part->id); - if (part->adt) write_animdata(wd, part->adt); - writestruct(wd, DATA, "PartDeflect", 1, part->pd); - writestruct(wd, DATA, "PartDeflect", 1, part->pd2); - writestruct(wd, DATA, "EffectorWeights", 1, part->effector_weights); + if (part->adt) { + write_animdata(wd, part->adt); + } + writestruct(wd, DATA, PartDeflect, 1, part->pd); + writestruct(wd, DATA, PartDeflect, 1, part->pd2); + writestruct(wd, DATA, EffectorWeights, 1, part->effector_weights); - if (part->clumpcurve) + if (part->clumpcurve) { write_curvemapping(wd, part->clumpcurve); - if (part->roughcurve) + } + if (part->roughcurve) { write_curvemapping(wd, part->roughcurve); - + } + dw = part->dupliweights.first; - for (; dw; dw=dw->next) { + for (; dw; dw = dw->next) { /* update indices */ dw->index = 0; if (part->dup_group) { /* can be NULL if lining fails or set to None */ go = part->dup_group->gobject.first; while (go && go->ob != dw->ob) { - go=go->next; + go = go->next; dw->index++; } } - writestruct(wd, DATA, "ParticleDupliWeight", 1, dw); + writestruct(wd, DATA, ParticleDupliWeight, 1, dw); } if (part->boids && part->phystype == PART_PHYS_BOIDS) { BoidState *state = part->boids->states.first; - writestruct(wd, DATA, "BoidSettings", 1, part->boids); + writestruct(wd, DATA, BoidSettings, 1, part->boids); - for (; state; state=state->next) + for (; state; state = state->next) { write_boid_state(wd, state); + } } if (part->fluid && part->phystype == PART_PHYS_FLUID) { - writestruct(wd, DATA, "SPHFluidSettings", 1, part->fluid); + writestruct(wd, DATA, SPHFluidSettings, 1, part->fluid); } - for (a=0; a<MAX_MTEX; a++) { - if (part->mtex[a]) writestruct(wd, DATA, "MTex", 1, part->mtex[a]); + for (a = 0; a < MAX_MTEX; a++) { + if (part->mtex[a]) { + writestruct(wd, DATA, MTex, 1, part->mtex[a]); + } } } - part= part->id.next; + part = part->id.next; } } static void write_particlesystems(WriteData *wd, ListBase *particles) { - ParticleSystem *psys= particles->first; + ParticleSystem *psys = particles->first; ParticleTarget *pt; int a; - for (; psys; psys=psys->next) { - writestruct(wd, DATA, "ParticleSystem", 1, psys); + for (; psys; psys = psys->next) { + writestruct(wd, DATA, ParticleSystem, 1, psys); if (psys->particles) { - writestruct(wd, DATA, "ParticleData", psys->totpart, psys->particles); + writestruct(wd, DATA, ParticleData, psys->totpart, psys->particles); if (psys->particles->hair) { ParticleData *pa = psys->particles; - for (a=0; a<psys->totpart; a++, pa++) - writestruct(wd, DATA, "HairKey", pa->totkey, pa->hair); + for (a = 0; a < psys->totpart; a++, pa++) { + writestruct(wd, DATA, HairKey, pa->totkey, pa->hair); + } } - if (psys->particles->boid && psys->part->phystype == PART_PHYS_BOIDS) - writestruct(wd, DATA, "BoidParticle", psys->totpart, psys->particles->boid); + if (psys->particles->boid && + (psys->part->phystype == PART_PHYS_BOIDS)) + { + writestruct(wd, DATA, BoidParticle, psys->totpart, psys->particles->boid); + } - if (psys->part->fluid && psys->part->phystype == PART_PHYS_FLUID && (psys->part->fluid->flag & SPH_VISCOELASTIC_SPRINGS)) - writestruct(wd, DATA, "ParticleSpring", psys->tot_fluidsprings, psys->fluid_springs); + if (psys->part->fluid && + (psys->part->phystype == PART_PHYS_FLUID) && + (psys->part->fluid->flag & SPH_VISCOELASTIC_SPRINGS)) + { + writestruct(wd, DATA, ParticleSpring, psys->tot_fluidsprings, psys->fluid_springs); + } } pt = psys->targets.first; - for (; pt; pt=pt->next) - writestruct(wd, DATA, "ParticleTarget", 1, pt); + for (; pt; pt = pt->next) { + writestruct(wd, DATA, ParticleTarget, 1, pt); + } - if (psys->child) writestruct(wd, DATA, "ChildParticle", psys->totchild, psys->child); + if (psys->child) { + writestruct(wd, DATA, ChildParticle, psys->totchild, psys->child); + } if (psys->clmd) { - writestruct(wd, DATA, "ClothModifierData", 1, psys->clmd); - writestruct(wd, DATA, "ClothSimSettings", 1, psys->clmd->sim_parms); - writestruct(wd, DATA, "ClothCollSettings", 1, psys->clmd->coll_parms); + writestruct(wd, DATA, ClothModifierData, 1, psys->clmd); + writestruct(wd, DATA, ClothSimSettings, 1, psys->clmd->sim_parms); + writestruct(wd, DATA, ClothCollSettings, 1, psys->clmd->coll_parms); } write_pointcaches(wd, &psys->ptcaches); @@ -1256,14 +1393,15 @@ static void write_properties(WriteData *wd, ListBase *lb) { bProperty *prop; - prop= lb->first; + prop = lb->first; while (prop) { - writestruct(wd, DATA, "bProperty", 1, prop); + writestruct(wd, DATA, bProperty, 1, prop); - if (prop->poin && prop->poin != &prop->data) + if (prop->poin && prop->poin != &prop->data) { writedata(wd, DATA, MEM_allocN_len(prop->poin), prop->poin); + } - prop= prop->next; + prop = prop->next; } } @@ -1271,57 +1409,57 @@ static void write_sensors(WriteData *wd, ListBase *lb) { bSensor *sens; - sens= lb->first; + sens = lb->first; while (sens) { - writestruct(wd, DATA, "bSensor", 1, sens); + writestruct(wd, DATA, bSensor, 1, sens); - writedata(wd, DATA, sizeof(void *)*sens->totlinks, sens->links); + writedata(wd, DATA, sizeof(void *) * sens->totlinks, sens->links); switch (sens->type) { - case SENS_NEAR: - writestruct(wd, DATA, "bNearSensor", 1, sens->data); - break; - case SENS_MOUSE: - writestruct(wd, DATA, "bMouseSensor", 1, sens->data); - break; - case SENS_KEYBOARD: - writestruct(wd, DATA, "bKeyboardSensor", 1, sens->data); - break; - case SENS_PROPERTY: - writestruct(wd, DATA, "bPropertySensor", 1, sens->data); - break; - case SENS_ARMATURE: - writestruct(wd, DATA, "bArmatureSensor", 1, sens->data); - break; - case SENS_ACTUATOR: - writestruct(wd, DATA, "bActuatorSensor", 1, sens->data); - break; - case SENS_DELAY: - writestruct(wd, DATA, "bDelaySensor", 1, sens->data); - break; - case SENS_COLLISION: - writestruct(wd, DATA, "bCollisionSensor", 1, sens->data); - break; - case SENS_RADAR: - writestruct(wd, DATA, "bRadarSensor", 1, sens->data); - break; - case SENS_RANDOM: - writestruct(wd, DATA, "bRandomSensor", 1, sens->data); - break; - case SENS_RAY: - writestruct(wd, DATA, "bRaySensor", 1, sens->data); - break; - case SENS_MESSAGE: - writestruct(wd, DATA, "bMessageSensor", 1, sens->data); - break; - case SENS_JOYSTICK: - writestruct(wd, DATA, "bJoystickSensor", 1, sens->data); - break; - default: - ; /* error: don't know how to write this file */ + case SENS_NEAR: + writestruct(wd, DATA, bNearSensor, 1, sens->data); + break; + case SENS_MOUSE: + writestruct(wd, DATA, bMouseSensor, 1, sens->data); + break; + case SENS_KEYBOARD: + writestruct(wd, DATA, bKeyboardSensor, 1, sens->data); + break; + case SENS_PROPERTY: + writestruct(wd, DATA, bPropertySensor, 1, sens->data); + break; + case SENS_ARMATURE: + writestruct(wd, DATA, bArmatureSensor, 1, sens->data); + break; + case SENS_ACTUATOR: + writestruct(wd, DATA, bActuatorSensor, 1, sens->data); + break; + case SENS_DELAY: + writestruct(wd, DATA, bDelaySensor, 1, sens->data); + break; + case SENS_COLLISION: + writestruct(wd, DATA, bCollisionSensor, 1, sens->data); + break; + case SENS_RADAR: + writestruct(wd, DATA, bRadarSensor, 1, sens->data); + break; + case SENS_RANDOM: + writestruct(wd, DATA, bRandomSensor, 1, sens->data); + break; + case SENS_RAY: + writestruct(wd, DATA, bRaySensor, 1, sens->data); + break; + case SENS_MESSAGE: + writestruct(wd, DATA, bMessageSensor, 1, sens->data); + break; + case SENS_JOYSTICK: + writestruct(wd, DATA, bJoystickSensor, 1, sens->data); + break; + default: + ; /* error: don't know how to write this file */ } - sens= sens->next; + sens = sens->next; } } @@ -1329,24 +1467,24 @@ static void write_controllers(WriteData *wd, ListBase *lb) { bController *cont; - cont= lb->first; + cont = lb->first; while (cont) { - writestruct(wd, DATA, "bController", 1, cont); + writestruct(wd, DATA, bController, 1, cont); - writedata(wd, DATA, sizeof(void *)*cont->totlinks, cont->links); + writedata(wd, DATA, sizeof(void *) * cont->totlinks, cont->links); switch (cont->type) { - case CONT_EXPRESSION: - writestruct(wd, DATA, "bExpressionCont", 1, cont->data); - break; - case CONT_PYTHON: - writestruct(wd, DATA, "bPythonCont", 1, cont->data); - break; - default: - ; /* error: don't know how to write this file */ + case CONT_EXPRESSION: + writestruct(wd, DATA, bExpressionCont, 1, cont->data); + break; + case CONT_PYTHON: + writestruct(wd, DATA, bPythonCont, 1, cont->data); + break; + default: + ; /* error: don't know how to write this file */ } - cont= cont->next; + cont = cont->next; } } @@ -1354,133 +1492,135 @@ static void write_actuators(WriteData *wd, ListBase *lb) { bActuator *act; - act= lb->first; + act = lb->first; while (act) { - writestruct(wd, DATA, "bActuator", 1, act); + writestruct(wd, DATA, bActuator, 1, act); switch (act->type) { - case ACT_ACTION: - case ACT_SHAPEACTION: - writestruct(wd, DATA, "bActionActuator", 1, act->data); - break; - case ACT_SOUND: - writestruct(wd, DATA, "bSoundActuator", 1, act->data); - break; - case ACT_OBJECT: - writestruct(wd, DATA, "bObjectActuator", 1, act->data); - break; - case ACT_PROPERTY: - writestruct(wd, DATA, "bPropertyActuator", 1, act->data); - break; - case ACT_CAMERA: - writestruct(wd, DATA, "bCameraActuator", 1, act->data); - break; - case ACT_CONSTRAINT: - writestruct(wd, DATA, "bConstraintActuator", 1, act->data); - break; - case ACT_EDIT_OBJECT: - writestruct(wd, DATA, "bEditObjectActuator", 1, act->data); - break; - case ACT_SCENE: - writestruct(wd, DATA, "bSceneActuator", 1, act->data); - break; - case ACT_GROUP: - writestruct(wd, DATA, "bGroupActuator", 1, act->data); - break; - case ACT_RANDOM: - writestruct(wd, DATA, "bRandomActuator", 1, act->data); - break; - case ACT_MESSAGE: - writestruct(wd, DATA, "bMessageActuator", 1, act->data); - break; - case ACT_GAME: - writestruct(wd, DATA, "bGameActuator", 1, act->data); - break; - case ACT_VISIBILITY: - writestruct(wd, DATA, "bVisibilityActuator", 1, act->data); - break; - case ACT_2DFILTER: - writestruct(wd, DATA, "bTwoDFilterActuator", 1, act->data); - break; - case ACT_PARENT: - writestruct(wd, DATA, "bParentActuator", 1, act->data); - break; - case ACT_STATE: - writestruct(wd, DATA, "bStateActuator", 1, act->data); - break; - case ACT_ARMATURE: - writestruct(wd, DATA, "bArmatureActuator", 1, act->data); - break; - case ACT_STEERING: - writestruct(wd, DATA, "bSteeringActuator", 1, act->data); - break; - case ACT_MOUSE: - writestruct(wd, DATA, "bMouseActuator", 1, act->data); - break; - default: - ; /* error: don't know how to write this file */ + case ACT_ACTION: + case ACT_SHAPEACTION: + writestruct(wd, DATA, bActionActuator, 1, act->data); + break; + case ACT_SOUND: + writestruct(wd, DATA, bSoundActuator, 1, act->data); + break; + case ACT_OBJECT: + writestruct(wd, DATA, bObjectActuator, 1, act->data); + break; + case ACT_PROPERTY: + writestruct(wd, DATA, bPropertyActuator, 1, act->data); + break; + case ACT_CAMERA: + writestruct(wd, DATA, bCameraActuator, 1, act->data); + break; + case ACT_CONSTRAINT: + writestruct(wd, DATA, bConstraintActuator, 1, act->data); + break; + case ACT_EDIT_OBJECT: + writestruct(wd, DATA, bEditObjectActuator, 1, act->data); + break; + case ACT_SCENE: + writestruct(wd, DATA, bSceneActuator, 1, act->data); + break; + case ACT_GROUP: + writestruct(wd, DATA, bGroupActuator, 1, act->data); + break; + case ACT_RANDOM: + writestruct(wd, DATA, bRandomActuator, 1, act->data); + break; + case ACT_MESSAGE: + writestruct(wd, DATA, bMessageActuator, 1, act->data); + break; + case ACT_GAME: + writestruct(wd, DATA, bGameActuator, 1, act->data); + break; + case ACT_VISIBILITY: + writestruct(wd, DATA, bVisibilityActuator, 1, act->data); + break; + case ACT_2DFILTER: + writestruct(wd, DATA, bTwoDFilterActuator, 1, act->data); + break; + case ACT_PARENT: + writestruct(wd, DATA, bParentActuator, 1, act->data); + break; + case ACT_STATE: + writestruct(wd, DATA, bStateActuator, 1, act->data); + break; + case ACT_ARMATURE: + writestruct(wd, DATA, bArmatureActuator, 1, act->data); + break; + case ACT_STEERING: + writestruct(wd, DATA, bSteeringActuator, 1, act->data); + break; + case ACT_MOUSE: + writestruct(wd, DATA, bMouseActuator, 1, act->data); + break; + default: + ; /* error: don't know how to write this file */ } - act= act->next; + act = act->next; } } static void write_motionpath(WriteData *wd, bMotionPath *mpath) { /* sanity checks */ - if (mpath == NULL) + if (mpath == NULL) { return; - + } + /* firstly, just write the motionpath struct */ - writestruct(wd, DATA, "bMotionPath", 1, mpath); - + writestruct(wd, DATA, bMotionPath, 1, mpath); + /* now write the array of data */ - writestruct(wd, DATA, "bMotionPathVert", mpath->length, mpath->points); + writestruct(wd, DATA, bMotionPathVert, mpath->length, mpath->points); } static void write_constraints(WriteData *wd, ListBase *conlist) { bConstraint *con; - for (con=conlist->first; con; con=con->next) { - const bConstraintTypeInfo *cti= BKE_constraint_typeinfo_get(con); - + for (con = conlist->first; con; con = con->next) { + const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); + /* Write the specific data */ if (cti && con->data) { /* firstly, just write the plain con->data struct */ - writestruct(wd, DATA, cti->structName, 1, con->data); - + writestruct_id(wd, DATA, cti->structName, 1, con->data); + /* do any constraint specific stuff */ switch (con->type) { case CONSTRAINT_TYPE_PYTHON: { - bPythonConstraint *data = (bPythonConstraint *)con->data; + bPythonConstraint *data = con->data; bConstraintTarget *ct; - + /* write targets */ - for (ct= data->targets.first; ct; ct= ct->next) - writestruct(wd, DATA, "bConstraintTarget", 1, ct); - + for (ct = data->targets.first; ct; ct = ct->next) { + writestruct(wd, DATA, bConstraintTarget, 1, ct); + } + /* Write ID Properties -- and copy this comment EXACTLY for easy finding * of library blocks that implement this.*/ IDP_WriteProperty(data->prop, wd); break; } - case CONSTRAINT_TYPE_SPLINEIK: + case CONSTRAINT_TYPE_SPLINEIK: { - bSplineIKConstraint *data = (bSplineIKConstraint *)con->data; - + bSplineIKConstraint *data = con->data; + /* write points array */ - writedata(wd, DATA, sizeof(float)*(data->numpoints), data->points); + writedata(wd, DATA, sizeof(float) * (data->numpoints), data->points); break; } } } - + /* Write the constraint */ - writestruct(wd, DATA, "bConstraint", 1, con); + writestruct(wd, DATA, bConstraint, 1, con); } } @@ -1490,176 +1630,191 @@ static void write_pose(WriteData *wd, bPose *pose) bActionGroup *grp; /* Write each channel */ - if (!pose) + if (pose == NULL) { return; + } /* Write channels */ - for (chan=pose->chanbase.first; chan; chan=chan->next) { + for (chan = pose->chanbase.first; chan; chan = chan->next) { /* Write ID Properties -- and copy this comment EXACTLY for easy finding * of library blocks that implement this.*/ - if (chan->prop) + if (chan->prop) { IDP_WriteProperty(chan->prop, wd); - + } + write_constraints(wd, &chan->constraints); - + write_motionpath(wd, chan->mpath); - - /* prevent crashes with autosave, when a bone duplicated in editmode has not yet been assigned to its posechannel */ - if (chan->bone) - chan->selectflag= chan->bone->flag & BONE_SELECTED; /* gets restored on read, for library armatures */ - - writestruct(wd, DATA, "bPoseChannel", 1, chan); - } - + + /* prevent crashes with autosave, + * when a bone duplicated in editmode has not yet been assigned to its posechannel */ + if (chan->bone) { + /* gets restored on read, for library armatures */ + chan->selectflag = chan->bone->flag & BONE_SELECTED; + } + + writestruct(wd, DATA, bPoseChannel, 1, chan); + } + /* Write groups */ - for (grp=pose->agroups.first; grp; grp=grp->next) - writestruct(wd, DATA, "bActionGroup", 1, grp); + for (grp = pose->agroups.first; grp; grp = grp->next) { + writestruct(wd, DATA, bActionGroup, 1, grp); + } /* write IK param */ if (pose->ikparam) { const char *structname = BKE_pose_ikparam_get_name(pose); - if (structname) - writestruct(wd, DATA, structname, 1, pose->ikparam); + if (structname) { + writestruct_id(wd, DATA, structname, 1, pose->ikparam); + } } /* Write this pose */ - writestruct(wd, DATA, "bPose", 1, pose); + writestruct(wd, DATA, bPose, 1, pose); } static void write_defgroups(WriteData *wd, ListBase *defbase) { - bDeformGroup *defgroup; - - for (defgroup=defbase->first; defgroup; defgroup=defgroup->next) - writestruct(wd, DATA, "bDeformGroup", 1, defgroup); + for (bDeformGroup *defgroup = defbase->first; defgroup; defgroup = defgroup->next) { + writestruct(wd, DATA, bDeformGroup, 1, defgroup); + } } static void write_modifiers(WriteData *wd, ListBase *modbase) { ModifierData *md; - if (modbase == NULL) return; - for (md=modbase->first; md; md= md->next) { + if (modbase == NULL) { + return; + } + + for (md = modbase->first; md; md = md->next) { const ModifierTypeInfo *mti = modifierType_getInfo(md->type); - if (mti == NULL) return; - - writestruct(wd, DATA, mti->structName, 1, md); - - if (md->type==eModifierType_Hook) { - HookModifierData *hmd = (HookModifierData*) md; - + if (mti == NULL) { + return; + } + + writestruct_id(wd, DATA, mti->structName, 1, md); + + if (md->type == eModifierType_Hook) { + HookModifierData *hmd = (HookModifierData *)md; + if (hmd->curfalloff) { write_curvemapping(wd, hmd->curfalloff); } - writedata(wd, DATA, sizeof(int)*hmd->totindex, hmd->indexar); + writedata(wd, DATA, sizeof(int) * hmd->totindex, hmd->indexar); } - else if (md->type==eModifierType_Cloth) { - ClothModifierData *clmd = (ClothModifierData*) md; - - writestruct(wd, DATA, "ClothSimSettings", 1, clmd->sim_parms); - writestruct(wd, DATA, "ClothCollSettings", 1, clmd->coll_parms); - writestruct(wd, DATA, "EffectorWeights", 1, clmd->sim_parms->effector_weights); + else if (md->type == eModifierType_Cloth) { + ClothModifierData *clmd = (ClothModifierData *)md; + + writestruct(wd, DATA, ClothSimSettings, 1, clmd->sim_parms); + writestruct(wd, DATA, ClothCollSettings, 1, clmd->coll_parms); + writestruct(wd, DATA, EffectorWeights, 1, clmd->sim_parms->effector_weights); write_pointcaches(wd, &clmd->ptcaches); } - else if (md->type==eModifierType_Smoke) { - SmokeModifierData *smd = (SmokeModifierData*) md; - + else if (md->type == eModifierType_Smoke) { + SmokeModifierData *smd = (SmokeModifierData *)md; + if (smd->type & MOD_SMOKE_TYPE_DOMAIN) { if (smd->domain) { write_pointcaches(wd, &(smd->domain->ptcaches[0])); /* create fake pointcache so that old blender versions can read it */ smd->domain->point_cache[1] = BKE_ptcache_add(&smd->domain->ptcaches[1]); - smd->domain->point_cache[1]->flag |= PTCACHE_DISK_CACHE|PTCACHE_FAKE_SMOKE; + smd->domain->point_cache[1]->flag |= PTCACHE_DISK_CACHE | PTCACHE_FAKE_SMOKE; smd->domain->point_cache[1]->step = 1; write_pointcaches(wd, &(smd->domain->ptcaches[1])); } - - writestruct(wd, DATA, "SmokeDomainSettings", 1, smd->domain); + + writestruct(wd, DATA, SmokeDomainSettings, 1, smd->domain); if (smd->domain) { /* cleanup the fake pointcache */ BKE_ptcache_free_list(&smd->domain->ptcaches[1]); smd->domain->point_cache[1] = NULL; - - writestruct(wd, DATA, "EffectorWeights", 1, smd->domain->effector_weights); + + writestruct(wd, DATA, EffectorWeights, 1, smd->domain->effector_weights); } } - else if (smd->type & MOD_SMOKE_TYPE_FLOW) - writestruct(wd, DATA, "SmokeFlowSettings", 1, smd->flow); - else if (smd->type & MOD_SMOKE_TYPE_COLL) - writestruct(wd, DATA, "SmokeCollSettings", 1, smd->coll); + else if (smd->type & MOD_SMOKE_TYPE_FLOW) { + writestruct(wd, DATA, SmokeFlowSettings, 1, smd->flow); + } + else if (smd->type & MOD_SMOKE_TYPE_COLL) { + writestruct(wd, DATA, SmokeCollSettings, 1, smd->coll); + } } - else if (md->type==eModifierType_Fluidsim) { - FluidsimModifierData *fluidmd = (FluidsimModifierData*) md; - - writestruct(wd, DATA, "FluidsimSettings", 1, fluidmd->fss); + else if (md->type == eModifierType_Fluidsim) { + FluidsimModifierData *fluidmd = (FluidsimModifierData *)md; + + writestruct(wd, DATA, FluidsimSettings, 1, fluidmd->fss); } - else if (md->type==eModifierType_DynamicPaint) { - DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md; - + else if (md->type == eModifierType_DynamicPaint) { + DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md; + if (pmd->canvas) { DynamicPaintSurface *surface; - writestruct(wd, DATA, "DynamicPaintCanvasSettings", 1, pmd->canvas); - + writestruct(wd, DATA, DynamicPaintCanvasSettings, 1, pmd->canvas); + /* write surfaces */ - for (surface=pmd->canvas->surfaces.first; surface; surface=surface->next) - writestruct(wd, DATA, "DynamicPaintSurface", 1, surface); + for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) { + writestruct(wd, DATA, DynamicPaintSurface, 1, surface); + } /* write caches and effector weights */ - for (surface=pmd->canvas->surfaces.first; surface; surface=surface->next) { + for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) { write_pointcaches(wd, &(surface->ptcaches)); - writestruct(wd, DATA, "EffectorWeights", 1, surface->effector_weights); + writestruct(wd, DATA, EffectorWeights, 1, surface->effector_weights); } } if (pmd->brush) { - writestruct(wd, DATA, "DynamicPaintBrushSettings", 1, pmd->brush); - writestruct(wd, DATA, "ColorBand", 1, pmd->brush->paint_ramp); - writestruct(wd, DATA, "ColorBand", 1, pmd->brush->vel_ramp); + writestruct(wd, DATA, DynamicPaintBrushSettings, 1, pmd->brush); + writestruct(wd, DATA, ColorBand, 1, pmd->brush->paint_ramp); + writestruct(wd, DATA, ColorBand, 1, pmd->brush->vel_ramp); } } - else if (md->type==eModifierType_Collision) { - + else if (md->type == eModifierType_Collision) { + #if 0 - CollisionModifierData *collmd = (CollisionModifierData*) md; - // TODO: CollisionModifier should use pointcache + CollisionModifierData *collmd = (CollisionModifierData *)md; + // TODO: CollisionModifier should use pointcache // + have proper reset events before enabling this - writestruct(wd, DATA, "MVert", collmd->numverts, collmd->x); - writestruct(wd, DATA, "MVert", collmd->numverts, collmd->xnew); - writestruct(wd, DATA, "MFace", collmd->numfaces, collmd->mfaces); + writestruct(wd, DATA, MVert, collmd->numverts, collmd->x); + writestruct(wd, DATA, MVert, collmd->numverts, collmd->xnew); + writestruct(wd, DATA, MFace, collmd->numfaces, collmd->mfaces); #endif } - else if (md->type==eModifierType_MeshDeform) { - MeshDeformModifierData *mmd = (MeshDeformModifierData*) md; + else if (md->type == eModifierType_MeshDeform) { + MeshDeformModifierData *mmd = (MeshDeformModifierData *)md; int size = mmd->dyngridsize; - writestruct(wd, DATA, "MDefInfluence", mmd->totinfluence, mmd->bindinfluences); + writestruct(wd, DATA, MDefInfluence, mmd->totinfluence, mmd->bindinfluences); writedata(wd, DATA, sizeof(int) * (mmd->totvert + 1), mmd->bindoffsets); writedata(wd, DATA, sizeof(float) * 3 * mmd->totcagevert, - mmd->bindcagecos); - writestruct(wd, DATA, "MDefCell", size*size*size, mmd->dyngrid); - writestruct(wd, DATA, "MDefInfluence", mmd->totinfluence, mmd->dyninfluences); - writedata(wd, DATA, sizeof(int)*mmd->totvert, mmd->dynverts); + mmd->bindcagecos); + writestruct(wd, DATA, MDefCell, size * size * size, mmd->dyngrid); + writestruct(wd, DATA, MDefInfluence, mmd->totinfluence, mmd->dyninfluences); + writedata(wd, DATA, sizeof(int) * mmd->totvert, mmd->dynverts); } - else if (md->type==eModifierType_Warp) { - WarpModifierData *tmd = (WarpModifierData*) md; + else if (md->type == eModifierType_Warp) { + WarpModifierData *tmd = (WarpModifierData *)md; if (tmd->curfalloff) { write_curvemapping(wd, tmd->curfalloff); } } - else if (md->type==eModifierType_WeightVGEdit) { - WeightVGEditModifierData *wmd = (WeightVGEditModifierData*) md; + else if (md->type == eModifierType_WeightVGEdit) { + WeightVGEditModifierData *wmd = (WeightVGEditModifierData *)md; - if (wmd->cmap_curve) + if (wmd->cmap_curve) { write_curvemapping(wd, wmd->cmap_curve); + } } - else if (md->type==eModifierType_LaplacianDeform) { - LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData*) md; + else if (md->type == eModifierType_LaplacianDeform) { + LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)md; - writedata(wd, DATA, sizeof(float)*lmd->total_verts * 3, lmd->vertexco); + writedata(wd, DATA, sizeof(float) * lmd->total_verts * 3, lmd->vertexco); } else if (md->type == eModifierType_CorrectiveSmooth) { CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)md; @@ -1674,19 +1829,21 @@ static void write_modifiers(WriteData *wd, ListBase *modbase) static void write_objects(WriteData *wd, ListBase *idbase) { Object *ob; - - ob= idbase->first; + + ob = idbase->first; while (ob) { - if (ob->id.us>0 || wd->current) { + if (ob->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_OB, "Object", 1, ob); + writestruct(wd, ID_OB, Object, 1, ob); write_iddata(wd, &ob->id); - if (ob->adt) write_animdata(wd, ob->adt); - + if (ob->adt) { + write_animdata(wd, ob->adt); + } + /* direct data */ - writedata(wd, DATA, sizeof(void *)*ob->totcol, ob->mat); - writedata(wd, DATA, sizeof(char)*ob->totcol, ob->matbits); + writedata(wd, DATA, sizeof(void *) * ob->totcol, ob->mat); + writedata(wd, DATA, sizeof(char) * ob->totcol, ob->matbits); /* write_effects(wd, &ob->effect); */ /* not used anymore */ write_properties(wd, &ob->prop); write_sensors(wd, &ob->sensors); @@ -1704,37 +1861,37 @@ static void write_objects(WriteData *wd, ListBase *idbase) write_defgroups(wd, &ob->defbase); write_constraints(wd, &ob->constraints); write_motionpath(wd, ob->mpath); - - writestruct(wd, DATA, "PartDeflect", 1, ob->pd); - writestruct(wd, DATA, "SoftBody", 1, ob->soft); + + writestruct(wd, DATA, PartDeflect, 1, ob->pd); + writestruct(wd, DATA, SoftBody, 1, ob->soft); if (ob->soft) { write_pointcaches(wd, &ob->soft->ptcaches); - writestruct(wd, DATA, "EffectorWeights", 1, ob->soft->effector_weights); + writestruct(wd, DATA, EffectorWeights, 1, ob->soft->effector_weights); } - writestruct(wd, DATA, "BulletSoftBody", 1, ob->bsoft); - + writestruct(wd, DATA, BulletSoftBody, 1, ob->bsoft); + if (ob->rigidbody_object) { - // TODO: if any extra data is added to handle duplis, will need separate function then - writestruct(wd, DATA, "RigidBodyOb", 1, ob->rigidbody_object); + /* TODO: if any extra data is added to handle duplis, will need separate function then */ + writestruct(wd, DATA, RigidBodyOb, 1, ob->rigidbody_object); } if (ob->rigidbody_constraint) { - writestruct(wd, DATA, "RigidBodyCon", 1, ob->rigidbody_constraint); + writestruct(wd, DATA, RigidBodyCon, 1, ob->rigidbody_constraint); } if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) { - writestruct(wd, DATA, "ImageUser", 1, ob->iuser); + writestruct(wd, DATA, ImageUser, 1, ob->iuser); } write_particlesystems(wd, &ob->particlesystem); write_modifiers(wd, &ob->modifiers); - writelist(wd, DATA, "LinkData", &ob->pc_ids); - writelist(wd, DATA, "LodLevel", &ob->lodlevels); + writelist(wd, DATA, LinkData, &ob->pc_ids); + writelist(wd, DATA, LodLevel, &ob->lodlevels); } write_previews(wd, ob->preview); - ob= ob->id.next; + ob = ob->id.next; } /* flush helps the compression for undo-save */ @@ -1745,25 +1902,25 @@ static void write_objects(WriteData *wd, ListBase *idbase) static void write_vfonts(WriteData *wd, ListBase *idbase) { VFont *vf; - PackedFile * pf; + PackedFile *pf; - vf= idbase->first; + vf = idbase->first; while (vf) { - if (vf->id.us>0 || wd->current) { + if (vf->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_VF, "VFont", 1, vf); + writestruct(wd, ID_VF, VFont, 1, vf); write_iddata(wd, &vf->id); /* direct data */ if (vf->packedfile) { pf = vf->packedfile; - writestruct(wd, DATA, "PackedFile", 1, pf); + writestruct(wd, DATA, PackedFile, 1, pf); writedata(wd, DATA, pf->size, pf->data); } } - vf= vf->id.next; + vf = vf->id.next; } } @@ -1773,25 +1930,29 @@ static void write_keys(WriteData *wd, ListBase *idbase) Key *key; KeyBlock *kb; - key= idbase->first; + key = idbase->first; while (key) { - if (key->id.us>0 || wd->current) { + if (key->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_KE, "Key", 1, key); + writestruct(wd, ID_KE, Key, 1, key); write_iddata(wd, &key->id); - if (key->adt) write_animdata(wd, key->adt); - + if (key->adt) { + write_animdata(wd, key->adt); + } + /* direct data */ - kb= key->block.first; + kb = key->block.first; while (kb) { - writestruct(wd, DATA, "KeyBlock", 1, kb); - if (kb->data) writedata(wd, DATA, kb->totelem*key->elemsize, kb->data); - kb= kb->next; + writestruct(wd, DATA, KeyBlock, 1, kb); + if (kb->data) { + writedata(wd, DATA, kb->totelem * key->elemsize, kb->data); + } + kb = kb->next; } } - key= key->id.next; + key = key->id.next; } /* flush helps the compression for undo-save */ mywrite(wd, MYWRITE_FLUSH, 0); @@ -1801,17 +1962,19 @@ static void write_cameras(WriteData *wd, ListBase *idbase) { Camera *cam; - cam= idbase->first; + cam = idbase->first; while (cam) { - if (cam->id.us>0 || wd->current) { + if (cam->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_CA, "Camera", 1, cam); + writestruct(wd, ID_CA, Camera, 1, cam); write_iddata(wd, &cam->id); - if (cam->adt) write_animdata(wd, cam->adt); + if (cam->adt) { + write_animdata(wd, cam->adt); + } } - cam= cam->id.next; + cam = cam->id.next; } } @@ -1820,24 +1983,26 @@ static void write_mballs(WriteData *wd, ListBase *idbase) MetaBall *mb; MetaElem *ml; - mb= idbase->first; + mb = idbase->first; while (mb) { - if (mb->id.us>0 || wd->current) { + if (mb->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_MB, "MetaBall", 1, mb); + writestruct(wd, ID_MB, MetaBall, 1, mb); write_iddata(wd, &mb->id); /* direct data */ - writedata(wd, DATA, sizeof(void *)*mb->totcol, mb->mat); - if (mb->adt) write_animdata(wd, mb->adt); + writedata(wd, DATA, sizeof(void *) * mb->totcol, mb->mat); + if (mb->adt) { + write_animdata(wd, mb->adt); + } - ml= mb->elems.first; + ml = mb->elems.first; while (ml) { - writestruct(wd, DATA, "MetaElem", 1, ml); - ml= ml->next; + writestruct(wd, DATA, MetaElem, 1, ml); + ml = ml->next; } } - mb= mb->id.next; + mb = mb->id.next; } } @@ -1846,43 +2011,50 @@ static void write_curves(WriteData *wd, ListBase *idbase) Curve *cu; Nurb *nu; - cu= idbase->first; + cu = idbase->first; while (cu) { - if (cu->id.us>0 || wd->current) { + if (cu->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_CU, "Curve", 1, cu); + writestruct(wd, ID_CU, Curve, 1, cu); write_iddata(wd, &cu->id); /* direct data */ - writedata(wd, DATA, sizeof(void *)*cu->totcol, cu->mat); - if (cu->adt) write_animdata(wd, cu->adt); - + writedata(wd, DATA, sizeof(void *) * cu->totcol, cu->mat); + if (cu->adt) { + write_animdata(wd, cu->adt); + } + if (cu->vfont) { writedata(wd, DATA, cu->len + 1, cu->str); - writestruct(wd, DATA, "CharInfo", cu->len_wchar + 1, cu->strinfo); - writestruct(wd, DATA, "TextBox", cu->totbox, cu->tb); + writestruct(wd, DATA, CharInfo, cu->len_wchar + 1, cu->strinfo); + writestruct(wd, DATA, TextBox, cu->totbox, cu->tb); } else { /* is also the order of reading */ - nu= cu->nurb.first; + nu = cu->nurb.first; while (nu) { - writestruct(wd, DATA, "Nurb", 1, nu); - nu= nu->next; + writestruct(wd, DATA, Nurb, 1, nu); + nu = nu->next; } - nu= cu->nurb.first; + nu = cu->nurb.first; while (nu) { - if (nu->type == CU_BEZIER) - writestruct(wd, DATA, "BezTriple", nu->pntsu, nu->bezt); + if (nu->type == CU_BEZIER) { + writestruct(wd, DATA, BezTriple, nu->pntsu, nu->bezt); + } else { - writestruct(wd, DATA, "BPoint", nu->pntsu*nu->pntsv, nu->bp); - if (nu->knotsu) writedata(wd, DATA, KNOTSU(nu)*sizeof(float), nu->knotsu); - if (nu->knotsv) writedata(wd, DATA, KNOTSV(nu)*sizeof(float), nu->knotsv); + writestruct(wd, DATA, BPoint, nu->pntsu * nu->pntsv, nu->bp); + if (nu->knotsu) { + writedata(wd, DATA, KNOTSU(nu) * sizeof(float), nu->knotsu); + } + if (nu->knotsv) { + writedata(wd, DATA, KNOTSV(nu) * sizeof(float), nu->knotsv); + } } - nu= nu->next; + nu = nu->next; } } } - cu= cu->id.next; + cu = cu->id.next; } /* flush helps the compression for undo-save */ @@ -1892,15 +2064,15 @@ static void write_curves(WriteData *wd, ListBase *idbase) static void write_dverts(WriteData *wd, int count, MDeformVert *dvlist) { if (dvlist) { - int i; - + /* Write the dvert list */ - writestruct(wd, DATA, "MDeformVert", count, dvlist); - + writestruct(wd, DATA, MDeformVert, count, dvlist); + /* Write deformation data for each dvert */ - for (i=0; i<count; i++) { - if (dvlist[i].dw) - writestruct(wd, DATA, "MDeformWeight", dvlist[i].totweight, dvlist[i].dw); + for (int i = 0; i < count; i++) { + if (dvlist[i].dw) { + writestruct(wd, DATA, MDeformWeight, dvlist[i].totweight, dvlist[i].dw); + } } } } @@ -1909,17 +2081,19 @@ static void write_mdisps(WriteData *wd, int count, MDisps *mdlist, int external) { if (mdlist) { int i; - - writestruct(wd, DATA, "MDisps", count, mdlist); + + writestruct(wd, DATA, MDisps, count, mdlist); for (i = 0; i < count; ++i) { MDisps *md = &mdlist[i]; if (md->disps) { - if (!external) + if (!external) { writedata(wd, DATA, sizeof(float) * 3 * md->totdisp, md->disps); + } } - - if (md->hidden) + + if (md->hidden) { writedata(wd, DATA, BLI_BITMAP_SIZE(md->totdisp), md->hidden); + } } } } @@ -1928,8 +2102,8 @@ static void write_grid_paint_mask(WriteData *wd, int count, GridPaintMask *grid_ { if (grid_paint_mask) { int i; - - writestruct(wd, DATA, "GridPaintMask", count, grid_paint_mask); + + writestruct(wd, DATA, GridPaintMask, count, grid_paint_mask); for (i = 0; i < count; ++i) { GridPaintMask *gpm = &grid_paint_mask[i]; if (gpm->data) { @@ -1949,11 +2123,12 @@ static void write_customdata( int i; /* write external customdata (not for undo) */ - if (data->external && !wd->current) + if (data->external && !wd->current) { CustomData_external_write(data, id, CD_MASK_MESH, count, 0); + } + + writestruct_at_address(wd, DATA, CustomDataLayer, data->totlayer, data->layers, layers); - writestruct_at_address(wd, DATA, "CustomDataLayer", data->totlayer, data->layers, layers); - for (i = 0; i < data->totlayer; i++) { CustomDataLayer *layer = &layers[i]; const char *structname; @@ -1979,10 +2154,14 @@ static void write_customdata( /* when using partial visibility, the MEdge and MFace layers * are smaller than the original, so their type and count is * passed to make this work */ - if (layer->type != partial_type) datasize= structnum*count; - else datasize= structnum*partial_count; + if (layer->type != partial_type) { + datasize = structnum * count; + } + else { + datasize = structnum * partial_count; + } - writestruct(wd, DATA, structname, datasize, layer->data); + writestruct_id(wd, DATA, structname, datasize, layer->data); } else { printf("%s error: layer '%s':%d - can't be written to file\n", @@ -1991,20 +2170,21 @@ static void write_customdata( } } - if (data->external) - writestruct(wd, DATA, "CustomDataExternal", 1, data->external); + if (data->external) { + writestruct(wd, DATA, CustomDataExternal, 1, data->external); + } } static void write_meshes(WriteData *wd, ListBase *idbase) { Mesh *mesh; - int save_for_old_blender= 0; + bool save_for_old_blender = false; #ifdef USE_BMESH_SAVE_AS_COMPAT save_for_old_blender = wd->use_mesh_compat; /* option to save with older mesh format */ #endif - mesh= idbase->first; + mesh = idbase->first; while (mesh) { CustomDataLayer *vlayers = NULL, vlayers_buff[CD_TEMP_CHUNK_SIZE]; CustomDataLayer *elayers = NULL, elayers_buff[CD_TEMP_CHUNK_SIZE]; @@ -2012,7 +2192,7 @@ static void write_meshes(WriteData *wd, ListBase *idbase) CustomDataLayer *llayers = NULL, llayers_buff[CD_TEMP_CHUNK_SIZE]; CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE]; - if (mesh->id.us>0 || wd->current) { + if (mesh->id.us > 0 || wd->current) { /* write LibData */ if (!save_for_old_blender) { /* write a copy of the mesh, don't modify in place because it is @@ -2045,13 +2225,15 @@ static void write_meshes(WriteData *wd, ListBase *idbase) CustomData_file_write_prepare(&mesh->ldata, &llayers, llayers_buff, ARRAY_SIZE(llayers_buff)); CustomData_file_write_prepare(&mesh->pdata, &players, players_buff, ARRAY_SIZE(players_buff)); - writestruct_at_address(wd, ID_ME, "Mesh", 1, old_mesh, mesh); + writestruct_at_address(wd, ID_ME, Mesh, 1, old_mesh, mesh); write_iddata(wd, &mesh->id); /* direct data */ - if (mesh->adt) write_animdata(wd, mesh->adt); + if (mesh->adt) { + write_animdata(wd, mesh->adt); + } - writedata(wd, DATA, sizeof(void *)*mesh->totcol, mesh->mat); + writedata(wd, DATA, sizeof(void *) * mesh->totcol, mesh->mat); writedata(wd, DATA, sizeof(MSelect) * mesh->totselect, mesh->mselect); write_customdata(wd, &mesh->id, mesh->totvert, &mesh->vdata, vlayers, -1, 0); @@ -2104,13 +2286,15 @@ static void write_meshes(WriteData *wd, ListBase *idbase) CustomData_file_write_prepare(&mesh->pdata, &players, players_buff, ARRAY_SIZE(players_buff)); #endif - writestruct_at_address(wd, ID_ME, "Mesh", 1, old_mesh, mesh); + writestruct_at_address(wd, ID_ME, Mesh, 1, old_mesh, mesh); write_iddata(wd, &mesh->id); /* direct data */ - if (mesh->adt) write_animdata(wd, mesh->adt); + if (mesh->adt) { + write_animdata(wd, mesh->adt); + } - writedata(wd, DATA, sizeof(void *)*mesh->totcol, mesh->mat); + writedata(wd, DATA, sizeof(void *) * mesh->totcol, mesh->mat); /* writedata(wd, DATA, sizeof(MSelect) * mesh->totselect, mesh->mselect); */ /* pre-bmesh NULL's */ write_customdata(wd, &mesh->id, mesh->totvert, &mesh->vdata, vlayers, -1, 0); @@ -2147,44 +2331,46 @@ static void write_meshes(WriteData *wd, ListBase *idbase) MEM_freeN(players); } - mesh= mesh->id.next; + mesh = mesh->id.next; } } static void write_lattices(WriteData *wd, ListBase *idbase) { Lattice *lt; - - lt= idbase->first; + + lt = idbase->first; while (lt) { - if (lt->id.us>0 || wd->current) { + if (lt->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_LT, "Lattice", 1, lt); + writestruct(wd, ID_LT, Lattice, 1, lt); write_iddata(wd, <->id); /* write animdata */ - if (lt->adt) write_animdata(wd, lt->adt); - + if (lt->adt) { + write_animdata(wd, lt->adt); + } + /* direct data */ - writestruct(wd, DATA, "BPoint", lt->pntsu*lt->pntsv*lt->pntsw, lt->def); - - write_dverts(wd, lt->pntsu*lt->pntsv*lt->pntsw, lt->dvert); - + writestruct(wd, DATA, BPoint, lt->pntsu * lt->pntsv * lt->pntsw, lt->def); + + write_dverts(wd, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert); + } - lt= lt->id.next; + lt = lt->id.next; } } static void write_images(WriteData *wd, ListBase *idbase) { Image *ima; - PackedFile * pf; + PackedFile *pf; ImageView *iv; ImagePackedFile *imapf; - ima= idbase->first; + ima = idbase->first; while (ima) { - if (ima->id.us>0 || wd->current) { + if (ima->id.us > 0 || wd->current) { /* Some trickery to keep forward compatibility of packed images. */ BLI_assert(ima->packedfile == NULL); if (ima->packedfiles.first != NULL) { @@ -2193,27 +2379,28 @@ static void write_images(WriteData *wd, ListBase *idbase) } /* write LibData */ - writestruct(wd, ID_IM, "Image", 1, ima); + writestruct(wd, ID_IM, Image, 1, ima); write_iddata(wd, &ima->id); for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) { - writestruct(wd, DATA, "ImagePackedFile", 1, imapf); + writestruct(wd, DATA, ImagePackedFile, 1, imapf); if (imapf->packedfile) { pf = imapf->packedfile; - writestruct(wd, DATA, "PackedFile", 1, pf); + writestruct(wd, DATA, PackedFile, 1, pf); writedata(wd, DATA, pf->size, pf->data); } } write_previews(wd, ima->preview); - for (iv = ima->views.first; iv; iv = iv->next) - writestruct(wd, DATA, "ImageView", 1, iv); - writestruct(wd, DATA, "Stereo3dFormat", 1, ima->stereo3d_format); + for (iv = ima->views.first; iv; iv = iv->next) { + writestruct(wd, DATA, ImageView, 1, iv); + } + writestruct(wd, DATA, Stereo3dFormat, 1, ima->stereo3d_format); ima->packedfile = NULL; } - ima= ima->id.next; + ima = ima->id.next; } /* flush helps the compression for undo-save */ mywrite(wd, MYWRITE_FLUSH, 0); @@ -2223,35 +2410,49 @@ static void write_textures(WriteData *wd, ListBase *idbase) { Tex *tex; - tex= idbase->first; + tex = idbase->first; while (tex) { - if (tex->id.us>0 || wd->current) { + if (tex->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_TE, "Tex", 1, tex); + writestruct(wd, ID_TE, Tex, 1, tex); write_iddata(wd, &tex->id); - if (tex->adt) write_animdata(wd, tex->adt); + if (tex->adt) { + write_animdata(wd, tex->adt); + } /* direct data */ - if (tex->coba) writestruct(wd, DATA, "ColorBand", 1, tex->coba); - if (tex->type == TEX_ENVMAP && tex->env) writestruct(wd, DATA, "EnvMap", 1, tex->env); + if (tex->coba) { + writestruct(wd, DATA, ColorBand, 1, tex->coba); + } + if (tex->type == TEX_ENVMAP && tex->env) { + writestruct(wd, DATA, EnvMap, 1, tex->env); + } if (tex->type == TEX_POINTDENSITY && tex->pd) { - writestruct(wd, DATA, "PointDensity", 1, tex->pd); - if (tex->pd->coba) writestruct(wd, DATA, "ColorBand", 1, tex->pd->coba); - if (tex->pd->falloff_curve) write_curvemapping(wd, tex->pd->falloff_curve); + writestruct(wd, DATA, PointDensity, 1, tex->pd); + if (tex->pd->coba) { + writestruct(wd, DATA, ColorBand, 1, tex->pd->coba); + } + if (tex->pd->falloff_curve) { + write_curvemapping(wd, tex->pd->falloff_curve); + } + } + if (tex->type == TEX_VOXELDATA) { + writestruct(wd, DATA, VoxelData, 1, tex->vd); + } + if (tex->type == TEX_OCEAN && tex->ot) { + writestruct(wd, DATA, OceanTex, 1, tex->ot); } - if (tex->type == TEX_VOXELDATA) writestruct(wd, DATA, "VoxelData", 1, tex->vd); - if (tex->type == TEX_OCEAN && tex->ot) writestruct(wd, DATA, "OceanTex", 1, tex->ot); - + /* nodetree is integral part of texture, no libdata */ if (tex->nodetree) { - writestruct(wd, DATA, "bNodeTree", 1, tex->nodetree); + writestruct(wd, DATA, bNodeTree, 1, tex->nodetree); write_nodetree(wd, tex->nodetree); } - + write_previews(wd, tex->preview); } - tex= tex->id.next; + tex = tex->id.next; } /* flush helps the compression for undo-save */ @@ -2263,31 +2464,39 @@ static void write_materials(WriteData *wd, ListBase *idbase) Material *ma; int a; - ma= idbase->first; + ma = idbase->first; while (ma) { - if (ma->id.us>0 || wd->current) { + if (ma->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_MA, "Material", 1, ma); + writestruct(wd, ID_MA, Material, 1, ma); write_iddata(wd, &ma->id); - if (ma->adt) write_animdata(wd, ma->adt); + if (ma->adt) { + write_animdata(wd, ma->adt); + } - for (a=0; a<MAX_MTEX; a++) { - if (ma->mtex[a]) writestruct(wd, DATA, "MTex", 1, ma->mtex[a]); + for (a = 0; a < MAX_MTEX; a++) { + if (ma->mtex[a]) { + writestruct(wd, DATA, MTex, 1, ma->mtex[a]); + } } - - if (ma->ramp_col) writestruct(wd, DATA, "ColorBand", 1, ma->ramp_col); - if (ma->ramp_spec) writestruct(wd, DATA, "ColorBand", 1, ma->ramp_spec); - + + if (ma->ramp_col) { + writestruct(wd, DATA, ColorBand, 1, ma->ramp_col); + } + if (ma->ramp_spec) { + writestruct(wd, DATA, ColorBand, 1, ma->ramp_spec); + } + /* nodetree is integral part of material, no libdata */ if (ma->nodetree) { - writestruct(wd, DATA, "bNodeTree", 1, ma->nodetree); + writestruct(wd, DATA, bNodeTree, 1, ma->nodetree); write_nodetree(wd, ma->nodetree); } write_previews(wd, ma->preview); } - ma= ma->id.next; + ma = ma->id.next; } } @@ -2296,28 +2505,32 @@ static void write_worlds(WriteData *wd, ListBase *idbase) World *wrld; int a; - wrld= idbase->first; + wrld = idbase->first; while (wrld) { - if (wrld->id.us>0 || wd->current) { + if (wrld->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_WO, "World", 1, wrld); + writestruct(wd, ID_WO, World, 1, wrld); write_iddata(wd, &wrld->id); - if (wrld->adt) write_animdata(wd, wrld->adt); - - for (a=0; a<MAX_MTEX; a++) { - if (wrld->mtex[a]) writestruct(wd, DATA, "MTex", 1, wrld->mtex[a]); + if (wrld->adt) { + write_animdata(wd, wrld->adt); + } + + for (a = 0; a < MAX_MTEX; a++) { + if (wrld->mtex[a]) { + writestruct(wd, DATA, MTex, 1, wrld->mtex[a]); + } } /* nodetree is integral part of world, no libdata */ if (wrld->nodetree) { - writestruct(wd, DATA, "bNodeTree", 1, wrld->nodetree); + writestruct(wd, DATA, bNodeTree, 1, wrld->nodetree); write_nodetree(wd, wrld->nodetree); } - + write_previews(wd, wrld->preview); } - wrld= wrld->id.next; + wrld = wrld->id.next; } } @@ -2326,33 +2539,38 @@ static void write_lamps(WriteData *wd, ListBase *idbase) Lamp *la; int a; - la= idbase->first; + la = idbase->first; while (la) { - if (la->id.us>0 || wd->current) { + if (la->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_LA, "Lamp", 1, la); + writestruct(wd, ID_LA, Lamp, 1, la); write_iddata(wd, &la->id); - if (la->adt) write_animdata(wd, la->adt); - + if (la->adt) { + write_animdata(wd, la->adt); + } + /* direct data */ - for (a=0; a<MAX_MTEX; a++) { - if (la->mtex[a]) writestruct(wd, DATA, "MTex", 1, la->mtex[a]); + for (a = 0; a < MAX_MTEX; a++) { + if (la->mtex[a]) { + writestruct(wd, DATA, MTex, 1, la->mtex[a]); + } } - - if (la->curfalloff) + + if (la->curfalloff) { write_curvemapping(wd, la->curfalloff); - + } + /* nodetree is integral part of lamps, no libdata */ if (la->nodetree) { - writestruct(wd, DATA, "bNodeTree", 1, la->nodetree); + writestruct(wd, DATA, bNodeTree, 1, la->nodetree); write_nodetree(wd, la->nodetree); } write_previews(wd, la->preview); - + } - la= la->id.next; + la = la->id.next; } } @@ -2364,21 +2582,21 @@ static void write_sequence_modifiers(WriteData *wd, ListBase *modbase) const SequenceModifierTypeInfo *smti = BKE_sequence_modifier_type_info_get(smd->type); if (smti) { - writestruct(wd, DATA, smti->struct_name, 1, smd); + writestruct_id(wd, DATA, smti->struct_name, 1, smd); if (smd->type == seqModifierType_Curves) { - CurvesModifierData *cmd = (CurvesModifierData *) smd; + CurvesModifierData *cmd = (CurvesModifierData *)smd; write_curvemapping(wd, &cmd->curve_mapping); } else if (smd->type == seqModifierType_HueCorrect) { - HueCorrectModifierData *hcmd = (HueCorrectModifierData *) smd; + HueCorrectModifierData *hcmd = (HueCorrectModifierData *)smd; write_curvemapping(wd, &hcmd->curve_mapping); } } else { - writestruct(wd, DATA, "SequenceModifierData", 1, smd); + writestruct(wd, DATA, SequenceModifierData, 1, smd); } } } @@ -2392,8 +2610,9 @@ static void write_view_settings(WriteData *wd, ColorManagedViewSettings *view_se static void write_paint(WriteData *wd, Paint *p) { - if (p->cavity_curve) + if (p->cavity_curve) { write_curvemapping(wd, p->cavity_curve); + } } static void write_scenes(WriteData *wd, ListBase *scebase) @@ -2411,106 +2630,114 @@ static void write_scenes(WriteData *wd, ListBase *scebase) ToolSettings *tos; FreestyleModuleConfig *fmc; FreestyleLineSet *fls; - - sce= scebase->first; + + sce = scebase->first; while (sce) { /* write LibData */ - writestruct(wd, ID_SCE, "Scene", 1, sce); + writestruct(wd, ID_SCE, Scene, 1, sce); write_iddata(wd, &sce->id); - if (sce->adt) write_animdata(wd, sce->adt); + if (sce->adt) { + write_animdata(wd, sce->adt); + } write_keyingsets(wd, &sce->keyingsets); - + /* direct data */ - base= sce->base.first; + base = sce->base.first; while (base) { - writestruct(wd, DATA, "Base", 1, base); - base= base->next; + writestruct(wd, DATA, Base, 1, base); + base = base->next; } - + tos = sce->toolsettings; - writestruct(wd, DATA, "ToolSettings", 1, tos); + writestruct(wd, DATA, ToolSettings, 1, tos); if (tos->vpaint) { - writestruct(wd, DATA, "VPaint", 1, tos->vpaint); + writestruct(wd, DATA, VPaint, 1, tos->vpaint); write_paint(wd, &tos->vpaint->paint); } if (tos->wpaint) { - writestruct(wd, DATA, "VPaint", 1, tos->wpaint); + writestruct(wd, DATA, VPaint, 1, tos->wpaint); write_paint(wd, &tos->wpaint->paint); } if (tos->sculpt) { - writestruct(wd, DATA, "Sculpt", 1, tos->sculpt); + writestruct(wd, DATA, Sculpt, 1, tos->sculpt); write_paint(wd, &tos->sculpt->paint); } if (tos->uvsculpt) { - writestruct(wd, DATA, "UvSculpt", 1, tos->uvsculpt); + writestruct(wd, DATA, UvSculpt, 1, tos->uvsculpt); write_paint(wd, &tos->uvsculpt->paint); } write_paint(wd, &tos->imapaint.paint); - ed= sce->ed; + ed = sce->ed; if (ed) { - writestruct(wd, DATA, "Editing", 1, ed); - + writestruct(wd, DATA, Editing, 1, ed); + /* reset write flags too */ - - SEQ_BEGIN (ed, seq) + + SEQ_BEGIN(ed, seq) { - if (seq->strip) seq->strip->done = false; - writestruct(wd, DATA, "Sequence", 1, seq); + if (seq->strip) { + seq->strip->done = false; + } + writestruct(wd, DATA, Sequence, 1, seq); } SEQ_END - - SEQ_BEGIN (ed, seq) + + SEQ_BEGIN(ed, seq) { - if (seq->strip && seq->strip->done==0) { + if (seq->strip && seq->strip->done == 0) { /* write strip with 'done' at 0 because readfile */ - + if (seq->effectdata) { switch (seq->type) { - case SEQ_TYPE_COLOR: - writestruct(wd, DATA, "SolidColorVars", 1, seq->effectdata); - break; - case SEQ_TYPE_SPEED: - writestruct(wd, DATA, "SpeedControlVars", 1, seq->effectdata); - break; - case SEQ_TYPE_WIPE: - writestruct(wd, DATA, "WipeVars", 1, seq->effectdata); - break; - case SEQ_TYPE_GLOW: - writestruct(wd, DATA, "GlowVars", 1, seq->effectdata); - break; - case SEQ_TYPE_TRANSFORM: - writestruct(wd, DATA, "TransformVars", 1, seq->effectdata); - break; - case SEQ_TYPE_GAUSSIAN_BLUR: - writestruct(wd, DATA, "GaussianBlurVars", 1, seq->effectdata); - break; - case SEQ_TYPE_TEXT: - writestruct(wd, DATA, "TextVars", 1, seq->effectdata); - break; + case SEQ_TYPE_COLOR: + writestruct(wd, DATA, SolidColorVars, 1, seq->effectdata); + break; + case SEQ_TYPE_SPEED: + writestruct(wd, DATA, SpeedControlVars, 1, seq->effectdata); + break; + case SEQ_TYPE_WIPE: + writestruct(wd, DATA, WipeVars, 1, seq->effectdata); + break; + case SEQ_TYPE_GLOW: + writestruct(wd, DATA, GlowVars, 1, seq->effectdata); + break; + case SEQ_TYPE_TRANSFORM: + writestruct(wd, DATA, TransformVars, 1, seq->effectdata); + break; + case SEQ_TYPE_GAUSSIAN_BLUR: + writestruct(wd, DATA, GaussianBlurVars, 1, seq->effectdata); + break; + case SEQ_TYPE_TEXT: + writestruct(wd, DATA, TextVars, 1, seq->effectdata); + break; } } - writestruct(wd, DATA, "Stereo3dFormat", 1, seq->stereo3d_format); + writestruct(wd, DATA, Stereo3dFormat, 1, seq->stereo3d_format); - strip= seq->strip; - writestruct(wd, DATA, "Strip", 1, strip); + strip = seq->strip; + writestruct(wd, DATA, Strip, 1, strip); if (seq->flag & SEQ_USE_CROP && strip->crop) { - writestruct(wd, DATA, "StripCrop", 1, strip->crop); + writestruct(wd, DATA, StripCrop, 1, strip->crop); } if (seq->flag & SEQ_USE_TRANSFORM && strip->transform) { - writestruct(wd, DATA, "StripTransform", 1, strip->transform); + writestruct(wd, DATA, StripTransform, 1, strip->transform); } if (seq->flag & SEQ_USE_PROXY && strip->proxy) { - writestruct(wd, DATA, "StripProxy", 1, strip->proxy); + writestruct(wd, DATA, StripProxy, 1, strip->proxy); + } + if (seq->type == SEQ_TYPE_IMAGE) { + writestruct(wd, DATA, StripElem, + MEM_allocN_len(strip->stripdata) / sizeof(struct StripElem), + strip->stripdata); + } + else if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SOUND_HD)) { + writestruct(wd, DATA, StripElem, 1, strip->stripdata); } - if (seq->type==SEQ_TYPE_IMAGE) - writestruct(wd, DATA, "StripElem", MEM_allocN_len(strip->stripdata) / sizeof(struct StripElem), strip->stripdata); - else if (seq->type==SEQ_TYPE_MOVIE || seq->type==SEQ_TYPE_SOUND_RAM || seq->type == SEQ_TYPE_SOUND_HD) - writestruct(wd, DATA, "StripElem", 1, strip->stripdata); - + strip->done = true; } @@ -2521,67 +2748,76 @@ static void write_scenes(WriteData *wd, ListBase *scebase) write_sequence_modifiers(wd, &seq->modifiers); } SEQ_END - + /* new; meta stack too, even when its nasty restore code */ - for (ms= ed->metastack.first; ms; ms= ms->next) { - writestruct(wd, DATA, "MetaStack", 1, ms); + for (ms = ed->metastack.first; ms; ms = ms->next) { + writestruct(wd, DATA, MetaStack, 1, ms); } } - + if (sce->r.avicodecdata) { - writestruct(wd, DATA, "AviCodecData", 1, sce->r.avicodecdata); - if (sce->r.avicodecdata->lpFormat) writedata(wd, DATA, sce->r.avicodecdata->cbFormat, sce->r.avicodecdata->lpFormat); - if (sce->r.avicodecdata->lpParms) writedata(wd, DATA, sce->r.avicodecdata->cbParms, sce->r.avicodecdata->lpParms); + writestruct(wd, DATA, AviCodecData, 1, sce->r.avicodecdata); + if (sce->r.avicodecdata->lpFormat) { + writedata(wd, DATA, sce->r.avicodecdata->cbFormat, sce->r.avicodecdata->lpFormat); + } + if (sce->r.avicodecdata->lpParms) { + writedata(wd, DATA, sce->r.avicodecdata->cbParms, sce->r.avicodecdata->lpParms); + } } if (sce->r.qtcodecdata) { - writestruct(wd, DATA, "QuicktimeCodecData", 1, sce->r.qtcodecdata); - if (sce->r.qtcodecdata->cdParms) writedata(wd, DATA, sce->r.qtcodecdata->cdSize, sce->r.qtcodecdata->cdParms); + writestruct(wd, DATA, QuicktimeCodecData, 1, sce->r.qtcodecdata); + if (sce->r.qtcodecdata->cdParms) { + writedata(wd, DATA, sce->r.qtcodecdata->cdSize, sce->r.qtcodecdata->cdParms); + } } if (sce->r.ffcodecdata.properties) { IDP_WriteProperty(sce->r.ffcodecdata.properties, wd); } /* writing dynamic list of TimeMarkers to the blend file */ - for (marker= sce->markers.first; marker; marker= marker->next) - writestruct(wd, DATA, "TimeMarker", 1, marker); - + for (marker = sce->markers.first; marker; marker = marker->next) { + writestruct(wd, DATA, TimeMarker, 1, marker); + } + /* writing dynamic list of TransformOrientations to the blend file */ - for (ts = sce->transform_spaces.first; ts; ts = ts->next) - writestruct(wd, DATA, "TransformOrientation", 1, ts); - + for (ts = sce->transform_spaces.first; ts; ts = ts->next) { + writestruct(wd, DATA, TransformOrientation, 1, ts); + } + for (srl = sce->r.layers.first; srl; srl = srl->next) { - writestruct(wd, DATA, "SceneRenderLayer", 1, srl); + writestruct(wd, DATA, SceneRenderLayer, 1, srl); for (fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) { - writestruct(wd, DATA, "FreestyleModuleConfig", 1, fmc); + writestruct(wd, DATA, FreestyleModuleConfig, 1, fmc); } for (fls = srl->freestyleConfig.linesets.first; fls; fls = fls->next) { - writestruct(wd, DATA, "FreestyleLineSet", 1, fls); + writestruct(wd, DATA, FreestyleLineSet, 1, fls); } } /* writing MultiView to the blend file */ - for (srv = sce->r.views.first; srv; srv = srv->next) - writestruct(wd, DATA, "SceneRenderView", 1, srv); - + for (srv = sce->r.views.first; srv; srv = srv->next) { + writestruct(wd, DATA, SceneRenderView, 1, srv); + } + if (sce->nodetree) { - writestruct(wd, DATA, "bNodeTree", 1, sce->nodetree); + writestruct(wd, DATA, bNodeTree, 1, sce->nodetree); write_nodetree(wd, sce->nodetree); } write_view_settings(wd, &sce->view_settings); - + /* writing RigidBodyWorld data to the blend file */ if (sce->rigidbody_world) { - writestruct(wd, DATA, "RigidBodyWorld", 1, sce->rigidbody_world); - writestruct(wd, DATA, "EffectorWeights", 1, sce->rigidbody_world->effector_weights); + writestruct(wd, DATA, RigidBodyWorld, 1, sce->rigidbody_world); + writestruct(wd, DATA, EffectorWeights, 1, sce->rigidbody_world->effector_weights); write_pointcaches(wd, &(sce->rigidbody_world->ptcaches)); } - + write_previews(wd, sce->preview); write_curvemapping_curves(wd, &sce->r.mblur_shutter_curve); - sce= sce->id.next; + sce = sce->id.next; } /* flush helps the compression for undo-save */ mywrite(wd, MYWRITE_FLUSH, 0); @@ -2593,27 +2829,29 @@ static void write_gpencils(WriteData *wd, ListBase *lb) bGPDlayer *gpl; bGPDframe *gpf; bGPDstroke *gps; - - for (gpd= lb->first; gpd; gpd= gpd->id.next) { - if (gpd->id.us>0 || wd->current) { + + for (gpd = lb->first; gpd; gpd = gpd->id.next) { + if (gpd->id.us > 0 || wd->current) { /* write gpd data block to file */ - writestruct(wd, ID_GD, "bGPdata", 1, gpd); + writestruct(wd, ID_GD, bGPdata, 1, gpd); write_iddata(wd, &gpd->id); - if (gpd->adt) write_animdata(wd, gpd->adt); - + if (gpd->adt) { + write_animdata(wd, gpd->adt); + } + /* write grease-pencil layers to file */ - writelist(wd, DATA, "bGPDlayer", &gpd->layers); - for (gpl= gpd->layers.first; gpl; gpl= gpl->next) { - + writelist(wd, DATA, bGPDlayer, &gpd->layers); + for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { + /* write this layer's frames to file */ - writelist(wd, DATA, "bGPDframe", &gpl->frames); - for (gpf= gpl->frames.first; gpf; gpf= gpf->next) { - + writelist(wd, DATA, bGPDframe, &gpl->frames); + for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { + /* write strokes */ - writelist(wd, DATA, "bGPDstroke", &gpf->strokes); - for (gps= gpf->strokes.first; gps; gps= gps->next) { - writestruct(wd, DATA, "bGPDspoint", gps->totpoints, gps->points); + writelist(wd, DATA, bGPDstroke, &gpf->strokes); + for (gps = gpf->strokes.first; gps; gps = gps->next) { + writestruct(wd, DATA, bGPDspoint, gps->totpoints, gps->points); } } } @@ -2625,33 +2863,35 @@ static void write_windowmanagers(WriteData *wd, ListBase *lb) { wmWindowManager *wm; wmWindow *win; - - for (wm= lb->first; wm; wm= wm->id.next) { - writestruct(wd, ID_WM, "wmWindowManager", 1, wm); + + for (wm = lb->first; wm; wm = wm->id.next) { + writestruct(wd, ID_WM, wmWindowManager, 1, wm); write_iddata(wd, &wm->id); - for (win= wm->windows.first; win; win= win->next) { - writestruct(wd, DATA, "wmWindow", 1, win); - writestruct(wd, DATA, "Stereo3dFormat", 1, win->stereo3d_format); + for (win = wm->windows.first; win; win = win->next) { + writestruct(wd, DATA, wmWindow, 1, win); + writestruct(wd, DATA, Stereo3dFormat, 1, win->stereo3d_format); } } } static void write_region(WriteData *wd, ARegion *ar, int spacetype) -{ - writestruct(wd, DATA, "ARegion", 1, ar); - +{ + writestruct(wd, DATA, ARegion, 1, ar); + if (ar->regiondata) { switch (spacetype) { case SPACE_VIEW3D: - if (ar->regiontype==RGN_TYPE_WINDOW) { - RegionView3D *rv3d= ar->regiondata; - writestruct(wd, DATA, "RegionView3D", 1, rv3d); - - if (rv3d->localvd) - writestruct(wd, DATA, "RegionView3D", 1, rv3d->localvd); - if (rv3d->clipbb) - writestruct(wd, DATA, "BoundBox", 1, rv3d->clipbb); + if (ar->regiontype == RGN_TYPE_WINDOW) { + RegionView3D *rv3d = ar->regiondata; + writestruct(wd, DATA, RegionView3D, 1, rv3d); + + if (rv3d->localvd) { + writestruct(wd, DATA, RegionView3D, 1, rv3d->localvd); + } + if (rv3d->clipbb) { + writestruct(wd, DATA, BoundBox, 1, rv3d->clipbb); + } } else @@ -2665,7 +2905,7 @@ static void write_region(WriteData *wd, ARegion *ar, int spacetype) static void write_uilist(WriteData *wd, uiList *ui_list) { - writestruct(wd, DATA, "uiList", 1, ui_list); + writestruct(wd, DATA, uiList, 1, ui_list); if (ui_list->properties) { IDP_WriteProperty(ui_list->properties, wd); @@ -2675,7 +2915,7 @@ static void write_uilist(WriteData *wd, uiList *ui_list) static void write_soops(WriteData *wd, SpaceOops *so, LinkNode **tmp_mem_list) { BLI_mempool *ts = so->treestore; - + if (ts) { int elems = BLI_mempool_count(ts); /* linearize mempool to array */ @@ -2687,13 +2927,13 @@ static void write_soops(WriteData *wd, SpaceOops *so, LinkNode **tmp_mem_list) ts_flat->usedelem = elems; ts_flat->totelem = elems; ts_flat->data = data; - + /* temporarily replace mempool-treestore by flat-treestore */ so->treestore = (BLI_mempool *)ts_flat; - writestruct(wd, DATA, "SpaceOops", 1, so); + writestruct(wd, DATA, SpaceOops, 1, so); - writestruct(wd, DATA, "TreeStore", 1, ts_flat); - writestruct(wd, DATA, "TreeStoreElem", elems, data); + writestruct(wd, DATA, TreeStore, 1, ts_flat); + writestruct(wd, DATA, TreeStoreElem, elems, data); /* we do not free the pointers immediately, because if we have multiple * outliners in a screen we might get the same address on the next @@ -2704,14 +2944,14 @@ static void write_soops(WriteData *wd, SpaceOops *so, LinkNode **tmp_mem_list) } else { so->treestore = NULL; - writestruct(wd, DATA, "SpaceOops", 1, so); + writestruct(wd, DATA, SpaceOops, 1, so); } /* restore old treestore */ so->treestore = ts; } else { - writestruct(wd, DATA, "SpaceOops", 1, so); + writestruct(wd, DATA, SpaceOops, 1, so); } } @@ -2723,208 +2963,225 @@ static void write_screens(WriteData *wd, ListBase *scrbase) ScrEdge *se; LinkNode *tmp_mem_list = NULL; - sc= scrbase->first; + sc = scrbase->first; while (sc) { - + /* write LibData */ /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */ - writestruct(wd, ID_SCRN, "Screen", 1, sc); + writestruct(wd, ID_SCRN, bScreen, 1, sc); write_iddata(wd, &sc->id); /* direct data */ - for (sv= sc->vertbase.first; sv; sv= sv->next) - writestruct(wd, DATA, "ScrVert", 1, sv); - - for (se= sc->edgebase.first; se; se= se->next) - writestruct(wd, DATA, "ScrEdge", 1, se); - - for (sa= sc->areabase.first; sa; sa= sa->next) { + for (sv = sc->vertbase.first; sv; sv = sv->next) { + writestruct(wd, DATA, ScrVert, 1, sv); + } + + for (se = sc->edgebase.first; se; se = se->next) { + writestruct(wd, DATA, ScrEdge, 1, se); + } + + for (sa = sc->areabase.first; sa; sa = sa->next) { SpaceLink *sl; Panel *pa; uiList *ui_list; uiPreview *ui_preview; PanelCategoryStack *pc_act; ARegion *ar; - - writestruct(wd, DATA, "ScrArea", 1, sa); - - for (ar= sa->regionbase.first; ar; ar= ar->next) { + + writestruct(wd, DATA, ScrArea, 1, sa); + + for (ar = sa->regionbase.first; ar; ar = ar->next) { write_region(wd, ar, sa->spacetype); - - for (pa= ar->panels.first; pa; pa= pa->next) - writestruct(wd, DATA, "Panel", 1, pa); - - for (pc_act = ar->panels_category_active.first; pc_act; pc_act = pc_act->next) - writestruct(wd, DATA, "PanelCategoryStack", 1, pc_act); - - for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) + + for (pa = ar->panels.first; pa; pa = pa->next) { + writestruct(wd, DATA, Panel, 1, pa); + } + + for (pc_act = ar->panels_category_active.first; pc_act; pc_act = pc_act->next) { + writestruct(wd, DATA, PanelCategoryStack, 1, pc_act); + } + + for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) { write_uilist(wd, ui_list); + } - for (ui_preview = ar->ui_previews.first; ui_preview; ui_preview = ui_preview->next) - writestruct(wd, DATA, "uiPreview", 1, ui_preview); + for (ui_preview = ar->ui_previews.first; ui_preview; ui_preview = ui_preview->next) { + writestruct(wd, DATA, uiPreview, 1, ui_preview); + } } - - sl= sa->spacedata.first; + + sl = sa->spacedata.first; while (sl) { - for (ar= sl->regionbase.first; ar; ar= ar->next) + for (ar = sl->regionbase.first; ar; ar = ar->next) { write_region(wd, ar, sl->spacetype); - - if (sl->spacetype==SPACE_VIEW3D) { - View3D *v3d= (View3D *) sl; + } + + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; BGpic *bgpic; - writestruct(wd, DATA, "View3D", 1, v3d); - for (bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) - writestruct(wd, DATA, "BGpic", 1, bgpic); - if (v3d->localvd) writestruct(wd, DATA, "View3D", 1, v3d->localvd); - - if (v3d->fx_settings.ssao) - writestruct(wd, DATA, "GPUSSAOSettings", 1, v3d->fx_settings.ssao); - if (v3d->fx_settings.dof) - writestruct(wd, DATA, "GPUDOFSettings", 1, v3d->fx_settings.dof); - } - else if (sl->spacetype==SPACE_IPO) { - SpaceIpo *sipo= (SpaceIpo *)sl; + writestruct(wd, DATA, View3D, 1, v3d); + for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) { + writestruct(wd, DATA, BGpic, 1, bgpic); + } + if (v3d->localvd) { + writestruct(wd, DATA, View3D, 1, v3d->localvd); + } + + if (v3d->fx_settings.ssao) { + writestruct(wd, DATA, GPUSSAOSettings, 1, v3d->fx_settings.ssao); + } + if (v3d->fx_settings.dof) { + writestruct(wd, DATA, GPUDOFSettings, 1, v3d->fx_settings.dof); + } + } + else if (sl->spacetype == SPACE_IPO) { + SpaceIpo *sipo = (SpaceIpo *)sl; ListBase tmpGhosts = sipo->ghostCurves; - + /* temporarily disable ghost curves when saving */ - sipo->ghostCurves.first= sipo->ghostCurves.last= NULL; - - writestruct(wd, DATA, "SpaceIpo", 1, sl); - if (sipo->ads) writestruct(wd, DATA, "bDopeSheet", 1, sipo->ads); - + sipo->ghostCurves.first = sipo->ghostCurves.last = NULL; + + writestruct(wd, DATA, SpaceIpo, 1, sl); + if (sipo->ads) { + writestruct(wd, DATA, bDopeSheet, 1, sipo->ads); + } + /* reenable ghost curves */ - sipo->ghostCurves= tmpGhosts; + sipo->ghostCurves = tmpGhosts; } - else if (sl->spacetype==SPACE_BUTS) { - writestruct(wd, DATA, "SpaceButs", 1, sl); + else if (sl->spacetype == SPACE_BUTS) { + writestruct(wd, DATA, SpaceButs, 1, sl); } - else if (sl->spacetype==SPACE_FILE) { - SpaceFile *sfile= (SpaceFile *)sl; + else if (sl->spacetype == SPACE_FILE) { + SpaceFile *sfile = (SpaceFile *)sl; - writestruct(wd, DATA, "SpaceFile", 1, sl); - if (sfile->params) - writestruct(wd, DATA, "FileSelectParams", 1, sfile->params); + writestruct(wd, DATA, SpaceFile, 1, sl); + if (sfile->params) { + writestruct(wd, DATA, FileSelectParams, 1, sfile->params); + } } - else if (sl->spacetype==SPACE_SEQ) { - writestruct(wd, DATA, "SpaceSeq", 1, sl); + else if (sl->spacetype == SPACE_SEQ) { + writestruct(wd, DATA, SpaceSeq, 1, sl); } - else if (sl->spacetype==SPACE_OUTLINER) { - SpaceOops *so= (SpaceOops *)sl; + else if (sl->spacetype == SPACE_OUTLINER) { + SpaceOops *so = (SpaceOops *)sl; write_soops(wd, so, &tmp_mem_list); } - else if (sl->spacetype==SPACE_IMAGE) { - writestruct(wd, DATA, "SpaceImage", 1, sl); + else if (sl->spacetype == SPACE_IMAGE) { + writestruct(wd, DATA, SpaceImage, 1, sl); } - else if (sl->spacetype==SPACE_TEXT) { - writestruct(wd, DATA, "SpaceText", 1, sl); + else if (sl->spacetype == SPACE_TEXT) { + writestruct(wd, DATA, SpaceText, 1, sl); } - else if (sl->spacetype==SPACE_SCRIPT) { - SpaceScript *scr = (SpaceScript*)sl; + else if (sl->spacetype == SPACE_SCRIPT) { + SpaceScript *scr = (SpaceScript *)sl; scr->but_refs = NULL; - writestruct(wd, DATA, "SpaceScript", 1, sl); + writestruct(wd, DATA, SpaceScript, 1, sl); } - else if (sl->spacetype==SPACE_ACTION) { - writestruct(wd, DATA, "SpaceAction", 1, sl); + else if (sl->spacetype == SPACE_ACTION) { + writestruct(wd, DATA, SpaceAction, 1, sl); } - else if (sl->spacetype==SPACE_NLA) { - SpaceNla *snla= (SpaceNla *)sl; - - writestruct(wd, DATA, "SpaceNla", 1, snla); - if (snla->ads) writestruct(wd, DATA, "bDopeSheet", 1, snla->ads); + else if (sl->spacetype == SPACE_NLA) { + SpaceNla *snla = (SpaceNla *)sl; + + writestruct(wd, DATA, SpaceNla, 1, snla); + if (snla->ads) { + writestruct(wd, DATA, bDopeSheet, 1, snla->ads); + } } - else if (sl->spacetype==SPACE_TIME) { - writestruct(wd, DATA, "SpaceTime", 1, sl); + else if (sl->spacetype == SPACE_TIME) { + writestruct(wd, DATA, SpaceTime, 1, sl); } - else if (sl->spacetype==SPACE_NODE) { + else if (sl->spacetype == SPACE_NODE) { SpaceNode *snode = (SpaceNode *)sl; bNodeTreePath *path; - writestruct(wd, DATA, "SpaceNode", 1, snode); - - for (path=snode->treepath.first; path; path=path->next) - writestruct(wd, DATA, "bNodeTreePath", 1, path); + writestruct(wd, DATA, SpaceNode, 1, snode); + + for (path = snode->treepath.first; path; path = path->next) { + writestruct(wd, DATA, bNodeTreePath, 1, path); + } } - else if (sl->spacetype==SPACE_LOGIC) { - writestruct(wd, DATA, "SpaceLogic", 1, sl); + else if (sl->spacetype == SPACE_LOGIC) { + writestruct(wd, DATA, SpaceLogic, 1, sl); } - else if (sl->spacetype==SPACE_CONSOLE) { - SpaceConsole *con = (SpaceConsole*)sl; + else if (sl->spacetype == SPACE_CONSOLE) { + SpaceConsole *con = (SpaceConsole *)sl; ConsoleLine *cl; - for (cl=con->history.first; cl; cl=cl->next) { + for (cl = con->history.first; cl; cl = cl->next) { /* 'len_alloc' is invalid on write, set from 'len' on read */ - writestruct(wd, DATA, "ConsoleLine", 1, cl); - writedata(wd, DATA, cl->len+1, cl->line); + writestruct(wd, DATA, ConsoleLine, 1, cl); + writedata(wd, DATA, cl->len + 1, cl->line); } - writestruct(wd, DATA, "SpaceConsole", 1, sl); + writestruct(wd, DATA, SpaceConsole, 1, sl); } - else if (sl->spacetype==SPACE_USERPREF) { - writestruct(wd, DATA, "SpaceUserPref", 1, sl); + else if (sl->spacetype == SPACE_USERPREF) { + writestruct(wd, DATA, SpaceUserPref, 1, sl); } - else if (sl->spacetype==SPACE_CLIP) { - writestruct(wd, DATA, "SpaceClip", 1, sl); + else if (sl->spacetype == SPACE_CLIP) { + writestruct(wd, DATA, SpaceClip, 1, sl); } else if (sl->spacetype == SPACE_INFO) { - writestruct(wd, DATA, "SpaceInfo", 1, sl); + writestruct(wd, DATA, SpaceInfo, 1, sl); } - sl= sl->next; + sl = sl->next; } } - sc= sc->id.next; + sc = sc->id.next; } BLI_linklist_freeN(tmp_mem_list); - + /* flush helps the compression for undo-save */ mywrite(wd, MYWRITE_FLUSH, 0); } static void write_bone(WriteData *wd, Bone *bone) { - Bone* cbone; - - // PATCH for upward compatibility after 2.37+ armature recode + /* PATCH for upward compatibility after 2.37+ armature recode */ bone->size[0] = bone->size[1] = bone->size[2] = 1.0f; - - // Write this bone - writestruct(wd, DATA, "Bone", 1, bone); + + /* Write this bone */ + writestruct(wd, DATA, Bone, 1, bone); /* Write ID Properties -- and copy this comment EXACTLY for easy finding * of library blocks that implement this.*/ - if (bone->prop) + if (bone->prop) { IDP_WriteProperty(bone->prop, wd); - - // Write Children - cbone= bone->childbase.first; - while (cbone) { + } + + /* Write Children */ + for (Bone *cbone = bone->childbase.first; cbone; cbone = cbone->next) { write_bone(wd, cbone); - cbone= cbone->next; } } static void write_armatures(WriteData *wd, ListBase *idbase) { - bArmature *arm; - Bone *bone; + bArmature *arm; + Bone *bone; - arm=idbase->first; + arm = idbase->first; while (arm) { - if (arm->id.us>0 || wd->current) { - writestruct(wd, ID_AR, "bArmature", 1, arm); + if (arm->id.us > 0 || wd->current) { + writestruct(wd, ID_AR, bArmature, 1, arm); write_iddata(wd, &arm->id); - if (arm->adt) write_animdata(wd, arm->adt); + if (arm->adt) { + write_animdata(wd, arm->adt); + } /* Direct data */ - bone= arm->bonebase.first; + bone = arm->bonebase.first; while (bone) { write_bone(wd, bone); - bone=bone->next; + bone = bone->next; } } - arm=arm->id.next; + arm = arm->id.next; } /* flush helps the compression for undo-save */ @@ -2936,33 +3193,37 @@ static void write_texts(WriteData *wd, ListBase *idbase) Text *text; TextLine *tmp; - text= idbase->first; + text = idbase->first; while (text) { - if ( (text->flags & TXT_ISMEM) && (text->flags & TXT_ISEXT)) text->flags &= ~TXT_ISEXT; + if ( (text->flags & TXT_ISMEM) && (text->flags & TXT_ISEXT)) { + text->flags &= ~TXT_ISEXT; + } /* write LibData */ - writestruct(wd, ID_TXT, "Text", 1, text); + writestruct(wd, ID_TXT, Text, 1, text); write_iddata(wd, &text->id); - if (text->name) writedata(wd, DATA, strlen(text->name)+1, text->name); + if (text->name) { + writedata(wd, DATA, strlen(text->name) + 1, text->name); + } if (!(text->flags & TXT_ISEXT)) { /* now write the text data, in two steps for optimization in the readfunction */ - tmp= text->lines.first; + tmp = text->lines.first; while (tmp) { - writestruct(wd, DATA, "TextLine", 1, tmp); - tmp= tmp->next; + writestruct(wd, DATA, TextLine, 1, tmp); + tmp = tmp->next; } - tmp= text->lines.first; + tmp = text->lines.first; while (tmp) { - writedata(wd, DATA, tmp->len+1, tmp->line); - tmp= tmp->next; + writedata(wd, DATA, tmp->len + 1, tmp->line); + tmp = tmp->next; } } - text= text->id.next; + text = text->id.next; } /* flush helps the compression for undo-save */ @@ -2973,16 +3234,18 @@ static void write_speakers(WriteData *wd, ListBase *idbase) { Speaker *spk; - spk= idbase->first; + spk = idbase->first; while (spk) { - if (spk->id.us>0 || wd->current) { + if (spk->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_SPK, "Speaker", 1, spk); + writestruct(wd, ID_SPK, Speaker, 1, spk); write_iddata(wd, &spk->id); - if (spk->adt) write_animdata(wd, spk->adt); + if (spk->adt) { + write_animdata(wd, spk->adt); + } } - spk= spk->id.next; + spk = spk->id.next; } } @@ -2990,22 +3253,22 @@ static void write_sounds(WriteData *wd, ListBase *idbase) { bSound *sound; - PackedFile * pf; + PackedFile *pf; - sound= idbase->first; + sound = idbase->first; while (sound) { - if (sound->id.us>0 || wd->current) { + if (sound->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_SO, "bSound", 1, sound); + writestruct(wd, ID_SO, bSound, 1, sound); write_iddata(wd, &sound->id); if (sound->packedfile) { pf = sound->packedfile; - writestruct(wd, DATA, "PackedFile", 1, pf); + writestruct(wd, DATA, PackedFile, 1, pf); writedata(wd, DATA, pf->size, pf->data); } } - sound= sound->id.next; + sound = sound->id.next; } /* flush helps the compression for undo-save */ @@ -3017,18 +3280,18 @@ static void write_groups(WriteData *wd, ListBase *idbase) Group *group; GroupObject *go; - for (group= idbase->first; group; group= group->id.next) { - if (group->id.us>0 || wd->current) { + for (group = idbase->first; group; group = group->id.next) { + if (group->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_GR, "Group", 1, group); + writestruct(wd, ID_GR, Group, 1, group); write_iddata(wd, &group->id); write_previews(wd, group->preview); - go= group->gobject.first; + go = group->gobject.first; while (go) { - writestruct(wd, DATA, "GroupObject", 1, go); - go= go->next; + writestruct(wd, DATA, GroupObject, 1, go); + go = go->next; } } } @@ -3037,10 +3300,10 @@ static void write_groups(WriteData *wd, ListBase *idbase) static void write_nodetrees(WriteData *wd, ListBase *idbase) { bNodeTree *ntree; - - for (ntree=idbase->first; ntree; ntree= ntree->id.next) { - if (ntree->id.us>0 || wd->current) { - writestruct(wd, ID_NT, "bNodeTree", 1, ntree); + + for (ntree = idbase->first; ntree; ntree = ntree->id.next) { + if (ntree->id.us > 0 || wd->current) { + writestruct(wd, ID_NT, bNodeTree, 1, ntree); /* Note that trees directly used by other IDs (materials etc.) are not 'real' ID, they cannot * be linked, etc., so we write actual id data here only, for 'real' ID trees. */ write_iddata(wd, &ntree->id); @@ -3055,11 +3318,12 @@ static void customnodes_add_deprecated_data(Main *mainvar) { FOREACH_NODETREE(mainvar, ntree, id) { bNodeLink *link, *last_link = ntree->links.last; - + /* only do this for node groups */ - if (id != &ntree->id) + if (id != &ntree->id) { continue; - + } + /* Forward compatibility for group nodes: add links to node tree interface sockets. * These links are invalid by new rules (missing node pointer)! * They will be removed again in customnodes_free_deprecated_data, @@ -3070,7 +3334,7 @@ static void customnodes_add_deprecated_data(Main *mainvar) for (link = ntree->links.first; link; link = link->next) { bNode *fromnode = link->fromnode, *tonode = link->tonode; bNodeSocket *fromsock = link->fromsock, *tosock = link->tosock; - + /* check both sides of the link, to handle direct input-to-output links */ if (fromnode->type == NODE_GROUP_INPUT) { fromnode = NULL; @@ -3081,22 +3345,23 @@ static void customnodes_add_deprecated_data(Main *mainvar) tonode = NULL; tosock = ntreeFindSocketInterface(ntree, SOCK_OUT, tosock->identifier); } - + if (!fromnode || !tonode) { /* Note: not using nodeAddLink here, it asserts existing node pointers */ bNodeLink *tlink = MEM_callocN(sizeof(bNodeLink), "group node link"); tlink->fromnode = fromnode; tlink->fromsock = fromsock; tlink->tonode = tonode; - tlink->tosock= tosock; + tlink->tosock = tosock; tosock->link = tlink; tlink->flag |= NODE_LINK_VALID; BLI_addtail(&ntree->links, tlink); } - + /* don't check newly created compatibility links */ - if (link == last_link) + if (link == last_link) { break; + } } } FOREACH_NODETREE_END @@ -3106,11 +3371,12 @@ static void customnodes_free_deprecated_data(Main *mainvar) { FOREACH_NODETREE(mainvar, ntree, id) { bNodeLink *link, *next_link; - + for (link = ntree->links.first; link; link = next_link) { next_link = link->next; - if (link->fromnode == NULL || link->tonode == NULL) + if (link->fromnode == NULL || link->tonode == NULL) { nodeRemLink(ntree, link); + } } } FOREACH_NODETREE_END @@ -3120,16 +3386,18 @@ static void customnodes_free_deprecated_data(Main *mainvar) static void write_brushes(WriteData *wd, ListBase *idbase) { Brush *brush; - - for (brush=idbase->first; brush; brush= brush->id.next) { - if (brush->id.us>0 || wd->current) { - writestruct(wd, ID_BR, "Brush", 1, brush); + + for (brush = idbase->first; brush; brush = brush->id.next) { + if (brush->id.us > 0 || wd->current) { + writestruct(wd, ID_BR, Brush, 1, brush); write_iddata(wd, &brush->id); - if (brush->curve) + if (brush->curve) { write_curvemapping(wd, brush->curve); - if (brush->gradient) - writestruct(wd, DATA, "ColorBand", 1, brush->gradient); + } + if (brush->gradient) { + writestruct(wd, DATA, ColorBand, 1, brush->gradient); + } } } } @@ -3141,11 +3409,12 @@ static void write_palettes(WriteData *wd, ListBase *idbase) for (palette = idbase->first; palette; palette = palette->id.next) { if (palette->id.us > 0 || wd->current) { PaletteColor *color; - writestruct(wd, ID_PAL, "Palette", 1, palette); + writestruct(wd, ID_PAL, Palette, 1, palette); write_iddata(wd, &palette->id); - for (color = palette->colors.first; color; color= color->next) - writestruct(wd, DATA, "PaletteColor", 1, color); + for (color = palette->colors.first; color; color = color->next) { + writestruct(wd, DATA, PaletteColor, 1, color); + } } } } @@ -3156,10 +3425,10 @@ static void write_paintcurves(WriteData *wd, ListBase *idbase) for (pc = idbase->first; pc; pc = pc->id.next) { if (pc->id.us > 0 || wd->current) { - writestruct(wd, ID_PC, "PaintCurve", 1, pc); + writestruct(wd, ID_PC, PaintCurve, 1, pc); write_iddata(wd, &pc->id); - writestruct(wd, DATA, "PaintCurvePoint", pc->tot_points, pc->points); + writestruct(wd, DATA, PaintCurvePoint, pc->tot_points, pc->points); } } } @@ -3168,14 +3437,15 @@ static void write_movieTracks(WriteData *wd, ListBase *tracks) { MovieTrackingTrack *track; - track= tracks->first; + track = tracks->first; while (track) { - writestruct(wd, DATA, "MovieTrackingTrack", 1, track); + writestruct(wd, DATA, MovieTrackingTrack, 1, track); - if (track->markers) - writestruct(wd, DATA, "MovieTrackingMarker", track->markersnr, track->markers); + if (track->markers) { + writestruct(wd, DATA, MovieTrackingMarker, track->markersnr, track->markers); + } - track= track->next; + track = track->next; } } @@ -3187,52 +3457,54 @@ static void write_moviePlaneTracks(WriteData *wd, ListBase *plane_tracks_base) plane_track; plane_track = plane_track->next) { - writestruct(wd, DATA, "MovieTrackingPlaneTrack", 1, plane_track); + writestruct(wd, DATA, MovieTrackingPlaneTrack, 1, plane_track); writedata(wd, DATA, sizeof(MovieTrackingTrack *) * plane_track->point_tracksnr, plane_track->point_tracks); - writestruct(wd, DATA, "MovieTrackingPlaneMarker", plane_track->markersnr, plane_track->markers); + writestruct(wd, DATA, MovieTrackingPlaneMarker, plane_track->markersnr, plane_track->markers); } } static void write_movieReconstruction(WriteData *wd, MovieTrackingReconstruction *reconstruction) { - if (reconstruction->camnr) - writestruct(wd, DATA, "MovieReconstructedCamera", reconstruction->camnr, reconstruction->cameras); + if (reconstruction->camnr) { + writestruct(wd, DATA, MovieReconstructedCamera, reconstruction->camnr, reconstruction->cameras); + } } static void write_movieclips(WriteData *wd, ListBase *idbase) { MovieClip *clip; - clip= idbase->first; + clip = idbase->first; while (clip) { - if (clip->id.us>0 || wd->current) { - MovieTracking *tracking= &clip->tracking; + if (clip->id.us > 0 || wd->current) { + MovieTracking *tracking = &clip->tracking; MovieTrackingObject *object; - writestruct(wd, ID_MC, "MovieClip", 1, clip); + writestruct(wd, ID_MC, MovieClip, 1, clip); write_iddata(wd, &clip->id); - if (clip->adt) + if (clip->adt) { write_animdata(wd, clip->adt); + } write_movieTracks(wd, &tracking->tracks); write_moviePlaneTracks(wd, &tracking->plane_tracks); write_movieReconstruction(wd, &tracking->reconstruction); - object= tracking->objects.first; + object = tracking->objects.first; while (object) { - writestruct(wd, DATA, "MovieTrackingObject", 1, object); + writestruct(wd, DATA, MovieTrackingObject, 1, object); write_movieTracks(wd, &object->tracks); write_moviePlaneTracks(wd, &object->plane_tracks); write_movieReconstruction(wd, &object->reconstruction); - object= object->next; + object = object->next; } } - clip= clip->id.next; + clip = clip->id.next; } /* flush helps the compression for undo-save */ @@ -3248,17 +3520,18 @@ static void write_masks(WriteData *wd, ListBase *idbase) if (mask->id.us > 0 || wd->current) { MaskLayer *masklay; - writestruct(wd, ID_MSK, "Mask", 1, mask); + writestruct(wd, ID_MSK, Mask, 1, mask); write_iddata(wd, &mask->id); - if (mask->adt) + if (mask->adt) { write_animdata(wd, mask->adt); + } for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { MaskSpline *spline; MaskLayerShape *masklay_shape; - writestruct(wd, DATA, "MaskLayer", 1, masklay); + writestruct(wd, DATA, MaskLayer, 1, masklay); for (spline = masklay->splines.first; spline; spline = spline->next) { int i; @@ -3266,22 +3539,28 @@ static void write_masks(WriteData *wd, ListBase *idbase) void *points_deform = spline->points_deform; spline->points_deform = NULL; - writestruct(wd, DATA, "MaskSpline", 1, spline); - writestruct(wd, DATA, "MaskSplinePoint", spline->tot_point, spline->points); + writestruct(wd, DATA, MaskSpline, 1, spline); + writestruct(wd, DATA, MaskSplinePoint, spline->tot_point, spline->points); spline->points_deform = points_deform; for (i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; - if (point->tot_uw) - writestruct(wd, DATA, "MaskSplinePointUW", point->tot_uw, point->uw); + if (point->tot_uw) { + writestruct(wd, DATA, MaskSplinePointUW, point->tot_uw, point->uw); + } } } - for (masklay_shape = masklay->splines_shapes.first; masklay_shape; masklay_shape = masklay_shape->next) { - writestruct(wd, DATA, "MaskLayerShape", 1, masklay_shape); - writedata(wd, DATA, masklay_shape->tot_vert * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE, masklay_shape->data); + for (masklay_shape = masklay->splines_shapes.first; + masklay_shape; + masklay_shape = masklay_shape->next) + { + writestruct(wd, DATA, MaskLayerShape, 1, masklay_shape); + writedata(wd, DATA, + masklay_shape->tot_vert * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE, + masklay_shape->data); } } } @@ -3296,65 +3575,65 @@ static void write_masks(WriteData *wd, ListBase *idbase) static void write_linestyle_color_modifiers(WriteData *wd, ListBase *modifiers) { LineStyleModifier *m; - const char *struct_name; for (m = modifiers->first; m; m = m->next) { + int struct_nr; switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - struct_name = "LineStyleColorModifier_AlongStroke"; - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - struct_name = "LineStyleColorModifier_DistanceFromCamera"; - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - struct_name = "LineStyleColorModifier_DistanceFromObject"; - break; - case LS_MODIFIER_MATERIAL: - struct_name = "LineStyleColorModifier_Material"; - break; - case LS_MODIFIER_TANGENT: - struct_name = "LineStyleColorModifier_Tangent"; - break; - case LS_MODIFIER_NOISE: - struct_name = "LineStyleColorModifier_Noise"; - break; - case LS_MODIFIER_CREASE_ANGLE: - struct_name = "LineStyleColorModifier_CreaseAngle"; - break; - case LS_MODIFIER_CURVATURE_3D: - struct_name = "LineStyleColorModifier_Curvature_3D"; - break; - default: - struct_name = "LineStyleColorModifier"; /* this should not happen */ + case LS_MODIFIER_ALONG_STROKE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_AlongStroke); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromCamera); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromObject); + break; + case LS_MODIFIER_MATERIAL: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Material); + break; + case LS_MODIFIER_TANGENT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Tangent); + break; + case LS_MODIFIER_NOISE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Noise); + break; + case LS_MODIFIER_CREASE_ANGLE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_CreaseAngle); + break; + case LS_MODIFIER_CURVATURE_3D: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Curvature_3D); + break; + default: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ } - writestruct(wd, DATA, struct_name, 1, m); + writestruct_nr(wd, DATA, struct_nr, 1, m); } for (m = modifiers->first; m; m = m->next) { switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp); - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp); - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp); - break; - case LS_MODIFIER_MATERIAL: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Material *)m)->color_ramp); - break; - case LS_MODIFIER_TANGENT: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Tangent *)m)->color_ramp); - break; - case LS_MODIFIER_NOISE: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Noise *)m)->color_ramp); - break; - case LS_MODIFIER_CREASE_ANGLE: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_CreaseAngle *)m)->color_ramp); - break; - case LS_MODIFIER_CURVATURE_3D: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Curvature_3D *)m)->color_ramp); - break; + case LS_MODIFIER_ALONG_STROKE: + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp); + break; + case LS_MODIFIER_MATERIAL: + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_Material *)m)->color_ramp); + break; + case LS_MODIFIER_TANGENT: + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_Tangent *)m)->color_ramp); + break; + case LS_MODIFIER_NOISE: + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_Noise *)m)->color_ramp); + break; + case LS_MODIFIER_CREASE_ANGLE: + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_CreaseAngle *)m)->color_ramp); + break; + case LS_MODIFIER_CURVATURE_3D: + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_Curvature_3D *)m)->color_ramp); + break; } } } @@ -3362,65 +3641,65 @@ static void write_linestyle_color_modifiers(WriteData *wd, ListBase *modifiers) static void write_linestyle_alpha_modifiers(WriteData *wd, ListBase *modifiers) { LineStyleModifier *m; - const char *struct_name; for (m = modifiers->first; m; m = m->next) { + int struct_nr; switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - struct_name = "LineStyleAlphaModifier_AlongStroke"; - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - struct_name = "LineStyleAlphaModifier_DistanceFromCamera"; - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - struct_name = "LineStyleAlphaModifier_DistanceFromObject"; - break; - case LS_MODIFIER_MATERIAL: - struct_name = "LineStyleAlphaModifier_Material"; - break; - case LS_MODIFIER_TANGENT: - struct_name = "LineStyleAlphaModifier_Tangent"; - break; - case LS_MODIFIER_NOISE: - struct_name = "LineStyleAlphaModifier_Noise"; - break; - case LS_MODIFIER_CREASE_ANGLE: - struct_name = "LineStyleAlphaModifier_CreaseAngle"; - break; - case LS_MODIFIER_CURVATURE_3D: - struct_name = "LineStyleAlphaModifier_Curvature_3D"; - break; - default: - struct_name = "LineStyleAlphaModifier"; /* this should not happen */ + case LS_MODIFIER_ALONG_STROKE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_AlongStroke); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromCamera); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromObject); + break; + case LS_MODIFIER_MATERIAL: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Material); + break; + case LS_MODIFIER_TANGENT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Tangent); + break; + case LS_MODIFIER_NOISE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Noise); + break; + case LS_MODIFIER_CREASE_ANGLE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_CreaseAngle); + break; + case LS_MODIFIER_CURVATURE_3D: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Curvature_3D); + break; + default: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ } - writestruct(wd, DATA, struct_name, 1, m); + writestruct_nr(wd, DATA, struct_nr, 1, m); } for (m = modifiers->first; m; m = m->next) { switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - write_curvemapping(wd, ((LineStyleAlphaModifier_AlongStroke *)m)->curve); - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - write_curvemapping(wd, ((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve); - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - write_curvemapping(wd, ((LineStyleAlphaModifier_DistanceFromObject *)m)->curve); - break; - case LS_MODIFIER_MATERIAL: - write_curvemapping(wd, ((LineStyleAlphaModifier_Material *)m)->curve); - break; - case LS_MODIFIER_TANGENT: - write_curvemapping(wd, ((LineStyleAlphaModifier_Tangent *)m)->curve); - break; - case LS_MODIFIER_NOISE: - write_curvemapping(wd, ((LineStyleAlphaModifier_Noise *)m)->curve); - break; - case LS_MODIFIER_CREASE_ANGLE: - write_curvemapping(wd, ((LineStyleAlphaModifier_CreaseAngle *)m)->curve); - break; - case LS_MODIFIER_CURVATURE_3D: - write_curvemapping(wd, ((LineStyleAlphaModifier_Curvature_3D *)m)->curve); - break; + case LS_MODIFIER_ALONG_STROKE: + write_curvemapping(wd, ((LineStyleAlphaModifier_AlongStroke *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + write_curvemapping(wd, ((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + write_curvemapping(wd, ((LineStyleAlphaModifier_DistanceFromObject *)m)->curve); + break; + case LS_MODIFIER_MATERIAL: + write_curvemapping(wd, ((LineStyleAlphaModifier_Material *)m)->curve); + break; + case LS_MODIFIER_TANGENT: + write_curvemapping(wd, ((LineStyleAlphaModifier_Tangent *)m)->curve); + break; + case LS_MODIFIER_NOISE: + write_curvemapping(wd, ((LineStyleAlphaModifier_Noise *)m)->curve); + break; + case LS_MODIFIER_CREASE_ANGLE: + write_curvemapping(wd, ((LineStyleAlphaModifier_CreaseAngle *)m)->curve); + break; + case LS_MODIFIER_CURVATURE_3D: + write_curvemapping(wd, ((LineStyleAlphaModifier_Curvature_3D *)m)->curve); + break; } } } @@ -3428,65 +3707,65 @@ static void write_linestyle_alpha_modifiers(WriteData *wd, ListBase *modifiers) static void write_linestyle_thickness_modifiers(WriteData *wd, ListBase *modifiers) { LineStyleModifier *m; - const char *struct_name; for (m = modifiers->first; m; m = m->next) { + int struct_nr; switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - struct_name = "LineStyleThicknessModifier_AlongStroke"; - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - struct_name = "LineStyleThicknessModifier_DistanceFromCamera"; - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - struct_name = "LineStyleThicknessModifier_DistanceFromObject"; - break; - case LS_MODIFIER_MATERIAL: - struct_name = "LineStyleThicknessModifier_Material"; - break; - case LS_MODIFIER_CALLIGRAPHY: - struct_name = "LineStyleThicknessModifier_Calligraphy"; - break; - case LS_MODIFIER_TANGENT: - struct_name = "LineStyleThicknessModifier_Tangent"; - break; - case LS_MODIFIER_NOISE: - struct_name = "LineStyleThicknessModifier_Noise"; - break; - case LS_MODIFIER_CREASE_ANGLE: - struct_name = "LineStyleThicknessModifier_CreaseAngle"; - break; - case LS_MODIFIER_CURVATURE_3D: - struct_name = "LineStyleThicknessModifier_Curvature_3D"; - break; - default: - struct_name = "LineStyleThicknessModifier"; /* this should not happen */ + case LS_MODIFIER_ALONG_STROKE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_AlongStroke); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromCamera); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromObject); + break; + case LS_MODIFIER_MATERIAL: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Material); + break; + case LS_MODIFIER_CALLIGRAPHY: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Calligraphy); + break; + case LS_MODIFIER_TANGENT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Tangent); + break; + case LS_MODIFIER_NOISE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Noise); + break; + case LS_MODIFIER_CREASE_ANGLE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_CreaseAngle); + break; + case LS_MODIFIER_CURVATURE_3D: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Curvature_3D); + break; + default: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ } - writestruct(wd, DATA, struct_name, 1, m); + writestruct_nr(wd, DATA, struct_nr, 1, m); } for (m = modifiers->first; m; m = m->next) { switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - write_curvemapping(wd, ((LineStyleThicknessModifier_AlongStroke *)m)->curve); - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - write_curvemapping(wd, ((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve); - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - write_curvemapping(wd, ((LineStyleThicknessModifier_DistanceFromObject *)m)->curve); - break; - case LS_MODIFIER_MATERIAL: - write_curvemapping(wd, ((LineStyleThicknessModifier_Material *)m)->curve); - break; - case LS_MODIFIER_TANGENT: - write_curvemapping(wd, ((LineStyleThicknessModifier_Tangent *)m)->curve); - break; - case LS_MODIFIER_CREASE_ANGLE: - write_curvemapping(wd, ((LineStyleThicknessModifier_CreaseAngle *)m)->curve); - break; - case LS_MODIFIER_CURVATURE_3D: - write_curvemapping(wd, ((LineStyleThicknessModifier_Curvature_3D *)m)->curve); - break; + case LS_MODIFIER_ALONG_STROKE: + write_curvemapping(wd, ((LineStyleThicknessModifier_AlongStroke *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + write_curvemapping(wd, ((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + write_curvemapping(wd, ((LineStyleThicknessModifier_DistanceFromObject *)m)->curve); + break; + case LS_MODIFIER_MATERIAL: + write_curvemapping(wd, ((LineStyleThicknessModifier_Material *)m)->curve); + break; + case LS_MODIFIER_TANGENT: + write_curvemapping(wd, ((LineStyleThicknessModifier_Tangent *)m)->curve); + break; + case LS_MODIFIER_CREASE_ANGLE: + write_curvemapping(wd, ((LineStyleThicknessModifier_CreaseAngle *)m)->curve); + break; + case LS_MODIFIER_CURVATURE_3D: + write_curvemapping(wd, ((LineStyleThicknessModifier_Curvature_3D *)m)->curve); + break; } } } @@ -3494,56 +3773,56 @@ static void write_linestyle_thickness_modifiers(WriteData *wd, ListBase *modifie static void write_linestyle_geometry_modifiers(WriteData *wd, ListBase *modifiers) { LineStyleModifier *m; - const char *struct_name; for (m = modifiers->first; m; m = m->next) { + int struct_nr; switch (m->type) { - case LS_MODIFIER_SAMPLING: - struct_name = "LineStyleGeometryModifier_Sampling"; - break; - case LS_MODIFIER_BEZIER_CURVE: - struct_name = "LineStyleGeometryModifier_BezierCurve"; - break; - case LS_MODIFIER_SINUS_DISPLACEMENT: - struct_name = "LineStyleGeometryModifier_SinusDisplacement"; - break; - case LS_MODIFIER_SPATIAL_NOISE: - struct_name = "LineStyleGeometryModifier_SpatialNoise"; - break; - case LS_MODIFIER_PERLIN_NOISE_1D: - struct_name = "LineStyleGeometryModifier_PerlinNoise1D"; - break; - case LS_MODIFIER_PERLIN_NOISE_2D: - struct_name = "LineStyleGeometryModifier_PerlinNoise2D"; - break; - case LS_MODIFIER_BACKBONE_STRETCHER: - struct_name = "LineStyleGeometryModifier_BackboneStretcher"; - break; - case LS_MODIFIER_TIP_REMOVER: - struct_name = "LineStyleGeometryModifier_TipRemover"; - break; - case LS_MODIFIER_POLYGONIZATION: - struct_name = "LineStyleGeometryModifier_Polygonalization"; - break; - case LS_MODIFIER_GUIDING_LINES: - struct_name = "LineStyleGeometryModifier_GuidingLines"; - break; - case LS_MODIFIER_BLUEPRINT: - struct_name = "LineStyleGeometryModifier_Blueprint"; - break; - case LS_MODIFIER_2D_OFFSET: - struct_name = "LineStyleGeometryModifier_2DOffset"; - break; - case LS_MODIFIER_2D_TRANSFORM: - struct_name = "LineStyleGeometryModifier_2DTransform"; - break; - case LS_MODIFIER_SIMPLIFICATION: - struct_name = "LineStyleGeometryModifier_Simplification"; - break; - default: - struct_name = "LineStyleGeometryModifier"; /* this should not happen */ + case LS_MODIFIER_SAMPLING: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Sampling); + break; + case LS_MODIFIER_BEZIER_CURVE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BezierCurve); + break; + case LS_MODIFIER_SINUS_DISPLACEMENT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_SinusDisplacement); + break; + case LS_MODIFIER_SPATIAL_NOISE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_SpatialNoise); + break; + case LS_MODIFIER_PERLIN_NOISE_1D: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_PerlinNoise1D); + break; + case LS_MODIFIER_PERLIN_NOISE_2D: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_PerlinNoise2D); + break; + case LS_MODIFIER_BACKBONE_STRETCHER: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BackboneStretcher); + break; + case LS_MODIFIER_TIP_REMOVER: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_TipRemover); + break; + case LS_MODIFIER_POLYGONIZATION: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Polygonalization); + break; + case LS_MODIFIER_GUIDING_LINES: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_GuidingLines); + break; + case LS_MODIFIER_BLUEPRINT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Blueprint); + break; + case LS_MODIFIER_2D_OFFSET: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_2DOffset); + break; + case LS_MODIFIER_2D_TRANSFORM: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_2DTransform); + break; + case LS_MODIFIER_SIMPLIFICATION: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Simplification); + break; + default: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ } - writestruct(wd, DATA, struct_name, 1, m); + writestruct_nr(wd, DATA, struct_nr, 1, m); } } @@ -3553,21 +3832,25 @@ static void write_linestyles(WriteData *wd, ListBase *idbase) int a; for (linestyle = idbase->first; linestyle; linestyle = linestyle->id.next) { - if (linestyle->id.us>0 || wd->current) { - writestruct(wd, ID_LS, "FreestyleLineStyle", 1, linestyle); + if (linestyle->id.us > 0 || wd->current) { + writestruct(wd, ID_LS, FreestyleLineStyle, 1, linestyle); write_iddata(wd, &linestyle->id); - if (linestyle->adt) + if (linestyle->adt) { write_animdata(wd, linestyle->adt); + } + write_linestyle_color_modifiers(wd, &linestyle->color_modifiers); write_linestyle_alpha_modifiers(wd, &linestyle->alpha_modifiers); write_linestyle_thickness_modifiers(wd, &linestyle->thickness_modifiers); write_linestyle_geometry_modifiers(wd, &linestyle->geometry_modifiers); - for (a=0; a<MAX_MTEX; a++) { - if (linestyle->mtex[a]) writestruct(wd, DATA, "MTex", 1, linestyle->mtex[a]); + for (a = 0; a < MAX_MTEX; a++) { + if (linestyle->mtex[a]) { + writestruct(wd, DATA, MTex, 1, linestyle->mtex[a]); + } } if (linestyle->nodetree) { - writestruct(wd, DATA, "bNodeTree", 1, linestyle->nodetree); + writestruct(wd, DATA, bNodeTree, 1, linestyle->nodetree); write_nodetree(wd, linestyle->nodetree); } } @@ -3582,23 +3865,26 @@ static void write_libraries(WriteData *wd, Main *main) int a, tot; bool found_one; - for (; main; main= main->next) { + for (; main; main = main->next) { - a=tot= set_listbasepointers(main, lbarray); + a = tot = set_listbasepointers(main, lbarray); /* test: is lib being used */ - if (main->curlib && main->curlib->packedfile) + if (main->curlib && main->curlib->packedfile) { found_one = true; + } else { found_one = false; while (tot--) { - for (id= lbarray[tot]->first; id; id= id->next) { + for (id = lbarray[tot]->first; id; id = id->next) { if (id->us > 0 && (id->tag & LIB_TAG_EXTERN)) { found_one = true; break; } } - if (found_one) break; + if (found_one) { + break; + } } } @@ -3606,26 +3892,27 @@ static void write_libraries(WriteData *wd, Main *main) /* XXX needs rethink, just like save UI in undo files now - would be nice to append things only for the] * quit.blend and temp saves */ if (found_one) { - writestruct(wd, ID_LI, "Library", 1, main->curlib); + writestruct(wd, ID_LI, Library, 1, main->curlib); write_iddata(wd, &main->curlib->id); if (main->curlib->packedfile) { PackedFile *pf = main->curlib->packedfile; - writestruct(wd, DATA, "PackedFile", 1, pf); + writestruct(wd, DATA, PackedFile, 1, pf); writedata(wd, DATA, pf->size, pf->data); - if (wd->current == NULL) + if (wd->current == NULL) { printf("write packed .blend: %s\n", main->curlib->name); + } } while (a--) { - for (id= lbarray[a]->first; id; id= id->next) { + for (id = lbarray[a]->first; id; id = id->next) { if (id->us > 0 && (id->tag & LIB_TAG_EXTERN)) { if (!BKE_idcode_is_linkable(GS(id->name))) { printf("ERROR: write file: datablock '%s' from lib '%s' is not linkable " "but is flagged as directly linked", id->name, main->curlib->filepath); BLI_assert(0); } - writestruct(wd, ID_ID, "ID", 1, id); + writestruct(wd, ID_ID, ID, 1, id); } } } @@ -3642,7 +3929,7 @@ static void write_global(WriteData *wd, int fileflags, Main *mainvar) FileGlobal fg; bScreen *screen; char subvstr[8]; - + /* prevent mem checkers from complaining */ memset(fg.pad, 0, sizeof(fg.pad)); memset(fg.filename, 0, sizeof(fg.filename)); @@ -3651,20 +3938,20 @@ static void write_global(WriteData *wd, int fileflags, Main *mainvar) current_screen_compat(mainvar, &screen, is_undo); /* XXX still remap G */ - fg.curscreen= screen; - fg.curscene= screen ? screen->scene : NULL; + fg.curscreen = screen; + fg.curscene = screen ? screen->scene : NULL; /* prevent to save this, is not good convention, and feature with concerns... */ - fg.fileflags= (fileflags & ~G_FILE_FLAGS_RUNTIME); + fg.fileflags = (fileflags & ~G_FILE_FLAGS_RUNTIME); - fg.globalf= G.f; + fg.globalf = G.f; BLI_strncpy(fg.filename, mainvar->name, sizeof(fg.filename)); sprintf(subvstr, "%4d", BLENDER_SUBVERSION); memcpy(fg.subvstr, subvstr, 4); - - fg.subversion= BLENDER_SUBVERSION; - fg.minversion= BLENDER_MINVERSION; - fg.minsubversion= BLENDER_MINSUBVERSION; + + fg.subversion = BLENDER_SUBVERSION; + fg.minversion = BLENDER_MINVERSION; + fg.minsubversion = BLENDER_MINSUBVERSION; #ifdef WITH_BUILDINFO { extern unsigned long build_commit_timestamp; @@ -3677,7 +3964,7 @@ static void write_global(WriteData *wd, int fileflags, Main *mainvar) fg.build_commit_timestamp = 0; BLI_strncpy(fg.build_hash, "unknown", sizeof(fg.build_hash)); #endif - writestruct(wd, GLOB, "FileGlobal", 1, &fg); + writestruct(wd, GLOB, FileGlobal, 1, &fg); } /* preview image, first 2 values are width and height @@ -3692,11 +3979,11 @@ static void write_thumb(WriteData *wd, const BlendThumbnail *thumb) } /* if MemFile * there's filesave to memory */ -static int write_file_handle( +static bool write_file_handle( Main *mainvar, WriteWrap *ww, MemFile *compare, MemFile *current, - int write_user_block, int write_flags, const BlendThumbnail *thumb) + int write_flags, const BlendThumbnail *thumb) { BHead bhead; ListBase mainlist; @@ -3731,42 +4018,42 @@ static int write_file_handle( write_global(wd, write_flags, mainvar); write_windowmanagers(wd, &mainvar->wm); - write_screens (wd, &mainvar->screen); - write_movieclips (wd, &mainvar->movieclip); - write_masks (wd, &mainvar->mask); - write_scenes (wd, &mainvar->scene); - write_curves (wd, &mainvar->curve); - write_mballs (wd, &mainvar->mball); - write_images (wd, &mainvar->image); - write_cameras (wd, &mainvar->camera); - write_lamps (wd, &mainvar->lamp); - write_lattices (wd, &mainvar->latt); - write_vfonts (wd, &mainvar->vfont); - write_keys (wd, &mainvar->key); - write_worlds (wd, &mainvar->world); - write_texts (wd, &mainvar->text); - write_speakers (wd, &mainvar->speaker); - write_sounds (wd, &mainvar->sound); - write_groups (wd, &mainvar->group); + write_screens(wd, &mainvar->screen); + write_movieclips(wd, &mainvar->movieclip); + write_masks(wd, &mainvar->mask); + write_scenes(wd, &mainvar->scene); + write_curves(wd, &mainvar->curve); + write_mballs(wd, &mainvar->mball); + write_images(wd, &mainvar->image); + write_cameras(wd, &mainvar->camera); + write_lamps(wd, &mainvar->lamp); + write_lattices(wd, &mainvar->latt); + write_vfonts(wd, &mainvar->vfont); + write_keys(wd, &mainvar->key); + write_worlds(wd, &mainvar->world); + write_texts(wd, &mainvar->text); + write_speakers(wd, &mainvar->speaker); + write_sounds(wd, &mainvar->sound); + write_groups(wd, &mainvar->group); write_armatures(wd, &mainvar->armature); - write_actions (wd, &mainvar->action); - write_objects (wd, &mainvar->object); + write_actions(wd, &mainvar->action); + write_objects(wd, &mainvar->object); write_materials(wd, &mainvar->mat); - write_textures (wd, &mainvar->tex); - write_meshes (wd, &mainvar->mesh); + write_textures(wd, &mainvar->tex); + write_meshes(wd, &mainvar->mesh); write_particlesettings(wd, &mainvar->particle); write_nodetrees(wd, &mainvar->nodetree); - write_brushes (wd, &mainvar->brush); - write_palettes (wd, &mainvar->palettes); - write_paintcurves (wd, &mainvar->paintcurves); - write_gpencils (wd, &mainvar->gpencil); + write_brushes(wd, &mainvar->brush); + write_palettes(wd, &mainvar->palettes); + write_paintcurves(wd, &mainvar->paintcurves); + write_gpencils(wd, &mainvar->gpencil); write_linestyles(wd, &mainvar->linestyle); write_libraries(wd, mainvar->next); - if (write_user_block) { + if (write_flags & G_FILE_USERPREFS) { write_userdef(wd); } - + /* dna as last, because (to be implemented) test for which structs are written */ writedata(wd, DNA1, wd->sdna->datalen, wd->sdna->data); @@ -3783,7 +4070,7 @@ static int write_file_handle( /* end of file */ memset(&bhead, 0, sizeof(BHead)); - bhead.code= ENDB; + bhead.code = ENDB; mywrite(wd, &bhead, sizeof(BHead)); blo_join_main(&mainlist); @@ -3796,16 +4083,19 @@ static int write_file_handle( static bool do_history(const char *name, ReportList *reports) { char tempname1[FILE_MAX], tempname2[FILE_MAX]; - int hisnr= U.versions; - - if (U.versions==0) return 0; - if (strlen(name)<2) { + int hisnr = U.versions; + + if (U.versions == 0) { + return 0; + } + + if (strlen(name) < 2) { BKE_report(reports, RPT_ERROR, "Unable to make version backup: filename too short"); return 1; } while (hisnr > 1) { - BLI_snprintf(tempname1, sizeof(tempname1), "%s%d", name, hisnr-1); + BLI_snprintf(tempname1, sizeof(tempname1), "%s%d", name, hisnr - 1); if (BLI_exists(tempname1)) { BLI_snprintf(tempname2, sizeof(tempname2), "%s%d", name, hisnr); @@ -3837,8 +4127,7 @@ bool BLO_write_file( Main *mainvar, const char *filepath, int write_flags, ReportList *reports, const BlendThumbnail *thumb) { - char tempname[FILE_MAX+1]; - int err, write_user_block; + char tempname[FILE_MAX + 1]; eWriteWrapType ww_type; WriteWrap ww; @@ -3893,13 +4182,13 @@ bool BLO_write_file( } } - write_user_block= write_flags & G_FILE_USERPREFS; - - if (write_flags & G_FILE_RELATIVE_REMAP) - BKE_bpath_relative_convert(mainvar, filepath, NULL); /* note, making relative to something OTHER then G.main->name */ + if (write_flags & G_FILE_RELATIVE_REMAP) { + /* note, making relative to something OTHER then G.main->name */ + BKE_bpath_relative_convert(mainvar, filepath, NULL); + } /* actual file writing */ - err = write_file_handle(mainvar, &ww, NULL, NULL, write_user_block, write_flags, thumb); + const bool err = write_file_handle(mainvar, &ww, NULL, NULL, write_flags, thumb); ww.close(&ww); @@ -3938,9 +4227,9 @@ bool BLO_write_file( */ bool BLO_write_file_mem(Main *mainvar, MemFile *compare, MemFile *current, int write_flags) { - int err; + write_flags &= ~G_FILE_USERPREFS; - err = write_file_handle(mainvar, NULL, compare, current, 0, write_flags, NULL); + const bool err = write_file_handle(mainvar, NULL, compare, current, write_flags, NULL); return (err == 0); } diff --git a/source/blender/bmesh/bmesh_class.h b/source/blender/bmesh/bmesh_class.h index e3caeedd2c9..72ea7bd7f5d 100644 --- a/source/blender/bmesh/bmesh_class.h +++ b/source/blender/bmesh/bmesh_class.h @@ -89,7 +89,6 @@ BLI_STATIC_ASSERT((sizeof(BMHeader) <= 16), "BMHeader size has grown!"); typedef struct BMVert { BMHeader head; - struct BMFlagLayer *oflags; /* keep after header, an array of flags, mostly used by the operator stack */ float co[3]; /* vertex coordinates */ float no[3]; /* vertex normal */ @@ -102,6 +101,11 @@ typedef struct BMVert { struct BMEdge *e; } BMVert; +typedef struct BMVert_OFlag { + BMVert base; + struct BMFlagLayer *oflags; +} BMVert_OFlag; + /* disk link structure, only used by edges */ typedef struct BMDiskLink { struct BMEdge *next, *prev; @@ -109,7 +113,6 @@ typedef struct BMDiskLink { typedef struct BMEdge { BMHeader head; - struct BMFlagLayer *oflags; /* keep after header, an array of flags, mostly used by the operator stack */ struct BMVert *v1, *v2; /* vertices (unordered) */ @@ -122,6 +125,11 @@ typedef struct BMEdge { BMDiskLink v1_disk_link, v2_disk_link; } BMEdge; +typedef struct BMEdge_OFlag { + BMEdge base; + struct BMFlagLayer *oflags; +} BMEdge_OFlag; + typedef struct BMLoop { BMHeader head; /* notice no flags layer */ @@ -142,10 +150,6 @@ typedef struct BMLoop { /* can cast BMFace/BMEdge/BMVert, but NOT BMLoop, since these don't have a flag layer */ typedef struct BMElemF { BMHeader head; - - /* keep directly after header, - * optional array of flags, only used by the operator stack */ - struct BMFlagLayer *oflags; } BMElemF; /* can cast anything to this, including BMLoop */ @@ -163,7 +167,6 @@ typedef struct BMLoopList { typedef struct BMFace { BMHeader head; - struct BMFlagLayer *oflags; /* an array of flags, mostly used by the operator stack */ #ifdef USE_BMESH_HOLES int totbounds; /*total boundaries, is one plus the number of holes in the face*/ @@ -177,6 +180,11 @@ typedef struct BMFace { // short _pad[3]; } BMFace; +typedef struct BMFace_OFlag { + BMFace base; + struct BMFlagLayer *oflags; +} BMFace_OFlag; + typedef struct BMFlagLayer { short f; /* flags */ } BMFlagLayer; @@ -217,6 +225,8 @@ typedef struct BMesh { /* operator api stuff (must be all NULL or all alloc'd) */ struct BLI_mempool *vtoolflagpool, *etoolflagpool, *ftoolflagpool; + unsigned int use_toolflags : 1; + int toolflag_index; struct BMOperator *currentop; @@ -259,10 +269,12 @@ enum { /* args for _Generic */ #define _BM_GENERIC_TYPE_ELEM_NONCONST \ void *, BMVert *, BMEdge *, BMLoop *, BMFace *, \ + BMVert_OFlag *, BMEdge_OFlag *, BMFace_OFlag *, \ BMElem *, BMElemF *, BMHeader * #define _BM_GENERIC_TYPE_ELEM_CONST \ const void *, const BMVert *, const BMEdge *, const BMLoop *, const BMFace *, \ + const BMVert_OFlag *, const BMEdge_OFlag *, const BMFace_OFlag *, \ const BMElem *, const BMElemF *, const BMHeader *, \ void * const, BMVert * const, BMEdge * const, BMLoop * const, BMFace * const, \ BMElem * const, BMElemF * const, BMHeader * const @@ -276,6 +288,27 @@ enum { #define BM_CHECK_TYPE_ELEM(ele) \ CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_ELEM_NONCONST, _BM_GENERIC_TYPE_ELEM_CONST) +/* vert */ +#define _BM_GENERIC_TYPE_VERT_NONCONST BMVert *, BMVert_OFlag * +#define _BM_GENERIC_TYPE_VERT_CONST const BMVert *, const BMVert_OFlag * +#define BM_CHECK_TYPE_VERT_CONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_VERT_CONST) +#define BM_CHECK_TYPE_VERT_NONCONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_ELEM_NONCONST) +#define BM_CHECK_TYPE_VERT(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_VERT_NONCONST, _BM_GENERIC_TYPE_VERT_CONST) +/* edge */ +#define _BM_GENERIC_TYPE_EDGE_NONCONST BMEdge *, BMEdge_OFlag * +#define _BM_GENERIC_TYPE_EDGE_CONST const BMEdge *, const BMEdge_OFlag * +#define BM_CHECK_TYPE_EDGE_CONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_EDGE_CONST) +#define BM_CHECK_TYPE_EDGE_NONCONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_ELEM_NONCONST) +#define BM_CHECK_TYPE_EDGE(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_EDGE_NONCONST, _BM_GENERIC_TYPE_EDGE_CONST) +/* face */ +#define _BM_GENERIC_TYPE_FACE_NONCONST BMFace *, BMFace_OFlag * +#define _BM_GENERIC_TYPE_FACE_CONST const BMFace *, const BMFace_OFlag * +#define BM_CHECK_TYPE_FACE_CONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_FACE_CONST) +#define BM_CHECK_TYPE_FACE_NONCONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_ELEM_NONCONST) +#define BM_CHECK_TYPE_FACE(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_FACE_NONCONST, _BM_GENERIC_TYPE_FACE_CONST) + + + /* Assignment from a void* to a typed pointer is not allowed in C++, * casting the LHS to void works fine though. */ diff --git a/source/blender/bmesh/intern/bmesh_construct.c b/source/blender/bmesh/intern/bmesh_construct.c index fdad93ee90d..4d92baab6eb 100644 --- a/source/blender/bmesh/intern/bmesh_construct.c +++ b/source/blender/bmesh/intern/bmesh_construct.c @@ -714,7 +714,9 @@ BMesh *BM_mesh_copy(BMesh *bm_old) const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_BM(bm_old); /* allocate a bmesh */ - bm_new = BM_mesh_create(&allocsize); + bm_new = BM_mesh_create( + &allocsize, + &((struct BMeshCreateParams){.use_toolflags = bm_old->use_toolflags,})); BM_mesh_copy_init_customdata(bm_new, bm_old, &allocsize); diff --git a/source/blender/bmesh/intern/bmesh_core.c b/source/blender/bmesh/intern/bmesh_core.c index 1d68cdcf28a..e83b752947c 100644 --- a/source/blender/bmesh/intern/bmesh_core.c +++ b/source/blender/bmesh/intern/bmesh_core.c @@ -81,7 +81,9 @@ BMVert *BM_vert_create( v->head.api_flag = 0; /* allocate flags */ - v->oflags = bm->vtoolflagpool ? BLI_mempool_calloc(bm->vtoolflagpool) : NULL; + if (bm->use_toolflags) { + ((BMVert_OFlag *)v)->oflags = bm->vtoolflagpool ? BLI_mempool_calloc(bm->vtoolflagpool) : NULL; + } /* 'v->no' is handled by BM_elem_attrs_copy */ if (co) { @@ -174,7 +176,9 @@ BMEdge *BM_edge_create( e->head.api_flag = 0; /* allocate flags */ - e->oflags = bm->etoolflagpool ? BLI_mempool_calloc(bm->etoolflagpool) : NULL; + if (bm->use_toolflags) { + ((BMEdge_OFlag *)e)->oflags = bm->etoolflagpool ? BLI_mempool_calloc(bm->etoolflagpool) : NULL; + } e->v1 = v1; e->v2 = v2; @@ -386,7 +390,9 @@ BLI_INLINE BMFace *bm_face_create__internal(BMesh *bm) f->head.api_flag = 0; /* allocate flags */ - f->oflags = bm->ftoolflagpool ? BLI_mempool_calloc(bm->ftoolflagpool) : NULL; + if (bm->use_toolflags) { + ((BMFace_OFlag *)f)->oflags = bm->ftoolflagpool ? BLI_mempool_calloc(bm->ftoolflagpool) : NULL; + } #ifdef USE_BMESH_HOLES BLI_listbase_clear(&f->loops); @@ -758,7 +764,7 @@ static void bm_kill_only_vert(BMesh *bm, BMVert *v) CustomData_bmesh_free_block(&bm->vdata, &v->head.data); if (bm->vtoolflagpool) { - BLI_mempool_free(bm->vtoolflagpool, v->oflags); + BLI_mempool_free(bm->vtoolflagpool, ((BMVert_OFlag *)v)->oflags); } BLI_mempool_free(bm->vpool, v); } @@ -779,7 +785,7 @@ static void bm_kill_only_edge(BMesh *bm, BMEdge *e) CustomData_bmesh_free_block(&bm->edata, &e->head.data); if (bm->etoolflagpool) { - BLI_mempool_free(bm->etoolflagpool, e->oflags); + BLI_mempool_free(bm->etoolflagpool, ((BMEdge_OFlag *)e)->oflags); } BLI_mempool_free(bm->epool, e); } @@ -803,7 +809,7 @@ static void bm_kill_only_face(BMesh *bm, BMFace *f) CustomData_bmesh_free_block(&bm->pdata, &f->head.data); if (bm->ftoolflagpool) { - BLI_mempool_free(bm->ftoolflagpool, f->oflags); + BLI_mempool_free(bm->ftoolflagpool, ((BMFace_OFlag *)f)->oflags); } BLI_mempool_free(bm->fpool, f); } @@ -2196,7 +2202,7 @@ BMFace *bmesh_jfke(BMesh *bm, BMFace *f1, BMFace *f2, BMEdge *e) /* deallocate edge and its two loops as well as f2 */ if (bm->etoolflagpool) { - BLI_mempool_free(bm->etoolflagpool, l_f1->e->oflags); + BLI_mempool_free(bm->etoolflagpool, ((BMEdge_OFlag *)l_f1->e)->oflags); } BLI_mempool_free(bm->epool, l_f1->e); bm->totedge--; @@ -2205,7 +2211,7 @@ BMFace *bmesh_jfke(BMesh *bm, BMFace *f1, BMFace *f2, BMEdge *e) BLI_mempool_free(bm->lpool, l_f2); bm->totloop--; if (bm->ftoolflagpool) { - BLI_mempool_free(bm->ftoolflagpool, f2->oflags); + BLI_mempool_free(bm->ftoolflagpool, ((BMFace_OFlag *)f2)->oflags); } BLI_mempool_free(bm->fpool, f2); bm->totface--; diff --git a/source/blender/bmesh/intern/bmesh_delete.c b/source/blender/bmesh/intern/bmesh_delete.c index 882d78ce6b3..1449a6ef9d7 100644 --- a/source/blender/bmesh/intern/bmesh_delete.c +++ b/source/blender/bmesh/intern/bmesh_delete.c @@ -54,7 +54,7 @@ static void bmo_remove_tagged_faces(BMesh *bm, const short oflag) BMIter iter; BM_ITER_MESH_MUTABLE (f, f_next, &iter, bm, BM_FACES_OF_MESH) { - if (BMO_elem_flag_test(bm, f, oflag)) { + if (BMO_face_flag_test(bm, f, oflag)) { BM_face_kill(bm, f); } } @@ -66,7 +66,7 @@ static void bmo_remove_tagged_edges(BMesh *bm, const short oflag) BMIter iter; BM_ITER_MESH_MUTABLE (e, e_next, &iter, bm, BM_EDGES_OF_MESH) { - if (BMO_elem_flag_test(bm, e, oflag)) { + if (BMO_edge_flag_test(bm, e, oflag)) { BM_edge_kill(bm, e); } } @@ -78,7 +78,7 @@ static void bmo_remove_tagged_verts(BMesh *bm, const short oflag) BMIter iter; BM_ITER_MESH_MUTABLE (v, v_next, &iter, bm, BM_VERTS_OF_MESH) { - if (BMO_elem_flag_test(bm, v, oflag)) { + if (BMO_vert_flag_test(bm, v, oflag)) { BM_vert_kill(bm, v); } } @@ -90,7 +90,7 @@ static void bmo_remove_tagged_verts_loose(BMesh *bm, const short oflag) BMIter iter; BM_ITER_MESH_MUTABLE (v, v_next, &iter, bm, BM_VERTS_OF_MESH) { - if (BMO_elem_flag_test(bm, v, oflag) && (v->e == NULL)) { + if (BMO_vert_flag_test(bm, v, oflag) && (v->e == NULL)) { BM_vert_kill(bm, v); } } @@ -132,9 +132,9 @@ void BMO_mesh_delete_oflag_context(BMesh *bm, const short oflag, const int type) { /* flush down to vert */ BM_ITER_MESH (e, &eiter, bm, BM_EDGES_OF_MESH) { - if (BMO_elem_flag_test(bm, e, oflag)) { - BMO_elem_flag_enable(bm, e->v1, oflag); - BMO_elem_flag_enable(bm, e->v2, oflag); + if (BMO_edge_flag_test(bm, e, oflag)) { + BMO_vert_flag_enable(bm, e->v1, oflag); + BMO_vert_flag_enable(bm, e->v2, oflag); } } bmo_remove_tagged_edges(bm, oflag); @@ -165,27 +165,27 @@ void BMO_mesh_delete_oflag_context(BMesh *bm, const short oflag, const int type) { /* go through and mark all edges and all verts of all faces for delete */ BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { - if (BMO_elem_flag_test(bm, f, oflag)) { + if (BMO_face_flag_test(bm, f, oflag)) { BMLoop *l_first = BM_FACE_FIRST_LOOP(f); BMLoop *l_iter; l_iter = l_first; do { - BMO_elem_flag_enable(bm, l_iter->v, oflag); - BMO_elem_flag_enable(bm, l_iter->e, oflag); + BMO_vert_flag_enable(bm, l_iter->v, oflag); + BMO_edge_flag_enable(bm, l_iter->e, oflag); } while ((l_iter = l_iter->next) != l_first); } } /* now go through and mark all remaining faces all edges for keeping */ BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { - if (!BMO_elem_flag_test(bm, f, oflag)) { + if (!BMO_face_flag_test(bm, f, oflag)) { BMLoop *l_first = BM_FACE_FIRST_LOOP(f); BMLoop *l_iter; l_iter = l_first; do { - BMO_elem_flag_disable(bm, l_iter->v, oflag); - BMO_elem_flag_disable(bm, l_iter->e, oflag); + BMO_vert_flag_disable(bm, l_iter->v, oflag); + BMO_edge_flag_disable(bm, l_iter->e, oflag); } while ((l_iter = l_iter->next) != l_first); } } @@ -195,13 +195,13 @@ void BMO_mesh_delete_oflag_context(BMesh *bm, const short oflag, const int type) /* Only exception to normal 'DEL_FACES' logic. */ if (type == DEL_FACES_KEEP_BOUNDARY) { if (BM_edge_is_boundary(e)) { - BMO_elem_flag_disable(bm, e, oflag); + BMO_edge_flag_disable(bm, e, oflag); } } - if (!BMO_elem_flag_test(bm, e, oflag)) { - BMO_elem_flag_disable(bm, e->v1, oflag); - BMO_elem_flag_disable(bm, e->v2, oflag); + if (!BMO_edge_flag_test(bm, e, oflag)) { + BMO_vert_flag_disable(bm, e->v1, oflag); + BMO_vert_flag_disable(bm, e->v2, oflag); } } diff --git a/source/blender/bmesh/intern/bmesh_iterators.c b/source/blender/bmesh/intern/bmesh_iterators.c index cc79e28a361..961b10d848a 100644 --- a/source/blender/bmesh/intern/bmesh_iterators.c +++ b/source/blender/bmesh/intern/bmesh_iterators.c @@ -339,16 +339,43 @@ int BMO_iter_elem_count_flag( const short oflag, const bool value) { BMIter iter; - BMElemF *ele; int count = 0; /* loops have no header flags */ BLI_assert(bm_iter_itype_htype_map[itype] != BM_LOOP); - BM_ITER_ELEM (ele, &iter, data, itype) { - if (BMO_elem_flag_test_bool(bm, ele, oflag) == value) { - count++; + switch (bm_iter_itype_htype_map[itype]) { + case BM_VERT: + { + BMVert *ele; + BM_ITER_ELEM (ele, &iter, data, itype) { + if (BMO_vert_flag_test_bool(bm, ele, oflag) == value) { + count++; + } + } + break; } + case BM_EDGE: + { + BMEdge *ele; + BM_ITER_ELEM (ele, &iter, data, itype) { + if (BMO_edge_flag_test_bool(bm, ele, oflag) == value) { + count++; + } + } + break; + } + case BM_FACE: + { + BMFace *ele; + BM_ITER_ELEM (ele, &iter, data, itype) { + if (BMO_face_flag_test_bool(bm, ele, oflag) == value) { + count++; + } + } + break; + } + } return count; } diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index ed1bd16b2e4..32aa80a4e73 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -48,16 +48,52 @@ const BMAllocTemplate bm_mesh_allocsize_default = {512, 1024, 2048, 512}; const BMAllocTemplate bm_mesh_chunksize_default = {512, 1024, 2048, 512}; -static void bm_mempool_init(BMesh *bm, const BMAllocTemplate *allocsize) +static void bm_mempool_init_ex( + const BMAllocTemplate *allocsize, const bool use_toolflags, + BLI_mempool **r_vpool, BLI_mempool **r_epool, BLI_mempool **r_lpool, BLI_mempool **r_fpool) { - bm->vpool = BLI_mempool_create(sizeof(BMVert), allocsize->totvert, - bm_mesh_chunksize_default.totvert, BLI_MEMPOOL_ALLOW_ITER); - bm->epool = BLI_mempool_create(sizeof(BMEdge), allocsize->totedge, - bm_mesh_chunksize_default.totedge, BLI_MEMPOOL_ALLOW_ITER); - bm->lpool = BLI_mempool_create(sizeof(BMLoop), allocsize->totloop, - bm_mesh_chunksize_default.totloop, BLI_MEMPOOL_NOP); - bm->fpool = BLI_mempool_create(sizeof(BMFace), allocsize->totface, - bm_mesh_chunksize_default.totface, BLI_MEMPOOL_ALLOW_ITER); + size_t vert_size, edge_size, loop_size, face_size; + + if (use_toolflags == true) { + vert_size = sizeof(BMVert_OFlag); + edge_size = sizeof(BMEdge_OFlag); + loop_size = sizeof(BMLoop); + face_size = sizeof(BMFace_OFlag); + } + else { + vert_size = sizeof(BMVert); + edge_size = sizeof(BMEdge); + loop_size = sizeof(BMLoop); + face_size = sizeof(BMFace); + } + + if (r_vpool) { + *r_vpool = BLI_mempool_create( + vert_size, allocsize->totvert, + bm_mesh_chunksize_default.totvert, BLI_MEMPOOL_ALLOW_ITER); + } + if (r_epool) { + *r_epool = BLI_mempool_create( + edge_size, allocsize->totedge, + bm_mesh_chunksize_default.totedge, BLI_MEMPOOL_ALLOW_ITER); + } + if (r_lpool) { + *r_lpool = BLI_mempool_create( + loop_size, allocsize->totloop, + bm_mesh_chunksize_default.totloop, BLI_MEMPOOL_NOP); + } + if (r_fpool) { + *r_fpool = BLI_mempool_create( + face_size, allocsize->totface, + bm_mesh_chunksize_default.totface, BLI_MEMPOOL_ALLOW_ITER); + } +} + +static void bm_mempool_init(BMesh *bm, const BMAllocTemplate *allocsize, const bool use_toolflags) +{ + bm_mempool_init_ex( + allocsize, use_toolflags, + &bm->vpool, &bm->epool, &bm->lpool, &bm->fpool); #ifdef USE_BMESH_HOLES bm->looplistpool = BLI_mempool_create(sizeof(BMLoopList), 512, 512, BLI_MEMPOOL_NOP); @@ -66,6 +102,8 @@ static void bm_mempool_init(BMesh *bm, const BMAllocTemplate *allocsize) void BM_mesh_elem_toolflags_ensure(BMesh *bm) { + BLI_assert(bm->use_toolflags); + if (bm->vtoolflagpool && bm->etoolflagpool && bm->ftoolflagpool) { return; } @@ -80,7 +118,7 @@ void BM_mesh_elem_toolflags_ensure(BMesh *bm) { BLI_mempool *toolflagpool = bm->vtoolflagpool; BMIter iter; - BMElemF *ele; + BMVert_OFlag *ele; BM_ITER_MESH (ele, &iter, bm, BM_VERTS_OF_MESH) { ele->oflags = BLI_mempool_calloc(toolflagpool); } @@ -89,7 +127,7 @@ void BM_mesh_elem_toolflags_ensure(BMesh *bm) { BLI_mempool *toolflagpool = bm->etoolflagpool; BMIter iter; - BMElemF *ele; + BMEdge_OFlag *ele; BM_ITER_MESH (ele, &iter, bm, BM_EDGES_OF_MESH) { ele->oflags = BLI_mempool_calloc(toolflagpool); } @@ -98,7 +136,7 @@ void BM_mesh_elem_toolflags_ensure(BMesh *bm) { BLI_mempool *toolflagpool = bm->ftoolflagpool; BMIter iter; - BMElemF *ele; + BMFace_OFlag *ele; BM_ITER_MESH (ele, &iter, bm, BM_FACES_OF_MESH) { ele->oflags = BLI_mempool_calloc(toolflagpool); } @@ -134,15 +172,18 @@ void BM_mesh_elem_toolflags_clear(BMesh *bm) * * \note ob is needed by multires */ -BMesh *BM_mesh_create(const BMAllocTemplate *allocsize) +BMesh *BM_mesh_create( + const BMAllocTemplate *allocsize, + const struct BMeshCreateParams *params) { /* allocate the structure */ BMesh *bm = MEM_callocN(sizeof(BMesh), __func__); /* allocate the memory pools for the mesh elements */ - bm_mempool_init(bm, allocsize); + bm_mempool_init(bm, allocsize, params->use_toolflags); /* allocate one flag pool that we don't get rid of. */ + bm->use_toolflags = params->use_toolflags; bm->toolflag_index = 0; bm->totflags = 0; @@ -239,13 +280,16 @@ void BM_mesh_data_free(BMesh *bm) */ void BM_mesh_clear(BMesh *bm) { + const bool use_toolflags = bm->use_toolflags; + /* free old mesh */ BM_mesh_data_free(bm); memset(bm, 0, sizeof(BMesh)); /* allocate the memory pools for the mesh elements */ - bm_mempool_init(bm, &bm_mesh_allocsize_default); + bm_mempool_init(bm, &bm_mesh_allocsize_default, use_toolflags); + bm->use_toolflags = use_toolflags; bm->toolflag_index = 0; bm->totflags = 0; @@ -1706,3 +1750,262 @@ void BM_mesh_remap( if (fptr_map) BLI_ghash_free(fptr_map, NULL, NULL); } + +/** + * Use new memory pools for this mesh. + * + * \note needed for re-sizing elements (adding/removing tool flags) + * but could also be used for packing fragmented bmeshes. + */ +void BM_mesh_rebuild( + BMesh *bm, const struct BMeshCreateParams *params, + BLI_mempool *vpool_dst, BLI_mempool *epool_dst, BLI_mempool *lpool_dst, BLI_mempool *fpool_dst) +{ + const char remap = + (vpool_dst ? BM_VERT : 0) | + (epool_dst ? BM_EDGE : 0) | + (lpool_dst ? BM_LOOP : 0) | + (fpool_dst ? BM_FACE : 0); + + BMVert **vtable_dst = (remap & BM_VERT) ? MEM_mallocN(bm->totvert * sizeof(BMVert *), __func__) : NULL; + BMEdge **etable_dst = (remap & BM_EDGE) ? MEM_mallocN(bm->totedge * sizeof(BMEdge *), __func__) : NULL; + BMLoop **ltable_dst = (remap & BM_LOOP) ? MEM_mallocN(bm->totloop * sizeof(BMLoop *), __func__) : NULL; + BMFace **ftable_dst = (remap & BM_FACE) ? MEM_mallocN(bm->totface * sizeof(BMFace *), __func__) : NULL; + + const bool use_toolflags = params->use_toolflags; + + if (remap & BM_VERT) { + BMIter iter; + int index; + BMVert *v_src; + BM_ITER_MESH_INDEX (v_src, &iter, bm, BM_VERTS_OF_MESH, index) { + BMVert *v_dst = BLI_mempool_alloc(vpool_dst); + memcpy(v_dst, v_src, sizeof(BMVert)); + if (use_toolflags) { + ((BMVert_OFlag *)v_dst)->oflags = bm->vtoolflagpool ? BLI_mempool_calloc(bm->vtoolflagpool) : NULL; + } + + vtable_dst[index] = v_dst; + BM_elem_index_set(v_src, index); /* set_ok */ + } + } + + if (remap & BM_EDGE) { + BMIter iter; + int index; + BMEdge *e_src; + BM_ITER_MESH_INDEX (e_src, &iter, bm, BM_EDGES_OF_MESH, index) { + BMEdge *e_dst = BLI_mempool_alloc(epool_dst); + memcpy(e_dst, e_src, sizeof(BMEdge)); + if (use_toolflags) { + ((BMEdge_OFlag *)e_dst)->oflags = bm->etoolflagpool ? BLI_mempool_calloc(bm->etoolflagpool) : NULL; + } + + etable_dst[index] = e_dst; + BM_elem_index_set(e_src, index); /* set_ok */ + } + } + + if (remap & (BM_LOOP | BM_FACE)) { + BMIter iter; + int index, index_loop = 0; + BMFace *f_src; + BM_ITER_MESH_INDEX (f_src, &iter, bm, BM_FACES_OF_MESH, index) { + + if (remap & BM_FACE) { + BMFace *f_dst = BLI_mempool_alloc(fpool_dst); + memcpy(f_dst, f_src, sizeof(BMFace)); + if (use_toolflags) { + ((BMFace_OFlag *)f_dst)->oflags = bm->ftoolflagpool ? BLI_mempool_calloc(bm->ftoolflagpool) : NULL; + } + + ftable_dst[index] = f_dst; + BM_elem_index_set(f_src, index); /* set_ok */ + } + + /* handle loops */ + if (remap & BM_LOOP) { + BMLoop *l_iter_src, *l_first_src; + l_iter_src = l_first_src = BM_FACE_FIRST_LOOP((BMFace *)f_src); + do { + BMLoop *l_dst = BLI_mempool_alloc(lpool_dst); + memcpy(l_dst, l_iter_src, sizeof(BMLoop)); + ltable_dst[index_loop] = l_dst; + BM_elem_index_set(l_iter_src, index_loop++); /* set_ok */ + } while ((l_iter_src = l_iter_src->next) != l_first_src); + } + } + } + +#define MAP_VERT(ele) vtable_dst[BM_elem_index_get(ele)] +#define MAP_EDGE(ele) etable_dst[BM_elem_index_get(ele)] +#define MAP_LOOP(ele) ltable_dst[BM_elem_index_get(ele)] +#define MAP_FACE(ele) ftable_dst[BM_elem_index_get(ele)] + +#define REMAP_VERT(ele) { if (remap & BM_VERT) { ele = MAP_VERT(ele); }} ((void)0) +#define REMAP_EDGE(ele) { if (remap & BM_EDGE) { ele = MAP_EDGE(ele); }} ((void)0) +#define REMAP_LOOP(ele) { if (remap & BM_LOOP) { ele = MAP_LOOP(ele); }} ((void)0) +#define REMAP_FACE(ele) { if (remap & BM_FACE) { ele = MAP_FACE(ele); }} ((void)0) + + /* verts */ + { + for (int i = 0; i < bm->totvert; i++) { + BMVert *v = vtable_dst[i]; + if (v->e) { + REMAP_EDGE(v->e); + } + } + } + + /* edges */ + { + for (int i = 0; i < bm->totedge; i++) { + BMEdge *e = etable_dst[i]; + REMAP_VERT(e->v1); + REMAP_VERT(e->v2); + REMAP_EDGE(e->v1_disk_link.next); + REMAP_EDGE(e->v1_disk_link.prev); + REMAP_EDGE(e->v2_disk_link.next); + REMAP_EDGE(e->v2_disk_link.prev); + if (e->l) { + REMAP_LOOP(e->l); + } + } + } + + /* faces */ + { + for (int i = 0; i < bm->totface; i++) { + BMFace *f = ftable_dst[i]; + REMAP_LOOP(f->l_first); + + { + BMLoop *l_iter, *l_first; + l_iter = l_first = BM_FACE_FIRST_LOOP((BMFace *)f); + do { + REMAP_VERT(l_iter->v); + REMAP_EDGE(l_iter->e); + REMAP_FACE(l_iter->f); + + REMAP_LOOP(l_iter->radial_next); + REMAP_LOOP(l_iter->radial_prev); + REMAP_LOOP(l_iter->next); + REMAP_LOOP(l_iter->prev); + } while ((l_iter = l_iter->next) != l_first); + } + } + } + + for (BMEditSelection *ese = bm->selected.first; ese; ese = ese->next) { + switch (ese->htype) { + case BM_VERT: + if (remap & BM_VERT) { + ese->ele = (BMElem *)MAP_VERT(ese->ele); + } + break; + case BM_EDGE: + if (remap & BM_EDGE) { + ese->ele = (BMElem *)MAP_EDGE(ese->ele); + } + break; + case BM_FACE: + if (remap & BM_FACE) { + ese->ele = (BMElem *)MAP_FACE(ese->ele); + } + break; + } + } + + if (bm->act_face) { + REMAP_FACE(bm->act_face); + } + +#undef MAP_VERT +#undef MAP_EDGE +#undef MAP_LOOP +#undef MAP_EDGE + +#undef REMAP_VERT +#undef REMAP_EDGE +#undef REMAP_LOOP +#undef REMAP_EDGE + + /* Cleanup, re-use local tables if the current mesh had tables allocated. + * could use irrespective but it may use more memory then the caller wants (and not be needed). */ + if (remap & BM_VERT) { + if (bm->vtable) { + SWAP(BMVert **, vtable_dst, bm->vtable); + bm->vtable_tot = bm->totvert; + bm->elem_table_dirty &= ~BM_VERT; + } + MEM_freeN(vtable_dst); + BLI_mempool_destroy(bm->vpool); + bm->vpool = vpool_dst; + } + + if (remap & BM_EDGE) { + if (bm->etable) { + SWAP(BMEdge **, etable_dst, bm->etable); + bm->etable_tot = bm->totedge; + bm->elem_table_dirty &= ~BM_EDGE; + } + MEM_freeN(etable_dst); + BLI_mempool_destroy(bm->epool); + bm->epool = epool_dst; + } + + if (remap & BM_LOOP) { + /* no loop table */ + MEM_freeN(ltable_dst); + BLI_mempool_destroy(bm->lpool); + bm->lpool = lpool_dst; + } + + if (remap & BM_FACE) { + if (bm->ftable) { + SWAP(BMFace **, ftable_dst, bm->ftable); + bm->ftable_tot = bm->totface; + bm->elem_table_dirty &= ~BM_FACE; + } + MEM_freeN(ftable_dst); + BLI_mempool_destroy(bm->fpool); + bm->fpool = fpool_dst; + } +} + +/** + * Re-allocatges mesh data with/without toolflags. + */ +void BM_mesh_toolflags_set(BMesh *bm, bool use_toolflags) +{ + if (bm->use_toolflags == use_toolflags) { + return; + } + + const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_BM(bm); + + BLI_mempool *vpool_dst = NULL; + BLI_mempool *epool_dst = NULL; + BLI_mempool *fpool_dst = NULL; + + bm_mempool_init_ex( + &allocsize, use_toolflags, + &vpool_dst, &epool_dst, NULL, &fpool_dst); + + if (use_toolflags == false) { + BLI_mempool_destroy(bm->vtoolflagpool); + BLI_mempool_destroy(bm->etoolflagpool); + BLI_mempool_destroy(bm->ftoolflagpool); + + bm->vtoolflagpool = NULL; + bm->etoolflagpool = NULL; + bm->ftoolflagpool = NULL; + } + + BM_mesh_rebuild( + bm, + &((struct BMeshCreateParams){.use_toolflags = use_toolflags,}), + vpool_dst, epool_dst, NULL, fpool_dst); + + bm->use_toolflags = use_toolflags; +}
\ No newline at end of file diff --git a/source/blender/bmesh/intern/bmesh_mesh.h b/source/blender/bmesh/intern/bmesh_mesh.h index b9cdc4ccf66..6a9540c3b60 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.h +++ b/source/blender/bmesh/intern/bmesh_mesh.h @@ -32,7 +32,14 @@ struct MLoopNorSpaceArray; void BM_mesh_elem_toolflags_ensure(BMesh *bm); void BM_mesh_elem_toolflags_clear(BMesh *bm); -BMesh *BM_mesh_create(const struct BMAllocTemplate *allocsize); + +struct BMeshCreateParams { + unsigned int use_toolflags : 1; +}; + +BMesh *BM_mesh_create( + const struct BMAllocTemplate *allocsize, + const struct BMeshCreateParams *params); void BM_mesh_free(BMesh *bm); void BM_mesh_data_free(BMesh *bm); @@ -53,6 +60,8 @@ void BM_mesh_elem_index_validate( BMesh *bm, const char *location, const char *func, const char *msg_a, const char *msg_b); +void BM_mesh_toolflags_set(BMesh *bm, bool use_toolflags); + #ifndef NDEBUG bool BM_mesh_elem_table_check(BMesh *bm); #endif @@ -83,6 +92,10 @@ void BM_mesh_remap( const unsigned int *edge_idx, const unsigned int *face_idx); +void BM_mesh_rebuild( + BMesh *bm, const struct BMeshCreateParams *params, + struct BLI_mempool *vpool, struct BLI_mempool *epool, struct BLI_mempool *lpool, struct BLI_mempool *fpool); + typedef struct BMAllocTemplate { int totvert, totedge, totloop, totface; } BMAllocTemplate; @@ -113,10 +126,4 @@ extern const BMAllocTemplate bm_mesh_chunksize_default; #define BMALLOC_TEMPLATE_FROM_DM(...) VA_NARGS_CALL_OVERLOAD(_VA_BMALLOC_TEMPLATE_FROM_DM_, __VA_ARGS__) - - -enum { - BM_MESH_CREATE_USE_TOOLFLAGS = (1 << 0) -}; - #endif /* __BMESH_MESH_H__ */ diff --git a/source/blender/bmesh/intern/bmesh_operator_api.h b/source/blender/bmesh/intern/bmesh_operator_api.h index cf93fe0935e..30cd1df9c4e 100644 --- a/source/blender/bmesh/intern/bmesh_operator_api.h +++ b/source/blender/bmesh/intern/bmesh_operator_api.h @@ -75,15 +75,74 @@ extern "C" { struct GHashIterator; -#define BMO_elem_flag_test( bm, ele, oflag) _bmo_elem_flag_test (bm, (ele)->oflags, oflag) -#define BMO_elem_flag_test_bool(bm, ele, oflag) _bmo_elem_flag_test_bool(bm, (ele)->oflags, oflag) -#define BMO_elem_flag_enable( bm, ele, oflag) _bmo_elem_flag_enable (bm, (ele)->oflags, oflag) -#define BMO_elem_flag_disable( bm, ele, oflag) _bmo_elem_flag_disable (bm, (ele)->oflags, oflag) -#define BMO_elem_flag_set( bm, ele, oflag, val) _bmo_elem_flag_set (bm, (ele)->oflags, oflag, val) -#define BMO_elem_flag_toggle( bm, ele, oflag) _bmo_elem_flag_toggle (bm, (ele)->oflags, oflag) - -BLI_INLINE short _bmo_elem_flag_test( BMesh *bm, BMFlagLayer *oflags, const short oflag); -BLI_INLINE bool _bmo_elem_flag_test_bool(BMesh *bm, BMFlagLayer *oflags, const short oflag); +BLI_INLINE BMFlagLayer *BMO_elem_flag_from_header(BMHeader *ele_head) +{ + switch (ele_head->htype) { + case BM_VERT: return ((BMVert_OFlag *)ele_head)->oflags; + case BM_EDGE: return ((BMEdge_OFlag *)ele_head)->oflags; + default: return ((BMFace_OFlag *)ele_head)->oflags; + } +} + +#define BMO_elem_flag_test(bm, ele, oflag) \ + _bmo_elem_flag_test(bm, BMO_elem_flag_from_header(&(ele)->head), oflag) +#define BMO_elem_flag_test_bool(bm, ele, oflag) \ + _bmo_elem_flag_test_bool(bm, BMO_elem_flag_from_header(&(ele)->head), oflag) +#define BMO_elem_flag_enable(bm, ele, oflag) \ + _bmo_elem_flag_enable(bm, (BM_CHECK_TYPE_ELEM_NONCONST(ele), BMO_elem_flag_from_header(&(ele)->head)), oflag) +#define BMO_elem_flag_disable(bm, ele, oflag) \ + _bmo_elem_flag_disable(bm, (BM_CHECK_TYPE_ELEM_NONCONST(ele), BMO_elem_flag_from_header(&(ele)->head)), oflag) +#define BMO_elem_flag_set(bm, ele, oflag, val) \ + _bmo_elem_flag_set(bm, (BM_CHECK_TYPE_ELEM_NONCONST(ele), BMO_elem_flag_from_header(&(ele)->head)), oflag, val) +#define BMO_elem_flag_toggle(bm, ele, oflag) \ + _bmo_elem_flag_toggle(bm, (BM_CHECK_TYPE_ELEM_NONCONST(ele), BMO_elem_flag_from_header(&(ele)->head)), oflag) + +/* take care not to instansiate args multiple times */ +#ifdef __GNUC___ +#define _BMO_CAST_V_CONST(e) ({ typeof(e) _e = e; \ + (BM_CHECK_TYPE_VERT(_e), BLI_assert(((const BMHeader *)_e)->htype == BM_VERT), (const BMVert_OFlag *)_e); }) +#define _BMO_CAST_E_CONST(e) ({ typeof(e) _e = e; \ + (BM_CHECK_TYPE_EDGE(_e), BLI_assert(((const BMHeader *)_e)->htype == BM_EDGE), (const BMEdge_OFlag *)_e); }) +#define _BMO_CAST_F_CONST(e) ({ typeof(e) _e = e; \ + (BM_CHECK_TYPE_FACE(_e), BLI_assert(((const BMHeader *)_e)->htype == BM_FACE), (const BMFace_OFlag *)_e); }) +#define _BMO_CAST_V(e) ({ typeof(e) _e = e; \ + (BM_CHECK_TYPE_VERT_NONCONST(_e), BLI_assert(((BMHeader *)_e)->htype == BM_VERT), (BMVert_OFlag *)_e); }) +#define _BMO_CAST_E(e) ({ typeof(e) _e = e; \ + (BM_CHECK_TYPE_EDGE_NONCONST(_e), BLI_assert(((BMHeader *)_e)->htype == BM_EDGE), (BMEdge_OFlag *)_e); }) +#define _BMO_CAST_F(e) ({ typeof(e) _e = e; \ + (BM_CHECK_TYPE_FACE_NONCONST(_e), BLI_assert(((BMHeader *)_e)->htype == BM_FACE), (BMFace_OFlag *)_e); }) +#else +#define _BMO_CAST_V_CONST(e) (BM_CHECK_TYPE_VERT(e), (const BMVert_OFlag *)e) +#define _BMO_CAST_E_CONST(e) (BM_CHECK_TYPE_EDGE(e), (const BMEdge_OFlag *)e) +#define _BMO_CAST_F_CONST(e) (BM_CHECK_TYPE_FACE(e), (const BMFace_OFlag *)e) +#define _BMO_CAST_V(e) (BM_CHECK_TYPE_VERT_NONCONST(e), (BMVert_OFlag *)e) +#define _BMO_CAST_E(e) (BM_CHECK_TYPE_EDGE_NONCONST(e), (BMEdge_OFlag *)e) +#define _BMO_CAST_F(e) (BM_CHECK_TYPE_FACE_NONCONST(e), (BMFace_OFlag *)e) +#endif + +#define BMO_vert_flag_test( bm, e, oflag) _bmo_elem_flag_test (bm, _BMO_CAST_V_CONST(e)->oflags, oflag) +#define BMO_vert_flag_test_bool(bm, e, oflag) _bmo_elem_flag_test_bool(bm, _BMO_CAST_V_CONST(e)->oflags, oflag) +#define BMO_vert_flag_enable( bm, e, oflag) _bmo_elem_flag_enable (bm, _BMO_CAST_V(e)->oflags, oflag) +#define BMO_vert_flag_disable( bm, e, oflag) _bmo_elem_flag_disable (bm, _BMO_CAST_V(e)->oflags, oflag) +#define BMO_vert_flag_set( bm, e, oflag, val) _bmo_elem_flag_set (bm, _BMO_CAST_V(e)->oflags, oflag, val) +#define BMO_vert_flag_toggle( bm, e, oflag) _bmo_elem_flag_toggle (bm, _BMO_CAST_V(e)->oflags, oflag) + +#define BMO_edge_flag_test( bm, e, oflag) _bmo_elem_flag_test (bm, _BMO_CAST_E_CONST(e)->oflags, oflag) +#define BMO_edge_flag_test_bool(bm, e, oflag) _bmo_elem_flag_test_bool(bm, _BMO_CAST_E_CONST(e)->oflags, oflag) +#define BMO_edge_flag_enable( bm, e, oflag) _bmo_elem_flag_enable (bm, _BMO_CAST_E(e)->oflags, oflag) +#define BMO_edge_flag_disable( bm, e, oflag) _bmo_elem_flag_disable (bm, _BMO_CAST_E(e)->oflags, oflag) +#define BMO_edge_flag_set( bm, e, oflag, val) _bmo_elem_flag_set (bm, _BMO_CAST_E(e)->oflags, oflag, val) +#define BMO_edge_flag_toggle( bm, e, oflag) _bmo_elem_flag_toggle (bm, _BMO_CAST_E(e)->oflags, oflag) + +#define BMO_face_flag_test( bm, e, oflag) _bmo_elem_flag_test (bm, _BMO_CAST_F_CONST(e)->oflags, oflag) +#define BMO_face_flag_test_bool(bm, e, oflag) _bmo_elem_flag_test_bool(bm, _BMO_CAST_F_CONST(e)->oflags, oflag) +#define BMO_face_flag_enable( bm, e, oflag) _bmo_elem_flag_enable (bm, _BMO_CAST_F(e)->oflags, oflag) +#define BMO_face_flag_disable( bm, e, oflag) _bmo_elem_flag_disable (bm, _BMO_CAST_F(e)->oflags, oflag) +#define BMO_face_flag_set( bm, e, oflag, val) _bmo_elem_flag_set (bm, _BMO_CAST_F(e)->oflags, oflag, val) +#define BMO_face_flag_toggle( bm, e, oflag) _bmo_elem_flag_toggle (bm, _BMO_CAST_F(e)->oflags, oflag) + +BLI_INLINE short _bmo_elem_flag_test( BMesh *bm, const BMFlagLayer *oflags, const short oflag); +BLI_INLINE bool _bmo_elem_flag_test_bool(BMesh *bm, const BMFlagLayer *oflags, const short oflag); BLI_INLINE void _bmo_elem_flag_enable( BMesh *bm, BMFlagLayer *oflags, const short oflag); BLI_INLINE void _bmo_elem_flag_disable( BMesh *bm, BMFlagLayer *oflags, const short oflag); BLI_INLINE void _bmo_elem_flag_set( BMesh *bm, BMFlagLayer *oflags, const short oflag, int val); diff --git a/source/blender/bmesh/intern/bmesh_operator_api_inline.h b/source/blender/bmesh/intern/bmesh_operator_api_inline.h index 00fcd9e7a9b..eb1c161f19d 100644 --- a/source/blender/bmesh/intern/bmesh_operator_api_inline.h +++ b/source/blender/bmesh/intern/bmesh_operator_api_inline.h @@ -39,32 +39,37 @@ /* flags 15 and 16 (1 << 14 and 1 << 15) are reserved for bmesh api use */ ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2) -BLI_INLINE short _bmo_elem_flag_test(BMesh *bm, BMFlagLayer *oflags, const short oflag) +BLI_INLINE short _bmo_elem_flag_test(BMesh *bm, const BMFlagLayer *oflags, const short oflag) { + BLI_assert(bm->use_toolflags); return oflags[bm->toolflag_index].f & oflag; } ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2) -BLI_INLINE bool _bmo_elem_flag_test_bool(BMesh *bm, BMFlagLayer *oflags, const short oflag) +BLI_INLINE bool _bmo_elem_flag_test_bool(BMesh *bm, const BMFlagLayer *oflags, const short oflag) { + BLI_assert(bm->use_toolflags); return (oflags[bm->toolflag_index].f & oflag) != 0; } ATTR_NONNULL(1, 2) BLI_INLINE void _bmo_elem_flag_enable(BMesh *bm, BMFlagLayer *oflags, const short oflag) { + BLI_assert(bm->use_toolflags); oflags[bm->toolflag_index].f |= oflag; } ATTR_NONNULL(1, 2) BLI_INLINE void _bmo_elem_flag_disable(BMesh *bm, BMFlagLayer *oflags, const short oflag) { + BLI_assert(bm->use_toolflags); oflags[bm->toolflag_index].f &= (short)~oflag; } ATTR_NONNULL(1, 2) BLI_INLINE void _bmo_elem_flag_set(BMesh *bm, BMFlagLayer *oflags, const short oflag, int val) { + BLI_assert(bm->use_toolflags); if (val) oflags[bm->toolflag_index].f |= oflag; else oflags[bm->toolflag_index].f &= (short)~oflag; } @@ -72,6 +77,7 @@ BLI_INLINE void _bmo_elem_flag_set(BMesh *bm, BMFlagLayer *oflags, const short o ATTR_NONNULL(1, 2) BLI_INLINE void _bmo_elem_flag_toggle(BMesh *bm, BMFlagLayer *oflags, const short oflag) { + BLI_assert(bm->use_toolflags); oflags[bm->toolflag_index].f ^= oflag; } diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c index 960ff568e93..706a7f74ed2 100644 --- a/source/blender/bmesh/intern/bmesh_operators.c +++ b/source/blender/bmesh/intern/bmesh_operators.c @@ -548,27 +548,44 @@ static int bmo_mesh_flag_count( BMesh *bm, const char htype, const short oflag, const bool test_for_enabled) { - const char iter_types[3] = {BM_VERTS_OF_MESH, - BM_EDGES_OF_MESH, - BM_FACES_OF_MESH}; + int count_vert = 0, count_edge = 0, count_face = 0; - const char flag_types[3] = {BM_VERT, BM_EDGE, BM_FACE}; - - BMIter iter; - int count = 0; - BMElemF *ele_f; - int i; - - for (i = 0; i < 3; i++) { - if (htype & flag_types[i]) { - BM_ITER_MESH (ele_f, &iter, bm, iter_types[i]) { - if (BMO_elem_flag_test_bool(bm, ele_f, oflag) == test_for_enabled) - count++; +#pragma omp parallel sections if ((bm->totvert + bm->totedge + bm->totface >= BM_OMP_LIMIT) && \ + (ELEM(htype, BM_VERT, BM_EDGE, BM_FACE) == 0)) + { +#pragma omp section + if (htype & BM_VERT) { + BMIter iter; + BMVert *ele; + BM_ITER_MESH (ele, &iter, bm, BM_VERTS_OF_MESH) { + if (BMO_vert_flag_test_bool(bm, ele, oflag) == test_for_enabled) { + count_vert++; + } + } + } +#pragma omp section + if (htype & BM_EDGE) { + BMIter iter; + BMEdge *ele; + BM_ITER_MESH (ele, &iter, bm, BM_EDGES_OF_MESH) { + if (BMO_edge_flag_test_bool(bm, ele, oflag) == test_for_enabled) { + count_edge++; + } + } + } +#pragma omp section + if (htype & BM_FACE) { + BMIter iter; + BMFace *ele; + BM_ITER_MESH (ele, &iter, bm, BM_FACES_OF_MESH) { + if (BMO_face_flag_test_bool(bm, ele, oflag) == test_for_enabled) { + count_face++; + } } } } - return count; + return (count_vert + count_edge + count_face); } @@ -584,21 +601,32 @@ int BMO_mesh_disabled_flag_count(BMesh *bm, const char htype, const short oflag) void BMO_mesh_flag_disable_all(BMesh *bm, BMOperator *UNUSED(op), const char htype, const short oflag) { - const char iter_types[3] = {BM_VERTS_OF_MESH, - BM_EDGES_OF_MESH, - BM_FACES_OF_MESH}; - - const char flag_types[3] = {BM_VERT, BM_EDGE, BM_FACE}; - BMElemF *ele; - int i; - -#pragma omp parallel for schedule(static) if (bm->totvert + bm->totedge + bm->totface >= BM_OMP_LIMIT) - for (i = 0; i < 3; i++) { - if (htype & flag_types[i]) { +#pragma omp parallel sections if ((bm->totvert + bm->totedge + bm->totface >= BM_OMP_LIMIT) && \ + (ELEM(htype, BM_VERT, BM_EDGE, BM_FACE) == 0)) + { +#pragma omp section + if (htype & BM_VERT) { BMIter iter; - BM_ITER_MESH (ele, &iter, bm, iter_types[i]) { - BMO_elem_flag_disable(bm, ele, oflag); + BMVert *ele; + BM_ITER_MESH (ele, &iter, bm, BM_VERTS_OF_MESH) { + BMO_vert_flag_disable(bm, ele, oflag); + } + } +#pragma omp section + if (htype & BM_EDGE) { + BMIter iter; + BMEdge *ele; + BM_ITER_MESH (ele, &iter, bm, BM_EDGES_OF_MESH) { + BMO_edge_flag_disable(bm, ele, oflag); + } + } +#pragma omp section + if (htype & BM_FACE) { + BMIter iter; + BMFace *ele; + BM_ITER_MESH (ele, &iter, bm, BM_FACES_OF_MESH) { + BMO_face_flag_disable(bm, ele, oflag); } } } @@ -1007,7 +1035,7 @@ static void bmo_slot_buffer_from_flag( if (htype & BM_VERT) { BM_ITER_MESH (ele, &iter, bm, BM_VERTS_OF_MESH) { - if (BMO_elem_flag_test_bool(bm, (BMElemF *)ele, oflag) == test_for_enabled) { + if (BMO_vert_flag_test_bool(bm, (BMVert *)ele, oflag) == test_for_enabled) { ele_array[i] = ele; i++; } @@ -1016,7 +1044,7 @@ static void bmo_slot_buffer_from_flag( if (htype & BM_EDGE) { BM_ITER_MESH (ele, &iter, bm, BM_EDGES_OF_MESH) { - if (BMO_elem_flag_test_bool(bm, (BMElemF *)ele, oflag) == test_for_enabled) { + if (BMO_edge_flag_test_bool(bm, (BMEdge *)ele, oflag) == test_for_enabled) { ele_array[i] = ele; i++; } @@ -1025,7 +1053,7 @@ static void bmo_slot_buffer_from_flag( if (htype & BM_FACE) { BM_ITER_MESH (ele, &iter, bm, BM_FACES_OF_MESH) { - if (BMO_elem_flag_test_bool(bm, (BMElemF *)ele, oflag) == test_for_enabled) { + if (BMO_face_flag_test_bool(bm, (BMFace *)ele, oflag) == test_for_enabled) { ele_array[i] = ele; i++; } @@ -1213,7 +1241,7 @@ static void bmo_flag_layer_alloc(BMesh *bm) #pragma omp section { BMIter iter; - BMElemF *ele; + BMVert_OFlag *ele; int i; BLI_mempool *newpool = bm->vtoolflagpool; @@ -1223,14 +1251,14 @@ static void bmo_flag_layer_alloc(BMesh *bm) void *oldflags = ele->oflags; ele->oflags = BLI_mempool_calloc(newpool); memcpy(ele->oflags, oldflags, old_totflags_size); - BM_elem_index_set(ele, i); /* set_inline */ + BM_elem_index_set(&ele->base, i); /* set_inline */ BM_ELEM_API_FLAG_CLEAR((BMElemF *)ele); } } #pragma omp section { BMIter iter; - BMElemF *ele; + BMEdge_OFlag *ele; int i; BLI_mempool *newpool = bm->etoolflagpool; @@ -1239,14 +1267,14 @@ static void bmo_flag_layer_alloc(BMesh *bm) void *oldflags = ele->oflags; ele->oflags = BLI_mempool_calloc(newpool); memcpy(ele->oflags, oldflags, old_totflags_size); - BM_elem_index_set(ele, i); /* set_inline */ + BM_elem_index_set(&ele->base, i); /* set_inline */ BM_ELEM_API_FLAG_CLEAR((BMElemF *)ele); } } #pragma omp section { BMIter iter; - BMElemF *ele; + BMFace_OFlag *ele; int i; BLI_mempool *newpool = bm->ftoolflagpool; @@ -1255,7 +1283,7 @@ static void bmo_flag_layer_alloc(BMesh *bm) void *oldflags = ele->oflags; ele->oflags = BLI_mempool_calloc(newpool); memcpy(ele->oflags, oldflags, old_totflags_size); - BM_elem_index_set(ele, i); /* set_inline */ + BM_elem_index_set(&ele->base, i); /* set_inline */ BM_ELEM_API_FLAG_CLEAR((BMElemF *)ele); } } @@ -1292,7 +1320,7 @@ static void bmo_flag_layer_free(BMesh *bm) #pragma omp section { BMIter iter; - BMElemF *ele; + BMVert_OFlag *ele; int i; BLI_mempool *newpool = bm->vtoolflagpool; @@ -1302,14 +1330,14 @@ static void bmo_flag_layer_free(BMesh *bm) void *oldflags = ele->oflags; ele->oflags = BLI_mempool_alloc(newpool); memcpy(ele->oflags, oldflags, new_totflags_size); - BM_elem_index_set(ele, i); /* set_inline */ + BM_elem_index_set(&ele->base, i); /* set_inline */ BM_ELEM_API_FLAG_CLEAR((BMElemF *)ele); } } #pragma omp section { BMIter iter; - BMElemF *ele; + BMEdge_OFlag *ele; int i; BLI_mempool *newpool = bm->etoolflagpool; @@ -1318,14 +1346,14 @@ static void bmo_flag_layer_free(BMesh *bm) void *oldflags = ele->oflags; ele->oflags = BLI_mempool_alloc(newpool); memcpy(ele->oflags, oldflags, new_totflags_size); - BM_elem_index_set(ele, i); /* set_inline */ + BM_elem_index_set(&ele->base, i); /* set_inline */ BM_ELEM_API_FLAG_CLEAR((BMElemF *)ele); } } #pragma omp section { BMIter iter; - BMElemF *ele; + BMFace_OFlag *ele; int i; BLI_mempool *newpool = bm->ftoolflagpool; @@ -1334,7 +1362,7 @@ static void bmo_flag_layer_free(BMesh *bm) void *oldflags = ele->oflags; ele->oflags = BLI_mempool_alloc(newpool); memcpy(ele->oflags, oldflags, new_totflags_size); - BM_elem_index_set(ele, i); /* set_inline */ + BM_elem_index_set(&ele->base, i); /* set_inline */ BM_ELEM_API_FLAG_CLEAR((BMElemF *)ele); } } @@ -1361,31 +1389,31 @@ static void bmo_flag_layer_clear(BMesh *bm) #pragma omp section { BMIter iter; - BMElemF *ele; + BMVert_OFlag *ele; int i; BM_ITER_MESH_INDEX (ele, &iter, bm, BM_VERTS_OF_MESH, i) { ele->oflags[totflags_offset] = zero_flag; - BM_elem_index_set(ele, i); /* set_inline */ + BM_elem_index_set(&ele->base, i); /* set_inline */ } } #pragma omp section { BMIter iter; - BMElemF *ele; + BMEdge_OFlag *ele; int i; BM_ITER_MESH_INDEX (ele, &iter, bm, BM_EDGES_OF_MESH, i) { ele->oflags[totflags_offset] = zero_flag; - BM_elem_index_set(ele, i); /* set_inline */ + BM_elem_index_set(&ele->base, i); /* set_inline */ } } #pragma omp section { BMIter iter; - BMElemF *ele; + BMFace_OFlag *ele; int i; BM_ITER_MESH_INDEX (ele, &iter, bm, BM_FACES_OF_MESH, i) { ele->oflags[totflags_offset] = zero_flag; - BM_elem_index_set(ele, i); /* set_inline */ + BM_elem_index_set(&ele->base, i); /* set_inline */ } } } diff --git a/source/blender/bmesh/intern/bmesh_private.h b/source/blender/bmesh/intern/bmesh_private.h index 9b3a147301d..d8d297c9298 100644 --- a/source/blender/bmesh/intern/bmesh_private.h +++ b/source/blender/bmesh/intern/bmesh_private.h @@ -67,12 +67,13 @@ enum { _FLAG_MV = (1 << 1), /* make face, vertex */ _FLAG_OVERLAP = (1 << 2), /* general overlap flag */ _FLAG_WALK = (1 << 3), /* general walk flag (keep clean) */ + _FLAG_WALK_ALT = (1 << 4), /* same as _FLAG_WALK, for when a second tag is needed */ _FLAG_ELEM_CHECK = (1 << 7), /* reserved for bmesh_elem_check */ }; #define BM_ELEM_API_FLAG_ENABLE(element, f) { ((element)->head.api_flag |= (f)); } (void)0 -#define BM_ELEM_API_FLAG_DISABLE(element, f) { ((element)->head.api_flag &= ~(f)); } (void)0 +#define BM_ELEM_API_FLAG_DISABLE(element, f) { ((element)->head.api_flag &= (unsigned char)~(f)); } (void)0 #define BM_ELEM_API_FLAG_TEST(element, f) ((element)->head.api_flag & (f)) #define BM_ELEM_API_FLAG_CLEAR(element) { ((element)->head.api_flag = 0); } (void)0 diff --git a/source/blender/bmesh/intern/bmesh_walkers_impl.c b/source/blender/bmesh/intern/bmesh_walkers_impl.c index 018700c0efa..279440984bb 100644 --- a/source/blender/bmesh/intern/bmesh_walkers_impl.c +++ b/source/blender/bmesh/intern/bmesh_walkers_impl.c @@ -49,7 +49,7 @@ static bool bmw_mask_check_vert(BMWalker *walker, BMVert *v) if ((walker->flag & BMW_FLAG_TEST_HIDDEN) && BM_elem_flag_test(v, BM_ELEM_HIDDEN)) { return false; } - else if (walker->mask_vert && !BMO_elem_flag_test(walker->bm, v, walker->mask_vert)) { + else if (walker->mask_vert && !BMO_vert_flag_test(walker->bm, v, walker->mask_vert)) { return false; } else { @@ -62,7 +62,7 @@ static bool bmw_mask_check_edge(BMWalker *walker, BMEdge *e) if ((walker->flag & BMW_FLAG_TEST_HIDDEN) && BM_elem_flag_test(e, BM_ELEM_HIDDEN)) { return false; } - else if (walker->mask_edge && !BMO_elem_flag_test(walker->bm, e, walker->mask_edge)) { + else if (walker->mask_edge && !BMO_edge_flag_test(walker->bm, e, walker->mask_edge)) { return false; } else { @@ -75,7 +75,7 @@ static bool bmw_mask_check_face(BMWalker *walker, BMFace *f) if ((walker->flag & BMW_FLAG_TEST_HIDDEN) && BM_elem_flag_test(f, BM_ELEM_HIDDEN)) { return false; } - else if (walker->mask_face && !BMO_elem_flag_test(walker->bm, f, walker->mask_face)) { + else if (walker->mask_face && !BMO_face_flag_test(walker->bm, f, walker->mask_face)) { return false; } else { @@ -223,7 +223,7 @@ static void *bmw_VertShellWalker_step(BMWalker *walker) do { if (!BLI_gset_haskey(walker->visit_set, curedge)) { if (!walker->restrictflag || - (walker->restrictflag && BMO_elem_flag_test(walker->bm, curedge, walker->restrictflag))) + (walker->restrictflag && BMO_edge_flag_test(walker->bm, curedge, walker->restrictflag))) { BMwShellWalker *newstate; @@ -748,7 +748,7 @@ static void *bmw_IslandboundWalker_step(BMWalker *walker) iwalk = BMW_state_add(walker); iwalk->base = owalk.base; - //if (!BMO_elem_flag_test(walker->bm, l->f, walker->restrictflag)) + //if (!BMO_face_flag_test(walker->bm, l->f, walker->restrictflag)) // iwalk->curloop = l->radial_next; iwalk->curloop = l; //else iwalk->curloop = l; iwalk->lastv = v; diff --git a/source/blender/bmesh/operators/bmo_beautify.c b/source/blender/bmesh/operators/bmo_beautify.c index 4a292c33472..c68d92ea5e0 100644 --- a/source/blender/bmesh/operators/bmo_beautify.c +++ b/source/blender/bmesh/operators/bmo_beautify.c @@ -52,7 +52,7 @@ void bmo_beautify_fill_exec(BMesh *bm, BMOperator *op) int edge_array_len = 0; BMO_ITER (f, &siter, op->slots_in, "faces", BM_FACE) { if (f->len == 3) { - BMO_elem_flag_enable(bm, f, FACE_MARK); + BMO_face_flag_enable(bm, f, FACE_MARK); } } @@ -68,8 +68,8 @@ void bmo_beautify_fill_exec(BMesh *bm, BMOperator *op) /* edge is manifold and can be rotated */ if (BM_edge_rotate_check(e) && /* faces are tagged */ - BMO_elem_flag_test(bm, e->l->f, FACE_MARK) && - BMO_elem_flag_test(bm, e->l->radial_next->f, FACE_MARK)) + BMO_face_flag_test(bm, e->l->f, FACE_MARK) && + BMO_face_flag_test(bm, e->l->radial_next->f, FACE_MARK)) { edge_array[edge_array_len] = e; edge_array_len++; diff --git a/source/blender/bmesh/operators/bmo_bridge.c b/source/blender/bmesh/operators/bmo_bridge.c index a0149a41921..6ef0fd6b084 100644 --- a/source/blender/bmesh/operators/bmo_bridge.c +++ b/source/blender/bmesh/operators/bmo_bridge.c @@ -131,13 +131,13 @@ static void bm_face_edges_tag_out(BMesh *bm, BMFace *f) BMLoop *l_iter, *l_first; l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { - BMO_elem_flag_enable(bm, l_iter->e, EDGE_OUT); + BMO_edge_flag_enable(bm, l_iter->e, EDGE_OUT); } while ((l_iter = l_iter->next) != l_first); } static bool bm_edge_test_cb(BMEdge *e, void *bm_v) { - return BMO_elem_flag_test((BMesh *)bm_v, e, EDGE_MARK); + return BMO_edge_flag_test((BMesh *)bm_v, e, EDGE_MARK); } static void bridge_loop_pair( @@ -425,7 +425,7 @@ static void bridge_loop_pair( if (f_example && (f_example != f)) { BM_elem_attrs_copy(bm, bm, f_example, f); } - BMO_elem_flag_enable(bm, f, FACE_OUT); + BMO_face_flag_enable(bm, f, FACE_OUT); BM_elem_flag_enable(f, BM_ELEM_TAG); /* tag all edges of the face, untag the loop edges after */ @@ -486,7 +486,7 @@ static void bridge_loop_pair( BMOIter siter; BMFace *f; BMO_ITER (f, &siter, op_sub.slots_in, "faces", BM_FACE) { - BMO_elem_flag_enable(bm, f, FACE_OUT); + BMO_face_flag_enable(bm, f, FACE_OUT); bm_face_edges_tag_out(bm, f); } } @@ -498,7 +498,7 @@ static void bridge_loop_pair( BMOIter siter; BMFace *f; BMO_ITER (f, &siter, op_sub.slots_out, "geom.out", BM_FACE) { - BMO_elem_flag_enable(bm, f, FACE_OUT); + BMO_face_flag_enable(bm, f, FACE_OUT); bm_face_edges_tag_out(bm, f); } } @@ -520,7 +520,7 @@ static void bridge_loop_pair( if (el_next) { if (el->data != el_next->data) { BMEdge *e = BM_edge_exists(el->data, el_next->data); - BMO_elem_flag_disable(bm, e, EDGE_OUT); + BMO_edge_flag_disable(bm, e, EDGE_OUT); } } } diff --git a/source/blender/bmesh/operators/bmo_connect.c b/source/blender/bmesh/operators/bmo_connect.c index 0213329118c..5c9cd8dc3fa 100644 --- a/source/blender/bmesh/operators/bmo_connect.c +++ b/source/blender/bmesh/operators/bmo_connect.c @@ -62,10 +62,10 @@ static int bm_face_connect_verts(BMesh *bm, BMFace *f, const bool check_degenera l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { - if (BMO_elem_flag_test(bm, l_iter->v, VERT_INPUT) && + if (BMO_vert_flag_test(bm, l_iter->v, VERT_INPUT) && /* ensure this vertex isnt part of a contiguous group */ - ((BMO_elem_flag_test(bm, l_iter->prev->v, VERT_INPUT) == 0) || - (BMO_elem_flag_test(bm, l_iter->next->v, VERT_INPUT) == 0))) + ((BMO_vert_flag_test(bm, l_iter->prev->v, VERT_INPUT) == 0) || + (BMO_vert_flag_test(bm, l_iter->next->v, VERT_INPUT) == 0))) { if (!l_tag_prev) { l_tag_prev = l_tag_first = l_iter; @@ -75,7 +75,7 @@ static int bm_face_connect_verts(BMesh *bm, BMFace *f, const bool check_degenera if (!BM_loop_is_adjacent(l_tag_prev, l_iter)) { BMEdge *e; e = BM_edge_exists(l_tag_prev->v, l_iter->v); - if (e == NULL || !BMO_elem_flag_test(bm, e, EDGE_OUT)) { + if (e == NULL || !BMO_edge_flag_test(bm, e, EDGE_OUT)) { BMLoop **l_pair = STACK_PUSH_RET(loops_split); l_pair[0] = l_tag_prev; l_pair[1] = l_iter; @@ -138,8 +138,8 @@ static int bm_face_connect_verts(BMesh *bm, BMFace *f, const bool check_degenera if (!l_new || !f_new) { return -1; } - // BMO_elem_flag_enable(bm, f_new, FACE_NEW); - BMO_elem_flag_enable(bm, l_new->e, EDGE_OUT); + // BMO_face_flag_enable(bm, f_new, FACE_NEW); + BMO_edge_flag_enable(bm, l_new->e, EDGE_OUT); } return 1; @@ -164,12 +164,12 @@ void bmo_connect_verts_exec(BMesh *bm, BMOperator *op) BMIter iter; BMLoop *l_iter; - BMO_elem_flag_enable(bm, v, VERT_INPUT); + BMO_vert_flag_enable(bm, v, VERT_INPUT); BM_ITER_ELEM (l_iter, &iter, v, BM_LOOPS_OF_VERT) { f = l_iter->f; - if (!BMO_elem_flag_test(bm, f, FACE_EXCLUDE)) { - if (!BMO_elem_flag_test(bm, f, FACE_TAG)) { - BMO_elem_flag_enable(bm, f, FACE_TAG); + if (!BMO_face_flag_test(bm, f, FACE_EXCLUDE)) { + if (!BMO_face_flag_test(bm, f, FACE_TAG)) { + BMO_face_flag_enable(bm, f, FACE_TAG); if (f->len > 3) { BLI_LINKSTACK_PUSH(faces, f); } @@ -179,11 +179,11 @@ void bmo_connect_verts_exec(BMesh *bm, BMOperator *op) /* flag edges even if these are not newly created * this way cut-pairs that include co-linear edges will get * predictable output. */ - if (BMO_elem_flag_test(bm, l_iter->prev->v, VERT_INPUT)) { - BMO_elem_flag_enable(bm, l_iter->prev->e, EDGE_OUT_ADJ); + if (BMO_vert_flag_test(bm, l_iter->prev->v, VERT_INPUT)) { + BMO_edge_flag_enable(bm, l_iter->prev->e, EDGE_OUT_ADJ); } - if (BMO_elem_flag_test(bm, l_iter->next->v, VERT_INPUT)) { - BMO_elem_flag_enable(bm, l_iter->e, EDGE_OUT_ADJ); + if (BMO_vert_flag_test(bm, l_iter->next->v, VERT_INPUT)) { + BMO_edge_flag_enable(bm, l_iter->e, EDGE_OUT_ADJ); } } } diff --git a/source/blender/bmesh/operators/bmo_connect_concave.c b/source/blender/bmesh/operators/bmo_connect_concave.c index 8b9c60ada52..9bb67ed9341 100644 --- a/source/blender/bmesh/operators/bmo_connect_concave.c +++ b/source/blender/bmesh/operators/bmo_connect_concave.c @@ -107,10 +107,10 @@ static bool bm_face_split_by_concave( int i; for (i = 0; i < faces_array_tot; i++) { BMFace *f = faces_array[i]; - BMO_elem_flag_enable(bm, f, FACE_OUT); + BMO_face_flag_enable(bm, f, FACE_OUT); } } - BMO_elem_flag_enable(bm, f_base, FACE_OUT); + BMO_face_flag_enable(bm, f_base, FACE_OUT); if (edges_array_tot) { int i; @@ -120,7 +120,7 @@ static bool bm_face_split_by_concave( for (i = 0; i < edges_array_tot; i++) { BMLoop *l_pair[2]; BMEdge *e = edges_array[i]; - BMO_elem_flag_enable(bm, e, EDGE_OUT); + BMO_edge_flag_enable(bm, e, EDGE_OUT); if (BM_edge_is_contiguous(e) && BM_edge_loop_pair(e, &l_pair[0], &l_pair[1])) @@ -153,7 +153,7 @@ static bool bm_face_split_by_concave( BMFace *f_new, *f_pair[2] = {l_pair[0]->f, l_pair[1]->f}; f_new = BM_faces_join(bm, f_pair, 2, true); if (f_new) { - BMO_elem_flag_enable(bm, f_new, FACE_OUT); + BMO_face_flag_enable(bm, f_new, FACE_OUT); } } } diff --git a/source/blender/bmesh/operators/bmo_connect_nonplanar.c b/source/blender/bmesh/operators/bmo_connect_nonplanar.c index c80fb95c44a..9b3e1d38feb 100644 --- a/source/blender/bmesh/operators/bmo_connect_nonplanar.c +++ b/source/blender/bmesh/operators/bmo_connect_nonplanar.c @@ -136,9 +136,9 @@ static bool bm_face_split_by_angle(BMesh *bm, BMFace *f, BMFace *r_f_pair[2], co r_f_pair[0] = f; r_f_pair[1] = f_new; - BMO_elem_flag_enable(bm, f, FACE_OUT); - BMO_elem_flag_enable(bm, f_new, FACE_OUT); - BMO_elem_flag_enable(bm, l_new->e, EDGE_OUT); + BMO_face_flag_enable(bm, f, FACE_OUT); + BMO_face_flag_enable(bm, f_new, FACE_OUT); + BMO_edge_flag_enable(bm, l_new->e, EDGE_OUT); return true; } } diff --git a/source/blender/bmesh/operators/bmo_connect_pair.c b/source/blender/bmesh/operators/bmo_connect_pair.c index 3b860778e1c..3eb6fe0cb97 100644 --- a/source/blender/bmesh/operators/bmo_connect_pair.c +++ b/source/blender/bmesh/operators/bmo_connect_pair.c @@ -67,18 +67,29 @@ #define ELE_TOUCHED 4 #define FACE_WALK_TEST(f) (CHECK_TYPE_INLINE(f, BMFace *), \ - BMO_elem_flag_test(pc->bm_bmoflag, f, FACE_EXCLUDE) == 0) + BMO_face_flag_test(pc->bm_bmoflag, f, FACE_EXCLUDE) == 0) #define VERT_WALK_TEST(v) (CHECK_TYPE_INLINE(v, BMVert *), \ - BMO_elem_flag_test(pc->bm_bmoflag, v, VERT_EXCLUDE) == 0) + BMO_vert_flag_test(pc->bm_bmoflag, v, VERT_EXCLUDE) == 0) +#if 0 #define ELE_TOUCH_TEST(e) \ (CHECK_TYPE_ANY(e, BMVert *, BMEdge *, BMElem *, BMElemF *), \ BMO_elem_flag_test(pc->bm_bmoflag, (BMElemF *)e, ELE_TOUCHED)) +#endif #define ELE_TOUCH_MARK(e) \ { CHECK_TYPE_ANY(e, BMVert *, BMEdge *, BMElem *, BMElemF *); \ BMO_elem_flag_enable(pc->bm_bmoflag, (BMElemF *)e, ELE_TOUCHED); } ((void)0) +#define ELE_TOUCH_TEST_VERT(v) BMO_vert_flag_test(pc->bm_bmoflag, v, ELE_TOUCHED) +// #define ELE_TOUCH_MARK_VERT(v) BMO_vert_flag_enable(pc->bm_bmoflag, (BMElemF *)e, ELE_TOUCHED) + +// #define ELE_TOUCH_TEST_EDGE(v) BMO_edge_flag_test(pc->bm_bmoflag, v, ELE_TOUCHED) +// #define ELE_TOUCH_MARK_EDGE(v) BMO_edge_flag_enable(pc->bm_bmoflag, (BMElemF *)e, ELE_TOUCHED) + +// #define ELE_TOUCH_TEST_FACE(v) BMO_face_flag_test(pc->bm_bmoflag, v, ELE_TOUCHED) +// #define ELE_TOUCH_MARK_FACE(v) BMO_face_flag_enable(pc->bm_bmoflag, (BMElemF *)e, ELE_TOUCHED) + // #define DEBUG_PRINT typedef struct PathContext { @@ -352,7 +363,7 @@ static PathLinkState *state_step__face_edges( BMElem *ele_next_from = (BMElem *)l_iter->f; if (FACE_WALK_TEST((BMFace *)ele_next_from) && - (ELE_TOUCH_TEST(ele_next) == false)) + (ELE_TOUCH_TEST_VERT((BMVert *)ele_next) == false)) { min_dist_dir_update(mddir, dist_dir); mddir->dist_min[index] = dist_test; @@ -397,7 +408,7 @@ static PathLinkState *state_step__face_verts( BMElem *ele_next_from = (BMElem *)l_iter->f; if (FACE_WALK_TEST((BMFace *)ele_next_from) && - (ELE_TOUCH_TEST(ele_next) == false)) + (ELE_TOUCH_TEST_VERT((BMVert *)ele_next) == false)) { min_dist_dir_update(mddir, dist_dir); mddir->dist_min[index] = dist_test; @@ -480,7 +491,7 @@ static bool state_step(PathContext *pc, PathLinkState *state) if (state_isect_co_exact(pc, v_other->co)) { BMElem *ele_next = (BMElem *)v_other; BMElem *ele_next_from = (BMElem *)e; - if (ELE_TOUCH_TEST(ele_next) == false) { + if (ELE_TOUCH_TEST_VERT((BMVert *)ele_next) == false) { state = state_link_add_test(pc, state, &state_orig, ele_next, ele_next_from); } } @@ -703,11 +714,11 @@ void bmo_connect_vert_pair_exec(BMesh *bm, BMOperator *op) BMVert *v_new; float e_fac = state_calc_co_pair_fac(&pc, e->v1->co, e->v2->co); v_new = BM_edge_split(bm, e, e->v1, NULL, e_fac); - BMO_elem_flag_enable(bm, v_new, VERT_OUT); + BMO_vert_flag_enable(bm, v_new, VERT_OUT); } else if (link->ele->head.htype == BM_VERT) { BMVert *v = (BMVert *)link->ele; - BMO_elem_flag_enable(bm, v, VERT_OUT); + BMO_vert_flag_enable(bm, v, VERT_OUT); } else { BLI_assert(0); @@ -715,8 +726,8 @@ void bmo_connect_vert_pair_exec(BMesh *bm, BMOperator *op) } while ((link = link->next)); } - BMO_elem_flag_enable(bm, pc.v_a, VERT_OUT); - BMO_elem_flag_enable(bm, pc.v_b, VERT_OUT); + BMO_vert_flag_enable(bm, pc.v_a, VERT_OUT); + BMO_vert_flag_enable(bm, pc.v_b, VERT_OUT); BLI_mempool_destroy(pc.link_pool); diff --git a/source/blender/bmesh/operators/bmo_create.c b/source/blender/bmesh/operators/bmo_create.c index a1e20dab63e..7b8cb36ab59 100644 --- a/source/blender/bmesh/operators/bmo_create.c +++ b/source/blender/bmesh/operators/bmo_create.c @@ -52,12 +52,19 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op) /* count number of each element type we were passe */ BMO_ITER (h, &oiter, op->slots_in, "geom", BM_VERT | BM_EDGE | BM_FACE) { switch (h->htype) { - case BM_VERT: totv++; break; - case BM_EDGE: tote++; break; - case BM_FACE: totf++; break; + case BM_VERT: + BMO_vert_flag_enable(bm, (BMVert *)h, ELE_NEW); + totv++; + break; + case BM_EDGE: + BMO_edge_flag_enable(bm, (BMEdge *)h, ELE_NEW); + tote++; + break; + case BM_FACE: + BMO_face_flag_enable(bm, (BMFace *)h, ELE_NEW); + totf++; + break; } - - BMO_elem_flag_enable(bm, (BMElemF *)h, ELE_NEW); } /* --- Support Edge Creation --- @@ -71,7 +78,7 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op) /* create edge */ e = BM_edge_create(bm, verts[0], verts[1], NULL, BM_CREATE_NO_DOUBLE); - BMO_elem_flag_enable(bm, e, ELE_OUT); + BMO_edge_flag_enable(bm, e, ELE_OUT); tote += 1; BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "edges.out", BM_EDGE, ELE_OUT); return; @@ -131,10 +138,10 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op) BMEdge *e; e = BM_edge_create(bm, v_free, v_a, NULL, BM_CREATE_NO_DOUBLE); - BMO_elem_flag_enable(bm, e, ELE_NEW); + BMO_edge_flag_enable(bm, e, ELE_NEW); e = BM_edge_create(bm, v_free, v_b, NULL, BM_CREATE_NO_DOUBLE); - BMO_elem_flag_enable(bm, e, ELE_NEW); + BMO_edge_flag_enable(bm, e, ELE_NEW); tote += 2; } } @@ -236,7 +243,7 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op) for (ese = bm->selected.first; ese; ese = ese->next) { if (ese->htype == BM_VERT) { - if (BMO_elem_flag_test(bm, (BMElemF *)ese->ele, ELE_NEW)) { + if (BMO_vert_flag_test(bm, (BMVert *)ese->ele, ELE_NEW)) { tot_ese_v++; } else { @@ -256,7 +263,7 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op) BMVert *v = (BMVert *)ese->ele; if (v_prev) { BMEdge *e = BM_edge_create(bm, v, v_prev, NULL, BM_CREATE_NO_DOUBLE); - BMO_elem_flag_enable(bm, e, ELE_OUT); + BMO_edge_flag_enable(bm, e, ELE_OUT); } v_prev = v; } @@ -286,7 +293,7 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op) f = BM_face_create_ngon_vcloud(bm, vert_arr, totv, NULL, BM_CREATE_NO_DOUBLE); if (f) { - BMO_elem_flag_enable(bm, f, ELE_OUT); + BMO_face_flag_enable(bm, f, ELE_OUT); f->mat_nr = mat_nr; if (use_smooth) { BM_elem_flag_enable(f, BM_ELEM_SMOOTH); diff --git a/source/blender/bmesh/operators/bmo_dissolve.c b/source/blender/bmesh/operators/bmo_dissolve.c index 86062ff0b66..05efb14a699 100644 --- a/source/blender/bmesh/operators/bmo_dissolve.c +++ b/source/blender/bmesh/operators/bmo_dissolve.c @@ -74,10 +74,10 @@ static bool UNUSED_FUNCTION(check_hole_in_region) (BMesh *bm, BMFace *f) for (f2 = BMW_begin(®walker, f); f2; f2 = BMW_step(®walker)) { BM_ITER_ELEM (l2, &liter2, f2, BM_LOOPS_OF_FACE) { l3 = l2->radial_next; - if (BMO_elem_flag_test(bm, l3->f, FACE_MARK) != - BMO_elem_flag_test(bm, l2->f, FACE_MARK)) + if (BMO_face_flag_test(bm, l3->f, FACE_MARK) != + BMO_face_flag_test(bm, l2->f, FACE_MARK)) { - if (!BMO_elem_flag_test(bm, l2->e, EDGE_MARK)) { + if (!BMO_edge_flag_test(bm, l2->e, EDGE_MARK)) { return false; } } @@ -99,14 +99,14 @@ static void bm_face_split(BMesh *bm, const short oflag, bool use_edge_delete) } BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { - if (BMO_elem_flag_test(bm, v, oflag)) { + if (BMO_vert_flag_test(bm, v, oflag)) { if (BM_vert_is_edge_pair(v) == false) { BMIter liter; BMLoop *l; BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) { if (l->f->len > 3) { - if (BMO_elem_flag_test(bm, l->next->v, oflag) == 0 && - BMO_elem_flag_test(bm, l->prev->v, oflag) == 0) + if (BMO_vert_flag_test(bm, l->next->v, oflag) == 0 && + BMO_vert_flag_test(bm, l->prev->v, oflag) == 0) { BM_face_split(bm, l->f, l->next, l->prev, NULL, NULL, true); } @@ -153,7 +153,7 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op) BMVert *v; BM_ITER_MESH (v, &viter, bm, BM_VERTS_OF_MESH) { - BMO_elem_flag_set(bm, v, VERT_MARK, !BM_vert_is_edge_pair(v)); + BMO_vert_flag_set(bm, v, VERT_MARK, !BM_vert_is_edge_pair(v)); } } @@ -162,7 +162,7 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op) /* collect region */ BMO_ITER (f, &oiter, op->slots_in, "faces", BM_FACE) { BMFace *f_iter; - if (!BMO_elem_flag_test(bm, f, FACE_TAG)) { + if (!BMO_face_flag_test(bm, f, FACE_TAG)) { continue; } @@ -181,8 +181,8 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op) for (i = 0; i < BLI_array_count(faces); i++) { f_iter = faces[i]; - BMO_elem_flag_disable(bm, f_iter, FACE_TAG); - BMO_elem_flag_enable(bm, f_iter, FACE_ORIG); + BMO_face_flag_disable(bm, f_iter, FACE_TAG); + BMO_face_flag_enable(bm, f_iter, FACE_ORIG); } if (BMO_error_occurred(bm)) { @@ -229,8 +229,8 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op) /* if making the new face failed (e.g. overlapping test) * unmark the original faces for deletion */ - BMO_elem_flag_disable(bm, f_new, FACE_ORIG); - BMO_elem_flag_enable(bm, f_new, FACE_NEW); + BMO_face_flag_disable(bm, f_new, FACE_ORIG); + BMO_face_flag_enable(bm, f_new, FACE_NEW); } /* Typically no faces need to be deleted */ @@ -243,7 +243,7 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op) BMVert *v, *v_next; BM_ITER_MESH_MUTABLE (v, v_next, &viter, bm, BM_VERTS_OF_MESH) { - if (BMO_elem_flag_test(bm, v, VERT_MARK)) { + if (BMO_vert_flag_test(bm, v, VERT_MARK)) { if (BM_vert_is_edge_pair(v)) { BM_vert_collapse_edge(bm, v->e, v, true, true); } @@ -285,14 +285,14 @@ void bmo_dissolve_edges_exec(BMesh *bm, BMOperator *op) BMIter itersub; int untag_count = 0; BM_ITER_ELEM (e, &itersub, v, BM_EDGES_OF_VERT) { - if (!BMO_elem_flag_test(bm, e, EDGE_TAG)) { + if (!BMO_edge_flag_test(bm, e, EDGE_TAG)) { untag_count++; } } /* check that we have 2 edges remaining after dissolve */ if (untag_count <= 2) { - BMO_elem_flag_enable(bm, v, VERT_TAG); + BMO_vert_flag_enable(bm, v, VERT_TAG); } } @@ -301,7 +301,7 @@ void bmo_dissolve_edges_exec(BMesh *bm, BMOperator *op) if (use_verts) { BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { - BMO_elem_flag_set(bm, v, VERT_MARK, !BM_vert_is_edge_pair(v)); + BMO_vert_flag_set(bm, v, VERT_MARK, !BM_vert_is_edge_pair(v)); } } @@ -314,8 +314,8 @@ void bmo_dissolve_edges_exec(BMesh *bm, BMOperator *op) BMLoop *l_first, *l_iter; l_iter = l_first = BM_FACE_FIRST_LOOP(f_pair[j]); do { - BMO_elem_flag_enable(bm, l_iter->v, VERT_ISGC); - BMO_elem_flag_enable(bm, l_iter->e, EDGE_ISGC); + BMO_vert_flag_enable(bm, l_iter->v, VERT_ISGC); + BMO_edge_flag_enable(bm, l_iter->e, EDGE_ISGC); } while ((l_iter = l_iter->next) != l_first); } } @@ -341,12 +341,12 @@ void bmo_dissolve_edges_exec(BMesh *bm, BMOperator *op) /* Cleanup geometry (#BM_faces_join_pair, but it removes geometry we're looping on) * so do this in a separate pass instead. */ BM_ITER_MESH_MUTABLE (e, e_next, &iter, bm, BM_EDGES_OF_MESH) { - if ((e->l == NULL) && BMO_elem_flag_test(bm, e, EDGE_ISGC)) { + if ((e->l == NULL) && BMO_edge_flag_test(bm, e, EDGE_ISGC)) { BM_edge_kill(bm, e); } } BM_ITER_MESH_MUTABLE (v, v_next, &iter, bm, BM_VERTS_OF_MESH) { - if ((v->e == NULL) && BMO_elem_flag_test(bm, v, VERT_ISGC)) { + if ((v->e == NULL) && BMO_vert_flag_test(bm, v, VERT_ISGC)) { BM_vert_kill(bm, v); } } @@ -355,7 +355,7 @@ void bmo_dissolve_edges_exec(BMesh *bm, BMOperator *op) if (use_verts) { BM_ITER_MESH_MUTABLE (v, v_next, &iter, bm, BM_VERTS_OF_MESH) { - if (BMO_elem_flag_test(bm, v, VERT_MARK)) { + if (BMO_vert_flag_test(bm, v, VERT_MARK)) { if (BM_vert_is_edge_pair(v)) { BM_vert_collapse_edge(bm, v->e, v, true, true); } @@ -376,7 +376,7 @@ void bmo_dissolve_verts_exec(BMesh *bm, BMOperator *op) const bool use_boundary_tear = BMO_slot_bool_get(op->slots_in, "use_boundary_tear"); BMO_ITER (v, &oiter, op->slots_in, "verts", BM_VERT) { - BMO_elem_flag_enable(bm, v, VERT_MARK | VERT_ISGC); + BMO_vert_flag_enable(bm, v, VERT_MARK | VERT_ISGC); } if (use_face_split) { @@ -388,7 +388,7 @@ void bmo_dissolve_verts_exec(BMesh *bm, BMOperator *op) if (!BM_vert_is_edge_pair(v)) { BM_ITER_ELEM (e, &iter, v, BM_EDGES_OF_VERT) { if (BM_edge_is_boundary(e)) { - BMO_elem_flag_enable(bm, v, VERT_MARK_TEAR); + BMO_vert_flag_enable(bm, v, VERT_MARK_TEAR); break; } } @@ -406,8 +406,8 @@ void bmo_dissolve_verts_exec(BMesh *bm, BMOperator *op) BMLoop *l_iter; l_iter = l_first; do { - BMO_elem_flag_enable(bm, l_iter->v, VERT_ISGC); - BMO_elem_flag_enable(bm, l_iter->e, EDGE_ISGC); + BMO_vert_flag_enable(bm, l_iter->v, VERT_ISGC); + BMO_edge_flag_enable(bm, l_iter->e, EDGE_ISGC); } while ((l_iter = l_iter->next) != l_first); e_first = l_first->e; @@ -428,14 +428,14 @@ void bmo_dissolve_verts_exec(BMesh *bm, BMOperator *op) BMO_ITER (v, &oiter, op->slots_in, "verts", BM_VERT) { /* tag here so we avoid feedback loop (checking topology as we edit) */ if (BM_vert_is_edge_pair(v)) { - BMO_elem_flag_enable(bm, v, VERT_MARK_PAIR); + BMO_vert_flag_enable(bm, v, VERT_MARK_PAIR); } } BMO_ITER (v, &oiter, op->slots_in, "verts", BM_VERT) { BMIter itersub; - if (!BMO_elem_flag_test(bm, v, VERT_MARK_PAIR)) { + if (!BMO_vert_flag_test(bm, v, VERT_MARK_PAIR)) { BM_ITER_ELEM (e, &itersub, v, BM_EDGES_OF_VERT) { BMFace *fa, *fb; if (BM_edge_face_pair(e, &fa, &fb)) { @@ -456,7 +456,7 @@ void bmo_dissolve_verts_exec(BMesh *bm, BMOperator *op) /* Cleanup geometry (#BM_faces_join_pair, but it removes geometry we're looping on) * so do this in a separate pass instead. */ BM_ITER_MESH_MUTABLE (e, e_next, &iter, bm, BM_EDGES_OF_MESH) { - if ((e->l == NULL) && BMO_elem_flag_test(bm, e, EDGE_ISGC)) { + if ((e->l == NULL) && BMO_edge_flag_test(bm, e, EDGE_ISGC)) { BM_edge_kill(bm, e); } } @@ -469,7 +469,7 @@ void bmo_dissolve_verts_exec(BMesh *bm, BMOperator *op) } BM_ITER_MESH_MUTABLE (v, v_next, &iter, bm, BM_VERTS_OF_MESH) { - if ((v->e == NULL) && BMO_elem_flag_test(bm, v, VERT_ISGC)) { + if ((v->e == NULL) && BMO_vert_flag_test(bm, v, VERT_ISGC)) { BM_vert_kill(bm, v); } } @@ -518,9 +518,9 @@ void bmo_dissolve_degenerate_exec(BMesh *bm, BMOperator *op) /* collapse zero length edges, this accounts for zero area faces too */ found = false; BM_ITER_MESH (e, &eiter, bm, BM_EDGES_OF_MESH) { - if (BMO_elem_flag_test(bm, e, EDGE_MARK)) { + if (BMO_edge_flag_test(bm, e, EDGE_MARK)) { if (BM_edge_calc_length_squared(e) < dist_sq) { - BMO_elem_flag_enable(bm, e, EDGE_COLLAPSE); + BMO_edge_flag_enable(bm, e, EDGE_COLLAPSE); found = true; } } @@ -543,7 +543,7 @@ void bmo_dissolve_degenerate_exec(BMesh *bm, BMOperator *op) /* clip degenerate ears from the face */ found = false; BM_ITER_MESH (e, &eiter, bm, BM_EDGES_OF_MESH) { - if (e->l && BMO_elem_flag_test(bm, e, EDGE_MARK)) { + if (e->l && BMO_edge_flag_test(bm, e, EDGE_MARK)) { BMLoop *l_iter, *l_first; l_iter = l_first = e->l; do { @@ -553,11 +553,11 @@ void bmo_dissolve_degenerate_exec(BMesh *bm, BMOperator *op) ((void)BM_elem_flag_enable(l_iter, BM_ELEM_TAG), /* check we're marked to tested (radial edge already tested) */ - BMO_elem_flag_test(bm, l_iter->prev->e, EDGE_MARK) && + BMO_edge_flag_test(bm, l_iter->prev->e, EDGE_MARK) && /* check edges are not already going to be collapsed */ - !BMO_elem_flag_test(bm, l_iter->e, EDGE_COLLAPSE) && - !BMO_elem_flag_test(bm, l_iter->prev->e, EDGE_COLLAPSE))) + !BMO_edge_flag_test(bm, l_iter->e, EDGE_COLLAPSE) && + !BMO_edge_flag_test(bm, l_iter->prev->e, EDGE_COLLAPSE))) { /* test if the faces loop (ear) is degenerate */ float dir_prev[3], len_prev; @@ -577,14 +577,14 @@ void bmo_dissolve_degenerate_exec(BMesh *bm, BMOperator *op) /* both edges the same length */ if (l_iter->f->len == 3) { /* ideally this would have been discovered with short edge test above */ - BMO_elem_flag_enable(bm, l_iter->next->e, EDGE_COLLAPSE); + BMO_edge_flag_enable(bm, l_iter->next->e, EDGE_COLLAPSE); found = true; } else { /* add a joining edge and tag for removal */ BMLoop *l_split; if (BM_face_split(bm, l_iter->f, l_iter->prev, l_iter->next, &l_split, NULL, true)) { - BMO_elem_flag_enable(bm, l_split->e, EDGE_COLLAPSE); + BMO_edge_flag_enable(bm, l_split->e, EDGE_COLLAPSE); found = true; reset = true; } @@ -599,7 +599,7 @@ void bmo_dissolve_degenerate_exec(BMesh *bm, BMOperator *op) BLI_assert(v_new == l_iter->next->v); (void)v_new; if (BM_face_split(bm, l_iter->f, l_iter->prev, l_iter->next, &l_split, NULL, true)) { - BMO_elem_flag_enable(bm, l_split->e, EDGE_COLLAPSE); + BMO_edge_flag_enable(bm, l_split->e, EDGE_COLLAPSE); found = true; } reset = true; @@ -613,7 +613,7 @@ void bmo_dissolve_degenerate_exec(BMesh *bm, BMOperator *op) BLI_assert(v_new == l_iter->prev->v); (void)v_new; if (BM_face_split(bm, l_iter->f, l_iter->prev, l_iter->next, &l_split, NULL, true)) { - BMO_elem_flag_enable(bm, l_split->e, EDGE_COLLAPSE); + BMO_edge_flag_enable(bm, l_split->e, EDGE_COLLAPSE); found = true; } reset = true; diff --git a/source/blender/bmesh/operators/bmo_dupe.c b/source/blender/bmesh/operators/bmo_dupe.c index fd430de80f9..56639a097b6 100644 --- a/source/blender/bmesh/operators/bmo_dupe.c +++ b/source/blender/bmesh/operators/bmo_dupe.c @@ -63,7 +63,7 @@ static BMVert *bmo_vert_copy( BM_elem_attrs_copy(bm_src, bm_dst, v_src, v_dst); /* Mark the vert for output */ - BMO_elem_flag_enable(bm_dst, v_dst, DUPE_NEW); + BMO_vert_flag_enable(bm_dst, v_dst, DUPE_NEW); return v_dst; } @@ -94,7 +94,7 @@ static BMEdge *bmo_edge_copy( BMLoop *l_iter_src, *l_first_src; l_iter_src = l_first_src = e_src->l; do { - if (BMO_elem_flag_test(bm_src, l_iter_src->f, DUPE_INPUT)) { + if (BMO_face_flag_test(bm_src, l_iter_src->f, DUPE_INPUT)) { rlen++; } } while ((l_iter_src = l_iter_src->radial_next) != l_first_src); @@ -123,7 +123,7 @@ static BMEdge *bmo_edge_copy( BM_elem_attrs_copy(bm_src, bm_dst, e_src, e_dst); /* Mark the edge for output */ - BMO_elem_flag_enable(bm_dst, e_dst, DUPE_NEW); + BMO_edge_flag_enable(bm_dst, e_dst, DUPE_NEW); return e_dst; } @@ -175,7 +175,7 @@ static BMFace *bmo_face_copy( (l_iter_src = l_iter_src->next) != l_first_src); /* Mark the face for output */ - BMO_elem_flag_enable(bm_dst, f_dst, DUPE_NEW); + BMO_face_flag_enable(bm_dst, f_dst, DUPE_NEW); return f_dst; } @@ -209,8 +209,8 @@ static void bmo_mesh_copy(BMOperator *op, BMesh *bm_dst, BMesh *bm_src) /* duplicate flagged vertices */ BM_ITER_MESH (v, &viter, bm_src, BM_VERTS_OF_MESH) { - if (BMO_elem_flag_test(bm_src, v, DUPE_INPUT) && - !BMO_elem_flag_test(bm_src, v, DUPE_DONE)) + if (BMO_vert_flag_test(bm_src, v, DUPE_INPUT) && + BMO_vert_flag_test(bm_src, v, DUPE_DONE) == false) { BMIter iter; bool isolated = true; @@ -218,7 +218,7 @@ static void bmo_mesh_copy(BMOperator *op, BMesh *bm_dst, BMesh *bm_src) v2 = bmo_vert_copy(op, slot_vert_map_out, bm_dst, bm_src, v, vhash); BM_ITER_ELEM (f, &iter, v, BM_FACES_OF_VERT) { - if (BMO_elem_flag_test(bm_src, f, DUPE_INPUT)) { + if (BMO_face_flag_test(bm_src, f, DUPE_INPUT)) { isolated = false; break; } @@ -226,7 +226,7 @@ static void bmo_mesh_copy(BMOperator *op, BMesh *bm_dst, BMesh *bm_src) if (isolated) { BM_ITER_ELEM (e, &iter, v, BM_EDGES_OF_VERT) { - if (BMO_elem_flag_test(bm_src, e, DUPE_INPUT)) { + if (BMO_edge_flag_test(bm_src, e, DUPE_INPUT)) { isolated = false; break; } @@ -237,53 +237,53 @@ static void bmo_mesh_copy(BMOperator *op, BMesh *bm_dst, BMesh *bm_src) BMO_slot_map_elem_insert(op, slot_isovert_map_out, v, v2); } - BMO_elem_flag_enable(bm_src, v, DUPE_DONE); + BMO_vert_flag_enable(bm_src, v, DUPE_DONE); } } /* now we dupe all the edges */ BM_ITER_MESH (e, &eiter, bm_src, BM_EDGES_OF_MESH) { - if (BMO_elem_flag_test(bm_src, e, DUPE_INPUT) && - !BMO_elem_flag_test(bm_src, e, DUPE_DONE)) + if (BMO_edge_flag_test(bm_src, e, DUPE_INPUT) && + BMO_edge_flag_test(bm_src, e, DUPE_DONE) == false) { /* make sure that verts are copied */ - if (!BMO_elem_flag_test(bm_src, e->v1, DUPE_DONE)) { + if (!BMO_vert_flag_test(bm_src, e->v1, DUPE_DONE)) { bmo_vert_copy(op, slot_vert_map_out, bm_dst, bm_src, e->v1, vhash); - BMO_elem_flag_enable(bm_src, e->v1, DUPE_DONE); + BMO_vert_flag_enable(bm_src, e->v1, DUPE_DONE); } - if (!BMO_elem_flag_test(bm_src, e->v2, DUPE_DONE)) { + if (!BMO_vert_flag_test(bm_src, e->v2, DUPE_DONE)) { bmo_vert_copy(op, slot_vert_map_out, bm_dst, bm_src, e->v2, vhash); - BMO_elem_flag_enable(bm_src, e->v2, DUPE_DONE); + BMO_vert_flag_enable(bm_src, e->v2, DUPE_DONE); } /* now copy the actual edge */ bmo_edge_copy(op, slot_edge_map_out, slot_boundary_map_out, bm_dst, bm_src, e, vhash, ehash); - BMO_elem_flag_enable(bm_src, e, DUPE_DONE); + BMO_edge_flag_enable(bm_src, e, DUPE_DONE); } } /* first we dupe all flagged faces and their elements from source */ BM_ITER_MESH (f, &fiter, bm_src, BM_FACES_OF_MESH) { - if (BMO_elem_flag_test(bm_src, f, DUPE_INPUT)) { + if (BMO_face_flag_test(bm_src, f, DUPE_INPUT)) { /* vertex pass */ BM_ITER_ELEM (v, &viter, f, BM_VERTS_OF_FACE) { - if (!BMO_elem_flag_test(bm_src, v, DUPE_DONE)) { + if (!BMO_vert_flag_test(bm_src, v, DUPE_DONE)) { bmo_vert_copy(op, slot_vert_map_out, bm_dst, bm_src, v, vhash); - BMO_elem_flag_enable(bm_src, v, DUPE_DONE); + BMO_vert_flag_enable(bm_src, v, DUPE_DONE); } } /* edge pass */ BM_ITER_ELEM (e, &eiter, f, BM_EDGES_OF_FACE) { - if (!BMO_elem_flag_test(bm_src, e, DUPE_DONE)) { + if (!BMO_edge_flag_test(bm_src, e, DUPE_DONE)) { bmo_edge_copy(op, slot_edge_map_out, slot_boundary_map_out, bm_dst, bm_src, e, vhash, ehash); - BMO_elem_flag_enable(bm_src, e, DUPE_DONE); + BMO_edge_flag_enable(bm_src, e, DUPE_DONE); } } bmo_face_copy(op, slot_face_map_out, bm_dst, bm_src, f, vhash, ehash); - BMO_elem_flag_enable(bm_src, f, DUPE_DONE); + BMO_face_flag_enable(bm_src, f, DUPE_DONE); } } @@ -408,26 +408,26 @@ void bmo_split_exec(BMesh *bm, BMOperator *op) BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { bool found = false; BM_ITER_ELEM (f, &iter2, e, BM_FACES_OF_EDGE) { - if (!BMO_elem_flag_test(bm, f, SPLIT_INPUT)) { + if (!BMO_face_flag_test(bm, f, SPLIT_INPUT)) { found = true; break; } } if (found == false) { - BMO_elem_flag_enable(bm, e, SPLIT_INPUT); + BMO_edge_flag_enable(bm, e, SPLIT_INPUT); } } BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { bool found = false; BM_ITER_ELEM (e, &iter2, v, BM_EDGES_OF_VERT) { - if (!BMO_elem_flag_test(bm, e, SPLIT_INPUT)) { + if (!BMO_edge_flag_test(bm, e, SPLIT_INPUT)) { found = true; break; } } if (found == false) { - BMO_elem_flag_enable(bm, v, SPLIT_INPUT); + BMO_vert_flag_enable(bm, v, SPLIT_INPUT); } } } diff --git a/source/blender/bmesh/operators/bmo_edgenet.c b/source/blender/bmesh/operators/bmo_edgenet.c index f348014cead..64b092da5c8 100644 --- a/source/blender/bmesh/operators/bmo_edgenet.c +++ b/source/blender/bmesh/operators/bmo_edgenet.c @@ -94,8 +94,8 @@ static BMEdge *edge_next(BMesh *bm, BMEdge *e) for (i = 0; i < 2; i++) { BM_ITER_ELEM (e2, &iter, i ? e->v2 : e->v1, BM_EDGES_OF_VERT) { - if ((BMO_elem_flag_test(bm, e2, EDGE_MARK)) && - (!BMO_elem_flag_test(bm, e2, EDGE_VIS)) && + if ((BMO_edge_flag_test(bm, e2, EDGE_MARK)) && + (BMO_edge_flag_test(bm, e2, EDGE_VIS) == false) && (e2 != e)) { return e2; @@ -144,7 +144,7 @@ void bmo_edgenet_prepare_exec(BMesh *bm, BMOperator *op) count = 0; while (1) { BMO_ITER (e, &siter, op->slots_in, "edges", BM_EDGE) { - if (!BMO_elem_flag_test(bm, e, EDGE_VIS)) { + if (!BMO_edge_flag_test(bm, e, EDGE_VIS)) { if (BMO_iter_elem_count_flag(bm, BM_EDGES_OF_VERT, e->v1, EDGE_MARK, true) == 1 || BMO_iter_elem_count_flag(bm, BM_EDGES_OF_VERT, e->v2, EDGE_MARK, true) == 1) { @@ -169,7 +169,7 @@ void bmo_edgenet_prepare_exec(BMesh *bm, BMOperator *op) i = 0; while (e) { - BMO_elem_flag_enable(bm, e, EDGE_VIS); + BMO_edge_flag_enable(bm, e, EDGE_VIS); BLI_array_grow_one(edges); edges[i] = e; @@ -258,9 +258,9 @@ void bmo_edgenet_prepare_exec(BMesh *bm, BMOperator *op) } e = BM_edge_create(bm, v1, v3, NULL, BM_CREATE_NO_DOUBLE); - BMO_elem_flag_enable(bm, e, ELE_NEW); + BMO_edge_flag_enable(bm, e, ELE_NEW); e = BM_edge_create(bm, v2, v4, NULL, BM_CREATE_NO_DOUBLE); - BMO_elem_flag_enable(bm, e, ELE_NEW); + BMO_edge_flag_enable(bm, e, ELE_NEW); } else if (edges1) { BMVert *v1, *v2; @@ -270,7 +270,7 @@ void bmo_edgenet_prepare_exec(BMesh *bm, BMOperator *op) i = BLI_array_count(edges1) - 1; v2 = BM_vert_in_edge(edges1[i - 1], edges1[i]->v1) ? edges1[i]->v2 : edges1[i]->v1; e = BM_edge_create(bm, v1, v2, NULL, BM_CREATE_NO_DOUBLE); - BMO_elem_flag_enable(bm, e, ELE_NEW); + BMO_edge_flag_enable(bm, e, ELE_NEW); } } diff --git a/source/blender/bmesh/operators/bmo_extrude.c b/source/blender/bmesh/operators/bmo_extrude.c index 5a3bef6ba81..f2a8e05d763 100644 --- a/source/blender/bmesh/operators/bmo_extrude.c +++ b/source/blender/bmesh/operators/bmo_extrude.c @@ -70,10 +70,10 @@ void bmo_extrude_discrete_faces_exec(BMesh *bm, BMOperator *op) BMLoop *l_org, *l_org_first; BMLoop *l_new; - BMO_elem_flag_enable(bm, f_org, EXT_DEL); + BMO_face_flag_enable(bm, f_org, EXT_DEL); f_new = BM_face_copy(bm, bm, f_org, true, true); - BMO_elem_flag_enable(bm, f_new, EXT_KEEP); + BMO_face_flag_enable(bm, f_new, EXT_KEEP); if (select_history_map) { BMEditSelection *ese; @@ -188,9 +188,9 @@ void bmo_extrude_edge_only_exec(BMesh *bm, BMOperator *op) BMEdge *e, *e_new; BMO_ITER (e, &siter, op->slots_in, "edges", BM_EDGE) { - BMO_elem_flag_enable(bm, e, EXT_INPUT); - BMO_elem_flag_enable(bm, e->v1, EXT_INPUT); - BMO_elem_flag_enable(bm, e->v2, EXT_INPUT); + BMO_edge_flag_enable(bm, e, EXT_INPUT); + BMO_vert_flag_enable(bm, e->v1, EXT_INPUT); + BMO_vert_flag_enable(bm, e->v2, EXT_INPUT); } BMO_op_initf( @@ -228,13 +228,14 @@ void bmo_extrude_edge_only_exec(BMesh *bm, BMOperator *op) f = BM_face_create_verts(bm, f_verts, 4, NULL, BM_CREATE_NOP, true); bm_extrude_copy_face_loop_attributes(bm, f); - if (BMO_elem_flag_test(bm, e, EXT_INPUT)) + if (BMO_edge_flag_test(bm, e, EXT_INPUT)) { e = e_new; + } - BMO_elem_flag_enable(bm, f, EXT_KEEP); - BMO_elem_flag_enable(bm, e, EXT_KEEP); - BMO_elem_flag_enable(bm, e->v1, EXT_KEEP); - BMO_elem_flag_enable(bm, e->v2, EXT_KEEP); + BMO_face_flag_enable(bm, f, EXT_KEEP); + BMO_edge_flag_enable(bm, e, EXT_KEEP); + BMO_vert_flag_enable(bm, e->v1, EXT_KEEP); + BMO_vert_flag_enable(bm, e->v2, EXT_KEEP); } @@ -258,7 +259,7 @@ void bmo_extrude_vert_indiv_exec(BMesh *bm, BMOperator *op) for (v = BMO_iter_new(&siter, op->slots_in, "verts", BM_VERT); v; v = BMO_iter_step(&siter)) { dupev = BM_vert_create(bm, v->co, v, BM_CREATE_NOP); - BMO_elem_flag_enable(bm, dupev, EXT_KEEP); + BMO_vert_flag_enable(bm, dupev, EXT_KEEP); if (has_vskin) bm_extrude_disable_skin_root(bm, v); @@ -279,7 +280,7 @@ void bmo_extrude_vert_indiv_exec(BMesh *bm, BMOperator *op) } e = BM_edge_create(bm, v, dupev, NULL, BM_CREATE_NOP); - BMO_elem_flag_enable(bm, e, EXT_KEEP); + BMO_edge_flag_enable(bm, e, EXT_KEEP); } if (select_history_map) { @@ -350,7 +351,7 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) int edge_face_tot; - if (!BMO_elem_flag_test(bm, e, EXT_INPUT)) { + if (!BMO_edge_flag_test(bm, e, EXT_INPUT)) { continue; } @@ -358,7 +359,7 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) edge_face_tot = 0; /* edge/face count */ BM_ITER_ELEM (f, &fiter, e, BM_FACES_OF_EDGE) { - if (!BMO_elem_flag_test(bm, f, EXT_INPUT)) { + if (!BMO_face_flag_test(bm, f, EXT_INPUT)) { found = true; delorig = true; break; @@ -369,7 +370,7 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) if ((edge_face_tot > 1) && (found == false)) { /* edge has a face user, that face isn't extrude input */ - BMO_elem_flag_enable(bm, e, EXT_DEL); + BMO_edge_flag_enable(bm, e, EXT_DEL); } } } @@ -380,7 +381,9 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) found = false; BM_ITER_ELEM (e, &viter, v, BM_EDGES_OF_VERT) { - if (!BMO_elem_flag_test(bm, e, EXT_INPUT) || !BMO_elem_flag_test(bm, e, EXT_DEL)) { + if (!BMO_edge_flag_test(bm, e, EXT_INPUT) || + !BMO_edge_flag_test(bm, e, EXT_DEL)) + { found = true; break; } @@ -389,7 +392,7 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) /* avoid an extra loop */ if (found == true) { BM_ITER_ELEM (f, &viter, v, BM_FACES_OF_VERT) { - if (!BMO_elem_flag_test(bm, f, EXT_INPUT)) { + if (!BMO_face_flag_test(bm, f, EXT_INPUT)) { found = true; break; } @@ -397,14 +400,14 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) } if (found == false) { - BMO_elem_flag_enable(bm, v, EXT_DEL); + BMO_vert_flag_enable(bm, v, EXT_DEL); } } } BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { - if (BMO_elem_flag_test(bm, f, EXT_INPUT)) { - BMO_elem_flag_enable(bm, f, EXT_DEL); + if (BMO_face_flag_test(bm, f, EXT_INPUT)) { + BMO_face_flag_enable(bm, f, EXT_DEL); } } @@ -426,7 +429,7 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) } slot_facemap_out = BMO_slot_get(dupeop.slots_out, "face_map.out"); - if (bm->act_face && BMO_elem_flag_test(bm, bm->act_face, EXT_INPUT)) { + if (bm->act_face && BMO_face_flag_test(bm, bm->act_face, EXT_INPUT)) { bm->act_face = BMO_slot_map_elem_get(slot_facemap_out, bm->act_face); } @@ -437,7 +440,7 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) /* if not delorig, reverse loops of original face */ if (!delorig) { BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { - if (BMO_elem_flag_test(bm, f, EXT_INPUT)) { + if (BMO_face_flag_test(bm, f, EXT_INPUT)) { BM_face_normal_flip(bm, f); } } @@ -583,7 +586,7 @@ static void calc_solidify_normals(BMesh *bm) BM_mesh_elem_index_ensure(bm, BM_EDGE); BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { - if (!BMO_elem_flag_test(bm, f, FACE_MARK)) { + if (!BMO_face_flag_test(bm, f, FACE_MARK)) { continue; } @@ -591,15 +594,15 @@ static void calc_solidify_normals(BMesh *bm) /* And mark all edges and vertices on the * marked faces */ - BMO_elem_flag_enable(bm, e, EDGE_MARK); - BMO_elem_flag_enable(bm, e->v1, VERT_MARK); - BMO_elem_flag_enable(bm, e->v2, VERT_MARK); + BMO_edge_flag_enable(bm, e, EDGE_MARK); + BMO_vert_flag_enable(bm, e->v1, VERT_MARK); + BMO_vert_flag_enable(bm, e->v2, VERT_MARK); edge_face_count[BM_elem_index_get(e)]++; } } BM_ITER_MESH (e, &eiter, bm, BM_EDGES_OF_MESH) { - if (!BMO_elem_flag_test(bm, e, EDGE_MARK)) { + if (!BMO_edge_flag_test(bm, e, EDGE_MARK)) { continue; } @@ -608,9 +611,9 @@ static void calc_solidify_normals(BMesh *bm) if (i == 0 || i > 2) { /* Edge & vertices are non-manifold even when considering * only marked faces */ - BMO_elem_flag_enable(bm, e, EDGE_NONMAN); - BMO_elem_flag_enable(bm, e->v1, VERT_NONMAN); - BMO_elem_flag_enable(bm, e->v2, VERT_NONMAN); + BMO_edge_flag_enable(bm, e, EDGE_NONMAN); + BMO_vert_flag_enable(bm, e->v1, VERT_NONMAN); + BMO_vert_flag_enable(bm, e->v2, VERT_NONMAN); } } MEM_freeN(edge_face_count); @@ -618,11 +621,11 @@ static void calc_solidify_normals(BMesh *bm) BM_ITER_MESH (v, &viter, bm, BM_VERTS_OF_MESH) { if (!BM_vert_is_manifold(v)) { - BMO_elem_flag_enable(bm, v, VERT_NONMAN); + BMO_vert_flag_enable(bm, v, VERT_NONMAN); continue; } - if (BMO_elem_flag_test(bm, v, VERT_MARK)) { + if (BMO_vert_flag_test(bm, v, VERT_MARK)) { zero_v3(v->no); } } @@ -631,20 +634,20 @@ static void calc_solidify_normals(BMesh *bm) /* If the edge is not part of a the solidify region * its normal should not be considered */ - if (!BMO_elem_flag_test(bm, e, EDGE_MARK)) { + if (!BMO_edge_flag_test(bm, e, EDGE_MARK)) { continue; } /* If the edge joins more than two marked faces high * quality normal computation won't work */ - if (BMO_elem_flag_test(bm, e, EDGE_NONMAN)) { + if (BMO_edge_flag_test(bm, e, EDGE_NONMAN)) { continue; } f1 = f2 = NULL; BM_ITER_ELEM (f, &fiter, e, BM_FACES_OF_EDGE) { - if (BMO_elem_flag_test(bm, f, FACE_MARK)) { + if (BMO_face_flag_test(bm, f, FACE_MARK)) { if (f1 == NULL) { f1 = f; } @@ -689,11 +692,11 @@ static void calc_solidify_normals(BMesh *bm) /* normalize accumulated vertex normal */ BM_ITER_MESH (v, &viter, bm, BM_VERTS_OF_MESH) { - if (!BMO_elem_flag_test(bm, v, VERT_MARK)) { + if (!BMO_vert_flag_test(bm, v, VERT_MARK)) { continue; } - if (BMO_elem_flag_test(bm, v, VERT_NONMAN)) { + if (BMO_vert_flag_test(bm, v, VERT_NONMAN)) { /* use standard normals for vertices connected to non-manifold edges */ BM_vert_normal_update(v); } @@ -701,7 +704,7 @@ static void calc_solidify_normals(BMesh *bm) /* exceptional case, totally flat. use the normal * of any marked face around the vertex */ BM_ITER_ELEM (f, &fiter, v, BM_FACES_OF_VERT) { - if (BMO_elem_flag_test(bm, f, FACE_MARK)) { + if (BMO_face_flag_test(bm, f, FACE_MARK)) { break; } } @@ -726,7 +729,7 @@ static void solidify_add_thickness(BMesh *bm, const float dist) BM_mesh_elem_index_ensure(bm, BM_VERT); BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { - if (BMO_elem_flag_test(bm, f, FACE_MARK)) { + if (BMO_face_flag_test(bm, f, FACE_MARK)) { /* array for passing verts to angle_poly_v3 */ float *face_angles = BLI_buffer_reinit_data(&face_angles_buf, float, f->len); diff --git a/source/blender/bmesh/operators/bmo_fill_edgeloop.c b/source/blender/bmesh/operators/bmo_fill_edgeloop.c index 0fbaf5ff11a..c68130bc11d 100644 --- a/source/blender/bmesh/operators/bmo_fill_edgeloop.c +++ b/source/blender/bmesh/operators/bmo_fill_edgeloop.c @@ -59,14 +59,14 @@ void bmo_edgeloop_fill_exec(BMesh *bm, BMOperator *op) i = 0; BMO_ITER (e, &oiter, op->slots_in, "edges", BM_EDGE) { BMIter viter; - BMO_elem_flag_enable(bm, e, EDGE_MARK); + BMO_edge_flag_enable(bm, e, EDGE_MARK); BM_ITER_ELEM (v, &viter, e, BM_VERTS_OF_EDGE) { - if (BMO_elem_flag_test(bm, v, VERT_USED) == false) { + if (BMO_vert_flag_test(bm, v, VERT_USED) == false) { if (i == tote) { goto cleanup; } - BMO_elem_flag_enable(bm, v, VERT_USED); + BMO_vert_flag_enable(bm, v, VERT_USED); verts[i++] = v; } } @@ -103,21 +103,21 @@ void bmo_edgeloop_fill_exec(BMesh *bm, BMOperator *op) while (totv_used < totv) { for (i = 0; i < totv; i++) { v = verts[i]; - if (BMO_elem_flag_test(bm, v, VERT_USED)) { + if (BMO_vert_flag_test(bm, v, VERT_USED)) { break; } } /* this should never fail, as long as (totv_used < totv) * we should have marked verts available */ - BLI_assert(BMO_elem_flag_test(bm, v, VERT_USED)); + BLI_assert(BMO_vert_flag_test(bm, v, VERT_USED)); /* watch it, 'i' is used for final face length */ i = 0; do { /* we know that there are 2 edges per vertex so no need to check */ BM_ITER_ELEM (e, &eiter, v, BM_EDGES_OF_VERT) { - if (BMO_elem_flag_test(bm, e, EDGE_MARK)) { + if (BMO_edge_flag_test(bm, e, EDGE_MARK)) { if (e != e_prev) { e_next = e; break; @@ -127,7 +127,7 @@ void bmo_edgeloop_fill_exec(BMesh *bm, BMOperator *op) /* fill in the array */ f_verts[i] = v; - BMO_elem_flag_disable(bm, v, VERT_USED); + BMO_vert_flag_disable(bm, v, VERT_USED); totv_used++; /* step over the edges */ @@ -141,7 +141,7 @@ void bmo_edgeloop_fill_exec(BMesh *bm, BMOperator *op) /* don't use calc_edges option because we already have the edges */ f = BM_face_create_ngon_verts(bm, f_verts, i, NULL, BM_CREATE_NOP, true, false); - BMO_elem_flag_enable(bm, f, ELE_OUT); + BMO_face_flag_enable(bm, f, ELE_OUT); f->mat_nr = mat_nr; if (use_smooth) { BM_elem_flag_enable(f, BM_ELEM_SMOOTH); diff --git a/source/blender/bmesh/operators/bmo_fill_grid.c b/source/blender/bmesh/operators/bmo_fill_grid.c index 77556591728..04ae915b707 100644 --- a/source/blender/bmesh/operators/bmo_fill_grid.c +++ b/source/blender/bmesh/operators/bmo_fill_grid.c @@ -466,7 +466,7 @@ static void bm_grid_fill_array( /* end interp */ - BMO_elem_flag_enable(bm, f, FACE_OUT); + BMO_face_flag_enable(bm, f, FACE_OUT); f->mat_nr = mat_nr; if (use_smooth) { BM_elem_flag_enable(f, BM_ELEM_SMOOTH); @@ -585,7 +585,7 @@ static void bm_edgeloop_flag_set(struct BMEdgeLoopStore *estore, char hflag, boo static bool bm_edge_test_cb(BMEdge *e, void *bm_v) { - return BMO_elem_flag_test_bool((BMesh *)bm_v, e, EDGE_MARK); + return BMO_edge_flag_test_bool((BMesh *)bm_v, e, EDGE_MARK); } static bool bm_edge_test_rail_cb(BMEdge *e, void *UNUSED(bm_v)) diff --git a/source/blender/bmesh/operators/bmo_hull.c b/source/blender/bmesh/operators/bmo_hull.c index 2dfad5a1f47..9c41e4f2115 100644 --- a/source/blender/bmesh/operators/bmo_hull.c +++ b/source/blender/bmesh/operators/bmo_hull.c @@ -81,7 +81,7 @@ static void hull_add_triangle( /* Mark triangles vertices as not interior */ for (i = 0; i < 3; i++) - BMO_elem_flag_disable(bm, t->v[i], HULL_FLAG_INTERIOR_ELE); + BMO_vert_flag_disable(bm, t->v[i], HULL_FLAG_INTERIOR_ELE); BLI_gset_insert(hull_triangles, t); normal_tri_v3(t->no, v1->co, v2->co, v3->co); @@ -93,8 +93,8 @@ static BMFace *hull_find_example_face(BMesh *bm, BMEdge *e) BMFace *f; BM_ITER_ELEM (f, &iter, e, BM_FACES_OF_EDGE) { - if (BMO_elem_flag_test(bm, f, HULL_FLAG_INPUT) || - !BMO_elem_flag_test(bm, f, HULL_FLAG_OUTPUT_GEOM)) + if (BMO_face_flag_test(bm, f, HULL_FLAG_INPUT) || + BMO_face_flag_test(bm, f, HULL_FLAG_OUTPUT_GEOM) == false) { return f; } @@ -124,9 +124,9 @@ static void hull_output_triangles(BMesh *bm, GSet *hull_triangles) * disabled, but an output face in the hull is the * same as a face in the existing mesh, it should not * be marked as unused or interior. */ - BMO_elem_flag_enable(bm, f, HULL_FLAG_OUTPUT_GEOM); - BMO_elem_flag_disable(bm, f, HULL_FLAG_HOLE); - BMO_elem_flag_disable(bm, f, HULL_FLAG_INTERIOR_ELE); + BMO_face_flag_enable(bm, f, HULL_FLAG_OUTPUT_GEOM); + BMO_face_flag_disable(bm, f, HULL_FLAG_HOLE); + BMO_face_flag_disable(bm, f, HULL_FLAG_INTERIOR_ELE); } else { /* Look for an adjacent face that existed before the hull */ @@ -140,12 +140,12 @@ static void hull_output_triangles(BMesh *bm, GSet *hull_triangles) BM_face_copy_shared(bm, f, NULL, NULL); } /* Mark face for 'geom.out' slot and select */ - BMO_elem_flag_enable(bm, f, HULL_FLAG_OUTPUT_GEOM); + BMO_face_flag_enable(bm, f, HULL_FLAG_OUTPUT_GEOM); BM_face_select_set(bm, f, true); /* Mark edges for 'geom.out' slot */ for (i = 0; i < 3; i++) { - BMO_elem_flag_enable(bm, edges[i], HULL_FLAG_OUTPUT_GEOM); + BMO_edge_flag_enable(bm, edges[i], HULL_FLAG_OUTPUT_GEOM); } } else { @@ -154,17 +154,17 @@ static void hull_output_triangles(BMesh *bm, GSet *hull_triangles) const int next = (i == 2 ? 0 : i + 1); BMEdge *e = BM_edge_exists(t->v[i], t->v[next]); if (e && - BMO_elem_flag_test(bm, e, HULL_FLAG_INPUT) && - !BMO_elem_flag_test(bm, e, HULL_FLAG_HOLE)) + BMO_edge_flag_test(bm, e, HULL_FLAG_INPUT) && + !BMO_edge_flag_test(bm, e, HULL_FLAG_HOLE)) { - BMO_elem_flag_enable(bm, e, HULL_FLAG_OUTPUT_GEOM); + BMO_edge_flag_enable(bm, e, HULL_FLAG_OUTPUT_GEOM); } } } /* Mark verts for 'geom.out' slot */ for (i = 0; i < 3; i++) { - BMO_elem_flag_enable(bm, t->v[i], HULL_FLAG_OUTPUT_GEOM); + BMO_vert_flag_enable(bm, t->v[i], HULL_FLAG_OUTPUT_GEOM); } } } @@ -292,8 +292,8 @@ static void hull_remove_overlapping( BM_vert_in_face(t->v[2], f) && f_on_hull) { t->skip = true; - BMO_elem_flag_disable(bm, f, HULL_FLAG_INTERIOR_ELE); - BMO_elem_flag_enable(bm, f, HULL_FLAG_HOLE); + BMO_face_flag_disable(bm, f, HULL_FLAG_INTERIOR_ELE); + BMO_face_flag_enable(bm, f, HULL_FLAG_HOLE); } } } @@ -310,13 +310,13 @@ static void hull_mark_interior_elements( /* Check for interior edges too */ BMO_ITER (e, &oiter, op->slots_in, "input", BM_EDGE) { if (!hull_final_edges_lookup(final_edges, e->v1, e->v2)) - BMO_elem_flag_enable(bm, e, HULL_FLAG_INTERIOR_ELE); + BMO_edge_flag_enable(bm, e, HULL_FLAG_INTERIOR_ELE); } /* Mark all input faces as interior, some may be unmarked in * hull_remove_overlapping() */ BMO_ITER (f, &oiter, op->slots_in, "input", BM_FACE) { - BMO_elem_flag_enable(bm, f, HULL_FLAG_INTERIOR_ELE); + BMO_face_flag_enable(bm, f, HULL_FLAG_INTERIOR_ELE); } } @@ -333,47 +333,50 @@ static void hull_tag_unused(BMesh *bm, BMOperator *op) * the hull), but that aren't also used by elements outside the * input set */ BMO_ITER (v, &oiter, op->slots_in, "input", BM_VERT) { - if (BMO_elem_flag_test(bm, v, HULL_FLAG_INTERIOR_ELE)) { + if (BMO_vert_flag_test(bm, v, HULL_FLAG_INTERIOR_ELE)) { bool del = true; BM_ITER_ELEM (e, &iter, v, BM_EDGES_OF_VERT) { - if (!BMO_elem_flag_test(bm, e, HULL_FLAG_INPUT)) { + if (!BMO_edge_flag_test(bm, e, HULL_FLAG_INPUT)) { del = false; break; } } BM_ITER_ELEM (f, &iter, v, BM_FACES_OF_VERT) { - if (!BMO_elem_flag_test(bm, f, HULL_FLAG_INPUT)) { + if (!BMO_face_flag_test(bm, f, HULL_FLAG_INPUT)) { del = false; break; } } - if (del) - BMO_elem_flag_enable(bm, v, HULL_FLAG_DEL); + if (del) { + BMO_vert_flag_enable(bm, v, HULL_FLAG_DEL); + } } } BMO_ITER (e, &oiter, op->slots_in, "input", BM_EDGE) { - if (BMO_elem_flag_test(bm, e, HULL_FLAG_INTERIOR_ELE)) { + if (BMO_edge_flag_test(bm, e, HULL_FLAG_INTERIOR_ELE)) { bool del = true; BM_ITER_ELEM (f, &iter, e, BM_FACES_OF_EDGE) { - if (!BMO_elem_flag_test(bm, f, HULL_FLAG_INPUT)) { + if (!BMO_face_flag_test(bm, f, HULL_FLAG_INPUT)) { del = false; break; } } - if (del) - BMO_elem_flag_enable(bm, e, HULL_FLAG_DEL); + if (del) { + BMO_edge_flag_enable(bm, e, HULL_FLAG_DEL); + } } } BMO_ITER (f, &oiter, op->slots_in, "input", BM_FACE) { - if (BMO_elem_flag_test(bm, f, HULL_FLAG_INTERIOR_ELE)) - BMO_elem_flag_enable(bm, f, HULL_FLAG_DEL); + if (BMO_face_flag_test(bm, f, HULL_FLAG_INTERIOR_ELE)) { + BMO_face_flag_enable(bm, f, HULL_FLAG_DEL); + } } } @@ -387,10 +390,10 @@ static void hull_tag_holes(BMesh *bm, BMOperator *op) /* Unmark any hole faces if they are isolated or part of a * border */ BMO_ITER (f, &oiter, op->slots_in, "input", BM_FACE) { - if (BMO_elem_flag_test(bm, f, HULL_FLAG_HOLE)) { + if (BMO_face_flag_test(bm, f, HULL_FLAG_HOLE)) { BM_ITER_ELEM (e, &iter, f, BM_EDGES_OF_FACE) { if (BM_edge_is_boundary(e)) { - BMO_elem_flag_disable(bm, f, HULL_FLAG_HOLE); + BMO_face_flag_disable(bm, f, HULL_FLAG_HOLE); break; } } @@ -405,14 +408,14 @@ static void hull_tag_holes(BMesh *bm, BMOperator *op) BM_ITER_ELEM (f, &iter, e, BM_FACES_OF_EDGE) { any_faces = true; - if (!BMO_elem_flag_test(bm, f, HULL_FLAG_HOLE)) { + if (!BMO_face_flag_test(bm, f, HULL_FLAG_HOLE)) { hole = false; break; } } if (hole && any_faces) - BMO_elem_flag_enable(bm, e, HULL_FLAG_HOLE); + BMO_edge_flag_enable(bm, e, HULL_FLAG_HOLE); } } @@ -578,11 +581,17 @@ void bmo_convex_hull_exec(BMesh *bm, BMOperator *op) /* Tag input elements */ BMO_ITER (ele, &oiter, op->slots_in, "input", BM_ALL) { - BMO_elem_flag_enable(bm, ele, HULL_FLAG_INPUT); - + /* Mark all vertices as interior to begin with */ - if (ele->head.htype == BM_VERT) - BMO_elem_flag_enable(bm, ele, HULL_FLAG_INTERIOR_ELE); + if (ele->head.htype == BM_VERT) { + BMO_vert_flag_enable(bm, (BMVert *)ele, HULL_FLAG_INPUT | HULL_FLAG_INTERIOR_ELE); + } + else if (ele->head.htype == BM_EDGE) { + BMO_edge_flag_enable(bm, (BMEdge *)ele, HULL_FLAG_INPUT); + } + else { + BMO_face_flag_enable(bm, (BMFace *)ele, HULL_FLAG_INPUT); + } } hull_pool = BLI_mempool_create(sizeof(HullTriangle), 0, 128, BLI_MEMPOOL_NOP); diff --git a/source/blender/bmesh/operators/bmo_inset.c b/source/blender/bmesh/operators/bmo_inset.c index ef5d90e6acb..c52c608e671 100644 --- a/source/blender/bmesh/operators/bmo_inset.c +++ b/source/blender/bmesh/operators/bmo_inset.c @@ -313,7 +313,7 @@ static void bmo_face_inset_individual( l_iter->next->v, l_iter->v, f, BM_CREATE_NOP); - BMO_elem_flag_enable(bm, f_new_outer, ELE_NEW); + BMO_face_flag_enable(bm, f_new_outer, ELE_NEW); /* copy loop data */ l_other = l_iter->radial_next; @@ -1037,7 +1037,7 @@ void bmo_inset_region_exec(BMesh *bm, BMOperator *op) /* no need to check doubles, we KNOW there won't be any */ /* yes - reverse face is correct in this case */ f = BM_face_create_verts(bm, varr, j, es->l->f, BM_CREATE_NOP, true); - BMO_elem_flag_enable(bm, f, ELE_NEW); + BMO_face_flag_enable(bm, f, ELE_NEW); /* copy for loop data, otherwise UV's and vcols are no good. * tiny speedup here we could be more clever and copy from known adjacent data diff --git a/source/blender/bmesh/operators/bmo_join_triangles.c b/source/blender/bmesh/operators/bmo_join_triangles.c index 3718f14276c..bc620e4a020 100644 --- a/source/blender/bmesh/operators/bmo_join_triangles.c +++ b/source/blender/bmesh/operators/bmo_join_triangles.c @@ -315,7 +315,7 @@ void bmo_join_triangles_exec(BMesh *bm, BMOperator *op) /* flag all edges of all input face */ BMO_ITER (f, &siter, op->slots_in, "faces", BM_FACE) { if (f->len == 3) { - BMO_elem_flag_enable(bm, f, FACE_INPUT); + BMO_face_flag_enable(bm, f, FACE_INPUT); } } @@ -323,11 +323,11 @@ void bmo_join_triangles_exec(BMesh *bm, BMOperator *op) BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { BMFace *f_a, *f_b; if (BM_edge_face_pair(e, &f_a, &f_b) && - (BMO_elem_flag_test(bm, f_a, FACE_INPUT) && - BMO_elem_flag_test(bm, f_b, FACE_INPUT))) + (BMO_face_flag_test(bm, f_a, FACE_INPUT) && + BMO_face_flag_test(bm, f_b, FACE_INPUT))) { if (!bm_edge_is_delimit(e, &delimit_data)) { - BMO_elem_flag_enable(bm, e, EDGE_MARK); + BMO_edge_flag_enable(bm, e, EDGE_MARK); totedge_tag++; } } @@ -345,7 +345,7 @@ void bmo_join_triangles_exec(BMesh *bm, BMOperator *op) const BMVert *verts[4]; float error; - if (!BMO_elem_flag_test(bm, e, EDGE_MARK)) + if (!BMO_edge_flag_test(bm, e, EDGE_MARK)) continue; bm_edge_to_quad_verts(e, verts); @@ -372,7 +372,7 @@ void bmo_join_triangles_exec(BMesh *bm, BMOperator *op) BMFace *f_new; f_new = BM_faces_join_pair(bm, f_a, f_b, e, true); if (f_new) { - BMO_elem_flag_enable(bm, f_new, FACE_OUT); + BMO_face_flag_enable(bm, f_new, FACE_OUT); } } } diff --git a/source/blender/bmesh/operators/bmo_normals.c b/source/blender/bmesh/operators/bmo_normals.c index 6044960265b..f0738303d5c 100644 --- a/source/blender/bmesh/operators/bmo_normals.c +++ b/source/blender/bmesh/operators/bmo_normals.c @@ -111,7 +111,7 @@ static int recalc_face_normals_find_index(BMesh *bm, BMFace **faces, const int f madd_v3_v3fl(cent, f_cent, cent_fac * f_area); cent_area_accum += f_area; - BLI_assert(BMO_elem_flag_test(bm, faces[i], FACE_TEMP) == 0); + BLI_assert(BMO_face_flag_test(bm, faces[i], FACE_TEMP) == 0); BLI_assert(BM_face_is_normal_valid(faces[i])); } @@ -209,7 +209,7 @@ static void bmo_recalc_face_normals_array(BMesh *bm, BMFace **faces, const int f f_start_index = recalc_face_normals_find_index(bm, faces, faces_len, &is_flip); if (is_flip) { - BMO_elem_flag_enable(bm, faces[f_start_index], FACE_FLIP); + BMO_face_flag_enable(bm, faces[f_start_index], FACE_FLIP); } /* now that we've found our starting face, make all connected faces @@ -219,10 +219,10 @@ static void bmo_recalc_face_normals_array(BMesh *bm, BMFace **faces, const int f BLI_LINKSTACK_INIT(fstack); BLI_LINKSTACK_PUSH(fstack, faces[f_start_index]); - BMO_elem_flag_enable(bm, faces[f_start_index], FACE_TEMP); + BMO_face_flag_enable(bm, faces[f_start_index], FACE_TEMP); while ((f = BLI_LINKSTACK_POP(fstack))) { - const bool flip_state = BMO_elem_flag_test_bool(bm, f, FACE_FLIP); + const bool flip_state = BMO_face_flag_test_bool(bm, f, FACE_FLIP); BMLoop *l_iter, *l_first; l_iter = l_first = BM_FACE_FIRST_LOOP(f); @@ -230,9 +230,9 @@ static void bmo_recalc_face_normals_array(BMesh *bm, BMFace **faces, const int f BMLoop *l_other = l_iter->radial_next; if ((l_other != l_iter) && bmo_recalc_normal_loop_filter_cb(l_iter, NULL)) { - if (!BMO_elem_flag_test(bm, l_other->f, FACE_TEMP)) { - BMO_elem_flag_enable(bm, l_other->f, FACE_TEMP); - BMO_elem_flag_set(bm, l_other->f, FACE_FLIP, (l_other->v == l_iter->v) != flip_state); + if (!BMO_face_flag_test(bm, l_other->f, FACE_TEMP)) { + BMO_face_flag_enable(bm, l_other->f, FACE_TEMP); + BMO_face_flag_set(bm, l_other->f, FACE_FLIP, (l_other->v == l_iter->v) != flip_state); BLI_LINKSTACK_PUSH(fstack, l_other->f); } } @@ -243,10 +243,10 @@ static void bmo_recalc_face_normals_array(BMesh *bm, BMFace **faces, const int f /* apply flipping to oflag'd faces */ for (i = 0; i < faces_len; i++) { - if (BMO_elem_flag_test(bm, faces[i], oflag_flip) == oflag_flip) { + if (BMO_face_flag_test(bm, faces[i], oflag_flip) == oflag_flip) { BM_face_normal_flip(bm, faces[i]); } - BMO_elem_flag_disable(bm, faces[i], FACE_TEMP); + BMO_face_flag_disable(bm, faces[i], FACE_TEMP); } } @@ -284,7 +284,7 @@ void bmo_recalc_face_normals_exec(BMesh *bm, BMOperator *op) faces_grp[j] = BM_face_at_index(bm, groups_array[fg_sta + j]); if (is_calc == false) { - is_calc = BMO_elem_flag_test_bool(bm, faces_grp[j], FACE_FLAG); + is_calc = BMO_face_flag_test_bool(bm, faces_grp[j], FACE_FLAG); } } diff --git a/source/blender/bmesh/operators/bmo_offset_edgeloops.c b/source/blender/bmesh/operators/bmo_offset_edgeloops.c index 8f4bc5ef3ad..7a6f779b34f 100644 --- a/source/blender/bmesh/operators/bmo_offset_edgeloops.c +++ b/source/blender/bmesh/operators/bmo_offset_edgeloops.c @@ -178,7 +178,7 @@ void bmo_offset_edgeloops_exec(BMesh *bm, BMOperator *op) #ifdef USE_CAP_OPTION if (v_edges_num_untag == 1) { - BMO_elem_flag_enable(bm, v, ELE_VERT_ENDPOINT); + BMO_vert_flag_enable(bm, v, ELE_VERT_ENDPOINT); } CLAMP_MIN(v_edges_max, v_edges_num); @@ -201,7 +201,7 @@ void bmo_offset_edgeloops_exec(BMesh *bm, BMOperator *op) (BM_elem_index_get(l->prev->v) == -1)) { #ifdef USE_CAP_OPTION - if (use_cap_endpoint || (BMO_elem_flag_test(bm, v, ELE_VERT_ENDPOINT) == 0)) + if (use_cap_endpoint || (BMO_vert_flag_test(bm, v, ELE_VERT_ENDPOINT) == 0)) #endif { BMLoop *l_new; @@ -209,7 +209,7 @@ void bmo_offset_edgeloops_exec(BMesh *bm, BMOperator *op) BLI_assert(f_cmp == l->f); BLI_assert(f_cmp != l_new->f); UNUSED_VARS_NDEBUG(f_cmp); - BMO_elem_flag_enable(bm, l_new->e, ELE_NEW); + BMO_edge_flag_enable(bm, l_new->e, ELE_NEW); } } else if (l->f->len > 4) { @@ -222,7 +222,7 @@ void bmo_offset_edgeloops_exec(BMesh *bm, BMOperator *op) BM_face_split(bm, l->f, l->prev->prev, l->next, &l_new, NULL, true); BLI_assert(f_cmp == l->f); BLI_assert(f_cmp != l_new->f); - BMO_elem_flag_enable(bm, l_new->e, ELE_NEW); + BMO_edge_flag_enable(bm, l_new->e, ELE_NEW); BM_elem_flag_disable(l->f, BM_ELEM_TAG); } else { @@ -230,7 +230,7 @@ void bmo_offset_edgeloops_exec(BMesh *bm, BMOperator *op) BMLoop *l_new; bm_face_split_walk_back(bm, l, &l_new); do { - BMO_elem_flag_enable(bm, l_new->e, ELE_NEW); + BMO_edge_flag_enable(bm, l_new->e, ELE_NEW); l_new = l_new->next; } while (BM_vert_is_edge_pair(l_new->v)); BM_elem_flag_disable(l->f, BM_ELEM_TAG); diff --git a/source/blender/bmesh/operators/bmo_planar_faces.c b/source/blender/bmesh/operators/bmo_planar_faces.c index 2856d3d18a6..a0951455fb4 100644 --- a/source/blender/bmesh/operators/bmo_planar_faces.c +++ b/source/blender/bmesh/operators/bmo_planar_faces.c @@ -71,13 +71,13 @@ void bmo_planar_faces_exec(BMesh *bm, BMOperator *op) l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { - if (!BMO_elem_flag_test(bm, l_iter->v, ELE_VERT_ADJUST)) { - BMO_elem_flag_enable(bm, l_iter->v, ELE_VERT_ADJUST); + if (!BMO_vert_flag_test(bm, l_iter->v, ELE_VERT_ADJUST)) { + BMO_vert_flag_enable(bm, l_iter->v, ELE_VERT_ADJUST); shared_vert_num += 1; } } while ((l_iter = l_iter->next) != l_first); - BMO_elem_flag_enable(bm, f, ELE_FACE_ADJUST); + BMO_face_flag_enable(bm, f, ELE_FACE_ADJUST); } vert_accum_pool = BLI_mempool_create(sizeof(struct VertAccum), 0, 512, BLI_MEMPOOL_NOP); @@ -91,10 +91,10 @@ void bmo_planar_faces_exec(BMesh *bm, BMOperator *op) BMLoop *l_iter, *l_first; float plane[4]; - if (!BMO_elem_flag_test(bm, f, ELE_FACE_ADJUST)) { + if (!BMO_face_flag_test(bm, f, ELE_FACE_ADJUST)) { continue; } - BMO_elem_flag_disable(bm, f, ELE_FACE_ADJUST); + BMO_face_flag_disable(bm, f, ELE_FACE_ADJUST); BLI_assert(f->len != 3); @@ -130,7 +130,7 @@ void bmo_planar_faces_exec(BMesh *bm, BMOperator *op) BMIter iter; if (len_squared_v3v3(v->co, va->co) > eps_sq) { - BMO_elem_flag_enable(bm, v, ELE_VERT_ADJUST); + BMO_vert_flag_enable(bm, v, ELE_VERT_ADJUST); interp_v3_v3v3(v->co, v->co, va->co, fac); changed = true; } @@ -138,7 +138,7 @@ void bmo_planar_faces_exec(BMesh *bm, BMOperator *op) /* tag for re-calculation */ BM_ITER_ELEM (f, &iter, v, BM_FACES_OF_VERT) { if (f->len != 3) { - BMO_elem_flag_enable(bm, f, ELE_FACE_ADJUST); + BMO_face_flag_enable(bm, f, ELE_FACE_ADJUST); } } } diff --git a/source/blender/bmesh/operators/bmo_poke.c b/source/blender/bmesh/operators/bmo_poke.c index 4d86d6e8e5b..32ad25b7b82 100644 --- a/source/blender/bmesh/operators/bmo_poke.c +++ b/source/blender/bmesh/operators/bmo_poke.c @@ -87,7 +87,7 @@ void bmo_poke_exec(BMesh *bm, BMOperator *op) bm_face_calc_center_fn(f, f_center); v_center = BM_vert_create(bm, f_center, NULL, BM_CREATE_NOP); - BMO_elem_flag_enable(bm, v_center, ELE_NEW); + BMO_vert_flag_enable(bm, v_center, ELE_NEW); if (cd_loop_mdisp_offset != -1) { if (center_mode == BMOP_POKE_MEAN) { @@ -128,7 +128,7 @@ void bmo_poke_exec(BMesh *bm, BMOperator *op) BM_elem_attrs_copy(bm, bm, l_iter, l_new); BM_elem_attrs_copy(bm, bm, l_iter->next, l_new->next); - BMO_elem_flag_enable(bm, f_new, ELE_NEW); + BMO_face_flag_enable(bm, f_new, ELE_NEW); if (cd_loop_mdisp_offset != -1) { float f_new_center[3]; diff --git a/source/blender/bmesh/operators/bmo_primitive.c b/source/blender/bmesh/operators/bmo_primitive.c index b120b48447f..d2b9fa9efa3 100644 --- a/source/blender/bmesh/operators/bmo_primitive.c +++ b/source/blender/bmesh/operators/bmo_primitive.c @@ -259,7 +259,7 @@ void bmo_create_grid_exec(BMesh *bm, BMOperator *op) vec[0] = ((x * xtot_inv2) - 1.0f) * dia; mul_v3_m4v3(tvec, mat, vec); varr[i] = BM_vert_create(bm, tvec, NULL, BM_CREATE_NOP); - BMO_elem_flag_enable(bm, varr[i], VERT_MARK); + BMO_vert_flag_enable(bm, varr[i], VERT_MARK); i++; } } @@ -277,7 +277,7 @@ void bmo_create_grid_exec(BMesh *bm, BMOperator *op) f = BM_face_create_verts(bm, vquad, 4, NULL, BM_CREATE_NOP, true); if (calc_uvs) { - BMO_elem_flag_enable(bm, f, FACE_MARK); + BMO_face_flag_enable(bm, f, FACE_MARK); } } } @@ -315,7 +315,7 @@ void BM_mesh_calc_uvs_grid(BMesh *bm, const unsigned int x_segments, const unsig BLI_assert(cd_loop_uv_offset != -1); BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { - if (!BMO_elem_flag_test(bm, f, oflag)) + if (!BMO_face_flag_test(bm, f, oflag)) continue; BM_ITER_ELEM_INDEX (l, &liter, f, BM_LOOPS_OF_FACE, loop_index) { @@ -380,11 +380,11 @@ void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op) vec[1] = dia * sinf(phi); vec[2] = dia * cosf(phi); eve = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); - BMO_elem_flag_enable(bm, eve, VERT_MARK); + BMO_vert_flag_enable(bm, eve, VERT_MARK); if (a != 0) { e = BM_edge_create(bm, preveve, eve, NULL, BM_CREATE_NOP); - BMO_elem_flag_enable(bm, e, EDGE_ORIG); + BMO_edge_flag_enable(bm, e, EDGE_ORIG); } phi += phid; @@ -442,14 +442,14 @@ void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op) bool valid = true; BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { - if (!BMO_elem_flag_test(bm, l->v, VERT_MARK)) { + if (!BMO_vert_flag_test(bm, l->v, VERT_MARK)) { valid = false; break; } } if (valid) { - BMO_elem_flag_enable(bm, f, FACE_MARK); + BMO_face_flag_enable(bm, f, FACE_MARK); } } @@ -458,7 +458,7 @@ void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op) /* and now do imat */ BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { - if (BMO_elem_flag_test(bm, eve, VERT_MARK)) { + if (BMO_vert_flag_test(bm, eve, VERT_MARK)) { mul_m4_v3(mat, eve->co); } } @@ -493,7 +493,7 @@ void bmo_create_icosphere_exec(BMesh *bm, BMOperator *op) vec[2] = dia_div * icovert[a][2]; eva[a] = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); - BMO_elem_flag_enable(bm, eva[a], VERT_MARK); + BMO_vert_flag_enable(bm, eva[a], VERT_MARK); } for (a = 0; a < 20; a++) { @@ -507,10 +507,10 @@ void bmo_create_icosphere_exec(BMesh *bm, BMOperator *op) eftemp = BM_face_create_quad_tri(bm, v1, v2, v3, NULL, NULL, BM_CREATE_NOP); BM_ITER_ELEM (l, &liter, eftemp, BM_LOOPS_OF_FACE) { - BMO_elem_flag_enable(bm, l->e, EDGE_MARK); + BMO_edge_flag_enable(bm, l->e, EDGE_MARK); } - BMO_elem_flag_enable(bm, eftemp, FACE_MARK); + BMO_face_flag_enable(bm, eftemp, FACE_MARK); } if (subdiv > 1) { @@ -540,14 +540,14 @@ void bmo_create_icosphere_exec(BMesh *bm, BMOperator *op) bool valid = true; BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { - if (!BMO_elem_flag_test(bm, l->v, VERT_MARK)) { + if (!BMO_vert_flag_test(bm, l->v, VERT_MARK)) { valid = false; break; } } if (valid) { - BMO_elem_flag_enable(bm, f, FACE_MARK); + BMO_face_flag_enable(bm, f, FACE_MARK); } } @@ -556,7 +556,7 @@ void bmo_create_icosphere_exec(BMesh *bm, BMOperator *op) /* must transform after because of sphere subdivision */ BM_ITER_MESH (v, &viter, bm, BM_VERTS_OF_MESH) { - if (BMO_elem_flag_test(bm, v, VERT_MARK)) { + if (BMO_vert_flag_test(bm, v, VERT_MARK)) { mul_m4_v3(mat, v->co); } } @@ -626,7 +626,7 @@ void BM_mesh_calc_uvs_sphere(BMesh *bm, const short oflag) BLI_assert(cd_loop_uv_offset != -1); /* caller is responsible for giving us UVs */ BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { - if (!BMO_elem_flag_test(bm, f, oflag)) + if (!BMO_face_flag_test(bm, f, oflag)) continue; bm_mesh_calc_uvs_sphere_face(f, mat_rot, cd_loop_uv_offset); @@ -650,7 +650,7 @@ void bmo_create_monkey_exec(BMesh *bm, BMOperator *op) v[1] = monkeyv[i][2] / -128.0; tv[i] = BM_vert_create(bm, v, NULL, BM_CREATE_NOP); - BMO_elem_flag_enable(bm, tv[i], VERT_MARK); + BMO_vert_flag_enable(bm, tv[i], VERT_MARK); if (fabsf(v[0] = -v[0]) < 0.001f) { tv[monkeynv + i] = tv[i]; @@ -661,7 +661,7 @@ void bmo_create_monkey_exec(BMesh *bm, BMOperator *op) tv[monkeynv + i] = eve; } - BMO_elem_flag_enable(bm, tv[monkeynv + i], VERT_MARK); + BMO_vert_flag_enable(bm, tv[monkeynv + i], VERT_MARK); mul_m4_v3(mat, tv[i]->co); } @@ -713,7 +713,7 @@ void bmo_create_circle_exec(BMesh *bm, BMOperator *op) mul_m4_v3(mat, vec); cent1 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); - BMO_elem_flag_enable(bm, cent1, VERT_MARK); + BMO_vert_flag_enable(bm, cent1, VERT_MARK); } for (a = 0; a < segs; a++, phi += phid) { @@ -724,7 +724,7 @@ void bmo_create_circle_exec(BMesh *bm, BMOperator *op) mul_m4_v3(mat, vec); v1 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); - BMO_elem_flag_enable(bm, v1, VERT_MARK); + BMO_vert_flag_enable(bm, v1, VERT_MARK); if (lastv1) BM_edge_create(bm, v1, lastv1, NULL, BM_CREATE_NOP); @@ -733,7 +733,7 @@ void bmo_create_circle_exec(BMesh *bm, BMOperator *op) BMFace *f; f = BM_face_create_quad_tri(bm, cent1, lastv1, v1, NULL, NULL, BM_CREATE_NOP); - BMO_elem_flag_enable(bm, f, FACE_NEW); + BMO_face_flag_enable(bm, f, FACE_NEW); } if (!firstv1) @@ -751,7 +751,7 @@ void bmo_create_circle_exec(BMesh *bm, BMOperator *op) BMFace *f; f = BM_face_create_quad_tri(bm, cent1, v1, firstv1, NULL, NULL, BM_CREATE_NOP); - BMO_elem_flag_enable(bm, f, FACE_NEW); + BMO_face_flag_enable(bm, f, FACE_NEW); if (calc_uvs) { BM_mesh_calc_uvs_circle(bm, mat, dia, FACE_NEW); @@ -791,7 +791,7 @@ void BM_mesh_calc_uvs_circle(BMesh *bm, float mat[4][4], const float radius, con invert_m4_m4(inv_mat, mat); BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { - if (!BMO_elem_flag_test(bm, f, oflag)) + if (!BMO_face_flag_test(bm, f, oflag)) continue; BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { @@ -845,8 +845,8 @@ void bmo_create_cone_exec(BMesh *bm, BMOperator *op) cent2 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); - BMO_elem_flag_enable(bm, cent1, VERT_MARK); - BMO_elem_flag_enable(bm, cent2, VERT_MARK); + BMO_vert_flag_enable(bm, cent1, VERT_MARK); + BMO_vert_flag_enable(bm, cent2, VERT_MARK); } for (a = 0; a < segs; a++, phi += phid) { @@ -862,27 +862,27 @@ void bmo_create_cone_exec(BMesh *bm, BMOperator *op) mul_m4_v3(mat, vec); v2 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); - BMO_elem_flag_enable(bm, v1, VERT_MARK); - BMO_elem_flag_enable(bm, v2, VERT_MARK); + BMO_vert_flag_enable(bm, v1, VERT_MARK); + BMO_vert_flag_enable(bm, v2, VERT_MARK); if (a) { if (cap_ends) { f = BM_face_create_quad_tri(bm, cent1, lastv1, v1, NULL, NULL, BM_CREATE_NOP); if (calc_uvs) { - BMO_elem_flag_enable(bm, f, FACE_MARK); + BMO_face_flag_enable(bm, f, FACE_MARK); } - BMO_elem_flag_enable(bm, f, FACE_NEW); + BMO_face_flag_enable(bm, f, FACE_NEW); f = BM_face_create_quad_tri(bm, cent2, v2, lastv2, NULL, NULL, BM_CREATE_NOP); if (calc_uvs) { - BMO_elem_flag_enable(bm, f, FACE_MARK); + BMO_face_flag_enable(bm, f, FACE_MARK); } - BMO_elem_flag_enable(bm, f, FACE_NEW); + BMO_face_flag_enable(bm, f, FACE_NEW); } f = BM_face_create_quad_tri(bm, lastv1, lastv2, v2, v1, NULL, BM_CREATE_NOP); if (calc_uvs) { - BMO_elem_flag_enable(bm, f, FACE_MARK); + BMO_face_flag_enable(bm, f, FACE_MARK); } } else { @@ -900,20 +900,20 @@ void bmo_create_cone_exec(BMesh *bm, BMOperator *op) if (cap_ends) { f = BM_face_create_quad_tri(bm, cent1, v1, firstv1, NULL, NULL, BM_CREATE_NOP); if (calc_uvs) { - BMO_elem_flag_enable(bm, f, FACE_MARK); + BMO_face_flag_enable(bm, f, FACE_MARK); } - BMO_elem_flag_enable(bm, f, FACE_NEW); + BMO_face_flag_enable(bm, f, FACE_NEW); f = BM_face_create_quad_tri(bm, cent2, firstv2, v2, NULL, NULL, BM_CREATE_NOP); if (calc_uvs) { - BMO_elem_flag_enable(bm, f, FACE_MARK); + BMO_face_flag_enable(bm, f, FACE_MARK); } - BMO_elem_flag_enable(bm, f, FACE_NEW); + BMO_face_flag_enable(bm, f, FACE_NEW); } f = BM_face_create_quad_tri(bm, v1, v2, firstv2, firstv1, NULL, BM_CREATE_NOP); if (calc_uvs) { - BMO_elem_flag_enable(bm, f, FACE_MARK); + BMO_face_flag_enable(bm, f, FACE_MARK); } if (calc_uvs) { @@ -981,7 +981,7 @@ void BM_mesh_calc_uvs_cone( y = 1.0f - uv_height; BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { - if (!BMO_elem_flag_test(bm, f, oflag)) + if (!BMO_face_flag_test(bm, f, oflag)) continue; if (f->len == 4 && radius_top && radius_bottom) { @@ -1063,7 +1063,7 @@ void bmo_create_cube_exec(BMesh *bm, BMOperator *op) float vec[3] = {(float)x * off, (float)y * off, (float)z * off}; mul_m4_v3(mat, vec); verts[i] = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); - BMO_elem_flag_enable(bm, verts[i], VERT_MARK); + BMO_vert_flag_enable(bm, verts[i], VERT_MARK); i++; } } @@ -1080,7 +1080,7 @@ void bmo_create_cube_exec(BMesh *bm, BMOperator *op) f = BM_face_create_verts(bm, quad, 4, NULL, BM_CREATE_NOP, true); if (calc_uvs) { - BMO_elem_flag_enable(bm, f, FACE_MARK); + BMO_face_flag_enable(bm, f, FACE_MARK); } } @@ -1117,7 +1117,7 @@ void BM_mesh_calc_uvs_cube(BMesh *bm, const short oflag) BLI_assert(cd_loop_uv_offset != -1); /* the caller can ensure that we have UVs */ BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { - if (!BMO_elem_flag_test(bm, f, oflag)) { + if (!BMO_face_flag_test(bm, f, oflag)) { continue; } diff --git a/source/blender/bmesh/operators/bmo_removedoubles.c b/source/blender/bmesh/operators/bmo_removedoubles.c index c58b4814726..6da591b23a0 100644 --- a/source/blender/bmesh/operators/bmo_removedoubles.c +++ b/source/blender/bmesh/operators/bmo_removedoubles.c @@ -98,7 +98,7 @@ static BMFace *remdoubles_createface(BMesh *bm, BMFace *f, BMOpSlot *slot_target { #define LOOP_MAP_VERT_INIT(l_init, v_map, is_del) \ v_map = l_init->v; \ - is_del = BMO_elem_flag_test_bool(bm, v_map, ELE_DEL); \ + is_del = BMO_vert_flag_test_bool(bm, v_map, ELE_DEL); \ if (is_del) { \ v_map = BMO_slot_map_elem_get(slot_targetmap, v_map); \ } ((void)0) @@ -131,12 +131,12 @@ static BMFace *remdoubles_createface(BMesh *bm, BMFace *f, BMOpSlot *slot_target } if (e_new) { - if (UNLIKELY(BMO_elem_flag_test(bm, v_curr, VERT_IN_FACE))) { + if (UNLIKELY(BMO_vert_flag_test(bm, v_curr, VERT_IN_FACE))) { /* we can't make the face, bail out */ STACK_CLEAR(edges); goto finally; } - BMO_elem_flag_enable(bm, v_curr, VERT_IN_FACE); + BMO_vert_flag_enable(bm, v_curr, VERT_IN_FACE); STACK_PUSH(edges, e_new); STACK_PUSH(loops, l_curr); @@ -155,7 +155,7 @@ finally: { unsigned int i; for (i = 0; i < STACK_SIZE(verts); i++) { - BMO_elem_flag_disable(bm, verts[i], VERT_IN_FACE); + BMO_vert_flag_disable(bm, verts[i], VERT_IN_FACE); } } @@ -198,7 +198,7 @@ void bmo_weld_verts_exec(BMesh *bm, BMOperator *op) /* mark merge verts for deletion */ BM_ITER_MESH (v1, &iter, bm, BM_VERTS_OF_MESH) { if ((v2 = BMO_slot_map_elem_get(slot_targetmap, v1))) { - BMO_elem_flag_enable(bm, v1, ELE_DEL); + BMO_vert_flag_enable(bm, v1, ELE_DEL); /* merge the vertex flags, else we get randomly selected/unselected verts */ BM_elem_flag_merge(v1, v2); @@ -212,8 +212,8 @@ void bmo_weld_verts_exec(BMesh *bm, BMOperator *op) } BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { - const bool is_del_v1 = BMO_elem_flag_test_bool(bm, (v1 = e->v1), ELE_DEL); - const bool is_del_v2 = BMO_elem_flag_test_bool(bm, (v2 = e->v2), ELE_DEL); + const bool is_del_v1 = BMO_vert_flag_test_bool(bm, (v1 = e->v1), ELE_DEL); + const bool is_del_v2 = BMO_vert_flag_test_bool(bm, (v2 = e->v2), ELE_DEL); if (is_del_v1 || is_del_v2) { if (is_del_v1) @@ -222,7 +222,7 @@ void bmo_weld_verts_exec(BMesh *bm, BMOperator *op) v2 = BMO_slot_map_elem_get(slot_targetmap, v2); if (v1 == v2) { - BMO_elem_flag_enable(bm, e, EDGE_COL); + BMO_edge_flag_enable(bm, e, EDGE_COL); } else { /* always merge flags, even for edges we already created */ @@ -233,7 +233,7 @@ void bmo_weld_verts_exec(BMesh *bm, BMOperator *op) BM_elem_flag_merge(e_new, e); } - BMO_elem_flag_enable(bm, e, ELE_DEL); + BMO_edge_flag_enable(bm, e, ELE_DEL); } } @@ -244,16 +244,16 @@ void bmo_weld_verts_exec(BMesh *bm, BMOperator *op) int edge_collapse = 0; BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { - if (BMO_elem_flag_test(bm, l->v, ELE_DEL)) { + if (BMO_vert_flag_test(bm, l->v, ELE_DEL)) { vert_delete = true; } - if (BMO_elem_flag_test(bm, l->e, EDGE_COL)) { + if (BMO_edge_flag_test(bm, l->e, EDGE_COL)) { edge_collapse++; } } if (vert_delete) { - BMO_elem_flag_enable(bm, f, ELE_DEL); + BMO_face_flag_enable(bm, f, ELE_DEL); if (f->len - edge_collapse >= 3) { BMFace *f_new = remdoubles_createface(bm, f, slot_targetmap); @@ -261,8 +261,12 @@ void bmo_weld_verts_exec(BMesh *bm, BMOperator *op) /* do this so we don't need to return a list of created faces */ if (f_new) { bmesh_face_swap_data(f_new, f); - SWAP(BMFlagLayer *, f->oflags, f_new->oflags); - BMO_elem_flag_disable(bm, f, ELE_DEL); + + if (bm->use_toolflags) { + SWAP(BMFlagLayer *, ((BMFace_OFlag *)f)->oflags, ((BMFace_OFlag *)f_new)->oflags); + } + + BMO_face_flag_disable(bm, f, ELE_DEL); BM_face_kill(bm, f_new); } @@ -439,7 +443,7 @@ void bmo_collapse_exec(BMesh *bm, BMOperator *op) float min[3], max[3], center[3]; BMVert *v_tar; - if (!BMO_elem_flag_test(bm, e, EDGE_MARK)) + if (!BMO_edge_flag_test(bm, e, EDGE_MARK)) continue; BLI_assert(BLI_stack_is_empty(edge_stack)); @@ -510,7 +514,7 @@ static void bmo_collapsecon_do_layer(BMesh *bm, const int layer, const short ofl BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { - if (BMO_elem_flag_test(bm, l->e, oflag)) { + if (BMO_edge_flag_test(bm, l->e, oflag)) { /* walk */ BLI_assert(BLI_stack_is_empty(block_stack)); @@ -606,7 +610,7 @@ static void bmesh_find_doubles_common( for (i = 0; i < verts_len; i++) { BMVert *v_check = verts[i]; - if (BMO_elem_flag_test(bm, v_check, VERT_DOUBLE | VERT_TARGET)) { + if (BMO_vert_flag_test(bm, v_check, VERT_DOUBLE | VERT_TARGET)) { continue; } @@ -614,7 +618,7 @@ static void bmesh_find_doubles_common( BMVert *v_other = verts[j]; /* a match has already been found, (we could check which is best, for now don't) */ - if (BMO_elem_flag_test(bm, v_other, VERT_DOUBLE | VERT_TARGET)) { + if (BMO_vert_flag_test(bm, v_other, VERT_DOUBLE | VERT_TARGET)) { continue; } @@ -628,19 +632,19 @@ static void bmesh_find_doubles_common( } if (keepvert) { - if (BMO_elem_flag_test(bm, v_other, VERT_KEEP) == BMO_elem_flag_test(bm, v_check, VERT_KEEP)) + if (BMO_vert_flag_test(bm, v_other, VERT_KEEP) == BMO_vert_flag_test(bm, v_check, VERT_KEEP)) continue; } if (compare_len_squared_v3v3(v_check->co, v_other->co, dist_sq)) { /* If one vert is marked as keep, make sure it will be the target */ - if (BMO_elem_flag_test(bm, v_other, VERT_KEEP)) { + if (BMO_vert_flag_test(bm, v_other, VERT_KEEP)) { SWAP(BMVert *, v_check, v_other); } - BMO_elem_flag_enable(bm, v_other, VERT_DOUBLE); - BMO_elem_flag_enable(bm, v_check, VERT_TARGET); + BMO_vert_flag_enable(bm, v_other, VERT_DOUBLE); + BMO_vert_flag_enable(bm, v_check, VERT_TARGET); BMO_slot_map_elem_insert(optarget, optarget_slot, v_other, v_check); } @@ -683,8 +687,8 @@ void bmo_automerge_exec(BMesh *bm, BMOperator *op) * as VERT_KEEP. */ BMO_slot_buffer_flag_enable(bm, op->slots_in, "verts", BM_VERT, VERT_IN); BM_ITER_MESH (v, &viter, bm, BM_VERTS_OF_MESH) { - if (!BMO_elem_flag_test(bm, v, VERT_IN)) { - BMO_elem_flag_enable(bm, v, VERT_KEEP); + if (!BMO_vert_flag_test(bm, v, VERT_IN)) { + BMO_vert_flag_enable(bm, v, VERT_KEEP); } } diff --git a/source/blender/bmesh/operators/bmo_similar.c b/source/blender/bmesh/operators/bmo_similar.c index 708d57a7a08..454d6d8c6c8 100644 --- a/source/blender/bmesh/operators/bmo_similar.c +++ b/source/blender/bmesh/operators/bmo_similar.c @@ -121,8 +121,8 @@ void bmo_similar_faces_exec(BMesh *bm, BMOperator *op) * and n is the total number of faces */ BMO_ITER (fs, &fs_iter, op->slots_in, "faces", BM_FACE) { - if (!BMO_elem_flag_test(bm, fs, FACE_MARK)) { /* is this really needed ? */ - BMO_elem_flag_enable(bm, fs, FACE_MARK); + if (!BMO_face_flag_test(bm, fs, FACE_MARK)) { /* is this really needed ? */ + BMO_face_flag_enable(bm, fs, FACE_MARK); num_sels++; } } @@ -134,7 +134,7 @@ void bmo_similar_faces_exec(BMesh *bm, BMOperator *op) /* loop through all the faces and fill the faces/indices structure */ BM_ITER_MESH (fm, &fm_iter, bm, BM_FACES_OF_MESH) { f_ext[i].f = fm; - if (BMO_elem_flag_test(bm, fm, FACE_MARK)) { + if (BMO_face_flag_test(bm, fm, FACE_MARK)) { indices[idx] = i; idx++; } @@ -179,21 +179,21 @@ void bmo_similar_faces_exec(BMesh *bm, BMOperator *op) /* now select the rest (if any) */ for (i = 0; i < num_total; i++) { fm = f_ext[i].f; - if (!BMO_elem_flag_test(bm, fm, FACE_MARK) && !BM_elem_flag_test(fm, BM_ELEM_HIDDEN)) { + if (!BMO_face_flag_test(bm, fm, FACE_MARK) && !BM_elem_flag_test(fm, BM_ELEM_HIDDEN)) { bool cont = true; for (idx = 0; idx < num_sels && cont == true; idx++) { fs = f_ext[indices[idx]].f; switch (type) { case SIMFACE_MATERIAL: if (fm->mat_nr == fs->mat_nr) { - BMO_elem_flag_enable(bm, fm, FACE_MARK); + BMO_face_flag_enable(bm, fm, FACE_MARK); cont = false; } break; case SIMFACE_IMAGE: if (f_ext[i].t == f_ext[indices[idx]].t) { - BMO_elem_flag_enable(bm, fm, FACE_MARK); + BMO_face_flag_enable(bm, fm, FACE_MARK); cont = false; } break; @@ -201,7 +201,7 @@ void bmo_similar_faces_exec(BMesh *bm, BMOperator *op) case SIMFACE_NORMAL: angle = angle_normalized_v3v3(fs->no, fm->no); /* if the angle between the normals -> 0 */ if (angle <= thresh_radians) { - BMO_elem_flag_enable(bm, fm, FACE_MARK); + BMO_face_flag_enable(bm, fm, FACE_MARK); cont = false; } break; @@ -218,7 +218,7 @@ void bmo_similar_faces_exec(BMesh *bm, BMOperator *op) if (angle <= thresh_radians) { /* and dot product difference -> 0 */ delta_fl = f_ext[i].d - (f_ext[indices[idx]].d * sign); if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) { - BMO_elem_flag_enable(bm, fm, FACE_MARK); + BMO_face_flag_enable(bm, fm, FACE_MARK); cont = false; } } @@ -227,7 +227,7 @@ void bmo_similar_faces_exec(BMesh *bm, BMOperator *op) case SIMFACE_AREA: delta_fl = f_ext[i].area - f_ext[indices[idx]].area; if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) { - BMO_elem_flag_enable(bm, fm, FACE_MARK); + BMO_face_flag_enable(bm, fm, FACE_MARK); cont = false; } break; @@ -235,7 +235,7 @@ void bmo_similar_faces_exec(BMesh *bm, BMOperator *op) case SIMFACE_SIDES: delta_i = fm->len - fs->len; if (bm_sel_similar_cmp_i(delta_i, compare)) { - BMO_elem_flag_enable(bm, fm, FACE_MARK); + BMO_face_flag_enable(bm, fm, FACE_MARK); cont = false; } break; @@ -243,14 +243,14 @@ void bmo_similar_faces_exec(BMesh *bm, BMOperator *op) case SIMFACE_PERIMETER: delta_fl = f_ext[i].perim - f_ext[indices[idx]].perim; if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) { - BMO_elem_flag_enable(bm, fm, FACE_MARK); + BMO_face_flag_enable(bm, fm, FACE_MARK); cont = false; } break; case SIMFACE_SMOOTH: if (BM_elem_flag_test(fm, BM_ELEM_SMOOTH) == BM_elem_flag_test(fs, BM_ELEM_SMOOTH)) { - BMO_elem_flag_enable(bm, fm, FACE_MARK); + BMO_face_flag_enable(bm, fm, FACE_MARK); cont = false; } break; @@ -263,7 +263,7 @@ void bmo_similar_faces_exec(BMesh *bm, BMOperator *op) ffa2 = CustomData_bmesh_get(&bm->pdata, fm->head.data, CD_FREESTYLE_FACE); if (ffa1 && ffa2 && (ffa1->flag & FREESTYLE_FACE_MARK) == (ffa2->flag & FREESTYLE_FACE_MARK)) { - BMO_elem_flag_enable(bm, fm, FACE_MARK); + BMO_face_flag_enable(bm, fm, FACE_MARK); cont = false; } } @@ -350,7 +350,7 @@ void bmo_similar_edges_exec(BMesh *bm, BMOperator *op) /* iterate through all selected edges and mark them */ BMO_ITER (es, &es_iter, op->slots_in, "edges", BM_EDGE) { - BMO_elem_flag_enable(bm, es, EDGE_MARK); + BMO_edge_flag_enable(bm, es, EDGE_MARK); num_sels++; } @@ -361,7 +361,7 @@ void bmo_similar_edges_exec(BMesh *bm, BMOperator *op) /* loop through all the edges and fill the edges/indices structure */ BM_ITER_MESH (e, &e_iter, bm, BM_EDGES_OF_MESH) { e_ext[i].e = e; - if (BMO_elem_flag_test(bm, e, EDGE_MARK)) { + if (BMO_edge_flag_test(bm, e, EDGE_MARK)) { indices[idx] = i; idx++; } @@ -397,7 +397,9 @@ void bmo_similar_edges_exec(BMesh *bm, BMOperator *op) /* select the edges if any */ for (i = 0; i < num_total; i++) { e = e_ext[i].e; - if (!BMO_elem_flag_test(bm, e, EDGE_MARK) && !BM_elem_flag_test(e, BM_ELEM_HIDDEN)) { + if (!BMO_edge_flag_test(bm, e, EDGE_MARK) && + !BM_elem_flag_test(e, BM_ELEM_HIDDEN)) + { bool cont = true; for (idx = 0; idx < num_sels && cont == true; idx++) { es = e_ext[indices[idx]].e; @@ -405,7 +407,7 @@ void bmo_similar_edges_exec(BMesh *bm, BMOperator *op) case SIMEDGE_LENGTH: delta_fl = e_ext[i].length - e_ext[indices[idx]].length; if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) { - BMO_elem_flag_enable(bm, e, EDGE_MARK); + BMO_edge_flag_enable(bm, e, EDGE_MARK); cont = false; } break; @@ -418,7 +420,7 @@ void bmo_similar_edges_exec(BMesh *bm, BMOperator *op) angle = fabsf(angle - (float)M_PI); if (angle / (float)M_PI_2 <= thresh) { - BMO_elem_flag_enable(bm, e, EDGE_MARK); + BMO_edge_flag_enable(bm, e, EDGE_MARK); cont = false; } break; @@ -426,7 +428,7 @@ void bmo_similar_edges_exec(BMesh *bm, BMOperator *op) case SIMEDGE_FACE: delta_i = e_ext[i].faces - e_ext[indices[idx]].faces; if (bm_sel_similar_cmp_i(delta_i, compare)) { - BMO_elem_flag_enable(bm, e, EDGE_MARK); + BMO_edge_flag_enable(bm, e, EDGE_MARK); cont = false; } break; @@ -435,7 +437,7 @@ void bmo_similar_edges_exec(BMesh *bm, BMOperator *op) if (e_ext[i].faces == 2) { if (e_ext[indices[idx]].faces == 2) { if (fabsf(e_ext[i].angle - e_ext[indices[idx]].angle) <= thresh) { - BMO_elem_flag_enable(bm, e, EDGE_MARK); + BMO_edge_flag_enable(bm, e, EDGE_MARK); cont = false; } } @@ -454,7 +456,7 @@ void bmo_similar_edges_exec(BMesh *bm, BMOperator *op) delta_fl = *c1 - *c2; if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) { - BMO_elem_flag_enable(bm, e, EDGE_MARK); + BMO_edge_flag_enable(bm, e, EDGE_MARK); cont = false; } } @@ -469,7 +471,7 @@ void bmo_similar_edges_exec(BMesh *bm, BMOperator *op) delta_fl = *c1 - *c2; if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) { - BMO_elem_flag_enable(bm, e, EDGE_MARK); + BMO_edge_flag_enable(bm, e, EDGE_MARK); cont = false; } } @@ -477,14 +479,14 @@ void bmo_similar_edges_exec(BMesh *bm, BMOperator *op) case SIMEDGE_SEAM: if (BM_elem_flag_test(e, BM_ELEM_SEAM) == BM_elem_flag_test(es, BM_ELEM_SEAM)) { - BMO_elem_flag_enable(bm, e, EDGE_MARK); + BMO_edge_flag_enable(bm, e, EDGE_MARK); cont = false; } break; case SIMEDGE_SHARP: if (BM_elem_flag_test(e, BM_ELEM_SMOOTH) == BM_elem_flag_test(es, BM_ELEM_SMOOTH)) { - BMO_elem_flag_enable(bm, e, EDGE_MARK); + BMO_edge_flag_enable(bm, e, EDGE_MARK); cont = false; } break; @@ -497,7 +499,7 @@ void bmo_similar_edges_exec(BMesh *bm, BMOperator *op) fed2 = CustomData_bmesh_get(&bm->edata, es->head.data, CD_FREESTYLE_EDGE); if (fed1 && fed2 && (fed1->flag & FREESTYLE_EDGE_MARK) == (fed2->flag & FREESTYLE_EDGE_MARK)) { - BMO_elem_flag_enable(bm, e, EDGE_MARK); + BMO_edge_flag_enable(bm, e, EDGE_MARK); cont = false; } } @@ -562,7 +564,7 @@ void bmo_similar_verts_exec(BMesh *bm, BMOperator *op) /* iterate through all selected edges and mark them */ BMO_ITER (vs, &vs_iter, op->slots_in, "verts", BM_VERT) { - BMO_elem_flag_enable(bm, vs, VERT_MARK); + BMO_vert_flag_enable(bm, vs, VERT_MARK); num_sels++; } @@ -573,7 +575,7 @@ void bmo_similar_verts_exec(BMesh *bm, BMOperator *op) /* loop through all the vertices and fill the vertices/indices structure */ BM_ITER_MESH (v, &v_iter, bm, BM_VERTS_OF_MESH) { v_ext[i].v = v; - if (BMO_elem_flag_test(bm, v, VERT_MARK)) { + if (BMO_vert_flag_test(bm, v, VERT_MARK)) { indices[idx] = i; idx++; } @@ -599,7 +601,9 @@ void bmo_similar_verts_exec(BMesh *bm, BMOperator *op) /* select the vertices if any */ for (i = 0; i < num_total; i++) { v = v_ext[i].v; - if (!BMO_elem_flag_test(bm, v, VERT_MARK) && !BM_elem_flag_test(v, BM_ELEM_HIDDEN)) { + if (!BMO_vert_flag_test(bm, v, VERT_MARK) && + !BM_elem_flag_test(v, BM_ELEM_HIDDEN)) + { bool cont = true; for (idx = 0; idx < num_sels && cont == true; idx++) { vs = v_ext[indices[idx]].v; @@ -607,7 +611,7 @@ void bmo_similar_verts_exec(BMesh *bm, BMOperator *op) case SIMVERT_NORMAL: /* compare the angle between the normals */ if (angle_normalized_v3v3(v->no, vs->no) <= thresh_radians) { - BMO_elem_flag_enable(bm, v, VERT_MARK); + BMO_vert_flag_enable(bm, v, VERT_MARK); cont = false; } break; @@ -615,7 +619,7 @@ void bmo_similar_verts_exec(BMesh *bm, BMOperator *op) /* number of adjacent faces */ delta_i = v_ext[i].num_faces - v_ext[indices[idx]].num_faces; if (bm_sel_similar_cmp_i(delta_i, compare)) { - BMO_elem_flag_enable(bm, v, VERT_MARK); + BMO_vert_flag_enable(bm, v, VERT_MARK); cont = false; } break; @@ -623,7 +627,7 @@ void bmo_similar_verts_exec(BMesh *bm, BMOperator *op) case SIMVERT_VGROUP: if (v_ext[i].dvert != NULL && v_ext[indices[idx]].dvert != NULL) { if (defvert_find_shared(v_ext[i].dvert, v_ext[indices[idx]].dvert) != -1) { - BMO_elem_flag_enable(bm, v, VERT_MARK); + BMO_vert_flag_enable(bm, v, VERT_MARK); cont = false; } } @@ -632,7 +636,7 @@ void bmo_similar_verts_exec(BMesh *bm, BMOperator *op) /* number of adjacent edges */ delta_i = v_ext[i].num_edges - v_ext[indices[idx]].num_edges; if (bm_sel_similar_cmp_i(delta_i, compare)) { - BMO_elem_flag_enable(bm, v, VERT_MARK); + BMO_vert_flag_enable(bm, v, VERT_MARK); cont = false; } break; diff --git a/source/blender/bmesh/operators/bmo_subdivide.c b/source/blender/bmesh/operators/bmo_subdivide.c index 38fa2cfdcc8..8d672b32caa 100644 --- a/source/blender/bmesh/operators/bmo_subdivide.c +++ b/source/blender/bmesh/operators/bmo_subdivide.c @@ -384,7 +384,7 @@ static BMVert *bm_subdivide_edge_addvert( v_new = BM_edge_split(bm, edge, edge->v1, r_edge, factor_edge_split); - BMO_elem_flag_enable(bm, v_new, ELE_INNER); + BMO_vert_flag_enable(bm, v_new, ELE_INNER); /* offset for smooth or sphere or fractal */ alter_co(v_new, e_orig, params, factor_subd, v_a, v_b); @@ -419,7 +419,7 @@ static BMVert *subdivide_edge_num( BMVert *v_new; float factor_edge_split, factor_subd; - if (BMO_elem_flag_test(bm, edge, EDGE_PERCENT) && totpoint == 1) { + if (BMO_edge_flag_test(bm, edge, EDGE_PERCENT) && totpoint == 1) { factor_edge_split = BMO_slot_map_float_get(params->slot_edge_percents, edge); factor_subd = 0.0f; } @@ -449,9 +449,9 @@ static void bm_subdivide_multicut( for (i = 0; i < numcuts; i++) { v = subdivide_edge_num(bm, eed, &e_tmp, i, params->numcuts, params, v_a, v_b, &e_new); - BMO_elem_flag_enable(bm, v, SUBD_SPLIT | ELE_SPLIT); - BMO_elem_flag_enable(bm, eed, SUBD_SPLIT | ELE_SPLIT); - BMO_elem_flag_enable(bm, e_new, SUBD_SPLIT | ELE_SPLIT); + BMO_vert_flag_enable(bm, v, SUBD_SPLIT | ELE_SPLIT); + BMO_edge_flag_enable(bm, eed, SUBD_SPLIT | ELE_SPLIT); + BMO_edge_flag_enable(bm, e_new, SUBD_SPLIT | ELE_SPLIT); BM_CHECK_ELEMENT(v); if (v->e) BM_CHECK_ELEMENT(v->e); @@ -698,8 +698,8 @@ static void quad_4edge_subdivide(BMesh *bm, BMFace *UNUSED(face), BMVert **verts if (!e) continue; - BMO_elem_flag_enable(bm, e, ELE_INNER); - BMO_elem_flag_enable(bm, f_new, ELE_INNER); + BMO_edge_flag_enable(bm, e, ELE_INNER); + BMO_face_flag_enable(bm, f_new, ELE_INNER); v1 = lines[(i + 1) * s] = verts[a]; @@ -711,7 +711,7 @@ static void quad_4edge_subdivide(BMesh *bm, BMFace *UNUSED(face), BMVert **verts BMESH_ASSERT(v != NULL); - BMO_elem_flag_enable(bm, e_new, ELE_INNER); + BMO_edge_flag_enable(bm, e_new, ELE_INNER); lines[(i + 1) * s + a + 1] = v; } } @@ -724,8 +724,8 @@ static void quad_4edge_subdivide(BMesh *bm, BMFace *UNUSED(face), BMVert **verts if (!e) continue; - BMO_elem_flag_enable(bm, e, ELE_INNER); - BMO_elem_flag_enable(bm, f_new, ELE_INNER); + BMO_edge_flag_enable(bm, e, ELE_INNER); + BMO_face_flag_enable(bm, f_new, ELE_INNER); } } @@ -802,8 +802,8 @@ static void tri_3edge_subdivide(BMesh *bm, BMFace *UNUSED(face), BMVert **verts, e = connect_smallest_face(bm, verts[a], verts[b], &f_new); if (!e) goto cleanup; - BMO_elem_flag_enable(bm, e, ELE_INNER); - BMO_elem_flag_enable(bm, f_new, ELE_INNER); + BMO_edge_flag_enable(bm, e, ELE_INNER); + BMO_face_flag_enable(bm, f_new, ELE_INNER); lines[i + 1][0] = verts[a]; lines[i + 1][i + 1] = verts[b]; @@ -817,7 +817,7 @@ static void tri_3edge_subdivide(BMesh *bm, BMFace *UNUSED(face), BMVert **verts, v = subdivide_edge_num(bm, e, &e_tmp, j, i, params, verts[a], verts[b], &e_new); lines[i + 1][j + 1] = v; - BMO_elem_flag_enable(bm, e_new, ELE_INNER); + BMO_edge_flag_enable(bm, e_new, ELE_INNER); } } @@ -837,13 +837,13 @@ static void tri_3edge_subdivide(BMesh *bm, BMFace *UNUSED(face), BMVert **verts, for (j = 0; j < i; j++) { e = connect_smallest_face(bm, lines[i][j], lines[i + 1][j + 1], &f_new); - BMO_elem_flag_enable(bm, e, ELE_INNER); - BMO_elem_flag_enable(bm, f_new, ELE_INNER); + BMO_edge_flag_enable(bm, e, ELE_INNER); + BMO_face_flag_enable(bm, f_new, ELE_INNER); e = connect_smallest_face(bm, lines[i][j + 1], lines[i + 1][j + 1], &f_new); - BMO_elem_flag_enable(bm, e, ELE_INNER); - BMO_elem_flag_enable(bm, f_new, ELE_INNER); + BMO_edge_flag_enable(bm, e, ELE_INNER); + BMO_face_flag_enable(bm, f_new, ELE_INNER); } } @@ -1023,7 +1023,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) edges[i] = l_new->e; verts[i] = l_new->v; - if (BMO_elem_flag_test(bm, edges[i], SUBD_SPLIT)) { + if (BMO_edge_flag_test(bm, edges[i], SUBD_SPLIT)) { if (!e1) e1 = edges[i]; else e2 = edges[i]; @@ -1043,13 +1043,13 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) } } - if (BMO_elem_flag_test(bm, face, FACE_CUSTOMFILL)) { + if (BMO_face_flag_test(bm, face, FACE_CUSTOMFILL)) { pat = *BMO_slot_map_data_get(params.slot_custom_patterns, face); for (i = 0; i < pat->len; i++) { matched = 1; for (j = 0; j < pat->len; j++) { a = (j + i) % pat->len; - if ((!!BMO_elem_flag_test(bm, edges[a], SUBD_SPLIT)) != (!!pat->seledges[j])) { + if ((!!BMO_edge_flag_test(bm, edges[a], SUBD_SPLIT)) != (!!pat->seledges[j])) { matched = 0; break; } @@ -1062,7 +1062,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) fd->start = verts[i]; fd->face = face; fd->totedgesel = totesel; - BMO_elem_flag_enable(bm, face, SUBD_SPLIT); + BMO_face_flag_enable(bm, face, SUBD_SPLIT); break; } } @@ -1082,7 +1082,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) matched = 1; for (b = 0; b < pat->len; b++) { j = (b + a) % pat->len; - if ((!!BMO_elem_flag_test(bm, edges[j], SUBD_SPLIT)) != (!!pat->seledges[b])) { + if ((!!BMO_edge_flag_test(bm, edges[j], SUBD_SPLIT)) != (!!pat->seledges[b])) { matched = 0; break; } @@ -1094,7 +1094,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) if (matched) { SubDFaceData *fd; - BMO_elem_flag_enable(bm, face, SUBD_SPLIT); + BMO_face_flag_enable(bm, face, SUBD_SPLIT); fd = BLI_stack_push_r(facedata); fd->pat = pat; @@ -1110,7 +1110,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) if (!matched && totesel) { SubDFaceData *fd; - BMO_elem_flag_enable(bm, face, SUBD_SPLIT); + BMO_face_flag_enable(bm, face, SUBD_SPLIT); /* must initialize all members here */ fd = BLI_stack_push_r(facedata); @@ -1162,22 +1162,22 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) /* find the boundary of one of the split edges */ for (a = 1; a < vlen; a++) { - if (!BMO_elem_flag_test(bm, loops[a - 1]->v, ELE_INNER) && - BMO_elem_flag_test(bm, loops[a]->v, ELE_INNER)) + if (!BMO_vert_flag_test(bm, loops[a - 1]->v, ELE_INNER) && + BMO_vert_flag_test(bm, loops[a]->v, ELE_INNER)) { break; } } - if (BMO_elem_flag_test(bm, loops[(a + numcuts + 1) % vlen]->v, ELE_INNER)) { + if (BMO_vert_flag_test(bm, loops[(a + numcuts + 1) % vlen]->v, ELE_INNER)) { b = (a + numcuts + 1) % vlen; } else { /* find the boundary of the other edge. */ for (j = 0; j < vlen; j++) { b = (j + a + numcuts + 1) % vlen; - if (!BMO_elem_flag_test(bm, loops[b == 0 ? vlen - 1 : b - 1]->v, ELE_INNER) && - BMO_elem_flag_test(bm, loops[b]->v, ELE_INNER)) + if (!BMO_vert_flag_test(bm, loops[b == 0 ? vlen - 1 : b - 1]->v, ELE_INNER) && + BMO_vert_flag_test(bm, loops[b]->v, ELE_INNER)) { break; } @@ -1245,7 +1245,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) BLI_assert(BM_edge_exists(loops_split[j][0]->v, loops_split[j][1]->v) == NULL); f_new = BM_face_split(bm, face, loops_split[j][0], loops_split[j][1], &l_new, NULL, false); if (f_new) { - BMO_elem_flag_enable(bm, l_new->e, ELE_INNER); + BMO_edge_flag_enable(bm, l_new->e, ELE_INNER); } } } diff --git a/source/blender/bmesh/operators/bmo_subdivide_edgering.c b/source/blender/bmesh/operators/bmo_subdivide_edgering.c index b5a95ad6283..b4a77bf1a38 100644 --- a/source/blender/bmesh/operators/bmo_subdivide_edgering.c +++ b/source/blender/bmesh/operators/bmo_subdivide_edgering.c @@ -128,7 +128,7 @@ static void bmo_edgeloop_vert_tag(BMesh *bm, struct BMEdgeLoopStore *el_store, c { LinkData *node = BM_edgeloop_verts_get(el_store)->first; do { - BMO_elem_flag_set(bm, (BMVert *)node->data, oflag, tag); + BMO_vert_flag_set(bm, (BMVert *)node->data, oflag, tag); } while ((node = node->next)); } @@ -137,7 +137,7 @@ static bool bmo_face_is_vert_tag_all(BMesh *bm, BMFace *f, short oflag) BMLoop *l_iter, *l_first; l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { - if (!BMO_elem_flag_test(bm, l_iter->v, oflag)) { + if (!BMO_vert_flag_test(bm, l_iter->v, oflag)) { return false; } } while ((l_iter = l_iter->next) != l_first); @@ -150,7 +150,7 @@ static bool bm_vert_is_tag_edge_connect(BMesh *bm, BMVert *v) BMEdge *e; BM_ITER_ELEM (e, &eiter, v, BM_EDGES_OF_VERT) { - if (BMO_elem_flag_test(bm, e, EDGE_RING)) { + if (BMO_edge_flag_test(bm, e, EDGE_RING)) { BMVert *v_other = BM_edge_other_vert(e, v); if (BM_elem_flag_test(v_other, BM_ELEM_TAG)) { return true; @@ -243,7 +243,7 @@ static GSet *bm_edgering_pair_calc(BMesh *bm, ListBase *eloops_rim) BMVert *v = ((LinkData *)BM_edgeloop_verts_get(el_store)->first)->data; BM_ITER_ELEM (e, &eiter, (BMVert *)v, BM_EDGES_OF_VERT) { - if (BMO_elem_flag_test(bm, e, EDGE_RING)) { + if (BMO_edge_flag_test(bm, e, EDGE_RING)) { struct BMEdgeLoopStore *el_store_other; BMVert *v_other = BM_edge_other_vert(e, v); GHashPair pair_test; @@ -339,7 +339,7 @@ static void bm_vert_calc_surface_tangent(BMesh *bm, BMVert *v, float r_no[3]) if (UNLIKELY(BM_edge_is_wire(e))) { /* pass - this may confuse things */ } - else if (BMO_elem_flag_test(bm, e, EDGE_RIM)) { + else if (BMO_edge_flag_test(bm, e, EDGE_RIM)) { BMIter liter; BMLoop *l; BM_ITER_ELEM (l, &liter, e, BM_LOOPS_OF_EDGE) { @@ -347,7 +347,7 @@ static void bm_vert_calc_surface_tangent(BMesh *bm, BMVert *v, float r_no[3]) float no[3]; // BM_face_normal_update(l->f); BM_edge_calc_face_tangent(e, l, no); - if (BMO_elem_flag_test(bm, l->f, FACE_SHARED)) { + if (BMO_face_flag_test(bm, l->f, FACE_SHARED)) { add_v3_v3(no_inner, no); found_inner = true; } @@ -356,7 +356,7 @@ static void bm_vert_calc_surface_tangent(BMesh *bm, BMVert *v, float r_no[3]) found_outer = true; /* other side is used too, blend midway */ - if (BMO_elem_flag_test(bm, l->f, FACE_OUT)) { + if (BMO_face_flag_test(bm, l->f, FACE_OUT)) { found_outer_tag = true; } } @@ -400,9 +400,9 @@ static void bm_faces_share_tag_flush(BMesh *bm, BMEdge **e_arr, const unsigned i l_iter = l_first = e->l; do { - if (!BMO_elem_flag_test(bm, l_iter->f, FACE_SHARED)) { + if (!BMO_face_flag_test(bm, l_iter->f, FACE_SHARED)) { if (bmo_face_is_vert_tag_all(bm, l_iter->f, VERT_SHARED)) { - BMO_elem_flag_enable(bm, l_iter->f, FACE_SHARED); + BMO_face_flag_enable(bm, l_iter->f, FACE_SHARED); } } } while ((l_iter = l_iter->radial_next) != l_first); @@ -422,7 +422,7 @@ static void bm_faces_share_tag_clear(BMesh *bm, BMEdge **e_arr_iter, const unsig l_iter = l_first = e->l; do { - BMO_elem_flag_disable(bm, l_iter->f, FACE_SHARED); + BMO_face_flag_disable(bm, l_iter->f, FACE_SHARED); } while ((l_iter = l_iter->radial_next) != l_first); } } @@ -834,8 +834,8 @@ static void bm_face_slice(BMesh *bm, BMLoop *l, const int cuts) if (l_new->f->len < l_new->radial_next->f->len) { l_new = l_new->radial_next; } - BMO_elem_flag_enable(bm, l_new->f, FACE_OUT); - BMO_elem_flag_enable(bm, l_new->radial_next->f, FACE_OUT); + BMO_face_flag_enable(bm, l_new->f, FACE_OUT); + BMO_face_flag_enable(bm, l_new->radial_next->f, FACE_OUT); } } @@ -903,7 +903,7 @@ static void bm_edgering_pair_order( node = lb_a->first; BM_ITER_ELEM (e, &eiter, (BMVert *)node->data, BM_EDGES_OF_VERT) { - if (BMO_elem_flag_test(bm, e, EDGE_RING)) { + if (BMO_edge_flag_test(bm, e, EDGE_RING)) { v_other = BM_edge_other_vert(e, (BMVert *)node->data); if (BM_elem_flag_test(v_other, BM_ELEM_TAG)) { break; @@ -938,7 +938,7 @@ static void bm_edgering_pair_order( /* if we dont share and edge - flip */ BMEdge *e = BM_edge_exists(((LinkData *)lb_a->first)->data, ((LinkData *)lb_b->first)->data); - if (e == NULL || !BMO_elem_flag_test(bm, e, EDGE_RING)) { + if (e == NULL || !BMO_edge_flag_test(bm, e, EDGE_RING)) { BM_edgeloop_flip(bm, el_store_b); } } @@ -983,19 +983,19 @@ static void bm_edgering_pair_subdiv( BMIter eiter; BM_ITER_ELEM (e, &eiter, (BMVert *)node->data, BM_EDGES_OF_VERT) { - if (!BMO_elem_flag_test(bm, e, EDGE_IN_STACK)) { + if (!BMO_edge_flag_test(bm, e, EDGE_IN_STACK)) { BMVert *v_other = BM_edge_other_vert(e, (BMVert *)node->data); if (BM_elem_flag_test(v_other, BM_ELEM_TAG)) { BMIter fiter; - BMO_elem_flag_enable(bm, e, EDGE_IN_STACK); + BMO_edge_flag_enable(bm, e, EDGE_IN_STACK); STACK_PUSH(edges_ring_arr, e); /* add faces to the stack */ BM_ITER_ELEM (f, &fiter, e, BM_FACES_OF_EDGE) { - if (BMO_elem_flag_test(bm, f, FACE_OUT)) { - if (!BMO_elem_flag_test(bm, f, FACE_IN_STACK)) { - BMO_elem_flag_enable(bm, f, FACE_IN_STACK); + if (BMO_face_flag_test(bm, f, FACE_OUT)) { + if (!BMO_face_flag_test(bm, f, FACE_IN_STACK)) { + BMO_face_flag_enable(bm, f, FACE_IN_STACK); STACK_PUSH(faces_ring_arr, f); } } @@ -1009,10 +1009,10 @@ static void bm_edgering_pair_subdiv( /* found opposite edge */ BMVert *v_other; - BMO_elem_flag_disable(bm, e, EDGE_IN_STACK); + BMO_edge_flag_disable(bm, e, EDGE_IN_STACK); /* unrelated to subdiv, but if we _don't_ clear flag, multiple rings fail */ - BMO_elem_flag_disable(bm, e, EDGE_RING); + BMO_edge_flag_disable(bm, e, EDGE_RING); v_other = BM_elem_flag_test(e->v1, BM_ELEM_TAG) ? e->v1 : e->v2; bm_edge_subdiv_as_loop(bm, eloops_ring, e, v_other, cuts); @@ -1021,12 +1021,12 @@ static void bm_edgering_pair_subdiv( while ((f = STACK_POP(faces_ring_arr))) { BMLoop *l_iter, *l_first; - BMO_elem_flag_disable(bm, f, FACE_IN_STACK); + BMO_face_flag_disable(bm, f, FACE_IN_STACK); /* Check each edge of the face */ l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { - if (BMO_elem_flag_test(bm, l_iter->e, EDGE_RIM)) { + if (BMO_edge_flag_test(bm, l_iter->e, EDGE_RIM)) { bm_face_slice(bm, l_iter, cuts); break; } @@ -1064,7 +1064,7 @@ static void bm_edgering_pair_ringsubd( static bool bm_edge_rim_test_cb(BMEdge *e, void *bm_v) { BMesh *bm = bm_v; - return BMO_elem_flag_test_bool(bm, e, EDGE_RIM); + return BMO_edge_flag_test_bool(bm, e, EDGE_RIM); } @@ -1099,25 +1099,25 @@ void bmo_subdivide_edgering_exec(BMesh *bm, BMOperator *op) BMFace *f; BM_ITER_ELEM (f, &fiter, e, BM_FACES_OF_EDGE) { - if (!BMO_elem_flag_test(bm, f, FACE_OUT)) { + if (!BMO_face_flag_test(bm, f, FACE_OUT)) { BMIter liter; BMLoop *l; bool ok = false; /* check at least 2 edges in the face are rings */ BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { - if (BMO_elem_flag_test(bm, l->e, EDGE_RING) && e != l->e) { + if (BMO_edge_flag_test(bm, l->e, EDGE_RING) && e != l->e) { ok = true; break; } } if (ok) { - BMO_elem_flag_enable(bm, f, FACE_OUT); + BMO_face_flag_enable(bm, f, FACE_OUT); BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { - if (!BMO_elem_flag_test(bm, l->e, EDGE_RING)) { - BMO_elem_flag_enable(bm, l->e, EDGE_RIM); + if (!BMO_edge_flag_test(bm, l->e, EDGE_RING)) { + BMO_edge_flag_enable(bm, l->e, EDGE_RIM); } } } diff --git a/source/blender/bmesh/operators/bmo_triangulate.c b/source/blender/bmesh/operators/bmo_triangulate.c index 974446f09c0..8938d086c1a 100644 --- a/source/blender/bmesh/operators/bmo_triangulate.c +++ b/source/blender/bmesh/operators/bmo_triangulate.c @@ -91,7 +91,7 @@ void bmo_triangle_fill_exec(BMesh *bm, BMOperator *op) BMVert **e_verts = &e->v1; unsigned int i; - BMO_elem_flag_enable(bm, e, EDGE_MARK); + BMO_edge_flag_enable(bm, e, EDGE_MARK); calc_winding = (calc_winding || BM_edge_is_boundary(e)); @@ -132,7 +132,7 @@ void bmo_triangle_fill_exec(BMesh *bm, BMOperator *op) add_v3_v3(normal, v->no); BM_ITER_ELEM (e, &eiter, v, BM_EDGES_OF_VERT) { - if (BMO_elem_flag_test(bm, e, EDGE_MARK)) { + if (BMO_edge_flag_test(bm, e, EDGE_MARK)) { if (e_index == 2) { e_index = 0; break; @@ -203,7 +203,7 @@ void bmo_triangle_fill_exec(BMesh *bm, BMOperator *op) for (i = 0, i_prev = 2; i < 3; i_prev = i++) { e = BM_edge_exists(v_tri[i], v_tri[i_prev]); - if (e && BM_edge_is_boundary(e) && BMO_elem_flag_test(bm, e, EDGE_MARK)) { + if (e && BM_edge_is_boundary(e) && BMO_edge_flag_test(bm, e, EDGE_MARK)) { winding_votes += (e->l->v == v_tri[i]) ? 1 : -1; } } @@ -226,10 +226,10 @@ void bmo_triangle_fill_exec(BMesh *bm, BMOperator *op) sf_tri->v1->tmp.p, sf_tri->v2->tmp.p, sf_tri->v3->tmp.p, NULL, NULL, BM_CREATE_NO_DOUBLE); - BMO_elem_flag_enable(bm, f, ELE_NEW); + BMO_face_flag_enable(bm, f, ELE_NEW); BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { - if (!BMO_elem_flag_test(bm, l->e, EDGE_MARK)) { - BMO_elem_flag_enable(bm, l->e, ELE_NEW); + if (!BMO_edge_flag_test(bm, l->e, EDGE_MARK)) { + BMO_edge_flag_enable(bm, l->e, ELE_NEW); } } } @@ -250,7 +250,7 @@ void bmo_triangle_fill_exec(BMesh *bm, BMOperator *op) BMIter iter; BM_ITER_MESH_MUTABLE (e, e_next, &iter, bm, BM_EDGES_OF_MESH) { - if (BMO_elem_flag_test(bm, e, ELE_NEW)) { + if (BMO_edge_flag_test(bm, e, ELE_NEW)) { /* in rare cases the edges face will have already been removed from the edge */ if (LIKELY(e->l)) { BMFace *f_new = BM_faces_join_pair( @@ -258,7 +258,7 @@ void bmo_triangle_fill_exec(BMesh *bm, BMOperator *op) e->l->radial_next->f, e, false); /* join faces */ if (f_new) { - BMO_elem_flag_enable(bm, f_new, ELE_NEW); + BMO_face_flag_enable(bm, f_new, ELE_NEW); BM_edge_kill(bm, e); } else { diff --git a/source/blender/bmesh/operators/bmo_utils.c b/source/blender/bmesh/operators/bmo_utils.c index e596032663e..aa1e4bc7523 100644 --- a/source/blender/bmesh/operators/bmo_utils.c +++ b/source/blender/bmesh/operators/bmo_utils.c @@ -48,7 +48,7 @@ void bmo_create_vert_exec(BMesh *bm, BMOperator *op) BMO_slot_vec_get(op->slots_in, "co", vec); - BMO_elem_flag_enable(bm, BM_vert_create(bm, vec, NULL, BM_CREATE_NOP), ELE_NEW); + BMO_vert_flag_enable(bm, BM_vert_create(bm, vec, NULL, BM_CREATE_NOP), ELE_NEW); BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "vert.out", BM_VERT, ELE_NEW); } @@ -74,7 +74,7 @@ void bmo_transform_exec(BMesh *UNUSED(bm), BMOperator *op) void bmo_translate_exec(BMesh *bm, BMOperator *op) { float mat[4][4], vec[3]; - + BMO_slot_vec_get(op->slots_in, "vec", vec); unit_m4(mat); @@ -86,7 +86,7 @@ void bmo_translate_exec(BMesh *bm, BMOperator *op) void bmo_scale_exec(BMesh *bm, BMOperator *op) { float mat[3][3], vec[3]; - + BMO_slot_vec_get(op->slots_in, "vec", vec); unit_m3(mat); @@ -143,18 +143,18 @@ void bmo_rotate_edges_exec(BMesh *bm, BMOperator *op) if (BM_edge_face_pair(e, &fa, &fb)) { /* check we're untouched */ - if (BMO_elem_flag_test(bm, fa, FACE_TAINT) == false && - BMO_elem_flag_test(bm, fb, FACE_TAINT) == false) + if (BMO_face_flag_test(bm, fa, FACE_TAINT) == false && + BMO_face_flag_test(bm, fb, FACE_TAINT) == false) { /* don't touch again (faces will be freed so run before rotating the edge) */ - BMO_elem_flag_enable(bm, fa, FACE_TAINT); - BMO_elem_flag_enable(bm, fb, FACE_TAINT); + BMO_face_flag_enable(bm, fa, FACE_TAINT); + BMO_face_flag_enable(bm, fb, FACE_TAINT); if (!(e2 = BM_edge_rotate(bm, e, use_ccw, check_flag))) { - BMO_elem_flag_disable(bm, fa, FACE_TAINT); - BMO_elem_flag_disable(bm, fb, FACE_TAINT); + BMO_face_flag_disable(bm, fa, FACE_TAINT); + BMO_face_flag_disable(bm, fb, FACE_TAINT); #if 0 BMO_error_raise(bm, op, BMERR_INVALID_SELECTION, "Could not rotate edge"); return; @@ -163,7 +163,7 @@ void bmo_rotate_edges_exec(BMesh *bm, BMOperator *op) continue; } - BMO_elem_flag_enable(bm, e2, EDGE_OUT); + BMO_edge_flag_enable(bm, e2, EDGE_OUT); } } } @@ -184,11 +184,11 @@ static void bmo_face_flag_set_flush(BMesh *bm, BMFace *f, const short oflag, con BMLoop *l_iter; BMLoop *l_first; - BMO_elem_flag_set(bm, f, oflag, value); + BMO_face_flag_set(bm, f, oflag, value); l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { - BMO_elem_flag_set(bm, l_iter->e, oflag, value); - BMO_elem_flag_set(bm, l_iter->v, oflag, value); + BMO_edge_flag_set(bm, l_iter->e, oflag, value); + BMO_vert_flag_set(bm, l_iter->v, oflag, value); } while ((l_iter = l_iter->next) != l_first); } @@ -210,7 +210,9 @@ static void bmo_region_extend_expand( BMEdge *e; BM_ITER_ELEM (e, &eiter, v, BM_EDGES_OF_VERT) { - if (!BMO_elem_flag_test(bm, e, SEL_ORIG) && !BM_elem_flag_test(e, BM_ELEM_HIDDEN)) { + if (!BMO_edge_flag_test(bm, e, SEL_ORIG) && + !BM_elem_flag_test(e, BM_ELEM_HIDDEN)) + { found = true; break; } @@ -223,9 +225,11 @@ static void bmo_region_extend_expand( BMEdge *e; BM_ITER_ELEM (e, &eiter, v, BM_EDGES_OF_VERT) { - if (!BMO_elem_flag_test(bm, e, SEL_FLAG) && !BM_elem_flag_test(e, BM_ELEM_HIDDEN)) { - BMO_elem_flag_enable(bm, e, SEL_FLAG); - BMO_elem_flag_enable(bm, BM_edge_other_vert(e, v), SEL_FLAG); + if (!BMO_edge_flag_test(bm, e, SEL_FLAG) && + !BM_elem_flag_test(e, BM_ELEM_HIDDEN)) + { + BMO_edge_flag_enable(bm, e, SEL_FLAG); + BMO_vert_flag_enable(bm, BM_edge_other_vert(e, v), SEL_FLAG); } } } @@ -234,7 +238,9 @@ static void bmo_region_extend_expand( BMFace *f; BM_ITER_ELEM (f, &fiter, v, BM_FACES_OF_VERT) { - if (!BMO_elem_flag_test(bm, f, SEL_FLAG) && !BM_elem_flag_test(f, BM_ELEM_HIDDEN)) { + if (!BMO_face_flag_test(bm, f, SEL_FLAG) && + !BM_elem_flag_test(f, BM_ELEM_HIDDEN)) + { bmo_face_flag_set_flush(bm, f, SEL_FLAG, true); } } @@ -245,9 +251,11 @@ static void bmo_region_extend_expand( BMEdge *e; BM_ITER_ELEM (e, &eiter, v, BM_EDGES_OF_VERT) { if (BM_edge_is_wire(e)) { - if (!BMO_elem_flag_test(bm, e, SEL_FLAG) && !BM_elem_flag_test(e, BM_ELEM_HIDDEN)) { - BMO_elem_flag_enable(bm, e, SEL_FLAG); - BMO_elem_flag_enable(bm, BM_edge_other_vert(e, v), SEL_FLAG); + if (!BMO_edge_flag_test(bm, e, SEL_FLAG) && + !BM_elem_flag_test(e, BM_ELEM_HIDDEN)) + { + BMO_edge_flag_enable(bm, e, SEL_FLAG); + BMO_vert_flag_enable(bm, BM_edge_other_vert(e, v), SEL_FLAG); } } } @@ -269,10 +277,10 @@ static void bmo_region_extend_expand( BMFace *f_other; BM_ITER_ELEM (f_other, &fiter, l->e, BM_FACES_OF_EDGE) { - if (!BMO_elem_flag_test(bm, f_other, SEL_ORIG | SEL_FLAG) && + if (!BMO_face_flag_test(bm, f_other, SEL_ORIG | SEL_FLAG) && !BM_elem_flag_test(f_other, BM_ELEM_HIDDEN)) { - BMO_elem_flag_enable(bm, f_other, SEL_FLAG); + BMO_face_flag_enable(bm, f_other, SEL_FLAG); } } } @@ -281,10 +289,10 @@ static void bmo_region_extend_expand( BMFace *f_other; BM_ITER_ELEM (f_other, &fiter, l->v, BM_FACES_OF_VERT) { - if (!BMO_elem_flag_test(bm, f_other, SEL_ORIG | SEL_FLAG) && + if (!BMO_face_flag_test(bm, f_other, SEL_ORIG | SEL_FLAG) && !BM_elem_flag_test(f_other, BM_ELEM_HIDDEN)) { - BMO_elem_flag_enable(bm, f_other, SEL_FLAG); + BMO_face_flag_enable(bm, f_other, SEL_FLAG); } } } @@ -310,7 +318,7 @@ static void bmo_region_extend_contract( BMEdge *e; BM_ITER_ELEM (e, &eiter, v, BM_EDGES_OF_VERT) { - if (!BMO_elem_flag_test(bm, e, SEL_ORIG)) { + if (!BMO_edge_flag_test(bm, e, SEL_ORIG)) { found = true; break; } @@ -321,7 +329,7 @@ static void bmo_region_extend_contract( BMFace *f; BM_ITER_ELEM (f, &fiter, v, BM_FACES_OF_VERT) { - if (!BMO_elem_flag_test(bm, f, SEL_ORIG)) { + if (!BMO_face_flag_test(bm, f, SEL_ORIG)) { found = true; break; } @@ -334,7 +342,7 @@ static void bmo_region_extend_contract( BM_ITER_ELEM (e, &eiter, v, BM_EDGES_OF_VERT) { if (BM_edge_is_wire(e)) { - if (!BMO_elem_flag_test(bm, e, SEL_ORIG)) { + if (!BMO_edge_flag_test(bm, e, SEL_ORIG)) { found = true; break; } @@ -347,10 +355,10 @@ static void bmo_region_extend_contract( BMIter eiter; BMEdge *e; - BMO_elem_flag_enable(bm, v, SEL_FLAG); + BMO_vert_flag_enable(bm, v, SEL_FLAG); BM_ITER_ELEM (e, &eiter, v, BM_EDGES_OF_VERT) { - BMO_elem_flag_enable(bm, e, SEL_FLAG); + BMO_edge_flag_enable(bm, e, SEL_FLAG); } } } @@ -369,8 +377,8 @@ static void bmo_region_extend_contract( BMFace *f_other; BM_ITER_ELEM (f_other, &fiter, l->e, BM_FACES_OF_EDGE) { - if (!BMO_elem_flag_test(bm, f_other, SEL_ORIG)) { - BMO_elem_flag_enable(bm, f, SEL_FLAG); + if (!BMO_face_flag_test(bm, f_other, SEL_ORIG)) { + BMO_face_flag_enable(bm, f, SEL_FLAG); break; } } @@ -380,8 +388,8 @@ static void bmo_region_extend_contract( BMFace *f_other; BM_ITER_ELEM (f_other, &fiter, l->v, BM_FACES_OF_VERT) { - if (!BMO_elem_flag_test(bm, f_other, SEL_ORIG)) { - BMO_elem_flag_enable(bm, f, SEL_FLAG); + if (!BMO_face_flag_test(bm, f_other, SEL_ORIG)) { + BMO_face_flag_enable(bm, f, SEL_FLAG); break; } } @@ -420,7 +428,7 @@ void bmo_smooth_vert_exec(BMesh *UNUSED(bm), BMOperator *op) const float fac = BMO_slot_float_get(op->slots_in, "factor"); int i, j, clipx, clipy, clipz; int xaxis, yaxis, zaxis; - + clipx = BMO_slot_bool_get(op->slots_in, "mirror_clip_x"); clipy = BMO_slot_bool_get(op->slots_in, "mirror_clip_y"); clipz = BMO_slot_bool_get(op->slots_in, "mirror_clip_z"); @@ -441,7 +449,7 @@ void bmo_smooth_vert_exec(BMesh *UNUSED(bm), BMOperator *op) add_v3_v3v3(co, co, co2); j += 1; } - + if (!j) { copy_v3_v3(co, v->co); i++; diff --git a/source/blender/bmesh/tools/bmesh_beautify.c b/source/blender/bmesh/tools/bmesh_beautify.c index 19fe492c670..3e3a6547b75 100644 --- a/source/blender/bmesh/tools/bmesh_beautify.c +++ b/source/blender/bmesh/tools/bmesh_beautify.c @@ -424,11 +424,13 @@ void BM_mesh_beautify_fill( flag, method); /* update flags */ - if (oflag_edge) - BMO_elem_flag_enable(bm, e, oflag_edge); + if (oflag_edge) { + BMO_edge_flag_enable(bm, e, oflag_edge); + } + if (oflag_face) { - BMO_elem_flag_enable(bm, e->l->f, oflag_face); - BMO_elem_flag_enable(bm, e->l->radial_next->f, oflag_face); + BMO_face_flag_enable(bm, e->l->f, oflag_face); + BMO_face_flag_enable(bm, e->l->radial_next->f, oflag_face); } } } diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c index 0ed1dffcafb..4dc1c8a9f00 100644 --- a/source/blender/bmesh/tools/bmesh_bevel.c +++ b/source/blender/bmesh/tools/bmesh_bevel.c @@ -1849,11 +1849,11 @@ static void build_boundary(BevelParams *bp, BevVert *bv, bool construct) do { BLI_assert(e->is_bev); /* Make the BoundVert for the right side of e; other side will be made - * when the beveled edge to the left of e is handled. - * Analyze edges until next beveled edge. - * They are either "in plane" (preceding and subsequent faces are coplanar) - * or not. The "non-in-plane" edges effect silhouette and we prefer to slide - * along one of those if possible. */ + * when the beveled edge to the left of e is handled. + * Analyze edges until next beveled edge. + * They are either "in plane" (preceding and subsequent faces are coplanar) + * or not. The "non-in-plane" edges effect silhouette and we prefer to slide + * along one of those if possible. */ nip = nnip = 0; /* counts of in-plane / not-in-plane */ enip = eip = NULL; /* representatives of each */ for (e2 = e->next; !e2->is_bev; e2 = e2->next) { diff --git a/source/blender/bmesh/tools/bmesh_bisect_plane.c b/source/blender/bmesh/tools/bmesh_bisect_plane.c index 9fb6d39a008..51b92a3c45e 100644 --- a/source/blender/bmesh/tools/bmesh_bisect_plane.c +++ b/source/blender/bmesh/tools/bmesh_bisect_plane.c @@ -155,9 +155,9 @@ static void bm_face_bisect_verts(BMesh *bm, BMFace *f, const float plane[4], con BM_face_split(bm, f, l_a, l_b, &l_new, NULL, true); if (l_new) { if (oflag_center) { - BMO_elem_flag_enable(bm, l_new->e, oflag_center); - BMO_elem_flag_enable(bm, l_new->f, oflag_center); - BMO_elem_flag_enable(bm, f, oflag_center); + BMO_edge_flag_enable(bm, l_new->e, oflag_center); + BMO_face_flag_enable(bm, l_new->f, oflag_center); + BMO_face_flag_enable(bm, f, oflag_center); } } } @@ -270,9 +270,9 @@ static void bm_face_bisect_verts(BMesh *bm, BMFace *f, const float plane[4], con if (l_new) { if (oflag_center) { - BMO_elem_flag_enable(bm, l_new->e, oflag_center); - BMO_elem_flag_enable(bm, l_new->f, oflag_center); - BMO_elem_flag_enable(bm, face_split_arr[j], oflag_center); + BMO_edge_flag_enable(bm, l_new->e, oflag_center); + BMO_face_flag_enable(bm, l_new->f, oflag_center); + BMO_face_flag_enable(bm, face_split_arr[j], oflag_center); } } @@ -372,7 +372,7 @@ void BM_mesh_bisect_plane( if (BM_VERT_DIR(v) == 0) { if (oflag_center) { - BMO_elem_flag_enable(bm, v, oflag_center); + BMO_vert_flag_enable(bm, v, oflag_center); } if (use_snap_center) { closest_to_plane_v3(v->co, plane, v->co); @@ -407,7 +407,7 @@ void BM_mesh_bisect_plane( v_new = BM_edge_split(bm, e, e->v1, NULL, e_fac); vert_is_center_enable(v_new); if (oflag_center) { - BMO_elem_flag_enable(bm, v_new, oflag_center); + BMO_vert_flag_enable(bm, v_new, oflag_center); } BM_VERT_DIR(v_new) = 0; @@ -439,7 +439,7 @@ void BM_mesh_bisect_plane( /* if both verts are on the center - tag it */ if (oflag_center) { if (side[0] == 0 && side[1] == 0) { - BMO_elem_flag_enable(bm, e, oflag_center); + BMO_edge_flag_enable(bm, e, oflag_center); } } } diff --git a/source/blender/bmesh/tools/bmesh_decimate_dissolve.c b/source/blender/bmesh/tools/bmesh_decimate_dissolve.c index ad35d57f35b..978cceee37c 100644 --- a/source/blender/bmesh/tools/bmesh_decimate_dissolve.c +++ b/source/blender/bmesh/tools/bmesh_decimate_dissolve.c @@ -335,7 +335,7 @@ void BM_mesh_decimate_dissolve_ex( /* update normal */ BM_face_normal_update(f_new); if (oflag_out) { - BMO_elem_flag_enable(bm, f_new, oflag_out); + BMO_face_flag_enable(bm, f_new, oflag_out); } /* re-calculate costs */ diff --git a/source/blender/bmesh/tools/bmesh_decimate_unsubdivide.c b/source/blender/bmesh/tools/bmesh_decimate_unsubdivide.c index db60b3e15e1..0fc571bc0a8 100644 --- a/source/blender/bmesh/tools/bmesh_decimate_unsubdivide.c +++ b/source/blender/bmesh/tools/bmesh_decimate_unsubdivide.c @@ -213,7 +213,7 @@ void BM_mesh_decimate_unsubdivide_ex(BMesh *bm, const int iterations, const bool BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { if (BM_elem_flag_test(v, BM_ELEM_TAG) && bm_vert_dissolve_fan_test(v)) { #ifdef USE_WALKER - BMO_elem_flag_enable(bm, v, ELE_VERT_TAG); + BMO_vert_flag_enable(bm, v, ELE_VERT_TAG); #endif BM_elem_index_set(v, VERT_INDEX_INIT); /* set_dirty! */ } @@ -238,7 +238,7 @@ void BM_mesh_decimate_unsubdivide_ex(BMesh *bm, const int iterations, const bool BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { if (v->e && (BM_elem_index_get(v) == VERT_INDEX_INIT)) { #ifdef USE_WALKER - if (BMO_elem_flag_test(bm, v, ELE_VERT_TAG)) + if (BMO_vert_flag_test(bm, v, ELE_VERT_TAG)) #endif { /* check again incase the topology changed */ diff --git a/source/blender/bmesh/tools/bmesh_intersect.c b/source/blender/bmesh/tools/bmesh_intersect.c index bd6a68faabb..58234ddf3bd 100644 --- a/source/blender/bmesh/tools/bmesh_intersect.c +++ b/source/blender/bmesh/tools/bmesh_intersect.c @@ -53,6 +53,8 @@ #include "BLI_buffer.h" #include "bmesh.h" +#include "intern/bmesh_private.h" + #include "bmesh_intersect.h" /* own include */ #include "tools/bmesh_edgesplit.h" @@ -87,18 +89,6 @@ // #define USE_DUMP -/* use only for small arrays */ -BLI_INLINE bool array_contains_pointer(const void **arr, unsigned int arr_len, const void *item) -{ - BLI_assert(arr_len < 3); - for (unsigned int i = 0; i < arr_len; i++) { - if (arr[i] == item) { - return true; - } - } - return false; -} - static void tri_v3_scale( float v1[3], float v2[3], float v3[3], const float t) @@ -547,9 +537,6 @@ static void bm_isect_tri_tri( const float *f_b_cos[3] = {UNPACK3_EX(, fv_b, ->co)}; float f_a_nor[3]; float f_b_nor[3]; - /* track vertices which have been added to 'iv_ls_a' & 'iv_ls_b' */ - int a_mask = 0; - int b_mask = 0; unsigned int i; @@ -569,24 +556,22 @@ static void bm_isect_tri_tri( STACK_INIT(iv_ls_a, ARRAY_SIZE(iv_ls_a)); STACK_INIT(iv_ls_b, ARRAY_SIZE(iv_ls_b)); - /* don't test, but we must be sure not to add doubles (assert instead). */ -#ifndef NDEBUG -# define STACK_PUSH_NOTEST(arr, ele) \ - { \ - BLI_assert(BLI_array_findindex(arr, STACK_SIZE(arr), &(ele)) == -1); \ - STACK_PUSH(arr, ele); \ +#define VERT_VISIT_A _FLAG_WALK +#define VERT_VISIT_B _FLAG_WALK_ALT + +#define STACK_PUSH_TEST_A(ele) \ + if (BM_ELEM_API_FLAG_TEST(ele, VERT_VISIT_A) == 0) { \ + BM_ELEM_API_FLAG_ENABLE(ele, VERT_VISIT_A); \ + STACK_PUSH(iv_ls_a, ele); \ } ((void)0) -#else -# define STACK_PUSH_NOTEST STACK_PUSH -#endif - /* warning, this seems like it might be inefficent, - * however there will be <3 items in this case. */ -# define STACK_PUSH_TEST(arr, ele, arr_offset) \ - if (!array_contains_pointer((const void **)(&(arr)[arr_offset]), STACK_SIZE(arr) - (arr_offset), (void *)ele)) { \ - STACK_PUSH(arr, ele); \ +#define STACK_PUSH_TEST_B(ele) \ + if (BM_ELEM_API_FLAG_TEST(ele, VERT_VISIT_B) == 0) { \ + BM_ELEM_API_FLAG_ENABLE(ele, VERT_VISIT_B); \ + STACK_PUSH(iv_ls_b, ele); \ } ((void)0) + /* vert-vert * --------- */ { @@ -598,22 +583,18 @@ static void bm_isect_tri_tri( unsigned int i_b; for (i_b = 0; i_b < 3; i_b++) { if (len_squared_v3v3(fv_a[i_a]->co, fv_b[i_b]->co) <= s->epsilon.eps2x_sq) { - if (!((1 << i_a) & a_mask)) { - STACK_PUSH_NOTEST(iv_ls_a, fv_a[i_a]); - a_mask |= (1 << i_a); #ifdef USE_DUMP + if (BM_ELEM_API_FLAG_TEST(fv_a[i_a], VERT_VISIT) == 0) { printf(" ('VERT-VERT-A') %d, %d),\n", i_a, BM_elem_index_get(fv_a[i_a])); -#endif } - if (!((1 << i_b) & b_mask)) { - STACK_PUSH_NOTEST(iv_ls_b, fv_b[i_b]); - b_mask |= (1 << i_b); -#ifdef USE_DUMP + if (BM_ELEM_API_FLAG_TEST(fv_b[i_b], VERT_VISIT) == 0) { printf(" ('VERT-VERT-B') %d, %d),\n", i_b, BM_elem_index_get(fv_b[i_b])); -#endif } +#endif + STACK_PUSH_TEST_A(fv_a[i_a]); + STACK_PUSH_TEST_B(fv_b[i_b]); } } } @@ -624,22 +605,25 @@ static void bm_isect_tri_tri( { unsigned int i_a; for (i_a = 0; i_a < 3; i_a++) { - if (!((1 << i_a) & a_mask)) { + if (BM_ELEM_API_FLAG_TEST(fv_a[i_a], VERT_VISIT_A) == 0) { unsigned int i_b_e0; for (i_b_e0 = 0; i_b_e0 < 3; i_b_e0++) { unsigned int i_b_e1 = (i_b_e0 + 1) % 3; - float fac; - if (((1 << i_b_e0) | (1 << i_b_e1)) & b_mask) + + if (BM_ELEM_API_FLAG_TEST(fv_b[i_b_e0], VERT_VISIT_B) || + BM_ELEM_API_FLAG_TEST(fv_b[i_b_e1], VERT_VISIT_B)) + { continue; - fac = line_point_factor_v3(fv_a[i_a]->co, fv_b[i_b_e0]->co, fv_b[i_b_e1]->co); + } + + const float fac = line_point_factor_v3(fv_a[i_a]->co, fv_b[i_b_e0]->co, fv_b[i_b_e1]->co); if ((fac > 0.0f - s->epsilon.eps) && (fac < 1.0f + s->epsilon.eps)) { float ix[3]; interp_v3_v3v3(ix, fv_b[i_b_e0]->co, fv_b[i_b_e1]->co, fac); if (len_squared_v3v3(ix, fv_a[i_a]->co) <= s->epsilon.eps2x_sq) { BMEdge *e; - STACK_PUSH_NOTEST(iv_ls_b, fv_a[i_a]); - // STACK_PUSH_NOTEST(iv_ls_a, fv_a[i_a]); - a_mask |= (1 << i_a); + STACK_PUSH_TEST_B(fv_a[i_a]); + // STACK_PUSH_TEST_A(fv_a[i_a]); e = BM_edge_exists(fv_b[i_b_e0], fv_b[i_b_e1]); #ifdef USE_DUMP printf(" ('VERT-EDGE-A', %d, %d),\n", @@ -662,22 +646,25 @@ static void bm_isect_tri_tri( { unsigned int i_b; for (i_b = 0; i_b < 3; i_b++) { - if (!((1 << i_b) & b_mask)) { + if (BM_ELEM_API_FLAG_TEST(fv_b[i_b], VERT_VISIT_B) == 0) { unsigned int i_a_e0; for (i_a_e0 = 0; i_a_e0 < 3; i_a_e0++) { unsigned int i_a_e1 = (i_a_e0 + 1) % 3; - float fac; - if (((1 << i_a_e0) | (1 << i_a_e1)) & a_mask) + + if (BM_ELEM_API_FLAG_TEST(fv_a[i_a_e0], VERT_VISIT_A) || + BM_ELEM_API_FLAG_TEST(fv_a[i_a_e1], VERT_VISIT_A)) + { continue; - fac = line_point_factor_v3(fv_b[i_b]->co, fv_a[i_a_e0]->co, fv_a[i_a_e1]->co); + } + + const float fac = line_point_factor_v3(fv_b[i_b]->co, fv_a[i_a_e0]->co, fv_a[i_a_e1]->co); if ((fac > 0.0f - s->epsilon.eps) && (fac < 1.0f + s->epsilon.eps)) { float ix[3]; interp_v3_v3v3(ix, fv_a[i_a_e0]->co, fv_a[i_a_e1]->co, fac); if (len_squared_v3v3(ix, fv_b[i_b]->co) <= s->epsilon.eps2x_sq) { BMEdge *e; - STACK_PUSH_NOTEST(iv_ls_a, fv_b[i_b]); + STACK_PUSH_TEST_A(fv_b[i_b]); // STACK_PUSH_NOTEST(iv_ls_b, fv_b[i_b]); - b_mask |= (1 << i_b); e = BM_edge_exists(fv_a[i_a_e0], fv_a[i_a_e1]); #ifdef USE_DUMP printf(" ('VERT-EDGE-B', %d, %d),\n", @@ -711,14 +698,15 @@ static void bm_isect_tri_tri( // second check for verts intersecting the triangle for (i_a = 0; i_a < 3; i_a++) { - float ix[3]; - if ((1 << i_a) & a_mask) + if (BM_ELEM_API_FLAG_TEST(fv_a[i_a], VERT_VISIT_A)) { continue; + } + + float ix[3]; if (isect_point_tri_v3(fv_a[i_a]->co, UNPACK3(t_scale), ix)) { if (len_squared_v3v3(ix, fv_a[i_a]->co) <= s->epsilon.eps2x_sq) { - STACK_PUSH_NOTEST(iv_ls_a, fv_a[i_a]); - STACK_PUSH_NOTEST(iv_ls_b, fv_a[i_a]); - a_mask |= (1 << i_a); + STACK_PUSH_TEST_A(fv_a[i_a]); + STACK_PUSH_TEST_B(fv_a[i_a]); #ifdef USE_DUMP printf(" 'VERT TRI-A',\n"); #endif @@ -737,15 +725,15 @@ static void bm_isect_tri_tri( tri_v3_scale(UNPACK3(t_scale), 1.0f - s->epsilon.eps2x); for (i_b = 0; i_b < 3; i_b++) { - float ix[3]; - if ((1 << i_b) & b_mask) + if (BM_ELEM_API_FLAG_TEST(fv_b[i_b], VERT_VISIT_B)) { continue; + } + float ix[3]; if (isect_point_tri_v3(fv_b[i_b]->co, UNPACK3(t_scale), ix)) { if (len_squared_v3v3(ix, fv_b[i_b]->co) <= s->epsilon.eps2x_sq) { - STACK_PUSH_NOTEST(iv_ls_a, fv_b[i_b]); - STACK_PUSH_NOTEST(iv_ls_b, fv_b[i_b]); - b_mask |= (1 << i_b); + STACK_PUSH_TEST_A(fv_b[i_b]); + STACK_PUSH_TEST_B(fv_b[i_b]); #ifdef USE_DUMP printf(" 'VERT TRI-B',\n"); #endif @@ -760,7 +748,7 @@ static void bm_isect_tri_tri( #ifdef USE_DUMP printf("# OVERLAP\n"); #endif - return; + goto finally; } normal_tri_v3(f_a_nor, UNPACK3(f_a_cos)); @@ -769,44 +757,42 @@ static void bm_isect_tri_tri( /* edge-tri & edge-edge * -------------------- */ { - /** - * Note that its possible to add the same vertex multiple times - * with near degenerate faces (or a large epsilon). - * - * For this reason we have #STACK_PUSH_TEST macro which only adds vertices that aren't already added. - * Since we know none of the vertices from #bm_isect_edge_tri, the check can be offset. - */ - - const unsigned int iv_ls_a_offset = STACK_SIZE(iv_ls_a); - const unsigned int iv_ls_b_offset = STACK_SIZE(iv_ls_b); - - unsigned int i_e0; - for (i_e0 = 0; i_e0 < 3; i_e0++) { - unsigned int i_e1 = (i_e0 + 1) % 3; + for (unsigned int i_a_e0 = 0; i_a_e0 < 3; i_a_e0++) { + unsigned int i_a_e1 = (i_a_e0 + 1) % 3; enum ISectType side; BMVert *iv; - if (((1 << i_e0) | (1 << i_e1)) & a_mask) + + if (BM_ELEM_API_FLAG_TEST(fv_a[i_a_e0], VERT_VISIT_A) || + BM_ELEM_API_FLAG_TEST(fv_a[i_a_e1], VERT_VISIT_A)) + { continue; - iv = bm_isect_edge_tri(s, fv_a[i_e0], fv_a[i_e1], fv_b, b_index, f_b_cos, f_b_nor, &side); + } + + iv = bm_isect_edge_tri(s, fv_a[i_a_e0], fv_a[i_a_e1], fv_b, b_index, f_b_cos, f_b_nor, &side); if (iv) { - STACK_PUSH_TEST(iv_ls_a, iv, iv_ls_a_offset); - STACK_PUSH_TEST(iv_ls_b, iv, iv_ls_b_offset); + STACK_PUSH_TEST_A(iv); + STACK_PUSH_TEST_B(iv); #ifdef USE_DUMP printf(" ('EDGE-TRI-A', %d),\n", side); #endif } } - for (i_e0 = 0; i_e0 < 3; i_e0++) { - unsigned int i_e1 = (i_e0 + 1) % 3; + for (unsigned int i_b_e0 = 0; i_b_e0 < 3; i_b_e0++) { + unsigned int i_b_e1 = (i_b_e0 + 1) % 3; enum ISectType side; BMVert *iv; - if (((1 << i_e0) | (1 << i_e1)) & b_mask) + + if (BM_ELEM_API_FLAG_TEST(fv_b[i_b_e0], VERT_VISIT_B) || + BM_ELEM_API_FLAG_TEST(fv_b[i_b_e1], VERT_VISIT_B)) + { continue; - iv = bm_isect_edge_tri(s, fv_b[i_e0], fv_b[i_e1], fv_a, a_index, f_a_cos, f_a_nor, &side); + } + + iv = bm_isect_edge_tri(s, fv_b[i_b_e0], fv_b[i_b_e1], fv_a, a_index, f_a_cos, f_a_nor, &side); if (iv) { - STACK_PUSH_TEST(iv_ls_a, iv, iv_ls_a_offset); - STACK_PUSH_TEST(iv_ls_b, iv, iv_ls_b_offset); + STACK_PUSH_TEST_A(iv); + STACK_PUSH_TEST_B(iv); #ifdef USE_DUMP printf(" ('EDGE-TRI-B', %d),\n", side); #endif @@ -859,6 +845,15 @@ static void bm_isect_tri_tri( // BLI_assert(len(ie_vs) <= 2) } } + +finally: + for (i = 0; i < STACK_SIZE(iv_ls_a); i++) { + BM_ELEM_API_FLAG_DISABLE(iv_ls_a[i], VERT_VISIT_A); \ + } + for (i = 0; i < STACK_SIZE(iv_ls_b); i++) { + BM_ELEM_API_FLAG_DISABLE(iv_ls_b[i], VERT_VISIT_B); \ + } + } #ifdef USE_BVH diff --git a/source/blender/collada/collada_utils.cpp b/source/blender/collada/collada_utils.cpp index f0984fbc127..649c86edd25 100644 --- a/source/blender/collada/collada_utils.cpp +++ b/source/blender/collada/collada_utils.cpp @@ -357,8 +357,11 @@ void bc_triangulate_mesh(Mesh *me) bool use_beauty = false; bool tag_only = false; int quad_method = MOD_TRIANGULATE_QUAD_SHORTEDGE; /* XXX: The triangulation method selection could be offered in the UI */ - - BMesh *bm = BM_mesh_create(&bm_mesh_allocsize_default); + + const struct BMeshCreateParams bm_create_params = {0}; + BMesh *bm = BM_mesh_create( + &bm_mesh_allocsize_default, + &bm_create_params); BMeshFromMeshParams bm_from_me_params = {0}; bm_from_me_params.calc_face_normal = true; BM_mesh_bm_from_me(bm, me, &bm_from_me_params); @@ -370,8 +373,8 @@ void bc_triangulate_mesh(Mesh *me) } /* -* A bone is a leaf when it has no children or all children are not connected. -*/ + * A bone is a leaf when it has no children or all children are not connected. + */ bool bc_is_leaf_bone(Bone *bone) { for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { @@ -410,10 +413,10 @@ int bc_set_layer(int bitfield, int layer, bool enable) } /** -* BoneExtended is a helper class needed for the Bone chain finder -* See ArmatureImporter::fix_leaf_bones() -* and ArmatureImporter::connect_bone_chains() -**/ + * BoneExtended is a helper class needed for the Bone chain finder + * See ArmatureImporter::fix_leaf_bones() + * and ArmatureImporter::connect_bone_chains() + */ BoneExtended::BoneExtended(EditBone *aBone) { diff --git a/source/blender/compositor/intern/COM_OpenCLDevice.h b/source/blender/compositor/intern/COM_OpenCLDevice.h index a513954ee0d..ad40b4851fb 100644 --- a/source/blender/compositor/intern/COM_OpenCLDevice.h +++ b/source/blender/compositor/intern/COM_OpenCLDevice.h @@ -95,9 +95,9 @@ public: void execute(WorkPackage *work); /** - * @brief determine an image format - * @param memorybuffer - */ + * @brief determine an image format + * @param memorybuffer + */ static const cl_image_format *determineImageFormat(MemoryBuffer *memoryBuffer); cl_context getContext() { return this->m_context; } diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index af0b3f8b70f..34c661b21f3 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -1434,20 +1434,20 @@ void DepsgraphRelationBuilder::build_rig(Scene *scene, Object *ob) } /* IK Solvers... - * - These require separate processing steps are pose-level - * to be executed between chains of bones (i.e. once the - * base transforms of a bunch of bones is done) - * - * - We build relations for these before the dependencies - * between ops in the same component as it is necessary - * to check whether such bones are in the same IK chain - * (or else we get weird issues with either in-chain - * references, or with bones being parented to IK'd bones) - * - * Unsolved Issues: - * - Care is needed to ensure that multi-headed trees work out the same as in ik-tree building - * - Animated chain-lengths are a problem... - */ + * - These require separate processing steps are pose-level + * to be executed between chains of bones (i.e. once the + * base transforms of a bunch of bones is done) + * + * - We build relations for these before the dependencies + * between ops in the same component as it is necessary + * to check whether such bones are in the same IK chain + * (or else we get weird issues with either in-chain + * references, or with bones being parented to IK'd bones) + * + * Unsolved Issues: + * - Care is needed to ensure that multi-headed trees work out the same as in ik-tree building + * - Animated chain-lengths are a problem... + */ RootPChanMap root_map; bool pose_depends_on_local_transform = false; for (bPoseChannel *pchan = (bPoseChannel *)ob->pose->chanbase.first; pchan; pchan = pchan->next) { diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c index a82cca9e52a..21c25f829b1 100644 --- a/source/blender/editors/animation/drivers.c +++ b/source/blender/editors/animation/drivers.c @@ -158,7 +158,7 @@ static int add_driver_with_target( ReportList *UNUSED(reports), ID *dst_id, const char dst_path[], int dst_index, ID *src_id, const char src_path[], int src_index, - PointerRNA *UNUSED(dst_ptr), PropertyRNA *dst_prop, + PointerRNA *dst_ptr, PropertyRNA *dst_prop, PointerRNA *src_ptr, PropertyRNA *src_prop, short flag, int driver_type) { @@ -207,11 +207,15 @@ static int add_driver_with_target( /* Create a driver variable for the target * - For transform properties, we want to automatically use "transform channel" instead * (The only issue is with quat rotations vs euler channels...) + * - To avoid problems with transform properties depending on the final transform that they + * control (thus creating pseudo-cycles - see T48734), we don't use transform channels + * when both the source and destinations are in same places. */ dvar = driver_add_new_variable(driver); if (ELEM(src_ptr->type, &RNA_Object, &RNA_PoseBone) && - (STREQ(prop_name, "location") || STREQ(prop_name, "scale") || STRPREFIX(prop_name, "rotation_"))) + (STREQ(prop_name, "location") || STREQ(prop_name, "scale") || STRPREFIX(prop_name, "rotation_")) && + (src_ptr->data != dst_ptr->data)) { /* Transform Channel */ DriverTarget *dtar; diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index 66b3a63c669..0c0f54f0179 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -1069,6 +1069,9 @@ short insert_keyframe(ReportList *reports, ID *id, bAction *act, const char grou if (ELEM(RNA_property_subtype(prop), PROP_TRANSLATION, PROP_XYZ, PROP_EULER, PROP_COLOR, PROP_COORDS)) { fcu->color_mode = FCURVE_COLOR_AUTO_RGB; } + else if (RNA_property_subtype(prop), PROP_QUATERNION) { + fcu->color_mode = FCURVE_COLOR_AUTO_YRGB; + } } /* insert keyframe */ diff --git a/source/blender/editors/curve/editfont_undo.c b/source/blender/editors/curve/editfont_undo.c index e028600659c..75f3df73118 100644 --- a/source/blender/editors/curve/editfont_undo.c +++ b/source/blender/editors/curve/editfont_undo.c @@ -77,7 +77,7 @@ static struct { /* We could have the undo API pass in the previous state, for now store a local list */ ListBase local_links; -} uf_arraystore = {NULL}; +} uf_arraystore = {{NULL}}; /** * \param create: When false, only free the arrays. diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c index b2c6107ab61..d62625baaa4 100644 --- a/source/blender/editors/gpencil/gpencil_utils.c +++ b/source/blender/editors/gpencil/gpencil_utils.c @@ -552,8 +552,8 @@ bool gp_smooth_stroke(bGPDstroke *gps, int i, float inf, bool affect_pressure) } /* Only affect endpoints by a fraction of the normal strength, - * to prevent the stroke from shrinking too much - */ + * to prevent the stroke from shrinking too much + */ if ((i == 0) || (i == gps->totpoints - 1)) { inf *= 0.1f; } diff --git a/source/blender/editors/hair/hair_undo.c b/source/blender/editors/hair/hair_undo.c index 511bd8edaf1..cb5ae43f5dd 100644 --- a/source/blender/editors/hair/hair_undo.c +++ b/source/blender/editors/hair/hair_undo.c @@ -121,7 +121,8 @@ static void strands_undo_to_edit(void *undov, void *editv, void *UNUSED(obdata)) edit->base.bm->shapenr = undo->shapenr; - bm = BM_mesh_create(&allocsize); + bm = BM_mesh_create(&allocsize, + &((struct BMeshCreateParams){.use_toolflags = false,})); params.cd_mask_extra = CD_MASK_STRANDS_BMESH; params.active_shapekey = undo->shapenr; BM_mesh_bm_from_me(bm, &undo->me, ¶ms); diff --git a/source/blender/editors/include/ED_fileselect.h b/source/blender/editors/include/ED_fileselect.h index 80f930a0c30..92acfa6c1d2 100644 --- a/source/blender/editors/include/ED_fileselect.h +++ b/source/blender/editors/include/ED_fileselect.h @@ -109,7 +109,7 @@ int ED_file_extension_icon(const char *path); void ED_file_read_bookmarks(void); -void ED_file_change_dir(struct bContext *C, const bool checkdir); +void ED_file_change_dir(struct bContext *C); /* File menu stuff */ diff --git a/source/blender/editors/include/ED_transform_snap_object_context.h b/source/blender/editors/include/ED_transform_snap_object_context.h index baf4ed574cf..7944b434057 100644 --- a/source/blender/editors/include/ED_transform_snap_object_context.h +++ b/source/blender/editors/include/ED_transform_snap_object_context.h @@ -75,7 +75,7 @@ SnapObjectContext *ED_transform_snap_object_context_create( SnapObjectContext *ED_transform_snap_object_context_create_view3d( struct Main *bmain, struct Scene *scene, int flag, /* extra args for view3d */ - struct ARegion *ar, struct View3D *v3d); + const struct ARegion *ar, const struct View3D *v3d); void ED_transform_snap_object_context_destroy(SnapObjectContext *sctx); /* callbacks to filter how snap works */ diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index baab6b6100d..b09284aa759 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -208,10 +208,12 @@ eV3DProjStatus ED_view3d_project_float_global(const struct ARegion *ar, const fl eV3DProjStatus ED_view3d_project_float_object(const struct ARegion *ar, const float co[3], float r_co[2], const eV3DProjTest flag); float ED_view3d_calc_zfac(const struct RegionView3D *rv3d, const float co[3], bool *r_flip); -bool ED_view3d_win_to_ray(const struct ARegion *ar, struct View3D *v3d, const float mval[2], - float ray_start[3], float ray_normal[3], const bool do_clip); -bool ED_view3d_win_to_ray_ex(const struct ARegion *ar, struct View3D *v3d, const float mval[2], - float r_ray_co[3], float r_ray_normal[3], float r_ray_start[3], bool do_clip); +bool ED_view3d_win_to_ray( + const struct ARegion *ar, const struct View3D *v3d, const float mval[2], + float ray_start[3], float ray_normal[3], const bool do_clip); +bool ED_view3d_win_to_ray_ex( + const struct ARegion *ar, const struct View3D *v3d, const float mval[2], + float r_ray_co[3], float r_ray_normal[3], float r_ray_start[3], bool do_clip); void ED_view3d_global_to_vector(const struct RegionView3D *rv3d, const float coord[3], float vec[3]); void ED_view3d_win_to_3d(const struct ARegion *ar, const float depth_pt[3], const float mval[2], float out[3]); void ED_view3d_win_to_3d_int(const struct ARegion *ar, const float depth_pt[3], const int mval[2], float out[3]); diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 77990066027..ba7240be5d8 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -2576,9 +2576,11 @@ static void ui_set_but_soft_range(uiBut *but) } else if (but->poin && (but->pointype & UI_BUT_POIN_TYPES)) { float value = ui_but_value_get(but); - CLAMP(value, but->hardmin, but->hardmax); - but->softmin = min_ff(but->softmin, value); - but->softmax = max_ff(but->softmax, value); + if (isfinite(value)) { + CLAMP(value, but->hardmin, but->hardmax); + but->softmin = min_ff(but->softmin, value); + but->softmax = max_ff(but->softmax, value); + } } else { BLI_assert(0); diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index f941993a9e1..e0b8003d8a9 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -6014,20 +6014,15 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt CurveMapping *cumap = (CurveMapping *)but->poin; CurveMap *cuma = cumap->cm + cumap->cur; CurveMapPoint *cmp; - float fx, fy, zoomx, zoomy, offsx, offsy; - float dist, mindist = 200.0f; // 14 pixels radius + const float m_xy[2] = {mx, my}; + float dist_min_sq = SQUARE(14.0f); /* 14 pixels radius */ int sel = -1; - zoomx = BLI_rctf_size_x(&but->rect) / BLI_rctf_size_x(&cumap->curr); - zoomy = BLI_rctf_size_y(&but->rect) / BLI_rctf_size_y(&cumap->curr); - offsx = cumap->curr.xmin; - offsy = cumap->curr.ymin; - if (event->ctrl) { - fx = ((float)mx - but->rect.xmin) / zoomx + offsx; - fy = ((float)my - but->rect.ymin) / zoomy + offsy; + float f_xy[2]; + BLI_rctf_transform_pt_v(&cumap->curr, &but->rect, f_xy, m_xy); - curvemap_insert(cuma, fx, fy); + curvemap_insert(cuma, f_xy[0], f_xy[1]); curvemapping_changed(cumap, false); changed = true; } @@ -6035,33 +6030,37 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt /* check for selecting of a point */ cmp = cuma->curve; /* ctrl adds point, new malloc */ for (a = 0; a < cuma->totpoint; a++) { - fx = but->rect.xmin + zoomx * (cmp[a].x - offsx); - fy = but->rect.ymin + zoomy * (cmp[a].y - offsy); - dist = (fx - mx) * (fx - mx) + (fy - my) * (fy - my); - if (dist < mindist) { + float f_xy[2]; + BLI_rctf_transform_pt_v(&but->rect, &cumap->curr, f_xy, &cmp[a].x); + const float dist_sq = len_squared_v2v2(m_xy, f_xy); + if (dist_sq < dist_min_sq) { sel = a; - mindist = dist; + dist_min_sq = dist_sq; } } if (sel == -1) { int i; + float f_xy[2], f_xy_prev[2]; /* if the click didn't select anything, check if it's clicked on the * curve itself, and if so, add a point */ - fx = ((float)mx - but->rect.xmin) / zoomx + offsx; - fy = ((float)my - but->rect.ymin) / zoomy + offsy; - cmp = cuma->table; - /* loop through the curve segment table and find what's near the mouse. - * 0.05 is kinda arbitrary, but seems to be what works nicely. */ - for (i = 0; i <= CM_TABLE; i++) { - if ((fabsf(fx - cmp[i].x) < 0.05f) && - (fabsf(fy - cmp[i].y) < 0.05f)) - { - - curvemap_insert(cuma, fx, fy); + BLI_rctf_transform_pt_v(&but->rect, &cumap->curr, f_xy, &cmp[0].x); + + /* with 160px height 8px should translate to the old 0.05 coefficient at no zoom */ + dist_min_sq = SQUARE(8.0f); + + /* loop through the curve segment table and find what's near the mouse. */ + for (i = 1; i <= CM_TABLE; i++) { + copy_v2_v2(f_xy_prev, f_xy); + BLI_rctf_transform_pt_v(&but->rect, &cumap->curr, f_xy, &cmp[i].x); + + if (dist_squared_to_line_segment_v2(m_xy, f_xy_prev, f_xy) < dist_min_sq) { + BLI_rctf_transform_pt_v(&cumap->curr, &but->rect, f_xy, m_xy); + + curvemap_insert(cuma, f_xy[0], f_xy[1]); curvemapping_changed(cumap, false); changed = true; @@ -6070,10 +6069,11 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt cmp = cuma->curve; /* find newly added point and make it 'sel' */ - for (a = 0; a < cuma->totpoint; a++) - if (cmp[a].x == fx) + for (a = 0; a < cuma->totpoint; a++) { + if (cmp[a].x == f_xy[0]) { sel = a; - + } + } break; } } diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index 423c48e5f55..8b41302b5bb 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -417,6 +417,11 @@ void uiStyleInit(void) blf_mono_font = -1; } + if (blf_mono_font_render != -1) { + BLF_unload_id(blf_mono_font_render); + blf_mono_font_render = -1; + } + font = U.uifonts.first; /* default builtin */ @@ -516,7 +521,12 @@ void uiStyleInit(void) BLF_size(blf_mono_font, 12 * U.pixelsize, 72); - /* second for rendering else we get threading problems */ + /** + * Second for rendering else we get threading problems, + * + * \note This isn't good that the render font depends on the preferences, + * keep for now though, since without this there is no way to display many unicode chars. + */ if (blf_mono_font_render == -1) blf_mono_font_render = BLF_load_mem_unique("monospace", monofont_ttf, monofont_size); diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index 84ae35fae6e..5d5731a7e16 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -2453,7 +2453,7 @@ static void select_linked_delimit_begin(BMesh *bm, int delimit) const bool is_walk_ok = ( (select_linked_delimit_test(e, delimit, &delimit_data) == false)); - BMO_elem_flag_set(bm, e, BMO_ELE_TAG, is_walk_ok); + BMO_edge_flag_set(bm, e, BMO_ELE_TAG, is_walk_ok); } } } @@ -2496,7 +2496,7 @@ static int edbm_select_linked_exec(bContext *C, wmOperator *op) if (delimit) { BMEdge *e; BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { - if (!BMO_elem_flag_test(bm, e, BMO_ELE_TAG)) { + if (!BMO_edge_flag_test(bm, e, BMO_ELE_TAG)) { BM_elem_flag_disable(e->v1, BM_ELEM_TAG); BM_elem_flag_disable(e->v2, BM_ELEM_TAG); } @@ -2552,7 +2552,7 @@ static int edbm_select_linked_exec(bContext *C, wmOperator *op) BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { BM_elem_flag_set( e, BM_ELEM_TAG, - (BM_elem_flag_test(e, BM_ELEM_SELECT) && BMO_elem_flag_test(bm, e, BMO_ELE_TAG))); + (BM_elem_flag_test(e, BM_ELEM_SELECT) && BMO_edge_flag_test(bm, e, BMO_ELE_TAG))); } } else { diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index efe179790da..9f1602ccfaf 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -2910,7 +2910,7 @@ static int edbm_knife_cut_exec(bContext *C, wmOperator *op) } } - BMO_elem_flag_set(bm, be, ELE_EDGE_CUT, is_cut); + BMO_edge_flag_set(bm, be, ELE_EDGE_CUT, is_cut); } @@ -2982,7 +2982,9 @@ static Base *mesh_separate_tagged(Main *bmain, Scene *scene, Base *base_old, BMe Object *obedit = base_old->object; BMesh *bm_new; - bm_new = BM_mesh_create(&bm_mesh_allocsize_default); + bm_new = BM_mesh_create( + &bm_mesh_allocsize_default, + &((struct BMeshCreateParams){.use_toolflags = true,})); BM_mesh_elem_toolflags_ensure(bm_new); /* needed for 'duplicate' bmo */ CustomData_copy(&bm_old->vdata, &bm_new->vdata, CD_MASK_BMESH, CD_CALLOC, 0); @@ -3294,7 +3296,9 @@ static int edbm_separate_exec(bContext *C, wmOperator *op) BMesh *bm_old = NULL; int retval_iter = 0; - bm_old = BM_mesh_create(&bm_mesh_allocsize_default); + bm_old = BM_mesh_create( + &bm_mesh_allocsize_default, + &((struct BMeshCreateParams){.use_toolflags = true,})); BM_mesh_bm_from_me(bm_old, me, (&(struct BMeshFromMeshParams){0})); diff --git a/source/blender/editors/mesh/editmesh_undo.c b/source/blender/editors/mesh/editmesh_undo.c index 36a90a0fdba..faa975406ce 100644 --- a/source/blender/editors/mesh/editmesh_undo.c +++ b/source/blender/editors/mesh/editmesh_undo.c @@ -114,7 +114,7 @@ static struct { TaskPool *task_pool; #endif -} um_arraystore = {NULL}; +} um_arraystore = {{NULL}}; static void um_arraystore_cd_compact( struct CustomData *cdata, const size_t data_len, @@ -563,7 +563,9 @@ static void undoMesh_to_editbtMesh(void *um_v, void *em_v, void *obdata) EDBM_mesh_free(em); - bm = BM_mesh_create(&allocsize); + bm = BM_mesh_create( + &allocsize, + &((struct BMeshCreateParams){.use_toolflags = true,})); BM_mesh_bm_from_me( bm, &um->me, (&(struct BMeshFromMeshParams){ diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c index 99be37845ee..5101608246a 100644 --- a/source/blender/editors/mesh/editmesh_utils.c +++ b/source/blender/editors/mesh/editmesh_utils.c @@ -354,7 +354,9 @@ void EDBM_mesh_make(ToolSettings *ts, Object *ob, const bool add_key_index) BKE_mesh_convert_mfaces_to_mpolys(me); } - bm = BKE_mesh_to_bmesh(me, ob, add_key_index); + bm = BKE_mesh_to_bmesh( + me, ob, add_key_index, + &((struct BMeshCreateParams){.use_toolflags = true,})); if (me->edit_btmesh) { /* this happens when switching shape keys */ @@ -399,10 +401,25 @@ void EDBM_mesh_load(Object *ob) BKE_mesh_tessface_calc(me); #endif - /* free derived mesh. usually this would happen through depsgraph but there + /* Free derived mesh. usually this would happen through depsgraph but there * are exceptions like file save that will not cause this, and we want to - * avoid ending up with an invalid derived mesh then */ - BKE_object_free_derived_caches(ob); + * avoid ending up with an invalid derived mesh then. + * + * Do it for all objects which shares the same mesh datablock, since their + * derived meshes might also be referencing data which was just freed, + * + * Annoying enough, but currently seems most efficient way to avoid access + * of freed data on scene update, especially in cases when there are dependency + * cycles. + */ + for (Object *other_object = G.main->object.first; + other_object != NULL; + other_object = other_object->id.next) + { + if (other_object->data == ob->data) { + BKE_object_free_derived_caches(other_object); + } + } } /** diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index f85c76291cd..0f1c72fcd55 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -73,6 +73,7 @@ #include "BKE_lamp.h" #include "BKE_lattice.h" #include "BKE_library.h" +#include "BKE_library_query.h" #include "BKE_key.h" #include "BKE_main.h" #include "BKE_material.h" @@ -1108,11 +1109,18 @@ static void object_delete_check_glsl_update(Object *ob) /* note: now unlinks constraints as well */ void ED_base_object_free_and_unlink(Main *bmain, Scene *scene, Base *base) { - DAG_id_type_tag(bmain, ID_OB); + if (BKE_library_ID_is_indirectly_used(bmain, base->object) && ID_REAL_USERS(base->object) <= 1) { + /* We cannot delete indirectly used object... */ + printf("WARNING, undeletable object '%s', should have been catched before reaching this function!", + base->object->id.name + 2); + return; + } + BKE_scene_base_unlink(scene, base); object_delete_check_glsl_update(base->object); BKE_libblock_free_us(bmain, base->object); MEM_freeN(base); + DAG_id_type_tag(bmain, ID_OB); } static int object_delete_exec(bContext *C, wmOperator *op) @@ -1129,6 +1137,19 @@ static int object_delete_exec(bContext *C, wmOperator *op) CTX_DATA_BEGIN (C, Base *, base, selected_bases) { + const bool is_indirectly_used = BKE_library_ID_is_indirectly_used(bmain, base->object); + if (base->object->id.tag & LIB_TAG_INDIRECT) { + /* Can this case ever happen? */ + BKE_reportf(op->reports, RPT_WARNING, "Cannot delete indirectly linked object '%s'", base->object->id.name + 2); + continue; + } + else if (is_indirectly_used && ID_REAL_USERS(base->object) <= 1) { + BKE_reportf(op->reports, RPT_WARNING, + "Cannot delete object '%s' from scene '%s', indirectly used objects need at least one user", + base->object->id.name + 2, scene->id.name + 2); + continue; + } + /* deselect object -- it could be used in other scenes */ base->object->flag &= ~SELECT; @@ -1144,6 +1165,12 @@ static int object_delete_exec(bContext *C, wmOperator *op) if (scene_iter != scene && !(scene_iter->id.lib)) { base_other = BKE_scene_base_find(scene_iter, base->object); if (base_other) { + if (is_indirectly_used && ID_REAL_USERS(base->object) <= 1) { + BKE_reportf(op->reports, RPT_WARNING, + "Cannot delete object '%s' from scene '%s', indirectly used objects need at least one user", + base->object->id.name + 2, scene_iter->id.name + 2); + break; + } ED_base_object_free_and_unlink(bmain, scene_iter, base_other); } } diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c index efd1ebbd51b..d7b7fd7040e 100644 --- a/source/blender/editors/object/object_constraint.c +++ b/source/blender/editors/object/object_constraint.c @@ -1560,12 +1560,12 @@ void OBJECT_OT_constraints_copy(wmOperatorType *ot) /************************ add constraint operators *********************/ /* get the Object and/or PoseChannel to use as target */ -static short get_new_constraint_target(bContext *C, int con_type, Object **tar_ob, bPoseChannel **tar_pchan, short add) +static bool get_new_constraint_target(bContext *C, int con_type, Object **tar_ob, bPoseChannel **tar_pchan, bool add) { Object *obact = ED_object_active_context(C); bPoseChannel *pchanact = BKE_pose_channel_active(obact); - short only_curve = 0, only_mesh = 0, only_ob = 0; - short found = 0; + bool only_curve = false, only_mesh = false, only_ob = false; + bool found = false; /* clear tar_ob and tar_pchan fields before use * - assume for now that both always exist... @@ -1585,7 +1585,7 @@ static short get_new_constraint_target(bContext *C, int con_type, Object **tar_o case CONSTRAINT_TYPE_ROTLIMIT: case CONSTRAINT_TYPE_SIZELIMIT: case CONSTRAINT_TYPE_SAMEVOL: - return 0; + return false; /* restricted target-type constraints -------------- */ /* NOTE: for these, we cannot try to add a target object if no valid ones are found, since that doesn't work */ @@ -1593,26 +1593,26 @@ static short get_new_constraint_target(bContext *C, int con_type, Object **tar_o case CONSTRAINT_TYPE_CLAMPTO: case CONSTRAINT_TYPE_FOLLOWPATH: case CONSTRAINT_TYPE_SPLINEIK: - only_curve = 1; - only_ob = 1; - add = 0; + only_curve = true; + only_ob = true; + add = false; break; /* mesh only? */ case CONSTRAINT_TYPE_SHRINKWRAP: - only_mesh = 1; - only_ob = 1; - add = 0; + only_mesh = true; + only_ob = true; + add = false; break; /* object only - add here is ok? */ case CONSTRAINT_TYPE_RIGIDBODYJOINT: - only_ob = 1; + only_ob = true; break; } /* if the active Object is Armature, and we can search for bones, do so... */ - if ((obact->type == OB_ARMATURE) && (only_ob == 0)) { + if ((obact->type == OB_ARMATURE) && (only_ob == false)) { /* search in list of selected Pose-Channels for target */ CTX_DATA_BEGIN (C, bPoseChannel *, pchan, selected_pose_bones) { @@ -1620,7 +1620,7 @@ static short get_new_constraint_target(bContext *C, int con_type, Object **tar_o if (pchan != pchanact) { *tar_ob = obact; *tar_pchan = pchan; - found = 1; + found = true; break; } @@ -1629,36 +1629,50 @@ static short get_new_constraint_target(bContext *C, int con_type, Object **tar_o } /* if not yet found, try selected Objects... */ - if (found == 0) { + if (found == false) { /* search in selected objects context */ CTX_DATA_BEGIN (C, Object *, ob, selected_objects) { /* just use the first object we encounter (that isn't the active object) * and which fulfills the criteria for the object-target that we've got */ - if ((ob != obact) && - ((!only_curve) || (ob->type == OB_CURVE)) && - ((!only_mesh) || (ob->type == OB_MESH))) - { - /* set target */ - *tar_ob = ob; - found = 1; - - /* perform some special operations on the target */ - if (only_curve) { - /* Curve-Path option must be enabled for follow-path constraints to be able to work */ - Curve *cu = (Curve *)ob->data; - cu->flag |= CU_PATH; + if (ob != obact) { + /* for armatures in pose mode, look inside the armature for the active bone + * so that we set up cross-armature constraints with less effort + */ + if ((ob->type == OB_ARMATURE) && (ob->mode & OB_MODE_POSE) && + (!only_curve && !only_mesh)) + { + /* just use the active bone, and assume that it is visible + usable */ + *tar_ob = ob; + *tar_pchan = BKE_pose_channel_active(ob); + found = true; + + break; + } + else if (((!only_curve) || (ob->type == OB_CURVE)) && + ((!only_mesh) || (ob->type == OB_MESH))) + { + /* set target */ + *tar_ob = ob; + found = true; + + /* perform some special operations on the target */ + if (only_curve) { + /* Curve-Path option must be enabled for follow-path constraints to be able to work */ + Curve *cu = (Curve *)ob->data; + cu->flag |= CU_PATH; + } + + break; } - - break; } } CTX_DATA_END; } /* if still not found, add a new empty to act as a target (if allowed) */ - if ((found == 0) && (add)) { + if ((found == false) && (add)) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); Base *base = BASACT, *newbase = NULL; @@ -1692,7 +1706,7 @@ static short get_new_constraint_target(bContext *C, int con_type, Object **tar_o /* make our new target the new object */ *tar_ob = obt; - found = 1; + found = true; } /* return whether there's any target */ diff --git a/source/blender/editors/object/object_group.c b/source/blender/editors/object/object_group.c index 2b87a890f0f..bcdd170c53c 100644 --- a/source/blender/editors/object/object_group.c +++ b/source/blender/editors/object/object_group.c @@ -528,7 +528,7 @@ static int group_unlink_exec(bContext *C, wmOperator *UNUSED(op)) if (!group) return OPERATOR_CANCELLED; - BKE_libblock_unlink(bmain, group, false); + BKE_libblock_unlink(bmain, group, false, false); BKE_libblock_free(bmain, group); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, NULL); diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index 827f83aa425..6ed969cb270 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -5858,7 +5858,9 @@ static int add_simple_uvs_exec(bContext *C, wmOperator *UNUSED(op)) Mesh *me = ob->data; bool synch_selection = (scene->toolsettings->uv_flag & UV_SYNC_SELECTION) != 0; - BMesh *bm = BM_mesh_create(&bm_mesh_allocsize_default); + BMesh *bm = BM_mesh_create( + &bm_mesh_allocsize_default, + &((struct BMeshCreateParams){.use_toolflags = false,})); /* turn synch selection off, since we are not in edit mode we need to ensure only the uv flags are tested */ scene->toolsettings->uv_flag &= ~UV_SYNC_SELECTION; diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index c173156de3a..0931456058d 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -5001,7 +5001,9 @@ void sculpt_dynamic_topology_enable(bContext *C) BKE_mesh_mselect_clear(me); /* Create triangles-only BMesh */ - ss->bm = BM_mesh_create(&allocsize); + ss->bm = BM_mesh_create( + &allocsize, + &((struct BMeshCreateParams){.use_toolflags = false,})); BM_mesh_bm_from_me( ss->bm, me, (&(struct BMeshFromMeshParams){ @@ -5011,7 +5013,9 @@ void sculpt_dynamic_topology_enable(bContext *C) BM_data_layer_add(ss->bm, &ss->bm->vdata, CD_PAINT_MASK); sculpt_dyntopo_node_layers_add(ss); /* make sure the data for existing faces are initialized */ - BM_mesh_normals_update(ss->bm); + if (me->totpoly != ss->bm->totface) { + BM_mesh_normals_update(ss->bm); + } /* Enable dynamic topology */ me->flag |= ME_SCULPT_DYNAMIC_TOPOLOGY; @@ -5088,6 +5092,8 @@ static int sculpt_dynamic_topology_toggle_exec(bContext *C, wmOperator *UNUSED(o Object *ob = CTX_data_active_object(C); SculptSession *ss = ob->sculpt; + WM_cursor_wait(1); + if (ss->bm) { sculpt_undo_push_begin("Dynamic topology disable"); sculpt_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_END); @@ -5100,16 +5106,24 @@ static int sculpt_dynamic_topology_toggle_exec(bContext *C, wmOperator *UNUSED(o } sculpt_undo_push_end(C); + WM_cursor_wait(0); + return OPERATOR_FINISHED; } +enum eDynTopoWarnFlag { + DYNTOPO_WARN_VDATA = (1 << 0), + DYNTOPO_WARN_EDATA = (1 << 1), + DYNTOPO_WARN_LDATA = (1 << 2), + DYNTOPO_WARN_MODIFIER = (1 << 3), +}; -static int dyntopo_warning_popup(bContext *C, wmOperatorType *ot, bool vdata, bool modifiers) +static int dyntopo_warning_popup(bContext *C, wmOperatorType *ot, enum eDynTopoWarnFlag flag) { uiPopupMenu *pup = UI_popup_menu_begin(C, IFACE_("Warning!"), ICON_ERROR); uiLayout *layout = UI_popup_menu_layout(pup); - if (vdata) { + if (flag & (DYNTOPO_WARN_VDATA | DYNTOPO_WARN_EDATA | DYNTOPO_WARN_LDATA)) { const char *msg_error = TIP_("Vertex Data Detected!"); const char *msg = TIP_("Dyntopo will not preserve vertex colors, UVs, or other customdata"); uiItemL(layout, msg_error, ICON_INFO); @@ -5117,7 +5131,7 @@ static int dyntopo_warning_popup(bContext *C, wmOperatorType *ot, bool vdata, bo uiItemS(layout); } - if (modifiers) { + if (flag & DYNTOPO_WARN_MODIFIER) { const char *msg_error = TIP_("Generative Modifiers Detected!"); const char *msg = TIP_("Keeping the modifiers will increase polycount when returning to object mode"); @@ -5133,33 +5147,35 @@ static int dyntopo_warning_popup(bContext *C, wmOperatorType *ot, bool vdata, bo return OPERATOR_INTERFACE; } - -static int sculpt_dynamic_topology_toggle_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) +static enum eDynTopoWarnFlag sculpt_dynamic_topology_check(bContext *C) { Object *ob = CTX_data_active_object(C); Mesh *me = ob->data; SculptSession *ss = ob->sculpt; - if (!ss->bm) { - Scene *scene = CTX_data_scene(C); - ModifierData *md; - VirtualModifierData virtualModifierData; - int i; - bool vdata = false; - bool modifiers = false; - - for (i = 0; i < CD_NUMTYPES; i++) { - if (!ELEM(i, CD_MVERT, CD_MEDGE, CD_MFACE, CD_MLOOP, CD_MPOLY, CD_PAINT_MASK, CD_ORIGINDEX) && - (CustomData_has_layer(&me->vdata, i) || - CustomData_has_layer(&me->edata, i) || - CustomData_has_layer(&me->ldata, i))) - { - vdata = true; - break; + Scene *scene = CTX_data_scene(C); + enum eDynTopoWarnFlag flag = 0; + + BLI_assert(ss->bm == NULL); + UNUSED_VARS_NDEBUG(ss); + + for (int i = 0; i < CD_NUMTYPES; i++) { + if (!ELEM(i, CD_MVERT, CD_MEDGE, CD_MFACE, CD_MLOOP, CD_MPOLY, CD_PAINT_MASK, CD_ORIGINDEX)) { + if (CustomData_has_layer(&me->vdata, i)) { + flag |= DYNTOPO_WARN_VDATA; + } + if (CustomData_has_layer(&me->edata, i)) { + flag |= DYNTOPO_WARN_EDATA; + } + if (CustomData_has_layer(&me->ldata, i)) { + flag |= DYNTOPO_WARN_LDATA; } } + } - md = modifiers_getVirtualModifierList(ob, &virtualModifierData); + { + VirtualModifierData virtualModifierData; + ModifierData *md = modifiers_getVirtualModifierList(ob, &virtualModifierData); /* exception for shape keys because we can edit those */ for (; md; md = md->next) { @@ -5167,14 +5183,26 @@ static int sculpt_dynamic_topology_toggle_invoke(bContext *C, wmOperator *op, co if (!modifier_isEnabled(scene, md, eModifierMode_Realtime)) continue; if (mti->type == eModifierTypeType_Constructive) { - modifiers = true; + flag |= DYNTOPO_WARN_MODIFIER; break; } } + } - if (vdata || modifiers) { + return flag; +} + +static int sculpt_dynamic_topology_toggle_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) +{ + Object *ob = CTX_data_active_object(C); + SculptSession *ss = ob->sculpt; + + if (!ss->bm) { + enum eDynTopoWarnFlag flag = sculpt_dynamic_topology_check(C); + + if (flag) { /* The mesh has customdata that will be lost, let the user confirm this is OK */ - return dyntopo_warning_popup(C, op->type, vdata, modifiers); + return dyntopo_warning_popup(C, op->type, flag); } } @@ -5249,6 +5277,8 @@ static int sculpt_symmetrize_exec(bContext *C, wmOperator *UNUSED(op)) sculpt_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_SYMMETRIZE); BM_log_before_all_removed(ss->bm, ss->bm_log); + BM_mesh_toolflags_set(ss->bm, true); + /* Symmetrize and re-triangulate */ BMO_op_callf(ss->bm, BMO_FLAG_DEFAULTS, "symmetrize input=%avef direction=%i dist=%f", @@ -5258,6 +5288,8 @@ static int sculpt_symmetrize_exec(bContext *C, wmOperator *UNUSED(op)) /* bisect operator flags edges (keep tags clean for edge queue) */ BM_mesh_elem_hflag_disable_all(ss->bm, BM_EDGE, BM_ELEM_TAG, false); + BM_mesh_toolflags_set(ss->bm, false); + /* Finish undo */ BM_log_all_added(ss->bm, ss->bm_log); sculpt_undo_push_end(C); @@ -5327,6 +5359,9 @@ static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op) * mode to ensure the undo stack stays in a consistent * state */ sculpt_dynamic_topology_toggle_exec(C, NULL); + + /* store so we know to re-enable when entering sculpt mode */ + me->flag |= ME_SCULPT_DYNAMIC_TOPOLOGY; } /* Leave sculptmode */ @@ -5340,12 +5375,6 @@ static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op) /* Enter sculptmode */ ob->mode |= mode_flag; - /* Remove dynamic-topology flag; this will be enabled if the - * file was saved with dynamic topology on, but we don't - * automatically re-enter dynamic-topology mode when loading a - * file. */ - me->flag &= ~ME_SCULPT_DYNAMIC_TOPOLOGY; - if (flush_recalc) DAG_id_tag_update(&ob->id, OB_RECALC_DATA); @@ -5399,6 +5428,49 @@ static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op) BKE_paint_init(scene, ePaintSculpt, PAINT_CURSOR_SCULPT); paint_cursor_start(C, sculpt_poll_view3d); + + /* Check dynamic-topology flag; re-enter dynamic-topology mode when changing modes, + * As long as no data was added that is not supported. */ + if (me->flag & ME_SCULPT_DYNAMIC_TOPOLOGY) { + const char *message_unsupported = NULL; + if (me->totloop != me->totpoly * 3) { + message_unsupported = TIP_("non-triangle face"); + } + else if (mmd != NULL) { + message_unsupported = TIP_("multi-res modifier"); + } + else { + enum eDynTopoWarnFlag flag = sculpt_dynamic_topology_check(C); + if (flag == 0) { + /* pass */ + } + else if (flag & DYNTOPO_WARN_VDATA) { + message_unsupported = TIP_("vertex data"); + } + else if (flag & DYNTOPO_WARN_EDATA) { + message_unsupported = TIP_("edge data"); + } + else if (flag & DYNTOPO_WARN_LDATA) { + message_unsupported = TIP_("face data"); + } + else if (flag & DYNTOPO_WARN_MODIFIER) { + message_unsupported = TIP_("constructive modifier"); + } + else { + BLI_assert(0); + } + } + + if (message_unsupported == NULL) { + sculpt_dynamic_topology_enable(C); + } + else { + BKE_reportf(op->reports, RPT_WARNING, + "Dynamic Topology found: %s, disabled", + message_unsupported); + me->flag &= ~ME_SCULPT_DYNAMIC_TOPOLOGY; + } + } } if (ob->derivedFinal) /* VBO no longer valid */ diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c index ceefda99002..44bd872d107 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.c +++ b/source/blender/editors/sculpt_paint/sculpt_undo.c @@ -366,7 +366,9 @@ static void sculpt_undo_bmesh_enable(Object *ob, sculpt_pbvh_clear(ob); /* Create empty BMesh and enable logging */ - ss->bm = BM_mesh_create(&bm_mesh_allocsize_default); + ss->bm = BM_mesh_create( + &bm_mesh_allocsize_default, + &((struct BMeshCreateParams){.use_toolflags = false,})); BM_data_layer_add(ss->bm, &ss->bm->vdata, CD_PAINT_MASK); sculpt_dyntopo_node_layers_add(ss); me->flag |= ME_SCULPT_DYNAMIC_TOPOLOGY; diff --git a/source/blender/editors/space_action/action_select.c b/source/blender/editors/space_action/action_select.c index 0b6d3cb1f60..7900217e28e 100644 --- a/source/blender/editors/space_action/action_select.c +++ b/source/blender/editors/space_action/action_select.c @@ -379,7 +379,7 @@ void ACTION_OT_select_border(wmOperatorType *ot) /* ******************** Region Select Operators ***************************** */ /* "Region Select" operators include the Lasso and Circle Select operators. * These two ended up being lumped together, as it was easier in the - * original Graph Editor implmentation of these to do it this way. + * original Graph Editor implementation of these to do it this way. */ static void region_select_action_keys(bAnimContext *ac, const rctf *rectf_view, short mode, short selectmode, void *data) diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h index 71e38f72a7a..a55b18a2212 100644 --- a/source/blender/editors/space_file/file_intern.h +++ b/source/blender/editors/space_file/file_intern.h @@ -128,6 +128,7 @@ void file_panels_register(struct ARegionType *art); /* file_utils.c */ void file_tile_boundbox(const ARegion *ar, FileLayout *layout, const int file, rcti *r_bounds); +bool file_is_dir(struct SpaceFile *sfile, const char *path); #endif /* __FILE_INTERN_H__ */ diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index d83a7d5ea62..c42ff120102 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -208,7 +208,7 @@ static FileSelect file_select_do(bContext *C, int selected_idx, bool do_diropen) BLI_add_slash(params->dir); } - ED_file_change_dir(C, false); + ED_file_change_dir(C); retval = FILE_SELECT_DIR; } } @@ -826,7 +826,7 @@ static int bookmark_select_exec(bContext *C, wmOperator *op) RNA_property_string_get(op->ptr, prop, entry); BLI_strncpy(params->dir, entry, sizeof(params->dir)); BLI_cleanup_dir(G.main->name, params->dir); - ED_file_change_dir(C, true); + ED_file_change_dir(C); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); } @@ -1379,7 +1379,7 @@ int file_exec(bContext *C, wmOperator *exec_op) BLI_add_slash(sfile->params->dir); } - ED_file_change_dir(C, false); + ED_file_change_dir(C); } /* opening file - sends events now, so things get handled on windowqueue level */ else if (sfile->op) { @@ -1447,19 +1447,7 @@ int file_parent_exec(bContext *C, wmOperator *UNUSED(unused)) if (sfile->params) { if (BLI_parent_dir(sfile->params->dir)) { BLI_cleanup_dir(G.main->name, sfile->params->dir); - /* if not browsing in .blend file, we still want to check whether the path is a directory */ - if (sfile->params->type == FILE_LOADLIB) { - char tdir[FILE_MAX]; - if (BLO_library_path_explode(sfile->params->dir, tdir, NULL, NULL)) { - ED_file_change_dir(C, false); - } - else { - ED_file_change_dir(C, true); - } - } - else { - ED_file_change_dir(C, true); - } + ED_file_change_dir(C); if (sfile->params->recursion_level > 1) { /* Disable 'dirtree' recursion when going up in tree. */ sfile->params->recursion_level = 0; @@ -1529,7 +1517,7 @@ int file_previous_exec(bContext *C, wmOperator *UNUSED(unused)) folderlist_popdir(sfile->folders_prev, sfile->params->dir); folderlist_pushdir(sfile->folders_next, sfile->params->dir); - ED_file_change_dir(C, true); + ED_file_change_dir(C); } WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); @@ -1561,7 +1549,7 @@ int file_next_exec(bContext *C, wmOperator *UNUSED(unused)) // update folders_prev so we can check for it in folderlist_clear_next() folderlist_pushdir(sfile->folders_prev, sfile->params->dir); - ED_file_change_dir(C, true); + ED_file_change_dir(C); } WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); @@ -1809,7 +1797,7 @@ int file_directory_new_exec(bContext *C, wmOperator *op) if (RNA_boolean_get(op->ptr, "open")) { BLI_strncpy(sfile->params->dir, path, sizeof(sfile->params->dir)); - ED_file_change_dir(C, true); + ED_file_change_dir(C); } WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); @@ -1906,17 +1894,35 @@ void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UN file_expand_directory(C); /* special case, user may have pasted a filepath into the directory */ - if (BLI_is_file(sfile->params->dir)) { - char path[sizeof(sfile->params->dir)]; - BLI_strncpy(path, sfile->params->dir, sizeof(path)); - BLI_split_dirfile(path, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file)); + if (!file_is_dir(sfile, sfile->params->dir)) { + char tdir[FILE_MAX_LIBEXTRA]; + char *group, *name; + + if (BLI_is_file(sfile->params->dir)) { + char path[sizeof(sfile->params->dir)]; + BLI_strncpy(path, sfile->params->dir, sizeof(path)); + BLI_split_dirfile(path, sfile->params->dir, sfile->params->file, + sizeof(sfile->params->dir), sizeof(sfile->params->file)); + } + else if (BLO_library_path_explode(sfile->params->dir, tdir, &group, &name)) { + if (group) { + BLI_path_append(tdir, sizeof(tdir), group); + } + BLI_strncpy(sfile->params->dir, tdir, sizeof(sfile->params->dir)); + if (name) { + BLI_strncpy(sfile->params->file, name, sizeof(sfile->params->file)); + } + else { + sfile->params->file[0] = '\0'; + } + } } BLI_cleanup_dir(G.main->name, sfile->params->dir); - if (BLI_exists(sfile->params->dir)) { + if (file_is_dir(sfile, sfile->params->dir)) { /* if directory exists, enter it immediately */ - ED_file_change_dir(C, true); + ED_file_change_dir(C); /* don't do for now because it selects entire text instead of * placing cursor at the end */ @@ -1931,20 +1937,26 @@ void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UN #endif else { const char *lastdir = folderlist_peeklastdir(sfile->folders_prev); + char tdir[FILE_MAX_LIBEXTRA]; - /* if not, ask to create it and enter if confirmed */ - wmOperatorType *ot = WM_operatortype_find("FILE_OT_directory_new", false); - PointerRNA ptr; - WM_operator_properties_create_ptr(&ptr, ot); - RNA_string_set(&ptr, "directory", sfile->params->dir); - RNA_boolean_set(&ptr, "open", true); - - if (lastdir) + /* If we are 'inside' a blend library, we cannot do anything... */ + if (lastdir && BLO_library_path_explode(lastdir, tdir, NULL, NULL)) { BLI_strncpy(sfile->params->dir, lastdir, sizeof(sfile->params->dir)); - - - WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr); - WM_operator_properties_free(&ptr); + } + else { + /* if not, ask to create it and enter if confirmed */ + wmOperatorType *ot = WM_operatortype_find("FILE_OT_directory_new", false); + PointerRNA ptr; + WM_operator_properties_create_ptr(&ptr, ot); + RNA_string_set(&ptr, "directory", sfile->params->dir); + RNA_boolean_set(&ptr, "open", true); + + if (lastdir) + BLI_strncpy(sfile->params->dir, lastdir, sizeof(sfile->params->dir)); + + WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr); + WM_operator_properties_free(&ptr); + } } WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); @@ -1971,8 +1983,6 @@ void file_filename_enter_handle(bContext *C, void *UNUSED(arg_unused), void *arg BLI_filename_make_safe(sfile->params->file); if (matches) { - /* int i, numfiles = filelist_numfiles(sfile->files); */ /* XXX UNUSED */ - sfile->params->file[0] = '\0'; /* replace the pattern (or filename that the user typed in, with the first selected file of the match */ BLI_strncpy(sfile->params->file, matched_file, sizeof(sfile->params->file)); @@ -1980,30 +1990,17 @@ void file_filename_enter_handle(bContext *C, void *UNUSED(arg_unused), void *arg } if (matches == 1) { - BLI_join_dirfile(filepath, sizeof(sfile->params->dir), sfile->params->dir, sfile->params->file); /* if directory, open it and empty filename field */ - if (BLI_is_dir(filepath)) { + if (file_is_dir(sfile, filepath)) { BLI_cleanup_dir(G.main->name, filepath); BLI_strncpy(sfile->params->dir, filepath, sizeof(sfile->params->dir)); sfile->params->file[0] = '\0'; - ED_file_change_dir(C, true); + ED_file_change_dir(C); UI_textbutton_activate_but(C, but); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); } - else if (sfile->params->type == FILE_LOADLIB) { - char tdir[FILE_MAX]; - BLI_add_slash(filepath); - if (BLO_library_path_explode(filepath, tdir, NULL, NULL)) { - BLI_cleanup_dir(G.main->name, filepath); - BLI_strncpy(sfile->params->dir, filepath, sizeof(sfile->params->dir)); - sfile->params->file[0] = '\0'; - ED_file_change_dir(C, false); - UI_textbutton_activate_but(C, but); - WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); - } - } } else if (matches > 1) { file_draw_check(C); diff --git a/source/blender/editors/space_file/file_utils.c b/source/blender/editors/space_file/file_utils.c index 3c007f25da3..f19e301064d 100644 --- a/source/blender/editors/space_file/file_utils.c +++ b/source/blender/editors/space_file/file_utils.c @@ -25,6 +25,9 @@ */ #include "BLI_rect.h" +#include "BLI_fileops.h" + +#include "BLO_readfile.h" #include "BKE_context.h" @@ -45,3 +48,17 @@ void file_tile_boundbox(const ARegion *ar, FileLayout *layout, const int file, r BLI_rcti_init(r_bounds, xmin, xmin + layout->tile_w + layout->tile_border_x, ymax - layout->tile_h - layout->tile_border_y, ymax); } + +/* Cannot directly use BLI_is_dir in libloading context... */ +bool file_is_dir(struct SpaceFile *sfile, const char *path) +{ + if (sfile->params->type == FILE_LOADLIB) { + char tdir[FILE_MAX_LIBEXTRA]; + char *name; + if (BLO_library_path_explode(sfile->params->dir, tdir, NULL, &name) && BLI_is_file(tdir)) { + /* .blend file itself and group are considered as directories, not final datablock names. */ + return name ? false : true; + } + } + return BLI_is_dir(path); +} diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index fc3341bfb92..5e9eb1f9207 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -624,7 +624,7 @@ static bool is_filtered_file(FileListInternEntry *file, const char *UNUSED(root) static bool is_filtered_lib(FileListInternEntry *file, const char *root, FileListFilter *filter) { bool is_filtered; - char path[FILE_MAX_LIBEXTRA], dir[FILE_MAXDIR], *group, *name; + char path[FILE_MAX_LIBEXTRA], dir[FILE_MAX_LIBEXTRA], *group, *name; BLI_join_dirfile(path, sizeof(path), root, file->relpath); @@ -697,7 +697,7 @@ void filelist_filter(FileList *filelist) if (filelist->max_recursion) { /* Never show lib ID 'categories' directories when we are in 'flat' mode, unless * root path is a blend file. */ - char dir[FILE_MAXDIR]; + char dir[FILE_MAX_LIBEXTRA]; if (!filelist_islibrary(filelist, dir, NULL)) { filelist->filter_data.flags |= FLF_HIDE_LIB_DIR; } @@ -947,7 +947,7 @@ static void filelist_checkdir_dir(struct FileList *UNUSED(filelist), char *r_dir static void filelist_checkdir_lib(struct FileList *UNUSED(filelist), char *r_dir) { - char dir[FILE_MAXDIR]; + char dir[FILE_MAX_LIBEXTRA]; if (!BLO_library_path_explode(r_dir, dir, NULL, NULL)) { /* if not a valid library, we need it to be a valid directory! */ BLI_make_exist(r_dir); @@ -2113,6 +2113,7 @@ unsigned int filelist_entry_select_index_get(FileList *filelist, const int index return 0; } +/* WARNING! dir must be FILE_MAX_LIBEXTRA long! */ bool filelist_islibrary(struct FileList *filelist, char *dir, char **group) { return BLO_library_path_explode(filelist->filelist.root, dir, group, NULL); @@ -2208,7 +2209,7 @@ static int filelist_readjob_list_lib(const char *root, ListBase *entries, const FileListInternEntry *entry; LinkNode *ln, *names; int i, nnames, idcode = 0, nbr_entries = 0; - char dir[FILE_MAX], *group; + char dir[FILE_MAX_LIBEXTRA], *group; bool ok; struct BlendHandle *libfiledata = NULL; diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index bf90a4ea170..175d83506c6 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -576,7 +576,7 @@ FileLayout *ED_fileselect_get_layout(struct SpaceFile *sfile, ARegion *ar) return sfile->layout; } -void ED_file_change_dir(bContext *C, const bool checkdir) +void ED_file_change_dir(bContext *C) { wmWindowManager *wm = CTX_wm_manager(C); SpaceFile *sfile = CTX_wm_space_file(C); @@ -590,7 +590,7 @@ void ED_file_change_dir(bContext *C, const bool checkdir) sfile->params->filter_search[0] = '\0'; sfile->params->active_file = -1; - if (checkdir && !BLI_is_dir(sfile->params->dir)) { + if (!file_is_dir(sfile, sfile->params->dir)) { BLI_strncpy(sfile->params->dir, filelist_dir(sfile->files), sizeof(sfile->params->dir)); /* could return but just refresh the current dir */ } diff --git a/source/blender/editors/space_graph/space_graph.c b/source/blender/editors/space_graph/space_graph.c index a7284694f64..8ae5932f3fd 100644 --- a/source/blender/editors/space_graph/space_graph.c +++ b/source/blender/editors/space_graph/space_graph.c @@ -611,6 +611,51 @@ static void graph_refresh(const bContext *C, ScrArea *sa) } break; } + case FCURVE_COLOR_AUTO_YRGB: + { + /* Like FCURVE_COLOR_AUTO_RGB, except this is for quaternions... */ + float *col = fcu->color; + + switch (fcu->array_index) { + case 1: + UI_GetThemeColor3fv(TH_AXIS_X, col); + break; + case 2: + UI_GetThemeColor3fv(TH_AXIS_Y, col); + break; + case 3: + UI_GetThemeColor3fv(TH_AXIS_Z, col); + break; + + case 0: + { + /* Special Case: "W" channel should be yellowish, so blend X and Y channel colors... */ + float c1[3], c2[3]; + float h1[3], h2[3]; + float hresult[3]; + + /* - get colors (rgb) */ + UI_GetThemeColor3fv(TH_AXIS_X, c1); + UI_GetThemeColor3fv(TH_AXIS_Y, c2); + + /* - perform blending in HSV space (to keep brightness similar) */ + rgb_to_hsv_v(c1, h1); + rgb_to_hsv_v(c2, h2); + + interp_v3_v3v3(hresult, h1, h2, 0.5f); + + /* - convert back to RGB for display */ + hsv_to_rgb_v(hresult, col); + break; + } + + default: + /* 'unknown' color - bluish so as to not conflict with handles */ + col[0] = 0.3f; col[1] = 0.8f; col[2] = 1.0f; + break; + } + break; + } case FCURVE_COLOR_AUTO_RAINBOW: default: { diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c index 687869ae727..07608b59d2e 100644 --- a/source/blender/editors/space_outliner/outliner_edit.c +++ b/source/blender/editors/space_outliner/outliner_edit.c @@ -55,6 +55,7 @@ #include "BKE_global.h" #include "BKE_idcode.h" #include "BKE_library.h" +#include "BKE_library_query.h" #include "BKE_library_remap.h" #include "BKE_main.h" #include "BKE_outliner_treehash.h" @@ -243,8 +244,9 @@ static void do_item_rename(ARegion *ar, TreeElement *te, TreeStoreElem *tselem, } } -void item_rename_cb(bContext *C, Scene *UNUSED(scene), TreeElement *te, - TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) +void item_rename_cb( + bContext *C, ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *te, + TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { ARegion *ar = CTX_wm_region(C); ReportList *reports = CTX_wm_reports(C); // XXX @@ -306,7 +308,7 @@ void OUTLINER_OT_item_rename(wmOperatorType *ot) /* ID delete --------------------------------------------------- */ -static void id_delete(bContext *C, TreeElement *te, TreeStoreElem *tselem) +static void id_delete(bContext *C, ReportList *reports, TreeElement *te, TreeStoreElem *tselem) { Main *bmain = CTX_data_main(C); ID *id = tselem->id; @@ -315,16 +317,28 @@ static void id_delete(bContext *C, TreeElement *te, TreeStoreElem *tselem) BLI_assert(te->idcode != ID_LI || ((Library *)id)->parent == NULL); UNUSED_VARS_NDEBUG(te); + if (id->tag & LIB_TAG_INDIRECT) { + BKE_reportf(reports, RPT_WARNING, "Cannot delete indirectly linked id '%s'", id->name); + return; + } + else if (BKE_library_ID_is_indirectly_used(bmain, id) && ID_REAL_USERS(id) <= 1) { + BKE_reportf(reports, RPT_WARNING, + "Cannot delete id '%s', indirectly used datablocks need at least one user", + id->name); + return; + } + + BKE_libblock_delete(bmain, id); WM_event_add_notifier(C, NC_WINDOW, NULL); } void id_delete_cb( - bContext *C, Scene *UNUSED(scene), TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, - void *UNUSED(user_data)) + bContext *C, ReportList *reports, Scene *UNUSED(scene), + TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { - id_delete(C, te, tselem); + id_delete(C, reports, te, tselem); } static int outliner_id_delete_invoke_do(bContext *C, ReportList *reports, TreeElement *te, const float mval[2]) @@ -338,7 +352,7 @@ static int outliner_id_delete_invoke_do(bContext *C, ReportList *reports, TreeEl "Cannot delete indirectly linked library '%s'", ((Library *)tselem->id)->filepath); return OPERATOR_CANCELLED; } - id_delete(C, te, tselem); + id_delete(C, reports, te, tselem); return OPERATOR_FINISHED; } } @@ -399,15 +413,24 @@ static int outliner_id_remap_exec(bContext *C, wmOperator *op) ID *new_id = BLI_findlink(which_libbase(CTX_data_main(C), id_type), RNA_enum_get(op->ptr, "new_id")); /* check for invalid states */ - if (soops == NULL) + if (soops == NULL) { return OPERATOR_CANCELLED; + } if (!(old_id && (old_id != new_id) && (GS(old_id->name) == GS(new_id->name)))) { + BKE_reportf(op->reports, RPT_ERROR_INVALID_INPUT, "Invalid old/new ID pair ('%s' / '%s')", + old_id->name, new_id->name); return OPERATOR_CANCELLED; } + if (old_id->lib) { + BKE_reportf(op->reports, RPT_WARNING, + "Old ID '%s' is linked from a library, indirect usages of this datablock will not be remapped", + old_id->name); + } + BKE_libblock_remap(bmain, old_id, new_id, - ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_NEVER_NULL_USAGE); + ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_NEVER_NULL_USAGE); BKE_main_lib_objects_recalc_all(bmain); @@ -511,7 +534,7 @@ void OUTLINER_OT_id_remap(wmOperatorType *ot) } void id_remap_cb( - bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te), + bContext *C, ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { wmOperatorType *ot = WM_operatortype_find("OUTLINER_OT_id_remap", false); @@ -532,7 +555,7 @@ void id_remap_cb( /* Library relocate/reload --------------------------------------------------- */ static int lib_relocate( - bContext *C, TreeElement *te, TreeStoreElem *tselem, wmOperatorType *ot, const bool reload) + bContext *C, TreeElement *te, TreeStoreElem *tselem, wmOperatorType *ot, const bool reload) { PointerRNA op_props; int ret = 0; @@ -570,7 +593,7 @@ static int lib_relocate( } static int outliner_lib_relocate_invoke_do( - bContext *C, ReportList *reports, TreeElement *te, const float mval[2], const bool reload) + bContext *C, ReportList *reports, TreeElement *te, const float mval[2], const bool reload) { if (mval[1] > te->ys && mval[1] < te->ys + UI_UNIT_Y) { TreeStoreElem *tselem = TREESTORE(te); @@ -633,9 +656,9 @@ void OUTLINER_OT_lib_relocate(wmOperatorType *ot) } /* XXX This does not work with several items - * (it is only called once in the end, due to the 'deffered' filebrowser invocation through event system...). */ + * (it is only called once in the end, due to the 'deferred' filebrowser invocation through event system...). */ void lib_relocate_cb( - bContext *C, Scene *UNUSED(scene), TreeElement *te, + bContext *C, ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { wmOperatorType *ot = WM_operatortype_find("WM_OT_lib_relocate", false); @@ -677,7 +700,7 @@ void OUTLINER_OT_lib_reload(wmOperatorType *ot) } void lib_reload_cb( - bContext *C, Scene *UNUSED(scene), TreeElement *te, + bContext *C, ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { wmOperatorType *ot = WM_operatortype_find("WM_OT_lib_reload", false); @@ -764,8 +787,9 @@ int common_restrict_check(bContext *C, Object *ob) /* Toggle Visibility ---------------------------------------- */ -void object_toggle_visibility_cb(bContext *C, Scene *scene, TreeElement *te, - TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) +void object_toggle_visibility_cb( + bContext *C, ReportList *UNUSED(reports), Scene *scene, TreeElement *te, + TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { Base *base = (Base *)te->directdata; Object *ob = (Object *)tselem->id; @@ -780,21 +804,22 @@ void object_toggle_visibility_cb(bContext *C, Scene *scene, TreeElement *te, } } -void group_toggle_visibility_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te), - TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) +void group_toggle_visibility_cb( + bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *scene, TreeElement *UNUSED(te), + TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { Group *group = (Group *)tselem->id; restrictbutton_gr_restrict_flag(scene, group, OB_RESTRICT_VIEW); } -static int outliner_toggle_visibility_exec(bContext *C, wmOperator *UNUSED(op)) +static int outliner_toggle_visibility_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); SpaceOops *soops = CTX_wm_space_outliner(C); Scene *scene = CTX_data_scene(C); ARegion *ar = CTX_wm_region(C); - outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_visibility_cb); + outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, object_toggle_visibility_cb); DAG_id_type_tag(bmain, ID_OB); WM_event_add_notifier(C, NC_SCENE | ND_OB_VISIBLE, scene); @@ -819,8 +844,9 @@ void OUTLINER_OT_visibility_toggle(wmOperatorType *ot) /* Toggle Selectability ---------------------------------------- */ -void object_toggle_selectability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te, - TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) +void object_toggle_selectability_cb( + bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *scene, TreeElement *te, + TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { Base *base = (Base *)te->directdata; @@ -830,20 +856,21 @@ void object_toggle_selectability_cb(bContext *UNUSED(C), Scene *scene, TreeEleme } } -void group_toggle_selectability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te), - TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) +void group_toggle_selectability_cb( + bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *scene, TreeElement *UNUSED(te), + TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { Group *group = (Group *)tselem->id; restrictbutton_gr_restrict_flag(scene, group, OB_RESTRICT_SELECT); } -static int outliner_toggle_selectability_exec(bContext *C, wmOperator *UNUSED(op)) +static int outliner_toggle_selectability_exec(bContext *C, wmOperator *op) { SpaceOops *soops = CTX_wm_space_outliner(C); Scene *scene = CTX_data_scene(C); ARegion *ar = CTX_wm_region(C); - outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_selectability_cb); + outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, object_toggle_selectability_cb); WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); ED_region_tag_redraw(ar); @@ -867,8 +894,9 @@ void OUTLINER_OT_selectability_toggle(wmOperatorType *ot) /* Toggle Renderability ---------------------------------------- */ -void object_toggle_renderability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te, - TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) +void object_toggle_renderability_cb( + bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *scene, TreeElement *te, + TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { Base *base = (Base *)te->directdata; @@ -878,20 +906,21 @@ void object_toggle_renderability_cb(bContext *UNUSED(C), Scene *scene, TreeEleme } } -void group_toggle_renderability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te), - TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) +void group_toggle_renderability_cb( + bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *scene, TreeElement *UNUSED(te), + TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { Group *group = (Group *)tselem->id; restrictbutton_gr_restrict_flag(scene, group, OB_RESTRICT_RENDER); } -static int outliner_toggle_renderability_exec(bContext *C, wmOperator *UNUSED(op)) +static int outliner_toggle_renderability_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); SpaceOops *soops = CTX_wm_space_outliner(C); Scene *scene = CTX_data_scene(C); - outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_renderability_cb); + outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, object_toggle_renderability_cb); DAG_id_type_tag(bmain, ID_OB); WM_event_add_notifier(C, NC_SCENE | ND_OB_RENDER, scene); diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h index d68815c5e57..d2666cd0b6d 100644 --- a/source/blender/editors/space_outliner/outliner_intern.h +++ b/source/blender/editors/space_outliner/outliner_intern.h @@ -153,44 +153,58 @@ eOLDrawState tree_element_active(struct bContext *C, struct Scene *scene, SpaceO int outliner_item_do_activate(struct bContext *C, int x, int y, bool extend, bool recursive); /* outliner_edit.c ---------------------------------------------- */ +typedef void (*outliner_operation_cb)( + struct bContext *C, struct ReportList *, struct Scene *scene, + struct TreeElement *, struct TreeStoreElem *, TreeStoreElem *, void *); void outliner_do_object_operation_ex( - struct bContext *C, struct Scene *scene, struct SpaceOops *soops, struct ListBase *lb, - void (*operation_cb)(struct bContext *C, struct Scene *scene, - struct TreeElement *, struct TreeStoreElem *, TreeStoreElem *, void *), - bool recurse_selected); + struct bContext *C, ReportList *reports, struct Scene *scene, struct SpaceOops *soops, struct ListBase *lb, + outliner_operation_cb operation_cb, bool recurse_selected); void outliner_do_object_operation( - struct bContext *C, struct Scene *scene, struct SpaceOops *soops, struct ListBase *lb, - void (*operation_cb)(struct bContext *C, struct Scene *scene, - struct TreeElement *, struct TreeStoreElem *, TreeStoreElem *, void *)); + struct bContext *C, ReportList *reports, struct Scene *scene, struct SpaceOops *soops, struct ListBase *lb, + outliner_operation_cb operation_cb); int common_restrict_check(struct bContext *C, struct Object *ob); int outliner_has_one_flag(struct SpaceOops *soops, ListBase *lb, short flag, const int curlevel); void outliner_set_flag(struct SpaceOops *soops, ListBase *lb, short flag, short set); -void object_toggle_visibility_cb(struct bContext *C, struct Scene *scene, TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data); -void object_toggle_selectability_cb(struct bContext *C, struct Scene *scene, TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data); -void object_toggle_renderability_cb(struct bContext *C, struct Scene *scene, TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data); - - -void group_toggle_visibility_cb(struct bContext *C, struct Scene *scene, TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data); -void group_toggle_selectability_cb(struct bContext *C, struct Scene *scene, TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data); -void group_toggle_renderability_cb(struct bContext *C, struct Scene *scene, TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data); - -void item_rename_cb(struct bContext *C, struct Scene *scene, TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data); +void object_toggle_visibility_cb( + struct bContext *C, struct ReportList *reports, struct Scene *scene, + TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data); +void object_toggle_selectability_cb( + struct bContext *C, struct ReportList *reports, struct Scene *scene, + TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data); +void object_toggle_renderability_cb( + struct bContext *C, struct ReportList *reports, struct Scene *scene, + TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data); + + +void group_toggle_visibility_cb( + struct bContext *C, struct ReportList *reports, struct Scene *scene, + TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data); +void group_toggle_selectability_cb( + struct bContext *C, struct ReportList *reports, struct Scene *scene, + TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data); +void group_toggle_renderability_cb( + struct bContext *C, struct ReportList *reports, struct Scene *scene, + TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data); + +void item_rename_cb( + struct bContext *C, struct ReportList *reports, struct Scene *scene, + TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data); void lib_relocate_cb( - struct bContext *C, struct Scene *scene, struct TreeElement *te, + struct bContext *C, struct ReportList *reports, struct Scene *scene, struct TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data); void lib_reload_cb( - struct bContext *C, struct Scene *scene, struct TreeElement *te, + struct bContext *C, struct ReportList *reports, struct Scene *scene, struct TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data); void id_delete_cb( - struct bContext *C, struct Scene *scene, struct TreeElement *te, + struct bContext *C, struct ReportList *reports, struct Scene *scene, struct TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data); void id_remap_cb( - struct bContext *C, struct Scene *scene, struct TreeElement *te, + struct bContext *C, struct ReportList *reports, struct Scene *scene, struct TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data); TreeElement *outliner_dropzone_find(const struct SpaceOops *soops, const float fmval[2], const bool children); diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c index 265df4a8def..bfec62997e1 100644 --- a/source/blender/editors/space_outliner/outliner_tools.c +++ b/source/blender/editors/space_outliner/outliner_tools.c @@ -57,6 +57,7 @@ #include "BKE_fcurve.h" #include "BKE_group.h" #include "BKE_library.h" +#include "BKE_library_query.h" #include "BKE_library_remap.h" #include "BKE_main.h" #include "BKE_report.h" @@ -134,15 +135,17 @@ static void set_operation_types(SpaceOops *soops, ListBase *lb, } } -static void unlink_action_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te), - TreeStoreElem *tsep, TreeStoreElem *UNUSED(tselem), void *UNUSED(user_data)) +static void unlink_action_cb( + bContext *C, ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *UNUSED(te), + TreeStoreElem *tsep, TreeStoreElem *UNUSED(tselem), void *UNUSED(user_data)) { /* just set action to NULL */ BKE_animdata_set_action(CTX_wm_reports(C), tsep->id, NULL); } -static void unlink_material_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *te, - TreeStoreElem *tsep, TreeStoreElem *UNUSED(tselem), void *UNUSED(user_data)) +static void unlink_material_cb( + bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *te, + TreeStoreElem *tsep, TreeStoreElem *UNUSED(tselem), void *UNUSED(user_data)) { Material **matar = NULL; int a, totcol = 0; @@ -181,8 +184,9 @@ static void unlink_material_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeEl } } -static void unlink_texture_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *te, - TreeStoreElem *tsep, TreeStoreElem *UNUSED(tselem), void *UNUSED(user_data)) +static void unlink_texture_cb( + bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *te, + TreeStoreElem *tsep, TreeStoreElem *UNUSED(tselem), void *UNUSED(user_data)) { MTex **mtex = NULL; int a; @@ -218,7 +222,7 @@ static void unlink_texture_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeEle } static void unlink_group_cb( - bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te), + bContext *C, ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *tsep, TreeStoreElem *tselem, void *UNUSED(user_data)) { Group *group = (Group *)tselem->id; @@ -231,13 +235,14 @@ static void unlink_group_cb( } else { Main *bmain = CTX_data_main(C); - BKE_libblock_unlink(bmain, group, false); + BKE_libblock_unlink(bmain, group, false, false); BKE_libblock_free(bmain, group); } } -static void unlink_world_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te), - TreeStoreElem *tsep, TreeStoreElem *tselem, void *UNUSED(user_data)) +static void unlink_world_cb( + bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *UNUSED(te), + TreeStoreElem *tsep, TreeStoreElem *tselem, void *UNUSED(user_data)) { Scene *parscene = (Scene *)tsep->id; World *wo = (World *)tselem->id; @@ -248,8 +253,8 @@ static void unlink_world_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeEleme } static void outliner_do_libdata_operation( - bContext *C, Scene *scene, SpaceOops *soops, ListBase *lb, - void (*operation_cb)(bContext *C, Scene *scene, TreeElement *, TreeStoreElem *, TreeStoreElem *, void *), + bContext *C, ReportList *reports, Scene *scene, SpaceOops *soops, ListBase *lb, + outliner_operation_cb operation_cb, void *user_data) { TreeElement *te; @@ -260,11 +265,11 @@ static void outliner_do_libdata_operation( if (tselem->flag & TSE_SELECTED) { if (tselem->type == 0) { TreeStoreElem *tsep = te->parent ? TREESTORE(te->parent) : NULL; - operation_cb(C, scene, te, tsep, tselem, user_data); + operation_cb(C, reports, scene, te, tsep, tselem, user_data); } } if (TSELEM_OPEN(tselem, soops)) { - outliner_do_libdata_operation(C, scene, soops, &te->subtree, operation_cb, user_data); + outliner_do_libdata_operation(C, reports, scene, soops, &te->subtree, operation_cb, user_data); } } } @@ -354,8 +359,9 @@ void OUTLINER_OT_scene_operation(wmOperatorType *ot) } /* ******************************************** */ -static void object_select_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te, - TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) +static void object_select_cb( + bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *scene, TreeElement *te, + TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { Base *base = (Base *)te->directdata; @@ -366,8 +372,9 @@ static void object_select_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te, } } -static void object_select_hierarchy_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te), - TreeStoreElem *UNUSED(tsep), TreeStoreElem *UNUSED(tselem), void *UNUSED(user_data)) +static void object_select_hierarchy_cb( + bContext *C, ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *UNUSED(te), + TreeStoreElem *UNUSED(tsep), TreeStoreElem *UNUSED(tselem), void *UNUSED(user_data)) { /* From where do i get the x,y coordinate of the mouse event ? */ wmWindow *win = CTX_wm_window(C); @@ -377,8 +384,9 @@ static void object_select_hierarchy_cb(bContext *C, Scene *UNUSED(scene), TreeEl } -static void object_deselect_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te, - TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) +static void object_deselect_cb( + bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *scene, TreeElement *te, + TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { Base *base = (Base *)te->directdata; @@ -389,14 +397,27 @@ static void object_deselect_cb(bContext *UNUSED(C), Scene *scene, TreeElement *t } } -static void object_delete_cb(bContext *C, Scene *scene, TreeElement *te, - TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) +static void object_delete_cb( + bContext *C, ReportList *reports, Scene *scene, TreeElement *te, + TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { Base *base = (Base *)te->directdata; if (base == NULL) base = BKE_scene_base_find(scene, (Object *)tselem->id); if (base) { + Main *bmain = CTX_data_main(C); + if (base->object->id.tag & LIB_TAG_INDIRECT) { + BKE_reportf(reports, RPT_WARNING, "Cannot delete indirectly linked object '%s'", base->object->id.name + 2); + return; + } + else if (BKE_library_ID_is_indirectly_used(bmain, base->object) && ID_REAL_USERS(base->object) <= 1) { + BKE_reportf(reports, RPT_WARNING, + "Cannot delete object '%s' from scene '%s', indirectly used objects need at least one user", + base->object->id.name + 2, scene->id.name + 2); + return; + } + // check also library later if (scene->obedit == base->object) ED_object_editmode_exit(C, EM_FREEDATA | EM_FREEUNDO | EM_WAITCURSOR | EM_DO_UNDO); @@ -410,8 +431,9 @@ static void object_delete_cb(bContext *C, Scene *scene, TreeElement *te, } } -static void id_local_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te), - TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) +static void id_local_cb( + bContext *C, ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *UNUSED(te), + TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { if (tselem->id->lib && (tselem->id->tag & LIB_TAG_EXTERN)) { /* if the ID type has no special local function, @@ -423,32 +445,36 @@ static void id_local_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(t } } -static void id_fake_user_set_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te), - TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) +static void id_fake_user_set_cb( + bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *UNUSED(te), + TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { ID *id = tselem->id; id_fake_user_set(id); } -static void id_fake_user_clear_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te), - TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) +static void id_fake_user_clear_cb( + bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *UNUSED(te), + TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { ID *id = tselem->id; id_fake_user_clear(id); } -static void id_select_linked_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te), - TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) +static void id_select_linked_cb( + bContext *C, ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *UNUSED(te), + TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { ID *id = tselem->id; ED_object_select_linked_by_id(C, id); } -static void singleuser_action_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te), - TreeStoreElem *tsep, TreeStoreElem *tselem, void *UNUSED(user_data)) +static void singleuser_action_cb( + bContext *C, ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *UNUSED(te), + TreeStoreElem *tsep, TreeStoreElem *tselem, void *UNUSED(user_data)) { ID *id = tselem->id; @@ -464,8 +490,9 @@ static void singleuser_action_cb(bContext *C, Scene *UNUSED(scene), TreeElement } } -static void singleuser_world_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te), - TreeStoreElem *tsep, TreeStoreElem *tselem, void *UNUSED(user_data)) +static void singleuser_world_cb( + bContext *C, ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *UNUSED(te), + TreeStoreElem *tsep, TreeStoreElem *tselem, void *UNUSED(user_data)) { ID *id = tselem->id; @@ -482,8 +509,9 @@ static void singleuser_world_cb(bContext *C, Scene *UNUSED(scene), TreeElement * } } -static void group_linkobs2scene_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te), - TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) +static void group_linkobs2scene_cb( + bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *scene, TreeElement *UNUSED(te), + TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { Group *group = (Group *)tselem->id; GroupObject *gob; @@ -508,8 +536,9 @@ static void group_linkobs2scene_cb(bContext *UNUSED(C), Scene *scene, TreeElemen } } -static void group_instance_cb(bContext *C, Scene *scene, TreeElement *UNUSED(te), - TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) +static void group_instance_cb( + bContext *C, ReportList *UNUSED(reports), Scene *scene, TreeElement *UNUSED(te), + TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { Group *group = (Group *)tselem->id; @@ -523,9 +552,8 @@ static void group_instance_cb(bContext *C, Scene *scene, TreeElement *UNUSED(te) * \param select_recurse: Set to false for operations which are already recursively operating on their children. */ void outliner_do_object_operation_ex( - bContext *C, Scene *scene_act, SpaceOops *soops, ListBase *lb, - void (*operation_cb)(bContext *, Scene *, TreeElement *, TreeStoreElem *, TreeStoreElem *, void *), - bool select_recurse) + bContext *C, ReportList *reports, Scene *scene_act, SpaceOops *soops, ListBase *lb, + outliner_operation_cb operation_cb, bool select_recurse) { TreeElement *te; @@ -542,23 +570,24 @@ void outliner_do_object_operation_ex( /* important to use 'scene_owner' not scene_act else deleting objects can crash. * only use 'scene_act' when 'scene_owner' is NULL, which can happen when the * outliner isn't showing scenes: Visible Layer draw mode for eg. */ - operation_cb(C, scene_owner ? scene_owner : scene_act, te, NULL, tselem, NULL); + operation_cb(C, reports, scene_owner ? scene_owner : scene_act, te, NULL, tselem, NULL); select_handled = true; } } if (TSELEM_OPEN(tselem, soops)) { if ((select_handled == false) || select_recurse) { - outliner_do_object_operation_ex(C, scene_act, soops, &te->subtree, operation_cb, select_recurse); + outliner_do_object_operation_ex( + C, reports, scene_act, soops, &te->subtree, operation_cb, select_recurse); } } } } void outliner_do_object_operation( - bContext *C, Scene *scene_act, SpaceOops *soops, ListBase *lb, - void (*operation_cb)(bContext *, Scene *, TreeElement *, TreeStoreElem *, TreeStoreElem *, void *)) + bContext *C, ReportList *reports, Scene *scene_act, SpaceOops *soops, ListBase *lb, + outliner_operation_cb operation_cb) { - outliner_do_object_operation_ex(C, scene_act, soops, lb, operation_cb, true); + outliner_do_object_operation_ex(C, reports, scene_act, soops, lb, operation_cb, true); } /* ******************************************** */ @@ -793,7 +822,7 @@ static void outliner_do_data_operation(SpaceOops *soops, int type, int event, Li } } -static Base *outline_delete_hierarchy(bContext *C, Scene *scene, Base *base) +static Base *outline_delete_hierarchy(bContext *C, ReportList *reports, Scene *scene, Base *base) { Base *child_base, *base_next; Object *parent; @@ -806,17 +835,30 @@ static Base *outline_delete_hierarchy(bContext *C, Scene *scene, Base *base) base_next = child_base->next; for (parent = child_base->object->parent; parent && (parent != base->object); parent = parent->parent); if (parent) { - base_next = outline_delete_hierarchy(C, scene, child_base); + base_next = outline_delete_hierarchy(C, reports, scene, child_base); } } base_next = base->next; + + Main *bmain = CTX_data_main(C); + if (base->object->id.tag & LIB_TAG_INDIRECT) { + BKE_reportf(reports, RPT_WARNING, "Cannot delete indirectly linked object '%s'", base->object->id.name + 2); + return base_next; + } + else if (BKE_library_ID_is_indirectly_used(bmain, base->object) && ID_REAL_USERS(base->object) <= 1) { + BKE_reportf(reports, RPT_WARNING, + "Cannot delete object '%s' from scene '%s', indirectly used objects need at least one user", + base->object->id.name + 2, scene->id.name + 2); + return base_next; + } ED_base_object_free_and_unlink(CTX_data_main(C), scene, base); return base_next; } static void object_delete_hierarchy_cb( - bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) + bContext *C, ReportList *reports, Scene *scene, + TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data)) { Base *base = (Base *)te->directdata; Object *obedit = scene->obedit; @@ -831,7 +873,7 @@ static void object_delete_hierarchy_cb( ED_object_editmode_exit(C, EM_FREEDATA | EM_FREEUNDO | EM_WAITCURSOR | EM_DO_UNDO); } - outline_delete_hierarchy(C, scene, base); + outline_delete_hierarchy(C, reports, scene, base); /* leave for ED_outliner_id_unref to handle */ #if 0 te->directdata = NULL; @@ -864,8 +906,8 @@ static EnumPropertyItem prop_object_op_types[] = { {OL_OP_SELECT_HIERARCHY, "SELECT_HIERARCHY", 0, "Select Hierarchy", ""}, {OL_OP_DELETE, "DELETE", 0, "Delete", ""}, {OL_OP_DELETE_HIERARCHY, "DELETE_HIERARCHY", 0, "Delete Hierarchy", ""}, - {OL_OP_REMAP, "REMAP", 0, "Remap Users", - "Make all users of selected datablocks to use instead a new chosen one"}, + {OL_OP_REMAP, "REMAP", 0, "Remap Users", + "Make all users of selected datablocks to use instead a new chosen one"}, {OL_OP_TOGVIS, "TOGVIS", 0, "Toggle Visible", ""}, {OL_OP_TOGSEL, "TOGSEL", 0, "Toggle Selectable", ""}, {OL_OP_TOGREN, "TOGREN", 0, "Toggle Renderable", ""}, @@ -889,7 +931,7 @@ static int outliner_object_operation_exec(bContext *C, wmOperator *op) if (event == OL_OP_SELECT) { Scene *sce = scene; // to be able to delete, scenes are set... - outliner_do_object_operation(C, scene, soops, &soops->tree, object_select_cb); + outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, object_select_cb); if (scene != sce) { ED_screen_set_scene(C, CTX_wm_screen(C), sce); } @@ -899,7 +941,7 @@ static int outliner_object_operation_exec(bContext *C, wmOperator *op) } else if (event == OL_OP_SELECT_HIERARCHY) { Scene *sce = scene; // to be able to delete, scenes are set... - outliner_do_object_operation_ex(C, scene, soops, &soops->tree, object_select_hierarchy_cb, false); + outliner_do_object_operation_ex(C, op->reports, scene, soops, &soops->tree, object_select_hierarchy_cb, false); if (scene != sce) { ED_screen_set_scene(C, CTX_wm_screen(C), sce); } @@ -907,12 +949,12 @@ static int outliner_object_operation_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); } else if (event == OL_OP_DESELECT) { - outliner_do_object_operation(C, scene, soops, &soops->tree, object_deselect_cb); + outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, object_deselect_cb); str = "Deselect Objects"; WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); } else if (event == OL_OP_DELETE) { - outliner_do_object_operation(C, scene, soops, &soops->tree, object_delete_cb); + outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, object_delete_cb); /* XXX: tree management normally happens from draw_outliner(), but when * you're clicking to fast on Delete object from context menu in @@ -926,7 +968,7 @@ static int outliner_object_operation_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); } else if (event == OL_OP_DELETE_HIERARCHY) { - outliner_do_object_operation_ex(C, scene, soops, &soops->tree, object_delete_hierarchy_cb, false); + outliner_do_object_operation_ex(C, op->reports, scene, soops, &soops->tree, object_delete_hierarchy_cb, false); /* XXX: See OL_OP_DELETE comment above. */ outliner_cleanup_tree(soops); @@ -936,30 +978,30 @@ static int outliner_object_operation_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); } else if (event == OL_OP_REMAP) { - outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_remap_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, id_remap_cb, NULL); str = "Remap ID"; } else if (event == OL_OP_LOCALIZED) { /* disabled, see above enum (ton) */ - outliner_do_object_operation(C, scene, soops, &soops->tree, id_local_cb); + outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, id_local_cb); str = "Localized Objects"; } else if (event == OL_OP_TOGVIS) { - outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_visibility_cb); + outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, object_toggle_visibility_cb); str = "Toggle Visibility"; WM_event_add_notifier(C, NC_SCENE | ND_OB_VISIBLE, scene); } else if (event == OL_OP_TOGSEL) { - outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_selectability_cb); + outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, object_toggle_selectability_cb); str = "Toggle Selectability"; WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); } else if (event == OL_OP_TOGREN) { - outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_renderability_cb); + outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, object_toggle_renderability_cb); str = "Toggle Renderability"; WM_event_add_notifier(C, NC_SCENE | ND_OB_RENDER, scene); } else if (event == OL_OP_RENAME) { - outliner_do_object_operation(C, scene, soops, &soops->tree, item_rename_cb); + outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, item_rename_cb); str = "Rename Object"; } else { @@ -1009,9 +1051,9 @@ static EnumPropertyItem prop_group_op_types[] = { {OL_GROUPOP_UNLINK, "UNLINK", 0, "Unlink Group", ""}, {OL_GROUPOP_LOCAL, "LOCAL", 0, "Make Local Group", ""}, {OL_GROUPOP_LINK, "LINK", 0, "Link Group Objects to Scene", ""}, - {OL_GROUPOP_DELETE, "DELETE", 0, "Delete Group", "WARNING: no undo"}, - {OL_GROUPOP_REMAP, "REMAP", 0, "Remap Users", - "Make all users of selected datablocks to use instead current (clicked) one"}, + {OL_GROUPOP_DELETE, "DELETE", 0, "Delete Group", "WARNING: no undo"}, + {OL_GROUPOP_REMAP, "REMAP", 0, "Remap Users", + "Make all users of selected datablocks to use instead current (clicked) one"}, {OL_GROUPOP_INSTANCE, "INSTANCE", 0, "Instance Groups in Scene", ""}, {OL_GROUPOP_TOGVIS, "TOGVIS", 0, "Toggle Visible Group", ""}, {OL_GROUPOP_TOGSEL, "TOGSEL", 0, "Toggle Selectable", ""}, @@ -1034,16 +1076,16 @@ static int outliner_group_operation_exec(bContext *C, wmOperator *op) switch (event) { case OL_GROUPOP_UNLINK: - outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_group_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, unlink_group_cb, NULL); break; case OL_GROUPOP_LOCAL: - outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_local_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, id_local_cb, NULL); break; case OL_GROUPOP_LINK: - outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_linkobs2scene_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, group_linkobs2scene_cb, NULL); break; case OL_GROUPOP_INSTANCE: - outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_instance_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, group_instance_cb, NULL); /* works without this except if you try render right after, see: 22027 */ DAG_relations_tag_update(CTX_data_main(C)); break; @@ -1051,19 +1093,19 @@ static int outliner_group_operation_exec(bContext *C, wmOperator *op) WM_operator_name_call(C, "OUTLINER_OT_id_delete", WM_OP_INVOKE_REGION_WIN, NULL); break; case OL_GROUPOP_REMAP: - outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_remap_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, id_remap_cb, NULL); break; case OL_GROUPOP_TOGVIS: - outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_toggle_visibility_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, group_toggle_visibility_cb, NULL); break; case OL_GROUPOP_TOGSEL: - outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_toggle_selectability_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, group_toggle_selectability_cb, NULL); break; case OL_GROUPOP_TOGREN: - outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_toggle_renderability_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, group_toggle_renderability_cb, NULL); break; case OL_GROUPOP_RENAME: - outliner_do_libdata_operation(C, scene, soops, &soops->tree, item_rename_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, item_rename_cb, NULL); break; default: BLI_assert(0); @@ -1116,9 +1158,9 @@ static EnumPropertyItem prop_id_op_types[] = { {OUTLINER_IDOP_UNLINK, "UNLINK", 0, "Unlink", ""}, {OUTLINER_IDOP_LOCAL, "LOCAL", 0, "Make Local", ""}, {OUTLINER_IDOP_SINGLE, "SINGLE", 0, "Make Single User", ""}, - {OUTLINER_IDOP_DELETE, "DELETE", 0, "Delete", "WARNING: no undo"}, - {OUTLINER_IDOP_REMAP, "REMAP", 0, "Remap Users", - "Make all users of selected datablocks to use instead current (clicked) one"}, + {OUTLINER_IDOP_DELETE, "DELETE", 0, "Delete", "WARNING: no undo"}, + {OUTLINER_IDOP_REMAP, "REMAP", 0, "Remap Users", + "Make all users of selected datablocks to use instead current (clicked) one"}, {OUTLINER_IDOP_FAKE_ADD, "ADD_FAKE", 0, "Add Fake User", "Ensure datablock gets saved even if it isn't in use (e.g. for motion and material libraries)"}, {OUTLINER_IDOP_FAKE_CLEAR, "CLEAR_FAKE", 0, "Clear Fake User", ""}, @@ -1148,25 +1190,25 @@ static int outliner_id_operation_exec(bContext *C, wmOperator *op) /* unlink datablock from its parent */ switch (idlevel) { case ID_AC: - outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_action_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, unlink_action_cb, NULL); WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ACTCHANGE, NULL); ED_undo_push(C, "Unlink action"); break; case ID_MA: - outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_material_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, unlink_material_cb, NULL); WM_event_add_notifier(C, NC_OBJECT | ND_OB_SHADING, NULL); ED_undo_push(C, "Unlink material"); break; case ID_TE: - outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_texture_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, unlink_texture_cb, NULL); WM_event_add_notifier(C, NC_OBJECT | ND_OB_SHADING, NULL); ED_undo_push(C, "Unlink texture"); break; case ID_WO: - outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_world_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, unlink_world_cb, NULL); WM_event_add_notifier(C, NC_SCENE | ND_WORLD, NULL); ED_undo_push(C, "Unlink world"); @@ -1180,7 +1222,7 @@ static int outliner_id_operation_exec(bContext *C, wmOperator *op) case OUTLINER_IDOP_LOCAL: { /* make local */ - outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_local_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, id_local_cb, NULL); ED_undo_push(C, "Localized Data"); break; } @@ -1189,14 +1231,14 @@ static int outliner_id_operation_exec(bContext *C, wmOperator *op) /* make single user */ switch (idlevel) { case ID_AC: - outliner_do_libdata_operation(C, scene, soops, &soops->tree, singleuser_action_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, singleuser_action_cb, NULL); WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ACTCHANGE, NULL); ED_undo_push(C, "Single-User Action"); break; case ID_WO: - outliner_do_libdata_operation(C, scene, soops, &soops->tree, singleuser_world_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, singleuser_world_cb, NULL); WM_event_add_notifier(C, NC_SCENE | ND_WORLD, NULL); ED_undo_push(C, "Single-User World"); @@ -1211,21 +1253,21 @@ static int outliner_id_operation_exec(bContext *C, wmOperator *op) case OUTLINER_IDOP_DELETE: { if (idlevel > 0) { - outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_delete_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, id_delete_cb, NULL); } break; } case OUTLINER_IDOP_REMAP: { if (idlevel > 0) { - outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_remap_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, id_remap_cb, NULL); } break; } case OUTLINER_IDOP_FAKE_ADD: { /* set fake user */ - outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_fake_user_set_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, id_fake_user_set_cb, NULL); WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL); ED_undo_push(C, "Add Fake User"); @@ -1234,7 +1276,7 @@ static int outliner_id_operation_exec(bContext *C, wmOperator *op) case OUTLINER_IDOP_FAKE_CLEAR: { /* clear fake user */ - outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_fake_user_clear_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, id_fake_user_clear_cb, NULL); WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL); ED_undo_push(C, "Clear Fake User"); @@ -1243,14 +1285,14 @@ static int outliner_id_operation_exec(bContext *C, wmOperator *op) case OUTLINER_IDOP_RENAME: { /* rename */ - outliner_do_libdata_operation(C, scene, soops, &soops->tree, item_rename_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, item_rename_cb, NULL); WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL); ED_undo_push(C, "Rename"); break; } case OUTLINER_IDOP_SELECT_LINKED: - outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_select_linked_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, id_select_linked_cb, NULL); ED_undo_push(C, "Select"); break; @@ -1299,9 +1341,9 @@ typedef enum eOutlinerLibOpTypes { static EnumPropertyItem outliner_lib_op_type_items[] = { {OL_LIB_RENAME, "RENAME", 0, "Rename", ""}, - {OL_LIB_DELETE, "DELETE", 0, "Delete", "Delete this library and all its item from Blender - WARNING: no undo"}, - {OL_LIB_RELOCATE, "RELOCATE", 0, "Relocate", "Select a new path for this library, and reload all its data"}, - {OL_LIB_RELOAD, "RELOAD", 0, "Reload", "Reload all data from this library"}, + {OL_LIB_DELETE, "DELETE", 0, "Delete", "Delete this library and all its item from Blender - WARNING: no undo"}, + {OL_LIB_RELOCATE, "RELOCATE", 0, "Relocate", "Select a new path for this library, and reload all its data"}, + {OL_LIB_RELOAD, "RELOAD", 0, "Reload", "Reload all data from this library"}, {0, NULL, 0, NULL, NULL} }; @@ -1324,7 +1366,7 @@ static int outliner_lib_operation_exec(bContext *C, wmOperator *op) case OL_LIB_RENAME: { /* rename */ - outliner_do_libdata_operation(C, scene, soops, &soops->tree, item_rename_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, item_rename_cb, NULL); WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL); ED_undo_push(C, "Rename"); @@ -1332,19 +1374,19 @@ static int outliner_lib_operation_exec(bContext *C, wmOperator *op) } case OL_LIB_DELETE: { - outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_delete_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, id_delete_cb, NULL); break; } case OL_LIB_RELOCATE: { /* rename */ - outliner_do_libdata_operation(C, scene, soops, &soops->tree, lib_relocate_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, lib_relocate_cb, NULL); break; } case OL_LIB_RELOAD: { /* rename */ - outliner_do_libdata_operation(C, scene, soops, &soops->tree, lib_reload_cb, NULL); + outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, lib_reload_cb, NULL); break; } default: diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index 0dea59fd68c..686a10fc785 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -567,7 +567,7 @@ static void text_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID { SpaceText *stext = (SpaceText *)slink; - if (!ELEM(GS(old_id->name), ID_GD)) { + if (!ELEM(GS(old_id->name), ID_TXT)) { return; } diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index ee82a4c5072..791ece14cb9 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -979,10 +979,17 @@ static void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d if (ob == OBACT) { if (ob->mode & OB_MODE_WEIGHT_PAINT) { dm_draw_flag |= DM_DRAW_USE_COLORS | DM_DRAW_ALWAYS_SMOOTH | DM_DRAW_SKIP_HIDDEN; - } else if (ob->mode & OB_MODE_SCULPT) { - dm_draw_flag |= DM_DRAW_SKIP_HIDDEN; + dm_draw_flag |= DM_DRAW_SKIP_HIDDEN | DM_DRAW_USE_COLORS; + } + else if ((ob->mode & OB_MODE_TEXTURE_PAINT) == 0) { + dm_draw_flag |= DM_DRAW_USE_COLORS; + } + } + else { + if ((ob->mode & OB_MODE_TEXTURE_PAINT) == 0) { + dm_draw_flag |= DM_DRAW_USE_COLORS; } } diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 8d796a5a998..1d6eab42edf 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -1402,8 +1402,8 @@ static void drawlamp(View3D *v3d, RegionView3D *rv3d, Base *base, float blend = z_abs * (1.0f - pow2f(la->spotblend)); /* hide line if it is zero size or overlaps with outer border, - * previously it adjusted to always to show it but that seems - * confusing because it doesn't show the actual blend size */ + * previously it adjusted to always to show it but that seems + * confusing because it doesn't show the actual blend size */ if (blend != 0.0f && blend != z_abs) { circ(0.0f, 0.0f, blend); } diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 329778cd716..1de06af0478 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -2599,6 +2599,7 @@ static void gpu_update_lamps_shadows_world(Scene *scene, View3D *v3d) GPU_mist_update_values(world->mistype, world->miststa, world->mistdist, world->misi, &world->horr); GPU_horizon_update_color(&world->horr); GPU_ambient_update_color(&world->ambr); + GPU_zenith_update_color(&world->zenr); } } diff --git a/source/blender/editors/space_view3d/view3d_project.c b/source/blender/editors/space_view3d/view3d_project.c index 797d97586c7..ac05853e6d0 100644 --- a/source/blender/editors/space_view3d/view3d_project.c +++ b/source/blender/editors/space_view3d/view3d_project.c @@ -302,8 +302,9 @@ float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3], bool *r_f return zfac; } -static void view3d_win_to_ray_segment(const ARegion *ar, View3D *v3d, const float mval[2], - float r_ray_co[3], float r_ray_dir[3], float r_ray_start[3], float r_ray_end[3]) +static void view3d_win_to_ray_segment( + const ARegion *ar, const View3D *v3d, const float mval[2], + float r_ray_co[3], float r_ray_dir[3], float r_ray_start[3], float r_ray_end[3]) { RegionView3D *rv3d = ar->regiondata; float _ray_co[3], _ray_dir[3], start_offset, end_offset; @@ -346,7 +347,7 @@ static void view3d_win_to_ray_segment(const ARegion *ar, View3D *v3d, const floa } } -BLI_INLINE bool view3d_clip_segment(RegionView3D *rv3d, float ray_start[3], float ray_end[3]) +BLI_INLINE bool view3d_clip_segment(const RegionView3D *rv3d, float ray_start[3], float ray_end[3]) { if ((rv3d->rflag & RV3D_CLIPPING) && (clip_segment_v3_plane_n(ray_start, ray_end, rv3d->clip, 6, @@ -373,8 +374,9 @@ BLI_INLINE bool view3d_clip_segment(RegionView3D *rv3d, float ray_start[3], floa * \param do_clip Optionally clip the start of the ray by the view clipping planes. * \return success, false if the ray is totally clipped. */ -bool ED_view3d_win_to_ray_ex(const ARegion *ar, View3D *v3d, const float mval[2], - float r_ray_co[3], float r_ray_normal[3], float r_ray_start[3], bool do_clip) +bool ED_view3d_win_to_ray_ex( + const ARegion *ar, const View3D *v3d, const float mval[2], + float r_ray_co[3], float r_ray_normal[3], float r_ray_start[3], bool do_clip) { float ray_end[3]; @@ -382,7 +384,7 @@ bool ED_view3d_win_to_ray_ex(const ARegion *ar, View3D *v3d, const float mval[2] /* bounds clipping */ if (do_clip) { - return view3d_clip_segment((RegionView3D *)ar->regiondata, r_ray_start, ray_end); + return view3d_clip_segment(ar->regiondata, r_ray_start, ray_end); } return true; @@ -401,8 +403,9 @@ bool ED_view3d_win_to_ray_ex(const ARegion *ar, View3D *v3d, const float mval[2] * \param do_clip Optionally clip the start of the ray by the view clipping planes. * \return success, false if the ray is totally clipped. */ -bool ED_view3d_win_to_ray(const ARegion *ar, View3D *v3d, const float mval[2], - float r_ray_start[3], float r_ray_normal[3], const bool do_clip) +bool ED_view3d_win_to_ray( + const ARegion *ar, const View3D *v3d, const float mval[2], + float r_ray_start[3], float r_ray_normal[3], const bool do_clip) { return ED_view3d_win_to_ray_ex(ar, v3d, mval, NULL, r_ray_normal, r_ray_start, do_clip); } diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 7671154526a..95864474fc0 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -5375,7 +5375,9 @@ static void slide_origdata_init_data( BMesh *bm = em->bm; sod->origfaces = BLI_ghash_ptr_new(__func__); - sod->bm_origfaces = BM_mesh_create(&bm_mesh_allocsize_default); + sod->bm_origfaces = BM_mesh_create( + &bm_mesh_allocsize_default, + &((struct BMeshCreateParams){.use_toolflags = false,})); /* we need to have matching customdata */ BM_mesh_copy_init_customdata(sod->bm_origfaces, bm, NULL); } diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c index 28ad1d93215..e85b686b5b3 100644 --- a/source/blender/editors/transform/transform_snap_object.c +++ b/source/blender/editors/transform/transform_snap_object.c @@ -68,13 +68,13 @@ typedef struct SnapObjectData { typedef struct SnapObjectData_Mesh { SnapObjectData sd; - BVHTreeFromMesh *bvh_trees[2]; + BVHTreeFromMesh *bvh_trees[3]; } SnapObjectData_Mesh; typedef struct SnapObjectData_EditMesh { SnapObjectData sd; - BVHTreeFromEditMesh *bvh_trees[2]; + BVHTreeFromEditMesh *bvh_trees[3]; } SnapObjectData_EditMesh; @@ -87,8 +87,8 @@ struct SnapObjectContext { * otherwise this doesn't take viewport into account. */ bool use_v3d; struct { - struct View3D *v3d; - struct ARegion *ar; + const struct View3D *v3d; + const struct ARegion *ar; } v3d_data; @@ -222,9 +222,12 @@ static void raycast_all_cb(void *userdata, int index, const BVHTreeRay *ray, BVH * \{ */ static bool snapEdge( - ARegion *ar, const float v1co[3], const short v1no[3], const float v2co[3], const short v2no[3], - float obmat[4][4], float timat[3][3], const float mval_fl[2], float *dist_px, - const float ray_start[3], const float ray_start_local[3], const float ray_normal_local[3], float *ray_depth, + const ARegion *ar, const float v1co[3], const short v1no[3], const float v2co[3], const short v2no[3], + float obmat[4][4], float timat[3][3], const float mval_fl[2], + const float ray_start[3], const float ray_start_local[3], const float ray_normal_local[3], + /* read/write args */ + float *ray_depth, float *dist_px, + /* return args */ float r_loc[3], float r_no[3]) { float intersect[3] = {0, 0, 0}, ray_end[3], dvec[3]; @@ -312,9 +315,12 @@ static bool snapEdge( } static bool snapVertex( - ARegion *ar, const float vco[3], const float vno[3], - float obmat[4][4], float timat[3][3], const float mval_fl[2], float *dist_px, - const float ray_start[3], const float ray_start_local[3], const float ray_normal_local[3], float *ray_depth, + const ARegion *ar, const float vco[3], const float vno[3], + float obmat[4][4], float timat[3][3], const float mval_fl[2], + const float ray_start[3], const float ray_start_local[3], const float ray_normal_local[3], + /* read/write args */ + float *ray_depth, float *dist_px, + /* return args */ float r_loc[3], float r_no[3]) { bool retval = false; @@ -362,9 +368,12 @@ static bool snapVertex( } static bool snapArmature( - ARegion *ar, Object *ob, bArmature *arm, float obmat[4][4], - const float mval[2], float *dist_px, const short snap_to, - const float ray_start[3], const float ray_normal[3], float *ray_depth, + const ARegion *ar, Object *ob, bArmature *arm, float obmat[4][4], + const float mval[2], const short snap_to, + const float ray_start[3], const float ray_normal[3], + /* read/write args */ + float *ray_depth, float *dist_px, + /* return args */ float r_loc[3], float *UNUSED(r_no)) { float imat[4][4]; @@ -444,9 +453,12 @@ static bool snapArmature( } static bool snapCurve( - ARegion *ar, Object *ob, Curve *cu, float obmat[4][4], - const float mval[2], float *dist_px, const short snap_to, - const float ray_start[3], const float ray_normal[3], float *ray_depth, + const ARegion *ar, Object *ob, Curve *cu, float obmat[4][4], + const float mval[2], const short snap_to, + const float ray_start[3], const float ray_normal[3], + /* read/write args */ + float *ray_depth, float *dist_px, + /* return args */ float r_loc[3], float *UNUSED(r_no)) { float imat[4][4]; @@ -481,24 +493,27 @@ static bool snapCurve( break; } retval |= snapVertex( - ar, nu->bezt[u].vec[1], NULL, obmat, NULL, mval, dist_px, - ray_start, ray_start_local, ray_normal_local, ray_depth, + ar, nu->bezt[u].vec[1], NULL, obmat, NULL, mval, + ray_start, ray_start_local, ray_normal_local, + ray_depth, dist_px, r_loc, NULL); /* don't snap if handle is selected (moving), or if it is aligning to a moving handle */ if (!(nu->bezt[u].f1 & SELECT) && !(nu->bezt[u].h1 & HD_ALIGN && nu->bezt[u].f3 & SELECT)) { retval |= snapVertex( - ar, nu->bezt[u].vec[0], NULL, obmat, NULL, mval, dist_px, - ray_start, ray_start_local, ray_normal_local, ray_depth, + ar, nu->bezt[u].vec[0], NULL, obmat, NULL, mval, + ray_start, ray_start_local, ray_normal_local, + ray_depth, dist_px, r_loc, NULL); } if (!(nu->bezt[u].f3 & SELECT) && !(nu->bezt[u].h2 & HD_ALIGN && nu->bezt[u].f1 & SELECT)) { retval |= snapVertex( - ar, nu->bezt[u].vec[2], NULL, obmat, NULL, mval, dist_px, - ray_start, ray_start_local, ray_normal_local, ray_depth, + ar, nu->bezt[u].vec[2], NULL, obmat, NULL, mval, + ray_start, ray_start_local, ray_normal_local, + ray_depth, dist_px, r_loc, NULL); } } @@ -508,8 +523,9 @@ static bool snapCurve( break; } retval |= snapVertex( - ar, nu->bp[u].vec, NULL, obmat, NULL, mval, dist_px, - ray_start, ray_start_local, ray_normal_local, ray_depth, + ar, nu->bp[u].vec, NULL, obmat, NULL, mval, + ray_start, ray_start_local, ray_normal_local, + ray_depth, dist_px, r_loc, NULL); } } @@ -518,14 +534,16 @@ static bool snapCurve( if (nu->pntsu > 1) { if (nu->bezt) { retval |= snapVertex( - ar, nu->bezt[u].vec[1], NULL, obmat, NULL, mval, dist_px, - ray_start, ray_start_local, ray_normal_local, ray_depth, + ar, nu->bezt[u].vec[1], NULL, obmat, NULL, mval, + ray_start, ray_start_local, ray_normal_local, + ray_depth, dist_px, r_loc, NULL); } else { retval |= snapVertex( - ar, nu->bp[u].vec, NULL, obmat, NULL, mval, dist_px, - ray_start, ray_start_local, ray_normal_local, ray_depth, + ar, nu->bp[u].vec, NULL, obmat, NULL, mval, + ray_start, ray_start_local, ray_normal_local, + ray_depth, dist_px, r_loc, NULL); } } @@ -542,9 +560,12 @@ static bool snapCurve( /* may extend later (for now just snaps to empty center) */ static bool snapEmpty( - ARegion *ar, Object *ob, float obmat[4][4], - const float mval[2], float *dist_px, const short snap_to, - const float ray_start[3], const float ray_normal[3], float *ray_depth, + const ARegion *ar, Object *ob, float obmat[4][4], + const float mval[2], const short snap_to, + const float ray_start[3], const float ray_normal[3], + /* read/write args */ + float *ray_depth, float *dist_px, + /* return args */ float r_loc[3], float *UNUSED(r_no)) { float imat[4][4]; @@ -582,9 +603,12 @@ static bool snapEmpty( } static bool snapCamera( - ARegion *ar, Scene *scene, Object *object, float obmat[4][4], - const float mval[2], float *dist_px, const short snap_to, - const float ray_start[3], const float ray_normal[3], float *ray_depth, + const ARegion *ar, Scene *scene, Object *object, float obmat[4][4], + const float mval[2], const short snap_to, + const float ray_start[3], const float ray_normal[3], + /* read/write args */ + float *ray_depth, float *dist_px, + /* return args */ float r_loc[3], float *UNUSED(r_no)) { float orig_camera_mat[4][4], orig_camera_imat[4][4], imat[4][4]; @@ -674,16 +698,166 @@ static int dm_looptri_to_poly_index(DerivedMesh *dm, const MLoopTri *lt) return index_mp_to_orig ? index_mp_to_orig[lt->poly] : lt->poly; } +struct NearestDM_Data { + void *bvhdata; + bool is_persp; + const float *ray_depth_range; + + float *ray_depth; +}; + +static bool test_vert( + const float vco[3], const float vno[3], const float ray_co[3], const float ray_dir[3], + const float ray_depth_range[2], const float scale[3], const bool is_persp, + /* read/write args */ + float *ray_depth, float *dist_to_ray_sq, + /* return args */ + float r_co[3], float r_no[3]) +{ + const float vco_sc[3] = { + vco[0] * scale[0], + vco[1] * scale[1], + vco[2] * scale[2], + }; + const float co_sc[3] = { + ray_co[0] * scale[0], + ray_co[1] * scale[1], + ray_co[2] * scale[2], + }; + const float dir_sc[3] = { + ray_dir[0] * scale[0], + ray_dir[1] * scale[1], + ray_dir[2] * scale[2], + }; + + float depth; + float dist_sq = dist_squared_to_ray_v3(co_sc, dir_sc, vco_sc, &depth); + + if (depth < ray_depth_range[0]) + return false; + + if (is_persp) + dist_sq /= SQUARE(depth); + + if ((dist_sq < *dist_to_ray_sq) && (depth < *ray_depth)) { + *dist_to_ray_sq = dist_sq; + + copy_v3_v3(r_co, vco); + + if (vno) { + copy_v3_v3(r_no, vno); + } + + *ray_depth = depth; + return true; + } + return false; +} + +static bool test_edge( + const float v1[3], const float v2[3], const float ray_co[3], const float ray_dir[3], + const float ray_depth_range[2], const float scale[3], const bool is_persp, + /* read/write args */ + float *ray_depth, float *dist_to_ray_sq, + /* return args */ + float r_co[3], float r_no[3]) +{ + const float v1_sc[3] = { + v1[0] * scale[0], + v1[1] * scale[1], + v1[2] * scale[2], + }; + const float v2_sc[3] = { + v2[0] * scale[0], + v2[1] * scale[1], + v2[2] * scale[2], + }; + const float co_sc[3] = { + ray_co[0] * scale[0], + ray_co[1] * scale[1], + ray_co[2] * scale[2], + }; + const float dir_sc[3] = { + ray_dir[0] * scale[0], + ray_dir[1] * scale[1], + ray_dir[2] * scale[2], + }; + + float tmp_co[3], depth; + float dist_sq = dist_squared_ray_to_seg_v3(co_sc, dir_sc, v1_sc, v2_sc, tmp_co, &depth); + + if (depth < ray_depth_range[0]) + return false; + + if (is_persp) + dist_sq /= SQUARE(depth); + + if ((dist_sq < *dist_to_ray_sq) && (depth < *ray_depth)) { + *dist_to_ray_sq = dist_sq; + + tmp_co[0] /= scale[0]; + tmp_co[1] /= scale[1]; + tmp_co[2] /= scale[2]; + + copy_v3_v3(r_co, tmp_co); + + if (r_no) { + sub_v3_v3v3(r_no, v1, v2); + } + + *ray_depth = depth; + return true; + } + return false; +} + +static void test_vert_depth_cb( + void *userdata, const float origin[3], const float dir[3], + const float scale[3], int index, BVHTreeNearest *nearest) +{ + struct NearestDM_Data *ndata = userdata; + const BVHTreeFromMesh *data = ndata->bvhdata; + const MVert *vert = data->vert + index; + + if (test_vert( + vert->co, NULL, origin, dir, ndata->ray_depth_range, scale, ndata->is_persp, + ndata->ray_depth, &nearest->dist_sq, + nearest->co, NULL)) + { + normal_short_to_float_v3(nearest->no, vert->no); + nearest->index = index; + } +} + +static void test_edge_depth_cb( + void *userdata, const float origin[3], const float dir[3], + const float scale[3], int index, BVHTreeNearest *nearest) +{ + struct NearestDM_Data *ndata = userdata; + const BVHTreeFromMesh *data = ndata->bvhdata; + const MVert *vert = data->vert; + const MEdge *edge = data->edge + index; + + if (test_edge( + vert[edge->v1].co, vert[edge->v2].co, origin, dir, ndata->ray_depth_range, scale, ndata->is_persp, + ndata->ray_depth, &nearest->dist_sq, + nearest->co, nearest->no)) + { + nearest->index = index; + } +} + static bool snapDerivedMesh( SnapObjectContext *sctx, - Object *ob, DerivedMesh *dm, float obmat[4][4], - const float mval[2], float *dist_px, const short snap_to, bool do_bb, - const float ray_start[3], const float ray_normal[3], const float ray_origin[3], - float *ray_depth, unsigned int ob_index, + Object *ob, DerivedMesh *dm, float obmat[4][4], const unsigned int ob_index, + const short snap_to, bool do_bb, + const float ray_origin[3], const float ray_start[3], const float ray_normal[3], const float ray_depth_range[2], + /* read/write args */ + float *ray_depth, float *dist_to_ray_sq, float *dist_px, + /* return args */ float r_loc[3], float r_no[3], int *r_index, ListBase *r_hit_list) { - ARegion *ar = sctx->v3d_data.ar; bool retval = false; if (snap_to == SCE_SNAP_MODE_FACE) { @@ -703,10 +877,8 @@ static bool snapDerivedMesh( } { - const bool do_ray_start_correction = ( - ELEM(snap_to, SCE_SNAP_MODE_FACE, SCE_SNAP_MODE_VERTEX) && - (sctx->use_v3d && !((RegionView3D *)sctx->v3d_data.ar->regiondata)->is_persp)); - bool need_ray_start_correction_init = do_ray_start_correction; + const bool is_persp = sctx->use_v3d && ((RegionView3D *)sctx->v3d_data.ar->regiondata)->is_persp; + bool need_ray_start_correction_init = (snap_to == SCE_SNAP_MODE_FACE) && sctx->use_v3d && !is_persp; float imat[4][4]; float timat[3][3]; /* transpose inverse matrix for normals */ @@ -772,6 +944,9 @@ static bool snapDerivedMesh( int tree_index = -1; switch (snap_to) { case SCE_SNAP_MODE_FACE: + tree_index = 2; + break; + case SCE_SNAP_MODE_EDGE: tree_index = 1; break; case SCE_SNAP_MODE_VERTEX: @@ -793,10 +968,8 @@ static bool snapDerivedMesh( } } else { - if (ELEM(snap_to, SCE_SNAP_MODE_FACE, SCE_SNAP_MODE_VERTEX)) { - treedata = &treedata_stack; - memset(treedata, 0, sizeof(*treedata)); - } + treedata = &treedata_stack; + memset(treedata, 0, sizeof(*treedata)); } if (treedata && treedata->tree == NULL) { @@ -804,53 +977,56 @@ static bool snapDerivedMesh( case SCE_SNAP_MODE_FACE: bvhtree_from_mesh_looptri(treedata, dm, 0.0f, 4, 6); break; + case SCE_SNAP_MODE_EDGE: + bvhtree_from_mesh_edges(treedata, dm, 0.0f, 2, 6); + break; case SCE_SNAP_MODE_VERTEX: bvhtree_from_mesh_verts(treedata, dm, 0.0f, 2, 6); break; } } - - if (need_ray_start_correction_init) { - /* We *need* a reasonably valid len_diff in this case. - * Use BHVTree to find the closest face from ray_start_local. - */ - if (treedata && treedata->tree != NULL) { - BVHTreeNearest nearest; - nearest.index = -1; - nearest.dist_sq = FLT_MAX; - /* Compute and store result. */ - BLI_bvhtree_find_nearest( - treedata->tree, ray_start_local, &nearest, treedata->nearest_callback, treedata); - if (nearest.index != -1) { - len_diff = sqrtf(nearest.dist_sq); - } - } - } - /* Only use closer ray_start in case of ortho view! In perspective one, ray_start may already - * been *inside* boundbox, leading to snap failures (see T38409). - * Note also ar might be null (see T38435), in this case we assume ray_start is ok! - */ - if (do_ray_start_correction) { - float ray_org_local[3]; - - copy_v3_v3(ray_org_local, ray_origin); - mul_m4_v3(imat, ray_org_local); - - /* We pass a temp ray_start, set from object's boundbox, to avoid precision issues with very far - * away ray_start values (as returned in case of ortho view3d), see T38358. - */ - len_diff -= local_scale; /* make temp start point a bit away from bbox hit point. */ - madd_v3_v3v3fl(ray_start_local, ray_org_local, ray_normal_local, - len_diff - len_v3v3(ray_start_local, ray_org_local)); - local_depth -= len_diff; - } - else { - len_diff = 0.0f; - } - switch (snap_to) { case SCE_SNAP_MODE_FACE: { + /* Only use closer ray_start in case of ortho view! In perspective one, ray_start may already + * been *inside* boundbox, leading to snap failures (see T38409). + * Note also ar might be null (see T38435), in this case we assume ray_start is ok! + */ + if (sctx->use_v3d && !is_persp) { /* do_ray_start_correction */ + if (need_ray_start_correction_init) { + /* We *need* a reasonably valid len_diff in this case. + * Use BHVTree to find the closest face from ray_start_local. + */ + if (treedata && treedata->tree != NULL) { + BVHTreeNearest nearest; + nearest.index = -1; + nearest.dist_sq = FLT_MAX; + /* Compute and store result. */ + BLI_bvhtree_find_nearest( + treedata->tree, ray_start_local, &nearest, treedata->nearest_callback, treedata); + if (nearest.index != -1) { + float dvec[3]; + sub_v3_v3v3(dvec, nearest.co, ray_start_local); + len_diff = dot_v3v3(dvec, ray_normal_local); + } + } + } + float ray_org_local[3]; + + copy_v3_v3(ray_org_local, ray_origin); + mul_m4_v3(imat, ray_org_local); + + /* We pass a temp ray_start, set from object's boundbox, to avoid precision issues with very far + * away ray_start values (as returned in case of ortho view3d), see T38358. + */ + len_diff -= local_scale; /* make temp start point a bit away from bbox hit point. */ + madd_v3_v3v3fl(ray_start_local, ray_org_local, ray_normal_local, + len_diff + ray_depth_range[0]); + local_depth -= len_diff; + } + else { + len_diff = 0.0f; + } if (r_hit_list) { struct RayCastAll_Data data; @@ -861,7 +1037,7 @@ static bool snapDerivedMesh( data.len_diff = len_diff; data.local_scale = local_scale; data.ob = ob; - data.ob_uuid = ob_index, + data.ob_uuid = ob_index; data.dm = dm; data.hit_list = r_hit_list; data.retval = retval; @@ -907,40 +1083,90 @@ static bool snapDerivedMesh( } case SCE_SNAP_MODE_VERTEX: { + float ray_org_local[3]; + + copy_v3_v3(ray_org_local, ray_origin); + mul_m4_v3(imat, ray_org_local); + BVHTreeNearest nearest; nearest.index = -1; - nearest.dist_sq = local_depth * local_depth; - if (treedata->tree && + nearest.dist_sq = *dist_to_ray_sq; + + struct NearestDM_Data userdata; + userdata.bvhdata = treedata; + userdata.is_persp = is_persp; + userdata.ray_depth_range = ray_depth_range; + userdata.ray_depth = ray_depth; + + float ob_scale[3]; + mat4_to_size(ob_scale, obmat); + + if (treedata->tree && ( + is_persp ? + BLI_bvhtree_find_nearest_to_ray_angle( + treedata->tree, ray_org_local, ray_normal_local, + true, ob_scale, &nearest, test_vert_depth_cb, &userdata) : BLI_bvhtree_find_nearest_to_ray( - treedata->tree, ray_start_local, ray_normal_local, - &nearest, NULL, NULL) != -1) + treedata->tree, ray_org_local, ray_normal_local, + true, ob_scale, &nearest, test_vert_depth_cb, &userdata)) != -1) { - const MVert *v = &treedata->vert[nearest.index]; - float vno[3]; - normal_short_to_float_v3(vno, v->no); - retval = snapVertex( - ar, v->co, vno, obmat, timat, mval, dist_px, - ray_start, ray_start_local, ray_normal_local, ray_depth, - r_loc, r_no); + copy_v3_v3(r_loc, nearest.co); + mul_m4_v3(obmat, r_loc); + if (r_no) { + copy_v3_v3(r_no, nearest.no); + mul_m3_v3(timat, r_no); + normalize_v3(r_no); + } + *dist_px *= nearest.dist_sq / (*dist_to_ray_sq); + *dist_to_ray_sq = nearest.dist_sq; + + retval = true; } break; } case SCE_SNAP_MODE_EDGE: { - MVert *verts = dm->getVertArray(dm); - MEdge *edges = dm->getEdgeArray(dm); - int totedge = dm->getNumEdges(dm); - - for (int i = 0; i < totedge; i++) { - MEdge *e = edges + i; - retval |= snapEdge( - ar, verts[e->v1].co, verts[e->v1].no, verts[e->v2].co, verts[e->v2].no, - obmat, timat, mval, dist_px, - ray_start, ray_start_local, ray_normal_local, ray_depth, - r_loc, r_no); - } + float ray_org_local[3]; + + copy_v3_v3(ray_org_local, ray_origin); + mul_m4_v3(imat, ray_org_local); + BVHTreeNearest nearest; + + nearest.index = -1; + nearest.dist_sq = *dist_to_ray_sq; + + struct NearestDM_Data userdata; + userdata.bvhdata = treedata; + userdata.is_persp = is_persp; + userdata.ray_depth_range = ray_depth_range; + userdata.ray_depth = ray_depth; + + float ob_scale[3]; + mat4_to_size(ob_scale, obmat); + + if (treedata->tree && ( + is_persp ? + BLI_bvhtree_find_nearest_to_ray_angle( + treedata->tree, ray_org_local, ray_normal_local, + true, ob_scale, &nearest, test_edge_depth_cb, &userdata) : + BLI_bvhtree_find_nearest_to_ray( + treedata->tree, ray_org_local, ray_normal_local, + true, ob_scale, &nearest, test_edge_depth_cb, &userdata)) != -1) + { + copy_v3_v3(r_loc, nearest.co); + mul_m4_v3(obmat, r_loc); + if (r_no) { + copy_v3_v3(r_no, nearest.no); + mul_m3_v3(timat, r_no); + normalize_v3(r_no); + } + *dist_px *= nearest.dist_sq / (*dist_to_ray_sq); + *dist_to_ray_sq = nearest.dist_sq; + + retval = true; + } break; } } @@ -955,17 +1181,51 @@ static bool snapDerivedMesh( return retval; } +static void test_bmvert_depth_cb( + void *userdata, const float origin[3], const float dir[3], + const float scale[3], int index, BVHTreeNearest *nearest) +{ + struct NearestDM_Data *ndata = userdata; + const BMEditMesh *em = ndata->bvhdata; + BMVert *eve = BM_vert_at_index(em->bm, index); + + if (test_vert( + eve->co, eve->no, origin, dir, ndata->ray_depth_range, scale, ndata->is_persp, + ndata->ray_depth, &nearest->dist_sq, + nearest->co, nearest->no)) + { + nearest->index = index; + } +} + +static void test_bmedge_depth_cb( + void *userdata, const float origin[3], const float dir[3], + const float scale[3], int index, BVHTreeNearest *nearest) +{ + struct NearestDM_Data *ndata = userdata; + const BMEditMesh *em = ndata->bvhdata; + BMEdge *eed = BM_edge_at_index(em->bm, index); + + if (test_edge( + eed->v1->co, eed->v2->co, origin, dir, ndata->ray_depth_range, scale, ndata->is_persp, + ndata->ray_depth, &nearest->dist_sq, + nearest->co, nearest->no)) + { + nearest->index = index; + } +} static bool snapEditMesh( SnapObjectContext *sctx, - Object *ob, BMEditMesh *em, float obmat[4][4], - const float mval[2], float *dist_px, const short snap_to, - const float ray_start[3], const float ray_normal[3], const float ray_origin[3], - float *ray_depth, const unsigned int ob_index, + Object *ob, BMEditMesh *em, float obmat[4][4], const unsigned int ob_index, + float *dist_px, const short snap_to, + const float ray_origin[3], const float ray_start[3], const float ray_normal[3], const float ray_depth_range[2], + /* read/write args */ + float *ray_depth, float *dist_to_ray_sq, + /* return args */ float r_loc[3], float r_no[3], int *r_index, ListBase *r_hit_list) { - ARegion *ar = sctx->v3d_data.ar; bool retval = false; if (snap_to == SCE_SNAP_MODE_FACE) { @@ -985,31 +1245,19 @@ static bool snapEditMesh( } { - const bool do_ray_start_correction = ( - ELEM(snap_to, SCE_SNAP_MODE_FACE, SCE_SNAP_MODE_VERTEX) && - (sctx->use_v3d && !((RegionView3D *)sctx->v3d_data.ar->regiondata)->is_persp)); + const bool is_persp = (sctx->use_v3d && ((RegionView3D *)sctx->v3d_data.ar->regiondata)->is_persp); float imat[4][4]; float timat[3][3]; /* transpose inverse matrix for normals */ - float ray_start_local[3], ray_normal_local[3]; - float local_scale, local_depth; + float ray_normal_local[3]; invert_m4_m4(imat, obmat); transpose_m3_m4(timat, imat); - copy_v3_v3(ray_start_local, ray_start); copy_v3_v3(ray_normal_local, ray_normal); - mul_m4_v3(imat, ray_start_local); mul_mat3_m4_v3(imat, ray_normal_local); - /* local scale in normal direction */ - local_scale = normalize_v3(ray_normal_local); - local_depth = *ray_depth; - if (local_depth != BVH_RAYCAST_DIST_MAX) { - local_depth *= local_scale; - } - SnapObjectData_EditMesh *sod = NULL; BVHTreeFromEditMesh *treedata = NULL, treedata_stack; @@ -1027,6 +1275,9 @@ static bool snapEditMesh( int tree_index = -1; switch (snap_to) { case SCE_SNAP_MODE_FACE: + tree_index = 2; + break; + case SCE_SNAP_MODE_EDGE: tree_index = 1; break; case SCE_SNAP_MODE_VERTEX: @@ -1041,10 +1292,8 @@ static bool snapEditMesh( } } else { - if (ELEM(snap_to, SCE_SNAP_MODE_FACE, SCE_SNAP_MODE_VERTEX)) { - treedata = &treedata_stack; - memset(treedata, 0, sizeof(*treedata)); - } + treedata = &treedata_stack; + memset(treedata, 0, sizeof(*treedata)); } if (treedata && treedata->tree == NULL) { @@ -1059,12 +1308,29 @@ static bool snapEditMesh( em->bm, looptri_mask, sctx->callbacks.edit_mesh.test_face_fn, sctx->callbacks.edit_mesh.user_data); } - bvhtree_from_editmesh_looptri_ex(treedata, em, looptri_mask, looptri_num_active, 0.0f, 4, 6); + bvhtree_from_editmesh_looptri_ex(treedata, em, looptri_mask, looptri_num_active, 0.0f, 4, 6, NULL); if (looptri_mask) { MEM_freeN(looptri_mask); } break; } + case SCE_SNAP_MODE_EDGE: + { + BLI_bitmap *edges_mask = NULL; + int edges_num_active = -1; + if (sctx->callbacks.edit_mesh.test_edge_fn) { + edges_mask = BLI_BITMAP_NEW(em->bm->totedge, __func__); + edges_num_active = BM_iter_mesh_bitmap_from_filter( + BM_EDGES_OF_MESH, em->bm, edges_mask, + (bool (*)(BMElem *, void *))sctx->callbacks.edit_mesh.test_edge_fn, + sctx->callbacks.edit_mesh.user_data); + } + bvhtree_from_editmesh_edges_ex(treedata, em, edges_mask, edges_num_active, 0.0f, 2, 6); + if (edges_mask) { + MEM_freeN(edges_mask); + } + break; + } case SCE_SNAP_MODE_VERTEX: { BLI_bitmap *verts_mask = NULL; @@ -1085,43 +1351,56 @@ static bool snapEditMesh( } } - /* Only use closer ray_start in case of ortho view! In perspective one, ray_start may already - * been *inside* boundbox, leading to snap failures (see T38409). - * Note also ar might be null (see T38435), in this case we assume ray_start is ok! - */ - float len_diff = 0.0f; - if (do_ray_start_correction) { - /* We *need* a reasonably valid len_diff in this case. - * Use BHVTree to find the closest face from ray_start_local. - */ - if (treedata && treedata->tree != NULL) { - BVHTreeNearest nearest; - nearest.index = -1; - nearest.dist_sq = FLT_MAX; - /* Compute and store result. */ - if (BLI_bvhtree_find_nearest( - treedata->tree, ray_start_local, &nearest, treedata->nearest_callback, treedata) != -1) - { - len_diff = sqrtf(nearest.dist_sq); - float ray_org_local[3]; - - copy_v3_v3(ray_org_local, ray_origin); - mul_m4_v3(imat, ray_org_local); - - /* We pass a temp ray_start, set from object's boundbox, to avoid precision issues with very far - * away ray_start values (as returned in case of ortho view3d), see T38358. - */ - len_diff -= local_scale; /* make temp start point a bit away from bbox hit point. */ - madd_v3_v3v3fl(ray_start_local, ray_org_local, ray_normal_local, - len_diff - len_v3v3(ray_start_local, ray_org_local)); - local_depth -= len_diff; - } - } - } - switch (snap_to) { case SCE_SNAP_MODE_FACE: { + float ray_start_local[3]; + copy_v3_v3(ray_start_local, ray_start); + mul_m4_v3(imat, ray_start_local); + + /* local scale in normal direction */ + float local_scale = normalize_v3(ray_normal_local); + float local_depth = *ray_depth; + if (local_depth != BVH_RAYCAST_DIST_MAX) { + local_depth *= local_scale; + } + + /* Only use closer ray_start in case of ortho view! In perspective one, ray_start may already + * been *inside* boundbox, leading to snap failures (see T38409). + * Note also ar might be null (see T38435), in this case we assume ray_start is ok! + */ + float len_diff = 0.0f; + if (sctx->use_v3d && !is_persp) { /* do_ray_start_correction */ + /* We *need* a reasonably valid len_diff in this case. + * Use BHVTree to find the closest face from ray_start_local. + */ + if (treedata && treedata->tree != NULL) { + BVHTreeNearest nearest; + nearest.index = -1; + nearest.dist_sq = FLT_MAX; + /* Compute and store result. */ + if (BLI_bvhtree_find_nearest( + treedata->tree, ray_start_local, &nearest, NULL, NULL) != -1) + { + float dvec[3]; + sub_v3_v3v3(dvec, nearest.co, ray_start_local); + len_diff = dot_v3v3(dvec, ray_normal_local); + float ray_org_local[3]; + + copy_v3_v3(ray_org_local, ray_origin); + mul_m4_v3(imat, ray_org_local); + + /* We pass a temp ray_start, set from object's boundbox, + * to avoid precision issues with very far away ray_start values + * (as returned in case of ortho view3d), see T38358. + */ + len_diff -= local_scale; /* make temp start point a bit away from bbox hit point. */ + madd_v3_v3v3fl(ray_start_local, ray_org_local, ray_normal_local, + len_diff + ray_depth_range[0]); + local_depth -= len_diff; + } + } + } if (r_hit_list) { struct RayCastAll_Data data; @@ -1176,47 +1455,92 @@ static bool snapEditMesh( } break; } - case SCE_SNAP_MODE_VERTEX: + case SCE_SNAP_MODE_EDGE: { + float ray_org_local[3]; + + copy_v3_v3(ray_org_local, ray_origin); + mul_m4_v3(imat, ray_org_local); + BVHTreeNearest nearest; nearest.index = -1; - nearest.dist_sq = local_depth * local_depth; - if (treedata->tree && + nearest.dist_sq = *dist_to_ray_sq; + + struct NearestDM_Data userdata; + userdata.bvhdata = em; + userdata.is_persp = is_persp; + userdata.ray_depth_range = ray_depth_range; + userdata.ray_depth = ray_depth; + + float ob_scale[3]; + mat4_to_size(ob_scale, obmat); + + if (treedata->tree && ( + is_persp ? + BLI_bvhtree_find_nearest_to_ray_angle( + treedata->tree, ray_org_local, ray_normal_local, + false, ob_scale, &nearest, test_bmedge_depth_cb, &userdata) : BLI_bvhtree_find_nearest_to_ray( - treedata->tree, ray_start_local, ray_normal_local, - &nearest, NULL, NULL) != -1) + treedata->tree, ray_org_local, ray_normal_local, + false, ob_scale, &nearest, test_bmedge_depth_cb, &userdata)) != -1) { - const BMVert *v = BM_vert_at_index(em->bm, nearest.index); - retval = snapVertex( - ar, v->co, v->no, obmat, timat, mval, dist_px, - ray_start, ray_start_local, ray_normal_local, ray_depth, - r_loc, r_no); + copy_v3_v3(r_loc, nearest.co); + mul_m4_v3(obmat, r_loc); + if (r_no) { + copy_v3_v3(r_no, nearest.no); + mul_m3_v3(timat, r_no); + normalize_v3(r_no); + } + *dist_px *= nearest.dist_sq / (*dist_to_ray_sq); + *dist_to_ray_sq = nearest.dist_sq; + + retval = true; } break; } - case SCE_SNAP_MODE_EDGE: + case SCE_SNAP_MODE_VERTEX: { - BM_mesh_elem_table_ensure(em->bm, BM_EDGE); - int totedge = em->bm->totedge; - for (int i = 0; i < totedge; i++) { - BMEdge *eed = BM_edge_at_index(em->bm, i); - - if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && - !BM_elem_flag_test(eed->v1, BM_ELEM_SELECT) && - !BM_elem_flag_test(eed->v2, BM_ELEM_SELECT)) - { - short v1no[3], v2no[3]; - normal_float_to_short_v3(v1no, eed->v1->no); - normal_float_to_short_v3(v2no, eed->v2->no); - retval |= snapEdge( - ar, eed->v1->co, v1no, eed->v2->co, v2no, - obmat, timat, mval, dist_px, - ray_start, ray_start_local, ray_normal_local, ray_depth, - r_loc, r_no); + float ray_org_local[3]; + + copy_v3_v3(ray_org_local, ray_origin); + mul_m4_v3(imat, ray_org_local); + + BVHTreeNearest nearest; + + nearest.index = -1; + nearest.dist_sq = *dist_to_ray_sq; + + struct NearestDM_Data userdata; + userdata.bvhdata = em; + userdata.is_persp = is_persp; + userdata.ray_depth_range = ray_depth_range; + userdata.ray_depth = ray_depth; + + float ob_scale[3]; + mat4_to_size(ob_scale, obmat); + + if (treedata->tree && ( + is_persp ? + BLI_bvhtree_find_nearest_to_ray_angle( + treedata->tree, ray_org_local, ray_normal_local, + false, ob_scale, &nearest, test_bmvert_depth_cb, &userdata) : + BLI_bvhtree_find_nearest_to_ray( + treedata->tree, ray_org_local, ray_normal_local, + false, ob_scale, &nearest, test_bmedge_depth_cb, &userdata)) != -1) + { + copy_v3_v3(r_loc, nearest.co); + mul_m4_v3(obmat, r_loc); + if (r_no) { + copy_v3_v3(r_no, nearest.no); + mul_m3_v3(timat, r_no); + normalize_v3(r_no); } - } + *dist_px *= nearest.dist_sq / (*dist_to_ray_sq); + *dist_to_ray_sq = nearest.dist_sq; + retval = true; + } break; } } @@ -1231,18 +1555,28 @@ static bool snapEditMesh( return retval; } +/** + * \param use_obedit: Uses the coordinates of BMesh (if any) to do the snapping; + * \param ray_depth_range: + * - 0: distance from the ray_origin to the clipping plane min (can be negative). + * - 1: maximum distance, elements outside this are ignored. + * \param ray_depth: maximum depth allowed for r_co. + * + * \note Duplicate args here are documented at #snapObjectsRay + */ static bool snapObject( SnapObjectContext *sctx, - Object *ob, float obmat[4][4], bool use_obedit, const short snap_to, - const float mval[2], float *dist_px, const unsigned int ob_index, - const float ray_start[3], const float ray_normal[3], const float ray_origin[3], - float *ray_depth, + Object *ob, float obmat[4][4], const unsigned int ob_index, + bool use_obedit, const short snap_to, const float mval[2], + const float ray_origin[3], const float ray_start[3], const float ray_normal[3], const float ray_depth_range[2], + /* read/write args */ + float *ray_depth, float *dist_to_ray_sq, float *dist_px, /* return args */ float r_loc[3], float r_no[3], int *r_index, Object **r_ob, float r_obmat[4][4], ListBase *r_hit_list) { - ARegion *ar = sctx->v3d_data.ar; + const ARegion *ar = sctx->v3d_data.ar; bool retval = false; if (ob->type == OB_MESH) { @@ -1251,9 +1585,10 @@ static bool snapObject( if (use_obedit) { em = BKE_editmesh_from_object(ob); retval = snapEditMesh( - sctx, ob, em, obmat, mval, dist_px, snap_to, - ray_start, ray_normal, ray_origin, - ray_depth, ob_index, + sctx, ob, em, obmat, ob_index, + dist_px, snap_to, + ray_origin, ray_start, ray_normal, ray_depth_range, + ray_depth, dist_to_ray_sq, r_loc, r_no, r_index, r_hit_list); } @@ -1269,36 +1604,42 @@ static bool snapObject( dm = mesh_get_derived_final(sctx->scene, ob, CD_MASK_BAREMESH); } retval = snapDerivedMesh( - sctx, ob, dm, obmat, mval, dist_px, snap_to, true, - ray_start, ray_normal, ray_origin, - ray_depth, ob_index, - r_loc, r_no, r_index, r_hit_list); + sctx, ob, dm, obmat, ob_index, + snap_to, true, + ray_origin, ray_start, ray_normal, ray_depth_range, + ray_depth, dist_to_ray_sq, dist_px, + r_loc, r_no, + r_index, r_hit_list); dm->release(dm); } } else if (ob->type == OB_ARMATURE) { retval = snapArmature( - ar, ob, ob->data, obmat, mval, dist_px, snap_to, - ray_start, ray_normal, ray_depth, + ar, ob, ob->data, obmat, mval, snap_to, + ray_start, ray_normal, + ray_depth, dist_px, r_loc, r_no); } else if (ob->type == OB_CURVE) { retval = snapCurve( - ar, ob, ob->data, obmat, mval, dist_px, snap_to, - ray_start, ray_normal, ray_depth, + ar, ob, ob->data, obmat, mval, snap_to, + ray_start, ray_normal, + ray_depth, dist_px, r_loc, r_no); } else if (ob->type == OB_EMPTY) { retval = snapEmpty( - ar, ob, obmat, mval, dist_px, snap_to, - ray_start, ray_normal, ray_depth, + ar, ob, obmat, mval, snap_to, + ray_start, ray_normal, + ray_depth, dist_px, r_loc, r_no); } else if (ob->type == OB_CAMERA) { retval = snapCamera( - ar, sctx->scene, ob, obmat, mval, dist_px, snap_to, - ray_start, ray_normal, ray_depth, + ar, sctx->scene, ob, obmat, mval, snap_to, + ray_start, ray_normal, + ray_depth, dist_px, r_loc, r_no); } @@ -1312,18 +1653,68 @@ static bool snapObject( return retval; } +/** + * Main Snapping Function + * ====================== + * + * Walks through all objects in the scene to find the closest snap element ray. + * + * \param sctx: Snap context to store data. + * \param snap_to: Element to snap, Vertice, Edge or Face. + * Currently only works one at a time, but can eventually operate as flag. + * + * \param snap_select: from enum SnapSelect. + * + * \param use_object_edit_cage: Uses the coordinates of BMesh (if any) to do the snapping. + * \param mval: Optional screen-space 2D location we're snapping to (may phase out). + * \param ray_origin: ray_start before being moved toward the ray_normal at the distance from vew3d clip_min. + * \param ray_start: ray_origin moved for the start clipping plane (clip_min). + * \param ray_normal: Unit length direction of the ray. + * + * Read/Write Args + * --------------- + * + * \param ray_depth: maximum depth allowed for r_co, elements deeper than this value will be ignored. + * \param dist_to_ray_sq: Real distance (3D) or Tangent (view cone radius at distance 1.0) squared. + * resulting of the function #dist_px_to_dist3d_or_tangent. + * + * \param dist_px: Pixel distance to element, + * note that this will eventually be replaced entirely by \a dist_to_ray_sq. + * + * Output Args + * ----------- + * + * \param r_loc: Hit location. + * \param r_no: Hit normal (optional). + * \param r_index: Hit index or -1 when no valid index is found. + * (currently only set to the polygon index when when using ``snap_to == SCE_SNAP_MODE_FACE``). + * \param r_ob: Hit object. + * \param r_obmat: Object matrix (may not be #Object.obmat with dupli-instances). + * \param r_hit_list: List of #SnapObjectHitDepth (caller must free). + * + */ static bool snapObjectsRay( SnapObjectContext *sctx, const unsigned short snap_to, const SnapSelect snap_select, - const bool use_object_edit_cage, - const float mval[2], float *dist_px, - const float ray_start[3], const float ray_normal[3], const float ray_origin[3], float *ray_depth, + const bool use_object_edit_cage, const float mval[2], + const float ray_origin[3], const float ray_start[3], const float ray_normal[3], + /* read/write args */ + float *ray_depth, float *dist_to_ray_sq, float *dist_px, /* return args */ float r_loc[3], float r_no[3], int *r_index, Object **r_ob, float r_obmat[4][4], ListBase *r_hit_list) { bool retval = false; + + float dvec[3]; + sub_v3_v3v3(dvec, ray_start, ray_origin); + + const float ray_depth_range[2] = { + dot_v3v3(dvec, ray_normal), + *ray_depth, + }; + unsigned int ob_index = 0; Object *obedit = use_object_edit_cage ? sctx->scene->obedit : NULL; @@ -1337,9 +1728,10 @@ static bool snapObjectsRay( Object *ob = base_act->object; retval |= snapObject( - sctx, ob, ob->obmat, false, snap_to, - mval, dist_px, ob_index++, - ray_start, ray_normal, ray_origin, ray_depth, + sctx, ob, ob->obmat, ob_index++, + false, snap_to, mval, + ray_origin, ray_start, ray_normal, ray_depth_range, + ray_depth, dist_to_ray_sq, dist_px, r_loc, r_no, r_index, r_ob, r_obmat, r_hit_list); } @@ -1372,9 +1764,10 @@ static bool snapObjectsRay( Object *dupli_snap = (use_obedit_dupli) ? obedit : dupli_ob->ob; retval |= snapObject( - sctx, dupli_snap, dupli_ob->mat, use_obedit_dupli, snap_to, - mval, dist_px, ob_index++, - ray_start, ray_normal, ray_origin, ray_depth, + sctx, dupli_snap, dupli_ob->mat, ob_index++, + use_obedit_dupli, snap_to, mval, + ray_origin, ray_start, ray_normal, ray_depth_range, + ray_depth, dist_to_ray_sq, dist_px, r_loc, r_no, r_index, r_ob, r_obmat, r_hit_list); } @@ -1385,9 +1778,10 @@ static bool snapObjectsRay( Object *ob_snap = use_obedit ? obedit : ob; retval |= snapObject( - sctx, ob_snap, ob->obmat, use_obedit, snap_to, - mval, dist_px, ob_index++, - ray_start, ray_normal, ray_origin, ray_depth, + sctx, ob_snap, ob->obmat, ob_index++, + use_obedit, snap_to, mval, + ray_origin, ray_start, ray_normal, ray_depth_range, + ray_depth, dist_to_ray_sq, dist_px, r_loc, r_no, r_index, r_ob, r_obmat, r_hit_list); } } @@ -1419,7 +1813,7 @@ SnapObjectContext *ED_transform_snap_object_context_create( SnapObjectContext *ED_transform_snap_object_context_create_view3d( Main *bmain, Scene *scene, int flag, /* extra args for view3d */ - ARegion *ar, View3D *v3d) + const ARegion *ar, const View3D *v3d) { SnapObjectContext *sctx = ED_transform_snap_object_context_create(bmain, scene, flag); @@ -1489,15 +1883,19 @@ bool ED_transform_snap_object_project_ray_ex( SnapObjectContext *sctx, const unsigned short snap_to, const struct SnapObjectParams *params, - const float ray_start[3], const float ray_normal[3], float *ray_depth, + const float ray_start[3], const float ray_normal[3], + float *ray_depth, float r_loc[3], float r_no[3], int *r_index, Object **r_ob, float r_obmat[4][4]) { + float dist_to_ray_sq = 0.0f; + return snapObjectsRay( sctx, snap_to, params->snap_select, params->use_object_edit_cage, - NULL, NULL, - ray_start, ray_normal, ray_start, ray_depth, + NULL, + ray_start, ray_start, ray_normal, + ray_depth, &dist_to_ray_sq, NULL, r_loc, r_no, r_index, r_ob, r_obmat, NULL); } @@ -1516,6 +1914,8 @@ bool ED_transform_snap_object_project_ray_all( float ray_depth, bool sort, ListBase *r_hit_list) { + float dist_to_ray_sq = 0.0f; + if (ray_depth == -1.0f) { ray_depth = BVH_RAYCAST_DIST_MAX; } @@ -1526,9 +1926,9 @@ bool ED_transform_snap_object_project_ray_all( bool retval = snapObjectsRay( sctx, - snap_to, params->snap_select, params->use_object_edit_cage, - NULL, NULL, - ray_start, ray_normal, ray_start, &ray_depth, + snap_to, params->snap_select, params->use_object_edit_cage, NULL, + ray_start, ray_start, ray_normal, + &ray_depth, &dist_to_ray_sq, NULL, NULL, NULL, NULL, NULL, NULL, r_hit_list); @@ -1637,6 +2037,21 @@ static bool transform_snap_context_project_view3d_mixed_impl( } /** + * From a threshold (maximum distance to snap in pixels) returns: + * + * - The *real* distance (3D) if you are in orthographic-view. + * - The *tangent* (view cone radius at distance 1.0) if you are in perspective-view. + */ +static float dist_px_to_dist3d_or_tangent(const ARegion *ar, const float dist_px) +{ + const RegionView3D *rv3d = ar->regiondata; + if (ar->winx >= ar->winy) + return 2 * (dist_px / ar->winx) / rv3d->winmat[0][0]; + else + return 2 * (dist_px / ar->winy) / rv3d->winmat[1][1]; +} + +/** * Convenience function for performing snapping. * * Given a 2D region value, snap to vert/edge/face. @@ -1672,7 +2087,7 @@ bool ED_transform_snap_object_project_view3d_ex( float *ray_depth, float r_loc[3], float r_no[3], int *r_index) { - float ray_start[3], ray_normal[3], ray_orgigin[3]; + float ray_start[3], ray_normal[3], ray_origin[3]; float ray_depth_fallback; if (ray_depth == NULL) { @@ -1682,16 +2097,37 @@ bool ED_transform_snap_object_project_view3d_ex( if (!ED_view3d_win_to_ray_ex( sctx->v3d_data.ar, sctx->v3d_data.v3d, - mval, ray_orgigin, ray_normal, ray_start, true)) + mval, ray_origin, ray_normal, ray_start, true)) { return false; } + float dist_to_ray_sq; + { + float radius = dist_px_to_dist3d_or_tangent(sctx->v3d_data.ar, *dist_px); + /** + * Workaround to use of cone (Instead of project the radius on view plane): + * In perspective view, the radius of the cone may decrease depending on the ray direction. + * This is more evident with small values of the `Viewport lens angle`. + * The threshold becomes distorted that way. + */ + RegionView3D *rv3d = sctx->v3d_data.ar->regiondata; + if (rv3d->is_persp) { + float view_dir[3]; + negate_v3_v3(view_dir, rv3d->viewinv[2]); + normalize_v3(view_dir); + radius *= dot_v3v3(ray_normal, view_dir); + } + + dist_to_ray_sq = SQUARE(radius); + } + return snapObjectsRay( sctx, snap_to, params->snap_select, params->use_object_edit_cage, - mval, dist_px, - ray_start, ray_normal, ray_orgigin, ray_depth, + mval, + ray_origin, ray_start, ray_normal, + ray_depth, &dist_to_ray_sq, dist_px, r_loc, r_no, r_index, NULL, NULL, NULL); } diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c index 59f9cd16908..cd368ab32e0 100644 --- a/source/blender/editors/uvedit/uvedit_parametrizer.c +++ b/source/blender/editors/uvedit/uvedit_parametrizer.c @@ -740,6 +740,16 @@ static PVert *p_vert_add(PHandle *handle, PHashKey key, const float co[3], PEdge { PVert *v = (PVert *)BLI_memarena_alloc(handle->arena, sizeof(*v)); copy_v3_v3(v->co, co); + + /* Sanity check, a single nan/inf point causes the entire result to be invalid. + * Note that values within the calculation may _become_ non-finite, + * so the rest of the code still needs to take this possability into account. */ + for (int i = 0; i < 3; i++) { + if (UNLIKELY(!isfinite(v->co[i]))) { + v->co[i] = 0.0f; + } + } + v->u.key = key; v->edge = e; v->flag = 0; @@ -2794,7 +2804,7 @@ static PBool p_chart_abf_solve(PChart *chart) static void p_chart_pin_positions(PChart *chart, PVert **pin1, PVert **pin2) { - if (pin1 == pin2) { + if (!*pin1 || !*pin2 || *pin1 == *pin2) { /* degenerate case */ PFace *f = chart->faces; *pin1 = f->edge->vert; @@ -3040,8 +3050,10 @@ static void p_chart_lscm_begin(PChart *chart, PBool live, PBool abf) p_chart_boundaries(chart, NULL, &outer); - if (!p_chart_symmetry_pins(chart, outer, &pin1, &pin2)) + /* outer can be NULL with non-finite coords. */ + if (!(outer && p_chart_symmetry_pins(chart, outer, &pin1, &pin2))) { p_chart_extrema_verts(chart, &pin1, &pin2); + } chart->u.lscm.pin1 = pin1; chart->u.lscm.pin2 = pin2; diff --git a/source/blender/freestyle/intern/geometry/normal_cycle.h b/source/blender/freestyle/intern/geometry/normal_cycle.h index 53bc23c6eb3..8d06865e31b 100644 --- a/source/blender/freestyle/intern/geometry/normal_cycle.h +++ b/source/blender/freestyle/intern/geometry/normal_cycle.h @@ -63,13 +63,13 @@ template <class T> inline void ogf_swap(T& x, T& y) //_________________________________________________________ /** -* NormalCycle evaluates the curvature tensor in function -* of a set of dihedral angles and associated vectors. -* Reference: -* Restricted Delaunay Triangulation and Normal Cycle, -* D. Cohen-Steiner and J.M. Morvan, -* SOCG 2003 -*/ + * NormalCycle evaluates the curvature tensor in function + * of a set of dihedral angles and associated vectors. + * Reference: + * Restricted Delaunay Triangulation and Normal Cycle, + * D. Cohen-Steiner and J.M. Morvan, + * SOCG 2003 + */ class NormalCycle { public: NormalCycle(); diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp index e35076ec7fe..96a8bee9394 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp @@ -121,7 +121,7 @@ static PyObject *StrokeVertexIterator_iternext(BPy_StrokeVertexIterator *self) return NULL; } /* If at the start of the iterator, only return the object - * and don't increment, to keep for-loops in sync */ + * and don't increment, to keep for-loops in sync */ else if (self->at_start) { self->at_start = false; } diff --git a/source/blender/freestyle/intern/scene_graph/FrsMaterial.h b/source/blender/freestyle/intern/scene_graph/FrsMaterial.h index a00f983bbcf..220c966a5d0 100644 --- a/source/blender/freestyle/intern/scene_graph/FrsMaterial.h +++ b/source/blender/freestyle/intern/scene_graph/FrsMaterial.h @@ -298,9 +298,9 @@ public: inline void setShininess(const float s); /*! Sets the line color priority. - * \param priority - * Priority - */ + * \param priority + * Priority + */ inline void setPriority(const int priority); /* operators */ diff --git a/source/blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.h b/source/blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.h index 4b079df5632..8dc93d84201 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.h +++ b/source/blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.h @@ -52,16 +52,6 @@ public: return _SceneRenderLayer; } - inline void setSceneRenderLayer(Scene& scene) - { - _Scene = scene; - } - - inline void setSceneRenderLayer(SceneRenderLayer& srl) - { - _SceneRenderLayer = srl; - } - /*! Accept the corresponding visitor */ virtual void accept(SceneVisitor& v); diff --git a/source/blender/freestyle/intern/stroke/AdvancedPredicates1D.h b/source/blender/freestyle/intern/stroke/AdvancedPredicates1D.h index f650e32b278..c65f121e9ba 100644 --- a/source/blender/freestyle/intern/stroke/AdvancedPredicates1D.h +++ b/source/blender/freestyle/intern/stroke/AdvancedPredicates1D.h @@ -46,8 +46,8 @@ namespace Predicates1D { // DensityLowerThanUP1D /*! Returns true if the density evaluated for the -* Interface1D is less than a user-defined density value. -*/ + * Interface1D is less than a user-defined density value. + */ class DensityLowerThanUP1D : public UnaryPredicate1D { public: diff --git a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.h b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.h index e3842f45eb0..cc935a7e311 100644 --- a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.h +++ b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.h @@ -619,9 +619,9 @@ public: } /*! Builds the shader. - * \param nodetree - * A node tree (of new shading nodes) to define textures. - */ + * \param nodetree + * A node tree (of new shading nodes) to define textures. + */ BlenderTextureShader(bNodeTree *nodetree) : StrokeShader() { _nodeTree = nodetree; diff --git a/source/blender/freestyle/intern/stroke/Stroke.h b/source/blender/freestyle/intern/stroke/Stroke.h index 5f0b4eab309..db96a27e073 100644 --- a/source/blender/freestyle/intern/stroke/Stroke.h +++ b/source/blender/freestyle/intern/stroke/Stroke.h @@ -605,15 +605,15 @@ public: */ int Resample(float iSampling); - /*! Removes all vertices from the Stroke. - */ - void RemoveAllVertices(); + /*! Removes all vertices from the Stroke. + */ + void RemoveAllVertices(); /*! Removes the stroke vertex iVertex - * from the stroke. - * The length and curvilinear abscissa are updated - * consequently. - */ + * from the stroke. + * The length and curvilinear abscissa are updated + * consequently. + */ void RemoveVertex(StrokeVertex *iVertex); /*! Inserts the stroke vertex iVertex in the stroke before next. diff --git a/source/blender/freestyle/intern/view_map/Functions0D.h b/source/blender/freestyle/intern/view_map/Functions0D.h index 647a3a530c6..f0009fca6ea 100644 --- a/source/blender/freestyle/intern/view_map/Functions0D.h +++ b/source/blender/freestyle/intern/view_map/Functions0D.h @@ -429,12 +429,12 @@ public: // QiF0D /*! Returns the quantitative invisibility of this Interface0D. -* This evaluation can be ambiguous (in the case of a TVertex for example). -* This functor tries to remove this ambiguity using the context offered by the 1D element to which the -* Interface0DIterator& belongs to. -* However, there still can be problematic cases, and the user willing to deal with this cases in a specific way -* should implement its own getQIF0D functor. -*/ + * This evaluation can be ambiguous (in the case of a TVertex for example). + * This functor tries to remove this ambiguity using the context offered by the 1D element to which the + * Interface0DIterator& belongs to. + * However, there still can be problematic cases, and the user willing to deal with this cases in a specific way + * should implement its own getQIF0D functor. + */ class QuantitativeInvisibilityF0D : public UnaryFunction0D<unsigned int> { public: diff --git a/source/blender/freestyle/intern/view_map/Silhouette.h b/source/blender/freestyle/intern/view_map/Silhouette.h index 0b20c9f6aa2..b9924e6ad95 100644 --- a/source/blender/freestyle/intern/view_map/Silhouette.h +++ b/source/blender/freestyle/intern/view_map/Silhouette.h @@ -1204,9 +1204,9 @@ public: } /*! Returns the index of the material of the face lying on the - * right of the FEdge. If this FEdge is a border, - * it has no Face on its right and therefore, no material. - */ + * right of the FEdge. If this FEdge is a border, + * it has no Face on its right and therefore, no material. + */ inline unsigned aFrsMaterialIndex() const { return _aFrsMaterialIndex; diff --git a/source/blender/freestyle/intern/winged_edge/Curvature.cpp b/source/blender/freestyle/intern/winged_edge/Curvature.cpp index 97dcc86cf31..989e101dd1a 100644 --- a/source/blender/freestyle/intern/winged_edge/Curvature.cpp +++ b/source/blender/freestyle/intern/winged_edge/Curvature.cpp @@ -372,21 +372,21 @@ void gts_vertex_principal_directions(WVertex *v, Vec3r Kh, real Kg, Vec3r &e1, V f2 = e->GetbFace(); /* We are solving for the values of the curvature tensor - * B = [ a b ; b c ]. - * The computations here are from section 5 of [Meyer et al 2002]. - * - * The first step is to calculate the linear equations governing the values of (a,b,c). These can be computed - * by setting the derivatives of the error E to zero (section 5.3). - * - * Since a + c = norm(Kh), we only compute the linear equations for dE/da and dE/db. (NB: [Meyer et al 2002] - * has the equation a + b = norm(Kh), but I'm almost positive this is incorrect). - * - * Note that the w_ij (defined in section 5.2) are all scaled by (1/8*A_mixed). We drop this uniform scale - * factor because the solution of the linear equations doesn't rely on it. - * - * The terms of the linear equations are xterm_dy with x in {a,b,c} and y in {a,b}. There are also const_dy - * terms that are the constant factors in the equations. - */ + * B = [ a b ; b c ]. + * The computations here are from section 5 of [Meyer et al 2002]. + * + * The first step is to calculate the linear equations governing the values of (a,b,c). These can be computed + * by setting the derivatives of the error E to zero (section 5.3). + * + * Since a + c = norm(Kh), we only compute the linear equations for dE/da and dE/db. (NB: [Meyer et al 2002] + * has the equation a + b = norm(Kh), but I'm almost positive this is incorrect). + * + * Note that the w_ij (defined in section 5.2) are all scaled by (1/8*A_mixed). We drop this uniform scale + * factor because the solution of the linear equations doesn't rely on it. + * + * The terms of the linear equations are xterm_dy with x in {a,b,c} and y in {a,b}. There are also const_dy + * terms that are the constant factors in the equations. + */ /* find the vector from v along edge e */ vec_edge = Vec3r(-1 * e->GetVec()); @@ -400,7 +400,7 @@ void gts_vertex_principal_directions(WVertex *v, Vec3r Kh, real Kg, Vec3r &e1, V /* section 5.2 */ /* I don't like performing a minimization where some of the weights can be negative (as can be the case - * if f1 or f2 are obtuse). To ensure all-positive weights, we check for obtuseness. */ + * if f1 or f2 are obtuse). To ensure all-positive weights, we check for obtuseness. */ weight = 0.0; if (!triangle_obtuse(v, f1)) { weight += ve2 * cotan(f1->GetNextOEdge(e->twin())->GetbVertex(), e->GetaVertex(), e->GetbVertex()) / 8.0; diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h index a79334df8ce..0d92d22a173 100644 --- a/source/blender/gpu/GPU_material.h +++ b/source/blender/gpu/GPU_material.h @@ -337,6 +337,7 @@ void GPU_mist_update_enable(short enable); void GPU_mist_update_values(int type, float start, float dist, float inten, float color[3]); void GPU_horizon_update_color(float color[3]); void GPU_ambient_update_color(float color[3]); +void GPU_zenith_update_color(float color[3]); struct GPUParticleInfo { diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index f14b2e6e170..fd7f205214e 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -88,6 +88,7 @@ static struct GPUWorld { float mistcol[4]; float horicol[3]; float ambcol[4]; + float zencol[3]; } GPUWorld; struct GPUMaterial { @@ -1673,6 +1674,11 @@ void GPU_ambient_update_color(float color[3]) GPUWorld.ambcol[3] = 1.0f; } +void GPU_zenith_update_color(float color[3]) +{ + copy_v3_v3(GPUWorld.zencol, color); +} + void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr) { GPUMaterial *mat = shi->gpumat; @@ -1729,6 +1735,33 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr) ulinfac, ulogfac, &shr->spec); } + /* environment lighting */ + if (!(mat->scene->gm.flag & GAME_GLSL_NO_ENV_LIGHTING) && (world->mode & WO_ENV_LIGHT) && (mat->scene->r.mode & R_SHADOW) && + !BKE_scene_use_new_shading_nodes(mat->scene)) + { + if ((world->ao_env_energy != 0.0f) && (GPU_link_changed(shi->amb) || ma->amb != 0.0f) && + (GPU_link_changed(shi->refl) || ma->ref != 0.0f)) + { + if (world->aocolor != WO_AOPLAIN) { + if (!(is_zero_v3(&world->horr) & is_zero_v3(&world->zenr))) + { + GPUNodeLink *fcol, *f; + GPU_link(mat, "math_multiply", shi->amb, shi->refl, &f); + GPU_link(mat, "math_multiply", f, GPU_uniform(&world->ao_env_energy), &f); + GPU_link(mat, "shade_mul_value", f, shi->rgb, &fcol); + GPU_link(mat, "env_apply", shr->combined, GPU_dynamic_uniform(GPUWorld.horicol, GPU_DYNAMIC_HORIZON_COLOR, NULL), + GPU_dynamic_uniform(GPUWorld.zencol, GPU_DYNAMIC_ZENITH_COLOR, NULL), fcol, GPU_builtin(GPU_VIEW_MATRIX), shi->vn, &shr->combined); + } + } + else { + GPUNodeLink *f; + GPU_link(mat, "math_multiply", shi->amb, shi->refl, &f); + GPU_link(mat, "math_multiply", f, GPU_uniform(&world->ao_env_energy), &f); + GPU_link(mat, "shade_maddf", shr->combined, f, shi->rgb, &shr->combined); + } + } + } + /* ambient color */ if (GPU_link_changed(shi->amb) || ma->amb != 0.0f) { GPU_link(mat, "shade_maddf", shr->combined, GPU_uniform(&ma->amb), @@ -2552,7 +2585,7 @@ int GPU_lamp_shadow_bind_code(GPULamp *lamp) float *GPU_lamp_dynpersmat(GPULamp *lamp) { - return lamp->dynpersmat ? (float *)lamp->dynpersmat : NULL; + return (float*)lamp->dynpersmat; } int GPU_lamp_shadow_layer(GPULamp *lamp) diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index 9914c4bb362..f3bd817a7cc 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -1358,6 +1358,13 @@ void mtex_cube_map(vec3 co, samplerCube ima, out float value, out vec4 color) value = 1.0; } +void mtex_cube_map_refl_from_refldir( + samplerCube ima, vec3 reflecteddirection, out float value, out vec4 color) +{ + color = textureCube(ima, reflecteddirection); + value = 1.0; +} + void mtex_cube_map_refl( samplerCube ima, vec3 vp, vec3 vn, mat4 viewmatrixinverse, mat4 viewmatrix, out float value, out vec4 color) @@ -2182,6 +2189,13 @@ void shade_madd_clamped(vec4 col, vec4 col1, vec4 col2, out vec4 outcol) outcol = col + max(col1 * col2, vec4(0.0, 0.0, 0.0, 0.0)); } +void env_apply(vec4 col, vec4 hor, vec4 zen, vec4 f, mat4 vm, vec3 vn, out vec4 outcol) +{ + vec3 vv = normalize(vm[2].xyz); + float skyfac = 0.5 * (1.0 + dot(vn, -vv)); + outcol = col + f * mix(hor, zen, skyfac); +} + void shade_maddf(vec4 col, float f, vec4 col1, out vec4 outcol) { outcol = col + f * col1; diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index 611ada5b077..89e796fb7ee 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -77,7 +77,7 @@ extern "C" { // The following prevents a linking error in debug mode for MSVC using the libs in CVS -#if defined(WITH_OPENEXR) && defined(_WIN32) && defined(DEBUG) && !defined(__MINGW32__) +#if defined(WITH_OPENEXR) && defined(_WIN32) && defined(DEBUG) && !defined(__MINGW32__) && _MSC_VER < 1900 _CRTIMP void __cdecl _invalid_parameter_noinfo(void) { } diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c index 95d061bcb75..3629332a4ac 100644 --- a/source/blender/imbuf/intern/thumbs.c +++ b/source/blender/imbuf/intern/thumbs.c @@ -46,6 +46,8 @@ #include "BLO_readfile.h" +#include "DNA_space_types.h" /* For FILE_MAX_LIBEXTRA */ + #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" #include "IMB_thumbs.h" @@ -533,7 +535,7 @@ ImBuf *IMB_thumb_manage(const char *org_path, ThumbSize size, ThumbSource source char thumb_path[FILE_MAX]; char thumb_name[40]; char uri[URI_MAX]; - char path_buff[FILE_MAX]; + char path_buff[FILE_MAX_LIBEXTRA]; const char *file_path; const char *path; BLI_stat_t st; diff --git a/source/blender/makesdna/DNA_anim_types.h b/source/blender/makesdna/DNA_anim_types.h index 4c1283452ff..6bd7b3a4999 100644 --- a/source/blender/makesdna/DNA_anim_types.h +++ b/source/blender/makesdna/DNA_anim_types.h @@ -537,8 +537,9 @@ typedef enum eFCurve_Extend { /* curve coloring modes */ typedef enum eFCurve_Coloring { FCURVE_COLOR_AUTO_RAINBOW = 0, /* automatically determine color using rainbow (calculated at drawtime) */ - FCURVE_COLOR_AUTO_RGB, /* automatically determine color using XYZ (array index) <-> RGB */ - FCURVE_COLOR_CUSTOM /* custom color */ + FCURVE_COLOR_AUTO_RGB = 1, /* automatically determine color using XYZ (array index) <-> RGB */ + FCURVE_COLOR_AUTO_YRGB = 3, /* automatically determine color where XYZ <-> RGB, but index(X) != 0 */ + FCURVE_COLOR_CUSTOM = 2, /* custom color */ } eFCurve_Coloring; /* ************************************************ */ diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 985c4575f23..e12692bec44 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -902,6 +902,7 @@ typedef struct GameData { #define GAME_GLSL_NO_COLOR_MANAGEMENT (1 << 15) #define GAME_SHOW_OBSTACLE_SIMULATION (1 << 16) #define GAME_NO_MATERIAL_CACHING (1 << 17) +#define GAME_GLSL_NO_ENV_LIGHTING (1 << 18) /* Note: GameData.flag is now an int (max 32 flags). A short could only take 16 flags */ /* GameData.playerflag */ diff --git a/source/blender/makesdna/intern/CMakeLists.txt b/source/blender/makesdna/intern/CMakeLists.txt index b4ada7ffbf1..0bb6e866bf4 100644 --- a/source/blender/makesdna/intern/CMakeLists.txt +++ b/source/blender/makesdna/intern/CMakeLists.txt @@ -56,8 +56,14 @@ add_executable(makesdna ${SRC} ${SRC_DNA_INC}) # Output dna.c add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dna.c - COMMAND "$<TARGET_FILE:makesdna>" ${CMAKE_CURRENT_BINARY_DIR}/dna.c ${CMAKE_SOURCE_DIR}/source/blender/makesdna/ + OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/dna.c + ${CMAKE_CURRENT_BINARY_DIR}/dna_type_offsets.h + COMMAND + "$<TARGET_FILE:makesdna>" + ${CMAKE_CURRENT_BINARY_DIR}/dna.c + ${CMAKE_CURRENT_BINARY_DIR}/dna_type_offsets.h + ${CMAKE_SOURCE_DIR}/source/blender/makesdna/ DEPENDS makesdna ) @@ -78,7 +84,11 @@ set(SRC ${SRC_DNA_INC} ) -set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/dna.c PROPERTIES GENERATED TRUE) +set_source_files_properties( + ${CMAKE_CURRENT_BINARY_DIR}/dna.c + ${CMAKE_CURRENT_BINARY_DIR}/dna_type_offsets.h + PROPERTIES GENERATED TRUE +) blender_add_lib(bf_dna "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c index fc94a8d9ff4..b78299316e1 100644 --- a/source/blender/makesdna/intern/makesdna.c +++ b/source/blender/makesdna/intern/makesdna.c @@ -968,7 +968,7 @@ void printStructLengths(void) } -static int make_structDNA(const char *baseDirectory, FILE *file) +static int make_structDNA(const char *baseDirectory, FILE *file, FILE *file_offsets) { int len, i; const short *sp; @@ -1159,6 +1159,19 @@ static int make_structDNA(const char *baseDirectory, FILE *file) /* end end padding test */ } + /* write a simple enum with all structs offsets, + * should only be accessed via SDNA_TYPE_FROM_STRUCT macro */ + { + fprintf(file_offsets, "#define SDNA_TYPE_FROM_STRUCT(id) _SDNA_TYPE_##id\n"); + fprintf(file_offsets, "enum {\n"); + for (i = 0; i < nr_structs; i++) { + const short *structpoin = structs[i]; + const int structtype = structpoin[0]; + fprintf(file_offsets, "\t_SDNA_TYPE_%s = %d,\n", types[structtype], i); + } + fprintf(file_offsets, "\tSDNA_TYPE_MAX = %d,\n", nr_structs); + fprintf(file_offsets, "};\n"); + } MEM_freeN(namedata); MEM_freeN(typedata); @@ -1190,43 +1203,53 @@ static void make_bad_file(const char *file, int line) int main(int argc, char **argv) { - FILE *file; int return_status = 0; - if (argc != 2 && argc != 3) { - printf("Usage: %s outfile.c [base directory]\n", argv[0]); + if (argc != 3 && argc != 4) { + printf("Usage: %s dna.c dna_struct_offsets.h [base directory]\n", argv[0]); return_status = 1; } else { - file = fopen(argv[1], "w"); - if (!file) { + FILE *file_dna = fopen(argv[1], "w"); + FILE *file_dna_offsets = fopen(argv[2], "w"); + if (!file_dna) { printf("Unable to open file: %s\n", argv[1]); return_status = 1; } + else if (!file_dna_offsets) { + printf("Unable to open file: %s\n", argv[2]); + return_status = 1; + } else { const char *baseDirectory; - if (argc == 3) { - baseDirectory = argv[2]; + if (argc == 4) { + baseDirectory = argv[3]; } else { baseDirectory = BASE_HEADER; } - fprintf(file, "const unsigned char DNAstr[] = {\n"); - if (make_structDNA(baseDirectory, file)) { + fprintf(file_dna, "const unsigned char DNAstr[] = {\n"); + if (make_structDNA(baseDirectory, file_dna, file_dna_offsets)) { /* error */ - fclose(file); + fclose(file_dna); + file_dna = NULL; make_bad_file(argv[1], __LINE__); return_status = 1; } else { - fprintf(file, "};\n"); - fprintf(file, "const int DNAlen = sizeof(DNAstr);\n"); - - fclose(file); + fprintf(file_dna, "};\n"); + fprintf(file_dna, "const int DNAlen = sizeof(DNAstr);\n"); } } + + if (file_dna) { + fclose(file_dna); + } + if (file_dna_offsets) { + fclose(file_dna_offsets); + } } diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index a89cb9c84d8..627a320ccf4 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -227,6 +227,10 @@ static const char *rna_safe_id(const char *id) return "operator_value"; else if (STREQ(id, "new")) return "create"; + else if (STREQ(id, "co_return")) { + /* MSVC2015, C++ uses for coroutines */ + return "coord_return"; + } return id; } diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index c49a6197a4e..0eaeabccd99 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -4678,7 +4678,7 @@ static void rna_path_array_multi_string_from_flat_index( } /** - * \param index_dim: The dimensiuon to show, 0 disables. 1 for 1d array, 2 for 2d. etc. + * \param index_dim: The dimension to show, 0 disables. 1 for 1d array, 2 for 2d. etc. * \param index: The *flattened* index to use when \a ``index_dim > 0``, * this is expanded when used with multi-dimensional arrays. */ diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c index 1487dfa074e..3043c5452c0 100644 --- a/source/blender/makesrna/intern/rna_fcurve.c +++ b/source/blender/makesrna/intern/rna_fcurve.c @@ -1844,6 +1844,8 @@ static void rna_def_fcurve(BlenderRNA *brna) "Cycle through the rainbow, trying to give each curve a unique color"}, {FCURVE_COLOR_AUTO_RGB, "AUTO_RGB", 0, "Auto XYZ to RGB", "Use axis colors for transform and color properties, and auto-rainbow for the rest"}, + {FCURVE_COLOR_AUTO_YRGB, "AUTO_YRGB", 0, "Auto WXYZ to YRGB", + "Use axis colors for XYZ parts of transform, and yellow for the 'W' channel"}, {FCURVE_COLOR_CUSTOM, "CUSTOM", 0, "User Defined", "Use custom hand-picked color for F-Curve"}, {0, NULL, 0, NULL, NULL} diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 111bdc4c537..a52f579fb29 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -4385,6 +4385,11 @@ static void rna_def_scene_game_data(BlenderRNA *brna) "Use extra textures like normal or specular maps for GLSL rendering"); RNA_def_property_update(prop, NC_SCENE | NA_EDITED, "rna_Scene_glsl_update"); + prop = RNA_def_property(srna, "use_glsl_environment_lighting", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_GLSL_NO_ENV_LIGHTING); + RNA_def_property_ui_text(prop, "GLSL Environment Lighting", "Use environment lighting for GLSL rendering"); + RNA_def_property_update(prop, NC_SCENE | NA_EDITED, "rna_Scene_glsl_update"); + prop = RNA_def_property(srna, "use_material_caching", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_NO_MATERIAL_CACHING); RNA_def_property_ui_text(prop, "Use Material Caching", diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 4273c29aed8..3586393e738 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -1803,7 +1803,7 @@ static void rna_FileBrowser_FSMenu_active_range( static void rna_FileBrowser_FSMenu_active_update(struct bContext *C, PointerRNA *UNUSED(ptr)) { - ED_file_change_dir(C, true); + ED_file_change_dir(C); } static int rna_FileBrowser_FSMenuSystem_active_get(PointerRNA *ptr) diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 5a1607aa7c7..d8dcbf1afd0 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -94,6 +94,13 @@ EnumPropertyItem rna_enum_navigation_mode_items[] = { {0, NULL, 0, NULL, NULL} }; +#if defined(WITH_INTERNATIONAL) || !defined(RNA_RUNTIME) +static EnumPropertyItem rna_enum_language_default_items[] = { + {0, "DEFAULT", 0, "Default (Default)", ""}, + {0, NULL, 0, NULL, NULL} +}; +#endif + #ifdef RNA_RUNTIME #include "DNA_object_types.h" @@ -642,7 +649,11 @@ static EnumPropertyItem *rna_userdef_audio_device_itemf(bContext *UNUSED(C), Poi static EnumPropertyItem *rna_lang_enum_properties_itemf(bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *UNUSED(r_free)) { - return BLT_lang_RNA_enum_properties(); + EnumPropertyItem *items = BLT_lang_RNA_enum_properties(); + if (items == NULL) { + items = rna_enum_language_default_items; + } + return items; } #endif @@ -3971,11 +3982,6 @@ static void rna_def_userdef_system(BlenderRNA *brna) {USER_MULTISAMPLE_16, "16", 0, "MultiSample: 16", "Use 16x OpenGL MultiSample (requires restart)"}, {0, NULL, 0, NULL, NULL} }; - - static EnumPropertyItem language_items[] = { - {0, "DEFAULT", 0, "Default (Default)", ""}, - {0, NULL, 0, NULL, NULL} - }; #ifdef WITH_CYCLES static EnumPropertyItem compute_device_items[] = { @@ -4058,7 +4064,7 @@ static void rna_def_userdef_system(BlenderRNA *brna) /* Language Selection */ prop = RNA_def_property(srna, "language", PROP_ENUM, PROP_NONE); - RNA_def_property_enum_items(prop, language_items); + RNA_def_property_enum_items(prop, rna_enum_language_default_items); #ifdef WITH_INTERNATIONAL RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_lang_enum_properties_itemf"); #endif diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index 0d11414c878..026d2e209a3 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -469,13 +469,15 @@ EnumPropertyItem rna_enum_wm_report_items[] = { static wmOperator *rna_OperatorProperties_find_operator(PointerRNA *ptr) { wmWindowManager *wm = ptr->id.data; - IDProperty *properties = (IDProperty *)ptr->data; - wmOperator *op; - if (wm) - for (op = wm->operators.first; op; op = op->next) - if (op->properties == properties) + if (wm) { + IDProperty *properties = (IDProperty *)ptr->data; + for (wmOperator *op = wm->operators.last; op; op = op->prev) { + if (op->properties == properties) { return op; + } + } + } return NULL; } diff --git a/source/blender/makesrna/intern/rna_world.c b/source/blender/makesrna/intern/rna_world.c index f950ba75c42..7c1ef6b0d87 100644 --- a/source/blender/makesrna/intern/rna_world.c +++ b/source/blender/makesrna/intern/rna_world.c @@ -102,8 +102,7 @@ static void rna_World_draw_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Poi } #endif -/* so camera mist limits redraw */ -static void rna_World_draw_mist_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) +static void rna_World_draw_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { World *wo = ptr->id.data; @@ -264,19 +263,19 @@ static void rna_def_lighting(BlenderRNA *brna) prop = RNA_def_property(srna, "use_environment_light", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "mode", WO_ENV_LIGHT); RNA_def_property_ui_text(prop, "Use Environment Lighting", "Add light coming from the environment"); - RNA_def_property_update(prop, 0, "rna_World_update"); + RNA_def_property_update(prop, 0, "rna_World_draw_update"); prop = RNA_def_property(srna, "environment_energy", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "ao_env_energy"); RNA_def_property_ui_range(prop, 0, FLT_MAX, 1, 3); RNA_def_property_ui_text(prop, "Environment Color", "Defines the strength of environment light"); - RNA_def_property_update(prop, 0, "rna_World_update"); + RNA_def_property_update(prop, 0, "rna_World_draw_update"); prop = RNA_def_property(srna, "environment_color", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "aocolor"); RNA_def_property_enum_items(prop, prop_color_items); RNA_def_property_ui_text(prop, "Environment Color", "Defines where the color of the environment light comes from"); - RNA_def_property_update(prop, 0, "rna_World_update"); + RNA_def_property_update(prop, 0, "rna_World_draw_update"); /* indirect lighting */ prop = RNA_def_property(srna, "use_indirect_light", PROP_BOOLEAN, PROP_NONE); @@ -405,27 +404,27 @@ static void rna_def_world_mist(BlenderRNA *brna) prop = RNA_def_property(srna, "use_mist", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "mode", WO_MIST); RNA_def_property_ui_text(prop, "Use Mist", "Occlude objects with the environment color as they are further away"); - RNA_def_property_update(prop, 0, "rna_World_draw_mist_update"); + RNA_def_property_update(prop, 0, "rna_World_draw_update"); prop = RNA_def_property(srna, "intensity", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "misi"); RNA_def_property_range(prop, 0, 1); RNA_def_property_ui_text(prop, "Minimum", "Overall minimum intensity of the mist effect"); - RNA_def_property_update(prop, 0, "rna_World_draw_mist_update"); + RNA_def_property_update(prop, 0, "rna_World_draw_update"); prop = RNA_def_property(srna, "start", PROP_FLOAT, PROP_DISTANCE); RNA_def_property_float_sdna(prop, NULL, "miststa"); RNA_def_property_range(prop, 0, FLT_MAX); RNA_def_property_ui_range(prop, 0, 10000, 10, 2); RNA_def_property_ui_text(prop, "Start", "Starting distance of the mist, measured from the camera"); - RNA_def_property_update(prop, 0, "rna_World_draw_mist_update"); + RNA_def_property_update(prop, 0, "rna_World_draw_update"); prop = RNA_def_property(srna, "depth", PROP_FLOAT, PROP_DISTANCE); RNA_def_property_float_sdna(prop, NULL, "mistdist"); RNA_def_property_range(prop, 0, FLT_MAX); RNA_def_property_ui_range(prop, 0, 10000, 10, 2); RNA_def_property_ui_text(prop, "Depth", "Distance over which the mist effect fades in"); - RNA_def_property_update(prop, 0, "rna_World_draw_mist_update"); + RNA_def_property_update(prop, 0, "rna_World_draw_update"); prop = RNA_def_property(srna, "height", PROP_FLOAT, PROP_DISTANCE); RNA_def_property_float_sdna(prop, NULL, "misthi"); @@ -437,7 +436,7 @@ static void rna_def_world_mist(BlenderRNA *brna) RNA_def_property_enum_sdna(prop, NULL, "mistype"); RNA_def_property_enum_items(prop, falloff_items); RNA_def_property_ui_text(prop, "Falloff", "Type of transition used to fade mist"); - RNA_def_property_update(prop, 0, "rna_World_draw_mist_update"); + RNA_def_property_update(prop, 0, "rna_World_draw_update"); } void RNA_def_world(BlenderRNA *brna) @@ -462,19 +461,19 @@ void RNA_def_world(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Horizon Color", "Color at the horizon"); /* RNA_def_property_update(prop, 0, "rna_World_update"); */ /* render-only uses this */ - RNA_def_property_update(prop, 0, "rna_World_draw_mist_update"); + RNA_def_property_update(prop, 0, "rna_World_draw_update"); prop = RNA_def_property(srna, "zenith_color", PROP_FLOAT, PROP_COLOR); RNA_def_property_float_sdna(prop, NULL, "zenr"); RNA_def_property_array(prop, 3); RNA_def_property_ui_text(prop, "Zenith Color", "Color at the zenith"); - RNA_def_property_update(prop, NC_WORLD | ND_WORLD_DRAW, "rna_World_update"); + RNA_def_property_update(prop, 0, "rna_World_draw_update"); prop = RNA_def_property(srna, "ambient_color", PROP_FLOAT, PROP_COLOR); RNA_def_property_float_sdna(prop, NULL, "ambr"); RNA_def_property_array(prop, 3); RNA_def_property_ui_text(prop, "Ambient Color", "Ambient color of the world"); - RNA_def_property_update(prop, 0, "rna_World_draw_mist_update"); + RNA_def_property_update(prop, 0, "rna_World_draw_update"); /* exp, range */ prop = RNA_def_property(srna, "exposure", PROP_FLOAT, PROP_NONE); diff --git a/source/blender/modifiers/intern/MOD_boolean.c b/source/blender/modifiers/intern/MOD_boolean.c index 1fcf4c5ec79..3f418fa16f3 100644 --- a/source/blender/modifiers/intern/MOD_boolean.c +++ b/source/blender/modifiers/intern/MOD_boolean.c @@ -222,7 +222,7 @@ static DerivedMesh *applyModifier_bmesh( #ifdef DEBUG_TIME TIMEIT_START(boolean_bmesh); #endif - bm = BM_mesh_create(&allocsize); + bm = BM_mesh_create_ex(&allocsize, ); DM_to_bmesh_ex(dm_other, bm, true); DM_to_bmesh_ex(dm, bm, true); diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.c b/source/blender/modifiers/intern/MOD_correctivesmooth.c index 4046620592b..44515bfdf35 100644 --- a/source/blender/modifiers/intern/MOD_correctivesmooth.c +++ b/source/blender/modifiers/intern/MOD_correctivesmooth.c @@ -1,29 +1,29 @@ /* -* ***** BEGIN GPL LICENSE BLOCK ***** -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software Foundation, -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -* -* The Original Code is Copyright (C) 2015 by the Blender Foundation. -* All rights reserved. -* -* Contributor(s): Jack Simpson, -* Campbell Barton -* -* ***** END GPL LICENSE BLOCK ***** -* -*/ + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 by the Blender Foundation. + * All rights reserved. + * + * Contributor(s): Jack Simpson, + * Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + * + */ /** \file blender/modifiers/intern/MOD_correctivesmooth.c * \ingroup modifiers diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.c index 9f1ec4de3d5..8ed623734be 100644 --- a/source/blender/modifiers/intern/MOD_skin.c +++ b/source/blender/modifiers/intern/MOD_skin.c @@ -1745,7 +1745,9 @@ static BMesh *build_skin(SkinNode *skin_nodes, int v; so.smd = smd; - so.bm = BM_mesh_create(&bm_mesh_allocsize_default); + so.bm = BM_mesh_create( + &bm_mesh_allocsize_default, + &((struct BMeshCreateParams){.use_toolflags = true,})); so.mat_nr = 0; /* BMESH_TODO: bumping up the stack level (see MOD_array.c) */ diff --git a/source/blender/modifiers/intern/MOD_wireframe.c b/source/blender/modifiers/intern/MOD_wireframe.c index fe21757d5c2..adadd4834d4 100644 --- a/source/blender/modifiers/intern/MOD_wireframe.c +++ b/source/blender/modifiers/intern/MOD_wireframe.c @@ -1,23 +1,23 @@ /* -* ***** BEGIN GPL LICENSE BLOCK ***** -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software Foundation, -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -* -* ***** END GPL LICENSE BLOCK ***** -* -*/ + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + * + */ /** \file blender/modifiers/intern/MOD_wireframe.c * \ingroup modifiers diff --git a/source/blender/nodes/shader/nodes/node_shader_brightness.c b/source/blender/nodes/shader/nodes/node_shader_brightness.c index 8c873b57790..e992c0773c2 100644 --- a/source/blender/nodes/shader/nodes/node_shader_brightness.c +++ b/source/blender/nodes/shader/nodes/node_shader_brightness.c @@ -23,8 +23,7 @@ * Contributor(s): none yet. * * ***** END GPL LICENSE BLOCK ***** - -*/ + */ #include "node_shader_util.h" diff --git a/source/blender/nodes/shader/nodes/node_shader_gamma.c b/source/blender/nodes/shader/nodes/node_shader_gamma.c index 0264abe451f..37439569f77 100644 --- a/source/blender/nodes/shader/nodes/node_shader_gamma.c +++ b/source/blender/nodes/shader/nodes/node_shader_gamma.c @@ -23,8 +23,7 @@ * Contributor(s): none yet. * * ***** END GPL LICENSE BLOCK ***** - -*/ + */ #include "node_shader_util.h" diff --git a/source/blender/nodes/shader/nodes/node_shader_texture.c b/source/blender/nodes/shader/nodes/node_shader_texture.c index 6edf6c2a0b4..b0b25a4878b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_texture.c +++ b/source/blender/nodes/shader/nodes/node_shader_texture.c @@ -33,6 +33,8 @@ #include "node_shader_util.h" +#include "GPU_material.h" + /* **************** TEXTURE ******************** */ static bNodeSocketTemplate sh_node_texture_in[] = { { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, /* no limit */ @@ -121,9 +123,20 @@ static int gpu_shader_texture(GPUMaterial *mat, bNode *node, bNodeExecData *UNUS { Tex *tex = (Tex *)node->id; - if (tex && tex->type == TEX_IMAGE && tex->ima) { - GPUNodeLink *texlink = GPU_image(tex->ima, &tex->iuser, false); - GPU_stack_link(mat, "texture_image", in, out, texlink); + if (tex && tex->ima && (tex->type == TEX_IMAGE || tex->type == TEX_ENVMAP)) { + if (tex->type == TEX_IMAGE) { + GPUNodeLink *texlink = GPU_image(tex->ima, &tex->iuser, false); + GPU_stack_link(mat, "texture_image", in, out, texlink); + } + else { /* TEX_ENVMAP */ + if (!in[0].link) + in[0].link = GPU_uniform(in[0].vec); + if (!GPU_material_use_world_space_shading(mat)) + GPU_link(mat, "direction_transform_m4v3", in[0].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &in[0].link); + GPU_link(mat, "mtex_cube_map_refl_from_refldir", + GPU_cube_map(tex->ima, &tex->iuser, false), in[0].link, &out[0].link, &out[1].link); + GPU_link(mat, "color_to_normal", out[1].link, &out[2].link); + } ImBuf *ibuf = BKE_image_acquire_ibuf(tex->ima, &tex->iuser, NULL); if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 && diff --git a/source/blender/python/bmesh/bmesh_py_api.c b/source/blender/python/bmesh/bmesh_py_api.c index 7c5d1961849..eb1594688c7 100644 --- a/source/blender/python/bmesh/bmesh_py_api.c +++ b/source/blender/python/bmesh/bmesh_py_api.c @@ -53,17 +53,31 @@ #include "bmesh_py_api.h" /* own include */ PyDoc_STRVAR(bpy_bm_new_doc, -".. method:: new()\n" +".. method:: new(use_operators=True)\n" "\n" +" :arg use_operators: Support calling operators in :mod:`bmesh.ops` (uses some extra memory per vert/edge/face).\n" +" :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n" ); -static PyObject *bpy_bm_new(PyObject *UNUSED(self)) +static PyObject *bpy_bm_new(PyObject *UNUSED(self), PyObject *args, PyObject *kw) { + static const char *kwlist[] = {"use_operators", NULL}; BMesh *bm; - bm = BM_mesh_create(&bm_mesh_allocsize_default); + bool use_operators = true; + + if (!PyArg_ParseTupleAndKeywords( + args, kw, "|$O&:new", (char **)kwlist, + PyC_ParseBool, &use_operators)) + { + return NULL; + } + + bm = BM_mesh_create( + &bm_mesh_allocsize_default, + &((struct BMeshCreateParams){.use_toolflags = use_operators,})); return BPy_BMesh_CreatePyObject(bm, BPY_BMFLAG_NOP); } @@ -155,7 +169,7 @@ static PyObject *bpy_bm_update_edit_mesh(PyObject *UNUSED(self), PyObject *args, } static struct PyMethodDef BPy_BM_methods[] = { - {"new", (PyCFunction)bpy_bm_new, METH_NOARGS, bpy_bm_new_doc}, + {"new", (PyCFunction)bpy_bm_new, METH_VARARGS | METH_KEYWORDS, bpy_bm_new_doc}, {"from_edit_mesh", (PyCFunction)bpy_bm_from_edit_mesh, METH_O, bpy_bm_from_edit_mesh_doc}, {"update_edit_mesh", (PyCFunction)bpy_bm_update_edit_mesh, METH_VARARGS | METH_KEYWORDS, bpy_bm_update_edit_mesh_doc}, {NULL, NULL, 0, NULL} diff --git a/source/blender/python/bmesh/bmesh_py_ops_call.c b/source/blender/python/bmesh/bmesh_py_ops_call.c index 1dc70c3d288..551a66d1ed8 100644 --- a/source/blender/python/bmesh/bmesh_py_ops_call.c +++ b/source/blender/python/bmesh/bmesh_py_ops_call.c @@ -698,6 +698,12 @@ PyObject *BPy_BMO_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject *kw) BPY_BM_CHECK_OBJ(py_bm); bm = py_bm->bm; + if (bm->use_toolflags == false) { + PyErr_SetString(PyExc_ValueError, + "bmesh created with 'use_operators=False'"); + return NULL; + } + /* could complain about entering with exceptions... */ BMO_error_clear(bm); } diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c index 4bd2e9d8d62..3ea10228ad4 100644 --- a/source/blender/python/generic/bgl.c +++ b/source/blender/python/generic/bgl.c @@ -983,7 +983,7 @@ static PyObject *Buffer_repr(Buffer *self) switch (self->type) { case GL_BYTE: typestr = "GL_BYTE"; break; case GL_SHORT: typestr = "GL_SHORT"; break; - case GL_INT: typestr = "GL_BYTE"; break; + case GL_INT: typestr = "GL_INT"; break; case GL_FLOAT: typestr = "GL_FLOAT"; break; case GL_DOUBLE: typestr = "GL_DOUBLE"; break; default: typestr = "UNKNOWN"; break; diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 11af0836e1c..311f621e13b 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -901,8 +901,8 @@ static void bpy_module_free(void *UNUSED(mod)) bool BPY_string_is_keyword(const char *str) { /* list is from... - * ", ".join(['"%s"' % kw for kw in __import__("keyword").kwlist]) - */ + * ", ".join(['"%s"' % kw for kw in __import__("keyword").kwlist]) + */ const char *kwlist[] = { "False", "None", "True", "and", "as", "assert", "break", diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index 9948ac99814..907974e20dc 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -3172,9 +3172,8 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) /* exception for tangent space baking */ if (me->mtpoly==NULL) { need_orco= 1; - need_tangent= 1; } - need_nmap_tangent_concrete = true; + need_tangent= 1; } /* check autosmooth and displacement, we then have to skip only-verts optimize diff --git a/source/blender/render/intern/source/envmap.c b/source/blender/render/intern/source/envmap.c index b1afb86e5af..d97e18d6511 100644 --- a/source/blender/render/intern/source/envmap.c +++ b/source/blender/render/intern/source/envmap.c @@ -52,6 +52,7 @@ #include "BKE_main.h" #include "BKE_image.h" /* BKE_imbuf_write */ #include "BKE_texture.h" +#include "BKE_scene.h" /* this module */ #include "render_types.h" @@ -737,21 +738,28 @@ int envmaptex(Tex *tex, const float texvec[3], float dxt[3], float dyt[3], int o /* rotate to envmap space, if object is set */ copy_v3_v3(vec, texvec); - if (env->object) mul_m3_v3(env->obimat, vec); - else mul_mat3_m4_v3(R.viewinv, vec); + if (env->object) { + mul_m3_v3(env->obimat, vec); + if (osatex) { + mul_m3_v3(env->obimat, dxt); + mul_m3_v3(env->obimat, dyt); + } + } + else { + if (!BKE_scene_use_world_space_shading(R.scene)) { + // texvec is in view space + mul_mat3_m4_v3(R.viewinv, vec); + if (osatex) { + mul_mat3_m4_v3(R.viewinv, dxt); + mul_mat3_m4_v3(R.viewinv, dyt); + } + } + } face = envcube_isect(env, vec, sco); ibuf = env->cube[face]; if (osatex) { - if (env->object) { - mul_m3_v3(env->obimat, dxt); - mul_m3_v3(env->obimat, dyt); - } - else { - mul_mat3_m4_v3(R.viewinv, dxt); - mul_mat3_m4_v3(R.viewinv, dyt); - } set_dxtdyt(dxts, dyts, dxt, dyt, face); imagewraposa(tex, NULL, ibuf, sco, dxts, dyts, texres, pool, skip_load_image); diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 4d711f86644..7af63051dfe 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -2178,12 +2178,12 @@ static void init_freestyle(Render *re) re->freestyle_bmain = BKE_main_new(); /* We use the same window manager for freestyle bmain as - * real bmain uses. This is needed because freestyle's - * bmain could be used to tag scenes for update, which - * implies call of ED_render_scene_update in some cases - * and that function requires proper window manager - * to present (sergey) - */ + * real bmain uses. This is needed because freestyle's + * bmain could be used to tag scenes for update, which + * implies call of ED_render_scene_update in some cases + * and that function requires proper window manager + * to present (sergey) + */ re->freestyle_bmain->wm = re->main->wm; FRS_init_stroke_renderer(re); @@ -2268,7 +2268,7 @@ static void free_all_freestyle_renders(void) if (freestyle_render) { freestyle_scene = freestyle_render->scene; RE_FreeRender(freestyle_render); - BKE_libblock_unlink(re1->freestyle_bmain, freestyle_scene, false); + BKE_libblock_unlink(re1->freestyle_bmain, freestyle_scene, false, false); BKE_libblock_free(re1->freestyle_bmain, freestyle_scene); } } diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c index 530ebc084be..dc22859bdc1 100644 --- a/source/blender/render/intern/source/render_texture.c +++ b/source/blender/render/intern/source/render_texture.c @@ -1720,6 +1720,21 @@ static void texco_mapping(ShadeInput *shi, Tex *tex, MTex *mtex, } else dxt[2]= dyt[2] = 0.f; } + + if (mtex->tex->type == TEX_ENVMAP) { + EnvMap *env = tex->env; + if (!env->object) { + // env->object is a view point for envmap rendering + // if it's not set, return the result depending on the world_space_shading flag + if (BKE_scene_use_world_space_shading(R.scene)) { + mul_mat3_m4_v3(R.viewinv, texvec); + if (shi->osatex) { + mul_mat3_m4_v3(R.viewinv, dxt); + mul_mat3_m4_v3(R.viewinv, dyt); + } + } + } + } } } diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c index 3709e10b366..12ad8f91064 100644 --- a/source/blender/windowmanager/intern/wm_files_link.c +++ b/source/blender/windowmanager/intern/wm_files_link.c @@ -264,7 +264,7 @@ static void wm_link_do( mainl, &bh, item->idcode, item->name, flag, scene, v3d, use_placeholders, force_indirect); if (new_id) { - /* If the link is sucessful, clear item's libs 'todo' flags. + /* If the link is successful, clear item's libs 'todo' flags. * This avoids trying to link same item with other libraries to come. */ BLI_BITMAP_SET_ALL(item->libraries, false, lapp_data->num_libraries); item->new_id = new_id; diff --git a/source/blenderplayer/bad_level_call_stubs/stubs.c b/source/blenderplayer/bad_level_call_stubs/stubs.c index f3111b3adb1..7c7958a4acd 100644 --- a/source/blenderplayer/bad_level_call_stubs/stubs.c +++ b/source/blenderplayer/bad_level_call_stubs/stubs.c @@ -378,7 +378,7 @@ void ED_area_tag_redraw_regiontype(struct ScrArea *sa, int regiontype) RET_NONE void ED_render_engine_changed(struct Main *bmain) RET_NONE void ED_file_read_bookmarks(void) RET_NONE -void ED_file_change_dir(struct bContext *C, const bool checkdir) RET_NONE +void ED_file_change_dir(struct bContext *C) RET_NONE void ED_preview_kill_jobs(struct wmWindowManager *wm, struct Main *bmain) RET_NONE struct FSMenu *ED_fsmenu_get(void) RET_NULL struct FSMenuEntry *ED_fsmenu_get_category(struct FSMenu *fsmenu, FSMenuCategory category) RET_NULL @@ -524,7 +524,7 @@ SnapObjectContext *ED_transform_snap_object_context_create( struct Main *bmain, struct Scene *scene, int flag) RET_NULL SnapObjectContext *ED_transform_snap_object_context_create_view3d( struct Main *bmain, struct Scene *scene, int flag, - struct ARegion *ar, struct View3D *v3d) RET_NULL + const struct ARegion *ar, const struct View3D *v3d) RET_NULL void ED_transform_snap_object_context_destroy(SnapObjectContext *sctx) RET_NONE bool ED_transform_snap_object_project_ray_ex( struct SnapObjectContext *sctx, diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 91d03da005e..4e8dd6f9fd3 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -172,18 +172,28 @@ if(WITH_BUILDINFO) include_directories(${CMAKE_CURRENT_BINARY_DIR}) - # XXX, "_buildinfo.h" is used twice here, + # XXX, ${buildinfo_h_fake} is used here, # because we rely on that file being detected as missing # every build so that the real header "buildinfo.h" is updated. # # Keep this until we find a better way to resolve! + set(buildinfo_h_real "${CMAKE_CURRENT_BINARY_DIR}/buildinfo.h") + set(buildinfo_h_fake "${CMAKE_CURRENT_BINARY_DIR}/buildinfo.h_fake") + + if(EXISTS ${buildinfo_h_fake}) + message(FATAL_ERROR "File \"${buildinfo_h_fake}\" found, this should never be created, remove!") + endif() + # a custom target that is always built add_custom_target(buildinfo ALL - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_buildinfo.h) + DEPENDS ${buildinfo_h_fake}) # creates buildinfo.h using cmake script - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_buildinfo.h + add_custom_command( + OUTPUT + ${buildinfo_h_fake} # ensure we always run + ${buildinfo_h_real} COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_SOURCE_DIR} # overrides only used when non-empty strings @@ -192,10 +202,14 @@ if(WITH_BUILDINFO) -P ${CMAKE_SOURCE_DIR}/build_files/cmake/buildinfo.cmake) # buildinfo.h is a generated file - set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/buildinfo.h + set_source_files_properties( + ${buildinfo_h_real} PROPERTIES GENERATED TRUE HEADER_FILE_ONLY TRUE) + unset(buildinfo_h_real) + unset(buildinfo_h_fake) + # add deps below, after adding blender # -------------- done with header values. diff --git a/source/gameengine/Expressions/intern/IntValue.cpp b/source/gameengine/Expressions/intern/IntValue.cpp index 25aff5b32ab..7b2e841f13f 100644 --- a/source/gameengine/Expressions/intern/IntValue.cpp +++ b/source/gameengine/Expressions/intern/IntValue.cpp @@ -3,17 +3,17 @@ */ // IntValue.cpp: implementation of the CIntValue class. /* -* Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> -* -* Permission to use, copy, modify, distribute and sell this software -* and its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and -* that both that copyright notice and this permission notice appear -* in supporting documentation. Erwin Coumans makes no -* representations about the suitability of this software for any -* purpose. It is provided "as is" without express or implied warranty. -* -*/ + * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Erwin Coumans makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ #include <stdio.h> diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index 1b52c61b816..e697306e038 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -633,7 +633,9 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode) if (!m_rasterizer) goto initFailed; - + + m_rasterizer->PrintHardwareInfo(); + // create the inputdevices m_keyboard = new GPG_KeyboardDevice(); if (!m_keyboard) diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index 0ea3a3e62eb..9c3f94f1918 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -46,8 +46,8 @@ #include "KX_PyConstraintBinding.h" // for PHY_SetActiveEnvironment /********************************** -* Begin Blender include block -**********************************/ + * Begin Blender include block + **********************************/ #ifdef __cplusplus extern "C" { @@ -103,8 +103,8 @@ extern char datatoc_bmonofont_ttf[]; #include "GPU_draw.h" /********************************** -* End Blender include block -**********************************/ + * End Blender include block + **********************************/ #include "BL_System.h" #include "GPG_Application.h" @@ -463,8 +463,8 @@ int main( /* Win32 Unicode Args */ /* NOTE: cannot use guardedalloc malloc here, as it's not yet initialized - * (it depends on the args passed in, which is what we're getting here!) - */ + * (it depends on the args passed in, which is what we're getting here!) + */ { wchar_t **argv_16 = CommandLineToArgvW(GetCommandLineW(), &argc); argv = (char**)malloc(argc * sizeof(char *)); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h index 7138409a7e8..831e7346df7 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h @@ -542,14 +542,14 @@ protected: CcdPhysicsController (const CcdConstructionInfo& ci); /** - * Delete the current Bullet shape used in the rigid body. - */ + * Delete the current Bullet shape used in the rigid body. + */ bool DeleteControllerShape(); /** - * Delete the old Bullet shape and set the new Bullet shape : newShape - * \param newShape The new Bullet shape to set, if is NULL we create a new Bullet shape - */ + * Delete the old Bullet shape and set the new Bullet shape : newShape + * \param newShape The new Bullet shape to set, if is NULL we create a new Bullet shape + */ bool ReplaceControllerShape(btCollisionShape *newShape); virtual ~CcdPhysicsController(); diff --git a/source/gameengine/Rasterizer/RAS_IOffScreen.h b/source/gameengine/Rasterizer/RAS_IOffScreen.h index e5f3dc43e5f..d61a31504b8 100644 --- a/source/gameengine/Rasterizer/RAS_IOffScreen.h +++ b/source/gameengine/Rasterizer/RAS_IOffScreen.h @@ -15,12 +15,12 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -* The Original Code is Copyright (C) 2015, Blender Foundation -* All rights reserved. -* -* The Original Code is: all of this file. -* -* Contributor(s): Blender Foundation. + * The Original Code is Copyright (C) 2015, Blender Foundation + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Blender Foundation. * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/gameengine/Rasterizer/RAS_ISync.h b/source/gameengine/Rasterizer/RAS_ISync.h index b9987dc1cad..7e34172c2a3 100644 --- a/source/gameengine/Rasterizer/RAS_ISync.h +++ b/source/gameengine/Rasterizer/RAS_ISync.h @@ -15,12 +15,12 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -* The Original Code is Copyright (C) 2015, Blender Foundation -* All rights reserved. -* -* The Original Code is: all of this file. -* -* Contributor(s): Blender Foundation. + * The Original Code is Copyright (C) 2015, Blender Foundation + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Blender Foundation. * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.cpp index 26ece47d8b3..e589bffcaf1 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.cpp @@ -15,12 +15,12 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -* The Original Code is Copyright (C) 2015, Blender Foundation -* All rights reserved. -* -* The Original Code is: all of this file. -* -* Contributor(s): Blender Foundation. + * The Original Code is Copyright (C) 2015, Blender Foundation + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Blender Foundation. * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.h index 94d0d4aa105..3f6845f1e21 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.h @@ -15,12 +15,12 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -* The Original Code is Copyright (C) 2015, Blender Foundation -* All rights reserved. -* -* The Original Code is: all of this file. -* -* Contributor(s): Blender Foundation. + * The Original Code is Copyright (C) 2015, Blender Foundation + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Blender Foundation. * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index fcb11ce2355..3f82c513f7d 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -141,8 +141,6 @@ RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas, RAS_STORAGE_TYPE glGetIntegerv(GL_MAX_LIGHTS, (GLint *) &m_numgllights); if (m_numgllights < 8) m_numgllights = 8; - - PrintHardwareInfo(); } diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLSync.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLSync.cpp index ebb4a9a3ca1..d54b3232067 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLSync.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLSync.cpp @@ -15,12 +15,12 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -* The Original Code is Copyright (C) 2015, Blender Foundation -* All rights reserved. -* -* The Original Code is: all of this file. -* -* Contributor(s): Blender Foundation. + * The Original Code is Copyright (C) 2015, Blender Foundation + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Blender Foundation. * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLSync.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLSync.h index 9b6340b04ac..4ba96903856 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLSync.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLSync.h @@ -15,12 +15,12 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -* The Original Code is Copyright (C) 2015, Blender Foundation -* All rights reserved. -* -* The Original Code is: all of this file. -* -* Contributor(s): Blender Foundation. + * The Original Code is Copyright (C) 2015, Blender Foundation + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Blender Foundation. * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/gameengine/VideoTexture/DeckLink.cpp b/source/gameengine/VideoTexture/DeckLink.cpp index 0506756ef2d..fa8ab8c641c 100644 --- a/source/gameengine/VideoTexture/DeckLink.cpp +++ b/source/gameengine/VideoTexture/DeckLink.cpp @@ -15,12 +15,12 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -* The Original Code is Copyright (C) 2015, Blender Foundation -* All rights reserved. -* -* The Original Code is: all of this file. -* -* Contributor(s): Blender Foundation. + * The Original Code is Copyright (C) 2015, Blender Foundation + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Blender Foundation. * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/gameengine/VideoTexture/DeckLink.h b/source/gameengine/VideoTexture/DeckLink.h index 1c96af7b4bc..4528fe7cec0 100644 --- a/source/gameengine/VideoTexture/DeckLink.h +++ b/source/gameengine/VideoTexture/DeckLink.h @@ -15,12 +15,12 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -* The Original Code is Copyright (C) 2015, Blender Foundation -* All rights reserved. -* -* The Original Code is: all of this file. -* -* Contributor(s): Blender Foundation. + * The Original Code is Copyright (C) 2015, Blender Foundation + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Blender Foundation. * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/gameengine/VideoTexture/VideoDeckLink.cpp b/source/gameengine/VideoTexture/VideoDeckLink.cpp index c8d3c28c551..4f5e34896fc 100644 --- a/source/gameengine/VideoTexture/VideoDeckLink.cpp +++ b/source/gameengine/VideoTexture/VideoDeckLink.cpp @@ -15,12 +15,12 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -* The Original Code is Copyright (C) 2015, Blender Foundation -* All rights reserved. -* -* The Original Code is: all of this file. -* -* Contributor(s): Blender Foundation. + * The Original Code is Copyright (C) 2015, Blender Foundation + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Blender Foundation. * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/gameengine/VideoTexture/VideoDeckLink.h b/source/gameengine/VideoTexture/VideoDeckLink.h index be81f63d93c..50099d2ead4 100644 --- a/source/gameengine/VideoTexture/VideoDeckLink.h +++ b/source/gameengine/VideoTexture/VideoDeckLink.h @@ -15,12 +15,12 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -* The Original Code is Copyright (C) 2015, Blender Foundation -* All rights reserved. -* -* The Original Code is: all of this file. -* -* Contributor(s): Blender Foundation. + * The Original Code is Copyright (C) 2015, Blender Foundation + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Blender Foundation. * * ***** END GPL LICENSE BLOCK ***** */ |