diff options
Diffstat (limited to 'source/blender/blenkernel')
66 files changed, 905 insertions, 532 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index e918f158682..79b0e5eb95f 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -531,18 +531,6 @@ DMCoNo *mesh_get_mapped_verts_nors(struct Scene *scene, struct Object *ob); void mesh_get_mapped_verts_coords(DerivedMesh *dm, float (*r_cos)[3], const int totcos); /* */ -DerivedMesh *mesh_get_derived_final( - struct Depsgraph *depsgraph, struct Scene *scene, - struct Object *ob, CustomDataMask dataMask); -struct Mesh *mesh_get_eval_final( - struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, CustomDataMask dataMask); - -DerivedMesh *mesh_get_derived_deform( - struct Depsgraph *depsgraph, struct Scene *scene, - struct Object *ob, CustomDataMask dataMask); -struct Mesh *mesh_get_eval_deform( - struct Depsgraph *depsgraph, struct Scene *scene, - struct Object *ob, CustomDataMask dataMask); DerivedMesh *mesh_create_derived_for_modifier( struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h index 701be9d44cc..2f7d0eaba03 100644 --- a/source/blender/blenkernel/BKE_anim.h +++ b/source/blender/blenkernel/BKE_anim.h @@ -32,16 +32,17 @@ * \author nzc * \since March 2001 */ -struct Depsgraph; -struct Path; -struct Object; -struct Scene; -struct ListBase; struct bAnimVizSettings; struct bMotionPath; struct bPoseChannel; -struct ReportList; +struct Depsgraph; +struct ListBase; struct Main; +struct Object; +struct ParticleSystem; +struct Path; +struct ReportList; +struct Scene; /* ---------------------------------------------------- */ /* Animation Visualization */ @@ -68,7 +69,6 @@ int where_on_path(struct Object *ob, float ctime, float vec[4], float dir[3], fl /* ---------------------------------------------------- */ /* Dupli-Geometry */ -struct ListBase *object_duplilist_ex(struct Depsgraph *depsgraph, struct Scene *sce, struct Object *ob, bool update); struct ListBase *object_duplilist(struct Depsgraph *depsgraph, struct Scene *sce, struct Object *ob); void free_object_duplilist(struct ListBase *lb); int count_duplilist(struct Object *ob); @@ -83,6 +83,26 @@ typedef struct DupliApplyData { DupliExtraData *extra; } DupliApplyData; +typedef struct DupliObject { + struct DupliObject *next, *prev; + struct Object *ob; + float mat[4][4]; + float orco[3], uv[2]; + + short type; /* from Object.transflag */ + char no_draw; + + /* Persistent identifier for a dupli object, for inter-frame matching of + * objects with motion blur, or inter-update matching for syncing. */ + int persistent_id[16]; /* 2*MAX_DUPLI_RECUR */ + + /* Particle this dupli was generated from. */ + struct ParticleSystem *particle_system; + + /* Random ID for shading */ + unsigned int random_id; +} DupliObject; + DupliApplyData *duplilist_apply(struct Depsgraph *depsgraph, struct Object *ob, struct Scene *scene, struct ListBase *duplilist); void duplilist_restore(struct ListBase *duplilist, DupliApplyData *apply_data); void duplilist_free_apply_data(DupliApplyData *apply_data); diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h index 8befeff498e..a1212322983 100644 --- a/source/blender/blenkernel/BKE_blender_version.h +++ b/source/blender/blenkernel/BKE_blender_version.h @@ -28,7 +28,7 @@ * and keep comment above the defines. * Use STRINGIFY() rather than defining with quotes */ #define BLENDER_VERSION 280 -#define BLENDER_SUBVERSION 16 +#define BLENDER_SUBVERSION 17 /* Several breakages with 270, e.g. constraint deg vs rad */ #define BLENDER_MINVERSION 270 #define BLENDER_MINSUBVERSION 6 diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h index edc24d9649e..fc5b19ccb4f 100644 --- a/source/blender/blenkernel/BKE_collection.h +++ b/source/blender/blenkernel/BKE_collection.h @@ -91,7 +91,6 @@ bool BKE_collection_is_in_scene(struct Collection *collection); void BKE_collections_after_lib_link(struct Main *bmain); bool BKE_collection_object_cyclic_check(struct Main *bmain, struct Object *object, struct Collection *collection); bool BKE_collection_is_animated(struct Collection *collection, struct Object *parent); -void BKE_collection_handle_recalc_and_update(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *parent, struct Collection *collection); /* Object list cache. */ diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index 0f05170b47c..28bc254f25a 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -182,6 +182,9 @@ struct BlendThumbnail *BKE_main_thumbnail_from_imbuf(struct Main *bmain, struct struct ImBuf *BKE_main_thumbnail_to_imbuf(struct Main *bmain, struct BlendThumbnail *data); void BKE_main_thumbnail_create(struct Main *bmain); +const char *BKE_main_blendfile_path(const struct Main *bmain) ATTR_NONNULL(); +const char *BKE_main_blendfile_path_from_global(void); + void BKE_main_id_tag_idcode(struct Main *mainvar, const short type, const int tag, const bool value); void BKE_main_id_tag_listbase(struct ListBase *lb, const int tag, const bool value); void BKE_main_id_tag_all(struct Main *mainvar, const int tag, const bool value); diff --git a/source/blender/blenkernel/BKE_mball.h b/source/blender/blenkernel/BKE_mball.h index 41f04c09e69..74ef9d9dbc0 100644 --- a/source/blender/blenkernel/BKE_mball.h +++ b/source/blender/blenkernel/BKE_mball.h @@ -76,8 +76,6 @@ void BKE_mball_select_swap(struct MetaBall *mb); struct Depsgraph; -void BKE_mball_eval_geometry(struct Depsgraph *depsgraph, - struct MetaBall *mball); /* Draw Cache */ enum { diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index efbc00c456f..cb58deb9511 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -178,9 +178,9 @@ struct Mesh *BKE_mesh_create_derived_for_modifier( struct ModifierData *md, int build_shapekey_layers); /* Copies a nomain-Mesh into an existing Mesh. */ -void BKE_nomain_mesh_to_mesh(struct Mesh *mesh_src, struct Mesh *mesh_dst, struct Object *ob, +void BKE_mesh_nomain_to_mesh(struct Mesh *mesh_src, struct Mesh *mesh_dst, struct Object *ob, CustomDataMask mask, bool take_ownership); -void BKE_nomain_mesh_to_meshkey(struct Mesh *mesh_src, struct Mesh *mesh_dst, struct KeyBlock *kb); +void BKE_mesh_nomain_to_meshkey(struct Mesh *mesh_src, struct Mesh *mesh_dst, struct KeyBlock *kb); /* vertex level transformations & checks (no derived mesh) */ @@ -206,23 +206,10 @@ void BKE_mesh_mselect_active_set(struct Mesh *me, int index, int type); void BKE_mesh_apply_vert_coords(struct Mesh *mesh, float (*vertCoords)[3]); -/* *** mesh_runtime.c *** */ -void BKE_mesh_runtime_reset(struct Mesh *mesh); -int BKE_mesh_runtime_looptri_len(const struct Mesh *mesh); -void BKE_mesh_runtime_looptri_recalc(struct Mesh *mesh); -const struct MLoopTri *BKE_mesh_runtime_looptri_ensure(struct Mesh *mesh); -bool BKE_mesh_runtime_ensure_edit_data(struct Mesh *mesh); -bool BKE_mesh_runtime_clear_edit_data(struct Mesh *mesh); -void BKE_mesh_runtime_clear_geometry(struct Mesh *mesh); -void BKE_mesh_runtime_clear_cache(struct Mesh *mesh); - -void BKE_mesh_runtime_verttri_from_looptri( - struct MVertTri *r_verttri, - const struct MLoop *mloop, const struct MLoopTri *looptri, int looptri_num); - /* *** mesh_evaluate.c *** */ +void BKE_mesh_calc_normals_mapping_simple(struct Mesh *me); void BKE_mesh_calc_normals_mapping( struct MVert *mverts, int numVerts, const struct MLoop *mloop, const struct MPoly *mpolys, int numLoops, int numPolys, float (*r_polyNors)[3], diff --git a/source/blender/blenkernel/BKE_mesh_runtime.h b/source/blender/blenkernel/BKE_mesh_runtime.h new file mode 100644 index 00000000000..6904ad529de --- /dev/null +++ b/source/blender/blenkernel/BKE_mesh_runtime.h @@ -0,0 +1,85 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ +#ifndef __BKE_MESH_RUNTIME_H__ +#define __BKE_MESH_RUNTIME_H__ + +/** \file BKE_mesh_runtime.h + * \ingroup bke + * + * This file contains access functions for the Mesh.runtime struct. + */ + +#include "BKE_customdata.h" /* for CustomDataMask */ + +struct Depsgraph; +struct Mesh; +struct MLoop; +struct MLoopTri; +struct MVertTri; +struct Object; +struct Scene; + +/* Undefine to hide DerivedMesh-based function declarations */ +#define USE_DERIVEDMESH + +#ifdef USE_DERIVEDMESH +struct DerivedMesh; +#endif + +void BKE_mesh_runtime_reset(struct Mesh *mesh); +int BKE_mesh_runtime_looptri_len(const struct Mesh *mesh); +void BKE_mesh_runtime_looptri_recalc(struct Mesh *mesh); +const struct MLoopTri *BKE_mesh_runtime_looptri_ensure(struct Mesh *mesh); +bool BKE_mesh_runtime_ensure_edit_data(struct Mesh *mesh); +bool BKE_mesh_runtime_clear_edit_data(struct Mesh *mesh); +void BKE_mesh_runtime_clear_geometry(struct Mesh *mesh); +void BKE_mesh_runtime_clear_cache(struct Mesh *mesh); + +void BKE_mesh_runtime_verttri_from_looptri( + struct MVertTri *r_verttri, + const struct MLoop *mloop, const struct MLoopTri *looptri, int looptri_num); + +/* NOTE: the functions below are defined in DerivedMesh.c, and are intended to be moved + * to a more suitable location when that file is removed. */ +#ifdef USE_DERIVEDMESH +struct DerivedMesh *mesh_get_derived_final( + struct Depsgraph *depsgraph, struct Scene *scene, + struct Object *ob, CustomDataMask dataMask); +#endif +struct Mesh *mesh_get_eval_final( + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, CustomDataMask dataMask); + +#ifdef USE_DERIVEDMESH +struct DerivedMesh *mesh_get_derived_deform( + struct Depsgraph *depsgraph, struct Scene *scene, + struct Object *ob, CustomDataMask dataMask); +#endif +struct Mesh *mesh_get_eval_deform( + struct Depsgraph *depsgraph, struct Scene *scene, + struct Object *ob, CustomDataMask dataMask); + +#endif /* __BKE_MESH_RUNTIME_H__ */ diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h index b5d3e67b970..b40d32203f6 100644 --- a/source/blender/blenkernel/BKE_modifier.h +++ b/source/blender/blenkernel/BKE_modifier.h @@ -468,7 +468,7 @@ void modifier_mdef_compact_influences(struct ModifierData *md); void modifier_path_init(char *path, int path_maxlen, const char *name); const char *modifier_path_relbase(struct Main *bmain, struct Object *ob); - +const char *modifier_path_relbase_from_global(struct Object *ob); /* wrappers for modifier callbacks that ensure valid normals */ diff --git a/source/blender/blenkernel/BKE_movieclip.h b/source/blender/blenkernel/BKE_movieclip.h index 5b5ebbf035c..014ea2b9159 100644 --- a/source/blender/blenkernel/BKE_movieclip.h +++ b/source/blender/blenkernel/BKE_movieclip.h @@ -49,7 +49,7 @@ void BKE_movieclip_make_local(struct Main *bmain, struct MovieClip *clip, const struct MovieClip *BKE_movieclip_file_add(struct Main *bmain, const char *name); struct MovieClip *BKE_movieclip_file_add_exists_ex(struct Main *bmain, const char *name, bool *r_exists); struct MovieClip *BKE_movieclip_file_add_exists(struct Main *bmain, const char *name); -void BKE_movieclip_reload(struct MovieClip *clip); +void BKE_movieclip_reload(struct Main *bmain, struct MovieClip *clip); void BKE_movieclip_clear_cache(struct MovieClip *clip); void BKE_movieclip_clear_proxy_cache(struct MovieClip *clip); diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 915cafd5d3d..cb211b65948 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1056,9 +1056,6 @@ void free_nodesystem(void); struct Depsgraph; -void BKE_nodetree_copy_default_values(struct bNodeTree *ntree_dst, - const struct bNodeTree *ntree_src); - void BKE_nodetree_shading_params_eval(struct Depsgraph *depsgraph, struct bNodeTree *ntree_dst, const struct bNodeTree *ntree_src); diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index 3929a97ab65..6172c9998af 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -66,6 +66,7 @@ void BKE_object_free_curve_cache(struct Object *ob); void BKE_object_free(struct Object *ob); void BKE_object_free_derived_caches(struct Object *ob); +void BKE_object_free_derived_mesh_caches(struct Object *ob); void BKE_object_free_caches(struct Object *object); void BKE_object_modifier_hook_reset(struct Object *ob, struct HookModifierData *hmd); @@ -274,6 +275,9 @@ void BKE_object_sculpt_modifiers_changed(struct Object *ob); int BKE_object_obdata_texspace_get(struct Object *ob, short **r_texflag, float **r_loc, float **r_size, float **r_rot); struct Mesh *BKE_object_get_evaluated_mesh(const struct Depsgraph *depsgraph, struct Object *ob); +struct Mesh *BKE_object_get_final_mesh(struct Object *object); +struct Mesh *BKE_object_get_pre_modified_mesh(struct Object *object); +struct Mesh *BKE_object_get_original_mesh(struct Object *object); int BKE_object_insert_ptcache(struct Object *ob); void BKE_object_delete_ptcache(struct Object *ob, int index); diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index 9bd73bd7553..412cf45de2b 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -40,6 +40,7 @@ struct CurveMapping; struct MeshElemMap; struct GridPaintMask; struct Main; +struct Mesh; struct MLoop; struct MLoopTri; struct MFace; @@ -185,7 +186,8 @@ typedef struct SculptSession { float *vmask; /* Mesh connectivity */ - const struct MeshElemMap *pmap; + struct MeshElemMap *pmap; + int *pmap_mem; /* BMesh for dynamic topology sculpting */ struct BMesh *bm; @@ -258,6 +260,8 @@ int BKE_sculpt_mask_layers_ensure(struct Object *ob, struct MultiresModifierData *mmd); void BKE_sculpt_toolsettings_data_ensure(struct Scene *scene); +struct PBVH *BKE_sculpt_object_pbvh_ensure(struct Object *ob, struct Mesh *me_eval_deform); + enum { SCULPT_MASK_LAYER_CALC_VERT = (1 << 0), SCULPT_MASK_LAYER_CALC_LOOP = (1 << 1) diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h index 4820f0173bf..d87d63454f0 100644 --- a/source/blender/blenkernel/BKE_particle.h +++ b/source/blender/blenkernel/BKE_particle.h @@ -303,15 +303,13 @@ void psys_set_current_num(Object *ob, int index); struct LatticeDeformData *psys_create_lattice_deform_data(struct ParticleSimulationData *sim); struct ParticleSystem *psys_orig_get(struct ParticleSystem *psys); -struct ParticleSystem *psys_eval_get(struct Depsgraph *depsgraph, - struct Object *object, - struct ParticleSystem *psys); bool psys_in_edit_mode(struct Depsgraph *depsgraph, struct ParticleSystem *psys); bool psys_check_enabled(struct Object *ob, struct ParticleSystem *psys, const bool use_render_params); bool psys_check_edited(struct ParticleSystem *psys); void psys_check_group_weights(struct ParticleSettings *part); int psys_uses_gravity(struct ParticleSimulationData *sim); +void BKE_particlesettings_fluid_default_settings(struct ParticleSettings *part); /* free */ void BKE_particlesettings_free(struct ParticleSettings *part); diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h index c18288de1bc..78c766f6115 100644 --- a/source/blender/blenkernel/BKE_pbvh.h +++ b/source/blender/blenkernel/BKE_pbvh.h @@ -240,7 +240,7 @@ void BKE_pbvh_node_layer_disp_free(PBVHNode *node); /* vertex deformer */ float (*BKE_pbvh_get_vertCos(struct PBVH *pbvh))[3]; -void BKE_pbvh_apply_vertCos(struct PBVH *pbvh, float (*vertCos)[3]); +void BKE_pbvh_apply_vertCos(struct PBVH *pbvh, float (*vertCos)[3], const int totvert); bool BKE_pbvh_isDeformed(struct PBVH *pbvh); /* Vertex Iterator */ diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h index 722a36c9f1d..0b95152ad8e 100644 --- a/source/blender/blenkernel/BKE_screen.h +++ b/source/blender/blenkernel/BKE_screen.h @@ -64,7 +64,7 @@ struct ScrAreaMap; #include "RNA_types.h" -/* spacetype has everything stored to get an editor working, it gets initialized via +/* spacetype has everything stored to get an editor working, it gets initialized via * ED_spacetypes_init() in editors/space_api/spacetypes.c */ /* an editor in Blender is a combined ScrArea + SpaceType + SpaceData */ @@ -72,36 +72,36 @@ struct ScrAreaMap; typedef struct SpaceType { struct SpaceType *next, *prev; - + char name[BKE_ST_MAXNAME]; /* for menus */ int spaceid; /* unique space identifier */ int iconid; /* icon lookup for menus */ - + /* Initial allocation, after this WM will call init() too. Some editors need * area and scene data (e.g. frame range) to set their initial scrolling. */ - struct SpaceLink *(*new)(const struct ScrArea *, const struct Scene *); + struct SpaceLink *(*new)(const struct ScrArea *sa, const struct Scene *scene); /* not free spacelink itself */ - void (*free)(struct SpaceLink *); - + void (*free)(struct SpaceLink *sl); + /* init is to cope with file load, screen (size) changes, check handlers */ - void (*init)(struct wmWindowManager *, struct ScrArea *); + void (*init)(struct wmWindowManager *wm, struct ScrArea *sa); /* exit is called when the area is hidden or removed */ - void (*exit)(struct wmWindowManager *, struct ScrArea *); + void (*exit)(struct wmWindowManager *wm, struct ScrArea *sa); /* Listeners can react to bContext changes */ - void (*listener)(struct bScreen *sc, struct ScrArea *, - struct wmNotifier *, struct Scene *scene, + void (*listener)(struct bScreen *sc, struct ScrArea *sa, + struct wmNotifier *wmn, struct Scene *scene, struct WorkSpace *workspace); - + /* refresh context, called after filereads, ED_area_tag_refresh() */ - void (*refresh)(const struct bContext *, struct ScrArea *); - + void (*refresh)(const struct bContext *C, struct ScrArea *sa); + /* after a spacedata copy, an init should result in exact same situation */ - struct SpaceLink *(*duplicate)(struct SpaceLink *); + struct SpaceLink *(*duplicate)(struct SpaceLink *sl); /* register operator types on startup */ void (*operatortypes)(void); /* add default items to WM keymap */ - void (*keymap)(struct wmKeyConfig *); + void (*keymap)(struct wmKeyConfig *keyconf); /* on startup, define dropboxes for spacetype+regions */ void (*dropboxes)(void); @@ -109,10 +109,10 @@ typedef struct SpaceType { void (*manipulators)(void); /* return context data */ - int (*context)(const struct bContext *, const char *, struct bContextDataResult *); + int (*context)(const struct bContext *C, const char *member, struct bContextDataResult *result); /* Used when we want to replace an ID by another (or NULL). */ - void (*id_remap)(struct ScrArea *, struct SpaceLink *, struct ID *, struct ID *); + void (*id_remap)(struct ScrArea *sa, struct SpaceLink *sl, struct ID *old_id, struct ID *new_id); int (*space_subtype_get)(struct ScrArea *sa); void (*space_subtype_set)(struct ScrArea *sa, int value); @@ -120,37 +120,37 @@ typedef struct SpaceType { /* region type definitions */ ListBase regiontypes; - + /* tool shelf definitions */ ListBase toolshelf; - + /* read and write... */ - + /* default keymaps to add */ int keymapflag; - + } SpaceType; /* region types are also defined using spacetypes_init, via a callback */ typedef struct ARegionType { struct ARegionType *next, *prev; - + int regionid; /* unique identifier within this space, defines RGN_TYPE_xxxx */ - + /* add handlers, stuff you only do once or on area/region type/size changes */ - void (*init)(struct wmWindowManager *, struct ARegion *); + void (*init)(struct wmWindowManager *wm, struct ARegion *ar); /* exit is called when the region is hidden or removed */ - void (*exit)(struct wmWindowManager *, struct ARegion *); + void (*exit)(struct wmWindowManager *wm, struct ARegion *ar); /* draw entirely, view changes should be handled here */ - void (*draw)(const struct bContext *, struct ARegion *); + void (*draw)(const struct bContext *C, struct ARegion *ar); /* optional, compute button layout before drawing for dynamic size */ - void (*layout)(const struct bContext *, struct ARegion *); + void (*layout)(const struct bContext *C, struct ARegion *ar); /* snap the size of the region (can be NULL for no snapping). */ int (*snap_size)(const struct ARegion *ar, int size, int axis); /* contextual changes should be handled here */ - void (*listener)(struct bScreen *, struct ScrArea *, struct ARegion *, - struct wmNotifier *, const struct Scene *scene); + void (*listener)(struct bScreen *sc, struct ScrArea *sa, struct ARegion *ar, + struct wmNotifier *wmn, const struct Scene *scene); /* Optional callback to generate subscriptions. */ void (*message_subscribe)( const struct bContext *C, @@ -161,18 +161,18 @@ typedef struct ARegionType { void (*free)(struct ARegion *); /* split region, copy data optionally */ - void *(*duplicate)(void *); + void *(*duplicate)(void *poin); + - /* register operator types on startup */ void (*operatortypes)(void); /* add own items to keymap */ - void (*keymap)(struct wmKeyConfig *); + void (*keymap)(struct wmKeyConfig *keyconf); /* allows default cursor per region */ - void (*cursor)(struct wmWindow *, struct ScrArea *, struct ARegion *ar); + void (*cursor)(struct wmWindow *win, struct ScrArea *sa, struct ARegion *ar); /* return context data */ - int (*context)(const struct bContext *, const char *, struct bContextDataResult *); + int (*context)(const struct bContext *C, const char *member, struct bContextDataResult *result); /* custom drawing callbacks */ ListBase drawcalls; @@ -182,7 +182,7 @@ typedef struct ARegionType { /* header type definitions */ ListBase headertypes; - + /* hardcoded constraints, smaller than these values region is not visible */ int minsizex, minsizey; /* when new region opens (region prefsizex/y are zero then */ @@ -199,24 +199,29 @@ typedef struct ARegionType { typedef struct PanelType { struct PanelType *next, *prev; - + char idname[BKE_ST_MAXNAME]; /* unique name */ char label[BKE_ST_MAXNAME]; /* for panel header */ char translation_context[BKE_ST_MAXNAME]; char context[BKE_ST_MAXNAME]; /* for buttons window */ char category[BKE_ST_MAXNAME]; /* for category tabs */ - char owner_id[BKE_ST_MAXNAME]; /* for work-spaces to selectively show. */ + char owner_id[BKE_ST_MAXNAME]; /* for work-spaces to selectively show. */ + char parent_id[BKE_ST_MAXNAME]; /* parent idname for subpanels */ int space_type; int region_type; int flag; /* verify if the panel should draw or not */ - int (*poll)(const struct bContext *, struct PanelType *); + int (*poll)(const struct bContext *C, struct PanelType *pt); /* draw header (optional) */ - void (*draw_header)(const struct bContext *, struct Panel *); + void (*draw_header)(const struct bContext *C, struct Panel *pa); /* draw entirely, view changes should be handled here */ - void (*draw)(const struct bContext *, struct Panel *); + void (*draw)(const struct bContext *C, struct Panel *pa); + + /* sub panels */ + struct PanelType *parent; + ListBase children; /* RNA integration */ ExtensionRNA ext; @@ -225,14 +230,18 @@ typedef struct PanelType { /* uilist types */ /* Draw an item in the uiList */ -typedef void (*uiListDrawItemFunc)(struct uiList *, struct bContext *, struct uiLayout *, struct PointerRNA *, - struct PointerRNA *, int, struct PointerRNA *, const char *, int, int); +typedef void (*uiListDrawItemFunc)( + struct uiList *ui_list, struct bContext *C, struct uiLayout *layout, struct PointerRNA *dataptr, + struct PointerRNA *itemptr, int icon, struct PointerRNA *active_dataptr, const char *active_propname, + int index, int flt_flag); /* Draw the filtering part of an uiList */ -typedef void (*uiListDrawFilterFunc)(struct uiList *, struct bContext *, struct uiLayout *); +typedef void (*uiListDrawFilterFunc)( + struct uiList *ui_list, struct bContext *C, struct uiLayout *layout); /* Filter items of an uiList */ -typedef void (*uiListFilterItemsFunc)(struct uiList *, struct bContext *, struct PointerRNA *, const char *); +typedef void (*uiListFilterItemsFunc)( + struct uiList *ui_list, struct bContext *C, struct PointerRNA *, const char *propname); typedef struct uiListType { struct uiListType *next, *prev; @@ -257,7 +266,7 @@ typedef struct HeaderType { int region_type; /* draw entirely, view changes should be handled here */ - void (*draw)(const struct bContext *, struct Header *); + void (*draw)(const struct bContext *C, struct Header *header); /* RNA integration */ ExtensionRNA ext; @@ -281,9 +290,9 @@ typedef struct MenuType { const char *description; /* verify if the menu should draw or not */ - int (*poll)(const struct bContext *, struct MenuType *); + int (*poll)(const struct bContext *C, struct MenuType *mt); /* draw entirely, view changes should be handled here */ - void (*draw)(const struct bContext *, struct Menu *); + void (*draw)(const struct bContext *C, struct Menu *menu); /* RNA integration */ ExtensionRNA ext; @@ -307,7 +316,8 @@ void BKE_spacedata_freelist(ListBase *lb); void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2); void BKE_spacedata_draw_locks(int set); -void BKE_spacedata_callback_id_remap_set(void (*func)(struct ScrArea *, struct SpaceLink *, struct ID *, struct ID *)); +void BKE_spacedata_callback_id_remap_set( + void (*func)(struct ScrArea *sa, struct SpaceLink *sl, struct ID *old_id, struct ID *new_id)); void BKE_spacedata_id_unref(struct ScrArea *sa, struct SpaceLink *sl, struct ID *id); /* area/regions */ @@ -344,7 +354,7 @@ float BKE_screen_view3d_zoom_to_fac(float camzoom); float BKE_screen_view3d_zoom_from_fac(float zoomfac); /* screen */ -void BKE_screen_free(struct bScreen *sc); +void BKE_screen_free(struct bScreen *sc); void BKE_screen_area_map_free(struct ScrAreaMap *area_map) ATTR_NONNULL(); unsigned int BKE_screen_visible_layers(struct bScreen *screen, struct Scene *scene); @@ -356,4 +366,3 @@ void BKE_screen_remove_unused_scredges(struct bScreen *sc); void BKE_screen_remove_unused_scrverts(struct bScreen *sc); #endif - diff --git a/source/blender/blenkernel/BKE_studiolight.h b/source/blender/blenkernel/BKE_studiolight.h index 2f2e948ab26..7883f89f33a 100644 --- a/source/blender/blenkernel/BKE_studiolight.h +++ b/source/blender/blenkernel/BKE_studiolight.h @@ -59,15 +59,23 @@ struct GPUTexture; enum StudioLightFlag { STUDIOLIGHT_DIFFUSE_LIGHT_CALCULATED = (1 << 0), STUDIOLIGHT_LIGHT_DIRECTION_CALCULATED = (1 << 1), - STUDIOLIGHT_EXTERNAL_FILE = (1 << 2), - STUDIOLIGHT_ORIENTATION_CAMERA = (1 << 3), - STUDIOLIGHT_ORIENTATION_WORLD = (1 << 4), - STUDIOLIGHT_EQUIRECTANGULAR_IMAGE_LOADED = (1 << 5), - STUDIOLIGHT_EQUIRECTANGULAR_IRRADIANCE_IMAGE_CALCULATED = (1 << 6), - STUDIOLIGHT_EQUIRECTANGULAR_RADIANCE_GPUTEXTURE = (1 << 7), - STUDIOLIGHT_EQUIRECTANGULAR_IRRADIANCE_GPUTEXTURE = (1 << 8), - STUDIOLIGHT_RADIANCE_BUFFERS_CALCULATED = (1 << 9), + STUDIOLIGHT_INTERNAL = (1 << 2), + STUDIOLIGHT_EXTERNAL_FILE = (1 << 3), + STUDIOLIGHT_USER_DEFINED = (1 << 12), + STUDIOLIGHT_ORIENTATION_CAMERA = (1 << 4), + STUDIOLIGHT_ORIENTATION_WORLD = (1 << 5), + STUDIOLIGHT_ORIENTATION_VIEWNORMAL = (1 << 6), + STUDIOLIGHT_EXTERNAL_IMAGE_LOADED = (1 << 7), + STUDIOLIGHT_EQUIRECTANGULAR_IRRADIANCE_IMAGE_CALCULATED = (1 << 8), + STUDIOLIGHT_EQUIRECTANGULAR_RADIANCE_GPUTEXTURE = (1 << 9), + STUDIOLIGHT_EQUIRECTANGULAR_IRRADIANCE_GPUTEXTURE = (1 << 10), + STUDIOLIGHT_RADIANCE_BUFFERS_CALCULATED = (1 << 11), + STUDIOLIGHT_UI_EXPANDED = (1 << 13), } StudioLightFlag; +#define STUDIOLIGHT_FLAG_ALL (STUDIOLIGHT_INTERNAL | STUDIOLIGHT_EXTERNAL_FILE) +#define STUDIOLIGHT_FLAG_ORIENTATIONS (STUDIOLIGHT_ORIENTATION_CAMERA | STUDIOLIGHT_ORIENTATION_WORLD | STUDIOLIGHT_ORIENTATION_VIEWNORMAL) +#define STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE (STUDIOLIGHT_INTERNAL | STUDIOLIGHT_ORIENTATION_WORLD) +#define STUDIOLIGHT_ORIENTATIONS_SOLID (STUDIOLIGHT_ORIENTATION_CAMERA | STUDIOLIGHT_ORIENTATION_WORLD) typedef struct StudioLight { struct StudioLight *next, *prev; @@ -89,9 +97,11 @@ typedef struct StudioLight { void BKE_studiolight_init(void); void BKE_studiolight_free(void); struct StudioLight *BKE_studiolight_find(const char *name, int flag); -struct StudioLight *BKE_studiolight_findindex(int index); +struct StudioLight *BKE_studiolight_findindex(int index, int flag); +struct StudioLight *BKE_studiolight_find_first(int flag); unsigned int *BKE_studiolight_preview(StudioLight *sl, int icon_size, int icon_id_type); -const struct ListBase *BKE_studiolight_listbase(void); +struct ListBase *BKE_studiolight_listbase(void); void BKE_studiolight_ensure_flag(StudioLight *sl, int flag); +void BKE_studiolight_refresh(void); #endif /* __BKE_STUDIOLIGHT_H__ */ diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index c554d5e7b6c..c081bb0799f 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -61,6 +61,7 @@ #include "BKE_modifier.h" #include "BKE_mesh.h" #include "BKE_mesh_mapping.h" +#include "BKE_mesh_runtime.h" #include "BKE_mesh_tangent.h" #include "BKE_object.h" #include "BKE_object_deform.h" @@ -94,7 +95,6 @@ static ThreadRWMutex loops_cache_lock = PTHREAD_RWLOCK_INITIALIZER; -static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *ob); static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape_uid); static void mesh_init_origspace(Mesh *mesh); @@ -1157,6 +1157,8 @@ DerivedMesh *mesh_create_derived(Mesh *me, float (*vertCos)[3]) return dm; } +/* XXX2.8(Sybren): can be removed once DerivedMesh port is done */ +#ifdef WITH_DERIVEDMESH_DEPRECATED_FUNCS DerivedMesh *mesh_create_derived_for_modifier( struct Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md, int build_shapekey_layers) @@ -1207,6 +1209,7 @@ DerivedMesh *mesh_create_derived_for_modifier( return dm; } +#endif static float (*get_editbmesh_orco_verts(BMEditMesh *em))[3] { @@ -1920,7 +1923,7 @@ static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape } } -static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *UNUSED(ob)) +static void UNUSED_FUNCTION(add_shapekey_layers)(DerivedMesh *dm, Mesh *me, Object *UNUSED(ob)) { KeyBlock *kb; Key *key = me->key; @@ -2790,7 +2793,7 @@ static void editbmesh_calc_modifiers( } else { struct Mesh *mesh = ob->data; - if (mesh->id.tag & LIB_TAG_COPY_ON_WRITE) { + if (mesh->id.tag & LIB_TAG_COPIED_ON_WRITE) { BKE_mesh_runtime_ensure_edit_data(mesh); mesh->runtime.edit_data->vertexCos = MEM_dupallocN(deformedVerts); } @@ -2832,7 +2835,7 @@ static void editbmesh_calc_modifiers( else { /* this is just a copy of the editmesh, no need to calc normals */ struct Mesh *mesh = ob->data; - if (mesh->id.tag & LIB_TAG_COPY_ON_WRITE) { + if (mesh->id.tag & LIB_TAG_COPIED_ON_WRITE) { BKE_mesh_runtime_ensure_edit_data(mesh); if (mesh->runtime.edit_data->vertexCos != NULL) MEM_freeN((void *)mesh->runtime.edit_data->vertexCos); @@ -2943,18 +2946,14 @@ static void mesh_finalize_eval(Object *object) if (mesh_eval->mat != NULL) { MEM_freeN(mesh_eval->mat); } + /* Set flag which makes it easier to see what's going on in a debugger. */ + mesh_eval->id.tag |= LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT; mesh_eval->mat = MEM_dupallocN(mesh->mat); mesh_eval->totcol = mesh->totcol; /* Make evaluated mesh to share same edit mesh pointer as original * and copied meshes. */ mesh_eval->edit_btmesh = mesh->edit_btmesh; - /* Special flags to help debugging and also to allow copy-on-write core - * to understand that on re-evaluation this mesh is to be preserved and - * to be remapped back to copied original mesh when used as object data. - */ - mesh_eval->id.tag |= LIB_TAG_COPY_ON_WRITE_EVAL; - mesh_eval->id.orig_id = &mesh->id; /* Copy autosmooth settings from original mesh. * This is not done by BKE_mesh_new_nomain_from_template(), so need to take * extra care here. @@ -2970,7 +2969,7 @@ static void mesh_finalize_eval(Object *object) /* Object is sometimes not evaluated! * TODO(sergey): BAD TEMPORARY HACK FOR UNTIL WE ARE SMARTER */ - if (object->id.tag & LIB_TAG_COPY_ON_WRITE) { + if (object->id.tag & LIB_TAG_COPIED_ON_WRITE) { object->data = mesh_eval; } else { @@ -3108,6 +3107,7 @@ void makeDerivedMesh( /***/ +#ifdef USE_DERIVEDMESH /* Deprecated DM, use: 'mesh_get_eval_final'. */ DerivedMesh *mesh_get_derived_final( struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask) @@ -3128,6 +3128,7 @@ DerivedMesh *mesh_get_derived_final( if (ob->derivedFinal) { BLI_assert(!(ob->derivedFinal->dirty & DM_DIRTY_NORMALS)); } return ob->derivedFinal; } +#endif Mesh *mesh_get_eval_final( struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask) { @@ -3137,7 +3138,7 @@ Mesh *mesh_get_eval_final( bool need_mapping; dataMask |= object_get_datamask(depsgraph, ob, &need_mapping); - if (!ob->derivedFinal || + if (!ob->runtime.mesh_eval || ((dataMask & ob->lastDataMask) != dataMask) || (need_mapping != ob->lastNeedMapping)) { @@ -3148,6 +3149,7 @@ Mesh *mesh_get_eval_final( return ob->runtime.mesh_eval; } +#ifdef USE_DERIVEDMESH /* Deprecated DM, use: 'mesh_get_eval_deform' instead. */ DerivedMesh *mesh_get_derived_deform(struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask) { @@ -3167,6 +3169,7 @@ DerivedMesh *mesh_get_derived_deform(struct Depsgraph *depsgraph, Scene *scene, return ob->derivedDeform; } +#endif Mesh *mesh_get_eval_deform(struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask) { /* if there's no derived mesh or the last data mask used doesn't include diff --git a/source/blender/blenkernel/intern/blender_undo.c b/source/blender/blenkernel/intern/blender_undo.c index 98482bcc8b1..857fc72672c 100644 --- a/source/blender/blenkernel/intern/blender_undo.c +++ b/source/blender/blenkernel/intern/blender_undo.c @@ -67,10 +67,11 @@ bool BKE_memfile_undo_decode(MemFileUndoData *mfu, bContext *C) { - char mainstr[sizeof(G.main->name)]; + Main *bmain = CTX_data_main(C); + char mainstr[sizeof(bmain->name)]; int success = 0, fileflags; - BLI_strncpy(mainstr, G.main->name, sizeof(mainstr)); /* temporal store */ + BLI_strncpy(mainstr, BKE_main_blendfile_path(bmain), sizeof(mainstr)); /* temporal store */ fileflags = G.fileflags; G.fileflags |= G_FILE_NO_UI; @@ -82,13 +83,14 @@ bool BKE_memfile_undo_decode(MemFileUndoData *mfu, bContext *C) success = BKE_blendfile_read_from_memfile(C, &mfu->memfile, NULL, 0); } - /* restore */ - BLI_strncpy(G.main->name, mainstr, sizeof(G.main->name)); /* restore */ + /* Restore, bmain has been re-allocated. */ + bmain = CTX_data_main(C); + BLI_strncpy(bmain->name, mainstr, sizeof(bmain->name)); G.fileflags = fileflags; if (success) { /* important not to update time here, else non keyed tranforms are lost */ - DEG_on_visible_update(G.main, false); + DEG_on_visible_update(bmain, false); } return success; diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c index 34079d778f7..597c69408b5 100644 --- a/source/blender/blenkernel/intern/blendfile.c +++ b/source/blender/blenkernel/intern/blendfile.c @@ -116,6 +116,7 @@ static void setup_app_data( bContext *C, BlendFileData *bfd, const char *filepath, ReportList *reports) { + Main *bmain = G.main; /* Valid usage */ Scene *curscene = NULL; const bool is_startup = (bfd->filename[0] == '\0'); const bool recover = (G.fileflags & G_FILE_RECOVER) != 0; @@ -172,9 +173,9 @@ static void setup_app_data( bool track_undo_scene; /* comes from readfile.c */ - SWAP(ListBase, G.main->wm, bfd->main->wm); - SWAP(ListBase, G.main->workspaces, bfd->main->workspaces); - SWAP(ListBase, G.main->screen, bfd->main->screen); + SWAP(ListBase, bmain->wm, bfd->main->wm); + SWAP(ListBase, bmain->workspaces, bfd->main->workspaces); + SWAP(ListBase, bmain->screen, bfd->main->screen); /* we re-use current window and screen */ win = CTX_wm_window(C); @@ -236,9 +237,9 @@ static void setup_app_data( /* clear old property update cache, in case some old references are left dangling */ RNA_property_update_cache_free(); - G.main = bfd->main; + bmain = G.main = bfd->main; - CTX_data_main_set(C, G.main); + CTX_data_main_set(C, bmain); if (bfd->user) { @@ -266,7 +267,7 @@ static void setup_app_data( /* Keep state from preferences. */ const int fileflags_skip = G_FILE_FLAGS_RUNTIME; G.fileflags = (G.fileflags & fileflags_skip) | (bfd->fileflags & ~fileflags_skip); - CTX_wm_manager_set(C, G.main->wm.first); + CTX_wm_manager_set(C, bmain->wm.first); CTX_wm_screen_set(C, bfd->curscreen); CTX_data_scene_set(C, bfd->curscene); CTX_wm_area_set(C, NULL); @@ -280,10 +281,10 @@ static void setup_app_data( wmWindow *win = CTX_wm_window(C); /* in case we don't even have a local scene, add one */ - if (!G.main->scene.first) - BKE_scene_add(G.main, "Empty"); + if (!bmain->scene.first) + BKE_scene_add(bmain, "Empty"); - CTX_data_scene_set(C, G.main->scene.first); + CTX_data_scene_set(C, bmain->scene.first); win->scene = CTX_data_scene(C); curscene = CTX_data_scene(C); } @@ -307,35 +308,35 @@ static void setup_app_data( /* FIXME: this version patching should really be part of the file-reading code, * but we still get too many unrelated data-corruption crashes otherwise... */ - if (G.main->versionfile < 250) - do_versions_ipos_to_animato(G.main); + if (bmain->versionfile < 250) + do_versions_ipos_to_animato(bmain); - G.main->recovered = 0; + bmain->recovered = 0; /* startup.blend or recovered startup */ if (bfd->filename[0] == 0) { - G.main->name[0] = 0; + bmain->name[0] = '\0'; } else if (recover && G.relbase_valid) { /* in case of autosave or quit.blend, use original filename instead * use relbase_valid to make sure the file is saved, else we get <memory2> in the filename */ filepath = bfd->filename; - G.main->recovered = 1; + bmain->recovered = 1; /* these are the same at times, should never copy to the same location */ - if (G.main->name != filepath) - BLI_strncpy(G.main->name, filepath, FILE_MAX); + if (bmain->name != filepath) + BLI_strncpy(bmain->name, filepath, FILE_MAX); } /* baseflags, groups, make depsgraph, etc */ /* first handle case if other windows have different scenes visible */ if (mode == LOAD_UI) { - wmWindowManager *wm = G.main->wm.first; + wmWindowManager *wm = bmain->wm.first; if (wm) { for (wmWindow *win = wm->windows.first; win; win = win->next) { if (win->scene && win->scene != curscene) { - BKE_scene_set_background(G.main, win->scene); + BKE_scene_set_background(bmain, win->scene); } } } @@ -346,10 +347,10 @@ static void setup_app_data( * constructing dependency graph. */ if (mode != LOAD_UNDO) { - IMB_colormanagement_check_file_config(G.main); + IMB_colormanagement_check_file_config(bmain); } - BKE_scene_set_background(G.main, curscene); + BKE_scene_set_background(bmain, curscene); if (mode != LOAD_UNDO) { /* TODO(sergey): Can this be also move above? */ @@ -431,9 +432,10 @@ bool BKE_blendfile_read_from_memfile( bContext *C, struct MemFile *memfile, ReportList *reports, int skip_flags) { + Main *bmain = CTX_data_main(C); BlendFileData *bfd; - bfd = BLO_read_from_memfile(CTX_data_main(C), G.main->name, memfile, reports, skip_flags); + bfd = BLO_read_from_memfile(bmain, BKE_main_blendfile_path(bmain), memfile, reports, skip_flags); if (bfd) { /* remove the unused screens and wm */ while (bfd->main->wm.first) diff --git a/source/blender/blenkernel/intern/bpath.c b/source/blender/blenkernel/intern/bpath.c index 1fd2797d2f8..82d9f9f8f69 100644 --- a/source/blender/blenkernel/intern/bpath.c +++ b/source/blender/blenkernel/intern/bpath.c @@ -325,7 +325,7 @@ void BKE_bpath_missing_files_find(Main *bmain, const char *searchpath, ReportLis struct BPathFind_Data data = {NULL}; const int flag = BKE_BPATH_TRAVERSE_ABS | BKE_BPATH_TRAVERSE_RELOAD_EDITED; - data.basedir = bmain->name; + data.basedir = BKE_main_blendfile_path(bmain); data.reports = reports; data.searchdir = searchpath; data.find_all = find_all; diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index b3ea3de6ea9..e8328139d64 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -45,6 +45,7 @@ #include "BKE_DerivedMesh.h" #include "BKE_editmesh.h" #include "BKE_mesh.h" +#include "BKE_mesh_runtime.h" #include "MEM_guardedalloc.h" diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c index 274f7b78529..74c0dca6279 100644 --- a/source/blender/blenkernel/intern/cachefile.c +++ b/source/blender/blenkernel/intern/cachefile.c @@ -89,13 +89,22 @@ void BKE_cachefile_free(CacheFile *cache_file) { BKE_animdata_free((ID *)cache_file, false); + if (cache_file->id.tag & LIB_TAG_NO_MAIN) { + /* CoW/no-main copies reuse the existing ArchiveReader and mutex */ + return; + } + + if (cache_file->handle) { #ifdef WITH_ALEMBIC - ABC_free_handle(cache_file->handle); + ABC_free_handle(cache_file->handle); #endif - + cache_file->handle = NULL; + } if (cache_file->handle_mutex) { BLI_mutex_free(cache_file->handle_mutex); + cache_file->handle_mutex = NULL; } + BLI_freelistN(&cache_file->object_paths); } @@ -110,8 +119,14 @@ void BKE_cachefile_free(CacheFile *cache_file) void BKE_cachefile_copy_data( Main *UNUSED(bmain), CacheFile *cache_file_dst, const CacheFile *UNUSED(cache_file_src), const int UNUSED(flag)) { + if (cache_file_dst->id.tag & LIB_TAG_NO_MAIN) { + /* CoW/no-main copies reuse the existing ArchiveReader and mutex */ + return; + } + cache_file_dst->handle = NULL; - BLI_listbase_clear(&cache_file_dst->object_paths); + cache_file_dst->handle_mutex = NULL; + BLI_duplicatelist(&cache_file_dst->object_paths, &cache_file_dst->object_paths); } CacheFile *BKE_cachefile_copy(Main *bmain, const CacheFile *cache_file) @@ -153,6 +168,8 @@ void BKE_cachefile_ensure_handle(const Main *bmain, CacheFile *cache_file) BLI_mutex_lock(cache_file->handle_mutex); if (cache_file->handle == NULL) { + /* Assigning to a CoW copy is a bad idea; assign to the original instead. */ + BLI_assert((cache_file->id.tag & LIB_TAG_COPIED_ON_WRITE) == 0); BKE_cachefile_reload(bmain, cache_file); } diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 773ef90aac8..7bcc05b0e37 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -46,6 +46,7 @@ #include "BKE_global.h" #include "BKE_mesh.h" #include "BKE_mesh_mapping.h" +#include "BKE_object.h" #include "BKE_paint.h" #include "BKE_editmesh.h" #include "BKE_curve.h" @@ -289,7 +290,7 @@ static PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm) * this derivedmesh is just original mesh. it's the multires subsurf dm * that this is actually for, to support a pbvh on a modified mesh */ if (!cddm->pbvh && ob->type == OB_MESH) { - Mesh *me = ob->data; + Mesh *me = BKE_object_get_original_mesh(ob); const int looptris_num = poly_to_tri_count(me->totpoly, me->totloop); MLoopTri *looptri; bool deformed; @@ -324,7 +325,7 @@ static PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm) totvert = deformdm->getNumVerts(deformdm); vertCos = MEM_malloc_arrayN(totvert, sizeof(float[3]), "cdDM_getPBVH vertCos"); deformdm->getVertCos(deformdm, vertCos); - BKE_pbvh_apply_vertCos(cddm->pbvh, vertCos); + BKE_pbvh_apply_vertCos(cddm->pbvh, vertCos, totvert); MEM_freeN(vertCos); } } diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index a39de284064..cc1c7260cbc 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -48,7 +48,7 @@ #include "BKE_cloth.h" #include "BKE_effect.h" #include "BKE_global.h" -#include "BKE_mesh.h" +#include "BKE_mesh_runtime.h" #include "BKE_modifier.h" #include "BKE_pointcache.h" diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index c4709a32f78..ab0ec8b0491 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -59,7 +59,7 @@ static bool collection_child_add(Collection *parent, Collection *collection, int flag, const bool add_us); static bool collection_child_remove(Collection *parent, Collection *collection); -static bool collection_object_add(Collection *collection, Object *ob, int flag, const bool add_us); +static bool collection_object_add(Main *bmain, Collection *collection, Object *ob, int flag, const bool add_us); static bool collection_object_remove(Main *bmain, Collection *collection, Object *ob, const bool free_us); static CollectionChild *collection_find_child(Collection *parent, Collection *collection); @@ -163,7 +163,7 @@ bool BKE_collection_delete(Main *bmain, Collection *collection, bool hierarchy) /* Link child object into parent collections. */ for (CollectionParent *cparent = collection->parents.first; cparent; cparent = cparent->next) { Collection *parent = cparent->collection; - collection_object_add(parent, cob->ob, 0, true); + collection_object_add(bmain, parent, cob->ob, 0, true); } /* Remove child object. */ @@ -190,7 +190,7 @@ bool BKE_collection_delete(Main *bmain, Collection *collection, bool hierarchy) * \param flag Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more). */ void BKE_collection_copy_data( - Main *UNUSED(bmain), Collection *collection_dst, const Collection *collection_src, const int flag) + Main *bmain, Collection *collection_dst, const Collection *collection_src, const int flag) { /* Do not copy collection's preview (same behavior as for objects). */ if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0 && false) { /* XXX TODO temp hack */ @@ -211,7 +211,7 @@ void BKE_collection_copy_data( collection_child_add(collection_dst, child->collection, flag, false); } for (CollectionObject *cob = collection_src->gobject.first; cob; cob = cob->next) { - collection_object_add(collection_dst, cob->ob, flag, false); + collection_object_add(bmain, collection_dst, cob->ob, flag, false); } } @@ -311,23 +311,6 @@ bool BKE_collection_is_animated(Collection *collection, Object *UNUSED(parent)) return false; } -/* puts all collection members in local timing system, after this call - * you can draw everything, leaves tags in objects to signal it needs further updating */ - -/* note: does not work for derivedmesh and render... it recreates all again in convertblender.c */ -void BKE_collection_handle_recalc_and_update( - struct Depsgraph *depsgraph, Scene *scene, Object *UNUSED(parent), Collection *collection) -{ - /* only do existing tags, as set by regular depsgraph */ - FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(collection, object) - { - if (object->id.recalc & ID_RECALC_ALL) { - BKE_object_handle_update(depsgraph, scene, object); - } - } - FOREACH_COLLECTION_OBJECT_RECURSIVE_END; -} - /* **************** Object List Cache *******************/ static void collection_object_cache_fill(ListBase *lb, Collection *collection, int parent_restrict) @@ -367,12 +350,12 @@ ListBase BKE_collection_object_cache_get(Collection *collection) if (!(collection->flag & COLLECTION_HAS_OBJECT_CACHE)) { static ThreadMutex cache_lock = BLI_MUTEX_INITIALIZER; + BLI_mutex_lock(&cache_lock); if (!(collection->flag & COLLECTION_HAS_OBJECT_CACHE)) { - BLI_mutex_lock(&cache_lock); collection_object_cache_fill(&collection->object_cache, collection, 0); collection->flag |= COLLECTION_HAS_OBJECT_CACHE; - BLI_mutex_unlock(&cache_lock); } + BLI_mutex_unlock(&cache_lock); } return collection->object_cache; @@ -522,7 +505,7 @@ Collection *BKE_collection_object_find(Main *bmain, Collection *collection, Obje /********************** Collection Objects *********************/ -static bool collection_object_add(Collection *collection, Object *ob, int flag, const bool add_us) +static bool collection_object_add(Main *bmain, Collection *collection, Object *ob, int flag, const bool add_us) { if (ob->dup_group) { /* Cyclic dependency check. */ @@ -545,6 +528,10 @@ static bool collection_object_add(Collection *collection, Object *ob, int flag, id_us_plus(&ob->id); } + if ((flag & LIB_ID_CREATE_NO_MAIN) == 0) { + DEG_id_tag_update_ex(bmain, &collection->id, DEG_TAG_COPY_ON_WRITE); + } + return true; } @@ -565,6 +552,8 @@ static bool collection_object_remove(Main *bmain, Collection *collection, Object id_us_min(&ob->id); } + DEG_id_tag_update_ex(bmain, &collection->id, DEG_TAG_COPY_ON_WRITE); + return true; } @@ -577,7 +566,7 @@ bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob) return false; } - if (!collection_object_add(collection, ob, 0, true)) { + if (!collection_object_add(bmain, collection, ob, 0, true)) { return false; } @@ -597,7 +586,7 @@ void BKE_collection_object_add_from(Main *bmain, Scene *scene, Object *ob_src, O FOREACH_SCENE_COLLECTION_BEGIN(scene, collection) { if (BKE_collection_has_object(collection, ob_src)) { - collection_object_add(collection, ob_dst, 0, true); + collection_object_add(bmain, collection, ob_dst, 0, true); } } FOREACH_SCENE_COLLECTION_END; diff --git a/source/blender/blenkernel/intern/data_transfer.c b/source/blender/blenkernel/intern/data_transfer.c index 0451031c5b8..3639649eab5 100644 --- a/source/blender/blenkernel/intern/data_transfer.c +++ b/source/blender/blenkernel/intern/data_transfer.c @@ -50,6 +50,7 @@ #include "BKE_DerivedMesh.h" #include "BKE_mesh.h" #include "BKE_mesh_mapping.h" +#include "BKE_mesh_runtime.h" #include "BKE_mesh_remap.h" #include "BKE_object.h" #include "BKE_object_deform.h" diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index fa996b8f73e..a591ab354f6 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -37,6 +37,7 @@ #include "MEM_guardedalloc.h" #include "DNA_curve_types.h" +#include "DNA_mesh_types.h" #include "DNA_scene_types.h" #include "DNA_object_types.h" #include "DNA_vfont_types.h" @@ -51,8 +52,10 @@ #include "BKE_displist.h" #include "BKE_cdderivedmesh.h" #include "BKE_object.h" +#include "BKE_library.h" #include "BKE_mball.h" #include "BKE_mball_tessellate.h" +#include "BKE_mesh.h" #include "BKE_curve.h" #include "BKE_key.h" #include "BKE_anim.h" @@ -925,7 +928,7 @@ static void curve_calc_modifiers_post( Curve *cu = ob->data; int required_mode = 0, totvert = 0; const bool editmode = (!for_render && (cu->editnurb || cu->editfont)); - DerivedMesh *dm = NULL, *ndm; + Mesh *modified = NULL, *mesh_applied; float (*vertCos)[3] = NULL; int useCache = !for_render; ModifierApplyFlag app_flag = 0; @@ -963,23 +966,21 @@ static void curve_calc_modifiers_post( continue; if (mti->type == eModifierTypeType_OnlyDeform || - (mti->type == eModifierTypeType_DeformOrConstruct && !dm)) + (mti->type == eModifierTypeType_DeformOrConstruct && !modified)) { - if (dm) { + if (modified) { if (!vertCos) { - totvert = dm->getNumVerts(dm); - vertCos = MEM_mallocN(sizeof(*vertCos) * totvert, "dfmv"); - dm->getVertCos(dm, vertCos); + vertCos = BKE_mesh_vertexCos_get(modified, &totvert); } - modifier_deformVerts_DM_deprecated(md, &mectx_deform, dm, vertCos, totvert); + modifier_deformVerts(md, &mectx_deform, modified, vertCos, totvert); } else { if (!vertCos) { vertCos = displist_get_allverts(dispbase, &totvert); } - modifier_deformVerts_DM_deprecated(md, &mectx_deform, NULL, vertCos, totvert); + modifier_deformVerts(md, &mectx_deform, NULL, vertCos, totvert); } } else { @@ -991,13 +992,17 @@ static void curve_calc_modifiers_post( break; } - if (dm) { + if (modified) { if (vertCos) { - DerivedMesh *tdm = CDDM_copy(dm); - dm->release(dm); - dm = tdm; - - CDDM_apply_vert_coords(dm, vertCos); + Mesh *temp_mesh; + BKE_id_copy_ex(NULL, &modified->id, (ID **)&temp_mesh, + LIB_ID_CREATE_NO_MAIN | LIB_ID_CREATE_NO_USER_REFCOUNT | + LIB_ID_CREATE_NO_DEG_TAG | LIB_ID_COPY_NO_PREVIEW, + false); + BKE_id_free(NULL, modified); + modified = temp_mesh; + + BKE_mesh_apply_vert_coords(modified, vertCos); } } else { @@ -1009,7 +1014,7 @@ static void curve_calc_modifiers_post( curve_to_filledpoly(cu, nurb, dispbase); } - dm = CDDM_from_curve_displist(ob, dispbase); + modified = BKE_mesh_new_nomain_from_curve_displist(ob, dispbase); } if (vertCos) { @@ -1018,26 +1023,31 @@ static void curve_calc_modifiers_post( vertCos = NULL; } - ndm = modwrap_applyModifier(md, &mectx_apply, dm); + mesh_applied = modifier_applyModifier(md, &mectx_apply, modified); - if (ndm) { + if (mesh_applied) { /* Modifier returned a new derived mesh */ - if (dm && dm != ndm) /* Modifier */ - dm->release(dm); - dm = ndm; + if (modified && modified != mesh_applied) /* Modifier */ + BKE_id_free(NULL, modified); + modified = mesh_applied; } } } if (vertCos) { - if (dm) { - DerivedMesh *tdm = CDDM_copy(dm); - dm->release(dm); - dm = tdm; + if (modified) { + Mesh *temp_mesh; + BKE_id_copy_ex(NULL, &modified->id, (ID **)&temp_mesh, + LIB_ID_CREATE_NO_MAIN | LIB_ID_CREATE_NO_USER_REFCOUNT | + LIB_ID_CREATE_NO_DEG_TAG | LIB_ID_COPY_NO_PREVIEW, + false); + BKE_id_free(NULL, modified); + modified = temp_mesh; + + BKE_mesh_apply_vert_coords(modified, vertCos); + BKE_mesh_calc_normals_mapping_simple(modified); - CDDM_apply_vert_coords(dm, vertCos); - CDDM_calc_normals_mapping(dm); MEM_freeN(vertCos); } else { @@ -1048,22 +1058,27 @@ static void curve_calc_modifiers_post( } if (r_dm_final) { - if (dm) { + if (modified) { /* see: mesh_calc_modifiers */ - if (dm->getNumTessFaces(dm) == 0) { - dm->recalcTessellation(dm); + if (modified->totface == 0) { + BKE_mesh_tessface_calc(modified); } /* Even if tessellation is not needed, some modifiers might have modified CD layers * (like mloopcol or mloopuv), hence we have to update those. */ - else if (dm->dirty & DM_DIRTY_TESS_CDLAYERS) { - DM_update_tessface_data(dm); + else if (modified->runtime.cd_dirty_vert & CD_MASK_TESSLOOPNORMAL) { + BKE_mesh_tessface_calc(modified); } - if (dm->type == DM_TYPE_CDDM) { - CDDM_calc_normals_mapping_ex(dm, (dm->dirty & DM_DIRTY_NORMALS) ? false : true); - } + /* XXX2.8(Sybren): make sure the face normals are recalculated as well */ + BKE_mesh_ensure_normals(modified); + + (*r_dm_final) = CDDM_from_mesh_ex(modified, CD_DUPLICATE, CD_MASK_MESH); + BKE_id_free(NULL, modified); + } + else { + (*r_dm_final) = NULL; } - (*r_dm_final) = dm; + } } @@ -1095,6 +1110,8 @@ static void displist_surf_indices(DispList *dl) } } +/* XXX2.8(Sybren): unused function; impossible to test after porting to Mesh */ +#ifdef WITH_DERIVEDMESH_DEPRECATED_FUNCS static DerivedMesh *create_orco_dm(Depsgraph *depsgraph, Scene *scene, Object *ob) { DerivedMesh *dm; @@ -1138,7 +1155,10 @@ static void add_orco_dm(Object *ob, DerivedMesh *dm, DerivedMesh *orcodm) else DM_add_vert_layer(dm, CD_ORCO, CD_ASSIGN, orco); } +#endif +/* XXX2.8(Sybren): unused function; impossible to test after porting to Mesh */ +#ifdef WITH_DERIVEDMESH_DEPRECATED_FUNCS static void curve_calc_orcodm( Depsgraph *depsgraph, Scene *scene, Object *ob, DerivedMesh *dm_final, const bool for_render, const bool use_render_resolution) @@ -1208,6 +1228,7 @@ static void curve_calc_orcodm( orcodm->release(orcodm); } +#endif void BKE_displist_make_surf( Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *dispbase, @@ -1816,6 +1837,8 @@ void BKE_displist_make_curveTypes_forOrco( } /* add Orco layer to the displist object which has got derived mesh and return orco */ +/* XXX2.8(Sybren): can be removed once DerivedMesh port is done */ +#ifdef WITH_DERIVEDMESH_DEPRECATED_FUNCS float *BKE_displist_make_orco( Depsgraph *depsgraph, Scene *scene, Object *ob, DerivedMesh *dm_final, const bool for_render, @@ -1838,6 +1861,7 @@ float *BKE_displist_make_orco( return orco; } +#endif void BKE_displist_minmax(ListBase *dispbase, float min[3], float max[3]) { diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 89f5f8facda..36452e1d2cf 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -3216,7 +3216,7 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char *filenam BKE_image_path_ensure_ext_from_imtype(output_file, format); /* Validate output file path */ - BLI_path_abs(output_file, G.main->name); + BLI_path_abs(output_file, BKE_main_blendfile_path_from_global()); BLI_make_existing_file(output_file); /* Init image buffer */ diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 34b185417e3..f7ab5415d1c 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -255,8 +255,8 @@ VFont *BKE_vfont_load(Main *bmain, const char *filepath) } else { BLI_split_file_part(filepath, filename, sizeof(filename)); - pf = newPackedFile(NULL, filepath, bmain->name); - temp_pf = newPackedFile(NULL, filepath, bmain->name); + pf = newPackedFile(NULL, filepath, BKE_main_blendfile_path(bmain)); + temp_pf = newPackedFile(NULL, filepath, BKE_main_blendfile_path(bmain)); is_builtin = false; } @@ -301,7 +301,7 @@ VFont *BKE_vfont_load_exists_ex(struct Main *bmain, const char *filepath, bool * char str[FILE_MAX], strtest[FILE_MAX]; BLI_strncpy(str, filepath, sizeof(str)); - BLI_path_abs(str, bmain->name); + BLI_path_abs(str, BKE_main_blendfile_path(bmain)); /* first search an identical filepath */ for (vfont = bmain->vfont.first; vfont; vfont = vfont->id.next) { diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index e5c192b3e1e..9a29a8a898b 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -592,7 +592,7 @@ Image *BKE_image_load(Main *bmain, const char *filepath) char str[FILE_MAX]; STRNCPY(str, filepath); - BLI_path_abs(str, bmain->name); + BLI_path_abs(str, BKE_main_blendfile_path(bmain)); /* exists? */ file = BLI_open(str, O_BINARY | O_RDONLY, 0); @@ -621,7 +621,7 @@ Image *BKE_image_load_exists_ex(const char *filepath, bool *r_exists) char str[FILE_MAX], strtest[FILE_MAX]; STRNCPY(str, filepath); - BLI_path_abs(str, G.main->name); + BLI_path_abs(str, BKE_main_blendfile_path_from_global()); /* first search an identical filepath */ for (ima = G.main->image.first; ima; ima = ima->id.next) { @@ -1648,7 +1648,8 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d time_t t; if (scene->r.stamp & R_STAMP_FILENAME) { - SNPRINTF(stamp_data->file, do_prefix ? "File %s" : "%s", G.relbase_valid ? G.main->name : "<untitled>"); + SNPRINTF(stamp_data->file, do_prefix ? "File %s" : "%s", + G.relbase_valid ? BKE_main_blendfile_path_from_global() : "<untitled>"); } else { stamp_data->file[0] = '\0'; @@ -4698,7 +4699,7 @@ static void image_update_views_format(Image *ima, ImageUser *iuser) char str[FILE_MAX]; STRNCPY(str, iv->filepath); - BLI_path_abs(str, G.main->name); + BLI_path_abs(str, BKE_main_blendfile_path_from_global()); /* exists? */ file = BLI_open(str, O_BINARY | O_RDONLY, 0); diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 0fa20f00823..b5b62de57ec 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -1057,7 +1057,7 @@ void BKE_lattice_modifiers_calc(struct Depsgraph *depsgraph, Scene *scene, Objec modifier_deformVerts_DM_deprecated(md, &mectx, NULL, vertexCos, numVerts); } - if (ob->id.tag & LIB_TAG_COPY_ON_WRITE) { + if (ob->id.tag & LIB_TAG_COPIED_ON_WRITE) { if (vertexCos) { BKE_lattice_vertexcos_apply(ob, vertexCos); MEM_freeN(vertexCos); diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index 16e349465f6..c7bb24cdcee 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -1264,6 +1264,16 @@ void BKE_layer_eval_view_layer( /* Store base in the array. */ view_layer->object_bases_array[base_index++] = base; } + if (view_layer == DEG_get_evaluated_view_layer(depsgraph)) { + ViewLayer *view_layer_orig = DEG_get_input_view_layer(depsgraph); + Base *base_orig = view_layer_orig->object_bases.first; + const Base *base_eval = view_layer->object_bases.first; + while (base_orig != NULL) { + base_orig->flag = base_eval->flag; + base_orig = base_orig->next; + base_eval = base_eval->next; + } + } } void BKE_layer_eval_view_layer_indexed( diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 917b318899c..8dac716ab02 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -155,7 +155,7 @@ * also note that the id _must_ have a library - campbell */ void BKE_id_lib_local_paths(Main *bmain, Library *lib, ID *id) { - const char *bpath_user_data[2] = {bmain->name, lib->filepath}; + const char *bpath_user_data[2] = {BKE_main_blendfile_path(bmain), lib->filepath}; BKE_bpath_traverse_id(bmain, id, BKE_bpath_relocate_visitor, @@ -1737,6 +1737,24 @@ void BKE_main_thumbnail_create(struct Main *bmain) bmain->blen_thumb->height = BLEN_THUMB_SIZE; } +/** + * Return filepath of given \a main. + */ +const char *BKE_main_blendfile_path(const Main *bmain) +{ + return bmain->name; +} + +/** + * Return filepath of global main (G.main). + * + * \warning Usage is not recommended, you should always try to get a velid Main pointer from context... + */ +const char *BKE_main_blendfile_path_from_global(void) +{ + return BKE_main_blendfile_path(G.main); +} + /* ***************** ID ************************ */ ID *BKE_libblock_find_name(struct Main *bmain, const short type, const char *name) { @@ -2525,7 +2543,7 @@ void BKE_library_filepath_set(Main *bmain, Library *lib, const char *filepath) */ /* Never make paths relative to parent lib - reading code (blenloader) always set *all* lib->name relative to * current main, not to their parent for indirectly linked ones. */ - const char *basepath = bmain->name; + const char *basepath = BKE_main_blendfile_path(bmain); BLI_path_abs(lib->filepath, basepath); } } diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 109b436292e..1ea2f170922 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -1315,7 +1315,5 @@ void paste_matcopybuf(Main *bmain, Material *ma) void BKE_material_eval(struct Depsgraph *depsgraph, Material *material) { DEG_debug_print_eval(depsgraph, __func__, material->id.name, material); - if ((BLI_listbase_is_empty(&material->gpumaterial) == false)) { - GPU_material_uniform_buffer_tag_dirty(&material->gpumaterial); - } + GPU_material_free(&material->gpumaterial); } diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index 339e79f2757..3afaf2d569e 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -563,11 +563,6 @@ void BKE_mball_select_swap(struct MetaBall *mb) /* **** Depsgraph evaluation **** */ -void BKE_mball_eval_geometry(struct Depsgraph *UNUSED(depsgraph), - MetaBall *UNUSED(mball)) -{ -} - /* Draw Engine */ void (*BKE_mball_batch_cache_dirty_cb)(MetaBall *mb, int mode) = NULL; diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index d27809586c2..b325d8d02d9 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -46,6 +46,7 @@ #include "BKE_DerivedMesh.h" #include "BKE_global.h" #include "BKE_mesh.h" +#include "BKE_mesh_runtime.h" #include "BKE_library.h" #include "BKE_material.h" #include "BKE_modifier.h" @@ -581,6 +582,34 @@ void BKE_mesh_copy_data(Main *bmain, Mesh *me_dst, const Mesh *me_src, const int } } +/* Custom data layer functions; those assume that totXXX are set correctly. */ +static void mesh_ensure_cdlayers_primary(Mesh *mesh, bool do_tessface) +{ + if (!CustomData_get_layer(&mesh->vdata, CD_MVERT)) + CustomData_add_layer(&mesh->vdata, CD_MVERT, CD_CALLOC, NULL, mesh->totvert); + if (!CustomData_get_layer(&mesh->edata, CD_MEDGE)) + CustomData_add_layer(&mesh->edata, CD_MEDGE, CD_CALLOC, NULL, mesh->totedge); + if (!CustomData_get_layer(&mesh->ldata, CD_MLOOP)) + CustomData_add_layer(&mesh->ldata, CD_MLOOP, CD_CALLOC, NULL, mesh->totloop); + if (!CustomData_get_layer(&mesh->pdata, CD_MPOLY)) + CustomData_add_layer(&mesh->pdata, CD_MPOLY, CD_CALLOC, NULL, mesh->totpoly); + + if (do_tessface && !CustomData_get_layer(&mesh->fdata, CD_MFACE)) + CustomData_add_layer(&mesh->fdata, CD_MFACE, CD_CALLOC, NULL, mesh->totface); +} +static void mesh_ensure_cdlayers_origindex(Mesh *mesh, bool do_tessface) +{ + if (!CustomData_get_layer(&mesh->vdata, CD_ORIGINDEX)) + CustomData_add_layer(&mesh->vdata, CD_ORIGINDEX, CD_CALLOC, NULL, mesh->totvert); + if (!CustomData_get_layer(&mesh->edata, CD_ORIGINDEX)) + CustomData_add_layer(&mesh->edata, CD_ORIGINDEX, CD_CALLOC, NULL, mesh->totedge); + if (!CustomData_get_layer(&mesh->pdata, CD_ORIGINDEX)) + CustomData_add_layer(&mesh->pdata, CD_ORIGINDEX, CD_CALLOC, NULL, mesh->totpoly); + + if (do_tessface && !CustomData_get_layer(&mesh->fdata, CD_ORIGINDEX)) + CustomData_add_layer(&mesh->fdata, CD_ORIGINDEX, CD_CALLOC, NULL, mesh->totface); +} + Mesh *BKE_mesh_new_nomain(int verts_len, int edges_len, int tessface_len, int loops_len, int polys_len) { Mesh *mesh = BKE_libblock_alloc( @@ -598,28 +627,16 @@ Mesh *BKE_mesh_new_nomain(int verts_len, int edges_len, int tessface_len, int lo copy_vn_i(mesh->ldata.typemap, CD_NUMTYPES, -1); copy_vn_i(mesh->pdata.typemap, CD_NUMTYPES, -1); - CustomData_add_layer(&mesh->vdata, CD_ORIGINDEX, CD_CALLOC, NULL, verts_len); - CustomData_add_layer(&mesh->edata, CD_ORIGINDEX, CD_CALLOC, NULL, edges_len); - CustomData_add_layer(&mesh->fdata, CD_ORIGINDEX, CD_CALLOC, NULL, tessface_len); - CustomData_add_layer(&mesh->pdata, CD_ORIGINDEX, CD_CALLOC, NULL, polys_len); - - CustomData_add_layer(&mesh->vdata, CD_MVERT, CD_CALLOC, NULL, verts_len); - CustomData_add_layer(&mesh->edata, CD_MEDGE, CD_CALLOC, NULL, edges_len); - CustomData_add_layer(&mesh->fdata, CD_MFACE, CD_CALLOC, NULL, tessface_len); - CustomData_add_layer(&mesh->ldata, CD_MLOOP, CD_CALLOC, NULL, loops_len); - CustomData_add_layer(&mesh->pdata, CD_MPOLY, CD_CALLOC, NULL, polys_len); - - mesh->mvert = CustomData_get_layer(&mesh->vdata, CD_MVERT); - mesh->medge = CustomData_get_layer(&mesh->edata, CD_MEDGE); - mesh->mface = CustomData_get_layer(&mesh->fdata, CD_MFACE); - mesh->mloop = CustomData_get_layer(&mesh->ldata, CD_MLOOP); - mesh->mpoly = CustomData_get_layer(&mesh->pdata, CD_MPOLY); - mesh->totvert = verts_len; mesh->totedge = edges_len; + mesh->totface = tessface_len; mesh->totloop = loops_len; mesh->totpoly = polys_len; + mesh_ensure_cdlayers_primary(mesh, true); + mesh_ensure_cdlayers_origindex(mesh, true); + BKE_mesh_update_customdata_pointers(mesh, false); + return mesh; } @@ -638,6 +655,7 @@ static Mesh *mesh_new_nomain_from_template_ex( me_dst->totvert = verts_len; me_dst->totedge = edges_len; + me_dst->totface = tessface_len; me_dst->totloop = loops_len; me_dst->totpoly = polys_len; @@ -652,15 +670,12 @@ static Mesh *mesh_new_nomain_from_template_ex( mesh_tessface_clear_intern(me_dst, false); } + /* The destination mesh should at least have valid primary CD layers, + * even in cases where the source mesh does not. */ + mesh_ensure_cdlayers_primary(me_dst, do_tessface); + mesh_ensure_cdlayers_origindex(me_dst, false); BKE_mesh_update_customdata_pointers(me_dst, false); - if (!CustomData_get_layer(&me_dst->vdata, CD_ORIGINDEX)) - CustomData_add_layer(&me_dst->vdata, CD_ORIGINDEX, CD_CALLOC, NULL, verts_len); - if (!CustomData_get_layer(&me_dst->edata, CD_ORIGINDEX)) - CustomData_add_layer(&me_dst->edata, CD_ORIGINDEX, CD_CALLOC, NULL, edges_len); - if (!CustomData_get_layer(&me_dst->pdata, CD_ORIGINDEX)) - CustomData_add_layer(&me_dst->pdata, CD_ORIGINDEX, CD_CALLOC, NULL, polys_len); - return me_dst; } diff --git a/source/blender/blenkernel/intern/mesh_convert.c b/source/blender/blenkernel/intern/mesh_convert.c index a3eef7b17b2..acd0cf32b13 100644 --- a/source/blender/blenkernel/intern/mesh_convert.c +++ b/source/blender/blenkernel/intern/mesh_convert.c @@ -43,6 +43,7 @@ #include "BKE_global.h" #include "BKE_key.h" #include "BKE_mesh.h" +#include "BKE_mesh_runtime.h" #include "BKE_modifier.h" #include "BKE_displist.h" #include "BKE_library.h" @@ -1263,7 +1264,7 @@ static void shapekey_layers_to_keyblocks(Mesh *mesh_src, Mesh *mesh_dst, int act /* This is a Mesh-based copy of DM_to_mesh() */ -void BKE_nomain_mesh_to_mesh(Mesh *mesh_src, Mesh *mesh_dst, Object *ob, CustomDataMask mask, bool take_ownership) +void BKE_mesh_nomain_to_mesh(Mesh *mesh_src, Mesh *mesh_dst, Object *ob, CustomDataMask mask, bool take_ownership) { /* mesh_src might depend on mesh_dst, so we need to do everything with a local copy */ /* TODO(Sybren): the above claim came from DM_to_mesh(); check whether it is still true with Mesh */ @@ -1414,7 +1415,7 @@ void BKE_nomain_mesh_to_mesh(Mesh *mesh_src, Mesh *mesh_dst, Object *ob, CustomD } /* This is a Mesh-based copy of DM_to_meshkey() */ -void BKE_nomain_mesh_to_meshkey(Mesh *mesh_src, Mesh *mesh_dst, KeyBlock *kb) +void BKE_mesh_nomain_to_meshkey(Mesh *mesh_src, Mesh *mesh_dst, KeyBlock *kb) { int a, totvert = mesh_src->totvert; float *fp; diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c index 068be0ef304..2d8476d6f02 100644 --- a/source/blender/blenkernel/intern/mesh_evaluate.c +++ b/source/blender/blenkernel/intern/mesh_evaluate.c @@ -88,6 +88,20 @@ static void mesh_calc_normals_vert_fallback(MVert *mverts, int numVerts) } } +/* TODO(Sybren): we can probably rename this to BKE_mesh_calc_normals_mapping(), + * and remove the function of the same name below, as that one doesn't seem to be + * called anywhere. */ +void BKE_mesh_calc_normals_mapping_simple(struct Mesh *mesh) +{ + const bool only_face_normals = CustomData_is_referenced_layer(&mesh->vdata, CD_MVERT); + + BKE_mesh_calc_normals_mapping_ex( + mesh->mvert, mesh->totvert, + mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, NULL, + mesh->mface, mesh->totface, NULL, NULL, + only_face_normals); +} + /* Calculate vertex and face normals, face normals are returned in *r_faceNors if non-NULL * and vertex normals are stored in actual mverts. */ diff --git a/source/blender/blenkernel/intern/mesh_runtime.c b/source/blender/blenkernel/intern/mesh_runtime.c index c8416811694..cd9db408d19 100644 --- a/source/blender/blenkernel/intern/mesh_runtime.c +++ b/source/blender/blenkernel/intern/mesh_runtime.c @@ -35,13 +35,22 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" +#include "DNA_object_types.h" #include "BLI_math_geom.h" #include "BLI_threads.h" #include "BKE_bvhutils.h" #include "BKE_mesh.h" +#include "BKE_mesh_runtime.h" +#ifdef USE_DERIVEDMESH +#include "BKE_DerivedMesh.h" +#endif + +/* -------------------------------------------------------------------- */ +/** \name Mesh Runtime Struct Utils + * \{ */ static ThreadRWMutex loops_cache_lock = PTHREAD_RWLOCK_INITIALIZER; @@ -145,8 +154,9 @@ const MLoopTri *BKE_mesh_runtime_looptri_ensure(Mesh *mesh) } /* This is a copy of DM_verttri_from_looptri(). */ -void BKE_mesh_runtime_verttri_from_looptri(MVertTri *r_verttri, const MLoop *mloop, - const MLoopTri *looptri, int looptri_num) +void BKE_mesh_runtime_verttri_from_looptri( + MVertTri *r_verttri, const MLoop *mloop, + const MLoopTri *looptri, int looptri_num) { int i; for (i = 0; i < looptri_num; i++) { @@ -192,6 +202,12 @@ void BKE_mesh_runtime_clear_geometry(Mesh *mesh) MEM_SAFE_FREE(mesh->runtime.looptris.array); } +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Mesh Batch Cache Callbacks + * \{ */ + /* Draw Engine */ void (*BKE_mesh_batch_cache_dirty_cb)(Mesh *me, int mode) = NULL; void (*BKE_mesh_batch_cache_free_cb)(Mesh *me) = NULL; @@ -208,3 +224,5 @@ void BKE_mesh_batch_cache_free(Mesh *me) BKE_mesh_batch_cache_free_cb(me); } } + +/** \} */ diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index bd9cd684548..0b904caf375 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -809,6 +809,18 @@ const char *modifier_path_relbase(Main *bmain, Object *ob) } } +const char *modifier_path_relbase_from_global(Object *ob) +{ + if (G.relbase_valid || ID_IS_LINKED(ob)) { + return ID_BLEND_PATH_FROM_GLOBAL(&ob->id); + } + else { + /* last resort, better then using "" which resolves to the current + * working directory */ + return BKE_tempdir_session(); + } +} + /* initializes the path with either */ void modifier_path_init(char *path, int path_maxlen, const char *name) { diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index d742bcea69d..fc236cc2ad0 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -199,7 +199,7 @@ static void get_proxy_fname(const MovieClip *clip, else BLI_snprintf(name, FILE_MAX, "%s/%s/proxy_%d/%08d", dir, clipfile, size, proxynr); - BLI_path_abs(name, G.main->name); + BLI_path_abs(name, BKE_main_blendfile_path_from_global()); BLI_path_frame(name, 1, 0); strcat(name, ".jpg"); @@ -270,7 +270,7 @@ static void movieclip_open_anim_file(MovieClip *clip) if (clip->flag & MCLIP_USE_PROXY_CUSTOM_DIR) { char dir[FILE_MAX]; BLI_strncpy(dir, clip->proxy.dir, sizeof(dir)); - BLI_path_abs(dir, G.main->name); + BLI_path_abs(dir, BKE_main_blendfile_path_from_global()); IMB_anim_set_index_dir(clip->anim, dir); } } @@ -627,13 +627,13 @@ static void movieclip_load_get_size(MovieClip *clip) } } -static void detect_clip_source(MovieClip *clip) +static void detect_clip_source(Main *bmain, MovieClip *clip) { ImBuf *ibuf; char name[FILE_MAX]; BLI_strncpy(name, clip->name, sizeof(name)); - BLI_path_abs(name, G.main->name); + BLI_path_abs(name, BKE_main_blendfile_path(bmain)); ibuf = IMB_testiffname(name, IB_rect | IB_multilayer); if (ibuf) { @@ -656,7 +656,7 @@ MovieClip *BKE_movieclip_file_add(Main *bmain, const char *name) char str[FILE_MAX]; BLI_strncpy(str, name, sizeof(str)); - BLI_path_abs(str, bmain->name); + BLI_path_abs(str, BKE_main_blendfile_path(bmain)); /* exists? */ file = BLI_open(str, O_BINARY | O_RDONLY, 0); @@ -670,7 +670,7 @@ MovieClip *BKE_movieclip_file_add(Main *bmain, const char *name) clip = movieclip_alloc(bmain, BLI_path_basename(name)); BLI_strncpy(clip->name, name, sizeof(clip->name)); - detect_clip_source(clip); + detect_clip_source(bmain, clip); movieclip_load_get_size(clip); if (clip->lastsize[0]) { @@ -690,7 +690,7 @@ MovieClip *BKE_movieclip_file_add_exists_ex(Main *bmain, const char *filepath, b char str[FILE_MAX], strtest[FILE_MAX]; BLI_strncpy(str, filepath, sizeof(str)); - BLI_path_abs(str, bmain->name); + BLI_path_abs(str, BKE_main_blendfile_path(bmain)); /* first search an identical filepath */ for (clip = bmain->movieclip.first; clip; clip = clip->id.next) { @@ -1282,13 +1282,13 @@ void BKE_movieclip_clear_proxy_cache(MovieClip *clip) } } -void BKE_movieclip_reload(MovieClip *clip) +void BKE_movieclip_reload(Main *bmain, MovieClip *clip) { /* clear cache */ free_buffers(clip); /* update clip source */ - detect_clip_source(clip); + detect_clip_source(bmain, clip); clip->lastsize[0] = clip->lastsize[1] = 0; movieclip_load_get_size(clip); diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index ee32c2398b2..39a472241bc 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -51,6 +51,7 @@ #include "BKE_cdderivedmesh.h" #include "BKE_mesh.h" #include "BKE_mesh_mapping.h" +#include "BKE_mesh_runtime.h" #include "BKE_modifier.h" #include "BKE_multires.h" #include "BKE_paint.h" diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 7a1f6c5d2b6..bf25306028f 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -3739,43 +3739,9 @@ void BKE_nodetree_remove_layer_n(bNodeTree *ntree, Scene *scene, const int layer } } -static void node_copy_default_values_list(ListBase *sockets_dst, - const ListBase *sockets_src) -{ - bNodeSocket *sock_dst = sockets_dst->first; - const bNodeSocket *sock_src = sockets_src->first; - while (sock_dst != NULL) { - node_socket_copy_default_value(sock_dst, sock_src); - sock_dst = sock_dst->next; - sock_src = sock_src->next; - } -} - -static void node_copy_default_values(bNode *node_dst, const bNode *node_src) -{ - node_copy_default_values_list(&node_dst->inputs, &node_src->inputs); - node_copy_default_values_list(&node_dst->outputs, &node_src->outputs); -} - -void BKE_nodetree_copy_default_values(bNodeTree *ntree_dst, - const bNodeTree *ntree_src) -{ - if (ntree_dst == ntree_src) { - return; - } - bNode *node_dst = ntree_dst->nodes.first; - const bNode *node_src = ntree_src->nodes.first; - while (node_dst != NULL) { - node_copy_default_values(node_dst, node_src); - node_dst = node_dst->next; - node_src = node_src->next; - } -} - void BKE_nodetree_shading_params_eval(struct Depsgraph *depsgraph, bNodeTree *ntree_dst, const bNodeTree *ntree_src) { DEG_debug_print_eval(depsgraph, __func__, ntree_src->id.name, ntree_dst); - BKE_nodetree_copy_default_values(ntree_dst, ntree_src); } diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 2eb35908d63..f55925f64f5 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -330,21 +330,14 @@ void BKE_object_free_derived_caches(Object *ob) ob->bb = NULL; } - if (ob->derivedFinal) { - ob->derivedFinal->needsFree = 1; - ob->derivedFinal->release(ob->derivedFinal); - ob->derivedFinal = NULL; - } - if (ob->derivedDeform) { - ob->derivedDeform->needsFree = 1; - ob->derivedDeform->release(ob->derivedDeform); - ob->derivedDeform = NULL; - } + BKE_object_free_derived_mesh_caches(ob); if (ob->runtime.mesh_eval != NULL) { Mesh *mesh_eval = ob->runtime.mesh_eval; /* Restore initial pointer. */ - ob->data = mesh_eval->id.orig_id; + if (ob->data == mesh_eval) { + ob->data = ob->runtime.mesh_orig; + } /* Evaluated mesh points to edit mesh, but does not own it. */ mesh_eval->edit_btmesh = NULL; BKE_mesh_free(mesh_eval); @@ -363,6 +356,20 @@ void BKE_object_free_derived_caches(Object *ob) BKE_object_free_curve_cache(ob); } +void BKE_object_free_derived_mesh_caches(struct Object *ob) +{ + if (ob->derivedFinal) { + ob->derivedFinal->needsFree = 1; + ob->derivedFinal->release(ob->derivedFinal); + ob->derivedFinal = NULL; + } + if (ob->derivedDeform) { + ob->derivedDeform->needsFree = 1; + ob->derivedDeform->release(ob->derivedDeform); + ob->derivedDeform = NULL; + } +} + void BKE_object_free_caches(Object *object) { ModifierData *md; @@ -2849,6 +2856,60 @@ Mesh *BKE_object_get_evaluated_mesh(const Depsgraph *depsgraph, Object *ob) return ob_eval->runtime.mesh_eval; } +/* Get object's mesh with all modifiers applied. */ +Mesh *BKE_object_get_final_mesh(Object *object) +{ + if (object->runtime.mesh_eval != NULL) { + BLI_assert((object->id.tag & LIB_TAG_COPIED_ON_WRITE) != 0); + BLI_assert(object->runtime.mesh_eval == object->data); + BLI_assert((object->runtime.mesh_eval->id.tag & LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT) != 0); + return object->runtime.mesh_eval; + } + /* Wasn't evaluated yet. */ + return object->data; +} + +/* Get mesh which is not affected by modifiers: + * - For original objects it will be same as object->data, and it is a mesh + * which is in the corresponding bmain. + * - For copied-on-write objects it will give pointer to a copied-on-write + * mesh which corresponds to original object's mesh. + */ +Mesh *BKE_object_get_pre_modified_mesh(Object *object) +{ + if (object->runtime.mesh_orig != NULL) { + BLI_assert(object->id.tag & LIB_TAG_COPIED_ON_WRITE); + BLI_assert(object->id.orig_id != NULL); + BLI_assert(object->runtime.mesh_orig->id.orig_id == ((Object *)object->id.orig_id)->data); + Mesh *result = object->runtime.mesh_orig; + BLI_assert((result->id.tag & LIB_TAG_COPIED_ON_WRITE) != 0); + BLI_assert((result->id.tag & LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT) == 0); + return result; + } + BLI_assert((object->id.tag & LIB_TAG_COPIED_ON_WRITE) == 0); + return object->data; +} + +/* Get a mesh which corresponds to very very original mesh from bmain. + * - For original objects it will be object->data. + * - For evaluated objects it will be same mesh as corresponding original + * object uses as data. + */ +Mesh *BKE_object_get_original_mesh(Object *object) +{ + Mesh *result = NULL; + if (object->id.orig_id == NULL) { + BLI_assert((object->id.tag & LIB_TAG_COPIED_ON_WRITE) == 0); + result = object->data; + } + else { + BLI_assert((object->id.tag & LIB_TAG_COPIED_ON_WRITE) != 0); + result = ((Object *)object->id.orig_id)->data; + } + BLI_assert(result != NULL); + BLI_assert((result->id.tag & (LIB_TAG_COPIED_ON_WRITE | LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT)) == 0); + return result; +} static int pc_cmp(const void *a, const void *b) { diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c index 2c94dc76854..324ad3a31dc 100644 --- a/source/blender/blenkernel/intern/object_dupli.c +++ b/source/blender/blenkernel/intern/object_dupli.c @@ -56,6 +56,7 @@ #include "BKE_lattice.h" #include "BKE_main.h" #include "BKE_mesh.h" +#include "BKE_mesh_runtime.h" #include "BKE_object.h" #include "BKE_particle.h" #include "BKE_scene.h" @@ -72,8 +73,6 @@ typedef struct DupliContext { Depsgraph *depsgraph; - bool do_update; - bool animated; Collection *collection; /* XXX child objects are selected from this group if set, could be nicer */ Object *obedit; /* Only to check if the object is in edit-mode. */ @@ -99,14 +98,11 @@ typedef struct DupliGenerator { static const DupliGenerator *get_dupli_generator(const DupliContext *ctx); /* create initial context for root object */ -static void init_context(DupliContext *r_ctx, Depsgraph *depsgraph, Scene *scene, Object *ob, float space_mat[4][4], bool update) +static void init_context(DupliContext *r_ctx, Depsgraph *depsgraph, Scene *scene, Object *ob, float space_mat[4][4]) { r_ctx->depsgraph = depsgraph; r_ctx->scene = scene; r_ctx->view_layer = DEG_get_evaluated_view_layer(depsgraph); - /* don't allow BKE_object_handle_update for viewport during render, can crash */ - r_ctx->do_update = update && !(G.is_rendering && DEG_get_mode(depsgraph) != DAG_EVAL_RENDER); - r_ctx->animated = false; r_ctx->collection = NULL; r_ctx->object = ob; @@ -123,12 +119,10 @@ static void init_context(DupliContext *r_ctx, Depsgraph *depsgraph, Scene *scene } /* create sub-context for recursive duplis */ -static void copy_dupli_context(DupliContext *r_ctx, const DupliContext *ctx, Object *ob, float mat[4][4], int index, bool animated) +static void copy_dupli_context(DupliContext *r_ctx, const DupliContext *ctx, Object *ob, float mat[4][4], int index) { *r_ctx = *ctx; - r_ctx->animated |= animated; /* object animation makes all children animated */ - /* XXX annoying, previously was done by passing an ID* argument, this at least is more explicit */ if (ctx->gen->type == OB_DUPLICOLLECTION) r_ctx->collection = ctx->object->dup_group; @@ -146,8 +140,7 @@ static void copy_dupli_context(DupliContext *r_ctx, const DupliContext *ctx, Obj * mat is transform of the object relative to current context (including object obmat) */ static DupliObject *make_dupli(const DupliContext *ctx, - Object *ob, float mat[4][4], int index, - bool animated, bool hide) + Object *ob, float mat[4][4], int index) { DupliObject *dob; int i; @@ -164,7 +157,6 @@ static DupliObject *make_dupli(const DupliContext *ctx, dob->ob = ob; mul_m4_m4m4(dob->mat, (float (*)[4])ctx->space_mat, mat); dob->type = ctx->gen->type; - dob->animated = animated || ctx->animated; /* object itself or some parent is animated */ /* set persistent id, which is an array with a persistent index for each level * (particle number, vertex number, ..). by comparing this we can find the same @@ -177,8 +169,6 @@ static DupliObject *make_dupli(const DupliContext *ctx, for (; i < MAX_DUPLI_RECUR; i++) dob->persistent_id[i] = INT_MAX; - if (hide) - dob->no_draw = true; /* metaballs never draw in duplis, they are instead merged into one by the basis * mball outside of the group. this does mean that if that mball is not in the * scene, they will not show up at all, limitation that should be solved once. */ @@ -208,12 +198,12 @@ static DupliObject *make_dupli(const DupliContext *ctx, /* recursive dupli objects * space_mat is the local dupli space (excluding dupli object obmat!) */ -static void make_recursive_duplis(const DupliContext *ctx, Object *ob, float space_mat[4][4], int index, bool animated) +static void make_recursive_duplis(const DupliContext *ctx, Object *ob, float space_mat[4][4], int index) { /* simple preventing of too deep nested collections with MAX_DUPLI_RECUR */ if (ctx->level < MAX_DUPLI_RECUR) { DupliContext rctx; - copy_dupli_context(&rctx, ctx, ob, space_mat, index, animated); + copy_dupli_context(&rctx, ctx, ob, space_mat, index); if (rctx.gen) { rctx.gen->make_duplis(&rctx); } @@ -247,7 +237,7 @@ static void make_child_duplis(const DupliContext *ctx, void *userdata, MakeChild Object *ob = base->object; if ((base->flag & BASE_VISIBLED) && ob != ctx->obedit && is_child(ob, parent)) { DupliContext pctx; - copy_dupli_context(&pctx, ctx, ctx->object, NULL, collectionid, false); + copy_dupli_context(&pctx, ctx, ctx->object, NULL, collectionid); /* mballs have a different dupli handling */ if (ob->type != OB_MBALL) { @@ -266,7 +256,7 @@ static void make_child_duplis(const DupliContext *ctx, void *userdata, MakeChild Object *ob = base->object; if ((ob != ctx->obedit) && is_child(ob, parent)) { DupliContext pctx; - copy_dupli_context(&pctx, ctx, ctx->object, NULL, baseid, false); + copy_dupli_context(&pctx, ctx, ctx->object, NULL, baseid); /* mballs have a different dupli handling */ if (ob->type != OB_MBALL) @@ -289,7 +279,6 @@ static void make_duplis_collection(const DupliContext *ctx) Base *base; float collection_mat[4][4]; int id; - bool animated; if (ob->dup_group == NULL) return; collection = ob->dup_group; @@ -300,17 +289,6 @@ static void make_duplis_collection(const DupliContext *ctx) mul_m4_m4m4(collection_mat, ob->obmat, collection_mat); /* don't access 'ob->obmat' from now on. */ - /* handles animated collections */ - - /* we need to check update for objects that are not in scene... */ - if (ctx->do_update) { - /* note: update is optional because we don't always need object - * transformations to be correct. Also fixes bug [#29616]. */ - BKE_collection_handle_recalc_and_update(ctx->depsgraph, ctx->scene, ob, collection); - } - - animated = BKE_collection_is_animated(collection, ob); - const ListBase dup_collection_objects = BKE_collection_object_cache_get(collection); for (base = dup_collection_objects.first, id = 0; base; base = base->next, id++) { if (base->object != ob && (base->flag & BASE_VISIBLED)) { @@ -319,10 +297,10 @@ static void make_duplis_collection(const DupliContext *ctx) /* collection dupli offset, should apply after everything else */ mul_m4_m4m4(mat, collection_mat, base->object->obmat); - make_dupli(ctx, base->object, mat, id, animated, false); + make_dupli(ctx, base->object, mat, id); /* recursion */ - make_recursive_duplis(ctx, base->object, collection_mat, id, animated); + make_recursive_duplis(ctx, base->object, collection_mat, id); } } } @@ -383,7 +361,7 @@ static void make_duplis_frames(const DupliContext *ctx) BKE_animsys_evaluate_animdata(depsgraph, scene, &ob->id, ob->adt, (float)scene->r.cfra, ADT_RECALC_ANIM); BKE_object_where_is_calc_time(depsgraph, scene, ob, (float)scene->r.cfra); - make_dupli(ctx, ob, ob->obmat, scene->r.cfra, false, false); + make_dupli(ctx, ob, ob->obmat, scene->r.cfra); } } @@ -469,13 +447,13 @@ static void vertex_dupli__mapFunc(void *userData, int index, const float co[3], */ mul_m4_m4m4(space_mat, obmat, inst_ob->imat); - dob = make_dupli(vdd->ctx, vdd->inst_ob, obmat, index, false, false); + dob = make_dupli(vdd->ctx, vdd->inst_ob, obmat, index); if (vdd->orco) copy_v3_v3(dob->orco, vdd->orco[index]); /* recursion */ - make_recursive_duplis(vdd->ctx, vdd->inst_ob, space_mat, index, false); + make_recursive_duplis(vdd->ctx, vdd->inst_ob, space_mat, index); } static void make_child_duplis_verts(const DupliContext *ctx, void *userdata, Object *child) @@ -654,7 +632,7 @@ static void make_duplis_font(const DupliContext *ctx) copy_v3_v3(obmat[3], vec); - make_dupli(ctx, ob, obmat, a, false, false); + make_dupli(ctx, ob, obmat, a); } } @@ -760,7 +738,7 @@ static void make_child_duplis_faces(const DupliContext *ctx, void *userdata, Obj */ mul_m4_m4m4(space_mat, obmat, inst_ob->imat); - dob = make_dupli(ctx, inst_ob, obmat, a, false, false); + dob = make_dupli(ctx, inst_ob, obmat, a); if (use_texcoords) { float w = 1.0f / (float)mp->totloop; @@ -780,7 +758,7 @@ static void make_child_duplis_faces(const DupliContext *ctx, void *userdata, Obj } /* recursion */ - make_recursive_duplis(ctx, inst_ob, space_mat, a, false); + make_recursive_duplis(ctx, inst_ob, space_mat, a); } } @@ -925,10 +903,6 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem /* gather list of objects or single object */ if (part->ren_as == PART_DRAW_GR) { - if (ctx->do_update) { - BKE_collection_handle_recalc_and_update(ctx->depsgraph, scene, par, part->dup_group); - } - if (part->draw & PART_DRAW_COUNT_GR) { for (dw = part->dupliweights.first; dw; dw = dw->next) totcollection += dw->count; @@ -1075,7 +1049,7 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem /* individual particle transform */ mul_m4_m4m4(mat, pamat, tmat); - dob = make_dupli(ctx, object, mat, a, false, false); + dob = make_dupli(ctx, object, mat, a); dob->particle_system = psys; if (use_texcoords) { @@ -1129,7 +1103,7 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem if (part->draw & PART_DRAW_GLOBAL_OB) add_v3_v3v3(mat[3], mat[3], vec); - dob = make_dupli(ctx, ob, mat, a, false, false); + dob = make_dupli(ctx, ob, mat, a); dob->particle_system = psys; if (use_texcoords) psys_get_dupli_texture(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco); @@ -1166,7 +1140,7 @@ static void make_duplis_particles(const DupliContext *ctx) for (psys = ctx->object->particlesystem.first, psysid = 0; psys; psys = psys->next, psysid++) { /* particles create one more level for persistent psys index */ DupliContext pctx; - copy_dupli_context(&pctx, ctx, ctx->object, NULL, psysid, false); + copy_dupli_context(&pctx, ctx, ctx->object, NULL, psysid); make_duplis_particle_system(&pctx, psys); } } @@ -1220,11 +1194,11 @@ static const DupliGenerator *get_dupli_generator(const DupliContext *ctx) /* ---- ListBase dupli container implementation ---- */ /* Returns a list of DupliObject */ -ListBase *object_duplilist_ex(Depsgraph *depsgraph, Scene *scene, Object *ob, bool update) +ListBase *object_duplilist(Depsgraph *depsgraph, Scene *sce, Object *ob) { ListBase *duplilist = MEM_callocN(sizeof(ListBase), "duplilist"); DupliContext ctx; - init_context(&ctx, depsgraph, scene, ob, NULL, update); + init_context(&ctx, depsgraph, sce, ob, NULL); if (ctx.gen) { ctx.duplilist = duplilist; ctx.gen->make_duplis(&ctx); @@ -1233,13 +1207,6 @@ ListBase *object_duplilist_ex(Depsgraph *depsgraph, Scene *scene, Object *ob, bo return duplilist; } -/* note: previously updating was always done, this is why it defaults to be on - * but there are likely places it can be called without updating */ -ListBase *object_duplilist(Depsgraph *depsgraph, Scene *sce, Object *ob) -{ - return object_duplilist_ex(depsgraph, sce, ob, true); -} - void free_object_duplilist(ListBase *lb) { BLI_freelistN(lb); diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c index 852d8197a6c..3b684ebfd94 100644 --- a/source/blender/blenkernel/intern/object_update.c +++ b/source/blender/blenkernel/intern/object_update.c @@ -145,6 +145,7 @@ void BKE_object_eval_done(Depsgraph *depsgraph, Object *ob) Object *ob_orig = DEG_get_original_object(ob); copy_m4_m4(ob_orig->obmat, ob->obmat); ob_orig->transflag = ob->transflag; + ob_orig->flag = ob->flag; } } diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c index afb155f7646..baa88f00985 100644 --- a/source/blender/blenkernel/intern/packedFile.c +++ b/source/blender/blenkernel/intern/packedFile.c @@ -246,14 +246,14 @@ void packAll(Main *bmain, ReportList *reports, bool verbose) for (vfont = bmain->vfont.first; vfont; vfont = vfont->id.next) { if (vfont->packedfile == NULL && !ID_IS_LINKED(vfont) && BKE_vfont_is_builtin(vfont) == false) { - vfont->packedfile = newPackedFile(reports, vfont->name, bmain->name); + vfont->packedfile = newPackedFile(reports, vfont->name, BKE_main_blendfile_path(bmain)); tot ++; } } for (sound = bmain->sound.first; sound; sound = sound->id.next) { if (sound->packedfile == NULL && !ID_IS_LINKED(sound)) { - sound->packedfile = newPackedFile(reports, sound->name, bmain->name); + sound->packedfile = newPackedFile(reports, sound->name, BKE_main_blendfile_path(bmain)); tot++; } } @@ -542,7 +542,7 @@ int unpackVFont(Main *bmain, ReportList *reports, VFont *vfont, int how) if (vfont != NULL) { unpack_generate_paths(vfont->name, (ID *)vfont, absname, localname, sizeof(absname), sizeof(localname)); - newname = unpackFile(reports, bmain->name, absname, localname, vfont->packedfile, how); + newname = unpackFile(reports, BKE_main_blendfile_path(bmain), absname, localname, vfont->packedfile, how); if (newname != NULL) { ret_value = RET_OK; freePackedFile(vfont->packedfile); @@ -563,7 +563,7 @@ int unpackSound(Main *bmain, ReportList *reports, bSound *sound, int how) if (sound != NULL) { unpack_generate_paths(sound->name, (ID *)sound, absname, localname, sizeof(absname), sizeof(localname)); - newname = unpackFile(reports, bmain->name, absname, localname, sound->packedfile, how); + newname = unpackFile(reports, BKE_main_blendfile_path(bmain), absname, localname, sound->packedfile, how); if (newname != NULL) { BLI_strncpy(sound->name, newname, sizeof(sound->name)); MEM_freeN(newname); @@ -591,7 +591,7 @@ int unpackImage(Main *bmain, ReportList *reports, Image *ima, int how) ImagePackedFile *imapf = ima->packedfiles.last; unpack_generate_paths(imapf->filepath, (ID *)ima, absname, localname, sizeof(absname), sizeof(localname)); - newname = unpackFile(reports, bmain->name, absname, localname, imapf->packedfile, how); + newname = unpackFile(reports, BKE_main_blendfile_path(bmain), absname, localname, imapf->packedfile, how); if (newname != NULL) { ImageView *iv; @@ -637,7 +637,7 @@ int unpackLibraries(Main *bmain, ReportList *reports) for (lib = bmain->library.first; lib; lib = lib->id.next) { if (lib->packedfile && lib->name[0]) { - newname = unpackFile(reports, bmain->name, lib->filepath, lib->filepath, lib->packedfile, PF_WRITE_ORIGINAL); + newname = unpackFile(reports, BKE_main_blendfile_path(bmain), lib->filepath, lib->filepath, lib->packedfile, PF_WRITE_ORIGINAL); if (newname != NULL) { ret_value = RET_OK; @@ -670,7 +670,7 @@ void packLibraries(Main *bmain, ReportList *reports) for (lib = bmain->library.first; lib; lib = lib->id.next) if (lib->packedfile == NULL) - lib->packedfile = newPackedFile(reports, lib->name, bmain->name); + lib->packedfile = newPackedFile(reports, lib->name, BKE_main_blendfile_path(bmain)); } void unpackAll(Main *bmain, ReportList *reports, int how) diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index f961510984a..f03b46c8a07 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -59,6 +59,8 @@ #include "BKE_key.h" #include "BKE_library.h" #include "BKE_mesh.h" +#include "BKE_mesh_mapping.h" +#include "BKE_mesh_runtime.h" #include "BKE_modifier.h" #include "BKE_object.h" #include "BKE_paint.h" @@ -753,7 +755,6 @@ void BKE_sculptsession_free(Object *ob) { if (ob && ob->sculpt) { SculptSession *ss = ob->sculpt; - DerivedMesh *dm = ob->derivedFinal; if (ss->bm) { BKE_sculptsession_bm_to_me(ob, true); @@ -762,12 +763,11 @@ void BKE_sculptsession_free(Object *ob) if (ss->pbvh) BKE_pbvh_free(ss->pbvh); + MEM_SAFE_FREE(ss->pmap); + MEM_SAFE_FREE(ss->pmap_mem); if (ss->bm_log) BM_log_free(ss->bm_log); - if (dm && dm->getPBVH) - dm->getPBVH(NULL, dm); /* signal to clear */ - if (ss->texcache) MEM_freeN(ss->texcache); @@ -872,9 +872,8 @@ void BKE_sculpt_update_mesh_elements( return; } - DerivedMesh *dm; SculptSession *ss = ob->sculpt; - Mesh *me = ob->data; + Mesh *me = BKE_object_get_original_mesh(ob); MultiresModifierData *mmd = BKE_sculpt_multires_active(scene, ob); ss->modifiers_active = sculpt_modifiers_active(scene, sd, ob); @@ -909,13 +908,14 @@ void BKE_sculpt_update_mesh_elements( ss->kb = (mmd == NULL) ? BKE_keyblock_from_object(ob) : NULL; - dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH); + Mesh *me_eval = mesh_get_eval_final(depsgraph, scene, ob, CD_MASK_BAREMESH); + Mesh *me_eval_deform = mesh_get_eval_deform(depsgraph, scene, ob, CD_MASK_BAREMESH); /* VWPaint require mesh info for loop lookup, so require sculpt mode here */ if (mmd && ob->mode & OB_MODE_SCULPT) { ss->multires = mmd; - ss->totvert = dm->getNumVerts(dm); - ss->totpoly = dm->getNumPolys(dm); + ss->totvert = me_eval->totvert; + ss->totpoly = me_eval->totpoly; ss->mvert = NULL; ss->mpoly = NULL; ss->mloop = NULL; @@ -930,8 +930,17 @@ void BKE_sculpt_update_mesh_elements( ss->vmask = CustomData_get_layer(&me->vdata, CD_PAINT_MASK); } - ss->pbvh = dm->getPBVH(ob, dm); - ss->pmap = (need_pmap && dm->getPolyMap) ? dm->getPolyMap(ob, dm) : NULL; + PBVH *pbvh = BKE_sculpt_object_pbvh_ensure(ob, me_eval_deform); + BLI_assert(pbvh == ss->pbvh); + UNUSED_VARS_NDEBUG(pbvh); + MEM_SAFE_FREE(ss->pmap); + MEM_SAFE_FREE(ss->pmap_mem); + if (need_pmap && ob->type == OB_MESH) { + BKE_mesh_vert_poly_map_create( + &ss->pmap, &ss->pmap_mem, + me->mpoly, me->mloop, + me->totvert, me->totpoly, me->totloop); + } pbvh_show_diffuse_color_set(ss->pbvh, ss->show_diffuse_color); pbvh_show_mask_set(ss->pbvh, ss->show_mask); @@ -945,7 +954,7 @@ void BKE_sculpt_update_mesh_elements( ss->orig_cos = (ss->kb) ? BKE_keyblock_convert_to_vertcos(ob, ss->kb) : BKE_mesh_vertexCos_get(me, NULL); BKE_crazyspace_build_sculpt(depsgraph, scene, ob, &ss->deform_imats, &ss->deform_cos); - BKE_pbvh_apply_vertCos(ss->pbvh, ss->deform_cos); + BKE_pbvh_apply_vertCos(ss->pbvh, ss->deform_cos, me->totvert); for (a = 0; a < me->totvert; ++a) { invert_m3(ss->deform_imats[a]); @@ -962,14 +971,14 @@ void BKE_sculpt_update_mesh_elements( /* if pbvh is deformed, key block is already applied to it */ if (ss->kb) { - bool pbvh_deformd = BKE_pbvh_isDeformed(ss->pbvh); - if (!pbvh_deformd || ss->deform_cos == NULL) { + bool pbvh_deformed = BKE_pbvh_isDeformed(ss->pbvh); + if (!pbvh_deformed || ss->deform_cos == NULL) { float (*vertCos)[3] = BKE_keyblock_convert_to_vertcos(ob, ss->kb); if (vertCos) { - if (!pbvh_deformd) { + if (!pbvh_deformed) { /* apply shape keys coordinates to PBVH */ - BKE_pbvh_apply_vertCos(ss->pbvh, vertCos); + BKE_pbvh_apply_vertCos(ss->pbvh, vertCos, me->totvert); } if (ss->deform_cos == NULL) { ss->deform_cos = vertCos; @@ -1091,3 +1100,96 @@ void BKE_sculpt_toolsettings_data_ensure(struct Scene *scene) sd->paint.tile_offset[2] = 1.0f; } } + +static bool check_sculpt_object_deformed(Object *object, const bool for_construction) +{ + bool deformed = false; + + /* Active modifiers means extra deformation, which can't be handled correct + * on birth of PBVH and sculpt "layer" levels, so use PBVH only for internal brush + * stuff and show final DerivedMesh so user would see actual object shape. + */ + deformed |= object->sculpt->modifiers_active; + + if (for_construction) { + deformed |= object->sculpt->kb != NULL; + } + else { + /* As in case with modifiers, we can't synchronize deformation made against + * PBVH and non-locked keyblock, so also use PBVH only for brushes and + * final DM to give final result to user. + */ + deformed |= object->sculpt->kb && (object->shapeflag & OB_SHAPE_LOCK) == 0; + } + + return deformed; +} + +PBVH *BKE_sculpt_object_pbvh_ensure(Object *ob, Mesh *me_eval_deform) +{ + if (!ob) { + return NULL; + } + + if (!ob->sculpt) { + return NULL; + } + + PBVH *pbvh = ob->sculpt->pbvh; + + /* Sculpting on a BMesh (dynamic-topology) gets a special PBVH */ + if (!pbvh && ob->sculpt->bm) { + pbvh = BKE_pbvh_new(); + + BKE_pbvh_build_bmesh(pbvh, ob->sculpt->bm, + ob->sculpt->bm_smooth_shading, + ob->sculpt->bm_log, ob->sculpt->cd_vert_node_offset, + ob->sculpt->cd_face_node_offset); + + pbvh_show_diffuse_color_set(pbvh, ob->sculpt->show_diffuse_color); + pbvh_show_mask_set(pbvh, ob->sculpt->show_mask); + } + + /* always build pbvh from original mesh, and only use it for drawing if + * this derivedmesh is just original mesh. it's the multires subsurf dm + * that this is actually for, to support a pbvh on a modified mesh */ + if (!pbvh && ob->type == OB_MESH) { + Mesh *me = BKE_object_get_original_mesh(ob); + const int looptris_num = poly_to_tri_count(me->totpoly, me->totloop); + MLoopTri *looptri; + bool deformed; + + pbvh = BKE_pbvh_new(); + + looptri = MEM_malloc_arrayN(looptris_num, sizeof(*looptri), __func__); + + BKE_mesh_recalc_looptri( + me->mloop, me->mpoly, + me->mvert, + me->totloop, me->totpoly, + looptri); + + BKE_pbvh_build_mesh( + pbvh, + me->mpoly, me->mloop, + me->mvert, me->totvert, &me->vdata, + looptri, looptris_num); + + pbvh_show_diffuse_color_set(pbvh, ob->sculpt->show_diffuse_color); + pbvh_show_mask_set(pbvh, ob->sculpt->show_mask); + + deformed = check_sculpt_object_deformed(ob, true); + + if (deformed && me_eval_deform) { + int totvert; + float (*v_cos)[3]; + + v_cos = BKE_mesh_vertexCos_get(me_eval_deform, &totvert); + BKE_pbvh_apply_vertCos(pbvh, v_cos, totvert); + MEM_freeN(v_cos); + } + } + + ob->sculpt->pbvh = pbvh; + return pbvh; +} diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 9550cbc6b50..8c322f0c853 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -298,24 +298,6 @@ ParticleSystem *psys_orig_get(ParticleSystem *psys) return psys->orig_psys; } -struct ParticleSystem *psys_eval_get(Depsgraph *depsgraph, - Object *object, - ParticleSystem *psys) -{ - Object *object_eval = DEG_get_evaluated_object(depsgraph, object); - if (object_eval == object) { - return psys; - } - ParticleSystem *psys_eval = object_eval->particlesystem.first; - while (psys_eval != NULL) { - if (psys_eval->orig_psys == psys) { - return psys_eval; - } - psys_eval = psys_eval->next; - } - return psys_eval; -} - static PTCacheEdit *psys_orig_edit_get(ParticleSystem *psys) { if (psys->orig_psys == NULL) { @@ -2618,7 +2600,6 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re } void psys_cache_edit_paths(Depsgraph *depsgraph, Scene *scene, Object *ob, PTCacheEdit *edit, float cfra, const bool use_render_params) { - Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); ParticleCacheKey *ca, **cache = edit->pathcache; ParticleEditSettings *pset = &scene->toolsettings->particle; @@ -2626,16 +2607,9 @@ void psys_cache_edit_paths(Depsgraph *depsgraph, Scene *scene, Object *ob, PTCac PTCacheEditKey *ekey = NULL; ParticleSystem *psys = edit->psys; - ParticleSystem *psys_eval = NULL; ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys); - ParticleSystemModifierData *psmd_eval = NULL; - if (psmd != NULL) { - psmd_eval = (ParticleSystemModifierData *)modifiers_findByName(ob_eval, psmd->modifier.name); - psys_eval = psmd_eval->psys; - } - - ParticleData *pa = psys_eval ? psys_eval->particles : NULL; + ParticleData *pa = psys ? psys->particles : NULL; ParticleInterpolationData pind; ParticleKey result; @@ -2664,7 +2638,7 @@ void psys_cache_edit_paths(Depsgraph *depsgraph, Scene *scene, Object *ob, PTCac /* frs_sec = (psys || edit->pid.flag & PTCACHE_VEL_PER_SEC) ? 25.0f : 1.0f; */ /* UNUSED */ - const bool use_weight = (pset->brushtype == PE_BRUSH_WEIGHT) && (psys_eval != NULL) && (psys_eval->particles != NULL); + const bool use_weight = (pset->brushtype == PE_BRUSH_WEIGHT) && (psys != NULL) && (psys->particles != NULL); if (use_weight) { ; /* use weight painting colors now... */ @@ -2709,10 +2683,10 @@ void psys_cache_edit_paths(Depsgraph *depsgraph, Scene *scene, Object *ob, PTCac cache[i]->segments = segments; /*--get the first data points--*/ - init_particle_interpolation(ob_eval, psys_eval, pa, &pind); + init_particle_interpolation(ob, psys, pa, &pind); - if (psys_eval) { - psys_mat_hair_to_global(ob_eval, psmd_eval->mesh_final, psys->part->from, pa, hairmat); + if (psys) { + psys_mat_hair_to_global(ob, psmd->mesh_final, psys->part->from, pa, hairmat); copy_v3_v3(rotmat[0], hairmat[2]); copy_v3_v3(rotmat[1], hairmat[1]); copy_v3_v3(rotmat[2], hairmat[0]); @@ -2731,7 +2705,7 @@ void psys_cache_edit_paths(Depsgraph *depsgraph, Scene *scene, Object *ob, PTCac time = (float)k / (float)segments; t = birthtime + time * (dietime - birthtime); result.time = -t; - do_particle_interpolation(psys_eval, i, pa, t, &pind, &result); + do_particle_interpolation(psys, i, pa, t, &pind, &result); copy_v3_v3(ca->co, result.co); /* non-hair points are already in global space */ @@ -2828,9 +2802,9 @@ void psys_cache_edit_paths(Depsgraph *depsgraph, Scene *scene, Object *ob, PTCac ParticleSimulationData sim = {0}; sim.depsgraph = depsgraph; sim.scene = scene; - sim.ob = ob_eval; - sim.psys = psys_eval; - sim.psmd = psys_get_modifier(ob_eval, psys_eval); + sim.ob = ob; + sim.psys = psys; + sim.psmd = psys_get_modifier(ob, psys); psys_cache_child_paths(&sim, cfra, true, use_render_params); } @@ -3089,6 +3063,9 @@ void object_remove_particle_system(Scene *UNUSED(scene), Object *ob) DEG_relations_tag_update(G.main); DEG_id_tag_update(&ob->id, OB_RECALC_DATA); + + /* Flush object mode. */ + DEG_id_tag_update(&ob->id, DEG_TAG_COPY_ON_WRITE); } static void default_particle_settings(ParticleSettings *part) diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index 88fc8c6a440..8d6991ff9f4 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -4150,7 +4150,7 @@ void psys_check_boid_data(ParticleSystem *psys) } } -static void fluid_default_settings(ParticleSettings *part) +void BKE_particlesettings_fluid_default_settings(ParticleSettings *part) { SPHFluidSettings *fluid = part->fluid; @@ -4182,24 +4182,12 @@ static void psys_prepare_physics(ParticleSimulationData *sim) sim->psys->flag &= ~PSYS_KEYED; } - if (part->phystype == PART_PHYS_BOIDS && part->boids == NULL) { - BoidState *state; - - part->boids = MEM_callocN(sizeof(BoidSettings), "Boid Settings"); - boid_default_settings(part->boids); - - state = boid_new_state(part->boids); - BLI_addtail(&state->rules, boid_new_rule(eBoidRuleType_Separate)); - BLI_addtail(&state->rules, boid_new_rule(eBoidRuleType_Flock)); - - ((BoidRule*)state->rules.first)->flag |= BOIDRULE_CURRENT; - - state->flag |= BOIDSTATE_CURRENT; - BLI_addtail(&part->boids->states, state); + /* RNA Update must ensure this is true. */ + if (part->phystype == PART_PHYS_BOIDS) { + BLI_assert(part->boids != NULL); } - else if (part->phystype == PART_PHYS_FLUID && part->fluid == NULL) { - part->fluid = MEM_callocN(sizeof(SPHFluidSettings), "SPH Fluid Settings"); - fluid_default_settings(part); + else if (part->phystype == PART_PHYS_FLUID) { + BLI_assert(part->fluid != NULL); } psys_check_boid_data(sim->psys); @@ -4229,6 +4217,18 @@ void particle_system_update(struct Depsgraph *depsgraph, Scene *scene, Object *o if (!psys_check_enabled(ob, psys, use_render_params)) return; + if (DEG_is_active(depsgraph)) { + if (psys->orig_psys != NULL && psys->orig_psys->edit != NULL) { + psys_cache_edit_paths( + depsgraph, + (Scene *)DEG_get_original_id(&scene->id), + DEG_get_original_object(ob), + psys->orig_psys->edit, + DEG_get_ctime(depsgraph), + DEG_get_mode(depsgraph) == DAG_EVAL_RENDER); + } + } + cfra = DEG_get_ctime(depsgraph); sim.depsgraph = depsgraph; diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index 7b53c5f8811..8cc8a8510f2 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -2189,8 +2189,13 @@ float (*BKE_pbvh_get_vertCos(PBVH *pbvh))[3] return vertCos; } -void BKE_pbvh_apply_vertCos(PBVH *pbvh, float (*vertCos)[3]) +void BKE_pbvh_apply_vertCos(PBVH *pbvh, float (*vertCos)[3], const int totvert) { + if (totvert != pbvh->totvert) { + BLI_assert(!"PBVH: Given deforming vcos number does not natch PBVH vertex number!"); + return; + } + if (!pbvh->deformed) { if (pbvh->verts) { /* if pbvh is not already deformed, verts/faces points to the */ diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index e219e27f851..af13909bf89 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -1802,7 +1802,7 @@ static int ptcache_frame_from_filename(const char *filename, const char *ext) static int ptcache_path(PTCacheID *pid, char *filename) { Library *lib = (pid->ob) ? pid->ob->id.lib : NULL; - const char *blendfilename= (lib && (pid->cache->flag & PTCACHE_IGNORE_LIBPATH)==0) ? lib->filepath: G.main->name; + const char *blendfilename= (lib && (pid->cache->flag & PTCACHE_IGNORE_LIBPATH)==0) ? lib->filepath: BKE_main_blendfile_path_from_global(); size_t i; if (pid->cache->flag & PTCACHE_EXTERNAL) { diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index 75018bbe5bd..e79f86c6520 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -705,7 +705,8 @@ static void rigidbody_validate_sim_object(RigidBodyWorld *rbw, Object *ob, bool /* --------------------- */ -static void rigidbody_constraint_set_limits(RigidBodyCon *rbc, void (*set_limits)(rbConstraint*,int,float,float)) +static void rigidbody_constraint_set_limits( + RigidBodyCon *rbc, void (*set_limits)(rbConstraint *, int, float, float)) { if (rbc->flag & RBC_FLAG_USE_LIMIT_LIN_X) set_limits(rbc->physics_constraint, RB_LIMIT_LIN_X, rbc->limit_lin_x_lower, rbc->limit_lin_x_upper); diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index a488386fed8..2916e5559c4 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -945,11 +945,11 @@ Scene *BKE_scene_set_name(Main *bmain, const char *name) Scene *sce = (Scene *)BKE_libblock_find_name(bmain, ID_SCE, name); if (sce) { BKE_scene_set_background(bmain, sce); - printf("Scene switch for render: '%s' in file: '%s'\n", name, bmain->name); + printf("Scene switch for render: '%s' in file: '%s'\n", name, BKE_main_blendfile_path(bmain)); return sce; } - printf("Can't find scene: '%s' in file: '%s'\n", name, bmain->name); + printf("Can't find scene: '%s' in file: '%s'\n", name, BKE_main_blendfile_path(bmain)); return NULL; } @@ -1029,7 +1029,7 @@ int BKE_scene_base_iter_next( * this enters eternal loop because of * makeDispListMBall getting called inside of collection_duplilist */ if ((*base)->object->dup_group == NULL) { - iter->duplilist = object_duplilist_ex(depsgraph, (*scene), (*base)->object, false); + iter->duplilist = object_duplilist(depsgraph, (*scene), (*base)->object); iter->dupob = iter->duplilist->first; diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index ece68884f5c..8cff10902ef 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -69,13 +69,19 @@ static void spacetype_free(SpaceType *st) for (art = st->regiontypes.first; art; art = art->next) { BLI_freelistN(&art->drawcalls); - for (pt = art->paneltypes.first; pt; pt = pt->next) - if (pt->ext.free) + for (pt = art->paneltypes.first; pt; pt = pt->next) { + if (pt->ext.free) { pt->ext.free(pt->ext.data); + } + + BLI_freelistN(&pt->children); + } - for (ht = art->headertypes.first; ht; ht = ht->next) - if (ht->ext.free) + for (ht = art->headertypes.first; ht; ht = ht->next) { + if (ht->ext.free) { ht->ext.free(ht->ext.data); + } + } BLI_freelistN(&art->paneltypes); BLI_freelistN(&art->headertypes); @@ -169,10 +175,35 @@ void BKE_spacedata_freelist(ListBase *lb) BLI_freelistN(lb); } +static void panel_list_copy(ListBase *newlb, const ListBase *lb) +{ + BLI_listbase_clear(newlb); + BLI_duplicatelist(newlb, lb); + + /* copy panel pointers */ + Panel *newpa = newlb->first; + Panel *pa = lb->first; + for (; newpa; newpa = newpa->next, pa = pa->next) { + newpa->activedata = NULL; + + Panel *newpatab = newlb->first; + Panel *patab = lb->first; + while (newpatab) { + if (newpa->paneltab == patab) { + newpa->paneltab = newpatab; + break; + } + newpatab = newpatab->next; + patab = patab->next; + } + + panel_list_copy(&newpa->children, &pa->children); + } +} + ARegion *BKE_area_region_copy(SpaceType *st, ARegion *ar) { ARegion *newar = MEM_dupallocN(ar); - Panel *pa, *newpa, *patab; newar->prev = newar->next = NULL; BLI_listbase_clear(&newar->handlers); @@ -199,25 +230,10 @@ ARegion *BKE_area_region_copy(SpaceType *st, ARegion *ar) if (ar->v2d.tab_offset) newar->v2d.tab_offset = MEM_dupallocN(ar->v2d.tab_offset); - BLI_listbase_clear(&newar->panels); - BLI_duplicatelist(&newar->panels, &ar->panels); + panel_list_copy(&newar->panels, &ar->panels); BLI_listbase_clear(&newar->ui_previews); BLI_duplicatelist(&newar->ui_previews, &ar->ui_previews); - - /* copy panel pointers */ - for (newpa = newar->panels.first; newpa; newpa = newpa->next) { - patab = newar->panels.first; - pa = ar->panels.first; - while (patab) { - if (newpa->paneltab == pa) { - newpa->paneltab = patab; - break; - } - patab = patab->next; - pa = pa->next; - } - } return newar; } @@ -329,6 +345,19 @@ void BKE_region_callback_free_manipulatormap_set(void (*callback)(struct wmManip region_free_manipulatormap_callback = callback; } +static void panel_list_free(ListBase *lb) +{ + Panel *pa, *pa_next; + for (pa = lb->first; pa; pa = pa_next) { + pa_next = pa->next; + if (pa->activedata) { + MEM_freeN(pa->activedata); + } + panel_list_free(&pa->children); + MEM_freeN(pa); + } +} + /* not region itself */ void BKE_area_region_free(SpaceType *st, ARegion *ar) { @@ -351,16 +380,7 @@ void BKE_area_region_free(SpaceType *st, ARegion *ar) ar->v2d.tab_offset = NULL; } - if (!BLI_listbase_is_empty(&ar->panels)) { - Panel *pa, *pa_next; - for (pa = ar->panels.first; pa; pa = pa_next) { - pa_next = pa->next; - if (pa->activedata) { - MEM_freeN(pa->activedata); - } - MEM_freeN(pa); - } - } + panel_list_free(&ar->panels); for (uilst = ar->ui_lists.first; uilst; uilst = uilst->next) { if (uilst->dyn_data) { diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index 0eca7a00515..00af9721f07 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -1767,13 +1767,13 @@ static float check_zone(WipeZone *wipezone, int x, int y, Sequence *seq, float f if (output != output) output = 1; if (wipe->forward) output = 1 - output; break; - /* BOX WIPE IS NOT WORKING YET */ + /* BOX WIPE IS NOT WORKING YET */ /* case DO_CROSS_WIPE: */ /* BOX WIPE IS NOT WORKING YET */ #if 0 - case DO_BOX_WIPE: - if (!wipe->forward) - facf0 = 1.0f - facf0; /* Go the other direction */ + case DO_BOX_WIPE: + if (!wipe->forward) + facf0 = 1.0f - facf0; /* Go the other direction */ width = (int)(wipe->edgeWidth * ((xo + yo) / 2.0)); hwidth = (float)width / 2.0; @@ -1806,8 +1806,9 @@ static float check_zone(WipeZone *wipezone, int x, int y, Sequence *seq, float f output = in_band(hwidth, hyp2, 1, 1) * in_band(hwidth, hyp, 1, 1); } - if (!wipe->forward) - facf0 = 1.0f - facf0; /* Go the other direction */ + if (!wipe->forward) { + facf0 = 1.0f - facf0; /* Go the other direction */ + } angle = -1 / angle; b1 = posy / 2 - (-angle) * posx / 2; b3 = (yo - posy / 2) - (-angle) * (xo - posx / 2); diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index f5d99e2615a..ecd0335fc4e 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -898,7 +898,7 @@ void BKE_sequence_reload_new_file(Scene *scene, Sequence *seq, const bool lock_r BLI_join_dirfile(path, sizeof(path), seq->strip->dir, seq->strip->stripdata->name); - BLI_path_abs(path, G.main->name); + BLI_path_abs(path, BKE_main_blendfile_path_from_global()); BKE_sequence_free_anim(seq); @@ -1546,7 +1546,7 @@ static void seq_open_anim_file(Scene *scene, Sequence *seq, bool openfile) BLI_join_dirfile(name, sizeof(name), seq->strip->dir, seq->strip->stripdata->name); - BLI_path_abs(name, G.main->name); + BLI_path_abs(name, BKE_main_blendfile_path_from_global()); proxy = seq->strip->proxy; @@ -1563,7 +1563,7 @@ static void seq_open_anim_file(Scene *scene, Sequence *seq, bool openfile) else { BLI_strncpy(dir, seq->strip->proxy->dir, sizeof(dir)); } - BLI_path_abs(dir, G.main->name); + BLI_path_abs(dir, BKE_main_blendfile_path_from_global()); } if (is_multiview && seq->views_format == R_IMF_VIEWS_INDIVIDUAL) { @@ -1691,7 +1691,7 @@ static bool seq_proxy_get_fname(Editing *ed, Sequence *seq, int cfra, int render return false; } BLI_path_append(dir, sizeof(dir), fname); - BLI_path_abs(name, G.main->name); + BLI_path_abs(name, BKE_main_blendfile_path_from_global()); } else if ((proxy->storage & SEQ_STORAGE_PROXY_CUSTOM_DIR) && (proxy->storage & SEQ_STORAGE_PROXY_CUSTOM_FILE)) { BLI_strncpy(dir, seq->strip->proxy->dir, sizeof(dir)); @@ -1723,7 +1723,7 @@ static bool seq_proxy_get_fname(Editing *ed, Sequence *seq, int cfra, int render { char fname[FILE_MAXFILE]; BLI_join_dirfile(fname, PROXY_MAXFILE, dir, proxy->file); - BLI_path_abs(fname, G.main->name); + BLI_path_abs(fname, BKE_main_blendfile_path_from_global()); if (suffix[0] != '\0') { /* TODO(sergey): This will actually append suffix after extension * which is weird but how was originally coded in multiview branch. @@ -1749,7 +1749,7 @@ static bool seq_proxy_get_fname(Editing *ed, Sequence *seq, int cfra, int render BLI_snprintf(name, PROXY_MAXFILE, "%s/proxy_misc/%d/####%s", dir, render_size, suffix); } - BLI_path_abs(name, G.main->name); + BLI_path_abs(name, BKE_main_blendfile_path_from_global()); BLI_path_frame(name, frameno, 0); strcat(name, ".jpg"); @@ -1894,7 +1894,7 @@ static bool seq_proxy_multiview_context_invalid(Sequence *seq, Scene *scene, con char path[FILE_MAX]; BLI_join_dirfile(path, sizeof(path), seq->strip->dir, seq->strip->stripdata->name); - BLI_path_abs(path, G.main->name); + BLI_path_abs(path, BKE_main_blendfile_path_from_global()); BKE_scene_multiview_view_prefix_get(scene, path, prefix, &ext); } else { @@ -2846,7 +2846,7 @@ static ImBuf *seq_render_image_strip(const SeqRenderData *context, Sequence *seq if (s_elem) { BLI_join_dirfile(name, sizeof(name), seq->strip->dir, s_elem->name); - BLI_path_abs(name, G.main->name); + BLI_path_abs(name, BKE_main_blendfile_path_from_global()); } flag = IB_rect | IB_metadata; @@ -5151,7 +5151,7 @@ void BKE_sequence_init_colorspace(Sequence *seq) ImBuf *ibuf; BLI_join_dirfile(name, sizeof(name), seq->strip->dir, seq->strip->stripdata->name); - BLI_path_abs(name, G.main->name); + BLI_path_abs(name, BKE_main_blendfile_path_from_global()); /* initialize input color space */ if (seq->type == SEQ_TYPE_IMAGE) { @@ -5319,6 +5319,7 @@ static void seq_anim_add_suffix(Scene *scene, struct anim *anim, const int view_ Sequence *BKE_sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo *seq_load) { + Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); /* only for sound */ char path[sizeof(seq_load->path)]; @@ -5333,7 +5334,7 @@ Sequence *BKE_sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoad int i; BLI_strncpy(path, seq_load->path, sizeof(path)); - BLI_path_abs(path, G.main->name); + BLI_path_abs(path, BKE_main_blendfile_path(bmain)); anim_arr = MEM_callocN(sizeof(struct anim *) * totfiles, "Video files"); diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 747ffdafe8b..a7f3fc1df9e 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -77,7 +77,7 @@ bSound *BKE_sound_new_file(struct Main *bmain, const char *filepath) BLI_strncpy(str, filepath, sizeof(str)); - path = /*bmain ? bmain->name :*/ G.main->name; + path = BKE_main_blendfile_path(bmain); BLI_path_abs(str, path); @@ -96,7 +96,7 @@ bSound *BKE_sound_new_file_exists_ex(struct Main *bmain, const char *filepath, b char str[FILE_MAX], strtest[FILE_MAX]; BLI_strncpy(str, filepath, sizeof(str)); - BLI_path_abs(str, bmain->name); + BLI_path_abs(str, BKE_main_blendfile_path(bmain)); /* first search an identical filepath */ for (sound = bmain->sound.first; sound; sound = sound->id.next) { diff --git a/source/blender/blenkernel/intern/studiolight.c b/source/blender/blenkernel/intern/studiolight.c index 4ef7b3d2247..e4b49656907 100644 --- a/source/blender/blenkernel/intern/studiolight.c +++ b/source/blender/blenkernel/intern/studiolight.c @@ -55,13 +55,13 @@ /* Statics */ static ListBase studiolights; -#define STUDIOLIGHT_EXTENSIONS ".jpg", ".hdr" #define STUDIOLIGHT_RADIANCE_CUBEMAP_SIZE 8 #define STUDIOLIGHT_IRRADIANCE_EQUIRECTANGULAR_HEIGHT 32 #define STUDIOLIGHT_IRRADIANCE_EQUIRECTANGULAR_WIDTH (STUDIOLIGHT_IRRADIANCE_EQUIRECTANGULAR_HEIGHT * 2) static const char *STUDIOLIGHT_CAMERA_FOLDER = "studiolights/camera/"; static const char *STUDIOLIGHT_WORLD_FOLDER = "studiolights/world/"; +static const char *STUDIOLIGHT_MATCAP_FOLDER = "studiolights/matcap/"; /* FUNCTIONS */ static void studiolight_free(struct StudioLight *sl) @@ -168,16 +168,16 @@ static void studiolight_load_equierectangular_image(StudioLight *sl) sl->equirectangular_radiance_buffer = ibuf; } } - sl->flag |= STUDIOLIGHT_EQUIRECTANGULAR_IMAGE_LOADED; + sl->flag |= STUDIOLIGHT_EXTERNAL_IMAGE_LOADED; } static void studiolight_create_equierectangular_radiance_gputexture(StudioLight *sl) { if (sl->flag & STUDIOLIGHT_EXTERNAL_FILE) { char error[256]; - BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_EQUIRECTANGULAR_IMAGE_LOADED); + BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_EXTERNAL_IMAGE_LOADED); ImBuf *ibuf = sl->equirectangular_radiance_buffer; - sl->equirectangular_radiance_gputexture = GPU_texture_create_2D(ibuf->x, ibuf->y, GPU_RGBA16F, ibuf->rect_float, error); + sl->equirectangular_radiance_gputexture = GPU_texture_create_2D(ibuf->x, ibuf->y, GPU_RGBA8, ibuf->rect_float, error); GPUTexture *tex = sl->equirectangular_radiance_gputexture; GPU_texture_bind(tex, 0); GPU_texture_filter_mode(tex, true); @@ -206,7 +206,7 @@ static void studiolight_create_equierectangular_irradiance_gputexture(StudioLigh static void studiolight_calculate_radiance_cubemap_buffers(StudioLight *sl) { if (sl->flag & STUDIOLIGHT_EXTERNAL_FILE) { - BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_EQUIRECTANGULAR_IMAGE_LOADED); + BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_EXTERNAL_IMAGE_LOADED); ImBuf *ibuf = sl->equirectangular_radiance_buffer; if (ibuf) { float *colbuf = MEM_mallocN(SQUARE(STUDIOLIGHT_RADIANCE_CUBEMAP_SIZE) * sizeof(float[4]), __func__); @@ -481,7 +481,7 @@ static void studiolight_add_files_from_datafolder(const int folder_id, const cha if ((dir[i].type & S_IFREG)) { const char *filename = dir[i].relname; const char *path = dir[i].path; - if (BLI_testextensie_n(filename, STUDIOLIGHT_EXTENSIONS, NULL)) { + if (BLI_testextensie_array(filename, imb_ext_image)) { sl = studiolight_create(); sl->flag = STUDIOLIGHT_EXTERNAL_FILE | flag; BLI_strncpy(sl->name, filename, FILE_MAXFILE); @@ -527,7 +527,7 @@ static int studiolight_cmp(const void *a, const void *b) /* icons */ static uint *studiolight_radiance_preview(StudioLight *sl, int icon_size) { - BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_EQUIRECTANGULAR_IMAGE_LOADED); + BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_EXTERNAL_IMAGE_LOADED); uint *rect = MEM_mallocN(icon_size * icon_size * sizeof(uint), __func__); int icon_center = icon_size / 2; @@ -579,6 +579,29 @@ static uint *studiolight_radiance_preview(StudioLight *sl, int icon_size) return rect; } +static uint *studiolight_matcap_preview(StudioLight *sl, int icon_size) +{ + BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_EXTERNAL_IMAGE_LOADED); + + uint *rect = MEM_mallocN(icon_size * icon_size * sizeof(uint), __func__); + const uint alphamask = 0xff000000; + float color[4]; + float fx, fy; + int offset = 0; + ImBuf *ibuf = sl->equirectangular_radiance_buffer; + for (int y = 0; y < icon_size; y++) { + for (int x = 0; x < icon_size; x++) { + fx = x * ibuf->x / icon_size; + fy = y * ibuf->y / icon_size; + nearest_interpolation_color(ibuf, NULL, color, fx, fy); + rect[offset++] = rgb_to_cpack(linearrgb_to_srgb(color[0]), + linearrgb_to_srgb(color[1]), + linearrgb_to_srgb(color[2])) | alphamask; + } + } + return rect; +} + static uint *studiolight_irradiance_preview(StudioLight *sl, int icon_size) { if (/*!(sl->flag & STUDIOLIGHT_EXTERNAL_FILE)*/ 1) { @@ -696,7 +719,7 @@ void BKE_studiolight_init(void) /* Add default studio light */ sl = studiolight_create(); BLI_strncpy(sl->name, "INTERNAL_01", FILE_MAXFILE); - sl->flag = STUDIOLIGHT_DIFFUSE_LIGHT_CALCULATED | STUDIOLIGHT_ORIENTATION_CAMERA; + sl->flag = STUDIOLIGHT_INTERNAL | STUDIOLIGHT_DIFFUSE_LIGHT_CALCULATED | STUDIOLIGHT_ORIENTATION_CAMERA; copy_v3_fl(sl->diffuse_light[STUDIOLIGHT_X_POS], 0.0f); copy_v3_fl(sl->diffuse_light[STUDIOLIGHT_X_NEG], 0.0f); copy_v3_fl(sl->diffuse_light[STUDIOLIGHT_Y_POS], 0.8f); @@ -706,9 +729,11 @@ void BKE_studiolight_init(void) BLI_addtail(&studiolights, sl); studiolight_add_files_from_datafolder(BLENDER_SYSTEM_DATAFILES, STUDIOLIGHT_CAMERA_FOLDER, STUDIOLIGHT_ORIENTATION_CAMERA); - studiolight_add_files_from_datafolder(BLENDER_USER_DATAFILES, STUDIOLIGHT_CAMERA_FOLDER, STUDIOLIGHT_ORIENTATION_CAMERA); + studiolight_add_files_from_datafolder(BLENDER_USER_DATAFILES, STUDIOLIGHT_CAMERA_FOLDER, STUDIOLIGHT_ORIENTATION_CAMERA | STUDIOLIGHT_USER_DEFINED); studiolight_add_files_from_datafolder(BLENDER_SYSTEM_DATAFILES, STUDIOLIGHT_WORLD_FOLDER, STUDIOLIGHT_ORIENTATION_WORLD); - studiolight_add_files_from_datafolder(BLENDER_USER_DATAFILES, STUDIOLIGHT_WORLD_FOLDER, STUDIOLIGHT_ORIENTATION_WORLD); + studiolight_add_files_from_datafolder(BLENDER_USER_DATAFILES, STUDIOLIGHT_WORLD_FOLDER, STUDIOLIGHT_ORIENTATION_WORLD | STUDIOLIGHT_USER_DEFINED); + studiolight_add_files_from_datafolder(BLENDER_SYSTEM_DATAFILES, STUDIOLIGHT_MATCAP_FOLDER, STUDIOLIGHT_ORIENTATION_VIEWNORMAL); + studiolight_add_files_from_datafolder(BLENDER_USER_DATAFILES, STUDIOLIGHT_MATCAP_FOLDER, STUDIOLIGHT_ORIENTATION_VIEWNORMAL | STUDIOLIGHT_USER_DEFINED); /* sort studio lights on filename. */ BLI_listbase_sort(&studiolights, studiolight_cmp); @@ -722,24 +747,34 @@ void BKE_studiolight_free(void) } } +struct StudioLight *BKE_studiolight_find_first(int flag) +{ + LISTBASE_FOREACH(StudioLight *, sl, &studiolights) { + if ((sl->flag & flag)) { + return sl; + } + } + return NULL; +} + struct StudioLight *BKE_studiolight_find(const char *name, int flag) { LISTBASE_FOREACH(StudioLight *, sl, &studiolights) { if (STREQLEN(sl->name, name, FILE_MAXFILE)) { - if ((sl->flag & flag) == flag) { + if ((sl->flag & flag)) { return sl; } else { /* flags do not match, so use default */ - return studiolights.first; + return BKE_studiolight_find_first(flag); } } } /* When not found, use the default studio light */ - return studiolights.first; + return BKE_studiolight_find_first(flag); } -struct StudioLight *BKE_studiolight_findindex(int index) +struct StudioLight *BKE_studiolight_findindex(int index, int flag) { LISTBASE_FOREACH(StudioLight *, sl, &studiolights) { if (sl->index == index) { @@ -747,10 +782,10 @@ struct StudioLight *BKE_studiolight_findindex(int index) } } /* When not found, use the default studio light */ - return studiolights.first; + return BKE_studiolight_find_first(flag); } -const struct ListBase *BKE_studiolight_listbase(void) +struct ListBase *BKE_studiolight_listbase(void) { return &studiolights; } @@ -758,7 +793,12 @@ const struct ListBase *BKE_studiolight_listbase(void) uint *BKE_studiolight_preview(StudioLight *sl, int icon_size, int icon_id_type) { if (icon_id_type == STUDIOLIGHT_ICON_ID_TYPE_IRRADIANCE) { - return studiolight_irradiance_preview(sl, icon_size); + if (sl->flag & STUDIOLIGHT_ORIENTATION_VIEWNORMAL) { + return studiolight_matcap_preview(sl, icon_size); + } + else { + return studiolight_irradiance_preview(sl, icon_size); + } } else { return studiolight_radiance_preview(sl, icon_size); @@ -771,7 +811,7 @@ void BKE_studiolight_ensure_flag(StudioLight *sl, int flag) return; } - if ((flag & STUDIOLIGHT_EQUIRECTANGULAR_IMAGE_LOADED)) { + if ((flag & STUDIOLIGHT_EXTERNAL_IMAGE_LOADED)) { studiolight_load_equierectangular_image(sl); } if ((flag & STUDIOLIGHT_RADIANCE_BUFFERS_CALCULATED)) { @@ -793,3 +833,9 @@ void BKE_studiolight_ensure_flag(StudioLight *sl, int flag) studiolight_calculate_irradiance_equirectangular_image(sl); } } + +void BKE_studiolight_refresh(void) +{ + BKE_studiolight_free(); + BKE_studiolight_init(); +} diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index ed23078a9d8..d735944c93d 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -69,6 +69,7 @@ #include "BKE_mesh_mapping.h" #include "BKE_modifier.h" #include "BKE_multires.h" +#include "BKE_object.h" #include "BKE_paint.h" #include "BKE_scene.h" #include "BKE_subsurf.h" @@ -2327,7 +2328,7 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm) numGrids, &key, (void **) ccgdm->gridFaces, ccgdm->gridFlagMats, ccgdm->gridHidden); } else if (ob->type == OB_MESH) { - Mesh *me = ob->data; + Mesh *me = BKE_object_get_original_mesh(ob); const int looptris_num = poly_to_tri_count(me->totpoly, me->totloop); MLoopTri *looptri; @@ -2351,7 +2352,7 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm) totvert = deformdm->getNumVerts(deformdm); vertCos = MEM_malloc_arrayN(totvert, sizeof(float[3]), "ccgDM_getPBVH vertCos"); deformdm->getVertCos(deformdm, vertCos); - BKE_pbvh_apply_vertCos(ccgdm->pbvh, vertCos); + BKE_pbvh_apply_vertCos(ccgdm->pbvh, vertCos, totvert); MEM_freeN(vertCos); } } diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 3892b2f0546..a24020d7764 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -388,7 +388,7 @@ bool BKE_text_reload(Text *text) } BLI_strncpy(filepath_abs, text->name, FILE_MAX); - BLI_path_abs(filepath_abs, G.main->name); + BLI_path_abs(filepath_abs, BKE_main_blendfile_path_from_global()); buffer = BLI_file_read_text_as_mem(filepath_abs, 0, &buffer_len); if (buffer == NULL) { @@ -557,7 +557,7 @@ int BKE_text_file_modified_check(Text *text) return 0; BLI_strncpy(file, text->name, FILE_MAX); - BLI_path_abs(file, G.main->name); + BLI_path_abs(file, BKE_main_blendfile_path_from_global()); if (!BLI_exists(file)) return 2; @@ -585,7 +585,7 @@ void BKE_text_file_modified_ignore(Text *text) if (!text->name) return; BLI_strncpy(file, text->name, FILE_MAX); - BLI_path_abs(file, G.main->name); + BLI_path_abs(file, BKE_main_blendfile_path_from_global()); if (!BLI_exists(file)) return; diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c index f5e4c354a02..a05e79aae1f 100644 --- a/source/blender/blenkernel/intern/undo_system.c +++ b/source/blender/blenkernel/intern/undo_system.c @@ -376,7 +376,7 @@ UndoStep *BKE_undosys_step_push_init_with_type(UndoStack *ustack, bContext *C, c us->type = ut; ustack->step_init = us; ut->step_encode_init(C, us); - undosys_stack_validate(ustack, true); + undosys_stack_validate(ustack, false); return us; } else { diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index 15bf01d2049..1b06e7ed851 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -53,6 +53,8 @@ #include "BKE_node.h" #include "BKE_world.h" +#include "DEG_depsgraph.h" + #include "GPU_material.h" /** Free (or release) any data used by this world (does not free the world itself). */ @@ -161,13 +163,10 @@ void BKE_world_make_local(Main *bmain, World *wrld, const bool lib_local) BKE_id_make_local_generic(bmain, &wrld->id, true, lib_local); } -void BKE_world_eval(struct Depsgraph *UNUSED(depsgraph), World *world) +void BKE_world_eval(struct Depsgraph *depsgraph, World *world) { - if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) { - printf("%s on %s (%p)\n", __func__, world->id.name, world); - } + DEG_debug_print_eval(depsgraph, __func__, world->id.name, world); if (!BLI_listbase_is_empty(&world->gpumaterial)) { world->update_flag = 1; - GPU_material_uniform_buffer_tag_dirty(&world->gpumaterial); } } diff --git a/source/blender/blenkernel/intern/writeavi.c b/source/blender/blenkernel/intern/writeavi.c index e357f13530d..33ac312425b 100644 --- a/source/blender/blenkernel/intern/writeavi.c +++ b/source/blender/blenkernel/intern/writeavi.c @@ -145,7 +145,7 @@ static void filepath_avi(char *string, RenderData *rd, bool preview, const char } strcpy(string, rd->pic); - BLI_path_abs(string, G.main->name); + BLI_path_abs(string, BKE_main_blendfile_path_from_global()); BLI_make_existing_file(string); diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c index 4a0f697c9ce..17c665f3bcd 100644 --- a/source/blender/blenkernel/intern/writeffmpeg.c +++ b/source/blender/blenkernel/intern/writeffmpeg.c @@ -1127,7 +1127,7 @@ static void ffmpeg_filepath_get(FFMpegContext *context, char *string, RenderData } strcpy(string, rd->pic); - BLI_path_abs(string, G.main->name); + BLI_path_abs(string, BKE_main_blendfile_path_from_global()); BLI_make_existing_file(string); |